@evomap/evolver-cli 2.0.0-beta.1 → 2.0.0-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/antiGeneBenchmark.js +12 -0
- package/dist/antiGeneEvidence.d.ts +15 -0
- package/dist/antiGeneEvidence.js +49 -0
- package/dist/antiGeneRollout.d.ts +3 -1
- package/dist/antiGeneRollout.js +16 -2
- package/dist/assetHealth.d.ts +6 -0
- package/dist/assetHealth.js +105 -0
- package/dist/assetSidecarRecovery.d.ts +14 -0
- package/dist/assetSidecarRecovery.js +171 -0
- package/dist/assetTrust.d.ts +24 -0
- package/dist/assetTrust.js +218 -0
- package/dist/atp.js +4 -2
- package/dist/autoDistillLlm.js +4 -1
- package/dist/autoexec.d.ts +13 -3
- package/dist/autoexec.js +71 -13
- package/dist/cli.js +12 -5
- package/dist/cliContracts.js +8 -2
- package/dist/cliLifecycle.d.ts +7 -0
- package/dist/cliLifecycle.js +9 -0
- package/dist/cycleConsumer.d.ts +61 -1
- package/dist/cycleConsumer.js +551 -16
- package/dist/dashboard.d.ts +23 -0
- package/dist/dashboard.js +191 -0
- package/dist/dispatch.d.ts +10 -1
- package/dist/dispatch.js +36 -2
- package/dist/distillObserver.js +2 -2
- package/dist/distillPrimitives.d.ts +1 -1
- package/dist/distillPrimitives.js +29 -2
- package/dist/doctor.d.ts +2 -0
- package/dist/doctor.js +33 -3
- package/dist/index.d.ts +7 -2
- package/dist/index.js +292 -36
- package/dist/lifecycle.d.ts +19 -1
- package/dist/lifecycle.js +226 -29
- package/dist/localMemoryGraph.d.ts +97 -0
- package/dist/localMemoryGraph.js +889 -0
- package/dist/login.d.ts +20 -4
- package/dist/login.js +58 -8
- package/dist/materialPackage.d.ts +52 -0
- package/dist/materialPackage.js +404 -0
- package/dist/materialSnapshot.d.ts +30 -0
- package/dist/materialSnapshot.js +148 -0
- package/dist/memoryEventMirror.d.ts +23 -0
- package/dist/memoryEventMirror.js +140 -0
- package/dist/migrate/fieldMap.js +25 -0
- package/dist/migrate/v1Import.d.ts +7 -1
- package/dist/migrate/v1Import.js +132 -11
- package/dist/nonGitWorkspaceNotice.d.ts +24 -0
- package/dist/nonGitWorkspaceNotice.js +122 -0
- package/dist/proxyToken.d.ts +10 -0
- package/dist/proxyToken.js +80 -0
- package/dist/recipe.d.ts +10 -2
- package/dist/recipe.js +349 -7
- package/dist/reuseReport.js +16 -16
- package/dist/runtimeCapabilities.d.ts +18 -0
- package/dist/runtimeCapabilities.js +81 -0
- package/dist/runtimeSessionSource.d.ts +10 -0
- package/dist/runtimeSessionSource.js +32 -5
- package/dist/setupHooks.d.ts +6 -1
- package/dist/setupHooks.js +5 -2
- package/dist/skill2gep.d.ts +38 -9
- package/dist/skill2gep.js +147 -14
- package/dist/skillDistill.d.ts +1 -0
- package/dist/skillDistill.js +4 -4
- package/dist/skillFetch.d.ts +18 -0
- package/dist/skillFetch.js +391 -0
- package/dist/solo/mode.js +5 -0
- package/dist/sync.d.ts +26 -0
- package/dist/sync.js +988 -0
- package/dist/trajectoryExport.js +23 -12
- package/dist/v1Compat.d.ts +24 -0
- package/dist/v1Compat.js +249 -0
- package/package.json +12 -6
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { hub, schema } from '@evomap/evolver-core';
|
|
3
|
+
import { parseRuntimeSessionSources } from './runtimeSessionSource.js';
|
|
4
|
+
export const MATERIAL_RUNTIME_SESSION_SNAPSHOT_SCHEMA = 'evolver.material.runtime_session_snapshot.v1';
|
|
5
|
+
const DEFAULT_MATERIAL_SNAPSHOT_MAX_CHARS = 24 * 1024;
|
|
6
|
+
function isRecord(value) {
|
|
7
|
+
return !!value && typeof value === 'object' && !Array.isArray(value);
|
|
8
|
+
}
|
|
9
|
+
function trimText(value, remaining) {
|
|
10
|
+
if (remaining <= 0)
|
|
11
|
+
return { text: '', used: 0, truncated: value.length > 0 };
|
|
12
|
+
const redacted = hub.redactString(value).replace(/\s+/g, ' ').trim();
|
|
13
|
+
if (redacted.length <= remaining)
|
|
14
|
+
return { text: redacted, used: redacted.length, truncated: false };
|
|
15
|
+
return { text: redacted.slice(0, remaining), used: remaining, truncated: true };
|
|
16
|
+
}
|
|
17
|
+
function snapshotTurnText(turn) {
|
|
18
|
+
return turn.text || turn.errorMessage || turn.toolResult || '';
|
|
19
|
+
}
|
|
20
|
+
function fitsInline(snapshot) {
|
|
21
|
+
return Buffer.byteLength(JSON.stringify(snapshot), 'utf8') <= schema.MATERIAL_PAYLOAD_INLINE_MAX_BYTES;
|
|
22
|
+
}
|
|
23
|
+
export function buildRuntimeSessionMaterialSnapshot(sources, maxChars = DEFAULT_MATERIAL_SNAPSHOT_MAX_CHARS) {
|
|
24
|
+
const safeMaxChars = Math.max(0, Math.min(maxChars, DEFAULT_MATERIAL_SNAPSHOT_MAX_CHARS));
|
|
25
|
+
let remaining = safeMaxChars;
|
|
26
|
+
let truncated = false;
|
|
27
|
+
const snapshotSources = [];
|
|
28
|
+
for (const source of sources) {
|
|
29
|
+
const turns = [];
|
|
30
|
+
for (const turn of source.turns) {
|
|
31
|
+
const rawText = snapshotTurnText(turn);
|
|
32
|
+
const trimmed = trimText(rawText, remaining);
|
|
33
|
+
remaining -= trimmed.used;
|
|
34
|
+
truncated = truncated || trimmed.truncated;
|
|
35
|
+
if (trimmed.text.length > 0) {
|
|
36
|
+
turns.push({
|
|
37
|
+
role: turn.role,
|
|
38
|
+
text: trimmed.text,
|
|
39
|
+
...(turn.isMeta ? { isMeta: true } : {}),
|
|
40
|
+
...(turn.toolName ? { toolName: hub.redactString(turn.toolName).slice(0, 120) } : {}),
|
|
41
|
+
...(turn.errorMessage && trimmed.text ? { errorMessage: trimmed.text } : {}),
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
if (remaining <= 0) {
|
|
45
|
+
truncated = true;
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
snapshotSources.push({
|
|
50
|
+
agent: source.agent,
|
|
51
|
+
label: source.label,
|
|
52
|
+
...(source.sessionId ? { sessionId: source.sessionId } : {}),
|
|
53
|
+
turns,
|
|
54
|
+
});
|
|
55
|
+
if (remaining <= 0)
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
const snapshot = {
|
|
59
|
+
schema: MATERIAL_RUNTIME_SESSION_SNAPSHOT_SCHEMA,
|
|
60
|
+
sourceKind: 'runtime_session',
|
|
61
|
+
kind: 'session_log',
|
|
62
|
+
sources: snapshotSources,
|
|
63
|
+
truncated,
|
|
64
|
+
maxChars: safeMaxChars,
|
|
65
|
+
};
|
|
66
|
+
while (!fitsInline(snapshot) && snapshot.sources.length > 0) {
|
|
67
|
+
const lastSource = snapshot.sources[snapshot.sources.length - 1];
|
|
68
|
+
if (lastSource.turns.length > 0)
|
|
69
|
+
lastSource.turns.pop();
|
|
70
|
+
else
|
|
71
|
+
snapshot.sources.pop();
|
|
72
|
+
snapshot.truncated = true;
|
|
73
|
+
}
|
|
74
|
+
return snapshot;
|
|
75
|
+
}
|
|
76
|
+
function sourceFromSnapshot(value) {
|
|
77
|
+
if (!isRecord(value))
|
|
78
|
+
return null;
|
|
79
|
+
const agent = typeof value['agent'] === 'string' ? value['agent'] : '';
|
|
80
|
+
const label = typeof value['label'] === 'string' ? value['label'] : '';
|
|
81
|
+
const turnsRaw = Array.isArray(value['turns']) ? value['turns'] : [];
|
|
82
|
+
if (!agent || !label)
|
|
83
|
+
return null;
|
|
84
|
+
const turns = turnsRaw
|
|
85
|
+
.map((turn) => {
|
|
86
|
+
if (!isRecord(turn))
|
|
87
|
+
return null;
|
|
88
|
+
const role = turn['role'];
|
|
89
|
+
const text = turn['text'];
|
|
90
|
+
if ((role !== 'user' && role !== 'assistant' && role !== 'tool' && role !== 'system') || typeof text !== 'string')
|
|
91
|
+
return null;
|
|
92
|
+
const toolName = typeof turn['toolName'] === 'string' && turn['toolName'].trim() ? turn['toolName'] : undefined;
|
|
93
|
+
const errorMessage = typeof turn['errorMessage'] === 'string' && turn['errorMessage'].trim() ? turn['errorMessage'] : undefined;
|
|
94
|
+
return {
|
|
95
|
+
role,
|
|
96
|
+
text,
|
|
97
|
+
isMeta: turn['isMeta'] === true,
|
|
98
|
+
...(toolName ? { toolName } : {}),
|
|
99
|
+
...(errorMessage ? { errorMessage } : {}),
|
|
100
|
+
};
|
|
101
|
+
})
|
|
102
|
+
.filter((turn) => turn !== null);
|
|
103
|
+
if (turns.length === 0)
|
|
104
|
+
return null;
|
|
105
|
+
const sessionId = typeof value['sessionId'] === 'string' && value['sessionId'].trim() ? value['sessionId'] : undefined;
|
|
106
|
+
return {
|
|
107
|
+
agent,
|
|
108
|
+
label,
|
|
109
|
+
...(sessionId ? { sessionId } : {}),
|
|
110
|
+
turns,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
export function runtimeSessionSourcesFromMaterialPayload(payload) {
|
|
114
|
+
if (!isRecord(payload))
|
|
115
|
+
return [];
|
|
116
|
+
if (payload['schema'] !== MATERIAL_RUNTIME_SESSION_SNAPSHOT_SCHEMA)
|
|
117
|
+
return [];
|
|
118
|
+
if (payload['sourceKind'] !== 'runtime_session' || payload['kind'] !== 'session_log')
|
|
119
|
+
return [];
|
|
120
|
+
const sources = Array.isArray(payload['sources']) ? payload['sources'] : [];
|
|
121
|
+
return sources
|
|
122
|
+
.map(sourceFromSnapshot)
|
|
123
|
+
.filter((source) => source !== null);
|
|
124
|
+
}
|
|
125
|
+
export function materialHasRuntimeSessionSnapshot(material) {
|
|
126
|
+
return runtimeSessionSourcesFromMaterialPayload(material.payload).length > 0;
|
|
127
|
+
}
|
|
128
|
+
export function materialSourceAvailable(material) {
|
|
129
|
+
return existsSync(material.sourcePath);
|
|
130
|
+
}
|
|
131
|
+
export function runtimeSessionSourcesForMaterial(material, readSource) {
|
|
132
|
+
let sourceError;
|
|
133
|
+
try {
|
|
134
|
+
const sources = parseRuntimeSessionSources(material.sourcePath, readSource);
|
|
135
|
+
const sourcesWithTurns = sources.filter((source) => source.turns.length > 0);
|
|
136
|
+
if (sourcesWithTurns.length > 0)
|
|
137
|
+
return sourcesWithTurns;
|
|
138
|
+
}
|
|
139
|
+
catch (error) {
|
|
140
|
+
sourceError = error;
|
|
141
|
+
}
|
|
142
|
+
const snapshotSources = runtimeSessionSourcesFromMaterialPayload(material.payload);
|
|
143
|
+
if (snapshotSources.length > 0)
|
|
144
|
+
return snapshotSources;
|
|
145
|
+
if (sourceError)
|
|
146
|
+
throw sourceError;
|
|
147
|
+
return [];
|
|
148
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { events, observers } from '@evomap/evolver-core';
|
|
2
|
+
import { type MemoryGraphEventKind, type MemoryGraphEventReceipt, type MemoryGraphEventReport } from '@evomap/evolver-adapter-public';
|
|
3
|
+
export interface MemoryEventHub {
|
|
4
|
+
recordMemoryEvent(report: MemoryGraphEventReport): Promise<MemoryGraphEventReceipt>;
|
|
5
|
+
}
|
|
6
|
+
export interface MemoryEventMirrorWiring {
|
|
7
|
+
enabled: boolean;
|
|
8
|
+
reason?: 'disabled' | 'no_hub';
|
|
9
|
+
observer: observers.Observer | null;
|
|
10
|
+
}
|
|
11
|
+
export declare function rootEventMemoryGraphKind(type: string): MemoryGraphEventKind | null;
|
|
12
|
+
export declare function buildMemoryGraphMirrorEvent(event: Readonly<events.RootEvent>, opts?: {
|
|
13
|
+
maxChars?: number;
|
|
14
|
+
env?: Record<string, string | undefined>;
|
|
15
|
+
}): {
|
|
16
|
+
kind: MemoryGraphEventKind;
|
|
17
|
+
event: Record<string, unknown>;
|
|
18
|
+
} | null;
|
|
19
|
+
export declare function memoryEventMirrorObserver(hub: MemoryEventHub, opts?: {
|
|
20
|
+
env?: Record<string, string | undefined>;
|
|
21
|
+
maxChars?: number;
|
|
22
|
+
}): observers.Observer;
|
|
23
|
+
export declare function resolveMemoryEventMirrorObserver(env?: Record<string, string | undefined>, hub?: Partial<MemoryEventHub> | null): MemoryEventMirrorWiring;
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { events, hub as hubNs, observers } from '@evomap/evolver-core';
|
|
2
|
+
import { HUB_CONNECT_TIMEOUT_MS, } from '@evomap/evolver-adapter-public';
|
|
3
|
+
const MEMORY_EVENT_MIRROR_TYPES = {
|
|
4
|
+
'cycle.started': 'attempt',
|
|
5
|
+
'decision.gene_selected': 'attempt',
|
|
6
|
+
'cycle.failed': 'validation',
|
|
7
|
+
'gene.distilled': 'skill_emit',
|
|
8
|
+
'capsule.produced': 'outcome',
|
|
9
|
+
'value.reuse_hit': 'outcome',
|
|
10
|
+
'value.reuse_outcome': 'outcome',
|
|
11
|
+
'mutation.built': 'mutation_draft',
|
|
12
|
+
'cycle.solidified': 'solidify',
|
|
13
|
+
'evolution_event.projected': 'solidify',
|
|
14
|
+
};
|
|
15
|
+
const MEMORY_EVENT_MIRROR_EVENT_TYPES = Object.keys(MEMORY_EVENT_MIRROR_TYPES);
|
|
16
|
+
const DEFAULT_MEMORY_EVENT_MAX_CHARS = 12_000;
|
|
17
|
+
const MEMORY_EVENT_MIRROR_TIMEOUT_MS = HUB_CONNECT_TIMEOUT_MS + 5_000;
|
|
18
|
+
function memoryGraphSyncDisabled(env = process.env) {
|
|
19
|
+
return isOff(env['MEMORY_GRAPH_SYNC_HUB']) || isOff(env['EVOLVER_MEMORY_GRAPH_SYNC_HUB']);
|
|
20
|
+
}
|
|
21
|
+
export function rootEventMemoryGraphKind(type) {
|
|
22
|
+
return MEMORY_EVENT_MIRROR_TYPES[type] ?? null;
|
|
23
|
+
}
|
|
24
|
+
export function buildMemoryGraphMirrorEvent(event, opts = {}) {
|
|
25
|
+
const kind = rootEventMemoryGraphKind(event.type);
|
|
26
|
+
if (!kind)
|
|
27
|
+
return null;
|
|
28
|
+
const maxChars = opts.maxChars ?? DEFAULT_MEMORY_EVENT_MAX_CHARS;
|
|
29
|
+
const env = opts.env ?? {};
|
|
30
|
+
const payload = sanitizeValue(event.payload, maxChars, env);
|
|
31
|
+
const human = sanitizeValue(event.human, maxChars, env);
|
|
32
|
+
const actor = sanitizeValue(event.actor, maxChars, env);
|
|
33
|
+
return {
|
|
34
|
+
kind,
|
|
35
|
+
event: {
|
|
36
|
+
type: 'MemoryGraphEvent',
|
|
37
|
+
kind,
|
|
38
|
+
id: event.eventId,
|
|
39
|
+
ts: event.ts,
|
|
40
|
+
source: {
|
|
41
|
+
eventId: event.eventId,
|
|
42
|
+
seq: event.seq,
|
|
43
|
+
type: event.type,
|
|
44
|
+
},
|
|
45
|
+
payload: payload.value,
|
|
46
|
+
human: human.value,
|
|
47
|
+
actor: actor.value,
|
|
48
|
+
...(payload.truncated || human.truncated || actor.truncated ? { truncated: true } : {}),
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
export function memoryEventMirrorObserver(hub, opts = {}) {
|
|
53
|
+
return {
|
|
54
|
+
meta: {
|
|
55
|
+
name: 'memory-event-mirror',
|
|
56
|
+
idempotent: true,
|
|
57
|
+
timeoutMs: MEMORY_EVENT_MIRROR_TIMEOUT_MS,
|
|
58
|
+
eventTypes: MEMORY_EVENT_MIRROR_EVENT_TYPES,
|
|
59
|
+
},
|
|
60
|
+
async handle(event) {
|
|
61
|
+
if (memoryGraphSyncDisabled(opts.env ?? process.env))
|
|
62
|
+
return;
|
|
63
|
+
const report = buildMemoryGraphMirrorEvent(event, { maxChars: opts.maxChars, env: opts.env ?? process.env });
|
|
64
|
+
if (!report)
|
|
65
|
+
return;
|
|
66
|
+
try {
|
|
67
|
+
await hub.recordMemoryEvent(report);
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
// Hub mirroring is telemetry only. Local root_event durability must never depend on it.
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
export function resolveMemoryEventMirrorObserver(env = process.env, hub) {
|
|
76
|
+
if (memoryGraphSyncDisabled(env))
|
|
77
|
+
return { enabled: false, reason: 'disabled', observer: null };
|
|
78
|
+
if (!hub || typeof hub.recordMemoryEvent !== 'function')
|
|
79
|
+
return { enabled: false, reason: 'no_hub', observer: null };
|
|
80
|
+
return { enabled: true, observer: memoryEventMirrorObserver(hub, { env }) };
|
|
81
|
+
}
|
|
82
|
+
function isOff(value) {
|
|
83
|
+
if (value === undefined)
|
|
84
|
+
return false;
|
|
85
|
+
const normalized = String(value ?? '').trim().toLowerCase();
|
|
86
|
+
return normalized === '' || normalized === '0' || normalized === 'false' || normalized === 'off';
|
|
87
|
+
}
|
|
88
|
+
function sanitizeValue(value, maxChars, env) {
|
|
89
|
+
const redacted = hubNs.redactDeep(redactEnvValues(value, env));
|
|
90
|
+
let json;
|
|
91
|
+
try {
|
|
92
|
+
json = JSON.stringify(redacted);
|
|
93
|
+
}
|
|
94
|
+
catch {
|
|
95
|
+
json = hubNs.redactString(String(redacted));
|
|
96
|
+
}
|
|
97
|
+
if (hubNs.detectEnvValueLeaks(json, env).length > 0) {
|
|
98
|
+
return {
|
|
99
|
+
value: {
|
|
100
|
+
redacted: true,
|
|
101
|
+
reason: 'env_value_leak',
|
|
102
|
+
},
|
|
103
|
+
truncated: false,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
if (json.length <= maxChars)
|
|
107
|
+
return { value: redacted, truncated: false };
|
|
108
|
+
return {
|
|
109
|
+
value: {
|
|
110
|
+
truncated: true,
|
|
111
|
+
redactedJson: hubNs.redactString(json).slice(0, maxChars),
|
|
112
|
+
},
|
|
113
|
+
truncated: true,
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
function redactEnvValues(value, env) {
|
|
117
|
+
if (typeof value === 'string')
|
|
118
|
+
return redactEnvValueString(value, env);
|
|
119
|
+
if (Array.isArray(value))
|
|
120
|
+
return value.map((item) => redactEnvValues(item, env));
|
|
121
|
+
if (!value || typeof value !== 'object')
|
|
122
|
+
return value;
|
|
123
|
+
const out = {};
|
|
124
|
+
for (const [key, nested] of Object.entries(value)) {
|
|
125
|
+
const safeKey = hubNs.redactString(redactEnvValueString(key, env));
|
|
126
|
+
out[safeKey] = redactEnvValues(nested, env);
|
|
127
|
+
}
|
|
128
|
+
return out;
|
|
129
|
+
}
|
|
130
|
+
function redactEnvValueString(value, env) {
|
|
131
|
+
let out = value;
|
|
132
|
+
for (const [key, secret] of Object.entries(env)) {
|
|
133
|
+
if (!secret || secret.length < 8)
|
|
134
|
+
continue;
|
|
135
|
+
if (hubNs.detectEnvValueLeaks(out, { [key]: secret }).length === 0)
|
|
136
|
+
continue;
|
|
137
|
+
out = out.split(secret).join(hubNs.REDACTED);
|
|
138
|
+
}
|
|
139
|
+
return out;
|
|
140
|
+
}
|
package/dist/migrate/fieldMap.js
CHANGED
|
@@ -45,6 +45,31 @@ export function mapV1Asset(kind, v1) {
|
|
|
45
45
|
record['tool_policy'] = toolPolicy;
|
|
46
46
|
else if (v1['tool_policy'] !== null && v1['tool_policy'] !== undefined)
|
|
47
47
|
dropped['tool_policy'] = v1['tool_policy'];
|
|
48
|
+
// v1 #302 `_source` block (generation_source / quality_score / quality_heuristics / overcame_errors) → v2
|
|
49
|
+
// `generation_meta`. v1 #302 was never merged to HEAD, so real v1 genes lack `_source`; this maps it IF present
|
|
50
|
+
// (forward-compat for a repo that carried the #302 branch). A `_source` whose generation_source normalizes away
|
|
51
|
+
// (unknown enum) is NOT silently dropped — the raw `_source` stays in `dropped` for audit (it already landed there
|
|
52
|
+
// above as a non-schema field). `generation_meta` itself (if a v1 gene already carried the v2 field name) is a
|
|
53
|
+
// deltaKey so it was skipped above and is handled here by normalize, same as the hints.
|
|
54
|
+
if (v1['_source'] !== undefined && v1['_source'] !== null) {
|
|
55
|
+
const src = v1['_source'];
|
|
56
|
+
if (src && typeof src === 'object') {
|
|
57
|
+
const s = src;
|
|
58
|
+
const mapped = wire.normalizeGenerationMeta({
|
|
59
|
+
source: s['generation_source'],
|
|
60
|
+
quality_score: s['quality_score'],
|
|
61
|
+
quality_heuristics: s['quality_heuristics'],
|
|
62
|
+
overcame_errors: s['overcame_errors'],
|
|
63
|
+
});
|
|
64
|
+
if (mapped)
|
|
65
|
+
record['generation_meta'] = mapped;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
const generationMeta = wire.normalizeGenerationMeta(v1['generation_meta']);
|
|
69
|
+
if (generationMeta)
|
|
70
|
+
record['generation_meta'] = generationMeta;
|
|
71
|
+
else if (v1['generation_meta'] !== null && v1['generation_meta'] !== undefined)
|
|
72
|
+
dropped['generation_meta'] = v1['generation_meta'];
|
|
48
73
|
}
|
|
49
74
|
if (allowed.has('schema_version') && record['schema_version'] === undefined)
|
|
50
75
|
record['schema_version'] = wire.SCHEMA_VERSION;
|
|
@@ -7,10 +7,16 @@ export interface ImportReport {
|
|
|
7
7
|
deduped: number;
|
|
8
8
|
sidecarExtensions: number;
|
|
9
9
|
memoryGraphArchived: boolean;
|
|
10
|
+
memoryGraphImported: number;
|
|
11
|
+
memoryGraphDeferred: boolean;
|
|
10
12
|
candidatesSkipped: boolean;
|
|
11
13
|
}
|
|
12
14
|
/**
|
|
13
15
|
* v1→v2 只读迁移(M8-2). 只读 v1(无双写); 冻结存量 asset_id; 非 schema 字段(avoid)落 sidecar;
|
|
14
16
|
* memory_graph 不强转(语义不符)→ 归档只读; candidates 候选池不属 wire 资产 → 跳过.
|
|
15
17
|
*/
|
|
16
|
-
export
|
|
18
|
+
export interface ImportV1Options {
|
|
19
|
+
workspace?: string;
|
|
20
|
+
userId?: string;
|
|
21
|
+
}
|
|
22
|
+
export declare function importV1(v1Dir: string, store: assetstore.LocalJsonlProvider, outDir: string, options?: ImportV1Options): Promise<ImportReport>;
|
package/dist/migrate/v1Import.js
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
1
2
|
import { createReadStream } from 'node:fs';
|
|
2
|
-
import { existsSync, mkdirSync,
|
|
3
|
-
import {
|
|
3
|
+
import { appendFileSync, closeSync, constants, existsSync, fstatSync, fsyncSync, linkSync, lstatSync, mkdirSync, openSync, readSync, realpathSync, unlinkSync, writeFileSync, writeSync, } from 'node:fs';
|
|
4
|
+
import { basename, dirname, join, resolve, sep } from 'node:path';
|
|
4
5
|
import { assetstore } from '@evomap/evolver-core';
|
|
5
6
|
import { mapV1Asset } from './fieldMap.js';
|
|
7
|
+
import { LocalMemoryGraph, MemoryGraphBusyError, MemoryGraphImportStateRejectedError, resolveLocalMemoryUserId, } from '../localMemoryGraph.js';
|
|
6
8
|
const FILES = { Gene: 'genes.jsonl', Capsule: 'capsules.jsonl', EvolutionEvent: 'events.jsonl' };
|
|
7
9
|
const DEFAULT_IMPORT_JSONL_MAX_LINE_BYTES = 16 * 1024 * 1024;
|
|
10
|
+
let migrationArchiveNonce = 0;
|
|
8
11
|
function maxJsonlLineBytes() {
|
|
9
12
|
const raw = Number(process.env['EVOLVER_IMPORT_JSONL_MAX_LINE_BYTES']);
|
|
10
13
|
return Number.isFinite(raw) && raw > 0 ? Math.floor(raw) : DEFAULT_IMPORT_JSONL_MAX_LINE_BYTES;
|
|
@@ -71,15 +74,11 @@ async function* readJsonl(path) {
|
|
|
71
74
|
for (const record of finish())
|
|
72
75
|
yield record;
|
|
73
76
|
}
|
|
74
|
-
|
|
75
|
-
* v1→v2 只读迁移(M8-2). 只读 v1(无双写); 冻结存量 asset_id; 非 schema 字段(avoid)落 sidecar;
|
|
76
|
-
* memory_graph 不强转(语义不符)→ 归档只读; candidates 候选池不属 wire 资产 → 跳过.
|
|
77
|
-
*/
|
|
78
|
-
export async function importV1(v1Dir, store, outDir) {
|
|
77
|
+
export async function importV1(v1Dir, store, outDir, options = {}) {
|
|
79
78
|
const sidecarPath = join(outDir, 'migration', 'v1_extensions.jsonl');
|
|
80
79
|
const rep = {
|
|
81
80
|
imported: { Gene: 0, Capsule: 0, EvolutionEvent: 0 }, frozen: 0, recomputed: 0, deduped: 0,
|
|
82
|
-
sidecarExtensions: 0, memoryGraphArchived: false, candidatesSkipped: false,
|
|
81
|
+
sidecarExtensions: 0, memoryGraphArchived: false, memoryGraphImported: 0, memoryGraphDeferred: false, candidatesSkipped: false,
|
|
83
82
|
};
|
|
84
83
|
const gepDir = join(v1Dir, 'assets', 'gep');
|
|
85
84
|
for (const kind of ['Gene', 'Capsule', 'EvolutionEvent']) {
|
|
@@ -103,16 +102,138 @@ export async function importV1(v1Dir, store, outDir) {
|
|
|
103
102
|
}
|
|
104
103
|
}
|
|
105
104
|
}
|
|
106
|
-
// memory_graph:
|
|
105
|
+
// memory_graph remains a sidecar: never convert it into EvolutionEvent or mutate Gene/Capsule identity.
|
|
107
106
|
const mg = join(v1Dir, 'memory', 'evolution', 'memory_graph.jsonl');
|
|
108
|
-
if (
|
|
107
|
+
if (secureRegularFileWithin(v1Dir, mg)) {
|
|
109
108
|
const dest = join(outDir, 'migration', 'legacy_memory_graph.jsonl');
|
|
110
109
|
mkdirSync(dirname(dest), { recursive: true });
|
|
111
|
-
|
|
110
|
+
archiveRegularFile(mg, dest);
|
|
112
111
|
rep.memoryGraphArchived = true;
|
|
112
|
+
const workspace = options.workspace ? canonicalDirectory(options.workspace) : null;
|
|
113
|
+
if (!workspace) {
|
|
114
|
+
rep.memoryGraphDeferred = true;
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
const source = realpathSync(mg);
|
|
118
|
+
const userId = options.userId ?? resolveLocalMemoryUserId();
|
|
119
|
+
const marker = scopedMemoryGraphMarker(outDir, workspace, userId, source);
|
|
120
|
+
if (!existsSync(marker)) {
|
|
121
|
+
const graph = new LocalMemoryGraph({ dir: join(outDir, 'evolution'), userId });
|
|
122
|
+
try {
|
|
123
|
+
for await (const record of readJsonl(mg)) {
|
|
124
|
+
if (graph.importV1Outcome(workspace, record, source))
|
|
125
|
+
rep.memoryGraphImported += 1;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
catch (error) {
|
|
129
|
+
if (!(error instanceof MemoryGraphImportStateRejectedError) && !(error instanceof MemoryGraphBusyError))
|
|
130
|
+
throw error;
|
|
131
|
+
rep.memoryGraphDeferred = true;
|
|
132
|
+
}
|
|
133
|
+
if (!rep.memoryGraphDeferred)
|
|
134
|
+
writeFileSync(marker, `${rep.memoryGraphImported}\n`, { mode: 0o600 });
|
|
135
|
+
}
|
|
136
|
+
}
|
|
113
137
|
}
|
|
114
138
|
// candidates 候选池非 wire 资产 → 不迁移(留作 selection 输入)
|
|
115
139
|
if (existsSync(join(gepDir, 'candidates.jsonl')))
|
|
116
140
|
rep.candidatesSkipped = true;
|
|
117
141
|
return rep;
|
|
142
|
+
}
|
|
143
|
+
function canonicalDirectory(path) {
|
|
144
|
+
try {
|
|
145
|
+
const absolute = resolve(path);
|
|
146
|
+
const stat = lstatSync(absolute);
|
|
147
|
+
return stat.isDirectory() && !stat.isSymbolicLink() ? realpathSync(absolute) : null;
|
|
148
|
+
}
|
|
149
|
+
catch {
|
|
150
|
+
return null;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
function scopedMemoryGraphMarker(outDir, workspace, userId, source) {
|
|
154
|
+
const scope = createHash('sha256').update(JSON.stringify({ workspace, userId, source })).digest('hex');
|
|
155
|
+
return join(outDir, 'migration', `v1_memory_graph_import.${scope}.complete`);
|
|
156
|
+
}
|
|
157
|
+
function secureRegularFileWithin(root, path) {
|
|
158
|
+
try {
|
|
159
|
+
const absoluteRoot = resolve(root);
|
|
160
|
+
const absolutePath = resolve(path);
|
|
161
|
+
const rootStat = lstatSync(absoluteRoot);
|
|
162
|
+
const fileStat = lstatSync(absolutePath);
|
|
163
|
+
if (!rootStat.isDirectory() || rootStat.isSymbolicLink() || !fileStat.isFile() || fileStat.isSymbolicLink())
|
|
164
|
+
return false;
|
|
165
|
+
const canonicalRoot = realpathSync(absoluteRoot);
|
|
166
|
+
const canonicalPath = realpathSync(absolutePath);
|
|
167
|
+
return canonicalPath.startsWith(canonicalRoot.endsWith(sep) ? canonicalRoot : `${canonicalRoot}${sep}`);
|
|
168
|
+
}
|
|
169
|
+
catch {
|
|
170
|
+
return false;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
function archiveRegularFile(source, destination) {
|
|
174
|
+
if (existsSync(destination)) {
|
|
175
|
+
const existing = lstatSync(destination);
|
|
176
|
+
if (!existing.isFile() || existing.isSymbolicLink())
|
|
177
|
+
throw new Error('memory_graph_archive_path_rejected');
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
const sourceFd = openSync(source, constants.O_RDONLY | constants.O_NOFOLLOW);
|
|
181
|
+
const temp = join(dirname(destination), `.${basename(destination)}.${process.pid}.${Date.now()}.${migrationArchiveNonce++}.tmp`);
|
|
182
|
+
let tempFd;
|
|
183
|
+
let copyError;
|
|
184
|
+
try {
|
|
185
|
+
if (!fstatSync(sourceFd).isFile())
|
|
186
|
+
throw new Error('memory_graph_source_path_rejected');
|
|
187
|
+
tempFd = openSync(temp, constants.O_WRONLY | constants.O_CREAT | constants.O_EXCL | constants.O_NOFOLLOW, 0o600);
|
|
188
|
+
const buffer = Buffer.alloc(64 * 1024);
|
|
189
|
+
for (;;) {
|
|
190
|
+
const bytesRead = readSync(sourceFd, buffer, 0, buffer.length, null);
|
|
191
|
+
if (bytesRead === 0)
|
|
192
|
+
break;
|
|
193
|
+
let offset = 0;
|
|
194
|
+
while (offset < bytesRead)
|
|
195
|
+
offset += writeSync(tempFd, buffer, offset, bytesRead - offset);
|
|
196
|
+
}
|
|
197
|
+
fsyncSync(tempFd);
|
|
198
|
+
}
|
|
199
|
+
catch (error) {
|
|
200
|
+
copyError = error;
|
|
201
|
+
}
|
|
202
|
+
finally {
|
|
203
|
+
closeSync(sourceFd);
|
|
204
|
+
if (tempFd !== undefined)
|
|
205
|
+
closeSync(tempFd);
|
|
206
|
+
}
|
|
207
|
+
if (copyError !== undefined) {
|
|
208
|
+
try {
|
|
209
|
+
if (existsSync(temp))
|
|
210
|
+
unlinkSync(temp);
|
|
211
|
+
}
|
|
212
|
+
catch {
|
|
213
|
+
// Preserve the source/copy failure; cleanup is best-effort.
|
|
214
|
+
}
|
|
215
|
+
throw copyError;
|
|
216
|
+
}
|
|
217
|
+
try {
|
|
218
|
+
if (existsSync(destination)) {
|
|
219
|
+
const existing = lstatSync(destination);
|
|
220
|
+
if (!existing.isFile() || existing.isSymbolicLink())
|
|
221
|
+
throw new Error('memory_graph_archive_path_rejected');
|
|
222
|
+
unlinkSync(temp);
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
// A same-directory hard link publishes without replacing a path created by a concurrent process.
|
|
226
|
+
linkSync(temp, destination);
|
|
227
|
+
unlinkSync(temp);
|
|
228
|
+
}
|
|
229
|
+
catch (error) {
|
|
230
|
+
try {
|
|
231
|
+
if (existsSync(temp))
|
|
232
|
+
unlinkSync(temp);
|
|
233
|
+
}
|
|
234
|
+
catch {
|
|
235
|
+
// Preserve the publication failure; cleanup is best-effort.
|
|
236
|
+
}
|
|
237
|
+
throw error;
|
|
238
|
+
}
|
|
118
239
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
type GitWorkspaceStatus = 'git' | 'non_git' | 'unknown';
|
|
2
|
+
export declare const NON_GIT_WORKSPACE_NOTICE_THROTTLE_MS: number;
|
|
3
|
+
export interface NonGitWorkspaceNoticeOptions {
|
|
4
|
+
cwd?: string;
|
|
5
|
+
statePath?: string;
|
|
6
|
+
now?: () => number;
|
|
7
|
+
throttleMs?: number;
|
|
8
|
+
detect?: (cwd: string) => GitWorkspaceStatus;
|
|
9
|
+
write?: (line: string) => void;
|
|
10
|
+
}
|
|
11
|
+
interface NonGitWorkspaceNoticeResult {
|
|
12
|
+
status: GitWorkspaceStatus;
|
|
13
|
+
emitted: boolean;
|
|
14
|
+
workspaceHash?: string;
|
|
15
|
+
}
|
|
16
|
+
type GitProbe = (file: string, args: readonly string[], options: {
|
|
17
|
+
encoding: 'utf8';
|
|
18
|
+
stdio: readonly ['ignore', 'pipe', 'pipe'];
|
|
19
|
+
timeout: number;
|
|
20
|
+
windowsHide: true;
|
|
21
|
+
}) => string;
|
|
22
|
+
export declare function detectGitWorkspace(cwd?: string, gitProbe?: GitProbe): GitWorkspaceStatus;
|
|
23
|
+
export declare function maybeEmitNonGitWorkspaceNotice(options?: NonGitWorkspaceNoticeOptions): NonGitWorkspaceNoticeResult;
|
|
24
|
+
export {};
|