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/fix.js
ADDED
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Autofix (M7).
|
|
3
|
+
*
|
|
4
|
+
* The product's job used to stop at "here is what is wrong". This module is the part that
|
|
5
|
+
* actually changes the profile — so it is written the way a tool that edits someone's install
|
|
6
|
+
* has to be:
|
|
7
|
+
*
|
|
8
|
+
* - **plan first, always**: `planFixes()` is pure (no disk, no network) and returns data, so the
|
|
9
|
+
* CLI, the panel and the tests all read the same plan;
|
|
10
|
+
* - **only one write exists today**: an exact-version exemption in the profile's
|
|
11
|
+
* `compatibility.json`, in the *same format upstream writes* (2-space JSON, sorted keys, one
|
|
12
|
+
* trailing newline, `0600`), and only when the installed runtime actually reads that file —
|
|
13
|
+
* `runtimeSupportsExemptions()` proves it by finding the implementation, not by hoping;
|
|
14
|
+
* - **every write is undoable**: the previous bytes are copied next to the journal before the
|
|
15
|
+
* atomic replace, and `undoFix()` restores them byte-for-byte;
|
|
16
|
+
* - **it refuses more than it does**: a version that is not canonical SemVer, a package whose
|
|
17
|
+
* install shape we do not know, a compatibility file we did not write and cannot parse — all
|
|
18
|
+
* refused with a reason. Widening a plugin's own `engines.dsh` (the fastest "fix" and a lie to
|
|
19
|
+
* the loader) is deliberately absent; see `docs/specs/M7-autofix.md` §1 C.
|
|
20
|
+
*/
|
|
21
|
+
import { isExactExemptionVersion as coreIsExactVersion } from '@dsh-triage/core';
|
|
22
|
+
import { copyFileSync, existsSync, mkdirSync, readFileSync, renameSync, rmSync, statSync, writeFileSync } from 'node:fs';
|
|
23
|
+
import { dirname, join } from 'node:path';
|
|
24
|
+
import { readProfileExemptions as readCompatibilityFile } from '@dsh-triage/core';
|
|
25
|
+
/* ------------------------------- detection -------------------------------- */
|
|
26
|
+
/**
|
|
27
|
+
* Does this profile's runtime read `compatibility.json`?
|
|
28
|
+
*
|
|
29
|
+
* Proven by the implementation being present, not by the version number: 0.2.x ships
|
|
30
|
+
* `@deepseek-ai/dsh-app-boot` with `setProfileVersionExemption`, 0.1.0-rc.6 ships nothing of the
|
|
31
|
+
* kind (checked by searching every installed `@deepseek-ai` package). A version comparison would
|
|
32
|
+
* be a guess; a missing implementation is a fact.
|
|
33
|
+
*/
|
|
34
|
+
export function runtimeSupportsExemptions(profileDir) {
|
|
35
|
+
const roots = [join(profileDir, 'node_modules'), join(dirname(profileDir), 'node_modules')];
|
|
36
|
+
for (const root of roots) {
|
|
37
|
+
const boot = join(root, '@deepseek-ai', 'dsh-app-boot', 'lib', 'index.js');
|
|
38
|
+
if (!existsSync(boot))
|
|
39
|
+
continue;
|
|
40
|
+
try {
|
|
41
|
+
const text = readFileSync(boot, 'utf8');
|
|
42
|
+
if (text.includes('compatibility.json') && text.includes('setProfileVersionExemption'))
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
// An unreadable runtime is treated as "does not support", never as "supports".
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
/* --------------------------------- plan ----------------------------------- */
|
|
52
|
+
/**
|
|
53
|
+
* Build the plan. Pure: the same `AuditData` yields the same plan, with no clock and no I/O.
|
|
54
|
+
*
|
|
55
|
+
* `installable` is the set of package names the profile lists in `dependencies` — the only
|
|
56
|
+
* packages whose install shape we can honestly claim to know. Everything else is planned as
|
|
57
|
+
* "you have to do this by hand", with the reason stated.
|
|
58
|
+
*/
|
|
59
|
+
export function planFixes(data, options) {
|
|
60
|
+
const runtime = data.env.dsh;
|
|
61
|
+
const installable = options.installable === undefined || options.installable === null ? [] : options.installable;
|
|
62
|
+
const items = [];
|
|
63
|
+
for (const verdict of data.rowVerdicts) {
|
|
64
|
+
if (verdict.conclusion !== 'blocked' && verdict.conclusion !== 'risky')
|
|
65
|
+
continue;
|
|
66
|
+
const name = verdict.subject.name;
|
|
67
|
+
const version = verdict.subject.version;
|
|
68
|
+
const packageVersion = version === null ? null : `${name}@${version}`;
|
|
69
|
+
const allowCommand = verdict.remediation.find((entry) => entry.kind === 'allow-version')?.command ??
|
|
70
|
+
(runtime === null ? null : `dsh plugin --profile ${data.env.profile} allow-version ${packageVersion ?? name} --dsh-version ${runtime} --accept-risk`);
|
|
71
|
+
if (options.exemptionSupport) {
|
|
72
|
+
items.push({
|
|
73
|
+
id: name,
|
|
74
|
+
action: 'exemption',
|
|
75
|
+
status: version === null ? 'unknown-version' : runtime === null ? 'unknown-version' : 'ready',
|
|
76
|
+
detail: version === null || runtime === null
|
|
77
|
+
? 'The exact package version or the runtime version is unknown, so an exemption cannot name it.'
|
|
78
|
+
: `Record an exemption for ${packageVersion} on dsh ${runtime}. This bypasses the declaration only — behaviour is still unproven.`,
|
|
79
|
+
packageVersion: version === null ? null : packageVersion,
|
|
80
|
+
command: allowCommand,
|
|
81
|
+
});
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
const canInstall = installable.includes(name);
|
|
85
|
+
items.push({
|
|
86
|
+
id: name,
|
|
87
|
+
action: 'pin',
|
|
88
|
+
status: version === null ? 'unknown-version' : canInstall ? 'no-compatible-version' : 'unknown-install-shape',
|
|
89
|
+
detail: version === null
|
|
90
|
+
? 'The installed version could not be read, so there is nothing to pin.'
|
|
91
|
+
: canInstall
|
|
92
|
+
? 'This runtime does not read exemptions, so the only real fix is a plugin version that declares support for it. No such version was resolved.'
|
|
93
|
+
: `${name} is not in the profile's dependencies, so this tool does not know how it was installed.`,
|
|
94
|
+
packageVersion: version === null ? null : packageVersion,
|
|
95
|
+
command: allowCommand,
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
return {
|
|
99
|
+
profileDir: data.env.profileDir,
|
|
100
|
+
runtime,
|
|
101
|
+
exemptionSupport: options.exemptionSupport,
|
|
102
|
+
items,
|
|
103
|
+
applicable: items.filter((item) => item.status === 'ready').length,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
const COMPAT_FILE = 'compatibility.json';
|
|
107
|
+
/** A filesystem-safe form of an ISO stamp: Windows cannot create a directory named "10:30". */
|
|
108
|
+
export function safeStamp(stamp) {
|
|
109
|
+
return stamp.replace(/:/g, '-');
|
|
110
|
+
}
|
|
111
|
+
/** Refuse anything that is not a canonical exact SemVer — the rule lives in core, not here. */
|
|
112
|
+
export const isExactVersion = coreIsExactVersion;
|
|
113
|
+
/** `name@version` where the version is exact. Throws otherwise; never guesses. */
|
|
114
|
+
export function parsePackageVersion(value) {
|
|
115
|
+
const at = value.lastIndexOf('@');
|
|
116
|
+
if (at <= 0)
|
|
117
|
+
throw new Error(`exemption keys are name@version; got "${value}"`);
|
|
118
|
+
const name = value.slice(0, at);
|
|
119
|
+
const version = value.slice(at + 1);
|
|
120
|
+
if (!/^(?:@[a-z0-9][a-z0-9._-]*\/)?[a-z0-9][a-z0-9._-]*$/.test(name))
|
|
121
|
+
throw new Error(`not an npm package name: "${name}"`);
|
|
122
|
+
if (!isExactVersion(version))
|
|
123
|
+
throw new Error(`not an exact version: "${version}"`);
|
|
124
|
+
return { name, version };
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Write the exemption and prove it: backup → atomic replace → read back.
|
|
128
|
+
*
|
|
129
|
+
* `dryRun` is the default at the CLI, and it writes **nothing at all** (not even a backup), so a
|
|
130
|
+
* preview can never leave a trace.
|
|
131
|
+
*/
|
|
132
|
+
export function applyExemptionFixes(plan, options) {
|
|
133
|
+
const ready = plan.items.filter((item) => item.status === 'ready' && item.packageVersion !== null);
|
|
134
|
+
const skipped = plan.items
|
|
135
|
+
.filter((item) => item.status !== 'ready')
|
|
136
|
+
.map((item) => ({ id: item.id, reason: item.status }));
|
|
137
|
+
if (options.dryRun || ready.length === 0) {
|
|
138
|
+
return { journal: '', changes: [], skipped, dryRun: true };
|
|
139
|
+
}
|
|
140
|
+
if (plan.runtime === null)
|
|
141
|
+
throw new Error('the runtime version is unknown; an exemption must name an exact runtime');
|
|
142
|
+
const file = join(plan.profileDir, COMPAT_FILE);
|
|
143
|
+
const current = readCompatibilityFile(plan.profileDir);
|
|
144
|
+
if (!current.rewritable) {
|
|
145
|
+
throw new Error(`${file} was not written by this tool and cannot be parsed; refusing to rewrite it (fix it by hand first)`);
|
|
146
|
+
}
|
|
147
|
+
const journalDir = join(plan.profileDir, '.dsh-triage', 'journal');
|
|
148
|
+
mkdirSync(journalDir, { recursive: true });
|
|
149
|
+
const base = safeStamp(options.stamp);
|
|
150
|
+
let runName = base;
|
|
151
|
+
for (let n = 2; existsSync(join(journalDir, `${runName}.json`)); n += 1)
|
|
152
|
+
runName = `${base}-${n}`;
|
|
153
|
+
const dir = join(plan.profileDir, '.dsh-triage', 'backups', runName);
|
|
154
|
+
mkdirSync(dir, { recursive: true });
|
|
155
|
+
const changes = [];
|
|
156
|
+
const next = {};
|
|
157
|
+
for (const [key, value] of Object.entries(current.exemptions))
|
|
158
|
+
next[key] = [...value];
|
|
159
|
+
for (const item of ready) {
|
|
160
|
+
const packageVersion = item.packageVersion;
|
|
161
|
+
parsePackageVersion(packageVersion);
|
|
162
|
+
const versions = next[packageVersion] ?? [];
|
|
163
|
+
const merged = [...new Set([...versions, plan.runtime])].sort();
|
|
164
|
+
next[packageVersion] = merged;
|
|
165
|
+
changes.push({
|
|
166
|
+
action: 'exemption',
|
|
167
|
+
packageVersion,
|
|
168
|
+
runtime: plan.runtime,
|
|
169
|
+
file,
|
|
170
|
+
before: existsSync(file) ? readFileSync(file, 'utf8') : null,
|
|
171
|
+
after: serialize(next),
|
|
172
|
+
backup: '',
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
const before = existsSync(file) ? readFileSync(file, 'utf8') : null;
|
|
176
|
+
const backupPath = join(dir, COMPAT_FILE);
|
|
177
|
+
if (before !== null)
|
|
178
|
+
copyFileSync(file, backupPath);
|
|
179
|
+
atomicWrite(file, serialize(next));
|
|
180
|
+
const after = readFileSync(file, 'utf8');
|
|
181
|
+
const verified = readCompatibilityFile(plan.profileDir);
|
|
182
|
+
if (!verified.rewritable)
|
|
183
|
+
throw new Error(`${file} could not be read back after writing; the profile may need manual repair`);
|
|
184
|
+
const journalPath = join(journalDir, `${runName}.json`);
|
|
185
|
+
const journal = {
|
|
186
|
+
schema_version: 1,
|
|
187
|
+
produced_by: 'packages/plugin/src/fix.ts',
|
|
188
|
+
generated_at: options.stamp,
|
|
189
|
+
profile_dir: plan.profileDir,
|
|
190
|
+
backup_dir: dir,
|
|
191
|
+
changes: changes.map((change) => ({
|
|
192
|
+
file: change.file,
|
|
193
|
+
backup: join(dir, COMPAT_FILE),
|
|
194
|
+
before: change.before,
|
|
195
|
+
after: change.after,
|
|
196
|
+
})),
|
|
197
|
+
};
|
|
198
|
+
writeFileSync(journalPath, `${JSON.stringify(journal, null, 2)}\n`, 'utf8');
|
|
199
|
+
return {
|
|
200
|
+
journal: journalPath,
|
|
201
|
+
changes: changes.map((change) => ({ ...change, after, backup: join(dir, COMPAT_FILE) })),
|
|
202
|
+
skipped,
|
|
203
|
+
dryRun: false,
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
/** Put every file back exactly as it was. Unknown/edited files are refused, not overwritten. */
|
|
207
|
+
export function undoFix(journalPath) {
|
|
208
|
+
const journal = JSON.parse(readFileSync(journalPath, 'utf8'));
|
|
209
|
+
if (journal.schema_version !== 1)
|
|
210
|
+
throw new Error(`unsupported journal schema: ${String(journal.schema_version)}`);
|
|
211
|
+
const restored = [];
|
|
212
|
+
for (const change of journal.changes) {
|
|
213
|
+
if (change.before === null) {
|
|
214
|
+
if (existsSync(change.file))
|
|
215
|
+
rmSync(change.file, { force: true });
|
|
216
|
+
restored.push(change.file);
|
|
217
|
+
continue;
|
|
218
|
+
}
|
|
219
|
+
if (!existsSync(change.backup))
|
|
220
|
+
throw new Error(`backup is missing: ${change.backup}`);
|
|
221
|
+
const current = existsSync(change.file) ? readFileSync(change.file, 'utf8') : null;
|
|
222
|
+
if (current !== change.after) {
|
|
223
|
+
throw new Error(`${change.file} changed after this journal was written; refusing to overwrite it`);
|
|
224
|
+
}
|
|
225
|
+
copyFileSync(change.backup, change.file);
|
|
226
|
+
restored.push(change.file);
|
|
227
|
+
}
|
|
228
|
+
return { restored };
|
|
229
|
+
}
|
|
230
|
+
/** Kept for callers and tests: the parser itself lives in core (`readProfileExemptions`). */
|
|
231
|
+
export function readCompatibility(profileDir) {
|
|
232
|
+
const reading = readCompatibilityFile(profileDir);
|
|
233
|
+
return { exemptions: reading.exemptions, rewritable: reading.rewritable };
|
|
234
|
+
}
|
|
235
|
+
/* -------------------------------- helpers --------------------------------- */
|
|
236
|
+
function serialize(exemptions) {
|
|
237
|
+
const sorted = {};
|
|
238
|
+
for (const key of Object.keys(exemptions).sort())
|
|
239
|
+
sorted[key] = [...(exemptions[key] ?? [])];
|
|
240
|
+
return `${JSON.stringify(sorted, undefined, 2)}\n`;
|
|
241
|
+
}
|
|
242
|
+
/** Temp file in the same directory, then rename: a crash never leaves a half-written file. */
|
|
243
|
+
function atomicWrite(file, text) {
|
|
244
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
245
|
+
const temp = `${file}.tmp-${process.pid}-${Date.now()}`;
|
|
246
|
+
writeFileSync(temp, text, { encoding: 'utf8', mode: 0o600 });
|
|
247
|
+
try {
|
|
248
|
+
if (existsSync(file))
|
|
249
|
+
statSync(file);
|
|
250
|
+
renameSync(temp, file);
|
|
251
|
+
}
|
|
252
|
+
catch (error) {
|
|
253
|
+
rmSync(temp, { force: true });
|
|
254
|
+
throw error;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
/** Package names the profile lists as its own dependencies — the only install shapes we know. */
|
|
258
|
+
export function readProfileDependencies(profileDir) {
|
|
259
|
+
try {
|
|
260
|
+
const manifest = JSON.parse(readFileSync(join(profileDir, 'package.json'), 'utf8'));
|
|
261
|
+
return [...Object.keys(manifest.dependencies ?? {}), ...Object.keys(manifest.devDependencies ?? {})];
|
|
262
|
+
}
|
|
263
|
+
catch {
|
|
264
|
+
return [];
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
//# sourceMappingURL=fix.js.map
|
package/dist/fix.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fix.js","sourceRoot":"","sources":["../src/fix.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAE,uBAAuB,IAAI,kBAAkB,EAAE,MAAM,kBAAkB,CAAA;AAChF,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,SAAS,EAAE,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IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,IAAI,CAAC,UAAU,EAAE,cAAc,CAAC,EAAE,MAAM,CAAC,CAGjF,CAAA;QACD,OAAO,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,YAAY,IAAI,EAAE,CAAC,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,eAAe,IAAI,EAAE,CAAC,CAAC,CAAA;IACtG,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,CAAA;IACX,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where the local outcome store lives, and whether it is switched on (spec §7 / §8).
|
|
3
|
+
*
|
|
4
|
+
* THREE RULES THIS FILE EXISTS FOR:
|
|
5
|
+
* 1. **default off** means nothing is created - not the directory, not the file, not an
|
|
6
|
+
* mtime. `readOutcomeConfig` therefore only ever *reads*, and a missing store is not an
|
|
7
|
+
* error (control N1 / N5).
|
|
8
|
+
* 2. **fail closed**: an empty/relative `%LOCALAPPDATA%`, an unreadable `config.json`, or an
|
|
9
|
+
* `outcomes` value outside the enum all mean `off`. A broken config is never "on"
|
|
10
|
+
* (control N10).
|
|
11
|
+
* 3. **no environment variable turns recording on.** The only switches are the config file
|
|
12
|
+
* and an explicit per-command flag; `%LOCALAPPDATA%` decides *where* the store is, not
|
|
13
|
+
* *whether* we write. An env-driven opt-in would explain "why did it start recording?"
|
|
14
|
+
* only to whoever happens to see the CI log.
|
|
15
|
+
*
|
|
16
|
+
* No network client is imported here, and none may ever be (spec §12, gate `outcome-privacy`).
|
|
17
|
+
*/
|
|
18
|
+
export type OutcomeMode = 'off' | 'local';
|
|
19
|
+
/** The directory name under the platform's local data dir. Never under `~/.dsh` (§8). */
|
|
20
|
+
export declare const STORE_DIR_NAME = "dsh-triage";
|
|
21
|
+
export declare const CONFIG_FILE = "config.json";
|
|
22
|
+
export declare const OUTCOMES_FILE = "outcomes.jsonl";
|
|
23
|
+
/** Scratch name for the atomic replace. Deleted by `outcomes --purge` like any owned file. */
|
|
24
|
+
export declare const CONFIG_TMP_FILE = "config.json.tmp";
|
|
25
|
+
/**
|
|
26
|
+
* Every file this tool may create inside the store.
|
|
27
|
+
*
|
|
28
|
+
* WHY A LIST AND NOT A HARD-CODED DELETE ORDER: purge enumerates the directory and deletes
|
|
29
|
+
* what it owns, so "a file we forgot to delete" is impossible as long as the writer and this
|
|
30
|
+
* list change together - and anything NOT in this list is reported in `remaining[]` instead
|
|
31
|
+
* of being destroyed (the user may have put their own notes there, §11).
|
|
32
|
+
*/
|
|
33
|
+
export declare const STORE_OWNED_FILES: readonly string[];
|
|
34
|
+
export type StoreLocationProblem = 'no-local-data-dir' | 'relative-local-data-dir' | 'unavailable';
|
|
35
|
+
export type StoreLocation = {
|
|
36
|
+
readonly ok: true;
|
|
37
|
+
readonly root: string;
|
|
38
|
+
} | {
|
|
39
|
+
readonly ok: false;
|
|
40
|
+
readonly problem: StoreLocationProblem;
|
|
41
|
+
readonly detail: string;
|
|
42
|
+
};
|
|
43
|
+
export interface OutcomeConfigReading {
|
|
44
|
+
readonly mode: OutcomeMode;
|
|
45
|
+
/** Where the mode came from. `flag` and `config` are explicit; `default` is "off, silently". */
|
|
46
|
+
readonly source: 'flag' | 'config' | 'default' | 'invalid-config' | 'no-store';
|
|
47
|
+
readonly root: string | null;
|
|
48
|
+
/** Human-readable, path-free problems. Empty when nothing is wrong. */
|
|
49
|
+
readonly problems: readonly string[];
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Resolve the store root for the given platform.
|
|
53
|
+
*
|
|
54
|
+
* win32 uses `%LOCALAPPDATA%` and NOT `%APPDATA%`: roaming profiles sync to a domain server,
|
|
55
|
+
* which would put a second copy of the user's outcome log somewhere we do not control.
|
|
56
|
+
*/
|
|
57
|
+
export declare function resolveStoreRoot(env?: Readonly<Record<string, string | undefined>>, platform?: string): StoreLocation;
|
|
58
|
+
export declare function configPathOf(root: string): string;
|
|
59
|
+
export declare function outcomesPathOf(root: string): string;
|
|
60
|
+
/**
|
|
61
|
+
* Read the opt-in switch. Never throws, never creates anything.
|
|
62
|
+
*
|
|
63
|
+
* `problems` is empty in the normal "no config file yet, therefore off" case, because a
|
|
64
|
+
* default-off run must not print anything at all (control N1). It carries a line only when
|
|
65
|
+
* the user's environment or config is actually broken (control N10).
|
|
66
|
+
*/
|
|
67
|
+
export declare function readOutcomeConfig(env?: Readonly<Record<string, string | undefined>>, platform?: string): OutcomeConfigReading;
|
|
68
|
+
/**
|
|
69
|
+
* The effective mode: command-line flag > `config.json` > default `off` (§7).
|
|
70
|
+
*
|
|
71
|
+
* The flag is per-invocation only; nothing here writes.
|
|
72
|
+
*/
|
|
73
|
+
export declare function effectiveOutcomeMode(options: {
|
|
74
|
+
readonly flag: OutcomeMode | null;
|
|
75
|
+
readonly env?: Readonly<Record<string, string | undefined>>;
|
|
76
|
+
readonly platform?: string;
|
|
77
|
+
}): OutcomeConfigReading;
|
|
78
|
+
export type ConfigWriteResult = {
|
|
79
|
+
readonly ok: true;
|
|
80
|
+
readonly changed: boolean;
|
|
81
|
+
readonly root: string;
|
|
82
|
+
} | {
|
|
83
|
+
readonly ok: false;
|
|
84
|
+
readonly detail: string;
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* Write the switch atomically (temp file + rename).
|
|
88
|
+
*
|
|
89
|
+
* Idempotent on purpose: re-enabling an already-enabled store does not rewrite the file, so
|
|
90
|
+
* its mtime stays put (spec §7: "已开会再写一次同样的内容"). This is also what makes
|
|
91
|
+
* `--enable && --disable` a no-op pair for anything that watches the file.
|
|
92
|
+
*/
|
|
93
|
+
export declare function writeOutcomeMode(mode: OutcomeMode, env?: Readonly<Record<string, string | undefined>>, platform?: string): ConfigWriteResult;
|
|
94
|
+
/** `EPERM` / `ENOSPC` / ... - a code, never a path (the message carries the path). */
|
|
95
|
+
export declare function errorCodeOf(error: unknown): string;
|
|
96
|
+
//# sourceMappingUR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@@ -0,0 +1,175 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where the local outcome store lives, and whether it is switched on (spec §7 / §8).
|
|
3
|
+
*
|
|
4
|
+
* THREE RULES THIS FILE EXISTS FOR:
|
|
5
|
+
* 1. **default off** means nothing is created - not the directory, not the file, not an
|
|
6
|
+
* mtime. `readOutcomeConfig` therefore only ever *reads*, and a missing store is not an
|
|
7
|
+
* error (control N1 / N5).
|
|
8
|
+
* 2. **fail closed**: an empty/relative `%LOCALAPPDATA%`, an unreadable `config.json`, or an
|
|
9
|
+
* `outcomes` value outside the enum all mean `off`. A broken config is never "on"
|
|
10
|
+
* (control N10).
|
|
11
|
+
* 3. **no environment variable turns recording on.** The only switches are the config file
|
|
12
|
+
* and an explicit per-command flag; `%LOCALAPPDATA%` decides *where* the store is, not
|
|
13
|
+
* *whether* we write. An env-driven opt-in would explain "why did it start recording?"
|
|
14
|
+
* only to whoever happens to see the CI log.
|
|
15
|
+
*
|
|
16
|
+
* No network client is imported here, and none may ever be (spec §12, gate `outcome-privacy`).
|
|
17
|
+
*/
|
|
18
|
+
import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs';
|
|
19
|
+
import { isAbsolute, join } from 'node:path';
|
|
20
|
+
import process from 'node:process';
|
|
21
|
+
/** The directory name under the platform's local data dir. Never under `~/.dsh` (§8). */
|
|
22
|
+
export const STORE_DIR_NAME = 'dsh-triage';
|
|
23
|
+
export const CONFIG_FILE = 'config.json';
|
|
24
|
+
export const OUTCOMES_FILE = 'outcomes.jsonl';
|
|
25
|
+
/** Scratch name for the atomic replace. Deleted by `outcomes --purge` like any owned file. */
|
|
26
|
+
export const CONFIG_TMP_FILE = 'config.json.tmp';
|
|
27
|
+
/**
|
|
28
|
+
* Every file this tool may create inside the store.
|
|
29
|
+
*
|
|
30
|
+
* WHY A LIST AND NOT A HARD-CODED DELETE ORDER: purge enumerates the directory and deletes
|
|
31
|
+
* what it owns, so "a file we forgot to delete" is impossible as long as the writer and this
|
|
32
|
+
* list change together - and anything NOT in this list is reported in `remaining[]` instead
|
|
33
|
+
* of being destroyed (the user may have put their own notes there, §11).
|
|
34
|
+
*/
|
|
35
|
+
export const STORE_OWNED_FILES = [CONFIG_FILE, CONFIG_TMP_FILE, OUTCOMES_FILE];
|
|
36
|
+
const isNonEmptyString = (value) => typeof value === 'string' && value.trim() !== '';
|
|
37
|
+
/**
|
|
38
|
+
* Resolve the store root for the given platform.
|
|
39
|
+
*
|
|
40
|
+
* win32 uses `%LOCALAPPDATA%` and NOT `%APPDATA%`: roaming profiles sync to a domain server,
|
|
41
|
+
* which would put a second copy of the user's outcome log somewhere we do not control.
|
|
42
|
+
*/
|
|
43
|
+
export function resolveStoreRoot(env = process.env, platform = process.platform) {
|
|
44
|
+
if (platform === 'win32') {
|
|
45
|
+
const localAppData = env['LOCALAPPDATA'];
|
|
46
|
+
if (!isNonEmptyString(localAppData)) {
|
|
47
|
+
return { ok: false, problem: 'no-local-data-dir', detail: 'LOCALAPPDATA is empty' };
|
|
48
|
+
}
|
|
49
|
+
if (!isAbsolute(localAppData)) {
|
|
50
|
+
return { ok: false, problem: 'relative-local-data-dir', detail: 'LOCALAPPDATA is not an absolute path' };
|
|
51
|
+
}
|
|
52
|
+
return { ok: true, root: join(localAppData, STORE_DIR_NAME) };
|
|
53
|
+
}
|
|
54
|
+
const xdg = env['XDG_DATA_HOME'];
|
|
55
|
+
if (isNonEmptyString(xdg)) {
|
|
56
|
+
if (!isAbsolute(xdg)) {
|
|
57
|
+
return { ok: false, problem: 'relative-local-data-dir', detail: 'XDG_DATA_HOME is not an absolute path' };
|
|
58
|
+
}
|
|
59
|
+
return { ok: true, root: join(xdg, STORE_DIR_NAME) };
|
|
60
|
+
}
|
|
61
|
+
const home = env['HOME'];
|
|
62
|
+
if (!isNonEmptyString(home)) {
|
|
63
|
+
return { ok: false, problem: 'no-local-data-dir', detail: 'HOME is empty' };
|
|
64
|
+
}
|
|
65
|
+
if (!isAbsolute(home)) {
|
|
66
|
+
return { ok: false, problem: 'relative-local-data-dir', detail: 'HOME is not an absolute path' };
|
|
67
|
+
}
|
|
68
|
+
return { ok: true, root: join(home, '.local', 'share', STORE_DIR_NAME) };
|
|
69
|
+
}
|
|
70
|
+
export function configPathOf(root) {
|
|
71
|
+
return join(root, CONFIG_FILE);
|
|
72
|
+
}
|
|
73
|
+
export function outcomesPathOf(root) {
|
|
74
|
+
return join(root, OUTCOMES_FILE);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Read the opt-in switch. Never throws, never creates anything.
|
|
78
|
+
*
|
|
79
|
+
* `problems` is empty in the normal "no config file yet, therefore off" case, because a
|
|
80
|
+
* default-off run must not print anything at all (control N1). It carries a line only when
|
|
81
|
+
* the user's environment or config is actually broken (control N10).
|
|
82
|
+
*/
|
|
83
|
+
export function readOutcomeConfig(env = process.env, platform = process.platform) {
|
|
84
|
+
const located = resolveStoreRoot(env, platform);
|
|
85
|
+
if (!located.ok) {
|
|
86
|
+
return { mode: 'off', source: 'no-store', root: null, problems: [located.detail] };
|
|
87
|
+
}
|
|
88
|
+
const path = configPathOf(located.root);
|
|
89
|
+
let text;
|
|
90
|
+
try {
|
|
91
|
+
text = readFileSync(path, 'utf8');
|
|
92
|
+
}
|
|
93
|
+
catch {
|
|
94
|
+
// No config file (or no permission to read it) ⇒ off. Deliberately silent: "off by
|
|
95
|
+
// default" is the normal state, not a problem to report on every command.
|
|
96
|
+
return { mode: 'off', source: 'default', root: located.root, problems: [] };
|
|
97
|
+
}
|
|
98
|
+
let parsed;
|
|
99
|
+
try {
|
|
100
|
+
parsed = JSON.parse(text.replace(/^\uFEFF/, ''));
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
return { mode: 'off', source: 'invalid-config', root: located.root, problems: [`${CONFIG_FILE} is not valid JSON`] };
|
|
104
|
+
}
|
|
105
|
+
if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed)) {
|
|
106
|
+
return { mode: 'off', source: 'invalid-config', root: located.root, problems: [`${CONFIG_FILE} is not a JSON object`] };
|
|
107
|
+
}
|
|
108
|
+
const record = parsed;
|
|
109
|
+
const unknownKeys = Object.keys(record).filter((key) => !['schema_version', 'outcomes'].includes(key));
|
|
110
|
+
if (unknownKeys.length > 0) {
|
|
111
|
+
return {
|
|
112
|
+
mode: 'off',
|
|
113
|
+
source: 'invalid-config',
|
|
114
|
+
root: located.root,
|
|
115
|
+
problems: [`${CONFIG_FILE} has an unknown field (${unknownKeys[0]})`],
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
if (record['schema_version'] !== 1) {
|
|
119
|
+
return { mode: 'off', source: 'invalid-config', root: located.root, problems: [`${CONFIG_FILE} has an unsupported schema_version`] };
|
|
120
|
+
}
|
|
121
|
+
const value = record['outcomes'];
|
|
122
|
+
if (value !== 'off' && value !== 'local') {
|
|
123
|
+
return { mode: 'off', source: 'invalid-config', root: located.root, problems: [`${CONFIG_FILE} has an outcomes value outside {off, local}`] };
|
|
124
|
+
}
|
|
125
|
+
return { mode: value, source: 'config', root: located.root, problems: [] };
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* The effective mode: command-line flag > `config.json` > default `off` (§7).
|
|
129
|
+
*
|
|
130
|
+
* The flag is per-invocation only; nothing here writes.
|
|
131
|
+
*/
|
|
132
|
+
export function effectiveOutcomeMode(options) {
|
|
133
|
+
const reading = readOutcomeConfig(options.env ?? process.env, options.platform ?? process.platform);
|
|
134
|
+
if (options.flag === null)
|
|
135
|
+
return reading;
|
|
136
|
+
return { ...reading, mode: options.flag, source: 'flag' };
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Write the switch atomically (temp file + rename).
|
|
140
|
+
*
|
|
141
|
+
* Idempotent on purpose: re-enabling an already-enabled store does not rewrite the file, so
|
|
142
|
+
* its mtime stays put (spec §7: "已开会再写一次同样的内容"). This is also what makes
|
|
143
|
+
* `--enable && --disable` a no-op pair for anything that watches the file.
|
|
144
|
+
*/
|
|
145
|
+
export function writeOutcomeMode(mode, env = process.env, platform = process.platform) {
|
|
146
|
+
const located = resolveStoreRoot(env, platform);
|
|
147
|
+
if (!located.ok)
|
|
148
|
+
return { ok: false, detail: located.detail };
|
|
149
|
+
const path = configPathOf(located.root);
|
|
150
|
+
const payload = { schema_version: 1, outcomes: mode };
|
|
151
|
+
const text = `${JSON.stringify(payload)}\n`;
|
|
152
|
+
try {
|
|
153
|
+
if (existsSync(path) && readFileSync(path, 'utf8') === text) {
|
|
154
|
+
return { ok: true, changed: false, root: located.root };
|
|
155
|
+
}
|
|
156
|
+
mkdirSync(located.root, { recursive: true });
|
|
157
|
+
const tmp = join(located.root, CONFIG_TMP_FILE);
|
|
158
|
+
writeFileSync(tmp, text, 'utf8');
|
|
159
|
+
renameSync(tmp, path);
|
|
160
|
+
return { ok: true, changed: true, root: located.root };
|
|
161
|
+
}
|
|
162
|
+
catch (error) {
|
|
163
|
+
return { ok: false, detail: errorCodeOf(error) };
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
/** `EPERM` / `ENOSPC` / ... - a code, never a path (the message carries the path). */
|
|
167
|
+
export function errorCodeOf(error) {
|
|
168
|
+
if (typeof error === 'object' && error !== null) {
|
|
169
|
+
const code = error.code;
|
|
170
|
+
if (typeof code === 'string' && code !== '')
|
|
171
|
+
return code;
|
|
172
|
+
}
|
|
173
|
+
return 'unknown-error';
|
|
174
|
+
}
|
|
175
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/outcomes/config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AACxF,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAC5C,OAAO,OAAO,MAAM,cAAc,CAAA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,IAAI,EAAE,MAAM,CAAC,CAAA;QAChC,UAAU,CAAC,GAAG,EAAE,IAAI,CAAC,CAAA;QACrB,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,CAAA;IACxD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,WAAW,CAAC,KAAK,CAAC,EAAE,CAAA;IAClD,CAAC;AACH,CAAC;AAED,sFAAsF;AACtF,MAAM,UAAU,WAAW,CAAC,KAAc;IACxC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QAChD,MAAM,IAAI,GAAI,KAA4B,CAAC,IAAI,CAAA;QAC/C,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,EAAE;YAAE,OAAO,IAAI,CAAA;IAC1D,CAAC;IACD,OAAO,eAAe,CAAA;AACxB,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `prior` annotation for `check --explain` (spec §10, `ADR-0011` option A).
|
|
3
|
+
*
|
|
4
|
+
* WHY THIS FILE EXISTS AT ALL: to keep the prior in one place that produces a SIBLING object
|
|
5
|
+
* of the verdict. It does not take a verdict, does not return one, and cannot change one.
|
|
6
|
+
* `check --json` (without `--explain`) never calls into this module, which is what makes the
|
|
7
|
+
* "with a prior / without a prior" outputs byte-identical (control N3).
|
|
8
|
+
*
|
|
9
|
+
* FAILURE POLICY: a store that cannot be read means "no prior", not an error. Recording is
|
|
10
|
+
* best-effort, so reading it back must be too - a broken local library may never turn a
|
|
11
|
+
* working `check` into a failing one (same discipline as N14).
|
|
12
|
+
*
|
|
13
|
+
* No network client is imported here, and none may ever be (spec §12).
|
|
14
|
+
*/
|
|
15
|
+
import { type EnvFingerprint, type Locale, type LocalPrior } from '@dsh-triage/core';
|
|
16
|
+
/**
|
|
17
|
+
* The prior for the exact key this run judged, or `null` when there is nothing to say.
|
|
18
|
+
*
|
|
19
|
+
* Both "no prior" cases (`n = 0`, incomplete key) come back as `null`, and the caller then
|
|
20
|
+
* OMITS the `prior` key entirely: "nothing" must not be rendered as `null` or `{}` (§10.2).
|
|
21
|
+
*/
|
|
22
|
+
export declare function localPriorFor(options: {
|
|
23
|
+
readonly env: EnvFingerprint;
|
|
24
|
+
readonly packageName: string;
|
|
25
|
+
readonly version: string;
|
|
26
|
+
readonly processEnv?: Readonly<Record<string, string | undefined>>;
|
|
27
|
+
readonly platform?: string;
|
|
28
|
+
}): LocalPrior | null;
|
|
29
|
+
/**
|
|
30
|
+
* One `explain` line: what this machine said about the exact key before, and the sentence
|
|
31
|
+
* that stops a reader from treating it as evidence.
|
|
32
|
+
*/
|
|
33
|
+
export declare function renderPrior(prior: LocalPrior, locale: Locale): string;
|
|
34
|
+
//# sourceMappingURL=prior.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prior.d.ts","sourceRoot":"","sources":["../../src/outcomes/prior.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAGH,OAAO,EAAyC,KAAK,cAAc,EAAE,KAAK,MAAM,EAAE,KAAK,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAI3H;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE;IACrC,QAAQ,CAAC,GAAG,EAAE,cAAc,CAAA;IAC5B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAA;IAC5B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;IACxB,QAAQ,CAAC,UAAU,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,CAAA;IAClE,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAC3B,GAAG,UAAU,GAAG,IAAI,CAapB;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAQrE"}
|