@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.
Files changed (91) hide show
  1. package/dist/antiGeneBenchmark.d.ts +9 -0
  2. package/dist/antiGeneBenchmark.js +173 -0
  3. package/dist/antiGeneRollout.d.ts +14 -0
  4. package/dist/antiGeneRollout.js +276 -0
  5. package/dist/atp.d.ts +122 -0
  6. package/dist/atp.js +413 -0
  7. package/dist/atpAutoDeliver.d.ts +53 -0
  8. package/dist/atpAutoDeliver.js +197 -0
  9. package/dist/atpAutobuyPrompt.d.ts +48 -0
  10. package/dist/atpAutobuyPrompt.js +109 -0
  11. package/dist/autoDistillAntiGene.d.ts +63 -0
  12. package/dist/autoDistillAntiGene.js +396 -0
  13. package/dist/autoDistillLlm.d.ts +94 -0
  14. package/dist/autoDistillLlm.js +510 -0
  15. package/dist/autoDistillTranscript.d.ts +87 -0
  16. package/dist/autoDistillTranscript.js +364 -0
  17. package/dist/autoRecall.d.ts +25 -0
  18. package/dist/autoRecall.js +80 -0
  19. package/dist/autoexec.d.ts +237 -0
  20. package/dist/autoexec.js +1041 -0
  21. package/dist/cli.d.ts +2 -0
  22. package/dist/cli.js +7 -0
  23. package/dist/cliContracts.d.ts +72 -0
  24. package/dist/cliContracts.js +815 -0
  25. package/dist/commands.d.ts +9 -0
  26. package/dist/commands.js +10 -0
  27. package/dist/cursorRewrite.d.ts +42 -0
  28. package/dist/cursorRewrite.js +65 -0
  29. package/dist/cycleConsumer.d.ts +42 -0
  30. package/dist/cycleConsumer.js +519 -0
  31. package/dist/daemonLoop.d.ts +33 -0
  32. package/dist/daemonLoop.js +72 -0
  33. package/dist/dispatch.d.ts +10 -0
  34. package/dist/dispatch.js +75 -0
  35. package/dist/distillObserver.d.ts +33 -0
  36. package/dist/distillObserver.js +146 -0
  37. package/dist/distillPrimitives.d.ts +48 -0
  38. package/dist/distillPrimitives.js +142 -0
  39. package/dist/doctor.d.ts +54 -0
  40. package/dist/doctor.js +931 -0
  41. package/dist/geneValue.d.ts +37 -0
  42. package/dist/geneValue.js +97 -0
  43. package/dist/index.d.ts +193 -0
  44. package/dist/index.js +1135 -0
  45. package/dist/lifecycle.d.ts +75 -0
  46. package/dist/lifecycle.js +859 -0
  47. package/dist/login.d.ts +10 -0
  48. package/dist/login.js +38 -0
  49. package/dist/migrate/divergenceAudit.d.ts +29 -0
  50. package/dist/migrate/divergenceAudit.js +37 -0
  51. package/dist/migrate/fieldMap.d.ts +18 -0
  52. package/dist/migrate/fieldMap.js +68 -0
  53. package/dist/migrate/v1Import.d.ts +16 -0
  54. package/dist/migrate/v1Import.js +118 -0
  55. package/dist/phub.d.ts +18 -0
  56. package/dist/phub.js +284 -0
  57. package/dist/recall.d.ts +26 -0
  58. package/dist/recall.js +162 -0
  59. package/dist/recipe.d.ts +61 -0
  60. package/dist/recipe.js +564 -0
  61. package/dist/reflectionObserver.d.ts +8 -0
  62. package/dist/reflectionObserver.js +6 -0
  63. package/dist/reuse.d.ts +48 -0
  64. package/dist/reuse.js +300 -0
  65. package/dist/reuseReport.d.ts +20 -0
  66. package/dist/reuseReport.js +255 -0
  67. package/dist/reviewFilter.d.ts +4 -0
  68. package/dist/reviewFilter.js +6 -0
  69. package/dist/runtimeSessionSource.d.ts +9 -0
  70. package/dist/runtimeSessionSource.js +29 -0
  71. package/dist/setupHooks.d.ts +2 -0
  72. package/dist/setupHooks.js +410 -0
  73. package/dist/skill2gep.d.ts +144 -0
  74. package/dist/skill2gep.js +321 -0
  75. package/dist/skillDistill.d.ts +75 -0
  76. package/dist/skillDistill.js +342 -0
  77. package/dist/solo/breaker.d.ts +14 -0
  78. package/dist/solo/breaker.js +21 -0
  79. package/dist/solo/gitGuard.d.ts +17 -0
  80. package/dist/solo/gitGuard.js +62 -0
  81. package/dist/solo/mode.d.ts +12 -0
  82. package/dist/solo/mode.js +55 -0
  83. package/dist/thesis.d.ts +43 -0
  84. package/dist/thesis.js +179 -0
  85. package/dist/trajectoryExport.d.ts +1 -0
  86. package/dist/trajectoryExport.js +895 -0
  87. package/dist/valueDigest.d.ts +33 -0
  88. package/dist/valueDigest.js +94 -0
  89. package/dist/version.d.ts +2 -0
  90. package/dist/version.js +14 -0
  91. package/package.json +38 -0
