@xzzpig/pi-subagents 0.24.2 → 0.25.1

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 (263) hide show
  1. package/CHANGELOG.md +37 -0
  2. package/bundle/agent-management.js +4 -4
  3. package/bundle/agents.js +3 -3
  4. package/bundle/child-tool-plan.js +2 -2
  5. package/bundle/chunk-34TUUBRN.js +1107 -0
  6. package/bundle/{chunk-SW2VMNIU.js → chunk-5OD3OWTE.js} +2 -2
  7. package/bundle/{chunk-EUPJB4S7.js → chunk-5Z7JAORM.js} +196 -1219
  8. package/bundle/{chunk-LCDJWBVM.js → chunk-66JNFRFS.js} +1 -1
  9. package/bundle/{chunk-ED55MIC2.js → chunk-CGFF4WA3.js} +42 -19
  10. package/bundle/{chunk-TMHVDPYW.js → chunk-DLVPMML3.js} +263 -154
  11. package/bundle/{chunk-RU522D5W.js → chunk-FQPV4O6C.js} +183 -28
  12. package/bundle/chunk-HXRB42AF.js +108 -0
  13. package/bundle/{chunk-355ECEP2.js → chunk-IH7LQVEE.js} +29 -14
  14. package/bundle/{chunk-Z6TFJ6BR.js → chunk-INWSUNI6.js} +1 -1
  15. package/bundle/{chunk-CYY5UMJU.js → chunk-IXCEOEJT.js} +411 -249
  16. package/bundle/{chunk-WW76JRIX.js → chunk-JAXVBXGF.js} +1 -1
  17. package/bundle/{chunk-ICNYIALB.js → chunk-JH5H4CYJ.js} +784 -474
  18. package/bundle/{chunk-224WMDIV.js → chunk-JUYNN63E.js} +350 -123
  19. package/bundle/{chunk-35GII5EF.js → chunk-JWFLPSTP.js} +41 -117
  20. package/bundle/{chunk-XWWUDWUW.js → chunk-KRNBJPZ2.js} +670 -400
  21. package/bundle/{chunk-RB4GELQA.js → chunk-LPJEKHOY.js} +1 -1
  22. package/bundle/chunk-LYKG4FKH.js +523 -0
  23. package/bundle/{chunk-X6LOM3Z4.js → chunk-LZ3HBDTR.js} +161 -78
  24. package/bundle/{chunk-JEA2ZKUA.js → chunk-MMJQMPOK.js} +37 -165
  25. package/bundle/{chunk-FG6SQJAR.js → chunk-OGPOCGWX.js} +24 -6
  26. package/bundle/{chunk-FJWI64H7.js → chunk-RMSABUN3.js} +27 -13
  27. package/bundle/{chunk-H36HBZB2.js → chunk-SJPABBZG.js} +2 -2
  28. package/bundle/{chunk-4UH4WS4G.js → chunk-SNDCIJMK.js} +23 -12
  29. package/bundle/{chunk-O4D5PBVI.js → chunk-TM2K53NX.js} +3 -2
  30. package/bundle/{chunk-3U633XDZ.js → chunk-U3ZDUUTM.js} +11 -3
  31. package/bundle/{chunk-LVWU2HOO.js → chunk-ULGMXABL.js} +16 -7
  32. package/bundle/{chunk-WPW4V6HM.js → chunk-W7ZA6TYD.js} +2 -2
  33. package/bundle/{chunk-BQ2OAB4Q.js → chunk-WWDUNXSE.js} +67 -30
  34. package/bundle/{chunk-V2KFIGFH.js → chunk-XAC2XNAP.js} +503 -304
  35. package/bundle/control-channel.js +2 -2
  36. package/bundle/index.js +1 -1
  37. package/bundle/intercom-bridge.js +2 -2
  38. package/bundle/preflight.js +12 -10
  39. package/bundle/project-panes.js +3 -3
  40. package/bundle/workflow-resources.js +1 -1
  41. package/docs/agents.md +27 -6
  42. package/docs/configuration.md +20 -8
  43. package/docs/extension-api.md +18 -1
  44. package/docs/models.md +6 -2
  45. package/docs/observability.md +2 -0
  46. package/docs/tool-reference.md +7 -1
  47. package/docs/workflows.md +30 -2
  48. package/package.json +2 -2
  49. package/skills/pi-subagents/SKILL.md +15 -6
  50. package/skills/pi-subagents/references/prompting-and-roles.md +1 -0
  51. package/src/agents/agent-management.d.ts +1 -0
  52. package/src/agents/agent-management.js +46 -18
  53. package/src/agents/agent-memory.d.ts +1 -4
  54. package/src/agents/agent-memory.js +1 -4
  55. package/src/agents/agent-serializer.d.ts +2 -0
  56. package/src/agents/agent-serializer.js +1 -1
  57. package/src/agents/agents.d.ts +2 -3
  58. package/src/agents/agents.js +46 -20
  59. package/src/agents/frontmatter.js +1 -8
  60. package/src/agents/global-npm-root.d.ts +1 -0
  61. package/src/agents/global-npm-root.js +11 -3
  62. package/src/agents/skills.d.ts +0 -3
  63. package/src/agents/skills.js +0 -3
  64. package/src/api/preflight.d.ts +3 -1
  65. package/src/api/preflight.js +2 -0
  66. package/src/extension/config.d.ts +1 -0
  67. package/src/extension/config.js +13 -1
  68. package/src/extension/herdr-pi-bridge.js +10 -2
  69. package/src/extension/index.d.ts +0 -13
  70. package/src/extension/index.js +51 -37
  71. package/src/extension/public-execution.d.ts +1 -0
  72. package/src/extension/public-execution.js +4 -0
  73. package/src/extension/reply-workflow-script.js +24 -4
  74. package/src/extension/schemas.d.ts +12 -3
  75. package/src/extension/schemas.js +7 -3
  76. package/src/extension/session-switch.d.ts +25 -0
  77. package/src/extension/session-switch.js +138 -0
  78. package/src/extension/subagent-guide.d.ts +1 -1
  79. package/src/extension/subagent-guide.js +1 -1
  80. package/src/extension/subagent-launch-tool.d.ts +25 -0
  81. package/src/extension/subagent-launch-tool.js +48 -0
  82. package/src/extension/tool-activation.js +55 -15
  83. package/src/extension/tool-description.d.ts +1 -1
  84. package/src/extension/tool-description.js +14 -8
  85. package/src/inspectors/herdr/actions.d.ts +0 -1
  86. package/src/inspectors/herdr/actions.js +0 -1
  87. package/src/inspectors/session-roots-codec.d.ts +0 -1
  88. package/src/inspectors/session-roots-codec.js +0 -1
  89. package/src/inspectors/tmux/actions.d.ts +0 -1
  90. package/src/inspectors/tmux/actions.js +0 -1
  91. package/src/integrations/herdr-status.js +3 -8
  92. package/src/intercom/native-supervisor-channel.js +65 -9
  93. package/src/runs/background/async-execution.d.ts +7 -10
  94. package/src/runs/background/async-execution.js +66 -29
  95. package/src/runs/background/async-job-tracker.js +12 -0
  96. package/src/runs/background/async-resume.d.ts +2 -1
  97. package/src/runs/background/async-resume.js +114 -40
  98. package/src/runs/background/async-retention.d.ts +0 -2
  99. package/src/runs/background/async-retention.js +17 -6
  100. package/src/runs/background/async-status.d.ts +2 -0
  101. package/src/runs/background/async-status.js +4 -0
  102. package/src/runs/background/auto-drain.js +2 -1
  103. package/src/runs/background/boot-id.d.ts +1 -3
  104. package/src/runs/background/boot-id.js +1 -3
  105. package/src/runs/background/completion-batcher.d.ts +3 -4
  106. package/src/runs/background/completion-batcher.js +2 -3
  107. package/src/runs/background/control-channel.d.ts +0 -6
  108. package/src/runs/background/control-channel.js +0 -6
  109. package/src/runs/background/fleet-view.js +2 -3
  110. package/src/runs/background/notify.d.ts +0 -2
  111. package/src/runs/background/notify.js +0 -2
  112. package/src/runs/background/result-watcher.d.ts +1 -0
  113. package/src/runs/background/result-watcher.js +59 -29
  114. package/src/runs/background/resume-guidance.js +4 -2
  115. package/src/runs/background/retained-children.js +2 -1
  116. package/src/runs/background/run-child-session.d.ts +2 -3
  117. package/src/runs/background/run-child-session.js +5 -8
  118. package/src/runs/background/run-status.js +9 -7
  119. package/src/runs/background/runner-aliases.js +15 -0
  120. package/src/runs/background/scheduled-runs.d.ts +3 -1
  121. package/src/runs/background/scheduled-runs.js +13 -16
  122. package/src/runs/background/steering.d.ts +2 -11
  123. package/src/runs/background/steering.js +11 -6
  124. package/src/runs/background/subagent-runner.d.ts +2 -6
  125. package/src/runs/background/subagent-runner.js +88 -70
  126. package/src/runs/background/subagent-wait.js +12 -15
  127. package/src/runs/background/wait-config.d.ts +2 -0
  128. package/src/runs/background/wait-config.js +17 -3
  129. package/src/runs/background/wait-subscriptions.js +124 -12
  130. package/src/runs/background/wait-tool.js +4 -2
  131. package/src/runs/background/workflow-terminal-proof.d.ts +0 -1
  132. package/src/runs/background/workflow-terminal-proof.js +0 -1
  133. package/src/runs/foreground/async-steering-action.js +24 -9
  134. package/src/runs/foreground/async-stop-action.d.ts +1 -1
  135. package/src/runs/foreground/async-stop-action.js +9 -1
  136. package/src/runs/foreground/execution.d.ts +0 -3
  137. package/src/runs/foreground/execution.js +68 -84
  138. package/src/runs/foreground/fork-tool-result-handler.d.ts +60 -0
  139. package/src/runs/foreground/fork-tool-result-handler.js +83 -0
  140. package/src/runs/foreground/prompt-audit.js +1 -0
  141. package/src/runs/foreground/subagent-executor.d.ts +5 -10
  142. package/src/runs/foreground/subagent-executor.js +164 -49
  143. package/src/runs/shared/acceptance.js +69 -26
  144. package/src/runs/shared/async-status-projection.d.ts +2 -0
  145. package/src/runs/shared/async-status-projection.js +10 -0
  146. package/src/runs/shared/child-commands.js +15 -2
  147. package/src/runs/shared/child-hooks.d.ts +1 -7
  148. package/src/runs/shared/child-hooks.js +13 -5
  149. package/src/runs/shared/child-launch.js +6 -2
  150. package/src/runs/shared/child-runtime-config.d.ts +0 -1
  151. package/src/runs/shared/child-session.d.ts +6 -5
  152. package/src/runs/shared/child-session.js +85 -38
  153. package/src/runs/shared/child-tool-plan.d.ts +0 -1
  154. package/src/runs/shared/child-tool-plan.js +0 -1
  155. package/src/runs/shared/claude-code-adapter.js +11 -0
  156. package/src/runs/shared/external-cli-contract.d.ts +49 -0
  157. package/src/runs/shared/external-cli-contract.js +18 -13
  158. package/src/runs/shared/external-cli-runner.js +26 -6
  159. package/src/runs/shared/herdr-connection.js +2 -1
  160. package/src/runs/shared/herdr-pane-host.d.ts +2 -2
  161. package/src/runs/shared/herdr-pane-host.js +17 -1
  162. package/src/runs/shared/herdr-placed-run.js +51 -24
  163. package/src/runs/shared/lane-metadata.d.ts +0 -1
  164. package/src/runs/shared/lane-metadata.js +0 -1
  165. package/src/runs/shared/mcp-config-sources.d.ts +4 -1
  166. package/src/runs/shared/mcp-config-sources.js +1 -1
  167. package/src/runs/shared/mcp-direct-tool-allowlist.d.ts +0 -3
  168. package/src/runs/shared/mcp-direct-tool-allowlist.js +26 -17
  169. package/src/runs/shared/mcp-direct-tool-grant.js +8 -1
  170. package/src/runs/shared/model-resolution-diagnostic.d.ts +0 -1
  171. package/src/runs/shared/model-resolution.d.ts +20 -5
  172. package/src/runs/shared/model-resolution.js +55 -50
  173. package/src/runs/shared/model-scope.d.ts +1 -5
  174. package/src/runs/shared/model-scope.js +1 -5
  175. package/src/runs/shared/mutation-evidence.d.ts +1 -1
  176. package/src/runs/shared/mutation-evidence.js +52 -7
  177. package/src/runs/shared/nested-events.d.ts +1 -0
  178. package/src/runs/shared/nested-events.js +1 -1
  179. package/src/runs/shared/parallel-utils.d.ts +0 -1
  180. package/src/runs/shared/permissions.js +5 -3
  181. package/src/runs/shared/placement-host.d.ts +5 -1
  182. package/src/runs/shared/rex-pane-host.d.ts +0 -1
  183. package/src/runs/shared/rex-pane-host.js +0 -2
  184. package/src/runs/shared/run-launch-folder.d.ts +12 -0
  185. package/src/runs/shared/run-launch-folder.js +21 -0
  186. package/src/runs/shared/runner-launcher.d.ts +12 -1
  187. package/src/runs/shared/runner-launcher.js +16 -0
  188. package/src/runs/shared/single-output.d.ts +3 -3
  189. package/src/runs/shared/single-output.js +5 -3
  190. package/src/runs/shared/structured-output.d.ts +8 -0
  191. package/src/runs/shared/structured-output.js +40 -5
  192. package/src/runs/shared/subagent-prompt-runtime.d.ts +0 -1
  193. package/src/runs/shared/subagent-prompt-runtime.js +18 -4
  194. package/src/runs/shared/supervisor-wait-timer.d.ts +16 -0
  195. package/src/runs/shared/supervisor-wait-timer.js +61 -0
  196. package/src/runs/shared/tool-timeout.js +2 -1
  197. package/src/runs/shared/worktree-cleanup-plan.d.ts +0 -1
  198. package/src/runs/shared/worktree-cleanup-plan.js +0 -1
  199. package/src/runs/shared/worktree.d.ts +3 -0
  200. package/src/runs/shared/worktree.js +20 -0
  201. package/src/shared/artifacts.d.ts +1 -0
  202. package/src/shared/artifacts.js +132 -22
  203. package/src/shared/capacity-resilient-json.d.ts +1 -1
  204. package/src/shared/child-cache-retention.d.ts +1 -2
  205. package/src/shared/child-cache-retention.js +1 -2
  206. package/src/shared/fleet-transcript-reader.d.ts +64 -0
  207. package/src/shared/fleet-transcript-reader.js +376 -0
  208. package/src/shared/formatters.d.ts +0 -18
  209. package/src/shared/formatters.js +0 -18
  210. package/src/shared/pruned-fork.js +2 -2
  211. package/src/shared/reported-progress.d.ts +1 -0
  212. package/src/shared/reported-progress.js +12 -0
  213. package/src/shared/session-succession.d.ts +16 -1
  214. package/src/shared/session-succession.js +41 -2
  215. package/src/shared/session-warnings.d.ts +7 -0
  216. package/src/shared/session-warnings.js +26 -0
  217. package/src/shared/settings.d.ts +0 -23
  218. package/src/shared/settings.js +3 -35
  219. package/src/shared/status-format.d.ts +1 -0
  220. package/src/shared/status-format.js +1 -1
  221. package/src/shared/types.d.ts +108 -59
  222. package/src/shared/types.js +0 -12
  223. package/src/shared/utils.d.ts +3 -15
  224. package/src/shared/utils.js +4 -22
  225. package/src/shared/wait-tool-name.d.ts +8 -0
  226. package/src/shared/wait-tool-name.js +13 -0
  227. package/src/slash/slash-commands.js +2 -1
  228. package/src/slash/subagent-cost.d.ts +3 -2
  229. package/src/slash/subagent-cost.js +22 -3
  230. package/src/slash/subagents-admin.js +0 -1
  231. package/src/tui/fleet-native-transcript.js +1 -1
  232. package/src/tui/fleet-status.d.ts +0 -5
  233. package/src/tui/fleet-status.js +4 -24
  234. package/src/tui/fleet-transcript.d.ts +1 -57
  235. package/src/tui/fleet-transcript.js +4 -370
  236. package/src/tui/fleet.js +6 -4
  237. package/src/tui/render.d.ts +0 -9
  238. package/src/tui/render.js +194 -68
  239. package/src/tui/subagent-messages.js +3 -2
  240. package/src/watchdog/model-selection.js +2 -2
  241. package/src/watchdog/permission-arbiter.js +1 -0
  242. package/src/watchdog/register-child.d.ts +2 -3
  243. package/src/watchdog/register-child.js +2 -3
  244. package/src/watchdog/review.d.ts +0 -5
  245. package/src/watchdog/review.js +4 -3
  246. package/src/watchdog/turn-delta.js +2 -1
  247. package/src/workflows/scripted-workflow.d.ts +2 -0
  248. package/src/workflows/scripted-workflow.js +344 -59
  249. package/src/workflows/structured-workflow-scripts.d.ts +4 -3
  250. package/src/workflows/structured-workflow-scripts.js +32 -11
  251. package/src/workflows/workflow-launch-record.d.ts +15 -6
  252. package/src/workflows/workflow-launch-record.js +30 -12
  253. package/src/workflows/workflow-receipt.js +36 -53
  254. package/src/workflows/workflow-resources.js +4 -4
  255. package/src/workflows/workflow-resume-claim.d.ts +2 -0
  256. package/src/workflows/workflow-resume-claim.js +3 -3
  257. package/src/workflows/workflow-resume.d.ts +1 -1
  258. package/src/workflows/workflow-resume.js +13 -8
  259. package/src/workflows/workflow-script-worker.d.ts +13 -0
  260. package/src/workflows/workflow-script-worker.js +81 -0
  261. package/workflow-script-process.cjs +36 -0
  262. package/workflow-script-worker.cjs +4 -1
  263. package/bundle/chunk-U4ODUYAG.js +0 -235
