pi-subagents 0.82.1 → 0.83.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 (77) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/bundle/agents.js +4 -4
  3. package/bundle/background-work.js +1 -1
  4. package/bundle/child-tool-plan.js +3 -3
  5. package/bundle/{chunk-FXUXCX2K.js → chunk-4BW55BTL.js} +6 -6
  6. package/bundle/{chunk-PBK2I7WY.js → chunk-527E3D2J.js} +6 -6
  7. package/bundle/{chunk-46XKCPJR.js → chunk-5ESXK62X.js} +7 -1073
  8. package/bundle/{chunk-UTT254JE.js → chunk-6B4ITO2W.js} +8 -4
  9. package/bundle/{chunk-CIZQXJ5Q.js → chunk-7F5SK2U3.js} +39 -6
  10. package/bundle/{chunk-OYF6AFDY.js → chunk-BKFWQ642.js} +2 -2
  11. package/bundle/{chunk-ZIV4J4HG.js → chunk-CDI3GMNV.js} +47 -30
  12. package/bundle/{chunk-3JCDWF4V.js → chunk-CGXWSNPA.js} +12 -18
  13. package/bundle/{chunk-JYUKW2SY.js → chunk-CNLDYEH4.js} +12 -12
  14. package/bundle/{chunk-4SDU2BZX.js → chunk-CSSZRTKY.js} +2 -2
  15. package/bundle/{chunk-VSUSLDNW.js → chunk-CZTMUBUI.js} +10 -8
  16. package/bundle/{chunk-IVAE5Z6Q.js → chunk-HJJAVHFB.js} +28 -24
  17. package/bundle/{chunk-GJECHSAR.js → chunk-HLE22FSH.js} +2 -2
  18. package/bundle/{chunk-4Y2ROR7L.js → chunk-HXVKGS33.js} +5 -5
  19. package/bundle/{chunk-5LFLVSTM.js → chunk-JEZOSEWG.js} +2 -0
  20. package/bundle/{chunk-YKEWIB4M.js → chunk-JHZ6DZ5M.js} +1 -1
  21. package/bundle/{chunk-QE4AGIMG.js → chunk-LDMXJIA6.js} +457 -657
  22. package/bundle/{chunk-43SCHIMD.js → chunk-MBDOYZ2V.js} +1 -1
  23. package/bundle/{chunk-XSWOTIA3.js → chunk-MHX22USZ.js} +1 -1
  24. package/bundle/{chunk-6XJB7PIX.js → chunk-OOFW75PV.js} +4 -4
  25. package/bundle/{chunk-RMQFMMAT.js → chunk-P2NCCTZP.js} +231 -10
  26. package/bundle/{chunk-UCPP4GNU.js → chunk-RZJN63GU.js} +12 -5
  27. package/bundle/{chunk-G4GZD3OJ.js → chunk-TJQJ3MEA.js} +10 -10
  28. package/bundle/{chunk-5TYMSZX3.js → chunk-VTMNBPCQ.js} +2 -2
  29. package/bundle/{chunk-52UBALJL.js → chunk-WG2OTTAK.js} +2 -2
  30. package/bundle/{chunk-N2BN7BF5.js → chunk-XA3DY6UG.js} +7 -5
  31. package/bundle/{chunk-PDZWJCHD.js → chunk-XXKG3P2W.js} +9 -6
  32. package/bundle/{chunk-PLCCBLPY.js → chunk-Y3I6H6DV.js} +2 -2
  33. package/bundle/control-channel.js +3 -3
  34. package/bundle/index.js +1 -1
  35. package/bundle/intercom-bridge.js +3 -3
  36. package/bundle/preflight.js +9 -9
  37. package/bundle/project-panes.js +4 -4
  38. package/bundle/shared-types.js +1 -1
  39. package/docs/configuration.md +1 -1
  40. package/docs/extension-api.md +19 -4
  41. package/docs/observability.md +1 -0
  42. package/docs/tool-reference.md +1 -1
  43. package/package.json +1 -1
  44. package/skills/pi-subagents/SKILL.md +6 -6
  45. package/src/agents/agent-management.js +8 -14
  46. package/src/agents/agent-serializer.js +1 -2
  47. package/src/agents/agents.js +19 -3
  48. package/src/api/background-work.d.ts +9 -6
  49. package/src/api/background-work.js +14 -7
  50. package/src/extension/index.js +4 -1
  51. package/src/extension/public-execution.d.ts +2 -2
  52. package/src/extension/public-execution.js +3 -3
  53. package/src/extension/reply-workflow-script.js +4 -5
  54. package/src/extension/rpc.js +3 -1
  55. package/src/extension/subagent-options.js +17 -4
  56. package/src/runs/background/async-execution.js +4 -1
  57. package/src/runs/background/async-job-tracker.js +2 -1
  58. package/src/runs/background/auto-drain.js +2 -3
  59. package/src/runs/background/fleet-view.js +1 -1
  60. package/src/runs/background/run-child-session.js +22 -6
  61. package/src/runs/background/subagent-wait.d.ts +2 -1
  62. package/src/runs/background/subagent-wait.js +5 -2
  63. package/src/runs/foreground/execution.js +22 -6
  64. package/src/runs/foreground/subagent-executor.js +2 -5
  65. package/src/runs/shared/child-launch.js +5 -2
  66. package/src/runs/shared/child-session.d.ts +6 -0
  67. package/src/runs/shared/child-session.js +20 -4
  68. package/src/runs/shared/herdr-machine.d.ts +2 -0
  69. package/src/runs/shared/herdr-machine.js +2 -0
  70. package/src/runs/shared/herdr-placed-run.js +11 -4
  71. package/src/runs/shared/subagent-prompt-runtime.js +11 -17
  72. package/src/shared/disabled-features.d.ts +3 -1
  73. package/src/shared/disabled-features.js +11 -3
  74. package/src/shared/types.d.ts +3 -1
  75. package/src/shared/types.js +2 -0
  76. package/src/workflows/scripted-workflow.js +9 -1070
  77. package/workflow-script-worker.cjs +1067 -0
