@evomap/evolver-cli 2.0.0-beta.2 → 2.0.0-beta.22

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 (124) hide show
  1. package/dist/antiGeneBenchmark.js +2 -0
  2. package/dist/antiGeneRollout.js +9 -3
  3. package/dist/assetHealth.d.ts +6 -0
  4. package/dist/assetHealth.js +107 -0
  5. package/dist/assetRepair.d.ts +24 -0
  6. package/dist/assetRepair.js +172 -0
  7. package/dist/assetSidecarRecovery.d.ts +14 -0
  8. package/dist/assetSidecarRecovery.js +171 -0
  9. package/dist/assetTrust.d.ts +24 -0
  10. package/dist/assetTrust.js +231 -0
  11. package/dist/atp.d.ts +10 -5
  12. package/dist/atp.js +119 -26
  13. package/dist/atpAutoBuyer.d.ts +120 -0
  14. package/dist/atpAutoBuyer.js +814 -0
  15. package/dist/atpAutoDeliver.js +2 -2
  16. package/dist/autoDistillAntiGene.js +7 -5
  17. package/dist/autoDistillLlm.d.ts +26 -0
  18. package/dist/autoDistillLlm.js +119 -22
  19. package/dist/autoDistillTranscript.js +3 -2
  20. package/dist/autoexec.d.ts +111 -24
  21. package/dist/autoexec.js +887 -120
  22. package/dist/autoexecConfig.d.ts +10 -0
  23. package/dist/autoexecConfig.js +69 -0
  24. package/dist/cli.js +13 -0
  25. package/dist/cliContracts.d.ts +33 -2
  26. package/dist/cliContracts.js +818 -78
  27. package/dist/commandCatalog.d.ts +72 -0
  28. package/dist/commandCatalog.js +120 -0
  29. package/dist/commands.d.ts +1 -0
  30. package/dist/commands.js +1 -0
  31. package/dist/curriculumCapabilityGaps.d.ts +6 -0
  32. package/dist/curriculumCapabilityGaps.js +24 -0
  33. package/dist/cycleConsumer.d.ts +17 -2
  34. package/dist/cycleConsumer.js +374 -50
  35. package/dist/dashboard.d.ts +13 -1
  36. package/dist/dashboard.js +235 -18
  37. package/dist/dispatch.d.ts +9 -2
  38. package/dist/dispatch.js +29 -6
  39. package/dist/distillAdmission.d.ts +13 -0
  40. package/dist/distillAdmission.js +35 -0
  41. package/dist/distillObserver.js +27 -12
  42. package/dist/distillPrimitives.d.ts +11 -8
  43. package/dist/distillPrimitives.js +116 -22
  44. package/dist/doctor.d.ts +13 -0
  45. package/dist/doctor.js +177 -10
  46. package/dist/identityHome.d.ts +9 -0
  47. package/dist/identityHome.js +47 -0
  48. package/dist/index.d.ts +73 -40
  49. package/dist/index.js +745 -207
  50. package/dist/issueReport.d.ts +7 -0
  51. package/dist/issueReport.js +291 -0
  52. package/dist/learningTrace.d.ts +15 -0
  53. package/dist/learningTrace.js +73 -0
  54. package/dist/lifecycle.d.ts +199 -2
  55. package/dist/lifecycle.js +4999 -152
  56. package/dist/lifecycleBootstrapTransaction.d.ts +235 -0
  57. package/dist/lifecycleBootstrapTransaction.js +2182 -0
  58. package/dist/localMemoryGraph.d.ts +184 -0
  59. package/dist/localMemoryGraph.js +2689 -0
  60. package/dist/login.d.ts +1 -1
  61. package/dist/login.js +3 -3
  62. package/dist/materialPackage.js +3 -6
  63. package/dist/materialSnapshot.d.ts +35 -1
  64. package/dist/materialSnapshot.js +265 -18
  65. package/dist/memoryGraphOps.d.ts +8 -0
  66. package/dist/memoryGraphOps.js +140 -0
  67. package/dist/migrate/assetFormatMap.d.ts +61 -0
  68. package/dist/migrate/assetFormatMap.js +53 -0
  69. package/dist/migrate/envTranslate.d.ts +26 -0
  70. package/dist/migrate/envTranslate.js +147 -0
  71. package/dist/migrate/fieldMap.d.ts +7 -5
  72. package/dist/migrate/fieldMap.js +20 -14
  73. package/dist/migrate/oauthImport.d.ts +66 -0
  74. package/dist/migrate/oauthImport.js +667 -0
  75. package/dist/migrate/v1Import.d.ts +98 -1
  76. package/dist/migrate/v1Import.js +1532 -71
  77. package/dist/modelCompatibility.d.ts +10 -0
  78. package/dist/modelCompatibility.js +296 -0
  79. package/dist/promptRecallHook.d.ts +24 -0
  80. package/dist/promptRecallHook.js +425 -0
  81. package/dist/recallVerifyReport.d.ts +37 -0
  82. package/dist/recallVerifyReport.js +244 -0
  83. package/dist/recipe.d.ts +14 -2
  84. package/dist/recipe.js +543 -65
  85. package/dist/repairedAssetStore.d.ts +2 -0
  86. package/dist/repairedAssetStore.js +12 -0
  87. package/dist/requiredSandboxValidation.d.ts +5 -0
  88. package/dist/requiredSandboxValidation.js +4 -0
  89. package/dist/reuse.d.ts +18 -4
  90. package/dist/reuse.js +375 -107
  91. package/dist/reviewFilter.d.ts +3 -1
  92. package/dist/reviewFilter.js +3 -1
  93. package/dist/runtimeCapabilities.d.ts +18 -0
  94. package/dist/runtimeCapabilities.js +81 -0
  95. package/dist/runtimeSessionSource.d.ts +8 -2
  96. package/dist/runtimeSessionSource.js +63 -11
  97. package/dist/selectionPolicyConfig.d.ts +8 -0
  98. package/dist/selectionPolicyConfig.js +18 -0
  99. package/dist/semanticIdfConfig.d.ts +2 -0
  100. package/dist/semanticIdfConfig.js +4 -0
  101. package/dist/sessionIngest.d.ts +43 -0
  102. package/dist/sessionIngest.js +180 -0
  103. package/dist/setupHooks.d.ts +5 -0
  104. package/dist/setupHooks.js +330 -14
  105. package/dist/skill2gep.d.ts +13 -9
  106. package/dist/skill2gep.js +99 -36
  107. package/dist/skillDistill.d.ts +8 -4
  108. package/dist/skillDistill.js +39 -9
  109. package/dist/solo/mode.js +1 -0
  110. package/dist/sync.d.ts +13 -1
  111. package/dist/sync.js +1947 -265
  112. package/dist/thesis.d.ts +1 -1
  113. package/dist/thesis.js +20 -3
  114. package/dist/trajectoryExport.js +21 -3
  115. package/dist/v1Compat.d.ts +1 -0
  116. package/dist/v1Compat.js +9 -0
  117. package/dist/valueDigest.js +8 -1
  118. package/dist/windowsLegacyTaskCleanup.d.ts +228 -0
  119. package/dist/windowsLegacyTaskCleanup.js +1475 -0
  120. package/dist/workflow.d.ts +39 -0
  121. package/dist/workflow.js +386 -0
  122. package/dist/workflowRuntime.d.ts +66 -0
  123. package/dist/workflowRuntime.js +638 -0
  124. package/package.json +14 -7
