@vicary/pi-subagents 0.85.0 → 0.87.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 (97) hide show
  1. package/CHANGELOG.md +48 -0
  2. package/bundle/agents.js +3 -3
  3. package/bundle/child-tool-plan.js +2 -2
  4. package/bundle/{chunk-O7CPL6H4.js → chunk-2D2DQGC2.js} +9 -9
  5. package/bundle/{chunk-KZ34KQQH.js → chunk-2NY5PCKQ.js} +11 -5
  6. package/bundle/{chunk-PVIVCDG2.js → chunk-3CVOAS77.js} +2 -2
  7. package/bundle/{chunk-N7B2KD74.js → chunk-6O7YH2QV.js} +1 -1
  8. package/bundle/{chunk-B3OOJJA6.js → chunk-75LVXBSA.js} +194 -94
  9. package/bundle/{chunk-H2NLFTC5.js → chunk-BFF6YDK6.js} +1 -1
  10. package/bundle/{chunk-UX4SCV5N.js → chunk-C3KWLXDH.js} +159 -98
  11. package/bundle/{chunk-GCSLVFCX.js → chunk-C5QWQSSM.js} +1 -1
  12. package/bundle/{chunk-KDMFBYFM.js → chunk-ESWW6XSX.js} +1 -1
  13. package/bundle/{chunk-CS4O36CZ.js → chunk-HDICKROY.js} +5 -5
  14. package/bundle/{chunk-JHBQ7N2L.js → chunk-HTI7DD5D.js} +2 -2
  15. package/bundle/{chunk-L2ENOFVZ.js → chunk-LZKVUWIY.js} +66 -26
  16. package/bundle/{chunk-RV5OGHLO.js → chunk-M2VBGET6.js} +2 -2
  17. package/bundle/{chunk-QZL2ZZPM.js → chunk-NJTSXIMG.js} +12 -12
  18. package/bundle/{chunk-YZBCREP5.js → chunk-NMYBVCGP.js} +39 -34
  19. package/bundle/{chunk-A7VJ5XXE.js → chunk-O7A26O6B.js} +8 -6
  20. package/bundle/{chunk-HFTBF7SG.js → chunk-OOE3R7IQ.js} +1 -1
  21. package/bundle/{chunk-LGMILZNE.js → chunk-PGU4TZV3.js} +79 -32
  22. package/bundle/{chunk-VEZMZDTW.js → chunk-PUSTU4Q7.js} +80 -37
  23. package/bundle/{chunk-KEY3UQMQ.js → chunk-SIAQXPJ4.js} +6 -8
  24. package/bundle/{chunk-QO75KJBT.js → chunk-USRX7QXD.js} +2 -2
  25. package/bundle/{chunk-7MAE3DJV.js → chunk-VFUFOZBU.js} +1 -1
  26. package/bundle/{chunk-NF7IEKBH.js → chunk-W2BZS6UC.js} +27 -13
  27. package/bundle/{chunk-T5V5BRCL.js → chunk-W52LJANO.js} +1 -1
  28. package/bundle/{chunk-PHZP3KHB.js → chunk-XSDYTXHF.js} +18 -11
  29. package/bundle/{chunk-LTPH2DXH.js → chunk-XV7RTWTS.js} +3 -3
  30. package/bundle/{chunk-JO67XSKD.js → chunk-YEXKJJVS.js} +12 -7
  31. package/bundle/{chunk-HS4WPO6B.js → chunk-Z4TR7MK6.js} +5 -5
  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 +12 -10
  36. package/bundle/project-panes.js +3 -3
  37. package/bundle/workflow-resources.js +1 -1
  38. package/docs/agents.md +9 -3
  39. package/docs/configuration.md +14 -6
  40. package/docs/extension-api.md +2 -0
  41. package/docs/models.md +6 -2
  42. package/docs/tool-reference.md +3 -0
  43. package/package.json +2 -2
  44. package/skills/pi-subagents/SKILL.md +7 -4
  45. package/skills/pi-subagents/references/prompting-and-roles.md +1 -0
  46. package/src/agents/agent-management.js +10 -6
  47. package/src/agents/agent-serializer.d.ts +2 -0
  48. package/src/agents/agent-serializer.js +1 -1
  49. package/src/agents/agents.js +37 -12
  50. package/src/api/preflight.d.ts +3 -1
  51. package/src/api/preflight.js +2 -0
  52. package/src/extension/index.js +4 -2
  53. package/src/extension/schemas.d.ts +2 -0
  54. package/src/extension/schemas.js +1 -0
  55. package/src/extension/tool-activation.js +10 -1
  56. package/src/extension/tool-description.d.ts +1 -1
  57. package/src/extension/tool-description.js +8 -8
  58. package/src/runs/background/async-execution.d.ts +2 -1
  59. package/src/runs/background/async-execution.js +4 -2
  60. package/src/runs/background/run-status.js +5 -4
  61. package/src/runs/background/runner-aliases.js +15 -0
  62. package/src/runs/background/subagent-runner.js +6 -6
  63. package/src/runs/background/wait-subscriptions.js +124 -12
  64. package/src/runs/foreground/async-stop-action.d.ts +1 -1
  65. package/src/runs/foreground/async-stop-action.js +9 -1
  66. package/src/runs/foreground/execution.js +1 -0
  67. package/src/runs/foreground/subagent-executor.d.ts +1 -0
  68. package/src/runs/foreground/subagent-executor.js +51 -8
  69. package/src/runs/shared/acceptance.js +69 -26
  70. package/src/runs/shared/child-session.d.ts +5 -4
  71. package/src/runs/shared/child-session.js +43 -33
  72. package/src/runs/shared/external-cli-contract.d.ts +49 -0
  73. package/src/runs/shared/external-cli-contract.js +18 -13
  74. package/src/runs/shared/herdr-placed-run.js +3 -2
  75. package/src/runs/shared/mcp-config-sources.d.ts +2 -1
  76. package/src/runs/shared/mcp-config-sources.js +1 -1
  77. package/src/runs/shared/mcp-direct-tool-allowlist.d.ts +0 -1
  78. package/src/runs/shared/mcp-direct-tool-allowlist.js +5 -6
  79. package/src/runs/shared/model-resolution.d.ts +19 -4
  80. package/src/runs/shared/model-resolution.js +50 -51
  81. package/src/runs/shared/structured-output.js +10 -3
  82. package/src/shared/artifacts.js +25 -13
  83. package/src/shared/pruned-fork.js +2 -2
  84. package/src/shared/types.d.ts +71 -48
  85. package/src/tui/render.js +83 -22
  86. package/src/watchdog/model-selection.js +2 -2
  87. package/src/watchdog/review.js +2 -2
  88. package/src/workflows/scripted-workflow.d.ts +2 -0
  89. package/src/workflows/scripted-workflow.js +103 -39
  90. package/src/workflows/structured-workflow-scripts.d.ts +4 -3
  91. package/src/workflows/structured-workflow-scripts.js +32 -11
  92. package/src/workflows/workflow-receipt.js +36 -53
  93. package/src/workflows/workflow-resources.js +4 -4
  94. package/src/workflows/workflow-resume-claim.d.ts +2 -0
  95. package/src/workflows/workflow-resume-claim.js +1 -1
  96. package/src/workflows/workflow-resume.d.ts +1 -1
  97. package/src/workflows/workflow-resume.js +3 -1
