pi-subagents 0.82.1 → 0.83.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 (94) hide show
  1. package/CHANGELOG.md +49 -0
  2. package/bundle/agents.js +5 -5
  3. package/bundle/background-work.js +1 -1
  4. package/bundle/capability-ceiling.js +1 -1
  5. package/bundle/child-tool-plan.js +4 -4
  6. package/bundle/{chunk-RMQFMMAT.js → chunk-2D52JFLF.js} +231 -10
  7. package/bundle/{chunk-52UBALJL.js → chunk-2DHZTCOL.js} +2 -2
  8. package/bundle/{chunk-43SCHIMD.js → chunk-2S4K53MV.js} +1 -1
  9. package/bundle/{chunk-IVAE5Z6Q.js → chunk-5YIITCPD.js} +31 -27
  10. package/bundle/{chunk-JYUKW2SY.js → chunk-AHIFYGR3.js} +13 -13
  11. package/bundle/{chunk-XSWOTIA3.js → chunk-C5P5CHYK.js} +1 -1
  12. package/bundle/{chunk-PDZWJCHD.js → chunk-C7JMPU5F.js} +10 -7
  13. package/bundle/{chunk-5TYMSZX3.js → chunk-D3JAFGMO.js} +2 -2
  14. package/bundle/{chunk-OYF6AFDY.js → chunk-F4ASL6OV.js} +2 -2
  15. package/bundle/{chunk-ZIV4J4HG.js → chunk-F5DBXJ2G.js} +51 -34
  16. package/bundle/{chunk-YKEWIB4M.js → chunk-G2Z6ZH26.js} +1 -1
  17. package/bundle/{chunk-G4GZD3OJ.js → chunk-IPGZMQXV.js} +11 -11
  18. package/bundle/{chunk-5LFLVSTM.js → chunk-JEZOSEWG.js} +2 -0
  19. package/bundle/{chunk-PLCCBLPY.js → chunk-LFDBD4PW.js} +2 -2
  20. package/bundle/{chunk-CIZQXJ5Q.js → chunk-LNRJCP2Y.js} +56 -20
  21. package/bundle/{chunk-UTT254JE.js → chunk-MABL3FUM.js} +8 -4
  22. package/bundle/{chunk-3JCDWF4V.js → chunk-NPIYWVOD.js} +12 -18
  23. package/bundle/{chunk-UCPP4GNU.js → chunk-QP5ZWNIS.js} +12 -5
  24. package/bundle/{chunk-Z7KVHQHL.js → chunk-QXASAHIA.js} +2 -2
  25. package/bundle/{chunk-46XKCPJR.js → chunk-RNIZLSEA.js} +2221 -3260
  26. package/bundle/{chunk-GJECHSAR.js → chunk-SSG7IEP5.js} +2 -2
  27. package/bundle/{chunk-VSUSLDNW.js → chunk-UFL7IYCW.js} +10 -8
  28. package/bundle/{chunk-QE4AGIMG.js → chunk-UUP372DR.js} +482 -705
  29. package/bundle/{chunk-6XJB7PIX.js → chunk-UYK5MZWE.js} +16 -12
  30. package/bundle/{chunk-4SDU2BZX.js → chunk-V2BZYLEP.js} +3 -3
  31. package/bundle/{chunk-FXUXCX2K.js → chunk-VLFZIN6D.js} +6 -6
  32. package/bundle/{chunk-N2BN7BF5.js → chunk-XA3DY6UG.js} +7 -5
  33. package/bundle/{chunk-PBK2I7WY.js → chunk-YXFJVCOL.js} +6 -6
  34. package/bundle/{chunk-4Y2ROR7L.js → chunk-ZVOAMTUQ.js} +5 -5
  35. package/bundle/control-channel.js +4 -4
  36. package/bundle/index.js +1 -1
  37. package/bundle/intercom-bridge.js +4 -4
  38. package/bundle/preflight.js +10 -10
  39. package/bundle/project-panes.js +5 -5
  40. package/bundle/shared-types.js +1 -1
  41. package/docs/configuration.md +13 -2
  42. package/docs/extension-api.md +21 -4
  43. package/docs/missions.md +2 -0
  44. package/docs/observability.md +1 -0
  45. package/docs/tool-reference.md +2 -2
  46. package/package.json +1 -1
  47. package/skills/pi-subagents/SKILL.md +6 -6
  48. package/src/agents/agent-management.d.ts +1 -1
  49. package/src/agents/agent-management.js +10 -16
  50. package/src/agents/agent-serializer.js +1 -2
  51. package/src/agents/agents.js +20 -5
  52. package/src/agents/frontmatter.js +22 -18
  53. package/src/api/background-work.d.ts +9 -6
  54. package/src/api/background-work.js +14 -7
  55. package/src/extension/index.js +6 -3
  56. package/src/extension/public-execution.d.ts +2 -2
  57. package/src/extension/public-execution.js +3 -3
  58. package/src/extension/reply-workflow-script.js +4 -5
  59. package/src/extension/rpc.js +3 -1
  60. package/src/extension/subagent-options.js +17 -4
  61. package/src/missions/actions.js +7 -2
  62. package/src/missions/lifecycle.d.ts +11 -0
  63. package/src/missions/lifecycle.js +37 -6
  64. package/src/missions/store.js +1 -0
  65. package/src/missions/types.d.ts +2 -0
  66. package/src/runs/background/async-execution.d.ts +1 -1
  67. package/src/runs/background/async-execution.js +7 -4
  68. package/src/runs/background/async-job-tracker.js +2 -1
  69. package/src/runs/background/async-resume.js +3 -2
  70. package/src/runs/background/auto-drain.js +2 -3
  71. package/src/runs/background/fleet-view.js +1 -1
  72. package/src/runs/background/retained-children.js +1 -1
  73. package/src/runs/background/run-child-session.js +22 -6
  74. package/src/runs/background/subagent-wait.d.ts +2 -1
  75. package/src/runs/background/subagent-wait.js +5 -2
  76. package/src/runs/foreground/execution.js +22 -6
  77. package/src/runs/foreground/subagent-executor.js +26 -56
  78. package/src/runs/shared/capability-ceiling.d.ts +2 -1
  79. package/src/runs/shared/capability-ceiling.js +3 -2
  80. package/src/runs/shared/child-launch.js +5 -2
  81. package/src/runs/shared/child-session.d.ts +6 -0
  82. package/src/runs/shared/child-session.js +20 -4
  83. package/src/runs/shared/herdr-machine.d.ts +2 -0
  84. package/src/runs/shared/herdr-machine.js +2 -0
  85. package/src/runs/shared/herdr-placed-run.js +11 -4
  86. package/src/runs/shared/parallel-handoff.d.ts +1 -1
  87. package/src/runs/shared/parallel-handoff.js +10 -6
  88. package/src/runs/shared/subagent-prompt-runtime.js +11 -17
  89. package/src/shared/disabled-features.d.ts +3 -1
  90. package/src/shared/disabled-features.js +11 -3
  91. package/src/shared/types.d.ts +4 -2
  92. package/src/shared/types.js +2 -0
  93. package/src/workflows/scripted-workflow.js +13 -1071
  94. package/workflow-script-worker.cjs +1068 -0
