opencode-swarm 7.140.4 → 7.140.5
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/.opencode/skills/plan/SKILL.md +40 -12
- package/dist/agents/architect.d.ts +2 -1
- package/dist/background/pending-delegations.d.ts +5 -0
- package/dist/cli/{config-doctor-qqe6172n.js → config-doctor-5vzpq4qa.js} +3 -3
- package/dist/cli/{core-52k057mf.js → core-xjzdc56e.js} +2 -2
- package/dist/cli/{curation-policy-9291bdat.js → curation-policy-avvb56x2.js} +6 -6
- package/dist/cli/{curator-04xqq68e.js → curator-5nytvg7p.js} +36 -36
- package/dist/cli/curator-llm-factory-rds75zhj.js +61 -0
- package/dist/cli/{evidence-summary-service-em58myd7.js → evidence-summary-service-zq4gyx6g.js} +14 -11
- package/dist/cli/gate-evidence-smn2wqft.js +51 -0
- package/dist/cli/guardrail-explain-an7jvam1.js +62 -0
- package/dist/cli/{guardrail-log-vb5zkegf.js → guardrail-log-0hnd2k9v.js} +4 -4
- package/dist/cli/{hive-promoter-z09khawt.js → hive-promoter-qe8pqg79.js} +36 -36
- package/dist/cli/{index-vrmkg8fm.js → index-01ggt2mj.js} +9 -9
- package/dist/cli/{index-hfwzxh3j.js → index-0r2m0vbq.js} +12 -10
- package/dist/cli/{index-v3xhc7kg.js → index-0rx9t9w8.js} +1 -1
- package/dist/cli/{index-hz0refz4.js → index-2bg901qt.js} +70 -29
- package/dist/cli/{index-7begd9aq.js → index-386ts4tm.js} +4 -4
- package/dist/cli/{index-v3x7j9ey.js → index-8rp1y4ab.js} +2 -2
- package/dist/cli/{index-35qep0v7.js → index-912qz4y0.js} +88 -88
- package/dist/cli/{index-2rb3x0fk.js → index-affh1gtg.js} +7 -7
- package/dist/cli/{index-c5kr20nz.js → index-c432knmy.js} +1 -1
- package/dist/cli/{index-v1an91bq.js → index-e0mpz2j3.js} +5 -5
- package/dist/cli/{index-bfhwtdsw.js → index-epvhf50h.js} +3 -3
- package/dist/cli/{index-s8g7jh1k.js → index-ex7r16gc.js} +2 -2
- package/dist/cli/{index-tj04dj06.js → index-jm4cpp4n.js} +2 -2
- package/dist/cli/{index-hxvkfx6t.js → index-jqsfsqbx.js} +15 -2
- package/dist/cli/{index-hfjvepk2.js → index-kb5q9v34.js} +3 -3
- package/dist/cli/{index-bn17ycxn.js → index-m9xrdjn0.js} +1 -1
- package/dist/cli/{index-djbhe0yh.js → index-mm2egvdt.js} +38 -38
- package/dist/cli/{index-pp5m7xga.js → index-nwrwy8eb.js} +70 -34
- package/dist/cli/index-nyjtzmsj.js +43 -0
- package/dist/cli/{index-4hp8nvwb.js → index-p8kk34am.js} +3 -3
- package/dist/cli/{index-ysa38bnr.js → index-ptn13xjn.js} +3 -3
- package/dist/cli/{index-1kyex7z2.js → index-qwm6vdyv.js} +32 -1
- package/dist/cli/{index-dtam929z.js → index-qy1nq52t.js} +1 -1
- package/dist/cli/{index-rrb6cz2f.js → index-s1v0wza5.js} +6 -2
- package/dist/cli/{index-w4etfamq.js → index-t5pytnca.js} +2 -2
- package/dist/cli/index-tjqzr3jc.js +623 -0
- package/dist/cli/{index-mrpfd1jx.js → index-vh05t3w5.js} +1 -1
- package/dist/cli/{index-ryq97w1x.js → index-wkt9fj06.js} +4 -4
- package/dist/cli/{index-wk8s1m7b.js → index-wrb0gykj.js} +217 -15
- package/dist/cli/{index-arza4m4j.js → index-z7h37d63.js} +2 -2
- package/dist/cli/{index-a1fjhx4w.js → index-z90nvqj3.js} +37836 -35986
- package/dist/cli/{index-b8zgtz81.js → index-zsrtt42s.js} +34 -1
- package/dist/cli/{index-mpytsq6k.js → index-ztgn70jz.js} +2 -2
- package/dist/cli/index.js +35 -35
- package/dist/cli/{knowledge-escalator-gdjnwszd.js → knowledge-escalator-4pfrc902.js} +12 -12
- package/dist/cli/{knowledge-events-581x4q7n.js → knowledge-events-3zkfnksk.js} +10 -10
- package/dist/cli/{knowledge-link-axx45d1h.js → knowledge-link-m9p80f4r.js} +5 -5
- package/dist/cli/{knowledge-store-ttg33482.js → knowledge-store-dpqgvvjt.js} +6 -6
- package/dist/cli/{knowledge-validator-8kywqt8b.js → knowledge-validator-2c7w87dk.js} +8 -8
- package/dist/cli/{pending-delegations-btwqsvz4.js → pending-delegations-cxx9tezp.js} +4 -4
- package/dist/cli/{pr-subscriptions-83y1cdwv.js → pr-subscriptions-2sfnb599.js} +4 -4
- package/dist/cli/{runner-fh3r41nw.js → runner-mky3vvht.js} +6 -6
- package/dist/cli/{scan-cursor-j8ytdpam.js → scan-cursor-1z60gwrw.js} +7 -7
- package/dist/cli/{schema-6xfqtpvn.js → schema-vpnkwvez.js} +2 -2
- package/dist/cli/{scope-persistence-8c72jrgp.js → scope-persistence-p9dmprry.js} +10 -5
- package/dist/cli/{skill-generator-n8vm1yhn.js → skill-generator-yx7ka1cj.js} +14 -14
- package/dist/cli/{telemetry-fb44gpba.js → telemetry-0x6kszvk.js} +1 -1
- package/dist/cli/{worktree-collision-ownership-f28r473k.js → worktree-collision-ownership-wm5pse49.js} +8 -8
- package/dist/cli/worktree-isolation-bwc6ra8e.js +102 -0
- package/dist/cli/worktree-provisioning-owner-sjh7te1h.js +22 -0
- package/dist/commands/acknowledge-spec-drift.d.ts +4 -5
- package/dist/config/evidence-schema.d.ts +3 -3
- package/dist/config/index.d.ts +2 -2
- package/dist/config/plan-schema.d.ts +8 -0
- package/dist/config/schema.d.ts +2 -2
- package/dist/council/council-evidence-writer.d.ts +1 -1
- package/dist/gate-evidence.d.ts +117 -4
- package/dist/hooks/delegation-gate.d.ts +21 -0
- package/dist/index.js +768 -743
- package/dist/plan/ledger.d.ts +55 -0
- package/dist/plan/manager.d.ts +9 -0
- package/dist/plan/planning-profile.d.ts +27 -0
- package/dist/services/spec-drift-recovery.d.ts +84 -0
- package/dist/session/snapshot-writer.d.ts +3 -1
- package/dist/state.d.ts +19 -17
- package/dist/summaries/schema.d.ts +2 -2
- package/dist/tools/convene-council.d.ts +6 -6
- package/dist/tools/save-plan.d.ts +8 -0
- package/dist/tools/submit-phase-council-verdicts.d.ts +6 -6
- package/dist/tools/tool-metadata.d.ts +28 -28
- package/dist/tools/update-task-status.d.ts +13 -0
- package/dist/tools/write-final-council-evidence.d.ts +6 -6
- package/dist/types/events.d.ts +29 -1
- package/dist/workflow/coder-settlement.d.ts +62 -0
- package/dist/workflow/task-repair.d.ts +30 -0
- package/dist/workflow/task-terminal.d.ts +52 -0
- package/package.json +1 -1
- package/dist/cli/curator-llm-factory-cfm8fhdw.js +0 -61
- package/dist/cli/gate-evidence-ezxfkb22.js +0 -32
- package/dist/cli/guardrail-explain-pn1bcgfz.js +0 -62
- package/dist/cli/index-d181x9zr.js +0 -71
- package/dist/cli/index-dtyeabmj.js +0 -239
|
@@ -2,12 +2,13 @@
|
|
|
2
2
|
import {
|
|
3
3
|
assertProjectRoot,
|
|
4
4
|
withEvidenceLock
|
|
5
|
-
} from "./index-
|
|
5
|
+
} from "./index-912qz4y0.js";
|
|
6
6
|
import {
|
|
7
7
|
ExecutionProfileSchema,
|
|
8
8
|
PlanSchema,
|
|
9
|
-
TaskStatusSchema
|
|
10
|
-
|
|
9
|
+
TaskStatusSchema,
|
|
10
|
+
init_loader
|
|
11
|
+
} from "./index-nwrwy8eb.js";
|
|
11
12
|
import {
|
|
12
13
|
criticalWarn,
|
|
13
14
|
init_logger,
|
|
@@ -15,7 +16,7 @@ import {
|
|
|
15
16
|
} from "./index-zgwm4ryv.js";
|
|
16
17
|
import {
|
|
17
18
|
emit
|
|
18
|
-
} from "./index-
|
|
19
|
+
} from "./index-epvhf50h.js";
|
|
19
20
|
|
|
20
21
|
// src/plan/utils.ts
|
|
21
22
|
import { createHash } from "crypto";
|
|
@@ -31,6 +32,20 @@ import * as crypto from "crypto";
|
|
|
31
32
|
import * as fs from "fs";
|
|
32
33
|
import * as path from "path";
|
|
33
34
|
init_logger();
|
|
35
|
+
|
|
36
|
+
// src/plan/planning-profile.ts
|
|
37
|
+
init_loader();
|
|
38
|
+
function normalizeExecutionProfileForHash(profile) {
|
|
39
|
+
if (!profile) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
...profile,
|
|
44
|
+
commit_after_each_completed_task: profile.commit_after_each_completed_task === true ? true : undefined
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// src/plan/ledger.ts
|
|
34
49
|
var LEDGER_SCHEMA_VERSION = "1.1.0";
|
|
35
50
|
var LEDGER_FILENAME = "plan-ledger.jsonl";
|
|
36
51
|
var LEDGER_LOCK_PATH = path.join(".swarm", LEDGER_FILENAME);
|
|
@@ -58,6 +73,45 @@ function writeFileFsyncedThenRename(tempPath, targetPath, data) {
|
|
|
58
73
|
}
|
|
59
74
|
fs.renameSync(tempPath, targetPath);
|
|
60
75
|
}
|
|
76
|
+
function fsyncRecoveryDirectory(directory) {
|
|
77
|
+
let fd;
|
|
78
|
+
try {
|
|
79
|
+
fd = fs.openSync(directory, "r");
|
|
80
|
+
fs.fsyncSync(fd);
|
|
81
|
+
} catch (error) {
|
|
82
|
+
const code = error.code;
|
|
83
|
+
const unsupportedOnWindows = process.platform === "win32" && ["EPERM", "EACCES", "EINVAL", "EBADF", "EISDIR", "ENOTSUP"].includes(code ?? "");
|
|
84
|
+
if (unsupportedOnWindows) {
|
|
85
|
+
log(`[ledger] Directory fsync unavailable for recovery archive ${directory}: ${error instanceof Error ? error.message : String(error)}`);
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
throw new Error(`Failed to fsync recovery archive directory before canonical replacement: ${error instanceof Error ? error.message : String(error)}`);
|
|
89
|
+
} finally {
|
|
90
|
+
if (fd !== undefined)
|
|
91
|
+
fs.closeSync(fd);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
function findRawMalformedSuffix(content) {
|
|
95
|
+
const decoder = new TextDecoder("utf-8", { fatal: true });
|
|
96
|
+
let lineStart = 0;
|
|
97
|
+
for (let index = 0;index <= content.length; index++) {
|
|
98
|
+
if (index < content.length && content[index] !== 10)
|
|
99
|
+
continue;
|
|
100
|
+
let lineEnd = index;
|
|
101
|
+
if (lineEnd > lineStart && content[lineEnd - 1] === 13)
|
|
102
|
+
lineEnd--;
|
|
103
|
+
const line = content.subarray(lineStart, lineEnd);
|
|
104
|
+
if (line.length > 0) {
|
|
105
|
+
try {
|
|
106
|
+
JSON.parse(decoder.decode(line));
|
|
107
|
+
} catch {
|
|
108
|
+
return content.subarray(lineStart);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
lineStart = index + 1;
|
|
112
|
+
}
|
|
113
|
+
return Buffer.alloc(0);
|
|
114
|
+
}
|
|
61
115
|
function computePlanHash(plan) {
|
|
62
116
|
const normalized = {
|
|
63
117
|
schema_version: plan.schema_version,
|
|
@@ -65,10 +119,7 @@ function computePlanHash(plan) {
|
|
|
65
119
|
swarm: plan.swarm,
|
|
66
120
|
current_phase: plan.current_phase,
|
|
67
121
|
migration_status: plan.migration_status,
|
|
68
|
-
execution_profile: plan.execution_profile
|
|
69
|
-
...plan.execution_profile,
|
|
70
|
-
commit_after_each_completed_task: plan.execution_profile.commit_after_each_completed_task === true ? true : undefined
|
|
71
|
-
} : undefined,
|
|
122
|
+
execution_profile: normalizeExecutionProfileForHash(plan.execution_profile),
|
|
72
123
|
phases: plan.phases.map((phase) => ({
|
|
73
124
|
id: phase.id,
|
|
74
125
|
name: phase.name,
|
|
@@ -98,10 +149,7 @@ function computePlanStructureHash(plan) {
|
|
|
98
149
|
swarm: plan.swarm,
|
|
99
150
|
current_phase: plan.current_phase,
|
|
100
151
|
migration_status: plan.migration_status,
|
|
101
|
-
execution_profile: plan.execution_profile
|
|
102
|
-
...plan.execution_profile,
|
|
103
|
-
commit_after_each_completed_task: plan.execution_profile.commit_after_each_completed_task === true ? true : undefined
|
|
104
|
-
} : undefined,
|
|
152
|
+
execution_profile: normalizeExecutionProfileForHash(plan.execution_profile),
|
|
105
153
|
phases: plan.phases.map((phase) => ({
|
|
106
154
|
id: phase.id,
|
|
107
155
|
name: phase.name,
|
|
@@ -232,8 +280,20 @@ async function appendLedgerEvent(directory, eventInput, options) {
|
|
|
232
280
|
assertProjectRoot(directory);
|
|
233
281
|
return withEvidenceLock(directory, LEDGER_LOCK_PATH, "plan-ledger", "append-ledger-event", async () => {
|
|
234
282
|
const ledgerPath = getLedgerPath(directory);
|
|
283
|
+
if (options?.expectedLedgerHash !== undefined && options.expectedSeq === undefined) {
|
|
284
|
+
throw new Error("expectedLedgerHash requires expectedSeq so stale-projection recovery is bound to one exact ledger tail");
|
|
285
|
+
}
|
|
235
286
|
const latestSeq = await getLatestLedgerSeq(directory);
|
|
236
287
|
const nextSeq = latestSeq + 1;
|
|
288
|
+
let ledgerHashBefore;
|
|
289
|
+
if (options?.expectedLedgerHash !== undefined) {
|
|
290
|
+
const events = await readLedgerEvents(directory);
|
|
291
|
+
const tail = events[events.length - 1];
|
|
292
|
+
if (!tail || tail.plan_hash_after !== options.expectedLedgerHash) {
|
|
293
|
+
throw new LedgerStaleWriterError(`Stale writer: expected ledger hash ${options.expectedLedgerHash} but found ${tail?.plan_hash_after ?? "<missing>"}`);
|
|
294
|
+
}
|
|
295
|
+
ledgerHashBefore = tail.plan_hash_after;
|
|
296
|
+
}
|
|
237
297
|
const planHashBefore = computeCurrentPlanHash(directory);
|
|
238
298
|
if (options?.expectedSeq !== undefined && options.expectedSeq !== latestSeq) {
|
|
239
299
|
throw new LedgerStaleWriterError(`Stale writer: expected seq ${options.expectedSeq} but found ${latestSeq}`);
|
|
@@ -246,7 +306,7 @@ async function appendLedgerEvent(directory, eventInput, options) {
|
|
|
246
306
|
...eventInput,
|
|
247
307
|
seq: nextSeq,
|
|
248
308
|
timestamp: new Date().toISOString(),
|
|
249
|
-
plan_hash_before: planHashBefore,
|
|
309
|
+
plan_hash_before: ledgerHashBefore ?? planHashBefore,
|
|
250
310
|
plan_hash_after: planHashAfter,
|
|
251
311
|
schema_version: LEDGER_SCHEMA_VERSION
|
|
252
312
|
};
|
|
@@ -262,6 +322,34 @@ async function appendLedgerEvent(directory, eventInput, options) {
|
|
|
262
322
|
return event;
|
|
263
323
|
});
|
|
264
324
|
}
|
|
325
|
+
async function appendLedgerEventWithRetry(directory, eventInput, options) {
|
|
326
|
+
const maxRetries = options.maxRetries ?? 3;
|
|
327
|
+
const backoffBase = options.backoffMs ?? 10;
|
|
328
|
+
let currentExpected = options.expectedHash;
|
|
329
|
+
let attempt = 0;
|
|
330
|
+
while (true) {
|
|
331
|
+
try {
|
|
332
|
+
return await appendLedgerEvent(directory, eventInput, {
|
|
333
|
+
expectedHash: currentExpected,
|
|
334
|
+
planHashAfter: options.planHashAfter
|
|
335
|
+
});
|
|
336
|
+
} catch (error) {
|
|
337
|
+
if (!(error instanceof LedgerStaleWriterError) || attempt >= maxRetries) {
|
|
338
|
+
throw error;
|
|
339
|
+
}
|
|
340
|
+
attempt++;
|
|
341
|
+
const delayMs = backoffBase * 2 ** (attempt - 1);
|
|
342
|
+
await new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
343
|
+
if (options.verifyValid) {
|
|
344
|
+
const stillValid = await options.verifyValid();
|
|
345
|
+
if (!stillValid) {
|
|
346
|
+
return null;
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
currentExpected = computeCurrentPlanHash(directory);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
}
|
|
265
353
|
async function takeSnapshotWithRetry(directory, plan, options) {
|
|
266
354
|
const MAX_RETRIES = 3;
|
|
267
355
|
const TOTAL_ATTEMPTS = 1 + MAX_RETRIES;
|
|
@@ -303,7 +391,94 @@ async function takeSnapshotEvent(directory, plan, options) {
|
|
|
303
391
|
source: options?.source ?? "takeSnapshotEvent",
|
|
304
392
|
plan_id: planId,
|
|
305
393
|
payload: snapshotPayload
|
|
306
|
-
}, {
|
|
394
|
+
}, {
|
|
395
|
+
planHashAfter: options?.planHashAfter,
|
|
396
|
+
expectedSeq: options?.expectedSeq,
|
|
397
|
+
expectedLedgerHash: options?.expectedLedgerHash
|
|
398
|
+
});
|
|
399
|
+
}
|
|
400
|
+
async function replaceTruncatedLedgerWithRecoveryRoot(directory, plan, expected) {
|
|
401
|
+
assertProjectRoot(directory);
|
|
402
|
+
const validated = PlanSchema.parse(plan);
|
|
403
|
+
return withEvidenceLock(directory, LEDGER_LOCK_PATH, "plan-ledger", "reconcile-truncated-ledger", async () => {
|
|
404
|
+
const ledgerPath = getLedgerPath(directory);
|
|
405
|
+
if (!fs.existsSync(ledgerPath)) {
|
|
406
|
+
throw new LedgerStaleWriterError("Stale writer: canonical ledger disappeared before truncated-ledger recovery");
|
|
407
|
+
}
|
|
408
|
+
const events = await readLedgerEvents(directory);
|
|
409
|
+
const tail = events[events.length - 1];
|
|
410
|
+
if (!tail || tail.seq !== expected.seq || tail.plan_hash_after !== expected.ledgerHash || events[0]?.plan_id !== derivePlanId(validated)) {
|
|
411
|
+
throw new LedgerStaleWriterError("Stale writer: ledger identity or tail changed before truncated-ledger recovery");
|
|
412
|
+
}
|
|
413
|
+
const integrity = await readLedgerEventsWithIntegrity(directory);
|
|
414
|
+
if (!integrity.truncated || integrity.badSuffix === null) {
|
|
415
|
+
throw new LedgerStaleWriterError("Stale writer: ledger is no longer truncated; retry against its current tail");
|
|
416
|
+
}
|
|
417
|
+
const originalBytes = fs.readFileSync(ledgerPath);
|
|
418
|
+
const archiveSha256 = crypto.createHash("sha256").update(originalBytes).digest("hex");
|
|
419
|
+
const swarmDir = path.dirname(ledgerPath);
|
|
420
|
+
const archiveSuffix = `.${archiveSha256.slice(0, 12)}.jsonl`;
|
|
421
|
+
let archiveName = `plan-ledger.reconcile-archive.${Date.now()}.${Math.floor(Math.random() * 1e9)}${archiveSuffix}`;
|
|
422
|
+
let archivePath = path.join(swarmDir, archiveName);
|
|
423
|
+
let archiveNeedsWrite = true;
|
|
424
|
+
for (const candidate of fs.readdirSync(swarmDir)) {
|
|
425
|
+
if (!candidate.startsWith("plan-ledger.reconcile-archive.") || !candidate.endsWith(archiveSuffix)) {
|
|
426
|
+
continue;
|
|
427
|
+
}
|
|
428
|
+
const candidatePath = path.join(swarmDir, candidate);
|
|
429
|
+
if (fs.readFileSync(candidatePath).equals(originalBytes)) {
|
|
430
|
+
archiveName = candidate;
|
|
431
|
+
archivePath = candidatePath;
|
|
432
|
+
archiveNeedsWrite = false;
|
|
433
|
+
break;
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
const archiveTempPath = `${archivePath}.tmp`;
|
|
437
|
+
const canonicalTempPath = `${ledgerPath}.reconcile.${Date.now()}.${Math.floor(Math.random() * 1e9)}.tmp`;
|
|
438
|
+
const planHash = computePlanHash(validated);
|
|
439
|
+
const rawBadSuffix = findRawMalformedSuffix(originalBytes);
|
|
440
|
+
if (rawBadSuffix.length === 0) {
|
|
441
|
+
throw new LedgerStaleWriterError("Stale writer: raw ledger bytes no longer contain the malformed suffix detected during replay");
|
|
442
|
+
}
|
|
443
|
+
const badSuffixSha256 = crypto.createHash("sha256").update(rawBadSuffix).digest("hex");
|
|
444
|
+
const recoveryRoot = {
|
|
445
|
+
seq: 1,
|
|
446
|
+
timestamp: new Date().toISOString(),
|
|
447
|
+
plan_id: derivePlanId(validated),
|
|
448
|
+
event_type: "plan_created",
|
|
449
|
+
source: "save_plan_truncated_ledger_reconcile",
|
|
450
|
+
plan_hash_before: "",
|
|
451
|
+
plan_hash_after: planHash,
|
|
452
|
+
schema_version: LEDGER_SCHEMA_VERSION,
|
|
453
|
+
payload: {
|
|
454
|
+
plan: validated,
|
|
455
|
+
payload_hash: planHash,
|
|
456
|
+
recovery: {
|
|
457
|
+
kind: "truncated_ledger_reconcile",
|
|
458
|
+
archived_ledger: `.swarm/${archiveName}`,
|
|
459
|
+
archived_sha256: archiveSha256,
|
|
460
|
+
bad_suffix_sha256: badSuffixSha256,
|
|
461
|
+
prior_tail_seq: expected.seq,
|
|
462
|
+
prior_tail_hash: expected.ledgerHash
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
};
|
|
466
|
+
try {
|
|
467
|
+
if (archiveNeedsWrite) {
|
|
468
|
+
_internals.writeFileFsyncedThenRename(archiveTempPath, archivePath, originalBytes);
|
|
469
|
+
}
|
|
470
|
+
_internals.fsyncRecoveryDirectory(swarmDir);
|
|
471
|
+
_internals.writeFileFsyncedThenRename(canonicalTempPath, ledgerPath, `${JSON.stringify(recoveryRoot)}
|
|
472
|
+
`);
|
|
473
|
+
} finally {
|
|
474
|
+
for (const tempPath of [archiveTempPath, canonicalTempPath]) {
|
|
475
|
+
try {
|
|
476
|
+
fs.unlinkSync(tempPath);
|
|
477
|
+
} catch {}
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
return { archivePath, archiveSha256, recoveryRoot };
|
|
481
|
+
});
|
|
307
482
|
}
|
|
308
483
|
async function replayFromLedger(directory, options) {
|
|
309
484
|
const { plan } = await replayFromLedgerWithStatus(directory, options);
|
|
@@ -521,6 +696,10 @@ async function loadLastApprovedPlan(directory, expectedPlanId) {
|
|
|
521
696
|
const events = await readLedgerEvents(directory);
|
|
522
697
|
return findLastApprovedSnapshot(events, expectedPlanId);
|
|
523
698
|
}
|
|
699
|
+
async function loadLastPlanCriticApprovedSnapshot(directory, expectedPlanId) {
|
|
700
|
+
const events = await readLedgerEvents(directory);
|
|
701
|
+
return findLastApprovedSnapshot(events, expectedPlanId, (payload) => payload.approval?.source === "plan_critic_gate");
|
|
702
|
+
}
|
|
524
703
|
function findLastApprovedSnapshot(events, expectedPlanId, extraFilter) {
|
|
525
704
|
if (events.length === 0) {
|
|
526
705
|
return null;
|
|
@@ -557,5 +736,28 @@ function findLastApprovedSnapshot(events, expectedPlanId, extraFilter) {
|
|
|
557
736
|
}
|
|
558
737
|
return null;
|
|
559
738
|
}
|
|
739
|
+
var _internals = {
|
|
740
|
+
computePlanHash,
|
|
741
|
+
computePlanStructureHash,
|
|
742
|
+
computeCurrentPlanHash,
|
|
743
|
+
ledgerExists,
|
|
744
|
+
getLatestLedgerSeq,
|
|
745
|
+
readLedgerEvents,
|
|
746
|
+
initLedger,
|
|
747
|
+
appendLedgerEvent,
|
|
748
|
+
appendLedgerEventWithRetry,
|
|
749
|
+
takeSnapshotEvent,
|
|
750
|
+
replayFromLedger,
|
|
751
|
+
replayFromLedgerWithStatus,
|
|
752
|
+
applyEventToPlan,
|
|
753
|
+
readLedgerEventsWithIntegrity,
|
|
754
|
+
quarantineLedgerSuffix,
|
|
755
|
+
loadLastApprovedPlan,
|
|
756
|
+
loadLastPlanCriticApprovedSnapshot,
|
|
757
|
+
getLedgerPath,
|
|
758
|
+
getPlanJsonPath,
|
|
759
|
+
writeFileFsyncedThenRename,
|
|
760
|
+
fsyncRecoveryDirectory
|
|
761
|
+
};
|
|
560
762
|
|
|
561
|
-
export { derivePlanId, derivePlanIdentityHash, LedgerStaleWriterError, computePlanHash, computePlanStructureHash, computeCurrentPlanHash, ledgerExists, getLatestLedgerSeq, readLedgerEvents, initLedger, appendLedgerEvent, takeSnapshotWithRetry, takeSnapshotEvent, replayFromLedger, replayFromLedgerWithStatus, loadLastApprovedPlan };
|
|
763
|
+
export { normalizeExecutionProfileForHash, derivePlanId, derivePlanIdentityHash, LedgerStaleWriterError, computePlanHash, computePlanStructureHash, computeCurrentPlanHash, ledgerExists, getLatestLedgerSeq, readLedgerEvents, initLedger, appendLedgerEvent, takeSnapshotWithRetry, takeSnapshotEvent, replaceTruncatedLedgerWithRecoveryRoot, replayFromLedger, replayFromLedgerWithStatus, readLedgerEventsWithIntegrity, loadLastApprovedPlan };
|
|
@@ -9,11 +9,11 @@ import {
|
|
|
9
9
|
PluginConfigSchema,
|
|
10
10
|
init_schema,
|
|
11
11
|
stripKnownSwarmPrefix
|
|
12
|
-
} from "./index-
|
|
12
|
+
} from "./index-jm4cpp4n.js";
|
|
13
13
|
import {
|
|
14
14
|
ALL_AGENT_NAMES,
|
|
15
15
|
init_constants
|
|
16
|
-
} from "./index-
|
|
16
|
+
} from "./index-jqsfsqbx.js";
|
|
17
17
|
|
|
18
18
|
// src/services/config-doctor.ts
|
|
19
19
|
init_constants();
|