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:
1 parent
604fec5ea0
commit
e7ce064817
16 files changed
+658
-139
No files matched your search
@@ -3,6 +3,17 @@ import { cn } from "@/lib/utils";
|
||||
/** Status-dot vocabulary from the design's `:PiSessions` state matrix. */
|
||||
export type DotStatus = "busy" | "compacting" | "idle" | "ok" | "err" | "attention" | "exited" | "dead";
|
||||
|
||||
/**
|
||||
* Blink rate, in shared-clock phases (`web/src/lib/blink.ts`): `fast` follows
|
||||
* `data-pi-blink-fast` (500ms), `slow` follows `data-pi-blink-slow` (1000ms).
|
||||
*/
|
||||
export type BlinkRate = "fast" | "slow";
|
||||
|
||||
/**
|
||||
* Colour only. Whether a dot blinks is NOT encoded here: `dot--busy` is amber
|
||||
* whether it pulses (a running turn) or not (a startup `connecting` chip), so a
|
||||
* class-keyed dim rule cannot express the matrix. `blink` carries it instead.
|
||||
*/
|
||||
export const DOT_CLASS: Record<DotStatus, string> = {
|
||||
busy: "dot--busy",
|
||||
compacting: "dot--compacting",
|
||||
@@ -14,6 +25,11 @@ export const DOT_CLASS: Record<DotStatus, string> = {
|
||||
dead: "dot--dead",
|
||||
};
|
||||
|
||||
export const BLINK_CLASS: Record<BlinkRate, string> = {
|
||||
fast: "dot--blink-fast",
|
||||
slow: "dot--blink-slow",
|
||||
};
|
||||
|
||||
export type ServerStatus = "online" | "degraded" | "offline";
|
||||
|
||||
/** Server / connection status mapping (online → ok, degraded → attention, else exited). */
|
||||
@@ -27,20 +43,29 @@ export function serverDotClass(status: ServerStatus | string | null | undefined)
|
||||
|
||||
export interface StatusDotProps {
|
||||
status: DotStatus;
|
||||
/**
|
||||
* Blink rate decided by the *view* that owns the dot (`DotView.blink`), never
|
||||
* by the DOM location or the colour class. Omitted/`null` = solid.
|
||||
*/
|
||||
blink?: BlinkRate | null;
|
||||
title?: string;
|
||||
className?: string;
|
||||
/** Pin the dot solid (no blink) — nvim's "focused child error is steady red". */
|
||||
steady?: boolean;
|
||||
/** "You are here" overlay (nvim `PiSessionsListCurrent`, agent blue). */
|
||||
current?: boolean;
|
||||
/** Decorative by default; pass a title to expose the state to assistive tech. */
|
||||
"aria-hidden"?: boolean;
|
||||
}
|
||||
|
||||
export function StatusDot({ status, title, className, steady, current, ...rest }: StatusDotProps) {
|
||||
export function StatusDot({ status, blink, title, className, current, ...rest }: StatusDotProps) {
|
||||
return (
|
||||
<span
|
||||
className={cn("dot", DOT_CLASS[status], steady && "dot--steady", current && "dot--current", className)}
|
||||
className={cn(
|
||||
"dot",
|
||||
DOT_CLASS[status],
|
||||
blink ? BLINK_CLASS[blink] : null,
|
||||
current && "dot--current",
|
||||
className,
|
||||
)}
|
||||
title={title}
|
||||
aria-label={title}
|
||||
aria-hidden={title ? undefined : true}
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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 ? (
|
||||
|
||||
@@ -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 {
|
||||
|
||||
+11
-2
@@ -126,6 +126,10 @@ function ChatExperience({ sessionId }: { sessionId?: string }) {
|
||||
if (!viewedSessionId || (!viewedDone && !viewedError)) return;
|
||||
useSessionsStore.getState().markSeen(viewedSessionId);
|
||||
}, [viewedSessionId, viewedDone, viewedError]);
|
||||
// The stream head shows the same session the selected tree row does, so it
|
||||
// renders that row's `DotView` (`viewed: true`) rather than re-deriving a
|
||||
// colour: one session must never show two different blink rates.
|
||||
const headDot = active ? sessionDot(active, { viewed: true }) : null;
|
||||
const history = useSessionHistory(
|
||||
active?.sessionId,
|
||||
active?.entries ?? NO_ENTRIES,
|
||||
@@ -544,8 +548,13 @@ function ChatExperience({ sessionId }: { sessionId?: string }) {
|
||||
</button>
|
||||
) : null}
|
||||
<div className="stream-title">
|
||||
{active ? (
|
||||
<StatusDot status={sessionDot(active).status} title={t(`state.${sessionStatusKey(active)}`)} />
|
||||
{active && headDot ? (
|
||||
<StatusDot
|
||||
status={headDot.status}
|
||||
blink={headDot.blink}
|
||||
current={headDot.current}
|
||||
title={t(`state.${sessionStatusKey(active)}`)}
|
||||
/>
|
||||
) : null}
|
||||
<h2 className="stream-name truncate" tabIndex={-1} ref={streamNameRef}>
|
||||
{active ? activeTitle?.text : (workspace?.name ?? t("nav.chat"))}
|
||||
|
||||
+12
-5
@@ -387,13 +387,20 @@ code, pre { font-family: var(--font-mono); font-size: 0.875em; }
|
||||
.dot--dead { background: var(--err); }
|
||||
.dot--attention { background: var(--warn); box-shadow: 0 0 0 2px color-mix(in oklch, var(--warn) 22%, transparent); }
|
||||
.dot--exited { background: transparent; box-shadow: inset 0 0 0 1.5px var(--muted-foreground); }
|
||||
/* "You are here" (nvim `PiSessionsListCurrent`): agent blue wherever the dot is
|
||||
mounted, so the stream-head dot and its list row cannot disagree. Scoping this
|
||||
to `.tree-row` would leave the head's `dot--current` inert. */
|
||||
.dot--current { background: var(--info); }
|
||||
@keyframes pulse { 50% { opacity: .35; } }
|
||||
|
||||
/* Shared blink phase driven by html[data-pi-blink-*] attributes (single window clock) */
|
||||
html[data-pi-blink-fast="dim"] .dot--busy:not(.dot--steady),
|
||||
html[data-pi-blink-fast="dim"] .dot--err:not(.dot--steady),
|
||||
html[data-pi-blink-fast="dim"] .tree-row .dot--ok { opacity: .35; }
|
||||
html[data-pi-blink-slow="dim"] .dot--compacting:not(.dot--steady) { opacity: .35; }
|
||||
/* One blink contract. The <html> attributes are the shared clock (lib/blink.ts);
|
||||
whether a dot participates — and at which rate — is decided once, by the view
|
||||
that renders it (`DotView.blink` → `.dot--blink-fast` / `.dot--blink-slow`).
|
||||
Nothing here may key on a colour class or on a component wrapper: the same
|
||||
status must blink the same in the session list, the stream head, a task row
|
||||
or a dialog. A dot without a `dot--blink-*` class is solid. */
|
||||
html[data-pi-blink-fast="dim"] .dot--blink-fast,
|
||||
html[data-pi-blink-slow="dim"] .dot--blink-slow { opacity: .35; }
|
||||
|
||||
.chip {
|
||||
display: inline-flex; align-items: center; gap: var(--space-2);
|
||||
|
||||
@@ -446,10 +446,8 @@
|
||||
}
|
||||
|
||||
/* 状态圆点:由 <html> 根节点上的单一全局时钟驱动(data-pi-blink-* 属性,见 app.css 与 blink.ts),
|
||||
不再使用每个圆点独立的 CSS animation,避免相位漂移。当前聚焦会话叠加高亮背景。 */
|
||||
.tree-row .dot--current {
|
||||
background: var(--info);
|
||||
}
|
||||
不再使用每个圆点独立的 CSS animation,避免相位漂移。当前会话的蓝色标记在 app.css 的
|
||||
`.dot--current`(不按容器限定:流头圆点与列表行必须同色)。 */
|
||||
|
||||
/* 子会话 / 子代理行:更矮、更小、灰一档;状态只由圆点表达。 */
|
||||
.tree-row--sub .tree-row__main {
|
||||
|
||||
Reference in new issue
Block a user