@evomap/evolver-cli 2.0.0-beta.0 → 2.0.0-beta.10
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.d.ts +6 -0
- package/dist/autoDistillLlm.js +44 -7
- package/dist/autoexec.d.ts +14 -12
- package/dist/autoexec.js +84 -34
- package/dist/autoexecConfig.d.ts +10 -0
- package/dist/autoexecConfig.js +68 -0
- package/dist/cli.js +12 -5
- package/dist/cliContracts.js +30 -3
- 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 +33 -0
- package/dist/dashboard.js +352 -0
- package/dist/dispatch.d.ts +10 -1
- package/dist/dispatch.js +40 -2
- package/dist/distillAdmission.d.ts +13 -0
- package/dist/distillAdmission.js +35 -0
- package/dist/distillObserver.js +6 -8
- package/dist/distillPrimitives.d.ts +9 -7
- package/dist/distillPrimitives.js +65 -12
- package/dist/doctor.d.ts +2 -0
- package/dist/doctor.js +49 -3
- package/dist/index.d.ts +8 -2
- package/dist/index.js +350 -42
- package/dist/issueReport.d.ts +7 -0
- package/dist/issueReport.js +291 -0
- 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 +401 -0
- package/dist/materialSnapshot.d.ts +54 -0
- package/dist/materialSnapshot.js +370 -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 +12 -2
- package/dist/recipe.js +381 -8
- package/dist/reuse.d.ts +5 -3
- package/dist/reuse.js +74 -6
- 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 +11 -1
- package/dist/setupHooks.js +235 -16
- 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 +38 -0
- package/dist/sync.js +1981 -0
- package/dist/trajectoryExport.js +23 -12
- package/dist/v1Compat.d.ts +24 -0
- package/dist/v1Compat.js +249 -0
- package/dist/version.js +2 -0
- package/dist/workflow.d.ts +39 -0
- package/dist/workflow.js +386 -0
- package/dist/workflowRuntime.d.ts +66 -0
- package/dist/workflowRuntime.js +631 -0
- package/package.json +12 -6
|
@@ -0,0 +1,370 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { hub, schema } from '@evomap/evolver-core';
|
|
3
|
+
import { summarizeSessionEvidence, } from '@evomap/evolver-runtime-adapters';
|
|
4
|
+
import { parseRuntimeSessionSources } from './runtimeSessionSource.js';
|
|
5
|
+
export const MATERIAL_RUNTIME_SESSION_SNAPSHOT_SCHEMA = 'evolver.material.runtime_session_snapshot.v1';
|
|
6
|
+
const DEFAULT_MATERIAL_SNAPSHOT_MAX_CHARS = 24 * 1024;
|
|
7
|
+
const SNAPSHOT_AGENT_MAX_CHARS = 64;
|
|
8
|
+
const SNAPSHOT_IDENTITY_MAX_CHARS = 256;
|
|
9
|
+
const SNAPSHOT_SOURCE_MAX_COUNT = 32;
|
|
10
|
+
const SNAPSHOT_TURN_MAX_COUNT = 256;
|
|
11
|
+
function isRecord(value) {
|
|
12
|
+
return !!value && typeof value === 'object' && !Array.isArray(value);
|
|
13
|
+
}
|
|
14
|
+
function trimText(value, remaining) {
|
|
15
|
+
if (remaining <= 0)
|
|
16
|
+
return { text: '', used: 0, truncated: value.length > 0 };
|
|
17
|
+
const redacted = hub.redactString(value).replace(/\s+/g, ' ').trim();
|
|
18
|
+
if (redacted.length <= remaining)
|
|
19
|
+
return { text: redacted, used: redacted.length, truncated: false };
|
|
20
|
+
return { text: redacted.slice(0, remaining), used: remaining, truncated: true };
|
|
21
|
+
}
|
|
22
|
+
function snapshotTurnText(turn) {
|
|
23
|
+
return turn.text || turn.errorMessage || turn.toolResult || '';
|
|
24
|
+
}
|
|
25
|
+
function fitsInline(snapshot) {
|
|
26
|
+
return Buffer.byteLength(JSON.stringify(snapshot), 'utf8') <= schema.MATERIAL_PAYLOAD_INLINE_MAX_BYTES;
|
|
27
|
+
}
|
|
28
|
+
function snapshotIdentity(value, maxChars) {
|
|
29
|
+
return hub.redactString(value).replace(/\s+/g, ' ').trim().slice(0, maxChars);
|
|
30
|
+
}
|
|
31
|
+
function appendEvidenceAggregate(aggregate, summary) {
|
|
32
|
+
const coverageCounts = aggregate
|
|
33
|
+
? { ...aggregate.coverageCounts }
|
|
34
|
+
: { complete: 0, partial: 0, empty: 0 };
|
|
35
|
+
coverageCounts[summary.coverage] += 1;
|
|
36
|
+
const counts = {};
|
|
37
|
+
for (const key of EVIDENCE_COUNT_KEYS) {
|
|
38
|
+
counts[key] = (aggregate?.counts[key] ?? 0) + summary.counts[key];
|
|
39
|
+
}
|
|
40
|
+
const gapCodes = [];
|
|
41
|
+
if (coverageCounts.empty > 0)
|
|
42
|
+
gapCodes.push('empty_session');
|
|
43
|
+
if (counts.missingToolResults > 0)
|
|
44
|
+
gapCodes.push('missing_tool_result');
|
|
45
|
+
if (counts.unmatchedToolResults > 0)
|
|
46
|
+
gapCodes.push('unmatched_tool_result');
|
|
47
|
+
return {
|
|
48
|
+
sourceCount: (aggregate?.sourceCount ?? 0) + 1,
|
|
49
|
+
coverageCounts,
|
|
50
|
+
counts,
|
|
51
|
+
gapCodes,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
const EVIDENCE_COUNT_KEYS = [
|
|
55
|
+
'nonMetaTurns',
|
|
56
|
+
'toolCalls',
|
|
57
|
+
'toolResults',
|
|
58
|
+
'matchedToolResults',
|
|
59
|
+
'missingToolResults',
|
|
60
|
+
'unmatchedToolResults',
|
|
61
|
+
'failedToolResults',
|
|
62
|
+
];
|
|
63
|
+
const EVIDENCE_GAP_CODES = new Set([
|
|
64
|
+
'empty_session',
|
|
65
|
+
'missing_tool_result',
|
|
66
|
+
'unmatched_tool_result',
|
|
67
|
+
]);
|
|
68
|
+
function evidenceSummaryFromSnapshot(value) {
|
|
69
|
+
if (!isRecord(value) || !isRecord(value['counts']) || !Array.isArray(value['gapCodes']))
|
|
70
|
+
return null;
|
|
71
|
+
const coverage = value['coverage'];
|
|
72
|
+
if (coverage !== 'complete' && coverage !== 'partial' && coverage !== 'empty')
|
|
73
|
+
return null;
|
|
74
|
+
const counts = {};
|
|
75
|
+
for (const key of EVIDENCE_COUNT_KEYS) {
|
|
76
|
+
const count = value['counts'][key];
|
|
77
|
+
if (!Number.isSafeInteger(count) || count < 0)
|
|
78
|
+
return null;
|
|
79
|
+
counts[key] = count;
|
|
80
|
+
}
|
|
81
|
+
const gapCodes = value['gapCodes'];
|
|
82
|
+
if (!gapCodes.every((gap) => (typeof gap === 'string' && EVIDENCE_GAP_CODES.has(gap))))
|
|
83
|
+
return null;
|
|
84
|
+
if (new Set(gapCodes).size !== gapCodes.length
|
|
85
|
+
|| counts.toolCalls + counts.toolResults > counts.nonMetaTurns
|
|
86
|
+
|| counts.matchedToolResults > counts.toolCalls
|
|
87
|
+
|| counts.matchedToolResults > counts.toolResults
|
|
88
|
+
|| counts.missingToolResults !== counts.toolCalls - counts.matchedToolResults
|
|
89
|
+
|| counts.unmatchedToolResults !== counts.toolResults - counts.matchedToolResults
|
|
90
|
+
|| counts.failedToolResults > counts.toolResults)
|
|
91
|
+
return null;
|
|
92
|
+
const expectedGaps = [];
|
|
93
|
+
if (counts.nonMetaTurns === 0)
|
|
94
|
+
expectedGaps.push('empty_session');
|
|
95
|
+
else {
|
|
96
|
+
if (counts.missingToolResults > 0)
|
|
97
|
+
expectedGaps.push('missing_tool_result');
|
|
98
|
+
if (counts.unmatchedToolResults > 0)
|
|
99
|
+
expectedGaps.push('unmatched_tool_result');
|
|
100
|
+
}
|
|
101
|
+
const expectedCoverage = counts.nonMetaTurns === 0
|
|
102
|
+
? 'empty'
|
|
103
|
+
: expectedGaps.length > 0 ? 'partial' : 'complete';
|
|
104
|
+
if (coverage !== expectedCoverage
|
|
105
|
+
|| gapCodes.length !== expectedGaps.length
|
|
106
|
+
|| gapCodes.some((gap, index) => gap !== expectedGaps[index]))
|
|
107
|
+
return null;
|
|
108
|
+
return { coverage, counts, gapCodes: [...gapCodes] };
|
|
109
|
+
}
|
|
110
|
+
function evidenceAggregateFromSnapshot(value) {
|
|
111
|
+
if (!isRecord(value)
|
|
112
|
+
|| !Number.isSafeInteger(value['sourceCount'])
|
|
113
|
+
|| value['sourceCount'] <= 0
|
|
114
|
+
|| !isRecord(value['coverageCounts'])
|
|
115
|
+
|| !isRecord(value['counts'])
|
|
116
|
+
|| !Array.isArray(value['gapCodes']))
|
|
117
|
+
return null;
|
|
118
|
+
const sourceCount = value['sourceCount'];
|
|
119
|
+
const coverageCounts = {};
|
|
120
|
+
for (const coverage of ['complete', 'partial', 'empty']) {
|
|
121
|
+
const count = value['coverageCounts'][coverage];
|
|
122
|
+
if (!Number.isSafeInteger(count) || count < 0)
|
|
123
|
+
return null;
|
|
124
|
+
coverageCounts[coverage] = count;
|
|
125
|
+
}
|
|
126
|
+
if (coverageCounts.complete + coverageCounts.partial + coverageCounts.empty !== sourceCount)
|
|
127
|
+
return null;
|
|
128
|
+
const counts = {};
|
|
129
|
+
for (const key of EVIDENCE_COUNT_KEYS) {
|
|
130
|
+
const count = value['counts'][key];
|
|
131
|
+
if (!Number.isSafeInteger(count) || count < 0)
|
|
132
|
+
return null;
|
|
133
|
+
counts[key] = count;
|
|
134
|
+
}
|
|
135
|
+
const gapCodes = value['gapCodes'];
|
|
136
|
+
if (!gapCodes.every((gap) => (typeof gap === 'string' && EVIDENCE_GAP_CODES.has(gap))) || new Set(gapCodes).size !== gapCodes.length
|
|
137
|
+
|| counts.toolCalls + counts.toolResults > counts.nonMetaTurns
|
|
138
|
+
|| counts.matchedToolResults > counts.toolCalls
|
|
139
|
+
|| counts.matchedToolResults > counts.toolResults
|
|
140
|
+
|| counts.missingToolResults !== counts.toolCalls - counts.matchedToolResults
|
|
141
|
+
|| counts.unmatchedToolResults !== counts.toolResults - counts.matchedToolResults
|
|
142
|
+
|| counts.failedToolResults > counts.toolResults)
|
|
143
|
+
return null;
|
|
144
|
+
const nonEmptySourceCount = coverageCounts.complete + coverageCounts.partial;
|
|
145
|
+
const structuralGapCount = counts.missingToolResults + counts.unmatchedToolResults;
|
|
146
|
+
if (counts.nonMetaTurns < nonEmptySourceCount
|
|
147
|
+
|| (coverageCounts.empty === sourceCount && counts.nonMetaTurns !== 0)
|
|
148
|
+
|| (coverageCounts.partial > 0) !== (structuralGapCount > 0)
|
|
149
|
+
|| structuralGapCount < coverageCounts.partial)
|
|
150
|
+
return null;
|
|
151
|
+
const expectedGaps = [];
|
|
152
|
+
if (coverageCounts.empty > 0)
|
|
153
|
+
expectedGaps.push('empty_session');
|
|
154
|
+
if (counts.missingToolResults > 0)
|
|
155
|
+
expectedGaps.push('missing_tool_result');
|
|
156
|
+
if (counts.unmatchedToolResults > 0)
|
|
157
|
+
expectedGaps.push('unmatched_tool_result');
|
|
158
|
+
if (gapCodes.length !== expectedGaps.length
|
|
159
|
+
|| gapCodes.some((gap, index) => gap !== expectedGaps[index]))
|
|
160
|
+
return null;
|
|
161
|
+
return { sourceCount, coverageCounts, counts, gapCodes: [...gapCodes] };
|
|
162
|
+
}
|
|
163
|
+
export function buildRuntimeSessionMaterialSnapshot(sources, maxChars = DEFAULT_MATERIAL_SNAPSHOT_MAX_CHARS) {
|
|
164
|
+
const safeMaxChars = Number.isFinite(maxChars)
|
|
165
|
+
? Math.max(0, Math.min(Math.trunc(maxChars), DEFAULT_MATERIAL_SNAPSHOT_MAX_CHARS))
|
|
166
|
+
: 0;
|
|
167
|
+
let remaining = safeMaxChars;
|
|
168
|
+
let truncated = false;
|
|
169
|
+
let retainedTurnCount = 0;
|
|
170
|
+
let omittedEvidenceAggregate;
|
|
171
|
+
const snapshotSources = [];
|
|
172
|
+
for (const source of sources) {
|
|
173
|
+
const evidenceSummary = summarizeSessionEvidence({ turns: source.turns });
|
|
174
|
+
if (snapshotSources.length >= SNAPSHOT_SOURCE_MAX_COUNT) {
|
|
175
|
+
omittedEvidenceAggregate = appendEvidenceAggregate(omittedEvidenceAggregate, evidenceSummary);
|
|
176
|
+
truncated = true;
|
|
177
|
+
continue;
|
|
178
|
+
}
|
|
179
|
+
const turns = [];
|
|
180
|
+
for (const turn of source.turns) {
|
|
181
|
+
if (retainedTurnCount >= SNAPSHOT_TURN_MAX_COUNT) {
|
|
182
|
+
truncated = true;
|
|
183
|
+
break;
|
|
184
|
+
}
|
|
185
|
+
const rawText = snapshotTurnText(turn);
|
|
186
|
+
const trimmed = trimText(rawText, remaining);
|
|
187
|
+
remaining -= trimmed.used;
|
|
188
|
+
truncated = truncated || trimmed.truncated;
|
|
189
|
+
if (trimmed.text.length > 0) {
|
|
190
|
+
retainedTurnCount += 1;
|
|
191
|
+
turns.push({
|
|
192
|
+
role: turn.role,
|
|
193
|
+
text: trimmed.text,
|
|
194
|
+
...(turn.isMeta ? { isMeta: true } : {}),
|
|
195
|
+
...(turn.toolName ? { toolName: hub.redactString(turn.toolName).slice(0, 120) } : {}),
|
|
196
|
+
...(turn.errorMessage && trimmed.text ? { errorMessage: trimmed.text } : {}),
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
if (remaining <= 0) {
|
|
200
|
+
truncated = true;
|
|
201
|
+
break;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
const safeSessionId = source.sessionId
|
|
205
|
+
? snapshotIdentity(source.sessionId, SNAPSHOT_IDENTITY_MAX_CHARS)
|
|
206
|
+
: '';
|
|
207
|
+
snapshotSources.push({
|
|
208
|
+
agent: snapshotIdentity(source.agent, SNAPSHOT_AGENT_MAX_CHARS) || 'unknown',
|
|
209
|
+
label: snapshotIdentity(source.label, SNAPSHOT_IDENTITY_MAX_CHARS) || 'unknown',
|
|
210
|
+
...(safeSessionId ? { sessionId: safeSessionId } : {}),
|
|
211
|
+
evidenceSummary,
|
|
212
|
+
turns,
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
const snapshot = {
|
|
216
|
+
schema: MATERIAL_RUNTIME_SESSION_SNAPSHOT_SCHEMA,
|
|
217
|
+
sourceKind: 'runtime_session',
|
|
218
|
+
kind: 'session_log',
|
|
219
|
+
sources: snapshotSources,
|
|
220
|
+
sourceCount: sources.length,
|
|
221
|
+
omittedSourceCount: omittedEvidenceAggregate?.sourceCount ?? 0,
|
|
222
|
+
...(omittedEvidenceAggregate ? { omittedEvidenceAggregate } : {}),
|
|
223
|
+
truncated: truncated || omittedEvidenceAggregate !== undefined,
|
|
224
|
+
maxChars: safeMaxChars,
|
|
225
|
+
};
|
|
226
|
+
// Source and turn caps make this loop constant-bounded even for very large Cursor databases.
|
|
227
|
+
while (!fitsInline(snapshot) && snapshot.sources.length > 0) {
|
|
228
|
+
let sourceWithTurns = snapshot.sources.length - 1;
|
|
229
|
+
while (sourceWithTurns >= 0 && snapshot.sources[sourceWithTurns]?.turns.length === 0) {
|
|
230
|
+
sourceWithTurns -= 1;
|
|
231
|
+
}
|
|
232
|
+
if (sourceWithTurns >= 0)
|
|
233
|
+
snapshot.sources[sourceWithTurns].turns.pop();
|
|
234
|
+
else {
|
|
235
|
+
const omitted = snapshot.sources.pop();
|
|
236
|
+
snapshot.omittedEvidenceAggregate = appendEvidenceAggregate(snapshot.omittedEvidenceAggregate, omitted.evidenceSummary);
|
|
237
|
+
snapshot.omittedSourceCount += 1;
|
|
238
|
+
}
|
|
239
|
+
snapshot.truncated = true;
|
|
240
|
+
}
|
|
241
|
+
return snapshot;
|
|
242
|
+
}
|
|
243
|
+
function sourceFromSnapshot(value) {
|
|
244
|
+
if (!isRecord(value))
|
|
245
|
+
return null;
|
|
246
|
+
const agent = typeof value['agent'] === 'string' ? value['agent'] : '';
|
|
247
|
+
const label = typeof value['label'] === 'string' ? value['label'] : '';
|
|
248
|
+
const turnsRaw = Array.isArray(value['turns']) ? value['turns'] : [];
|
|
249
|
+
if (!agent || !label)
|
|
250
|
+
return null;
|
|
251
|
+
const turns = turnsRaw
|
|
252
|
+
.map((turn) => {
|
|
253
|
+
if (!isRecord(turn))
|
|
254
|
+
return null;
|
|
255
|
+
const role = turn['role'];
|
|
256
|
+
const text = turn['text'];
|
|
257
|
+
if ((role !== 'user' && role !== 'assistant' && role !== 'tool' && role !== 'system') || typeof text !== 'string')
|
|
258
|
+
return null;
|
|
259
|
+
const toolName = typeof turn['toolName'] === 'string' && turn['toolName'].trim() ? turn['toolName'] : undefined;
|
|
260
|
+
const errorMessage = typeof turn['errorMessage'] === 'string' && turn['errorMessage'].trim() ? turn['errorMessage'] : undefined;
|
|
261
|
+
return {
|
|
262
|
+
role,
|
|
263
|
+
text,
|
|
264
|
+
isMeta: turn['isMeta'] === true,
|
|
265
|
+
...(toolName ? { toolName } : {}),
|
|
266
|
+
...(errorMessage ? { errorMessage } : {}),
|
|
267
|
+
};
|
|
268
|
+
})
|
|
269
|
+
.filter((turn) => turn !== null);
|
|
270
|
+
if (turns.length === 0)
|
|
271
|
+
return null;
|
|
272
|
+
const sessionId = typeof value['sessionId'] === 'string' && value['sessionId'].trim() ? value['sessionId'] : undefined;
|
|
273
|
+
return {
|
|
274
|
+
agent,
|
|
275
|
+
label,
|
|
276
|
+
...(sessionId ? { sessionId } : {}),
|
|
277
|
+
turns,
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
export function runtimeSessionSourcesFromMaterialPayload(payload) {
|
|
281
|
+
if (!isRecord(payload))
|
|
282
|
+
return [];
|
|
283
|
+
if (payload['schema'] !== MATERIAL_RUNTIME_SESSION_SNAPSHOT_SCHEMA)
|
|
284
|
+
return [];
|
|
285
|
+
if (payload['sourceKind'] !== 'runtime_session' || payload['kind'] !== 'session_log')
|
|
286
|
+
return [];
|
|
287
|
+
const sources = Array.isArray(payload['sources']) ? payload['sources'] : [];
|
|
288
|
+
return sources
|
|
289
|
+
.map(sourceFromSnapshot)
|
|
290
|
+
.filter((source) => source !== null);
|
|
291
|
+
}
|
|
292
|
+
export function runtimeSessionEvidenceSummariesFromMaterialPayload(payload) {
|
|
293
|
+
if (!isRecord(payload))
|
|
294
|
+
return null;
|
|
295
|
+
if (payload['schema'] !== MATERIAL_RUNTIME_SESSION_SNAPSHOT_SCHEMA)
|
|
296
|
+
return null;
|
|
297
|
+
if (payload['sourceKind'] !== 'runtime_session' || payload['kind'] !== 'session_log')
|
|
298
|
+
return null;
|
|
299
|
+
const sources = Array.isArray(payload['sources']) ? payload['sources'] : [];
|
|
300
|
+
const hasCountMetadata = payload['sourceCount'] !== undefined || payload['omittedSourceCount'] !== undefined;
|
|
301
|
+
const sourceCount = hasCountMetadata ? payload['sourceCount'] : sources.length;
|
|
302
|
+
const omittedSourceCount = hasCountMetadata ? payload['omittedSourceCount'] : 0;
|
|
303
|
+
if (!Number.isSafeInteger(sourceCount)
|
|
304
|
+
|| sourceCount < sources.length
|
|
305
|
+
|| !Number.isSafeInteger(omittedSourceCount)
|
|
306
|
+
|| omittedSourceCount < 0
|
|
307
|
+
|| omittedSourceCount !== sourceCount - sources.length)
|
|
308
|
+
return null;
|
|
309
|
+
const omittedEvidenceAggregate = payload['omittedEvidenceAggregate'] === undefined
|
|
310
|
+
? undefined
|
|
311
|
+
: evidenceAggregateFromSnapshot(payload['omittedEvidenceAggregate']);
|
|
312
|
+
if (omittedSourceCount > 0) {
|
|
313
|
+
if (!omittedEvidenceAggregate || omittedEvidenceAggregate.sourceCount !== omittedSourceCount)
|
|
314
|
+
return null;
|
|
315
|
+
}
|
|
316
|
+
else if (payload['omittedEvidenceAggregate'] !== undefined)
|
|
317
|
+
return null;
|
|
318
|
+
const summaries = sources.flatMap((source) => {
|
|
319
|
+
if (!isRecord(source)
|
|
320
|
+
|| typeof source['agent'] !== 'string'
|
|
321
|
+
|| !source['agent'].trim()
|
|
322
|
+
|| typeof source['label'] !== 'string'
|
|
323
|
+
|| !source['label'].trim())
|
|
324
|
+
return [];
|
|
325
|
+
const summary = evidenceSummaryFromSnapshot(source['evidenceSummary']);
|
|
326
|
+
if (!summary)
|
|
327
|
+
return [];
|
|
328
|
+
const sessionId = typeof source['sessionId'] === 'string' && source['sessionId'].trim()
|
|
329
|
+
? source['sessionId']
|
|
330
|
+
: undefined;
|
|
331
|
+
return [{
|
|
332
|
+
agent: source['agent'],
|
|
333
|
+
label: source['label'],
|
|
334
|
+
...(sessionId ? { sessionId } : {}),
|
|
335
|
+
evidenceSummary: summary,
|
|
336
|
+
}];
|
|
337
|
+
});
|
|
338
|
+
if (hasCountMetadata && summaries.length !== sources.length)
|
|
339
|
+
return null;
|
|
340
|
+
return {
|
|
341
|
+
sourceCount: sourceCount,
|
|
342
|
+
omittedSourceCount: omittedSourceCount,
|
|
343
|
+
summaries,
|
|
344
|
+
...(omittedEvidenceAggregate ? { omittedEvidenceAggregate } : {}),
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
export function materialHasRuntimeSessionSnapshot(material) {
|
|
348
|
+
return runtimeSessionSourcesFromMaterialPayload(material.payload).length > 0;
|
|
349
|
+
}
|
|
350
|
+
export function materialSourceAvailable(material) {
|
|
351
|
+
return existsSync(material.sourcePath);
|
|
352
|
+
}
|
|
353
|
+
export function runtimeSessionSourcesForMaterial(material, readSource) {
|
|
354
|
+
let sourceError;
|
|
355
|
+
try {
|
|
356
|
+
const sources = parseRuntimeSessionSources(material.sourcePath, readSource);
|
|
357
|
+
const sourcesWithTurns = sources.filter((source) => source.turns.length > 0);
|
|
358
|
+
if (sourcesWithTurns.length > 0)
|
|
359
|
+
return sourcesWithTurns;
|
|
360
|
+
}
|
|
361
|
+
catch (error) {
|
|
362
|
+
sourceError = error;
|
|
363
|
+
}
|
|
364
|
+
const snapshotSources = runtimeSessionSourcesFromMaterialPayload(material.payload);
|
|
365
|
+
if (snapshotSources.length > 0)
|
|
366
|
+
return snapshotSources;
|
|
367
|
+
if (sourceError)
|
|
368
|
+
throw sourceError;
|
|
369
|
+
return [];
|
|
370
|
+
}
|
|
@@ -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>;
|