@evomap/evolver-cli 2.0.0-beta.0 → 2.0.0-beta.2
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/atp.js +4 -2
- package/dist/autoDistillLlm.js +4 -1
- package/dist/autoexec.d.ts +4 -1
- package/dist/autoexec.js +23 -5
- package/dist/cli.js +12 -5
- package/dist/cliContracts.js +8 -2
- package/dist/cliLifecycle.d.ts +7 -0
- package/dist/cliLifecycle.js +9 -0
- package/dist/cycleConsumer.d.ts +59 -1
- package/dist/cycleConsumer.js +382 -5
- package/dist/dashboard.d.ts +21 -0
- package/dist/dashboard.js +173 -0
- package/dist/dispatch.d.ts +1 -0
- package/dist/dispatch.js +27 -2
- package/dist/distillObserver.js +2 -2
- package/dist/distillPrimitives.d.ts +1 -1
- package/dist/distillPrimitives.js +29 -2
- package/dist/doctor.js +15 -3
- package/dist/index.d.ts +6 -1
- package/dist/index.js +251 -30
- package/dist/lifecycle.js +6 -2
- package/dist/login.d.ts +20 -4
- package/dist/login.js +58 -8
- package/dist/materialPackage.d.ts +52 -0
- package/dist/materialPackage.js +404 -0
- package/dist/materialSnapshot.d.ts +30 -0
- package/dist/materialSnapshot.js +148 -0
- package/dist/memoryEventMirror.d.ts +23 -0
- package/dist/memoryEventMirror.js +140 -0
- package/dist/migrate/fieldMap.js +25 -0
- 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 +10 -2
- package/dist/recipe.js +349 -7
- package/dist/reuseReport.js +16 -16
- package/dist/runtimeSessionSource.d.ts +10 -0
- package/dist/runtimeSessionSource.js +32 -5
- package/dist/setupHooks.d.ts +6 -1
- package/dist/setupHooks.js +5 -2
- 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 +26 -0
- package/dist/sync.js +988 -0
- package/dist/trajectoryExport.js +23 -12
- package/dist/v1Compat.d.ts +24 -0
- package/dist/v1Compat.js +249 -0
- package/dist/version.js +2 -0
- package/package.json +8 -6
package/dist/recipe.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { existsSync, mkdirSync, readFileSync, unlinkSync, writeFileSync } from 'node:fs';
|
|
2
2
|
import { homedir } from 'node:os';
|
|
3
|
-
import { join } from 'node:path';
|
|
3
|
+
import { dirname, isAbsolute, join, resolve } from 'node:path';
|
|
4
4
|
import { assetstore, events, mailbox } from '@evomap/evolver-core';
|
|
5
|
-
import { AuthError, HubClientError, HubUnreachableError, connectPublicHub, isHubDryRunEnabled, isNodeSecret, parseNodeSecretVersion } from '@evomap/evolver-adapter-public';
|
|
5
|
+
import { AuthError, HubClientError, HubUnreachableError, connectPublicHub, isHubDryRunEnabled, isNodeSecret, parseNodeSecretVersion, resolveHubUrl } from '@evomap/evolver-adapter-public';
|
|
6
|
+
import { loadEnvFileFromEnv } from '@evomap/evolver-mcp';
|
|
6
7
|
import { resolveAtpSenderId } from './atp.js';
|
|
8
|
+
import { parseSkillMd, reverseDistill } from './skill2gep.js';
|
|
9
|
+
import { recordSkillDistillation } from './skillDistill.js';
|
|
7
10
|
const MAX_RECIPE_STEPS = 20;
|
|
8
11
|
const MAX_ID_LENGTH = 200;
|
|
9
|
-
const DEFAULT_PUBLIC_HUB_URL = 'https://evomap.ai';
|
|
10
12
|
const SENSITIVE_ERROR_KEYS = new Set(['authorization', 'node_secret', 'nodesecret', 'token', 'access_token', 'refresh_token', 'secret']);
|
|
11
13
|
const STALE_NODE_SECRET_ERRORS = new Set(['node_secret_invalid', 'node_secret_not_set']);
|
|
12
14
|
export async function runRecipeCommand(argv, deps = {}) {
|
|
@@ -22,6 +24,8 @@ export async function runRecipeCommand(argv, deps = {}) {
|
|
|
22
24
|
if (isHubDryRunEnabled(env)) {
|
|
23
25
|
if (parsed.value.sub === 'build')
|
|
24
26
|
return await runRecipeBuildDryRun(parsed.value, deps.store, { log, err });
|
|
27
|
+
if (parsed.value.sub === 'from-skills')
|
|
28
|
+
return await runRecipeFromSkills(parsed.value, undefined, deps, { log, err }, true);
|
|
25
29
|
return runRecipeReuseDryRun(parsed.value, { log });
|
|
26
30
|
}
|
|
27
31
|
const hub = deps.hub ?? createRecipeHubFromEnv(env, deps.connectHub ?? connectPublicHub);
|
|
@@ -31,6 +35,8 @@ export async function runRecipeCommand(argv, deps = {}) {
|
|
|
31
35
|
}
|
|
32
36
|
if (parsed.value.sub === 'build')
|
|
33
37
|
return await runRecipeBuild(parsed.value, hub, deps.store, { log, err });
|
|
38
|
+
if (parsed.value.sub === 'from-skills')
|
|
39
|
+
return await runRecipeFromSkills(parsed.value, hub, deps, { log, err }, false);
|
|
34
40
|
return await runRecipeReuse(parsed.value, hub, { log, err });
|
|
35
41
|
}
|
|
36
42
|
catch (e) {
|
|
@@ -67,6 +73,7 @@ function runRecipeReuseDryRun(opts, io) {
|
|
|
67
73
|
return 0;
|
|
68
74
|
}
|
|
69
75
|
export function createRecipeHubFromEnv(env = process.env, connectHub = connectPublicHub) {
|
|
76
|
+
loadEnvFileFromEnv(env);
|
|
70
77
|
const hubUrl = resolveRecipeHubUrl(env);
|
|
71
78
|
const credentials = resolveRecipeHubCredentials(env);
|
|
72
79
|
if (!credentials.nodeSecret && !existsSync(join(credentials.evomapDir, 'token.json'))) {
|
|
@@ -90,16 +97,17 @@ export function createRecipeHubFromEnv(env = process.env, connectHub = connectPu
|
|
|
90
97
|
return connected.hub;
|
|
91
98
|
}
|
|
92
99
|
function resolveRecipeHubUrl(env) {
|
|
93
|
-
|
|
94
|
-
return hubUrl;
|
|
100
|
+
return resolveHubUrl(env);
|
|
95
101
|
}
|
|
96
102
|
export function parseRecipeArgs(argv) {
|
|
97
103
|
const sub = argv[0];
|
|
98
|
-
if (sub !== 'build' && sub !== 'reuse')
|
|
99
|
-
return { ok: false, error: 'recipe subcommand must be build|reuse' };
|
|
104
|
+
if (sub !== 'build' && sub !== 'reuse' && sub !== 'from-skills')
|
|
105
|
+
return { ok: false, error: 'recipe subcommand must be build|reuse|from-skills' };
|
|
100
106
|
const args = argv.slice(1);
|
|
101
107
|
if (sub === 'build')
|
|
102
108
|
return parseBuildArgs(args);
|
|
109
|
+
if (sub === 'from-skills')
|
|
110
|
+
return parseFromSkillsArgs(args);
|
|
103
111
|
return parseReuseArgs(args);
|
|
104
112
|
}
|
|
105
113
|
async function runRecipeBuild(opts, hub, store, io) {
|
|
@@ -129,6 +137,132 @@ async function runRecipeBuild(opts, hub, store, io) {
|
|
|
129
137
|
}
|
|
130
138
|
return 0;
|
|
131
139
|
}
|
|
140
|
+
async function runRecipeFromSkills(opts, hub, deps, io, dryRun) {
|
|
141
|
+
const loaded = loadRecipeFromSkillsManifest(opts.manifestPath);
|
|
142
|
+
if (!loaded.ok) {
|
|
143
|
+
io.err(loaded.error);
|
|
144
|
+
return 1;
|
|
145
|
+
}
|
|
146
|
+
const preflight = preflightRecipeFromSkillsSteps(loaded.value.steps);
|
|
147
|
+
if (!preflight.ok) {
|
|
148
|
+
io.err(preflight.error);
|
|
149
|
+
return 1;
|
|
150
|
+
}
|
|
151
|
+
const store = deps.store ?? new assetstore.LocalJsonlProvider(events.assetsDir());
|
|
152
|
+
const ingestor = deps.ingestor ?? new events.Ingestor({ path: events.rootEventsPath() });
|
|
153
|
+
const steps = [];
|
|
154
|
+
const distilled = [];
|
|
155
|
+
for (const prepared of preflight.value) {
|
|
156
|
+
const existing = await findReusableRecipeStep(store, prepared);
|
|
157
|
+
if (existing) {
|
|
158
|
+
addRecipeFromSkillsStep(steps, distilled, existing);
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
161
|
+
const step = prepared.step;
|
|
162
|
+
const res = await recordSkillDistillation(step.skill, step.execution, {
|
|
163
|
+
store,
|
|
164
|
+
...(deps.review ? { review: deps.review } : {}),
|
|
165
|
+
ingestor,
|
|
166
|
+
}, step.scenario ? { scenario: step.scenario } : {});
|
|
167
|
+
if (!res.geneId || !res.geneAssetId) {
|
|
168
|
+
const recovered = await findReusableRecipeStep(store, prepared);
|
|
169
|
+
if (recovered) {
|
|
170
|
+
addRecipeFromSkillsStep(steps, distilled, recovered);
|
|
171
|
+
continue;
|
|
172
|
+
}
|
|
173
|
+
io.err(`recipe from-skills step ${prepared.position + 1} did not produce a Gene: ${res.errors.join('; ') || 'refused'}`);
|
|
174
|
+
return 1;
|
|
175
|
+
}
|
|
176
|
+
if (!res.capsuleId) {
|
|
177
|
+
io.err(`recipe from-skills step ${prepared.position + 1} missing Capsule evidence: ${res.capsuleDiagnostic ?? 'missing_capsule_evidence'}`);
|
|
178
|
+
return 1;
|
|
179
|
+
}
|
|
180
|
+
if (!(await hasCapsuleEvidence(store, res.capsuleId, res.geneId))) {
|
|
181
|
+
io.err(`recipe from-skills step ${prepared.position + 1} missing persisted Capsule evidence`);
|
|
182
|
+
return 1;
|
|
183
|
+
}
|
|
184
|
+
addRecipeFromSkillsStep(steps, distilled, {
|
|
185
|
+
position: prepared.position,
|
|
186
|
+
geneId: res.geneId,
|
|
187
|
+
geneAssetId: res.geneAssetId,
|
|
188
|
+
capsuleId: res.capsuleId,
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
if (dryRun) {
|
|
192
|
+
const payload = recipeFromSkillsPayload({
|
|
193
|
+
mode: 'dry_run',
|
|
194
|
+
title: loaded.value.title,
|
|
195
|
+
publish: opts.publish,
|
|
196
|
+
steps: distilled,
|
|
197
|
+
});
|
|
198
|
+
if (opts.jsonOut)
|
|
199
|
+
io.log(JSON.stringify(payload, null, 2));
|
|
200
|
+
else {
|
|
201
|
+
io.log(`[recipe from-skills] dry-run: would create DRAFT recipe ("${loaded.value.title}", ${steps.length} step${steps.length === 1 ? '' : 's'}).`);
|
|
202
|
+
if (opts.publish)
|
|
203
|
+
io.log('[recipe from-skills] dry-run: would publish the recipe after creation.');
|
|
204
|
+
else
|
|
205
|
+
io.log('[recipe from-skills] dry-run: would leave the recipe as draft.');
|
|
206
|
+
}
|
|
207
|
+
return 0;
|
|
208
|
+
}
|
|
209
|
+
if (!hub?.recipes) {
|
|
210
|
+
io.err('recipe capability is not available for the configured Hub adapter');
|
|
211
|
+
return 1;
|
|
212
|
+
}
|
|
213
|
+
const createReceipt = await callRecipeWithAuthRetry(hub, 'recipe from-skills', () => hub.recipes.create({
|
|
214
|
+
title: loaded.value.title,
|
|
215
|
+
steps,
|
|
216
|
+
...(loaded.value.description ? { description: loaded.value.description } : {}),
|
|
217
|
+
...(loaded.value.pricePerExecution !== undefined ? { pricePerExecution: loaded.value.pricePerExecution } : {}),
|
|
218
|
+
}), io);
|
|
219
|
+
const recipeId = createReceipt.recipeId;
|
|
220
|
+
if (!opts.jsonOut) {
|
|
221
|
+
io.log(`[recipe from-skills] Created DRAFT recipe ${recipeId ?? '(id pending)'} ("${loaded.value.title}", ${steps.length} step${steps.length === 1 ? '' : 's'}).`);
|
|
222
|
+
}
|
|
223
|
+
if (opts.publish) {
|
|
224
|
+
if (!recipeId) {
|
|
225
|
+
io.err('[recipe from-skills] Hub did not return a recipe id; cannot publish.');
|
|
226
|
+
return 1;
|
|
227
|
+
}
|
|
228
|
+
try {
|
|
229
|
+
await callRecipeWithAuthRetry(hub, 'recipe from-skills', () => hub.recipes.publish(recipeId), io);
|
|
230
|
+
}
|
|
231
|
+
catch (e) {
|
|
232
|
+
if (opts.jsonOut) {
|
|
233
|
+
io.log(JSON.stringify(recipeFromSkillsPayload({
|
|
234
|
+
ok: false,
|
|
235
|
+
mode: 'draft',
|
|
236
|
+
title: loaded.value.title,
|
|
237
|
+
publish: opts.publish,
|
|
238
|
+
steps: distilled,
|
|
239
|
+
recipeId,
|
|
240
|
+
error: 'publish_failed',
|
|
241
|
+
}), null, 2));
|
|
242
|
+
}
|
|
243
|
+
else {
|
|
244
|
+
io.err(`[recipe from-skills] Created DRAFT recipe ${recipeId}; publish failed before it was made live.`);
|
|
245
|
+
}
|
|
246
|
+
throw e;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
const payload = recipeFromSkillsPayload({
|
|
250
|
+
mode: opts.publish ? 'published' : 'draft',
|
|
251
|
+
title: loaded.value.title,
|
|
252
|
+
publish: opts.publish,
|
|
253
|
+
steps: distilled,
|
|
254
|
+
recipeId,
|
|
255
|
+
});
|
|
256
|
+
if (opts.jsonOut)
|
|
257
|
+
io.log(JSON.stringify(payload, null, 2));
|
|
258
|
+
else {
|
|
259
|
+
if (opts.publish)
|
|
260
|
+
io.log(`[recipe from-skills] Published recipe ${recipeId}.`);
|
|
261
|
+
else
|
|
262
|
+
io.log('[recipe from-skills] Left as draft. Re-run with --publish to make it live.');
|
|
263
|
+
}
|
|
264
|
+
return 0;
|
|
265
|
+
}
|
|
132
266
|
async function runRecipeReuse(opts, hub, io) {
|
|
133
267
|
await callRecipeWithAuthRetry(hub, 'recipe reuse', () => hub.recipes.get(opts.recipeId), io);
|
|
134
268
|
const receipt = await callRecipeWithAuthRetry(hub, 'recipe reuse', () => hub.recipes.express(opts.recipeId, { inputPayload: opts.inputPayload }), io);
|
|
@@ -150,6 +284,198 @@ async function recipeStepsFromLocalAssets(assetIds, store) {
|
|
|
150
284
|
return { assetId, assetType, position: index };
|
|
151
285
|
});
|
|
152
286
|
}
|
|
287
|
+
function preflightRecipeFromSkillsSteps(steps) {
|
|
288
|
+
const prepared = [];
|
|
289
|
+
for (let i = 0; i < steps.length; i += 1) {
|
|
290
|
+
const step = steps[i];
|
|
291
|
+
const parsed = parseSkillMd(step.skill);
|
|
292
|
+
const preview = reverseDistill(parsed, step.execution, step.scenario ? { scenario: step.scenario } : {});
|
|
293
|
+
if (!preview.gene) {
|
|
294
|
+
return {
|
|
295
|
+
ok: false,
|
|
296
|
+
error: `recipe from-skills step ${i + 1} did not produce a Gene: ${preview.errors.join('; ') || 'refused'}`,
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
if (!preview.capsule) {
|
|
300
|
+
const diag = preview.capsuleDiagnostic
|
|
301
|
+
? (preview.capsuleDiagnostic.detail ?? preview.capsuleDiagnostic.reason)
|
|
302
|
+
: 'missing_capsule_evidence';
|
|
303
|
+
return {
|
|
304
|
+
ok: false,
|
|
305
|
+
error: `recipe from-skills step ${i + 1} missing Capsule evidence: ${diag}`,
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
prepared.push({
|
|
309
|
+
position: i,
|
|
310
|
+
step,
|
|
311
|
+
candidateSignals: normalizedSignalList(preview.gene.signals_match),
|
|
312
|
+
candidateCapsuleId: preview.capsule.id,
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
return { ok: true, value: prepared };
|
|
316
|
+
}
|
|
317
|
+
async function findReusableRecipeStep(store, prepared) {
|
|
318
|
+
const candidateSignals = prepared.candidateSignals;
|
|
319
|
+
if (candidateSignals.length === 0)
|
|
320
|
+
return null;
|
|
321
|
+
const genes = await store.list('Gene', 10_000);
|
|
322
|
+
const capsules = await store.list('Capsule', 10_000);
|
|
323
|
+
for (const gene of genes) {
|
|
324
|
+
const signals = new Set(normalizedSignalList(gene['signals_match']));
|
|
325
|
+
if (!candidateSignals.every((signal) => signals.has(signal)))
|
|
326
|
+
continue;
|
|
327
|
+
const geneId = typeof gene['id'] === 'string' && gene['id'].trim()
|
|
328
|
+
? gene['id'].trim()
|
|
329
|
+
: String(gene['asset_id'] ?? '');
|
|
330
|
+
const geneAssetId = typeof gene['asset_id'] === 'string' ? gene['asset_id'] : '';
|
|
331
|
+
if (!geneId || !geneAssetId)
|
|
332
|
+
continue;
|
|
333
|
+
const capsule = capsules.find((record) => String(record['id']) === prepared.candidateCapsuleId &&
|
|
334
|
+
String(record['gene']) === geneId);
|
|
335
|
+
if (!capsule)
|
|
336
|
+
continue;
|
|
337
|
+
return {
|
|
338
|
+
position: prepared.position,
|
|
339
|
+
geneId,
|
|
340
|
+
geneAssetId,
|
|
341
|
+
capsuleId: String(capsule['id']),
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
return null;
|
|
345
|
+
}
|
|
346
|
+
function addRecipeFromSkillsStep(steps, distilled, result) {
|
|
347
|
+
steps.push({ assetId: result.geneAssetId, assetType: 'Gene', position: result.position });
|
|
348
|
+
distilled.push(result);
|
|
349
|
+
}
|
|
350
|
+
async function hasCapsuleEvidence(store, capsuleId, geneId) {
|
|
351
|
+
const capsules = await store.list('Capsule', 10_000);
|
|
352
|
+
return capsules.some((capsule) => String(capsule['id']) === capsuleId &&
|
|
353
|
+
String(capsule['gene']) === geneId);
|
|
354
|
+
}
|
|
355
|
+
function normalizedSignalList(value) {
|
|
356
|
+
return Array.isArray(value)
|
|
357
|
+
? value.map((item) => String(item).trim().toLowerCase()).filter(Boolean)
|
|
358
|
+
: [];
|
|
359
|
+
}
|
|
360
|
+
function loadRecipeFromSkillsManifest(path) {
|
|
361
|
+
let raw;
|
|
362
|
+
const manifestPath = resolve(path);
|
|
363
|
+
try {
|
|
364
|
+
raw = readFileSync(manifestPath, 'utf8');
|
|
365
|
+
}
|
|
366
|
+
catch {
|
|
367
|
+
return { ok: false, error: 'recipe from-skills cannot read --manifest file' };
|
|
368
|
+
}
|
|
369
|
+
let parsed;
|
|
370
|
+
try {
|
|
371
|
+
parsed = JSON.parse(raw);
|
|
372
|
+
}
|
|
373
|
+
catch {
|
|
374
|
+
return { ok: false, error: 'recipe from-skills --manifest must be valid JSON' };
|
|
375
|
+
}
|
|
376
|
+
if (!isPlainRecord(parsed))
|
|
377
|
+
return { ok: false, error: 'recipe from-skills --manifest must be a JSON object' };
|
|
378
|
+
const title = typeof parsed['title'] === 'string' ? parsed['title'].trim() : '';
|
|
379
|
+
if (!title)
|
|
380
|
+
return { ok: false, error: 'recipe from-skills manifest requires title' };
|
|
381
|
+
const rawSteps = parsed['steps'];
|
|
382
|
+
if (!Array.isArray(rawSteps) || rawSteps.length === 0)
|
|
383
|
+
return { ok: false, error: 'recipe from-skills manifest requires non-empty steps[]' };
|
|
384
|
+
if (rawSteps.length > MAX_RECIPE_STEPS)
|
|
385
|
+
return { ok: false, error: `recipe from-skills supports at most ${MAX_RECIPE_STEPS} steps` };
|
|
386
|
+
const priceRaw = parsed['pricePerExecution'];
|
|
387
|
+
if (priceRaw === null)
|
|
388
|
+
return { ok: false, error: 'recipe from-skills pricePerExecution must be a non-negative number' };
|
|
389
|
+
const price = priceRaw === undefined ? undefined : Number(priceRaw);
|
|
390
|
+
if (price !== undefined && (!Number.isFinite(price) || price < 0))
|
|
391
|
+
return { ok: false, error: 'recipe from-skills pricePerExecution must be a non-negative number' };
|
|
392
|
+
const baseDir = dirname(manifestPath);
|
|
393
|
+
const steps = [];
|
|
394
|
+
for (let i = 0; i < rawSteps.length; i += 1) {
|
|
395
|
+
const rawStep = rawSteps[i];
|
|
396
|
+
if (!isPlainRecord(rawStep))
|
|
397
|
+
return { ok: false, error: `recipe from-skills step ${i + 1} must be a JSON object` };
|
|
398
|
+
const skillRef = typeof rawStep['skill'] === 'string' ? rawStep['skill'].trim() : '';
|
|
399
|
+
if (!skillRef)
|
|
400
|
+
return { ok: false, error: `recipe from-skills step ${i + 1} requires skill` };
|
|
401
|
+
let skill;
|
|
402
|
+
try {
|
|
403
|
+
skill = readFileSync(resolveManifestRef(baseDir, skillRef), 'utf8');
|
|
404
|
+
}
|
|
405
|
+
catch {
|
|
406
|
+
return { ok: false, error: `recipe from-skills step ${i + 1} cannot read skill` };
|
|
407
|
+
}
|
|
408
|
+
const execution = loadSkillExecution(rawStep['execution'], baseDir, i + 1);
|
|
409
|
+
if (!execution.ok)
|
|
410
|
+
return execution;
|
|
411
|
+
const scenario = typeof rawStep['scenario'] === 'string' && rawStep['scenario'].trim()
|
|
412
|
+
? rawStep['scenario'].trim()
|
|
413
|
+
: undefined;
|
|
414
|
+
steps.push({
|
|
415
|
+
skill,
|
|
416
|
+
execution: execution.value,
|
|
417
|
+
...(scenario ? { scenario } : {}),
|
|
418
|
+
});
|
|
419
|
+
}
|
|
420
|
+
const description = typeof parsed['description'] === 'string' && parsed['description'].trim()
|
|
421
|
+
? parsed['description'].trim()
|
|
422
|
+
: undefined;
|
|
423
|
+
return {
|
|
424
|
+
ok: true,
|
|
425
|
+
value: {
|
|
426
|
+
title,
|
|
427
|
+
...(description ? { description } : {}),
|
|
428
|
+
...(price !== undefined ? { pricePerExecution: price } : {}),
|
|
429
|
+
steps,
|
|
430
|
+
},
|
|
431
|
+
};
|
|
432
|
+
}
|
|
433
|
+
function loadSkillExecution(raw, baseDir, stepNumber) {
|
|
434
|
+
if (typeof raw === 'string' && raw.trim()) {
|
|
435
|
+
let text;
|
|
436
|
+
try {
|
|
437
|
+
text = readFileSync(resolveManifestRef(baseDir, raw.trim()), 'utf8');
|
|
438
|
+
}
|
|
439
|
+
catch {
|
|
440
|
+
return { ok: false, error: `recipe from-skills step ${stepNumber} cannot read execution` };
|
|
441
|
+
}
|
|
442
|
+
try {
|
|
443
|
+
const parsed = JSON.parse(text);
|
|
444
|
+
if (isPlainRecord(parsed))
|
|
445
|
+
return { ok: true, value: parsed };
|
|
446
|
+
return { ok: false, error: `recipe from-skills step ${stepNumber} execution must be a JSON object` };
|
|
447
|
+
}
|
|
448
|
+
catch {
|
|
449
|
+
return { ok: false, error: `recipe from-skills step ${stepNumber} execution must be valid JSON` };
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
if (isPlainRecord(raw))
|
|
453
|
+
return { ok: true, value: raw };
|
|
454
|
+
return { ok: false, error: `recipe from-skills step ${stepNumber} requires execution evidence` };
|
|
455
|
+
}
|
|
456
|
+
function resolveManifestRef(baseDir, ref) {
|
|
457
|
+
return isAbsolute(ref) ? ref : resolve(baseDir, ref);
|
|
458
|
+
}
|
|
459
|
+
function isPlainRecord(value) {
|
|
460
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
461
|
+
}
|
|
462
|
+
function recipeFromSkillsPayload(opts) {
|
|
463
|
+
return {
|
|
464
|
+
ok: opts.ok ?? true,
|
|
465
|
+
group: 'recipe.from_skills',
|
|
466
|
+
mode: opts.mode,
|
|
467
|
+
title: opts.title,
|
|
468
|
+
...(opts.recipeId ? { recipeId: opts.recipeId } : {}),
|
|
469
|
+
...(opts.error ? { error: opts.error } : {}),
|
|
470
|
+
publish: opts.publish,
|
|
471
|
+
steps: opts.steps.map((step) => ({
|
|
472
|
+
position: step.position,
|
|
473
|
+
geneId: step.geneId,
|
|
474
|
+
geneAssetId: step.geneAssetId,
|
|
475
|
+
capsuleId: step.capsuleId,
|
|
476
|
+
})),
|
|
477
|
+
};
|
|
478
|
+
}
|
|
153
479
|
async function callRecipeWithAuthRetry(hub, tag, fn, io) {
|
|
154
480
|
try {
|
|
155
481
|
return await fn();
|
|
@@ -198,6 +524,20 @@ function parseBuildArgs(args) {
|
|
|
198
524
|
},
|
|
199
525
|
};
|
|
200
526
|
}
|
|
527
|
+
function parseFromSkillsArgs(args) {
|
|
528
|
+
const manifestPath = flagValue(args, '--manifest');
|
|
529
|
+
if (!manifestPath)
|
|
530
|
+
return { ok: false, error: 'recipe from-skills requires --manifest <file>' };
|
|
531
|
+
return {
|
|
532
|
+
ok: true,
|
|
533
|
+
value: {
|
|
534
|
+
sub: 'from-skills',
|
|
535
|
+
manifestPath,
|
|
536
|
+
publish: args.includes('--publish'),
|
|
537
|
+
jsonOut: args.includes('--json'),
|
|
538
|
+
},
|
|
539
|
+
};
|
|
540
|
+
}
|
|
201
541
|
function parseReuseArgs(args) {
|
|
202
542
|
const recipeId = flagValue(args, '--id') ?? firstPositional(args);
|
|
203
543
|
if (!recipeId)
|
|
@@ -559,6 +899,8 @@ function recipeUsage() {
|
|
|
559
899
|
'Recipe subcommands:',
|
|
560
900
|
' evolver recipe build --title <title> --genes <asset_id,...> [--description <text>] [--price <n>] [--publish]',
|
|
561
901
|
' Creates a draft recipe by default. --publish is explicit.',
|
|
902
|
+
' evolver recipe from-skills --manifest <file> [--publish] [--json]',
|
|
903
|
+
' Distills ordered SKILL.md steps with execution evidence, then creates a recipe.',
|
|
562
904
|
' evolver recipe reuse --id <recipe_id> [--input <json-object>] [--json]',
|
|
563
905
|
].join('\n');
|
|
564
906
|
}
|
package/dist/reuseReport.js
CHANGED
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
// `--anti-gene` is the read-only operator view for #326: it surfaces local AntiGene assets, review state, shadow
|
|
17
17
|
// observations, and whether approved warnings have actually appeared in selection decisions.
|
|
18
18
|
import { events, ops, assetstore, algo } from '@evomap/evolver-core';
|
|
19
|
+
import { formatAntiGeneEvidenceAction, formatAntiGeneEvidenceSummary, summarizeAntiGeneEvidence } from './antiGeneEvidence.js';
|
|
19
20
|
function parseFlags(argv) {
|
|
20
21
|
let quarantine = false, promote = false, antiGene = false, minNegative = 3, minUnsafe = 1;
|
|
21
22
|
for (let i = 0; i < argv.length; i++) {
|
|
@@ -70,7 +71,7 @@ async function reportProbation(deps, log) {
|
|
|
70
71
|
return 0;
|
|
71
72
|
}
|
|
72
73
|
function reviewState(review, assetId) {
|
|
73
|
-
return reviewRecord(review, assetId)?.state ?? '
|
|
74
|
+
return reviewRecord(review, assetId)?.state ?? 'unreviewed';
|
|
74
75
|
}
|
|
75
76
|
function reviewRecord(review, assetId) {
|
|
76
77
|
return review?.get?.(assetId) ?? null;
|
|
@@ -81,12 +82,6 @@ function stringArray(value) {
|
|
|
81
82
|
function optionalString(value) {
|
|
82
83
|
return typeof value === 'string' && value.trim().length > 0 ? value.trim() : undefined;
|
|
83
84
|
}
|
|
84
|
-
function countLabel(value) {
|
|
85
|
-
return Array.isArray(value) ? String(value.length) : '0';
|
|
86
|
-
}
|
|
87
|
-
function numberLabel(value) {
|
|
88
|
-
return typeof value === 'number' && Number.isFinite(value) ? String(value) : '-';
|
|
89
|
-
}
|
|
90
85
|
function reviewAuditLabel(record) {
|
|
91
86
|
if (!record)
|
|
92
87
|
return '';
|
|
@@ -146,26 +141,31 @@ async function reportAntiGenes(deps, log) {
|
|
|
146
141
|
log('anti-gene: no AntiGene assets or shadow observations recorded yet.');
|
|
147
142
|
return 0;
|
|
148
143
|
}
|
|
149
|
-
const counts = { approved: 0, quarantined: 0, rejected: 0 };
|
|
144
|
+
const counts = { approved: 0, quarantined: 0, rejected: 0, unreviewed: 0 };
|
|
150
145
|
for (const asset of assets)
|
|
151
146
|
counts[reviewState(review, String(asset.asset_id))] += 1;
|
|
152
|
-
log(`anti-gene: ${assets.length} stored asset(s); review approved=${counts.approved} quarantined=${counts.quarantined} rejected=${counts.rejected}; shadow candidate=${shadowCandidates.length} declined=${shadowDeclines.length}`);
|
|
147
|
+
log(`anti-gene: ${assets.length} stored asset(s); review approved=${counts.approved} quarantined=${counts.quarantined} rejected=${counts.rejected} unreviewed=${counts.unreviewed}; shadow candidate=${shadowCandidates.length} declined=${shadowDeclines.length}`);
|
|
153
148
|
for (const asset of assets) {
|
|
154
149
|
const assetId = String(asset.asset_id);
|
|
155
150
|
const id = typeof asset['id'] === 'string' ? String(asset['id']) : assetId;
|
|
156
151
|
const record = reviewRecord(review, assetId);
|
|
157
|
-
const state = record?.state ?? '
|
|
152
|
+
const state = record?.state ?? 'unreviewed';
|
|
158
153
|
const severity = optionalString(asset['severity']) ?? '-';
|
|
159
154
|
const trigger = stringArray(asset['trigger']).slice(0, 6).join(',');
|
|
160
155
|
const avoid = stringArray(asset['avoid']).slice(0, 2).join(' | ');
|
|
161
|
-
const evidence = `failures=${numberLabel(asset['failure_count'])} clusters=${countLabel(asset['source_clusters'])} evidence=${countLabel(asset['evidence_capsules'])}`;
|
|
162
156
|
const audit = reviewAuditLabel(record);
|
|
163
157
|
const injected = (injectedCounts.get(id) ?? 0) + (id === assetId ? 0 : injectedCounts.get(assetId) ?? 0);
|
|
164
|
-
const
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
158
|
+
const evidenceSummary = summarizeAntiGeneEvidence(asset, injected);
|
|
159
|
+
const evidence = `${formatAntiGeneEvidenceSummary(evidenceSummary)} ${formatAntiGeneEvidenceAction(evidenceSummary, state)}`;
|
|
160
|
+
const next = state === 'unreviewed' && injected > 0
|
|
161
|
+
? `observed historically in ${injected} decision(s); explicit approval required`
|
|
162
|
+
: state === 'quarantined' || state === 'unreviewed'
|
|
163
|
+
? evidenceSummary.strength === 'weak'
|
|
164
|
+
? `reject/defer, or approve with evolver review --approve ${id} --allow-weak-evidence before warning injection`
|
|
165
|
+
: 'approve with evolver review --approve before warning injection'
|
|
166
|
+
: state === 'approved'
|
|
167
|
+
? (injected > 0 ? `observed in ${injected} decision(s)` : 'approved; waiting for matching selection')
|
|
168
|
+
: 'rejected; withheld from warning injection';
|
|
169
169
|
log(` ${id} {${state}} severity=${severity} trigger=${trigger || '-'} avoid=${avoid || '-'} ${evidence}${audit ? ` ${audit}` : ''} ${next}`);
|
|
170
170
|
}
|
|
171
171
|
if (shadowCandidates.length > 0 || shadowDeclines.length > 0) {
|
|
@@ -5,5 +5,15 @@ export interface RuntimeSessionSource {
|
|
|
5
5
|
sessionId?: string;
|
|
6
6
|
turns: NormalizedTurn[];
|
|
7
7
|
}
|
|
8
|
+
export interface RuntimeSessionParseDiagnostics {
|
|
9
|
+
rowsScanned: number;
|
|
10
|
+
rowsRead: number;
|
|
11
|
+
invalidJson: number;
|
|
12
|
+
}
|
|
13
|
+
export interface RuntimeSessionParseResult {
|
|
14
|
+
sources: RuntimeSessionSource[];
|
|
15
|
+
diagnostics: RuntimeSessionParseDiagnostics;
|
|
16
|
+
}
|
|
8
17
|
export declare function isRuntimeSessionSourcePath(path: string): boolean;
|
|
18
|
+
export declare function parseRuntimeSessionSourcesWithDiagnostics(path: string, readSource?: (path: string) => string): RuntimeSessionParseResult;
|
|
9
19
|
export declare function parseRuntimeSessionSources(path: string, readSource?: (path: string) => string): RuntimeSessionSource[];
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { readFileSync } from 'node:fs';
|
|
2
2
|
import { resolve } from 'node:path';
|
|
3
|
-
import { adapterForPath, isCursorStateVscdbPath, parseCursorStateVscdb, } from '@evomap/evolver-runtime-adapters';
|
|
3
|
+
import { adapterForPath, isCursorStateVscdbPath, parseJsonlLinesWithStats, parseCursorStateVscdb, stripUtf8Bom, } from '@evomap/evolver-runtime-adapters';
|
|
4
|
+
const EMPTY_DIAGNOSTICS = { rowsScanned: 0, rowsRead: 0, invalidJson: 0 };
|
|
4
5
|
export function isRuntimeSessionSourcePath(path) {
|
|
5
6
|
return isCursorStateVscdbPath(path) || adapterForPath(path) !== undefined;
|
|
6
7
|
}
|
|
@@ -15,15 +16,41 @@ function cursorSourceFromSession(session, index) {
|
|
|
15
16
|
turns: session.turns,
|
|
16
17
|
};
|
|
17
18
|
}
|
|
18
|
-
|
|
19
|
+
function diagnosticsForRuntimeSource(raw) {
|
|
20
|
+
const trimmed = stripUtf8Bom(raw).trim();
|
|
21
|
+
if (!trimmed)
|
|
22
|
+
return { ...EMPTY_DIAGNOSTICS };
|
|
23
|
+
try {
|
|
24
|
+
JSON.parse(trimmed);
|
|
25
|
+
return { rowsScanned: 1, rowsRead: 1, invalidJson: 0 };
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
return parseJsonlLinesWithStats(raw).stats;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
export function parseRuntimeSessionSourcesWithDiagnostics(path, readSource = (p) => readFileSync(p, 'utf8')) {
|
|
19
32
|
const absPath = resolve(path);
|
|
20
33
|
if (isCursorStateVscdbPath(absPath)) {
|
|
21
|
-
|
|
34
|
+
const sources = parseCursorStateVscdb(absPath)
|
|
22
35
|
.map(cursorSourceFromSession)
|
|
23
36
|
.filter((source) => source !== null);
|
|
37
|
+
return { sources, diagnostics: { ...EMPTY_DIAGNOSTICS } };
|
|
24
38
|
}
|
|
25
39
|
const adapter = adapterForPath(absPath);
|
|
26
40
|
if (!adapter)
|
|
27
|
-
return [];
|
|
28
|
-
|
|
41
|
+
return { sources: [], diagnostics: { ...EMPTY_DIAGNOSTICS } };
|
|
42
|
+
const raw = readSource(absPath);
|
|
43
|
+
const sessionId = adapter.sessionIdFromPath?.(absPath)?.trim();
|
|
44
|
+
return {
|
|
45
|
+
sources: [{
|
|
46
|
+
agent: adapter.agent,
|
|
47
|
+
label: sessionId ? `${adapter.agent}:${sessionId}` : adapter.agent,
|
|
48
|
+
...(sessionId ? { sessionId } : {}),
|
|
49
|
+
turns: adapter.parse(raw),
|
|
50
|
+
}],
|
|
51
|
+
diagnostics: diagnosticsForRuntimeSource(raw),
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
export function parseRuntimeSessionSources(path, readSource = (p) => readFileSync(p, 'utf8')) {
|
|
55
|
+
return parseRuntimeSessionSourcesWithDiagnostics(path, readSource).sources;
|
|
29
56
|
}
|
package/dist/setupHooks.d.ts
CHANGED
|
@@ -1,2 +1,7 @@
|
|
|
1
1
|
import { assetstore } from '@evomap/evolver-core';
|
|
2
|
-
|
|
2
|
+
import { maybeEmitNonGitWorkspaceNotice } from './nonGitWorkspaceNotice.js';
|
|
3
|
+
interface SetupHooksDeps {
|
|
4
|
+
emitNonGitWorkspaceNotice?: typeof maybeEmitNonGitWorkspaceNotice;
|
|
5
|
+
}
|
|
6
|
+
export declare function runSetupHooks(argv: readonly string[], store?: assetstore.AssetStoreProvider, review?: assetstore.ReviewLedger, deps?: SetupHooksDeps): Promise<number>;
|
|
7
|
+
export {};
|
package/dist/setupHooks.js
CHANGED
|
@@ -12,6 +12,7 @@ import { fileURLToPath } from 'node:url';
|
|
|
12
12
|
import { currentTopCursorGenes } from './cursorRewrite.js';
|
|
13
13
|
import { resolveProxyBinPath, resolveStableNodePath } from './lifecycle.js';
|
|
14
14
|
import { reviewLedgerForStore } from './reviewFilter.js';
|
|
15
|
+
import { maybeEmitNonGitWorkspaceNotice } from './nonGitWorkspaceNotice.js';
|
|
15
16
|
const requireFromHere = createRequire(import.meta.url);
|
|
16
17
|
function parseFlags(argv) {
|
|
17
18
|
const out = {};
|
|
@@ -273,7 +274,7 @@ function appendAdapterNotes(text, hints) {
|
|
|
273
274
|
? `${text}\n\nAdapter notes:\n${hints.map((hint) => ` - ${hint}`).join('\n')}`
|
|
274
275
|
: text;
|
|
275
276
|
}
|
|
276
|
-
export async function runSetupHooks(argv, store, review) {
|
|
277
|
+
export async function runSetupHooks(argv, store, review, deps = {}) {
|
|
277
278
|
const f = parseFlags(argv);
|
|
278
279
|
const runtimeRaw = typeof f['runtime'] === 'string'
|
|
279
280
|
? f['runtime']
|
|
@@ -300,7 +301,7 @@ export async function runSetupHooks(argv, store, review) {
|
|
|
300
301
|
process.stderr.write(`${support.reason}\n${USAGE}`);
|
|
301
302
|
return 1;
|
|
302
303
|
}
|
|
303
|
-
//
|
|
304
|
+
// Installed runtimes have a real config writer + uninstaller (including Antigravity MCP config).
|
|
304
305
|
const runtime = runtimeRaw;
|
|
305
306
|
const configRoot = typeof f['root'] === 'string' ? f['root'] : process.cwd();
|
|
306
307
|
// claude-code: user scope targets ~/.claude.json regardless of --root; project scope uses configRoot.
|
|
@@ -359,6 +360,8 @@ export async function runSetupHooks(argv, store, review) {
|
|
|
359
360
|
return 0;
|
|
360
361
|
}
|
|
361
362
|
const server = buildServer(f, descriptor);
|
|
363
|
+
if (runtime === 'cursor')
|
|
364
|
+
(deps.emitNonGitWorkspaceNotice ?? maybeEmitNonGitWorkspaceNotice)({ cwd: configRoot });
|
|
362
365
|
// cursor seeds .cursor/rules/evolver.mdc with the CURRENT top REVIEW-APPROVED genes so the file is useful
|
|
363
366
|
// immediately (before the first daemon rewrite) without seeding an unapproved draft (A2a). The renderer thus
|
|
364
367
|
// has a real production caller even without the daemon running.
|