pi-subagents 0.84.0 → 0.86.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 +83 -0
- package/bundle/agents.js +3 -3
- package/bundle/child-tool-plan.js +2 -2
- package/bundle/{chunk-JG4QKI5M.js → chunk-2IYBCYFU.js} +214 -97
- package/bundle/{chunk-V2BZYLEP.js → chunk-374MZFF4.js} +7 -2
- package/bundle/{chunk-4E7BKDTX.js → chunk-3RKFH2UZ.js} +11 -156
- package/bundle/{chunk-F4ASL6OV.js → chunk-5H4BICQZ.js} +1 -1
- package/bundle/{chunk-PALJGGYC.js → chunk-6VD7BGIC.js} +6 -3
- package/bundle/{chunk-C5P5CHYK.js → chunk-77ASNIEM.js} +1 -1
- package/bundle/{chunk-XDQORLZ5.js → chunk-7ADDXUGF.js} +15 -6
- package/bundle/{chunk-PV63UFUR.js → chunk-7QA7ZA46.js} +183 -28
- package/bundle/{chunk-NKQ6JNAS.js → chunk-7ZUFN6ME.js} +2 -1
- package/bundle/{chunk-SSG7IEP5.js → chunk-A637IMAO.js} +2 -2
- package/bundle/{chunk-L3WFKBEI.js → chunk-BGXEAYUM.js} +247 -153
- package/bundle/{chunk-J5YL7LYR.js → chunk-BU6PFPVX.js} +59 -27
- package/bundle/{chunk-DZDETGRJ.js → chunk-BWC2LVII.js} +259 -216
- package/bundle/{chunk-CGN2TVE7.js → chunk-GJGTMLPE.js} +322 -18
- package/bundle/{chunk-D3JAFGMO.js → chunk-GRJHIXYF.js} +1 -1
- package/bundle/chunk-HXRB42AF.js +108 -0
- package/bundle/{chunk-LFDBD4PW.js → chunk-LGINOOY5.js} +2 -2
- package/bundle/{chunk-G2Z6ZH26.js → chunk-NAFLUJ26.js} +1 -1
- package/bundle/{chunk-235AWJUQ.js → chunk-O3YH7XIY.js} +324 -111
- package/bundle/{chunk-2DHZTCOL.js → chunk-PYOAIN3V.js} +2 -2
- package/bundle/{chunk-LNRJCP2Y.js → chunk-QGO6HXHG.js} +417 -242
- package/bundle/{chunk-VQVVHSY6.js → chunk-QM3JGE4W.js} +22 -11
- package/bundle/{chunk-2S4K53MV.js → chunk-S2Q75LP3.js} +1 -1
- package/bundle/{chunk-NENDSQUY.js → chunk-UR7OW5S7.js} +9 -6
- package/bundle/{chunk-AKOIVLA5.js → chunk-WN2E5XHN.js} +135 -77
- package/bundle/{chunk-2D52JFLF.js → chunk-YK3QYNLE.js} +41 -117
- package/bundle/{chunk-7BWGNDNK.js → chunk-ZJJCPV3L.js} +190 -1177
- package/bundle/chunk-ZPY5QZCS.js +1067 -0
- package/bundle/control-channel.js +2 -2
- package/bundle/index.js +1 -1
- package/bundle/intercom-bridge.js +2 -2
- package/bundle/preflight.js +8 -8
- package/bundle/project-panes.js +3 -3
- package/docs/agents.md +23 -2
- package/docs/configuration.md +4 -4
- package/docs/extension-api.md +16 -1
- package/docs/tool-reference.md +2 -0
- package/docs/workflows.md +30 -2
- package/package.json +1 -1
- package/src/agents/agent-management.js +27 -11
- package/src/agents/agent-memory.d.ts +1 -4
- package/src/agents/agent-memory.js +1 -4
- package/src/agents/agents.d.ts +1 -3
- package/src/agents/agents.js +7 -6
- package/src/agents/frontmatter.js +1 -8
- package/src/agents/global-npm-root.d.ts +1 -0
- package/src/agents/global-npm-root.js +11 -3
- package/src/agents/skills.d.ts +0 -3
- package/src/agents/skills.js +0 -3
- package/src/extension/config.js +7 -1
- package/src/extension/herdr-pi-bridge.js +10 -2
- package/src/extension/index.d.ts +0 -13
- package/src/extension/index.js +43 -32
- package/src/extension/public-execution.d.ts +1 -0
- package/src/extension/public-execution.js +4 -0
- package/src/extension/reply-workflow-script.js +24 -4
- package/src/extension/schemas.d.ts +8 -3
- package/src/extension/schemas.js +5 -3
- package/src/extension/session-switch.d.ts +25 -0
- package/src/extension/session-switch.js +138 -0
- package/src/extension/subagent-guide.d.ts +1 -1
- package/src/extension/subagent-guide.js +1 -1
- package/src/extension/subagent-launch-tool.d.ts +25 -0
- package/src/extension/subagent-launch-tool.js +48 -0
- package/src/extension/tool-activation.js +35 -12
- package/src/extension/tool-description.d.ts +1 -1
- package/src/extension/tool-description.js +14 -8
- package/src/inspectors/herdr/actions.d.ts +0 -1
- package/src/inspectors/herdr/actions.js +0 -1
- package/src/inspectors/session-roots-codec.d.ts +0 -1
- package/src/inspectors/session-roots-codec.js +0 -1
- package/src/inspectors/tmux/actions.d.ts +0 -1
- package/src/inspectors/tmux/actions.js +0 -1
- package/src/integrations/herdr-status.js +3 -8
- package/src/intercom/native-supervisor-channel.js +65 -9
- package/src/runs/background/async-execution.d.ts +5 -9
- package/src/runs/background/async-execution.js +62 -27
- package/src/runs/background/async-job-tracker.js +12 -0
- package/src/runs/background/async-resume.d.ts +2 -1
- package/src/runs/background/async-resume.js +112 -39
- package/src/runs/background/async-retention.js +6 -1
- package/src/runs/background/auto-drain.js +2 -1
- package/src/runs/background/boot-id.d.ts +1 -3
- package/src/runs/background/boot-id.js +1 -3
- package/src/runs/background/completion-batcher.d.ts +3 -4
- package/src/runs/background/completion-batcher.js +2 -3
- package/src/runs/background/control-channel.d.ts +0 -6
- package/src/runs/background/control-channel.js +0 -6
- package/src/runs/background/fleet-view.js +2 -3
- package/src/runs/background/notify.d.ts +0 -2
- package/src/runs/background/notify.js +0 -2
- package/src/runs/background/result-watcher.d.ts +1 -0
- package/src/runs/background/result-watcher.js +59 -29
- package/src/runs/background/resume-guidance.js +4 -2
- package/src/runs/background/retained-children.js +2 -1
- package/src/runs/background/run-child-session.d.ts +0 -1
- package/src/runs/background/run-child-session.js +1 -1
- package/src/runs/background/run-status.js +9 -7
- package/src/runs/background/scheduled-runs.d.ts +3 -1
- package/src/runs/background/scheduled-runs.js +13 -16
- package/src/runs/background/subagent-runner.d.ts +2 -4
- package/src/runs/background/subagent-runner.js +15 -12
- package/src/runs/background/subagent-wait.js +12 -15
- package/src/runs/background/wait-config.d.ts +2 -0
- package/src/runs/background/wait-config.js +17 -3
- package/src/runs/background/wait-tool.js +4 -2
- package/src/runs/background/workflow-terminal-proof.d.ts +0 -1
- package/src/runs/background/workflow-terminal-proof.js +0 -1
- package/src/runs/foreground/execution.d.ts +0 -3
- package/src/runs/foreground/execution.js +17 -9
- package/src/runs/foreground/subagent-executor.d.ts +3 -2
- package/src/runs/foreground/subagent-executor.js +107 -26
- package/src/runs/shared/acceptance.js +69 -26
- package/src/runs/shared/child-commands.js +15 -2
- package/src/runs/shared/child-hooks.d.ts +1 -7
- package/src/runs/shared/child-hooks.js +13 -5
- package/src/runs/shared/child-launch.js +6 -2
- package/src/runs/shared/child-runtime-config.d.ts +0 -1
- package/src/runs/shared/child-session.d.ts +1 -1
- package/src/runs/shared/child-session.js +21 -2
- package/src/runs/shared/child-tool-plan.d.ts +0 -1
- package/src/runs/shared/child-tool-plan.js +0 -1
- package/src/runs/shared/claude-code-adapter.js +11 -0
- package/src/runs/shared/external-cli-contract.d.ts +49 -0
- package/src/runs/shared/external-cli-contract.js +18 -13
- package/src/runs/shared/external-cli-runner.js +26 -6
- package/src/runs/shared/herdr-connection.js +2 -1
- package/src/runs/shared/herdr-pane-host.d.ts +2 -2
- package/src/runs/shared/herdr-pane-host.js +17 -1
- package/src/runs/shared/herdr-placed-run.js +48 -22
- package/src/runs/shared/lane-metadata.d.ts +0 -1
- package/src/runs/shared/lane-metadata.js +0 -1
- package/src/runs/shared/mcp-direct-tool-grant.js +8 -1
- package/src/runs/shared/model-resolution-diagnostic.d.ts +0 -1
- package/src/runs/shared/model-resolution.d.ts +2 -2
- package/src/runs/shared/model-resolution.js +7 -1
- package/src/runs/shared/model-scope.d.ts +1 -5
- package/src/runs/shared/model-scope.js +1 -5
- package/src/runs/shared/mutation-evidence.d.ts +1 -1
- package/src/runs/shared/mutation-evidence.js +52 -7
- package/src/runs/shared/nested-events.d.ts +1 -0
- package/src/runs/shared/nested-events.js +1 -1
- package/src/runs/shared/parallel-utils.d.ts +0 -1
- package/src/runs/shared/permissions.js +5 -3
- package/src/runs/shared/placement-host.d.ts +5 -1
- package/src/runs/shared/rex-pane-host.d.ts +0 -1
- package/src/runs/shared/rex-pane-host.js +0 -2
- package/src/runs/shared/run-launch-folder.d.ts +12 -0
- package/src/runs/shared/run-launch-folder.js +21 -0
- package/src/runs/shared/runner-launcher.d.ts +12 -1
- package/src/runs/shared/runner-launcher.js +16 -0
- package/src/runs/shared/single-output.d.ts +3 -3
- package/src/runs/shared/single-output.js +5 -3
- package/src/runs/shared/structured-output.d.ts +8 -0
- package/src/runs/shared/structured-output.js +40 -5
- package/src/runs/shared/subagent-prompt-runtime.d.ts +0 -1
- package/src/runs/shared/subagent-prompt-runtime.js +4 -2
- package/src/runs/shared/tool-timeout.js +2 -1
- package/src/runs/shared/worktree-cleanup-plan.d.ts +0 -1
- package/src/runs/shared/worktree-cleanup-plan.js +0 -1
- package/src/runs/shared/worktree.d.ts +3 -0
- package/src/runs/shared/worktree.js +20 -0
- package/src/shared/capacity-resilient-json.d.ts +1 -1
- package/src/shared/child-cache-retention.d.ts +1 -2
- package/src/shared/child-cache-retention.js +1 -2
- package/src/shared/fleet-transcript-reader.d.ts +51 -0
- package/src/shared/fleet-transcript-reader.js +333 -0
- package/src/shared/formatters.d.ts +0 -18
- package/src/shared/formatters.js +0 -18
- package/src/shared/session-succession.d.ts +16 -1
- package/src/shared/session-succession.js +41 -2
- package/src/shared/session-warnings.d.ts +7 -0
- package/src/shared/session-warnings.js +26 -0
- package/src/shared/settings.d.ts +0 -23
- package/src/shared/settings.js +3 -35
- package/src/shared/types.d.ts +85 -59
- package/src/shared/types.js +0 -12
- package/src/shared/utils.d.ts +0 -14
- package/src/shared/utils.js +0 -22
- package/src/shared/wait-tool-name.d.ts +8 -0
- package/src/shared/wait-tool-name.js +13 -0
- package/src/slash/slash-commands.js +2 -1
- package/src/slash/subagent-cost.d.ts +3 -2
- package/src/slash/subagent-cost.js +22 -3
- package/src/slash/subagents-admin.js +0 -1
- package/src/tui/fleet-status.d.ts +0 -5
- package/src/tui/fleet-status.js +4 -24
- package/src/tui/fleet-transcript.d.ts +1 -44
- package/src/tui/fleet-transcript.js +1 -327
- package/src/tui/fleet.js +6 -4
- package/src/tui/render.d.ts +0 -9
- package/src/tui/render.js +161 -66
- package/src/tui/subagent-messages.js +3 -2
- package/src/watchdog/register-child.d.ts +2 -3
- package/src/watchdog/register-child.js +2 -3
- package/src/watchdog/turn-delta.js +2 -1
- package/src/workflows/scripted-workflow.js +241 -20
- package/src/workflows/workflow-launch-record.d.ts +15 -6
- package/src/workflows/workflow-launch-record.js +30 -12
- package/src/workflows/workflow-receipt.js +36 -53
- package/src/workflows/workflow-resume-claim.js +2 -2
- package/src/workflows/workflow-resume.d.ts +1 -1
- package/src/workflows/workflow-resume.js +11 -8
- package/src/workflows/workflow-script-worker.d.ts +13 -0
- package/src/workflows/workflow-script-worker.js +79 -0
- package/workflow-script-process.cjs +36 -0
- package/workflow-script-worker.cjs +4 -1
package/src/shared/settings.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Chain behavior, template resolution, and directory management
|
|
3
|
-
*/
|
|
4
1
|
import * as fs from "node:fs";
|
|
5
2
|
import * as os from "node:os";
|
|
6
3
|
import * as path from "node:path";
|
|
@@ -8,19 +5,15 @@ import { discoverAgents, formatUnknownAgentError, unknownAgentDiagnosticContext
|
|
|
8
5
|
import { normalizeSkillInput } from "../agents/skills.js";
|
|
9
6
|
import { normalizeOutputOverride } from "../runs/shared/child-launch-plan.js";
|
|
10
7
|
import { CHAIN_RUNS_DIR } from "./types.js";
|
|
11
|
-
const CHAIN_DIR_MAX_AGE_MS = 24 * 60 * 60 * 1000;
|
|
8
|
+
const CHAIN_DIR_MAX_AGE_MS = 24 * 60 * 60 * 1000;
|
|
12
9
|
const INITIAL_PROGRESS_CONTENT = "# Progress\n\n## Status\nIn Progress\n\n## Tasks\n\n## Files Changed\n\n## Notes\n";
|
|
13
10
|
export { planChildLaunch, resolveStepBehavior, resolveTaskTextForFileUpdatePolicy, suppressProgressForReadOnlyTask, taskDisallowsFileUpdates, } from "../runs/shared/child-launch-plan.js";
|
|
14
|
-
// =============================================================================
|
|
15
|
-
// Type Guards
|
|
16
|
-
// =============================================================================
|
|
17
11
|
export function isParallelStep(step) {
|
|
18
12
|
return "parallel" in step && Array.isArray(step.parallel);
|
|
19
13
|
}
|
|
20
14
|
export function isDynamicParallelStep(step) {
|
|
21
15
|
return "expand" in step && "collect" in step && "parallel" in step && !Array.isArray(step.parallel);
|
|
22
16
|
}
|
|
23
|
-
/** Get all agent names in a step (single for sequential, multiple for parallel) */
|
|
24
17
|
export function getStepAgents(step) {
|
|
25
18
|
if (isParallelStep(step)) {
|
|
26
19
|
return step.parallel.map((t) => t.agent);
|
|
@@ -30,9 +23,6 @@ export function getStepAgents(step) {
|
|
|
30
23
|
}
|
|
31
24
|
return [step.agent];
|
|
32
25
|
}
|
|
33
|
-
// =============================================================================
|
|
34
|
-
// Chain Directory Management
|
|
35
|
-
// =============================================================================
|
|
36
26
|
export function createChainDir(runId, baseDir) {
|
|
37
27
|
const chainDir = path.join(baseDir ? path.resolve(baseDir) : CHAIN_RUNS_DIR, runId);
|
|
38
28
|
fs.mkdirSync(chainDir, { recursive: true });
|
|
@@ -72,35 +62,24 @@ export function cleanupOldChainDirs() {
|
|
|
72
62
|
}
|
|
73
63
|
}
|
|
74
64
|
}
|
|
75
|
-
/**
|
|
76
|
-
* Resolve templates for a chain with parallel step support.
|
|
77
|
-
* Returns string for sequential steps, string[] for parallel steps.
|
|
78
|
-
*/
|
|
79
65
|
export function resolveChainTemplates(steps) {
|
|
80
66
|
return steps.map((step, i) => {
|
|
81
67
|
if (isParallelStep(step)) {
|
|
82
|
-
// Parallel step: resolve each task's template
|
|
83
68
|
return step.parallel.map((task) => {
|
|
84
69
|
if (task.task)
|
|
85
70
|
return task.task;
|
|
86
|
-
// Default for parallel tasks is {previous}
|
|
87
71
|
return "{previous}";
|
|
88
72
|
});
|
|
89
73
|
}
|
|
90
74
|
if (isDynamicParallelStep(step)) {
|
|
91
75
|
return step.parallel.task ?? "{previous}";
|
|
92
76
|
}
|
|
93
|
-
// Sequential step: existing logic
|
|
94
77
|
const seq = step;
|
|
95
78
|
if (seq.task)
|
|
96
79
|
return seq.task;
|
|
97
|
-
// Default: first step uses {task}, others use {previous}
|
|
98
80
|
return i === 0 ? "{task}" : "{previous}";
|
|
99
81
|
});
|
|
100
82
|
}
|
|
101
|
-
// =============================================================================
|
|
102
|
-
// Chain Instruction Injection
|
|
103
|
-
// =============================================================================
|
|
104
83
|
/**
|
|
105
84
|
* Expand a leading `~`/`~/` to the user's home directory. Other forms (relative,
|
|
106
85
|
* absolute, `~user/`) pass through unchanged.
|
|
@@ -130,10 +109,6 @@ export function resolveExistingReadInstructionPaths(reads, instructionCwd, exist
|
|
|
130
109
|
export function resolveExistingReadPaths(reads, cwd) {
|
|
131
110
|
return resolveExistingReadInstructionPaths(reads, cwd);
|
|
132
111
|
}
|
|
133
|
-
/**
|
|
134
|
-
* Build chain instructions from resolved behavior.
|
|
135
|
-
* These are appended to the task to tell the agent what to read/write.
|
|
136
|
-
*/
|
|
137
112
|
export function writeInitialProgressFile(progressDir) {
|
|
138
113
|
fs.mkdirSync(progressDir, { recursive: true });
|
|
139
114
|
fs.writeFileSync(path.join(progressDir, "progress.md"), INITIAL_PROGRESS_CONTENT);
|
|
@@ -162,7 +137,6 @@ export function buildChainInstructions(behavior, chainDir, isFirstProgressAgent,
|
|
|
162
137
|
suffixParts.push(`Update progress at: ${progressPath}`);
|
|
163
138
|
}
|
|
164
139
|
}
|
|
165
|
-
// Include previous step's summary in suffix if available
|
|
166
140
|
if (previousSummary && previousSummary.trim()) {
|
|
167
141
|
suffixParts.push(`Previous step output:\n${previousSummary.trim()}`);
|
|
168
142
|
}
|
|
@@ -185,7 +159,6 @@ export function resolveParallelBehaviors(tasks, agentConfigs, stepIndex, chainSk
|
|
|
185
159
|
: unknownAgentDiagnosticContext(discoverAgents(path.resolve(diagnostics.cwd), diagnostics.scope ?? "both"));
|
|
186
160
|
throw new Error(formatUnknownAgentError(task.agent, context));
|
|
187
161
|
}
|
|
188
|
-
// Build subdirectory path for this parallel task
|
|
189
162
|
const subdir = path.join(`parallel-${stepIndex}`, `${taskIndex}-${task.agent}`);
|
|
190
163
|
// Output: task override > agent default (namespaced) > false
|
|
191
164
|
// Absolute paths pass through unchanged; relative paths get namespaced under subdir
|
|
@@ -197,19 +170,17 @@ export function resolveParallelBehaviors(tasks, agentConfigs, stepIndex, chainSk
|
|
|
197
170
|
output = false;
|
|
198
171
|
}
|
|
199
172
|
else if (path.isAbsolute(taskOutput)) {
|
|
200
|
-
output = taskOutput;
|
|
173
|
+
output = taskOutput;
|
|
201
174
|
}
|
|
202
175
|
else {
|
|
203
|
-
output = path.join(subdir, taskOutput);
|
|
176
|
+
output = path.join(subdir, taskOutput);
|
|
204
177
|
}
|
|
205
178
|
}
|
|
206
179
|
else if (configOutput) {
|
|
207
180
|
// Agent defaults are always relative, so namespace them
|
|
208
181
|
output = path.join(subdir, configOutput);
|
|
209
182
|
}
|
|
210
|
-
// Reads: task override > agent default > false
|
|
211
183
|
const reads = task.reads !== undefined ? task.reads : config.defaultReads ?? false;
|
|
212
|
-
// Progress: task override > agent default > false
|
|
213
184
|
const progress = task.progress !== undefined
|
|
214
185
|
? task.progress
|
|
215
186
|
: config.defaultProgress ?? false;
|
|
@@ -235,9 +206,6 @@ export function resolveParallelBehaviors(tasks, agentConfigs, stepIndex, chainSk
|
|
|
235
206
|
return { output, outputMode, reads, progress, skills, model };
|
|
236
207
|
});
|
|
237
208
|
}
|
|
238
|
-
/**
|
|
239
|
-
* Create subdirectories for parallel step outputs
|
|
240
|
-
*/
|
|
241
209
|
export function createParallelDirs(chainDir, stepIndex, taskCount, agentNames) {
|
|
242
210
|
for (let i = 0; i < taskCount; i++) {
|
|
243
211
|
const subdir = path.join(chainDir, `parallel-${stepIndex}`, `${i}-${agentNames[i]}`);
|
package/src/shared/types.d.ts
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Type definitions for the subagent extension
|
|
3
|
-
*/
|
|
4
1
|
import type { Message } from "@earendil-works/pi-ai";
|
|
5
2
|
import type { SubagentDelegationProviderDiagnostics } from "../api/delegation.ts";
|
|
6
3
|
import type { AgentConfig } from "../agents/agents.ts";
|
|
@@ -340,6 +337,8 @@ export interface WaitToolConfigObject {
|
|
|
340
337
|
enabled?: boolean;
|
|
341
338
|
/** Default blocking window for bg_wait calls that omit timeoutMs. */
|
|
342
339
|
defaultTimeoutMs?: number;
|
|
340
|
+
/** Registers the wait tool under this name instead of bg_wait, e.g. when another extension uses bg_wait. */
|
|
341
|
+
name?: string;
|
|
343
342
|
}
|
|
344
343
|
export type WaitToolConfig = boolean | WaitToolConfigObject;
|
|
345
344
|
export interface ControlEvent {
|
|
@@ -749,13 +748,29 @@ export interface SteeringRecoveryDescriptor {
|
|
|
749
748
|
requiredExtensions?: RequiredChildExtensionSnapshot;
|
|
750
749
|
runFanoutBudget: RunFanoutBudgetDescriptor;
|
|
751
750
|
sourceRunId: string;
|
|
751
|
+
/** The session that launched the run; only it, or a session that replaced it, may resume the run. */
|
|
752
|
+
sessionId?: string;
|
|
752
753
|
agentContract?: AgentContract;
|
|
753
754
|
agent: string;
|
|
754
755
|
sessionFile?: string;
|
|
756
|
+
/**
|
|
757
|
+
* The managed worktree the launch chose, so a resume never takes its cwd from the run's own
|
|
758
|
+
* handoff.json alone: the native cwd the parent computed, or the Worktrunk branch it requested.
|
|
759
|
+
*/
|
|
760
|
+
managedWorktree?: {
|
|
761
|
+
provider: "native";
|
|
762
|
+
cwd: string;
|
|
763
|
+
} | {
|
|
764
|
+
provider: "worktrunk";
|
|
765
|
+
branch: string;
|
|
766
|
+
};
|
|
755
767
|
/** Git ref used to allocate managed worktrees for this run. */
|
|
756
768
|
baseRef?: string;
|
|
757
|
-
/** Launcher name the run was wrapped with; resume re-reads its argv from current user config.
|
|
758
|
-
|
|
769
|
+
/** Launcher name the run was wrapped with, or null when it ran unwrapped; resume re-reads its argv from current user config.
|
|
770
|
+
* Absence (descriptors written before null was recorded) means unknown: resume uses the agent file's current launcher. */
|
|
771
|
+
launcher?: string | null;
|
|
772
|
+
/** The launcher and agent definition digest the launch required; a resume refuses unless both still hold. */
|
|
773
|
+
requiredLauncher?: RequiredRunnerLauncher;
|
|
759
774
|
cwd: string;
|
|
760
775
|
model?: string;
|
|
761
776
|
modelProvider?: string;
|
|
@@ -789,7 +804,6 @@ export interface SteeringRecoveryDescriptor {
|
|
|
789
804
|
structuredOutputSchema?: JsonSchemaObject;
|
|
790
805
|
acceptance?: AcceptanceInput;
|
|
791
806
|
controlConfig?: ResolvedControlConfig;
|
|
792
|
-
/** Resolved launch context for this async child. */
|
|
793
807
|
context?: "fresh" | "fork";
|
|
794
808
|
/** Raw per-run bridge override. Omitted descriptors continue to use global config. */
|
|
795
809
|
intercomBridge?: IntercomBridgeConfig;
|
|
@@ -1147,7 +1161,6 @@ export interface SingleResult {
|
|
|
1147
1161
|
/** Human-readable display name for the child's own session (agent + task
|
|
1148
1162
|
* excerpt), when the launcher derived one. Display metadata only. */
|
|
1149
1163
|
sessionName?: string;
|
|
1150
|
-
/** Resolved launch context for this child. */
|
|
1151
1164
|
context?: "fresh" | "fork";
|
|
1152
1165
|
exitCode: number;
|
|
1153
1166
|
processSignal?: string | null;
|
|
@@ -1247,7 +1260,6 @@ export interface WaitCompletionChild {
|
|
|
1247
1260
|
runId?: string;
|
|
1248
1261
|
/** Bounded accounting projection used by /subagent-cost after async completion. */
|
|
1249
1262
|
usage?: Usage;
|
|
1250
|
-
/** Persisted Pi child session when available. */
|
|
1251
1263
|
sessionFile?: string;
|
|
1252
1264
|
success?: boolean;
|
|
1253
1265
|
outputState?: SubagentOutputState;
|
|
@@ -1315,6 +1327,7 @@ export interface AgentCapabilityRow {
|
|
|
1315
1327
|
model?: {
|
|
1316
1328
|
value?: string;
|
|
1317
1329
|
thinking?: string | false;
|
|
1330
|
+
unavailable?: true;
|
|
1318
1331
|
};
|
|
1319
1332
|
execution?: {
|
|
1320
1333
|
defaultAsync?: boolean;
|
|
@@ -1721,54 +1734,9 @@ export interface ExternalCliReceiptMetadata {
|
|
|
1721
1734
|
};
|
|
1722
1735
|
capabilities: ExternalCliCapabilities;
|
|
1723
1736
|
machine?: ExternalCliMachineStatus;
|
|
1724
|
-
safety?:
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
ephemeral: true;
|
|
1728
|
-
} | {
|
|
1729
|
-
access: "workspace-write";
|
|
1730
|
-
sandbox: "workspace-write";
|
|
1731
|
-
approvalPolicy: "never";
|
|
1732
|
-
ephemeral: true;
|
|
1733
|
-
} | {
|
|
1734
|
-
permissionMode: "plan";
|
|
1735
|
-
tools: "none";
|
|
1736
|
-
mcp: "empty-strict";
|
|
1737
|
-
settingSources: "none";
|
|
1738
|
-
sessionPersistence: false;
|
|
1739
|
-
} | {
|
|
1740
|
-
access: "read-only";
|
|
1741
|
-
authentication: "existing-cli-required";
|
|
1742
|
-
permissionMode: "plan";
|
|
1743
|
-
tools: "none";
|
|
1744
|
-
mcp: "empty-strict";
|
|
1745
|
-
settingSources: "user";
|
|
1746
|
-
userSettingsTrust: "required";
|
|
1747
|
-
sessionPersistence: false;
|
|
1748
|
-
} | {
|
|
1749
|
-
access: "workspace-write";
|
|
1750
|
-
authentication: "existing-cli-required";
|
|
1751
|
-
permissionMode: "acceptEdits";
|
|
1752
|
-
tools: "Read,Write,Edit,Glob,Grep";
|
|
1753
|
-
mcp: "empty-strict";
|
|
1754
|
-
settingSources: "user";
|
|
1755
|
-
userSettingsTrust: "required";
|
|
1756
|
-
sessionPersistence: false;
|
|
1757
|
-
} | {
|
|
1758
|
-
access: "read-only";
|
|
1759
|
-
authentication: "cursor-api-key-or-existing-login";
|
|
1760
|
-
mode: "ask";
|
|
1761
|
-
sandbox: "enabled";
|
|
1762
|
-
workspaceTrust: "existing-required";
|
|
1763
|
-
sessionReuse: false;
|
|
1764
|
-
} | {
|
|
1765
|
-
access: "workspace-write";
|
|
1766
|
-
authentication: "cursor-api-key-or-existing-login";
|
|
1767
|
-
mode: "print";
|
|
1768
|
-
sandbox: "enabled";
|
|
1769
|
-
workspaceTrust: "existing-required";
|
|
1770
|
-
sessionReuse: false;
|
|
1771
|
-
};
|
|
1737
|
+
safety?: ExternalCliProfileSafety;
|
|
1738
|
+
/** Where `safety` came from. Nothing in it is measured from the launched process. */
|
|
1739
|
+
safetySource?: ExternalCliSafetySource;
|
|
1772
1740
|
outputArtifacts?: {
|
|
1773
1741
|
stdoutPath?: string;
|
|
1774
1742
|
stderrPath?: string;
|
|
@@ -1783,6 +1751,59 @@ export interface ExternalCliReceiptMetadata {
|
|
|
1783
1751
|
};
|
|
1784
1752
|
nonResumableReason: string;
|
|
1785
1753
|
}
|
|
1754
|
+
export type ExternalCliProfileSafety = {
|
|
1755
|
+
sandbox: "read-only";
|
|
1756
|
+
approvalPolicy: "never";
|
|
1757
|
+
ephemeral: true;
|
|
1758
|
+
} | {
|
|
1759
|
+
access: "workspace-write";
|
|
1760
|
+
sandbox: "workspace-write";
|
|
1761
|
+
approvalPolicy: "never";
|
|
1762
|
+
ephemeral: true;
|
|
1763
|
+
} | {
|
|
1764
|
+
permissionMode: "plan";
|
|
1765
|
+
tools: "none";
|
|
1766
|
+
mcp: "empty-strict";
|
|
1767
|
+
settingSources: "none";
|
|
1768
|
+
sessionPersistence: false;
|
|
1769
|
+
} | {
|
|
1770
|
+
access: "read-only";
|
|
1771
|
+
authentication: "existing-cli-required";
|
|
1772
|
+
permissionMode: "plan";
|
|
1773
|
+
tools: "none";
|
|
1774
|
+
mcp: "empty-strict";
|
|
1775
|
+
settingSources: "user";
|
|
1776
|
+
userSettingsTrust: "required";
|
|
1777
|
+
sessionPersistence: false;
|
|
1778
|
+
} | {
|
|
1779
|
+
access: "workspace-write";
|
|
1780
|
+
authentication: "existing-cli-required";
|
|
1781
|
+
permissionMode: "acceptEdits";
|
|
1782
|
+
tools: "Read,Write,Edit,Glob,Grep";
|
|
1783
|
+
mcp: "empty-strict";
|
|
1784
|
+
settingSources: "user";
|
|
1785
|
+
userSettingsTrust: "required";
|
|
1786
|
+
sessionPersistence: false;
|
|
1787
|
+
} | {
|
|
1788
|
+
access: "read-only";
|
|
1789
|
+
authentication: "cursor-api-key-or-existing-login";
|
|
1790
|
+
mode: "ask";
|
|
1791
|
+
sandbox: "enabled";
|
|
1792
|
+
workspaceTrust: "existing-required";
|
|
1793
|
+
sessionReuse: false;
|
|
1794
|
+
} | {
|
|
1795
|
+
access: "workspace-write";
|
|
1796
|
+
authentication: "cursor-api-key-or-existing-login";
|
|
1797
|
+
mode: "print";
|
|
1798
|
+
sandbox: "enabled";
|
|
1799
|
+
workspaceTrust: "existing-required";
|
|
1800
|
+
sessionReuse: false;
|
|
1801
|
+
};
|
|
1802
|
+
export interface ExternalCliSafetySource {
|
|
1803
|
+
measured: false;
|
|
1804
|
+
/** The launch command, absent on a Herdr saved machine. A wrapper script here can grant more or less than the adapter profile. */
|
|
1805
|
+
command?: string;
|
|
1806
|
+
}
|
|
1786
1807
|
export interface ExternalCliRunnerStatus {
|
|
1787
1808
|
type: "external-cli";
|
|
1788
1809
|
command: string;
|
|
@@ -1790,6 +1811,7 @@ export interface ExternalCliRunnerStatus {
|
|
|
1790
1811
|
promptDelivery: "stdin" | "prompt-file";
|
|
1791
1812
|
adapter: ExternalCliReceiptMetadata["adapter"];
|
|
1792
1813
|
safety?: ExternalCliReceiptMetadata["safety"];
|
|
1814
|
+
safetySource?: ExternalCliSafetySource;
|
|
1793
1815
|
capabilities: ExternalCliCapabilities;
|
|
1794
1816
|
unsupportedReasons: Record<Exclude<keyof ExternalCliCapabilities, "stop">, string>;
|
|
1795
1817
|
nonResumableReason: string;
|
|
@@ -1928,7 +1950,6 @@ export interface AsyncStatus {
|
|
|
1928
1950
|
runner?: ExternalCliRunnerStatus | ExternalJobRunnerStatus;
|
|
1929
1951
|
externalProcess?: ExternalProcessStatus;
|
|
1930
1952
|
externalJob?: ExternalJobStatus;
|
|
1931
|
-
/** Resolved launch context for this child step. */
|
|
1932
1953
|
context?: "fresh" | "fork";
|
|
1933
1954
|
/** Short caller-facing task/goal shown in fleet surfaces when available. */
|
|
1934
1955
|
description?: string;
|
|
@@ -2403,6 +2424,11 @@ export interface RunnerLauncher {
|
|
|
2403
2424
|
name: string;
|
|
2404
2425
|
argv: string[];
|
|
2405
2426
|
}
|
|
2427
|
+
/** A call's requirement that its agent runs under this launcher with this agent definition digest. */
|
|
2428
|
+
export interface RequiredRunnerLauncher {
|
|
2429
|
+
name: string;
|
|
2430
|
+
definitionDigest: string;
|
|
2431
|
+
}
|
|
2406
2432
|
export declare const SUBAGENT_ASYNC_COMPLETE_EVENT = "subagent:async-complete";
|
|
2407
2433
|
export declare const SUBAGENT_PROCESS_TERMINAL_EVENT = "subagent:process-terminal";
|
|
2408
2434
|
export declare const SUBAGENT_FOREGROUND_COMPLETE_EVENT = "subagent:foreground-complete";
|
|
@@ -2457,7 +2483,6 @@ export interface RunSyncOptions {
|
|
|
2457
2483
|
parentSessionId?: string;
|
|
2458
2484
|
/** The parent session's file, recorded as a new child session's `parentSession` header. */
|
|
2459
2485
|
parentSessionFile?: string;
|
|
2460
|
-
/** Resolved launch context for this child. */
|
|
2461
2486
|
context?: "fresh" | "fork";
|
|
2462
2487
|
cwd?: string;
|
|
2463
2488
|
/** Resolved pane-native saved-machine placement. */
|
|
@@ -2485,6 +2510,8 @@ export interface RunSyncOptions {
|
|
|
2485
2510
|
/** Internal structured-delegation transport optimization: skip unchanged live snapshots. */
|
|
2486
2511
|
suppressUnchangedDelegationUpdates?: boolean;
|
|
2487
2512
|
onControlEvent?: (event: ControlEvent) => void;
|
|
2513
|
+
/** Reports a problem found by a timer callback, with a stable key to de-duplicate it; without it the message goes to stderr. */
|
|
2514
|
+
onWarning?: (message: string, key: string) => void;
|
|
2488
2515
|
/** Exposes a non-terminating detach callback while the child is active. */
|
|
2489
2516
|
onDetachReady?: (detach: (reason?: string) => boolean) => void;
|
|
2490
2517
|
/** Internal foreground receipt proposal; returns true only when the outer waiter accepted it. */
|
|
@@ -2540,7 +2567,6 @@ export interface RunSyncOptions {
|
|
|
2540
2567
|
preferredModelProvider?: string;
|
|
2541
2568
|
/** Parent Pi event host used to snapshot runtime-registered MCP servers before child launch. */
|
|
2542
2569
|
runtimeSnapshotHost?: import("../runs/shared/mcp-direct-tool-allowlist.ts").McpRuntimeSnapshotHost;
|
|
2543
|
-
/** Optional subagent model-scope enforcement. */
|
|
2544
2570
|
modelScope?: ModelScopeRule | ModelScopeRule[];
|
|
2545
2571
|
/** Skills to make available (overrides agent default if provided) */
|
|
2546
2572
|
skills?: string[];
|
package/src/shared/types.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Type definitions for the subagent extension
|
|
3
|
-
*/
|
|
4
1
|
import * as os from "node:os";
|
|
5
2
|
import * as path from "node:path";
|
|
6
3
|
export const SUBAGENT_LIFECYCLE_ARTIFACT_VERSION = 3;
|
|
@@ -39,9 +36,6 @@ export const FLEET_KEYBINDING_ACTIONS = [
|
|
|
39
36
|
"stop",
|
|
40
37
|
"toggleTools",
|
|
41
38
|
];
|
|
42
|
-
// ============================================================================
|
|
43
|
-
// Constants
|
|
44
|
-
// ============================================================================
|
|
45
39
|
export const DEFAULT_MAX_OUTPUT = {
|
|
46
40
|
bytes: 200 * 1024,
|
|
47
41
|
lines: 5000,
|
|
@@ -165,9 +159,6 @@ export function wrapForkTask(task, preamble) {
|
|
|
165
159
|
return task;
|
|
166
160
|
return `${wrappedPrefix}${task}`;
|
|
167
161
|
}
|
|
168
|
-
// ============================================================================
|
|
169
|
-
// Recursion Depth Guard
|
|
170
|
-
// ============================================================================
|
|
171
162
|
function normalizeNonNegativeInteger(value) {
|
|
172
163
|
const parsed = typeof value === "number" ? value : typeof value === "string" ? Number(value) : NaN;
|
|
173
164
|
if (!Number.isInteger(parsed) || parsed < 0)
|
|
@@ -227,9 +218,6 @@ export function resolveMaxSubagentSpawnsPerRun(configMaxSpawns) {
|
|
|
227
218
|
?? normalizeMaxSubagentSpawnsPerRun(configMaxSpawns)
|
|
228
219
|
?? DEFAULT_MAX_SUBAGENT_SPAWNS_PER_RUN;
|
|
229
220
|
}
|
|
230
|
-
// ============================================================================
|
|
231
|
-
// Utility Functions
|
|
232
|
-
// ============================================================================
|
|
233
221
|
function formatBytes(bytes) {
|
|
234
222
|
if (bytes < 1024)
|
|
235
223
|
return `${bytes}B`;
|
package/src/shared/utils.d.ts
CHANGED
|
@@ -11,9 +11,6 @@ export declare function getProjectConfigDir(projectRoot: string): string;
|
|
|
11
11
|
export declare function getAgentDir(): string;
|
|
12
12
|
export declare function pruneStatusCacheForAsyncRoot(asyncDirRoot: string, runIds: Iterable<string>): number;
|
|
13
13
|
export declare function resolveChildCwd(baseCwd: string, childCwd: string | undefined): string;
|
|
14
|
-
/**
|
|
15
|
-
* Read async job status from disk (with mtime-based caching)
|
|
16
|
-
*/
|
|
17
14
|
export declare function readStatus(asyncDir: string): AsyncStatus | null;
|
|
18
15
|
export declare function getLastActivity(outputFile: string | undefined): string;
|
|
19
16
|
export declare function findLatestSessionFile(sessionDir: string): string | null;
|
|
@@ -30,13 +27,9 @@ export declare function assistantMessageError(message: {
|
|
|
30
27
|
}): string | undefined;
|
|
31
28
|
export declare function getFinalOutput(messages: Message[]): string;
|
|
32
29
|
export declare function getSingleResultOutput(result: Pick<SingleResult, "finalOutput" | "messages">): string;
|
|
33
|
-
/**
|
|
34
|
-
* Extract display items (text and tool calls) from messages
|
|
35
|
-
*/
|
|
36
30
|
export declare function getDisplayItems(messages: Message[] | undefined): DisplayItem[];
|
|
37
31
|
export declare function sumResultsUsage(results: SingleResult[]): Usage;
|
|
38
32
|
export declare function toAgentToolUsage(usage: Usage): PiUsage;
|
|
39
|
-
/** Sum input tokens, output tokens, and cost across a set of SingleResults. */
|
|
40
33
|
export declare function sumResultsCost(results: SingleResult[]): NonNullable<Details["totalCost"]>;
|
|
41
34
|
export declare function compactForegroundResult(result: SingleResult): SingleResult;
|
|
42
35
|
export declare function compactForegroundDetails(details: Details): Details;
|
|
@@ -56,7 +49,6 @@ export declare function compactForegroundDetails(details: Details): Details;
|
|
|
56
49
|
export declare const MAX_STREAMED_RECENT_TOOLS = 32;
|
|
57
50
|
export declare const MAX_STREAMED_TOOL_CALLS = 64;
|
|
58
51
|
export declare const MAX_STREAMED_OUTPUT_LINE_CHARS = 2000;
|
|
59
|
-
/** Keep only the most recent tool-history entries in a streamed snapshot. */
|
|
60
52
|
export declare function boundStreamedRecentTools(recentTools: AgentProgress["recentTools"]): AgentProgress["recentTools"];
|
|
61
53
|
/** Cap per-line length of recent output so one long line can't inflate a snapshot. */
|
|
62
54
|
export declare function boundStreamedRecentOutput(recentOutput: string[]): string[];
|
|
@@ -72,12 +64,6 @@ export declare function formatEmptyTerminalAssistantResponseError(messages: Mess
|
|
|
72
64
|
* Detect errors in subagent execution from messages (only errors with no subsequent success)
|
|
73
65
|
*/
|
|
74
66
|
export declare function detectSubagentError(messages: Message[]): ErrorInfo;
|
|
75
|
-
/**
|
|
76
|
-
* Extract a preview of tool arguments for display
|
|
77
|
-
*/
|
|
78
67
|
export declare function extractToolArgsPreview(args: Record<string, unknown>): string;
|
|
79
|
-
/**
|
|
80
|
-
* Extract text content from various message content formats
|
|
81
|
-
*/
|
|
82
68
|
export declare function extractTextFromContent(content: unknown): string;
|
|
83
69
|
export { mapConcurrent } from "../runs/shared/parallel-utils.ts";
|
package/src/shared/utils.js
CHANGED
|
@@ -119,9 +119,6 @@ function isNotFoundError(error) {
|
|
|
119
119
|
&& "code" in error
|
|
120
120
|
&& error.code === "ENOENT";
|
|
121
121
|
}
|
|
122
|
-
/**
|
|
123
|
-
* Read async job status from disk (with mtime-based caching)
|
|
124
|
-
*/
|
|
125
122
|
export function readStatus(asyncDir) {
|
|
126
123
|
if (Buffer.byteLength(path.basename(asyncDir), "utf-8") > 255) {
|
|
127
124
|
return null;
|
|
@@ -291,9 +288,6 @@ export function getFinalOutput(messages) {
|
|
|
291
288
|
export function getSingleResultOutput(result) {
|
|
292
289
|
return result.finalOutput ?? getFinalOutput(result.messages ?? []);
|
|
293
290
|
}
|
|
294
|
-
/**
|
|
295
|
-
* Extract display items (text and tool calls) from messages
|
|
296
|
-
*/
|
|
297
291
|
export function getDisplayItems(messages) {
|
|
298
292
|
if (!messages || messages.length === 0)
|
|
299
293
|
return [];
|
|
@@ -387,7 +381,6 @@ function addNestedCost(total, children) {
|
|
|
387
381
|
addNestedCost(total, step.children);
|
|
388
382
|
}
|
|
389
383
|
}
|
|
390
|
-
/** Sum input tokens, output tokens, and cost across a set of SingleResults. */
|
|
391
384
|
export function sumResultsCost(results) {
|
|
392
385
|
const total = { inputTokens: 0, outputTokens: 0, costUsd: 0 };
|
|
393
386
|
for (const result of results) {
|
|
@@ -435,7 +428,6 @@ export function compactForegroundDetails(details) {
|
|
|
435
428
|
export const MAX_STREAMED_RECENT_TOOLS = 32;
|
|
436
429
|
export const MAX_STREAMED_TOOL_CALLS = 64;
|
|
437
430
|
export const MAX_STREAMED_OUTPUT_LINE_CHARS = 2000;
|
|
438
|
-
/** Keep only the most recent tool-history entries in a streamed snapshot. */
|
|
439
431
|
export function boundStreamedRecentTools(recentTools) {
|
|
440
432
|
return recentTools.slice(-MAX_STREAMED_RECENT_TOOLS).map((tool) => ({ ...tool }));
|
|
441
433
|
}
|
|
@@ -519,9 +511,6 @@ export function detectSubagentError(messages) {
|
|
|
519
511
|
}
|
|
520
512
|
return { hasError: false };
|
|
521
513
|
}
|
|
522
|
-
/**
|
|
523
|
-
* Extract a preview of tool arguments for display
|
|
524
|
-
*/
|
|
525
514
|
export function extractToolArgsPreview(args) {
|
|
526
515
|
const stringifyPreviewValue = (value) => {
|
|
527
516
|
if (typeof value === "string" && value.trim().length > 0)
|
|
@@ -573,32 +562,24 @@ export function extractToolArgsPreview(args) {
|
|
|
573
562
|
}
|
|
574
563
|
return "";
|
|
575
564
|
}
|
|
576
|
-
/**
|
|
577
|
-
* Extract text content from various message content formats
|
|
578
|
-
*/
|
|
579
565
|
export function extractTextFromContent(content) {
|
|
580
566
|
if (!content)
|
|
581
567
|
return "";
|
|
582
|
-
// Handle string content directly
|
|
583
568
|
if (typeof content === "string")
|
|
584
569
|
return content;
|
|
585
|
-
// Handle array content
|
|
586
570
|
if (!Array.isArray(content))
|
|
587
571
|
return "";
|
|
588
572
|
const texts = [];
|
|
589
573
|
for (const part of content) {
|
|
590
574
|
if (part && typeof part === "object") {
|
|
591
|
-
// Handle { type: "text", text: "..." }
|
|
592
575
|
if ("type" in part && part.type === "text" && "text" in part) {
|
|
593
576
|
texts.push(String(part.text));
|
|
594
577
|
}
|
|
595
|
-
// Handle { type: "tool_result", content: "..." }
|
|
596
578
|
else if ("type" in part && part.type === "tool_result" && "content" in part) {
|
|
597
579
|
const inner = extractTextFromContent(part.content);
|
|
598
580
|
if (inner)
|
|
599
581
|
texts.push(inner);
|
|
600
582
|
}
|
|
601
|
-
// Handle { text: "..." } without type
|
|
602
583
|
else if ("text" in part) {
|
|
603
584
|
texts.push(String(part.text));
|
|
604
585
|
}
|
|
@@ -606,7 +587,4 @@ export function extractTextFromContent(content) {
|
|
|
606
587
|
}
|
|
607
588
|
return texts.join("\n");
|
|
608
589
|
}
|
|
609
|
-
// ============================================================================
|
|
610
|
-
// Concurrency Utilities
|
|
611
|
-
// ============================================================================
|
|
612
590
|
export { mapConcurrent } from "../runs/shared/parallel-utils.js";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare const DEFAULT_WAIT_TOOL_NAME = "bg_wait";
|
|
2
|
+
/**
|
|
3
|
+
* The name pi-subagents registers its wait tool under (`config.waitTool.name`). One value per process: the parent
|
|
4
|
+
* sets it from config, a child runtime from its launch config, and an async runner from its runner config, because
|
|
5
|
+
* every runtime in a process descends from the same parent setting.
|
|
6
|
+
*/
|
|
7
|
+
export declare function waitToolName(): string;
|
|
8
|
+
export declare function setWaitToolName(name: string): void;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export const DEFAULT_WAIT_TOOL_NAME = "bg_wait";
|
|
2
|
+
let current = DEFAULT_WAIT_TOOL_NAME;
|
|
3
|
+
/**
|
|
4
|
+
* The name pi-subagents registers its wait tool under (`config.waitTool.name`). One value per process: the parent
|
|
5
|
+
* sets it from config, a child runtime from its launch config, and an async runner from its runner config, because
|
|
6
|
+
* every runtime in a process descends from the same parent setting.
|
|
7
|
+
*/
|
|
8
|
+
export function waitToolName() {
|
|
9
|
+
return current;
|
|
10
|
+
}
|
|
11
|
+
export function setWaitToolName(name) {
|
|
12
|
+
current = name;
|
|
13
|
+
}
|
|
@@ -22,6 +22,7 @@ import { SUBAGENT_GUIDE_TOPICS } from "../extension/subagent-guide.js";
|
|
|
22
22
|
import { getInspectorPlugins } from "../inspectors/plugins.js";
|
|
23
23
|
import { applySlashUpdate, buildSlashInitialResult, failSlashResult, finalizeSlashResult, } from "./slash-live-state.js";
|
|
24
24
|
import { SLASH_RESULT_TYPE, SLASH_TEXT_RESULT_TYPE, SLASH_TEXT_VIEW_ONLY_DETAILS, SLASH_SUBAGENT_CANCEL_EVENT, SLASH_SUBAGENT_REQUEST_EVENT, SLASH_SUBAGENT_RESPONSE_EVENT, SLASH_SUBAGENT_STARTED_EVENT, SLASH_SUBAGENT_UPDATE_EVENT, DIRS, } from "../shared/types.js";
|
|
25
|
+
import { waitToolName } from "../shared/wait-tool-name.js";
|
|
25
26
|
const parseInlineConfig = (raw) => {
|
|
26
27
|
const config = {};
|
|
27
28
|
for (const part of raw.split(",")) {
|
|
@@ -729,7 +730,7 @@ export function registerSlashCommands(pi, state, options = {}) {
|
|
|
729
730
|
ctx.ui.notify(`Foreground run ${control.runId} is not currently detachable.`, "info");
|
|
730
731
|
return;
|
|
731
732
|
}
|
|
732
|
-
sendSlashText(pi, `Detached foreground run ${control.runId} without terminating its child. Use subagent({ action: "status", id: ${JSON.stringify(control.runId)} }) or
|
|
733
|
+
sendSlashText(pi, `Detached foreground run ${control.runId} without terminating its child. Use subagent({ action: "status", id: ${JSON.stringify(control.runId)} }) or ${waitToolName()}({ id: ${JSON.stringify(control.runId)} }) to recover the eventual result. This does not daemonize the process or guarantee survival across Pi reload/restart.`);
|
|
733
734
|
};
|
|
734
735
|
pi.registerCommand("subagents-detach", {
|
|
735
736
|
description: "Detach the active foreground single-subagent run without terminating it",
|
|
@@ -21,8 +21,9 @@ export declare const SUBAGENT_COST_REPORT_VERSION: 1;
|
|
|
21
21
|
/**
|
|
22
22
|
* Collect parent and child usage for the current session branch. Foreground
|
|
23
23
|
* children come from persisted `subagent`/`bg_wait` tool-result details; async
|
|
24
|
-
*
|
|
25
|
-
*
|
|
24
|
+
* runs come from those results and `subagent-notify` completions. Async workflow
|
|
25
|
+
* children are resolved through receipts, and other async runs through their
|
|
26
|
+
* status steps, then artifact metadata.
|
|
26
27
|
*/
|
|
27
28
|
export declare function collectSubagentCost(ctx: ExtensionContext, state: Pick<SubagentState, "baseCwd" | "artifactDirPreference">): SubagentCostReport;
|
|
28
29
|
/** The `/subagent-cost` text rendering of a collected report. */
|
|
@@ -6,6 +6,7 @@ import { DIRS, SLASH_RESULT_TYPE } from "../shared/types.js";
|
|
|
6
6
|
import { readStatus } from "../shared/utils.js";
|
|
7
7
|
import { readWorkflowReceipt } from "../workflows/workflow-receipt.js";
|
|
8
8
|
import { resolveSlashMessageDetails } from "./slash-live-state.js";
|
|
9
|
+
import { DEFAULT_WAIT_TOOL_NAME, waitToolName } from "../shared/wait-tool-name.js";
|
|
9
10
|
export const SUBAGENT_COST_REPORT_VERSION = 1;
|
|
10
11
|
function emptyUsage() {
|
|
11
12
|
return { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, cost: 0, turns: 0 };
|
|
@@ -95,10 +96,25 @@ function detailsFromSessionEntry(entry) {
|
|
|
95
96
|
if (record.type !== "message" || !record.message || typeof record.message !== "object")
|
|
96
97
|
return undefined;
|
|
97
98
|
const message = record.message;
|
|
98
|
-
|
|
99
|
+
// Results saved before a waitTool.name rename carry bg_wait; another extension's bg_wait results fail isSubagentDetails.
|
|
100
|
+
if (message.role !== "toolResult" || (message.toolName !== "subagent" && message.toolName !== waitToolName() && message.toolName !== DEFAULT_WAIT_TOOL_NAME))
|
|
99
101
|
return undefined;
|
|
100
102
|
return isSubagentDetails(message.details) ? message.details : undefined;
|
|
101
103
|
}
|
|
104
|
+
/** Background runs a `subagent-notify` completion reports; an RPC `spawn` launch has no tool result, so this is its only record. */
|
|
105
|
+
function notifiedAsyncRuns(entry) {
|
|
106
|
+
if (!entry || typeof entry !== "object")
|
|
107
|
+
return [];
|
|
108
|
+
const record = entry;
|
|
109
|
+
if (record.type !== "custom_message" || record.customType !== "subagent-notify")
|
|
110
|
+
return [];
|
|
111
|
+
const runs = record.details?.runs;
|
|
112
|
+
if (!Array.isArray(runs))
|
|
113
|
+
return [];
|
|
114
|
+
return runs.flatMap((run) =>
|
|
115
|
+
// A detached foreground task keeps no async status directory to read usage from.
|
|
116
|
+
run && typeof run.runId === "string" && run.source !== "foreground" ? [{ runId: run.runId, workflow: run.workflowRunId === run.runId }] : []);
|
|
117
|
+
}
|
|
102
118
|
function metadataUsage(artifactsDirs, input, indexes = [0, undefined]) {
|
|
103
119
|
if (!/^[A-Za-z0-9._-]+$/.test(input.runId))
|
|
104
120
|
return undefined;
|
|
@@ -126,8 +142,9 @@ function metadataUsage(artifactsDirs, input, indexes = [0, undefined]) {
|
|
|
126
142
|
/**
|
|
127
143
|
* Collect parent and child usage for the current session branch. Foreground
|
|
128
144
|
* children come from persisted `subagent`/`bg_wait` tool-result details; async
|
|
129
|
-
*
|
|
130
|
-
*
|
|
145
|
+
* runs come from those results and `subagent-notify` completions. Async workflow
|
|
146
|
+
* children are resolved through receipts, and other async runs through their
|
|
147
|
+
* status steps, then artifact metadata.
|
|
131
148
|
*/
|
|
132
149
|
export function collectSubagentCost(ctx, state) {
|
|
133
150
|
const parent = emptyUsage();
|
|
@@ -163,6 +180,8 @@ export function collectSubagentCost(ctx, state) {
|
|
|
163
180
|
const parentUsage = assistantUsageFromMessage(message) ?? compactionUsageFromEntry(entry);
|
|
164
181
|
if (parentUsage)
|
|
165
182
|
addUsage(parent, parentUsage);
|
|
183
|
+
for (const run of notifiedAsyncRuns(entry))
|
|
184
|
+
(run.workflow ? workflowRunIds : asyncRunIds).add(run.runId);
|
|
166
185
|
const details = detailsFromSessionEntry(entry);
|
|
167
186
|
if (!details)
|
|
168
187
|
continue;
|
|
@@ -442,7 +442,6 @@ export async function openSubagentsAdmin(pi, ctx, args = "") {
|
|
|
442
442
|
sendAdminMessage(pi, message);
|
|
443
443
|
}
|
|
444
444
|
else if (action === "Show details") {
|
|
445
|
-
// Full metadata is now opt-in (previously always posted to the thread).
|
|
446
445
|
sendAdminMessage(pi, metadataFor(agent));
|
|
447
446
|
}
|
|
448
447
|
}
|