@evomap/evolver-proxy 2.0.48 → 2.0.50
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/bin/evolver-proxy.js +86 -50
- package/dist/daemon/backgroundCuration.d.ts +54 -0
- package/dist/daemon/backgroundCuration.js +159 -0
- package/dist/daemon/curationGit.d.ts +5 -0
- package/dist/daemon/curationGit.js +140 -0
- package/dist/daemon/distillMeasures.d.ts +59 -0
- package/dist/daemon/distillMeasures.js +139 -0
- package/dist/daemon/localRecall.d.ts +6 -1
- package/dist/daemon/localRecall.js +59 -6
- package/dist/daemon/observedEvidence.d.ts +43 -0
- package/dist/daemon/observedEvidence.js +116 -0
- package/dist/daemon/proxyDaemon.d.ts +19 -0
- package/dist/daemon/proxyDaemon.js +179 -30
- package/dist/daemon/recallContext.js +2 -1
- package/dist/lifecycle/claimNudge.js +1 -1
- package/dist/lifecycle/deployGuard.js +1 -1
- package/dist/lifecycle/legacyNodeId.js +1 -1
- package/dist/lifecycle/manager.js +1 -1
- package/dist/llm/index.js +1 -1
- package/dist/llm/server.js +1 -1
- package/dist/llm/traceBackfill.js +1 -1
- package/dist/llm/traceConfig.js +1 -1
- package/dist/llm/traceControl.js +1 -1
- package/dist/llm/traceEnvelope.js +1 -1
- package/dist/llm/traceSink.js +1 -1
- package/dist/llm/traceUploadPayload.js +1 -1
- package/dist/llm/upstream.js +1 -1
- package/dist/router/cachePassthrough.js +1 -1
- package/dist/router/features.js +1 -1
- package/dist/router/index.js +1 -1
- package/dist/router/messagesRoute.js +1 -1
- package/dist/router/modelRouter.js +1 -1
- package/dist/router/providerRoutes.js +1 -1
- package/dist/router/sseScan.js +1 -1
- package/dist/selfUpdate/bootstrap.js +40 -46
- package/dist/selfUpdate/bootstrapReadiness.js +15 -3
- package/dist/selfUpdate/migration.js +37 -22
- package/dist/selfUpdate/transaction.js +158 -59
- package/dist/selfUpdate/windowsUpdater.js +70 -10
- package/dist/sync/engine.js +1 -1
- package/package.json +3 -3
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
2
|
+
import { appendFileSync, existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import { dirname, join } from 'node:path';
|
|
4
|
+
const MAX_OUTCOMES = 1_000;
|
|
5
|
+
const MAX_CONTROLS = 5_000;
|
|
6
|
+
const WINDOW_HOURS = 24;
|
|
7
|
+
const WITHHOLDING_TTL_MS = 24 * 3_600_000;
|
|
8
|
+
// One trial recall in five is withheld, so a draft's pass rate can be compared with sessions that did without it.
|
|
9
|
+
const HOLDOUT_BUCKETS = 5;
|
|
10
|
+
const MAX_EFFECT_ROWS = 10;
|
|
11
|
+
const MAX_LISTED_CAPSULES = 20_000;
|
|
12
|
+
/** An append-only JSON-lines file that keeps its newest `max` entries. */
|
|
13
|
+
class BoundedJsonl {
|
|
14
|
+
path;
|
|
15
|
+
max;
|
|
16
|
+
constructor(path, max) {
|
|
17
|
+
this.path = path;
|
|
18
|
+
this.max = max;
|
|
19
|
+
}
|
|
20
|
+
read() {
|
|
21
|
+
if (!existsSync(this.path))
|
|
22
|
+
return [];
|
|
23
|
+
return readFileSync(this.path, 'utf8').split('\n').flatMap((line) => {
|
|
24
|
+
if (!line.trim())
|
|
25
|
+
return [];
|
|
26
|
+
try {
|
|
27
|
+
return [JSON.parse(line)];
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return [];
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
append(entry) {
|
|
35
|
+
mkdirSync(dirname(this.path), { recursive: true });
|
|
36
|
+
appendFileSync(this.path, `${JSON.stringify(entry)}\n`, { mode: 0o600 });
|
|
37
|
+
const entries = this.read();
|
|
38
|
+
if (entries.length <= this.max)
|
|
39
|
+
return;
|
|
40
|
+
const temporary = `${this.path}.${process.pid}.tmp`;
|
|
41
|
+
writeFileSync(temporary, entries.slice(-this.max).map((item) => JSON.stringify(item)).join('\n') + '\n', { mode: 0o600 });
|
|
42
|
+
renameSync(temporary, this.path);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
export function distillOutcomeOf(result, at) {
|
|
46
|
+
const stamp = at.toISOString();
|
|
47
|
+
if (!result.ok)
|
|
48
|
+
return { at: stamp, status: 'skipped', reason: result.quality?.reason ?? result.reason };
|
|
49
|
+
if (result.status === 'stored')
|
|
50
|
+
return { at: stamp, status: 'stored' };
|
|
51
|
+
return result.quality.ok ? { at: stamp, status: 'draft' } : { at: stamp, status: 'rejected', reason: result.quality.reason ?? 'quality_gate' };
|
|
52
|
+
}
|
|
53
|
+
export class DistillOutcomeLog {
|
|
54
|
+
log;
|
|
55
|
+
constructor(assetStoreDir) {
|
|
56
|
+
this.log = new BoundedJsonl(join(assetStoreDir, 'distill-outcomes.jsonl'), MAX_OUTCOMES);
|
|
57
|
+
}
|
|
58
|
+
record(outcome) {
|
|
59
|
+
this.log.append(outcome);
|
|
60
|
+
}
|
|
61
|
+
summary(now) {
|
|
62
|
+
const since = now.getTime() - WINDOW_HOURS * 3_600_000;
|
|
63
|
+
const status = { window_hours: WINDOW_HOURS, stored: 0, drafts: 0, rejected: {}, skipped: {} };
|
|
64
|
+
const count = (byReason, reason = 'unknown') => { byReason[reason] = (byReason[reason] ?? 0) + 1; };
|
|
65
|
+
for (const outcome of this.log.read()) {
|
|
66
|
+
if (Date.parse(outcome.at) < since)
|
|
67
|
+
continue;
|
|
68
|
+
if (outcome.status === 'stored')
|
|
69
|
+
status.stored += 1;
|
|
70
|
+
else if (outcome.status === 'draft')
|
|
71
|
+
status.drafts += 1;
|
|
72
|
+
else
|
|
73
|
+
count(outcome.status === 'skipped' ? status.skipped : status.rejected, outcome.reason);
|
|
74
|
+
}
|
|
75
|
+
return status;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
export class TrialControlLog {
|
|
79
|
+
log;
|
|
80
|
+
withholdings;
|
|
81
|
+
constructor(assetStoreDir) {
|
|
82
|
+
this.log = new BoundedJsonl(join(assetStoreDir, 'trial-control.jsonl'), MAX_CONTROLS);
|
|
83
|
+
this.withholdings = new BoundedJsonl(join(assetStoreDir, 'trial-withheld.jsonl'), MAX_CONTROLS);
|
|
84
|
+
}
|
|
85
|
+
/** Records one withholding and names it; the turn that went without the draft reports its control under this id. */
|
|
86
|
+
withheld(assetId, at) {
|
|
87
|
+
const id = randomUUID();
|
|
88
|
+
this.withholdings.append({ id, asset_id: assetId, at: at.toISOString() });
|
|
89
|
+
return id;
|
|
90
|
+
}
|
|
91
|
+
/** A control counts only against the withholding it names: of that draft, in the last day, and only once. */
|
|
92
|
+
record(entry) {
|
|
93
|
+
const withholding = this.withholdings.read().find((known) => known.id === entry.withheld_id);
|
|
94
|
+
if (!withholding || withholding.asset_id !== entry.asset_id
|
|
95
|
+
|| Date.parse(withholding.at) < Date.parse(entry.at) - WITHHOLDING_TTL_MS)
|
|
96
|
+
return 'not_withheld';
|
|
97
|
+
if (this.log.read().some((known) => known.withheld_id === entry.withheld_id))
|
|
98
|
+
return 'duplicate';
|
|
99
|
+
this.log.append(entry);
|
|
100
|
+
return 'recorded';
|
|
101
|
+
}
|
|
102
|
+
list() {
|
|
103
|
+
return this.log.read();
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Keyed by the Gene's own id, not its asset id: the asset id also hashes runtime metadata (model, `env_class`), so the
|
|
108
|
+
* same draft would land in another arm on another machine.
|
|
109
|
+
*/
|
|
110
|
+
export function isTrialHoldout(geneId, recallText) {
|
|
111
|
+
return createHash('sha256').update(`${geneId}\n${recallText}`).digest()[0] % HOLDOUT_BUCKETS === 0;
|
|
112
|
+
}
|
|
113
|
+
const arm = () => ({ runs: 0, passed: 0 });
|
|
114
|
+
/** Each trial draft with a control arm: how often checks passed with it recalled, and without. */
|
|
115
|
+
export async function trialEffect(store, controls) {
|
|
116
|
+
const rows = new Map();
|
|
117
|
+
for (const entry of controls.list()) {
|
|
118
|
+
const row = rows.get(entry.asset_id) ?? { treated: arm(), control: arm() };
|
|
119
|
+
row.control.runs += 1;
|
|
120
|
+
if (entry.passed)
|
|
121
|
+
row.control.passed += 1;
|
|
122
|
+
rows.set(entry.asset_id, row);
|
|
123
|
+
}
|
|
124
|
+
if (rows.size === 0)
|
|
125
|
+
return [];
|
|
126
|
+
for (const capsule of await store.list('Capsule', MAX_LISTED_CAPSULES)) {
|
|
127
|
+
const row = capsule['source_type'] === 'reused' ? rows.get(String(capsule['reused_asset_id'] ?? '')) : undefined;
|
|
128
|
+
if (!row)
|
|
129
|
+
continue;
|
|
130
|
+
row.treated.runs += 1;
|
|
131
|
+
if (capsule['outcome']?.status === 'success')
|
|
132
|
+
row.treated.passed += 1;
|
|
133
|
+
}
|
|
134
|
+
const ranked = [...rows].sort(([, a], [, b]) => (b.treated.runs + b.control.runs) - (a.treated.runs + a.control.runs)).slice(0, MAX_EFFECT_ROWS);
|
|
135
|
+
return Promise.all(ranked.map(async ([assetId, row]) => {
|
|
136
|
+
const gene = await store.get(assetId);
|
|
137
|
+
return { gene_asset_id: assetId, title: String(gene?.['summary'] ?? '').slice(0, 80), ...row };
|
|
138
|
+
}));
|
|
139
|
+
}
|
|
@@ -19,6 +19,11 @@ export interface LocalRecallDiagnostics {
|
|
|
19
19
|
error?: string;
|
|
20
20
|
/** The store held more records of a kind than one recall reads; the rest were not considered. */
|
|
21
21
|
truncated?: boolean;
|
|
22
|
+
/** A trial draft this recall would have returned, held back so the turn can serve as its control. */
|
|
23
|
+
trial_withheld?: {
|
|
24
|
+
asset_id: string;
|
|
25
|
+
withheld_id?: string;
|
|
26
|
+
};
|
|
22
27
|
}
|
|
23
28
|
export interface LocalRecallOutcome {
|
|
24
29
|
assets: assetstore.AssetRecord[];
|
|
@@ -33,5 +38,5 @@ interface LocalRecallRead {
|
|
|
33
38
|
* when that history changed. */
|
|
34
39
|
export declare function rootEventReuseTallies(path?: string): ReuseTallies;
|
|
35
40
|
/** The local Gene, with its project's notes, that this prompt should get from the local store, or none. */
|
|
36
|
-
export declare function recallFromLocalStore(store: assetstore.AssetStoreProvider, text: string, projectDir: unknown): Promise<LocalRecallRead>;
|
|
41
|
+
export declare function recallFromLocalStore(store: assetstore.AssetStoreProvider, text: string, projectDir: unknown, onWithheld?: (assetId: string) => string | undefined): Promise<LocalRecallRead>;
|
|
37
42
|
export {};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { assetstore, events, ops } from '@evomap/evolver-core';
|
|
1
|
+
import { assetstore, events, hub, ops } from '@evomap/evolver-core';
|
|
2
|
+
import { isTrialHoldout } from './distillMeasures.js';
|
|
2
3
|
const MAX_LOCAL_RECALL_RECORDS = 20_000;
|
|
3
4
|
// Passing the local strength gate is already the evidence; the floor keeps a local hit above the host's own
|
|
4
5
|
// similarity cut (0.3) and comparable with the Hub's scores, which the host ranks the merged candidates by.
|
|
@@ -49,11 +50,14 @@ export function rootEventReuseTallies(path = events.rootEventsPath()) {
|
|
|
49
50
|
}
|
|
50
51
|
};
|
|
51
52
|
}
|
|
52
|
-
|
|
53
|
+
const TRIAL_NOTICE = '[On trial, not yet verified] ';
|
|
54
|
+
const TRIAL_BAN_FAILURES = 2;
|
|
55
|
+
function recalledAsset(hit, trial) {
|
|
53
56
|
// Only notes recall matched to this project leave the store; a record's own fields cannot carry any.
|
|
54
57
|
const { project_notes: _unvouched, recall: _claimed, ...gene } = hit.gene;
|
|
55
58
|
return {
|
|
56
59
|
...gene,
|
|
60
|
+
...(trial && typeof gene['summary'] === 'string' ? { summary: `${TRIAL_NOTICE}${gene['summary']}` } : {}),
|
|
57
61
|
similarity: LOCAL_SIMILARITY_FLOOR + (1 - LOCAL_SIMILARITY_FLOOR) * hit.relevance,
|
|
58
62
|
...(hit.projectNotes.length > 0 ? { project_notes: hit.projectNotes } : {}),
|
|
59
63
|
recall: {
|
|
@@ -64,9 +68,40 @@ function recalledAsset(hit) {
|
|
|
64
68
|
project_match: hit.projectMatch,
|
|
65
69
|
reuse: hit.reuse,
|
|
66
70
|
merged_asset_ids: hit.mergedAssetIds,
|
|
71
|
+
...(trial ? { trial: true } : {}),
|
|
67
72
|
},
|
|
68
73
|
};
|
|
69
74
|
}
|
|
75
|
+
/** A project-bound Gene is recalled only in the project one of its Capsules was distilled in. */
|
|
76
|
+
function isBoundHere(gene, capsules, fingerprint) {
|
|
77
|
+
if (!fingerprint)
|
|
78
|
+
return false;
|
|
79
|
+
const geneId = String(gene['id'] ?? gene.asset_id);
|
|
80
|
+
return capsules.some((capsule) => capsule['gene'] === geneId
|
|
81
|
+
&& capsule['content']?.project_fingerprint === fingerprint);
|
|
82
|
+
}
|
|
83
|
+
/** Quarantined drafts that may be tried once: every other gate still applies, and two failures end the trial. */
|
|
84
|
+
function trialPool(genes, capsules, eligibility) {
|
|
85
|
+
const onTrial = genes.filter((gene) => eligibility.review.get(gene.asset_id)?.state === 'quarantined');
|
|
86
|
+
if (onTrial.length === 0)
|
|
87
|
+
return [];
|
|
88
|
+
const review = new Map(eligibility.review);
|
|
89
|
+
for (const gene of onTrial)
|
|
90
|
+
review.delete(gene.asset_id);
|
|
91
|
+
const relaxed = { ...eligibility, review };
|
|
92
|
+
const failures = new Map();
|
|
93
|
+
for (const capsule of capsules) {
|
|
94
|
+
if (capsule['outcome']?.status !== 'failed' || capsule['resolution_status'] === 'pending')
|
|
95
|
+
continue;
|
|
96
|
+
const geneId = String(capsule['gene'] ?? '');
|
|
97
|
+
failures.set(geneId, (failures.get(geneId) ?? 0) + 1);
|
|
98
|
+
}
|
|
99
|
+
const trialGenes = onTrial.filter((gene) => (failures.get(String(gene['id'] ?? gene.asset_id)) ?? 0) < TRIAL_BAN_FAILURES
|
|
100
|
+
&& assetstore.assetContextEligibilityReason(gene, relaxed) === undefined);
|
|
101
|
+
const ids = new Set(trialGenes.map((gene) => String(gene['id'] ?? gene.asset_id)));
|
|
102
|
+
return [...trialGenes, ...capsules.filter((capsule) => ids.has(String(capsule['gene'] ?? ''))
|
|
103
|
+
&& assetstore.assetContextEligibilityReason(capsule, relaxed) === undefined)];
|
|
104
|
+
}
|
|
70
105
|
function diagnosticsOf(result) {
|
|
71
106
|
return {
|
|
72
107
|
considered: result.considered,
|
|
@@ -77,7 +112,7 @@ function diagnosticsOf(result) {
|
|
|
77
112
|
};
|
|
78
113
|
}
|
|
79
114
|
/** The local Gene, with its project's notes, that this prompt should get from the local store, or none. */
|
|
80
|
-
export async function recallFromLocalStore(store, text, projectDir) {
|
|
115
|
+
export async function recallFromLocalStore(store, text, projectDir, onWithheld = () => undefined) {
|
|
81
116
|
const [geneRead, capsuleRead] = await Promise.allSettled([
|
|
82
117
|
Promise.resolve().then(() => store.list('Gene', MAX_LOCAL_RECALL_RECORDS + 1)),
|
|
83
118
|
Promise.resolve().then(() => store.list('Capsule', MAX_LOCAL_RECALL_RECORDS + 1)),
|
|
@@ -103,10 +138,28 @@ export async function recallFromLocalStore(store, text, projectDir) {
|
|
|
103
138
|
const contexts = typeof store.readLocalContextsV1 === 'function' && capsules.length > 0
|
|
104
139
|
? await store.readLocalContextsV1(capsules.map((capsule) => capsule.asset_id)) : [];
|
|
105
140
|
const query = { text, projectFingerprint: await assetstore.projectFingerprint(projectDir) };
|
|
141
|
+
const outcomeOf = (result, trial) => {
|
|
142
|
+
const rawAssets = new Map(result.hits.map((hit) => [recalledAsset(hit, trial), hit.gene]));
|
|
143
|
+
return { assets: [...rawAssets.keys()], rawAssets, diagnostics: { ...diagnosticsOf(result), ...(truncated ? { truncated } : {}) } };
|
|
144
|
+
};
|
|
145
|
+
const inScope = genes.filter((gene) => !hub.isProjectBoundGene(gene) || isBoundHere(gene, capsules, query.projectFingerprint));
|
|
106
146
|
return { finish: (eligibility, reuse) => {
|
|
107
|
-
const qualified = [...
|
|
147
|
+
const qualified = [...inScope, ...capsules].filter((asset) => assetstore.assetContextEligibilityReason(asset, eligibility) === undefined);
|
|
108
148
|
const result = assetstore.recallLocalAssets(qualified, query, reuse, contexts);
|
|
109
|
-
|
|
110
|
-
|
|
149
|
+
if (result.hits.length > 0)
|
|
150
|
+
return outcomeOf(result, false);
|
|
151
|
+
const trial = trialPool(inScope, capsules, eligibility);
|
|
152
|
+
if (trial.length === 0)
|
|
153
|
+
return outcomeOf(result, false);
|
|
154
|
+
const trialResult = assetstore.recallLocalAssets(trial, { ...query, limit: 1 }, reuse, contexts);
|
|
155
|
+
const drafted = trialResult.hits[0]?.gene;
|
|
156
|
+
if (!drafted)
|
|
157
|
+
return outcomeOf(result, false);
|
|
158
|
+
if (!isTrialHoldout(String(drafted['id'] ?? drafted.asset_id), text))
|
|
159
|
+
return outcomeOf(trialResult, true);
|
|
160
|
+
const withheldId = onWithheld(drafted.asset_id);
|
|
161
|
+
const withheld = outcomeOf(result, false);
|
|
162
|
+
const named = { asset_id: drafted.asset_id, ...(withheldId ? { withheld_id: withheldId } : {}) };
|
|
163
|
+
return { ...withheld, diagnostics: { ...withheld.diagnostics, trial_withheld: named } };
|
|
111
164
|
} };
|
|
112
165
|
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { assetstore, hub as hubNs, verify } from '@evomap/evolver-core';
|
|
2
|
+
export interface VerificationContext {
|
|
3
|
+
geneAssetId: string;
|
|
4
|
+
geneId: string;
|
|
5
|
+
root: string;
|
|
6
|
+
head: string;
|
|
7
|
+
diff?: string;
|
|
8
|
+
commands: string[];
|
|
9
|
+
checks: readonly verify.ObservedCheck[];
|
|
10
|
+
planDigest?: string;
|
|
11
|
+
distillInput: Record<string, unknown>;
|
|
12
|
+
recordedAt: string;
|
|
13
|
+
verifiedAt?: string;
|
|
14
|
+
failedAtVerification?: number;
|
|
15
|
+
lastAttempt?: {
|
|
16
|
+
at: string;
|
|
17
|
+
result: string;
|
|
18
|
+
};
|
|
19
|
+
published?: {
|
|
20
|
+
at: string;
|
|
21
|
+
envelopeId: string;
|
|
22
|
+
assetIds: string[];
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export declare class VerificationContextStore {
|
|
26
|
+
private readonly dir;
|
|
27
|
+
constructor(assetStoreDir: string);
|
|
28
|
+
private pathOf;
|
|
29
|
+
get(geneAssetId: string): VerificationContext | undefined;
|
|
30
|
+
/** A Gene is addressed by its content, so once it is published a later plan for it keeps that mark. */
|
|
31
|
+
put(context: VerificationContext): void;
|
|
32
|
+
list(): VerificationContext[];
|
|
33
|
+
}
|
|
34
|
+
/** Old sidecars may already have lost cwd occurrences and must be observed again. */
|
|
35
|
+
export declare function hasVerificationPlan(context: VerificationContext): context is VerificationContext & {
|
|
36
|
+
planDigest: string;
|
|
37
|
+
};
|
|
38
|
+
/** The project state a host hook recorded with an observed distillation, or none when it cannot be replayed. */
|
|
39
|
+
export declare function verificationContextOf(body: hubNs.ConversationDistillInput, gene: assetstore.AssetRecord, now: Date, checks: readonly verify.ObservedCheck[] | undefined): VerificationContext | undefined;
|
|
40
|
+
/** Whether a host hook observed the reused turn's last check and its result; agent-reported evidence never qualifies. */
|
|
41
|
+
export declare function isObservedCheckEvidence(evidence: Record<string, unknown> | undefined): boolean;
|
|
42
|
+
export type ObservedReuseRecording = 'recorded' | 'duplicate' | 'not_local' | 'no_task';
|
|
43
|
+
export declare function recordObservedReuse(store: assetstore.AssetStoreProvider, assetId: string, taskId: string | undefined, passed: boolean): Promise<ObservedReuseRecording>;
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { existsSync, mkdirSync, readdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import { isAbsolute, join } from 'node:path';
|
|
4
|
+
import { algo, assetstore, hub as hubNs, verify } from '@evomap/evolver-core';
|
|
5
|
+
const MAX_DIFF_BYTES = 256 * 1024;
|
|
6
|
+
export class VerificationContextStore {
|
|
7
|
+
dir;
|
|
8
|
+
constructor(assetStoreDir) {
|
|
9
|
+
this.dir = join(assetStoreDir, 'verification-context');
|
|
10
|
+
}
|
|
11
|
+
pathOf(geneAssetId) {
|
|
12
|
+
return join(this.dir, `${createHash('sha256').update(geneAssetId).digest('hex').slice(0, 40)}.json`);
|
|
13
|
+
}
|
|
14
|
+
get(geneAssetId) {
|
|
15
|
+
const path = this.pathOf(geneAssetId);
|
|
16
|
+
if (!existsSync(path))
|
|
17
|
+
return undefined;
|
|
18
|
+
try {
|
|
19
|
+
const parsed = JSON.parse(readFileSync(path, 'utf8'));
|
|
20
|
+
return parsed.geneAssetId === geneAssetId ? parsed : undefined;
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/** A Gene is addressed by its content, so once it is published a later plan for it keeps that mark. */
|
|
27
|
+
put(context) {
|
|
28
|
+
mkdirSync(this.dir, { recursive: true, mode: 0o700 });
|
|
29
|
+
const path = this.pathOf(context.geneAssetId);
|
|
30
|
+
const published = context.published ?? this.get(context.geneAssetId)?.published;
|
|
31
|
+
const tmp = `${path}.${process.pid}.${Date.now()}.tmp`;
|
|
32
|
+
writeFileSync(tmp, `${JSON.stringify(published ? { ...context, published } : context)}\n`, { mode: 0o600 });
|
|
33
|
+
renameSync(tmp, path);
|
|
34
|
+
}
|
|
35
|
+
list() {
|
|
36
|
+
if (!existsSync(this.dir))
|
|
37
|
+
return [];
|
|
38
|
+
const out = [];
|
|
39
|
+
for (const name of readdirSync(this.dir)) {
|
|
40
|
+
if (!name.endsWith('.json'))
|
|
41
|
+
continue;
|
|
42
|
+
try {
|
|
43
|
+
out.push(JSON.parse(readFileSync(join(this.dir, name), 'utf8')));
|
|
44
|
+
}
|
|
45
|
+
catch { /* a torn file is skipped, never fatal */ }
|
|
46
|
+
}
|
|
47
|
+
return out;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
function record(value) {
|
|
51
|
+
return value && typeof value === 'object' && !Array.isArray(value) ? value : {};
|
|
52
|
+
}
|
|
53
|
+
function planDigest({ root, head, diff, checks }) {
|
|
54
|
+
return hubNs.publishBindingDigest('observed-validation-plan.v1', { root, head, diff: diff ?? '', checks });
|
|
55
|
+
}
|
|
56
|
+
function checkMatchesCommand(check, command) {
|
|
57
|
+
return Boolean(check && typeof check.command === 'string' && check.command === command
|
|
58
|
+
&& check.command.length <= 180 && verify.isValidationCommandAllowed(check.command)
|
|
59
|
+
&& (check.cwd === undefined || (typeof check.cwd === 'string' && !isAbsolute(check.cwd))));
|
|
60
|
+
}
|
|
61
|
+
/** Old sidecars may already have lost cwd occurrences and must be observed again. */
|
|
62
|
+
export function hasVerificationPlan(context) {
|
|
63
|
+
if (typeof context.root !== 'string' || !isAbsolute(context.root)
|
|
64
|
+
|| typeof context.head !== 'string' || !/^[0-9a-f]{7,64}$/.test(context.head)
|
|
65
|
+
|| (context.diff !== undefined && (typeof context.diff !== 'string' || Buffer.byteLength(context.diff, 'utf8') > MAX_DIFF_BYTES))
|
|
66
|
+
|| !Array.isArray(context.commands) || !Array.isArray(context.checks)
|
|
67
|
+
|| context.checks.length < 1 || context.checks.length > 8 || context.commands.length !== context.checks.length)
|
|
68
|
+
return false;
|
|
69
|
+
return context.checks.every((check, index) => checkMatchesCommand(check, context.commands[index]))
|
|
70
|
+
&& typeof context.planDigest === 'string' && context.planDigest === planDigest(context);
|
|
71
|
+
}
|
|
72
|
+
/** The project state a host hook recorded with an observed distillation, or none when it cannot be replayed. */
|
|
73
|
+
export function verificationContextOf(body, gene, now, checks) {
|
|
74
|
+
const project = record(body['project']);
|
|
75
|
+
const root = typeof project['root'] === 'string' ? project['root'] : '';
|
|
76
|
+
const head = typeof project['head'] === 'string' ? project['head'] : '';
|
|
77
|
+
if (!checks?.length || project['diff_omitted'] !== undefined)
|
|
78
|
+
return undefined;
|
|
79
|
+
if (project['diff'] !== undefined && typeof project['diff'] !== 'string')
|
|
80
|
+
return undefined;
|
|
81
|
+
const diff = project['diff'];
|
|
82
|
+
const validation = Array.isArray(gene['validation']) ? gene['validation'] : [];
|
|
83
|
+
if (validation.includes('node --version'))
|
|
84
|
+
return undefined;
|
|
85
|
+
const plan = { root, head, ...(diff ? { diff } : {}), checks: checks.map((check) => ({ ...check })) };
|
|
86
|
+
const { project: _project, execution: _execution, persist: _persist, publish: _publish, ...distillInput } = body;
|
|
87
|
+
const context = {
|
|
88
|
+
geneAssetId: gene.asset_id,
|
|
89
|
+
geneId: String(gene['id'] ?? gene.asset_id),
|
|
90
|
+
...plan, commands: validation, planDigest: planDigest(plan), distillInput, recordedAt: now.toISOString(),
|
|
91
|
+
};
|
|
92
|
+
return hasVerificationPlan(context) ? context : undefined;
|
|
93
|
+
}
|
|
94
|
+
/** Whether a host hook observed the reused turn's last check and its result; agent-reported evidence never qualifies. */
|
|
95
|
+
export function isObservedCheckEvidence(evidence) {
|
|
96
|
+
return evidence?.['source'] === 'observed' && evidence['tier'] === 'L1' && typeof record(evidence['check'])['passed'] === 'boolean';
|
|
97
|
+
}
|
|
98
|
+
export async function recordObservedReuse(store, assetId, taskId, passed) {
|
|
99
|
+
if (!taskId)
|
|
100
|
+
return 'no_task';
|
|
101
|
+
const gene = await store.get(assetId);
|
|
102
|
+
if (!gene || gene.type !== 'Gene')
|
|
103
|
+
return 'not_local';
|
|
104
|
+
const capsule = algo.observedReuseCapsule({
|
|
105
|
+
geneId: String(gene['id'] ?? gene.asset_id),
|
|
106
|
+
geneAssetId: gene.asset_id,
|
|
107
|
+
trigger: Array.isArray(gene['signals_match']) ? gene['signals_match'].map(String).slice(0, 8) : [],
|
|
108
|
+
taskId,
|
|
109
|
+
passed,
|
|
110
|
+
});
|
|
111
|
+
const existing = await store.search({ kind: 'Capsule', gene: String(gene['id'] ?? gene.asset_id), limit: 10_000 });
|
|
112
|
+
if (existing.some((c) => c['id'] === capsule.id))
|
|
113
|
+
return 'duplicate';
|
|
114
|
+
await store.put(capsule);
|
|
115
|
+
return 'recorded';
|
|
116
|
+
}
|
|
@@ -5,6 +5,7 @@ import { type SelfUpdateDeps } from '../selfUpdate/executor.js';
|
|
|
5
5
|
import type { AtpOrderConsentGate } from './atpConsent.js';
|
|
6
6
|
import type { PrivateBoundReuseFeedback } from '../private/adapterLoader.js';
|
|
7
7
|
import { type ReuseTallies } from './localRecall.js';
|
|
8
|
+
import { type VerificationPlan } from './backgroundCuration.js';
|
|
8
9
|
import { type PublishRecallVerifierPort } from './publishRecallVerifier.js';
|
|
9
10
|
type HubCapability = hubNs.HubCapability;
|
|
10
11
|
type AssetStoreProvider = assetstore.AssetStoreProvider;
|
|
@@ -102,6 +103,8 @@ export interface ProxyDaemonDeps {
|
|
|
102
103
|
* 宿主专属的真实执行验证器。缺失时,conversation distill 只能返回草稿,绝不持久化或排队发布。
|
|
103
104
|
*/
|
|
104
105
|
publishExecutionVerifier?: ConversationDistillExecutionVerifier;
|
|
106
|
+
/** Builds a verifier bound to one validation copy; the background curation pass verifies each Gene in its own copy. */
|
|
107
|
+
publishVerifierForRoot?: (root: string, plan?: VerificationPlan) => ConversationDistillExecutionVerifier;
|
|
105
108
|
/** 验证器响应的硬超时,防止发布请求因宿主执行器挂起而永久占用连接。 */
|
|
106
109
|
publishExecutionVerifierTimeoutMs?: number;
|
|
107
110
|
}
|
|
@@ -210,6 +213,13 @@ export declare class ProxyDaemon {
|
|
|
210
213
|
/** A poke that arrived between ticks (no sleep in flight) parks the wake here so it is not lost. */
|
|
211
214
|
private wakeRunnerPending;
|
|
212
215
|
private started;
|
|
216
|
+
private readonly verificationContexts;
|
|
217
|
+
private readonly distillOutcomes;
|
|
218
|
+
private readonly trialControls;
|
|
219
|
+
private lastRouteAt;
|
|
220
|
+
private curationTimer;
|
|
221
|
+
private lastCurationAt;
|
|
222
|
+
private curationRunning;
|
|
213
223
|
private feedbackRecovery;
|
|
214
224
|
private lifecycleArmed;
|
|
215
225
|
private lastTickAt;
|
|
@@ -237,6 +247,15 @@ export declare class ProxyDaemon {
|
|
|
237
247
|
private recordTickError;
|
|
238
248
|
/** 启动: 锁 + IPC 监听 + 初次 hello. 返回 IPC 端口. */
|
|
239
249
|
start(): Promise<number>;
|
|
250
|
+
private scheduleCuration;
|
|
251
|
+
private curateWhenIdle;
|
|
252
|
+
private enqueueVerifiedDistillation;
|
|
253
|
+
private trackStoredDraft;
|
|
254
|
+
/** The control arm of a trial draft: a turn that ran its checks with the draft withheld. */
|
|
255
|
+
private recordTrialControl;
|
|
256
|
+
private enqueueDistillPublication;
|
|
257
|
+
private registerDistillPublication;
|
|
258
|
+
private distillPublicationEnvelope;
|
|
240
259
|
private listenIpc;
|
|
241
260
|
private drainTriggerFeedbackRecovery;
|
|
242
261
|
/** 单轮: core pump/TTL/wake + proxy 出站 + hub 入站 + 到点心跳. */
|