@@ -1,7 +1,7 @@
1
1
  // package.json
2
2
  var package_default = {
3
3
  name: "pi-subagents",
4
- version: "0.82.1",
4
+ version: "0.83.0",
5
5
  private: true,
6
6
  description: "Pi extension for single-agent delegation and scripted multi-agent workflows",
7
7
  author: "Nico Bailon",
@@ -50,6 +50,7 @@ var package_default = {
50
50
  "index.ts",
51
51
  "src/**/*.ts",
52
52
  "*.mjs",
53
+ "workflow-script-worker.cjs",
53
54
  "agents/",
54
55
  "skills/**/*",
55
56
  "prompts/**/*",
@@ -112,14 +113,17 @@ var package_default = {
112
113
  devDependencies: {
113
114
  "@earendil-works/pi-agent-core": "1.2.0",
114
115
  "@earendil-works/pi-ai": "1.2.0",
116
+ "@earendil-works/pi-coding-agent": "1.2.0",
115
117
  "@earendil-works/pi-tui": "1.2.0",
116
118
  "@oxlint/plugins": "1.80.0",
117
119
  "@types/node": "24.13.3",
118
120
  esbuild: "0.28.2",
119
121
  oxlint: "1.80.0",
120
- typescript: "5.9.3",
121
- "@earendil-works/pi-coding-agent": "1.2.0",
122
- typebox: "1.3.27"
122
+ typebox: "1.3.27",
123
+ typescript: "5.9.3"
124
+ },
125
+ overrides: {
126
+ undici: "$undici"
123
127
  }
124
128
  };
125
129
 
@@ -2,7 +2,7 @@ import {
2
2
  CHAIN_RUNS_DIR,
3
3
  RUNNER_LAUNCHER_NAME_PATTERN,
4
4
  RUNNER_LAUNCHER_NAME_RULE
5
- } from "./chunk-5LFLVSTM.js";
5
+ } from "./chunk-JEZOSEWG.js";
6
6
  import {
7
7
  previewDisplayText,
8
8
  sanitizeDisplayText,
@@ -1203,9 +1203,7 @@ function serializeAgent(config, options = {}) {
1203
1203
  }
1204
1204
  if (config.model || preserve("model")) lines.push(`model: ${config.model ?? ""}`);
1205
1205
  if (config.fast === true || preserve("fast")) lines.push(`fast: ${config.fast === void 0 ? "" : config.fast ? "true" : "false"}`);
1206
- if (config.thinking && (config.thinking !== "off" || preserve("thinking")) || !config.thinking && preserve("thinking")) {
1207
- lines.push(`thinking: ${config.thinking ?? ""}`);
1208
- }
1206
+ if (config.thinking || preserve("thinking")) lines.push(`thinking: ${config.thinking ?? ""}`);
1209
1207
  if (!preservingExistingFrontmatter || preserve("systemPromptMode")) lines.push(`systemPromptMode: ${config.systemPromptMode}`);
1210
1208
  if (!preservingExistingFrontmatter || preserve("inheritProjectContext")) lines.push(`inheritProjectContext: ${config.inheritProjectContext ? "true" : "false"}`);
1211
1209
  if (config.inheritGlobalContext || preserve("inheritGlobalContext")) lines.push(`inheritGlobalContext: ${config.inheritGlobalContext ? "true" : "false"}`);
@@ -4232,6 +4230,35 @@ function defaultInheritProjectContext(name) {
4232
4230
  function defaultInheritSkills() {
4233
4231
  return false;
4234
4232
  }
4233
+ var BUILTIN_OVERRIDE_FIELDS = {
4234
+ description: true,
4235
+ advertise: true,
4236
+ machine: true,
4237
+ output: true,
4238
+ outputMode: true,
4239
+ defaultReads: true,
4240
+ model: true,
4241
+ defaultProvider: true,
4242
+ fast: true,
4243
+ thinking: true,
4244
+ systemPromptMode: true,
4245
+ inheritProjectContext: true,
4246
+ inheritGlobalContext: true,
4247
+ inheritSkills: true,
4248
+ defaultContext: true,
4249
+ acceptanceRole: true,
4250
+ disabled: true,
4251
+ systemPrompt: true,
4252
+ skills: true,
4253
+ tools: true,
4254
+ excludeTools: true,
4255
+ allowNestedSubagents: true,
4256
+ allowedAgents: true,
4257
+ extensions: true,
4258
+ subagentOnlyExtensions: true,
4259
+ mutationTools: true,
4260
+ toolBudget: true
4261
+ };
4235
4262
  var EMPTY_SUBAGENT_SETTINGS = { overrides: {}, providerOverrides: {} };
4236
4263
  var agentFrontmatterFields = /* @__PURE__ */ new WeakMap();
4237
4264
  var AGENT_SOURCE_PRIORITY = {
@@ -4830,6 +4857,11 @@ function parseBuiltinOverrideEntry(name, value, filePath) {
4830
4857
  if (Object.hasOwn(input, "launcher")) {
4831
4858
  throw new Error(`Builtin override '${name}' in '${filePath}' sets 'launcher', which settings overrides do not support; set 'launcher' in a user agent file instead.`);
4832
4859
  }
4860
+ for (const key of Object.keys(input)) {
4861
+ if (Object.hasOwn(BUILTIN_OVERRIDE_FIELDS, key)) continue;
4862
+ const suggestion = closestMatch(key, Object.keys(BUILTIN_OVERRIDE_FIELDS));
4863
+ throw new Error(`Builtin override '${name}' in '${filePath}' has unknown field '${key}'.${suggestion ? ` Did you mean '${suggestion}'?` : ""}`);
4864
+ }
4833
4865
  const override = {};
4834
4866
  if ("description" in input) {
4835
4867
  if (typeof input.description === "string" && input.description.trim()) {
@@ -4862,8 +4894,9 @@ function parseBuiltinOverrideEntry(name, value, filePath) {
4862
4894
  else throw new Error(`Builtin override '${name}' in '${filePath}' has invalid 'fast'; expected a boolean.`);
4863
4895
  }
4864
4896
  if ("thinking" in input) {
4865
- if (typeof input.thinking === "string" || input.thinking === false) override.thinking = input.thinking;
4866
- else throw new Error(`Builtin override '${name}' in '${filePath}' has invalid 'thinking'; expected a string or false.`);
4897
+ const level = THINKING_LEVELS.find((candidate) => candidate === input.thinking);
4898
+ if (level !== void 0 || input.thinking === false) override.thinking = level ?? false;
4899
+ else throw new Error(`Builtin override '${name}' in '${filePath}' has invalid 'thinking'; expected one of ${THINKING_LEVELS.join(", ")}, or false.`);
4867
4900
  }
4868
4901
  if ("systemPromptMode" in input) {
4869
4902
  if (input.systemPromptMode === "append" || input.systemPromptMode === "replace") {
@@ -4,10 +4,10 @@ import {
4
4
  import {
5
5
  resolveWatchPath,
6
6
  writeAtomicJson
7
- } from "./chunk-CIZQXJ5Q.js";
7
+ } from "./chunk-7F5SK2U3.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-CZTMUBUI.js";
15
15
  import {
16
16
  resolveGitRepositoryIdentity
17
- } from "./chunk-FXUXCX2K.js";
17
+ } from "./chunk-4BW55BTL.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-OOFW75PV.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-5ESXK62X.js";
54
54
  import {
55
55
  requestAsyncCommand,
56
56
  watchAsyncControlInbox
57
- } from "./chunk-OYF6AFDY.js";
57
+ } from "./chunk-BKFWQ642.js";
58
58
  import {
59
59
  supervisorChannelDir
60
- } from "./chunk-4SDU2BZX.js";
60
+ } from "./chunk-CSSZRTKY.js";
61
61
  import {
62
62
  createHerdrClient,
63
63
  detectHerdr
64
- } from "./chunk-52UBALJL.js";
64
+ } from "./chunk-WG2OTTAK.js";
65
65
  import {
66
66
  getProjectSubagentsDir
67
- } from "./chunk-5TYMSZX3.js";
67
+ } from "./chunk-VTMNBPCQ.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-JHZ6DZ5M.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-7F5SK2U3.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,
@@ -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;
@@ -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-XXKG3P2W.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
@@ -15,15 +15,15 @@ import {
15
15
  resolveCurrentSessionId,
16
16
  resolveWatchdogReviewModel,
17
17
  startWatchdogDiffBaselineCapture
18
- } from "./chunk-VSUSLDNW.js";
18
+ } from "./chunk-CZTMUBUI.js";
19
19
  import {
20
20
  MODEL_ONLY_TOOL,
21
21
  agentStreamOptions,
22
22
  opencodeSessionHeaders
23
- } from "./chunk-6XJB7PIX.js";
23
+ } from "./chunk-OOFW75PV.js";
24
24
  import {
25
25
  inheritedNestedRouteOf
26
- } from "./chunk-46XKCPJR.js";
26
+ } from "./chunk-5ESXK62X.js";
27
27
  import {
28
28
  CHILD_WATCHDOG_STATUS_EVENT,
29
29
  MISSING_STRUCTURED_ACCEPTANCE_REPORT_ERROR,
@@ -39,10 +39,10 @@ import {
39
39
  toolBudgetSoftNudge,
40
40
  validateAcceptanceReport,
41
41
  validateStructuredOutputValue
42
- } from "./chunk-CIZQXJ5Q.js";
42
+ } from "./chunk-7F5SK2U3.js";
43
43
  import {
44
44
  INTERCOM_SESSION_IDENTITY_EVENT
45
- } from "./chunk-5LFLVSTM.js";
45
+ } from "./chunk-JEZOSEWG.js";
46
46
 
