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:
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");
|
||||
|
||||
|
||||
@@ -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));
|
||||
|
||||
Reference in new issue
Block a user