@aeondave/pi-theme-1337 0.0.0-stage → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +253 -0
- package/LICENSE +21 -0
- package/README.md +159 -2
- package/assets/banner.png +0 -0
- package/assets/palettes.gif +0 -0
- package/docs/architecture.md +167 -0
- package/docs/configuration.md +87 -0
- package/docs/palette-design.md +51 -0
- package/docs/theme-motion.md +88 -0
- package/package.json +68 -4
- package/src/avatar.ts +174 -0
- package/src/background.ts +82 -0
- package/src/config.ts +357 -0
- package/src/diff-spans.ts +77 -0
- package/src/editor.ts +443 -0
- package/src/format.ts +464 -0
- package/src/frame.ts +380 -0
- package/src/index.ts +1195 -0
- package/src/quota.ts +581 -0
- package/src/redraw-guard.ts +79 -0
- package/src/run-summary.ts +623 -0
- package/src/spinner.ts +72 -0
- package/src/terminal-title.ts +67 -0
- package/src/tool-activity.ts +216 -0
- package/src/tool-adapter.ts +491 -0
- package/src/tool-groups.ts +192 -0
- package/src/tool-lexicon.ts +200 -0
- package/src/tool-view.ts +788 -0
- package/src/width.ts +246 -0
- package/themes/1337-amber.json +94 -0
- package/themes/1337-amber.pi1337 +3 -0
- package/themes/1337-cosmos.json +94 -0
- package/themes/1337-cosmos.pi1337 +3 -0
- package/themes/1337-cyber.json +94 -0
- package/themes/1337-cyber.pi1337 +3 -0
- package/themes/1337-cyberpunk-2077-edgerunner.json +94 -0
- package/themes/1337-cyberpunk-2077-edgerunner.pi1337 +7 -0
- package/themes/1337-cyberpunk-2077.json +94 -0
- package/themes/1337-cyberpunk-2077.pi1337 +7 -0
- package/themes/1337-fallout.json +94 -0
- package/themes/1337-fallout.pi1337 +4 -0
- package/themes/1337-ice.json +94 -0
- package/themes/1337-ice.pi1337 +3 -0
- package/themes/1337-magma.json +94 -0
- package/themes/1337-magma.pi1337 +1 -0
- package/themes/1337-neon.json +94 -0
- package/themes/1337-neon.pi1337 +3 -0
- package/themes/1337-poison.json +94 -0
- package/themes/1337-poison.pi1337 +3 -0
- package/themes/1337-skynet-dark.json +94 -0
- package/themes/1337-skynet-dark.pi1337 +4 -0
- package/themes/1337-skynet.json +94 -0
- package/themes/1337-skynet.pi1337 +4 -0
- package/themes/1337.json +95 -0
- package/themes/1337.pi1337 +3 -0
package/src/spinner.ts
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { Color } from "@earendil-works/pi-tui";
|
|
2
|
+
import { visibleWidth } from "./width.ts";
|
|
3
|
+
|
|
4
|
+
export interface SpinnerProfile {
|
|
5
|
+
/** First row of each frame; retained for the single-row API. */
|
|
6
|
+
readonly frames: readonly string[];
|
|
7
|
+
readonly intervalMs: number;
|
|
8
|
+
readonly columns: number;
|
|
9
|
+
readonly height: number;
|
|
10
|
+
readonly color?: Color;
|
|
11
|
+
readonly frameRows: (index: number) => readonly string[];
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const DEFAULT_FRAMES = Object.freeze(["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]);
|
|
15
|
+
|
|
16
|
+
export const DEFAULT_SPINNER: SpinnerProfile = Object.freeze({
|
|
17
|
+
frames: DEFAULT_FRAMES,
|
|
18
|
+
intervalMs: 90,
|
|
19
|
+
columns: 1,
|
|
20
|
+
height: 1,
|
|
21
|
+
frameRows: (index: number) => {
|
|
22
|
+
const safeIndex = Number.isFinite(index) ? Math.trunc(index) : 0;
|
|
23
|
+
return [DEFAULT_FRAMES[((safeIndex % DEFAULT_FRAMES.length) + DEFAULT_FRAMES.length) % DEFAULT_FRAMES.length]];
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
const MAX_FRAMES = 32;
|
|
28
|
+
const MAX_FRAME_LENGTH = 256;
|
|
29
|
+
const MIN_INTERVAL = 60;
|
|
30
|
+
const MAX_INTERVAL = 500;
|
|
31
|
+
const unsafeText = /[\p{Cc}\p{Cf}\p{Cs}\p{Zl}\p{Zp}\t\r\n]/u;
|
|
32
|
+
|
|
33
|
+
/** Validate untrusted sidecar data using the same width ruler used to paint it. */
|
|
34
|
+
export function parseSpinner(value: unknown): SpinnerProfile | undefined {
|
|
35
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return undefined;
|
|
36
|
+
const candidate = value as { frames?: unknown; intervalMs?: unknown; color?: unknown };
|
|
37
|
+
if (!Array.isArray(candidate.frames) || candidate.frames.length < 1 || candidate.frames.length > MAX_FRAMES) return undefined;
|
|
38
|
+
if (candidate.intervalMs !== undefined && (typeof candidate.intervalMs !== "number" || !Number.isFinite(candidate.intervalMs) || candidate.intervalMs < MIN_INTERVAL || candidate.intervalMs > MAX_INTERVAL)) return undefined;
|
|
39
|
+
const rows: string[][] = [];
|
|
40
|
+
let columns: number | undefined;
|
|
41
|
+
let height: number | undefined;
|
|
42
|
+
for (const item of candidate.frames) {
|
|
43
|
+
const frame = typeof item === "string" ? [item] : Array.isArray(item) ? item : undefined;
|
|
44
|
+
if (!frame || frame.length < 1 || frame.length > 2 || (height !== undefined && frame.length !== height)) return undefined;
|
|
45
|
+
const checked: string[] = [];
|
|
46
|
+
for (const line of frame) {
|
|
47
|
+
if (typeof line !== "string" || line.length === 0 || line.length > MAX_FRAME_LENGTH || unsafeText.test(line) || !/\P{White_Space}/u.test(line)) return undefined;
|
|
48
|
+
const width = visibleWidth(line);
|
|
49
|
+
if (width < 1 || width > 3 || (columns !== undefined && width !== columns)) return undefined;
|
|
50
|
+
columns = width;
|
|
51
|
+
checked.push(line);
|
|
52
|
+
}
|
|
53
|
+
height = frame.length;
|
|
54
|
+
rows.push(checked);
|
|
55
|
+
}
|
|
56
|
+
let color: Color | undefined;
|
|
57
|
+
if (candidate.color !== undefined) {
|
|
58
|
+
if (typeof candidate.color !== "string" || !/^#[0-9a-fA-F]{6}$/.test(candidate.color)) return undefined;
|
|
59
|
+
color = Object.freeze({ kind: "rgb", r: parseInt(candidate.color.slice(1, 3), 16), g: parseInt(candidate.color.slice(3, 5), 16), b: parseInt(candidate.color.slice(5, 7), 16) });
|
|
60
|
+
}
|
|
61
|
+
const frozenRows = Object.freeze(rows.map((row) => Object.freeze(row)));
|
|
62
|
+
const frameRows = (index: number): readonly string[] => {
|
|
63
|
+
const safeIndex = Number.isFinite(index) ? Math.trunc(index) : 0;
|
|
64
|
+
return frozenRows[((safeIndex % frozenRows.length) + frozenRows.length) % frozenRows.length];
|
|
65
|
+
};
|
|
66
|
+
return Object.freeze({ frames: Object.freeze(frozenRows.map((row) => row[0])), intervalMs: candidate.intervalMs === undefined ? 90 : candidate.intervalMs, columns: columns!, height: height!, color, frameRows });
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function spinnerFrame(profile: SpinnerProfile, index: number): string {
|
|
70
|
+
const safeIndex = Number.isFinite(index) ? Math.trunc(index) : 0;
|
|
71
|
+
return profile.frames[((safeIndex % profile.frames.length) + profile.frames.length) % profile.frames.length];
|
|
72
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure terminal-title text. The state leads, because tabs truncate the end;
|
|
3
|
+
* the place follows: the session name when there is one, else the cwd
|
|
4
|
+
* basename, the same pieces Pi puts in its own title.
|
|
5
|
+
*
|
|
6
|
+
* A title is foreign text going to the terminal (session names come from
|
|
7
|
+
* session files, labels from model arguments): every piece is sanitized and
|
|
8
|
+
* bounded here. Pi's own `setTitle` also strips controls; this keeps the text
|
|
9
|
+
* one short, printable line before it gets there.
|
|
10
|
+
*/
|
|
11
|
+
import { backgroundSummary, sanitizeInlineText, type BackgroundWork } from "./format.ts";
|
|
12
|
+
|
|
13
|
+
/** Pi's APP_TITLE for a stock install. Not exported by the host; a renamed (`piConfig.name`) build differs. */
|
|
14
|
+
export const PI_TITLE = "π";
|
|
15
|
+
/** Characters kept from any one piece: long enough for any real name, short enough for a tab. */
|
|
16
|
+
const PIECE_LIMIT = 128;
|
|
17
|
+
const GRAPHEMES = new Intl.Segmenter(undefined, { granularity: "grapheme" });
|
|
18
|
+
|
|
19
|
+
export type TitlePhase = "idle" | "running" | "waiting" | "done" | "failed";
|
|
20
|
+
|
|
21
|
+
export interface TitleState {
|
|
22
|
+
phase: TitlePhase;
|
|
23
|
+
/** The status row's activity label ("Running npm test…"), running only. */
|
|
24
|
+
label?: string;
|
|
25
|
+
/**
|
|
26
|
+
* pi-persona's background work still running (parsed counts, never its text),
|
|
27
|
+
* done only: a run that ended with work outstanding is not "Done" yet.
|
|
28
|
+
*/
|
|
29
|
+
background?: BackgroundWork;
|
|
30
|
+
session?: string;
|
|
31
|
+
/** Basename of the session's cwd. */
|
|
32
|
+
cwdBase: string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function piece(value: string | undefined): string {
|
|
36
|
+
const safe = sanitizeInlineText(value ?? "");
|
|
37
|
+
if (safe.length <= PIECE_LIMIT) return safe;
|
|
38
|
+
let out = "";
|
|
39
|
+
for (const { segment } of GRAPHEMES.segment(safe)) {
|
|
40
|
+
if (out.length + segment.length > PIECE_LIMIT - 1) break;
|
|
41
|
+
out += segment;
|
|
42
|
+
}
|
|
43
|
+
return `${out}…`;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Pi's own title, rebuilt: "π - <session> - <cwd basename>" or "π - <cwd basename>". */
|
|
47
|
+
export function defaultTitle(session: string | undefined, cwdBase: string): string {
|
|
48
|
+
const name = piece(session);
|
|
49
|
+
const base = piece(cwdBase);
|
|
50
|
+
return name ? `${PI_TITLE} - ${name} - ${base}` : `${PI_TITLE} - ${base}`;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function terminalTitle(state: TitleState): string {
|
|
54
|
+
const where = piece(state.session) || piece(state.cwdBase);
|
|
55
|
+
const place = where ? ` — ${where}` : "";
|
|
56
|
+
switch (state.phase) {
|
|
57
|
+
case "running": {
|
|
58
|
+
const label = piece(state.label);
|
|
59
|
+
return `● ${label || "Working"}${place}`;
|
|
60
|
+
}
|
|
61
|
+
case "waiting": return `? Waiting for you${place}`;
|
|
62
|
+
// One kind is named, several are counted: a tab has no room for the breakdown.
|
|
63
|
+
case "done": return state.background ? `◌ Waiting on ${backgroundSummary(state.background)}${place}` : `✓ Done${place}`;
|
|
64
|
+
case "failed": return `✗ Failed${place}`;
|
|
65
|
+
default: return defaultTitle(state.session, state.cwdBase);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure activity tracking for the status row's transient "what is pi doing" label.
|
|
3
|
+
*
|
|
4
|
+
* Fed by Pi's `tool_execution_start`/`end` events (the wiring skips nested
|
|
5
|
+
* `parentToolCallId` calls, which the host never renders as rows). Time is
|
|
6
|
+
* injected, so this module starts no timer: the label is revealed by the frame's
|
|
7
|
+
* existing spinner repaint once a call has outlived ACTIVITY_GRACE_MS, which
|
|
8
|
+
* keeps fast calls (a 5 ms read) from flashing for a single frame. Labels are
|
|
9
|
+
* model-controlled text: every fragment passes the bounded sanitizer here, and
|
|
10
|
+
* editor.ts sanitizes again before the frame sees it.
|
|
11
|
+
*
|
|
12
|
+
* There is deliberately no `delegate` special case: pi-persona launches
|
|
13
|
+
* interactive delegate/council/flow work in the background and the call returns
|
|
14
|
+
* within milliseconds, so the grace period keeps it out of the label and a
|
|
15
|
+
* "Waiting for agent" verb would be false. pi-persona's own widget and
|
|
16
|
+
* messages carry that signal.
|
|
17
|
+
*
|
|
18
|
+
* The same slot has a second, quieter tenant: the run clock ("Working… 45s"),
|
|
19
|
+
* for the stretches of a run no call is named in. It follows the same rules —
|
|
20
|
+
* injected time, no timer, revealed by the spinner's repaint.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
import { recordOf, sanitizeInlineText, textOf } from "./format.ts";
|
|
24
|
+
import { toolWords } from "./tool-lexicon.ts";
|
|
25
|
+
|
|
26
|
+
/** A running call worth naming, ready for the status row. */
|
|
27
|
+
export interface Activity {
|
|
28
|
+
/** Sanitized, one line, ends with "…": "Running npm test…". */
|
|
29
|
+
readonly label: string;
|
|
30
|
+
/** Other top-level calls still running beside it. */
|
|
31
|
+
readonly more: number;
|
|
32
|
+
/** How long the named call has run: `now` − its own start, from the injected clock. */
|
|
33
|
+
readonly elapsedMs: number;
|
|
34
|
+
/**
|
|
35
|
+
* Set only on the run clock's entry (see createRunClock): the label names no
|
|
36
|
+
* call, `elapsedMs` is the run's own age, and the row shows it whole or not
|
|
37
|
+
* at all. Absent on a named tool call.
|
|
38
|
+
*/
|
|
39
|
+
readonly run?: true;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** A call must run this long before it is named; shorter calls never flash. */
|
|
43
|
+
export const ACTIVITY_GRACE_MS = 500;
|
|
44
|
+
|
|
45
|
+
/** Upper bound on concurrently tracked calls; a runaway fan-out (or lost end events) cannot grow the map forever. */
|
|
46
|
+
const MAX_TRACKED = 64;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Characters of a foreign argument inspected at all. The label is one short row,
|
|
50
|
+
* so a multi-megabyte command is never split, matched or sanitized whole.
|
|
51
|
+
*/
|
|
52
|
+
const SCAN_LIMIT = 4096;
|
|
53
|
+
|
|
54
|
+
/** Bound a foreign string before any scan, without leaving a split surrogate pair. */
|
|
55
|
+
function bounded(value: unknown): string {
|
|
56
|
+
const text = textOf(value);
|
|
57
|
+
if (text.length <= SCAN_LIMIT) return text;
|
|
58
|
+
const cut = text.slice(0, SCAN_LIMIT);
|
|
59
|
+
const last = cut.charCodeAt(cut.length - 1);
|
|
60
|
+
return last >= 0xd800 && last <= 0xdbff ? cut.slice(0, -1) : cut;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** `cd <path> &&` / `cd <path>;` — navigation noise in front of the real command. */
|
|
64
|
+
const CD_PREFIX = /^cd\s+(?:"[^"]*"|'[^']*'|\S+)\s*(?:&&|;)\s*/;
|
|
65
|
+
|
|
66
|
+
/** First meaningful command line: blank and `#` comment lines skipped, a leading `cd` dropped. */
|
|
67
|
+
function commandTarget(command: unknown): string {
|
|
68
|
+
for (const raw of bounded(command).split("\n")) {
|
|
69
|
+
// Judge the line as it would display: a row of bare controls is as blank as whitespace.
|
|
70
|
+
const line = sanitizeInlineText(raw);
|
|
71
|
+
if (!line || line.startsWith("#")) continue;
|
|
72
|
+
const rest = line.replace(CD_PREFIX, "");
|
|
73
|
+
return rest.trim() ? rest : line;
|
|
74
|
+
}
|
|
75
|
+
return "";
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** Last path segment, in either slash direction. */
|
|
79
|
+
function basename(path: unknown): string {
|
|
80
|
+
return bounded(path).replaceAll("\\", "/").split("/").filter(Boolean).pop() ?? "";
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** Pattern in the transcript rows' curly quotes; nothing when it sanitizes away. */
|
|
84
|
+
function quoted(pattern: unknown): string {
|
|
85
|
+
const safe = sanitizeInlineText(bounded(pattern));
|
|
86
|
+
return safe ? `“${safe}”` : "";
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function targetOf(toolName: string, args: Record<string, unknown>): string {
|
|
90
|
+
switch (toolName) {
|
|
91
|
+
case "bash":
|
|
92
|
+
return commandTarget(args.command);
|
|
93
|
+
case "read":
|
|
94
|
+
case "edit":
|
|
95
|
+
case "write":
|
|
96
|
+
return basename(args.path);
|
|
97
|
+
case "ls": {
|
|
98
|
+
const name = basename(args.path);
|
|
99
|
+
return name === "." ? "" : name;
|
|
100
|
+
}
|
|
101
|
+
case "grep":
|
|
102
|
+
case "find":
|
|
103
|
+
return quoted(args.pattern);
|
|
104
|
+
default:
|
|
105
|
+
return "";
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* One-line, present-progressive description of a running call, ending in a
|
|
111
|
+
* single "…": "Running npm test…", "Reading width.ts…", "Searching “TODO”…".
|
|
112
|
+
* Targets derive only from the call's own arguments.
|
|
113
|
+
*/
|
|
114
|
+
export function describeToolActivity(toolName: string, args: unknown): string {
|
|
115
|
+
const words = toolWords(toolName);
|
|
116
|
+
let composed: string;
|
|
117
|
+
if (words) {
|
|
118
|
+
const target = sanitizeInlineText(targetOf(toolName, recordOf(args)));
|
|
119
|
+
composed = target ? `${words.doing} ${target}` : words.doing;
|
|
120
|
+
} else {
|
|
121
|
+
const name = sanitizeInlineText(bounded(toolName));
|
|
122
|
+
composed = name ? `Running ${name}` : "Working";
|
|
123
|
+
}
|
|
124
|
+
// "echo waiting..." must not end in "...…": the visual ellipsis is ours alone.
|
|
125
|
+
return `${composed.replace(/[\s.…]+$/u, "")}…`;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** Event-fed view of the currently running top-level tool calls. */
|
|
129
|
+
export interface ActivityTracker {
|
|
130
|
+
onStart(callId: string, toolName: string, args: unknown, now: number): void;
|
|
131
|
+
onEnd(callId: string): void;
|
|
132
|
+
clear(): void;
|
|
133
|
+
/** The longest-running call once it has run for ACTIVITY_GRACE_MS; undefined before that. */
|
|
134
|
+
current(now: number): Activity | undefined;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export function createActivityTracker(): ActivityTracker {
|
|
138
|
+
// Insertion order = start order. The oldest call leads and changes only when it
|
|
139
|
+
// ends, so a parallel batch starting and finishing beside it never moves the label.
|
|
140
|
+
const running = new Map<string, { label: string; startedAt: number }>();
|
|
141
|
+
return {
|
|
142
|
+
onStart(callId, toolName, args, now) {
|
|
143
|
+
if (!callId || running.has(callId)) return;
|
|
144
|
+
running.set(callId, { label: describeToolActivity(toolName, args), startedAt: now });
|
|
145
|
+
// Evict the oldest: an entry whose end event was lost must not pin the
|
|
146
|
+
// label (or block every later call) for the rest of the run.
|
|
147
|
+
if (running.size > MAX_TRACKED) {
|
|
148
|
+
const oldest = running.keys().next();
|
|
149
|
+
if (!oldest.done) running.delete(oldest.value);
|
|
150
|
+
}
|
|
151
|
+
},
|
|
152
|
+
onEnd(callId) {
|
|
153
|
+
running.delete(callId);
|
|
154
|
+
},
|
|
155
|
+
clear() {
|
|
156
|
+
running.clear();
|
|
157
|
+
},
|
|
158
|
+
current(now) {
|
|
159
|
+
const first = running.values().next();
|
|
160
|
+
const elapsedMs = first.done ? 0 : now - first.value.startedAt;
|
|
161
|
+
if (first.done || elapsedMs < ACTIVITY_GRACE_MS) return undefined;
|
|
162
|
+
return { label: first.value.label, more: running.size - 1, elapsedMs };
|
|
163
|
+
},
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/** A run must last this long before its clock shows; a quick reply never grows a counter. */
|
|
168
|
+
export const RUN_CLOCK_GRACE_MS = 3000;
|
|
169
|
+
/** What the slot says while Pi thinks or streams and no call is named. Ours, not foreign text. */
|
|
170
|
+
export const RUN_CLOCK_LABEL = "Working…";
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* How long the current run has lasted, for the stretches no tool is named in:
|
|
174
|
+
* thinking, streaming, the gap between two calls. Like the tracker it holds one
|
|
175
|
+
* number and starts no timer; the spinner's repaint reads it against the
|
|
176
|
+
* injected clock.
|
|
177
|
+
*/
|
|
178
|
+
export interface RunClock {
|
|
179
|
+
/**
|
|
180
|
+
* The run's first agent_start. Pi's in-run continuations (a retry, a mid-run
|
|
181
|
+
* compaction, a drained follow-up) must not call it: the clock is the run's.
|
|
182
|
+
*/
|
|
183
|
+
start(now: number): void;
|
|
184
|
+
/** agent_settled, a new session, or a run that has no start to measure from. */
|
|
185
|
+
stop(): void;
|
|
186
|
+
/** `Working…` with the run's age once it has lasted RUN_CLOCK_GRACE_MS; undefined before, and when stopped. */
|
|
187
|
+
current(now: number): Activity | undefined;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export function createRunClock(): RunClock {
|
|
191
|
+
let startedAt: number | undefined;
|
|
192
|
+
return {
|
|
193
|
+
start(now) {
|
|
194
|
+
startedAt = Number.isFinite(now) ? now : undefined;
|
|
195
|
+
},
|
|
196
|
+
stop() {
|
|
197
|
+
startedAt = undefined;
|
|
198
|
+
},
|
|
199
|
+
current(now) {
|
|
200
|
+
if (startedAt === undefined) return undefined;
|
|
201
|
+
const elapsedMs = now - startedAt;
|
|
202
|
+
// A clock that stepped backwards (or NaN) shows nothing rather than a wrong time.
|
|
203
|
+
if (!(elapsedMs >= RUN_CLOCK_GRACE_MS)) return undefined;
|
|
204
|
+
return { label: RUN_CLOCK_LABEL, more: 0, elapsedMs, run: true };
|
|
205
|
+
},
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* What the status row's slot shows now: a named call once it has outlived its
|
|
211
|
+
* own grace period, else the run clock. A call still inside its grace period
|
|
212
|
+
* does not blank the slot, so a burst of fast calls never makes the clock flicker.
|
|
213
|
+
*/
|
|
214
|
+
export function currentActivity(tracker: ActivityTracker, clock: RunClock | undefined, now: number): Activity | undefined {
|
|
215
|
+
return tracker.current(now) ?? clock?.current(now);
|
|
216
|
+
}
|