@evomap/evolver-cli 2.0.49 → 2.0.51
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/assetEvolution.d.ts +9 -0
- package/dist/assetEvolution.js +164 -0
- package/dist/commandCatalog.d.ts +4 -0
- package/dist/commandCatalog.js +4 -0
- package/dist/containedWrite.d.ts +8 -0
- package/dist/containedWrite.js +79 -0
- package/dist/dispatch.js +8 -0
- package/dist/experience.js +34 -2
- package/dist/gene.d.ts +3 -0
- package/dist/gene.js +174 -0
- package/dist/jsonCommand.d.ts +34 -0
- package/dist/jsonCommand.js +118 -0
- package/dist/lifecycle.js +1 -4
- package/dist/lifecycleBootstrapTransaction.js +38 -17
- package/dist/localMemoryGraph.js +10 -4
- package/dist/pluginDrafts.d.ts +19 -0
- package/dist/pluginDrafts.js +87 -0
- package/dist/promptRecallRuntime.js +2 -0
- package/dist/publishPolicy.d.ts +6 -0
- package/dist/publishPolicy.js +19 -0
- package/dist/redact.d.ts +3 -0
- package/dist/redact.js +27 -0
- package/dist/sessionIngest.d.ts +1 -0
- package/dist/sessionIngest.js +6 -3
- 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/dist/skillFetch.d.ts +1 -0
- package/dist/skillFetch.js +18 -26
- package/dist/workflow.d.ts +2 -1
- package/dist/workflow.js +35 -12
- package/package.json +7 -7
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;
|