@evomap/evolver-cli 2.0.0-beta.1 → 2.0.0-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/antiGeneBenchmark.js +12 -0
- package/dist/antiGeneEvidence.d.ts +15 -0
- package/dist/antiGeneEvidence.js +49 -0
- package/dist/antiGeneRollout.d.ts +3 -1
- package/dist/antiGeneRollout.js +16 -2
- package/dist/assetHealth.d.ts +6 -0
- package/dist/assetHealth.js +105 -0
- package/dist/assetSidecarRecovery.d.ts +14 -0
- package/dist/assetSidecarRecovery.js +171 -0
- package/dist/assetTrust.d.ts +24 -0
- package/dist/assetTrust.js +218 -0
- package/dist/atp.js +4 -2
- package/dist/autoDistillLlm.js +4 -1
- package/dist/autoexec.d.ts +13 -3
- package/dist/autoexec.js +71 -13
- package/dist/cli.js +12 -5
- package/dist/cliContracts.js +8 -2
- package/dist/cliLifecycle.d.ts +7 -0
- package/dist/cliLifecycle.js +9 -0
- package/dist/cycleConsumer.d.ts +61 -1
- package/dist/cycleConsumer.js +551 -16
- package/dist/dashboard.d.ts +23 -0
- package/dist/dashboard.js +191 -0
- package/dist/dispatch.d.ts +10 -1
- package/dist/dispatch.js +36 -2
- package/dist/distillObserver.js +2 -2
- package/dist/distillPrimitives.d.ts +1 -1
- package/dist/distillPrimitives.js +29 -2
- package/dist/doctor.d.ts +2 -0
- package/dist/doctor.js +33 -3
- package/dist/index.d.ts +7 -2
- package/dist/index.js +292 -36
- package/dist/lifecycle.d.ts +19 -1
- package/dist/lifecycle.js +226 -29
- package/dist/localMemoryGraph.d.ts +97 -0
- package/dist/localMemoryGraph.js +889 -0
- package/dist/login.d.ts +20 -4
- package/dist/login.js +58 -8
- package/dist/materialPackage.d.ts +52 -0
- package/dist/materialPackage.js +404 -0
- package/dist/materialSnapshot.d.ts +30 -0
- package/dist/materialSnapshot.js +148 -0
- package/dist/memoryEventMirror.d.ts +23 -0
- package/dist/memoryEventMirror.js +140 -0
- package/dist/migrate/fieldMap.js +25 -0
- package/dist/migrate/v1Import.d.ts +7 -1
- package/dist/migrate/v1Import.js +132 -11
- package/dist/nonGitWorkspaceNotice.d.ts +24 -0
- package/dist/nonGitWorkspaceNotice.js +122 -0
- package/dist/proxyToken.d.ts +10 -0
- package/dist/proxyToken.js +80 -0
- package/dist/recipe.d.ts +10 -2
- package/dist/recipe.js +349 -7
- package/dist/reuseReport.js +16 -16
- package/dist/runtimeCapabilities.d.ts +18 -0
- package/dist/runtimeCapabilities.js +81 -0
- package/dist/runtimeSessionSource.d.ts +10 -0
- package/dist/runtimeSessionSource.js +32 -5
- package/dist/setupHooks.d.ts +6 -1
- package/dist/setupHooks.js +5 -2
- package/dist/skill2gep.d.ts +38 -9
- package/dist/skill2gep.js +147 -14
- package/dist/skillDistill.d.ts +1 -0
- package/dist/skillDistill.js +4 -4
- package/dist/skillFetch.d.ts +18 -0
- package/dist/skillFetch.js +391 -0
- package/dist/solo/mode.js +5 -0
- package/dist/sync.d.ts +26 -0
- package/dist/sync.js +988 -0
- package/dist/trajectoryExport.js +23 -12
- package/dist/v1Compat.d.ts +24 -0
- package/dist/v1Compat.js +249 -0
- package/package.json +12 -6
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { execFileSync } from 'node:child_process';
|
|
2
|
+
import { createHash } from 'node:crypto';
|
|
3
|
+
import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs';
|
|
4
|
+
import { dirname, join, parse, resolve } from 'node:path';
|
|
5
|
+
import { events } from '@evomap/evolver-core';
|
|
6
|
+
export const NON_GIT_WORKSPACE_NOTICE_THROTTLE_MS = 24 * 60 * 60 * 1000;
|
|
7
|
+
const NON_GIT_WORKSPACE_NOTICE = '[evolver] This workspace is not a git repository; Evolver will still run, but recording, recall, and rollback context may be limited. Run from a project root or initialize git for full context.\n';
|
|
8
|
+
const GIT_DETECT_TIMEOUT_MS = 500;
|
|
9
|
+
function nonGitWorkspaceNoticeStatePath() {
|
|
10
|
+
return join(events.evomapHome(), 'evolution', 'non-git-workspace-notice.json');
|
|
11
|
+
}
|
|
12
|
+
function hasGitMarkerAncestor(cwd) {
|
|
13
|
+
let cur = resolve(cwd);
|
|
14
|
+
const root = parse(cur).root;
|
|
15
|
+
for (;;) {
|
|
16
|
+
if (existsSync(join(cur, '.git')))
|
|
17
|
+
return true;
|
|
18
|
+
if (cur === root)
|
|
19
|
+
return false;
|
|
20
|
+
cur = dirname(cur);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
export function detectGitWorkspace(cwd = process.cwd(), gitProbe = execFileSync) {
|
|
24
|
+
try {
|
|
25
|
+
const out = gitProbe('git', ['-C', cwd, 'rev-parse', '--is-inside-work-tree'], {
|
|
26
|
+
encoding: 'utf8',
|
|
27
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
28
|
+
timeout: GIT_DETECT_TIMEOUT_MS,
|
|
29
|
+
windowsHide: true,
|
|
30
|
+
}).trim();
|
|
31
|
+
if (out === 'true')
|
|
32
|
+
return 'git';
|
|
33
|
+
if (out === 'false')
|
|
34
|
+
return 'unknown';
|
|
35
|
+
return 'unknown';
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
const err = error;
|
|
39
|
+
const stderr = Buffer.isBuffer(err.stderr) ? err.stderr.toString('utf8') : typeof err.stderr === 'string' ? err.stderr : '';
|
|
40
|
+
const msg = `${stderr} ${typeof err.message === 'string' ? err.message : ''}`;
|
|
41
|
+
if (err.status === 128) {
|
|
42
|
+
if (hasGitMarkerAncestor(cwd))
|
|
43
|
+
return 'unknown';
|
|
44
|
+
if (/not a git repository|not a git repo/i.test(msg))
|
|
45
|
+
return 'non_git';
|
|
46
|
+
return 'non_git';
|
|
47
|
+
}
|
|
48
|
+
return 'unknown';
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function workspaceHash(cwd) {
|
|
52
|
+
const normalized = resolve(cwd);
|
|
53
|
+
return createHash('sha256').update(normalized).digest('hex');
|
|
54
|
+
}
|
|
55
|
+
function readState(path) {
|
|
56
|
+
try {
|
|
57
|
+
const parsed = JSON.parse(readFileSync(path, 'utf8'));
|
|
58
|
+
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed))
|
|
59
|
+
return { version: 1, workspaces: {} };
|
|
60
|
+
const workspaces = parsed.workspaces;
|
|
61
|
+
if (!workspaces || typeof workspaces !== 'object' || Array.isArray(workspaces))
|
|
62
|
+
return { version: 1, workspaces: {} };
|
|
63
|
+
const out = {};
|
|
64
|
+
for (const [key, value] of Object.entries(workspaces)) {
|
|
65
|
+
if (!/^[a-f0-9]{64}$/.test(key))
|
|
66
|
+
continue;
|
|
67
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
68
|
+
continue;
|
|
69
|
+
const lastNotifiedAt = value.lastNotifiedAt;
|
|
70
|
+
if (typeof lastNotifiedAt === 'string')
|
|
71
|
+
out[key] = { lastNotifiedAt };
|
|
72
|
+
}
|
|
73
|
+
return { version: 1, workspaces: out };
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
return { version: 1, workspaces: {} };
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
function writeStateBestEffort(path, state) {
|
|
80
|
+
try {
|
|
81
|
+
mkdirSync(dirname(path), { recursive: true, mode: 0o700 });
|
|
82
|
+
const tmp = `${path}.${process.pid}.${Date.now()}.tmp`;
|
|
83
|
+
writeFileSync(tmp, `${JSON.stringify(state, null, 2)}\n`, { encoding: 'utf8', mode: 0o600 });
|
|
84
|
+
renameSync(tmp, path);
|
|
85
|
+
}
|
|
86
|
+
catch {
|
|
87
|
+
// The notice is operator UX only; state persistence must never break hooks.
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
function isThrottled(lastNotifiedAt, now, throttleMs) {
|
|
91
|
+
if (!lastNotifiedAt)
|
|
92
|
+
return false;
|
|
93
|
+
const previous = Date.parse(lastNotifiedAt);
|
|
94
|
+
if (!Number.isFinite(previous))
|
|
95
|
+
return false;
|
|
96
|
+
return now - previous < throttleMs;
|
|
97
|
+
}
|
|
98
|
+
export function maybeEmitNonGitWorkspaceNotice(options = {}) {
|
|
99
|
+
const cwd = options.cwd ?? process.cwd();
|
|
100
|
+
const detect = options.detect ?? detectGitWorkspace;
|
|
101
|
+
const status = detect(cwd);
|
|
102
|
+
if (status !== 'non_git')
|
|
103
|
+
return { status, emitted: false };
|
|
104
|
+
const now = options.now ? options.now() : Date.now();
|
|
105
|
+
const throttleMs = options.throttleMs ?? NON_GIT_WORKSPACE_NOTICE_THROTTLE_MS;
|
|
106
|
+
const statePath = options.statePath ?? nonGitWorkspaceNoticeStatePath();
|
|
107
|
+
const hash = workspaceHash(cwd);
|
|
108
|
+
const state = readState(statePath);
|
|
109
|
+
if (isThrottled(state.workspaces[hash]?.lastNotifiedAt, now, throttleMs)) {
|
|
110
|
+
return { status, emitted: false, workspaceHash: hash };
|
|
111
|
+
}
|
|
112
|
+
const write = options.write ?? ((line) => process.stderr.write(line));
|
|
113
|
+
try {
|
|
114
|
+
write(NON_GIT_WORKSPACE_NOTICE);
|
|
115
|
+
}
|
|
116
|
+
catch {
|
|
117
|
+
return { status, emitted: false, workspaceHash: hash };
|
|
118
|
+
}
|
|
119
|
+
state.workspaces[hash] = { lastNotifiedAt: new Date(now).toISOString() };
|
|
120
|
+
writeStateBestEffort(statePath, state);
|
|
121
|
+
return { status, emitted: true, workspaceHash: hash };
|
|
122
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { lstatSync, readFileSync } from 'node:fs';
|
|
2
|
+
export interface ProxyTokenDeps {
|
|
3
|
+
env?: Record<string, string | undefined>;
|
|
4
|
+
stdout?: (text: string) => void;
|
|
5
|
+
stderr?: (text: string) => void;
|
|
6
|
+
homeDir?: string;
|
|
7
|
+
lstat?: typeof lstatSync;
|
|
8
|
+
readFile?: typeof readFileSync;
|
|
9
|
+
}
|
|
10
|
+
export declare function runProxyToken(argv: readonly string[], deps?: ProxyTokenDeps): Promise<number>;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { lstatSync, readFileSync } from 'node:fs';
|
|
2
|
+
import { homedir } from 'node:os';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
const USAGE = 'Usage: evolver proxy-token [--settings FILE]\n';
|
|
5
|
+
function proxyTokenUsage() {
|
|
6
|
+
return USAGE;
|
|
7
|
+
}
|
|
8
|
+
function resolveProxyTokenSettingsPath(env = process.env, homeDir = homedir(), explicitSettings) {
|
|
9
|
+
const explicit = explicitSettings?.trim();
|
|
10
|
+
if (explicit)
|
|
11
|
+
return explicit;
|
|
12
|
+
const proxySettingsFile = env['EVOLVER_PROXY_SETTINGS_FILE']?.trim();
|
|
13
|
+
if (proxySettingsFile)
|
|
14
|
+
return proxySettingsFile;
|
|
15
|
+
const settingsDir = env['EVOLVER_SETTINGS_DIR']?.trim() || join(homeDir, '.evolver');
|
|
16
|
+
return join(settingsDir, 'settings.json');
|
|
17
|
+
}
|
|
18
|
+
function readProxyTokenFromSettingsFile(settingsPath, deps = {}) {
|
|
19
|
+
const stat = deps.lstat ?? lstatSync;
|
|
20
|
+
const read = deps.readFile ?? readFileSync;
|
|
21
|
+
try {
|
|
22
|
+
if (!stat(settingsPath).isFile())
|
|
23
|
+
return undefined;
|
|
24
|
+
const parsed = JSON.parse(read(settingsPath, 'utf8'));
|
|
25
|
+
const proxy = recordValue(recordValue(parsed)['proxy']);
|
|
26
|
+
const token = typeof proxy['token'] === 'string' ? proxy['token'].trim() : '';
|
|
27
|
+
return token || undefined;
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export async function runProxyToken(argv, deps = {}) {
|
|
34
|
+
const stdout = deps.stdout ?? ((text) => { process.stdout.write(text); });
|
|
35
|
+
const stderr = deps.stderr ?? ((text) => { process.stderr.write(text); });
|
|
36
|
+
const env = deps.env ?? process.env;
|
|
37
|
+
let settingsFile;
|
|
38
|
+
for (let i = 0; i < argv.length; i++) {
|
|
39
|
+
const arg = argv[i];
|
|
40
|
+
if (arg === '-h' || arg === '--help') {
|
|
41
|
+
stdout(proxyTokenUsage());
|
|
42
|
+
return 0;
|
|
43
|
+
}
|
|
44
|
+
if (arg === '--settings') {
|
|
45
|
+
const value = argv[i + 1];
|
|
46
|
+
if (value === undefined || value.length === 0) {
|
|
47
|
+
stderr(USAGE);
|
|
48
|
+
stderr('[proxy-token] missing value for --settings\n');
|
|
49
|
+
return 2;
|
|
50
|
+
}
|
|
51
|
+
settingsFile = value;
|
|
52
|
+
i++;
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
if (arg?.startsWith('--settings=')) {
|
|
56
|
+
const value = arg.slice('--settings='.length);
|
|
57
|
+
if (!value) {
|
|
58
|
+
stderr(USAGE);
|
|
59
|
+
stderr('[proxy-token] missing value for --settings\n');
|
|
60
|
+
return 2;
|
|
61
|
+
}
|
|
62
|
+
settingsFile = value;
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
stderr(USAGE);
|
|
66
|
+
stderr('[proxy-token] unknown argument\n');
|
|
67
|
+
return 2;
|
|
68
|
+
}
|
|
69
|
+
const path = resolveProxyTokenSettingsPath(env, deps.homeDir ?? homedir(), settingsFile);
|
|
70
|
+
const token = readProxyTokenFromSettingsFile(path, deps);
|
|
71
|
+
if (!token) {
|
|
72
|
+
stderr('[proxy-token] no active proxy token found; start evolver-proxy first\n');
|
|
73
|
+
return 1;
|
|
74
|
+
}
|
|
75
|
+
stdout(`${token}\n`);
|
|
76
|
+
return 0;
|
|
77
|
+
}
|
|
78
|
+
function recordValue(value) {
|
|
79
|
+
return value && typeof value === 'object' && !Array.isArray(value) ? value : {};
|
|
80
|
+
}
|
package/dist/recipe.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { assetstore, type hub as hubNs } from '@evomap/evolver-core';
|
|
1
|
+
import { assetstore, events, type hub as hubNs } from '@evomap/evolver-core';
|
|
2
2
|
import type { ConnectPublicOptions, PublicHubCapability } from '@evomap/evolver-adapter-public';
|
|
3
3
|
export interface RecipeCliDeps {
|
|
4
4
|
hub?: RecipeHub;
|
|
@@ -6,6 +6,8 @@ export interface RecipeCliDeps {
|
|
|
6
6
|
env?: NodeJS.ProcessEnv;
|
|
7
7
|
log?: (line: string) => void;
|
|
8
8
|
err?: (line: string) => void;
|
|
9
|
+
ingestor?: events.Ingestor;
|
|
10
|
+
review?: assetstore.ReviewLedger;
|
|
9
11
|
connectHub?: (opts: ConnectPublicOptions) => {
|
|
10
12
|
hub: PublicHubCapability;
|
|
11
13
|
auth: hubNs.AuthProvider;
|
|
@@ -42,7 +44,13 @@ export interface RecipeReuseOptions {
|
|
|
42
44
|
inputPayload: Record<string, unknown>;
|
|
43
45
|
jsonOut: boolean;
|
|
44
46
|
}
|
|
45
|
-
export
|
|
47
|
+
export interface RecipeFromSkillsOptions {
|
|
48
|
+
sub: 'from-skills';
|
|
49
|
+
manifestPath: string;
|
|
50
|
+
publish: boolean;
|
|
51
|
+
jsonOut: boolean;
|
|
52
|
+
}
|
|
53
|
+
export type RecipeOptions = RecipeBuildOptions | RecipeReuseOptions | RecipeFromSkillsOptions;
|
|
46
54
|
export declare function runRecipeCommand(argv: readonly string[], deps?: RecipeCliDeps): Promise<number>;
|
|
47
55
|
export declare function createRecipeHubFromEnv(env?: NodeJS.ProcessEnv, connectHub?: (opts: ConnectPublicOptions) => {
|
|
48
56
|
hub: PublicHubCapability;
|
package/dist/recipe.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { existsSync, mkdirSync, readFileSync, unlinkSync, writeFileSync } from 'node:fs';
|
|
2
2
|
import { homedir } from 'node:os';
|
|
3
|
-
import { join } from 'node:path';
|
|
3
|
+
import { dirname, isAbsolute, join, resolve } from 'node:path';
|
|
4
4
|
import { assetstore, events, mailbox } from '@evomap/evolver-core';
|
|
5
|
-
import { AuthError, HubClientError, HubUnreachableError, connectPublicHub, isHubDryRunEnabled, isNodeSecret, parseNodeSecretVersion } from '@evomap/evolver-adapter-public';
|
|
5
|
+
import { AuthError, HubClientError, HubUnreachableError, connectPublicHub, isHubDryRunEnabled, isNodeSecret, parseNodeSecretVersion, resolveHubUrl } from '@evomap/evolver-adapter-public';
|
|
6
|
+
import { loadEnvFileFromEnv } from '@evomap/evolver-mcp';
|
|
6
7
|
import { resolveAtpSenderId } from './atp.js';
|
|
8
|
+
import { parseSkillMd, reverseDistill } from './skill2gep.js';
|
|
9
|
+
import { recordSkillDistillation } from './skillDistill.js';
|
|
7
10
|
const MAX_RECIPE_STEPS = 20;
|
|
8
11
|
const MAX_ID_LENGTH = 200;
|
|
9
|
-
const DEFAULT_PUBLIC_HUB_URL = 'https://evomap.ai';
|
|
10
12
|
const SENSITIVE_ERROR_KEYS = new Set(['authorization', 'node_secret', 'nodesecret', 'token', 'access_token', 'refresh_token', 'secret']);
|
|
11
13
|
const STALE_NODE_SECRET_ERRORS = new Set(['node_secret_invalid', 'node_secret_not_set']);
|
|
12
14
|
export async function runRecipeCommand(argv, deps = {}) {
|
|
@@ -22,6 +24,8 @@ export async function runRecipeCommand(argv, deps = {}) {
|
|
|
22
24
|
if (isHubDryRunEnabled(env)) {
|
|
23
25
|
if (parsed.value.sub === 'build')
|
|
24
26
|
return await runRecipeBuildDryRun(parsed.value, deps.store, { log, err });
|
|
27
|
+
if (parsed.value.sub === 'from-skills')
|
|
28
|
+
return await runRecipeFromSkills(parsed.value, undefined, deps, { log, err }, true);
|
|
25
29
|
return runRecipeReuseDryRun(parsed.value, { log });
|
|
26
30
|
}
|
|
27
31
|
const hub = deps.hub ?? createRecipeHubFromEnv(env, deps.connectHub ?? connectPublicHub);
|
|
@@ -31,6 +35,8 @@ export async function runRecipeCommand(argv, deps = {}) {
|
|
|
31
35
|
}
|
|
32
36
|
if (parsed.value.sub === 'build')
|
|
33
37
|
return await runRecipeBuild(parsed.value, hub, deps.store, { log, err });
|
|
38
|
+
if (parsed.value.sub === 'from-skills')
|
|
39
|
+
return await runRecipeFromSkills(parsed.value, hub, deps, { log, err }, false);
|
|
34
40
|
return await runRecipeReuse(parsed.value, hub, { log, err });
|
|
35
41
|
}
|
|
36
42
|
catch (e) {
|
|
@@ -67,6 +73,7 @@ function runRecipeReuseDryRun(opts, io) {
|
|
|
67
73
|
return 0;
|
|
68
74
|
}
|
|
69
75
|
export function createRecipeHubFromEnv(env = process.env, connectHub = connectPublicHub) {
|
|
76
|
+
loadEnvFileFromEnv(env);
|
|
70
77
|
const hubUrl = resolveRecipeHubUrl(env);
|
|
71
78
|
const credentials = resolveRecipeHubCredentials(env);
|
|
72
79
|
if (!credentials.nodeSecret && !existsSync(join(credentials.evomapDir, 'token.json'))) {
|
|
@@ -90,16 +97,17 @@ export function createRecipeHubFromEnv(env = process.env, connectHub = connectPu
|
|
|
90
97
|
return connected.hub;
|
|
91
98
|
}
|
|
92
99
|
function resolveRecipeHubUrl(env) {
|
|
93
|
-
|
|
94
|
-
return hubUrl;
|
|
100
|
+
return resolveHubUrl(env);
|
|
95
101
|
}
|
|
96
102
|
export function parseRecipeArgs(argv) {
|
|
97
103
|
const sub = argv[0];
|
|
98
|
-
if (sub !== 'build' && sub !== 'reuse')
|
|
99
|
-
return { ok: false, error: 'recipe subcommand must be build|reuse' };
|
|
104
|
+
if (sub !== 'build' && sub !== 'reuse' && sub !== 'from-skills')
|
|
105
|
+
return { ok: false, error: 'recipe subcommand must be build|reuse|from-skills' };
|
|
100
106
|
const args = argv.slice(1);
|
|
101
107
|
if (sub === 'build')
|
|
102
108
|
return parseBuildArgs(args);
|
|
109
|
+
if (sub === 'from-skills')
|
|
110
|
+
return parseFromSkillsArgs(args);
|
|
103
111
|
return parseReuseArgs(args);
|
|
104
112
|
}
|
|
105
113
|
async function runRecipeBuild(opts, hub, store, io) {
|
|
@@ -129,6 +137,132 @@ async function runRecipeBuild(opts, hub, store, io) {
|
|
|
129
137
|
}
|
|
130
138
|
return 0;
|
|
131
139
|
}
|
|
140
|
+
async function runRecipeFromSkills(opts, hub, deps, io, dryRun) {
|
|
141
|
+
const loaded = loadRecipeFromSkillsManifest(opts.manifestPath);
|
|
142
|
+
if (!loaded.ok) {
|
|
143
|
+
io.err(loaded.error);
|
|
144
|
+
return 1;
|
|
145
|
+
}
|
|
146
|
+
const preflight = preflightRecipeFromSkillsSteps(loaded.value.steps);
|
|
147
|
+
if (!preflight.ok) {
|
|
148
|
+
io.err(preflight.error);
|
|
149
|
+
return 1;
|
|
150
|
+
}
|
|
151
|
+
const store = deps.store ?? new assetstore.LocalJsonlProvider(events.assetsDir());
|
|
152
|
+
const ingestor = deps.ingestor ?? new events.Ingestor({ path: events.rootEventsPath() });
|
|
153
|
+
const steps = [];
|
|
154
|
+
const distilled = [];
|
|
155
|
+
for (const prepared of preflight.value) {
|
|
156
|
+
const existing = await findReusableRecipeStep(store, prepared);
|
|
157
|
+
if (existing) {
|
|
158
|
+
addRecipeFromSkillsStep(steps, distilled, existing);
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
161
|
+
const step = prepared.step;
|
|
162
|
+
const res = await recordSkillDistillation(step.skill, step.execution, {
|
|
163
|
+
store,
|
|
164
|
+
...(deps.review ? { review: deps.review } : {}),
|
|
165
|
+
ingestor,
|
|
166
|
+
}, step.scenario ? { scenario: step.scenario } : {});
|
|
167
|
+
if (!res.geneId || !res.geneAssetId) {
|
|
168
|
+
const recovered = await findReusableRecipeStep(store, prepared);
|
|
169
|
+
if (recovered) {
|
|
170
|
+
addRecipeFromSkillsStep(steps, distilled, recovered);
|
|
171
|
+
continue;
|
|
172
|
+
}
|
|
173
|
+
io.err(`recipe from-skills step ${prepared.position + 1} did not produce a Gene: ${res.errors.join('; ') || 'refused'}`);
|
|
174
|
+
return 1;
|
|
175
|
+
}
|
|
176
|
+
if (!res.capsuleId) {
|
|
177
|
+
io.err(`recipe from-skills step ${prepared.position + 1} missing Capsule evidence: ${res.capsuleDiagnostic ?? 'missing_capsule_evidence'}`);
|
|
178
|
+
return 1;
|
|
179
|
+
}
|
|
180
|
+
if (!(await hasCapsuleEvidence(store, res.capsuleId, res.geneId))) {
|
|
181
|
+
io.err(`recipe from-skills step ${prepared.position + 1} missing persisted Capsule evidence`);
|
|
182
|
+
return 1;
|
|
183
|
+
}
|
|
184
|
+
addRecipeFromSkillsStep(steps, distilled, {
|
|
185
|
+
position: prepared.position,
|
|
186
|
+
geneId: res.geneId,
|
|
187
|
+
geneAssetId: res.geneAssetId,
|
|
188
|
+
capsuleId: res.capsuleId,
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
if (dryRun) {
|
|
192
|
+
const payload = recipeFromSkillsPayload({
|
|
193
|
+
mode: 'dry_run',
|
|
194
|
+
title: loaded.value.title,
|
|
195
|
+
publish: opts.publish,
|
|
196
|
+
steps: distilled,
|
|
197
|
+
});
|
|
198
|
+
if (opts.jsonOut)
|
|
199
|
+
io.log(JSON.stringify(payload, null, 2));
|
|
200
|
+
else {
|
|
201
|
+
io.log(`[recipe from-skills] dry-run: would create DRAFT recipe ("${loaded.value.title}", ${steps.length} step${steps.length === 1 ? '' : 's'}).`);
|
|
202
|
+
if (opts.publish)
|
|
203
|
+
io.log('[recipe from-skills] dry-run: would publish the recipe after creation.');
|
|
204
|
+
else
|
|
205
|
+
io.log('[recipe from-skills] dry-run: would leave the recipe as draft.');
|
|
206
|
+
}
|
|
207
|
+
return 0;
|
|
208
|
+
}
|
|
209
|
+
if (!hub?.recipes) {
|
|
210
|
+
io.err('recipe capability is not available for the configured Hub adapter');
|
|
211
|
+
return 1;
|
|
212
|
+
}
|
|
213
|
+
const createReceipt = await callRecipeWithAuthRetry(hub, 'recipe from-skills', () => hub.recipes.create({
|
|
214
|
+
title: loaded.value.title,
|
|
215
|
+
steps,
|
|
216
|
+
...(loaded.value.description ? { description: loaded.value.description } : {}),
|
|
217
|
+
...(loaded.value.pricePerExecution !== undefined ? { pricePerExecution: loaded.value.pricePerExecution } : {}),
|
|
218
|
+
}), io);
|
|
219
|
+
const recipeId = createReceipt.recipeId;
|
|
220
|
+
if (!opts.jsonOut) {
|
|
221
|
+
io.log(`[recipe from-skills] Created DRAFT recipe ${recipeId ?? '(id pending)'} ("${loaded.value.title}", ${steps.length} step${steps.length === 1 ? '' : 's'}).`);
|
|
222
|
+
}
|
|
223
|
+
if (opts.publish) {
|
|
224
|
+
if (!recipeId) {
|
|
225
|
+
io.err('[recipe from-skills] Hub did not return a recipe id; cannot publish.');
|
|
226
|
+
return 1;
|
|
227
|
+
}
|
|
228
|
+
try {
|
|
229
|
+
await callRecipeWithAuthRetry(hub, 'recipe from-skills', () => hub.recipes.publish(recipeId), io);
|
|
230
|
+
}
|
|
231
|
+
catch (e) {
|
|
232
|
+
if (opts.jsonOut) {
|
|
233
|
+
io.log(JSON.stringify(recipeFromSkillsPayload({
|
|
234
|
+
ok: false,
|
|
235
|
+
mode: 'draft',
|
|
236
|
+
title: loaded.value.title,
|
|
237
|
+
publish: opts.publish,
|
|
238
|
+
steps: distilled,
|
|
239
|
+
recipeId,
|
|
240
|
+
error: 'publish_failed',
|
|
241
|
+
}), null, 2));
|
|
242
|
+
}
|
|
243
|
+
else {
|
|
244
|
+
io.err(`[recipe from-skills] Created DRAFT recipe ${recipeId}; publish failed before it was made live.`);
|
|
245
|
+
}
|
|
246
|
+
throw e;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
const payload = recipeFromSkillsPayload({
|
|
250
|
+
mode: opts.publish ? 'published' : 'draft',
|
|
251
|
+
title: loaded.value.title,
|
|
252
|
+
publish: opts.publish,
|
|
253
|
+
steps: distilled,
|
|
254
|
+
recipeId,
|
|
255
|
+
});
|
|
256
|
+
if (opts.jsonOut)
|
|
257
|
+
io.log(JSON.stringify(payload, null, 2));
|
|
258
|
+
else {
|
|
259
|
+
if (opts.publish)
|
|
260
|
+
io.log(`[recipe from-skills] Published recipe ${recipeId}.`);
|
|
261
|
+
else
|
|
262
|
+
io.log('[recipe from-skills] Left as draft. Re-run with --publish to make it live.');
|
|
263
|
+
}
|
|
264
|
+
return 0;
|
|
265
|
+
}
|
|
132
266
|
async function runRecipeReuse(opts, hub, io) {
|
|
133
267
|
await callRecipeWithAuthRetry(hub, 'recipe reuse', () => hub.recipes.get(opts.recipeId), io);
|
|
134
268
|
const receipt = await callRecipeWithAuthRetry(hub, 'recipe reuse', () => hub.recipes.express(opts.recipeId, { inputPayload: opts.inputPayload }), io);
|
|
@@ -150,6 +284,198 @@ async function recipeStepsFromLocalAssets(assetIds, store) {
|
|
|
150
284
|
return { assetId, assetType, position: index };
|
|
151
285
|
});
|
|
152
286
|
}
|
|
287
|
+
function preflightRecipeFromSkillsSteps(steps) {
|
|
288
|
+
const prepared = [];
|
|
289
|
+
for (let i = 0; i < steps.length; i += 1) {
|
|
290
|
+
const step = steps[i];
|
|
291
|
+
const parsed = parseSkillMd(step.skill);
|
|
292
|
+
const preview = reverseDistill(parsed, step.execution, step.scenario ? { scenario: step.scenario } : {});
|
|
293
|
+
if (!preview.gene) {
|
|
294
|
+
return {
|
|
295
|
+
ok: false,
|
|
296
|
+
error: `recipe from-skills step ${i + 1} did not produce a Gene: ${preview.errors.join('; ') || 'refused'}`,
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
if (!preview.capsule) {
|
|
300
|
+
const diag = preview.capsuleDiagnostic
|
|
301
|
+
? (preview.capsuleDiagnostic.detail ?? preview.capsuleDiagnostic.reason)
|
|
302
|
+
: 'missing_capsule_evidence';
|
|
303
|
+
return {
|
|
304
|
+
ok: false,
|
|
305
|
+
error: `recipe from-skills step ${i + 1} missing Capsule evidence: ${diag}`,
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
prepared.push({
|
|
309
|
+
position: i,
|
|
310
|
+
step,
|
|
311
|
+
candidateSignals: normalizedSignalList(preview.gene.signals_match),
|
|
312
|
+
candidateCapsuleId: preview.capsule.id,
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
return { ok: true, value: prepared };
|
|
316
|
+
}
|
|
317
|
+
async function findReusableRecipeStep(store, prepared) {
|
|
318
|
+
const candidateSignals = prepared.candidateSignals;
|
|
319
|
+
if (candidateSignals.length === 0)
|
|
320
|
+
return null;
|
|
321
|
+
const genes = await store.list('Gene', 10_000);
|
|
322
|
+
const capsules = await store.list('Capsule', 10_000);
|
|
323
|
+
for (const gene of genes) {
|
|
324
|
+
const signals = new Set(normalizedSignalList(gene['signals_match']));
|
|
325
|
+
if (!candidateSignals.every((signal) => signals.has(signal)))
|
|
326
|
+
continue;
|
|
327
|
+
const geneId = typeof gene['id'] === 'string' && gene['id'].trim()
|
|
328
|
+
? gene['id'].trim()
|
|
329
|
+
: String(gene['asset_id'] ?? '');
|
|
330
|
+
const geneAssetId = typeof gene['asset_id'] === 'string' ? gene['asset_id'] : '';
|
|
331
|
+
if (!geneId || !geneAssetId)
|
|
332
|
+
continue;
|
|
333
|
+
const capsule = capsules.find((record) => String(record['id']) === prepared.candidateCapsuleId &&
|
|
334
|
+
String(record['gene']) === geneId);
|
|
335
|
+
if (!capsule)
|
|
336
|
+
continue;
|
|
337
|
+
return {
|
|
338
|
+
position: prepared.position,
|
|
339
|
+
geneId,
|
|
340
|
+
geneAssetId,
|
|
341
|
+
capsuleId: String(capsule['id']),
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
return null;
|
|
345
|
+
}
|
|
346
|
+
function addRecipeFromSkillsStep(steps, distilled, result) {
|
|
347
|
+
steps.push({ assetId: result.geneAssetId, assetType: 'Gene', position: result.position });
|
|
348
|
+
distilled.push(result);
|
|
349
|
+
}
|
|
350
|
+
async function hasCapsuleEvidence(store, capsuleId, geneId) {
|
|
351
|
+
const capsules = await store.list('Capsule', 10_000);
|
|
352
|
+
return capsules.some((capsule) => String(capsule['id']) === capsuleId &&
|
|
353
|
+
String(capsule['gene']) === geneId);
|
|
354
|
+
}
|
|
355
|
+
function normalizedSignalList(value) {
|
|
356
|
+
return Array.isArray(value)
|
|
357
|
+
? value.map((item) => String(item).trim().toLowerCase()).filter(Boolean)
|
|
358
|
+
: [];
|
|
359
|
+
}
|
|
360
|
+
function loadRecipeFromSkillsManifest(path) {
|
|
361
|
+
let raw;
|
|
362
|
+
const manifestPath = resolve(path);
|
|
363
|
+
try {
|
|
364
|
+
raw = readFileSync(manifestPath, 'utf8');
|
|
365
|
+
}
|
|
366
|
+
catch {
|
|
367
|
+
return { ok: false, error: 'recipe from-skills cannot read --manifest file' };
|
|
368
|
+
}
|
|
369
|
+
let parsed;
|
|
370
|
+
try {
|
|
371
|
+
parsed = JSON.parse(raw);
|
|
372
|
+
}
|
|
373
|
+
catch {
|
|
374
|
+
return { ok: false, error: 'recipe from-skills --manifest must be valid JSON' };
|
|
375
|
+
}
|
|
376
|
+
if (!isPlainRecord(parsed))
|
|
377
|
+
return { ok: false, error: 'recipe from-skills --manifest must be a JSON object' };
|
|
378
|
+
const title = typeof parsed['title'] === 'string' ? parsed['title'].trim() : '';
|
|
379
|
+
if (!title)
|
|
380
|
+
return { ok: false, error: 'recipe from-skills manifest requires title' };
|
|
381
|
+
const rawSteps = parsed['steps'];
|
|
382
|
+
if (!Array.isArray(rawSteps) || rawSteps.length === 0)
|
|
383
|
+
return { ok: false, error: 'recipe from-skills manifest requires non-empty steps[]' };
|
|
384
|
+
if (rawSteps.length > MAX_RECIPE_STEPS)
|
|
385
|
+
return { ok: false, error: `recipe from-skills supports at most ${MAX_RECIPE_STEPS} steps` };
|
|
386
|
+
const priceRaw = parsed['pricePerExecution'];
|
|
387
|
+
if (priceRaw === null)
|
|
388
|
+
return { ok: false, error: 'recipe from-skills pricePerExecution must be a non-negative number' };
|
|
389
|
+
const price = priceRaw === undefined ? undefined : Number(priceRaw);
|
|
390
|
+
if (price !== undefined && (!Number.isFinite(price) || price < 0))
|
|
391
|
+
return { ok: false, error: 'recipe from-skills pricePerExecution must be a non-negative number' };
|
|
392
|
+
const baseDir = dirname(manifestPath);
|
|
393
|
+
const steps = [];
|
|
394
|
+
for (let i = 0; i < rawSteps.length; i += 1) {
|
|
395
|
+
const rawStep = rawSteps[i];
|
|
396
|
+
if (!isPlainRecord(rawStep))
|
|
397
|
+
return { ok: false, error: `recipe from-skills step ${i + 1} must be a JSON object` };
|
|
398
|
+
const skillRef = typeof rawStep['skill'] === 'string' ? rawStep['skill'].trim() : '';
|
|
399
|
+
if (!skillRef)
|
|
400
|
+
return { ok: false, error: `recipe from-skills step ${i + 1} requires skill` };
|
|
401
|
+
let skill;
|
|
402
|
+
try {
|
|
403
|
+
skill = readFileSync(resolveManifestRef(baseDir, skillRef), 'utf8');
|
|
404
|
+
}
|
|
405
|
+
catch {
|
|
406
|
+
return { ok: false, error: `recipe from-skills step ${i + 1} cannot read skill` };
|
|
407
|
+
}
|
|
408
|
+
const execution = loadSkillExecution(rawStep['execution'], baseDir, i + 1);
|
|
409
|
+
if (!execution.ok)
|
|
410
|
+
return execution;
|
|
411
|
+
const scenario = typeof rawStep['scenario'] === 'string' && rawStep['scenario'].trim()
|
|
412
|
+
? rawStep['scenario'].trim()
|
|
413
|
+
: undefined;
|
|
414
|
+
steps.push({
|
|
415
|
+
skill,
|
|
416
|
+
execution: execution.value,
|
|
417
|
+
...(scenario ? { scenario } : {}),
|
|
418
|
+
});
|
|
419
|
+
}
|
|
420
|
+
const description = typeof parsed['description'] === 'string' && parsed['description'].trim()
|
|
421
|
+
? parsed['description'].trim()
|
|
422
|
+
: undefined;
|
|
423
|
+
return {
|
|
424
|
+
ok: true,
|
|
425
|
+
value: {
|
|
426
|
+
title,
|
|
427
|
+
...(description ? { description } : {}),
|
|
428
|
+
...(price !== undefined ? { pricePerExecution: price } : {}),
|
|
429
|
+
steps,
|
|
430
|
+
},
|
|
431
|
+
};
|
|
432
|
+
}
|
|
433
|
+
function loadSkillExecution(raw, baseDir, stepNumber) {
|
|
434
|
+
if (typeof raw === 'string' && raw.trim()) {
|
|
435
|
+
let text;
|
|
436
|
+
try {
|
|
437
|
+
text = readFileSync(resolveManifestRef(baseDir, raw.trim()), 'utf8');
|
|
438
|
+
}
|
|
439
|
+
catch {
|
|
440
|
+
return { ok: false, error: `recipe from-skills step ${stepNumber} cannot read execution` };
|
|
441
|
+
}
|
|
442
|
+
try {
|
|
443
|
+
const parsed = JSON.parse(text);
|
|
444
|
+
if (isPlainRecord(parsed))
|
|
445
|
+
return { ok: true, value: parsed };
|
|
446
|
+
return { ok: false, error: `recipe from-skills step ${stepNumber} execution must be a JSON object` };
|
|
447
|
+
}
|
|
448
|
+
catch {
|
|
449
|
+
return { ok: false, error: `recipe from-skills step ${stepNumber} execution must be valid JSON` };
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
if (isPlainRecord(raw))
|
|
453
|
+
return { ok: true, value: raw };
|
|
454
|
+
return { ok: false, error: `recipe from-skills step ${stepNumber} requires execution evidence` };
|
|
455
|
+
}
|
|
456
|
+
function resolveManifestRef(baseDir, ref) {
|
|
457
|
+
return isAbsolute(ref) ? ref : resolve(baseDir, ref);
|
|
458
|
+
}
|
|
459
|
+
function isPlainRecord(value) {
|
|
460
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
461
|
+
}
|
|
462
|
+
function recipeFromSkillsPayload(opts) {
|
|
463
|
+
return {
|
|
464
|
+
ok: opts.ok ?? true,
|
|
465
|
+
group: 'recipe.from_skills',
|
|
466
|
+
mode: opts.mode,
|
|
467
|
+
title: opts.title,
|
|
468
|
+
...(opts.recipeId ? { recipeId: opts.recipeId } : {}),
|
|
469
|
+
...(opts.error ? { error: opts.error } : {}),
|
|
470
|
+
publish: opts.publish,
|
|
471
|
+
steps: opts.steps.map((step) => ({
|
|
472
|
+
position: step.position,
|
|
473
|
+
geneId: step.geneId,
|
|
474
|
+
geneAssetId: step.geneAssetId,
|
|
475
|
+
capsuleId: step.capsuleId,
|
|
476
|
+
})),
|
|
477
|
+
};
|
|
478
|
+
}
|
|
153
479
|
async function callRecipeWithAuthRetry(hub, tag, fn, io) {
|
|
154
480
|
try {
|
|
155
481
|
return await fn();
|
|
@@ -198,6 +524,20 @@ function parseBuildArgs(args) {
|
|
|
198
524
|
},
|
|
199
525
|
};
|
|
200
526
|
}
|
|
527
|
+
function parseFromSkillsArgs(args) {
|
|
528
|
+
const manifestPath = flagValue(args, '--manifest');
|
|
529
|
+
if (!manifestPath)
|
|
530
|
+
return { ok: false, error: 'recipe from-skills requires --manifest <file>' };
|
|
531
|
+
return {
|
|
532
|
+
ok: true,
|
|
533
|
+
value: {
|
|
534
|
+
sub: 'from-skills',
|
|
535
|
+
manifestPath,
|
|
536
|
+
publish: args.includes('--publish'),
|
|
537
|
+
jsonOut: args.includes('--json'),
|
|
538
|
+
},
|
|
539
|
+
};
|
|
540
|
+
}
|
|
201
541
|
function parseReuseArgs(args) {
|
|
202
542
|
const recipeId = flagValue(args, '--id') ?? firstPositional(args);
|
|
203
543
|
if (!recipeId)
|
|
@@ -559,6 +899,8 @@ function recipeUsage() {
|
|
|
559
899
|
'Recipe subcommands:',
|
|
560
900
|
' evolver recipe build --title <title> --genes <asset_id,...> [--description <text>] [--price <n>] [--publish]',
|
|
561
901
|
' Creates a draft recipe by default. --publish is explicit.',
|
|
902
|
+
' evolver recipe from-skills --manifest <file> [--publish] [--json]',
|
|
903
|
+
' Distills ordered SKILL.md steps with execution evidence, then creates a recipe.',
|
|
562
904
|
' evolver recipe reuse --id <recipe_id> [--input <json-object>] [--json]',
|
|
563
905
|
].join('\n');
|
|
564
906
|
}
|