pi-subagents 0.84.0 → 0.85.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 (204) hide show
  1. package/CHANGELOG.md +62 -0
  2. package/bundle/agents.js +3 -3
  3. package/bundle/child-tool-plan.js +2 -2
  4. package/bundle/{chunk-235AWJUQ.js → chunk-3UZ5FVVJ.js} +310 -101
  5. package/bundle/{chunk-F4ASL6OV.js → chunk-7MAE3DJV.js} +1 -1
  6. package/bundle/{chunk-4E7BKDTX.js → chunk-CS4O36CZ.js} +11 -156
  7. package/bundle/{chunk-VQVVHSY6.js → chunk-DV2NCNPR.js} +22 -11
  8. package/bundle/{chunk-G2Z6ZH26.js → chunk-GCSLVFCX.js} +1 -1
  9. package/bundle/{chunk-2S4K53MV.js → chunk-H2NLFTC5.js} +1 -1
  10. package/bundle/{chunk-NKQ6JNAS.js → chunk-HFTBF7SG.js} +2 -1
  11. package/bundle/chunk-HXRB42AF.js +108 -0
  12. package/bundle/{chunk-7BWGNDNK.js → chunk-IQIWF2VX.js} +190 -1177
  13. package/bundle/{chunk-XDQORLZ5.js → chunk-JNXT3MPI.js} +15 -6
  14. package/bundle/{chunk-J5YL7LYR.js → chunk-JO67XSKD.js} +59 -27
  15. package/bundle/{chunk-JG4QKI5M.js → chunk-JWYG26RE.js} +209 -93
  16. package/bundle/{chunk-C5P5CHYK.js → chunk-KDMFBYFM.js} +1 -1
  17. package/bundle/{chunk-V2BZYLEP.js → chunk-KEY3UQMQ.js} +7 -2
  18. package/bundle/{chunk-NENDSQUY.js → chunk-KZ34KQQH.js} +9 -6
  19. package/bundle/{chunk-AKOIVLA5.js → chunk-L2ENOFVZ.js} +76 -58
  20. package/bundle/{chunk-CGN2TVE7.js → chunk-LGMILZNE.js} +322 -18
  21. package/bundle/{chunk-L3WFKBEI.js → chunk-LTPH2DXH.js} +247 -153
  22. package/bundle/{chunk-2D52JFLF.js → chunk-N7B2KD74.js} +41 -117
  23. package/bundle/{chunk-PV63UFUR.js → chunk-O7CPL6H4.js} +183 -28
  24. package/bundle/{chunk-D3JAFGMO.js → chunk-PHZP3KHB.js} +1 -1
  25. package/bundle/{chunk-2DHZTCOL.js → chunk-PVIVCDG2.js} +2 -2
  26. package/bundle/{chunk-LFDBD4PW.js → chunk-QO75KJBT.js} +2 -2
  27. package/bundle/{chunk-SSG7IEP5.js → chunk-RQAUNAWG.js} +2 -2
  28. package/bundle/{chunk-PALJGGYC.js → chunk-RV5OGHLO.js} +6 -3
  29. package/bundle/chunk-T5V5BRCL.js +1067 -0
  30. package/bundle/{chunk-LNRJCP2Y.js → chunk-UX4SCV5N.js} +337 -207
  31. package/bundle/{chunk-DZDETGRJ.js → chunk-WOVMHDES.js} +231 -182
  32. package/bundle/control-channel.js +2 -2
  33. package/bundle/index.js +1 -1
  34. package/bundle/intercom-bridge.js +2 -2
  35. package/bundle/preflight.js +8 -8
  36. package/bundle/project-panes.js +3 -3
  37. package/docs/agents.md +17 -2
  38. package/docs/configuration.md +2 -2
  39. package/docs/extension-api.md +16 -1
  40. package/docs/workflows.md +30 -2
  41. package/package.json +1 -1
  42. package/src/agents/agent-management.js +27 -11
  43. package/src/agents/agent-memory.d.ts +1 -4
  44. package/src/agents/agent-memory.js +1 -4
  45. package/src/agents/agents.d.ts +1 -3
  46. package/src/agents/agents.js +7 -6
  47. package/src/agents/frontmatter.js +1 -8
  48. package/src/agents/global-npm-root.d.ts +1 -0
  49. package/src/agents/global-npm-root.js +11 -3
  50. package/src/agents/skills.d.ts +0 -3
  51. package/src/agents/skills.js +0 -3
  52. package/src/extension/config.js +7 -1
  53. package/src/extension/herdr-pi-bridge.js +10 -2
  54. package/src/extension/index.d.ts +0 -13
  55. package/src/extension/index.js +43 -32
  56. package/src/extension/public-execution.d.ts +1 -0
  57. package/src/extension/public-execution.js +4 -0
  58. package/src/extension/reply-workflow-script.js +24 -4
  59. package/src/extension/schemas.d.ts +8 -3
  60. package/src/extension/schemas.js +5 -3
  61. package/src/extension/session-switch.d.ts +25 -0
  62. package/src/extension/session-switch.js +138 -0
  63. package/src/extension/subagent-guide.d.ts +1 -1
  64. package/src/extension/subagent-guide.js +1 -1
  65. package/src/extension/subagent-launch-tool.d.ts +25 -0
  66. package/src/extension/subagent-launch-tool.js +48 -0
  67. package/src/extension/tool-activation.js +25 -11
  68. package/src/extension/tool-description.js +6 -0
  69. package/src/inspectors/herdr/actions.d.ts +0 -1
  70. package/src/inspectors/herdr/actions.js +0 -1
  71. package/src/inspectors/session-roots-codec.d.ts +0 -1
  72. package/src/inspectors/session-roots-codec.js +0 -1
  73. package/src/inspectors/tmux/actions.d.ts +0 -1
  74. package/src/inspectors/tmux/actions.js +0 -1
  75. package/src/integrations/herdr-status.js +3 -8
  76. package/src/intercom/native-supervisor-channel.js +65 -9
  77. package/src/runs/background/async-execution.d.ts +5 -9
  78. package/src/runs/background/async-execution.js +62 -27
  79. package/src/runs/background/async-job-tracker.js +12 -0
  80. package/src/runs/background/async-resume.d.ts +2 -1
  81. package/src/runs/background/async-resume.js +112 -39
  82. package/src/runs/background/async-retention.js +6 -1
  83. package/src/runs/background/auto-drain.js +2 -1
  84. package/src/runs/background/boot-id.d.ts +1 -3
  85. package/src/runs/background/boot-id.js +1 -3
  86. package/src/runs/background/completion-batcher.d.ts +3 -4
  87. package/src/runs/background/completion-batcher.js +2 -3
  88. package/src/runs/background/control-channel.d.ts +0 -6
  89. package/src/runs/background/control-channel.js +0 -6
  90. package/src/runs/background/fleet-view.js +2 -3
  91. package/src/runs/background/notify.d.ts +0 -2
  92. package/src/runs/background/notify.js +0 -2
  93. package/src/runs/background/result-watcher.d.ts +1 -0
  94. package/src/runs/background/result-watcher.js +59 -29
  95. package/src/runs/background/resume-guidance.js +4 -2
  96. package/src/runs/background/retained-children.js +2 -1
  97. package/src/runs/background/run-child-session.d.ts +0 -1
  98. package/src/runs/background/run-child-session.js +1 -1
  99. package/src/runs/background/run-status.js +4 -3
  100. package/src/runs/background/scheduled-runs.d.ts +3 -1
  101. package/src/runs/background/scheduled-runs.js +13 -16
  102. package/src/runs/background/subagent-runner.d.ts +2 -4
  103. package/src/runs/background/subagent-runner.js +9 -6
  104. package/src/runs/background/subagent-wait.js +12 -15
  105. package/src/runs/background/wait-config.d.ts +2 -0
  106. package/src/runs/background/wait-config.js +17 -3
  107. package/src/runs/background/wait-tool.js +4 -2
  108. package/src/runs/background/workflow-terminal-proof.d.ts +0 -1
  109. package/src/runs/background/workflow-terminal-proof.js +0 -1
  110. package/src/runs/foreground/execution.d.ts +0 -3
  111. package/src/runs/foreground/execution.js +17 -9
  112. package/src/runs/foreground/subagent-executor.d.ts +3 -2
  113. package/src/runs/foreground/subagent-executor.js +107 -26
  114. package/src/runs/shared/child-commands.js +15 -2
  115. package/src/runs/shared/child-hooks.d.ts +1 -7
  116. package/src/runs/shared/child-hooks.js +13 -5
  117. package/src/runs/shared/child-launch.js +6 -2
  118. package/src/runs/shared/child-runtime-config.d.ts +0 -1
  119. package/src/runs/shared/child-session.d.ts +1 -1
  120. package/src/runs/shared/child-session.js +21 -2
  121. package/src/runs/shared/child-tool-plan.d.ts +0 -1
  122. package/src/runs/shared/child-tool-plan.js +0 -1
  123. package/src/runs/shared/claude-code-adapter.js +11 -0
  124. package/src/runs/shared/external-cli-runner.js +26 -6
  125. package/src/runs/shared/herdr-connection.js +2 -1
  126. package/src/runs/shared/herdr-pane-host.d.ts +2 -2
  127. package/src/runs/shared/herdr-pane-host.js +17 -1
  128. package/src/runs/shared/herdr-placed-run.js +48 -22
  129. package/src/runs/shared/lane-metadata.d.ts +0 -1
  130. package/src/runs/shared/lane-metadata.js +0 -1
  131. package/src/runs/shared/mcp-direct-tool-grant.js +8 -1
  132. package/src/runs/shared/model-resolution-diagnostic.d.ts +0 -1
  133. package/src/runs/shared/model-resolution.d.ts +2 -2
  134. package/src/runs/shared/model-resolution.js +7 -1
  135. package/src/runs/shared/model-scope.d.ts +1 -5
  136. package/src/runs/shared/model-scope.js +1 -5
  137. package/src/runs/shared/mutation-evidence.d.ts +1 -1
  138. package/src/runs/shared/mutation-evidence.js +52 -7
  139. package/src/runs/shared/nested-events.d.ts +1 -0
  140. package/src/runs/shared/nested-events.js +1 -1
  141. package/src/runs/shared/parallel-utils.d.ts +0 -1
  142. package/src/runs/shared/permissions.js +5 -3
  143. package/src/runs/shared/placement-host.d.ts +5 -1
  144. package/src/runs/shared/rex-pane-host.d.ts +0 -1
  145. package/src/runs/shared/rex-pane-host.js +0 -2
  146. package/src/runs/shared/run-launch-folder.d.ts +12 -0
  147. package/src/runs/shared/run-launch-folder.js +21 -0
  148. package/src/runs/shared/runner-launcher.d.ts +12 -1
  149. package/src/runs/shared/runner-launcher.js +16 -0
  150. package/src/runs/shared/single-output.d.ts +3 -3
  151. package/src/runs/shared/single-output.js +5 -3
  152. package/src/runs/shared/structured-output.d.ts +8 -0
  153. package/src/runs/shared/structured-output.js +30 -2
  154. package/src/runs/shared/subagent-prompt-runtime.d.ts +0 -1
  155. package/src/runs/shared/subagent-prompt-runtime.js +4 -2
  156. package/src/runs/shared/tool-timeout.js +2 -1
  157. package/src/runs/shared/worktree-cleanup-plan.d.ts +0 -1
  158. package/src/runs/shared/worktree-cleanup-plan.js +0 -1
  159. package/src/runs/shared/worktree.d.ts +3 -0
  160. package/src/runs/shared/worktree.js +20 -0
  161. package/src/shared/capacity-resilient-json.d.ts +1 -1
  162. package/src/shared/child-cache-retention.d.ts +1 -2
  163. package/src/shared/child-cache-retention.js +1 -2
  164. package/src/shared/fleet-transcript-reader.d.ts +51 -0
  165. package/src/shared/fleet-transcript-reader.js +333 -0
  166. package/src/shared/formatters.d.ts +0 -18
  167. package/src/shared/formatters.js +0 -18
  168. package/src/shared/session-succession.d.ts +16 -1
  169. package/src/shared/session-succession.js +41 -2
  170. package/src/shared/session-warnings.d.ts +7 -0
  171. package/src/shared/session-warnings.js +26 -0
  172. package/src/shared/settings.d.ts +0 -23
  173. package/src/shared/settings.js +3 -35
  174. package/src/shared/types.d.ts +28 -11
  175. package/src/shared/types.js +0 -12
  176. package/src/shared/utils.d.ts +0 -14
  177. package/src/shared/utils.js +0 -22
  178. package/src/shared/wait-tool-name.d.ts +8 -0
  179. package/src/shared/wait-tool-name.js +13 -0
  180. package/src/slash/slash-commands.js +2 -1
  181. package/src/slash/subagent-cost.d.ts +3 -2
  182. package/src/slash/subagent-cost.js +22 -3
  183. package/src/slash/subagents-admin.js +0 -1
  184. package/src/tui/fleet-status.d.ts +0 -5
  185. package/src/tui/fleet-status.js +4 -24
  186. package/src/tui/fleet-transcript.d.ts +1 -44
  187. package/src/tui/fleet-transcript.js +1 -327
  188. package/src/tui/fleet.js +6 -4
  189. package/src/tui/render.d.ts +0 -9
  190. package/src/tui/render.js +81 -47
  191. package/src/tui/subagent-messages.js +3 -2
  192. package/src/watchdog/register-child.d.ts +2 -3
  193. package/src/watchdog/register-child.js +2 -3
  194. package/src/watchdog/turn-delta.js +2 -1
  195. package/src/workflows/scripted-workflow.js +241 -20
  196. package/src/workflows/workflow-launch-record.d.ts +15 -6
  197. package/src/workflows/workflow-launch-record.js +30 -12
  198. package/src/workflows/workflow-resume-claim.js +2 -2
  199. package/src/workflows/workflow-resume.d.ts +1 -1
  200. package/src/workflows/workflow-resume.js +11 -8
  201. package/src/workflows/workflow-script-worker.d.ts +13 -0
  202. package/src/workflows/workflow-script-worker.js +79 -0
  203. package/workflow-script-process.cjs +36 -0
  204. package/workflow-script-worker.cjs +4 -1
