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