fix(web): let the view decide the blink, not the CSS colour class

A dot's animation was keyed on its colour class plus a component wrapper:
`html[data-pi-blink-fast="dim"] .tree-row .dot--ok` made green blink only inside
the session tree, `.dot--busy`/`.dot--err` blazed everywhere they appeared, and
`dot--steady` existed only to subtract what that selector had just added. Two
consequences the matrix in docs/session-dot.md already forbids: a failed task's
red blinked forever with no gesture to acknowledge it, and the same session
could blink in the list and sit solid in the stream head.

`DotView` now carries the rate (`blink: "fast" | "slow"`, omitted = solid) next
to the colour, and `<StatusDot>` renders it as `dot--blink-fast` /
`dot--blink-slow`. `dot--steady` is gone — to make a dot solid you omit `blink`.
app.css keeps exactly two dim rules, with no colour or component scoping and no
knowledge of *whether* anything blinks, only of when the shared clock dims it.

Filling in the matrix this exposed: parent `err`/`ok`/`busy` blink fast and
`compacting` slow; a viewed child or subagent failure is solid while an unviewed
one blinks; `interrupted` is the same solid dead red as `exited` (the plugin has
no interrupted, and in the plugin `exited` outranks its own unread flags —
`sessionDot(active)` is now rendered `viewed: true` for the stream head, so one
session can never show two different rates); task dots follow `:PiTasks`
(`taskDotView`, shared by the tray and the output modal) where only `running`
blinks, `completed` is solid green and `stopped` is amber attention. The
`/status` task card renders the same colours, solid, since nothing there
acknowledges anything.
This commit is contained in:
yuez committed 2026-10-28 08:14:25 +08:00
1 parent 604fec5ea0
commit e7ce064817
16 files changed
+658 -139

No files matched your search