@@ -0,0 +1,81 @@
1
+ const supported = (evidence) => ({ status: 'supported', evidence });
2
+ const experimental = (evidence) => ({ status: 'experimental', evidence });
3
+ const unsupported = (evidence) => ({ status: 'unsupported', evidence });
4
+ /** Product-level runtime matrix. A transcript parser never implies execution, verification, or resumability. */
5
+ export const RUNTIME_CAPABILITY_MATRIX = {
6
+ 'claude-code': {
7
+ runtime: 'claude-code',
8
+ ingest: supported('normalized Claude Code JSONL adapter'),
9
+ inject: supported('MCP registration plus SessionStart hook'),
10
+ execute: unsupported('built-in Claude is fail-closed until host filesystem and network containment is verified'),
11
+ verify: unsupported('no safely runnable autonomous Claude verification path'),
12
+ resume: unsupported('native session identity mapping is implemented, but built-in Claude execution is disabled until host containment is verified'),
13
+ },
14
+ codex: {
15
+ runtime: 'codex',
16
+ ingest: supported('normalized Codex rollout adapter'),
17
+ inject: supported('project MCP config plus SessionStart hook'),
18
+ execute: unsupported('built-in Codex is fail-closed because workspace-write does not contain host filesystem reads'),
19
+ verify: unsupported('no safely runnable autonomous Codex verification path without external host containment'),
20
+ resume: unsupported('cycle runner starts a new codex exec session'),
21
+ },
22
+ cursor: {
23
+ runtime: 'cursor',
24
+ ingest: supported('Cursor transcript and state.vscdb adapters'),
25
+ inject: supported('always-on project rules injection'),
26
+ execute: unsupported('headless Cursor workspace trust grants uncontained host filesystem and network access'),
27
+ verify: unsupported('no safely runnable autonomous Cursor execution path'),
28
+ resume: unsupported('native session identity mapping is implemented, but autonomous Cursor execution is disabled until host filesystem and network containment are verified'),
29
+ },
30
+ gemini: {
31
+ runtime: 'gemini',
32
+ ingest: supported('normalized Gemini CLI session adapter'),
33
+ inject: unsupported('no Evolver Gemini injection installer'),
34
+ execute: experimental('Gemini CLI 0.46.0 deterministic real-runtime cycle smoke passed; provider-backed live E2E smoke is not complete'),
35
+ verify: experimental('real CLI edit, independent validation, Git patch proof, and cleanup passed with deterministic responses; provider-backed live E2E verification is not complete'),
36
+ resume: unsupported('Gemini resume accepts latest/index; ingested UUIDs cannot be mapped reliably'),
37
+ },
38
+ antigravity: {
39
+ runtime: 'antigravity',
40
+ ingest: supported('strict Antigravity transcript adapter'),
41
+ inject: supported('user-level MCP tool discovery only; no SessionStart hook'),
42
+ execute: unsupported('agy is not installed or live-verified in the implementation environment'),
43
+ verify: unsupported('no Antigravity runner result is wired to state proof'),
44
+ resume: unsupported('no verified transcript-id to agy resume contract'),
45
+ },
46
+ kimi: {
47
+ runtime: 'kimi',
48
+ ingest: experimental('registered parser for the documented Kimi wire.jsonl shape; no sanitized real-log golden fixture'),
49
+ inject: unsupported('no Evolver Kimi injection installer'),
50
+ execute: unsupported('no verified Kimi runner contract'),
51
+ verify: unsupported('no Kimi execution runner exists'),
52
+ resume: unsupported('no verified Kimi resume contract'),
53
+ },
54
+ kiro: {
55
+ runtime: 'kiro',
56
+ ingest: unsupported('transcript adapter is not registered; no real-log golden fixture'),
57
+ inject: supported('verified Kiro MCP config installer for tool discovery; no lifecycle prompt injection'),
58
+ execute: unsupported('no verified Kiro runner contract'),
59
+ verify: unsupported('no Kiro execution runner exists'),
60
+ resume: unsupported('no verified Kiro resume contract'),
61
+ },
62
+ opencode: {
63
+ runtime: 'opencode',
64
+ ingest: unsupported('transcript adapter is not registered; no real-log golden fixture'),
65
+ inject: supported('verified OpenCode MCP config installer for tool discovery; no lifecycle prompt injection'),
66
+ execute: unsupported('no verified OpenCode runner contract'),
67
+ verify: unsupported('no OpenCode execution runner exists'),
68
+ resume: unsupported('no verified OpenCode resume contract'),
69
+ },
70
+ 'generic-chat': {
71
+ runtime: 'generic-chat',
72
+ ingest: supported('normalized standard OpenAI and Anthropic message JSON/JSONL adapter'),
73
+ inject: unsupported('generic transcript interchange has no Evolver injection installer'),
74
+ execute: unsupported('generic chat transcripts do not identify a runnable provider or CLI contract'),
75
+ verify: unsupported('no provider-backed execution runner exists for generic chat transcripts'),
76
+ resume: unsupported('no provider or session identity contract exists for generic chat transcripts'),
77
+ },
78
+ };
79
+ export function runtimeCapabilities() {
80
+ return Object.values(RUNTIME_CAPABILITY_MATRIX);
81
+ }
@@ -3,6 +3,12 @@ export interface RuntimeSessionSource {
3
3
  agent: string;
4
4
  label: string;
5
5
  sessionId?: string;
6
+ resumeIdentityProvenance?: 'canonical_native_transcript';
7
+ /**
8
+ * Canonical task domain slug when producer resolved exactly one `task_domain:` token.
9
+ * Absent/ambiguous/invalid domains are never invented here — omit the field.
10
+ */
11
+ taskDomain?: string;
6
12
  turns: NormalizedTurn[];
7
13
  }