@@ -10,10 +10,10 @@ import {
10
10
  setInlineWorkflowCoverage,
11
11
  setMainThinkingLevelSource,
12
12
  widgetRenderKey
13
- } from "./chunk-4Y2ROR7L.js";
13
+ } from "./chunk-ZVOAMTUQ.js";
14
14
  import {
15
15
  package_default
16
- } from "./chunk-UTT254JE.js";
16
+ } from "./chunk-MABL3FUM.js";
17
17
  import {
18
18
  EXTERNAL_JOB_BRIDGE_REQUEST_DIR,
19
19
  REVIVAL_ORIGIN_FILE,
@@ -61,7 +61,7 @@ import {
61
61
  snapshotProviderDiagnostics,
62
62
  workflowResumeClaimState,
63
63
  workflowResumeRefusal
64
- } from "./chunk-ZIV4J4HG.js";
64
+ } from "./chunk-F5DBXJ2G.js";
65
65
  import {
66
66
  CONTACT_SUPERVISOR_TOOL_NAME,
67
67
  NATIVE_SUPERVISOR_TOOL_NAME,
@@ -89,14 +89,14 @@ import {
89
89
  resolveWaitToolConfig,
90
90
  setDeclarationPinning,
91
91
  topLevelSupervisorTool
92
- } from "./chunk-VSUSLDNW.js";
92
+ } from "./chunk-UFL7IYCW.js";
93
93
  import {
94
94
  deliverAsyncRunStop,
95
95
  ownerConfirmedDead,
96
96
  readSessionMessagesTail,
97
97
  resolveSubagentRunId,
98
98
  restoreForegroundRunHistory
99
- } from "./chunk-FXUXCX2K.js";
99
+ } from "./chunk-VLFZIN6D.js";
100
100
  import {
101
101
  ASYNC_STATUS_SNAPSHOT_KIND,
102
102
  ASYNC_STATUS_SNAPSHOT_VERSION,
@@ -118,7 +118,7 @@ import {
118
118
  resolveAsyncStatusChild,
119
119
  stopStoppableAsyncStatusChildren,
120
120
  withCachedUiContext
121
- } from "./chunk-6XJB7PIX.js";
121
+ } from "./chunk-UYK5MZWE.js";
122
122
  import "./chunk-NF7IEKBH.js";
123
123
  import {
124
124
  disabledFeatureUseError,
@@ -129,7 +129,7 @@ import {
129
129
  resolveDisabledFeatureSurface,
130
130
  resolveMaxActiveAsyncRunsPerSession,
131
131
  resolveScheduledStoreRoot
132
- } from "./chunk-UCPP4GNU.js";
132
+ } from "./chunk-QP5ZWNIS.js";
133
133
  import {
134
134
  ACTIVE_RUN_INDEX_DIR,
135
135
  MissionNotFoundError,
@@ -178,41 +178,41 @@ import {
178
178
  withWorkflowChildRunModel,
179
179
  writeAsyncResultFile,
180
180
  writeResultIndexForData
181
- } from "./chunk-46XKCPJR.js";
182
- import "./chunk-OYF6AFDY.js";
181
+ } from "./chunk-RNIZLSEA.js";
182
+ import "./chunk-F4ASL6OV.js";
183
183
  import {
184
184
  shouldUseNativeFsWatch
185
185
  } from "./chunk-NIXWDZZV.js";
186
186
  import {
187
187
  validateIntercomBridgeConfig
188
- } from "./chunk-XSWOTIA3.js";
188
+ } from "./chunk-C5P5CHYK.js";
189
189
  import "./chunk-7F6RKT6W.js";
190
- import "./chunk-4SDU2BZX.js";
190
+ import "./chunk-V2BZYLEP.js";
191
191
  import "./chunk-CTPAE36Y.js";
192
192
  import {
193
193
  listHerdrProjectPaneRoots,
194
194
  restoreHerdrProjectPaneSnapshots
195
- } from "./chunk-52UBALJL.js";
195
+ } from "./chunk-2DHZTCOL.js";
196
196
  import "./chunk-7J4ZXMY7.js";
197
197
  import {
198
198
  cleanupAllArtifactDirs,
199
199
  cleanupOldArtifacts,
200
200
  getArtifactPaths,
201
201
  getArtifactsDir
202
- } from "./chunk-5TYMSZX3.js";
202
+ } from "./chunk-D3JAFGMO.js";
203
203
  import {
204
204
  listBackgroundWorkProviders
205
- } from "./chunk-N2BN7BF5.js";
205
+ } from "./chunk-XA3DY6UG.js";
206
206
  import "./chunk-YYREO77V.js";
207
207
  import "./chunk-UKG4V45O.js";
