@evomap/evolver-cli 2.0.0-beta.9 → 2.0.1

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 (87) hide show
  1. package/dist/antiGeneBenchmark.js +2 -0
  2. package/dist/antiGeneRollout.js +9 -3
  3. package/dist/assetHealth.js +2 -0
  4. package/dist/assetTrust.js +14 -1
  5. package/dist/atp.d.ts +10 -5
  6. package/dist/atp.js +119 -26
  7. package/dist/atpAutoBuyer.d.ts +120 -0
  8. package/dist/atpAutoBuyer.js +814 -0
  9. package/dist/atpAutoDeliver.js +2 -2
  10. package/dist/autoDistillLlm.js +2 -1
  11. package/dist/autoDistillTranscript.js +3 -2
  12. package/dist/autoexec.d.ts +101 -13
  13. package/dist/autoexec.js +794 -91
  14. package/dist/cli.js +13 -0
  15. package/dist/cliContracts.d.ts +23 -2
  16. package/dist/cliContracts.js +504 -54
  17. package/dist/commands.d.ts +1 -0
  18. package/dist/commands.js +1 -0
  19. package/dist/curriculumCapabilityGaps.d.ts +6 -0
  20. package/dist/curriculumCapabilityGaps.js +24 -0
  21. package/dist/cycleConsumer.d.ts +13 -0
  22. package/dist/cycleConsumer.js +186 -20
  23. package/dist/dashboard.js +47 -9
  24. package/dist/dispatch.js +8 -2
  25. package/dist/distillPrimitives.d.ts +3 -2
  26. package/dist/distillPrimitives.js +80 -12
  27. package/dist/doctor.js +120 -11
  28. package/dist/identityHome.d.ts +9 -0
  29. package/dist/identityHome.js +47 -0
  30. package/dist/index.d.ts +70 -40
  31. package/dist/index.js +581 -193
  32. package/dist/learningTrace.d.ts +15 -0
  33. package/dist/learningTrace.js +73 -0
  34. package/dist/lifecycle.d.ts +67 -1
  35. package/dist/lifecycle.js +738 -44
  36. package/dist/localMemoryGraph.d.ts +90 -3
  37. package/dist/localMemoryGraph.js +2031 -231
  38. package/dist/login.d.ts +1 -1
  39. package/dist/login.js +3 -3
  40. package/dist/materialSnapshot.d.ts +9 -1
  41. package/dist/materialSnapshot.js +23 -6
  42. package/dist/memoryGraphOps.d.ts +8 -0
  43. package/dist/memoryGraphOps.js +140 -0
  44. package/dist/migrate/assetFormatMap.d.ts +61 -0
  45. package/dist/migrate/assetFormatMap.js +53 -0
  46. package/dist/migrate/envTranslate.d.ts +26 -0
  47. package/dist/migrate/envTranslate.js +147 -0
  48. package/dist/migrate/fieldMap.d.ts +4 -2
  49. package/dist/migrate/fieldMap.js +9 -5
  50. package/dist/migrate/oauthImport.d.ts +66 -0
  51. package/dist/migrate/oauthImport.js +667 -0
  52. package/dist/migrate/v1Import.d.ts +92 -1
  53. package/dist/migrate/v1Import.js +1481 -141
  54. package/dist/promptRecallHook.d.ts +24 -0
  55. package/dist/promptRecallHook.js +425 -0
  56. package/dist/recallVerifyReport.d.ts +37 -0
  57. package/dist/recallVerifyReport.js +244 -0
  58. package/dist/recipe.d.ts +7 -1
  59. package/dist/recipe.js +426 -56
  60. package/dist/requiredSandboxValidation.d.ts +5 -0
  61. package/dist/requiredSandboxValidation.js +4 -0
  62. package/dist/reuse.d.ts +9 -0
  63. package/dist/reuse.js +151 -56
  64. package/dist/runtimeCapabilities.js +15 -15
  65. package/dist/runtimeSessionSource.d.ts +3 -2
  66. package/dist/runtimeSessionSource.js +63 -11
  67. package/dist/selectionPolicyConfig.d.ts +8 -0
  68. package/dist/selectionPolicyConfig.js +18 -0
  69. package/dist/semanticIdfConfig.d.ts +2 -0
  70. package/dist/semanticIdfConfig.js +4 -0
  71. package/dist/sessionIngest.d.ts +37 -0
  72. package/dist/sessionIngest.js +156 -0
  73. package/dist/setupHooks.js +95 -1
  74. package/dist/skill2gep.d.ts +13 -9
  75. package/dist/skill2gep.js +42 -30
  76. package/dist/skillDistill.d.ts +8 -4
  77. package/dist/skillDistill.js +38 -9
  78. package/dist/solo/mode.js +1 -0
  79. package/dist/sync.d.ts +12 -0
  80. package/dist/sync.js +1246 -151
  81. package/dist/thesis.d.ts +1 -1
  82. package/dist/thesis.js +20 -3
  83. package/dist/trajectoryExport.js +21 -3
  84. package/dist/v1Compat.d.ts +1 -0
  85. package/dist/v1Compat.js +9 -0
  86. package/dist/workflowRuntime.js +24 -18
  87. package/package.json +11 -8