@@ -3,7 +3,7 @@ import {
3
3
  projectRuntimeAcknowledgedExtensions,
4
4
  registerSubagentPromptBoundary,
5
5
  registerSubagentPromptRuntime
6
- } from "./chunk-HS4WPO6B.js";
6
+ } from "./chunk-Z4TR7MK6.js";
7
7
  import {
8
8
  INSPECTOR_ACTIONS,
9
9
  canQueueRetainedAsyncFollowUp,
@@ -25,12 +25,12 @@ import {
25
25
  updateSteeringTarget,
26
26
  waitForSteeringAction,
27
27
  workflowAsyncChildSteeringGuidance
28
- } from "./chunk-CS4O36CZ.js";
28
+ } from "./chunk-HDICKROY.js";
29
29
  import {
30
30
  PLACED_RESTORE_UNSUPPORTED,
31
31
  formatHerdrMachineRunnerUnsupported,
32
32
  resolveMachinePlacement
33
- } from "./chunk-N7B2KD74.js";
33
+ } from "./chunk-6O7YH2QV.js";
34
34
  import {
35
35
  COMPLETION_ACTION,
36
36
  DEFAULT_CONTROL_CONFIG,
@@ -119,7 +119,7 @@ import {
119
119
  workflowScriptDigest,
120
120
  workflowStopCause,
121
121
  writeWorkflowReceipt
122
- } from "./chunk-B3OOJJA6.js";
122
+ } from "./chunk-75LVXBSA.js";
123
123
  import {
124
124
  SUBAGENT_PARENT_SESSION_ENV,
125
125
  applyWatchdogLaunchRules,
@@ -132,7 +132,7 @@ import {
132
132
  resolveWatchdogConfig,
133
133
  sendRuleViolationWarning,
134
134
  writeWatchdogModelSettings
135
- } from "./chunk-A7VJ5XXE.js";
135
+ } from "./chunk-O7A26O6B.js";
136
136
  import {
137
137
  MAX_REMEMBERED_FOREGROUND_RUNS,
138
138
  discardRunningForegroundRun,
@@ -145,7 +145,7 @@ import {
145
145
  resolveSubagentRunId,
146
146
  resolveWorkflowChatProgress,
147
147
  stopAsyncRun
148
- } from "./chunk-KZ34KQQH.js";
148
+ } from "./chunk-2NY5PCKQ.js";
149
149
  import {
150
150
  RunFanoutLimitError,
151
151
  annotateWorkflowPreflightTrace,
@@ -206,12 +206,12 @@ import {
206
206
  writeRunFanoutBudgetDescriptor,
207
207
  writeWorkflowLaunchRecord,
208
208
  writeWorktreeSetupHandoff
209
- } from "./chunk-LTPH2DXH.js";
209
+ } from "./chunk-XV7RTWTS.js";
210
210
  import {
211
211
  NATIVE_SUPERVISOR_TOOL_NAME,
212
212
  createNativeSupervisorChannel,
213
213
  resolveSupervisorChannelDir
214
- } from "./chunk-T5V5BRCL.js";
214
+ } from "./chunk-W52LJANO.js";
215
215
  import {
216
216
  MODEL_ONLY_TOOL,
217
217
  inheritedSessionIds,
@@ -228,16 +228,16 @@ import {
228
228
  resolveStructuredWorkflowResource,
229
229
  resolveWorkflowResource,
230
230
  validateWorkflowChildPermitRoot
231
- } from "./chunk-NF7IEKBH.js";
231
+ } from "./chunk-W2BZS6UC.js";
232
232
  import {
233
233
  buildEffectiveSystemPrompt,
234
234
  canPreferFork,
235
235
  createForkContextResolver,
236
236
  resolveSubagentLaunchContext
237
- } from "./chunk-JHBQ7N2L.js";
237
+ } from "./chunk-HTI7DD5D.js";
238
238
  import {
239
239
  handleRefinementAction
240
- } from "./chunk-QO75KJBT.js";
240
+ } from "./chunk-USRX7QXD.js";
241
241
  import {
242
242
  ActiveAsyncCapacityError,
243
243
  acquireActiveAsyncCapacity,
@@ -252,7 +252,7 @@ import {
252
252
  resolveDisabledFeatureSurface,
253
253
  resolveMaxActiveAsyncRunsPerSession,
254
254
  transferActiveAsyncCapacity
255
- } from "./chunk-RV5OGHLO.js";
255
+ } from "./chunk-M2VBGET6.js";
256
256
  import {
257
257
  DEFAULT_STALE_TERMINAL_ACTIVE_MARKER_MS,
258
258
  MACHINE_DIFF_OPTIONS,
@@ -338,7 +338,7 @@ import {
338
338
  writeNestedControlRequest,
339
339
  writeNestedControlResult,
340
340
  writeNestedEvent
341
- } from "./chunk-LGMILZNE.js";
341
+ } from "./chunk-PGU4TZV3.js";
342
342
  import {
343
343
  closeSteerInbox,
344
344
  consumeSteerRequests,
@@ -346,7 +346,7 @@ import {
346
346
  readRevivalBriefs,
347
347
  requestAsyncSteer,
348
348
  watchAsyncControlInbox
349
- } from "./chunk-7MAE3DJV.js";
349
+ } from "./chunk-VFUFOZBU.js";
350
350
  import "./chunk-NIXWDZZV.js";
