@evomap/evolver 1.89.20 → 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/README.md +27 -564
- package/bin/evolver-llm-proxy.js +3 -0
- package/bin/evolver-mcp.js +2 -0
- package/bin/evolver-proxy.js +3 -0
- package/bin/evolver.js +4 -0
- package/index.js +1 -3586
- package/package.json +32 -62
- package/CONTRIBUTING.md +0 -19
- package/LICENSE +0 -641
- package/README.ja-JP.md +0 -521
- package/README.ko-KR.md +0 -520
- package/README.zh-CN.md +0 -531
- package/SKILL.md +0 -365
- package/assets/cover.png +0 -0
- package/assets/gep/genes.seed.json +0 -496
- package/conformance/savings-core/constants.json +0 -30
- package/conformance/savings-core/golden-vectors.json +0 -333
- package/scripts/a2a_export.js +0 -63
- package/scripts/a2a_ingest.js +0 -79
- package/scripts/a2a_promote.js +0 -118
- package/scripts/analyze_by_skill.js +0 -121
- package/scripts/build_binaries.js +0 -479
- package/scripts/check-changelog.js +0 -166
- package/scripts/extract_log.js +0 -85
- package/scripts/generate_history.js +0 -75
- package/scripts/gep_append_event.js +0 -96
- package/scripts/gep_personality_report.js +0 -234
- package/scripts/human_report.js +0 -147
- package/scripts/recall-verify-report.js +0 -234
- package/scripts/recover_loop.js +0 -61
- package/scripts/refresh_stars_badge.js +0 -168
- package/scripts/seed-merchants.js +0 -91
- package/scripts/skill2recipes.js +0 -118
- package/scripts/suggest_version.js +0 -89
- package/scripts/validate-modules.js +0 -38
- package/scripts/validate-suite.js +0 -78
- package/skills/_meta/SKILL.md +0 -41
- package/skills/index.json +0 -14
- package/src/adapters/claudeCode.js +0 -194
- package/src/adapters/codex.js +0 -216
- package/src/adapters/cursor.js +0 -91
- package/src/adapters/hookAdapter.js +0 -469
- package/src/adapters/kiro.js +0 -195
- package/src/adapters/opencode.js +0 -326
- package/src/adapters/scripts/_lockPaths.js +0 -74
- package/src/adapters/scripts/_memoryFiltering.js +0 -35
- package/src/adapters/scripts/_runtimePaths.js +0 -440
- package/src/adapters/scripts/evolver-session-end.js +0 -321
- package/src/adapters/scripts/evolver-session-start.js +0 -587
- package/src/adapters/scripts/evolver-signal-detect.js +0 -98
- package/src/adapters/scripts/evolver-task-recall.js +0 -173
- package/src/atp/atpExecute.js +0 -283
- package/src/atp/atpTaskPickup.js +0 -233
- package/src/atp/autoBuyer.js +0 -382
- package/src/atp/autoDeliver.js +0 -215
- package/src/atp/cli.js +0 -354
- package/src/atp/cliAutobuyPrompt.js +0 -154
- package/src/atp/consumerAgent.js +0 -157
- package/src/atp/defaultHandler.js +0 -69
- package/src/atp/heartbeatSignalsHandler.js +0 -254
- package/src/atp/hubClient.js +0 -317
- package/src/atp/index.js +0 -38
- package/src/atp/merchantAgent.js +0 -118
- package/src/atp/protocol.js +0 -41
- package/src/atp/questionComposer.js +0 -133
- package/src/atp/serviceHelper.js +0 -92
- package/src/canary.js +0 -13
- package/src/config.js +0 -351
- package/src/evolve/guards.js +0 -1
- package/src/evolve/pipeline/collect.js +0 -1
- package/src/evolve/pipeline/dispatch.js +0 -1
- package/src/evolve/pipeline/enrich.js +0 -1
- package/src/evolve/pipeline/hub.js +0 -1
- package/src/evolve/pipeline/select.js +0 -1
- package/src/evolve/pipeline/signals.js +0 -1
- package/src/evolve/utils.js +0 -1
- package/src/evolve.js +0 -1
- package/src/experiment/agentRunner.js +0 -229
- package/src/experiment/cli.js +0 -159
- package/src/experiment/comparison.js +0 -233
- package/src/experiment/metrics.js +0 -75
- package/src/forceUpdate.js +0 -991
- package/src/gep/a2a.js +0 -173
- package/src/gep/a2aProtocol.js +0 -1
- package/src/gep/analyzer.js +0 -35
- package/src/gep/antiAbuseTelemetry.js +0 -1
- package/src/gep/assetCallLog.js +0 -197
- package/src/gep/assetStore.js +0 -723
- package/src/gep/assets.js +0 -36
- package/src/gep/autoDistillConv.js +0 -1
- package/src/gep/autoDistillLlm.js +0 -1
- package/src/gep/bridge.js +0 -138
- package/src/gep/candidateEval.js +0 -1
- package/src/gep/candidates.js +0 -1
- package/src/gep/claimNudge.js +0 -121
- package/src/gep/cliContracts.js +0 -1190
- package/src/gep/contentHash.js +0 -1
- package/src/gep/conversationDistiller.js +0 -1
- package/src/gep/conversationSniffer.js +0 -1
- package/src/gep/crypto.js +0 -1
- package/src/gep/curriculum.js +0 -1
- package/src/gep/deviceId.js +0 -1
- package/src/gep/directoryClient.js +0 -115
- package/src/gep/envFingerprint.js +0 -1
- package/src/gep/epigenetics.js +0 -1
- package/src/gep/execBridge.js +0 -1
- package/src/gep/executionTrace.js +0 -291
- package/src/gep/explore.js +0 -1
- package/src/gep/featureFlags.js +0 -121
- package/src/gep/gitOps.js +0 -265
- package/src/gep/hash.js +0 -1
- package/src/gep/hostErrorClassifier.js +0 -34
- package/src/gep/hubFetch.js +0 -1
- package/src/gep/hubReview.js +0 -1
- package/src/gep/hubSearch.js +0 -1
- package/src/gep/hubVerify.js +0 -1
- package/src/gep/idleScheduler.js +0 -400
- package/src/gep/issueReporter.js +0 -416
- package/src/gep/learningSignals.js +0 -1
- package/src/gep/llmReview.js +0 -92
- package/src/gep/localStateAwareness.js +0 -243
- package/src/gep/mailboxTransport.js +0 -119
- package/src/gep/memoryGraph.js +0 -1
- package/src/gep/memoryGraphAdapter.js +0 -1
- package/src/gep/mutation.js +0 -1
- package/src/gep/narrativeMemory.js +0 -1
- package/src/gep/oauthLogin.js +0 -181
- package/src/gep/openPRRegistry.js +0 -1
- package/src/gep/paths.js +0 -522
- package/src/gep/personality.js +0 -1
- package/src/gep/policyCheck.js +0 -1
- package/src/gep/portable.js +0 -103
- package/src/gep/privacyClient.js +0 -235
- package/src/gep/prompt.js +0 -1
- package/src/gep/questionGenerator.js +0 -518
- package/src/gep/recallInject.js +0 -1
- package/src/gep/recallVerifier.js +0 -1
- package/src/gep/reflection.js +0 -1
- package/src/gep/sanitize.js +0 -264
- package/src/gep/savingsCore.js +0 -1
- package/src/gep/schemas/capsule.js +0 -170
- package/src/gep/schemas/gene.js +0 -154
- package/src/gep/schemas/index.js +0 -8
- package/src/gep/schemas/protocol.js +0 -51
- package/src/gep/schemas/task.js +0 -74
- package/src/gep/selector.js +0 -1
- package/src/gep/selfPR.js +0 -469
- package/src/gep/signals.js +0 -776
- package/src/gep/skill2gep.js +0 -1056
- package/src/gep/skill2gepAudit.js +0 -303
- package/src/gep/skill2recipes.js +0 -511
- package/src/gep/skillDistiller.js +0 -1
- package/src/gep/skillPublisher.js +0 -358
- package/src/gep/solidify.js +0 -1
- package/src/gep/strategy.js +0 -1
- package/src/gep/taskReceiver.js +0 -575
- package/src/gep/tokenSavings.js +0 -1
- package/src/gep/trajectoryExport.js +0 -1
- package/src/gep/validationReport.js +0 -55
- package/src/gep/validator/index.js +0 -411
- package/src/gep/validator/reporter.js +0 -210
- package/src/gep/validator/sandboxExecutor.js +0 -480
- package/src/gep/validator/stakeBootstrap.js +0 -357
- package/src/gep/workspaceKeychain.js +0 -1
- package/src/ops/cleanup.js +0 -80
- package/src/ops/commentary.js +0 -60
- package/src/ops/health_check.js +0 -104
- package/src/ops/index.js +0 -11
- package/src/ops/innovation.js +0 -67
- package/src/ops/lifecycle.js +0 -798
- package/src/ops/self_repair.js +0 -76
- package/src/ops/skills_monitor.js +0 -147
- package/src/ops/trigger.js +0 -33
- package/src/proxy/clientSettings.js +0 -405
- package/src/proxy/envelope.js +0 -59
- package/src/proxy/extensions/dmHandler.js +0 -45
- package/src/proxy/extensions/sessionHandler.js +0 -141
- package/src/proxy/extensions/skillUpdater.js +0 -64
- package/src/proxy/extensions/traceControl.js +0 -1
- package/src/proxy/index.js +0 -1395
- package/src/proxy/inject.js +0 -1
- package/src/proxy/lifecycle/manager.js +0 -1568
- package/src/proxy/mailbox/state.js +0 -207
- package/src/proxy/mailbox/store.js +0 -590
- package/src/proxy/router/cache_passthrough.js +0 -26
- package/src/proxy/router/features.js +0 -84
- package/src/proxy/router/gemini_route.js +0 -154
- package/src/proxy/router/messages_route.js +0 -535
- package/src/proxy/router/model_router.js +0 -113
- package/src/proxy/router/models_route.js +0 -52
- package/src/proxy/router/ollama_route.js +0 -103
- package/src/proxy/router/responses_route.js +0 -170
- package/src/proxy/router/vertex_route.js +0 -110
- package/src/proxy/server/http.js +0 -363
- package/src/proxy/server/routes.js +0 -558
- package/src/proxy/server/settings.js +0 -115
- package/src/proxy/sync/engine.js +0 -179
- package/src/proxy/sync/inbound.js +0 -211
- package/src/proxy/sync/outbound.js +0 -320
- package/src/proxy/task/monitor.js +0 -131
- package/src/proxy/trace/extractor.js +0 -1
- package/src/proxy/trace/usage.js +0 -1
- package/src/webui/client/clientJs/assets.js +0 -111
- package/src/webui/client/clientJs/bootstrap.js +0 -92
- package/src/webui/client/clientJs/common.js +0 -77
- package/src/webui/client/clientJs/i18n.js +0 -366
- package/src/webui/client/clientJs/index.js +0 -35
- package/src/webui/client/clientJs/interactions.js +0 -351
- package/src/webui/client/clientJs/overview.js +0 -152
- package/src/webui/client/clientJs/personality.js +0 -285
- package/src/webui/client/clientJs/pipelines.js +0 -330
- package/src/webui/client/indexHtml.js +0 -221
- package/src/webui/client/static.js +0 -23
- package/src/webui/client/stylesCss.js +0 -639
- package/src/webui/client/vendor/README.md +0 -15
- package/src/webui/client/vendor/echarts.min.js +0 -45
- package/src/webui/index.js +0 -14
- package/src/webui/observer/assets.js +0 -146
- package/src/webui/observer/index.js +0 -37
- package/src/webui/observer/interactions.js +0 -127
- package/src/webui/observer/jsonl.js +0 -75
- package/src/webui/observer/paths.js +0 -46
- package/src/webui/observer/personality.js +0 -43
- package/src/webui/observer/pipelineEvents.js +0 -58
- package/src/webui/observer/redact.js +0 -63
- package/src/webui/observer/runs.js +0 -356
- package/src/webui/observer/safety.js +0 -57
- package/src/webui/observer/skills.js +0 -70
- package/src/webui/observer/status.js +0 -71
- package/src/webui/server/http.js +0 -138
- package/src/webui/server/routes.js +0 -41
package/src/gep/skill2recipes.js
DELETED
|
@@ -1,511 +0,0 @@
|
|
|
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
|
-
};
|