@yycholla/pi-dynamic-workflows 3.3.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 (179) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +325 -0
  3. package/assets/readme/hero.png +0 -0
  4. package/assets/readme/hero.svg +70 -0
  5. package/assets/readme/package-cover.png +0 -0
  6. package/assets/readme/package-cover.svg +66 -0
  7. package/assets/readme/workflow.png +0 -0
  8. package/assets/readme/workflow.svg +77 -0
  9. package/dist/accept-workflow-guidance.d.ts +14 -0
  10. package/dist/accept-workflow-guidance.js +53 -0
  11. package/dist/adversarial-review.d.ts +30 -0
  12. package/dist/adversarial-review.js +107 -0
  13. package/dist/agent-history.d.ts +20 -0
  14. package/dist/agent-history.js +122 -0
  15. package/dist/agent-registry.d.ts +83 -0
  16. package/dist/agent-registry.js +190 -0
  17. package/dist/agent.d.ts +364 -0
  18. package/dist/agent.js +714 -0
  19. package/dist/builtin-commands.d.ts +19 -0
  20. package/dist/builtin-commands.js +251 -0
  21. package/dist/builtin-workflows.d.ts +45 -0
  22. package/dist/builtin-workflows.js +121 -0
  23. package/dist/code-review.d.ts +26 -0
  24. package/dist/code-review.js +181 -0
  25. package/dist/config.d.ts +37 -0
  26. package/dist/config.js +44 -0
  27. package/dist/deep-research.d.ts +30 -0
  28. package/dist/deep-research.js +124 -0
  29. package/dist/display.d.ts +134 -0
  30. package/dist/display.js +248 -0
  31. package/dist/effort-command.d.ts +28 -0
  32. package/dist/effort-command.js +68 -0
  33. package/dist/enums.d.ts +69 -0
  34. package/dist/enums.js +78 -0
  35. package/dist/errors.d.ts +113 -0
  36. package/dist/errors.js +140 -0
  37. package/dist/extension-reload.d.ts +37 -0
  38. package/dist/extension-reload.js +78 -0
  39. package/dist/fs-persistence.d.ts +63 -0
  40. package/dist/fs-persistence.js +102 -0
  41. package/dist/index.d.ts +57 -0
  42. package/dist/index.js +35 -0
  43. package/dist/logger.d.ts +21 -0
  44. package/dist/logger.js +66 -0
  45. package/dist/model-routing.d.ts +30 -0
  46. package/dist/model-routing.js +50 -0
  47. package/dist/model-spec.d.ts +29 -0
  48. package/dist/model-spec.js +252 -0
  49. package/dist/model-tier-config.d.ts +133 -0
  50. package/dist/model-tier-config.js +249 -0
  51. package/dist/run-persistence.d.ts +180 -0
  52. package/dist/run-persistence.js +294 -0
  53. package/dist/saved-commands.d.ts +28 -0
  54. package/dist/saved-commands.js +100 -0
  55. package/dist/shared-store.d.ts +98 -0
  56. package/dist/shared-store.js +212 -0
  57. package/dist/structured-output.d.ts +19 -0
  58. package/dist/structured-output.js +30 -0
  59. package/dist/task-panel.d.ts +61 -0
  60. package/dist/task-panel.js +422 -0
  61. package/dist/usage-limit-scheduler.d.ts +145 -0
  62. package/dist/usage-limit-scheduler.js +368 -0
  63. package/dist/web-tools.d.ts +20 -0
  64. package/dist/web-tools.js +120 -0
  65. package/dist/workflow-authoring-coverage.d.ts +70 -0
  66. package/dist/workflow-authoring-coverage.js +421 -0
  67. package/dist/workflow-authoring-reference.d.ts +20 -0
  68. package/dist/workflow-authoring-reference.js +156 -0
  69. package/dist/workflow-capability-contract.d.ts +131 -0
  70. package/dist/workflow-capability-contract.js +604 -0
  71. package/dist/workflow-commands.d.ts +18 -0
  72. package/dist/workflow-commands.js +260 -0
  73. package/dist/workflow-comprehension.d.ts +133 -0
  74. package/dist/workflow-comprehension.js +1321 -0
  75. package/dist/workflow-context-measurement.d.ts +72 -0
  76. package/dist/workflow-context-measurement.js +213 -0
  77. package/dist/workflow-control-tool.d.ts +30 -0
  78. package/dist/workflow-control-tool.js +176 -0
  79. package/dist/workflow-delivery-choice.d.ts +20 -0
  80. package/dist/workflow-delivery-choice.js +48 -0
  81. package/dist/workflow-editor.d.ts +93 -0
  82. package/dist/workflow-editor.js +363 -0
  83. package/dist/workflow-manager.d.ts +492 -0
  84. package/dist/workflow-manager.js +1124 -0
  85. package/dist/workflow-paths.d.ts +22 -0
  86. package/dist/workflow-paths.js +46 -0
  87. package/dist/workflow-release-gate.d.ts +39 -0
  88. package/dist/workflow-release-gate.js +309 -0
  89. package/dist/workflow-saved.d.ts +38 -0
  90. package/dist/workflow-saved.js +126 -0
  91. package/dist/workflow-settings.d.ts +70 -0
  92. package/dist/workflow-settings.js +131 -0
  93. package/dist/workflow-tool.d.ts +71 -0
  94. package/dist/workflow-tool.js +367 -0
  95. package/dist/workflow-ui.d.ts +182 -0
  96. package/dist/workflow-ui.js +1587 -0
  97. package/dist/workflow.d.ts +333 -0
  98. package/dist/workflow.js +1151 -0
  99. package/dist/workflows-models-command.d.ts +31 -0
  100. package/dist/workflows-models-command.js +156 -0
  101. package/dist/worktree.d.ts +25 -0
  102. package/dist/worktree.js +61 -0
  103. package/extensions/workflow.ts +151 -0
  104. package/package.json +104 -0
  105. package/skills/workflow-authoring/SKILL.md +30 -0
  106. package/skills/workflow-authoring/examples/adversarial-verification.js +63 -0
  107. package/skills/workflow-authoring/examples/bounded-semantic-retry.js +56 -0
  108. package/skills/workflow-authoring/examples/classify-and-act.js +67 -0
  109. package/skills/workflow-authoring/examples/fan-out-and-synthesize.js +47 -0
  110. package/skills/workflow-authoring/examples/generate-and-filter.js +68 -0
  111. package/skills/workflow-authoring/examples/loop-until-done.js +68 -0
  112. package/skills/workflow-authoring/examples/phased-budgets.js +75 -0
  113. package/skills/workflow-authoring/examples/saved-nested-workflows.js +44 -0
  114. package/skills/workflow-authoring/examples/structured-output.js +37 -0
  115. package/skills/workflow-authoring/examples/tournament.js +81 -0
  116. package/skills/workflow-authoring/examples/validated-gate.js +63 -0
  117. package/skills/workflow-authoring/references/capabilities.md +41 -0
  118. package/skills/workflow-authoring/references/capability-details.md +357 -0
  119. package/skills/workflow-authoring/references/common-helpers.md +4 -0
  120. package/skills/workflow-authoring/references/debugging.md +27 -0
  121. package/skills/workflow-authoring/references/focused-recipes.md +11 -0
  122. package/skills/workflow-authoring/references/helpers.md +9 -0
  123. package/skills/workflow-authoring/references/lifecycle.md +33 -0
  124. package/skills/workflow-authoring/references/pattern-selection.md +15 -0
  125. package/skills/workflow-authoring/references/quality-helpers.md +8 -0
  126. package/skills/workflow-authoring/references/registry-ownership.md +15 -0
  127. package/skills/workflow-authoring/references/retry-helper.md +5 -0
  128. package/skills/workflow-authoring/references/review.md +43 -0
  129. package/skills/workflow-authoring/references/runtime.md +27 -0
  130. package/skills/workflow-authoring/references/specialized-helpers.md +19 -0
  131. package/skills/workflow-authoring/references/versions.md +13 -0
  132. package/skills/workflow-patterns/SKILL.md +51 -0
  133. package/src/accept-workflow-guidance.ts +71 -0
  134. package/src/adversarial-review.ts +120 -0
  135. package/src/agent-history.ts +157 -0
  136. package/src/agent-registry.ts +221 -0
  137. package/src/agent.ts +929 -0
  138. package/src/builtin-commands.ts +286 -0
  139. package/src/builtin-workflows.ts +155 -0
  140. package/src/code-review.ts +183 -0
  141. package/src/config.ts +55 -0
  142. package/src/deep-research.ts +135 -0
  143. package/src/display.ts +367 -0
  144. package/src/effort-command.ts +87 -0
  145. package/src/enums.ts +77 -0
  146. package/src/errors.ts +199 -0
  147. package/src/extension-reload.ts +100 -0
  148. package/src/fs-persistence.ts +124 -0
  149. package/src/index.ts +176 -0
  150. package/src/logger.ts +88 -0
  151. package/src/model-routing.ts +73 -0
  152. package/src/model-spec.ts +309 -0
  153. package/src/model-tier-config.ts +296 -0
  154. package/src/run-persistence.ts +484 -0
  155. package/src/saved-commands.ts +115 -0
  156. package/src/shared-store.ts +228 -0
  157. package/src/structured-output.ts +47 -0
  158. package/src/task-panel.ts +490 -0
  159. package/src/usage-limit-scheduler.ts +432 -0
  160. package/src/web-tools.ts +124 -0
  161. package/src/workflow-authoring-coverage.ts +486 -0
  162. package/src/workflow-authoring-reference.ts +186 -0
  163. package/src/workflow-capability-contract.ts +806 -0
  164. package/src/workflow-commands.ts +287 -0
  165. package/src/workflow-comprehension.ts +1673 -0
  166. package/src/workflow-context-measurement.ts +262 -0
  167. package/src/workflow-control-tool.ts +238 -0
  168. package/src/workflow-delivery-choice.ts +69 -0
  169. package/src/workflow-editor.ts +444 -0
  170. package/src/workflow-manager.ts +1405 -0
  171. package/src/workflow-paths.ts +63 -0
  172. package/src/workflow-release-gate.ts +529 -0
  173. package/src/workflow-saved.ts +180 -0
  174. package/src/workflow-settings.ts +194 -0
  175. package/src/workflow-tool.ts +464 -0
  176. package/src/workflow-ui.ts +1789 -0
  177. package/src/workflow.ts +1615 -0
  178. package/src/workflows-models-command.ts +211 -0
  179. package/src/worktree.ts +76 -0
