@sema-agent/core 5.19.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 (329) hide show
  1. package/CHANGELOG.md +102 -4
  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/roster-store.js +3 -0
  13. package/dist/agents/send-message-tool.d.ts +92 -0
  14. package/dist/agents/session-util.d.ts +5 -0
  15. package/dist/agents/subagent-steps.d.ts +66 -0
  16. package/dist/agents/subagent.d.ts +600 -0
  17. package/dist/agents/suspend-guard.d.ts +29 -0
  18. package/dist/agents/teacher.d.ts +75 -0
  19. package/dist/agents/team.d.ts +120 -1
  20. package/dist/agents/tool-filter.d.ts +34 -0
  21. package/dist/agents/verify.d.ts +198 -0
  22. package/dist/bench/metrics.d.ts +455 -0
  23. package/dist/brain/anthropic.d.ts +30 -0
  24. package/dist/brain/circuit-breaker.d.ts +33 -0
  25. package/dist/brain/circuit-breaker.js +14 -3
  26. package/dist/brain/context-overflow.d.ts +60 -3
  27. package/dist/brain/degrading.d.ts +67 -0
  28. package/dist/brain/errors.d.ts +42 -0
  29. package/dist/brain/failover.d.ts +15 -0
  30. package/dist/brain/media-degrade.d.ts +39 -0
  31. package/dist/brain/model-presets.d.ts +31 -0
  32. package/dist/brain/open-responses.d.ts +19 -0
  33. package/dist/brain/openai.d.ts +46 -0
  34. package/dist/brain/reasoning.d.ts +106 -1
  35. package/dist/brain/repetition.d.ts +83 -0
  36. package/dist/brain/request-params.d.ts +56 -0
  37. package/dist/brain/retry.d.ts +46 -0
  38. package/dist/brain/routing.d.ts +12 -0
  39. package/dist/brain/status-sink.d.ts +30 -1
  40. package/dist/brain/stream-engine.d.ts +147 -0
  41. package/dist/brain/stream-shared.d.ts +34 -0
  42. package/dist/brain/terminal-cause.d.ts +31 -0
  43. package/dist/brain/timeout.d.ts +108 -0
  44. package/dist/brain/timeout.js +11 -0
  45. package/dist/brain/tool-call-id.d.ts +20 -0
  46. package/dist/brain/tool-call-repair.d.ts +13 -0
  47. package/dist/config/catalog.d.ts +47 -0
  48. package/dist/config/defaults.d.ts +33 -0
  49. package/dist/core/a2a-task-state.d.ts +53 -0
  50. package/dist/core/a2a.d.ts +51 -0
  51. package/dist/core/arg-summary.d.ts +62 -0
  52. package/dist/core/ask-question.d.ts +272 -2
  53. package/dist/core/auto-compaction.d.ts +467 -0
  54. package/dist/core/auto-compaction.js +20 -6
  55. package/dist/core/auto-mode-prompt-assets.d.ts +8 -0
  56. package/dist/core/auto-mode-prompt.d.ts +27 -0
  57. package/dist/core/auto-mode.d.ts +54 -3
  58. package/dist/core/auto-promote.d.ts +100 -0
  59. package/dist/core/background-agent-store.d.ts +293 -0
  60. package/dist/core/background-agent-store.js +5 -0
  61. package/dist/core/background-shell.d.ts +110 -0
  62. package/dist/core/cache-break-detector.d.ts +34 -0
  63. package/dist/core/canonical-json.d.ts +57 -0
  64. package/dist/core/checkpoint-store.d.ts +1574 -16
  65. package/dist/core/compliance.d.ts +30 -0
  66. package/dist/core/consolidate-scope.d.ts +75 -0
  67. package/dist/core/context-edit.d.ts +99 -0
  68. package/dist/core/context-guard.d.ts +46 -0
  69. package/dist/core/exec-gate.d.ts +44 -0
  70. package/dist/core/exec-output-tail.d.ts +61 -0
  71. package/dist/core/file-snapshot-store.d.ts +104 -0
  72. package/dist/core/fs-write-gate-policy.d.ts +36 -0
  73. package/dist/core/git-worktree-env.d.ts +31 -0
  74. package/dist/core/governance-codes.d.ts +19 -0
  75. package/dist/core/hooks.d.ts +609 -1
  76. package/dist/core/human-input-projection.d.ts +37 -0
  77. package/dist/core/human-input-projection.js +13 -0
  78. package/dist/core/image-downsample.d.ts +74 -0
  79. package/dist/core/locked-config.d.ts +37 -0
  80. package/dist/core/lsp-diagnostics.d.ts +77 -0
  81. package/dist/core/lsp-protocol.d.ts +29 -0
  82. package/dist/core/lsp-session.d.ts +60 -1
  83. package/dist/core/lsp.d.ts +150 -1
  84. package/dist/core/mailbox-store.d.ts +57 -0
  85. package/dist/core/mailbox-store.js +2 -0
  86. package/dist/core/mcp.d.ts +385 -0
  87. package/dist/core/mcp.js +58 -11
  88. package/dist/core/media-byte-cap.d.ts +21 -0
  89. package/dist/core/memory-admission.d.ts +71 -0
  90. package/dist/core/memory-engine/content-origin.d.ts +64 -0
  91. package/dist/core/memory-engine/data-plane.d.ts +43 -0
  92. package/dist/core/memory-engine/dual-root.d.ts +24 -0
  93. package/dist/core/memory-engine/engine.d.ts +230 -0
  94. package/dist/core/memory-engine/engine.js +103 -35
  95. package/dist/core/memory-engine/file-backend.d.ts +155 -0
  96. package/dist/core/memory-engine/frontmatter.d.ts +16 -0
  97. package/dist/core/memory-engine/layout.d.ts +217 -0
  98. package/dist/core/memory-engine/memory-backend-contract.d.ts +12 -0
  99. package/dist/core/memory-engine/migrate.d.ts +9 -0
  100. package/dist/core/memory-engine/scan.d.ts +12 -0
  101. package/dist/core/memory-engine/scope-contract.d.ts +61 -1
  102. package/dist/core/memory-engine/sync-client.d.ts +87 -0
  103. package/dist/core/memory-engine/sync.d.ts +60 -0
  104. package/dist/core/memory-engine/tools.d.ts +41 -0
  105. package/dist/core/memory-engine/types.d.ts +188 -0
  106. package/dist/core/memory-recall.d.ts +141 -0
  107. package/dist/core/memory-vector.d.ts +20 -0
  108. package/dist/core/memory.d.ts +458 -0
  109. package/dist/core/message-utils.d.ts +6 -0
  110. package/dist/core/oracle-isolation.d.ts +69 -0
  111. package/dist/core/permission-rule-consent.d.ts +138 -0
  112. package/dist/core/permission-rule-model.d.ts +122 -0
  113. package/dist/core/permission-rule-store.d.ts +119 -3
  114. package/dist/core/permission-rules.d.ts +87 -1
  115. package/dist/core/present-plan-tool.d.ts +20 -0
  116. package/dist/core/pricing.d.ts +26 -0
  117. package/dist/core/property-harness.d.ts +86 -0
  118. package/dist/core/protocol-naming.d.ts +38 -0
  119. package/dist/core/protocol-table.d.ts +61 -0
  120. package/dist/core/push-queue.d.ts +1 -0
  121. package/dist/core/remote-env.d.ts +383 -1
  122. package/dist/core/retention-policy.d.ts +40 -0
  123. package/dist/core/retention-policy.js +21 -0
  124. package/dist/core/retention.d.ts +51 -0
  125. package/dist/core/roles.d.ts +59 -0
  126. package/dist/core/runner/active-skill-scope.d.ts +34 -0
  127. package/dist/core/runner/assemble-result.d.ts +134 -0
  128. package/dist/core/runner/compaction-call-options.d.ts +97 -1
  129. package/dist/core/runner/grounding-signal.d.ts +10 -0
  130. package/dist/core/runner/image.d.ts +17 -0
  131. package/dist/core/runner/image.js +29 -15
  132. package/dist/core/runner/memory-consolidation.d.ts +60 -0
  133. package/dist/core/runner/prepare-memory.d.ts +59 -0
  134. package/dist/core/runner/prepare-task.d.ts +1011 -2
  135. package/dist/core/runner/prepare-task.js +51 -14
  136. package/dist/core/runner/prompt-suggestions.d.ts +7 -0
  137. package/dist/core/runner/runtask.d.ts +304 -3
  138. package/dist/core/runner/runtask.js +17 -2
  139. package/dist/core/runner/session-file-state-replay.d.ts +49 -0
  140. package/dist/core/runner/session-rule-policy.d.ts +58 -0
  141. package/dist/core/runner/strict-output-schema.d.ts +18 -3
  142. package/dist/core/runner/synthetic-tools.d.ts +113 -0
  143. package/dist/core/runner/teardown-bounded.d.ts +34 -0
  144. package/dist/core/runner/tool-disclosure.d.ts +227 -0
  145. package/dist/core/runner/tool-output-projection.d.ts +6 -0
  146. package/dist/core/runner/turn-attachments.d.ts +634 -0
  147. package/dist/core/runner/usage-accounting.d.ts +32 -0
  148. package/dist/core/runtime.d.ts +9 -0
  149. package/dist/core/safe-notify.d.ts +64 -0
  150. package/dist/core/safety-axis-vocab.d.ts +23 -0
  151. package/dist/core/safety-merge-corpus.d.ts +37 -0
  152. package/dist/core/scheduler.d.ts +121 -0
  153. package/dist/core/secret-env.d.ts +32 -0
  154. package/dist/core/select-model.d.ts +15 -0
  155. package/dist/core/sensitive-path-policy.d.ts +42 -0
  156. package/dist/core/session-policy-store.d.ts +94 -0
  157. package/dist/core/session-reconcile.d.ts +80 -0
  158. package/dist/core/session-store.d.ts +85 -0
  159. package/dist/core/session.d.ts +153 -0
  160. package/dist/core/shared-memory/contract.d.ts +22 -0
  161. package/dist/core/shared-memory/normalize.d.ts +123 -2
  162. package/dist/core/shared-memory/tools.d.ts +14 -0
  163. package/dist/core/shared-memory/types.d.ts +105 -0
  164. package/dist/core/shutdown-debug.d.ts +6 -0
  165. package/dist/core/side-query.d.ts +38 -0
  166. package/dist/core/side-query.js +6 -1
  167. package/dist/core/skill-tool-specifier.d.ts +72 -0
  168. package/dist/core/skills-directory.d.ts +100 -1
  169. package/dist/core/spec-contract.d.ts +89 -0
  170. package/dist/core/store-contracts/background-agent-store-contract.d.ts +31 -0
  171. package/dist/core/store-contracts/checkpoint-store-contract.d.ts +26 -0
  172. package/dist/core/store-contracts/contract-harness.d.ts +20 -0
  173. package/dist/core/store-contracts/contract-kit-version.d.ts +27 -0
  174. package/dist/core/store-contracts/file-snapshot-store-contract.d.ts +8 -0
  175. package/dist/core/store-contracts/mailbox-store-contract.d.ts +42 -0
  176. package/dist/core/store-contracts/tool-result-store-contract.d.ts +13 -0
  177. package/dist/core/strategy-store.d.ts +37 -0
  178. package/dist/core/stub-env.d.ts +7 -0
  179. package/dist/core/surrogate-safe-slice.d.ts +35 -0
  180. package/dist/core/task-notification.d.ts +202 -0
  181. package/dist/core/task-outcome.d.ts +53 -0
  182. package/dist/core/task-registry-agent.d.ts +337 -1
  183. package/dist/core/task-registry-agent.js +2 -0
  184. package/dist/core/task-registry-monitor.d.ts +12 -0
  185. package/dist/core/task-registry-shared.d.ts +540 -0
  186. package/dist/core/task-registry.d.ts +343 -0
  187. package/dist/core/task-registry.js +13 -2
  188. package/dist/core/task-tool-shape.d.ts +44 -0
  189. package/dist/core/tighten-task-spec.d.ts +21 -0
  190. package/dist/core/tool-detach.d.ts +21 -0
  191. package/dist/core/tool-errors.d.ts +131 -0
  192. package/dist/core/tool-errors.js +4 -0
  193. package/dist/core/tool-name-aliases.d.ts +27 -0
  194. package/dist/core/tool-policy.d.ts +555 -0
  195. package/dist/core/tool-policy.js +3 -0
  196. package/dist/core/tool-result-budget.d.ts +32 -0
  197. package/dist/core/tool-result-store.d.ts +174 -1
  198. package/dist/core/tools.d.ts +45 -0
  199. package/dist/core/trace.d.ts +323 -0
  200. package/dist/core/types.d.ts +3859 -2
  201. package/dist/core/untrusted-egress.d.ts +8 -0
  202. package/dist/core/untrusted-text.d.ts +156 -0
  203. package/dist/core/usage-window-store.d.ts +95 -0
  204. package/dist/core/version.d.ts +1 -0
  205. package/dist/core/warm-resume.d.ts +17 -0
  206. package/dist/core/wiring-manifest.d.ts +169 -0
  207. package/dist/core/with-retry.d.ts +24 -0
  208. package/dist/core/workflow-journal-store.d.ts +160 -0
  209. package/dist/core/workflow-run-store-contract.d.ts +25 -0
  210. package/dist/core/workflow-run-store.d.ts +119 -0
  211. package/dist/core/workflow-run-store.js +2 -0
  212. package/dist/engine/compaction/compaction.d.ts +256 -1
  213. package/dist/engine/compaction/utils.d.ts +94 -0
  214. package/dist/engine/execution-env/kill-tree.d.ts +29 -0
  215. package/dist/engine/execution-env/node-execution-env.d.ts +94 -0
  216. package/dist/engine/harness/agent-harness.d.ts +116 -0
  217. package/dist/engine/harness/agent-harness.js +3 -14
  218. package/dist/engine/harness/messages.d.ts +15 -0
  219. package/dist/engine/harness/types.d.ts +464 -2
  220. package/dist/engine/llm/diagnostics.d.ts +4 -0
  221. package/dist/engine/llm/event-stream.d.ts +3 -0
  222. package/dist/engine/llm/index.d.ts +7 -0
  223. package/dist/engine/llm/types.d.ts +500 -3
  224. package/dist/engine/llm/validation.d.ts +3 -0
  225. package/dist/engine/loop/agent-loop.d.ts +87 -2
  226. package/dist/engine/loop/runtime-deps.d.ts +7 -0
  227. package/dist/engine/loop/types.d.ts +424 -0
  228. package/dist/engine/lsp/frame-decoder.d.ts +13 -0
  229. package/dist/engine/lsp/node-lsp-manager.d.ts +107 -0
  230. package/dist/engine/lsp/stdio-lsp-transport.d.ts +7 -0
  231. package/dist/engine/session/import-validate.d.ts +27 -0
  232. package/dist/engine/session/log-digest.d.ts +93 -0
  233. package/dist/engine/session/memory-repo.d.ts +6 -0
  234. package/dist/engine/session/memory-storage.d.ts +2 -0
  235. package/dist/engine/session/session.d.ts +75 -0
  236. package/dist/engine/session/storage-base.d.ts +8 -0
  237. package/dist/fixtures/index.d.ts +36 -0
  238. package/dist/index.d.ts +17 -2
  239. package/dist/index.js +1 -2
  240. package/dist/internal/harness-types.d.ts +6 -0
  241. package/dist/internal/harness.d.ts +11 -0
  242. package/dist/internal/llm.d.ts +6 -0
  243. package/dist/orchestration/builtin-workflows.d.ts +53 -0
  244. package/dist/orchestration/dev-vm-script-runner.d.ts +19 -0
  245. package/dist/orchestration/goal.d.ts +57 -0
  246. package/dist/orchestration/goal.js +3 -0
  247. package/dist/orchestration/run-spec.d.ts +42 -0
  248. package/dist/orchestration/run-spec.js +4 -0
  249. package/dist/orchestration/run-workflow-tool.d.ts +169 -0
  250. package/dist/orchestration/workflow-governance.d.ts +61 -0
  251. package/dist/orchestration/workflow-meta.d.ts +28 -0
  252. package/dist/orchestration/workflow-observe.d.ts +60 -0
  253. package/dist/orchestration/workflow-primitives.d.ts +23 -1
  254. package/dist/orchestration/workflow-sandbox-conformance.d.ts +38 -0
  255. package/dist/orchestration/workflow-script-runner.d.ts +88 -0
  256. package/dist/orchestration/workflow-script-store.d.ts +98 -0
  257. package/dist/orchestration/workflow-size-guideline.d.ts +67 -0
  258. package/dist/orchestration/workflow-types.d.ts +169 -2
  259. package/dist/orchestration/workflow.d.ts +358 -0
  260. package/dist/orchestration/workflow.js +13 -2
  261. package/dist/prompt-assembly/artifact-store.d.ts +33 -0
  262. package/dist/prompt-assembly/artifact.d.ts +25 -0
  263. package/dist/prompt-assembly/assemble.d.ts +20 -0
  264. package/dist/prompt-assembly/composer.d.ts +29 -0
  265. package/dist/prompt-assembly/epoch.d.ts +55 -1
  266. package/dist/prompt-assembly/event-registry.d.ts +35 -0
  267. package/dist/prompt-assembly/explain.d.ts +12 -0
  268. package/dist/prompt-assembly/tool-catalog.d.ts +38 -0
  269. package/dist/prompt-assembly/turn-snapshot.d.ts +40 -0
  270. package/dist/prompt-assembly/types.d.ts +115 -0
  271. package/dist/prompts/coordinator.d.ts +27 -0
  272. package/dist/prompts/default.d.ts +539 -0
  273. package/dist/prompts/simple-sections.d.ts +45 -0
  274. package/dist/prompts/supervisor.d.ts +66 -0
  275. package/dist/scenarios/env.d.ts +28 -0
  276. package/dist/scenarios/full-body.d.ts +50 -0
  277. package/dist/scenarios/scenario-registry.d.ts +60 -0
  278. package/dist/scenarios/teacher-quickstart.d.ts +27 -0
  279. package/dist/server/http.d.ts +17 -0
  280. package/dist/stores/cc/lockfile.d.ts +6 -0
  281. package/dist/stores/cc/mailbox-store.d.ts +8 -0
  282. package/dist/stores/cc/roster-adapter.d.ts +4 -0
  283. package/dist/stores/cc/sidecar-transcript.d.ts +66 -0
  284. package/dist/stores/file/background-agent-store.d.ts +24 -0
  285. package/dist/stores/file/background-agent-store.js +2 -1
  286. package/dist/stores/file/checkpoint-store.d.ts +38 -0
  287. package/dist/stores/file/file-snapshot-store.d.ts +25 -0
  288. package/dist/stores/file/fs-atomic.d.ts +155 -0
  289. package/dist/stores/file/index.d.ts +89 -0
  290. package/dist/stores/file/mailbox-store.d.ts +36 -0
  291. package/dist/stores/file/mailbox-store.js +2 -0
  292. package/dist/stores/file/memory-store.d.ts +82 -0
  293. package/dist/stores/file/permission-rule-store.d.ts +79 -0
  294. package/dist/stores/file/session-policy-store.d.ts +28 -0
  295. package/dist/stores/file/session-store.d.ts +40 -0
  296. package/dist/stores/file/shared-ledger.d.ts +83 -0
  297. package/dist/stores/file/tool-result-store.d.ts +11 -0
  298. package/dist/stores/file/usage-window-store.d.ts +18 -0
  299. package/dist/stores/file/workflow-journal-store.d.ts +100 -0
  300. package/dist/stores/file/workflow-run-store.d.ts +11 -0
  301. package/dist/stores/file/workflow-run-store.js +2 -0
  302. package/dist/tools/fs/bash-readonly-classifier.d.ts +282 -0
  303. package/dist/tools/fs/encoding.d.ts +60 -0
  304. package/dist/tools/fs/fs-bash.d.ts +133 -0
  305. package/dist/tools/fs/fs-pdf.d.ts +28 -0
  306. package/dist/tools/fs/fs-search-tools.d.ts +5 -0
  307. package/dist/tools/fs/fs-shared.d.ts +360 -0
  308. package/dist/tools/fs/fs-write.d.ts +16 -0
  309. package/dist/tools/fs/gh-rate-limit.d.ts +22 -0
  310. package/dist/tools/fs/index.d.ts +79 -0
  311. package/dist/tools/fs/notebook.d.ts +56 -0
  312. package/dist/tools/fs/pdf.d.ts +70 -0
  313. package/dist/tools/fs/pdf.js +8 -2
  314. package/dist/tools/fs/repo-map.d.ts +10 -0
  315. package/dist/tools/fs/safety.d.ts +376 -0
  316. package/dist/tools/fs/search.d.ts +131 -0
  317. package/dist/tools/loop-tick.d.ts +24 -0
  318. package/dist/tools/monitor.d.ts +55 -0
  319. package/dist/tools/scheduler-tools.d.ts +51 -0
  320. package/dist/tools/sql-adapters.d.ts +18 -0
  321. package/dist/tools/sql.d.ts +25 -0
  322. package/dist/tools/task-list.d.ts +77 -0
  323. package/dist/tools/todo.d.ts +8 -0
  324. package/dist/tools/web.d.ts +184 -0
  325. package/dist/tools/web.js +32 -5
  326. package/dist/tools/worktree.d.ts +81 -0
  327. package/package.json +2 -2
  328. package/dist/tools/gitea-issue.d.ts +0 -13
  329. package/dist/tools/gitea-issue.js +0 -75
