@aoshizuku/pi-subagent 0.0.0-stage → 0.1.0
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/LICENSE +21 -0
- package/README.md +173 -2
- package/agents/explore.md +20 -0
- package/agents/general.md +17 -0
- package/package.json +55 -5
- package/src/batcher.ts +77 -0
- package/src/child.ts +212 -0
- package/src/cleanup.ts +40 -0
- package/src/config.ts +181 -0
- package/src/detail.ts +408 -0
- package/src/focus.ts +240 -0
- package/src/hud-state.ts +183 -0
- package/src/index.ts +1013 -0
- package/src/list.ts +223 -0
- package/src/manager.ts +588 -0
- package/src/models.ts +80 -0
- package/src/observer.ts +275 -0
- package/src/prompts.ts +103 -0
- package/src/render.ts +592 -0
- package/src/result.ts +226 -0
- package/src/run.ts +204 -0
- package/src/settings.ts +140 -0
- package/src/shizuku-settings.ts +92 -0
- package/src/stop-confirm.ts +47 -0
- package/src/test-helpers.ts +194 -0
- package/src/tool-line.ts +85 -0
- package/src/types.ts +257 -0
package/src/focus.ts
ADDED
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
// Keyboard focus on the HUD's agent rows, driven by ctx.ui.onTerminalInput (docs/07 §4).
|
|
2
|
+
//
|
|
3
|
+
// Listeners registered with onTerminalInput see every key before the editor (pi-tui tui.ts:1095-1110) and
|
|
4
|
+
// keep seeing keys while an overlay or dialog has focus. Esc is the dangerous key: in focus mode it is
|
|
5
|
+
// swallowed so it cannot interrupt the main agent, so focus mode must never get stuck. Every exit
|
|
6
|
+
// condition in docs/07 §4.3 is implemented here and covered by focus.test.ts.
|
|
7
|
+
|
|
8
|
+
import { isKeyRelease, matchesKey } from "@earendil-works/pi-tui";
|
|
9
|
+
|
|
10
|
+
import { StopConfirm } from "./stop-confirm.js";
|
|
11
|
+
|
|
12
|
+
export const FOCUS_IDLE_MS = 30_000;
|
|
13
|
+
|
|
14
|
+
export interface FocusDeps {
|
|
15
|
+
/** pi-hud announced that it renders the agent rows (subagent:hud). */
|
|
16
|
+
hudRendering(): boolean;
|
|
17
|
+
/** The main editor holds no text. */
|
|
18
|
+
editorEmpty(): boolean;
|
|
19
|
+
/** The main editor has keyboard focus (no dialog, selector or overlay took it). */
|
|
20
|
+
editorFocused(): boolean;
|
|
21
|
+
/** Agent ids in focus-mode order (hud-state focusOrder). */
|
|
22
|
+
agentIds(): string[];
|
|
23
|
+
/** Enter: open the detail overlay. The controller is suspended until resume(). */
|
|
24
|
+
open(agentId: string): void;
|
|
25
|
+
/** x: stop the agent (only called when canStop; with confirmStop, on the second x). */
|
|
26
|
+
stop(agentId: string): void;
|
|
27
|
+
canStop(agentId: string): boolean;
|
|
28
|
+
/** x must be pressed twice (docs/07 §4.4); default true. */
|
|
29
|
+
confirmStop?(): boolean;
|
|
30
|
+
/** Focus state or selection changed: re-publish the HUD state. */
|
|
31
|
+
onChange(): void;
|
|
32
|
+
idleMs?: number;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export type InputResult = { consume: true } | undefined;
|
|
36
|
+
|
|
37
|
+
const CONSUME: InputResult = { consume: true };
|
|
38
|
+
|
|
39
|
+
/** Mouse reports never reach extensions in fullscreen (the alt-screen listener runs first), but be safe. */
|
|
40
|
+
function isMouseSequence(data: string): boolean {
|
|
41
|
+
return data.startsWith("\x1b[<") || (data.startsWith("\x1b[M") && data.length >= 6);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export class FocusController {
|
|
45
|
+
private selected: string | undefined;
|
|
46
|
+
private lastIndex = 0;
|
|
47
|
+
private suspended = false;
|
|
48
|
+
private timer: ReturnType<typeof setTimeout> | undefined;
|
|
49
|
+
private disposed = false;
|
|
50
|
+
private readonly confirm: StopConfirm;
|
|
51
|
+
|
|
52
|
+
constructor(private readonly deps: FocusDeps) {
|
|
53
|
+
this.confirm = new StopConfirm(() => deps.confirmStop?.() ?? true);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Selected agent id while in focus mode (also while suspended behind the detail overlay). */
|
|
57
|
+
get selectedId(): string | undefined {
|
|
58
|
+
return this.selected;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** The selected agent got the first x and waits for the second (docs/07 §4.4). */
|
|
62
|
+
get armed(): boolean {
|
|
63
|
+
return this.confirm.isArmed(this.selected);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
get active(): boolean {
|
|
67
|
+
return this.selected !== undefined;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** True while the detail overlay opened from focus mode is showing. */
|
|
71
|
+
get isSuspended(): boolean {
|
|
72
|
+
return this.suspended;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
readonly handleInput = (data: string): InputResult => {
|
|
76
|
+
if (this.disposed || this.suspended || isMouseSequence(data)) return undefined;
|
|
77
|
+
if (!this.active) return this.handleUnfocused(data);
|
|
78
|
+
|
|
79
|
+
// Exit conditions checked on every key (docs/07 §4.3): the key then goes to pi untouched.
|
|
80
|
+
if (!this.deps.hudRendering() || !this.deps.editorFocused() || !this.deps.editorEmpty()) {
|
|
81
|
+
this.exit();
|
|
82
|
+
return undefined;
|
|
83
|
+
}
|
|
84
|
+
if (isKeyRelease(data)) return CONSUME;
|
|
85
|
+
const ids = this.deps.agentIds();
|
|
86
|
+
if (ids.length === 0) {
|
|
87
|
+
this.exit();
|
|
88
|
+
return undefined;
|
|
89
|
+
}
|
|
90
|
+
this.armTimer();
|
|
91
|
+
const index = this.indexIn(ids);
|
|
92
|
+
const isX = data === "x" || matchesKey(data, "x");
|
|
93
|
+
|
|
94
|
+
// Armed: only x goes on to stop. ↑↓ cancel and still move (↑ on the first row still leaves); every other
|
|
95
|
+
// key only cancels and is swallowed. Esc does not leave focus mode, Enter does not open the detail, and
|
|
96
|
+
// typed text does not land in the editor: a key pressed to back out of the stop does only that.
|
|
97
|
+
this.keepArm();
|
|
98
|
+
if (this.armed && !isX) {
|
|
99
|
+
this.disarm();
|
|
100
|
+
if (!matchesKey(data, "up") && !matchesKey(data, "down")) return CONSUME;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (matchesKey(data, "escape")) {
|
|
104
|
+
this.exit();
|
|
105
|
+
return CONSUME;
|
|
106
|
+
}
|
|
107
|
+
if (matchesKey(data, "up")) {
|
|
108
|
+
if (index <= 0) this.exit();
|
|
109
|
+
else this.select(ids, index - 1);
|
|
110
|
+
return CONSUME;
|
|
111
|
+
}
|
|
112
|
+
if (matchesKey(data, "down")) {
|
|
113
|
+
if (index < ids.length - 1) this.select(ids, index + 1);
|
|
114
|
+
return CONSUME;
|
|
115
|
+
}
|
|
116
|
+
if (matchesKey(data, "enter")) {
|
|
117
|
+
const id = ids[index];
|
|
118
|
+
if (id) {
|
|
119
|
+
this.suspended = true;
|
|
120
|
+
this.clearTimer();
|
|
121
|
+
this.deps.open(id);
|
|
122
|
+
}
|
|
123
|
+
return CONSUME;
|
|
124
|
+
}
|
|
125
|
+
if (isX) {
|
|
126
|
+
const id = ids[index];
|
|
127
|
+
if (id && this.deps.canStop(id)) {
|
|
128
|
+
if (this.confirm.press(id)) this.deps.stop(id);
|
|
129
|
+
this.deps.onChange();
|
|
130
|
+
}
|
|
131
|
+
return CONSUME;
|
|
132
|
+
}
|
|
133
|
+
// Anything else, typing included: leave focus mode and let the editor have the key.
|
|
134
|
+
this.exit();
|
|
135
|
+
return undefined;
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
/** The detail overlay opened from focus mode closed: back to focus mode with the same selection. */
|
|
139
|
+
resume(): void {
|
|
140
|
+
if (!this.suspended) return;
|
|
141
|
+
this.suspended = false;
|
|
142
|
+
if (this.disposed || !this.active) return;
|
|
143
|
+
const ids = this.deps.agentIds();
|
|
144
|
+
if (ids.length === 0 || !this.deps.hudRendering()) {
|
|
145
|
+
this.exit();
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
this.select(ids, this.indexIn(ids));
|
|
149
|
+
this.armTimer();
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* The set of agents changed. Exits when nothing is left; keeps the selected agent by id, or selects
|
|
154
|
+
* its neighbour when it disappeared.
|
|
155
|
+
*/
|
|
156
|
+
sync(): void {
|
|
157
|
+
if (!this.active) return;
|
|
158
|
+
const ids = this.deps.agentIds();
|
|
159
|
+
if (ids.length === 0) {
|
|
160
|
+
this.exit();
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
const index = ids.indexOf(this.selected ?? "");
|
|
164
|
+
if (index !== -1) {
|
|
165
|
+
this.lastIndex = index;
|
|
166
|
+
// The armed agent may have ended on its own, or a stop may have been requested elsewhere.
|
|
167
|
+
this.keepArm();
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
this.select(ids, Math.min(this.lastIndex, ids.length - 1));
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/** pi-hud stopped (or started) rendering the rows. */
|
|
174
|
+
setHudRendering(rendering: boolean): void {
|
|
175
|
+
if (!rendering) this.exit();
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
exit(): void {
|
|
179
|
+
this.clearTimer();
|
|
180
|
+
this.suspended = false;
|
|
181
|
+
this.confirm.cancel();
|
|
182
|
+
if (this.selected === undefined) return;
|
|
183
|
+
this.selected = undefined;
|
|
184
|
+
this.deps.onChange();
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/** session_shutdown. */
|
|
188
|
+
dispose(): void {
|
|
189
|
+
this.exit();
|
|
190
|
+
this.disposed = true;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
private handleUnfocused(data: string): InputResult {
|
|
194
|
+
if (!matchesKey(data, "down") || isKeyRelease(data)) return undefined;
|
|
195
|
+
if (!this.deps.hudRendering() || !this.deps.editorFocused() || !this.deps.editorEmpty()) return undefined;
|
|
196
|
+
const ids = this.deps.agentIds();
|
|
197
|
+
if (ids.length === 0) return undefined;
|
|
198
|
+
this.select(ids, 0);
|
|
199
|
+
this.armTimer();
|
|
200
|
+
return CONSUME;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
private indexIn(ids: readonly string[]): number {
|
|
204
|
+
const index = ids.indexOf(this.selected ?? "");
|
|
205
|
+
return index === -1 ? Math.min(this.lastIndex, ids.length - 1) : index;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
private select(ids: readonly string[], index: number): void {
|
|
209
|
+
const id = ids[index];
|
|
210
|
+
if (id === undefined) return;
|
|
211
|
+
this.lastIndex = index;
|
|
212
|
+
if (this.selected === id) return;
|
|
213
|
+
this.selected = id;
|
|
214
|
+
this.confirm.cancel();
|
|
215
|
+
this.deps.onChange();
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/** Drop the arm unless the selected agent can still be stopped; re-publishes when it dropped. */
|
|
219
|
+
private keepArm(): void {
|
|
220
|
+
const id = this.selected;
|
|
221
|
+
if (this.confirm.keep(id, id !== undefined && this.deps.canStop(id))) this.deps.onChange();
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
private disarm(): void {
|
|
225
|
+
if (this.confirm.cancel()) this.deps.onChange();
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
private armTimer(): void {
|
|
229
|
+
this.clearTimer();
|
|
230
|
+
this.timer = setTimeout(() => {
|
|
231
|
+
this.timer = undefined;
|
|
232
|
+
if (!this.suspended) this.exit();
|
|
233
|
+
}, this.deps.idleMs ?? FOCUS_IDLE_MS);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
private clearTimer(): void {
|
|
237
|
+
if (this.timer) clearTimeout(this.timer);
|
|
238
|
+
this.timer = undefined;
|
|
239
|
+
}
|
|
240
|
+
}
|
package/src/hud-state.ts
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
// HUD agent rows: which agents to show, in which order, and the windowing in focus mode (docs/07 §3.2-§3.3).
|
|
2
|
+
// pi-hud draws the rows exactly as given; it never decides which agents appear.
|
|
3
|
+
|
|
4
|
+
import { displayTokens, type UsageTotals } from "./observer.js";
|
|
5
|
+
import type { AgentStatus } from "./run.js";
|
|
6
|
+
import { clip } from "./tool-line.js";
|
|
7
|
+
|
|
8
|
+
/** pi.events channels (docs/07 §3.3). */
|
|
9
|
+
export const STATE_CHANNEL = "subagent:state";
|
|
10
|
+
export const STATE_REQUEST_CHANNEL = "subagent:state:request";
|
|
11
|
+
export const HUD_CHANNEL = "subagent:hud";
|
|
12
|
+
export const HUD_REQUEST_CHANNEL = "subagent:hud:request";
|
|
13
|
+
export const OPEN_CHANNEL = "subagent:open";
|
|
14
|
+
|
|
15
|
+
/** Finished agents stay visible this long outside focus mode (claude-hud's COMPLETED_RETENTION_MS). */
|
|
16
|
+
export const RETENTION_MS = 60_000;
|
|
17
|
+
export const MAX_ROWS = 4;
|
|
18
|
+
export const FOCUS_WINDOW = 8;
|
|
19
|
+
const DETAIL_MAX = 30;
|
|
20
|
+
|
|
21
|
+
export interface AgentRow {
|
|
22
|
+
id: string;
|
|
23
|
+
type: string;
|
|
24
|
+
description: string;
|
|
25
|
+
status: AgentStatus;
|
|
26
|
+
startedAt?: number;
|
|
27
|
+
endedAt?: number;
|
|
28
|
+
/** Current turn number, while running. */
|
|
29
|
+
turn?: number;
|
|
30
|
+
/** Short model name, only when it differs from the parent's model. */
|
|
31
|
+
model?: string;
|
|
32
|
+
/** Failure reason and the like, already shortened. */
|
|
33
|
+
detail?: string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface HudState {
|
|
37
|
+
rows: AgentRow[];
|
|
38
|
+
/** Rows hidden above the window (focus mode only). */
|
|
39
|
+
above: number;
|
|
40
|
+
/** Rows hidden below; outside focus mode the N of "+N more agents". */
|
|
41
|
+
below: number;
|
|
42
|
+
/** `armed`: the selected agent got the first x and waits for the second (docs/07 §4.4). */
|
|
43
|
+
focus: { selectedId: string; armed?: true } | null;
|
|
44
|
+
/** input + output + cacheWrite over all agents and runs (docs/07 §3.5). */
|
|
45
|
+
tokens: number;
|
|
46
|
+
cost: number;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export const EMPTY_STATE: HudState = { rows: [], above: 0, below: 0, focus: null, tokens: 0, cost: 0 };
|
|
50
|
+
|
|
51
|
+
/** The record fields the HUD needs; satisfied by AgentRecord. */
|
|
52
|
+
export interface HudRecord {
|
|
53
|
+
agentId: string;
|
|
54
|
+
type: string;
|
|
55
|
+
description: string;
|
|
56
|
+
status: AgentStatus;
|
|
57
|
+
reason?: string;
|
|
58
|
+
createdAt: number;
|
|
59
|
+
startedAt?: number;
|
|
60
|
+
endedAt?: number;
|
|
61
|
+
model: string;
|
|
62
|
+
stats: { turns: number };
|
|
63
|
+
totalUsage: UsageTotals;
|
|
64
|
+
/** Set once a stop was requested; the run keeps its status until it returns. */
|
|
65
|
+
stoppedBy?: string;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function isActive(status: AgentStatus): boolean {
|
|
69
|
+
return status === "queued" || status === "running";
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Running first, then queued, each in start order (queued ones by creation). */
|
|
73
|
+
function activeOrder(a: HudRecord, b: HudRecord): number {
|
|
74
|
+
if (a.status !== b.status) return a.status === "running" ? -1 : 1;
|
|
75
|
+
return (a.startedAt ?? a.createdAt) - (b.startedAt ?? b.createdAt) || a.createdAt - b.createdAt;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function endedOrder(a: HudRecord, b: HudRecord): number {
|
|
79
|
+
return (b.endedAt ?? 0) - (a.endedAt ?? 0);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** Outside focus mode: active agents, then those that ended within the retention window, newest first. */
|
|
83
|
+
export function shownRecords<T extends HudRecord>(records: readonly T[], now: number): T[] {
|
|
84
|
+
const active = records.filter((record) => isActive(record.status)).sort(activeOrder);
|
|
85
|
+
const recent = records
|
|
86
|
+
.filter((record) => !isActive(record.status) && record.endedAt !== undefined && now - record.endedAt <= RETENTION_MS)
|
|
87
|
+
.sort(endedOrder);
|
|
88
|
+
return [...active, ...recent];
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** Focus mode and the /agents list: every agent of the session, active first, the rest by end time. */
|
|
92
|
+
export function focusOrder<T extends HudRecord>(records: readonly T[]): T[] {
|
|
93
|
+
const active = records.filter((record) => isActive(record.status)).sort(activeOrder);
|
|
94
|
+
const ended = records.filter((record) => !isActive(record.status)).sort(endedOrder);
|
|
95
|
+
return [...active, ...ended];
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** Model id without the provider prefix, when it differs from the parent's provider/id. */
|
|
99
|
+
export function shortModel(model: string, parentModel: string | undefined): string | undefined {
|
|
100
|
+
if (!model || model === "(default)" || model === parentModel) return undefined;
|
|
101
|
+
const slash = model.indexOf("/");
|
|
102
|
+
return slash === -1 ? model : model.slice(slash + 1);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export function toRow(record: HudRecord, parentModel: string | undefined): AgentRow {
|
|
106
|
+
const row: AgentRow = { id: record.agentId, type: record.type, description: record.description, status: record.status };
|
|
107
|
+
if (record.status !== "queued" && record.startedAt !== undefined) row.startedAt = record.startedAt;
|
|
108
|
+
if (record.endedAt !== undefined && !isActive(record.status)) row.endedAt = record.endedAt;
|
|
109
|
+
// A stop was requested and the run has not returned yet: "stopping" in place of the turn.
|
|
110
|
+
const stopping = isActive(record.status) && record.stoppedBy !== undefined;
|
|
111
|
+
if (record.status === "running" && !stopping) row.turn = record.stats.turns + 1;
|
|
112
|
+
const model = shortModel(record.model, parentModel);
|
|
113
|
+
if (model) row.model = model;
|
|
114
|
+
if (stopping) row.detail = "stopping";
|
|
115
|
+
else if (record.status === "failed") row.detail = clip(record.reason ?? "failed", DETAIL_MAX);
|
|
116
|
+
else if (record.status === "max_turns") row.detail = "out of turns";
|
|
117
|
+
else if (record.status === "context_limit") row.detail = "context full";
|
|
118
|
+
return row;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/** Window of `size` rows that keeps `index` roughly centred. */
|
|
122
|
+
export function windowAround(count: number, index: number, size = FOCUS_WINDOW): { start: number; end: number } {
|
|
123
|
+
if (count <= size) return { start: 0, end: count };
|
|
124
|
+
const start = Math.max(0, Math.min(index - Math.floor(size / 2), count - size));
|
|
125
|
+
return { start, end: start + size };
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export interface BuildOptions {
|
|
129
|
+
now: number;
|
|
130
|
+
/** provider/id of the parent session's model. */
|
|
131
|
+
parentModel?: string;
|
|
132
|
+
/** Selected agent in focus mode; undefined outside it. */
|
|
133
|
+
focusId?: string;
|
|
134
|
+
/** The selected agent waits for the second x. */
|
|
135
|
+
focusArmed?: boolean;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export function buildHudState(records: readonly HudRecord[], options: BuildOptions): HudState {
|
|
139
|
+
let tokens = 0;
|
|
140
|
+
let cost = 0;
|
|
141
|
+
for (const record of records) {
|
|
142
|
+
tokens += displayTokens(record.totalUsage);
|
|
143
|
+
cost += record.totalUsage.cost;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if (options.focusId !== undefined) {
|
|
147
|
+
const ordered = focusOrder(records);
|
|
148
|
+
const index = Math.max(
|
|
149
|
+
0,
|
|
150
|
+
ordered.findIndex((record) => record.agentId === options.focusId),
|
|
151
|
+
);
|
|
152
|
+
const { start, end } = windowAround(ordered.length, index);
|
|
153
|
+
return {
|
|
154
|
+
rows: ordered.slice(start, end).map((record) => toRow(record, options.parentModel)),
|
|
155
|
+
above: start,
|
|
156
|
+
below: ordered.length - end,
|
|
157
|
+
focus: options.focusArmed ? { selectedId: options.focusId, armed: true } : { selectedId: options.focusId },
|
|
158
|
+
tokens,
|
|
159
|
+
cost,
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const shown = shownRecords(records, options.now);
|
|
164
|
+
return {
|
|
165
|
+
rows: shown.slice(0, MAX_ROWS).map((record) => toRow(record, options.parentModel)),
|
|
166
|
+
above: 0,
|
|
167
|
+
below: Math.max(0, shown.length - MAX_ROWS),
|
|
168
|
+
focus: null,
|
|
169
|
+
tokens,
|
|
170
|
+
cost,
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/** When the next finished row drops out of the retention window, so the HUD can be refreshed then. */
|
|
175
|
+
export function nextExpiry(records: readonly HudRecord[], now: number): number | undefined {
|
|
176
|
+
let next: number | undefined;
|
|
177
|
+
for (const record of records) {
|
|
178
|
+
if (isActive(record.status) || record.endedAt === undefined) continue;
|
|
179
|
+
const expiry = record.endedAt + RETENTION_MS;
|
|
180
|
+
if (expiry > now && (next === undefined || expiry < next)) next = expiry;
|
|
181
|
+
}
|
|
182
|
+
return next;
|
|
183
|
+
}
|