@@ -12,7 +12,6 @@ export { splitThinkingSuffix };
12
12
  * to, so the virtual selection's provider/id is compared exactly with the launch candidate instead.
13
13
  */
14
14
  export declare function formatSubagentModelVerificationError(expectedModel: string, observedModel: string, availableModels: AvailableModelInfo[] | undefined, modelResponseAliases?: Record<string, string[]>, observedVirtualModel?: string): string | undefined;
15
- /** Sentinel model value requesting that a subagent inherit the parent session's model. */
16
15
  export declare const INHERIT_MODEL = "inherit";
17
16
  /** Minimal shape of the parent session's in-memory model (`ctx.model`). */
18
17
  export interface ParentModel {
@@ -36,18 +35,31 @@ export declare function scopedModelIdsFromContext(ctx: {
36
35
  * repeated separators.
37
36
  */
38
37
  export declare function normalizeModelSegment(segment: string): string;
38
+ /**
39
+ * Every provider in Pi's full catalog, signed in or not, read only when a query's prefix is not an available
40
+ * provider. Without it, a query naming a provider the user is not signed in to would be read as an `owner/name` id
41
+ * and could match that id under another provider (OpenRouter's `anthropic/...` copies), running and billing a
42
+ * different account.
43
+ */
44
+ export type KnownProviders = () => readonly string[];
45
+ /** {@link KnownProviders} for one launch; the full catalog is copied at most once. */
46
+ export declare function knownModelProviders(registry: {
47
+ getAll(): ReadonlyArray<{
48
+ provider: string;
49
+ }>;
50
+ }): KnownProviders;
39
51
  /**
40
52
  * Fuzzy-resolve a base model id (thinking suffix already stripped) against the
41
53
  * registry, tolerating separator, case, and optional date-stamp differences so
42
54
  * users do not have to spell provider/model exactly. A slash is a provider
43
- * prefix only when that prefix is a registered provider; otherwise the whole
55
+ * prefix only when that prefix is a known provider; otherwise the whole
44
56
  * string is the model id (Hugging Face `owner/name`). A qualified provider
45
57
  * query only matches within the named provider — this never silently switches
46
58
  * providers for security/cost-sensitive configs. Returns the matched `fullId`,
47
59
  * or `undefined` when there is no match or the match is ambiguous across
48
60
  * providers (and no `preferredProvider` disambiguates).
49
61
  */
50
- export declare function fuzzyResolveModel(baseModel: string, availableModels: AvailableModelInfo[], preferredProvider?: string): string | undefined;
62
+ export declare function fuzzyResolveModel(baseModel: string, availableModels: AvailableModelInfo[], preferredProvider?: string, knownProviders?: KnownProviders): string | undefined;
51
63
  /**
52
64
  * Resolve a possibly-loose model id to a canonical `provider/id` (plus any
53
65
  * thinking suffix). Exact registry matches win; fuzzy normalization
@@ -55,7 +67,9 @@ export declare function fuzzyResolveModel(baseModel: string, availableModels: Av
55
67
  * spelling differences still resolve. Never switches providers for a qualified
56
68
  * query.
57
69
  */
58
- export declare function resolveModelCandidate(model: string | undefined, availableModels: AvailableModelInfo[] | undefined, preferredProvider?: string): string | undefined;
70
+ export declare function resolveModelCandidate(model: string | undefined, availableModels: AvailableModelInfo[] | undefined, preferredProvider?: string, knownProviders?: KnownProviders): string | undefined;
71
+ /** A configured pin that launch refuses because the registry cannot resolve it. An empty registry checks nothing. */
72
+ export declare function isUnavailableSubagentModel(model: string | undefined, availableModels: AvailableModelInfo[] | undefined, preferredProvider?: string, knownProviders?: KnownProviders): boolean;
59
73
  export interface ResolveSubagentModelOverrideOptions {
60
74
  /** When set with `enforce: true`, out-of-scope models are rejected. */
61
75
  scope?: ModelScopeCheckRule | ModelScopeCheckRule[];
@@ -63,6 +77,7 @@ export interface ResolveSubagentModelOverrideOptions {
63
77
  source?: ModelSource;
64
78
  /** Called for warn-severity violations instead of `console.warn`. */
65
79
  onWarn?: (violation: ModelScopeViolation) => void;
80
+ knownProviders?: KnownProviders;
66
81
  }
67
82
  /**
68
83
  * Resolve the `--model` override passed to a spawned subagent.
@@ -90,8 +105,8 @@ export interface ResolveModelSelectionOptions {
90
105
  onWarn?: (violation: ModelScopeViolation) => void;
91
106
  /** The primary model came from the running parent session, not configuration. */
92
107
  primaryModelFromParent?: boolean;
93
- /** How the model was selected. */
94
108
  origin?: ModelOrigin;
109
+ knownProviders?: KnownProviders;
95
110
  }
96
111
  export declare function resolveModelOrigin(input: {
97
112
  explicitModel?: string | boolean;
@@ -31,7 +31,6 @@ export function formatSubagentModelVerificationError(expectedModel, observedMode
31
31
  }
32
32
  return `model_verification_failed: native Pi child reported a different model than the launch candidate. Expected '${expectedModel}' but observed '${observedModel}'. If you have independently verified this response ID identifies the requested model, declare the exact mapping in modelResponseAliases in ~/.pi/agent/extensions/subagent/config.json (see docs/configuration.md#modelresponsealiases). Use the resolved provider/model ID without its thinking suffix as the key. This leaves the outgoing request unchanged. Configuration changes affect new independent native runs; resumed native runs retain their launch-time declaration. External CLI adapters do not use this setting.`;
33
33
  }
34
- /** Sentinel model value requesting that a subagent inherit the parent session's model. */
35
34
  export const INHERIT_MODEL = "inherit";
36
35
  export function normalizeParentModel(model) {
37
36
  if (!model || typeof model !== "object")
@@ -89,20 +88,26 @@ function stripTrailingDateStamp(segment) {
89
88
  return compact[1];
90
89
  return segment;
91
90
  }
92
- function isRegisteredProvider(provider, availableModels) {
91
+ function isRegisteredProvider(provider, availableModels, knownProviders) {
93
92
  const normalized = normalizeModelSegment(provider);
94
- return availableModels.some((entry) => normalizeModelSegment(entry.provider) === normalized);
93
+ return availableModels.some((entry) => normalizeModelSegment(entry.provider) === normalized)
94
+ || (knownProviders?.().some((name) => normalizeModelSegment(name) === normalized) ?? false);
95
+ }
96
+ /** {@link KnownProviders} for one launch; the full catalog is copied at most once. */
97
+ export function knownModelProviders(registry) {
98
+ let providers;
99
+ return () => providers ??= [...new Set(registry.getAll().map((model) => model.provider))];
95
100
  }
96
101
  /**
97
- * Split `provider/id` only when the first path segment is a registered provider.
102
+ * Split `provider/id` only when the first path segment is a known provider.
98
103
  * Hugging Face-style `owner/name` ids therefore stay intact unless `owner` is
99
- * itself a provider in the active registry. `:` and `.` keep the same rule.
104
+ * itself a provider Pi knows. `:` and `.` keep the same rule.
100
105
  */
101
- function splitQualifiedModelQuery(baseModel, availableModels) {
106
+ function splitQualifiedModelQuery(baseModel, availableModels, knownProviders) {
102
107
  const slashIdx = baseModel.indexOf("/");
103
108
  if (slashIdx !== -1) {
104
109
  const providerPart = baseModel.slice(0, slashIdx);
105
- if (isRegisteredProvider(providerPart, availableModels)) {
110
+ if (isRegisteredProvider(providerPart, availableModels, knownProviders)) {
106
111
  return { queryProvider: normalizeModelSegment(providerPart), queryIdRaw: baseModel.slice(slashIdx + 1) };
107
112
  }
108
113
  return { queryIdRaw: baseModel };
@@ -113,7 +118,7 @@ function splitQualifiedModelQuery(baseModel, availableModels) {
113
118
  if (separatorIdx <= 0)
114
119
  continue;
115
120
  const providerPart = baseModel.slice(0, separatorIdx);
116
- if (!isRegisteredProvider(providerPart, availableModels))
121
+ if (!isRegisteredProvider(providerPart, availableModels, knownProviders))
117
122
  continue;
118
123
  return { queryProvider: normalizeModelSegment(providerPart), queryIdRaw: baseModel.slice(separatorIdx + 1) };
119
124
  }
@@ -130,17 +135,17 @@ function resolveExactIdMatches(baseModel, availableModels, preferredProvider) {
130
135
  return exactMatches[0].fullId;
131
136
  return undefined;
132
137
  }
133
- function resolveBaseModelCandidate(baseModel, availableModels, preferredProvider) {
138
+ function resolveBaseModelCandidate(baseModel, availableModels, preferredProvider, knownProviders) {
134
139
  const exact = availableModels.find((entry) => entry.fullId === baseModel);
135
140
  if (exact)
136
141
  return exact.fullId;
137
- const { queryProvider } = splitQualifiedModelQuery(baseModel, availableModels);
142
+ const { queryProvider } = splitQualifiedModelQuery(baseModel, availableModels, knownProviders);
138
143
  if (queryProvider === undefined) {
139
144
  const exactId = resolveExactIdMatches(baseModel, availableModels, preferredProvider);
140
145
  if (exactId)
141
146
  return exactId;
142
147
  }
143
- const fuzzy = fuzzyResolveModel(baseModel, availableModels, preferredProvider);
148
+ const fuzzy = fuzzyResolveModel(baseModel, availableModels, preferredProvider, knownProviders);
144
149
  if (fuzzy || queryProvider === undefined)
145
150
  return fuzzy;
146
151
  // Some catalogs (OpenRouter's `openrouter/auto-beta`) repeat the provider inside the id.
@@ -152,15 +157,15 @@ function resolveBaseModelCandidate(baseModel, availableModels, preferredProvider
152
157
  * Fuzzy-resolve a base model id (thinking suffix already stripped) against the
153
158
  * registry, tolerating separator, case, and optional date-stamp differences so
154
159
  * users do not have to spell provider/model exactly. A slash is a provider
155
- * prefix only when that prefix is a registered provider; otherwise the whole
160
+ * prefix only when that prefix is a known provider; otherwise the whole
156
161
  * string is the model id (Hugging Face `owner/name`). A qualified provider
157
162
  * query only matches within the named provider — this never silently switches
158
163
  * providers for security/cost-sensitive configs. Returns the matched `fullId`,
159
164
  * or `undefined` when there is no match or the match is ambiguous across
160
165
  * providers (and no `preferredProvider` disambiguates).
161
166
  */
162
- export function fuzzyResolveModel(baseModel, availableModels, preferredProvider) {
163
- const { queryProvider, queryIdRaw } = splitQualifiedModelQuery(baseModel, availableModels);
167
+ export function fuzzyResolveModel(baseModel, availableModels, preferredProvider, knownProviders) {
168
+ const { queryProvider, queryIdRaw } = splitQualifiedModelQuery(baseModel, availableModels, knownProviders);
164
169
  const queryId = normalizeModelSegment(queryIdRaw);
165
170
  const queryIdNoDate = stripTrailingDateStamp(queryId);
166
171
  const candidates = availableModels.filter((entry) => {
@@ -190,40 +195,41 @@ export function fuzzyResolveModel(baseModel, availableModels, preferredProvider)
190
195
  * spelling differences still resolve. Never switches providers for a qualified
191
196
  * query.
192
197
  */
193
- export function resolveModelCandidate(model, availableModels, preferredProvider) {
198
+ export function resolveModelCandidate(model, availableModels, preferredProvider, knownProviders) {
194
199
  if (!model)
195
200
  return undefined;
196
201
  if (!availableModels || availableModels.length === 0)
197
202
  return model;
198
- const resolvedWhole = resolveBaseModelCandidate(model, availableModels, preferredProvider);
203
+ const resolvedWhole = resolveBaseModelCandidate(model, availableModels, preferredProvider, knownProviders);
199
204
  if (resolvedWhole)
200
205
  return resolvedWhole;
201
206
  const { baseModel, thinkingSuffix } = splitThinkingSuffix(model);
202
207
  if (!thinkingSuffix)
203
208
  return model;
204
- const resolvedBase = resolveBaseModelCandidate(baseModel, availableModels, preferredProvider);
209
+ const resolvedBase = resolveBaseModelCandidate(baseModel, availableModels, preferredProvider, knownProviders);
205
210
  if (resolvedBase)
206
211
  return `${resolvedBase}${thinkingSuffix}`;
207
212
  return model;
208
213
  }
209
- function resolveSubagentModelCandidate(model, availableModels, preferredProvider) {
214
+ function resolveSubagentModelCandidate(model, availableModels, preferredProvider, knownProviders) {
210
215
  if (!availableModels || availableModels.length === 0)
211
216
  return model;
212
- const resolvedWhole = resolveBaseModelCandidate(model, availableModels, preferredProvider);
217
+ const resolvedWhole = resolveBaseModelCandidate(model, availableModels, preferredProvider, knownProviders);
213
218
  if (resolvedWhole)
214
219
  return resolvedWhole;
215
220
  const { baseModel, thinkingSuffix } = splitThinkingSuffix(model);
216
- const resolvedBase = thinkingSuffix ? resolveBaseModelCandidate(baseModel, availableModels, preferredProvider) : undefined;
221
+ const resolvedBase = thinkingSuffix ? resolveBaseModelCandidate(baseModel, availableModels, preferredProvider, knownProviders) : undefined;
217
222
  return resolvedBase ? `${resolvedBase}${thinkingSuffix}` : undefined;
218
223
  }
219
- function suggestAlternateProviderModel(model, availableModels) {
224
+ function suggestAlternateProviderModel(model, availableModels, knownProviders) {
220
225
  if (!availableModels || availableModels.length === 0)
221
226
  return undefined;
222
227
  const { baseModel, thinkingSuffix } = splitThinkingSuffix(model);
223
- const { queryProvider, queryIdRaw } = splitQualifiedModelQuery(baseModel, availableModels);
228
+ const { queryProvider, queryIdRaw } = splitQualifiedModelQuery(baseModel, availableModels, knownProviders);
224
229
  if (queryProvider === undefined)
225
230
  return undefined;
226
- const suggestion = resolveBaseModelCandidate(queryIdRaw, availableModels);
231
+ // Without knownProviders the whole query reads as an owner/name id, which finds catalogs such as OpenRouter's `anthropic/...`.
232
+ const suggestion = resolveBaseModelCandidate(queryIdRaw, availableModels) ?? resolveBaseModelCandidate(baseModel, availableModels);
227
233
  if (!suggestion)
228
234
  return undefined;
229
235
  const matched = availableModels.find((entry) => entry.fullId === suggestion);
@@ -233,11 +239,11 @@ function suggestAlternateProviderModel(model, availableModels) {
233
239
  }
234
240
  const MAX_MODEL_CANDIDATES = 5;
235
241
  /** Exact registry ids for an unresolved request: the same id under any provider first, then near spellings. */
236
- function closestModelCandidates(model, availableModels) {
242
+ function closestModelCandidates(model, availableModels, knownProviders) {
237
243
  if (!availableModels || availableModels.length === 0)
238
244
  return [];
239
245
  const { baseModel, thinkingSuffix } = splitThinkingSuffix(model);
240
- const { queryProvider, queryIdRaw } = splitQualifiedModelQuery(baseModel, availableModels);
246
+ const { queryProvider, queryIdRaw } = splitQualifiedModelQuery(baseModel, availableModels, knownProviders);
241
247
  const queryId = normalizeModelSegment(queryIdRaw);
242
248
  const queryIdNoDate = stripTrailingDateStamp(queryId);
243
249
  return availableModels
@@ -257,12 +263,19 @@ function closestModelCandidates(model, availableModels) {
257
263
  .slice(0, MAX_MODEL_CANDIDATES)
258
264
  .map((entry) => `${entry.fullId}${thinkingSuffix}`);
259
265
  }
260
- function resolveRequiredSubagentModelCandidate(model, availableModels, preferredProvider) {
261
- const resolved = resolveSubagentModelCandidate(model, availableModels, preferredProvider);
266
+ /** A configured pin that launch refuses because the registry cannot resolve it. An empty registry checks nothing. */
267
+ export function isUnavailableSubagentModel(model, availableModels, preferredProvider, knownProviders) {
268
+ const trimmed = model?.trim();
269
+ if (!trimmed || trimmed === INHERIT_MODEL || !availableModels?.length)
270
+ return false;
271
+ return resolveSubagentModelCandidate(trimmed, availableModels, preferredProvider, knownProviders) === undefined;
272
+ }
273
+ function resolveRequiredSubagentModelCandidate(model, availableModels, preferredProvider, knownProviders) {
274
+ const resolved = resolveSubagentModelCandidate(model, availableModels, preferredProvider, knownProviders);
262
275
  if (resolved)
263
276
  return resolved;
264
- const suggestion = suggestAlternateProviderModel(model, availableModels);
265
- const candidates = closestModelCandidates(model, availableModels).filter((candidate) => candidate !== suggestion);
277
+ const suggestion = suggestAlternateProviderModel(model, availableModels, knownProviders);
278
+ const candidates = closestModelCandidates(model, availableModels, knownProviders).filter((candidate) => candidate !== suggestion);
266
279
  throw new Error(`Unknown subagent model '${model}' in the active Pi model registry.${suggestion ? ` Did you mean '${suggestion}'?` : ""}${candidates.length ? ` Closest registry models: ${candidates.join(", ")}.` : ""}`);
267
280
  }
268
281
  function defaultScopeWarn(violation) {
@@ -316,25 +329,19 @@ export function resolveSubagentModelOverride(requestedModel, parentModel, availa
316
329
  if (!parentModel)
317
330
  throwForUnresolvedEnforcedReservedScope(options?.scope, explicit === undefined || options?.source === "inherited");
318
331
  let resolved;
319
- let resolvedFromRegistry = explicit === undefined;
320
332
  if (explicit === undefined) {
321
333
  resolved = parentModel ? `${parentModel.provider}/${parentModel.id}` : undefined;
322
334
  }
335
+ else if (options?.source === "explicit") {
336
+ resolved = resolveRequiredSubagentModelCandidate(explicit, availableModels, preferredProvider, options.knownProviders);
337
+ }
323
338
  else {
324
- const candidate = resolveSubagentModelCandidate(explicit, availableModels, preferredProvider);
325
- if (options?.source === "explicit") {
326
- resolved = candidate ?? resolveRequiredSubagentModelCandidate(explicit, availableModels, preferredProvider);
327
- resolvedFromRegistry = true;
328
- }
329
- else if (candidate) {
330
- resolved = candidate;
331
- resolvedFromRegistry = true;
332
- }
333
- else {
334
- resolved = explicit;
335
- }
339
+ resolved = resolveSubagentModelCandidate(explicit, availableModels, preferredProvider, options?.knownProviders);
340
+ // An inherited model the registry does not know passes through unchecked.
341
+ if (!resolved)
342
+ return explicit;
336
343
  }
337
- if (resolved && options?.scope && resolvedFromRegistry) {
344
+ if (resolved && options?.scope) {
338
345
  const source = explicit === undefined ? "inherited" : (options.source ?? "inherited");
339
346
  enforceModelScopes(resolved, options.scope, source, options.onWarn);
340
347
  }
@@ -368,14 +375,12 @@ export function resolveModelSelection(model, availableModels, preferredProvider,
368
375
  const origin = options?.origin ?? (options?.primaryModelFromParent ? "inherited" : "configured");
369
376
  const requestedModel = origin === "inherited" ? undefined : model;
370
377
  const scopes = configuredScopes(options?.scope);
371
- if (origin === "explicit" && model) {
372
- const normalized = resolveRequiredSubagentModelCandidate(model.trim(), availableModels, preferredProvider);
373
- enforceModelScopes(normalized, scopes, "explicit", options?.onWarn);
374
- model = normalized;
378
+ let resolved = model?.trim();
379
+ if (model && (origin === "explicit" || (origin !== "inherited" && !options?.primaryModelFromParent))) {
380
+ resolved = resolveRequiredSubagentModelCandidate(model.trim(), availableModels, preferredProvider, options?.knownProviders);
381
+ if (origin === "explicit")
382
+ enforceModelScopes(resolved, scopes, "explicit", options?.onWarn);
375
383
  }
376
- const resolved = model && (origin === "inherited" || origin === "explicit" || options?.primaryModelFromParent)
377
- ? model.trim()
378
- : model ? resolveRequiredSubagentModelCandidate(model.trim(), availableModels, preferredProvider) : undefined;
379
384
  if (resolved && scopes.some((scope) => scope.enforce === true && scope.strict === true)) {
380
385
  enforceModelScopes(resolved, scopes, "inherited", options?.onWarn);
381
386
  }
@@ -8,9 +8,6 @@
8
8
  * inherited from agent frontmatter / `defaultModel` / the parent session only
9
9
  * emits a warning so existing configurations keep working. Optional strict
10
10
  * enforcement makes inherited models hard errors too.
11
- *
12
- * The decision logic ({@link checkModelScope}) is a pure function of its
13
- * inputs so it can be unit-tested without touching the filesystem or config.
14
11
  */
15
12
  export interface ModelScopeRule {
16
13
  enforce?: boolean;
@@ -60,8 +57,7 @@ export declare function resolveModelScopesForAgent(config: ModelScopeConfig | un
60
57
  } | undefined, scopedModelIds?: readonly string[]): ResolvedModelScope[];
61
58
  /**
62
59
  * Validate and normalize a raw `subagents.modelScope` value from settings.
63
- * Throws a descriptive error for malformed configs (matching the surrounding
64
- * settings-parsing style). Returns `undefined` when the field is absent.
60
+ * Throws a descriptive error for malformed configs. Returns `undefined` when the field is absent.
65
61
  */
66
62
  export declare function parseModelScopeConfig(value: unknown, meta: {
67
63
  filePath: string;
@@ -8,9 +8,6 @@
8
8
  * inherited from agent frontmatter / `defaultModel` / the parent session only
9
9
  * emits a warning so existing configurations keep working. Optional strict
10
10
  * enforcement makes inherited models hard errors too.
11
- *
12
- * The decision logic ({@link checkModelScope}) is a pure function of its
13
- * inputs so it can be unit-tested without touching the filesystem or config.
14
11
  */
15
12
  import { splitKnownThinkingSuffix } from "../../shared/model-info.js";
16
13
  export const SCOPED_PATTERN = "scoped";
@@ -140,8 +137,7 @@ export function resolveModelScopesForAgent(config, agentName, parentModel, scope
140
137
  }
141
138
  /**
142
139
  * Validate and normalize a raw `subagents.modelScope` value from settings.
143
- * Throws a descriptive error for malformed configs (matching the surrounding
144
- * settings-parsing style). Returns `undefined` when the field is absent.
140
+ * Throws a descriptive error for malformed configs. Returns `undefined` when the field is absent.
145
141
  */
146
142
  export function parseModelScopeConfig(value, meta) {
147
143
  if (value === undefined)
@@ -1,6 +1,6 @@
1
1
  import type { ArtifactPaths, TimeoutRecoveryProjection, TimeoutRecoverySummary, TrackedMutationEvidence, TrackedMutationSnapshot } from "../../shared/types.ts";
2
2
  export declare function snapshotTrackedMutations(cwd: string): TrackedMutationSnapshot;
3
- export declare function collectTrackedMutationEvidence(snapshot: TrackedMutationSnapshot, cwd?: string): TrackedMutationEvidence;
3
+ export declare function collectTrackedMutationEvidence(snapshot: TrackedMutationSnapshot, cwd?: string): Promise<TrackedMutationEvidence>;
4
4
  /** Keep status and completion details to bounded routing evidence, not raw output or effects. */
5
5
  export declare function projectTimeoutRecovery(value: unknown): TimeoutRecoveryProjection | undefined;
6
6
  /** Render only the bounded recovery route needed by a parent/operator. */
@@ -1,8 +1,9 @@
1
- import { execFileSync } from "node:child_process";
1
+ import { execFile, execFileSync } from "node:child_process";
2
2
  import { createHash } from "node:crypto";
3
3
  import * as fs from "node:fs";
4
4
  import * as os from "node:os";
5
5
  import * as path from "node:path";
6
+ import { promisify } from "node:util";
6
7
  const MAX_TRACKED_PATHS = 500;
7
8
  const MAX_HASH_BYTES = 1024 * 1024;
8
9
  const MAX_TIMEOUT_FILES = 20;
@@ -13,6 +14,32 @@ function gitArguments(args) {
13
14
  function gitOutput(cwd, args, maxBuffer = MAX_HASH_BYTES) {
14
15
  return execFileSync("git", gitArguments(args), { cwd, encoding: "utf-8", stdio: ["ignore", "pipe", "pipe"], maxBuffer, windowsHide: true });
15
16
  }
17
+ const execFileAsync = promisify(execFile);
18
+ /** The collection path runs while sibling children settle, so git runs off the event loop. */
19
+ async function gitOutputAsync(cwd, args) {
20
+ return (await execFileAsync("git", gitArguments(args), { cwd, encoding: "utf-8", maxBuffer: MAX_HASH_BYTES, windowsHide: true })).stdout;
21
+ }
22
+ /** Yields to the event loop every 2 MiB so hashing a large diff does not stall other work. */
23
+ async function hashFileAsync(diffPath) {
24
+ const hash = createHash("sha256");
25
+ const fd = fs.openSync(diffPath, "r");
26
+ try {
27
+ const buffer = Buffer.alloc(64 * 1024);
28
+ let chunks = 0;
29
+ for (;;) {
30
+ const bytesRead = fs.readSync(fd, buffer, 0, buffer.length, null);
31
+ if (bytesRead === 0)
32
+ break;
33
+ hash.update(bytesRead === buffer.length ? buffer : buffer.subarray(0, bytesRead));
34
+ if (++chunks % 32 === 0)
35
+ await new Promise((resolve) => setImmediate(resolve));
36
+ }
37
+ }
38
+ finally {
39
+ fs.closeSync(fd);
40
+ }
41
+ return hash.digest("hex");
42
+ }
16
43
  function splitNul(output) {
17
44
  return output.split("\0").filter((part) => part.length > 0);
18
45
  }
@@ -41,8 +68,9 @@ function hashLargeDiff(cwd, relativePath) {
41
68
  fs.rmSync(tempDir, { recursive: true, force: true });
42
69
  }
43
70
  }
44
- function listChangedTrackedFiles(cwd) {
45
- const paths = splitNul(gitOutput(cwd, ["diff", "--no-ext-diff", "--name-only", "-z", "HEAD", "--"], MAX_HASH_BYTES));
71
+ const CHANGED_FILES_ARGS = ["diff", "--no-ext-diff", "--name-only", "-z", "HEAD", "--"];
72
+ function changedTrackedFiles(nameOnlyOutput) {
73
+ const paths = splitNul(nameOnlyOutput);
46
74
  return { paths: paths.slice(0, MAX_TRACKED_PATHS), truncated: paths.length > MAX_TRACKED_PATHS };
47
75
  }
48
76
  function fingerprintPath(cwd, relativePath) {
@@ -61,7 +89,7 @@ function sameFingerprint(left, right) {
61
89
  }
62
90
  export function snapshotTrackedMutations(cwd) {
63
91
  try {
64
- const changed = listChangedTrackedFiles(cwd);
92
+ const changed = changedTrackedFiles(gitOutput(cwd, CHANGED_FILES_ARGS));
65
93
  const fingerprints = {};
66
94
  for (const file of changed.paths)
67
95
  fingerprints[file] = fingerprintPath(cwd, file);
@@ -71,12 +99,29 @@ export function snapshotTrackedMutations(cwd) {
71
99
  return { source: "tracked-files", trackedOnly: true, cwd, dirtyFiles: [], fingerprints: {}, unavailable: error instanceof Error ? error.message : String(error) };
72
100
  }
73
101
  }
74
- export function collectTrackedMutationEvidence(snapshot, cwd = snapshot.cwd) {
102
+ async function fingerprintPathAsync(cwd, relativePath) {
103
+ try {
104
+ const diff = await gitOutputAsync(cwd, ["diff", "--no-ext-diff", "--binary", "HEAD", "--", relativePath]);
105
+ return { kind: "diff", digest: createHash("sha256").update(diff).digest("hex") };
106
+ }
107
+ catch {
108
+ const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "pi-mutation-evidence-"));
109
+ try {
110
+ const diffPath = path.join(tempDir, "diff.bin");
111
+ await gitOutputAsync(cwd, ["diff", "--no-ext-diff", "--binary", `--output=${diffPath}`, "HEAD", "--", relativePath]);
112
+ return { kind: "diff", digest: await hashFileAsync(diffPath) };
113
+ }
114
+ finally {
115
+ fs.rmSync(tempDir, { recursive: true, force: true });
116
+ }
117
+ }
118
+ }
119
+ export async function collectTrackedMutationEvidence(snapshot, cwd = snapshot.cwd) {
75
120
  if (snapshot.unavailable) {
76
121
  return { source: "tracked-files", trackedOnly: true, changedFiles: [], attemptedMutation: false, unavailable: snapshot.unavailable };
77
122
  }
78
123
  try {
79
- const current = listChangedTrackedFiles(cwd);
124
+ const current = changedTrackedFiles(await gitOutputAsync(cwd, CHANGED_FILES_ARGS));
80
125
  const startDirty = new Set(snapshot.dirtyFiles);
81
126
  const candidates = new Set([...snapshot.dirtyFiles, ...current.paths]);
82
127
  const changedFiles = [];
@@ -86,7 +131,7 @@ export function collectTrackedMutationEvidence(snapshot, cwd = snapshot.cwd) {
86
131
  changedFiles.push(file);
87
132
  continue;
88
133
  }
89
- if (!sameFingerprint(snapshot.fingerprints[file], fingerprintPath(cwd, file)))
134
+ if (!sameFingerprint(snapshot.fingerprints[file], await fingerprintPathAsync(cwd, file)))
90
135
  changedFiles.push(file);
91
136
  }
92
137
  changedFiles.sort();
@@ -87,6 +87,7 @@ export interface NestedRunResolutionScope {
87
87
  parentStepIndex?: number;
88
88
  };
89
89
  }
90
+ export declare function collectNestedRuns(children: NestedRunSummary[] | undefined, output?: NestedRunSummary[]): NestedRunSummary[];
90
91
  export declare function findNestedRunMatchesById(id: string, options?: {
91
92
  prefix?: boolean;
92
93
  scope?: NestedRunResolutionScope;
@@ -585,7 +585,7 @@ export function retainNestedLookupRoute(state, route, sessionId) {
585
585
  }
586
586
  state.retainedNestedLookupRoutes.routes.set(route.rootRunId, route);
587
587
  }
588
- function collectNestedRuns(children, output = []) {
588
+ export function collectNestedRuns(children, output = []) {
589
589
  for (const child of children ?? []) {
590
590
  output.push(child);
591
591
  collectNestedRuns(child.children, output);
@@ -26,7 +26,6 @@ export interface RunnerSubagentStep {
26
26
  requestId: string;
27
27
  requestDigest: string;
28
28
  };
29
- /** Resolved launch context for this child. */
30
29
  context?: "fresh" | "fork";
31
30
  importAsyncRoot?: {
32
31
  runId: string;
@@ -1,6 +1,8 @@
1
1
  import * as fs from "node:fs";
2
2
  import * as path from "node:path";
3
- const INTERNAL_TOOLS = new Set(["contact_supervisor", "intercom", "bg_wait", "structured_output"]);
3
+ import { DEFAULT_WAIT_TOOL_NAME, waitToolName } from "../../shared/wait-tool-name.js";
4
+ const COORDINATION_TOOLS = new Set(["contact_supervisor", "intercom", "structured_output"]);
5
+ const isInternalTool = (tool) => COORDINATION_TOOLS.has(tool) || tool === waitToolName();
4
6
  const DECISIONS = new Set(["allow", "ask", "deny"]);
5
7
  const MAX_POLICY_BYTES = 16 * 1024;
6
8
  const MAX_PREVIEW_BYTES = 2048;
@@ -20,7 +22,7 @@ export function validatePermissionRules(value, label) {
20
22
  throw new Error(`${label} contains an empty tool name.`);
21
23
  if (tool === "bash")
22
24
  throw new Error(`${label}.bash is unsupported; pi-subagents leaves bash policy to pi-guard.`);
23
- if (INTERNAL_TOOLS.has(tool))
25
+ if (isInternalTool(tool) || tool === DEFAULT_WAIT_TOOL_NAME)
24
26
  throw new Error(`${label}.${tool} is reserved for child coordination and cannot be gated.`);
25
27
  if (!DECISIONS.has(decision))
26
28
  throw new Error(`${label}.${tool} must be allow, ask, or deny.`);
@@ -47,7 +49,7 @@ export function resolvePermissionRules(globalConfig, agentRules) {
47
49
  return Object.keys(merged).length ? merged : undefined;
48
50
  }
49
51
  export function permissionDecision(rules, toolName) {
50
- if (toolName === "bash" || INTERNAL_TOOLS.has(toolName))
52
+ if (toolName === "bash" || isInternalTool(toolName))
51
53
  return "allow";
52
54
  return rules?.[toolName] ?? "allow";
53
55
  }
@@ -39,6 +39,10 @@ export interface PlacementStartOptions {
39
39
  wait(ms: number): Promise<void>;
40
40
  };
41
41
  }
42
+ /** `stopped` ends a pending prompt retry once the run is aborted or disposed, so a refused prompt is never sent after that. */
43
+ export interface PlacementPromptOptions extends PlacementStartOptions {
44
+ stopped?: () => boolean;
45
+ }
42
46
  /** What to start in a new pane; the pane is created in the machine's cwd with this environment. */
43
47
  export interface PlacementLaunchRequest {
44
48
  kind: PlacementAgentKind;
@@ -81,7 +85,7 @@ export interface PlacementPaneHost<C extends PlacementSockets = PlacementSockets
81
85
  owned: PlacementOwnedPane;
82
86
  terminalId: string;
83
87
  }>;
84
- prompt(connection: C, identity: HerdrRunIdentity, text: string): Promise<void>;
88
+ prompt(connection: C, identity: HerdrRunIdentity, text: string, options?: PlacementPromptOptions): Promise<void>;
85
89
  subscribe(connection: C, paneId: string, listener: (event: unknown) => void, onDisconnect: (error: Error) => void): Promise<() => void>;
86
90
  paneEvent(event: unknown, fallback: PlacementRunState): {
87
91
  terminalId: unknown;
@@ -51,7 +51,6 @@ export declare const rexPaneHost: {
51
51
  reconcile: typeof reconcileRexPlacedRun;
52
52
  closeOwnedPane: typeof closeOwnedRexPane;
53
53
  };
54
- /** The placed-run owner bound to Rex and the pane machine's access. */
55
54
  export declare class RexPlacedRunOwner extends PlacedRunOwner<RexConnection, RexMachineReference> {
56
55
  private constructor();
57
56
  /** A Rex SSH owner's machine carries the resolved remote cwd, and its host reconnects only to the session recorded here. */
@@ -40,7 +40,6 @@ function requireRexSuccess(result, what) {
40
40
  if (result.status !== 0)
41
41
  throw new Error(`Rex ${what} exited with code ${result.status}: ${result.stderr.trim().slice(0, 512)}`);
42
42
  }
43
- /** Parses rex's JSON output against its schema; undefined when the shape does not match. */
44
43
  function parseRexJson(text, validator, what) {
45
44
  let value;
46
45
  try {
@@ -284,7 +283,6 @@ function removeRexRuntimeDir(access, runtimeDir) {
284
283
  throw error;
285
284
  }
286
285
  }
287
- /** The placed-run owner bound to Rex and the pane machine's access. */
288
286
  export class RexPlacedRunOwner extends PlacedRunOwner {
289
287
  constructor(machine, runId, runtimeDir, connection, access, host) { super(machine, runId, runtimeDir, connection, host, access, () => removeRexRuntimeDir(access, runtimeDir)); }
290
288
  /** A Rex SSH owner's machine carries the resolved remote cwd, and its host reconnects only to the session recorded here. */
@@ -0,0 +1,12 @@
1
+ /**
2
+ * The parent-owned folder for a run's relaunch records: `async-subagent-launches/<id>/`, beside the
3
+ * runs root that holds the run folder. A runner launcher that isolates a run binds only the run's own
4
+ * folder, so the run cannot rewrite what a later resume starts or under which identity.
5
+ * Callers pass a runs root they know (never one derived from a requested path), because a run can
6
+ * build a runs-shaped tree inside its own folder.
7
+ * A nested run's records stay in its root run's folder (`nested-subagent-runs/<root>/.launches/<id>/`):
8
+ * the child runner that started it writes them, so they add no isolation, and a folder shared by every
9
+ * root run would only mix their records.
10
+ */
11
+ export declare function runLaunchDir(runsRoot: string, runId: string): string;
12
+ export declare function recoveryDescriptorPath(runsRoot: string, runId: string): string;
@@ -0,0 +1,21 @@
1
+ import * as path from "node:path";
2
+ /**
3
+ * The parent-owned folder for a run's relaunch records: `async-subagent-launches/<id>/`, beside the
4
+ * runs root that holds the run folder. A runner launcher that isolates a run binds only the run's own
5
+ * folder, so the run cannot rewrite what a later resume starts or under which identity.
6
+ * Callers pass a runs root they know (never one derived from a requested path), because a run can
7
+ * build a runs-shaped tree inside its own folder.
8
+ * A nested run's records stay in its root run's folder (`nested-subagent-runs/<root>/.launches/<id>/`):
9
+ * the child runner that started it writes them, so they add no isolation, and a folder shared by every
10
+ * root run would only mix their records.
11
+ */
12
+ export function runLaunchDir(runsRoot, runId) {
13
+ if (!runId || runId !== path.basename(runId) || runId === "." || runId === "..")
14
+ throw new Error(`Invalid run id for a launch folder: '${runId}'.`);
15
+ if (path.basename(path.dirname(runsRoot)) === "nested-subagent-runs")
16
+ return path.join(runsRoot, ".launches", runId);
17
+ return path.join(path.dirname(runsRoot), "async-subagent-launches", runId);
18
+ }
19
+ export function recoveryDescriptorPath(runsRoot, runId) {
20
+ return path.join(runLaunchDir(runsRoot, runId), "recovery-descriptor.json");
21
+ }
@@ -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
+ };