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-IQIWF2VX.js → chunk-AIL46SZU.js} +8 -6
  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-3UZ5FVVJ.js → chunk-DGTZKYIE.js} +39 -34
  13. package/bundle/{chunk-KDMFBYFM.js → chunk-ESWW6XSX.js} +1 -1
  14. package/bundle/{chunk-WOVMHDES.js → chunk-EYGBK6CE.js} +194 -94
  15. package/bundle/{chunk-CS4O36CZ.js → chunk-HDICKROY.js} +5 -5
  16. package/bundle/{chunk-DV2NCNPR.js → chunk-JLDQ6YUR.js} +12 -12
  17. package/bundle/{chunk-RQAUNAWG.js → chunk-LFKMM3UH.js} +2 -2
  18. package/bundle/{chunk-L2ENOFVZ.js → chunk-LZKVUWIY.js} +66 -26
  19. package/bundle/{chunk-RV5OGHLO.js → chunk-M2VBGET6.js} +2 -2
  20. package/bundle/{chunk-HFTBF7SG.js → chunk-OOE3R7IQ.js} +1 -1
  21. package/bundle/{chunk-JNXT3MPI.js → chunk-OTLDAYEQ.js} +5 -5
  22. package/bundle/{chunk-JWYG26RE.js → chunk-OZCPYJEY.js} +80 -37
  23. package/bundle/{chunk-LGMILZNE.js → chunk-PGU4TZV3.js} +79 -32
  24. package/bundle/{chunk-KEY3UQMQ.js → chunk-SIAQXPJ4.js} +6 -8
  25. package/bundle/{chunk-QO75KJBT.js → chunk-USRX7QXD.js} +2 -2
  26. package/bundle/{chunk-7MAE3DJV.js → chunk-VFUFOZBU.js} +1 -1
  27. package/bundle/{chunk-NF7IEKBH.js → chunk-W2BZS6UC.js} +27 -13
  28. package/bundle/{chunk-T5V5BRCL.js → chunk-W52LJANO.js} +1 -1
  29. package/bundle/{chunk-PHZP3KHB.js → chunk-XSDYTXHF.js} +18 -11
  30. package/bundle/{chunk-LTPH2DXH.js → chunk-XV7RTWTS.js} +3 -3
  31. package/bundle/{chunk-JO67XSKD.js → chunk-YEXKJJVS.js} +12 -7
  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 +1 -1
  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
@@ -7,7 +7,28 @@ const OUTPUT_NAME_PATTERN = /^[A-Za-z_][A-Za-z0-9_]*$/;
7
7
  const PLACEHOLDER_PATTERN = /\{(?:task|previous|outputs\.([A-Za-z_][A-Za-z0-9_]*))\}/g;
8
8
  /** Optional per-child launch fields copied verbatim onto the generated runs.all item. */
9
9
  const CHILD_FIELDS = ["cwd", "model"];
