@timmyjl12/pi-subagents 0.0.0-stage → 0.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 (244) hide show
  1. package/CHANGELOG.md +862 -0
  2. package/CONTRIBUTING.md +72 -0
  3. package/LICENSE +21 -0
  4. package/README.md +1125 -3
  5. package/SECURITY.md +97 -0
  6. package/dist/abortable.d.ts +12 -0
  7. package/dist/abortable.js +42 -0
  8. package/dist/active-agents-prompt.d.ts +40 -0
  9. package/dist/active-agents-prompt.js +98 -0
  10. package/dist/advisor-status.d.ts +16 -0
  11. package/dist/advisor-status.js +74 -0
  12. package/dist/agent-color.d.ts +35 -0
  13. package/dist/agent-color.js +131 -0
  14. package/dist/agent-file-toggle.d.ts +125 -0
  15. package/dist/agent-file-toggle.js +264 -0
  16. package/dist/agent-manager.d.ts +872 -0
  17. package/dist/agent-manager.js +2910 -0
  18. package/dist/agent-runner.d.ts +358 -0
  19. package/dist/agent-runner.js +1219 -0
  20. package/dist/agent-types.d.ts +142 -0
  21. package/dist/agent-types.js +315 -0
  22. package/dist/awaited-result.d.ts +37 -0
  23. package/dist/awaited-result.js +150 -0
  24. package/dist/child-context.d.ts +15 -0
  25. package/dist/child-context.js +181 -0
  26. package/dist/child-session-shutdown.d.ts +21 -0
  27. package/dist/child-session-shutdown.js +97 -0
  28. package/dist/cleanup-plans.d.ts +10 -0
  29. package/dist/cleanup-plans.js +112 -0
  30. package/dist/context.d.ts +12 -0
  31. package/dist/context.js +56 -0
  32. package/dist/cross-extension-rpc.d.ts +73 -0
  33. package/dist/cross-extension-rpc.js +192 -0
  34. package/dist/custom-agents.d.ts +79 -0
  35. package/dist/custom-agents.js +583 -0
  36. package/dist/default-agents.d.ts +7 -0
  37. package/dist/default-agents.js +125 -0
  38. package/dist/enabled-models.d.ts +49 -0
  39. package/dist/enabled-models.js +145 -0
  40. package/dist/env.d.ts +6 -0
  41. package/dist/env.js +28 -0
  42. package/dist/error-log.d.ts +64 -0
  43. package/dist/error-log.js +176 -0
  44. package/dist/force-main-model.d.ts +21 -0
  45. package/dist/force-main-model.js +28 -0
  46. package/dist/goal-bridge.d.ts +155 -0
  47. package/dist/goal-bridge.js +305 -0
  48. package/dist/group-join.d.ts +36 -0
  49. package/dist/group-join.js +161 -0
  50. package/dist/index.d.ts +52 -0
  51. package/dist/index.js +6390 -0
  52. package/dist/invocation-config.d.ts +164 -0
  53. package/dist/invocation-config.js +158 -0
  54. package/dist/memory.d.ts +53 -0
  55. package/dist/memory.js +165 -0
  56. package/dist/mention-clone.d.ts +87 -0
  57. package/dist/mention-clone.js +178 -0
  58. package/dist/mention.d.ts +81 -0
  59. package/dist/mention.js +131 -0
  60. package/dist/model-resolver.d.ts +36 -0
  61. package/dist/model-resolver.js +95 -0
  62. package/dist/model-scope.d.ts +49 -0
  63. package/dist/model-scope.js +48 -0
  64. package/dist/nested-tools.d.ts +76 -0
  65. package/dist/nested-tools.js +393 -0
  66. package/dist/output-diagnostics.d.ts +11 -0
  67. package/dist/output-diagnostics.js +64 -0
  68. package/dist/output-file.d.ts +64 -0
  69. package/dist/output-file.js +351 -0
  70. package/dist/prompts.d.ts +61 -0
  71. package/dist/prompts.js +94 -0
  72. package/dist/recovery.d.ts +56 -0
  73. package/dist/recovery.js +341 -0
  74. package/dist/report-cleanup.d.ts +204 -0
  75. package/dist/report-cleanup.js +1632 -0
  76. package/dist/report-store.d.ts +738 -0
  77. package/dist/report-store.js +3612 -0
  78. package/dist/schedule-store.d.ts +52 -0
  79. package/dist/schedule-store.js +240 -0
  80. package/dist/schedule.d.ts +121 -0
  81. package/dist/schedule.js +420 -0
  82. package/dist/settings.d.ts +388 -0
  83. package/dist/settings.js +268 -0
  84. package/dist/skill-loader.d.ts +24 -0
  85. package/dist/skill-loader.js +93 -0
  86. package/dist/standalone-fallback.d.ts +30 -0
  87. package/dist/standalone-fallback.js +239 -0
  88. package/dist/status-note.d.ts +61 -0
  89. package/dist/status-note.js +85 -0
  90. package/dist/structured-output.d.ts +61 -0
  91. package/dist/structured-output.js +112 -0
  92. package/dist/terminal-progress.d.ts +115 -0
  93. package/dist/terminal-progress.js +206 -0
  94. package/dist/types.d.ts +411 -0
  95. package/dist/types.js +5 -0
  96. package/dist/ui/agent-mention.d.ts +82 -0
  97. package/dist/ui/agent-mention.js +187 -0
  98. package/dist/ui/agent-widget.d.ts +304 -0
  99. package/dist/ui/agent-widget.js +770 -0
  100. package/dist/ui/cleanup-preview.d.ts +59 -0
  101. package/dist/ui/cleanup-preview.js +466 -0
  102. package/dist/ui/conversation-viewer.d.ts +105 -0
  103. package/dist/ui/conversation-viewer.js +544 -0
  104. package/dist/ui/fleet-list.d.ts +183 -0
  105. package/dist/ui/fleet-list.js +494 -0
  106. package/dist/ui/fleet-overlay.d.ts +203 -0
  107. package/dist/ui/fleet-overlay.js +887 -0
  108. package/dist/ui/hub-feed.d.ts +52 -0
  109. package/dist/ui/hub-feed.js +148 -0
  110. package/dist/ui/native-transcript.d.ts +33 -0
  111. package/dist/ui/native-transcript.js +234 -0
  112. package/dist/ui/schedule-menu.d.ts +16 -0
  113. package/dist/ui/schedule-menu.js +94 -0
  114. package/dist/ui/select-item.d.ts +27 -0
  115. package/dist/ui/select-item.js +34 -0
  116. package/dist/ui/tool-progress.d.ts +22 -0
  117. package/dist/ui/tool-progress.js +56 -0
  118. package/dist/ui/viewer-keys.d.ts +20 -0
  119. package/dist/ui/viewer-keys.js +17 -0
  120. package/dist/ui/workflow-card.d.ts +175 -0
  121. package/dist/ui/workflow-card.js +332 -0
  122. package/dist/ui/workflow-dialog.d.ts +305 -0
  123. package/dist/ui/workflow-dialog.js +848 -0
  124. package/dist/ui/workflow-menu.d.ts +60 -0
  125. package/dist/ui/workflow-menu.js +147 -0
  126. package/dist/usage.d.ts +147 -0
  127. package/dist/usage.js +147 -0
  128. package/dist/workflow/collisions.d.ts +95 -0
  129. package/dist/workflow/collisions.js +88 -0
  130. package/dist/workflow/entry.d.ts +32 -0
  131. package/dist/workflow/entry.js +29 -0
  132. package/dist/workflow/host.d.ts +65 -0
  133. package/dist/workflow/host.js +477 -0
  134. package/dist/workflow/journal.d.ts +113 -0
  135. package/dist/workflow/journal.js +177 -0
  136. package/dist/workflow/json-schema.d.ts +51 -0
  137. package/dist/workflow/json-schema.js +111 -0
  138. package/dist/workflow/meta.d.ts +67 -0
  139. package/dist/workflow/meta.js +317 -0
  140. package/dist/workflow/progress.d.ts +224 -0
  141. package/dist/workflow/progress.js +361 -0
  142. package/dist/workflow/runtime.d.ts +373 -0
  143. package/dist/workflow/runtime.js +919 -0
  144. package/dist/workflow/saved.d.ts +90 -0
  145. package/dist/workflow/saved.js +203 -0
  146. package/dist/workflow/task.d.ts +145 -0
  147. package/dist/workflow/task.js +213 -0
  148. package/dist/workflow/tool-description.d.ts +43 -0
  149. package/dist/workflow/tool-description.js +204 -0
  150. package/dist/workflow/worker-source.d.ts +47 -0
  151. package/dist/workflow/worker-source.js +778 -0
  152. package/dist/worktree.d.ts +52 -0
  153. package/dist/worktree.js +164 -0
  154. package/dist/xml.d.ts +10 -0
  155. package/dist/xml.js +12 -0
  156. package/docs/DEVELOPMENT.md +40 -0
  157. package/docs/artifacts.md +93 -0
  158. package/docs/recovery.md +62 -0
  159. package/docs/rpc.md +252 -0
  160. package/docs/runtime-performance.md +53 -0
  161. package/docs/workflows.md +467 -0
  162. package/examples/agent-tool-description.md +43 -0
  163. package/examples/workflows/compose.js +51 -0
  164. package/examples/workflows/fan-out-audit.js +47 -0
  165. package/examples/workflows/gated-fix.js +60 -0
  166. package/examples/workflows/lib/count-child.js +27 -0
  167. package/examples/workflows/review-panel.js +66 -0
  168. package/examples/workflows/structured-findings.js +78 -0
  169. package/package.json +75 -6
  170. package/src/abortable.ts +43 -0
  171. package/src/active-agents-prompt.ts +115 -0
  172. package/src/advisor-status.ts +74 -0
  173. package/src/agent-color.ts +169 -0
  174. package/src/agent-file-toggle.ts +273 -0
  175. package/src/agent-manager.ts +3312 -0
  176. package/src/agent-runner.ts +1500 -0
  177. package/src/agent-types.ts +390 -0
  178. package/src/awaited-result.ts +187 -0
  179. package/src/child-context.ts +173 -0
  180. package/src/child-session-shutdown.ts +114 -0
  181. package/src/cleanup-plans.ts +112 -0
  182. package/src/context.ts +58 -0
  183. package/src/cross-extension-rpc.ts +257 -0
  184. package/src/custom-agents.ts +689 -0
  185. package/src/default-agents.ts +129 -0
  186. package/src/enabled-models.ts +180 -0
  187. package/src/env.ts +33 -0
  188. package/src/error-log.ts +202 -0
  189. package/src/force-main-model.ts +29 -0
  190. package/src/goal-bridge.ts +468 -0
  191. package/src/group-join.ts +188 -0
  192. package/src/index.ts +6856 -0
  193. package/src/invocation-config.ts +276 -0
  194. package/src/memory.ts +179 -0
  195. package/src/mention-clone.ts +221 -0
  196. package/src/mention.ts +141 -0
  197. package/src/model-resolver.ts +118 -0
  198. package/src/model-scope.ts +70 -0
  199. package/src/nested-tools.ts +553 -0
  200. package/src/output-diagnostics.ts +68 -0
  201. package/src/output-file.ts +380 -0
  202. package/src/prompts.ts +151 -0
  203. package/src/recovery.ts +320 -0
  204. package/src/report-cleanup.ts +2044 -0
  205. package/src/report-store.ts +4130 -0
  206. package/src/schedule-store.ts +244 -0
  207. package/src/schedule.ts +450 -0
  208. package/src/settings.ts +632 -0
  209. package/src/skill-loader.ts +102 -0
  210. package/src/standalone-fallback.ts +195 -0
  211. package/src/status-note.ts +90 -0
  212. package/src/structured-output.ts +130 -0
  213. package/src/terminal-progress.ts +215 -0
  214. package/src/types.ts +424 -0
  215. package/src/ui/agent-mention.ts +216 -0
  216. package/src/ui/agent-widget.ts +866 -0
  217. package/src/ui/cleanup-preview.ts +518 -0
  218. package/src/ui/conversation-viewer.ts +527 -0
  219. package/src/ui/fleet-list.ts +563 -0
  220. package/src/ui/fleet-overlay.ts +1048 -0
  221. package/src/ui/hub-feed.ts +179 -0
  222. package/src/ui/native-transcript.ts +224 -0
  223. package/src/ui/schedule-menu.ts +105 -0
  224. package/src/ui/select-item.ts +45 -0
  225. package/src/ui/tool-progress.ts +67 -0
  226. package/src/ui/viewer-keys.ts +39 -0
  227. package/src/ui/workflow-card.ts +470 -0
  228. package/src/ui/workflow-dialog.ts +1119 -0
  229. package/src/ui/workflow-menu.ts +193 -0
  230. package/src/usage.ts +217 -0
  231. package/src/workflow/collisions.ts +123 -0
  232. package/src/workflow/entry.ts +47 -0
  233. package/src/workflow/host.ts +524 -0
  234. package/src/workflow/journal.ts +221 -0
  235. package/src/workflow/json-schema.ts +128 -0
  236. package/src/workflow/meta.ts +325 -0
  237. package/src/workflow/progress.ts +550 -0
  238. package/src/workflow/runtime.ts +1342 -0
  239. package/src/workflow/saved.ts +217 -0
  240. package/src/workflow/task.ts +313 -0
  241. package/src/workflow/tool-description.ts +205 -0
  242. package/src/workflow/worker-source.ts +781 -0
  243. package/src/worktree.ts +205 -0
  244. package/src/xml.ts +13 -0
