feat(workspaces): title recent-activity rows from a bounded preview

The activity column's disk-only rows had no title: the recent feed carried file
metadata only, so every session outside a live instance rendered "(unnamed)".

recentSessions() now projects a display title for the rows it returns — the
latest `session_info` name and the first user message — from a 128 KiB head +
32 KiB tail of each session file, cached by (mtime, size). Entries are never
parsed into session state: the read is bounded, opt-in, and only paid for the
≤limit rows the caller renders, so the daemon stays a router.

The web client keeps the disk title as a fallback under the live state, and the
B4 e2e scenario asserts session-first rows with their links and titles.
This commit is contained in:
yuez committed 2026-10-30 15:15:09 +08:00
1 parent 086cac8c8e
commit 17fcf931c0
11 files changed
+431 -30

No files matched your search

@@ -55,11 +55,17 @@ type Phrases = { unnamed: string; subagentUnnamed: string };
function ActivityRow({ session, phrases }: { session: RecentSessionRow; phrases: Phrases }) {
const { t } = useTranslation();
// A disk-only row has no live state; the session title contract then falls
// back to `(unnamed)` (never an id), and the dot is the hollow "exited".
const title = session.state
? sessionTitle(session.state, phrases)
: { text: phrases.unnamed, provisional: true, spinner: false };
// A live row carries the authoritative name/first message. A disk-only row
// gets the daemon's bounded preview (latest `session_info` name → first user
// message); only a session with neither falls back to `(unnamed)`. Merge the
// two so a sparse live row still keeps the disk title.
const title = sessionTitle(
{
name: session.state?.name || session.name,
firstMessage: session.state?.firstMessage || session.firstMessage,
},
phrases,
);
const dot = session.state ? sessionDot(session.state) : { status: "exited" as const };
const label = session.state ? t(`state.${sessionStatusKey(session.state)}`) : t("state.exited");
+13 -1
View File
@@ -20,6 +20,10 @@ export interface RecentSessionRow {
ts: number;
/** Full state when a live instance answered for the workspace; null for disk-only rows. */
state: SessionState | null;
/** Disk title: latest `session_info` name in the file, when the daemon saw one. */
name?: string;
/** Disk title fallback: the first user message (≤80 chars). */
firstMessage?: string;
}
function rec(value: unknown): Record<string, unknown> | undefined {
@@ -47,6 +51,8 @@ export function normalizeRecentSessions(payload: unknown): RecentSessionInfo[] {
const sessionId = str(row?.sessionId);
const workspaceId = str(row?.workspaceId);
if (!row || !sessionId || !workspaceId) continue;
const name = str(row.name);
const firstMessage = str(row.firstMessage);
rows.push({
sessionId,
workspaceId,
@@ -55,6 +61,8 @@ export function normalizeRecentSessions(payload: unknown): RecentSessionInfo[] {
sessionFile: str(row.sessionFile) ?? "",
timestamp: num(row.timestamp) ?? 0,
modified: num(row.modified) ?? 0,
...(name === undefined ? {} : { name }),
...(firstMessage === undefined ? {} : { firstMessage }),
});
}
return rows;
@@ -65,7 +73,9 @@ export function normalizeRecentSessions(payload: unknown): RecentSessionInfo[] {
*
* Disk rows are the base (they exist after a daemon restart, before any
* workspace is spawned). A live row with the same id replaces the metadata:
* it carries the authoritative name/first message/status. Sub-sessions are
* it carries the authoritative name/first message/status. Disk rows keep the
* daemon's bounded display preview (`name`/`firstMessage`) so a history row in
* a workspace with no running instance still renders a title. Sub-sessions are
* dropped — the design's activity column is a list of workspace roots.
*/
export function mergeRecentSessions(
@@ -105,6 +115,8 @@ export function mergeRecentSessions(
workspaceName: nameById.get(workspaceId) ?? entry.disk?.workspaceName ?? "",
ts,
state: entry.live ?? null,
...(entry.disk?.name === undefined ? {} : { name: entry.disk.name }),
...(entry.disk?.firstMessage === undefined ? {} : { firstMessage: entry.disk.firstMessage }),
});
}
rows.sort((a, b) => b.ts - a.ts || a.sessionId.localeCompare(b.sessionId));
+39
View File
@@ -275,6 +275,45 @@ describe("WorkspacesPage", () => {
expect(row?.querySelector(".dot")).toHaveClass("dot--busy");
});
it("titles disk-only rows from the daemon's bounded display preview", async () => {
const items = [
workspace({ workspaceId: "ws-a", cwd: "/work/a", name: "Alpha" }),
workspace({ workspaceId: "ws-b", cwd: "/work/b", name: "Bravo" }),
];
mockApi([
{ path: "/api/v1/info", handler: () => ({ body: infoBody }) },
{ path: "/api/v1/workspaces", handler: () => ({ body: items }) },
recentRoute([
diskSession({
sessionId: "s-name",
workspaceId: "ws-a",
workspaceName: "Alpha",
modified: 2_000,
name: "Renamed session",
}),
diskSession({
sessionId: "s-msg",
workspaceId: "ws-b",
workspaceName: "Bravo",
modified: 1_000,
firstMessage: "Please fix the recent list",
}),
]),
]);
await renderPage(routes(), "/workspaces", { paired: true });
await waitForCards(2);
const activity = screen.getByTestId("workspaces-activity");
expect(await within(activity).findByText("Renamed session")).toBeInTheDocument();
expect(within(activity).getByText("Please fix the recent list")).toBeInTheDocument();
// Neither row has a live instance; the title is data, not `(unnamed)`.
const rows = within(activity).getAllByTestId("workspace-activity-row");
expect(rows[0]?.querySelector(".ws-activity__name")).toHaveTextContent("Renamed session");
expect(rows[1]?.querySelector(".ws-activity__name")).toHaveTextContent("Please fix the recent list");
expect(within(activity).queryByText("(unnamed)")).toBeNull();
});
it("opens the new-workspace dialog from the empty state", async () => {
const fetchMock = mockApi([
{ path: "/api/v1/info", handler: () => ({ body: infoBody }) },