@evomap/evolver-cli 2.0.0-beta.0
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.d.ts +9 -0
- package/dist/antiGeneBenchmark.js +173 -0
- package/dist/antiGeneRollout.d.ts +14 -0
- package/dist/antiGeneRollout.js +276 -0
- package/dist/atp.d.ts +122 -0
- package/dist/atp.js +413 -0
- package/dist/atpAutoDeliver.d.ts +53 -0
- package/dist/atpAutoDeliver.js +197 -0
- package/dist/atpAutobuyPrompt.d.ts +48 -0
- package/dist/atpAutobuyPrompt.js +109 -0
- package/dist/autoDistillAntiGene.d.ts +63 -0
- package/dist/autoDistillAntiGene.js +396 -0
- package/dist/autoDistillLlm.d.ts +94 -0
- package/dist/autoDistillLlm.js +510 -0
- package/dist/autoDistillTranscript.d.ts +87 -0
- package/dist/autoDistillTranscript.js +364 -0
- package/dist/autoRecall.d.ts +25 -0
- package/dist/autoRecall.js +80 -0
- package/dist/autoexec.d.ts +237 -0
- package/dist/autoexec.js +1041 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +7 -0
- package/dist/cliContracts.d.ts +72 -0
- package/dist/cliContracts.js +815 -0
- package/dist/commands.d.ts +9 -0
- package/dist/commands.js +10 -0
- package/dist/cursorRewrite.d.ts +42 -0
- package/dist/cursorRewrite.js +65 -0
- package/dist/cycleConsumer.d.ts +42 -0
- package/dist/cycleConsumer.js +519 -0
- package/dist/daemonLoop.d.ts +33 -0
- package/dist/daemonLoop.js +72 -0
- package/dist/dispatch.d.ts +10 -0
- package/dist/dispatch.js +75 -0
- package/dist/distillObserver.d.ts +33 -0
- package/dist/distillObserver.js +146 -0
- package/dist/distillPrimitives.d.ts +48 -0
- package/dist/distillPrimitives.js +142 -0
- package/dist/doctor.d.ts +54 -0
- package/dist/doctor.js +931 -0
- package/dist/geneValue.d.ts +37 -0
- package/dist/geneValue.js +97 -0
- package/dist/index.d.ts +193 -0
- package/dist/index.js +1135 -0
- package/dist/lifecycle.d.ts +75 -0
- package/dist/lifecycle.js +859 -0
- package/dist/login.d.ts +10 -0
- package/dist/login.js +38 -0
- package/dist/migrate/divergenceAudit.d.ts +29 -0
- package/dist/migrate/divergenceAudit.js +37 -0
- package/dist/migrate/fieldMap.d.ts +18 -0
- package/dist/migrate/fieldMap.js +68 -0
- package/dist/migrate/v1Import.d.ts +16 -0
- package/dist/migrate/v1Import.js +118 -0
- package/dist/phub.d.ts +18 -0
- package/dist/phub.js +284 -0
- package/dist/recall.d.ts +26 -0
- package/dist/recall.js +162 -0
- package/dist/recipe.d.ts +61 -0
- package/dist/recipe.js +564 -0
- package/dist/reflectionObserver.d.ts +8 -0
- package/dist/reflectionObserver.js +6 -0
- package/dist/reuse.d.ts +48 -0
- package/dist/reuse.js +300 -0
- package/dist/reuseReport.d.ts +20 -0
- package/dist/reuseReport.js +255 -0
- package/dist/reviewFilter.d.ts +4 -0
- package/dist/reviewFilter.js +6 -0
- package/dist/runtimeSessionSource.d.ts +9 -0
- package/dist/runtimeSessionSource.js +29 -0
- package/dist/setupHooks.d.ts +2 -0
- package/dist/setupHooks.js +410 -0
- package/dist/skill2gep.d.ts +144 -0
- package/dist/skill2gep.js +321 -0
- package/dist/skillDistill.d.ts +75 -0
- package/dist/skillDistill.js +342 -0
- package/dist/solo/breaker.d.ts +14 -0
- package/dist/solo/breaker.js +21 -0
- package/dist/solo/gitGuard.d.ts +17 -0
- package/dist/solo/gitGuard.js +62 -0
- package/dist/solo/mode.d.ts +12 -0
- package/dist/solo/mode.js +55 -0
- package/dist/thesis.d.ts +43 -0
- package/dist/thesis.js +179 -0
- package/dist/trajectoryExport.d.ts +1 -0
- package/dist/trajectoryExport.js +895 -0
- package/dist/valueDigest.d.ts +33 -0
- package/dist/valueDigest.js +94 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.js +14 -0
- package/package.json +38 -0
package/dist/recipe.js
ADDED
|
@@ -0,0 +1,564 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, unlinkSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { homedir } from 'node:os';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { assetstore, events, mailbox } from '@evomap/evolver-core';
|
|
5
|
+
import { AuthError, HubClientError, HubUnreachableError, connectPublicHub, isHubDryRunEnabled, isNodeSecret, parseNodeSecretVersion } from '@evomap/evolver-adapter-public';
|
|
6
|
+
import { resolveAtpSenderId } from './atp.js';
|
|
7
|
+
const MAX_RECIPE_STEPS = 20;
|
|
8
|
+
const MAX_ID_LENGTH = 200;
|
|
9
|
+
const DEFAULT_PUBLIC_HUB_URL = 'https://evomap.ai';
|
|
10
|
+
const SENSITIVE_ERROR_KEYS = new Set(['authorization', 'node_secret', 'nodesecret', 'token', 'access_token', 'refresh_token', 'secret']);
|
|
11
|
+
const STALE_NODE_SECRET_ERRORS = new Set(['node_secret_invalid', 'node_secret_not_set']);
|
|
12
|
+
export async function runRecipeCommand(argv, deps = {}) {
|
|
13
|
+
const parsed = parseRecipeArgs(argv);
|
|
14
|
+
const err = deps.err ?? ((line) => { process.stderr.write(`${line}\n`); });
|
|
15
|
+
const log = deps.log ?? ((line) => { process.stdout.write(`${line}\n`); });
|
|
16
|
+
if (!parsed.ok) {
|
|
17
|
+
err(`${parsed.error}\n${recipeUsage()}`);
|
|
18
|
+
return 1;
|
|
19
|
+
}
|
|
20
|
+
try {
|
|
21
|
+
const env = deps.env ?? process.env;
|
|
22
|
+
if (isHubDryRunEnabled(env)) {
|
|
23
|
+
if (parsed.value.sub === 'build')
|
|
24
|
+
return await runRecipeBuildDryRun(parsed.value, deps.store, { log, err });
|
|
25
|
+
return runRecipeReuseDryRun(parsed.value, { log });
|
|
26
|
+
}
|
|
27
|
+
const hub = deps.hub ?? createRecipeHubFromEnv(env, deps.connectHub ?? connectPublicHub);
|
|
28
|
+
if (!hub.recipes) {
|
|
29
|
+
err('recipe capability is not available for the configured Hub adapter');
|
|
30
|
+
return 1;
|
|
31
|
+
}
|
|
32
|
+
if (parsed.value.sub === 'build')
|
|
33
|
+
return await runRecipeBuild(parsed.value, hub, deps.store, { log, err });
|
|
34
|
+
return await runRecipeReuse(parsed.value, hub, { log, err });
|
|
35
|
+
}
|
|
36
|
+
catch (e) {
|
|
37
|
+
err(recipeErrorMessage(e));
|
|
38
|
+
return 1;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
async function runRecipeBuildDryRun(opts, store, io) {
|
|
42
|
+
const steps = await recipeStepsFromLocalAssets(opts.assetIds, store ?? new assetstore.LocalJsonlProvider(events.assetsDir()));
|
|
43
|
+
if (steps.length === 0) {
|
|
44
|
+
io.err('recipe build requires at least one asset id');
|
|
45
|
+
return 1;
|
|
46
|
+
}
|
|
47
|
+
io.log(`[recipe build] dry-run: would create DRAFT recipe ("${opts.title}", ${steps.length} step${steps.length === 1 ? '' : 's'}).`);
|
|
48
|
+
if (opts.publish) {
|
|
49
|
+
io.log('[recipe build] dry-run: would publish the recipe after creation.');
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
io.log('[recipe build] dry-run: would leave the recipe as draft.');
|
|
53
|
+
}
|
|
54
|
+
return 0;
|
|
55
|
+
}
|
|
56
|
+
function runRecipeReuseDryRun(opts, io) {
|
|
57
|
+
io.log(`[recipe reuse] dry-run: would fetch recipe ${opts.recipeId}.`);
|
|
58
|
+
io.log(`[recipe reuse] dry-run: would express recipe ${opts.recipeId}.`);
|
|
59
|
+
if (opts.jsonOut) {
|
|
60
|
+
io.log(JSON.stringify({
|
|
61
|
+
dry_run: true,
|
|
62
|
+
would: 'express_recipe',
|
|
63
|
+
recipe_id: opts.recipeId,
|
|
64
|
+
input_payload: opts.inputPayload,
|
|
65
|
+
}, null, 2));
|
|
66
|
+
}
|
|
67
|
+
return 0;
|
|
68
|
+
}
|
|
69
|
+
export function createRecipeHubFromEnv(env = process.env, connectHub = connectPublicHub) {
|
|
70
|
+
const hubUrl = resolveRecipeHubUrl(env);
|
|
71
|
+
const credentials = resolveRecipeHubCredentials(env);
|
|
72
|
+
if (!credentials.nodeSecret && !existsSync(join(credentials.evomapDir, 'token.json'))) {
|
|
73
|
+
throw new Error(`recipe requires Hub credentials: run "evolver login" or set EVOMAP_NODE_SECRET`);
|
|
74
|
+
}
|
|
75
|
+
if (!credentials.nodeSecret && !credentials.senderId) {
|
|
76
|
+
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');
|
|
77
|
+
}
|
|
78
|
+
const connected = credentials.nodeSecret
|
|
79
|
+
? connectHub({
|
|
80
|
+
hubUrl,
|
|
81
|
+
authMode: 'legacy',
|
|
82
|
+
evomapDir: credentials.evomapDir,
|
|
83
|
+
nodeSecret: credentials.nodeSecret,
|
|
84
|
+
...(credentials.nodeSecretVersion !== undefined ? { nodeSecretVersion: credentials.nodeSecretVersion } : {}),
|
|
85
|
+
senderId: () => credentials.senderId,
|
|
86
|
+
onNodeSecretRotated: (secret, version) => persistRotatedNodeSecret(secret, version, env, credentials.rotatePersistDir),
|
|
87
|
+
onNodeSecretVersionUpdated: (version) => persistNodeSecretVersion(version, env, credentials.rotatePersistDir),
|
|
88
|
+
})
|
|
89
|
+
: connectHub({ hubUrl, authMode: 'oauth', evomapDir: credentials.evomapDir, senderId: () => credentials.senderId });
|
|
90
|
+
return connected.hub;
|
|
91
|
+
}
|
|
92
|
+
function resolveRecipeHubUrl(env) {
|
|
93
|
+
const hubUrl = (env['A2A_HUB_URL']?.trim() || env['EVOMAP_HUB_URL']?.trim() || DEFAULT_PUBLIC_HUB_URL).replace(/\/+$/, '');
|
|
94
|
+
return hubUrl;
|
|
95
|
+
}
|
|
96
|
+
export function parseRecipeArgs(argv) {
|
|
97
|
+
const sub = argv[0];
|
|
98
|
+
if (sub !== 'build' && sub !== 'reuse')
|
|
99
|
+
return { ok: false, error: 'recipe subcommand must be build|reuse' };
|
|
100
|
+
const args = argv.slice(1);
|
|
101
|
+
if (sub === 'build')
|
|
102
|
+
return parseBuildArgs(args);
|
|
103
|
+
return parseReuseArgs(args);
|
|
104
|
+
}
|
|
105
|
+
async function runRecipeBuild(opts, hub, store, io) {
|
|
106
|
+
const steps = await recipeStepsFromLocalAssets(opts.assetIds, store ?? new assetstore.LocalJsonlProvider(events.assetsDir()));
|
|
107
|
+
if (steps.length === 0) {
|
|
108
|
+
io.err('recipe build requires at least one asset id');
|
|
109
|
+
return 1;
|
|
110
|
+
}
|
|
111
|
+
const createReceipt = await callRecipeWithAuthRetry(hub, 'recipe build', () => hub.recipes.create({
|
|
112
|
+
title: opts.title,
|
|
113
|
+
steps,
|
|
114
|
+
...(opts.description ? { description: opts.description } : {}),
|
|
115
|
+
...(opts.pricePerExecution !== undefined ? { pricePerExecution: opts.pricePerExecution } : {}),
|
|
116
|
+
}), io);
|
|
117
|
+
const recipeId = createReceipt.recipeId;
|
|
118
|
+
io.log(`[recipe build] Created DRAFT recipe ${recipeId ?? '(id pending)'} ("${opts.title}", ${steps.length} step${steps.length === 1 ? '' : 's'}).`);
|
|
119
|
+
if (opts.publish) {
|
|
120
|
+
if (!recipeId) {
|
|
121
|
+
io.err('[recipe build] Hub did not return a recipe id; cannot publish.');
|
|
122
|
+
return 1;
|
|
123
|
+
}
|
|
124
|
+
await callRecipeWithAuthRetry(hub, 'recipe build', () => hub.recipes.publish(recipeId), io);
|
|
125
|
+
io.log(`[recipe build] Published recipe ${recipeId}.`);
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
io.log('[recipe build] Left as draft. Re-run with --publish to make it live.');
|
|
129
|
+
}
|
|
130
|
+
return 0;
|
|
131
|
+
}
|
|
132
|
+
async function runRecipeReuse(opts, hub, io) {
|
|
133
|
+
await callRecipeWithAuthRetry(hub, 'recipe reuse', () => hub.recipes.get(opts.recipeId), io);
|
|
134
|
+
const receipt = await callRecipeWithAuthRetry(hub, 'recipe reuse', () => hub.recipes.express(opts.recipeId, { inputPayload: opts.inputPayload }), io);
|
|
135
|
+
io.log(`[recipe reuse] Expressed recipe ${opts.recipeId}.`);
|
|
136
|
+
if (opts.jsonOut)
|
|
137
|
+
io.log(JSON.stringify(receipt.raw, null, 2));
|
|
138
|
+
return 0;
|
|
139
|
+
}
|
|
140
|
+
async function recipeStepsFromLocalAssets(assetIds, store) {
|
|
141
|
+
const byId = new Map();
|
|
142
|
+
for (const kind of ['Gene', 'Capsule']) {
|
|
143
|
+
for (const asset of await store.list(kind, 10_000)) {
|
|
144
|
+
if (asset.asset_id)
|
|
145
|
+
byId.set(asset.asset_id, kind);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return assetIds.map((assetId, index) => {
|
|
149
|
+
const assetType = byId.get(assetId) ?? 'Gene';
|
|
150
|
+
return { assetId, assetType, position: index };
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
async function callRecipeWithAuthRetry(hub, tag, fn, io) {
|
|
154
|
+
try {
|
|
155
|
+
return await fn();
|
|
156
|
+
}
|
|
157
|
+
catch (e) {
|
|
158
|
+
if (!(e instanceof AuthError) || !hub.hello)
|
|
159
|
+
throw e;
|
|
160
|
+
if (!authErrorIndicatesStaleNodeSecret(e))
|
|
161
|
+
throw e;
|
|
162
|
+
io.log(`[${tag}] Hub reported a stale node secret; rotating credentials once and retrying...`);
|
|
163
|
+
const hello = await hub.hello({ rotate: true });
|
|
164
|
+
if (!hello.ok) {
|
|
165
|
+
io.err(`[${tag}] Could not auto-rotate credentials: ${hello.error ?? 'unknown'}`);
|
|
166
|
+
io.err(' Recover by resetting the Hub credential, then re-run `evolver login` or update EVOMAP_NODE_SECRET.');
|
|
167
|
+
throw e;
|
|
168
|
+
}
|
|
169
|
+
return await fn();
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
function parseBuildArgs(args) {
|
|
173
|
+
const title = flagValue(args, '--title');
|
|
174
|
+
const genesRaw = flagValue(args, '--genes') ?? flagValue(args, '--assets');
|
|
175
|
+
if (!title)
|
|
176
|
+
return { ok: false, error: 'recipe build requires --title <title>' };
|
|
177
|
+
if (!genesRaw)
|
|
178
|
+
return { ok: false, error: 'recipe build requires --genes <asset_id,...>' };
|
|
179
|
+
const assetIds = splitIds(genesRaw);
|
|
180
|
+
if (assetIds.length === 0)
|
|
181
|
+
return { ok: false, error: '--genes is empty' };
|
|
182
|
+
if (assetIds.length > MAX_RECIPE_STEPS)
|
|
183
|
+
return { ok: false, error: `recipe build supports at most ${MAX_RECIPE_STEPS} steps` };
|
|
184
|
+
const priceRaw = flagValue(args, '--price');
|
|
185
|
+
const price = priceRaw === null ? undefined : Number(priceRaw);
|
|
186
|
+
if (price !== undefined && (!Number.isFinite(price) || price < 0))
|
|
187
|
+
return { ok: false, error: '--price must be a non-negative number' };
|
|
188
|
+
const description = flagValue(args, '--description');
|
|
189
|
+
return {
|
|
190
|
+
ok: true,
|
|
191
|
+
value: {
|
|
192
|
+
sub: 'build',
|
|
193
|
+
title,
|
|
194
|
+
assetIds,
|
|
195
|
+
...(description ? { description } : {}),
|
|
196
|
+
...(price !== undefined ? { pricePerExecution: price } : {}),
|
|
197
|
+
publish: args.includes('--publish'),
|
|
198
|
+
},
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
function parseReuseArgs(args) {
|
|
202
|
+
const recipeId = flagValue(args, '--id') ?? firstPositional(args);
|
|
203
|
+
if (!recipeId)
|
|
204
|
+
return { ok: false, error: 'recipe reuse requires --id <recipe_id>' };
|
|
205
|
+
if (recipeId.length > MAX_ID_LENGTH)
|
|
206
|
+
return { ok: false, error: `recipe id must be <= ${MAX_ID_LENGTH} characters` };
|
|
207
|
+
const inputRaw = flagValue(args, '--input');
|
|
208
|
+
const input = inputRaw === null ? { ok: true, value: {} } : parseJsonObject(inputRaw);
|
|
209
|
+
if (!input.ok)
|
|
210
|
+
return input;
|
|
211
|
+
return { ok: true, value: { sub: 'reuse', recipeId, inputPayload: input.value, jsonOut: args.includes('--json') } };
|
|
212
|
+
}
|
|
213
|
+
function splitIds(raw) {
|
|
214
|
+
return raw.split(',').map((s) => s.trim()).filter(Boolean).filter((s) => s.length <= MAX_ID_LENGTH);
|
|
215
|
+
}
|
|
216
|
+
function flagValue(args, flag) {
|
|
217
|
+
for (let i = 0; i < args.length; i += 1) {
|
|
218
|
+
const token = args[i];
|
|
219
|
+
if (token === undefined)
|
|
220
|
+
continue;
|
|
221
|
+
if (token === flag) {
|
|
222
|
+
const next = args[i + 1];
|
|
223
|
+
return next && !next.startsWith('--') ? next : null;
|
|
224
|
+
}
|
|
225
|
+
if (token.startsWith(`${flag}=`))
|
|
226
|
+
return token.slice(flag.length + 1);
|
|
227
|
+
}
|
|
228
|
+
return null;
|
|
229
|
+
}
|
|
230
|
+
function firstPositional(args) {
|
|
231
|
+
return args.find((a) => typeof a === 'string' && !a.startsWith('--')) ?? null;
|
|
232
|
+
}
|
|
233
|
+
function parseJsonObject(raw) {
|
|
234
|
+
try {
|
|
235
|
+
const parsed = JSON.parse(raw);
|
|
236
|
+
if (parsed && typeof parsed === 'object' && !Array.isArray(parsed))
|
|
237
|
+
return { ok: true, value: parsed };
|
|
238
|
+
return { ok: false, error: '--input must be a JSON object' };
|
|
239
|
+
}
|
|
240
|
+
catch {
|
|
241
|
+
return { ok: false, error: '--input must be valid JSON' };
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
function recipeErrorMessage(e) {
|
|
245
|
+
if (e instanceof HubClientError)
|
|
246
|
+
return `recipe Hub call failed (HTTP ${e.status}): ${JSON.stringify(redactHubErrorBody(e.body))}`;
|
|
247
|
+
if (e instanceof AuthError) {
|
|
248
|
+
const details = e.body === undefined ? '' : `: ${JSON.stringify(redactHubErrorBody(e.body))}`;
|
|
249
|
+
return `recipe Hub auth failed (HTTP ${e.status})${details}; run "evolver login" or refresh EVOMAP_NODE_SECRET`;
|
|
250
|
+
}
|
|
251
|
+
if (e instanceof HubUnreachableError)
|
|
252
|
+
return `recipe Hub is unreachable: ${e.message}`;
|
|
253
|
+
return e instanceof Error ? e.message : String(e);
|
|
254
|
+
}
|
|
255
|
+
function redactHubErrorBody(value, depth = 0) {
|
|
256
|
+
if (depth > 5)
|
|
257
|
+
return '[redacted-depth]';
|
|
258
|
+
if (typeof value === 'string')
|
|
259
|
+
return redactSensitiveString(value);
|
|
260
|
+
if (Array.isArray(value))
|
|
261
|
+
return value.map((item) => redactHubErrorBody(item, depth + 1));
|
|
262
|
+
if (!value || typeof value !== 'object')
|
|
263
|
+
return value;
|
|
264
|
+
const out = {};
|
|
265
|
+
for (const [key, nested] of Object.entries(value)) {
|
|
266
|
+
out[key] = isSensitiveErrorKey(key) ? '[redacted]' : redactHubErrorBody(nested, depth + 1);
|
|
267
|
+
}
|
|
268
|
+
return out;
|
|
269
|
+
}
|
|
270
|
+
function authErrorIndicatesStaleNodeSecret(e) {
|
|
271
|
+
const text = [
|
|
272
|
+
e.errorCode,
|
|
273
|
+
...authErrorStringValues(e.body),
|
|
274
|
+
].filter((value) => typeof value === 'string' && value.length > 0).join(' ').toLowerCase();
|
|
275
|
+
return [...STALE_NODE_SECRET_ERRORS].some((code) => text.includes(code));
|
|
276
|
+
}
|
|
277
|
+
function authErrorStringValues(value, depth = 0) {
|
|
278
|
+
if (depth > 5 || value === undefined || value === null)
|
|
279
|
+
return [];
|
|
280
|
+
if (typeof value === 'string')
|
|
281
|
+
return [value];
|
|
282
|
+
if (typeof value === 'number' || typeof value === 'boolean')
|
|
283
|
+
return [String(value)];
|
|
284
|
+
if (Array.isArray(value))
|
|
285
|
+
return value.flatMap((item) => authErrorStringValues(item, depth + 1));
|
|
286
|
+
if (typeof value !== 'object')
|
|
287
|
+
return [];
|
|
288
|
+
return Object.entries(value).flatMap(([key, nested]) => [
|
|
289
|
+
key,
|
|
290
|
+
...authErrorStringValues(nested, depth + 1),
|
|
291
|
+
]);
|
|
292
|
+
}
|
|
293
|
+
function isSensitiveErrorKey(key) {
|
|
294
|
+
const normalized = key.toLowerCase();
|
|
295
|
+
return SENSITIVE_ERROR_KEYS.has(normalized) || normalized.includes('token') || normalized.includes('secret');
|
|
296
|
+
}
|
|
297
|
+
function redactSensitiveString(value) {
|
|
298
|
+
return value
|
|
299
|
+
.replace(/\bBearer\s+[A-Za-z0-9._~+/=-]+/gi, 'Bearer [redacted]')
|
|
300
|
+
.replace(/\b(authorization|node_secret|nodeSecret|access_token|refresh_token|token|secret)\b\s*[:=]\s*["']?[^"',\s;}]+/gi, '$1=[redacted]');
|
|
301
|
+
}
|
|
302
|
+
function resolveRecipeHubCredentials(env) {
|
|
303
|
+
const homeCandidates = recipeHomeCandidates(env);
|
|
304
|
+
const defaultHome = homeCandidates[0] ?? events.evomapHome();
|
|
305
|
+
const fromEnv = env['EVOMAP_NODE_SECRET']?.trim() || env['A2A_NODE_SECRET']?.trim();
|
|
306
|
+
const envNodeSecretVersion = parseNodeSecretVersion(env['EVOMAP_NODE_SECRET_VERSION'] ?? env['A2A_NODE_SECRET_VERSION']);
|
|
307
|
+
const stored = readRecipeStoreNodeCredentials(env);
|
|
308
|
+
const explicitSenderId = explicitRecipeSenderId(env);
|
|
309
|
+
if (stored?.source === 'hub_rotate' && stored.nodeSecret) {
|
|
310
|
+
return {
|
|
311
|
+
evomapDir: defaultHome,
|
|
312
|
+
nodeSecret: stored.nodeSecret,
|
|
313
|
+
...(stored.nodeSecretVersion !== undefined ? { nodeSecretVersion: stored.nodeSecretVersion } : {}),
|
|
314
|
+
senderId: explicitSenderId ?? firstLegacyNodeId(homeCandidates) ?? resolveAtpSenderId(env),
|
|
315
|
+
rotatePersistDir: defaultHome,
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
if (fromEnv) {
|
|
319
|
+
const legacyNodeId = firstLegacyNodeId(homeCandidates);
|
|
320
|
+
const nodeSecretVersion = envNodeSecretVersion ?? pairedStoreNodeSecretVersion(fromEnv, stored) ?? pairedLegacyNodeSecretVersion(fromEnv, homeCandidates);
|
|
321
|
+
return {
|
|
322
|
+
evomapDir: defaultHome,
|
|
323
|
+
nodeSecret: fromEnv,
|
|
324
|
+
...(nodeSecretVersion !== undefined ? { nodeSecretVersion } : {}),
|
|
325
|
+
senderId: explicitSenderId ?? legacyNodeId ?? resolveAtpSenderId(env),
|
|
326
|
+
rotatePersistDir: defaultHome,
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
if (stored?.nodeSecret) {
|
|
330
|
+
return {
|
|
331
|
+
evomapDir: defaultHome,
|
|
332
|
+
nodeSecret: stored.nodeSecret,
|
|
333
|
+
...(stored.nodeSecretVersion !== undefined ? { nodeSecretVersion: stored.nodeSecretVersion } : {}),
|
|
334
|
+
senderId: explicitSenderId ?? firstLegacyNodeId(homeCandidates) ?? resolveAtpSenderId(env),
|
|
335
|
+
rotatePersistDir: defaultHome,
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
const legacy = firstLegacyNodeCredentials(homeCandidates);
|
|
339
|
+
if (legacy) {
|
|
340
|
+
return {
|
|
341
|
+
evomapDir: legacy.dir,
|
|
342
|
+
nodeSecret: legacy.nodeSecret,
|
|
343
|
+
...(legacy.nodeSecretVersion !== undefined ? { nodeSecretVersion: legacy.nodeSecretVersion } : {}),
|
|
344
|
+
senderId: legacy.nodeId ?? explicitSenderId ?? firstLegacyNodeId(homeCandidates) ?? resolveAtpSenderId(env),
|
|
345
|
+
rotatePersistDir: legacy.dir,
|
|
346
|
+
};
|
|
347
|
+
}
|
|
348
|
+
const oauthDir = homeCandidates.find((dir) => existsSync(join(dir, 'token.json'))) ?? defaultHome;
|
|
349
|
+
return {
|
|
350
|
+
evomapDir: oauthDir,
|
|
351
|
+
senderId: explicitSenderId ?? firstLegacyNodeId(homeCandidates) ?? resolveAtpSenderId(env),
|
|
352
|
+
rotatePersistDir: oauthDir,
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
/**
|
|
356
|
+
* The EXPLICIT home overrides (EVOMAP_DIR / EVOLVER_HOME / EVOMAP_HOME) the recipe credential layer honors,
|
|
357
|
+
* resolved purely from the passed env with no process.env fallback. Exported so `reset-local-secret` (index.ts)
|
|
358
|
+
* can clear the SAME explicit directories the recipe path may persist rotated legacy files into
|
|
359
|
+
* (rotatePersistDir = recipeHomeCandidates(env)[0], which is the first explicit home when any is set) — otherwise
|
|
360
|
+
* a reset that only wiped ~/.evomap would leave a stale node_secret under EVOMAP_DIR/EVOMAP_HOME that resurrects on
|
|
361
|
+
* the next recipe run (H3). Kept env-pure (no events.evomapHome()) so reset stays hermetic under an injected env.
|
|
362
|
+
*/
|
|
363
|
+
export function explicitRecipeHomes(env) {
|
|
364
|
+
const explicit = [
|
|
365
|
+
env['EVOMAP_DIR'],
|
|
366
|
+
env['EVOLVER_HOME'],
|
|
367
|
+
env['EVOMAP_HOME'],
|
|
368
|
+
];
|
|
369
|
+
return uniqueStrings(explicit.map((value) => value?.trim()).filter((value) => Boolean(value)));
|
|
370
|
+
}
|
|
371
|
+
function recipeHomeCandidates(env) {
|
|
372
|
+
const explicitHomes = explicitRecipeHomes(env);
|
|
373
|
+
if (explicitHomes.length > 0)
|
|
374
|
+
return explicitHomes;
|
|
375
|
+
const candidates = [
|
|
376
|
+
env['HOME'] ? join(env['HOME'], '.evomap') : undefined,
|
|
377
|
+
events.evomapHome(),
|
|
378
|
+
];
|
|
379
|
+
return uniqueStrings(candidates.map((value) => value?.trim()).filter((value) => Boolean(value)));
|
|
380
|
+
}
|
|
381
|
+
function explicitRecipeSenderId(env) {
|
|
382
|
+
return env['EVOMAP_NODE_ID']?.trim() || env['A2A_NODE_ID']?.trim();
|
|
383
|
+
}
|
|
384
|
+
function readRecipeStoreNodeCredentials(env) {
|
|
385
|
+
const storePath = recipeProxyStorePath(env);
|
|
386
|
+
if (!existsSync(storePath))
|
|
387
|
+
return undefined;
|
|
388
|
+
const store = new mailbox.MailboxStore({ path: storePath });
|
|
389
|
+
try {
|
|
390
|
+
const storedSecret = store.getState('node_secret');
|
|
391
|
+
const nodeSecret = storedSecret && isNodeSecret(storedSecret) ? storedSecret : undefined;
|
|
392
|
+
const nodeSecretVersion = parseNodeSecretVersion(store.getState('node_secret_version'));
|
|
393
|
+
const source = store.getState('node_secret_source') || undefined;
|
|
394
|
+
return {
|
|
395
|
+
...(nodeSecret ? { nodeSecret } : {}),
|
|
396
|
+
...(nodeSecretVersion !== undefined ? { nodeSecretVersion } : {}),
|
|
397
|
+
...(source ? { source } : {}),
|
|
398
|
+
};
|
|
399
|
+
}
|
|
400
|
+
finally {
|
|
401
|
+
store.close();
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
// Reuse the store's node_secret_version for an env-supplied secret ONLY when the store holds a node_secret
|
|
405
|
+
// EQUAL to it. v1 (manager.js nodeSecretVersion getter: `return storeSecret === envSecret ? storeVersion : null`)
|
|
406
|
+
// and v2's own proxy (evolver-proxy.ts: `envNodeSecret === storeSecret ? storedNodeSecretVersion : undefined`)
|
|
407
|
+
// both require strict equality — neither reuses a version when the store has a version but NO secret. The
|
|
408
|
+
// previous `!stored.nodeSecret` passthrough was strictly wider than both, pairing an orphan version onto an
|
|
409
|
+
// unrelated env secret. A version is meaningful only as the version OF a specific secret, so a versioned env
|
|
410
|
+
// secret whose pair is unknown locally must carry no version (the hub assigns one on hello).
|
|
411
|
+
function pairedStoreNodeSecretVersion(secret, stored) {
|
|
412
|
+
if (!stored?.nodeSecretVersion)
|
|
413
|
+
return undefined;
|
|
414
|
+
return stored.nodeSecret === secret ? stored.nodeSecretVersion : undefined;
|
|
415
|
+
}
|
|
416
|
+
// Legacy-file counterpart of the rule above: v1 (extractor.js: `if (legacySecret === envSecret) return <version>`)
|
|
417
|
+
// requires the on-disk node_secret to equal the env secret before reusing its node_secret_version. Drop the
|
|
418
|
+
// previous `!rawSecret` passthrough so a version file with no matching secret file is never paired onto the env
|
|
419
|
+
// secret.
|
|
420
|
+
function pairedLegacyNodeSecretVersion(secret, dirs) {
|
|
421
|
+
for (const dir of dirs) {
|
|
422
|
+
const nodeSecretVersion = readLegacyNodeSecretVersion(dir);
|
|
423
|
+
if (nodeSecretVersion === undefined)
|
|
424
|
+
continue;
|
|
425
|
+
const rawSecret = readTrimmedFile(join(dir, 'node_secret'));
|
|
426
|
+
if (rawSecret === secret)
|
|
427
|
+
return nodeSecretVersion;
|
|
428
|
+
}
|
|
429
|
+
return undefined;
|
|
430
|
+
}
|
|
431
|
+
function firstLegacyNodeCredentials(dirs) {
|
|
432
|
+
for (const dir of dirs) {
|
|
433
|
+
const nodeSecret = readLegacyNodeSecret(dir);
|
|
434
|
+
if (!nodeSecret)
|
|
435
|
+
continue;
|
|
436
|
+
const nodeSecretVersion = readLegacyNodeSecretVersion(dir);
|
|
437
|
+
return {
|
|
438
|
+
dir,
|
|
439
|
+
nodeSecret,
|
|
440
|
+
...(nodeSecretVersion !== undefined ? { nodeSecretVersion } : {}),
|
|
441
|
+
nodeId: readLegacyNodeId(dir),
|
|
442
|
+
};
|
|
443
|
+
}
|
|
444
|
+
return undefined;
|
|
445
|
+
}
|
|
446
|
+
function firstLegacyNodeId(dirs) {
|
|
447
|
+
for (const dir of dirs) {
|
|
448
|
+
const nodeId = readLegacyNodeId(dir);
|
|
449
|
+
if (nodeId)
|
|
450
|
+
return nodeId;
|
|
451
|
+
}
|
|
452
|
+
return undefined;
|
|
453
|
+
}
|
|
454
|
+
function uniqueStrings(values) {
|
|
455
|
+
const seen = new Set();
|
|
456
|
+
const out = [];
|
|
457
|
+
for (const value of values) {
|
|
458
|
+
if (seen.has(value))
|
|
459
|
+
continue;
|
|
460
|
+
seen.add(value);
|
|
461
|
+
out.push(value);
|
|
462
|
+
}
|
|
463
|
+
return out;
|
|
464
|
+
}
|
|
465
|
+
function recipeProxyStorePath(env) {
|
|
466
|
+
const configuredStore = env['EVOLVER_PROXY_STORE'];
|
|
467
|
+
if (configuredStore && configuredStore.length > 0)
|
|
468
|
+
return configuredStore;
|
|
469
|
+
const configuredHome = env['EVOLVER_HOME'];
|
|
470
|
+
// `env['HOME'] || homedir()` (NOT `?? homedir()`): an empty-string HOME must fall back to homedir(), otherwise
|
|
471
|
+
// `join('', '.evomap', ...)` resolves to the RELATIVE path `.evomap/proxy/mailbox.db` and the CLI reads/writes a
|
|
472
|
+
// different mailbox.db than the proxy. This mirrors evolver-proxy's resolveLocalHome / evomapHome, which both
|
|
473
|
+
// treat '' as unset, so cli and proxy land on the same store.
|
|
474
|
+
const evomapHome = configuredHome && configuredHome.length > 0
|
|
475
|
+
? configuredHome
|
|
476
|
+
: join(env['HOME'] || homedir(), '.evomap');
|
|
477
|
+
return join(evomapHome, 'proxy', 'mailbox.db');
|
|
478
|
+
}
|
|
479
|
+
function setOptionalStoreState(store, key, value) {
|
|
480
|
+
store.setState(key, value ?? '');
|
|
481
|
+
}
|
|
482
|
+
function persistRotatedNodeSecret(secret, version, env, legacyDir) {
|
|
483
|
+
const storePath = recipeProxyStorePath(env);
|
|
484
|
+
const store = new mailbox.MailboxStore({ path: storePath });
|
|
485
|
+
try {
|
|
486
|
+
store.setState('node_secret', secret);
|
|
487
|
+
store.setState('node_secret_source', 'hub_rotate');
|
|
488
|
+
setOptionalStoreState(store, 'node_secret_version', version !== undefined ? String(version) : undefined);
|
|
489
|
+
}
|
|
490
|
+
finally {
|
|
491
|
+
store.close();
|
|
492
|
+
}
|
|
493
|
+
persistLegacyNodeSecret(secret, version, legacyDir);
|
|
494
|
+
}
|
|
495
|
+
function persistNodeSecretVersion(version, env, legacyDir) {
|
|
496
|
+
const storePath = recipeProxyStorePath(env);
|
|
497
|
+
const store = new mailbox.MailboxStore({ path: storePath });
|
|
498
|
+
try {
|
|
499
|
+
setOptionalStoreState(store, 'node_secret_version', version !== undefined ? String(version) : undefined);
|
|
500
|
+
}
|
|
501
|
+
finally {
|
|
502
|
+
store.close();
|
|
503
|
+
}
|
|
504
|
+
persistLegacyNodeSecretVersion(version, legacyDir);
|
|
505
|
+
}
|
|
506
|
+
function readLegacyNodeSecret(evomapDir) {
|
|
507
|
+
const secret = readTrimmedFile(join(evomapDir, 'node_secret'));
|
|
508
|
+
return secret && isNodeSecret(secret) ? secret : undefined;
|
|
509
|
+
}
|
|
510
|
+
function readLegacyNodeSecretVersion(evomapDir) {
|
|
511
|
+
return parseNodeSecretVersion(readTrimmedFile(join(evomapDir, 'node_secret_version')));
|
|
512
|
+
}
|
|
513
|
+
function readLegacyNodeId(evomapDir) {
|
|
514
|
+
return readTrimmedFile(join(evomapDir, 'node_id'));
|
|
515
|
+
}
|
|
516
|
+
function persistLegacyNodeSecret(secret, version, evomapDir) {
|
|
517
|
+
if (!isNodeSecret(secret))
|
|
518
|
+
return;
|
|
519
|
+
try {
|
|
520
|
+
mkdirSync(evomapDir, { recursive: true, mode: 0o700 });
|
|
521
|
+
writeFileSync(join(evomapDir, 'node_secret'), secret, { encoding: 'utf8', mode: 0o600 });
|
|
522
|
+
writeLegacyNodeSecretVersion(version, evomapDir);
|
|
523
|
+
}
|
|
524
|
+
catch {
|
|
525
|
+
// Mailbox persistence above is authoritative for v2; legacy file persistence is best effort.
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
function persistLegacyNodeSecretVersion(version, evomapDir) {
|
|
529
|
+
try {
|
|
530
|
+
mkdirSync(evomapDir, { recursive: true, mode: 0o700 });
|
|
531
|
+
writeLegacyNodeSecretVersion(version, evomapDir);
|
|
532
|
+
}
|
|
533
|
+
catch {
|
|
534
|
+
// Mailbox persistence above is authoritative for v2; legacy file persistence is best effort.
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
function writeLegacyNodeSecretVersion(version, evomapDir) {
|
|
538
|
+
const versionPath = join(evomapDir, 'node_secret_version');
|
|
539
|
+
if (version !== undefined) {
|
|
540
|
+
writeFileSync(versionPath, String(version), { encoding: 'utf8', mode: 0o600 });
|
|
541
|
+
return;
|
|
542
|
+
}
|
|
543
|
+
if (existsSync(versionPath))
|
|
544
|
+
unlinkSync(versionPath);
|
|
545
|
+
}
|
|
546
|
+
function readTrimmedFile(path) {
|
|
547
|
+
try {
|
|
548
|
+
if (!existsSync(path))
|
|
549
|
+
return undefined;
|
|
550
|
+
const value = readFileSync(path, 'utf8').trim();
|
|
551
|
+
return value.length > 0 ? value : undefined;
|
|
552
|
+
}
|
|
553
|
+
catch {
|
|
554
|
+
return undefined;
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
function recipeUsage() {
|
|
558
|
+
return [
|
|
559
|
+
'Recipe subcommands:',
|
|
560
|
+
' evolver recipe build --title <title> --genes <asset_id,...> [--description <text>] [--price <n>] [--publish]',
|
|
561
|
+
' Creates a draft recipe by default. --publish is explicit.',
|
|
562
|
+
' evolver recipe reuse --id <recipe_id> [--input <json-object>] [--json]',
|
|
563
|
+
].join('\n');
|
|
564
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { observers, type events } from '@evomap/evolver-core';
|
|
2
|
+
export interface ReflectionObserverWiring {
|
|
3
|
+
enabled: boolean;
|
|
4
|
+
observer: ReturnType<typeof observers.reflectionObserver> | null;
|
|
5
|
+
}
|
|
6
|
+
export declare function resolveReflectionObserver(env: NodeJS.ProcessEnv | undefined, opts: {
|
|
7
|
+
ingestor: events.Ingestor;
|
|
8
|
+
}): ReflectionObserverWiring;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { observers } from '@evomap/evolver-core';
|
|
2
|
+
export function resolveReflectionObserver(env = process.env, opts) {
|
|
3
|
+
if (env['EVOLVER_REFLECTION'] === '0')
|
|
4
|
+
return { enabled: false, observer: null };
|
|
5
|
+
return { enabled: true, observer: observers.reflectionObserver({ ingestor: opts.ingestor }) };
|
|
6
|
+
}
|
package/dist/reuse.d.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { assetstore, hub as hubNs } from '@evomap/evolver-core';
|
|
2
|
+
import type { ConnectPublicOptions, PublicHubCapability } from '@evomap/evolver-adapter-public';
|
|
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';
|
|
5
|
+
/** The stable reuse.v1 machine contract printed to stdout on success AND failure. Field set is locked by the
|
|
6
|
+
* consumer (evox-desktop `evolverReuseEnvelope`, #1008): { ok, contract, status, reason, message }. */
|
|
7
|
+
export interface ReuseEnvelope {
|
|
8
|
+
ok: boolean;
|
|
9
|
+
contract: typeof REUSE_CONTRACT;
|
|
10
|
+
status: ReuseStatus;
|
|
11
|
+
reason: string;
|
|
12
|
+
message: string;
|
|
13
|
+
}
|
|
14
|
+
/** Minimal hub surface this command needs: the reuse pull is a single fetch-by-id. PublicHubCapability satisfies it. */
|
|
15
|
+
type AssetByIdFetcher = {
|
|
16
|
+
fetchAssetById(assetId: string): Promise<assetstore.AssetRecord | null>;
|
|
17
|
+
};
|
|
18
|
+
export interface ReuseCliDeps {
|
|
19
|
+
store?: assetstore.AssetStoreProvider;
|
|
20
|
+
assetsDir?: string;
|
|
21
|
+
hub?: AssetByIdFetcher;
|
|
22
|
+
callLog?: {
|
|
23
|
+
append(entry: hubNs.AssetCallEntry): void;
|
|
24
|
+
};
|
|
25
|
+
env?: NodeJS.ProcessEnv;
|
|
26
|
+
stdout?: (line: string) => void;
|
|
27
|
+
stderr?: (line: string) => void;
|
|
28
|
+
connectHub?: (opts: ConnectPublicOptions) => {
|
|
29
|
+
hub: PublicHubCapability;
|
|
30
|
+
auth: hubNs.AuthProvider;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
interface ReuseOptions {
|
|
34
|
+
id: string;
|
|
35
|
+
mode: 'direct' | 'reference';
|
|
36
|
+
runId?: string;
|
|
37
|
+
}
|
|
38
|
+
type ParseResult<T> = {
|
|
39
|
+
ok: true;
|
|
40
|
+
value: T;
|
|
41
|
+
} | {
|
|
42
|
+
ok: false;
|
|
43
|
+
error: string;
|
|
44
|
+
status?: ReuseStatus;
|
|
45
|
+
};
|
|
46
|
+
export declare function runReuseCommand(argv: readonly string[], deps?: ReuseCliDeps): Promise<number>;
|
|
47
|
+
export declare function parseReuseArgs(argv: readonly string[]): ParseResult<ReuseOptions>;
|
|
48
|
+
export {};
|