@evomap/evolver-cli 2.0.36 → 2.0.37
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/antiGeneRollout.d.ts +2 -0
- package/dist/antiGeneRollout.js +21 -3
- package/dist/assetTrust.js +9 -0
- package/dist/atpAutoDeliver.d.ts +10 -0
- package/dist/atpAutoDeliver.js +28 -1
- package/dist/autoRecall.js +8 -4
- package/dist/autoexec.d.ts +15 -0
- package/dist/autoexec.js +139 -7
- package/dist/autoexecConfig.d.ts +1 -1
- package/dist/autoexecConfig.js +1 -1
- package/dist/cursorRewrite.d.ts +6 -0
- package/dist/cursorRewrite.js +64 -6
- package/dist/cycleConsumer.js +1 -0
- package/dist/index.js +11 -3
- package/dist/promptRecallHook.js +11 -4
- package/dist/recall.d.ts +2 -0
- package/dist/recall.js +19 -1
- package/dist/referenceAccess.d.ts +3 -0
- package/dist/referenceAccess.js +232 -0
- package/dist/reviewFilter.d.ts +1 -1
- package/dist/reviewFilter.js +12 -1
- package/dist/sourceQualification.d.ts +2 -0
- package/dist/sourceQualification.js +120 -0
- package/dist/taskCommitments.d.ts +135 -0
- package/dist/taskCommitments.js +492 -0
- package/dist/taskReceiver.d.ts +151 -0
- package/dist/taskReceiver.js +459 -0
- package/dist/thesis.d.ts +3 -0
- package/dist/thesis.js +122 -100
- package/dist/workflowRuntime.js +13 -2
- package/package.json +7 -7
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { assetstore, benchmark, events, exec } from '@evomap/evolver-core';
|
|
2
2
|
export interface AntiGeneRolloutCommandDeps {
|
|
3
|
+
env?: Readonly<NodeJS.ProcessEnv>;
|
|
4
|
+
provenance?: assetstore.ProvenanceStore;
|
|
3
5
|
store?: assetstore.AssetStoreProvider;
|
|
4
6
|
review?: assetstore.ReviewLedger;
|
|
5
7
|
readEvents?: (eventsPath?: string) => events.ReportEvent[];
|
package/dist/antiGeneRollout.js
CHANGED
|
@@ -194,7 +194,7 @@ function validationCommand(commandLine, cwd) {
|
|
|
194
194
|
});
|
|
195
195
|
}
|
|
196
196
|
function liveMakeExecute(repo, runner, validation, deps = {}) {
|
|
197
|
-
return ({ store, review }) => {
|
|
197
|
+
return ({ store, review, provenance, benchmark: sourceBenchmark }) => {
|
|
198
198
|
const validate = async (_mutation, _decision, cwd) => {
|
|
199
199
|
for (const command of validation) {
|
|
200
200
|
if (await validationCommand(command, cwd) !== 0)
|
|
@@ -207,6 +207,7 @@ function liveMakeExecute(repo, runner, validation, deps = {}) {
|
|
|
207
207
|
...(runner ? { runner } : {}),
|
|
208
208
|
}, {
|
|
209
209
|
review,
|
|
210
|
+
...(sourceBenchmark ? { benchmark: sourceBenchmark, provenance } : {}),
|
|
210
211
|
validate,
|
|
211
212
|
validationCmds: validation,
|
|
212
213
|
...(deps.agent ? { agent: deps.agent } : {}),
|
|
@@ -240,6 +241,14 @@ export async function runAntiGeneRolloutCommand(argv, deps = {}) {
|
|
|
240
241
|
process.stderr.write(usage);
|
|
241
242
|
return 1;
|
|
242
243
|
}
|
|
244
|
+
let sourceBenchmark;
|
|
245
|
+
try {
|
|
246
|
+
sourceBenchmark = assetstore.benchmarkContext((deps.env ?? process.env)['EVOLVER_BENCHMARK_ID']);
|
|
247
|
+
}
|
|
248
|
+
catch {
|
|
249
|
+
process.stderr.write('anti-gene-rollout: invalid_benchmark_id\n');
|
|
250
|
+
return 1;
|
|
251
|
+
}
|
|
243
252
|
if (flags.minSamples !== undefined && (!Number.isFinite(flags.minSamples) || flags.minSamples < 1)) {
|
|
244
253
|
process.stderr.write('anti-gene-rollout: --min-samples must be >= 1\n');
|
|
245
254
|
return 1;
|
|
@@ -274,12 +283,21 @@ export async function runAntiGeneRolloutCommand(argv, deps = {}) {
|
|
|
274
283
|
return 1;
|
|
275
284
|
}
|
|
276
285
|
const assetsDir = flags.assets ? resolve(flags.assets) : events.assetsDir();
|
|
277
|
-
const reviewDir = flags.reviewDir ? resolve(flags.reviewDir) : assetsDir;
|
|
278
286
|
const store = deps.store ?? new assetstore.LocalJsonlProvider(assetsDir);
|
|
287
|
+
if (sourceBenchmark && !(store instanceof assetstore.LocalJsonlProvider)
|
|
288
|
+
&& (!deps.provenance || (!deps.review && !flags.reviewDir))) {
|
|
289
|
+
process.stderr.write('anti-gene-rollout: benchmark_source_ledgers_required\n');
|
|
290
|
+
return 1;
|
|
291
|
+
}
|
|
292
|
+
const reviewDir = flags.reviewDir ? resolve(flags.reviewDir)
|
|
293
|
+
: sourceBenchmark && store instanceof assetstore.LocalJsonlProvider ? store.baseDir : assetsDir;
|
|
279
294
|
const review = deps.review ?? new assetstore.ReviewLedger(reviewDir, deps.now);
|
|
280
295
|
const eventsPath = flags.events ? resolve(flags.events) : join(mkdtempSync(join(tmpdir(), 'anti-gene-rollout-events-')), 'root_events.jsonl');
|
|
281
296
|
const makeExecute = deps.makeExecute ?? liveMakeExecute(resolve(flags.repo), flags.runner, suite.validation, deps);
|
|
282
|
-
const report = await benchmark.runAntiGeneRollout(suite, { store, review, makeExecute
|
|
297
|
+
const report = await benchmark.runAntiGeneRollout(suite, { store, review, makeExecute,
|
|
298
|
+
...(deps.provenance ? { provenance: deps.provenance } : {}),
|
|
299
|
+
}, {
|
|
300
|
+
...(sourceBenchmark ? { benchmark: sourceBenchmark } : {}),
|
|
283
301
|
eventsPath,
|
|
284
302
|
now: deps.now,
|
|
285
303
|
...(!semanticIdfEnabled() ? { disableSemanticIdf: true } : {}),
|
package/dist/assetTrust.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { assetstore, events, hub } from '@evomap/evolver-core';
|
|
2
2
|
import { loadEnvFileFromEnv } from '@evomap/evolver-mcp';
|
|
3
|
+
import { runSourceQualificationCommand } from './sourceQualification.js';
|
|
4
|
+
import { runReferenceAccessCommand } from './referenceAccess.js';
|
|
3
5
|
const GROUP = 'asset-trust';
|
|
4
6
|
const DEFAULT_LIMIT = 50;
|
|
5
7
|
const MAX_LIMIT = 200;
|
|
@@ -13,6 +15,9 @@ const USAGE = [
|
|
|
13
15
|
' evolver asset-trust show <asset_id> [--json]',
|
|
14
16
|
' evolver asset-trust promote <asset_id> --reason <text> [--json]',
|
|
15
17
|
' evolver asset-trust revoke <asset_id> --reason <text> [--json]',
|
|
18
|
+
' evolver asset-trust qualify <asset_id> --evidence <file> --reason <text> [--exception <reason>] [--json]',
|
|
19
|
+
' evolver asset-trust qualification <asset_id> --benchmark <id> [--evidence-digest <sha256>] [--json]',
|
|
20
|
+
' evolver asset-trust access <replay|get|read> --help',
|
|
16
21
|
'',
|
|
17
22
|
].join('\n');
|
|
18
23
|
function parseArgs(argv) {
|
|
@@ -133,6 +138,10 @@ async function recordTrustEvent(ingestor, action, view, reason, actorId) {
|
|
|
133
138
|
}
|
|
134
139
|
}
|
|
135
140
|
export async function runAssetTrustCommand(argv, deps = {}) {
|
|
141
|
+
if (argv[0] === 'access')
|
|
142
|
+
return runReferenceAccessCommand(argv.slice(1), deps);
|
|
143
|
+
if (argv[0] === 'qualify' || argv[0] === 'qualification')
|
|
144
|
+
return runSourceQualificationCommand(argv, deps, safeActorId);
|
|
136
145
|
const stdout = deps.stdout ?? ((text) => { process.stdout.write(text); });
|
|
137
146
|
const stderr = deps.stderr ?? ((text) => { process.stderr.write(text); });
|
|
138
147
|
if (argv.includes('--help') || argv.includes('-h')) {
|
package/dist/atpAutoDeliver.d.ts
CHANGED
|
@@ -9,6 +9,12 @@ export declare const ATP_AUTODELIVER_COOLDOWN_CAP_MS: number;
|
|
|
9
9
|
export interface AtpAutoDeliverClient {
|
|
10
10
|
listMyTasks(limit?: number, nodeId?: string): Promise<AtpResult>;
|
|
11
11
|
submitDelivery(orderId: string, proofPayload?: unknown): Promise<AtpResult>;
|
|
12
|
+
/**
|
|
13
|
+
* The node this client authenticates as — the only node its deliveries can be for.
|
|
14
|
+
* Optional so an older injected client still compiles and still runs; not answering is
|
|
15
|
+
* simply not being trusted, because there is no fallback identity to guess with.
|
|
16
|
+
*/
|
|
17
|
+
nodeId?(): string | undefined;
|
|
12
18
|
}
|
|
13
19
|
export interface AtpAutoDeliverLedger {
|
|
14
20
|
version: 2;
|
|
@@ -23,6 +29,8 @@ export interface AtpAutoDeliverTickResult {
|
|
|
23
29
|
checked: number;
|
|
24
30
|
delivered: number;
|
|
25
31
|
skippedTasks: number;
|
|
32
|
+
/** Tasks another node holds. Delivering those is what the Hub rejects. */
|
|
33
|
+
skippedForeign: number;
|
|
26
34
|
terminalFailures: number;
|
|
27
35
|
transientFailures: number;
|
|
28
36
|
/** 429 rate-limit hits this tick — backed off (a subset of "failed", tracked apart for observability). */
|
|
@@ -30,6 +38,8 @@ export interface AtpAutoDeliverTickResult {
|
|
|
30
38
|
}
|
|
31
39
|
export interface AtpAutoDeliverDeps {
|
|
32
40
|
client?: AtpAutoDeliverClient;
|
|
41
|
+
/** Which node we are. A task claimed by anyone else is not ours to deliver. */
|
|
42
|
+
nodeId?: string;
|
|
33
43
|
createClient?: (env: NodeJS.ProcessEnv) => AtpAutoDeliverClient;
|
|
34
44
|
env?: NodeJS.ProcessEnv;
|
|
35
45
|
ledgerPath?: string;
|
package/dist/atpAutoDeliver.js
CHANGED
|
@@ -11,7 +11,7 @@ export const ATP_AUTODELIVER_LEDGER_MAX_ENTRIES = 500;
|
|
|
11
11
|
// capped. The first 429 waits BASE; subsequent ones BASE*2^(hits-1) up to CAP.
|
|
12
12
|
export const ATP_AUTODELIVER_COOLDOWN_BASE_MS = 5 * 60_000; // 5 min
|
|
13
13
|
export const ATP_AUTODELIVER_COOLDOWN_CAP_MS = 6 * 60 * 60_000; // 6 h
|
|
14
|
-
const EMPTY_TICK = { checked: 0, delivered: 0, skippedTasks: 0, terminalFailures: 0, transientFailures: 0, cooldownFailures: 0 };
|
|
14
|
+
const EMPTY_TICK = { checked: 0, delivered: 0, skippedTasks: 0, skippedForeign: 0, terminalFailures: 0, transientFailures: 0, cooldownFailures: 0 };
|
|
15
15
|
export function isAtpAutoDeliverEnabled(env = process.env) {
|
|
16
16
|
const raw = (env['EVOLVER_ATP_AUTODELIVER'] ?? 'on').toLowerCase().trim();
|
|
17
17
|
return raw !== 'off' && raw !== '0' && raw !== 'false';
|
|
@@ -38,6 +38,24 @@ export async function runAtpAutoDeliverTick(deps = {}) {
|
|
|
38
38
|
const nowMs = deps.nowMs ?? (() => Date.now());
|
|
39
39
|
const log = deps.log ?? (() => { });
|
|
40
40
|
const out = { ...EMPTY_TICK };
|
|
41
|
+
// The identity that filters has to BE the identity that submits. The client is the one
|
|
42
|
+
// that will be on the wire, so when it can name itself it decides — a caller-supplied
|
|
43
|
+
// nodeId only fills in for a client that cannot, and a caller that disagrees with the
|
|
44
|
+
// credentials is a misconfiguration whose every delivery the Hub would reject anyway.
|
|
45
|
+
// Called defensively: a client from before this method existed is a stranger, not a
|
|
46
|
+
// crash. It delivers nothing either way, but it fails the check rather than the process.
|
|
47
|
+
const nodeId = typeof client.nodeId === 'function' ? client.nodeId() : undefined;
|
|
48
|
+
if (deps.nodeId && nodeId && deps.nodeId !== nodeId) {
|
|
49
|
+
log(`[ATP-AutoDeliver] refusing to deliver: asked to act as ${deps.nodeId} with ${nodeId}'s credentials`);
|
|
50
|
+
return out;
|
|
51
|
+
}
|
|
52
|
+
// Only the submitting client's own credentials can say whose work this is. An env or
|
|
53
|
+
// caller-supplied id is unbound to them, and filtering by one identity while submitting
|
|
54
|
+
// as another is the separation this check exists to stop. Fail closed, loudly.
|
|
55
|
+
if (!nodeId) {
|
|
56
|
+
log('[ATP-AutoDeliver] the hub client cannot name the node it authenticates as; refusing to deliver (ownership cannot be checked)');
|
|
57
|
+
return out;
|
|
58
|
+
}
|
|
41
59
|
try {
|
|
42
60
|
const listed = await client.listMyTasks(deps.limit ?? 20);
|
|
43
61
|
if (!listed.ok)
|
|
@@ -68,6 +86,15 @@ export async function runAtpAutoDeliverTick(deps = {}) {
|
|
|
68
86
|
out.skippedTasks += 1;
|
|
69
87
|
continue;
|
|
70
88
|
}
|
|
89
|
+
// /a2a/task/my answers with every task this node can see, including ones another
|
|
90
|
+
// node claimed. Delivering someone else's work is what the Hub rejects (#1168).
|
|
91
|
+
// A task that names no claimant proves nothing either: "not visibly someone else's"
|
|
92
|
+
// is not "ours", so only an explicit match gets delivered.
|
|
93
|
+
const claimedBy = taskString(task, 'claimed_by') ?? taskString(task, 'claimedBy');
|
|
94
|
+
if (claimedBy !== nodeId) {
|
|
95
|
+
out.skippedForeign += 1;
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
71
98
|
const status = taskString(task, 'status') ?? taskString(task, 'task_status');
|
|
72
99
|
if (status && status !== 'claimed' && status !== 'completed') {
|
|
73
100
|
out.skippedTasks += 1;
|
package/dist/autoRecall.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
// This feeds the experience loop with OBSERVED data, turning the inert manual `evolver recall` into the loop's
|
|
5
5
|
// real, unbiased input. PURE-ish + injectable; best-effort + never throws (it must never break session ingest).
|
|
6
6
|
import { events, ops, assetstore } from '@evomap/evolver-core';
|
|
7
|
-
import { sessionIdFromTranscript, pickInjectEvent, geneIdsOf,
|
|
7
|
+
import { sessionIdFromTranscript, pickInjectEvent, geneIdsOf, geneFromRecallSelection, resolveGene } from './recall.js';
|
|
8
8
|
/**
|
|
9
9
|
* Derive + emit `value.recall` for ONE session transcript. Returns the number of verdicts emitted (0 when there is
|
|
10
10
|
* no matching inject, no resolvable gene, or the session was already recalled). Idempotent: a session whose
|
|
@@ -49,8 +49,11 @@ export async function emitSessionRecall(transcriptPath, turns, deps) {
|
|
|
49
49
|
const genes = [];
|
|
50
50
|
for (const id of geneIds) {
|
|
51
51
|
const a = await resolveGene(store, id);
|
|
52
|
-
if (a)
|
|
53
|
-
|
|
52
|
+
if (a) {
|
|
53
|
+
const gene = geneFromRecallSelection(a, id, inject);
|
|
54
|
+
if (gene)
|
|
55
|
+
genes.push(gene);
|
|
56
|
+
}
|
|
54
57
|
}
|
|
55
58
|
if (genes.length === 0)
|
|
56
59
|
return 0;
|
|
@@ -65,7 +68,8 @@ export async function emitSessionRecall(transcriptPath, turns, deps) {
|
|
|
65
68
|
try {
|
|
66
69
|
await deps.ingestor.ingest({
|
|
67
70
|
type: ops.VALUE_RECALL_EVENT,
|
|
68
|
-
|
|
71
|
+
// 展示标题遵守既有 80 字符上限;payload 中的完整版本身份不能截断。
|
|
72
|
+
human: { title: `recall ${r.recalled}: ${r.geneId}`.slice(0, 80), detail: `session ${sessionId}` },
|
|
69
73
|
payload: payload,
|
|
70
74
|
});
|
|
71
75
|
emitted += 1;
|
package/dist/autoexec.d.ts
CHANGED
|
@@ -32,6 +32,12 @@ export interface AutoExecDirs {
|
|
|
32
32
|
/** Create the queue layout under <home>/autoexec/{tasks,inflight,done,refused}. */
|
|
33
33
|
export declare function ensureAutoExecDirs(base: string): AutoExecDirs;
|
|
34
34
|
export declare function summarizeSandboxedValidation(result: verify.SandboxedValidationResult): string | null;
|
|
35
|
+
/**
|
|
36
|
+
* Whether a claim for this queue id is already checked out to the exec pass. The name has
|
|
37
|
+
* to match on both ends — `--hub-1` is a prefix of `--hub-10`, and treating one task as
|
|
38
|
+
* another's execution either strands it until its commitment lapses or runs it twice.
|
|
39
|
+
*/
|
|
40
|
+
export declare function hasInflightClaim(dirs: AutoExecDirs, queueTaskId: string): boolean;
|
|
35
41
|
/**
|
|
36
42
|
* One queue pass: atomically claim regular tasks/*.json into inflight/, then route each verdict to done/
|
|
37
43
|
* (success or failure) or refused/ (deny-by-default). A claim is atomically marked started before runOne;
|
|
@@ -41,6 +47,15 @@ export declare function summarizeSandboxedValidation(result: verify.SandboxedVal
|
|
|
41
47
|
export declare function autoExecPass(dirs: AutoExecDirs, runOne: (task: exec.AutoExecTask) => Promise<exec.AutoExecVerdict>, options?: {
|
|
42
48
|
executePendingTasks?: boolean;
|
|
43
49
|
}): Promise<exec.AutoExecVerdict[]>;
|
|
50
|
+
/**
|
|
51
|
+
* Which repo Hub tasks land in. A Hub task does not say which one it belongs to, so a
|
|
52
|
+
* multi-repo allowlist cannot be spread across — one receiver serves one repo. Silently
|
|
53
|
+
* taking the first is a guess the operator never made, so EVOLVER_TASK_RECEIVER_REPO lets
|
|
54
|
+
* them say; it must still be allowlisted, or the receiver has no repo and stays off.
|
|
55
|
+
*/
|
|
56
|
+
export declare function taskReceiverRepo(env: NodeJS.ProcessEnv, allowedRoots: readonly string[]): string | undefined;
|
|
57
|
+
/** Runners cleared to take work off the queue, rather than only keeping the daemon alive. */
|
|
58
|
+
export declare function canExecuteQueue(runner: exec.RunnerName): boolean;
|
|
44
59
|
/** Keep unsupported built-in runners away from the execution queue without stopping the resident daemon. */
|
|
45
60
|
export declare function runnerBoundAutoExecPass(runner: exec.RunnerName, dirs: AutoExecDirs, runOne: (task: exec.AutoExecTask) => Promise<exec.AutoExecVerdict>): () => Promise<exec.AutoExecVerdict[]>;
|
|
46
61
|
/**
|
package/dist/autoexec.js
CHANGED
|
@@ -22,6 +22,7 @@ import { runTranscriptDistillTick, transcriptDistillMode } from './autoDistillTr
|
|
|
22
22
|
import { runSessionIngestTick, scanSessionDirs } from './sessionIngest.js';
|
|
23
23
|
import { LocalMemoryGraph, resolveLocalMemoryUserIdentity } from './localMemoryGraph.js';
|
|
24
24
|
import { resolveAtpAutoDeliver } from './atpAutoDeliver.js';
|
|
25
|
+
import { memoryEventsFromCycleLog, resolveTaskReceiver } from './taskReceiver.js';
|
|
25
26
|
import { createAtpClientFromEnv, getAtpConsent, resolveAtpHome, resolveAtpSenderId } from './atp.js';
|
|
26
27
|
import { AtpAutoBuyer } from './atpAutoBuyer.js';
|
|
27
28
|
import { resolveExplicitNodeCredentials, resolveIdentityHome } from './identityHome.js';
|
|
@@ -178,6 +179,18 @@ function parseAutoExecClaim(name) {
|
|
|
178
179
|
}
|
|
179
180
|
return encodedName.endsWith('.json') ? { name, originalName: encodedName, phase: 'legacy' } : null;
|
|
180
181
|
}
|
|
182
|
+
/**
|
|
183
|
+
* Whether a claim for this queue id is already checked out to the exec pass. The name has
|
|
184
|
+
* to match on both ends — `--hub-1` is a prefix of `--hub-10`, and treating one task as
|
|
185
|
+
* another's execution either strands it until its commitment lapses or runs it twice.
|
|
186
|
+
*/
|
|
187
|
+
export function hasInflightClaim(dirs, queueTaskId) {
|
|
188
|
+
// `.json` is the pre-suffix layout a running daemon may still have on disk after an
|
|
189
|
+
// upgrade; parseAutoExecClaim reads those as legacy claims, so this has to see them too.
|
|
190
|
+
const suffixes = [CLAIMED_TASK_SUFFIX, STARTED_TASK_SUFFIX, '.json'];
|
|
191
|
+
return readdirSync(dirs.inflight)
|
|
192
|
+
.some((name) => suffixes.some((suffix) => name.endsWith(`--${queueTaskId}${suffix}`)));
|
|
193
|
+
}
|
|
181
194
|
function taskClaimName(originalName) {
|
|
182
195
|
return `${randomUUID()}--${originalName.slice(0, -'.json'.length)}${CLAIMED_TASK_SUFFIX}`;
|
|
183
196
|
}
|
|
@@ -341,9 +354,25 @@ export async function autoExecPass(dirs, runOne, options = {}) {
|
|
|
341
354
|
cleanupOrphanReceiptArtifacts(dirs);
|
|
342
355
|
return out;
|
|
343
356
|
}
|
|
357
|
+
/**
|
|
358
|
+
* Which repo Hub tasks land in. A Hub task does not say which one it belongs to, so a
|
|
359
|
+
* multi-repo allowlist cannot be spread across — one receiver serves one repo. Silently
|
|
360
|
+
* taking the first is a guess the operator never made, so EVOLVER_TASK_RECEIVER_REPO lets
|
|
361
|
+
* them say; it must still be allowlisted, or the receiver has no repo and stays off.
|
|
362
|
+
*/
|
|
363
|
+
export function taskReceiverRepo(env, allowedRoots) {
|
|
364
|
+
const chosen = env['EVOLVER_TASK_RECEIVER_REPO']?.trim();
|
|
365
|
+
if (!chosen)
|
|
366
|
+
return allowedRoots[0];
|
|
367
|
+
return allowedRoots.includes(chosen) ? chosen : undefined;
|
|
368
|
+
}
|
|
369
|
+
/** Runners cleared to take work off the queue, rather than only keeping the daemon alive. */
|
|
370
|
+
export function canExecuteQueue(runner) {
|
|
371
|
+
return runner === 'gemini' || runner === 'llm';
|
|
372
|
+
}
|
|
344
373
|
/** Keep unsupported built-in runners away from the execution queue without stopping the resident daemon. */
|
|
345
374
|
export function runnerBoundAutoExecPass(runner, dirs, runOne) {
|
|
346
|
-
return () => autoExecPass(dirs, runOne, { executePendingTasks: runner
|
|
375
|
+
return () => autoExecPass(dirs, runOne, { executePendingTasks: canExecuteQueue(runner) });
|
|
347
376
|
}
|
|
348
377
|
const ATP_CAPABILITY_PATTERN = /^[A-Za-z][A-Za-z0-9_-]{0,47}$/;
|
|
349
378
|
function atpCapabilityGaps(signals) {
|
|
@@ -579,7 +608,8 @@ async function emitReuseHit(ingestor, hit) {
|
|
|
579
608
|
/** Build the same event for byte-budget admission and durable emission. */
|
|
580
609
|
export function injectEvent(info) {
|
|
581
610
|
const payload = {
|
|
582
|
-
geneIds: info.geneIds,
|
|
611
|
+
geneIds: info.sourceQualifications ? info.sourceQualifications.map((item) => item.assetId) : info.geneIds,
|
|
612
|
+
...(info.sourceQualifications ? assetstore.compactQualificationReceipts(info.sourceQualifications) : {}),
|
|
583
613
|
...(info.contentSchema ? { contentSchema: info.contentSchema } : {}),
|
|
584
614
|
...(info.content ? { content: info.content } : {}),
|
|
585
615
|
...(info.omittedByBudget !== undefined ? { omittedByBudget: info.omittedByBudget } : {}),
|
|
@@ -1499,8 +1529,8 @@ export async function runAutoExec(argv) {
|
|
|
1499
1529
|
const home = argv.find((a) => !a.startsWith('-')) ?? join(events.evomapHome(), 'autoexec');
|
|
1500
1530
|
const dirs = ensureAutoExecDirs(home);
|
|
1501
1531
|
const cfg = readAutoExecConfig(home);
|
|
1502
|
-
if (cfg.runner
|
|
1503
|
-
process.stderr.write('evolver autoexec: execute queue is disabled for the configured built-in runner; non-execution daemon duties remain active. Set "runner":"gemini"
|
|
1532
|
+
if (!canExecuteQueue(cfg.runner)) {
|
|
1533
|
+
process.stderr.write('evolver autoexec: execute queue is disabled for the configured built-in runner; non-execution daemon duties remain active. Set "runner":"llm" (no agent CLI needed) or "runner":"gemini" after reviewing its experimental capability boundary\n');
|
|
1504
1534
|
}
|
|
1505
1535
|
// Solo mode (--solo): the "constrained wild" profile. Hard-cut network + ATP
|
|
1506
1536
|
// at the SOURCE — in-process, before any resolve* below reads its env gate — so
|
|
@@ -1589,6 +1619,7 @@ export async function runAutoExec(argv) {
|
|
|
1589
1619
|
};
|
|
1590
1620
|
const deps = withAutoExecSelectionConfig({
|
|
1591
1621
|
engine, store, provenance, review, personality: personalityStore, memoryGraph,
|
|
1622
|
+
...(process.env['EVOLVER_BENCHMARK_ID'] !== undefined ? { benchmark: assetstore.benchmarkContext(process.env['EVOLVER_BENCHMARK_ID']) } : {}),
|
|
1592
1623
|
executionBinding: {
|
|
1593
1624
|
journal: new exec.ExecutionBindingJournal(ingestor),
|
|
1594
1625
|
authority: executionBindingAuthority,
|
|
@@ -1666,9 +1697,23 @@ export async function runAutoExec(argv) {
|
|
|
1666
1697
|
const antiGeneDistill = resolveAutoDistillAntiGene(process.env, { store, review, ingestor });
|
|
1667
1698
|
const transcriptDistill = resolveAutoDistillTranscript(process.env, { store, review, ingestor });
|
|
1668
1699
|
const atpAutoDeliver = resolveAtpAutoDeliver(process.env);
|
|
1700
|
+
const taskReceiver = resolveTaskReceiver(process.env, {
|
|
1701
|
+
repo: taskReceiverRepo(process.env, cfg.allowedRoots),
|
|
1702
|
+
queueDir: dirs.tasks,
|
|
1703
|
+
memoryEvents: () => memoryEventsFromCycleLog(events.readEvents(events.rootEventsPath())),
|
|
1704
|
+
// An unreadable inflight directory is not an empty one: answering "nothing is running"
|
|
1705
|
+
// there would hand the executor a task it may already be running. Say "busy" instead —
|
|
1706
|
+
// a task that waits one beat is recoverable, one run twice is not.
|
|
1707
|
+
inFlight: (queueTaskId) => { try {
|
|
1708
|
+
return hasInflightClaim(dirs, queueTaskId);
|
|
1709
|
+
}
|
|
1710
|
+
catch {
|
|
1711
|
+
return true;
|
|
1712
|
+
} },
|
|
1713
|
+
});
|
|
1669
1714
|
const uninstallBrokenPipeGuards = installAutoexecBrokenPipeGuards();
|
|
1670
1715
|
const reuseEnabled = process.env['EVOLVER_REUSE_BEFORE_SOLVE'] === '1' && hubLink !== undefined;
|
|
1671
|
-
process.stdout.write(`evolver autoexec: runner=${cfg.runner} queue=${dirs.tasks} allowlist=${JSON.stringify(cfg.allowedRoots)} poll=${cfg.pollMs}ms reuse=${reuseEnabled ? 'on' : 'off'} reuse-signal=${reuseSignalOn ? 'on' : 'off'} semantic-idf=${semanticIdfOn ? 'on' : 'off'} selection-policy=${selectionPolicy} selection-guard=${selectionGuard} selection-floor=${selectionFloor === undefined ? 'unset' : selectionFloor} probation=${probationOn ? 'on' : 'off'} questions=${hubQuestionLink ? 'on' : 'off'} permit=${solidifyPermit ? 'on' : 'off'} value-digest=${digest.enabled ? 'on' : 'off'} reflection=${reflection.enabled ? 'on' : 'off'} learning-trace=${learningTrace.enabled ? `on(upload=${learningTrace.upload})` : 'off'} memory-event-mirror=${memoryEventMirror.enabled ? 'on' : `off(${memoryEventMirror.reason ?? 'no_hub'})`} cursor-rewrite=${cursorRewrite.enabled ? 'on' : `off(${cursorRewrite.reason})`} auto-distill=${distill.enabled ? 'on' : 'off'} auto-distill-llm=${llmDistill.enabled ? llmDistill.mode : 'off'} auto-distill-anti-gene=${antiGeneDistill.enabled ? antiGeneDistill.mode : 'off'} auto-distill-transcript=${transcriptDistill.enabled ? transcriptDistill.mode : 'off'} atp-autodeliver=${atpAutoDeliver.enabled ? 'on' : `off(${atpAutoDeliver.reason})`}\n`);
|
|
1716
|
+
process.stdout.write(`evolver autoexec: runner=${cfg.runner} queue=${dirs.tasks} allowlist=${JSON.stringify(cfg.allowedRoots)} poll=${cfg.pollMs}ms reuse=${reuseEnabled ? 'on' : 'off'} reuse-signal=${reuseSignalOn ? 'on' : 'off'} semantic-idf=${semanticIdfOn ? 'on' : 'off'} selection-policy=${selectionPolicy} selection-guard=${selectionGuard} selection-floor=${selectionFloor === undefined ? 'unset' : selectionFloor} probation=${probationOn ? 'on' : 'off'} questions=${hubQuestionLink ? 'on' : 'off'} permit=${solidifyPermit ? 'on' : 'off'} value-digest=${digest.enabled ? 'on' : 'off'} reflection=${reflection.enabled ? 'on' : 'off'} learning-trace=${learningTrace.enabled ? `on(upload=${learningTrace.upload})` : 'off'} memory-event-mirror=${memoryEventMirror.enabled ? 'on' : `off(${memoryEventMirror.reason ?? 'no_hub'})`} cursor-rewrite=${cursorRewrite.enabled ? 'on' : `off(${cursorRewrite.reason})`} auto-distill=${distill.enabled ? 'on' : 'off'} auto-distill-llm=${llmDistill.enabled ? llmDistill.mode : 'off'} auto-distill-anti-gene=${antiGeneDistill.enabled ? antiGeneDistill.mode : 'off'} auto-distill-transcript=${transcriptDistill.enabled ? transcriptDistill.mode : 'off'} atp-autodeliver=${atpAutoDeliver.enabled ? 'on' : `off(${atpAutoDeliver.reason})`} task-receiver=${taskReceiver.enabled ? `on(repo=${taskReceiverRepo(process.env, cfg.allowedRoots)})` : `off(${taskReceiver.reason})`}\n`);
|
|
1672
1717
|
if (cfg.allowedRoots.length === 0)
|
|
1673
1718
|
process.stdout.write(' (allowlist empty → deny-by-default: nothing runs until you add a repo to config.json)\n');
|
|
1674
1719
|
// Single-instance lock (#106): a second daemon on the same home would double-process the queue. That is harmless
|
|
@@ -1720,11 +1765,20 @@ export async function runAutoExec(argv) {
|
|
|
1720
1765
|
const guardedAntiGeneDistill = antiGeneDistill.enabled ? exec.singleFlight(() => antiGeneDistill.tick()) : null;
|
|
1721
1766
|
const guardedTranscriptDistill = transcriptDistill.enabled ? exec.singleFlight(() => transcriptDistill.tick()) : null;
|
|
1722
1767
|
const guardedAtpAutoDeliver = atpAutoDeliver.enabled ? exec.singleFlight(() => atpAutoDeliver.tick()) : null;
|
|
1768
|
+
const guardedTaskReceiver = taskReceiver.enabled ? exec.singleFlight(() => taskReceiver.tick()) : null;
|
|
1723
1769
|
if (distill.observer)
|
|
1724
1770
|
distill.observer.kick(); // recover any un-acked backlog from a prior run (restart)
|
|
1725
1771
|
// One idle-aware resident beat runs the exec pass, ATP auto-delivery, THEN the distill scan (single-flight
|
|
1726
1772
|
// guarded). Idle-aware pacing (#106): an idle machine polls more often, an active one backs off to the base
|
|
1727
1773
|
// cadence. Off via EVOLVER_IDLE_AWARE=0 → fixed cfg.pollMs (exactly the previous behavior).
|
|
1774
|
+
const completionLine = (ack, assetId) => {
|
|
1775
|
+
if (ack.completed)
|
|
1776
|
+
return 'reported';
|
|
1777
|
+
// The asset outlived the claim: name it, or the work is lost with no way back to it.
|
|
1778
|
+
if (ack.error === 'commitment_expired')
|
|
1779
|
+
return `commitment expired, asset ${assetId} not sent`;
|
|
1780
|
+
return `${ack.pending ? 'owed, will retry' : 'failed'} ${ack.error ?? ''}`;
|
|
1781
|
+
};
|
|
1728
1782
|
const tick = async (beat) => {
|
|
1729
1783
|
let failed = false;
|
|
1730
1784
|
const r = await guarded();
|
|
@@ -1735,6 +1789,33 @@ export async function runAutoExec(argv) {
|
|
|
1735
1789
|
// default / not in allowlist) is a no-op, not a broken edit.
|
|
1736
1790
|
if (r.some((v) => v.status === 'failed'))
|
|
1737
1791
|
failed = true;
|
|
1792
|
+
// A claim is a promise. The Hub only learns it was kept when the produced capsule
|
|
1793
|
+
// comes back — but a cycle solo rollback is about to revert has not kept it, and the
|
|
1794
|
+
// Hub cannot take a completion back. Stay silent and let the commitment expire.
|
|
1795
|
+
// Only a registered claim is Hub work: the `hub-` prefix is a naming convention a
|
|
1796
|
+
// local task may also use, and reporting its capsule would complete someone's task
|
|
1797
|
+
// with an unrelated asset. The generation narrows it further — a queue id can be
|
|
1798
|
+
// claimed, run and claimed again, and a result from the earlier filing is not this
|
|
1799
|
+
// claim's to hand over.
|
|
1800
|
+
const hubDone = r.flatMap((v) => {
|
|
1801
|
+
const claim = v.status === 'solidified' && v.resultAssetId ? taskReceiver.claimFor(v.taskId) : null;
|
|
1802
|
+
if (!claim || !v.resultAssetId)
|
|
1803
|
+
return [];
|
|
1804
|
+
if (claim.generation !== v.generation) {
|
|
1805
|
+
process.stdout.write(` task-complete: ${claim.hubTaskId} result is from an earlier claim (${v.generation ?? 'none'} ≠ ${claim.generation}); not reporting it\n`);
|
|
1806
|
+
return [];
|
|
1807
|
+
}
|
|
1808
|
+
return [{ hubTaskId: claim.hubTaskId, resultAssetId: v.resultAssetId, generation: claim.generation }];
|
|
1809
|
+
});
|
|
1810
|
+
if (failed && solo && hubDone.length > 0) {
|
|
1811
|
+
process.stdout.write(` task-complete: holding ${hubDone.length} report(s) — this cycle rolls back\n`);
|
|
1812
|
+
}
|
|
1813
|
+
else {
|
|
1814
|
+
for (const task of hubDone) {
|
|
1815
|
+
const ack = await taskReceiver.complete(task.hubTaskId, task.resultAssetId, task.generation);
|
|
1816
|
+
process.stdout.write(` task-complete: ${task.hubTaskId} ${completionLine(ack, task.resultAssetId)}\n`);
|
|
1817
|
+
}
|
|
1818
|
+
}
|
|
1738
1819
|
}
|
|
1739
1820
|
// Evidence-based auto-promote (#306 phase 2): after a pass, a probation gene that has proven itself (>= K clean
|
|
1740
1821
|
// successes, 0 failures) is auto-approved — the cross-AI loop self-closes without a human quality gate. Bad ones
|
|
@@ -1747,6 +1828,45 @@ export async function runAutoExec(argv) {
|
|
|
1747
1828
|
}
|
|
1748
1829
|
catch { /* never break the loop on a promotion side-effect */ }
|
|
1749
1830
|
}
|
|
1831
|
+
// Take work before delivering it: a task claimed this beat lands in the queue the
|
|
1832
|
+
// next pass reads, and the Hub only accepts delivery for tasks this node holds.
|
|
1833
|
+
// Debts before new work, and outside the receive switch: a claim taken by an earlier run
|
|
1834
|
+
// still owes the Hub its report, and a delivery the Hub never acknowledged gets
|
|
1835
|
+
// re-dispatched when the commitment expires. Turning the receiver off stops new work
|
|
1836
|
+
// only. A debt this beat just created is not due yet, so it waits for the next one.
|
|
1837
|
+
const requeued = await taskReceiver.retryQueueWrites();
|
|
1838
|
+
if (requeued.retried > 0 || requeued.dropped > 0)
|
|
1839
|
+
process.stdout.write(` task-receiver: requeued=${requeued.queued}/${requeued.retried} still-unqueued=${requeued.pending}${requeued.dropped > 0 ? ` dropped=${requeued.dropped}` : ''}\n`);
|
|
1840
|
+
const owed = await taskReceiver.retryCompletions();
|
|
1841
|
+
if (owed.retried > 0)
|
|
1842
|
+
process.stdout.write(` task-complete: retried=${owed.retried} reported=${owed.completed} abandoned=${owed.abandoned} owed=${owed.pending}${owed.unrecorded > 0 ? ` unrecorded=${owed.unrecorded}` : ''}\n`);
|
|
1843
|
+
for (const gone of owed.abandonedTasks) {
|
|
1844
|
+
// Dropped from the ledger after the retry budget: nothing will mention it again.
|
|
1845
|
+
process.stdout.write(` task-complete: GAVE UP on ${gone.taskId} (asset ${gone.resultAssetId}) — ${gone.lastError}\n`);
|
|
1846
|
+
}
|
|
1847
|
+
if (guardedTaskReceiver) {
|
|
1848
|
+
const t = await guardedTaskReceiver();
|
|
1849
|
+
if (t && !('skipped' in t) && t.claimed && t.task) {
|
|
1850
|
+
process.stdout.write(` task-receiver: ${t.reason} ${t.task.task_id}${t.commitmentDeadline ? ` until=${t.commitmentDeadline}` : ''}\n`);
|
|
1851
|
+
}
|
|
1852
|
+
else if (t && !('skipped' in t) && t.reason === 'claim_failed') {
|
|
1853
|
+
process.stdout.write(` task-receiver: claim failed ${t.task?.task_id ?? ''} ${t.error ?? ''}\n`);
|
|
1854
|
+
}
|
|
1855
|
+
else if (t && !('skipped' in t) && t.reason === 'expired') {
|
|
1856
|
+
process.stdout.write(` task-receiver: commitment on ${t.task?.task_id ?? ''} already expired, not resuming\n`);
|
|
1857
|
+
}
|
|
1858
|
+
else if (t && !('skipped' in t) && t.reason === 'fetch_failed') {
|
|
1859
|
+
process.stdout.write(` task-receiver: fetch failed ${t.error ?? ''}\n`);
|
|
1860
|
+
}
|
|
1861
|
+
else if (t && !('skipped' in t) && t.reason === 'queue_failed') {
|
|
1862
|
+
process.stdout.write(` task-receiver: claimed ${t.task?.task_id ?? ''} but could not queue it — ${t.error ?? ''}\n`);
|
|
1863
|
+
}
|
|
1864
|
+
else if (t && !('skipped' in t) && (t.seen > 0 || (t.rejected ?? 0) > 0)) {
|
|
1865
|
+
// The Hub had work but none of it was ours to take. Saying so is the only
|
|
1866
|
+
// way an operator can tell "fetching works" from "nothing ever ran".
|
|
1867
|
+
process.stdout.write(` task-receiver: none (seen=${t.seen}${t.rejected ? ` rejected=${t.rejected}` : ''})\n`);
|
|
1868
|
+
}
|
|
1869
|
+
}
|
|
1750
1870
|
if (guardedAtpAutoDeliver) {
|
|
1751
1871
|
const d = await guardedAtpAutoDeliver();
|
|
1752
1872
|
if (d && !('skipped' in d) && (d.delivered > 0 || d.terminalFailures > 0 || d.transientFailures > 0 || d.cooldownFailures > 0)) {
|
|
@@ -1795,7 +1915,9 @@ export async function runAutoExec(argv) {
|
|
|
1795
1915
|
process.stderr.write(`[Solo] 连续失败 ${soloState.consecutiveFailures} 次达阈值,熔断停机(非盲重生)。\n`);
|
|
1796
1916
|
// Stop scheduling, release the lock, and exit non-zero. Detached so we
|
|
1797
1917
|
// don't await our own loop.stop() from inside a tick.
|
|
1798
|
-
void
|
|
1918
|
+
void stopRuntime().catch((error) => {
|
|
1919
|
+
process.stderr.write(`[Solo] shutdown drain failed: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
1920
|
+
}).finally(() => { cleanupAutoexecRuntime(); process.exit(1); });
|
|
1799
1921
|
}
|
|
1800
1922
|
};
|
|
1801
1923
|
// Heartbeat (#106): record liveness + pacing on the AE spine for the WebUI console, THROTTLED so a fast poll does
|
|
@@ -1803,6 +1925,7 @@ export async function runAutoExec(argv) {
|
|
|
1803
1925
|
const heartbeatMinMs = Math.max(0, Number(process.env['EVOLVER_HEARTBEAT_MS'] ?? 60_000));
|
|
1804
1926
|
let lastBeatAt = 0;
|
|
1805
1927
|
let lastIntensity = '';
|
|
1928
|
+
await cursorRewrite.start?.();
|
|
1806
1929
|
const loop = startResidentLoop({
|
|
1807
1930
|
tick: solo ? soloTick : tick,
|
|
1808
1931
|
basePollMs: cfg.pollMs,
|
|
@@ -1823,5 +1946,14 @@ export async function runAutoExec(argv) {
|
|
|
1823
1946
|
});
|
|
1824
1947
|
// SIGINT/SIGTERM drain the in-flight beat before cleanup. SIGHUP cannot hot-reload this composition safely,
|
|
1825
1948
|
// so it is explicit and non-destructive: keep running until the operator performs a normal restart.
|
|
1826
|
-
|
|
1949
|
+
async function stopRuntime() {
|
|
1950
|
+
try {
|
|
1951
|
+
await loop.stop();
|
|
1952
|
+
await bus.drain();
|
|
1953
|
+
}
|
|
1954
|
+
finally {
|
|
1955
|
+
await cursorRewrite.stop?.();
|
|
1956
|
+
}
|
|
1957
|
+
}
|
|
1958
|
+
return await waitForAutoexecShutdown({ stop: stopRuntime, cleanup: cleanupAutoexecRuntime });
|
|
1827
1959
|
}
|
package/dist/autoexecConfig.d.ts
CHANGED
package/dist/autoexecConfig.js
CHANGED
|
@@ -10,7 +10,7 @@ const MAX_VALIDATION_COMMAND_LENGTH = 300;
|
|
|
10
10
|
const PROFILE_NAME_RE = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/;
|
|
11
11
|
const SECRET_TEXT_RE = /(?:\bBearer\s+[A-Za-z0-9._~+/=-]{8,}|\b(?:sk|gh[oprsu])_[A-Za-z0-9_-]{8,}|-----BEGIN [A-Z ]*PRIVATE KEY-----|\b(?:password|passwd|secret|token|api[_-]?key)\s*[:=]\s*\S+)/i;
|
|
12
12
|
function parseRunner(value) {
|
|
13
|
-
return value === 'codex' || value === 'cursor' || value === 'gemini' ? value : 'claude';
|
|
13
|
+
return value === 'codex' || value === 'cursor' || value === 'gemini' || value === 'llm' ? value : 'claude';
|
|
14
14
|
}
|
|
15
15
|
function isSafeValidationCommand(value) {
|
|
16
16
|
if (typeof value !== 'string')
|
package/dist/cursorRewrite.d.ts
CHANGED
|
@@ -9,6 +9,10 @@ export declare function geneToCursorGene(g: assetstore.AssetRecord): CursorGene;
|
|
|
9
9
|
export interface CursorRewriteWiring {
|
|
10
10
|
/** EVOLVER_CURSOR_REWRITE !== '0' AND cursor injection is installed at the project root (default ON when both). */
|
|
11
11
|
enabled: boolean;
|
|
12
|
+
/** Start cross-process benchmark reconciliation after daemon ownership is acquired. */
|
|
13
|
+
start?: () => Promise<void>;
|
|
14
|
+
/** Stop scheduling and drain pending file writes before releasing daemon ownership. */
|
|
15
|
+
stop?: () => Promise<void>;
|
|
12
16
|
/** Why it is disabled (for the daemon's startup line): 'off' (env) | 'not-installed' | undefined when enabled. */
|
|
13
17
|
reason?: 'off' | 'not-installed';
|
|
14
18
|
/** The wired observer (null when disabled). */
|
|
@@ -27,6 +31,8 @@ export interface CursorRewriteOptions {
|
|
|
27
31
|
maxGenes?: number;
|
|
28
32
|
/** Debounce window (a cycle's burst of gene events ⇒ one rewrite). Default the observer's default (2s). */
|
|
29
33
|
debounceMs?: number;
|
|
34
|
+
/** Benchmark sidecar change-check cadence; independent of potentially long execution beats. */
|
|
35
|
+
pollMs?: number;
|
|
30
36
|
}
|
|
31
37
|
/**
|
|
32
38
|
* Build the live cursor rewrite observer from the environment. Returns enabled=false (no observer) when
|
package/dist/cursorRewrite.js
CHANGED
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
// 2. one-switch off: EVOLVER_CURSOR_REWRITE=0 disables it even when installed.
|
|
15
15
|
import { assetstore, events, observers } from '@evomap/evolver-core';
|
|
16
16
|
import { cursorRulesInstalled, rewriteCursorRules, formatCursorGeneLine } from '@evomap/evolver-mcp';
|
|
17
|
+
import { startResidentLoop } from './daemonLoop.js';
|
|
17
18
|
import { listApprovedGenes, provenanceStoreForStore, reviewLedgerForStore } from './reviewFilter.js';
|
|
18
19
|
/**
|
|
19
20
|
* Map a stored gene asset onto the renderer's minimal CursorGene shape. Mirrors the CC SessionStart line voice
|
|
@@ -43,18 +44,75 @@ export function resolveCursorRewriteObserver(env = process.env, opts = {}) {
|
|
|
43
44
|
const store = opts.store ?? new assetstore.LocalJsonlProvider(events.assetsDir());
|
|
44
45
|
const review = opts.review ?? reviewLedgerForStore(store); // co-located with the store, not pinned to live dir
|
|
45
46
|
const provenance = opts.provenance ?? provenanceStoreForStore(store); // co-located with the store, not pinned to live dir
|
|
46
|
-
const
|
|
47
|
+
const benchmark = assetstore.benchmarkContext(env['EVOLVER_BENCHMARK_ID']);
|
|
48
|
+
const maxGenes = benchmark ? Math.min(opts.maxGenes ?? 8, 8) : (opts.maxGenes ?? 8);
|
|
49
|
+
let lastRevision;
|
|
47
50
|
const observer = observers.cursorRewriteObserver({
|
|
48
51
|
...(opts.debounceMs !== undefined ? { debounceMs: opts.debounceMs } : {}),
|
|
49
52
|
// The real side effect: read the current top TRUSTED + REVIEW-APPROVED genes and re-render the rules file.
|
|
50
|
-
// The gates
|
|
51
|
-
// drafts could be rendered straight into cursor's alwaysApply rules.
|
|
53
|
+
// The gates also apply to sidecar refreshes; drafts must never reach alwaysApply rules.
|
|
52
54
|
async rewrite() {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
+
try {
|
|
56
|
+
if (benchmark && (!Number.isSafeInteger(maxGenes) || maxGenes < 1))
|
|
57
|
+
throw new Error('invalid_benchmark_gene_limit');
|
|
58
|
+
// 此wiring已从env选定上下文;刷新只重读账本,不再从process.env选择另一个benchmark。
|
|
59
|
+
const genes = (await assetstore.listApprovedGenes(store, review, maxGenes, provenance, { ...(benchmark ? { benchmark } : {}) })).map(geneToCursorGene);
|
|
60
|
+
return rewriteCursorRules(projectRoot, genes, maxGenes);
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
// A damaged or unavailable qualification ledger must not leave old benchmark memory active.
|
|
64
|
+
// 清空派生规则后不能继续信任旧revision,事件触发的失败同样需要轮询恢复。
|
|
65
|
+
lastRevision = undefined;
|
|
66
|
+
if (benchmark)
|
|
67
|
+
rewriteCursorRules(projectRoot, [], maxGenes);
|
|
68
|
+
throw error;
|
|
69
|
+
}
|
|
55
70
|
},
|
|
56
71
|
});
|
|
57
|
-
|
|
72
|
+
let loop;
|
|
73
|
+
let stopped = false;
|
|
74
|
+
let started = false;
|
|
75
|
+
let lastDiagnostic;
|
|
76
|
+
const reconcile = async () => {
|
|
77
|
+
let revision;
|
|
78
|
+
try {
|
|
79
|
+
revision = JSON.stringify([provenance.revision(), review.revision()]);
|
|
80
|
+
}
|
|
81
|
+
catch { /* Re-read through the normal gate to clear unsafe rules. */ }
|
|
82
|
+
if (revision !== undefined && revision === lastRevision)
|
|
83
|
+
return;
|
|
84
|
+
try {
|
|
85
|
+
observer.invalidate();
|
|
86
|
+
await observer.flush();
|
|
87
|
+
lastRevision = revision;
|
|
88
|
+
lastDiagnostic = undefined;
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
lastRevision = undefined;
|
|
92
|
+
const diagnostic = error instanceof Error ? error.message : String(error);
|
|
93
|
+
if (diagnostic !== lastDiagnostic)
|
|
94
|
+
process.stderr.write(`[cursor-rewrite] source reconciliation failed; retrying: ${diagnostic}\n`);
|
|
95
|
+
lastDiagnostic = diagnostic;
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
return {
|
|
99
|
+
enabled: true, observer,
|
|
100
|
+
async start() {
|
|
101
|
+
if (started || stopped || !benchmark)
|
|
102
|
+
return;
|
|
103
|
+
started = true;
|
|
104
|
+
// Reconcile at startup too: a qualification can change while this daemon is stopped.
|
|
105
|
+
await reconcile();
|
|
106
|
+
if (!stopped)
|
|
107
|
+
loop = startResidentLoop({ tick: reconcile, basePollMs: opts.pollMs ?? 1000,
|
|
108
|
+
idleAware: false, runFirstImmediately: false });
|
|
109
|
+
},
|
|
110
|
+
async stop() {
|
|
111
|
+
stopped = true;
|
|
112
|
+
await loop?.stop();
|
|
113
|
+
await observer.stop();
|
|
114
|
+
},
|
|
115
|
+
};
|
|
58
116
|
}
|
|
59
117
|
/** Re-export for the installer composition: `setup-hooks --runtime=cursor` seeds evolver.mdc with the current
|
|
60
118
|
* top REVIEW-APPROVED genes (so the file is useful immediately, before the first daemon rewrite — without
|
package/dist/cycleConsumer.js
CHANGED
|
@@ -547,6 +547,7 @@ async function processMaterial(material, opts, deps) {
|
|
|
547
547
|
engine: deps.engine,
|
|
548
548
|
store: deps.store,
|
|
549
549
|
provenance: deps.provenance,
|
|
550
|
+
...(process.env['EVOLVER_BENCHMARK_ID'] !== undefined ? { benchmark: assetstore.benchmarkContext(process.env['EVOLVER_BENCHMARK_ID']) } : {}),
|
|
550
551
|
review: deps.review,
|
|
551
552
|
personality: deps.personality,
|
|
552
553
|
memoryGraph: deps.memoryGraph,
|