@evomap/evolver-cli 2.0.0-beta.18 → 2.0.0-beta.19

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 (63) hide show
  1. package/dist/antiGeneRollout.js +7 -3
  2. package/dist/assetTrust.js +14 -1
  3. package/dist/atp.d.ts +8 -3
  4. package/dist/atp.js +82 -11
  5. package/dist/atpAutoBuyer.d.ts +120 -0
  6. package/dist/atpAutoBuyer.js +814 -0
  7. package/dist/atpAutoDeliver.js +2 -2
  8. package/dist/autoDistillLlm.js +2 -1
  9. package/dist/autoDistillTranscript.js +3 -2
  10. package/dist/autoexec.d.ts +90 -13
  11. package/dist/autoexec.js +731 -84
  12. package/dist/cli.js +13 -0
  13. package/dist/cliContracts.d.ts +5 -2
  14. package/dist/cliContracts.js +135 -8
  15. package/dist/commands.d.ts +1 -0
  16. package/dist/commands.js +1 -0
  17. package/dist/curriculumCapabilityGaps.d.ts +6 -0
  18. package/dist/curriculumCapabilityGaps.js +24 -0
  19. package/dist/cycleConsumer.d.ts +4 -0
  20. package/dist/cycleConsumer.js +175 -20
  21. package/dist/dashboard.js +47 -9
  22. package/dist/dispatch.js +6 -2
  23. package/dist/distillPrimitives.js +18 -6
  24. package/dist/doctor.js +63 -5
  25. package/dist/identityHome.js +2 -1
  26. package/dist/index.d.ts +67 -39
  27. package/dist/index.js +504 -185
  28. package/dist/learningTrace.js +8 -2
  29. package/dist/lifecycle.d.ts +54 -1
  30. package/dist/lifecycle.js +489 -37
  31. package/dist/materialSnapshot.d.ts +9 -1
  32. package/dist/materialSnapshot.js +23 -6
  33. package/dist/migrate/envTranslate.d.ts +26 -0
  34. package/dist/migrate/envTranslate.js +145 -0
  35. package/dist/migrate/oauthImport.d.ts +66 -0
  36. package/dist/migrate/oauthImport.js +667 -0
  37. package/dist/migrate/v1Import.d.ts +13 -1
  38. package/dist/migrate/v1Import.js +621 -122
  39. package/dist/promptRecallHook.d.ts +24 -0
  40. package/dist/promptRecallHook.js +425 -0
  41. package/dist/recallVerifyReport.d.ts +37 -0
  42. package/dist/recallVerifyReport.js +244 -0
  43. package/dist/requiredSandboxValidation.d.ts +5 -0
  44. package/dist/requiredSandboxValidation.js +4 -0
  45. package/dist/reuse.d.ts +1 -0
  46. package/dist/reuse.js +45 -37
  47. package/dist/runtimeCapabilities.js +13 -13
  48. package/dist/runtimeSessionSource.d.ts +3 -2
  49. package/dist/runtimeSessionSource.js +63 -11
  50. package/dist/sessionIngest.d.ts +37 -0
  51. package/dist/sessionIngest.js +156 -0
  52. package/dist/setupHooks.js +95 -1
  53. package/dist/skill2gep.d.ts +4 -7
  54. package/dist/skill2gep.js +4 -21
  55. package/dist/solo/mode.js +1 -0
  56. package/dist/sync.js +125 -23
  57. package/dist/thesis.d.ts +1 -1
  58. package/dist/thesis.js +18 -3
  59. package/dist/trajectoryExport.js +21 -3
  60. package/dist/v1Compat.d.ts +1 -0
  61. package/dist/v1Compat.js +9 -0
  62. package/dist/workflowRuntime.js +24 -18
  63. package/package.json +10 -7
