Show initial-agent workspaces as Working
This commit is contained in:
@@ -238,7 +238,13 @@ export async function expectComposerGithubAttachmentPill(
|
|||||||
|
|
||||||
export async function assertNewWorkspaceSidebarAndHeader(
|
export async function assertNewWorkspaceSidebarAndHeader(
|
||||||
page: Page,
|
page: Page,
|
||||||
input: { serverId: string; previousWorkspaceId: string; projectDisplayName: string },
|
input: {
|
||||||
|
serverId: string;
|
||||||
|
previousWorkspaceId: string;
|
||||||
|
projectDisplayName: string;
|
||||||
|
assertSidebarRow?: boolean;
|
||||||
|
assertHeader?: boolean;
|
||||||
|
},
|
||||||
): Promise<{ workspaceId: string }> {
|
): Promise<{ workspaceId: string }> {
|
||||||
// Wait for URL to redirect to the newly created workspace.
|
// Wait for URL to redirect to the newly created workspace.
|
||||||
// Uses URL as source of truth to avoid picking up sidebar rows from concurrent tests.
|
// Uses URL as source of truth to avoid picking up sidebar rows from concurrent tests.
|
||||||
@@ -256,15 +262,19 @@ export async function assertNewWorkspaceSidebarAndHeader(
|
|||||||
throw new Error(`Expected URL to redirect to a new workspace.\nCurrent URL: ${page.url()}`);
|
throw new Error(`Expected URL to redirect to a new workspace.\nCurrent URL: ${page.url()}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const createdWorkspaceRow = page.getByTestId(
|
if (input.assertSidebarRow !== false) {
|
||||||
`sidebar-workspace-row-${input.serverId}:${workspaceId}`,
|
const createdWorkspaceRow = page.getByTestId(
|
||||||
);
|
`sidebar-workspace-row-${input.serverId}:${workspaceId}`,
|
||||||
await expect(createdWorkspaceRow.first()).toBeVisible({ timeout: 30_000 });
|
);
|
||||||
|
await expect(createdWorkspaceRow.first()).toBeVisible({ timeout: 30_000 });
|
||||||
|
}
|
||||||
|
|
||||||
await expectWorkspaceHeader(page, {
|
if (input.assertHeader !== false) {
|
||||||
title: workspaceLabelFromPath(workspaceId),
|
await expectWorkspaceHeader(page, {
|
||||||
subtitle: input.projectDisplayName,
|
title: workspaceLabelFromPath(workspaceId),
|
||||||
});
|
subtitle: input.projectDisplayName,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return { workspaceId };
|
return { workspaceId };
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,6 +38,147 @@ import {
|
|||||||
workspaceLabelFromPath,
|
workspaceLabelFromPath,
|
||||||
} from "./helpers/workspace-ui";
|
} from "./helpers/workspace-ui";
|
||||||
|
|
||||||
|
interface WorkspaceStatusGroupEvent {
|
||||||
|
rowTestId: string;
|
||||||
|
bucket: string;
|
||||||
|
indicatorTestId: string | null;
|
||||||
|
label: string;
|
||||||
|
at: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function switchSidebarToStatusGrouping(page: import("@playwright/test").Page) {
|
||||||
|
await page.getByTestId("sidebar-grouping-selector").click();
|
||||||
|
await page.getByTestId("sidebar-grouping-status").click();
|
||||||
|
await expect(page.getByTestId("sidebar-status-group-done")).toBeVisible({ timeout: 30_000 });
|
||||||
|
}
|
||||||
|
|
||||||
|
async function startTrackingSidebarStatusGroups(page: import("@playwright/test").Page) {
|
||||||
|
await page.evaluate(() => {
|
||||||
|
interface StatusGroupEvent {
|
||||||
|
rowTestId: string;
|
||||||
|
bucket: string;
|
||||||
|
indicatorTestId: string | null;
|
||||||
|
label: string;
|
||||||
|
at: number;
|
||||||
|
}
|
||||||
|
const win = window as typeof window & {
|
||||||
|
__workspaceStatusGroupEvents?: StatusGroupEvent[];
|
||||||
|
__workspaceStatusGroupObserver?: MutationObserver;
|
||||||
|
};
|
||||||
|
win.__workspaceStatusGroupEvents = [];
|
||||||
|
win.__workspaceStatusGroupObserver?.disconnect();
|
||||||
|
|
||||||
|
const capture = () => {
|
||||||
|
const events = win.__workspaceStatusGroupEvents;
|
||||||
|
if (!events) return;
|
||||||
|
const groups = document.querySelectorAll<HTMLElement>(
|
||||||
|
'[data-testid^="sidebar-status-group-"]',
|
||||||
|
);
|
||||||
|
for (const group of groups) {
|
||||||
|
const groupTestId = group.getAttribute("data-testid") ?? "";
|
||||||
|
const bucket = groupTestId.replace("sidebar-status-group-", "");
|
||||||
|
const label = group.textContent ?? "";
|
||||||
|
const block = group.parentElement?.parentElement;
|
||||||
|
if (!block) continue;
|
||||||
|
const rows = block.querySelectorAll<HTMLElement>('[data-testid^="sidebar-workspace-row-"]');
|
||||||
|
for (const row of rows) {
|
||||||
|
const rowTestId = row.getAttribute("data-testid");
|
||||||
|
if (!rowTestId) continue;
|
||||||
|
const indicatorTestId =
|
||||||
|
row
|
||||||
|
.querySelector<HTMLElement>('[data-testid^="workspace-status-indicator-"]')
|
||||||
|
?.getAttribute("data-testid") ?? null;
|
||||||
|
const last = events.at(-1);
|
||||||
|
if (
|
||||||
|
last?.rowTestId === rowTestId &&
|
||||||
|
last.bucket === bucket &&
|
||||||
|
last.indicatorTestId === indicatorTestId
|
||||||
|
) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
events.push({ rowTestId, bucket, indicatorTestId, label, at: performance.now() });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
capture();
|
||||||
|
const observer = new MutationObserver(capture);
|
||||||
|
observer.observe(document.body, { childList: true, subtree: true, characterData: true });
|
||||||
|
win.__workspaceStatusGroupObserver = observer;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getTrackedSidebarStatusGroups(
|
||||||
|
page: import("@playwright/test").Page,
|
||||||
|
): Promise<WorkspaceStatusGroupEvent[]> {
|
||||||
|
return page.evaluate(() => {
|
||||||
|
const win = window as typeof window & {
|
||||||
|
__workspaceStatusGroupEvents?: WorkspaceStatusGroupEvent[];
|
||||||
|
};
|
||||||
|
return win.__workspaceStatusGroupEvents ?? [];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function waitForWorkspaceStatusGroupEvent(input: {
|
||||||
|
page: import("@playwright/test").Page;
|
||||||
|
rowTestId: string;
|
||||||
|
bucket: string;
|
||||||
|
}) {
|
||||||
|
await input.page.waitForFunction(
|
||||||
|
({ expectedRowTestId, expectedBucket }) => {
|
||||||
|
const win = window as typeof window & {
|
||||||
|
__workspaceStatusGroupEvents?: WorkspaceStatusGroupEvent[];
|
||||||
|
};
|
||||||
|
for (const event of win.__workspaceStatusGroupEvents ?? []) {
|
||||||
|
if (event.rowTestId === expectedRowTestId && event.bucket === expectedBucket) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
},
|
||||||
|
{ expectedRowTestId: input.rowTestId, expectedBucket: input.bucket },
|
||||||
|
{ timeout: 30_000 },
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function expectWorkspaceStatusGroupEvents(input: {
|
||||||
|
page: import("@playwright/test").Page;
|
||||||
|
rowTestId: string;
|
||||||
|
includes: string;
|
||||||
|
excludes: string;
|
||||||
|
includesIndicator?: string;
|
||||||
|
excludesIndicator?: string;
|
||||||
|
}) {
|
||||||
|
await waitForWorkspaceStatusGroupEvent({
|
||||||
|
page: input.page,
|
||||||
|
rowTestId: input.rowTestId,
|
||||||
|
bucket: input.includes,
|
||||||
|
});
|
||||||
|
const createdWorkspaceEvents = (await getTrackedSidebarStatusGroups(input.page)).filter(
|
||||||
|
(event) => event.rowTestId === input.rowTestId,
|
||||||
|
);
|
||||||
|
expect(createdWorkspaceEvents.map((event) => event.bucket)).toContain(input.includes);
|
||||||
|
expect(createdWorkspaceEvents.filter((event) => event.bucket === input.excludes)).toEqual([]);
|
||||||
|
if (input.includesIndicator) {
|
||||||
|
expect(createdWorkspaceEvents.map((event) => event.indicatorTestId)).toContain(
|
||||||
|
input.includesIndicator,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (input.excludesIndicator) {
|
||||||
|
expect(
|
||||||
|
createdWorkspaceEvents.filter((event) => event.indicatorTestId === input.excludesIndicator),
|
||||||
|
).toEqual([]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function submitNewWorkspaceWithoutPrompt(page: import("@playwright/test").Page) {
|
||||||
|
const createButton = page
|
||||||
|
.getByTestId("message-input-root")
|
||||||
|
.getByRole("button", { name: "Create" });
|
||||||
|
await expect(createButton).toBeVisible({ timeout: 30_000 });
|
||||||
|
await createButton.click();
|
||||||
|
}
|
||||||
|
|
||||||
test.describe("New workspace flow", () => {
|
test.describe("New workspace flow", () => {
|
||||||
let client: Awaited<ReturnType<typeof connectNewWorkspaceDaemonClient>>;
|
let client: Awaited<ReturnType<typeof connectNewWorkspaceDaemonClient>>;
|
||||||
const localWorkspaceIds = new Set<string>();
|
const localWorkspaceIds = new Set<string>();
|
||||||
@@ -227,6 +368,8 @@ test.describe("New workspace flow", () => {
|
|||||||
serverId,
|
serverId,
|
||||||
previousWorkspaceId: openedProject.workspaceId,
|
previousWorkspaceId: openedProject.workspaceId,
|
||||||
projectDisplayName: openedProject.projectDisplayName,
|
projectDisplayName: openedProject.projectDisplayName,
|
||||||
|
assertSidebarRow: false,
|
||||||
|
assertHeader: false,
|
||||||
});
|
});
|
||||||
createdWorktreeIds.add(createdWorkspace.workspaceId);
|
createdWorktreeIds.add(createdWorkspace.workspaceId);
|
||||||
|
|
||||||
@@ -313,6 +456,8 @@ test.describe("New workspace flow", () => {
|
|||||||
serverId,
|
serverId,
|
||||||
previousWorkspaceId: openedProject.workspaceId,
|
previousWorkspaceId: openedProject.workspaceId,
|
||||||
projectDisplayName: openedProject.projectDisplayName,
|
projectDisplayName: openedProject.projectDisplayName,
|
||||||
|
assertSidebarRow: false,
|
||||||
|
assertHeader: false,
|
||||||
});
|
});
|
||||||
createdWorktreeIds.add(createdWorkspace.workspaceId);
|
createdWorktreeIds.add(createdWorkspace.workspaceId);
|
||||||
|
|
||||||
@@ -344,6 +489,117 @@ test.describe("New workspace flow", () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("new workspace with initial agent never appears in the Done status group", async ({
|
||||||
|
page,
|
||||||
|
}) => {
|
||||||
|
const serverId = getServerId();
|
||||||
|
|
||||||
|
const tempRepo = await createTempGitRepo("new-workspace-status-optimistic-");
|
||||||
|
|
||||||
|
try {
|
||||||
|
const openedProject = await openProjectViaDaemon(client, tempRepo.path);
|
||||||
|
localWorkspaceIds.add(openedProject.workspaceId);
|
||||||
|
|
||||||
|
await gotoAppShell(page);
|
||||||
|
await waitForSidebarHydration(page);
|
||||||
|
|
||||||
|
await switchWorkspaceViaSidebar({
|
||||||
|
page,
|
||||||
|
serverId,
|
||||||
|
targetWorkspacePath: openedProject.workspaceId,
|
||||||
|
});
|
||||||
|
await expectWorkspaceHeader(page, {
|
||||||
|
title: openedProject.workspaceName,
|
||||||
|
subtitle: openedProject.projectDisplayName,
|
||||||
|
});
|
||||||
|
|
||||||
|
await switchSidebarToStatusGrouping(page);
|
||||||
|
await startTrackingSidebarStatusGroups(page);
|
||||||
|
|
||||||
|
await openGlobalNewWorkspaceComposer(page);
|
||||||
|
await expectNewWorkspaceProjectSelected(page, openedProject.projectDisplayName);
|
||||||
|
await submitNewWorkspacePrompt(page);
|
||||||
|
|
||||||
|
const createdWorkspace = await assertNewWorkspaceSidebarAndHeader(page, {
|
||||||
|
serverId,
|
||||||
|
previousWorkspaceId: openedProject.workspaceId,
|
||||||
|
projectDisplayName: openedProject.projectDisplayName,
|
||||||
|
assertSidebarRow: false,
|
||||||
|
assertHeader: false,
|
||||||
|
});
|
||||||
|
createdWorktreeIds.add(createdWorkspace.workspaceId);
|
||||||
|
|
||||||
|
const rowTestId = `sidebar-workspace-row-${serverId}:${createdWorkspace.workspaceId}`;
|
||||||
|
await expectWorkspaceStatusGroupEvents({
|
||||||
|
page,
|
||||||
|
rowTestId,
|
||||||
|
includes: "running",
|
||||||
|
excludes: "done",
|
||||||
|
includesIndicator: "workspace-status-indicator-running",
|
||||||
|
});
|
||||||
|
} finally {
|
||||||
|
await tempRepo.cleanup();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
test("new workspace without an initial agent appears in the Done status group", async ({
|
||||||
|
page,
|
||||||
|
}) => {
|
||||||
|
const serverId = getServerId();
|
||||||
|
|
||||||
|
const tempRepo = await createTempGitRepo("new-workspace-status-empty-");
|
||||||
|
|
||||||
|
try {
|
||||||
|
const openedProject = await openProjectViaDaemon(client, tempRepo.path);
|
||||||
|
localWorkspaceIds.add(openedProject.workspaceId);
|
||||||
|
|
||||||
|
await gotoAppShell(page);
|
||||||
|
await waitForSidebarHydration(page);
|
||||||
|
|
||||||
|
await switchWorkspaceViaSidebar({
|
||||||
|
page,
|
||||||
|
serverId,
|
||||||
|
targetWorkspacePath: openedProject.workspaceId,
|
||||||
|
});
|
||||||
|
await expectWorkspaceHeader(page, {
|
||||||
|
title: openedProject.workspaceName,
|
||||||
|
subtitle: openedProject.projectDisplayName,
|
||||||
|
});
|
||||||
|
|
||||||
|
await switchSidebarToStatusGrouping(page);
|
||||||
|
await startTrackingSidebarStatusGroups(page);
|
||||||
|
|
||||||
|
await openGlobalNewWorkspaceComposer(page);
|
||||||
|
await expectNewWorkspaceProjectSelected(page, openedProject.projectDisplayName);
|
||||||
|
await submitNewWorkspaceWithoutPrompt(page);
|
||||||
|
|
||||||
|
const createdWorkspace = await assertNewWorkspaceSidebarAndHeader(page, {
|
||||||
|
serverId,
|
||||||
|
previousWorkspaceId: openedProject.workspaceId,
|
||||||
|
projectDisplayName: openedProject.projectDisplayName,
|
||||||
|
});
|
||||||
|
createdWorktreeIds.add(createdWorkspace.workspaceId);
|
||||||
|
|
||||||
|
const rowTestId = `sidebar-workspace-row-${serverId}:${createdWorkspace.workspaceId}`;
|
||||||
|
await expectWorkspaceStatusGroupEvents({
|
||||||
|
page,
|
||||||
|
rowTestId,
|
||||||
|
includes: "done",
|
||||||
|
excludes: "running",
|
||||||
|
excludesIndicator: "workspace-status-indicator-loading",
|
||||||
|
});
|
||||||
|
await expectWorkspaceStatusGroupEvents({
|
||||||
|
page,
|
||||||
|
rowTestId,
|
||||||
|
includes: "done",
|
||||||
|
excludes: "running",
|
||||||
|
excludesIndicator: "workspace-status-indicator-running",
|
||||||
|
});
|
||||||
|
} finally {
|
||||||
|
await tempRepo.cleanup();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
test("selected branch becomes the base of a new workspace worktree", async ({ page }) => {
|
test("selected branch becomes the base of a new workspace worktree", async ({ page }) => {
|
||||||
const serverId = getServerId();
|
const serverId = getServerId();
|
||||||
|
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ import {
|
|||||||
parseHostWorkspaceRouteFromPathname,
|
parseHostWorkspaceRouteFromPathname,
|
||||||
} from "@/utils/host-routes";
|
} from "@/utils/host-routes";
|
||||||
import {
|
import {
|
||||||
createSidebarWorkspaceEntry,
|
useSidebarWorkspaceEntry,
|
||||||
type SidebarProjectEntry,
|
type SidebarProjectEntry,
|
||||||
type SidebarWorkspaceEntry,
|
type SidebarWorkspaceEntry,
|
||||||
} from "@/hooks/use-sidebar-workspaces-list";
|
} from "@/hooks/use-sidebar-workspaces-list";
|
||||||
@@ -105,8 +105,8 @@ import {
|
|||||||
SidebarWorkspaceTrailingActionSlot,
|
SidebarWorkspaceTrailingActionSlot,
|
||||||
} from "@/components/sidebar/sidebar-workspace-row-content";
|
} from "@/components/sidebar/sidebar-workspace-row-content";
|
||||||
import {
|
import {
|
||||||
useHydratedWorkspaceEntries,
|
|
||||||
useProjectNamesMap,
|
useProjectNamesMap,
|
||||||
|
useStatusModeWorkspaceEntries,
|
||||||
} from "@/hooks/use-status-mode-workspaces";
|
} from "@/hooks/use-status-mode-workspaces";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
|
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
|
||||||
@@ -117,8 +117,7 @@ import { useKeyboardActionHandler } from "@/hooks/use-keyboard-action-handler";
|
|||||||
import { useClearWorkspaceAttention } from "@/hooks/use-clear-workspace-attention";
|
import { useClearWorkspaceAttention } from "@/hooks/use-clear-workspace-attention";
|
||||||
import type { PrHint } from "@/git/use-pr-status-query";
|
import type { PrHint } from "@/git/use-pr-status-query";
|
||||||
import { buildSidebarProjectRowModel } from "@/utils/sidebar-project-row-model";
|
import { buildSidebarProjectRowModel } from "@/utils/sidebar-project-row-model";
|
||||||
import { useSessionStore, type WorkspaceDescriptor } from "@/stores/session-store";
|
import { useSessionStore } from "@/stores/session-store";
|
||||||
import { useWorkspaceFields } from "@/stores/session-store-hooks";
|
|
||||||
import { redirectIfArchivingActiveWorkspace } from "@/utils/sidebar-workspace-archive-redirect";
|
import { redirectIfArchivingActiveWorkspace } from "@/utils/sidebar-workspace-archive-redirect";
|
||||||
import { openExternalUrl } from "@/utils/open-external-url";
|
import { openExternalUrl } from "@/utils/open-external-url";
|
||||||
import {
|
import {
|
||||||
@@ -293,19 +292,6 @@ function getWorkspaceArchiveStatus(
|
|||||||
return "idle";
|
return "idle";
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useSidebarWorkspaceEntry(
|
|
||||||
serverId: string | null,
|
|
||||||
workspaceId: string | null,
|
|
||||||
): SidebarWorkspaceEntry | null {
|
|
||||||
const projectWorkspaceEntry = useCallback(
|
|
||||||
(workspace: WorkspaceDescriptor): SidebarWorkspaceEntry =>
|
|
||||||
createSidebarWorkspaceEntry({ serverId: serverId ?? "", workspace }),
|
|
||||||
[serverId],
|
|
||||||
);
|
|
||||||
|
|
||||||
return useWorkspaceFields(serverId, workspaceId, projectWorkspaceEntry);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function PrBadge({ hint }: { hint: PrHint }) {
|
export function PrBadge({ hint }: { hint: PrHint }) {
|
||||||
const [isHovered, setIsHovered] = useState(false);
|
const [isHovered, setIsHovered] = useState(false);
|
||||||
|
|
||||||
@@ -2382,6 +2368,7 @@ export function SidebarWorkspaceList({
|
|||||||
return (
|
return (
|
||||||
<SidebarStatusModeWrapper
|
<SidebarStatusModeWrapper
|
||||||
serverId={serverId}
|
serverId={serverId}
|
||||||
|
projects={projects}
|
||||||
shortcutIndexByWorkspaceKey={shortcutIndexByWorkspaceKey}
|
shortcutIndexByWorkspaceKey={shortcutIndexByWorkspaceKey}
|
||||||
onWorkspacePress={onWorkspacePress}
|
onWorkspacePress={onWorkspacePress}
|
||||||
/>
|
/>
|
||||||
@@ -2406,14 +2393,16 @@ export function SidebarWorkspaceList({
|
|||||||
|
|
||||||
function SidebarStatusModeWrapper({
|
function SidebarStatusModeWrapper({
|
||||||
serverId,
|
serverId,
|
||||||
|
projects,
|
||||||
shortcutIndexByWorkspaceKey: _projectShortcutIndex,
|
shortcutIndexByWorkspaceKey: _projectShortcutIndex,
|
||||||
onWorkspacePress,
|
onWorkspacePress,
|
||||||
}: {
|
}: {
|
||||||
serverId: string | null;
|
serverId: string | null;
|
||||||
|
projects: SidebarProjectEntry[];
|
||||||
shortcutIndexByWorkspaceKey: Map<string, number>;
|
shortcutIndexByWorkspaceKey: Map<string, number>;
|
||||||
onWorkspacePress?: () => void;
|
onWorkspacePress?: () => void;
|
||||||
}) {
|
}) {
|
||||||
const hydratedWorkspaces = useHydratedWorkspaceEntries(serverId);
|
const hydratedWorkspaces = useStatusModeWorkspaceEntries({ serverId, projects });
|
||||||
const projectNamesByKey = useProjectNamesMap(serverId);
|
const projectNamesByKey = useProjectNamesMap(serverId);
|
||||||
const showShortcutBadges = useShowShortcutBadges();
|
const showShortcutBadges = useShowShortcutBadges();
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ import {
|
|||||||
Pencil,
|
Pencil,
|
||||||
} from "lucide-react-native";
|
} from "lucide-react-native";
|
||||||
import { DiffStat } from "@/components/diff-stat";
|
import { DiffStat } from "@/components/diff-stat";
|
||||||
import { useSidebarWorkspaceEntry } from "../sidebar-workspace-list";
|
import { useSidebarWorkspaceEntry } from "@/hooks/use-sidebar-workspaces-list";
|
||||||
import {
|
import {
|
||||||
DropdownMenu,
|
DropdownMenu,
|
||||||
DropdownMenuTrigger,
|
DropdownMenuTrigger,
|
||||||
|
|||||||
@@ -186,7 +186,7 @@ function WorkspaceStatusIndicator({
|
|||||||
|
|
||||||
if (loading) {
|
if (loading) {
|
||||||
return (
|
return (
|
||||||
<View style={styles.workspaceStatusDot}>
|
<View style={styles.workspaceStatusDot} testID="workspace-status-indicator-loading">
|
||||||
<ThemedActivityIndicator size={8} uniProps={foregroundMutedColorMapping} />
|
<ThemedActivityIndicator size={8} uniProps={foregroundMutedColorMapping} />
|
||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
@@ -194,7 +194,7 @@ function WorkspaceStatusIndicator({
|
|||||||
|
|
||||||
if (shouldShowSyncedLoader) {
|
if (shouldShowSyncedLoader) {
|
||||||
return (
|
return (
|
||||||
<View style={styles.workspaceStatusDot}>
|
<View style={styles.workspaceStatusDot} testID="workspace-status-indicator-running">
|
||||||
<ThemedSyncedLoader size={11} uniProps={syncedLoaderColorMapping} />
|
<ThemedSyncedLoader size={11} uniProps={syncedLoaderColorMapping} />
|
||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { useEffect, useMemo } from "react";
|
import { useEffect, useMemo } from "react";
|
||||||
import {
|
import {
|
||||||
useHydratedWorkspaceEntries,
|
|
||||||
useProjectNamesMap,
|
useProjectNamesMap,
|
||||||
|
useStatusModeWorkspaceEntries,
|
||||||
} from "@/hooks/use-status-mode-workspaces";
|
} from "@/hooks/use-status-mode-workspaces";
|
||||||
import { useSidebarWorkspacesList } from "@/hooks/use-sidebar-workspaces-list";
|
import { useSidebarWorkspacesList } from "@/hooks/use-sidebar-workspaces-list";
|
||||||
import { useKeyboardShortcutsStore } from "@/stores/keyboard-shortcuts-store";
|
import { useKeyboardShortcutsStore } from "@/stores/keyboard-shortcuts-store";
|
||||||
@@ -20,7 +20,10 @@ export function WorkspaceShortcutTargetsSubscriber({
|
|||||||
serverId: string | null;
|
serverId: string | null;
|
||||||
}) {
|
}) {
|
||||||
const { projects } = useSidebarWorkspacesList({ serverId, enabled });
|
const { projects } = useSidebarWorkspacesList({ serverId, enabled });
|
||||||
const statusWorkspaces = useHydratedWorkspaceEntries(enabled ? serverId : null);
|
const statusWorkspaces = useStatusModeWorkspaceEntries({
|
||||||
|
serverId: enabled ? serverId : null,
|
||||||
|
projects,
|
||||||
|
});
|
||||||
const projectNamesByKey = useProjectNamesMap(enabled ? serverId : null);
|
const projectNamesByKey = useProjectNamesMap(enabled ? serverId : null);
|
||||||
const groupMode = useSidebarViewStore((state) =>
|
const groupMode = useSidebarViewStore((state) =>
|
||||||
enabled && serverId ? state.getGroupMode(serverId) : "project",
|
enabled && serverId ? state.getGroupMode(serverId) : "project",
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
import { useCallback, useEffect, useMemo, useSyncExternalStore } from "react";
|
import { useCallback, useEffect, useMemo, useSyncExternalStore } from "react";
|
||||||
import { useSessionStore, type WorkspaceDescriptor } from "@/stores/session-store";
|
import { useCreateFlowStore, type PendingCreateAttempt } from "@/stores/create-flow-store";
|
||||||
|
import { useSessionStore, type Agent, type WorkspaceDescriptor } from "@/stores/session-store";
|
||||||
|
import { useWorkspaceFields } from "@/stores/session-store-hooks";
|
||||||
|
import { deriveSidebarStateBucket } from "@/utils/sidebar-agent-state";
|
||||||
|
import { normalizeWorkspacePath } from "@/utils/workspace-identity";
|
||||||
import { selectPrHintFromStatus } from "@/git/use-pr-status-query";
|
import { selectPrHintFromStatus } from "@/git/use-pr-status-query";
|
||||||
import { useHostProjects } from "@/projects/host-projects";
|
import { useHostProjects } from "@/projects/host-projects";
|
||||||
import { fetchAllWorkspaceDescriptors } from "@/projects/workspace-fetching";
|
import { fetchAllWorkspaceDescriptors } from "@/projects/workspace-fetching";
|
||||||
@@ -31,7 +35,10 @@ export {
|
|||||||
export function createSidebarWorkspaceEntry(input: {
|
export function createSidebarWorkspaceEntry(input: {
|
||||||
serverId: string;
|
serverId: string;
|
||||||
workspace: WorkspaceDescriptor;
|
workspace: WorkspaceDescriptor;
|
||||||
|
pendingCreateAttempts?: Record<string, PendingCreateAttempt>;
|
||||||
|
agents?: Map<string, Agent>;
|
||||||
}): SidebarWorkspaceEntry {
|
}): SidebarWorkspaceEntry {
|
||||||
|
const effectiveStatus = deriveEffectiveWorkspaceStatus(input);
|
||||||
return {
|
return {
|
||||||
workspaceKey: `${input.serverId}:${input.workspace.id}`,
|
workspaceKey: `${input.serverId}:${input.workspace.id}`,
|
||||||
serverId: input.serverId,
|
serverId: input.serverId,
|
||||||
@@ -42,8 +49,8 @@ export function createSidebarWorkspaceEntry(input: {
|
|||||||
projectKind: input.workspace.projectKind,
|
projectKind: input.workspace.projectKind,
|
||||||
workspaceKind: input.workspace.workspaceKind,
|
workspaceKind: input.workspace.workspaceKind,
|
||||||
name: input.workspace.name,
|
name: input.workspace.name,
|
||||||
statusBucket: input.workspace.status,
|
statusBucket: effectiveStatus.status,
|
||||||
statusEnteredAt: input.workspace.statusEnteredAt,
|
statusEnteredAt: effectiveStatus.enteredAt,
|
||||||
archivingAt: input.workspace.archivingAt,
|
archivingAt: input.workspace.archivingAt,
|
||||||
diffStat: input.workspace.diffStat,
|
diffStat: input.workspace.diffStat,
|
||||||
prHint: selectPrHintFromStatus(input.workspace.githubRuntime?.pullRequest),
|
prHint: selectPrHintFromStatus(input.workspace.githubRuntime?.pullRequest),
|
||||||
@@ -54,6 +61,110 @@ export function createSidebarWorkspaceEntry(input: {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface EffectiveWorkspaceStatus {
|
||||||
|
status: WorkspaceDescriptor["status"];
|
||||||
|
enteredAt: Date | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface WorkspaceAgentActivity extends EffectiveWorkspaceStatus {}
|
||||||
|
|
||||||
|
function deriveEffectiveWorkspaceStatus(input: {
|
||||||
|
serverId: string;
|
||||||
|
workspace: WorkspaceDescriptor;
|
||||||
|
pendingCreateAttempts?: Record<string, PendingCreateAttempt>;
|
||||||
|
agents?: Map<string, Agent>;
|
||||||
|
}): EffectiveWorkspaceStatus {
|
||||||
|
if (input.workspace.status !== "done") {
|
||||||
|
return { status: input.workspace.status, enteredAt: input.workspace.statusEnteredAt };
|
||||||
|
}
|
||||||
|
|
||||||
|
const pendingStartedAt = getPendingInitialAgentCreateStartedAt({
|
||||||
|
serverId: input.serverId,
|
||||||
|
workspaceId: input.workspace.id,
|
||||||
|
pendingCreateAttempts: input.pendingCreateAttempts,
|
||||||
|
});
|
||||||
|
if (pendingStartedAt) {
|
||||||
|
return { status: "running", enteredAt: pendingStartedAt };
|
||||||
|
}
|
||||||
|
|
||||||
|
const rootAgentActivity = getRootAgentWorkspaceActivity({
|
||||||
|
workspace: input.workspace,
|
||||||
|
agents: input.agents,
|
||||||
|
});
|
||||||
|
if (rootAgentActivity && rootAgentActivity.status !== "done") {
|
||||||
|
return rootAgentActivity;
|
||||||
|
}
|
||||||
|
|
||||||
|
return { status: input.workspace.status, enteredAt: input.workspace.statusEnteredAt };
|
||||||
|
}
|
||||||
|
|
||||||
|
function getPendingInitialAgentCreateStartedAt(input: {
|
||||||
|
serverId: string;
|
||||||
|
workspaceId: string;
|
||||||
|
pendingCreateAttempts: Record<string, PendingCreateAttempt> | undefined;
|
||||||
|
}): Date | null {
|
||||||
|
let latestStartedAt: Date | null = null;
|
||||||
|
for (const pending of Object.values(input.pendingCreateAttempts ?? {})) {
|
||||||
|
if (pending.serverId !== input.serverId) continue;
|
||||||
|
if (pending.workspaceId !== input.workspaceId) continue;
|
||||||
|
if (pending.lifecycle === "abandoned") continue;
|
||||||
|
const startedAt = new Date(pending.timestamp);
|
||||||
|
if (!latestStartedAt || startedAt > latestStartedAt) {
|
||||||
|
latestStartedAt = startedAt;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return latestStartedAt;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getRootAgentWorkspaceActivity(input: {
|
||||||
|
workspace: WorkspaceDescriptor;
|
||||||
|
agents: Map<string, Agent> | undefined;
|
||||||
|
}): WorkspaceAgentActivity | null {
|
||||||
|
const workspaceDirectory = normalizeWorkspacePath(input.workspace.workspaceDirectory);
|
||||||
|
if (!workspaceDirectory) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
let latest: WorkspaceAgentActivity | null = null;
|
||||||
|
for (const agent of input.agents?.values() ?? []) {
|
||||||
|
if (agent.archivedAt || agent.parentAgentId) continue;
|
||||||
|
if (normalizeWorkspacePath(agent.cwd) !== workspaceDirectory) continue;
|
||||||
|
const status = deriveSidebarStateBucket({
|
||||||
|
status: agent.status,
|
||||||
|
pendingPermissionCount: agent.pendingPermissions.length,
|
||||||
|
requiresAttention: agent.requiresAttention,
|
||||||
|
attentionReason: agent.attentionReason,
|
||||||
|
});
|
||||||
|
const enteredAt = agent.attentionTimestamp ?? agent.updatedAt;
|
||||||
|
if (!latest || enteredAt > (latest.enteredAt ?? new Date(0))) {
|
||||||
|
latest = { status, enteredAt };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return latest;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useSidebarWorkspaceEntry(
|
||||||
|
serverId: string | null,
|
||||||
|
workspaceId: string | null,
|
||||||
|
): SidebarWorkspaceEntry | null {
|
||||||
|
const pendingCreateAttempts = useCreateFlowStore((state) => state.pendingByDraftId);
|
||||||
|
const agents = useSessionStore((state) =>
|
||||||
|
serverId ? state.sessions[serverId]?.agents : undefined,
|
||||||
|
);
|
||||||
|
const projectWorkspaceEntry = useCallback(
|
||||||
|
(workspace: WorkspaceDescriptor): SidebarWorkspaceEntry =>
|
||||||
|
createSidebarWorkspaceEntry({
|
||||||
|
serverId: serverId ?? "",
|
||||||
|
workspace,
|
||||||
|
pendingCreateAttempts,
|
||||||
|
agents,
|
||||||
|
}),
|
||||||
|
[agents, pendingCreateAttempts, serverId],
|
||||||
|
);
|
||||||
|
|
||||||
|
return useWorkspaceFields(serverId, workspaceId, projectWorkspaceEntry);
|
||||||
|
}
|
||||||
|
|
||||||
const EMPTY_ORDER: string[] = [];
|
const EMPTY_ORDER: string[] = [];
|
||||||
const EMPTY_PROJECTS: SidebarProjectEntry[] = [];
|
const EMPTY_PROJECTS: SidebarProjectEntry[] = [];
|
||||||
|
|
||||||
|
|||||||
@@ -1,21 +1,47 @@
|
|||||||
import { useMemo } from "react";
|
import { useMemo } from "react";
|
||||||
import { useSessionStore, type WorkspaceDescriptor } from "@/stores/session-store";
|
import { useCreateFlowStore } from "@/stores/create-flow-store";
|
||||||
|
import { useSessionStore } from "@/stores/session-store";
|
||||||
import {
|
import {
|
||||||
createSidebarWorkspaceEntry,
|
createSidebarWorkspaceEntry,
|
||||||
|
type SidebarProjectEntry,
|
||||||
type SidebarWorkspaceEntry,
|
type SidebarWorkspaceEntry,
|
||||||
} from "./use-sidebar-workspaces-list";
|
} from "./use-sidebar-workspaces-list";
|
||||||
|
|
||||||
export function useHydratedWorkspaceEntries(serverId: string | null): SidebarWorkspaceEntry[] {
|
const EMPTY_WORKSPACES: SidebarWorkspaceEntry[] = [];
|
||||||
|
|
||||||
|
export function useStatusModeWorkspaceEntries(input: {
|
||||||
|
serverId: string | null;
|
||||||
|
projects: SidebarProjectEntry[];
|
||||||
|
}): SidebarWorkspaceEntry[] {
|
||||||
const workspaces = useSessionStore((state) =>
|
const workspaces = useSessionStore((state) =>
|
||||||
serverId ? state.sessions[serverId]?.workspaces : undefined,
|
input.serverId ? state.sessions[input.serverId]?.workspaces : undefined,
|
||||||
);
|
);
|
||||||
|
const agents = useSessionStore((state) =>
|
||||||
|
input.serverId ? state.sessions[input.serverId]?.agents : undefined,
|
||||||
|
);
|
||||||
|
const pendingCreateAttempts = useCreateFlowStore((state) => state.pendingByDraftId);
|
||||||
|
|
||||||
return useMemo(() => {
|
return useMemo(() => {
|
||||||
if (!serverId || !workspaces || workspaces.size === 0) return [];
|
if (!input.serverId || input.projects.length === 0 || !workspaces) {
|
||||||
return Array.from(workspaces.values()).map((workspace: WorkspaceDescriptor) =>
|
return EMPTY_WORKSPACES;
|
||||||
createSidebarWorkspaceEntry({ serverId, workspace }),
|
}
|
||||||
);
|
|
||||||
}, [serverId, workspaces]);
|
const entries: SidebarWorkspaceEntry[] = [];
|
||||||
|
for (const placedWorkspace of input.projects.flatMap((project) => project.workspaces)) {
|
||||||
|
const workspace = workspaces.get(placedWorkspace.workspaceId);
|
||||||
|
entries.push(
|
||||||
|
workspace
|
||||||
|
? createSidebarWorkspaceEntry({
|
||||||
|
serverId: input.serverId,
|
||||||
|
workspace,
|
||||||
|
pendingCreateAttempts,
|
||||||
|
agents,
|
||||||
|
})
|
||||||
|
: placedWorkspace,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return entries;
|
||||||
|
}, [agents, input.projects, input.serverId, pendingCreateAttempts, workspaces]);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useProjectNamesMap(serverId: string | null): Map<string, string> {
|
export function useProjectNamesMap(serverId: string | null): Map<string, string> {
|
||||||
|
|||||||
@@ -591,7 +591,10 @@ async function createAndMergeWorkspace(input: {
|
|||||||
throw new Error(payload.error ?? "Failed to create worktree");
|
throw new Error(payload.error ?? "Failed to create worktree");
|
||||||
}
|
}
|
||||||
const normalizedWorkspace = normalizeWorkspaceDescriptor(payload.workspace);
|
const normalizedWorkspace = normalizeWorkspaceDescriptor(payload.workspace);
|
||||||
input.mergeWorkspaces(input.serverId, [normalizedWorkspace]);
|
const workspaceForInitialMerge = input.createInput.firstAgentContext
|
||||||
|
? { ...normalizedWorkspace, status: "running" as const, statusEnteredAt: new Date() }
|
||||||
|
: normalizedWorkspace;
|
||||||
|
input.mergeWorkspaces(input.serverId, [workspaceForInitialMerge]);
|
||||||
return normalizedWorkspace;
|
return normalizedWorkspace;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -726,6 +729,7 @@ function submitWorkspaceDraft(input: SubmitDraftInput): void {
|
|||||||
useCreateFlowStore.getState().setPending({
|
useCreateFlowStore.getState().setPending({
|
||||||
serverId,
|
serverId,
|
||||||
draftId,
|
draftId,
|
||||||
|
workspaceId,
|
||||||
agentId: null,
|
agentId: null,
|
||||||
clientMessageId,
|
clientMessageId,
|
||||||
text: text.trim(),
|
text: text.trim(),
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ export type CreateFlowLifecycleState = "active" | "abandoned" | "sent";
|
|||||||
export interface PendingCreateAttempt {
|
export interface PendingCreateAttempt {
|
||||||
draftId: string;
|
draftId: string;
|
||||||
serverId: string;
|
serverId: string;
|
||||||
|
workspaceId?: string;
|
||||||
agentId: string | null;
|
agentId: string | null;
|
||||||
clientMessageId: string;
|
clientMessageId: string;
|
||||||
text: string;
|
text: string;
|
||||||
|
|||||||
Reference in New Issue
Block a user