@@ -1,15 +1,29 @@
1
1
  import type { TaskResult, TaskStatus, ToolActivity } from "../core/types.js";
2
2
  export type WorkflowRunStatus = "running" | "completed" | "failed";
3
+ /** Status of one phase / agent-run within a workflow. */
3
4
  export type WorkflowItemStatus = "running" | "completed" | "failed";
4
5
  export interface WorkflowPhase {
5
6
  title: string;
7
+ /** F7/B7 (CC pretty.js:446478): a phase PRE-REGISTERED from `meta.phases` starts as `"pending"` — the plan
8
+ * is visible before execution. The first `phase()` call with the SAME title adopts it (→ running). A phase
9
+ * still pending at the run's terminal was planned but never reached (left pending, honestly). */
6
10
  status: WorkflowItemStatus | "pending";
11
+ /** meta.phases[].detail, when pre-registered. */
7
12
  detail?: string;
13
+ /** meta.phases[].model (CC card :448042) — display-only phase model note. */
8
14
  model?: string;
15
+ /** Number of agents grouped under this phase whose record ended `"failed"` (every non-`completed`
16
+ * terminal — failed/blocked/timeout — folds to that record status). Stamped when the phase settles,
17
+ * only when > 0 (absent = no failures). ADDITIVE observation field: a phase whose BODY returned
18
+ * normally stays `"completed"` even when agents inside it failed — the script owns control flow —
19
+ * but the partial failure must be visible on the phase box, not only per agent row. */
9
20
  agentFailures?: number;
21
+ /** For a pre-registered phase this is the ADOPTION time (0 while pending — it hasn't started). */
10
22
  startedAt: number;
11
23
  endedAt?: number;
12
24
  }
