@evomap/evolver-cli 2.0.1 → 2.0.8
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/lifecycle.d.ts +95 -5
- package/dist/lifecycle.js +4099 -241
- package/dist/lifecycleBootstrapTransaction.d.ts +235 -0
- package/dist/lifecycleBootstrapTransaction.js +2182 -0
- package/dist/reuse.d.ts +1 -1
- package/dist/reuse.js +145 -97
- package/dist/sync.d.ts +1 -1
- package/dist/sync.js +761 -174
- package/package.json +7 -7
package/dist/reuse.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ export interface ReuseEnvelope {
|
|
|
14
14
|
/** Minimal hub surface this command needs: a single fetch-by-id, plus an optional trust-establishing hello
|
|
15
15
|
* (PublicHubCapability satisfies both; a bare fetcher in tests may omit hello). */
|
|
16
16
|
type AssetByIdFetcher = {
|
|
17
|
-
fetchAssetById(assetId: string): Promise<assetstore.AssetRecord | null>;
|
|
17
|
+
fetchAssetById(assetId: string, options?: hubNs.FetchAssetByIdOptions): Promise<assetstore.AssetRecord | null>;
|
|
18
18
|
hello?(opts: PublicHelloOptions): Promise<unknown>;
|
|
19
19
|
};
|
|
20
20
|
type PrivateReuseProxy = {
|
package/dist/reuse.js
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
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
13
|
import { assetstore, events, hub as hubNs, wire } from '@evomap/evolver-core';
|
|
14
|
-
import { AuthError, HubClientError, HubUnreachableError, connectPublicHub, isHubDryRunEnabled } from '@evomap/evolver-adapter-public';
|
|
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';
|
|
17
17
|
import { getCliVersion } from './version.js';
|
|
@@ -24,29 +24,6 @@ const REUSE_USAGE = [
|
|
|
24
24
|
// Flags that consume the following token as their value. firstPositional must skip those values so a flag value
|
|
25
25
|
// (e.g. the `reference` in `--mode reference`) is never mistaken for a bare positional asset id.
|
|
26
26
|
const VALUE_FLAGS = new Set(['--id', '--mode', '--run']);
|
|
27
|
-
// Keep this list limited to Hub-only fields. `confidence` is canonical Capsule content and must
|
|
28
|
-
// survive integrity verification even though delivery rows also use a field with that name.
|
|
29
|
-
const HUB_METADATA_KEYS = new Set([
|
|
30
|
-
'credit_cost',
|
|
31
|
-
'gdi_score',
|
|
32
|
-
'success_rate',
|
|
33
|
-
'reuse_count',
|
|
34
|
-
'ranking_score',
|
|
35
|
-
'source_node_id',
|
|
36
|
-
'fetched_at',
|
|
37
|
-
'receipt',
|
|
38
|
-
'hub_receipt',
|
|
39
|
-
'already_purchased',
|
|
40
|
-
'_semantic_similarity',
|
|
41
|
-
'semantic_similarity',
|
|
42
|
-
'_search_score',
|
|
43
|
-
'search_score',
|
|
44
|
-
'_match_score',
|
|
45
|
-
'match_score',
|
|
46
|
-
'_retrieval_rank',
|
|
47
|
-
'retrieval_rank',
|
|
48
|
-
'original_asset_id',
|
|
49
|
-
]);
|
|
50
27
|
export async function runReuseCommand(argv, deps = {}) {
|
|
51
28
|
const ctx = {
|
|
52
29
|
jsonOut: argv.includes('--json'),
|
|
@@ -81,13 +58,19 @@ export async function runReuseCommand(argv, deps = {}) {
|
|
|
81
58
|
const store = deps.store ?? new assetstore.LocalJsonlProvider(deps.assetsDir ?? events.assetsDir(env));
|
|
82
59
|
// 1) Already in the local recall library → reuse is idempotent: log + ok, no hub round-trip.
|
|
83
60
|
const local = await resolveLocalReuseAsset(store, opts.id);
|
|
84
|
-
if (local
|
|
85
|
-
|
|
86
|
-
|
|
61
|
+
if (local) {
|
|
62
|
+
const disposition = localReuseDisposition(local, store, deps);
|
|
63
|
+
if (disposition === 'revoked') {
|
|
64
|
+
return emit({ ok: false, status: 'integrity_failed', message: 'local asset has been revoked' }, ctx);
|
|
65
|
+
}
|
|
66
|
+
if (disposition === 'reusable') {
|
|
67
|
+
logReuse(deps, opts, local, 'local');
|
|
68
|
+
return emit({ ok: true, status: 'ok', message: 'asset already in local recall library' }, ctx);
|
|
69
|
+
}
|
|
87
70
|
}
|
|
88
71
|
// 2) Dry-run: describe the intended pull, touch nothing.
|
|
89
72
|
if (isHubDryRunEnabled(env)) {
|
|
90
|
-
return emit({ ok: true, status: 'dry_run', message:
|
|
73
|
+
return emit({ ok: true, status: 'dry_run', message: 'would fetch the requested asset and write it to the local recall library' }, ctx);
|
|
91
74
|
}
|
|
92
75
|
// 3) Pull the global asset by id, write it into the local recall library (put dedups → idempotent on repeat).
|
|
93
76
|
const hub = deps.hub ?? createReuseFetcherFromEnv(env, deps);
|
|
@@ -97,9 +80,11 @@ export async function runReuseCommand(argv, deps = {}) {
|
|
|
97
80
|
// trust. Best-effort by design:
|
|
98
81
|
// a hello failure must not block the fetch — the fetch's own error path classifies precisely.
|
|
99
82
|
await establishReuseTrust(hub);
|
|
100
|
-
|
|
83
|
+
// This command owns the quarantine path below. Keep the shared adapter strict for every other caller and
|
|
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 });
|
|
101
86
|
if (!asset)
|
|
102
|
-
return emit({ ok: false, status: 'not_found', message:
|
|
87
|
+
return emit({ ok: false, status: 'not_found', message: 'asset not found on the hub' }, ctx);
|
|
103
88
|
const { record, verified } = await ingestHubAsset(store, deps, asset, opts.id);
|
|
104
89
|
logReuse(deps, opts, record, 'hub');
|
|
105
90
|
// Both land the asset (exit 0). A verified reuse is a plain success; an unverified one is a first-class
|
|
@@ -130,14 +115,7 @@ function createReuseFetcherFromEnv(env, deps) {
|
|
|
130
115
|
return {
|
|
131
116
|
fetchAssetById: async (assetId) => {
|
|
132
117
|
const body = await proxy.fetchAsset({ assetId, expectedHubMode: 'private' });
|
|
133
|
-
|
|
134
|
-
const payload = recordValue(root['payload']);
|
|
135
|
-
const assets = Array.isArray(root['assets']) ? root['assets'] : Array.isArray(payload['assets']) ? payload['assets'] : [];
|
|
136
|
-
const asset = assets.find((candidate) => {
|
|
137
|
-
const record = recordValue(candidate);
|
|
138
|
-
return record['asset_id'] === assetId || record['id'] === assetId;
|
|
139
|
-
});
|
|
140
|
-
return asset && typeof asset === 'object' && !Array.isArray(asset) ? asset : null;
|
|
118
|
+
return selectPrivateReuseAsset(body, assetId);
|
|
141
119
|
},
|
|
142
120
|
};
|
|
143
121
|
}
|
|
@@ -147,6 +125,48 @@ function configuredHubMode(env) {
|
|
|
147
125
|
return value;
|
|
148
126
|
throw new Error('EVOMAP_HUB_MODE must be public or private');
|
|
149
127
|
}
|
|
128
|
+
function selectPrivateReuseAsset(body, requestedId) {
|
|
129
|
+
const root = recordValue(body);
|
|
130
|
+
const payload = recordValue(root['payload']);
|
|
131
|
+
const candidates = Array.isArray(root['assets'])
|
|
132
|
+
? root['assets']
|
|
133
|
+
: Array.isArray(payload['assets'])
|
|
134
|
+
? payload['assets']
|
|
135
|
+
: [];
|
|
136
|
+
const matches = [];
|
|
137
|
+
for (const candidate of candidates) {
|
|
138
|
+
const record = optionalRecord(candidate);
|
|
139
|
+
if (!record || !privateDeliveryMatchesRequestedId(record, requestedId))
|
|
140
|
+
continue;
|
|
141
|
+
const asset = record;
|
|
142
|
+
const delivery = unwrapHubAssetContent(asset);
|
|
143
|
+
const cleaned = stripHubDeliveryMetadataForIntegrity(delivery.content);
|
|
144
|
+
let canonical;
|
|
145
|
+
try {
|
|
146
|
+
canonical = wire.canonicalize(cleaned);
|
|
147
|
+
}
|
|
148
|
+
catch {
|
|
149
|
+
throw integrityError(delivery.synthesized);
|
|
150
|
+
}
|
|
151
|
+
matches.push({ asset, canonical, synthesized: delivery.synthesized });
|
|
152
|
+
}
|
|
153
|
+
if (matches.length === 0)
|
|
154
|
+
return null;
|
|
155
|
+
if (matches.some((match) => match.canonical !== matches[0].canonical)) {
|
|
156
|
+
throw integrityError(matches.some((match) => match.synthesized));
|
|
157
|
+
}
|
|
158
|
+
return matches.find((match) => match.synthesized)?.asset ?? matches[0].asset;
|
|
159
|
+
}
|
|
160
|
+
function privateDeliveryMatchesRequestedId(record, requestedId) {
|
|
161
|
+
const payload = optionalRecord(record['payload']);
|
|
162
|
+
if (requestedId.startsWith('sha256:')) {
|
|
163
|
+
return stringField(record, 'asset_id') === requestedId
|
|
164
|
+
|| (payload !== undefined && stringField(payload, 'asset_id') === requestedId);
|
|
165
|
+
}
|
|
166
|
+
return stringField(record, 'id') === requestedId
|
|
167
|
+
|| stringField(record, 'local_id') === requestedId
|
|
168
|
+
|| (payload !== undefined && stringField(payload, 'id') === requestedId);
|
|
169
|
+
}
|
|
150
170
|
/** Flags this CLI understands. parseReuseArgs walks argv and rejects anything outside this set with reason
|
|
151
171
|
* `unsupported` so a typoed flag never silently falls through to a Hub round-trip — review blocker on V1 #283
|
|
152
172
|
* (the previous tightening lived only in cliContracts.ts; dispatch.ts routes `reuse` here, so this is the path
|
|
@@ -170,7 +190,7 @@ export function parseReuseArgs(argv) {
|
|
|
170
190
|
const eq = token.indexOf('=');
|
|
171
191
|
const flag = eq >= 0 ? token.slice(0, eq) : token;
|
|
172
192
|
if (!KNOWN_REUSE_FLAGS.has(flag))
|
|
173
|
-
return { ok: false, status: 'unsupported', error:
|
|
193
|
+
return { ok: false, status: 'unsupported', error: 'unsupported reuse argument' };
|
|
174
194
|
if (eq < 0 && VALUE_FLAGS.has(flag)) {
|
|
175
195
|
// Value flag in space form consumes the next token; skip it so it doesn't get re-checked as a flag/positional.
|
|
176
196
|
const next = argv[i + 1];
|
|
@@ -183,10 +203,10 @@ export function parseReuseArgs(argv) {
|
|
|
183
203
|
// `--`-prefixed check above and would otherwise be silently accepted as an asset id, violating the
|
|
184
204
|
// fail-closed contract. Legal asset ids (`sha256:…`, `gene_distilled_…`, logical ids) never start with `-`.
|
|
185
205
|
if (token.startsWith('-'))
|
|
186
|
-
return { ok: false, status: 'unsupported', error:
|
|
206
|
+
return { ok: false, status: 'unsupported', error: 'unsupported reuse argument' };
|
|
187
207
|
// First (and only) bare positional is the asset id; further positionals are unsupported.
|
|
188
208
|
if (positional !== undefined)
|
|
189
|
-
return { ok: false, status: 'unsupported', error:
|
|
209
|
+
return { ok: false, status: 'unsupported', error: 'unsupported reuse argument' };
|
|
190
210
|
positional = token;
|
|
191
211
|
}
|
|
192
212
|
if (!jsonOut)
|
|
@@ -195,7 +215,7 @@ export function parseReuseArgs(argv) {
|
|
|
195
215
|
// typo'd/extra arg — or a conflicting second id — pass fail-OPEN, contradicting the fail-closed contract.
|
|
196
216
|
const idFromFlag = flagValue(argv, '--id');
|
|
197
217
|
if (idFromFlag !== null && positional !== undefined) {
|
|
198
|
-
return { ok: false, status: 'unsupported', error:
|
|
218
|
+
return { ok: false, status: 'unsupported', error: 'unsupported reuse argument' };
|
|
199
219
|
}
|
|
200
220
|
const id = idFromFlag ?? positional;
|
|
201
221
|
if (!id)
|
|
@@ -217,29 +237,43 @@ class ReuseIntegrityError extends Error {
|
|
|
217
237
|
const INTEGRITY_MISMATCH_MESSAGE = 'hub-delivered content does not match the asset content fingerprint';
|
|
218
238
|
const INTEGRITY_BACKFILLED_MESSAGE = 'hub delivered a synthesized payload for this asset; the original published content is unavailable for verification';
|
|
219
239
|
const INTEGRITY_LOGICAL_ID_MESSAGE = 'hub-delivered asset does not match the requested logical id';
|
|
240
|
+
const INTEGRITY_REVOKED_MESSAGE = 'hub-delivered asset has been revoked';
|
|
220
241
|
function integrityError(synthesized) {
|
|
221
242
|
return new ReuseIntegrityError(synthesized ? INTEGRITY_BACKFILLED_MESSAGE : INTEGRITY_MISMATCH_MESSAGE);
|
|
222
243
|
}
|
|
223
244
|
async function ingestHubAsset(store, deps, asset, requestedId) {
|
|
224
|
-
const
|
|
225
|
-
//
|
|
226
|
-
//
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
// id conflict on the second reuse of the same synthesized asset (Bugbot HIGH, broke idempotency).
|
|
231
|
-
const synthesized = stringField(delivered, 'payload_backfill_reason') !== undefined;
|
|
232
|
-
const cleaned = withoutHubDeliveryMarkers(delivered);
|
|
233
|
-
const actualAssetId = wire.computeAssetId(cleaned);
|
|
245
|
+
const delivery = unwrapHubAssetContent(asset);
|
|
246
|
+
// Use the same content projection as the public adapter and sync. Delivery metadata is classified first, then
|
|
247
|
+
// removed from every hash and from the stored bytes; Capsule confidence remains canonical content.
|
|
248
|
+
const cleaned = stripHubDeliveryMetadataForIntegrity(delivery.content);
|
|
249
|
+
const synthesized = delivery.synthesized;
|
|
250
|
+
const type = stringField(cleaned, 'type');
|
|
234
251
|
const contentAssetId = stringField(cleaned, 'asset_id');
|
|
235
|
-
if (
|
|
252
|
+
if ((type !== 'Gene' && type !== 'Capsule')
|
|
253
|
+
|| !contentAssetId
|
|
254
|
+
|| !isContentAssetId(contentAssetId)
|
|
255
|
+
|| !wire.validateWireDeep(cleaned).ok) {
|
|
256
|
+
throw integrityError(synthesized);
|
|
257
|
+
}
|
|
258
|
+
try {
|
|
259
|
+
assetstore.assertCapsuleGeneBinding(cleaned);
|
|
260
|
+
}
|
|
261
|
+
catch (error) {
|
|
262
|
+
if (error instanceof assetstore.CapsuleGeneBindingError)
|
|
263
|
+
throw integrityError(synthesized);
|
|
264
|
+
throw error;
|
|
265
|
+
}
|
|
266
|
+
const actualAssetId = wire.computeAssetId(cleaned);
|
|
267
|
+
if (!actualAssetId || !isContentAssetId(actualAssetId)) {
|
|
236
268
|
// Malformed beyond classification — no computable hash or no declared id — stays a hard reject.
|
|
237
269
|
throw integrityError(synthesized);
|
|
238
270
|
}
|
|
239
271
|
// Identity guards stay STRICT: a hub that returned a DIFFERENT asset than requested (a self-consistent asset
|
|
240
272
|
// B under a request for A, or a different logical id) is a delivery fault, not the hub's known content-rewrite
|
|
241
273
|
// of the RIGHT asset — reject it so a reuse never silently pulls the wrong gene.
|
|
242
|
-
if (
|
|
274
|
+
if (requestedId.startsWith('sha256:')) {
|
|
275
|
+
if (!isContentAssetId(requestedId))
|
|
276
|
+
throw integrityError(synthesized);
|
|
243
277
|
if (contentAssetId !== requestedId)
|
|
244
278
|
throw integrityError(synthesized);
|
|
245
279
|
}
|
|
@@ -264,51 +298,68 @@ async function ingestHubAsset(store, deps, asset, requestedId) {
|
|
|
264
298
|
throw new Error('local asset id conflict');
|
|
265
299
|
return { record: { ...cleaned, asset_id: stored.asset_id }, verified: false };
|
|
266
300
|
}
|
|
267
|
-
/**
|
|
268
|
-
* Drop hub DELIVERY markers that unwrapHubAssetContent lifts onto the content for classification but that must
|
|
269
|
-
* never reach content-addressed storage. Right now that is `payload_backfill_reason`; keeping this as a named
|
|
270
|
-
* helper localizes the "these keys describe HOW the hub delivered the asset, not the asset" rule.
|
|
271
|
-
*/
|
|
272
|
-
function withoutHubDeliveryMarkers(asset) {
|
|
273
|
-
const rest = { ...asset };
|
|
274
|
-
delete rest['payload_backfill_reason'];
|
|
275
|
-
return rest;
|
|
276
|
-
}
|
|
277
301
|
async function resolveLocalReuseAsset(store, id) {
|
|
278
302
|
// A logical id does not identify an asset type. Gene and Capsule ids may overlap, so only the Hub can resolve
|
|
279
303
|
// which remote asset the caller requested; treating either local type as a hit can silently reuse the wrong one.
|
|
280
304
|
return isContentAssetId(id) ? store.get(id) : null;
|
|
281
305
|
}
|
|
282
306
|
function unwrapHubAssetContent(asset) {
|
|
283
|
-
const
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
307
|
+
const row = asset;
|
|
308
|
+
const payload = optionalRecord(row['payload']);
|
|
309
|
+
// Revocation is a delivery decision, not canonical content. Reject it before wrapper unwrapping or metadata
|
|
310
|
+
// stripping can erase the marker and accidentally turn a revoked listing/fetch race into an ingestible asset.
|
|
311
|
+
if (hasRevokedDeliveryMarker(row) || (payload !== undefined && hasRevokedDeliveryMarker(payload))) {
|
|
312
|
+
throw new ReuseIntegrityError(INTEGRITY_REVOKED_MESSAGE);
|
|
313
|
+
}
|
|
314
|
+
const outerType = stringField(row, 'type');
|
|
315
|
+
const innerType = payload ? stringField(payload, 'type') : undefined;
|
|
316
|
+
const synthesized = stringField(row, 'payload_backfill_reason') !== undefined
|
|
317
|
+
|| (payload !== undefined && stringField(payload, 'payload_backfill_reason') !== undefined);
|
|
318
|
+
// A typed row is already a raw GEP record. Do not reinterpret a canonical payload field as a delivery wrapper.
|
|
319
|
+
if (outerType !== undefined || !payload || innerType === undefined) {
|
|
320
|
+
const transportType = stringField(row, 'asset_type');
|
|
321
|
+
const transportLogicalId = stringField(row, 'local_id');
|
|
322
|
+
if ((transportType !== undefined && transportType !== outerType)
|
|
323
|
+
|| (transportLogicalId !== undefined && transportLogicalId !== stringField(row, 'id'))) {
|
|
324
|
+
throw integrityError(synthesized);
|
|
289
325
|
}
|
|
290
|
-
return content;
|
|
326
|
+
return { content: asset, synthesized };
|
|
291
327
|
}
|
|
292
|
-
|
|
328
|
+
const outerAssetId = stringField(row, 'asset_id');
|
|
329
|
+
const innerAssetId = stringField(payload, 'asset_id');
|
|
330
|
+
const outerAssetType = stringField(row, 'asset_type');
|
|
331
|
+
const innerLogicalId = stringField(payload, 'id');
|
|
332
|
+
if (!outerAssetId
|
|
333
|
+
|| !innerAssetId
|
|
334
|
+
|| outerAssetId !== innerAssetId
|
|
335
|
+
|| (outerAssetType !== undefined && outerAssetType !== innerType)
|
|
336
|
+
|| (stringField(row, 'id') !== undefined && stringField(row, 'id') !== innerLogicalId)
|
|
337
|
+
|| (stringField(row, 'local_id') !== undefined && stringField(row, 'local_id') !== innerLogicalId)) {
|
|
338
|
+
throw integrityError(synthesized);
|
|
339
|
+
}
|
|
340
|
+
return { content: payload, synthesized };
|
|
293
341
|
}
|
|
294
|
-
function
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
return out;
|
|
342
|
+
function hasRevokedDeliveryMarker(record) {
|
|
343
|
+
return ['status', 'trust_state'].some((key) => {
|
|
344
|
+
const value = record[key];
|
|
345
|
+
return typeof value === 'string' && value.trim().toLowerCase() === 'revoked';
|
|
346
|
+
});
|
|
300
347
|
}
|
|
301
348
|
function storeBaseDir(store, deps) {
|
|
302
349
|
return store instanceof assetstore.LocalJsonlProvider
|
|
303
350
|
? store.baseDir
|
|
304
351
|
: deps.assetsDir ?? events.assetsDir(deps.env ?? process.env);
|
|
305
352
|
}
|
|
306
|
-
function
|
|
307
|
-
if (wire.verifyAssetId(asset))
|
|
308
|
-
return false;
|
|
353
|
+
function localReuseDisposition(asset, store, deps) {
|
|
309
354
|
const record = new assetstore.ProvenanceStore(storeBaseDir(store, deps)).get(asset.asset_id);
|
|
310
|
-
|
|
311
|
-
|
|
355
|
+
// An explicit revoke dominates content-hash validity and every prior trust state. Do not let a canonical body
|
|
356
|
+
// bypass the operator decision, and do not fall through to Hub refetch: this local id is intentionally blocked.
|
|
357
|
+
if (record?.decision === 'revoked')
|
|
358
|
+
return 'revoked';
|
|
359
|
+
if (wire.verifyAssetId(asset))
|
|
360
|
+
return 'reusable';
|
|
361
|
+
if (record?.trusted === true || record?.decision === 'promoted')
|
|
362
|
+
return 'reusable';
|
|
312
363
|
const supportedReason = (record?.source === 'hub'
|
|
313
364
|
&& (record.reason === 'unverified_hub_rewrite' || record.reason === 'unverified_hub_synthesized')) || (record?.source === 'migrated' && record.reason === 'unverified_gepx_import');
|
|
314
365
|
const isActiveWaiver = supportedReason
|
|
@@ -317,14 +368,14 @@ function isUnsafeUnverifiedLocalAsset(asset, store, deps) {
|
|
|
317
368
|
&& record.decidedBy === undefined
|
|
318
369
|
&& record.promotedBy === undefined
|
|
319
370
|
&& record.frozenContentId === wire.computeAssetId(asset);
|
|
320
|
-
return
|
|
371
|
+
return isActiveWaiver ? 'reusable' : 'refetch';
|
|
321
372
|
}
|
|
322
373
|
function stringField(record, key) {
|
|
323
374
|
const value = record[key];
|
|
324
375
|
return typeof value === 'string' && value.length > 0 ? value : undefined;
|
|
325
376
|
}
|
|
326
377
|
function isContentAssetId(value) {
|
|
327
|
-
return
|
|
378
|
+
return /^sha256:[0-9a-f]{64}$/.test(value);
|
|
328
379
|
}
|
|
329
380
|
function logReuse(deps, opts, asset, source) {
|
|
330
381
|
// AssetCallLog.append is best-effort (never throws) — a logging failure must not break the reuse write.
|
|
@@ -373,6 +424,9 @@ function hubErrorField(body) {
|
|
|
373
424
|
function recordValue(value) {
|
|
374
425
|
return value && typeof value === 'object' && !Array.isArray(value) ? value : {};
|
|
375
426
|
}
|
|
427
|
+
function optionalRecord(value) {
|
|
428
|
+
return value && typeof value === 'object' && !Array.isArray(value) ? value : undefined;
|
|
429
|
+
}
|
|
376
430
|
function mapError(e) {
|
|
377
431
|
if (e instanceof ReuseIntegrityError) {
|
|
378
432
|
return { ok: false, status: 'integrity_failed', message: e.message };
|
|
@@ -414,15 +468,18 @@ function mapError(e) {
|
|
|
414
468
|
return { ok: false, status: 'unavailable', message: 'private Hub proxy is not configured' };
|
|
415
469
|
}
|
|
416
470
|
if (/Hub URL|EVOMAP_HUB_URL|A2A_HUB_URL/i.test(msg)) {
|
|
417
|
-
return { ok: false, status: 'unavailable', message:
|
|
471
|
+
return { ok: false, status: 'unavailable', message: 'hub URL configuration is invalid' };
|
|
418
472
|
}
|
|
419
473
|
if (/Hub credentials|node identity|evolver login|EVOMAP_NODE_SECRET/i.test(msg)) {
|
|
420
|
-
return { ok: false, status: 'unauthorized', message:
|
|
474
|
+
return { ok: false, status: 'unauthorized', message: 'hub authentication failed; run `evolver login` or set EVOMAP_NODE_SECRET' };
|
|
421
475
|
}
|
|
422
476
|
if (/\b(?:hub|http)\s*5\d\d\b/i.test(msg) || /\b(network|fetch failed|ECONN[A-Z_]*|ENOTFOUND|ETIMEDOUT)\b/i.test(msg)) {
|
|
423
477
|
return { ok: false, status: 'network', message: 'hub is unreachable' };
|
|
424
478
|
}
|
|
425
|
-
|
|
479
|
+
if (msg === 'local asset id conflict') {
|
|
480
|
+
return { ok: false, status: 'internal_error', message: 'local asset id conflict' };
|
|
481
|
+
}
|
|
482
|
+
return { ok: false, status: 'internal_error', message: 'reuse operation failed' };
|
|
426
483
|
}
|
|
427
484
|
function emit(outcome, ctx) {
|
|
428
485
|
if (ctx.jsonOut) {
|
|
@@ -438,15 +495,6 @@ function emit(outcome, ctx) {
|
|
|
438
495
|
}
|
|
439
496
|
return outcome.ok ? 0 : 1;
|
|
440
497
|
}
|
|
441
|
-
/** Defensive redaction so a stray credential in an error string never reaches stdout/stderr. */
|
|
442
|
-
function redact(value) {
|
|
443
|
-
return value
|
|
444
|
-
.replace(/\bBearer\s+[A-Za-z0-9._~+/=-]+/gi, 'Bearer [redacted]')
|
|
445
|
-
.replace(/\b([A-Z][A-Z0-9_]*(?:_SECRET|_TOKEN))\b\s*[:=]\s*["']?[^"',\s;}]+/g, '$1=[redacted]')
|
|
446
|
-
.replace(/\b(authorization|node_secret|nodeSecret|access_token|refresh_token|token|secret)\b\s*[:=]\s*["']?[^"',\s;}]+/gi, '$1=[redacted]')
|
|
447
|
-
.replace(/\bsk-[A-Za-z0-9-]{16,}/g, 'sk-[redacted]')
|
|
448
|
-
.replace(/\bgh[pousr]_[A-Za-z0-9]{20,}/g, 'gh_[redacted]');
|
|
449
|
-
}
|
|
450
498
|
function flagValue(args, flag) {
|
|
451
499
|
for (let i = 0; i < args.length; i += 1) {
|
|
452
500
|
const token = args[i];
|
package/dist/sync.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export interface SyncAccountAssetLister {
|
|
|
5
5
|
listAccountAssets(opts: AccountAssetListOptions): Promise<AccountAssetListResult>;
|
|
6
6
|
}
|
|
7
7
|
export interface SyncAccountAssetHub extends SyncAccountAssetLister {
|
|
8
|
-
fetchAssetById(assetId: string): Promise<assetstore.AssetRecord | null>;
|
|
8
|
+
fetchAssetById(assetId: string, options?: hubNs.FetchAssetByIdOptions): Promise<assetstore.AssetRecord | null>;
|
|
9
9
|
}
|
|
10
10
|
export interface SyncCliDeps {
|
|
11
11
|
hub?: SyncAccountAssetLister | SyncAccountAssetHub;
|