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

+90 -10
View File
@@ -446,16 +446,96 @@ function attentionPending(state: SessionState): boolean {
return state.flags.attention || state.attention.length > 0;
}
/** `:PiSessions` status matrix → base.css dot class. */
export function sessionDot(state: SessionState): DotStatus {
if (attentionPending(state)) return "attention";
if (state.status === "busy" || state.status === "starting") return "busy";
if (state.status === "compacting") return "compacting";
if (state.status === "interrupted") return "attention";
if (state.status === "exited") return "exited";
if (state.flags.error) return "err";
if (state.flags.done) return "ok";
return "idle";
/**
* A dot render decision: the base status plus the two overlay modifiers.
* `steady` pins the dot solid, `current` paints the "you are here" overlay.
*/
export interface DotView {
status: DotStatus;
steady?: boolean;
current?: boolean;
}
/**
* The current-tab marker: `:PiSessions` paints the dot of the session its tab is
* showing in agent blue, steady while idle and blinking while busy, and never on
* top of a notification colour (`dot_hl` outranks it — see
* `refresh_current_markers`). The browser's analogue is the row the user has
* open. A focused `compacting` session blinks at the busy rate, not half speed.
*/
function withCurrent(view: DotView, state: SessionState, viewed: boolean): DotView {
if (!viewed) return view;
if (state.flags.error || state.flags.done || attentionPending(state)) return view;
if (state.status === "exited" || state.status === "interrupted") return view;
return { current: true, status: state.status === "compacting" ? "busy" : view.status };
}
/**
* `:PiSessions` parent row matrix (`dot_hl`, priority order): exited > error >
* attention > done > busy > compacting > idle. `interrupted` is the wire's
* "the process died badly" — it shares the exited red with `exited`, never the
* attention amber (`sessionStatusKey` still labels it "interrupted").
*/
function parentDot(state: SessionState): DotView {
if (state.status === "exited") return { status: "dead" };
if (state.flags.error) return { status: "err" };
if (attentionPending(state)) return { status: "attention" };
if (state.flags.done) return { status: "ok" };
if (state.status === "busy") return { status: "busy" };
if (state.status === "compacting") return { status: "compacting" };
if (state.status === "interrupted") return { status: "dead" };
return { status: "idle" };
}
/** `:PiSessions` → dot for a parent (depth 0) session row. */
export function sessionDot(state: SessionState, opts: { viewed?: boolean } = {}): DotView {
return withCurrent(parentDot(state), state, opts.viewed === true);
}
/**
* `:PiSessions` sub-session matrix (`child_dot_hl`) — deliberately not the
* parent's: an exited/dormant child is the hollow `◌` (never the exited red), a
* failed child is steady red while you are looking at it and blinking red while
* you are not, and `busy`/`compacting` share the busy amber at the busy rate.
* A child never shows `ok` or `attention`: the plugin forces `done = false` and
* `attention = 0` there, surfacing both in the parent chat instead.
*/
function childDot(state: SessionState, viewed: boolean): DotView {
if (state.status === "exited") return { status: "exited" };
if (state.status === "interrupted") return { status: "dead" };
if (state.flags.error) return { status: "err", steady: viewed };
if (state.status === "busy" || state.status === "compacting") return { status: "busy" };
return { status: "idle" };
}
/** `:PiSessions` → dot for a sub-session (depth > 0) row. */
export function childSessionDot(state: SessionState, opts: { viewed?: boolean } = {}): DotView {
const viewed = opts.viewed === true;
return withCurrent(childDot(state, viewed), state, viewed);
}
/**
* `:PiSessions` → dot for a manifest-only subagent row. A `completed` subagent is
* the hollow dot, not a green one: the plugin shows a finished child as dormant
* `◌` and keeps green for "a turn finished while you were elsewhere" on parents.
*/
export function subagentDot(
subagent: SessionState["subagents"][number],
opts: { viewed?: boolean } = {},
): DotView {
switch (subagent.status) {
case "active":
return { status: "busy" };
case "completed":
case "dormant":
return { status: "exited" };
case "failed":
return { status: "err", steady: opts.viewed === true };
case "interrupted":
return { status: "dead" };
default:
return { status: "idle" };
}
}
/** i18n key under `state.*` for the current session status. */
+9 -4
View File
@@ -4,10 +4,10 @@ import { useTranslation } from "react-i18next";
import { Icon } from "@/components/icons";
import { Empty } from "@/components/ui/empty";
import { StatusDot, subagentDotClass } from "@/components/ui/status-dot";
import { StatusDot } from "@/components/ui/status-dot";
import { cn } from "@/lib/utils";
import { SessionRowMenu } from "./session-row-menu";
import { flattenSubagents, sessionDot } from "./session-state";
import { childSessionDot, flattenSubagents, sessionDot, subagentDot } from "./session-state";
import { sessionTitle, subagentTitle } from "./session-title";
import { SessionTitleSpinner } from "./session-title-spinner";
import {
@@ -178,6 +178,10 @@ export function SessionTree({
function renderSessionRow(node: SessionTreeNode) {
const session = node.session;
const selected = session.sessionId === selectedId;
const dot =
node.depth > 0
? childSessionDot(session, { viewed: selected })
: sessionDot(session, { viewed: selected });
const menuOpen = rowMenu?.session.sessionId === session.sessionId;
// A row is never labelled with its id (pi2.nvim shows `(unnamed)`).
const title = sessionTitle(session, titlePhrases);
@@ -209,7 +213,7 @@ export function SessionTree({
aria-current={selected ? "true" : undefined}
onClick={() => onSelectSession(session.sessionId)}
>
<StatusDot status={sessionDot(session)} />
<StatusDot status={dot.status} steady={dot.steady} current={dot.current} />
{title.spinner ? <SessionTitleSpinner /> : null}
<span
className={cn(
@@ -244,6 +248,7 @@ export function SessionTree({
function renderSubagentRow(node: SubagentTreeNode) {
const { session, subagent } = node;
const viewing = subagent.id === activeSubagentId;
const dot = subagentDot(subagent, { viewed: viewing });
// Sub-session rows resolve name → task prompt (40 chars) → `sub-session`;
// the id stays an identity, never a label.
const title = subagentTitle(subagent, titlePhrases);
@@ -275,7 +280,7 @@ export function SessionTree({
data-sub-id={subagent.id}
onClick={() => onSelectSubagent(session.sessionId, subagent.id)}
>
<span className={cn("dot", subagentDotClass(subagent.status))} aria-hidden="true" />
<StatusDot status={dot.status} steady={dot.steady} />
<span
className={cn(
"t-name truncate",