@evomap/evolver-cli 2.0.49 → 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/lifecycle.js +1 -4
- package/dist/lifecycleBootstrapTransaction.js +38 -17
- package/dist/localMemoryGraph.js +10 -4
- package/dist/promptRecallRuntime.js +2 -0
- package/dist/setupHooks.js +70 -13
- 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/package.json +7 -7
package/dist/lifecycle.js
CHANGED
|
@@ -5468,10 +5468,7 @@ function forceKill(pid) {
|
|
|
5468
5468
|
function readProxySettings(path, options = {}) {
|
|
5469
5469
|
let descriptor;
|
|
5470
5470
|
try {
|
|
5471
|
-
|
|
5472
|
-
if (process.platform === 'win32' && before.dev === 0n && before.isFile() && !before.isSymbolicLink()) {
|
|
5473
|
-
before = coreUtil.statRegularFileIdentity(path);
|
|
5474
|
-
}
|
|
5471
|
+
const before = coreUtil.statRegularFileIdentity(path);
|
|
5475
5472
|
if (!before.isFile() || before.isSymbolicLink() || before.size > BigInt(MAX_PROXY_SETTINGS_BYTES)
|
|
5476
5473
|
|| before.dev <= 0n || before.ino <= 0n) {
|
|
5477
5474
|
throw new Error('proxy settings are not a bounded regular file');
|
|
@@ -145,11 +145,31 @@ function assertWindowsAclChecksTrusted(checks) {
|
|
|
145
145
|
function assertWindowsAclTrusted(path, ownerCurrentOnly = false) {
|
|
146
146
|
assertWindowsAclChecksTrusted([{ path, parentOnly: false, ownerCurrentOnly }]);
|
|
147
147
|
}
|
|
148
|
+
function statBootstrapFileIdentity(path) {
|
|
149
|
+
const before = lstatSync(path, { bigint: true });
|
|
150
|
+
if (process.platform !== 'win32')
|
|
151
|
+
return before;
|
|
152
|
+
if (before.isSymbolicLink())
|
|
153
|
+
throw new util.UnsafeLockPathError('symlink');
|
|
154
|
+
if (!before.isFile())
|
|
155
|
+
throw new util.UnsafeLockPathError('not_regular_file');
|
|
156
|
+
// Keep the initial pathname metadata, not just the later normalized snapshot.
|
|
157
|
+
// Only a real handle may supply a missing Windows pathname volume identity.
|
|
158
|
+
const identity = util.statRegularFileIdentity(path);
|
|
159
|
+
if (identity.dev <= 0n || identity.ino <= 0n || before.ino !== identity.ino
|
|
160
|
+
|| before.dev < 0n || (before.dev !== 0n && before.dev !== identity.dev)
|
|
161
|
+
|| before.size !== identity.size || before.mtimeNs !== identity.mtimeNs
|
|
162
|
+
|| before.ctimeNs !== identity.ctimeNs || before.nlink !== identity.nlink
|
|
163
|
+
|| before.uid !== identity.uid || before.mode !== identity.mode) {
|
|
164
|
+
throw new util.UnsafeLockPathError('path_changed');
|
|
165
|
+
}
|
|
166
|
+
return identity;
|
|
167
|
+
}
|
|
148
168
|
function hardenWindowsOwnedFile(path, expected) {
|
|
149
169
|
if (process.platform !== 'win32' || bootstrapWindowsAclTrustForTest)
|
|
150
170
|
return;
|
|
151
171
|
const assertIdentity = () => {
|
|
152
|
-
const current =
|
|
172
|
+
const current = statBootstrapFileIdentity(path);
|
|
153
173
|
if (!current.isFile() || current.isSymbolicLink() || current.nlink !== 1n
|
|
154
174
|
|| current.dev !== expected.dev || current.ino !== expected.ino || current.size !== expected.size) {
|
|
155
175
|
throw new Error(`bootstrap Windows owned file changed before hardening: ${path}`);
|
|
@@ -281,7 +301,9 @@ function readBoundedRegularText(path, maxBytes, label, options = {}) {
|
|
|
281
301
|
const uid = platform === 'win32' || typeof process.getuid !== 'function'
|
|
282
302
|
? undefined
|
|
283
303
|
: BigInt(process.getuid());
|
|
284
|
-
|
|
304
|
+
// Windows runtimes in our supported range can report pathname dev=0. Bind
|
|
305
|
+
// each path snapshot to a real handle rather than accepting an unknown volume.
|
|
306
|
+
const before = statBootstrapFileIdentity(path);
|
|
285
307
|
if (before.isSymbolicLink() || !before.isFile() || before.size > BigInt(maxBytes)
|
|
286
308
|
|| (options.requireOwnerOnly === true && before.nlink !== 1n)
|
|
287
309
|
|| before.dev <= 0n || before.ino <= 0n) {
|
|
@@ -332,7 +354,7 @@ function readBoundedRegularText(path, maxBytes, label, options = {}) {
|
|
|
332
354
|
if (platform === 'win32') {
|
|
333
355
|
(options.assertWindowsAcl ?? assertWindowsAclTrusted)(path);
|
|
334
356
|
}
|
|
335
|
-
const settled =
|
|
357
|
+
const settled = statBootstrapFileIdentity(path);
|
|
336
358
|
if (!settled.isFile() || settled.isSymbolicLink()
|
|
337
359
|
|| settled.dev !== opened.dev || settled.ino !== opened.ino || settled.size !== opened.size
|
|
338
360
|
|| settled.mtimeNs !== opened.mtimeNs || settled.ctimeNs !== opened.ctimeNs
|
|
@@ -442,7 +464,7 @@ function writeDurableExclusive(path, content, mode, publication) {
|
|
|
442
464
|
}
|
|
443
465
|
if (publication && claimPath && ownershipReceipt) {
|
|
444
466
|
syncDirectory(directory);
|
|
445
|
-
const receipt =
|
|
467
|
+
const receipt = statBootstrapFileIdentity(ownershipReceipt);
|
|
446
468
|
if (!opened.isFile() || opened.dev <= 0n || opened.ino <= 0n
|
|
447
469
|
|| receipt.dev !== opened.dev || receipt.ino !== opened.ino) {
|
|
448
470
|
throw new Error('bootstrap artifact ownership receipt does not bind the staged claim');
|
|
@@ -450,7 +472,7 @@ function writeDurableExclusive(path, content, mode, publication) {
|
|
|
450
472
|
linkSync(ownershipReceipt, claimPath);
|
|
451
473
|
syncDirectory(directory);
|
|
452
474
|
claimPublished = true;
|
|
453
|
-
const claim =
|
|
475
|
+
const claim = statBootstrapFileIdentity(claimPath);
|
|
454
476
|
if (claim.dev !== opened.dev || claim.ino !== opened.ino) {
|
|
455
477
|
throw new Error('bootstrap artifact claim does not bind the staged ownership receipt');
|
|
456
478
|
}
|
|
@@ -1620,12 +1642,6 @@ function assertTrustedBootstrapArtifactLeaf(stat, platform, uid, path, role) {
|
|
|
1620
1642
|
}
|
|
1621
1643
|
}
|
|
1622
1644
|
export const _assertTrustedBootstrapArtifactLeafForTest = assertTrustedBootstrapArtifactLeaf;
|
|
1623
|
-
function bootstrapPathMetadata(path) {
|
|
1624
|
-
const stat = lstatSync(path, { bigint: true });
|
|
1625
|
-
// Reuse the native file witness; a missing Windows volume is not an identity.
|
|
1626
|
-
return process.platform === 'win32' && stat.dev === 0n && stat.isFile() && !stat.isSymbolicLink()
|
|
1627
|
-
? util.statRegularFileIdentity(path) : stat;
|
|
1628
|
-
}
|
|
1629
1645
|
export function readBootstrapArtifactFile(path, maxBytes = MAX_ARTIFACT_BYTES, hooks = {}) {
|
|
1630
1646
|
if (!Number.isSafeInteger(maxBytes) || maxBytes < 1 || maxBytes > MAX_ARTIFACT_BYTES) {
|
|
1631
1647
|
throw new Error('bootstrap artifact read limit is invalid');
|
|
@@ -1637,7 +1653,9 @@ export function readBootstrapArtifactFile(path, maxBytes = MAX_ARTIFACT_BYTES, h
|
|
|
1637
1653
|
const assertTrustedLeaf = (stat) => assertTrustedBootstrapArtifactLeaf(stat, process.platform, trustedUid, path, role);
|
|
1638
1654
|
if (process.platform === 'win32')
|
|
1639
1655
|
assertWindowsAclTrusted(path, role === 'owned');
|
|
1640
|
-
|
|
1656
|
+
// Windows runtimes in our supported range can report pathname dev=0. Bind
|
|
1657
|
+
// each path snapshot to a real handle rather than accepting an unknown volume.
|
|
1658
|
+
const before = statBootstrapFileIdentity(path);
|
|
1641
1659
|
if (before.isSymbolicLink() || !before.isFile() || before.size > BigInt(maxBytes)
|
|
1642
1660
|
|| before.dev <= 0n || before.ino <= 0n) {
|
|
1643
1661
|
throw new Error(`bootstrap artifact is not a regular owned file: ${path}`);
|
|
@@ -1647,7 +1665,9 @@ export function readBootstrapArtifactFile(path, maxBytes = MAX_ARTIFACT_BYTES, h
|
|
|
1647
1665
|
try {
|
|
1648
1666
|
const opened = fstatSync(descriptor, { bigint: true });
|
|
1649
1667
|
if (!opened.isFile() || opened.dev !== before.dev || opened.ino !== before.ino
|
|
1650
|
-
|| opened.dev <= 0n || opened.ino <= 0n || opened.size > BigInt(maxBytes)
|
|
1668
|
+
|| opened.dev <= 0n || opened.ino <= 0n || opened.size > BigInt(maxBytes)
|
|
1669
|
+
|| opened.size !== before.size || opened.mtimeNs !== before.mtimeNs
|
|
1670
|
+
|| opened.ctimeNs !== before.ctimeNs || opened.nlink !== before.nlink) {
|
|
1651
1671
|
throw new Error(`bootstrap artifact changed while opening: ${path}`);
|
|
1652
1672
|
}
|
|
1653
1673
|
assertTrustedLeaf(opened);
|
|
@@ -1668,7 +1688,8 @@ export function readBootstrapArtifactFile(path, maxBytes = MAX_ARTIFACT_BYTES, h
|
|
|
1668
1688
|
hash.update(chunk);
|
|
1669
1689
|
}
|
|
1670
1690
|
const after = fstatSync(descriptor, { bigint: true });
|
|
1671
|
-
if (after.
|
|
1691
|
+
if (!after.isFile() || after.dev !== opened.dev || after.ino !== opened.ino
|
|
1692
|
+
|| after.size !== opened.size || after.nlink !== opened.nlink
|
|
1672
1693
|
|| after.mtimeNs !== opened.mtimeNs || after.ctimeNs !== opened.ctimeNs
|
|
1673
1694
|
|| BigInt(size) !== opened.size) {
|
|
1674
1695
|
throw new Error(`bootstrap artifact changed while hashing: ${path}`);
|
|
@@ -1677,11 +1698,11 @@ export function readBootstrapArtifactFile(path, maxBytes = MAX_ARTIFACT_BYTES, h
|
|
|
1677
1698
|
hooks.afterRead?.();
|
|
1678
1699
|
if (process.platform === 'win32')
|
|
1679
1700
|
assertWindowsAclTrusted(path, role === 'owned');
|
|
1680
|
-
const settled =
|
|
1701
|
+
const settled = statBootstrapFileIdentity(path);
|
|
1681
1702
|
if (!settled.isFile() || settled.isSymbolicLink()
|
|
1682
1703
|
|| settled.dev !== opened.dev || settled.ino !== opened.ino
|
|
1683
|
-
|| settled.size !== opened.size || settled.
|
|
1684
|
-
|| settled.ctimeNs !== opened.ctimeNs) {
|
|
1704
|
+
|| settled.size !== opened.size || settled.nlink !== opened.nlink
|
|
1705
|
+
|| settled.mtimeNs !== opened.mtimeNs || settled.ctimeNs !== opened.ctimeNs) {
|
|
1685
1706
|
throw new Error(`bootstrap artifact changed after reading: ${path}`);
|
|
1686
1707
|
}
|
|
1687
1708
|
assertTrustedLeaf(settled);
|
package/dist/localMemoryGraph.js
CHANGED
|
@@ -2044,7 +2044,7 @@ export class LocalMemoryGraph {
|
|
|
2044
2044
|
let closed = false;
|
|
2045
2045
|
let published = false;
|
|
2046
2046
|
try {
|
|
2047
|
-
tempIdentity = graphPathSnapshot(temp);
|
|
2047
|
+
tempIdentity = graphPathSnapshot(temp, 'write');
|
|
2048
2048
|
const descriptorIdentity = fstatSync(fd, { bigint: true });
|
|
2049
2049
|
if (!tempIdentity.isFile() || tempIdentity.isSymbolicLink()
|
|
2050
2050
|
|| !descriptorIdentity.isFile() || descriptorIdentity.isSymbolicLink()
|
|
@@ -2071,7 +2071,7 @@ export class LocalMemoryGraph {
|
|
|
2071
2071
|
}
|
|
2072
2072
|
if (!published && tempIdentity !== null) {
|
|
2073
2073
|
try {
|
|
2074
|
-
const currentIdentity = graphPathSnapshot(temp);
|
|
2074
|
+
const currentIdentity = graphPathSnapshot(temp, 'write');
|
|
2075
2075
|
if (currentIdentity.isFile() && !currentIdentity.isSymbolicLink()
|
|
2076
2076
|
&& sameGraphFileIdentity(tempIdentity, currentIdentity))
|
|
2077
2077
|
unlinkSync(temp);
|
|
@@ -2718,9 +2718,15 @@ function writeAll(fd, payload, position = null) {
|
|
|
2718
2718
|
offset += written;
|
|
2719
2719
|
}
|
|
2720
2720
|
}
|
|
2721
|
-
function graphPathSnapshot(path) {
|
|
2721
|
+
function graphPathSnapshot(path, witnessAccess = 'read') {
|
|
2722
2722
|
const named = lstatSync(path, { bigint: true });
|
|
2723
|
-
|
|
2723
|
+
const stat = named.isFile() && !named.isSymbolicLink()
|
|
2724
|
+
? assetstore.captureRegularAssetFileSnapshot(path, witnessAccess === 'write' ? constants.O_WRONLY : constants.O_RDONLY)
|
|
2725
|
+
: named;
|
|
2726
|
+
if (process.platform === 'win32' && stat.isFile() && (stat.dev <= 0n || stat.ino <= 0n)) {
|
|
2727
|
+
throw new Error('memory_graph_path_rejected');
|
|
2728
|
+
}
|
|
2729
|
+
return stat;
|
|
2724
2730
|
}
|
|
2725
2731
|
function sameGraphFileIdentity(left, right) {
|
|
2726
2732
|
const hasStableFileId = left.dev !== 0n || left.ino !== 0n || right.dev !== 0n || right.ino !== 0n;
|
|
@@ -265,6 +265,7 @@ async function selectPromptGenes(prompt, snapshot, maxGenes, budget, benchmark)
|
|
|
265
265
|
const boundedPrompt = promptTokens.join(' ');
|
|
266
266
|
const receipts = new Map();
|
|
267
267
|
const approved = recall.approvedGenesFromSnapshot(snapshot, PROMPT_RECALL_SCAN_LIMIT, {
|
|
268
|
+
recent: true,
|
|
268
269
|
signal: budget.signal, deadlineAt: budget.deadlineAt,
|
|
269
270
|
...(benchmark ? { benchmark } : {}),
|
|
270
271
|
onQualification: (values) => { for (const receipt of values)
|
|
@@ -574,6 +575,7 @@ async function runPromptRecallHookOwned(argv, deps) {
|
|
|
574
575
|
if (!recall.isBuiltInPromptProvider(store))
|
|
575
576
|
throw new Error('unsupported_prompt_context_provider_v1');
|
|
576
577
|
return store.beginPromptGeneSnapshotV1({
|
|
578
|
+
recent: true,
|
|
577
579
|
deadlineAt: budget.deadlineAt, signal: budget.signal,
|
|
578
580
|
maxFileBytes: MAX_PROMPT_RECALL_LOCAL_FILE_BYTES, maxTotalBytes: MAX_PROMPT_RECALL_LOCAL_TOTAL_BYTES
|
|
579
581
|
});
|
package/dist/setupHooks.js
CHANGED
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
// cleanly removes only evolver's entries.
|
|
7
7
|
import { planInjection, installInjection, uninstallInjection, runtimeSupport, renderManualWiring, renderServiceGuidance, SETUP_RUNTIMES, SERVICE_TARGETS, kiroConfigRoot, resolveOpenCodeConfig, McpConfigConflictError, McpConfigOwnershipError, McpConfigVerificationError, McpServerValidationError } from '@evomap/evolver-mcp';
|
|
8
8
|
import { assetstore, events } from '@evomap/evolver-core';
|
|
9
|
-
import { resolveInstallComponents } from '@evomap/evolver-mcp';
|
|
10
|
-
import { accessSync, constants, existsSync, readFileSync, realpathSync, statSync } from 'node:fs';
|
|
9
|
+
import { resolveInstallComponents, InstallerTransactionError, installerTransactionFromError } from '@evomap/evolver-mcp';
|
|
10
|
+
import { accessSync, constants, existsSync, lstatSync, readFileSync, realpathSync, statSync } from 'node:fs';
|
|
11
11
|
import { createRequire } from 'node:module';
|
|
12
12
|
import { homedir } from 'node:os';
|
|
13
13
|
import { basename, delimiter, dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
|
|
@@ -18,7 +18,7 @@ import { reviewLedgerForStore } from './reviewFilter.js';
|
|
|
18
18
|
import { maybeEmitNonGitWorkspaceNotice } from './nonGitWorkspaceNotice.js';
|
|
19
19
|
import { AGENT_PLUGIN_NAME, pluginHostNamed } from './pluginHosts.js';
|
|
20
20
|
import { protectedAuditInstallReport } from './protectedAuditStatus.js';
|
|
21
|
-
import { createSetupLifecyclePlan, decodeSetupLifecyclePlan, executeSetupLifecyclePlan, SETUP_LIFECYCLE_SCHEMA, setupLifecycleCapabilities, SetupLifecycleError, verifySetupLifecycle, } from './setupHooksLifecycle.js';
|
|
21
|
+
import { createSetupLifecyclePlan, decodeSetupLifecyclePlan, executeSetupLifecyclePlan, inspectSetupTransactions, recoverSetupLifecycle, SETUP_LIFECYCLE_SCHEMA, setupLifecycleCapabilities, SetupLifecycleError, verifySetupLifecycle, } from './setupHooksLifecycle.js';
|
|
22
22
|
const requireFromHere = createRequire(import.meta.url);
|
|
23
23
|
function configuredHomeDir() {
|
|
24
24
|
const configured = process.platform === 'win32'
|
|
@@ -26,6 +26,14 @@ function configuredHomeDir() {
|
|
|
26
26
|
: process.env['HOME'];
|
|
27
27
|
return configured && configured.trim() ? configured : homedir();
|
|
28
28
|
}
|
|
29
|
+
function projectRootIsDirectoryOrMissing(path) {
|
|
30
|
+
try {
|
|
31
|
+
return lstatSync(path).isDirectory();
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
return error.code === 'ENOENT';
|
|
35
|
+
}
|
|
36
|
+
}
|
|
29
37
|
function parseFlags(argv) {
|
|
30
38
|
const out = {};
|
|
31
39
|
for (let i = 0; i < argv.length; i++) {
|
|
@@ -46,7 +54,8 @@ function parseFlags(argv) {
|
|
|
46
54
|
}
|
|
47
55
|
return out;
|
|
48
56
|
}
|
|
49
|
-
const USAGE = `usage: evolver setup-hooks [--runtime=${SETUP_RUNTIMES.join('|')}] [--scope=user|project|global] [--components=product-only|evolution-only|both] [--root=<dir>] [--lifecycle=capabilities|plan|verify|execute] [--action=install|uninstall] [--confirmed-plan=<base64url>] [--target-id=<id>] [--completed-targets=<id,id>] [--env-file=<path>] [--profile-descriptor=<json>] [--service=${SERVICE_TARGETS.join('|')}] [--verify] [--uninstall] [--dry-run] [--force] [--json] [--hook-command="evolver inject session-start"] [--prompt-recall-hook-command="evolver inject prompt-recall"] [--server-node=<absolute-node>] [--server-command=<cmd>] [--server-args=a,b] [--service-command=<cmd>] [--service-args=a,b]\n --verify is read-only for claude-code, codex, opencode and kiro\n lifecycle operations are versioned JSON and require --json\n`;
|
|
57
|
+
const USAGE = `usage: evolver setup-hooks [--runtime=${SETUP_RUNTIMES.join('|')}] [--scope=user|project|global] [--components=product-only|evolution-only|both] [--root=<dir>] [--lifecycle=capabilities|plan|verify|execute|status|recover] [--action=install|uninstall] [--confirmed-plan=<base64url>] [--target-id=<id>] [--completed-targets=<id,id>] [--env-file=<path>] [--profile-descriptor=<json>] [--service=${SERVICE_TARGETS.join('|')}] [--verify] [--uninstall] [--dry-run] [--force] [--json] [--hook-command="evolver inject session-start"] [--prompt-recall-hook-command="evolver inject prompt-recall"] [--server-node=<absolute-node>] [--server-command=<cmd>] [--server-args=a,b] [--service-command=<cmd>] [--service-args=a,b]\n --verify is read-only for claude-code, codex, opencode and kiro\n lifecycle operations are versioned JSON and require --json\n`;
|
|
58
|
+
const TRANSACTION_USAGE = '\nRecovery (configuration files and ownership backups; sequential, not instant cross-file visibility):\n --lifecycle=status --json [--transaction-id=<id>]\n --lifecycle=recover --json --transaction-id=<id> --recovery=rollback\n --lifecycle=recover --json --transaction-id=<id> --recovery=resume --action=install|uninstall\n After manually reconciling a blocked config, inspect status again, then explicitly preserve that reviewed state:\n --lifecycle=recover --json --transaction-id=<id> --recovery=accept-current --confirmed-state=<resolution_digest>\nUse the same runtime, scope, root and original install options. Concurrent edits block rollback rather than being overwritten.\n';
|
|
50
59
|
export function commandNamesForPath(command, platform, pathExt) {
|
|
51
60
|
if (platform !== 'win32' || /\.[^\\/]+$/.test(command))
|
|
52
61
|
return [command];
|
|
@@ -204,6 +213,8 @@ function displayResultPaths(paths, configRoot, scope) {
|
|
|
204
213
|
export function safeSetupOperationError(error) {
|
|
205
214
|
if (error instanceof Error && error.message === '[setup-hooks] product bridge is user-owned; explicit --force is required')
|
|
206
215
|
return error.message;
|
|
216
|
+
if (error instanceof InstallerTransactionError)
|
|
217
|
+
return error.message;
|
|
207
218
|
if (error instanceof McpConfigConflictError)
|
|
208
219
|
return error.message;
|
|
209
220
|
if (error instanceof McpConfigOwnershipError)
|
|
@@ -527,7 +538,7 @@ function appendAdapterNotes(text, hints) {
|
|
|
527
538
|
: text;
|
|
528
539
|
}
|
|
529
540
|
const SETUP_VALUE_FLAGS = new Set([
|
|
530
|
-
'runtime', 'platform', 'scope', 'root', 'components', 'lifecycle', 'action', 'confirmed-plan', 'target-id', 'completed-targets', 'env-file', 'profile-descriptor', 'service',
|
|
541
|
+
'runtime', 'platform', 'scope', 'root', 'components', 'lifecycle', 'action', 'confirmed-plan', 'transaction-id', 'recovery', 'confirmed-state', 'target-id', 'completed-targets', 'env-file', 'profile-descriptor', 'service',
|
|
531
542
|
'hook-command', 'server-node', 'server-command', 'server-args', 'service-command', 'service-args',
|
|
532
543
|
]);
|
|
533
544
|
function setupHelpRequested(argv) {
|
|
@@ -564,7 +575,7 @@ function runSetupLifecycle(f, runtime, scope, configRoot, emit, deps) {
|
|
|
564
575
|
};
|
|
565
576
|
if (f['json'] !== true)
|
|
566
577
|
return fail('PLAN_INVALID', 'lifecycle operations require --json');
|
|
567
|
-
if (typeof operation !== 'string' || !['capabilities', 'plan', 'verify', 'execute'].includes(operation)) {
|
|
578
|
+
if (typeof operation !== 'string' || !['capabilities', 'plan', 'verify', 'execute', 'status', 'recover'].includes(operation)) {
|
|
568
579
|
return fail('PLAN_INVALID', 'invalid --lifecycle operation');
|
|
569
580
|
}
|
|
570
581
|
if (f['verify'] !== undefined || f['uninstall'] !== undefined || f['dry-run'] !== undefined || f['force'] !== undefined) {
|
|
@@ -589,8 +600,20 @@ function runSetupLifecycle(f, runtime, scope, configRoot, emit, deps) {
|
|
|
589
600
|
}
|
|
590
601
|
if (!capabilities.supported)
|
|
591
602
|
return fail('CAPABILITY_UNAVAILABLE', `lifecycle protocol is unavailable for ${runtime}/${scope}`);
|
|
603
|
+
if ((f['transaction-id'] !== undefined && operation !== 'status' && operation !== 'recover')
|
|
604
|
+
|| (f['recovery'] !== undefined && operation !== 'recover')
|
|
605
|
+
|| (f['confirmed-state'] !== undefined && (operation !== 'recover' || f['recovery'] !== 'accept-current'))) {
|
|
606
|
+
return fail('PLAN_INVALID', 'transaction recovery flags require --lifecycle=status|recover');
|
|
607
|
+
}
|
|
608
|
+
const transactionID = f['transaction-id'];
|
|
609
|
+
const recovery = f['recovery'];
|
|
610
|
+
if ((transactionID !== undefined && (typeof transactionID !== 'string' || !/^[a-f0-9]{64}$/.test(transactionID)))
|
|
611
|
+
|| operation === 'recover' && (typeof transactionID !== 'string' || recovery !== 'resume' && recovery !== 'rollback' && recovery !== 'accept-current')
|
|
612
|
+
|| recovery === 'accept-current' && (typeof f['confirmed-state'] !== 'string' || !/^[a-f0-9]{64}$/.test(f['confirmed-state']))) {
|
|
613
|
+
return fail('PLAN_INVALID', 'recovery requires --transaction-id=<id> and --recovery=resume|rollback|accept-current; accept-current also requires --confirmed-state=<resolution_digest>');
|
|
614
|
+
}
|
|
592
615
|
const action = lifecycleAction(f['action']);
|
|
593
|
-
if ((operation === 'plan' || operation === 'execute') && action === undefined) {
|
|
616
|
+
if ((operation === 'plan' || operation === 'execute' || operation === 'recover' && recovery === 'resume') && action === undefined) {
|
|
594
617
|
return fail('PLAN_INVALID', '--action=install|uninstall is required');
|
|
595
618
|
}
|
|
596
619
|
const descriptor = f['components'] === 'product-only'
|
|
@@ -600,7 +623,7 @@ function runSetupLifecycle(f, runtime, scope, configRoot, emit, deps) {
|
|
|
600
623
|
return fail('PLAN_INVALID', descriptor.error, 1);
|
|
601
624
|
let server = { command: 'evolver-mcp' };
|
|
602
625
|
let productBridgeNodePath;
|
|
603
|
-
if (operation === 'verify' || action === 'install') {
|
|
626
|
+
if (operation === 'verify' || action === 'install' && operation !== 'status' && !(operation === 'recover' && recovery !== 'resume')) {
|
|
604
627
|
try {
|
|
605
628
|
const built = buildServer(f, descriptor.descriptor, deps.resolveMcpNodePath);
|
|
606
629
|
server = built.server;
|
|
@@ -635,6 +658,22 @@ function runSetupLifecycle(f, runtime, scope, configRoot, emit, deps) {
|
|
|
635
658
|
},
|
|
636
659
|
};
|
|
637
660
|
try {
|
|
661
|
+
if (operation === 'status') {
|
|
662
|
+
emit({ schema: SETUP_LIFECYCLE_SCHEMA, operation, ok: true,
|
|
663
|
+
transactions: inspectSetupTransactions(context, typeof transactionID === 'string' ? transactionID : undefined)
|
|
664
|
+
.filter(transaction => transaction.runtime === runtime && transaction.scope === scope) });
|
|
665
|
+
return 0;
|
|
666
|
+
}
|
|
667
|
+
if (operation === 'recover') {
|
|
668
|
+
if (recovery === 'resume') {
|
|
669
|
+
const recorded = inspectSetupTransactions(context, transactionID)[0];
|
|
670
|
+
if (recorded && recorded.action !== action)
|
|
671
|
+
return fail('PLAN_INVALID', 'resume action does not match the durable transaction', 1);
|
|
672
|
+
}
|
|
673
|
+
const result = recoverSetupLifecycle(context, transactionID, recovery, typeof f['confirmed-state'] === 'string' ? f['confirmed-state'] : undefined);
|
|
674
|
+
emit({ schema: SETUP_LIFECYCLE_SCHEMA, operation, ok: true, result });
|
|
675
|
+
return result.complete ? 0 : 1;
|
|
676
|
+
}
|
|
638
677
|
if (operation === 'plan') {
|
|
639
678
|
const plan = createSetupLifecyclePlan(context, action);
|
|
640
679
|
emit({ schema: SETUP_LIFECYCLE_SCHEMA, operation, ok: true, plan });
|
|
@@ -672,12 +711,17 @@ function runSetupLifecycle(f, runtime, scope, configRoot, emit, deps) {
|
|
|
672
711
|
catch (error) {
|
|
673
712
|
if (error instanceof SetupLifecycleError)
|
|
674
713
|
return fail(error.code, error.message, 1);
|
|
714
|
+
if (error instanceof InstallerTransactionError) {
|
|
715
|
+
emit({ schema: SETUP_LIFECYCLE_SCHEMA, operation, ok: false, code: error.code, error: error.message,
|
|
716
|
+
...(error.transaction ? { transaction: error.transaction } : {}) });
|
|
717
|
+
return 1;
|
|
718
|
+
}
|
|
675
719
|
return fail('VERIFY_FAILED', safeSetupOperationError(error), 1);
|
|
676
720
|
}
|
|
677
721
|
}
|
|
678
722
|
export async function runSetupHooks(argv, store, review, deps = {}) {
|
|
679
723
|
if (setupHelpRequested(argv)) {
|
|
680
|
-
process.stdout.write(USAGE);
|
|
724
|
+
process.stdout.write(USAGE + TRANSACTION_USAGE);
|
|
681
725
|
return 0;
|
|
682
726
|
}
|
|
683
727
|
const f = parseFlags(argv);
|
|
@@ -731,6 +775,17 @@ export async function runSetupHooks(argv, store, review, deps = {}) {
|
|
|
731
775
|
process.stderr.write(`${message}\n`);
|
|
732
776
|
return 2;
|
|
733
777
|
}
|
|
778
|
+
// Reject invalid project roots before Node resolution or recovery-state creation. Lifecycle recovery
|
|
779
|
+
// and user-only targets keep their existing handling of missing or unrelated project paths.
|
|
780
|
+
if (support.outcome === 'installed' && scope === 'project' && runtime !== 'antigravity'
|
|
781
|
+
&& !projectRootIsDirectoryOrMissing(configRoot)) {
|
|
782
|
+
const error = '[setup-hooks] config root must be a real directory';
|
|
783
|
+
if (json)
|
|
784
|
+
emit({ runtime, outcome: 'error', files: [], error });
|
|
785
|
+
else
|
|
786
|
+
process.stderr.write(`${error}\n`);
|
|
787
|
+
return 1;
|
|
788
|
+
}
|
|
734
789
|
// V1 exposed setup-hooks --verify as a read-only operation. Silently ignoring it is unsafe: the command then
|
|
735
790
|
// falls through to installInjection and can rewrite runtime configuration while the operator asked only to
|
|
736
791
|
// inspect it. V2's JSON MCP installers already have a transaction-free dry-run preflight, so use that as the
|
|
@@ -839,7 +894,8 @@ export async function runSetupHooks(argv, store, review, deps = {}) {
|
|
|
839
894
|
catch (error) {
|
|
840
895
|
const message = safeSetupOperationError(error);
|
|
841
896
|
if (json)
|
|
842
|
-
emit({ runtime, action: 'uninstall', files: [], error: message
|
|
897
|
+
emit({ runtime, action: 'uninstall', files: [], error: message,
|
|
898
|
+
transaction: installerTransactionFromError(error) });
|
|
843
899
|
else
|
|
844
900
|
process.stderr.write(`${message}\n`);
|
|
845
901
|
return 1;
|
|
@@ -862,7 +918,7 @@ export async function runSetupHooks(argv, store, review, deps = {}) {
|
|
|
862
918
|
return 0;
|
|
863
919
|
}
|
|
864
920
|
if (json)
|
|
865
|
-
emit({ runtime, action: 'uninstall', files, backups });
|
|
921
|
+
emit({ runtime, action: 'uninstall', files, backups, transaction: r.transaction });
|
|
866
922
|
else
|
|
867
923
|
process.stdout.write(files.length ? `removed evolver from: ${files.join(', ')}\n` : 'nothing to remove\n');
|
|
868
924
|
return 0;
|
|
@@ -1008,7 +1064,8 @@ export async function runSetupHooks(argv, store, review, deps = {}) {
|
|
|
1008
1064
|
// distinct from the support-matrix `unsupported` (an unrecognized runtime id) (Bugbot #264).
|
|
1009
1065
|
const msg = safeSetupOperationError(e);
|
|
1010
1066
|
if (json)
|
|
1011
|
-
emit({ runtime, outcome: 'error', files: [], error: msg
|
|
1067
|
+
emit({ runtime, outcome: 'error', files: [], error: msg,
|
|
1068
|
+
transaction: installerTransactionFromError(e) });
|
|
1012
1069
|
else
|
|
1013
1070
|
process.stderr.write(`${msg}\n`);
|
|
1014
1071
|
return 1;
|
|
@@ -1062,7 +1119,7 @@ export async function runSetupHooks(argv, store, review, deps = {}) {
|
|
|
1062
1119
|
return 0;
|
|
1063
1120
|
}
|
|
1064
1121
|
if (json)
|
|
1065
|
-
emit({ runtime, outcome: 'installed', files, backups, mode: r.mode, verified: r.verified, ...audit, ...warningFields });
|
|
1122
|
+
emit({ runtime, outcome: 'installed', files, backups, mode: r.mode, verified: r.verified, transaction: r.transaction, ...audit, ...warningFields });
|
|
1066
1123
|
else
|
|
1067
1124
|
process.stdout.write(`installed evolver (${r.mode}) → ${files.join(', ')}\n`);
|
|
1068
1125
|
emitWarnings(warnings);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { type InjectionPlan, type InstallOptions, type InstallScope, type RuntimeId } from '@evomap/evolver-mcp';
|
|
1
|
+
import { INSTALLER_TRANSACTION_SCHEMA, type InstallerTransactionSummary, type InjectionPlan, type InstallOptions, type InstallScope, type RuntimeId } from '@evomap/evolver-mcp';
|
|
2
|
+
export { inspectSetupTransactions } from './setupHooksTransaction.js';
|
|
2
3
|
export declare const SETUP_LIFECYCLE_SCHEMA = "evolver.setup_hooks.lifecycle.v1";
|
|
3
4
|
export declare const SETUP_LIFECYCLE_PLAN_TTL_MS = 120000;
|
|
4
5
|
export type SetupLifecycleAction = 'install' | 'uninstall';
|
|
@@ -11,6 +12,12 @@ export interface SetupLifecycleCapabilities {
|
|
|
11
12
|
hookCommandsBound: boolean;
|
|
12
13
|
standaloneMcp: boolean;
|
|
13
14
|
operations: Record<SetupLifecycleOperation, boolean>;
|
|
15
|
+
transactions: {
|
|
16
|
+
schema: typeof INSTALLER_TRANSACTION_SCHEMA;
|
|
17
|
+
durable: boolean;
|
|
18
|
+
atomicVisibility: false;
|
|
19
|
+
recovery: boolean;
|
|
20
|
+
};
|
|
14
21
|
}
|
|
15
22
|
export interface SetupLifecycleTarget {
|
|
16
23
|
target_id: string;
|
|
@@ -37,7 +44,8 @@ export interface SetupLifecycleTargetResult {
|
|
|
37
44
|
outcome: 'installed' | 'removed' | 'already_satisfied' | 'already_absent' | 'failed';
|
|
38
45
|
committed: boolean;
|
|
39
46
|
verified: boolean;
|
|
40
|
-
recovery?: 'REFRESH_PLAN' | 'OPEN_CONFIG' | 'RETRY_VERIFICATION';
|
|
47
|
+
recovery?: 'REFRESH_PLAN' | 'OPEN_CONFIG' | 'RETRY_VERIFICATION' | 'ROLLBACK_TRANSACTION';
|
|
48
|
+
rolled_back?: boolean;
|
|
41
49
|
}
|
|
42
50
|
export interface SetupLifecycleExecutionResult {
|
|
43
51
|
schema: typeof SETUP_LIFECYCLE_SCHEMA;
|
|
@@ -50,6 +58,13 @@ export interface SetupLifecycleExecutionResult {
|
|
|
50
58
|
complete: boolean;
|
|
51
59
|
verified: boolean;
|
|
52
60
|
targets: SetupLifecycleTargetResult[];
|
|
61
|
+
transaction?: InstallerTransactionSummary;
|
|
62
|
+
failure?: {
|
|
63
|
+
code: string;
|
|
64
|
+
target_id?: string;
|
|
65
|
+
message: string;
|
|
66
|
+
recovery: 'REFRESH_PLAN' | 'ROLLBACK_TRANSACTION';
|
|
67
|
+
};
|
|
53
68
|
}
|
|
54
69
|
export interface SetupLifecycleExecutionOptions {
|
|
55
70
|
targetId?: string;
|
|
@@ -72,4 +87,5 @@ export declare function createSetupLifecyclePlan(context: SetupLifecycleContext,
|
|
|
72
87
|
export declare function encodeSetupLifecyclePlan(plan: SetupLifecyclePlan): string;
|
|
73
88
|
export declare function decodeSetupLifecyclePlan(raw: string): SetupLifecyclePlan;
|
|
74
89
|
export declare function verifySetupLifecycle(context: SetupLifecycleContext): boolean;
|
|
75
|
-
export declare function executeSetupLifecyclePlan(context: SetupLifecycleContext, confirmed: SetupLifecyclePlan, options?: SetupLifecycleExecutionOptions): SetupLifecycleExecutionResult;
|
|
90
|
+
export declare function executeSetupLifecyclePlan(context: SetupLifecycleContext, confirmed: SetupLifecyclePlan, options?: SetupLifecycleExecutionOptions): SetupLifecycleExecutionResult;
|
|
91
|
+
export declare function recoverSetupLifecycle(context: SetupLifecycleContext, id: string, recovery: 'resume' | 'rollback' | 'accept-current', confirmedState?: string): InstallerTransactionSummary | SetupLifecycleExecutionResult;
|
|
@@ -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/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",
|