208
208
  import {
209
209
  registerRuntimeAgentEventListener
210
- } from "./chunk-43SCHIMD.js";
210
+ } from "./chunk-2S4K53MV.js";
211
211
  import {
212
212
  clearRuntimeAgentsForPi,
213
213
  listRuntimeAgentConfigs,
214
214
  mergeRuntimeAgents
215
- } from "./chunk-YKEWIB4M.js";
215
+ } from "./chunk-G2Z6ZH26.js";
216
216
  import {
217
217
  DEFAULT_FILE_SYSTEM_RETRY_DELAYS_MS,
218
218
  EXTRA_AGENT_DIRS_ENV,
@@ -252,7 +252,7 @@ import {
252
252
  waitForFileSystemRetry,
253
253
  withSettingsFileLease,
254
254
  writeAtomicJson
255
- } from "./chunk-CIZQXJ5Q.js";
255
+ } from "./chunk-LNRJCP2Y.js";
256
256
  import {
257
257
  DEFAULT_ARTIFACT_CONFIG,
258
258
  DIRS,
@@ -269,13 +269,14 @@ import {
269
269
  SUBAGENT_CHILD_STATUS_EVENT,
270
270
  SUBAGENT_CONTROL_EVENT,
271
271
  SUBAGENT_CONTROL_INTERCOM_EVENT,
272
+ SUBAGENT_JOBS_CHANGED_EVENT,
272
273
  SUBAGENT_LIFECYCLE_ARTIFACT_VERSION,
273
274
  SUBAGENT_PROCESS_TERMINAL_EVENT,
274
275
  SUBAGENT_STEERING_NOTICE_EVENT,
275
276
  WIDGET_ANIMATION_INTERVAL_MS,
276
277
  WIDGET_KEY,
277
278
  resolveMaxSubagentSpawnsPerSession
278
- } from "./chunk-5LFLVSTM.js";
279
+ } from "./chunk-JEZOSEWG.js";
279
280
  import {
280
281
  safeTerminalText,
281
282
  sanitizeDisplayText,
@@ -292,7 +293,7 @@ import {
292
293
  import {
293
294
  isAgentAllowedByCapabilityCeiling,
294
295
  resolveCurrentSubagentCapabilityCeiling
295
- } from "./chunk-Z7KVHQHL.js";
296
+ } from "./chunk-QXASAHIA.js";
296
297
 
297
298
  // src/extension/index.ts
298
299
  import { randomUUID as randomUUID3 } from "node:crypto";
@@ -475,6 +476,7 @@ function createAsyncJobTracker(pi, state, asyncDirRoot, options = {}) {
475
476
  };
476
477
  const rerenderWidget = (ctx, jobs = Array.from(state.asyncJobs.values())) => {
477
478
  options.onJobsChanged?.();
479
+ pi.events.emit(SUBAGENT_JOBS_CHANGED_EVENT, { version: 1 });
478
480
  if (state.widgetsSuspended) return;
479
481
  renderWidget(ctx, options.widgetEnabled === false ? [] : jobs, options.widgetCollapsed, options.widgetLayout);
480
482
  ctx.ui.requestRender?.();
@@ -5180,7 +5182,7 @@ function registerSlashCommands(pi, state, options = {}) {
5180
5182
  }
5181
5183
  fleetOpen = true;
5182
5184
  try {
5183
- const { openSubagentFleet } = await import("./chunk-G4GZD3OJ.js");
5185
+ const { openSubagentFleet } = await import("./chunk-IPGZMQXV.js");
5184
5186
  await openSubagentFleet(ctx, state, { asyncDirRoot: DIRS.async, inspectorPlugins: () => getInspectorPlugins(pi), resultsDir: DIRS.results, fleetKeybindings: options.fleetKeybindings });
5185
5187
  } finally {
5186
5188
  fleetOpen = false;
@@ -7410,8 +7412,10 @@ function pingData(ctx, options) {
7410
7412
  request: SUBAGENT_RPC_REQUEST_EVENT,
7411
7413
  replyPrefix: SUBAGENT_RPC_REPLY_EVENT_PREFIX,
7412
7414
  asyncComplete: SUBAGENT_ASYNC_COMPLETE_EVENT,
7415
+ asyncStarted: SUBAGENT_ASYNC_STARTED_EVENT,
7413
7416
  childStatus: SUBAGENT_CHILD_STATUS_EVENT,
7414
- processTerminal: SUBAGENT_PROCESS_TERMINAL_EVENT
7417
+ processTerminal: SUBAGENT_PROCESS_TERMINAL_EVENT,
7418
+ jobsChanged: SUBAGENT_JOBS_CHANGED_EVENT
7415
7419
  },
7416
7420
  session: sessionData(ctx)
7417
7421
  };
@@ -8567,7 +8571,7 @@ function registerSubagentExtension(pi) {
8567
8571
  const ctx = withLastUiContext((current) => current);
8568
8572
  if (!ctx) return;
8569
8573
  try {
8570
- const { openSubagentFleet } = await import("./chunk-G4GZD3OJ.js");
8574
+ const { openSubagentFleet } = await import("./chunk-IPGZMQXV.js");
8571
8575
  await openSubagentFleet(ctx, state, { initialKey: itemKey, asyncDirRoot: DIRS.async, resultsDir: DIRS.results, fleetKeybindings: config.fleetKeybindings, inspectorPlugins: () => getInspectorPlugins(pi) });
8572
8576
  } catch (error) {
8573
8577
  if (isStaleExtensionContextError(error)) {
@@ -8763,7 +8767,7 @@ function registerSubagentExtension(pi) {
8763
8767
  let executor;
8764
8768
  let executorPromise;
8765
8769
  let executorModulePromise;
8766
- const loadExecutorModule = () => executorModulePromise ??= import("./chunk-QE4AGIMG.js");
8770
+ const loadExecutorModule = () => executorModulePromise ??= import("./chunk-UUP372DR.js");
8767
8771
  const getExecutor = () => {
8768
8772
  executorPromise ??= loadExecutorModule().then(({ createSubagentExecutor }) => {
8769
8773
  executor = createSubagentExecutor(executorDeps);
@@ -8777,7 +8781,7 @@ function registerSubagentExtension(pi) {
8777
8781
  modulePreloadTimer = setTimeout(() => {
8778
8782
  loadExecutorModule().catch(() => {
8779
8783
  });
8780
- if (fleetViewEnabled) import("./chunk-G4GZD3OJ.js").catch(() => {
8784
+ if (fleetViewEnabled) import("./chunk-IPGZMQXV.js").catch(() => {
8781
8785
  });
8782
8786
  }, MODULE_PRELOAD_DELAY_MS);
8783
8787
  modulePreloadTimer.unref?.();
@@ -8800,7 +8804,7 @@ function registerSubagentExtension(pi) {
8800
8804
  );
8801
8805
  });
8802
8806
  const markedMessageTypes = /* @__PURE__ */ new Set([...SUBAGENT_MESSAGE_TYPES, "subagent-compaction-resume", SLASH_RESULT_TYPE, SLASH_TEXT_RESULT_TYPE, ADMIN_MESSAGE_TYPE]);
8803
- pi.on("context", (event) => {
8807
+ pi.on("context_with_system", (event) => {
8804
8808
  const messages = [];
8805
8809
  for (const message2 of event.messages) {
8806
8810
  if (message2.role !== "custom" || !markedMessageTypes.has(message2.customType)) {
@@ -8943,7 +8947,7 @@ ${close}` }]
8943
8947
  const activeRuns = config.activeRunsPrompt === true ? buildActiveRunsSection(state.asyncJobs.values(), sessionId) : void 0;
8944
8948
  if (activeRuns) event.systemPromptOptions.sections.active_subagents = activeRuns;
8945
8949
  if (!event.systemPromptOptions.selectedTools.includes("subagent")) return;
8946
- const catalog = buildAdvertisedAgentCatalog(advertisedAgents, resolveCurrentSubagentCapabilityCeiling(sessionId), recordedPromptSection(pi, "advertised_subagents"));
8950
+ const catalog = buildAdvertisedAgentCatalog(advertisedAgents, resolveCurrentSubagentCapabilityCeiling(ctx.sessionManager.getSessionId() ?? void 0), recordedPromptSection(pi, "advertised_subagents"));
8947
8951
  if (catalog) event.systemPromptOptions.sections.advertised_subagents = catalog;
8948
8952
  });
8949
8953
  registerWaitTool(pi, state, waitToolConfig.enabled, waitSubscriptionManager, waitToolConfig.defaultTimeoutMs, void 0, supervisorChannel.hasPendingRequests);
@@ -9357,7 +9361,7 @@ ${close}` }]
9357
9361
  hasPendingSupervisorRequest: () => [...supervisorChannel.pending.values()].some((request) => request.expectsReply),
9358
9362
  advertisedPrompt: async () => {
9359
9363
  await waitForAdvertisement();
9360
- return buildAdvertisedAgentPrompt(advertisedAgents, resolveCurrentSubagentCapabilityCeiling(state.currentSessionId ?? void 0));
9364
+ return buildAdvertisedAgentPrompt(advertisedAgents, resolveCurrentSubagentCapabilityCeiling(state.supervisorOwnerSessionId ?? void 0));
9361
9365
  }
9362
9366
  });
9363
9367
  }
@@ -1,26 +1,26 @@
1
1
  import {
2
2
  rewriteSubagentPrompt
3
- } from "./chunk-3JCDWF4V.js";
3
+ } from "./chunk-NPIYWVOD.js";
4
4
  import {
5
5
  package_default
6
- } from "./chunk-UTT254JE.js";
7
- import "./chunk-VSUSLDNW.js";
6
+ } from "./chunk-MABL3FUM.js";
7
+ import "./chunk-UFL7IYCW.js";
8
8
  import {
9
9
  MODEL_ONLY_TOOL
10
- } from "./chunk-6XJB7PIX.js";
10
+ } from "./chunk-UYK5MZWE.js";
11
11
  import "./chunk-NF7IEKBH.js";
12
12
  import {
13
13
  appendAgentRefinementOverlay
14
- } from "./chunk-PLCCBLPY.js";
15
- import "./chunk-46XKCPJR.js";
14
+ } from "./chunk-LFDBD4PW.js";
15
+ import "./chunk-RNIZLSEA.js";
16
16
  import "./chunk-NIXWDZZV.js";
17
- import "./chunk-XSWOTIA3.js";
17
+ import "./chunk-C5P5CHYK.js";
18
18
  import "./chunk-7F6RKT6W.js";
19
19
  import {
20
20
  assertNoToolModifierEntries
21
- } from "./chunk-4SDU2BZX.js";
21
+ } from "./chunk-V2BZYLEP.js";
22
22
  import "./chunk-CTPAE36Y.js";
23
- import "./chunk-5TYMSZX3.js";
23
+ import "./chunk-D3JAFGMO.js";
24
24
  import {
25
25
  HERDR_PI_MAX_FRAME_BYTES,
26
26
  HERDR_PI_PROTOCOL,
@@ -30,17 +30,17 @@ import {
30
30
  encodeHerdrPiFrame,
31
31
  validateHerdrPiRunId
32
32
  } from "./chunk-4QFZZV3O.js";
33
- import "./chunk-N2BN7BF5.js";
33
+ import "./chunk-XA3DY6UG.js";
34
34
  import {
35
35
  buildAgentMemoryInjection,
36
36
  buildSkillInjection,
37
37
  discoverAgents,
38
38
  resolveExistingReadPaths,
39
39
  resolveSkills
40
- } from "./chunk-CIZQXJ5Q.js";
41
- import "./chunk-5LFLVSTM.js";
40
+ } from "./chunk-LNRJCP2Y.js";
41
+ import "./chunk-JEZOSEWG.js";
42
42
  import "./chunk-YFCK7H2S.js";
43
- import "./chunk-Z7KVHQHL.js";
43
+ import "./chunk-QXASAHIA.js";
44
44
 
45
45
  // src/extension/herdr-pi-bridge.ts
46
46
  import { spawnSync } from "node:child_process";
@@ -3,7 +3,7 @@ import {
3
3
  } from "./chunk-7F6RKT6W.js";
4
4
  import {
5
5
  getAgentDir
6
- } from "./chunk-CIZQXJ5Q.js";
6
+ } from "./chunk-LNRJCP2Y.js";
7
7
 
8
8
  // src/intercom/intercom-bridge.ts
9
9
  import * as fs from "node:fs";
@@ -1,4 +1,5 @@
1
1
  import {
2
+ PLACED_RESTORE_UNSUPPORTED,
2
3
  REX_BUNDLE_BIN,
3
4
  REX_CALL_TIMEOUT_MS,
4
5
  REX_EXIT_GONE,
@@ -12,10 +13,10 @@ import {
12
13
  rexGlobalArgs,
13
14
  runBoundedCommand,
14
15
  sshMachineAccess
15
- } from "./chunk-RMQFMMAT.js";
16
+ } from "./chunk-2D52JFLF.js";
16
17
  import {
17
18
  package_default
18
- } from "./chunk-UTT254JE.js";
19
+ } from "./chunk-MABL3FUM.js";
19
20
  import {
20
21
  HERDR_PI_MODE_ENV,
21
22
  HERDR_PI_PROTOCOL,
@@ -28,10 +29,10 @@ import {
28
29
  import {
29
30
  getAgentDir,
30
31
  getPiSpawnCommand
31
- } from "./chunk-CIZQXJ5Q.js";
32
- import "./chunk-5LFLVSTM.js";
32
+ } from "./chunk-LNRJCP2Y.js";
33
+ import "./chunk-JEZOSEWG.js";
33
34
  import "./chunk-YFCK7H2S.js";
34
- import "./chunk-Z7KVHQHL.js";
35
+ import "./chunk-QXASAHIA.js";
35
36
 
36
37
  // src/runs/shared/herdr-placed-run.ts
37
38
  import { randomBytes as randomBytes2 } from "node:crypto";
@@ -840,11 +841,11 @@ function safeRunId(value) {
840
841
  return validateHerdrPiRunId(`${prefix}_${randomBytes2(8).toString("hex")}`);
841
842
  }
842
843
  function serializeHerdrPiLaunch(launch) {
843
- if (launch.storage.kind === "file") throw new Error("Pane-native remote Pi does not support fork, resume, or revival; use fresh context.");
844
+ if (launch.storage.kind === "file" && fs3.existsSync(launch.storage.sessionFile)) throw new Error(PLACED_RESTORE_UNSUPPORTED);
844
845
  if (launch.extensionPaths.length || launch.requiredExtensions?.length) throw new Error("Pane-native remote Pi cannot transfer local extension paths; install/configure pi-subagents on the remote machine.");
845
846
  if (launch.processEnv && Object.values(launch.processEnv).some((value) => value !== void 0 && value !== "__none__")) throw new Error("Pane-native remote Pi cannot transfer local bindings, MCP selections, or process environment.");
846
847
  if (launch.runtime.nestedRoute || launch.runtime.fanoutChild || launch.runtime.depth > 1) throw new Error("Nested delegation from a pane-native remote Pi is not supported.");
847
- if (launch.excludeTools?.length || launch.runtime.permissions || launch.runtime.toolBudget || launch.runtime.requiredExtensions || launch.runtime.requiredTools?.length || launch.runtime.mcpDirectTools?.length) throw new Error("Pane-native remote Pi cannot yet represent exclusions, permission rules, tool budgets, MCP direct tools, or required-tool/extension contracts; remove machine placement.");
848
+ if (launch.excludeTools?.length || launch.runtime.permissions || launch.runtime.toolBudget || launch.runtime.requiredExtensions || launch.runtime.mcpDirectTools?.length) throw new Error("Pane-native remote Pi cannot yet represent exclusions, permission rules, tool budgets, MCP direct tools, or required-extension contracts; remove machine placement.");
848
849
  const resources = launch.remoteResources;
849
850
  if (!resources || !/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/u.test(resources.agent) || resources.skills?.some((name) => !/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/u.test(name)) || resources.toolCeiling?.some((name) => !/^[A-Za-z0-9_-]{1,64}$/u.test(name)) || resources.reads !== void 0 && resources.reads !== false && resources.reads.some((read) => typeof read !== "string" || Buffer.byteLength(read) > 4096)) throw new Error("Pane-native remote resources require bounded logical agent, skill, tool, and read names.");
850
851
  const args = [];
@@ -1254,6 +1255,8 @@ async function startPlacedPiSession(launch, owner, policy) {
1254
1255
  const configured = await Promise.race([bridge.configure(policy.resources), bridge.failure]);
1255
1256
  if (configured.nativeSessionId !== manifest.nativeSessionId || configured.agent !== policy.resources.agent) throw new Error("Remote Pi resource resolution identity mismatch.");
1256
1257
  if (!Array.isArray(configured.tools) || policy.resources.toolCeiling && configured.tools.some((tool) => !policy.resources.toolCeiling.includes(String(tool)))) throw new Error("Remote Pi active-tool ceiling acknowledgement mismatch.");
1258
+ const missingRequired = (launch.runtime.requiredTools ?? []).filter((tool) => !configured.tools.includes(tool));
1259
+ if (missingRequired.length) throw new Error(`Remote Pi agent '${policy.resources.agent}' did not activate required tools: ${missingRequired.join(", ")}.`);
1257
1260
  if (launch.model && configured.model !== launch.model.split(":")[0]) throw new Error(`Remote Pi model '${launch.model}' did not resolve to the requested provider/model.`);
1258
1261
  const identity = { runId, machineId: machine.id, target: isRexLocalMachine(machine) ? machine.id : machine.target, session: owner.host.sessionOf(connection), workspaceId: owned.workspaceId, tabId: owned.tabId, paneId: owned.paneId, terminalId, agentName, nativeSessionId: manifest.nativeSessionId, cwd: machine.cwd, runtimeDir };
1259
1262
  owner.journal(identity);
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  getAgentDir
3
- } from "./chunk-CIZQXJ5Q.js";
3
+ } from "./chunk-LNRJCP2Y.js";
4
4
  import {
5
5
  TEMP_ARTIFACTS_DIR
6
- } from "./chunk-5LFLVSTM.js";
6
+ } from "./chunk-JEZOSEWG.js";
7
7
 
8
8
  // src/shared/artifacts.ts
9
9
  import * as fs from "node:fs";
@@ -4,10 +4,10 @@ import {
4
4
  import {
5
5
  resolveWatchPath,
6
6
  writeAtomicJson
7
- } from "./chunk-CIZQXJ5Q.js";
7
+ } from "./chunk-LNRJCP2Y.js";
8
8
  import {
9
9
  POLL_INTERVAL_MS
10
- } from "./chunk-5LFLVSTM.js";
10
+ } from "./chunk-JEZOSEWG.js";
11
11
 
12
12
  // src/runs/background/control-channel.ts
13
13
  import { randomUUID } from "node:crypto";
@@ -11,10 +11,10 @@ import {
11
11
  startWatchdogDiffBaselineCapture,
12
12
  writeUserWatchdogEnabled,
13
13
  writeWatchdogModelSettings
14
- } from "./chunk-VSUSLDNW.js";
14
+ } from "./chunk-UFL7IYCW.js";
15
15
  import {
16
16
  resolveGitRepositoryIdentity
17
- } from "./chunk-FXUXCX2K.js";
17
+ } from "./chunk-VLFZIN6D.js";
18
18
  import {
19
19
  listAsyncRuns,
20
20
  ownsRun,
@@ -22,7 +22,7 @@ import {
22
22
  parseWorkflowChildSummary,
23
23
  readAsyncRecoveryDescriptor,
24
24
  resolveRetainedWorktreeCwd
25
- } from "./chunk-6XJB7PIX.js";
25
+ } from "./chunk-UYK5MZWE.js";
26
26
  import {
27
27
  deepFreezeWorkflowArgs,
28
28
  normalizeWorkflowArgs
@@ -50,21 +50,21 @@ import {
50
50
  resolveMissionStoreLocation,
51
51
  validateMissionId,
52
52
  workflowRunParamsFingerprint
53
- } from "./chunk-46XKCPJR.js";
53
+ } from "./chunk-RNIZLSEA.js";
54
54
  import {
55
55
  requestAsyncCommand,
56
56
  watchAsyncControlInbox
57
- } from "./chunk-OYF6AFDY.js";
57
+ } from "./chunk-F4ASL6OV.js";
58
58
  import {
59
59
  supervisorChannelDir
60
- } from "./chunk-4SDU2BZX.js";
60
+ } from "./chunk-V2BZYLEP.js";
61
61
  import {
62
62
  createHerdrClient,
63
63
  detectHerdr
64
- } from "./chunk-52UBALJL.js";
64
+ } from "./chunk-2DHZTCOL.js";
65
65
  import {
66
66
  getProjectSubagentsDir
67
- } from "./chunk-5TYMSZX3.js";
67
+ } from "./chunk-D3JAFGMO.js";
68
68
  import {
69
69
  ExternalJobProviderError,
70
70
  getExternalJobProvider,
@@ -74,7 +74,7 @@ import {
74
74
  } from "./chunk-YYREO77V.js";
75
75
  import {
76
76
  mergeRuntimeAgents
77
- } from "./chunk-YKEWIB4M.js";
77
+ } from "./chunk-G2Z6ZH26.js";
78
78
  import {
79
79
  CODE_OWNED_EXTERNAL_CLI_ADAPTER_LABEL,
80
80
  PI_CODING_AGENT_PACKAGE,
@@ -129,7 +129,7 @@ import {
129
129
  withFileLease,
130
130
  writeAtomicJson,
131
131
  writePrivateAtomicJson
132
- } from "./chunk-CIZQXJ5Q.js";
132
+ } from "./chunk-LNRJCP2Y.js";
133
133
  import {
134
134
  DIRS,
135
135
  INTERCOM_DETACH_REQUEST_EVENT,
@@ -142,7 +142,7 @@ import {
142
142
  SUBAGENT_FOREGROUND_COMPLETE_EVENT,
143
143
  SUBAGENT_RESULT_INTERCOM_DELIVERY_EVENT,
144
144
  SUBAGENT_RESULT_INTERCOM_EVENT
145
- } from "./chunk-5LFLVSTM.js";
145
+ } from "./chunk-JEZOSEWG.js";
146
146
  import {
147
147
  previewDisplayText,
148
148
  safeTerminalText,
@@ -155,7 +155,7 @@ import {
155
155
  capabilityCeilingAgentRestrictionSources,
156
156
  isAgentAllowedByCapabilityCeiling,
157
157
  resolveCurrentSubagentCapabilityCeiling
158
- } from "./chunk-Z7KVHQHL.js";
158
+ } from "./chunk-QXASAHIA.js";
159
159
 
