@sema-agent/core 5.20.0 → 5.21.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 (312) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/dist/agents/agent-definition.d.ts +7 -0
  3. package/dist/agents/agent-transcript-tool.d.ts +30 -0
  4. package/dist/agents/builtin-agents.d.ts +60 -0
  5. package/dist/agents/cascade.d.ts +107 -0
  6. package/dist/agents/cumulative-stats.d.ts +56 -0
  7. package/dist/agents/observer.d.ts +162 -0
  8. package/dist/agents/peer-admission.d.ts +95 -0
  9. package/dist/agents/repair-loop.d.ts +226 -0
  10. package/dist/agents/retain-ledger.d.ts +141 -0
  11. package/dist/agents/roster-store.d.ts +105 -0
  12. package/dist/agents/send-message-tool.d.ts +92 -0
  13. package/dist/agents/session-util.d.ts +5 -0
  14. package/dist/agents/subagent-steps.d.ts +66 -0
  15. package/dist/agents/subagent.d.ts +600 -0
  16. package/dist/agents/suspend-guard.d.ts +29 -0
  17. package/dist/agents/teacher.d.ts +75 -0
  18. package/dist/agents/team.d.ts +120 -1
  19. package/dist/agents/tool-filter.d.ts +34 -0
  20. package/dist/agents/verify.d.ts +198 -0
  21. package/dist/bench/metrics.d.ts +455 -0
  22. package/dist/brain/anthropic.d.ts +30 -0
  23. package/dist/brain/circuit-breaker.d.ts +33 -0
  24. package/dist/brain/context-overflow.d.ts +60 -3
  25. package/dist/brain/degrading.d.ts +67 -0
  26. package/dist/brain/errors.d.ts +42 -0
  27. package/dist/brain/failover.d.ts +15 -0
  28. package/dist/brain/media-degrade.d.ts +39 -0
  29. package/dist/brain/model-presets.d.ts +31 -0
  30. package/dist/brain/open-responses.d.ts +19 -0
  31. package/dist/brain/openai.d.ts +46 -0
  32. package/dist/brain/reasoning.d.ts +106 -1
  33. package/dist/brain/repetition.d.ts +83 -0
  34. package/dist/brain/request-params.d.ts +56 -0
  35. package/dist/brain/retry.d.ts +46 -0
  36. package/dist/brain/routing.d.ts +12 -0
  37. package/dist/brain/status-sink.d.ts +30 -1
  38. package/dist/brain/stream-engine.d.ts +147 -0
  39. package/dist/brain/stream-shared.d.ts +34 -0
  40. package/dist/brain/terminal-cause.d.ts +31 -0
  41. package/dist/brain/timeout.d.ts +107 -0
  42. package/dist/brain/tool-call-id.d.ts +20 -0
  43. package/dist/brain/tool-call-repair.d.ts +13 -0
  44. package/dist/config/catalog.d.ts +47 -0
  45. package/dist/config/defaults.d.ts +33 -0
  46. package/dist/core/a2a-task-state.d.ts +53 -0
  47. package/dist/core/a2a.d.ts +51 -0
  48. package/dist/core/arg-summary.d.ts +62 -0
  49. package/dist/core/ask-question.d.ts +272 -2
  50. package/dist/core/auto-compaction.d.ts +467 -0
  51. package/dist/core/auto-compaction.js +20 -6
  52. package/dist/core/auto-mode-prompt-assets.d.ts +8 -0
  53. package/dist/core/auto-mode-prompt.d.ts +27 -0
  54. package/dist/core/auto-mode.d.ts +54 -3
  55. package/dist/core/auto-promote.d.ts +100 -0
  56. package/dist/core/background-agent-store.d.ts +292 -0
  57. package/dist/core/background-shell.d.ts +110 -0
  58. package/dist/core/cache-break-detector.d.ts +34 -0
  59. package/dist/core/canonical-json.d.ts +57 -0
  60. package/dist/core/checkpoint-store.d.ts +1574 -16
  61. package/dist/core/compliance.d.ts +30 -0
  62. package/dist/core/consolidate-scope.d.ts +75 -0
  63. package/dist/core/context-edit.d.ts +99 -0
  64. package/dist/core/context-guard.d.ts +46 -0
  65. package/dist/core/exec-gate.d.ts +44 -0
  66. package/dist/core/exec-output-tail.d.ts +61 -0
  67. package/dist/core/file-snapshot-store.d.ts +104 -0
  68. package/dist/core/fs-write-gate-policy.d.ts +36 -0
  69. package/dist/core/git-worktree-env.d.ts +31 -0
  70. package/dist/core/governance-codes.d.ts +19 -0
  71. package/dist/core/hooks.d.ts +608 -1
  72. package/dist/core/human-input-projection.d.ts +37 -0
  73. package/dist/core/human-input-projection.js +13 -0
  74. package/dist/core/image-downsample.d.ts +74 -0
  75. package/dist/core/locked-config.d.ts +37 -0
  76. package/dist/core/lsp-diagnostics.d.ts +77 -0
  77. package/dist/core/lsp-protocol.d.ts +29 -0
  78. package/dist/core/lsp-session.d.ts +60 -1
  79. package/dist/core/lsp.d.ts +150 -1
  80. package/dist/core/mailbox-store.d.ts +57 -0
  81. package/dist/core/mcp.d.ts +381 -0
  82. package/dist/core/media-byte-cap.d.ts +21 -0
  83. package/dist/core/memory-admission.d.ts +71 -0
  84. package/dist/core/memory-engine/content-origin.d.ts +64 -0
  85. package/dist/core/memory-engine/data-plane.d.ts +43 -0
  86. package/dist/core/memory-engine/dual-root.d.ts +24 -0
  87. package/dist/core/memory-engine/engine.d.ts +230 -0
  88. package/dist/core/memory-engine/engine.js +103 -35
  89. package/dist/core/memory-engine/file-backend.d.ts +155 -0
  90. package/dist/core/memory-engine/frontmatter.d.ts +16 -0
  91. package/dist/core/memory-engine/layout.d.ts +217 -0
  92. package/dist/core/memory-engine/memory-backend-contract.d.ts +12 -0
  93. package/dist/core/memory-engine/migrate.d.ts +9 -0
  94. package/dist/core/memory-engine/scan.d.ts +12 -0
  95. package/dist/core/memory-engine/scope-contract.d.ts +61 -1
  96. package/dist/core/memory-engine/sync-client.d.ts +87 -0
  97. package/dist/core/memory-engine/sync.d.ts +60 -0
  98. package/dist/core/memory-engine/tools.d.ts +41 -0
  99. package/dist/core/memory-engine/types.d.ts +188 -0
  100. package/dist/core/memory-recall.d.ts +141 -0
  101. package/dist/core/memory-vector.d.ts +20 -0
  102. package/dist/core/memory.d.ts +458 -0
  103. package/dist/core/message-utils.d.ts +6 -0
  104. package/dist/core/oracle-isolation.d.ts +69 -0
  105. package/dist/core/permission-rule-consent.d.ts +138 -0
  106. package/dist/core/permission-rule-model.d.ts +122 -0
  107. package/dist/core/permission-rule-store.d.ts +119 -3
  108. package/dist/core/permission-rules.d.ts +87 -1
  109. package/dist/core/present-plan-tool.d.ts +20 -0
  110. package/dist/core/pricing.d.ts +26 -0
  111. package/dist/core/property-harness.d.ts +86 -0
  112. package/dist/core/protocol-naming.d.ts +38 -0
  113. package/dist/core/protocol-table.d.ts +61 -0
  114. package/dist/core/push-queue.d.ts +1 -0
  115. package/dist/core/remote-env.d.ts +383 -1
  116. package/dist/core/retention-policy.d.ts +33 -0
  117. package/dist/core/retention.d.ts +51 -0
  118. package/dist/core/roles.d.ts +59 -0
  119. package/dist/core/runner/active-skill-scope.d.ts +34 -0
  120. package/dist/core/runner/assemble-result.d.ts +134 -0
  121. package/dist/core/runner/compaction-call-options.d.ts +97 -1
  122. package/dist/core/runner/grounding-signal.d.ts +10 -0
  123. package/dist/core/runner/image.d.ts +17 -0
  124. package/dist/core/runner/image.js +29 -15
  125. package/dist/core/runner/memory-consolidation.d.ts +60 -0
  126. package/dist/core/runner/prepare-memory.d.ts +59 -0
  127. package/dist/core/runner/prepare-task.d.ts +1011 -2
  128. package/dist/core/runner/prepare-task.js +12 -11
  129. package/dist/core/runner/prompt-suggestions.d.ts +7 -0
  130. package/dist/core/runner/runtask.d.ts +304 -3
  131. package/dist/core/runner/session-file-state-replay.d.ts +49 -0
  132. package/dist/core/runner/session-rule-policy.d.ts +58 -0
  133. package/dist/core/runner/strict-output-schema.d.ts +18 -3
  134. package/dist/core/runner/synthetic-tools.d.ts +113 -0
  135. package/dist/core/runner/teardown-bounded.d.ts +34 -0
  136. package/dist/core/runner/tool-disclosure.d.ts +227 -0
  137. package/dist/core/runner/tool-output-projection.d.ts +6 -0
  138. package/dist/core/runner/turn-attachments.d.ts +634 -0
  139. package/dist/core/runner/usage-accounting.d.ts +32 -0
  140. package/dist/core/runtime.d.ts +9 -0
  141. package/dist/core/safe-notify.d.ts +64 -0
  142. package/dist/core/safety-axis-vocab.d.ts +23 -0
  143. package/dist/core/safety-merge-corpus.d.ts +37 -0
  144. package/dist/core/scheduler.d.ts +121 -0
  145. package/dist/core/secret-env.d.ts +32 -0
  146. package/dist/core/select-model.d.ts +15 -0
  147. package/dist/core/sensitive-path-policy.d.ts +42 -0
  148. package/dist/core/session-policy-store.d.ts +94 -0
  149. package/dist/core/session-reconcile.d.ts +80 -0
  150. package/dist/core/session-store.d.ts +85 -0
  151. package/dist/core/session.d.ts +153 -0
  152. package/dist/core/shared-memory/contract.d.ts +22 -0
  153. package/dist/core/shared-memory/normalize.d.ts +123 -2
  154. package/dist/core/shared-memory/tools.d.ts +14 -0
  155. package/dist/core/shared-memory/types.d.ts +105 -0
  156. package/dist/core/shutdown-debug.d.ts +6 -0
  157. package/dist/core/side-query.d.ts +38 -0
  158. package/dist/core/side-query.js +6 -1
  159. package/dist/core/skill-tool-specifier.d.ts +72 -0
  160. package/dist/core/skills-directory.d.ts +100 -1
  161. package/dist/core/spec-contract.d.ts +89 -0
  162. package/dist/core/store-contracts/background-agent-store-contract.d.ts +31 -0
  163. package/dist/core/store-contracts/checkpoint-store-contract.d.ts +26 -0
  164. package/dist/core/store-contracts/contract-harness.d.ts +20 -0
  165. package/dist/core/store-contracts/contract-kit-version.d.ts +27 -0
  166. package/dist/core/store-contracts/file-snapshot-store-contract.d.ts +8 -0
  167. package/dist/core/store-contracts/mailbox-store-contract.d.ts +42 -0
  168. package/dist/core/store-contracts/tool-result-store-contract.d.ts +13 -0
  169. package/dist/core/strategy-store.d.ts +37 -0
  170. package/dist/core/stub-env.d.ts +7 -0
  171. package/dist/core/surrogate-safe-slice.d.ts +35 -0
  172. package/dist/core/task-notification.d.ts +202 -0
  173. package/dist/core/task-outcome.d.ts +53 -0
  174. package/dist/core/task-registry-agent.d.ts +337 -1
  175. package/dist/core/task-registry-monitor.d.ts +12 -0
  176. package/dist/core/task-registry-shared.d.ts +540 -0
  177. package/dist/core/task-registry.d.ts +343 -0
  178. package/dist/core/task-registry.js +13 -2
  179. package/dist/core/task-tool-shape.d.ts +44 -0
  180. package/dist/core/tighten-task-spec.d.ts +21 -0
  181. package/dist/core/tool-detach.d.ts +21 -0
  182. package/dist/core/tool-errors.d.ts +131 -0
  183. package/dist/core/tool-errors.js +4 -0
  184. package/dist/core/tool-name-aliases.d.ts +27 -0
  185. package/dist/core/tool-policy.d.ts +555 -0
  186. package/dist/core/tool-result-budget.d.ts +32 -0
  187. package/dist/core/tool-result-store.d.ts +174 -1
  188. package/dist/core/tools.d.ts +45 -0
  189. package/dist/core/trace.d.ts +323 -0
  190. package/dist/core/types.d.ts +3859 -2
  191. package/dist/core/untrusted-egress.d.ts +8 -0
  192. package/dist/core/untrusted-text.d.ts +156 -0
  193. package/dist/core/usage-window-store.d.ts +95 -0
  194. package/dist/core/version.d.ts +1 -0
  195. package/dist/core/warm-resume.d.ts +17 -0
  196. package/dist/core/wiring-manifest.d.ts +169 -0
  197. package/dist/core/with-retry.d.ts +24 -0
  198. package/dist/core/workflow-journal-store.d.ts +160 -0
  199. package/dist/core/workflow-run-store-contract.d.ts +25 -0
  200. package/dist/core/workflow-run-store.d.ts +119 -0
  201. package/dist/engine/compaction/compaction.d.ts +256 -1
  202. package/dist/engine/compaction/utils.d.ts +94 -0
  203. package/dist/engine/execution-env/kill-tree.d.ts +29 -0
  204. package/dist/engine/execution-env/node-execution-env.d.ts +94 -0
  205. package/dist/engine/harness/agent-harness.d.ts +116 -0
  206. package/dist/engine/harness/agent-harness.js +3 -14
  207. package/dist/engine/harness/messages.d.ts +15 -0
  208. package/dist/engine/harness/types.d.ts +464 -2
  209. package/dist/engine/llm/diagnostics.d.ts +4 -0
  210. package/dist/engine/llm/event-stream.d.ts +3 -0
  211. package/dist/engine/llm/index.d.ts +7 -0
  212. package/dist/engine/llm/types.d.ts +500 -3
  213. package/dist/engine/llm/validation.d.ts +3 -0
  214. package/dist/engine/loop/agent-loop.d.ts +87 -2
  215. package/dist/engine/loop/runtime-deps.d.ts +7 -0
  216. package/dist/engine/loop/types.d.ts +424 -0
  217. package/dist/engine/lsp/frame-decoder.d.ts +13 -0
  218. package/dist/engine/lsp/node-lsp-manager.d.ts +107 -0
  219. package/dist/engine/lsp/stdio-lsp-transport.d.ts +7 -0
  220. package/dist/engine/session/import-validate.d.ts +27 -0
  221. package/dist/engine/session/log-digest.d.ts +93 -0
  222. package/dist/engine/session/memory-repo.d.ts +6 -0
  223. package/dist/engine/session/memory-storage.d.ts +2 -0
  224. package/dist/engine/session/session.d.ts +75 -0
  225. package/dist/engine/session/storage-base.d.ts +8 -0
  226. package/dist/fixtures/index.d.ts +36 -0
  227. package/dist/index.d.ts +16 -1
  228. package/dist/index.js +0 -1
  229. package/dist/internal/harness-types.d.ts +6 -0
  230. package/dist/internal/harness.d.ts +11 -0
  231. package/dist/internal/llm.d.ts +6 -0
  232. package/dist/orchestration/builtin-workflows.d.ts +53 -0
  233. package/dist/orchestration/dev-vm-script-runner.d.ts +19 -0
  234. package/dist/orchestration/goal.d.ts +57 -0
  235. package/dist/orchestration/goal.js +3 -0
  236. package/dist/orchestration/run-spec.d.ts +42 -0
  237. package/dist/orchestration/run-workflow-tool.d.ts +169 -0
  238. package/dist/orchestration/workflow-governance.d.ts +61 -0
  239. package/dist/orchestration/workflow-meta.d.ts +28 -0
  240. package/dist/orchestration/workflow-observe.d.ts +60 -0
  241. package/dist/orchestration/workflow-primitives.d.ts +23 -1
  242. package/dist/orchestration/workflow-sandbox-conformance.d.ts +38 -0
  243. package/dist/orchestration/workflow-script-runner.d.ts +88 -0
  244. package/dist/orchestration/workflow-script-store.d.ts +98 -0
  245. package/dist/orchestration/workflow-size-guideline.d.ts +67 -0
  246. package/dist/orchestration/workflow-types.d.ts +169 -2
  247. package/dist/orchestration/workflow.d.ts +358 -0
  248. package/dist/prompt-assembly/artifact-store.d.ts +33 -0
  249. package/dist/prompt-assembly/artifact.d.ts +25 -0
  250. package/dist/prompt-assembly/assemble.d.ts +20 -0
  251. package/dist/prompt-assembly/composer.d.ts +29 -0
  252. package/dist/prompt-assembly/epoch.d.ts +55 -1
  253. package/dist/prompt-assembly/event-registry.d.ts +35 -0
  254. package/dist/prompt-assembly/explain.d.ts +12 -0
  255. package/dist/prompt-assembly/tool-catalog.d.ts +38 -0
  256. package/dist/prompt-assembly/turn-snapshot.d.ts +40 -0
  257. package/dist/prompt-assembly/types.d.ts +115 -0
  258. package/dist/prompts/coordinator.d.ts +27 -0
  259. package/dist/prompts/default.d.ts +539 -0
  260. package/dist/prompts/simple-sections.d.ts +45 -0
  261. package/dist/prompts/supervisor.d.ts +66 -0
  262. package/dist/scenarios/env.d.ts +28 -0
  263. package/dist/scenarios/full-body.d.ts +50 -0
  264. package/dist/scenarios/scenario-registry.d.ts +60 -0
  265. package/dist/scenarios/teacher-quickstart.d.ts +27 -0
  266. package/dist/server/http.d.ts +17 -0
  267. package/dist/stores/cc/lockfile.d.ts +6 -0
  268. package/dist/stores/cc/mailbox-store.d.ts +8 -0
  269. package/dist/stores/cc/roster-adapter.d.ts +4 -0
  270. package/dist/stores/cc/sidecar-transcript.d.ts +66 -0
  271. package/dist/stores/file/background-agent-store.d.ts +24 -0
  272. package/dist/stores/file/checkpoint-store.d.ts +38 -0
  273. package/dist/stores/file/file-snapshot-store.d.ts +25 -0
  274. package/dist/stores/file/fs-atomic.d.ts +155 -0
  275. package/dist/stores/file/index.d.ts +89 -0
  276. package/dist/stores/file/mailbox-store.d.ts +36 -0
  277. package/dist/stores/file/memory-store.d.ts +82 -0
  278. package/dist/stores/file/permission-rule-store.d.ts +79 -0
  279. package/dist/stores/file/session-policy-store.d.ts +28 -0
  280. package/dist/stores/file/session-store.d.ts +40 -0
  281. package/dist/stores/file/shared-ledger.d.ts +83 -0
  282. package/dist/stores/file/tool-result-store.d.ts +11 -0
  283. package/dist/stores/file/usage-window-store.d.ts +18 -0
  284. package/dist/stores/file/workflow-journal-store.d.ts +100 -0
  285. package/dist/stores/file/workflow-run-store.d.ts +11 -0
  286. package/dist/tools/fs/bash-readonly-classifier.d.ts +282 -0
  287. package/dist/tools/fs/encoding.d.ts +60 -0
  288. package/dist/tools/fs/fs-bash.d.ts +133 -0
  289. package/dist/tools/fs/fs-pdf.d.ts +28 -0
  290. package/dist/tools/fs/fs-search-tools.d.ts +5 -0
  291. package/dist/tools/fs/fs-shared.d.ts +360 -0
  292. package/dist/tools/fs/fs-write.d.ts +16 -0
  293. package/dist/tools/fs/gh-rate-limit.d.ts +22 -0
  294. package/dist/tools/fs/index.d.ts +79 -0
  295. package/dist/tools/fs/notebook.d.ts +56 -0
  296. package/dist/tools/fs/pdf.d.ts +70 -0
  297. package/dist/tools/fs/pdf.js +8 -2
  298. package/dist/tools/fs/repo-map.d.ts +10 -0
  299. package/dist/tools/fs/safety.d.ts +376 -0
  300. package/dist/tools/fs/search.d.ts +131 -0
  301. package/dist/tools/loop-tick.d.ts +24 -0
  302. package/dist/tools/monitor.d.ts +55 -0
  303. package/dist/tools/scheduler-tools.d.ts +51 -0
  304. package/dist/tools/sql-adapters.d.ts +18 -0
  305. package/dist/tools/sql.d.ts +25 -0
  306. package/dist/tools/task-list.d.ts +77 -0
  307. package/dist/tools/todo.d.ts +8 -0
  308. package/dist/tools/web.d.ts +184 -0
  309. package/dist/tools/worktree.d.ts +81 -0
  310. package/package.json +2 -2
  311. package/dist/tools/gitea-issue.d.ts +0 -13
  312. package/dist/tools/gitea-issue.js +0 -75