@@ -0,0 +1,333 @@
1
+ import type { TSchema } from "typebox";
2
+ import type { AgentUsage } from "./agent.js";
3
+ import { type AgentRunOptions, type WorkflowAgentOptions } from "./agent.js";
4
+ import type { AgentHistoryEntry } from "./agent-history.js";
5
+ import { type AgentRegistry } from "./agent-registry.js";
6
+ import { WorkflowErrorCode } from "./errors.js";
7
+ import { SharedStore } from "./shared-store.js";
8
+ export interface WorkflowMetaPhase {
9
+ title: string;
10
+ detail?: string;
11
+ model?: string;
12
+ }
13
+ export interface WorkflowMeta {
14
+ name: string;
15
+ description: string;
16
+ phases?: WorkflowMetaPhase[];
17
+ /** Default model for agents whose phase has no route and that set no model/tier. */
18
+ model?: string;
19
+ }
20
+ /** One cached agent() result, keyed by its deterministic call index. */
21
+ export interface JournalEntry {
22
+ index: number;
23
+ /**
24
+ * The runId of the frame (top-level run, or a nested workflow()'s own run)
25
+ * this entry's `index` is scoped to. A nested workflow() restarts its own
26
+ * callSeq at 0, so `index` alone collides between a parent's and a child's
27
+ * same-numbered calls — see `resumeJournal`'s key format, which namespaces
28
+ * on this the same way SharedStore's deltaKey already does. Absent on
29
+ * journal entries persisted before this field existed; such legacy entries
30
+ * are treated as belonging to the run's own top-level runId (see
31
+ * WorkflowManager.resume()) — a legacy entry that actually belonged to a
32
+ * nested frame simply cache-misses on resume (safe degradation: it re-runs
33
+ * live, it does not apply to the wrong call).
34
+ */
35
+ runId?: string;
36
+ /** sha256 of the call's identity (prompt + model + phase + agentType + schema). */
37
+ hash: string;
38
+ result: unknown;
39
+ /**
40
+ * Per-agent write delta (keys set by this agent) for additive replay on resume.
41
+ * Replaces the former full-map snapshot to fix parallel-agent ordering: applying
42
+ * deltas in callSeq order accumulates all agents' writes correctly regardless of
43
+ * which agent finished first. Absent on older journal entries.
44
+ */
45
+ storeDelta?: Record<string, unknown>;
46
+ }
47
+ /**
48
+ * Global resources shared across a run and any workflow() nested inside it, so
49
+ * the 16-concurrent / 1000-total caps and the token budget hold across nesting
50
+ * instead of each level getting its own limiter and counters.
51
+ */
52
+ export interface SharedRuntime {
53
+ limiter: <T>(fn: () => Promise<T>) => Promise<T>;
54
+ agentCount: number;
55
+ spent: number;
56
+ tokenUsage: {
57
+ input: number;
58
+ output: number;
59
+ total: number;
60
+ cost: number;
61
+ cacheRead: number;
62
+ cacheWrite: number;
63
+ };
64
+ depth: number;
65
+ /**
66
+ * Monotonic count of every workflow() call anywhere in this run tree,
67
+ * regardless of nesting depth — used (instead of `depth`) to build each
68
+ * nested run's runId suffix (see workflowFn below). `depth` alone is NOT
69
+ * enough: it returns to 0 after each nested call finishes, so two
70
+ * SEQUENTIAL nested workflow() calls at the same depth (`await
71
+ * workflow('a'); await workflow('b')`) would otherwise both compute the
72
+ * exact same `${runId}-nested1` suffix. That collision matters because a
73
+ * child's own callSeq restarts at 0, so its deltaKey (`${childRunId}:
74
+ * ${callIndex}`) — the same id used as SharedStore's delta key AND as the
75
+ * onAgentStart/onAgentEnd/onAgentHistory event id (see item 2's identity
76
+ * model) — would collide between the two children's same-callIndex calls.
77
+ * That's a real, not just theoretical, collision risk: an un-awaited
78
+ * stray agent() call from the first child (still in SharedRuntime.inFlight,
79
+ * not yet drained — only the top-level frame drains) can still be pending
80
+ * when the second child starts and mints the very same id.
81
+ */
82
+ nestedCallSeq: number;
83
+ /**
84
+ * Fires exactly once a run-fatal error is determined: an error that escaped
85
+ * the TOP-level script's own execution completely uncaught (see runWorkflow's
86
+ * catch below) — i.e. nothing anywhere in the call chain, at any nesting
87
+ * depth, caught it, so the run really is failing. Shared (not per-nesting-
88
+ * level) so a nested workflow()'s in-flight siblings wind down too, the
89
+ * instant the fate of the WHOLE run is sealed — not the instant any single
90
+ * fan-out rejects, which would break parallel()'s null-on-recoverable-error
91
+ * contract and a script's own try/catch around agent()/workflow(). Every
92
+ * agent() call (this level and any nested workflow()) links its per-attempt
93
+ * AbortController to this signal, alongside the caller's own options.signal,
94
+ * so already-in-flight sibling subagent sessions actually abort instead of
95
+ * running to completion on a run whose outcome is already decided. Wrapped
96
+ * in an AbortController (not a bare boolean) purely so workflow.ts never
97
+ * needs write access to the caller-owned options.signal/AbortController.
98
+ */
99
+ runFatalController: AbortController;
100
+ /**
101
+ * Every agent() promise spawned anywhere in this run (this level's script
102
+ * and any nested workflow()'s), added on call and removed on settle. Drained
103
+ * (awaited to completion) by the TOP-level runWorkflow's finally, before the
104
+ * SharedStore is disposed — so a script that forgets to `await agent(...)`
105
+ * can never have that call still mutating the store (or reporting results)
106
+ * after the run has been marked complete and torn down. See the drain below.
107
+ */
108
+ inFlight: Set<Promise<unknown>>;
109
+ }
110
+ /** Runtime instrumentation for workflow boundaries, quality helpers, and control attempts. */
111
+ export type WorkflowRuntimeEvent = {
112
+ type: "phase";
113
+ title: string;
114
+ budget: number | null;
115
+ } | {
116
+ type: "workflow";
117
+ stage: "start" | "end";
118
+ name: string;
119
+ args: unknown;
120
+ } | {
121
+ type: "quality";
122
+ stage: "start" | "end";
123
+ helper: "verify" | "judgePanel" | "completenessCheck";
124
+ } | {
125
+ type: "control-attempt";
126
+ helper: "retry" | "gate";
127
+ attempt: number;
128
+ accepted: boolean;
129
+ };
130
+ /** Minimal injected agent surface used by the workflow runtime and deterministic tests. */
131
+ export interface WorkflowAgentRunner {
132
+ run(prompt: string, options?: AgentRunOptions<TSchema>): Promise<unknown>;
133
+ }
134
+ export interface WorkflowRunOptions extends WorkflowAgentOptions {
135
+ args?: unknown;
136
+ agent?: WorkflowAgentRunner;
137
+ /** The session's main model (provider/id), shown in /workflows for default agents. */
138
+ mainModel?: string;
139
+ /**
140
+ * Named subagent definitions for `agent({ agentType })`. Snapshotted once per
141
+ * run for determinism. Defaults to scanning `.pi/agents` (project) +
142
+ * `~/.pi/agent/agents` (user, primary) + `~/.pi/agents` (user, deprecated
143
+ * fallback). Injectable for tests.
144
+ */
145
+ agentRegistry?: AgentRegistry;
146
+ concurrency?: number;
147
+ /** Retry attempts after a recoverable agent failure. Default 0. */
148
+ agentRetries?: number;
149
+ tokenBudget?: number | null;
150
+ signal?: AbortSignal;
151
+ /** Maximum number of agents allowed in this run. Default: 1000 */
152
+ maxAgents?: number;
153
+ /** Timeout per agent in milliseconds. null/omitted means no hard timeout. */
154
+ agentTimeoutMs?: number | null;
155
+ /** Whether to persist logs to disk. Default: true */
156
+ persistLogs?: boolean;
157
+ /** Run ID for persistence. Auto-generated if not provided. */
158
+ runId?: string;
159
+ /**
160
+ * Resume: cached agent/checkpoint results keyed by `${runId}:${callIndex}`
161
+ * — the same namespacing SharedStore's deltaKey uses — so a nested
162
+ * workflow() call's callIndex-0 (its callSeq restarts at 0) can never
163
+ * collide with the parent's own callIndex-0 entry. A legacy entry with no
164
+ * `runId` (persisted before namespacing existed) is looked up under the
165
+ * run's own top-level runId only; see `JournalEntry.runId`.
166
+ */
167
+ resumeJournal?: Map<string, JournalEntry>;
168
+ /** Resume: the run being resumed (informational; enables resume mode). */
169
+ resumeFromRunId?: string;
170
+ /** Called after each live agent completes so the caller can persist the journal. */
171
+ onAgentJournal?: (entry: JournalEntry) => void;
172
+ /**
173
+ * Called once per FAILED-AND-RETRIED attempt (not the final attempt of an
174
+ * agent() call, which reports its own tokens via onAgentEnd as before),
175
+ * with that attempt's token cost. recordTokens() already folds a retried
176
+ * attempt's spend into shared.spent/shared.tokenUsage (so the run-wide
177
+ * budget was never leaky) — but onAgentEnd only ever reports the FINAL
178
+ * attempt's tokens, so a caller accumulating a persisted total purely from
179
+ * onAgentEnd (see WorkflowManager) would under-count by exactly the
180
+ * wasted retried attempts' spend. This is a separate, silent channel
181
+ * specifically so retried-attempt spend can be accounted for without
182
+ * changing onAgentEnd's one-call-per-agent-call cadence (a contract other
183
+ * code depends on).
184
+ */
185
+ onRetrySpend?: (tokens: number) => void;
186
+ /** Internal: shared runtime inherited by a nested workflow() call. */
187
+ sharedRuntime?: SharedRuntime;
188
+ /**
189
+ * Seed the FRESH SharedRuntime's cumulative spend/tokenUsage counters from a
190
+ * previously-persisted total (resume()), instead of starting at zero. Used
191
+ * only on the fresh-SharedRuntime branch below — never applied when
192
+ * `sharedRuntime` is supplied (a nested workflow() call inherits the
193
+ * parent's live, already-correct counters and must not be re-seeded).
194
+ * Without this, a resumed run's tokenBudget cap silently resets: it would
195
+ * enforce the ceiling against only what THIS execution spends, ignoring
196
+ * whatever was already spent before the pause.
197
+ */
198
+ initialTokenUsage?: {
199
+ input: number;
200
+ output: number;
201
+ total: number;
202
+ cost: number;
203
+ cacheRead: number;
204
+ cacheWrite: number;
205
+ };
206
+ /**
207
+ * Shared store for this run. One instance is created per top-level run and
208
+ * propagated into nested workflow() calls. Pass an existing instance to share
209
+ * state across a parent and child run; omit to create a fresh isolated store.
210
+ */
211
+ sharedStore?: SharedStore;
212
+ /** Resolve a saved-workflow name to its script, enabling `workflow('name', args)`. */
213
+ loadSavedWorkflow?: (name: string) => string | undefined;
214
+ /**
215
+ * Ask the human a checkpoint() question and resolve to their reply. Threaded from
216
+ * a UI-bearing tool context. Absent => headless: checkpoint() takes its declared
217
+ * default (and journals it), so a detached/background run never hangs.
218
+ */
219
+ confirm?: (promptText: string, options: CheckpointOptions) => Promise<unknown>;
220
+ onLog?: (message: string) => void;
221
+ onPhase?: (title: string) => void;
222
+ /** Runtime behavior trace used by diagnostics and comprehension evidence. */
223
+ onRuntimeEvent?: (event: WorkflowRuntimeEvent) => void;
224
+ onAgentStart?: (event: {
225
+ id: string;
226
+ label: string;
227
+ phase?: string;
228
+ prompt: string;
229
+ model?: string;
230
+ }) => void;
231
+ onAgentEnd?: (event: {
232
+ /**
233
+ * Unique per agent() CALL (not per label — concurrent agents routinely
234
+ * share a label, e.g. parallel()'s default `"${phase} agent N"` labels or
235
+ * an author-supplied label reused across a fan-out). Stable across this
236
+ * call's start/end/history events. Callers must key any per-agent
237
+ * bookkeeping on this, never on label, to avoid misattributing a
238
+ * concurrent same-label agent's event to the wrong entry.
239
+ */
240
+ id: string;
241
+ label: string;
242
+ phase?: string;
243
+ result: unknown;
244
+ tokens?: number;
245
+ tokenUsage?: AgentUsage;
246
+ worktree?: string;
247
+ model?: string;
248
+ error?: string;
249
+ errorCode?: WorkflowErrorCode;
250
+ recoverable?: boolean;
251
+ }) => void;
252
+ onAgentHistory?: (event: {
253
+ id: string;
254
+ label: string;
255
+ phase?: string;
256
+ history: AgentHistoryEntry[];
257
+ }) => void;
258
+ onTokenUsage?: (usage: {
259
+ input: number;
260
+ output: number;
261
+ total: number;
262
+ cost: number;
263
+ cacheRead?: number;
264
+ cacheWrite?: number;
265
+ }) => void;
266
+ }
267
+ export interface WorkflowRunResult<T = unknown> {
268
+ meta: WorkflowMeta;
269
+ result: T;
270
+ logs: string[];
271
+ phases: string[];
272
+ agentCount: number;
273
+ durationMs: number;
274
+ runId?: string;
275
+ tokenUsage?: {
276
+ input: number;
277
+ output: number;
278
+ total: number;
279
+ cost: number;
280
+ cacheRead?: number;
281
+ cacheWrite?: number;
282
+ };
283
+ }
284
+ export interface AgentOptions<TSchemaDef extends TSchema | undefined = TSchema | undefined> {
285
+ label?: string;
286
+ phase?: string;
287
+ schema?: TSchemaDef;
288
+ /**
289
+ * Run this agent on a specific model (`provider/modelId` or a bare `modelId`).
290
+ * The workflow author chooses per-agent models per the routing policy in the
291
+ * tool guidelines (e.g. a lighter model for exploration, the main model for
292
+ * analysis). When omitted, the session's main model is used.
293
+ */
294
+ model?: string;
295
+ /**
296
+ * Coarse model tier ("small" | "medium" | "big"), resolved from the user's
297
+ * model-tiers config (see /workflows-models). An explicit `model` takes
298
+ * precedence; a tier takes precedence over the phase model. When the tier has
299
+ * no configured entry it falls back to the session's main model.
300
+ */
301
+ tier?: string;
302
+ isolation?: "worktree";
303
+ /**
304
+ * Name of a registered subagent definition (`.pi/agents/<name>.md`, project >
305
+ * user). Binds that definition's tool allow/denylist, model, and body prompt
306
+ * to this agent. An explicit `model` overrides the definition's model; the
307
+ * definition's model overrides `tier`/phase. An unknown name logs a warning
308
+ * and falls back to default tools/model (with the name as a prose hint).
309
+ */
310
+ agentType?: string;
311
+ /** Override timeout for this specific agent. null means no hard timeout. */
312
+ timeoutMs?: number | null;
313
+ /** Retry attempts after a recoverable failure for this specific agent. */
314
+ retries?: number;
315
+ }
316
+ /** Options for a human checkpoint() — a deterministic, journaled, replayable gate. */
317
+ export interface CheckpointOptions {
318
+ /** Reply used when no UI is available (headless/background) and headless != "abort". */
319
+ default?: unknown;
320
+ /** Headless behavior: "default" (take `default`/true) or "abort" (throw). Default "default". */
321
+ headless?: "default" | "abort";
322
+ /** Confirm | free-text input | pick-one. Affects the hash and the UI widget. */
323
+ kind?: "confirm" | "input" | "select";
324
+ /** For kind "select". */
325
+ choices?: string[];
326
+ /** Per-checkpoint timeout in ms for the interactive prompt. */
327
+ timeoutMs?: number;
328
+ }
329
+ export declare function runWorkflow<T = unknown>(script: string, options?: WorkflowRunOptions): Promise<WorkflowRunResult<T>>;
330
+ export declare function parseWorkflowScript(script: string): {
331
+ meta: WorkflowMeta;
332
+ body: string;
333
+ };