agent-cli-runtime 0.1.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (151) hide show
  1. package/CHANGELOG.md +51 -0
  2. package/CONTRIBUTING.md +60 -0
  3. package/LICENSE +202 -0
  4. package/README.md +573 -0
  5. package/README.zh-CN.md +571 -0
  6. package/SECURITY.md +35 -0
  7. package/dist/adapters/adapter-types.d.ts +138 -0
  8. package/dist/adapters/adapter-types.js +2 -0
  9. package/dist/adapters/adapter-types.js.map +1 -0
  10. package/dist/adapters/claude.d.ts +2 -0
  11. package/dist/adapters/claude.js +97 -0
  12. package/dist/adapters/claude.js.map +1 -0
  13. package/dist/adapters/codex.d.ts +3 -0
  14. package/dist/adapters/codex.js +120 -0
  15. package/dist/adapters/codex.js.map +1 -0
  16. package/dist/adapters/opencode.d.ts +4 -0
  17. package/dist/adapters/opencode.js +111 -0
  18. package/dist/adapters/opencode.js.map +1 -0
  19. package/dist/adapters/registry.d.ts +9 -0
  20. package/dist/adapters/registry.js +23 -0
  21. package/dist/adapters/registry.js.map +1 -0
  22. package/dist/cli/main.d.ts +2 -0
  23. package/dist/cli/main.js +978 -0
  24. package/dist/cli/main.js.map +1 -0
  25. package/dist/core/async-queue.d.ts +10 -0
  26. package/dist/core/async-queue.js +49 -0
  27. package/dist/core/async-queue.js.map +1 -0
  28. package/dist/core/diagnostics.d.ts +20 -0
  29. package/dist/core/diagnostics.js +4 -0
  30. package/dist/core/diagnostics.js.map +1 -0
  31. package/dist/core/event-contract.d.ts +32 -0
  32. package/dist/core/event-contract.js +128 -0
  33. package/dist/core/event-contract.js.map +1 -0
  34. package/dist/core/events.d.ts +147 -0
  35. package/dist/core/events.js +4 -0
  36. package/dist/core/events.js.map +1 -0
  37. package/dist/core/ids.d.ts +1 -0
  38. package/dist/core/ids.js +5 -0
  39. package/dist/core/ids.js.map +1 -0
  40. package/dist/core/redaction.d.ts +4 -0
  41. package/dist/core/redaction.js +51 -0
  42. package/dist/core/redaction.js.map +1 -0
  43. package/dist/core/runtime.d.ts +41 -0
  44. package/dist/core/runtime.js +83 -0
  45. package/dist/core/runtime.js.map +1 -0
  46. package/dist/core/schema-contract.d.ts +55 -0
  47. package/dist/core/schema-contract.js +143 -0
  48. package/dist/core/schema-contract.js.map +1 -0
  49. package/dist/detection/detect.d.ts +14 -0
  50. package/dist/detection/detect.js +293 -0
  51. package/dist/detection/detect.js.map +1 -0
  52. package/dist/detection/env.d.ts +2 -0
  53. package/dist/detection/env.js +15 -0
  54. package/dist/detection/env.js.map +1 -0
  55. package/dist/detection/executable-resolution.d.ts +12 -0
  56. package/dist/detection/executable-resolution.js +50 -0
  57. package/dist/detection/executable-resolution.js.map +1 -0
  58. package/dist/detection/invocation.d.ts +9 -0
  59. package/dist/detection/invocation.js +22 -0
  60. package/dist/detection/invocation.js.map +1 -0
  61. package/dist/goals/goal-scheduler.d.ts +31 -0
  62. package/dist/goals/goal-scheduler.js +518 -0
  63. package/dist/goals/goal-scheduler.js.map +1 -0
  64. package/dist/goals/goal-store.d.ts +37 -0
  65. package/dist/goals/goal-store.js +300 -0
  66. package/dist/goals/goal-store.js.map +1 -0
  67. package/dist/goals/goal-types.d.ts +103 -0
  68. package/dist/goals/goal-types.js +2 -0
  69. package/dist/goals/goal-types.js.map +1 -0
  70. package/dist/goals/planner-prompts.d.ts +3 -0
  71. package/dist/goals/planner-prompts.js +26 -0
  72. package/dist/goals/planner-prompts.js.map +1 -0
  73. package/dist/goals/task-graph.d.ts +9 -0
  74. package/dist/goals/task-graph.js +229 -0
  75. package/dist/goals/task-graph.js.map +1 -0
  76. package/dist/goals/validation-runner.d.ts +7 -0
  77. package/dist/goals/validation-runner.js +63 -0
  78. package/dist/goals/validation-runner.js.map +1 -0
  79. package/dist/index.d.ts +11 -0
  80. package/dist/index.js +2 -0
  81. package/dist/index.js.map +1 -0
  82. package/dist/parsers/claude-stream-json.d.ts +11 -0
  83. package/dist/parsers/claude-stream-json.js +102 -0
  84. package/dist/parsers/claude-stream-json.js.map +1 -0
  85. package/dist/parsers/codex-json.d.ts +8 -0
  86. package/dist/parsers/codex-json.js +107 -0
  87. package/dist/parsers/codex-json.js.map +1 -0
  88. package/dist/parsers/line-buffer.d.ts +7 -0
  89. package/dist/parsers/line-buffer.js +28 -0
  90. package/dist/parsers/line-buffer.js.map +1 -0
  91. package/dist/parsers/opencode-json.d.ts +8 -0
  92. package/dist/parsers/opencode-json.js +72 -0
  93. package/dist/parsers/opencode-json.js.map +1 -0
  94. package/dist/parsers/plain-lines.d.ts +6 -0
  95. package/dist/parsers/plain-lines.js +9 -0
  96. package/dist/parsers/plain-lines.js.map +1 -0
  97. package/dist/public-types.d.ts +143 -0
  98. package/dist/public-types.js +2 -0
  99. package/dist/public-types.js.map +1 -0
  100. package/dist/runs/process-runner.d.ts +35 -0
  101. package/dist/runs/process-runner.js +97 -0
  102. package/dist/runs/process-runner.js.map +1 -0
  103. package/dist/runs/prompt-transport.d.ts +10 -0
  104. package/dist/runs/prompt-transport.js +43 -0
  105. package/dist/runs/prompt-transport.js.map +1 -0
  106. package/dist/runs/run-result.d.ts +9 -0
  107. package/dist/runs/run-result.js +22 -0
  108. package/dist/runs/run-result.js.map +1 -0
  109. package/dist/runs/run-scheduler.d.ts +25 -0
  110. package/dist/runs/run-scheduler.js +552 -0
  111. package/dist/runs/run-scheduler.js.map +1 -0
  112. package/dist/runs/run-store.d.ts +42 -0
  113. package/dist/runs/run-store.js +297 -0
  114. package/dist/runs/run-store.js.map +1 -0
  115. package/dist/runs/run-types.d.ts +59 -0
  116. package/dist/runs/run-types.js +2 -0
  117. package/dist/runs/run-types.js.map +1 -0
  118. package/dist/smoke/parser-samples.d.ts +17 -0
  119. package/dist/smoke/parser-samples.js +186 -0
  120. package/dist/smoke/parser-samples.js.map +1 -0
  121. package/dist/storage/file-storage.d.ts +35 -0
  122. package/dist/storage/file-storage.js +271 -0
  123. package/dist/storage/file-storage.js.map +1 -0
  124. package/dist/storage/jsonl-store.d.ts +9 -0
  125. package/dist/storage/jsonl-store.js +138 -0
  126. package/dist/storage/jsonl-store.js.map +1 -0
  127. package/dist/storage/manifest-validation.d.ts +11 -0
  128. package/dist/storage/manifest-validation.js +102 -0
  129. package/dist/storage/manifest-validation.js.map +1 -0
  130. package/dist/storage/storage-lease.d.ts +40 -0
  131. package/dist/storage/storage-lease.js +223 -0
  132. package/dist/storage/storage-lease.js.map +1 -0
  133. package/dist/storage/storage-types.d.ts +55 -0
  134. package/dist/storage/storage-types.js +2 -0
  135. package/dist/storage/storage-types.js.map +1 -0
  136. package/dist/storage/store-inspection.d.ts +28 -0
  137. package/dist/storage/store-inspection.js +941 -0
  138. package/dist/storage/store-inspection.js.map +1 -0
  139. package/docs/api-schema-contract.md +92 -0
  140. package/docs/compatibility.md +832 -0
  141. package/docs/daemon-ready-contract.md +283 -0
  142. package/docs/production-readiness.md +281 -0
  143. package/docs/release-checklist.md +257 -0
  144. package/docs/release-publish-runbook.md +201 -0
  145. package/docs/release-report.md +517 -0
  146. package/docs/ssot.md +1257 -0
  147. package/examples/cli-dogfood.md +113 -0
  148. package/examples/library-goal.js +94 -0
  149. package/examples/library-run.js +84 -0
  150. package/package.json +79 -0
  151. package/scripts/dogfood.mjs +243 -0