@@ -1,16 +1,40 @@
1
+ /**
2
+ * design/98 §2.5 / §E.2 (S8b, security core) — the DEFAULT-DENY governance for a sub-agent an LLM-authored
3
+ * workflow script spawns. The child spec is BUILT (complete-by-construction) from the deployment's trusted
4
+ * {@link WorkflowGovernanceBaseline} + a strict WHITELIST of safe work-fields the script may set — NEVER by
5
+ * stripping a denylist off the untrusted spec (codex BLOCKER2: a missed control-plane field would leak).
6
+ *
7
+ * The script's spec is UNTRUSTED. Only {@link WHITELIST_KEYS} are ever read from it; every other field
8
+ * (toolPolicy / onAsk / hooks / principal / tools / mcp / skills / lspManager / checkpointStore /
9
+ * getApiKeyAndHeaders / promptProvider / sessionId / signal / …) is structurally never copied. The model is
10
+ * chosen by NAME ONLY (resolved against an allowlist to a deploy-configured `Model` — the script never sees a
11
+ * `Model` object, which carries `baseUrl`/`headers` = an exfil surface, codex v3 BLOCKER). Resource limits
12
+ * are CLAMPED to the baseline + workflow ceilings (`tightenTaskSpec` only covers the safety knobs, not
13
+ * cost/token caps — codex Q4).
14
+ */
1
15
  import type { Model } from "../internal/llm.js";
