@esso0428/pi-subagents 0.15.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.
Files changed (98) hide show
  1. package/CHANGELOG.md +638 -0
  2. package/CONTRIBUTING.md +68 -0
  3. package/LICENSE +21 -0
  4. package/README.md +745 -0
  5. package/SECURITY.md +95 -0
  6. package/dist/agent-manager.d.ts +144 -0
  7. package/dist/agent-manager.js +542 -0
  8. package/dist/agent-runner.d.ts +212 -0
  9. package/dist/agent-runner.js +850 -0
  10. package/dist/agent-types.d.ts +67 -0
  11. package/dist/agent-types.js +168 -0
  12. package/dist/context.d.ts +12 -0
  13. package/dist/context.js +56 -0
  14. package/dist/cross-extension-rpc.d.ts +46 -0
  15. package/dist/cross-extension-rpc.js +76 -0
  16. package/dist/custom-agents.d.ts +17 -0
  17. package/dist/custom-agents.js +156 -0
  18. package/dist/default-agents.d.ts +7 -0
  19. package/dist/default-agents.js +122 -0
  20. package/dist/enabled-models.d.ts +49 -0
  21. package/dist/enabled-models.js +145 -0
  22. package/dist/env.d.ts +6 -0
  23. package/dist/env.js +28 -0
  24. package/dist/group-join.d.ts +32 -0
  25. package/dist/group-join.js +116 -0
  26. package/dist/index.d.ts +16 -0
  27. package/dist/index.js +2209 -0
  28. package/dist/invocation-config.d.ts +22 -0
  29. package/dist/invocation-config.js +15 -0
  30. package/dist/memory.d.ts +53 -0
  31. package/dist/memory.js +165 -0
  32. package/dist/model-resolver.d.ts +19 -0
  33. package/dist/model-resolver.js +80 -0
  34. package/dist/nico-overrides.d.ts +53 -0
  35. package/dist/nico-overrides.js +169 -0
  36. package/dist/output-file.d.ts +24 -0
  37. package/dist/output-file.js +101 -0
  38. package/dist/prompts.d.ts +32 -0
  39. package/dist/prompts.js +73 -0
  40. package/dist/schedule-store.d.ts +38 -0
  41. package/dist/schedule-store.js +155 -0
  42. package/dist/schedule.d.ts +109 -0
  43. package/dist/schedule.js +338 -0
  44. package/dist/settings.d.ts +141 -0
  45. package/dist/settings.js +162 -0
  46. package/dist/skill-loader.d.ts +24 -0
  47. package/dist/skill-loader.js +93 -0
  48. package/dist/status-note.d.ts +13 -0
  49. package/dist/status-note.js +24 -0
  50. package/dist/types.d.ts +197 -0
  51. package/dist/types.js +5 -0
  52. package/dist/ui/agent-widget.d.ts +160 -0
  53. package/dist/ui/agent-widget.js +484 -0
  54. package/dist/ui/conversation-viewer.d.ts +57 -0
  55. package/dist/ui/conversation-viewer.js +354 -0
  56. package/dist/ui/fleet-list.d.ts +106 -0
  57. package/dist/ui/fleet-list.js +345 -0
  58. package/dist/ui/schedule-menu.d.ts +16 -0
  59. package/dist/ui/schedule-menu.js +95 -0
  60. package/dist/ui/viewer-keys.d.ts +20 -0
  61. package/dist/ui/viewer-keys.js +17 -0
  62. package/dist/usage.d.ts +50 -0
  63. package/dist/usage.js +49 -0
  64. package/dist/worktree.d.ts +45 -0
  65. package/dist/worktree.js +160 -0
  66. package/examples/agent-tool-description.md +42 -0
  67. package/package.json +56 -0
  68. package/src/agent-manager.ts +631 -0
  69. package/src/agent-runner.ts +1014 -0
  70. package/src/agent-types.ts +202 -0
  71. package/src/context.ts +58 -0
  72. package/src/cross-extension-rpc.ts +122 -0
  73. package/src/custom-agents.ts +167 -0
  74. package/src/default-agents.ts +126 -0
  75. package/src/enabled-models.ts +180 -0
  76. package/src/env.ts +33 -0
  77. package/src/group-join.ts +141 -0
  78. package/src/index.ts +2400 -0
  79. package/src/invocation-config.ts +40 -0
  80. package/src/memory.ts +179 -0
  81. package/src/model-resolver.ts +100 -0
  82. package/src/nico-overrides.ts +235 -0
  83. package/src/output-file.ts +110 -0
  84. package/src/prompts.ts +99 -0
  85. package/src/schedule-store.ts +153 -0
  86. package/src/schedule.ts +365 -0
  87. package/src/settings.ts +288 -0
  88. package/src/skill-loader.ts +102 -0
  89. package/src/status-note.ts +25 -0
  90. package/src/types.ts +208 -0
  91. package/src/ui/agent-widget.ts +566 -0
  92. package/src/ui/conversation-viewer.ts +362 -0
  93. package/src/ui/fleet-list.ts +380 -0
  94. package/src/ui/schedule-menu.ts +104 -0
  95. package/src/ui/viewer-keys.ts +39 -0
  96. package/src/usage.ts +60 -0
  97. package/src/worktree.ts +191 -0
  98. package/vitest.config.ts +18 -0