10
- export const TOP_LEVEL_CONTROLS_HINT = " Put worktree and other child controls on the subagent call itself; they apply to every child.";
10
+ // Outer subagent-call controls that default onto every workflow child (docs/workflows.md); output gets its own advice.
11
+ const SHARED_CHILD_CONTROLS = new Set(["worktree", "baseRef", "context", "skill", "fast", "agentScope", "outputMode", "outputSchema", "agentContract", "acceptance", "gate", "toolBudget", "toolTimeoutMs", "control"]);
12
+ // runs.run/runs.all child fields whose outer-call form is missing or means something else (async and timeoutMs apply to the workflow).
13
+ const SCRIPT_CHILD_FIELDS = new Set(["key", "label", "phase", "resume", "async", "timeoutMs"]);
14
+ /** Recovery advice per rejected field, so a retry keeps the caller's intent instead of dropping the field. */
15
+ export function unsupportedChildFieldAdvice(fields, scripts) {
16
+ const perChild = scripts ? "use workflow: true with runs.all items" : "you need workflow scripts, which disabledFeatures has turned off";
17
+ const advice = [];
18
+ const itemFields = fields.filter((field) => CHILD_FIELDS.includes(field));
19
+ if (itemFields.length > 0)
20
+ advice.push(`Set ${itemFields.join(", ")} on each item, or on the subagent call itself to give every child the same value.`);
21
+ if (fields.includes("output"))
22
+ 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.`);
23
+ const shared = fields.filter((field) => SHARED_CHILD_CONTROLS.has(field));
24
+ if (shared.length > 0)
25
+ advice.push(`Set ${shared.join(", ")} on the subagent call itself to give every child the same value; for different values per child, ${perChild}.`);
26
+ const scriptOnly = fields.filter((field) => SCRIPT_CHILD_FIELDS.has(field));
27
+ if (scriptOnly.length > 0)
28
+ advice.push(`For per-child ${scriptOnly.join(", ")}, ${perChild}.`);
29
+ advice.push("No child was launched.");
30
+ return advice.join(" ");
31
+ }
11
32
  export function isPlainRecord(value) {
12
33
  if (!value || typeof value !== "object" || Array.isArray(value))
13
34
  return false;
@@ -19,12 +40,12 @@ function nonEmptyString(value, path) {
19
40
  throw new Error(`${path} must be a non-empty string.`);
20
41
  return value;
21
42
  }
22
- function exactFields(value, path, allowed, hint) {
43
+ function exactFields(value, path, allowed, hint, scripts) {
23
44
  if (!isPlainRecord(value))
24
45
  throw new Error(`${path} must be an object.`);
25
46
  const unsupported = Object.keys(value).filter((key) => !allowed.includes(key));
26
47
  if (unsupported.length > 0)
27
- throw new Error(`${path} contains unsupported fields: ${unsupported.join(", ")}. ${hint}`);
48
+ throw new Error(`${path} contains unsupported fields: ${unsupported.join(", ")}. ${hint} ${unsupportedChildFieldAdvice(unsupported, scripts)}`);
28
49
  return value;
29
50
  }
30
51
  /** Single pass: text inserted for a placeholder is never scanned again. Unrecognized brace text stays literal. */
@@ -93,12 +114,12 @@ const SETTLE_HELPER = [
93
114
  " 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(\"; \"));",
94
115
  "}",
95
116
  ].join("\n");
96
- function buildTasksScript(steps, originalTask) {
117
+ function buildTasksScript(steps, originalTask, scripts) {
97
118
  if (!Array.isArray(steps) || steps.length === 0)
98
119
  throw new Error("tasks must be a non-empty array of { agent, task } items.");
99
120
  const children = steps.map((item, index) => {
100
121
  const path = `tasks[${index}]`;
101
- 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}`);
122
+ const record = exactFields(item, path, ["agent", "task", ...CHILD_FIELDS], "Each tasks item accepts agent and task, plus optional cwd and model.", scripts);
102
123
  const agent = nonEmptyString(record.agent, `${path}.agent`);
103
124
  const task = nonEmptyString(record.task, `${path}.task`);