package/dist/login.d.ts CHANGED
@@ -18,7 +18,7 @@ export declare function publicOAuthTokenPath(opts?: PublicAuthPathOptions): stri
18
18
  *
19
19
  * Hub URL follows A2A_HUB_URL -> EVOMAP_HUB_URL -> EVOLVER_DEFAULT_HUB_URL -> https://evomap.ai. Credential
20
20
  * home follows the same public Hub precedence as publish/ATP:
21
- * EVOMAP_DIR → EVOLVER_HOME → EVOMAP_HOME → ~/.evomap. The token replaces
21
+ * EVOMAP_HOME → EVOMAP_DIR → EVOLVER_HOME → ~/.evomap. The token replaces
22
22
  * node_secret for publish + /a2a calls (it carries the `a2a` scope).
23
23
  */
24
24
  export declare function runLogin(argv: readonly string[]): Promise<number>;
package/dist/login.js CHANGED
@@ -1,12 +1,12 @@
1
1
  import { existsSync, unlinkSync } from 'node:fs';
2
- import { homedir } from 'node:os';
3
2
  import { join } from 'node:path';
4
3
  import { PublicOAuthProvider, createOAuthHttpTransport, resolveHubUrl } from '@evomap/evolver-adapter-public';
5
4
  import { loadEnvFileFromEnv } from '@evomap/evolver-mcp';
5
+ import { resolveIdentityHome } from './identityHome.js';
6
6
  const LOGIN_USAGE = 'usage: evolver login\n';
7
7
  function publicAuthDir(opts = {}) {
8
8
  const env = opts.env ?? process.env;
9
- return env.EVOMAP_DIR ?? env.EVOLVER_HOME ?? env.EVOMAP_HOME ?? join(opts.homeDir ?? homedir(), '.evomap');
9
+ return resolveIdentityHome(env, opts.homeDir);
10
10
  }
