@evomap/evolver-cli 2.0.0-beta.0 → 2.0.0-beta.2
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/atp.js +4 -2
- package/dist/autoDistillLlm.js +4 -1
- package/dist/autoexec.d.ts +4 -1
- package/dist/autoexec.js +23 -5
- 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 +59 -1
- package/dist/cycleConsumer.js +382 -5
- package/dist/dashboard.d.ts +21 -0
- package/dist/dashboard.js +173 -0
- package/dist/dispatch.d.ts +1 -0
- package/dist/dispatch.js +27 -2
- package/dist/distillObserver.js +2 -2
- package/dist/distillPrimitives.d.ts +1 -1
- package/dist/distillPrimitives.js +29 -2
- package/dist/doctor.js +15 -3
- package/dist/index.d.ts +6 -1
- package/dist/index.js +251 -30
- package/dist/lifecycle.js +6 -2
- 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/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/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/dist/version.js +2 -0
- package/package.json +8 -6
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { assetstore, events, material as materialNs, schema } from '@evomap/evolver-core';
|
|
2
|
+
declare const GROUP = "material.package_gene";
|
|
3
|
+
type PackageBlocker = 'usage' | 'material_not_found' | 'unsupported_material' | 'source_unavailable' | 'draft_unavailable' | 'gene_intake_rejected' | 'missing_capsule_evidence' | 'gene_not_found' | 'capsule_not_found' | 'capsule_gene_mismatch' | 'publish_bundle_invalid' | 'publish_bundle_blocked' | 'cycle_not_solidified' | 'write_failed';
|
|
4
|
+
interface MaterialPackageOptions {
|
|
5
|
+
materialId: string;
|
|
6
|
+
write: boolean;
|
|
7
|
+
json: boolean;
|
|
8
|
+
}
|
|
9
|
+
export interface MaterialGenePackageDeps {
|
|
10
|
+
materialStore?: materialNs.MaterialStore;
|
|
11
|
+
store?: assetstore.AssetStoreProvider;
|
|
12
|
+
review?: assetstore.ReviewLedger;
|
|
13
|
+
ingestor?: events.Ingestor;
|
|
14
|
+
readSource?: (path: string) => string;
|
|
15
|
+
env?: NodeJS.ProcessEnv;
|
|
16
|
+
stdout?: (line: string) => void;
|
|
17
|
+
stderr?: (line: string) => void;
|
|
18
|
+
}
|
|
19
|
+
interface PackageAssetSummary {
|
|
20
|
+
assetId: string;
|
|
21
|
+
id?: string;
|
|
22
|
+
type: 'Gene' | 'Capsule';
|
|
23
|
+
}
|
|
24
|
+
type PackageReviewState = 'quarantined' | 'approved' | 'rejected' | 'default_approved' | 'unproven_preview';
|
|
25
|
+
interface MaterialGenePackageResult {
|
|
26
|
+
ok: boolean;
|
|
27
|
+
group: typeof GROUP;
|
|
28
|
+
mode: 'preview' | 'write';
|
|
29
|
+
materialId?: string;
|
|
30
|
+
sourceKind?: schema.Material['sourceKind'];
|
|
31
|
+
kind?: schema.Material['kind'];
|
|
32
|
+
publishable: boolean;
|
|
33
|
+
blockers: PackageBlocker[];
|
|
34
|
+
gene?: PackageAssetSummary & {
|
|
35
|
+
reviewState?: PackageReviewState;
|
|
36
|
+
written?: boolean;
|
|
37
|
+
};
|
|
38
|
+
capsule?: PackageAssetSummary & {
|
|
39
|
+
outcomeStatus?: string;
|
|
40
|
+
};
|
|
41
|
+
publishCommand?: string;
|
|
42
|
+
sourceCount?: number;
|
|
43
|
+
signalCount?: number;
|
|
44
|
+
message?: string;
|
|
45
|
+
}
|
|
46
|
+
type MaterialGenePackageBuildResult = {
|
|
47
|
+
result: MaterialGenePackageResult;
|
|
48
|
+
code: number;
|
|
49
|
+
};
|
|
50
|
+
export declare function buildMaterialGenePackage(opts: MaterialPackageOptions, deps?: MaterialGenePackageDeps): Promise<MaterialGenePackageBuildResult>;
|
|
51
|
+
export declare function runMaterialCommand(argv: readonly string[], deps?: MaterialGenePackageDeps): Promise<number>;
|
|
52
|
+
export {};
|
|
@@ -0,0 +1,404 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { assetstore, algo, events, hub, material as materialNs, schema, signals } from '@evomap/evolver-core';
|
|
3
|
+
import { runtimeSessionSourcesForMaterial, runtimeSessionSourcesFromMaterialPayload } from './materialSnapshot.js';
|
|
4
|
+
import { assessDraftAdmission, draftGeneCandidate } from './distillPrimitives.js';
|
|
5
|
+
import { reviewLedgerForStore } from './reviewFilter.js';
|
|
6
|
+
import { buildPublishBundle } from './cliContracts.js';
|
|
7
|
+
const GROUP = 'material.package_gene';
|
|
8
|
+
const USAGE = 'usage: evolver material package-gene --material <id> [--write] [--json]';
|
|
9
|
+
function parseMaterialArgs(argv) {
|
|
10
|
+
if (argv.includes('--help') || argv.includes('-h'))
|
|
11
|
+
return { ok: false, message: USAGE };
|
|
12
|
+
const unknown = argv.find((arg) => arg.startsWith('--') && !['--material', '--write', '--json'].includes(arg) && !arg.startsWith('--material='));
|
|
13
|
+
if (unknown)
|
|
14
|
+
return { ok: false, message: `unsupported material argument: ${unknown}` };
|
|
15
|
+
const materialId = flagValue(argv, '--material');
|
|
16
|
+
if (!materialId)
|
|
17
|
+
return { ok: false, message: 'material package-gene requires --material <id>' };
|
|
18
|
+
return { ok: true, value: { materialId, write: argv.includes('--write'), json: argv.includes('--json') } };
|
|
19
|
+
}
|
|
20
|
+
function flagValue(argv, flag) {
|
|
21
|
+
for (let i = 0; i < argv.length; i += 1) {
|
|
22
|
+
const token = argv[i];
|
|
23
|
+
if (token === flag) {
|
|
24
|
+
const next = argv[i + 1];
|
|
25
|
+
return next && !next.startsWith('--') ? next.trim() : undefined;
|
|
26
|
+
}
|
|
27
|
+
if (token?.startsWith(`${flag}=`)) {
|
|
28
|
+
const value = token.slice(flag.length + 1).trim();
|
|
29
|
+
return value || undefined;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
function assetIdOf(asset) {
|
|
35
|
+
return String(asset.asset_id);
|
|
36
|
+
}
|
|
37
|
+
function assetLogicalId(asset) {
|
|
38
|
+
const value = asset['id'];
|
|
39
|
+
return typeof value === 'string' && value.trim() ? value : undefined;
|
|
40
|
+
}
|
|
41
|
+
function summarizeGene(asset, review, written, reviewState) {
|
|
42
|
+
const assetId = assetIdOf(asset);
|
|
43
|
+
const record = review.get(assetId);
|
|
44
|
+
return {
|
|
45
|
+
type: 'Gene',
|
|
46
|
+
assetId,
|
|
47
|
+
...(assetLogicalId(asset) ? { id: assetLogicalId(asset) } : {}),
|
|
48
|
+
reviewState: reviewState ?? record?.state ?? 'default_approved',
|
|
49
|
+
...(written !== undefined ? { written } : {}),
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
function summarizeCapsule(asset) {
|
|
53
|
+
const outcome = asset['outcome'] && typeof asset['outcome'] === 'object' ? asset['outcome'] : {};
|
|
54
|
+
const status = typeof outcome['status'] === 'string' ? outcome['status'] : undefined;
|
|
55
|
+
return {
|
|
56
|
+
type: 'Capsule',
|
|
57
|
+
assetId: assetIdOf(asset),
|
|
58
|
+
...(assetLogicalId(asset) ? { id: assetLogicalId(asset) } : {}),
|
|
59
|
+
...(status ? { outcomeStatus: status } : {}),
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
async function findAssetByRef(store, kind, ref) {
|
|
63
|
+
if (!ref)
|
|
64
|
+
return null;
|
|
65
|
+
const direct = await store.get(ref);
|
|
66
|
+
if (direct?.type === kind)
|
|
67
|
+
return direct;
|
|
68
|
+
const rows = await store.list(kind, 10_000);
|
|
69
|
+
return rows.find((row) => row.asset_id === ref || row['id'] === ref) ?? null;
|
|
70
|
+
}
|
|
71
|
+
function terminalForMaterial(rootEvents, materialId) {
|
|
72
|
+
const cycleIds = [];
|
|
73
|
+
for (const event of rootEvents) {
|
|
74
|
+
if (event.type !== 'cycle.consumed')
|
|
75
|
+
continue;
|
|
76
|
+
const payload = event.payload;
|
|
77
|
+
if (payload?.['materialId'] !== materialId)
|
|
78
|
+
continue;
|
|
79
|
+
const value = payload['cycleId'];
|
|
80
|
+
if (typeof value === 'string' && value.trim())
|
|
81
|
+
cycleIds.push(value);
|
|
82
|
+
}
|
|
83
|
+
const defaultCycleId = `autoexec-material-${materialId}`;
|
|
84
|
+
if (!cycleIds.includes(defaultCycleId))
|
|
85
|
+
cycleIds.push(defaultCycleId);
|
|
86
|
+
const cycleIdSet = new Set(cycleIds);
|
|
87
|
+
const producedCapsules = new Map();
|
|
88
|
+
for (const event of rootEvents) {
|
|
89
|
+
if (event.type !== 'capsule.produced' && event.type !== 'evolution_event.projected')
|
|
90
|
+
continue;
|
|
91
|
+
const payload = event.payload;
|
|
92
|
+
if (!payload)
|
|
93
|
+
continue;
|
|
94
|
+
const cycleId = typeof payload['cycleId'] === 'string' ? payload['cycleId'] : undefined;
|
|
95
|
+
if (!cycleId || !cycleIdSet.has(cycleId))
|
|
96
|
+
continue;
|
|
97
|
+
const value = payload['capsuleId'];
|
|
98
|
+
if (typeof value === 'string' && value.trim())
|
|
99
|
+
producedCapsules.set(cycleId, value);
|
|
100
|
+
}
|
|
101
|
+
let terminal = null;
|
|
102
|
+
for (const event of rootEvents) {
|
|
103
|
+
if (event.type !== 'cycle.solidified' && event.type !== 'cycle.failed' && event.type !== 'cycle.aborted')
|
|
104
|
+
continue;
|
|
105
|
+
const payload = event.payload;
|
|
106
|
+
if (!payload)
|
|
107
|
+
continue;
|
|
108
|
+
const cycleId = typeof payload['cycleId'] === 'string' ? payload['cycleId'] : undefined;
|
|
109
|
+
if (!cycleId || !cycleIdSet.has(cycleId))
|
|
110
|
+
continue;
|
|
111
|
+
const geneRef = typeof payload['gene'] === 'string' ? payload['gene'] : undefined;
|
|
112
|
+
const capsuleId = typeof payload['capsuleId'] === 'string' ? payload['capsuleId'] : producedCapsules.get(cycleId);
|
|
113
|
+
terminal = {
|
|
114
|
+
cycleId,
|
|
115
|
+
status: event.type === 'cycle.solidified' ? 'solidified' : event.type === 'cycle.failed' ? 'failed' : 'aborted',
|
|
116
|
+
...(geneRef ? { geneRef } : {}),
|
|
117
|
+
...(capsuleId ? { capsuleId } : {}),
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
return terminal;
|
|
121
|
+
}
|
|
122
|
+
function geneMatchesCapsule(gene, capsule) {
|
|
123
|
+
const capsuleGene = capsule['gene'];
|
|
124
|
+
return capsuleGene === gene.asset_id || capsuleGene === gene['id'];
|
|
125
|
+
}
|
|
126
|
+
function redactRuntimeSessionSources(sources) {
|
|
127
|
+
return sources.map((source) => ({
|
|
128
|
+
...source,
|
|
129
|
+
label: hub.redactString(source.label),
|
|
130
|
+
...(source.sessionId ? { sessionId: hub.redactString(source.sessionId) } : {}),
|
|
131
|
+
turns: source.turns.map((turn) => ({
|
|
132
|
+
...turn,
|
|
133
|
+
text: hub.redactString(turn.text ?? ''),
|
|
134
|
+
...(turn.toolName ? { toolName: hub.redactString(turn.toolName) } : {}),
|
|
135
|
+
...(turn.errorMessage ? { errorMessage: hub.redactString(turn.errorMessage) } : {}),
|
|
136
|
+
...(turn.toolResult ? { toolResult: hub.redactString(turn.toolResult) } : {}),
|
|
137
|
+
})),
|
|
138
|
+
}));
|
|
139
|
+
}
|
|
140
|
+
function packageRuntimeSessionSourcesForMaterial(material, readSource) {
|
|
141
|
+
const snapshotSources = runtimeSessionSourcesFromMaterialPayload(material.payload);
|
|
142
|
+
if (snapshotSources.length > 0)
|
|
143
|
+
return redactRuntimeSessionSources(snapshotSources);
|
|
144
|
+
return redactRuntimeSessionSources(runtimeSessionSourcesForMaterial(material, readSource));
|
|
145
|
+
}
|
|
146
|
+
async function findCapsuleForTerminal(store, terminal) {
|
|
147
|
+
if (terminal.capsuleId)
|
|
148
|
+
return findAssetByRef(store, 'Capsule', terminal.capsuleId);
|
|
149
|
+
const rows = await store.list('Capsule', 10_000);
|
|
150
|
+
return rows.find((capsule) => {
|
|
151
|
+
const capsuleCycleId = capsule['cycleId'] ?? capsule['cycle_id'];
|
|
152
|
+
return typeof capsuleCycleId === 'string' && capsuleCycleId === terminal.cycleId;
|
|
153
|
+
}) ?? null;
|
|
154
|
+
}
|
|
155
|
+
async function draftGeneFromMaterial(material, store, readSource) {
|
|
156
|
+
if (material.sourceKind !== 'runtime_session' || material.kind !== 'session_log') {
|
|
157
|
+
return { blocker: 'unsupported_material', message: 'only runtime session material can be packaged into a Gene' };
|
|
158
|
+
}
|
|
159
|
+
let sources;
|
|
160
|
+
try {
|
|
161
|
+
sources = packageRuntimeSessionSourcesForMaterial(material, readSource);
|
|
162
|
+
}
|
|
163
|
+
catch {
|
|
164
|
+
return { blocker: 'source_unavailable', message: 'material source is unavailable and no usable snapshot exists' };
|
|
165
|
+
}
|
|
166
|
+
if (sources.length === 0)
|
|
167
|
+
return { blocker: 'source_unavailable', message: 'material has no usable runtime session source', sourceCount: 0, signalCount: 0 };
|
|
168
|
+
const existing = (await store.list('Gene', 10_000)).map((g) => ({
|
|
169
|
+
id: typeof g['id'] === 'string' ? String(g['id']) : undefined,
|
|
170
|
+
signals_match: Array.isArray(g['signals_match']) ? g['signals_match'] : [],
|
|
171
|
+
}));
|
|
172
|
+
let signalCount = 0;
|
|
173
|
+
let sawCandidate = false;
|
|
174
|
+
let lastIntakeError = '';
|
|
175
|
+
for (const source of sources) {
|
|
176
|
+
const sigs = signals.extractSignals(source.turns);
|
|
177
|
+
signalCount += sigs.length;
|
|
178
|
+
const candidate = draftGeneCandidate(source.turns, sigs, source.agent);
|
|
179
|
+
if (!candidate)
|
|
180
|
+
continue;
|
|
181
|
+
sawCandidate = true;
|
|
182
|
+
const normalized = algo.intakeGene(candidate, []);
|
|
183
|
+
if (!normalized.ok || !normalized.gene) {
|
|
184
|
+
lastIntakeError = normalized.errors.join('; ') || 'gene intake rejected the candidate';
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
const alreadyStored = await store.get(normalized.gene.asset_id);
|
|
188
|
+
if (alreadyStored?.type === 'Gene') {
|
|
189
|
+
return { gene: alreadyStored, sourceCount: sources.length, signalCount, stored: true };
|
|
190
|
+
}
|
|
191
|
+
const admission = assessDraftAdmission(candidate, existing);
|
|
192
|
+
if (!admission.admit) {
|
|
193
|
+
lastIntakeError = admission.reason ?? 'gene draft admission rejected the candidate';
|
|
194
|
+
continue;
|
|
195
|
+
}
|
|
196
|
+
const intake = algo.intakeGene(candidate, existing);
|
|
197
|
+
if (!intake.ok || !intake.gene) {
|
|
198
|
+
lastIntakeError = intake.errors.join('; ') || 'gene intake rejected the candidate';
|
|
199
|
+
continue;
|
|
200
|
+
}
|
|
201
|
+
return { gene: intake.gene, sourceCount: sources.length, signalCount, stored: false };
|
|
202
|
+
}
|
|
203
|
+
if (sawCandidate) {
|
|
204
|
+
return {
|
|
205
|
+
blocker: 'gene_intake_rejected',
|
|
206
|
+
message: lastIntakeError || 'gene intake rejected every candidate',
|
|
207
|
+
sourceCount: sources.length,
|
|
208
|
+
signalCount,
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
return { blocker: 'draft_unavailable', message: 'material does not contain enough strong signals and strategy turns', sourceCount: sources.length, signalCount };
|
|
212
|
+
}
|
|
213
|
+
async function alreadyAudited(ingestor, assetId) {
|
|
214
|
+
return ingestor.readAll().some((event) => {
|
|
215
|
+
if (event.type !== 'gene.distilled')
|
|
216
|
+
return false;
|
|
217
|
+
const payload = event.payload;
|
|
218
|
+
return payload?.['assetId'] === assetId;
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
async function writeDraftGene(gene, material, store, review, ingestor) {
|
|
222
|
+
const assetId = String(gene.asset_id);
|
|
223
|
+
const existing = await store.get(assetId);
|
|
224
|
+
if (existing?.type === 'Gene') {
|
|
225
|
+
return { gene: existing, written: false };
|
|
226
|
+
}
|
|
227
|
+
if (!await alreadyAudited(ingestor, assetId)) {
|
|
228
|
+
await ingestor.ingest({
|
|
229
|
+
type: 'gene.distilled',
|
|
230
|
+
payload: {
|
|
231
|
+
geneId: gene['id'],
|
|
232
|
+
assetId,
|
|
233
|
+
category: gene['category'],
|
|
234
|
+
source: 'material-package',
|
|
235
|
+
materialId: material.materialId,
|
|
236
|
+
},
|
|
237
|
+
human: { title: `material-packaged gene ${String(gene['id'] ?? assetId)} (UNPROVEN - awaiting review)`, severity: 'info' },
|
|
238
|
+
actor: { kind: 'machine', id: 'material-package' },
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
review.quarantineIfAbsent(assetId, 'material-packaged gene - review before publish/reuse');
|
|
242
|
+
const put = await store.put(gene);
|
|
243
|
+
const stored = await store.get(assetId) ?? gene;
|
|
244
|
+
return { gene: stored, written: put.stored };
|
|
245
|
+
}
|
|
246
|
+
async function validatePublishBundle(gene, capsule, store, env) {
|
|
247
|
+
const bundle = await buildPublishBundle([String(gene.asset_id), String(capsule.asset_id)], { assetStore: store, env });
|
|
248
|
+
if (!bundle.ok)
|
|
249
|
+
return 'publish_bundle_invalid';
|
|
250
|
+
return bundle.blockReasons.length > 0 ? 'publish_bundle_blocked' : null;
|
|
251
|
+
}
|
|
252
|
+
export async function buildMaterialGenePackage(opts, deps = {}) {
|
|
253
|
+
const materialStore = deps.materialStore ?? new materialNs.MaterialStore({ path: events.materialStorePath() });
|
|
254
|
+
const store = deps.store ?? new assetstore.LocalJsonlProvider(events.assetsDir());
|
|
255
|
+
const review = deps.review ?? reviewLedgerForStore(store);
|
|
256
|
+
const ingestor = deps.ingestor ?? new events.Ingestor({ path: events.rootEventsPath() });
|
|
257
|
+
const mode = opts.write ? 'write' : 'preview';
|
|
258
|
+
const material = materialStore.get(opts.materialId);
|
|
259
|
+
if (!material) {
|
|
260
|
+
return {
|
|
261
|
+
code: 1,
|
|
262
|
+
result: { ok: false, group: GROUP, mode, materialId: opts.materialId, publishable: false, blockers: ['material_not_found'], message: 'material not found' },
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
const base = {
|
|
266
|
+
group: GROUP,
|
|
267
|
+
mode,
|
|
268
|
+
materialId: material.materialId,
|
|
269
|
+
sourceKind: material.sourceKind,
|
|
270
|
+
kind: material.kind,
|
|
271
|
+
};
|
|
272
|
+
if (material.sourceKind !== 'runtime_session' || material.kind !== 'session_log') {
|
|
273
|
+
return { code: 1, result: { ok: false, ...base, publishable: false, blockers: ['unsupported_material'], message: 'only runtime session material can be packaged into a Gene' } };
|
|
274
|
+
}
|
|
275
|
+
const terminal = terminalForMaterial(ingestor.readAll(), material.materialId);
|
|
276
|
+
if (terminal) {
|
|
277
|
+
const terminalBase = { ...base, mode: 'preview' };
|
|
278
|
+
if (terminal.status !== 'solidified') {
|
|
279
|
+
return { code: 1, result: { ok: false, ...terminalBase, publishable: false, blockers: ['cycle_not_solidified'], message: 'material terminal cycle did not solidify Capsule evidence' } };
|
|
280
|
+
}
|
|
281
|
+
const capsule = await findCapsuleForTerminal(store, terminal);
|
|
282
|
+
if (!capsule) {
|
|
283
|
+
return { code: 1, result: { ok: false, ...terminalBase, publishable: false, blockers: ['capsule_not_found'], message: 'terminal cycle references a missing capsule' } };
|
|
284
|
+
}
|
|
285
|
+
const capsuleGeneRef = typeof capsule['gene'] === 'string' ? capsule['gene'] : undefined;
|
|
286
|
+
const geneFromCapsule = await findAssetByRef(store, 'Gene', capsuleGeneRef);
|
|
287
|
+
const geneFromTerminal = await findAssetByRef(store, 'Gene', terminal.geneRef);
|
|
288
|
+
const gene = geneFromCapsule ?? (geneFromTerminal && geneMatchesCapsule(geneFromTerminal, capsule) ? geneFromTerminal : null);
|
|
289
|
+
if (!gene) {
|
|
290
|
+
return { code: 1, result: { ok: false, ...terminalBase, capsule: summarizeCapsule(capsule), publishable: false, blockers: ['gene_not_found'], message: 'terminal cycle references a missing Gene asset' } };
|
|
291
|
+
}
|
|
292
|
+
if (!geneMatchesCapsule(gene, capsule)) {
|
|
293
|
+
return { code: 1, result: { ok: false, ...terminalBase, gene: summarizeGene(gene, review), capsule: summarizeCapsule(capsule), publishable: false, blockers: ['capsule_gene_mismatch'], message: 'capsule does not bind to the selected Gene' } };
|
|
294
|
+
}
|
|
295
|
+
const bundleBlocker = await validatePublishBundle(gene, capsule, store, deps.env ?? process.env);
|
|
296
|
+
if (bundleBlocker) {
|
|
297
|
+
return { code: 1, result: { ok: false, ...terminalBase, gene: summarizeGene(gene, review), capsule: summarizeCapsule(capsule), publishable: false, blockers: [bundleBlocker], message: 'Gene + Capsule bundle is not publishable' } };
|
|
298
|
+
}
|
|
299
|
+
const publishCommand = `evolver publish --asset ${gene.asset_id} --asset ${capsule.asset_id} --json`;
|
|
300
|
+
return {
|
|
301
|
+
code: 0,
|
|
302
|
+
result: {
|
|
303
|
+
ok: true,
|
|
304
|
+
...terminalBase,
|
|
305
|
+
gene: summarizeGene(gene, review),
|
|
306
|
+
capsule: summarizeCapsule(capsule),
|
|
307
|
+
publishable: true,
|
|
308
|
+
blockers: [],
|
|
309
|
+
publishCommand,
|
|
310
|
+
},
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
const draft = await draftGeneFromMaterial(material, store, deps.readSource ?? ((path) => readFileSync(path, 'utf8')));
|
|
314
|
+
if ('blocker' in draft) {
|
|
315
|
+
return {
|
|
316
|
+
code: 1,
|
|
317
|
+
result: {
|
|
318
|
+
ok: false,
|
|
319
|
+
...base,
|
|
320
|
+
publishable: false,
|
|
321
|
+
blockers: [draft.blocker],
|
|
322
|
+
message: draft.message,
|
|
323
|
+
...(draft.sourceCount !== undefined ? { sourceCount: draft.sourceCount } : {}),
|
|
324
|
+
...(draft.signalCount !== undefined ? { signalCount: draft.signalCount } : {}),
|
|
325
|
+
},
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
let gene = draft.gene;
|
|
329
|
+
let written;
|
|
330
|
+
if (opts.write) {
|
|
331
|
+
try {
|
|
332
|
+
const write = await writeDraftGene(gene, material, store, review, ingestor);
|
|
333
|
+
gene = write.gene;
|
|
334
|
+
written = write.written;
|
|
335
|
+
}
|
|
336
|
+
catch {
|
|
337
|
+
return { code: 1, result: { ok: false, ...base, publishable: false, blockers: ['write_failed'], message: 'failed to write Gene draft' } };
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
return {
|
|
341
|
+
code: 0,
|
|
342
|
+
result: {
|
|
343
|
+
ok: true,
|
|
344
|
+
...base,
|
|
345
|
+
gene: summarizeGene(gene, review, written, !opts.write && !draft.stored ? 'unproven_preview' : undefined),
|
|
346
|
+
publishable: false,
|
|
347
|
+
blockers: ['missing_capsule_evidence'],
|
|
348
|
+
sourceCount: draft.sourceCount,
|
|
349
|
+
signalCount: draft.signalCount,
|
|
350
|
+
message: 'Gene draft is available, but publish requires terminal Capsule evidence from cycle',
|
|
351
|
+
},
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
function emitResult(result, json, stdout) {
|
|
355
|
+
if (json) {
|
|
356
|
+
stdout(JSON.stringify(result));
|
|
357
|
+
return;
|
|
358
|
+
}
|
|
359
|
+
const status = result.publishable ? 'publishable=true' : `publishable=false blockers=${result.blockers.join(',') || 'none'}`;
|
|
360
|
+
stdout(`material package-gene: material=${result.materialId ?? 'unknown'} mode=${result.mode} ${status}`);
|
|
361
|
+
if (result.gene) {
|
|
362
|
+
const review = result.gene.reviewState ? ` review=${result.gene.reviewState}` : '';
|
|
363
|
+
const written = result.gene.written !== undefined ? ` written=${result.gene.written}` : '';
|
|
364
|
+
stdout(` gene: ${result.gene.id ?? result.gene.assetId} asset=${result.gene.assetId}${review}${written}`);
|
|
365
|
+
}
|
|
366
|
+
if (result.capsule) {
|
|
367
|
+
const outcome = result.capsule.outcomeStatus ? ` outcome=${result.capsule.outcomeStatus}` : '';
|
|
368
|
+
stdout(` capsule: ${result.capsule.id ?? result.capsule.assetId} asset=${result.capsule.assetId}${outcome}`);
|
|
369
|
+
}
|
|
370
|
+
if (result.publishCommand)
|
|
371
|
+
stdout(` publish: ${result.publishCommand}`);
|
|
372
|
+
if (result.message)
|
|
373
|
+
stdout(` note: ${result.message}`);
|
|
374
|
+
}
|
|
375
|
+
function emitUsage(message, json, stdout, stderr) {
|
|
376
|
+
if (message === USAGE) {
|
|
377
|
+
stdout(USAGE);
|
|
378
|
+
return 0;
|
|
379
|
+
}
|
|
380
|
+
if (json)
|
|
381
|
+
stdout(JSON.stringify({ ok: false, group: GROUP, mode: 'preview', publishable: false, blockers: ['usage'], message }));
|
|
382
|
+
else
|
|
383
|
+
stderr(`${message}\n${USAGE}`);
|
|
384
|
+
return 1;
|
|
385
|
+
}
|
|
386
|
+
export async function runMaterialCommand(argv, deps = {}) {
|
|
387
|
+
const stdout = deps.stdout ?? ((line) => { process.stdout.write(`${line}\n`); });
|
|
388
|
+
const stderr = deps.stderr ?? ((line) => { process.stderr.write(`${line}\n`); });
|
|
389
|
+
const sub = argv[0];
|
|
390
|
+
if (sub !== 'package-gene') {
|
|
391
|
+
if (sub === '--help' || sub === '-h') {
|
|
392
|
+
stdout(USAGE);
|
|
393
|
+
return 0;
|
|
394
|
+
}
|
|
395
|
+
stderr(`material subcommand must be package-gene\n${USAGE}`);
|
|
396
|
+
return 1;
|
|
397
|
+
}
|
|
398
|
+
const parsed = parseMaterialArgs(argv.slice(1));
|
|
399
|
+
if (!parsed.ok)
|
|
400
|
+
return emitUsage(parsed.message, argv.includes('--json'), stdout, stderr);
|
|
401
|
+
const { result, code } = await buildMaterialGenePackage(parsed.value, deps);
|
|
402
|
+
emitResult(result, parsed.value.json, stdout);
|
|
403
|
+
return code;
|
|
404
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { schema } from '@evomap/evolver-core';
|
|
2
|
+
import { type RuntimeSessionSource } from './runtimeSessionSource.js';
|
|
3
|
+
export declare const MATERIAL_RUNTIME_SESSION_SNAPSHOT_SCHEMA = "evolver.material.runtime_session_snapshot.v1";
|
|
4
|
+
interface SnapshotTurn {
|
|
5
|
+
role: RuntimeSessionSource['turns'][number]['role'];
|
|
6
|
+
text: string;
|
|
7
|
+
isMeta?: boolean;
|
|
8
|
+
toolName?: string;
|
|
9
|
+
errorMessage?: string;
|
|
10
|
+
}
|
|
11
|
+
interface SnapshotSource {
|
|
12
|
+
agent: string;
|
|
13
|
+
label: string;
|
|
14
|
+
sessionId?: string;
|
|
15
|
+
turns: SnapshotTurn[];
|
|
16
|
+
}
|
|
17
|
+
export interface RuntimeSessionMaterialSnapshotV1 {
|
|
18
|
+
schema: typeof MATERIAL_RUNTIME_SESSION_SNAPSHOT_SCHEMA;
|
|
19
|
+
sourceKind: 'runtime_session';
|
|
20
|
+
kind: 'session_log';
|
|
21
|
+
sources: SnapshotSource[];
|
|
22
|
+
truncated: boolean;
|
|
23
|
+
maxChars: number;
|
|
24
|
+
}
|
|
25
|
+
export declare function buildRuntimeSessionMaterialSnapshot(sources: readonly RuntimeSessionSource[], maxChars?: number): RuntimeSessionMaterialSnapshotV1;
|
|
26
|
+
export declare function runtimeSessionSourcesFromMaterialPayload(payload: unknown): RuntimeSessionSource[];
|
|
27
|
+
export declare function materialHasRuntimeSessionSnapshot(material: schema.Material): boolean;
|
|
28
|
+
export declare function materialSourceAvailable(material: schema.Material): boolean;
|
|
29
|
+
export declare function runtimeSessionSourcesForMaterial(material: schema.Material, readSource?: (path: string) => string): RuntimeSessionSource[];
|
|
30
|
+
export {};
|
|
@@ -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;
|