@@ -0,0 +1,223 @@
1
+ import { appendFileSync, closeSync, existsSync, ftruncateSync, mkdirSync, openSync, readFileSync, unlinkSync, writeFileSync, writeSync } from "node:fs";
2
+ import path from "node:path";
3
+ import { createId } from "../core/ids.js";
4
+ import { redactUnknown } from "../core/redaction.js";
5
+ export const STORAGE_LOCK_FILE = "runtime.lock.json";
6
+ export const DEFAULT_LEASE_STALE_MS = 30_000;
7
+ export class StorageLease {
8
+ storageDir;
9
+ owner;
10
+ staleMs;
11
+ faults;
12
+ closed = false;
13
+ lost = false;
14
+ constructor(storageDir, owner, staleMs, faults = {}) {
15
+ this.storageDir = storageDir;
16
+ this.owner = owner;
17
+ this.staleMs = staleMs;
18
+ this.faults = faults;
19
+ }
20
+ static acquire(storageDir, init = {}) {
21
+ const staleMs = init.staleMs ?? DEFAULT_LEASE_STALE_MS;
22
+ mkdirSync(storageDir, { recursive: true });
23
+ const owner = createRuntimeOwner();
24
+ const lockPath = path.join(storageDir, STORAGE_LOCK_FILE);
25
+ const diagnostics = [];
26
+ while (true) {
27
+ try {
28
+ init.faults?.beforeAcquire?.(lockPath);
29
+ const fd = openSync(lockPath, "wx");
30
+ try {
31
+ writeFileSync(fd, `${JSON.stringify(owner, null, 2)}\n`, "utf8");
32
+ }
33
+ finally {
34
+ closeSync(fd);
35
+ }
36
+ if (diagnostics.length > 0)
37
+ appendLeaseDiagnostics(storageDir, diagnostics);
38
+ return new StorageLease(storageDir, owner, staleMs, init.faults);
39
+ }
40
+ catch (error) {
41
+ if (!isFileExistsError(error))
42
+ throw error;
43
+ const inspection = inspectStorageLock(storageDir, { staleMs });
44
+ if (inspection.status !== "stale" && inspection.status !== "closed" && inspection.status !== "invalid") {
45
+ const heldBy = inspection.owner ? `pid ${inspection.owner.pid}` : "another runtime";
46
+ throw new Error(`storageDir is already open for writing by ${heldBy}; use read-only inspection commands or wait for the owner to close`);
47
+ }
48
+ diagnostics.push(`Storage lock takeover: previous owner was ${inspection.status}${inspection.reason ? ` (${inspection.reason})` : ""}.`);
49
+ try {
50
+ unlinkSync(lockPath);
51
+ }
52
+ catch (unlinkError) {
53
+ if (existsSync(lockPath))
54
+ throw unlinkError;
55
+ }
56
+ }
57
+ }
58
+ }
59
+ currentOwner() {
60
+ return { ...this.owner };
61
+ }
62
+ ownsCurrentLock() {
63
+ if (this.closed || this.lost)
64
+ return false;
65
+ let fd;
66
+ try {
67
+ fd = openSync(path.join(this.storageDir, STORAGE_LOCK_FILE), "r");
68
+ const current = parseRuntimeOwner(JSON.parse(readFileSync(fd, "utf8")));
69
+ if (current?.runtimeInstanceId !== this.owner.runtimeInstanceId) {
70
+ this.lost = true;
71
+ return false;
72
+ }
73
+ return true;
74
+ }
75
+ catch {
76
+ this.lost = true;
77
+ return false;
78
+ }
79
+ finally {
80
+ if (fd !== undefined)
81
+ closeSync(fd);
82
+ }
83
+ }
84
+ heartbeat() {
85
+ if (this.closed || this.lost)
86
+ return undefined;
87
+ this.owner.heartbeatAt = Date.now();
88
+ if (!this.writeIfCurrentOwner(this.owner))
89
+ return undefined;
90
+ return this.currentOwner();
91
+ }
92
+ close() {
93
+ if (this.closed || this.lost)
94
+ return undefined;
95
+ this.closed = true;
96
+ this.owner.heartbeatAt = Date.now();
97
+ this.owner.closedAt = this.owner.heartbeatAt;
98
+ this.faults.beforeClose?.(path.join(this.storageDir, STORAGE_LOCK_FILE));
99
+ if (!this.writeIfCurrentOwner(this.owner))
100
+ return undefined;
101
+ return this.currentOwner();
102
+ }
103
+ writeIfCurrentOwner(owner) {
104
+ let fd;
105
+ try {
106
+ fd = openSync(path.join(this.storageDir, STORAGE_LOCK_FILE), "r+");
107
+ const current = parseRuntimeOwner(JSON.parse(readFileSync(fd, "utf8")));
108
+ if (current?.runtimeInstanceId !== this.owner.runtimeInstanceId) {
109
+ this.lost = true;
110
+ return false;
111
+ }
112
+ ftruncateSync(fd, 0);
113
+ writeSync(fd, `${JSON.stringify(redactUnknown(owner), null, 2)}\n`, 0, "utf8");
114
+ return true;
115
+ }
116
+ catch {
117
+ this.lost = true;
118
+ return false;
119
+ }
120
+ finally {
121
+ if (fd !== undefined)
122
+ closeSync(fd);
123
+ }
124
+ }
125
+ }
126
+ export function createRuntimeOwner() {
127
+ const now = Date.now();
128
+ return {
129
+ runtimeInstanceId: createId("runtime"),
130
+ pid: process.pid,
131
+ startedAt: now,
132
+ heartbeatAt: now,
133
+ };
134
+ }
135
+ export function inspectStorageLock(storageDir, init = {}) {
136
+ const staleMs = init.staleMs ?? DEFAULT_LEASE_STALE_MS;
137
+ const file = STORAGE_LOCK_FILE;
138
+ const lockPath = path.join(storageDir, STORAGE_LOCK_FILE);
139
+ if (!existsSync(lockPath))
140
+ return { file, status: "missing", staleMs, diagnostics: [] };
141
+ try {
142
+ const parsed = JSON.parse(readFileSync(lockPath, "utf8"));
143
+ const owner = parseRuntimeOwner(parsed);
144
+ if (!owner)
145
+ return { file, status: "invalid", staleMs, diagnostics: ["Storage lock owner is invalid."] };
146
+ const inspected = inspectOwner(owner, { staleMs });
147
+ return redactUnknown({ file, staleMs, diagnostics: [], ...inspected });
148
+ }
149
+ catch (error) {
150
+ return {
151
+ file,
152
+ status: "invalid",
153
+ staleMs,
154
+ diagnostics: [error instanceof Error ? error.message : String(error)],
155
+ };
156
+ }
157
+ }
158
+ export function inspectOwner(owner, init = {}) {
159
+ if (!owner)
160
+ return { status: "missing", reason: "owner metadata is missing" };
161
+ const now = init.now ?? Date.now();
162
+ const staleMs = init.staleMs ?? DEFAULT_LEASE_STALE_MS;
163
+ const ageMs = Math.max(0, now - owner.heartbeatAt);
164
+ if (owner.closedAt !== undefined)
165
+ return { status: "closed", owner, ageMs, reason: "owner closed the lease" };
166
+ if (ageMs > staleMs)
167
+ return { status: "stale", owner, ageMs, reason: "owner heartbeat is stale" };
168
+ if (!isPidAlive(owner.pid))
169
+ return { status: "stale", owner, ageMs, reason: "owner process is not alive" };
170
+ return { status: "live", owner, ageMs };
171
+ }
172
+ export function parseRuntimeOwner(value) {
173
+ if (!value || typeof value !== "object" || Array.isArray(value))
174
+ return undefined;
175
+ const record = value;
176
+ if (typeof record.runtimeInstanceId !== "string")
177
+ return undefined;
178
+ if (typeof record.pid !== "number")
179
+ return undefined;
180
+ if (typeof record.startedAt !== "number" || typeof record.heartbeatAt !== "number")
181
+ return undefined;
182
+ if ("closedAt" in record && record.closedAt !== undefined && typeof record.closedAt !== "number")
183
+ return undefined;
184
+ return {
185
+ runtimeInstanceId: record.runtimeInstanceId,
186
+ pid: record.pid,
187
+ startedAt: record.startedAt,
188
+ heartbeatAt: record.heartbeatAt,
189
+ closedAt: typeof record.closedAt === "number" ? record.closedAt : undefined,
190
+ };
191
+ }
192
+ function appendLeaseDiagnostics(storageDir, messages) {
193
+ for (const message of messages) {
194
+ try {
195
+ appendFileSync(path.join(storageDir, "diagnostics.jsonl"), `${JSON.stringify(redactUnknown({
196
+ timestamp: Date.now(),
197
+ diagnostic: {
198
+ code: "AGENT_STORAGE_LEASE_TAKEOVER",
199
+ message,
200
+ retryable: false,
201
+ },
202
+ }))}\n`, "utf8");
203
+ }
204
+ catch {
205
+ // Lease diagnostics must never block lock acquisition.
206
+ }
207
+ }
208
+ }
209
+ function isPidAlive(pid) {
210
+ if (!Number.isInteger(pid) || pid <= 0)
211
+ return false;
212
+ try {
213
+ process.kill(pid, 0);
214
+ return true;
215
+ }
216
+ catch {
217
+ return false;
218
+ }
219
+ }
220
+ function isFileExistsError(error) {
221
+ return Boolean(error && typeof error === "object" && "code" in error && error.code === "EEXIST");
222
+ }
223
+ //# sourceMappingURL=storage-lease.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storage-lease.js","sourceRoot":"","sources":["../../src/storage/storage-lease.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,UAAU,EAAE,aAAa,EAAE,SAAS,EAAE,QAAQ,EAAE,YAAY,EAAE,UAAU,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACxJ,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAGrD,MAAM,CAAC,MAAM,iBAAiB,GAAG,mBAAmB,CAAC;AACrD,MAAM,CAAC,MAAM,sBAAsB,GAAG,MAAM,CAAC;AAc7C,MAAM,OAAO,YAAY;IAKJ;IACA;IACA;IACA;IAPX,MAAM,GAAG,KAAK,CAAC;IACf,IAAI,GAAG,KAAK,CAAC;IAErB,YACmB,UAAkB,EAClB,KAAmB,EACnB,OAAe,EACf,SAAiC,EAAE;QAHnC,eAAU,GAAV,UAAU,CAAQ;QAClB,UAAK,GAAL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AAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,IAAI,KAAK,IAAK,KAA4B,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC;AAC3H,CAAC"}
@@ -0,0 +1,55 @@
1
+ import type { ReplayEvent } from "../core/events.js";
2
+ import type { GoalRecord } from "../goals/goal-types.js";
3
+ import type { RunRecord } from "../runs/run-types.js";
4
+ import type { AgentEvent, SchedulerEvent } from "../core/events.js";
5
+ export interface JsonlReadResult<T> {
6
+ records: Array<ReplayEvent<T>>;
7
+ error?: Error;
8
+ issue?: JsonlReadIssue;
9
+ issues: JsonlReadIssue[];
10
+ }
11
+ export interface JsonlReadIssue {
12
+ file: string;
13
+ line: number;
14
+ reason: string;
15
+ retainedEventCount: number;
16
+ partialTail: boolean;
17
+ corruptLineCount: number;
18
+ partialTailDetected: boolean;
19
+ lastGoodEventId?: number;
20
+ lastGoodSequence?: number;
21
+ repairRecommendation: "none" | "truncate_partial_tail" | "isolate_corrupt_line" | "manual_review";
22
+ redactedTailPreview?: string;
23
+ }
24
+ export interface StoredRunSnapshot {
25
+ manifest: RunRecord;
26
+ events: Array<ReplayEvent<AgentEvent>>;
27
+ manifestError?: Error;
28
+ eventsError?: Error;
29
+ eventsIssue?: JsonlReadIssue;
30
+ }
31
+ export interface StoredGoalSnapshot {
32
+ manifest: GoalRecord;
33
+ events: Array<ReplayEvent<SchedulerEvent>>;
34
+ manifestError?: Error;
35
+ eventsError?: Error;
36
+ eventsIssue?: JsonlReadIssue;
37
+ }
38
+ export interface FileStorage {
39
+ listRuns(): StoredRunSnapshot[];
40
+ writeRunManifest(record: RunRecord): void;
41
+ appendRunEvent(runId: string, event: ReplayEvent<AgentEvent>): void;
42
+ listGoals(): StoredGoalSnapshot[];
43
+ writeGoalManifest(record: GoalRecord): void;
44
+ appendGoalEvent(goalId: string, event: ReplayEvent<SchedulerEvent>): void;
45
+ }
46
+ export type StorageDurability = "relaxed" | "fsync";
47
+ export interface StorageSyncHooks {
48
+ fdatasyncSync?: (fd: number) => void;
49
+ fsyncSync?: (fd: number) => void;
50
+ }
51
+ export interface StorageFaultHooks {
52
+ beforeManifestTempWrite?: (file: string) => void;
53
+ beforeManifestRename?: (tmp: string, file: string) => void;
54
+ beforeJsonlAppend?: (file: string) => void;
55
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=storage-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storage-types.js","sourceRoot":"","sources":["../../src/storage/storage-types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,28 @@
1
+ import type { ReplayEvent } from "../core/events.js";
2
+ import type { AgentEvent, SchedulerEvent } from "../core/events.js";
3
+ import type { RunRecord } from "../runs/run-types.js";
4
+ import type { GoalRecord } from "../goals/goal-types.js";
5
+ import type { DiagnosticsBundle, ExportDiagnosticsRequest, StorageLockInspection, StoreHealth, StoreRepairReport } from "../public-types.js";
6
+ export interface StoreRepairFaultHooks {
7
+ beforeBackupWrite?: (file: string) => void;
8
+ beforeRepairRewrite?: (file: string) => void;
9
+ }
10
+ export declare function inspectStoreDirectory(storageDir: string): StoreHealth;
11
+ export declare function inspectStoreLock(storageDir: string): StorageLockInspection;
12
+ export declare function listStoredRuns(storageDir: string, options?: {
13
+ status?: "active" | RunRecord["status"];
14
+ }): RunRecord[];
15
+ export declare function getStoredRun(storageDir: string, runId: string): RunRecord | null;
16
+ export declare function replayStoredRunEvents(storageDir: string, runId: string, afterEventId?: number): Array<ReplayEvent<AgentEvent>>;
17
+ export declare function listStoredGoals(storageDir: string, options?: {
18
+ status?: "active" | GoalRecord["status"];
19
+ }): GoalRecord[];
20
+ export declare function getStoredGoal(storageDir: string, goalId: string): GoalRecord | null;
21
+ export declare function replayStoredGoalEvents(storageDir: string, goalId: string, afterEventId?: number): Array<ReplayEvent<SchedulerEvent>>;
22
+ export declare function inspectStoreRepairDryRun(storageDir: string): StoreRepairReport;
23
+ export declare function inspectStoreRepair(storageDir: string, options?: {
24
+ apply?: boolean;
25
+ faults?: StoreRepairFaultHooks;
26
+ }): StoreRepairReport;
27
+ export declare function exportDiagnosticsBundle(request: ExportDiagnosticsRequest, storageDir: string): DiagnosticsBundle;
28
+ export declare function atomicWriteJsonFile(file: string, value: unknown): void;