@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
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env -S node --
|
|
2
2
|
import { createHash, randomBytes } from 'node:crypto';
|
|
3
3
|
import { readFileSync, realpathSync, rmSync } from 'node:fs';
|
|
4
|
-
import { homedir } from 'node:os';
|
|
4
|
+
import { homedir, userInfo } from 'node:os';
|
|
5
5
|
import { join, resolve } from 'node:path';
|
|
6
6
|
import { fileURLToPath } from 'node:url';
|
|
7
7
|
import { bootstrap as coreBootstrap, daemon, events, exec as execCore, hub as hubNs, mailbox, util, verify } from '@evomap/evolver-core';
|
|
@@ -388,7 +388,7 @@ export function proxyUsage(command = 'evolver-proxy') {
|
|
|
388
388
|
'',
|
|
389
389
|
'Useful options are configured through env or EVOLVER_ENV_FILE:',
|
|
390
390
|
' EVOLVER_IPC_PORT, EVOLVER_IPC_TOKEN, EVOLVER_PROXY_SETTINGS_FILE',
|
|
391
|
-
'
|
|
391
|
+
' EVOLVER_PUBLISH_VALIDATION_ROOT=<dir> (HTTP 发布验证根目录;隔离可用时后台验证按 Gene 自建副本)',
|
|
392
392
|
' EVOLVER_SELF_UPDATE, EVOLVER_LLM_TRACE_CAPTURE_BODIES',
|
|
393
393
|
'',
|
|
394
394
|
].join('\n');
|
|
@@ -698,7 +698,8 @@ export function createProxyDaemonDeps(options) {
|
|
|
698
698
|
const env = options.env ?? process.env;
|
|
699
699
|
const traceBackfill = resolveTraceBackfillConfig(env);
|
|
700
700
|
const heartbeatIntervalMs = positiveIntegerEnv(env['HEARTBEAT_INTERVAL_MS']);
|
|
701
|
-
const
|
|
701
|
+
const verifierFactory = nativeVerifierFactory();
|
|
702
|
+
const publishExecutionVerifier = configuredRootVerifier(env, verifierFactory);
|
|
702
703
|
const hubAuthFailurePolicy = resolveHubAuthFailurePolicy(env);
|
|
703
704
|
const triggerFeedback = options.triggerFeedback ?? execCore.createTriggerFeedbackLocalFacade(env);
|
|
704
705
|
return {
|
|
@@ -726,69 +727,104 @@ export function createProxyDaemonDeps(options) {
|
|
|
726
727
|
...(selfUpdate ? { selfUpdate } : {}),
|
|
727
728
|
...(traceBackfill ? { traceBackfill } : {}),
|
|
728
729
|
...(publishExecutionVerifier ? { publishExecutionVerifier } : {}),
|
|
730
|
+
...(verifierFactory ? { publishVerifierForRoot: verifierFactory } : {}),
|
|
729
731
|
};
|
|
730
732
|
}
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
// 原生发布验证器只能在完整的 OS 隔离可用时装配。Windows/macOS 目前没有
|
|
739
|
-
// 与 Linux namespace、只读文件系统和 cgroup 等价的实现,必须保持 draft-only,
|
|
740
|
-
// 不能先暴露一个运行时必然失败的“验证器”能力。
|
|
733
|
+
function nativeValidationChecks(commands, plan) {
|
|
734
|
+
if (!plan)
|
|
735
|
+
return commands.map((command) => ({ command }));
|
|
736
|
+
return plan.checks.length === commands.length && plan.checks.every((check, index) => check.command === commands[index])
|
|
737
|
+
? plan.checks : undefined;
|
|
738
|
+
}
|
|
739
|
+
function nativeVerifierFactory() {
|
|
741
740
|
try {
|
|
742
741
|
if (!verify.readOnlyIsolationAvailable())
|
|
743
742
|
return undefined;
|
|
744
743
|
}
|
|
745
744
|
catch {
|
|
746
|
-
// 隔离探测本身失败也必须保持 fail-closed,而不能阻止代理启动。
|
|
747
745
|
return undefined;
|
|
748
746
|
}
|
|
749
|
-
|
|
747
|
+
return (validationRoot, plan) => {
|
|
748
|
+
const rootFingerprint = hubNs.publishBindingDigest('publish-validation-root.v1', validationRoot);
|
|
749
|
+
const scrubLocalPaths = localPathScrubber([
|
|
750
|
+
[validationRoot, '.'],
|
|
751
|
+
...(plan ? [[plan.dependencySourceRoot, '.']] : []),
|
|
752
|
+
[homedir(), '~'],
|
|
753
|
+
[userInfo().homedir, '~'],
|
|
754
|
+
]);
|
|
755
|
+
return async (input, signal) => {
|
|
756
|
+
const commands = Array.isArray(input.validation)
|
|
757
|
+
? input.validation.filter((value) => typeof value === 'string').map((value) => value.trim()).filter(Boolean)
|
|
758
|
+
: [];
|
|
759
|
+
if (commands.length === 0
|
|
760
|
+
|| commands.length > 8
|
|
761
|
+
|| !Array.isArray(input.validation)
|
|
762
|
+
|| input.validation.length !== commands.length
|
|
763
|
+
|| commands.some((command) => command.length > 180
|
|
764
|
+
|| !verify.isValidationCommandAllowed(command)
|
|
765
|
+
|| verify.sanitizeExecutionCommand(command).blocked)
|
|
766
|
+
|| signal.aborted
|
|
767
|
+
|| !hubNs.isPublishVerificationRequest(input['verification_request'])
|
|
768
|
+
|| input['verification_request'].validationDigest !== hubNs.publishBindingDigest('publish-validation.v1', commands))
|
|
769
|
+
return null;
|
|
770
|
+
const checks = nativeValidationChecks(commands, plan);
|
|
771
|
+
if (!checks)
|
|
772
|
+
return null;
|
|
773
|
+
const result = await verify.runSandboxedChecks(checks, validationRoot, {
|
|
774
|
+
requireIsolation: true,
|
|
775
|
+
signal,
|
|
776
|
+
resourceBudget: VALIDATION_RESOURCE_BUDGET,
|
|
777
|
+
...(plan ? { dependencySourceRoot: plan.dependencySourceRoot, writableCheckout: true } : {}),
|
|
778
|
+
});
|
|
779
|
+
if (signal.aborted || !result.passed || result.results.length !== commands.length)
|
|
780
|
+
return null;
|
|
781
|
+
return {
|
|
782
|
+
binding: { request: structuredClone(input['verification_request']), rootFingerprint },
|
|
783
|
+
validation: commands,
|
|
784
|
+
trace: result.results.map((row) => ({
|
|
785
|
+
command: row.cmd,
|
|
786
|
+
exit: row.exitCode ?? 1,
|
|
787
|
+
...(row.stdoutSummary ? { summary: scrubLocalPaths(row.stdoutSummary) } : {}),
|
|
788
|
+
})),
|
|
789
|
+
};
|
|
790
|
+
};
|
|
791
|
+
};
|
|
792
|
+
}
|
|
793
|
+
// Real check commands run whole test suites: vitest forks a worker per core and needs well over the 1 GiB default.
|
|
794
|
+
const VALIDATION_RESOURCE_BUDGET = { memoryBytes: 4 * 1024 * 1024 * 1024, processes: 256 };
|
|
795
|
+
/**
|
|
796
|
+
* The trace is published, local paths are not: tools print their working directory (vitest's "RUN <root>").
|
|
797
|
+
* Each path is matched as given, canonicalized, and without macOS's /private prefix, longest first so a checkout
|
|
798
|
+
* under HOME becomes "." rather than "~/...".
|
|
799
|
+
*/
|
|
800
|
+
function localPathScrubber(entries) {
|
|
801
|
+
const spellings = entries.flatMap(([path, replacement]) => {
|
|
802
|
+
let canonical = path;
|
|
803
|
+
try {
|
|
804
|
+
canonical = realpathSync(path);
|
|
805
|
+
}
|
|
806
|
+
catch { /* keep the given spelling */ }
|
|
807
|
+
return [path, resolve(path), canonical, canonical.replace(/^\/private(?=\/)/, '')]
|
|
808
|
+
.filter((spelling) => spelling.length > 1)
|
|
809
|
+
.map((spelling) => [spelling, replacement]);
|
|
810
|
+
});
|
|
811
|
+
const ordered = [...new Map(spellings).entries()].sort(([a], [b]) => b.length - a.length);
|
|
812
|
+
return (text) => ordered.reduce((out, [spelling, replacement]) => out.split(spelling).join(replacement), text);
|
|
813
|
+
}
|
|
814
|
+
/**
|
|
815
|
+
* HTTP callers verify against the root the deployer configured; falling back to the daemon's cwd would detach
|
|
816
|
+
* the verified tree from the published one.
|
|
817
|
+
*/
|
|
818
|
+
function configuredRootVerifier(env, factory) {
|
|
750
819
|
const configuredRoot = env['EVOLVER_PUBLISH_VALIDATION_ROOT']?.trim();
|
|
751
|
-
if (!configuredRoot)
|
|
820
|
+
if (!factory || !configuredRoot)
|
|
752
821
|
return undefined;
|
|
753
|
-
let validationRoot;
|
|
754
822
|
try {
|
|
755
|
-
|
|
823
|
+
return factory(realpathSync(resolve(configuredRoot)));
|
|
756
824
|
}
|
|
757
825
|
catch {
|
|
758
826
|
return undefined;
|
|
759
827
|
}
|
|
760
|
-
const rootFingerprint = hubNs.publishBindingDigest('publish-validation-root.v1', validationRoot);
|
|
761
|
-
return async (input, signal) => {
|
|
762
|
-
const commands = Array.isArray(input.validation)
|
|
763
|
-
? input.validation.filter((value) => typeof value === 'string').map((value) => value.trim()).filter(Boolean)
|
|
764
|
-
: [];
|
|
765
|
-
if (commands.length === 0
|
|
766
|
-
|| commands.length > 8
|
|
767
|
-
|| !Array.isArray(input.validation)
|
|
768
|
-
|| input.validation.length !== commands.length
|
|
769
|
-
|| commands.some((command) => command.length > 180
|
|
770
|
-
|| !verify.isValidationCommandAllowed(command)
|
|
771
|
-
|| verify.sanitizeExecutionCommand(command).blocked)
|
|
772
|
-
|| signal.aborted
|
|
773
|
-
|| !hubNs.isPublishVerificationRequest(input['verification_request'])
|
|
774
|
-
|| input['verification_request'].validationDigest !== hubNs.publishBindingDigest('publish-validation.v1', commands))
|
|
775
|
-
return null;
|
|
776
|
-
const result = await verify.runSandboxedValidation(commands, validationRoot, {
|
|
777
|
-
requireIsolation: true,
|
|
778
|
-
signal,
|
|
779
|
-
});
|
|
780
|
-
if (signal.aborted || !result.passed || result.results.length !== commands.length)
|
|
781
|
-
return null;
|
|
782
|
-
return {
|
|
783
|
-
binding: { request: structuredClone(input['verification_request']), rootFingerprint },
|
|
784
|
-
validation: commands,
|
|
785
|
-
trace: result.results.map((row) => ({
|
|
786
|
-
command: row.cmd,
|
|
787
|
-
exit: row.exitCode ?? 1,
|
|
788
|
-
...(row.stdoutSummary ? { summary: row.stdoutSummary } : {}),
|
|
789
|
-
})),
|
|
790
|
-
};
|
|
791
|
-
};
|
|
792
828
|
}
|
|
793
829
|
function positiveIntegerEnv(value) {
|
|
794
830
|
const trimmed = value?.trim();
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { assetstore, type hub as hubNs, type verify } from '@evomap/evolver-core';
|
|
2
|
+
import { type VerificationContextStore } from './observedEvidence.js';
|
|
3
|
+
export declare const CURATION_INTERVAL_MS: number;
|
|
4
|
+
export declare const CURATION_IDLE_MS: number;
|
|
5
|
+
export declare const CURATION_POLL_MS = 30000;
|
|
6
|
+
export type ExecutionVerifier = (input: hubNs.ConversationDistillInput, signal: AbortSignal) => Promise<hubNs.ConversationDistillVerifiedExecution | null>;
|
|
7
|
+
export interface CuratedPublication {
|
|
8
|
+
queued: boolean;
|
|
9
|
+
reason?: string;
|
|
10
|
+
envelopeId?: string;
|
|
11
|
+
assetIds?: string[];
|
|
12
|
+
}
|
|
13
|
+
export type CuratedMailboxCommit = (send: () => boolean) => 'stored' | 'not_stored' | 'review_not_approved' | 'verification_plan_changed';
|
|
14
|
+
/** Where each check runs inside the copy, and which project lends the copy its installed dependencies. */
|
|
15
|
+
export interface VerificationPlan {
|
|
16
|
+
checks: readonly verify.ObservedCheck[];
|
|
17
|
+
dependencySourceRoot: string;
|
|
18
|
+
}
|
|
19
|
+
export interface CurationDeps {
|
|
20
|
+
store: assetstore.AssetStoreProvider;
|
|
21
|
+
review: assetstore.ReviewLedger;
|
|
22
|
+
contexts: VerificationContextStore;
|
|
23
|
+
/** Absent where read-only isolation is unavailable: genes then wait, never published unverified. */
|
|
24
|
+
verifierForRoot: ((root: string, plan?: VerificationPlan) => ExecutionVerifier) | undefined;
|
|
25
|
+
verify: (body: hubNs.ConversationDistillInput, verifier: ExecutionVerifier, planDigest: string) => Promise<hubNs.ConversationDistillVerifiedExecution | undefined>;
|
|
26
|
+
enqueue: (body: hubNs.ConversationDistillInput, verified: hubNs.ConversationDistillVerifiedExecution, planDigest: string, commit: CuratedMailboxCommit, expectedGeneAssetId: string) => Promise<CuratedPublication>;
|
|
27
|
+
now: () => Date;
|
|
28
|
+
scratchDir?: string;
|
|
29
|
+
}
|
|
30
|
+
export interface CurationReport {
|
|
31
|
+
promoted: string[];
|
|
32
|
+
attempted?: {
|
|
33
|
+
geneAssetId: string;
|
|
34
|
+
result: string;
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* One idle pass: promote probation drafts that earned it, then verify and publish at most one promoted Gene.
|
|
39
|
+
* Every refusal leaves the Gene local and is retried on a later pass.
|
|
40
|
+
*/
|
|
41
|
+
export declare function runCurationTick(deps: CurationDeps): Promise<CurationReport>;
|
|
42
|
+
export interface CurationStatus {
|
|
43
|
+
publish_verifier: 'available' | 'unavailable';
|
|
44
|
+
publish_verifier_reason?: 'read_only_isolation_unavailable';
|
|
45
|
+
awaiting_verification: number;
|
|
46
|
+
published: number;
|
|
47
|
+
last_attempt?: {
|
|
48
|
+
gene_asset_id: string;
|
|
49
|
+
result: string;
|
|
50
|
+
at: string;
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
/** Why promoted genes are or are not leaving this machine, for /proxy/status and the plugin's status command. */
|
|
54
|
+
export declare function curationStatus(contexts: VerificationContextStore, review: assetstore.ReviewLedger, verifierAvailable: boolean): CurationStatus;
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { mkdtempSync, rmSync } from 'node:fs';
|
|
2
|
+
import { tmpdir } from 'node:os';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { algo, assetstore, wire } from '@evomap/evolver-core';
|
|
5
|
+
import { createRecordedCheckout, RecordedTreeMismatch } from './curationGit.js';
|
|
6
|
+
import { hasVerificationPlan } from './observedEvidence.js';
|
|
7
|
+
export const CURATION_INTERVAL_MS = 10 * 60_000;
|
|
8
|
+
export const CURATION_IDLE_MS = 2 * 60_000;
|
|
9
|
+
// Host relays reach the Proxy every minute or two; checking only at each interval boundary would almost always land
|
|
10
|
+
// inside their activity, so the quiet window is polled for and a run still starts at most once per interval.
|
|
11
|
+
export const CURATION_POLL_MS = 30_000;
|
|
12
|
+
function geneDigest(gene) {
|
|
13
|
+
return wire.canonicalize(gene);
|
|
14
|
+
}
|
|
15
|
+
async function withValidationCopy(context, scratchDir, use) {
|
|
16
|
+
let parent;
|
|
17
|
+
try {
|
|
18
|
+
let copy;
|
|
19
|
+
try {
|
|
20
|
+
parent = mkdtempSync(join(scratchDir, 'evolver-validation-'));
|
|
21
|
+
copy = await createRecordedCheckout(context, parent);
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
return error instanceof RecordedTreeMismatch ? 'not_reproducible' : 'git_setup_failed';
|
|
25
|
+
}
|
|
26
|
+
return await use(copy);
|
|
27
|
+
}
|
|
28
|
+
finally {
|
|
29
|
+
if (parent)
|
|
30
|
+
rmSync(parent, { recursive: true, force: true });
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
function verifiedCapsule(context, gene, calls) {
|
|
34
|
+
const { capsule } = algo.solidify({
|
|
35
|
+
geneId: context.geneId,
|
|
36
|
+
trigger: Array.isArray(gene['signals_match']) ? gene['signals_match'].map(String).slice(0, 8) : [],
|
|
37
|
+
summary: `Host-verified validation of ${context.geneId}`,
|
|
38
|
+
confidence: 0.9,
|
|
39
|
+
outcome: { status: 'success', score: 0.9 },
|
|
40
|
+
proofOfWork: { kind: 'tool_call_trace', tool_call_trace: { calls, ref: 'host-verified' } },
|
|
41
|
+
strongEvidence: true,
|
|
42
|
+
});
|
|
43
|
+
return capsule;
|
|
44
|
+
}
|
|
45
|
+
const TERMINAL_RESULTS = new Set(['not_reproducible', 'new_failures', 'verification_plan_unavailable']);
|
|
46
|
+
const awaitsVerification = (context) => !context.published && !TERMINAL_RESULTS.has(context.lastAttempt?.result ?? '');
|
|
47
|
+
async function pendingCandidate(deps) {
|
|
48
|
+
const queue = deps.contexts.list()
|
|
49
|
+
.filter(awaitsVerification)
|
|
50
|
+
.sort((a, b) => (a.lastAttempt?.at ?? '').localeCompare(b.lastAttempt?.at ?? ''));
|
|
51
|
+
for (const context of queue) {
|
|
52
|
+
if (deps.review.get(context.geneAssetId)?.state !== 'approved')
|
|
53
|
+
continue;
|
|
54
|
+
const gene = await deps.store.get(context.geneAssetId);
|
|
55
|
+
if (gene?.type === 'Gene')
|
|
56
|
+
return { context, gene };
|
|
57
|
+
}
|
|
58
|
+
return undefined;
|
|
59
|
+
}
|
|
60
|
+
function currentObservation(contexts, attempted) {
|
|
61
|
+
const current = contexts.get(attempted.geneAssetId);
|
|
62
|
+
return current && current.recordedAt === attempted.recordedAt && current.planDigest === attempted.planDigest ? current : undefined;
|
|
63
|
+
}
|
|
64
|
+
function saveCurrentObservation(contexts, attempted, update) {
|
|
65
|
+
const current = currentObservation(contexts, attempted);
|
|
66
|
+
if (!current || (update.verifiedAt !== undefined && !hasVerificationPlan(current)))
|
|
67
|
+
return false;
|
|
68
|
+
contexts.put({ ...current, ...update });
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
function isCurrentPlan(contexts, attempted) {
|
|
72
|
+
const current = currentObservation(contexts, attempted);
|
|
73
|
+
return current !== undefined && !current.published && hasVerificationPlan(current);
|
|
74
|
+
}
|
|
75
|
+
async function enqueueCurrentVerification(deps, context, body, verified, geneBefore) {
|
|
76
|
+
if (!algo.isGenePublishEligible(await assetstore.aggregateLearningHistory(deps.store, context.geneId)))
|
|
77
|
+
return 'not_publish_eligible';
|
|
78
|
+
const current = await deps.store.get(context.geneAssetId);
|
|
79
|
+
if (!current || geneDigest(current) !== geneBefore)
|
|
80
|
+
return 'gene_changed';
|
|
81
|
+
const isCurrent = () => isCurrentPlan(deps.contexts, context);
|
|
82
|
+
if (!isCurrent())
|
|
83
|
+
return 'verification_plan_changed';
|
|
84
|
+
const at = deps.now().toISOString();
|
|
85
|
+
// The mark is written in the same synchronous step as the send, so no later plan can find the Gene unpublished.
|
|
86
|
+
const commit = (send) => deps.review.withExplicitApproval(context.geneAssetId, () => {
|
|
87
|
+
if (!isCurrent())
|
|
88
|
+
return 'verification_plan_changed';
|
|
89
|
+
if (!send())
|
|
90
|
+
return 'not_stored';
|
|
91
|
+
saveCurrentObservation(deps.contexts, context, { published: { at, envelopeId: '', assetIds: [] } });
|
|
92
|
+
return 'stored';
|
|
93
|
+
}) ?? 'review_not_approved';
|
|
94
|
+
const publication = await deps.enqueue(body, verified, context.planDigest, commit, context.geneAssetId);
|
|
95
|
+
if (!publication.queued)
|
|
96
|
+
return publication.reason ?? 'publish_blocked';
|
|
97
|
+
const latest = deps.contexts.get(context.geneAssetId);
|
|
98
|
+
if (latest) {
|
|
99
|
+
deps.contexts.put({ ...latest, published: { at, envelopeId: publication.envelopeId ?? '', assetIds: publication.assetIds ?? [] } });
|
|
100
|
+
}
|
|
101
|
+
return 'published';
|
|
102
|
+
}
|
|
103
|
+
async function curateOne(deps, context, gene) {
|
|
104
|
+
if (!hasVerificationPlan(context))
|
|
105
|
+
return 'verification_plan_unavailable';
|
|
106
|
+
const verifierForRoot = deps.verifierForRoot;
|
|
107
|
+
const history = await assetstore.aggregateLearningHistory(deps.store, context.geneId);
|
|
108
|
+
if (context.failedAtVerification !== undefined && history.failed !== context.failedAtVerification)
|
|
109
|
+
return 'new_failures';
|
|
110
|
+
const before = geneDigest(gene);
|
|
111
|
+
const checks = Object.freeze(context.checks.map((check) => Object.freeze({ ...check })));
|
|
112
|
+
const validation = Object.freeze(checks.map(({ command }) => command));
|
|
113
|
+
const body = { ...context.distillInput, validation, publish: true, persist: true };
|
|
114
|
+
// The Linux verifier mounts scratch over /tmp before entering the checkout.
|
|
115
|
+
const scratch = deps.scratchDir ?? (process.platform === 'linux' ? '/var/tmp' : tmpdir());
|
|
116
|
+
const verified = await withValidationCopy(context, scratch, (root) => deps.verify(body, verifierForRoot(root, { checks, dependencySourceRoot: context.root }), context.planDigest));
|
|
117
|
+
if (typeof verified === 'string')
|
|
118
|
+
return verified;
|
|
119
|
+
if (!verified)
|
|
120
|
+
return 'verification_failed';
|
|
121
|
+
if (!isCurrentPlan(deps.contexts, context))
|
|
122
|
+
return 'verification_plan_changed';
|
|
123
|
+
if (!deps.review.isExplicitlyApproved(context.geneAssetId))
|
|
124
|
+
return 'review_not_approved';
|
|
125
|
+
await deps.store.put(verifiedCapsule(context, gene, verified.trace.length));
|
|
126
|
+
if (!saveCurrentObservation(deps.contexts, context, {
|
|
127
|
+
verifiedAt: deps.now().toISOString(), failedAtVerification: history.failed,
|
|
128
|
+
}))
|
|
129
|
+
return 'verification_plan_changed';
|
|
130
|
+
return enqueueCurrentVerification(deps, context, body, verified, before);
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* One idle pass: promote probation drafts that earned it, then verify and publish at most one promoted Gene.
|
|
134
|
+
* Every refusal leaves the Gene local and is retried on a later pass.
|
|
135
|
+
*/
|
|
136
|
+
export async function runCurationTick(deps) {
|
|
137
|
+
const promoted = await algo.autoPromoteProbationGenes(deps.store, deps.review, { by: 'proxy-auto-promote' });
|
|
138
|
+
if (!deps.verifierForRoot)
|
|
139
|
+
return { promoted };
|
|
140
|
+
const candidate = await pendingCandidate(deps);
|
|
141
|
+
if (!candidate)
|
|
142
|
+
return { promoted };
|
|
143
|
+
const result = await curateOne(deps, candidate.context, candidate.gene);
|
|
144
|
+
saveCurrentObservation(deps.contexts, candidate.context, { lastAttempt: { at: deps.now().toISOString(), result } });
|
|
145
|
+
return { promoted, attempted: { geneAssetId: candidate.context.geneAssetId, result } };
|
|
146
|
+
}
|
|
147
|
+
/** Why promoted genes are or are not leaving this machine, for /proxy/status and the plugin's status command. */
|
|
148
|
+
export function curationStatus(contexts, review, verifierAvailable) {
|
|
149
|
+
const all = contexts.list();
|
|
150
|
+
const latest = all.filter((context) => context.lastAttempt)
|
|
151
|
+
.sort((a, b) => (b.lastAttempt.at).localeCompare(a.lastAttempt.at))[0];
|
|
152
|
+
return {
|
|
153
|
+
publish_verifier: verifierAvailable ? 'available' : 'unavailable',
|
|
154
|
+
...(verifierAvailable ? {} : { publish_verifier_reason: 'read_only_isolation_unavailable' }),
|
|
155
|
+
awaiting_verification: all.filter((context) => awaitsVerification(context) && review.get(context.geneAssetId)?.state === 'approved').length,
|
|
156
|
+
published: all.filter((context) => context.published).length,
|
|
157
|
+
...(latest ? { last_attempt: { gene_asset_id: latest.geneAssetId, result: latest.lastAttempt.result, at: latest.lastAttempt.at } } : {}),
|
|
158
|
+
};
|
|
159
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { VerificationContext } from './observedEvidence.js';
|
|
2
|
+
export declare class RecordedTreeMismatch extends Error {
|
|
3
|
+
}
|
|
4
|
+
/** All checkout and patch operations use our own config and index, even for a linked source worktree. */
|
|
5
|
+
export declare function createRecordedCheckout(context: VerificationContext, parent: string): Promise<string>;
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { execFile } from 'node:child_process';
|
|
2
|
+
import { accessSync, closeSync, constants, fstatSync, lstatSync, openSync, readSync, realpathSync, statSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import { delimiter, isAbsolute, join, relative, resolve, sep } from 'node:path';
|
|
4
|
+
import { exec } from '@evomap/evolver-core';
|
|
5
|
+
const GIT_TIMEOUT_MS = 60_000;
|
|
6
|
+
const GIT_POINTER_MAX_BYTES = 8192;
|
|
7
|
+
const GIT_CONFIG_MAX_BYTES = 1024 * 1024;
|
|
8
|
+
const PATCH_REJECTION = /^error: (?:patch failed: .+|.+: patch does not apply|binary patch does not apply to '.+'|corrupt patch at line \d+|No valid patches in input \(allow with "--allow-empty"\))$/;
|
|
9
|
+
const SAFE_GIT_OPTIONS = [
|
|
10
|
+
'--no-pager', '-c', 'core.hooksPath=/dev/null', '-c', 'core.fsmonitor=false',
|
|
11
|
+
'-c', 'core.attributesFile=/dev/null', '-c', 'core.autocrlf=false',
|
|
12
|
+
'-c', 'submodule.recurse=false', '-c', 'protocol.allow=never',
|
|
13
|
+
'-c', 'gc.auto=0', '-c', 'maintenance.auto=false',
|
|
14
|
+
];
|
|
15
|
+
export class RecordedTreeMismatch extends Error {
|
|
16
|
+
}
|
|
17
|
+
function inside(root, path) {
|
|
18
|
+
const name = relative(root, path);
|
|
19
|
+
return name !== '..' && !name.startsWith(`..${sep}`) && !isAbsolute(name);
|
|
20
|
+
}
|
|
21
|
+
function hostGit(root, env) {
|
|
22
|
+
const executable = process.platform === 'win32' ? 'git.exe' : 'git';
|
|
23
|
+
for (const directory of env['PATH']?.split(delimiter) ?? []) {
|
|
24
|
+
if (!isAbsolute(directory))
|
|
25
|
+
continue;
|
|
26
|
+
try {
|
|
27
|
+
const file = realpathSync.native(join(directory, executable));
|
|
28
|
+
if (inside(root, file) || !statSync(file).isFile())
|
|
29
|
+
continue;
|
|
30
|
+
accessSync(file, constants.X_OK);
|
|
31
|
+
return file;
|
|
32
|
+
}
|
|
33
|
+
catch { /* Look for the next native Git on the daemon PATH. */ }
|
|
34
|
+
}
|
|
35
|
+
throw new Error('curation Git executable unavailable outside source checkout');
|
|
36
|
+
}
|
|
37
|
+
function readGitFile(path, limit) {
|
|
38
|
+
let original;
|
|
39
|
+
try {
|
|
40
|
+
original = lstatSync(path);
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
if (error.code === 'ENOENT')
|
|
44
|
+
return undefined;
|
|
45
|
+
throw error;
|
|
46
|
+
}
|
|
47
|
+
if (!original.isFile() || original.size >= limit)
|
|
48
|
+
throw new Error('invalid curation Git metadata');
|
|
49
|
+
const fd = openSync(path, constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0) | (constants.O_NONBLOCK ?? 0));
|
|
50
|
+
try {
|
|
51
|
+
const stat = fstatSync(fd);
|
|
52
|
+
if (!stat.isFile() || stat.dev !== original.dev || stat.ino !== original.ino || stat.size !== original.size) {
|
|
53
|
+
throw new Error('curation Git metadata changed');
|
|
54
|
+
}
|
|
55
|
+
const bytes = Buffer.alloc(stat.size + 1);
|
|
56
|
+
const count = readSync(fd, bytes, 0, bytes.length, 0);
|
|
57
|
+
if (count !== stat.size)
|
|
58
|
+
throw new Error('curation Git metadata changed');
|
|
59
|
+
return bytes.subarray(0, count);
|
|
60
|
+
}
|
|
61
|
+
finally {
|
|
62
|
+
closeSync(fd);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
function readGitPointer(path, prefix) {
|
|
66
|
+
const bytes = readGitFile(path, GIT_POINTER_MAX_BYTES);
|
|
67
|
+
if (bytes === undefined)
|
|
68
|
+
return undefined;
|
|
69
|
+
const line = new TextDecoder('utf-8', { fatal: true }).decode(bytes).replace(/\r?\n$/, '');
|
|
70
|
+
if (!line.startsWith(prefix) || line.length <= prefix.length || /[\0\r\n]/.test(line)) {
|
|
71
|
+
throw new Error('invalid curation Git pointer');
|
|
72
|
+
}
|
|
73
|
+
return line.slice(prefix.length);
|
|
74
|
+
}
|
|
75
|
+
function sourceGitDirectory(root) {
|
|
76
|
+
const dotGit = join(root, '.git');
|
|
77
|
+
const gitDir = lstatSync(dotGit).isDirectory() ? dotGit : resolve(root, readGitPointer(dotGit, 'gitdir: ') ?? '');
|
|
78
|
+
if (gitDir === root)
|
|
79
|
+
throw new Error('curation Git directory unavailable');
|
|
80
|
+
const common = readGitPointer(join(gitDir, 'commondir'), '');
|
|
81
|
+
return realpathSync.native(common === undefined ? gitDir : resolve(gitDir, common));
|
|
82
|
+
}
|
|
83
|
+
function rejectsRecordedTree(args, diagnostic) {
|
|
84
|
+
if (args[0] === 'rev-parse')
|
|
85
|
+
return diagnostic === 'fatal: Needed a single revision';
|
|
86
|
+
return args[0] === 'apply' && diagnostic.split(/\r?\n/).every((line) => PATCH_REJECTION.test(line));
|
|
87
|
+
}
|
|
88
|
+
function gitRunner(bin, env) {
|
|
89
|
+
return (args, cwd, input) => new Promise((resolve, reject) => {
|
|
90
|
+
const child = execFile(bin, [...SAFE_GIT_OPTIONS, ...args], {
|
|
91
|
+
cwd, timeout: GIT_TIMEOUT_MS, encoding: 'utf8', env,
|
|
92
|
+
}, (error, stdout, stderr) => {
|
|
93
|
+
const diagnostic = stderr.trim();
|
|
94
|
+
if (!error || (args[0] === 'config' && error.code === 1 && !diagnostic)) {
|
|
95
|
+
resolve(stdout.trim());
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
const mismatch = typeof error.code === 'number' && !error.killed && !error.signal && rejectsRecordedTree(args, diagnostic);
|
|
99
|
+
reject(mismatch ? new RecordedTreeMismatch('recorded Git tree mismatch') : error);
|
|
100
|
+
});
|
|
101
|
+
if (input !== undefined)
|
|
102
|
+
child.stdin?.on('error', () => { }).end(input);
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
/** All checkout and patch operations use our own config and index, even for a linked source worktree. */
|
|
106
|
+
export async function createRecordedCheckout(context, parent) {
|
|
107
|
+
const root = realpathSync.native(context.root);
|
|
108
|
+
const gitDir = sourceGitDirectory(root);
|
|
109
|
+
const objects = realpathSync.native(join(gitDir, 'objects'));
|
|
110
|
+
if (!statSync(objects).isDirectory() || /[\0\r\n]/.test(objects))
|
|
111
|
+
throw new Error('invalid curation Git object directory');
|
|
112
|
+
const nullDevice = '/dev/null';
|
|
113
|
+
const env = {
|
|
114
|
+
...exec.scrubAgentEnv(process.env),
|
|
115
|
+
LC_ALL: 'C', LANGUAGE: 'C',
|
|
116
|
+
GIT_CONFIG_NOSYSTEM: '1', GIT_CONFIG_SYSTEM: nullDevice, GIT_CONFIG_GLOBAL: nullDevice,
|
|
117
|
+
GIT_ATTR_NOSYSTEM: '1', GIT_TERMINAL_PROMPT: '0', GIT_NO_LAZY_FETCH: '1', GIT_NO_REPLACE_OBJECTS: '1',
|
|
118
|
+
// An explicit ceiling keeps the metadata-only config command outside any ancestor repository.
|
|
119
|
+
GIT_CEILING_DIRECTORIES: parent,
|
|
120
|
+
};
|
|
121
|
+
const git = gitRunner(hostGit(root, env), env);
|
|
122
|
+
const sourceConfig = readGitFile(join(gitDir, 'config'), GIT_CONFIG_MAX_BYTES);
|
|
123
|
+
if (!sourceConfig)
|
|
124
|
+
throw new Error('curation Git config unavailable');
|
|
125
|
+
const configured = await git(['config', '--file', '-', '--no-includes', '--get', 'extensions.objectFormat'], parent, sourceConfig);
|
|
126
|
+
const format = configured || 'sha1';
|
|
127
|
+
if (format !== 'sha1' && format !== 'sha256')
|
|
128
|
+
throw new Error('unsupported curation Git object format');
|
|
129
|
+
const copy = join(parent, 'tree');
|
|
130
|
+
await git(['init', '--quiet', '--template=', `--object-format=${format}`, '--', copy], parent);
|
|
131
|
+
// Git reads alternate objects but writes all local metadata and new objects to the disposable repository.
|
|
132
|
+
// Only tracked attributes can select built-in checkout conversions; the source's filter config is absent.
|
|
133
|
+
const objectPath = process.platform === 'win32' ? objects.replaceAll('\\', '/') : objects;
|
|
134
|
+
writeFileSync(join(copy, '.git', 'objects', 'info', 'alternates'), `${objectPath}\n`, { flag: 'wx', mode: 0o600 });
|
|
135
|
+
const commit = await git(['rev-parse', '--verify', '--end-of-options', `${context.head}^{commit}`], copy);
|
|
136
|
+
await git(['checkout', '--quiet', '--detach', commit], copy);
|
|
137
|
+
if (context.diff)
|
|
138
|
+
await git(['apply', '--whitespace=nowarn', '-'], copy, context.diff);
|
|
139
|
+
return copy;
|
|
140
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { assetstore, hub as hubNs } from '@evomap/evolver-core';
|
|
2
|
+
type DistillOutcomeStatus = 'stored' | 'draft' | 'rejected' | 'skipped';
|
|
3
|
+
export interface DistillOutcome {
|
|
4
|
+
at: string;
|
|
5
|
+
status: DistillOutcomeStatus;
|
|
6
|
+
reason?: string;
|
|
7
|
+
}
|
|
8
|
+
export interface DistillationStatus {
|
|
9
|
+
window_hours: number;
|
|
10
|
+
stored: number;
|
|
11
|
+
drafts: number;
|
|
12
|
+
/** Drafts the quality gate refused, by reason. */
|
|
13
|
+
rejected: Record<string, number>;
|
|
14
|
+
/** Requests that never became a draft (IR structure, references, contracts, repairs, too little to go on), by reason. */
|
|
15
|
+
skipped: Record<string, number>;
|
|
16
|
+
}
|
|
17
|
+
export interface TrialControl {
|
|
18
|
+
asset_id: string;
|
|
19
|
+
withheld_id: string;
|
|
20
|
+
task_id: string;
|
|
21
|
+
passed: boolean;
|
|
22
|
+
platform?: string;
|
|
23
|
+
at: string;
|
|
24
|
+
}
|
|
25
|
+
interface TrialArm {
|
|
26
|
+
runs: number;
|
|
27
|
+
passed: number;
|
|
28
|
+
}
|
|
29
|
+
export interface TrialEffect {
|
|
30
|
+
gene_asset_id: string;
|
|
31
|
+
title: string;
|
|
32
|
+
treated: TrialArm;
|
|
33
|
+
control: TrialArm;
|
|
34
|
+
}
|
|
35
|
+
export declare function distillOutcomeOf(result: hubNs.ConversationDistillResult, at: Date): DistillOutcome;
|
|
36
|
+
export declare class DistillOutcomeLog {
|
|
37
|
+
private readonly log;
|
|
38
|
+
constructor(assetStoreDir: string);
|
|
39
|
+
record(outcome: DistillOutcome): void;
|
|
40
|
+
summary(now: Date): DistillationStatus;
|
|
41
|
+
}
|
|
42
|
+
export declare class TrialControlLog {
|
|
43
|
+
private readonly log;
|
|
44
|
+
private readonly withholdings;
|
|
45
|
+
constructor(assetStoreDir: string);
|
|
46
|
+
/** Records one withholding and names it; the turn that went without the draft reports its control under this id. */
|
|
47
|
+
withheld(assetId: string, at: Date): string;
|
|
48
|
+
/** A control counts only against the withholding it names: of that draft, in the last day, and only once. */
|
|
49
|
+
record(entry: TrialControl): 'recorded' | 'duplicate' | 'not_withheld';
|
|
50
|
+
list(): TrialControl[];
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Keyed by the Gene's own id, not its asset id: the asset id also hashes runtime metadata (model, `env_class`), so the
|
|
54
|
+
* same draft would land in another arm on another machine.
|
|
55
|
+
*/
|
|
56
|
+
export declare function isTrialHoldout(geneId: string, recallText: string): boolean;
|
|
57
|
+
/** Each trial draft with a control arm: how often checks passed with it recalled, and without. */
|
|
58
|
+
export declare function trialEffect(store: assetstore.AssetStoreProvider, controls: TrialControlLog): Promise<TrialEffect[]>;
|
|
59
|
+
export {};
|