mirror of
https://github.com/getpaseo/paseo.git
synced 2026-12-06 15:16:03 +00:00
Compare commits
11
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
020e402ea2 | ||
|
|
9bd46b80b0 | ||
|
|
5242c4dbcd | ||
|
|
6b96005868 | ||
|
|
d08bb64020 | ||
|
|
b3906a4cdf | ||
|
|
47f60678a5 | ||
|
|
8e379b17f8 | ||
|
|
4c4fd69c26 | ||
|
|
0cefa98a6a | ||
|
|
67472e3814 |
@@ -24,6 +24,18 @@ value.
|
||||
|
||||
Animate only `transform` and `opacity`. Anything else is painted on the main thread every frame.
|
||||
|
||||
## The waiting mark
|
||||
|
||||
A workspace or agent with no turn running and counted background work alive shows the waiting mark
|
||||
instead of the ring: one 10 px circle stroked with eight equal dashes and gaps, so each dash is a
|
||||
short arc with its ends cut along the radius. It has no centre dot and does not move, so it needs
|
||||
none of the machinery above. It is centred in the running ring's frame
|
||||
(`components/status-ring/waiting.tsx`). Draw it wherever the ring shows for this state and nowhere
|
||||
else. The frame and its knockout stay the running ring's size so a row never changes height when the
|
||||
state changes; the smaller ring only leaves more space between the mark and the icon it sits on.
|
||||
It is `react-native-svg`, the same on web and native. The whole `Svg` is wrapped in
|
||||
`withUnistyles`, as in the context window ring, so the stroke follows theme changes.
|
||||
|
||||
## Hidden panels
|
||||
|
||||
A phone's sidebar slides into view before its panel counts as showing: the panel's active signal
|
||||
|
||||
@@ -0,0 +1,139 @@
|
||||
import type { Page } from "@playwright/test";
|
||||
import { test, expect } from "../support/fixtures";
|
||||
import { gotoAppShell } from "../support/helpers/app";
|
||||
import { seedMockAgentWorkspace, type MockAgentWorkspace } from "../support/helpers/mock-agent";
|
||||
import { getServerId } from "../support/helpers/server-id";
|
||||
import {
|
||||
listOfferedSidebarSorts,
|
||||
pinWorkspaceFromSidebar,
|
||||
readSidebarSortValue,
|
||||
selectSidebarGrouping,
|
||||
selectSidebarSort,
|
||||
} from "../support/helpers/sidebar";
|
||||
|
||||
const FINISH_MS = 20_000;
|
||||
|
||||
async function seedFinishedWorkspace(title: string): Promise<MockAgentWorkspace> {
|
||||
const workspace = await seedMockAgentWorkspace({
|
||||
repoPrefix: "sidebar-ungrouped-",
|
||||
title,
|
||||
initialPrompt: "Finish this turn.",
|
||||
});
|
||||
await workspace.client.waitForFinish(workspace.agentId, FINISH_MS);
|
||||
return workspace;
|
||||
}
|
||||
|
||||
/** The workspace ids in the flat list, top to bottom. Pinned rows are not part of it. */
|
||||
async function flatListOrder(page: Page): Promise<string[]> {
|
||||
const rows = page
|
||||
.getByTestId("sidebar-status-group-rows-all")
|
||||
.locator('[data-testid^="sidebar-workspace-row-"]');
|
||||
const testIds = await rows.evaluateAll((elements) =>
|
||||
elements.map((element) => element.getAttribute("data-testid") ?? ""),
|
||||
);
|
||||
const prefix = `sidebar-workspace-row-${getServerId()}:`;
|
||||
return testIds.map((testId) => testId.slice(prefix.length));
|
||||
}
|
||||
|
||||
async function expectFlatListOrder(page: Page, workspaces: MockAgentWorkspace[]): Promise<void> {
|
||||
await expect
|
||||
.poll(() => flatListOrder(page), { timeout: 30_000 })
|
||||
.toEqual(workspaces.map((workspace) => workspace.workspaceId));
|
||||
}
|
||||
|
||||
test.describe("Sidebar group: none", () => {
|
||||
test.describe.configure({ timeout: 180_000 });
|
||||
|
||||
const seeded: MockAgentWorkspace[] = [];
|
||||
|
||||
test.afterEach(async () => {
|
||||
for (const workspace of seeded.splice(0)) await workspace.cleanup();
|
||||
});
|
||||
|
||||
test("shows one flat list, sorts it, and gives Project and Status grouping back unchanged", async ({
|
||||
page,
|
||||
}) => {
|
||||
const first = await seedFinishedWorkspace("First");
|
||||
const second = await seedFinishedWorkspace("Second");
|
||||
const third = await seedFinishedWorkspace("Third");
|
||||
seeded.push(first, second, third);
|
||||
|
||||
await gotoAppShell(page);
|
||||
await expect(page.getByTestId("sidebar-project-workspace-list-scroll")).toBeVisible({
|
||||
timeout: 30_000,
|
||||
});
|
||||
// Project grouping keeps Manual, which only it offers.
|
||||
await selectSidebarSort(page, "manual");
|
||||
expect(await readSidebarSortValue(page)).toContain("Manual");
|
||||
|
||||
// 1. Group: None is one list with no group headers; a pinned row stays in Pinned above it.
|
||||
await selectSidebarGrouping(page, "none");
|
||||
await expect(page.getByTestId("sidebar-status-list-scroll")).toBeVisible({ timeout: 30_000 });
|
||||
await pinWorkspaceFromSidebar(page, third.workspaceId);
|
||||
await expect(
|
||||
page
|
||||
.getByTestId("sidebar-pinned-section")
|
||||
.getByTestId(`sidebar-workspace-row-${getServerId()}:${third.workspaceId}`),
|
||||
).toBeVisible({ timeout: 30_000 });
|
||||
await expect(page.locator('[data-testid^="sidebar-status-group-attention"]')).toHaveCount(0);
|
||||
await expect(page.locator('[data-testid^="sidebar-project-row-"]')).toHaveCount(0);
|
||||
await expectFlatListOrder(page, [second, first]);
|
||||
|
||||
// 2. The sorts under None, and Manual is not one of them: the stored Manual reads as Created.
|
||||
expect(await listOfferedSidebarSorts(page)).toEqual(["created", "lastPrompt", "statusChange"]);
|
||||
expect(await readSidebarSortValue(page)).toContain("Created");
|
||||
|
||||
await first.client.sendAgentMessage(first.agentId, "Finish this turn again.");
|
||||
await first.client.waitForFinish(first.agentId, FINISH_MS);
|
||||
await selectSidebarSort(page, "lastPrompt");
|
||||
await expectFlatListOrder(page, [first, second]);
|
||||
|
||||
// 3. Status change: a workspace whose status changes moves to the top.
|
||||
await selectSidebarSort(page, "statusChange");
|
||||
await second.client.clearWorkspaceAttention(second.workspaceId);
|
||||
await expectFlatListOrder(page, [second, first]);
|
||||
await first.client.clearWorkspaceAttention(first.workspaceId);
|
||||
await expectFlatListOrder(page, [first, second]);
|
||||
|
||||
// 6. Reloading keeps the choice.
|
||||
await page.reload();
|
||||
await expect(page.getByTestId("sidebar-status-list-scroll")).toBeVisible({ timeout: 30_000 });
|
||||
expect(await readSidebarSortValue(page)).toContain("Status change");
|
||||
await expectFlatListOrder(page, [first, second]);
|
||||
|
||||
// 4. Project grouping reads a sort it does not offer as Created ...
|
||||
await selectSidebarGrouping(page, "project");
|
||||
await expect(page.getByTestId("sidebar-project-workspace-list-scroll")).toBeVisible({
|
||||
timeout: 30_000,
|
||||
});
|
||||
expect(await listOfferedSidebarSorts(page)).toEqual(["manual", "created", "lastPrompt"]);
|
||||
expect(await readSidebarSortValue(page)).toContain("Created");
|
||||
|
||||
// ... and Status grouping offers no sort at all.
|
||||
await selectSidebarGrouping(page, "status");
|
||||
await expect(page.getByTestId("sidebar-status-group-done")).toBeVisible({ timeout: 30_000 });
|
||||
expect(await readSidebarSortValue(page)).toBeNull();
|
||||
});
|
||||
|
||||
test("Project grouping gets the stored Manual sort back after a visit to None", async ({
|
||||
page,
|
||||
}) => {
|
||||
const only = await seedFinishedWorkspace("Only");
|
||||
seeded.push(only);
|
||||
|
||||
await gotoAppShell(page);
|
||||
await expect(page.getByTestId("sidebar-project-workspace-list-scroll")).toBeVisible({
|
||||
timeout: 30_000,
|
||||
});
|
||||
await selectSidebarSort(page, "manual");
|
||||
|
||||
await selectSidebarGrouping(page, "none");
|
||||
await expect(page.getByTestId("sidebar-status-list-scroll")).toBeVisible({ timeout: 30_000 });
|
||||
await selectSidebarGrouping(page, "project");
|
||||
await expect(page.getByTestId("sidebar-project-workspace-list-scroll")).toBeVisible({
|
||||
timeout: 30_000,
|
||||
});
|
||||
|
||||
expect(await readSidebarSortValue(page)).toContain("Manual");
|
||||
});
|
||||
});
|
||||
@@ -27,7 +27,14 @@ import { expectWorkspaceHeader, waitForSidebarHydration } from "../support/helpe
|
||||
import { getVisibleWorkspaceAgentTabIds } from "../support/helpers/workspace-tabs";
|
||||
|
||||
type NewWorkspaceDaemonClient = Awaited<ReturnType<typeof connectNewWorkspaceDaemonClient>>;
|
||||
type WorkspaceIndicator = "attention" | "done" | "failed" | "loading" | "needs_input" | "running";
|
||||
type WorkspaceIndicator =
|
||||
| "attention"
|
||||
| "done"
|
||||
| "failed"
|
||||
| "loading"
|
||||
| "needs_input"
|
||||
| "running"
|
||||
| "waiting";
|
||||
|
||||
interface CreatedAgentAssertion {
|
||||
workspaceId: string;
|
||||
@@ -126,6 +133,7 @@ async function expectWorkspaceRowHasOnlyIndicator(
|
||||
"loading",
|
||||
"needs_input",
|
||||
"running",
|
||||
"waiting",
|
||||
] satisfies WorkspaceIndicator[]) {
|
||||
const locator = row.locator(`[data-testid="workspace-status-indicator-${indicator}"]`);
|
||||
if (indicator === input.indicator) {
|
||||
|
||||
@@ -0,0 +1,147 @@
|
||||
import type { Page } from "@playwright/test";
|
||||
import { test, expect } from "../support/fixtures";
|
||||
import {
|
||||
openAgentRoute,
|
||||
seedMockAgentWorkspace,
|
||||
type MockAgentWorkspace,
|
||||
} from "../support/helpers/mock-agent";
|
||||
import { getServerId } from "../support/helpers/server-id";
|
||||
import { selectSidebarStatusGrouping } from "../support/helpers/sidebar";
|
||||
import { seedParentWithSubagent, seedSubagent } from "../support/helpers/subagents";
|
||||
import { seedWorkspace } from "../support/helpers/seed-client";
|
||||
|
||||
const BACKGROUND_COMMAND_MS = 20_000;
|
||||
|
||||
function workspaceRow(page: Page, workspaceId: string) {
|
||||
return page.getByTestId(`sidebar-workspace-row-${getServerId()}:${workspaceId}`);
|
||||
}
|
||||
|
||||
async function rowHeight(page: Page, workspaceId: string): Promise<number> {
|
||||
const box = await workspaceRow(page, workspaceId).boundingBox();
|
||||
if (!box) throw new Error("workspace row is not laid out");
|
||||
return box.height;
|
||||
}
|
||||
|
||||
async function seedBackgroundShellAgent(
|
||||
title: string,
|
||||
commandMs = BACKGROUND_COMMAND_MS,
|
||||
): Promise<MockAgentWorkspace> {
|
||||
return await seedMockAgentWorkspace({
|
||||
repoPrefix: "waiting-status-",
|
||||
title,
|
||||
initialPrompt: `Please start a background shell command for ${commandMs}ms.`,
|
||||
});
|
||||
}
|
||||
|
||||
test.describe("Waiting on background work", () => {
|
||||
test.describe.configure({ timeout: 120_000 });
|
||||
|
||||
const seeded: MockAgentWorkspace[] = [];
|
||||
|
||||
test.afterEach(async () => {
|
||||
for (const workspace of seeded.splice(0)) await workspace.cleanup();
|
||||
});
|
||||
|
||||
test("the agent's tab shows waiting, not running, once its turn has ended", async ({ page }) => {
|
||||
// The app opens after the agent exists, so the command must outlast a slow startup.
|
||||
const subject = await seedBackgroundShellAgent("Tab subject", 90_000);
|
||||
seeded.push(subject);
|
||||
await openAgentRoute(page, { workspaceId: subject.workspaceId, agentId: subject.agentId });
|
||||
|
||||
await expect(page.getByLabel("Agent waiting").first()).toBeVisible({ timeout: 30_000 });
|
||||
await expect(page.getByLabel("Agent running")).toHaveCount(0);
|
||||
const pill = page.getByTestId("background-work");
|
||||
await expect(pill.getByTestId("status-waiting-ring")).toBeVisible();
|
||||
await expect(pill.getByTestId("status-ring")).toHaveCount(0);
|
||||
});
|
||||
|
||||
test("the row shows the waiting mark at a steady height, then the unread dot when the command ends", async ({
|
||||
page,
|
||||
}) => {
|
||||
const other = await seedMockAgentWorkspace({
|
||||
repoPrefix: "waiting-status-other-",
|
||||
title: "Other agent",
|
||||
initialPrompt: "Finish this turn.",
|
||||
});
|
||||
seeded.push(other);
|
||||
await other.client.waitForFinish(other.agentId, 20_000);
|
||||
await other.client.clearWorkspaceAttention(other.workspaceId);
|
||||
await openAgentRoute(page, { workspaceId: other.workspaceId, agentId: other.agentId });
|
||||
|
||||
// The command's timer starts when the agent is seeded, so seed it once the app is open.
|
||||
const subject = await seedBackgroundShellAgent("Row subject");
|
||||
seeded.push(subject);
|
||||
const row = workspaceRow(page, subject.workspaceId);
|
||||
|
||||
await expect(row.getByTestId("workspace-status-indicator-waiting")).toBeVisible({
|
||||
timeout: 30_000,
|
||||
});
|
||||
const waitingHeight = await rowHeight(page, subject.workspaceId);
|
||||
|
||||
await expect(row.getByTestId("workspace-status-indicator-attention")).toBeVisible({
|
||||
timeout: BACKGROUND_COMMAND_MS + 15_000,
|
||||
});
|
||||
expect(await rowHeight(page, subject.workspaceId)).toBe(waitingHeight);
|
||||
});
|
||||
|
||||
test("status grouping files the row under Waiting, then under Ready to review", async ({
|
||||
page,
|
||||
}) => {
|
||||
const other = await seedMockAgentWorkspace({
|
||||
repoPrefix: "waiting-status-other-",
|
||||
title: "Other agent",
|
||||
initialPrompt: "Finish this turn.",
|
||||
});
|
||||
seeded.push(other);
|
||||
await other.client.waitForFinish(other.agentId, 20_000);
|
||||
await other.client.clearWorkspaceAttention(other.workspaceId);
|
||||
await openAgentRoute(page, { workspaceId: other.workspaceId, agentId: other.agentId });
|
||||
await selectSidebarStatusGrouping(page);
|
||||
|
||||
const subject = await seedBackgroundShellAgent("Grouped subject");
|
||||
seeded.push(subject);
|
||||
const rowTestId = `sidebar-workspace-row-${getServerId()}:${subject.workspaceId}`;
|
||||
const group = (bucket: string) => page.getByTestId(`sidebar-status-group-rows-${bucket}`);
|
||||
|
||||
await expect(group("waiting").getByTestId(rowTestId)).toBeVisible({ timeout: 30_000 });
|
||||
await expect(page.getByTestId("sidebar-status-group-waiting")).toContainText("Waiting");
|
||||
await expect(group("running").getByTestId(rowTestId)).toHaveCount(0);
|
||||
|
||||
await expect(group("attention").getByTestId(rowTestId)).toBeVisible({
|
||||
timeout: BACKGROUND_COMMAND_MS + 15_000,
|
||||
});
|
||||
await expect(group("waiting").getByTestId(rowTestId)).toHaveCount(0);
|
||||
});
|
||||
|
||||
test("the subagent pill counts a child that only waits on background work as waiting", async ({
|
||||
page,
|
||||
}) => {
|
||||
const workspace = await seedWorkspace({ repoPrefix: "waiting-status-pill-" });
|
||||
try {
|
||||
const agents = await seedParentWithSubagent(workspace, {
|
||||
parentTitle: "Pill parent",
|
||||
childTitle: "Working child",
|
||||
});
|
||||
const waitingChild = await seedSubagent(workspace, {
|
||||
parentId: agents.parent.id,
|
||||
title: "Waiting child",
|
||||
});
|
||||
await workspace.client.sendAgentMessage(
|
||||
agents.child.id,
|
||||
"Please hold a running shell tool call for 90000ms.",
|
||||
);
|
||||
await workspace.client.sendAgentMessage(
|
||||
waitingChild.id,
|
||||
"Please start a background shell command for 90000ms.",
|
||||
);
|
||||
await openAgentRoute(page, { workspaceId: agents.workspaceId, agentId: agents.parent.id });
|
||||
|
||||
const pill = page.getByTestId("subagents-track-header");
|
||||
await expect(pill).toContainText("1 working", { timeout: 30_000 });
|
||||
await expect(pill).toContainText("1 waiting");
|
||||
await expect(pill.getByTestId("status-waiting-ring")).toHaveCount(1);
|
||||
} finally {
|
||||
await workspace.cleanup();
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -290,6 +290,38 @@ export async function selectSidebarStatusGrouping(page: Page): Promise<void> {
|
||||
await page.getByTestId("sidebar-grouping-status").click();
|
||||
}
|
||||
|
||||
export type SidebarGrouping = "project" | "status" | "none";
|
||||
export type SidebarSortChoice = "manual" | "created" | "lastPrompt" | "statusChange";
|
||||
|
||||
export async function selectSidebarGrouping(page: Page, grouping: SidebarGrouping): Promise<void> {
|
||||
await openSidebarDisplayPage(page, "sidebar-display-grouping");
|
||||
await page.getByTestId(`sidebar-grouping-${grouping}`).click();
|
||||
}
|
||||
|
||||
export async function selectSidebarSort(page: Page, sort: SidebarSortChoice): Promise<void> {
|
||||
await openSidebarDisplayPage(page, "sidebar-display-sort");
|
||||
await page.getByTestId(`sidebar-sort-${sort}`).click();
|
||||
}
|
||||
|
||||
/** The sorts the Sort page offers, in the order it lists them. */
|
||||
export async function listOfferedSidebarSorts(page: Page): Promise<string[]> {
|
||||
await openSidebarDisplayPage(page, "sidebar-display-sort");
|
||||
const ids = await page
|
||||
.locator('[data-testid^="sidebar-sort-"]')
|
||||
.evaluateAll((elements) => elements.map((element) => element.getAttribute("data-testid")));
|
||||
await closeSidebarDisplayPreferences(page);
|
||||
return ids.map((id) => (id ?? "").replace("sidebar-sort-", ""));
|
||||
}
|
||||
|
||||
/** What the Sort row on the menu's first page currently reads, or null when there is no row. */
|
||||
export async function readSidebarSortValue(page: Page): Promise<string | null> {
|
||||
await page.getByTestId("sidebar-display-preferences-menu").click();
|
||||
const row = page.getByTestId("sidebar-display-sort");
|
||||
const text = (await row.count()) === 0 ? null : await row.innerText();
|
||||
await closeSidebarDisplayPreferences(page);
|
||||
return text;
|
||||
}
|
||||
|
||||
export async function openMobileAgentSidebar(page: Page): Promise<void> {
|
||||
await page.getByRole("button", { name: "Open menu" }).click();
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ export function buildAgentDescriptor(input: {
|
||||
return {
|
||||
label: label ?? "",
|
||||
subtitle:
|
||||
statusBucket === "running" && !input.isTurnActive && input.status !== "running"
|
||||
statusBucket === "waiting"
|
||||
? i18n.t("message.backgroundWork.running")
|
||||
: `${formatProviderLabel(provider)} agent`,
|
||||
tooltip: label ?? `${formatProviderLabel(provider)} agent`,
|
||||
|
||||
@@ -18,9 +18,12 @@ function kindKey(kind: string): "shell" | "monitor" | "heartbeat" | "other" {
|
||||
export function BackgroundWorkTrack({
|
||||
model,
|
||||
count,
|
||||
bucket,
|
||||
}: {
|
||||
model: ReturnType<typeof createHostBackgroundWorkModel>;
|
||||
count: number;
|
||||
/** `running` while the agent's turn runs; `waiting` once only its background work is alive. */
|
||||
bucket: "running" | "waiting";
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
const { items, status, stops } = useSyncExternalStore(
|
||||
@@ -40,7 +43,7 @@ export function BackgroundWorkTrack({
|
||||
panelTitle={t("message.backgroundWork.title")}
|
||||
segments={[
|
||||
{
|
||||
bucket: "running",
|
||||
bucket,
|
||||
text:
|
||||
visibleCount === 1
|
||||
? t("message.backgroundWork.pillOne")
|
||||
|
||||
@@ -17,6 +17,7 @@ import Clock from "lucide-react-native/icons/clock";
|
||||
import Diff from "lucide-react-native/icons/diff";
|
||||
import EyeOff from "lucide-react-native/icons/eye-off";
|
||||
import Folder from "lucide-react-native/icons/folder";
|
||||
import List from "lucide-react-native/icons/list";
|
||||
import GitBranch from "lucide-react-native/icons/git-branch";
|
||||
import GitPullRequest from "lucide-react-native/icons/git-pull-request";
|
||||
import Globe from "lucide-react-native/icons/globe";
|
||||
@@ -50,6 +51,12 @@ import {
|
||||
} from "@/stores/sidebar-view-store";
|
||||
import { workspaceLabelKey, type WorkspaceLabelColor } from "@getpaseo/protocol/workspace-labels";
|
||||
import type { WorkspaceTitleSource } from "@/hooks/use-settings";
|
||||
import {
|
||||
offeredSidebarSorts,
|
||||
resolveSidebarSort,
|
||||
sortNeedsHostSortTimes,
|
||||
type SidebarSort,
|
||||
} from "../sidebar-sort";
|
||||
import { SIDEBAR_CHECKS_DISPLAYS, type SidebarChecksDisplay } from "./checks-display";
|
||||
import { useSidebarDisplayPreferences, type SidebarTrailingChoice } from "./model";
|
||||
import { SIDEBAR_ROW_ITEMS, type SidebarRowItem } from "./row-items";
|
||||
@@ -90,6 +97,7 @@ type OptionIcon = ComponentType<{
|
||||
const GROUPING_ICONS: Record<SidebarGroupMode, OptionIcon> = {
|
||||
project: withUnistyles(Folder),
|
||||
status: withUnistyles(CircleDashed),
|
||||
none: withUnistyles(List),
|
||||
};
|
||||
|
||||
const TITLE_SOURCE_ICONS: Record<WorkspaceTitleSource, OptionIcon> = {
|
||||
@@ -121,13 +129,21 @@ const TRAILING_ICONS: Record<SidebarTrailingChoice, OptionIcon> = {
|
||||
timestamp: withUnistyles(Clock),
|
||||
};
|
||||
|
||||
const GROUPING_MODES: readonly SidebarGroupMode[] = ["project", "status"];
|
||||
const GROUPING_MODES: readonly SidebarGroupMode[] = ["project", "status", "none"];
|
||||
const TITLE_SOURCES: readonly WorkspaceTitleSource[] = ["title", "branch"];
|
||||
const TRAILING_CHOICES: readonly SidebarTrailingChoice[] = ["diff", "timestamp"];
|
||||
|
||||
const GROUPING_LABEL_KEYS: Record<SidebarGroupMode, string> = {
|
||||
project: "sidebar.display.grouping.project",
|
||||
status: "sidebar.display.grouping.status",
|
||||
none: "sidebar.display.grouping.none",
|
||||
};
|
||||
|
||||
const SORT_LABEL_KEYS: Record<SidebarSort, string> = {
|
||||
manual: "sidebar.display.sort.manual",
|
||||
created: "sidebar.display.sort.created",
|
||||
lastPrompt: "sidebar.display.sort.lastPrompt",
|
||||
statusChange: "sidebar.display.sort.statusChange",
|
||||
};
|
||||
|
||||
const TITLE_SOURCE_LABEL_KEYS: Record<WorkspaceTitleSource, string> = {
|
||||
@@ -182,6 +198,7 @@ export function SidebarDisplayPreferencesMenu(): ReactElement {
|
||||
[],
|
||||
);
|
||||
|
||||
const sortChoice = resolveSidebarSort(preferences.grouping, preferences.workspaceSort);
|
||||
const showHostFilter = hosts.length > 1;
|
||||
// One project is the whole sidebar, so filtering to it is a no-op with a menu row attached.
|
||||
const showProjectFilter = allProjects.length > 1;
|
||||
@@ -241,12 +258,17 @@ export function SidebarDisplayPreferencesMenu(): ReactElement {
|
||||
},
|
||||
];
|
||||
|
||||
if (preferences.grouping === "project") {
|
||||
if (sortChoice !== null) {
|
||||
definitions.push({
|
||||
id: "sort",
|
||||
title: t("sidebar.display.sort.label"),
|
||||
content: (
|
||||
<SortPage preferences={preferences} automaticSortSupported={workspaceSortSupported} />
|
||||
<SortPage
|
||||
grouping={preferences.grouping}
|
||||
selectedSort={sortChoice}
|
||||
onSelect={preferences.setWorkspaceSort}
|
||||
hostSortTimesSupported={workspaceSortSupported}
|
||||
/>
|
||||
),
|
||||
});
|
||||
}
|
||||
@@ -284,6 +306,7 @@ export function SidebarDisplayPreferencesMenu(): ReactElement {
|
||||
}, [
|
||||
t,
|
||||
preferences,
|
||||
sortChoice,
|
||||
workspaceSortSupported,
|
||||
hosts,
|
||||
showHostFilter,
|
||||
@@ -324,14 +347,15 @@ export function SidebarDisplayPreferencesMenu(): ReactElement {
|
||||
>
|
||||
{t("sidebar.display.grouping.label")}
|
||||
</MenuSubTrigger>
|
||||
{preferences.grouping === "project" ? (
|
||||
{sortChoice !== null ? (
|
||||
<MenuSubTrigger
|
||||
id="sort"
|
||||
value={
|
||||
workspaceSortSupported || preferences.workspaceSort === "manual"
|
||||
? t(`sidebar.display.sort.${preferences.workspaceSort}`)
|
||||
workspaceSortSupported || !sortNeedsHostSortTimes(sortChoice)
|
||||
? t(SORT_LABEL_KEYS[sortChoice])
|
||||
: undefined
|
||||
}
|
||||
testID="sidebar-display-sort"
|
||||
>
|
||||
{t("sidebar.display.sort.label")}
|
||||
</MenuSubTrigger>
|
||||
@@ -403,38 +427,61 @@ export function SidebarDisplayPreferencesMenu(): ReactElement {
|
||||
}
|
||||
|
||||
function SortPage({
|
||||
preferences,
|
||||
automaticSortSupported,
|
||||
grouping,
|
||||
selectedSort,
|
||||
onSelect,
|
||||
hostSortTimesSupported,
|
||||
}: {
|
||||
preferences: Preferences;
|
||||
automaticSortSupported: boolean;
|
||||
}): ReactElement {
|
||||
grouping: SidebarGroupMode;
|
||||
selectedSort: SidebarSort;
|
||||
onSelect: (sort: SidebarSort) => void;
|
||||
hostSortTimesSupported: boolean;
|
||||
}): ReactNode {
|
||||
const { t } = useTranslation();
|
||||
const { setWorkspaceSort } = preferences;
|
||||
const selectManual = useCallback(() => setWorkspaceSort("manual"), [setWorkspaceSort]);
|
||||
const selectCreated = useCallback(() => setWorkspaceSort("created"), [setWorkspaceSort]);
|
||||
const selectLastPrompt = useCallback(() => setWorkspaceSort("lastPrompt"), [setWorkspaceSort]);
|
||||
const items: ReactElement[] = [];
|
||||
let updateHostShown = false;
|
||||
for (const sort of offeredSidebarSorts(grouping)) {
|
||||
if (sortNeedsHostSortTimes(sort) && !hostSortTimesSupported) {
|
||||
// One row stands in for every sort this host cannot do.
|
||||
if (!updateHostShown) {
|
||||
items.push(
|
||||
<MenuItem key="updateHost" disabled>
|
||||
{t("sidebar.display.sort.updateHost")}
|
||||
</MenuItem>,
|
||||
);
|
||||
updateHostShown = true;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
items.push(
|
||||
<SortOption
|
||||
key={sort}
|
||||
sort={sort}
|
||||
selected={sort === selectedSort}
|
||||
onSelect={onSelect}
|
||||
label={t(SORT_LABEL_KEYS[sort])}
|
||||
/>,
|
||||
);
|
||||
}
|
||||
return items;
|
||||
}
|
||||
|
||||
function SortOption({
|
||||
sort,
|
||||
selected,
|
||||
onSelect,
|
||||
label,
|
||||
}: {
|
||||
sort: SidebarSort;
|
||||
selected: boolean;
|
||||
onSelect: (sort: SidebarSort) => void;
|
||||
label: string;
|
||||
}): ReactElement {
|
||||
const handleSelect = useCallback(() => onSelect(sort), [onSelect, sort]);
|
||||
return (
|
||||
<>
|
||||
<MenuItem selected={preferences.workspaceSort === "manual"} onSelect={selectManual}>
|
||||
{t("sidebar.display.sort.manual")}
|
||||
</MenuItem>
|
||||
{automaticSortSupported ? (
|
||||
<>
|
||||
<MenuItem selected={preferences.workspaceSort === "created"} onSelect={selectCreated}>
|
||||
{t("sidebar.display.sort.created")}
|
||||
</MenuItem>
|
||||
<MenuItem
|
||||
selected={preferences.workspaceSort === "lastPrompt"}
|
||||
onSelect={selectLastPrompt}
|
||||
>
|
||||
{t("sidebar.display.sort.lastPrompt")}
|
||||
</MenuItem>
|
||||
</>
|
||||
) : (
|
||||
<MenuItem disabled>{t("sidebar.display.sort.updateHost")}</MenuItem>
|
||||
)}
|
||||
</>
|
||||
<MenuItem selected={selected} onSelect={handleSelect} testID={`sidebar-sort-${sort}`}>
|
||||
{label}
|
||||
</MenuItem>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { WorkspaceSort } from "@/projects/workspace-structure";
|
||||
import type { SidebarSort } from "../sidebar-sort";
|
||||
import { useCallback, useMemo } from "react";
|
||||
import {
|
||||
useAppSettings,
|
||||
@@ -26,8 +26,8 @@ export interface SidebarDisplayPreferences {
|
||||
showBackground: boolean;
|
||||
toggleBackground: () => void;
|
||||
grouping: SidebarGroupMode;
|
||||
workspaceSort: WorkspaceSort;
|
||||
setWorkspaceSort: (sort: WorkspaceSort) => void;
|
||||
workspaceSort: SidebarSort;
|
||||
setWorkspaceSort: (sort: SidebarSort) => void;
|
||||
setGrouping: (mode: SidebarGroupMode) => void;
|
||||
titleSource: WorkspaceTitleSource;
|
||||
setTitleSource: (source: WorkspaceTitleSource) => void;
|
||||
|
||||
@@ -21,6 +21,7 @@ import {
|
||||
STATUS_INDICATOR_FILLED_DOT_SIZE,
|
||||
} from "@/utils/status-indicator-geometry";
|
||||
import { StatusRing } from "@/components/status-ring";
|
||||
import { StatusWaitingRing } from "@/components/status-ring/waiting";
|
||||
import { getStatusRingOffset } from "@/components/status-ring/geometry";
|
||||
import type { SidebarSurfaceBackdrop } from "@/styles/surface-backdrop";
|
||||
|
||||
@@ -180,7 +181,7 @@ function ProjectStatusBadge({
|
||||
// Running skips the shell. The ring is wider than the 12pt shell and carries its own knockout,
|
||||
// so nesting it inside would clip it against the very thing that was meant to separate it from
|
||||
// the icon. It anchors to the same corner instead, growing around the centre the dot had.
|
||||
if (content.kind === "dot" && content.bucket === "running") {
|
||||
if (content.kind === "dot" && (content.bucket === "running" || content.bucket === "waiting")) {
|
||||
return (
|
||||
<View
|
||||
role="status"
|
||||
@@ -188,7 +189,11 @@ function ProjectStatusBadge({
|
||||
style={styles.statusRingAnchor}
|
||||
testID="project-status-badge"
|
||||
>
|
||||
<StatusRing backdrop={backdrop} />
|
||||
{content.bucket === "waiting" ? (
|
||||
<StatusWaitingRing backdrop={backdrop} />
|
||||
) : (
|
||||
<StatusRing backdrop={backdrop} />
|
||||
)}
|
||||
</View>
|
||||
);
|
||||
}
|
||||
@@ -257,7 +262,7 @@ function ProjectInlineChevron({ chevron }: { chevron: "expand" | "collapse" | nu
|
||||
|
||||
function getStatusDotColorStyle(bucket: ProjectStatusBadgeDotBucket): ViewStyle {
|
||||
if (bucket === "failed") return styles.statusDotFailed;
|
||||
if (bucket === "running") return styles.statusDotRunning;
|
||||
if (bucket === "running" || bucket === "waiting") return styles.statusDotRunning;
|
||||
return styles.statusDotAttention;
|
||||
}
|
||||
|
||||
|
||||
@@ -26,6 +26,8 @@ function workspace(
|
||||
currentBranch: "main",
|
||||
statusBucket: "done",
|
||||
statusEnteredAt: null,
|
||||
createdAt: null,
|
||||
lastUserMessageAt: null,
|
||||
archivingAt: null,
|
||||
diffStat: null,
|
||||
prHint: null,
|
||||
|
||||
@@ -7,7 +7,8 @@ export interface SidebarWorkspaceGroup {
|
||||
key: string;
|
||||
label: string;
|
||||
rows: SidebarWorkspaceEntry[];
|
||||
leading: { kind: "status"; bucket: StatusBucket };
|
||||
/** The header's icon. Null is a group with no header, whose rows cannot be collapsed. */
|
||||
leading: { kind: "status"; bucket: StatusBucket } | null;
|
||||
}
|
||||
|
||||
export function statusWorkspaceGroups(groups: readonly StatusGroup[]): SidebarWorkspaceGroup[] {
|
||||
|
||||
@@ -62,6 +62,7 @@ export function SidebarModelProvider({
|
||||
const list = useSidebarWorkspacesList({ enabled: modelActive });
|
||||
const showBackground = useSidebarViewStore((state) => state.showBackground);
|
||||
const groupMode = useSidebarViewStore((state) => state.groupMode);
|
||||
const workspaceSort = useSidebarViewStore((state) => state.workspaceSort);
|
||||
const labelFilter = useSidebarViewStore((state) => state.labelFilter);
|
||||
const projectFilters = useSidebarViewStore((state) => state.projectFilters);
|
||||
const reconcileLabelFilter = useSidebarViewStore((state) => state.reconcileLabelFilter);
|
||||
@@ -160,6 +161,8 @@ export function SidebarModelProvider({
|
||||
workspaceEntriesByKey: filteredWorkspaceEntriesByKey,
|
||||
projectNamesByViewKey: list.projectNamesByViewKey,
|
||||
groupMode,
|
||||
workspaceSort,
|
||||
workspaceSortSupported: list.workspaceSortSupported,
|
||||
pinnedCollapsed,
|
||||
collapsedProjectKeys,
|
||||
collapsedWorkspaceGroupKeys,
|
||||
@@ -169,6 +172,8 @@ export function SidebarModelProvider({
|
||||
collapsedProjectKeys,
|
||||
collapsedWorkspaceGroupKeys,
|
||||
groupMode,
|
||||
workspaceSort,
|
||||
list.workspaceSortSupported,
|
||||
list.projectNamesByViewKey,
|
||||
filteredProjects,
|
||||
pinnedCollapsed,
|
||||
|
||||
@@ -21,6 +21,8 @@ function workspace(workspaceId: string, projectViewKey: string): SidebarWorkspac
|
||||
currentBranch: "main",
|
||||
statusBucket: "done",
|
||||
statusEnteredAt: null,
|
||||
createdAt: null,
|
||||
lastUserMessageAt: null,
|
||||
archivingAt: null,
|
||||
diffStat: null,
|
||||
prHint: null,
|
||||
|
||||
@@ -6,6 +6,7 @@ import type {
|
||||
SidebarWorkspacePlacement,
|
||||
} from "@/hooks/use-sidebar-workspaces-list";
|
||||
import { buildSidebarProjection } from "./sidebar-projection";
|
||||
import type { SidebarSort } from "./sidebar-sort";
|
||||
|
||||
function makeWorkspace(
|
||||
id: string,
|
||||
@@ -31,6 +32,8 @@ function makeWorkspace(
|
||||
currentBranch: null,
|
||||
statusBucket,
|
||||
statusEnteredAt: null,
|
||||
createdAt: null,
|
||||
lastUserMessageAt: null,
|
||||
archivingAt: null,
|
||||
diffStat: null,
|
||||
prHint: null,
|
||||
@@ -65,7 +68,8 @@ function makeProject(
|
||||
}
|
||||
|
||||
function projectionInput(options?: {
|
||||
groupMode?: "project" | "status";
|
||||
groupMode?: "project" | "status" | "none";
|
||||
workspaceSort?: SidebarSort;
|
||||
pinnedCollapsed?: boolean;
|
||||
}) {
|
||||
const pinned = makeWorkspace("pinned", "running");
|
||||
@@ -83,6 +87,8 @@ function projectionInput(options?: {
|
||||
]),
|
||||
projectNamesByViewKey: new Map([["project", "Project"]]),
|
||||
groupMode: options?.groupMode ?? ("project" as const),
|
||||
workspaceSort: options?.workspaceSort ?? ("created" as const),
|
||||
workspaceSortSupported: true,
|
||||
pinnedCollapsed: options?.pinnedCollapsed ?? false,
|
||||
collapsedProjectKeys: new Set<string>(),
|
||||
collapsedWorkspaceGroupKeys: new Set<string>(),
|
||||
@@ -94,7 +100,7 @@ function projectionInput(options?: {
|
||||
* Two projects, one workspace each, both labelled — so every grouping mode puts rows from more
|
||||
* than one project on screen, and a mode that asked for fewer icons than it renders would show it.
|
||||
*/
|
||||
function twoProjectInput(groupMode: "project" | "status") {
|
||||
function twoProjectInput(groupMode: "project" | "status" | "none") {
|
||||
const first = makeWorkspace("first", "running", ["Urgent"], "project");
|
||||
const second = makeWorkspace("second", "needs_input", ["Backend"], "other-project");
|
||||
return {
|
||||
@@ -112,10 +118,14 @@ function twoProjectInput(groupMode: "project" | "status") {
|
||||
};
|
||||
}
|
||||
|
||||
function rowIds(rows: readonly { workspaceId: string }[] | undefined): string[] {
|
||||
return (rows ?? []).map((entry) => entry.workspaceId);
|
||||
}
|
||||
|
||||
describe("buildSidebarProjection", () => {
|
||||
// The rule that outlived the bug it was written for: a project icon is fetched per project, so
|
||||
// whatever a mode groups by, the rows it produces can only reference projects already covered.
|
||||
for (const groupMode of ["project", "status"] as const) {
|
||||
for (const groupMode of ["project", "status", "none"] as const) {
|
||||
it(`covers every row ${groupMode} grouping renders with a project icon target`, () => {
|
||||
const projection = buildSidebarProjection(twoProjectInput(groupMode));
|
||||
const covered = new Set(projection.projectIconTargets.map((target) => target.projectViewKey));
|
||||
@@ -157,9 +167,7 @@ describe("buildSidebarProjection", () => {
|
||||
const projection = buildSidebarProjection(projectionInput({ groupMode: "status" }));
|
||||
|
||||
expect(projection.workspaceGroups.map((group) => group.key)).toEqual(["needs_input"]);
|
||||
expect(projection.workspaceGroups[0]?.rows.map((entry) => entry.workspaceId)).toEqual([
|
||||
"unpinned",
|
||||
]);
|
||||
expect(rowIds(projection.workspaceGroups[0]?.rows)).toEqual(["unpinned"]);
|
||||
expect(projection.shortcutModel.shortcutTargets).toEqual([
|
||||
{ serverId: "srv", workspaceId: "pinned" },
|
||||
{ serverId: "srv", workspaceId: "unpinned" },
|
||||
@@ -175,4 +183,63 @@ describe("buildSidebarProjection", () => {
|
||||
{ serverId: "srv", workspaceId: "unpinned" },
|
||||
]);
|
||||
});
|
||||
describe("ungrouped", () => {
|
||||
function ungroupedInput(workspaceSort: SidebarSort) {
|
||||
const pinned = makeWorkspace("pinned", "running");
|
||||
const old = makeWorkspace("old", "done");
|
||||
const recent = makeWorkspace("recent", "done");
|
||||
old.entry.name = "alpha";
|
||||
recent.entry.name = "zulu";
|
||||
old.entry.createdAt = new Date("2026-01-01T00:00:00Z");
|
||||
old.entry.statusEnteredAt = new Date("2026-03-02T00:00:00Z");
|
||||
recent.entry.createdAt = new Date("2026-02-01T00:00:00Z");
|
||||
recent.entry.statusEnteredAt = new Date("2026-03-01T00:00:00Z");
|
||||
return {
|
||||
...projectionInput({ groupMode: "none", workspaceSort }),
|
||||
projects: [makeProject([pinned.placement, old.placement, recent.placement])],
|
||||
pinnedKeys: {
|
||||
pinnedWorkspaceKeys: [pinned.placement.workspaceKey],
|
||||
pinnedAtByKey: { [pinned.placement.workspaceKey]: "2026-07-12T12:00:00.000Z" },
|
||||
},
|
||||
workspaceEntriesByKey: new Map(
|
||||
[pinned, old, recent].map(({ entry }) => [entry.workspaceKey, entry]),
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
it("is one headerless list of the unpinned workspaces, with pinned chats above it", () => {
|
||||
const projection = buildSidebarProjection(ungroupedInput("created"));
|
||||
|
||||
expect(projection.workspaceGroups).toHaveLength(1);
|
||||
expect(projection.workspaceGroups[0]?.leading).toBeNull();
|
||||
expect(rowIds(projection.workspaceGroups[0]?.rows)).toEqual(["recent", "old"]);
|
||||
expect(rowIds(projection.pinnedGroups.pinnedChats)).toEqual(["pinned"]);
|
||||
expect(projection.shortcutModel.shortcutTargets).toEqual([
|
||||
{ serverId: "srv", workspaceId: "pinned" },
|
||||
{ serverId: "srv", workspaceId: "recent" },
|
||||
{ serverId: "srv", workspaceId: "old" },
|
||||
]);
|
||||
});
|
||||
|
||||
it("orders the list by the stored sort", () => {
|
||||
const byStatusChange = buildSidebarProjection(ungroupedInput("statusChange"));
|
||||
|
||||
expect(rowIds(byStatusChange.workspaceGroups[0]?.rows)).toEqual(["old", "recent"]);
|
||||
});
|
||||
|
||||
it("orders by name when a host cannot supply the sort times", () => {
|
||||
const projection = buildSidebarProjection({
|
||||
...ungroupedInput("created"),
|
||||
workspaceSortSupported: false,
|
||||
});
|
||||
|
||||
expect(rowIds(projection.workspaceGroups[0]?.rows)).toEqual(["old", "recent"]);
|
||||
});
|
||||
|
||||
it("reads a stored sort this grouping does not offer as Created", () => {
|
||||
const projection = buildSidebarProjection(ungroupedInput("manual"));
|
||||
|
||||
expect(rowIds(projection.workspaceGroups[0]?.rows)).toEqual(["recent", "old"]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import type { TFunction } from "i18next";
|
||||
import { buildStatusGroups } from "@/hooks/sidebar-status-view-model";
|
||||
import { sortUngroupedWorkspaces } from "@/hooks/sidebar-ungrouped-view-model";
|
||||
import {
|
||||
splitPinnedSidebarGroups,
|
||||
type PinnedSidebarGroups,
|
||||
@@ -20,6 +21,9 @@ import {
|
||||
type SidebarShortcutSection,
|
||||
} from "@/utils/sidebar-shortcuts";
|
||||
import { statusWorkspaceGroups, type SidebarWorkspaceGroup } from "./sidebar-labels";
|
||||
import { resolveUngroupedSortForHosts, type SidebarSort } from "./sidebar-sort";
|
||||
|
||||
const UNGROUPED_GROUP_KEY = "all";
|
||||
|
||||
export interface SidebarProjection {
|
||||
pinnedGroups: PinnedSidebarGroups;
|
||||
@@ -43,6 +47,9 @@ export interface SidebarProjectionInput {
|
||||
workspaceEntriesByKey: ReadonlyMap<string, SidebarWorkspaceEntry>;
|
||||
projectNamesByViewKey: Map<string, string>;
|
||||
groupMode: SidebarGroupMode;
|
||||
workspaceSort: SidebarSort;
|
||||
/** False when a host predates the Created and Last prompt times. */
|
||||
workspaceSortSupported: boolean;
|
||||
pinnedCollapsed: boolean;
|
||||
collapsedProjectKeys: ReadonlySet<string>;
|
||||
collapsedWorkspaceGroupKeys: ReadonlySet<string>;
|
||||
@@ -79,7 +86,8 @@ export function buildSidebarProjection(input: SidebarProjectionInput): SidebarPr
|
||||
sections.push(
|
||||
...workspaceGroups.map((group) => ({
|
||||
workspaces: group.rows,
|
||||
collapsed: input.collapsedWorkspaceGroupKeys.has(group.key),
|
||||
// A headerless group has no control to collapse it.
|
||||
collapsed: group.leading !== null && input.collapsedWorkspaceGroupKeys.has(group.key),
|
||||
})),
|
||||
);
|
||||
}
|
||||
@@ -92,7 +100,10 @@ export function buildSidebarProjection(input: SidebarProjectionInput): SidebarPr
|
||||
};
|
||||
}
|
||||
|
||||
/** Project mode keeps its project headers and groups nothing; status mode groups the rows. */
|
||||
/**
|
||||
* Project mode keeps its project headers and groups nothing; status mode groups the rows; no
|
||||
* grouping puts every row in one group that has no header.
|
||||
*/
|
||||
function buildWorkspaceGroups(
|
||||
input: SidebarProjectionInput,
|
||||
unpinnedWorkspaces: SidebarWorkspaceEntry[],
|
||||
@@ -104,5 +115,20 @@ function buildWorkspaceGroups(
|
||||
return statusWorkspaceGroups(
|
||||
buildStatusGroups(unpinnedWorkspaces, input.projectNamesByViewKey, input.t),
|
||||
);
|
||||
case "none":
|
||||
return unpinnedWorkspaces.length === 0
|
||||
? []
|
||||
: [
|
||||
{
|
||||
key: UNGROUPED_GROUP_KEY,
|
||||
label: "",
|
||||
rows: sortUngroupedWorkspaces(
|
||||
unpinnedWorkspaces,
|
||||
resolveUngroupedSortForHosts(input.workspaceSort, input.workspaceSortSupported),
|
||||
input.projectNamesByViewKey,
|
||||
),
|
||||
leading: null,
|
||||
},
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
offeredSidebarSorts,
|
||||
resolveProjectSort,
|
||||
resolveSidebarSort,
|
||||
resolveUngroupedSortForHosts,
|
||||
resolveUngroupedSort,
|
||||
} from "./sidebar-sort";
|
||||
|
||||
describe("sidebar sort", () => {
|
||||
it("offers each grouping its own sorts", () => {
|
||||
expect(offeredSidebarSorts("project")).toEqual(["manual", "created", "lastPrompt"]);
|
||||
expect(offeredSidebarSorts("status")).toEqual([]);
|
||||
expect(offeredSidebarSorts("none")).toEqual(["created", "lastPrompt", "statusChange"]);
|
||||
});
|
||||
|
||||
it("shows Created for a stored sort the grouping does not offer", () => {
|
||||
expect(resolveProjectSort("statusChange")).toBe("created");
|
||||
expect(resolveUngroupedSort("manual")).toBe("created");
|
||||
});
|
||||
|
||||
it("keeps a stored sort the grouping offers", () => {
|
||||
expect(resolveProjectSort("manual")).toBe("manual");
|
||||
expect(resolveProjectSort("lastPrompt")).toBe("lastPrompt");
|
||||
expect(resolveUngroupedSort("statusChange")).toBe("statusChange");
|
||||
expect(resolveUngroupedSort("lastPrompt")).toBe("lastPrompt");
|
||||
});
|
||||
|
||||
it("resolves no sort for status grouping", () => {
|
||||
expect(resolveSidebarSort("status", "lastPrompt")).toBeNull();
|
||||
expect(resolveSidebarSort("none", "manual")).toBe("created");
|
||||
expect(resolveSidebarSort("project", "statusChange")).toBe("created");
|
||||
});
|
||||
|
||||
it("gives the flat list no sort when its time sort needs times the hosts do not send", () => {
|
||||
expect(resolveUngroupedSortForHosts("created", false)).toBeUndefined();
|
||||
expect(resolveUngroupedSortForHosts("manual", false)).toBeUndefined();
|
||||
expect(resolveUngroupedSortForHosts("lastPrompt", false)).toBeUndefined();
|
||||
expect(resolveUngroupedSortForHosts("statusChange", false)).toBe("statusChange");
|
||||
expect(resolveUngroupedSortForHosts("created", true)).toBe("created");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,75 @@
|
||||
import type { WorkspaceSort } from "@/projects/workspace-structure";
|
||||
import type { SidebarGroupMode } from "@/stores/sidebar-view-store";
|
||||
|
||||
/**
|
||||
* The stored Sort value. One field serves every grouping, and each grouping offers some of its
|
||||
* values: Manual only makes sense under project headers, Status change only without them.
|
||||
*/
|
||||
export type SidebarSort = WorkspaceSort | "statusChange";
|
||||
|
||||
export type UngroupedSort = Exclude<SidebarSort, "manual">;
|
||||
|
||||
const PROJECT_SORTS = [
|
||||
"manual",
|
||||
"created",
|
||||
"lastPrompt",
|
||||
] as const satisfies readonly WorkspaceSort[];
|
||||
const UNGROUPED_SORTS = [
|
||||
"created",
|
||||
"lastPrompt",
|
||||
"statusChange",
|
||||
] as const satisfies readonly UngroupedSort[];
|
||||
|
||||
const OFFERED_SORTS: Record<SidebarGroupMode, readonly SidebarSort[]> = {
|
||||
project: PROJECT_SORTS,
|
||||
// Status grouping has one fixed order, so it offers no choice.
|
||||
status: [],
|
||||
none: UNGROUPED_SORTS,
|
||||
};
|
||||
|
||||
export function offeredSidebarSorts(mode: SidebarGroupMode): readonly SidebarSort[] {
|
||||
return OFFERED_SORTS[mode];
|
||||
}
|
||||
|
||||
/**
|
||||
* What a grouping displays for the stored sort. A value the grouping does not offer reads as
|
||||
* Created, and the stored value is left alone so switching back restores it.
|
||||
*/
|
||||
export function resolveProjectSort(stored: SidebarSort): WorkspaceSort {
|
||||
return PROJECT_SORTS.find((sort) => sort === stored) ?? "created";
|
||||
}
|
||||
|
||||
export function resolveUngroupedSort(stored: SidebarSort): UngroupedSort {
|
||||
return UNGROUPED_SORTS.find((sort) => sort === stored) ?? "created";
|
||||
}
|
||||
|
||||
/** What the Sort row shows for a grouping, or null when the grouping offers no choice. */
|
||||
export function resolveSidebarSort(
|
||||
mode: SidebarGroupMode,
|
||||
stored: SidebarSort,
|
||||
): SidebarSort | null {
|
||||
if (mode === "project") return resolveProjectSort(stored);
|
||||
if (mode === "none") return resolveUngroupedSort(stored);
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Created and Last prompt read times that only hosts from v0.13.0 send, so they cannot order a
|
||||
* list on an older host. Manual and Status change need nothing newer.
|
||||
*/
|
||||
export function sortNeedsHostSortTimes(sort: SidebarSort): boolean {
|
||||
return sort === "created" || sort === "lastPrompt";
|
||||
}
|
||||
|
||||
/**
|
||||
* The sort the flat list orders by, or undefined when it has none to apply: a time sort needs
|
||||
* times the host sends, and a host that predates them has none to order by. Project grouping falls
|
||||
* back to name order the same way, and the menu offers no matching choice either.
|
||||
*/
|
||||
export function resolveUngroupedSortForHosts(
|
||||
stored: SidebarSort,
|
||||
hostSortTimesSupported: boolean,
|
||||
): UngroupedSort | undefined {
|
||||
const sort = resolveUngroupedSort(stored);
|
||||
return sortNeedsHostSortTimes(sort) && !hostSortTimesSupported ? undefined : sort;
|
||||
}
|
||||
@@ -34,6 +34,7 @@ import ChevronDown from "lucide-react-native/icons/chevron-down";
|
||||
import ChevronRight from "lucide-react-native/icons/chevron-right";
|
||||
import CircleAlert from "lucide-react-native/icons/circle-alert";
|
||||
import CircleCheck from "lucide-react-native/icons/circle-check";
|
||||
import CircleDashed from "lucide-react-native/icons/circle-dashed";
|
||||
import CircleDot from "lucide-react-native/icons/circle-dot";
|
||||
import CircleX from "lucide-react-native/icons/circle-x";
|
||||
import { useToast } from "@/contexts/toast-context";
|
||||
@@ -103,11 +104,15 @@ const attentionGroupIconProps = densityIconProps("sm", (theme) => ({
|
||||
const runningGroupIconProps = densityIconProps("sm", (theme) => ({
|
||||
color: getStatusDotColor({ theme, bucket: "running" }) ?? undefined,
|
||||
}));
|
||||
const waitingGroupIconProps = densityIconProps("sm", (theme) => ({
|
||||
color: getStatusDotColor({ theme, bucket: "waiting" }) ?? undefined,
|
||||
}));
|
||||
|
||||
const ThemedChevronDown = withUnistyles(ChevronDown);
|
||||
const ThemedChevronRight = withUnistyles(ChevronRight);
|
||||
const ThemedCircleAlert = withUnistyles(CircleAlert);
|
||||
const ThemedCircleCheck = withUnistyles(CircleCheck);
|
||||
const ThemedCircleDashed = withUnistyles(CircleDashed);
|
||||
const ThemedCircleDot = withUnistyles(CircleDot);
|
||||
const ThemedCircleX = withUnistyles(CircleX);
|
||||
const EMPTY_SHORTCUT_INDEX = new Map<string, number>();
|
||||
@@ -214,7 +219,9 @@ export function SidebarStatusWorkspaceList({
|
||||
}
|
||||
}
|
||||
for (const group of current.groups) {
|
||||
if (current.collapsedWorkspaceGroupKeys.has(group.key) || group.rows.length === 0) {
|
||||
const collapsed =
|
||||
group.leading !== null && current.collapsedWorkspaceGroupKeys.has(group.key);
|
||||
if (collapsed || group.rows.length === 0) {
|
||||
continue;
|
||||
}
|
||||
const { leadingItem, visibleItems } = selectSidebarGroupVisibility({
|
||||
@@ -424,7 +431,7 @@ const STATUS_GROUP_VISIBILITY = {
|
||||
|
||||
function StatusGroupRows({
|
||||
group,
|
||||
collapsed,
|
||||
collapsed: collapsedByHeader,
|
||||
workspacesExpanded,
|
||||
onToggleWorkspacesExpanded,
|
||||
projectIconByProjectViewKey,
|
||||
@@ -448,6 +455,9 @@ function StatusGroupRows({
|
||||
onToggleWorkspacePin: ToggleSidebarWorkspacePin;
|
||||
}) {
|
||||
const activeWorkspaceSelection = useActiveWorkspaceSelection();
|
||||
// A group with no header has nothing to collapse it with.
|
||||
const hasHeader = group.leading !== null;
|
||||
const collapsed = hasHeader && collapsedByHeader;
|
||||
const toggleWorkspacesExpanded = useCallback(
|
||||
() => onToggleWorkspacesExpanded(group.key),
|
||||
[group.key, onToggleWorkspacesExpanded],
|
||||
@@ -484,7 +494,9 @@ function StatusGroupRows({
|
||||
|
||||
return (
|
||||
<View style={collapsed ? undefined : styles.statusGroupBlockExpanded}>
|
||||
<StatusGroupHeader group={group} collapsed={collapsed} />
|
||||
{group.leading ? (
|
||||
<StatusGroupHeader group={group} leading={group.leading} collapsed={collapsed} />
|
||||
) : null}
|
||||
{!collapsed ? (
|
||||
<View
|
||||
style={styles.statusWorkspaceListContainer}
|
||||
@@ -530,9 +542,11 @@ function buildStatusRowProjectPresentation({
|
||||
|
||||
function StatusGroupHeader({
|
||||
group,
|
||||
leading,
|
||||
collapsed,
|
||||
}: {
|
||||
group: SidebarWorkspaceGroup;
|
||||
leading: NonNullable<SidebarWorkspaceGroup["leading"]>;
|
||||
collapsed: boolean;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
@@ -565,7 +579,7 @@ function StatusGroupHeader({
|
||||
<View style={styles.statusGroupRowLeft}>
|
||||
<View style={styles.statusGroupLeadingVisualSlot}>
|
||||
<StatusGroupLeadingVisual
|
||||
leading={group.leading}
|
||||
leading={leading}
|
||||
collapsed={collapsed}
|
||||
showChevron={isHovered}
|
||||
/>
|
||||
@@ -586,7 +600,7 @@ function StatusGroupLeadingVisual({
|
||||
collapsed,
|
||||
showChevron,
|
||||
}: {
|
||||
leading: SidebarWorkspaceGroup["leading"];
|
||||
leading: NonNullable<SidebarWorkspaceGroup["leading"]>;
|
||||
collapsed: boolean;
|
||||
showChevron: boolean;
|
||||
}) {
|
||||
@@ -609,6 +623,9 @@ function StatusGroupIcon({ bucket }: { bucket: StatusBucket }) {
|
||||
return <ThemedCircleCheck uniProps={attentionGroupIconProps} />;
|
||||
case "running":
|
||||
return <ThemedCircleDot uniProps={runningGroupIconProps} />;
|
||||
case "waiting":
|
||||
// The dashed circle teaches what the dashed ring on a waiting row means.
|
||||
return <ThemedCircleDashed uniProps={waitingGroupIconProps} />;
|
||||
case "done":
|
||||
return <ThemedCircleCheck uniProps={mutedGroupIconProps} />;
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ import {
|
||||
} from "@/utils/status-indicator-geometry";
|
||||
import { shouldRenderSyncedStatusLoader } from "@/utils/status-loader";
|
||||
import { StatusRing } from "@/components/status-ring";
|
||||
import { StatusWaitingRing } from "@/components/status-ring/waiting";
|
||||
import { resolveSidebarWorkspacePrimaryLabel } from "@/components/sidebar/sidebar-workspace-title";
|
||||
import { DensityIcon } from "@/components/ui/density-icon";
|
||||
import { SCRIM_WIDTH, TrailingActionScrim } from "@/components/ui/trailing-action-scrim";
|
||||
@@ -296,6 +297,14 @@ function WorkspaceStatusIndicator({
|
||||
);
|
||||
}
|
||||
|
||||
if (bucket === "waiting") {
|
||||
return (
|
||||
<View style={styles.workspaceStatusDot} testID="workspace-status-indicator-waiting">
|
||||
<StatusWaitingRing />
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
if (bucket === "needs_input") {
|
||||
return (
|
||||
<View style={styles.workspaceStatusDot} testID="workspace-status-indicator-needs_input">
|
||||
@@ -349,6 +358,7 @@ function getStatusDotColorStyle(bucket: SidebarStateBucket) {
|
||||
case "failed":
|
||||
return styles.statusDotFailed;
|
||||
case "running":
|
||||
case "waiting":
|
||||
return styles.statusDotRunning;
|
||||
case "attention":
|
||||
return styles.statusDotAttention;
|
||||
|
||||
@@ -6,6 +6,7 @@ import type { SidebarStateBucket } from "@/utils/sidebar-agent-state";
|
||||
import type { SurfaceBackdrop } from "@/styles/surface-backdrop";
|
||||
import { getStatusDotColor } from "@/utils/status-dot-color";
|
||||
import { StatusRing } from "@/components/status-ring";
|
||||
import { StatusWaitingRing } from "@/components/status-ring/waiting";
|
||||
import { getStatusRingOffset } from "@/components/status-ring/geometry";
|
||||
import {
|
||||
STATUS_INDICATOR_ALERT_SIZE,
|
||||
@@ -37,6 +38,7 @@ export function StatusIcon({
|
||||
}: StatusIconProps): ReactElement {
|
||||
const bucket = statusBucket;
|
||||
const isRunning = bucket === "running";
|
||||
const isWaiting = bucket === "waiting";
|
||||
let statusDotColor: string | undefined;
|
||||
if (bucket === "failed") statusDotColor = styles.statusDotFailed.color;
|
||||
else if (bucket === "attention") statusDotColor = styles.statusDotAttention.color;
|
||||
@@ -68,6 +70,11 @@ export function StatusIcon({
|
||||
<StatusRing backdrop={backdrop} />
|
||||
</View>
|
||||
) : null}
|
||||
{isWaiting ? (
|
||||
<View style={styles.statusRing} accessibilityLabel="Agent waiting">
|
||||
<StatusWaitingRing backdrop={backdrop} />
|
||||
</View>
|
||||
) : null}
|
||||
{statusDotColor ? <View style={statusDotStyle} /> : null}
|
||||
{showNeedsInputAlert ? (
|
||||
<View style={styles.statusAlertOverlay}>
|
||||
|
||||
@@ -32,10 +32,23 @@ export interface StatusRingProps {
|
||||
*/
|
||||
export function StatusRingFrame({ backdrop, children }: StatusRingProps & { children: ReactNode }) {
|
||||
return (
|
||||
<View style={[styles.frame, getBackdropStyle(backdrop)]} testID="status-ring">
|
||||
<StatusMarkFrame backdrop={backdrop} testID="status-ring">
|
||||
<View style={styles.track} />
|
||||
{children}
|
||||
<View style={styles.centerDot} />
|
||||
</StatusMarkFrame>
|
||||
);
|
||||
}
|
||||
|
||||
/** The box and knockout every busy mark is drawn in, so running and waiting fill the same space. */
|
||||
export function StatusMarkFrame({
|
||||
backdrop,
|
||||
children,
|
||||
testID,
|
||||
}: StatusRingProps & { children: ReactNode; testID: string }) {
|
||||
return (
|
||||
<View style={[styles.frame, getBackdropStyle(backdrop)]} testID={testID}>
|
||||
{children}
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -27,6 +27,24 @@ export const STATUS_RING_FRAME_SIZE = STATUS_RING_SIZE + STATUS_RING_HALO_INSET
|
||||
export const STATUS_RING_TRACK_OPACITY = 0.3;
|
||||
export const STATUS_RING_HEAD_OPACITY = 0.9;
|
||||
|
||||
// The waiting mark keeps the running ring's stroke and colour but drops the dot and the motion:
|
||||
// one circle stroked with a dash pattern, so each dash is a short arc with its ends cut along the
|
||||
// radius. Nothing is in flight, so nothing turns.
|
||||
//
|
||||
// It is drawn smaller than the running ring and centred in the same frame. The frame and its
|
||||
// knockout stay the size the running ring needs, so nothing around the mark moves; the difference
|
||||
// is negative space between the ring and the icon art the knockout sits on.
|
||||
export const STATUS_WAITING_DASH_COUNT = 8;
|
||||
export const STATUS_WAITING_RING_SIZE = 10;
|
||||
export const STATUS_WAITING_RING_RADIUS = (STATUS_WAITING_RING_SIZE - STATUS_RING_STROKE) / 2;
|
||||
// A dash and the gap after it are the same length, so the 8 dashes and 8 gaps close the circle
|
||||
// with nothing left over at the start point.
|
||||
export const STATUS_WAITING_DASH_LENGTH =
|
||||
(2 * Math.PI * STATUS_WAITING_RING_RADIUS) / STATUS_WAITING_DASH_COUNT / 2;
|
||||
// A stroked circle starts at three o'clock. Half a dash short of twelve puts a dash, not a gap,
|
||||
// across the top, so the mark is symmetric about both axes.
|
||||
export const STATUS_WAITING_START_ANGLE = -90 - 360 / STATUS_WAITING_DASH_COUNT / 4;
|
||||
|
||||
// One period for every ring in the app. Each platform runs the rings off one clock that does not
|
||||
// depend on when a ring mounted, so a row that appears mid-flight lands in step with the rings
|
||||
// already turning.
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
import { memo } from "react";
|
||||
import Svg, { Circle } from "react-native-svg";
|
||||
import { withUnistyles } from "react-native-unistyles";
|
||||
import { StatusMarkFrame, type StatusRingProps } from "@/components/status-ring/frame";
|
||||
import {
|
||||
STATUS_RING_STROKE,
|
||||
STATUS_WAITING_DASH_LENGTH,
|
||||
STATUS_WAITING_RING_RADIUS,
|
||||
STATUS_WAITING_RING_SIZE,
|
||||
STATUS_WAITING_START_ANGLE,
|
||||
} from "@/components/status-ring/geometry";
|
||||
import { isNative } from "@/constants/platform";
|
||||
import type { Theme } from "@/styles/theme";
|
||||
import { getStatusDotColor } from "@/utils/status-dot-color";
|
||||
|
||||
const CENTER = STATUS_WAITING_RING_SIZE / 2;
|
||||
|
||||
// Wrap the whole SVG: withUnistyles adds a div on web, which cannot sit inside an SVG.
|
||||
const WaitingRingDashes = withUnistyles(function WaitingRingDashes({ color }: { color?: string }) {
|
||||
return (
|
||||
<Svg
|
||||
width={STATUS_WAITING_RING_SIZE}
|
||||
height={STATUS_WAITING_RING_SIZE}
|
||||
viewBox={`0 0 ${STATUS_WAITING_RING_SIZE} ${STATUS_WAITING_RING_SIZE}`}
|
||||
{...(isNative
|
||||
? { accessibilityElementsHidden: true, importantForAccessibility: "no-hide-descendants" }
|
||||
: { "aria-hidden": true })}
|
||||
>
|
||||
<Circle
|
||||
cx={CENTER}
|
||||
cy={CENTER}
|
||||
r={STATUS_WAITING_RING_RADIUS}
|
||||
fill="none"
|
||||
stroke={color}
|
||||
strokeWidth={STATUS_RING_STROKE}
|
||||
strokeLinecap="butt"
|
||||
strokeDasharray={`${STATUS_WAITING_DASH_LENGTH} ${STATUS_WAITING_DASH_LENGTH}`}
|
||||
transform={`rotate(${STATUS_WAITING_START_ANGLE} ${CENTER} ${CENTER})`}
|
||||
/>
|
||||
</Svg>
|
||||
);
|
||||
});
|
||||
|
||||
const waitingColorMapping = (theme: Theme) => ({
|
||||
color: getStatusDotColor({ theme, bucket: "waiting" }) ?? undefined,
|
||||
});
|
||||
|
||||
/**
|
||||
* The indicator for an agent that has no turn running and is waiting on something it started:
|
||||
* the running ring's frame, stroke and colour, drawn as a dashed circle (a ring of short arcs)
|
||||
* with no centre dot and no motion.
|
||||
*/
|
||||
export const StatusWaitingRing = memo(function StatusWaitingRing({ backdrop }: StatusRingProps) {
|
||||
return (
|
||||
<StatusMarkFrame backdrop={backdrop} testID="status-waiting-ring">
|
||||
<WaitingRingDashes uniProps={waitingColorMapping} />
|
||||
</StatusMarkFrame>
|
||||
);
|
||||
});
|
||||
@@ -22,6 +22,7 @@ import {
|
||||
type MenuTriggerState,
|
||||
} from "@/components/ui/menu";
|
||||
import { StatusRing } from "@/components/status-ring";
|
||||
import { StatusWaitingRing } from "@/components/status-ring/waiting";
|
||||
import { bySizing } from "@/components/ui/control-geometry";
|
||||
import {
|
||||
HorizontalScrollBoundaryShades,
|
||||
@@ -362,10 +363,17 @@ export function ComposerTrackMark({
|
||||
</View>
|
||||
);
|
||||
}
|
||||
if (bucket === "waiting") {
|
||||
return (
|
||||
<View style={styles.ringMark}>
|
||||
<StatusWaitingRing />
|
||||
</View>
|
||||
);
|
||||
}
|
||||
return <View style={dotColorStyle(bucket)} />;
|
||||
}
|
||||
|
||||
function dotColorStyle(bucket: Exclude<SidebarStateBucket, "running">) {
|
||||
function dotColorStyle(bucket: Exclude<SidebarStateBucket, "running" | "waiting">) {
|
||||
switch (bucket) {
|
||||
case "needs_input":
|
||||
return styles.dotNeedsInput;
|
||||
@@ -381,7 +389,7 @@ function dotColorStyle(bucket: Exclude<SidebarStateBucket, "running">) {
|
||||
const styles = StyleSheet.create((theme) => {
|
||||
// Colours come from the one bucket-to-colour map so the pill cannot drift from the status dots
|
||||
// everywhere else, and are baked into each variant so the style prop stays a stable object.
|
||||
const statusDot = (bucket: Exclude<SidebarStateBucket, "running">) => ({
|
||||
const statusDot = (bucket: Exclude<SidebarStateBucket, "running" | "waiting">) => ({
|
||||
width: STATUS_INDICATOR_FILLED_DOT_SIZE,
|
||||
height: STATUS_INDICATOR_FILLED_DOT_SIZE,
|
||||
borderRadius: theme.borderRadius.full,
|
||||
|
||||
@@ -27,6 +27,8 @@ function ws(
|
||||
currentBranch: input.currentBranch ?? null,
|
||||
statusBucket: input.statusBucket ?? "done",
|
||||
statusEnteredAt: input.statusEnteredAt ?? null,
|
||||
createdAt: null,
|
||||
lastUserMessageAt: null,
|
||||
archivingAt: null,
|
||||
diffStat: null,
|
||||
prHint: null,
|
||||
@@ -64,6 +66,42 @@ describe("buildStatusGroups", () => {
|
||||
expect(groups[2]?.label).toBe("Done");
|
||||
});
|
||||
|
||||
it("gives waiting workspaces their own Waiting group between Working and Done", () => {
|
||||
const workspaces = [
|
||||
ws({ workspaceKey: "srv:done-ws", statusBucket: "done", name: "done-ws" }),
|
||||
ws({ workspaceKey: "srv:waiting-ws", statusBucket: "waiting", name: "waiting-ws" }),
|
||||
ws({ workspaceKey: "srv:running-ws", statusBucket: "running", name: "running-ws" }),
|
||||
];
|
||||
|
||||
const groups = buildStatusGroups(workspaces, emptyProjectNames, i18n.t);
|
||||
|
||||
expect(groups.map((g) => g.bucket)).toEqual(["running", "waiting", "done"]);
|
||||
expect(groups.map((g) => g.label)).toEqual(["Working", "Waiting", "Done"]);
|
||||
expect(groups[0]?.rows.map((w) => w.name)).toEqual(["running-ws"]);
|
||||
expect(groups[1]?.rows.map((w) => w.name)).toEqual(["waiting-ws"]);
|
||||
});
|
||||
|
||||
it("orders waiting rows like every other group, newest entry first", () => {
|
||||
const workspaces = [
|
||||
ws({
|
||||
workspaceKey: "srv:older",
|
||||
statusBucket: "waiting",
|
||||
name: "older",
|
||||
statusEnteredAt: d("2026-01-01T10:00:00Z"),
|
||||
}),
|
||||
ws({
|
||||
workspaceKey: "srv:newer",
|
||||
statusBucket: "waiting",
|
||||
name: "newer",
|
||||
statusEnteredAt: d("2026-01-01T11:00:00Z"),
|
||||
}),
|
||||
];
|
||||
|
||||
const groups = buildStatusGroups(workspaces, emptyProjectNames, i18n.t);
|
||||
|
||||
expect(groups[0]?.rows.map((w) => w.name)).toEqual(["newer", "older"]);
|
||||
});
|
||||
|
||||
it("omits empty buckets", () => {
|
||||
const workspaces = [
|
||||
ws({ workspaceKey: "srv:a", statusBucket: "done" }),
|
||||
@@ -178,6 +216,11 @@ describe("buildStatusGroups", () => {
|
||||
statusBucket: "running",
|
||||
statusEnteredAt: d("2026-01-01T00:00:00Z"),
|
||||
}),
|
||||
ws({
|
||||
workspaceKey: "srv:wait",
|
||||
statusBucket: "waiting",
|
||||
statusEnteredAt: d("2026-01-01T00:00:00Z"),
|
||||
}),
|
||||
ws({ workspaceKey: "srv:dn", statusBucket: "done", statusEnteredAt: null }),
|
||||
];
|
||||
|
||||
@@ -241,6 +284,7 @@ describe("getStatusBucketLabel", () => {
|
||||
"Échec",
|
||||
"À relire",
|
||||
"En cours",
|
||||
"En attente",
|
||||
"Terminé",
|
||||
]);
|
||||
} finally {
|
||||
|
||||
@@ -2,6 +2,7 @@ import type { TFunction } from "i18next";
|
||||
import { STATUS_BUCKET_ORDER } from "@/utils/sidebar-agent-state";
|
||||
import type { SidebarWorkspaceEntry } from "@/hooks/sidebar-workspaces-view-model";
|
||||
|
||||
/** A group in status grouping. A row is in the group named by its own status, and no other. */
|
||||
export type StatusBucket = SidebarWorkspaceEntry["statusBucket"];
|
||||
|
||||
export { STATUS_BUCKET_ORDER };
|
||||
@@ -11,10 +12,14 @@ const STATUS_BUCKET_LABEL_KEYS = {
|
||||
failed: "sidebar.statusBucket.failed",
|
||||
attention: "sidebar.statusBucket.readyToReview",
|
||||
running: "sidebar.statusBucket.working",
|
||||
waiting: "sidebar.statusBucket.waiting",
|
||||
done: "sidebar.statusBucket.done",
|
||||
} as const satisfies Record<StatusBucket, string>;
|
||||
} as const satisfies Record<SidebarWorkspaceEntry["statusBucket"], string>;
|
||||
|
||||
export function getStatusBucketLabel(bucket: StatusBucket, t: TFunction): string {
|
||||
export function getStatusBucketLabel(
|
||||
bucket: SidebarWorkspaceEntry["statusBucket"],
|
||||
t: TFunction,
|
||||
): string {
|
||||
return t(STATUS_BUCKET_LABEL_KEYS[bucket]);
|
||||
}
|
||||
|
||||
@@ -32,7 +37,7 @@ export function buildStatusGroups(
|
||||
const bucketRows = new Map<StatusBucket, SidebarWorkspaceEntry[]>();
|
||||
|
||||
for (const ws of workspaces) {
|
||||
const bucket: StatusBucket = ws.statusBucket;
|
||||
const bucket = ws.statusBucket;
|
||||
let rows = bucketRows.get(bucket);
|
||||
if (!rows) {
|
||||
rows = [];
|
||||
@@ -54,7 +59,7 @@ export function buildStatusGroups(
|
||||
return groups;
|
||||
}
|
||||
|
||||
function compareStatusRows(
|
||||
export function compareStatusRows(
|
||||
a: SidebarWorkspaceEntry,
|
||||
b: SidebarWorkspaceEntry,
|
||||
projectNamesByViewKey: Map<string, string>,
|
||||
|
||||
@@ -0,0 +1,199 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import type { SidebarWorkspaceEntry } from "./sidebar-workspaces-view-model";
|
||||
import { sortUngroupedWorkspaces } from "./sidebar-ungrouped-view-model";
|
||||
|
||||
function ws(
|
||||
input: Partial<SidebarWorkspaceEntry> & { workspaceKey: string },
|
||||
): SidebarWorkspaceEntry {
|
||||
return {
|
||||
serverId: "srv",
|
||||
workspaceId: input.workspaceKey.split(":")[1] ?? "ws",
|
||||
projectViewKey: "proj",
|
||||
projectName: "Project",
|
||||
workspaceDirectory: "",
|
||||
workspaceDirectoryLabel: "",
|
||||
projectKind: "git",
|
||||
workspaceKind: "worktree",
|
||||
name: input.workspaceKey,
|
||||
title: null,
|
||||
currentBranch: null,
|
||||
statusBucket: "done",
|
||||
statusEnteredAt: null,
|
||||
createdAt: null,
|
||||
lastUserMessageAt: null,
|
||||
archivingAt: null,
|
||||
diffStat: null,
|
||||
prHint: null,
|
||||
archiveHasUncommittedChanges: null,
|
||||
archiveUnpushedCommitCount: null,
|
||||
scripts: [],
|
||||
hasRunningScripts: false,
|
||||
...input,
|
||||
};
|
||||
}
|
||||
|
||||
function d(iso: string): Date {
|
||||
return new Date(iso);
|
||||
}
|
||||
|
||||
function keys(rows: SidebarWorkspaceEntry[]): string[] {
|
||||
return rows.map((row) => row.workspaceKey);
|
||||
}
|
||||
|
||||
const projectNames = new Map<string, string>();
|
||||
|
||||
describe("sortUngroupedWorkspaces", () => {
|
||||
it("orders the whole list by created time, newest first, across projects", () => {
|
||||
const rows = [
|
||||
ws({ workspaceKey: "srv:old", projectViewKey: "a", createdAt: d("2026-01-01T00:00:00Z") }),
|
||||
ws({ workspaceKey: "srv:new", projectViewKey: "b", createdAt: d("2026-03-01T00:00:00Z") }),
|
||||
ws({ workspaceKey: "srv:mid", projectViewKey: "a", createdAt: d("2026-02-01T00:00:00Z") }),
|
||||
];
|
||||
|
||||
expect(keys(sortUngroupedWorkspaces(rows, "created", projectNames))).toEqual([
|
||||
"srv:new",
|
||||
"srv:mid",
|
||||
"srv:old",
|
||||
]);
|
||||
});
|
||||
|
||||
it("orders by the last prompt, falling back to created time", () => {
|
||||
const rows = [
|
||||
ws({
|
||||
workspaceKey: "srv:prompted-early",
|
||||
createdAt: d("2026-03-01T00:00:00Z"),
|
||||
lastUserMessageAt: d("2026-03-02T00:00:00Z"),
|
||||
}),
|
||||
ws({ workspaceKey: "srv:never-prompted", createdAt: d("2026-03-05T00:00:00Z") }),
|
||||
ws({
|
||||
workspaceKey: "srv:prompted-late",
|
||||
createdAt: d("2026-01-01T00:00:00Z"),
|
||||
lastUserMessageAt: d("2026-03-09T00:00:00Z"),
|
||||
}),
|
||||
];
|
||||
|
||||
expect(keys(sortUngroupedWorkspaces(rows, "lastPrompt", projectNames))).toEqual([
|
||||
"srv:prompted-late",
|
||||
"srv:never-prompted",
|
||||
"srv:prompted-early",
|
||||
]);
|
||||
});
|
||||
|
||||
it("orders by the time the status last changed, whatever the status is", () => {
|
||||
const rows = [
|
||||
ws({
|
||||
workspaceKey: "srv:done-recently",
|
||||
statusBucket: "done",
|
||||
statusEnteredAt: d("2026-03-03T00:00:00Z"),
|
||||
}),
|
||||
ws({
|
||||
workspaceKey: "srv:needs-input-long-ago",
|
||||
statusBucket: "needs_input",
|
||||
statusEnteredAt: d("2026-03-01T00:00:00Z"),
|
||||
}),
|
||||
ws({
|
||||
workspaceKey: "srv:running-now",
|
||||
statusBucket: "running",
|
||||
statusEnteredAt: d("2026-03-04T00:00:00Z"),
|
||||
}),
|
||||
ws({ workspaceKey: "srv:no-status-time", statusBucket: "done" }),
|
||||
];
|
||||
|
||||
expect(keys(sortUngroupedWorkspaces(rows, "statusChange", projectNames))).toEqual([
|
||||
"srv:running-now",
|
||||
"srv:done-recently",
|
||||
"srv:needs-input-long-ago",
|
||||
"srv:no-status-time",
|
||||
]);
|
||||
});
|
||||
|
||||
it("sorts a waiting workspace by its status time like any other status", () => {
|
||||
const rows = [
|
||||
ws({
|
||||
workspaceKey: "srv:running",
|
||||
statusBucket: "running",
|
||||
statusEnteredAt: d("2026-03-01T00:00:00Z"),
|
||||
}),
|
||||
ws({
|
||||
workspaceKey: "srv:waiting",
|
||||
statusBucket: "waiting",
|
||||
statusEnteredAt: d("2026-03-02T00:00:00Z"),
|
||||
}),
|
||||
];
|
||||
|
||||
expect(keys(sortUngroupedWorkspaces(rows, "statusChange", projectNames))).toEqual([
|
||||
"srv:waiting",
|
||||
"srv:running",
|
||||
]);
|
||||
});
|
||||
|
||||
it("moves a workspace to the top when its status changes, and leaves it when only other fields change", () => {
|
||||
const before = [
|
||||
ws({
|
||||
workspaceKey: "srv:a",
|
||||
statusBucket: "done",
|
||||
statusEnteredAt: d("2026-03-02T00:00:00Z"),
|
||||
}),
|
||||
ws({
|
||||
workspaceKey: "srv:b",
|
||||
statusBucket: "done",
|
||||
statusEnteredAt: d("2026-03-01T00:00:00Z"),
|
||||
}),
|
||||
];
|
||||
expect(keys(sortUngroupedWorkspaces(before, "statusChange", projectNames))).toEqual([
|
||||
"srv:a",
|
||||
"srv:b",
|
||||
]);
|
||||
|
||||
const changedFields = [before[0]!, ws({ ...before[1]!, title: "renamed", name: "renamed" })];
|
||||
expect(keys(sortUngroupedWorkspaces(changedFields, "statusChange", projectNames))).toEqual([
|
||||
"srv:a",
|
||||
"srv:b",
|
||||
]);
|
||||
|
||||
const statusChanged = [
|
||||
before[0]!,
|
||||
ws({ ...before[1]!, statusBucket: "running", statusEnteredAt: d("2026-03-03T00:00:00Z") }),
|
||||
];
|
||||
expect(keys(sortUngroupedWorkspaces(statusChanged, "statusChange", projectNames))).toEqual([
|
||||
"srv:b",
|
||||
"srv:a",
|
||||
]);
|
||||
});
|
||||
|
||||
it("breaks ties by workspace key so the order is stable", () => {
|
||||
const same = d("2026-03-01T00:00:00Z");
|
||||
const rows = [
|
||||
ws({ workspaceKey: "srv:b", createdAt: same }),
|
||||
ws({ workspaceKey: "srv:a", createdAt: same }),
|
||||
];
|
||||
|
||||
expect(keys(sortUngroupedWorkspaces(rows, "created", projectNames))).toEqual([
|
||||
"srv:a",
|
||||
"srv:b",
|
||||
]);
|
||||
});
|
||||
|
||||
it("orders by name when the hosts cannot supply the sort times", () => {
|
||||
const rows = [
|
||||
ws({ workspaceKey: "srv:2", name: "Zulu", createdAt: d("2026-03-01T00:00:00Z") }),
|
||||
ws({ workspaceKey: "srv:1", name: "Alpha", createdAt: d("2026-01-01T00:00:00Z") }),
|
||||
];
|
||||
|
||||
expect(keys(sortUngroupedWorkspaces(rows, undefined, projectNames))).toEqual([
|
||||
"srv:1",
|
||||
"srv:2",
|
||||
]);
|
||||
});
|
||||
|
||||
it("does not reorder the input", () => {
|
||||
const rows = [
|
||||
ws({ workspaceKey: "srv:old", createdAt: d("2026-01-01T00:00:00Z") }),
|
||||
ws({ workspaceKey: "srv:new", createdAt: d("2026-02-01T00:00:00Z") }),
|
||||
];
|
||||
|
||||
sortUngroupedWorkspaces(rows, "created", projectNames);
|
||||
|
||||
expect(keys(rows)).toEqual(["srv:old", "srv:new"]);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,33 @@
|
||||
import type { UngroupedSort } from "@/components/sidebar/sidebar-sort";
|
||||
import { compareNames, compareText } from "@/utils/collation";
|
||||
import { workspaceSortTime } from "@/projects/workspace-structure";
|
||||
import { compareStatusRows } from "./sidebar-status-view-model";
|
||||
import type { SidebarWorkspaceEntry } from "./sidebar-workspaces-view-model";
|
||||
|
||||
/**
|
||||
* Orders every unpinned workspace as one list, newest first by the chosen time.
|
||||
*
|
||||
* Created and Last prompt use the same times, with the same fallback, as the per-project sort in
|
||||
* `buildWorkspaceStructureProjects`. With no sort, rows go by name. Status change uses the time status grouping orders rows by
|
||||
* inside a group, so the row's right-hand time and the order never disagree.
|
||||
*/
|
||||
export function sortUngroupedWorkspaces(
|
||||
workspaces: readonly SidebarWorkspaceEntry[],
|
||||
sort: UngroupedSort | undefined,
|
||||
projectNamesByViewKey: Map<string, string>,
|
||||
): SidebarWorkspaceEntry[] {
|
||||
const rows = [...workspaces];
|
||||
if (sort === undefined) {
|
||||
return rows.sort(
|
||||
(a, b) => compareNames(a.name, b.name) || compareText(a.workspaceKey, b.workspaceKey),
|
||||
);
|
||||
}
|
||||
if (sort === "statusChange") {
|
||||
return rows.sort((a, b) => compareStatusRows(a, b, projectNamesByViewKey));
|
||||
}
|
||||
return rows.sort(
|
||||
(a, b) =>
|
||||
workspaceSortTime(b, sort) - workspaceSortTime(a, sort) ||
|
||||
a.workspaceKey.localeCompare(b.workspaceKey),
|
||||
);
|
||||
}
|
||||
@@ -39,6 +39,9 @@ export interface SidebarStatusWorkspacePlacement extends SidebarWorkspacePlaceme
|
||||
}
|
||||
|
||||
export interface SidebarWorkspaceEntry extends SidebarStatusWorkspacePlacement {
|
||||
// The times the Created and Last prompt sorts order by. Null from a host that predates them.
|
||||
createdAt: Date | null;
|
||||
lastUserMessageAt: Date | null;
|
||||
workspaceDirectory: string;
|
||||
workspaceDirectoryLabel: string;
|
||||
// Raw user-set title (null when the name is derived from branch/directory).
|
||||
@@ -170,6 +173,8 @@ export function createSidebarWorkspaceEntry(input: {
|
||||
currentBranch: normalizeCurrentBranch(input.workspace.gitRuntime?.currentBranch),
|
||||
statusBucket: effectiveStatus.status,
|
||||
statusEnteredAt: effectiveStatus.enteredAt,
|
||||
createdAt: input.workspace.createdAt,
|
||||
lastUserMessageAt: input.workspace.lastUserMessageAt,
|
||||
archivingAt: input.workspace.archivingAt,
|
||||
diffStat: input.workspace.diffStat,
|
||||
prHint: selectPrHintFromStatus(
|
||||
|
||||
@@ -29,6 +29,8 @@ function workspace(projectKey: string, workspaceId: string): SidebarWorkspaceEnt
|
||||
currentBranch: null,
|
||||
statusBucket: "done",
|
||||
statusEnteredAt: null,
|
||||
createdAt: null,
|
||||
lastUserMessageAt: null,
|
||||
archivingAt: null,
|
||||
diffStat: null,
|
||||
prHint: null,
|
||||
|
||||
@@ -7,6 +7,7 @@ import { useWorkspaceDirectoryServerIds } from "@/stores/session-store-hooks";
|
||||
import { workspaceEqualityFns } from "@/stores/session-store-hooks/selectors";
|
||||
import { useWorkspaceStructure } from "@/stores/session-store-hooks";
|
||||
import { getHostRuntimeStore, useHostRegistryLoaded, useHosts } from "@/runtime/host-runtime";
|
||||
import { resolveProjectSort } from "@/components/sidebar/sidebar-sort";
|
||||
import { useSidebarOrderStore } from "@/stores/sidebar-order-store";
|
||||
import { useSidebarViewStore } from "@/stores/sidebar-view-store";
|
||||
import {
|
||||
@@ -145,9 +146,10 @@ export function useSidebarWorkspacesList(options?: {
|
||||
const sortSupport = useHostFeatureAvailabilityMap(directoryServerIds, "workspaceSortTimes");
|
||||
// Cached workspaces are visible before their host sends server info.
|
||||
const workspaceSortSupported = ![...sortSupport.values()].includes(false);
|
||||
const projectSort = resolveProjectSort(workspaceSort);
|
||||
const sort =
|
||||
groupMode === "project" && (workspaceSort === "manual" || workspaceSortSupported)
|
||||
? workspaceSort
|
||||
groupMode === "project" && (projectSort === "manual" || workspaceSortSupported)
|
||||
? projectSort
|
||||
: undefined;
|
||||
const { projects: hostProjects } = useWorkspaceStructure(directoryServerIds, sort);
|
||||
|
||||
|
||||
@@ -1334,6 +1334,7 @@ export const ar: TranslationResources = {
|
||||
failed: "فشل",
|
||||
readyToReview: "جاهزة للمراجعة",
|
||||
working: "قيد العمل",
|
||||
waiting: "في الانتظار",
|
||||
done: "تم",
|
||||
},
|
||||
display: {
|
||||
@@ -1345,12 +1346,14 @@ export const ar: TranslationResources = {
|
||||
created: "تاريخ الإنشاء",
|
||||
manual: "يدوي",
|
||||
lastPrompt: "آخر طلب",
|
||||
statusChange: "تغيّر الحالة",
|
||||
updateHost: "حدّث المضيفين لترتيب مساحات العمل",
|
||||
},
|
||||
grouping: {
|
||||
label: "التجميع",
|
||||
project: "المشروع",
|
||||
status: "الحالة",
|
||||
none: "بلا",
|
||||
labels: "التسميات",
|
||||
},
|
||||
titleSource: {
|
||||
@@ -2427,6 +2430,7 @@ export const ar: TranslationResources = {
|
||||
pillLabelOne: "وكيل فرعي واحد",
|
||||
pillLabelMany: "{{count}} وكلاء فرعيين",
|
||||
pillLabelWorking: "{{count}} قيد التشغيل",
|
||||
pillLabelWaiting: "{{count}} في الانتظار",
|
||||
pillLabelFailed: "{{count}} فشلت",
|
||||
pillLabelNeedsInputOne: "واحد يحتاج إدخالاً",
|
||||
pillLabelNeedsInputMany: "{{count}} تحتاج إدخالاً",
|
||||
|
||||
@@ -1345,6 +1345,7 @@ export const en = {
|
||||
failed: "Failed",
|
||||
readyToReview: "Ready to review",
|
||||
working: "Working",
|
||||
waiting: "Waiting",
|
||||
done: "Done",
|
||||
},
|
||||
display: {
|
||||
@@ -1356,12 +1357,14 @@ export const en = {
|
||||
created: "Created",
|
||||
manual: "Manual",
|
||||
lastPrompt: "Last prompt",
|
||||
statusChange: "Status change",
|
||||
updateHost: "Update hosts to sort workspaces",
|
||||
},
|
||||
grouping: {
|
||||
label: "Grouping",
|
||||
project: "Project",
|
||||
status: "Status",
|
||||
none: "None",
|
||||
labels: "Labels",
|
||||
},
|
||||
titleSource: {
|
||||
@@ -2459,6 +2462,7 @@ export const en = {
|
||||
pillLabelOne: "1 subagent",
|
||||
pillLabelMany: "{{count}} subagents",
|
||||
pillLabelWorking: "{{count}} working",
|
||||
pillLabelWaiting: "{{count}} waiting",
|
||||
pillLabelFailed: "{{count}} failed",
|
||||
pillLabelNeedsInputOne: "1 needs input",
|
||||
pillLabelNeedsInputMany: "{{count}} need input",
|
||||
|
||||
@@ -1371,6 +1371,7 @@ export const es: TranslationResources = {
|
||||
failed: "Con error",
|
||||
readyToReview: "Para revisar",
|
||||
working: "En ejecución",
|
||||
waiting: "En espera",
|
||||
done: "Terminado",
|
||||
},
|
||||
display: {
|
||||
@@ -1382,12 +1383,14 @@ export const es: TranslationResources = {
|
||||
created: "Creación",
|
||||
manual: "Manual",
|
||||
lastPrompt: "Último prompt",
|
||||
statusChange: "Cambio de estado",
|
||||
updateHost: "Actualiza los hosts para ordenar los espacios de trabajo",
|
||||
},
|
||||
grouping: {
|
||||
label: "Agrupación",
|
||||
project: "Proyecto",
|
||||
status: "Estado",
|
||||
none: "Ninguno",
|
||||
labels: "Etiquetas",
|
||||
},
|
||||
titleSource: {
|
||||
@@ -2487,6 +2490,7 @@ export const es: TranslationResources = {
|
||||
pillLabelOne: "1 subagente",
|
||||
pillLabelMany: "{{count}} subagentes",
|
||||
pillLabelWorking: "{{count}} en ejecución",
|
||||
pillLabelWaiting: "{{count}} en espera",
|
||||
pillLabelFailed: "{{count}} con error",
|
||||
pillLabelNeedsInputOne: "1 necesita datos",
|
||||
pillLabelNeedsInputMany: "{{count}} necesitan datos",
|
||||
|
||||
@@ -1363,6 +1363,7 @@ export const fr: TranslationResources = {
|
||||
failed: "Échec",
|
||||
readyToReview: "À relire",
|
||||
working: "En cours",
|
||||
waiting: "En attente",
|
||||
done: "Terminé",
|
||||
},
|
||||
display: {
|
||||
@@ -1374,12 +1375,14 @@ export const fr: TranslationResources = {
|
||||
created: "Création",
|
||||
manual: "Manuel",
|
||||
lastPrompt: "Dernier prompt",
|
||||
statusChange: "Changement de statut",
|
||||
updateHost: "Mettez les hôtes à jour pour trier les espaces de travail",
|
||||
},
|
||||
grouping: {
|
||||
label: "Regroupement",
|
||||
project: "Projet",
|
||||
status: "Statut",
|
||||
none: "Aucun",
|
||||
labels: "Libellés",
|
||||
},
|
||||
titleSource: {
|
||||
@@ -2483,6 +2486,7 @@ export const fr: TranslationResources = {
|
||||
pillLabelOne: "1 sous-agent",
|
||||
pillLabelMany: "{{count}} sous-agents",
|
||||
pillLabelWorking: "{{count}} en cours",
|
||||
pillLabelWaiting: "{{count}} en attente",
|
||||
pillLabelFailed: "{{count}} en échec",
|
||||
pillLabelNeedsInputOne: "1 attend une réponse",
|
||||
pillLabelNeedsInputMany: "{{count}} attendent une réponse",
|
||||
|
||||
@@ -1348,6 +1348,7 @@ export const ja: TranslationResources = {
|
||||
failed: "失敗",
|
||||
readyToReview: "レビュー待ち",
|
||||
working: "実行中",
|
||||
waiting: "待機中",
|
||||
done: "完了",
|
||||
},
|
||||
display: {
|
||||
@@ -1359,12 +1360,14 @@ export const ja: TranslationResources = {
|
||||
created: "作成日時",
|
||||
manual: "手動",
|
||||
lastPrompt: "最後のプロンプト",
|
||||
statusChange: "ステータス変更",
|
||||
updateHost: "ワークスペースを並べ替えるにはホストを更新してください",
|
||||
},
|
||||
grouping: {
|
||||
label: "グループ化",
|
||||
project: "プロジェクト",
|
||||
status: "ステータス",
|
||||
none: "なし",
|
||||
labels: "ラベル",
|
||||
},
|
||||
titleSource: {
|
||||
@@ -2453,6 +2456,7 @@ export const ja: TranslationResources = {
|
||||
pillLabelOne: "サブエージェント 1 件",
|
||||
pillLabelMany: "サブエージェント {{count}} 件",
|
||||
pillLabelWorking: "{{count}} 件実行中",
|
||||
pillLabelWaiting: "{{count}} 件待機中",
|
||||
pillLabelFailed: "{{count}} 件失敗",
|
||||
pillLabelNeedsInputOne: "1 件が入力待ち",
|
||||
pillLabelNeedsInputMany: "{{count}} 件が入力待ち",
|
||||
|
||||
@@ -1341,6 +1341,7 @@ export const ko: TranslationResources = {
|
||||
failed: "실패",
|
||||
readyToReview: "검토 대기",
|
||||
working: "실행 중",
|
||||
waiting: "대기 중",
|
||||
done: "완료",
|
||||
},
|
||||
display: {
|
||||
@@ -1352,12 +1353,14 @@ export const ko: TranslationResources = {
|
||||
created: "생성일",
|
||||
manual: "수동",
|
||||
lastPrompt: "마지막 프롬프트",
|
||||
statusChange: "상태 변경",
|
||||
updateHost: "작업 공간을 정렬하려면 호스트를 업데이트하세요",
|
||||
},
|
||||
grouping: {
|
||||
label: "그룹화",
|
||||
project: "프로젝트",
|
||||
status: "상태",
|
||||
none: "없음",
|
||||
labels: "레이블",
|
||||
},
|
||||
titleSource: {
|
||||
@@ -2444,6 +2447,7 @@ export const ko: TranslationResources = {
|
||||
pillLabelOne: "하위 에이전트 1개",
|
||||
pillLabelMany: "하위 에이전트 {{count}}개",
|
||||
pillLabelWorking: "{{count}}개 실행 중",
|
||||
pillLabelWaiting: "{{count}}개 대기 중",
|
||||
pillLabelFailed: "{{count}}개 실패",
|
||||
pillLabelNeedsInputOne: "1개 입력 필요",
|
||||
pillLabelNeedsInputMany: "{{count}}개 입력 필요",
|
||||
|
||||
@@ -1361,6 +1361,7 @@ export const ptBR: TranslationResources = {
|
||||
failed: "Com falha",
|
||||
readyToReview: "Para revisar",
|
||||
working: "Em execução",
|
||||
waiting: "Aguardando",
|
||||
done: "Concluído",
|
||||
},
|
||||
display: {
|
||||
@@ -1372,12 +1373,14 @@ export const ptBR: TranslationResources = {
|
||||
created: "Criação",
|
||||
manual: "Manual",
|
||||
lastPrompt: "Último prompt",
|
||||
statusChange: "Mudança de status",
|
||||
updateHost: "Atualize os hosts para ordenar os espaços de trabalho",
|
||||
},
|
||||
grouping: {
|
||||
label: "Agrupamento",
|
||||
project: "Projeto",
|
||||
status: "Status",
|
||||
none: "Nenhum",
|
||||
labels: "Etiquetas",
|
||||
},
|
||||
titleSource: {
|
||||
@@ -2469,6 +2472,7 @@ export const ptBR: TranslationResources = {
|
||||
pillLabelOne: "1 subagente",
|
||||
pillLabelMany: "{{count}} subagentes",
|
||||
pillLabelWorking: "{{count}} em execução",
|
||||
pillLabelWaiting: "{{count}} aguardando",
|
||||
pillLabelFailed: "{{count}} com falha",
|
||||
pillLabelNeedsInputOne: "1 precisa de resposta",
|
||||
pillLabelNeedsInputMany: "{{count}} precisam de resposta",
|
||||
|
||||
@@ -1353,6 +1353,7 @@ export const ru: TranslationResources = {
|
||||
failed: "Ошибка",
|
||||
readyToReview: "На проверку",
|
||||
working: "В работе",
|
||||
waiting: "Ожидание",
|
||||
done: "Готово",
|
||||
},
|
||||
display: {
|
||||
@@ -1364,12 +1365,14 @@ export const ru: TranslationResources = {
|
||||
created: "Дата создания",
|
||||
manual: "Вручную",
|
||||
lastPrompt: "Последний запрос",
|
||||
statusChange: "Смена статуса",
|
||||
updateHost: "Обновите хосты для сортировки рабочих пространств",
|
||||
},
|
||||
grouping: {
|
||||
label: "Группировка",
|
||||
project: "Проект",
|
||||
status: "Статус",
|
||||
none: "Без группировки",
|
||||
labels: "Метки",
|
||||
},
|
||||
titleSource: {
|
||||
@@ -2469,6 +2472,7 @@ export const ru: TranslationResources = {
|
||||
pillLabelOne: "1 субагент",
|
||||
pillLabelMany: "Субагентов: {{count}}",
|
||||
pillLabelWorking: "{{count}} в работе",
|
||||
pillLabelWaiting: "{{count}} в ожидании",
|
||||
pillLabelFailed: "{{count}} с ошибкой",
|
||||
pillLabelNeedsInputOne: "1 ожидает ввода",
|
||||
pillLabelNeedsInputMany: "{{count}} ожидают ввода",
|
||||
|
||||
@@ -1326,6 +1326,7 @@ export const zhCN: TranslationResources = {
|
||||
failed: "失败",
|
||||
readyToReview: "待查看",
|
||||
working: "运行中",
|
||||
waiting: "等待中",
|
||||
done: "已完成",
|
||||
},
|
||||
display: {
|
||||
@@ -1337,12 +1338,14 @@ export const zhCN: TranslationResources = {
|
||||
created: "创建时间",
|
||||
manual: "手动",
|
||||
lastPrompt: "最近提示词",
|
||||
statusChange: "状态变更",
|
||||
updateHost: "请更新主机以排序工作区",
|
||||
},
|
||||
grouping: {
|
||||
label: "分组",
|
||||
project: "项目",
|
||||
status: "状态",
|
||||
none: "不分组",
|
||||
labels: "标签",
|
||||
},
|
||||
titleSource: {
|
||||
@@ -2400,6 +2403,7 @@ export const zhCN: TranslationResources = {
|
||||
pillLabelOne: "1 个 subagent",
|
||||
pillLabelMany: "{{count}} 个 subagent",
|
||||
pillLabelWorking: "{{count}} 个运行中",
|
||||
pillLabelWaiting: "{{count}} 个等待中",
|
||||
pillLabelFailed: "{{count}} 个失败",
|
||||
pillLabelNeedsInputOne: "1 个需要输入",
|
||||
pillLabelNeedsInputMany: "{{count}} 个需要输入",
|
||||
|
||||
@@ -105,9 +105,9 @@ describe("shared agent descriptor", () => {
|
||||
expect(describeAgent({ isTurnActive: true }).statusBucket).toBe("running");
|
||||
});
|
||||
|
||||
it("shows background work as running without making the turn active", () => {
|
||||
it("shows background work as waiting without making the turn active", () => {
|
||||
expect(describeAgent({ backgroundWork: { count: 1 } })).toMatchObject({
|
||||
statusBucket: "running",
|
||||
statusBucket: "waiting",
|
||||
subtitle: "Background work running",
|
||||
});
|
||||
expect(
|
||||
@@ -118,6 +118,9 @@ describe("shared agent descriptor", () => {
|
||||
}).statusBucket,
|
||||
).toBe("failed");
|
||||
expect(describeAgent({ backgroundWork: { count: 1 }, status: "error" }).statusBucket).toBe(
|
||||
"waiting",
|
||||
);
|
||||
expect(describeAgent({ backgroundWork: { count: 1 }, isTurnActive: true }).statusBucket).toBe(
|
||||
"running",
|
||||
);
|
||||
});
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { AgentAddress } from "@getpaseo/protocol/addresses";
|
||||
import { isAgentBusy, isAgentTurnRunning } from "@getpaseo/protocol/agent-state-bucket";
|
||||
import { memo, useCallback, useMemo, useRef, type ReactElement } from "react";
|
||||
import type { View } from "react-native";
|
||||
import { BackgroundWorkTrack, createHostBackgroundWorkModel } from "@/background-work";
|
||||
@@ -9,7 +10,7 @@ import { useIsCompactFormFactor } from "@/constants/layout";
|
||||
import { usePaneContext } from "@/panels/pane-context";
|
||||
import { useSettings } from "@/hooks/use-settings";
|
||||
import { PluginComposerPillItems, PluginComposerPills } from "@/plugins";
|
||||
import { useSessionStore } from "@/stores/session-store";
|
||||
import { selectAgentTurnPresentation, useSessionStore } from "@/stores/session-store";
|
||||
import {
|
||||
useArchiveFinishedSubagents,
|
||||
useArchiveSubagent,
|
||||
@@ -58,6 +59,15 @@ export const AgentTracks = memo(function AgentTracks({
|
||||
const agent = session?.agents.get(agentId) ?? session?.agentDetails.get(agentId);
|
||||
return agent?.backgroundWork?.count ?? 0;
|
||||
});
|
||||
// The same turn state the tab reads, so a follow-up being sent turns both marks to running.
|
||||
const backgroundWorkBucket = useSessionStore((state) => {
|
||||
const session = state.sessions[serverId];
|
||||
const agent = session?.agents.get(agentId) ?? session?.agentDetails.get(agentId);
|
||||
const turnRunning =
|
||||
selectAgentTurnPresentation(session, agentId).isActive ||
|
||||
isAgentTurnRunning({ status: agent?.status });
|
||||
return !turnRunning && agent && isAgentBusy(agent) ? "waiting" : "running";
|
||||
});
|
||||
const backgroundModel = useMemo(
|
||||
() => createHostBackgroundWorkModel(serverId, agentId),
|
||||
[serverId, agentId],
|
||||
@@ -123,7 +133,11 @@ export const AgentTracks = memo(function AgentTracks({
|
||||
|
||||
return (
|
||||
<ComposerTrackBar trackViewportRef={trackViewportRef}>
|
||||
<BackgroundWorkTrack model={backgroundModel} count={backgroundWorkCount} />
|
||||
<BackgroundWorkTrack
|
||||
model={backgroundModel}
|
||||
count={backgroundWorkCount}
|
||||
bucket={backgroundWorkBucket}
|
||||
/>
|
||||
{parentAgentId ? <ParentAgentPill serverId={serverId} parentAgentId={parentAgentId} /> : null}
|
||||
<AgentTaskList tasks={tasks} />
|
||||
<SubagentsTrack
|
||||
|
||||
@@ -177,6 +177,12 @@ describe("sidebar entity snapshots", () => {
|
||||
expect(Object.isFrozen(snapshot.metadata.issues)).toBe(true);
|
||||
});
|
||||
|
||||
it("reports a waiting workspace to plugins as waiting, labelled Working", () => {
|
||||
const snapshot = createPluginWorkspaceSnapshot({ ...workspace, status: "waiting" }, "host-1");
|
||||
expect(snapshot.indicator).toBe("waiting");
|
||||
expect(snapshot.indicatorLabel).toBe("Working");
|
||||
});
|
||||
|
||||
it("reads projects without requiring a workspace", () => {
|
||||
const project = {
|
||||
projectId: "empty",
|
||||
|
||||
@@ -116,6 +116,7 @@ const indicatorLabelKeys = {
|
||||
needs_input: "sidebar.statusBucket.needsInput",
|
||||
failed: "sidebar.statusBucket.failed",
|
||||
running: "sidebar.statusBucket.working",
|
||||
waiting: "sidebar.statusBucket.working",
|
||||
attention: "sidebar.statusBucket.readyToReview",
|
||||
done: "sidebar.statusBucket.done",
|
||||
} as const;
|
||||
|
||||
@@ -211,8 +211,8 @@ function compareWorkspaceStructureItems(left: WorkspaceSortItem, right: Workspac
|
||||
);
|
||||
}
|
||||
|
||||
function workspaceSortTime(
|
||||
workspace: WorkspaceDescriptor,
|
||||
export function workspaceSortTime(
|
||||
workspace: Pick<WorkspaceDescriptor, "createdAt" | "lastUserMessageAt">,
|
||||
sort: WorkspaceSort | undefined,
|
||||
): number {
|
||||
if (!sort) return 0;
|
||||
|
||||
@@ -398,6 +398,20 @@ describe("ReplicaCache", () => {
|
||||
expect(restored.workspaces.get(workspace.id)?.forgeWeb).toEqual(forgeWeb);
|
||||
});
|
||||
|
||||
it("preserves a waiting workspace status across cache reopen", async () => {
|
||||
const storage = new MemoryStorage();
|
||||
const writer = createCache(storage);
|
||||
const baseline = directory();
|
||||
const workspace = normalizeWorkspaceDescriptor({ ...workspacePayload(), status: "waiting" });
|
||||
baseline.workspaces.set(workspace.id, workspace);
|
||||
commitDirectory(writer, SERVER_ID, baseline);
|
||||
await writer.flush();
|
||||
const reader = createCache(storage);
|
||||
expect((await reader.readDirectory(SERVER_ID)).workspaces.get(workspace.id)?.status).toBe(
|
||||
"waiting",
|
||||
);
|
||||
});
|
||||
|
||||
it("preserves workspace sorting timestamps across cache reopen", async () => {
|
||||
const storage = new MemoryStorage();
|
||||
const writer = createCache(storage);
|
||||
|
||||
@@ -364,7 +364,7 @@ const StoredWorkspaceSchema = z.strictObject({
|
||||
labels: z.array(z.string()).optional(),
|
||||
// Require metadata so older rows written before metadata was cached invalidate the workspace cursor.
|
||||
metadata: z.record(z.string(), z.unknown() as z.ZodType<JsonValue>),
|
||||
status: z.enum(["needs_input", "failed", "running", "attention", "done"]),
|
||||
status: z.enum(["needs_input", "failed", "running", "waiting", "attention", "done"]),
|
||||
statusEnteredAt: IsoDateSchema.nullable(),
|
||||
activityAt: z.null(),
|
||||
archivingAt: z.string().nullable(),
|
||||
|
||||
@@ -25,6 +25,8 @@ function makeEntry(
|
||||
currentBranch: overrides.workspaceId,
|
||||
statusBucket: "done",
|
||||
statusEnteredAt: null,
|
||||
createdAt: null,
|
||||
lastUserMessageAt: null,
|
||||
archivingAt: null,
|
||||
diffStat: null,
|
||||
prHint: null,
|
||||
|
||||
@@ -50,6 +50,8 @@ function makeEntry(id: string): SidebarWorkspaceEntry {
|
||||
currentBranch: id,
|
||||
statusBucket: "done",
|
||||
statusEnteredAt: null,
|
||||
createdAt: null,
|
||||
lastUserMessageAt: null,
|
||||
archivingAt: null,
|
||||
diffStat: null,
|
||||
prHint: null,
|
||||
|
||||
@@ -250,6 +250,25 @@ describe("sidebar view store", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("carries the ungrouped arrangement and its sort through the version migration", () => {
|
||||
expect(
|
||||
migrateSidebarViewState({ groupMode: "none", workspaceSort: "statusChange" }),
|
||||
).toMatchObject({ groupMode: "none", workspaceSort: "statusChange" });
|
||||
});
|
||||
|
||||
it("keeps the stored sort when the grouping changes", () => {
|
||||
const store = useSidebarViewStore.getState();
|
||||
store.setWorkspaceSort("manual");
|
||||
|
||||
store.setGroupMode("none");
|
||||
store.setGroupMode("project");
|
||||
|
||||
expect(useSidebarViewStore.getState()).toMatchObject({
|
||||
groupMode: "project",
|
||||
workspaceSort: "manual",
|
||||
});
|
||||
});
|
||||
|
||||
it("falls back to the legacy storage key when the new key is empty", async () => {
|
||||
const storage = createMemoryStorage({
|
||||
"sidebar-view": null,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { WorkspaceSort } from "@/projects/workspace-structure";
|
||||
import type { SidebarSort } from "@/components/sidebar/sidebar-sort";
|
||||
import AsyncStorage from "@react-native-async-storage/async-storage";
|
||||
import { create } from "zustand";
|
||||
import { persist, type StateStorage } from "zustand/middleware";
|
||||
@@ -6,7 +6,8 @@ import { z } from "zod";
|
||||
import { workspaceLabelKey } from "@getpaseo/protocol/workspace-labels";
|
||||
import { createValidatedPersistStorage } from "@/storage/validated-persist-storage";
|
||||
|
||||
export type SidebarGroupMode = "project" | "status";
|
||||
/** "none" is one flat list with no group headers. */
|
||||
export type SidebarGroupMode = "project" | "status" | "none";
|
||||
|
||||
const SIDEBAR_VIEW_STORAGE_KEY = "sidebar-view";
|
||||
const LEGACY_SIDEBAR_GROUP_MODE_STORAGE_KEY = "sidebar-group-mode";
|
||||
@@ -48,7 +49,7 @@ function toggleFilterEntry(list: readonly string[], key: string): string[] {
|
||||
|
||||
interface SidebarViewStoreState {
|
||||
groupMode: SidebarGroupMode;
|
||||
workspaceSort: WorkspaceSort;
|
||||
workspaceSort: SidebarSort;
|
||||
showBackground: boolean;
|
||||
// Empty means "all hosts". A non-empty list pins the sidebar to those hosts.
|
||||
hostFilters: string[];
|
||||
@@ -66,7 +67,7 @@ interface SidebarViewStoreState {
|
||||
labelFilter: SidebarLabelFilter;
|
||||
toggleBackground: () => void;
|
||||
setGroupMode: (mode: SidebarGroupMode) => void;
|
||||
setWorkspaceSort: (sort: WorkspaceSort) => void;
|
||||
setWorkspaceSort: (sort: SidebarSort) => void;
|
||||
toggleHostFilter: (serverId: string) => void;
|
||||
clearHostFilters: () => void;
|
||||
focusHost: (serverId: string) => void;
|
||||
@@ -80,19 +81,19 @@ interface SidebarViewStoreState {
|
||||
|
||||
interface SidebarViewPersistedState {
|
||||
groupMode: SidebarGroupMode;
|
||||
workspaceSort: WorkspaceSort;
|
||||
workspaceSort: SidebarSort;
|
||||
showBackground: boolean;
|
||||
hostFilters: string[];
|
||||
projectFilters: string[];
|
||||
labelFilter: SidebarLabelFilter;
|
||||
}
|
||||
|
||||
const PersistedSidebarGroupModeSchema = z.enum(["project", "status", "label"]);
|
||||
const PersistedSidebarGroupModeSchema = z.enum(["project", "status", "none", "label"]);
|
||||
const SidebarLabelFilterSchema = z.object({
|
||||
labels: z.array(z.string()),
|
||||
});
|
||||
const SidebarViewPersistedStateSchema = z.strictObject({
|
||||
workspaceSort: z.enum(["manual", "created", "lastPrompt"]).optional(),
|
||||
workspaceSort: z.enum(["manual", "created", "lastPrompt", "statusChange"]).optional(),
|
||||
showBackground: z.boolean().optional(),
|
||||
groupMode: PersistedSidebarGroupModeSchema.optional(),
|
||||
hostFilters: z.array(z.string()).optional(),
|
||||
@@ -115,6 +116,11 @@ function readLegacyGroupMode(persistedState: SidebarViewStorageState): SidebarGr
|
||||
return modes.includes("status") ? "status" : "project";
|
||||
}
|
||||
|
||||
// A persisted legacy `"label"` value folds to project.
|
||||
function readGroupMode(groupMode: SidebarViewStorageState["groupMode"]): SidebarGroupMode {
|
||||
return groupMode === "status" || groupMode === "none" ? groupMode : "project";
|
||||
}
|
||||
|
||||
// Reads the host filter from any persisted shape: the current `hostFilters` array, or the
|
||||
// pre-v2 single `hostFilter` string (null/absent meant "all hosts").
|
||||
function readHostFilters(persistedState: SidebarViewStorageState): string[] {
|
||||
@@ -156,7 +162,7 @@ export function migrateSidebarViewState(persistedState: unknown): SidebarViewPer
|
||||
|
||||
return {
|
||||
showBackground: state.showBackground ?? false,
|
||||
groupMode: state.groupMode === "status" ? "status" : "project",
|
||||
groupMode: readGroupMode(state.groupMode),
|
||||
workspaceSort: state.workspaceSort ?? "created",
|
||||
hostFilters: readHostFilters(state),
|
||||
projectFilters: state.projectFilters ?? [],
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { isAgentRunning } from "@getpaseo/protocol/agent-state-bucket";
|
||||
import { isAgentBusy } from "@getpaseo/protocol/agent-state-bucket";
|
||||
import type { Agent } from "@/stores/session-store";
|
||||
import type { ConfirmDialogInput } from "@/utils/confirm-dialog";
|
||||
|
||||
@@ -26,7 +26,7 @@ export function resolveArchiveSubagentDialog(
|
||||
input: ResolveArchiveSubagentDialogInput,
|
||||
): ConfirmDialogInput {
|
||||
const subagentLabel = resolveSubagentLabel(input.title) ?? "this subagent";
|
||||
const isRunning = isAgentRunning(input);
|
||||
const isRunning = isAgentBusy(input);
|
||||
|
||||
let message = `Remove ${subagentLabel} from the track. The subagent will be archived.`;
|
||||
if (isRunning) {
|
||||
|
||||
@@ -49,6 +49,22 @@ describe("buildSubagentPillPresentation", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("counts a child that only waits on background work in its own segment after working", () => {
|
||||
expect(
|
||||
pill([
|
||||
row({ id: "waits", status: "idle", backgroundWork: { count: 1 } }),
|
||||
row({ id: "works", status: "running" }),
|
||||
row({ id: "waits-too", status: "idle", backgroundWork: { count: 2 } }),
|
||||
]),
|
||||
).toEqual({
|
||||
segments: [
|
||||
{ bucket: "running", text: "1 working" },
|
||||
{ bucket: "waiting", text: "2 waiting" },
|
||||
],
|
||||
accessibilityLabel: "1 working, 2 waiting",
|
||||
});
|
||||
});
|
||||
|
||||
it("counts every child in the state it reports", () => {
|
||||
expect(
|
||||
pill([
|
||||
@@ -194,11 +210,19 @@ describe("buildSubagentRowPresentationData", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("shows a child with background work as running after its foreground turn ends", () => {
|
||||
it("shows a child with background work as waiting after its foreground turn ends", () => {
|
||||
expect(
|
||||
buildSubagentRowPresentationData(
|
||||
row({ id: "a", status: "idle", backgroundWork: { count: 1 } }),
|
||||
).statusBucket,
|
||||
).toBe("waiting");
|
||||
});
|
||||
|
||||
it("keeps a child that is running a turn as running while it has background work", () => {
|
||||
expect(
|
||||
buildSubagentRowPresentationData(
|
||||
row({ id: "a", status: "running", backgroundWork: { count: 1 } }),
|
||||
).statusBucket,
|
||||
).toBe("running");
|
||||
});
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { TFunction } from "i18next";
|
||||
import type { ComposerTrackPillSegment } from "@/composer/tracks";
|
||||
import type { SidebarStateBucket } from "@/utils/sidebar-agent-state";
|
||||
import { isAgentRunning } from "@getpaseo/protocol/agent-state-bucket";
|
||||
import { deriveAgentStateBucket } from "@getpaseo/protocol/agent-state-bucket";
|
||||
import type { AgentBackgroundWorkSummary } from "@getpaseo/protocol/messages";
|
||||
import type { AgentLifecycleStatus } from "@getpaseo/protocol/agent-lifecycle";
|
||||
import { STATUS_BUCKET_ORDER } from "@/utils/sidebar-agent-state";
|
||||
@@ -26,8 +26,9 @@ export function deriveSubagentStatusBucket(
|
||||
backgroundWork?: AgentBackgroundWorkSummary | null,
|
||||
): SidebarStateBucket {
|
||||
if (status === "error") return "failed";
|
||||
if (isAgentRunning({ status, backgroundWork })) return "running";
|
||||
return "done";
|
||||
// Running, waiting and done come from the shared rule, so the track cannot disagree with the
|
||||
// sidebar about a child that has ended its turn with background work still alive.
|
||||
return deriveAgentStateBucket({ status, backgroundWork });
|
||||
}
|
||||
|
||||
export interface SubagentRowPresentationData {
|
||||
@@ -88,8 +89,8 @@ export interface SubagentPillPresentation {
|
||||
* "1 failed" over a child that is still working says the fan-out has stopped. Every state present
|
||||
* gets its own mark and its own count, in the order the sidebar's status groups list them.
|
||||
*
|
||||
* It stays one line because subagent rows only ever reach three states — see
|
||||
* `buildSubagentRowPresentationData`, which reports no attention of its own — so the pill is two
|
||||
* It stays one line because subagent rows only ever reach four states — see
|
||||
* `buildSubagentRowPresentationData`, which reports no attention of its own — so the pill is three
|
||||
* segments at worst, and falls back to naming what it opens once nothing is happening.
|
||||
*/
|
||||
export function buildSubagentPillPresentation(
|
||||
@@ -114,6 +115,8 @@ function statusLabel(t: TFunction, bucket: ActiveStatusBucket, count: number): s
|
||||
switch (bucket) {
|
||||
case "running":
|
||||
return t("subagents.pillLabelWorking", { count });
|
||||
case "waiting":
|
||||
return t("subagents.pillLabelWaiting", { count });
|
||||
case "failed":
|
||||
return t("subagents.pillLabelFailed", { count });
|
||||
case "needs_input":
|
||||
|
||||
@@ -43,6 +43,20 @@ describe("deriveFaviconStatus", () => {
|
||||
).toBe("running");
|
||||
});
|
||||
|
||||
it("stays quiet for an idle agent that only has background work", () => {
|
||||
expect(
|
||||
deriveFaviconStatus(
|
||||
stateWith(
|
||||
agent({
|
||||
id: "a",
|
||||
status: "idle",
|
||||
backgroundWork: { count: 1, runningCount: 1 },
|
||||
} as Partial<Agent> & { id: string }),
|
||||
),
|
||||
),
|
||||
).toBe("none");
|
||||
});
|
||||
|
||||
it("needs attention for attention or pending permissions", () => {
|
||||
expect(deriveFaviconStatus(stateWith(agent({ id: "a", requiresAttention: true })))).toBe(
|
||||
"attention",
|
||||
|
||||
@@ -6,6 +6,10 @@ describe("getProjectStatusBadgeContent", () => {
|
||||
expect(getProjectStatusBadgeContent("running")).toEqual({ kind: "dot", bucket: "running" });
|
||||
});
|
||||
|
||||
it("shows a waiting dot while only background work is alive", () => {
|
||||
expect(getProjectStatusBadgeContent("waiting")).toEqual({ kind: "dot", bucket: "waiting" });
|
||||
});
|
||||
|
||||
it("shows the alert when input is needed", () => {
|
||||
expect(getProjectStatusBadgeContent("needs_input")).toEqual({ kind: "alert" });
|
||||
});
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { SidebarStateBucket } from "@/utils/sidebar-agent-state";
|
||||
|
||||
export type ProjectStatusBadgeDotBucket = "failed" | "attention" | "running";
|
||||
export type ProjectStatusBadgeDotBucket = "failed" | "attention" | "running" | "waiting";
|
||||
|
||||
export type ProjectStatusBadgeContent =
|
||||
| { kind: "alert" }
|
||||
@@ -22,7 +22,12 @@ export function getProjectStatusBadgeContent(
|
||||
if (statusBucket === "needs_input") {
|
||||
return { kind: "alert" };
|
||||
}
|
||||
if (statusBucket === "failed" || statusBucket === "attention" || statusBucket === "running") {
|
||||
if (
|
||||
statusBucket === "failed" ||
|
||||
statusBucket === "attention" ||
|
||||
statusBucket === "running" ||
|
||||
statusBucket === "waiting"
|
||||
) {
|
||||
return { kind: "dot", bucket: statusBucket };
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -78,6 +78,12 @@ describe("aggregateSidebarStateBuckets", () => {
|
||||
expect(aggregateSidebarStateBuckets(["attention", "running"])).toBe("running");
|
||||
});
|
||||
|
||||
it("ranks waiting below running and above ready-to-review", () => {
|
||||
expect(aggregateSidebarStateBuckets(["waiting", "running"])).toBe("running");
|
||||
expect(aggregateSidebarStateBuckets(["attention", "waiting"])).toBe("waiting");
|
||||
expect(aggregateSidebarStateBuckets(["done", "waiting"])).toBe("waiting");
|
||||
});
|
||||
|
||||
it("prefers ready-to-review over done", () => {
|
||||
expect(aggregateSidebarStateBuckets(["done", "attention", "done"])).toBe("attention");
|
||||
});
|
||||
|
||||
@@ -4,7 +4,13 @@ import {
|
||||
type AgentStateBucketInput,
|
||||
} from "@getpaseo/protocol/agent-state-bucket";
|
||||
|
||||
export type SidebarStateBucket = "needs_input" | "failed" | "running" | "attention" | "done";
|
||||
export type SidebarStateBucket =
|
||||
| "needs_input"
|
||||
| "failed"
|
||||
| "running"
|
||||
| "waiting"
|
||||
| "attention"
|
||||
| "done";
|
||||
export type SidebarAttentionReason = AgentAttentionReason;
|
||||
|
||||
export function deriveSidebarStateBucket(input: AgentStateBucketInput): SidebarStateBucket {
|
||||
@@ -18,12 +24,13 @@ export function isSidebarActiveAgent(input: AgentStateBucketInput): boolean {
|
||||
// Most urgent first, for collapsing a project's workspaces into one badge. This is
|
||||
// deliberately NOT STATUS_BUCKET_ORDER below, which ranks "attention" above "running": on a
|
||||
// collapsed project row we want an actively-working project to keep showing the loader,
|
||||
// so "running" outranks "attention" here. needs_input and failed still win over both;
|
||||
// done stays last.
|
||||
// so "running" and "waiting" outrank "attention" here. needs_input and failed still win over
|
||||
// them; done stays last.
|
||||
const STATUS_BUCKET_PRIORITY: readonly SidebarStateBucket[] = [
|
||||
"needs_input",
|
||||
"failed",
|
||||
"running",
|
||||
"waiting",
|
||||
"attention",
|
||||
"done",
|
||||
];
|
||||
@@ -31,13 +38,15 @@ const STATUS_BUCKET_PRIORITY: readonly SidebarStateBucket[] = [
|
||||
/**
|
||||
* The order states are listed in when all of them are shown side by side rather than collapsed
|
||||
* into one — the sidebar's status groups, and the subagent pill's segments. Anything the user has
|
||||
* to act on comes before anything that is still moving on its own.
|
||||
* to act on comes before anything that is still moving on its own, and a turn that is running
|
||||
* comes before one that is only waiting on background work.
|
||||
*/
|
||||
export const STATUS_BUCKET_ORDER: readonly SidebarStateBucket[] = [
|
||||
"needs_input",
|
||||
"failed",
|
||||
"attention",
|
||||
"running",
|
||||
"waiting",
|
||||
"done",
|
||||
] as const;
|
||||
|
||||
|
||||
@@ -32,6 +32,8 @@ function workspace(overrides: Partial<SidebarWorkspaceEntry> = {}): SidebarWorks
|
||||
scripts: [],
|
||||
hasRunningScripts: false,
|
||||
statusEnteredAt: null,
|
||||
createdAt: null,
|
||||
lastUserMessageAt: null,
|
||||
...overrides,
|
||||
archivingAt: overrides.archivingAt ?? null,
|
||||
};
|
||||
|
||||
@@ -37,6 +37,8 @@ function workspace(input: {
|
||||
statusBucket: input.statusBucket ?? "done",
|
||||
archivingAt: null,
|
||||
statusEnteredAt: input.statusEnteredAt ?? null,
|
||||
createdAt: null,
|
||||
lastUserMessageAt: null,
|
||||
diffStat: null,
|
||||
prHint: null,
|
||||
archiveHasUncommittedChanges: null,
|
||||
|
||||
@@ -21,7 +21,7 @@ export function getStatusDotColor(input: {
|
||||
if (bucket === "failed") {
|
||||
return theme.colors.statusDotDanger;
|
||||
}
|
||||
if (bucket === "running") {
|
||||
if (bucket === "running" || bucket === "waiting") {
|
||||
return theme.colors.statusDotRunning;
|
||||
}
|
||||
if (bucket === "attention") {
|
||||
|
||||
@@ -1,4 +1,10 @@
|
||||
export type StatusLoaderBucket = "needs_input" | "failed" | "running" | "attention" | "done";
|
||||
export type StatusLoaderBucket =
|
||||
| "needs_input"
|
||||
| "failed"
|
||||
| "running"
|
||||
| "waiting"
|
||||
| "attention"
|
||||
| "done";
|
||||
|
||||
export function shouldRenderSyncedStatusLoader(input: {
|
||||
bucket: StatusLoaderBucket | null | undefined;
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import type { WorkspaceDescriptorPayload } from "@getpaseo/protocol/messages";
|
||||
import { render } from "../../output/render.js";
|
||||
import { toWorkspaceRow, workspaceSchema } from "./shared.js";
|
||||
|
||||
function descriptor(status: WorkspaceDescriptorPayload["status"]): WorkspaceDescriptorPayload {
|
||||
return {
|
||||
id: "ws-1",
|
||||
projectId: "project-1",
|
||||
projectDisplayName: "paseo",
|
||||
projectRootPath: "/repo",
|
||||
workspaceDirectory: "/repo",
|
||||
projectKind: "git",
|
||||
workspaceKind: "local_checkout",
|
||||
name: "main",
|
||||
status,
|
||||
statusEnteredAt: null,
|
||||
activityAt: null,
|
||||
} as WorkspaceDescriptorPayload;
|
||||
}
|
||||
|
||||
describe("workspace ls", () => {
|
||||
it("prints the status of each workspace, including waiting", () => {
|
||||
const output = render(
|
||||
{ type: "list", data: [toWorkspaceRow(descriptor("waiting"))], schema: workspaceSchema },
|
||||
{ format: "table", noColor: true },
|
||||
);
|
||||
expect(output).toMatch(/STATUS/);
|
||||
expect(output).toMatch(/waiting/);
|
||||
});
|
||||
});
|
||||
@@ -6,6 +6,7 @@ export interface WorkspaceRow {
|
||||
project: string;
|
||||
name: string;
|
||||
isolation: "local" | "worktree";
|
||||
status: WorkspaceDescriptorPayload["status"];
|
||||
cwd: string;
|
||||
background: boolean;
|
||||
}
|
||||
@@ -17,6 +18,7 @@ export const workspaceSchema: OutputSchema<WorkspaceRow> = {
|
||||
{ header: "PROJECT", field: "project", width: 20 },
|
||||
{ header: "NAME", field: "name", width: 22 },
|
||||
{ header: "ISOLATION", field: "isolation", width: 10 },
|
||||
{ header: "STATUS", field: "status", width: 10 },
|
||||
{ header: "CWD", field: "cwd", width: 42 },
|
||||
],
|
||||
};
|
||||
@@ -36,6 +38,7 @@ export function toWorkspaceRow(workspace: WorkspaceDescriptorPayload): Workspace
|
||||
project: workspace.projectDisplayName,
|
||||
name: workspace.name,
|
||||
isolation: workspace.workspaceKind === "worktree" ? "worktree" : "local",
|
||||
status: workspace.status,
|
||||
cwd: workspace.workspaceDirectory,
|
||||
background: workspace.background === true,
|
||||
};
|
||||
|
||||
@@ -157,6 +157,7 @@ export const DEFAULT_CLIENT_CAPABILITIES = {
|
||||
[CLIENT_CAPS.pluginBinaryPayloads]: true,
|
||||
[CLIENT_CAPS.backgroundAgents]: true,
|
||||
[CLIENT_CAPS.explicitEventSubscriptions]: true,
|
||||
[CLIENT_CAPS.workspaceWaitingStatus]: true,
|
||||
} satisfies Record<
|
||||
Exclude<ClientCapability, typeof CLIENT_CAPS.browserHost | typeof CLIENT_CAPS.frameCodecs>,
|
||||
true
|
||||
|
||||
@@ -1339,6 +1339,7 @@ test("advertises client capabilities in hello", async () => {
|
||||
plugin_binary_payloads: true,
|
||||
workspace_setup_blocked: true,
|
||||
workspace_setup_observation: true,
|
||||
workspace_waiting_status: true,
|
||||
hello_rejection: true,
|
||||
evolvable_hello_rejection: true,
|
||||
background_agents: true,
|
||||
|
||||
@@ -20,7 +20,13 @@ export interface PluginTheme {
|
||||
};
|
||||
}
|
||||
|
||||
export type WorkspaceIndicator = "needs_input" | "failed" | "running" | "attention" | "done";
|
||||
export type WorkspaceIndicator =
|
||||
| "needs_input"
|
||||
| "failed"
|
||||
| "running"
|
||||
| "waiting"
|
||||
| "attention"
|
||||
| "done";
|
||||
|
||||
export interface PluginWorkspaceSnapshot {
|
||||
readonly ref: WorkspaceRef;
|
||||
@@ -50,8 +56,12 @@ export interface PluginWorkspaceSnapshot {
|
||||
readonly kind: "directory" | "local_checkout" | "checkout" | "worktree";
|
||||
readonly name: string;
|
||||
readonly title: string | null;
|
||||
/** Raw daemon status; prefer indicator for presentation. */
|
||||
readonly status: "needs_input" | "failed" | "running" | "attention" | "done";
|
||||
/**
|
||||
* Raw daemon status; prefer indicator for presentation. `waiting` means no turn is running and
|
||||
* the workspace is waiting on background work an agent started. Hosts that predate it report
|
||||
* that state as `running`.
|
||||
*/
|
||||
readonly status: WorkspaceIndicator;
|
||||
readonly statusEnteredAt: string | null;
|
||||
readonly archivingAt: string | null;
|
||||
readonly diffStat: { readonly additions: number; readonly deletions: number } | null;
|
||||
|
||||
@@ -3,10 +3,12 @@ import {
|
||||
deriveAgentStateBucket,
|
||||
getAgentStatusPriority,
|
||||
getWorkspaceStateBucketPriority,
|
||||
isAgentBusy,
|
||||
isAgentTurnRunning,
|
||||
} from "./agent-state-bucket.js";
|
||||
|
||||
describe("deriveAgentStateBucket", () => {
|
||||
it("shows idle agents with background work as running while preserving attention precedence", () => {
|
||||
it("shows idle agents with background work as waiting while preserving attention precedence", () => {
|
||||
const backgroundWork = { count: 1 };
|
||||
expect(
|
||||
deriveAgentStateBucket({
|
||||
@@ -15,11 +17,11 @@ describe("deriveAgentStateBucket", () => {
|
||||
requiresAttention: true,
|
||||
attentionReason: "finished",
|
||||
}),
|
||||
).toBe("running");
|
||||
).toBe("waiting");
|
||||
expect(
|
||||
deriveAgentStateBucket({ status: "idle", backgroundWork, attentionReason: "permission" }),
|
||||
).toBe("needs_input");
|
||||
expect(deriveAgentStateBucket({ status: "error", backgroundWork })).toBe("running");
|
||||
expect(deriveAgentStateBucket({ status: "error", backgroundWork })).toBe("waiting");
|
||||
expect(
|
||||
deriveAgentStateBucket({
|
||||
status: "error",
|
||||
@@ -38,7 +40,13 @@ describe("deriveAgentStateBucket", () => {
|
||||
expect(getAgentStatusPriority(passive)).toBe(getAgentStatusPriority({ status: "idle" }));
|
||||
expect(
|
||||
deriveAgentStateBucket({ ...passive, backgroundWork: { count: 2, runningCount: 1 } }),
|
||||
).toBe("running");
|
||||
).toBe("waiting");
|
||||
});
|
||||
|
||||
it("keeps a running turn as running while background work is alive", () => {
|
||||
expect(deriveAgentStateBucket({ status: "running", backgroundWork: { count: 1 } })).toBe(
|
||||
"running",
|
||||
);
|
||||
});
|
||||
|
||||
it("prioritizes pending permissions as needs_input", () => {
|
||||
@@ -122,11 +130,25 @@ describe("deriveAgentStateBucket", () => {
|
||||
describe("getWorkspaceStateBucketPriority", () => {
|
||||
it("orders active buckets before done", () => {
|
||||
expect(
|
||||
["done", "attention", "running", "failed", "needs_input"].sort(
|
||||
["done", "attention", "waiting", "running", "failed", "needs_input"].sort(
|
||||
(left, right) =>
|
||||
getWorkspaceStateBucketPriority(left) - getWorkspaceStateBucketPriority(right),
|
||||
),
|
||||
).toEqual(["needs_input", "failed", "running", "attention", "done"]);
|
||||
).toEqual(["needs_input", "failed", "running", "waiting", "attention", "done"]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("agent busy predicates", () => {
|
||||
it("separates a running turn from counted background work", () => {
|
||||
const idleWithWork = { status: "idle", backgroundWork: { count: 1 } } as const;
|
||||
expect(isAgentTurnRunning(idleWithWork)).toBe(false);
|
||||
expect(isAgentBusy(idleWithWork)).toBe(true);
|
||||
expect(isAgentTurnRunning({ status: "running" })).toBe(true);
|
||||
expect(isAgentBusy({ status: "running" })).toBe(true);
|
||||
expect(isAgentBusy({ status: "idle", backgroundWork: { count: 1, runningCount: 0 } })).toBe(
|
||||
false,
|
||||
);
|
||||
expect(isAgentBusy({ status: "idle" })).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -12,20 +12,33 @@ export interface AgentStateBucketInput {
|
||||
backgroundWork?: AgentBackgroundWorkSummary | null;
|
||||
}
|
||||
|
||||
export function isAgentRunning(input: {
|
||||
interface AgentActivityInput {
|
||||
status: AgentLifecycleStatus | null | undefined;
|
||||
backgroundWork?: AgentBackgroundWorkSummary | null;
|
||||
}): boolean {
|
||||
const { status, backgroundWork } = input;
|
||||
return status === "running" || (backgroundWork?.runningCount ?? backgroundWork?.count ?? 0) > 0;
|
||||
}
|
||||
|
||||
/** A turn is running. Background work alone does not make this true. */
|
||||
export function isAgentTurnRunning(input: Pick<AgentActivityInput, "status">): boolean {
|
||||
return input.status === "running";
|
||||
}
|
||||
|
||||
function hasCountedBackgroundWork(input: Pick<AgentActivityInput, "backgroundWork">): boolean {
|
||||
const { backgroundWork } = input;
|
||||
return (backgroundWork?.runningCount ?? backgroundWork?.count ?? 0) > 0;
|
||||
}
|
||||
|
||||
/** Running a turn, or waiting on counted background work after the turn ended. */
|
||||
export function isAgentBusy(input: AgentActivityInput): boolean {
|
||||
return isAgentTurnRunning(input) || hasCountedBackgroundWork(input);
|
||||
}
|
||||
|
||||
const WORKSPACE_STATE_BUCKET_PRIORITY = {
|
||||
needs_input: 0,
|
||||
failed: 1,
|
||||
running: 2,
|
||||
attention: 3,
|
||||
done: 4,
|
||||
waiting: 3,
|
||||
attention: 4,
|
||||
done: 5,
|
||||
} as const satisfies Record<WorkspaceStateBucket, number>;
|
||||
|
||||
// An error is a notification like a finish: once the user has seen it, the agent stops showing as
|
||||
@@ -41,9 +54,12 @@ export function deriveAgentStateBucket(input: AgentStateBucketInput): WorkspaceS
|
||||
if (hasUnreadError(input)) {
|
||||
return "failed";
|
||||
}
|
||||
if (isAgentRunning(input)) {
|
||||
if (isAgentTurnRunning(input)) {
|
||||
return "running";
|
||||
}
|
||||
if (hasCountedBackgroundWork(input)) {
|
||||
return "waiting";
|
||||
}
|
||||
if (input.requiresAttention) {
|
||||
return "attention";
|
||||
}
|
||||
@@ -61,7 +77,8 @@ export function getAgentStatusPriority(input: AgentStateBucketInput): number {
|
||||
if (hasUnreadError(input)) {
|
||||
return 1;
|
||||
}
|
||||
if (isAgentRunning(input)) {
|
||||
// Lists keep every busy agent together; running versus waiting is a display distinction.
|
||||
if (isAgentBusy(input)) {
|
||||
return 2;
|
||||
}
|
||||
if (input.status === "initializing") {
|
||||
|
||||
@@ -73,6 +73,10 @@ export const CLIENT_CAPS = {
|
||||
// An agent sender's steer means wait-for-turn-end from clients without it, because older
|
||||
// CLIs and connected hosts send an explicit steer for every default agent send.
|
||||
agentActiveTurnBehaviors: "agent_active_turn_behaviors",
|
||||
// COMPAT(workspaceWaitingStatus): added in v0.19.3, remove after 2027-06-06 once client floor >= v0.19.3.
|
||||
// Older clients validate workspace `status` against a closed enum and drop a workspace carrying
|
||||
// "waiting"; the daemon sends them "running", which is what they showed for this state before.
|
||||
workspaceWaitingStatus: "workspace_waiting_status",
|
||||
} as const;
|
||||
|
||||
export type ClientCapability = (typeof CLIENT_CAPS)[keyof typeof CLIENT_CAPS];
|
||||
|
||||
@@ -1550,6 +1550,7 @@ const WorkspaceStateBucketSchema = z.enum([
|
||||
"needs_input",
|
||||
"failed",
|
||||
"running",
|
||||
"waiting",
|
||||
"attention",
|
||||
"done",
|
||||
]);
|
||||
|
||||
@@ -122,6 +122,28 @@ describe("MockLoadTestAgentClient", () => {
|
||||
expect(events.at(-1)).toMatchObject({ type: "turn_completed", provider: "mock" });
|
||||
});
|
||||
|
||||
test("a background shell command outlives the turn that started it", async () => {
|
||||
vi.useFakeTimers();
|
||||
const client = new MockLoadTestAgentClient();
|
||||
const session = await client.createSession({ provider: "mock", cwd: process.cwd() });
|
||||
const events: AgentStreamEvent[] = [];
|
||||
session.subscribe((event) => events.push(event));
|
||||
|
||||
const run = session.run("Please start a background shell command for 5000ms.");
|
||||
await vi.advanceTimersByTimeAsync(1);
|
||||
await run;
|
||||
|
||||
const types = events.map((event) =>
|
||||
event.type === "background_work" ? `background_work:${event.items?.length}` : event.type,
|
||||
);
|
||||
expect(types.indexOf("background_work:1")).toBeGreaterThan(-1);
|
||||
expect(types.indexOf("background_work:1")).toBeLessThan(types.indexOf("turn_completed"));
|
||||
expect(types.at(-1)).toBe("turn_completed");
|
||||
|
||||
await vi.advanceTimersByTimeAsync(5_000);
|
||||
expect(events.at(-1)).toMatchObject({ type: "background_work", items: [] });
|
||||
});
|
||||
|
||||
test("can withhold the provider user-message echo until an immediate interrupt", async () => {
|
||||
vi.useFakeTimers();
|
||||
const client = new MockLoadTestAgentClient();
|
||||
|
||||
@@ -288,6 +288,17 @@ function parseHeldToolCallMs(prompt: AgentPromptInput): number | null {
|
||||
return Number.isSafeInteger(holdMs) ? Math.min(holdMs, MAX_HELD_TOOL_CALL_MS) : null;
|
||||
}
|
||||
|
||||
// A turn that starts a shell command in the background and ends. The command stays in the
|
||||
// agent's background work for the given time, so the agent is waiting with no turn running.
|
||||
function parseBackgroundShellMs(prompt: AgentPromptInput): number | null {
|
||||
const match = /start a background shell command for (\d+)ms/i.exec(promptToText(prompt));
|
||||
if (!match) {
|
||||
return null;
|
||||
}
|
||||
const durationMs = Number(match[1]);
|
||||
return Number.isSafeInteger(durationMs) ? Math.min(durationMs, MAX_HELD_TOOL_CALL_MS) : null;
|
||||
}
|
||||
|
||||
function parseSettledAssistantImageMarkdown(prompt: AgentPromptInput): string | null {
|
||||
const match = /^emit settled assistant image markdown:\s*(!\[[^\]\r\n]*\]\(.+\))\s*$/i.exec(
|
||||
promptToText(prompt),
|
||||
@@ -960,11 +971,14 @@ export class MockLoadTestAgentSession implements AgentSession {
|
||||
const settledAssistantImageMarkdown = parseSettledAssistantImageMarkdown(prompt);
|
||||
const steeringReplayShape = parseSteeringReplayShape(prompt);
|
||||
const heldToolCallMs = parseHeldToolCallMs(prompt);
|
||||
const backgroundShellMs = parseBackgroundShellMs(prompt);
|
||||
const scheduleTurn = () => {
|
||||
if (shouldEmitTurnFailure(prompt)) {
|
||||
this.scheduleFailedTurn(turn);
|
||||
} else if (heldToolCallMs !== null) {
|
||||
this.scheduleHeldToolCallTurn(turn, heldToolCallMs);
|
||||
} else if (backgroundShellMs !== null) {
|
||||
this.scheduleBackgroundShellTurn(turn, backgroundShellMs);
|
||||
} else if (steeringReplayShape) {
|
||||
this.scheduleSteeringReplayTurn(turn, steeringReplayShape);
|
||||
} else if (this.streamingAssistantResponse !== null) {
|
||||
@@ -1369,6 +1383,32 @@ export class MockLoadTestAgentSession implements AgentSession {
|
||||
turn.timer.unref?.();
|
||||
}
|
||||
|
||||
private scheduleBackgroundShellTurn(turn: ActiveTurn, durationMs: number): void {
|
||||
turn.timer = setTimeout(() => {
|
||||
if (this.activeTurn !== turn) return;
|
||||
this.clearTurnTimer(turn);
|
||||
this.emitTurnStarted(turn);
|
||||
this.emit({
|
||||
type: "background_work",
|
||||
provider: this.provider,
|
||||
items: [
|
||||
{
|
||||
id: `${turn.turnId}:background-shell`,
|
||||
kind: "shell",
|
||||
description: `sleep ${Math.ceil(durationMs / 1000)}`,
|
||||
command: `sleep ${Math.ceil(durationMs / 1000)}`,
|
||||
},
|
||||
],
|
||||
});
|
||||
this.emitSettledAssistantTurn(turn, "Started a background shell command.");
|
||||
const finish = setTimeout(() => {
|
||||
this.emit({ type: "background_work", provider: this.provider, items: [] });
|
||||
}, durationMs);
|
||||
finish.unref?.();
|
||||
}, 0);
|
||||
turn.timer.unref?.();
|
||||
}
|
||||
|
||||
private scheduleSplitClosingFenceTurn(turn: ActiveTurn): void {
|
||||
const chunks = [...SPLIT_CLOSING_FENCE_CHUNKS];
|
||||
const finalText = chunks.map((chunk) => chunk.text).join("");
|
||||
|
||||
@@ -127,6 +127,7 @@ import { toWireDaemonConfig, type DaemonConfigStore } from "./daemon-config-stor
|
||||
import { releaseWorkspaceServicePortPlan } from "./workspace-service-port-registry.js";
|
||||
import { getErrorMessage, getErrorMessageOr } from "@getpaseo/protocol/error-utils";
|
||||
import { getAgentStatusPriority } from "@getpaseo/protocol/agent-state-bucket";
|
||||
import { workspaceStatusForClient } from "./workspace-waiting-status-compat.js";
|
||||
import { getParentAgentIdFromLabels } from "@getpaseo/protocol/agent-labels";
|
||||
import { applyRecordPatch } from "./record-patch.js";
|
||||
import type { WorkspaceGitRuntimeSnapshot, WorkspaceGitService } from "./workspace-git-service.js";
|
||||
@@ -877,7 +878,7 @@ export class Session {
|
||||
return this.onBinaryMessageToSource(source, frame);
|
||||
} else this.emitBinary(frame);
|
||||
},
|
||||
(source, message) => this.workspaceSetupMessageForClient(message, source),
|
||||
(source, message) => this.messageForClient(message, source),
|
||||
(request, message) =>
|
||||
this.sessionLogger.warn(
|
||||
{
|
||||
@@ -10558,7 +10559,7 @@ export class Session {
|
||||
!this.delivery.isModern(source) &&
|
||||
this.wantsEvent(event, source)
|
||||
)
|
||||
this.onMessageToSource(source, this.workspaceSetupMessageForClient(message, source));
|
||||
this.onMessageToSource(source, this.messageForClient(message, source));
|
||||
}
|
||||
} else if (delivered.size === 0 && this.wantsEvent(event)) this.onMessage(message);
|
||||
return true;
|
||||
@@ -10588,13 +10589,26 @@ export class Session {
|
||||
if (msg.type === "workspace_setup_status_response") {
|
||||
if (this.clientSources.size > 0 && this.onMessageToSource) {
|
||||
for (const [source] of this.clientSources) {
|
||||
this.onMessageToSource(source, this.workspaceSetupMessageForClient(msg, source));
|
||||
this.onMessageToSource(source, this.messageForClient(msg, source));
|
||||
}
|
||||
return;
|
||||
}
|
||||
msg = this.workspaceSetupMessageForClient(msg);
|
||||
}
|
||||
this.onMessage(msg);
|
||||
this.onMessage(this.messageForClient(msg));
|
||||
}
|
||||
|
||||
/** Adapts one outbound message to what the receiving client's capabilities can read. */
|
||||
private messageForClient(
|
||||
message: SessionOutboundMessage,
|
||||
source?: object,
|
||||
): SessionOutboundMessage {
|
||||
const supportsWaiting = source
|
||||
? this.supportsForSource(CLIENT_CAPS.workspaceWaitingStatus, source)
|
||||
: this.supports(CLIENT_CAPS.workspaceWaitingStatus);
|
||||
return workspaceStatusForClient(
|
||||
this.workspaceSetupMessageForClient(message, source),
|
||||
supportsWaiting,
|
||||
);
|
||||
}
|
||||
|
||||
// COMPAT(workspaceSetupBlocked): added in v0.8.0, remove after 2027-03-07 once client floor >= v0.8.0.
|
||||
|
||||
@@ -252,6 +252,7 @@ function makeAgent(input: {
|
||||
attentionReason?: AgentSnapshotPayload["attentionReason"];
|
||||
attentionTimestamp?: string | null;
|
||||
labels?: Record<string, string>;
|
||||
backgroundWork?: AgentSnapshotPayload["backgroundWork"];
|
||||
}): AgentSnapshotPayload {
|
||||
const pendingPermissionCount = input.pendingPermissions ?? 0;
|
||||
return {
|
||||
@@ -292,6 +293,7 @@ function makeAgent(input: {
|
||||
requiresAttention: input.requiresAttention ?? false,
|
||||
attentionReason: input.attentionReason ?? null,
|
||||
attentionTimestamp: input.attentionTimestamp ?? null,
|
||||
...(input.backgroundWork ? { backgroundWork: input.backgroundWork } : {}),
|
||||
archivedAt: null,
|
||||
};
|
||||
}
|
||||
@@ -3761,6 +3763,54 @@ test("branch/detached policies and dominant status bucket are deterministic", as
|
||||
expect(result.entries[0]?.status).toBe("needs_input");
|
||||
});
|
||||
|
||||
test("an idle agent with background work makes its workspace waiting only for clients that know the state", async () => {
|
||||
const deliveries = new Map<object, SessionOutboundMessage[]>();
|
||||
const session = createSessionForWorkspaceTests({
|
||||
onMessageToSource: (source, message) => {
|
||||
deliveries.set(source, [...(deliveries.get(source) ?? []), message]);
|
||||
},
|
||||
});
|
||||
session.workspaceRegistry.listAll = session.workspaceRegistry.listActive = async () => [
|
||||
createPersistedWorkspaceRecord({
|
||||
workspaceId: "ws-waiting",
|
||||
projectId: "proj-waiting",
|
||||
cwd: REPO_CWD,
|
||||
kind: "local_checkout",
|
||||
displayName: "repo",
|
||||
createdAt: "2026-03-01T12:00:00.000Z",
|
||||
updatedAt: "2026-03-01T12:00:00.000Z",
|
||||
}),
|
||||
];
|
||||
session.listAgentPayloads = async () => [
|
||||
makeAgent({
|
||||
id: "a1",
|
||||
cwd: REPO_CWD,
|
||||
workspaceId: "ws-waiting",
|
||||
status: "idle",
|
||||
updatedAt: "2026-03-01T12:00:00.000Z",
|
||||
backgroundWork: { count: 1 },
|
||||
}),
|
||||
];
|
||||
|
||||
const olderApp = {};
|
||||
const currentApp = {};
|
||||
session.updateClientCapabilities({}, olderApp);
|
||||
session.updateClientCapabilities({ [CLIENT_CAPS.workspaceWaitingStatus]: true }, currentApp);
|
||||
for (const source of [olderApp, currentApp]) {
|
||||
await session.handleMessage(
|
||||
{ type: "fetch_workspaces_request", requestId: "fetch-waiting" },
|
||||
source,
|
||||
);
|
||||
}
|
||||
|
||||
const statusSeenBy = (source: object) =>
|
||||
filterByType(deliveries.get(source) ?? [], "fetch_workspaces_response").map((message) =>
|
||||
message.payload.entries.map((entry) => entry.status),
|
||||
);
|
||||
expect(statusSeenBy(currentApp)).toEqual([["waiting"]]);
|
||||
expect(statusSeenBy(olderApp)).toEqual([["running"]]);
|
||||
});
|
||||
|
||||
test("subdirectory agents contribute to their owning workspace descriptor", async () => {
|
||||
const session = createSessionForWorkspaceTests();
|
||||
session.workspaceRegistry.listAll = session.workspaceRegistry.listActive = async () => [
|
||||
|
||||
@@ -341,7 +341,7 @@ function createAgent(
|
||||
}
|
||||
|
||||
describe("WorkspaceDirectory", () => {
|
||||
test("treats background work as running without changing foreground status", async () => {
|
||||
test("treats background work as waiting without changing foreground status", async () => {
|
||||
const workspace = new WorkspaceStatus();
|
||||
workspace.hasRootAgent({
|
||||
id: "root-agent",
|
||||
@@ -350,8 +350,28 @@ describe("WorkspaceDirectory", () => {
|
||||
requiresAttention: true,
|
||||
attentionReason: "finished",
|
||||
});
|
||||
await expect(workspace.workspaceStatus()).resolves.toBe("waiting");
|
||||
});
|
||||
|
||||
test("a running turn outranks background work in the same workspace", async () => {
|
||||
const workspace = new WorkspaceStatus();
|
||||
workspace.hasRootAgent({ id: "waiting-root", status: "idle", backgroundWork: { count: 1 } });
|
||||
workspace.hasRootAgent({ id: "running-root", status: "running" });
|
||||
await expect(workspace.workspaceStatus()).resolves.toBe("running");
|
||||
});
|
||||
|
||||
test("same-workspace subagent with background work contributes waiting to its parent workspace", async () => {
|
||||
const workspace = new WorkspaceStatus();
|
||||
|
||||
workspace.hasRootAgent({ id: "parent-agent", status: "idle" });
|
||||
workspace.hasDelegatedAgent({
|
||||
id: "child-agent",
|
||||
status: "idle",
|
||||
backgroundWork: { count: 1 },
|
||||
});
|
||||
|
||||
await expect(workspace.workspaceStatus()).resolves.toBe("waiting");
|
||||
});
|
||||
test("keeps the workspace idle when root and delegated agents only have passive background work", async () => {
|
||||
const workspace = new WorkspaceStatus();
|
||||
const backgroundWork = { count: 1, runningCount: 0 };
|
||||
|
||||
@@ -8,7 +8,8 @@ import type {
|
||||
} from "./messages.js";
|
||||
import {
|
||||
deriveAgentStateBucket,
|
||||
isAgentRunning,
|
||||
isAgentBusy,
|
||||
isAgentTurnRunning,
|
||||
getWorkspaceStateBucketPriority,
|
||||
type WorkspaceStateBucket,
|
||||
} from "@getpaseo/protocol/agent-state-bucket";
|
||||
@@ -428,7 +429,7 @@ export class WorkspaceDirectory {
|
||||
// keeping the highest-priority bucket. A record's owner IS its `workspaceId`;
|
||||
// status never fans out to same-cwd siblings. A subagent in another workspace
|
||||
// is a root for that workspace. Same-workspace descendants contribute only
|
||||
// running activity to the nearest ancestor in that workspace.
|
||||
// running (a turn) or waiting (background work) to the nearest ancestor in that workspace.
|
||||
private applyAgentBucketContributions(params: {
|
||||
activeAgents: AgentSnapshotPayload[];
|
||||
descriptorsByWorkspaceId: Map<string, WorkspaceDescriptorPayload>;
|
||||
@@ -442,7 +443,7 @@ export class WorkspaceDirectory {
|
||||
continue;
|
||||
}
|
||||
const isWorkspaceRoot = workspaceAgent.id === agent.id;
|
||||
if (!isWorkspaceRoot && !isAgentRunning(agent)) {
|
||||
if (!isWorkspaceRoot && !isAgentBusy(agent)) {
|
||||
continue;
|
||||
}
|
||||
const bucket = isWorkspaceRoot
|
||||
@@ -453,7 +454,7 @@ export class WorkspaceDirectory {
|
||||
attentionReason: agent.attentionReason ?? null,
|
||||
backgroundWork: agent.backgroundWork,
|
||||
})
|
||||
: "running";
|
||||
: descendantBucket(agent);
|
||||
|
||||
const workspaceId = workspaceAgent.workspaceId;
|
||||
if (!workspaceId) {
|
||||
@@ -850,6 +851,10 @@ function groupAgentsByWorkspaceId(
|
||||
return byWorkspaceId;
|
||||
}
|
||||
|
||||
function descendantBucket(agent: AgentSnapshotPayload): "running" | "waiting" {
|
||||
return isAgentTurnRunning(agent) ? "running" : "waiting";
|
||||
}
|
||||
|
||||
export function resolveWorkspaceRootAgent(
|
||||
agent: AgentSnapshotPayload,
|
||||
activeAgentsById: ReadonlyMap<string, AgentSnapshotPayload>,
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
import { describe, expect, test } from "vitest";
|
||||
import type { SessionOutboundMessage, WorkspaceDescriptorPayload } from "./messages.js";
|
||||
import { workspaceStatusForClient } from "./workspace-waiting-status-compat.js";
|
||||
|
||||
function descriptor(status: WorkspaceDescriptorPayload["status"]): WorkspaceDescriptorPayload {
|
||||
return {
|
||||
id: "ws-1",
|
||||
projectId: "proj-1",
|
||||
projectDisplayName: "repo",
|
||||
projectRootPath: "/repo",
|
||||
workspaceDirectory: "/repo",
|
||||
projectKind: "git",
|
||||
workspaceKind: "local_checkout",
|
||||
name: "main",
|
||||
status,
|
||||
statusEnteredAt: null,
|
||||
activityAt: null,
|
||||
} as WorkspaceDescriptorPayload;
|
||||
}
|
||||
|
||||
const upsert = (status: WorkspaceDescriptorPayload["status"]): SessionOutboundMessage => ({
|
||||
type: "workspace_update",
|
||||
payload: { kind: "upsert", workspace: descriptor(status) },
|
||||
});
|
||||
|
||||
describe("workspaceStatusForClient", () => {
|
||||
test("an older app gets running in a live workspace update", () => {
|
||||
expect(workspaceStatusForClient(upsert("waiting"), false)).toEqual(upsert("running"));
|
||||
});
|
||||
|
||||
test("an older app gets running in the workspace list", () => {
|
||||
const message: SessionOutboundMessage = {
|
||||
type: "fetch_workspaces_response",
|
||||
payload: {
|
||||
requestId: "r1",
|
||||
entries: [descriptor("waiting"), descriptor("done")],
|
||||
pageInfo: { nextCursor: null, prevCursor: null, hasMore: false },
|
||||
},
|
||||
} as SessionOutboundMessage;
|
||||
const result = workspaceStatusForClient(message, false);
|
||||
expect(
|
||||
result.type === "fetch_workspaces_response" && result.payload.entries.map((e) => e.status),
|
||||
).toEqual(["running", "done"]);
|
||||
});
|
||||
|
||||
test("a current app gets waiting unchanged", () => {
|
||||
const message = upsert("waiting");
|
||||
expect(workspaceStatusForClient(message, true)).toBe(message);
|
||||
});
|
||||
|
||||
test("other statuses pass through for an older app", () => {
|
||||
const message = upsert("attention");
|
||||
expect(workspaceStatusForClient(message, false)).toEqual(message);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,34 @@
|
||||
import type { SessionOutboundMessage, WorkspaceDescriptorPayload } from "./messages.js";
|
||||
|
||||
function withoutWaiting(workspace: WorkspaceDescriptorPayload): WorkspaceDescriptorPayload {
|
||||
return workspace.status === "waiting" ? { ...workspace, status: "running" } : workspace;
|
||||
}
|
||||
|
||||
/**
|
||||
* COMPAT(workspaceWaitingStatus): added in v0.19.3, remove after 2027-06-06 once client floor >= v0.19.3.
|
||||
*
|
||||
* Older clients reject a workspace whose `status` is "waiting" and drop it from lists and updates.
|
||||
* They showed this state as "running" before it had its own value, so they get "running".
|
||||
*
|
||||
* Only these two messages carry a computed status. Every other message that embeds a workspace
|
||||
* descriptor (create, open, worktree responses) carries the record's initial "done".
|
||||
*/
|
||||
export function workspaceStatusForClient(
|
||||
message: SessionOutboundMessage,
|
||||
supportsWaiting: boolean,
|
||||
): SessionOutboundMessage {
|
||||
if (supportsWaiting) return message;
|
||||
if (message.type === "fetch_workspaces_response") {
|
||||
return {
|
||||
...message,
|
||||
payload: { ...message.payload, entries: message.payload.entries.map(withoutWaiting) },
|
||||
};
|
||||
}
|
||||
if (message.type === "workspace_update" && message.payload.kind === "upsert") {
|
||||
return {
|
||||
...message,
|
||||
payload: { ...message.payload, workspace: withoutWaiting(message.payload.workspace) },
|
||||
};
|
||||
}
|
||||
return message;
|
||||
}
|
||||
@@ -2261,23 +2261,23 @@ Both hooks return `null` when the record is unavailable. Otherwise they run sync
|
||||
|
||||
Workspace snapshot fields:
|
||||
|
||||
| Field | Type |
|
||||
| -------------------- | ----------------------------------------------------------------- |
|
||||
| `id` | `string` |
|
||||
| `projectId` | `string` |
|
||||
| `projectDisplayName` | `string` |
|
||||
| `projectRootPath` | `string` |
|
||||
| `directory` | `string` |
|
||||
| `projectKind` | `"git" \| "non_git" \| "directory"` |
|
||||
| `kind` | `"directory" \| "local_checkout" \| "checkout" \| "worktree"` |
|
||||
| `name` | `string` |
|
||||
| `title` | `string \| null` |
|
||||
| `status` | `"needs_input" \| "failed" \| "running" \| "attention" \| "done"` |
|
||||
| `statusEnteredAt` | ISO timestamp or `null` |
|
||||
| `archivingAt` | ISO timestamp or `null` |
|
||||
| `diffStat` | `{ additions: number; deletions: number } \| null` |
|
||||
| `parentWorkspace` | `WorkspaceRef \| null` |
|
||||
| `metadata` | `Readonly<Record<string, JsonValue>>` |
|
||||
| Field | Type |
|
||||
| -------------------- | ------------------------------------------------------------------------------ |
|
||||
| `id` | `string` |
|
||||
| `projectId` | `string` |
|
||||
| `projectDisplayName` | `string` |
|
||||
| `projectRootPath` | `string` |
|
||||
| `directory` | `string` |
|
||||
| `projectKind` | `"git" \| "non_git" \| "directory"` |
|
||||
| `kind` | `"directory" \| "local_checkout" \| "checkout" \| "worktree"` |
|
||||
| `name` | `string` |
|
||||
| `title` | `string \| null` |
|
||||
| `status` | `"needs_input" \| "failed" \| "running" \| "waiting" \| "attention" \| "done"` |
|
||||
| `statusEnteredAt` | ISO timestamp or `null` |
|
||||
| `archivingAt` | ISO timestamp or `null` |
|
||||
| `diffStat` | `{ additions: number; deletions: number } \| null` |
|
||||
| `parentWorkspace` | `WorkspaceRef \| null` |
|
||||
| `metadata` | `Readonly<Record<string, JsonValue>>` |
|
||||
|
||||
Agent snapshot fields:
|
||||
|
||||
|
||||
@@ -1826,23 +1826,23 @@ const [state, setState] = useTabState(tab, schema, { view: "preview" });
|
||||
|
||||
工作区快照字段:
|
||||
|
||||
| 字段 | 类型 |
|
||||
| -------------------- | ----------------------------------------------------------------- |
|
||||
| `id` | `string` |
|
||||
| `projectId` | `string` |
|
||||
| `projectDisplayName` | `string` |
|
||||
| `projectRootPath` | `string` |
|
||||
| `directory` | `string` |
|
||||
| `projectKind` | `"git" \| "non_git" \| "directory"` |
|
||||
| `kind` | `"directory" \| "local_checkout" \| "checkout" \| "worktree"` |
|
||||
| `name` | `string` |
|
||||
| `title` | `string \| null` |
|
||||
| `status` | `"needs_input" \| "failed" \| "running" \| "attention" \| "done"` |
|
||||
| `statusEnteredAt` | ISO 时间戳或 `null` |
|
||||
| `archivingAt` | ISO 时间戳或 `null` |
|
||||
| `diffStat` | `{ additions: number; deletions: number } \| null` |
|
||||
| `parentWorkspace` | `WorkspaceRef \| null` |
|
||||
| `metadata` | `Readonly<Record<string, JsonValue>>` |
|
||||
| 字段 | 类型 |
|
||||
| -------------------- | ------------------------------------------------------------------------------ |
|
||||
| `id` | `string` |
|
||||
| `projectId` | `string` |
|
||||
| `projectDisplayName` | `string` |
|
||||
| `projectRootPath` | `string` |
|
||||
| `directory` | `string` |
|
||||
| `projectKind` | `"git" \| "non_git" \| "directory"` |
|
||||
| `kind` | `"directory" \| "local_checkout" \| "checkout" \| "worktree"` |
|
||||
| `name` | `string` |
|
||||
| `title` | `string \| null` |
|
||||
| `status` | `"needs_input" \| "failed" \| "running" \| "waiting" \| "attention" \| "done"` |
|
||||
| `statusEnteredAt` | ISO 时间戳或 `null` |
|
||||
| `archivingAt` | ISO 时间戳或 `null` |
|
||||
| `diffStat` | `{ additions: number; deletions: number } \| null` |
|
||||
| `parentWorkspace` | `WorkspaceRef \| null` |
|
||||
| `metadata` | `Readonly<Record<string, JsonValue>>` |
|
||||
|
||||
Agent 快照字段:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user