@evomap/evolver-cli 2.0.0-beta.9 → 2.0.1
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/antiGeneBenchmark.js +2 -0
- package/dist/antiGeneRollout.js +9 -3
- package/dist/assetHealth.js +2 -0
- package/dist/assetTrust.js +14 -1
- package/dist/atp.d.ts +10 -5
- package/dist/atp.js +119 -26
- package/dist/atpAutoBuyer.d.ts +120 -0
- package/dist/atpAutoBuyer.js +814 -0
- package/dist/atpAutoDeliver.js +2 -2
- package/dist/autoDistillLlm.js +2 -1
- package/dist/autoDistillTranscript.js +3 -2
- package/dist/autoexec.d.ts +101 -13
- package/dist/autoexec.js +794 -91
- package/dist/cli.js +13 -0
- package/dist/cliContracts.d.ts +23 -2
- package/dist/cliContracts.js +504 -54
- package/dist/commands.d.ts +1 -0
- package/dist/commands.js +1 -0
- package/dist/curriculumCapabilityGaps.d.ts +6 -0
- package/dist/curriculumCapabilityGaps.js +24 -0
- package/dist/cycleConsumer.d.ts +13 -0
- package/dist/cycleConsumer.js +186 -20
- package/dist/dashboard.js +47 -9
- package/dist/dispatch.js +8 -2
- package/dist/distillPrimitives.d.ts +3 -2
- package/dist/distillPrimitives.js +80 -12
- package/dist/doctor.js +120 -11
- package/dist/identityHome.d.ts +9 -0
- package/dist/identityHome.js +47 -0
- package/dist/index.d.ts +70 -40
- package/dist/index.js +581 -193
- package/dist/learningTrace.d.ts +15 -0
- package/dist/learningTrace.js +73 -0
- package/dist/lifecycle.d.ts +67 -1
- package/dist/lifecycle.js +738 -44
- package/dist/localMemoryGraph.d.ts +90 -3
- package/dist/localMemoryGraph.js +2031 -231
- package/dist/login.d.ts +1 -1
- package/dist/login.js +3 -3
- package/dist/materialSnapshot.d.ts +9 -1
- package/dist/materialSnapshot.js +23 -6
- package/dist/memoryGraphOps.d.ts +8 -0
- package/dist/memoryGraphOps.js +140 -0
- package/dist/migrate/assetFormatMap.d.ts +61 -0
- package/dist/migrate/assetFormatMap.js +53 -0
- package/dist/migrate/envTranslate.d.ts +26 -0
- package/dist/migrate/envTranslate.js +147 -0
- package/dist/migrate/fieldMap.d.ts +4 -2
- package/dist/migrate/fieldMap.js +9 -5
- package/dist/migrate/oauthImport.d.ts +66 -0
- package/dist/migrate/oauthImport.js +667 -0
- package/dist/migrate/v1Import.d.ts +92 -1
- package/dist/migrate/v1Import.js +1481 -141
- package/dist/promptRecallHook.d.ts +24 -0
- package/dist/promptRecallHook.js +425 -0
- package/dist/recallVerifyReport.d.ts +37 -0
- package/dist/recallVerifyReport.js +244 -0
- package/dist/recipe.d.ts +7 -1
- package/dist/recipe.js +426 -56
- package/dist/requiredSandboxValidation.d.ts +5 -0
- package/dist/requiredSandboxValidation.js +4 -0
- package/dist/reuse.d.ts +9 -0
- package/dist/reuse.js +151 -56
- package/dist/runtimeCapabilities.js +15 -15
- package/dist/runtimeSessionSource.d.ts +3 -2
- package/dist/runtimeSessionSource.js +63 -11
- package/dist/selectionPolicyConfig.d.ts +8 -0
- package/dist/selectionPolicyConfig.js +18 -0
- package/dist/semanticIdfConfig.d.ts +2 -0
- package/dist/semanticIdfConfig.js +4 -0
- package/dist/sessionIngest.d.ts +37 -0
- package/dist/sessionIngest.js +156 -0
- package/dist/setupHooks.js +95 -1
- package/dist/skill2gep.d.ts +13 -9
- package/dist/skill2gep.js +42 -30
- package/dist/skillDistill.d.ts +8 -4
- package/dist/skillDistill.js +38 -9
- package/dist/solo/mode.js +1 -0
- package/dist/sync.d.ts +12 -0
- package/dist/sync.js +1246 -151
- package/dist/thesis.d.ts +1 -1
- package/dist/thesis.js +20 -3
- package/dist/trajectoryExport.js +21 -3
- package/dist/v1Compat.d.ts +1 -0
- package/dist/v1Compat.js +9 -0
- package/dist/workflowRuntime.js +24 -18
- package/package.json +11 -8
package/dist/recipe.js
CHANGED
|
@@ -1,16 +1,26 @@
|
|
|
1
|
-
import { existsSync, mkdirSync, readFileSync, unlinkSync, writeFileSync } from 'node:fs';
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, realpathSync, statSync, unlinkSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { createHash } from 'node:crypto';
|
|
2
3
|
import { homedir } from 'node:os';
|
|
3
|
-
import { dirname, isAbsolute, join, resolve } from 'node:path';
|
|
4
|
-
import { assetstore, events, mailbox } from '@evomap/evolver-core';
|
|
4
|
+
import { dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
|
|
5
|
+
import { assetstore, events, mailbox, verify } from '@evomap/evolver-core';
|
|
5
6
|
import { AuthError, HubClientError, HubUnreachableError, connectPublicHub, isHubDryRunEnabled, isNodeSecret, parseNodeSecretVersion, resolveHubUrl } from '@evomap/evolver-adapter-public';
|
|
6
7
|
import { loadEnvFileFromEnv } from '@evomap/evolver-mcp';
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
8
|
+
import { resolveExplicitNodeCredentials } from './identityHome.js';
|
|
9
|
+
import { getCliVersion } from './version.js';
|
|
10
|
+
import { parseSkillMd, reverseDistill, synthesizeGene } from './skill2gep.js';
|
|
9
11
|
import { recordSkillDistillation } from './skillDistill.js';
|
|
12
|
+
import { buildPublishBundle } from './cliContracts.js';
|
|
10
13
|
const MAX_RECIPE_STEPS = 20;
|
|
14
|
+
const MAX_RECIPE_VALIDATION_COMMANDS = 5;
|
|
15
|
+
const MAX_RECIPE_INPUT_BYTES = 1024 * 1024;
|
|
11
16
|
const MAX_ID_LENGTH = 200;
|
|
12
17
|
const SENSITIVE_ERROR_KEYS = new Set(['authorization', 'node_secret', 'nodesecret', 'token', 'access_token', 'refresh_token', 'secret']);
|
|
13
18
|
const STALE_NODE_SECRET_ERRORS = new Set(['node_secret_invalid', 'node_secret_not_set']);
|
|
19
|
+
function recipeIdempotencyKey(operation, value) {
|
|
20
|
+
const digest = createHash('sha256').update(JSON.stringify(value)).digest('hex');
|
|
21
|
+
return `evolver-recipe-${operation}-${digest}`;
|
|
22
|
+
}
|
|
23
|
+
const recipeIdentityBootstraps = new WeakMap();
|
|
14
24
|
export async function runRecipeCommand(argv, deps = {}) {
|
|
15
25
|
const parsed = parseRecipeArgs(argv);
|
|
16
26
|
const err = deps.err ?? ((line) => { process.stderr.write(`${line}\n`); });
|
|
@@ -21,6 +31,7 @@ export async function runRecipeCommand(argv, deps = {}) {
|
|
|
21
31
|
}
|
|
22
32
|
try {
|
|
23
33
|
const env = deps.env ?? process.env;
|
|
34
|
+
loadEnvFileFromEnv(env);
|
|
24
35
|
if (isHubDryRunEnabled(env)) {
|
|
25
36
|
if (parsed.value.sub === 'build')
|
|
26
37
|
return await runRecipeBuildDryRun(parsed.value, deps.store, { log, err });
|
|
@@ -29,6 +40,7 @@ export async function runRecipeCommand(argv, deps = {}) {
|
|
|
29
40
|
return runRecipeReuseDryRun(parsed.value, { log });
|
|
30
41
|
}
|
|
31
42
|
const hub = deps.hub ?? createRecipeHubFromEnv(env, deps.connectHub ?? connectPublicHub);
|
|
43
|
+
await recipeIdentityBootstraps.get(hub)?.();
|
|
32
44
|
if (!hub.recipes) {
|
|
33
45
|
err('recipe capability is not available for the configured Hub adapter');
|
|
34
46
|
return 1;
|
|
@@ -82,6 +94,7 @@ export function createRecipeHubFromEnv(env = process.env, connectHub = connectPu
|
|
|
82
94
|
if (!credentials.nodeSecret && !credentials.senderId) {
|
|
83
95
|
throw new Error('recipe OAuth mode requires a node identity: register a node first, set EVOMAP_NODE_ID or A2A_NODE_ID, or ensure the Evolver proxy store contains node_id');
|
|
84
96
|
}
|
|
97
|
+
let senderId = credentials.senderId;
|
|
85
98
|
const connected = credentials.nodeSecret
|
|
86
99
|
? connectHub({
|
|
87
100
|
hubUrl,
|
|
@@ -89,13 +102,52 @@ export function createRecipeHubFromEnv(env = process.env, connectHub = connectPu
|
|
|
89
102
|
evomapDir: credentials.evomapDir,
|
|
90
103
|
nodeSecret: credentials.nodeSecret,
|
|
91
104
|
...(credentials.nodeSecretVersion !== undefined ? { nodeSecretVersion: credentials.nodeSecretVersion } : {}),
|
|
92
|
-
senderId: () =>
|
|
93
|
-
onNodeSecretRotated: (secret, version) => persistRotatedNodeSecret(secret, version, env, credentials.rotatePersistDir),
|
|
105
|
+
senderId: () => senderId,
|
|
106
|
+
onNodeSecretRotated: (secret, version) => persistRotatedNodeSecret(secret, version, senderId, env, credentials.rotatePersistDir),
|
|
94
107
|
onNodeSecretVersionUpdated: (version) => persistNodeSecretVersion(version, env, credentials.rotatePersistDir),
|
|
95
108
|
})
|
|
96
|
-
: connectHub({ hubUrl, authMode: 'oauth', evomapDir: credentials.evomapDir, senderId: () =>
|
|
109
|
+
: connectHub({ hubUrl, authMode: 'oauth', evomapDir: credentials.evomapDir, senderId: () => senderId });
|
|
110
|
+
if (credentials.nodeSecret && !senderId) {
|
|
111
|
+
recipeIdentityBootstraps.set(connected.hub, async () => {
|
|
112
|
+
const hello = await connected.hub.hello({
|
|
113
|
+
rotate: false,
|
|
114
|
+
evolverVersion: getCliVersion(),
|
|
115
|
+
preserveCredentials: true,
|
|
116
|
+
});
|
|
117
|
+
if (!hello.ok || !hello.nodeId) {
|
|
118
|
+
throw new Error(`recipe could not establish Hub node identity: ${hello.error ?? 'node_id_missing'}`);
|
|
119
|
+
}
|
|
120
|
+
senderId = hello.nodeId;
|
|
121
|
+
persistRecipeNodeId(senderId, env, credentials.rotatePersistDir);
|
|
122
|
+
recipeIdentityBootstraps.delete(connected.hub);
|
|
123
|
+
});
|
|
124
|
+
}
|
|
97
125
|
return connected.hub;
|
|
98
126
|
}
|
|
127
|
+
/** Opaque identity for resume isolation; raw credentials, account ids, and local paths never leave this helper. */
|
|
128
|
+
export function resolveRecipeHubResumeIdentityFingerprint(env) {
|
|
129
|
+
loadEnvFileFromEnv(env);
|
|
130
|
+
const credentials = resolveRecipeHubCredentials(env);
|
|
131
|
+
let credential;
|
|
132
|
+
if (credentials.nodeSecret) {
|
|
133
|
+
credential = credentials.nodeSecret;
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
try {
|
|
137
|
+
credential = createHash('sha256')
|
|
138
|
+
.update(readFileSync(join(credentials.evomapDir, 'token.json'), 'utf8'))
|
|
139
|
+
.digest('hex');
|
|
140
|
+
}
|
|
141
|
+
catch {
|
|
142
|
+
throw new Error('Hub resume identity credentials are unavailable');
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return createHash('sha256').update(JSON.stringify({
|
|
146
|
+
authMode: credentials.nodeSecret ? 'legacy' : 'oauth',
|
|
147
|
+
senderId: credentials.senderId ?? '',
|
|
148
|
+
credential,
|
|
149
|
+
})).digest('hex');
|
|
150
|
+
}
|
|
99
151
|
function resolveRecipeHubUrl(env) {
|
|
100
152
|
return resolveHubUrl(env);
|
|
101
153
|
}
|
|
@@ -116,20 +168,32 @@ async function runRecipeBuild(opts, hub, store, io) {
|
|
|
116
168
|
io.err('recipe build requires at least one asset id');
|
|
117
169
|
return 1;
|
|
118
170
|
}
|
|
119
|
-
const
|
|
171
|
+
const createRequest = {
|
|
120
172
|
title: opts.title,
|
|
121
173
|
steps,
|
|
122
174
|
...(opts.description ? { description: opts.description } : {}),
|
|
123
175
|
...(opts.pricePerExecution !== undefined ? { pricePerExecution: opts.pricePerExecution } : {}),
|
|
124
|
-
}
|
|
176
|
+
};
|
|
177
|
+
createRequest.idempotencyKey = recipeIdempotencyKey('create', createRequest);
|
|
178
|
+
const createReceipt = await callRecipeWithAuthRetry(hub, 'recipe build', () => hub.recipes.create(createRequest), io);
|
|
125
179
|
const recipeId = createReceipt.recipeId;
|
|
180
|
+
if (createReceipt.status !== 'draft') {
|
|
181
|
+
io.err(`[recipe build] Hub returned unexpected create status: ${createReceipt.status ?? 'unknown'}.`);
|
|
182
|
+
return 1;
|
|
183
|
+
}
|
|
126
184
|
io.log(`[recipe build] Created DRAFT recipe ${recipeId ?? '(id pending)'} ("${opts.title}", ${steps.length} step${steps.length === 1 ? '' : 's'}).`);
|
|
127
185
|
if (opts.publish) {
|
|
128
186
|
if (!recipeId) {
|
|
129
187
|
io.err('[recipe build] Hub did not return a recipe id; cannot publish.');
|
|
130
188
|
return 1;
|
|
131
189
|
}
|
|
132
|
-
await callRecipeWithAuthRetry(hub, 'recipe build', () => hub.recipes.publish(recipeId
|
|
190
|
+
const publishReceipt = await callRecipeWithAuthRetry(hub, 'recipe build', () => hub.recipes.publish(recipeId, {
|
|
191
|
+
idempotencyKey: recipeIdempotencyKey('publish', recipeId),
|
|
192
|
+
}), io);
|
|
193
|
+
if (publishReceipt.status !== 'published') {
|
|
194
|
+
io.err(`[recipe build] Hub returned unexpected publish status: ${publishReceipt.status ?? 'unknown'}.`);
|
|
195
|
+
return 1;
|
|
196
|
+
}
|
|
133
197
|
io.log(`[recipe build] Published recipe ${recipeId}.`);
|
|
134
198
|
}
|
|
135
199
|
else {
|
|
@@ -143,7 +207,12 @@ async function runRecipeFromSkills(opts, hub, deps, io, dryRun) {
|
|
|
143
207
|
io.err(loaded.error);
|
|
144
208
|
return 1;
|
|
145
209
|
}
|
|
146
|
-
const
|
|
210
|
+
const verified = await verifyRecipeFromSkillsSteps(loaded.value.steps, deps.runValidation ?? verify.runSandboxedValidation);
|
|
211
|
+
if (!verified.ok) {
|
|
212
|
+
io.err(verified.error);
|
|
213
|
+
return 1;
|
|
214
|
+
}
|
|
215
|
+
const preflight = preflightRecipeFromSkillsSteps(verified.value);
|
|
147
216
|
if (!preflight.ok) {
|
|
148
217
|
io.err(preflight.error);
|
|
149
218
|
return 1;
|
|
@@ -163,7 +232,12 @@ async function runRecipeFromSkills(opts, hub, deps, io, dryRun) {
|
|
|
163
232
|
store,
|
|
164
233
|
...(deps.review ? { review: deps.review } : {}),
|
|
165
234
|
ingestor,
|
|
166
|
-
},
|
|
235
|
+
}, {
|
|
236
|
+
evidenceMode: 'validation_only',
|
|
237
|
+
geneIdentity: 'semantic',
|
|
238
|
+
completeValidationPlan: true,
|
|
239
|
+
...(step.scenario ? { scenario: step.scenario } : {}),
|
|
240
|
+
});
|
|
167
241
|
if (!res.geneId || !res.geneAssetId) {
|
|
168
242
|
const recovered = await findReusableRecipeStep(store, prepared);
|
|
169
243
|
if (recovered) {
|
|
@@ -188,6 +262,13 @@ async function runRecipeFromSkills(opts, hub, deps, io, dryRun) {
|
|
|
188
262
|
capsuleId: res.capsuleId,
|
|
189
263
|
});
|
|
190
264
|
}
|
|
265
|
+
const publishPrepared = await prepareRecipeFromSkillsAssets(distilled, store, dryRun ? undefined : hub, deps.env ?? process.env, io);
|
|
266
|
+
if (!publishPrepared.ok) {
|
|
267
|
+
io.err(publishPrepared.error);
|
|
268
|
+
return 1;
|
|
269
|
+
}
|
|
270
|
+
steps.splice(0, steps.length, ...publishPrepared.value.steps);
|
|
271
|
+
distilled.splice(0, distilled.length, ...publishPrepared.value.distilled);
|
|
191
272
|
if (dryRun) {
|
|
192
273
|
const payload = recipeFromSkillsPayload({
|
|
193
274
|
mode: 'dry_run',
|
|
@@ -210,13 +291,32 @@ async function runRecipeFromSkills(opts, hub, deps, io, dryRun) {
|
|
|
210
291
|
io.err('recipe capability is not available for the configured Hub adapter');
|
|
211
292
|
return 1;
|
|
212
293
|
}
|
|
213
|
-
const
|
|
294
|
+
const createRequest = {
|
|
214
295
|
title: loaded.value.title,
|
|
215
296
|
steps,
|
|
216
297
|
...(loaded.value.description ? { description: loaded.value.description } : {}),
|
|
217
298
|
...(loaded.value.pricePerExecution !== undefined ? { pricePerExecution: loaded.value.pricePerExecution } : {}),
|
|
218
|
-
}
|
|
299
|
+
};
|
|
300
|
+
createRequest.idempotencyKey = recipeIdempotencyKey('create', createRequest);
|
|
301
|
+
const createReceipt = await callRecipeWithAuthRetry(hub, 'recipe from-skills', () => hub.recipes.create(createRequest), io);
|
|
219
302
|
const recipeId = createReceipt.recipeId;
|
|
303
|
+
if (createReceipt.status !== 'draft') {
|
|
304
|
+
if (opts.jsonOut) {
|
|
305
|
+
io.log(JSON.stringify(recipeFromSkillsPayload({
|
|
306
|
+
ok: false,
|
|
307
|
+
mode: 'failed',
|
|
308
|
+
title: loaded.value.title,
|
|
309
|
+
publish: opts.publish,
|
|
310
|
+
steps: distilled,
|
|
311
|
+
recipeId,
|
|
312
|
+
error: 'create_failed',
|
|
313
|
+
}), null, 2));
|
|
314
|
+
}
|
|
315
|
+
else {
|
|
316
|
+
io.err(`[recipe from-skills] Hub did not confirm draft creation for recipe ${recipeId ?? '(id missing)'} (status: ${createReceipt.status ?? 'missing'}).`);
|
|
317
|
+
}
|
|
318
|
+
return 1;
|
|
319
|
+
}
|
|
220
320
|
if (!opts.jsonOut) {
|
|
221
321
|
io.log(`[recipe from-skills] Created DRAFT recipe ${recipeId ?? '(id pending)'} ("${loaded.value.title}", ${steps.length} step${steps.length === 1 ? '' : 's'}).`);
|
|
222
322
|
}
|
|
@@ -226,7 +326,26 @@ async function runRecipeFromSkills(opts, hub, deps, io, dryRun) {
|
|
|
226
326
|
return 1;
|
|
227
327
|
}
|
|
228
328
|
try {
|
|
229
|
-
await callRecipeWithAuthRetry(hub, 'recipe from-skills', () => hub.recipes.publish(recipeId
|
|
329
|
+
const publishReceipt = await callRecipeWithAuthRetry(hub, 'recipe from-skills', () => hub.recipes.publish(recipeId, {
|
|
330
|
+
idempotencyKey: recipeIdempotencyKey('publish', recipeId),
|
|
331
|
+
}), io);
|
|
332
|
+
if (publishReceipt.status !== 'published') {
|
|
333
|
+
if (opts.jsonOut) {
|
|
334
|
+
io.log(JSON.stringify(recipeFromSkillsPayload({
|
|
335
|
+
ok: false,
|
|
336
|
+
mode: 'draft',
|
|
337
|
+
title: loaded.value.title,
|
|
338
|
+
publish: opts.publish,
|
|
339
|
+
steps: distilled,
|
|
340
|
+
recipeId,
|
|
341
|
+
error: 'publish_failed',
|
|
342
|
+
}), null, 2));
|
|
343
|
+
}
|
|
344
|
+
else {
|
|
345
|
+
io.err(`[recipe from-skills] Created DRAFT recipe ${recipeId}; Hub did not confirm publish (status: ${publishReceipt.status ?? 'missing'}).`);
|
|
346
|
+
}
|
|
347
|
+
return 1;
|
|
348
|
+
}
|
|
230
349
|
}
|
|
231
350
|
catch (e) {
|
|
232
351
|
if (opts.jsonOut) {
|
|
@@ -284,12 +403,96 @@ async function recipeStepsFromLocalAssets(assetIds, store) {
|
|
|
284
403
|
return { assetId, assetType, position: index };
|
|
285
404
|
});
|
|
286
405
|
}
|
|
406
|
+
async function verifyRecipeFromSkillsSteps(steps, runValidation) {
|
|
407
|
+
const verified = [];
|
|
408
|
+
for (let i = 0; i < steps.length; i += 1) {
|
|
409
|
+
const step = steps[i];
|
|
410
|
+
const parsed = parseSkillMd(step.skill, { completeValidationPlan: true });
|
|
411
|
+
if (parsed.validation.length > MAX_RECIPE_VALIDATION_COMMANDS) {
|
|
412
|
+
return {
|
|
413
|
+
ok: false,
|
|
414
|
+
error: `recipe from-skills step ${i + 1} supports at most ${MAX_RECIPE_VALIDATION_COMMANDS} validation commands`,
|
|
415
|
+
};
|
|
416
|
+
}
|
|
417
|
+
const synthesized = synthesizeGene(parsed, step.execution, { strict: true });
|
|
418
|
+
if (!synthesized.gene) {
|
|
419
|
+
return {
|
|
420
|
+
ok: false,
|
|
421
|
+
error: `recipe from-skills step ${i + 1} did not produce a Gene: ${synthesized.errors.join('; ') || 'refused'}`,
|
|
422
|
+
};
|
|
423
|
+
}
|
|
424
|
+
if (!recipeValidationPlanIsComplete(parsed.validation, synthesized.gene.validation)) {
|
|
425
|
+
return {
|
|
426
|
+
ok: false,
|
|
427
|
+
error: `recipe from-skills step ${i + 1} contains unsupported validation commands; every declared command must be allowed`,
|
|
428
|
+
};
|
|
429
|
+
}
|
|
430
|
+
const startedAt = new Date().toISOString();
|
|
431
|
+
let validation;
|
|
432
|
+
try {
|
|
433
|
+
validation = await runValidation(synthesized.gene.validation ?? [], step.validationCwd, {
|
|
434
|
+
requireIsolation: true,
|
|
435
|
+
readOnlyRoot: step.validationRoot,
|
|
436
|
+
});
|
|
437
|
+
}
|
|
438
|
+
catch {
|
|
439
|
+
return { ok: false, error: `recipe from-skills step ${i + 1} validation execution failed` };
|
|
440
|
+
}
|
|
441
|
+
if (!validation.isolated) {
|
|
442
|
+
return {
|
|
443
|
+
ok: false,
|
|
444
|
+
error: `recipe from-skills step ${i + 1} requires Linux namespace isolation and cgroup v2 resource limits`,
|
|
445
|
+
};
|
|
446
|
+
}
|
|
447
|
+
if (validation.skipped.length > 0) {
|
|
448
|
+
const skipped = validation.skipped.map((item) => item.script).join(', ');
|
|
449
|
+
return { ok: false, error: `recipe from-skills step ${i + 1} validation incomplete: missing ${skipped}` };
|
|
450
|
+
}
|
|
451
|
+
if (!validation.passed) {
|
|
452
|
+
return { ok: false, error: `recipe from-skills step ${i + 1} validation failed` };
|
|
453
|
+
}
|
|
454
|
+
const execution = {
|
|
455
|
+
...(Array.isArray(step.execution.signals)
|
|
456
|
+
? { signals: step.execution.signals.map((value) => String(value)).filter(Boolean) }
|
|
457
|
+
: {}),
|
|
458
|
+
...(Array.isArray(step.execution.trigger)
|
|
459
|
+
? { trigger: step.execution.trigger.map((value) => String(value)).filter(Boolean) }
|
|
460
|
+
: {}),
|
|
461
|
+
...(typeof step.execution.summary === 'string' && step.execution.summary.trim()
|
|
462
|
+
? { summary: step.execution.summary.trim() }
|
|
463
|
+
: {}),
|
|
464
|
+
status: 'success',
|
|
465
|
+
score: validation.score,
|
|
466
|
+
started_at: startedAt,
|
|
467
|
+
blast_radius: { files: 0, lines: 0 },
|
|
468
|
+
reference_distilled: true,
|
|
469
|
+
success_reason: 'All declared validation commands passed in the local verifier.',
|
|
470
|
+
trace: validation.results.map((result, index) => ({
|
|
471
|
+
step: index + 1,
|
|
472
|
+
cmd: result.cmd,
|
|
473
|
+
exit: result.exitCode ?? undefined,
|
|
474
|
+
stdout_tail: '',
|
|
475
|
+
})),
|
|
476
|
+
};
|
|
477
|
+
verified.push({ ...step, execution });
|
|
478
|
+
}
|
|
479
|
+
return { ok: true, value: verified };
|
|
480
|
+
}
|
|
481
|
+
function recipeValidationPlanIsComplete(declared, runnable) {
|
|
482
|
+
const declaredCommands = normalizedStringList(declared);
|
|
483
|
+
const runnableCommands = normalizedStringList(runnable);
|
|
484
|
+
return declaredCommands.length === runnableCommands.length &&
|
|
485
|
+
declaredCommands.every((command, index) => command === runnableCommands[index]);
|
|
486
|
+
}
|
|
287
487
|
function preflightRecipeFromSkillsSteps(steps) {
|
|
288
488
|
const prepared = [];
|
|
289
489
|
for (let i = 0; i < steps.length; i += 1) {
|
|
290
490
|
const step = steps[i];
|
|
291
|
-
const parsed = parseSkillMd(step.skill);
|
|
292
|
-
const preview = reverseDistill(parsed, step.execution,
|
|
491
|
+
const parsed = parseSkillMd(step.skill, { completeValidationPlan: true });
|
|
492
|
+
const preview = reverseDistill(parsed, step.execution, {
|
|
493
|
+
evidenceMode: 'validation_only',
|
|
494
|
+
...(step.scenario ? { scenario: step.scenario } : {}),
|
|
495
|
+
});
|
|
293
496
|
if (!preview.gene) {
|
|
294
497
|
return {
|
|
295
498
|
ok: false,
|
|
@@ -309,11 +512,74 @@ function preflightRecipeFromSkillsSteps(steps) {
|
|
|
309
512
|
position: i,
|
|
310
513
|
step,
|
|
311
514
|
candidateSignals: normalizedSignalList(preview.gene.signals_match),
|
|
312
|
-
|
|
515
|
+
candidateValidations: Array.isArray(preview.gene.validation) ? [...preview.gene.validation] : [],
|
|
516
|
+
candidateDefinition: reusableGeneDefinition(preview.gene),
|
|
313
517
|
});
|
|
314
518
|
}
|
|
315
519
|
return { ok: true, value: prepared };
|
|
316
520
|
}
|
|
521
|
+
async function prepareRecipeFromSkillsAssets(distilled, store, hub, env, io) {
|
|
522
|
+
const steps = [];
|
|
523
|
+
const prepared = [];
|
|
524
|
+
const publishedByBundle = new Map();
|
|
525
|
+
for (const step of distilled) {
|
|
526
|
+
const bundle = await buildPublishBundle([step.geneAssetId, step.capsuleId], { assetStore: store, env });
|
|
527
|
+
if (!bundle.ok) {
|
|
528
|
+
return { ok: false, error: `recipe from-skills step ${step.position + 1} asset bundle rejected: ${bundle.reason}` };
|
|
529
|
+
}
|
|
530
|
+
if (bundle.blockReasons.length > 0) {
|
|
531
|
+
return { ok: false, error: `recipe from-skills step ${step.position + 1} asset bundle rejected: ${bundle.blockReasons.join(',')}` };
|
|
532
|
+
}
|
|
533
|
+
const gene = bundle.sanitized.find((asset) => asset.type === 'Gene');
|
|
534
|
+
const capsule = bundle.sanitized.find((asset) => asset.type === 'Capsule');
|
|
535
|
+
if (!gene?.asset_id || !capsule?.asset_id) {
|
|
536
|
+
return { ok: false, error: `recipe from-skills step ${step.position + 1} asset bundle is missing Gene or Capsule` };
|
|
537
|
+
}
|
|
538
|
+
const bundleKey = `${gene.asset_id}\n${capsule.asset_id}`;
|
|
539
|
+
let geneAssetId = publishedByBundle.get(bundleKey);
|
|
540
|
+
if (!geneAssetId && hub) {
|
|
541
|
+
const receipt = await callRecipeWithAuthRetry(hub, 'recipe from-skills asset publish', () => hub.publish(bundle.sanitized), io);
|
|
542
|
+
if (!assetPublishSucceeded(receipt, bundle.sanitized)) {
|
|
543
|
+
const duplicateIsIncomplete = receipt.status === 'rejected' &&
|
|
544
|
+
(receipt.reason === 'already_published' || receipt.reason === 'duplicate');
|
|
545
|
+
return {
|
|
546
|
+
ok: false,
|
|
547
|
+
error: duplicateIsIncomplete
|
|
548
|
+
? `recipe from-skills step ${step.position + 1} duplicate asset publish did not identify the published Gene and Capsule bundle`
|
|
549
|
+
: `recipe from-skills step ${step.position + 1} asset publish rejected: ${receipt.reason ?? receipt.status}`,
|
|
550
|
+
};
|
|
551
|
+
}
|
|
552
|
+
geneAssetId = publishedGeneAssetId(receipt, gene.asset_id);
|
|
553
|
+
if (!geneAssetId) {
|
|
554
|
+
return {
|
|
555
|
+
ok: false,
|
|
556
|
+
error: `recipe from-skills step ${step.position + 1} duplicate asset publish did not identify the published Gene`,
|
|
557
|
+
};
|
|
558
|
+
}
|
|
559
|
+
publishedByBundle.set(bundleKey, geneAssetId);
|
|
560
|
+
}
|
|
561
|
+
geneAssetId ??= gene.asset_id;
|
|
562
|
+
steps.push({ assetId: geneAssetId, assetType: 'Gene', position: step.position });
|
|
563
|
+
prepared.push({ ...step, geneAssetId });
|
|
564
|
+
}
|
|
565
|
+
return { ok: true, value: { steps, distilled: prepared } };
|
|
566
|
+
}
|
|
567
|
+
function assetPublishSucceeded(receipt, submitted) {
|
|
568
|
+
if (receipt.status === 'accepted')
|
|
569
|
+
return true;
|
|
570
|
+
if (receipt.status !== 'rejected' ||
|
|
571
|
+
(receipt.reason !== 'already_published' && receipt.reason !== 'duplicate'))
|
|
572
|
+
return false;
|
|
573
|
+
const published = new Set(receipt.assetIds ?? []);
|
|
574
|
+
return submitted.every((asset) => typeof asset.asset_id === 'string' && published.has(asset.asset_id));
|
|
575
|
+
}
|
|
576
|
+
function publishedGeneAssetId(receipt, localAssetId) {
|
|
577
|
+
if (receipt.status === 'accepted')
|
|
578
|
+
return localAssetId;
|
|
579
|
+
if (receipt.assetId === localAssetId || receipt.assetIds?.includes(localAssetId))
|
|
580
|
+
return localAssetId;
|
|
581
|
+
return undefined;
|
|
582
|
+
}
|
|
317
583
|
async function findReusableRecipeStep(store, prepared) {
|
|
318
584
|
const candidateSignals = prepared.candidateSignals;
|
|
319
585
|
if (candidateSignals.length === 0)
|
|
@@ -321,8 +587,11 @@ async function findReusableRecipeStep(store, prepared) {
|
|
|
321
587
|
const genes = await store.list('Gene', 10_000);
|
|
322
588
|
const capsules = await store.list('Capsule', 10_000);
|
|
323
589
|
for (const gene of genes) {
|
|
324
|
-
const signals =
|
|
325
|
-
if (
|
|
590
|
+
const signals = normalizedSignalList(gene['signals_match']);
|
|
591
|
+
if (signals.length !== candidateSignals.length ||
|
|
592
|
+
!candidateSignals.every((signal, index) => signal === signals[index]))
|
|
593
|
+
continue;
|
|
594
|
+
if (reusableGeneDefinition(gene) !== prepared.candidateDefinition)
|
|
326
595
|
continue;
|
|
327
596
|
const geneId = typeof gene['id'] === 'string' && gene['id'].trim()
|
|
328
597
|
? gene['id'].trim()
|
|
@@ -330,8 +599,8 @@ async function findReusableRecipeStep(store, prepared) {
|
|
|
330
599
|
const geneAssetId = typeof gene['asset_id'] === 'string' ? gene['asset_id'] : '';
|
|
331
600
|
if (!geneId || !geneAssetId)
|
|
332
601
|
continue;
|
|
333
|
-
const capsule = capsules.find((record) => String(record['
|
|
334
|
-
|
|
602
|
+
const capsule = capsules.find((record) => String(record['gene']) === geneId &&
|
|
603
|
+
capsuleProvesValidations(record, prepared.candidateValidations));
|
|
335
604
|
if (!capsule)
|
|
336
605
|
continue;
|
|
337
606
|
return {
|
|
@@ -343,6 +612,41 @@ async function findReusableRecipeStep(store, prepared) {
|
|
|
343
612
|
}
|
|
344
613
|
return null;
|
|
345
614
|
}
|
|
615
|
+
function capsuleProvesValidations(capsule, validations) {
|
|
616
|
+
if (capsule['source_type'] !== 'skill2gep_validation')
|
|
617
|
+
return false;
|
|
618
|
+
const outcome = isPlainRecord(capsule['outcome']) ? capsule['outcome'] : null;
|
|
619
|
+
if (outcome?.['status'] !== 'success')
|
|
620
|
+
return false;
|
|
621
|
+
const trace = Array.isArray(capsule['execution_trace']) ? capsule['execution_trace'] : [];
|
|
622
|
+
return validations.every((validation) => trace.some((entry) => {
|
|
623
|
+
if (!isPlainRecord(entry))
|
|
624
|
+
return false;
|
|
625
|
+
return normalizeValidationCommand(entry['cmd']) === normalizeValidationCommand(validation) && entry['exit'] === 0;
|
|
626
|
+
}));
|
|
627
|
+
}
|
|
628
|
+
function normalizeValidationCommand(value) {
|
|
629
|
+
return String(value ?? '').replace(/\s+/g, ' ').trim();
|
|
630
|
+
}
|
|
631
|
+
function reusableGeneDefinition(gene) {
|
|
632
|
+
const constraints = isPlainRecord(gene['constraints']) ? gene['constraints'] : {};
|
|
633
|
+
return JSON.stringify({
|
|
634
|
+
category: String(gene['category'] ?? ''),
|
|
635
|
+
strategy: normalizedStringList(gene['strategy']),
|
|
636
|
+
summary: String(gene['summary'] ?? ''),
|
|
637
|
+
preconditions: normalizedStringList(gene['preconditions']),
|
|
638
|
+
constraints: {
|
|
639
|
+
maxFiles: Number(constraints['max_files'] ?? 0),
|
|
640
|
+
forbiddenPaths: normalizedStringList(constraints['forbidden_paths']),
|
|
641
|
+
},
|
|
642
|
+
validation: normalizedStringList(gene['validation']).map(normalizeValidationCommand),
|
|
643
|
+
});
|
|
644
|
+
}
|
|
645
|
+
function normalizedStringList(value) {
|
|
646
|
+
return Array.isArray(value)
|
|
647
|
+
? value.map((item) => String(item).trim()).filter(Boolean)
|
|
648
|
+
: [];
|
|
649
|
+
}
|
|
346
650
|
function addRecipeFromSkillsStep(steps, distilled, result) {
|
|
347
651
|
steps.push({ assetId: result.geneAssetId, assetType: 'Gene', position: result.position });
|
|
348
652
|
distilled.push(result);
|
|
@@ -354,14 +658,14 @@ async function hasCapsuleEvidence(store, capsuleId, geneId) {
|
|
|
354
658
|
}
|
|
355
659
|
function normalizedSignalList(value) {
|
|
356
660
|
return Array.isArray(value)
|
|
357
|
-
? value.map((item) => String(item).trim().toLowerCase()).filter(Boolean)
|
|
661
|
+
? value.map((item) => String(item).trim().toLowerCase()).filter(Boolean).sort()
|
|
358
662
|
: [];
|
|
359
663
|
}
|
|
360
664
|
function loadRecipeFromSkillsManifest(path) {
|
|
361
665
|
let raw;
|
|
362
666
|
const manifestPath = resolve(path);
|
|
363
667
|
try {
|
|
364
|
-
raw =
|
|
668
|
+
raw = readRecipeInputFile(manifestPath);
|
|
365
669
|
}
|
|
366
670
|
catch {
|
|
367
671
|
return { ok: false, error: 'recipe from-skills cannot read --manifest file' };
|
|
@@ -390,6 +694,13 @@ function loadRecipeFromSkillsManifest(path) {
|
|
|
390
694
|
if (price !== undefined && (!Number.isFinite(price) || price < 0))
|
|
391
695
|
return { ok: false, error: 'recipe from-skills pricePerExecution must be a non-negative number' };
|
|
392
696
|
const baseDir = dirname(manifestPath);
|
|
697
|
+
let validationRoot;
|
|
698
|
+
try {
|
|
699
|
+
validationRoot = realpathSync(baseDir);
|
|
700
|
+
}
|
|
701
|
+
catch {
|
|
702
|
+
return { ok: false, error: 'recipe from-skills cannot resolve the manifest directory' };
|
|
703
|
+
}
|
|
393
704
|
const steps = [];
|
|
394
705
|
for (let i = 0; i < rawSteps.length; i += 1) {
|
|
395
706
|
const rawStep = rawSteps[i];
|
|
@@ -398,14 +709,24 @@ function loadRecipeFromSkillsManifest(path) {
|
|
|
398
709
|
const skillRef = typeof rawStep['skill'] === 'string' ? rawStep['skill'].trim() : '';
|
|
399
710
|
if (!skillRef)
|
|
400
711
|
return { ok: false, error: `recipe from-skills step ${i + 1} requires skill` };
|
|
712
|
+
let skillPath;
|
|
713
|
+
try {
|
|
714
|
+
skillPath = realpathSync(resolveManifestRef(baseDir, skillRef));
|
|
715
|
+
}
|
|
716
|
+
catch {
|
|
717
|
+
return { ok: false, error: `recipe from-skills step ${i + 1} cannot read skill` };
|
|
718
|
+
}
|
|
719
|
+
if (!pathIsWithin(validationRoot, skillPath)) {
|
|
720
|
+
return { ok: false, error: `recipe from-skills step ${i + 1} skill must stay within the manifest directory` };
|
|
721
|
+
}
|
|
401
722
|
let skill;
|
|
402
723
|
try {
|
|
403
|
-
skill =
|
|
724
|
+
skill = readRecipeInputFile(skillPath);
|
|
404
725
|
}
|
|
405
726
|
catch {
|
|
406
727
|
return { ok: false, error: `recipe from-skills step ${i + 1} cannot read skill` };
|
|
407
728
|
}
|
|
408
|
-
const execution = loadSkillExecution(rawStep['execution'], baseDir, i + 1);
|
|
729
|
+
const execution = loadSkillExecution(rawStep['execution'], baseDir, validationRoot, i + 1);
|
|
409
730
|
if (!execution.ok)
|
|
410
731
|
return execution;
|
|
411
732
|
const scenario = typeof rawStep['scenario'] === 'string' && rawStep['scenario'].trim()
|
|
@@ -414,6 +735,8 @@ function loadRecipeFromSkillsManifest(path) {
|
|
|
414
735
|
steps.push({
|
|
415
736
|
skill,
|
|
416
737
|
execution: execution.value,
|
|
738
|
+
validationCwd: dirname(skillPath),
|
|
739
|
+
validationRoot,
|
|
417
740
|
...(scenario ? { scenario } : {}),
|
|
418
741
|
});
|
|
419
742
|
}
|
|
@@ -430,11 +753,25 @@ function loadRecipeFromSkillsManifest(path) {
|
|
|
430
753
|
},
|
|
431
754
|
};
|
|
432
755
|
}
|
|
433
|
-
function
|
|
756
|
+
function pathIsWithin(root, target) {
|
|
757
|
+
const rel = relative(root, target);
|
|
758
|
+
return rel === '' || (rel !== '..' && !rel.startsWith(`..${sep}`) && !isAbsolute(rel));
|
|
759
|
+
}
|
|
760
|
+
function loadSkillExecution(raw, baseDir, validationRoot, stepNumber) {
|
|
434
761
|
if (typeof raw === 'string' && raw.trim()) {
|
|
762
|
+
let executionPath;
|
|
763
|
+
try {
|
|
764
|
+
executionPath = realpathSync(resolveManifestRef(baseDir, raw.trim()));
|
|
765
|
+
}
|
|
766
|
+
catch {
|
|
767
|
+
return { ok: false, error: `recipe from-skills step ${stepNumber} cannot read execution` };
|
|
768
|
+
}
|
|
769
|
+
if (!pathIsWithin(validationRoot, executionPath)) {
|
|
770
|
+
return { ok: false, error: `recipe from-skills step ${stepNumber} execution must stay within the manifest directory` };
|
|
771
|
+
}
|
|
435
772
|
let text;
|
|
436
773
|
try {
|
|
437
|
-
text =
|
|
774
|
+
text = readRecipeInputFile(executionPath);
|
|
438
775
|
}
|
|
439
776
|
catch {
|
|
440
777
|
return { ok: false, error: `recipe from-skills step ${stepNumber} cannot read execution` };
|
|
@@ -453,6 +790,12 @@ function loadSkillExecution(raw, baseDir, stepNumber) {
|
|
|
453
790
|
return { ok: true, value: raw };
|
|
454
791
|
return { ok: false, error: `recipe from-skills step ${stepNumber} requires execution evidence` };
|
|
455
792
|
}
|
|
793
|
+
function readRecipeInputFile(path) {
|
|
794
|
+
const stat = statSync(path);
|
|
795
|
+
if (!stat.isFile() || stat.size > MAX_RECIPE_INPUT_BYTES)
|
|
796
|
+
throw new Error('invalid recipe input file');
|
|
797
|
+
return readFileSync(path, 'utf8');
|
|
798
|
+
}
|
|
456
799
|
function resolveManifestRef(baseDir, ref) {
|
|
457
800
|
return isAbsolute(ref) ? ref : resolve(baseDir, ref);
|
|
458
801
|
}
|
|
@@ -485,8 +828,8 @@ async function callRecipeWithAuthRetry(hub, tag, fn, io) {
|
|
|
485
828
|
throw e;
|
|
486
829
|
if (!authErrorIndicatesStaleNodeSecret(e))
|
|
487
830
|
throw e;
|
|
488
|
-
io.
|
|
489
|
-
const hello = await hub.hello({ rotate: true });
|
|
831
|
+
io.err(`[${tag}] Hub reported a stale node secret; rotating credentials once and retrying...`);
|
|
832
|
+
const hello = await hub.hello({ rotate: true, evolverVersion: getCliVersion() });
|
|
490
833
|
if (!hello.ok) {
|
|
491
834
|
io.err(`[${tag}] Could not auto-rotate credentials: ${hello.error ?? 'unknown'}`);
|
|
492
835
|
io.err(' Recover by resetting the Hub credential, then re-run `evolver login` or update EVOMAP_NODE_SECRET.');
|
|
@@ -642,27 +985,38 @@ function redactSensitiveString(value) {
|
|
|
642
985
|
function resolveRecipeHubCredentials(env) {
|
|
643
986
|
const homeCandidates = recipeHomeCandidates(env);
|
|
644
987
|
const defaultHome = homeCandidates[0] ?? events.evomapHome();
|
|
645
|
-
const
|
|
646
|
-
const
|
|
647
|
-
const
|
|
648
|
-
const
|
|
649
|
-
|
|
988
|
+
const explicitCredentials = resolveExplicitNodeCredentials(env);
|
|
989
|
+
const fromEnv = explicitCredentials.nodeSecret;
|
|
990
|
+
const envNodeSecretVersion = parseNodeSecretVersion(explicitCredentials.nodeSecretVersion);
|
|
991
|
+
const storedCandidate = readRecipeStoreNodeCredentials(env);
|
|
992
|
+
const stored = storedCandidate?.source?.startsWith('pending_') ? undefined : storedCandidate;
|
|
993
|
+
const explicitSenderId = explicitCredentials.senderId;
|
|
994
|
+
const legacy = firstLegacyNodeCredentials(homeCandidates);
|
|
995
|
+
const pairedStoredSenderId = stored?.nodeSecret
|
|
996
|
+
? stored.nodeId
|
|
997
|
+
?? (fromEnv === stored.nodeSecret ? explicitSenderId : undefined)
|
|
998
|
+
?? (legacy?.nodeSecret === stored.nodeSecret ? legacy.nodeId : undefined)
|
|
999
|
+
: undefined;
|
|
1000
|
+
const completeExplicitOverridesOrphan = Boolean(fromEnv
|
|
1001
|
+
&& explicitSenderId
|
|
1002
|
+
&& fromEnv !== stored?.nodeSecret
|
|
1003
|
+
&& pairedStoredSenderId !== explicitSenderId);
|
|
1004
|
+
if (stored?.source === 'hub_rotate' && stored.nodeSecret && !completeExplicitOverridesOrphan) {
|
|
650
1005
|
return {
|
|
651
1006
|
evomapDir: defaultHome,
|
|
652
1007
|
nodeSecret: stored.nodeSecret,
|
|
653
1008
|
...(stored.nodeSecretVersion !== undefined ? { nodeSecretVersion: stored.nodeSecretVersion } : {}),
|
|
654
|
-
senderId:
|
|
1009
|
+
senderId: pairedStoredSenderId,
|
|
655
1010
|
rotatePersistDir: defaultHome,
|
|
656
1011
|
};
|
|
657
1012
|
}
|
|
658
1013
|
if (fromEnv) {
|
|
659
|
-
const legacyNodeId = firstLegacyNodeId(homeCandidates);
|
|
660
1014
|
const nodeSecretVersion = envNodeSecretVersion ?? pairedStoreNodeSecretVersion(fromEnv, stored) ?? pairedLegacyNodeSecretVersion(fromEnv, homeCandidates);
|
|
661
1015
|
return {
|
|
662
1016
|
evomapDir: defaultHome,
|
|
663
1017
|
nodeSecret: fromEnv,
|
|
664
1018
|
...(nodeSecretVersion !== undefined ? { nodeSecretVersion } : {}),
|
|
665
|
-
senderId: explicitSenderId ??
|
|
1019
|
+
senderId: explicitSenderId ?? (legacy?.nodeSecret === fromEnv ? legacy.nodeId : undefined),
|
|
666
1020
|
rotatePersistDir: defaultHome,
|
|
667
1021
|
};
|
|
668
1022
|
}
|
|
@@ -671,27 +1025,38 @@ function resolveRecipeHubCredentials(env) {
|
|
|
671
1025
|
evomapDir: defaultHome,
|
|
672
1026
|
nodeSecret: stored.nodeSecret,
|
|
673
1027
|
...(stored.nodeSecretVersion !== undefined ? { nodeSecretVersion: stored.nodeSecretVersion } : {}),
|
|
674
|
-
senderId:
|
|
1028
|
+
senderId: pairedStoredSenderId,
|
|
675
1029
|
rotatePersistDir: defaultHome,
|
|
676
1030
|
};
|
|
677
1031
|
}
|
|
678
|
-
const legacy = firstLegacyNodeCredentials(homeCandidates);
|
|
679
1032
|
if (legacy) {
|
|
680
1033
|
return {
|
|
681
1034
|
evomapDir: legacy.dir,
|
|
682
1035
|
nodeSecret: legacy.nodeSecret,
|
|
683
1036
|
...(legacy.nodeSecretVersion !== undefined ? { nodeSecretVersion: legacy.nodeSecretVersion } : {}),
|
|
684
|
-
senderId: legacy.nodeId
|
|
1037
|
+
senderId: legacy.nodeId,
|
|
685
1038
|
rotatePersistDir: legacy.dir,
|
|
686
1039
|
};
|
|
687
1040
|
}
|
|
688
1041
|
const oauthDir = homeCandidates.find((dir) => existsSync(join(dir, 'token.json'))) ?? defaultHome;
|
|
689
1042
|
return {
|
|
690
1043
|
evomapDir: oauthDir,
|
|
691
|
-
senderId:
|
|
1044
|
+
senderId: resolveRecipeOAuthSenderId(env, oauthDir),
|
|
692
1045
|
rotatePersistDir: oauthDir,
|
|
693
1046
|
};
|
|
694
1047
|
}
|
|
1048
|
+
function resolveRecipeOAuthSenderId(env, oauthDir) {
|
|
1049
|
+
const evomapNodeId = env['EVOMAP_NODE_ID']?.trim();
|
|
1050
|
+
if (evomapNodeId)
|
|
1051
|
+
return evomapNodeId;
|
|
1052
|
+
const identityNodeId = readLegacyNodeId(oauthDir);
|
|
1053
|
+
if (identityNodeId)
|
|
1054
|
+
return identityNodeId;
|
|
1055
|
+
const a2aNodeId = env['A2A_NODE_ID']?.trim();
|
|
1056
|
+
if (a2aNodeId)
|
|
1057
|
+
return a2aNodeId;
|
|
1058
|
+
return readRecipeStoreNodeCredentials(env)?.nodeId;
|
|
1059
|
+
}
|
|
695
1060
|
/**
|
|
696
1061
|
* The EXPLICIT home overrides (EVOMAP_DIR / EVOLVER_HOME / EVOMAP_HOME) the recipe credential layer honors,
|
|
697
1062
|
* resolved purely from the passed env with no process.env fallback. Exported so `reset-local-secret` (index.ts)
|
|
@@ -724,20 +1089,19 @@ function recipeHomeCandidates(env) {
|
|
|
724
1089
|
];
|
|
725
1090
|
return uniqueStrings(candidates.map((value) => value?.trim()).filter((value) => Boolean(value)));
|
|
726
1091
|
}
|
|
727
|
-
function explicitRecipeSenderId(env) {
|
|
728
|
-
return env['EVOMAP_NODE_ID']?.trim() || env['A2A_NODE_ID']?.trim();
|
|
729
|
-
}
|
|
730
1092
|
function readRecipeStoreNodeCredentials(env) {
|
|
731
1093
|
const storePath = recipeProxyStorePath(env);
|
|
732
1094
|
if (!existsSync(storePath))
|
|
733
1095
|
return undefined;
|
|
734
1096
|
const store = new mailbox.MailboxStore({ path: storePath });
|
|
735
1097
|
try {
|
|
1098
|
+
const nodeId = store.getState('node_id')?.trim() || undefined;
|
|
736
1099
|
const storedSecret = store.getState('node_secret');
|
|
737
1100
|
const nodeSecret = storedSecret && isNodeSecret(storedSecret) ? storedSecret : undefined;
|
|
738
1101
|
const nodeSecretVersion = parseNodeSecretVersion(store.getState('node_secret_version'));
|
|
739
1102
|
const source = store.getState('node_secret_source') || undefined;
|
|
740
1103
|
return {
|
|
1104
|
+
...(nodeId ? { nodeId } : {}),
|
|
741
1105
|
...(nodeSecret ? { nodeSecret } : {}),
|
|
742
1106
|
...(nodeSecretVersion !== undefined ? { nodeSecretVersion } : {}),
|
|
743
1107
|
...(source ? { source } : {}),
|
|
@@ -789,14 +1153,6 @@ function firstLegacyNodeCredentials(dirs) {
|
|
|
789
1153
|
}
|
|
790
1154
|
return undefined;
|
|
791
1155
|
}
|
|
792
|
-
function firstLegacyNodeId(dirs) {
|
|
793
|
-
for (const dir of dirs) {
|
|
794
|
-
const nodeId = readLegacyNodeId(dir);
|
|
795
|
-
if (nodeId)
|
|
796
|
-
return nodeId;
|
|
797
|
-
}
|
|
798
|
-
return undefined;
|
|
799
|
-
}
|
|
800
1156
|
function uniqueStrings(values) {
|
|
801
1157
|
const seen = new Set();
|
|
802
1158
|
const out = [];
|
|
@@ -825,19 +1181,33 @@ function recipeProxyStorePath(env) {
|
|
|
825
1181
|
function setOptionalStoreState(store, key, value) {
|
|
826
1182
|
store.setState(key, value ?? '');
|
|
827
1183
|
}
|
|
828
|
-
function persistRotatedNodeSecret(secret, version, env, legacyDir) {
|
|
1184
|
+
function persistRotatedNodeSecret(secret, version, nodeId, env, legacyDir) {
|
|
829
1185
|
const storePath = recipeProxyStorePath(env);
|
|
830
1186
|
const store = new mailbox.MailboxStore({ path: storePath });
|
|
831
1187
|
try {
|
|
1188
|
+
store.setState('node_secret_source', 'pending_rotate');
|
|
1189
|
+
if (nodeId)
|
|
1190
|
+
store.setState('node_id', nodeId);
|
|
832
1191
|
store.setState('node_secret', secret);
|
|
833
|
-
store.setState('node_secret_source', 'hub_rotate');
|
|
834
1192
|
setOptionalStoreState(store, 'node_secret_version', version !== undefined ? String(version) : undefined);
|
|
1193
|
+
store.setState('node_secret_source', 'hub_rotate');
|
|
835
1194
|
}
|
|
836
1195
|
finally {
|
|
837
1196
|
store.close();
|
|
838
1197
|
}
|
|
839
1198
|
persistLegacyNodeSecret(secret, version, legacyDir);
|
|
840
1199
|
}
|
|
1200
|
+
function persistRecipeNodeId(nodeId, env, legacyDir) {
|
|
1201
|
+
const store = new mailbox.MailboxStore({ path: recipeProxyStorePath(env) });
|
|
1202
|
+
try {
|
|
1203
|
+
store.setState('node_id', nodeId);
|
|
1204
|
+
}
|
|
1205
|
+
finally {
|
|
1206
|
+
store.close();
|
|
1207
|
+
}
|
|
1208
|
+
mkdirSync(legacyDir, { recursive: true, mode: 0o700 });
|
|
1209
|
+
writeFileSync(join(legacyDir, 'node_id'), nodeId, { encoding: 'utf8', mode: 0o600 });
|
|
1210
|
+
}
|
|
841
1211
|
function persistNodeSecretVersion(version, env, legacyDir) {
|
|
842
1212
|
const storePath = recipeProxyStorePath(env);
|
|
843
1213
|
const store = new mailbox.MailboxStore({ path: storePath });
|