47
47
  // src/runs/shared/subagent-prompt-runtime.ts
48
48
  import { createHash } from "node:crypto";
@@ -851,6 +851,7 @@ function registerSubagentPromptRuntime(pi, config, drainObservation) {
851
851
  onRuntimeEvent("session_start", (_event, ctx) => {
852
852
  const sessionManager = ctx?.sessionManager;
853
853
  waitState.currentSessionId = sessionManager ? resolveCurrentSessionId(sessionManager) : null;
854
+ waitState.supervisorOwnerSessionId = sessionManager?.getSessionId() || null;
854
855
  registerNativeSupervisorClientOnce();
855
856
  });
856
857
  onRuntimeEvent("agent_start", () => {
@@ -892,25 +893,18 @@ function registerSubagentPromptRuntime(pi, config, drainObservation) {
892
893
  if (config.forkCacheKey) onRuntimeEvent("before_provider_headers", (event, ctx) => {
893
894
  applyForkSessionAffinity(event?.headers, ctx?.model, config.parentSessionId, readInherited(ctx)?.model);
894
895
  });
895
- if (config.forkCacheKey) onRuntimeEvent("context_with_system", (event, ctx) => {
896
+ onRuntimeEvent("context_with_system", (event, ctx) => {
896
897
  if (!event || typeof event !== "object" || !("messages" in event) || !Array.isArray(event.messages)) return void 0;
897
- const fork = readInherited(ctx);
898
- if (!fork) return void 0;
899
- const messages = projectForkRequest(event.messages, fork.system, fork.forkedAt, { boundary });
900
- return messages === event.messages ? void 0 : { messages };
901
- });
902
- onRuntimeEvent("context", (event, ctx) => {
903
- if (!event || typeof event !== "object" || !("messages" in event) || !Array.isArray(event.messages)) return void 0;
904
- const forkedAt = config.forkCacheKey ? Date.parse(ctx?.sessionManager?.getHeader()?.timestamp ?? "") : Number.NaN;
905
- const messages = stripParentOnlySubagentMessages(event.messages, {
898
+ const fork = config.forkCacheKey ? readInherited(ctx) : void 0;
899
+ const stripped = stripParentOnlySubagentMessages(event.messages, {
906
900
  sanitizeToolIds: !COMPOSITE_TOOL_ID_APIS.has(ctx?.model?.api ?? ""),
907
901
  // Providers that reuse the Codex Responses wire under their own api id (e.g. cliproxyapi-codex-responses) split call_id|item_id the same way.
908
902
  preserveBoundedCompositeToolIds: ctx?.model?.api?.endsWith("-codex-responses") === true,
909
903
  preserveFanoutToolHistory: config.fanoutChild,
910
- ...Number.isFinite(forkedAt) ? { inheritedBefore: forkedAt } : {}
904
+ ...fork ? { inheritedBefore: fork.forkedAt } : {}
911
905
  });
912
- if (messages === event.messages) return void 0;
913
- return { messages };
906
+ const messages = fork ? projectForkRequest(stripped, fork.system, fork.forkedAt, { boundary }) : stripped;
907
+ return messages === event.messages ? void 0 : { messages };
914
908
  });
915
909
  const routingName = config.intercomSessionName;
916
910
  let intercomIdClaimed = false;
@@ -1,26 +1,26 @@
1
1
  import {
2
2
  rewriteSubagentPrompt
3
- } from "./chunk-3JCDWF4V.js";
3
+ } from "./chunk-CGXWSNPA.js";
4
4
  import {
5
5
  package_default
6
- } from "./chunk-UTT254JE.js";
7
- import "./chunk-VSUSLDNW.js";
6
+ } from "./chunk-6B4ITO2W.js";
7
+ import "./chunk-CZTMUBUI.js";
8
8
  import {
9
9
  MODEL_ONLY_TOOL
10
- } from "./chunk-6XJB7PIX.js";
10
+ } from "./chunk-OOFW75PV.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-Y3I6H6DV.js";
15
+ import "./chunk-5ESXK62X.js";
16
16
  import "./chunk-NIXWDZZV.js";
17
- import "./chunk-XSWOTIA3.js";
17
+ import "./chunk-MHX22USZ.js";
18
18
  import "./chunk-7F6RKT6W.js";
19
19
  import {
20
20
  assertNoToolModifierEntries
21
- } from "./chunk-4SDU2BZX.js";
21
+ } from "./chunk-CSSZRTKY.js";
22
22
  import "./chunk-CTPAE36Y.js";
23
- import "./chunk-5TYMSZX3.js";
23
+ import "./chunk-VTMNBPCQ.js";
24
24
  import {
25
25
  HERDR_PI_MAX_FRAME_BYTES,
26
26
  HERDR_PI_PROTOCOL,
@@ -30,15 +30,15 @@ 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-7F5SK2U3.js";
41
+ import "./chunk-JEZOSEWG.js";
42
42
  import "./chunk-YFCK7H2S.js";
43
43
  import "./chunk-Z7KVHQHL.js";
44
44
 
@@ -7,10 +7,10 @@ import {
7
7
  getAgentDir,
8
8
  getConfigDirName,
9
9
  getProjectConfigDir
10
- } from "./chunk-CIZQXJ5Q.js";
10
+ } from "./chunk-7F5SK2U3.js";
11
11
  import {
12
12
  TEMP_ROOT_DIR
13
- } from "./chunk-5LFLVSTM.js";
13
+ } from "./chunk-JEZOSEWG.js";
14
14
  import {
15
15
  capabilityCeilingAgentRestrictionSources,
16
16
  intersectSubagentCapabilityCeilings,
@@ -11,7 +11,7 @@ import {
11
11
  projectTimeoutRecovery,
12
12
  readAsyncRecoveryDescriptor,
13
13
  utf8Tail
14
- } from "./chunk-6XJB7PIX.js";
14
+ } from "./chunk-OOFW75PV.js";
15
15
  import {
16
16
  MAX_ARGS_BYTES,
17
17
  MAX_ARGS_DEPTH,
@@ -24,17 +24,17 @@ import {
24
24
  resultFilePath,
25
25
  resultPayloadMatchesSessionRun,
26
26
  resultPayloadPathForSessionRun
27
- } from "./chunk-46XKCPJR.js";
27
+ } from "./chunk-5ESXK62X.js";
28
28
  import {
29
29
  shouldUseNativeFsWatch
30
30
  } from "./chunk-NIXWDZZV.js";
31
31
  import {
32
32
  PROJECT_SUBAGENTS_RELATIVE_DIR
33
- } from "./chunk-5TYMSZX3.js";
33
+ } from "./chunk-VTMNBPCQ.js";
34
34
  import {
35
35
  listBackgroundWorkWakeChannels,
36
36
  snapshotBackgroundWork
37
- } from "./chunk-N2BN7BF5.js";
37
+ } from "./chunk-XA3DY6UG.js";
38
38
  import {
39
39
  SUBAGENT_WATCHDOG_WARNING_TYPE,
40
40
  THINKING_LEVELS,
@@ -55,7 +55,7 @@ import {
55
55
  withSettingsFileLease,
56
56
  writeAtomicJson,
57
57
  writePrivateAtomicJson
58
- } from "./chunk-CIZQXJ5Q.js";
58
+ } from "./chunk-7F5SK2U3.js";
59
59
  import {
60
60
  ASYNC_DIR,
61
61
  DIRS,
@@ -67,7 +67,7 @@ import {
67
67
  SUBAGENT_FOREGROUND_COMPLETE_EVENT,
68
68
  SUBAGENT_RESULT_INTERCOM_EVENT,
69
69
  TEMP_ROOT_DIR
70
- } from "./chunk-5LFLVSTM.js";
70
+ } from "./chunk-JEZOSEWG.js";
71
71
 
72
72
  // src/intercom/native-supervisor-channel.ts
73
73
  import { randomUUID } from "node:crypto";
@@ -2530,7 +2530,9 @@ function backgroundWorkIdentity(item) {
2530
2530
  function backgroundWorkForSession(deps, nowMs) {
2531
2531
  const sessionId = deps.state.currentSessionId;
2532
2532
  if (!sessionId) throw new Error("bg_wait requires an active session identity to scope background work safely.");
2533
- return deps.backgroundWork?.snapshot(sessionId, nowMs) ?? snapshotBackgroundWork(sessionId, nowMs);
2533
+ const piSessionId = deps.state.supervisorOwnerSessionId;
2534
+ const sessionIds = piSessionId ? [sessionId, piSessionId] : [sessionId];
2535
+ return deps.backgroundWork?.snapshot(sessionIds, nowMs) ?? snapshotBackgroundWork(sessionIds, nowMs);
2534
2536
  }
2535
2537
  function waitRunScopes(deps) {
2536
2538
  return [
@@ -3231,7 +3233,7 @@ function hasOutstandingWork(deps, sessionId, nowMs, observation) {
3231
3233
  const detachedForeground = [...deps.state.foregroundRuns?.values() ?? []].some(
3232
3234
  (run) => run.sessionId === sessionId && run.children.some((child) => child.status === "detached")
3233
3235
  );
3234
- return asyncRuns.length > 0 || snapshotBackgroundWork(sessionId, nowMs).items.length > 0 || detachedForeground;
3236
+ return asyncRuns.length > 0 || backgroundWorkForSession(deps, nowMs).items.length > 0 || detachedForeground;
3235
3237
  }
3236
3238
  async function drainOutstandingWork(deps, observation) {
3237
3239
  const sessionId = deps.state.currentSessionId;