@evomap/evolver-cli 2.0.0-beta.10 → 2.0.0-beta.12

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.
@@ -18,6 +18,7 @@ function renderText(report, stdout) {
18
18
  `corrupt=${report.totals.corruptRows}`,
19
19
  `duplicate=${report.totals.duplicateRows}`,
20
20
  `hash_mismatch=${report.totals.hashMismatchRows}`,
21
+ `unverified=${report.totals.unverifiedRows}`,
21
22
  `schema_invalid=${report.totals.schemaInvalidRows}`,
22
23
  `unsafe=${report.totals.unsafeFiles}`,
23
24
  `unavailable=${report.totals.unavailableFiles}`,
@@ -32,6 +33,7 @@ function renderText(report, stdout) {
32
33
  `corrupt=${file.corruptRows}`,
33
34
  `duplicate=${file.duplicateRows}`,
34
35
  `hash_mismatch=${file.hashMismatchRows}`,
36
+ `unverified=${file.unverifiedRows}`,
35
37
  `schema_invalid=${file.schemaInvalidRows}`,
36
38
  ...(file.unterminated ? ['unterminated=true'] : []),
37
39
  ...(file.reason ? [`reason=${file.reason}`] : []),
@@ -34,9 +34,12 @@ export interface LifecycleResult {
34
34
  files?: string[];
35
35
  service?: string;
36
36
  }
37
+ type UnixRecoveryControllerModule = Pick<typeof import('@evomap/evolver-proxy'), 'provisionStableUnixRecoveryController' | 'stableUnixRecoveryControllerPathForTarget' | 'UNIX_RECOVERY_CONTROLLER_ARG'>;
38
+ type LoadUnixRecoveryController = () => Promise<UnixRecoveryControllerModule>;
37
39
  interface RunLifecycleDeps {
38
40
  argv1?: string;
39
41
  env?: NodeJS.ProcessEnv;
42
+ loadUnixRecoveryController?: LoadUnixRecoveryController;
40
43
  stdout?: (text: string) => void;
41
44
  stderr?: (text: string) => void;
42
45
  }
package/dist/lifecycle.js CHANGED
@@ -73,7 +73,7 @@ async function runLifecycleCommandInner(argv, deps) {
73
73
  if (envFileResult.error)
74
74
  throw new Error('failed to load lifecycle environment file');
75
75
  const target = serviceTarget(flags);
76
- const result = await installService(target, flags, env, deps.argv1 ?? process.argv[1]);
76
+ const result = await installService(target, flags, env, deps.argv1 ?? process.argv[1], deps.loadUnixRecoveryController);
77
77
  stdout(`${JSON.stringify(result, null, 2)}\n`);
78
78
  return 0;
79
79
  }
@@ -494,7 +494,7 @@ function serviceTarget(flags) {
494
494
  return value;
495
495
  throw new Error('missing or invalid --target (expected: launchd|systemd|windows)');
496
496
  }
497
- async function installService(target, flags, env, argv1) {
497
+ async function installService(target, flags, env, argv1, loadUnixRecoveryController = () => import('@evomap/evolver-proxy')) {
498
498
  const dryRun = flags['dry-run'] === true;
499
499
  const envFile = typeof flags['env-file'] === 'string' ? flags['env-file'] : env['EVOLVER_ENV_FILE'];
500
500
  const supervised = configuredSelfUpdateTarget(env)
@@ -506,7 +506,7 @@ async function installService(target, flags, env, argv1) {
506
506
  let unixController;
507
507
  let unixControllerStateDir;
508
508
  if (target !== 'windows' && standaloneTarget) {
509
- const { provisionStableUnixRecoveryController, stableUnixRecoveryControllerPathForTarget, UNIX_RECOVERY_CONTROLLER_ARG, } = await import('@evomap/evolver-proxy');
509
+ const { provisionStableUnixRecoveryController, stableUnixRecoveryControllerPathForTarget, UNIX_RECOVERY_CONTROLLER_ARG, } = await loadUnixRecoveryController();
510
510
  const stateDir = env['EVOLVER_SELF_UPDATE_STATE_DIR']?.trim() || undefined;
511
511
  const controllerPath = dryRun
512
512
  ? stableUnixRecoveryControllerPathForTarget(standaloneTarget, stateDir)
package/dist/reuse.js CHANGED
@@ -98,9 +98,20 @@ export async function runReuseCommand(argv, deps = {}) {
98
98
  const asset = await hub.fetchAssetById(opts.id);
99
99
  if (!asset)
100
100
  return emit({ ok: false, status: 'not_found', message: `asset ${opts.id} not found on the hub` }, ctx);
101
- const cleaned = await ingestHubAsset(store, deps, asset, opts.id);
102
- logReuse(deps, opts, cleaned, 'hub');
103
- return emit({ ok: true, status: 'ok', message: 'reused into local recall library' }, ctx);
101
+ const { record, verified } = await ingestHubAsset(store, deps, asset, opts.id);
102
+ logReuse(deps, opts, record, 'hub');
103
+ // Both land the asset (exit 0). A verified reuse is a plain success; an unverified one is a first-class
104
+ // success too — the operator's save happened — but carries reason `unverified` so the desktop adapter can
105
+ // surface "added (unverified)" instead of a plain "added". status stays `ok` so older desktop builds, which
106
+ // key success on status==='ok' and ignore reason, keep working unchanged.
107
+ return emit(verified
108
+ ? { ok: true, status: 'ok', message: 'reused into local recall library' }
109
+ : {
110
+ ok: true,
111
+ status: 'ok',
112
+ reason: 'unverified',
113
+ message: 'reused into local recall library as untrusted: hub-delivered content does not match its content fingerprint and could not be verified',
114
+ }, ctx);
104
115
  }
105
116
  catch (e) {
106
117
  return emit(mapError(e), ctx);
@@ -176,27 +187,59 @@ class ReuseIntegrityError extends Error {
176
187
  const INTEGRITY_MISMATCH_MESSAGE = 'hub-delivered content does not match the asset content fingerprint';
177
188
  const INTEGRITY_BACKFILLED_MESSAGE = 'hub delivered a synthesized payload for this asset; the original published content is unavailable for verification';
178
189
  const INTEGRITY_LOGICAL_ID_MESSAGE = 'hub-delivered asset does not match the requested logical id';
179
- function integrityError(content) {
180
- const backfilled = stringField(content, 'payload_backfill_reason') !== undefined;
181
- return new ReuseIntegrityError(backfilled ? INTEGRITY_BACKFILLED_MESSAGE : INTEGRITY_MISMATCH_MESSAGE);
190
+ function integrityError(synthesized) {
191
+ return new ReuseIntegrityError(synthesized ? INTEGRITY_BACKFILLED_MESSAGE : INTEGRITY_MISMATCH_MESSAGE);
182
192
  }
183
193
  async function ingestHubAsset(store, deps, asset, requestedId) {
184
- const cleaned = stripHubMetadata(unwrapHubAssetContent(asset));
194
+ const delivered = stripHubMetadata(unwrapHubAssetContent(asset));
195
+ // `payload_backfill_reason` is a hub DELIVERY marker (unwrapHubAssetContent lifts it onto the content so a
196
+ // synthesized payload can be classified). It is NOT publisher content, so it must be excluded from EVERY hash
197
+ // — identity, the local-conflict check, AND the stored bytes — and never persisted. Capture the
198
+ // classification fact, then drop the marker ONCE, up front: hashing it here but stripping it before storage
199
+ // made assertNoLocalReuseIdConflict hash a different byte string than what landed on disk, throwing a false
200
+ // id conflict on the second reuse of the same synthesized asset (Bugbot HIGH, broke idempotency).
201
+ const synthesized = stringField(delivered, 'payload_backfill_reason') !== undefined;
202
+ const cleaned = withoutHubDeliveryMarkers(delivered);
185
203
  const actualAssetId = wire.computeAssetId(cleaned);
186
204
  const contentAssetId = stringField(cleaned, 'asset_id');
187
- if (!actualAssetId || !contentAssetId || actualAssetId !== contentAssetId) {
188
- throw integrityError(cleaned);
205
+ if (!actualAssetId || !contentAssetId) {
206
+ // Malformed beyond classification — no computable hash or no declared id — stays a hard reject.
207
+ throw integrityError(synthesized);
189
208
  }
190
- if (isContentAssetId(requestedId) && actualAssetId !== requestedId) {
191
- throw integrityError(cleaned);
209
+ // Identity guards stay STRICT: a hub that returned a DIFFERENT asset than requested (a self-consistent asset
210
+ // B under a request for A, or a different logical id) is a delivery fault, not the hub's known content-rewrite
211
+ // of the RIGHT asset — reject it so a reuse never silently pulls the wrong gene.
212
+ if (isContentAssetId(requestedId)) {
213
+ if (contentAssetId !== requestedId)
214
+ throw integrityError(synthesized);
192
215
  }
193
- if (!isContentAssetId(requestedId) && stringField(cleaned, 'id') !== requestedId) {
216
+ else if (stringField(cleaned, 'id') !== requestedId) {
194
217
  throw new ReuseIntegrityError(INTEGRITY_LOGICAL_ID_MESSAGE);
195
218
  }
196
219
  await assertNoLocalReuseIdConflict(cleaned, store);
197
220
  const provenance = new assetstore.ProvenanceStore(storeBaseDir(store, deps));
198
- const stored = await assetstore.ingestUntrusted(store, provenance, cleaned, 'hub');
199
- return { ...cleaned, asset_id: stored.asset_id };
221
+ // Identity is confirmed; now content integrity. When the (marker-free) payload hashes to its declared id it
222
+ // lands verified (still sidecar-marked untrusted per #30). When it does NOT, the hub rewrote the delivered
223
+ // bytes of the right asset (#570) — DOWNGRADE instead of reject: freeze it under the network id and mark it
224
+ // unverified so the save actually happens and the loop (which already reuses hub content without
225
+ // re-verifying) can use it, while trust-first selection keeps it out of the reasoning pool until promotion.
226
+ if (actualAssetId === contentAssetId) {
227
+ const stored = await assetstore.ingestUntrusted(store, provenance, cleaned, 'hub');
228
+ return { record: { ...cleaned, asset_id: stored.asset_id }, verified: true };
229
+ }
230
+ const reason = synthesized ? 'unverified_hub_synthesized' : 'unverified_hub_rewrite';
231
+ const stored = await assetstore.ingestUnverified(store, provenance, cleaned, reason, 'hub');
232
+ return { record: { ...cleaned, asset_id: stored.asset_id }, verified: false };
233
+ }
234
+ /**
235
+ * Drop hub DELIVERY markers that unwrapHubAssetContent lifts onto the content for classification but that must
236
+ * never reach content-addressed storage. Right now that is `payload_backfill_reason`; keeping this as a named
237
+ * helper localizes the "these keys describe HOW the hub delivered the asset, not the asset" rule.
238
+ */
239
+ function withoutHubDeliveryMarkers(asset) {
240
+ const rest = { ...asset };
241
+ delete rest['payload_backfill_reason'];
242
+ return rest;
200
243
  }
201
244
  async function resolveLocalReuseAsset(store, id) {
202
245
  const direct = await store.get(id);
@@ -332,7 +375,7 @@ function mapError(e) {
332
375
  function emit(outcome, ctx) {
333
376
  if (ctx.jsonOut) {
334
377
  // stdout ONLY, exactly one object — the desktop adapter json.Unmarshals the whole stdout stream.
335
- const envelope = { ok: outcome.ok, contract: REUSE_CONTRACT, status: outcome.status, reason: outcome.status, message: outcome.message };
378
+ const envelope = { ok: outcome.ok, contract: REUSE_CONTRACT, status: outcome.status, reason: outcome.reason ?? outcome.status, message: outcome.message };
336
379
  ctx.stdout(JSON.stringify(envelope));
337
380
  }
338
381
  else if (outcome.ok) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@evomap/evolver-cli",
3
- "version": "2.0.0-beta.10",
3
+ "version": "2.0.0-beta.12",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "evolver CLI (status/watch/cycles/rebuild-views/...)",
@@ -20,12 +20,12 @@
20
20
  }
21
21
  },
22
22
  "dependencies": {
23
- "@evomap/evolver-core": "2.0.0-beta.10",
24
- "@evomap/evolver-adapter-public": "2.0.0-beta.10",
25
- "@evomap/evolver-mcp": "2.0.0-beta.10",
26
- "@evomap/evolver-proxy": "2.0.0-beta.10",
27
- "@evomap/evolver-runtime-adapters": "2.0.0-beta.10",
28
- "@evomap/evolver-webui": "2.0.0-beta.10"
23
+ "@evomap/evolver-core": "2.0.0-beta.12",
24
+ "@evomap/evolver-adapter-public": "2.0.0-beta.12",
25
+ "@evomap/evolver-mcp": "2.0.0-beta.12",
26
+ "@evomap/evolver-proxy": "2.0.0-beta.12",
27
+ "@evomap/evolver-runtime-adapters": "2.0.0-beta.12",
28
+ "@evomap/evolver-webui": "2.0.0-beta.12"
29
29
  },
30
30
  "repository": {
31
31
  "type": "git",