@@ -0,0 +1,93 @@
1
+ /**
2
+ * skill-loader.ts — Preload named skills.
3
+ *
4
+ * Roots, in precedence order:
5
+ * - <cwd>/.pi/skills (project, Pi's standard)
6
+ * - <cwd>/.agents/skills (project, cross-tool Agent Skills spec — https://agentskills.io)
7
+ * - getAgentDir()/skills (user, default ~/.pi/agent/skills — Pi's standard)
8
+ * - ~/.agents/skills (user, cross-tool Agent Skills spec)
9
+ * - ~/.pi/skills (legacy global, pre-Pi)
10
+ *
11
+ * Layout per root:
12
+ * - <root>/<name>.md (flat file at the top level)
13
+ * - <root>/.../<name>/SKILL.md (directory skill, may be nested — Pi's standard)
14
+ *
15
+ * Recursion skips dotfile entries and node_modules. A directory that itself contains
16
+ * SKILL.md is a skill — we don't descend into it (Pi: skills don't nest).
17
+ *
18
+ * Symlinks are rejected for security (deviation from Pi, which follows them).
19
+ */
20
+ import { existsSync, readdirSync } from "node:fs";
21
+ import { homedir } from "node:os";
22
+ import { join } from "node:path";
23
+ import { getAgentDir } from "@earendil-works/pi-coding-agent";
24
+ import { isSymlink, isUnsafeName, safeReadFile } from "./memory.js";
25
+ export function preloadSkills(skillNames, cwd) {
26
+ return skillNames.map((name) => ({ name, content: loadSkillContent(name, cwd) }));
27
+ }
28
+ function loadSkillContent(name, cwd) {
29
+ if (isUnsafeName(name)) {
30
+ return `(Skill "${name}" skipped: name contains path traversal characters)`;
31
+ }
32
+ const roots = [
33
+ join(cwd, ".pi", "skills"), // project — Pi standard
34
+ join(cwd, ".agents", "skills"), // project — Agent Skills spec
35
+ join(getAgentDir(), "skills"), // user — Pi standard
36
+ join(homedir(), ".agents", "skills"), // user — Agent Skills spec
37
+ join(homedir(), ".pi", "skills"), // legacy global, pre-Pi
38
+ ];
39
+ for (const root of roots) {
40
+ const content = findInRoot(root, name);
41
+ if (content !== undefined)
42
+ return content;
43
+ }
44
+ return `(Skill "${name}" not found in .pi/skills/, .agents/skills/, or global skill locations)`;
45
+ }
46
+ function findInRoot(root, name) {
47
+ if (isSymlink(root))
48
+ return undefined; // reject symlinked roots entirely
49
+ const flat = safeReadFile(join(root, `${name}.md`))?.trim();
50
+ if (flat !== undefined)
51
+ return flat;
52
+ return findSkillDirectory(root, name);
53
+ }
54
+ /** BFS under `root` for a directory named `name` containing `SKILL.md`. Pi-conforming filters. */
55
+ function findSkillDirectory(root, name) {
56
+ if (!existsSync(root))
57
+ return undefined;
58
+ const queue = [root];
59
+ while (queue.length > 0) {
60
+ const current = queue.shift();
61
+ if (current === undefined)
62
+ continue;
63
+ let entries;
64
+ try {
65
+ entries = readdirSync(current, { withFileTypes: true });
66
+ }
67
+ catch {
68
+ continue;
69
+ }
70
+ // Deterministic byte-order traversal — locale-independent.
71
+ entries.sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0));
72
+ for (const entry of entries) {
73
+ if (!entry.isDirectory())
74
+ continue;
75
+ if (entry.name.startsWith(".") || entry.name === "node_modules")
76
+ continue;
77
+ // Symlinked dirs already filtered by entry.isDirectory() — Dirent uses lstat semantics.
78
+ const path = join(current, entry.name);
79
+ const skillMd = join(path, "SKILL.md");
80
+ const isSkillDir = existsSync(skillMd);
81
+ if (isSkillDir) {
82
+ if (entry.name === name) {
83
+ const content = safeReadFile(skillMd)?.trim();
84
+ if (content !== undefined)
85
+ return content;
86
+ }
87
+ continue; // Pi rule: skills don't nest — don't descend into a skill dir
88
+ }
89
+ queue.push(path);
90
+ }
91
+ }
92
+ return undefined;
93
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * status-note.ts — Parenthetical status note appended to agent result text.
3
+ */
4
+ /**
5
+ * Explicit parenthetical note for a non-normal terminal outcome, so the parent
6
+ * agent can't mistake partial output for a completed result. Empty string for a
7
+ * clean completion (and any unknown/non-terminal status).
8
+ *
9
+ * `stopped` (a human aborted it) is deliberately distinct from `aborted` (the
10
+ * turn limit was hit) — the parent should treat human intervention differently
11
+ * from a budget cutoff.
12
+ */
13
+ export declare function getStatusNote(status: string): string;
@@ -0,0 +1,24 @@
1
+ /**
2
+ * status-note.ts — Parenthetical status note appended to agent result text.
3
+ */
4
+ /**
5
+ * Explicit parenthetical note for a non-normal terminal outcome, so the parent
6
+ * agent can't mistake partial output for a completed result. Empty string for a
7
+ * clean completion (and any unknown/non-terminal status).
8
+ *
9
+ * `stopped` (a human aborted it) is deliberately distinct from `aborted` (the
10
+ * turn limit was hit) — the parent should treat human intervention differently
11
+ * from a budget cutoff.
12
+ */
13
+ export function getStatusNote(status) {
14
+ switch (status) {
15
+ case "stopped":
16
+ return " (STOPPED BY THE USER before completion — output is partial; the task was NOT finished)";
17
+ case "aborted":
18
+ return " (aborted — hit the turn limit before completion; output may be incomplete)";
19
+ case "steered":
20
+ return " (wrapped up at the turn limit — output may be partial)";
21
+ default:
22
+ return "";
23
+ }
24
+ }
@@ -0,0 +1,197 @@
1
+ /**
2
+ * types.ts — Type definitions for the subagent system.
3
+ */
4
+ import type { ThinkingLevel } from "@earendil-works/pi-ai";
5
+ import type { AgentSession } from "@earendil-works/pi-coding-agent";
6
+ import type { LifetimeUsage } from "./usage.js";
7
+ export type { ThinkingLevel };
8
+ /** Agent type: any string name (built-in defaults or user-defined). */
9
+ export type SubagentType = string;
10
+ /** Names of the three embedded default agents. */
11
+ export declare const DEFAULT_AGENT_NAMES: readonly ["general-purpose", "Explore", "Plan"];
12
+ /** Memory scope for persistent agent memory. */
13
+ export type MemoryScope = "user" | "project" | "local";
14
+ /** Isolation mode for agent execution. */
15
+ export type IsolationMode = "worktree";
16
+ /** Unified agent configuration — used for both default and user-defined agents. */
17
+ export interface AgentConfig {
18
+ name: string;
19
+ displayName?: string;
20
+ description: string;
21
+ builtinToolNames?: string[];
22
+ /** Raw `ext:` selector entries from the `tools:` CSV, e.g. ["ext:foo", "ext:bar/x"].
23
+ * Presence of any entry flips extension tools to an explicit allowlist. */
24
+ extSelectors?: string[];
25
+ /** Tool denylist — these tools are removed even if `builtinToolNames` or extensions include them. */
26
+ disallowedTools?: string[];
27
+ /** true = inherit all, string[] = only listed, false = none */
28
+ extensions: true | string[] | false;
29
+ /** Extension-name denylist applied after the `extensions:` include set. Exclude wins.
30
+ * Plain canonical names only (case-insensitive); no paths, no wildcard. */
31
+ excludeExtensions?: string[];
32
+ /** true = inherit all, string[] = only listed, false = none */
33
+ skills: true | string[] | false;
34
+ model?: string;
35
+ thinking?: ThinkingLevel;
36
+ maxTurns?: number;
37
+ /** Persist this subagent as a normal pi session instead of keeping it in memory only. */
38
+ persistSession?: boolean;
39
+ /** Write the subagent's .output transcript. Defaults to true; false suppresses only that transcript. */
40
+ outputTranscript?: boolean;
41
+ /** Optional session directory used when persistSession is true. Omitted = pi's normal session location. */
42
+ sessionDir?: string;
43
+ systemPrompt: string;
44
+ promptMode: "replace" | "append";
45
+ /** Default for spawn: fork parent conversation. undefined = caller decides. */
46
+ inheritContext?: boolean;
47
+ /** Default for spawn: run in background. undefined = caller decides. */
48
+ runInBackground?: boolean;
49
+ /** Default for spawn: no extension tools. undefined = caller decides. */
50
+ isolated?: boolean;
51
+ /** Persistent memory scope — agents with memory get a persistent directory and MEMORY.md */
52
+ memory?: MemoryScope;
53
+ /** Isolation mode — "worktree" runs the agent in a temporary git worktree */
54
+ isolation?: IsolationMode;
55
+ /** true = this is an embedded default agent (informational) */
56
+ isDefault?: boolean;
57
+ /** false = agent is hidden from the registry */
58
+ enabled?: boolean;
59
+ /** Where this agent was loaded from */
60
+ source?: "default" | "project" | "global";
61
+ }
62
+ export type JoinMode = 'async' | 'group' | 'smart';
63
+ /**
64
+ * Display mode for the persistent above-editor agent widget.
65
+ * - `all`: show every agent (foreground + background).
66
+ * - `background`: hide foreground agents (they already render inline as the
67
+ * Agent tool result, #118); show background/queued/scheduled/RPC.
68
+ * - `off`: hide the widget entirely.
69
+ */
70
+ export type WidgetMode = 'all' | 'background' | 'off';
71
+ export interface AgentRecord {
72
+ id: string;
73
+ type: SubagentType;
74
+ description: string;
75
+ status: "queued" | "running" | "completed" | "steered" | "aborted" | "stopped" | "error";
76
+ result?: string;
77
+ error?: string;
78
+ toolUses: number;
79
+ startedAt: number;
80
+ completedAt?: number;
81
+ session?: AgentSession;
82
+ abortController?: AbortController;
83
+ promise?: Promise<string>;
84
+ groupId?: string;
85
+ joinMode?: JoinMode;
86
+ /** Set when result was already consumed via get_subagent_result — suppresses completion notification. */
87
+ resultConsumed?: boolean;
88
+ /** Steering messages queued before the session was ready. */
89
+ pendingSteers?: string[];
90
+ /** Worktree info if the agent is running in an isolated worktree. */
91
+ worktree?: {
92
+ path: string;
93
+ branch: string;
94
+ baseSha: string;
95
+ workPath: string;
96
+ };
97
+ /** Worktree cleanup result after agent completion. */
98
+ worktreeResult?: {
99
+ hasChanges: boolean;
100
+ branch?: string;
101
+ };
102
+ /** The tool_use_id from the original Agent tool call. */
103
+ toolCallId?: string;
104
+ /** Path to the streaming output transcript file. */
105
+ outputFile?: string;
106
+ /** Cleanup function for the output file stream subscription. */
107
+ outputCleanup?: () => void;
108
+ /**
109
+ * Lifetime usage breakdown, accumulated via `message_end` events. Survives
110
+ * compaction. Total = input + output + cacheWrite (cacheRead deliberately
111
+ * excluded — see issue #38). Initialized to zeros at spawn.
112
+ */
113
+ lifetimeUsage: LifetimeUsage;
114
+ /** Number of times this agent's session has compacted. Initialized to 0 at spawn. */
115
+ compactionCount: number;
116
+ /**
117
+ * Whether this agent was spawned to run in the background. Tri-state, set at
118
+ * spawn from `SpawnOptions.isBackground`: `true` = background, `false` =
119
+ * foreground (has an inline Agent tool-result surface), `undefined` = the
120
+ * caller never declared it (e.g. a cross-extension RPC spawn, which is detached
121
+ * and has no inline surface). The widget's background-only filter keys off this
122
+ * — and excludes only explicit `false`, so `undefined` agents stay visible.
123
+ * Reliable across ALL spawn paths, unlike the UI-only `invocation` snapshot,
124
+ * which only the Agent-tool path populates.
125
+ */
126
+ isBackground?: boolean;
127
+ /** Resolved spawn params, captured for UI display. Fixed at spawn time. */
128
+ invocation?: AgentInvocation;
129
+ }
130
+ export interface AgentInvocation {
131
+ /** Short display name, e.g. "haiku" — only set when different from parent. */
132
+ modelName?: string;
133
+ thinking?: ThinkingLevel;
134
+ maxTurns?: number;
135
+ isolated?: boolean;
136
+ inheritContext?: boolean;
137
+ runInBackground?: boolean;
138
+ isolation?: IsolationMode;
139
+ }
140
+ /** Details attached to custom notification messages for visual rendering. */
141
+ export interface NotificationDetails {
142
+ id: string;
143
+ description: string;
144
+ status: string;
145
+ toolUses: number;
146
+ turnCount: number;
147
+ maxTurns?: number;
148
+ totalTokens: number;
149
+ durationMs: number;
150
+ outputFile?: string;
151
+ error?: string;
152
+ resultPreview: string;
153
+ /** Additional agents in a group notification. */
154
+ others?: NotificationDetails[];
155
+ }
156
+ export interface EnvInfo {
157
+ isGitRepo: boolean;
158
+ branch: string;
159
+ platform: string;
160
+ }
161
+ /**
162
+ * A subagent spawn registered to fire on a schedule.
163
+ *
164
+ * Stored at `<cwd>/.pi/subagent-schedules/<sessionId>.json`. Session-scoped:
165
+ * survives `/resume` but resets on `/new`, mirroring pi-chonky-tasks.
166
+ */
167
+ export interface ScheduledSubagent {
168
+ id: string;
169
+ /** Unique within store. Defaults to `description`. */
170
+ name: string;
171
+ description: string;
172
+ /** Raw user input — cron expr | "+10m" | ISO | "5m". */
173
+ schedule: string;
174
+ scheduleType: "cron" | "once" | "interval";
175
+ /** Computed at create time for interval/once. */
176
+ intervalMs?: number;
177
+ subagent_type: SubagentType;
178
+ prompt: string;
179
+ model?: string;
180
+ thinking?: ThinkingLevel;
181
+ max_turns?: number;
182
+ isolated?: boolean;
183
+ isolation?: IsolationMode;
184
+ enabled: boolean;
185
+ /** ISO timestamp. */
186
+ createdAt: string;
187
+ lastRun?: string;
188
+ lastStatus?: "success" | "error" | "running";
189
+ /** Refreshed on every fire and on store load. */
190
+ nextRun?: string;
191
+ runCount: number;
192
+ }
193
+ export interface ScheduleStoreData {
194
+ /** For future migrations. */
195
+ version: 1;
196
+ jobs: ScheduledSubagent[];
197
+ }
package/dist/types.js ADDED
@@ -0,0 +1,5 @@
1
+ /**
2
+ * types.ts — Type definitions for the subagent system.
3
+ */
4
+ /** Names of the three embedded default agents. */
5
+ export const DEFAULT_AGENT_NAMES = ["general-purpose", "Explore", "Plan"];
@@ -0,0 +1,160 @@
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 LifetimeUsage, 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
+ /** Lifetime usage breakdown — see LifetimeUsage docs. */
38
+ lifetimeUsage: LifetimeUsage;
39
+ }
40
+ /** Metadata attached to Agent tool results for custom rendering. */
41
+ export interface AgentDetails {
42
+ displayName: string;
43
+ description: string;
44
+ subagentType: string;
45
+ toolUses: number;
46
+ tokens: string;
47
+ durationMs: number;
48
+ status: "queued" | "running" | "completed" | "steered" | "aborted" | "stopped" | "error" | "background";
49
+ /** Human-readable description of what the agent is currently doing. */
50
+ activity?: string;
51
+ /** Current spinner frame index (for animated running indicator). */
52
+ spinnerFrame?: number;
53
+ /** Short model name if different from parent (e.g. "haiku", "sonnet"). */
54
+ modelName?: string;
55
+ /** Notable config tags (e.g. ["thinking: high", "isolated"]). */
56
+ tags?: string[];
57
+ /** Current turn count. */
58
+ turnCount?: number;
59
+ /** Effective max turns (undefined = unlimited). */
60
+ maxTurns?: 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
+ * Token count with optional context-fill % and compaction-count annotations.
70
+ * Thresholds for percent: <70% dim, 70–85% warning, ≥85% error.
71
+ * Compaction count rendered as `⇊N` in dim.
72
+ *
73
+ * "12.3k token" — no annotations
74
+ * "12.3k token (45%)" — percent only
75
+ * "12.3k token (⇊2)" — compactions only (e.g. right after compact)
76
+ * "12.3k token (45% · ⇊2)" — both
77
+ */
78
+ export declare function formatSessionTokens(tokens: number, percent: number | null, theme: Theme, compactions?: number): string;
79
+ /** Format turn count with optional max limit: "↻5≤30" or "↻5". */
80
+ export declare function formatTurns(turnCount: number, maxTurns?: number | null): string;
81
+ /** Format milliseconds as human-readable duration. */
82
+ export declare function formatMs(ms: number): string;
83
+ /** Format duration from start/completed timestamps. */
84
+ export declare function formatDuration(startedAt: number, completedAt?: number): string;
85
+ /** Get display name for any agent type (built-in or custom). */
86
+ export declare function getDisplayName(type: SubagentType): string;
87
+ /** Short label for prompt mode: "twin" for append, nothing for replace (the default). */
88
+ export declare function getPromptModeLabel(type: SubagentType): string | undefined;
89
+ /** Mode label is not included — callers add it where they want it. */
90
+ export declare function buildInvocationTags(invocation: AgentInvocation | undefined): {
91
+ modelName?: string;
92
+ tags: string[];
93
+ };
94
+ /** Build a human-readable activity string from currently-running tools or response text. */
95
+ export declare function describeActivity(activeTools: Map<string, string>, responseText?: string): string;
96
+ export declare class AgentWidget {
97
+ private manager;
98
+ private agentActivity;
99
+ /**
100
+ * Read live at render time. Selects which agents the widget shows — see
101
+ * `WidgetMode`. Defaults to `"all"` when a caller supplies no policy; the
102
+ * extension supplies one defaulting to `"background"`.
103
+ */
104
+ private mode;
105
+ private uiCtx;
106
+ private widgetFrame;
107
+ private widgetInterval;
108
+ /** Tracks how many turns each finished agent has survived. Key: agent ID, Value: turns since finished. */
109
+ private finishedTurnAge;
110
+ /** How many extra turns errors/aborted agents linger (completed agents clear after 1 turn). */
111
+ private static readonly ERROR_LINGER_TURNS;
112
+ /** Whether the widget callback is currently registered with the TUI. */
113
+ private widgetRegistered;
114
+ /** Cached TUI reference from widget factory callback, used for requestRender(). */
115
+ private tui;
116
+ /** Last status bar text, used to avoid redundant setStatus calls. */
117
+ private lastStatusText;
118
+ constructor(manager: AgentManager, agentActivity: Map<string, AgentActivity>,
119
+ /**
120
+ * Read live at render time. Selects which agents the widget shows — see
121
+ * `WidgetMode`. Defaults to `"all"` when a caller supplies no policy; the
122
+ * extension supplies one defaulting to `"background"`.
123
+ */
124
+ mode?: () => WidgetMode);
125
+ /**
126
+ * Agents eligible for the widget, per the current `WidgetMode`:
127
+ * - `off`: none (the widget's existing empty-state path hides it entirely).
128
+ * - `background`: drop only agents *known* to be foreground
129
+ * (`isBackground === false`); keep everything else — background, queued,
130
+ * scheduled, or RPC-spawned (`undefined`). Keying off the `isBackground`
131
+ * record flag rather than the UI-only `invocation` snapshot (which only the
132
+ * Agent-tool path sets), and excluding rather than allow-listing, means
133
+ * only proven-foreground runs drop out — nothing else silently vanishes.
134
+ * - `all`: every agent.
135
+ */
136
+ private widgetAgents;
137
+ /** Set the UI context (grabbed from first tool execution). */
138
+ setUICtx(ctx: UICtx): void;
139
+ /**
140
+ * Called on each new turn (tool_execution_start).
141
+ * Ages finished agents and clears those that have lingered long enough.
142
+ */
143
+ onTurnStart(): void;
144
+ /** Ensure the widget update timer is running. */
145
+ ensureTimer(): void;
146
+ /** Check if a finished agent should still be shown in the widget. */
147
+ private shouldShowFinished;
148
+ /** Record an agent as finished (call when agent completes). */
149
+ markFinished(agentId: string): void;
150
+ /** Render a finished agent line. */
151
+ private renderFinishedLine;
152
+ /**
153
+ * Render the widget content. Called from the registered widget's render() callback,
154
+ * reading live state each time instead of capturing it in a closure.
155
+ */
156
+ private renderWidget;
157
+ /** Force an immediate widget update. */
158
+ update(): void;
159
+ dispose(): void;
160
+ }