@evomap/evolver-cli 2.0.2 → 2.0.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.
- package/dist/assetRepair.d.ts +24 -0
- package/dist/assetRepair.js +164 -0
- package/dist/autoDistillLlm.d.ts +20 -0
- package/dist/autoDistillLlm.js +56 -2
- package/dist/cliContracts.d.ts +5 -0
- package/dist/cliContracts.js +263 -52
- package/dist/dispatch.js +2 -0
- 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/repairedAssetStore.d.ts +2 -0
- package/dist/repairedAssetStore.js +12 -0
- package/dist/reuse.d.ts +4 -1
- package/dist/reuse.js +212 -107
- package/dist/sync.d.ts +1 -1
- package/dist/sync.js +761 -174
- package/dist/workflowRuntime.js +5 -4
- package/package.json +7 -7
package/dist/cliContracts.js
CHANGED
|
@@ -1,18 +1,24 @@
|
|
|
1
1
|
import { existsSync, readFileSync, statSync } from 'node:fs';
|
|
2
|
-
import {
|
|
2
|
+
import { resolve } from 'node:path';
|
|
3
3
|
import { inspect, format } from 'node:util';
|
|
4
|
-
import { assetstore, events, hub, wire, algo, verify } from '@evomap/evolver-core';
|
|
4
|
+
import { assetrepair, assetstore, events, hub, wire, algo, verify } from '@evomap/evolver-core';
|
|
5
5
|
import { AuthError, HubClientError, HubFetch, HubUnreachableError, connectPublicHub, gepEnvelope, globalFetchLike, resolveHubUrl, } from '@evomap/evolver-adapter-public';
|
|
6
6
|
import { loadEnvFileFromEnv, proxyClientFromEnv } from '@evomap/evolver-mcp';
|
|
7
7
|
import { resolveAtpSenderId } from './atp.js';
|
|
8
|
+
import { storeRepairedAsset } from './repairedAssetStore.js';
|
|
8
9
|
import { resolveExplicitNodeCredentials, resolveIdentityHome } from './identityHome.js';
|
|
9
10
|
const REUSE_CONTRACT = 'reuse.v1';
|
|
10
11
|
const PUBLISH_CONTRACT = 'publish.v1';
|
|
11
12
|
const REVERSIBILITY = 'irreversible';
|
|
13
|
+
const OAUTH_AUTH_REQUIRED_MESSAGE = "Hub authentication required; run 'evolver login' and retry";
|
|
14
|
+
const LEGACY_AUTH_REQUIRED_MESSAGE = 'Hub node authentication failed; verify the configured node credentials and retry';
|
|
15
|
+
const PRIVATE_AUTH_REQUIRED_MESSAGE = 'Private Hub authentication failed; verify proxy enrollment, credentials, and hub mode';
|
|
16
|
+
const BUNDLE_REQUIRED_MESSAGE = 'publish requires Gene + Capsule bundle; pass --gene <id|path> --capsule <id|path>';
|
|
12
17
|
const MAX_ASSETS = 50;
|
|
13
18
|
const PUBLISH_USAGE = [
|
|
14
|
-
'usage: evolver publish --asset <gene_id_or_path> --asset <capsule_id_or_path> --json [--dry-run]',
|
|
19
|
+
'usage: evolver publish --asset <gene_id_or_path> --asset <capsule_id_or_path> --json [--dry-run] [--repair]',
|
|
15
20
|
' evolver publish --gene <id_or_path> --capsule <id_or_path> --json [--dry-run]',
|
|
21
|
+
' evolver publish --gene <id_or_path> --auto-pair --json [--dry-run]',
|
|
16
22
|
].join('\n');
|
|
17
23
|
const ASSET_FLAGS = new Set(['--asset', '--gene', '--capsule', '--event']);
|
|
18
24
|
const STABLE_CONTRACT_REASONS = new Set([
|
|
@@ -140,7 +146,7 @@ export async function runPublishCommand(args, deps = {}) {
|
|
|
140
146
|
runtimeDeps = { ...deps, env: preserveInheritedSecrets(runtimeEnv, inheritedEnv) };
|
|
141
147
|
}
|
|
142
148
|
catch (err) {
|
|
143
|
-
const failure = classifyError(err, 'publish');
|
|
149
|
+
const failure = classifyError(err, 'publish', deps.env ?? process.env);
|
|
144
150
|
return writeJson(out, publishFailure(failure.reason, failure.message, {
|
|
145
151
|
retryable: failure.retryable,
|
|
146
152
|
mode: parsed.dryRun ? 'dry_run' : 'publish',
|
|
@@ -149,7 +155,10 @@ export async function runPublishCommand(args, deps = {}) {
|
|
|
149
155
|
const write = (value, code) => writeJson(out, value, code, runtimeDeps);
|
|
150
156
|
return withMachineJsonConsole(Boolean(parsed.jsonOut), runtimeDeps, async () => {
|
|
151
157
|
try {
|
|
152
|
-
const
|
|
158
|
+
const effectiveRefs = parsed.autoPair
|
|
159
|
+
? await autoPairPublishRefs(assetRefs, parsed.geneRef, runtimeDeps)
|
|
160
|
+
: assetRefs;
|
|
161
|
+
const bundle = await buildPublishBundle(effectiveRefs, runtimeDeps);
|
|
153
162
|
if (!bundle.ok) {
|
|
154
163
|
return write(publishFailure(bundle.reason, bundle.message, { retryable: false, gates: bundle.gates }), 1);
|
|
155
164
|
}
|
|
@@ -167,7 +176,12 @@ export async function runPublishCommand(args, deps = {}) {
|
|
|
167
176
|
}
|
|
168
177
|
const transport = deps.transport ?? createDefaultTransport(runtimeDeps);
|
|
169
178
|
const validate = deps.validate ?? transport.validate;
|
|
170
|
-
|
|
179
|
+
// A field-level refusal is a defect in the RECORD, not a verdict on the work in it. Read the Hub's own
|
|
180
|
+
// `details[]`, mend what is mechanically derivable, and (only when asked) try once more — otherwise the
|
|
181
|
+
// envelope still carries the plan, so the operator can see the asset is salvageable instead of losing it.
|
|
182
|
+
const validationAttempt = await callHubWithRepair(validate, bundle.sanitized, parsed.repair === true);
|
|
183
|
+
const validation = validationAttempt.result;
|
|
184
|
+
let effectiveAssets = validationAttempt.assets;
|
|
171
185
|
const validationCredits = extractCredits(validation.body);
|
|
172
186
|
const validationUnavailable = transport.validationCapabilityOptional === true
|
|
173
187
|
&& isValidationCapabilityUnavailable(validation.body);
|
|
@@ -189,32 +203,42 @@ export async function runPublishCommand(args, deps = {}) {
|
|
|
189
203
|
bundle.blockReasons.push('quality_gate_failed');
|
|
190
204
|
return write(dryRunEnvelope(bundle, validationCredits, detail), 0);
|
|
191
205
|
}
|
|
192
|
-
return write(publishFailure(reason, publishReasonMessage(reason), {
|
|
206
|
+
return write(publishFailure(reason, publishReasonMessage(reason, runtimeDeps.env), {
|
|
193
207
|
retryable: publishRetryable(reason),
|
|
194
208
|
mode: parsed.dryRun ? 'dry_run' : 'publish',
|
|
195
209
|
gates: parsed.dryRun ? bundle.gates : { ...bundle.gates, quality: 'fail' },
|
|
196
210
|
assets: bundle.assets,
|
|
197
211
|
...(detail ? { detail } : {}),
|
|
198
212
|
...(validationCredits ? { credits: validationCredits } : {}),
|
|
213
|
+
...repairEnvelopeField(validationAttempt),
|
|
199
214
|
}), 1);
|
|
200
215
|
}
|
|
201
216
|
if (parsed.dryRun)
|
|
202
|
-
return write(dryRunEnvelope(bundle, validationCredits), 0);
|
|
217
|
+
return write(dryRunEnvelope(bundle, validationCredits, undefined, validationAttempt), 0);
|
|
203
218
|
const publish = deps.publish ?? transport.publish;
|
|
204
|
-
const
|
|
219
|
+
const publishAttempt = await callHubWithRepair(publish, effectiveAssets, parsed.repair === true);
|
|
220
|
+
const published = publishAttempt.result;
|
|
221
|
+
effectiveAssets = publishAttempt.assets;
|
|
222
|
+
const repairApplied = mergeRepairAttempts(validationAttempt, publishAttempt);
|
|
205
223
|
const publishCredits = extractCredits(published.body);
|
|
206
224
|
if (!published.ok) {
|
|
207
225
|
const reason = publishReasonFromResponse(published.status, published.body);
|
|
208
226
|
const detail = hubDetailFromBody(published.body);
|
|
209
|
-
return write(publishFailure(reason, publishReasonMessage(reason), {
|
|
227
|
+
return write(publishFailure(reason, publishReasonMessage(reason, runtimeDeps.env), {
|
|
210
228
|
retryable: publishRetryable(reason),
|
|
211
229
|
mode: 'publish',
|
|
212
230
|
gates: bundle.gates,
|
|
213
231
|
assets: bundle.assets,
|
|
214
232
|
...(detail ? { detail } : {}),
|
|
215
233
|
...(publishCredits ? { credits: publishCredits } : {}),
|
|
234
|
+
...repairEnvelopeField(repairApplied),
|
|
216
235
|
}), 1);
|
|
217
236
|
}
|
|
237
|
+
// The repaired records are what the network now holds. Persist them so the local library and the Hub do
|
|
238
|
+
// not silently diverge; a storage failure is reported, never fatal — the publish already happened.
|
|
239
|
+
const repairPersisted = repairApplied?.applied === true
|
|
240
|
+
? await persistRepairedBundle(effectiveAssets, bundle.sanitized, runtimeDeps)
|
|
241
|
+
: undefined;
|
|
218
242
|
const payload = payloadRecord(published.body);
|
|
219
243
|
const decision = stringField(payload, 'decision');
|
|
220
244
|
const hubReason = stringField(payload, 'reason');
|
|
@@ -242,7 +266,8 @@ export async function runPublishCommand(args, deps = {}) {
|
|
|
242
266
|
}
|
|
243
267
|
const receiptId = stringField(payload, 'receipt_id');
|
|
244
268
|
const bundleId = stringField(payload, 'bundle_id');
|
|
245
|
-
|
|
269
|
+
const publishedBundle = { ...bundle, sanitized: [...effectiveAssets] };
|
|
270
|
+
appendPublishedCapsuleCall(publishedBundle, deps, { status, receiptId, bundleId });
|
|
246
271
|
return write({
|
|
247
272
|
ok: true,
|
|
248
273
|
contract: PUBLISH_CONTRACT,
|
|
@@ -252,12 +277,14 @@ export async function runPublishCommand(args, deps = {}) {
|
|
|
252
277
|
...(receiptId ? { receipt_id: receiptId } : {}),
|
|
253
278
|
...(bundleId ? { bundle_id: bundleId } : {}),
|
|
254
279
|
...(safetyCandidate ? { hub_reason: hubReason } : {}),
|
|
255
|
-
|
|
280
|
+
// What the Hub actually holds — after a repair that is the mended record, not the one first submitted.
|
|
281
|
+
assets: repairApplied?.applied === true ? summarizePublishAssets(effectiveAssets) : bundle.assets,
|
|
256
282
|
...(publishCredits ? { credits: publishCredits } : {}),
|
|
283
|
+
...repairEnvelopeField(repairApplied, repairPersisted),
|
|
257
284
|
}, 0);
|
|
258
285
|
}
|
|
259
286
|
catch (err) {
|
|
260
|
-
const failure = classifyError(err, 'publish');
|
|
287
|
+
const failure = classifyError(err, 'publish', runtimeDeps.env ?? process.env);
|
|
261
288
|
return write(publishFailure(failure.reason, failure.message, {
|
|
262
289
|
retryable: failure.retryable,
|
|
263
290
|
mode: parsed.dryRun ? 'dry_run' : 'publish',
|
|
@@ -265,6 +292,76 @@ export async function runPublishCommand(args, deps = {}) {
|
|
|
265
292
|
}
|
|
266
293
|
});
|
|
267
294
|
}
|
|
295
|
+
async function callHubWithRepair(call, assets, allowRepair) {
|
|
296
|
+
const first = await call(assets);
|
|
297
|
+
if (first.ok)
|
|
298
|
+
return { result: first, assets, applied: false, entries: [] };
|
|
299
|
+
const plan = planBundleRepair(assets, first.body);
|
|
300
|
+
// Retry only when the WHOLE bundle is mended. One unrepairable asset means the Hub will refuse the bundle
|
|
301
|
+
// again for the same reason, and a second refusal costs the operator another paid round-trip for nothing.
|
|
302
|
+
const repairable = plan.entries.some((entry) => entry.repair_status === 'repaired')
|
|
303
|
+
&& plan.entries.every((entry) => entry.repair_status !== 'unrepairable');
|
|
304
|
+
if (!repairable || !allowRepair)
|
|
305
|
+
return { result: first, assets, applied: false, entries: plan.entries };
|
|
306
|
+
// Exactly one retry: a Hub that refuses the mended record too is telling us the defect is not mechanical,
|
|
307
|
+
// and a repair loop against a paid endpoint is how you burn credits without converging.
|
|
308
|
+
const retried = await call(plan.assets);
|
|
309
|
+
return { result: retried, assets: plan.assets, applied: true, entries: plan.entries };
|
|
310
|
+
}
|
|
311
|
+
function planBundleRepair(assets, rejectionBody) {
|
|
312
|
+
const hubIssues = assetrepair.hubRejectionIssues(rejectionBody);
|
|
313
|
+
const bundleIssues = hubIssues.byAssetIndex.get(-1) ?? [];
|
|
314
|
+
const repaired = [];
|
|
315
|
+
const entries = [];
|
|
316
|
+
for (const [index, asset] of assets.entries()) {
|
|
317
|
+
const issues = [...(hubIssues.byAssetIndex.get(index) ?? []), ...bundleIssues];
|
|
318
|
+
const report = assetrepair.repairAssetRecord(asset, { hubIssues: issues });
|
|
319
|
+
repaired.push(report.asset ?? asset);
|
|
320
|
+
entries.push({
|
|
321
|
+
...(asset.asset_id ? { asset_id: asset.asset_id } : {}),
|
|
322
|
+
...(report.asset && report.asset.asset_id !== asset.asset_id ? { repaired_asset_id: report.asset.asset_id } : {}),
|
|
323
|
+
repair_status: report.status,
|
|
324
|
+
changes: report.changes.map((change) => `${change.path}: ${change.action}`),
|
|
325
|
+
blockers: report.blockers.map(repairBlockerText),
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
return { assets: repaired, entries };
|
|
329
|
+
}
|
|
330
|
+
function repairBlockerText(blocker) {
|
|
331
|
+
return `${blocker.path || '(record)'}: ${stripControlChars(blocker.message).replace(/\s+/g, ' ').trim()}`.slice(0, HUB_DETAIL_MAX_CHARS);
|
|
332
|
+
}
|
|
333
|
+
/** Report the LATER attempt's plan: it is the one describing the bundle that was actually refused last. */
|
|
334
|
+
function mergeRepairAttempts(validation, publish) {
|
|
335
|
+
if (publish.applied || publish.entries.length > 0) {
|
|
336
|
+
return { ...publish, applied: publish.applied || validation.applied };
|
|
337
|
+
}
|
|
338
|
+
return validation.entries.length > 0 || validation.applied ? validation : undefined;
|
|
339
|
+
}
|
|
340
|
+
function repairEnvelopeField(attempt, persisted) {
|
|
341
|
+
if (!attempt || (attempt.entries.length === 0 && !attempt.applied))
|
|
342
|
+
return {};
|
|
343
|
+
return {
|
|
344
|
+
repair: {
|
|
345
|
+
applied: attempt.applied,
|
|
346
|
+
...(persisted !== undefined ? { persisted } : {}),
|
|
347
|
+
...(attempt.applied ? {} : { hint: 're-run with --repair to publish the mended record' }),
|
|
348
|
+
assets: attempt.entries,
|
|
349
|
+
},
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
async function persistRepairedBundle(published, submitted, deps) {
|
|
353
|
+
const env = deps.env ?? process.env;
|
|
354
|
+
const store = deps.assetStore ?? new assetstore.LocalJsonlProvider(contractAssetsDir(deps));
|
|
355
|
+
// Only the records repair actually changed are new locally; the untouched ones are already stored.
|
|
356
|
+
const changed = published.filter((asset, index) => asset.asset_id !== submitted[index]?.asset_id);
|
|
357
|
+
try {
|
|
358
|
+
const stored = await Promise.all(changed.map((asset) => storeRepairedAsset(asset, store, env)));
|
|
359
|
+
return stored.every(Boolean);
|
|
360
|
+
}
|
|
361
|
+
catch {
|
|
362
|
+
return false;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
268
365
|
function appendPublishedCapsuleCall(bundle, deps, receipt) {
|
|
269
366
|
const capsuleIndex = bundle.sanitized.findIndex((asset) => asset.type === 'Capsule');
|
|
270
367
|
if (capsuleIndex < 0)
|
|
@@ -329,7 +426,13 @@ export function parseReuseArgs(args) {
|
|
|
329
426
|
}
|
|
330
427
|
export function parsePublishArgs(args) {
|
|
331
428
|
const assetRefs = [];
|
|
429
|
+
let geneRef;
|
|
430
|
+
let geneCount = 0;
|
|
431
|
+
let capsuleRef;
|
|
432
|
+
let hasUntypedAsset = false;
|
|
433
|
+
let autoPair = false;
|
|
332
434
|
let dryRun = false;
|
|
435
|
+
let repair = false;
|
|
333
436
|
let jsonOut = false;
|
|
334
437
|
for (let i = 0; i < args.length; i++) {
|
|
335
438
|
const token = args[i];
|
|
@@ -343,34 +446,67 @@ export function parsePublishArgs(args) {
|
|
|
343
446
|
jsonOut = true;
|
|
344
447
|
continue;
|
|
345
448
|
}
|
|
449
|
+
if (token === '--auto-pair') {
|
|
450
|
+
autoPair = true;
|
|
451
|
+
continue;
|
|
452
|
+
}
|
|
453
|
+
if (token === '--repair') {
|
|
454
|
+
repair = true;
|
|
455
|
+
continue;
|
|
456
|
+
}
|
|
346
457
|
const equalFlag = [...ASSET_FLAGS].find((flag) => token.startsWith(`${flag}=`));
|
|
347
458
|
if (equalFlag) {
|
|
348
459
|
const value = token.slice(equalFlag.length + 1).trim();
|
|
349
460
|
if (!value)
|
|
350
461
|
return { ok: false, reason: 'bundle_required', message: `${equalFlag} requires a value` };
|
|
351
462
|
assetRefs.push(value);
|
|
463
|
+
if (equalFlag === '--gene') {
|
|
464
|
+
geneRef = value;
|
|
465
|
+
geneCount++;
|
|
466
|
+
}
|
|
467
|
+
if (equalFlag === '--capsule')
|
|
468
|
+
capsuleRef = value;
|
|
469
|
+
if (equalFlag === '--asset')
|
|
470
|
+
hasUntypedAsset = true;
|
|
352
471
|
continue;
|
|
353
472
|
}
|
|
354
473
|
if (ASSET_FLAGS.has(token)) {
|
|
355
474
|
const next = args[i + 1];
|
|
356
475
|
if (!next || next.startsWith('--'))
|
|
357
476
|
return { ok: false, reason: 'bundle_required', message: `${token} requires a value` };
|
|
358
|
-
|
|
477
|
+
const value = next.trim();
|
|
478
|
+
if (!value)
|
|
479
|
+
return { ok: false, reason: 'bundle_required', message: `${token} requires a value` };
|
|
480
|
+
assetRefs.push(value);
|
|
481
|
+
if (token === '--gene') {
|
|
482
|
+
geneRef = value;
|
|
483
|
+
geneCount++;
|
|
484
|
+
}
|
|
485
|
+
if (token === '--capsule')
|
|
486
|
+
capsuleRef = value;
|
|
487
|
+
if (token === '--asset')
|
|
488
|
+
hasUntypedAsset = true;
|
|
359
489
|
i++;
|
|
360
490
|
continue;
|
|
361
491
|
}
|
|
362
492
|
if (!token.startsWith('--'))
|
|
363
|
-
return { ok: false, reason: 'unsupported', message: 'unsupported publish argument' };
|
|
364
|
-
|
|
493
|
+
return { ok: false, reason: 'unsupported', message: 'unsupported publish argument; did you mean --asset <id|path>?' };
|
|
494
|
+
if (token === '--home' || token.startsWith('--home=') || token === '--evomap-home' || token.startsWith('--evomap-home=')) {
|
|
495
|
+
return { ok: false, reason: 'unsupported', message: 'publish does not accept home flags; set EVOLVER_HOME or EVOMAP_HOME before running evolver publish' };
|
|
496
|
+
}
|
|
497
|
+
return { ok: false, reason: 'unsupported', message: "unsupported publish flag; run 'evolver publish --help'" };
|
|
365
498
|
}
|
|
366
499
|
if (!jsonOut)
|
|
367
500
|
return { ok: false, reason: 'unsupported', message: 'publish requires --json' };
|
|
368
|
-
|
|
501
|
+
if (autoPair && (geneCount !== 1 || !geneRef || capsuleRef || hasUntypedAsset)) {
|
|
502
|
+
return { ok: false, reason: 'bundle_required', message: '--auto-pair requires exactly one explicit --gene and no --asset or --capsule' };
|
|
503
|
+
}
|
|
504
|
+
const refs = assetRefs;
|
|
369
505
|
if (refs.length === 0)
|
|
370
506
|
return { ok: false, reason: 'bundle_required', message: 'publish requires --asset <id|path>' };
|
|
371
507
|
if (refs.length > MAX_ASSETS)
|
|
372
508
|
return { ok: false, reason: 'bundle_required', message: `publish supports at most ${MAX_ASSETS} assets` };
|
|
373
|
-
return { ok: true, assetRefs: refs, dryRun, jsonOut };
|
|
509
|
+
return { ok: true, assetRefs: refs, ...(geneRef ? { geneRef } : {}), ...(autoPair ? { autoPair: true } : {}), dryRun, repair, jsonOut };
|
|
374
510
|
}
|
|
375
511
|
export async function buildPublishBundle(refs, deps = {}) {
|
|
376
512
|
let original;
|
|
@@ -578,7 +714,8 @@ function withRecomputedAssetId(asset) {
|
|
|
578
714
|
const assetId = wire.computeAssetId(asset);
|
|
579
715
|
return { ...asset, asset_id: assetId ?? asset.asset_id };
|
|
580
716
|
}
|
|
581
|
-
|
|
717
|
+
/** Resolve `<asset_id|logical_id|path>` the way publish does. Shared so `asset-repair` speaks the same refs. */
|
|
718
|
+
export async function loadAssetRef(ref, deps) {
|
|
582
719
|
if (looksLikeFile(ref)) {
|
|
583
720
|
try {
|
|
584
721
|
return normalizeAsset(JSON.parse(readFileSync(resolve(ref), 'utf8')));
|
|
@@ -596,37 +733,96 @@ async function loadAssetRef(ref, deps) {
|
|
|
596
733
|
const fromStore = await findAssetInStore(ref, store);
|
|
597
734
|
// `not_found`, not `schema_invalid`: nothing was located, so no schema was
|
|
598
735
|
// ever read. `reuse` already reports this ref-resolution failure that way.
|
|
599
|
-
if (!fromStore)
|
|
600
|
-
|
|
601
|
-
throw new ContractError('not_found', `asset file not found: ${ref}`);
|
|
602
|
-
throw new ContractError('not_found', `asset not found: ${ref}`);
|
|
603
|
-
}
|
|
736
|
+
if (!fromStore)
|
|
737
|
+
throw new ContractError('not_found', 'asset not found');
|
|
604
738
|
return normalizeAsset(fromStore);
|
|
605
739
|
}
|
|
606
740
|
const assetsDir = contractAssetsDir(deps);
|
|
607
741
|
const readOnly = loadLocalAssetsReadOnly(assetsDir, ref);
|
|
608
|
-
const
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
742
|
+
const byAssetId = readOnly.filter((asset) => asset.asset_id === ref);
|
|
743
|
+
if (byAssetId.length > 1)
|
|
744
|
+
throw new ContractError('not_found', 'asset reference is ambiguous');
|
|
745
|
+
let found = byAssetId[0];
|
|
612
746
|
if (!found) {
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
747
|
+
const exactLogical = readOnly.filter((asset) => stringField(asset, 'id') === ref);
|
|
748
|
+
if (exactLogical.length > 1)
|
|
749
|
+
throw new ContractError('not_found', 'asset reference is ambiguous');
|
|
750
|
+
found = exactLogical[0];
|
|
751
|
+
}
|
|
752
|
+
if (!found) {
|
|
753
|
+
const fallback = prefixedLogicalRef(ref);
|
|
754
|
+
if (fallback) {
|
|
755
|
+
const matches = readOnly.filter((asset) => asset.type === fallback.kind && stringField(asset, 'id') === fallback.id);
|
|
756
|
+
if (matches.length > 1)
|
|
757
|
+
throw new ContractError('not_found', 'asset reference is ambiguous');
|
|
758
|
+
found = matches[0];
|
|
759
|
+
}
|
|
616
760
|
}
|
|
761
|
+
if (!found)
|
|
762
|
+
throw new ContractError('not_found', 'asset not found');
|
|
617
763
|
return normalizeAsset(found);
|
|
618
764
|
}
|
|
765
|
+
function prefixedLogicalRef(ref) {
|
|
766
|
+
const match = /^(gene|capsule):(.+)$/.exec(ref);
|
|
767
|
+
if (!match?.[2])
|
|
768
|
+
return null;
|
|
769
|
+
return { kind: match[1] === 'gene' ? 'Gene' : 'Capsule', id: match[2] };
|
|
770
|
+
}
|
|
771
|
+
async function findLogicalAsset(store, id, kind) {
|
|
772
|
+
if (store.findByLogicalId) {
|
|
773
|
+
const matches = await store.findByLogicalId(id, 2, kind);
|
|
774
|
+
if (matches.length > 1)
|
|
775
|
+
throw new ContractError('not_found', 'asset reference is ambiguous');
|
|
776
|
+
return matches[0] ?? null;
|
|
777
|
+
}
|
|
778
|
+
const scanLimit = 10_000;
|
|
779
|
+
const rows = await store.list(kind, scanLimit + 1);
|
|
780
|
+
if (rows.length > scanLimit)
|
|
781
|
+
throw new ContractError('not_found', 'asset lookup is truncated; use an exact asset_id');
|
|
782
|
+
const matches = rows.filter((asset) => stringField(asset, 'id') === id);
|
|
783
|
+
if (matches.length > 1)
|
|
784
|
+
throw new ContractError('not_found', 'asset reference is ambiguous');
|
|
785
|
+
return matches[0] ?? null;
|
|
786
|
+
}
|
|
619
787
|
async function findAssetInStore(ref, store) {
|
|
620
788
|
const byAssetId = await store.get(ref);
|
|
621
789
|
if (byAssetId)
|
|
622
790
|
return byAssetId;
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
791
|
+
const exact = await findLogicalAsset(store, ref);
|
|
792
|
+
if (exact)
|
|
793
|
+
return exact;
|
|
794
|
+
const fallback = prefixedLogicalRef(ref);
|
|
795
|
+
return fallback ? findLogicalAsset(store, fallback.id, fallback.kind) : null;
|
|
796
|
+
}
|
|
797
|
+
async function autoPairPublishRefs(refs, geneRef, deps) {
|
|
798
|
+
const store = deps.assetStore ?? new assetstore.LocalJsonlProvider(contractAssetsDir(deps));
|
|
799
|
+
if (!(store instanceof assetstore.LocalJsonlProvider)) {
|
|
800
|
+
throw new ContractError('bundle_required', '--auto-pair requires a local asset store; pass --capsule <id|path> explicitly');
|
|
628
801
|
}
|
|
629
|
-
|
|
802
|
+
const gene = await loadAssetRef(geneRef, { ...deps, assetStore: store });
|
|
803
|
+
if (gene.type !== 'Gene')
|
|
804
|
+
throw new ContractError('bundle_required', '--auto-pair requires a Gene reference');
|
|
805
|
+
const geneIds = new Set([gene.asset_id, stringField(gene, 'id')].filter((id) => Boolean(id)));
|
|
806
|
+
const trust = new assetstore.ProvenanceStore(store.baseDir).snapshot();
|
|
807
|
+
const candidates = store.listAll('Capsule').filter((candidate) => {
|
|
808
|
+
if (!geneIds.has(String(candidate['gene'] ?? '')))
|
|
809
|
+
return false;
|
|
810
|
+
const outcome = asRecord(candidate['outcome']);
|
|
811
|
+
if (outcome?.['status'] !== 'success')
|
|
812
|
+
return false;
|
|
813
|
+
if (trust.get(candidate.asset_id)?.trusted === false)
|
|
814
|
+
return false;
|
|
815
|
+
if (!wire.validateWireDeep(candidate).ok)
|
|
816
|
+
return false;
|
|
817
|
+
return wire.verifyAssetId(candidate);
|
|
818
|
+
});
|
|
819
|
+
if (candidates.length === 0) {
|
|
820
|
+
throw new ContractError('bundle_required', 'no eligible successful Capsule found; pass --capsule <id|path> explicitly');
|
|
821
|
+
}
|
|
822
|
+
if (candidates.length > 1) {
|
|
823
|
+
throw new ContractError('bundle_required', 'multiple eligible Capsules found; pass --capsule <id|path> explicitly');
|
|
824
|
+
}
|
|
825
|
+
return [...refs, candidates[0].asset_id];
|
|
630
826
|
}
|
|
631
827
|
function loadLocalAssetsReadOnly(baseDir, targetRef) {
|
|
632
828
|
return [
|
|
@@ -708,7 +904,7 @@ function checkBundle(bundle) {
|
|
|
708
904
|
return { ok: false, message: 'publish supports one Gene + one Capsule + optional one EvolutionEvent bundle' };
|
|
709
905
|
}
|
|
710
906
|
if (genes.length === 0 || capsules.length === 0)
|
|
711
|
-
return { ok: false, message:
|
|
907
|
+
return { ok: false, message: BUNDLE_REQUIRED_MESSAGE };
|
|
712
908
|
const gene = genes[0];
|
|
713
909
|
const capsule = capsules[0];
|
|
714
910
|
const geneIds = new Set([gene.asset_id, stringField(gene, 'id')].filter((id) => Boolean(id)));
|
|
@@ -752,7 +948,7 @@ function storeBaseDir(store, deps) {
|
|
|
752
948
|
function contractAssetsDir(deps) {
|
|
753
949
|
return deps.assetsDir ?? events.assetsDir(deps.env ?? process.env);
|
|
754
950
|
}
|
|
755
|
-
function dryRunEnvelope(bundle, credits, blockDetail) {
|
|
951
|
+
function dryRunEnvelope(bundle, credits, blockDetail, repairAttempt) {
|
|
756
952
|
const suppressPayload = bundle.blockReasons.includes('leak_detected');
|
|
757
953
|
// Collect detailed messages for block reasons
|
|
758
954
|
const blockDetails = [];
|
|
@@ -776,6 +972,7 @@ function dryRunEnvelope(bundle, credits, blockDetail) {
|
|
|
776
972
|
...(suppressPayload ? {} : { payload: { assets: bundle.sanitized } }),
|
|
777
973
|
gates: bundle.gates,
|
|
778
974
|
...(credits ? { credits } : {}),
|
|
975
|
+
...repairEnvelopeField(repairAttempt),
|
|
779
976
|
};
|
|
780
977
|
}
|
|
781
978
|
function publishFailure(reason, message, opts) {
|
|
@@ -787,6 +984,7 @@ function publishFailure(reason, message, opts) {
|
|
|
787
984
|
...(opts.assets ? { assets: opts.assets } : {}),
|
|
788
985
|
...(opts.detail ? { detail: opts.detail } : {}),
|
|
789
986
|
...(opts.credits ? { credits: opts.credits } : {}),
|
|
987
|
+
...(opts.repair ? { repair: opts.repair } : {}),
|
|
790
988
|
reason,
|
|
791
989
|
retryable: opts.retryable,
|
|
792
990
|
message,
|
|
@@ -1032,20 +1230,28 @@ function isAuthLikeError(err) {
|
|
|
1032
1230
|
const message = err instanceof Error ? err.message : String(err);
|
|
1033
1231
|
return /oauth|login|credential|auth|401|403|node_secret/i.test(message);
|
|
1034
1232
|
}
|
|
1035
|
-
function classifyError(err, command) {
|
|
1233
|
+
function classifyError(err, command, env = {}) {
|
|
1036
1234
|
if (err instanceof ContractError)
|
|
1037
1235
|
return { reason: err.reason, message: err.safeMessage, retryable: err.reason === 'network_error' };
|
|
1038
1236
|
if (err instanceof AuthError)
|
|
1039
|
-
return {
|
|
1237
|
+
return {
|
|
1238
|
+
reason: 'auth_required',
|
|
1239
|
+
message: command === 'publish' ? publishAuthRequiredMessage(env) : 'Hub authentication required',
|
|
1240
|
+
retryable: false,
|
|
1241
|
+
};
|
|
1040
1242
|
if (err instanceof HubUnreachableError)
|
|
1041
1243
|
return { reason: 'network_error', message: 'Hub unreachable', retryable: true };
|
|
1042
1244
|
if (err instanceof HubClientError) {
|
|
1043
1245
|
const reason = stableContractReasonFromBody(err.body) ?? (command === 'reuse' ? reuseReasonFromStatus(err.status) : publishReasonFromStatus(err.status));
|
|
1044
|
-
return { reason, message: command === 'publish' ? publishReasonMessage(reason) : reuseReasonMessage(reason), retryable: publishRetryable(reason) };
|
|
1246
|
+
return { reason, message: command === 'publish' ? publishReasonMessage(reason, env) : reuseReasonMessage(reason), retryable: publishRetryable(reason) };
|
|
1045
1247
|
}
|
|
1046
1248
|
const message = err instanceof Error ? err.message : String(err);
|
|
1047
1249
|
if (/oauth|login|credential|auth|401|403|node_secret/i.test(message))
|
|
1048
|
-
return {
|
|
1250
|
+
return {
|
|
1251
|
+
reason: 'auth_required',
|
|
1252
|
+
message: command === 'publish' ? publishAuthRequiredMessage(env) : 'Hub authentication required',
|
|
1253
|
+
retryable: false,
|
|
1254
|
+
};
|
|
1049
1255
|
if (/network|fetch failed|ECONN|ENOTFOUND|ETIMEDOUT|hub 5\d\d/i.test(message))
|
|
1050
1256
|
return { reason: 'network_error', message: 'Hub unreachable', retryable: true };
|
|
1051
1257
|
return { reason: 'internal_error', message: `evolver ${command} failed`, retryable: false };
|
|
@@ -1074,11 +1280,22 @@ function publishReasonFromResponse(status, body) {
|
|
|
1074
1280
|
function publishRetryable(reason) {
|
|
1075
1281
|
return reason === 'network_error';
|
|
1076
1282
|
}
|
|
1077
|
-
function
|
|
1283
|
+
function publishAuthRequiredMessage(env) {
|
|
1284
|
+
const rawMode = env['EVOMAP_HUB_MODE']?.trim().toLowerCase();
|
|
1285
|
+
if (rawMode && rawMode !== 'public' && rawMode !== 'private') {
|
|
1286
|
+
return 'Hub authentication failed; verify EVOMAP_HUB_MODE and the configured credentials';
|
|
1287
|
+
}
|
|
1288
|
+
if (rawMode === 'private')
|
|
1289
|
+
return PRIVATE_AUTH_REQUIRED_MESSAGE;
|
|
1290
|
+
return resolveExplicitNodeCredentials(env).nodeSecret
|
|
1291
|
+
? LEGACY_AUTH_REQUIRED_MESSAGE
|
|
1292
|
+
: OAUTH_AUTH_REQUIRED_MESSAGE;
|
|
1293
|
+
}
|
|
1294
|
+
function publishReasonMessage(reason, env = {}) {
|
|
1078
1295
|
const map = {
|
|
1079
1296
|
missing_id: 'missing asset id',
|
|
1080
1297
|
cli_unavailable: 'evolver CLI unavailable',
|
|
1081
|
-
auth_required:
|
|
1298
|
+
auth_required: publishAuthRequiredMessage(env),
|
|
1082
1299
|
not_found: 'asset not found',
|
|
1083
1300
|
network_error: 'Hub unreachable',
|
|
1084
1301
|
unsupported: 'publish unsupported',
|
|
@@ -1086,7 +1303,7 @@ function publishReasonMessage(reason) {
|
|
|
1086
1303
|
redaction_unavailable: 'redaction unavailable',
|
|
1087
1304
|
leak_detected: 'leak detected after redaction',
|
|
1088
1305
|
schema_invalid: 'asset schema is invalid',
|
|
1089
|
-
bundle_required:
|
|
1306
|
+
bundle_required: BUNDLE_REQUIRED_MESSAGE,
|
|
1090
1307
|
quality_gate_failed: 'Hub quality gate failed',
|
|
1091
1308
|
gene_unproven: 'gene has no proven success yet — run it to a successful outcome before publishing',
|
|
1092
1309
|
insufficient_credits: 'insufficient credits',
|
|
@@ -1260,12 +1477,6 @@ function looksLikeFile(value) {
|
|
|
1260
1477
|
return false;
|
|
1261
1478
|
}
|
|
1262
1479
|
}
|
|
1263
|
-
function looksLikeAssetPath(value) {
|
|
1264
|
-
return isAbsolute(value)
|
|
1265
|
-
|| /^[A-Za-z]:/.test(value)
|
|
1266
|
-
|| /[\\/]/.test(value)
|
|
1267
|
-
|| /\.jsonl?$/i.test(value);
|
|
1268
|
-
}
|
|
1269
1480
|
function isRecord(value) {
|
|
1270
1481
|
return Boolean(value && typeof value === 'object' && !Array.isArray(value));
|
|
1271
1482
|
}
|
package/dist/dispatch.js
CHANGED
|
@@ -32,6 +32,7 @@ import { runDashboardCommand } from './dashboard.js';
|
|
|
32
32
|
import { runIssueReportCommand } from './issueReport.js';
|
|
33
33
|
import { runAssetTrustCommand } from './assetTrust.js';
|
|
34
34
|
import { runAssetHealthCommand } from './assetHealth.js';
|
|
35
|
+
import { runAssetRepairCommand } from './assetRepair.js';
|
|
35
36
|
import { runV1FetchCompat, runV1RunCompat, runV1SolidifyCompat, runV1WebuiCompat, runV1ExecCompat } from './v1Compat.js';
|
|
36
37
|
import { runWorkflowCommand } from './workflow.js';
|
|
37
38
|
import { runMemoryGraphCommand } from './memoryGraphOps.js';
|
|
@@ -81,6 +82,7 @@ export const ASYNC_COMMANDS = {
|
|
|
81
82
|
'issue-report': runIssueReportCommand,
|
|
82
83
|
'asset-trust': runAssetTrustCommand,
|
|
83
84
|
'asset-health': runAssetHealthCommand,
|
|
85
|
+
'asset-repair': runAssetRepairCommand,
|
|
84
86
|
proxy: runProxyCommand,
|
|
85
87
|
run: runV1RunCompat,
|
|
86
88
|
solidify: runV1SolidifyCompat,
|