dsh-triage 0.1.0 → 0.2.0

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/cli.js CHANGED
@@ -16,13 +16,17 @@ import { createHash } from 'node:crypto';
16
16
  import { homedir, tmpdir } from 'node:os';
17
17
  import { join, resolve } from 'node:path';
18
18
  import process from 'node:process';
19
- import { catalogFor, compareInventory, evaluateAdmission, extractEntryClaims, extractPresetDeclarations, findEntryIdCollisions, findPresetDivergence, format, groupClaimsBySource, judgeVersionDrift, loadEnv, parseInventorySnapshot, parsePatchYaml, redactEnv, redactPath, redactVerdict, renderVerdict, rowTargets, verdictFromAdmission, verdictsFromCollisions, verdictsFromDuplicateCopies, verdictsFromInventory, verdictsFromRowAdmission, } from '@dsh-triage/core';
19
+ import { catalogFor, compareInventory, evaluateAdmission, extractEntryClaims, extractPresetDeclarations, findEntryIdCollisions, findPresetDivergence, format, groupClaimsBySource, hasNewDenials, judgeUpgradeImpact, judgeVersionDrift, loadEnv, parseInventorySnapshot, parsePatchYaml, redactEnv, redactPath, redactVerdict, registryFactFor, renderUpgradeImpact, renderVerdict, rowTargets, upgradeTargetProblem, verdictFromAdmission, verdictsFromCollisions, verdictsFromDuplicateCopies, verdictsFromInventory, verdictsFromRowAdmission, } from '@dsh-triage/core';
20
20
  import { buildProbePlan, executeProbe, findFreePort, judgeProbe, probeVerdict } from '@dsh-triage/probe';
21
21
  import { discoverLocalArtifacts, fetchPackument } from '@dsh-triage/signals';
22
22
  import { auditExitOutcome, auditJsonPayload, auditRedactRoots, loadAuditData, redactedEnv, redactedVerdicts, } from './audit-data.js';
23
23
  import { renderBadge, summarizeEvidence } from './badge.js';
24
24
  import { buildMarketIndex, entriesFromEvidence } from './index-source.js';
25
25
  import { findDuplicateCopies, loadComposition, resolveRows } from './load.js';
26
+ import { readOutcomeConfig, writeOutcomeMode } from './outcomes/config.js';
27
+ import { localPriorFor, renderPrior } from './outcomes/prior.js';
28
+ import { outcomeStatus, purgeOutcomes, renderPurge, renderStatus } from './outcomes/purge.js';
29
+ import { recordOutcomes } from './outcomes/store.js';
26
30
  import { candidatePackageName, normalizeCandidateSpec, probeScratchRoot, realDshHomeOf, realProbeDeps, sandboxBundles, } from './probe-run.js';
27
31
  import { startPanel } from './serve.js';
28
32
  const EXIT_OK = 0;
@@ -45,6 +49,8 @@ Usage
45
49
  dsh-triage serve open a read-only local evidence panel (127.0.0.1)
46
50
  dsh-triage badge <pkg[@version]> shields-style SVG rendered from recorded evidence
47
51
  dsh-triage index format-1 market index of versions measured "go" here
52
+ dsh-triage outcomes local outcome store: status / --enable / --disable / --purge
53
+ dsh-triage upgrade --to <version> which rows/bundles the target dsh would deny, and how to fix
48
54
  Flags
49
55
  --json machine-readable output
50
56
  --all include findings that are not blocking
@@ -55,6 +61,7 @@ Flags
55
61
  --no-redact keep absolute paths in --json output (default: redact to ~)
56
62
  --stamp <iso> fixed timestamp for reproducible output
57
63
  --snapshot <file> (audit) judge runtime phases from a pluginInventory snapshot
64
+ --snapshot <file> (upgrade) judge a frozen composition snapshot (schema_version 1)
58
65
  --explain (check) show the registry tag facts behind the verdict
59
66
  --execute (probe) really run the plan inside an isolated DSH_HOME
60
67
  --dsh-main <path> (probe --execute) DSH launcher entry the sandbox boots
@@ -68,6 +75,13 @@ Flags
68
75
  --out <file> (badge) write the SVG here instead of stdout
69
76
  --allow-execute (serve) enable actions; without it the panel is read-only