2
16
  import type { ImageInput, TaskSpec, ThinkingLevel, WorkflowGovernanceBaseline } from "../core/types.js";
17
+ /** Thrown when an LLM-authored script picks a `modelName` not in the workflow model allowlist (or no
18
+ * allowlist is configured). FAIL-CLOSED: a script can only ever name a model the deployment pre-approved. */
3
19
  export declare class WorkflowModelNotAllowedError extends Error {
4
20
  readonly modelName: string;
5
21
  readonly code = "workflow.model_not_allowed";
6
22
  constructor(modelName: string, reason: string);
7
23
  }
24
+ /**
25
+ * The SAFE fields an LLM-authored workflow script may set per sub-agent — the WORK, never the control plane.
26
+ * `model` is a NAME (string), NOT a `ModelRef`/`Model` object (codex v3 BLOCKER: a `Model` carries
27
+ * `baseUrl`/`headers`/`extraBody` = endpoint + auth-header injection). No `modelRole`/`roles` (a `roles.select`
28
+ * conditional selector is its own vector). The engine resolves `modelName` against the allowlist.
29
+ */
8
30
  export interface WorkflowAgentSpec {
9
31
  objective: string;
10
32
  modelName?: string;
11
33
  thinking?: ThinkingLevel;
12
34
  systemPrompt?: string;
13
35
  images?: ImageInput[];
36
+ /** Every sub-field must be a POSITIVE number — a non-positive value is a DISABLE sentinel downstream
37
+ * (or an exhausted budget), never a tighter ceiling, and is refused (see {@link NON_POSITIVE_LIMIT_MSG}). */
14
38
  limits?: {
15
39
  maxTurns?: number;
16
40
  maxWalltimeMs?: number;
@@ -18,17 +42,54 @@ export interface WorkflowAgentSpec {
18
42
  maxCostUsd?: number;
19
43
  };
20
44
  }
45
+ /**
46
+ * The SINGLE source of truth for the whitelist (a test pins that it contains no control-plane key). `objective`
47
+ * + `modelName` are handled explicitly in {@link buildGovernedChildSpec}; the rest map 1:1 onto `TaskSpec`.
48
+ */
21
49
  export declare const WHITELIST_KEYS: readonly ["objective", "modelName", "thinking", "systemPrompt", "images", "limits"];
50
+ /** Per-child workflow ceilings the engine forces onto every spawned agent (design/98 §D.6), independent of
51
+ * what the script asks for. The child's effective limits = min(script, baseline, these). */
22
52
  export interface WorkflowChildCaps {
53
+ /** design/164 — per-child wall-clock ceiling in MILLISECONDS (was `perAgentTimeoutSec`, seconds).
54
+ * No default: a deployment that wants a ceiling states it. */
23
55
  perAgentMaxWalltimeMs?: number;
24
56
  childMaxCostUsd?: number;
25
57
  childMaxTokens?: number;
26
58
  childMaxTurns?: number;
27
59
  }
60
+ /**
61
+ * RB-378 disclosure — one resource field whose EFFECTIVE (applied) value differs from what the script's spec
62
+ * literally carried. `requested` is `undefined` when the script omitted the field entirely (a baseline/cap
63
+ * ceiling was FORCED onto an unset field, not just a script value pushed down). Emitted so a caller can tell
64
+ * "the script asked for/omitted X" apart from "the child actually ran under Y" — see
65
+ * {@link buildGovernedChildSpec}'s `onResourceClamp` param.
66
+ */
28
67
  export interface ResourceClampNote {
29
68
  field: "maxCostUsd" | "maxTokens" | "maxWalltimeMs" | "maxTurns";
69
+ /** What the script's spec literally set for this field, or `undefined` if it never set it. */
30
70
  requested: number | undefined;
71
+ /** The effective value the child actually runs under (min of script/baseline/caps, or a forced ceiling). */
31
72
  applied: number;
32
73
  }
74
+ /** Resolve an LLM-supplied model NAME to a deploy-configured `Model`, FAIL-CLOSED against the allowlist.
75
+ * Throws (never falls open to the whole catalog) when no allowlist is configured or the name is not on it. */
33
76
  export declare function resolveModelName(name: string, allowlist: string[] | undefined, models: Record<string, Model> | undefined): Model;
77
+ /**
78
+ * Build a TRUSTED child `TaskSpec` for an LLM-authored sub-agent (design/98 §2.5). Complete-by-construction:
79
+ * 1. read ONLY the whitelist work-fields off the untrusted script spec (type-checked);
80
+ * 2. resolve `modelName` → a deploy `Model` against the allowlist (fail-closed);
81
+ * 3. clamp resource limits to the baseline + workflow ceilings;
82
+ * 4. `tightenTaskSpec(baseline.base, safe)` → the child spec (baseline governance FIRST, safe work-fields
83
+ * overlay; safety fields can only equal-or-tighten — belt-and-suspenders over the whitelist).
84
+ * Every governance/control-plane field of the result comes from `baseline.base` (the deployment's trusted
85
+ * config), never from the script.
86
+ *
87
+ * RB-378: `onResourceClamp`, when given, receives the non-empty list of {@link ResourceClampNote}s produced by
88
+ * step 3 — i.e. it fires exactly when the child's effective maxCostUsd/maxTokens/maxWalltimeMs/maxTurns diverges
89
+ * from what the script's spec literally asked for (never called when nothing was clamped/forced). The clamp
90
+ * VALUES and the fact that it is always-tighten-never-raise are UNCHANGED by this param — it is a pure
91
+ * disclosure hook the caller can wire to a log/event channel (see `buildWorkflowPrimitives`, which logs it
92
+ * onto the run's log stream so the LLM-authored script's caller can see requested→applied per field instead
93
+ * of the child silently running under different limits than the script wrote).
94
+ */
34
95
  export declare function buildGovernedChildSpec(scriptSpec: unknown, baseline: WorkflowGovernanceBaseline, models: Record<string, Model> | undefined, caps?: WorkflowChildCaps, onResourceClamp?: (notes: ResourceClampNote[]) => void): TaskSpec;
@@ -1,11 +1,39 @@
1
+ /**
2
+ * design/98 §2.4 (S8b) — STATIC, NON-EVAL extraction of a workflow script's `export const meta = {...}`.
3
+ *
4
+ * 🔴 The meta block is parsed as PURE DATA by a small recursive-descent reader that NEVER executes the
5
+ * script (no `vm`, no `eval`, no `Function`) — evaluating untrusted source to read its metadata would itself
6
+ * be the injection surface. The reader accepts ONLY literal values (string / number / boolean / null / array
7
+ * / plain object) and REJECTS anything that could carry behavior or pollute a prototype:
8
+ * - identifier values (a variable reference), function calls, template literals, spreads, computed keys,
9
+ * method shorthand, getters/setters;
10
+ * - the dangerous keys `__proto__` / `constructor` / `prototype` (prototype-pollution guard).
11
+ * Any violation throws {@link WorkflowScriptError} so the `run_workflow` tool can hand the LLM a structured
12
+ * "fix your meta" error BEFORE the (hard) sandbox ever runs the body.
13
+ */
1
14
  import type { WorkflowMeta } from "./workflow-script-runner.js";
15
+ /** Thrown when an LLM-authored workflow script is malformed at the static layer (bad meta, oversized source,
16
+ * a forbidden construct). Carries a `code` so the tool can return a structured error the model can act on. */
2
17
  export declare class WorkflowScriptError extends Error {
3
18
  readonly code = "workflow.script_error";
4
19
  constructor(message: string);
5
20
  }
21
+ /**
22
+ * Statically extract + validate a workflow script's `export const meta`. Returns a typed {@link WorkflowMeta}
23
+ * (name + description required, both strings; `phases`/`whenToUse` optional). NEVER executes the script.
24
+ * @throws {WorkflowScriptError} on a missing/malformed/non-literal meta.
25
+ */
6
26
  export declare function parseWorkflowMeta(source: string): WorkflowMeta;
27
+ /** Replace every string literal (incl. template text, recursing into `${…}` code) and comment with spaces. */
7
28
  export declare function stripStringsAndComments(src: string): string;
29
+ /** CC `wxl` semantics: a `Date.now` / `Math.random` member access, or an ARGLESS `new Date()`, anywhere in the
30
+ * body's CODE (strings/comments stripped) — each silently busts the resume prefix cache. */
8
31
  export declare function workflowScriptReadsClockOrRandom(body: string): boolean;
32
+ /**
33
+ * Parse the meta AND return the script BODY with the `export const meta = {...}` declaration removed — for a
34
+ * runner that compiles the remaining body as an async function (the meta is DATA, parsed statically; only the
35
+ * body is ever executed). An optional trailing `;` after the declaration is trimmed.
36
+ */
9
37
  export declare function splitWorkflowMeta(source: string): {
10
38
  meta: WorkflowMeta;
11
39
  body: string;
@@ -1,16 +1,76 @@
1
1
  import type { WorkflowRunStore, WorkflowRunSummary } from "../core/workflow-run-store.js";
2
2
  import type { WorkflowEvent, WorkflowItemStatus, WorkflowRun, WorkflowRunStatus } from "./workflow.js";
3
+ /** design/97 S1c: mark a run RUNNING (called by `runWorkflow` before it emits `run_start`).
4
+ * γ 批 B-3 (BREAKING): carries the run's SCOPE — {@link subscribeWorkflow} gates on it. */
3
5
  export declare function markWorkflowActive(runId: string, scope: string): void;
6
+ /** T2A-9 (2026-07-05 soak): is this runId currently ACTIVE in-process? Used by `startWorkflow` to reject an
7
+ * explicit duplicate `opts.runId` up front — two runs sharing one observation channel let the first finisher
8
+ * close the second's event stream (and best-effort-swallow its store writes). Synchronous, race-free with
9
+ * markWorkflowActive/closeWorkflowChannel (same tick). */
4
10
  export declare function isWorkflowRunActive(runId: string): boolean;
11
+ /**
12
+ * design/97 S1c: fan one {@link WorkflowEvent} to every live subscriber of `runId`. Called by `runWorkflow`
13
+ * for EVERY emitted event. BEST-EFFORT — a `push` never throws (the {@link PushQueue} just buffers), and a
14
+ * missing channel (no subscriber) is a no-op; nothing here can break the workflow. A subscriber that
15
+ * registered AFTER the run started receives only events from that point on (live progress, not a replay).
16
+ */
5
17
  export declare function publishWorkflowEvent(runId: string, event: WorkflowEvent): void;
18
+ /**
19
+ * design/97 S1c: close the live channel for `runId` (called by `runWorkflow` at `run_end`). Closes every
20
+ * subscriber's queue so their `for await` loops END cleanly, and drops the channel entry (no leak). A
21
+ * subscriber's queue is also pruned individually if it stops iterating before the run ends (see
22
+ * {@link subscribeWorkflow}). Idempotent — closing a missing/already-closed channel is a no-op.
23
+ */
6
24
  export declare function closeWorkflowChannel(runId: string): void;
25
+ /**
26
+ * design/97 S1c: subscribe to a RUNNING workflow's live {@link WorkflowEvent} progress (the `/workflows` live
27
+ * view). Returns an `AsyncIterable<WorkflowEvent>` that yields every event emitted AFTER subscription and ends
28
+ * when the run finishes (its channel closes at `run_end`). **In-process + opt-in**: subscribing registers a
29
+ * queue in the module registry; `runWorkflow` only fans events to a runId that HAS a subscriber, so this is
30
+ * pay-for-what-you-use.
31
+ *
32
+ * Subscribe BEFORE or DURING the run: a queue registered before `run_start` catches the whole stream; one
33
+ * registered mid-run catches the rest (no replay of past events — the historical view is {@link getWorkflowRun}).
34
+ * If the run already ended (or never ran in this process), the returned iterable simply yields nothing and ends.
35
+ *
36
+ * The queue is pruned from the registry when the consumer's iteration ENDS (loop completes, `break`, or throw)
37
+ * — so a consumer that stops early does not leak a buffer (the `finally` removes it).
38
+ */
7
39
  export declare function subscribeWorkflow(runId: string, scope: string): AsyncIterable<WorkflowEvent>;
40
+ /**
41
+ * design/97 S1c: list a scope's workflow runs (newest first) as lightweight {@link WorkflowRunSummary}
42
+ * projections — **history included** (completed / failed, not just running), the "看之前的" query. A thin
43
+ * pass-through to {@link WorkflowRunStore.listByScope}; `opts.status` filters to one lifecycle state and
44
+ * `opts.limit` caps the count (newest N).
45
+ */
8
46
  export declare function listWorkflowRuns(store: WorkflowRunStore, scope: string, opts?: {
9
47
  status?: WorkflowRunStatus;
10
48
  limit?: number;
11
49
  }): Promise<WorkflowRunSummary[]>;
50
+ /**
51
+ * design/97 S1c: fetch ONE full {@link WorkflowRun} (phases / agents / stats) by id — the `/workflows` detail
52
+ * view. 🔐 SCOPED (CORE-1~9 audit BLOCKER): returns the run ONLY when its `scope` equals the caller's `scope`
53
+ * (the tenant) — else `null`, just like {@link listWorkflowRuns}/the journal load. A run id is unguessable, but
54
+ * without this check a cross-tenant id leaks the run's metadata / groups / redacted prompts+outputs / stats; the
55
+ * store's lower-level `get(id)` carries no scope, so the isolation MUST be enforced here at the observe layer.
56
+ */
12
57
  export declare function getWorkflowRun(store: WorkflowRunStore, id: string, scope: string): Promise<WorkflowRun | null>;
58
+ /** design/99 MF-W display status. */
13
59
  export type AgentDisplayStatus = "queued" | "running" | "done" | "failed" | "interrupted";
60
+ /**
61
+ * design/99 MF-W (design-review DoR ⑤+⑥): the SHARED, anti-drift projection of a workflow agent's record-level
62
+ * status → a CC-style display status, derived PURELY from the persisted record (the agent's `status` + `startedAt`
63
+ * + the run's status), so the shell + service render IDENTICALLY (no per-shell drift — the WPe port lives once,
64
+ * here, not copied N times). Covers 5 of the 8 contract states from the durable record:
65
+ * - `completed` → `done`; `failed` → `failed`.
66
+ * - `running` but `startedAt` ABSENT → `queued` (enqueued, still waiting for a concurrency slot — the DoR ⑥ fix:
67
+ * a queued agent no longer lies as `running`).
68
+ * - `running` + started, while the RUN still runs → `running`; started but the RUN terminated (the agent never
69
+ * finished) → `interrupted`.
70
+ * The other contract states are intentionally NOT here: `idle` (last-activity age) is a SERVICE live aggregation
71
+ * (core's `ToolActivity` has no timestamp); `skipped`/`paused`/`stopped` are not core states (no engine producer —
72
+ * see the DoR "don't model an enum arm the engine never emits").
73
+ */
14
74
  export declare function deriveAgentDisplayStatus(agent: {
15
75
  status: WorkflowItemStatus;
16
76
  startedAt?: number;
@@ -1,11 +1,33 @@
1
+ /**
2
+ * design/98 §E.1 (S8b) — the MEMBRANE adapter: extract the bound primitive functions FROM a trusted
3
+ * {@link WorkflowRunContext} and assemble a flat, sterile {@link WorkflowPrimitives} record. A
4
+ * {@link WorkflowScriptRunner} receives ONLY this record — the host `ctx` object (with its prototype chain
5
+ * into the host realm) structurally never enters the runner, so a script cannot walk
6
+ * `ctx.constructor.constructor(...)` to escape (the chain is unreachable: there is no `ctx`).
7
+ *
8
+ * Two modes:
9
+ * - **governed** (`governance` set) — for an LLM-AUTHORED script: the `agent` primitive runs the untrusted
10
+ * spec through {@link buildGovernedChildSpec} (default-deny whitelist + baseline + model allowlist + clamp)
11
+ * BEFORE `ctx.agent`. The script can ONLY tighten the deployment governance, never escape it.
12
+ * - **trusted-dev** (no `governance`) — for a developer-authored script: the `agent` primitive passes the
13
+ * full `TaskSpec` straight through (the author IS the deployment).
14
+ */
1
15
  import type { Model } from "../internal/llm.js";
2
16
  import type { TaskSpec, WorkflowGovernanceBaseline } from "../core/types.js";
3
17
  import type { WorkflowAgentHandle, WorkflowRunContext } from "./workflow.js";
4
18
  import type { WorkflowPrimitives } from "./workflow-script-runner.js";
5
19
  import { type WorkflowChildCaps } from "./workflow-governance.js";
20
+ /** What an LLM-authored workflow needs to GOVERN each spawned sub-agent (design/98 §2.5). */
6
21
  export interface WorkflowGovernance {
7
22
  baseline: WorkflowGovernanceBaseline;
8
23
  models?: Record<string, Model>;
9
24
  caps?: WorkflowChildCaps;
10
25
  }
11
- export declare function buildWorkflowPrimitives(ctx: WorkflowRunContext, governance?: WorkflowGovernance, onAgentSpawn?: (handle: WorkflowAgentHandle) => void, parentThinking?: () => TaskSpec["thinking"], parentPrincipal?: string, parentCheckpointStoreDisabled?: boolean): WorkflowPrimitives;
26
+ /**
27
+ * Build the flat {@link WorkflowPrimitives} a {@link WorkflowScriptRunner} runs the script against. The
28
+ * `agent` primitive is GOVERNED when `governance` is set (LLM-authored), else a trusted pass-through.
29
+ */
30
+ export declare function buildWorkflowPrimitives(ctx: WorkflowRunContext, governance?: WorkflowGovernance, onAgentSpawn?: (handle: WorkflowAgentHandle) => void, parentThinking?: () => TaskSpec["thinking"], parentPrincipal?: string,
31
+ /** ruled 2026-08-04 — the host run set `TaskSpec.checkpointStore: null` (the per-run durable off
32
+ * switch). Every agent this workflow spawns inherits it; see the injection below. */
33
+ parentCheckpointStoreDisabled?: boolean): WorkflowPrimitives;
@@ -1,4 +1,42 @@
1
+ /**
2
+ * design/98 §2.3 (S8b) — the reusable CONFORMANCE CONTRACT a HARD {@link WorkflowScriptRunner}
3
+ * (`safeForUntrustedScripts:true`) MUST pass. Core ships the contract (zero deps beyond `node:assert`); a
4
+ * deployment's isolated-vm / separate-process runner imports it and runs it in its OWN test suite to prove
5
+ * its membrane does not leak. It runs a battery of sandbox-escape scripts against the runner and asserts each
6
+ * FAILS to reach a host capability (`process` / `require` / a host `Function`).
7
+ *
8
+ * The dev `vm` runner deliberately does NOT pass this (it is not a boundary) — see
9
+ * `test/workflow-vm-escape.test.ts`, which PROVES that and asserts `safeForUntrustedScripts === false`.
10
+ */
1
11
  import type { WorkflowScriptRunner } from "./workflow-script-runner.js";
12
+ /**
13
+ * Assert a HARD runner passes the sandbox-escape battery. Throws an `AssertionError` on the first escape that
14
+ * reaches a host capability.
15
+ *
16
+ * Structure, in the order it must hold:
17
+ * 1. a POSITIVE CONTROL ({@link runLivenessCanary}) — the runner executes a body, sees `scriptArgs`, and
18
+ * returns the value. Without this the battery is vacuous.
19
+ * 2. four probe families, each judging the MARSHALLED result. The capability families return an in-isolate
20
+ * WITNESS ({@link WITNESS_PRELUDE}) rather than the capability object, so a leak whose value cannot cross
21
+ * the marshalling boundary is no longer swallowed as "blocked".
22
+ * 3. a probe that THROWS is re-tested for liveness before its throw is read as "blocked"
23
+ * ({@link runProbeBody}) — the two meanings of a throw are separated by evidence, not by assumption.
24
+ */
25
+ /**
26
+ * The PRIMITIVES-WIRING battery. A production incident was a hard runner whose
27
+ * injection table wired only `agent` (+ return): `phase`/`log` were silently absent in the isolate, so whole
28
+ * runs recorded `phases: []` with no error anywhere. Sandbox tightness alone doesn't catch that — a runner can
29
+ * be perfectly escape-proof AND miss half the API. This battery proves EVERY {@link WorkflowPrimitives} member
30
+ * is present in-isolate, callable, and actually bridged back to the HOST primitives (recorded on the host
31
+ * side, not just observed in-script). Run it in the same suite as the escape battery.
32
+ */
2
33
  export declare function assertWorkflowPrimitivesWiring(runner: WorkflowScriptRunner): Promise<void>;
3
34
  export declare function assertWorkflowSandboxConformance(runner: WorkflowScriptRunner): Promise<void>;
35
+ /**
36
+ * PARITY-SPOT-WORKFLOW B2/F3 (CC `S0m` parity) — assert a runner ENFORCES determinism: Date.now() /
37
+ * Math.random() / argless new Date() throw (a clock/randomness read silently busts the resume prefix cache),
38
+ * while DATED construction (`new Date(0)`) stays available. SEPARATE from the sandbox/wiring batteries — those
39
+ * accept a minimal stub runner (they test the assertion's own leak/bridge logic); determinism requires a
40
+ * runner that actually executes the body against shimmed intrinsics (the dev vm runner + any hard runner).
41
+ */
4
42
  export declare function assertWorkflowDeterminism(runner: WorkflowScriptRunner): Promise<void>;
@@ -1,10 +1,55 @@
1
1
  import type { RunnerDeps, TaskSpec } from "../core/types.js";
2
+ /**
3
+ * design/98 §1.2 / §C — is LLM self-orchestration ACTIVE for this task? `true` ONLY when the task opted in
4
+ * AND the deployment provides BOTH a hard sandbox (`workflowScriptRunner.safeForUntrustedScripts`) AND a
5
+ * governance baseline (`workflowGovernanceBaseline`). This is the SINGLE gate that drives BOTH the
6
+ * orchestration-prompt injection (S8a) and the `run_workflow` tool mount (S8c) — kept in lockstep so the
7
+ * prompt never claims a capability the task lacks (§6.3). FAIL-CLOSED: any missing piece ⇒ off.
8
+ */
2
9
  export declare function isSelfOrchestrationActive(spec: TaskSpec, deps: RunnerDeps): boolean;
10
+ /**
11
+ * design/98 §C — the DEPLOYMENT-level capability: does this deployment SUPPORT self-orchestration / workflows
12
+ * AT ALL? `true` ⟺ it provides BOTH a hard sandbox (`workflowScriptRunner.safeForUntrustedScripts`) AND a
13
+ * governance baseline (`workflowGovernanceBaseline`). This is the deps half of {@link isSelfOrchestrationActive}
14
+ * with NO per-task `selfOrchestration` opt-in — the canonical predicate a control plane projects onto a
15
+ * capability surface (e.g. service `GET /v1/capabilities`.`workflows`) so a shell can HONESTLY gate `/workflows`
16
+ * + ultracode affordances: dark when `false` (the deployment can never run a workflow), available when `true`.
17
+ *
18
+ * SINGLE SOURCE so the surfaced capability can never drift from the gate that actually mounts `run_workflow`
19
+ * (a shell that shows `/workflows` as available while the engine fail-closes the tool = the exact mismatch
20
+ * design/98 §6.3 forbids). Per-principal/tier gating does NOT exist today — this is deployment-wide.
21
+ */
3
22
  export declare function workflowsCapability(deps: RunnerDeps): boolean;
23
+ /**
24
+ * design/98 §1.2 — the task OPTED IN (`selfOrchestration:true`) but the deployment did not meet the bar (a
25
+ * hard sandbox + a governance baseline), so self-orchestration is FAIL-CLOSED. Returns a human-readable
26
+ * reason for an operator warning, or `null` when not in this state (off, or fully active). The runner emits
27
+ * ONE operator-visible warning so a misconfigured opt-in is never silent.
28
+ */
4
29
  export declare function selfOrchestrationFailClosedReason(spec: TaskSpec, deps: RunnerDeps): string | null;
30
+ /**
31
+ * design/98 §D.3/§E.1 — the `WorkflowScriptRunner` SEAM for running an LLM-AUTHORED workflow script
32
+ * (S8 self-orchestration). A deployment provides the runner; **core does NOT ship a hard sandbox** (the
33
+ * isolated-vm / separate-process implementation is a deployment concern or a separate
34
+ * `@ai-only/workflow-sandbox` package). Core defines this contract + a TRUSTED-DEV vm runner
35
+ * ({@link import("./dev-vm-script-runner.js").devWorkflowScriptRunner}, S8b) that is explicitly NOT a
36
+ * security boundary, plus a conformance contract a hard runner must pass.
37
+ *
38
+ * 🔴 **Membrane = STRUCTURAL constraint, not a behavioral promise (codex v3/v4 BLOCKER).** The seam's
39
+ * `run()` accepts ONLY {@link WorkflowPrimitives} — a flat, sterile record of bound callbacks + a budget
40
+ * DATA snapshot. It does NOT accept a `WorkflowRunContext` (a host object whose prototype chain the script
41
+ * could walk via `ctx.constructor.constructor("return process")()` to escape). The engine extracts the bound
42
+ * functions FROM the context and constructs the primitives; the host context object structurally never
43
+ * enters the runner — there is no prototype chain into the host reachable from the script. A hard runner
44
+ * bridges each primitive as an isolated-vm `Reference`/`Callback` and copies `scriptArgs` via `ExternalCopy`.
45
+ */
46
+ /** The `export const meta = {...}` a workflow script declares (a PURE literal — parsed by the meta-AST,
47
+ * never `eval`'d; design/98 §2.4). Only `name`/`description` are required; the rest is observability. */
5
48
  export interface WorkflowMeta {
6
49
  name: string;
7
50
  description: string;
51
+ /** PARITY-SPOT-WORKFLOW B7 (CC card pretty.js:448042): `model` on a phase entry documents that phase's
52
+ * model override — parsed + stored + displayed on the pre-registered run phase (no behavior yet). */
8
53
  phases?: Array<{
9
54
  title: string;
10
55
  detail?: string;
@@ -12,24 +57,67 @@ export interface WorkflowMeta {
12
57
  }>;
13
58
  whenToUse?: string;
14
59
  }
60
+ /**
61
+ * The FLAT, STERILE primitives a workflow script may call — bound functions + a budget DATA snapshot, and
62
+ * NOTHING else from the host (design/98 §2.1). NO `ctx` object, NO host prototype chain. The HARD runner
63
+ * bridges each function as an isolated-vm `Reference`/`Callback` (the script `await`s them, round-tripping
64
+ * back to the main isolate where the real {@link import("./workflow.js").WorkflowRunContext} executes them).
65
+ *
66
+ * The `spec`/`opts`/stage/thunk shapes are `unknown` at this boundary on purpose: an LLM-authored `spec` is
67
+ * UNTRUSTED input that the engine's `agent` primitive validates + governs (whitelist construction +
68
+ * `tightenTaskSpec`, design/98 §2.5) BEFORE it ever reaches `runner.runTask`. The seam must not promise a
69
+ * trusted `TaskSpec` here.
70
+ */
15
71
  export interface WorkflowPrimitives {
72
+ /** Spawn one governed sub-agent. `spec` is an UNTRUSTED `WorkflowAgentSpec` (whitelist-constructed by the
73
+ * engine, design/98 §2.5); `opts` carries `label`/`phase`/`schema`. Resolves to the task result. */
16
74
  agent(spec: unknown, opts?: unknown): Promise<unknown>;
75
+ /** Run thunks concurrently (BARRIER); a thrown thunk resolves to `null`. */
17
76
  parallel(thunks: unknown[]): Promise<unknown[]>;
77
+ /** Run each item through all stages independently (no barrier between stages). */
18
78
  pipeline(items: unknown[], ...stages: unknown[]): Promise<unknown[]>;
79
+ /** Group work under a named phase (observability). */
19
80
  phase(title: string, body: unknown): Promise<unknown>;
81
+ /** Emit a narrator log line. */
20
82
  log(message: string): void;
83
+ /** LIVE budget accessors, mirroring {@link import("./workflow.js").WorkflowBudget} (NOT a one-shot data
84
+ * snapshot — a static snapshot would break the `while (budget.remaining() > N)` budget-scaled-depth loop
85
+ * the orchestration guidance promotes). `total` is a stable number/null; `spent()`/`remaining()` are bound
86
+ * functions the hard runner bridges (an isolated-vm `Reference`/`Callback`, like the other primitives) so
87
+ * each call re-reads the current spend. */
21
88
  budget: {
22
89
  total: number | null;
23
90
  spent(): number;
24
91
  remaining(): number;
25
92
  };
26
93
  }
94
+ /**
95
+ * The seam a deployment implements to execute an LLM-authored workflow script. The engine calls `run()` with
96
+ * the sterile {@link WorkflowPrimitives} + the script source + (copied) args; the runner compiles/executes
97
+ * the script in its isolation domain and returns the script's value + parsed {@link WorkflowMeta}.
98
+ */
27
99
  export interface WorkflowScriptRunner {
100
+ /**
101
+ * Whether this runner can SAFELY execute UNTRUSTED (LLM-authored) scripts. `true` = a hard sandbox
102
+ * (isolated-vm / separate process + container/seccomp). `false` = trusted-DEV authors only (the Node `vm`
103
+ * runner — NOT a security boundary, see {@link import("./dev-vm-script-runner.js").devWorkflowScriptRunner}).
104
+ *
105
+ * 🔴 The S8 gate (design/98 §C / §1.2) mounts the `run_workflow` tool + injects the orchestration prompt
106
+ * ONLY when this is `true`. `selfOrchestration:true` with no hard runner ⇒ FAIL-CLOSED (tool not mounted,
107
+ * prompt not injected, operator warning). Core NEVER runs an LLM script in the dev `vm`.
108
+ */
28
109
  readonly safeForUntrustedScripts: boolean;
29
110
  run(input: {
30
111
  scriptSource: string;
31
112
  primitives: WorkflowPrimitives;
32
113
  scriptArgs: unknown;
114
+ /**
115
+ * A HOST `AbortSignal` for ABORT CONTROL (the workflow aborting cancels the script run). 🔐 The runner MUST
116
+ * NOT expose this raw host object to the untrusted script — a host object's `.constructor.constructor` climbs
117
+ * to the host `Function`/`process`. Use it to abort isolate execution; if you surface abort-awareness to the
118
+ * script at all, wrap it isolate-side. {@link assertWorkflowSandboxConformance} supplies a host signal and
119
+ * probes for this leak (CORE-1~9 audit MAJOR).
120
+ */
33
121
  signal?: AbortSignal;
34
122
  }): Promise<{
35
123
  result: unknown;
@@ -1,20 +1,118 @@
1
+ /**
2
+ * PARITY-SPOT-WORKFLOW B5/F2 (CC pretty.js:449105-449141 + `Pqi` :149631) — the script-persistence seam behind
3
+ * the Workflow tool's `scriptPath`/`name` calling surface. CC persists EVERY invocation's script under the
4
+ * session directory and returns the path in the tool result, so the model iterates by EDITING THE FILE and
5
+ * re-invoking with `{scriptPath}` instead of resending the whole script; `{name}` resolves a saved workflow.
6
+ *
7
+ * Core is deployment-neutral: the tool takes this seam via `RunWorkflowToolDeps.scriptStore` (optional — when
8
+ * absent, `scriptPath`/`name` calls get an honest structured error and inline `script` works as before). The
9
+ * file-backed implementation below is the TOC default (mirrors CC's session-dir posture: dir 0o700 / file
10
+ * 0o600, best-effort persist that never blocks a launch).
11
+ */
12
+ /**
13
+ * design/140 §6 1a — a named-registry entry's RESOLVED form: the script source plus the registration's
14
+ * `defaultArgs` layer (the middle tier of the merge chain: call-time args > registered defaultArgs >
15
+ * script-internal fallbacks). ONE return shape: a registry that carries no defaults returns `{ script }`
16
+ * — the bare-string return is RETIRED (RB-482 #9, ruled 2026-08-03), matching {@link
17
+ * WorkflowScriptStore.resolveName}'s contract. A plain-JS store still returning a bare string is refused
18
+ * with a structured migration error at the tool boundary, not read as a resolution.
19
+ */
1
20
  export interface NamedWorkflowResolution {
2
21
  script: string;
22
+ /** Registration-time default args (a JSON value — this is where a control-plane/center下发的默认 lands).
23
+ * Merged UNDER the call-time args by {@link mergeWorkflowArgs} at tool-resolve time (parse-time snapshot:
24
+ * the run receives the merged VALUE; nothing re-queries the registry after launch). */
3
25
  defaultArgs?: unknown;
26
+ /**
27
+ * 团队通道 [426] CORE-1 — the top-level key a BARE STRING call-time arg normalizes into, so the "裸 string =
28
+ * <key>" ergonomic entry (published by the built-in `team-discussion` script: a bare string args IS the
29
+ * topic) composes with a registered object `defaultArgs` instead of colliding with it. When a `{name}` call
30
+ * passes a raw string AND this resolution carries an object `defaultArgs`, the tool wraps the string as
31
+ * `{ [stringArgKey]: <string> }` BEFORE the object merge (see {@link normalizeStringArg} / the run-workflow
32
+ * tool's resolve path). Defaults to `"topic"` (the built-in ergonomic contract). Ignored when `defaultArgs`
33
+ * is not a plain object (a bare string then reaches the script verbatim — pre-[426] behavior preserved). */
4
34
  stringArgKey?: string;
5
35
  }
36
+ /**
37
+ * design/140 §6 1b — one row of the named-workflow LISTING projection (the LLM-facing consumption face of
38
+ * `meta.whenToUse`). Mirrors the agents-side roster entry (subagent.ts `agentWhenToUseText`/CC `tIl`):
39
+ * `whenToUse` is shown when present, else `description`.
40
+ */
6
41
  export interface NamedWorkflowListing {
7
42
  name: string;
8
43
  description?: string;
9
44
  whenToUse?: string;
10
45
  }
11
46
  export interface WorkflowScriptStore {
47
+ /** γ 批 B-4 (codex γ-G3) — the CONFORMANCE MARKER for the scope-partitioned contract. Structural
48
+ * typing would otherwise let a pre-partition adapter (`load(path)`, `persist(runId, script)`)
49
+ * remain assignable — fewer-parameter functions are compatible in TypeScript — and silently
50
+ * ignore the scope argument, serving cross-tenant reads while the tool presents the operation as
51
+ * scope-bounded. A REQUIRED literal field breaks that assignability at compile time; the
52
+ * run-workflow tool also refuses at runtime when it is absent (plain-JS adapters). */
12
53
  readonly scopePartitioned: true;
54
+ /** Persist THIS invocation's resolved script, keyed by its runId. Returns the persisted path (what the tool
55
+ * reports back to the model). Failures should throw — the tool treats persistence as best-effort.
56
+ * γ 批 B-4 (BREAKING): `scope` PARTITIONS per-run scripts — the CC anchor is a per-session directory,
57
+ * and the port had dropped the axis (one flat directory let a model-supplied scriptPath read another
58
+ * scope's script). Implementations key storage by scope (the file store uses per-scope subdirs). */
13
59
  persist(runId: string, script: string, scope: string): Promise<string> | string;
60
+ /** Read a previously persisted script back. MUST refuse paths outside the store (the argument is
61
+ * model-supplied — containment is the store's contract, not the tool's).
62
+ * γ 批 B-4 (BREAKING): `scope` bounds the read to the CALLER's partition — a path pointing into
63
+ * another scope's partition must be refused exactly like a path outside the store. */
14
64
  load(scriptPath: string, scope: string): Promise<string> | string;
65
+ /** Resolve a SAVED workflow name to its registration (undefined = unknown name). Optional — a deployment
66
+ * without a named registry simply omits it. RB-482 #9 (ruled 2026-08-03): ONE return form — a
67
+ * {@link NamedWorkflowResolution} ({ script, defaultArgs? }); the legacy bare-string return is retired. A
68
+ * deployment entry of the SAME NAME as a built-in workflow SHADOWS the built-in (design/140 §6 1c).
69
+ * γ 批 RULING: deliberately NO scope axis here — saved names are a DEPLOYMENT-level registry (the
70
+ * built-ins' tier), shared across scopes like agent definitions; a multi-tenant deployment that wants
71
+ * per-tenant registries mounts per-tenant store instances. */
15
72
  resolveName?(name: string): Promise<NamedWorkflowResolution | undefined> | NamedWorkflowResolution | undefined;
73
+ /**
74
+ * design/140 §6 1b — enumerate the registry's SAVED workflows for the listing projection (tool card /
75
+ * roster faces). Optional: a store without a stable name registry omits it (the file store below does —
76
+ * its directory mixes per-run persisted scripts with saved names, so enumeration would advertise every
77
+ * past run as a "named workflow"). NOTE: only a SYNCHRONOUS return reaches the statically-built Workflow
78
+ * tool card; an async store should precompute if it wants card visibility.
79
+ */
16
80
  list?(): NamedWorkflowListing[] | Promise<NamedWorkflowListing[]>;
17
81
  }
82
+ /**
83
+ * design/140 §6 1a — the default-args merge: **call-time args > registered defaultArgs** (the script's own
84
+ * internal fallbacks remain the third tier, applied by the script itself). Semantics (locked by test):
85
+ * - both sides plain objects → SHALLOW top-level merge (`{...defaults, ...call}`): a top-level key present in
86
+ * the call args wins WHOLESALE — nested objects/arrays/scalars are replaced, never deep-merged;
87
+ * - call args absent (`undefined`) → the registered defaults verbatim;
88
+ * - call args a non-object (array / scalar / null) → the call args win wholesale (no structural mixing).
89
+ * Pure value-in/value-out: the caller snapshots the RESULT into the run (parse-time discipline, design/140 §2 —
90
+ * a resume replay never re-queries the registry; a post-launch registry change cannot reach an in-flight run).
91
+ */
18
92
  export declare function mergeWorkflowArgs(callArgs: unknown, defaultArgs: unknown): unknown;
93
+ /**
94
+ * 团队通道 [426] CORE-1 — NORMALIZE a bare-string call-time arg into `{ [key]: <string> }` so the published
95
+ * "裸 string = <key>" ergonomic entry (built-in `team-discussion`: bare string args IS the topic) COMPOSES
96
+ * with a registered object `defaultArgs` instead of colliding with it.
97
+ *
98
+ * The bug it fixes: {@link mergeWorkflowArgs}'s non-object branch lets a bare string win WHOLESALE — so a
99
+ * named workflow whose registration carries object `defaultArgs` (center 配的 members/rounds/finalizer) had
100
+ * its whole defaults block silently wiped the moment a caller used the ergonomic `{name, args: "<topic>"}`
101
+ * form, and the collab template quietly ran as a generic advocate/skeptic. Wrapping the string here lets the
102
+ * subsequent object merge preserve the defaults AND honor the topic.
103
+ *
104
+ * Applied ONLY when BOTH hold (otherwise return `callArgs` untouched — pre-[426] behavior byte-preserved):
105
+ * - `callArgs` is a string (the ergonomic form), AND
106
+ * - `defaultArgs` is a PLAIN OBJECT (there ARE object defaults to merge under; with no/scalar defaults a bare
107
+ * string must still reach the script verbatim — the built-in's own `raw === "string"` fallback handles it).
108
+ * `key` is the resolution's `stringArgKey` (a registry may declare which key its bare string maps to); the
109
+ * caller passes the built-in default `"topic"` when the resolution omits it.
110
+ */
19
111
  export declare function normalizeStringArg(callArgs: unknown, defaultArgs: unknown, key?: string): unknown;
112
+ /**
113
+ * File-backed {@link WorkflowScriptStore}: per-run scripts land as `<dir>/<scopeDir>/<runId>.js`
114
+ * (γ 批 B-4: per-scope partition — the CC per-session-dir posture restored on the tenant axis);
115
+ * `resolveName` reads `<dir>/<name>.js` at the ROOT (the deployment-level saved-name tier, see the
116
+ * interface RULING — deliberately outside every scope partition).
117
+ */
20
118
  export declare function createFileWorkflowScriptStore(dir: string): WorkflowScriptStore;
@@ -1,14 +1,81 @@
1
+ /**
2
+ * CC config key `workflowSizeGuideline`: an ADVISORY size guideline for LLM-authored workflows
3
+ * (small/medium/large/unrestricted), injected into the Workflow tool's prompt/description. It is
4
+ * guidance, NOT a cap — the hard ceiling stays `WorkflowLimits.maxAgents`.
5
+ *
6
+ * RB-339 (2026-07-30, clay A 案) — REBASELINED on CC 2.1.220 (语料 ../cc-decoded/pretty220.js). The
7
+ * module was anchored to 2.1.206 and had drifted on four points; all four are corrected here and the
8
+ * old "verbatim" claims (which were not true of the two sentence builders) are replaced with what
9
+ * each function actually is:
10
+ * 1. DEFAULT. CC's `_Td = "medium"` (:455529) with `Oft` (:455538) returning `{ size: "medium",
11
+ * isDefault: true }` whenever the setting is absent or not a member of the enum. sema defaulted
12
+ * to "unrestricted" (= inject nothing), so an unconfigured deployment got NO guideline at all.
13
+ * Behavior narrowing, declared: an unconfigured task now carries the medium section.
14
+ * 2. TWO-ARM SECTION. CC's `TTd(size, isDefault)` (:455514) has a DEFAULT arm ("This session has the
15
+ * default …" + the "/config" escape sentence) and an EXPLICIT arm ("A workflow size guideline is
16
+ * configured for this session:" with no escape sentence). sema had a single hand-written form.
17
+ * 3. CHANGE NOTICE. CC's `ETd` (:455523) — both arms differed from sema's wording.
18
+ * 4. Normalization. CC's `Msn` (:455494) is a MEMBERSHIP test returning `undefined` for a non-member
19
+ * (which then falls to the medium default); sema mapped every unknown value to "unrestricted",
20
+ * i.e. a typo in the setting silently disabled the guideline. Now `undefined`, per CC.
21
+ *
22
+ * Still-current 220 anchors: `rLs` enum (:455532) / `oko` caps (:455533) / `bTd` describe (:455507) /
23
+ * `STd` not-a-hard-limit sentence (:455511) / `Sj_` display label (:455497). Those five ARE verbatim.
24
+ *
25
+ * Injection site: CC appends the section to BOTH `prompt()` and `description()` of the Workflow tool
26
+ * (`oLs`, :455548 — returns "" for "unrestricted", else "\n\n" + the sentence). Snapshot semantics:
27
+ * CC memoizes the SESSION-START value (`Nsn`) so the card is stable within a session; a mid-session
28
+ * /config change reaches the model via a `workflow_size_guideline_change` attachment (`vTd`, :455555)
29
+ * rendered with `ETd`. sema equivalence: the card is built once per mount (`createRunWorkflowTool`) =
30
+ * per-task snapshot — same stability property.
31
+ *
32
+ * Mid-session change lane (SHIPPED — the module no longer ships static injection only): CC's `vTd`
33
+ * (:455555) recomputes the RESOLVED guideline each turn, recovers the last announced one (its own
34
+ * previous attachment, falling back to the session-start snapshot) and emits a
35
+ * `workflow_size_guideline_change` attachment rendered with `ETd` on inequality. sema's equivalent
36
+ * lives at the run loop's turn-boundary steerer (`runtask.ts`, alongside the structurally identical
37
+ * date_change / instructions_change lanes): the leg's resolved guideline is the baseline, the live
38
+ * `RunnerDeps.workflowLimits` read is the current value, and {@link workflowSizeGuidelineChangeNotice}
39
+ * is the copy. Comparison is on the RESOLVED coordinate on both sides, CC-exact — `vTd` compares
40
+ * `Oft(...).size` against `Nsn(...).size`, so a deployment writing down the value already in force by
41
+ * default is not a change. Two lane properties are sema's own and deliberate: the frame is
42
+ * continuation-gated (an advisory retune must never revive a finished run), and only the
43
+ * `WorkflowLimits` channel is watched — the direct-construction `RunWorkflowToolDeps.sizeGuideline` is
44
+ * a per-mount pin the runner never sets.
45
+ */
46
+ /** CC `rLs` member type — the config value space. */
1
47
  export type WorkflowSizeGuideline = "small" | "medium" | "large" | "unrestricted";
48
+ /** CC `rLs` (:455532) — the enum options, in CC's settings-face order. */
2
49
  export declare const WORKFLOW_SIZE_GUIDELINES: readonly WorkflowSizeGuideline[];
50
+ /** CC `_Td` (:455529) — the guideline in force when the deployment configured none. */
3
51
  export declare const WORKFLOW_SIZE_GUIDELINE_DEFAULT: WorkflowSizeGuideline;
52
+ /** CC `oko` (:455533) — the advisory agent count each tier aims under. */
4
53
  export declare const WORKFLOW_SIZE_GUIDELINE_AGENT_CAPS: Readonly<Record<"small" | "medium" | "large", number>>;
54
+ /** CC `Msn` (:455494) — a MEMBERSHIP test: the value when it is one of the four options, otherwise
55
+ * `undefined` (an unknown/absent value is "unconfigured", NOT "unrestricted" — see
56
+ * {@link resolveWorkflowSizeGuideline}, which is where the default is applied). */
5
57
  export declare function normalizeWorkflowSizeGuideline(value: unknown): WorkflowSizeGuideline | undefined;
58
+ /** CC `Oft` (:455538) — resolve the guideline in force plus whether it came from the default.
59
+ * `isDefault` drives the two arms of {@link workflowSizeGuidelineSection}. */
6
60
  export declare function resolveWorkflowSizeGuideline(value: unknown): {
7
61
  size: WorkflowSizeGuideline;
8
62
  isDefault: boolean;
9
63
  };
64
+ /** CC `ubd`/`yTd` — the tier's advisory agent count (undefined for "unrestricted"). CC feeds this into
65
+ * its workflow-size warning thresholds; exported for the same future lane + deployments. */
10
66
  export declare function workflowSizeGuidelineAgentCap(g: WorkflowSizeGuideline): number | undefined;
67
+ /** CC `bTd` (:455507) — the tier description embedded in the injected sentences. Verbatim. */
11
68
  export declare function describeWorkflowSizeGuideline(g: WorkflowSizeGuideline): string;
69
+ /** CC `Sj_` (:455497) — the settings-face display label ("Dynamic workflow size" enum row). Verbatim.
70
+ * Exported for a shell's settings 透传 (the shell only surfaces the key; the engine hosts it). */
12
71
  export declare function formatWorkflowSizeGuidelineLabel(g: WorkflowSizeGuideline): string;
72
+ /**
73
+ * CC `oLs` (:455548) — the section appended to the Workflow tool's prompt AND description, including
74
+ * the leading blank line. An EXPLICIT "unrestricted" injects nothing; an absent/unknown value resolves
75
+ * to the medium DEFAULT and injects the default arm (RB-339 — this is the behavior narrowing).
76
+ */
13
77
  export declare function workflowSizeGuidelineSection(value: unknown): string;
78
+ /** CC `ETd` (:455523) — the mid-session change notice. Verbatim. Emitted by the run loop's
79
+ * `workflow_size_guideline_change` turn-boundary lane (see the module header); this is that frame's
80
+ * ONLY copy — the lane renders through here rather than restating the sentences. */
14
81
  export declare function workflowSizeGuidelineChangeNotice(g: WorkflowSizeGuideline): string;