@evomap/evolver 1.89.19 → 1.89.20

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.
Files changed (57) hide show
  1. package/package.json +1 -1
  2. package/scripts/skill2recipes.js +118 -0
  3. package/src/evolve/guards.js +1 -1
  4. package/src/evolve/pipeline/collect.js +1 -1
  5. package/src/evolve/pipeline/dispatch.js +1 -1
  6. package/src/evolve/pipeline/enrich.js +1 -1
  7. package/src/evolve/pipeline/hub.js +1 -1
  8. package/src/evolve/pipeline/select.js +1 -1
  9. package/src/evolve/pipeline/signals.js +1 -1
  10. package/src/evolve/utils.js +1 -1
  11. package/src/evolve.js +1 -1
  12. package/src/gep/a2aProtocol.js +1 -1
  13. package/src/gep/antiAbuseTelemetry.js +1 -1
  14. package/src/gep/autoDistillConv.js +1 -1
  15. package/src/gep/autoDistillLlm.js +1 -1
  16. package/src/gep/candidateEval.js +1 -1
  17. package/src/gep/candidates.js +1 -1
  18. package/src/gep/contentHash.js +1 -1
  19. package/src/gep/conversationDistiller.js +1 -1
  20. package/src/gep/conversationSniffer.js +1 -1
  21. package/src/gep/crypto.js +1 -1
  22. package/src/gep/curriculum.js +1 -1
  23. package/src/gep/deviceId.js +1 -1
  24. package/src/gep/envFingerprint.js +1 -1
  25. package/src/gep/epigenetics.js +1 -1
  26. package/src/gep/execBridge.js +1 -1
  27. package/src/gep/explore.js +1 -1
  28. package/src/gep/hash.js +1 -1
  29. package/src/gep/hubFetch.js +1 -1
  30. package/src/gep/hubReview.js +1 -1
  31. package/src/gep/hubSearch.js +1 -1
  32. package/src/gep/hubVerify.js +1 -1
  33. package/src/gep/learningSignals.js +1 -1
  34. package/src/gep/memoryGraph.js +1 -1
  35. package/src/gep/memoryGraphAdapter.js +1 -1
  36. package/src/gep/mutation.js +1 -1
  37. package/src/gep/narrativeMemory.js +1 -1
  38. package/src/gep/openPRRegistry.js +1 -1
  39. package/src/gep/personality.js +1 -1
  40. package/src/gep/policyCheck.js +1 -1
  41. package/src/gep/prompt.js +1 -1
  42. package/src/gep/recallInject.js +1 -1
  43. package/src/gep/recallVerifier.js +1 -1
  44. package/src/gep/reflection.js +1 -1
  45. package/src/gep/savingsCore.js +1 -1
  46. package/src/gep/selector.js +1 -1
  47. package/src/gep/skill2recipes.js +511 -0
  48. package/src/gep/skillDistiller.js +1 -1
  49. package/src/gep/solidify.js +1 -1
  50. package/src/gep/strategy.js +1 -1
  51. package/src/gep/tokenSavings.js +1 -1
  52. package/src/gep/trajectoryExport.js +1 -1
  53. package/src/gep/workspaceKeychain.js +1 -1
  54. package/src/proxy/extensions/traceControl.js +1 -1
  55. package/src/proxy/inject.js +1 -1
  56. package/src/proxy/trace/extractor.js +1 -1
  57. package/src/proxy/trace/usage.js +1 -1