package/dist/recall.js ADDED
@@ -0,0 +1,162 @@
1
+ // `evolver recall` — run the recallVerifier primitive (#204) over a real session transcript so an operator can
2
+ // SEE which injected genes the agent actually used. Manual entry point for the inject->recall attribution loop
3
+ // Genes come either from explicit `--gene <id>` flags or, with `--from-inject`, from the value.inject event tied to
4
+ // THIS transcript: the inject is stamped with the runtime session id (#205) and the Claude Code transcript is named
5
+ // `<session_id>.jsonl`, so recall matches them by session id (falling back to the most-recent inject for un-stamped
6
+ // events / runtimes with no id). Pure logic lives in evolver-core/ops/recall; this module is the IO glue (read
7
+ // transcript -> turns, resolve genes from the store, pull geneIds off the matching inject event).
8
+ import { readFileSync } from 'node:fs';
9
+ import { basename } from 'node:path';
10
+ import { assetstore, events, ops } from '@evomap/evolver-core';
11
+ import { adapterForPath } from '@evomap/evolver-runtime-adapters';
12
+ /** Claude Code names a transcript `<session_id>.jsonl`, so the basename (minus extension) is the session id used to
13
+ * match the inject event that produced THIS session (#205). Other runtimes' names simply won't match any stamped
14
+ * sessionId, and the caller falls back to the most-recent inject — safe, never wrong, just less precise. */
15
+ export function sessionIdFromTranscript(p) {
16
+ const base = basename(p).replace(/\.jsonl$/i, '');
17
+ return base.length > 0 ? base : undefined;
18
+ }
19
+ /** Pick the `value.inject` event for this run: the latest (max seq) one STAMPED with `sessionId` when that matches
20
+ * the transcript's session (#205 precise tie), else the latest inject overall (back-compat for un-stamped events
21
+ * and runtimes with no session id). Returns undefined when there is no inject event at all. */
22
+ export function pickInjectEvent(evts, sessionId) {
23
+ let bestMatch;
24
+ let bestAny;
25
+ for (const e of evts) {
26
+ if (e.type !== ops.VALUE_INJECT_EVENT)
27
+ continue;
28
+ if (bestAny === undefined || e.seq > bestAny.seq)
29
+ bestAny = e;
30
+ if (sessionId !== undefined && e.payload?.['sessionId'] === sessionId && (bestMatch === undefined || e.seq > bestMatch.seq))
31
+ bestMatch = e;
32
+ }
33
+ return bestMatch ?? bestAny;
34
+ }
35
+ export function geneIdsOf(e) {
36
+ const ids = e?.payload?.['geneIds'];
37
+ return Array.isArray(ids) ? ids.filter((x) => typeof x === 'string') : [];
38
+ }
39
+ export function geneFromAsset(a) {
40
+ // Report under the logical id when present (the `gene-a` id value.inject records), else the content asset_id.
41
+ const geneId = typeof a['id'] === 'string' ? String(a['id']) : String(a.asset_id);
42
+ const strategy = Array.isArray(a['strategy']) ? a['strategy'].filter((s) => typeof s === 'string') : undefined;
43
+ const summary = typeof a['summary'] === 'string' ? a['summary'] : undefined;
44
+ return { geneId, ...(strategy ? { strategy } : {}), ...(summary ? { summary } : {}) };
45
+ }
46
+ // Resolve a --gene argument to its Gene asset, mirroring `evolver review`: an asset_id (sha256:…) hits the index
47
+ // directly (guarded to type Gene, since asset_id is a content hash), while a LOGICAL id (the `gene-a` style id that
48
+ // value.inject records in geneIds) falls back to a bounded Gene-only scan. Resolving via asset_id ALONE would report
49
+ // every inject-logged logical id as "not found" even when the gene exists — exactly the id an operator would paste in.
50
+ export async function resolveGene(store, id) {
51
+ let g = id.startsWith('sha256:') ? await store.get(id) : null;
52
+ if (g && g.type !== 'Gene')
53
+ g = null;
54
+ if (!g) {
55
+ const genes = await store.list('Gene', 1000);
56
+ g = genes.find((x) => String(x['id']) === id || String(x.asset_id) === id) ?? null;
57
+ }
58
+ return g;
59
+ }
60
+ /** Parse argv: positional <transcript> + repeatable `--gene <assetId>` + `--from-inject`. */
61
+ function parseArgs(argv) {
62
+ const geneIds = [];
63
+ let transcript;
64
+ let fromInject = false;
65
+ for (let i = 0; i < argv.length; i++) {
66
+ const a = argv[i];
67
+ if (a === '--gene') {
68
+ const v = argv[++i];
69
+ if (v)
70
+ geneIds.push(v);
71
+ continue;
72
+ }
73
+ if (a === '--from-inject') {
74
+ fromInject = true;
75
+ continue;
76
+ }
77
+ if (!a.startsWith('-') && transcript === undefined)
78
+ transcript = a;
79
+ }
80
+ return { ...(transcript !== undefined ? { transcript } : {}), geneIds, fromInject };
81
+ }
82
+ export async function runRecall(argv, deps = {}) {
83
+ const log = deps.log ?? ((s) => process.stdout.write(`${s}\n`));
84
+ const err = deps.err ?? ((s) => process.stderr.write(`${s}\n`));
85
+ const { transcript, geneIds, fromInject } = parseArgs(argv);
86
+ // --from-inject: pull the geneIds off the most recent value.inject root_event so the operator does not have to
87
+ // retype them (a semi-automatic step toward the auto-loop, which still needs the inject<->session key #205 to
88
+ // pick the RIGHT inject for THIS transcript). Union with any explicit --gene; dedupe preserving order.
89
+ if (fromInject) {
90
+ const evts = (deps.readEvents ?? events.readEvents)();
91
+ const wantSession = transcript ? sessionIdFromTranscript(transcript) : undefined;
92
+ const picked = pickInjectEvent(evts, wantSession);
93
+ const fromEvent = geneIdsOf(picked);
94
+ // Empty inject is fatal only when there is nothing else to run; with explicit --gene present, honour the union
95
+ // and continue (just warn) rather than discarding the genes the operator typed.
96
+ if (fromEvent.length === 0) {
97
+ if (geneIds.length === 0) {
98
+ err('recall: --from-inject found no value.inject event with geneIds');
99
+ return 1;
100
+ }
101
+ err('recall: --from-inject found no value.inject geneIds; proceeding with explicit --gene only');
102
+ }
103
+ else if (wantSession !== undefined && picked?.payload?.['sessionId'] !== wantSession
104
+ && evts.some((e) => e.type === ops.VALUE_INJECT_EVENT && typeof e.payload?.['sessionId'] === 'string')) {
105
+ // Stamping IS in use (some inject carries a sessionId) but none matched this transcript's session, so the
106
+ // genes come from the most-recent inject, not the one provably tied to this transcript. Stay silent when NO
107
+ // inject is stamped at all (the precise-match path is simply dormant — e.g. pre-#205 events).
108
+ err(`recall: no value.inject matched session ${wantSession}; using the most recent inject instead`);
109
+ }
110
+ for (const id of fromEvent)
111
+ if (!geneIds.includes(id))
112
+ geneIds.push(id);
113
+ }
114
+ if (!transcript || geneIds.length === 0) {
115
+ err('用法: evolver recall <session-transcript> (--gene <id> ... | --from-inject)');
116
+ return 2;
117
+ }
118
+ let content;
119
+ try {
120
+ content = (deps.readFile ?? ((p) => readFileSync(p, 'utf8')))(transcript);
121
+ }
122
+ catch (e) {
123
+ err(`recall: cannot read ${transcript}: ${e instanceof Error ? e.message : String(e)}`);
124
+ return 1;
125
+ }
126
+ const parse = deps.parseTranscript ?? ((p, c) => (adapterForPath(p)?.parse(c) ?? []));
127
+ const parsed = parse(transcript, content);
128
+ if (parsed.length === 0) {
129
+ err(`recall: no turns parsed from ${transcript} (unrecognized session format?)`);
130
+ return 1;
131
+ }
132
+ // Drop meta turns (heartbeats, NO_REPLY, empty) before scoring: they are not substantive agent output, so
133
+ // counting them would inflate overlap and, worse, flip a heartbeat-only session from 'unknown' (no judgeable
134
+ // output) to 'unused'. Keep the format-recognition check above on the RAW parse so "only meta" is not mistaken
135
+ // for "unrecognized format" — a transcript of pure heartbeats correctly yields 'unknown' per gene.
136
+ const turns = parsed.filter((t) => !t.isMeta).map((t) => ({ role: t.role, text: t.text }));
137
+ const store = deps.store ?? new assetstore.LocalJsonlProvider(events.assetsDir());
138
+ const genes = [];
139
+ for (const id of geneIds) {
140
+ const a = await resolveGene(store, id);
141
+ if (!a) {
142
+ err(`recall: gene not found in local store: ${id}`);
143
+ continue;
144
+ }
145
+ genes.push(geneFromAsset(a));
146
+ }
147
+ if (genes.length === 0) {
148
+ err('recall: no resolvable genes');
149
+ return 1;
150
+ }
151
+ const results = ops.verifyInjectedGenes(genes, turns);
152
+ const sum = ops.summarizeRecall(results);
153
+ for (const r of results) {
154
+ log(`${r.recalled.toUpperCase().padEnd(7)} ${r.geneId} score=${r.score.toFixed(2)} matched=[${r.matched.join(', ')}]`);
155
+ }
156
+ log(`recall: ${sum.used} used / ${sum.unused} unused / ${sum.unknown} unknown of ${sum.total}`);
157
+ if (sum.pruneCandidates.length > 0)
158
+ log(`prune candidates (injected but unused): ${sum.pruneCandidates.join(', ')}`);
159
+ return 0;
160
+ }
161
+ /** Registry-shaped handler (argv -> exit code). */
162
+ export const runRecallCommand = (argv) => runRecall(argv);
@@ -0,0 +1,61 @@
1
+ import { assetstore, type hub as hubNs } from '@evomap/evolver-core';
2
+ import type { ConnectPublicOptions, PublicHubCapability } from '@evomap/evolver-adapter-public';
3
+ export interface RecipeCliDeps {
4
+ hub?: RecipeHub;
5
+ store?: assetstore.AssetStoreProvider;
6
+ env?: NodeJS.ProcessEnv;
7
+ log?: (line: string) => void;
8
+ err?: (line: string) => void;
9
+ connectHub?: (opts: ConnectPublicOptions) => {
10
+ hub: PublicHubCapability;
11
+ auth: hubNs.AuthProvider;
12
+ };
13
+ }
14
+ export interface RecipeHub {
15
+ recipes?: hubNs.RecipeCapability;
16
+ hello?(opts: {
17
+ rotate: boolean;
18
+ evolverVersion?: string;
19
+ }): Promise<{
20
+ ok: boolean;
21
+ error?: string;
22
+ }>;
23
+ }
24
+ type ParseResult<T> = {
25
+ ok: true;
26
+ value: T;
27
+ } | {
28
+ ok: false;
29
+ error: string;
30
+ };
31
+ export interface RecipeBuildOptions {
32
+ sub: 'build';
33
+ title: string;
34
+ assetIds: string[];
35
+ description?: string;
36
+ pricePerExecution?: number;
37
+ publish: boolean;
38
+ }
39
+ export interface RecipeReuseOptions {
40
+ sub: 'reuse';
41
+ recipeId: string;
42
+ inputPayload: Record<string, unknown>;
43
+ jsonOut: boolean;
44
+ }
45
+ export type RecipeOptions = RecipeBuildOptions | RecipeReuseOptions;
46
+ export declare function runRecipeCommand(argv: readonly string[], deps?: RecipeCliDeps): Promise<number>;
47
+ export declare function createRecipeHubFromEnv(env?: NodeJS.ProcessEnv, connectHub?: (opts: ConnectPublicOptions) => {
48
+ hub: PublicHubCapability;
49
+ auth: hubNs.AuthProvider;
50
+ }): PublicHubCapability;
51
+ export declare function parseRecipeArgs(argv: readonly string[]): ParseResult<RecipeOptions>;
52
+ /**
53
+ * The EXPLICIT home overrides (EVOMAP_DIR / EVOLVER_HOME / EVOMAP_HOME) the recipe credential layer honors,
54
+ * resolved purely from the passed env with no process.env fallback. Exported so `reset-local-secret` (index.ts)
55
+ * can clear the SAME explicit directories the recipe path may persist rotated legacy files into
56
+ * (rotatePersistDir = recipeHomeCandidates(env)[0], which is the first explicit home when any is set) — otherwise
57
+ * a reset that only wiped ~/.evomap would leave a stale node_secret under EVOMAP_DIR/EVOMAP_HOME that resurrects on
58
+ * the next recipe run (H3). Kept env-pure (no events.evomapHome()) so reset stays hermetic under an injected env.
59
+ */
60
+ export declare function explicitRecipeHomes(env: NodeJS.ProcessEnv): string[];
61
+ export {};