11
11
  export function publicOAuthTokenPath(opts = {}) {
12
12
  return join(publicAuthDir(opts), 'token.json');
@@ -18,7 +18,7 @@ export function publicOAuthTokenPath(opts = {}) {
18
18
  *
19
19
  * Hub URL follows A2A_HUB_URL -> EVOMAP_HUB_URL -> EVOLVER_DEFAULT_HUB_URL -> https://evomap.ai. Credential
20
20
  * home follows the same public Hub precedence as publish/ATP:
21
- * EVOMAP_DIR → EVOLVER_HOME → EVOMAP_HOME → ~/.evomap. The token replaces
21
+ * EVOMAP_HOME → EVOMAP_DIR → EVOLVER_HOME → ~/.evomap. The token replaces
22
22
  * node_secret for publish + /a2a calls (it carries the `a2a` scope).
23
23
  */
24
24
  export async function runLogin(argv) {
@@ -13,6 +13,7 @@ interface SnapshotSource {
13
13
  agent: string;
14
14
  label: string;
15
15
  sessionId?: string;
16
+ resumeIdentityProvenance?: 'canonical_native_transcript';
16
17
  evidenceSummary: RuntimeSessionEvidenceSummary;
17
18
  turns: SnapshotTurn[];
18
19
  }
@@ -31,6 +32,7 @@ export interface RuntimeSessionEvidenceSummarySource {
31
32
  agent: string;
32
33
  label: string;
33
34
  sessionId?: string;
35
+ resumeIdentityProvenance?: 'canonical_native_transcript';
34
36
  evidenceSummary: RuntimeSessionEvidenceSummary;
35
37
  }
36
38
  export interface RuntimeSessionEvidenceAggregate {
@@ -50,5 +52,11 @@ export declare function runtimeSessionSourcesFromMaterialPayload(payload: unknow
50
52
  export declare function runtimeSessionEvidenceSummariesFromMaterialPayload(payload: unknown): RuntimeSessionEvidenceSummaryCollection | null;
51
53
  export declare function materialHasRuntimeSessionSnapshot(material: schema.Material): boolean;
52
54
  export declare function materialSourceAvailable(material: schema.Material): boolean;
53
- export declare function runtimeSessionSourcesForMaterial(material: schema.Material, readSource?: (path: string) => string): RuntimeSessionSource[];
55
+ export interface RuntimeSessionMaterialSources {
56
+ sources: RuntimeSessionSource[];
57
+ liveSources?: RuntimeSessionSource[];
58
+ sourceError?: unknown;
59
+ }
60
+ export declare function runtimeSessionSourcesForMaterialDetails(material: schema.Material, readSource?: (path: string) => string, nativeSessionHome?: string): RuntimeSessionMaterialSources;
61
+ export declare function runtimeSessionSourcesForMaterial(material: schema.Material, readSource?: (path: string) => string, nativeSessionHome?: string): RuntimeSessionSource[];
54
62
  export {};
@@ -208,6 +208,7 @@ export function buildRuntimeSessionMaterialSnapshot(sources, maxChars = DEFAULT_
208
208
  agent: snapshotIdentity(source.agent, SNAPSHOT_AGENT_MAX_CHARS) || 'unknown',
209
209
  label: snapshotIdentity(source.label, SNAPSHOT_IDENTITY_MAX_CHARS) || 'unknown',
210
210
  ...(safeSessionId ? { sessionId: safeSessionId } : {}),
211
+ ...(source.resumeIdentityProvenance ? { resumeIdentityProvenance: source.resumeIdentityProvenance } : {}),
211
212
  evidenceSummary,
212
213
  turns,
213
214
  });
@@ -270,10 +271,14 @@ function sourceFromSnapshot(value) {
270
271
  if (turns.length === 0)
271
272
  return null;
272
273
  const sessionId = typeof value['sessionId'] === 'string' && value['sessionId'].trim() ? value['sessionId'] : undefined;
274
+ const resumeIdentityProvenance = value['resumeIdentityProvenance'] === 'canonical_native_transcript'
275
+ ? value['resumeIdentityProvenance']
276
+ : undefined;
273
277
  return {
274
278
  agent,
275
279
  label,
276
280
  ...(sessionId ? { sessionId } : {}),
281
+ ...(resumeIdentityProvenance ? { resumeIdentityProvenance } : {}),
277
282
  turns,
278
283
  };
279
284
  }
@@ -328,10 +333,14 @@ export function runtimeSessionEvidenceSummariesFromMaterialPayload(payload) {
328
333
  const sessionId = typeof source['sessionId'] === 'string' && source['sessionId'].trim()
329
334
  ? source['sessionId']
330
335
  : undefined;
336
+ const resumeIdentityProvenance = source['resumeIdentityProvenance'] === 'canonical_native_transcript'
337
+ ? 'canonical_native_transcript'
338
+ : undefined;
331
339
  return [{
332
340
  agent: source['agent'],
333
341
  label: source['label'],
334
342
  ...(sessionId ? { sessionId } : {}),
343
+ ...(resumeIdentityProvenance ? { resumeIdentityProvenance } : {}),
335
344
  evidenceSummary: summary,
336
345
  }];
337
346
  });
@@ -350,21 +359,29 @@ export function materialHasRuntimeSessionSnapshot(material) {
350
359
  export function materialSourceAvailable(material) {
351
360
  return existsSync(material.sourcePath);
352
361
  }
353
- export function runtimeSessionSourcesForMaterial(material, readSource) {
362
+ export function runtimeSessionSourcesForMaterialDetails(material, readSource, nativeSessionHome) {
354
363
  let sourceError;
355
364
  try {
356
- const sources = parseRuntimeSessionSources(material.sourcePath, readSource);
357
- const sourcesWithTurns = sources.filter((source) => source.turns.length > 0);
365
+ const liveSources = parseRuntimeSessionSources(material.sourcePath, readSource, nativeSessionHome);
366
+ const sourcesWithTurns = liveSources.filter((source) => source.turns.length > 0);
358
367
  if (sourcesWithTurns.length > 0)
359
- return sourcesWithTurns;
368
+ return { sources: sourcesWithTurns, liveSources };
369
+ const snapshotSources = runtimeSessionSourcesFromMaterialPayload(material.payload);
370
+ return {
371
+ sources: snapshotSources,
372
+ liveSources,
373
+ };
360
374
  }
361
375
  catch (error) {
362
376
  sourceError = error;
363
377
  }
364
378
  const snapshotSources = runtimeSessionSourcesFromMaterialPayload(material.payload);
365
379
  if (snapshotSources.length > 0)
366
- return snapshotSources;
380
+ return { sources: snapshotSources, sourceError };
367
381
  if (sourceError)
368
382
  throw sourceError;
369
- return [];
383
+ return { sources: [] };
384
+ }
385
+ export function runtimeSessionSourcesForMaterial(material, readSource, nativeSessionHome) {
386
+ return runtimeSessionSourcesForMaterialDetails(material, readSource, nativeSessionHome).sources;
370
387
  }
@@ -0,0 +1,8 @@
1
+ import { LocalMemoryGraph } from './localMemoryGraph.js';
2
+ export interface MemoryGraphOpsDeps {
3
+ env?: Record<string, string | undefined>;
4
+ stdout?: (text: string) => void;
5
+ stderr?: (text: string) => void;
6
+ createGraph?: (dir: string) => LocalMemoryGraph;
7
+ }
8
+ export declare function runMemoryGraphCommand(argv: readonly string[], deps?: MemoryGraphOpsDeps): Promise<number>;
@@ -0,0 +1,140 @@
1
+ /**
2
+ * Operator maintenance CLI for local MemoryGraph (Refs #674).
3
+ */
4
+ import { events } from '@evomap/evolver-core';
5
+ import { loadEnvFileFromEnv } from '@evomap/evolver-mcp';
6
+ import { join } from 'node:path';
7
+ import { LocalMemoryGraph, formatMemoryGraphOperatorStatus, loadMemoryGraphOperatorStatus, resolveLocalMemoryUserIdentity, } from './localMemoryGraph.js';
8
+ const USAGE = [
9
+ 'Usage:',
10
+ ' evolver memory-graph status [--json]',
11
+ ' evolver memory-graph maintain [--json] # recovery or threshold rotation + compaction',
12
+ ' evolver memory-graph prune [--json] # enforce rotated-archive retention',
13
+ ' evolver memory-graph recover [--json] # rebuild compact from retained current-epoch state',
14
+ ' evolver memory-graph reset --yes [--json] # copy a backup, then advance the local epoch',
15
+ '',
16
+ 'Graph dir: $EVOLVER_HOME/evolution, then $EVOMAP_HOME/evolution, then ~/.evomap/evolution.',
17
+ 'Destructive reset requires --yes. Predictive cross-epoch weighting remains deferred (#670).',
18
+ '',
19
+ ].join('\n');
20
+ function writeJson(write, value) {
21
+ write(`${JSON.stringify(value)}\n`);
22
+ }
23
+ function graphFor(env, deps) {
24
+ const home = events.evomapHome(env);
25
+ if (!home.trim())
26
+ throw new Error('memory_graph_home_rejected');
27
+ const dir = join(home, 'evolution');
28
+ if (deps.createGraph)
29
+ return deps.createGraph(dir);
30
+ return new LocalMemoryGraph({ dir, ...resolveLocalMemoryUserIdentity(dir) });
31
+ }
32
+ function renderMaintain(report, stdout) {
33
+ stdout([
34
+ `rotated=${report.rotated ? 1 : 0}`,
35
+ `compacted=${report.compactedRecords}`,
36
+ `corrupt=${report.corruptLines}`,
37
+ `oversized_lines=${report.oversizedLines}`,
38
+ `archives=${report.archives}`,
39
+ `recovery=${report.recovery}`,
40
+ ].join(' ') + '\n');
41
+ }
42
+ function renderReset(report, stdout) {
43
+ renderMaintain(report, stdout);
44
+ stdout(`backup_id=${report.backupId ?? 'none'} backup_files=${report.backupFiles} epoch_id=${report.epochId ?? 'unchanged'}\n`);
45
+ }
46
+ function writeFailure(command, reason, json, stdout, stderr, usage = false) {
47
+ if (json)
48
+ writeJson(stdout, { ok: false, command, reason });
49
+ else
50
+ stderr(`[memory-graph] ${reason}\n${usage ? USAGE : ''}`);
51
+ return reason === 'unknown_argument' || reason === 'confirmation_required' ? 2 : 1;
52
+ }
53
+ function writeMaintenance(command, report, json, stdout) {
54
+ const ok = report.recovery !== 'degraded';
55
+ if (json)
56
+ writeJson(stdout, { ok, command, report });
57
+ else
58
+ renderMaintain(report, stdout);
59
+ return ok ? 0 : 1;
60
+ }
61
+ function operationFailureReason(error) {
62
+ const message = error instanceof Error ? error.message : '';
63
+ return new Set([
64
+ 'memory_graph_busy',
65
+ 'memory_graph_dir_rejected',
66
+ 'memory_graph_epoch_rejected',
67
+ 'memory_graph_home_rejected',
68
+ 'memory_graph_append_rollback_failed',
69
+ 'memory_graph_path_rejected',
70
+ 'memory_graph_rotation_backup_failed',
71
+ 'memory_graph_rotation_journal_rejected',
72
+ 'memory_graph_rotation_recovery_failed',
73
+ 'memory_graph_reset_backup_failed',
74
+ 'memory_graph_reset_failed',
75
+ 'memory_graph_write_failed',
76
+ ]).has(message) ? message : 'memory_graph_operation_failed';
77
+ }
78
+ export async function runMemoryGraphCommand(argv, deps = {}) {
79
+ const stdout = deps.stdout ?? ((text) => { process.stdout.write(text); });
80
+ const stderr = deps.stderr ?? ((text) => { process.stderr.write(text); });
81
+ if (argv.length === 0 || argv.includes('--help') || argv.includes('-h')) {
82
+ stdout(USAGE);
83
+ return argv.length === 0 ? 1 : 0;
84
+ }
85
+ const sub = argv[0] ?? '';
86
+ const rest = argv.slice(1);
87
+ const json = rest.includes('--json') || argv.includes('--json');
88
+ const known = new Set(['status', 'maintain', 'prune', 'recover', 'reset']);
89
+ if (!known.has(sub)) {
90
+ if (json)
91
+ writeJson(stdout, { ok: false, command: sub, reason: 'unknown_subcommand' });
92
+ else
93
+ stderr(`unknown memory-graph subcommand: ${sub}\n${USAGE}`);
94
+ return 1;
95
+ }
96
+ const allowed = new Set(sub === 'reset' ? ['--json', '--yes'] : ['--json']);
97
+ if (rest.some((arg) => !allowed.has(arg))) {
98
+ return writeFailure(sub, 'unknown_argument', json, stdout, stderr, true);
99
+ }
100
+ if (sub === 'reset' && !rest.includes('--yes')) {
101
+ return writeFailure(sub, 'confirmation_required', json, stdout, stderr, true);
102
+ }
103
+ const env = { ...(deps.env ?? process.env) };
104
+ const envFile = loadEnvFileFromEnv(env);
105
+ if (envFile.error)
106
+ return writeFailure(sub, 'env_file_unavailable', json, stdout, stderr);
107
+ if (!events.evomapHome(env).trim()) {
108
+ return writeFailure(sub, 'memory_graph_home_rejected', json, stdout, stderr);
109
+ }
110
+ if (sub === 'status') {
111
+ const status = loadMemoryGraphOperatorStatus(env);
112
+ const ok = status.recovery !== 'degraded' && status.busy !== true;
113
+ if (json)
114
+ writeJson(stdout, { ok, command: 'status', status });
115
+ else
116
+ stdout(`${formatMemoryGraphOperatorStatus(status)}\n`);
117
+ return ok ? 0 : 1;
118
+ }
119
+ try {
120
+ const graph = graphFor(env, deps);
121
+ if (sub === 'maintain')
122
+ return writeMaintenance(sub, graph.maintain(), json, stdout);
123
+ if (sub === 'prune')
124
+ return writeMaintenance(sub, graph.prune(), json, stdout);
125
+ if (sub === 'recover')
126
+ return writeMaintenance(sub, graph.recoverFromArchives(), json, stdout);
127
+ const report = graph.resetGraph();
128
+ if (report.lockReleaseWarning) {
129
+ stderr(`[memory-graph] reset completed; lock release incomplete: ${report.lockReleaseWarning}\n`);
130
+ }
131
+ if (json)
132
+ writeJson(stdout, { ok: true, command: 'reset', report });
133
+ else
134
+ renderReset(report, stdout);
135
+ return 0;
136
+ }
137
+ catch (error) {
138
+ return writeFailure(sub, operationFailureReason(error), json, stdout, stderr);
139
+ }
140
+ }
@@ -0,0 +1,61 @@
1
+ /** V1→V2 asset path / schema mapping — Refs #684 (R4 Asset-format, 5 sub-items). */
2
+ export declare const CURRENT_WIRE_SCHEMA_VERSION: "1.12.1";
3
+ export declare const V1_EVENT_SCHEMA_VERSION_EXAMPLE: "1.6.0";
4
+ /** Machine-readable mapping for the five issue rows. */
5
+ export declare const ASSET_FORMAT_MAP: readonly [{
6
+ readonly id: 1;
7
+ readonly severity: "major";
8
+ readonly v1: "events.jsonl in the selected current store, or repository legacy assets/gep (EvolutionEvent plus ValidationReport rows; stored schema often 1.6.0)";
9
+ readonly v2: "content-addressed EvolutionEvent JSONL; existing schema_version is preserved";
10
+ readonly migrate: "import-v1 injects 1.12.1 only when schema_version is missing; frozen hash mismatches remain untrusted; ValidationReport rows are validated, counted, and preserved in the V1 source";
11
+ }, {
12
+ readonly id: 2;
13
+ readonly severity: "cosmetic";
14
+ readonly v1: "capsules.json(.l) in the selected current store, then repository legacy fallback";
15
+ readonly v2: "LocalJsonlProvider Capsule stream + migration/v1_extensions.jsonl for non-schema fields";
16
+ readonly migrate: "import-v1 combines the capsules envelope and JSONL overlay by id; JSONL wins";
17
+ }, {
18
+ readonly id: 3;
19
+ readonly severity: "cosmetic";
20
+ readonly v1: "candidates.jsonl in the selected current store, then repository legacy fallback";
21
+ readonly v2: "material/candidates (selection input — not wire assets)";
22
+ readonly migrate: "import-v1 skips candidates (report.candidatesSkipped=true); operators keep pool outside wire store";
23
+ }, {
24
+ readonly id: 4;
25
+ readonly severity: "cosmetic";
26
+ readonly v1: "failed_capsules.json";
27
+ readonly v2: "no automatic wire mapping";
28
+ readonly migrate: "not imported; preserve the V1 source for explicit operator recovery";
29
+ }, {
30
+ readonly id: 5;
31
+ readonly severity: "cosmetic";
32
+ readonly v1: "genes.json(.l) in the selected current store, then repository legacy fallback";
33
+ readonly v2: "LocalJsonlProvider Gene JSONL (content-addressed)";
34
+ readonly migrate: "import-v1 combines the genes envelope and JSONL overlay by id; JSONL wins";
35
+ }];
36
+ /** V1 path components used to select one current workspace plus the repository legacy fallback. */
37
+ export declare const V1_GEP_SOURCE_LAYOUT: {
38
+ readonly workspaceCurrent: readonly ["workspace", ".evolver", "gep"];
39
+ readonly rootCurrent: readonly [".evolver", "gep"];
40
+ readonly legacy: readonly ["assets", "gep"];
41
+ };
42
+ export declare const V1_GEP_WIRE_SOURCES: {
43
+ readonly Gene: {
44
+ readonly envelope: {
45
+ readonly basename: "genes.json";
46
+ readonly key: "genes";
47
+ };
48
+ readonly jsonl: "genes.jsonl";
49
+ };
50
+ readonly Capsule: {
51
+ readonly envelope: {
52
+ readonly basename: "capsules.json";
53
+ readonly key: "capsules";
54
+ };
55
+ readonly jsonl: "capsules.jsonl";
56
+ };
57
+ readonly EvolutionEvent: {
58
+ readonly jsonl: "events.jsonl";
59
+ };
60
+ };
61
+ export type AssetFormatMapEntry = (typeof ASSET_FORMAT_MAP)[number];
@@ -0,0 +1,53 @@
1
+ import { wire } from '@evomap/evolver-core';
2
+ /** V1→V2 asset path / schema mapping — Refs #684 (R4 Asset-format, 5 sub-items). */
3
+ export const CURRENT_WIRE_SCHEMA_VERSION = wire.SCHEMA_VERSION;
4
+ export const V1_EVENT_SCHEMA_VERSION_EXAMPLE = '1.6.0';
5
+ /** Machine-readable mapping for the five issue rows. */
6
+ export const ASSET_FORMAT_MAP = [
7
+ {
8
+ id: 1,
9
+ severity: 'major',
10
+ v1: 'events.jsonl in the selected current store, or repository legacy assets/gep (EvolutionEvent plus ValidationReport rows; stored schema often 1.6.0)',
11
+ v2: 'content-addressed EvolutionEvent JSONL; existing schema_version is preserved',
12
+ migrate: `import-v1 injects ${CURRENT_WIRE_SCHEMA_VERSION} only when schema_version is missing; frozen hash mismatches remain untrusted; ValidationReport rows are validated, counted, and preserved in the V1 source`,
13
+ },
14
+ {
15
+ id: 2,
16
+ severity: 'cosmetic',
17
+ v1: 'capsules.json(.l) in the selected current store, then repository legacy fallback',
18
+ v2: 'LocalJsonlProvider Capsule stream + migration/v1_extensions.jsonl for non-schema fields',
19
+ migrate: 'import-v1 combines the capsules envelope and JSONL overlay by id; JSONL wins',
20
+ },
21
+ {
22
+ id: 3,
23
+ severity: 'cosmetic',
24
+ v1: 'candidates.jsonl in the selected current store, then repository legacy fallback',
25
+ v2: 'material/candidates (selection input — not wire assets)',
26
+ migrate: 'import-v1 skips candidates (report.candidatesSkipped=true); operators keep pool outside wire store',
27
+ },
28
+ {
29
+ id: 4,
30
+ severity: 'cosmetic',
31
+ v1: 'failed_capsules.json',
32
+ v2: 'no automatic wire mapping',
33
+ migrate: 'not imported; preserve the V1 source for explicit operator recovery',
34
+ },
35
+ {
36
+ id: 5,
37
+ severity: 'cosmetic',
38
+ v1: 'genes.json(.l) in the selected current store, then repository legacy fallback',
39
+ v2: 'LocalJsonlProvider Gene JSONL (content-addressed)',
40
+ migrate: 'import-v1 combines the genes envelope and JSONL overlay by id; JSONL wins',
41
+ },
42
+ ];
43
+ /** V1 path components used to select one current workspace plus the repository legacy fallback. */
44
+ export const V1_GEP_SOURCE_LAYOUT = {
45
+ workspaceCurrent: ['workspace', '.evolver', 'gep'],
46
+ rootCurrent: ['.evolver', 'gep'],
47
+ legacy: ['assets', 'gep'],
48
+ };
49
+ export const V1_GEP_WIRE_SOURCES = {
50
+ Gene: { envelope: { basename: 'genes.json', key: 'genes' }, jsonl: 'genes.jsonl' },
51
+ Capsule: { envelope: { basename: 'capsules.json', key: 'capsules' }, jsonl: 'capsules.jsonl' },
52
+ EvolutionEvent: { jsonl: 'events.jsonl' },
53
+ };
@@ -0,0 +1,26 @@
1
+ import { bootstrap } from '@evomap/evolver-core';
2
+ export interface MigrateEnvOptions {
3
+ /** Path to a dotenv file to scan. When omitted, scans process env only. */
4
+ file?: string;
5
+ /** Also scan process.env (default true when file set). File values win, matching the runtime loader. */
6
+ includeProcessEnv?: boolean;
7
+ json?: boolean;
8
+ /** Optional path to write a suggested dotenv fragment (non-secret mapped keys only). */
9
+ writeSuggestions?: string;
10
+ }
11
+ export interface MigrateEnvResult {
12
+ report: bootstrap.V1EnvTranslationReport;
13
+ scannedKeys: string[];
14
+ source: 'process' | 'file' | 'file+process';
15
+ }
16
+ export declare function runMigrateEnvScan(opts: MigrateEnvOptions, processEnv?: Record<string, string | undefined>): MigrateEnvResult;
17
+ /** Build a dotenv fragment for mappable keys only (never writes secret values for keep/GITHUB). */
18
+ export declare function formatMappedDotenvFragment(report: bootstrap.V1EnvTranslationReport): string;
19
+ export declare function parseMigrateEnvArgs(argv: readonly string[]): MigrateEnvOptions | {
20
+ error: string;
21
+ };
22
+ export declare function runMigrateEnvCommand(argv: readonly string[], io?: {
23
+ stdout?: (line: string) => void;
24
+ stderr?: (line: string) => void;
25
+ env?: Record<string, string | undefined>;
26
+ }): Promise<number>;
@@ -0,0 +1,147 @@
1
+ // Offline V1→V2 env translation for `evolver migrate env` (Refs #698).
2
+ import { readFileSync, writeFileSync } from 'node:fs';
3
+ import { resolve } from 'node:path';
4
+ import { bootstrap } from '@evomap/evolver-core';
5
+ import { expandHomePath, parseEnvFile } from '@evomap/evolver-mcp';
6
+ function loadFileEnv(path) {
7
+ const resolved = resolve(expandHomePath(path));
8
+ return parseEnvFile(readFileSync(resolved, 'utf8'));
9
+ }
10
+ export function runMigrateEnvScan(opts, processEnv = process.env) {
11
+ let env = {};
12
+ let source = 'process';
13
+ if (opts.file) {
14
+ const fromFile = loadFileEnv(opts.file);
15
+ env = { ...fromFile };
16
+ source = 'file';
17
+ if (opts.includeProcessEnv !== false) {
18
+ env = { ...processEnv, ...fromFile };
19
+ source = 'file+process';
20
+ }
21
+ }
22
+ else {
23
+ env = { ...processEnv };
24
+ }
25
+ const report = bootstrap.translateV1Env(env);
26
+ return { report, scannedKeys: Object.keys(env).sort(), source };
27
+ }
28
+ /** Build a dotenv fragment for mappable keys only (never writes secret values for keep/GITHUB). */
29
+ export function formatMappedDotenvFragment(report) {
30
+ const lines = [
31
+ '# Generated by: evolver migrate env --write-suggestions',
32
+ '# Only MAP suggestions (V1 → V2 rename). Review before applying.',
33
+ '# Manual and removed V1 keys are comments; resolve manual items before deleting them.',
34
+ ...(report.caveats ?? []).map((caveat) => `# CAVEAT ${caveat}`),
35
+ '',
36
+ ];
37
+ for (const s of report.suggestions) {
38
+ if (s.action === 'map' && s.v2Name && s.v2Value !== undefined) {
39
+ lines.push(`# was ${s.v1Name}`);
40
+ lines.push(`${s.v2Name}=${JSON.stringify(s.v2Value)}`);
41
+ lines.push('');
42
+ }
43
+ else if (s.action === 'manual') {
44
+ lines.push(`# REVIEW ${s.v1Name} — ${s.guidance}`);
45
+ lines.push('');
46
+ }
47
+ else if (s.action === 'remove') {
48
+ lines.push(`# REMOVE ${s.v1Name} — ${s.guidance}`);
49
+ lines.push('');
50
+ }
51
+ }
52
+ return lines.join('\n');
53
+ }
54
+ export function parseMigrateEnvArgs(argv) {
55
+ const opts = {};
56
+ for (let i = 0; i < argv.length; i += 1) {
57
+ const a = argv[i] ?? '';
58
+ if (a === '--json')
59
+ opts.json = true;
60
+ else if (a === '--file' || a === '--env-file') {
61
+ const v = argv[++i];
62
+ if (!v || v.startsWith('--'))
63
+ return { error: 'migrate env --file requires a path' };
64
+ opts.file = v;
65
+ }
66
+ else if (a.startsWith('--file='))
67
+ opts.file = a.slice('--file='.length);
68
+ else if (a.startsWith('--env-file='))
69
+ opts.file = a.slice('--env-file='.length);
70
+ else if (a === '--write-suggestions') {
71
+ const v = argv[++i];
72
+ if (!v || v.startsWith('--'))
73
+ return { error: 'migrate env --write-suggestions requires a path' };
74
+ opts.writeSuggestions = v;
75
+ }
76
+ else if (a.startsWith('--write-suggestions='))
77
+ opts.writeSuggestions = a.slice('--write-suggestions='.length);
78
+ else if (a === '--no-process-env')
79
+ opts.includeProcessEnv = false;
80
+ else if (a === '--help' || a === '-h')
81
+ return { error: 'help' };
82
+ else
83
+ return { error: `unknown argument: ${a}` };
84
+ }
85
+ return opts;
86
+ }
87
+ export async function runMigrateEnvCommand(argv, io = {}) {
88
+ const stdout = io.stdout ?? ((line) => { process.stdout.write(line); });
89
+ const stderr = io.stderr ?? ((line) => { process.stderr.write(line); });
90
+ const usage = [
91
+ 'Usage: evolver migrate env [--file <dotenv>] [--json] [--write-suggestions <path>] [--no-process-env]',
92
+ '',
93
+ 'Offline V1→V2 env translation for knobs removed or renamed after upgrade (Refs #698).',
94
+ 'Does not load secrets into resolvers; prints key names and actions only in text mode.',
95
+ '',
96
+ ].join('\n');
97
+ const parsed = parseMigrateEnvArgs(argv);
98
+ if ('error' in parsed) {
99
+ if (parsed.error === 'help') {
100
+ stdout(usage);
101
+ return 0;
102
+ }
103
+ stderr(`${parsed.error}\n${usage}`);
104
+ return 1;
105
+ }
106
+ try {
107
+ const result = runMigrateEnvScan(parsed, io.env ?? process.env);
108
+ if (parsed.writeSuggestions) {
109
+ const fragment = formatMappedDotenvFragment(result.report);
110
+ writeFileSync(resolve(expandHomePath(parsed.writeSuggestions)), fragment, {
111
+ encoding: 'utf8',
112
+ flag: 'wx',
113
+ mode: 0o600,
114
+ });
115
+ }
116
+ if (parsed.json) {
117
+ // JSON mode deliberately emits metadata only; raw source and mapped values stay in memory.
118
+ const safe = {
119
+ source: result.source,
120
+ detectedCount: result.report.detectedCount,
121
+ mappableCount: result.report.mappableCount,
122
+ manualCount: result.report.manualCount,
123
+ removableCount: result.report.removableCount,
124
+ githubTokenPresent: result.report.githubTokenPresent,
125
+ caveats: result.report.caveats ?? [],
126
+ suggestions: result.report.suggestions.map((s) => ({
127
+ v1Name: s.v1Name,
128
+ action: s.action,
129
+ v2Name: s.v2Name,
130
+ guidance: s.guidance,
131
+ })),
132
+ };
133
+ stdout(`${JSON.stringify(safe, null, 2)}\n`);
134
+ }
135
+ else {
136
+ stdout(bootstrap.formatV1EnvTranslationReport(result.report));
137
+ if (parsed.writeSuggestions) {
138
+ stdout(`wrote suggestions: ${parsed.writeSuggestions}\n`);
139
+ }
140
+ }
141
+ return 0;
142
+ }
143
+ catch (error) {
144
+ stderr(`migrate env: ${error instanceof Error ? error.message : String(error)}\n`);
145
+ return 1;
146
+ }
147
+ }
@@ -7,9 +7,11 @@ export interface MappedAsset {
7
7
  /**
8
8
  * v1 资产 → v2 wire(M8-2). 规则:
9
9
  * - 只留 gep-sdk schema 允许字段, 其余(avoid 等)落 dropped→sidecar(不参与 canonicalize, 不动 asset_id).
10
- * - Gene 缺 schema_version → 注入 wire.SCHEMA_VERSION(权威 1.6.0, 非 package version).
10
+ * - 缺 schema_version → 注入 wire.SCHEMA_VERSION 作为新记录 authoring default;已有版本原样保留。
11
+ * SDK package version 不是最低可接受 wire version。
11
12
  * - source_type 非标枚举 → generated; mutation_id null → ''.
12
- * - asset_id: 有则**冻结**(原样); 仅 event 缺 asset_id 时新算(recomputed=true).
13
+ * - asset_id: 有则**冻结**(原样); 缺失时新算(recomputed=true). 若映射改变正文,importer 会用
14
+ * content-bound provenance 隔离 frozen mismatch,而不是把它默认为可信资产(Refs #677).
13
15
  * - v2 新增 optional(resolution_status/proof_of_work/...) v1 无 → 自然省略(不合成).
14
16
  * - Gene 的 routing_hint/tool_policy 是 v2-delta(v1 PR #93): gep-sdk gene.schema.json 尚无 → schemaProperties
15
17
  * 不含它们, 默认会落 sidecar; 这里按已知 delta 归一化后保留在 record(保真). 存在但归一化为 null 的脏值
@@ -1,13 +1,15 @@
1
1
  import { wire } from '@evomap/evolver-core';
2
2
  // v1→v2 source_type 枚举转换(skill2gep_distillation 等非标 → generated).
3
3
  const SOURCE_TYPE_MAP = { skill2gep_distillation: 'generated' };
4
- const KNOWN_SOURCE = new Set(['generated', 'reused', 'reference']);
4
+ const KNOWN_SOURCE = new Set(['generated', 'reused', 'reference', 'user_authored']);
5
5
  /**
6
6
  * v1 资产 → v2 wire(M8-2). 规则:
7
7
  * - 只留 gep-sdk schema 允许字段, 其余(avoid 等)落 dropped→sidecar(不参与 canonicalize, 不动 asset_id).
8
- * - Gene 缺 schema_version → 注入 wire.SCHEMA_VERSION(权威 1.6.0, 非 package version).
8
+ * - 缺 schema_version → 注入 wire.SCHEMA_VERSION 作为新记录 authoring default;已有版本原样保留。
9
+ * SDK package version 不是最低可接受 wire version。
9
10
  * - source_type 非标枚举 → generated; mutation_id null → ''.
10
- * - asset_id: 有则**冻结**(原样); 仅 event 缺 asset_id 时新算(recomputed=true).
11
+ * - asset_id: 有则**冻结**(原样); 缺失时新算(recomputed=true). 若映射改变正文,importer 会用
12
+ * content-bound provenance 隔离 frozen mismatch,而不是把它默认为可信资产(Refs #677).
11
13
  * - v2 新增 optional(resolution_status/proof_of_work/...) v1 无 → 自然省略(不合成).
12
14
  * - Gene 的 routing_hint/tool_policy 是 v2-delta(v1 PR #93): gep-sdk gene.schema.json 尚无 → schemaProperties
13
15
  * 不含它们, 默认会落 sidecar; 这里按已知 delta 归一化后保留在 record(保真). 存在但归一化为 null 的脏值
@@ -15,8 +17,10 @@ const KNOWN_SOURCE = new Set(['generated', 'reused', 'reference']);
15
17
  */
16
18
  export function mapV1Asset(kind, v1) {
17
19
  const allowed = new Set(wire.schemaProperties(kind));
18
- const record = {};
19
- const dropped = {};
20
+ // V1 rows are untrusted. Null prototypes keep keys such as `__proto__` auditable instead of invoking
21
+ // Object.prototype setters and silently losing extension data.
22
+ const record = Object.create(null);
23
+ const dropped = Object.create(null);
20
24
  // v2-delta gene 提示字段不当作"非 schema 字段"丢 sidecar — 下方归一化后保留为 record 一等字段.
21
25
  const deltaKeys = kind === 'Gene' ? new Set(wire.GENE_HINT_FIELDS) : new Set();
22
26
  for (const [k, val] of Object.entries(v1)) {