toolsplice 0.0.0-stage → 0.0.2

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 (172) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +104 -2
  3. package/dist/abortable.d.ts +6 -0
  4. package/dist/abortable.js +50 -0
  5. package/dist/adaptive-read.d.ts +50 -0
  6. package/dist/adaptive-read.js +780 -0
  7. package/dist/answer-wait.d.ts +7 -0
  8. package/dist/answer-wait.js +45 -0
  9. package/dist/cache-reads.d.ts +18 -0
  10. package/dist/cache-reads.js +89 -0
  11. package/dist/calibration-ledger.d.ts +37 -0
  12. package/dist/calibration-ledger.js +148 -0
  13. package/dist/calibration-marker.d.ts +4 -0
  14. package/dist/calibration-marker.js +77 -0
  15. package/dist/catalog-setup.d.ts +33 -0
  16. package/dist/catalog-setup.js +89 -0
  17. package/dist/catalog.d.ts +10 -0
  18. package/dist/catalog.js +42 -0
  19. package/dist/checkpoint-files.d.ts +15 -0
  20. package/dist/checkpoint-files.js +99 -0
  21. package/dist/cli.d.ts +2 -0
  22. package/dist/cli.js +1454 -0
  23. package/dist/coalesce-reads.d.ts +6 -0
  24. package/dist/coalesce-reads.js +33 -0
  25. package/dist/codegen.d.ts +44 -0
  26. package/dist/codegen.js +479 -0
  27. package/dist/contract-caller.d.ts +23 -0
  28. package/dist/contract-caller.js +326 -0
  29. package/dist/contract-corrections.d.ts +35 -0
  30. package/dist/contract-corrections.js +159 -0
  31. package/dist/contract-schema.d.ts +7 -0
  32. package/dist/contract-schema.js +156 -0
  33. package/dist/contracts.d.ts +72 -0
  34. package/dist/contracts.js +370 -0
  35. package/dist/core.d.ts +44 -0
  36. package/dist/core.js +43 -0
  37. package/dist/db-final-answer.d.ts +9 -0
  38. package/dist/db-final-answer.js +62 -0
  39. package/dist/define.d.ts +78 -0
  40. package/dist/define.js +14 -0
  41. package/dist/doctor.d.ts +22 -0
  42. package/dist/doctor.js +91 -0
  43. package/dist/drift.d.ts +23 -0
  44. package/dist/drift.js +111 -0
  45. package/dist/execution.d.ts +38 -0
  46. package/dist/execution.js +66 -0
  47. package/dist/extract.d.ts +34 -0
  48. package/dist/extract.js +73 -0
  49. package/dist/final-answer-stores.d.ts +71 -0
  50. package/dist/final-answer-stores.js +72 -0
  51. package/dist/final-answer.d.ts +32 -0
  52. package/dist/final-answer.js +104 -0
  53. package/dist/impact.d.ts +48 -0
  54. package/dist/impact.js +71 -0
  55. package/dist/index.d.ts +51 -0
  56. package/dist/index.js +47 -0
  57. package/dist/local-tool.d.ts +18 -0
  58. package/dist/local-tool.js +32 -0
  59. package/dist/mcp-apps.d.ts +53 -0
  60. package/dist/mcp-apps.js +32 -0
  61. package/dist/mcp-event-delivery.d.ts +98 -0
  62. package/dist/mcp-event-delivery.js +211 -0
  63. package/dist/mcp-extensions.d.ts +46 -0
  64. package/dist/mcp-extensions.js +200 -0
  65. package/dist/mcp-peer.d.ts +45 -0
  66. package/dist/mcp-peer.js +207 -0
  67. package/dist/mcp-server-card.d.ts +21 -0
  68. package/dist/mcp-server-card.js +54 -0
  69. package/dist/ordered-transport.d.ts +12 -0
  70. package/dist/ordered-transport.js +106 -0
  71. package/dist/page-checkpoint.d.ts +71 -0
  72. package/dist/page-checkpoint.js +286 -0
  73. package/dist/page-read-gate.d.ts +15 -0
  74. package/dist/page-read-gate.js +48 -0
  75. package/dist/pattern.d.ts +3 -0
  76. package/dist/pattern.js +54 -0
  77. package/dist/postgres.d.ts +41 -0
  78. package/dist/postgres.js +264 -0
  79. package/dist/probe.d.ts +29 -0
  80. package/dist/probe.js +121 -0
  81. package/dist/proxy.d.ts +40 -0
  82. package/dist/proxy.js +436 -0
  83. package/dist/read-pages.d.ts +25 -0
  84. package/dist/read-pages.js +85 -0
  85. package/dist/read-policy.d.ts +6 -0
  86. package/dist/read-policy.js +16 -0
  87. package/dist/read-steps.d.ts +12 -0
  88. package/dist/read-steps.js +36 -0
  89. package/dist/result-session.d.ts +109 -0
  90. package/dist/result-session.js +620 -0
  91. package/dist/route-checkpoint.d.ts +3 -0
  92. package/dist/route-checkpoint.js +80 -0
  93. package/dist/route-driver-cli.d.ts +3 -0
  94. package/dist/route-driver-cli.js +43 -0
  95. package/dist/route-evaluation.d.ts +141 -0
  96. package/dist/route-evaluation.js +329 -0
  97. package/dist/row-groups.d.ts +17 -0
  98. package/dist/row-groups.js +79 -0
  99. package/dist/row-query.d.ts +62 -0
  100. package/dist/row-query.js +172 -0
  101. package/dist/rules.d.ts +30 -0
  102. package/dist/rules.js +72 -0
  103. package/dist/run-diagnostics.d.ts +75 -0
  104. package/dist/run-diagnostics.js +212 -0
  105. package/dist/runtime.d.ts +6 -0
  106. package/dist/runtime.js +26 -0
  107. package/dist/schema.d.ts +17 -0
  108. package/dist/schema.js +299 -0
  109. package/dist/search-fetch.d.ts +50 -0
  110. package/dist/search-fetch.js +264 -0
  111. package/dist/shape.d.ts +91 -0
  112. package/dist/shape.js +499 -0
  113. package/dist/skill-files.d.ts +9 -0
  114. package/dist/skill-files.js +49 -0
  115. package/dist/splice-diagnostics.d.ts +44 -0
  116. package/dist/splice-diagnostics.js +88 -0
  117. package/dist/splice-measure.d.ts +33 -0
  118. package/dist/splice-measure.js +55 -0
  119. package/dist/splice-project.d.ts +125 -0
  120. package/dist/splice-project.js +348 -0
  121. package/dist/splice-recording.d.ts +132 -0
  122. package/dist/splice-recording.js +481 -0
  123. package/dist/splice.d.ts +181 -0
  124. package/dist/splice.js +1263 -0
  125. package/dist/sqlite-checkpoint-store.d.ts +5 -0
  126. package/dist/sqlite-checkpoint-store.js +91 -0
  127. package/dist/sqlite-checkpoint-worker.d.ts +1 -0
  128. package/dist/sqlite-checkpoint-worker.js +115 -0
  129. package/dist/storage.d.ts +17 -0
  130. package/dist/storage.js +1 -0
  131. package/dist/store.d.ts +151 -0
  132. package/dist/store.js +735 -0
  133. package/dist/test-difference.d.ts +13 -0
  134. package/dist/test-difference.js +42 -0
  135. package/dist/testing.d.ts +122 -0
  136. package/dist/testing.js +261 -0
  137. package/dist/text-pages.d.ts +24 -0
  138. package/dist/text-pages.js +36 -0
  139. package/dist/tool-discovery.d.ts +59 -0
  140. package/dist/tool-discovery.js +136 -0
  141. package/dist/unevaluated.d.ts +7 -0
  142. package/dist/unevaluated.js +156 -0
  143. package/dist/v2.d.ts +49 -0
  144. package/dist/v2.js +413 -0
  145. package/dist/validate-output.d.ts +3 -0
  146. package/dist/validate-output.js +73 -0
  147. package/dist/version.d.ts +1 -0
  148. package/dist/version.js +1 -0
  149. package/dist/workflow-json.d.ts +8 -0
  150. package/dist/workflow-json.js +74 -0
  151. package/docs/AGENT-FRAMEWORKS.md +431 -0
  152. package/docs/BENCHMARKS.md +43 -0
  153. package/docs/INTEGRATION-QUICKSTART.md +859 -0
  154. package/docs/LEARNING-AND-STORAGE.md +393 -0
  155. package/docs/MCP.md +204 -0
  156. package/docs/PROJECTS-AND-UPGRADES.md +173 -0
  157. package/docs/PYTHON-REFERENCE.md +348 -0
  158. package/docs/PYTHON.md +120 -0
  159. package/docs/RECORDING-AND-CORRECTIONS.md +205 -0
  160. package/docs/TESTING.md +259 -0
  161. package/examples/mcp-app/build.mjs +11 -0
  162. package/examples/mcp-app/view.mjs +22 -0
  163. package/examples/quickstart.mjs +43 -0
  164. package/examples/route-driver.mjs +67 -0
  165. package/integrations/ai.d.mts +36 -0
  166. package/integrations/ai.mjs +178 -0
  167. package/integrations/call-options.mjs +9 -0
  168. package/integrations/langchain.d.mts +31 -0
  169. package/integrations/langchain.mjs +114 -0
  170. package/integrations/managed.mjs +154 -0
  171. package/integrations/types.d.mts +13 -0
  172. package/package.json +139 -4