8
14
  export interface RuntimeSessionParseDiagnostics {
@@ -15,5 +21,5 @@ export interface RuntimeSessionParseResult {
15
21
  diagnostics: RuntimeSessionParseDiagnostics;
16
22
  }
17
23
  export declare function isRuntimeSessionSourcePath(path: string): boolean;
18
- export declare function parseRuntimeSessionSourcesWithDiagnostics(path: string, readSource?: (path: string) => string): RuntimeSessionParseResult;
19
- export declare function parseRuntimeSessionSources(path: string, readSource?: (path: string) => string): RuntimeSessionSource[];
24
+ export declare function parseRuntimeSessionSourcesWithDiagnostics(path: string, readSource?: (path: string) => string, nativeSessionHome?: string): RuntimeSessionParseResult;
25
+ export declare function parseRuntimeSessionSources(path: string, readSource?: (path: string) => string, nativeSessionHome?: string): RuntimeSessionSource[];
@@ -1,7 +1,25 @@
1
- import { readFileSync } from 'node:fs';
2
- import { resolve } from 'node:path';
1
+ import { readFileSync, realpathSync } from 'node:fs';
2
+ import { homedir } from 'node:os';
3
+ import { isAbsolute, join, relative, resolve } from 'node:path';
3
4
  import { adapterForPath, isCursorStateVscdbPath, parseJsonlLinesWithStats, parseCursorStateVscdb, stripUtf8Bom, } from '@evomap/evolver-runtime-adapters';
4
5
  const EMPTY_DIAGNOSTICS = { rowsScanned: 0, rowsRead: 0, invalidJson: 0 };
6
+ function canonicalNativeSessionSource(path, agent, nativeSessionHome) {
7
+ const runtimeRoot = agent === 'claude-code'
8
+ ? join(nativeSessionHome, '.claude', 'projects')
9
+ : agent === 'cursor' ? join(nativeSessionHome, '.cursor', 'projects') : undefined;
10
+ if (!runtimeRoot)
11
+ return path;
12
+ try {
13
+ const canonicalRoot = realpathSync(runtimeRoot);
14
+ const canonicalPath = realpathSync(path);
15
+ const child = relative(canonicalRoot, canonicalPath);
16
+ return child !== '' && !child.startsWith(`..${process.platform === 'win32' ? '\\' : '/'}`)
17
+ && child !== '..' && !isAbsolute(child) ? canonicalPath : undefined;
18
+ }
19
+ catch {
20
+ return undefined;
21
+ }
22
+ }
5
23
  export function isRuntimeSessionSourcePath(path) {
6
24
  return isCursorStateVscdbPath(path) || adapterForPath(path) !== undefined;
7
25
  }
@@ -28,7 +46,7 @@ function diagnosticsForRuntimeSource(raw) {
28
46
  return parseJsonlLinesWithStats(raw).stats;
29
47
  }
30
48
  }
