fix(web): rebuild the session dot matrix from pi2.nvim

The Chat session list dot did not follow the plugin it mirrors
(:PiSessions in pi2.nvim, lua/pi/ui/sessions.lua). Four things were wrong:

- priority: attention outranked error and exited; the plugin order is
  exited > error > attention > done > busy > compacting > idle.
- interrupted wore the attention amber, the same colour as "waiting for you";
  it is a dead process, so it takes the solid exited red (dot--dead).
- exited and dormant were collapsed into the hollow grey ring; a dead parent
  is the solid red one, the hollow ring is the dormant sub-session.
- sub-sessions reused the parent matrix. They now follow child_dot_hl: a
  failed child is steady red while you are looking at it and blinking red
  while you are not, busy/compacting blink at the busy rate, and a child
  never shows green (the plugin forces done=false there).

The current-tab marker (PiSessionsListCurrent) was missing entirely: the row
the console has open now carries dot--current, steady on idle and blinking
on busy, and never on top of a notification colour - same guard as
refresh_current_markers. It is the browser analogue of the focused nvim tab,
so no wire change is needed.

Also drops the unreachable sessionDotClass() dead code, whose second mapping
was the reason the divergence went unnoticed, and consolidates the three
subagent dot tables into subagentDot().

Unread notifications now expire like the plugin's: done/error are unread
markers, not states (on_agent_end only raises done for a tab that is not
current, clear_flags wipes both on TabEnter). The store gained markSeen(),
called when the routed session carries done/error, so a session you open
stops being green or red. The canonical reducer and fixtures/ are untouched:
this is a client-side view concern.
This commit is contained in:
yuez committed 2026-10-27 18:43:13 +08:00
1 parent 81e7f96a64
commit bf01fd549d
5 files changed
+153 -66

No files matched your search

+35 -4
View File
@@ -15,6 +15,14 @@ export interface SessionsStore {
renameSessionId: (from: string, to: string) => void;
removeSession: (sessionId: string) => void;
selectSession: (sessionId: string | null) => void;
/**
* `:PiSessions` TabEnter: the user is now looking at this session, so its
* unread notifications (`done` / `error` / a stale `attention` flag) are
* consumed. `:PiSessions` clears both on TabEnter and only sets `done` when
* the session is not the current tab; the browser has no tabs, so owning a
* row's notifications means opening it.
*/
markSeen: (sessionId: string) => void;
listFor: (workspaceId: string) => SessionState[];
getSession: (sessionId: string) => SessionState | undefined;
setStatus: (status: "idle" | "loading" | "error", error?: string | null) => void;
@@ -46,16 +54,19 @@ export const useSessionsStore = create<SessionsStore>((set, get) => ({
return { byWorkspace: { ...state.byWorkspace, [session.workspaceId]: [...list, session] } };
}
// Tree metadata is list metadata: a live update (`pi2:session`,
// reducer events, a rename) carries no `parentId`/`visible`/`task` and
// must not orphan the row. Explicit `undefined` is the only
// "not carried" marker — an explicit `parentId: null` means root and
// wins, which `??` would invert.
// reducer events, a rename) carries no `parentId`/`visible`/`task`/
// `tab`/`createdAt`/`lastActiveAt` and must not orphan the row.
// Explicit `undefined` is the only "not carried" marker — an explicit
// `parentId: null` means root and wins, which `??` would invert.
const previous = list[index] as SessionState;
const merged: SessionState = {
...session,
parentId: session.parentId !== undefined ? session.parentId : previous.parentId,
visible: session.visible !== undefined ? session.visible : previous.visible,
task: session.task !== undefined ? session.task : previous.task,
tab: session.tab !== undefined ? session.tab : previous.tab,
createdAt: session.createdAt !== undefined ? session.createdAt : previous.createdAt,
lastActiveAt: session.lastActiveAt !== undefined ? session.lastActiveAt : previous.lastActiveAt,
};
const next = list.map((s, i) => (i === index ? merged : s));
return { byWorkspace: { ...state.byWorkspace, [session.workspaceId]: next } };
@@ -117,6 +128,26 @@ export const useSessionsStore = create<SessionsStore>((set, get) => ({
selectSession: (selectedSessionId) => set({ selectedSessionId }),
markSeen: (sessionId) =>
set((state) => {
let changed = false;
const byWorkspace: Record<string, SessionState[]> = {};
for (const [workspaceId, list] of Object.entries(state.byWorkspace)) {
const next = list.map((session) => {
if (session.sessionId !== sessionId) return session;
const attention = session.attention.length > 0;
if (!session.flags.done && !session.flags.error && session.flags.attention === attention) {
return session;
}
changed = true;
return { ...session, flags: { attention, done: false, error: false } };
});
byWorkspace[workspaceId] = next;
}
// Nothing to consume: keep the state object so zustand skips the render.
return changed ? { byWorkspace } : state;
}),
listFor: (workspaceId) => get().byWorkspace[workspaceId] ?? [],
getSession: (sessionId) => {