@ddse/acm-runtime 0.5.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.
- package/LICENSE +21 -0
- package/README.md +393 -0
- package/dist/src/checkpoint.d.ts +97 -0
- package/dist/src/checkpoint.d.ts.map +1 -0
- package/dist/src/checkpoint.js +200 -0
- package/dist/src/checkpoint.js.map +1 -0
- package/dist/src/execution-transcript.d.ts +30 -0
- package/dist/src/execution-transcript.d.ts.map +1 -0
- package/dist/src/execution-transcript.js +70 -0
- package/dist/src/execution-transcript.js.map +1 -0
- package/dist/src/executor.d.ts +49 -0
- package/dist/src/executor.d.ts.map +1 -0
- package/dist/src/executor.js +390 -0
- package/dist/src/executor.js.map +1 -0
- package/dist/src/guards.d.ts +7 -0
- package/dist/src/guards.d.ts.map +1 -0
- package/dist/src/guards.js +13 -0
- package/dist/src/guards.js.map +1 -0
- package/dist/src/index.d.ts +9 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +10 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/ledger.d.ts +12 -0
- package/dist/src/ledger.d.ts.map +1 -0
- package/dist/src/ledger.js +53 -0
- package/dist/src/ledger.js.map +1 -0
- package/dist/src/resumable-executor.d.ts +39 -0
- package/dist/src/resumable-executor.d.ts.map +1 -0
- package/dist/src/resumable-executor.js +354 -0
- package/dist/src/resumable-executor.js.map +1 -0
- package/dist/src/retry.d.ts +7 -0
- package/dist/src/retry.d.ts.map +1 -0
- package/dist/src/retry.js +25 -0
- package/dist/src/retry.js.map +1 -0
- package/dist/src/tool-envelope.d.ts +14 -0
- package/dist/src/tool-envelope.d.ts.map +1 -0
- package/dist/src/tool-envelope.js +84 -0
- package/dist/src/tool-envelope.js.map +1 -0
- package/dist/tests/resumable.test.d.ts +2 -0
- package/dist/tests/resumable.test.d.ts.map +1 -0
- package/dist/tests/resumable.test.js +337 -0
- package/dist/tests/resumable.test.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +29 -0
- package/src/checkpoint.ts +311 -0
- package/src/execution-transcript.ts +108 -0
- package/src/executor.ts +540 -0
- package/src/guards.ts +21 -0
- package/src/index.ts +9 -0
- package/src/ledger.ts +63 -0
- package/src/resumable-executor.ts +471 -0
- package/src/retry.ts +37 -0
- package/src/tool-envelope.ts +113 -0
- package/tests/resumable.test.ts +421 -0
- package/tsconfig.json +11 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 DDSE Foundation
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,393 @@
|
|
|
1
|
+
# @ddse/acm-runtime
|
|
2
|
+
|
|
3
|
+
ACM v0.5 execution engine with guards, retries, policy hooks, and memory ledger.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
The runtime package provides deterministic plan execution with full ACM v0.5 semantics including guard evaluation, retry logic, policy enforcement, verification, and decision logging.
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
pnpm add @ddse/acm-runtime @ddse/acm-sdk
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Features
|
|
16
|
+
|
|
17
|
+
- ✅ Task graph execution with topological ordering
|
|
18
|
+
- ✅ Guard expression evaluation
|
|
19
|
+
- ✅ Configurable retry with exponential backoff
|
|
20
|
+
- ✅ Policy pre/post hooks
|
|
21
|
+
- ✅ Verification assertions
|
|
22
|
+
- ✅ Memory ledger (append-only decision log)
|
|
23
|
+
- ✅ Streaming progress updates
|
|
24
|
+
- ✅ Error handling and compensation
|
|
25
|
+
- ✅ **Resumable execution with checkpointing** (NEW in Phase 2)
|
|
26
|
+
|
|
27
|
+
## Usage
|
|
28
|
+
|
|
29
|
+
### Basic Execution
|
|
30
|
+
|
|
31
|
+
```typescript
|
|
32
|
+
import { executePlan, MemoryLedger } from '@ddse/acm-runtime';
|
|
33
|
+
import type { Goal, Context, Plan } from '@ddse/acm-sdk';
|
|
34
|
+
|
|
35
|
+
const result = await executePlan({
|
|
36
|
+
goal: { id: 'g1', intent: 'Process order' },
|
|
37
|
+
context: { id: 'ctx1', facts: { orderId: 'O123' } },
|
|
38
|
+
plan: myPlan,
|
|
39
|
+
capabilityRegistry: myCapabilities,
|
|
40
|
+
toolRegistry: myTools,
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
const taskRecord = result.outputsByTask['task-1'];
|
|
44
|
+
console.log('Task output:', taskRecord?.output);
|
|
45
|
+
console.log('Narrative:', taskRecord?.narrative);
|
|
46
|
+
console.log('Ledger entries:', result.ledger.length);
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### With Policy Enforcement
|
|
50
|
+
|
|
51
|
+
```typescript
|
|
52
|
+
import { PolicyEngine, type PolicyDecision } from '@ddse/acm-sdk';
|
|
53
|
+
|
|
54
|
+
class MyPolicyEngine implements PolicyEngine {
|
|
55
|
+
async evaluate(action: string, payload: any): Promise<PolicyDecision> {
|
|
56
|
+
if (action === 'task.pre' && payload.riskLevel === 'HIGH') {
|
|
57
|
+
return { allow: false, reason: 'Risk too high' };
|
|
58
|
+
}
|
|
59
|
+
return { allow: true };
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const result = await executePlan({
|
|
64
|
+
goal,
|
|
65
|
+
context,
|
|
66
|
+
plan,
|
|
67
|
+
capabilityRegistry,
|
|
68
|
+
toolRegistry,
|
|
69
|
+
policy: new MyPolicyEngine(),
|
|
70
|
+
});
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### With Verification
|
|
74
|
+
|
|
75
|
+
```typescript
|
|
76
|
+
const verify = async (taskId: string, output: any, expressions: string[]): Promise<boolean> => {
|
|
77
|
+
for (const expr of expressions) {
|
|
78
|
+
const func = new Function('output', `return ${expr};`);
|
|
79
|
+
if (!func(output)) {
|
|
80
|
+
console.error(`Verification failed: ${expr}`);
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return true;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
const result = await executePlan({
|
|
88
|
+
goal,
|
|
89
|
+
context,
|
|
90
|
+
plan,
|
|
91
|
+
capabilityRegistry,
|
|
92
|
+
toolRegistry,
|
|
93
|
+
verify,
|
|
94
|
+
});
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### With Streaming
|
|
98
|
+
|
|
99
|
+
```typescript
|
|
100
|
+
import { DefaultStreamSink } from '@ddse/acm-sdk';
|
|
101
|
+
|
|
102
|
+
const stream = new DefaultStreamSink();
|
|
103
|
+
|
|
104
|
+
stream.attach('task', (update) => {
|
|
105
|
+
console.log(`[${update.taskId}] ${update.status}`);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
const result = await executePlan({
|
|
109
|
+
goal,
|
|
110
|
+
context,
|
|
111
|
+
plan,
|
|
112
|
+
capabilityRegistry,
|
|
113
|
+
toolRegistry,
|
|
114
|
+
stream,
|
|
115
|
+
});
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### Memory Ledger
|
|
119
|
+
|
|
120
|
+
```typescript
|
|
121
|
+
import { MemoryLedger } from '@ddse/acm-runtime';
|
|
122
|
+
|
|
123
|
+
const ledger = new MemoryLedger();
|
|
124
|
+
|
|
125
|
+
const result = await executePlan({
|
|
126
|
+
goal,
|
|
127
|
+
context,
|
|
128
|
+
plan,
|
|
129
|
+
capabilityRegistry,
|
|
130
|
+
toolRegistry,
|
|
131
|
+
ledger,
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
// Inspect decisions
|
|
135
|
+
for (const entry of ledger.getEntries()) {
|
|
136
|
+
console.log(`${entry.type} at ${entry.ts}:`, entry.details);
|
|
137
|
+
}
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
### Resumable Execution (Phase 2)
|
|
141
|
+
|
|
142
|
+
Execute plans with automatic checkpointing and resume support:
|
|
143
|
+
|
|
144
|
+
```typescript
|
|
145
|
+
import { executeResumablePlan, FileCheckpointStore } from '@ddse/acm-runtime';
|
|
146
|
+
|
|
147
|
+
// Setup checkpoint storage
|
|
148
|
+
const checkpointStore = new FileCheckpointStore('./checkpoints');
|
|
149
|
+
const runId = 'my-run-123';
|
|
150
|
+
|
|
151
|
+
// Execute with checkpointing
|
|
152
|
+
const result = await executeResumablePlan({
|
|
153
|
+
goal,
|
|
154
|
+
context,
|
|
155
|
+
plan,
|
|
156
|
+
capabilityRegistry,
|
|
157
|
+
toolRegistry,
|
|
158
|
+
runId,
|
|
159
|
+
checkpointStore,
|
|
160
|
+
checkpointInterval: 1, // Checkpoint after each task
|
|
161
|
+
});
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
Resume from a previous execution:
|
|
165
|
+
|
|
166
|
+
```typescript
|
|
167
|
+
// Resume from checkpoint
|
|
168
|
+
const result = await executeResumablePlan({
|
|
169
|
+
goal,
|
|
170
|
+
context,
|
|
171
|
+
plan,
|
|
172
|
+
capabilityRegistry,
|
|
173
|
+
toolRegistry,
|
|
174
|
+
runId: 'my-run-123',
|
|
175
|
+
resumeFrom: 'checkpoint-xyz', // Resume from specific checkpoint
|
|
176
|
+
checkpointStore,
|
|
177
|
+
});
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
Using the ResumableExecutor class:
|
|
181
|
+
|
|
182
|
+
```typescript
|
|
183
|
+
import { ResumableExecutor, FileCheckpointStore } from '@ddse/acm-runtime';
|
|
184
|
+
|
|
185
|
+
const executor = new ResumableExecutor(
|
|
186
|
+
new FileCheckpointStore('./checkpoints')
|
|
187
|
+
);
|
|
188
|
+
|
|
189
|
+
// Execute with checkpointing
|
|
190
|
+
const result = await executor.execute({
|
|
191
|
+
goal,
|
|
192
|
+
context,
|
|
193
|
+
plan,
|
|
194
|
+
capabilityRegistry,
|
|
195
|
+
toolRegistry,
|
|
196
|
+
runId: 'my-run-123',
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
// List checkpoints
|
|
200
|
+
const checkpoints = await executor.listCheckpoints('my-run-123');
|
|
201
|
+
console.log(`Available checkpoints: ${checkpoints.length}`);
|
|
202
|
+
|
|
203
|
+
// Resume from latest checkpoint
|
|
204
|
+
const latest = await executor.getCheckpoint('my-run-123');
|
|
205
|
+
const resumed = await executor.execute({
|
|
206
|
+
goal,
|
|
207
|
+
context,
|
|
208
|
+
plan,
|
|
209
|
+
capabilityRegistry,
|
|
210
|
+
toolRegistry,
|
|
211
|
+
runId: 'my-run-123',
|
|
212
|
+
resumeFrom: latest?.id,
|
|
213
|
+
});
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
## API Reference
|
|
217
|
+
|
|
218
|
+
### executePlan(options)
|
|
219
|
+
|
|
220
|
+
Execute a plan with full ACM v0.5 semantics.
|
|
221
|
+
|
|
222
|
+
**Options:**
|
|
223
|
+
|
|
224
|
+
- `goal: Goal` - The goal being pursued
|
|
225
|
+
- `context: Context` - Immutable context packet
|
|
226
|
+
- `plan: Plan` - The plan to execute
|
|
227
|
+
- `capabilityRegistry: CapabilityRegistry` - Task registry
|
|
228
|
+
- `toolRegistry: ToolRegistry` - Tool registry
|
|
229
|
+
- `policy?: PolicyEngine` - Optional policy enforcement
|
|
230
|
+
- `verify?: (taskId, output, expressions) => Promise<boolean>` - Optional verification
|
|
231
|
+
- `stream?: StreamSink` - Optional streaming sink
|
|
232
|
+
- `ledger?: MemoryLedger` - Optional ledger (created if not provided)
|
|
233
|
+
|
|
234
|
+
**Returns:**
|
|
235
|
+
|
|
236
|
+
```typescript
|
|
237
|
+
{
|
|
238
|
+
outputsByTask: Record<string, TaskExecutionRecord>;
|
|
239
|
+
ledger: readonly LedgerEntry[];
|
|
240
|
+
}
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
Each `TaskExecutionRecord` captures:
|
|
244
|
+
|
|
245
|
+
- `taskId: string` – Identifier for the executed task.
|
|
246
|
+
- `title: string` – Task title from the structured plan.
|
|
247
|
+
- `objective?: string` – Optional objective provided by the planner.
|
|
248
|
+
- `successCriteria?: string[]` – Optional success criteria checklist.
|
|
249
|
+
- `metadata?: TaskMetadata` – Arbitrary TaskSpec metadata.
|
|
250
|
+
- `narrative?: TaskNarrative` – { start, checkpoints, completion } narrative emitted by the Nucleus.
|
|
251
|
+
- `output?: unknown` – The task's output payload, when present.
|
|
252
|
+
|
|
253
|
+
### evaluateGuard(expr, context)
|
|
254
|
+
|
|
255
|
+
Evaluate a guard expression.
|
|
256
|
+
|
|
257
|
+
**Parameters:**
|
|
258
|
+
|
|
259
|
+
- `expr: string` - JavaScript boolean expression
|
|
260
|
+
- `context: { context, outputs, policy }` - Evaluation context
|
|
261
|
+
|
|
262
|
+
**Returns:** `boolean`
|
|
263
|
+
|
|
264
|
+
### withRetry(fn, config)
|
|
265
|
+
|
|
266
|
+
Execute a function with retry logic.
|
|
267
|
+
|
|
268
|
+
**Parameters:**
|
|
269
|
+
|
|
270
|
+
- `fn: () => Promise<T>` - Function to retry
|
|
271
|
+
- `config: { attempts, backoff, baseMs?, jitter? }` - Retry configuration
|
|
272
|
+
|
|
273
|
+
**Returns:** `Promise<T>`
|
|
274
|
+
|
|
275
|
+
### MemoryLedger
|
|
276
|
+
|
|
277
|
+
Append-only decision log.
|
|
278
|
+
|
|
279
|
+
**Methods:**
|
|
280
|
+
|
|
281
|
+
- `append(type, details)` - Add entry
|
|
282
|
+
- `getEntries()` - Get all entries
|
|
283
|
+
- `clear()` - Clear ledger (for testing)
|
|
284
|
+
|
|
285
|
+
### executeResumablePlan(options)
|
|
286
|
+
|
|
287
|
+
Execute a plan with checkpoint and resume support.
|
|
288
|
+
|
|
289
|
+
**Additional Options (extends executePlan):**
|
|
290
|
+
|
|
291
|
+
- `runId?: string` - Unique run identifier (generated if not provided)
|
|
292
|
+
- `checkpointStore?: CheckpointStore` - Storage backend (default: MemoryCheckpointStore)
|
|
293
|
+
- `checkpointInterval?: number` - Checkpoint after N tasks (default: 1)
|
|
294
|
+
- `resumeFrom?: string` - Checkpoint ID to resume from
|
|
295
|
+
|
|
296
|
+
**Returns:** Same as `executePlan`
|
|
297
|
+
|
|
298
|
+
### CheckpointStore
|
|
299
|
+
|
|
300
|
+
Interface for checkpoint storage backends.
|
|
301
|
+
|
|
302
|
+
**Implementations:**
|
|
303
|
+
|
|
304
|
+
- `MemoryCheckpointStore` - In-memory storage (for testing)
|
|
305
|
+
- `FileCheckpointStore(basePath)` - File-based storage
|
|
306
|
+
|
|
307
|
+
**Methods:**
|
|
308
|
+
|
|
309
|
+
- `put(runId, checkpoint)` - Store a checkpoint
|
|
310
|
+
- `get(runId, checkpointId?)` - Retrieve checkpoint (latest if no ID)
|
|
311
|
+
- `list(runId)` - List all checkpoints for a run
|
|
312
|
+
- `prune(runId, keepLast)` - Remove old checkpoints
|
|
313
|
+
|
|
314
|
+
### ResumableExecutor
|
|
315
|
+
|
|
316
|
+
High-level class for managing resumable executions.
|
|
317
|
+
|
|
318
|
+
**Constructor:**
|
|
319
|
+
|
|
320
|
+
- `new ResumableExecutor(checkpointStore?)` - Create executor with optional store
|
|
321
|
+
|
|
322
|
+
**Methods:**
|
|
323
|
+
|
|
324
|
+
- `execute(options)` - Execute with checkpointing
|
|
325
|
+
- `listCheckpoints(runId)` - List available checkpoints
|
|
326
|
+
- `getCheckpoint(runId, checkpointId?)` - Get specific checkpoint
|
|
327
|
+
- `pruneCheckpoints(runId, keepLast)` - Clean up old checkpoints
|
|
328
|
+
|
|
329
|
+
## Guard Expressions
|
|
330
|
+
|
|
331
|
+
Guards are JavaScript boolean expressions evaluated with:
|
|
332
|
+
|
|
333
|
+
- `context`: The Context Packet facts
|
|
334
|
+
- `outputs`: Task outputs so far
|
|
335
|
+
- `policy`: Policy decisions
|
|
336
|
+
|
|
337
|
+
Examples:
|
|
338
|
+
|
|
339
|
+
```javascript
|
|
340
|
+
// Simple fact check
|
|
341
|
+
'context.region === "EU"'
|
|
342
|
+
|
|
343
|
+
// Output dependency
|
|
344
|
+
'outputs.t1.riskTier !== "HIGH"'
|
|
345
|
+
|
|
346
|
+
// Policy check
|
|
347
|
+
'policy.t1.allow === true'
|
|
348
|
+
|
|
349
|
+
// Combined
|
|
350
|
+
'context.amount > 100 && outputs.t2.approved === true'
|
|
351
|
+
```
|
|
352
|
+
|
|
353
|
+
## Retry Configuration
|
|
354
|
+
|
|
355
|
+
```typescript
|
|
356
|
+
{
|
|
357
|
+
attempts: 3,
|
|
358
|
+
backoff: 'exp', // or 'fixed'
|
|
359
|
+
baseMs: 1000,
|
|
360
|
+
jitter: true
|
|
361
|
+
}
|
|
362
|
+
```
|
|
363
|
+
|
|
364
|
+
Backoff strategies:
|
|
365
|
+
|
|
366
|
+
- **fixed**: Always wait `baseMs`
|
|
367
|
+
- **exp**: Wait `baseMs * 2^attempt`
|
|
368
|
+
- **jitter**: Add random variation (50-100% of delay)
|
|
369
|
+
|
|
370
|
+
## Ledger Entry Types
|
|
371
|
+
|
|
372
|
+
- `PLAN_SELECTED` - Plan chosen for execution
|
|
373
|
+
- `GUARD_EVAL` - Guard evaluation result
|
|
374
|
+
- `TASK_START` - Task execution started
|
|
375
|
+
- `TASK_END` - Task execution completed
|
|
376
|
+
- `POLICY_PRE` - Policy pre-check
|
|
377
|
+
- `POLICY_POST` - Policy post-check
|
|
378
|
+
- `VERIFICATION` - Verification result
|
|
379
|
+
- `ERROR` - Error occurred
|
|
380
|
+
- `COMPENSATION` - Compensation triggered
|
|
381
|
+
|
|
382
|
+
## ACM v0.5 Compliance
|
|
383
|
+
|
|
384
|
+
- ✅ Section 6.1: Task execution ordering
|
|
385
|
+
- ✅ Section 6.2: Guard evaluation (deterministic)
|
|
386
|
+
- ✅ Section 6.3: Retry and backoff
|
|
387
|
+
- ✅ Section 6.4: Policy enforcement hooks
|
|
388
|
+
- ✅ Section 6.5: Verification hooks
|
|
389
|
+
- ✅ Section 5.8: Memory Ledger
|
|
390
|
+
|
|
391
|
+
## License
|
|
392
|
+
|
|
393
|
+
Apache-2.0
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import type { Goal, Context, Plan, LedgerEntry } from '@ddse/acm-sdk';
|
|
2
|
+
import type { TaskExecutionRecord } from './executor.js';
|
|
3
|
+
/**
|
|
4
|
+
* Schema version for checkpoint compatibility
|
|
5
|
+
*/
|
|
6
|
+
export declare const CHECKPOINT_VERSION = "1.0.0";
|
|
7
|
+
/**
|
|
8
|
+
* Checkpoint represents a snapshot of execution state
|
|
9
|
+
*/
|
|
10
|
+
export interface Checkpoint {
|
|
11
|
+
id: string;
|
|
12
|
+
runId: string;
|
|
13
|
+
ts: number;
|
|
14
|
+
version: string;
|
|
15
|
+
state: CheckpointState;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Execution state captured in a checkpoint
|
|
19
|
+
*/
|
|
20
|
+
export interface CheckpointState {
|
|
21
|
+
goal: Goal;
|
|
22
|
+
context: Context;
|
|
23
|
+
plan: Plan;
|
|
24
|
+
outputs: Record<string, any>;
|
|
25
|
+
executionRecords?: Record<string, TaskExecutionRecord>;
|
|
26
|
+
executed: string[];
|
|
27
|
+
ledger: LedgerEntry[];
|
|
28
|
+
metrics: {
|
|
29
|
+
costUsd: number;
|
|
30
|
+
elapsedSec: number;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Metadata for a checkpoint (lightweight listing)
|
|
35
|
+
*/
|
|
36
|
+
export interface CheckpointMetadata {
|
|
37
|
+
id: string;
|
|
38
|
+
runId: string;
|
|
39
|
+
ts: number;
|
|
40
|
+
version: string;
|
|
41
|
+
tasksCompleted: number;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Storage interface for checkpoints
|
|
45
|
+
*/
|
|
46
|
+
export interface CheckpointStore {
|
|
47
|
+
/**
|
|
48
|
+
* Store a checkpoint
|
|
49
|
+
*/
|
|
50
|
+
put(runId: string, checkpoint: Checkpoint): Promise<void>;
|
|
51
|
+
/**
|
|
52
|
+
* Retrieve a checkpoint by ID (or latest if no ID provided)
|
|
53
|
+
*/
|
|
54
|
+
get(runId: string, checkpointId?: string): Promise<Checkpoint | null>;
|
|
55
|
+
/**
|
|
56
|
+
* List all checkpoints for a run
|
|
57
|
+
*/
|
|
58
|
+
list(runId: string): Promise<CheckpointMetadata[]>;
|
|
59
|
+
/**
|
|
60
|
+
* Prune old checkpoints, keeping only the last N
|
|
61
|
+
*/
|
|
62
|
+
prune(runId: string, keepLast: number): Promise<void>;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Create a checkpoint from current execution state
|
|
66
|
+
*/
|
|
67
|
+
export declare function createCheckpoint(runId: string, state: CheckpointState): Checkpoint;
|
|
68
|
+
/**
|
|
69
|
+
* Validate checkpoint compatibility
|
|
70
|
+
*/
|
|
71
|
+
export declare function validateCheckpoint(checkpoint: Checkpoint): boolean;
|
|
72
|
+
/**
|
|
73
|
+
* In-memory checkpoint store (for testing and simple use cases)
|
|
74
|
+
*/
|
|
75
|
+
export declare class MemoryCheckpointStore implements CheckpointStore {
|
|
76
|
+
private checkpoints;
|
|
77
|
+
put(runId: string, checkpoint: Checkpoint): Promise<void>;
|
|
78
|
+
get(runId: string, checkpointId?: string): Promise<Checkpoint | null>;
|
|
79
|
+
list(runId: string): Promise<CheckpointMetadata[]>;
|
|
80
|
+
prune(runId: string, keepLast: number): Promise<void>;
|
|
81
|
+
/**
|
|
82
|
+
* Clear all checkpoints (for testing)
|
|
83
|
+
*/
|
|
84
|
+
clear(): void;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* File-based checkpoint store
|
|
88
|
+
*/
|
|
89
|
+
export declare class FileCheckpointStore implements CheckpointStore {
|
|
90
|
+
private basePath;
|
|
91
|
+
constructor(basePath: string);
|
|
92
|
+
put(runId: string, checkpoint: Checkpoint): Promise<void>;
|
|
93
|
+
get(runId: string, checkpointId?: string): Promise<Checkpoint | null>;
|
|
94
|
+
list(runId: string): Promise<CheckpointMetadata[]>;
|
|
95
|
+
prune(runId: string, keepLast: number): Promise<void>;
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=checkpoint.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checkpoint.d.ts","sourceRoot":"","sources":["../../src/checkpoint.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,IAAI,EACJ,OAAO,EACP,IAAI,EACJ,WAAW,EACZ,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAEzD;;GAEG;AACH,eAAO,MAAM,kBAAkB,UAAU,CAAC;AAE1C;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,MAA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