70
77
  --audit (serve) expose GET /api/audit (current composition, same engine as the CLI)
78
+ --outcomes <mode> (check, probe) record this verdict locally: off | local (per-run, not saved)
79
+ --enable (outcomes) opt in to the local outcome store
80
+ --disable (outcomes) opt out again; existing records are kept until --purge
81
+ --purge (outcomes) delete every record this tool stored, then the directory
82
+ --status (outcomes) how many records exist (default when no verb is given)
83
+ --to <version> (upgrade) target dsh version, exact semver (e.g. 0.3.0)
84
+ --registry (upgrade) annotate with published builds that declare the target (offline by default)
71
85
  --help this text
72
86
 
73
87
  Exit codes: 0 ok · 1 findings (audit always, others only with --strict) · 2 usage · 3 unavailable
@@ -99,6 +113,10 @@ async function run(argv) {
99
113
  return commandIndex(flags);
100
114
  case 'serve':
101
115
  return commandServe(flags);
116
+ case 'outcomes':
117
+ return commandOutcomes(flags);
118
+ case 'upgrade':
119
+ return commandUpgrade(flags);
102
120
  default:
103
121
  process.stderr.write(`unknown command "${command}"; see --help\n`);
104
122
  return EXIT_USAGE;
@@ -352,6 +370,271 @@ async function commandWhy(flags) {
352
370
  }
353
371
  return exitFor(flags, findings);
354
372
  }
