@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
|
@@ -0,0 +1,410 @@
|
|
|
1
|
+
// `evolver setup-hooks` — wire (or remove) evolver into an agent runtime. Drives the evolver-mcp installer:
|
|
2
|
+
// for Claude Code it registers the evolver MCP server AND merges a SessionStart hook so memory is injected at
|
|
3
|
+
// session start (the hybrid). `--scope=user` registers into ~/.claude.json so evolver loads in EVERY project
|
|
4
|
+
// (the real device-wide scope); `--scope=project` (default) writes the project's own .mcp.json. Deny-nothing:
|
|
5
|
+
// it only writes the runtime's own config, is idempotent, refuses symlinked adapter paths, and `--uninstall`
|
|
6
|
+
// cleanly removes only evolver's entries.
|
|
7
|
+
import { planInjection, installInjection, uninstallInjection, runtimeSupport, renderManualWiring, renderServiceGuidance, SETUP_RUNTIMES, SERVICE_TARGETS } from '@evomap/evolver-mcp';
|
|
8
|
+
import { assetstore, events } from '@evomap/evolver-core';
|
|
9
|
+
import { readFileSync } from 'node:fs';
|
|
10
|
+
import { createRequire } from 'node:module';
|
|
11
|
+
import { fileURLToPath } from 'node:url';
|
|
12
|
+
import { currentTopCursorGenes } from './cursorRewrite.js';
|
|
13
|
+
import { resolveProxyBinPath, resolveStableNodePath } from './lifecycle.js';
|
|
14
|
+
import { reviewLedgerForStore } from './reviewFilter.js';
|
|
15
|
+
const requireFromHere = createRequire(import.meta.url);
|
|
16
|
+
function parseFlags(argv) {
|
|
17
|
+
const out = {};
|
|
18
|
+
for (let i = 0; i < argv.length; i++) {
|
|
19
|
+
const a = argv[i];
|
|
20
|
+
if (a && a.startsWith('--')) {
|
|
21
|
+
const key = a.slice(2);
|
|
22
|
+
const eq = key.indexOf('=');
|
|
23
|
+
if (eq >= 0) {
|
|
24
|
+
out[key.slice(0, eq)] = key.slice(eq + 1);
|
|
25
|
+
}
|
|
26
|
+
else if (argv[i + 1] && !argv[i + 1].startsWith('--')) {
|
|
27
|
+
out[key] = argv[++i];
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
out[key] = true;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return out;
|
|
35
|
+
}
|
|
36
|
+
const USAGE = `usage: evolver setup-hooks [--runtime=${SETUP_RUNTIMES.join('|')}] [--scope=user|project|global] [--root=<dir>] [--env-file=<path>] [--profile-descriptor=<json>] [--service=${SERVICE_TARGETS.join('|')}] [--uninstall] [--force] [--json] [--hook-command="evolver inject session-start"] [--server-command=<cmd>] [--server-args=a,b] [--service-command=<cmd>] [--service-args=a,b]\n`;
|
|
37
|
+
const PROFILE_DESCRIPTOR_FLAG = 'profile-descriptor';
|
|
38
|
+
const SECRET_ASSIGNMENT_RE = /\b(?:A2A_NODE_SECRET|EVOMAP_ENTERPRISE_TOKEN|EVOMAP_PRIVATE_HUB_TOKEN|EVOMAP_NODE_SECRET|EVOLVER_IPC_TOKEN|EVOLVER_LLM_TOKEN|PHUB_ENTERPRISE_TOKEN|PRIVATE_HUB_ENTERPRISE_TOKEN)\b\s*[:=]\s*["']?[^"'\s<]+/;
|
|
39
|
+
const INLINE_BEARER_RE = /\bBearer\s+(?!<|\$|%|REDACTED\b|TOKEN\b|token\b|env:)[A-Za-z0-9._~+/=-]{12,}/i;
|
|
40
|
+
const INLINE_SECRET_FLAG_RE = /(?:^|\s)--?(?:api[-_]?key|password|passwd|secret|token)(?:=|\s+)["']?(?!<|\$|%|REDACTED\b|TOKEN\b|token\b|env:)[^"'\s]+/i;
|
|
41
|
+
const RAW_SECRET_VALUE_RE = /^(?=.{16,}$)(?!.*[\\/])(?=.*(?:evomap|key|phub|private|secret|token))(?=.*[A-Za-z])(?=.*\d)[A-Za-z0-9._~+/=-]+$/i;
|
|
42
|
+
/** Map and validate --scope before any config write. Omitted keeps the legacy project default; values are
|
|
43
|
+
* intentionally case-sensitive so typos do not silently install into project scope. */
|
|
44
|
+
function parseScope(raw) {
|
|
45
|
+
if (raw === undefined)
|
|
46
|
+
return { ok: true, scope: 'project' };
|
|
47
|
+
if (raw === 'project')
|
|
48
|
+
return { ok: true, scope: 'project' };
|
|
49
|
+
if (raw === 'user' || raw === 'global')
|
|
50
|
+
return { ok: true, scope: 'user' };
|
|
51
|
+
if (raw === true) {
|
|
52
|
+
return { ok: false, error: 'missing value for --scope (expected: project|user|global)' };
|
|
53
|
+
}
|
|
54
|
+
return { ok: false, error: `invalid --scope '${raw}' (expected: project|user|global; values are case-sensitive)` };
|
|
55
|
+
}
|
|
56
|
+
function isRecord(value) {
|
|
57
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
58
|
+
}
|
|
59
|
+
function hasInlineSecretSyntax(value) {
|
|
60
|
+
return SECRET_ASSIGNMENT_RE.test(value) || INLINE_BEARER_RE.test(value) || INLINE_SECRET_FLAG_RE.test(value);
|
|
61
|
+
}
|
|
62
|
+
function hasInlineSecretHint(hint) {
|
|
63
|
+
const trimmed = hint.trim();
|
|
64
|
+
return hasInlineSecretSyntax(trimmed) || RAW_SECRET_VALUE_RE.test(trimmed);
|
|
65
|
+
}
|
|
66
|
+
function looksLikeEnvFilePointer(value) {
|
|
67
|
+
return /[\\/]/.test(value)
|
|
68
|
+
|| /^[A-Za-z]:[\\/]/.test(value)
|
|
69
|
+
|| /^[.~$%]/.test(value)
|
|
70
|
+
|| /\.(?:env|dotenv)(?:$|[._-])/i.test(value);
|
|
71
|
+
}
|
|
72
|
+
function validatePointerValue(label, value) {
|
|
73
|
+
const trimmed = value.trim();
|
|
74
|
+
return hasInlineSecretSyntax(trimmed) || (!looksLikeEnvFilePointer(trimmed) && RAW_SECRET_VALUE_RE.test(trimmed))
|
|
75
|
+
? `--${PROFILE_DESCRIPTOR_FLAG}.${label} contains an inline secret-looking value; use an EVOLVER_ENV_FILE pointer path instead`
|
|
76
|
+
: undefined;
|
|
77
|
+
}
|
|
78
|
+
function profileDescriptorFromFlag(f) {
|
|
79
|
+
const rawPath = f[PROFILE_DESCRIPTOR_FLAG];
|
|
80
|
+
if (rawPath === undefined)
|
|
81
|
+
return { ok: true, descriptor: { manualHints: {} } };
|
|
82
|
+
if (rawPath === true || rawPath.trim().length === 0) {
|
|
83
|
+
return { ok: false, error: `missing value for --${PROFILE_DESCRIPTOR_FLAG}` };
|
|
84
|
+
}
|
|
85
|
+
let parsed;
|
|
86
|
+
try {
|
|
87
|
+
parsed = JSON.parse(readFileSync(rawPath, 'utf8'));
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
return { ok: false, error: `cannot read --${PROFILE_DESCRIPTOR_FLAG}: ${error instanceof Error ? error.message : String(error)}` };
|
|
91
|
+
}
|
|
92
|
+
if (!isRecord(parsed)) {
|
|
93
|
+
return { ok: false, error: `--${PROFILE_DESCRIPTOR_FLAG} must be a JSON object` };
|
|
94
|
+
}
|
|
95
|
+
const envFileRaw = parsed['envFile'] ?? parsed['env_file'];
|
|
96
|
+
let envFile;
|
|
97
|
+
if (envFileRaw !== undefined) {
|
|
98
|
+
if (typeof envFileRaw !== 'string' || envFileRaw.trim().length === 0) {
|
|
99
|
+
return { ok: false, error: `--${PROFILE_DESCRIPTOR_FLAG}.envFile must be a non-empty string` };
|
|
100
|
+
}
|
|
101
|
+
envFile = envFileRaw.trim();
|
|
102
|
+
const error = validatePointerValue('envFile', envFile);
|
|
103
|
+
if (error)
|
|
104
|
+
return { ok: false, error };
|
|
105
|
+
}
|
|
106
|
+
const mcpServer = parseDescriptorServer(parsed['mcpServer'] ?? parsed['mcp_server'], 'mcpServer');
|
|
107
|
+
if (!mcpServer.ok)
|
|
108
|
+
return mcpServer;
|
|
109
|
+
const serviceExec = parseDescriptorServer(parsed['serviceExec'] ?? parsed['service_exec'], 'serviceExec');
|
|
110
|
+
if (!serviceExec.ok)
|
|
111
|
+
return serviceExec;
|
|
112
|
+
const hintsByRuntime = parsed['manualHints'] ?? parsed['manual_hints'];
|
|
113
|
+
const manualHints = {};
|
|
114
|
+
if (hintsByRuntime === undefined) {
|
|
115
|
+
return {
|
|
116
|
+
ok: true,
|
|
117
|
+
descriptor: {
|
|
118
|
+
...(envFile !== undefined ? { envFile } : {}),
|
|
119
|
+
...(mcpServer.server ? { mcpServer: mcpServer.server } : {}),
|
|
120
|
+
...(serviceExec.server ? { serviceExec: serviceExec.server } : {}),
|
|
121
|
+
manualHints,
|
|
122
|
+
},
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
if (!isRecord(hintsByRuntime)) {
|
|
126
|
+
return { ok: false, error: `--${PROFILE_DESCRIPTOR_FLAG}.manualHints must be an object keyed by runtime` };
|
|
127
|
+
}
|
|
128
|
+
for (const [runtime, runtimeHints] of Object.entries(hintsByRuntime)) {
|
|
129
|
+
if (!Array.isArray(runtimeHints) || runtimeHints.some((hint) => typeof hint !== 'string')) {
|
|
130
|
+
return { ok: false, error: `--${PROFILE_DESCRIPTOR_FLAG}.manualHints.${runtime} must be an array of strings` };
|
|
131
|
+
}
|
|
132
|
+
const hints = runtimeHints.map((hint) => hint.trim()).filter(Boolean);
|
|
133
|
+
const secretHint = hints.find(hasInlineSecretHint);
|
|
134
|
+
if (secretHint) {
|
|
135
|
+
return { ok: false, error: `--${PROFILE_DESCRIPTOR_FLAG}.manualHints.${runtime} contains an inline secret-looking value; use an EVOLVER_ENV_FILE pointer instead` };
|
|
136
|
+
}
|
|
137
|
+
manualHints[runtime] = hints;
|
|
138
|
+
}
|
|
139
|
+
return {
|
|
140
|
+
ok: true,
|
|
141
|
+
descriptor: {
|
|
142
|
+
...(envFile !== undefined ? { envFile } : {}),
|
|
143
|
+
...(mcpServer.server ? { mcpServer: mcpServer.server } : {}),
|
|
144
|
+
...(serviceExec.server ? { serviceExec: serviceExec.server } : {}),
|
|
145
|
+
manualHints,
|
|
146
|
+
},
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
function parseDescriptorServer(value, label) {
|
|
150
|
+
if (value === undefined)
|
|
151
|
+
return { ok: true };
|
|
152
|
+
if (!isRecord(value)) {
|
|
153
|
+
return { ok: false, error: `--${PROFILE_DESCRIPTOR_FLAG}.${label} must be an object` };
|
|
154
|
+
}
|
|
155
|
+
if (typeof value['command'] !== 'string' || value['command'].trim().length === 0) {
|
|
156
|
+
return { ok: false, error: `--${PROFILE_DESCRIPTOR_FLAG}.${label}.command must be a non-empty string` };
|
|
157
|
+
}
|
|
158
|
+
const argsRaw = value['args'];
|
|
159
|
+
if (argsRaw !== undefined && (!Array.isArray(argsRaw) || argsRaw.some((arg) => typeof arg !== 'string'))) {
|
|
160
|
+
return { ok: false, error: `--${PROFILE_DESCRIPTOR_FLAG}.${label}.args must be an array of strings` };
|
|
161
|
+
}
|
|
162
|
+
const command = value['command'].trim();
|
|
163
|
+
const args = argsRaw;
|
|
164
|
+
const commandLine = [command, ...(args ?? [])].join(' ');
|
|
165
|
+
if (hasInlineSecretHint(commandLine)) {
|
|
166
|
+
return { ok: false, error: `--${PROFILE_DESCRIPTOR_FLAG}.${label}.command/args contain an inline secret-looking value; use an EVOLVER_ENV_FILE pointer instead` };
|
|
167
|
+
}
|
|
168
|
+
const envRaw = value['env'];
|
|
169
|
+
let env;
|
|
170
|
+
if (envRaw !== undefined) {
|
|
171
|
+
if (!isRecord(envRaw))
|
|
172
|
+
return { ok: false, error: `--${PROFILE_DESCRIPTOR_FLAG}.${label}.env must be an object` };
|
|
173
|
+
const keys = Object.keys(envRaw);
|
|
174
|
+
const unsupported = keys.filter((key) => key !== 'EVOLVER_ENV_FILE');
|
|
175
|
+
if (unsupported.length > 0) {
|
|
176
|
+
return { ok: false, error: `--${PROFILE_DESCRIPTOR_FLAG}.${label}.env may only contain EVOLVER_ENV_FILE` };
|
|
177
|
+
}
|
|
178
|
+
const envFile = envRaw['EVOLVER_ENV_FILE'];
|
|
179
|
+
if (envFile !== undefined) {
|
|
180
|
+
if (typeof envFile !== 'string' || envFile.trim().length === 0) {
|
|
181
|
+
return { ok: false, error: `--${PROFILE_DESCRIPTOR_FLAG}.${label}.env.EVOLVER_ENV_FILE must be a non-empty string` };
|
|
182
|
+
}
|
|
183
|
+
const pointer = envFile.trim();
|
|
184
|
+
const error = validatePointerValue(`${label}.env.EVOLVER_ENV_FILE`, pointer);
|
|
185
|
+
if (error)
|
|
186
|
+
return { ok: false, error };
|
|
187
|
+
env = { EVOLVER_ENV_FILE: pointer };
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
return {
|
|
191
|
+
ok: true,
|
|
192
|
+
server: {
|
|
193
|
+
command,
|
|
194
|
+
...(args !== undefined ? { args } : {}),
|
|
195
|
+
...(env ? { env } : {}),
|
|
196
|
+
},
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
function argsFromFlag(value) {
|
|
200
|
+
return typeof value === 'string' ? value.split(',').filter(Boolean) : undefined;
|
|
201
|
+
}
|
|
202
|
+
function defaultMcpServer() {
|
|
203
|
+
let stdioPath;
|
|
204
|
+
try {
|
|
205
|
+
stdioPath = requireFromHere.resolve('@evomap/evolver-mcp/stdio');
|
|
206
|
+
}
|
|
207
|
+
catch {
|
|
208
|
+
stdioPath = fileURLToPath(new URL('../../evolver-mcp/dist/stdio.js', import.meta.url));
|
|
209
|
+
}
|
|
210
|
+
return { command: process.execPath, args: [stdioPath] };
|
|
211
|
+
}
|
|
212
|
+
function defaultProxyDaemon() {
|
|
213
|
+
return { command: resolveStableNodePath(), args: [resolveProxyBinPath() ?? '/ABSOLUTE/PATH/TO/evolver-proxy.js'] };
|
|
214
|
+
}
|
|
215
|
+
function withEnvFile(server, envFile) {
|
|
216
|
+
if (typeof envFile !== 'string' || !envFile.trim())
|
|
217
|
+
return server;
|
|
218
|
+
return {
|
|
219
|
+
...server,
|
|
220
|
+
env: {
|
|
221
|
+
...(server.env ?? {}),
|
|
222
|
+
EVOLVER_ENV_FILE: envFile.trim(),
|
|
223
|
+
},
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
/** The evolver MCP stdio server command (default or --server-command/--server-args), with the --env-file pointer
|
|
227
|
+
* merged in. Shared by the installed path (registered into config) and the manual path (rendered into wiring text). */
|
|
228
|
+
function descriptorEnvFile(f, descriptor, descriptorServer) {
|
|
229
|
+
if (typeof f['env-file'] === 'string' && f['env-file'].trim().length > 0)
|
|
230
|
+
return f['env-file'];
|
|
231
|
+
return descriptorServer?.env?.['EVOLVER_ENV_FILE'] ?? descriptor.envFile;
|
|
232
|
+
}
|
|
233
|
+
function buildServer(f, descriptor = { manualHints: {} }) {
|
|
234
|
+
const serverArgs = argsFromFlag(f['server-args']);
|
|
235
|
+
const serverBase = typeof f['server-command'] === 'string'
|
|
236
|
+
? {
|
|
237
|
+
command: f['server-command'],
|
|
238
|
+
...(serverArgs !== undefined ? { args: serverArgs } : {}),
|
|
239
|
+
...(serverArgs === undefined && descriptor.mcpServer?.args ? { args: descriptor.mcpServer.args } : {}),
|
|
240
|
+
}
|
|
241
|
+
: descriptor.mcpServer
|
|
242
|
+
? {
|
|
243
|
+
...descriptor.mcpServer,
|
|
244
|
+
...(serverArgs !== undefined ? { args: serverArgs } : {}),
|
|
245
|
+
}
|
|
246
|
+
: {
|
|
247
|
+
...defaultMcpServer(),
|
|
248
|
+
...(serverArgs !== undefined ? { args: serverArgs } : {}),
|
|
249
|
+
};
|
|
250
|
+
return withEnvFile(serverBase, descriptorEnvFile(f, descriptor, descriptor.mcpServer));
|
|
251
|
+
}
|
|
252
|
+
function buildServiceExec(f, descriptor = { manualHints: {} }) {
|
|
253
|
+
const serviceArgs = argsFromFlag(f['service-args']);
|
|
254
|
+
const serviceBase = typeof f['service-command'] === 'string'
|
|
255
|
+
? {
|
|
256
|
+
command: f['service-command'],
|
|
257
|
+
...(serviceArgs !== undefined ? { args: serviceArgs } : {}),
|
|
258
|
+
...(serviceArgs === undefined && descriptor.serviceExec?.args ? { args: descriptor.serviceExec.args } : {}),
|
|
259
|
+
}
|
|
260
|
+
: descriptor.serviceExec
|
|
261
|
+
? {
|
|
262
|
+
...descriptor.serviceExec,
|
|
263
|
+
...(serviceArgs !== undefined ? { args: serviceArgs } : {}),
|
|
264
|
+
}
|
|
265
|
+
: {
|
|
266
|
+
...defaultProxyDaemon(),
|
|
267
|
+
...(serviceArgs !== undefined ? { args: serviceArgs } : {}),
|
|
268
|
+
};
|
|
269
|
+
return withEnvFile(serviceBase, descriptorEnvFile(f, descriptor, descriptor.serviceExec));
|
|
270
|
+
}
|
|
271
|
+
function appendAdapterNotes(text, hints) {
|
|
272
|
+
return hints && hints.length > 0
|
|
273
|
+
? `${text}\n\nAdapter notes:\n${hints.map((hint) => ` - ${hint}`).join('\n')}`
|
|
274
|
+
: text;
|
|
275
|
+
}
|
|
276
|
+
export async function runSetupHooks(argv, store, review) {
|
|
277
|
+
const f = parseFlags(argv);
|
|
278
|
+
const runtimeRaw = typeof f['runtime'] === 'string'
|
|
279
|
+
? f['runtime']
|
|
280
|
+
: (typeof f['platform'] === 'string' ? f['platform'] : 'claude-code');
|
|
281
|
+
const json = f['json'] === true;
|
|
282
|
+
const emit = (obj) => { if (json)
|
|
283
|
+
process.stdout.write(`${JSON.stringify(obj)}\n`); };
|
|
284
|
+
const scopeResult = parseScope(f['scope']);
|
|
285
|
+
if (!scopeResult.ok) {
|
|
286
|
+
if (json)
|
|
287
|
+
emit({ runtime: runtimeRaw, outcome: 'error', files: [], error: scopeResult.error });
|
|
288
|
+
else
|
|
289
|
+
process.stderr.write(`${scopeResult.error}\n${USAGE}`);
|
|
290
|
+
return 1;
|
|
291
|
+
}
|
|
292
|
+
// Tri-state setup matrix (#217): classify BEFORE touching any config so a bootstrapper gets a deterministic
|
|
293
|
+
// installed/manual/unsupported answer. Only the `installed` class proceeds to mutate runtime config; `manual`
|
|
294
|
+
// prints the honest "do it by hand" reason without mutating, and `unsupported` refuses with a clear reason.
|
|
295
|
+
const support = runtimeSupport(runtimeRaw);
|
|
296
|
+
if (support.outcome === 'unsupported') {
|
|
297
|
+
if (json)
|
|
298
|
+
emit({ runtime: runtimeRaw, outcome: 'unsupported', files: [], reason: support.reason });
|
|
299
|
+
else
|
|
300
|
+
process.stderr.write(`${support.reason}\n${USAGE}`);
|
|
301
|
+
return 1;
|
|
302
|
+
}
|
|
303
|
+
// installed class: claude-code / codex / cursor: v2 owns a real config writer + uninstaller for these.
|
|
304
|
+
const runtime = runtimeRaw;
|
|
305
|
+
const configRoot = typeof f['root'] === 'string' ? f['root'] : process.cwd();
|
|
306
|
+
// claude-code: user scope targets ~/.claude.json regardless of --root; project scope uses configRoot.
|
|
307
|
+
const scope = scopeResult.scope;
|
|
308
|
+
if (support.outcome === 'installed' && f['uninstall']) {
|
|
309
|
+
const r = uninstallInjection(runtime, { configRoot, scope });
|
|
310
|
+
if (!r.ok) {
|
|
311
|
+
if (json)
|
|
312
|
+
emit({ runtime, action: 'uninstall', files: [], error: r.error ?? 'uninstall failed' });
|
|
313
|
+
else
|
|
314
|
+
process.stderr.write(`${r.error ?? 'uninstall failed'}\n`);
|
|
315
|
+
return 1;
|
|
316
|
+
}
|
|
317
|
+
if (json)
|
|
318
|
+
emit({ runtime, action: 'uninstall', files: r.files });
|
|
319
|
+
else
|
|
320
|
+
process.stdout.write(r.files.length ? `removed evolver from: ${r.files.join(', ')}\n` : 'nothing to remove\n');
|
|
321
|
+
return 0;
|
|
322
|
+
}
|
|
323
|
+
const profileDescriptor = profileDescriptorFromFlag(f);
|
|
324
|
+
if (!profileDescriptor.ok) {
|
|
325
|
+
if (json)
|
|
326
|
+
emit({ runtime: runtimeRaw, outcome: 'error', files: [], error: profileDescriptor.error });
|
|
327
|
+
else
|
|
328
|
+
process.stderr.write(`${profileDescriptor.error}\n`);
|
|
329
|
+
return 1;
|
|
330
|
+
}
|
|
331
|
+
const descriptor = profileDescriptor.descriptor;
|
|
332
|
+
if (support.outcome === 'manual') {
|
|
333
|
+
const server = buildServer(f, descriptor);
|
|
334
|
+
// server + --service=<target>: emit a ready service template (#217 slice 4). Print-only — evolver does NOT
|
|
335
|
+
// manage service lifecycle; it just prints a template wiring the EVOLVER_ENV_FILE pointer (never a secret).
|
|
336
|
+
if (runtimeRaw === 'server' && typeof f['service'] === 'string') {
|
|
337
|
+
const target = f['service'];
|
|
338
|
+
if (!SERVICE_TARGETS.includes(target)) {
|
|
339
|
+
const msg = `unknown --service target '${target}' (supported: ${SERVICE_TARGETS.join('|')})`;
|
|
340
|
+
if (json)
|
|
341
|
+
emit({ runtime: runtimeRaw, outcome: 'manual', files: [], error: msg });
|
|
342
|
+
else
|
|
343
|
+
process.stderr.write(`${msg}\n`);
|
|
344
|
+
return 1;
|
|
345
|
+
}
|
|
346
|
+
const template = appendAdapterNotes(renderServiceGuidance(target, { exec: buildServiceExec(f, descriptor) }), descriptor.manualHints[runtimeRaw]);
|
|
347
|
+
if (json)
|
|
348
|
+
emit({ runtime: runtimeRaw, outcome: 'manual', files: [], service: target, template });
|
|
349
|
+
else
|
|
350
|
+
process.stdout.write(`${template}\n`);
|
|
351
|
+
return 0;
|
|
352
|
+
}
|
|
353
|
+
// Otherwise: PRECISE manual wiring (#217 slice 2) so manual is actionable, not a dead end.
|
|
354
|
+
const instructions = renderManualWiring(runtimeRaw, { server, hints: descriptor.manualHints[runtimeRaw] ?? [] });
|
|
355
|
+
if (json)
|
|
356
|
+
emit({ runtime: runtimeRaw, outcome: 'manual', files: [], reason: support.reason, instructions });
|
|
357
|
+
else
|
|
358
|
+
process.stdout.write(`${instructions}\n`);
|
|
359
|
+
return 0;
|
|
360
|
+
}
|
|
361
|
+
const server = buildServer(f, descriptor);
|
|
362
|
+
// cursor seeds .cursor/rules/evolver.mdc with the CURRENT top REVIEW-APPROVED genes so the file is useful
|
|
363
|
+
// immediately (before the first daemon rewrite) without seeding an unapproved draft (A2a). The renderer thus
|
|
364
|
+
// has a real production caller even without the daemon running.
|
|
365
|
+
const cursorStore = store ?? new assetstore.LocalJsonlProvider(events.assetsDir());
|
|
366
|
+
const cursorGenes = runtime === 'cursor'
|
|
367
|
+
? await currentTopCursorGenes(cursorStore, review ?? reviewLedgerForStore(cursorStore))
|
|
368
|
+
: undefined;
|
|
369
|
+
let r;
|
|
370
|
+
try {
|
|
371
|
+
r = installInjection(planInjection(runtime, server), {
|
|
372
|
+
configRoot, server, scope,
|
|
373
|
+
...(typeof f['hook-command'] === 'string' ? { hookCommand: f['hook-command'] } : {}),
|
|
374
|
+
...(cursorGenes ? { genes: cursorGenes } : {}),
|
|
375
|
+
force: f['force'] === true,
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
catch (e) {
|
|
379
|
+
// A SUPPORTED runtime whose install THROWS (symlinked adapter path, I/O error) is an install ERROR, not an
|
|
380
|
+
// `unsupported` runtime. Reporting `unsupported` here would tell a bootstrapper the runtime isn't supported and
|
|
381
|
+
// make it stop trying, when the real cause is operational. `error` is a CLI result status (the attempt failed),
|
|
382
|
+
// distinct from the support-matrix `unsupported` (an unrecognized runtime id) (Bugbot #264).
|
|
383
|
+
const msg = e instanceof Error ? e.message : String(e);
|
|
384
|
+
if (json)
|
|
385
|
+
emit({ runtime, outcome: 'error', files: [], error: msg });
|
|
386
|
+
else
|
|
387
|
+
process.stderr.write(`${msg}\n`);
|
|
388
|
+
return 1;
|
|
389
|
+
}
|
|
390
|
+
if (!r.ok) {
|
|
391
|
+
// Same reasoning for an ok:false install result: a failed install of a supported runtime is `error`, not `unsupported`.
|
|
392
|
+
if (json)
|
|
393
|
+
emit({ runtime, outcome: 'error', files: [], error: r.error ?? 'install failed' });
|
|
394
|
+
else
|
|
395
|
+
process.stderr.write(`${r.error ?? 'install failed'}\n`);
|
|
396
|
+
return 1;
|
|
397
|
+
}
|
|
398
|
+
if (r.alreadyInstalled) {
|
|
399
|
+
if (json)
|
|
400
|
+
emit({ runtime, outcome: 'installed', files: r.files, alreadyInstalled: true });
|
|
401
|
+
else
|
|
402
|
+
process.stdout.write('evolver already installed (use --force to reinstall)\n');
|
|
403
|
+
return 0;
|
|
404
|
+
}
|
|
405
|
+
if (json)
|
|
406
|
+
emit({ runtime, outcome: 'installed', files: r.files, mode: r.mode });
|
|
407
|
+
else
|
|
408
|
+
process.stdout.write(`installed evolver (${r.mode}) → ${r.files.join(', ')}\n`);
|
|
409
|
+
return 0;
|
|
410
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { type algo } from '@evomap/evolver-core';
|
|
2
|
+
/** Max strategy steps kept from a skill (v1 parity: MAX_STRATEGY_STEPS). */
|
|
3
|
+
export declare const MAX_STRATEGY_STEPS = 28;
|
|
4
|
+
/** Structured view of a SKILL.md (the input to gene/capsule synthesis). */
|
|
5
|
+
export interface ParsedSkill {
|
|
6
|
+
frontmatter: Record<string, string>;
|
|
7
|
+
sections: Record<string, string>;
|
|
8
|
+
name: string;
|
|
9
|
+
description: string;
|
|
10
|
+
signals_match: string[];
|
|
11
|
+
strategy: string[];
|
|
12
|
+
avoid: string[];
|
|
13
|
+
validation: string[];
|
|
14
|
+
preconditions: string[];
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Parse a SKILL.md into a structured intermediate — faithful port of v1 `parseSkillMd`. Pure. Section keywords are
|
|
18
|
+
* matched against lower-cased headings and include CJK synonyms (skills authored in Chinese), though the signal
|
|
19
|
+
* tokenizer keeps ASCII `[a-z0-9_]` only, so a CJK skill's signals come from its (English) frontmatter description.
|
|
20
|
+
*/
|
|
21
|
+
export declare function parseSkillMd(skillMd: string): ParsedSkill;
|
|
22
|
+
/** Whether a validation command is safe to run as a Gene.validation entry (faithful port of v1
|
|
23
|
+
* policyCheck.isValidationCommandAllowed): a `node …` command with no command substitution, no shell
|
|
24
|
+
* metacharacters (outside quoted strings), and no node eval flags (-e/--eval/--print/-p). */
|
|
25
|
+
export declare function isValidationCommandAllowed(cmd: string): boolean;
|
|
26
|
+
/** Infer a gene category from signals + description (v1 inferCategory): priority repair > innovate > optimize,
|
|
27
|
+
* substring match (catches inflections + underscore signal tokens like `log_error`). */
|
|
28
|
+
export declare function inferCategory(signals: readonly string[], description: string): string;
|
|
29
|
+
export interface SynthesizeOptions {
|
|
30
|
+
strict?: boolean;
|
|
31
|
+
skillName?: string;
|
|
32
|
+
maxFiles?: number;
|
|
33
|
+
}
|
|
34
|
+
export interface SynthesizeResult {
|
|
35
|
+
gene: algo.GeneCandidate | null;
|
|
36
|
+
errors: string[];
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Assemble a draft GeneCandidate from a parsed skill + its execution trace (B2a — faithful port of v1
|
|
40
|
+
* `synthesizeGene`'s Gene half, mapped onto v2 `GeneCandidate`; pool intake/dedup/asset_id is the caller's
|
|
41
|
+
* `algo.intakeGene`). Signals merge skill + trace; strategy pads to ≥3 generic steps; validation keeps only the
|
|
42
|
+
* allowed `node …` commands. STRICT mode + no allowed validation → refuse (errors, no gene); non-strict falls back
|
|
43
|
+
* to `node --version` so Gene.validation is never empty (an empty validation would silently defeat the Capsule
|
|
44
|
+
* coverage check in B2b). `avoid` / `_source` are dropped here (not on GeneCandidate) — re-added if the schema grows.
|
|
45
|
+
*/
|
|
46
|
+
export declare function synthesizeGene(parsed: ParsedSkill, execution: {
|
|
47
|
+
signals?: readonly string[];
|
|
48
|
+
}, opts?: SynthesizeOptions): SynthesizeResult;
|
|
49
|
+
/** One real command run while the skill executed. */
|
|
50
|
+
export interface SkillTraceEntry {
|
|
51
|
+
step?: number;
|
|
52
|
+
cmd?: string;
|
|
53
|
+
exit?: number;
|
|
54
|
+
stdout_tail?: string;
|
|
55
|
+
}
|
|
56
|
+
/** The real execution evidence a skill invocation produced (the Capsule's ground truth). */
|
|
57
|
+
export interface SkillExecution {
|
|
58
|
+
status?: 'success' | 'failed';
|
|
59
|
+
score?: number;
|
|
60
|
+
started_at?: string;
|
|
61
|
+
trace?: readonly SkillTraceEntry[];
|
|
62
|
+
blast_radius?: {
|
|
63
|
+
files?: number;
|
|
64
|
+
lines?: number;
|
|
65
|
+
};
|
|
66
|
+
trigger?: readonly string[];
|
|
67
|
+
signals?: readonly string[];
|
|
68
|
+
summary?: string;
|
|
69
|
+
success_reason?: string;
|
|
70
|
+
content_summary?: string;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Forgery guard (v1 detectForgery) — RED LINE #1. A status=success Capsule with no real execution evidence is
|
|
74
|
+
* refused outright: empty trace, zero blast radius, or no recorded exit code. The core defence against an agent
|
|
75
|
+
* hallucinating a successful run to pad the registry. Non-success executions are honest, so not checked. Returns
|
|
76
|
+
* the rejection reason, or null when clean.
|
|
77
|
+
*/
|
|
78
|
+
export declare function detectForgery(execution: SkillExecution): string | null;
|
|
79
|
+
/** A synthesized Capsule (faithful to v1's shape; schema-conform / persistence is B3's concern). */
|
|
80
|
+
export interface SkillCapsule {
|
|
81
|
+
type: 'Capsule';
|
|
82
|
+
id: string;
|
|
83
|
+
gene: string;
|
|
84
|
+
trigger: string[];
|
|
85
|
+
summary: string;
|
|
86
|
+
confidence: number;
|
|
87
|
+
blast_radius: {
|
|
88
|
+
files: number;
|
|
89
|
+
lines: number;
|
|
90
|
+
};
|
|
91
|
+
outcome: {
|
|
92
|
+
status: string;
|
|
93
|
+
score: number;
|
|
94
|
+
};
|
|
95
|
+
success_reason: string | null;
|
|
96
|
+
env_fingerprint: unknown;
|
|
97
|
+
source_type: string;
|
|
98
|
+
strategy: string[];
|
|
99
|
+
content: string;
|
|
100
|
+
execution_trace: {
|
|
101
|
+
step: number;
|
|
102
|
+
cmd: string;
|
|
103
|
+
exit: number | null;
|
|
104
|
+
stdout_tail: string;
|
|
105
|
+
}[];
|
|
106
|
+
schema_version: string;
|
|
107
|
+
}
|
|
108
|
+
export type AssembleResult = {
|
|
109
|
+
ok: true;
|
|
110
|
+
capsule: SkillCapsule;
|
|
111
|
+
} | {
|
|
112
|
+
ok: false;
|
|
113
|
+
reason: string;
|
|
114
|
+
missing?: string[];
|
|
115
|
+
cmd?: string;
|
|
116
|
+
};
|
|
117
|
+
/**
|
|
118
|
+
* Assemble a Capsule from a gene + real execution evidence (v1 assembleCapsule) — RED LINE #2/#3. Every
|
|
119
|
+
* `Gene.validation` command MUST appear in `execution.trace` (whitespace-normalized exact match) AND carry an
|
|
120
|
+
* integer exit code; otherwise refuse → the caller degrades to Gene-only. No coverage = no Capsule.
|
|
121
|
+
*/
|
|
122
|
+
export declare function assembleCapsule(gene: algo.GeneCandidate, execution: SkillExecution, opts?: {
|
|
123
|
+
scenario?: string;
|
|
124
|
+
}): AssembleResult;
|
|
125
|
+
export interface ReverseDistillResult {
|
|
126
|
+
gene: algo.GeneCandidate | null;
|
|
127
|
+
capsule: SkillCapsule | null;
|
|
128
|
+
capsuleDiagnostic: {
|
|
129
|
+
reason: string;
|
|
130
|
+
detail?: string;
|
|
131
|
+
missing?: string[];
|
|
132
|
+
cmd?: string;
|
|
133
|
+
} | null;
|
|
134
|
+
errors: string[];
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Reverse-distill a parsed SKILL.md + its execution into GEP assets — the PURE core of v1 runOnSkillInvocation
|
|
138
|
+
* (file read / persist / idempotency are B3's wiring). RED LINE: a Capsule is emitted ONLY when the execution is a
|
|
139
|
+
* real, forgery-clear success AND its trace covers every Gene.validation; otherwise Gene-only + a diagnostic. The
|
|
140
|
+
* human-review gate stays the caller's — a skill-distilled Gene is a draft like any other.
|
|
141
|
+
*/
|
|
142
|
+
export declare function reverseDistill(parsed: ParsedSkill, execution?: SkillExecution, opts?: SynthesizeOptions & {
|
|
143
|
+
scenario?: string;
|
|
144
|
+
}): ReverseDistillResult;
|