@@ -0,0 +1,373 @@
1
+ /**
2
+ * runtime.ts — the host half of a workflow run.
3
+ *
4
+ * Owns the worker lifecycle, the RPC bridge, the concurrency semaphore, the
5
+ * per-run caps, and the progress log. The script's only route to an agent is a
6
+ * `call` message landing here, which is what makes the caps and the abort story
7
+ * enforceable at all: a script cannot go around them because it has nothing to
8
+ * go around them *with*.
9
+ *
10
+ * Spawning is injected rather than imported. `AgentManager` is a large, stateful
11
+ * dependency and wiring it in directly would make every test here an integration
12
+ * test; a {@link WorkflowHost} stub is a dozen lines. The adapter that binds this
13
+ * to the real manager lives at the call site.
14
+ */
15
+ import { type WorkflowJournalEntry } from "./journal.ts";
16
+ import { type CompiledSchema } from "./json-schema.ts";
17
+ import { type WorkflowMeta } from "./meta.ts";
18
+ import type { WorkflowEntry } from "./progress.ts";
19
+ /** Matches the `script` field's `maxLength` in the tool schema. */
20
+ export declare const MAX_SCRIPT_LENGTH = 524288;
21
+ /** Economical workflow role; explicit run and per-call roles take precedence. */
22
+ export declare const DEFAULT_WORKFLOW_AGENT_TYPE = "task";
23
+ /** Agents one run may schedule, in total. */
24
+ export declare const WORKFLOW_AGENT_CAP = 1000;
25
+ /** Items one `parallel()` or `pipeline()` call may take. */
26
+ export declare const WORKFLOW_ITEM_CAP = 4096;
27
+ /** Nested `workflow()` invocations allowed per run. */
28
+ export declare const WORKFLOW_NESTED_CAP = 256;
29
+ export declare class WorkflowRuntimeError extends Error {
30
+ }
31
+ /**
32
+ * Concurrent agents allowed, leaving two cores for the host and the TUI.
33
+ *
34
+ * `Math.max(1, …)` is not decoration: the raw `min(16, cpus - 2)` is 0 on a one-
35
+ * or two-core machine, and a semaphore with zero permits never hands out a slot,
36
+ * so the run would hang before its first agent rather than fail.
37
+ */
38
+ export declare function workflowConcurrency(cpuCount?: number): number;
39
+ /** One agent the script asked for. `agentId` is the handle for {@link WorkflowHost.abortAgent}. */
40
+ export interface WorkflowSpawnRequest {
41
+ agentId: string;
42
+ /** Position in the run, and the progress entry's stable identity. */
43
+ index: number;
44
+ prompt: string;
45
+ label: string;
46
+ agentType: string;
47
+ /**
48
+ * True when the call's opts.agentType or the run's agentType selected a role.
49
+ * A setting-derived default is not explicit, and a configured generic
50
+ * fallback must not turn that default into an authorized premium request.
51
+ */
52
+ agentTypeExplicit?: boolean;
53
+ model?: string;
54
+ /**
55
+ * Reasoning effort for this child, as one of pi's thinking levels.
56
+ *
57
+ * Typed as a plain string because this interface is the host boundary and
58
+ * deliberately knows nothing about pi — `host.ts` is where it becomes a
59
+ * `ThinkingLevel`. The worker has already rejected anything off the list.
60
+ */
61
+ effort?: string;
62
+ isolation?: "worktree";
63
+ /**
64
+ * Called by the host once the child's EFFECTIVE configuration is known —
65
+ * which is when its session exists, not when the spawn resolves.
66
+ *
67
+ * Without it a row could only ever show what the script asked for: a fuzzy
68
+ * `model: "haiku"` stays `haiku` instead of the id it resolved to, an
69
+ * `agent()` that named no model shows nothing at all, and a level pi clamped
70
+ * is presented as the level that was requested (#168, #182).
71
+ *
72
+ * Plain strings, like `effort` above: this interface is the host boundary and
73
+ * deliberately knows nothing about pi's `AgentInvocation`. Optional, so a host
74
+ * that cannot report any of this simply does not, and the row keeps the
75
+ * requested values it started with.
76
+ */
77
+ onResolved?(info: {
78
+ /**
79
+ * The host's own id for the child — the manager's `AgentRecord` id here.
80
+ *
81
+ * Reported as soon as the host has one, which is earlier than the rest of
82
+ * this: the model is knowable only once a session exists, but the id is
83
+ * what lets a reader open that child's conversation, and a child that
84
+ * never got a model is exactly the one worth opening.
85
+ */
86
+ recordId?: string;
87
+ modelName?: string;
88
+ modelId?: string;
89
+ thinking?: string;
90
+ requestedThinking?: string;
91
+ requestedModel?: string;
92
+ }): void;
93
+ /**
94
+ * Compiled from the script's `agent({ schema })`.
95
+ *
96
+ * The host must give the child a `StructuredOutput` tool built from it and
97
+ * return the validated payload as JSON text. Compiled rather than raw so the
98
+ * runtime can re-check the answer without re-parsing the schema per call.
99
+ */
100
+ schema?: CompiledSchema;
101
+ phaseIndex?: number;
102
+ phaseTitle?: string;
103
+ /**
104
+ * The `gate` command this agent is being spawned under, when it has one.
105
+ *
106
+ * Passed down rather than run purely from here because an isolated child's
107
+ * worktree is destroyed as part of its own settle: a host that can reach
108
+ * inside that settle runs the gate there, against the tree the child wrote,
109
+ * and reports the outcome back as {@link WorkflowSpawnResult.gate}. A host
110
+ * that ignores this leaves the gate to {@link applyGate}, which then runs it
111
+ * itself — so exactly one execution either way.
112
+ */
113
+ gate?: string;
114
+ }
115
+ export interface WorkflowSpawnResult {
116
+ ok: boolean;
117
+ /** The agent's answer. Present when `ok`. */
118
+ text?: string;
119
+ /** Why it failed. Present when not `ok`. */
120
+ error?: string;
121
+ /** Configuration failures must not be swallowed as a null pipeline item. */
122
+ fatal?: boolean;
123
+ /** The user dismissed it rather than it failing; renders as skipped. */
124
+ skipped?: boolean;
125
+ tokens?: number;
126
+ /**
127
+ * Output tokens only, for the script's `budget.spent()`.
128
+ *
129
+ * Separate from {@link tokens}, which is the lifetime total. Claude Code's
130
+ * budget counts output, and a fan-out's re-sent input would swamp it.
131
+ */
132
+ outputTokens?: number;
133
+ /** Whether the child needed an extra prompt to produce its structured answer. */
134
+ structuredRetried?: boolean;
135
+ toolCalls?: number;
136
+ /**
137
+ * Where the child actually ran.
138
+ *
139
+ * Only meaningful for `isolation: "worktree"`, and the whole reason it exists:
140
+ * a gate has to run against the tree the child edited, not the main one, or it
141
+ * verifies the wrong working copy. Left unset, a gate runs wherever the host
142
+ * runs commands by default.
143
+ *
144
+ * Usually unset for a worktree child even so: the copy is removed during the
145
+ * child's own settle, so it no longer exists by the time this is read. That
146
+ * is what {@link gate} is for.
147
+ */
148
+ cwd?: string;
149
+ /**
150
+ * The outcome of this agent's `gate`, when the host already ran it.
151
+ *
152
+ * Set only by a host that ran the command itself — inside the child's
153
+ * worktree, while that directory still existed. Its presence is what tells
154
+ * {@link applyGate} the command has already been executed; the pass/fail
155
+ * decision and the error shaping still happen there, in one place.
156
+ */
157
+ gate?: WorkflowGateResult;
158
+ }
159
+ /** Outcome of a `gate` command. `output` is what the user is shown when it fails. */
160
+ export interface WorkflowGateResult {
161
+ ok: boolean;
162
+ /** Combined stdout/stderr, or whatever the host wants surfaced as the failure. */
163
+ output: string;
164
+ }
165
+ /** The one seam between a workflow and the rest of the extension. */
166
+ /** How a script names another workflow: a saved name, or a path to a file. */
167
+ export interface WorkflowScriptRef {
168
+ name?: string;
169
+ scriptPath?: string;
170
+ }
171
+ export type WorkflowScriptSource = {
172
+ ok: true;
173
+ script: string;
174
+ path?: string;
175
+ } | {
176
+ ok: false;
177
+ message: string;
178
+ };
179
+ export interface WorkflowHost {
180
+ spawnAgent(request: WorkflowSpawnRequest): Promise<WorkflowSpawnResult>;
181
+ /** Called for every in-flight agent when the run aborts. */
182
+ abortAgent(agentId: string): void;
183
+ /**
184
+ * Continue a child that already ran in this run, keeping its context.
185
+ *
186
+ * `agentId` is one previously handed out in a {@link WorkflowSpawnRequest};
187
+ * the child keeps the agent type, model and tool contract it started with, so
188
+ * only the follow-up prompt crosses.
189
+ *
190
+ * Optional: a host without it rejects `resume` rather than quietly starting a
191
+ * fresh child that has none of the context the script is counting on.
192
+ */
193
+ resumeAgent?(agentId: string, prompt: string,
194
+ /**
195
+ * Same reporter {@link WorkflowSpawnRequest.onResolved} carries, for the
196
+ * same reason: a resumed row is rebuilt from scratch, so without it the
197
+ * continuation of a child would show the model the script *asked* for while
198
+ * the row above it shows the one that ran.
199
+ */
200
+ onResolved?: WorkflowSpawnRequest["onResolved"]): Promise<WorkflowSpawnResult>;
201
+ /**
202
+ * Run a `gate` command and report whether it passed.
203
+ *
204
+ * `cwd` is the child's worktree when it had one. Optional for the same reason
205
+ * as {@link resumeAgent}, and more sharply: a gate that silently does not run
206
+ * would mark unverified work as verified, so the runtime fails the call
207
+ * instead of skipping it.
208
+ */
209
+ runGate?(command: string, options: {
210
+ agentId: string;
211
+ cwd?: string;
212
+ }): Promise<WorkflowGateResult>;
213
+ /**
214
+ * Resolve a nested `workflow()` reference to source.
215
+ *
216
+ * The runtime knows nothing about the filesystem or about pi, so it asks. It
217
+ * still decides whether what comes back *is* a workflow — see
218
+ * {@link validateScript} — because those rules belong with the runtime that
219
+ * enforces them everywhere else.
220
+ *
221
+ * Optional for the same reason as {@link resumeAgent}: a host without it
222
+ * rejects `workflow()` outright rather than silently running nothing.
223
+ */
224
+ loadWorkflow?(ref: WorkflowScriptRef): Promise<WorkflowScriptSource> | WorkflowScriptSource;
225
+ }
226
+ /**
227
+ * What a run can be told to do while it is going, from the workflows dialog.
228
+ *
229
+ * Every method is best-effort and idempotent: the dialog renders off a progress
230
+ * log that lags the runtime slightly, so it will sometimes ask for something
231
+ * that has just stopped being possible. `false` means "there was nothing to do
232
+ * that to" — a caller can say so, but it is never an error.
233
+ */
234
+ export interface WorkflowControl {
235
+ /**
236
+ * Stop *starting* agents. Ones already running are left to finish, because
237
+ * killing model work mid-turn throws away everything it has spent and there
238
+ * is no way to hand it back its context.
239
+ */
240
+ pause(): void;
241
+ resume(): void;
242
+ isPaused(): boolean;
243
+ /**
244
+ * Give up on the agent at `index`: its `agent()` call returns `null`, exactly
245
+ * as a terminal failure does, and the row renders skipped.
246
+ *
247
+ * Immediate for a running agent and for one held at a pause. An agent parked
248
+ * behind the concurrency limit takes its skip when it reaches the front —
249
+ * the alternative is a cancellable semaphore for a case that resolves itself
250
+ * as soon as any sibling finishes.
251
+ */
252
+ skip(index: number): boolean;
253
+ /**
254
+ * Start the agent at `index` over: the child is stopped and the same call is
255
+ * re-run, so the script's `agent()` promise is still the one waiting and it
256
+ * gets the new answer.
257
+ *
258
+ * Only while it is running — that is the whole window. Once the call has
259
+ * settled its value is already the script's, and re-running would produce a
260
+ * result with nowhere to go.
261
+ */
262
+ retry(index: number): boolean;
263
+ }
264
+ export interface RunWorkflowOptions {
265
+ /** Full script source, starting with `export const meta = { … }`. */
266
+ script: string;
267
+ args?: unknown;
268
+ /** Used only when an agent() call does not name its own role. */
269
+ defaultAgentType?: string;
270
+ /** True when the run's `agentType` named that default — see {@link WorkflowSpawnRequest.agentTypeExplicit}. */
271
+ defaultAgentTypeExplicit?: boolean;
272
+ host: WorkflowHost;
273
+ signal?: AbortSignal;
274
+ /** Fired per batch, not per entry — see the worker's progress batching. */
275
+ onProgress?(entries: readonly WorkflowEntry[]): void;
276
+ concurrency?: number;
277
+ agentCap?: number;
278
+ itemCap?: number;
279
+ /**
280
+ * Hands the caller the run's control surface, once per run.
281
+ *
282
+ * A callback rather than a return value because `runWorkflow` resolves when
283
+ * the run is *over*, which is the one moment there is nothing left to
284
+ * control. Fired before the first agent starts.
285
+ */
286
+ onControl?(control: WorkflowControl): void;
287
+ /**
288
+ * How many nested `workflow()` invocations one run may make in total.
289
+ *
290
+ * Each costs a compile and a scope rather than a thread, so the ceiling is
291
+ * generous — but unbounded is worse than capped, on the same reasoning as
292
+ * {@link agentCap}.
293
+ */
294
+ nestedCap?: number;
295
+ /**
296
+ * Replay and record, for `resumeFromRunId`.
297
+ *
298
+ * The runtime does no file IO — `entries` come in already read and `append`
299
+ * goes back out — so its tests stay free of a filesystem, the same reason
300
+ * spawning is behind {@link WorkflowHost}.
301
+ */
302
+ journal?: {
303
+ /** A previous run's settled calls, in position order. Empty replays nothing. */
304
+ entries?: readonly WorkflowJournalEntry[];
305
+ /**
306
+ * Called as each call of *this* run settles, so it can be resumed in turn.
307
+ *
308
+ * May return a promise. The runtime accepts records synchronously and
309
+ * writes them through one ordered chain, so a slow disk never blocks an
310
+ * agent's response and a failed write never drops the records after it.
311
+ * {@link onJournalDrain} is how a caller waits for that chain: this callback
312
+ * only runs once the record reaches the front of it.
313
+ */
314
+ append?(entry: WorkflowJournalEntry): void | Promise<void>;
315
+ };
316
+ /**
317
+ * The run's accepted-write drain, handed over before any work starts.
318
+ *
319
+ * Whatever {@link journal.append} is given is queued inside this run first, so
320
+ * a record can be accepted long before the journal module has been handed it
321
+ * — and `readJournal` can only wait for appends it was given. A caller that
322
+ * reads the journal back (a paused run being resumed, a shutdown that must
323
+ * not lose the tail) needs to wait for the *queue*. The handle delivered here
324
+ * resolves once every record accepted so far has settled, and keeps following
325
+ * the queue if a call settles while it is waiting. Nothing accepted is ever
326
+ * dropped, and a failed write is still swallowed rather than failing the wait:
327
+ * this is the same best-effort treatment `append` gets.
328
+ *
329
+ * Called once, before the worker exists. A handle delivered later could miss
330
+ * a call that had already settled for a run nobody had been told about yet.
331
+ */
332
+ onJournalDrain?(drain: () => Promise<void>): void;
333
+ }
334
+ export interface WorkflowRunResult {
335
+ status: "completed" | "failed" | "killed";
336
+ meta: WorkflowMeta;
337
+ /** The script's return value, JSON-checked at the boundary. */
338
+ value?: unknown;
339
+ error?: string;
340
+ /** The append-only log, in emission order. */
341
+ progress: WorkflowEntry[];
342
+ /** Agents scheduled, including those that failed. */
343
+ agentCount: number;
344
+ /** How many of those came back from the journal instead of being spawned. */
345
+ replayedCount: number;
346
+ }
347
+ /**
348
+ * Reject anything that cannot survive the round trip to the worker and into a
349
+ * resume journal. Structured clone would happily carry a `Map` or a cycle that
350
+ * the journal then cannot represent, so the check is stricter than the transport.
351
+ */
352
+ export declare function assertBoundarySafe(value: unknown, path: string): void;
353
+ /**
354
+ * Run one workflow script to completion.
355
+ *
356
+ * Rejects before starting for a script that cannot run at all (bad `meta`, over
357
+ * the size limit, control characters, non-JSON `args`). Everything after the
358
+ * worker is live resolves instead, carrying the failure in `status` — by then
359
+ * there is a progress log worth handing back.
360
+ */
361
+ /**
362
+ * Everything a script must satisfy before it is compiled.
363
+ *
364
+ * Extracted so a nested `workflow()` is held to exactly the same standard as a
365
+ * top-level run: same size limit, same character rules, same `meta` contract.
366
+ * The host resolves a reference to source; deciding whether that source is a
367
+ * workflow stays here, where the rules live.
368
+ */
369
+ export declare function validateScript(script: string): {
370
+ meta: WorkflowMeta;
371
+ body: string;
372
+ };
373
+ export declare function runWorkflow(options: RunWorkflowOptions): Promise<WorkflowRunResult>;