@clearideas/agent-runtime-store-local 0.9.0 → 1.0.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/NOTICE +2 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/run-store.file.d.ts +7 -2
- package/dist/run-store.file.js +67 -2
- package/dist/run-store.memory.d.ts +14 -1
- package/dist/run-store.memory.js +37 -0
- package/package.json +3 -3
package/NOTICE
CHANGED
|
@@ -3,6 +3,6 @@ Copyright 2026 Clear Ideas Incorporated
|
|
|
3
3
|
|
|
4
4
|
Clear Ideas is a trademark of Clear Ideas Incorporated.
|
|
5
5
|
|
|
6
|
-
The documentation site includes @clearideas/analytics 1.
|
|
6
|
+
The documentation site includes @clearideas/consent-analytics 0.1.0-rc.1, distributed
|
|
7
7
|
under the MIT License. Its license text is available at
|
|
8
|
-
docs/public/assets/analytics/LICENSE.clearideas-analytics.txt.
|
|
8
|
+
docs/public/assets/analytics/LICENSE.clearideas-consent-analytics.txt.
|
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export { ConsoleEventSink, JsonlEventSink } from "./event-sinks.js";
|
|
|
3
3
|
export { FileAgentManifestSource } from "./manifest-source.file.js";
|
|
4
4
|
export { FileAgentRunManifestSource } from "./run-manifest-source.file.js";
|
|
5
5
|
export { FileRunStore } from "./run-store.file.js";
|
|
6
|
-
export { MemoryRunStore } from "./run-store.memory.js";
|
|
6
|
+
export { MemoryRunStore, type RunStoreRetentionOptions, } from "./run-store.memory.js";
|
|
7
7
|
export { LocalDirectoryWorkspace, type LocalDirectoryWorkspaceOptions, } from "./workspace.directory.js";
|
|
8
8
|
export { MemoryWorkspace, type MemoryWorkspaceOptions, } from "./workspace.memory.js";
|
|
9
9
|
export { compileGlob } from "./workspace-common.js";
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@ export { ConsoleEventSink, JsonlEventSink } from "./event-sinks.js";
|
|
|
3
3
|
export { FileAgentManifestSource } from "./manifest-source.file.js";
|
|
4
4
|
export { FileAgentRunManifestSource } from "./run-manifest-source.file.js";
|
|
5
5
|
export { FileRunStore } from "./run-store.file.js";
|
|
6
|
-
export { MemoryRunStore } from "./run-store.memory.js";
|
|
6
|
+
export { MemoryRunStore, } from "./run-store.memory.js";
|
|
7
7
|
export { LocalDirectoryWorkspace, } from "./workspace.directory.js";
|
|
8
8
|
export { MemoryWorkspace, } from "./workspace.memory.js";
|
|
9
9
|
export { compileGlob } from "./workspace-common.js";
|
package/dist/run-store.file.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { RunCheckpoint, RunError } from "@clearideas/agent-runtime-contracts";
|
|
2
|
-
import type { CompletedRunRecord, ResumeRunOptions, RunRecord, RunStore } from "@clearideas/agent-runtime-core";
|
|
2
|
+
import type { CompletedRunRecord, ResumeRunOptions, RunCheckpointSummary, RunRecord, RunStore } from "@clearideas/agent-runtime-core";
|
|
3
|
+
import type { RunStoreRetentionOptions } from "./run-store.memory.js";
|
|
3
4
|
/**
|
|
4
5
|
* Durable zero-service persistence for one Agent Runtime process. Atomic file
|
|
5
6
|
* replacement protects readers from partial JSON, but cross-process resume
|
|
@@ -7,10 +8,14 @@ import type { CompletedRunRecord, ResumeRunOptions, RunRecord, RunStore } from "
|
|
|
7
8
|
*/
|
|
8
9
|
export declare class FileRunStore implements RunStore {
|
|
9
10
|
#private;
|
|
10
|
-
constructor(rootDirectory: string);
|
|
11
|
+
constructor(rootDirectory: string, options?: RunStoreRetentionOptions);
|
|
11
12
|
createRun(record: RunRecord): Promise<void>;
|
|
12
13
|
loadRun(runId: string): Promise<RunRecord | null>;
|
|
13
14
|
loadLatestCheckpoint(runId: string): Promise<RunCheckpoint | null>;
|
|
15
|
+
listCheckpoints(runId: string, options?: {
|
|
16
|
+
boundaries?: boolean;
|
|
17
|
+
}): Promise<RunCheckpointSummary[]>;
|
|
18
|
+
loadCheckpoint(runId: string, sequence: number): Promise<RunCheckpoint | null>;
|
|
14
19
|
resumeRun(runId: string, resumedAt: string, options?: ResumeRunOptions): Promise<number>;
|
|
15
20
|
saveCheckpoint(checkpoint: RunCheckpoint): Promise<void>;
|
|
16
21
|
suspendRun(runId: string, suspendedAt: string, expectedAttempt: number): Promise<void>;
|
package/dist/run-store.file.js
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
|
-
import { access, mkdir, open, unlink } from "node:fs/promises";
|
|
2
|
+
import { access, mkdir, open, readdir, unlink } from "node:fs/promises";
|
|
3
3
|
import path from "node:path";
|
|
4
|
+
import { summarizeCheckpoint } from "@clearideas/agent-runtime-core";
|
|
4
5
|
import { readTextWithRetry, renameWithRetry } from "./file-retry.js";
|
|
5
6
|
import { safePathComponent } from "./path-component.js";
|
|
6
7
|
const RUN_FILE = "run.json";
|
|
7
8
|
const CHECKPOINT_FILE = "checkpoint.json";
|
|
9
|
+
/** Step-completion checkpoints (restart points), one file per sequence. */
|
|
10
|
+
const BOUNDARY_DIRECTORY = "checkpoints";
|
|
8
11
|
const pathExists = async (filePath) => {
|
|
9
12
|
try {
|
|
10
13
|
await access(filePath);
|
|
@@ -56,10 +59,12 @@ const writeJsonAtomically = async (filePath, value) => {
|
|
|
56
59
|
export class FileRunStore {
|
|
57
60
|
#rootDirectory;
|
|
58
61
|
#runLocks = new Map();
|
|
59
|
-
|
|
62
|
+
#maxNested;
|
|
63
|
+
constructor(rootDirectory, options = {}) {
|
|
60
64
|
if (!rootDirectory.trim())
|
|
61
65
|
throw new Error("FileRunStore requires a root directory.");
|
|
62
66
|
this.#rootDirectory = path.resolve(rootDirectory);
|
|
67
|
+
this.#maxNested = options.maxNestedRestartPoints ?? 10;
|
|
63
68
|
}
|
|
64
69
|
async createRun(record) {
|
|
65
70
|
return this.#withRunLock(record.runId, async () => {
|
|
@@ -75,6 +80,31 @@ export class FileRunStore {
|
|
|
75
80
|
async loadLatestCheckpoint(runId) {
|
|
76
81
|
return readJson(this.#checkpointFile(runId));
|
|
77
82
|
}
|
|
83
|
+
async listCheckpoints(runId, options = {}) {
|
|
84
|
+
const retained = new Map();
|
|
85
|
+
for (const entry of await this.#boundarySequences(runId)) {
|
|
86
|
+
const checkpoint = await readJson(this.#boundaryFile(runId, entry.sequence, entry.nested));
|
|
87
|
+
if (checkpoint)
|
|
88
|
+
retained.set(checkpoint.sequence, checkpoint);
|
|
89
|
+
}
|
|
90
|
+
const latest = await this.loadLatestCheckpoint(runId);
|
|
91
|
+
if (latest && (!options.boundaries || latest.boundary))
|
|
92
|
+
retained.set(latest.sequence, latest);
|
|
93
|
+
return [...retained.values()]
|
|
94
|
+
.sort((left, right) => left.sequence - right.sequence)
|
|
95
|
+
.map(summarizeCheckpoint);
|
|
96
|
+
}
|
|
97
|
+
async loadCheckpoint(runId, sequence) {
|
|
98
|
+
const latest = await this.loadLatestCheckpoint(runId);
|
|
99
|
+
if (latest?.sequence === sequence)
|
|
100
|
+
return latest;
|
|
101
|
+
if (!Number.isSafeInteger(sequence) || sequence < 1)
|
|
102
|
+
return null;
|
|
103
|
+
const entry = (await this.#boundarySequences(runId)).find((candidate) => candidate.sequence === sequence);
|
|
104
|
+
return entry
|
|
105
|
+
? readJson(this.#boundaryFile(runId, entry.sequence, entry.nested))
|
|
106
|
+
: null;
|
|
107
|
+
}
|
|
78
108
|
async resumeRun(runId, resumedAt, options) {
|
|
79
109
|
return this.#withRunLock(runId, async () => {
|
|
80
110
|
const existing = await this.#requireRun(runId);
|
|
@@ -88,6 +118,7 @@ export class FileRunStore {
|
|
|
88
118
|
const attempt = (existing.attempt ?? 1) + 1;
|
|
89
119
|
await writeJsonAtomically(this.#runFile(runId), {
|
|
90
120
|
...existing,
|
|
121
|
+
...(options?.manifest ? { manifest: options.manifest } : {}),
|
|
91
122
|
status: "running",
|
|
92
123
|
attempt,
|
|
93
124
|
updatedAt: resumedAt,
|
|
@@ -120,6 +151,20 @@ export class FileRunStore {
|
|
|
120
151
|
else if (checkpoint.sequence !== 1) {
|
|
121
152
|
throw new Error(`First checkpoint for run ${checkpoint.runId} must have sequence 1`);
|
|
122
153
|
}
|
|
154
|
+
// A restart point is kept after later checkpoints replace the latest.
|
|
155
|
+
if (checkpoint.boundary) {
|
|
156
|
+
const nested = checkpoint.boundary.stepPath.includes("/");
|
|
157
|
+
await writeJsonAtomically(this.#boundaryFile(checkpoint.runId, checkpoint.sequence, nested), checkpoint);
|
|
158
|
+
// Bounded retention: all top-level restart points, recent nested ones.
|
|
159
|
+
if (nested) {
|
|
160
|
+
const stale = (await this.#boundarySequences(checkpoint.runId))
|
|
161
|
+
.filter((entry) => entry.nested)
|
|
162
|
+
.sort((left, right) => right.sequence - left.sequence)
|
|
163
|
+
.slice(this.#maxNested);
|
|
164
|
+
for (const entry of stale)
|
|
165
|
+
await unlink(this.#boundaryFile(checkpoint.runId, entry.sequence, true)).catch(() => undefined);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
123
168
|
await writeJsonAtomically(this.#checkpointFile(checkpoint.runId), checkpoint);
|
|
124
169
|
});
|
|
125
170
|
}
|
|
@@ -254,4 +299,24 @@ export class FileRunStore {
|
|
|
254
299
|
#checkpointFile(runId) {
|
|
255
300
|
return path.join(this.#runDirectory(runId), CHECKPOINT_FILE);
|
|
256
301
|
}
|
|
302
|
+
#boundaryFile(runId, sequence, nested) {
|
|
303
|
+
return path.join(this.#runDirectory(runId), BOUNDARY_DIRECTORY, `${String(sequence).padStart(12, "0")}${nested ? ".nested" : ""}.json`);
|
|
304
|
+
}
|
|
305
|
+
async #boundarySequences(runId) {
|
|
306
|
+
try {
|
|
307
|
+
return (await readdir(path.join(this.#runDirectory(runId), BOUNDARY_DIRECTORY)))
|
|
308
|
+
.map((name) => /^(\d{12})(\.nested)?\.json$/u.exec(name))
|
|
309
|
+
.filter((match) => match !== null)
|
|
310
|
+
.map((match) => ({
|
|
311
|
+
sequence: Number(match[1]),
|
|
312
|
+
nested: match[2] !== undefined,
|
|
313
|
+
}))
|
|
314
|
+
.sort((left, right) => left.sequence - right.sequence);
|
|
315
|
+
}
|
|
316
|
+
catch (error) {
|
|
317
|
+
if (error.code === "ENOENT")
|
|
318
|
+
return [];
|
|
319
|
+
throw error;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
257
322
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { RunCheckpoint, RunError } from "@clearideas/agent-runtime-contracts";
|
|
2
|
-
import type { CompletedRunRecord, ResumeRunOptions, RunRecord, RunStore } from "@clearideas/agent-runtime-core";
|
|
2
|
+
import type { CompletedRunRecord, ResumeRunOptions, RunCheckpointSummary, RunRecord, RunStore } from "@clearideas/agent-runtime-core";
|
|
3
3
|
export type FailedRunRecord = RunRecord & {
|
|
4
4
|
status: "failed";
|
|
5
5
|
error: RunError;
|
|
@@ -10,9 +10,22 @@ export type InterruptedRunRecord = RunRecord & {
|
|
|
10
10
|
error: RunError;
|
|
11
11
|
interruptedAt: string;
|
|
12
12
|
};
|
|
13
|
+
export interface RunStoreRetentionOptions {
|
|
14
|
+
/**
|
|
15
|
+
* Restart points inside steps (a completed child of a loop iteration) kept
|
|
16
|
+
* per run, most recent first. Every top-level restart point is kept.
|
|
17
|
+
* Defaults to 10.
|
|
18
|
+
*/
|
|
19
|
+
maxNestedRestartPoints?: number;
|
|
20
|
+
}
|
|
13
21
|
/** In-process persistence for tests, embedded use, and short-lived local runs. */
|
|
14
22
|
export declare class MemoryRunStore implements RunStore {
|
|
15
23
|
#private;
|
|
24
|
+
constructor(options?: RunStoreRetentionOptions);
|
|
25
|
+
listCheckpoints(runId: string, options?: {
|
|
26
|
+
boundaries?: boolean;
|
|
27
|
+
}): Promise<RunCheckpointSummary[]>;
|
|
28
|
+
loadCheckpoint(runId: string, sequence: number): Promise<RunCheckpoint | null>;
|
|
16
29
|
createRun(record: RunRecord): Promise<void>;
|
|
17
30
|
loadRun(runId: string): Promise<RunRecord | null>;
|
|
18
31
|
loadLatestCheckpoint(runId: string): Promise<RunCheckpoint | null>;
|
package/dist/run-store.memory.js
CHANGED
|
@@ -1,8 +1,32 @@
|
|
|
1
|
+
import { summarizeCheckpoint } from "@clearideas/agent-runtime-core";
|
|
1
2
|
const clone = (value) => structuredClone(value);
|
|
3
|
+
const isNestedBoundary = (checkpoint) => checkpoint.boundary?.stepPath.includes("/") === true;
|
|
2
4
|
/** In-process persistence for tests, embedded use, and short-lived local runs. */
|
|
3
5
|
export class MemoryRunStore {
|
|
4
6
|
#runs = new Map();
|
|
5
7
|
#checkpoints = new Map();
|
|
8
|
+
/** Step-completion checkpoints (restart points) per run, by sequence. */
|
|
9
|
+
#boundaries = new Map();
|
|
10
|
+
#maxNested;
|
|
11
|
+
constructor(options = {}) {
|
|
12
|
+
this.#maxNested = options.maxNestedRestartPoints ?? 10;
|
|
13
|
+
}
|
|
14
|
+
async listCheckpoints(runId, options = {}) {
|
|
15
|
+
const retained = new Map(this.#boundaries.get(runId) ?? []);
|
|
16
|
+
const latest = this.#checkpoints.get(runId);
|
|
17
|
+
if (latest && !options.boundaries)
|
|
18
|
+
retained.set(latest.sequence, latest);
|
|
19
|
+
return [...retained.values()]
|
|
20
|
+
.sort((left, right) => left.sequence - right.sequence)
|
|
21
|
+
.map(summarizeCheckpoint);
|
|
22
|
+
}
|
|
23
|
+
async loadCheckpoint(runId, sequence) {
|
|
24
|
+
const latest = this.#checkpoints.get(runId);
|
|
25
|
+
const checkpoint = latest?.sequence === sequence
|
|
26
|
+
? latest
|
|
27
|
+
: this.#boundaries.get(runId)?.get(sequence);
|
|
28
|
+
return checkpoint ? clone(checkpoint) : null;
|
|
29
|
+
}
|
|
6
30
|
async createRun(record) {
|
|
7
31
|
if (this.#runs.has(record.runId)) {
|
|
8
32
|
throw new Error(`Run already exists: ${record.runId}`);
|
|
@@ -29,6 +53,7 @@ export class MemoryRunStore {
|
|
|
29
53
|
const attempt = (existing.attempt ?? 1) + 1;
|
|
30
54
|
this.#runs.set(runId, {
|
|
31
55
|
...clone(existing),
|
|
56
|
+
...(options?.manifest ? { manifest: clone(options.manifest) } : {}),
|
|
32
57
|
status: "running",
|
|
33
58
|
attempt,
|
|
34
59
|
updatedAt: resumedAt,
|
|
@@ -60,6 +85,17 @@ export class MemoryRunStore {
|
|
|
60
85
|
throw new Error(`First checkpoint for run ${checkpoint.runId} must have sequence 1`);
|
|
61
86
|
}
|
|
62
87
|
this.#checkpoints.set(checkpoint.runId, clone(checkpoint));
|
|
88
|
+
if (checkpoint.boundary) {
|
|
89
|
+
const boundaries = this.#boundaries.get(checkpoint.runId) ?? new Map();
|
|
90
|
+
boundaries.set(checkpoint.sequence, clone(checkpoint));
|
|
91
|
+
this.#boundaries.set(checkpoint.runId, boundaries);
|
|
92
|
+
// Bounded retention: all top-level restart points, recent nested ones.
|
|
93
|
+
const nested = [...boundaries.values()]
|
|
94
|
+
.filter(isNestedBoundary)
|
|
95
|
+
.sort((left, right) => right.sequence - left.sequence);
|
|
96
|
+
for (const stale of nested.slice(this.#maxNested))
|
|
97
|
+
boundaries.delete(stale.sequence);
|
|
98
|
+
}
|
|
63
99
|
}
|
|
64
100
|
async suspendRun(runId, suspendedAt, expectedAttempt) {
|
|
65
101
|
const existing = this.#requireRun(runId);
|
|
@@ -159,6 +195,7 @@ export class MemoryRunStore {
|
|
|
159
195
|
}
|
|
160
196
|
this.#runs.delete(runId);
|
|
161
197
|
this.#checkpoints.delete(runId);
|
|
198
|
+
this.#boundaries.delete(runId);
|
|
162
199
|
return true;
|
|
163
200
|
}
|
|
164
201
|
#requireRun(runId) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@clearideas/agent-runtime-store-local",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "Memory, file, console, and JSONL adapters for Clear Ideas Agent Runtime.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Clear Ideas Incorporated",
|
|
@@ -36,8 +36,8 @@
|
|
|
36
36
|
"postpack": "node ../../scripts/cleanup-package-license.mjs"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@clearideas/agent-runtime-contracts": "0.
|
|
40
|
-
"@clearideas/agent-runtime-core": "0.
|
|
39
|
+
"@clearideas/agent-runtime-contracts": "1.0.0",
|
|
40
|
+
"@clearideas/agent-runtime-core": "1.0.0",
|
|
41
41
|
"yaml": "^2.9.1"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|