+2 -1
View File
@@ -1,6 +1,7 @@
import { useTranslation } from "react-i18next";
import { Icon } from "@/components/icons";
import { StatusDot } from "@/components/ui/status-dot";
import { cn } from "@/lib/utils";
import type { TrayTab } from "./store";
@@ -80,7 +81,7 @@ export function HeadChips({
>
<Icon name="terminal" />
<span className="head-chip__label">{t("chat.tabTasks")}</span>
{running ? <span className="dot dot--busy" aria-hidden="true" /> : null}
{running ? <StatusDot status="busy" blink="fast" /> : null}
<span className="head-chip__count tabular">{taskCount}</span>
</button>
</div>
+4 -1
View File
@@ -6,12 +6,14 @@ import { Button } from "@/components/ui/button";
import { Modal } from "@/components/ui/dialog";
import { KV } from "@/components/ui/kv";
import { Spinner } from "@/components/ui/spinner";
import { StatusDot } from "@/components/ui/status-dot";
import { toast } from "@/components/ui/toast";
import { ApiError, errorI18nKey } from "@/lib/api";
import { chatCommands, runCommand } from "./commands";
import type { ModelGroup } from "./data";
import { withCurrentModel } from "./data";
import { formatDuration, THINKING_LEVELS } from "./format";
import { taskDotView } from "./session-tray";
function rec(value: unknown): Record<string, unknown> | undefined {
return value && typeof value === "object" && !Array.isArray(value) ? (value as Record<string, unknown>) : undefined;
@@ -259,6 +261,7 @@ export function TaskOutputModal({ open, session, task, onClose, onStop }: TaskOu
if (!task) return null;
const status = result?.status ?? task.status;
const running = status === "running";
const dot = taskDotView(status);
const duration = result?.durationMs ?? (running ? Date.now() - task.startTime : (task.durationMs ?? 0));
const exitCode = result?.exitCode !== undefined ? result.exitCode : (task.exitCode ?? null);
const outputFile = result?.outputFile ?? task.outputFile;
@@ -295,7 +298,7 @@ export function TaskOutputModal({ open, session, task, onClose, onStop }: TaskOu
<div>
<KV label={t("chat.status")}>
<span className="row">
<span className={`dot ${running ? "dot--busy" : status === "completed" ? "dot--ok" : status === "failed" ? "dot--err" : "dot--idle"}`} />
<StatusDot status={dot.status} blink={dot.blink} />
{t(`state.${status}`)}
</span>
</KV>
+23 -12
View File
@@ -1,6 +1,6 @@
import { applyEvent, createReducer, type Reducer } from "@protocol/reducer";
import type { Entry, ModelRef, SessionEvent, SessionState, ThinkingLevel } from "@protocol/types";
import type { DotStatus } from "@/components/ui/status-dot";
import type { BlinkRate, DotStatus } from "@/components/ui/status-dot";
import { normalizeTodos, projectEntries, type ProjectedEntry } from "@/lib/entry-projection";
const EMPTY_USAGE = { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, cost: 0 };
@@ -509,12 +509,14 @@ function attentionPending(state: SessionState): boolean {
}
/**
* A dot render decision: the base status plus the two overlay modifiers.
* `steady` pins the dot solid, `current` paints the "you are here" overlay.
* A dot render decision: the colour, its blink rate and the "you are here"
* overlay. `blink` is the *only* place the animation is decided — the renderer
* never infers it from the colour class or from where the dot is mounted — and
* omitting it means the dot is solid.
*/
export interface DotView {
status: DotStatus;
steady?: boolean;
blink?: BlinkRate;
current?: boolean;
}
@@ -531,7 +533,10 @@ function withCurrent(view: DotView, state: SessionState, viewed: boolean): DotVi
// The plugin's `markable` is a positive list: only a live session carries the
// marker, and a `compacting` one blinks at the busy rate under it.
if (state.status !== "idle" && state.status !== "busy" && state.status !== "compacting") return view;
return { current: true, status: state.status === "compacting" ? "busy" : view.status };
// The rate follows the painted status, so a focused compacting row blinks at
// the busy rate (fast) instead of half speed, exactly like the plugin.
if (state.status === "compacting") return { current: true, status: "busy", blink: "fast" };
return { ...view, current: true };
}
/**
@@ -545,11 +550,11 @@ function parentDot(state: SessionState): DotView {
// plugin every "not running" row is `exited` (sessions.lua:75-78), which is
// why a dead row outranks its own unread error/attention/done flags.
if (state.status === "exited" || state.status === "interrupted") return { status: "dead" };
if (state.flags.error) return { status: "err" };
if (state.flags.error) return { status: "err", blink: "fast" };
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.flags.done) return { status: "ok", blink: "fast" };
if (state.status === "busy") return { status: "busy", blink: "fast" };
if (state.status === "compacting") return { status: "compacting", blink: "slow" };
return { status: "idle" };
}
@@ -569,8 +574,8 @@ export function sessionDot(state: SessionState, opts: { viewed?: boolean } = {})
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" };
if (state.flags.error) return viewed ? { status: "err" } : { status: "err", blink: "fast" };
if (state.status === "busy" || state.status === "compacting") return { status: "busy", blink: "fast" };
return { status: "idle" };
}
@@ -591,12 +596,18 @@ export function subagentDot(
): DotView {
switch (subagent.status) {
case "active":
// A manifest entry with a live session is rendered as *that* session
// row, so this branch only ever sees a manifest nothing live owns (a
// spawn in flight, or a stale entry). The plugin colours a child by its
// live status (`sessions.lua` `append_child_row`) and blinks only the
// live busy one, so the amber is informative but must stay solid —
// nothing acknowledges a manifest blink and it would blink forever.
return { status: "busy" };
case "completed":
case "dormant":
return { status: "exited" };
case "failed":
return { status: "err", steady: opts.viewed === true };
return opts.viewed === true ? { status: "err" } : { status: "err", blink: "fast" };
case "interrupted":
return { status: "dead" };
default:
+17 -7
View File
@@ -6,11 +6,12 @@ import { Icon } from "@/components/icons";
import { Badge } from "@/components/ui/badge";
import { Empty } from "@/components/ui/empty";
import { Progress } from "@/components/ui/progress";
import { StatusDot, type DotStatus } from "@/components/ui/status-dot";
import { StatusDot } from "@/components/ui/status-dot";
import { cn } from "@/lib/utils";
import { TodoList } from "./blocks";
import { formatDuration } from "./format";
import type { DotView } from "./session-state";
import { subagentTitle } from "./session-title";
import type { TrayTab } from "./store";
@@ -36,11 +37,19 @@ export interface SessionTrayProps {
const TABS: TrayTab[] = ["todo", "tasks"];
function taskDot(status: TaskItem["status"]): DotStatus {
if (status === "running") return "busy";
if (status === "completed") return "ok";
if (status === "failed") return "err";
return "idle";
/**
* `:PiTasks` (`lua/pi/ui/tasks.lua` `dot_hl`) parity, shared with the
* task-output modal: only a *running* task blinks. A finished task is solid —
* a `completed` green is not an unread notification, and a `failed` red has no
* acknowledgement path, so blinking it would blink forever next to session dots
* that the user has already seen.
*/
export function taskDotView(status: TaskItem["status"]): DotView {
if (status === "running") return { status: "busy", blink: "fast" };
if (status === "completed") return { status: "ok" };
if (status === "failed") return { status: "err" };
if (status === "stopped") return { status: "attention" };
return { status: "idle" };
}
/**
@@ -274,9 +283,10 @@ export function SessionTray({
{tasks.map((task) => {
const running = task.status === "running";
const duration = running ? Date.now() - task.startTime : task.durationMs;
const dot = taskDotView(task.status);
return (
<div key={task.id} className="task-row" data-task-id={task.id}>
<StatusDot status={taskDot(task.status)} />
<StatusDot status={dot.status} blink={dot.blink} />
<button
type="button"
className="task-row__main"
+2 -2
View File
@@ -213,7 +213,7 @@ export function SessionTree({
aria-current={selected ? "true" : undefined}
onClick={() => onSelectSession(session.sessionId)}
>
<StatusDot status={dot.status} steady={dot.steady} current={dot.current} />
<StatusDot status={dot.status} blink={dot.blink} current={dot.current} />
{title.spinner ? <SessionTitleSpinner /> : null}
<span
className={cn(
@@ -280,7 +280,7 @@ export function SessionTree({
data-sub-id={subagent.id}
onClick={() => onSelectSubagent(session.sessionId, subagent.id)}
>
<StatusDot status={dot.status} steady={dot.steady} />
<StatusDot status={dot.status} blink={dot.blink} />
<span
className={cn(
"t-name truncate",
+1 -5
View File
@@ -279,11 +279,7 @@ export function SubagentView({
<span className="sub-back__label">{t("chat.subview.back")}</span>
</button>
<div className="stream-title">
<StatusDot
status={dot.status}
steady={dot.steady}
title={t(`state.${subagent.status}`)}
/>
<StatusDot status={dot.status} blink={dot.blink} title={t(`state.${subagent.status}`)} />
<h2 className="stream-name truncate" tabIndex={-1} title={task ? `${name} · ${task}` : name}>
{name}
</h2>
+1 -1
View File
@@ -188,7 +188,7 @@ export function Telemetry({ session, subagent, entries, className }: TelemetryPr
data-testid="telemetry"
>
<span className={cn("telemetry__state", "sub-state", tone)} data-testid="telemetry-state">
<StatusDot status={dot.status} steady={dot.steady} />
<StatusDot status={dot.status} blink={dot.blink} />
{t(`state.${subagent.status}`)}
</span>
{elapsed ? (
+4 -1
View File
@@ -8,11 +8,14 @@ import { ErrorBlock, LoadingBlock, StatusCard, StatusEmpty } from "./card-parts"
export type { StatusTask };
/** `:PiTasks` (`lua/pi/ui/tasks.lua` `dot_hl`) vocabulary — the same colours the
* chat tray renders through `taskDotView`; this card just never blinks (a
* monitoring report has no acknowledgement gesture). */
const TASK_DOT: Record<string, DotStatus> = {
running: "busy",
completed: "ok",
failed: "err",
stopped: "exited",
stopped: "attention",
};
export interface TasksCardProps {