160
160
  // src/inspectors/herdr/actions.ts
161
161
  import * as fs from "node:fs";
@@ -3199,10 +3199,7 @@ function preservedAgentFrontmatterFields(agent, cfg) {
3199
3199
  if (hasKey(cfg, "extensions")) changed("extensions");
3200
3200
  if (hasKey(cfg, "subagentOnlyExtensions")) changed("subagentOnlyExtensions");
3201
3201
  if (hasKey(cfg, "mutationTools")) changed("mutationTools");
3202
- if (hasKey(cfg, "thinking")) {
3203
- changed("thinking");
3204
- if (cfg.thinking === "off") fields.add("thinking");
3205
- }
3202
+ if (hasKey(cfg, "thinking")) changed("thinking");
3206
3203
  if (hasKey(cfg, "systemPromptMode")) {
3207
3204
  changed("systemPromptMode");
3208
3205
  fields.add("systemPromptMode");
@@ -3358,12 +3355,11 @@ function applyAgentConfig(target, cfg) {
3358
3355
  else return "config.mutationTools must be a comma-separated string, empty string, or false when provided.";
3359
3356
  }
3360
3357
  if (hasKey(cfg, "thinking")) {
3361
- if (cfg.thinking === false || cfg.thinking === "") delete target.thinking;
3362
- else if (typeof cfg.thinking === "string") {
3363
- const thinking = cfg.thinking.trim();
3364
- if (thinking) target.thinking = thinking;
3365
- else delete target.thinking;
3366
- } else return "config.thinking must be a string or false when provided.";
3358
+ const thinking = typeof cfg.thinking === "string" ? cfg.thinking.trim() : cfg.thinking;
3359
+ const level = THINKING_LEVELS.find((candidate) => candidate === thinking);
3360
+ if (thinking === false || thinking === "") delete target.thinking;
3361
+ else if (level) target.thinking = level;
3362
+ else return `config.thinking must be one of ${THINKING_LEVELS.join(", ")}, or false when provided.`;
3367
3363
  }
3368
3364
  if (hasKey(cfg, "systemPromptMode")) {
3369
3365
  if (cfg.systemPromptMode === "append" || cfg.systemPromptMode === "replace") target.systemPromptMode = cfg.systemPromptMode;
@@ -3761,7 +3757,7 @@ function handleList(params, ctx) {
3761
3757
  const d = discoverCatalog(ctx, ctx.cwd, ctx.model?.provider);
3762
3758
  let scopedAgents = effectiveAgentsForScope(scope, d, ctx.runtimeAgentOwner, ctx.model?.provider);
3763
3759
  scopedAgents = scopedAgents.sort((a, b) => a.name.localeCompare(b.name));
3764
- const capabilityCeiling = resolveCurrentSubagentCapabilityCeiling(ctx.currentSessionId);
3760
+ const capabilityCeiling = resolveCurrentSubagentCapabilityCeiling(ctx.piSessionId);
3765
3761
  const visibleAgents = scopedAgents.filter((a) => !a.disabled);
3766
3762
  const agents = visibleAgents.filter((a) => isAgentAllowedByCapabilityCeiling(a.name, capabilityCeiling));
3767
3763
  const restrictedAgents = visibleAgents.filter((a) => !isAgentAllowedByCapabilityCeiling(a.name, capabilityCeiling));
@@ -3813,7 +3809,7 @@ function handleModels(params, ctx) {
3813
3809
  const availableModels = ctx.modelRegistry.getAvailable().map(toModelInfo);
3814
3810
  const currentModel = ctx.model ? { provider: ctx.model.provider, id: ctx.model.id } : void 0;
3815
3811
  const preferredProvider = ctx.model?.provider;
3816
- const capabilityCeiling = resolveCurrentSubagentCapabilityCeiling(ctx.currentSessionId);
3812
+ const capabilityCeiling = resolveCurrentSubagentCapabilityCeiling(ctx.piSessionId);
3817
3813
  let selectedAgents = effectiveAgents;
3818
3814
  if (requestedAgent) {
3819
3815
  const matches = findAgentsInDiscovery(requestedAgent, discovered, scope, ctx.runtimeAgentOwner, ctx.model?.provider);
@@ -7314,11 +7310,14 @@ function resetExtensionCacheOnReload(loader) {
7314
7310
  return true;
7315
7311
  }
7316
7312
  function applyProcessEnv(values) {
7317
- if (!values) return;
7313
+ if (!values) return () => {
7314
+ };
7315
+ const previous = Object.fromEntries(Object.keys(values).map((name) => [name, process.env[name]]));
7318
7316
  for (const [name, value] of Object.entries(values)) {
7319
7317
  if (value === void 0) delete process.env[name];
7320
7318
  else process.env[name] = value;
7321
7319
  }
7320
+ return () => applyProcessEnv(previous);
7322
7321
  }
7323
7322
  function selectedBuiltinMcpExtension(pi, selections, readinessTool) {
7324
7323
  const createMcpExtension = pi.createMcpExtension;
@@ -7534,7 +7533,10 @@ function createDefaultChildSessionFactory(options = {}) {
7534
7533
  await commands?.shutdown();
7535
7534
  const runner = session2.extensionRunner;
7536
7535
  if (runner.hasHandlers("session_shutdown")) {
7537
- await Promise.race([runner.emit({ type: "session_shutdown", reason: "quit" }), new Promise((resolve4) => setTimeout(resolve4, shutdownTimeoutMs).unref?.())]);
7536
+ let bound;
7537
+ await Promise.race([runner.emit({ type: "session_shutdown", reason: "quit" }), new Promise((resolve4) => {
7538
+ bound = setTimeout(resolve4, shutdownTimeoutMs);
7539
+ })]).finally(() => clearTimeout(bound));
7538
7540
  }
7539
7541
  } catch (error2) {
7540
7542
  launch.onExtensionError?.({ extensionPath: "<session>", event: "session_shutdown", error: error2 });
@@ -7543,8 +7545,7 @@ function createDefaultChildSessionFactory(options = {}) {
7543
7545
  }
7544
7546
  };
7545
7547
  let inheritedProviders = /* @__PURE__ */ new Set();
7546
- const open = async () => {
7547
- applyProcessEnv(launch.processEnv);
7548
+ const openSession = async () => {
7548
7549
  if (!resetExtensionCacheOnReload(loader) && (launch.ambientExtensions || launch.extensionPaths.length)) launch.onExtensionError?.({ extensionPath: "<loader>", event: "load", error: new Error("pi's extension cache reset is unavailable; extensions loaded into this child share module state with other sessions in this process.") });
7549
7550
  await loader.reload();
7550
7551
  if (requiredPaths.size > 0) for (const extension of loader.getExtensions().extensions) resolvedExtensionPaths.set(extension.path, extension.resolvedPath);
@@ -7608,6 +7609,14 @@ function createDefaultChildSessionFactory(options = {}) {
7608
7609
  }
7609
7610
  return session2;
7610
7611
  };
7612
+ const open = async () => {
7613
+ const restoreEnv = applyProcessEnv(launch.processEnv);
7614
+ try {
7615
+ return await openSession();
7616
+ } finally {
7617
+ if (launch.restoreProcessEnv) restoreEnv();
7618
+ }
7619
+ };
7611
7620
  const opened = loading.catch(() => {
7612
7621
  }).then(open);
7613
7622
  loading = opened;
@@ -7709,7 +7718,7 @@ function childSessionFactory() {
7709
7718
  }
7710
7719
  function createLazyPlacementFactory(local) {
7711
7720
  let placed;
7712
- const factory = async () => placed ??= (await import("./chunk-PDZWJCHD.js")).createPlacementAwareChildSessionFactory(local);
7721
+ const factory = async () => placed ??= (await import("./chunk-C7JMPU5F.js")).createPlacementAwareChildSessionFactory(local);
7713
7722
  return {
7714
7723
  async create(launch) {
7715
7724
  return launch.machine ? (await factory()).create(launch) : local.create(launch);
@@ -7933,6 +7942,7 @@ function prepareWorkflowResume(input) {
7933
7942
  // src/extension/subagent-options.ts
7934
7943
  import { isDeepStrictEqual } from "node:util";
7935
7944
  import { Compile } from "typebox/compile";
7945
+ import { Value } from "typebox/value";
7936
7946
  var optionKeys = new Set(SUBAGENT_OPTION_KEYS);
7937
7947
  var ALIAS_HINTS = { runId: "id (top-level)", maxRuntimeMs: "options.timeoutMs", isolation: "worktree (top-level)" };
7938
7948
  var optionsValidator = Compile(SubagentOptionParams);
@@ -7944,6 +7954,12 @@ function flattenSubagentToolOptions(params, disabled) {
7944
7954
  if (!options || typeof options !== "object" || Array.isArray(options)) throw new Error("subagent: options must be an object.");
7945
7955
  const removedField = removedModelWorkflowFieldError(options);
7946
7956
  if (removedField) throw new Error(removedField);
7957
+ const { script, ...rest } = options;
7958
+ if (script !== void 0) {
7959
+ if (typeof script !== "string" || !script.trim()) throw new Error("subagent: options.script must be the workflow script's source text.");
7960
+ if (topLevel.workflow !== void 0) throw new Error("subagent: options.script replaces workflow; pass only one of them.");
7961
+ return { ...flattenSubagentToolOptions({ ...topLevel, options: rest }, disabled), workflowScript: script };
7962
+ }
7947
7963
  const entries = Object.entries(options);
7948
7964
  const enabledKeys = SUBAGENT_OPTION_KEYS.filter((key) => !disabled?.params.has(key));
7949
7965
  const unknown = entries.map(([key]) => key).filter((key) => !optionKeys.has(key));
@@ -7959,13 +7975,14 @@ function flattenSubagentToolOptions(params, disabled) {
7959
7975
  }
7960
7976
  const disabledKey = entries.find(([key]) => disabled?.params.has(key))?.[0];
7961
7977
  if (disabledKey) throw new Error(`subagent option 'options.${disabledKey}' is disabled by config ${disabled.params.get(disabledKey)}.`);
7962
- if (!optionsValidator.Check(options)) {
7963
- const errors = [...optionsValidator.Errors(options)].slice(0, 4).map((error2) => `options${error2.instancePath.replaceAll("/", ".")} ${error2.message}`);
7978
+ const converted = Value.Convert(SubagentOptionParams, structuredClone(options));
7979
+ if (!optionsValidator.Check(converted)) {
7980
+ const errors = [...optionsValidator.Errors(converted)].slice(0, 4).map((error2) => `options${error2.instancePath.replaceAll("/", ".")} ${error2.message}`);
7964
7981
  throw new Error(`subagent: ${errors.join("; ")}.`);
7965
7982
  }
7966
- const conflicts = entries.filter(([key, value]) => topLevel[key] !== void 0 && !isDeepStrictEqual(topLevel[key], value)).map(([key]) => `'${key}'`);
7983
+ const conflicts = Object.entries(converted).filter(([key, value]) => topLevel[key] !== void 0 && !isDeepStrictEqual(topLevel[key], value)).map(([key]) => `'${key}'`);
7967
7984
  if (conflicts.length > 0) throw new Error(`subagent: ${conflicts.join(", ")} given both at the top level and in options with different values; give each once.`);
7968
- return { ...topLevel, ...options };
7985
+ return { ...topLevel, ...converted };
7969
7986
  }
7970
7987
 
7971
7988
  // src/runs/background/retained-children.ts
@@ -8009,7 +8026,7 @@ function childResumability(run, step) {
8009
8026
  }
8010
8027
  let requiredCwd;
8011
8028
  try {
8012
- requiredCwd = resolveRetainedWorktreeCwd(parallelHandoffPath(run.asyncDir), run.id, step.index) ?? recoveryDescriptor.cwd ?? run.cwd;
8029
+ requiredCwd = resolveRetainedWorktreeCwd(parallelHandoffPath(run.asyncDir), run.id, step.index, step.worktreePath) ?? recoveryDescriptor.cwd ?? run.cwd;
8013
8030
  if (!requiredCwd || !fs16.statSync(requiredCwd).isDirectory()) return { state: "not-resumable", reason: `required cwd is missing: ${requiredCwd ?? "unknown"}` };
8014
8031
  } catch (error2) {
8015
8032
  return { state: "not-resumable", reason: `resume dependency unavailable: ${error2 instanceof Error ? error2.message : String(error2)}` };
@@ -8,7 +8,7 @@ import {
8
8
  validateCodeOwnedProfileRunner,
9
9
  validatePermissionRules,
10
10
  validateToolBudgetConfig
11
- } from "./chunk-CIZQXJ5Q.js";
11
+ } from "./chunk-LNRJCP2Y.js";
12
12
 
13
13
  // src/agents/runtime-agent-registry.ts
14
14
  var RUNTIME_AGENT_REGISTRY_KEY = "pi-subagents.runtime-agents.v1";