@evomap/evolver-cli 2.0.8 → 2.0.15

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/reuse.d.ts CHANGED
@@ -15,6 +15,9 @@ export interface ReuseEnvelope {
15
15
  * (PublicHubCapability satisfies both; a bare fetcher in tests may omit hello). */
16
16
  type AssetByIdFetcher = {
17
17
  fetchAssetById(assetId: string, options?: hubNs.FetchAssetByIdOptions): Promise<assetstore.AssetRecord | null>;
18
+ /** Preferred: says WHY there is no asset, so "the hub does not have it" and "the hub delivered something
19
+ * unusable" stop sharing one status. Optional so a bare fetcher (tests, private proxy) still satisfies this. */
20
+ fetchAssetDeliveryById?(assetId: string, options?: hubNs.FetchAssetByIdOptions): Promise<hubNs.AssetDeliveryOutcome>;
18
21
  hello?(opts: PublicHelloOptions): Promise<unknown>;
19
22
  };
20
23
  type PrivateReuseProxy = {
package/dist/reuse.js CHANGED
@@ -10,7 +10,7 @@
10
10
  // and degrades to the agent `/pack apply` path on any non-ok result. Two hard rules follow:
11
11
  // 1. Print EXACTLY ONE envelope object to STDOUT on BOTH success and failure (in --json mode).
12
12
  // 2. NEVER let a token/secret reach any stream — error text is mapped to fixed messages / redacted.
13
- import { assetstore, events, hub as hubNs, wire } from '@evomap/evolver-core';
13
+ import { assetrepair, assetstore, events, hub as hubNs, wire } from '@evomap/evolver-core';
14
14
  import { AuthError, HubClientError, HubUnreachableError, connectPublicHub, isHubDryRunEnabled, stripHubDeliveryMetadataForIntegrity, } from '@evomap/evolver-adapter-public';
15
15
  import { loadEnvFileFromEnv, proxyClientFromEnv } from '@evomap/evolver-mcp';
16
16
  import { createRecipeHubFromEnv } from './recipe.js';
@@ -82,23 +82,27 @@ export async function runReuseCommand(argv, deps = {}) {
82
82
  await establishReuseTrust(hub);
83
83
  // This command owns the quarantine path below. Keep the shared adapter strict for every other caller and
84
84
  // explicitly request an exact declared-ID delivery only where we will revalidate and freeze it as unverified.
85
- const asset = await hub.fetchAssetById(opts.id, { allowUnverifiedExactIdentity: true });
86
- if (!asset)
85
+ const delivery = await fetchReuseDelivery(hub, opts.id);
86
+ if (delivery.status === 'absent')
87
87
  return emit({ ok: false, status: 'not_found', message: 'asset not found on the hub' }, ctx);
88
- const { record, verified } = await ingestHubAsset(store, deps, asset, opts.id);
88
+ if (delivery.status === 'rejected')
89
+ return emit(rejectedDeliveryOutcome(delivery.reason), ctx);
90
+ const { record, verified, repaired } = await ingestHubAsset(store, deps, delivery.asset, opts.id);
89
91
  logReuse(deps, opts, record, 'hub');
90
92
  // Both land the asset (exit 0). A verified reuse is a plain success; an unverified one is a first-class
91
93
  // success too — the operator's save happened — but carries reason `unverified` so the desktop adapter can
92
94
  // surface "added (unverified)" instead of a plain "added". status stays `ok` so older desktop builds, which
93
95
  // key success on status==='ok' and ignore reason, keep working unchanged.
94
- return emit(verified
95
- ? { ok: true, status: 'ok', message: 'reused into local recall library' }
96
- : {
97
- ok: true,
98
- status: 'ok',
99
- reason: 'unverified',
100
- message: 'reused into local recall library as untrusted: hub-delivered content does not match its content fingerprint and could not be verified',
101
- }, ctx);
96
+ if (verified)
97
+ return emit({ ok: true, status: 'ok', message: 'reused into local recall library' }, ctx);
98
+ return emit({
99
+ ok: true,
100
+ status: 'ok',
101
+ reason: 'unverified',
102
+ message: repaired
103
+ ? 'reused into local recall library as untrusted: hub-delivered content was incomplete and was repaired to a schema-valid record; it does not match its content fingerprint and could not be verified'
104
+ : 'reused into local recall library as untrusted: hub-delivered content does not match its content fingerprint and could not be verified',
105
+ }, ctx);
102
106
  }
103
107
  catch (e) {
104
108
  return emit(mapError(e), ctx);
@@ -237,6 +241,7 @@ class ReuseIntegrityError extends Error {
237
241
  const INTEGRITY_MISMATCH_MESSAGE = 'hub-delivered content does not match the asset content fingerprint';
238
242
  const INTEGRITY_BACKFILLED_MESSAGE = 'hub delivered a synthesized payload for this asset; the original published content is unavailable for verification';
239
243
  const INTEGRITY_LOGICAL_ID_MESSAGE = 'hub-delivered asset does not match the requested logical id';
244
+ const INTEGRITY_INCOMPLETE_MESSAGE = 'hub-delivered content is missing fields that cannot be repaired without the original publisher';
240
245
  const INTEGRITY_REVOKED_MESSAGE = 'hub-delivered asset has been revoked';
241
246
  function integrityError(synthesized) {
242
247
  return new ReuseIntegrityError(synthesized ? INTEGRITY_BACKFILLED_MESSAGE : INTEGRITY_MISMATCH_MESSAGE);
@@ -245,16 +250,21 @@ async function ingestHubAsset(store, deps, asset, requestedId) {
245
250
  const delivery = unwrapHubAssetContent(asset);
246
251
  // Use the same content projection as the public adapter and sync. Delivery metadata is classified first, then
247
252
  // removed from every hash and from the stored bytes; Capsule confidence remains canonical content.
248
- const cleaned = stripHubDeliveryMetadataForIntegrity(delivery.content);
253
+ const projection = stripHubDeliveryMetadataForIntegrity(delivery.content);
249
254
  const synthesized = delivery.synthesized;
250
- const type = stringField(cleaned, 'type');
251
- const contentAssetId = stringField(cleaned, 'asset_id');
252
- if ((type !== 'Gene' && type !== 'Capsule')
253
- || !contentAssetId
254
- || !isContentAssetId(contentAssetId)
255
- || !wire.validateWireDeep(cleaned).ok) {
255
+ const type = stringField(projection, 'type');
256
+ const contentAssetId = stringField(projection, 'asset_id');
257
+ if ((type !== 'Gene' && type !== 'Capsule') || !contentAssetId || !isContentAssetId(contentAssetId)) {
256
258
  throw integrityError(synthesized);
257
259
  }
260
+ // The hub delivers a LOSSY projection of the published record (dropped `schema_version`/`id`, emptied
261
+ // `constraints`, extra non-schema keys — measured across promoted genes on 2026-08-14), so a schema verdict
262
+ // here is a verdict on the DELIVERY, not on the asset. Repair it into a storable record instead of throwing
263
+ // the asset away; the identity guards below stay untouched, and the result is still quarantined as unverified.
264
+ const repair = repairHubProjection(projection, contentAssetId);
265
+ if (!repair.ok)
266
+ throw new ReuseIntegrityError(repair.message);
267
+ const cleaned = repair.record;
258
268
  try {
259
269
  assetstore.assertCapsuleGeneBinding(cleaned);
260
270
  }
@@ -290,13 +300,60 @@ async function ingestHubAsset(store, deps, asset, requestedId) {
290
300
  const stored = await assetstore.ingestUntrustedConditional(store, provenance, cleaned);
291
301
  if (stored.status === 'logical_collision')
292
302
  throw new Error('local asset id conflict');
293
- return { record: { ...cleaned, asset_id: stored.asset_id }, verified: true };
303
+ return { record: { ...cleaned, asset_id: stored.asset_id }, verified: true, repaired: false };
294
304
  }
295
305
  const reason = synthesized ? 'unverified_hub_synthesized' : 'unverified_hub_rewrite';
296
306
  const stored = await assetstore.ingestUnverifiedConditional(store, provenance, cleaned, reason);
297
307
  if (stored.status === 'logical_collision')
298
308
  throw new Error('local asset id conflict');
299
- return { record: { ...cleaned, asset_id: stored.asset_id }, verified: false };
309
+ return { record: { ...cleaned, asset_id: stored.asset_id }, verified: false, repaired: repair.repaired };
310
+ }
311
+ /**
312
+ * Make a hub delivery storable without letting it drift off the network identity it was fetched under.
313
+ * `repairAssetRecord` re-derives `asset_id` from the repaired content by design; here the DECLARED network id
314
+ * must survive instead, because the quarantine write freezes the repaired body under that id.
315
+ */
316
+ function repairHubProjection(projection, declaredAssetId) {
317
+ const report = assetrepair.repairAssetRecord(projection);
318
+ if (report.status === 'already_valid')
319
+ return { ok: true, record: projection, repaired: false };
320
+ if (report.status === 'unrepairable') {
321
+ return { ok: false, message: `${INTEGRITY_INCOMPLETE_MESSAGE}: ${blockerSummary(report.blockers)}` };
322
+ }
323
+ const repairedContent = report.changes.some((change) => change.path !== 'asset_id');
324
+ return {
325
+ ok: true,
326
+ record: { ...report.asset, asset_id: declaredAssetId },
327
+ repaired: repairedContent,
328
+ };
329
+ }
330
+ // Hard rule 2 of this command: nothing dynamic reaches a stream unfiltered. Field paths come from the schema
331
+ // gate, but an `additionalProperties` path is named by hub-controlled content — so only plain field-path shapes
332
+ // pass, and only a handful of them.
333
+ const SAFE_FIELD_PATH = /^[A-Za-z0-9_.[\]]{1,40}$/;
334
+ function blockerSummary(blockers) {
335
+ const fields = [...new Set(blockers.map((blocker) => blocker.path))]
336
+ .filter((path) => SAFE_FIELD_PATH.test(path))
337
+ .slice(0, 5);
338
+ return fields.length > 0 ? `unrepairable fields: ${fields.join(', ')}` : 'the delivered record could not be classified';
339
+ }
340
+ async function fetchReuseDelivery(hub, assetId) {
341
+ const options = { allowUnverifiedExactIdentity: true };
342
+ if (hub.fetchAssetDeliveryById)
343
+ return hub.fetchAssetDeliveryById(assetId, options);
344
+ const asset = await hub.fetchAssetById(assetId, options);
345
+ return asset ? { status: 'delivered', asset, verified: true } : { status: 'absent' };
346
+ }
347
+ // A delivered-but-refused asset is NOT a missing asset. Reporting both as `not_found` sent operators looking for
348
+ // an asset the hub was serving the whole time; each rejection now names what the hub actually did.
349
+ function rejectedDeliveryOutcome(reason) {
350
+ const messages = {
351
+ identity_mismatch: 'hub delivered an asset whose identity does not match the requested id',
352
+ revoked: INTEGRITY_REVOKED_MESSAGE,
353
+ ambiguous: 'hub delivered conflicting copies of the requested asset',
354
+ unverified_not_allowed: INTEGRITY_MISMATCH_MESSAGE,
355
+ };
356
+ return { ok: false, status: 'integrity_failed', message: messages[reason] };
300
357
  }
301
358
  async function resolveLocalReuseAsset(store, id) {
302
359
  // A logical id does not identify an asset type. Gene and Capsule ids may overlap, so only the Hub can resolve
@@ -4,6 +4,11 @@ export interface RuntimeSessionSource {
4
4
  label: string;
5
5
  sessionId?: string;
6
6
  resumeIdentityProvenance?: 'canonical_native_transcript';
7
+ /**
8
+ * Canonical task domain slug when producer resolved exactly one `task_domain:` token.
9
+ * Absent/ambiguous/invalid domains are never invented here — omit the field.
10
+ */
11
+ taskDomain?: string;
7
12
  turns: NormalizedTurn[];
8
13
  }
9
14
  export interface RuntimeSessionParseDiagnostics {
@@ -1,6 +1,12 @@
1
1
  import { events, material as materialNs } from '@evomap/evolver-core';
2
2
  import { type RuntimeSessionMaterialSnapshotV1 } from './materialSnapshot.js';
3
- import { type RuntimeSessionParseDiagnostics } from './runtimeSessionSource.js';
3
+ import { type RuntimeSessionParseDiagnostics, type RuntimeSessionSource } from './runtimeSessionSource.js';
4
+ /**
5
+ * Stamp a resolved canonical task domain onto each source when turn/signal text carries exactly one
6
+ * valid `task_domain:` token. Never invents domains; absent/ambiguous/invalid → leave field unset.
7
+ * Additive only — does not mutate parse diagnostics or turn content.
8
+ */
9
+ export declare function stampResolvedTaskDomain(sources: readonly RuntimeSessionSource[]): RuntimeSessionSource[];
4
10
  /** Material consumer group shared by ingestion and the downstream cycle consumer. */
5
11
  export declare const INGEST_CONSUMER_GROUP = "cycle";
6
12
  /** Injectable substrate dependencies for session and trace ingestion. */
@@ -5,6 +5,30 @@ import { isCursorStateVscdbPath } from '@evomap/evolver-runtime-adapters';
5
5
  import { emitSessionRecall } from './autoRecall.js';
6
6
  import { buildRuntimeSessionMaterialSnapshot } from './materialSnapshot.js';
7
7
  import { isRuntimeSessionSourcePath, parseRuntimeSessionSourcesWithDiagnostics, } from './runtimeSessionSource.js';
8
+ /** Wire-form `task_domain:` tokens embedded in session text (case-insensitive match; resolver fail-closes). */
9
+ const TASK_DOMAIN_TOKEN_RE = /\btask_domain:[A-Za-z0-9][A-Za-z0-9-]{0,63}\b/gi;
10
+ /**
11
+ * Stamp a resolved canonical task domain onto each source when turn/signal text carries exactly one
12
+ * valid `task_domain:` token. Never invents domains; absent/ambiguous/invalid → leave field unset.
13
+ * Additive only — does not mutate parse diagnostics or turn content.
14
+ */
15
+ export function stampResolvedTaskDomain(sources) {
16
+ return sources.map((source) => {
17
+ const tokens = [];
18
+ for (const turn of source.turns) {
19
+ const text = `${turn.text ?? ''}\n${turn.errorMessage ?? ''}\n${turn.toolResult ?? ''}`;
20
+ for (const match of text.matchAll(TASK_DOMAIN_TOKEN_RE)) {
21
+ tokens.push(match[0].toLowerCase());
22
+ }
23
+ }
24
+ const resolution = signals.resolveTaskDomainSignals(tokens);
25
+ if (resolution.status !== 'resolved')
26
+ return source;
27
+ if (source.taskDomain === resolution.slug)
28
+ return source;
29
+ return { ...source, taskDomain: resolution.slug };
30
+ });
31
+ }
8
32
  /** Material consumer group shared by ingestion and the downstream cycle consumer. */
9
33
  export const INGEST_CONSUMER_GROUP = 'cycle';
10
34
  export function resolveIngestDeps(deps) {
@@ -115,7 +139,7 @@ export async function runSessionIngestTick(dirs, deps = {}) {
115
139
  continue;
116
140
  }
117
141
  try {
118
- const parsedSources = parsed.sources;
142
+ const parsedSources = stampResolvedTaskDomain(parsed.sources);
119
143
  const agent = parsedSources[0] ? toMaterialSourceAgent(parsedSources[0].agent) : undefined;
120
144
  if (parsedSources.length === 0 || !agent)
121
145
  continue;
@@ -1,7 +1,7 @@
1
1
  import { createHash } from 'node:crypto';
2
2
  import { realpathSync, statSync } from 'node:fs';
3
3
  import { basename, dirname, isAbsolute, join, resolve, sep } from 'node:path';
4
- import { algo, assetstore, events, exec, verify, wire, workflow } from '@evomap/evolver-core';
4
+ import { algo, assetstore, events, exec, schema, verify, wire, workflow } from '@evomap/evolver-core';
5
5
  import { readAutoExecConfig } from './autoexecConfig.js';
6
6
  import { runRequiredSandboxedValidation } from './requiredSandboxValidation.js';
7
7
  const DEFAULT_MAX_CONCURRENT_RUNS = 4;
@@ -256,10 +256,11 @@ function safeScore(value) {
256
256
  return Number.isFinite(value) ? Math.max(0, Math.min(1, value)) : 0;
257
257
  }
258
258
  function diffSummary(result) {
259
- const diff = result.proofOfWork?.kind === 'git_diff' ? result.proofOfWork.gitDiff : undefined;
259
+ // #961: snake_case 优先, 兼容读旧 camelCase 存量资产(gitDiffOf).
260
+ const diff = result.proofOfWork?.kind === 'git_diff' ? schema.gitDiffOf(result.proofOfWork) : undefined;
260
261
  return {
261
- changedFiles: Number.isSafeInteger(diff?.files) && (diff?.files ?? -1) >= 0 ? diff.files : 0,
262
- changedLines: Number.isSafeInteger(diff?.lines) && (diff?.lines ?? -1) >= 0 ? diff.lines : 0,
262
+ changedFiles: Number.isSafeInteger(diff?.files) && (diff?.files ?? -1) >= 0 ? (diff?.files ?? 0) : 0,
263
+ changedLines: Number.isSafeInteger(diff?.lines) && (diff?.lines ?? -1) >= 0 ? (diff?.lines ?? 0) : 0,
263
264
  };
264
265
  }
265
266
  async function requireReviewedGene(context, store, provenance, review) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@evomap/evolver-cli",
3
- "version": "2.0.8",
3
+ "version": "2.0.15",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "engines": {
@@ -23,12 +23,12 @@
23
23
  }
24
24
  },
25
25
  "dependencies": {
26
- "@evomap/evolver-core": "2.0.8",
27
- "@evomap/evolver-adapter-public": "2.0.8",
28
- "@evomap/evolver-mcp": "2.0.8",
29
- "@evomap/evolver-proxy": "2.0.8",
30
- "@evomap/evolver-runtime-adapters": "2.0.8",
31
- "@evomap/evolver-webui": "2.0.8"
26
+ "@evomap/evolver-core": "2.0.15",
27
+ "@evomap/evolver-adapter-public": "2.0.15",
28
+ "@evomap/evolver-mcp": "2.0.15",
29
+ "@evomap/evolver-proxy": "2.0.15",
30
+ "@evomap/evolver-runtime-adapters": "2.0.15",
31
+ "@evomap/evolver-webui": "2.0.15"
32
32
  },
33
33
  "repository": {
34
34
  "type": "git",