@evomap/evolver-cli 2.0.36 → 2.0.38
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 +148 -7
- package/dist/autoexecConfig.d.ts +1 -1
- package/dist/autoexecConfig.js +1 -1
- package/dist/cliContracts.d.ts +7 -2
- package/dist/cliContracts.js +97 -13
- 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/localPublishBinding.d.ts +25 -0
- package/dist/localPublishBinding.js +139 -0
- package/dist/promptRecallHook.js +86 -10
- package/dist/recall.d.ts +2 -0
- package/dist/recall.js +19 -1
- package/dist/recipe.d.ts +5 -1
- package/dist/recipe.js +123 -42
- package/dist/referenceAccess.d.ts +3 -0
- package/dist/referenceAccess.js +232 -0
- package/dist/referencePublish.d.ts +4 -0
- package/dist/referencePublish.js +40 -0
- package/dist/requiredSandboxValidation.js +6 -1
- 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
package/dist/cliContracts.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { existsSync, readFileSync, statSync } from 'node:fs';
|
|
2
2
|
import { resolve } from 'node:path';
|
|
3
3
|
import { inspect, format } from 'node:util';
|
|
4
|
-
import { assetrepair, assetstore, events, hub, wire, algo, verify } from '@evomap/evolver-core';
|
|
5
|
-
import {
|
|
4
|
+
import { assetrepair, assetstore, events, hub, wire, algo, verify, reference } from '@evomap/evolver-core';
|
|
5
|
+
import { hasReferenceEvidenceMode, validateReferencePublishBundle, validReferenceReceipt } from './referencePublish.js';
|
|
6
|
+
import { AuthError, HubClientError, HubFetch, HubUnreachableError, connectPublicHub, gepEnvelope, globalFetchLike, isHubDryRunEnabled, resolveHubUrl, } from '@evomap/evolver-adapter-public';
|
|
6
7
|
import { loadEnvFileFromEnv, proxyClientFromEnv } from '@evomap/evolver-mcp';
|
|
7
8
|
import { resolveAtpSenderId } from './atp.js';
|
|
8
9
|
import { storeRepairedAsset } from './repairedAssetStore.js';
|
|
9
10
|
import { resolveExplicitNodeCredentials, resolveIdentityHome } from './identityHome.js';
|
|
11
|
+
import { LocalPublishBindingError, reverifyPublishBundle, withLocalPublishBinding, } from './localPublishBinding.js';
|
|
10
12
|
const REUSE_CONTRACT = 'reuse.v1';
|
|
11
13
|
const PUBLISH_CONTRACT = 'publish.v1';
|
|
12
14
|
const REVERSIBILITY = 'irreversible';
|
|
@@ -19,6 +21,8 @@ const PUBLISH_USAGE = [
|
|
|
19
21
|
'usage: evolver publish --asset <gene_id_or_path> --asset <capsule_id_or_path> --json [--dry-run] [--repair] [--no-recipe]',
|
|
20
22
|
' evolver publish --gene <id_or_path> --capsule <id_or_path> --json [--dry-run] [--no-recipe]',
|
|
21
23
|
' evolver publish --gene <id_or_path> --auto-pair --json [--dry-run] [--no-recipe]',
|
|
24
|
+
' evolver publish --gene <id_or_path> --capsule <id_or_path> --reverify --json [--no-recipe]',
|
|
25
|
+
' --reverify 明确请求本机宿主重新验证并保存新资产;不改写原资产,不与 --dry-run/--repair 合用。',
|
|
22
26
|
].join('\n');
|
|
23
27
|
const ASSET_FLAGS = new Set(['--asset', '--gene', '--capsule', '--event']);
|
|
24
28
|
const STABLE_CONTRACT_REASONS = new Set([
|
|
@@ -37,6 +41,7 @@ const STABLE_CONTRACT_REASONS = new Set([
|
|
|
37
41
|
'gene_unproven',
|
|
38
42
|
'insufficient_credits',
|
|
39
43
|
'unsafe_validation_command',
|
|
44
|
+
'verification_required',
|
|
40
45
|
]);
|
|
41
46
|
const HUB_METADATA_KEYS = new Set([
|
|
42
47
|
'credit_cost',
|
|
@@ -136,7 +141,7 @@ export async function runPublishCommand(args, deps = {}) {
|
|
|
136
141
|
}
|
|
137
142
|
const parsed = parsePublishArgs(args);
|
|
138
143
|
if (!parsed.ok || !parsed.assetRefs) {
|
|
139
|
-
return writeJson(out, publishFailure(parsed.reason ?? 'bundle_required', parsed.message ?? publishReasonMessage('bundle_required'), { retryable: false }), 1, deps);
|
|
144
|
+
return writeJson(out, publishFailure(parsed.reason ?? 'bundle_required', parsed.message ?? publishReasonMessage('bundle_required'), { retryable: false, mode: parsed.dryRun ? 'dry_run' : 'publish' }), 1, deps);
|
|
140
145
|
}
|
|
141
146
|
const assetRefs = parsed.assetRefs;
|
|
142
147
|
let runtimeDeps;
|
|
@@ -152,16 +157,38 @@ export async function runPublishCommand(args, deps = {}) {
|
|
|
152
157
|
mode: parsed.dryRun ? 'dry_run' : 'publish',
|
|
153
158
|
}), 1, deps);
|
|
154
159
|
}
|
|
155
|
-
|
|
160
|
+
if (parsed.reverify && isHubDryRunEnabled(runtimeDeps.env ?? {})) {
|
|
161
|
+
return writeJson(out, publishFailure('unsupported', '--reverify cannot be combined with HUB_DRY_RUN', {
|
|
162
|
+
retryable: false, mode: 'dry_run',
|
|
163
|
+
}), 1, runtimeDeps);
|
|
164
|
+
}
|
|
165
|
+
let reverification;
|
|
166
|
+
const write = (value, code) => writeJson(out, reverification && asRecord(value) ? { ...asRecord(value), reverification } : value, code, runtimeDeps);
|
|
156
167
|
return withMachineJsonConsole(Boolean(parsed.jsonOut), runtimeDeps, async () => {
|
|
157
168
|
try {
|
|
158
169
|
const effectiveRefs = parsed.autoPair
|
|
159
170
|
? await autoPairPublishRefs(assetRefs, parsed.geneRef, runtimeDeps)
|
|
160
171
|
: assetRefs;
|
|
161
|
-
|
|
172
|
+
let bundle = await buildPublishBundle(effectiveRefs, runtimeDeps);
|
|
162
173
|
if (!bundle.ok) {
|
|
163
174
|
return write(publishFailure(bundle.reason, bundle.message, { retryable: false, gates: bundle.gates }), 1);
|
|
164
175
|
}
|
|
176
|
+
const referenceOnly = bundle.gates.quality_evidence === 'reference_integrity';
|
|
177
|
+
if (referenceOnly && (parsed.reverify || parsed.repair || configuredHubMode(runtimeDeps.env ?? {}) === 'private')) {
|
|
178
|
+
return write(publishFailure('unsupported', 'reference publication requires the public Hub and immutable assets; execution reverify and repair are not supported', {
|
|
179
|
+
retryable: false, mode: parsed.dryRun ? 'dry_run' : 'publish', gates: bundle.gates,
|
|
180
|
+
}), 1);
|
|
181
|
+
}
|
|
182
|
+
if (parsed.reverify && bundle.blockReasons.every((reason) => reason === 'gene_unproven')) {
|
|
183
|
+
const verified = await reverifyPublishBundle(bundle.original, runtimeDeps.env ?? {}, runtimeDeps.resolveProxyClient);
|
|
184
|
+
reverification = {
|
|
185
|
+
applied: true, original_assets_unchanged: true, stored: verified.stored,
|
|
186
|
+
source_asset_ids: verified.sourceAssetIds, asset_ids: verified.assets.map((asset) => asset.asset_id),
|
|
187
|
+
};
|
|
188
|
+
bundle = await assessPublishRecords(verified.assets.map(normalizeAsset), runtimeDeps);
|
|
189
|
+
if (!bundle.ok)
|
|
190
|
+
return write(publishFailure(bundle.reason, bundle.message, { retryable: false, gates: bundle.gates }), 1);
|
|
191
|
+
}
|
|
165
192
|
if (bundle.blockReasons.length > 0) {
|
|
166
193
|
if (parsed.dryRun)
|
|
167
194
|
return write(dryRunEnvelope(bundle), 0);
|
|
@@ -175,7 +202,7 @@ export async function runPublishCommand(args, deps = {}) {
|
|
|
175
202
|
}), 1);
|
|
176
203
|
}
|
|
177
204
|
const transport = deps.transport ?? createDefaultTransport(runtimeDeps, {
|
|
178
|
-
composeRecipe: parsed.noRecipe !== true,
|
|
205
|
+
composeRecipe: !referenceOnly && parsed.noRecipe !== true,
|
|
179
206
|
});
|
|
180
207
|
const validate = deps.validate ?? transport.validate;
|
|
181
208
|
// A field-level refusal is a defect in the RECORD, not a verdict on the work in it. Read the Hub's own
|
|
@@ -215,6 +242,11 @@ export async function runPublishCommand(args, deps = {}) {
|
|
|
215
242
|
...repairEnvelopeField(validationAttempt),
|
|
216
243
|
}), 1);
|
|
217
244
|
}
|
|
245
|
+
if (referenceOnly && !validReferenceReceipt(validation.body, bundle.sanitized, true)) {
|
|
246
|
+
return write(publishFailure('quality_gate_failed', 'reference validation response does not attest the submitted non-execution pair', {
|
|
247
|
+
retryable: false, mode: parsed.dryRun ? 'dry_run' : 'publish', gates: { ...bundle.gates, quality: 'fail' },
|
|
248
|
+
}), 1);
|
|
249
|
+
}
|
|
218
250
|
if (parsed.dryRun)
|
|
219
251
|
return write(dryRunEnvelope(bundle, validationCredits, undefined, validationAttempt), 0);
|
|
220
252
|
const publish = deps.publish ?? transport.publish;
|
|
@@ -236,6 +268,20 @@ export async function runPublishCommand(args, deps = {}) {
|
|
|
236
268
|
...repairEnvelopeField(repairApplied),
|
|
237
269
|
}), 1);
|
|
238
270
|
}
|
|
271
|
+
if (referenceOnly) {
|
|
272
|
+
if (!validReferenceReceipt(published.body, bundle.sanitized, false)) {
|
|
273
|
+
return write(publishFailure('quality_gate_failed', 'reference publication lacks a matching stored_reference receipt; persistence is unconfirmed', {
|
|
274
|
+
retryable: false, mode: 'publish', gates: { ...bundle.gates, quality: 'fail' }, assets: bundle.assets,
|
|
275
|
+
}), 1);
|
|
276
|
+
}
|
|
277
|
+
const payload = payloadRecord(published.body);
|
|
278
|
+
return write({
|
|
279
|
+
ok: true, contract: PUBLISH_CONTRACT, mode: 'publish', status: 'stored_reference',
|
|
280
|
+
reversibility: REVERSIBILITY, evidence_mode: 'reference_only', ...reference.REFERENCE_ELIGIBILITY,
|
|
281
|
+
bundle_id: payload['bundle_id'], gene_asset_id: payload['gene_asset_id'], capsule_asset_id: payload['capsule_asset_id'],
|
|
282
|
+
credit_reward: 0, gates: bundle.gates, assets: bundle.assets,
|
|
283
|
+
}, 0);
|
|
284
|
+
}
|
|
239
285
|
// The repaired records are what the network now holds. Persist them so the local library and the Hub do
|
|
240
286
|
// not silently diverge; a storage failure is reported, never fatal — the publish already happened.
|
|
241
287
|
const repairPersisted = repairApplied?.applied === true
|
|
@@ -292,10 +338,10 @@ export async function runPublishCommand(args, deps = {}) {
|
|
|
292
338
|
}
|
|
293
339
|
catch (err) {
|
|
294
340
|
const failure = classifyError(err, 'publish', runtimeDeps.env ?? process.env);
|
|
295
|
-
return write(publishFailure(failure.reason, failure.message, {
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
341
|
+
return write({ ...publishFailure(failure.reason, failure.message, {
|
|
342
|
+
retryable: failure.retryable,
|
|
343
|
+
mode: parsed.dryRun ? 'dry_run' : 'publish',
|
|
344
|
+
}), ...(err instanceof LocalPublishBindingError && err.recovery ? { recovery: err.recovery } : {}) }, 1);
|
|
299
345
|
}
|
|
300
346
|
});
|
|
301
347
|
}
|
|
@@ -443,6 +489,7 @@ export function parsePublishArgs(args) {
|
|
|
443
489
|
let dryRun = false;
|
|
444
490
|
let repair = false;
|
|
445
491
|
let noRecipe = false;
|
|
492
|
+
let reverify = false;
|
|
446
493
|
let jsonOut = false;
|
|
447
494
|
for (let i = 0; i < args.length; i++) {
|
|
448
495
|
const token = args[i];
|
|
@@ -468,6 +515,10 @@ export function parsePublishArgs(args) {
|
|
|
468
515
|
noRecipe = true;
|
|
469
516
|
continue;
|
|
470
517
|
}
|
|
518
|
+
if (token === '--reverify') {
|
|
519
|
+
reverify = true;
|
|
520
|
+
continue;
|
|
521
|
+
}
|
|
471
522
|
const equalFlag = [...ASSET_FLAGS].find((flag) => token.startsWith(`${flag}=`));
|
|
472
523
|
if (equalFlag) {
|
|
473
524
|
const value = token.slice(equalFlag.length + 1).trim();
|
|
@@ -512,6 +563,10 @@ export function parsePublishArgs(args) {
|
|
|
512
563
|
}
|
|
513
564
|
if (!jsonOut)
|
|
514
565
|
return { ok: false, reason: 'unsupported', message: 'publish requires --json' };
|
|
566
|
+
if (reverify && (dryRun || repair))
|
|
567
|
+
return {
|
|
568
|
+
ok: false, dryRun, reason: 'unsupported', message: '--reverify cannot be combined with --dry-run or --repair; verification never runs implicitly',
|
|
569
|
+
};
|
|
515
570
|
if (autoPair && (geneCount !== 1 || !geneRef || capsuleRef || hasUntypedAsset)) {
|
|
516
571
|
return { ok: false, reason: 'bundle_required', message: '--auto-pair requires exactly one explicit --gene and no --asset or --capsule' };
|
|
517
572
|
}
|
|
@@ -528,6 +583,7 @@ export function parsePublishArgs(args) {
|
|
|
528
583
|
dryRun,
|
|
529
584
|
repair,
|
|
530
585
|
...(noRecipe ? { noRecipe: true } : {}),
|
|
586
|
+
...(reverify ? { reverify: true } : {}),
|
|
531
587
|
jsonOut,
|
|
532
588
|
};
|
|
533
589
|
}
|
|
@@ -550,12 +606,26 @@ export async function buildPublishBundle(refs, deps = {}) {
|
|
|
550
606
|
gates: reason === 'schema_invalid' ? { schema: 'fail' } : {},
|
|
551
607
|
};
|
|
552
608
|
}
|
|
609
|
+
return assessPublishRecords(original, deps);
|
|
610
|
+
}
|
|
611
|
+
export async function assessPublishRecords(original, deps) {
|
|
553
612
|
const bundleCheck = checkBundle(original);
|
|
554
613
|
if (!bundleCheck.ok)
|
|
555
614
|
return { ok: false, reason: 'bundle_required', message: bundleCheck.message, gates: { schema: 'pass', bundle: 'fail' } };
|
|
615
|
+
const referenceOnly = hasReferenceEvidenceMode(original);
|
|
616
|
+
if (referenceOnly) {
|
|
617
|
+
try {
|
|
618
|
+
validateReferencePublishBundle(original);
|
|
619
|
+
}
|
|
620
|
+
catch (error) {
|
|
621
|
+
const message = error instanceof Error && /^reference_[a-z_]+$/.test(error.message)
|
|
622
|
+
? error.message : 'reference_integrity_invalid';
|
|
623
|
+
return { ok: false, reason: 'schema_invalid', message, gates: { schema: 'fail', quality: 'fail' } };
|
|
624
|
+
}
|
|
625
|
+
}
|
|
556
626
|
let sanitized;
|
|
557
627
|
try {
|
|
558
|
-
sanitized = sanitizePublishBundle(original);
|
|
628
|
+
sanitized = referenceOnly ? structuredClone(original) : sanitizePublishBundle(original);
|
|
559
629
|
}
|
|
560
630
|
catch {
|
|
561
631
|
return { ok: false, reason: 'redaction_unavailable', message: 'redaction unavailable', gates: { redaction: 'unavailable' } };
|
|
@@ -571,7 +641,9 @@ export async function buildPublishBundle(refs, deps = {}) {
|
|
|
571
641
|
// leaks to the Hub and comes back as an opaque `quality_gate_failed` after a
|
|
572
642
|
// round-trip. Assessing the gene's outcome evidence here fails fast, locally,
|
|
573
643
|
// with a precise reason. Read-only: aggregates the local capsule history.
|
|
574
|
-
const geneEvidence =
|
|
644
|
+
const geneEvidence = referenceOnly
|
|
645
|
+
? { eligible: true, source: 'reference_integrity' }
|
|
646
|
+
: await assessPublishGeneEvidence(original, deps);
|
|
575
647
|
const geneProven = geneEvidence?.eligible ?? true;
|
|
576
648
|
// Local quality gate: validation command safety check.
|
|
577
649
|
// Only applies to Gene assets. Checks that all validation commands are safe
|
|
@@ -727,6 +799,10 @@ function checkValidationCommands(original) {
|
|
|
727
799
|
}
|
|
728
800
|
function sanitizePublishBundle(original) {
|
|
729
801
|
const sanitized = original.map((asset) => hub.sanitizeAsset(stripPublishMetadata(asset)));
|
|
802
|
+
// 已绑定记录的 business-id 引用同样属于完整内容,不能在验证后改成另一种引用并重算资产。
|
|
803
|
+
// 脱敏若真正改变内容,后续 host ledger 会要求重新验证;人工无声明路径保留旧引用规范化。
|
|
804
|
+
if (hub.requiresPublishBinding(original))
|
|
805
|
+
return sanitized;
|
|
730
806
|
const finalGeneIdByOriginalRef = new Map();
|
|
731
807
|
for (let i = 0; i < original.length; i++) {
|
|
732
808
|
const source = original[i];
|
|
@@ -1006,6 +1082,8 @@ function dryRunEnvelope(bundle, credits, blockDetail, repairAttempt) {
|
|
|
1006
1082
|
mode: 'dry_run',
|
|
1007
1083
|
reversibility: REVERSIBILITY,
|
|
1008
1084
|
blocked: bundle.blockReasons.length > 0,
|
|
1085
|
+
...(bundle.gates.quality_evidence === 'reference_integrity'
|
|
1086
|
+
? { evidence_mode: 'reference_only', ...reference.REFERENCE_ELIGIBILITY } : {}),
|
|
1009
1087
|
block_reasons: bundle.blockReasons,
|
|
1010
1088
|
...(blockDetails.length > 0 ? { block_details: blockDetails } : {}),
|
|
1011
1089
|
assets: bundle.assets,
|
|
@@ -1156,7 +1234,7 @@ function createDefaultTransport(deps, opts = {}) {
|
|
|
1156
1234
|
return {
|
|
1157
1235
|
fetchAssetById: (assetId) => connected.hub.fetchAssetById(assetId),
|
|
1158
1236
|
validate: (bundle) => call('/a2a/validate', 'validate', bundle),
|
|
1159
|
-
publish: (bundle) => call('/a2a/publish', 'publish',
|
|
1237
|
+
publish: (bundle) => withLocalPublishBinding(bundle, env, (authorized) => call('/a2a/publish', 'publish', authorized), deps.resolveProxyClient),
|
|
1160
1238
|
...(opts.composeRecipe === false ? {} : {
|
|
1161
1239
|
composeRecipe: (payload) => hub.composeRecipeAfterAssetPublish(connected.hub, payload),
|
|
1162
1240
|
}),
|
|
@@ -1282,6 +1360,9 @@ function privatePublishExplicitFailure(body) {
|
|
|
1282
1360
|
return root['ok'] === false || root['stored'] === false || payload['ok'] === false || payload['stored'] === false;
|
|
1283
1361
|
}
|
|
1284
1362
|
function privateProxyFailure(err) {
|
|
1363
|
+
if (err instanceof Error && /^publish_(?:binding|reverification|verification)_/.test(err.message)) {
|
|
1364
|
+
return { ok: false, status: 422, body: { ok: false, reason: 'verification_required' } };
|
|
1365
|
+
}
|
|
1285
1366
|
return { ok: false, status: isAuthLikeError(err) ? 401 : 0 };
|
|
1286
1367
|
}
|
|
1287
1368
|
function isAuthLikeError(err) {
|
|
@@ -1289,6 +1370,8 @@ function isAuthLikeError(err) {
|
|
|
1289
1370
|
return /oauth|login|credential|auth|401|403|node_secret/i.test(message);
|
|
1290
1371
|
}
|
|
1291
1372
|
function classifyError(err, command, env = {}) {
|
|
1373
|
+
if (err instanceof LocalPublishBindingError)
|
|
1374
|
+
return { reason: 'verification_required', message: err.message, retryable: false };
|
|
1292
1375
|
if (err instanceof ContractError)
|
|
1293
1376
|
return { reason: err.reason, message: err.safeMessage, retryable: err.reason === 'network_error' };
|
|
1294
1377
|
if (err instanceof AuthError)
|
|
@@ -1366,6 +1449,7 @@ function publishReasonMessage(reason, env = {}) {
|
|
|
1366
1449
|
gene_unproven: 'gene has no proven success yet — run it to a successful outcome before publishing',
|
|
1367
1450
|
insufficient_credits: 'insufficient credits',
|
|
1368
1451
|
unsafe_validation_command: 'validation command contains unsafe patterns (e.g., node -e, shell metacharacters) blocked by sandbox security policy',
|
|
1452
|
+
verification_required: '资产需要当前本机宿主验证;请使用 --reverify 或本机重新验证接口',
|
|
1369
1453
|
};
|
|
1370
1454
|
return map[reason] ?? map.internal_error;
|
|
1371
1455
|
}
|
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,
|
package/dist/index.js
CHANGED
|
@@ -1654,12 +1654,15 @@ export async function runInject(argv, deps = {}) {
|
|
|
1654
1654
|
const ingestor = deps.ingestor ?? new events.Ingestor({ path: deps.eventsPath ?? events.rootEventsPath() });
|
|
1655
1655
|
const review = deps.review ?? reviewLedgerForStore(store); // co-located with the store, not pinned to live dir
|
|
1656
1656
|
const provenance = deps.provenance ?? provenanceStoreForStore(store); // co-located with the store, not pinned to live dir
|
|
1657
|
-
const maxGenes = deps.maxGenes ?? 8;
|
|
1657
|
+
const maxGenes = process.env['EVOLVER_BENCHMARK_ID'] !== undefined ? Math.min(deps.maxGenes ?? 8, 8) : (deps.maxGenes ?? 8);
|
|
1658
1658
|
const hardCap = deps.tokenBudgetHardCap ?? 8000;
|
|
1659
1659
|
// Gene pool → injection candidates: the most recent TRUSTED + REVIEW-APPROVED local genes (bounded), rendered as
|
|
1660
1660
|
// compact hint lines. The provenance gate keeps untrusted hub assets out until promotion; the review gate (A2a)
|
|
1661
1661
|
// keeps auto-distilled UNPROVEN drafts out until approval.
|
|
1662
|
-
|
|
1662
|
+
let sourceQualifications;
|
|
1663
|
+
const genes = await listApprovedGenes(store, review, maxGenes, provenance, {
|
|
1664
|
+
onQualification: (receipts) => { sourceQualifications = receipts; },
|
|
1665
|
+
});
|
|
1663
1666
|
const rendered = genes.map((g) => renderSessionGene(g, contentMode, hardCap * 4));
|
|
1664
1667
|
const geneLines = rendered.map((gene) => gene.text);
|
|
1665
1668
|
const geneIds = genes.map((g) => (typeof g['id'] === 'string' ? String(g['id']) : String(g.asset_id)));
|
|
@@ -1677,6 +1680,10 @@ export async function runInject(argv, deps = {}) {
|
|
|
1677
1680
|
// readHookInput. Default (no flag, no seam) never touches stdin — so a plain `evolver inject session-start` and
|
|
1678
1681
|
// the test suite can never block on a stdin read (the Windows CI hang this guards against).
|
|
1679
1682
|
const sessionId = deps.sessionId ?? ((fromHookStdin || deps.readHookInput) ? await readHookSessionId(deps.readHookInput) : undefined);
|
|
1683
|
+
if (sourceQualifications && [sessionId, deps.cycleId].some((id) => id !== undefined && Buffer.byteLength(id, 'utf8') > 128)) {
|
|
1684
|
+
process.stderr.write('inject session-start: benchmark关联ID超过审计预算,未注入。\n');
|
|
1685
|
+
return 1;
|
|
1686
|
+
}
|
|
1680
1687
|
const compose = (count) => {
|
|
1681
1688
|
injectedInfo = undefined;
|
|
1682
1689
|
return hooks.composeSessionStartWithRecap({ tokenBudgetHardCap: hardCap, preamble: SESSION_START_PREAMBLE }, { injectGenes: geneLines.slice(0, count), geneIds: geneIds.slice(0, count), successCount: summary.topGenes.length, summary }, {
|
|
@@ -1689,13 +1696,14 @@ export async function runInject(argv, deps = {}) {
|
|
|
1689
1696
|
const content = rendered.slice(0, count).map((gene) => gene.content);
|
|
1690
1697
|
return { ...injectedInfo, geneIds: geneIds.slice(0, count), contentSchema: 'session-gene-content.v1', content,
|
|
1691
1698
|
omittedByBudget: rendered.length - count + content.filter((gene) => gene.omissionReason === 'budget').length,
|
|
1699
|
+
...(sourceQualifications ? { sourceQualifications: sourceQualifications.slice(0, count) } : {}),
|
|
1692
1700
|
};
|
|
1693
1701
|
};
|
|
1694
1702
|
let inj = compose(rendered.length);
|
|
1695
1703
|
const tokenLimitedCount = inj.genes.length;
|
|
1696
1704
|
let low = 0;
|
|
1697
1705
|
let high = inj.genes.length;
|
|
1698
|
-
// Find the largest whole-gene prefix whose content receipts fit
|
|
1706
|
+
// Find the largest whole-gene prefix whose content and qualification receipts fit
|
|
1699
1707
|
// the actual writer envelope, before any prompt bytes reach the runtime.
|
|
1700
1708
|
while (low < high) {
|
|
1701
1709
|
const count = Math.ceil((low + high) / 2);
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { assetstore } from '@evomap/evolver-core';
|
|
2
|
+
import { type ProxyAssetBundle, type ProxyAssetReverification, type ProxyReverificationRecovery } from '@evomap/evolver-mcp';
|
|
3
|
+
export interface LocalPublishVerifierClient {
|
|
4
|
+
authorizeAssetPublication(input: ProxyAssetBundle, opts?: {
|
|
5
|
+
signal?: AbortSignal;
|
|
6
|
+
}): Promise<unknown>;
|
|
7
|
+
reverifyAssets(input: ProxyAssetReverification, opts?: {
|
|
8
|
+
signal?: AbortSignal;
|
|
9
|
+
}): Promise<unknown>;
|
|
10
|
+
}
|
|
11
|
+
export type LocalPublishVerifierResolver = (env: NodeJS.ProcessEnv) => Partial<LocalPublishVerifierClient> | undefined;
|
|
12
|
+
export declare class LocalPublishBindingError extends Error {
|
|
13
|
+
readonly reason: string;
|
|
14
|
+
readonly recovery?: ProxyReverificationRecovery;
|
|
15
|
+
constructor(reason: string, recovery?: ProxyReverificationRecovery);
|
|
16
|
+
}
|
|
17
|
+
/** 只消费本机 ledger 的判定;不把客户端 hash、外部 receipt 或未验证的历史声明当作授权。 */
|
|
18
|
+
export declare function withLocalPublishBinding<T>(bundle: readonly assetstore.AssetRecord[], env: NodeJS.ProcessEnv, publish: (assets: assetstore.AssetRecord[]) => Promise<T>, resolveProxy?: LocalPublishVerifierResolver): Promise<T>;
|
|
19
|
+
export interface ReverifiedPublishBundle {
|
|
20
|
+
assets: assetstore.AssetRecord[];
|
|
21
|
+
sourceAssetIds: string[];
|
|
22
|
+
stored: boolean;
|
|
23
|
+
}
|
|
24
|
+
/** 显式迁移产生新记录;原始资产和历史 trace 不原地更新,也不自动广播。 */
|
|
25
|
+
export declare function reverifyPublishBundle(bundle: readonly assetstore.AssetRecord[], env: NodeJS.ProcessEnv, resolveProxy?: LocalPublishVerifierResolver): Promise<ReverifiedPublishBundle>;
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { assetstore, hub, wire } from '@evomap/evolver-core';
|
|
2
|
+
import { proxyClientFromEnv, ProxyReverificationError, safeReverificationRecovery, } from '@evomap/evolver-mcp';
|
|
3
|
+
export class LocalPublishBindingError extends Error {
|
|
4
|
+
reason;
|
|
5
|
+
recovery;
|
|
6
|
+
constructor(reason, recovery) {
|
|
7
|
+
super(recovery
|
|
8
|
+
? `${reason}: 请先检查 source_asset_ids、asset_ids 对应的本机资产与 ledger;状态不明确时勿盲目重新执行 --reverify,不回滚已保存资产或撤销合法回执`
|
|
9
|
+
: reason === 'publish_reverification_unavailable'
|
|
10
|
+
? `${reason}: 当前本机没有可用的隔离验证器;需配置受支持的 native verifier,不支持的平台保持 draft-only`
|
|
11
|
+
: `${reason}: 请通过当前本机宿主重新验证;使用 evolver publish --gene <id|path> --capsule <id|path> --reverify --json`);
|
|
12
|
+
this.reason = reason;
|
|
13
|
+
if (recovery)
|
|
14
|
+
this.recovery = safeReverificationRecovery(recovery);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function safeFailureReason(error, fallback, operation = 'reverification') {
|
|
18
|
+
if (error instanceof Error) {
|
|
19
|
+
if (/^publish_(?:binding|reverification)_[a-z_]{1,70}$/.test(error.message))
|
|
20
|
+
return error.message;
|
|
21
|
+
if (error.message === 'proxy_hub_mode_mismatch')
|
|
22
|
+
return 'publish_binding_hub_mode_mismatch';
|
|
23
|
+
if (error.name === 'TimeoutError')
|
|
24
|
+
return `publish_${operation}_timeout`;
|
|
25
|
+
if (error.name === 'AbortError')
|
|
26
|
+
return `publish_${operation}_aborted`;
|
|
27
|
+
}
|
|
28
|
+
return fallback;
|
|
29
|
+
}
|
|
30
|
+
function mode(env) {
|
|
31
|
+
const value = (env['EVOMAP_HUB_MODE'] ?? 'public').trim().toLowerCase();
|
|
32
|
+
if (value !== 'public' && value !== 'private')
|
|
33
|
+
throw new LocalPublishBindingError('publish_binding_hub_mode_invalid');
|
|
34
|
+
return value;
|
|
35
|
+
}
|
|
36
|
+
function record(value) {
|
|
37
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value)
|
|
38
|
+
? value : {};
|
|
39
|
+
}
|
|
40
|
+
function snapshot(bundle) {
|
|
41
|
+
return structuredClone(bundle).map((asset) => assetstore.normalizeForPut(asset).record);
|
|
42
|
+
}
|
|
43
|
+
/** 只消费本机 ledger 的判定;不把客户端 hash、外部 receipt 或未验证的历史声明当作授权。 */
|
|
44
|
+
export async function withLocalPublishBinding(bundle, env, publish, resolveProxy = proxyClientFromEnv) {
|
|
45
|
+
const assets = snapshot(bundle);
|
|
46
|
+
if (!hub.requiresPublishBinding(assets))
|
|
47
|
+
return publish(assets);
|
|
48
|
+
const expectedHubMode = mode(env);
|
|
49
|
+
await authorizeSnapshot(assets, expectedHubMode, resolveProxy(env));
|
|
50
|
+
return publish(assets);
|
|
51
|
+
}
|
|
52
|
+
async function authorizeSnapshot(assets, expectedHubMode, proxy) {
|
|
53
|
+
if (!proxy?.authorizeAssetPublication)
|
|
54
|
+
throw new LocalPublishBindingError('publish_verification_required');
|
|
55
|
+
const digest = hub.publishBundleDigest(assets);
|
|
56
|
+
// 授权 callback 只能持有独立副本;即使其在返回后修改请求,也不能污染 publisher 私有数据。
|
|
57
|
+
const requestAssets = structuredClone(assets);
|
|
58
|
+
const requestDigest = hub.publishBundleDigest(requestAssets);
|
|
59
|
+
let response;
|
|
60
|
+
try {
|
|
61
|
+
response = record(await proxy.authorizeAssetPublication({
|
|
62
|
+
assets: requestAssets, expected_hub_mode: expectedHubMode,
|
|
63
|
+
}, { signal: AbortSignal.timeout(30_000) }));
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
throw new LocalPublishBindingError(safeFailureReason(error, 'publish_binding_authorization_unavailable', 'binding_authorization'));
|
|
67
|
+
}
|
|
68
|
+
if (response['ok'] !== true || response['binding_verified'] !== true || response['bundle_digest'] !== digest
|
|
69
|
+
|| requestDigest !== digest || hub.publishBundleDigest(requestAssets) !== requestDigest
|
|
70
|
+
|| hub.publishBundleDigest(assets) !== digest) {
|
|
71
|
+
throw new LocalPublishBindingError('publish_binding_authorization_invalid');
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/** 显式迁移产生新记录;原始资产和历史 trace 不原地更新,也不自动广播。 */
|
|
75
|
+
export async function reverifyPublishBundle(bundle, env, resolveProxy = proxyClientFromEnv) {
|
|
76
|
+
if (bundle.length !== 2)
|
|
77
|
+
throw new LocalPublishBindingError('publish_reverification_pair_required');
|
|
78
|
+
let assets;
|
|
79
|
+
try {
|
|
80
|
+
assets = structuredClone(bundle).map(hub.normalizePublishReverificationSource);
|
|
81
|
+
}
|
|
82
|
+
catch (error) {
|
|
83
|
+
throw new LocalPublishBindingError(safeFailureReason(error, 'publish_reverification_invalid_wire'));
|
|
84
|
+
}
|
|
85
|
+
if (assets.length !== 2 || assets.filter((asset) => asset.type === 'Gene').length !== 1
|
|
86
|
+
|| assets.filter((asset) => asset.type === 'Capsule').length !== 1) {
|
|
87
|
+
throw new LocalPublishBindingError('publish_reverification_pair_required');
|
|
88
|
+
}
|
|
89
|
+
const expectedHubMode = mode(env);
|
|
90
|
+
const proxy = resolveProxy(env);
|
|
91
|
+
if (!proxy?.reverifyAssets)
|
|
92
|
+
throw new LocalPublishBindingError('publish_reverification_unavailable');
|
|
93
|
+
const sourceIds = assets.map((asset) => asset.asset_id).sort();
|
|
94
|
+
let response;
|
|
95
|
+
try {
|
|
96
|
+
response = record(await proxy.reverifyAssets({
|
|
97
|
+
assets, persist: true, expected_hub_mode: expectedHubMode,
|
|
98
|
+
}, { signal: AbortSignal.timeout(30_000) }));
|
|
99
|
+
}
|
|
100
|
+
catch (error) {
|
|
101
|
+
throw new LocalPublishBindingError(safeFailureReason(error, 'publish_reverification_failed'), safeReverificationRecovery({
|
|
102
|
+
...(error instanceof ProxyReverificationError ? error.recovery : {}), source_asset_ids: sourceIds,
|
|
103
|
+
}));
|
|
104
|
+
}
|
|
105
|
+
const recovery = safeReverificationRecovery({
|
|
106
|
+
...response, source_asset_ids: sourceIds,
|
|
107
|
+
asset_ids: Array.isArray(response['assets']) ? response['assets'].slice(0, 2).map((asset) => record(asset)['asset_id']) : [],
|
|
108
|
+
});
|
|
109
|
+
const returnedSourceIds = response['source_asset_ids'];
|
|
110
|
+
if (response['ok'] !== true || response['status'] !== 'reverified' || response['publishable'] !== true
|
|
111
|
+
|| response['queued'] !== false || response['stored'] !== true
|
|
112
|
+
|| !Array.isArray(response['assets']) || response['assets'].length !== 2
|
|
113
|
+
|| !Array.isArray(returnedSourceIds) || returnedSourceIds.length !== sourceIds.length
|
|
114
|
+
|| returnedSourceIds.some((id) => typeof id !== 'string')
|
|
115
|
+
|| JSON.stringify([...returnedSourceIds].sort()) !== JSON.stringify(sourceIds)) {
|
|
116
|
+
throw new LocalPublishBindingError('publish_reverification_invalid_response', recovery);
|
|
117
|
+
}
|
|
118
|
+
let verified;
|
|
119
|
+
try {
|
|
120
|
+
verified = snapshot(response['assets']);
|
|
121
|
+
if (verified.filter((asset) => asset.type === 'Gene').length !== 1
|
|
122
|
+
|| verified.filter((asset) => asset.type === 'Capsule').length !== 1
|
|
123
|
+
|| verified.some((asset) => !wire.validateWireDeep(asset.type === 'Gene' ? wire.stripGeneHints(asset) : asset).ok)) {
|
|
124
|
+
throw new Error('publish_reverification_invalid_assets');
|
|
125
|
+
}
|
|
126
|
+
hub.assertPublishBindingReceipt(verified, response['publish_receipt']);
|
|
127
|
+
}
|
|
128
|
+
catch (error) {
|
|
129
|
+
throw new LocalPublishBindingError(safeFailureReason(error, 'publish_reverification_invalid_assets'), recovery);
|
|
130
|
+
}
|
|
131
|
+
// 显式重新验证无条件读取同一 host ledger,不借用普通人工发布的“无需绑定”早退。
|
|
132
|
+
try {
|
|
133
|
+
await authorizeSnapshot(verified, expectedHubMode, proxy);
|
|
134
|
+
}
|
|
135
|
+
catch (error) {
|
|
136
|
+
throw new LocalPublishBindingError(error instanceof LocalPublishBindingError ? error.reason : 'publish_binding_authorization_unavailable', recovery);
|
|
137
|
+
}
|
|
138
|
+
return { assets: verified, sourceAssetIds: sourceIds, stored: true };
|
|
139
|
+
}
|