hiveagents-runtime 0.0.0-stage → 0.1.0-beta.3
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.
- package/LICENSE +202 -0
- package/README.md +89 -2
- package/dist/adapter-kit.d.ts +37 -0
- package/dist/adapter-kit.js +34 -0
- package/dist/adapter-kit.js.map +1 -0
- package/dist/agent-Bj5YPrO7.d.ts +169 -0
- package/dist/agent-D6OXR7UF.js +24 -0
- package/dist/agent-D6OXR7UF.js.map +1 -0
- package/dist/agent-readiness-KSGNKTGK.js +19 -0
- package/dist/agent-readiness-KSGNKTGK.js.map +1 -0
- package/dist/capture-runtime-GP6NZ2ee.d.ts +54 -0
- package/dist/chunk-2RK74GCA.js +2397 -0
- package/dist/chunk-2RK74GCA.js.map +1 -0
- package/dist/chunk-3TIYA3K5.js +55 -0
- package/dist/chunk-3TIYA3K5.js.map +1 -0
- package/dist/chunk-6FIXXWNM.js +1 -0
- package/dist/chunk-6FIXXWNM.js.map +1 -0
- package/dist/chunk-6XIJW65Q.js +52 -0
- package/dist/chunk-6XIJW65Q.js.map +1 -0
- package/dist/chunk-7LDQKJKI.js +248 -0
- package/dist/chunk-7LDQKJKI.js.map +1 -0
- package/dist/chunk-CPN4DOXH.js +115 -0
- package/dist/chunk-CPN4DOXH.js.map +1 -0
- package/dist/chunk-DAXPAV2L.js +810 -0
- package/dist/chunk-DAXPAV2L.js.map +1 -0
- package/dist/chunk-DQEMIGKC.js +291 -0
- package/dist/chunk-DQEMIGKC.js.map +1 -0
- package/dist/chunk-DZFFGUIA.js +81 -0
- package/dist/chunk-DZFFGUIA.js.map +1 -0
- package/dist/chunk-EEUYQFCP.js +106 -0
- package/dist/chunk-EEUYQFCP.js.map +1 -0
- package/dist/chunk-G6JV7WV6.js +521 -0
- package/dist/chunk-G6JV7WV6.js.map +1 -0
- package/dist/chunk-GFVYNPLS.js +118 -0
- package/dist/chunk-GFVYNPLS.js.map +1 -0
- package/dist/chunk-GS5U3KUN.js +201 -0
- package/dist/chunk-GS5U3KUN.js.map +1 -0
- package/dist/chunk-HB7FBSH2.js +960 -0
- package/dist/chunk-HB7FBSH2.js.map +1 -0
- package/dist/chunk-HZFZX5A3.js +21 -0
- package/dist/chunk-HZFZX5A3.js.map +1 -0
- package/dist/chunk-J7VAYJKM.js +595 -0
- package/dist/chunk-J7VAYJKM.js.map +1 -0
- package/dist/chunk-NCNSHOF7.js +52 -0
- package/dist/chunk-NCNSHOF7.js.map +1 -0
- package/dist/chunk-RH5A5U7G.js +202 -0
- package/dist/chunk-RH5A5U7G.js.map +1 -0
- package/dist/chunk-RX3XZENU.js +385 -0
- package/dist/chunk-RX3XZENU.js.map +1 -0
- package/dist/chunk-RXU2Q2HF.js +49 -0
- package/dist/chunk-RXU2Q2HF.js.map +1 -0
- package/dist/chunk-TG7NTMTR.js +208 -0
- package/dist/chunk-TG7NTMTR.js.map +1 -0
- package/dist/chunk-TWGEYWMO.js +1217 -0
- package/dist/chunk-TWGEYWMO.js.map +1 -0
- package/dist/chunk-UZPDDQVJ.js +2910 -0
- package/dist/chunk-UZPDDQVJ.js.map +1 -0
- package/dist/chunk-WMKO5XOE.js +601 -0
- package/dist/chunk-WMKO5XOE.js.map +1 -0
- package/dist/chunk-WOQBVJH5.js +175 -0
- package/dist/chunk-WOQBVJH5.js.map +1 -0
- package/dist/chunk-WVT5SEKC.js +581 -0
- package/dist/chunk-WVT5SEKC.js.map +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +26 -0
- package/dist/cli.js.map +1 -0
- package/dist/errors-BNHvvjn9.d.ts +98 -0
- package/dist/execution-halt-B8G0fOKS.d.ts +12 -0
- package/dist/execution-types-ClYYqPQP.d.ts +239 -0
- package/dist/host-ledger-VPRWVVOS.js +25 -0
- package/dist/host-ledger-VPRWVVOS.js.map +1 -0
- package/dist/hosted-runtime.d.ts +168 -0
- package/dist/hosted-runtime.js +858 -0
- package/dist/hosted-runtime.js.map +1 -0
- package/dist/index-B86C6VAD.d.ts +41 -0
- package/dist/index.d.ts +344 -0
- package/dist/index.js +8825 -0
- package/dist/index.js.map +1 -0
- package/dist/memory-items-BSTC0_R0.d.ts +28 -0
- package/dist/memory-tools.d.ts +222 -0
- package/dist/memory-tools.js +923 -0
- package/dist/memory-tools.js.map +1 -0
- package/dist/orchestration/dynamic.d.ts +854 -0
- package/dist/orchestration/dynamic.js +3150 -0
- package/dist/orchestration/dynamic.js.map +1 -0
- package/dist/orchestration/graph.d.ts +11 -0
- package/dist/orchestration/graph.js +9 -0
- package/dist/orchestration/graph.js.map +1 -0
- package/dist/orchestration/index.d.ts +2385 -0
- package/dist/orchestration/index.js +6409 -0
- package/dist/orchestration/index.js.map +1 -0
- package/dist/orchestration/log.d.ts +301 -0
- package/dist/orchestration/log.js +3058 -0
- package/dist/orchestration/log.js.map +1 -0
- package/dist/orchestration/memory.d.ts +711 -0
- package/dist/orchestration/memory.js +27 -0
- package/dist/orchestration/memory.js.map +1 -0
- package/dist/provider-DX5Mf0uq.d.ts +151 -0
- package/dist/routing/index.d.ts +29 -0
- package/dist/routing/index.js +386 -0
- package/dist/routing/index.js.map +1 -0
- package/dist/routing/learning/index.d.ts +433 -0
- package/dist/routing/learning/index.js +2502 -0
- package/dist/routing/learning/index.js.map +1 -0
- package/dist/runtime-BSjrnxeF.d.ts +283 -0
- package/dist/runtime-OISPXS4I.js +19 -0
- package/dist/runtime-OISPXS4I.js.map +1 -0
- package/dist/store-types-2YdceOMy.d.ts +78 -0
- package/dist/types-BB7KqceP.d.ts +52 -0
- package/dist/types-CIqkKXix.d.ts +86 -0
- package/dist/types-DTFc1qO6.d.ts +1065 -0
- package/dist/types-DYex3p7_.d.ts +88 -0
- package/docs/licenses/ruflo-memory-MIT.txt +21 -0
- package/docs/releases/0.1.0-beta.3.md +13 -0
- package/package.json +114 -4
|
@@ -0,0 +1,854 @@
|
|
|
1
|
+
import { J as JsonValue } from '../types-DYex3p7_.js';
|
|
2
|
+
import { U as Usage, d as AgentOptions } from '../types-DTFc1qO6.js';
|
|
3
|
+
import { R as Runtime } from '../runtime-BSjrnxeF.js';
|
|
4
|
+
import { R as RuntimeErrorCode } from '../errors-BNHvvjn9.js';
|
|
5
|
+
import '../capture-runtime-GP6NZ2ee.js';
|
|
6
|
+
import '../types-BB7KqceP.js';
|
|
7
|
+
import '../provider-DX5Mf0uq.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Dynamic workflows: the public contract.
|
|
11
|
+
*
|
|
12
|
+
* A dynamic workflow is an orchestration the model (or the application) writes for one task at run time:
|
|
13
|
+
* which agents run, in what order, over which items, with what structured output. It then runs
|
|
14
|
+
* deterministically under limits the application sets, every agent call is journaled, and an interrupted
|
|
15
|
+
* run resumes from its journal without re-running the agents that already finished.
|
|
16
|
+
*
|
|
17
|
+
* Two authoring forms run on one engine:
|
|
18
|
+
* - a `DynamicWorkflowPlan`: JSON data a model can write safely (never code), validated before it runs;
|
|
19
|
+
* - a `DynamicWorkflowScript`: an application-written async function over `DynamicWorkflowContext`
|
|
20
|
+
* (`agent`, `parallel`, `pipeline`, `phase`, `log`, `budget`).
|
|
21
|
+
*
|
|
22
|
+
* Every agent call is a real `Agent` turn: a CLI process the SDK launches. Nothing here only records
|
|
23
|
+
* intent; a call either ran (and its turn is in the journal) or it did not.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
/** JSON Schema (draft-07, strict ajv: the same dialect as `TurnOptions.outputSchema`) for an agent's structured output. */
|
|
27
|
+
type DynamicJsonSchema = Record<string, unknown>;
|
|
28
|
+
/** The most an agent of the run may do; a plan or script can only narrow it, never widen it. */
|
|
29
|
+
type DynamicPermissionMode = 'analyze' | 'edit';
|
|
30
|
+
/** Options of one agent call, shared by plans and scripts. */
|
|
31
|
+
interface DynamicAgentOptions {
|
|
32
|
+
/** Short, unique within the run when given; shown in events and the journal. */
|
|
33
|
+
readonly label?: string;
|
|
34
|
+
/** Phase title (must be one of the declared phases when the workflow declares them). */
|
|
35
|
+
readonly phase?: string;
|
|
36
|
+
/** Structured output: the result is the parsed, schema-valid object; otherwise the turn text. */
|
|
37
|
+
readonly schema?: DynamicJsonSchema;
|
|
38
|
+
/** A model id the application allows (`DynamicLimits.models`); default: the application's default. */
|
|
39
|
+
readonly model?: string;
|
|
40
|
+
readonly effort?: string;
|
|
41
|
+
/** At most the run's ceiling; default 'analyze'. */
|
|
42
|
+
readonly permissions?: DynamicPermissionMode;
|
|
43
|
+
/** 'worktree' runs the agent in its own git worktree (requires `DynamicRunOptions.isolation`). */
|
|
44
|
+
readonly isolation?: 'none' | 'worktree';
|
|
45
|
+
/** Per-call timeout; at most `DynamicLimits.agentTimeoutMs`. */
|
|
46
|
+
readonly timeoutMs?: number;
|
|
47
|
+
}
|
|
48
|
+
/** A finished agent call as the journal keeps it and the caller receives it. */
|
|
49
|
+
interface DynamicAgentResult {
|
|
50
|
+
readonly key: string;
|
|
51
|
+
readonly label?: string;
|
|
52
|
+
readonly status: 'completed' | 'failed' | 'skipped';
|
|
53
|
+
/** Parsed object when a schema was given, else the turn text; `null` when failed or skipped. */
|
|
54
|
+
readonly output: JsonValue;
|
|
55
|
+
readonly usage?: Usage;
|
|
56
|
+
readonly durationMs: number;
|
|
57
|
+
/** Where an isolated agent worked; the application merges or discards it. */
|
|
58
|
+
readonly worktree?: {
|
|
59
|
+
readonly path: string;
|
|
60
|
+
readonly branch: string;
|
|
61
|
+
readonly changed: boolean;
|
|
62
|
+
};
|
|
63
|
+
/** Bounded, never provider text. */
|
|
64
|
+
readonly error?: {
|
|
65
|
+
readonly code: string;
|
|
66
|
+
readonly message: string;
|
|
67
|
+
};
|
|
68
|
+
/** True when replayed from the journal on resume. */
|
|
69
|
+
readonly cached: boolean;
|
|
70
|
+
}
|
|
71
|
+
/** The context a script receives. */
|
|
72
|
+
interface DynamicWorkflowContext {
|
|
73
|
+
readonly runId: string;
|
|
74
|
+
/** Read-only, JSON. */
|
|
75
|
+
readonly args: JsonValue;
|
|
76
|
+
/** Runs one agent; resolves to its output, or `null` when it failed (never rejects for agent failures). */
|
|
77
|
+
agent(prompt: string, options?: DynamicAgentOptions): Promise<JsonValue>;
|
|
78
|
+
/** Like `agent` but returns the full result record. */
|
|
79
|
+
agentResult(prompt: string, options?: DynamicAgentOptions): Promise<DynamicAgentResult>;
|
|
80
|
+
/** Runs thunks concurrently (bounded by the run's concurrency); a rejected thunk becomes `null`. */
|
|
81
|
+
parallel<T>(thunks: ReadonlyArray<() => Promise<T>>): Promise<Array<T | null>>;
|
|
82
|
+
/** Passes each item through every stage in order, items flowing independently (no barrier between stages). */
|
|
83
|
+
pipeline<T>(items: readonly T[], ...stages: ReadonlyArray<(value: any, item: T, index: number) => Promise<unknown>>): Promise<JsonValue[]>;
|
|
84
|
+
/** Marks the current phase (must be declared when phases are declared). */
|
|
85
|
+
phase(title: string): void;
|
|
86
|
+
/** A progress line for events; never sent to an agent. */
|
|
87
|
+
log(message: string): void;
|
|
88
|
+
readonly budget: {
|
|
89
|
+
readonly total?: number;
|
|
90
|
+
spent(): number;
|
|
91
|
+
remaining(): number | undefined;
|
|
92
|
+
};
|
|
93
|
+
readonly signal: AbortSignal;
|
|
94
|
+
}
|
|
95
|
+
type DynamicWorkflowScript = (context: DynamicWorkflowContext) => Promise<JsonValue>;
|
|
96
|
+
/** Declared up front, read without running anything (plans and scripts alike). */
|
|
97
|
+
interface DynamicWorkflowMeta {
|
|
98
|
+
readonly name: string;
|
|
99
|
+
readonly description: string;
|
|
100
|
+
readonly phases?: ReadonlyArray<{
|
|
101
|
+
readonly title: string;
|
|
102
|
+
readonly detail?: string;
|
|
103
|
+
}>;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* A template string. `{{args.<path>}}`, `{{steps.<id>}}` (a previous step's output, whole) and, inside
|
|
107
|
+
* a `map` step, `{{item}}` / `{{index}}` are the only substitutions. Substituted values are rendered as
|
|
108
|
+
* indented, labelled reference data, never spliced into the instruction text.
|
|
109
|
+
*/
|
|
110
|
+
type DynamicTemplate = string;
|
|
111
|
+
interface DynamicAgentStep extends Omit<DynamicAgentOptions, 'label'> {
|
|
112
|
+
readonly kind: 'agent';
|
|
113
|
+
readonly id: string;
|
|
114
|
+
readonly prompt: DynamicTemplate;
|
|
115
|
+
}
|
|
116
|
+
/** Fans one agent out over an array (a previous step's array output or an array in `args`). */
|
|
117
|
+
interface DynamicMapStep extends Omit<DynamicAgentOptions, 'label'> {
|
|
118
|
+
readonly kind: 'map';
|
|
119
|
+
readonly id: string;
|
|
120
|
+
/** `args.<path>` or `steps.<id>` (or `steps.<id>.<path>`) resolving to an array. */
|
|
121
|
+
readonly over: string;
|
|
122
|
+
readonly prompt: DynamicTemplate;
|
|
123
|
+
/** Items beyond this are refused before anything runs (never silently truncated). */
|
|
124
|
+
readonly maxItems?: number;
|
|
125
|
+
}
|
|
126
|
+
type DynamicPlanStep = DynamicAgentStep | DynamicMapStep;
|
|
127
|
+
interface DynamicWorkflowPlan {
|
|
128
|
+
readonly format: 1;
|
|
129
|
+
readonly meta: DynamicWorkflowMeta;
|
|
130
|
+
/** Steps run when every step they reference has finished; independent steps run concurrently. */
|
|
131
|
+
readonly steps: readonly DynamicPlanStep[];
|
|
132
|
+
/** The step whose output is the workflow's result; default: the last step. */
|
|
133
|
+
readonly result?: string;
|
|
134
|
+
}
|
|
135
|
+
/** Hard limits the application sets; a plan or script can never exceed them. */
|
|
136
|
+
interface DynamicLimits {
|
|
137
|
+
/**
|
|
138
|
+
* Agent calls per run: each `agent()` call counts once (cached replays included), however many attempts
|
|
139
|
+
* it takes; default 50, at most 1000. Attempts are bounded per call by `schemaRetries` and
|
|
140
|
+
* `rateLimitRetries`, and their cost by `tokens`.
|
|
141
|
+
*/
|
|
142
|
+
readonly maxAgents?: number;
|
|
143
|
+
/**
|
|
144
|
+
* Ceiling of concurrent agent calls; default 8, at most 16. The run adapts its window between 1 and this
|
|
145
|
+
* ceiling: it starts at `initialConcurrency`, is cut to floor(0.75 x window) (at least 1) when the provider
|
|
146
|
+
* rate-limits a call (RATE_LIMITED), and grows by 1 for each answered call while it is full
|
|
147
|
+
* (`concurrency.changed` events).
|
|
148
|
+
*/
|
|
149
|
+
readonly concurrency?: number;
|
|
150
|
+
/** Where the adaptive window starts; default min(4, `concurrency`), at most `concurrency`. */
|
|
151
|
+
readonly initialConcurrency?: number;
|
|
152
|
+
/** Items in one `map`/`pipeline`/`parallel`; default 256, at most 4096. */
|
|
153
|
+
readonly maxItems?: number;
|
|
154
|
+
/** Total tokens (input + output, as reported) the run may spend; once spent, further calls fail with BUDGET. */
|
|
155
|
+
readonly tokens?: number;
|
|
156
|
+
/** Per-attempt timeout ceiling (first turn, each schema and rate-limit retry); default 15 minutes, at most 24 hours. */
|
|
157
|
+
readonly agentTimeoutMs?: number;
|
|
158
|
+
/** Most an agent may do; default 'analyze'. */
|
|
159
|
+
readonly permissions?: DynamicPermissionMode;
|
|
160
|
+
/** Models an agent may name; absent means only the default model. */
|
|
161
|
+
readonly models?: readonly string[];
|
|
162
|
+
/** Retries of a schema-invalid structured output; default 2, at most 5. */
|
|
163
|
+
readonly schemaRetries?: number;
|
|
164
|
+
/**
|
|
165
|
+
* Retries of a call the provider rate-limited (RATE_LIMITED), each after an exponential backoff with
|
|
166
|
+
* jitter (at least until the provider's reset when the SDK reports one) during which the call holds no
|
|
167
|
+
* concurrency slot; default 3, at most 10. A reset further away than the call's timeout fails the call
|
|
168
|
+
* at once. Once spent, the call fails with RATE_LIMITED.
|
|
169
|
+
*/
|
|
170
|
+
readonly rateLimitRetries?: number;
|
|
171
|
+
}
|
|
172
|
+
/** Durable record of finished agent calls, keyed by call key; resume replays them. */
|
|
173
|
+
interface DynamicJournal {
|
|
174
|
+
/** Called once before the run's first call: take ownership, load the index. */
|
|
175
|
+
open?(runId: string): Promise<void>;
|
|
176
|
+
get(runId: string, key: string): Promise<DynamicAgentResult | undefined>;
|
|
177
|
+
put(runId: string, result: DynamicAgentResult): Promise<void>;
|
|
178
|
+
/** Called once when the run ends: release ownership. */
|
|
179
|
+
close?(runId: string): Promise<void>;
|
|
180
|
+
}
|
|
181
|
+
/** Creates and reports per-agent git worktrees; the application owns merging and cleanup. */
|
|
182
|
+
interface DynamicIsolation {
|
|
183
|
+
create(request: {
|
|
184
|
+
runId: string;
|
|
185
|
+
key: string;
|
|
186
|
+
label?: string;
|
|
187
|
+
signal: AbortSignal;
|
|
188
|
+
}): Promise<{
|
|
189
|
+
path: string;
|
|
190
|
+
branch: string;
|
|
191
|
+
}>;
|
|
192
|
+
/** Whether the agent changed anything there; called after the agent finished. */
|
|
193
|
+
inspect(worktree: {
|
|
194
|
+
path: string;
|
|
195
|
+
branch: string;
|
|
196
|
+
}): Promise<{
|
|
197
|
+
changed: boolean;
|
|
198
|
+
}>;
|
|
199
|
+
}
|
|
200
|
+
/** What the engine needs to run one agent call: the application builds the Agent (its runtime, cwd, auth). */
|
|
201
|
+
interface DynamicAgentRequest {
|
|
202
|
+
readonly runId: string;
|
|
203
|
+
readonly key: string;
|
|
204
|
+
readonly prompt: string;
|
|
205
|
+
readonly options: DynamicAgentOptions & {
|
|
206
|
+
readonly permissions: DynamicPermissionMode;
|
|
207
|
+
};
|
|
208
|
+
/** Set when the call is isolated. */
|
|
209
|
+
readonly cwd?: string;
|
|
210
|
+
readonly signal: AbortSignal;
|
|
211
|
+
}
|
|
212
|
+
interface DynamicAgentRunner {
|
|
213
|
+
/**
|
|
214
|
+
* Runs one turn and returns its text, structured output (when a schema was asked) and usage. Must
|
|
215
|
+
* settle promptly once `request.signal` aborts: the engine relies on it for timeouts, abort and slots.
|
|
216
|
+
*/
|
|
217
|
+
run(request: DynamicAgentRequest): Promise<{
|
|
218
|
+
text: string;
|
|
219
|
+
output?: JsonValue;
|
|
220
|
+
usage?: Usage;
|
|
221
|
+
}>;
|
|
222
|
+
}
|
|
223
|
+
type DynamicWorkflowEvent = {
|
|
224
|
+
type: 'run.started';
|
|
225
|
+
runId: string;
|
|
226
|
+
meta: DynamicWorkflowMeta;
|
|
227
|
+
at: string;
|
|
228
|
+
} | {
|
|
229
|
+
type: 'phase.started';
|
|
230
|
+
runId: string;
|
|
231
|
+
title: string;
|
|
232
|
+
at: string;
|
|
233
|
+
} | {
|
|
234
|
+
type: 'agent.started';
|
|
235
|
+
runId: string;
|
|
236
|
+
key: string;
|
|
237
|
+
label?: string;
|
|
238
|
+
phase?: string;
|
|
239
|
+
at: string;
|
|
240
|
+
} | {
|
|
241
|
+
type: 'agent.finished';
|
|
242
|
+
runId: string;
|
|
243
|
+
result: Omit<DynamicAgentResult, 'output'>;
|
|
244
|
+
at: string;
|
|
245
|
+
} | {
|
|
246
|
+
type: 'log';
|
|
247
|
+
runId: string;
|
|
248
|
+
message: string;
|
|
249
|
+
at: string;
|
|
250
|
+
} | {
|
|
251
|
+
type: 'budget';
|
|
252
|
+
runId: string;
|
|
253
|
+
spent: number;
|
|
254
|
+
total?: number;
|
|
255
|
+
at: string;
|
|
256
|
+
}
|
|
257
|
+
/** The adaptive concurrency window changed: cut on a rate limit, or grown after an answered call while full. */
|
|
258
|
+
| {
|
|
259
|
+
type: 'concurrency.changed';
|
|
260
|
+
runId: string;
|
|
261
|
+
previous: number;
|
|
262
|
+
window: number;
|
|
263
|
+
ceiling: number;
|
|
264
|
+
reason: 'rate-limited' | 'recovered';
|
|
265
|
+
at: string;
|
|
266
|
+
} | {
|
|
267
|
+
type: 'run.finished';
|
|
268
|
+
runId: string;
|
|
269
|
+
status: DynamicRunStatus;
|
|
270
|
+
agents: number;
|
|
271
|
+
spent: number;
|
|
272
|
+
at: string;
|
|
273
|
+
};
|
|
274
|
+
type DynamicRunStatus = 'completed' | 'failed' | 'aborted' | 'budget-exhausted';
|
|
275
|
+
interface DynamicRunOptions {
|
|
276
|
+
/** Identifies the run; reusing it resumes from the journal. */
|
|
277
|
+
readonly runId: string;
|
|
278
|
+
readonly runner: DynamicAgentRunner;
|
|
279
|
+
readonly journal?: DynamicJournal;
|
|
280
|
+
readonly isolation?: DynamicIsolation;
|
|
281
|
+
readonly limits?: DynamicLimits;
|
|
282
|
+
readonly args?: JsonValue;
|
|
283
|
+
readonly signal?: AbortSignal;
|
|
284
|
+
readonly onEvent?: (event: DynamicWorkflowEvent) => void;
|
|
285
|
+
}
|
|
286
|
+
/** The engine entry (engine.ts). */
|
|
287
|
+
type RunWorkflowScript = (meta: DynamicWorkflowMeta, script: DynamicWorkflowScript, options: DynamicRunOptions) => Promise<DynamicRunReport>;
|
|
288
|
+
/** A validated plan compiled to the script the engine runs (plan-compile.ts). */
|
|
289
|
+
type CompilePlan = (plan: DynamicWorkflowPlan, limits?: DynamicLimits) => {
|
|
290
|
+
readonly meta: DynamicWorkflowMeta;
|
|
291
|
+
readonly script: DynamicWorkflowScript;
|
|
292
|
+
};
|
|
293
|
+
interface DynamicRunReport {
|
|
294
|
+
readonly runId: string;
|
|
295
|
+
readonly status: DynamicRunStatus;
|
|
296
|
+
readonly result: JsonValue;
|
|
297
|
+
readonly agents: readonly Omit<DynamicAgentResult, 'output'>[];
|
|
298
|
+
readonly spent: number;
|
|
299
|
+
/** Bounded, never provider text. */
|
|
300
|
+
readonly error?: {
|
|
301
|
+
readonly code: string;
|
|
302
|
+
readonly message: string;
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/** The time source of rate-limit backoff waits; default real time (`Date.now`, `setTimeout`). */
|
|
307
|
+
interface DynamicClock {
|
|
308
|
+
/** Epoch milliseconds, the same clock as a provider `retryAt`. */
|
|
309
|
+
now(): number;
|
|
310
|
+
/** Resolves after `ms`; rejects promptly once `signal` aborts. */
|
|
311
|
+
sleep(ms: number, signal: AbortSignal): Promise<void>;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* Dynamic workflows: limits, meta and per-call option validation.
|
|
316
|
+
*
|
|
317
|
+
* Everything here is synchronous and pure, so an invalid limit, meta or agent option is refused with a
|
|
318
|
+
* `TypeError` before anything runs. Errors raised here are SDK-authored; the engine may surface their
|
|
319
|
+
* message in a report (`isDynamicUsageError`), never a provider's text.
|
|
320
|
+
*/
|
|
321
|
+
|
|
322
|
+
/** Defaults and hard ceilings of `DynamicLimits` (the contract's JSDoc). */
|
|
323
|
+
declare const DYNAMIC_LIMIT_BOUNDS: Readonly<{
|
|
324
|
+
maxAgents: Readonly<{
|
|
325
|
+
min: 1;
|
|
326
|
+
default: 50;
|
|
327
|
+
max: 1000;
|
|
328
|
+
}>;
|
|
329
|
+
/** The ceiling of the adaptive window. */
|
|
330
|
+
concurrency: Readonly<{
|
|
331
|
+
min: 1;
|
|
332
|
+
default: 8;
|
|
333
|
+
max: 16;
|
|
334
|
+
}>;
|
|
335
|
+
/** Where the window starts; the default is min(4, concurrency) and it may never exceed `concurrency`. */
|
|
336
|
+
initialConcurrency: Readonly<{
|
|
337
|
+
min: 1;
|
|
338
|
+
default: 4;
|
|
339
|
+
max: 16;
|
|
340
|
+
}>;
|
|
341
|
+
maxItems: Readonly<{
|
|
342
|
+
min: 1;
|
|
343
|
+
default: 256;
|
|
344
|
+
max: 4096;
|
|
345
|
+
}>;
|
|
346
|
+
schemaRetries: Readonly<{
|
|
347
|
+
min: 0;
|
|
348
|
+
default: 2;
|
|
349
|
+
max: 5;
|
|
350
|
+
}>;
|
|
351
|
+
rateLimitRetries: Readonly<{
|
|
352
|
+
min: 0;
|
|
353
|
+
default: 3;
|
|
354
|
+
max: 10;
|
|
355
|
+
}>;
|
|
356
|
+
/** 15 minutes by default; 24 hours at most (beyond that a timer is no longer a meaningful bound). */
|
|
357
|
+
agentTimeoutMs: Readonly<{
|
|
358
|
+
min: 1;
|
|
359
|
+
default: number;
|
|
360
|
+
max: number;
|
|
361
|
+
}>;
|
|
362
|
+
}>;
|
|
363
|
+
interface ResolvedDynamicLimits {
|
|
364
|
+
readonly maxAgents: number;
|
|
365
|
+
readonly concurrency: number;
|
|
366
|
+
readonly initialConcurrency: number;
|
|
367
|
+
readonly maxItems: number;
|
|
368
|
+
readonly tokens: number | undefined;
|
|
369
|
+
readonly agentTimeoutMs: number;
|
|
370
|
+
readonly permissions: DynamicPermissionMode;
|
|
371
|
+
readonly models: readonly string[];
|
|
372
|
+
readonly schemaRetries: number;
|
|
373
|
+
readonly rateLimitRetries: number;
|
|
374
|
+
}
|
|
375
|
+
/** Validates the application's limits and fills the defaults; out-of-range values are refused, never clamped. */
|
|
376
|
+
declare function resolveDynamicLimits(limits: DynamicLimits | undefined): ResolvedDynamicLimits;
|
|
377
|
+
/** Validates and copies the workflow's meta: labelled name, description, unique declared phases. */
|
|
378
|
+
declare function validateDynamicMeta(meta: DynamicWorkflowMeta): DynamicWorkflowMeta;
|
|
379
|
+
|
|
380
|
+
/** A host-wide launch cap (for example an adapter over `SharedLaunchBudget`): held while an agent runs. */
|
|
381
|
+
interface DynamicLaunchGate {
|
|
382
|
+
acquire(signal: AbortSignal): Promise<{
|
|
383
|
+
release(): void | Promise<void>;
|
|
384
|
+
}>;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
/** Engine-wide options (not per run), shared by every run of this engine. */
|
|
388
|
+
interface DynamicEngineOptions {
|
|
389
|
+
/**
|
|
390
|
+
* Held from just before an agent attempt starts until its runner settles (given up while a rate-limited
|
|
391
|
+
* call backs off); a refusal fails the call with LAUNCH.
|
|
392
|
+
*/
|
|
393
|
+
readonly launch?: DynamicLaunchGate;
|
|
394
|
+
/** The time source of rate-limit backoff waits (tests, simulations); default real time. */
|
|
395
|
+
readonly clock?: DynamicClock;
|
|
396
|
+
}
|
|
397
|
+
/** Builds an engine; `createDynamicEngine({ launch })` adds a host-wide launch gate. */
|
|
398
|
+
declare function createDynamicEngine(engine?: DynamicEngineOptions): RunWorkflowScript;
|
|
399
|
+
/** The default engine (no launch gate). */
|
|
400
|
+
declare const runWorkflowScript: RunWorkflowScript;
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
* Dynamic workflows: journal records, run ids, journal errors and the optional journal lifecycle.
|
|
404
|
+
*/
|
|
405
|
+
|
|
406
|
+
/** Optional lifecycle the engine honours when a journal implements it. */
|
|
407
|
+
interface DynamicJournalLifecycle {
|
|
408
|
+
/** Claims the run for this writer and loads its records; rejects when another writer holds it or it is corrupt. */
|
|
409
|
+
open?(runId: string): Promise<void>;
|
|
410
|
+
/** Flushes pending writes and releases the run. */
|
|
411
|
+
close?(runId: string): Promise<void>;
|
|
412
|
+
}
|
|
413
|
+
type ManagedDynamicJournal = DynamicJournal & Required<DynamicJournalLifecycle>;
|
|
414
|
+
/** Thrown when another writer holds the run (inspect the lock; there is no automatic expiry). */
|
|
415
|
+
declare class DynamicJournalLockedError extends Error {
|
|
416
|
+
readonly runId: string;
|
|
417
|
+
readonly lockPath?: string | undefined;
|
|
418
|
+
constructor(runId: string, lockPath?: string | undefined);
|
|
419
|
+
}
|
|
420
|
+
/** Thrown when a journal line other than a torn last line fails its checksum or shape; the run is refused. */
|
|
421
|
+
declare class DynamicJournalCorruptError extends Error {
|
|
422
|
+
readonly runId: string;
|
|
423
|
+
readonly line: number;
|
|
424
|
+
constructor(runId: string, line: number);
|
|
425
|
+
}
|
|
426
|
+
/**
|
|
427
|
+
* Thrown by every `put` after an append failed and the journal could not cut the file back to its last
|
|
428
|
+
* complete record: nothing more is written in this session. Close the run and open it again (the partial
|
|
429
|
+
* tail is then dropped as a torn write).
|
|
430
|
+
*/
|
|
431
|
+
declare class DynamicJournalWriteError extends Error {
|
|
432
|
+
readonly runId: string;
|
|
433
|
+
constructor(runId: string);
|
|
434
|
+
}
|
|
435
|
+
/** Run ids name journal files: `^[A-Za-z0-9._-]{1,128}$`, never `.` or `..`. */
|
|
436
|
+
declare function validateDynamicRunId(runId: unknown): string;
|
|
437
|
+
|
|
438
|
+
interface DynamicJournalOwner {
|
|
439
|
+
readonly format: 1;
|
|
440
|
+
readonly runId: string;
|
|
441
|
+
readonly token: string;
|
|
442
|
+
readonly pid: number;
|
|
443
|
+
readonly host: string;
|
|
444
|
+
}
|
|
445
|
+
interface FileDynamicJournal extends ManagedDynamicJournal {
|
|
446
|
+
readonly directory: string;
|
|
447
|
+
/** The writer that holds the run, if any (read-only; never changes the lock). */
|
|
448
|
+
inspectOwner(runId: string): Promise<DynamicJournalOwner | undefined>;
|
|
449
|
+
/**
|
|
450
|
+
* Explicit crash recovery, never based on age: removes a lock whose owner process is gone. Refuses a
|
|
451
|
+
* live PID, another host or a changed token. The caller asserts the owner's agents have stopped.
|
|
452
|
+
* Recoverers of one token are serialized by a claim file (`<runId>.lock.recovering-<token>.<n>`),
|
|
453
|
+
* and the lock is re-read under it, so a new owner's lock is never removed and only one recoverer
|
|
454
|
+
* succeeds; a concurrent one is refused ("in progress"). A recovery interrupted at any point (its
|
|
455
|
+
* process killed) is completed by calling this again with the same token: the dead recoverer's
|
|
456
|
+
* claim is stepped over, and if it had already removed the lock the call just resolves. A tombstone
|
|
457
|
+
* (`<runId>.lock.recovered-<token>`) is kept as a record. Once the recovery finished cleanly, or a
|
|
458
|
+
* new owner holds the run, the old token is refused ("token changed").
|
|
459
|
+
*/
|
|
460
|
+
recoverAbandoned(runId: string, expectedToken: string, acknowledgement: {
|
|
461
|
+
ownerStopped: true;
|
|
462
|
+
}): Promise<void>;
|
|
463
|
+
}
|
|
464
|
+
/** A durable, single-writer journal in `directory` (created 0700 when missing). */
|
|
465
|
+
declare function fileDynamicJournal(directory: string): FileDynamicJournal;
|
|
466
|
+
|
|
467
|
+
/**
|
|
468
|
+
* In-process journal: records live in memory (lost with the process). `open`/`close` give the same
|
|
469
|
+
* one-writer-per-run rule as the file journal, within this process.
|
|
470
|
+
*/
|
|
471
|
+
declare function memoryDynamicJournal(): ManagedDynamicJournal;
|
|
472
|
+
|
|
473
|
+
/** Hard bounds of a plan, whatever the limits say. */
|
|
474
|
+
declare const PLAN_BOUNDS: Readonly<{
|
|
475
|
+
steps: 256;
|
|
476
|
+
phases: 32;
|
|
477
|
+
promptBytes: number;
|
|
478
|
+
schemaBytes: number;
|
|
479
|
+
nameChars: 128;
|
|
480
|
+
descriptionChars: 2000;
|
|
481
|
+
overChars: 256;
|
|
482
|
+
}>;
|
|
483
|
+
/** JSON Schema of a `DynamicWorkflowPlan`, for a planner's structured output. `validatePlan` is the authority. */
|
|
484
|
+
declare const DYNAMIC_PLAN_JSON_SCHEMA: Readonly<Record<string, unknown>>;
|
|
485
|
+
|
|
486
|
+
/**
|
|
487
|
+
* Plan validation: a plan is JSON a model may write, so it is checked as untrusted input before anything
|
|
488
|
+
* runs. Every object is closed (an unknown key anywhere is an error), every string is bounded, every
|
|
489
|
+
* reference resolves, the step graph is acyclic and nothing exceeds the application's `DynamicLimits`.
|
|
490
|
+
*/
|
|
491
|
+
/** The limits a plan is checked against, with the contract's defaults applied. */
|
|
492
|
+
interface PlanLimits {
|
|
493
|
+
readonly maxAgents: number;
|
|
494
|
+
readonly maxItems: number;
|
|
495
|
+
readonly agentTimeoutMs: number;
|
|
496
|
+
readonly permissions: DynamicPermissionMode;
|
|
497
|
+
readonly models: readonly string[];
|
|
498
|
+
}
|
|
499
|
+
/** The plan's steps in dependency waves: each wave's steps depend only on earlier waves. */
|
|
500
|
+
declare function planWaves(plan: DynamicWorkflowPlan): DynamicPlanStep[][];
|
|
501
|
+
/**
|
|
502
|
+
* Validates a plan and returns a frozen, typed copy holding only the known keys. Throws `DynamicPlanError`
|
|
503
|
+
* listing every issue found (code + JSON path). `limits` are the run's limits: a plan never exceeds them.
|
|
504
|
+
*/
|
|
505
|
+
declare function validatePlan(value: unknown, limits?: DynamicLimits): DynamicWorkflowPlan;
|
|
506
|
+
type DynamicAgentCount = number | 'unknown-until-run';
|
|
507
|
+
interface DynamicPlanEstimate {
|
|
508
|
+
/** Agent calls of a full run: exact when every map is over `args`, else 'unknown-until-run'. */
|
|
509
|
+
readonly agents: DynamicAgentCount;
|
|
510
|
+
/** Agent calls known now (maps over earlier outputs count 0). */
|
|
511
|
+
readonly minAgents: number;
|
|
512
|
+
/** Most agent calls the limits allow (each unknown map at its item ceiling). */
|
|
513
|
+
readonly maxAgents: number;
|
|
514
|
+
/** Dependency waves (sequential stages). */
|
|
515
|
+
readonly waves: number;
|
|
516
|
+
readonly steps: ReadonlyArray<{
|
|
517
|
+
readonly id: string;
|
|
518
|
+
readonly kind: 'agent' | 'map';
|
|
519
|
+
readonly phase?: string;
|
|
520
|
+
readonly agents: DynamicAgentCount;
|
|
521
|
+
}>;
|
|
522
|
+
readonly phases: ReadonlyArray<{
|
|
523
|
+
readonly title: string;
|
|
524
|
+
readonly agents: DynamicAgentCount;
|
|
525
|
+
}>;
|
|
526
|
+
}
|
|
527
|
+
/**
|
|
528
|
+
* Cost projection of a validated plan, without running anything. A map over `args` is counted from
|
|
529
|
+
* `args`; one that is not an array or holds more items than allowed throws `DynamicPlanError` now,
|
|
530
|
+
* as the run would refuse it before its first call.
|
|
531
|
+
*/
|
|
532
|
+
declare function estimatePlan(plan: DynamicWorkflowPlan, args?: JsonValue, limits?: DynamicLimits): DynamicPlanEstimate;
|
|
533
|
+
/**
|
|
534
|
+
* Checks a validated plan against the run's args before anything runs: every `{{args.<path>}}` names a
|
|
535
|
+
* value and every map over `args` is an array within its item ceiling. Throws `DynamicPlanError`.
|
|
536
|
+
*/
|
|
537
|
+
declare function checkPlanArgs(plan: DynamicWorkflowPlan, args: JsonValue | undefined, limits?: DynamicLimits): void;
|
|
538
|
+
|
|
539
|
+
/** Typed errors of dynamic workflow plans: validation, template rendering and the planner. */
|
|
540
|
+
type DynamicPlanErrorCode = 'NOT_JSON' | 'SHAPE' | 'UNKNOWN_KEY' | 'MISSING' | 'TYPE' | 'FORMAT' | 'LABEL' | 'ID' | 'DUPLICATE' | 'TEMPLATE' | 'REFERENCE' | 'CYCLE' | 'PHASE' | 'PERMISSIONS' | 'MODEL' | 'LIMIT' | 'SCHEMA' | 'SCHEMA_PATTERN' | 'RESULT' | 'MISSING_VALUE' | 'OVER_NOT_ARRAY' | 'MAX_ITEMS' | 'PROMPT_TOO_LARGE';
|
|
541
|
+
/** One problem, located by a JSON path into the plan (`$.steps[2].prompt`). */
|
|
542
|
+
interface DynamicPlanIssue {
|
|
543
|
+
readonly code: DynamicPlanErrorCode;
|
|
544
|
+
readonly path: string;
|
|
545
|
+
readonly message: string;
|
|
546
|
+
}
|
|
547
|
+
/**
|
|
548
|
+
* A plan that cannot be accepted or run. `code` and `path` are the first issue; `issues` holds every
|
|
549
|
+
* issue found (validation keeps going after the first one, up to a bound), so a planner can repair them all.
|
|
550
|
+
*/
|
|
551
|
+
declare class DynamicPlanError extends Error {
|
|
552
|
+
readonly code: DynamicPlanErrorCode;
|
|
553
|
+
readonly path: string;
|
|
554
|
+
readonly issues: readonly DynamicPlanIssue[];
|
|
555
|
+
constructor(issues: readonly DynamicPlanIssue[]);
|
|
556
|
+
static of(code: DynamicPlanErrorCode, path: string, message: string): DynamicPlanError;
|
|
557
|
+
}
|
|
558
|
+
/** The planner gave up: every attempt (the first and each repair) produced an invalid plan. */
|
|
559
|
+
declare class DynamicPlannerError extends Error {
|
|
560
|
+
readonly attempts: number;
|
|
561
|
+
readonly issues: readonly DynamicPlanIssue[];
|
|
562
|
+
readonly code: "PLAN_INVALID";
|
|
563
|
+
constructor(attempts: number, issues: readonly DynamicPlanIssue[]);
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
declare const compilePlan: CompilePlan;
|
|
567
|
+
|
|
568
|
+
/**
|
|
569
|
+
* Plan templates.
|
|
570
|
+
*
|
|
571
|
+
* The only substitutions are `{{args.<path>}}`, `{{steps.<id>}}`, `{{steps.<id>.<path>}}`, `{{item}}`,
|
|
572
|
+
* `{{item.<path>}}` and `{{index}}`. Any other `{{…}}` (or an unclosed `{{`) is an error, found when the
|
|
573
|
+
* plan is validated. A path is dot-separated: names (`files`, `max-depth`) or array indexes (`0`, `12`).
|
|
574
|
+
*
|
|
575
|
+
* A substituted value is never spliced into the instruction text. It renders as a labelled data block:
|
|
576
|
+
* a `[data: <reference>]` header on its own line, then every line of the value (a string as is, anything
|
|
577
|
+
* else as indented JSON) indented by four spaces. A value therefore never starts a line at column zero,
|
|
578
|
+
* so it cannot forge a heading, an instruction or another block header, and values are never re-scanned
|
|
579
|
+
* for placeholders: a `{{…}}` inside a value is inert text.
|
|
580
|
+
*/
|
|
581
|
+
type TemplateReference = {
|
|
582
|
+
readonly kind: 'args';
|
|
583
|
+
readonly path: readonly string[];
|
|
584
|
+
readonly source: string;
|
|
585
|
+
} | {
|
|
586
|
+
readonly kind: 'steps';
|
|
587
|
+
readonly step: string;
|
|
588
|
+
readonly path: readonly string[];
|
|
589
|
+
readonly source: string;
|
|
590
|
+
} | {
|
|
591
|
+
readonly kind: 'item';
|
|
592
|
+
readonly path: readonly string[];
|
|
593
|
+
readonly source: string;
|
|
594
|
+
} | {
|
|
595
|
+
readonly kind: 'index';
|
|
596
|
+
readonly path: readonly string[];
|
|
597
|
+
readonly source: string;
|
|
598
|
+
};
|
|
599
|
+
interface TemplateScope {
|
|
600
|
+
readonly args: JsonValue | undefined;
|
|
601
|
+
/** Outputs of finished steps by id (`null` for a failed agent). */
|
|
602
|
+
readonly steps: Readonly<Record<string, JsonValue>>;
|
|
603
|
+
/** Set inside a `map` step only. */
|
|
604
|
+
readonly item?: JsonValue;
|
|
605
|
+
readonly index?: number;
|
|
606
|
+
}
|
|
607
|
+
/** Default bound of one rendered prompt, in UTF-8 bytes. */
|
|
608
|
+
declare const MAX_RENDERED_PROMPT_BYTES: number;
|
|
609
|
+
/**
|
|
610
|
+
* Every placeholder of a template, in order. Throws `DynamicPlanError` (code TEMPLATE, path `$`) for an
|
|
611
|
+
* unknown or malformed placeholder; the validator relocates the path to the template's field.
|
|
612
|
+
*/
|
|
613
|
+
declare function templateReferences(template: string): TemplateReference[];
|
|
614
|
+
/**
|
|
615
|
+
* Renders a template against a scope. Substitutions become data blocks (see the module comment); when
|
|
616
|
+
* there is at least one, `DATA_NOTE` precedes the prompt. Throws `DynamicPlanError` for a malformed
|
|
617
|
+
* template (TEMPLATE), a value the scope does not have (MISSING_VALUE) or a rendered prompt over
|
|
618
|
+
* `maxBytes` UTF-8 bytes (PROMPT_TOO_LARGE).
|
|
619
|
+
*/
|
|
620
|
+
declare function renderTemplate(template: string, scope: TemplateScope, options?: {
|
|
621
|
+
maxBytes?: number;
|
|
622
|
+
}): string;
|
|
623
|
+
|
|
624
|
+
/** The planner's fixed instructions; the application's guidance is appended after them. */
|
|
625
|
+
declare const PLANNER_INSTRUCTIONS: string;
|
|
626
|
+
|
|
627
|
+
/**
|
|
628
|
+
* A model writes the plan; the application approves and runs it.
|
|
629
|
+
*
|
|
630
|
+
* `planWorkflow` builds a restricted Agent for each attempt and closes it afterwards, with the same
|
|
631
|
+
* discipline as the memory curator's distiller: `permissions: { mode: 'analyze' }`, the exec transport,
|
|
632
|
+
* `context: { profile: 'clean', memory: 'off' }`, `memory: false`, no application tools, no pinned
|
|
633
|
+
* constraints, and for Claude `providerOptions.claude = { tools: [], strictMcpConfig: true }` (`--tools ""`
|
|
634
|
+
* and `--strict-mcp-config` without an MCP config: no built-in tool and no MCP server). Options that would
|
|
635
|
+
* change any of that are refused with a TypeError. Any provider other than Claude is refused unless the
|
|
636
|
+
* caller passes `allowProviderReadTools: true`, accepting that the CLI keeps its read tools.
|
|
637
|
+
*
|
|
638
|
+
* The goal reaches the model as an indented, labelled data block, never as instructions; the limits are
|
|
639
|
+
* stated in the prompt and enforced by `validatePlan`. A reply that is not JSON or not a valid plan is
|
|
640
|
+
* sent back with every validation error, up to `maxRepairs` times; after that `DynamicPlannerError`.
|
|
641
|
+
* The planner never runs the plan.
|
|
642
|
+
*
|
|
643
|
+
* The Agent class is loaded on the first call, so importing this module does not load the runtime.
|
|
644
|
+
*/
|
|
645
|
+
/** The Agent options a planner may set; everything that grants tools, permissions, context or memory is excluded. */
|
|
646
|
+
type PlannerAgentOptions = Omit<AgentOptions, 'tools' | 'permissions' | 'memory' | 'pinned' | 'instructions' | 'providerOptions' | 'transport' | 'context'> & {
|
|
647
|
+
/** Only `exec`, which is forced anyway. */
|
|
648
|
+
transport?: 'exec';
|
|
649
|
+
/** Only the clean profile with provider memory off, which is forced anyway. */
|
|
650
|
+
context?: {
|
|
651
|
+
profile?: 'clean';
|
|
652
|
+
memory?: 'off';
|
|
653
|
+
};
|
|
654
|
+
};
|
|
655
|
+
interface PlanWorkflowOptions {
|
|
656
|
+
/** What the workflow should achieve; untrusted data for the planner. */
|
|
657
|
+
goal: string;
|
|
658
|
+
agent: PlannerAgentOptions;
|
|
659
|
+
/** Runtime the planner's Agents run on. Default: the SDK's default runtime. */
|
|
660
|
+
runtime?: Runtime;
|
|
661
|
+
/** The limits the plan will run under; stated in the prompt and enforced by validation. */
|
|
662
|
+
limits?: DynamicLimits;
|
|
663
|
+
/** The run's args: the planner sees their shape (paths and types, never values); the estimate counts maps over them. */
|
|
664
|
+
args?: JsonValue;
|
|
665
|
+
/** Application guidance appended to the fixed instructions. */
|
|
666
|
+
instructions?: string;
|
|
667
|
+
/** Required for a provider other than Claude: that CLI keeps its read tools. Default false. */
|
|
668
|
+
allowProviderReadTools?: boolean;
|
|
669
|
+
/** Re-asks after an invalid reply: integer 0..5, default 2. */
|
|
670
|
+
maxRepairs?: number;
|
|
671
|
+
/** Deadline of each planner turn in milliseconds. Default: 300 000. */
|
|
672
|
+
timeoutMs?: number;
|
|
673
|
+
/** Ask through `outputSchema` (default true); false parses the turn text strictly instead. */
|
|
674
|
+
structuredOutput?: boolean;
|
|
675
|
+
signal?: AbortSignal;
|
|
676
|
+
}
|
|
677
|
+
interface PlannedWorkflow {
|
|
678
|
+
readonly plan: DynamicWorkflowPlan;
|
|
679
|
+
readonly estimate: DynamicPlanEstimate;
|
|
680
|
+
/** Planner turns used: 1 plus the repairs. */
|
|
681
|
+
readonly attempts: number;
|
|
682
|
+
}
|
|
683
|
+
declare function planWorkflow(input: PlanWorkflowOptions): Promise<PlannedWorkflow>;
|
|
684
|
+
|
|
685
|
+
/**
|
|
686
|
+
* Dynamic workflows: the closed error of agent runners.
|
|
687
|
+
*
|
|
688
|
+
* Shared by the bundled `agentRunner` (which throws it) and the engine (which reports its closed code and
|
|
689
|
+
* counts its usage). Type-only imports: loading this module never loads the runtime.
|
|
690
|
+
*/
|
|
691
|
+
|
|
692
|
+
type DynamicRunnerErrorCode =
|
|
693
|
+
/** The request named a model outside the allowlist. Nothing ran. */
|
|
694
|
+
'MODEL_NOT_ALLOWED'
|
|
695
|
+
/** The request asked for permissions above the runner's ceiling. Nothing ran. */
|
|
696
|
+
| 'PERMISSION_DENIED'
|
|
697
|
+
/** The request was malformed (prompt, cwd, effort, timeout). Nothing ran. */
|
|
698
|
+
| 'INVALID_REQUEST' | 'TIMEOUT' | 'ABORTED'
|
|
699
|
+
/** The turn ended with a native provider refusal. */
|
|
700
|
+
| 'REFUSED'
|
|
701
|
+
/** The provider or transport cannot run this request (unknown model, missing capability, unenforceable policy). */
|
|
702
|
+
| 'UNSUPPORTED'
|
|
703
|
+
/** The provider's structured output was missing or not JSON. The engine re-asks it like a schema mismatch. */
|
|
704
|
+
| 'OUTPUT_INVALID'
|
|
705
|
+
/**
|
|
706
|
+
* The provider rate-limited or usage-limited the turn (the SDK's `USAGE_LIMIT`). The engine shrinks the
|
|
707
|
+
* run's concurrency window and retries the call after a backoff, up to `DynamicLimits.rateLimitRetries`.
|
|
708
|
+
*/
|
|
709
|
+
| 'RATE_LIMITED' | 'PROVIDER_FAILED';
|
|
710
|
+
/**
|
|
711
|
+
* Message: fixed per code, plus the SDK runtime code when there is one; `cause` keeps the original for the
|
|
712
|
+
* application's own diagnostics. `usage` is what the failed turn spent as the provider reported it (a
|
|
713
|
+
* rejected structured output, a refusal, a provider failure): the engine counts it against the run budget.
|
|
714
|
+
* `retryAt` (RATE_LIMITED only) is the provider-reported reset in epoch milliseconds, when the SDK confirmed
|
|
715
|
+
* one: the engine waits at least until then before retrying, or fails the call when it is too far away.
|
|
716
|
+
*/
|
|
717
|
+
declare class DynamicRunnerError extends Error {
|
|
718
|
+
readonly code: DynamicRunnerErrorCode;
|
|
719
|
+
/** The SDK's closed `AgentRuntimeError` code that led here, when any. */
|
|
720
|
+
readonly runtimeCode?: RuntimeErrorCode;
|
|
721
|
+
/** Provider-reported usage of the failed turn, when known. */
|
|
722
|
+
readonly usage?: Usage;
|
|
723
|
+
/** RATE_LIMITED only: the provider-reported reset (epoch ms), when known. */
|
|
724
|
+
readonly retryAt?: number;
|
|
725
|
+
constructor(code: DynamicRunnerErrorCode, options?: {
|
|
726
|
+
runtimeCode?: RuntimeErrorCode;
|
|
727
|
+
detail?: string;
|
|
728
|
+
cause?: unknown;
|
|
729
|
+
usage?: Usage;
|
|
730
|
+
retryAt?: number;
|
|
731
|
+
});
|
|
732
|
+
}
|
|
733
|
+
|
|
734
|
+
interface AgentRunnerOptions {
|
|
735
|
+
/** The application's base Agent options; `model` is the default model of the workflow's agents. */
|
|
736
|
+
agent: AgentOptions;
|
|
737
|
+
/** Runtime the Agents run on. Default: the SDK's default runtime. */
|
|
738
|
+
runtime?: Runtime;
|
|
739
|
+
/** Most an agent may do. Default 'analyze'. */
|
|
740
|
+
ceiling?: DynamicPermissionMode;
|
|
741
|
+
/** Models a request may name besides the base model. Absent: only the base model. */
|
|
742
|
+
models?: readonly string[];
|
|
743
|
+
/** Close each Agent after its turn. Default true; false skips `close()` (and its wait for memory captures). */
|
|
744
|
+
closeAgents?: boolean;
|
|
745
|
+
}
|
|
746
|
+
declare function agentRunner(input: AgentRunnerOptions): DynamicAgentRunner;
|
|
747
|
+
|
|
748
|
+
/** Helpers of `gitWorktreeIsolation`: the git process wrapper, name validation and path checks. */
|
|
749
|
+
type DynamicIsolationErrorCode =
|
|
750
|
+
/** A runId, key, ref, prefix or path that is not allowed. Nothing ran. */
|
|
751
|
+
'INVALID_INPUT' | 'NOT_A_REPOSITORY'
|
|
752
|
+
/** The worktree root is inside the repository's working tree and not ignored by git. */
|
|
753
|
+
| 'ROOT_INSIDE_REPOSITORY'
|
|
754
|
+
/** The path or branch of a worktree is taken by something this isolation did not create. */
|
|
755
|
+
| 'WORKTREE_CONFLICT'
|
|
756
|
+
/**
|
|
757
|
+
* The worktree's `.git` pointer, its directory or its registration (the admin directory's `gitdir`
|
|
758
|
+
* or `commondir`, or an `index` that exists but is not a regular file) is not what git wrote when it
|
|
759
|
+
* was created (for example a `.git` or `commondir` file an agent rewrote): no git command runs
|
|
760
|
+
* there, and it is kept.
|
|
761
|
+
*/
|
|
762
|
+
| 'WORKTREE_UNTRUSTED' | 'GIT_UNAVAILABLE' | 'GIT_FAILED' | 'OUTPUT_LIMIT' | 'TIMEOUT' | 'ABORTED';
|
|
763
|
+
/** The message carries the code, and for git failures the subcommand and exit code: never git's output. */
|
|
764
|
+
declare class DynamicIsolationError extends Error {
|
|
765
|
+
readonly code: DynamicIsolationErrorCode;
|
|
766
|
+
readonly subcommand?: string;
|
|
767
|
+
readonly exitCode?: number | null;
|
|
768
|
+
constructor(code: DynamicIsolationErrorCode, detail?: {
|
|
769
|
+
subcommand?: string;
|
|
770
|
+
exitCode?: number | null;
|
|
771
|
+
reason?: string;
|
|
772
|
+
});
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
/**
|
|
776
|
+
* Per-agent git worktrees for dynamic workflows.
|
|
777
|
+
*
|
|
778
|
+
* `create` adds `<root>/<runId>/<leaf>` on a new branch `<branchPrefix><runId>/<leaf>` from
|
|
779
|
+
* `baseRef`, where `<leaf>` is a slug of the call's label plus a digest of its key; calling it again
|
|
780
|
+
* for the same run and key (a resumed run) reuses that worktree. `inspect` reports whether the agent
|
|
781
|
+
* changed anything there: modified, staged, untracked or ignored files, commits beyond `baseRef`, or
|
|
782
|
+
* a HEAD moved off the branch. `cleanupWorktrees` removes a run's unchanged worktrees and their
|
|
783
|
+
* branches; a changed or untrusted one is never removed and nothing is ever forced. Every worktree
|
|
784
|
+
* directory of the run whose branch still exists is in its report, including one whose registration
|
|
785
|
+
* the agent rewrote (kept, as changed).
|
|
786
|
+
*
|
|
787
|
+
* A worktree is a separate working tree of the same repository, not a sandbox: the agent runs as the
|
|
788
|
+
* user and can reach anything the user can, within what its permissions allow. The application
|
|
789
|
+
* reviews, merges or discards each changed worktree; nothing here merges.
|
|
790
|
+
*
|
|
791
|
+
* `root` must be outside the repository's working tree, or inside it only where git ignores it (for
|
|
792
|
+
* example a `.worktrees/` line in `.gitignore`): otherwise every worktree would show up as untracked
|
|
793
|
+
* files of the main checkout. That is checked on first use (ROOT_INSIDE_REPOSITORY). The SDK's git
|
|
794
|
+
* commands run without a shell, with the repository's hooks and fsmonitor disabled, without system
|
|
795
|
+
* or global attribute files, without any inherited `GIT_*` variable and under a deadline. Git never
|
|
796
|
+
* discovers the repository from inside a worktree: see `isolation-worktree.ts` for how a worktree is
|
|
797
|
+
* trusted (WORKTREE_UNTRUSTED otherwise) and which filters configured outside it can still run.
|
|
798
|
+
*/
|
|
799
|
+
interface GitWorktreeIsolationOptions {
|
|
800
|
+
/** Absolute path of a git repository (any directory of its working tree). */
|
|
801
|
+
repository: string;
|
|
802
|
+
/** Absolute directory the worktrees go under; created when missing. */
|
|
803
|
+
root: string;
|
|
804
|
+
/** Commit the worktrees branch from. Default 'HEAD', resolved once per isolation. */
|
|
805
|
+
baseRef?: string;
|
|
806
|
+
/** Default 'oar/dw/'. */
|
|
807
|
+
branchPrefix?: string;
|
|
808
|
+
/** What `cleanupWorktrees` keeps by default: 'changed' (default) removes unchanged ones; 'always' removes nothing. */
|
|
809
|
+
keep?: 'changed' | 'always';
|
|
810
|
+
/** Deadline of each git command. Default 60 000 ms. */
|
|
811
|
+
gitTimeoutMs?: number;
|
|
812
|
+
}
|
|
813
|
+
/**
|
|
814
|
+
* Why a worktree was kept without a verdict on its contents (it then reports `changed: true`):
|
|
815
|
+
* - `untrusted`: its `.git`, registration or admin directory is not what git wrote (WORKTREE_UNTRUSTED),
|
|
816
|
+
* or git would read a per-worktree configuration of it to remove it;
|
|
817
|
+
* - `missing`: registered but its directory is gone (or not registered there at all);
|
|
818
|
+
* - `failed`: a git command or file check on it failed (an unreadable index, a deadline, ...).
|
|
819
|
+
*/
|
|
820
|
+
type WorktreeKeptReason = 'untrusted' | 'missing' | 'failed';
|
|
821
|
+
interface WorktreeCleanupReport {
|
|
822
|
+
/** `branchDeleted` is false when the branch moved after it was inspected (or could not be deleted): it is then left in place. */
|
|
823
|
+
readonly removed: ReadonlyArray<{
|
|
824
|
+
readonly path: string;
|
|
825
|
+
readonly branch: string;
|
|
826
|
+
readonly branchDeleted: boolean;
|
|
827
|
+
}>;
|
|
828
|
+
readonly kept: ReadonlyArray<{
|
|
829
|
+
readonly path: string;
|
|
830
|
+
readonly branch: string;
|
|
831
|
+
readonly changed: boolean;
|
|
832
|
+
readonly reason?: WorktreeKeptReason;
|
|
833
|
+
}>;
|
|
834
|
+
}
|
|
835
|
+
interface GitWorktreeIsolation extends DynamicIsolation {
|
|
836
|
+
/** Removes the run's unchanged worktrees and branches (keep 'changed'); never a changed one. */
|
|
837
|
+
cleanupWorktrees(options: {
|
|
838
|
+
runId: string;
|
|
839
|
+
keep?: 'changed' | 'always';
|
|
840
|
+
signal?: AbortSignal;
|
|
841
|
+
}): Promise<WorktreeCleanupReport>;
|
|
842
|
+
}
|
|
843
|
+
declare function gitWorktreeIsolation(options: GitWorktreeIsolationOptions): GitWorktreeIsolation;
|
|
844
|
+
|
|
845
|
+
/**
|
|
846
|
+
* Validates and runs a plan under the run's limits, then `runWorkflowScript`. Before anything runs it
|
|
847
|
+
* rejects with `DynamicPlanError` for an invalid plan or args that do not fit it (`checkPlanArgs`), and
|
|
848
|
+
* with a TypeError for malformed limits or args, or for a step asking `isolation: 'worktree'` when the run
|
|
849
|
+
* has no `DynamicRunOptions.isolation`. A plan error found mid-run (a map over a failed step's `null`) ends
|
|
850
|
+
* the run `failed` with code PLAN_INVALID; agent failures are in the report.
|
|
851
|
+
*/
|
|
852
|
+
declare function runWorkflowPlan(plan: DynamicWorkflowPlan | unknown, options: DynamicRunOptions): Promise<DynamicRunReport>;
|
|
853
|
+
|
|
854
|
+
export { type AgentRunnerOptions, type CompilePlan, DYNAMIC_LIMIT_BOUNDS, DYNAMIC_PLAN_JSON_SCHEMA, type DynamicAgentCount, type DynamicAgentOptions, type DynamicAgentRequest, type DynamicAgentResult, type DynamicAgentRunner, type DynamicAgentStep, type DynamicClock, type DynamicEngineOptions, type DynamicIsolation, DynamicIsolationError, type DynamicIsolationErrorCode, type DynamicJournal, DynamicJournalCorruptError, DynamicJournalLockedError, type DynamicJournalOwner, DynamicJournalWriteError, type DynamicJsonSchema, type DynamicLaunchGate, type DynamicLimits, type DynamicMapStep, type DynamicPermissionMode, DynamicPlanError, type DynamicPlanErrorCode, type DynamicPlanEstimate, type DynamicPlanIssue, type DynamicPlanStep, DynamicPlannerError, type DynamicRunOptions, type DynamicRunReport, type DynamicRunStatus, DynamicRunnerError, type DynamicRunnerErrorCode, type DynamicTemplate, type DynamicWorkflowContext, type DynamicWorkflowEvent, type DynamicWorkflowMeta, type DynamicWorkflowPlan, type DynamicWorkflowScript, type FileDynamicJournal, type GitWorktreeIsolation, type GitWorktreeIsolationOptions, JsonValue, MAX_RENDERED_PROMPT_BYTES, type ManagedDynamicJournal, PLANNER_INSTRUCTIONS, PLAN_BOUNDS, type PlanLimits, type PlanWorkflowOptions, type PlannedWorkflow, type PlannerAgentOptions, type RunWorkflowScript, type WorktreeCleanupReport, agentRunner, checkPlanArgs, compilePlan, createDynamicEngine, estimatePlan, fileDynamicJournal, gitWorktreeIsolation, memoryDynamicJournal, planWaves, planWorkflow, renderTemplate, resolveDynamicLimits, runWorkflowPlan, runWorkflowScript, templateReferences, validateDynamicMeta, validateDynamicRunId, validatePlan };
|