373
+ /**
374
+ * `upgrade --to <version>`: which loader rows and bundles the **target** runtime would deny
375
+ * (`T-502`, `docs/specs/M5-upgrade.md`).
376
+ *
377
+ * Same engine, one runtime further: every unit is judged by `evaluateAdmission` with `env.dsh`
378
+ * replaced by the target, and the result is the verdict `why` would print on that runtime.
379
+ * Nothing here re-implements a range, and nothing here claims a boot was measured.
380
+ *
381
+ * NOT DONE ON PURPOSE: no profile edit, no automatic pin, no probe run, and no network unless
382
+ * `--registry` is passed (registry facts are annotations that cannot move a unit).
383
+ */
384
+ async function commandUpgrade(flags) {
385
+ if (flags.to === null) {
386
+ process.stderr.write('usage: dsh-triage upgrade --to <version> [--profile <name>] [--dsh-home <path>] [--snapshot <file>] [--registry] [--strict] [--json]\n');
387
+ return EXIT_USAGE;
388
+ }
389
+ // Validate BEFORE reading anything: a bad target must be a usage error whether or not the
390
+ // profile exists, and must never reach `satisfies()` (which returns false for garbage and
391
+ // would turn "bad flag" into "everything will break").
392
+ const problem = upgradeTargetProblem(flags.to);
393
+ if (problem !== null) {
394
+ process.stderr.write(`${problem}\n`);
395
+ return EXIT_USAGE;
396
+ }
397
+ const target = flags.to.trim();
398
+ const stamp = stampOf(flags);
399
+ const warnings = [];
400
+ let env;
401
+ let bundles;
402
+ let rows;
403
+ let profileSource;
404
+ if (flags.snapshot !== null) {
405
+ const snapshot = readCompositionSnapshot(flags.snapshot);
406
+ if (!snapshot.ok) {
407
+ process.stderr.write(`cannot use composition snapshot ${flags.snapshot}: ${snapshot.detail}\n`);
408
+ return EXIT_USAGE;
409
+ }
410
+ // A snapshot names the profile it was taken from; the answer belongs to that name, not to
411
+ // whatever `--profile` says (two profiles, two answers — BS-38).
412
+ env = {
413
+ dsh: snapshot.value.dsh,
414
+ node: process.versions.node,
415
+ platform: process.platform,
416
+ arch: process.arch,
417
+ profile: snapshot.value.profile,
418
+ profileDir: `<dsh-home>/profiles/${snapshot.value.profile}`,
419
+ bundles: snapshot.value.bundles.map((bundle) => bundle.name),
420
+ installed: [],
421
+ };
422
+ bundles = snapshot.value.bundles;
423
+ rows = snapshot.value.rows;
424
+ profileSource = 'snapshot';
425
+ }
426
+ else {
427
+ // Resolve the home first: a *relative* `--dsh-home` would otherwise produce a relative
428
+ // `profileDir` in the embedded verdicts, which redaction cannot match against an absolute
429
+ // root (and `--json` is meant to be pasted into an issue).
430
+ const dshHome = resolve(resolveDshHome(flags));
431
+ const liveEnv = await requireEnv(flags, dshHome);
432
+ if (liveEnv === null)
433
+ return EXIT_UNAVAILABLE;
434
+ const composition = await loadComposition(liveEnv, dshHome);
435
+ const claims = collectClaims(composition, warnings);
436
+ env = liveEnv;
437
+ bundles = composition.layers.map((layer) => ({ name: layer.name, version: layer.version, manifest: layer.manifest }));
438
+ rows = await resolveRows(liveEnv, rowTargets(claims));
439
+ profileSource = 'live';
440
+ }
441
+ // "Nothing sampled" is not a green report: an empty impact list would read as "all fine",
442
+ // so the command refuses to print one.
443
+ if (rows.length === 0 && bundles.length === 0) {
444
+ process.stderr.write(`nothing sampled: profile "${env.profile}" has no bundle layer and no loader row, so there is no impact to report\n`);
445
+ for (const warning of warnings)
446
+ process.stderr.write(`warn ${warning}\n`);
447
+ return EXIT_UNAVAILABLE;
448
+ }
449
+ const input = { env, target, bundles, rows, generatedAt: stamp, profileSource };
450
+ const first = judgeUpgradeImpact(input);
451
+ if (!first.ok) {
452
+ process.stderr.write(`${first.detail}\n`);
453
+ return EXIT_USAGE;
454
+ }
455
+ // The registry is asked only about units that need a version to move to, and only after the
456
+ // first (offline) judgement has decided which those are.
457
+ let judged = first;
458
+ if (flags.registry) {
459
+ const lookup = await registryLookupFor(first.impact, target, stamp);
460
+ judged = judgeUpgradeImpact({ ...input, registry: lookup.facts, registryFailures: lookup.failures });
461
+ if (!judged.ok) {
462
+ process.stderr.write(`${judged.detail}\n`);
463
+ return EXIT_USAGE;
464
+ }
465
+ if (lookup.failures.length > 0) {
466
+ process.stderr.write(`registry: ${lookup.failures.length} lookup(s) failed; the report is unchanged\n`);
467
+ }
468
+ }
469
+ const impact = judged.impact;
470
+ if (flags.json) {
471
+ writeJson(upgradeJsonPayload(impact));
472
+ }
473
+ else {
474
+ process.stdout.write(renderUpgradeImpact(impact, flags.locale));
475
+ for (const warning of warnings)
476
+ process.stdout.write(`warn ${warning}\n`);
477
+ }
478
+ return flags.strict && hasNewDenials(impact) ? EXIT_FINDINGS : EXIT_OK;
479
+ }
480
+ /** At most this many registry lookups per run (spec §6 rule 6): a 95-row profile must not fan out. */
481
+ const MAX_REGISTRY_LOOKUPS = 12;
482
+ /**
483
+ * Ask npm for "is there a published build that declares the target?".
484
+ *
485
+ * Secondary evidence only: the caller merges these facts into a second `judgeUpgradeImpact`
486
+ * call where they can only attach annotations (spec §6, N9). A failed lookup is recorded and
487
+ * never changes the exit code.
488
+ */
489
+ async function registryLookupFor(impact, target, stamp) {
490
+ const wanted = [
491
+ ...new Set(impact.units
492
+ .filter((unit) => (unit.bucket === 'would-be-denied' || unit.bucket === 'cannot-tell') && unit.version !== null)
493
+ .map((unit) => unit.name)),
494
+ ]
495
+ .sort((left, right) => (left < right ? -1 : left > right ? 1 : 0))
496
+ .slice(0, MAX_REGISTRY_LOOKUPS);
497
+ const facts = [];
498
+ const failures = [];
499
+ for (const name of wanted) {
500
+ const packument = await fetchPackument(name, { at: stamp });
501
+ if (!packument.ok) {
502
+ failures.push({ package: name, code: packument.error.code, detail: packument.error.detail });
503
+ continue;
504
+ }
505
+ const fact = registryFactFor({
506
+ packageName: name,
507
+ versions: packument.value.versions,
508
+ target,
509
+ publishedAt: packument.value.publishedAt,
510
+ });
511
+ if (fact !== null)
512
+ facts.push(fact);
513
+ }
514
+ return { facts, failures };
515
+ }
516
+ /**
517
+ * `upgrade --json`: the impact list, with the per-unit judgement **flattened**.
518
+ *
519
+ * WHY NOT THE NESTED VERDICT: on a 190-row profile the full `Verdict` objects are ~1.8 MB,
520
+ * and every field a reader needs (`reasons`, `remediation`, `missing_evidence`) is already on
521
+ * the unit. The nested object duplicates them a second time. `conclusion` / `evidence_tiers`
522
+ * are copied out of it here, so the payload still says which tier the judgement rests on —
523
+ * and no `Verdict` object means no `profileDir` in a file that is meant to be shareable.
524
+ */
525
+ function upgradeJsonPayload(impact) {
526
+ return {
527
+ schema_version: 1,
528
+ command: 'upgrade',
529
+ profile: impact.profile,
530
+ profile_source: impact.profile_source,
531
+ current: impact.current,
532
+ current_valid: impact.current_valid,
533
+ target: impact.target,
534
+ target_relation: impact.target_relation,
535
+ buckets: impact.buckets,
536
+ counts: impact.counts,
537
+ registry: impact.registry,
538
+ units: impact.units.map((unit) => {
539
+ const { verdict, ...rest } = unit;
540
+ return {
541
+ ...rest,
542
+ conclusion: verdict === null ? null : verdict.conclusion,
543
+ evidence_tiers: verdict === null
544
+ ? []
545
+ : [...new Set(verdict.evidence.map((item) => item.tier))].sort((left, right) => (left < right ? -1 : 1)),
546
+ };
547
+ }),
548
+ generated_at: impact.generated_at,
549
+ };
550
+ }
551
+ /**
552
+ * Read an `upgrade --snapshot` file: a frozen **composition** (declarations), not a runtime
553
+ * inventory. `audit --snapshot` reads the latter; the two share a flag name and nothing else.
554
+ *
555
+ * A rejected snapshot never falls back to the live profile: "I could not read your file" and
556
+ * "your profile is fine" are different sentences.
557
+ */
558
+ function readCompositionSnapshot(path) {
559
+ let raw;
560
+ try {
561
+ raw = JSON.parse(readFileSync(path, 'utf8'));
562
+ }
563
+ catch (error) {
564
+ return { ok: false, detail: `not readable as JSON (${error instanceof Error ? error.message : String(error)})` };
565
+ }
566
+ if (raw === null || typeof raw !== 'object' || Array.isArray(raw)) {
567
+ return { ok: false, detail: 'expected a JSON object' };
568
+ }
569
+ const record = raw;
570
+ if (record['schema_version'] !== 1)
571
+ return { ok: false, detail: 'schema_version must be 1' };
572
+ const profile = record['profile'];
573
+ if (typeof profile !== 'string' || profile.trim() === '') {
574
+ return { ok: false, detail: 'profile must be a non-empty string (the answer belongs to that profile)' };
575
+ }
576
+ const dsh = record['dsh'];
577
+ if (dsh !== undefined && dsh !== null) {
578
+ if (typeof dsh !== 'string' || upgradeTargetProblem(dsh) !== null) {
579
+ return { ok: false, detail: 'dsh must be an exact version string or null' };
580
+ }
581
+ }
582
+ const rawBundles = record['bundles'];
583
+ if (!Array.isArray(rawBundles))
584
+ return { ok: false, detail: 'bundles must be an array (may be empty)' };
585
+ const bundles = [];
586
+ for (const [index, entry] of rawBundles.entries()) {
587
+ if (entry === null || typeof entry !== 'object')
588
+ return { ok: false, detail: `bundles[${index}] is not an object` };
589
+ const bundle = entry;
590
+ if (typeof bundle['name'] !== 'string' || bundle['name'].trim() === '') {
591
+ return { ok: false, detail: `bundles[${index}].name must be a non-empty string` };
592
+ }
593
+ const manifest = bundle['manifest'];
594
+ if (manifest === undefined)
595
+ return { ok: false, detail: `bundles[${index}].manifest is required (null when unknown)` };
596
+ if (manifest !== null && (typeof manifest !== 'object' || Array.isArray(manifest))) {
597
+ return { ok: false, detail: `bundles[${index}].manifest must be an object or null` };
598
+ }
599
+ const version = bundle['version'];
600
+ if (version !== undefined && version !== null && typeof version !== 'string') {
601
+ return { ok: false, detail: `bundles[${index}].version must be a string or null` };
602
+ }
603
+ bundles.push({ name: bundle['name'], version: version ?? null, manifest });
604
+ }
605
+ const rawRows = record['rows'];
606
+ if (!Array.isArray(rawRows))
607
+ return { ok: false, detail: 'rows must be an array (may be empty)' };
608
+ const rows = [];
609
+ for (const [index, entry] of rawRows.entries()) {
610
+ if (entry === null || typeof entry !== 'object')
611
+ return { ok: false, detail: `rows[${index}] is not an object` };
612
+ const row = entry;
613
+ for (const field of ['rowId', 'module', 'source']) {
614
+ if (typeof row[field] !== 'string' || row[field].trim() === '') {
615
+ return { ok: false, detail: `rows[${index}].${field} must be a non-empty string` };
616
+ }
617
+ }
618
+ const manifest = row['manifest'];
619
+ if (manifest === undefined)
620
+ return { ok: false, detail: `rows[${index}].manifest is required (null when not installed)` };
621
+ if (manifest !== null && (typeof manifest !== 'object' || Array.isArray(manifest))) {
622
+ return { ok: false, detail: `rows[${index}].manifest must be an object or null` };
623
+ }
624
+ const version = row['version'];
625
+ if (version !== undefined && version !== null && typeof version !== 'string') {
626
+ return { ok: false, detail: `rows[${index}].version must be a string or null` };
627
+ }
628
+ rows.push({
629
+ rowId: row['rowId'],
630
+ module: row['module'],
631
+ source: row['source'],
632
+ version: version ?? null,
633
+ manifest,
634
+ });
635
+ }
636
+ return { ok: true, value: { profile: profile.trim(), dsh: typeof dsh === 'string' ? dsh : null, bundles, rows } };
637
+ }
355
638
  async function commandCheck(flags, spec) {
356
639
  if (spec === undefined || spec.trim() === '') {
357
640
  process.stderr.write('usage: dsh-triage check <pkg[@version]>\n');
@@ -399,8 +682,27 @@ async function commandCheck(flags, spec) {
399
682
  registryDrift: drift,
400
683
  rangeAdvice: true,
401
684
  });
685
+ /*
686
+ * M5-a (spec §7/§9): the verdict exists, so it may be recorded - BEFORE anything is printed
687
+ * and without touching the verdict, the output or the exit code. `recordOutcomes` is a
688
+ * no-op unless the user opted in and never throws (control N14).
689
+ *
690
+ * The prior is read BEFORE the record is appended, so the annotation says "this machine said
691
+ * X before this run" and cannot include the run it is annotating (§10.2: a prior is history,
692
+ * not a self-reference). The prior is only read for `--explain` (control N3: without it the
693
+ * output is byte-identical whether or not a prior exists).
694
+ */
695
+ const prior = flags.explain ? localPriorFor({ env, packageName: name, version: targetVersion }) : null;
696
+ recordOutcomes({
697
+ source: 'check',
698
+ subjects: [{ verdict, version: targetVersion }],
699
+ at: stamp,
700
+ probe: null,
701
+ flag: flags.outcomes,
702
+ stderr: (line) => process.stderr.write(line),
703
+ });
402
704
  if (flags.json) {
403
- writeJson({
705
+ const payload = {
404
706
  schema_version: 1,
405
707
  command: 'check',
406
708
  verdict: safeVerdicts(flags, [verdict])[0],
@@ -417,13 +719,20 @@ async function commandCheck(flags, spec) {
417
719
  detail: drift.detail,
418
720
  },
419
721
  },
420
- });
722
+ };
723
+ // A sibling key, never a field of `verdict` (ADR-0011 §4.1).
724
+ if (prior !== null)
725
+ payload['prior'] = prior;
726
+ writeJson(payload);
421
727
  return exitFor(flags, [verdict]);
422
728
  }
