@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
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { resolve } from 'node:path';
|
|
3
|
+
import { installerTransactionRoot, inspectInstallerTransactions, withInstallerTransaction, InstallerTransactionError, installerTransactionFromError, completeManagedInstallerTransaction, installInjection, uninstallInjection, } from '@evomap/evolver-mcp';
|
|
4
|
+
import { SETUP_LIFECYCLE_SCHEMA, SETUP_LIFECYCLE_PLAN_TTL_MS, SetupLifecycleError, } from './setupHooksLifecycle.js';
|
|
5
|
+
function hash(value) { return createHash('sha256').update(value).digest('hex'); }
|
|
6
|
+
function verificationContext(context) {
|
|
7
|
+
return { ...context, installOptions: { ...context.installOptions, force: false } };
|
|
8
|
+
}
|
|
9
|
+
function verifyTarget(context, action, path, driver) {
|
|
10
|
+
const checking = verificationContext(context);
|
|
11
|
+
const result = driver.preview({ ...checking, installOptions: { ...checking.installOptions, ...(path ? { targetPath: path } : {}) } }, action);
|
|
12
|
+
return result.ok && result.verified !== false && result.files.length === 0 && (result.backups?.length ?? 0) === 0;
|
|
13
|
+
}
|
|
14
|
+
export function executeSetupTransaction(context, confirmed, options, driver) {
|
|
15
|
+
if (confirmed.runtime !== context.runtime || confirmed.scope !== context.scope) {
|
|
16
|
+
throw new SetupLifecycleError('PLAN_INVALID', 'confirmed lifecycle plan does not match runtime scope');
|
|
17
|
+
}
|
|
18
|
+
const { plan_id: id, ...base } = confirmed;
|
|
19
|
+
if (hash(JSON.stringify(base)) !== id)
|
|
20
|
+
throw new SetupLifecycleError('PLAN_INVALID', 'confirmed lifecycle plan identity is invalid');
|
|
21
|
+
if (driver.intent(context, confirmed.action) !== confirmed.intent_digest) {
|
|
22
|
+
throw new SetupLifecycleError('PLAN_STALE', 'lifecycle write intent changed; create a fresh plan');
|
|
23
|
+
}
|
|
24
|
+
const createdAt = new Date(confirmed.created_at);
|
|
25
|
+
const expiresAt = new Date(confirmed.expires_at);
|
|
26
|
+
if (!Number.isFinite(createdAt.getTime()) || !Number.isFinite(expiresAt.getTime())
|
|
27
|
+
|| expiresAt.getTime() - createdAt.getTime() !== SETUP_LIFECYCLE_PLAN_TTL_MS) {
|
|
28
|
+
throw new SetupLifecycleError('PLAN_INVALID', 'confirmed lifecycle plan has invalid timestamps or lifetime');
|
|
29
|
+
}
|
|
30
|
+
const root = installerTransactionRoot(context.runtime, context.installOptions);
|
|
31
|
+
const existing = inspectInstallerTransactions(root, id)[0];
|
|
32
|
+
const now = (context.now ?? (() => new Date()))().getTime();
|
|
33
|
+
if (!existing && createdAt.getTime() > now)
|
|
34
|
+
throw new SetupLifecycleError('PLAN_INVALID', 'confirmed lifecycle plan cannot start in the future');
|
|
35
|
+
if (!existing && now > expiresAt.getTime()) {
|
|
36
|
+
throw new SetupLifecycleError('PLAN_EXPIRED', 'confirmed lifecycle plan expired; create a fresh plan');
|
|
37
|
+
}
|
|
38
|
+
const selected = options.targetId;
|
|
39
|
+
if (selected !== undefined && !confirmed.targets.some(target => target.target_id === selected)) {
|
|
40
|
+
throw new SetupLifecycleError('PLAN_INVALID', 'selected lifecycle target is not in the confirmed plan');
|
|
41
|
+
}
|
|
42
|
+
const claimed = options.completedTargetIds ?? [];
|
|
43
|
+
if (claimed.length && selected === undefined || new Set(claimed).size !== claimed.length
|
|
44
|
+
|| claimed.includes(selected ?? '') || claimed.some(id => !confirmed.targets.some(target => target.target_id === id))) {
|
|
45
|
+
throw new SetupLifecycleError('PLAN_INVALID', 'completed lifecycle target set is invalid');
|
|
46
|
+
}
|
|
47
|
+
if (claimed.some(id => !existing?.completed_target_ids.includes(id))) {
|
|
48
|
+
throw new SetupLifecycleError('PLAN_INVALID', 'completed target claims are not backed by the durable transaction');
|
|
49
|
+
}
|
|
50
|
+
const paths = new Map();
|
|
51
|
+
let targets;
|
|
52
|
+
if (!existing || confirmed.targets.every(target => target.disposition === 'already_satisfied')) {
|
|
53
|
+
const current = driver.plan(context, confirmed.action, createdAt, expiresAt, paths);
|
|
54
|
+
if (JSON.stringify(current) !== JSON.stringify(confirmed)) {
|
|
55
|
+
throw new SetupLifecycleError('PLAN_STALE', 'lifecycle target identity or ownership evidence changed; create a fresh plan');
|
|
56
|
+
}
|
|
57
|
+
const preview = driver.preview(context, confirmed.action);
|
|
58
|
+
targets = confirmed.targets.map(target => {
|
|
59
|
+
const path = paths.get(target.target_id);
|
|
60
|
+
return { id: target.target_id, paths: path === undefined ? [] : [path, ...(preview.backups ?? []).filter(backup => resolve(backup) === `${path}.evolver-backup.json`)] };
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
let session;
|
|
64
|
+
const attempted = new Map();
|
|
65
|
+
let transaction;
|
|
66
|
+
let failure;
|
|
67
|
+
let executionFailed = false;
|
|
68
|
+
let activeTarget;
|
|
69
|
+
try {
|
|
70
|
+
withInstallerTransaction({ root, id, binding: confirmed.intent_digest, targets,
|
|
71
|
+
metadata: { source: 'lifecycle', runtime: context.runtime, scope: context.scope, action: confirmed.action, plan: confirmed },
|
|
72
|
+
validatePrepared: artifacts => {
|
|
73
|
+
const current = driver.plan(context, confirmed.action, createdAt, expiresAt);
|
|
74
|
+
if (JSON.stringify(current) !== JSON.stringify(confirmed)) {
|
|
75
|
+
throw new SetupLifecycleError('PLAN_STALE', 'lifecycle target identity or ownership evidence changed; create a fresh plan');
|
|
76
|
+
}
|
|
77
|
+
for (const target of confirmed.targets.filter(target => target.disposition !== 'already_satisfied')) {
|
|
78
|
+
const captured = artifacts.filter(artifact => artifact.target === target.target_id);
|
|
79
|
+
const expected = hash(JSON.stringify(captured.map(artifact => hash(JSON.stringify([artifact.path, artifact.identity])))));
|
|
80
|
+
if (!captured.length || expected !== target.expected_identity) {
|
|
81
|
+
throw new SetupLifecycleError('PLAN_STALE', 'lifecycle target identity or ownership evidence changed; create a fresh plan');
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
const preparingAt = (context.now ?? (() => new Date()))().getTime();
|
|
85
|
+
if (createdAt.getTime() > preparingAt)
|
|
86
|
+
throw new SetupLifecycleError('PLAN_INVALID', 'confirmed lifecycle plan cannot start in the future');
|
|
87
|
+
if (preparingAt > expiresAt.getTime())
|
|
88
|
+
throw new SetupLifecycleError('PLAN_EXPIRED', 'confirmed lifecycle plan expired; create a fresh plan');
|
|
89
|
+
return true;
|
|
90
|
+
},
|
|
91
|
+
}, current => {
|
|
92
|
+
session = current;
|
|
93
|
+
const metadata = current.metadata;
|
|
94
|
+
if (JSON.stringify(metadata.plan) !== JSON.stringify(confirmed))
|
|
95
|
+
throw new SetupLifecycleError('PLAN_STALE', 'durable lifecycle plan metadata changed');
|
|
96
|
+
if (claimed.some(id => !current.hasCompleted(id)))
|
|
97
|
+
throw new SetupLifecycleError('PLAN_INVALID', 'completed target claims are not backed by the durable transaction');
|
|
98
|
+
if (current.status.state === 'rollback_pending' || current.status.state === 'rolled_back' || current.status.state === 'released') {
|
|
99
|
+
throw new InstallerTransactionError('TRANSACTION_PENDING', 'This transaction cannot resume installation; finish rollback or create a fresh plan', current.status);
|
|
100
|
+
}
|
|
101
|
+
if (current.status.state !== 'committed')
|
|
102
|
+
current.armRollback();
|
|
103
|
+
current.assertCurrent();
|
|
104
|
+
const checkTarget = (path) => {
|
|
105
|
+
const verify = () => verifyTarget(context, confirmed.action, path, driver);
|
|
106
|
+
return confirmed.action === 'uninstall' ? current.verifyUninstall(verify) : verify();
|
|
107
|
+
};
|
|
108
|
+
const selectedTargets = selected === undefined ? confirmed.targets : confirmed.targets.filter(target => target.target_id === selected);
|
|
109
|
+
for (const target of selectedTargets) {
|
|
110
|
+
activeTarget = target.target_id;
|
|
111
|
+
const path = current.targets.find(candidate => candidate.id === target.target_id)?.paths[0];
|
|
112
|
+
const already = current.hasCompleted(target.target_id);
|
|
113
|
+
const noOp = target.disposition === 'already_satisfied';
|
|
114
|
+
if (already) {
|
|
115
|
+
// Identity receipts alone are not proof that the runtime still consumes this target (e.g. OpenCode precedence).
|
|
116
|
+
if (!checkTarget(path))
|
|
117
|
+
throw new SetupLifecycleError('PLAN_STALE', 'a completed lifecycle target is no longer verified');
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
current.runTarget(target.target_id, () => {
|
|
121
|
+
if (noOp)
|
|
122
|
+
return;
|
|
123
|
+
const result = driver.apply(context, confirmed.action, path);
|
|
124
|
+
if (!result.ok)
|
|
125
|
+
throw new Error(result.error ?? 'Lifecycle installer failed');
|
|
126
|
+
}, () => checkTarget(path));
|
|
127
|
+
}
|
|
128
|
+
attempted.set(target.target_id, {
|
|
129
|
+
target_id: target.target_id,
|
|
130
|
+
outcome: already || noOp ? confirmed.action === 'uninstall' ? 'already_absent' : 'already_satisfied'
|
|
131
|
+
: confirmed.action === 'install' ? 'installed' : 'removed',
|
|
132
|
+
committed: !already && !noOp && current.wasChanged(target.target_id), verified: true,
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
activeTarget = undefined;
|
|
136
|
+
if (current.targets.every(target => current.hasCompleted(target.id))) {
|
|
137
|
+
const verify = () => confirmed.action === 'install' ? driver.verify(verificationContext(context))
|
|
138
|
+
: confirmed.targets.every(target => checkTarget(current.targets.find(candidate => candidate.id === target.target_id)?.paths[0])) && checkTarget(undefined);
|
|
139
|
+
if (current.status.state !== 'committed')
|
|
140
|
+
current.commit(verify);
|
|
141
|
+
else if (!verify())
|
|
142
|
+
throw new SetupLifecycleError('PLAN_STALE', 'the committed lifecycle plan is no longer verified by the runtime');
|
|
143
|
+
}
|
|
144
|
+
transaction = current.status;
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
catch (error) {
|
|
148
|
+
executionFailed = true;
|
|
149
|
+
failure = error;
|
|
150
|
+
transaction = installerTransactionFromError(error) ?? session?.status;
|
|
151
|
+
// Pre-write invalid plans retain the established CLI error envelope. Mutation failures return all rollback facts.
|
|
152
|
+
if (!session || !session.rollbackOnError && error instanceof SetupLifecycleError)
|
|
153
|
+
throw error;
|
|
154
|
+
}
|
|
155
|
+
const resultTargets = (selected === undefined ? confirmed.targets : confirmed.targets.filter(target => target.target_id === selected)).map(target => {
|
|
156
|
+
const previous = attempted.get(target.target_id);
|
|
157
|
+
if (!executionFailed)
|
|
158
|
+
return previous;
|
|
159
|
+
const blocked = transaction?.blocked_target_ids.includes(target.target_id) ?? true;
|
|
160
|
+
return {
|
|
161
|
+
target_id: target.target_id, outcome: 'failed',
|
|
162
|
+
committed: blocked && (session?.wasChanged(target.target_id) ?? false), verified: false,
|
|
163
|
+
rolled_back: transaction?.state === 'rolled_back' || transaction?.state === 'rollback_pending' && !blocked,
|
|
164
|
+
...(blocked ? { recovery: 'ROLLBACK_TRANSACTION' } : {}),
|
|
165
|
+
};
|
|
166
|
+
});
|
|
167
|
+
const verified = !executionFailed && resultTargets.every(target => target.verified);
|
|
168
|
+
return {
|
|
169
|
+
schema: SETUP_LIFECYCLE_SCHEMA, action: confirmed.action, runtime: context.runtime, scope: context.scope,
|
|
170
|
+
plan_id: id, generation: confirmed.generation, target_set_digest: confirmed.target_set_digest,
|
|
171
|
+
complete: verified && (selected !== undefined || transaction?.state === 'committed'), verified, targets: resultTargets,
|
|
172
|
+
...(transaction ? { transaction } : {}),
|
|
173
|
+
...(executionFailed ? { failure: {
|
|
174
|
+
code: failure instanceof InstallerTransactionError || failure instanceof SetupLifecycleError ? failure.code : 'WRITE_FAILED',
|
|
175
|
+
...(activeTarget ? { target_id: activeTarget } : {}),
|
|
176
|
+
message: failure instanceof InstallerTransactionError || failure instanceof SetupLifecycleError ? failure.message
|
|
177
|
+
: `${context.runtime}/${context.scope} could not complete the confirmed target; inspect the configuration and ownership evidence before creating a fresh plan.`,
|
|
178
|
+
recovery: transaction?.state === 'rollback_pending' ? 'ROLLBACK_TRANSACTION' : 'REFRESH_PLAN',
|
|
179
|
+
} } : {}),
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
export function inspectSetupTransactions(context, id) {
|
|
183
|
+
return inspectInstallerTransactions(installerTransactionRoot(context.runtime, context.installOptions), id);
|
|
184
|
+
}
|
|
185
|
+
export function recoverSetupTransaction(context, id, recovery, driver, confirmedState) {
|
|
186
|
+
const root = installerTransactionRoot(context.runtime, context.installOptions);
|
|
187
|
+
if (recovery === 'rollback' || recovery === 'accept-current') {
|
|
188
|
+
return withInstallerTransaction({ root, id }, transaction => {
|
|
189
|
+
const metadata = transaction.metadata;
|
|
190
|
+
if (metadata.runtime !== context.runtime || metadata.scope !== context.scope) {
|
|
191
|
+
throw new InstallerTransactionError('TRANSACTION_INVALID', 'Transaction does not belong to this runtime scope');
|
|
192
|
+
}
|
|
193
|
+
return recovery === 'accept-current' ? transaction.acceptCurrent(confirmedState ?? '') : transaction.rollback();
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
let plan;
|
|
197
|
+
let installerResult;
|
|
198
|
+
withInstallerTransaction({ root, id }, transaction => {
|
|
199
|
+
const metadata = transaction.metadata;
|
|
200
|
+
if (metadata.runtime !== context.runtime || metadata.scope !== context.scope) {
|
|
201
|
+
throw new InstallerTransactionError('TRANSACTION_INVALID', 'Transaction does not belong to this runtime scope');
|
|
202
|
+
}
|
|
203
|
+
if (metadata.source === 'installer' && metadata.options && metadata.action) {
|
|
204
|
+
const action = metadata.action;
|
|
205
|
+
const options = metadata.options;
|
|
206
|
+
const injectionPlan = metadata.plan;
|
|
207
|
+
const preview = (verification) => action === 'install'
|
|
208
|
+
? installInjection(injectionPlan, { ...options, dryRun: true, ...(verification ? { force: false } : {}) })
|
|
209
|
+
: uninstallInjection(context.runtime, { ...options, dryRun: true });
|
|
210
|
+
completeManagedInstallerTransaction(transaction, context.runtime, action, action === 'install' ? injectionPlan.mode : 'uninstall', preview, targetPath => action === 'install' ? installInjection(injectionPlan, { ...options, targetPath })
|
|
211
|
+
: uninstallInjection(context.runtime, { ...options, targetPath }));
|
|
212
|
+
installerResult = transaction.status;
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
plan = metadata.plan;
|
|
216
|
+
if (!plan)
|
|
217
|
+
throw new InstallerTransactionError('TRANSACTION_INVALID', 'Resume requires durable installer intent');
|
|
218
|
+
});
|
|
219
|
+
return installerResult ?? executeSetupTransaction(context, plan, {}, driver);
|
|
220
|
+
}
|
package/dist/skillFetch.d.ts
CHANGED
package/dist/skillFetch.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { dirname, isAbsolute, relative, resolve } from 'node:path';
|
|
1
|
+
import { join } from 'node:path';
|
|
3
2
|
import { assetstore, wire } from '@evomap/evolver-core';
|
|
4
3
|
import { AuthError, HubClientError, HubUnreachableError, connectPublicHub, isHubDryRunEnabled, } from '@evomap/evolver-adapter-public';
|
|
5
4
|
import { loadEnvFileFromEnv } from '@evomap/evolver-mcp';
|
|
5
|
+
import { relativePathInsideRoot, writeFileInsideRoot } from './containedWrite.js';
|
|
6
6
|
import { createRecipeHubFromEnv } from './recipe.js';
|
|
7
7
|
import { geneToSkillMd } from './skillDistill.js';
|
|
8
8
|
const GROUP = 'skill.fetch';
|
|
@@ -53,13 +53,11 @@ async function runSkillFetchCommand(argv, deps = {}) {
|
|
|
53
53
|
stdout: deps.stdout ?? ((line) => { process.stdout.write(`${line}\n`); }),
|
|
54
54
|
stderr: deps.stderr ?? ((line) => { process.stderr.write(`${line}\n`); }),
|
|
55
55
|
};
|
|
56
|
-
const
|
|
56
|
+
const cwd = deps.cwd ?? process.cwd();
|
|
57
|
+
const parsed = parseSkillFetchArgs(argv, cwd);
|
|
57
58
|
if (!parsed.ok)
|
|
58
59
|
return emitFailure(parsed.reason, parsed.message, argv.includes('--json'), io);
|
|
59
60
|
const opts = parsed.value;
|
|
60
|
-
if (opts.source.kind === 'asset' && !opts.write && opts.outDir) {
|
|
61
|
-
// Preview with --out is still read-only; target paths are shown below.
|
|
62
|
-
}
|
|
63
61
|
try {
|
|
64
62
|
const env = deps.env ?? process.env;
|
|
65
63
|
loadEnvFileFromEnv(env);
|
|
@@ -68,7 +66,7 @@ async function runSkillFetchCommand(argv, deps = {}) {
|
|
|
68
66
|
return 0;
|
|
69
67
|
}
|
|
70
68
|
const hub = deps.hub ?? createSkillFetchHubFromEnv(deps, env);
|
|
71
|
-
const run = await buildSkillFetchResult(hub, opts);
|
|
69
|
+
const run = await buildSkillFetchResult(hub, opts, cwd);
|
|
72
70
|
if (!run.ok)
|
|
73
71
|
return emitFailure(run.reason, run.message, opts.json, io);
|
|
74
72
|
emitSuccess(run.value, opts.json, io);
|
|
@@ -79,7 +77,7 @@ async function runSkillFetchCommand(argv, deps = {}) {
|
|
|
79
77
|
return emitFailure(mapped.reason, mapped.message, opts.json, io);
|
|
80
78
|
}
|
|
81
79
|
}
|
|
82
|
-
function parseSkillFetchArgs(argv) {
|
|
80
|
+
function parseSkillFetchArgs(argv, cwd) {
|
|
83
81
|
if (argv.includes('--help') || argv.includes('-h')) {
|
|
84
82
|
return { ok: false, reason: 'usage', message: USAGE };
|
|
85
83
|
}
|
|
@@ -97,9 +95,12 @@ function parseSkillFetchArgs(argv) {
|
|
|
97
95
|
if (!Number.isSafeInteger(limit) || limit <= 0)
|
|
98
96
|
return { ok: false, reason: 'invalid_arg', message: '--limit must be a positive integer' };
|
|
99
97
|
const write = argv.includes('--write');
|
|
100
|
-
const
|
|
101
|
-
if (write && !
|
|
98
|
+
const outRaw = flagValue(argv, '--out') || undefined;
|
|
99
|
+
if (write && !outRaw)
|
|
102
100
|
return { ok: false, reason: 'invalid_arg', message: 'skill fetch --write requires --out <dir>' };
|
|
101
|
+
const outDir = outRaw === undefined ? undefined : relativePathInsideRoot(cwd, outRaw);
|
|
102
|
+
if (outDir === null)
|
|
103
|
+
return { ok: false, reason: 'invalid_arg', message: '--out must resolve to a path inside the current working directory' };
|
|
103
104
|
const select = flagValue(argv, '--select') ?? undefined;
|
|
104
105
|
const source = asset
|
|
105
106
|
? { kind: 'asset', id: asset.trim() }
|
|
@@ -127,7 +128,7 @@ function parseSkillFetchArgs(argv) {
|
|
|
127
128
|
},
|
|
128
129
|
};
|
|
129
130
|
}
|
|
130
|
-
async function buildSkillFetchResult(hub, opts) {
|
|
131
|
+
async function buildSkillFetchResult(hub, opts, cwd) {
|
|
131
132
|
const direct = opts.source.kind === 'asset' ? await fetchGeneById(hub, opts.source.id) : null;
|
|
132
133
|
if (direct && !direct.ok)
|
|
133
134
|
return direct;
|
|
@@ -157,7 +158,7 @@ async function buildSkillFetchResult(hub, opts) {
|
|
|
157
158
|
if (selected.asset.asset_id !== previewed.assetId) {
|
|
158
159
|
return { ok: false, reason: 'integrity_error', message: 'selected Gene asset_id changed after preview' };
|
|
159
160
|
}
|
|
160
|
-
const written = writeSkill(selected.asset, opts.outDir, opts.force);
|
|
161
|
+
const written = writeSkill(selected.asset, cwd, opts.outDir, opts.force);
|
|
161
162
|
if (!written.ok)
|
|
162
163
|
return written;
|
|
163
164
|
return { ok: true, value: { mode: 'write', candidates: [candidateFromGene(selected.asset, opts.outDir)], written: written.value } };
|
|
@@ -231,16 +232,14 @@ function candidateFromGene(gene, outDir) {
|
|
|
231
232
|
candidate.target = relativeSkillPath(name);
|
|
232
233
|
return candidate;
|
|
233
234
|
}
|
|
234
|
-
function writeSkill(gene, outDir, force) {
|
|
235
|
+
function writeSkill(gene, cwd, outDir, force) {
|
|
235
236
|
const name = skillNameForGene(gene);
|
|
236
237
|
const target = relativeSkillPath(name);
|
|
237
|
-
const
|
|
238
|
-
if (!
|
|
239
|
-
return { ok: false, reason: 'invalid_arg', message: 'resolved skill target escapes --out directory' };
|
|
240
|
-
if (existsSync(targetPath) && !force)
|
|
238
|
+
const write = writeFileInsideRoot(cwd, join(outDir, target), geneToSkillMd(gene, { name }), force);
|
|
239
|
+
if (!write.ok && write.reason === 'exists')
|
|
241
240
|
return { ok: false, reason: 'conflict', message: `SKILL.md already exists for skill ${name}; use --force to overwrite` };
|
|
242
|
-
|
|
243
|
-
|
|
241
|
+
if (!write.ok)
|
|
242
|
+
return { ok: false, reason: 'invalid_arg', message: 'skill target path must not pass through a symlink, junction, hard link, or non-directory' };
|
|
244
243
|
const written = { target, assetId: gene.asset_id, name };
|
|
245
244
|
const geneId = stringField(gene, 'id');
|
|
246
245
|
if (geneId)
|
|
@@ -361,16 +360,9 @@ function safeSkillName(value) {
|
|
|
361
360
|
.slice(0, 80);
|
|
362
361
|
return slug || 'skill';
|
|
363
362
|
}
|
|
364
|
-
function targetSkillPath(outDir, name) {
|
|
365
|
-
return resolve(outDir, 'skills', safeSkillName(name), 'SKILL.md');
|
|
366
|
-
}
|
|
367
363
|
function relativeSkillPath(name) {
|
|
368
364
|
return `skills/${safeSkillName(name)}/SKILL.md`;
|
|
369
365
|
}
|
|
370
|
-
function isInside(parent, child) {
|
|
371
|
-
const rel = relative(parent, child);
|
|
372
|
-
return rel.length > 0 && !rel.startsWith('..') && !isAbsolute(rel);
|
|
373
|
-
}
|
|
374
366
|
function arrayOfStrings(value) {
|
|
375
367
|
return Array.isArray(value) ? value.map((item) => String(item).trim()).filter(Boolean) : [];
|
|
376
368
|
}
|
package/dist/workflow.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { workflow } from '@evomap/evolver-core';
|
|
2
2
|
import { type ProductionWorkflowRuntimeOptions } from './workflowRuntime.js';
|
|
3
|
-
export declare const WORKFLOW_SUBCOMMANDS: readonly ["start", "submit", "list", "status", "history", "pause", "resume", "cancel", "approve", "reject"];
|
|
3
|
+
export declare const WORKFLOW_SUBCOMMANDS: readonly ["start", "submit", "list", "status", "inspect", "history", "pause", "resume", "cancel", "approve", "reject"];
|
|
4
4
|
type OutputStream = Pick<NodeJS.WriteStream, 'write'>;
|
|
5
5
|
type RuntimeControlOptions = {
|
|
6
6
|
actor: string;
|
|
@@ -18,6 +18,7 @@ type WorkflowRuntimeLike = {
|
|
|
18
18
|
};
|
|
19
19
|
type WorkflowStoreLike = {
|
|
20
20
|
read(runId: string): workflow.WorkflowRunState;
|
|
21
|
+
inspect?: (runId: string) => workflow.WorkflowRunState;
|
|
21
22
|
listRunIds(): string[];
|
|
22
23
|
history?: (runId: string) => unknown;
|
|
23
24
|
readHistory?: (runId: string) => unknown;
|
package/dist/workflow.js
CHANGED
|
@@ -7,7 +7,7 @@ const MAX_SPEC_BYTES = 1_048_576;
|
|
|
7
7
|
const MAX_REASON_LENGTH = 500;
|
|
8
8
|
const DEFAULT_ACTOR = 'local-operator';
|
|
9
9
|
export const WORKFLOW_SUBCOMMANDS = [
|
|
10
|
-
'start', 'submit', 'list', 'status', 'history', 'pause', 'resume', 'cancel', 'approve', 'reject',
|
|
10
|
+
'start', 'submit', 'list', 'status', 'inspect', 'history', 'pause', 'resume', 'cancel', 'approve', 'reject',
|
|
11
11
|
];
|
|
12
12
|
class WorkflowCliError extends Error {
|
|
13
13
|
code;
|
|
@@ -23,6 +23,7 @@ function usage(stderr) {
|
|
|
23
23
|
' evolver workflow start|submit <spec-file> [--run-id <id>] [--state-dir <path>] [--autoexec-home <path>] [--json]',
|
|
24
24
|
' evolver workflow list [--state-dir <path>] [--autoexec-home <path>] [--json]',
|
|
25
25
|
' evolver workflow status|history <run-id> [--state-dir <path>] [--autoexec-home <path>] [--json]',
|
|
26
|
+
' evolver workflow inspect <run-id> [--state-dir <path>] [--json] # stored checkpoint; no writes or recovery',
|
|
26
27
|
' evolver workflow pause|resume|cancel <run-id> [--actor <id>] [--reason <text>] [--state-dir <path>] [--autoexec-home <path>] [--json]',
|
|
27
28
|
' evolver workflow approve|reject <run-id> <gate-id> [--actor <id>] [--reason <text>] [--state-dir <path>] [--autoexec-home <path>] [--json]',
|
|
28
29
|
].join('\n') + '\n');
|
|
@@ -157,24 +158,34 @@ function statusPayload(state) {
|
|
|
157
158
|
attempts: current?.attempts ?? 0,
|
|
158
159
|
maxAttempts: current?.maxAttempts ?? 0,
|
|
159
160
|
lastErrorClass: safeMetadataToken(state.lastErrorClass),
|
|
160
|
-
createdAt: state.createdAt,
|
|
161
|
-
updatedAt: state.updatedAt,
|
|
162
|
-
completedAt: state.completedAt
|
|
161
|
+
createdAt: safeString(state.createdAt, 64),
|
|
162
|
+
updatedAt: safeString(state.updatedAt, 64),
|
|
163
|
+
completedAt: safeString(state.completedAt, 64),
|
|
163
164
|
};
|
|
164
165
|
}
|
|
165
166
|
function safeString(value, maxLength = 500) {
|
|
166
167
|
if (typeof value !== 'string' || value.length > maxLength || workflow.containsWorkflowSensitiveText(value))
|
|
167
168
|
return null;
|
|
168
|
-
|
|
169
|
-
const code = character.charCodeAt(0);
|
|
170
|
-
return code <= 0x1f || code === 0x7f;
|
|
171
|
-
});
|
|
172
|
-
return hasControlCharacter ? null : value;
|
|
169
|
+
return /[\p{Cc}\p{Bidi_Control}\p{Zl}\p{Zp}]/u.test(value) ? null : value;
|
|
173
170
|
}
|
|
174
|
-
function safeMetadataToken(value) {
|
|
175
|
-
const candidate = safeString(value,
|
|
171
|
+
function safeMetadataToken(value, maxLength = 64) {
|
|
172
|
+
const candidate = safeString(value, maxLength);
|
|
176
173
|
return candidate !== null && /^[A-Za-z0-9._-]+$/.test(candidate) ? candidate : null;
|
|
177
174
|
}
|
|
175
|
+
function inspectionPayload(state) {
|
|
176
|
+
const gateId = state.status === 'waiting_approval' ? safeMetadataToken(state.approval?.gateId, 128) : null;
|
|
177
|
+
const nextAction = state.status === 'waiting_approval' && gateId !== null ? 'review_approval'
|
|
178
|
+
: state.status === 'unsafe_to_resume' ? 'manual_reconciliation'
|
|
179
|
+
: state.status === 'failed' || state.status === 'waiting_approval' ? 'inspect_history'
|
|
180
|
+
: state.status === 'paused' ? 'review_before_resume'
|
|
181
|
+
: state.status === 'succeeded' || state.status === 'cancelled' ? 'none' : 'observe';
|
|
182
|
+
const step = state.currentStep ? state.steps[state.currentStep] : undefined;
|
|
183
|
+
const metadata = Object.fromEntries(Object.entries(statusPayload(state))
|
|
184
|
+
.map(([key, value]) => [key, typeof value === 'string' ? safeString(value)
|
|
185
|
+
: typeof value === 'number' && Number.isFinite(value) ? value : null]));
|
|
186
|
+
return { ...metadata, view: 'stored_checkpoint', nextAction, approvalGateId: gateId,
|
|
187
|
+
nextAttemptAt: state.status === 'retry_wait' ? safeString(step?.nextAttemptAt, 64) : null };
|
|
188
|
+
}
|
|
178
189
|
function historyPayload(entry) {
|
|
179
190
|
if (!isRecord(entry))
|
|
180
191
|
return { type: 'unknown' };
|
|
@@ -350,6 +361,18 @@ export async function runWorkflowCommand(argv, deps = {}) {
|
|
|
350
361
|
return 0;
|
|
351
362
|
}
|
|
352
363
|
runId = validateId(parsed.positionals[0] ?? '', 'runId');
|
|
364
|
+
if (parsed.command === 'inspect') {
|
|
365
|
+
if (!store.inspect)
|
|
366
|
+
throw new WorkflowCliError('INSPECTION_NOT_SUPPORTED');
|
|
367
|
+
const payload = inspectionPayload(store.inspect(runId));
|
|
368
|
+
if (parsed.json)
|
|
369
|
+
writeJson(stdout, { ok: true, ...payload });
|
|
370
|
+
else {
|
|
371
|
+
writeStatusText(stdout, payload);
|
|
372
|
+
stdout.write(`view=stored_checkpoint action=${String(payload['nextAction'])} gate=${String(payload['approvalGateId'] ?? '-')}\n`);
|
|
373
|
+
}
|
|
374
|
+
return 0;
|
|
375
|
+
}
|
|
353
376
|
if (parsed.command === 'status') {
|
|
354
377
|
const payload = statusPayload(store.read(runId));
|
|
355
378
|
if (parsed.json)
|
|
@@ -378,7 +401,7 @@ export async function runWorkflowCommand(argv, deps = {}) {
|
|
|
378
401
|
catch (error) {
|
|
379
402
|
const code = errorCode(error, parsed.command);
|
|
380
403
|
if (parsed.json)
|
|
381
|
-
writeJson(stdout, { ok: false, command: parsed.command, ...(runId ? { runId } : {}), error: code });
|
|
404
|
+
writeJson(stdout, { ok: false, command: parsed.command, ...(runId && safeString(runId, 128) !== null ? { runId } : {}), error: code });
|
|
382
405
|
else
|
|
383
406
|
stderr.write(`workflow ${parsed.command} failed: ${code}\n`);
|
|
384
407
|
return 1;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@evomap/evolver-cli",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.51",
|
|
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.51",
|
|
31
|
+
"@evomap/evolver-adapter-public": "2.0.51",
|
|
32
|
+
"@evomap/evolver-mcp": "2.0.51",
|
|
33
|
+
"@evomap/evolver-proxy": "2.0.51",
|
|
34
|
+
"@evomap/evolver-runtime-adapters": "2.0.51",
|
|
35
|
+
"@evomap/evolver-webui": "2.0.51"
|
|
36
36
|
},
|
|
37
37
|
"repository": {
|
|
38
38
|
"type": "git",
|