@@ -0,0 +1,24 @@
1
+ import { assetstore, hub } from '@evomap/evolver-core';
2
+ export type PromptRecallMode = 'off' | 'shadow' | 'enforce';
3
+ /** The hook sees a raw user prompt, so reject oversized payloads instead of retaining a partial JSON document. */
4
+ export declare const MAX_PROMPT_RECALL_STDIN_BYTES: number;
5
+ export declare const MAX_PROMPT_RECALL_LOCAL_FILE_BYTES: number;
6
+ export declare const MAX_PROMPT_RECALL_LOCAL_TOTAL_BYTES: number;
7
+ type HookInputReader = () => string | undefined | Promise<string | undefined>;
8
+ export interface PromptRecallHookDeps {
9
+ store?: assetstore.AssetStoreProvider;
10
+ review?: assetstore.ReviewLedger;
11
+ provenance?: assetstore.ProvenanceStore;
12
+ callLog?: Pick<hub.AssetCallLog, 'append'>;
13
+ env?: NodeJS.ProcessEnv;
14
+ readHookInput?: HookInputReader;
15
+ stdout?: (text: string) => void;
16
+ selectionTimeoutMs?: number;
17
+ }
18
+ export declare function promptRecallMode(env?: NodeJS.ProcessEnv): PromptRecallMode;
19
+ /**
20
+ * Shared Claude Code/Codex UserPromptSubmit entrypoint. It is intentionally local-only and fail-open: no Hub
21
+ * query, no transcript read, no prompt persistence, and exactly one JSON object on stdout for every outcome.
22
+ */
23
+ export declare function runPromptRecallHook(argv: readonly string[], deps?: PromptRecallHookDeps): Promise<number>;
24
+ export {};
@@ -0,0 +1,425 @@
1
+ import { assetstore, events, hub, signals } from '@evomap/evolver-core';
2
+ import { loadEnvFileFromEnv } from '@evomap/evolver-mcp';
3
+ import { lstatSync } from 'node:fs';
4
+ import { join } from 'node:path';
5
+ import { performance } from 'node:perf_hooks';
6
+ /** The hook sees a raw user prompt, so reject oversized payloads instead of retaining a partial JSON document. */
7
+ export const MAX_PROMPT_RECALL_STDIN_BYTES = 64 * 1024;
8
+ export const MAX_PROMPT_RECALL_LOCAL_FILE_BYTES = 4 * 1024 * 1024;
9
+ export const MAX_PROMPT_RECALL_LOCAL_TOTAL_BYTES = 8 * 1024 * 1024;
10
+ const PROMPT_RECALL_STDIN_TIMEOUT_MS = 250;
11
+ const PROMPT_RECALL_SELECTION_TIMEOUT_MS = 750;
12
+ const PROMPT_RECALL_SCAN_LIMIT = 1000;
13
+ const PROMPT_RECALL_CONTEXT_MAX_CHARS = 800;
14
+ const PROMPT_RECALL_DEFAULT_MAX_GENES = 1;
15
+ const PROMPT_RECALL_MAX_GENES = 10;
16
+ const PROMPT_RECALL_MATCH_CHARS = 16 * 1024;
17
+ const PROMPT_RECALL_MATCH_TOKENS = 512;
18
+ const PROMPT_RECALL_SIGNAL_PATTERNS = 16;
19
+ const PROMPT_RECALL_SIGNAL_PATTERN_CHARS = 512;
20
+ const PROMPT_RECALL_SIGNAL_ALIASES = 4;
21
+ const PROMPT_RECALL_SIGNAL_ALIAS_CHARS = 192;
22
+ const PROMPT_RECALL_SIGNAL_ALIAS_TOKENS = 12;
23
+ const PROMPT_RECALL_TOKEN_CHARS = 96;
24
+ const PROMPT_RECALL_GENE_FIELD_CHARS = 512;
25
+ const PROMPT_RECALL_YIELD_EVERY_GENES = 8;
26
+ const PROMPT_RECALL_LOCAL_FILES = [
27
+ 'genes.jsonl',
28
+ 'capsules.jsonl',
29
+ 'events.jsonl',
30
+ 'anti-genes.jsonl',
31
+ 'review.jsonl',
32
+ 'provenance.jsonl',
33
+ ];
34
+ export function promptRecallMode(env = process.env) {
35
+ const value = String(env['EVOLVER_RECALL_MODE'] ?? '').trim().toLowerCase();
36
+ return value === 'shadow' || value === 'enforce' ? value : 'off';
37
+ }
38
+ function promptRecallMaxGenes(env) {
39
+ const parsed = Number.parseInt(String(env['EVOLVER_RECALL_MAX'] ?? ''), 10);
40
+ return Number.isFinite(parsed) && parsed > 0 && parsed <= PROMPT_RECALL_MAX_GENES
41
+ ? parsed
42
+ : PROMPT_RECALL_DEFAULT_MAX_GENES;
43
+ }
44
+ function readStdinBounded(timeoutMs = PROMPT_RECALL_STDIN_TIMEOUT_MS, maxBytes = MAX_PROMPT_RECALL_STDIN_BYTES) {
45
+ return new Promise((resolve) => {
46
+ const stdin = process.stdin;
47
+ if (stdin.isTTY) {
48
+ resolve(undefined);
49
+ return;
50
+ }
51
+ let data = '';
52
+ let bytes = 0;
53
+ let settled = false;
54
+ const finish = (value) => {
55
+ if (settled)
56
+ return;
57
+ settled = true;
58
+ clearTimeout(timer);
59
+ stdin.removeListener('data', onData);
60
+ stdin.removeListener('end', onEnd);
61
+ stdin.removeListener('error', onError);
62
+ try {
63
+ stdin.pause();
64
+ }
65
+ catch { /* already closed */ }
66
+ resolve(value);
67
+ };
68
+ const onData = (chunk) => {
69
+ const text = chunk.toString();
70
+ bytes += Buffer.byteLength(text, 'utf8');
71
+ if (bytes > maxBytes) {
72
+ finish(undefined);
73
+ return;
74
+ }
75
+ data += text;
76
+ };
77
+ const onEnd = () => finish(data);
78
+ const onError = () => finish(undefined);
79
+ const timer = setTimeout(() => finish(undefined), timeoutMs);
80
+ timer.unref?.();
81
+ stdin.setEncoding('utf8');
82
+ stdin.on('data', onData);
83
+ stdin.on('end', onEnd);
84
+ stdin.on('error', onError);
85
+ try {
86
+ stdin.resume();
87
+ }
88
+ catch {
89
+ finish(undefined);
90
+ }
91
+ });
92
+ }
93
+ async function readHookPayload(readHookInput) {
94
+ const raw = readHookInput ? await readHookInput() : await readStdinBounded();
95
+ if (typeof raw !== 'string' || Buffer.byteLength(raw, 'utf8') > MAX_PROMPT_RECALL_STDIN_BYTES)
96
+ return undefined;
97
+ return raw;
98
+ }
99
+ function normalizedTokens(text, maxChars, maxTokens) {
100
+ const bounded = text.slice(0, maxChars);
101
+ const matches = bounded
102
+ .toLowerCase()
103
+ .normalize('NFKC')
104
+ .match(/[\p{L}\p{N}]+/gu)
105
+ ?.filter((token) => (token.length >= 2 || /^\d+$/.test(token)) && token.length <= PROMPT_RECALL_TOKEN_CHARS)
106
+ ?? [];
107
+ // A character-boundary cut can leave a partial final token. Dropping it is conservative: it avoids a false
108
+ // literal match while keeping prompt processing independent of the raw prompt's total size.
109
+ if (text.length > maxChars && matches.length > 0)
110
+ matches.pop();
111
+ return matches.slice(0, maxTokens);
112
+ }
113
+ function normalizedAliasTokens(text) {
114
+ const runs = text
115
+ .toLowerCase()
116
+ .normalize('NFKC')
117
+ .match(/[\p{L}\p{N}]+/gu) ?? [];
118
+ if (runs.some((token) => token.length > PROMPT_RECALL_TOKEN_CHARS))
119
+ return [];
120
+ const tokens = runs.filter((token) => token.length >= 2 || /^\d+$/.test(token));
121
+ return tokens.length <= PROMPT_RECALL_SIGNAL_ALIAS_TOKENS ? tokens : [];
122
+ }
123
+ function promptTokenSegments(prompt) {
124
+ if (prompt.length <= PROMPT_RECALL_MATCH_CHARS) {
125
+ return [normalizedTokens(prompt, PROMPT_RECALL_MATCH_CHARS, PROMPT_RECALL_MATCH_TOKENS)];
126
+ }
127
+ const segmentChars = Math.floor(PROMPT_RECALL_MATCH_CHARS / 2);
128
+ const segmentTokens = Math.floor(PROMPT_RECALL_MATCH_TOKENS / 2);
129
+ const tailTokens = normalizedTokens(prompt.slice(-segmentChars), segmentChars, segmentTokens);
130
+ // The tail slice may begin in the middle of a token. Discard its first run rather than admit a prefix match.
131
+ tailTokens.shift();
132
+ return [
133
+ normalizedTokens(prompt, segmentChars, segmentTokens),
134
+ tailTokens,
135
+ ];
136
+ }
137
+ function buildPromptSequenceIndex(segments) {
138
+ const root = { children: new Map() };
139
+ for (const tokens of segments) {
140
+ for (let start = 0; start < tokens.length; start += 1) {
141
+ let node = root;
142
+ const end = Math.min(tokens.length, start + PROMPT_RECALL_SIGNAL_ALIAS_TOKENS);
143
+ for (let offset = start; offset < end; offset += 1) {
144
+ const token = tokens[offset];
145
+ let child = node.children.get(token);
146
+ if (!child) {
147
+ child = { children: new Map() };
148
+ node.children.set(token, child);
149
+ }
150
+ node = child;
151
+ }
152
+ }
153
+ }
154
+ return root;
155
+ }
156
+ function containsSequence(index, needle) {
157
+ if (needle.length === 0)
158
+ return false;
159
+ let node = index;
160
+ for (const token of needle) {
161
+ const child = node.children.get(token);
162
+ if (!child)
163
+ return false;
164
+ node = child;
165
+ }
166
+ return true;
167
+ }
168
+ function boundedSignalPatterns(gene) {
169
+ const patterns = Array.isArray(gene['signals_match']) ? gene['signals_match'] : [];
170
+ return patterns
171
+ .slice(0, PROMPT_RECALL_SIGNAL_PATTERNS)
172
+ .filter((pattern) => (typeof pattern === 'string' && pattern.length <= PROMPT_RECALL_SIGNAL_PATTERN_CHARS));
173
+ }
174
+ /**
175
+ * V1 required a real local signals_match hit before prompt-time injection. Keep that conservative gate: aliases
176
+ * separated by `|` are matched as normalized token sequences, while regex-looking patterns are never evaluated
177
+ * (a persisted pattern must not be able to run an expensive regular expression on a private prompt).
178
+ */
179
+ function literalSignalHits(promptIndex, patterns) {
180
+ let hits = 0;
181
+ for (const pattern of patterns) {
182
+ const aliases = pattern.split('|', PROMPT_RECALL_SIGNAL_ALIASES + 1).slice(0, PROMPT_RECALL_SIGNAL_ALIASES);
183
+ const matched = aliases.some((alias) => {
184
+ const trimmed = alias.trim();
185
+ if (!trimmed
186
+ || trimmed.length > PROMPT_RECALL_SIGNAL_ALIAS_CHARS
187
+ || (trimmed.startsWith('/') && trimmed.lastIndexOf('/') > 0))
188
+ return false;
189
+ return containsSequence(promptIndex, normalizedAliasTokens(trimmed));
190
+ });
191
+ if (matched)
192
+ hits += 1;
193
+ }
194
+ return hits;
195
+ }
196
+ function boundedGeneField(value) {
197
+ return typeof value === 'string' ? value.slice(0, PROMPT_RECALL_GENE_FIELD_CHARS) : undefined;
198
+ }
199
+ function geneText(gene, signalsMatch) {
200
+ return [boundedGeneField(gene['id']), boundedGeneField(gene['category']), boundedGeneField(gene['summary']), ...signalsMatch]
201
+ .filter((value) => typeof value === 'string')
202
+ .join(' ');
203
+ }
204
+ function selectionExpired(budget) {
205
+ return budget.cancelled || performance.now() >= budget.deadlineMs;
206
+ }
207
+ function localRecallFilesWithinBudget(store) {
208
+ if (!(store instanceof assetstore.LocalJsonlProvider))
209
+ return true;
210
+ try {
211
+ lstatSync(join(store.baseDir, '.assetstore.lock'));
212
+ return false;
213
+ }
214
+ catch (error) {
215
+ if (error.code !== 'ENOENT')
216
+ return false;
217
+ }
218
+ let totalBytes = 0;
219
+ for (const file of PROMPT_RECALL_LOCAL_FILES) {
220
+ try {
221
+ const stat = lstatSync(join(store.baseDir, file));
222
+ if (!stat.isFile() || stat.isSymbolicLink() || stat.size > MAX_PROMPT_RECALL_LOCAL_FILE_BYTES)
223
+ return false;
224
+ totalBytes += stat.size;
225
+ if (totalBytes > MAX_PROMPT_RECALL_LOCAL_TOTAL_BYTES)
226
+ return false;
227
+ }
228
+ catch (error) {
229
+ if (error.code !== 'ENOENT')
230
+ return false;
231
+ }
232
+ }
233
+ return true;
234
+ }
235
+ function yieldToEventLoop() {
236
+ return new Promise((resolve) => setImmediate(resolve));
237
+ }
238
+ async function selectPromptGenes(prompt, store, review, provenance, maxGenes, budget) {
239
+ const tokenSegments = promptTokenSegments(prompt);
240
+ const promptTokens = tokenSegments.flat();
241
+ if (promptTokens.length === 0)
242
+ return [];
243
+ const promptIndex = buildPromptSequenceIndex(tokenSegments);
244
+ const boundedPrompt = promptTokens.join(' ');
245
+ const approved = await assetstore.listApprovedGenes(store, review, PROMPT_RECALL_SCAN_LIMIT, provenance);
246
+ if (selectionExpired(budget))
247
+ return [];
248
+ const ranked = [];
249
+ for (let index = 0; index < approved.length; index += 1) {
250
+ if (selectionExpired(budget))
251
+ return [];
252
+ const gene = approved[index];
253
+ const signalsMatch = boundedSignalPatterns(gene);
254
+ const literalHits = literalSignalHits(promptIndex, signalsMatch);
255
+ if (literalHits > 0) {
256
+ const semanticScore = signals.tagOverlapScore(promptTokens, {
257
+ signalsMatch,
258
+ geneId: boundedGeneField(gene['id']),
259
+ category: boundedGeneField(gene['category']),
260
+ summary: boundedGeneField(gene['summary']),
261
+ }) + signals.bagCosine(boundedPrompt, geneText(gene, signalsMatch));
262
+ ranked.push({
263
+ gene,
264
+ literalHits,
265
+ semanticScore,
266
+ assetKey: String(gene.asset_id).slice(0, 128),
267
+ });
268
+ }
269
+ if ((index + 1) % PROMPT_RECALL_YIELD_EVERY_GENES === 0) {
270
+ await yieldToEventLoop();
271
+ if (selectionExpired(budget))
272
+ return [];
273
+ }
274
+ }
275
+ if (selectionExpired(budget))
276
+ return [];
277
+ ranked.sort((left, right) => (right.literalHits - left.literalHits
278
+ || right.semanticScore - left.semanticScore
279
+ || left.assetKey.localeCompare(right.assetKey)));
280
+ return ranked.slice(0, maxGenes);
281
+ }
282
+ function renderGeneLine(gene) {
283
+ const id = (typeof gene['id'] === 'string' ? gene['id'] : String(gene.asset_id)).slice(0, 128);
284
+ const category = typeof gene['category'] === 'string' ? gene['category'].slice(0, 96) : '';
285
+ const summary = typeof gene['summary'] === 'string'
286
+ ? gene['summary'].slice(0, PROMPT_RECALL_GENE_FIELD_CHARS).replace(/\s+/g, ' ').trim()
287
+ : '';
288
+ return `- ${id}${category ? ` [${category}]` : ''}${summary ? `: ${summary.slice(0, 240)}` : ''}`;
289
+ }
290
+ function renderPromptRecallContext(genes) {
291
+ const header = '[Evolver memory - relevant prior capability]';
292
+ const footer = 'Use only when directly relevant. Adapt and verify before applying; do not mention this memory block unless asked or materially relevant.';
293
+ const lines = [header];
294
+ const rendered = [];
295
+ for (const ranked of genes) {
296
+ const { gene } = ranked;
297
+ const line = renderGeneLine(gene);
298
+ if ([...lines, line, footer].join('\n').length > PROMPT_RECALL_CONTEXT_MAX_CHARS)
299
+ break;
300
+ lines.push(line);
301
+ rendered.push(ranked);
302
+ }
303
+ if (lines.length === 1)
304
+ return { text: '', genes: [] };
305
+ lines.push(footer);
306
+ return { text: lines.join('\n'), genes: rendered };
307
+ }
308
+ function boundedAuditString(value) {
309
+ if (typeof value !== 'string')
310
+ return undefined;
311
+ const trimmed = value.trim();
312
+ return trimmed ? trimmed.slice(0, 256) : undefined;
313
+ }
314
+ function logPromptRecallSelections(genes, mode, sessionId, env, injectedLog) {
315
+ if (genes.length === 0)
316
+ return;
317
+ const callLog = injectedLog ?? new hub.AssetCallLog(events.assetCallLogPath(env));
318
+ const runId = `recall:${boundedAuditString(sessionId) ?? 'unknown'}`;
319
+ for (const ranked of genes) {
320
+ const sourceNodeId = boundedAuditString(ranked.gene['source_node_id'] ?? ranked.gene['author_node_id']);
321
+ const chainId = boundedAuditString(ranked.gene['chain_id']);
322
+ try {
323
+ callLog.append({
324
+ run_id: runId,
325
+ action: mode === 'enforce' ? 'asset_inject' : 'asset_inject_shadow',
326
+ asset_id: ranked.assetKey,
327
+ asset_type: 'Gene',
328
+ ...(sourceNodeId ? { source_node_id: sourceNodeId } : {}),
329
+ ...(chainId ? { chain_id: chainId } : {}),
330
+ score: ranked.semanticScore,
331
+ reason: 'local_gene_pattern_hit',
332
+ extra: {
333
+ via: 'prompt_recall',
334
+ attribution: 'correlational_local',
335
+ origin: 'local',
336
+ literal_hits: ranked.literalHits,
337
+ },
338
+ });
339
+ }
340
+ catch { /* local attribution must never block prompt submission */ }
341
+ }
342
+ }
343
+ async function withSelectionBudget(timeoutMs, fallback, run) {
344
+ const boundedTimeoutMs = Number.isFinite(timeoutMs) ? Math.max(0, timeoutMs) : PROMPT_RECALL_SELECTION_TIMEOUT_MS;
345
+ const budget = {
346
+ deadlineMs: performance.now() + boundedTimeoutMs,
347
+ cancelled: false,
348
+ };
349
+ let timer;
350
+ try {
351
+ return await Promise.race([
352
+ Promise.resolve().then(() => run(budget)),
353
+ new Promise((resolve) => {
354
+ timer = setTimeout(() => {
355
+ budget.cancelled = true;
356
+ resolve(fallback);
357
+ }, boundedTimeoutMs);
358
+ }),
359
+ ]);
360
+ }
361
+ finally {
362
+ if (timer)
363
+ clearTimeout(timer);
364
+ }
365
+ }
366
+ /**
367
+ * Shared Claude Code/Codex UserPromptSubmit entrypoint. It is intentionally local-only and fail-open: no Hub
368
+ * query, no transcript read, no prompt persistence, and exactly one JSON object on stdout for every outcome.
369
+ */
370
+ export async function runPromptRecallHook(argv, deps = {}) {
371
+ const write = deps.stdout ?? ((text) => { process.stdout.write(text); });
372
+ let output = {};
373
+ const env = deps.env ?? process.env;
374
+ const envFile = loadEnvFileFromEnv(env);
375
+ if (env['EVOLVER_ENV_FILE']?.trim() && !envFile.loaded) {
376
+ write('{}\n');
377
+ return 0;
378
+ }
379
+ const mode = promptRecallMode(env);
380
+ // Privacy invariant from V1: default-off does not even read the prompt-bearing stdin payload.
381
+ if (mode === 'off' || !argv.includes('--hook-stdin')) {
382
+ write('{}\n');
383
+ return 0;
384
+ }
385
+ try {
386
+ const raw = await readHookPayload(deps.readHookInput);
387
+ if (!raw?.trim())
388
+ throw new Error('empty hook payload');
389
+ const input = JSON.parse(raw);
390
+ if (typeof input.hook_event_name === 'string' && input.hook_event_name !== 'UserPromptSubmit') {
391
+ throw new Error('unexpected hook event');
392
+ }
393
+ const prompt = input.prompt;
394
+ if (typeof prompt !== 'string' || prompt.trim().length < 8)
395
+ throw new Error('prompt is not recallable');
396
+ const store = deps.store ?? new assetstore.LocalJsonlProvider(events.assetsDir());
397
+ // These cold-loaded JSONL files are parsed synchronously inside the existing store/ledger APIs. Preflight
398
+ // their footprint before entering those APIs so an append-only sidecar cannot defeat the hook deadline.
399
+ if (!localRecallFilesWithinBudget(store))
400
+ throw new Error('local recall files exceed the prompt-hook budget');
401
+ const review = deps.review ?? assetstore.reviewLedgerForStore(store);
402
+ const provenance = deps.provenance ?? assetstore.provenanceStoreForStore(store);
403
+ const timeoutMs = deps.selectionTimeoutMs ?? PROMPT_RECALL_SELECTION_TIMEOUT_MS;
404
+ const ranked = await withSelectionBudget(timeoutMs, [], (budget) => selectPromptGenes(prompt, store, review, provenance, promptRecallMaxGenes(env), budget));
405
+ if (ranked.length > 0) {
406
+ const rendered = renderPromptRecallContext(ranked);
407
+ if (rendered.text) {
408
+ logPromptRecallSelections(rendered.genes, mode, input.session_id, env, deps.callLog);
409
+ }
410
+ if (mode === 'enforce' && rendered.text) {
411
+ output = {
412
+ hookSpecificOutput: {
413
+ hookEventName: 'UserPromptSubmit',
414
+ additionalContext: rendered.text,
415
+ },
416
+ };
417
+ }
418
+ }
419
+ }
420
+ catch {
421
+ output = {};
422
+ }
423
+ write(`${JSON.stringify(output)}\n`);
424
+ return 0;
425
+ }
@@ -0,0 +1,37 @@
1
+ import type { PublishRecallState } from '@evomap/evolver-proxy';
2
+ export interface RecallVerifyRow {
3
+ assetType: string;
4
+ total: number;
5
+ ok: number;
6
+ missing: number;
7
+ mismatch: number;
8
+ error: number;
9
+ skipped: number;
10
+ successRate: number;
11
+ p50LatencyMs: number;
12
+ p95LatencyMs: number;
13
+ p99LatencyMs: number;
14
+ p50AgeMs: number;
15
+ p95AgeMs: number;
16
+ p99AgeMs: number;
17
+ }
18
+ export interface RecallVerifyReport {
19
+ since: string | null;
20
+ retainedOutcomes: number;
21
+ queued: number;
22
+ rows: RecallVerifyRow[];
23
+ totals: RecallVerifyRow;
24
+ gate: 'GREEN' | 'YELLOW' | 'RED';
25
+ retentionNotice: string;
26
+ }
27
+ export interface RecallVerifyReportDeps {
28
+ env?: NodeJS.ProcessEnv;
29
+ storePath?: string;
30
+ readState?: (key: string) => string | undefined;
31
+ now?: () => number;
32
+ log?: (line: string) => void;
33
+ err?: (line: string) => void;
34
+ }
35
+ export declare function aggregateRecallVerifyState(state: PublishRecallState | undefined, sinceMs: number | null): RecallVerifyReport;
36
+ export declare function runRecallVerifyReport(argv: readonly string[], deps?: RecallVerifyReportDeps): Promise<number>;
37
+ export declare const runRecallVerifyReportCommand: (argv: string[]) => Promise<number>;