@@ -0,0 +1,5 @@
1
+ import type { FinalAnswerStore } from "./final-answer-stores.js";
2
+ /** A local, cross-process checkpoint store. Own one connection per worker and close it at shutdown. */
3
+ export declare function openSqliteCheckpointStore(filename: string): Promise<FinalAnswerStore & {
4
+ close(): Promise<void>;
5
+ }>;
@@ -0,0 +1,91 @@
1
+ import { Worker } from "node:worker_threads";
2
+ import { resolve } from "node:path";
3
+ /** A local, cross-process checkpoint store. Own one connection per worker and close it at shutdown. */
4
+ export async function openSqliteCheckpointStore(filename) {
5
+ if (typeof filename !== "string" || !filename || filename === ":memory:")
6
+ throw new TypeError("Provide a local SQLite database file.");
7
+ const worker = new Worker(new URL(new URL(import.meta.url).pathname.endsWith(".ts")
8
+ ? "./sqlite-checkpoint-worker.ts"
9
+ : "./sqlite-checkpoint-worker.js", import.meta.url), {
10
+ workerData: resolve(filename),
11
+ execArgv: [],
12
+ });
13
+ const batchSize = 64;
14
+ let sequence = 0;
15
+ let stopped;
16
+ let closing;
17
+ const pending = new Map();
18
+ const queue = [];
19
+ let scheduled;
20
+ function flush() {
21
+ if (scheduled)
22
+ clearImmediate(scheduled);
23
+ scheduled = undefined;
24
+ for (let start = 0; start < queue.length; start += batchSize)
25
+ worker.postMessage({ batch: queue.slice(start, start + batchSize) });
26
+ queue.length = 0;
27
+ }
28
+ function stop(error) {
29
+ stopped ??= error;
30
+ if (scheduled)
31
+ clearImmediate(scheduled);
32
+ queue.length = 0;
33
+ for (const request of pending.values())
34
+ request.reject(error);
35
+ pending.clear();
36
+ }
37
+ worker.on("error", stop);
38
+ worker.on("exit", () => stop(new Error("SQLite checkpoint connection closed.")));
39
+ worker.on("message", (message) => {
40
+ for (const reply of Array.isArray(message) ? message : [message]) {
41
+ const item = pending.get(reply.id);
42
+ if (!item)
43
+ continue;
44
+ pending.delete(reply.id);
45
+ if (reply.error !== undefined)
46
+ item.reject(new Error(reply.error));
47
+ else
48
+ item.resolve(reply.value);
49
+ }
50
+ if (!pending.size)
51
+ worker.unref();
52
+ });
53
+ function request(method, ...args) {
54
+ // A malformed binding must never roll back another job in the same commit.
55
+ // SQLite UTF-8 bindings would silently replace an unpaired JS surrogate.
56
+ if (args.some((value) => typeof value !== "string" || /[\uD800-\uDFFF]/u.test(value)))
57
+ return Promise.reject(new TypeError("SQLite checkpoint arguments must be valid Unicode strings."));
58
+ if (closing || stopped)
59
+ return Promise.reject(stopped ?? new Error("SQLite checkpoint connection is closing."));
60
+ const id = ++sequence;
61
+ return new Promise((resolve, reject) => {
62
+ pending.set(id, { resolve: (value) => resolve(value), reject });
63
+ worker.ref();
64
+ if (method === "open" || method === "close") {
65
+ flush();
66
+ worker.postMessage({ id, method, args });
67
+ }
68
+ else {
69
+ queue.push({ id, method, args });
70
+ scheduled ??= setImmediate(flush);
71
+ }
72
+ });
73
+ }
74
+ try {
75
+ await request("open");
76
+ }
77
+ catch (error) {
78
+ await worker.terminate();
79
+ throw error;
80
+ }
81
+ return {
82
+ read: (job) => request("read", job),
83
+ claim: (job, identity) => request("claim", job, identity),
84
+ complete: (job, identity, payload) => request("complete", job, identity, payload),
85
+ close() {
86
+ return (closing ??= request("close").finally(async () => {
87
+ await worker.terminate();
88
+ }));
89
+ },
90
+ };
91
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,115 @@
1
+ import { DatabaseSync } from "node:sqlite";
2
+ import { closeSync, openSync } from "node:fs";
3
+ import { parentPort, workerData } from "node:worker_threads";
4
+ import { setTimeout as wait } from "node:timers/promises";
5
+ const port = parentPort;
6
+ let db;
7
+ let read, claim, complete;
8
+ async function enableWal(db) {
9
+ const deadline = performance.now() + 5000;
10
+ for (let delay = 5;; delay = Math.min(delay * 2, 100)) {
11
+ try {
12
+ return db.prepare("PRAGMA journal_mode=WAL").get();
13
+ }
14
+ catch (error) {
15
+ const code = error.errcode ?? 0;
16
+ if ((code & 255) !== 5 || performance.now() >= deadline)
17
+ throw error;
18
+ // SQLite may skip its busy handler when concurrent openers upgrade journal mode.
19
+ await wait(Math.min(delay, Math.max(0, deadline - performance.now())));
20
+ }
21
+ }
22
+ }
23
+ async function open() {
24
+ const version = process.versions.sqlite;
25
+ if (!version)
26
+ throw new Error("A Node build with SQLite is required.");
27
+ const [major, minor, patch] = version.split(".").map(Number);
28
+ const fixed = major > 3 ||
29
+ (major === 3 &&
30
+ (minor > 51 ||
31
+ (minor === 51 && patch >= 3) ||
32
+ (minor === 50 && patch >= 7) ||
33
+ (minor === 44 && patch >= 6)));
34
+ if (!fixed)
35
+ throw new Error("SQLite " +
36
+ version +
37
+ " requires a WAL-reset fix. Use 3.51.3 or later, or a patched 3.50.7/3.44.6 release.");
38
+ // Only the creator sets the mode. Application-owned files keep their existing permissions.
39
+ try {
40
+ closeSync(openSync(workerData, "wx", 0o600));
41
+ }
42
+ catch (error) {
43
+ if (error.code !== "EEXIST")
44
+ throw error;
45
+ }
46
+ db = new DatabaseSync(workerData);
47
+ db.exec("PRAGMA busy_timeout=5000; PRAGMA fullfsync=ON; PRAGMA synchronous=FULL");
48
+ const mode = await enableWal(db);
49
+ if (mode?.journal_mode !== "wal" ||
50
+ db.prepare("PRAGMA fullfsync").get()?.fullfsync !== 1 ||
51
+ db.prepare("PRAGMA synchronous").get()?.synchronous !== 2)
52
+ throw new Error("Could not enable durable SQLite WAL mode.");
53
+ db.exec("CREATE TABLE IF NOT EXISTS toolsplice_checkpoints (job TEXT PRIMARY KEY, identity TEXT NOT NULL, payload TEXT) WITHOUT ROWID");
54
+ read = db.prepare("SELECT identity,payload FROM toolsplice_checkpoints WHERE job=?");
55
+ claim = db.prepare("INSERT INTO toolsplice_checkpoints(job,identity) VALUES(?,?) ON CONFLICT(job) DO NOTHING");
56
+ complete = db.prepare("UPDATE toolsplice_checkpoints SET payload=? WHERE job=? AND identity=? AND payload IS NULL");
57
+ }
58
+ function execute({ method, args: [job, identity, payload] }) {
59
+ switch (method) {
60
+ case "read":
61
+ return read.get(job) ?? null;
62
+ case "claim":
63
+ return claim.run(job, identity).changes === 1;
64
+ case "complete":
65
+ return complete.run(payload, job, identity).changes === 1;
66
+ default:
67
+ throw new Error("Unknown SQLite checkpoint operation.");
68
+ }
69
+ }
70
+ function dispatch(batch) {
71
+ const group = batch.length > 1 && batch.some((op) => op.method !== "read");
72
+ let inTransaction = false;
73
+ try {
74
+ if (group) {
75
+ db.exec("BEGIN IMMEDIATE");
76
+ inTransaction = true;
77
+ }
78
+ const replies = batch.map((op) => ({ id: op.id, value: execute(op) }));
79
+ if (group)
80
+ db.exec("COMMIT");
81
+ port.postMessage(replies);
82
+ }
83
+ catch (error) {
84
+ if (inTransaction && db.isTransaction)
85
+ db.exec("ROLLBACK");
86
+ const reason = error instanceof Error ? error.message : String(error);
87
+ port.postMessage(batch.map((op) => ({ id: op.id, error: reason })));
88
+ }
89
+ }
90
+ port.on("message", async (message) => {
91
+ if ("batch" in message) {
92
+ dispatch(message.batch);
93
+ return;
94
+ }
95
+ const { id, method } = message;
96
+ try {
97
+ if (method === "open")
98
+ await open();
99
+ else if (method === "close") {
100
+ db?.close();
101
+ db = undefined;
102
+ }
103
+ else
104
+ throw new Error("Unknown SQLite connection operation.");
105
+ port.postMessage({ id });
106
+ }
107
+ catch (error) {
108
+ if (method === "open")
109
+ db?.close();
110
+ port.postMessage({
111
+ id,
112
+ error: error instanceof Error ? error.message : String(error),
113
+ });
114
+ }
115
+ });
@@ -0,0 +1,17 @@
1
+ import type { ServerRecord, ShapeStoreDiagnostic } from "./store.js";
2
+ export type Awaitable<T> = T | Promise<T>;
3
+ /** Backends must serialize mutations against the latest committed record.
4
+ * Mutators are synchronous and must not perform external effects. Never retry a
5
+ * mutator after entry: a failed commit can have an unknown outcome. */
6
+ export interface LearningStore {
7
+ load(name: string, version?: string): Awaitable<ServerRecord>;
8
+ refresh(name: string): Awaitable<ServerRecord | undefined>;
9
+ has(name: string): Awaitable<boolean>;
10
+ list(): Awaitable<string[]>;
11
+ transact<T>(name: string, mutate: (record: ServerRecord) => T): Awaitable<T>;
12
+ remove(name: string): Awaitable<void>;
13
+ diagnostics?(): Awaitable<ShapeStoreDiagnostic[]>;
14
+ watch?(name: string, onChange: () => void, onError?: () => void): () => void;
15
+ /** The application owns backend lifetime; closing one proxy must not close a shared store. */
16
+ close?(): Awaitable<void>;
17
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,151 @@
1
+ import type { Extracted, OutputKind } from "./extract.js";
2
+ import { type JsonSchema } from "./schema.js";
3
+ import { type ObserveOptions, type Shape } from "./shape.js";
4
+ export interface ToolAnnotations {
5
+ title?: string;
6
+ readOnlyHint?: boolean;
7
+ destructiveHint?: boolean;
8
+ idempotentHint?: boolean;
9
+ openWorldHint?: boolean;
10
+ }
11
+ export interface ToolRecord {
12
+ name: string;
13
+ description?: string;
14
+ inputSchema?: JsonSchema;
15
+ /** outputSchema the server itself declares, if any. */
16
+ outputSchema?: JsonSchema;
17
+ annotations?: ToolAnnotations;
18
+ drift?: import("./drift.js").DriftState;
19
+ schemaValidation?: {
20
+ checked: number;
21
+ mismatches: number;
22
+ latest: "valid" | "mismatch" | "unverified";
23
+ paths: string[];
24
+ };
25
+ calls: number;
26
+ kinds: Record<OutputKind, number>;
27
+ /** Learned from structuredContent and JSON text results. */
28
+ shape: Shape;
29
+ textSamples: string[];
30
+ errorSamples: string[];
31
+ prefixes: string[];
32
+ updatedAt?: string;
33
+ }
34
+ export interface ServerRecord {
35
+ exportedAt?: string;
36
+ exportedFingerprint?: string;
37
+ name: string;
38
+ version?: string;
39
+ tools: Record<string, ToolRecord>;
40
+ updatedAt?: string;
41
+ }
42
+ export interface ToolListEntry {
43
+ name: string;
44
+ description?: string;
45
+ inputSchema?: unknown;
46
+ outputSchema?: unknown;
47
+ annotations?: ToolAnnotations;
48
+ }
49
+ export declare function newServer(name: string, version?: string): ServerRecord;
50
+ export declare function newTool(name: string): ToolRecord;
51
+ export declare function recordToolList(server: ServerRecord, tools: ToolListEntry[]): void;
52
+ /**
53
+ * Reapply privacy to retained learning across every tool, including tools absent from a new list.
54
+ * Mutates learned shapes and text/error/prefix samples only. Server-declared schemas (including
55
+ * their examples/defaults), descriptions, annotations, and other metadata are outside this scope.
56
+ * Call inside transact on load/list to persist a policy change before any tool calls occur.
57
+ */
58
+ export declare function applyExamplePolicy(server: ServerRecord, options?: ObserveOptions): void;
59
+ export declare function recordCall(server: ServerRecord, toolName: string, result: Extracted, options?: ObserveOptions): ToolRecord;
60
+ /** Masks things that look like paths, emails, ids and tokens in a short message. */
61
+ export declare function scrub(text: string): string;
62
+ export interface ToolOutput {
63
+ /** Undefined when the tool has only ever returned plain text. */
64
+ schema?: JsonSchema;
65
+ source: "declared" | "learned";
66
+ encoding: "structured" | "json-text" | "text";
67
+ samples: number;
68
+ /** The tool returned JSON most of the time but sometimes plain text (often "no results"). */
69
+ alsoText: boolean;
70
+ /** A successful response without text/structured data decodes to null. */
71
+ alsoEmpty?: boolean;
72
+ textSample?: string;
73
+ prefix?: string;
74
+ warning?: string;
75
+ }
76
+ /** The best available description of what a tool returns. */
77
+ export declare function toolOutput(tool: ToolRecord): ToolOutput | undefined;
78
+ /**
79
+ * Copies learned examples and observed values onto the matching properties of a declared schema.
80
+ * A declared `{ content: string }` says nothing about what the string looks like; an example does.
81
+ */
82
+ export declare function withLearnedExamples(declared: JsonSchema, learned: JsonSchema): JsonSchema;
83
+ export interface ShapeStoreOptions {
84
+ /** Diagnostics from list(), which skips unreadable/corrupt entries. Never includes file contents. */
85
+ onWarning?: (message: string) => void;
86
+ }
87
+ export interface ShapeStoreDiagnostic {
88
+ file: string;
89
+ kind: "locked" | "orphan-temp";
90
+ pid?: number;
91
+ owner: "running" | "not-running" | "unknown";
92
+ }
93
+ export declare class ShapeStoreError extends Error {
94
+ readonly code: "CORRUPT" | "IDENTITY" | "CONFLICT" | "LOCKED" | "IO";
95
+ constructor(code: "CORRUPT" | "IDENTITY" | "CONFLICT" | "LOCKED" | "IO", message: string, cause?: unknown);
96
+ }
97
+ /**
98
+ * Explicit reads and writes throw on failure; a proxy should catch recording failures.
99
+ * Saves are atomic and reject stale snapshots instead of silently losing another writer's data.
100
+ * Locks are nonblocking: after a crashed writer, inspect/remove its .lock file before retrying.
101
+ * PID/inode checks cannot make stale-lock unlink atomic, so locks are never auto-reclaimed.
102
+ * SIGKILL can leave one private .tmp per in-flight write; repeated manual recovery/crashes can
103
+ * accumulate orphans. Inspect/clean these only after stopping writers.
104
+ */
105
+ export declare class ShapeStore {
106
+ readonly dir: string;
107
+ private readonly options;
108
+ private cache;
109
+ private snapshots;
110
+ constructor(dir: string, options?: ShapeStoreOptions);
111
+ /** Read disk without consulting an old session's cache, including external forget. */
112
+ refresh(name: string): ServerRecord | undefined;
113
+ watch(_name: string, onChange: () => void, onError?: () => void): () => void;
114
+ load(name: string, version?: string): ServerRecord;
115
+ has(name: string): boolean;
116
+ save(name: string): void;
117
+ /**
118
+ * Apply one synchronous mutation to the latest persisted record while holding its writer lock.
119
+ * If no file exists, reuse only a never-persisted cache as a detached copy. A previously
120
+ * persisted record that disappeared starts fresh, respecting another process's forget.
121
+ * A successful return means the write committed and the cache/save baseline were refreshed.
122
+ *
123
+ * A throw has NO return value and does NOT imply the mutator was never called: read/lock
124
+ * failures precede it, while serialization/write failures follow it. The mutator is never
125
+ * retried internally. For fail-open recording, capture its record and mark callback entry;
126
+ * if it ran, use that in-memory record without applying the mutation again. The cache is
127
+ * replaced only on success; failed callback records remain available only to their caller.
128
+ * Unsaved local changes are superseded whenever a persisted record exists. Callbacks must
129
+ * not perform upstream calls or other irreversible effects. Existing locks fail with LOCKED.
130
+ */
131
+ transact<T>(name: string, mutate: (record: ServerRecord) => T): T;
132
+ /** Forget only files whose validated identity matches name. Never contacts the server. */
133
+ remove(name: string): void;
134
+ list(): string[];
135
+ /**
136
+ * Read-only, best-effort snapshot of lock/temp artifacts; never reclaims or reads result data.
137
+ * Each lock read is bounded to 64 bytes. Symlinks/nonregular/unreadable locks report unknown.
138
+ * Temp PIDs come only from recognized filenames; their contents are never opened.
139
+ * A temp may belong to an active write. Liveness is advisory, not permission to delete: PID
140
+ * reuse, concurrent file replacement, and process namespaces prevent reliable ownership proof.
141
+ */
142
+ diagnostics(): ShapeStoreDiagnostic[];
143
+ private locate;
144
+ private fileFor;
145
+ private legacyFileFor;
146
+ private serialize;
147
+ private cleanup;
148
+ private warn;
149
+ }
150
+ /** Internal shared validation for persistent backends. The label must not contain credentials. */
151
+ export declare function decodeStoredRecord(raw: string, name: string): ServerRecord;