@evomap/evolver-cli 2.0.0-beta.1 → 2.0.0-beta.10
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 +12 -0
- package/dist/antiGeneEvidence.d.ts +15 -0
- package/dist/antiGeneEvidence.js +49 -0
- package/dist/antiGeneRollout.d.ts +3 -1
- package/dist/antiGeneRollout.js +16 -2
- package/dist/assetHealth.d.ts +6 -0
- package/dist/assetHealth.js +105 -0
- package/dist/assetSidecarRecovery.d.ts +14 -0
- package/dist/assetSidecarRecovery.js +171 -0
- package/dist/assetTrust.d.ts +24 -0
- package/dist/assetTrust.js +218 -0
- package/dist/atp.js +4 -2
- package/dist/autoDistillLlm.d.ts +6 -0
- package/dist/autoDistillLlm.js +44 -7
- package/dist/autoexec.d.ts +14 -12
- package/dist/autoexec.js +84 -34
- package/dist/autoexecConfig.d.ts +10 -0
- package/dist/autoexecConfig.js +68 -0
- package/dist/cli.js +12 -5
- package/dist/cliContracts.js +30 -3
- package/dist/cliLifecycle.d.ts +7 -0
- package/dist/cliLifecycle.js +9 -0
- package/dist/cycleConsumer.d.ts +61 -1
- package/dist/cycleConsumer.js +551 -16
- package/dist/dashboard.d.ts +33 -0
- package/dist/dashboard.js +352 -0
- package/dist/dispatch.d.ts +10 -1
- package/dist/dispatch.js +40 -2
- package/dist/distillAdmission.d.ts +13 -0
- package/dist/distillAdmission.js +35 -0
- package/dist/distillObserver.js +6 -8
- package/dist/distillPrimitives.d.ts +9 -7
- package/dist/distillPrimitives.js +65 -12
- package/dist/doctor.d.ts +2 -0
- package/dist/doctor.js +49 -3
- package/dist/index.d.ts +8 -2
- package/dist/index.js +350 -42
- package/dist/issueReport.d.ts +7 -0
- package/dist/issueReport.js +291 -0
- package/dist/lifecycle.d.ts +19 -1
- package/dist/lifecycle.js +226 -29
- package/dist/localMemoryGraph.d.ts +97 -0
- package/dist/localMemoryGraph.js +889 -0
- package/dist/login.d.ts +20 -4
- package/dist/login.js +58 -8
- package/dist/materialPackage.d.ts +52 -0
- package/dist/materialPackage.js +401 -0
- package/dist/materialSnapshot.d.ts +54 -0
- package/dist/materialSnapshot.js +370 -0
- package/dist/memoryEventMirror.d.ts +23 -0
- package/dist/memoryEventMirror.js +140 -0
- package/dist/migrate/fieldMap.js +25 -0
- package/dist/migrate/v1Import.d.ts +7 -1
- package/dist/migrate/v1Import.js +132 -11
- package/dist/nonGitWorkspaceNotice.d.ts +24 -0
- package/dist/nonGitWorkspaceNotice.js +122 -0
- package/dist/proxyToken.d.ts +10 -0
- package/dist/proxyToken.js +80 -0
- package/dist/recipe.d.ts +12 -2
- package/dist/recipe.js +381 -8
- package/dist/reuse.d.ts +5 -3
- package/dist/reuse.js +74 -6
- package/dist/reuseReport.js +16 -16
- package/dist/runtimeCapabilities.d.ts +18 -0
- package/dist/runtimeCapabilities.js +81 -0
- package/dist/runtimeSessionSource.d.ts +10 -0
- package/dist/runtimeSessionSource.js +32 -5
- package/dist/setupHooks.d.ts +11 -1
- package/dist/setupHooks.js +235 -16
- package/dist/skill2gep.d.ts +38 -9
- package/dist/skill2gep.js +147 -14
- package/dist/skillDistill.d.ts +1 -0
- package/dist/skillDistill.js +4 -4
- package/dist/skillFetch.d.ts +18 -0
- package/dist/skillFetch.js +391 -0
- package/dist/solo/mode.js +5 -0
- package/dist/sync.d.ts +38 -0
- package/dist/sync.js +1981 -0
- package/dist/trajectoryExport.js +23 -12
- package/dist/v1Compat.d.ts +24 -0
- package/dist/v1Compat.js +249 -0
- package/dist/workflow.d.ts +39 -0
- package/dist/workflow.js +386 -0
- package/dist/workflowRuntime.d.ts +66 -0
- package/dist/workflowRuntime.js +631 -0
- package/package.json +12 -6
package/dist/recipe.js
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import { existsSync, mkdirSync, readFileSync, unlinkSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { createHash } from 'node:crypto';
|
|
2
3
|
import { homedir } from 'node:os';
|
|
3
|
-
import { join } from 'node:path';
|
|
4
|
+
import { dirname, isAbsolute, join, resolve } from 'node:path';
|
|
4
5
|
import { assetstore, events, mailbox } from '@evomap/evolver-core';
|
|
5
|
-
import { AuthError, HubClientError, HubUnreachableError, connectPublicHub, isHubDryRunEnabled, isNodeSecret, parseNodeSecretVersion } from '@evomap/evolver-adapter-public';
|
|
6
|
+
import { AuthError, HubClientError, HubUnreachableError, connectPublicHub, isHubDryRunEnabled, isNodeSecret, parseNodeSecretVersion, resolveHubUrl } from '@evomap/evolver-adapter-public';
|
|
7
|
+
import { loadEnvFileFromEnv } from '@evomap/evolver-mcp';
|
|
6
8
|
import { resolveAtpSenderId } from './atp.js';
|
|
9
|
+
import { parseSkillMd, reverseDistill } from './skill2gep.js';
|
|
10
|
+
import { recordSkillDistillation } from './skillDistill.js';
|
|
7
11
|
const MAX_RECIPE_STEPS = 20;
|
|
8
12
|
const MAX_ID_LENGTH = 200;
|
|
9
|
-
const DEFAULT_PUBLIC_HUB_URL = 'https://evomap.ai';
|
|
10
13
|
const SENSITIVE_ERROR_KEYS = new Set(['authorization', 'node_secret', 'nodesecret', 'token', 'access_token', 'refresh_token', 'secret']);
|
|
11
14
|
const STALE_NODE_SECRET_ERRORS = new Set(['node_secret_invalid', 'node_secret_not_set']);
|
|
12
15
|
export async function runRecipeCommand(argv, deps = {}) {
|
|
@@ -22,6 +25,8 @@ export async function runRecipeCommand(argv, deps = {}) {
|
|
|
22
25
|
if (isHubDryRunEnabled(env)) {
|
|
23
26
|
if (parsed.value.sub === 'build')
|
|
24
27
|
return await runRecipeBuildDryRun(parsed.value, deps.store, { log, err });
|
|
28
|
+
if (parsed.value.sub === 'from-skills')
|
|
29
|
+
return await runRecipeFromSkills(parsed.value, undefined, deps, { log, err }, true);
|
|
25
30
|
return runRecipeReuseDryRun(parsed.value, { log });
|
|
26
31
|
}
|
|
27
32
|
const hub = deps.hub ?? createRecipeHubFromEnv(env, deps.connectHub ?? connectPublicHub);
|
|
@@ -31,6 +36,8 @@ export async function runRecipeCommand(argv, deps = {}) {
|
|
|
31
36
|
}
|
|
32
37
|
if (parsed.value.sub === 'build')
|
|
33
38
|
return await runRecipeBuild(parsed.value, hub, deps.store, { log, err });
|
|
39
|
+
if (parsed.value.sub === 'from-skills')
|
|
40
|
+
return await runRecipeFromSkills(parsed.value, hub, deps, { log, err }, false);
|
|
34
41
|
return await runRecipeReuse(parsed.value, hub, { log, err });
|
|
35
42
|
}
|
|
36
43
|
catch (e) {
|
|
@@ -67,6 +74,7 @@ function runRecipeReuseDryRun(opts, io) {
|
|
|
67
74
|
return 0;
|
|
68
75
|
}
|
|
69
76
|
export function createRecipeHubFromEnv(env = process.env, connectHub = connectPublicHub) {
|
|
77
|
+
loadEnvFileFromEnv(env);
|
|
70
78
|
const hubUrl = resolveRecipeHubUrl(env);
|
|
71
79
|
const credentials = resolveRecipeHubCredentials(env);
|
|
72
80
|
if (!credentials.nodeSecret && !existsSync(join(credentials.evomapDir, 'token.json'))) {
|
|
@@ -89,17 +97,42 @@ export function createRecipeHubFromEnv(env = process.env, connectHub = connectPu
|
|
|
89
97
|
: connectHub({ hubUrl, authMode: 'oauth', evomapDir: credentials.evomapDir, senderId: () => credentials.senderId });
|
|
90
98
|
return connected.hub;
|
|
91
99
|
}
|
|
100
|
+
/** Opaque identity for resume isolation; raw credentials, account ids, and local paths never leave this helper. */
|
|
101
|
+
export function resolveRecipeHubResumeIdentityFingerprint(env) {
|
|
102
|
+
loadEnvFileFromEnv(env);
|
|
103
|
+
const credentials = resolveRecipeHubCredentials(env);
|
|
104
|
+
let credential;
|
|
105
|
+
if (credentials.nodeSecret) {
|
|
106
|
+
credential = credentials.nodeSecret;
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
try {
|
|
110
|
+
credential = createHash('sha256')
|
|
111
|
+
.update(readFileSync(join(credentials.evomapDir, 'token.json'), 'utf8'))
|
|
112
|
+
.digest('hex');
|
|
113
|
+
}
|
|
114
|
+
catch {
|
|
115
|
+
throw new Error('Hub resume identity credentials are unavailable');
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return createHash('sha256').update(JSON.stringify({
|
|
119
|
+
authMode: credentials.nodeSecret ? 'legacy' : 'oauth',
|
|
120
|
+
senderId: credentials.senderId ?? '',
|
|
121
|
+
credential,
|
|
122
|
+
})).digest('hex');
|
|
123
|
+
}
|
|
92
124
|
function resolveRecipeHubUrl(env) {
|
|
93
|
-
|
|
94
|
-
return hubUrl;
|
|
125
|
+
return resolveHubUrl(env);
|
|
95
126
|
}
|
|
96
127
|
export function parseRecipeArgs(argv) {
|
|
97
128
|
const sub = argv[0];
|
|
98
|
-
if (sub !== 'build' && sub !== 'reuse')
|
|
99
|
-
return { ok: false, error: 'recipe subcommand must be build|reuse' };
|
|
129
|
+
if (sub !== 'build' && sub !== 'reuse' && sub !== 'from-skills')
|
|
130
|
+
return { ok: false, error: 'recipe subcommand must be build|reuse|from-skills' };
|
|
100
131
|
const args = argv.slice(1);
|
|
101
132
|
if (sub === 'build')
|
|
102
133
|
return parseBuildArgs(args);
|
|
134
|
+
if (sub === 'from-skills')
|
|
135
|
+
return parseFromSkillsArgs(args);
|
|
103
136
|
return parseReuseArgs(args);
|
|
104
137
|
}
|
|
105
138
|
async function runRecipeBuild(opts, hub, store, io) {
|
|
@@ -129,6 +162,132 @@ async function runRecipeBuild(opts, hub, store, io) {
|
|
|
129
162
|
}
|
|
130
163
|
return 0;
|
|
131
164
|
}
|
|
165
|
+
async function runRecipeFromSkills(opts, hub, deps, io, dryRun) {
|
|
166
|
+
const loaded = loadRecipeFromSkillsManifest(opts.manifestPath);
|
|
167
|
+
if (!loaded.ok) {
|
|
168
|
+
io.err(loaded.error);
|
|
169
|
+
return 1;
|
|
170
|
+
}
|
|
171
|
+
const preflight = preflightRecipeFromSkillsSteps(loaded.value.steps);
|
|
172
|
+
if (!preflight.ok) {
|
|
173
|
+
io.err(preflight.error);
|
|
174
|
+
return 1;
|
|
175
|
+
}
|
|
176
|
+
const store = deps.store ?? new assetstore.LocalJsonlProvider(events.assetsDir());
|
|
177
|
+
const ingestor = deps.ingestor ?? new events.Ingestor({ path: events.rootEventsPath() });
|
|
178
|
+
const steps = [];
|
|
179
|
+
const distilled = [];
|
|
180
|
+
for (const prepared of preflight.value) {
|
|
181
|
+
const existing = await findReusableRecipeStep(store, prepared);
|
|
182
|
+
if (existing) {
|
|
183
|
+
addRecipeFromSkillsStep(steps, distilled, existing);
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
186
|
+
const step = prepared.step;
|
|
187
|
+
const res = await recordSkillDistillation(step.skill, step.execution, {
|
|
188
|
+
store,
|
|
189
|
+
...(deps.review ? { review: deps.review } : {}),
|
|
190
|
+
ingestor,
|
|
191
|
+
}, step.scenario ? { scenario: step.scenario } : {});
|
|
192
|
+
if (!res.geneId || !res.geneAssetId) {
|
|
193
|
+
const recovered = await findReusableRecipeStep(store, prepared);
|
|
194
|
+
if (recovered) {
|
|
195
|
+
addRecipeFromSkillsStep(steps, distilled, recovered);
|
|
196
|
+
continue;
|
|
197
|
+
}
|
|
198
|
+
io.err(`recipe from-skills step ${prepared.position + 1} did not produce a Gene: ${res.errors.join('; ') || 'refused'}`);
|
|
199
|
+
return 1;
|
|
200
|
+
}
|
|
201
|
+
if (!res.capsuleId) {
|
|
202
|
+
io.err(`recipe from-skills step ${prepared.position + 1} missing Capsule evidence: ${res.capsuleDiagnostic ?? 'missing_capsule_evidence'}`);
|
|
203
|
+
return 1;
|
|
204
|
+
}
|
|
205
|
+
if (!(await hasCapsuleEvidence(store, res.capsuleId, res.geneId))) {
|
|
206
|
+
io.err(`recipe from-skills step ${prepared.position + 1} missing persisted Capsule evidence`);
|
|
207
|
+
return 1;
|
|
208
|
+
}
|
|
209
|
+
addRecipeFromSkillsStep(steps, distilled, {
|
|
210
|
+
position: prepared.position,
|
|
211
|
+
geneId: res.geneId,
|
|
212
|
+
geneAssetId: res.geneAssetId,
|
|
213
|
+
capsuleId: res.capsuleId,
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
if (dryRun) {
|
|
217
|
+
const payload = recipeFromSkillsPayload({
|
|
218
|
+
mode: 'dry_run',
|
|
219
|
+
title: loaded.value.title,
|
|
220
|
+
publish: opts.publish,
|
|
221
|
+
steps: distilled,
|
|
222
|
+
});
|
|
223
|
+
if (opts.jsonOut)
|
|
224
|
+
io.log(JSON.stringify(payload, null, 2));
|
|
225
|
+
else {
|
|
226
|
+
io.log(`[recipe from-skills] dry-run: would create DRAFT recipe ("${loaded.value.title}", ${steps.length} step${steps.length === 1 ? '' : 's'}).`);
|
|
227
|
+
if (opts.publish)
|
|
228
|
+
io.log('[recipe from-skills] dry-run: would publish the recipe after creation.');
|
|
229
|
+
else
|
|
230
|
+
io.log('[recipe from-skills] dry-run: would leave the recipe as draft.');
|
|
231
|
+
}
|
|
232
|
+
return 0;
|
|
233
|
+
}
|
|
234
|
+
if (!hub?.recipes) {
|
|
235
|
+
io.err('recipe capability is not available for the configured Hub adapter');
|
|
236
|
+
return 1;
|
|
237
|
+
}
|
|
238
|
+
const createReceipt = await callRecipeWithAuthRetry(hub, 'recipe from-skills', () => hub.recipes.create({
|
|
239
|
+
title: loaded.value.title,
|
|
240
|
+
steps,
|
|
241
|
+
...(loaded.value.description ? { description: loaded.value.description } : {}),
|
|
242
|
+
...(loaded.value.pricePerExecution !== undefined ? { pricePerExecution: loaded.value.pricePerExecution } : {}),
|
|
243
|
+
}), io);
|
|
244
|
+
const recipeId = createReceipt.recipeId;
|
|
245
|
+
if (!opts.jsonOut) {
|
|
246
|
+
io.log(`[recipe from-skills] Created DRAFT recipe ${recipeId ?? '(id pending)'} ("${loaded.value.title}", ${steps.length} step${steps.length === 1 ? '' : 's'}).`);
|
|
247
|
+
}
|
|
248
|
+
if (opts.publish) {
|
|
249
|
+
if (!recipeId) {
|
|
250
|
+
io.err('[recipe from-skills] Hub did not return a recipe id; cannot publish.');
|
|
251
|
+
return 1;
|
|
252
|
+
}
|
|
253
|
+
try {
|
|
254
|
+
await callRecipeWithAuthRetry(hub, 'recipe from-skills', () => hub.recipes.publish(recipeId), io);
|
|
255
|
+
}
|
|
256
|
+
catch (e) {
|
|
257
|
+
if (opts.jsonOut) {
|
|
258
|
+
io.log(JSON.stringify(recipeFromSkillsPayload({
|
|
259
|
+
ok: false,
|
|
260
|
+
mode: 'draft',
|
|
261
|
+
title: loaded.value.title,
|
|
262
|
+
publish: opts.publish,
|
|
263
|
+
steps: distilled,
|
|
264
|
+
recipeId,
|
|
265
|
+
error: 'publish_failed',
|
|
266
|
+
}), null, 2));
|
|
267
|
+
}
|
|
268
|
+
else {
|
|
269
|
+
io.err(`[recipe from-skills] Created DRAFT recipe ${recipeId}; publish failed before it was made live.`);
|
|
270
|
+
}
|
|
271
|
+
throw e;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
const payload = recipeFromSkillsPayload({
|
|
275
|
+
mode: opts.publish ? 'published' : 'draft',
|
|
276
|
+
title: loaded.value.title,
|
|
277
|
+
publish: opts.publish,
|
|
278
|
+
steps: distilled,
|
|
279
|
+
recipeId,
|
|
280
|
+
});
|
|
281
|
+
if (opts.jsonOut)
|
|
282
|
+
io.log(JSON.stringify(payload, null, 2));
|
|
283
|
+
else {
|
|
284
|
+
if (opts.publish)
|
|
285
|
+
io.log(`[recipe from-skills] Published recipe ${recipeId}.`);
|
|
286
|
+
else
|
|
287
|
+
io.log('[recipe from-skills] Left as draft. Re-run with --publish to make it live.');
|
|
288
|
+
}
|
|
289
|
+
return 0;
|
|
290
|
+
}
|
|
132
291
|
async function runRecipeReuse(opts, hub, io) {
|
|
133
292
|
await callRecipeWithAuthRetry(hub, 'recipe reuse', () => hub.recipes.get(opts.recipeId), io);
|
|
134
293
|
const receipt = await callRecipeWithAuthRetry(hub, 'recipe reuse', () => hub.recipes.express(opts.recipeId, { inputPayload: opts.inputPayload }), io);
|
|
@@ -150,6 +309,198 @@ async function recipeStepsFromLocalAssets(assetIds, store) {
|
|
|
150
309
|
return { assetId, assetType, position: index };
|
|
151
310
|
});
|
|
152
311
|
}
|
|
312
|
+
function preflightRecipeFromSkillsSteps(steps) {
|
|
313
|
+
const prepared = [];
|
|
314
|
+
for (let i = 0; i < steps.length; i += 1) {
|
|
315
|
+
const step = steps[i];
|
|
316
|
+
const parsed = parseSkillMd(step.skill);
|
|
317
|
+
const preview = reverseDistill(parsed, step.execution, step.scenario ? { scenario: step.scenario } : {});
|
|
318
|
+
if (!preview.gene) {
|
|
319
|
+
return {
|
|
320
|
+
ok: false,
|
|
321
|
+
error: `recipe from-skills step ${i + 1} did not produce a Gene: ${preview.errors.join('; ') || 'refused'}`,
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
if (!preview.capsule) {
|
|
325
|
+
const diag = preview.capsuleDiagnostic
|
|
326
|
+
? (preview.capsuleDiagnostic.detail ?? preview.capsuleDiagnostic.reason)
|
|
327
|
+
: 'missing_capsule_evidence';
|
|
328
|
+
return {
|
|
329
|
+
ok: false,
|
|
330
|
+
error: `recipe from-skills step ${i + 1} missing Capsule evidence: ${diag}`,
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
prepared.push({
|
|
334
|
+
position: i,
|
|
335
|
+
step,
|
|
336
|
+
candidateSignals: normalizedSignalList(preview.gene.signals_match),
|
|
337
|
+
candidateCapsuleId: preview.capsule.id,
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
return { ok: true, value: prepared };
|
|
341
|
+
}
|
|
342
|
+
async function findReusableRecipeStep(store, prepared) {
|
|
343
|
+
const candidateSignals = prepared.candidateSignals;
|
|
344
|
+
if (candidateSignals.length === 0)
|
|
345
|
+
return null;
|
|
346
|
+
const genes = await store.list('Gene', 10_000);
|
|
347
|
+
const capsules = await store.list('Capsule', 10_000);
|
|
348
|
+
for (const gene of genes) {
|
|
349
|
+
const signals = new Set(normalizedSignalList(gene['signals_match']));
|
|
350
|
+
if (!candidateSignals.every((signal) => signals.has(signal)))
|
|
351
|
+
continue;
|
|
352
|
+
const geneId = typeof gene['id'] === 'string' && gene['id'].trim()
|
|
353
|
+
? gene['id'].trim()
|
|
354
|
+
: String(gene['asset_id'] ?? '');
|
|
355
|
+
const geneAssetId = typeof gene['asset_id'] === 'string' ? gene['asset_id'] : '';
|
|
356
|
+
if (!geneId || !geneAssetId)
|
|
357
|
+
continue;
|
|
358
|
+
const capsule = capsules.find((record) => String(record['id']) === prepared.candidateCapsuleId &&
|
|
359
|
+
String(record['gene']) === geneId);
|
|
360
|
+
if (!capsule)
|
|
361
|
+
continue;
|
|
362
|
+
return {
|
|
363
|
+
position: prepared.position,
|
|
364
|
+
geneId,
|
|
365
|
+
geneAssetId,
|
|
366
|
+
capsuleId: String(capsule['id']),
|
|
367
|
+
};
|
|
368
|
+
}
|
|
369
|
+
return null;
|
|
370
|
+
}
|
|
371
|
+
function addRecipeFromSkillsStep(steps, distilled, result) {
|
|
372
|
+
steps.push({ assetId: result.geneAssetId, assetType: 'Gene', position: result.position });
|
|
373
|
+
distilled.push(result);
|
|
374
|
+
}
|
|
375
|
+
async function hasCapsuleEvidence(store, capsuleId, geneId) {
|
|
376
|
+
const capsules = await store.list('Capsule', 10_000);
|
|
377
|
+
return capsules.some((capsule) => String(capsule['id']) === capsuleId &&
|
|
378
|
+
String(capsule['gene']) === geneId);
|
|
379
|
+
}
|
|
380
|
+
function normalizedSignalList(value) {
|
|
381
|
+
return Array.isArray(value)
|
|
382
|
+
? value.map((item) => String(item).trim().toLowerCase()).filter(Boolean)
|
|
383
|
+
: [];
|
|
384
|
+
}
|
|
385
|
+
function loadRecipeFromSkillsManifest(path) {
|
|
386
|
+
let raw;
|
|
387
|
+
const manifestPath = resolve(path);
|
|
388
|
+
try {
|
|
389
|
+
raw = readFileSync(manifestPath, 'utf8');
|
|
390
|
+
}
|
|
391
|
+
catch {
|
|
392
|
+
return { ok: false, error: 'recipe from-skills cannot read --manifest file' };
|
|
393
|
+
}
|
|
394
|
+
let parsed;
|
|
395
|
+
try {
|
|
396
|
+
parsed = JSON.parse(raw);
|
|
397
|
+
}
|
|
398
|
+
catch {
|
|
399
|
+
return { ok: false, error: 'recipe from-skills --manifest must be valid JSON' };
|
|
400
|
+
}
|
|
401
|
+
if (!isPlainRecord(parsed))
|
|
402
|
+
return { ok: false, error: 'recipe from-skills --manifest must be a JSON object' };
|
|
403
|
+
const title = typeof parsed['title'] === 'string' ? parsed['title'].trim() : '';
|
|
404
|
+
if (!title)
|
|
405
|
+
return { ok: false, error: 'recipe from-skills manifest requires title' };
|
|
406
|
+
const rawSteps = parsed['steps'];
|
|
407
|
+
if (!Array.isArray(rawSteps) || rawSteps.length === 0)
|
|
408
|
+
return { ok: false, error: 'recipe from-skills manifest requires non-empty steps[]' };
|
|
409
|
+
if (rawSteps.length > MAX_RECIPE_STEPS)
|
|
410
|
+
return { ok: false, error: `recipe from-skills supports at most ${MAX_RECIPE_STEPS} steps` };
|
|
411
|
+
const priceRaw = parsed['pricePerExecution'];
|
|
412
|
+
if (priceRaw === null)
|
|
413
|
+
return { ok: false, error: 'recipe from-skills pricePerExecution must be a non-negative number' };
|
|
414
|
+
const price = priceRaw === undefined ? undefined : Number(priceRaw);
|
|
415
|
+
if (price !== undefined && (!Number.isFinite(price) || price < 0))
|
|
416
|
+
return { ok: false, error: 'recipe from-skills pricePerExecution must be a non-negative number' };
|
|
417
|
+
const baseDir = dirname(manifestPath);
|
|
418
|
+
const steps = [];
|
|
419
|
+
for (let i = 0; i < rawSteps.length; i += 1) {
|
|
420
|
+
const rawStep = rawSteps[i];
|
|
421
|
+
if (!isPlainRecord(rawStep))
|
|
422
|
+
return { ok: false, error: `recipe from-skills step ${i + 1} must be a JSON object` };
|
|
423
|
+
const skillRef = typeof rawStep['skill'] === 'string' ? rawStep['skill'].trim() : '';
|
|
424
|
+
if (!skillRef)
|
|
425
|
+
return { ok: false, error: `recipe from-skills step ${i + 1} requires skill` };
|
|
426
|
+
let skill;
|
|
427
|
+
try {
|
|
428
|
+
skill = readFileSync(resolveManifestRef(baseDir, skillRef), 'utf8');
|
|
429
|
+
}
|
|
430
|
+
catch {
|
|
431
|
+
return { ok: false, error: `recipe from-skills step ${i + 1} cannot read skill` };
|
|
432
|
+
}
|
|
433
|
+
const execution = loadSkillExecution(rawStep['execution'], baseDir, i + 1);
|
|
434
|
+
if (!execution.ok)
|
|
435
|
+
return execution;
|
|
436
|
+
const scenario = typeof rawStep['scenario'] === 'string' && rawStep['scenario'].trim()
|
|
437
|
+
? rawStep['scenario'].trim()
|
|
438
|
+
: undefined;
|
|
439
|
+
steps.push({
|
|
440
|
+
skill,
|
|
441
|
+
execution: execution.value,
|
|
442
|
+
...(scenario ? { scenario } : {}),
|
|
443
|
+
});
|
|
444
|
+
}
|
|
445
|
+
const description = typeof parsed['description'] === 'string' && parsed['description'].trim()
|
|
446
|
+
? parsed['description'].trim()
|
|
447
|
+
: undefined;
|
|
448
|
+
return {
|
|
449
|
+
ok: true,
|
|
450
|
+
value: {
|
|
451
|
+
title,
|
|
452
|
+
...(description ? { description } : {}),
|
|
453
|
+
...(price !== undefined ? { pricePerExecution: price } : {}),
|
|
454
|
+
steps,
|
|
455
|
+
},
|
|
456
|
+
};
|
|
457
|
+
}
|
|
458
|
+
function loadSkillExecution(raw, baseDir, stepNumber) {
|
|
459
|
+
if (typeof raw === 'string' && raw.trim()) {
|
|
460
|
+
let text;
|
|
461
|
+
try {
|
|
462
|
+
text = readFileSync(resolveManifestRef(baseDir, raw.trim()), 'utf8');
|
|
463
|
+
}
|
|
464
|
+
catch {
|
|
465
|
+
return { ok: false, error: `recipe from-skills step ${stepNumber} cannot read execution` };
|
|
466
|
+
}
|
|
467
|
+
try {
|
|
468
|
+
const parsed = JSON.parse(text);
|
|
469
|
+
if (isPlainRecord(parsed))
|
|
470
|
+
return { ok: true, value: parsed };
|
|
471
|
+
return { ok: false, error: `recipe from-skills step ${stepNumber} execution must be a JSON object` };
|
|
472
|
+
}
|
|
473
|
+
catch {
|
|
474
|
+
return { ok: false, error: `recipe from-skills step ${stepNumber} execution must be valid JSON` };
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
if (isPlainRecord(raw))
|
|
478
|
+
return { ok: true, value: raw };
|
|
479
|
+
return { ok: false, error: `recipe from-skills step ${stepNumber} requires execution evidence` };
|
|
480
|
+
}
|
|
481
|
+
function resolveManifestRef(baseDir, ref) {
|
|
482
|
+
return isAbsolute(ref) ? ref : resolve(baseDir, ref);
|
|
483
|
+
}
|
|
484
|
+
function isPlainRecord(value) {
|
|
485
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
486
|
+
}
|
|
487
|
+
function recipeFromSkillsPayload(opts) {
|
|
488
|
+
return {
|
|
489
|
+
ok: opts.ok ?? true,
|
|
490
|
+
group: 'recipe.from_skills',
|
|
491
|
+
mode: opts.mode,
|
|
492
|
+
title: opts.title,
|
|
493
|
+
...(opts.recipeId ? { recipeId: opts.recipeId } : {}),
|
|
494
|
+
...(opts.error ? { error: opts.error } : {}),
|
|
495
|
+
publish: opts.publish,
|
|
496
|
+
steps: opts.steps.map((step) => ({
|
|
497
|
+
position: step.position,
|
|
498
|
+
geneId: step.geneId,
|
|
499
|
+
geneAssetId: step.geneAssetId,
|
|
500
|
+
capsuleId: step.capsuleId,
|
|
501
|
+
})),
|
|
502
|
+
};
|
|
503
|
+
}
|
|
153
504
|
async function callRecipeWithAuthRetry(hub, tag, fn, io) {
|
|
154
505
|
try {
|
|
155
506
|
return await fn();
|
|
@@ -198,6 +549,20 @@ function parseBuildArgs(args) {
|
|
|
198
549
|
},
|
|
199
550
|
};
|
|
200
551
|
}
|
|
552
|
+
function parseFromSkillsArgs(args) {
|
|
553
|
+
const manifestPath = flagValue(args, '--manifest');
|
|
554
|
+
if (!manifestPath)
|
|
555
|
+
return { ok: false, error: 'recipe from-skills requires --manifest <file>' };
|
|
556
|
+
return {
|
|
557
|
+
ok: true,
|
|
558
|
+
value: {
|
|
559
|
+
sub: 'from-skills',
|
|
560
|
+
manifestPath,
|
|
561
|
+
publish: args.includes('--publish'),
|
|
562
|
+
jsonOut: args.includes('--json'),
|
|
563
|
+
},
|
|
564
|
+
};
|
|
565
|
+
}
|
|
201
566
|
function parseReuseArgs(args) {
|
|
202
567
|
const recipeId = flagValue(args, '--id') ?? firstPositional(args);
|
|
203
568
|
if (!recipeId)
|
|
@@ -361,10 +726,16 @@ function resolveRecipeHubCredentials(env) {
|
|
|
361
726
|
* the next recipe run (H3). Kept env-pure (no events.evomapHome()) so reset stays hermetic under an injected env.
|
|
362
727
|
*/
|
|
363
728
|
export function explicitRecipeHomes(env) {
|
|
729
|
+
// Identity-first order (#555 T2): EVOMAP_HOME is THE identity home and outranks the state root
|
|
730
|
+
// (EVOLVER_HOME). This order decides BOTH the read fall-through AND rotatePersistDir (= homes[0]),
|
|
731
|
+
// so under the evox agentDir split (EVOMAP_HOME=<agentDir>/evomap, EVOLVER_HOME=<agentDir>/evolver)
|
|
732
|
+
// a hub-rotated secret persists into the evomap dir the desktop actually reads — the old
|
|
733
|
+
// EVOLVER_HOME-first order would strand it in the state root and split-brain the node on rotation.
|
|
734
|
+
// Read-your-writes holds because read and persist share this one order; single-home setups are unchanged.
|
|
364
735
|
const explicit = [
|
|
736
|
+
env['EVOMAP_HOME'],
|
|
365
737
|
env['EVOMAP_DIR'],
|
|
366
738
|
env['EVOLVER_HOME'],
|
|
367
|
-
env['EVOMAP_HOME'],
|
|
368
739
|
];
|
|
369
740
|
return uniqueStrings(explicit.map((value) => value?.trim()).filter((value) => Boolean(value)));
|
|
370
741
|
}
|
|
@@ -559,6 +930,8 @@ function recipeUsage() {
|
|
|
559
930
|
'Recipe subcommands:',
|
|
560
931
|
' evolver recipe build --title <title> --genes <asset_id,...> [--description <text>] [--price <n>] [--publish]',
|
|
561
932
|
' Creates a draft recipe by default. --publish is explicit.',
|
|
933
|
+
' evolver recipe from-skills --manifest <file> [--publish] [--json]',
|
|
934
|
+
' Distills ordered SKILL.md steps with execution evidence, then creates a recipe.',
|
|
562
935
|
' evolver recipe reuse --id <recipe_id> [--input <json-object>] [--json]',
|
|
563
936
|
].join('\n');
|
|
564
937
|
}
|
package/dist/reuse.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { assetstore, hub as hubNs } from '@evomap/evolver-core';
|
|
2
|
-
import type { ConnectPublicOptions, PublicHubCapability } from '@evomap/evolver-adapter-public';
|
|
2
|
+
import type { ConnectPublicOptions, PublicHelloOptions, PublicHubCapability } from '@evomap/evolver-adapter-public';
|
|
3
3
|
declare const REUSE_CONTRACT = "reuse.v1";
|
|
4
|
-
export type ReuseStatus = 'ok' | 'dry_run' | 'invalid_arg' | 'missing_id' | 'unsupported' | 'not_found' | 'unauthorized' | 'unavailable' | 'network' | 'internal_error';
|
|
4
|
+
export type ReuseStatus = 'ok' | 'dry_run' | 'invalid_arg' | 'missing_id' | 'unsupported' | 'not_found' | 'unauthorized' | 'unavailable' | 'network' | 'rate_limited' | 'integrity_failed' | 'internal_error';
|
|
5
5
|
/** The stable reuse.v1 machine contract printed to stdout on success AND failure. Field set is locked by the
|
|
6
6
|
* consumer (evox-desktop `evolverReuseEnvelope`, #1008): { ok, contract, status, reason, message }. */
|
|
7
7
|
export interface ReuseEnvelope {
|
|
@@ -11,9 +11,11 @@ export interface ReuseEnvelope {
|
|
|
11
11
|
reason: string;
|
|
12
12
|
message: string;
|
|
13
13
|
}
|
|
14
|
-
/** Minimal hub surface this command needs:
|
|
14
|
+
/** Minimal hub surface this command needs: a single fetch-by-id, plus an optional trust-establishing hello
|
|
15
|
+
* (PublicHubCapability satisfies both; a bare fetcher in tests may omit hello). */
|
|
15
16
|
type AssetByIdFetcher = {
|
|
16
17
|
fetchAssetById(assetId: string): Promise<assetstore.AssetRecord | null>;
|
|
18
|
+
hello?(opts: PublicHelloOptions): Promise<unknown>;
|
|
17
19
|
};
|
|
18
20
|
export interface ReuseCliDeps {
|
|
19
21
|
store?: assetstore.AssetStoreProvider;
|
package/dist/reuse.js
CHANGED
|
@@ -14,6 +14,7 @@ import { assetstore, events, hub as hubNs, wire } from '@evomap/evolver-core';
|
|
|
14
14
|
import { AuthError, HubClientError, HubUnreachableError, connectPublicHub, isHubDryRunEnabled } from '@evomap/evolver-adapter-public';
|
|
15
15
|
import { loadEnvFileFromEnv } from '@evomap/evolver-mcp';
|
|
16
16
|
import { createRecipeHubFromEnv } from './recipe.js';
|
|
17
|
+
import { getCliVersion } from './version.js';
|
|
17
18
|
const REUSE_CONTRACT = 'reuse.v1';
|
|
18
19
|
const MAX_ID_LENGTH = 200;
|
|
19
20
|
const REUSE_USAGE = [
|
|
@@ -23,6 +24,8 @@ const REUSE_USAGE = [
|
|
|
23
24
|
// Flags that consume the following token as their value. firstPositional must skip those values so a flag value
|
|
24
25
|
// (e.g. the `reference` in `--mode reference`) is never mistaken for a bare positional asset id.
|
|
25
26
|
const VALUE_FLAGS = new Set(['--id', '--mode', '--run']);
|
|
27
|
+
// Keep this list limited to Hub-only fields. `confidence` is canonical Capsule content and must
|
|
28
|
+
// survive integrity verification even though delivery rows also use a field with that name.
|
|
26
29
|
const HUB_METADATA_KEYS = new Set([
|
|
27
30
|
'credit_cost',
|
|
28
31
|
'gdi_score',
|
|
@@ -86,6 +89,12 @@ export async function runReuseCommand(argv, deps = {}) {
|
|
|
86
89
|
}
|
|
87
90
|
// 3) Pull the global asset by id, write it into the local recall library (put dedups → idempotent on repeat).
|
|
88
91
|
const hub = deps.hub ?? createRecipeHubFromEnv(env, deps.connectHub ?? connectPublicHub);
|
|
92
|
+
// One-shot CLIs never heartbeat, so the hub may hold no env fingerprint for this node and its anti-abuse
|
|
93
|
+
// layer then 403s /a2a/fetch (`bulk_fetch_blocked: IP antibody`, #555). A fingerprinted hello
|
|
94
|
+
// (rotate:false + preserveCredentials:true) neither requests nor applies credential mutation while establishing
|
|
95
|
+
// trust. Best-effort by design:
|
|
96
|
+
// a hello failure must not block the fetch — the fetch's own error path classifies precisely.
|
|
97
|
+
await establishReuseTrust(hub);
|
|
89
98
|
const asset = await hub.fetchAssetById(opts.id);
|
|
90
99
|
if (!asset)
|
|
91
100
|
return emit({ ok: false, status: 'not_found', message: `asset ${opts.id} not found on the hub` }, ctx);
|
|
@@ -158,18 +167,31 @@ export function parseReuseArgs(argv) {
|
|
|
158
167
|
const runId = flagValue(argv, '--run');
|
|
159
168
|
return { ok: true, value: { id, mode: modeRaw === 'direct' ? 'direct' : 'reference', ...(runId ? { runId } : {}) } };
|
|
160
169
|
}
|
|
170
|
+
// Integrity rejection is a first-class outcome, not an internal fault: the hub demonstrably rewrites
|
|
171
|
+
// delivered payloads (injected `validation`, wholesale `payload_backfill_reason` synthesis — #570), so the
|
|
172
|
+
// desktop adapter needs a typed reason to tell "this asset cannot be verified" apart from "the engine broke".
|
|
173
|
+
// Messages are fixed strings by construction (hard rule 2: nothing dynamic can reach a stream).
|
|
174
|
+
class ReuseIntegrityError extends Error {
|
|
175
|
+
}
|
|
176
|
+
const INTEGRITY_MISMATCH_MESSAGE = 'hub-delivered content does not match the asset content fingerprint';
|
|
177
|
+
const INTEGRITY_BACKFILLED_MESSAGE = 'hub delivered a synthesized payload for this asset; the original published content is unavailable for verification';
|
|
178
|
+
const INTEGRITY_LOGICAL_ID_MESSAGE = 'hub-delivered asset does not match the requested logical id';
|
|
179
|
+
function integrityError(content) {
|
|
180
|
+
const backfilled = stringField(content, 'payload_backfill_reason') !== undefined;
|
|
181
|
+
return new ReuseIntegrityError(backfilled ? INTEGRITY_BACKFILLED_MESSAGE : INTEGRITY_MISMATCH_MESSAGE);
|
|
182
|
+
}
|
|
161
183
|
async function ingestHubAsset(store, deps, asset, requestedId) {
|
|
162
|
-
const cleaned = stripHubMetadata(asset);
|
|
184
|
+
const cleaned = stripHubMetadata(unwrapHubAssetContent(asset));
|
|
163
185
|
const actualAssetId = wire.computeAssetId(cleaned);
|
|
164
186
|
const contentAssetId = stringField(cleaned, 'asset_id');
|
|
165
187
|
if (!actualAssetId || !contentAssetId || actualAssetId !== contentAssetId) {
|
|
166
|
-
throw
|
|
188
|
+
throw integrityError(cleaned);
|
|
167
189
|
}
|
|
168
190
|
if (isContentAssetId(requestedId) && actualAssetId !== requestedId) {
|
|
169
|
-
throw
|
|
191
|
+
throw integrityError(cleaned);
|
|
170
192
|
}
|
|
171
193
|
if (!isContentAssetId(requestedId) && stringField(cleaned, 'id') !== requestedId) {
|
|
172
|
-
throw new
|
|
194
|
+
throw new ReuseIntegrityError(INTEGRITY_LOGICAL_ID_MESSAGE);
|
|
173
195
|
}
|
|
174
196
|
await assertNoLocalReuseIdConflict(cleaned, store);
|
|
175
197
|
const provenance = new assetstore.ProvenanceStore(storeBaseDir(store, deps));
|
|
@@ -203,6 +225,18 @@ async function assertNoLocalReuseIdConflict(asset, store) {
|
|
|
203
225
|
if (incomingAssetId !== localAssetId)
|
|
204
226
|
throw new Error('local asset id conflict');
|
|
205
227
|
}
|
|
228
|
+
function unwrapHubAssetContent(asset) {
|
|
229
|
+
const payload = asset.payload;
|
|
230
|
+
if (payload && typeof payload === 'object' && !Array.isArray(payload) && stringField(payload, 'asset_id')) {
|
|
231
|
+
const content = payload;
|
|
232
|
+
const backfillReason = stringField(asset, 'payload_backfill_reason');
|
|
233
|
+
if (backfillReason && stringField(payload, 'payload_backfill_reason') === undefined) {
|
|
234
|
+
return { ...content, payload_backfill_reason: backfillReason };
|
|
235
|
+
}
|
|
236
|
+
return content;
|
|
237
|
+
}
|
|
238
|
+
return asset;
|
|
239
|
+
}
|
|
206
240
|
function stripHubMetadata(asset) {
|
|
207
241
|
const out = {};
|
|
208
242
|
for (const [key, value] of Object.entries(asset))
|
|
@@ -232,17 +266,51 @@ function logReuse(deps, opts, asset, source) {
|
|
|
232
266
|
extra: { source },
|
|
233
267
|
});
|
|
234
268
|
}
|
|
269
|
+
async function establishReuseTrust(hub) {
|
|
270
|
+
if (typeof hub.hello !== 'function')
|
|
271
|
+
return;
|
|
272
|
+
try {
|
|
273
|
+
await hub.hello({ rotate: false, evolverVersion: getCliVersion(), preserveCredentials: true });
|
|
274
|
+
}
|
|
275
|
+
catch { /* fetch decides the outcome */ }
|
|
276
|
+
}
|
|
277
|
+
const ANTI_ABUSE_BLOCK_MESSAGE = 'hub anti-abuse temporarily blocked asset fetch for this node; keep the local Evolver proxy running so the node builds trust, then retry';
|
|
278
|
+
function antiAbuseOutcome() {
|
|
279
|
+
return { ok: false, status: 'rate_limited', message: ANTI_ABUSE_BLOCK_MESSAGE };
|
|
280
|
+
}
|
|
281
|
+
function isAntiAbuseFetchBlock(status, code) {
|
|
282
|
+
return status === 403 && code !== undefined && /antibody|bulk_fetch|anti[-_]?abuse/i.test(code);
|
|
283
|
+
}
|
|
284
|
+
function hubErrorField(body) {
|
|
285
|
+
if (!body || typeof body !== 'object')
|
|
286
|
+
return undefined;
|
|
287
|
+
const err = body['error'];
|
|
288
|
+
return typeof err === 'string' ? err : undefined;
|
|
289
|
+
}
|
|
235
290
|
function mapError(e) {
|
|
236
|
-
if (e instanceof
|
|
291
|
+
if (e instanceof ReuseIntegrityError) {
|
|
292
|
+
return { ok: false, status: 'integrity_failed', message: e.message };
|
|
293
|
+
}
|
|
294
|
+
if (e instanceof AuthError) {
|
|
295
|
+
// hubFetch raises AuthError for BOTH 401 and 403, so the hub's anti-abuse 403
|
|
296
|
+
// (`bulk_fetch_blocked: IP antibody active`) used to be misreported as "log in" — it is an
|
|
297
|
+
// abuse-control block on a perfectly healthy credential, not an auth failure (#555).
|
|
298
|
+
if (isAntiAbuseFetchBlock(e.status, e.errorCode))
|
|
299
|
+
return antiAbuseOutcome();
|
|
237
300
|
return { ok: false, status: 'unauthorized', message: 'hub authentication failed; run `evolver login` or set EVOMAP_NODE_SECRET' };
|
|
301
|
+
}
|
|
238
302
|
if (e instanceof HubUnreachableError)
|
|
239
303
|
return { ok: false, status: 'network', message: 'hub is unreachable' };
|
|
240
304
|
if (e instanceof HubClientError) {
|
|
305
|
+
if (e.status === 429)
|
|
306
|
+
return { ok: false, status: 'rate_limited', message: 'hub rate limited the request; retry later' };
|
|
307
|
+
if (isAntiAbuseFetchBlock(e.status, hubErrorField(e.body)))
|
|
308
|
+
return antiAbuseOutcome();
|
|
241
309
|
if (e.status === 401 || e.status === 403)
|
|
242
310
|
return { ok: false, status: 'unauthorized', message: 'hub authentication failed; run `evolver login` or set EVOMAP_NODE_SECRET' };
|
|
243
311
|
if (e.status === 404)
|
|
244
312
|
return { ok: false, status: 'not_found', message: 'asset not found on the hub' };
|
|
245
|
-
if (e.status
|
|
313
|
+
if (e.status >= 500)
|
|
246
314
|
return { ok: false, status: 'network', message: 'hub is temporarily unavailable' };
|
|
247
315
|
return { ok: false, status: 'internal_error', message: 'hub rejected the reuse request' };
|
|
248
316
|
}
|