423
729
  process.stdout.write(`${renderVerdict(verdict, flags.locale)}\n`);
424
730
  if (flags.explain) {
425
731
  process.stdout.write(`${renderRegistryExplain(drift, flags.locale)}\n`);
426
732
  }
733
+ if (prior !== null) {
734
+ process.stdout.write(renderPrior(prior, flags.locale));
735
+ }
427
736
  if (admission.status === 'admitted') {
428
737
  process.stdout.write('note declaration passes; runtime behaviour is still unproven (probe lands in M3).\n');
429
738
  }
@@ -708,6 +1017,23 @@ async function commandProbe(flags, spec) {
708
1017
  };
709
1018
  const verdict = probeVerdict({ run, judgement, env, at: stamp });
710
1019
  const roots = [homedir(), dshHome, probeScratchRoot()];
1020
+ /*
1021
+ * M5-a (spec §9): a `probe --execute` records exactly one outcome. The candidate's EXACT
1022
+ * version is the key, so a spec that does not name one (a local path, a tag) is skipped
1023
+ * rather than guessed. Sum of step durations is the only "total" the run actually measures.
1024
+ */
1025
+ recordOutcomes({
1026
+ source: 'probe',
1027
+ subjects: [{ verdict, version: exactVersionOfSpec(spec) }],
1028
+ at: stamp,
1029
+ probe: {
1030
+ totalMs: run.steps.reduce((sum, step) => sum + (Number.isFinite(step.ms) ? step.ms : 0), 0),
1031
+ bootMs: run.timings.bootToSampleMs,
1032
+ profile: plan.value.profile,
1033
+ },
1034
+ flag: flags.outcomes,
1035
+ stderr: (line) => process.stderr.write(line),
1036
+ });
711
1037
  if (flags.json) {
712
1038
  writeJson({
713
1039
  schema_version: 1,
@@ -824,8 +1150,75 @@ async function commandServe(flags) {
824
1150
  return EXIT_OK;
825
1151
  }
826
1152
  /* -------------------------------- helpers -------------------------------- */
827
- async function requireEnv(flags) {
828
- const result = await loadEnv({ dshHome: resolveDshHome(flags), profile: flags.profile });
1153
+ /**
1154
+ * `outcomes` — the local store's three verbs (M5-a, spec §7 / §11).
1155
+ *
1156
+ * `--purge` deliberately needs no opt-in: deleting must always be possible, and it must never
1157
+ * be the thing that creates the directory (control N5). Text output carries counts only - no
1158
+ * record, no package name, no path (control N13).
1159
+ */
1160
+ async function commandOutcomes(flags) {
1161
+ const at = stampOf(flags);
1162
+ const verbs = [flags.enable, flags.disable, flags.purge].filter(Boolean).length;
1163
+ if (verbs > 1) {
1164
+ process.stderr.write('usage: dsh-triage outcomes [--status | --enable | --disable | --purge]\n');
1165
+ return EXIT_USAGE;
1166
+ }
1167
+ if (flags.purge) {
1168
+ const result = purgeOutcomes({ at });
1169
+ if (!result.ok) {
1170
+ process.stderr.write(`cannot purge the outcome store (${result.detail}); nothing was reported as deleted\n`);
1171
+ return EXIT_FINDINGS;
1172
+ }
1173
+ if (flags.json)
1174
+ writeJson(result.report);
1175
+ else
1176
+ process.stdout.write(renderPurge(result.report));
1177
+ return EXIT_OK;
1178
+ }
1179
+ if (flags.enable || flags.disable) {
1180
+ const mode = flags.enable ? 'local' : 'off';
1181
+ const written = writeOutcomeMode(mode);
1182
+ if (!written.ok) {
1183
+ process.stderr.write(`cannot write the outcome config (${written.detail})\n`);
1184
+ return EXIT_FINDINGS;
1185
+ }
1186
+ if (flags.json) {
1187
+ writeJson({ schema_version: 1, mode, changed: written.changed });
1188
+ }
1189
+ else {
1190
+ process.stdout.write(`outcomes ${mode}${written.changed ? '' : ' (already set)'}\n`);
1191
+ }
1192
+ return EXIT_OK;
1193
+ }
1194
+ // `--status` is the default verb: "how much is actually stored right now".
1195
+ const reading = readOutcomeConfig();
1196
+ for (const problem of reading.problems)
1197
+ process.stderr.write(`outcomes: off (${problem})\n`);
1198
+ const report = outcomeStatus({});
1199
+ if (flags.json)
1200
+ writeJson(report);
1201
+ else
1202
+ process.stdout.write(renderStatus(report));
1203
+ return EXIT_OK;
1204
+ }
1205
+ /**
1206
+ * The exact version a probe candidate pins, or `null`.
1207
+ *
1208
+ * WHY NOT ASK THE REGISTRY: a record's key must be the version that was actually installed, and
1209
+ * a spec without a version cannot state it. Guessing `latest` would file the measurement under
1210
+ * a build that may already be replaced, so the caller skips the record instead.
1211
+ */
1212
+ function exactVersionOfSpec(spec) {
1213
+ const trimmed = spec.trim();
1214
+ const at = trimmed.lastIndexOf('@');
1215
+ if (at <= 0)
1216
+ return null;
1217
+ const version = trimmed.slice(at + 1);
1218
+ return /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/.test(version) ? version : null;
1219
+ }
1220
+ async function requireEnv(flags, dshHomeOverride) {
1221
+ const result = await loadEnv({ dshHome: dshHomeOverride ?? resolveDshHome(flags), profile: flags.profile });
829
1222
  if (!result.ok) {
830
1223
  process.stderr.write(`cannot read the profile: ${result.error.code} — ${result.error.detail}\n`);
831
1224
  if (result.error.code === 'profile-not-found') {
@@ -941,6 +1334,13 @@ function parseArgs(argv) {
941
1334
  let readinessTimeoutMs = null;
942
1335
  let unsettledReadinessMs = null;
943
1336
  let copyProfile = null;
1337
+ let outcomes = null;
1338
+ let enable = false;
1339
+ let disable = false;
1340
+ let purge = false;
1341
+ let status = false;
1342
+ let to = null;
1343
+ let registry = false;
944
1344
  for (let index = 0; index < argv.length; index += 1) {
945
1345
  const token = argv[index];
946
1346
  if (token === undefined)
@@ -1085,6 +1485,35 @@ function parseArgs(argv) {
1085
1485
  copyProfile = value;
1086
1486
  break;
1087
1487
  }
1488
+ case '--outcomes': {
1489
+ const value = takeValue();
1490
+ if (value !== 'off' && value !== 'local')
1491
+ return null;
1492
+ outcomes = value;
1493
+ break;
1494
+ }
1495
+ case '--enable':
1496
+ enable = true;
1497
+ break;
1498
+ case '--disable':
1499
+ disable = true;
1500
+ break;
1501
+ case '--purge':
1502
+ purge = true;
1503
+ break;
1504
+ case '--status':
1505
+ status = true;
1506
+ break;
1507
+ case '--to': {
1508
+ const value = takeValue();
1509
+ if (value === null)
1510
+ return null;
1511
+ to = value;
1512
+ break;
1513
+ }
1514
+ case '--registry':
1515
+ registry = true;
1516
+ break;
1088
1517
  case '--locale': {
1089
1518
  const value = takeValue();
1090
1519
  if (value !== 'en' && value !== 'zh')
@@ -1096,7 +1525,7 @@ function parseArgs(argv) {
1096
1525
  return null;
1097
1526
  }
1098
1527
  }
1099
- const flags = { json, all, strict, execute, dshHome, profile, stamp, locale, noRedact, snapshot, explain, dshMain, noHttp, browser, port, results, allowExecute, audit, readinessTimeoutMs, unsettledReadinessMs, copyProfile, profileExplicit, out };
1528
+ const flags = { json, all, strict, execute, dshHome, profile, stamp, locale, noRedact, snapshot, explain, dshMain, noHttp, browser, port, results, allowExecute, audit, readinessTimeoutMs, unsettledReadinessMs, copyProfile, profileExplicit, out, outcomes, enable, disable, purge, status, to, registry };
1100
1529
  if (help)
1101
1530
  return { command: 'help', positionals: [], flags };
1102
1531
  const command = positionals.shift() ?? 'help';