@timmyjl12/pi-subagents 0.0.0-stage → 0.21.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 +862 -0
- package/CONTRIBUTING.md +72 -0
- package/LICENSE +21 -0
- package/README.md +1125 -3
- 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 +40 -0
- package/dist/active-agents-prompt.js +98 -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 +131 -0
- package/dist/agent-file-toggle.d.ts +125 -0
- package/dist/agent-file-toggle.js +264 -0
- package/dist/agent-manager.d.ts +872 -0
- package/dist/agent-manager.js +2910 -0
- package/dist/agent-runner.d.ts +358 -0
- package/dist/agent-runner.js +1219 -0
- package/dist/agent-types.d.ts +142 -0
- package/dist/agent-types.js +315 -0
- package/dist/awaited-result.d.ts +37 -0
- package/dist/awaited-result.js +150 -0
- package/dist/child-context.d.ts +15 -0
- package/dist/child-context.js +181 -0
- package/dist/child-session-shutdown.d.ts +21 -0
- package/dist/child-session-shutdown.js +97 -0
- package/dist/cleanup-plans.d.ts +10 -0
- package/dist/cleanup-plans.js +112 -0
- package/dist/context.d.ts +12 -0
- package/dist/context.js +56 -0
- package/dist/cross-extension-rpc.d.ts +73 -0
- package/dist/cross-extension-rpc.js +192 -0
- package/dist/custom-agents.d.ts +79 -0
- package/dist/custom-agents.js +583 -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 +64 -0
- package/dist/error-log.js +176 -0
- package/dist/force-main-model.d.ts +21 -0
- package/dist/force-main-model.js +28 -0
- package/dist/goal-bridge.d.ts +155 -0
- package/dist/goal-bridge.js +305 -0
- package/dist/group-join.d.ts +36 -0
- package/dist/group-join.js +161 -0
- package/dist/index.d.ts +52 -0
- package/dist/index.js +6390 -0
- package/dist/invocation-config.d.ts +164 -0
- package/dist/invocation-config.js +158 -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 +76 -0
- package/dist/nested-tools.js +393 -0
- package/dist/output-diagnostics.d.ts +11 -0
- package/dist/output-diagnostics.js +64 -0
- package/dist/output-file.d.ts +64 -0
- package/dist/output-file.js +351 -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/report-cleanup.d.ts +204 -0
- package/dist/report-cleanup.js +1632 -0
- package/dist/report-store.d.ts +738 -0
- package/dist/report-store.js +3612 -0
- package/dist/schedule-store.d.ts +52 -0
- package/dist/schedule-store.js +240 -0
- package/dist/schedule.d.ts +121 -0
- package/dist/schedule.js +420 -0
- package/dist/settings.d.ts +388 -0
- package/dist/settings.js +268 -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 +411 -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 +304 -0
- package/dist/ui/agent-widget.js +770 -0
- package/dist/ui/cleanup-preview.d.ts +59 -0
- package/dist/ui/cleanup-preview.js +466 -0
- package/dist/ui/conversation-viewer.d.ts +105 -0
- package/dist/ui/conversation-viewer.js +544 -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 +203 -0
- package/dist/ui/fleet-overlay.js +887 -0
- package/dist/ui/hub-feed.d.ts +52 -0
- package/dist/ui/hub-feed.js +148 -0
- package/dist/ui/native-transcript.d.ts +33 -0
- package/dist/ui/native-transcript.js +234 -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 +848 -0
- package/dist/ui/workflow-menu.d.ts +60 -0
- package/dist/ui/workflow-menu.js +147 -0
- package/dist/usage.d.ts +147 -0
- package/dist/usage.js +147 -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 +65 -0
- package/dist/workflow/host.js +477 -0
- package/dist/workflow/journal.d.ts +113 -0
- package/dist/workflow/journal.js +177 -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 +373 -0
- package/dist/workflow/runtime.js +919 -0
- package/dist/workflow/saved.d.ts +90 -0
- package/dist/workflow/saved.js +203 -0
- package/dist/workflow/task.d.ts +145 -0
- package/dist/workflow/task.js +213 -0
- package/dist/workflow/tool-description.d.ts +43 -0
- package/dist/workflow/tool-description.js +204 -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/DEVELOPMENT.md +40 -0
- package/docs/artifacts.md +93 -0
- package/docs/recovery.md +62 -0
- package/docs/rpc.md +252 -0
- package/docs/runtime-performance.md +53 -0
- package/docs/workflows.md +467 -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 +66 -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 +115 -0
- package/src/advisor-status.ts +74 -0
- package/src/agent-color.ts +169 -0
- package/src/agent-file-toggle.ts +273 -0
- package/src/agent-manager.ts +3312 -0
- package/src/agent-runner.ts +1500 -0
- package/src/agent-types.ts +390 -0
- package/src/awaited-result.ts +187 -0
- package/src/child-context.ts +173 -0
- package/src/child-session-shutdown.ts +114 -0
- package/src/cleanup-plans.ts +112 -0
- package/src/context.ts +58 -0
- package/src/cross-extension-rpc.ts +257 -0
- package/src/custom-agents.ts +689 -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 +202 -0
- package/src/force-main-model.ts +29 -0
- package/src/goal-bridge.ts +468 -0
- package/src/group-join.ts +188 -0
- package/src/index.ts +6856 -0
- package/src/invocation-config.ts +276 -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 +553 -0
- package/src/output-diagnostics.ts +68 -0
- package/src/output-file.ts +380 -0
- package/src/prompts.ts +151 -0
- package/src/recovery.ts +320 -0
- package/src/report-cleanup.ts +2044 -0
- package/src/report-store.ts +4130 -0
- package/src/schedule-store.ts +244 -0
- package/src/schedule.ts +450 -0
- package/src/settings.ts +632 -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 +424 -0
- package/src/ui/agent-mention.ts +216 -0
- package/src/ui/agent-widget.ts +866 -0
- package/src/ui/cleanup-preview.ts +518 -0
- package/src/ui/conversation-viewer.ts +527 -0
- package/src/ui/fleet-list.ts +563 -0
- package/src/ui/fleet-overlay.ts +1048 -0
- package/src/ui/hub-feed.ts +179 -0
- package/src/ui/native-transcript.ts +224 -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 +1119 -0
- package/src/ui/workflow-menu.ts +193 -0
- package/src/usage.ts +217 -0
- package/src/workflow/collisions.ts +123 -0
- package/src/workflow/entry.ts +47 -0
- package/src/workflow/host.ts +524 -0
- package/src/workflow/journal.ts +221 -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 +1342 -0
- package/src/workflow/saved.ts +217 -0
- package/src/workflow/task.ts +313 -0
- package/src/workflow/tool-description.ts +205 -0
- package/src/workflow/worker-source.ts +781 -0
- package/src/worktree.ts +205 -0
- package/src/xml.ts +13 -0
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* terminal-progress.ts — Keep the terminal's progress spinner alive while subagents run.
|
|
3
|
+
*
|
|
4
|
+
* pi drives the tab/taskbar progress spinner (OSC 9;4, "indeterminate") from
|
|
5
|
+
* the MAIN session only: `turn_start` sets it, `agent_end` clears it. A turn
|
|
6
|
+
* that ends with background agents still running therefore blanks the spinner
|
|
7
|
+
* even though work continues — the session looks finished when it isn't.
|
|
8
|
+
*
|
|
9
|
+
* This module holds the indicator up across exactly that gap, writing the same
|
|
10
|
+
* escape sequences pi itself writes (pi-tui's `ProcessTerminal.setProgress`):
|
|
11
|
+
*
|
|
12
|
+
* active: ESC ] 9 ; 4 ; 3 BEL — indeterminate progress
|
|
13
|
+
* clear: ESC ] 9 ; 4 ; 0 BEL — progress off
|
|
14
|
+
*
|
|
15
|
+
* Two writers share one indicator, so ownership rules keep them from fighting:
|
|
16
|
+
*
|
|
17
|
+
* - While the MAIN session is busy (`ctx.isIdle()` false — an agent run, a
|
|
18
|
+
* queued continuation, a retry, a compaction), pi owns the indicator. We
|
|
19
|
+
* still assert alongside it — the bytes are identical, so the duplicate
|
|
20
|
+
* write is invisible — but we never CLEAR in that window; that would blank
|
|
21
|
+
* pi's own spinner. pi clears at its `agent_end`, and the `agent_end` hook
|
|
22
|
+
* re-asserts right behind it (see onMainAgentEnd).
|
|
23
|
+
* - While the main session is idle and subagent work exists, we own it: assert
|
|
24
|
+
* on every refresh, re-send on a 1s keepalive (same cadence as pi — some
|
|
25
|
+
* terminals, Windows Terminal included, drop the progress state when the
|
|
26
|
+
* title is rewritten, so it must be re-sent), and CLEAR once when the work
|
|
27
|
+
* drains — only ever undoing our own assert.
|
|
28
|
+
* - With no subagent work we never assert: sessions that never spawn agents
|
|
29
|
+
* see pi's indicator behavior untouched.
|
|
30
|
+
*
|
|
31
|
+
* Writes are gated to `ctx.mode === "tui"`: RPC mode's stdout is a JSON
|
|
32
|
+
* channel the sequences would corrupt, and headless child sessions — every
|
|
33
|
+
* subagent re-activates this extension in-process — have no terminal to spin.
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
37
|
+
import { join } from "node:path";
|
|
38
|
+
import { getAgentDir } from "@earendil-works/pi-coding-agent";
|
|
39
|
+
|
|
40
|
+
/** OSC 9;4;3 — indeterminate progress. BEL-terminated, like pi-tui's. */
|
|
41
|
+
const PROGRESS_ACTIVE = "\x1b]9;4;3\x07";
|
|
42
|
+
/** OSC 9;4;0 — progress off. */
|
|
43
|
+
const PROGRESS_CLEAR = "\x1b]9;4;0\x07";
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Keepalive cadence. Mirrors pi-tui's TERMINAL_PROGRESS_KEEPALIVE_MS so the
|
|
47
|
+
* two writers re-assert at the same rate; a faster one would win nothing and
|
|
48
|
+
* a slower one would let the state drop for longer.
|
|
49
|
+
*/
|
|
50
|
+
const KEEPALIVE_MS = 1_000;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Read pi's `terminal.showTerminalProgress` setting (project
|
|
54
|
+
* `<cwd>/.pi/settings.json` over global `<agentDir>/settings.json`, mirroring
|
|
55
|
+
* pi's SettingsManager merge — the same precedence src/enabled-models.ts uses
|
|
56
|
+
* for `enabledModels`).
|
|
57
|
+
*
|
|
58
|
+
* The gate matters because pi's own indicator is opt-in (pi defaults the
|
|
59
|
+
* setting to false): a user who disabled terminal progress should not get a
|
|
60
|
+
* subagent-driven spinner pi would never have shown. Defaults to false on
|
|
61
|
+
* absent field and on unreadable file — the same effective state pi itself
|
|
62
|
+
* degrades to — with a stderr warning on a corrupt file so the miss is
|
|
63
|
+
* diagnosable rather than looking like a dead feature.
|
|
64
|
+
*/
|
|
65
|
+
export function readShowTerminalProgress(cwd: string): boolean {
|
|
66
|
+
const read = (path: string): boolean | undefined => {
|
|
67
|
+
if (!existsSync(path)) return undefined;
|
|
68
|
+
try {
|
|
69
|
+
const raw: unknown = JSON.parse(readFileSync(path, "utf-8"));
|
|
70
|
+
const value = (raw as { terminal?: { showTerminalProgress?: unknown } } | null)?.terminal
|
|
71
|
+
?.showTerminalProgress;
|
|
72
|
+
return typeof value === "boolean" ? value : undefined;
|
|
73
|
+
} catch (err) {
|
|
74
|
+
const reason = err instanceof Error ? err.message : String(err);
|
|
75
|
+
console.warn(`[pi-subagents] Ignoring malformed settings at ${path}: ${reason}`);
|
|
76
|
+
return undefined;
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
const project = read(join(cwd, ".pi", "settings.json"));
|
|
80
|
+
if (project !== undefined) return project;
|
|
81
|
+
return read(join(getAgentDir(), "settings.json")) ?? false;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** Live inputs the tracker reads on every decision. All are getters on purpose: state is re-probed, never cached. */
|
|
85
|
+
export interface TerminalProgressInputs {
|
|
86
|
+
/** Whether any subagent work is running or queued (AgentManager.hasRunning). */
|
|
87
|
+
hasWork(): boolean;
|
|
88
|
+
/** Whether the MAIN session owns the indicator: an agent run or compaction in flight (pi shows its own spinner). */
|
|
89
|
+
isMainBusy(): boolean;
|
|
90
|
+
/** Whether writing to the terminal is allowed at all (interactive TUI session). */
|
|
91
|
+
canWrite(): boolean;
|
|
92
|
+
/** Whether the user enabled terminal progress in pi's settings. */
|
|
93
|
+
enabled(): boolean;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export class TerminalProgressTracker {
|
|
97
|
+
private interval: ReturnType<typeof setInterval> | undefined;
|
|
98
|
+
/** Last sequence this tracker wrote. ACTIVE re-sends are the keepalive's whole job; CLEAR only ever undoes an assert (see clear()). */
|
|
99
|
+
private lastWrite: "active" | "clear" | undefined;
|
|
100
|
+
private disposed = false;
|
|
101
|
+
|
|
102
|
+
constructor(
|
|
103
|
+
private inputs: TerminalProgressInputs,
|
|
104
|
+
/** Sink for the escape sequences. Injectable so tests can capture writes. */
|
|
105
|
+
private write: (data: string) => void = (data) => { process.stdout.write(data); },
|
|
106
|
+
) {}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Re-evaluate and sync the indicator. Called when subagent work starts or
|
|
110
|
+
* settles, and from the keepalive tick — a re-probe, so a missed event
|
|
111
|
+
* self-heals within one keepalive period.
|
|
112
|
+
*/
|
|
113
|
+
refresh(): void {
|
|
114
|
+
if (this.disposed) return;
|
|
115
|
+
if (!this.inputs.enabled() || !this.inputs.canWrite()) {
|
|
116
|
+
// Opted out, or nowhere to write. Undo an assert this tracker made —
|
|
117
|
+
// clear() keys off `lastWrite`, which is proof this tracker passed the
|
|
118
|
+
// write gate when it asserted (child/RPC activations can never assert,
|
|
119
|
+
// and the sink never changes), so the clear lands on the same stdout the
|
|
120
|
+
// ACTIVE did; that is also the policy dispose() states. The mid-session
|
|
121
|
+
// opt-out this guards against is unreachable today (the setting is read
|
|
122
|
+
// once per session bind); the branch is the correct undo if that ever
|
|
123
|
+
// becomes live-read, and without it a stranded ACTIVE would have no
|
|
124
|
+
// re-probe left — the keepalive is being stopped here.
|
|
125
|
+
this.clear();
|
|
126
|
+
this.stopKeepalive();
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
if (this.inputs.hasWork()) {
|
|
130
|
+
this.assert();
|
|
131
|
+
} else {
|
|
132
|
+
this.stopKeepalive();
|
|
133
|
+
// No subagent work. Clear only when pi isn't mid-run: pi clears its own
|
|
134
|
+
// indicator at its agent_end, and a clear from us in that window would
|
|
135
|
+
// blank the main session's spinner until pi's 1s keepalive re-sent it.
|
|
136
|
+
if (!this.inputs.isMainBusy()) this.clear();
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Hook for the main session's `agent_end`.
|
|
142
|
+
*
|
|
143
|
+
* pi clears the indicator there AFTER extension handlers run (agent-session
|
|
144
|
+
* emits to extensions before its own listeners), so re-asserting
|
|
145
|
+
* synchronously would be overwritten a moment later. Deferring with
|
|
146
|
+
* setImmediate lands after pi's write in the common case — but that ordering
|
|
147
|
+
* is not guaranteed: another extension's agent_end handler that awaits real
|
|
148
|
+
* I/O lets this callback run first, and the ACTIVE is wiped by pi's clear.
|
|
149
|
+
* That is fine by design: the 1s keepalive re-sends within a second, and the
|
|
150
|
+
* `agent_settled` refresh (which the wiring registers) re-probes the final
|
|
151
|
+
* state. This hook is the fast path, not the only one.
|
|
152
|
+
*
|
|
153
|
+
* Deliberately not gated on `isMainBusy`: agent_end also fires between an
|
|
154
|
+
* intermediate turn and its queued continuation, a window where pi has
|
|
155
|
+
* already cleared but work is still ongoing — the spinner belongs up there
|
|
156
|
+
* too. pi's next turn_start re-asserts over ours harmlessly.
|
|
157
|
+
*/
|
|
158
|
+
onMainAgentEnd(): void {
|
|
159
|
+
if (this.disposed) return;
|
|
160
|
+
if (!this.inputs.enabled() || !this.inputs.canWrite()) return;
|
|
161
|
+
setImmediate(() => {
|
|
162
|
+
if (!this.disposed && this.inputs.hasWork()) this.assert();
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Stop the keepalive and clear the indicator. Call on session shutdown, before pi restores the terminal.
|
|
168
|
+
*
|
|
169
|
+
* The clear goes through clear()'s "only undo our own assert" guard, which
|
|
170
|
+
* is the only safe gate here: dispose runs in every activation
|
|
171
|
+
* (session_shutdown fires inside child sessions too, #242), and both a child
|
|
172
|
+
* activation (mode "print") and an RPC-mode root must not put these bytes
|
|
173
|
+
* on stdout — RPC's stdout is a JSON channel, and a child teardown clearing
|
|
174
|
+
* mid-run would blank the root session's spinner. Those activations never
|
|
175
|
+
* pass the write gate, so they never assert, and dispose writes nothing.
|
|
176
|
+
* Reading `canWrite()` here instead would be wrong in the one case dispose
|
|
177
|
+
* exists for: the root TUI session, whose handler has already dropped
|
|
178
|
+
* `currentCtx` by the time dispose runs.
|
|
179
|
+
*/
|
|
180
|
+
dispose(): void {
|
|
181
|
+
if (this.disposed) return;
|
|
182
|
+
this.disposed = true;
|
|
183
|
+
this.stopKeepalive();
|
|
184
|
+
this.clear();
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
private assert(): void {
|
|
188
|
+
this.ensureKeepalive();
|
|
189
|
+
this.write(PROGRESS_ACTIVE);
|
|
190
|
+
this.lastWrite = "active";
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
private clear(): void {
|
|
194
|
+
// Only undo an assert this tracker made. A speculative clear would be
|
|
195
|
+
// noise on every no-work refresh (session bind), and worse: it cannot
|
|
196
|
+
// know the terminal's true state — pi drives the indicator too. If our
|
|
197
|
+
// ACTIVE was clobbered by pi's own clear, the keepalive re-asserts; the
|
|
198
|
+
// indicator is only ever cleared by whoever left it up.
|
|
199
|
+
if (this.lastWrite !== "active") return;
|
|
200
|
+
this.write(PROGRESS_CLEAR);
|
|
201
|
+
this.lastWrite = "clear";
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
private ensureKeepalive(): void {
|
|
205
|
+
if (this.interval) return;
|
|
206
|
+
this.interval = setInterval(() => this.refresh(), KEEPALIVE_MS);
|
|
207
|
+
this.interval.unref?.();
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
private stopKeepalive(): void {
|
|
211
|
+
if (!this.interval) return;
|
|
212
|
+
clearInterval(this.interval);
|
|
213
|
+
this.interval = undefined;
|
|
214
|
+
}
|
|
215
|
+
}
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,424 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* types.ts — Type definitions for the subagent system.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { AgentSession } from "@earendil-works/pi-coding-agent";
|
|
6
|
+
import type { AdvisorStatus } from "./advisor-status.ts";
|
|
7
|
+
import type { LifetimeUsage } from "./usage.ts";
|
|
8
|
+
|
|
9
|
+
/** Use the session's full control surface, including the explicit "off" level. */
|
|
10
|
+
export type ThinkingLevel = AgentSession["thinkingLevel"];
|
|
11
|
+
|
|
12
|
+
/** Agent type: any string name (built-in defaults or user-defined). */
|
|
13
|
+
export type SubagentType = string;
|
|
14
|
+
|
|
15
|
+
/** Names of the three embedded default agents. */
|
|
16
|
+
export const DEFAULT_AGENT_NAMES = ["general-purpose", "Explore", "Plan"] as const;
|
|
17
|
+
|
|
18
|
+
/** Memory scope for persistent agent memory. */
|
|
19
|
+
export type MemoryScope = "user" | "project" | "local";
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Isolation mode for agent execution.
|
|
23
|
+
*
|
|
24
|
+
* `"off"` exists for the caller's benefit, not the runtime's: models that fill
|
|
25
|
+
* every optional parameter had no legal way to decline a single-value
|
|
26
|
+
* `isolation` field and kept spawning worktrees they had just reasoned their
|
|
27
|
+
* way out of (#231, #184). It is an input spelling only —
|
|
28
|
+
* `resolveAgentInvocationConfig` collapses it to `undefined`, so nothing
|
|
29
|
+
* downstream sees a value other than `"worktree"`. In an agent file it is a
|
|
30
|
+
* genuine veto, since agent config outranks tool-call params.
|
|
31
|
+
*/
|
|
32
|
+
export type IsolationMode = "worktree" | "off";
|
|
33
|
+
|
|
34
|
+
/** Unified agent configuration — used for both default and user-defined agents. */
|
|
35
|
+
export interface AgentConfig {
|
|
36
|
+
name: string;
|
|
37
|
+
/** UI name. `display_name` wins; Claude Code's `name` is accepted as a fallback. */
|
|
38
|
+
displayName?: string;
|
|
39
|
+
/** Claude Code-compatible name color (named color or #RRGGBB). */
|
|
40
|
+
color?: string;
|
|
41
|
+
description: string;
|
|
42
|
+
builtinToolNames?: string[];
|
|
43
|
+
/** Raw `ext:` selector entries from the `tools:` CSV, e.g. ["ext:foo", "ext:bar/x"].
|
|
44
|
+
* Presence of any entry flips extension tools to an explicit allowlist. */
|
|
45
|
+
extSelectors?: string[];
|
|
46
|
+
/** Tool denylist — these tools are removed even if `builtinToolNames` or extensions include them. */
|
|
47
|
+
disallowedTools?: string[];
|
|
48
|
+
/** true = inherit all, string[] = only listed, false = none */
|
|
49
|
+
extensions: true | string[] | false;
|
|
50
|
+
/** Extension-name denylist applied after the `extensions:` include set. Exclude wins.
|
|
51
|
+
* Plain canonical names only (case-insensitive); no paths, no wildcard. */
|
|
52
|
+
excludeExtensions?: string[];
|
|
53
|
+
/** true = inherit all, string[] = only listed, false = none */
|
|
54
|
+
skills: true | string[] | false;
|
|
55
|
+
model?: string;
|
|
56
|
+
/** Standalone recovery target when pi-fallback-chains is absent; runner wiring is separate. */
|
|
57
|
+
fallbackModel?: string;
|
|
58
|
+
/**
|
|
59
|
+
* Per-agent pi-advisor control for this agent's child sessions.
|
|
60
|
+
* `false` excludes the advisor family (pi-advisor, pi-omp-advisor) from the
|
|
61
|
+
* child's loader outright; `true` keeps it loaded and raises
|
|
62
|
+
* `PI_ADVISOR_SUBAGENTS=1` for the child's extension-bind window so the
|
|
63
|
+
* advisor's default-enable gate turns on. Undefined defers to pi-advisor's
|
|
64
|
+
* own precedence (env → WATCHDOG `subagents:` → built-in off) untouched.
|
|
65
|
+
*/
|
|
66
|
+
advisor?: boolean;
|
|
67
|
+
thinking?: ThinkingLevel;
|
|
68
|
+
maxTurns?: number;
|
|
69
|
+
/** Persist this subagent as a normal pi session instead of keeping it in memory only. */
|
|
70
|
+
persistSession?: boolean;
|
|
71
|
+
/** Write the subagent's .output transcript. Defaults to true; false suppresses only that transcript. */
|
|
72
|
+
outputTranscript?: boolean;
|
|
73
|
+
/** Optional session directory used when persistSession is true. Omitted = pi's normal session location. */
|
|
74
|
+
sessionDir?: string;
|
|
75
|
+
/**
|
|
76
|
+
* Nested delegation, off by default: undefined = no nested tools;
|
|
77
|
+
* "all" = any enabled agent; string[] = only those agent types.
|
|
78
|
+
*/
|
|
79
|
+
allowedSubagents?: "all" | string[];
|
|
80
|
+
systemPrompt: string;
|
|
81
|
+
promptMode: "replace" | "append";
|
|
82
|
+
/** Default for spawn: fork parent conversation. undefined = caller decides. */
|
|
83
|
+
inheritContext?: boolean;
|
|
84
|
+
/** Default for spawn: run in background. undefined = caller decides. */
|
|
85
|
+
runInBackground?: boolean;
|
|
86
|
+
/** Default for spawn: no extension tools. undefined = caller decides. */
|
|
87
|
+
isolated?: boolean;
|
|
88
|
+
/** Persistent memory scope — agents with memory get a persistent directory and MEMORY.md */
|
|
89
|
+
memory?: MemoryScope;
|
|
90
|
+
/**
|
|
91
|
+
* Isolation mode — "worktree" runs the agent in a temporary git worktree,
|
|
92
|
+
* "off" refuses one even when the caller asks (frontmatter outranks params).
|
|
93
|
+
*/
|
|
94
|
+
isolation?: IsolationMode;
|
|
95
|
+
/** true = this is an embedded default agent (informational) */
|
|
96
|
+
isDefault?: boolean;
|
|
97
|
+
/** false = agent is hidden from the registry */
|
|
98
|
+
enabled?: boolean;
|
|
99
|
+
/** Where this agent was loaded from */
|
|
100
|
+
source?: "default" | "project" | "global";
|
|
101
|
+
/** Path of the .md it was loaded from. Unset for embedded defaults. */
|
|
102
|
+
sourcePath?: string;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export type JoinMode = 'async' | 'group' | 'smart';
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Display mode for the persistent agent widget.
|
|
109
|
+
* - `all`: show every agent (foreground + background).
|
|
110
|
+
* - `background`: hide foreground agents (they already render inline as the
|
|
111
|
+
* Agent tool result, #118); show background/queued/scheduled/RPC.
|
|
112
|
+
* - `off`: hide the widget entirely.
|
|
113
|
+
*/
|
|
114
|
+
export type WidgetMode = 'all' | 'background' | 'off';
|
|
115
|
+
|
|
116
|
+
/** Placement of the compact agent widget relative to the prompt editor. */
|
|
117
|
+
export type WidgetPlacement = 'above' | 'below';
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* How much of the conversation viewer's transcript is rendered as Markdown.
|
|
121
|
+
* - `off`: every line wraps as literal text, as it did before the mode existed.
|
|
122
|
+
* - `assistant`: assistant text renders as Markdown; tool results stay verbatim
|
|
123
|
+
* and dim. The default, because assistant text *is* Markdown by contract
|
|
124
|
+
* while a tool result is arbitrary bytes — a Markdown pass over a log or a
|
|
125
|
+
* diff eats `#` from shell comments, swallows a `---` line into a setext
|
|
126
|
+
* heading, re-fences indented output and redraws `| a | b |` as a table.
|
|
127
|
+
* (Ordered-list renumbering is the one such rewrite actively suppressed —
|
|
128
|
+
* see `MARKDOWN_OPTIONS` — because it silently changes data, not layout.)
|
|
129
|
+
* - `all`: tool results render as Markdown too, for tools that genuinely emit
|
|
130
|
+
* it (#210's `ctx_execute`), accepting the rewrites above on ones that don't.
|
|
131
|
+
*/
|
|
132
|
+
export type ViewerMarkdownMode = 'off' | 'assistant' | 'all';
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* How `@handle message` starts an agent that is not already running.
|
|
136
|
+
* - `model`: inject Claude Code's `agent_mention` reminder and let the main
|
|
137
|
+
* model spawn it with the `Agent` tool, which is what Claude Code does.
|
|
138
|
+
* - `direct`: spawn it here, immediately, with the typed message as its prompt
|
|
139
|
+
* and no main-model turn spent.
|
|
140
|
+
* - `off`: `@` means only "attach a file" again.
|
|
141
|
+
*
|
|
142
|
+
* Messaging a running agent and resuming a finished one are direct in every
|
|
143
|
+
* mode — Claude Code only differs from us on the *new* invocation.
|
|
144
|
+
*/
|
|
145
|
+
export type AgentMentionMode = 'model' | 'direct' | 'off';
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* What survives a record's eviction so `@handle` keeps working. The live record
|
|
149
|
+
* is discarded after ~10 minutes, but the pi session it wrote is still on disk,
|
|
150
|
+
* and this is the little that is needed to find and describe it again.
|
|
151
|
+
*/
|
|
152
|
+
export interface AgentTombstone {
|
|
153
|
+
handle: string;
|
|
154
|
+
alias?: string;
|
|
155
|
+
id: string;
|
|
156
|
+
type: SubagentType;
|
|
157
|
+
description: string;
|
|
158
|
+
/** Always set — a record with no session file is never tombstoned. */
|
|
159
|
+
sessionFile: string;
|
|
160
|
+
completedAt: number;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* What `@handle` resolved to: an agent still in memory, or the remains of one
|
|
165
|
+
* whose conversation can be reopened from disk.
|
|
166
|
+
*/
|
|
167
|
+
export type MentionResolution =
|
|
168
|
+
| { kind: "live"; record: AgentRecord }
|
|
169
|
+
| { kind: "tombstone"; entry: AgentTombstone };
|
|
170
|
+
|
|
171
|
+
export interface AgentRecord {
|
|
172
|
+
id: string;
|
|
173
|
+
type: SubagentType;
|
|
174
|
+
/**
|
|
175
|
+
* Typeable name for the `@handle message` prompt mention, derived from the
|
|
176
|
+
* agent type and numbered when siblings collide (`explore`, `explore-2`).
|
|
177
|
+
* Top-level agents only — nested children are hidden from every top-level
|
|
178
|
+
* surface, so nothing can address them.
|
|
179
|
+
*/
|
|
180
|
+
handle?: string;
|
|
181
|
+
/**
|
|
182
|
+
* A second, memorable handle from the spawner's `name` (`@auth-audit`), drawn
|
|
183
|
+
* from the same namespace as `handle` so the two can never collide. Purely
|
|
184
|
+
* additive: `handle` is assigned regardless, so a named agent stays reachable
|
|
185
|
+
* by its type and `@explore` never comes to mean "start another one".
|
|
186
|
+
*/
|
|
187
|
+
alias?: string;
|
|
188
|
+
description: string;
|
|
189
|
+
status: "queued" | "running" | "completed" | "steered" | "aborted" | "stopped" | "error";
|
|
190
|
+
result?: string;
|
|
191
|
+
error?: string;
|
|
192
|
+
toolUses: number;
|
|
193
|
+
startedAt: number;
|
|
194
|
+
completedAt?: number;
|
|
195
|
+
session?: AgentSession;
|
|
196
|
+
abortController?: AbortController;
|
|
197
|
+
promise?: Promise<string>;
|
|
198
|
+
/**
|
|
199
|
+
* A caller is awaiting this agent inline (`spawnAndWait`) — what
|
|
200
|
+
* `maxConcurrentForeground` bounds. Distinct from `isBackground === false`,
|
|
201
|
+
* which says only that the agent has an inline result surface: a detached
|
|
202
|
+
* cross-extension RPC spawn is foreground by that measure and yet blocks
|
|
203
|
+
* nobody, so it takes no slot.
|
|
204
|
+
*/
|
|
205
|
+
blocking?: boolean;
|
|
206
|
+
/**
|
|
207
|
+
* Present only while the record is "queued": resolves when it leaves the
|
|
208
|
+
* queue, started or aborted. `spawnAndWait` waits on this because a queued
|
|
209
|
+
* record has no `promise` yet. Always resolves, never rejects — a rejection
|
|
210
|
+
* would escape into the caller's tool `execute` and take down pi's whole
|
|
211
|
+
* Promise.all tool batch.
|
|
212
|
+
*/
|
|
213
|
+
startGate?: Promise<void>;
|
|
214
|
+
groupId?: string;
|
|
215
|
+
joinMode?: JoinMode;
|
|
216
|
+
/**
|
|
217
|
+
* Run identity within one record: incremented once when a resume starts a new
|
|
218
|
+
* run. Completions, group holds and held nudges captured under an older
|
|
219
|
+
* generation are superseded and must not deliver against this run.
|
|
220
|
+
* Undefined (0) is the initial run.
|
|
221
|
+
*/
|
|
222
|
+
runGeneration?: number;
|
|
223
|
+
/** Set when result was already consumed via get_subagent_result — suppresses completion notification. */
|
|
224
|
+
resultConsumed?: boolean;
|
|
225
|
+
/** Steering messages queued before the session was ready. */
|
|
226
|
+
pendingSteers?: string[];
|
|
227
|
+
/**
|
|
228
|
+
* Steering messages still queued in the child session when its run ended.
|
|
229
|
+
* They are discarded at completion (so a later resume cannot replay stale
|
|
230
|
+
* instructions) and counted here so the result can say so.
|
|
231
|
+
*/
|
|
232
|
+
droppedSteers?: number;
|
|
233
|
+
/** Worktree info if the agent is running in an isolated worktree. */
|
|
234
|
+
worktree?: { path: string; branch: string; baseSha: string; workPath: string };
|
|
235
|
+
/** Worktree cleanup result after agent completion. */
|
|
236
|
+
worktreeResult?: { hasChanges: boolean; branch?: string };
|
|
237
|
+
/** The tool_use_id from the original Agent tool call. */
|
|
238
|
+
toolCallId?: string;
|
|
239
|
+
/** Path to the streaming output transcript file. */
|
|
240
|
+
outputFile?: string;
|
|
241
|
+
/**
|
|
242
|
+
* Every ancestor agent that owns this record, nearest first, captured at
|
|
243
|
+
* spawn time from the live parent chain.
|
|
244
|
+
*
|
|
245
|
+
* This exists so ownership survives the eviction of an intermediate parent:
|
|
246
|
+
* a grandchild archived after Parent2 is gone still names Parent1, which is
|
|
247
|
+
* what an active cleanup uses to protect the descendant's files. A workflow
|
|
248
|
+
* owner stays on `workflowId`; this list is the agent lineage only.
|
|
249
|
+
*/
|
|
250
|
+
ownerIds?: string[];
|
|
251
|
+
/**
|
|
252
|
+
* The agent's pi session file, when it was persisted (`persist_session`, or
|
|
253
|
+
* the `rememberAgents` default). Captured so a mention can reopen the
|
|
254
|
+
* conversation after the record itself has been evicted; undefined for an
|
|
255
|
+
* in-memory session, which leaves nothing to reopen.
|
|
256
|
+
*/
|
|
257
|
+
sessionFile?: string;
|
|
258
|
+
/** Cleanup function for the output file stream subscription. */
|
|
259
|
+
/** Detaches the transcript stream; resolves once its final flush is on disk (awaited at settle). */
|
|
260
|
+
outputCleanup?: () => void | Promise<void>;
|
|
261
|
+
/**
|
|
262
|
+
* Lifetime usage breakdown, accumulated via `message_end` events. Survives
|
|
263
|
+
* compaction. Total = input + output + cacheWrite (cacheRead deliberately
|
|
264
|
+
* excluded — see issue #38). Initialized to zeros at spawn.
|
|
265
|
+
*/
|
|
266
|
+
lifetimeUsage: LifetimeUsage;
|
|
267
|
+
/** Number of times this agent's session has compacted. Initialized to 0 at spawn. */
|
|
268
|
+
compactionCount: number;
|
|
269
|
+
/** Latest child-local advisor snapshot; absent means telemetry is unavailable. */
|
|
270
|
+
advisorStatus?: AdvisorStatus;
|
|
271
|
+
/**
|
|
272
|
+
* Whether this agent was spawned to run in the background. Tri-state, set at
|
|
273
|
+
* spawn from `SpawnOptions.isBackground`: `true` = background, `false` =
|
|
274
|
+
* foreground (has an inline Agent tool-result surface), `undefined` = the
|
|
275
|
+
* caller never declared it (e.g. a cross-extension RPC spawn, which is detached
|
|
276
|
+
* and has no inline surface). The widget's background-only filter keys off this
|
|
277
|
+
* — and excludes only explicit `false`, so `undefined` agents stay visible.
|
|
278
|
+
* Reliable across ALL spawn paths, unlike the UI-only `invocation` snapshot,
|
|
279
|
+
* which only the Agent-tool path populates.
|
|
280
|
+
*/
|
|
281
|
+
isBackground?: boolean;
|
|
282
|
+
/** Resolved spawn params, captured for UI display. Fixed at spawn time. */
|
|
283
|
+
invocation?: AgentInvocation;
|
|
284
|
+
/** Nesting depth: top-level subagent = 1. */
|
|
285
|
+
depth?: number;
|
|
286
|
+
/**
|
|
287
|
+
* The validated `StructuredOutput` payload, as canonical JSON.
|
|
288
|
+
*
|
|
289
|
+
* Set only when the spawn asked for a schema. Separate from `result` because
|
|
290
|
+
* `result` is prose for a reader — previewed in the widget, written to the
|
|
291
|
+
* transcript, and appended to with the worktree branch note — and JSON that
|
|
292
|
+
* has been appended to no longer parses.
|
|
293
|
+
*/
|
|
294
|
+
structuredJson?: string;
|
|
295
|
+
/** Whether the child needed the extra structured-output prompt. */
|
|
296
|
+
structuredRetried?: boolean;
|
|
297
|
+
/** Parent agent ID for ownership-scoped nested controls. */
|
|
298
|
+
parentAgentId?: string;
|
|
299
|
+
/**
|
|
300
|
+
* The workflow run that owns this child, when a workflow spawned it.
|
|
301
|
+
*
|
|
302
|
+
* Owned the same way a nested child is owned by its parent: filtered out of
|
|
303
|
+
* every top-level surface, and outside the `maxConcurrent` pool. See
|
|
304
|
+
* `isTopLevelAgent`.
|
|
305
|
+
*/
|
|
306
|
+
workflowId?: string;
|
|
307
|
+
/** Effective inherited nesting cap for this branch. */
|
|
308
|
+
maxSubagentDepth?: number;
|
|
309
|
+
/**
|
|
310
|
+
* Session id of the root (main) session this branch descends from. Nested
|
|
311
|
+
* spawns inherit it so their transcripts file under the same session
|
|
312
|
+
* directory as their ancestors' instead of the child session's own id.
|
|
313
|
+
*
|
|
314
|
+
* Also pinned for spawns that enter outside the Agent tool (mentions,
|
|
315
|
+
* schedules, RPC) from the session context that started them, so child
|
|
316
|
+
* sessions and their archived provenance share one stable root.
|
|
317
|
+
*/
|
|
318
|
+
rootSessionId?: string;
|
|
319
|
+
/** Stable root project directory; never a worktree copy's cwd. */
|
|
320
|
+
rootCwd?: string;
|
|
321
|
+
/** The root session's pi JSONL file, when it has one. */
|
|
322
|
+
rootSessionFile?: string;
|
|
323
|
+
/** The child session id, once a session exists. Plain string, never a session. */
|
|
324
|
+
sessionId?: string;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
/** Actual session level after SDK model-capability clamping. */
|
|
328
|
+
export type EffectiveThinkingLevel = ThinkingLevel;
|
|
329
|
+
|
|
330
|
+
export interface AgentInvocation {
|
|
331
|
+
/** Short display name for tight rows, e.g. "haiku 4.5". Always set once known. */
|
|
332
|
+
modelName?: string;
|
|
333
|
+
/** Canonical `provider/id`, for surfaces with room to disambiguate providers. */
|
|
334
|
+
modelId?: string;
|
|
335
|
+
/** The level actually in effect, once a session exists to report one. */
|
|
336
|
+
thinking?: EffectiveThinkingLevel;
|
|
337
|
+
/**
|
|
338
|
+
* What the caller asked for, kept only when they did not get it — pi clamped
|
|
339
|
+
* the level to the model's capabilities, or an agent file's frontmatter
|
|
340
|
+
* outranked the parameter (#182). The snapshot exists to answer "did the spawn
|
|
341
|
+
* honor my instructions?" (#62), which it cannot do if the request is lost, so
|
|
342
|
+
* neither `requested*` field is overwritten once set.
|
|
343
|
+
*/
|
|
344
|
+
requestedThinking?: EffectiveThinkingLevel;
|
|
345
|
+
/** The caller's `model` parameter, as written, when an agent file's pin won. */
|
|
346
|
+
requestedModel?: string;
|
|
347
|
+
maxTurns?: number;
|
|
348
|
+
isolated?: boolean;
|
|
349
|
+
inheritContext?: boolean;
|
|
350
|
+
runInBackground?: boolean;
|
|
351
|
+
isolation?: IsolationMode;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/** Details attached to custom notification messages for visual rendering. */
|
|
355
|
+
export interface NotificationDetails {
|
|
356
|
+
id: string;
|
|
357
|
+
description: string;
|
|
358
|
+
status: string;
|
|
359
|
+
toolUses: number;
|
|
360
|
+
turnCount: number;
|
|
361
|
+
maxTurns?: number;
|
|
362
|
+
totalTokens: number;
|
|
363
|
+
/**
|
|
364
|
+
* Estimated cost in USD, from pi's per-message `usage.cost.total`. Always
|
|
365
|
+
* populated (0 when the model has no pricing); the renderer decides whether
|
|
366
|
+
* to show it, per the `showCost` setting.
|
|
367
|
+
*/
|
|
368
|
+
totalCost?: number;
|
|
369
|
+
durationMs: number;
|
|
370
|
+
outputFile?: string;
|
|
371
|
+
error?: string;
|
|
372
|
+
resultPreview: string;
|
|
373
|
+
/** Additional agents in a group notification. */
|
|
374
|
+
others?: NotificationDetails[];
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
export interface EnvInfo {
|
|
378
|
+
isGitRepo: boolean;
|
|
379
|
+
branch: string;
|
|
380
|
+
platform: string;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
/**
|
|
384
|
+
* A subagent spawn registered to fire on a schedule.
|
|
385
|
+
*
|
|
386
|
+
* Stored at `<cwd>/.pi/subagent-schedules/<sessionId>.json`. Session-scoped:
|
|
387
|
+
* survives `/resume` but resets on `/new`, mirroring pi-chonky-tasks.
|
|
388
|
+
*/
|
|
389
|
+
export interface ScheduledSubagent {
|
|
390
|
+
id: string;
|
|
391
|
+
/** Unique within store. Defaults to `description`. */
|
|
392
|
+
name: string;
|
|
393
|
+
description: string;
|
|
394
|
+
/** Raw user input — cron expr | "+10m" | ISO | "5m". */
|
|
395
|
+
schedule: string;
|
|
396
|
+
scheduleType: "cron" | "once" | "interval";
|
|
397
|
+
/** Computed at create time for interval/once. */
|
|
398
|
+
intervalMs?: number;
|
|
399
|
+
|
|
400
|
+
// spawn params (subset of Agent tool params; no inherit_context, no resume)
|
|
401
|
+
subagent_type: SubagentType;
|
|
402
|
+
prompt: string;
|
|
403
|
+
model?: string;
|
|
404
|
+
thinking?: ThinkingLevel;
|
|
405
|
+
max_turns?: number;
|
|
406
|
+
isolated?: boolean;
|
|
407
|
+
isolation?: IsolationMode;
|
|
408
|
+
|
|
409
|
+
// state
|
|
410
|
+
enabled: boolean;
|
|
411
|
+
/** ISO timestamp. */
|
|
412
|
+
createdAt: string;
|
|
413
|
+
lastRun?: string;
|
|
414
|
+
lastStatus?: "success" | "error" | "running";
|
|
415
|
+
/** Refreshed on every fire and on store load. */
|
|
416
|
+
nextRun?: string;
|
|
417
|
+
runCount: number;
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
export interface ScheduleStoreData {
|
|
421
|
+
/** For future migrations. */
|
|
422
|
+
version: 1;
|
|
423
|
+
jobs: ScheduledSubagent[];
|
|
424
|
+
}
|