104
125
  const taskExpression = compileTemplate(task, {
@@ -132,20 +153,20 @@ function buildChainScript(steps, originalTask) {
132
153
  let stepChildren;
133
154
  let outputName;
134
155
  if (isPlainRecord(step) && Object.hasOwn(step, "parallel")) {
135
- const record = exactFields(step, path, ["parallel"], `A parallel step accepts only parallel; as is supported on sequential steps only.${TOP_LEVEL_CONTROLS_HINT}`);
156
+ const record = exactFields(step, path, ["parallel"], "A parallel step accepts only parallel; as is supported on sequential steps only.", false);
136
157
  const items = record.parallel;
137
158
  if (!Array.isArray(items) || items.length === 0)
138
159
  throw new Error(`${path}.parallel must be a non-empty array of { agent, task } items.`);
139
160
  stepChildren = items.map((item, itemIndex) => {
140
161
  const itemPath = `${path}.parallel[${itemIndex}]`;
141
- 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}`);
162
+ const itemRecord = exactFields(item, itemPath, ["agent", "task", ...CHILD_FIELDS], "Each parallel item accepts agent and task, plus optional cwd and model.", false);
142
163
  const agent = nonEmptyString(itemRecord.agent, `${itemPath}.agent`);
143
164
  const task = nonEmptyString(itemRecord.task, `${itemPath}.task`);
144
165
  return { key: `step-${number}-${itemIndex + 1}`, agent, fields: childFields(itemRecord, itemPath), taskExpression: compileTemplate(task, { path: `${itemPath}.task`, hasOriginalTask, previous, outputs }) };
145
166
  });
146
167
  }
147
168
  else {
148
- 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}`);
169
+ 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);
149
170
  const agent = nonEmptyString(record.agent, `${path}.agent`);
150
171
  let task;
151
172
  if (record.task === undefined) {
@@ -173,7 +194,7 @@ function buildChainScript(steps, originalTask) {
173
194
  lines.push("return { ok: true, children };");
174
195
  return lines.join("\n");
175
196
  }
176
- /** Validate exact data shapes and expand them into a package-owned workflow script. */
177
- export function buildStructuredWorkflowScript(kind, steps, originalTask) {
178
- return kind === "tasks" ? buildTasksScript(steps, originalTask) : buildChainScript(steps, originalTask);
197
+ /** Validate exact data shapes and expand them into a package-owned workflow script. `scripts` is true only for the named `parallel` workflow; top-level tasks and chain exist only when workflow scripts are disabled. */
198
+ export function buildStructuredWorkflowScript(kind, steps, originalTask, scripts) {
199
+ return kind === "tasks" ? buildTasksScript(steps, originalTask, scripts) : buildChainScript(steps, originalTask);
179
200
  }
@@ -5,6 +5,7 @@ import { parseWorkflowChildSummary } from "./workflow-child-summary.js";
5
5
  import { HOST_STEP_MAX_COUNT, assertUniqueHostStepIds, parseHostStepNode } from "../runs/shared/host-step-status.js";
6
6
  import { assertWorkflowLaneKey, normalizeWorkflowLaneMetadata } from "../runs/shared/lane-metadata.js";
7
7
  import { projectWorkflowKeyRevival } from "./workflow-revival.js";
8
+ import { EXTERNAL_CLI_ADAPTER_SAFETY, isCodeOwnedExternalCliAdapterId } from "../runs/shared/external-cli-contract.js";
8
9
  export const WORKFLOW_RECEIPT_VERSION = 1;
9
10
  export const WORKFLOW_RECEIPT_FILE = "workflow-receipt.json";
10
11
  const MAX_WORKFLOW_RECEIPT_BYTES = 2 * 1024 * 1024;
@@ -127,6 +128,30 @@ function parseExternalCliMachine(value, label) {
127
128
  if (unknownRemoteGit.length > 0 || (remoteGit.head !== undefined && (typeof remoteGit.head !== "string" || !remoteGit.head.trim())) || (remoteGit.branch !== undefined && (typeof remoteGit.branch !== "string" || !remoteGit.branch.trim())) || (remoteGit.dirty !== undefined && typeof remoteGit.dirty !== "boolean"))
128
129
  throw new Error(`${label}.machine.remoteGit is invalid.`);
129
130
  }
131
+ function parseCodeOwnedSafety(value, adapter, label) {
132
+ if (!value || typeof value !== "object" || Array.isArray(value))
133
+ throw new Error(`${label}.safety is missing.`);
134
+ const safety = value;
135
+ const profile = EXTERNAL_CLI_ADAPTER_SAFETY[adapter];
136
+ const unknownSafety = Object.keys(safety).filter((field) => !Object.hasOwn(profile, field));
137
+ if (unknownSafety.length > 0)
138
+ throw new Error(`${label}.safety has unsupported fields: ${unknownSafety.join(", ")}.`);
139
+ if (Object.entries(profile).some(([field, expected]) => safety[field] !== expected))
140
+ throw new Error(`${label}.safety is invalid.`);
141
+ }
142
+ function parseExternalCliSafetySource(value, label) {
143
+ if (value === undefined)
144
+ return false;
145
+ if (!value || typeof value !== "object" || Array.isArray(value))
146
+ throw new Error(`${label}.safetySource must be an object.`);
147
+ const source = value;
148
+ const unknownSource = Object.keys(source).filter((field) => !["measured", "command"].includes(field));
149
+ if (unknownSource.length > 0)
150
+ throw new Error(`${label}.safetySource has unsupported fields: ${unknownSource.join(", ")}.`);
151
+ if (source.measured !== false || (source.command !== undefined && (typeof source.command !== "string" || !source.command.trim())))
152
+ throw new Error(`${label}.safetySource is invalid.`);
153
+ return true;
154
+ }
130
155
  function parseExternalCliReceiptMetadata(value, key, source) {
131
156
  if (value === undefined)
132
157
  return undefined;
@@ -134,7 +159,7 @@ function parseExternalCliReceiptMetadata(value, key, source) {
134
159
  if (!value || typeof value !== "object" || Array.isArray(value))
135
160
  throw new Error(`${label} must be an object.`);
136
161
  const metadata = value;
137
- const unknownMetadata = Object.keys(metadata).filter((field) => !["adapter", "capabilities", "machine", "safety", "outputArtifacts", "handoff", "supervisor", "nonResumableReason"].includes(field));
162
+ const unknownMetadata = Object.keys(metadata).filter((field) => !["adapter", "capabilities", "machine", "safety", "safetySource", "outputArtifacts", "handoff", "supervisor", "nonResumableReason"].includes(field));
138
163
  if (unknownMetadata.length > 0)
139
164
  throw new Error(`${label} has unsupported fields: ${unknownMetadata.join(", ")}.`);
140
165
  const adapter = metadata.adapter;
@@ -160,65 +185,21 @@ function parseExternalCliReceiptMetadata(value, key, source) {
160
185
  if (metadata.machine !== undefined)
161
186
  parseExternalCliMachine(metadata.machine, label);
162
187
  const safety = metadata.safety;
163
- if (adapterRecord.id === "codex-exec") {
164
- if (!safety || typeof safety !== "object" || Array.isArray(safety))
165
- throw new Error(`${label}.safety is missing.`);
166
- const safetyRecord = safety;
167
- const unknownSafety = Object.keys(safetyRecord).filter((field) => !["sandbox", "approvalPolicy", "ephemeral"].includes(field));
168
- if (unknownSafety.length > 0)
169
- throw new Error(`${label}.safety has unsupported fields: ${unknownSafety.join(", ")}.`);
170
- if (safetyRecord.sandbox !== "read-only" || safetyRecord.approvalPolicy !== "never" || safetyRecord.ephemeral !== true)
171
- throw new Error(`${label}.safety is invalid.`);
172
- }
173
- else if (adapterRecord.id === "codex-exec-writer") {
174
- if (!safety || typeof safety !== "object" || Array.isArray(safety))
175
- throw new Error(`${label}.safety is missing.`);
188
+ const hasSafetySource = parseExternalCliSafetySource(metadata.safetySource, label);
189
+ if (adapterRecord.id === "claude-code" && !hasSafetySource && safety && typeof safety === "object" && !Array.isArray(safety) && safety.authentication === undefined) {
176
190
  const safetyRecord = safety;
177
- const unknownSafety = Object.keys(safetyRecord).filter((field) => !["access", "sandbox", "approvalPolicy", "ephemeral"].includes(field));
191
+ const unknownSafety = Object.keys(safetyRecord).filter((field) => !["permissionMode", "tools", "mcp", "settingSources", "sessionPersistence"].includes(field));
178
192
  if (unknownSafety.length > 0)
179
193
  throw new Error(`${label}.safety has unsupported fields: ${unknownSafety.join(", ")}.`);
180
- if (safetyRecord.access !== "workspace-write" || safetyRecord.sandbox !== "workspace-write" || safetyRecord.approvalPolicy !== "never" || safetyRecord.ephemeral !== true)
194
+ if (safetyRecord.permissionMode !== "plan" || safetyRecord.tools !== "none" || safetyRecord.mcp !== "empty-strict" || safetyRecord.settingSources !== "none" || safetyRecord.sessionPersistence !== false)
181
195
  throw new Error(`${label}.safety is invalid.`);
182
196
  }
183
- else if (adapterRecord.id === "claude-code") {
184
- if (!safety || typeof safety !== "object" || Array.isArray(safety))
185
- throw new Error(`${label}.safety is missing.`);
186
- const safetyRecord = safety;
187
- const legacy = safetyRecord.authentication === undefined;
188
- const unknownSafety = Object.keys(safetyRecord).filter((field) => !(legacy
189
- ? ["permissionMode", "tools", "mcp", "settingSources", "sessionPersistence"]
190
- : ["access", "authentication", "permissionMode", "tools", "mcp", "settingSources", "userSettingsTrust", "sessionPersistence"]).includes(field));
191
- if (unknownSafety.length > 0)
192
- throw new Error(`${label}.safety has unsupported fields: ${unknownSafety.join(", ")}.`);
193
- if (legacy) {
194
- if (safetyRecord.permissionMode !== "plan" || safetyRecord.tools !== "none" || safetyRecord.mcp !== "empty-strict" || safetyRecord.settingSources !== "none" || safetyRecord.sessionPersistence !== false)
195
- throw new Error(`${label}.safety is invalid.`);
196
- }
197
- else if (safetyRecord.access !== "read-only" || safetyRecord.authentication !== "existing-cli-required" || safetyRecord.permissionMode !== "plan" || safetyRecord.tools !== "none" || safetyRecord.mcp !== "empty-strict" || safetyRecord.settingSources !== "user" || safetyRecord.userSettingsTrust !== "required" || safetyRecord.sessionPersistence !== false)
198
- throw new Error(`${label}.safety is invalid.`);
199
- }
200
- else if (adapterRecord.id === "claude-code-writer") {
201
- if (!safety || typeof safety !== "object" || Array.isArray(safety))
202
- throw new Error(`${label}.safety is missing.`);
203
- const safetyRecord = safety;
204
- const unknownSafety = Object.keys(safetyRecord).filter((field) => !["access", "authentication", "permissionMode", "tools", "mcp", "settingSources", "userSettingsTrust", "sessionPersistence"].includes(field));
205
- if (unknownSafety.length > 0)
206
- throw new Error(`${label}.safety has unsupported fields: ${unknownSafety.join(", ")}.`);
207
- if (safetyRecord.access !== "workspace-write" || safetyRecord.authentication !== "existing-cli-required" || safetyRecord.permissionMode !== "acceptEdits" || safetyRecord.tools !== "Read,Write,Edit,Glob,Grep" || safetyRecord.mcp !== "empty-strict" || safetyRecord.settingSources !== "user" || safetyRecord.userSettingsTrust !== "required" || safetyRecord.sessionPersistence !== false)
208
- throw new Error(`${label}.safety is invalid.`);
209
- }
210
- else if (adapterRecord.id === "cursor-agent" || adapterRecord.id === "cursor-agent-writer") {
211
- if (!safety || typeof safety !== "object" || Array.isArray(safety))
212
- throw new Error(`${label}.safety is missing.`);
213
- const safetyRecord = safety;
214
- const unknownSafety = Object.keys(safetyRecord).filter((field) => !["access", "authentication", "mode", "sandbox", "workspaceTrust", "sessionReuse"].includes(field));
215
- if (unknownSafety.length > 0)
216
- throw new Error(`${label}.safety has unsupported fields: ${unknownSafety.join(", ")}.`);
217
- const writer = adapterRecord.id === "cursor-agent-writer";
218
- if (safetyRecord.access !== (writer ? "workspace-write" : "read-only") || safetyRecord.authentication !== "cursor-api-key-or-existing-login" || safetyRecord.mode !== (writer ? "print" : "ask") || safetyRecord.sandbox !== "enabled" || safetyRecord.workspaceTrust !== "existing-required" || safetyRecord.sessionReuse !== false)
219
- throw new Error(`${label}.safety is invalid.`);
197
+ else if (isCodeOwnedExternalCliAdapterId(adapterRecord.id)) {
198
+ parseCodeOwnedSafety(safety, adapterRecord.id, label);
220
199
  }
221
200
  else if (adapterRecord.id === "grok-build") {
201
+ if (hasSafetySource)
202
+ throw new Error(`${label}.safetySource is invalid for the legacy grok-build adapter.`);
222
203
  if (!safety || typeof safety !== "object" || Array.isArray(safety))
223
204
  throw new Error(`${label}.safety is missing.`);
224
205
  const safetyRecord = safety;
@@ -228,6 +209,8 @@ function parseExternalCliReceiptMetadata(value, key, source) {
228
209
  if (safetyRecord.access !== "read-only" || safetyRecord.authentication !== "xai-api-key-required" || safetyRecord.permissionMode !== "plan" || safetyRecord.tools !== "read_file,grep,list_dir" || safetyRecord.deniedTools !== "run_terminal_cmd,search_replace,Agent,Bash,Edit,Write,MCPTool" || safetyRecord.sandbox !== "read-only" || safetyRecord.webSearch !== false || safetyRecord.subagents !== false || safetyRecord.config !== "temporary-home" || safetyRecord.updates !== "disabled" || safetyRecord.sessionPersistence !== false)
229
210
  throw new Error(`${label}.safety is invalid.`);
230
211
  }
212
+ else if (hasSafetySource)
213
+ throw new Error(`${label}.safetySource is invalid for the generic adapter.`);
231
214
  else if (safety !== undefined)
232
215
  throw new Error(`${label}.safety is invalid for the generic adapter.`);
233
216
  const handoff = metadata.handoff;
@@ -1,7 +1,7 @@
1
1
  import { randomUUID } from "node:crypto";
2
2
  import { stableJsonDigest } from "../shared/launch-contract.js";
3
3
  import { createWorkflowResourcePermit, } from "../shared/workflow-child-permit.js";
4
- import { buildStructuredWorkflowScript, isPlainRecord, TOP_LEVEL_CONTROLS_HINT } from "./structured-workflow-scripts.js";
4
+ import { buildStructuredWorkflowScript, isPlainRecord, unsupportedChildFieldAdvice } from "./structured-workflow-scripts.js";
5
5
  const RESOURCE_NAME_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;
6
6
  export const MAX_ARGS_BYTES = 16 * 1024;
7
7
  export const MAX_ARGS_FIELDS = 16;
@@ -152,9 +152,9 @@ function resolveRunCi(args) {
152
152
  function resolveParallel(args) {
153
153
  const unsupported = Object.keys(args).filter((key) => key !== "tasks");
154
154
  if (unsupported.length > 0)
155
- return { error: `workflow 'parallel' args contain unsupported fields: ${unsupported.join(", ")}. Pass args.tasks: [{ agent, task, cwd?, model? }, ...].${TOP_LEVEL_CONTROLS_HINT}` };
155
+ return { error: `workflow 'parallel' args contain unsupported fields: ${unsupported.join(", ")}. Pass args.tasks: [{ agent, task, cwd?, model? }, ...]. ${unsupportedChildFieldAdvice(unsupported, true)}` };
156
156
  try {
157
- return { script: buildStructuredWorkflowScript("tasks", args.tasks, undefined) };
157
+ return { script: buildStructuredWorkflowScript("tasks", args.tasks, undefined, true) };
158
158
  }
159
159
  catch (error) {
160
160
  return { error: `workflow 'parallel' args.${error instanceof Error ? error.message : String(error)}` };
@@ -204,7 +204,7 @@ export function resolveStructuredWorkflowResource(input) {
204
204
  }
205
205
  if (jsonByteLength({ [kind]: steps, task }) > MAX_ARGS_BYTES)
206
206
  return { ok: false, error: `${kind} input exceeds ${MAX_ARGS_BYTES} bytes.` };
207
- const script = buildStructuredWorkflowScript(kind, JSON.parse(JSON.stringify(steps)), task);
207
+ const script = buildStructuredWorkflowScript(kind, JSON.parse(JSON.stringify(steps)), task, false);
208
208
  return { ok: true, resource: issueWorkflowResource(kind, STRUCTURED_WORKFLOW_RESOURCE_VERSION, script) };
209
209
  }
210
210
  catch (error) {
@@ -54,6 +54,8 @@ export declare function resumedRunStarted(sourceAsyncDir: string, newRunId: stri
54
54
  export declare function workflowResumeClaimState(asyncDir: string, options?: {
55
55
  liveness?: ClaimLiveness;
56
56
  }): WorkflowResumeClaimState;
57
+ /** Creates the claim file only if none exists, with its whole body in place at once. */
58
+ export declare function createClaimFile(filePath: string, claim: object): boolean;
57
59
  /**
58
60
  * Claims the right to continue the stopped run in `asyncDir` as `newRunId`. A dead claimant is
59
61
  * superseded by the next generation file; of several takers, the one whose exclusive create
@@ -93,7 +93,7 @@ export function workflowResumeClaimState(asyncDir, options = {}) {
93
93
  return claimantLiveness(top.filePath, top.claim, options.liveness) === "dead" ? { kind: "none" } : { kind: "busy", pid: top.claim.pid, newRunId: top.claim.newRunId };
94
94
  }
95
95
  /** Creates the claim file only if none exists, with its whole body in place at once. */
96
- function createClaimFile(filePath, claim) {
96
+ export function createClaimFile(filePath, claim) {
97
97
  const tempPath = `${filePath}.${process.pid}.${randomUUID()}.tmp`;
98
98
  try {
99
99
  fs.writeFileSync(tempPath, JSON.stringify(claim, null, 2), "utf-8");
@@ -1,5 +1,5 @@
1
1
  type WorkflowResumeTrigger = "auto" | "manual";
2
- export type WorkflowResumeRefusalCode = "not-owned" | "not-interrupted" | "claim-busy" | "claim-resumed" | "launch-missing" | "launch-invalid" | "structured" | "internal" | "digest" | "authority" | "capacity" | "attempts" | "launch-failed";
2
+ export type WorkflowResumeRefusalCode = "not-owned" | "not-interrupted" | "claim-busy" | "claim-resumed" | "launch-missing" | "launch-invalid" | "structured" | "internal" | "digest" | "authority" | "capacity" | "attempts" | "launch-failed" | "drained";
3
3
  export interface WorkflowResumeRefusalReason {
4
4
  code: WorkflowResumeRefusalCode;
5
5
  reason: string;
@@ -12,7 +12,7 @@ import { isReusableWorkflowStopCause, WORKFLOW_STOP_CAUSE_OWNER_EXITED } from ".
12
12
  /** A run may be resumed again after at most this many resumes that followed Pi exits (auto-resume only). */
13
13
  const MAX_WORKFLOW_RESUME_ATTEMPTS = 3;
14
14
  export function workflowResumeRefusal(code, reason, runId) {
15
- const byHand = code === "launch-missing" || code === "launch-invalid" || code === "structured" || code === "internal" || code === "digest" || code === "authority"
15
+ const byHand = code === "launch-missing" || code === "launch-invalid" || code === "structured" || code === "internal" || code === "digest" || code === "authority" || code === "drained"
16
16
  ? relaunchByHandText(runId)
17
17
  : code === "capacity" || code === "attempts" || code === "launch-failed" ? resumeByHandText(runId) : "";
18
18
  return { code, reason, byHand };
@@ -67,6 +67,8 @@ export function prepareWorkflowResume(input) {
67
67
  const status = readStatus(sourceAsyncDir);
68
68
  if (!status || status.mode !== "workflow" || !isReusableWorkflowStopCause(status.workflow?.stopCause))
69
69
  return refuse("not-interrupted", "not interrupted; pass message to revive one of its children");
70
+ if (status.workflow?.drainRequestedAt !== undefined)
71
+ return refuse("drained", "it was being drained when it was interrupted");
70
72
  // The attempt the resumed run records: only resumes that follow a Pi exit count.
71
73
  const attempt = (status.workflow?.resumeOrigin?.attempt ?? 0) + (status.workflow?.stopCause === WORKFLOW_STOP_CAUSE_OWNER_EXITED ? 1 : 0);
72
74
  if (trigger === "auto" && attempt > MAX_WORKFLOW_RESUME_ATTEMPTS)