@@ -0,0 +1,511 @@
1
+ 'use strict';
2
+
3
+ // skill2recipes.js -- Compose a published GEP *Recipe* out of one or more
4
+ // locally-invoked Skills.
5
+ //
6
+ // This is the layer ABOVE skill2gep.js:
7
+ // skill2gep.js : 1 SKILL.md (+ run) -> Gene + Capsule (assets)
8
+ // skill2recipes.js : N SKILL.md hydrolyzed+verified -> ordered Recipe on Hub
9
+ //
10
+ // Pipeline per step (the "水解 -> 验证 -> 资产" half is delegated to skill2gep):
11
+ // 1. 水解 (hydrolyze): parseSkillMd + synthesizeGene -> validated draft Gene
12
+ // 2. 验证 (verify): policyCheck.runValidations(gene) actually EXECUTES the
13
+ // gene's validation commands in repoRoot and produces a
14
+ // real execution trace. assembleCapsule + detectForgery
15
+ // then refuse to mint a Capsule without that evidence.
16
+ // 3. 资产 (assets): buildPublishBundle stamps the authoritative asset_id
17
+ // (computeAssetId) on Gene+Capsule and POSTs them to
18
+ // /a2a/publish; the Gene's asset_id is what the recipe
19
+ // step will reference.
20
+ //
21
+ // Why Gene+Capsule is mandatory, not optional:
22
+ // The Hub's /a2a/publish ONLY accepts a Gene+Capsule bundle (validateBundle
23
+ // rejects assets.length < 2), and that bundle path is the only thing that
24
+ // writes an Asset row. recipeService.validateStepAssets requires every
25
+ // step.asset_id to already exist as an Asset of the matching type. So a Gene
26
+ // can only become a recipe-referenceable asset_id if it was published next to
27
+ // a Capsule -- which, per the forgery guard, requires real execution
28
+ // evidence. "Prefer Gene, add Capsule only with evidence" therefore resolves
29
+ // to: every step IS verified, the Capsule is the evidence, and the recipe
30
+ // step points at the Gene. Skills with no runnable validation cannot enter a
31
+ // recipe -- by design, not by accident.
32
+ //
33
+ // Compose & upload:
34
+ // 4. POST /a2a/recipe with steps=[{asset_id, asset_type:'Gene', ...}]
35
+ // 5. POST /a2a/recipe/:id/publish -> appears at evomap.ai/market?tab=recipes
36
+ //
37
+ // Recipe is a plain REST resource on the Hub (NOT an A2A message_type), so we
38
+ // talk to it with a direct fetch + buildHubHeaders (Bearer node_secret), unlike
39
+ // publish/fetch which ride a2a.httpTransportSend.
40
+
41
+ const fs = require('fs');
42
+ const path = require('path');
43
+ const crypto = require('crypto');
44
+
45
+ const paths = require('./paths');
46
+ const assetStore = require('./assetStore');
47
+ const policyCheck = require('./policyCheck');
48
+ const skill2gep = require('./skill2gep');
49
+ const a2a = require('./a2aProtocol');
50
+ const { computeAssetId } = require('./contentHash');
51
+
52
+ const LOG_FILE = 'skill2recipes_log.jsonl';
53
+ const STATE_FILE = 'skill2recipes_state.json';
54
+ const VALIDATION_TIMEOUT_MS = 180000;
55
+ const RECIPE_TIMEOUT_MS = 20000;
56
+ const MAX_STEPS = 20; // mirrors recipeService.MAX_STEPS_PER_RECIPE
57
+
58
+ function ensureDir(p) { if (!fs.existsSync(p)) fs.mkdirSync(p, { recursive: true }); }
59
+
60
+ function readJsonSafe(p, fallback) {
61
+ try {
62
+ if (!fs.existsSync(p)) return fallback;
63
+ const raw = fs.readFileSync(p, 'utf8');
64
+ if (!raw.trim()) return fallback;
65
+ return JSON.parse(raw);
66
+ } catch (_) { return fallback; }
67
+ }
68
+
69
+ function appendJsonl(p, obj) {
70
+ ensureDir(path.dirname(p));
71
+ fs.appendFileSync(p, JSON.stringify(obj) + '\n', 'utf8');
72
+ }
73
+
74
+ function logPath() { return path.join(paths.getMemoryDir(), LOG_FILE); }
75
+ function statePath() { return path.join(paths.getMemoryDir(), STATE_FILE); }
76
+
77
+ function readState() { return readJsonSafe(statePath(), { recipes: {} }); }
78
+ function writeState(s) {
79
+ ensureDir(path.dirname(statePath()));
80
+ const tmp = statePath() + '.tmp';
81
+ fs.writeFileSync(tmp, JSON.stringify(s, null, 2) + '\n', 'utf8');
82
+ fs.renameSync(tmp, statePath());
83
+ }
84
+
85
+ function shortHash(s) {
86
+ return crypto.createHash('sha256').update(String(s || '')).digest('hex').slice(0, 12);
87
+ }
88
+
89
+ // ---------------------------------------------------------------------------
90
+ // Normalize a manifest into a list of steps. Accepts either:
91
+ // { title, description, steps: [{ skill_path, optional?, condition?, ... }] }
92
+ // { title, steps: ["./a", "./b"] } (bare paths)
93
+ // or a bare array of paths (CLI shorthand, title supplied separately).
94
+ // ---------------------------------------------------------------------------
95
+ function normalizeManifest(manifest, opts) {
96
+ opts = opts || {};
97
+ let m = manifest;
98
+ if (Array.isArray(manifest)) m = { steps: manifest };
99
+ m = m || {};
100
+
101
+ const rawSteps = Array.isArray(m.steps) ? m.steps
102
+ : Array.isArray(m.skills) ? m.skills
103
+ : [];
104
+ const steps = rawSteps.map((s, i) => {
105
+ const step = (typeof s === 'string') ? { skill_path: s } : (s || {});
106
+ const skillPath = step.skill_path || step.skillPath || step.path;
107
+ return {
108
+ skill_path: skillPath,
109
+ skill_name: step.skill_name || step.skillName || null,
110
+ platform: step.platform || null,
111
+ position: Number.isInteger(step.position) ? step.position : i,
112
+ optional: Boolean(step.optional),
113
+ condition: step.condition != null ? String(step.condition) : null,
114
+ parameters: step.parameters || null,
115
+ };
116
+ });
117
+
118
+ return {
119
+ title: opts.title || m.title || null,
120
+ description: opts.description || m.description || '',
121
+ price_per_execution: opts.pricePerExecution != null ? opts.pricePerExecution
122
+ : (m.price_per_execution != null ? m.price_per_execution : undefined),
123
+ currency: m.currency || undefined,
124
+ max_concurrent: m.max_concurrent != null ? m.max_concurrent : undefined,
125
+ input_schema: m.input_schema || null,
126
+ output_schema: m.output_schema || null,
127
+ steps: steps,
128
+ };
129
+ }
130
+
131
+ // ---------------------------------------------------------------------------
132
+ // Hydrolyze + verify a single skill into a published Gene asset.
133
+ //
134
+ // Returns { ok, gene, capsule, asset_id, asset_type, diagnostic }.
135
+ // asset_id is the *Gene* asset_id (sha256:...) once the bundle has been built;
136
+ // the recipe step references the Gene, with the Capsule riding along as the
137
+ // execution evidence that let it through the forgery guard.
138
+ // ---------------------------------------------------------------------------
139
+ function hydrolyzeAndVerify(step, opts) {
140
+ opts = opts || {};
141
+ const skillPath = step.skill_path;
142
+ if (!skillPath || !fs.existsSync(skillPath)) {
143
+ return { ok: false, diagnostic: { reason: 'skill_path_missing', skill_path: skillPath } };
144
+ }
145
+
146
+ let skillMdPath = skillPath;
147
+ try {
148
+ if (fs.statSync(skillPath).isDirectory()) skillMdPath = path.join(skillPath, 'SKILL.md');
149
+ } catch (_) { return { ok: false, diagnostic: { reason: 'skill_path_unreadable', skill_path: skillPath } }; }
150
+ if (!fs.existsSync(skillMdPath)) {
151
+ return { ok: false, diagnostic: { reason: 'skill_md_missing', tried: skillMdPath } };
152
+ }
153
+
154
+ let skillMd;
155
+ try { skillMd = fs.readFileSync(skillMdPath, 'utf8'); }
156
+ catch (err) { return { ok: false, diagnostic: { reason: 'skill_md_read_failed', error: errMsg(err) } }; }
157
+ const skillHash = shortHash(skillMd);
158
+
159
+ // -- 水解: parse + synthesize a validated Gene. strict=true here, because a
160
+ // recipe step with a fallback "node --version" validation would verify
161
+ // nothing -- we want every step to carry a real, runnable check.
162
+ const parsed = skill2gep.parseSkillMd(skillMd);
163
+ const geneRes = skill2gep.synthesizeGene(parsed, {}, {
164
+ skillName: step.skill_name || parsed.name,
165
+ platform: step.platform || null,
166
+ skillHash: skillHash,
167
+ strict: opts.strict !== false,
168
+ });
169
+ if (!geneRes.valid) {
170
+ return { ok: false, diagnostic: { reason: 'gene_validation_failed', errors: geneRes.errors } };
171
+ }
172
+ const gene = geneRes.gene;
173
+
174
+ // -- 验证: actually run the gene's validation commands in repoRoot. This is
175
+ // what produces the real execution trace that the Capsule needs.
176
+ const repoRoot = opts.repoRoot || paths.getRepoRoot();
177
+ const valRes = policyCheck.runValidations(gene, { repoRoot, timeoutMs: VALIDATION_TIMEOUT_MS });
178
+
179
+ const trace = (valRes.results || []).map((r, i) => ({
180
+ step: i + 1,
181
+ cmd: r.cmd,
182
+ exit: r.ok ? 0 : 1,
183
+ stdout_tail: String(r.out || r.err || '').slice(0, 300),
184
+ }));
185
+ const allPassed = Boolean(valRes.ok);
186
+ const execution = {
187
+ status: allPassed ? 'success' : 'failed',
188
+ score: allPassed ? 0.85 : 0.2,
189
+ started_at: new Date().toISOString(),
190
+ trace: trace,
191
+ // Blast radius for a verification-only run is the commands we executed;
192
+ // the forgery guard only needs *some* evidence (non-zero files/lines or a
193
+ // recorded exit), so we attribute one "file touched" per command run plus
194
+ // the gene's declared validation surface.
195
+ blast_radius: { files: Math.max(1, trace.length), lines: trace.length },
196
+ trigger: (gene.signals_match || []).slice(0, 6),
197
+ signals: gene.signals_match || [],
198
+ summary: 'Verified skill "' + (parsed.name || gene.id) + '": '
199
+ + trace.filter((t) => t.exit === 0).length + '/' + trace.length + ' validation command(s) passed.',
200
+ success_reason: allPassed ? 'All declared validation commands exited 0 in repoRoot.' : null,
201
+ };
202
+
203
+ // A step only earns a place in the recipe if its validation actually
204
+ // passed. Whether a failure aborts the recipe or is silently skipped is the
205
+ // caller's decision (based on step.optional) -- here we just report it
206
+ // unverified. (Without this, assembleCapsule would happily mint a
207
+ // failed-outcome Capsule, since the failing command is still "covered" by
208
+ // the trace, and the dud step would slip into the genome.)
209
+ if (!allPassed) {
210
+ return {
211
+ ok: false,
212
+ gene: gene,
213
+ diagnostic: { reason: 'validation_failed', failed: trace.filter((t) => t.exit !== 0).map((t) => t.cmd) },
214
+ };
215
+ }
216
+
217
+ // Forgery guard + capsule assembly (delegated to skill2gep's hardened logic).
218
+ const forgery = skill2gep.detectForgery(execution);
219
+ if (forgery) {
220
+ return { ok: false, gene: gene, diagnostic: { reason: 'capsule_rejected_forgery', detail: forgery } };
221
+ }
222
+ const capRes = skill2gep.assembleCapsule(gene, execution, { scenario: parsed.name });
223
+ if (!capRes.ok) {
224
+ return { ok: false, gene: gene, diagnostic: { reason: 'capsule_assembly_failed', detail: capRes } };
225
+ }
226
+
227
+ return {
228
+ ok: true,
229
+ gene: gene,
230
+ capsule: capRes.capsule,
231
+ skill_name: parsed.name,
232
+ skill_hash: skillHash,
233
+ execution: execution,
234
+ };
235
+ }
236
+
237
+ // ---------------------------------------------------------------------------
238
+ // Publish a Gene+Capsule bundle to the Hub and return the authoritative
239
+ // asset_ids.
240
+ //
241
+ // asset_id is content-addressed (computeAssetId), so we can stamp it WITHOUT a
242
+ // node_secret -- that lets dry runs (--no-publish) produce the exact same ids
243
+ // the Hub will store, without requiring node registration. The signed bundle
244
+ // (which needs the secret) is only built when we actually POST. Our capsule
245
+ // already carries a non-empty execution_trace from assembleCapsule, so
246
+ // buildPublishBundle's trace-synthesis path never fires and the id it computes
247
+ // matches the one we stamped here.
248
+ // ---------------------------------------------------------------------------
249
+ async function publishStepBundle(gene, capsule, opts) {
250
+ opts = opts || {};
251
+ const geneClone = JSON.parse(JSON.stringify(gene));
252
+ const capsuleClone = JSON.parse(JSON.stringify(capsule));
253
+
254
+ // Stamp content-addressed ids up front (no secret needed).
255
+ geneClone.asset_id = computeAssetId(geneClone);
256
+ capsuleClone.asset_id = computeAssetId(capsuleClone);
257
+ const geneAssetId = geneClone.asset_id;
258
+ const capsuleAssetId = capsuleClone.asset_id;
259
+
260
+ // Persist locally before/independently of the network round-trip so the
261
+ // assets survive a Hub outage (mirrors skill2gep's persist-then-publish).
262
+ const persistErrors = [];
263
+ try { assetStore.upsertGene(geneClone); }
264
+ catch (err) { persistErrors.push({ step: 'upsertGene', error: errMsg(err) }); }
265
+ try { assetStore.appendCapsule(capsuleClone); }
266
+ catch (err) { persistErrors.push({ step: 'appendCapsule', error: errMsg(err) }); }
267
+
268
+ if (opts.publish === false) {
269
+ return {
270
+ ok: true,
271
+ gene_asset_id: geneAssetId,
272
+ capsule_asset_id: capsuleAssetId,
273
+ publish: { skipped: 'publish_disabled' },
274
+ persist_errors: persistErrors,
275
+ };
276
+ }
277
+
278
+ let message;
279
+ try {
280
+ message = a2a.buildPublishBundle({ gene: geneClone, capsule: capsuleClone, nodeId: a2a.getNodeId() });
281
+ } catch (err) {
282
+ return { ok: false, reason: 'build_publish_bundle_failed', error: errMsg(err), gene_asset_id: geneAssetId, capsule_asset_id: capsuleAssetId, persist_errors: persistErrors };
283
+ }
284
+
285
+ let sendRes;
286
+ try {
287
+ sendRes = await Promise.resolve(a2a.httpTransportSend(message, {
288
+ hubUrl: a2a.getHubUrl(),
289
+ timeoutMs: 15000,
290
+ }));
291
+ } catch (err) {
292
+ sendRes = { ok: false, error: errMsg(err) };
293
+ }
294
+
295
+ return {
296
+ ok: Boolean(sendRes && sendRes.ok),
297
+ gene_asset_id: geneAssetId,
298
+ capsule_asset_id: capsuleAssetId,
299
+ publish: sendRes,
300
+ persist_errors: persistErrors,
301
+ };
302
+ }
303
+
304
+ // ---------------------------------------------------------------------------
305
+ // Create + publish the recipe on the Hub. Recipe is a REST resource, not an
306
+ // A2A message_type, so we POST directly with buildHubHeaders (Bearer
307
+ // node_secret). Returns { ok, recipe_id, create, publish }.
308
+ // ---------------------------------------------------------------------------
309
+ async function postRecipe(recipeBody, opts) {
310
+ opts = opts || {};
311
+ // Dry run: build the body and report it, but make no network calls at all.
312
+ if (opts.publish === false) {
313
+ return { ok: true, recipe_id: null, dry_run: true, body: recipeBody, publish: { skipped: 'publish_disabled' } };
314
+ }
315
+ const hubUrl = a2a.getHubUrl();
316
+ if (!hubUrl) return { ok: false, reason: 'no_hub_url' };
317
+ const base = hubUrl.replace(/\/+$/, '');
318
+ const headers = a2a.buildHubHeaders();
319
+
320
+ let createJson;
321
+ try {
322
+ const res = await fetch(base + '/a2a/recipe', {
323
+ method: 'POST',
324
+ headers: headers,
325
+ body: JSON.stringify(recipeBody),
326
+ signal: AbortSignal.timeout(RECIPE_TIMEOUT_MS),
327
+ });
328
+ const text = await res.text();
329
+ try { createJson = JSON.parse(text); } catch (_) { createJson = { raw: text }; }
330
+ if (!res.ok) return { ok: false, reason: 'recipe_create_failed', status: res.status, body: createJson };
331
+ } catch (err) {
332
+ return { ok: false, reason: 'recipe_create_request_failed', error: errMsg(err) };
333
+ }
334
+
335
+ const recipeId = createJson && createJson.recipe && (createJson.recipe.id || createJson.recipe.recipe_id);
336
+ if (!recipeId) return { ok: false, reason: 'recipe_id_missing', create: createJson };
337
+
338
+ if (opts.publish === false) {
339
+ return { ok: true, recipe_id: recipeId, create: createJson, publish: { skipped: 'publish_disabled' } };
340
+ }
341
+
342
+ let publishJson;
343
+ try {
344
+ const res = await fetch(base + '/a2a/recipe/' + encodeURIComponent(recipeId) + '/publish', {
345
+ method: 'POST',
346
+ headers: a2a.buildHubHeaders(),
347
+ body: JSON.stringify({ sender_id: recipeBody.sender_id }),
348
+ signal: AbortSignal.timeout(RECIPE_TIMEOUT_MS),
349
+ });
350
+ const text = await res.text();
351
+ try { publishJson = JSON.parse(text); } catch (_) { publishJson = { raw: text }; }
352
+ if (!res.ok) {
353
+ return { ok: false, reason: 'recipe_publish_failed', recipe_id: recipeId, status: res.status, body: publishJson, create: createJson };
354
+ }
355
+ } catch (err) {
356
+ return { ok: false, reason: 'recipe_publish_request_failed', recipe_id: recipeId, error: errMsg(err), create: createJson };
357
+ }
358
+
359
+ return { ok: true, recipe_id: recipeId, create: createJson, publish: publishJson };
360
+ }
361
+
362
+ function errMsg(err) { return err && err.message ? err.message : String(err); }
363
+
364
+ // ---------------------------------------------------------------------------
365
+ // Main entrypoint: composeRecipeFromSkills(manifest, opts)
366
+ //
367
+ // opts = {
368
+ // title, description, pricePerExecution -- override manifest fields
369
+ // repoRoot -- where validation commands run (default paths.getRepoRoot())
370
+ // publish -- false to do everything locally but skip Hub network calls
371
+ // strict -- default true: require real runnable validation per step
372
+ // }
373
+ //
374
+ // Returns {
375
+ // ok, recipe_id, steps: [{ skill_path, asset_id, asset_type, position, ... }],
376
+ // skipped: [{ skill_path, reason }], // optional steps that didn't verify
377
+ // gene_publish, recipe, errors
378
+ // }
379
+ // ---------------------------------------------------------------------------
380
+ async function composeRecipeFromSkills(manifest, opts) {
381
+ opts = opts || {};
382
+ const norm = normalizeManifest(manifest, opts);
383
+
384
+ if (!norm.title || norm.title.trim().length < 3) {
385
+ return { ok: false, reason: 'title_min_3_chars' };
386
+ }
387
+ if (!norm.steps.length) return { ok: false, reason: 'no_steps' };
388
+ if (norm.steps.length > MAX_STEPS) {
389
+ return { ok: false, reason: 'too_many_steps', max: MAX_STEPS, got: norm.steps.length };
390
+ }
391
+
392
+ const recipeSteps = [];
393
+ const skipped = [];
394
+ const genePublishResults = [];
395
+ const errors = [];
396
+
397
+ for (const step of norm.steps) {
398
+ const hv = hydrolyzeAndVerify(step, { repoRoot: opts.repoRoot, strict: opts.strict });
399
+ if (!hv.ok) {
400
+ if (step.optional) {
401
+ skipped.push({ skill_path: step.skill_path, reason: hv.diagnostic });
402
+ appendJsonl(logPath(), { timestamp: new Date().toISOString(), status: 'step_skipped_optional', skill_path: step.skill_path, diagnostic: hv.diagnostic });
403
+ continue;
404
+ }
405
+ // A required step that failed to hydrolyze/verify aborts the whole
406
+ // recipe -- we never publish a half-built genome.
407
+ appendJsonl(logPath(), { timestamp: new Date().toISOString(), status: 'step_failed_abort', skill_path: step.skill_path, diagnostic: hv.diagnostic });
408
+ return { ok: false, reason: 'step_failed', skill_path: step.skill_path, diagnostic: hv.diagnostic, steps_done: recipeSteps };
409
+ }
410
+
411
+ const pub = await publishStepBundle(hv.gene, hv.capsule, { publish: opts.publish });
412
+ genePublishResults.push({ skill_path: step.skill_path, gene_id: hv.gene.id, result: pub });
413
+ if (!pub.ok && opts.publish !== false) {
414
+ appendJsonl(logPath(), { timestamp: new Date().toISOString(), status: 'gene_publish_failed', skill_path: step.skill_path, result: pub });
415
+ if (step.optional) { skipped.push({ skill_path: step.skill_path, reason: { reason: 'gene_publish_failed', detail: pub } }); continue; }
416
+ return { ok: false, reason: 'gene_publish_failed', skill_path: step.skill_path, detail: pub, steps_done: recipeSteps };
417
+ }
418
+
419
+ recipeSteps.push({
420
+ asset_id: pub.gene_asset_id,
421
+ asset_type: 'Gene',
422
+ position: recipeSteps.length,
423
+ optional: step.optional,
424
+ condition: step.condition,
425
+ parameters: step.parameters,
426
+ _skill_path: step.skill_path,
427
+ _capsule_asset_id: pub.capsule_asset_id,
428
+ });
429
+ }
430
+
431
+ if (!recipeSteps.length) {
432
+ return { ok: false, reason: 'all_steps_skipped', skipped: skipped };
433
+ }
434
+
435
+ const senderId = a2a.getNodeId();
436
+ const recipeBody = {
437
+ sender_id: senderId,
438
+ title: norm.title,
439
+ description: norm.description || undefined,
440
+ steps: recipeSteps.map((s) => ({
441
+ asset_id: s.asset_id,
442
+ asset_type: s.asset_type,
443
+ position: s.position,
444
+ optional: s.optional,
445
+ condition: s.condition,
446
+ parameters: s.parameters,
447
+ })),
448
+ };
449
+ if (norm.price_per_execution != null) recipeBody.price_per_execution = norm.price_per_execution;
450
+ if (norm.currency) recipeBody.currency = norm.currency;
451
+ if (norm.max_concurrent != null) recipeBody.max_concurrent = norm.max_concurrent;
452
+ if (norm.input_schema) recipeBody.input_schema = norm.input_schema;
453
+ if (norm.output_schema) recipeBody.output_schema = norm.output_schema;
454
+
455
+ const recipeRes = await postRecipe(recipeBody, { publish: opts.publish });
456
+
457
+ const state = readState();
458
+ state.recipes = state.recipes || {};
459
+ const key = shortHash(norm.title + '|' + recipeSteps.map((s) => s.asset_id).join(','));
460
+ state.recipes[key] = {
461
+ at: new Date().toISOString(),
462
+ title: norm.title,
463
+ recipe_id: recipeRes.recipe_id || null,
464
+ step_asset_ids: recipeSteps.map((s) => s.asset_id),
465
+ published: Boolean(recipeRes.ok),
466
+ };
467
+ try { writeState(state); } catch (err) { errors.push({ step: 'writeState', error: errMsg(err) }); }
468
+
469
+ appendJsonl(logPath(), {
470
+ timestamp: new Date().toISOString(),
471
+ status: recipeRes.ok ? 'recipe_published' : 'recipe_failed',
472
+ title: norm.title,
473
+ recipe_id: recipeRes.recipe_id || null,
474
+ step_count: recipeSteps.length,
475
+ skipped_count: skipped.length,
476
+ recipe_result: recipeRes,
477
+ });
478
+
479
+ return {
480
+ ok: Boolean(recipeRes.ok),
481
+ recipe_id: recipeRes.recipe_id || null,
482
+ title: norm.title,
483
+ market_url: recipeRes.recipe_id ? 'https://evomap.ai/market?tab=recipes' : null,
484
+ steps: recipeSteps.map((s) => ({
485
+ skill_path: s._skill_path,
486
+ asset_id: s.asset_id,
487
+ asset_type: s.asset_type,
488
+ position: s.position,
489
+ optional: s.optional,
490
+ condition: s.condition,
491
+ capsule_asset_id: s._capsule_asset_id,
492
+ })),
493
+ skipped: skipped,
494
+ gene_publish: genePublishResults,
495
+ recipe: recipeRes,
496
+ errors: errors,
497
+ };
498
+ }
499
+
500
+ module.exports = {
501
+ LOG_FILE,
502
+ STATE_FILE,
503
+ MAX_STEPS,
504
+ normalizeManifest,
505
+ hydrolyzeAndVerify,
506
+ publishStepBundle,
507
+ postRecipe,
508
+ composeRecipeFromSkills,
509
+ logPath,
510
+ statePath,
511
+ };