@timmyjl12/pi-subagents 0.0.0-stage → 0.20.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/CHANGELOG.md +827 -0
- package/CONTRIBUTING.md +72 -0
- package/LICENSE +21 -0
- package/README.md +1079 -2
- package/SECURITY.md +97 -0
- package/dist/abortable.d.ts +12 -0
- package/dist/abortable.js +42 -0
- package/dist/active-agents-prompt.d.ts +18 -0
- package/dist/active-agents-prompt.js +34 -0
- package/dist/advisor-status.d.ts +16 -0
- package/dist/advisor-status.js +74 -0
- package/dist/agent-color.d.ts +35 -0
- package/dist/agent-color.js +123 -0
- package/dist/agent-file-toggle.d.ts +125 -0
- package/dist/agent-file-toggle.js +264 -0
- package/dist/agent-manager.d.ts +485 -0
- package/dist/agent-manager.js +1380 -0
- package/dist/agent-runner.d.ts +319 -0
- package/dist/agent-runner.js +1128 -0
- package/dist/agent-types.d.ts +119 -0
- package/dist/agent-types.js +286 -0
- package/dist/child-context.d.ts +15 -0
- package/dist/child-context.js +181 -0
- package/dist/child-session-shutdown.d.ts +3 -0
- package/dist/child-session-shutdown.js +48 -0
- package/dist/context.d.ts +12 -0
- package/dist/context.js +56 -0
- package/dist/cross-extension-rpc.d.ts +66 -0
- package/dist/cross-extension-rpc.js +138 -0
- package/dist/custom-agents.d.ts +54 -0
- package/dist/custom-agents.js +386 -0
- package/dist/default-agents.d.ts +7 -0
- package/dist/default-agents.js +125 -0
- package/dist/enabled-models.d.ts +49 -0
- package/dist/enabled-models.js +145 -0
- package/dist/env.d.ts +6 -0
- package/dist/env.js +28 -0
- package/dist/error-log.d.ts +58 -0
- package/dist/error-log.js +168 -0
- package/dist/group-join.d.ts +32 -0
- package/dist/group-join.js +116 -0
- package/dist/index.d.ts +52 -0
- package/dist/index.js +3896 -0
- package/dist/invocation-config.d.ts +137 -0
- package/dist/invocation-config.js +129 -0
- package/dist/memory.d.ts +53 -0
- package/dist/memory.js +165 -0
- package/dist/mention-clone.d.ts +87 -0
- package/dist/mention-clone.js +178 -0
- package/dist/mention.d.ts +81 -0
- package/dist/mention.js +131 -0
- package/dist/model-resolver.d.ts +36 -0
- package/dist/model-resolver.js +95 -0
- package/dist/model-scope.d.ts +49 -0
- package/dist/model-scope.js +48 -0
- package/dist/nested-tools.d.ts +55 -0
- package/dist/nested-tools.js +299 -0
- package/dist/output-diagnostics.d.ts +11 -0
- package/dist/output-diagnostics.js +64 -0
- package/dist/output-file.d.ts +53 -0
- package/dist/output-file.js +248 -0
- package/dist/prompts.d.ts +61 -0
- package/dist/prompts.js +94 -0
- package/dist/recovery.d.ts +56 -0
- package/dist/recovery.js +341 -0
- package/dist/schedule-store.d.ts +44 -0
- package/dist/schedule-store.js +210 -0
- package/dist/schedule.d.ts +109 -0
- package/dist/schedule.js +359 -0
- package/dist/settings.d.ts +360 -0
- package/dist/settings.js +251 -0
- package/dist/skill-loader.d.ts +24 -0
- package/dist/skill-loader.js +93 -0
- package/dist/standalone-fallback.d.ts +30 -0
- package/dist/standalone-fallback.js +239 -0
- package/dist/status-note.d.ts +61 -0
- package/dist/status-note.js +85 -0
- package/dist/structured-output.d.ts +61 -0
- package/dist/structured-output.js +112 -0
- package/dist/terminal-progress.d.ts +115 -0
- package/dist/terminal-progress.js +206 -0
- package/dist/types.d.ts +382 -0
- package/dist/types.js +5 -0
- package/dist/ui/agent-mention.d.ts +82 -0
- package/dist/ui/agent-mention.js +187 -0
- package/dist/ui/agent-widget.d.ts +235 -0
- package/dist/ui/agent-widget.js +652 -0
- package/dist/ui/conversation-viewer.d.ts +105 -0
- package/dist/ui/conversation-viewer.js +540 -0
- package/dist/ui/fleet-list.d.ts +183 -0
- package/dist/ui/fleet-list.js +494 -0
- package/dist/ui/fleet-overlay.d.ts +172 -0
- package/dist/ui/fleet-overlay.js +691 -0
- package/dist/ui/native-transcript.d.ts +33 -0
- package/dist/ui/native-transcript.js +230 -0
- package/dist/ui/schedule-menu.d.ts +16 -0
- package/dist/ui/schedule-menu.js +94 -0
- package/dist/ui/select-item.d.ts +27 -0
- package/dist/ui/select-item.js +34 -0
- package/dist/ui/tool-progress.d.ts +22 -0
- package/dist/ui/tool-progress.js +56 -0
- package/dist/ui/viewer-keys.d.ts +20 -0
- package/dist/ui/viewer-keys.js +17 -0
- package/dist/ui/workflow-card.d.ts +175 -0
- package/dist/ui/workflow-card.js +332 -0
- package/dist/ui/workflow-dialog.d.ts +305 -0
- package/dist/ui/workflow-dialog.js +843 -0
- package/dist/ui/workflow-menu.d.ts +60 -0
- package/dist/ui/workflow-menu.js +147 -0
- package/dist/usage.d.ts +135 -0
- package/dist/usage.js +120 -0
- package/dist/workflow/collisions.d.ts +95 -0
- package/dist/workflow/collisions.js +88 -0
- package/dist/workflow/entry.d.ts +32 -0
- package/dist/workflow/entry.js +29 -0
- package/dist/workflow/host.d.ts +62 -0
- package/dist/workflow/host.js +363 -0
- package/dist/workflow/journal.d.ts +97 -0
- package/dist/workflow/journal.js +120 -0
- package/dist/workflow/json-schema.d.ts +51 -0
- package/dist/workflow/json-schema.js +111 -0
- package/dist/workflow/meta.d.ts +67 -0
- package/dist/workflow/meta.js +317 -0
- package/dist/workflow/progress.d.ts +224 -0
- package/dist/workflow/progress.js +361 -0
- package/dist/workflow/runtime.d.ts +334 -0
- package/dist/workflow/runtime.js +830 -0
- package/dist/workflow/saved.d.ts +90 -0
- package/dist/workflow/saved.js +203 -0
- package/dist/workflow/task.d.ts +136 -0
- package/dist/workflow/task.js +207 -0
- package/dist/workflow/tool-description.d.ts +38 -0
- package/dist/workflow/tool-description.js +199 -0
- package/dist/workflow/worker-source.d.ts +47 -0
- package/dist/workflow/worker-source.js +778 -0
- package/dist/worktree.d.ts +52 -0
- package/dist/worktree.js +164 -0
- package/dist/xml.d.ts +10 -0
- package/dist/xml.js +12 -0
- package/docs/FORK.md +40 -0
- package/docs/recovery.md +62 -0
- package/docs/rpc.md +189 -0
- package/docs/workflows.md +437 -0
- package/examples/agent-tool-description.md +43 -0
- package/examples/workflows/compose.js +51 -0
- package/examples/workflows/fan-out-audit.js +47 -0
- package/examples/workflows/gated-fix.js +60 -0
- package/examples/workflows/lib/count-child.js +27 -0
- package/examples/workflows/review-panel.js +63 -0
- package/examples/workflows/structured-findings.js +78 -0
- package/package.json +75 -6
- package/src/abortable.ts +43 -0
- package/src/active-agents-prompt.ts +39 -0
- package/src/advisor-status.ts +74 -0
- package/src/agent-color.ts +161 -0
- package/src/agent-file-toggle.ts +273 -0
- package/src/agent-manager.ts +1601 -0
- package/src/agent-runner.ts +1372 -0
- package/src/agent-types.ts +345 -0
- package/src/child-context.ts +173 -0
- package/src/child-session-shutdown.ts +46 -0
- package/src/context.ts +58 -0
- package/src/cross-extension-rpc.ts +198 -0
- package/src/custom-agents.ts +417 -0
- package/src/default-agents.ts +129 -0
- package/src/enabled-models.ts +180 -0
- package/src/env.ts +33 -0
- package/src/error-log.ts +193 -0
- package/src/group-join.ts +141 -0
- package/src/index.ts +4218 -0
- package/src/invocation-config.ts +230 -0
- package/src/memory.ts +179 -0
- package/src/mention-clone.ts +221 -0
- package/src/mention.ts +141 -0
- package/src/model-resolver.ts +118 -0
- package/src/model-scope.ts +70 -0
- package/src/nested-tools.ts +422 -0
- package/src/output-diagnostics.ts +68 -0
- package/src/output-file.ts +258 -0
- package/src/prompts.ts +151 -0
- package/src/recovery.ts +320 -0
- package/src/schedule-store.ts +201 -0
- package/src/schedule.ts +386 -0
- package/src/settings.ts +587 -0
- package/src/skill-loader.ts +102 -0
- package/src/standalone-fallback.ts +195 -0
- package/src/status-note.ts +90 -0
- package/src/structured-output.ts +130 -0
- package/src/terminal-progress.ts +215 -0
- package/src/types.ts +394 -0
- package/src/ui/agent-mention.ts +216 -0
- package/src/ui/agent-widget.ts +732 -0
- package/src/ui/conversation-viewer.ts +523 -0
- package/src/ui/fleet-list.ts +563 -0
- package/src/ui/fleet-overlay.ts +847 -0
- package/src/ui/native-transcript.ts +220 -0
- package/src/ui/schedule-menu.ts +105 -0
- package/src/ui/select-item.ts +45 -0
- package/src/ui/tool-progress.ts +67 -0
- package/src/ui/viewer-keys.ts +39 -0
- package/src/ui/workflow-card.ts +470 -0
- package/src/ui/workflow-dialog.ts +1115 -0
- package/src/ui/workflow-menu.ts +193 -0
- package/src/usage.ts +167 -0
- package/src/workflow/collisions.ts +123 -0
- package/src/workflow/entry.ts +47 -0
- package/src/workflow/host.ts +404 -0
- package/src/workflow/journal.ts +164 -0
- package/src/workflow/json-schema.ts +128 -0
- package/src/workflow/meta.ts +325 -0
- package/src/workflow/progress.ts +550 -0
- package/src/workflow/runtime.ts +1219 -0
- package/src/workflow/saved.ts +217 -0
- package/src/workflow/task.ts +302 -0
- package/src/workflow/tool-description.ts +200 -0
- package/src/workflow/worker-source.ts +781 -0
- package/src/worktree.ts +205 -0
- package/src/xml.ts +13 -0
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* fleet-list.ts — Claude Code-style "FleetView" list rendered below the editor.
|
|
3
|
+
*
|
|
4
|
+
* Shows `main` + each running/queued subagent as a navigable list. Pressing ↓ (or
|
|
5
|
+
* ←) at an empty prompt activates the list; ↑/↓ move the selection (filled ● marker),
|
|
6
|
+
* Enter opens the selected agent's live conversation overlay, Esc returns to the prompt.
|
|
7
|
+
* A viewer stays open when its agent finishes; finished agents linger briefly in the list.
|
|
8
|
+
*
|
|
9
|
+
* Mechanics (see plan): the list is a `belowEditor` widget (render-only), and ALL key
|
|
10
|
+
* handling goes through `onTerminalInput` — which fires before the focused editor and
|
|
11
|
+
* can `consume` keys — gated on `getEditorText() === ""` so normal typing is untouched.
|
|
12
|
+
*/
|
|
13
|
+
import { type AgentManager } from "../agent-manager.js";
|
|
14
|
+
import type { AgentRecord } from "../types.js";
|
|
15
|
+
import { type AgentActivity, type Theme } from "./agent-widget.js";
|
|
16
|
+
/** Minimal UI surface the FleetView needs from `ctx.ui` (structural subset). */
|
|
17
|
+
export type FleetUICtx = {
|
|
18
|
+
setWidget(key: string, content: undefined | ((tui: any, theme: Theme) => {
|
|
19
|
+
render(width: number): string[];
|
|
20
|
+
invalidate(): void;
|
|
21
|
+
dispose?(): void;
|
|
22
|
+
}), options?: {
|
|
23
|
+
placement?: "aboveEditor" | "belowEditor";
|
|
24
|
+
}): void;
|
|
25
|
+
onTerminalInput(handler: (data: string) => {
|
|
26
|
+
consume?: boolean;
|
|
27
|
+
data?: string;
|
|
28
|
+
} | undefined): () => void;
|
|
29
|
+
getEditorText(): string;
|
|
30
|
+
notify(message: string, type?: "info" | "warning" | "error"): void;
|
|
31
|
+
custom<T>(factory: (tui: any, theme: Theme, keybindings: any, done: (result: T) => void) => {
|
|
32
|
+
render(width: number): string[];
|
|
33
|
+
invalidate(): void;
|
|
34
|
+
dispose?(): void;
|
|
35
|
+
}, options?: {
|
|
36
|
+
overlay?: boolean;
|
|
37
|
+
overlayOptions?: unknown;
|
|
38
|
+
onHandle?: (handle: unknown) => void;
|
|
39
|
+
}): Promise<T>;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* A workflow run, as the fleet list needs to see it.
|
|
43
|
+
*
|
|
44
|
+
* Narrow on purpose: the list knows nothing about `WorkflowTask`, the runtime
|
|
45
|
+
* or the dialog, so it stays as testable as it was when it only held agents.
|
|
46
|
+
* The extension maps its tasks into this shape and injects an opener.
|
|
47
|
+
*/
|
|
48
|
+
export interface FleetWorkflow {
|
|
49
|
+
id: string;
|
|
50
|
+
/** The `meta.name` of the run, or its id when the script named nothing. */
|
|
51
|
+
name: string;
|
|
52
|
+
status: "running" | "completed" | "failed" | "killed" | "paused";
|
|
53
|
+
doneCount: number;
|
|
54
|
+
totalCount: number;
|
|
55
|
+
startedAt: number;
|
|
56
|
+
/** Set once the run settles, which is what freezes its clock. */
|
|
57
|
+
completedAt?: number;
|
|
58
|
+
tokens: number;
|
|
59
|
+
}
|
|
60
|
+
/** `11s` — integer seconds, no decimal/suffix (matches Claude Code, unlike formatMs). */
|
|
61
|
+
export declare function formatFleetElapsed(ms: number): string;
|
|
62
|
+
/** `↓ 13.1k tokens` — down-arrow prefix, compact magnitude, plural "tokens". */
|
|
63
|
+
export declare function formatFleetTokens(count: number): string;
|
|
64
|
+
export declare class FleetList {
|
|
65
|
+
private manager;
|
|
66
|
+
/**
|
|
67
|
+
* Read live at render time. Whether each row shows an estimated cost after
|
|
68
|
+
* its token count. Defaults to off — the extension supplies the user's
|
|
69
|
+
* `showCost` setting.
|
|
70
|
+
*/
|
|
71
|
+
private showCost;
|
|
72
|
+
private ui;
|
|
73
|
+
private tui;
|
|
74
|
+
private inputUnsub;
|
|
75
|
+
private widgetRegistered;
|
|
76
|
+
private timer;
|
|
77
|
+
private enabled;
|
|
78
|
+
/** Whether arrow keys currently navigate the list (vs. flow to the editor). */
|
|
79
|
+
private active;
|
|
80
|
+
/** 0 = `main`, 1..N = workflows/agents; also the fallback if the row disappears. */
|
|
81
|
+
private selectedIndex;
|
|
82
|
+
private selectedKey;
|
|
83
|
+
/** Set while a conversation overlay is open; calling it closes the overlay. */
|
|
84
|
+
private viewerClose;
|
|
85
|
+
private viewingAgentId;
|
|
86
|
+
private openAgent;
|
|
87
|
+
/**
|
|
88
|
+
* Injected by the extension; opens the full two-pane fleet overlay. When set,
|
|
89
|
+
* ← at an empty prompt opens that overlay instead of engaging inline
|
|
90
|
+
* navigation (↓ still does). Without it ← keeps its legacy activator role, so
|
|
91
|
+
* a host that only wires the list sees no behavior change.
|
|
92
|
+
*/
|
|
93
|
+
private overlayOpener;
|
|
94
|
+
/** Injected by the extension; absent until workflows are wired (or at all). */
|
|
95
|
+
private workflowSource;
|
|
96
|
+
private openWorkflow;
|
|
97
|
+
/**
|
|
98
|
+
* Set while the workflow inspector is up.
|
|
99
|
+
*
|
|
100
|
+
* It does the two jobs `viewerClose` does for an agent's overlay — keep the
|
|
101
|
+
* list out of the dialog's keys, and remember which row to come back to —
|
|
102
|
+
* minus the close handle, because that overlay belongs to the extension.
|
|
103
|
+
*/
|
|
104
|
+
private viewingWorkflowId;
|
|
105
|
+
constructor(manager: AgentManager, _agentActivity: Map<string, AgentActivity>,
|
|
106
|
+
/**
|
|
107
|
+
* Read live at render time. Whether each row shows an estimated cost after
|
|
108
|
+
* its token count. Defaults to off — the extension supplies the user's
|
|
109
|
+
* `showCost` setting.
|
|
110
|
+
*/
|
|
111
|
+
showCost?: () => boolean);
|
|
112
|
+
/** One extension-owned opener for fleet, menu, and workflow entry points. */
|
|
113
|
+
setAgentOpener(open: (record: AgentRecord, onCloseReady: (close: () => void) => void) => Promise<void>): void;
|
|
114
|
+
/** Wire the two-pane overlay as what ← opens (see the field's note). */
|
|
115
|
+
setOverlayOpener(open: () => void): void;
|
|
116
|
+
setEnabled(enabled: boolean): void;
|
|
117
|
+
/** Capture the UI context and (re)register the global input handler. */
|
|
118
|
+
setUICtx(ui: FleetUICtx): void;
|
|
119
|
+
/** Ensure the re-render timer is running (called when an agent spawns). */
|
|
120
|
+
ensureTimer(): void;
|
|
121
|
+
/**
|
|
122
|
+
* Called when an agent finishes. The viewer (if open on it) stays open so the
|
|
123
|
+
* final output remains readable, and the row lingers in the list — just refresh.
|
|
124
|
+
*/
|
|
125
|
+
onAgentFinished(_id: string): void;
|
|
126
|
+
dispose(): void;
|
|
127
|
+
/** Re-register/refresh the below-editor widget; clears it when nothing remains. */
|
|
128
|
+
update(): void;
|
|
129
|
+
/**
|
|
130
|
+
* Agents shown in the list, ordered earliest-launched first so the ones you
|
|
131
|
+
* started sooner sit at the top. Every row is openable (has a session), so Enter
|
|
132
|
+
* never dead-ends. Included: running/queued, plus the agent currently being
|
|
133
|
+
* viewed, plus recently-finished ones (they linger briefly before dropping out).
|
|
134
|
+
* Pending agents with no session yet are hidden until they start.
|
|
135
|
+
* (`listAgents()` is newest-first, so we re-sort.)
|
|
136
|
+
*/
|
|
137
|
+
private agentRecords;
|
|
138
|
+
/**
|
|
139
|
+
* Wire workflow runs into the list.
|
|
140
|
+
*
|
|
141
|
+
* Injected rather than constructed here because the fleet list predates
|
|
142
|
+
* workflows and must keep working without them — a session with the feature
|
|
143
|
+
* switched off never calls this, and the roster is agents-only exactly as
|
|
144
|
+
* before.
|
|
145
|
+
*/
|
|
146
|
+
setWorkflowSource(source: () => readonly FleetWorkflow[], open: (id: string) => Promise<void> | void): void;
|
|
147
|
+
/** Live runs, plus recently settled ones — the same linger the agents get. */
|
|
148
|
+
private workflows;
|
|
149
|
+
/**
|
|
150
|
+
* Runs sit above the agents rather than interleaved by start time: a run owns
|
|
151
|
+
* most of the agents under it, so listing the container first is what makes
|
|
152
|
+
* the list read as a hierarchy rather than a shuffle.
|
|
153
|
+
*/
|
|
154
|
+
private roster;
|
|
155
|
+
private select;
|
|
156
|
+
private clampSelection;
|
|
157
|
+
/** Returns `{consume:true}` to swallow a key, or undefined to let it through. */
|
|
158
|
+
handleKey(data: string): {
|
|
159
|
+
consume?: boolean;
|
|
160
|
+
data?: string;
|
|
161
|
+
} | undefined;
|
|
162
|
+
/**
|
|
163
|
+
* True when pi's prompt editor owns the keyboard. pi's editor is an `Editor`
|
|
164
|
+
* subclass (CustomEditor) while every dialog/selector is not, and the loader
|
|
165
|
+
* aliases pi-tui to pi's own copy, so `instanceof` is a reliable identity
|
|
166
|
+
* check. Prefer Pi's public accessor; the fallback supports older UI test
|
|
167
|
+
* hosts. Unknowable focus counts as the editor so activation keeps working.
|
|
168
|
+
*/
|
|
169
|
+
private editorHasFocus;
|
|
170
|
+
private deactivate;
|
|
171
|
+
private openSelected;
|
|
172
|
+
/** Reset overlay state and return to the list (on close, auto-close, or error). */
|
|
173
|
+
private clearViewer;
|
|
174
|
+
private renderBar;
|
|
175
|
+
private bullet;
|
|
176
|
+
/**
|
|
177
|
+
* A run's row. Shaped like an agent's — bullet, kind, name, stats flush right
|
|
178
|
+
* — so the two read as one list, with the agent count where an agent has its
|
|
179
|
+
* description and the same elapsed/token tail.
|
|
180
|
+
*/
|
|
181
|
+
private renderWorkflowRow;
|
|
182
|
+
private renderAgentRow;
|
|
183
|
+
}
|
|
@@ -0,0 +1,494 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* fleet-list.ts — Claude Code-style "FleetView" list rendered below the editor.
|
|
3
|
+
*
|
|
4
|
+
* Shows `main` + each running/queued subagent as a navigable list. Pressing ↓ (or
|
|
5
|
+
* ←) at an empty prompt activates the list; ↑/↓ move the selection (filled ● marker),
|
|
6
|
+
* Enter opens the selected agent's live conversation overlay, Esc returns to the prompt.
|
|
7
|
+
* A viewer stays open when its agent finishes; finished agents linger briefly in the list.
|
|
8
|
+
*
|
|
9
|
+
* Mechanics (see plan): the list is a `belowEditor` widget (render-only), and ALL key
|
|
10
|
+
* handling goes through `onTerminalInput` — which fires before the focused editor and
|
|
11
|
+
* can `consume` keys — gated on `getEditorText() === ""` so normal typing is untouched.
|
|
12
|
+
*/
|
|
13
|
+
import { Editor, isKeyRelease, Key, matchesKey, truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
|
|
14
|
+
import { hasAgentBadge, renderAgentName } from "../agent-color.js";
|
|
15
|
+
import { isTopLevelAgent } from "../agent-manager.js";
|
|
16
|
+
import { getLifetimeCost, getLifetimeTotal } from "../usage.js";
|
|
17
|
+
import { formatCost } from "./agent-widget.js";
|
|
18
|
+
/** Widget key for the below-editor fleet list. */
|
|
19
|
+
const FLEET_KEY = "fleet";
|
|
20
|
+
/** Max agent rows shown at once; extras collapse into a "↓ N more" indicator. */
|
|
21
|
+
const MAX_AGENT_ROWS = 5;
|
|
22
|
+
/** Re-render cadence so elapsed/token stats tick while agents run. */
|
|
23
|
+
const TICK_MS = 200;
|
|
24
|
+
/** How long a finished agent lingers in the list before it drops out. */
|
|
25
|
+
const FINISHED_LINGER_MS = 4000;
|
|
26
|
+
function entryKey(entry) {
|
|
27
|
+
return entry.kind === "agent" ? `agent:${entry.record.id}`
|
|
28
|
+
: entry.kind === "workflow" ? `workflow:${entry.workflow.id}` : "main";
|
|
29
|
+
}
|
|
30
|
+
/** `11s` — integer seconds, no decimal/suffix (matches Claude Code, unlike formatMs). */
|
|
31
|
+
export function formatFleetElapsed(ms) {
|
|
32
|
+
return `${Math.max(0, Math.round(ms / 1000))}s`;
|
|
33
|
+
}
|
|
34
|
+
/** `↓ 13.1k tokens` — down-arrow prefix, compact magnitude, plural "tokens". */
|
|
35
|
+
export function formatFleetTokens(count) {
|
|
36
|
+
let compact;
|
|
37
|
+
if (count >= 1_000_000)
|
|
38
|
+
compact = `${(count / 1_000_000).toFixed(1)}M`;
|
|
39
|
+
else if (count >= 1_000)
|
|
40
|
+
compact = `${(count / 1_000).toFixed(1)}k`;
|
|
41
|
+
else
|
|
42
|
+
compact = `${count}`;
|
|
43
|
+
return `↓ ${compact} tokens`;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Place `right` flush to `width`, truncating `left` first so the stats survive.
|
|
47
|
+
* The final clamp guarantees the line never exceeds `width` (which would wrap and
|
|
48
|
+
* desync pi's line-diff → flicker) even on a terminal too narrow for the stats.
|
|
49
|
+
*/
|
|
50
|
+
function rightAlign(left, right, width) {
|
|
51
|
+
const rightW = visibleWidth(right);
|
|
52
|
+
const maxLeft = Math.max(0, width - rightW - 1);
|
|
53
|
+
const leftClamped = truncateToWidth(left, maxLeft);
|
|
54
|
+
const gap = Math.max(1, width - visibleWidth(leftClamped) - rightW);
|
|
55
|
+
return truncateToWidth(leftClamped + " ".repeat(gap) + right, width);
|
|
56
|
+
}
|
|
57
|
+
export class FleetList {
|
|
58
|
+
manager;
|
|
59
|
+
showCost;
|
|
60
|
+
ui;
|
|
61
|
+
tui;
|
|
62
|
+
inputUnsub;
|
|
63
|
+
widgetRegistered = false;
|
|
64
|
+
timer;
|
|
65
|
+
enabled = true;
|
|
66
|
+
/** Whether arrow keys currently navigate the list (vs. flow to the editor). */
|
|
67
|
+
active = false;
|
|
68
|
+
/** 0 = `main`, 1..N = workflows/agents; also the fallback if the row disappears. */
|
|
69
|
+
selectedIndex = 0;
|
|
70
|
+
selectedKey = "main";
|
|
71
|
+
/** Set while a conversation overlay is open; calling it closes the overlay. */
|
|
72
|
+
viewerClose;
|
|
73
|
+
viewingAgentId;
|
|
74
|
+
openAgent;
|
|
75
|
+
/**
|
|
76
|
+
* Injected by the extension; opens the full two-pane fleet overlay. When set,
|
|
77
|
+
* ← at an empty prompt opens that overlay instead of engaging inline
|
|
78
|
+
* navigation (↓ still does). Without it ← keeps its legacy activator role, so
|
|
79
|
+
* a host that only wires the list sees no behavior change.
|
|
80
|
+
*/
|
|
81
|
+
overlayOpener;
|
|
82
|
+
/** Injected by the extension; absent until workflows are wired (or at all). */
|
|
83
|
+
workflowSource;
|
|
84
|
+
openWorkflow;
|
|
85
|
+
/**
|
|
86
|
+
* Set while the workflow inspector is up.
|
|
87
|
+
*
|
|
88
|
+
* It does the two jobs `viewerClose` does for an agent's overlay — keep the
|
|
89
|
+
* list out of the dialog's keys, and remember which row to come back to —
|
|
90
|
+
* minus the close handle, because that overlay belongs to the extension.
|
|
91
|
+
*/
|
|
92
|
+
viewingWorkflowId;
|
|
93
|
+
constructor(manager, _agentActivity,
|
|
94
|
+
/**
|
|
95
|
+
* Read live at render time. Whether each row shows an estimated cost after
|
|
96
|
+
* its token count. Defaults to off — the extension supplies the user's
|
|
97
|
+
* `showCost` setting.
|
|
98
|
+
*/
|
|
99
|
+
showCost = () => false) {
|
|
100
|
+
this.manager = manager;
|
|
101
|
+
this.showCost = showCost;
|
|
102
|
+
}
|
|
103
|
+
/** One extension-owned opener for fleet, menu, and workflow entry points. */
|
|
104
|
+
setAgentOpener(open) {
|
|
105
|
+
this.openAgent = open;
|
|
106
|
+
}
|
|
107
|
+
/** Wire the two-pane overlay as what ← opens (see the field's note). */
|
|
108
|
+
setOverlayOpener(open) {
|
|
109
|
+
this.overlayOpener = open;
|
|
110
|
+
}
|
|
111
|
+
// ---- Lifecycle ----
|
|
112
|
+
setEnabled(enabled) {
|
|
113
|
+
if (enabled === this.enabled)
|
|
114
|
+
return;
|
|
115
|
+
this.enabled = enabled;
|
|
116
|
+
if (!enabled)
|
|
117
|
+
this.active = false;
|
|
118
|
+
this.update();
|
|
119
|
+
}
|
|
120
|
+
/** Capture the UI context and (re)register the global input handler. */
|
|
121
|
+
setUICtx(ui) {
|
|
122
|
+
if (ui === this.ui)
|
|
123
|
+
return;
|
|
124
|
+
this.inputUnsub?.();
|
|
125
|
+
this.ui = ui;
|
|
126
|
+
this.widgetRegistered = false;
|
|
127
|
+
this.tui = undefined;
|
|
128
|
+
this.inputUnsub = ui.onTerminalInput(data => this.handleKey(data));
|
|
129
|
+
}
|
|
130
|
+
/** Ensure the re-render timer is running (called when an agent spawns). */
|
|
131
|
+
ensureTimer() {
|
|
132
|
+
if (!this.timer)
|
|
133
|
+
this.timer = setInterval(() => this.update(), TICK_MS);
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Called when an agent finishes. The viewer (if open on it) stays open so the
|
|
137
|
+
* final output remains readable, and the row lingers in the list — just refresh.
|
|
138
|
+
*/
|
|
139
|
+
onAgentFinished(_id) {
|
|
140
|
+
this.update();
|
|
141
|
+
}
|
|
142
|
+
dispose() {
|
|
143
|
+
if (this.timer) {
|
|
144
|
+
clearInterval(this.timer);
|
|
145
|
+
this.timer = undefined;
|
|
146
|
+
}
|
|
147
|
+
this.inputUnsub?.();
|
|
148
|
+
this.inputUnsub = undefined;
|
|
149
|
+
if (this.viewerClose) {
|
|
150
|
+
this.viewerClose();
|
|
151
|
+
this.viewerClose = undefined;
|
|
152
|
+
}
|
|
153
|
+
this.viewingAgentId = undefined;
|
|
154
|
+
// No handle to close the workflow inspector with, but the list is going
|
|
155
|
+
// away — leaving the id set would keep it swallowing input forever.
|
|
156
|
+
this.viewingWorkflowId = undefined;
|
|
157
|
+
if (this.ui && this.widgetRegistered)
|
|
158
|
+
this.ui.setWidget(FLEET_KEY, undefined);
|
|
159
|
+
this.widgetRegistered = false;
|
|
160
|
+
this.tui = undefined;
|
|
161
|
+
this.active = false;
|
|
162
|
+
// Null last so a `viewerClose()` microtask above can't re-register the widget.
|
|
163
|
+
this.ui = undefined;
|
|
164
|
+
}
|
|
165
|
+
/** Re-register/refresh the below-editor widget; clears it when nothing remains. */
|
|
166
|
+
update() {
|
|
167
|
+
if (!this.ui)
|
|
168
|
+
return;
|
|
169
|
+
// A run with no agents of its own left in the list is still worth a row —
|
|
170
|
+
// it is the thing the user opens to see what its children did. Read off the
|
|
171
|
+
// roster for the same reason activation does: two counts of "is there
|
|
172
|
+
// anything here" drifted apart once before.
|
|
173
|
+
const roster = this.enabled ? this.roster() : [{ kind: "main" }];
|
|
174
|
+
const hasRows = roster.length > 1;
|
|
175
|
+
if (!hasRows) {
|
|
176
|
+
if (this.widgetRegistered) {
|
|
177
|
+
this.ui.setWidget(FLEET_KEY, undefined);
|
|
178
|
+
this.widgetRegistered = false;
|
|
179
|
+
this.tui = undefined;
|
|
180
|
+
}
|
|
181
|
+
if (this.timer) {
|
|
182
|
+
clearInterval(this.timer);
|
|
183
|
+
this.timer = undefined;
|
|
184
|
+
}
|
|
185
|
+
this.active = false;
|
|
186
|
+
this.select(0, roster);
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
this.clampSelection(roster);
|
|
190
|
+
this.ensureTimer(); // keep stats ticking whenever the list is shown (e.g. after a re-enable)
|
|
191
|
+
if (!this.widgetRegistered) {
|
|
192
|
+
this.ui.setWidget(FLEET_KEY, (tui, theme) => {
|
|
193
|
+
this.tui = tui;
|
|
194
|
+
return {
|
|
195
|
+
render: (w) => this.renderBar(w, theme),
|
|
196
|
+
invalidate: () => { this.widgetRegistered = false; this.tui = undefined; },
|
|
197
|
+
};
|
|
198
|
+
}, { placement: "belowEditor" });
|
|
199
|
+
this.widgetRegistered = true;
|
|
200
|
+
}
|
|
201
|
+
else {
|
|
202
|
+
this.tui?.requestRender();
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
// ---- Roster ----
|
|
206
|
+
/**
|
|
207
|
+
* Agents shown in the list, ordered earliest-launched first so the ones you
|
|
208
|
+
* started sooner sit at the top. Every row is openable (has a session), so Enter
|
|
209
|
+
* never dead-ends. Included: running/queued, plus the agent currently being
|
|
210
|
+
* viewed, plus recently-finished ones (they linger briefly before dropping out).
|
|
211
|
+
* Pending agents with no session yet are hidden until they start.
|
|
212
|
+
* (`listAgents()` is newest-first, so we re-sort.)
|
|
213
|
+
*/
|
|
214
|
+
agentRecords() {
|
|
215
|
+
const now = Date.now();
|
|
216
|
+
return this.manager.listAgents()
|
|
217
|
+
.filter(a => isTopLevelAgent(a) && a.session && (a.status === "running" || a.status === "queued"
|
|
218
|
+
|| a.id === this.viewingAgentId
|
|
219
|
+
|| (a.completedAt != null && now - a.completedAt < FINISHED_LINGER_MS)))
|
|
220
|
+
.sort((a, b) => a.startedAt - b.startedAt);
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Wire workflow runs into the list.
|
|
224
|
+
*
|
|
225
|
+
* Injected rather than constructed here because the fleet list predates
|
|
226
|
+
* workflows and must keep working without them — a session with the feature
|
|
227
|
+
* switched off never calls this, and the roster is agents-only exactly as
|
|
228
|
+
* before.
|
|
229
|
+
*/
|
|
230
|
+
setWorkflowSource(source, open) {
|
|
231
|
+
this.workflowSource = source;
|
|
232
|
+
this.openWorkflow = open;
|
|
233
|
+
}
|
|
234
|
+
/** Live runs, plus recently settled ones — the same linger the agents get. */
|
|
235
|
+
workflows() {
|
|
236
|
+
if (!this.workflowSource)
|
|
237
|
+
return [];
|
|
238
|
+
const now = Date.now();
|
|
239
|
+
return [...this.workflowSource()]
|
|
240
|
+
.filter(run => run.status === "running"
|
|
241
|
+
|| run.status === "paused"
|
|
242
|
+
|| (run.completedAt != null && now - run.completedAt < FINISHED_LINGER_MS))
|
|
243
|
+
.sort((a, b) => a.startedAt - b.startedAt);
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Runs sit above the agents rather than interleaved by start time: a run owns
|
|
247
|
+
* most of the agents under it, so listing the container first is what makes
|
|
248
|
+
* the list read as a hierarchy rather than a shuffle.
|
|
249
|
+
*/
|
|
250
|
+
roster() {
|
|
251
|
+
return [
|
|
252
|
+
{ kind: "main" },
|
|
253
|
+
...this.workflows().map(workflow => ({ kind: "workflow", workflow })),
|
|
254
|
+
...this.agentRecords().map(record => ({ kind: "agent", record })),
|
|
255
|
+
];
|
|
256
|
+
}
|
|
257
|
+
select(index, roster = this.roster()) {
|
|
258
|
+
this.selectedIndex = Math.max(0, Math.min(index, roster.length - 1));
|
|
259
|
+
this.selectedKey = entryKey(roster[this.selectedIndex]);
|
|
260
|
+
}
|
|
261
|
+
clampSelection(roster) {
|
|
262
|
+
const index = roster.findIndex(entry => entryKey(entry) === this.selectedKey);
|
|
263
|
+
// Keep identity across inserts/reorders; a removed row falls to the same
|
|
264
|
+
// position (its successor), or the preceding row when it was last.
|
|
265
|
+
this.select(index >= 0 ? index : this.selectedIndex, roster);
|
|
266
|
+
}
|
|
267
|
+
// ---- Key handling ----
|
|
268
|
+
/** Returns `{consume:true}` to swallow a key, or undefined to let it through. */
|
|
269
|
+
handleKey(data) {
|
|
270
|
+
if (!this.enabled || !this.ui)
|
|
271
|
+
return undefined;
|
|
272
|
+
// Input listeners receive BOTH key-press and key-release (the kitty protocol
|
|
273
|
+
// emits both, and matchesKey matches either) — act on press only, or every
|
|
274
|
+
// tap would move/fire twice. Repeats still pass through for held-key nav.
|
|
275
|
+
if (isKeyRelease(data))
|
|
276
|
+
return undefined;
|
|
277
|
+
// While an overlay is open, let it own all input. Checked before the focus
|
|
278
|
+
// test below, which would otherwise read the dialog holding the keyboard as
|
|
279
|
+
// "the user left the list" and reset the selection out from under it.
|
|
280
|
+
if (this.viewingAgentId || this.viewingWorkflowId)
|
|
281
|
+
return undefined;
|
|
282
|
+
// Input listeners fire BEFORE the focused component, and dialogs
|
|
283
|
+
// (ctx.ui.select/confirm/input, pi's own menus) swap the prompt editor out
|
|
284
|
+
// while getEditorText() still reads the detached — empty — editor. So when
|
|
285
|
+
// anything but the editor owns the keyboard, stay out of its keys (#123).
|
|
286
|
+
if (!this.editorHasFocus()) {
|
|
287
|
+
if (this.active)
|
|
288
|
+
this.deactivate();
|
|
289
|
+
return undefined;
|
|
290
|
+
}
|
|
291
|
+
if (!this.active) {
|
|
292
|
+
// ← opens the two-pane overlay when the host wired it; the overlay is the
|
|
293
|
+
// fuller surface (detail card, settled history), so inline activation
|
|
294
|
+
// falls to ↓ alone. Without an opener ← stays an activator, exactly as ↓.
|
|
295
|
+
if (matchesKey(data, "left") && this.overlayOpener) {
|
|
296
|
+
if (this.roster().length > 1 && this.ui.getEditorText() === "") {
|
|
297
|
+
this.overlayOpener();
|
|
298
|
+
return { consume: true };
|
|
299
|
+
}
|
|
300
|
+
return undefined;
|
|
301
|
+
}
|
|
302
|
+
// Activate: ↓ at an empty prompt moves focus into the list.
|
|
303
|
+
const isActivator = matchesKey(data, "down") || (matchesKey(data, "left") && !this.overlayOpener);
|
|
304
|
+
// Gated on the roster, not the agents: a session whose only row is a
|
|
305
|
+
// workflow run still has somewhere to go, and requiring an agent would
|
|
306
|
+
// render the row but refuse to move into it.
|
|
307
|
+
if (isActivator && this.roster().length > 1 && this.ui.getEditorText() === "") {
|
|
308
|
+
this.active = true;
|
|
309
|
+
this.select(0);
|
|
310
|
+
this.update();
|
|
311
|
+
return { consume: true };
|
|
312
|
+
}
|
|
313
|
+
return undefined;
|
|
314
|
+
}
|
|
315
|
+
// Reconcile even before the next timer tick/render, including on Enter.
|
|
316
|
+
const roster = this.roster();
|
|
317
|
+
this.clampSelection(roster);
|
|
318
|
+
// Active — arrows navigate, Enter opens, Esc / Up-past-top exits.
|
|
319
|
+
if (matchesKey(data, "down")) {
|
|
320
|
+
this.select(this.selectedIndex + 1, roster);
|
|
321
|
+
this.update();
|
|
322
|
+
return { consume: true };
|
|
323
|
+
}
|
|
324
|
+
if (matchesKey(data, "up")) {
|
|
325
|
+
if (this.selectedIndex === 0) {
|
|
326
|
+
this.deactivate();
|
|
327
|
+
return { consume: true };
|
|
328
|
+
}
|
|
329
|
+
this.select(this.selectedIndex - 1, roster);
|
|
330
|
+
this.update();
|
|
331
|
+
return { consume: true };
|
|
332
|
+
}
|
|
333
|
+
if (matchesKey(data, "escape")) {
|
|
334
|
+
this.deactivate();
|
|
335
|
+
return { consume: true };
|
|
336
|
+
}
|
|
337
|
+
if (matchesKey(data, Key.enter)) {
|
|
338
|
+
this.openSelected();
|
|
339
|
+
return { consume: true };
|
|
340
|
+
}
|
|
341
|
+
// While navigating, ← reaches for the fuller surface too: leave the inline
|
|
342
|
+
// list and open the overlay. The editor holds no text here (activation
|
|
343
|
+
// requires an empty prompt), so nothing typed is disturbed either way.
|
|
344
|
+
if (matchesKey(data, "left") && this.overlayOpener) {
|
|
345
|
+
this.deactivate();
|
|
346
|
+
this.overlayOpener();
|
|
347
|
+
return { consume: true };
|
|
348
|
+
}
|
|
349
|
+
// Any other key cancels navigation and flows to the editor.
|
|
350
|
+
this.deactivate();
|
|
351
|
+
return undefined;
|
|
352
|
+
}
|
|
353
|
+
/**
|
|
354
|
+
* True when pi's prompt editor owns the keyboard. pi's editor is an `Editor`
|
|
355
|
+
* subclass (CustomEditor) while every dialog/selector is not, and the loader
|
|
356
|
+
* aliases pi-tui to pi's own copy, so `instanceof` is a reliable identity
|
|
357
|
+
* check. Prefer Pi's public accessor; the fallback supports older UI test
|
|
358
|
+
* hosts. Unknowable focus counts as the editor so activation keeps working.
|
|
359
|
+
*/
|
|
360
|
+
editorHasFocus() {
|
|
361
|
+
const focused = this.tui?.getFocusedComponent?.() ?? this.tui?.focusedComponent;
|
|
362
|
+
return focused == null || focused instanceof Editor;
|
|
363
|
+
}
|
|
364
|
+
deactivate() {
|
|
365
|
+
this.active = false;
|
|
366
|
+
this.select(0);
|
|
367
|
+
this.update();
|
|
368
|
+
}
|
|
369
|
+
openSelected() {
|
|
370
|
+
const roster = this.roster();
|
|
371
|
+
this.clampSelection(roster);
|
|
372
|
+
const entry = roster[this.selectedIndex];
|
|
373
|
+
if (!entry || entry.kind === "main") {
|
|
374
|
+
// `main` = return to the prompt; the native transcript is already shown.
|
|
375
|
+
this.deactivate();
|
|
376
|
+
return;
|
|
377
|
+
}
|
|
378
|
+
if (entry.kind === "workflow") {
|
|
379
|
+
// The extension owns this overlay and closes it, so there is no
|
|
380
|
+
// `viewerClose` to hold — but the list still has to know one is up, and
|
|
381
|
+
// still has to put the cursor back on the run when it comes down.
|
|
382
|
+
this.viewingWorkflowId = entry.workflow.id;
|
|
383
|
+
void Promise.resolve(this.openWorkflow?.(entry.workflow.id)).then(() => this.clearViewer(), () => this.clearViewer());
|
|
384
|
+
return;
|
|
385
|
+
}
|
|
386
|
+
const record = entry.record;
|
|
387
|
+
if (!this.ui)
|
|
388
|
+
return;
|
|
389
|
+
if (!record.session) {
|
|
390
|
+
this.ui.notify(`Agent is ${record.status} — no session available.`, "info");
|
|
391
|
+
return;
|
|
392
|
+
}
|
|
393
|
+
if (!this.openAgent) {
|
|
394
|
+
this.ui.notify("Child conversation opener is unavailable.", "warning");
|
|
395
|
+
return;
|
|
396
|
+
}
|
|
397
|
+
this.viewingAgentId = record.id;
|
|
398
|
+
void this.openAgent(record, close => { this.viewerClose = close; }).then(() => this.clearViewer(), error => {
|
|
399
|
+
this.ui?.notify(`Could not open child: ${error instanceof Error ? error.message : String(error)}`, "error");
|
|
400
|
+
this.clearViewer();
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
/** Reset overlay state and return to the list (on close, auto-close, or error). */
|
|
404
|
+
clearViewer() {
|
|
405
|
+
// Keep the cursor on the agent we were viewing — re-resolve by id so it
|
|
406
|
+
// still feels natural if the list reordered (an earlier agent finished)
|
|
407
|
+
// while the overlay was open. If that agent is gone, leave the index for
|
|
408
|
+
// update()'s clamp to settle.
|
|
409
|
+
const viewed = this.viewingAgentId !== undefined ? `agent:${this.viewingAgentId}`
|
|
410
|
+
: this.viewingWorkflowId !== undefined ? `workflow:${this.viewingWorkflowId}` : undefined;
|
|
411
|
+
if (viewed !== undefined) {
|
|
412
|
+
const roster = this.roster();
|
|
413
|
+
const idx = roster.findIndex(entry => entryKey(entry) === viewed);
|
|
414
|
+
if (idx >= 0)
|
|
415
|
+
this.select(idx, roster);
|
|
416
|
+
}
|
|
417
|
+
this.viewerClose = undefined;
|
|
418
|
+
this.viewingAgentId = undefined;
|
|
419
|
+
this.viewingWorkflowId = undefined;
|
|
420
|
+
this.update();
|
|
421
|
+
}
|
|
422
|
+
// ---- Rendering ----
|
|
423
|
+
renderBar(width, theme) {
|
|
424
|
+
const roster = this.roster();
|
|
425
|
+
this.clampSelection(roster);
|
|
426
|
+
const rows = roster.slice(1);
|
|
427
|
+
if (rows.length === 0)
|
|
428
|
+
return [];
|
|
429
|
+
const sel = this.selectedIndex;
|
|
430
|
+
const hint = this.active
|
|
431
|
+
? "↑↓ select · enter view · esc back"
|
|
432
|
+
: "esc to interrupt · ← for agents · ↓ to manage";
|
|
433
|
+
const lines = [];
|
|
434
|
+
lines.push(truncateToWidth(" " + theme.fg("dim", hint), width));
|
|
435
|
+
lines.push("");
|
|
436
|
+
lines.push(truncateToWidth(` ${this.bullet(0, sel, theme)} main`, width));
|
|
437
|
+
// Window the rows so the selected one stays visible.
|
|
438
|
+
const visible = Math.min(MAX_AGENT_ROWS, rows.length);
|
|
439
|
+
const selRow = Math.max(0, sel - 1);
|
|
440
|
+
const start = selRow < visible ? 0 : selRow - visible + 1;
|
|
441
|
+
const hiddenBelow = rows.length - (start + visible);
|
|
442
|
+
if (start > 0)
|
|
443
|
+
lines.push(rightAlign("", theme.fg("dim", `↑ ${start} more`), width));
|
|
444
|
+
for (let a = start; a < start + visible; a++) {
|
|
445
|
+
const row = rows[a];
|
|
446
|
+
lines.push(row.kind === "workflow" ?
|
|
447
|
+
this.renderWorkflowRow(a + 1, sel, row.workflow, width, theme)
|
|
448
|
+
: this.renderAgentRow(a + 1, sel, row.record, width, theme));
|
|
449
|
+
}
|
|
450
|
+
if (hiddenBelow > 0)
|
|
451
|
+
lines.push(rightAlign("", theme.fg("dim", `↓ ${hiddenBelow} more`), width));
|
|
452
|
+
return lines;
|
|
453
|
+
}
|
|
454
|
+
bullet(rosterIndex, sel, theme) {
|
|
455
|
+
return rosterIndex === sel ? theme.fg("accent", "●") : theme.fg("dim", "○");
|
|
456
|
+
}
|
|
457
|
+
/**
|
|
458
|
+
* A run's row. Shaped like an agent's — bullet, kind, name, stats flush right
|
|
459
|
+
* — so the two read as one list, with the agent count where an agent has its
|
|
460
|
+
* description and the same elapsed/token tail.
|
|
461
|
+
*/
|
|
462
|
+
renderWorkflowRow(rosterIndex, sel, workflow, width, theme) {
|
|
463
|
+
const selected = rosterIndex === sel;
|
|
464
|
+
const kind = theme.fg(selected ? "text" : "muted", "workflow");
|
|
465
|
+
const name = selected ? theme.fg("text", workflow.name) : workflow.name;
|
|
466
|
+
const left = ` ${this.bullet(rosterIndex, sel, theme)} ${kind} ${name}`;
|
|
467
|
+
// Frozen once the run settles, exactly as an agent's clock is.
|
|
468
|
+
const elapsed = (workflow.completedAt ?? Date.now()) - workflow.startedAt;
|
|
469
|
+
const agents = `${workflow.doneCount}/${workflow.totalCount} agent${workflow.totalCount === 1 ? "" : "s"}`;
|
|
470
|
+
const stats = `${agents} · ${formatFleetElapsed(elapsed)} · ${formatFleetTokens(workflow.tokens)}`;
|
|
471
|
+
return rightAlign(left, selected ? theme.fg("text", stats) : theme.fg("dim", stats), width);
|
|
472
|
+
}
|
|
473
|
+
renderAgentRow(rosterIndex, sel, record, width, theme) {
|
|
474
|
+
// The selected row renders in the theme's primary text color so it reads as
|
|
475
|
+
// one selection (#230). A configured badge survives — Claude Code's FleetView
|
|
476
|
+
// keeps the agent color on the selected row too and only bolds it — which also
|
|
477
|
+
// keeps the row's width fixed as the selection moves.
|
|
478
|
+
const selected = rosterIndex === sel;
|
|
479
|
+
const name = renderAgentName(record.type, theme, selected
|
|
480
|
+
? { fallbackColor: "text", bold: hasAgentBadge(record.type) }
|
|
481
|
+
: { fallbackColor: "muted" });
|
|
482
|
+
const description = selected ? theme.fg("text", record.description) : record.description;
|
|
483
|
+
const left = ` ${this.bullet(rosterIndex, sel, theme)} ${name} ${description}`;
|
|
484
|
+
// The record, not the activity tracker — see the note in AgentWidget's
|
|
485
|
+
// running line: only the record carries a nested child's spend, and only it
|
|
486
|
+
// outlives the agent.
|
|
487
|
+
const tokens = getLifetimeTotal(record.lifetimeUsage);
|
|
488
|
+
const elapsedMs = (record.completedAt ?? Date.now()) - record.startedAt; // freezes once finished
|
|
489
|
+
const cost = this.showCost() ? formatCost(getLifetimeCost(record.lifetimeUsage)) : "";
|
|
490
|
+
const stats = `${formatFleetElapsed(elapsedMs)} · ${formatFleetTokens(tokens)}${cost ? ` · ${cost}` : ""}`;
|
|
491
|
+
const right = selected ? theme.fg("text", stats) : theme.fg("dim", stats);
|
|
492
|
+
return rightAlign(left, right, width);
|
|
493
|
+
}
|
|
494
|
+
}
|