@evomap/evolver-cli 2.0.48 → 2.0.50
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/dist/autoDistillTranscript.d.ts +1 -1
- package/dist/autoDistillTranscript.js +9 -2
- package/dist/autoexec.js +3 -0
- package/dist/cliContracts.js +5 -28
- package/dist/cycleConsumer.js +3 -0
- package/dist/distillAdmission.d.ts +8 -1
- package/dist/distillAdmission.js +30 -0
- package/dist/distillObserver.d.ts +0 -6
- package/dist/distillObserver.js +17 -5
- package/dist/distillPrimitives.d.ts +4 -3
- package/dist/distillPrimitives.js +27 -18
- package/dist/doctor.d.ts +3 -0
- package/dist/doctor.js +17 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +7 -0
- package/dist/lifecycle.d.ts +9 -0
- package/dist/lifecycle.js +159 -102
- package/dist/lifecycleAutoexecCompanion.d.ts +40 -0
- package/dist/lifecycleAutoexecCompanion.js +102 -0
- package/dist/lifecycleBootstrapTransaction.js +38 -17
- package/dist/llmCycle.js +15 -5
- package/dist/localMemoryGraph.js +29 -19
- package/dist/promptRecallRuntime.d.ts +3 -0
- package/dist/promptRecallRuntime.js +8 -0
- package/dist/promptRecallShared.d.ts +2 -0
- package/dist/promptRecallShared.js +13 -3
- package/dist/protectedAuditStatus.d.ts +22 -0
- package/dist/protectedAuditStatus.js +234 -0
- package/dist/recall.js +2 -3
- package/dist/runtimeCapabilities.d.ts +1 -1
- package/dist/runtimeCapabilities.js +24 -0
- package/dist/runtimeSessionSource.js +4 -4
- package/dist/sessionIngest.js +3 -0
- package/dist/setupHooks.d.ts +3 -0
- package/dist/setupHooks.js +98 -17
- package/dist/setupHooksLifecycle.d.ts +19 -3
- package/dist/setupHooksLifecycle.js +17 -246
- package/dist/setupHooksTransaction.d.ts +12 -0
- package/dist/setupHooksTransaction.js +220 -0
- package/dist/trajectoryExport.js +2 -2
- package/package.json +7 -7
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { createHash } from 'node:crypto';
|
|
2
|
-
import { lstatSync, readFileSync } from 'node:fs';
|
|
3
2
|
import { homedir } from 'node:os';
|
|
4
3
|
import { isAbsolute, relative, resolve, sep } from 'node:path';
|
|
5
|
-
import { DEFAULT_HOOK_COMMAND, DEFAULT_PROMPT_RECALL_HOOK_COMMAND, claudeCodeTargets, codexConfigTarget, installInjection, uninstallInjection, resolveInstallComponents, cursorRulesPath, resolveAntigravityConfigTargets, resolveOpenCodeConfig, resolveKiroConfig, } from '@evomap/evolver-mcp';
|
|
4
|
+
import { DEFAULT_HOOK_COMMAND, DEFAULT_PROMPT_RECALL_HOOK_COMMAND, claudeCodeTargets, codexConfigTarget, installInjection, uninstallInjection, resolveInstallComponents, cursorRulesPath, resolveAntigravityConfigTargets, resolveOpenCodeConfig, resolveKiroConfig, readSharedFileSnapshot, INSTALLER_TRANSACTION_SCHEMA, } from '@evomap/evolver-mcp';
|
|
5
|
+
import { executeSetupTransaction, recoverSetupTransaction } from './setupHooksTransaction.js';
|
|
6
|
+
export { inspectSetupTransactions } from './setupHooksTransaction.js';
|
|
6
7
|
export const SETUP_LIFECYCLE_SCHEMA = 'evolver.setup_hooks.lifecycle.v1';
|
|
7
8
|
export const SETUP_LIFECYCLE_PLAN_TTL_MS = 120_000;
|
|
8
9
|
export class SetupLifecycleError extends Error {
|
|
@@ -24,6 +25,7 @@ export function setupLifecycleCapabilities(runtime, scope) {
|
|
|
24
25
|
supported,
|
|
25
26
|
hookCommandsBound: runtime === 'claude-code' || runtime === 'codex',
|
|
26
27
|
standaloneMcp: true,
|
|
28
|
+
transactions: { schema: INSTALLER_TRANSACTION_SCHEMA, durable: supported, atomicVisibility: false, recovery: supported },
|
|
27
29
|
operations: {
|
|
28
30
|
plan: supported,
|
|
29
31
|
verify: supported,
|
|
@@ -51,9 +53,9 @@ function lifecycleIntentDigest(context, action) {
|
|
|
51
53
|
const options = lifecycleInstallOptions(context);
|
|
52
54
|
const targetResolution = {
|
|
53
55
|
components: resolveInstallComponents(options.components),
|
|
54
|
-
configRoot: context.configRoot,
|
|
56
|
+
configRoot: resolve(context.configRoot),
|
|
55
57
|
scope: context.scope,
|
|
56
|
-
homeDir: options.homeDir,
|
|
58
|
+
homeDir: resolve(options.homeDir ?? homedir()),
|
|
57
59
|
codexHome: options.codexHome,
|
|
58
60
|
kiroHome: options.kiroHome,
|
|
59
61
|
xdgConfigHome: options.xdgConfigHome,
|
|
@@ -92,22 +94,7 @@ function lifecycleIntentDigest(context, action) {
|
|
|
92
94
|
return digest(JSON.stringify(canonicalJson(intent)));
|
|
93
95
|
}
|
|
94
96
|
function fileIdentity(path) {
|
|
95
|
-
|
|
96
|
-
const stat = lstatSync(path);
|
|
97
|
-
if (stat.isSymbolicLink())
|
|
98
|
-
return digest(`symlink:${path}`);
|
|
99
|
-
if (!stat.isFile())
|
|
100
|
-
return digest(`non-file:${path}:${stat.mode}`);
|
|
101
|
-
return digest(Buffer.concat([
|
|
102
|
-
Buffer.from(`file:${path}:${stat.mode}:`),
|
|
103
|
-
readFileSync(path),
|
|
104
|
-
]));
|
|
105
|
-
}
|
|
106
|
-
catch (error) {
|
|
107
|
-
if (error.code === 'ENOENT')
|
|
108
|
-
return digest(`absent:${path}`);
|
|
109
|
-
throw error;
|
|
110
|
-
}
|
|
97
|
+
return digest(JSON.stringify([path, readSharedFileSnapshot(path).identity]));
|
|
111
98
|
}
|
|
112
99
|
function displayTarget(path, context) {
|
|
113
100
|
const base = context.scope === 'user' ? context.installOptions.homeDir ?? homedir() : context.configRoot;
|
|
@@ -130,21 +117,6 @@ function applyLifecycleMutation(context, action, targetPath) {
|
|
|
130
117
|
? installInjection(context.injectionPlan, options)
|
|
131
118
|
: uninstallInjection(context.runtime, options);
|
|
132
119
|
}
|
|
133
|
-
function applyConfirmedTargets(context, plan, paths) {
|
|
134
|
-
const files = [];
|
|
135
|
-
for (const target of plan.targets) {
|
|
136
|
-
if (target.disposition === 'already_satisfied')
|
|
137
|
-
continue;
|
|
138
|
-
const path = paths.get(target.target_id);
|
|
139
|
-
if (!path)
|
|
140
|
-
throw new SetupLifecycleError('PLAN_STALE', 'confirmed target is no longer resolved');
|
|
141
|
-
const result = applyLifecycleMutation(context, plan.action, path);
|
|
142
|
-
files.push(...result.files);
|
|
143
|
-
if (!result.ok)
|
|
144
|
-
return { ...result, files };
|
|
145
|
-
}
|
|
146
|
-
return { ok: true, runtime: context.runtime, mode: context.injectionPlan.mode, files };
|
|
147
|
-
}
|
|
148
120
|
function lifecycleConfigPaths(context) {
|
|
149
121
|
const options = lifecycleInstallOptions(context);
|
|
150
122
|
switch (context.runtime) {
|
|
@@ -168,14 +140,15 @@ function planForTimes(context, action, createdAt, expiresAt, resolvedPaths) {
|
|
|
168
140
|
if (!dryRun.ok)
|
|
169
141
|
throw new SetupLifecycleError('PLAN_INVALID', dryRun.error ?? 'lifecycle plan failed');
|
|
170
142
|
if (resolvedPaths) {
|
|
171
|
-
const paths = [...lifecycleConfigPaths(context), ...dryRun.files];
|
|
143
|
+
const paths = [...lifecycleConfigPaths(context), ...dryRun.files, ...(dryRun.backups ?? []).map(path => path.replace(/\.evolver-backup\.json$/, ''))];
|
|
172
144
|
for (const path of paths.map((path) => resolve(path))) {
|
|
173
145
|
resolvedPaths.set(digest(`${context.runtime}\0${context.scope}\0${path}`).slice(0, 32), path);
|
|
174
146
|
}
|
|
175
147
|
}
|
|
176
|
-
const files = [...new Set(dryRun.files.map((path) => resolve(path)))].sort();
|
|
148
|
+
const files = [...new Set([...dryRun.files, ...(dryRun.backups ?? []).map(path => path.replace(/\.evolver-backup\.json$/, ''))].map((path) => resolve(path)))].sort();
|
|
177
149
|
const targets = files.map((path) => {
|
|
178
|
-
const
|
|
150
|
+
const backups = (dryRun.backups ?? []).filter(backup => resolve(backup) === `${path}.evolver-backup.json`);
|
|
151
|
+
const expectedIdentity = digest(JSON.stringify([fileIdentity(path), ...backups.map(fileIdentity)]));
|
|
179
152
|
const targetId = digest(`${context.runtime}\0${context.scope}\0${path}`).slice(0, 32);
|
|
180
153
|
return {
|
|
181
154
|
target_id: targetId,
|
|
@@ -257,214 +230,12 @@ export function verifySetupLifecycle(context) {
|
|
|
257
230
|
const result = installInjection(context.injectionPlan, { ...lifecycleInstallOptions(context), dryRun: true });
|
|
258
231
|
return result.ok && result.alreadyInstalled === true && result.verified === true && result.files.length === 0;
|
|
259
232
|
}
|
|
233
|
+
const transactionDriver = {
|
|
234
|
+
intent: lifecycleIntentDigest, plan: planForTimes, preview: planResult, apply: applyLifecycleMutation, verify: verifySetupLifecycle,
|
|
235
|
+
};
|
|
260
236
|
export function executeSetupLifecyclePlan(context, confirmed, options = {}) {
|
|
261
|
-
|
|
262
|
-
throw new SetupLifecycleError('PLAN_INVALID', 'confirmed lifecycle plan does not match runtime scope');
|
|
263
|
-
}
|
|
264
|
-
const { plan_id: confirmedPlanID, ...confirmedBase } = confirmed;
|
|
265
|
-
if (digest(JSON.stringify(confirmedBase)) !== confirmedPlanID) {
|
|
266
|
-
throw new SetupLifecycleError('PLAN_INVALID', 'confirmed lifecycle plan identity is invalid');
|
|
267
|
-
}
|
|
268
|
-
if (lifecycleIntentDigest(context, confirmed.action) !== confirmed.intent_digest) {
|
|
269
|
-
throw new SetupLifecycleError('PLAN_STALE', 'lifecycle write intent changed; create a fresh plan');
|
|
270
|
-
}
|
|
271
|
-
const now = (context.now ?? (() => new Date()))();
|
|
272
|
-
const createdAt = new Date(confirmed.created_at);
|
|
273
|
-
const expiresAt = new Date(confirmed.expires_at);
|
|
274
|
-
if (!Number.isFinite(createdAt.getTime()) || !Number.isFinite(expiresAt.getTime())) {
|
|
275
|
-
throw new SetupLifecycleError('PLAN_INVALID', 'confirmed lifecycle plan has invalid timestamps');
|
|
276
|
-
}
|
|
277
|
-
const continuingTargetExecution = options.targetId !== undefined && (options.completedTargetIds?.length ?? 0) > 0;
|
|
278
|
-
if (now.getTime() > expiresAt.getTime() && !continuingTargetExecution) {
|
|
279
|
-
throw new SetupLifecycleError('PLAN_EXPIRED', 'confirmed lifecycle plan expired; create a fresh plan');
|
|
280
|
-
}
|
|
281
|
-
if (options.targetId !== undefined) {
|
|
282
|
-
return executeSetupLifecycleTarget(context, confirmed, options.targetId, options.completedTargetIds ?? [], createdAt, expiresAt);
|
|
283
|
-
}
|
|
284
|
-
const resolvedPaths = new Map();
|
|
285
|
-
const current = planForTimes(context, confirmed.action, createdAt, expiresAt, resolvedPaths);
|
|
286
|
-
const sameTargets = JSON.stringify(current.targets.map((target) => target.target_id))
|
|
287
|
-
=== JSON.stringify(confirmed.targets.map((target) => target.target_id));
|
|
288
|
-
if (current.plan_id !== confirmed.plan_id
|
|
289
|
-
|| current.generation !== confirmed.generation
|
|
290
|
-
|| current.target_set_digest !== confirmed.target_set_digest
|
|
291
|
-
|| !sameTargets) {
|
|
292
|
-
throw new SetupLifecycleError('PLAN_STALE', 'lifecycle target identity changed; create a fresh plan');
|
|
293
|
-
}
|
|
294
|
-
let result;
|
|
295
|
-
let executionFailed = false;
|
|
296
|
-
try {
|
|
297
|
-
result = context.runtime === 'claude-code' || context.runtime === 'codex'
|
|
298
|
-
? applyLifecycleMutation(context, confirmed.action)
|
|
299
|
-
: applyConfirmedTargets(context, confirmed, resolvedPaths);
|
|
300
|
-
executionFailed = !result.ok;
|
|
301
|
-
}
|
|
302
|
-
catch {
|
|
303
|
-
executionFailed = true;
|
|
304
|
-
}
|
|
305
|
-
let verified = false;
|
|
306
|
-
if (!executionFailed) {
|
|
307
|
-
try {
|
|
308
|
-
verified = confirmed.action === 'install'
|
|
309
|
-
? verifySetupLifecycle(context)
|
|
310
|
-
: planResult(context, 'uninstall').files.length === 0;
|
|
311
|
-
}
|
|
312
|
-
catch {
|
|
313
|
-
executionFailed = true;
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
const targets = confirmed.targets.map((target) => {
|
|
317
|
-
const path = resolvedPaths.get(target.target_id);
|
|
318
|
-
const committed = path !== undefined && fileIdentity(path) !== target.expected_identity;
|
|
319
|
-
const targetVerified = !executionFailed && verified;
|
|
320
|
-
return {
|
|
321
|
-
target_id: target.target_id,
|
|
322
|
-
outcome: target.disposition === 'already_satisfied' || !committed && targetVerified
|
|
323
|
-
? confirmed.action === 'uninstall' ? 'already_absent' : 'already_satisfied'
|
|
324
|
-
: committed
|
|
325
|
-
? confirmed.action === 'install' ? 'installed' : 'removed'
|
|
326
|
-
: 'failed',
|
|
327
|
-
committed,
|
|
328
|
-
verified: targetVerified,
|
|
329
|
-
...(!targetVerified ? { recovery: committed ? 'RETRY_VERIFICATION' : 'OPEN_CONFIG' } : {}),
|
|
330
|
-
};
|
|
331
|
-
});
|
|
332
|
-
return {
|
|
333
|
-
schema: SETUP_LIFECYCLE_SCHEMA,
|
|
334
|
-
action: confirmed.action,
|
|
335
|
-
runtime: context.runtime,
|
|
336
|
-
scope: context.scope,
|
|
337
|
-
plan_id: confirmed.plan_id,
|
|
338
|
-
generation: confirmed.generation,
|
|
339
|
-
target_set_digest: confirmed.target_set_digest,
|
|
340
|
-
complete: verified,
|
|
341
|
-
verified,
|
|
342
|
-
targets,
|
|
343
|
-
};
|
|
237
|
+
return executeSetupTransaction(context, confirmed, options, transactionDriver);
|
|
344
238
|
}
|
|
345
|
-
function
|
|
346
|
-
|
|
347
|
-
if (!selected)
|
|
348
|
-
throw new SetupLifecycleError('PLAN_INVALID', 'selected lifecycle target is not in the confirmed plan');
|
|
349
|
-
const confirmedIds = new Set(confirmed.targets.map((target) => target.target_id));
|
|
350
|
-
const completed = new Set(completedTargetIds);
|
|
351
|
-
if (completed.size !== completedTargetIds.length || completed.has(targetId) || [...completed].some((id) => !confirmedIds.has(id))) {
|
|
352
|
-
throw new SetupLifecycleError('PLAN_INVALID', 'completed lifecycle target set is invalid');
|
|
353
|
-
}
|
|
354
|
-
const resolvedPaths = new Map();
|
|
355
|
-
const current = planForTimes(context, confirmed.action, createdAt, expiresAt, resolvedPaths);
|
|
356
|
-
const currentTargets = current.targets.filter((target) => target.disposition !== 'already_satisfied');
|
|
357
|
-
const currentByID = new Map(currentTargets.map((target) => [target.target_id, target]));
|
|
358
|
-
if (currentTargets.some((target) => !confirmedIds.has(target.target_id))) {
|
|
359
|
-
throw new SetupLifecycleError('PLAN_STALE', 'lifecycle target set changed; create a fresh plan');
|
|
360
|
-
}
|
|
361
|
-
const currentSelected = currentByID.get(targetId);
|
|
362
|
-
if (currentSelected && (currentSelected.target_ref !== selected.target_ref || currentSelected.disposition !== selected.disposition)) {
|
|
363
|
-
throw new SetupLifecycleError('PLAN_STALE', 'selected lifecycle target metadata changed');
|
|
364
|
-
}
|
|
365
|
-
if (selected.disposition === 'already_satisfied') {
|
|
366
|
-
if (current.plan_id !== confirmed.plan_id)
|
|
367
|
-
throw new SetupLifecycleError('PLAN_STALE', 'no-op lifecycle plan changed');
|
|
368
|
-
return {
|
|
369
|
-
schema: SETUP_LIFECYCLE_SCHEMA,
|
|
370
|
-
action: confirmed.action,
|
|
371
|
-
runtime: context.runtime,
|
|
372
|
-
scope: context.scope,
|
|
373
|
-
plan_id: confirmed.plan_id,
|
|
374
|
-
generation: confirmed.generation,
|
|
375
|
-
target_set_digest: confirmed.target_set_digest,
|
|
376
|
-
complete: true,
|
|
377
|
-
verified: true,
|
|
378
|
-
targets: [{
|
|
379
|
-
target_id: targetId,
|
|
380
|
-
outcome: confirmed.action === 'uninstall' ? 'already_absent' : 'already_satisfied',
|
|
381
|
-
committed: false,
|
|
382
|
-
verified: true,
|
|
383
|
-
}],
|
|
384
|
-
};
|
|
385
|
-
}
|
|
386
|
-
const targetPath = resolvedPaths.get(targetId);
|
|
387
|
-
if (targetPath === undefined
|
|
388
|
-
|| displayTarget(targetPath, context) !== selected.target_ref
|
|
389
|
-
|| selected.disposition !== (confirmed.action === 'install' ? 'installable' : 'removable')) {
|
|
390
|
-
throw new SetupLifecycleError('PLAN_STALE', 'selected lifecycle target is not owned by this operation');
|
|
391
|
-
}
|
|
392
|
-
for (const target of confirmed.targets) {
|
|
393
|
-
if (target.disposition === 'already_satisfied')
|
|
394
|
-
continue;
|
|
395
|
-
const currentTarget = currentByID.get(target.target_id);
|
|
396
|
-
if (completed.has(target.target_id)) {
|
|
397
|
-
if (currentTarget)
|
|
398
|
-
throw new SetupLifecycleError('PLAN_STALE', 'a completed lifecycle target is no longer verified');
|
|
399
|
-
continue;
|
|
400
|
-
}
|
|
401
|
-
if (target.target_id === targetId) {
|
|
402
|
-
if (currentTarget && currentTarget.expected_identity !== target.expected_identity) {
|
|
403
|
-
throw new SetupLifecycleError('PLAN_STALE', 'selected lifecycle target identity changed');
|
|
404
|
-
}
|
|
405
|
-
continue;
|
|
406
|
-
}
|
|
407
|
-
if (!currentTarget || currentTarget.expected_identity !== target.expected_identity) {
|
|
408
|
-
throw new SetupLifecycleError('PLAN_STALE', 'a pending lifecycle target identity changed');
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
|
-
const alreadyApplied = !currentByID.has(targetId);
|
|
412
|
-
if (alreadyApplied) {
|
|
413
|
-
return {
|
|
414
|
-
schema: SETUP_LIFECYCLE_SCHEMA,
|
|
415
|
-
action: confirmed.action,
|
|
416
|
-
runtime: context.runtime,
|
|
417
|
-
scope: context.scope,
|
|
418
|
-
plan_id: confirmed.plan_id,
|
|
419
|
-
generation: confirmed.generation,
|
|
420
|
-
target_set_digest: confirmed.target_set_digest,
|
|
421
|
-
complete: true,
|
|
422
|
-
verified: true,
|
|
423
|
-
targets: [{
|
|
424
|
-
target_id: targetId,
|
|
425
|
-
outcome: confirmed.action === 'uninstall' ? 'already_absent' : 'already_satisfied',
|
|
426
|
-
committed: false,
|
|
427
|
-
verified: true,
|
|
428
|
-
}],
|
|
429
|
-
};
|
|
430
|
-
}
|
|
431
|
-
let executionFailed = false;
|
|
432
|
-
try {
|
|
433
|
-
const result = applyLifecycleMutation(context, confirmed.action, targetPath);
|
|
434
|
-
executionFailed = !result.ok;
|
|
435
|
-
}
|
|
436
|
-
catch {
|
|
437
|
-
executionFailed = true;
|
|
438
|
-
}
|
|
439
|
-
let verified = false;
|
|
440
|
-
try {
|
|
441
|
-
const after = planForTimes(context, confirmed.action, createdAt, expiresAt);
|
|
442
|
-
verified = !after.targets.some((target) => target.target_id === targetId);
|
|
443
|
-
}
|
|
444
|
-
catch {
|
|
445
|
-
executionFailed = true;
|
|
446
|
-
}
|
|
447
|
-
const committed = fileIdentity(targetPath) !== selected.expected_identity;
|
|
448
|
-
const targetVerified = !executionFailed && verified;
|
|
449
|
-
const outcome = targetVerified
|
|
450
|
-
? confirmed.action === 'install' ? 'installed' : 'removed'
|
|
451
|
-
: 'failed';
|
|
452
|
-
return {
|
|
453
|
-
schema: SETUP_LIFECYCLE_SCHEMA,
|
|
454
|
-
action: confirmed.action,
|
|
455
|
-
runtime: context.runtime,
|
|
456
|
-
scope: context.scope,
|
|
457
|
-
plan_id: confirmed.plan_id,
|
|
458
|
-
generation: confirmed.generation,
|
|
459
|
-
target_set_digest: confirmed.target_set_digest,
|
|
460
|
-
complete: targetVerified,
|
|
461
|
-
verified: targetVerified,
|
|
462
|
-
targets: [{
|
|
463
|
-
target_id: targetId,
|
|
464
|
-
outcome,
|
|
465
|
-
committed,
|
|
466
|
-
verified: targetVerified,
|
|
467
|
-
...(!targetVerified ? { recovery: committed ? 'RETRY_VERIFICATION' : 'OPEN_CONFIG' } : {}),
|
|
468
|
-
}],
|
|
469
|
-
};
|
|
239
|
+
export function recoverSetupLifecycle(context, id, recovery, confirmedState) {
|
|
240
|
+
return recoverSetupTransaction(context, id, recovery, transactionDriver, confirmedState);
|
|
470
241
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type InstallResult, type InstallerTransactionSummary } from '@evomap/evolver-mcp';
|
|
2
|
+
import { type SetupLifecycleAction, type SetupLifecycleContext, type SetupLifecyclePlan, type SetupLifecycleExecutionOptions, type SetupLifecycleExecutionResult } from './setupHooksLifecycle.js';
|
|
3
|
+
export interface SetupLifecycleDriver {
|
|
4
|
+
intent(context: SetupLifecycleContext, action: SetupLifecycleAction): string;
|
|
5
|
+
plan(context: SetupLifecycleContext, action: SetupLifecycleAction, createdAt: Date, expiresAt: Date, paths?: Map<string, string>): SetupLifecyclePlan;
|
|
6
|
+
preview(context: SetupLifecycleContext, action: SetupLifecycleAction): InstallResult;
|
|
7
|
+
apply(context: SetupLifecycleContext, action: SetupLifecycleAction, path?: string): InstallResult;
|
|
8
|
+
verify(context: SetupLifecycleContext): boolean;
|
|
9
|
+
}
|
|
10
|
+
export declare function executeSetupTransaction(context: SetupLifecycleContext, confirmed: SetupLifecyclePlan, options: SetupLifecycleExecutionOptions, driver: SetupLifecycleDriver): SetupLifecycleExecutionResult;
|
|
11
|
+
export declare function inspectSetupTransactions(context: SetupLifecycleContext, id?: string): InstallerTransactionSummary[];
|
|
12
|
+
export declare function recoverSetupTransaction(context: SetupLifecycleContext, id: string, recovery: 'resume' | 'rollback' | 'accept-current', driver: SetupLifecycleDriver, confirmedState?: string): InstallerTransactionSummary | SetupLifecycleExecutionResult;
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { resolve } from 'node:path';
|
|
3
|
+
import { installerTransactionRoot, inspectInstallerTransactions, withInstallerTransaction, InstallerTransactionError, installerTransactionFromError, completeManagedInstallerTransaction, installInjection, uninstallInjection, } from '@evomap/evolver-mcp';
|
|
4
|
+
import { SETUP_LIFECYCLE_SCHEMA, SETUP_LIFECYCLE_PLAN_TTL_MS, SetupLifecycleError, } from './setupHooksLifecycle.js';
|
|
5
|
+
function hash(value) { return createHash('sha256').update(value).digest('hex'); }
|
|
6
|
+
function verificationContext(context) {
|
|
7
|
+
return { ...context, installOptions: { ...context.installOptions, force: false } };
|
|
8
|
+
}
|
|
9
|
+
function verifyTarget(context, action, path, driver) {
|
|
10
|
+
const checking = verificationContext(context);
|
|
11
|
+
const result = driver.preview({ ...checking, installOptions: { ...checking.installOptions, ...(path ? { targetPath: path } : {}) } }, action);
|
|
12
|
+
return result.ok && result.verified !== false && result.files.length === 0 && (result.backups?.length ?? 0) === 0;
|
|
13
|
+
}
|
|
14
|
+
export function executeSetupTransaction(context, confirmed, options, driver) {
|
|
15
|
+
if (confirmed.runtime !== context.runtime || confirmed.scope !== context.scope) {
|
|
16
|
+
throw new SetupLifecycleError('PLAN_INVALID', 'confirmed lifecycle plan does not match runtime scope');
|
|
17
|
+
}
|
|
18
|
+
const { plan_id: id, ...base } = confirmed;
|
|
19
|
+
if (hash(JSON.stringify(base)) !== id)
|
|
20
|
+
throw new SetupLifecycleError('PLAN_INVALID', 'confirmed lifecycle plan identity is invalid');
|
|
21
|
+
if (driver.intent(context, confirmed.action) !== confirmed.intent_digest) {
|
|
22
|
+
throw new SetupLifecycleError('PLAN_STALE', 'lifecycle write intent changed; create a fresh plan');
|
|
23
|
+
}
|
|
24
|
+
const createdAt = new Date(confirmed.created_at);
|
|
25
|
+
const expiresAt = new Date(confirmed.expires_at);
|
|
26
|
+
if (!Number.isFinite(createdAt.getTime()) || !Number.isFinite(expiresAt.getTime())
|
|
27
|
+
|| expiresAt.getTime() - createdAt.getTime() !== SETUP_LIFECYCLE_PLAN_TTL_MS) {
|
|
28
|
+
throw new SetupLifecycleError('PLAN_INVALID', 'confirmed lifecycle plan has invalid timestamps or lifetime');
|
|
29
|
+
}
|
|
30
|
+
const root = installerTransactionRoot(context.runtime, context.installOptions);
|
|
31
|
+
const existing = inspectInstallerTransactions(root, id)[0];
|
|
32
|
+
const now = (context.now ?? (() => new Date()))().getTime();
|
|
33
|
+
if (!existing && createdAt.getTime() > now)
|
|
34
|
+
throw new SetupLifecycleError('PLAN_INVALID', 'confirmed lifecycle plan cannot start in the future');
|
|
35
|
+
if (!existing && now > expiresAt.getTime()) {
|
|
36
|
+
throw new SetupLifecycleError('PLAN_EXPIRED', 'confirmed lifecycle plan expired; create a fresh plan');
|
|
37
|
+
}
|
|
38
|
+
const selected = options.targetId;
|
|
39
|
+
if (selected !== undefined && !confirmed.targets.some(target => target.target_id === selected)) {
|
|
40
|
+
throw new SetupLifecycleError('PLAN_INVALID', 'selected lifecycle target is not in the confirmed plan');
|
|
41
|
+
}
|
|
42
|
+
const claimed = options.completedTargetIds ?? [];
|
|
43
|
+
if (claimed.length && selected === undefined || new Set(claimed).size !== claimed.length
|
|
44
|
+
|| claimed.includes(selected ?? '') || claimed.some(id => !confirmed.targets.some(target => target.target_id === id))) {
|
|
45
|
+
throw new SetupLifecycleError('PLAN_INVALID', 'completed lifecycle target set is invalid');
|
|
46
|
+
}
|
|
47
|
+
if (claimed.some(id => !existing?.completed_target_ids.includes(id))) {
|
|
48
|
+
throw new SetupLifecycleError('PLAN_INVALID', 'completed target claims are not backed by the durable transaction');
|
|
49
|
+
}
|
|
50
|
+
const paths = new Map();
|
|
51
|
+
let targets;
|
|
52
|
+
if (!existing || confirmed.targets.every(target => target.disposition === 'already_satisfied')) {
|
|
53
|
+
const current = driver.plan(context, confirmed.action, createdAt, expiresAt, paths);
|
|
54
|
+
if (JSON.stringify(current) !== JSON.stringify(confirmed)) {
|
|
55
|
+
throw new SetupLifecycleError('PLAN_STALE', 'lifecycle target identity or ownership evidence changed; create a fresh plan');
|
|
56
|
+
}
|
|
57
|
+
const preview = driver.preview(context, confirmed.action);
|
|
58
|
+
targets = confirmed.targets.map(target => {
|
|
59
|
+
const path = paths.get(target.target_id);
|
|
60
|
+
return { id: target.target_id, paths: path === undefined ? [] : [path, ...(preview.backups ?? []).filter(backup => resolve(backup) === `${path}.evolver-backup.json`)] };
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
let session;
|
|
64
|
+
const attempted = new Map();
|
|
65
|
+
let transaction;
|
|
66
|
+
let failure;
|
|
67
|
+
let executionFailed = false;
|
|
68
|
+
let activeTarget;
|
|
69
|
+
try {
|
|
70
|
+
withInstallerTransaction({ root, id, binding: confirmed.intent_digest, targets,
|
|
71
|
+
metadata: { source: 'lifecycle', runtime: context.runtime, scope: context.scope, action: confirmed.action, plan: confirmed },
|
|
72
|
+
validatePrepared: artifacts => {
|
|
73
|
+
const current = driver.plan(context, confirmed.action, createdAt, expiresAt);
|
|
74
|
+
if (JSON.stringify(current) !== JSON.stringify(confirmed)) {
|
|
75
|
+
throw new SetupLifecycleError('PLAN_STALE', 'lifecycle target identity or ownership evidence changed; create a fresh plan');
|
|
76
|
+
}
|
|
77
|
+
for (const target of confirmed.targets.filter(target => target.disposition !== 'already_satisfied')) {
|
|
78
|
+
const captured = artifacts.filter(artifact => artifact.target === target.target_id);
|
|
79
|
+
const expected = hash(JSON.stringify(captured.map(artifact => hash(JSON.stringify([artifact.path, artifact.identity])))));
|
|
80
|
+
if (!captured.length || expected !== target.expected_identity) {
|
|
81
|
+
throw new SetupLifecycleError('PLAN_STALE', 'lifecycle target identity or ownership evidence changed; create a fresh plan');
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
const preparingAt = (context.now ?? (() => new Date()))().getTime();
|
|
85
|
+
if (createdAt.getTime() > preparingAt)
|
|
86
|
+
throw new SetupLifecycleError('PLAN_INVALID', 'confirmed lifecycle plan cannot start in the future');
|
|
87
|
+
if (preparingAt > expiresAt.getTime())
|
|
88
|
+
throw new SetupLifecycleError('PLAN_EXPIRED', 'confirmed lifecycle plan expired; create a fresh plan');
|
|
89
|
+
return true;
|
|
90
|
+
},
|
|
91
|
+
}, current => {
|
|
92
|
+
session = current;
|
|
93
|
+
const metadata = current.metadata;
|
|
94
|
+
if (JSON.stringify(metadata.plan) !== JSON.stringify(confirmed))
|
|
95
|
+
throw new SetupLifecycleError('PLAN_STALE', 'durable lifecycle plan metadata changed');
|
|
96
|
+
if (claimed.some(id => !current.hasCompleted(id)))
|
|
97
|
+
throw new SetupLifecycleError('PLAN_INVALID', 'completed target claims are not backed by the durable transaction');
|
|
98
|
+
if (current.status.state === 'rollback_pending' || current.status.state === 'rolled_back' || current.status.state === 'released') {
|
|
99
|
+
throw new InstallerTransactionError('TRANSACTION_PENDING', 'This transaction cannot resume installation; finish rollback or create a fresh plan', current.status);
|
|
100
|
+
}
|
|
101
|
+
if (current.status.state !== 'committed')
|
|
102
|
+
current.armRollback();
|
|
103
|
+
current.assertCurrent();
|
|
104
|
+
const checkTarget = (path) => {
|
|
105
|
+
const verify = () => verifyTarget(context, confirmed.action, path, driver);
|
|
106
|
+
return confirmed.action === 'uninstall' ? current.verifyUninstall(verify) : verify();
|
|
107
|
+
};
|
|
108
|
+
const selectedTargets = selected === undefined ? confirmed.targets : confirmed.targets.filter(target => target.target_id === selected);
|
|
109
|
+
for (const target of selectedTargets) {
|
|
110
|
+
activeTarget = target.target_id;
|
|
111
|
+
const path = current.targets.find(candidate => candidate.id === target.target_id)?.paths[0];
|
|
112
|
+
const already = current.hasCompleted(target.target_id);
|
|
113
|
+
const noOp = target.disposition === 'already_satisfied';
|
|
114
|
+
if (already) {
|
|
115
|
+
// Identity receipts alone are not proof that the runtime still consumes this target (e.g. OpenCode precedence).
|
|
116
|
+
if (!checkTarget(path))
|
|
117
|
+
throw new SetupLifecycleError('PLAN_STALE', 'a completed lifecycle target is no longer verified');
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
current.runTarget(target.target_id, () => {
|
|
121
|
+
if (noOp)
|
|
122
|
+
return;
|
|
123
|
+
const result = driver.apply(context, confirmed.action, path);
|
|
124
|
+
if (!result.ok)
|
|
125
|
+
throw new Error(result.error ?? 'Lifecycle installer failed');
|
|
126
|
+
}, () => checkTarget(path));
|
|
127
|
+
}
|
|
128
|
+
attempted.set(target.target_id, {
|
|
129
|
+
target_id: target.target_id,
|
|
130
|
+
outcome: already || noOp ? confirmed.action === 'uninstall' ? 'already_absent' : 'already_satisfied'
|
|
131
|
+
: confirmed.action === 'install' ? 'installed' : 'removed',
|
|
132
|
+
committed: !already && !noOp && current.wasChanged(target.target_id), verified: true,
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
activeTarget = undefined;
|
|
136
|
+
if (current.targets.every(target => current.hasCompleted(target.id))) {
|
|
137
|
+
const verify = () => confirmed.action === 'install' ? driver.verify(verificationContext(context))
|
|
138
|
+
: confirmed.targets.every(target => checkTarget(current.targets.find(candidate => candidate.id === target.target_id)?.paths[0])) && checkTarget(undefined);
|
|
139
|
+
if (current.status.state !== 'committed')
|
|
140
|
+
current.commit(verify);
|
|
141
|
+
else if (!verify())
|
|
142
|
+
throw new SetupLifecycleError('PLAN_STALE', 'the committed lifecycle plan is no longer verified by the runtime');
|
|
143
|
+
}
|
|
144
|
+
transaction = current.status;
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
catch (error) {
|
|
148
|
+
executionFailed = true;
|
|
149
|
+
failure = error;
|
|
150
|
+
transaction = installerTransactionFromError(error) ?? session?.status;
|
|
151
|
+
// Pre-write invalid plans retain the established CLI error envelope. Mutation failures return all rollback facts.
|
|
152
|
+
if (!session || !session.rollbackOnError && error instanceof SetupLifecycleError)
|
|
153
|
+
throw error;
|
|
154
|
+
}
|
|
155
|
+
const resultTargets = (selected === undefined ? confirmed.targets : confirmed.targets.filter(target => target.target_id === selected)).map(target => {
|
|
156
|
+
const previous = attempted.get(target.target_id);
|
|
157
|
+
if (!executionFailed)
|
|
158
|
+
return previous;
|
|
159
|
+
const blocked = transaction?.blocked_target_ids.includes(target.target_id) ?? true;
|
|
160
|
+
return {
|
|
161
|
+
target_id: target.target_id, outcome: 'failed',
|
|
162
|
+
committed: blocked && (session?.wasChanged(target.target_id) ?? false), verified: false,
|
|
163
|
+
rolled_back: transaction?.state === 'rolled_back' || transaction?.state === 'rollback_pending' && !blocked,
|
|
164
|
+
...(blocked ? { recovery: 'ROLLBACK_TRANSACTION' } : {}),
|
|
165
|
+
};
|
|
166
|
+
});
|
|
167
|
+
const verified = !executionFailed && resultTargets.every(target => target.verified);
|
|
168
|
+
return {
|
|
169
|
+
schema: SETUP_LIFECYCLE_SCHEMA, action: confirmed.action, runtime: context.runtime, scope: context.scope,
|
|
170
|
+
plan_id: id, generation: confirmed.generation, target_set_digest: confirmed.target_set_digest,
|
|
171
|
+
complete: verified && (selected !== undefined || transaction?.state === 'committed'), verified, targets: resultTargets,
|
|
172
|
+
...(transaction ? { transaction } : {}),
|
|
173
|
+
...(executionFailed ? { failure: {
|
|
174
|
+
code: failure instanceof InstallerTransactionError || failure instanceof SetupLifecycleError ? failure.code : 'WRITE_FAILED',
|
|
175
|
+
...(activeTarget ? { target_id: activeTarget } : {}),
|
|
176
|
+
message: failure instanceof InstallerTransactionError || failure instanceof SetupLifecycleError ? failure.message
|
|
177
|
+
: `${context.runtime}/${context.scope} could not complete the confirmed target; inspect the configuration and ownership evidence before creating a fresh plan.`,
|
|
178
|
+
recovery: transaction?.state === 'rollback_pending' ? 'ROLLBACK_TRANSACTION' : 'REFRESH_PLAN',
|
|
179
|
+
} } : {}),
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
export function inspectSetupTransactions(context, id) {
|
|
183
|
+
return inspectInstallerTransactions(installerTransactionRoot(context.runtime, context.installOptions), id);
|
|
184
|
+
}
|
|
185
|
+
export function recoverSetupTransaction(context, id, recovery, driver, confirmedState) {
|
|
186
|
+
const root = installerTransactionRoot(context.runtime, context.installOptions);
|
|
187
|
+
if (recovery === 'rollback' || recovery === 'accept-current') {
|
|
188
|
+
return withInstallerTransaction({ root, id }, transaction => {
|
|
189
|
+
const metadata = transaction.metadata;
|
|
190
|
+
if (metadata.runtime !== context.runtime || metadata.scope !== context.scope) {
|
|
191
|
+
throw new InstallerTransactionError('TRANSACTION_INVALID', 'Transaction does not belong to this runtime scope');
|
|
192
|
+
}
|
|
193
|
+
return recovery === 'accept-current' ? transaction.acceptCurrent(confirmedState ?? '') : transaction.rollback();
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
let plan;
|
|
197
|
+
let installerResult;
|
|
198
|
+
withInstallerTransaction({ root, id }, transaction => {
|
|
199
|
+
const metadata = transaction.metadata;
|
|
200
|
+
if (metadata.runtime !== context.runtime || metadata.scope !== context.scope) {
|
|
201
|
+
throw new InstallerTransactionError('TRANSACTION_INVALID', 'Transaction does not belong to this runtime scope');
|
|
202
|
+
}
|
|
203
|
+
if (metadata.source === 'installer' && metadata.options && metadata.action) {
|
|
204
|
+
const action = metadata.action;
|
|
205
|
+
const options = metadata.options;
|
|
206
|
+
const injectionPlan = metadata.plan;
|
|
207
|
+
const preview = (verification) => action === 'install'
|
|
208
|
+
? installInjection(injectionPlan, { ...options, dryRun: true, ...(verification ? { force: false } : {}) })
|
|
209
|
+
: uninstallInjection(context.runtime, { ...options, dryRun: true });
|
|
210
|
+
completeManagedInstallerTransaction(transaction, context.runtime, action, action === 'install' ? injectionPlan.mode : 'uninstall', preview, targetPath => action === 'install' ? installInjection(injectionPlan, { ...options, targetPath })
|
|
211
|
+
: uninstallInjection(context.runtime, { ...options, targetPath }));
|
|
212
|
+
installerResult = transaction.status;
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
plan = metadata.plan;
|
|
216
|
+
if (!plan)
|
|
217
|
+
throw new InstallerTransactionError('TRANSACTION_INVALID', 'Resume requires durable installer intent');
|
|
218
|
+
});
|
|
219
|
+
return installerResult ?? executeSetupTransaction(context, plan, {}, driver);
|
|
220
|
+
}
|
package/dist/trajectoryExport.js
CHANGED
|
@@ -2,7 +2,7 @@ import { closeSync, existsSync, lstatSync, openSync, readSync, readdirSync, read
|
|
|
2
2
|
import { basename, delimiter, dirname, extname, join, resolve, sep } from 'node:path';
|
|
3
3
|
import { homedir } from 'node:os';
|
|
4
4
|
import { events, ops, trace } from '@evomap/evolver-core';
|
|
5
|
-
import { ADAPTERS, isRemovedAdapter, adapterForPath, genericChatAdapter, isCursorStateVscdbPath, parseCursorStateVscdb, parseJsonlLines, parseJsonlLinesWithStats, } from '@evomap/evolver-runtime-adapters';
|
|
5
|
+
import { ADAPTERS, isRemovedAdapter, adapterForPath, genericChatAdapter, isCursorStateVscdbPath, parseCursorStateVscdb, parseJsonlLines, readSessionLog, parseJsonlLinesWithStats, } from '@evomap/evolver-runtime-adapters';
|
|
6
6
|
const TRACE_FILE_RE = /(^|[/\\])llm-trace-[^/\\]*\.jsonl$/i;
|
|
7
7
|
const RUNTIME_SESSION_ENABLE_ENV = 'EVOLVER_TRAJECTORY_RUNTIME_SESSIONS';
|
|
8
8
|
const RUNTIME_SESSION_ENABLE_ENV_LEGACY = 'EVOLVER_TRAJECTORY_EXPORT_RUNTIME_SESSIONS';
|
|
@@ -862,7 +862,7 @@ export async function runTrajectoryExport(argv) {
|
|
|
862
862
|
continue;
|
|
863
863
|
}
|
|
864
864
|
}
|
|
865
|
-
const chunk = readFileSync(file.path, 'utf8');
|
|
865
|
+
const chunk = file.kind === 'session' ? readSessionLog(file.path) : readFileSync(file.path, 'utf8');
|
|
866
866
|
if (file.kind === 'trace') {
|
|
867
867
|
const result = trace.readTraceRowsFromJsonl(chunk, readOpts);
|
|
868
868
|
allRows.push(...result.rows);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@evomap/evolver-cli",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.50",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -27,12 +27,12 @@
|
|
|
27
27
|
}
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@evomap/evolver-core": "2.0.
|
|
31
|
-
"@evomap/evolver-adapter-public": "2.0.
|
|
32
|
-
"@evomap/evolver-mcp": "2.0.
|
|
33
|
-
"@evomap/evolver-proxy": "2.0.
|
|
34
|
-
"@evomap/evolver-runtime-adapters": "2.0.
|
|
35
|
-
"@evomap/evolver-webui": "2.0.
|
|
30
|
+
"@evomap/evolver-core": "2.0.50",
|
|
31
|
+
"@evomap/evolver-adapter-public": "2.0.50",
|
|
32
|
+
"@evomap/evolver-mcp": "2.0.50",
|
|
33
|
+
"@evomap/evolver-proxy": "2.0.50",
|
|
34
|
+
"@evomap/evolver-runtime-adapters": "2.0.50",
|
|
35
|
+
"@evomap/evolver-webui": "2.0.50"
|
|
36
36
|
},
|
|
37
37
|
"repository": {
|
|
38
38
|
"type": "git",
|