25
+ /** design/97 CORE-3: one nested `ctx.workflow` sub-group. The tree is reconstructed from `parentGroupId`
26
+ * (undefined = a child of the root) + the agents/phases that carry this `groupId`. */
13
27
  export interface WorkflowGroup {
14
28
  groupId: string;
15
29
  parentGroupId?: string;
@@ -18,33 +32,80 @@ export interface WorkflowGroup {
18
32
  endedAt?: number;
19
33
  }
20
34
  export interface WorkflowAgentRun {
35
+ /** Display label (caller-supplied via opts.label, else an auto `agent-N`). */
21
36
  label: string;
37
+ /** design/97 CORE-1: the STABLE deterministic identity of this `ctx.agent` call ({@link workflowAgentCallKey}
38
+ * = `ordinal:specIdentityHash`). The resume journal (CORE-7) keys a cached result on it. */
22
39
  callKey: string;
40
+ /** design/97 CORE-1: the nesting GROUP this agent ran under — `undefined` = top-level (root); a nested
41
+ * `ctx.workflow` (CORE-3) sets a sub-group id so the observe/UI can render the agent tree. */
23
42
  groupId?: string;
43
+ /** The phase this agent ran under, if any (opts.phase, else the enclosing `phase()` title). */
24
44
  phase?: string;
45
+ /** design/97 CORE-8 (①): the model display label (`spec.model` id/name) — for a CC-style "Opus 4.8" per-agent row. */
25
46
  model?: string;
47
+ /** design/97 CORE-4 (#5 observability): what the worker was ASKED — its objective (+ systemPrompt), redacted
48
+ * + size-bounded. NOT fenced at rest; a consumer feeding it to an LLM must fence (untrustedEgressForHuman). */
26
49
  prompt?: string;
50
+ /** design/97 CORE-4 (#5 observability): the worker's final OUTPUT (structuredOutput or result text), redacted
51
+ * + size-bounded. Same fencing caveat as `prompt`. Set on a completed/returned run (absent on a thrown one). */
27
52
  output?: string;
53
+ /** design/97 CORE-8 (②): total tool calls the worker made (from `TaskResult.stats.toolCalls`). */
28
54
  toolCalls?: number;
55
+ /** design/97 CORE-8 (③): the worker's tool-call ACTIVITY — bounded to the LAST {@link MAX_ACTIVITY} beats (a
56
+ * CC-style "last N of M tool calls"; M is `toolCalls`). Structural only (name/phase/ids), no args/output. */
29
57
  activity?: ToolActivity[];
30
58
  status: WorkflowItemStatus;
59
+ /** [1238](B) — the failed task's machine code + bounded human message, surfaced ON THE RECORD
60
+ * (runs.jsonl / monitor rows / agent_end) so a dead agent is diagnosable without re-running.
61
+ * Previously only the script's return value carried them and every display face showed "". */
31
62
  errorCode?: string;
32
63
  errorMessage?: string;
64
+ /** The underlying task's terminal {@link TaskStatus} (a non-`completed` status maps to `failed` above). */
33
65
  taskStatus?: TaskStatus;
66
+ /** design/99 MF-W (design-review DoR ⑥): when this agent was ENQUEUED (the `ctx.agent`/`ctx.agentStream` call,
67
+ * before it waited on the concurrency semaphore). Always set. A record with `queuedAt` set but `startedAt`
68
+ * ABSENT is QUEUED (waiting for a slot) — `deriveAgentDisplayStatus` projects that to `"queued"`. */
34
69
  queuedAt: number;
70
+ /** When the agent ACTUALLY started running — set AFTER it acquired a concurrency slot (post-queue). ABSENT
71
+ * while queued, or if it was aborted/the-run-finalized before it ever ran. So `durationMs` (`endedAt -
72
+ * startedAt`) excludes the queue wait (the DoR fix: a queued agent no longer reports a wrong running duration). */
35
73
  startedAt?: number;
36
74
  endedAt?: number;
75
+ /** This agent's OWN (root) usage — nested/delegated usage rolls into the run's {@link WorkflowRunStats.nested}. */
37
76
  stats?: {
38
77
  tokens: number;
39
78
  turns: number;
40
79
  costMicroUsd?: number;
41
80
  };
81
+ /** design/97 CORE-7: set when this agent's result was REPLAYED from a resume journal (cached, no live runTask)
82
+ * rather than freshly run. Its stats count toward `run.stats` (total work) but not `ctx.budget.spent()`. */
42
83
  replayed?: boolean;
84
+ /** F5/B4: total attempts this call made (set only when > 1 — stall/throttle retries happened). The record's
85
+ * `stats` are the FINAL attempt's; burned retry spend rolls into `run.stats`/budget (CC semantics). */
43
86
  attempts?: number;
87
+ /** F5/B4: why the LAST retry happened — "stalled" (progress watchdog) or "throttled" (degraded response). */
44
88
  lastAttemptReason?: string;
89
+ /** design/114 — the session id of this agent's run (= its `TaskResult.sessionId`). Surfaces the conversation
90
+ * handle to the observation layer so an external initiator can WARM-resume a failed/timed-out agent
91
+ * (`fork(sessionId)→runTask`, or `runTask({sessionId})`) instead of a fresh re-run. An opaque id (not
92
+ * content) → scope-gated via `getWorkflowRun`, no redaction needed. Absent for a stub run that minted none. */
45
93
  sessionId?: string;
94
+ /** RB-393① (黑板 [2107]②/[2113]) — the WORKTREE directory this agent ran in, present ONLY for an
95
+ * `isolation: "worktree"` agent whose worktree the engine actually minted (reported by the runner's
96
+ * workspace-observation seam and folded on while the agent is still RUNNING, so an interrupted run's
97
+ * recovery path has the coordinate instead of enumerating the worktrees directory and guessing). ABSENCE
98
+ * means the agent ran in the SHARED working tree — never "unknown": the shared root is deliberately not
99
+ * written here, so a consumer acting on this path (diff / merge / remove, the userland half of the
100
+ * isolate-only contract) can never be handed a tree it must not touch. A host path, not content → same
101
+ * scope-gated, unredacted posture as {@link sessionId}. */
46
102
  worktreeDir?: string;
47
103
  }
104
+ /**
105
+ * Cumulative workflow usage. `own` (top-level) and `nested` (each agent's delegated sub-agents) are kept
106
+ * SEPARATE — never folded — mirroring `TaskResult.stats` (R-5): a consumer adds them. Total spend =
107
+ * `tokens + nested.tokens`.
108
+ */
48
109
  export interface WorkflowRunStats {
49
110
  tokens: number;
50
111
  turns: number;
@@ -59,25 +120,72 @@ export interface WorkflowRunStats {
59
120
  export interface WorkflowRun {
60
121
  id: string;
61
122
  scope: string;
123
+ /** design/99 MF-W (workflow monitor header): the workflow's display name + one-line description, from the
124
+ * script's `export const meta = {...}` (the run_workflow tool passes them in). Absent for a direct
125
+ * `runWorkflow` call that supplies no name. */
62
126
  name?: string;
63
127
  description?: string;
128
+ /** design/114 #3 (service) — the HOST task id that started this workflow (the `RunWorkflow` tool's source
129
+ * task). Lets a crash-recovered consumer rebuilding from `getWorkflowRun` re-associate the run with its
130
+ * initiator: the live notify path carries it, but the recovery path can't otherwise recover it (it rebuilds
131
+ * from the persisted `WorkflowRun`, which until now dropped it). Absent for a direct `runWorkflow` call. */
64
132
  sourceTaskId?: string;
133
+ /** The ORIGINATING session id, recorded like {@link sourceTaskId} so crash-recovery
134
+ * rebuilds a completion payload symmetric with the live notify (which carries it since 1.208). */
65
135
  originatingSessionId?: string;
136
+ /** design/140 §6 1a — the MERGED effective args the script actually received (call-time args over the
137
+ * registration's defaultArgs), snapshotted at RESOLVE time (parse-time discipline, design/140 §2).
138
+ * OBSERVATION-ONLY (a /workflows viewer / recovery consumer reads what the run got) — never a gate input,
139
+ * never re-read by the engine; a resume's identity is carried by the journal callKeys, not this field.
140
+ * Absent for a direct `runWorkflow` call or an argless invocation. */
66
141
  effectiveArgs?: unknown;
67
142
  status: WorkflowRunStatus;
143
+ /** Number of agent-runs that ended `"failed"` (failed/blocked/timeout terminals) across the whole run.
144
+ * Stamped at the run's terminal, only when > 0 (absent = every agent completed). ADDITIVE observation
145
+ * field: a run whose script body returned normally is still `status: "completed"` even when agents
146
+ * inside it failed (the script's return value is the source of truth) — this surfaces the
147
+ * "completed, with failures" outcome WITHOUT extending {@link WorkflowRunStatus}, which is a wire
148
+ * contract (store status filters, terminal checks like `isTerminalWorkflowStatus`, monitor rows all
149
+ * switch on the closed enum — a new enum value would break them; an optional field cannot). */
68
150
  agentFailures?: number;
69
151
  phases: WorkflowPhase[];
70
152
  agents: WorkflowAgentRun[];
153
+ /** design/97 CORE-3: nested `ctx.workflow` sub-groups (the persisted group tree). Empty when the script
154
+ * used no nesting. Agents/phases reference a group via their `groupId`. */
71
155
  groups: WorkflowGroup[];
72
156
  stats: WorkflowRunStats;
73
157
  startedAt: number;
74
158
  endedAt?: number;
75
159
  createdAt: number;
160
+ /** Optimistic-concurrency revision for the store (S1b); unset for a pure in-memory run. */
76
161
  rev?: number;
162
+ /** Set when `status === "failed"`: the error the script threw. */
77
163
  error?: string;
164
+ /** The script's RETURN VALUE, bounded + redacted at completion time (same egress
165
+ * discipline as the notifier `result`), so a terminal `TaskOutput` poll can hand the
166
+ * model the result instead of sending it in poll circles. Absent on failed runs and runs recorded by
167
+ * older engine versions. */
78
168
  result?: string;
169
+ /** NH-1: the FULL return value (redacted, capped at {@link WORKFLOW_RESULT_FULL_MAX}), set ONLY
170
+ * when `result` above was truncated by its display bound. Terminal poll replies inline this instead of the
171
+ * truncated `result`, so the generic large-tool-result offload (design/30) persists it under a REAL
172
+ * `read_tool_result` ref — previously the `…[+N chars]` tail dead-ended (no retrieval path; models tried
173
+ * the runId as a ref and hit the store-miss message). Display/notify surfaces keep using `result`. */
79
174
  resultFull?: string;
175
+ /** P1-3(黑板 [1920]/[1921]/[1924]/[1925]) — the cross-channel completion correlation id, minted
176
+ * fill-once at this run's terminal transition (see {@link "../core/task-registry.js".UnifiedTaskOutput.completionId}
177
+ * for the shared cross-lane contract). Persisted alongside `status`/`endedAt` so a store round-trip
178
+ * (restart / crash recovery) replays the exact same id — there is no second mint point downstream of
179
+ * this field ever being set. Absent while `status === "running"`, or on a run recorded by an older
180
+ * engine version. */
80
181
  completionId?: string;
182
+ /** RB-243 ([1937]): what this run's `resumeFromRunId` actually yielded — ADDITIVE observation (same
183
+ * contract as {@link agentFailures}: never a gate input; absent on non-resume runs, on runs recorded by
184
+ * older engines, and on a column-mapped store that doesn't project it). Previously a resume whose journal
185
+ * loaded ZERO entries (unknown/pruned runId, cross-scope, unreadable record) re-ran everything live with
186
+ * no trace that nothing replayed. `fromRunId` is charset-clamped (the raw id is LLM-controlled).
187
+ * `divergedAtOrdinal`/`divergedReason` record the FIRST replay stop only; under `parallel` the ordinal is
188
+ * best-effort. */
81
189
  resume?: {
82
190
  fromRunId: string;
83
191
  journalEntries: number;
@@ -85,6 +193,9 @@ export interface WorkflowRun {
85
193
  divergedAtOrdinal?: number;
86
194
  divergedReason?: string;
87
195
  };
196
+ /** RB-243 ([1937]): how many agent results were NOT journaled because they exceeded the per-entry size
197
+ * cap ({@link MAX_JOURNAL_RESULT_BYTES}) — each skip also logs and journals a tombstone. Additive
198
+ * observation; absent when 0. */
88
199
  journalSkips?: number;
89
200
  }
90
201
  export type WorkflowEvent = {
@@ -164,22 +275,58 @@ export type WorkflowEvent = {
164
275
  agentFailures?: number;
165
276
  ts: number;
166
277
  };
278
+ /** Thrown by `ctx.agent` once the workflow's cumulative token spend reaches the budget (design/96 G#4: a
279
+ * hard ceiling, typed error in v1; durable suspend is left to a future slice). */
167
280
  export declare class WorkflowBudgetExceededError extends Error {
168
281
  readonly spent: number;
169
282
  readonly total: number;
170
283
  readonly code = "workflow.budget_exceeded";
171
284
  constructor(spent: number, total: number);
172
285
  }
286
+ /**
287
+ * Thrown by `runWorkflow`/`startWorkflow` when a workflow is started INSIDE another workflow — nesting is
288
+ * capped at ONE level (design/97 §H.1, the S8 prerequisite). A workflow's agent (a `runner.runTask` child)
289
+ * cannot itself start a workflow: the LLM-facing `run_workflow` tool hits this guard, and so does a
290
+ * trusted-dev nested `runWorkflow(...)` call. The depth is read from the TRUSTED
291
+ * {@link WorkflowInternals.workflowDepth} first (the cross-process channel — a worker/script cannot forge it,
292
+ * it is not a `TaskSpec` field) then the in-process {@link workflowDepthStore} (AsyncLocalStorage), so neither
293
+ * a spec field nor a tool param can defeat it (design/98 §0.1 BLOCKER3).
294
+ */
173
295
  export declare class WorkflowNestingError extends Error {
174
296
  readonly code = "workflow.nesting";
175
297
  constructor();
176
298
  }
299
+ /**
300
+ * Thrown by `ctx.agent(spec, { schema })` (design/98 §0.2, strict mode) when the sub-agent **completed but
301
+ * produced no `structuredOutput`** — i.e. the model answered in PROSE, which core's `outputSchema` path
302
+ * permits by default (types.ts: "may still answer in prose"). A workflow script that asked for a structured
303
+ * result must not silently receive `undefined`; it fails loud here instead. A task that ended NON-`completed`
304
+ * (failed / blocked / timeout) is returned as-is (the script checks `result.status`) and never turned into
305
+ * this error — that path already carries its own signal.
306
+ */
177
307
  export declare class WorkflowAgentSchemaError extends Error {
178
308
  readonly label: string;
309
+ /** The agent's completed-but-prose TaskResult (when available). The prose was paid for and may still be
310
+ * useful as a degraded fallback — a caller that catches this error can consume `result.result` instead
311
+ * of losing the output entirely. The throw itself stays the strict-mode signal. */
179
312
  readonly result?: TaskResult | undefined;
180
313
  readonly code = "workflow.agent_schema";
181
- constructor(label: string, result?: TaskResult | undefined);
314
+ constructor(label: string,
315
+ /** The agent's completed-but-prose TaskResult (when available). The prose was paid for and may still be
316
+ * useful as a degraded fallback — a caller that catches this error can consume `result.result` instead
317
+ * of losing the output entirely. The throw itself stays the strict-mode signal. */
318
+ result?: TaskResult | undefined);
182
319
  }
320
+ /**
321
+ * Thrown by `ctx.agent` when the progress watchdog aborted EVERY attempt (stall-retry exhaustion). The throw
322
+ * is the terminal contract (stall exhaustion throws; `null` is not the stall terminal), but the LAST attempt
323
+ * may still have produced a real `TaskResult` — partial text, burned spend, and the warm-resume `sessionId`.
324
+ * That result rides on the error as {@link lastResult} so a caller can salvage the partial output or resume
325
+ * the session instead of losing paid-for work; the engine also backfills the run record and journal entry
326
+ * from it. `lastResult` is absent when the aborted attempt rejected without returning a result. Its `status`
327
+ * is never `"completed"` (a completed attempt ends the retry loop), so a journaled entry is never replayed
328
+ * on a resume — the call retries live.
329
+ */
183
330
  export declare class WorkflowAgentStalledError extends Error {
184
331
  readonly attempts: number;
185
332
  readonly stallMs: number;
@@ -187,14 +334,34 @@ export declare class WorkflowAgentStalledError extends Error {
187
334
  readonly code = "workflow.agent_stalled";
188
335
  constructor(attempts: number, stallMs: number, lastResult?: TaskResult | undefined);
189
336
  }
337
+ /** Machine code stamped on the agent record (and its journal entry / `agent_end` frame) when the spawn
338
+ * review refused to start a child. Deliberately the SAME string the delegation-tool lane returns for a
339
+ * refused sub-agent, so one code covers "a child the classifier did not let start", whichever lane. */
190
340
  export declare const WORKFLOW_SPAWN_BLOCKED_ERROR_CODE = "autoMode.spawn_blocked";
341
+ /**
342
+ * Thrown by `ctx.agent` / `ctx.agentStream` when the pre-spawn review refused the child — either the
343
+ * auto-mode classifier returned a `block` verdict over the finalized objective/toolset/output-schema, or the
344
+ * child's requested output schema could not be presented to the classifier at all (non-serializable, or
345
+ * larger than the review cap: an unclassifiable schema is refused rather than waved through).
346
+ *
347
+ * The child never starts. The refusal is NOT silent: the engine records the agent as `failed` with
348
+ * {@link WORKFLOW_SPAWN_BLOCKED_ERROR_CODE}, emits `agent_end`, and (on the `ctx.agent` lane) journals a
349
+ * synthetic failed entry at the call's true ordinal, so a resume retries the call live rather than replaying
350
+ * a refusal. `category` is the classifier's matched rule name (`""` for the schema-cap refusal).
351
+ */
191
352
  export declare class WorkflowAgentBlockedError extends Error {
192
353
  readonly label: string;
193
354
  readonly category: string;
355
+ /** Human-readable cause, already bounded + redacted by the engine (classifier text is model output). */
194
356
  readonly reason: string;
195
357
  readonly code = "workflow.agent_blocked";
196
- constructor(label: string, category: string, reason: string);
358
+ constructor(label: string, category: string,
359
+ /** Human-readable cause, already bounded + redacted by the engine (classifier text is model output). */
360
+ reason: string);
197
361
  }
362
+ /** design/98 §D.6 hard cap: thrown by `ctx.agent` once the workflow has spawned `max` agents (a runaway
363
+ * LLM-authored script is bounded, not trusted — budget alone is checked only pre-spawn, so a concurrent
364
+ * fan-out can overshoot it; this counts cumulative spawns). */
198
365
  export declare class WorkflowMaxAgentsError extends Error {
199
366
  readonly max: number;
200
367
  readonly code = "workflow.max_agents";