@diousk/pi-subagents-fast 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 +808 -0
- package/CONTRIBUTING.md +72 -0
- package/LICENSE +21 -0
- package/README.md +1034 -0
- package/SECURITY.md +95 -0
- package/dist/abortable.d.ts +12 -0
- package/dist/abortable.js +42 -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 +260 -0
- package/dist/agent-manager.d.ts +472 -0
- package/dist/agent-manager.js +1338 -0
- package/dist/agent-runner.d.ts +312 -0
- package/dist/agent-runner.js +1034 -0
- package/dist/agent-types.d.ts +119 -0
- package/dist/agent-types.js +286 -0
- package/dist/child-context.d.ts +2 -0
- package/dist/child-context.js +12 -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 +316 -0
- package/dist/default-agents.d.ts +7 -0
- package/dist/default-agents.js +122 -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/group-join.d.ts +32 -0
- package/dist/group-join.js +116 -0
- package/dist/index.d.ts +50 -0
- package/dist/index.js +3682 -0
- package/dist/invocation-config.d.ts +107 -0
- package/dist/invocation-config.js +83 -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 +153 -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-file.d.ts +43 -0
- package/dist/output-file.js +142 -0
- package/dist/prompts.d.ts +55 -0
- package/dist/prompts.js +91 -0
- package/dist/schedule-store.d.ts +38 -0
- package/dist/schedule-store.js +155 -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/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/types.d.ts +371 -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 +219 -0
- package/dist/ui/agent-widget.js +592 -0
- package/dist/ui/conversation-viewer.d.ts +120 -0
- package/dist/ui/conversation-viewer.js +578 -0
- package/dist/ui/fleet-list.d.ts +195 -0
- package/dist/ui/fleet-list.js +471 -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/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 +362 -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/rpc.md +183 -0
- package/docs/workflows.md +437 -0
- package/examples/agent-tool-description.md +42 -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 +68 -0
- package/src/abortable.ts +43 -0
- package/src/agent-color.ts +161 -0
- package/src/agent-file-toggle.ts +270 -0
- package/src/agent-manager.ts +1581 -0
- package/src/agent-runner.ts +1286 -0
- package/src/agent-types.ts +346 -0
- package/src/child-context.ts +15 -0
- package/src/context.ts +58 -0
- package/src/cross-extension-rpc.ts +198 -0
- package/src/custom-agents.ts +333 -0
- package/src/default-agents.ts +126 -0
- package/src/enabled-models.ts +180 -0
- package/src/env.ts +33 -0
- package/src/group-join.ts +141 -0
- package/src/index.ts +3991 -0
- package/src/invocation-config.ts +155 -0
- package/src/memory.ts +179 -0
- package/src/mention-clone.ts +196 -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-file.ts +155 -0
- package/src/prompts.ts +142 -0
- package/src/schedule-store.ts +153 -0
- package/src/schedule.ts +386 -0
- package/src/settings.ts +587 -0
- package/src/skill-loader.ts +102 -0
- package/src/status-note.ts +90 -0
- package/src/structured-output.ts +130 -0
- package/src/types.ts +384 -0
- package/src/ui/agent-mention.ts +216 -0
- package/src/ui/agent-widget.ts +664 -0
- package/src/ui/conversation-viewer.ts +589 -0
- package/src/ui/fleet-list.ts +543 -0
- package/src/ui/schedule-menu.ts +105 -0
- package/src/ui/select-item.ts +45 -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 +403 -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,219 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* agent-widget.ts — Persistent widget showing running/completed agents above the editor.
|
|
3
|
+
*
|
|
4
|
+
* Displays a tree of agents with animated spinners, live stats, and activity descriptions.
|
|
5
|
+
* Uses the callback form of setWidget for themed rendering.
|
|
6
|
+
*/
|
|
7
|
+
import { type AgentManager } from "../agent-manager.js";
|
|
8
|
+
import type { AgentInvocation, SubagentType, WidgetMode } from "../types.js";
|
|
9
|
+
import { type SessionLike } from "../usage.js";
|
|
10
|
+
/** Braille spinner frames for animated running indicator. */
|
|
11
|
+
export declare const SPINNER: string[];
|
|
12
|
+
/** Statuses that indicate an error/non-success outcome (used for linger behavior and icon rendering). */
|
|
13
|
+
export declare const ERROR_STATUSES: Set<string>;
|
|
14
|
+
export type Theme = {
|
|
15
|
+
fg(color: string, text: string): string;
|
|
16
|
+
bold(text: string): string;
|
|
17
|
+
};
|
|
18
|
+
export type UICtx = {
|
|
19
|
+
setStatus(key: string, text: string | undefined): void;
|
|
20
|
+
setWidget(key: string, content: undefined | ((tui: any, theme: Theme) => {
|
|
21
|
+
render(): string[];
|
|
22
|
+
invalidate(): void;
|
|
23
|
+
}), options?: {
|
|
24
|
+
placement?: "aboveEditor" | "belowEditor";
|
|
25
|
+
}): void;
|
|
26
|
+
};
|
|
27
|
+
/** Per-agent live activity state. */
|
|
28
|
+
export interface AgentActivity {
|
|
29
|
+
activeTools: Map<string, string>;
|
|
30
|
+
toolUses: number;
|
|
31
|
+
responseText: string;
|
|
32
|
+
session?: SessionLike;
|
|
33
|
+
/** Current turn count. */
|
|
34
|
+
turnCount: number;
|
|
35
|
+
/** Effective max turns for this agent (undefined = unlimited). */
|
|
36
|
+
maxTurns?: number;
|
|
37
|
+
}
|
|
38
|
+
/** Metadata attached to Agent tool results for custom rendering. */
|
|
39
|
+
export interface AgentDetails {
|
|
40
|
+
displayName: string;
|
|
41
|
+
description: string;
|
|
42
|
+
subagentType: string;
|
|
43
|
+
toolUses: number;
|
|
44
|
+
tokens: string;
|
|
45
|
+
durationMs: number;
|
|
46
|
+
status: "queued" | "running" | "completed" | "steered" | "aborted" | "stopped" | "error" | "background";
|
|
47
|
+
/** Human-readable description of what the agent is currently doing. */
|
|
48
|
+
activity?: string;
|
|
49
|
+
/** Current spinner frame index (for animated running indicator). */
|
|
50
|
+
spinnerFrame?: number;
|
|
51
|
+
/** Short label for the model the run used, e.g. "haiku 4.5". */
|
|
52
|
+
modelName?: string;
|
|
53
|
+
/** Notable config tags (e.g. ["thinking: high", "isolated"]). */
|
|
54
|
+
tags?: string[];
|
|
55
|
+
/** Current turn count. */
|
|
56
|
+
turnCount?: number;
|
|
57
|
+
/** Effective max turns (undefined = unlimited). */
|
|
58
|
+
maxTurns?: number;
|
|
59
|
+
/** Estimated cost in USD; 0 when the model has no pricing data. */
|
|
60
|
+
cost?: number;
|
|
61
|
+
agentId?: string;
|
|
62
|
+
error?: string;
|
|
63
|
+
}
|
|
64
|
+
/** Apply foreground styling while restoring it after nested foreground/full ANSI resets. */
|
|
65
|
+
export declare function fgPreservingNestedStyles(theme: Theme, color: string, text: string): string;
|
|
66
|
+
/** Format a token count compactly: "33.8k token", "1.2M token". */
|
|
67
|
+
export declare function formatTokens(count: number): string;
|
|
68
|
+
/**
|
|
69
|
+
* Format a cost as `~$0.0042`, or "" when there is nothing to show.
|
|
70
|
+
*
|
|
71
|
+
* The tilde is load-bearing: this is pi's own estimate from the model's listed
|
|
72
|
+
* rates, not a billed figure, and the surfaces that print it sit next to token
|
|
73
|
+
* counts that ARE exact.
|
|
74
|
+
*
|
|
75
|
+
* Nothing is printed for zero, which is also what a model with no pricing data
|
|
76
|
+
* reports: `$0.00` beside a local model's tokens would claim its cost was
|
|
77
|
+
* measured and found to be nothing, rather than never measured at all. For the
|
|
78
|
+
* same reason a real cost too small for four decimals reads `<$0.0001` — it was
|
|
79
|
+
* measured, and rounding it to `~$0.0000` would say the opposite.
|
|
80
|
+
*/
|
|
81
|
+
export declare function formatCost(cost: number): string;
|
|
82
|
+
/**
|
|
83
|
+
* Token count with optional context-fill % and compaction-count annotations.
|
|
84
|
+
* Thresholds for percent: <70% dim, 70–85% warning, ≥85% error.
|
|
85
|
+
* Compaction count rendered as `⇊N` in dim.
|
|
86
|
+
*
|
|
87
|
+
* "12.3k token" — no annotations
|
|
88
|
+
* "12.3k token (45%)" — percent only
|
|
89
|
+
* "12.3k token (⇊2)" — compactions only (e.g. right after compact)
|
|
90
|
+
* "12.3k token (45% · ⇊2)" — both
|
|
91
|
+
*/
|
|
92
|
+
export declare function formatSessionTokens(tokens: number, percent: number | null, theme: Theme, compactions?: number): string;
|
|
93
|
+
/** Format turn count with optional max limit: "↻5≤30" or "↻5". */
|
|
94
|
+
export declare function formatTurns(turnCount: number, maxTurns?: number | null): string;
|
|
95
|
+
/** Format milliseconds as human-readable duration. */
|
|
96
|
+
export declare function formatMs(ms: number): string;
|
|
97
|
+
/** Format duration from start/completed timestamps. */
|
|
98
|
+
export declare function formatDuration(startedAt: number, completedAt?: number): string;
|
|
99
|
+
/** Get display name for any agent type (built-in or custom). */
|
|
100
|
+
export declare function getDisplayName(type: SubagentType): string;
|
|
101
|
+
/** Short label for prompt mode: "twin" for append, nothing for replace (the default). */
|
|
102
|
+
export declare function getPromptModeLabel(type: SubagentType): string | undefined;
|
|
103
|
+
/**
|
|
104
|
+
* Mode label is not included — callers add it where they want it.
|
|
105
|
+
*
|
|
106
|
+
* Both model forms come back so each surface can pick by width; the
|
|
107
|
+
* "(asked X)" annotation is applied here rather than by callers, so a value the
|
|
108
|
+
* spawn did not honor cannot be rendered as though it had been (#182). A service
|
|
109
|
+
* tier is emitted only when the effective API supports it; callers leave it unset
|
|
110
|
+
* for unsupported providers so an ignored request is not shown as active.
|
|
111
|
+
*/
|
|
112
|
+
export declare function buildInvocationTags(invocation: AgentInvocation | undefined): {
|
|
113
|
+
modelName?: string;
|
|
114
|
+
modelId?: string;
|
|
115
|
+
tags: string[];
|
|
116
|
+
};
|
|
117
|
+
/** Build a human-readable activity string from currently-running tools or response text. */
|
|
118
|
+
export declare function describeActivity(activeTools: Map<string, string>, responseText?: string): string;
|
|
119
|
+
export declare class AgentWidget {
|
|
120
|
+
private manager;
|
|
121
|
+
private agentActivity;
|
|
122
|
+
/**
|
|
123
|
+
* Read live at render time. Selects which agents the widget shows — see
|
|
124
|
+
* `WidgetMode`. Defaults to `"all"` when a caller supplies no policy; the
|
|
125
|
+
* extension supplies one defaulting to `"background"`.
|
|
126
|
+
*/
|
|
127
|
+
private mode;
|
|
128
|
+
/**
|
|
129
|
+
* Read live at render time, like `mode`. Whether running agents show an
|
|
130
|
+
* estimated cost beside their token count. Defaults to off — the extension
|
|
131
|
+
* supplies the user's `showCost` setting.
|
|
132
|
+
*/
|
|
133
|
+
private showCost;
|
|
134
|
+
/**
|
|
135
|
+
* Read live at render time, like `mode`. Whether running agents name the
|
|
136
|
+
* model, thinking level, and configured service tier when the effective API
|
|
137
|
+
* supports it. Defaults to off — the extension supplies the user's `showModel`
|
|
138
|
+
* setting — because the row is already dense and the same details are on the
|
|
139
|
+
* tool result and in the conversation viewer when applicable.
|
|
140
|
+
*/
|
|
141
|
+
private showModel;
|
|
142
|
+
private uiCtx;
|
|
143
|
+
private widgetFrame;
|
|
144
|
+
private widgetInterval;
|
|
145
|
+
/** Tracks how many turns each finished agent has survived. Key: agent ID, Value: turns since finished. */
|
|
146
|
+
private finishedTurnAge;
|
|
147
|
+
/** How many extra turns errors/aborted agents linger (completed agents clear after 1 turn). */
|
|
148
|
+
private static readonly ERROR_LINGER_TURNS;
|
|
149
|
+
/** Whether the widget callback is currently registered with the TUI. */
|
|
150
|
+
private widgetRegistered;
|
|
151
|
+
/** Cached TUI reference from widget factory callback, used for requestRender(). */
|
|
152
|
+
private tui;
|
|
153
|
+
/** Last status bar text, used to avoid redundant setStatus calls. */
|
|
154
|
+
private lastStatusText;
|
|
155
|
+
constructor(manager: AgentManager, agentActivity: Map<string, AgentActivity>,
|
|
156
|
+
/**
|
|
157
|
+
* Read live at render time. Selects which agents the widget shows — see
|
|
158
|
+
* `WidgetMode`. Defaults to `"all"` when a caller supplies no policy; the
|
|
159
|
+
* extension supplies one defaulting to `"background"`.
|
|
160
|
+
*/
|
|
161
|
+
mode?: () => WidgetMode,
|
|
162
|
+
/**
|
|
163
|
+
* Read live at render time, like `mode`. Whether running agents show an
|
|
164
|
+
* estimated cost beside their token count. Defaults to off — the extension
|
|
165
|
+
* supplies the user's `showCost` setting.
|
|
166
|
+
*/
|
|
167
|
+
showCost?: () => boolean,
|
|
168
|
+
/**
|
|
169
|
+
* Read live at render time, like `mode`. Whether running agents name the
|
|
170
|
+
* model, thinking level, and configured service tier when the effective API
|
|
171
|
+
* supports it. Defaults to off — the extension supplies the user's `showModel`
|
|
172
|
+
* setting — because the row is already dense and the same details are on the
|
|
173
|
+
* tool result and in the conversation viewer when applicable.
|
|
174
|
+
*/
|
|
175
|
+
showModel?: () => boolean);
|
|
176
|
+
/**
|
|
177
|
+
* Agents eligible for the widget, per the current `WidgetMode`:
|
|
178
|
+
* - `off`: none (the widget's existing empty-state path hides it entirely).
|
|
179
|
+
* - `background`: drop only agents *known* to be foreground
|
|
180
|
+
* (`isBackground === false`); keep everything else — background, queued,
|
|
181
|
+
* scheduled, or RPC-spawned (`undefined`). Keying off the `isBackground`
|
|
182
|
+
* record flag rather than the UI-only `invocation` snapshot (which only the
|
|
183
|
+
* Agent-tool path sets), and excluding rather than allow-listing, means
|
|
184
|
+
* only proven-foreground runs drop out — nothing else silently vanishes.
|
|
185
|
+
* - `all`: every agent.
|
|
186
|
+
*/
|
|
187
|
+
private widgetAgents;
|
|
188
|
+
/** Set the UI context (grabbed from first tool execution). */
|
|
189
|
+
setUICtx(ctx: UICtx): void;
|
|
190
|
+
/**
|
|
191
|
+
* Called on each new turn (tool_execution_start).
|
|
192
|
+
* Ages finished agents and clears those that have lingered long enough.
|
|
193
|
+
*/
|
|
194
|
+
onTurnStart(): void;
|
|
195
|
+
/** Ensure the widget update timer is running. */
|
|
196
|
+
ensureTimer(): void;
|
|
197
|
+
/** Check if a finished agent should still be shown in the widget. */
|
|
198
|
+
private shouldShowFinished;
|
|
199
|
+
/** Record an agent as finished (call when agent completes). */
|
|
200
|
+
markFinished(agentId: string): void;
|
|
201
|
+
/**
|
|
202
|
+
* Drop an agent's finished-age (call when a settled agent starts running
|
|
203
|
+
* again, i.e. a background resume). markFinished only seeds an age it has not
|
|
204
|
+
* seen before, so a resumed agent would otherwise keep the age from its
|
|
205
|
+
* previous run — already past the linger limit, hiding the new run's
|
|
206
|
+
* completion line entirely.
|
|
207
|
+
*/
|
|
208
|
+
markRunning(agentId: string): void;
|
|
209
|
+
/** Render a finished agent line. */
|
|
210
|
+
private renderFinishedLine;
|
|
211
|
+
/**
|
|
212
|
+
* Render the widget content. Called from the registered widget's render() callback,
|
|
213
|
+
* reading live state each time instead of capturing it in a closure.
|
|
214
|
+
*/
|
|
215
|
+
private renderWidget;
|
|
216
|
+
/** Force an immediate widget update. */
|
|
217
|
+
update(): void;
|
|
218
|
+
dispose(): void;
|
|
219
|
+
}
|