351
351
  import {
352
352
  INTERCOM_BRIDGE_MARKER,
@@ -355,7 +355,7 @@ import {
355
355
  resolveIntercomBridge,
356
356
  resolveIntercomSessionTarget,
357
357
  resolveSubagentIntercomTarget
358
- } from "./chunk-KDMFBYFM.js";
358
+ } from "./chunk-ESWW6XSX.js";
359
359
  import {
360
360
  agentDefinitionDigest,
361
361
  resolveLaunchBinding,
@@ -370,7 +370,7 @@ import {
370
370
  resolvePiLaunchToolPlan,
371
371
  resolveRuntimeModulePath,
372
372
  supervisorChannelDir
373
- } from "./chunk-KEY3UQMQ.js";
373
+ } from "./chunk-SIAQXPJ4.js";
374
374
  import {
375
375
  assertRequiredChildExtensionsAdmitted,
376
376
  hasMandatoryRequiredChildExtensions,
@@ -381,7 +381,7 @@ import {
381
381
  import {
382
382
  HERDR_PROJECT_PANE_ACTIONS,
383
383
  handleHerdrProjectPaneAction
384
- } from "./chunk-PVIVCDG2.js";
384
+ } from "./chunk-3CVOAS77.js";
385
385
  import "./chunk-7J4ZXMY7.js";
386
386
  import {
387
387
  PROJECT_SUBAGENTS_RELATIVE_DIR,
@@ -394,12 +394,12 @@ import {
394
394
  getProjectSubagentsDir,
395
395
  writeArtifact,
396
396
  writeMetadata
397
- } from "./chunk-PHZP3KHB.js";
397
+ } from "./chunk-XSDYTXHF.js";
398
398
  import "./chunk-XA3DY6UG.js";
399
399
  import {
400
400
  getExternalJobProvider
401
401
  } from "./chunk-YYREO77V.js";
402
- import "./chunk-GCSLVFCX.js";
402
+ import "./chunk-C5QWQSSM.js";
403
403
  import {
404
404
  ChainOutputValidationError,
405
405
  DEFAULT_WAIT_TOOL_NAME,
@@ -485,6 +485,7 @@ import {
485
485
  isSettlementFatalOutputError,
486
486
  isStorageCapacityError,
487
487
  isToolBudgetBlockedMessage,
488
+ knownModelProviders,
488
489
  normalizeAcceptanceInput,
489
490
  normalizeExtensionBindings,
490
491
  normalizeExternalCliRunnerStatus,
@@ -550,7 +551,7 @@ import {
550
551
  writeAtomicJson,
551
552
  writeInitialProgressFile,
552
553
  writePrivateAtomicJson
553
- } from "./chunk-UX4SCV5N.js";
554
+ } from "./chunk-C3KWLXDH.js";
554
555
  import {
555
556
  CHAIN_RUNS_DIR,
556
557
  DEFAULT_ARTIFACT_CONFIG,
@@ -2330,7 +2331,7 @@ function buildAsyncRunnerSteps(id, params) {
2330
2331
  ctx.currentModel,
2331
2332
  availableModels,
2332
2333
  a.modelProvider ?? ctx.currentModelProvider,
2333
- { scope: modelScopes, source: modelOrigin === "explicit" ? "explicit" : "inherited" }
2334
+ { scope: modelScopes, source: modelOrigin === "explicit" ? "explicit" : "inherited", knownProviders: ctx.knownProviders }
2334
2335
  );
2335
2336
  const thinkingOverride = flatIndex === void 0 ? void 0 : thinkingOverridesByFlatIndex?.[flatIndex];
2336
2337
  let claudeCodeOverride;
@@ -2374,7 +2375,8 @@ function buildAsyncRunnerSteps(id, params) {
2374
2375
  const modelEvidence = resolveModelSelection(primaryModel, availableModels, a.modelProvider ?? ctx.currentModelProvider, {
2375
2376
  scope: modelScopes,
2376
2377
  primaryModelFromParent,
2377
- origin: modelOrigin
2378
+ origin: modelOrigin,
2379
+ knownProviders: ctx.knownProviders
2378
2380
  });
2379
2381
  requestedModel = modelEvidence.requestedModel;
2380
2382
  selectedModel = applyThinkingSuffix(modelEvidence.model, effectiveThinking, thinkingOverride !== void 0);
@@ -3108,7 +3110,7 @@ function executeAsyncSingle(id, params) {
3108
3110
  ctx.currentModel,
3109
3111
  availableModels,
3110
3112
  ctx.currentModelProvider,
3111
- { scope: modelScopes, source: modelOrigin === "explicit" ? "explicit" : "inherited" }
3113
+ { scope: modelScopes, source: modelOrigin === "explicit" ? "explicit" : "inherited", knownProviders: ctx.knownProviders }
3112
3114
  );
3113
3115
  } catch (error) {
3114
3116
  return formatAsyncStartError("single", error instanceof Error ? error.message : String(error));
@@ -3169,7 +3171,8 @@ function executeAsyncSingle(id, params) {
3169
3171
  const modelEvidence = resolveModelSelection(primaryModel, availableModels, agentConfig.modelProvider ?? ctx.currentModelProvider, {
3170
3172
  scope: modelScopes,
3171
3173
  primaryModelFromParent: modelOrigin === "inherited",
3172
- origin: modelOrigin
3174
+ origin: modelOrigin,
3175
+ knownProviders: ctx.knownProviders
3173
3176
  });
3174
3177
  requestedModel = modelEvidence.requestedModel;
3175
3178
  selectedModel = applyThinkingSuffix(modelEvidence.model, effectiveThinking, params.thinkingOverride !== void 0);
@@ -6651,7 +6654,8 @@ ${acceptancePrompt}` : task;
6651
6654
  {
6652
6655
  scope: options.modelScope,
6653
6656
  primaryModelFromParent: options.modelOverrideFromParent,
6654
- origin: options.modelOrigin ?? (options.modelOverrideFromParent ? "inherited" : "configured")
6657
+ origin: options.modelOrigin ?? (options.modelOverrideFromParent ? "inherited" : "configured"),
6658
+ knownProviders: options.knownProviders
6655
6659
  }
6656
6660
  );
6657
6661
  try {
@@ -7557,7 +7561,7 @@ async function createPrunedForkSessionWriter(ctx, config, signal) {
7557
7561
  };
7558
7562
  if (!config.model?.trim()) throw new Error("Pruned fork context requires config.forkContext.model.");
7559
7563
  const available = ctx.modelRegistry.getAvailable();
7560
- const resolved = resolveModelCandidate(config.model.trim(), available.map(toModelInfo), ctx.model?.provider);
7564
+ const resolved = resolveModelCandidate(config.model.trim(), available.map(toModelInfo), ctx.model?.provider, knownModelProviders(ctx.modelRegistry));
7561
7565
  if (!resolved) throw new Error(`Pruned fork model '${config.model}' did not match exactly one available model.`);
7562
7566
  const { baseModel } = splitKnownThinkingSuffix(resolved);
7563
7567
  const named = splitProviderModel(baseModel);
@@ -8873,10 +8877,11 @@ Extensions denied: ${status.capabilityCeiling.denyExtensions ? "yes" : "no"} (so
8873
8877
  lines.push(` Runner: external-cli (${runner.command}${runner.args.length ? ` ${runner.args.join(" ")}` : ""})`);
8874
8878
  lines.push(` Adapter: ${runner.adapter.id} v${runner.adapter.version} (${runner.adapter.executionMode})`);
8875
8879
  if (runner.safety) {
8876
- if ("approvalPolicy" in runner.safety) lines.push(` Safety: ${"access" in runner.safety ? `access=${runner.safety.access}, ` : ""}sandbox=${runner.safety.sandbox}, approval=${runner.safety.approvalPolicy}, ephemeral=${runner.safety.ephemeral}`);
8877
- else if ("mode" in runner.safety) lines.push(` Safety: access=${runner.safety.access}, auth=${runner.safety.authentication}, mode=${runner.safety.mode}, sandbox=${runner.safety.sandbox}, workspaceTrust=${runner.safety.workspaceTrust}, sessionReuse=${runner.safety.sessionReuse}`);
8878
- else if ("authentication" in runner.safety) lines.push(` Safety: access=${runner.safety.access}, auth=${runner.safety.authentication}, permission=${runner.safety.permissionMode}, tools=${runner.safety.tools}, mcp=${runner.safety.mcp}, settings=${runner.safety.settingSources}, settingsTrust=${runner.safety.userSettingsTrust}, persistence=${runner.safety.sessionPersistence}`);
8879
- else lines.push(` Safety: access=read-only, permission=${runner.safety.permissionMode}, tools=${runner.safety.tools}, mcp=${runner.safety.mcp}, settings=${runner.safety.settingSources}, persistence=${runner.safety.sessionPersistence}`);
8880
+ const safetyLabel = " Safety (adapter profile, not measured):";
8881
+ if ("approvalPolicy" in runner.safety) lines.push(`${safetyLabel} ${"access" in runner.safety ? `access=${runner.safety.access}, ` : ""}sandbox=${runner.safety.sandbox}, approval=${runner.safety.approvalPolicy}, ephemeral=${runner.safety.ephemeral}`);
8882
+ else if ("mode" in runner.safety) lines.push(`${safetyLabel} access=${runner.safety.access}, auth=${runner.safety.authentication}, mode=${runner.safety.mode}, sandbox=${runner.safety.sandbox}, workspaceTrust=${runner.safety.workspaceTrust}, sessionReuse=${runner.safety.sessionReuse}`);
8883
+ else if ("authentication" in runner.safety) lines.push(`${safetyLabel} access=${runner.safety.access}, auth=${runner.safety.authentication}, permission=${runner.safety.permissionMode}, tools=${runner.safety.tools}, mcp=${runner.safety.mcp}, settings=${runner.safety.settingSources}, settingsTrust=${runner.safety.userSettingsTrust}, persistence=${runner.safety.sessionPersistence}`);
8884
+ else lines.push(`${safetyLabel} access=read-only, permission=${runner.safety.permissionMode}, tools=${runner.safety.tools}, mcp=${runner.safety.mcp}, settings=${runner.safety.settingSources}, persistence=${runner.safety.sessionPersistence}`);
8880
8885
  }
8881
8886
  lines.push(` Capabilities: stop=${runner.capabilities.stop}, steer=false, resume=false, structuredOutput=false, toolEvents=false, supervisor=unsupported, forkContext=false, extensionBindings=false`);
8882
8887
  lines.push(` Unsupported steer: ${runner.unsupportedReasons.steer}`);
@@ -10660,6 +10665,7 @@ function appendStepToAsyncChain(input) {
10660
10665
  parentProviderRegistry: input.ctx.modelRegistry,
10661
10666
  currentModel: parentModel,
10662
10667
  scopedModelIds: scopedModelIdsFromContext(input.ctx),
10668
+ knownProviders: knownModelProviders(input.ctx.modelRegistry),
10663
10669
  modelScope: discoveredForAppend.modelScope,
10664
10670
  modelResponseAliases: input.deps.config.modelResponseAliases,
10665
10671
  interactive: input.ctx.hasUI,
@@ -11063,6 +11069,7 @@ async function resumeExternalJobFollowUp(input) {
11063
11069
  parentProviderRegistry: input.ctx.modelRegistry,
11064
11070
  currentModel: parentModel,
11065
11071
  scopedModelIds: scopedModelIdsFromContext(input.ctx),
11072
+ knownProviders: knownModelProviders(input.ctx.modelRegistry),
11066
11073
  modelScope: input.modelScope,
11067
11074
  modelResponseAliases: input.deps.config.modelResponseAliases,
11068
11075
  interactive: input.ctx.hasUI,
@@ -11341,6 +11348,7 @@ async function resumeAsyncRun(input) {
11341
11348
  parentProviderRegistry: input.ctx.modelRegistry,
11342
11349
  currentModel: parentModel2,
11343
11350
  scopedModelIds: scopedModelIdsFromContext(input.ctx),
11351
+ knownProviders: knownModelProviders(input.ctx.modelRegistry),
11344
11352
  modelScope,
11345
11353
  modelResponseAliases: input.deps.config.modelResponseAliases,
11346
11354
  runnerLaunchers: input.deps.config.runnerLaunchers,
@@ -11466,6 +11474,7 @@ async function resumeAsyncRun(input) {
11466
11474
  parentProviderRegistry: input.ctx.modelRegistry,
11467
11475
  currentModel: parentModel,
11468
11476
  scopedModelIds: scopedModelIdsFromContext(input.ctx),
11477
+ knownProviders: knownModelProviders(input.ctx.modelRegistry),
11469
11478
  modelScope,
11470
11479
  // Absence in the retained contract is meaningful; never acquire current aliases.
11471
11480
  modelResponseAliases: recoveryDescriptor ? recoveryDescriptor.modelResponseAliases : foregroundContract?.modelResponseAliases,
@@ -12234,7 +12243,7 @@ function resolveStaticLaunchSummary(input) {
12234
12243
  input.parentModel,
12235
12244
  input.availableModels,
12236
12245
  agentConfig?.modelProvider ?? input.currentProvider,
12237
- modelScopes.length === 0 ? {} : { scope: modelScopes }
12246
+ { scope: modelScopes, knownProviders: input.knownProviders }
12238
12247
  );
12239
12248
  const thinkingOverride = externalRunner ? void 0 : input.thinkingOverrideForTask();
12240
12249
  const thinking = externalRunner ? void 0 : resolveEffectiveThinking(model, thinkingOverride ?? agentConfig?.thinking);
@@ -12253,6 +12262,7 @@ function collectStaticLaunchSummaries(input) {
12253
12262
  parentModel: input.parentModel,
12254
12263
  scopedModelIds: input.scopedModelIds,
12255
12264
  availableModels: input.availableModels,
12265
+ knownProviders: input.knownProviders,
12256
12266
  currentProvider: input.currentProvider,
12257
12267
  modelScope: input.modelScope,
12258
12268
  thinkingOverrideForTask: input.thinkingOverrideForTask
@@ -12526,6 +12536,7 @@ async function runAsyncPath(data, deps) {
12526
12536
  parentProviderRegistry: ctx.modelRegistry,
12527
12537
  currentModel: parentModel,
12528
12538
  scopedModelIds: data.scopedModelIds,
12539
+ knownProviders: knownModelProviders(ctx.modelRegistry),
12529
12540
  modelScope: data.modelScope,
12530
12541
  modelResponseAliases: deps.config.modelResponseAliases,
12531
12542
  runnerLaunchers: deps.config.runnerLaunchers,
@@ -12566,8 +12577,9 @@ async function runAsyncPath(data, deps) {
12566
12577
  parentModel
12567
12578
  });
12568
12579
  const modelOverride = a.runner?.type === "external-cli" || a.runner?.type === "external-job" ? params.model ?? (externalRunnerWithoutExplicitModel ? void 0 : a.model) : resolveEffectiveSubagentModel(params.model, a.model, parentModel, availableModels, a.modelProvider ?? currentProvider, {
12569
- ...modelScopes.length === 0 ? {} : { scope: modelScopes },
12570
- source: modelOrigin === "explicit" ? "explicit" : "inherited"
12580
+ scope: modelScopes,
12581
+ source: modelOrigin === "explicit" ? "explicit" : "inherited",
12582
+ knownProviders: asyncCtx.knownProviders
12571
12583
  });
12572
12584
  const modelOverrideFromParent = modelOrigin === "inherited";
12573
12585
  const launchRuleError = applyWatchdogLaunchRules({ cwd: effectiveCwd, agent: a.name, model: modelOverride ?? (parentModel && `${parentModel.provider}/${parentModel.id}`), warn: (violation) => deps.watchdog?.displayRuleWarning(violation) });
@@ -12980,6 +12992,7 @@ async function runSinglePath(data, deps) {
12980
12992
  const parentModel = data.parentModel;
12981
12993
  const currentProvider = parentModel?.provider;
12982
12994
  const availableModels = ctx.modelRegistry.getAvailable().map(toModelInfo);
12995
+ const knownProviders = knownModelProviders(ctx.modelRegistry);
12983
12996
  const modelScopes = resolveModelScopesForAgent(data.modelScope, agentConfig.name, parentModel, data.scopedModelIds);
12984
12997
  let task = typeof params.task === "string" ? params.task : "";
12985
12998
  const modelOrigin = resolveModelOrigin({
@@ -12995,8 +13008,9 @@ async function runSinglePath(data, deps) {
12995
13008
  availableModels,
12996
13009
  agentConfig.modelProvider ?? currentProvider,
12997
13010
  {
12998
- ...modelScopes.length === 0 ? {} : { scope: modelScopes },
12999
- source: modelOrigin === "explicit" ? "explicit" : "inherited"
13011
+ scope: modelScopes,
13012
+ source: modelOrigin === "explicit" ? "explicit" : "inherited",
13013
+ knownProviders
13000
13014
  }
13001
13015
  );
13002
13016
  const modelOverrideFromParent = modelOrigin === "inherited";
@@ -13253,6 +13267,7 @@ async function runSinglePath(data, deps) {
13253
13267
  thinkingCeiling: agentConfig.maxThinking,
13254
13268
  extensionBindings: params.extensionBindings,
13255
13269
  availableModels,
13270
+ knownProviders,
13256
13271
  modelResponseAliases,
13257
13272
  preferredModelProvider: currentProvider,
13258
13273
  modelScope: modelScopes,
@@ -14306,6 +14321,7 @@ function createSubagentExecutor(deps) {
14306
14321
  const controller = new AbortController();
14307
14322
  deps2.state.workflowControllers ??= /* @__PURE__ */ new Map();
14308
14323
  deps2.state.workflowChildStops ??= /* @__PURE__ */ new Map();
14324
+ deps2.state.workflowDrains ??= /* @__PURE__ */ new Map();
14309
14325
  deps2.state.workflowControllers.set(workflowRunId, controller);
14310
14326
  workflowCapacity?.markWorkflowStarted();
14311
14327
  if (workflowCapacity) deps2.state.activeAsyncCapacity = getActiveAsyncCapacitySnapshot(currentSessionId, resolveMaxActiveAsyncRunsPerSession(deps2.config.maxActiveAsyncRunsPerSession), { liveWorkflowRunIds: new Set(deps2.state.workflowControllers.keys()), abandonedSlotReleaseAfterMs: resolveAbandonedSlotReleaseAfterMs(deps2.config.capacity?.abandonedSlotReleaseAfterMs) });
@@ -14829,6 +14845,30 @@ Parent action: ${STATUS_ACTION}`,
14829
14845
  if (stop) deps2.state.workflowChildStops?.set(workflowRunId, stop);
14830
14846
  else deps2.state.workflowChildStops?.delete(workflowRunId);
14831
14847
  },
14848
+ registerDrain: (drain) => {
14849
+ if (!drain) deps2.state.workflowDrains?.delete(workflowRunId);
14850
+ else deps2.state.workflowDrains?.set(workflowRunId, () => {
14851
+ if (workflowRunEvidence.drainRequestedAt === void 0) {
14852
+ const previousWorkflow = status.workflow;
14853
+ workflowRunEvidence.drainRequestedAt = Date.now();
14854
+ status.workflow = { ...previousWorkflow ?? { trace: [], emits: [], console: [] }, drainRequestedAt: workflowRunEvidence.drainRequestedAt };
14855
+ let saved = false;
14856
+ try {
14857
+ persist();
14858
+ saved = runPersistence.pendingCount() === 0;
14859
+ } catch (error) {
14860
+ console.error(`Failed to save the drain request for async workflow '${workflowRunId}':`, error);
14861
+ }
14862
+ if (!saved) {
14863
+ delete workflowRunEvidence.drainRequestedAt;
14864
+ status.workflow = previousWorkflow;
14865
+ persist({ tolerateStatusWriteFailure: true });
14866
+ return { ok: false };
14867
+ }
14868
+ }
14869
+ return { ok: true, started: drain(() => queueMicrotask(() => controller.abort(new Error("Workflow drained: started children finished; no new children were started.")))) };
14870
+ });
14871
+ },
14832
14872
  ...workflowState2 ? { state: workflowState2 } : {},
14833
14873
  onTrace: updateTrace,
14834
14874
  onChildSettled: (notification) => {
@@ -15936,6 +15976,7 @@ ${item.text}` } : item)
15936
15976
  }
15937
15977
  if (action === "stop") {
15938
15978
  const targetRunId = paramsWithResolvedCwd.runId ?? paramsWithResolvedCwd.id;
15979
+ if (paramsWithResolvedCwd.drain && paramsWithResolvedCwd.childId !== void 0) return { content: [{ type: "text", text: "action='stop' drain applies to a whole workflow; omit childId." }], isError: true, details: { mode: "management", results: [] } };
15939
15980
  const workflowRunId = targetRunId && paramsWithResolvedCwd.childId !== void 0 ? resolveLiveWorkflowRunId(deps2, targetRunId) : void 0;
15940
15981
  if (workflowRunId && paramsWithResolvedCwd.childId !== void 0) {
15941
15982
  const stopChild = deps2.state.workflowChildStops?.get(workflowRunId);
@@ -15975,7 +16016,7 @@ ${item.text}` } : item)
15975
16016
  if (paramsWithResolvedCwd.dir) {
15976
16017
  try {
15977
16018
  const location = resolveAsyncRunLocation(paramsWithResolvedCwd, DIRS.async, DIRS.results);
15978
- const stopResult2 = stopAsyncRun(deps2.state, location.resolvedId ?? targetRunId ?? path18.basename(location.asyncDir ?? paramsWithResolvedCwd.dir), deps2.kill, location, paramsWithResolvedCwd.childId);
16019
+ const stopResult2 = stopAsyncRun(deps2.state, location.resolvedId ?? targetRunId ?? path18.basename(location.asyncDir ?? paramsWithResolvedCwd.dir), deps2.kill, location, paramsWithResolvedCwd.childId, paramsWithResolvedCwd.drain);
15979
16020
  return stopResult2 ?? { content: [{ type: "text", text: `No running or queued async run was found for '${targetRunId ?? paramsWithResolvedCwd.dir}'.` }], isError: true, details: { mode: "management", results: [] } };
15980
16021
  } catch (error) {
15981
16022
  const text = error instanceof Error ? error.message : String(error);
@@ -15996,7 +16037,8 @@ ${item.text}` } : item)
15996
16037
  resolved?.kind === "async" ? resolved.id : targetRunId,
15997
16038
  deps2.kill,
15998
16039
  resolved?.kind === "async" ? resolved.location : void 0,
15999
- paramsWithResolvedCwd.childId
16040
+ paramsWithResolvedCwd.childId,
16041
+ paramsWithResolvedCwd.drain
16000
16042
  );
16001
16043
  if (stopResult) return stopResult;
16002
16044
  return {
@@ -16488,6 +16530,7 @@ ${item.text}` } : item)
16488
16530
  parentModel: requestParentModel,
16489
16531
  scopedModelIds: scopedModelIdsFromContext(ctx),
16490
16532
  availableModels: ctx.modelRegistry.getAvailable().map(toModelInfo),
16533
+ knownProviders: knownModelProviders(ctx.modelRegistry),
16491
16534
  currentProvider: requestParentModel?.provider,
16492
16535
  modelScope,
16493
16536
  thinkingOverrideForTask,
@@ -7,7 +7,7 @@ import {
7
7
  getAgentDir,
8
8
  getConfigDirName,
9
9
  getProjectConfigDir
10
- } from "./chunk-UX4SCV5N.js";
10
+ } from "./chunk-C3KWLXDH.js";
11
11
  import {
12
12
  TEMP_ROOT_DIR
13
13
  } from "./chunk-JEZOSEWG.js";
@@ -56,7 +56,7 @@ function isMcpServerDefinition(value) {
56
56
  }
57
57
  if (value.requestHeadersCommand !== void 0 && !isRequestHeadersCommand(value.requestHeadersCommand)) return false;
58
58
  if (value.auth !== void 0 && value.auth !== "oauth" && value.auth !== "bearer" && value.auth !== false) return false;
59
- return value.directTools === void 0 || typeof value.directTools === "boolean" || isStringArray(value.directTools);
59
+ return value.directTools === void 0 || typeof value.directTools === "boolean" || value.directTools === "search" || isStringArray(value.directTools);
60
60
  }
61
61
  function isRecord(value) {
62
62
  return value !== null && typeof value === "object" && !Array.isArray(value);
@@ -705,10 +705,8 @@ function parseServerEntries(value) {
705
705
  function parseSettings(value) {
706
706
  if (!isRecord2(value)) return void 0;
707
707
  const toolPrefix = value.toolPrefix === "server" || value.toolPrefix === "short" || value.toolPrefix === "none" || value.toolPrefix === "mcp" ? value.toolPrefix : void 0;
708
- const directTools = typeof value.directTools === "boolean" ? value.directTools : void 0;
709
708
  const settings = {
710
709
  ...toolPrefix ? { toolPrefix } : {},
711
- ...directTools !== void 0 ? { directTools } : {},
712
710
  ...value.agentPluginPaths !== void 0 ? { agentPluginPaths: value.agentPluginPaths } : {}
713
711
  };
714
712
  return Object.keys(settings).length ? settings : void 0;
@@ -807,7 +805,7 @@ function interpolateEnvRecord(values) {
807
805
  return Object.fromEntries(Object.entries(values).map(([key, value]) => [key, interpolateSecretExpression(value)]));
808
806
  }
809
807
  function interpolateEnvVars(value) {
810
- return value.replace(/\$\{(\w+)\}/g, (_, name) => process.env[name] ?? "").replace(/\$env:(\w+)/g, (_, name) => process.env[name] ?? "").replace(/\{env:(\w+)\}/g, (_, name) => process.env[name] ?? "");
808
+ return value.replace(/\$\{(\w+)(?::-([^}]*))?\}/g, (_, name, fallback) => process.env[name] ?? fallback ?? "").replace(/\$env:(\w+)/g, (_, name) => process.env[name] ?? "").replace(/\{env:(\w+)\}/g, (_, name) => process.env[name] ?? "");
811
809
  }
812
810
  function interpolateSecretExpression(value) {
813
811
  if (value.startsWith("!!")) return interpolateEnvVars(value.slice(1));
@@ -815,9 +813,9 @@ function interpolateSecretExpression(value) {
815
813
  }
816
814
  function getMissingEnvVars(value) {
817
815
  const missing = /* @__PURE__ */ new Set();
818
- for (const match of value.matchAll(/\$\{(\w+)\}|\$env:(\w+)|\{env:(\w+)\}/g)) {
819
- const name = match[1] ?? match[2] ?? match[3];
820
- if (name && process.env[name] === void 0) missing.add(name);
816
+ for (const match of value.matchAll(/\$\{(\w+)(:-[^}]*)?\}|\$env:(\w+)|\{env:(\w+)\}/g)) {
817
+ const name = match[1] ?? match[3] ?? match[4];
818
+ if (name && match[2] === void 0 && process.env[name] === void 0) missing.add(name);
821
819
  }
822
820
  return [...missing];
823
821
  }
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  getProjectSubagentsDir
3
- } from "./chunk-PHZP3KHB.js";
3
+ } from "./chunk-XSDYTXHF.js";
4
4
  import {
5
5
  discoverAgents,
6
6
  formatUnknownAgentError,
7
7
  resolveAgentName,
8
8
  unknownAgentDiagnosticContext
9
- } from "./chunk-UX4SCV5N.js";
9
+ } from "./chunk-C3KWLXDH.js";
10
10
 
11
11
  // src/agents/agent-refinements.ts
12
12
  import { createHash, randomUUID } from "node:crypto";
@@ -4,7 +4,7 @@ import {
4
4
  import {
5
5
  resolveWatchPath,
6
6
  writeAtomicJson
7
- } from "./chunk-UX4SCV5N.js";
7
+ } from "./chunk-C3KWLXDH.js";
8
8
  import {
9
9
  POLL_INTERVAL_MS
10
10
  } from "./chunk-JEZOSEWG.js";
@@ -112,7 +112,21 @@ import { randomUUID } from "node:crypto";
112
112
  var OUTPUT_NAME_PATTERN = /^[A-Za-z_][A-Za-z0-9_]*$/;
113
113
  var PLACEHOLDER_PATTERN = /\{(?:task|previous|outputs\.([A-Za-z_][A-Za-z0-9_]*))\}/g;
114
114
  var CHILD_FIELDS = ["cwd", "model"];
115
- var TOP_LEVEL_CONTROLS_HINT = " Put worktree and other child controls on the subagent call itself; they apply to every child.";
115
+ var SHARED_CHILD_CONTROLS = /* @__PURE__ */ new Set(["worktree", "baseRef", "context", "skill", "fast", "agentScope", "outputMode", "outputSchema", "agentContract", "acceptance", "gate", "toolBudget", "toolTimeoutMs", "control"]);
116
+ var SCRIPT_CHILD_FIELDS = /* @__PURE__ */ new Set(["key", "label", "phase", "resume", "async", "timeoutMs"]);
117
+ function unsupportedChildFieldAdvice(fields, scripts) {
118
+ const perChild = scripts ? "use workflow: true with runs.all items" : "you need workflow scripts, which disabledFeatures has turned off";
119
+ const advice = [];
120
+ const itemFields = fields.filter((field) => CHILD_FIELDS.includes(field));
121
+ if (itemFields.length > 0) advice.push(`Set ${itemFields.join(", ")} on each item, or on the subagent call itself to give every child the same value.`);
122
+ if (fields.includes("output")) advice.push(`For one shared output, set output on the subagent call itself: the workflow result is written there and each child gets its own file beside it. For exact or different per-child paths, ${perChild}. Do not drop output if you need durable child files.`);
123
+ const shared = fields.filter((field) => SHARED_CHILD_CONTROLS.has(field));
124
+ if (shared.length > 0) advice.push(`Set ${shared.join(", ")} on the subagent call itself to give every child the same value; for different values per child, ${perChild}.`);
125
+ const scriptOnly = fields.filter((field) => SCRIPT_CHILD_FIELDS.has(field));
126
+ if (scriptOnly.length > 0) advice.push(`For per-child ${scriptOnly.join(", ")}, ${perChild}.`);
127
+ advice.push("No child was launched.");
128
+ return advice.join(" ");
129
+ }
116
130
  function isPlainRecord(value) {
117
131
  if (!value || typeof value !== "object" || Array.isArray(value)) return false;
118
132
  const prototype = Object.getPrototypeOf(value);
@@ -122,10 +136,10 @@ function nonEmptyString(value, path) {
122
136
  if (typeof value !== "string" || !value.trim()) throw new Error(`${path} must be a non-empty string.`);
123
137
  return value;
124
138
  }
125
- function exactFields(value, path, allowed, hint) {
139
+ function exactFields(value, path, allowed, hint, scripts) {
126
140
  if (!isPlainRecord(value)) throw new Error(`${path} must be an object.`);
127
141
  const unsupported = Object.keys(value).filter((key) => !allowed.includes(key));
128
- if (unsupported.length > 0) throw new Error(`${path} contains unsupported fields: ${unsupported.join(", ")}. ${hint}`);
142
+ if (unsupported.length > 0) throw new Error(`${path} contains unsupported fields: ${unsupported.join(", ")}. ${hint} ${unsupportedChildFieldAdvice(unsupported, scripts)}`);
129
143
  return value;
130
144
  }
131
145
  function compileTemplate(template, scope) {
@@ -184,11 +198,11 @@ var SETTLE_HELPER = [
184
198
  ' return new Error(label + ": " + children.filter(function (child) { return !child.ok; }).map(function (child) { return child.key + " (" + child.agent + ") failed" + (child.error ? ": " + child.error : ""); }).join("; "));',
185
199
  "}"
186
200
  ].join("\n");
187
- function buildTasksScript(steps, originalTask) {
201
+ function buildTasksScript(steps, originalTask, scripts) {
188
202
  if (!Array.isArray(steps) || steps.length === 0) throw new Error("tasks must be a non-empty array of { agent, task } items.");
189
203
  const children = steps.map((item, index) => {
190
204
  const path = `tasks[${index}]`;
191
- const record = exactFields(item, path, ["agent", "task", ...CHILD_FIELDS], `Each tasks item accepts agent and task, plus optional cwd and model.${TOP_LEVEL_CONTROLS_HINT}`);
205
+ const record = exactFields(item, path, ["agent", "task", ...CHILD_FIELDS], "Each tasks item accepts agent and task, plus optional cwd and model.", scripts);
192
206
  const agent = nonEmptyString(record.agent, `${path}.agent`);
193
207
  const task = nonEmptyString(record.task, `${path}.task`);
194
208
  const taskExpression = compileTemplate(task, {
@@ -219,18 +233,18 @@ function buildChainScript(steps, originalTask) {
219
233
  let stepChildren;
220
234
  let outputName;
221
235
  if (isPlainRecord(step) && Object.hasOwn(step, "parallel")) {
222
- const record = exactFields(step, path, ["parallel"], `A parallel step accepts only parallel; as is supported on sequential steps only.${TOP_LEVEL_CONTROLS_HINT}`);
236
+ const record = exactFields(step, path, ["parallel"], "A parallel step accepts only parallel; as is supported on sequential steps only.", false);
223
237
  const items = record.parallel;
224
238
  if (!Array.isArray(items) || items.length === 0) throw new Error(`${path}.parallel must be a non-empty array of { agent, task } items.`);
225
239
  stepChildren = items.map((item, itemIndex) => {
226
240
  const itemPath = `${path}.parallel[${itemIndex}]`;
227
- const itemRecord = exactFields(item, itemPath, ["agent", "task", ...CHILD_FIELDS], `Each parallel item accepts agent and task, plus optional cwd and model.${TOP_LEVEL_CONTROLS_HINT}`);
241
+ const itemRecord = exactFields(item, itemPath, ["agent", "task", ...CHILD_FIELDS], "Each parallel item accepts agent and task, plus optional cwd and model.", false);
228
242
  const agent = nonEmptyString(itemRecord.agent, `${itemPath}.agent`);
229
243
  const task = nonEmptyString(itemRecord.task, `${itemPath}.task`);
230
244
  return { key: `step-${number}-${itemIndex + 1}`, agent, fields: childFields(itemRecord, itemPath), taskExpression: compileTemplate(task, { path: `${itemPath}.task`, hasOriginalTask, previous, outputs }) };
231
245
  });
232
246
  } else {
233
- const record = exactFields(step, path, ["agent", "task", "as", ...CHILD_FIELDS], `A sequential step accepts agent, task, as, cwd and model; a parallel step accepts only parallel.${TOP_LEVEL_CONTROLS_HINT}`);
247
+ const record = exactFields(step, path, ["agent", "task", "as", ...CHILD_FIELDS], "A sequential step accepts agent, task, as, cwd and model; a parallel step accepts only parallel.", false);
234
248
  const agent = nonEmptyString(record.agent, `${path}.agent`);
235
249
  let task;
236
250
  if (record.task === void 0) {
@@ -256,8 +270,8 @@ function buildChainScript(steps, originalTask) {
256
270
  lines.push("return { ok: true, children };");
257
271
  return lines.join("\n");
258
272
  }
259
- function buildStructuredWorkflowScript(kind, steps, originalTask) {
260
- return kind === "tasks" ? buildTasksScript(steps, originalTask) : buildChainScript(steps, originalTask);
273
+ function buildStructuredWorkflowScript(kind, steps, originalTask, scripts) {
274
+ return kind === "tasks" ? buildTasksScript(steps, originalTask, scripts) : buildChainScript(steps, originalTask);
261
275
  }
262
276
 
263
277
  // src/workflows/workflow-resources.ts
@@ -375,9 +389,9 @@ function resolveRunCi(args) {
375
389
  }
376
390
  function resolveParallel(args) {
377
391
  const unsupported = Object.keys(args).filter((key) => key !== "tasks");
378
- if (unsupported.length > 0) return { error: `workflow 'parallel' args contain unsupported fields: ${unsupported.join(", ")}. Pass args.tasks: [{ agent, task, cwd?, model? }, ...].${TOP_LEVEL_CONTROLS_HINT}` };
392
+ if (unsupported.length > 0) return { error: `workflow 'parallel' args contain unsupported fields: ${unsupported.join(", ")}. Pass args.tasks: [{ agent, task, cwd?, model? }, ...]. ${unsupportedChildFieldAdvice(unsupported, true)}` };
379
393
  try {
380
- return { script: buildStructuredWorkflowScript("tasks", args.tasks, void 0) };
394
+ return { script: buildStructuredWorkflowScript("tasks", args.tasks, void 0, true) };
381
395
  } catch (error) {
382
396
  return { error: `workflow 'parallel' args.${error instanceof Error ? error.message : String(error)}` };
383
397
  }
@@ -415,7 +429,7 @@ function resolveStructuredWorkflowResource(input) {
415
429
  validatePlainJson(task, "task");
416
430
  }
417
431
  if (jsonByteLength({ [kind]: steps, task }) > MAX_ARGS_BYTES) return { ok: false, error: `${kind} input exceeds ${MAX_ARGS_BYTES} bytes.` };
418
- const script = buildStructuredWorkflowScript(kind, JSON.parse(JSON.stringify(steps)), task);
432
+ const script = buildStructuredWorkflowScript(kind, JSON.parse(JSON.stringify(steps)), task, false);
419
433
  return { ok: true, resource: issueWorkflowResource(kind, STRUCTURED_WORKFLOW_RESOURCE_VERSION, script) };
420
434
  } catch (error) {
421
435
  return { ok: false, error: error instanceof Error ? error.message.slice(0, 4096) : "Structured workflow resolution failed." };
@@ -11,7 +11,7 @@ import {
11
11
  readStatus,
12
12
  writeAtomicJson,
13
13
  writePrivateAtomicJson
14
- } from "./chunk-UX4SCV5N.js";
14
+ } from "./chunk-C3KWLXDH.js";
15
15
  import {
16
16
  ASYNC_DIR,
17
17
  INTERCOM_DETACH_REQUEST_EVENT,
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  getAgentDir
3
- } from "./chunk-UX4SCV5N.js";
3
+ } from "./chunk-C3KWLXDH.js";
4
4
  import {
5
5
  TEMP_ARTIFACTS_DIR
6
6
  } from "./chunk-JEZOSEWG.js";
@@ -9,6 +9,7 @@ import {
9
9
  import * as fs from "node:fs";
10
10
  import * as path from "node:path";
11
11
  var CLEANUP_MARKER_FILE = ".last-cleanup";
12
+ var RETAINED_ARTIFACT_DIRS = /* @__PURE__ */ new Set(["handoffs", "worktree-diffs"]);
12
13
  var PROJECT_SUBAGENTS_RELATIVE_DIR = ".pi/subagents";
13
14
  var PROJECT_ARTIFACT_PATHS = [
14
15
  `${PROJECT_SUBAGENTS_RELATIVE_DIR}/artifacts/output.md`,
@@ -187,19 +188,25 @@ function cleanupOldArtifacts(dir, maxAgeDays) {
187
188
  }
188
189
  const maxAgeMs = maxAgeDays * 24 * 60 * 60 * 1e3;
189
190
  const cutoff = now - maxAgeMs;
190
- for (const file of fs.readdirSync(dir)) {
191
- if (file === CLEANUP_MARKER_FILE) continue;
192
- const filePath = path.join(dir, file);
193
- try {
194
- const stat = fs.statSync(filePath);
195
- if (stat.mtimeMs < cutoff) {
196
- fs.unlinkSync(filePath);
197
- }
198
- } catch {
199
- }
191
+ for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
192
+ if (entry.name === CLEANUP_MARKER_FILE || entry.isDirectory() && RETAINED_ARTIFACT_DIRS.has(entry.name)) continue;
193
+ removeOldEntry(path.join(dir, entry.name), cutoff);
200
194
  }
201
195
  fs.writeFileSync(markerPath, String(now));
202
196
  }
197
+ function removeOldEntry(entryPath, cutoff) {
198
+ try {
199
+ const stat = fs.lstatSync(entryPath);
200
+ const old = stat.mtimeMs < cutoff;
201
+ if (!stat.isDirectory()) {
202
+ if (old) fs.unlinkSync(entryPath);
203
+ return;
204
+ }
205
+ for (const name of fs.readdirSync(entryPath)) removeOldEntry(path.join(entryPath, name), cutoff);
206
+ if (old && fs.readdirSync(entryPath).length === 0) fs.rmdirSync(entryPath);
207
+ } catch {
208
+ }
209
+ }
203
210
  function cleanupAllArtifactDirs(maxAgeDays) {
204
211
  cleanupOldArtifacts(TEMP_ARTIFACTS_DIR, maxAgeDays);
205
212
  const sessionsBase = path.join(getAgentDir(), "sessions");