@@ -1,5 +1,6 @@
1
1
  import type { AgentConfig } from "../../agents/agents.ts";
2
- import type { RunnerLauncher } from "../../shared/types.ts";
2
+ import type { RequiredRunnerLauncher, RunnerLauncher } from "../../shared/types.ts";
3
+ export declare const REQUIRE_LAUNCHER_SHAPE_ERROR = "requireLauncher is supported only on a top-level single-agent call (agent + task); it cannot be combined with tasks, chain, workflow, an action, resume, or a workflow child.";
3
4
  /** Own-property lookup, so an inherited object key can never select a command. */
4
5
  export declare function lookupRunnerLauncher(runnerLaunchers: Record<string, string[]> | undefined, name: string): RunnerLauncher | undefined;
5
6
  /** A launcher wraps the local Pi background runner, so it cannot combine with machine placement or an external runner. */
@@ -9,3 +10,13 @@ export declare function resolveAgentRunnerLauncher(agent: Pick<AgentConfig, "nam
9
10
  launcher?: RunnerLauncher;
10
11
  error?: string;
11
12
  };
13
+ /**
14
+ * Checks a call's launcher requirement against the agent and launcher a launch resolved. On a match it returns the
15
+ * digest it checked, so the launch can record that digest instead of hashing the agent file again.
16
+ */
17
+ export declare function checkRequiredRunnerLauncher(agent: AgentConfig, launcherName: string | undefined, required: RequiredRunnerLauncher): {
18
+ definitionDigest: string;
19
+ error?: undefined;
20
+ } | {
21
+ error: string;
22
+ };
@@ -1,3 +1,5 @@
1
+ import { agentDefinitionDigest } from "../../shared/launch-contract.js";
2
+ export const REQUIRE_LAUNCHER_SHAPE_ERROR = "requireLauncher is supported only on a top-level single-agent call (agent + task); it cannot be combined with tasks, chain, workflow, an action, resume, or a workflow child.";
1
3
  /** Own-property lookup, so an inherited object key can never select a command. */
