dsh-triage 0.1.1 → 0.3.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/audit-data.d.ts.map +1 -1
- package/dist/audit-data.js +5 -2
- package/dist/audit-data.js.map +1 -1
- package/dist/cli.js +774 -20
- package/dist/cli.js.map +1 -1
- package/dist/fix.d.ts +115 -0
- package/dist/fix.d.ts.map +1 -0
- package/dist/fix.js +267 -0
- package/dist/fix.js.map +1 -0
- package/dist/outcomes/config.d.ts +96 -0
- package/dist/outcomes/config.d.ts.map +1 -0
- package/dist/outcomes/config.js +175 -0
- package/dist/outcomes/config.js.map +1 -0
- package/dist/outcomes/prior.d.ts +34 -0
- package/dist/outcomes/prior.d.ts.map +1 -0
- package/dist/outcomes/prior.js +55 -0
- package/dist/outcomes/prior.js.map +1 -0
- package/dist/outcomes/purge.d.ts +71 -0
- package/dist/outcomes/purge.d.ts.map +1 -0
- package/dist/outcomes/purge.js +166 -0
- package/dist/outcomes/purge.js.map +1 -0
- package/dist/outcomes/store.d.ts +102 -0
- package/dist/outcomes/store.d.ts.map +1 -0
- package/dist/outcomes/store.js +230 -0
- package/dist/outcomes/store.js.map +1 -0
- package/dist/serve.d.ts +49 -14
- package/dist/serve.d.ts.map +1 -1
- package/dist/serve.js +1023 -141
- package/dist/serve.js.map +1 -1
- package/dist/summary.d.ts +78 -0
- package/dist/summary.d.ts.map +1 -0
- package/dist/summary.js +235 -0
- package/dist/summary.js.map +1 -0
- package/package.json +7 -4
package/dist/cli.js
CHANGED
|
@@ -11,20 +11,26 @@
|
|
|
11
11
|
*
|
|
12
12
|
* Exit codes: 0 ok · 1 findings (audit always, others only with --strict) · 2 usage · 3 unavailable
|
|
13
13
|
*/
|
|
14
|
-
import { existsSync, readFileSync, readdirSync, writeFileSync } from 'node:fs';
|
|
14
|
+
import { existsSync, mkdirSync, readFileSync, readdirSync, renameSync, unlinkSync, writeFileSync } from 'node:fs';
|
|
15
15
|
import { createHash } from 'node:crypto';
|
|
16
16
|
import { homedir, tmpdir } from 'node:os';
|
|
17
|
-
import { join, resolve } from 'node:path';
|
|
17
|
+
import { dirname, isAbsolute, join, relative, 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, DIST_TAG_PACKAGE, distTagTargetOf, evaluateAdmission, extractEntryClaims, extractPresetDeclarations, findEntryIdCollisions, findPresetDivergence, format, groupClaimsBySource, hasNewDenials, judgeUpgradeImpact, judgeVersionDrift, loadEnv, parseInventorySnapshot, parsePatchYaml, redactEnv, redactPath, redactVerdict, registryFactFor, renderUpgradeImpact, renderUpgradeCard, renderVerdict, resolveDistTagTarget, 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';
|
|
31
|
+
import { applyExemptionFixes, planFixes, readProfileDependencies, runtimeSupportsExemptions, undoFix } from './fix.js';
|
|
27
32
|
import { startPanel } from './serve.js';
|
|
33
|
+
import { buildProfileSummary, formatProfileSummary } from './summary.js';
|
|
28
34
|
const EXIT_OK = 0;
|
|
29
35
|
const EXIT_FINDINGS = 1;
|
|
30
36
|
const EXIT_USAGE = 2;
|
|
@@ -37,17 +43,25 @@ const MAX_RENDERED_VERDICTS = 20;
|
|
|
37
43
|
const HELP = `dsh-triage — the judgment layer for DeepSeek Harness plugins
|
|
38
44
|
|
|
39
45
|
Usage
|
|
46
|
+
dsh-triage one screen: is this profile broken, which row, what to type
|
|
47
|
+
dsh-triage status the same answer, as an explicit command
|
|
40
48
|
dsh-triage env environment fingerprint
|
|
41
49
|
dsh-triage why why did a plugin silently disappear?
|
|
42
50
|
dsh-triage check <pkg[@version]> judge a candidate before installing
|
|
43
|
-
dsh-triage audit
|
|
51
|
+
dsh-triage audit the same answer, plus the full ledger with --all
|
|
44
52
|
dsh-triage probe <pkg[@version]> print an isolated probe plan (dry-run)
|
|
45
|
-
dsh-triage serve open
|
|
53
|
+
dsh-triage serve open the local panel (127.0.0.1, token-gated)
|
|
46
54
|
dsh-triage badge <pkg[@version]> shields-style SVG rendered from recorded evidence
|
|
47
55
|
dsh-triage index format-1 market index of versions measured "go" here
|
|
56
|
+
dsh-triage outcomes local outcome store: status / --enable / --disable / --purge
|
|
57
|
+
dsh-triage upgrade --to <version> which rows/bundles the target dsh would deny, and how to fix
|
|
58
|
+
dsh-triage upgrade --to next|latest same judgement, with the target resolved from npm dist-tags
|
|
59
|
+
dsh-triage fix what can be repaired automatically; --apply writes, --undo reverts
|
|
48
60
|
Flags
|
|
49
61
|
--json machine-readable output
|
|
50
|
-
--all include findings that are not blocking
|
|
62
|
+
--all include findings that are not blocking (audit: print the full ledger)
|
|
63
|
+
--apply (fix) actually write the plan; without it nothing is written
|
|
64
|
+
--undo <journal> (fix) restore the files an earlier --apply changed
|
|
51
65
|
--strict exit 1 when a conclusion is not "go"
|
|
52
66
|
--profile <name> profile name (default: web)
|
|
53
67
|
--dsh-home <path> override $DSH_HOME (default: ~/.dsh)
|
|
@@ -55,6 +69,7 @@ Flags
|
|
|
55
69
|
--no-redact keep absolute paths in --json output (default: redact to ~)
|
|
56
70
|
--stamp <iso> fixed timestamp for reproducible output
|
|
57
71
|
--snapshot <file> (audit) judge runtime phases from a pluginInventory snapshot
|
|
72
|
+
--snapshot <file> (upgrade) judge a frozen composition snapshot (schema_version 1)
|
|
58
73
|
--explain (check) show the registry tag facts behind the verdict
|
|
59
74
|
--execute (probe) really run the plan inside an isolated DSH_HOME
|
|
60
75
|
--dsh-main <path> (probe --execute) DSH launcher entry the sandbox boots
|
|
@@ -65,9 +80,18 @@ Flags
|
|
|
65
80
|
--copy-profile <name> (probe) measure inside a copy of this profile's declarations (T-304)
|
|
66
81
|
--port <n> (serve) port to bind on 127.0.0.1; 0 picks a free one
|
|
67
82
|
--results <dir> (serve, badge) directory of evidence to read (default: ./data/results)
|
|
68
|
-
--out <file> (badge) write the SVG here
|
|
83
|
+
--out <file> (badge) write the SVG here; (upgrade --card) write the card here, print the path
|
|
69
84
|
--allow-execute (serve) enable actions; without it the panel is read-only
|
|
85
|
+
--no-audit (serve) artifacts only; skip reading the current profile
|
|
70
86
|
--audit (serve) expose GET /api/audit (current composition, same engine as the CLI)
|
|
87
|
+
--outcomes <mode> (check, probe) record this verdict locally: off | local (per-run, not saved)
|
|
88
|
+
--enable (outcomes) opt in to the local outcome store
|
|
89
|
+
--disable (outcomes) opt out again; existing records are kept until --purge
|
|
90
|
+
--purge (outcomes) delete every record this tool stored, then the directory
|
|
91
|
+
--status (outcomes) how many records exist (default when no verb is given)
|
|
92
|
+
--to <version> (upgrade) target dsh: exact semver (e.g. 0.3.0), or next / latest (resolved from npm)
|
|
93
|
+
--registry (upgrade) annotate with published builds that declare the target (offline by default)
|
|
94
|
+
--card (upgrade) paste-ready markdown for the release discussion (four buckets + boundary)
|
|
71
95
|
--help this text
|
|
72
96
|
|
|
73
97
|
Exit codes: 0 ok · 1 findings (audit always, others only with --strict) · 2 usage · 3 unavailable
|
|
@@ -83,6 +107,10 @@ async function run(argv) {
|
|
|
83
107
|
case 'help':
|
|
84
108
|
process.stdout.write(HELP);
|
|
85
109
|
return EXIT_OK;
|
|
110
|
+
case 'status':
|
|
111
|
+
return commandStatus(flags);
|
|
112
|
+
case 'fix':
|
|
113
|
+
return commandFix(flags);
|
|
86
114
|
case 'env':
|
|
87
115
|
return commandEnv(flags);
|
|
88
116
|
case 'why':
|
|
@@ -99,6 +127,10 @@ async function run(argv) {
|
|
|
99
127
|
return commandIndex(flags);
|
|
100
128
|
case 'serve':
|
|
101
129
|
return commandServe(flags);
|
|
130
|
+
case 'outcomes':
|
|
131
|
+
return commandOutcomes(flags);
|
|
132
|
+
case 'upgrade':
|
|
133
|
+
return commandUpgrade(flags);
|
|
102
134
|
default:
|
|
103
135
|
process.stderr.write(`unknown command "${command}"; see --help\n`);
|
|
104
136
|
return EXIT_USAGE;
|
|
@@ -352,6 +384,423 @@ async function commandWhy(flags) {
|
|
|
352
384
|
}
|
|
353
385
|
return exitFor(flags, findings);
|
|
354
386
|
}
|
|
387
|
+
/**
|
|
388
|
+
* `upgrade --to <version>`: which loader rows and bundles the **target** runtime would deny
|
|
389
|
+
* (`T-502`, `docs/specs/M5-upgrade.md`).
|
|
390
|
+
*
|
|
391
|
+
* Same engine, one runtime further: every unit is judged by `evaluateAdmission` with `env.dsh`
|
|
392
|
+
* replaced by the target, and the result is the verdict `why` would print on that runtime.
|
|
393
|
+
* Nothing here re-implements a range, and nothing here claims a boot was measured.
|
|
394
|
+
*
|
|
395
|
+
* NOT DONE ON PURPOSE: no profile edit, no automatic pin, no probe run, and no network unless
|
|
396
|
+
* `--registry` is passed or the target is one of the two dist-tag keywords (`next` / `latest`,
|
|
397
|
+
* M6 C9). Registry facts are annotations that cannot move a unit; a dist-tag only decides which
|
|
398
|
+
* exact version gets judged, and then the same engine judges it.
|
|
399
|
+
*/
|
|
400
|
+
async function commandUpgrade(flags) {
|
|
401
|
+
// No target, no judgement (M6 C8): the guidance reports what could be read and never invents
|
|
402
|
+
// a target, a bucket or a verdict.
|
|
403
|
+
if (flags.to === null)
|
|
404
|
+
return commandUpgradeGuidance(flags);
|
|
405
|
+
const stamp = stampOf(flags);
|
|
406
|
+
// Validate BEFORE reading anything: a bad target must be a usage error whether or not the
|
|
407
|
+
// profile exists, and must never reach `satisfies()` (which returns false for garbage and
|
|
408
|
+
// would turn "bad flag" into "everything will break").
|
|
409
|
+
let target = flags.to.trim();
|
|
410
|
+
let distTag = null;
|
|
411
|
+
const requestedTag = distTagTargetOf(target);
|
|
412
|
+
if (requestedTag !== null) {
|
|
413
|
+
const resolved = await resolveUpgradeTag(requestedTag, stamp);
|
|
414
|
+
if (resolved === null)
|
|
415
|
+
return EXIT_UNAVAILABLE;
|
|
416
|
+
target = resolved.version;
|
|
417
|
+
distTag = resolved;
|
|
418
|
+
// stdout stays the report — the card gets pasted in public, so the resolution goes to stderr.
|
|
419
|
+
process.stderr.write(`target ${distTag.tag} → ${distTag.version} (npm ${DIST_TAG_PACKAGE})\n`);
|
|
420
|
+
}
|
|
421
|
+
const problem = upgradeTargetProblem(target);
|
|
422
|
+
if (problem !== null) {
|
|
423
|
+
process.stderr.write(`${problem}\n`);
|
|
424
|
+
return EXIT_USAGE;
|
|
425
|
+
}
|
|
426
|
+
const warnings = [];
|
|
427
|
+
let env;
|
|
428
|
+
let bundles;
|
|
429
|
+
let rows;
|
|
430
|
+
let profileSource;
|
|
431
|
+
if (flags.snapshot !== null) {
|
|
432
|
+
const snapshot = readCompositionSnapshot(flags.snapshot);
|
|
433
|
+
if (!snapshot.ok) {
|
|
434
|
+
process.stderr.write(`cannot use composition snapshot ${flags.snapshot}: ${snapshot.detail}\n`);
|
|
435
|
+
return EXIT_USAGE;
|
|
436
|
+
}
|
|
437
|
+
// A snapshot names the profile it was taken from; the answer belongs to that name, not to
|
|
438
|
+
// whatever `--profile` says (two profiles, two answers — BS-38).
|
|
439
|
+
env = {
|
|
440
|
+
dsh: snapshot.value.dsh,
|
|
441
|
+
node: process.versions.node,
|
|
442
|
+
platform: process.platform,
|
|
443
|
+
arch: process.arch,
|
|
444
|
+
profile: snapshot.value.profile,
|
|
445
|
+
profileDir: `<dsh-home>/profiles/${snapshot.value.profile}`,
|
|
446
|
+
bundles: snapshot.value.bundles.map((bundle) => bundle.name),
|
|
447
|
+
installed: [],
|
|
448
|
+
};
|
|
449
|
+
bundles = snapshot.value.bundles;
|
|
450
|
+
rows = snapshot.value.rows;
|
|
451
|
+
profileSource = 'snapshot';
|
|
452
|
+
}
|
|
453
|
+
else {
|
|
454
|
+
// Resolve the home first: a *relative* `--dsh-home` would otherwise produce a relative
|
|
455
|
+
// `profileDir` in the embedded verdicts, which redaction cannot match against an absolute
|
|
456
|
+
// root (and `--json` is meant to be pasted into an issue).
|
|
457
|
+
const dshHome = resolve(resolveDshHome(flags));
|
|
458
|
+
const liveEnv = await requireEnv(flags, dshHome);
|
|
459
|
+
if (liveEnv === null)
|
|
460
|
+
return EXIT_UNAVAILABLE;
|
|
461
|
+
const composition = await loadComposition(liveEnv, dshHome);
|
|
462
|
+
const claims = collectClaims(composition, warnings);
|
|
463
|
+
env = liveEnv;
|
|
464
|
+
bundles = composition.layers.map((layer) => ({ name: layer.name, version: layer.version, manifest: layer.manifest }));
|
|
465
|
+
rows = await resolveRows(liveEnv, rowTargets(claims));
|
|
466
|
+
profileSource = 'live';
|
|
467
|
+
}
|
|
468
|
+
// "Nothing sampled" is not a green report: an empty impact list would read as "all fine",
|
|
469
|
+
// so the command refuses to print one.
|
|
470
|
+
if (rows.length === 0 && bundles.length === 0) {
|
|
471
|
+
process.stderr.write(`nothing sampled: profile "${env.profile}" has no bundle layer and no loader row, so there is no impact to report\n`);
|
|
472
|
+
for (const warning of warnings)
|
|
473
|
+
process.stderr.write(`warn ${warning}\n`);
|
|
474
|
+
return EXIT_UNAVAILABLE;
|
|
475
|
+
}
|
|
476
|
+
const input = { env, target, bundles, rows, generatedAt: stamp, profileSource };
|
|
477
|
+
const first = judgeUpgradeImpact(input);
|
|
478
|
+
if (!first.ok) {
|
|
479
|
+
process.stderr.write(`${first.detail}\n`);
|
|
480
|
+
return EXIT_USAGE;
|
|
481
|
+
}
|
|
482
|
+
// The registry is asked only about units that need a version to move to, and only after the
|
|
483
|
+
// first (offline) judgement has decided which those are.
|
|
484
|
+
let judged = first;
|
|
485
|
+
if (flags.registry) {
|
|
486
|
+
const lookup = await registryLookupFor(first.impact, target, stamp);
|
|
487
|
+
judged = judgeUpgradeImpact({ ...input, registry: lookup.facts, registryFailures: lookup.failures });
|
|
488
|
+
if (!judged.ok) {
|
|
489
|
+
process.stderr.write(`${judged.detail}\n`);
|
|
490
|
+
return EXIT_USAGE;
|
|
491
|
+
}
|
|
492
|
+
if (lookup.failures.length > 0) {
|
|
493
|
+
process.stderr.write(`registry: ${lookup.failures.length} lookup(s) failed; the report is unchanged\n`);
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
const impact = judged.impact;
|
|
497
|
+
if (flags.json) {
|
|
498
|
+
// One output per run (M6 N7): `--json` wins, and the ignored `--card` / `--out` are said out loud
|
|
499
|
+
// rather than dropped silently.
|
|
500
|
+
if (flags.card)
|
|
501
|
+
process.stderr.write('card: ignored because --json was given (one output per run)\n');
|
|
502
|
+
if (flags.out !== null)
|
|
503
|
+
process.stderr.write('out: ignored because --json was given (one output per run)\n');
|
|
504
|
+
writeJson(upgradeJsonPayload(impact, distTag));
|
|
505
|
+
}
|
|
506
|
+
else if (flags.card) {
|
|
507
|
+
const card = renderUpgradeCard(impact, {
|
|
508
|
+
locale: flags.locale,
|
|
509
|
+
redactRoots: [homedir(), flags.dshHome ?? resolveDshHome(flags)],
|
|
510
|
+
});
|
|
511
|
+
if (flags.out === null) {
|
|
512
|
+
process.stdout.write(card);
|
|
513
|
+
}
|
|
514
|
+
else {
|
|
515
|
+
// M6 C10: the file gets the same bytes a bare `--card` prints, written atomically. Nothing
|
|
516
|
+
// half-written is left behind, and stdout carries only the path a user can copy.
|
|
517
|
+
const written = writeCardFile(flags.out, card);
|
|
518
|
+
if (!written.ok) {
|
|
519
|
+
process.stderr.write(`${written.detail}\n`);
|
|
520
|
+
return written.reason === 'exists' ? EXIT_USAGE : EXIT_UNAVAILABLE;
|
|
521
|
+
}
|
|
522
|
+
process.stdout.write(`${written.display}\n`);
|
|
523
|
+
}
|
|
524
|
+
// The card is pasted in public, so warnings go to stderr: a `warn` line inside the markdown would be copied too.
|
|
525
|
+
for (const warning of warnings)
|
|
526
|
+
process.stderr.write(`warn ${warning}\n`);
|
|
527
|
+
}
|
|
528
|
+
else {
|
|
529
|
+
process.stdout.write(renderUpgradeImpact(impact, flags.locale));
|
|
530
|
+
for (const warning of warnings)
|
|
531
|
+
process.stdout.write(`warn ${warning}\n`);
|
|
532
|
+
}
|
|
533
|
+
return flags.strict && hasNewDenials(impact) ? EXIT_FINDINGS : EXIT_OK;
|
|
534
|
+
}
|
|
535
|
+
/**
|
|
536
|
+
* Turn `next` / `latest` into the exact version the registry publishes (`T-806`, M6 C9).
|
|
537
|
+
*
|
|
538
|
+
* Two refusals, both exit 3 and both producing **no bucket**: npm did not answer, or the tag exists
|
|
539
|
+
* but does not name an exact version. Neither is a finding about the user's composition, so neither
|
|
540
|
+
* may be reported as one.
|
|
541
|
+
*/
|
|
542
|
+
async function resolveUpgradeTag(tag, stamp) {
|
|
543
|
+
const packument = await fetchPackument(DIST_TAG_PACKAGE, { at: stamp });
|
|
544
|
+
if (!packument.ok) {
|
|
545
|
+
process.stderr.write(`cannot resolve --to ${tag}: npm did not answer for ${DIST_TAG_PACKAGE} (${packument.error.code}) — ${packument.error.detail}\n`);
|
|
546
|
+
process.stderr.write('hint: pass the exact version instead — that path never touches the network\n');
|
|
547
|
+
return null;
|
|
548
|
+
}
|
|
549
|
+
const resolved = resolveDistTagTarget({ requested: tag, distTags: packument.value.distTags });
|
|
550
|
+
if (!resolved.ok) {
|
|
551
|
+
process.stderr.write(`${resolved.detail}\n`);
|
|
552
|
+
process.stderr.write('hint: pass the exact version instead — that path never touches the network\n');
|
|
553
|
+
return null;
|
|
554
|
+
}
|
|
555
|
+
return { tag: resolved.tag, version: resolved.version };
|
|
556
|
+
}
|
|
557
|
+
/**
|
|
558
|
+
* `upgrade` with no `--to` (`T-807`, M6 C8): say what could be read, and refuse to judge.
|
|
559
|
+
*
|
|
560
|
+
* WHY IT STILL EXITS 2: without a target there is nothing to judge, and an empty report would read
|
|
561
|
+
* as "nothing will break". The guidance is on stderr for the same reason every other usage path is:
|
|
562
|
+
* a non-zero exit must never put a report-shaped thing on stdout.
|
|
563
|
+
*
|
|
564
|
+
* WHY IT READS THE REGISTRY ONCE: "your options are next=X / latest=Z" is the whole point of the
|
|
565
|
+
* guidance (a stranger should not have to guess a version string). That single read is bounded and
|
|
566
|
+
* read-only; when it fails the line says `unknown` and no value is invented.
|
|
567
|
+
*/
|
|
568
|
+
async function commandUpgradeGuidance(flags) {
|
|
569
|
+
const catalog = catalogFor(flags.locale);
|
|
570
|
+
const line = (id, params) => {
|
|
571
|
+
const template = catalog.messages[id];
|
|
572
|
+
return template === undefined ? id : format(template, params);
|
|
573
|
+
};
|
|
574
|
+
const out = [line('upgrade.guidance.headline')];
|
|
575
|
+
const dshHome = resolve(resolveDshHome(flags));
|
|
576
|
+
const envReading = await loadEnv({ dshHome, profile: flags.profile });
|
|
577
|
+
if (!envReading.ok) {
|
|
578
|
+
out.push(line('upgrade.guidance.current-unknown', { detail: `${envReading.error.code} — ${envReading.error.detail}` }));
|
|
579
|
+
}
|
|
580
|
+
else {
|
|
581
|
+
const runtime = envReading.value.dsh === null ? null : envReading.value.dsh.trim();
|
|
582
|
+
out.push(runtime === null || runtime === ''
|
|
583
|
+
? line('upgrade.guidance.current-unknown', { detail: 'this profile declares no dsh version' })
|
|
584
|
+
: line('upgrade.guidance.current', { version: runtime, profile: envReading.value.profile }));
|
|
585
|
+
}
|
|
586
|
+
const packument = await fetchPackument(DIST_TAG_PACKAGE, { at: stampOf(flags) });
|
|
587
|
+
if (!packument.ok) {
|
|
588
|
+
out.push(line('upgrade.guidance.targets-unknown', { detail: `npm ${packument.error.code}` }));
|
|
589
|
+
}
|
|
590
|
+
else {
|
|
591
|
+
const next = packument.value.distTags['next'];
|
|
592
|
+
const latest = packument.value.distTags['latest'];
|
|
593
|
+
out.push(next === undefined && latest === undefined
|
|
594
|
+
? line('upgrade.guidance.targets-unknown', { detail: `${DIST_TAG_PACKAGE} publishes no next/latest dist-tag` })
|
|
595
|
+
: line('upgrade.guidance.targets', { next: next ?? '—', latest: latest ?? '—', package: DIST_TAG_PACKAGE }));
|
|
596
|
+
}
|
|
597
|
+
out.push(line('upgrade.guidance.next-step'));
|
|
598
|
+
process.stderr.write(`${out.join('\n')}\n`);
|
|
599
|
+
return EXIT_USAGE;
|
|
600
|
+
}
|
|
601
|
+
/**
|
|
602
|
+
* Write the card atomically (`T-808`, M6 C10).
|
|
603
|
+
*
|
|
604
|
+
* Refuses to overwrite (a card is evidence a user may be about to paste; silently replacing it is
|
|
605
|
+
* how two different readings end up in one file), and never leaves a partial file: the text lands
|
|
606
|
+
* in a sibling temp file first and is renamed into place.
|
|
607
|
+
*
|
|
608
|
+
* The printed path is relative when the file is under the current directory: the card's stdout is
|
|
609
|
+
* the thing users copy into a public issue, and `C:\\Users\\<name>` must never ride along.
|
|
610
|
+
*/
|
|
611
|
+
function writeCardFile(rawPath, text) {
|
|
612
|
+
const target = resolve(rawPath);
|
|
613
|
+
if (existsSync(target)) {
|
|
614
|
+
// A usage error, not an outage: the user picked a path that already holds something.
|
|
615
|
+
return {
|
|
616
|
+
ok: false,
|
|
617
|
+
reason: 'exists',
|
|
618
|
+
detail: `refusing to overwrite existing file: ${rawPath} (move it or pick another path)`,
|
|
619
|
+
};
|
|
620
|
+
}
|
|
621
|
+
const temp = `${target}.tmp-${process.pid}`;
|
|
622
|
+
try {
|
|
623
|
+
mkdirSync(dirname(target), { recursive: true });
|
|
624
|
+
writeFileSync(temp, text, 'utf8');
|
|
625
|
+
renameSync(temp, target);
|
|
626
|
+
}
|
|
627
|
+
catch (error) {
|
|
628
|
+
// Best effort: a leftover temp file is still a partial artifact on disk.
|
|
629
|
+
try {
|
|
630
|
+
if (existsSync(temp))
|
|
631
|
+
unlinkSync(temp);
|
|
632
|
+
}
|
|
633
|
+
catch {
|
|
634
|
+
/* the original error is the one worth reporting */
|
|
635
|
+
}
|
|
636
|
+
return { ok: false, reason: 'unwritable', detail: `cannot write ${rawPath}: ${error instanceof Error ? error.message : String(error)}` };
|
|
637
|
+
}
|
|
638
|
+
const fromCwd = relative(process.cwd(), target);
|
|
639
|
+
const display = fromCwd !== '' && !fromCwd.startsWith('..') && !isAbsolute(fromCwd) ? fromCwd : target;
|
|
640
|
+
return { ok: true, display };
|
|
641
|
+
}
|
|
642
|
+
/** At most this many registry lookups per run (spec §6 rule 6): a 95-row profile must not fan out. */
|
|
643
|
+
const MAX_REGISTRY_LOOKUPS = 12;
|
|
644
|
+
/**
|
|
645
|
+
* Ask npm for "is there a published build that declares the target?".
|
|
646
|
+
*
|
|
647
|
+
* Secondary evidence only: the caller merges these facts into a second `judgeUpgradeImpact`
|
|
648
|
+
* call where they can only attach annotations (spec §6, N9). A failed lookup is recorded and
|
|
649
|
+
* never changes the exit code.
|
|
650
|
+
*/
|
|
651
|
+
async function registryLookupFor(impact, target, stamp) {
|
|
652
|
+
const wanted = [
|
|
653
|
+
...new Set(impact.units
|
|
654
|
+
.filter((unit) => (unit.bucket === 'would-be-denied' || unit.bucket === 'cannot-tell') && unit.version !== null)
|
|
655
|
+
.map((unit) => unit.name)),
|
|
656
|
+
]
|
|
657
|
+
.sort((left, right) => (left < right ? -1 : left > right ? 1 : 0))
|
|
658
|
+
.slice(0, MAX_REGISTRY_LOOKUPS);
|
|
659
|
+
const facts = [];
|
|
660
|
+
const failures = [];
|
|
661
|
+
for (const name of wanted) {
|
|
662
|
+
const packument = await fetchPackument(name, { at: stamp });
|
|
663
|
+
if (!packument.ok) {
|
|
664
|
+
failures.push({ package: name, code: packument.error.code, detail: packument.error.detail });
|
|
665
|
+
continue;
|
|
666
|
+
}
|
|
667
|
+
const fact = registryFactFor({
|
|
668
|
+
packageName: name,
|
|
669
|
+
versions: packument.value.versions,
|
|
670
|
+
target,
|
|
671
|
+
publishedAt: packument.value.publishedAt,
|
|
672
|
+
});
|
|
673
|
+
if (fact !== null)
|
|
674
|
+
facts.push(fact);
|
|
675
|
+
}
|
|
676
|
+
return { facts, failures };
|
|
677
|
+
}
|
|
678
|
+
/**
|
|
679
|
+
* `upgrade --json`: the impact list, with the per-unit judgement **flattened**.
|
|
680
|
+
*
|
|
681
|
+
* WHY NOT THE NESTED VERDICT: on a 190-row profile the full `Verdict` objects are ~1.8 MB,
|
|
682
|
+
* and every field a reader needs (`reasons`, `remediation`, `missing_evidence`) is already on
|
|
683
|
+
* the unit. The nested object duplicates them a second time. `conclusion` / `evidence_tiers`
|
|
684
|
+
* are copied out of it here, so the payload still says which tier the judgement rests on —
|
|
685
|
+
* and no `Verdict` object means no `profileDir` in a file that is meant to be shareable.
|
|
686
|
+
*/
|
|
687
|
+
function upgradeJsonPayload(impact, distTag) {
|
|
688
|
+
return {
|
|
689
|
+
schema_version: 1,
|
|
690
|
+
command: 'upgrade',
|
|
691
|
+
profile: impact.profile,
|
|
692
|
+
profile_source: impact.profile_source,
|
|
693
|
+
current: impact.current,
|
|
694
|
+
current_valid: impact.current_valid,
|
|
695
|
+
target: impact.target,
|
|
696
|
+
// Where the target came from (M6 C9): an exact version is judged offline; a dist-tag says which
|
|
697
|
+
// word was resolved and against which package, so a reader can re-check the registry themselves.
|
|
698
|
+
target_source: distTag === null ? 'explicit' : 'dist-tag',
|
|
699
|
+
dist_tag: distTag === null ? null : { tag: distTag.tag, version: distTag.version, package: DIST_TAG_PACKAGE },
|
|
700
|
+
target_relation: impact.target_relation,
|
|
701
|
+
buckets: impact.buckets,
|
|
702
|
+
counts: impact.counts,
|
|
703
|
+
registry: impact.registry,
|
|
704
|
+
units: impact.units.map((unit) => {
|
|
705
|
+
const { verdict, ...rest } = unit;
|
|
706
|
+
return {
|
|
707
|
+
...rest,
|
|
708
|
+
conclusion: verdict === null ? null : verdict.conclusion,
|
|
709
|
+
evidence_tiers: verdict === null
|
|
710
|
+
? []
|
|
711
|
+
: [...new Set(verdict.evidence.map((item) => item.tier))].sort((left, right) => (left < right ? -1 : 1)),
|
|
712
|
+
};
|
|
713
|
+
}),
|
|
714
|
+
generated_at: impact.generated_at,
|
|
715
|
+
};
|
|
716
|
+
}
|
|
717
|
+
/**
|
|
718
|
+
* Read an `upgrade --snapshot` file: a frozen **composition** (declarations), not a runtime
|
|
719
|
+
* inventory. `audit --snapshot` reads the latter; the two share a flag name and nothing else.
|
|
720
|
+
*
|
|
721
|
+
* A rejected snapshot never falls back to the live profile: "I could not read your file" and
|
|
722
|
+
* "your profile is fine" are different sentences.
|
|
723
|
+
*/
|
|
724
|
+
function readCompositionSnapshot(path) {
|
|
725
|
+
let raw;
|
|
726
|
+
try {
|
|
727
|
+
raw = JSON.parse(readFileSync(path, 'utf8'));
|
|
728
|
+
}
|
|
729
|
+
catch (error) {
|
|
730
|
+
return { ok: false, detail: `not readable as JSON (${error instanceof Error ? error.message : String(error)})` };
|
|
731
|
+
}
|
|
732
|
+
if (raw === null || typeof raw !== 'object' || Array.isArray(raw)) {
|
|
733
|
+
return { ok: false, detail: 'expected a JSON object' };
|
|
734
|
+
}
|
|
735
|
+
const record = raw;
|
|
736
|
+
if (record['schema_version'] !== 1)
|
|
737
|
+
return { ok: false, detail: 'schema_version must be 1' };
|
|
738
|
+
const profile = record['profile'];
|
|
739
|
+
if (typeof profile !== 'string' || profile.trim() === '') {
|
|
740
|
+
return { ok: false, detail: 'profile must be a non-empty string (the answer belongs to that profile)' };
|
|
741
|
+
}
|
|
742
|
+
const dsh = record['dsh'];
|
|
743
|
+
if (dsh !== undefined && dsh !== null) {
|
|
744
|
+
if (typeof dsh !== 'string' || upgradeTargetProblem(dsh) !== null) {
|
|
745
|
+
return { ok: false, detail: 'dsh must be an exact version string or null' };
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
const rawBundles = record['bundles'];
|
|
749
|
+
if (!Array.isArray(rawBundles))
|
|
750
|
+
return { ok: false, detail: 'bundles must be an array (may be empty)' };
|
|
751
|
+
const bundles = [];
|
|
752
|
+
for (const [index, entry] of rawBundles.entries()) {
|
|
753
|
+
if (entry === null || typeof entry !== 'object')
|
|
754
|
+
return { ok: false, detail: `bundles[${index}] is not an object` };
|
|
755
|
+
const bundle = entry;
|
|
756
|
+
if (typeof bundle['name'] !== 'string' || bundle['name'].trim() === '') {
|
|
757
|
+
return { ok: false, detail: `bundles[${index}].name must be a non-empty string` };
|
|
758
|
+
}
|
|
759
|
+
const manifest = bundle['manifest'];
|
|
760
|
+
if (manifest === undefined)
|
|
761
|
+
return { ok: false, detail: `bundles[${index}].manifest is required (null when unknown)` };
|
|
762
|
+
if (manifest !== null && (typeof manifest !== 'object' || Array.isArray(manifest))) {
|
|
763
|
+
return { ok: false, detail: `bundles[${index}].manifest must be an object or null` };
|
|
764
|
+
}
|
|
765
|
+
const version = bundle['version'];
|
|
766
|
+
if (version !== undefined && version !== null && typeof version !== 'string') {
|
|
767
|
+
return { ok: false, detail: `bundles[${index}].version must be a string or null` };
|
|
768
|
+
}
|
|
769
|
+
bundles.push({ name: bundle['name'], version: version ?? null, manifest });
|
|
770
|
+
}
|
|
771
|
+
const rawRows = record['rows'];
|
|
772
|
+
if (!Array.isArray(rawRows))
|
|
773
|
+
return { ok: false, detail: 'rows must be an array (may be empty)' };
|
|
774
|
+
const rows = [];
|
|
775
|
+
for (const [index, entry] of rawRows.entries()) {
|
|
776
|
+
if (entry === null || typeof entry !== 'object')
|
|
777
|
+
return { ok: false, detail: `rows[${index}] is not an object` };
|
|
778
|
+
const row = entry;
|
|
779
|
+
for (const field of ['rowId', 'module', 'source']) {
|
|
780
|
+
if (typeof row[field] !== 'string' || row[field].trim() === '') {
|
|
781
|
+
return { ok: false, detail: `rows[${index}].${field} must be a non-empty string` };
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
const manifest = row['manifest'];
|
|
785
|
+
if (manifest === undefined)
|
|
786
|
+
return { ok: false, detail: `rows[${index}].manifest is required (null when not installed)` };
|
|
787
|
+
if (manifest !== null && (typeof manifest !== 'object' || Array.isArray(manifest))) {
|
|
788
|
+
return { ok: false, detail: `rows[${index}].manifest must be an object or null` };
|
|
789
|
+
}
|
|
790
|
+
const version = row['version'];
|
|
791
|
+
if (version !== undefined && version !== null && typeof version !== 'string') {
|
|
792
|
+
return { ok: false, detail: `rows[${index}].version must be a string or null` };
|
|
793
|
+
}
|
|
794
|
+
rows.push({
|
|
795
|
+
rowId: row['rowId'],
|
|
796
|
+
module: row['module'],
|
|
797
|
+
source: row['source'],
|
|
798
|
+
version: version ?? null,
|
|
799
|
+
manifest,
|
|
800
|
+
});
|
|
801
|
+
}
|
|
802
|
+
return { ok: true, value: { profile: profile.trim(), dsh: typeof dsh === 'string' ? dsh : null, bundles, rows } };
|
|
803
|
+
}
|
|
355
804
|
async function commandCheck(flags, spec) {
|
|
356
805
|
if (spec === undefined || spec.trim() === '') {
|
|
357
806
|
process.stderr.write('usage: dsh-triage check <pkg[@version]>\n');
|
|
@@ -399,8 +848,27 @@ async function commandCheck(flags, spec) {
|
|
|
399
848
|
registryDrift: drift,
|
|
400
849
|
rangeAdvice: true,
|
|
401
850
|
});
|
|
851
|
+
/*
|
|
852
|
+
* M5-a (spec §7/§9): the verdict exists, so it may be recorded - BEFORE anything is printed
|
|
853
|
+
* and without touching the verdict, the output or the exit code. `recordOutcomes` is a
|
|
854
|
+
* no-op unless the user opted in and never throws (control N14).
|
|
855
|
+
*
|
|
856
|
+
* The prior is read BEFORE the record is appended, so the annotation says "this machine said
|
|
857
|
+
* X before this run" and cannot include the run it is annotating (§10.2: a prior is history,
|
|
858
|
+
* not a self-reference). The prior is only read for `--explain` (control N3: without it the
|
|
859
|
+
* output is byte-identical whether or not a prior exists).
|
|
860
|
+
*/
|
|
861
|
+
const prior = flags.explain ? localPriorFor({ env, packageName: name, version: targetVersion }) : null;
|
|
862
|
+
recordOutcomes({
|
|
863
|
+
source: 'check',
|
|
864
|
+
subjects: [{ verdict, version: targetVersion }],
|
|
865
|
+
at: stamp,
|
|
866
|
+
probe: null,
|
|
867
|
+
flag: flags.outcomes,
|
|
868
|
+
stderr: (line) => process.stderr.write(line),
|
|
869
|
+
});
|
|
402
870
|
if (flags.json) {
|
|
403
|
-
|
|
871
|
+
const payload = {
|
|
404
872
|
schema_version: 1,
|
|
405
873
|
command: 'check',
|
|
406
874
|
verdict: safeVerdicts(flags, [verdict])[0],
|
|
@@ -417,13 +885,20 @@ async function commandCheck(flags, spec) {
|
|
|
417
885
|
detail: drift.detail,
|
|
418
886
|
},
|
|
419
887
|
},
|
|
420
|
-
}
|
|
888
|
+
};
|
|
889
|
+
// A sibling key, never a field of `verdict` (ADR-0011 §4.1).
|
|
890
|
+
if (prior !== null)
|
|
891
|
+
payload['prior'] = prior;
|
|
892
|
+
writeJson(payload);
|
|
421
893
|
return exitFor(flags, [verdict]);
|
|
422
894
|
}
|
|
423
895
|
process.stdout.write(`${renderVerdict(verdict, flags.locale)}\n`);
|
|
424
896
|
if (flags.explain) {
|
|
425
897
|
process.stdout.write(`${renderRegistryExplain(drift, flags.locale)}\n`);
|
|
426
898
|
}
|
|
899
|
+
if (prior !== null) {
|
|
900
|
+
process.stdout.write(renderPrior(prior, flags.locale));
|
|
901
|
+
}
|
|
427
902
|
if (admission.status === 'admitted') {
|
|
428
903
|
process.stdout.write('note declaration passes; runtime behaviour is still unproven (probe lands in M3).\n');
|
|
429
904
|
}
|
|
@@ -479,6 +954,131 @@ function countPresetRows(preset) {
|
|
|
479
954
|
}
|
|
480
955
|
return `${active} active · ${disabled} disabled · ${conditional} conditional · ${other} other`;
|
|
481
956
|
}
|
|
957
|
+
async function commandStatus(flags) {
|
|
958
|
+
const env = await requireEnv(flags);
|
|
959
|
+
if (env === null)
|
|
960
|
+
return EXIT_UNAVAILABLE;
|
|
961
|
+
const dshHome = resolveDshHome(flags);
|
|
962
|
+
const loaded = await loadAuditData({
|
|
963
|
+
env,
|
|
964
|
+
dshHome,
|
|
965
|
+
stamp: stampOf(flags),
|
|
966
|
+
snapshotPath: flags.snapshot,
|
|
967
|
+
noRedact: flags.noRedact,
|
|
968
|
+
});
|
|
969
|
+
if (!loaded.ok) {
|
|
970
|
+
process.stderr.write(`${loaded.message}\n`);
|
|
971
|
+
return EXIT_UNAVAILABLE;
|
|
972
|
+
}
|
|
973
|
+
const summary = buildProfileSummary(loaded.data, { locale: flags.locale });
|
|
974
|
+
// Same exit contract as `audit` (one function, not a second opinion).
|
|
975
|
+
const outcome = auditExitOutcome(loaded.data) === 'ok' ? EXIT_OK : EXIT_FINDINGS;
|
|
976
|
+
if (flags.json) {
|
|
977
|
+
writeJson({
|
|
978
|
+
schema_version: 1,
|
|
979
|
+
command: 'status',
|
|
980
|
+
env: redactedEnv(env, { noRedact: flags.noRedact, roots: auditRedactRoots(dshHome) }),
|
|
981
|
+
...summary,
|
|
982
|
+
});
|
|
983
|
+
return outcome;
|
|
984
|
+
}
|
|
985
|
+
process.stdout.write(formatProfileSummary(summary, { locale: flags.locale, env }));
|
|
986
|
+
return outcome;
|
|
987
|
+
}
|
|
988
|
+
/**
|
|
989
|
+
* `dsh-triage fix` — the autofix surface (M7, `docs/specs/M7-autofix.md`).
|
|
990
|
+
*
|
|
991
|
+
* Prints a plan by default and writes NOTHING. `--apply` writes only the items the plan marked
|
|
992
|
+
* `ready`, backs the file up first, and records a journal so `--undo` can put it back.
|
|
993
|
+
*/
|
|
994
|
+
async function commandFix(flags) {
|
|
995
|
+
if (flags.undo !== null) {
|
|
996
|
+
try {
|
|
997
|
+
const { restored } = undoFix(flags.undo);
|
|
998
|
+
if (flags.json) {
|
|
999
|
+
writeJson({ schema_version: 1, command: 'fix', undo: flags.undo, restored });
|
|
1000
|
+
}
|
|
1001
|
+
else {
|
|
1002
|
+
process.stdout.write(`restored ${restored.length} file(s):\n`);
|
|
1003
|
+
for (const file of restored)
|
|
1004
|
+
process.stdout.write(` ${file}\n`);
|
|
1005
|
+
}
|
|
1006
|
+
return EXIT_OK;
|
|
1007
|
+
}
|
|
1008
|
+
catch (error) {
|
|
1009
|
+
process.stderr.write(`cannot undo: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
1010
|
+
return EXIT_UNAVAILABLE;
|
|
1011
|
+
}
|
|
1012
|
+
}
|
|
1013
|
+
const env = await requireEnv(flags);
|
|
1014
|
+
if (env === null)
|
|
1015
|
+
return EXIT_UNAVAILABLE;
|
|
1016
|
+
const dshHome = resolveDshHome(flags);
|
|
1017
|
+
const loaded = await loadAuditData({
|
|
1018
|
+
env,
|
|
1019
|
+
dshHome,
|
|
1020
|
+
stamp: stampOf(flags),
|
|
1021
|
+
snapshotPath: flags.snapshot,
|
|
1022
|
+
noRedact: flags.noRedact,
|
|
1023
|
+
});
|
|
1024
|
+
if (!loaded.ok) {
|
|
1025
|
+
process.stderr.write(`${loaded.message}\n`);
|
|
1026
|
+
return EXIT_UNAVAILABLE;
|
|
1027
|
+
}
|
|
1028
|
+
const exemptionSupport = runtimeSupportsExemptions(env.profileDir);
|
|
1029
|
+
const plan = planFixes(loaded.data, {
|
|
1030
|
+
exemptionSupport,
|
|
1031
|
+
installable: readProfileDependencies(env.profileDir),
|
|
1032
|
+
});
|
|
1033
|
+
let run = { journal: '', changes: [], skipped: [], dryRun: true };
|
|
1034
|
+
if (flags.apply && plan.applicable > 0) {
|
|
1035
|
+
try {
|
|
1036
|
+
run = applyExemptionFixes(plan, { stamp: stampOf(flags), dryRun: false });
|
|
1037
|
+
}
|
|
1038
|
+
catch (error) {
|
|
1039
|
+
process.stderr.write(`cannot apply: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
1040
|
+
return EXIT_UNAVAILABLE;
|
|
1041
|
+
}
|
|
1042
|
+
}
|
|
1043
|
+
if (flags.json) {
|
|
1044
|
+
// Same rule as every other command: absolute home paths are redacted unless --no-redact.
|
|
1045
|
+
const safePlan = flags.noRedact
|
|
1046
|
+
? plan
|
|
1047
|
+
: { ...plan, profileDir: plan.profileDir.replace(/^[A-Za-z]:\\Users\\[^\\]+/u, '~').replace(/^\/home\/[^/]+/u, '~') };
|
|
1048
|
+
writeJson({ schema_version: 1, command: 'fix', plan: safePlan, run });
|
|
1049
|
+
}
|
|
1050
|
+
else {
|
|
1051
|
+
const zh = flags.locale === 'zh';
|
|
1052
|
+
if (plan.items.length === 0) {
|
|
1053
|
+
process.stdout.write(zh ? '没有需要修复的项。\n' : 'nothing to fix.\n');
|
|
1054
|
+
}
|
|
1055
|
+
else {
|
|
1056
|
+
process.stdout.write(zh ? `可修复 ${plan.applicable} / ${plan.items.length} 项\n` : `${plan.applicable} of ${plan.items.length} fixable\n`);
|
|
1057
|
+
for (const item of plan.items) {
|
|
1058
|
+
const mark = item.status === 'ready' ? '✓' : '·';
|
|
1059
|
+
process.stdout.write(` ${mark} ${item.id} [${item.action}/${item.status}]\n ${item.detail}\n`);
|
|
1060
|
+
if (item.status !== 'ready' && item.command !== null)
|
|
1061
|
+
process.stdout.write(` ${item.command}\n`);
|
|
1062
|
+
}
|
|
1063
|
+
}
|
|
1064
|
+
if (!plan.exemptionSupport) {
|
|
1065
|
+
process.stdout.write(zh
|
|
1066
|
+
? `\n本机运行时(dsh ${plan.runtime ?? '?'})不读取 compatibility.json,因此豁免类修复不可用。\n`
|
|
1067
|
+
: `\nthis runtime (dsh ${plan.runtime ?? '?'}) does not read compatibility.json, so exemptions cannot be applied here.\n`);
|
|
1068
|
+
}
|
|
1069
|
+
if (run.dryRun) {
|
|
1070
|
+
if (plan.applicable > 0) {
|
|
1071
|
+
process.stdout.write(zh ? '\n只出了计划,没有写任何文件。要执行:dsh-triage fix --apply\n' : '\nplan only — nothing was written. To apply: dsh-triage fix --apply\n');
|
|
1072
|
+
}
|
|
1073
|
+
}
|
|
1074
|
+
else {
|
|
1075
|
+
process.stdout.write(zh ? `\n已写入 ${run.changes.length} 处,撤销:dsh-triage fix --undo ${run.journal}\n` : `\nwrote ${run.changes.length} change(s); undo with: dsh-triage fix --undo ${run.journal}\n`);
|
|
1076
|
+
}
|
|
1077
|
+
}
|
|
1078
|
+
if (plan.items.length === 0)
|
|
1079
|
+
return EXIT_OK;
|
|
1080
|
+
return run.dryRun ? EXIT_FINDINGS : plan.applicable === run.changes.length ? EXIT_OK : EXIT_FINDINGS;
|
|
1081
|
+
}
|
|
482
1082
|
async function commandAudit(flags) {
|
|
483
1083
|
const env = await requireEnv(flags);
|
|
484
1084
|
if (env === null)
|
|
@@ -504,7 +1104,15 @@ async function commandAudit(flags) {
|
|
|
504
1104
|
writeJson(auditJsonPayload(data, { noRedact: flags.noRedact, roots: auditRedactRoots(dshHome) }));
|
|
505
1105
|
return auditExitOutcome(data) === 'ok' ? EXIT_OK : EXIT_FINDINGS;
|
|
506
1106
|
}
|
|
507
|
-
|
|
1107
|
+
// R49: the human answer first. The ledger below is the evidence, and it is one flag away
|
|
1108
|
+
// (`--all`) instead of being the only thing between the user and their answer.
|
|
1109
|
+
const summary = buildProfileSummary(data, { locale: flags.locale });
|
|
1110
|
+
process.stdout.write(formatProfileSummary(summary, { locale: flags.locale, env }));
|
|
1111
|
+
if (!flags.all) {
|
|
1112
|
+
process.stdout.write('\n(full ledger behind --all; `audit --json` carries every field)\n');
|
|
1113
|
+
return auditExitOutcome(data) === 'ok' ? EXIT_OK : EXIT_FINDINGS;
|
|
1114
|
+
}
|
|
1115
|
+
process.stdout.write(`\ncapability ledger · dsh ${env.dsh ?? 'unknown'} · profile ${env.profile}\n`);
|
|
508
1116
|
for (const [source, list] of grouped) {
|
|
509
1117
|
process.stdout.write(`\n${source} (${list.length} rows)\n`);
|
|
510
1118
|
for (const claim of list) {
|
|
@@ -708,6 +1316,23 @@ async function commandProbe(flags, spec) {
|
|
|
708
1316
|
};
|
|
709
1317
|
const verdict = probeVerdict({ run, judgement, env, at: stamp });
|
|
710
1318
|
const roots = [homedir(), dshHome, probeScratchRoot()];
|
|
1319
|
+
/*
|
|
1320
|
+
* M5-a (spec §9): a `probe --execute` records exactly one outcome. The candidate's EXACT
|
|
1321
|
+
* version is the key, so a spec that does not name one (a local path, a tag) is skipped
|
|
1322
|
+
* rather than guessed. Sum of step durations is the only "total" the run actually measures.
|
|
1323
|
+
*/
|
|
1324
|
+
recordOutcomes({
|
|
1325
|
+
source: 'probe',
|
|
1326
|
+
subjects: [{ verdict, version: exactVersionOfSpec(spec) }],
|
|
1327
|
+
at: stamp,
|
|
1328
|
+
probe: {
|
|
1329
|
+
totalMs: run.steps.reduce((sum, step) => sum + (Number.isFinite(step.ms) ? step.ms : 0), 0),
|
|
1330
|
+
bootMs: run.timings.bootToSampleMs,
|
|
1331
|
+
profile: plan.value.profile,
|
|
1332
|
+
},
|
|
1333
|
+
flag: flags.outcomes,
|
|
1334
|
+
stderr: (line) => process.stderr.write(line),
|
|
1335
|
+
});
|
|
711
1336
|
if (flags.json) {
|
|
712
1337
|
writeJson({
|
|
713
1338
|
schema_version: 1,
|
|
@@ -763,10 +1388,12 @@ async function commandProbe(flags, spec) {
|
|
|
763
1388
|
async function commandServe(flags) {
|
|
764
1389
|
const resultsDir = flags.results === null ? resolve(process.cwd(), 'data/results') : resolve(flags.results);
|
|
765
1390
|
const dshHome = resolveDshHome(flags);
|
|
766
|
-
//
|
|
767
|
-
//
|
|
768
|
-
|
|
769
|
-
|
|
1391
|
+
// R49: the panel's whole purpose is the current composition, so it reads the profile by
|
|
1392
|
+
// default. `--no-audit` keeps the old artifacts-only mode (and `/api/audit` answers 501,
|
|
1393
|
+
// never an empty ledger that looks clean).
|
|
1394
|
+
const audit = flags.noAudit
|
|
1395
|
+
? null
|
|
1396
|
+
: async () => {
|
|
770
1397
|
const loadedEnv = await loadEnv({ dshHome, profile: flags.profile });
|
|
771
1398
|
if (!loadedEnv.ok) {
|
|
772
1399
|
return { ok: false, message: `cannot read the profile: ${loadedEnv.error.code} — ${loadedEnv.error.detail}` };
|
|
@@ -785,9 +1412,12 @@ async function commandServe(flags) {
|
|
|
785
1412
|
return {
|
|
786
1413
|
ok: true,
|
|
787
1414
|
payload: auditJsonPayload(loaded.data, { noRedact: false, roots: auditRedactRoots(dshHome) }),
|
|
1415
|
+
// Same object the CLI's first screen prints, from the same scan.
|
|
1416
|
+
// The panel has room the terminal does not: show more than the CLI's default so
|
|
1417
|
+
// "show all" in the UI is not a lie. The counts are unaffected by the cap.
|
|
1418
|
+
summary: buildProfileSummary(loaded.data, { locale: flags.locale, limit: 50 }),
|
|
788
1419
|
};
|
|
789
|
-
}
|
|
790
|
-
: null;
|
|
1420
|
+
};
|
|
791
1421
|
const panel = await startPanel({
|
|
792
1422
|
resultsDir,
|
|
793
1423
|
port: flags.port ?? 0,
|
|
@@ -824,8 +1454,75 @@ async function commandServe(flags) {
|
|
|
824
1454
|
return EXIT_OK;
|
|
825
1455
|
}
|
|
826
1456
|
/* -------------------------------- helpers -------------------------------- */
|
|
827
|
-
|
|
828
|
-
|
|
1457
|
+
/**
|
|
1458
|
+
* `outcomes` — the local store's three verbs (M5-a, spec §7 / §11).
|
|
1459
|
+
*
|
|
1460
|
+
* `--purge` deliberately needs no opt-in: deleting must always be possible, and it must never
|
|
1461
|
+
* be the thing that creates the directory (control N5). Text output carries counts only - no
|
|
1462
|
+
* record, no package name, no path (control N13).
|
|
1463
|
+
*/
|
|
1464
|
+
async function commandOutcomes(flags) {
|
|
1465
|
+
const at = stampOf(flags);
|
|
1466
|
+
const verbs = [flags.enable, flags.disable, flags.purge].filter(Boolean).length;
|
|
1467
|
+
if (verbs > 1) {
|
|
1468
|
+
process.stderr.write('usage: dsh-triage outcomes [--status | --enable | --disable | --purge]\n');
|
|
1469
|
+
return EXIT_USAGE;
|
|
1470
|
+
}
|
|
1471
|
+
if (flags.purge) {
|
|
1472
|
+
const result = purgeOutcomes({ at });
|
|
1473
|
+
if (!result.ok) {
|
|
1474
|
+
process.stderr.write(`cannot purge the outcome store (${result.detail}); nothing was reported as deleted\n`);
|
|
1475
|
+
return EXIT_FINDINGS;
|
|
1476
|
+
}
|
|
1477
|
+
if (flags.json)
|
|
1478
|
+
writeJson(result.report);
|
|
1479
|
+
else
|
|
1480
|
+
process.stdout.write(renderPurge(result.report));
|
|
1481
|
+
return EXIT_OK;
|
|
1482
|
+
}
|
|
1483
|
+
if (flags.enable || flags.disable) {
|
|
1484
|
+
const mode = flags.enable ? 'local' : 'off';
|
|
1485
|
+
const written = writeOutcomeMode(mode);
|
|
1486
|
+
if (!written.ok) {
|
|
1487
|
+
process.stderr.write(`cannot write the outcome config (${written.detail})\n`);
|
|
1488
|
+
return EXIT_FINDINGS;
|
|
1489
|
+
}
|
|
1490
|
+
if (flags.json) {
|
|
1491
|
+
writeJson({ schema_version: 1, mode, changed: written.changed });
|
|
1492
|
+
}
|
|
1493
|
+
else {
|
|
1494
|
+
process.stdout.write(`outcomes ${mode}${written.changed ? '' : ' (already set)'}\n`);
|
|
1495
|
+
}
|
|
1496
|
+
return EXIT_OK;
|
|
1497
|
+
}
|
|
1498
|
+
// `--status` is the default verb: "how much is actually stored right now".
|
|
1499
|
+
const reading = readOutcomeConfig();
|
|
1500
|
+
for (const problem of reading.problems)
|
|
1501
|
+
process.stderr.write(`outcomes: off (${problem})\n`);
|
|
1502
|
+
const report = outcomeStatus({});
|
|
1503
|
+
if (flags.json)
|
|
1504
|
+
writeJson(report);
|
|
1505
|
+
else
|
|
1506
|
+
process.stdout.write(renderStatus(report));
|
|
1507
|
+
return EXIT_OK;
|
|
1508
|
+
}
|
|
1509
|
+
/**
|
|
1510
|
+
* The exact version a probe candidate pins, or `null`.
|
|
1511
|
+
*
|
|
1512
|
+
* WHY NOT ASK THE REGISTRY: a record's key must be the version that was actually installed, and
|
|
1513
|
+
* a spec without a version cannot state it. Guessing `latest` would file the measurement under
|
|
1514
|
+
* a build that may already be replaced, so the caller skips the record instead.
|
|
1515
|
+
*/
|
|
1516
|
+
function exactVersionOfSpec(spec) {
|
|
1517
|
+
const trimmed = spec.trim();
|
|
1518
|
+
const at = trimmed.lastIndexOf('@');
|
|
1519
|
+
if (at <= 0)
|
|
1520
|
+
return null;
|
|
1521
|
+
const version = trimmed.slice(at + 1);
|
|
1522
|
+
return /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/.test(version) ? version : null;
|
|
1523
|
+
}
|
|
1524
|
+
async function requireEnv(flags, dshHomeOverride) {
|
|
1525
|
+
const result = await loadEnv({ dshHome: dshHomeOverride ?? resolveDshHome(flags), profile: flags.profile });
|
|
829
1526
|
if (!result.ok) {
|
|
830
1527
|
process.stderr.write(`cannot read the profile: ${result.error.code} — ${result.error.detail}\n`);
|
|
831
1528
|
if (result.error.code === 'profile-not-found') {
|
|
@@ -937,10 +1634,21 @@ function parseArgs(argv) {
|
|
|
937
1634
|
let results = null;
|
|
938
1635
|
let out = null;
|
|
939
1636
|
let allowExecute = false;
|
|
1637
|
+
let apply = false;
|
|
1638
|
+
let undo = null;
|
|
940
1639
|
let audit = false;
|
|
1640
|
+
let noAudit = false;
|
|
941
1641
|
let readinessTimeoutMs = null;
|
|
942
1642
|
let unsettledReadinessMs = null;
|
|
943
1643
|
let copyProfile = null;
|
|
1644
|
+
let outcomes = null;
|
|
1645
|
+
let enable = false;
|
|
1646
|
+
let disable = false;
|
|
1647
|
+
let purge = false;
|
|
1648
|
+
let status = false;
|
|
1649
|
+
let to = null;
|
|
1650
|
+
let registry = false;
|
|
1651
|
+
let card = false;
|
|
944
1652
|
for (let index = 0; index < argv.length; index += 1) {
|
|
945
1653
|
const token = argv[index];
|
|
946
1654
|
if (token === undefined)
|
|
@@ -981,6 +1689,16 @@ function parseArgs(argv) {
|
|
|
981
1689
|
case '--explain':
|
|
982
1690
|
explain = true;
|
|
983
1691
|
break;
|
|
1692
|
+
case '--apply':
|
|
1693
|
+
apply = true;
|
|
1694
|
+
break;
|
|
1695
|
+
case '--undo': {
|
|
1696
|
+
const value = takeValue();
|
|
1697
|
+
if (value === null)
|
|
1698
|
+
return null;
|
|
1699
|
+
undo = value;
|
|
1700
|
+
break;
|
|
1701
|
+
}
|
|
984
1702
|
case '--help':
|
|
985
1703
|
case '-h':
|
|
986
1704
|
help = true;
|
|
@@ -1058,6 +1776,9 @@ function parseArgs(argv) {
|
|
|
1058
1776
|
case '--audit':
|
|
1059
1777
|
audit = true;
|
|
1060
1778
|
break;
|
|
1779
|
+
case '--no-audit':
|
|
1780
|
+
noAudit = true;
|
|
1781
|
+
break;
|
|
1061
1782
|
case '--readiness-timeout': {
|
|
1062
1783
|
const value = takeValue();
|
|
1063
1784
|
if (value === null)
|
|
@@ -1085,6 +1806,38 @@ function parseArgs(argv) {
|
|
|
1085
1806
|
copyProfile = value;
|
|
1086
1807
|
break;
|
|
1087
1808
|
}
|
|
1809
|
+
case '--outcomes': {
|
|
1810
|
+
const value = takeValue();
|
|
1811
|
+
if (value !== 'off' && value !== 'local')
|
|
1812
|
+
return null;
|
|
1813
|
+
outcomes = value;
|
|
1814
|
+
break;
|
|
1815
|
+
}
|
|
1816
|
+
case '--enable':
|
|
1817
|
+
enable = true;
|
|
1818
|
+
break;
|
|
1819
|
+
case '--disable':
|
|
1820
|
+
disable = true;
|
|
1821
|
+
break;
|
|
1822
|
+
case '--purge':
|
|
1823
|
+
purge = true;
|
|
1824
|
+
break;
|
|
1825
|
+
case '--status':
|
|
1826
|
+
status = true;
|
|
1827
|
+
break;
|
|
1828
|
+
case '--to': {
|
|
1829
|
+
const value = takeValue();
|
|
1830
|
+
if (value === null)
|
|
1831
|
+
return null;
|
|
1832
|
+
to = value;
|
|
1833
|
+
break;
|
|
1834
|
+
}
|
|
1835
|
+
case '--registry':
|
|
1836
|
+
registry = true;
|
|
1837
|
+
break;
|
|
1838
|
+
case '--card':
|
|
1839
|
+
card = true;
|
|
1840
|
+
break;
|
|
1088
1841
|
case '--locale': {
|
|
1089
1842
|
const value = takeValue();
|
|
1090
1843
|
if (value !== 'en' && value !== 'zh')
|
|
@@ -1096,10 +1849,11 @@ function parseArgs(argv) {
|
|
|
1096
1849
|
return null;
|
|
1097
1850
|
}
|
|
1098
1851
|
}
|
|
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 };
|
|
1852
|
+
const flags = { json, all, strict, execute, dshHome, profile, stamp, locale, noRedact, snapshot, explain, dshMain, noHttp, browser, port, results, allowExecute, apply, undo, audit, noAudit, readinessTimeoutMs, unsettledReadinessMs, copyProfile, profileExplicit, out, outcomes, enable, disable, purge, status, to, registry, card };
|
|
1100
1853
|
if (help)
|
|
1101
1854
|
return { command: 'help', positionals: [], flags };
|
|
1102
|
-
|
|
1855
|
+
// R49: no subcommand is not an error. It is the question the product exists to answer.
|
|
1856
|
+
const command = positionals.shift() ?? 'status';
|
|
1103
1857
|
return { command, positionals, flags };
|
|
1104
1858
|
}
|
|
1105
1859
|
function splitFlag(token) {
|