31
- export function parseRuntimeSessionSourcesWithDiagnostics(path, readSource = (p) => readFileSync(p, 'utf8')) {
49
+ export function parseRuntimeSessionSourcesWithDiagnostics(path, readSource = (p) => readFileSync(p, 'utf8'), nativeSessionHome = homedir()) {
32
50
  const absPath = resolve(path);
33
51
  if (isCursorStateVscdbPath(absPath)) {
34
52
  const sources = parseCursorStateVscdb(absPath)
@@ -39,18 +57,52 @@ export function parseRuntimeSessionSourcesWithDiagnostics(path, readSource = (p)
39
57
  const adapter = adapterForPath(absPath);
40
58
  if (!adapter)
41
59
  return { sources: [], diagnostics: { ...EMPTY_DIAGNOSTICS } };
42
- const raw = readSource(absPath);
43
- const sessionId = adapter.sessionIdFromPath?.(absPath)?.trim();
44
- return {
45
- sources: [{
60
+ const canonicalResumeSource = adapter.resumeIdentityFromSource
61
+ ? canonicalNativeSessionSource(absPath, adapter.agent, nativeSessionHome)
62
+ : undefined;
63
+ const raw = readSource(canonicalResumeSource ?? absPath);
64
+ const nativeResumeIdentity = adapter.resumeIdentityFromSource && canonicalResumeSource
65
+ ? adapter.resumeIdentityFromSource(canonicalResumeSource, raw)
66
+ : undefined;
67
+ if (adapter.resumeIdentityFromSource) {
68
+ const sessionId = nativeResumeIdentity?.sessionId.trim();
69
+ return {
70
+ sources: [{
71
+ agent: adapter.agent,
72
+ label: sessionId ? `${adapter.agent}:${sessionId}` : adapter.agent,
73
+ ...(sessionId ? { sessionId } : {}),
74
+ ...(sessionId ? { resumeIdentityProvenance: 'canonical_native_transcript' } : {}),
75
+ turns: adapter.parse(raw),
76
+ }],
77
+ diagnostics: diagnosticsForRuntimeSource(raw),
78
+ };
79
+ }
80
+ const pathSessionId = adapter.sessionIdFromPath?.(absPath)?.trim();
81
+ const parsedSessions = adapter.parseSessions?.(raw)
82
+ ?? (adapter.parseSession ? [adapter.parseSession(raw)] : []);
83
+ const sources = parsedSessions.length > 0
84
+ ? parsedSessions.map((session, index) => {
85
+ const sessionId = pathSessionId ?? session.sessionId?.trim();
86
+ return {
46
87
  agent: adapter.agent,
47
- label: sessionId ? `${adapter.agent}:${sessionId}` : adapter.agent,
88
+ label: sessionId
89
+ ? `${adapter.agent}:${sessionId}`
90
+ : parsedSessions.length > 1 ? `${adapter.agent}:${index + 1}` : adapter.agent,
48
91
  ...(sessionId ? { sessionId } : {}),
92
+ turns: session.turns,
93
+ };
94
+ })
95
+ : [{
96
+ agent: adapter.agent,
97
+ label: pathSessionId ? `${adapter.agent}:${pathSessionId}` : adapter.agent,
98
+ ...(pathSessionId ? { sessionId: pathSessionId } : {}),
49
99
  turns: adapter.parse(raw),
50
- }],
100
+ }];
101
+ return {
102
+ sources,
51
103
  diagnostics: diagnosticsForRuntimeSource(raw),
52
104
  };
53
105
  }
54
- export function parseRuntimeSessionSources(path, readSource = (p) => readFileSync(p, 'utf8')) {
55
- return parseRuntimeSessionSourcesWithDiagnostics(path, readSource).sources;
106
+ export function parseRuntimeSessionSources(path, readSource = (p) => readFileSync(p, 'utf8'), nativeSessionHome = homedir()) {
107
+ return parseRuntimeSessionSourcesWithDiagnostics(path, readSource, nativeSessionHome).sources;
56
108
  }
@@ -0,0 +1,8 @@
1
+ export type ConfiguredSelectionPolicy = 'engine-health' | 'ucb1-shadow' | 'ucb1';
2
+ export type ConfiguredSelectionGuard = 'legacy' | 'shadow' | 'enforce';
3
+ /** Unknown values fail safe to the current production policy. */
4
+ export declare function selectionPolicyFromEnv(env?: NodeJS.ProcessEnv): ConfiguredSelectionPolicy;
5
+ /** Unknown values fail safe to the production relevance guard. */
6
+ export declare function selectionGuardFromEnv(env?: NodeJS.ProcessEnv): ConfiguredSelectionGuard;
7
+ /** Optional score floor. Invalid values are omitted so core keeps its declared default. */
8
+ export declare function selectionFloorFromEnv(env?: NodeJS.ProcessEnv): number | undefined;
@@ -0,0 +1,18 @@
1
+ /** Unknown values fail safe to the current production policy. */
2
+ export function selectionPolicyFromEnv(env = process.env) {
3
+ const value = env['EVOLVER_SELECTION_POLICY']?.trim().toLowerCase();
4
+ return value === 'ucb1-shadow' || value === 'ucb1' ? value : 'engine-health';
5
+ }
6
+ /** Unknown values fail safe to the production relevance guard. */
7
+ export function selectionGuardFromEnv(env = process.env) {
8
+ const value = env['EVOLVER_SELECTION_GUARD']?.trim().toLowerCase();
9
+ return value === 'legacy' || value === 'shadow' ? value : 'enforce';
10
+ }
11
+ /** Optional score floor. Invalid values are omitted so core keeps its declared default. */
12
+ export function selectionFloorFromEnv(env = process.env) {
13
+ const raw = env['EVOLVER_SELECTION_FLOOR']?.trim();
14
+ if (!raw)
15
+ return undefined;
16
+ const value = Number(raw);
17
+ return Number.isFinite(value) && value >= 0 && value <= 1 ? value : undefined;
18
+ }
@@ -0,0 +1,2 @@
1
+ /** Semantic IDF is default-on; exact `0` is the emergency rollback value. */
2
+ export declare function semanticIdfEnabled(env?: NodeJS.ProcessEnv): boolean;
@@ -0,0 +1,4 @@
1
+ /** Semantic IDF is default-on; exact `0` is the emergency rollback value. */
2
+ export function semanticIdfEnabled(env = process.env) {
3
+ return env['EVOLVER_SEMANTIC_IDF'] !== '0';
4
+ }
@@ -0,0 +1,43 @@
1
+ import { events, material as materialNs } from '@evomap/evolver-core';
2
+ import { type RuntimeSessionMaterialSnapshotV1 } from './materialSnapshot.js';
3
+ import { type RuntimeSessionParseDiagnostics, type RuntimeSessionSource } from './runtimeSessionSource.js';
4
+ /**
5
+ * Stamp a resolved canonical task domain onto each source when turn/signal text carries exactly one
6
+ * valid `task_domain:` token. Never invents domains; absent/ambiguous/invalid → leave field unset.
7
+ * Additive only — does not mutate parse diagnostics or turn content.
8
+ */
9
+ export declare function stampResolvedTaskDomain(sources: readonly RuntimeSessionSource[]): RuntimeSessionSource[];
10
+ /** Material consumer group shared by ingestion and the downstream cycle consumer. */
11
+ export declare const INGEST_CONSUMER_GROUP = "cycle";
12
+ /** Injectable substrate dependencies for session and trace ingestion. */
13
+ export interface IngestDeps {
14
+ materialStore?: materialNs.MaterialStore;
15
+ watermarkStore?: materialNs.WatermarkStore;
16
+ ingestor?: events.Ingestor;
17
+ /** User home whose native runtime directories may contribute resumable session identities. */
18
+ nativeSessionHome?: string;
19
+ }
20
+ export interface SessionIngestTickResult {
21
+ recorded: number;
22
+ sourceAgents: string[];
23
+ signalKinds: string[];
24
+ signalStrengths: string[];
25
+ invalidJsonRows?: number;
26
+ /** Cursor databases that could not be opened or parsed; no path or native error text is exposed. */
27
+ parseFailures?: number;
28
+ }
29
+ export declare function resolveIngestDeps(deps: IngestDeps): {
30
+ materialStore: materialNs.MaterialStore;
31
+ watermarkStore: materialNs.WatermarkStore;
32
+ ingestor: events.Ingestor;
33
+ };
34
+ export declare function toMaterialSourceAgent(agent: string): materialNs.BuildMaterialInput['sourceAgent'] | undefined;
35
+ export declare function recordSessionMaterial(sourceAgent: materialNs.BuildMaterialInput['sourceAgent'], absPath: string, signalCount: number, deps: ReturnType<typeof resolveIngestDeps>, recordCount?: number, payload?: RuntimeSessionMaterialSnapshotV1, diagnostics?: RuntimeSessionParseDiagnostics): Promise<{
36
+ recorded: boolean;
37
+ emitted: boolean;
38
+ materialId?: string;
39
+ }>;
40
+ /** Recursively enumerate recognized runtime-session sources, skipping inaccessible directories. */
41
+ export declare function scanSessionDirs(dirs: readonly string[]): string[];
42
+ /** Record all new or changed runtime sessions as material for the auto-distill loop. */
43
+ export declare function runSessionIngestTick(dirs: readonly string[], deps?: IngestDeps): Promise<SessionIngestTickResult>;
@@ -0,0 +1,180 @@
1
+ import { readdirSync } from 'node:fs';
2
+ import { join, resolve } from 'node:path';
3
+ import { events, material as materialNs, signals } from '@evomap/evolver-core';
4
+ import { isCursorStateVscdbPath } from '@evomap/evolver-runtime-adapters';
5
+ import { emitSessionRecall } from './autoRecall.js';
6
+ import { buildRuntimeSessionMaterialSnapshot } from './materialSnapshot.js';
7
+ import { isRuntimeSessionSourcePath, parseRuntimeSessionSourcesWithDiagnostics, } from './runtimeSessionSource.js';
8
+ /** Wire-form `task_domain:` tokens embedded in session text (case-insensitive match; resolver fail-closes). */
9
+ const TASK_DOMAIN_TOKEN_RE = /\btask_domain:[A-Za-z0-9][A-Za-z0-9-]{0,63}\b/gi;
10
+ /**
11
+ * Stamp a resolved canonical task domain onto each source when turn/signal text carries exactly one
12
+ * valid `task_domain:` token. Never invents domains; absent/ambiguous/invalid → leave field unset.
13
+ * Additive only — does not mutate parse diagnostics or turn content.
14
+ */
15
+ export function stampResolvedTaskDomain(sources) {
16
+ return sources.map((source) => {
17
+ const tokens = [];
18
+ for (const turn of source.turns) {
19
+ const text = `${turn.text ?? ''}\n${turn.errorMessage ?? ''}\n${turn.toolResult ?? ''}`;
20
+ for (const match of text.matchAll(TASK_DOMAIN_TOKEN_RE)) {
21
+ tokens.push(match[0].toLowerCase());
22
+ }
23
+ }
24
+ const resolution = signals.resolveTaskDomainSignals(tokens);
25
+ if (resolution.status !== 'resolved')
26
+ return source;
27
+ if (source.taskDomain === resolution.slug)
28
+ return source;
29
+ return { ...source, taskDomain: resolution.slug };
30
+ });
31
+ }
32
+ /** Material consumer group shared by ingestion and the downstream cycle consumer. */
33
+ export const INGEST_CONSUMER_GROUP = 'cycle';
34
+ export function resolveIngestDeps(deps) {
35
+ return {
36
+ materialStore: deps.materialStore ?? new materialNs.MaterialStore({ path: events.materialStorePath() }),
37
+ watermarkStore: deps.watermarkStore ?? new materialNs.WatermarkStore(events.materialWatermarkPath()),
38
+ ingestor: deps.ingestor ?? new events.Ingestor({ path: events.rootEventsPath() }),
39
+ };
40
+ }
41
+ const MATERIAL_SOURCE_AGENTS = new Set([
42
+ 'claude-code',
43
+ 'codex',
44
+ 'cursor',
45
+ 'gemini',
46
+ 'antigravity',
47
+ 'kimi',
48
+ 'kiro',
49
+ 'opencode',
50
+ 'generic-chat',
51
+ ]);
52
+ export function toMaterialSourceAgent(agent) {
53
+ return MATERIAL_SOURCE_AGENTS.has(agent) ? agent : undefined;
54
+ }
55
+ function materialExistsFor(store, sourcePath, watermark) {
56
+ if (watermark.contentHash === undefined)
57
+ return false;
58
+ for (const material of store.iterate()) {
59
+ if (material.sourcePath === sourcePath
60
+ && material.watermark.size === watermark.size
61
+ && material.watermark.contentHash === watermark.contentHash)
62
+ return true;
63
+ }
64
+ return false;
65
+ }
66
+ export async function recordSessionMaterial(sourceAgent, absPath, signalCount, deps, recordCount = 1, payload, diagnostics) {
67
+ const previous = deps.watermarkStore.get(absPath);
68
+ const scan = materialNs.scanFile(absPath, previous);
69
+ if (previous && !scan.changed)
70
+ return { recorded: false, emitted: false };
71
+ const material = materialNs.buildMaterial({
72
+ sourceAgent,
73
+ sourceKind: 'runtime_session',
74
+ sourcePath: absPath,
75
+ kind: 'session_log',
76
+ watermark: scan.watermark,
77
+ consumerGroup: INGEST_CONSUMER_GROUP,
78
+ ...(payload ? { payload } : {}),
79
+ });
80
+ const isNew = !materialExistsFor(deps.materialStore, absPath, scan.watermark);
81
+ if (isNew)
82
+ await deps.materialStore.put(material);
83
+ const parseDiagnostics = diagnostics && diagnostics.invalidJson > 0
84
+ ? { rowsScanned: diagnostics.rowsScanned, rowsRead: diagnostics.rowsRead, invalidJson: diagnostics.invalidJson }
85
+ : undefined;
86
+ await deps.ingestor.ingest({
87
+ type: 'material.batch_ready',
88
+ payload: { source: absPath, recordCount, signalCount, ...(parseDiagnostics ? { parseDiagnostics } : {}) },
89
+ human: {
90
+ title: `material 已落地: ${sourceAgent} session`,
91
+ ...(parseDiagnostics ? { detail: `skipped ${parseDiagnostics.invalidJson} invalid JSONL row(s)` } : {}),
92
+ severity: 'info',
93
+ },
94
+ actor: { kind: 'machine' },
95
+ });
96
+ deps.watermarkStore.set(absPath, scan.watermark);
97
+ return { recorded: isNew, emitted: true, materialId: material.materialId };
98
+ }
99
+ /** Recursively enumerate recognized runtime-session sources, skipping inaccessible directories. */
100
+ export function scanSessionDirs(dirs) {
101
+ const out = [];
102
+ for (const dir of dirs) {
103
+ let entries;
104
+ try {
105
+ entries = readdirSync(resolve(dir), { recursive: true });
106
+ }
107
+ catch {
108
+ continue;
109
+ }
110
+ for (const entry of entries) {
111
+ const file = join(resolve(dir), entry);
112
+ if (isRuntimeSessionSourcePath(file))
113
+ out.push(file);
114
+ }
115
+ }
116
+ return out;
117
+ }
118
+ function sortedStrings(values) {
119
+ return [...new Set([...values].map(String).filter(Boolean))].sort();
120
+ }
121
+ /** Record all new or changed runtime sessions as material for the auto-distill loop. */
122
+ export async function runSessionIngestTick(dirs, deps = {}) {
123
+ const resolvedDeps = resolveIngestDeps(deps);
124
+ let recorded = 0;
125
+ const sourceAgents = new Set();
126
+ const signalKinds = new Set();
127
+ const signalStrengths = new Set();
128
+ let invalidJsonRows = 0;
129
+ let parseFailures = 0;
130
+ const autoRecallOn = process.env['EVOLVER_AUTO_RECALL'] === '1';
131
+ for (const file of scanSessionDirs(dirs)) {
132
+ let parsed;
133
+ try {
134
+ parsed = parseRuntimeSessionSourcesWithDiagnostics(file, undefined, deps.nativeSessionHome);
135
+ }
136
+ catch {
137
+ if (isCursorStateVscdbPath(file))
138
+ parseFailures += 1;
139
+ continue;
140
+ }
141
+ try {
142
+ const parsedSources = stampResolvedTaskDomain(parsed.sources);
143
+ const agent = parsedSources[0] ? toMaterialSourceAgent(parsedSources[0].agent) : undefined;
144
+ if (parsedSources.length === 0 || !agent)
145
+ continue;
146
+ const signalsBySource = parsedSources.map((source) => signals.extractSignals(source.turns));
147
+ const snapshot = buildRuntimeSessionMaterialSnapshot(parsedSources);
148
+ const result = await recordSessionMaterial(agent, file, signalsBySource.reduce((sum, sourceSignals) => sum + sourceSignals.length, 0), resolvedDeps, parsedSources.length, snapshot, parsed.diagnostics);
149
+ if (result.emitted)
150
+ invalidJsonRows += parsed.diagnostics.invalidJson;
151
+ if (result.recorded) {
152
+ recorded += 1;
153
+ sourceAgents.add(agent);
154
+ for (const sourceSignals of signalsBySource) {
155
+ for (const signal of sourceSignals) {
156
+ signalKinds.add(signal.kind);
157
+ signalStrengths.add(signal.strength);
158
+ }
159
+ }
160
+ }
161
+ if (autoRecallOn && parsedSources.length === 1 && !parsedSources[0].sessionId) {
162
+ const turns = parsedSources[0].turns
163
+ .filter((turn) => !turn.isMeta)
164
+ .map((turn) => ({ role: turn.role, text: turn.text }));
165
+ await emitSessionRecall(file, turns, { ingestor: resolvedDeps.ingestor });
166
+ }
167
+ }
168
+ catch {
169
+ // Individual session files are best-effort and must not stop the daemon scan.
170
+ }
171
+ }
172
+ return {
173
+ recorded,
174
+ sourceAgents: sortedStrings(sourceAgents),
175
+ signalKinds: sortedStrings(signalKinds),
176
+ signalStrengths: sortedStrings(signalStrengths),
177
+ ...(invalidJsonRows > 0 ? { invalidJsonRows } : {}),
178
+ ...(parseFailures > 0 ? { parseFailures } : {}),
179
+ };
180
+ }
@@ -1,7 +1,12 @@
1
+ import { type InstallScope } from '@evomap/evolver-mcp';
1
2
  import { assetstore } from '@evomap/evolver-core';
2
3
  import { maybeEmitNonGitWorkspaceNotice } from './nonGitWorkspaceNotice.js';
3
4
  interface SetupHooksDeps {
4
5
  emitNonGitWorkspaceNotice?: typeof maybeEmitNonGitWorkspaceNotice;
6
+ runtimeAvailable?: (runtime: 'opencode' | 'kiro', configRoot: string, scope: InstallScope) => boolean;
5
7
  }
8
+ export declare function commandNamesForPath(command: string, platform: NodeJS.Platform, pathExt: string | undefined): string[];
9
+ export declare function safeSetupOperationError(error: unknown): string;
10
+ export declare function safeSetupResultError(error: unknown): string;
6
11
  export declare function runSetupHooks(argv: readonly string[], store?: assetstore.AssetStoreProvider, review?: assetstore.ReviewLedger, deps?: SetupHooksDeps): Promise<number>;
7
12
  export {};