2
4
  export function lookupRunnerLauncher(runnerLaunchers, name) {
3
5
  const argv = runnerLaunchers && Object.hasOwn(runnerLaunchers, name) ? runnerLaunchers[name] : undefined;
@@ -22,3 +24,17 @@ export function resolveAgentRunnerLauncher(agent, runnerLaunchers, machine) {
22
24
  const launcher = lookupRunnerLauncher(runnerLaunchers, agent.launcher);
23
25
  return launcher ? { launcher } : { error: `Agent '${agent.name}' uses launcher '${agent.launcher}', which is not defined in runnerLaunchers in the user subagent config.` };
24
26
  }
27
+ /**
28
+ * Checks a call's launcher requirement against the agent and launcher a launch resolved. On a match it returns the
29
+ * digest it checked, so the launch can record that digest instead of hashing the agent file again.
30
+ */
31
+ export function checkRequiredRunnerLauncher(agent, launcherName, required) {
32
+ if (launcherName === undefined)
33
+ return { error: `Agent '${agent.name}' has no launcher, but the call requires launcher '${required.name}'.` };
34
+ if (launcherName !== required.name)
35
+ return { error: `Agent '${agent.name}' uses launcher '${launcherName}', but the call requires launcher '${required.name}'.` };
36
+ const definitionDigest = agentDefinitionDigest(agent);
37
+ if (definitionDigest !== required.definitionDigest)
38
+ return { error: `Agent '${agent.name}' definition digest is ${definitionDigest}, but the call requires ${required.definitionDigest}; the agent definition changed after it was checked.` };
39
+ return { definitionDigest };
40
+ }
@@ -1,5 +1,5 @@
1
1
  import type { Message } from "@earendil-works/pi-ai";
2
- import type { OutputMode, SavedOutputReference } from "../../shared/types.ts";
2
+ import type { OutputMode, PlacementMachineReference, SavedOutputReference } from "../../shared/types.ts";
3
3
  export interface SingleOutputSnapshot {
4
4
  exists: boolean;
5
5
  mtimeMs?: number;
@@ -27,7 +27,8 @@ export declare function outputPathMappingFromTask(task: string, savedPath: strin
27
27
  requestedPath: string;
28
28
  savedPath: string;
29
29
  } | undefined;
30
- export declare function injectSingleOutputInstruction(task: string, outputPath: string | undefined, capabilities?: OutputInstructionCapabilities): string;
30
+ /** A child on another machine cannot write the parent-side path; its final reply is saved there instead. */
31
+ export declare function injectSingleOutputInstruction(task: string, outputPath: string | undefined, capabilities?: OutputInstructionCapabilities, machine?: PlacementMachineReference): string;
31
32
  export declare function formatSavedOutputReference(savedPath: string, fullOutput: string): SavedOutputReference;
32
33
  /**
33
34
  * Keeps at most INLINE_OUTPUT_HEAD_CHARS of a child's output inline and points to the file holding all of it.
@@ -78,7 +79,6 @@ export declare function finalizeSingleOutput(params: {
78
79
  saveError?: string;
79
80
  };
80
81
  /**
81
- * Determines whether an output resolution error represents an unrecoverable settlement failure.
82
82
  * Returns true for fatal claim-path mismatches in any mode, or when required file-only output
83
83
  * fails to persist without a savedPath. Inline and optional outputs remain nonfatal warnings.
84
84
  */
@@ -1,5 +1,6 @@
1
1
  import * as fs from "node:fs";
2
2
  import * as path from "node:path";
3
+ import { isRexLocalMachine } from "./rex-machine.js";
3
4
  const READ_ONLY_OUTPUT_TOOLS = new Set([
4
5
  "read", "grep", "find", "ls", "web_search", "fetch_content", "get_search_content",
5
6
  "source_check", "intercom", "contact_supervisor", "structured_output", "watchdog_diff",
@@ -98,10 +99,12 @@ export function outputPathMappingFromTask(task, savedPath) {
98
99
  return undefined;
99
100
  return { requestedPath, savedPath };
100
101
  }
101
- export function injectSingleOutputInstruction(task, outputPath, capabilities) {
102
+ /** A child on another machine cannot write the parent-side path; its final reply is saved there instead. */
103
+ export function injectSingleOutputInstruction(task, outputPath, capabilities, machine) {
102
104
  if (!outputPath)
103
105
  return task;
104
- const delivery = !capabilities || hasOutputWriteCapability(capabilities.tools, capabilities.mcpDirectTools)
106
+ const remote = machine !== undefined && !isRexLocalMachine(machine);
107
+ const delivery = !remote && (!capabilities || hasOutputWriteCapability(capabilities.tools, capabilities.mcpDirectTools))
105
108
  ? `Write your findings to exactly this path: ${outputPath}`
106
109
  : [
107
110
  "Return the complete artifact in your final response.",
@@ -339,7 +342,6 @@ export function finalizeSingleOutput(params) {
339
342
  return { displayOutput };
340
343
  }
341
344
  /**
342
- * Determines whether an output resolution error represents an unrecoverable settlement failure.
343
345
  * Returns true for fatal claim-path mismatches in any mode, or when required file-only output
344
346
  * fails to persist without a savedPath. Inline and optional outputs remain nonfatal warnings.
345
347
  */
@@ -38,6 +38,8 @@ interface JsonSchemaValidationError {
38
38
  }
39
39
  type CompileJsonSchema = (schema: unknown) => CompiledJsonSchema;
40
40
  export declare function resolveCompileFromPackageRoot(packageRoot: string): Promise<CompileJsonSchema | undefined>;
41
+ /** Resolves once the validator has loaded or failed; a failure is reported by the structured_output call. */
42
+ export declare function structuredOutputValidatorReady(): Promise<void>;
41
43
  export declare function assertJsonSchemaObject(schema: unknown, label?: string): asserts schema is JsonSchemaObject;
42
44
  export declare function createStructuredOutputRuntime(schema: JsonSchemaObject, baseDir?: string, options?: {
43
45
  acceptanceReport?: ResolvedAcceptanceReportMode;
@@ -48,6 +50,12 @@ export declare function validateStructuredOutputValue(schema: JsonSchemaObject,
48
50
  status: "invalid";
49
51
  message: string;
50
52
  }>;
53
+ /**
54
+ * The tool's `prepareArguments` hook: checks the raw `value` before Pi converts tool arguments
55
+ * (Pi can turn `"x"` into `["x"]` or `null` into `"null"`), so only a value that already matches
56
+ * the schema is captured. Fails closed when the validator has not loaded.
57
+ */
58
+ export declare function prepareStructuredOutputArguments(schema: JsonSchemaObject, args: unknown): unknown;
51
59
  export declare function readStructuredOutput(runtime: StructuredOutputRuntime): Promise<{
52
60
  value?: unknown;
53
61
  error?: string;
@@ -152,6 +152,9 @@ export function createStructuredOutputToolParameters(schema, options = {}) {
152
152
  };
153
153
  }
154
154
  let cachedCompile;
155
+ // prepareArguments is synchronous, so it can only use a compiler that has already loaded.
156
+ let loadedCompile;
157
+ let compileLoadError;
155
158
  export async function resolveCompileFromPackageRoot(packageRoot) {
156
159
  const requireFromRoot = createRequire(path.join(packageRoot, "package.json"));
157
160
  const resolved = requireFromRoot.resolve("typebox/compile");
@@ -196,13 +199,21 @@ async function importCompile() {
196
199
  }
197
200
  function loadCompile() {
198
201
  if (!cachedCompile) {
199
- cachedCompile = importCompile().catch((error) => {
202
+ cachedCompile = importCompile().then((compile) => {
203
+ loadedCompile = compile;
204
+ return compile;
205
+ }, (error) => {
200
206
  cachedCompile = undefined;
207
+ compileLoadError = error;
201
208
  throw error;
202
209
  });
203
210
  }
204
211
  return cachedCompile;
205
212
  }
213
+ /** Resolves once the validator has loaded or failed; a failure is reported by the structured_output call. */
214
+ export function structuredOutputValidatorReady() {
215
+ return loadCompile().then(() => undefined, () => undefined);
216
+ }
206
217
  function jsonPointerTarget(root, pointer) {
207
218
  if (pointer === "#")
208
219
  return root;
@@ -379,7 +390,24 @@ export function createStructuredOutputRuntime(schema, baseDir, options = {}) {
379
390
  };
380
391
  }
381
392
  export async function validateStructuredOutputValue(schema, value) {
382
- const compile = await loadCompile();
393
+ return validateWithCompile(await loadCompile(), schema, value);
394
+ }
395
+ /**
396
+ * The tool's `prepareArguments` hook: checks the raw `value` before Pi converts tool arguments
397
+ * (Pi can turn `"x"` into `["x"]` or `null` into `"null"`), so only a value that already matches
398
+ * the schema is captured. Fails closed when the validator has not loaded.
399
+ */
400
+ export function prepareStructuredOutputArguments(schema, args) {
401
+ if (!args || typeof args !== "object" || !("value" in args))
402
+ return args;
403
+ if (!loadedCompile)
404
+ throw compileLoadError ?? new Error("Structured output validator is still loading; call structured_output again.");
405
+ const validation = validateWithCompile(loadedCompile, schema, args.value);
406
+ if (validation.status === "invalid")
407
+ throw new Error(`Structured output validation failed: ${validation.message}`);
408
+ return args;
409
+ }
410
+ function validateWithCompile(compile, schema, value) {
383
411
  let validator;
384
412
  try {
385
413
  validator = compile(schema);
@@ -85,6 +85,5 @@ export declare function stripParentOnlySubagentMessages(messages: unknown[], opt
85
85
  }): unknown[];
86
86
  export declare function formatSteerMessage(request: SteerRequest): string;
87
87
  export declare function registerPermissionGate(pi: ExtensionAPI, permissions: ChildPermissions | undefined, childWatchdog: ChildWatchdogConfig | undefined, requestPermission?: (request: WatchdogPermissionRequest) => Promise<WatchdogPermissionResult>): void;
88
- /** Register every child-side hook the prompt runtime owns for one child session. */
89
88
  export default function registerSubagentPromptRuntime(pi: ExtensionAPI, config?: ChildRuntimeConfig, drainObservation?: import("./readonly-drain-observation.ts").ReadonlyDrainObservation): void;
90
89
  export {};
@@ -5,7 +5,7 @@ import { declarationsEqual, getCurrentSystemMessage, getCurrentTools } from "@ea
5
5
  import { registerNativeSupervisorClient } from "../../intercom/native-supervisor-channel.js";
6
6
  import { permissionDecision } from "./permissions.js";
7
7
  import { RUNTIME_EXTENSION_ACK_EVENT, isRuntimeAcknowledgedExtensionId } from "./runtime-acknowledged-extensions.js";
8
- import { createStructuredOutputToolParameters, MISSING_STRUCTURED_ACCEPTANCE_REPORT_ERROR, validateStructuredOutputValue } from "./structured-output.js";
8
+ import { createStructuredOutputToolParameters, MISSING_STRUCTURED_ACCEPTANCE_REPORT_ERROR, prepareStructuredOutputArguments, validateStructuredOutputValue } from "./structured-output.js";
9
9
  import { validateAcceptanceReport } from "./acceptance.js";
10
10
  import { formatChildToolDiagnostic } from "./tool-availability.js";
11
11
  import { shouldBlockToolForBudget, toolBudgetBlockedMessage, toolBudgetSoftNudge } from "./tool-budget.js";
@@ -20,6 +20,7 @@ import { inheritedNestedRouteOf } from "./nested-events.js";
20
20
  import { registerWaitTool } from "../background/wait-tool.js";
21
21
  import { drainOutstandingWork } from "../background/auto-drain.js";
22
22
  import { MODEL_ONLY_TOOL } from "../../shared/extension-context.js";
23
+ import { DEFAULT_WAIT_TOOL_NAME, setWaitToolName } from "../../shared/wait-tool-name.js";
23
24
  import { childSupervisorMetadata, evaluateChildToolDiagnostic, } from "./child-runtime-config.js";
24
25
  const STRUCTURED_OUTPUT_INSTRUCTIONS = [
25
26
  "This subagent step has a strict structured output contract.",
@@ -593,6 +594,7 @@ function registerStructuredOutputTool(pi, structured) {
593
594
  label: "Structured Output",
594
595
  description: "Submit the required final structured output for this subagent step. This terminates the step.",
595
596
  parameters,
597
+ prepareArguments: (args) => prepareStructuredOutputArguments(structured.schema, args),
596
598
  async execute(_id, params) {
597
599
  const validation = await validateStructuredOutputValue(structured.schema, params.value);
598
600
  if (validation.status === "invalid") {
@@ -617,7 +619,6 @@ function registerStructuredOutputTool(pi, structured) {
617
619
  },
618
620
  });
619
621
  }
620
- /** Register every child-side hook the prompt runtime owns for one child session. */
621
622
  export default function registerSubagentPromptRuntime(pi, config, drainObservation) {
622
623
  // A path-based load has no ChildRuntimeConfig. This can happen if an
623
624
  // ambient-extension discovery path finds the runtime module in addition to
@@ -655,6 +656,7 @@ export default function registerSubagentPromptRuntime(pi, config, drainObservati
655
656
  };
656
657
  const nestedRootRunId = inheritedNestedRouteOf(config)?.rootRunId;
657
658
  // fanout-child assigns config.hasPendingSupervisorRequest after this hook registers, so read it per wait.
659
+ setWaitToolName(config.waitTool.name ?? DEFAULT_WAIT_TOOL_NAME);
658
660
  if (typeof pi.registerTool === "function")
659
661
  registerWaitTool(pi, waitState, config.waitTool.enabled, undefined, config.waitTool.defaultTimeoutMs, { nestedRootRunId }, () => config.hasPendingSupervisorRequest?.() === true);
660
662
  const supervisorMetadata = childSupervisorMetadata(config);
@@ -1,3 +1,4 @@
1
+ import { waitToolName } from "../../shared/wait-tool-name.js";
1
2
  export const TOOL_TIMEOUT_ENV = "PI_SUBAGENT_TOOL_TIMEOUT_MS";
2
3
  /** Maximum delay a Node.js timer accepts without overflow. */
3
4
  const MAX_TIMER_DELAY_MS = 2_147_483_647;
@@ -16,7 +17,7 @@ export const TOOL_TIMEOUT_EXEMPT_TOOLS = new Set(["contact_supervisor", "interco
16
17
  // Backward-compatible export name for existing callers/tests.
17
18
  export const TOOL_TIMEOUT_ALLOWLIST = TOOL_TIMEOUT_EXEMPT_TOOLS;
18
19
  export function isToolTimeoutExempt(toolName) {
19
- return toolName !== undefined && TOOL_TIMEOUT_EXEMPT_TOOLS.has(toolName);
20
+ return toolName !== undefined && (TOOL_TIMEOUT_EXEMPT_TOOLS.has(toolName) || toolName === waitToolName());
20
21
  }
21
22
  export function defaultToolTimeoutMs(toolName) {
22
23
  return toolName !== undefined && DEFAULT_FAST_TOOL_TIMEOUT_TOOLS.has(toolName)
@@ -68,7 +68,6 @@ interface GitWorktreeRecord {
68
68
  locked?: boolean;
69
69
  }
70
70
  declare function realpathExisting(candidate: string, nativeRealpath?: (filePath: string) => string, fallbackRealpath?: (filePath: string) => string): string;
71
- /** Internal test seam; this is not part of the public subagent tool API. */
72
71
  export declare const __testables: {
73
72
  realpathExisting: typeof realpathExisting;
74
73
  };
@@ -50,7 +50,6 @@ function realpathExisting(candidate, nativeRealpath = fs.realpathSync.native, fa
50
50
  return fallbackRealpath(candidate);
51
51
  }
52
52
  }
53
- /** Internal test seam; this is not part of the public subagent tool API. */
54
53
  export const __testables = { realpathExisting };
55
54
  function comparablePath(candidate) {
56
55
  let current = path.resolve(candidate);
@@ -151,6 +151,9 @@ export declare class WorktreeSetupError extends Error {
151
151
  }
152
152
  /** Later async finalization owners wrap their synchronous diff/cleanup as ONE turn. */
153
153
  export declare function withWorktreeTransaction<T>(action: () => T | Promise<T>): Promise<T>;
154
+ export declare function findListedWorktreeOnBranch(repoCwd: string, branch: string): string | undefined;
155
+ export declare function findListedWorktreeAgentCwd(repoCwd: string, branch: string): string | undefined;
156
+ export declare function isComparablePathInside(parent: string, child: string): boolean;
154
157
  /** Validate a captured patch against the worktree index without changing either. */
155
158
  export declare function validateWorktreePatch(worktreePath: string, patchPath: string): string | undefined;
156
159
  export declare function validateWorktreePatchRepresentsCurrentWorktree(worktreePath: string, baseCommit: string, patchPath: string): string | undefined;
@@ -136,6 +136,26 @@ function runGitChecked(cwd, args) {
136
136
  }
137
137
  return result.stdout;
138
138
  }
139
+ export function findListedWorktreeOnBranch(repoCwd, branch) {
140
+ let current;
141
+ for (const line of runGitChecked(repoCwd, ["worktree", "list", "--porcelain"]).split("\n")) {
142
+ if (line.startsWith("worktree "))
143
+ current = line.slice("worktree ".length);
144
+ else if (line === `branch refs/heads/${branch}` && current)
145
+ return normalizeComparableCwd(current);
146
+ }
147
+ return undefined;
148
+ }
149
+ export function findListedWorktreeAgentCwd(repoCwd, branch) {
150
+ const worktree = findListedWorktreeOnBranch(repoCwd, branch);
151
+ if (!worktree)
152
+ return undefined;
153
+ const cwdRelative = resolveRepoCwdRelative(repoCwd);
154
+ return cwdRelative ? path.join(worktree, cwdRelative) : worktree;
155
+ }
156
+ export function isComparablePathInside(parent, child) {
157
+ return isPathInside(normalizeComparableCwd(parent), normalizeComparableCwd(child));
158
+ }
139
159
  /** Validate a captured patch against the worktree index without changing either. */
140
160
  export function validateWorktreePatch(worktreePath, patchPath) {
141
161
  const result = runGit(worktreePath, [...PATCH_VALIDATION_OPTIONS, patchPath]);
@@ -3,7 +3,7 @@ type TimerApi = {
3
3
  clearTimeout(handle: unknown): void;
4
4
  };
5
5
  export type CapacityResilientJsonWriterOptions = {
6
- /** The underlying write operation. It must be atomic for each target path. */
6
+ /** It must be atomic for each target path. */
7
7
  write?: (filePath: string, payload: object) => void;
8
8
  /** Keep retry timers referenced by the event loop (needed by child runners). */
9
9
  keepAlive?: boolean;
@@ -7,8 +7,7 @@ import type { StreamFn } from "@earendil-works/pi-agent-core";
7
7
  * parent keeps `long`, the same split Claude Code makes between its main
8
8
  * conversation and its subagents.
9
9
  *
10
- * Unset means children inherit the parent's retention, which is the behaviour
11
- * before this setting existed.
10
+ * Unset means children inherit the parent's retention.
12
11
  */
13
12
  export declare function childCacheRetention(env?: NodeJS.ProcessEnv): string | undefined;
14
13
  /**
@@ -6,8 +6,7 @@
6
6
  * parent keeps `long`, the same split Claude Code makes between its main
7
7
  * conversation and its subagents.
8
8
  *
9
- * Unset means children inherit the parent's retention, which is the behaviour
10
- * before this setting existed.
9
+ * Unset means children inherit the parent's retention.
11
10
  */
12
11
  export function childCacheRetention(env = process.env) {
13
12
  return env.PI_SUBAGENT_CACHE_RETENTION || undefined;
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Fleet transcript reading: trusted-path validation, tail reads, and JSONL
3
+ * parsing into display events. Pure data layer — no TUI imports — so both the
4
+ * engine (run status) and the TUI (fleet view) can share one parser.
5
+ */
6
+ export type FleetTranscriptEvent = {
7
+ kind: "assistant";
8
+ text: string;
9
+ model?: string;
10
+ timestamp?: number;
11
+ } | {
12
+ kind: "user";
13
+ text: string;
14
+ timestamp?: number;
15
+ } | {
16
+ kind: "tool";
17
+ toolCallId?: string;
18
+ name: string;
19
+ args?: string;
20
+ argsPayload?: string;
21
+ output?: string;
22
+ outputTruncated?: boolean;
23
+ status: "running" | "complete" | "error";
24
+ error?: string;
25
+ startedAt?: number;
26
+ endedAt?: number;
27
+ timestamp?: number;
28
+ } | {
29
+ kind: "notice";
30
+ text: string;
31
+ tone: "muted" | "warning" | "error";
32
+ timestamp?: number;
33
+ };
34
+ export interface FleetTranscript {
35
+ path: string;
36
+ events: FleetTranscriptEvent[];
37
+ truncated: boolean;
38
+ warning?: string;
39
+ /** The path was refused or the file could not be read, as opposed to a read that only skipped records. */
40
+ readFailed?: true;
41
+ }
42
+ export interface FleetTranscriptReadOptions {
43
+ trustedRoots: string[];
44
+ trustedFiles?: string[];
45
+ trustedFileRoot?: string;
46
+ maxRecords?: number;
47
+ maxBytes?: number;
48
+ }
49
+ export declare function objectValue(value: unknown): Record<string, unknown> | undefined;
50
+ export declare function safeTranscriptEvent(event: FleetTranscriptEvent): FleetTranscriptEvent;
51
+ export declare function readFleetTranscript(filePath: string, options: FleetTranscriptReadOptions): FleetTranscript;