dsh-triage 0.3.3 → 0.3.5
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/README.md +13 -13
- package/client.js +96 -29
- package/dist/audit-data.d.ts +1 -0
- package/dist/audit-data.d.ts.map +1 -1
- package/dist/audit-data.js +6 -1
- package/dist/audit-data.js.map +1 -1
- package/dist/cli.js +269 -11
- package/dist/cli.js.map +1 -1
- package/dist/host-allow.d.ts +41 -0
- package/dist/host-allow.d.ts.map +1 -0
- package/dist/host-allow.js +79 -0
- package/dist/host-allow.js.map +1 -0
- package/dist/host-audit-route.d.ts +25 -0
- package/dist/host-audit-route.d.ts.map +1 -1
- package/dist/host-audit-route.js +47 -9
- package/dist/host-audit-route.js.map +1 -1
- package/dist/host-summary-route.d.ts.map +1 -1
- package/dist/host-summary-route.js +2 -7
- package/dist/host-summary-route.js.map +1 -1
- package/dist/host-upgrade-route.d.ts.map +1 -1
- package/dist/host-upgrade-route.js +2 -7
- package/dist/host-upgrade-route.js.map +1 -1
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +4 -0
- package/dist/host.js.map +1 -1
- package/dist/load.d.ts +18 -0
- package/dist/load.d.ts.map +1 -1
- package/dist/load.js +41 -8
- package/dist/load.js.map +1 -1
- package/dist/rescue.d.ts +156 -0
- package/dist/rescue.d.ts.map +1 -0
- package/dist/rescue.js +271 -0
- package/dist/rescue.js.map +1 -0
- package/dist/serve.d.ts +38 -1
- package/dist/serve.d.ts.map +1 -1
- package/dist/serve.js +114 -28
- package/dist/serve.js.map +1 -1
- package/dist/summary.d.ts +13 -0
- package/dist/summary.d.ts.map +1 -1
- package/dist/summary.js +17 -1
- package/dist/summary.js.map +1 -1
- package/package.json +4 -4
package/dist/rescue.d.ts
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rescue (M8) — "the host will not start, what is the smallest reversible thing I can try?"
|
|
3
|
+
*
|
|
4
|
+
* WHY THIS MODULE EXISTS: every other command in this package reads the profile and answers a
|
|
5
|
+
* question. This one is the first that is *about* changing it, and the project's rule for that is
|
|
6
|
+
* the same one `fix` follows: **the plan is the product, the write is a separate permission**.
|
|
7
|
+
*
|
|
8
|
+
* WHAT IT ANSWERS (A 段, this build): which entries of `dsh.profile.bundles` are third-party, which
|
|
9
|
+
* ones are listed but not installed, and what a rescue would trim. Nothing is written.
|
|
10
|
+
*
|
|
11
|
+
* WHAT IT REFUSES TO SAY: that trimming them makes the host start. That is a runtime question and
|
|
12
|
+
* only `probe --execute` can answer it; the CLI says so in the same breath (spec C5).
|
|
13
|
+
*
|
|
14
|
+
* THREE ORIGINS, NEVER TWO: `unresolved` is not a flavour of `third-party`. The first means the
|
|
15
|
+
* file and the disk disagree; the second means the package is not ours. Merging them lets one
|
|
16
|
+
* sentence ("you have 3 third-party bundles") describe two different failures.
|
|
17
|
+
*
|
|
18
|
+
* PURE / IMPURE SPLIT: `classifyBundles()` takes everything as input and touches nothing, so the
|
|
19
|
+
* plan is reproducible byte for byte (C1). `readProfileBundles()` is the only function that reads
|
|
20
|
+
* disk, and it reads exactly one file: `<profile>/package.json`.
|
|
21
|
+
*/
|
|
22
|
+
export type BundleOrigin = 'official' | 'third-party' | 'unresolved';
|
|
23
|
+
export interface DeclaredBundle {
|
|
24
|
+
readonly name: string;
|
|
25
|
+
/** Verbatim value from the profile's `dependencies`, or `null` when it is not listed there. */
|
|
26
|
+
readonly spec: string | null;
|
|
27
|
+
}
|
|
28
|
+
export interface InstalledReading {
|
|
29
|
+
readonly name: string;
|
|
30
|
+
readonly version: string | null;
|
|
31
|
+
}
|
|
32
|
+
export interface RescueEntry {
|
|
33
|
+
readonly name: string;
|
|
34
|
+
readonly spec: string | null;
|
|
35
|
+
readonly version: string | null;
|
|
36
|
+
readonly origin: BundleOrigin;
|
|
37
|
+
/** Whether a rescue would take it out of `dsh.profile.bundles`. */
|
|
38
|
+
readonly removable: boolean;
|
|
39
|
+
/** One sentence for a human. Never a code, never a claim about booting. */
|
|
40
|
+
readonly detail: string;
|
|
41
|
+
/** How to put it back: its index in the declared list plus the verbatim entry. */
|
|
42
|
+
readonly restore: {
|
|
43
|
+
readonly at: number;
|
|
44
|
+
readonly entry: string;
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
export interface RescuePlan {
|
|
48
|
+
/** C7: this is read off the profile (`scanned`), never `declared`. */
|
|
49
|
+
readonly evidence: 'scanned';
|
|
50
|
+
readonly profile: string;
|
|
51
|
+
/** sha256 of the manifest **as read**. If it changes, something wrote (C4). */
|
|
52
|
+
readonly manifestSha256: string;
|
|
53
|
+
/** Every declared bundle, in declared order. */
|
|
54
|
+
readonly bundles: readonly RescueEntry[];
|
|
55
|
+
readonly removable: readonly RescueEntry[];
|
|
56
|
+
readonly thirdParty: number;
|
|
57
|
+
readonly unresolved: number;
|
|
58
|
+
readonly empty: boolean;
|
|
59
|
+
/** `absent` and `empty` are different facts and get different sentences (C6 / N6). */
|
|
60
|
+
readonly field: 'present' | 'empty' | 'absent';
|
|
61
|
+
}
|
|
62
|
+
export interface ClassifyInput {
|
|
63
|
+
readonly profile: string;
|
|
64
|
+
readonly declared: readonly DeclaredBundle[];
|
|
65
|
+
readonly installed: readonly InstalledReading[];
|
|
66
|
+
readonly manifestSha256: string;
|
|
67
|
+
readonly field?: 'present' | 'empty' | 'absent';
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Pure: the whole answer is a function of the four inputs. No clock, no network, no disk.
|
|
71
|
+
*
|
|
72
|
+
* Order of the rules matters and is the only judgement in this function:
|
|
73
|
+
* 1. not installed on disk -> `unresolved` (the file and the disk disagree; that is not "third-party")
|
|
74
|
+
* 2. local install shape -> `third-party` (your code, whatever the scope says)
|
|
75
|
+
* 3. official scope -> `official`
|
|
76
|
+
* 4. anything else -> `third-party`
|
|
77
|
+
*/
|
|
78
|
+
export declare function classifyBundles(input: ClassifyInput): RescuePlan;
|
|
79
|
+
export type ProfileBundlesReading = {
|
|
80
|
+
readonly ok: true;
|
|
81
|
+
readonly declared: readonly DeclaredBundle[];
|
|
82
|
+
readonly manifestSha256: string;
|
|
83
|
+
readonly field: 'present' | 'empty' | 'absent';
|
|
84
|
+
} | {
|
|
85
|
+
readonly ok: false;
|
|
86
|
+
readonly reason: string;
|
|
87
|
+
};
|
|
88
|
+
/**
|
|
89
|
+
* Read exactly one file: `<profile>/package.json`.
|
|
90
|
+
*
|
|
91
|
+
* Returns `ok:false` (never throws) so the CLI can report "cannot read the profile" as a distinct
|
|
92
|
+
* outcome from "nothing to trim" — the two are different answers and only one of them is good news.
|
|
93
|
+
*/
|
|
94
|
+
export declare function readProfileBundles(profileDir: string): ProfileBundlesReading;
|
|
95
|
+
/**
|
|
96
|
+
* B 段: the one write this tool performs on a profile, and the reason it is written this way.
|
|
97
|
+
*
|
|
98
|
+
* - **only `dsh.profile.bundles`** changes; `dependencies` is copied verbatim, so "undo" stays an
|
|
99
|
+
* array edit instead of a reinstall (spec §3 rule 3);
|
|
100
|
+
* - **backup → atomic replace → read back → journal**, in that order; a failure at any point puts
|
|
101
|
+
* the original bytes back before the error escapes;
|
|
102
|
+
* - **the journal carries before/after sha256**, so `undoRescue` can refuse to overwrite a profile
|
|
103
|
+
* the user edited in the meantime instead of quietly discarding their change.
|
|
104
|
+
*/
|
|
105
|
+
export interface RescueChange {
|
|
106
|
+
readonly file: string;
|
|
107
|
+
readonly before: string | null;
|
|
108
|
+
readonly after: string;
|
|
109
|
+
readonly backup: string | null;
|
|
110
|
+
readonly removed: readonly {
|
|
111
|
+
readonly name: string;
|
|
112
|
+
readonly at: number;
|
|
113
|
+
}[];
|
|
114
|
+
}
|
|
115
|
+
export interface RescueRun {
|
|
116
|
+
readonly journal: string;
|
|
117
|
+
readonly backupDir: string | null;
|
|
118
|
+
readonly changes: readonly RescueChange[];
|
|
119
|
+
readonly removed: readonly string[];
|
|
120
|
+
readonly dryRun: boolean;
|
|
121
|
+
}
|
|
122
|
+
export interface ApplyRescueInput {
|
|
123
|
+
readonly plan: RescuePlan;
|
|
124
|
+
readonly profileDir: string;
|
|
125
|
+
readonly stamp: string;
|
|
126
|
+
readonly dryRun: boolean;
|
|
127
|
+
/**
|
|
128
|
+
* Test seam, called **after** the backup exists and **before** the atomic write. Throwing here
|
|
129
|
+
* is how "a failed apply must roll back" is proven without pretending to be the disk.
|
|
130
|
+
*/
|
|
131
|
+
readonly beforeWrite?: () => void;
|
|
132
|
+
/**
|
|
133
|
+
* Test seam, called **after** the atomic write and **before** the read-back verification. This is
|
|
134
|
+
* the failure that matters: the file has already changed, so only a rollback can save it.
|
|
135
|
+
*/
|
|
136
|
+
readonly afterWrite?: () => void;
|
|
137
|
+
}
|
|
138
|
+
/** Windows cannot create a directory named `10:30`, so the stamp is made filesystem-safe. */
|
|
139
|
+
export declare function safeStamp(stamp: string): string;
|
|
140
|
+
/**
|
|
141
|
+
* Take the removable entries out of `dsh.profile.bundles`.
|
|
142
|
+
*
|
|
143
|
+
* `dryRun` (the CLI default) writes **nothing at all** — no directory, no backup, no journal — so a
|
|
144
|
+
* preview can never leave a trace (C4 still holds after B 段).
|
|
145
|
+
*/
|
|
146
|
+
export declare function applyRescue(input: ApplyRescueInput): RescueRun;
|
|
147
|
+
/**
|
|
148
|
+
* Put the manifest back byte for byte.
|
|
149
|
+
*
|
|
150
|
+
* Refuses when the current bytes are not the ones this journal produced: someone edited the profile
|
|
151
|
+
* after the rescue, and overwriting that edit would be a second, silent change (N11).
|
|
152
|
+
*/
|
|
153
|
+
export declare function undoRescue(journalPath: string): {
|
|
154
|
+
readonly restored: readonly string[];
|
|
155
|
+
};
|
|
156
|
+
//# sourceMappingURL=rescue.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rescue.d.ts","sourceRoot":"","sources":["../src/rescue.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAMH,MAAM,MAAM,YAAY,GAAG,UAAU,GAAG,aAAa,GAAG,Y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AE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;KAAE,EAAE,CAAA;CAC5E;AAED,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;IACxB,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAA;IACjC,QAAQ,CAAC,OAAO,EAAE,SAAS,YAAY,EAAE,CAAA;IACzC,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAA;IACnC,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAA;CACzB;AAED,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAA;IACzB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;IAC3B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAA;IACxB;;;OAGG;IACH,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,IAAI,CAAA;IACjC;;;OAGG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,IAAI,CAAA;CACjC;AAiBD,6FAA6F;AAC7F,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE/C;AAyBD;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,gBAAgB,GAAG,SAAS,CAkF9D;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,WAAW,EAAE,MAAM,GAAG;IAAE,QAAQ,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAA;CAAE,CAexF"}
|
package/dist/rescue.js
ADDED
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rescue (M8) — "the host will not start, what is the smallest reversible thing I can try?"
|
|
3
|
+
*
|
|
4
|
+
* WHY THIS MODULE EXISTS: every other command in this package reads the profile and answers a
|
|
5
|
+
* question. This one is the first that is *about* changing it, and the project's rule for that is
|
|
6
|
+
* the same one `fix` follows: **the plan is the product, the write is a separate permission**.
|
|
7
|
+
*
|
|
8
|
+
* WHAT IT ANSWERS (A 段, this build): which entries of `dsh.profile.bundles` are third-party, which
|
|
9
|
+
* ones are listed but not installed, and what a rescue would trim. Nothing is written.
|
|
10
|
+
*
|
|
11
|
+
* WHAT IT REFUSES TO SAY: that trimming them makes the host start. That is a runtime question and
|
|
12
|
+
* only `probe --execute` can answer it; the CLI says so in the same breath (spec C5).
|
|
13
|
+
*
|
|
14
|
+
* THREE ORIGINS, NEVER TWO: `unresolved` is not a flavour of `third-party`. The first means the
|
|
15
|
+
* file and the disk disagree; the second means the package is not ours. Merging them lets one
|
|
16
|
+
* sentence ("you have 3 third-party bundles") describe two different failures.
|
|
17
|
+
*
|
|
18
|
+
* PURE / IMPURE SPLIT: `classifyBundles()` takes everything as input and touches nothing, so the
|
|
19
|
+
* plan is reproducible byte for byte (C1). `readProfileBundles()` is the only function that reads
|
|
20
|
+
* disk, and it reads exactly one file: `<profile>/package.json`.
|
|
21
|
+
*/
|
|
22
|
+
import { createHash } from 'node:crypto';
|
|
23
|
+
import { copyFileSync, existsSync, mkdirSync, readFileSync, renameSync, rmSync, statSync, writeFileSync } from 'node:fs';
|
|
24
|
+
import { dirname, join } from 'node:path';
|
|
25
|
+
/* ------------------------------- classification ------------------------------- */
|
|
26
|
+
/**
|
|
27
|
+
* A dependency value that points at this disk instead of a registry.
|
|
28
|
+
*
|
|
29
|
+
* `workspace:` is included because a workspace bundle is the user's code even when the name is
|
|
30
|
+
* scoped `@deepseek-ai/...` — the scope says who named it, the spec says where it came from.
|
|
31
|
+
*/
|
|
32
|
+
const LOCAL_SPEC = /^(?:link:|file:|workspace:|portal:|\.{0,2}[\\/]|[A-Za-z]:[\\/])/;
|
|
33
|
+
const OFFICIAL_SCOPE = '@deepseek-ai/';
|
|
34
|
+
/**
|
|
35
|
+
* Pure: the whole answer is a function of the four inputs. No clock, no network, no disk.
|
|
36
|
+
*
|
|
37
|
+
* Order of the rules matters and is the only judgement in this function:
|
|
38
|
+
* 1. not installed on disk -> `unresolved` (the file and the disk disagree; that is not "third-party")
|
|
39
|
+
* 2. local install shape -> `third-party` (your code, whatever the scope says)
|
|
40
|
+
* 3. official scope -> `official`
|
|
41
|
+
* 4. anything else -> `third-party`
|
|
42
|
+
*/
|
|
43
|
+
export function classifyBundles(input) {
|
|
44
|
+
const versions = new Map(input.installed.map((reading) => [reading.name, reading.version]));
|
|
45
|
+
const bundles = input.declared.map((declared, index) => {
|
|
46
|
+
const version = versions.get(declared.name) ?? null;
|
|
47
|
+
const local = declared.spec !== null && LOCAL_SPEC.test(declared.spec);
|
|
48
|
+
const official = declared.name.startsWith(OFFICIAL_SCOPE) && !local;
|
|
49
|
+
const origin = version === null ? 'unresolved' : official ? 'official' : 'third-party';
|
|
50
|
+
/*
|
|
51
|
+
* An official-scope bundle we cannot resolve is REPORTED, never trimmed: the likeliest cause is
|
|
52
|
+
* our own resolver not understanding the layout (a non-hoisted store, a nested copy), and
|
|
53
|
+
* "trim the core bundle because we could not find it" is the single most destructive thing this
|
|
54
|
+
* command could do. A third-party bundle that is not installed is different: the file already
|
|
55
|
+
* disagrees with the disk, and putting the line back is one `--undo` away.
|
|
56
|
+
*/
|
|
57
|
+
const removable = origin === 'third-party' || (origin === 'unresolved' && !official);
|
|
58
|
+
const detail = origin === 'unresolved'
|
|
59
|
+
? official
|
|
60
|
+
? 'Listed in dsh.profile.bundles but not installed under this profile, and it is an official bundle: reported only — check the install before trimming a core bundle.'
|
|
61
|
+
: 'Listed in dsh.profile.bundles but not installed under this profile: trimming it makes the file match the disk.'
|
|
62
|
+
: origin === 'official'
|
|
63
|
+
? 'Official bundle: outside what a rescue would trim.'
|
|
64
|
+
: local
|
|
65
|
+
? 'Installed from a local path, so it is your own code: reversible to trim, and the first thing to try when the host will not start.'
|
|
66
|
+
: 'Third-party bundle: reversible to trim, and the first thing to try when the host will not start.';
|
|
67
|
+
return {
|
|
68
|
+
name: declared.name,
|
|
69
|
+
spec: declared.spec,
|
|
70
|
+
version,
|
|
71
|
+
origin,
|
|
72
|
+
removable,
|
|
73
|
+
detail,
|
|
74
|
+
restore: { at: index, entry: declared.name },
|
|
75
|
+
};
|
|
76
|
+
});
|
|
77
|
+
const field = input.field ?? (bundles.length === 0 ? 'empty' : 'present');
|
|
78
|
+
return {
|
|
79
|
+
evidence: 'scanned',
|
|
80
|
+
profile: input.profile,
|
|
81
|
+
manifestSha256: input.manifestSha256,
|
|
82
|
+
bundles,
|
|
83
|
+
removable: bundles.filter((entry) => entry.removable),
|
|
84
|
+
thirdParty: bundles.filter((entry) => entry.origin === 'third-party').length,
|
|
85
|
+
unresolved: bundles.filter((entry) => entry.origin === 'unresolved').length,
|
|
86
|
+
empty: bundles.length === 0,
|
|
87
|
+
field,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
function isRecord(value) {
|
|
91
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Read exactly one file: `<profile>/package.json`.
|
|
95
|
+
*
|
|
96
|
+
* Returns `ok:false` (never throws) so the CLI can report "cannot read the profile" as a distinct
|
|
97
|
+
* outcome from "nothing to trim" — the two are different answers and only one of them is good news.
|
|
98
|
+
*/
|
|
99
|
+
export function readProfileBundles(profileDir) {
|
|
100
|
+
const file = join(profileDir, 'package.json');
|
|
101
|
+
let text;
|
|
102
|
+
try {
|
|
103
|
+
text = readFileSync(file, 'utf8');
|
|
104
|
+
}
|
|
105
|
+
catch {
|
|
106
|
+
return { ok: false, reason: `cannot read the profile manifest at ${file}` };
|
|
107
|
+
}
|
|
108
|
+
let parsed;
|
|
109
|
+
try {
|
|
110
|
+
parsed = JSON.parse(text);
|
|
111
|
+
}
|
|
112
|
+
catch {
|
|
113
|
+
return { ok: false, reason: `the profile manifest at ${file} is not valid JSON` };
|
|
114
|
+
}
|
|
115
|
+
if (!isRecord(parsed))
|
|
116
|
+
return { ok: false, reason: `the profile manifest at ${file} is not an object` };
|
|
117
|
+
const dependencies = isRecord(parsed['dependencies']) ? parsed['dependencies'] : {};
|
|
118
|
+
const dsh = isRecord(parsed['dsh']) ? parsed['dsh'] : {};
|
|
119
|
+
const profile = isRecord(dsh['profile']) ? dsh['profile'] : {};
|
|
120
|
+
const raw = profile['bundles'];
|
|
121
|
+
const manifestSha256 = createHash('sha256').update(text).digest('hex');
|
|
122
|
+
if (!Array.isArray(raw)) {
|
|
123
|
+
return { ok: true, declared: [], manifestSha256, field: 'absent' };
|
|
124
|
+
}
|
|
125
|
+
const declared = [];
|
|
126
|
+
for (const entry of raw) {
|
|
127
|
+
if (typeof entry !== 'string')
|
|
128
|
+
continue;
|
|
129
|
+
const spec = dependencies[entry];
|
|
130
|
+
declared.push({ name: entry, spec: typeof spec === 'string' ? spec : null });
|
|
131
|
+
}
|
|
132
|
+
return { ok: true, declared, manifestSha256, field: declared.length === 0 ? 'empty' : 'present' };
|
|
133
|
+
}
|
|
134
|
+
const MANIFEST = 'package.json';
|
|
135
|
+
/** Windows cannot create a directory named `10:30`, so the stamp is made filesystem-safe. */
|
|
136
|
+
export function safeStamp(stamp) {
|
|
137
|
+
return stamp.replace(/[:.]/g, '-');
|
|
138
|
+
}
|
|
139
|
+
function sha256(text) {
|
|
140
|
+
return createHash('sha256').update(text).digest('hex');
|
|
141
|
+
}
|
|
142
|
+
/** Atomic write: temp file beside the target, then rename. A crash never leaves half a file. */
|
|
143
|
+
function atomicWrite(file, text) {
|
|
144
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
145
|
+
const temp = `${file}.tmp-${process.pid}-${Date.now()}`;
|
|
146
|
+
writeFileSync(temp, text, { encoding: 'utf8', mode: 0o600 });
|
|
147
|
+
try {
|
|
148
|
+
if (existsSync(file))
|
|
149
|
+
statSync(file);
|
|
150
|
+
renameSync(temp, file);
|
|
151
|
+
}
|
|
152
|
+
catch (error) {
|
|
153
|
+
rmSync(temp, { force: true });
|
|
154
|
+
throw error;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
/** Serialise keeping key order (JSON.parse preserves it) and the repo's 2-space + newline shape. */
|
|
158
|
+
function serializeManifest(manifest) {
|
|
159
|
+
return `${JSON.stringify(manifest, null, 2)}\n`;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Take the removable entries out of `dsh.profile.bundles`.
|
|
163
|
+
*
|
|
164
|
+
* `dryRun` (the CLI default) writes **nothing at all** — no directory, no backup, no journal — so a
|
|
165
|
+
* preview can never leave a trace (C4 still holds after B 段).
|
|
166
|
+
*/
|
|
167
|
+
export function applyRescue(input) {
|
|
168
|
+
const removable = input.plan.removable;
|
|
169
|
+
if (input.dryRun || removable.length === 0) {
|
|
170
|
+
return { journal: '', backupDir: null, changes: [], removed: [], dryRun: true };
|
|
171
|
+
}
|
|
172
|
+
const file = join(input.profileDir, MANIFEST);
|
|
173
|
+
const before = readFileSync(file, 'utf8');
|
|
174
|
+
const parsed = JSON.parse(before);
|
|
175
|
+
if (!isRecord(parsed))
|
|
176
|
+
throw new Error(`${file} is not an object; refusing to edit it`);
|
|
177
|
+
const dsh = isRecord(parsed['dsh']) ? parsed['dsh'] : null;
|
|
178
|
+
const profile = dsh !== null && isRecord(dsh['profile']) ? dsh['profile'] : null;
|
|
179
|
+
if (profile === null || !Array.isArray(profile['bundles'])) {
|
|
180
|
+
throw new Error(`${file} has no dsh.profile.bundles array; refusing to invent one`);
|
|
181
|
+
}
|
|
182
|
+
const names = new Set(removable.map((entry) => entry.name));
|
|
183
|
+
const kept = [];
|
|
184
|
+
const removed = [];
|
|
185
|
+
for (const [index, entry] of profile['bundles'].entries()) {
|
|
186
|
+
if (typeof entry === 'string' && names.has(entry)) {
|
|
187
|
+
removed.push({ name: entry, at: index });
|
|
188
|
+
continue;
|
|
189
|
+
}
|
|
190
|
+
kept.push(entry);
|
|
191
|
+
}
|
|
192
|
+
if (removed.length === 0) {
|
|
193
|
+
// The plan said there was something to trim and the file disagrees: stop rather than "succeed".
|
|
194
|
+
throw new Error('the plan lists removable bundles but the manifest no longer contains them');
|
|
195
|
+
}
|
|
196
|
+
const nextManifest = { ...parsed };
|
|
197
|
+
nextManifest['dsh'] = { ...dsh, profile: { ...profile, bundles: kept } };
|
|
198
|
+
const after = serializeManifest(nextManifest);
|
|
199
|
+
const base = safeStamp(input.stamp);
|
|
200
|
+
const journalDir = join(input.profileDir, '.dsh-triage', 'rescue');
|
|
201
|
+
const backupDir = join(journalDir, base);
|
|
202
|
+
mkdirSync(backupDir, { recursive: true });
|
|
203
|
+
const backup = join(backupDir, MANIFEST);
|
|
204
|
+
copyFileSync(file, backup);
|
|
205
|
+
try {
|
|
206
|
+
input.beforeWrite?.();
|
|
207
|
+
atomicWrite(file, after);
|
|
208
|
+
input.afterWrite?.();
|
|
209
|
+
// Read back: a write we cannot verify is not a write we can call done.
|
|
210
|
+
const readBack = readFileSync(file, 'utf8');
|
|
211
|
+
if (readBack !== after)
|
|
212
|
+
throw new Error('the manifest did not read back as written; rolling back');
|
|
213
|
+
const check = readProfileBundles(input.profileDir);
|
|
214
|
+
if (!check.ok)
|
|
215
|
+
throw new Error(`the manifest could not be re-read after writing: ${check.reason}`);
|
|
216
|
+
if (check.declared.length !== kept.length) {
|
|
217
|
+
throw new Error(`expected ${kept.length} bundle(s) after the write, read back ${check.declared.length}`);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
catch (error) {
|
|
221
|
+
// Rollback is part of the write path, not an afterthought.
|
|
222
|
+
copyFileSync(backup, file);
|
|
223
|
+
throw error;
|
|
224
|
+
}
|
|
225
|
+
const journal = {
|
|
226
|
+
schema_version: 1,
|
|
227
|
+
produced_by: 'packages/plugin/src/rescue.ts',
|
|
228
|
+
generated_at: input.stamp,
|
|
229
|
+
profile_dir: input.profileDir,
|
|
230
|
+
backup,
|
|
231
|
+
removed,
|
|
232
|
+
before_sha256: sha256(before),
|
|
233
|
+
after_sha256: sha256(after),
|
|
234
|
+
before,
|
|
235
|
+
after,
|
|
236
|
+
};
|
|
237
|
+
const journalPath = join(journalDir, `${base}.json`);
|
|
238
|
+
writeFileSync(journalPath, `${JSON.stringify(journal, null, 2)}\n`, 'utf8');
|
|
239
|
+
return {
|
|
240
|
+
journal: journalPath,
|
|
241
|
+
backupDir,
|
|
242
|
+
changes: [{ file, before, after, backup, removed }],
|
|
243
|
+
removed: removed.map((entry) => entry.name),
|
|
244
|
+
dryRun: false,
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Put the manifest back byte for byte.
|
|
249
|
+
*
|
|
250
|
+
* Refuses when the current bytes are not the ones this journal produced: someone edited the profile
|
|
251
|
+
* after the rescue, and overwriting that edit would be a second, silent change (N11).
|
|
252
|
+
*/
|
|
253
|
+
export function undoRescue(journalPath) {
|
|
254
|
+
const journal = JSON.parse(readFileSync(journalPath, 'utf8'));
|
|
255
|
+
if (journal.schema_version !== 1)
|
|
256
|
+
throw new Error(`unsupported journal schema: ${String(journal.schema_version)}`);
|
|
257
|
+
const file = join(journal.profile_dir, MANIFEST);
|
|
258
|
+
if (!existsSync(journal.backup))
|
|
259
|
+
throw new Error(`backup is missing: ${journal.backup}`);
|
|
260
|
+
const current = existsSync(file) ? readFileSync(file, 'utf8') : null;
|
|
261
|
+
if (current === null || sha256(current) !== journal.after_sha256) {
|
|
262
|
+
throw new Error(`${file} changed after this rescue was applied; refusing to overwrite it`);
|
|
263
|
+
}
|
|
264
|
+
copyFileSync(journal.backup, file);
|
|
265
|
+
const restored = readFileSync(file, 'utf8');
|
|
266
|
+
if (sha256(restored) !== journal.before_sha256) {
|
|
267
|
+
throw new Error(`${file} was restored but its bytes do not match the pre-rescue manifest`);
|
|
268
|
+
}
|
|
269
|
+
return { restored: [file] };
|
|
270
|
+
}
|
|
271
|
+
//# sourceMappingURL=rescue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rescue.js","sourceRoot":"","sources":["../src/rescue.ts"],"names":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O,EAAE,QAAQ,EAAE,CAAC,IAAI,CAAC,EAAE,CAAA;AAC7B,CAAC"}
|
package/dist/serve.d.ts
CHANGED
|
@@ -24,11 +24,28 @@
|
|
|
24
24
|
*/
|
|
25
25
|
import { type Server } from 'node:http';
|
|
26
26
|
import type { ProfileSummary } from './summary.js';
|
|
27
|
+
/**
|
|
28
|
+
* ADR-0015 / T-814: how long a scan answer may be reused.
|
|
29
|
+
*
|
|
30
|
+
* WHY 1 SECOND AND NOT A FLAG: a profile scan is fs-bound and takes ~0.4–1s on a real profile
|
|
31
|
+
* (R68: median 921ms). Clicking refresh ten times in a second used to mean ten full scans. One
|
|
32
|
+
* second is far below the rate at which a plugin actually changes (installs are minute-scale),
|
|
33
|
+
* and a constant cannot be tuned down to 0 by someone chasing a benchmark.
|
|
34
|
+
*/
|
|
35
|
+
export declare const AUDIT_REUSE_MS = 1000;
|
|
27
36
|
export interface ServeOptions {
|
|
28
37
|
/** Directory holding `*.json` + `.sha256` evidence files. */
|
|
29
38
|
readonly resultsDir: string;
|
|
30
|
-
/**
|
|
39
|
+
/**
|
|
40
|
+
* Bind address; defaults to 127.0.0.1.
|
|
41
|
+
*
|
|
42
|
+
* ADR-0014: this is no longer "not meant to be changed" — binding a non-loopback address is a
|
|
43
|
+
* deliberate act that requires `allowHosts` to name the address clients will use, so the Host
|
|
44
|
+
* check can tell "my address" from "a name that resolves to me".
|
|
45
|
+
*/
|
|
31
46
|
readonly host?: string;
|
|
47
|
+
/** ADR-0014: extra `Host` names to accept (`name` or `name:port`). Empty for loopback only. */
|
|
48
|
+
readonly allowHosts?: readonly string[];
|
|
32
49
|
/** 0 picks a free port (tests use this). */
|
|
33
50
|
readonly port?: number;
|
|
34
51
|
/** Locale for the tiny bit of chrome copy on the page. */
|
|
@@ -104,7 +121,26 @@ export interface EnvHeadline {
|
|
|
104
121
|
readonly arch: string | null;
|
|
105
122
|
}
|
|
106
123
|
export declare function createPanelServer(options: ServeOptions): PanelServer;
|
|
124
|
+
/**
|
|
125
|
+
* The `name:port` a person should type to reach this panel (ADR-0014).
|
|
126
|
+
*
|
|
127
|
+
* Three cases that a naive `${host}:${port}` gets wrong, all found by an independent reviewer:
|
|
128
|
+
* 1. `--host ::1` → `http://::1:5555/` is not a URL; IPv6 literals need brackets;
|
|
129
|
+
* 2. `--host 0.0.0.0 --allow-host panel.local:8080` → appending the socket port gives
|
|
130
|
+
* `panel.local:8080:61247`, which is also not a URL;
|
|
131
|
+
* 3. `ssh -L 8080:127.0.0.1:<port>` (or any reverse proxy): the browser will send
|
|
132
|
+
* `Host: localhost:8080`, so the printed link must use that pair, not the socket port.
|
|
133
|
+
*/
|
|
134
|
+
export declare function panelAuthority(host: string | undefined, allowHosts: readonly string[] | undefined, port: number): string;
|
|
107
135
|
export declare function startPanel(options: ServeOptions): Promise<PanelServer>;
|
|
136
|
+
/** One answer from the shared scan, with enough metadata to say whether it was fresh (ADR-0015). */
|
|
137
|
+
export interface ScanOutcome {
|
|
138
|
+
readonly snapshot: AuditSnapshot;
|
|
139
|
+
/** True when this answer came out of the reuse window instead of a new scan. */
|
|
140
|
+
readonly reused: boolean;
|
|
141
|
+
/** How old the reused answer is (0 for a fresh scan). */
|
|
142
|
+
readonly age_ms: number;
|
|
143
|
+
}
|
|
108
144
|
/** Deterministic digest helper used by the smoke recorder. */
|
|
109
145
|
export declare function sha256OfText(text: string): string;
|
|
110
146
|
/**
|
|
@@ -124,3 +160,4 @@ export declare function sha256OfText(text: string): string;
|
|
|
124
160
|
* command text, so "what do I type" is one click instead of a transcription.
|
|
125
161
|
*/
|
|
126
162
|
export declare function renderPanelHtml(locale: 'en' | 'zh'): string;
|
|
163
|
+
//# sourceMappingURL=serve.d.ts.map
|
package/dist/serve.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serve.d.ts","sourceRoot":"","sources":["../src/serve.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,EA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