@memnexus-ai/mx-agent-cli 0.1.291 → 0.1.292
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/__tests__/config-fidelity-unreadable-fixture.d.ts +32 -0
- package/dist/__tests__/config-fidelity-unreadable-fixture.d.ts.map +1 -0
- package/dist/__tests__/config-fidelity-unreadable-fixture.js +37 -0
- package/dist/__tests__/config-fidelity-unreadable-fixture.js.map +1 -0
- package/dist/__tests__/config-fidelity.test.d.ts +16 -0
- package/dist/__tests__/config-fidelity.test.d.ts.map +1 -0
- package/dist/__tests__/config-fidelity.test.js +2546 -0
- package/dist/__tests__/config-fidelity.test.js.map +1 -0
- package/dist/__tests__/doctor-config-fidelity.test.d.ts +19 -0
- package/dist/__tests__/doctor-config-fidelity.test.d.ts.map +1 -0
- package/dist/__tests__/doctor-config-fidelity.test.js +324 -0
- package/dist/__tests__/doctor-config-fidelity.test.js.map +1 -0
- package/dist/commands/doctor.d.ts +46 -7
- package/dist/commands/doctor.d.ts.map +1 -1
- package/dist/commands/doctor.js +81 -9
- package/dist/commands/doctor.js.map +1 -1
- package/dist/commands/start.d.ts.map +1 -1
- package/dist/commands/start.js +56 -0
- package/dist/commands/start.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +33 -9
- package/dist/index.js.map +1 -1
- package/dist/lib/config-fidelity.d.ts +500 -0
- package/dist/lib/config-fidelity.d.ts.map +1 -0
- package/dist/lib/config-fidelity.js +1713 -0
- package/dist/lib/config-fidelity.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,1713 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* config-fidelity.ts — assert that the agent-config DEPLOYED into a project
|
|
3
|
+
* (`.claude/`) matches the agent-config SOURCE it was generated from (A2 of the
|
|
4
|
+
* MX framework extraction, #5412).
|
|
5
|
+
*
|
|
6
|
+
* HOW THIS DIFFERS FROM hook-completeness.ts — READ THIS BEFORE MERGING THEM.
|
|
7
|
+
* • hook-completeness.ts checks the deployed config's REFERENTIAL INTEGRITY:
|
|
8
|
+
* every hook registered in the deployed settings.json exists on disk, every
|
|
9
|
+
* expected guard is registered, every reference resolves. It compares the
|
|
10
|
+
* deployed config against ITSELF (plus the source's registration list). It
|
|
11
|
+
* is a never-throwing detection primitive feeding a fail-OPEN heal path
|
|
12
|
+
* (verifyAndHealHooks in claude.ts).
|
|
13
|
+
* • config-fidelity.ts checks deployed file CONTENT against source content.
|
|
14
|
+
* It is fail-CLOSED on the verdict and never heals.
|
|
15
|
+
* A stale-but-present file passes hook-completeness trivially — that property
|
|
16
|
+
* held the entire time the three drifts in #5412 were live. Only a content
|
|
17
|
+
* comparison catches it. Do NOT fold this into hook-completeness: one control
|
|
18
|
+
* cannot hold a fail-open and a fail-closed contract at the same time.
|
|
19
|
+
*
|
|
20
|
+
* WHY THIS MATTERS MORE AFTER THE EXTRACTION. Inside one repository a stale
|
|
21
|
+
* deployed copy is a nuisance. Once the framework lives in its own repository,
|
|
22
|
+
* "the deployed config equals the source config" IS the seam between framework
|
|
23
|
+
* and consumer, and nothing else asserts it.
|
|
24
|
+
*
|
|
25
|
+
* ── SOURCE RESOLVES PER LAYER, AT THE REF THE GENERATOR USED ────────────────
|
|
26
|
+
* `scripts/generate-claude.mjs` (generateClaudeConfigForBoot) deliberately
|
|
27
|
+
* SPLITS deployment across two refs:
|
|
28
|
+
* settings.json, hooks/ ← origin/<baseBranch> (trusted remote)
|
|
29
|
+
* agents/, skills/, commands/, rules/ ← the WORKING TREE
|
|
30
|
+
* A naive working-tree-vs-deployed comparison would therefore report every
|
|
31
|
+
* unmerged commit touching hooks/ or settings.json as drift, and would be red on
|
|
32
|
+
* nearly every feature branch — which is how a check gets disabled in week one.
|
|
33
|
+
* So this module compares each layer against the ref the generator sourced it
|
|
34
|
+
* from, and every reported mismatch NAMES that ref: "differs from
|
|
35
|
+
* source@origin/main" and "differs from source (working tree)" are different
|
|
36
|
+
* findings and must not be confused for one another.
|
|
37
|
+
*
|
|
38
|
+
* ── BUNDLE MODE (the post-extraction shape) ────────────────────────────────
|
|
39
|
+
* A consuming project that has no in-repo agent-config tree gets its config from
|
|
40
|
+
* the CLI bundle (`<cliDist>/agent-config/`, resolved by bundled-config.ts's
|
|
41
|
+
* getBundledConfigDir()). There is no git and no origin/<base> for that source,
|
|
42
|
+
* so the per-layer ref split COLLAPSES: every layer is compared against the
|
|
43
|
+
* bundle, because the package version is the trusted ref. The bundle carries no
|
|
44
|
+
* `local/` overlay, so the overlay always resolves from the consuming repo.
|
|
45
|
+
*
|
|
46
|
+
* RESOLUTION ORDER, and why it is NOT bundled-config.ts's order:
|
|
47
|
+
* 1. an explicit `opts.sourceDir` (in-process test seam / power user)
|
|
48
|
+
* 2. `<worktree>/<configSource>/settings.json` — the repo's own source tree
|
|
49
|
+
* 3. the MX_BUNDLED_CONFIG_DIR environment override
|
|
50
|
+
* 4. the CLI bundle
|
|
51
|
+
* Each of the four is recorded as a distinct `sourceAuthority`, and TWO of them
|
|
52
|
+
* are overrides: `env-override` and `explicit`. An explicit dir that resolves to
|
|
53
|
+
* the worktree's own `<configSource>` is not an override — it names the same
|
|
54
|
+
* authority the resolver would have chosen on its own — but any OTHER explicit
|
|
55
|
+
* dir is a directory an operator named, which is the same "whoever chose the
|
|
56
|
+
* ground truth decides the verdict" problem as the environment variable, and it
|
|
57
|
+
* carries the same caveat and the same exit 2.
|
|
58
|
+
* MX_BUNDLED_CONFIG_DIR sits BELOW the repo tree deliberately. bundled-config.ts
|
|
59
|
+
* documents that variable as "trusted by design", which is sound for deciding
|
|
60
|
+
* what to DEPLOY and unsound for verifying what WAS deployed: if an environment
|
|
61
|
+
* variable can name the ground truth, anyone who can set one in the session's
|
|
62
|
+
* environment can make a tampered deployment certify itself CLEAN. So a project
|
|
63
|
+
* that owns a source tree always compares against that tree, and where the
|
|
64
|
+
* override is honoured at all the result carries `sourceOverridden: true`, the
|
|
65
|
+
* output leads with a line saying so, and the exit code is 2 (NOT VERIFIED)
|
|
66
|
+
* rather than 0.
|
|
67
|
+
* getBundledConfigDir() puts the bundle FIRST, which is right for its job
|
|
68
|
+
* (deciding what to deploy) and wrong for this one. Measured 2026-08-11: in this
|
|
69
|
+
* monorepo `dist/agent-config/` is a copy of the WORKING TREE made by
|
|
70
|
+
* `npm run build`, not a published package. Trusting it as "the ref" re-creates
|
|
71
|
+
* the exact false red the layer split removes — a working-tree-only hook read as
|
|
72
|
+
* deployment drift (`hooks/bar-raiser-readonly-guard.sh` did, on the first
|
|
73
|
+
* end-to-end run). Where the project owns a source tree, that tree plus its git
|
|
74
|
+
* refs is the authority; the bundle is the fallback for projects that have none.
|
|
75
|
+
*
|
|
76
|
+
* ── BYTE COMPARISON IS DELIBERATE (do not "fix" it into template-awareness) ──
|
|
77
|
+
* A scan of agent-config/{hooks,agents,skills,rules} on 2026-08-10 found only
|
|
78
|
+
* three placeholder-shaped strings — `${WORKTREE_NAME}`, `${WORKTREE}` and
|
|
79
|
+
* `__MX__` — and all three are false positives: the first two are RUNTIME shell
|
|
80
|
+
* variables inside the scripts, the third is an MCP tool-name prefix. The files
|
|
81
|
+
* containing them deploy byte-identical. The generator copies these layers
|
|
82
|
+
* verbatim (readFileSync → writeFileSync). Byte comparison is therefore the
|
|
83
|
+
* correct instrument for everything except settings.json.
|
|
84
|
+
*
|
|
85
|
+
* ── EXCLUSIONS, each with its reason ───────────────────────────────────────
|
|
86
|
+
* • CLAUDE.md / AGENTS.md — genuinely templated (AGENTS.md.template,
|
|
87
|
+
* CLAUDE.md.template, agent-config/claude-md/compose.mjs). A byte comparison
|
|
88
|
+
* is the wrong instrument; the right one is undetermined and out of A2 scope.
|
|
89
|
+
* • .claude/settings.local.json — per-machine, user-owned, has no source
|
|
90
|
+
* counterpart at all.
|
|
91
|
+
* • .claude/worktrees/** — foreign debris: stale Claude Code agent checkouts,
|
|
92
|
+
* each with its own .claude/ inside. The generator already refuses to scan
|
|
93
|
+
* it (see assertNoSymlinksInTree's TRAVERSAL SCOPE note); scanning into it
|
|
94
|
+
* hard-blocked customer-portal session starts on 2026-08-01. There IS now a
|
|
95
|
+
* deployed-side walk (the reverse-inclusion pass below), and it is scoped to
|
|
96
|
+
* `.claude/<layer>/` for every directory layer whose SOURCE ROOT IS PRESENT
|
|
97
|
+
* — required or optional, see REVERSE_INCLUSION_LAYERS. `worktrees` is
|
|
98
|
+
* not a layer, so the walk never descends there, and it does not follow
|
|
99
|
+
* symlinks (a symlinked deployed entry is recorded as a leaf, never
|
|
100
|
+
* traversed). Anyone widening that walk to the whole of `.claude/` re-opens
|
|
101
|
+
* the 2026-08-01 hang.
|
|
102
|
+
* • FILE MODES — the generator normalises every `*.sh` to 0755 regardless of
|
|
103
|
+
* the source blob's mode, so comparing modes produces false reds.
|
|
104
|
+
* • NO `*.test.sh` RULE. Resolved decision: tests DO deploy. generate-claude
|
|
105
|
+
* copies them deliberately and says so at the hooks step ("*.sh → 0755
|
|
106
|
+
* (incl. *.test.sh)"). Adding an exclusion here would re-open the
|
|
107
|
+
* inconsistency that makes the first red ambiguous. (In BUNDLE mode they are
|
|
108
|
+
* simply absent from the source set — bundled-config.ts keeps them out of the
|
|
109
|
+
* published package — and one-way inclusion means absent-from-source is not a
|
|
110
|
+
* finding.)
|
|
111
|
+
*
|
|
112
|
+
* ── DIRECTION: TWO-WAY INSIDE EVERY PRESENT LAYER, ONE-WAY EVERYWHERE ELSE ──
|
|
113
|
+
* FORWARD (every layer): for every file in the resolved SOURCE set there must be
|
|
114
|
+
* a counterpart in `.claude/` with matching content.
|
|
115
|
+
* REVERSE (every directory layer whose source root is PRESENT — hooks/, agents/,
|
|
116
|
+
* skills/, commands/, rules/): every file under `.claude/<layer>/` must have a
|
|
117
|
+
* counterpart in the resolved source union, or it is an `unaccounted` mismatch
|
|
118
|
+
* reading `deployed file has no source counterpart`. It carries NO ref: nothing
|
|
119
|
+
* was compared, so no ref was consulted.
|
|
120
|
+
* The reverse half used to be absent, justified by "the overlay contributes
|
|
121
|
+
* agents and commands that have no shared-source counterpart". That reason was
|
|
122
|
+
* STALE: the overlay (`agent-config/local/`) is itself walked as source, so its
|
|
123
|
+
* files ARE inside the resolved union and were never the extras the exemption
|
|
124
|
+
* described. What the exemption actually covered was an attacker-added deployed
|
|
125
|
+
* file — a seventh agent in `.claude/agents/` that no source root mentions, which
|
|
126
|
+
* Claude Code loads and this check never looked at. Measured on the honest tree
|
|
127
|
+
* on 2026-08-11 (`comm -23` deployed against source union): hooks 44/44,
|
|
128
|
+
* agents 26/26, commands 6/6, rules 4/4, skills 13/13, ZERO extras in every
|
|
129
|
+
* layer. The genuine extras — `settings.local.json`, `scheduled_tasks.lock` —
|
|
130
|
+
* sit at the TOP LEVEL of `.claude/`, outside every layer directory, and the walk
|
|
131
|
+
* never sees them. The one exemption left is a layer whose SOURCE ROOT IS ABSENT
|
|
132
|
+
* — there is nothing to subtract from, so a consumer who ships deployed rules
|
|
133
|
+
* with no source `rules/` is not made red. Exempting the optional LAYER instead
|
|
134
|
+
* of the absent ROOT is what let a planted `.claude/rules/attacker-rule.md`
|
|
135
|
+
* certify CLEAN (round-7 MF).
|
|
136
|
+
*
|
|
137
|
+
* ── COVERAGE IS A DECLARED PER-ROOT CONTRACT, AND ZERO IS NOT CLEAN ───────
|
|
138
|
+
* An absent or unreadable source layer used to contribute nothing and leave the
|
|
139
|
+
* verdict a pure function of the mismatch count — so a source tree stripped of
|
|
140
|
+
* `hooks/` reported CLEAN with the deployed permission layer replaced by
|
|
141
|
+
* `exit 0`. The first fix for that applied to `hooks/` ALONE, which left the
|
|
142
|
+
* same hole open one layer over: with `agents/` missing from the source, a
|
|
143
|
+
* deployed `security-reviewer.md` rewritten to grant `Bash` certified CLEAN,
|
|
144
|
+
* because `agents/` carries the subagent tool grants and nothing required it to
|
|
145
|
+
* be compared. A special case per layer is a bug per layer. So the contract is
|
|
146
|
+
* DECLARED, once — and it counts PER SOURCE ROOT, not per layer, because
|
|
147
|
+
* `agents` and `skills` each have TWO roots (base and overlay) and a per-LAYER
|
|
148
|
+
* count is satisfied by EITHER one alone. Measured before this fix, in repo
|
|
149
|
+
* mode: delete the base `agents/` from the source tree (an uncommitted
|
|
150
|
+
* working-tree change, since the behavioral layers read from the working tree,
|
|
151
|
+
* so it leaves no commit), rewrite every deployed base agent in `.claude/agents/`
|
|
152
|
+
* including `security-reviewer.md`, and the run prints `agents 13` and exits 0 —
|
|
153
|
+
* the number looks right because the overlay supplies exactly 13. Four shapes
|
|
154
|
+
* reached CLEAN/exit 0 that way: base `agents/` removed, base `agents/` emptied,
|
|
155
|
+
* base `skills/` removed, and overlay `local/agents/` removed with a tampered
|
|
156
|
+
* deployed overlay agent.
|
|
157
|
+
* • REQUIRED_LAYERS — settings.json, hooks, agents, skills, commands. EVERY
|
|
158
|
+
* root of theirs declared `required: true` must be PRESENT before the walk
|
|
159
|
+
* and must have contributed at least one source entry after it. Either
|
|
160
|
+
* failure is COULD_NOT_RUN, naming the ROOT and its layer.
|
|
161
|
+
* • A root declared `required: false` is one a consumer may legitimately not
|
|
162
|
+
* ship — the `local/` overlay half of `agents` and `skills`. Its absence is
|
|
163
|
+
* not a finding; what closes the hole that leaves is the REVERSE inclusion
|
|
164
|
+
* pass above, which reports the deployed overlay files nothing accounts for.
|
|
165
|
+
* • The two contracts are coupled, and the coupling is CHECKED rather than
|
|
166
|
+
* assumed: rootContractGaps() requires every REQUIRED layer to declare at
|
|
167
|
+
* least one required root and every OPTIONAL layer to declare none. Without
|
|
168
|
+
* it, a future edit flipping `required` to false on the base `agents` root
|
|
169
|
+
* restores exactly this hole, silently.
|
|
170
|
+
* • rules/ is the one OPTIONAL layer: a consumer may genuinely ship none, and
|
|
171
|
+
* a check that is red for every such consumer gets disabled. When it is
|
|
172
|
+
* absent it is recorded as `absentOptionalLayers` and PRINTED as
|
|
173
|
+
* `rules 0 (absent from source)`, so a reader can tell "nothing to compare"
|
|
174
|
+
* from "nothing compared".
|
|
175
|
+
* • the CLEAN line PRINTS the per-layer counts, so "0 agents compared" is
|
|
176
|
+
* visible rather than something a reader has to infer from a total.
|
|
177
|
+
* "Layer genuinely absent from source" and "layer unreadable" are different: the
|
|
178
|
+
* first is legitimate only for an optional layer, the second is always
|
|
179
|
+
* COULD_NOT_RUN. That distinction lives in ONE place — statOrAbsent /
|
|
180
|
+
* isAbsentErrno — and every filesystem probe in this module routes through it.
|
|
181
|
+
* `existsSync` is banned here: it answers false for both, and both times that
|
|
182
|
+
* conflation reached this file it produced a false green.
|
|
183
|
+
*
|
|
184
|
+
* ── FAILURE MODEL: FAIL CLOSED ON THE VERDICT, NEVER SELF-HEAL ─────────────
|
|
185
|
+
* CLEAN → exit 0
|
|
186
|
+
* DRIFTED → exit 1, listing every mismatching path with its layer and ref
|
|
187
|
+
* COULD_NOT_RUN → exit 2 (source unresolvable, origin/<base> unavailable,
|
|
188
|
+
* settings.json unparseable, a symlink anywhere in the source
|
|
189
|
+
* tree — including settings.json itself — or at a layer root
|
|
190
|
+
* on either side, no hooks/ layer, a source directory that
|
|
191
|
+
* exists but cannot be read).
|
|
192
|
+
*
|
|
193
|
+
* SYMLINKS, one rule, two places it lands. The SOURCE side fails closed
|
|
194
|
+
* (COULD_NOT_RUN): a tree the generator refuses to deploy from is not a tree
|
|
195
|
+
* this check can certify anything against. The DEPLOYED side is DRIFT: a
|
|
196
|
+
* symlink there is simply not the artifact the source describes, and it is
|
|
197
|
+
* reported for EVERY path component — deployedIsPlain — not for layer roots and
|
|
198
|
+
* leaf files only. The gap that rule closed: a deployed `.claude/settings.json`
|
|
199
|
+
* or an intermediate `.claude/skills/<name>` replaced by a link to an identical
|
|
200
|
+
* file or directory outside the tree read CLEAN, because content is read
|
|
201
|
+
* THROUGH the link and the redirect itself was what went unrecorded.
|
|
202
|
+
* source overridden → exit 2 even when the comparison itself came back CLEAN.
|
|
203
|
+
* A check that has stopped evaluating must never report PASS. This module never
|
|
204
|
+
* regenerates or repairs anything — heal is verifyAndHealHooks's job, and a
|
|
205
|
+
* checker that heals erases its own evidence.
|
|
206
|
+
*/
|
|
207
|
+
import { spawnSync } from 'child_process';
|
|
208
|
+
import { lstatSync, mkdtempSync, readFileSync, readdirSync, readlinkSync, realpathSync, rmSync } from 'fs';
|
|
209
|
+
import { tmpdir } from 'os';
|
|
210
|
+
import { dirname, join, resolve } from 'path';
|
|
211
|
+
import { fileURLToPath } from 'url';
|
|
212
|
+
import { getBundledConfigDir } from './bundled-config.js';
|
|
213
|
+
import { safeConfigSource } from './isolation-probe.js';
|
|
214
|
+
/**
|
|
215
|
+
* Every layer, in report order — and the SINGLE definition point for what a
|
|
216
|
+
* layer is. `FidelityLayer` is DERIVED from this array, not declared beside it.
|
|
217
|
+
*
|
|
218
|
+
* The direction matters. When the union was declared first and the array typed
|
|
219
|
+
* `readonly FidelityLayer[]`, a 6-of-7 subset type-checked: adding a seventh
|
|
220
|
+
* layer to the union broke compilation at `zeroPerLayer` and `layerRoots` — the
|
|
221
|
+
* two Record sites — and a maintainer who fixed exactly the errors the compiler
|
|
222
|
+
* reported left the new layer OUT of this array, which compiles clean and
|
|
223
|
+
* silently drops the layer from the deployed-root symlink loop, the presence
|
|
224
|
+
* contract, the coverage floor and the per-layer print. Measured on a tampered
|
|
225
|
+
* `plugins` layer: `CLEAN, 96 files, exit 0`, with the layer absent from the
|
|
226
|
+
* per-layer line entirely. Deriving the type from the array inverts that: the
|
|
227
|
+
* array is the only place a layer can be added, and adding one there is what
|
|
228
|
+
* produces the Record errors.
|
|
229
|
+
*/
|
|
230
|
+
export const FIDELITY_LAYERS = [
|
|
231
|
+
'settings.json',
|
|
232
|
+
'hooks',
|
|
233
|
+
'rules',
|
|
234
|
+
'agents',
|
|
235
|
+
'skills',
|
|
236
|
+
'commands',
|
|
237
|
+
];
|
|
238
|
+
/** Exit codes. The verdict is fail-closed: only CLEAN is 0. */
|
|
239
|
+
export const FIDELITY_EXIT = {
|
|
240
|
+
CLEAN: 0,
|
|
241
|
+
DRIFTED: 1,
|
|
242
|
+
COULD_NOT_RUN: 2,
|
|
243
|
+
};
|
|
244
|
+
const DEFAULT_CONFIG_SOURCE = 'mx-agent-system/agent-config';
|
|
245
|
+
function zeroPerLayer() {
|
|
246
|
+
return { 'settings.json': 0, hooks: 0, rules: 0, agents: 0, skills: 0, commands: 0 };
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* The layers whose absence is never legitimate. Each one must have a PRESENT
|
|
250
|
+
* source root before the walk and a NON-ZERO comparison count after it.
|
|
251
|
+
*
|
|
252
|
+
* Why each is here rather than only hooks/: hooks/ and settings.json are the
|
|
253
|
+
* permission layer; agents/ carries every subagent's `tools:` grant, so an
|
|
254
|
+
* unverified agents/ layer is an unverified authorization boundary; skills/ and
|
|
255
|
+
* commands/ carry instructions the session executes. A source tree missing any
|
|
256
|
+
* of them is not a tree this check can certify anything about.
|
|
257
|
+
*/
|
|
258
|
+
export const REQUIRED_LAYERS = [
|
|
259
|
+
'settings.json',
|
|
260
|
+
'hooks',
|
|
261
|
+
'agents',
|
|
262
|
+
'skills',
|
|
263
|
+
'commands',
|
|
264
|
+
];
|
|
265
|
+
/**
|
|
266
|
+
* The layers a consumer may legitimately ship none of. Absence here is recorded
|
|
267
|
+
* and printed, not treated as a failure — a check that is red for every consumer
|
|
268
|
+
* without a rules/ overlay is a check that gets switched off.
|
|
269
|
+
*/
|
|
270
|
+
export const OPTIONAL_LAYERS = ['rules'];
|
|
271
|
+
/**
|
|
272
|
+
* REQUIRED ∪ OPTIONAL must be exactly FIDELITY_LAYERS — every layer is declared
|
|
273
|
+
* required or optional, none is both, none is neither.
|
|
274
|
+
*
|
|
275
|
+
* The type system cannot express this: all three are `readonly FidelityLayer[]`,
|
|
276
|
+
* so a layer in NEITHER list compiles fine and then falls through the presence
|
|
277
|
+
* loop's `!REQUIRED_LAYERS.includes(layer)` branch into `absentOptionalLayers` —
|
|
278
|
+
* i.e. it is silently treated as optional, and its absence from source stops
|
|
279
|
+
* being a finding. That is the same defect shape as the un-coupled array above,
|
|
280
|
+
* one hop over.
|
|
281
|
+
*
|
|
282
|
+
* Returns the problems rather than throwing so it can be exercised directly with
|
|
283
|
+
* injected lists; the production call below turns a non-empty result into
|
|
284
|
+
* COULD_NOT_RUN, which is the fail-closed answer for a check whose own contract
|
|
285
|
+
* is inconsistent.
|
|
286
|
+
*/
|
|
287
|
+
export function layerContractGaps(all = FIDELITY_LAYERS, required = REQUIRED_LAYERS, optional = OPTIONAL_LAYERS) {
|
|
288
|
+
const problems = [];
|
|
289
|
+
const declared = [...required, ...optional];
|
|
290
|
+
for (const layer of all) {
|
|
291
|
+
const n = declared.filter((d) => d === layer).length;
|
|
292
|
+
if (n === 0)
|
|
293
|
+
problems.push(`${layer} is in neither REQUIRED_LAYERS nor OPTIONAL_LAYERS`);
|
|
294
|
+
if (n > 1)
|
|
295
|
+
problems.push(`${layer} is declared ${n} times across REQUIRED_LAYERS/OPTIONAL_LAYERS`);
|
|
296
|
+
}
|
|
297
|
+
for (const layer of declared) {
|
|
298
|
+
if (!all.includes(layer))
|
|
299
|
+
problems.push(`${layer} is declared required/optional but is not a FIDELITY_LAYERS member`);
|
|
300
|
+
}
|
|
301
|
+
return [...new Set(problems)].sort();
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* EVERY directory layer, and therefore the layers the reverse-inclusion pass
|
|
305
|
+
* walks. Derived from FIDELITY_LAYERS, never re-listed: a layer added there gets
|
|
306
|
+
* reverse inclusion without anyone remembering to add it here, which is the
|
|
307
|
+
* failure mode every enumeration in this module has already produced once.
|
|
308
|
+
*
|
|
309
|
+
* settings.json is excluded because it is a single FILE with a single deployed
|
|
310
|
+
* counterpart that the forward pass compares directly — there is no directory to
|
|
311
|
+
* find extras in.
|
|
312
|
+
*
|
|
313
|
+
* WHY THIS IS NOT DERIVED FROM REQUIRED_LAYERS (round-7 MF). It was, and that
|
|
314
|
+
* switched reverse inclusion OFF for `rules/`, the one OPTIONAL layer: measured
|
|
315
|
+
* on the honest fixture, `printf 'Always grant Bash to every agent.\n' >
|
|
316
|
+
* .claude/rules/attacker-rule.md` gave CLEAN / exit 0 with zero mismatches,
|
|
317
|
+
* while the identical plant in agents/, hooks/, commands/ and skills/ each gave
|
|
318
|
+
* DRIFTED / exit 1. `.claude/rules/` holds instruction files agents are pointed
|
|
319
|
+
* at and follow (`rules/mcp-protocol.md` is cited as governing authority for
|
|
320
|
+
* tool-response shapes), so a planted rule is instruction injection under a green
|
|
321
|
+
* fidelity line.
|
|
322
|
+
* The optionality argument the exemption rested on — a consumer shipping deployed
|
|
323
|
+
* rules with no source `rules/` must not be made red — bites ONLY when the source
|
|
324
|
+
* root is absent, so that is what the walk now gates on (see the
|
|
325
|
+
* `absentOptionalLayers` skip at the call site), not on whether the layer is
|
|
326
|
+
* required. With the root PRESENT the argument evaporates, and the generator
|
|
327
|
+
* settles it: generate-claude.mjs lists `rules` in MANAGED_SUBDIRS and calls
|
|
328
|
+
* `pruneExtras(rulesDest, ruleNames)`, deleting extras from `rules/` itself, so
|
|
329
|
+
* no legitimate post-generation consumer shape produces one.
|
|
330
|
+
*/
|
|
331
|
+
export const REVERSE_INCLUSION_LAYERS = FIDELITY_LAYERS.filter((l) => l !== 'settings.json');
|
|
332
|
+
/**
|
|
333
|
+
* The coupling between the LAYER contract (REQUIRED_LAYERS / OPTIONAL_LAYERS)
|
|
334
|
+
* and the ROOT contract (`required` per root), checked rather than assumed.
|
|
335
|
+
*
|
|
336
|
+
* Two ways they can disagree, both of which reinstate a hole that has already
|
|
337
|
+
* shipped once:
|
|
338
|
+
* • a REQUIRED layer with no required root — nothing has to be present and
|
|
339
|
+
* nothing has to be compared, so the layer is required in name only. This is
|
|
340
|
+
* exactly the state `agents` was in before this round, expressed as data.
|
|
341
|
+
* • an OPTIONAL layer with a required root — the layer is documented as one a
|
|
342
|
+
* consumer may ship none of, and the run fails closed for every consumer who
|
|
343
|
+
* does. That is how a check gets switched off.
|
|
344
|
+
*
|
|
345
|
+
* Returns problems rather than throwing, like layerContractGaps, so it can be
|
|
346
|
+
* exercised with injected tables; the production call turns a non-empty result
|
|
347
|
+
* into COULD_NOT_RUN.
|
|
348
|
+
*/
|
|
349
|
+
export function rootContractGaps(roots, required = REQUIRED_LAYERS, optional = OPTIONAL_LAYERS) {
|
|
350
|
+
const problems = [];
|
|
351
|
+
for (const [layer, list] of Object.entries(roots)) {
|
|
352
|
+
const requiredRoots = list.filter((r) => r.required).length;
|
|
353
|
+
if (list.length === 0)
|
|
354
|
+
problems.push(`${layer} declares no source roots at all`);
|
|
355
|
+
if (required.includes(layer) && requiredRoots === 0) {
|
|
356
|
+
problems.push(`${layer} is a REQUIRED layer but declares no required source root`);
|
|
357
|
+
}
|
|
358
|
+
if (optional.includes(layer) && requiredRoots > 0) {
|
|
359
|
+
problems.push(`${layer} is an OPTIONAL layer but declares ${requiredRoots} required source root(s)`);
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
return problems.sort();
|
|
363
|
+
}
|
|
364
|
+
// ── ONE path classifier — absent is not unreadable ──────────────────────────
|
|
365
|
+
/**
|
|
366
|
+
* ABSENT and UNREADABLE are different answers, and this is the ONLY place in the
|
|
367
|
+
* module that decides which one a failed filesystem call is.
|
|
368
|
+
*
|
|
369
|
+
* It is factored out because the same conflation was found twice, in two
|
|
370
|
+
* functions that each carried their own copy of the decision: `listEntries`
|
|
371
|
+
* turned EACCES into "empty layer", and `resolveSourceDir` turned EACCES into
|
|
372
|
+
* "this project has no source tree" (via `existsSync`, which cannot express the
|
|
373
|
+
* difference) and handed source authority to the next candidate. Both produced a
|
|
374
|
+
* CLEAN verdict over a tampered deployment. A rule that lives in one place
|
|
375
|
+
* cannot be half-applied.
|
|
376
|
+
*
|
|
377
|
+
* ABSENT = ENOENT (nothing there) or ENOTDIR (a non-directory component in the
|
|
378
|
+
* path). EVERYTHING else — EACCES, EIO, ELOOP, EMFILE, ENAMETOOLONG — is
|
|
379
|
+
* UNREADABLE, and unreadable is COULD_NOT_RUN.
|
|
380
|
+
*/
|
|
381
|
+
function isAbsentErrno(err) {
|
|
382
|
+
const code = err.code;
|
|
383
|
+
return code === 'ENOENT' || code === 'ENOTDIR';
|
|
384
|
+
}
|
|
385
|
+
/** lstat a path. Returns null when ABSENT; bails when UNREADABLE. */
|
|
386
|
+
function statOrAbsent(path, label) {
|
|
387
|
+
try {
|
|
388
|
+
return lstatSync(path);
|
|
389
|
+
}
|
|
390
|
+
catch (err) {
|
|
391
|
+
if (isAbsentErrno(err))
|
|
392
|
+
return null;
|
|
393
|
+
bail(`cannot stat ${label} at ${path}: ${err instanceof Error ? err.message : String(err)} — ` +
|
|
394
|
+
`a path that exists but cannot be read is not the same as an absent one, ` +
|
|
395
|
+
`so this check has not produced a verdict`);
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
/**
|
|
399
|
+
* Does this path exist? Bails when the answer cannot be determined.
|
|
400
|
+
*
|
|
401
|
+
* This replaces every `existsSync` in the module. `existsSync` returns false for
|
|
402
|
+
* "not there" AND for "there, unreadable", and every place that difference was
|
|
403
|
+
* collapsed here became a false green: the source-authority decision fell
|
|
404
|
+
* through to the bundle when the repo's own agent-config was chmod 000, with
|
|
405
|
+
* `sourceOverridden: false` and no caveat.
|
|
406
|
+
*/
|
|
407
|
+
function pathPresent(path, label) {
|
|
408
|
+
return statOrAbsent(path, label) !== null;
|
|
409
|
+
}
|
|
410
|
+
// ── small helpers ───────────────────────────────────────────────────────────
|
|
411
|
+
// ── ONE statement of the symlink rule; every site below is a consumer ───────
|
|
412
|
+
/**
|
|
413
|
+
* THE symlink rule. One statement, one message, one policy — everything else in
|
|
414
|
+
* this module that can encounter a link routes here.
|
|
415
|
+
*
|
|
416
|
+
* It used to be six independent statements of the same sentence: `ent.isLink`
|
|
417
|
+
* bails inside compareFlatDir, compareTree, unionFlat and unionDirs, plus two
|
|
418
|
+
* root-assert shapes — each with its own copy of the message. Six copies is six
|
|
419
|
+
* opportunities for a path that none of them covers, and that is exactly what
|
|
420
|
+
* happened four rounds running: the walked-entry copies never see a directory
|
|
421
|
+
* reached by path construction, and the root-assert copies lstat only the path
|
|
422
|
+
* they are handed, so an INTERMEDIATE component (`mx-agent-system`,
|
|
423
|
+
* `agent-config`, `local`) was traversed silently and an attacker-owned tree
|
|
424
|
+
* certified itself CLEAN. The rule is now stated here and nowhere else; the
|
|
425
|
+
* three entry points below (a walked directory, a constructed root, a whole
|
|
426
|
+
* path) all call it.
|
|
427
|
+
*
|
|
428
|
+
* The wording is generate-claude.mjs's assertNoSymlinksInTree, so the generator
|
|
429
|
+
* and the checker read identically: a tree the generator refuses to deploy from
|
|
430
|
+
* must not be certified OK here.
|
|
431
|
+
*/
|
|
432
|
+
/**
|
|
433
|
+
* How a repo-mode permission root's display names the ref it was read from. Held
|
|
434
|
+
* as a constant because TWO sites depend on the exact text: permissionDisplay
|
|
435
|
+
* writes it, and displayChild below has to keep it LAST when it appends an entry
|
|
436
|
+
* name. A copy in either place drifts silently — the message still renders.
|
|
437
|
+
*/
|
|
438
|
+
const DISPLAY_REF_NOTE = ' (source tree at ';
|
|
439
|
+
/**
|
|
440
|
+
* Append a child entry name to a root DISPLAY.
|
|
441
|
+
*
|
|
442
|
+
* Not `join()`. A display is a path OPTIONALLY followed by the ref note above,
|
|
443
|
+
* so joining puts the entry after the note and produces
|
|
444
|
+
* `.../agent-config/hooks (source tree at origin/main)/evil.sh` — a string that
|
|
445
|
+
* is not a path, reads as two findings, and buries the entry name. The note has
|
|
446
|
+
* to stay last. For every root whose display IS just its path (all six
|
|
447
|
+
* behavioral ones, and both permission roots in bundle mode) this is exactly
|
|
448
|
+
* `${display}/${name}`.
|
|
449
|
+
*/
|
|
450
|
+
function displayChild(display, name) {
|
|
451
|
+
const at = display.indexOf(DISPLAY_REF_NOTE);
|
|
452
|
+
return at === -1 ? `${display}/${name}` : `${display.slice(0, at)}/${name}${display.slice(at)}`;
|
|
453
|
+
}
|
|
454
|
+
function bailSymlink(path, treeLabel, plainWhat, displayPath = path) {
|
|
455
|
+
// WHERE IT POINTS, not only where it is (round-5 SF-1). Without the target an
|
|
456
|
+
// operator cannot tell a link that redirects inside the repo from one that
|
|
457
|
+
// redirects to an attacker-owned directory — the two need different responses
|
|
458
|
+
// and the message named neither. readlink is wrapped because this is a
|
|
459
|
+
// MESSAGE, never a verdict: the verdict (COULD_NOT_RUN) is already decided by
|
|
460
|
+
// the time we get here, and a link that cannot be read must not change it.
|
|
461
|
+
let target = '';
|
|
462
|
+
try {
|
|
463
|
+
target = ` -> ${readlinkSync(path)}`;
|
|
464
|
+
}
|
|
465
|
+
catch {
|
|
466
|
+
/* unreadable link target — the finding stands without it */
|
|
467
|
+
}
|
|
468
|
+
bail(`FAIL-CLOSED — symlink found in ${treeLabel} at ${displayPath}${target}; ` +
|
|
469
|
+
`the generator refuses to emit or follow symlinks. Replace it with a plain ${plainWhat}.`);
|
|
470
|
+
}
|
|
471
|
+
/**
|
|
472
|
+
* ENTRY POINT 1 — a WALKED source directory. Listing and the symlink rule are
|
|
473
|
+
* one operation, because every caller did both and a caller that forgot the
|
|
474
|
+
* second was a hole. There is deliberately no way to list a source directory
|
|
475
|
+
* without applying the rule: the returned entries carry no `isLink` field at
|
|
476
|
+
* all, so a future walk cannot re-derive its own copy of the decision.
|
|
477
|
+
*
|
|
478
|
+
* Shares its errno classification with every other filesystem probe here
|
|
479
|
+
* (isAbsentErrno) rather than restating it: an absent directory is legitimately
|
|
480
|
+
* empty, an unreadable one must never contribute a silent zero to a CLEAN
|
|
481
|
+
* verdict.
|
|
482
|
+
*/
|
|
483
|
+
function listSourceEntries(dir,
|
|
484
|
+
/**
|
|
485
|
+
* How BOTH bails on this function name what they found — the unreadable-directory
|
|
486
|
+
* bail names this directory, the per-entry symlink bail names `display/<entry>` —
|
|
487
|
+
* see FidelityRoot.display. For
|
|
488
|
+
* a permission-layer root in repo mode `dir` is inside the `git archive`
|
|
489
|
+
* staging tree, which is deleted before the message is read and names no ref
|
|
490
|
+
* (round-7 SF-3). Every caller threads its root's display through.
|
|
491
|
+
*/
|
|
492
|
+
display = dir) {
|
|
493
|
+
let raw;
|
|
494
|
+
try {
|
|
495
|
+
raw = readdirSync(dir, { withFileTypes: true });
|
|
496
|
+
}
|
|
497
|
+
catch (err) {
|
|
498
|
+
if (isAbsentErrno(err))
|
|
499
|
+
return [];
|
|
500
|
+
bail(`cannot read directory ${display}: ${err instanceof Error ? err.message : String(err)}`);
|
|
501
|
+
}
|
|
502
|
+
return raw.map((e) => {
|
|
503
|
+
if (e.isSymbolicLink())
|
|
504
|
+
bailSymlink(join(dir, e.name), 'source tree', e.isDirectory() ? 'directory' : 'file',
|
|
505
|
+
// Same display as the unreadable bail above, one level down: the two bails
|
|
506
|
+
// on this one function must name an entry the same way (round-9 SF-4).
|
|
507
|
+
displayChild(display, e.name));
|
|
508
|
+
return { name: e.name, isFile: e.isFile(), isDir: e.isDirectory() };
|
|
509
|
+
});
|
|
510
|
+
}
|
|
511
|
+
/**
|
|
512
|
+
* ENTRY POINT 2 — a single path reached by CONSTRUCTION rather than by a walk
|
|
513
|
+
* (the six layer roots, `.claude` itself). Returns the Stats when the path is a
|
|
514
|
+
* real entry, null when it is absent; bails when it is a symlink or unreadable.
|
|
515
|
+
*
|
|
516
|
+
* Used on BOTH trees: the source side is the caller's `'source tree'` label, the
|
|
517
|
+
* deployed layer roots pass `'deployed tree'`.
|
|
518
|
+
*/
|
|
519
|
+
function assertNotSymlink(path, treeLabel, plainWhat, displayPath = path) {
|
|
520
|
+
// Same absent-vs-unreadable rule as everything else in this module — see
|
|
521
|
+
// statOrAbsent. This function used to carry its own copy of it.
|
|
522
|
+
const st = statOrAbsent(path, `${treeLabel} entry`);
|
|
523
|
+
if (st === null)
|
|
524
|
+
return null;
|
|
525
|
+
// `displayPath` exists for ONE caller: the git-archive staging tree, whose
|
|
526
|
+
// real path is an ephemeral `/tmp/mx-fidelity-XXXX/...` that cleanup() deletes
|
|
527
|
+
// before an operator can read the message. The link is read from the real
|
|
528
|
+
// path; the message names the repo-relative one. See archiveRef.
|
|
529
|
+
if (st.isSymbolicLink())
|
|
530
|
+
bailSymlink(path, treeLabel, plainWhat, displayPath);
|
|
531
|
+
return st;
|
|
532
|
+
}
|
|
533
|
+
/**
|
|
534
|
+
* ENTRY POINT 3 — the SOURCE-side counterpart of deployedIsPlain: EVERY path
|
|
535
|
+
* component under `base`, not the leaf.
|
|
536
|
+
*
|
|
537
|
+
* This is the round-5 Must Fix. `assertNotSymlink` lstats the path it is given
|
|
538
|
+
* and nothing above it, so `lstat("<...>/local/agents")` follows a symlinked
|
|
539
|
+
* `local` and reports a real directory. Three executed shapes reached
|
|
540
|
+
* `CLEAN / exit 0` over a deployed `security-reviewer.md` whose `tools:` grant
|
|
541
|
+
* had been rewritten, with nothing in the output naming the attacker directory:
|
|
542
|
+
* `agent-config/local` symlinked (the overlay wins the union, so it shadows the
|
|
543
|
+
* base file), `mx-agent-system/agent-config` symlinked, and the intermediate
|
|
544
|
+
* `mx-agent-system` symlinked. In bundle mode `permissionDir = sourceDir`, so a
|
|
545
|
+
* redirected component takes settings.json and hooks/ with it.
|
|
546
|
+
*
|
|
547
|
+
* ORDERING IS LOAD-BEARING: `samePath` canonicalises through `realpathSync`, so
|
|
548
|
+
* a symlinked source root still resolves to `authority: 'repo-tree'` and the
|
|
549
|
+
* override caveat never fires. This walk must run BEFORE mode derivation.
|
|
550
|
+
*/
|
|
551
|
+
function assertPlainPathTo(base, relPath, treeLabel, hideBase = false) {
|
|
552
|
+
let cur = base;
|
|
553
|
+
let shown = '';
|
|
554
|
+
for (const seg of relPath.split('/')) {
|
|
555
|
+
if (seg === '')
|
|
556
|
+
continue;
|
|
557
|
+
cur = join(cur, seg);
|
|
558
|
+
shown = shown === '' ? seg : `${shown}/${seg}`;
|
|
559
|
+
// Bails on a link, returns null on an absent component — an absent path is
|
|
560
|
+
// some other check's finding, never this one's.
|
|
561
|
+
// `hideBase` is for the git-archive staging tree only: its base is a temp
|
|
562
|
+
// directory that is deleted before the message is read, so the reported path
|
|
563
|
+
// is relative to the tree the operator can actually inspect.
|
|
564
|
+
assertNotSymlink(cur, treeLabel, 'directory', hideBase ? shown : cur);
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
/**
|
|
568
|
+
* Assert that a LAYER ROOT is a real directory and not a symlink, on either
|
|
569
|
+
* side. Returns true when the directory is present, false when it is absent.
|
|
570
|
+
*
|
|
571
|
+
* A consumer of entry point 2, not a statement of the rule. The six layer roots
|
|
572
|
+
* are reached by path construction, never by a walk, so nothing else lstats them
|
|
573
|
+
* — a symlinked `agent-config/hooks` (or `.claude/hooks`) pointed at an empty
|
|
574
|
+
* directory outside the repo made the whole layer vanish with the verdict still
|
|
575
|
+
* CLEAN.
|
|
576
|
+
*/
|
|
577
|
+
function assertRealDir(dir, treeLabel,
|
|
578
|
+
/**
|
|
579
|
+
* How the NOT-A-DIRECTORY and symlink bails name this root — see
|
|
580
|
+
* FidelityRoot.display. The permission roots live inside the `git archive`
|
|
581
|
+
* staging tree in repo mode, so the raw `dir` is a `/tmp/mx-fidelity-XXXX/...`
|
|
582
|
+
* path cleanup() deletes before the line reaches a terminal, and it names no
|
|
583
|
+
* ref (round-8 SF-2, the same defect as round-7 SF-3 at a third bail).
|
|
584
|
+
* Provoked: `agent-config/hooks` committed to origin/main as a plain FILE —
|
|
585
|
+
* git records file-vs-directory — printed `source tree entry
|
|
586
|
+
* /tmp/mx-fidelity-llga1Y/mx-agent-system/agent-config/hooks exists but is not
|
|
587
|
+
* a directory`.
|
|
588
|
+
*/
|
|
589
|
+
display = dir) {
|
|
590
|
+
const st = assertNotSymlink(dir, treeLabel, 'directory', display);
|
|
591
|
+
if (st === null)
|
|
592
|
+
return false;
|
|
593
|
+
if (!st.isDirectory())
|
|
594
|
+
bail(`${treeLabel} entry ${display} exists but is not a directory`);
|
|
595
|
+
return true;
|
|
596
|
+
}
|
|
597
|
+
/**
|
|
598
|
+
* The FILE-root counterpart of assertRealDir. Today that is settings.json.
|
|
599
|
+
*
|
|
600
|
+
* `display` names the root the way assertRealDir's does — see FidelityRoot.display.
|
|
601
|
+
* In repo mode the settings.json root lives inside the `git archive` staging tree,
|
|
602
|
+
* so the raw `path` is a `/tmp/mx-fidelity-XXXX/...` path cleanup() deletes before
|
|
603
|
+
* the line reaches a terminal, and it names no ref (round-9 SF-3, the same defect
|
|
604
|
+
* as round-7 SF-3 and round-8 SF-2 at a fourth bail). Provoked: `settings.json`
|
|
605
|
+
* committed to origin/main as a SYMLINK — git records mode 120000 and
|
|
606
|
+
* `git archive | tar` recreates the link.
|
|
607
|
+
*/
|
|
608
|
+
function assertRealFile(path, treeLabel, display = path) {
|
|
609
|
+
return assertNotSymlink(path, treeLabel, 'file', display) !== null;
|
|
610
|
+
}
|
|
611
|
+
function samePath(a, b) {
|
|
612
|
+
const canon = (p) => {
|
|
613
|
+
try {
|
|
614
|
+
return realpathSync(p);
|
|
615
|
+
}
|
|
616
|
+
catch {
|
|
617
|
+
return resolve(p);
|
|
618
|
+
}
|
|
619
|
+
};
|
|
620
|
+
return canon(a) === canon(b);
|
|
621
|
+
}
|
|
622
|
+
/** Thrown internally to abort with COULD_NOT_RUN; never escapes this module. */
|
|
623
|
+
class CouldNotRun extends Error {
|
|
624
|
+
}
|
|
625
|
+
function bail(reason) {
|
|
626
|
+
throw new CouldNotRun(reason);
|
|
627
|
+
}
|
|
628
|
+
/**
|
|
629
|
+
* Order-insensitive structural equality for parsed JSON. Object key ORDER and
|
|
630
|
+
* source indentation are irrelevant — a JSON writer is free to change both, and
|
|
631
|
+
* a byte comparison of settings.json would go red on a reformat while staying
|
|
632
|
+
* green on a removed hook registration. Array order IS significant: hook
|
|
633
|
+
* registration order is semantic.
|
|
634
|
+
*/
|
|
635
|
+
export function jsonDeepEqual(a, b) {
|
|
636
|
+
if (a === b)
|
|
637
|
+
return true;
|
|
638
|
+
if (typeof a !== typeof b)
|
|
639
|
+
return false;
|
|
640
|
+
if (a === null || b === null)
|
|
641
|
+
return a === b;
|
|
642
|
+
if (Array.isArray(a) || Array.isArray(b)) {
|
|
643
|
+
if (!Array.isArray(a) || !Array.isArray(b) || a.length !== b.length)
|
|
644
|
+
return false;
|
|
645
|
+
return a.every((v, i) => jsonDeepEqual(v, b[i]));
|
|
646
|
+
}
|
|
647
|
+
if (typeof a === 'object') {
|
|
648
|
+
const ao = a;
|
|
649
|
+
const bo = b;
|
|
650
|
+
const ak = Object.keys(ao).sort();
|
|
651
|
+
const bk = Object.keys(bo).sort();
|
|
652
|
+
if (ak.length !== bk.length || ak.some((k, i) => k !== bk[i]))
|
|
653
|
+
return false;
|
|
654
|
+
return ak.every((k) => jsonDeepEqual(ao[k], bo[k]));
|
|
655
|
+
}
|
|
656
|
+
return false;
|
|
657
|
+
}
|
|
658
|
+
/**
|
|
659
|
+
* The top-level settings.json keys whose values differ, so the mismatch names
|
|
660
|
+
* WHAT drifted rather than only THAT something did. Keys present on one side
|
|
661
|
+
* only are included.
|
|
662
|
+
*/
|
|
663
|
+
function differingTopLevelKeys(source, deployed) {
|
|
664
|
+
if (typeof source !== 'object' || source === null || Array.isArray(source))
|
|
665
|
+
return [];
|
|
666
|
+
if (typeof deployed !== 'object' || deployed === null || Array.isArray(deployed))
|
|
667
|
+
return [];
|
|
668
|
+
const s = source;
|
|
669
|
+
const d = deployed;
|
|
670
|
+
const keys = new Set([...Object.keys(s), ...Object.keys(d)]);
|
|
671
|
+
return [...keys].filter((k) => !jsonDeepEqual(s[k], d[k])).sort();
|
|
672
|
+
}
|
|
673
|
+
// ── git archive of the permission layer ─────────────────────────────────────
|
|
674
|
+
/** Wall-clock cap on each subprocess this module spawns. */
|
|
675
|
+
const ARCHIVE_TIMEOUT_MS = 15_000;
|
|
676
|
+
/** Cap on the archive read. 131 entries in this repo; 32MB is ample. */
|
|
677
|
+
const ARCHIVE_MAX_BUFFER_BYTES = 32 * 1024 * 1024;
|
|
678
|
+
/**
|
|
679
|
+
* Stage `<ref>:<configSource>` into a fresh temp dir via `git archive` — the
|
|
680
|
+
* same mechanism generate-claude.mjs's withArchivedConfig uses, so the bytes
|
|
681
|
+
* compared are the bytes the generator would have written.
|
|
682
|
+
*
|
|
683
|
+
* Deliberately does NOT fetch. A checker must not perform network I/O as a side
|
|
684
|
+
* effect; if origin/<base> is not present locally the verdict is COULD_NOT_RUN
|
|
685
|
+
* with a reason that names the fetch.
|
|
686
|
+
*/
|
|
687
|
+
function archiveRef(repoRoot, ref, configSource) {
|
|
688
|
+
const staging = mkdtempSync(join(tmpdir(), 'mx-fidelity-'));
|
|
689
|
+
const cleanup = () => {
|
|
690
|
+
try {
|
|
691
|
+
rmSync(staging, { recursive: true, force: true });
|
|
692
|
+
}
|
|
693
|
+
catch {
|
|
694
|
+
/* best-effort */
|
|
695
|
+
}
|
|
696
|
+
};
|
|
697
|
+
// TIMEOUTS ARE MANDATORY HERE. start.ts runs this synchronously before the
|
|
698
|
+
// session launches, so a git or tar that never returns — a stalled network
|
|
699
|
+
// filesystem, a stuck lock — hangs session start, and the try/catch in
|
|
700
|
+
// checkConfigFidelity catches throws, not hangs. Same rule doctor.ts states
|
|
701
|
+
// for its own collectors: a stalled filesystem must never hang a session. On
|
|
702
|
+
// timeout spawnSync returns a non-zero/null status, which the existing
|
|
703
|
+
// failure path below turns into COULD_NOT_RUN.
|
|
704
|
+
//
|
|
705
|
+
// maxBuffer is 32MB, not 256MB: this repo's agent-config archive is 131
|
|
706
|
+
// entries, and the cap exists to stop an unbounded read into memory on a
|
|
707
|
+
// shared VM, not to accommodate an archive we would never legitimately have.
|
|
708
|
+
const archive = spawnSync('git', ['archive', '--format=tar', ref, '--', configSource], {
|
|
709
|
+
cwd: repoRoot,
|
|
710
|
+
encoding: 'buffer',
|
|
711
|
+
maxBuffer: ARCHIVE_MAX_BUFFER_BYTES,
|
|
712
|
+
timeout: ARCHIVE_TIMEOUT_MS,
|
|
713
|
+
});
|
|
714
|
+
if (archive.status !== 0 || !archive.stdout || archive.stdout.length === 0) {
|
|
715
|
+
cleanup();
|
|
716
|
+
const msg = archive.stderr ? archive.stderr.toString().trim() : `git archive ${ref} failed`;
|
|
717
|
+
bail(`cannot read the permission layer from ${ref} — ${msg}. ` +
|
|
718
|
+
`Fetch it first: git -C ${repoRoot} fetch origin`);
|
|
719
|
+
}
|
|
720
|
+
const extract = spawnSync('tar', ['-x', '-C', staging], {
|
|
721
|
+
input: archive.stdout,
|
|
722
|
+
maxBuffer: ARCHIVE_MAX_BUFFER_BYTES,
|
|
723
|
+
timeout: ARCHIVE_TIMEOUT_MS,
|
|
724
|
+
});
|
|
725
|
+
if (extract.status !== 0) {
|
|
726
|
+
cleanup();
|
|
727
|
+
bail(`cannot extract the archive of ${ref}:${configSource}`);
|
|
728
|
+
}
|
|
729
|
+
// The same component walk the working tree gets, on the STAGED tree. `git
|
|
730
|
+
// archive | tar` faithfully recreates a committed symlink, including one at an
|
|
731
|
+
// intermediate component of configSource, and the working-tree walk says
|
|
732
|
+
// nothing about what origin/<base> holds. Cleanup is the caller's, and it runs
|
|
733
|
+
// in checkConfigFidelity's `finally`, so a bail here still removes the staging
|
|
734
|
+
// dir — assign it before this can throw.
|
|
735
|
+
//
|
|
736
|
+
// The tree label NAMES THE REF and the path is repo-relative (round-5 SF-2).
|
|
737
|
+
// This bail used to read `symlink found in source tree at
|
|
738
|
+
// /tmp/mx-fidelity-XXXX/mx-agent-system/agent-config`, which is wrong twice
|
|
739
|
+
// over: the staging directory is deleted by cleanup() before an operator reads
|
|
740
|
+
// the line, and `source tree` sends them to their WORKING tree, where there is
|
|
741
|
+
// nothing to find — the symlink is at origin/<base>. It now reads
|
|
742
|
+
// `symlink found in source tree at origin/main at mx-agent-system/agent-config`.
|
|
743
|
+
try {
|
|
744
|
+
assertPlainPathTo(staging, configSource, `source tree at ${ref}`, true);
|
|
745
|
+
}
|
|
746
|
+
catch (err) {
|
|
747
|
+
cleanup();
|
|
748
|
+
throw err;
|
|
749
|
+
}
|
|
750
|
+
return { dir: join(staging, configSource), cleanup };
|
|
751
|
+
}
|
|
752
|
+
/** Record one comparison against the total, its layer and its source root. */
|
|
753
|
+
function countComparison(ctx, layer, rootPath) {
|
|
754
|
+
ctx.compared++;
|
|
755
|
+
ctx.perLayer[layer]++;
|
|
756
|
+
if (rootPath !== null)
|
|
757
|
+
countRootEntry(ctx, rootPath);
|
|
758
|
+
}
|
|
759
|
+
/**
|
|
760
|
+
* Record that a source root yielded one entry. Called from the ENUMERATION
|
|
761
|
+
* sites only — the flat/tree walks via countComparison, and the union builders
|
|
762
|
+
* directly (a shadowed entry is enumerated but never compared).
|
|
763
|
+
*/
|
|
764
|
+
function countRootEntry(ctx, rootPath) {
|
|
765
|
+
ctx.rootEntries.set(rootPath, (ctx.rootEntries.get(rootPath) ?? 0) + 1);
|
|
766
|
+
}
|
|
767
|
+
/**
|
|
768
|
+
* EVERY deployed path this module touches is a plain file or plain directory —
|
|
769
|
+
* one rule, applied to every path COMPONENT, in one place.
|
|
770
|
+
*
|
|
771
|
+
* The rule used to exist as three independent per-site copies (assertRealDir for
|
|
772
|
+
* the six layer roots, `ent.isLink` for walked SOURCE entries, and an
|
|
773
|
+
* `st.isSymbolicLink()` on the leaf inside compareFile), and the paths no copy
|
|
774
|
+
* covered were the defect. Two of them:
|
|
775
|
+
* • `.claude/settings.json` — compareSettings only asked whether it was
|
|
776
|
+
* absent, so readFileSync followed a symlink there and the run was CLEAN.
|
|
777
|
+
* • an INTERMEDIATE directory, e.g. `.claude/skills/<name>` — neither a layer
|
|
778
|
+
* root (only the layer's own root is lstat'd) nor the final component (all
|
|
779
|
+
* compareFile lstat'd), so it was traversed silently.
|
|
780
|
+
* In both, content is read THROUGH the link, so the bytes match and the redirect
|
|
781
|
+
* itself is the undetected fact: the effective config becomes a file outside the
|
|
782
|
+
* tree this check just blessed, which is precisely what an adversary with write
|
|
783
|
+
* access to `.claude/` wants. The module header already declared the policy
|
|
784
|
+
* ("a symlink in the source tree or at a layer root on either side" →
|
|
785
|
+
* COULD_NOT_RUN); the code disagreed with its own contract.
|
|
786
|
+
*
|
|
787
|
+
* ABSENCE is deliberately NOT decided here — it is the caller's `missing`
|
|
788
|
+
* finding. Two places deciding what absence means is how this rule fragmented.
|
|
789
|
+
*/
|
|
790
|
+
function deployedIsPlain(ctx, relPath, layer, ref) {
|
|
791
|
+
const segments = relPath.split('/');
|
|
792
|
+
let cur = ctx.deployedRoot;
|
|
793
|
+
for (const [i, seg] of segments.entries()) {
|
|
794
|
+
cur = join(cur, seg);
|
|
795
|
+
const st = statOrAbsent(cur, 'deployed tree entry');
|
|
796
|
+
if (st === null)
|
|
797
|
+
return true; // absent — the caller reports it as `missing`
|
|
798
|
+
if (st.isSymbolicLink()) {
|
|
799
|
+
ctx.mismatches.push({
|
|
800
|
+
path: relPath,
|
|
801
|
+
layer,
|
|
802
|
+
ref,
|
|
803
|
+
kind: 'differs',
|
|
804
|
+
detail: i === segments.length - 1
|
|
805
|
+
? 'deployed entry is a symlink'
|
|
806
|
+
: `deployed path component ${seg} is a symlink`,
|
|
807
|
+
});
|
|
808
|
+
return false;
|
|
809
|
+
}
|
|
810
|
+
}
|
|
811
|
+
return true;
|
|
812
|
+
}
|
|
813
|
+
function compareFile(ctx, sourcePath, relPath, layer, ref,
|
|
814
|
+
/**
|
|
815
|
+
* The source root this file was enumerated under, or null when the enumeration
|
|
816
|
+
* already counted it (the union builders, which must count SHADOWED entries
|
|
817
|
+
* too). Not optional: a caller that forgets it is how the per-root floor would
|
|
818
|
+
* silently stop counting a root.
|
|
819
|
+
*/
|
|
820
|
+
rootPath) {
|
|
821
|
+
countComparison(ctx, layer, rootPath);
|
|
822
|
+
ctx.accountedFor.add(relPath);
|
|
823
|
+
const deployedPath = join(ctx.deployedRoot, relPath);
|
|
824
|
+
// The one deployed-side symlink rule, over every component — not the leaf
|
|
825
|
+
// alone. The generator emits plain files and plain directories only; a symlink
|
|
826
|
+
// anywhere on the path is not the artifact the source describes, whatever it
|
|
827
|
+
// happens to resolve to.
|
|
828
|
+
if (!deployedIsPlain(ctx, relPath, layer, ref))
|
|
829
|
+
return;
|
|
830
|
+
// Absence is decided HERE, not in deployedIsPlain — see its note.
|
|
831
|
+
try {
|
|
832
|
+
lstatSync(deployedPath);
|
|
833
|
+
}
|
|
834
|
+
catch {
|
|
835
|
+
ctx.mismatches.push({ path: relPath, layer, ref, kind: 'missing' });
|
|
836
|
+
return;
|
|
837
|
+
}
|
|
838
|
+
let sourceBytes;
|
|
839
|
+
let deployedBytes;
|
|
840
|
+
try {
|
|
841
|
+
sourceBytes = readFileSync(sourcePath);
|
|
842
|
+
}
|
|
843
|
+
catch (err) {
|
|
844
|
+
bail(`cannot read source file ${sourcePath}: ${err instanceof Error ? err.message : String(err)}`);
|
|
845
|
+
}
|
|
846
|
+
try {
|
|
847
|
+
deployedBytes = readFileSync(deployedPath);
|
|
848
|
+
}
|
|
849
|
+
catch (err) {
|
|
850
|
+
ctx.mismatches.push({
|
|
851
|
+
path: relPath,
|
|
852
|
+
layer,
|
|
853
|
+
ref,
|
|
854
|
+
kind: 'differs',
|
|
855
|
+
detail: `deployed file unreadable: ${err instanceof Error ? err.message : String(err)}`,
|
|
856
|
+
});
|
|
857
|
+
return;
|
|
858
|
+
}
|
|
859
|
+
if (!sourceBytes.equals(deployedBytes)) {
|
|
860
|
+
ctx.mismatches.push({
|
|
861
|
+
path: relPath,
|
|
862
|
+
layer,
|
|
863
|
+
ref,
|
|
864
|
+
kind: 'differs',
|
|
865
|
+
detail: `${sourceBytes.length} source bytes vs ${deployedBytes.length} deployed`,
|
|
866
|
+
});
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
/**
|
|
870
|
+
* Compare a source directory of top-level FILES against `.claude/<relDir>`.
|
|
871
|
+
* Mirrors the generator, which copies `if (!ent.isFile()) continue;` at this
|
|
872
|
+
* level — a stray subdirectory under hooks/ or agents/ is not deployed, so it
|
|
873
|
+
* must not be asserted.
|
|
874
|
+
*/
|
|
875
|
+
function compareFlatDir(ctx, root, relDir, layer, ref) {
|
|
876
|
+
// listSourceEntries applies the one symlink rule; there is no per-site copy of
|
|
877
|
+
// it here any more, and no `isLink` on the entry to write one against.
|
|
878
|
+
for (const ent of listSourceEntries(root.path, root.display)) {
|
|
879
|
+
if (!ent.isFile)
|
|
880
|
+
continue;
|
|
881
|
+
compareFile(ctx, join(root.path, ent.name), `${relDir}/${ent.name}`, layer, ref, root.path);
|
|
882
|
+
}
|
|
883
|
+
}
|
|
884
|
+
/**
|
|
885
|
+
* Compare a source directory recursively (files at every depth).
|
|
886
|
+
*
|
|
887
|
+
* `rootPath` is the ROOT the subtree belongs to, not the subtree itself, so the
|
|
888
|
+
* per-root floor counts the root a skill directory came from rather than the
|
|
889
|
+
* skill.
|
|
890
|
+
*/
|
|
891
|
+
function compareTree(ctx, sourceDir,
|
|
892
|
+
/** Display name for sourceDir — see listSourceEntries. Descends with the walk. */
|
|
893
|
+
displayDir, relDir, layer, ref, rootPath) {
|
|
894
|
+
for (const ent of listSourceEntries(sourceDir, displayDir)) {
|
|
895
|
+
const rel = `${relDir}/${ent.name}`;
|
|
896
|
+
const abs = join(sourceDir, ent.name);
|
|
897
|
+
const shown = `${displayDir}/${ent.name}`;
|
|
898
|
+
if (ent.isDir)
|
|
899
|
+
compareTree(ctx, abs, shown, rel, layer, ref, rootPath);
|
|
900
|
+
else if (ent.isFile)
|
|
901
|
+
compareFile(ctx, abs, rel, layer, ref, rootPath);
|
|
902
|
+
}
|
|
903
|
+
}
|
|
904
|
+
/**
|
|
905
|
+
* Resolve the winning source path for each top-level file name across base and
|
|
906
|
+
* overlay. Overlay wins on a collision, matching the generator's last-write-wins
|
|
907
|
+
* union — assert against the winner only, or a shadowed base file produces a
|
|
908
|
+
* mismatch for a file that was never supposed to deploy.
|
|
909
|
+
*
|
|
910
|
+
* Takes the DECLARED roots rather than two bare paths: the roots are the unit
|
|
911
|
+
* the coverage contract is expressed in, and a call site that re-derives them
|
|
912
|
+
* with its own `join()` is a second enumeration of the layer's sources — which
|
|
913
|
+
* is how this layer's contract and its walk drifted apart in the first place.
|
|
914
|
+
* Every enumerated entry is counted against its root, including a shadowed one.
|
|
915
|
+
*/
|
|
916
|
+
function unionFlat(ctx, roots) {
|
|
917
|
+
const winners = new Map();
|
|
918
|
+
for (const root of roots) {
|
|
919
|
+
for (const ent of listSourceEntries(root.path, root.display)) {
|
|
920
|
+
if (!ent.isFile)
|
|
921
|
+
continue;
|
|
922
|
+
countRootEntry(ctx, root.path);
|
|
923
|
+
winners.set(ent.name, {
|
|
924
|
+
path: join(root.path, ent.name),
|
|
925
|
+
root: root.path,
|
|
926
|
+
display: `${root.display}/${ent.name}`,
|
|
927
|
+
});
|
|
928
|
+
}
|
|
929
|
+
}
|
|
930
|
+
return winners;
|
|
931
|
+
}
|
|
932
|
+
/** Same union, for skills — whose unit is a top-level DIRECTORY, copied recursively. */
|
|
933
|
+
function unionDirs(ctx, roots) {
|
|
934
|
+
const winners = new Map();
|
|
935
|
+
for (const root of roots) {
|
|
936
|
+
for (const ent of listSourceEntries(root.path, root.display)) {
|
|
937
|
+
if (!ent.isDir)
|
|
938
|
+
continue;
|
|
939
|
+
countRootEntry(ctx, root.path);
|
|
940
|
+
winners.set(ent.name, {
|
|
941
|
+
path: join(root.path, ent.name),
|
|
942
|
+
root: root.path,
|
|
943
|
+
display: `${root.display}/${ent.name}`,
|
|
944
|
+
});
|
|
945
|
+
}
|
|
946
|
+
}
|
|
947
|
+
return winners;
|
|
948
|
+
}
|
|
949
|
+
/**
|
|
950
|
+
* List a DEPLOYED directory for the reverse-inclusion pass.
|
|
951
|
+
*
|
|
952
|
+
* Deliberately NOT listSourceEntries: a symlink on the source side is
|
|
953
|
+
* COULD_NOT_RUN, a symlink on the deployed side is DRIFT (see deployedIsPlain),
|
|
954
|
+
* and routing the deployed walk through the source rule would turn every
|
|
955
|
+
* deployed link into a fail-closed bail. A symlinked dirent reports
|
|
956
|
+
* `isDirectory() === false` (readdir lstats), so it is treated as a LEAF and is
|
|
957
|
+
* never traversed — the walk cannot be led outside `.claude/<layer>/`.
|
|
958
|
+
*
|
|
959
|
+
* Absent is empty; UNREADABLE bails, by the same one classifier every other
|
|
960
|
+
* probe in this module uses. An unreadable deployed layer directory must not
|
|
961
|
+
* quietly contribute "no extras found".
|
|
962
|
+
*/
|
|
963
|
+
function listDeployedEntries(dir) {
|
|
964
|
+
let raw;
|
|
965
|
+
try {
|
|
966
|
+
raw = readdirSync(dir, { withFileTypes: true });
|
|
967
|
+
}
|
|
968
|
+
catch (err) {
|
|
969
|
+
if (isAbsentErrno(err))
|
|
970
|
+
return [];
|
|
971
|
+
bail(`cannot read deployed directory ${dir}: ${err instanceof Error ? err.message : String(err)}`);
|
|
972
|
+
}
|
|
973
|
+
return raw.map((e) => ({ name: e.name, isDir: e.isDirectory() }));
|
|
974
|
+
}
|
|
975
|
+
/**
|
|
976
|
+
* REVERSE INCLUSION for one required layer: every file under `.claude/<layer>/`
|
|
977
|
+
* that the forward pass did not account for is a deployed artifact no source
|
|
978
|
+
* root mentions.
|
|
979
|
+
*
|
|
980
|
+
* `ctx.accountedFor` is the forward pass's own record, so the two directions
|
|
981
|
+
* cannot disagree about what the source set was — a second derivation of the
|
|
982
|
+
* source union here would be one more copy of a rule this module has already
|
|
983
|
+
* fragmented twice.
|
|
984
|
+
*
|
|
985
|
+
* TRAVERSAL SCOPE: rooted at `.claude/<layer>` for the directory layers whose
|
|
986
|
+
* source root is present (the caller skips `absentOptionalLayers`).
|
|
987
|
+
* `.claude/worktrees/**` (foreign agent checkouts) and the top level of
|
|
988
|
+
* `.claude/` (settings.local.json, scheduled_tasks.lock) are outside every one of
|
|
989
|
+
* those roots and are never visited. Do not widen this to `.claude/` itself —
|
|
990
|
+
* that walk hard-blocked customer-portal session starts on 2026-08-01.
|
|
991
|
+
*/
|
|
992
|
+
function reportUnaccountedDeployed(ctx, layer) {
|
|
993
|
+
const walk = (relDir) => {
|
|
994
|
+
for (const ent of listDeployedEntries(join(ctx.deployedRoot, relDir))) {
|
|
995
|
+
const rel = `${relDir}/${ent.name}`;
|
|
996
|
+
if (ent.isDir) {
|
|
997
|
+
walk(rel);
|
|
998
|
+
continue;
|
|
999
|
+
}
|
|
1000
|
+
if (ctx.accountedFor.has(rel))
|
|
1001
|
+
continue;
|
|
1002
|
+
ctx.mismatches.push({
|
|
1003
|
+
path: rel,
|
|
1004
|
+
layer,
|
|
1005
|
+
// NO REF (round-7 SF-5). This finding is not a comparison against a ref:
|
|
1006
|
+
// nothing in the source union names this path, so there is nothing at
|
|
1007
|
+
// origin/<base> or in the working tree it was measured against. The line
|
|
1008
|
+
// used to read `deployed differs from source@origin/main`, which sends an
|
|
1009
|
+
// operator to diff against a ref where there is nothing to find.
|
|
1010
|
+
kind: 'unaccounted',
|
|
1011
|
+
// A SYMLINKED deployed directory reads as a leaf here (readdir lstats),
|
|
1012
|
+
// so a redirected `skills/<name>` reached this branch and was reported as
|
|
1013
|
+
// `deployed file has no source counterpart` — untrue, and it sorted FIRST,
|
|
1014
|
+
// so it was the headline finding (round-7 SF-4). The source counterpart
|
|
1015
|
+
// exists; what is wrong is that the deployed entry is not a directory.
|
|
1016
|
+
// The forward pass reports the redirect itself, per file, from
|
|
1017
|
+
// deployedIsPlain.
|
|
1018
|
+
detail: sourceHasChildrenUnder(ctx, rel)
|
|
1019
|
+
? 'deployed entry is not a directory, but the source has files under this path ' +
|
|
1020
|
+
'(a symlinked directory reads as a leaf here)'
|
|
1021
|
+
: 'deployed file has no source counterpart',
|
|
1022
|
+
});
|
|
1023
|
+
}
|
|
1024
|
+
};
|
|
1025
|
+
walk(layer);
|
|
1026
|
+
}
|
|
1027
|
+
/**
|
|
1028
|
+
* Did the forward pass account for any file BENEATH this deployed path?
|
|
1029
|
+
*
|
|
1030
|
+
* The reverse pass matches whole paths against `ctx.accountedFor`, which holds
|
|
1031
|
+
* FILES only, so a deployed directory name never matches and a directory that
|
|
1032
|
+
* arrives here as a leaf looks unaccounted. This distinguishes "no source
|
|
1033
|
+
* counterpart" from "source counterpart exists and is a directory".
|
|
1034
|
+
*/
|
|
1035
|
+
function sourceHasChildrenUnder(ctx, rel) {
|
|
1036
|
+
const prefix = `${rel}/`;
|
|
1037
|
+
for (const p of ctx.accountedFor) {
|
|
1038
|
+
if (p.startsWith(prefix))
|
|
1039
|
+
return true;
|
|
1040
|
+
}
|
|
1041
|
+
return false;
|
|
1042
|
+
}
|
|
1043
|
+
/**
|
|
1044
|
+
* Resolve the agent-config source to compare against. See the RESOLUTION ORDER
|
|
1045
|
+
* note in the file header for why the repo's own tree outranks the CLI bundle
|
|
1046
|
+
* here, the reverse of bundled-config.ts's order.
|
|
1047
|
+
*/
|
|
1048
|
+
function resolveSourceDir(explicit, repoSource) {
|
|
1049
|
+
// In-process option first: it is a call-site decision, not an ambient one. It
|
|
1050
|
+
// is an OVERRIDE all the same unless it names the project's own tree — see
|
|
1051
|
+
// authorityIsOverride. A --source-dir flag that exits 0 against an
|
|
1052
|
+
// operator-named directory is the MX_BUNDLED_CONFIG_DIR bypass with a
|
|
1053
|
+
// different spelling.
|
|
1054
|
+
if (explicit) {
|
|
1055
|
+
return { dir: explicit, authority: samePath(explicit, repoSource) ? 'repo-tree' : 'explicit' };
|
|
1056
|
+
}
|
|
1057
|
+
// The project's own tree OUTRANKS the environment override. A verifier whose
|
|
1058
|
+
// ground truth is env-settable verifies nothing: pointing the variable at a
|
|
1059
|
+
// copy of a tampered deployment made that deployment certify itself.
|
|
1060
|
+
//
|
|
1061
|
+
// pathPresent, NOT existsSync: existsSync answers false when the tree exists
|
|
1062
|
+
// and cannot be read, so `chmod 000 mx-agent-system/agent-config` used to
|
|
1063
|
+
// demote the project's own source silently and let the bundle certify a
|
|
1064
|
+
// tampered deployment CLEAN with no caveat at all.
|
|
1065
|
+
if (pathPresent(join(repoSource, 'settings.json'), 'repo source tree')) {
|
|
1066
|
+
return { dir: repoSource, authority: 'repo-tree' };
|
|
1067
|
+
}
|
|
1068
|
+
const envDir = process.env.MX_BUNDLED_CONFIG_DIR;
|
|
1069
|
+
if (envDir && pathPresent(envDir, 'MX_BUNDLED_CONFIG_DIR source')) {
|
|
1070
|
+
return { dir: envDir, authority: 'env-override' };
|
|
1071
|
+
}
|
|
1072
|
+
return { dir: getBundledConfigDir(), authority: 'bundle' };
|
|
1073
|
+
}
|
|
1074
|
+
/**
|
|
1075
|
+
* Which authorities mean "someone outside the project chose what correct is".
|
|
1076
|
+
* Both force exit 2 on an otherwise-CLEAN comparison and both print a caveat.
|
|
1077
|
+
*/
|
|
1078
|
+
function authorityIsOverride(authority) {
|
|
1079
|
+
return authority === 'env-override' || authority === 'explicit';
|
|
1080
|
+
}
|
|
1081
|
+
/** How the caveat names the authority, so a reader knows who chose the truth. */
|
|
1082
|
+
function authorityLabel(authority) {
|
|
1083
|
+
switch (authority) {
|
|
1084
|
+
case 'env-override':
|
|
1085
|
+
return 'the MX_BUNDLED_CONFIG_DIR environment variable';
|
|
1086
|
+
case 'explicit':
|
|
1087
|
+
return 'an explicitly supplied source directory (--source-dir / in-process option)';
|
|
1088
|
+
case 'bundle':
|
|
1089
|
+
return 'the installed CLI bundle';
|
|
1090
|
+
case 'unresolved':
|
|
1091
|
+
return 'no source (resolution did not complete)';
|
|
1092
|
+
default:
|
|
1093
|
+
return "the project's own agent-config tree";
|
|
1094
|
+
}
|
|
1095
|
+
}
|
|
1096
|
+
/** How a layer names itself in a message: `settings.json`, or `agents/`. */
|
|
1097
|
+
function layerWhat(layer) {
|
|
1098
|
+
return layer === 'settings.json' ? 'settings.json' : `${layer}/`;
|
|
1099
|
+
}
|
|
1100
|
+
/**
|
|
1101
|
+
* Apply the ROOT contract to the declared table, and RETURN it.
|
|
1102
|
+
*
|
|
1103
|
+
* Returning the table is the point. Everything downstream reads its roots from
|
|
1104
|
+
* the return value, so validation cannot be reordered behind the walk without
|
|
1105
|
+
* failing to compile. The alternative — a runtime "was this validated?" guard —
|
|
1106
|
+
* was tried and could never fire (round-5 SF-3).
|
|
1107
|
+
*
|
|
1108
|
+
* Three rules, in order:
|
|
1109
|
+
* 1. the table agrees with the layer contract (rootContractGaps);
|
|
1110
|
+
* 2. every root is probed through the ONE symlink/absent/unreadable rule, and
|
|
1111
|
+
* a `required: true` root that is not present is COULD_NOT_RUN naming that
|
|
1112
|
+
* root — not the layer, because a union layer's other root being present is
|
|
1113
|
+
* exactly the state that used to pass;
|
|
1114
|
+
* 3. a layer with NO root present and no required root is an absent optional
|
|
1115
|
+
* layer, recorded for the per-layer print.
|
|
1116
|
+
*/
|
|
1117
|
+
function validateLayerRoots(declared, absentOptionalLayers) {
|
|
1118
|
+
const gaps = rootContractGaps(declared);
|
|
1119
|
+
if (gaps.length > 0) {
|
|
1120
|
+
bail(`the source-root contract is inconsistent — ${gaps.join('; ')}`);
|
|
1121
|
+
}
|
|
1122
|
+
for (const layer of FIDELITY_LAYERS) {
|
|
1123
|
+
let anyPresent = false;
|
|
1124
|
+
for (const root of declared[layer]) {
|
|
1125
|
+
// settings.json is a FILE root, the other five are directory roots — two
|
|
1126
|
+
// shapes of the SAME rule: present, readable, and not a symlink.
|
|
1127
|
+
const present = layer === 'settings.json'
|
|
1128
|
+
? assertRealFile(root.path, 'source tree', root.display)
|
|
1129
|
+
: assertRealDir(root.path, 'source tree', root.display);
|
|
1130
|
+
if (present)
|
|
1131
|
+
anyPresent = true;
|
|
1132
|
+
if (!present && root.required) {
|
|
1133
|
+
// NAMES THE ROOT'S DISPLAY, not its real path (round-7 SF-3): in repo
|
|
1134
|
+
// mode the permission roots live in the git-archive staging tree, so the
|
|
1135
|
+
// real path is a /tmp directory cleanup() has already deleted and it says
|
|
1136
|
+
// nothing about the ref the layer was read from.
|
|
1137
|
+
bail(`source has no ${layerWhat(layer)} at ${root.display} — that source root is REQUIRED ` +
|
|
1138
|
+
`for the ${layer} layer, so there is nothing to verify the deployed files against`);
|
|
1139
|
+
}
|
|
1140
|
+
}
|
|
1141
|
+
// Reached only by a layer with no required root — rootContractGaps has
|
|
1142
|
+
// already refused a REQUIRED layer that declares none.
|
|
1143
|
+
if (!anyPresent)
|
|
1144
|
+
absentOptionalLayers.push(layer);
|
|
1145
|
+
}
|
|
1146
|
+
return declared;
|
|
1147
|
+
}
|
|
1148
|
+
// ── the check ───────────────────────────────────────────────────────────────
|
|
1149
|
+
/**
|
|
1150
|
+
* Compare the deployed `.claude/` tree against its source. Never throws — every
|
|
1151
|
+
* failure path resolves to a COULD_NOT_RUN result.
|
|
1152
|
+
*/
|
|
1153
|
+
export function checkConfigFidelity(worktreePath, opts = {}) {
|
|
1154
|
+
// Derived exactly as verifyAndHealHooks derives it, so the two controls agree
|
|
1155
|
+
// on which ref the permission layer came from.
|
|
1156
|
+
const baseBranch = opts.baseBranch ?? 'main';
|
|
1157
|
+
// configSource arrives from mx-agent.config.json — a checked-in, agent-editable
|
|
1158
|
+
// file, so it is untrusted input to a path join AND to a `git archive`
|
|
1159
|
+
// pathspec (CWE-22). One sanitizer for this exact field already exists;
|
|
1160
|
+
// isolation-probe's safeConfigSource is reused rather than restated, because
|
|
1161
|
+
// two controls reading the same untrusted field must not disagree about what
|
|
1162
|
+
// it is allowed to say. Sanitizing HERE covers both call sites (doctor.ts and
|
|
1163
|
+
// start.ts) at once instead of relying on each to remember.
|
|
1164
|
+
const configSource = safeConfigSource(opts.configSource ?? DEFAULT_CONFIG_SOURCE);
|
|
1165
|
+
const deployedRoot = join(worktreePath, '.claude');
|
|
1166
|
+
const repoSource = join(worktreePath, configSource);
|
|
1167
|
+
// Resolution now performs filesystem probes that can BAIL (an unreadable repo
|
|
1168
|
+
// source tree is COULD_NOT_RUN, not "no repo source"), so these are `let`s
|
|
1169
|
+
// assigned inside the single try below, and `base()` closes over them. The
|
|
1170
|
+
// module's never-throws contract is held by that one catch.
|
|
1171
|
+
let sourceDir = null;
|
|
1172
|
+
// 'unresolved' until resolveSourceDir returns. It can bail (an unreadable
|
|
1173
|
+
// source tree is COULD_NOT_RUN), and a result from that path must not claim
|
|
1174
|
+
// the bundle supplied the source — that is precisely the fall-through the
|
|
1175
|
+
// bail exists to stop.
|
|
1176
|
+
let sourceAuthority = 'unresolved';
|
|
1177
|
+
// 'unresolved' until resolveSourceDir returns, for the same reason
|
|
1178
|
+
// sourceAuthority is: the bail paths above resolution must not report a mode
|
|
1179
|
+
// that names a source nothing ever chose.
|
|
1180
|
+
let mode = 'unresolved';
|
|
1181
|
+
const absentOptionalLayers = [];
|
|
1182
|
+
const ctx = {
|
|
1183
|
+
deployedRoot,
|
|
1184
|
+
mismatches: [],
|
|
1185
|
+
compared: 0,
|
|
1186
|
+
perLayer: zeroPerLayer(),
|
|
1187
|
+
rootEntries: new Map(),
|
|
1188
|
+
accountedFor: new Set(),
|
|
1189
|
+
};
|
|
1190
|
+
let cleanup = null;
|
|
1191
|
+
const sourceLabel = () => {
|
|
1192
|
+
// Nothing supplied the source, so no ref label may name a candidate as
|
|
1193
|
+
// though it had. `CLI bundle (unresolved)` was a claim about where the
|
|
1194
|
+
// comparison read from, in a result where no comparison happened.
|
|
1195
|
+
if (sourceAuthority === 'unresolved')
|
|
1196
|
+
return 'unresolved source';
|
|
1197
|
+
if (sourceAuthority === 'env-override')
|
|
1198
|
+
return `MX_BUNDLED_CONFIG_DIR (${sourceDir ?? 'unresolved'})`;
|
|
1199
|
+
if (sourceAuthority === 'explicit')
|
|
1200
|
+
return `supplied source dir (${sourceDir ?? 'unresolved'})`;
|
|
1201
|
+
return `CLI bundle (${sourceDir ?? 'unresolved'})`;
|
|
1202
|
+
};
|
|
1203
|
+
const refs = () => mode === 'repo'
|
|
1204
|
+
? { permissionRef: `origin/${baseBranch}`, behavioralRef: 'working tree' }
|
|
1205
|
+
: { permissionRef: sourceLabel(), behavioralRef: sourceLabel() };
|
|
1206
|
+
const base = (verdict) => ({
|
|
1207
|
+
verdict,
|
|
1208
|
+
mismatches: [],
|
|
1209
|
+
filesCompared: 0,
|
|
1210
|
+
perLayer: zeroPerLayer(),
|
|
1211
|
+
absentOptionalLayers: [],
|
|
1212
|
+
sourceOverridden: authorityIsOverride(sourceAuthority),
|
|
1213
|
+
sourceAuthority,
|
|
1214
|
+
...refs(),
|
|
1215
|
+
mode,
|
|
1216
|
+
sourceDir: sourceDir ?? '',
|
|
1217
|
+
configSource,
|
|
1218
|
+
});
|
|
1219
|
+
try {
|
|
1220
|
+
// The module's own contract, checked before it is relied on: a layer in
|
|
1221
|
+
// neither REQUIRED_LAYERS nor OPTIONAL_LAYERS is silently treated as
|
|
1222
|
+
// optional by the presence loop below.
|
|
1223
|
+
const contractGaps = layerContractGaps();
|
|
1224
|
+
if (contractGaps.length > 0) {
|
|
1225
|
+
bail(`the layer contract is inconsistent — ${contractGaps.join('; ')}`);
|
|
1226
|
+
}
|
|
1227
|
+
// ── THE SOURCE-SIDE PATH WALK, FIRST, BEFORE ANYTHING CANONICALISES ──
|
|
1228
|
+
// Every component of the path to the repo's own agent-config —
|
|
1229
|
+
// `mx-agent-system` and `agent-config`, or whatever configSource names.
|
|
1230
|
+
// This runs ahead of resolveSourceDir and ahead of the mode derivation on
|
|
1231
|
+
// purpose: both go through samePath, which canonicalises with realpathSync,
|
|
1232
|
+
// so a symlinked source root resolves to `authority: 'repo-tree'` and the
|
|
1233
|
+
// run reports itself as a verification of the project's own tree. The walk
|
|
1234
|
+
// has to fail closed before that happens.
|
|
1235
|
+
assertPlainPathTo(worktreePath, configSource, 'source tree');
|
|
1236
|
+
const resolved = resolveSourceDir(opts.sourceDir, repoSource);
|
|
1237
|
+
sourceDir = resolved.dir;
|
|
1238
|
+
sourceAuthority = resolved.authority;
|
|
1239
|
+
// REPO mode only when source resolved to this worktree's own agent-config
|
|
1240
|
+
// tree — that is the only case where the per-layer ref split is meaningful,
|
|
1241
|
+
// because it is the only case where a git ref for the source exists. Anything
|
|
1242
|
+
// else (the CLI bundle, an explicit override) is BUNDLE mode: one trusted ref,
|
|
1243
|
+
// the package.
|
|
1244
|
+
mode = sourceDir !== null && samePath(sourceDir, repoSource) ? 'repo' : 'bundle';
|
|
1245
|
+
if (!sourceDir || !pathPresent(sourceDir, 'source tree')) {
|
|
1246
|
+
bail('agent-config source could not be resolved (no CLI bundle and no repo tree)');
|
|
1247
|
+
}
|
|
1248
|
+
if (!pathPresent(deployedRoot, 'deployed tree')) {
|
|
1249
|
+
// Not "clean by vacuity" and not drift of a particular file: there is no
|
|
1250
|
+
// deployed config to compare at all. Fail closed as COULD_NOT_RUN so the
|
|
1251
|
+
// message points at provisioning rather than at a file list.
|
|
1252
|
+
bail(`no deployed config at ${deployedRoot}`);
|
|
1253
|
+
}
|
|
1254
|
+
// Permission layer (settings.json + hooks/): origin/<baseBranch> in repo
|
|
1255
|
+
// mode — the ref generateClaudeConfigForBoot sourced it from — and the
|
|
1256
|
+
// bundle itself in bundle mode, where there is no git to pin against.
|
|
1257
|
+
let permissionDir;
|
|
1258
|
+
if (mode === 'repo') {
|
|
1259
|
+
const archived = archiveRef(worktreePath, refs().permissionRef, configSource);
|
|
1260
|
+
permissionDir = archived.dir;
|
|
1261
|
+
cleanup = archived.cleanup;
|
|
1262
|
+
}
|
|
1263
|
+
else {
|
|
1264
|
+
permissionDir = sourceDir;
|
|
1265
|
+
}
|
|
1266
|
+
const { permissionRef, behavioralRef } = refs();
|
|
1267
|
+
// The overlay always resolves from the CONSUMING repo: the published bundle
|
|
1268
|
+
// carries no `local/`, and the overlay is by definition project-owned.
|
|
1269
|
+
//
|
|
1270
|
+
// `local` is walked on BOTH candidate bases before either is probed. It is
|
|
1271
|
+
// the component the executed exploit used: a symlinked `agent-config/local`
|
|
1272
|
+
// pointing at an attacker directory whose `agents/` shadows the base layer
|
|
1273
|
+
// (overlay wins the union), which reached CLEAN / exit 0 with nothing in the
|
|
1274
|
+
// output naming the outside directory.
|
|
1275
|
+
assertPlainPathTo(sourceDir, 'local', 'source tree');
|
|
1276
|
+
assertPlainPathTo(repoSource, 'local', 'source tree');
|
|
1277
|
+
const overlayDir = pathPresent(join(sourceDir, 'local'), 'source tree')
|
|
1278
|
+
? join(sourceDir, 'local')
|
|
1279
|
+
: join(repoSource, 'local');
|
|
1280
|
+
// ── layer roots are lstat'd on BOTH sides before anything is walked ──
|
|
1281
|
+
// Nothing below reaches a layer root through a directory walk, so without
|
|
1282
|
+
// this a symlinked root is followed silently and its whole layer disappears
|
|
1283
|
+
// from the comparison with the verdict unchanged.
|
|
1284
|
+
//
|
|
1285
|
+
// DERIVED from FIDELITY_LAYERS, never re-listed. The literal list that used
|
|
1286
|
+
// to sit here was the last layer enumeration outside the three declared
|
|
1287
|
+
// constants, and it was not type-coupled to them: adding a seventh layer
|
|
1288
|
+
// breaks compilation in `layerRoots` and `zeroPerLayer` but would have
|
|
1289
|
+
// compiled fine here, so the new layer would have silently lost its
|
|
1290
|
+
// deployed-side symlink check. That is the same defect generator that
|
|
1291
|
+
// produced the per-layer coverage hole one round earlier.
|
|
1292
|
+
assertRealDir(deployedRoot, 'deployed tree');
|
|
1293
|
+
for (const layer of FIDELITY_LAYERS.filter((l) => l !== 'settings.json')) {
|
|
1294
|
+
assertRealDir(join(deployedRoot, layer), 'deployed tree');
|
|
1295
|
+
}
|
|
1296
|
+
// ── THE PER-ROOT COVERAGE CONTRACT, declared once for every root ──
|
|
1297
|
+
// Where each layer's source lives, in one table, so the presence rule, the
|
|
1298
|
+
// zero-entry floor and the error messages are the SAME rule for every root.
|
|
1299
|
+
// The previous shape stated the rule for hooks/ only, which is how a source
|
|
1300
|
+
// tree with no agents/ certified a deployed subagent whose tool grants had
|
|
1301
|
+
// been rewritten; the shape after that stated it per LAYER, which is how a
|
|
1302
|
+
// source tree with no BASE agents/ did the same thing while the overlay's 13
|
|
1303
|
+
// files supplied a plausible-looking `agents 13`.
|
|
1304
|
+
//
|
|
1305
|
+
// Each root also carries how it NAMES ITSELF in a failure message
|
|
1306
|
+
// (FidelityRoot.display, round-7 SF-3). For every root a reader can go and
|
|
1307
|
+
// inspect that is the path itself; for the two PERMISSION roots in repo mode
|
|
1308
|
+
// it is the repo-relative path plus the ref, because the real path is inside
|
|
1309
|
+
// the `git archive` staging tree that cleanup() deletes before the message
|
|
1310
|
+
// reaches a terminal, and it names no ref at all.
|
|
1311
|
+
const permissionDisplay = (rel) =>
|
|
1312
|
+
// DISPLAY_REF_NOTE, not a literal: displayChild has to find this note to keep
|
|
1313
|
+
// it last when it appends an entry name (round-9 SF-4).
|
|
1314
|
+
mode === 'repo' ? `${configSource}/${rel}${DISPLAY_REF_NOTE}${permissionRef})` : join(permissionDir, rel);
|
|
1315
|
+
// NO DEFAULT for `display` (round-8 SF-1). A `display: string = path` default
|
|
1316
|
+
// reinstates at the CALL SITE exactly what making the field required removed
|
|
1317
|
+
// at the TYPE: a permission-layer root added later as
|
|
1318
|
+
// `root(join(permissionDir, 'x'), true)` would compile and silently take the
|
|
1319
|
+
// `/tmp` staging path as its display — the round-7 SF-3 defect, back. Every
|
|
1320
|
+
// root states its display; the six behavioral ones state their own path.
|
|
1321
|
+
const root = (path, required, display) => ({
|
|
1322
|
+
path,
|
|
1323
|
+
display,
|
|
1324
|
+
required,
|
|
1325
|
+
});
|
|
1326
|
+
// Each behavioral root's path is constructed ONCE and named, so the round-6
|
|
1327
|
+
// grep guard (every root enumerated exactly once) still holds while the
|
|
1328
|
+
// display is stated at the call site rather than defaulted.
|
|
1329
|
+
const rulesRoot = join(sourceDir, 'rules');
|
|
1330
|
+
const baseAgentsRoot = join(sourceDir, 'agents');
|
|
1331
|
+
const overlayAgentsRoot = join(overlayDir, 'agents');
|
|
1332
|
+
const baseSkillsRoot = join(sourceDir, 'skills');
|
|
1333
|
+
const overlaySkillsRoot = join(overlayDir, 'skills');
|
|
1334
|
+
const commandsRoot = join(overlayDir, 'commands');
|
|
1335
|
+
const declaredRoots = {
|
|
1336
|
+
'settings.json': [
|
|
1337
|
+
root(join(permissionDir, 'settings.json'), true, permissionDisplay('settings.json')),
|
|
1338
|
+
],
|
|
1339
|
+
hooks: [root(join(permissionDir, 'hooks'), true, permissionDisplay('hooks'))],
|
|
1340
|
+
// rules/ is the OPTIONAL layer, so its single root is not required.
|
|
1341
|
+
rules: [root(rulesRoot, false, rulesRoot)],
|
|
1342
|
+
// agents/ and skills/ are a UNION of two roots. The BASE root is required —
|
|
1343
|
+
// it is what every consumer ships and what carries the subagent tool
|
|
1344
|
+
// grants. The OVERLAY root is not: a consumer may ship no local agents at
|
|
1345
|
+
// all. Deployed overlay files with no source counterpart are caught by the
|
|
1346
|
+
// reverse-inclusion pass below, not by this flag.
|
|
1347
|
+
agents: [
|
|
1348
|
+
root(baseAgentsRoot, true, baseAgentsRoot),
|
|
1349
|
+
root(overlayAgentsRoot, false, overlayAgentsRoot),
|
|
1350
|
+
],
|
|
1351
|
+
skills: [
|
|
1352
|
+
root(baseSkillsRoot, true, baseSkillsRoot),
|
|
1353
|
+
root(overlaySkillsRoot, false, overlaySkillsRoot),
|
|
1354
|
+
],
|
|
1355
|
+
// commands/ is overlay-only — there is no base/commands — and REQUIRED.
|
|
1356
|
+
commands: [root(commandsRoot, true, commandsRoot)],
|
|
1357
|
+
};
|
|
1358
|
+
// ── VALIDATION PRODUCES THE TABLE THE WALK USES ──
|
|
1359
|
+
// `layerRoots` is what validateLayerRoots RETURNS, and every site below reads
|
|
1360
|
+
// roots from it. That is the coupling, expressed as a data dependency rather
|
|
1361
|
+
// than as a runtime guard: an edit that moves the walk in front of the
|
|
1362
|
+
// validation does not compile (block-scoped `const` used before declaration),
|
|
1363
|
+
// where the previous runtime guard for the same coupling could not fire at
|
|
1364
|
+
// all — settings.json is REQUIRED, so the presence rule always bailed first,
|
|
1365
|
+
// and no mutation could reach the guard (round-5 SF-3).
|
|
1366
|
+
const layerRoots = validateLayerRoots(declaredRoots, absentOptionalLayers);
|
|
1367
|
+
compareSettings(ctx, layerRoots['settings.json'][0], permissionRef);
|
|
1368
|
+
compareFlatDir(ctx, layerRoots.hooks[0], 'hooks', 'hooks', permissionRef);
|
|
1369
|
+
compareFlatDir(ctx, layerRoots.rules[0], 'rules', 'rules', behavioralRef);
|
|
1370
|
+
for (const [name, entry] of unionFlat(ctx, layerRoots.agents)) {
|
|
1371
|
+
compareFile(ctx, entry.path, `agents/${name}`, 'agents', behavioralRef, null);
|
|
1372
|
+
}
|
|
1373
|
+
for (const [name, entry] of unionDirs(ctx, layerRoots.skills)) {
|
|
1374
|
+
compareTree(ctx, entry.path, entry.display, `skills/${name}`, 'skills', behavioralRef, null);
|
|
1375
|
+
}
|
|
1376
|
+
// commands/ come from the OVERLAY only — there is no base/commands.
|
|
1377
|
+
compareTree(ctx, layerRoots.commands[0].path, layerRoots.commands[0].display, 'commands', 'commands', behavioralRef, layerRoots.commands[0].path);
|
|
1378
|
+
// ── REVERSE INCLUSION, for the REQUIRED directory layers ──
|
|
1379
|
+
// The forward pass proves every SOURCE file is deployed and unchanged. It
|
|
1380
|
+
// says nothing about a deployed file no source root mentions — a seventh
|
|
1381
|
+
// agent in `.claude/agents/`, or the whole of a deployed overlay layer whose
|
|
1382
|
+
// source root was deleted (root 4 of the four executed round-6 shapes, which
|
|
1383
|
+
// the required-root rule alone does not cover, because a consumer may
|
|
1384
|
+
// legitimately ship no overlay).
|
|
1385
|
+
//
|
|
1386
|
+
// GATED ON ROOT PRESENCE, not on whether the layer is REQUIRED (round-7 MF).
|
|
1387
|
+
// A layer with no source root at all has nothing to subtract deployed files
|
|
1388
|
+
// from, so every deployed file in it would be reported — that is the shape
|
|
1389
|
+
// the `rules/` exemption was protecting, and it is the only one it ever
|
|
1390
|
+
// legitimately covered. A layer whose root IS present gets the pass whether
|
|
1391
|
+
// it is required or optional.
|
|
1392
|
+
for (const layer of REVERSE_INCLUSION_LAYERS) {
|
|
1393
|
+
if (absentOptionalLayers.includes(layer))
|
|
1394
|
+
continue;
|
|
1395
|
+
reportUnaccountedDeployed(ctx, layer);
|
|
1396
|
+
}
|
|
1397
|
+
// ── COVERAGE FLOOR, after the walk, for EVERY REQUIRED ROOT ──
|
|
1398
|
+
// The presence check above passes for a root that exists and is empty, and
|
|
1399
|
+
// the verdict below is a function of the mismatch count only — which zero
|
|
1400
|
+
// entries satisfy trivially. Applied per required ROOT, from the same
|
|
1401
|
+
// declared table as the presence rule, so neither a layer nor one root of a
|
|
1402
|
+
// union layer can be quietly exempt.
|
|
1403
|
+
for (const layer of FIDELITY_LAYERS) {
|
|
1404
|
+
for (const root of layerRoots[layer]) {
|
|
1405
|
+
if (!root.required)
|
|
1406
|
+
continue;
|
|
1407
|
+
if ((ctx.rootEntries.get(root.path) ?? 0) > 0)
|
|
1408
|
+
continue;
|
|
1409
|
+
// Same display rule as the presence bail above (round-7 SF-3).
|
|
1410
|
+
bail(`the ${layerWhat(layer)} layer's REQUIRED source root ${root.display} contributed 0 comparisons ` +
|
|
1411
|
+
`— nothing under it was verified, so this is not a pass`);
|
|
1412
|
+
}
|
|
1413
|
+
}
|
|
1414
|
+
}
|
|
1415
|
+
catch (err) {
|
|
1416
|
+
if (err instanceof CouldNotRun) {
|
|
1417
|
+
return { ...base('COULD_NOT_RUN'), reason: err.message };
|
|
1418
|
+
}
|
|
1419
|
+
return {
|
|
1420
|
+
...base('COULD_NOT_RUN'),
|
|
1421
|
+
reason: `unexpected error: ${err instanceof Error ? err.message : String(err)}`,
|
|
1422
|
+
};
|
|
1423
|
+
}
|
|
1424
|
+
finally {
|
|
1425
|
+
if (cleanup)
|
|
1426
|
+
cleanup();
|
|
1427
|
+
}
|
|
1428
|
+
const mismatches = ctx.mismatches.sort((a, b) => a.layer === b.layer ? a.path.localeCompare(b.path) : a.layer.localeCompare(b.layer));
|
|
1429
|
+
return {
|
|
1430
|
+
verdict: mismatches.length === 0 ? 'CLEAN' : 'DRIFTED',
|
|
1431
|
+
mismatches,
|
|
1432
|
+
filesCompared: ctx.compared,
|
|
1433
|
+
perLayer: ctx.perLayer,
|
|
1434
|
+
absentOptionalLayers,
|
|
1435
|
+
sourceOverridden: authorityIsOverride(sourceAuthority),
|
|
1436
|
+
sourceAuthority,
|
|
1437
|
+
...refs(),
|
|
1438
|
+
mode,
|
|
1439
|
+
sourceDir: sourceDir ?? '',
|
|
1440
|
+
configSource,
|
|
1441
|
+
};
|
|
1442
|
+
}
|
|
1443
|
+
/**
|
|
1444
|
+
* settings.json — compared as PARSED JSON, not bytes. Key order and indentation
|
|
1445
|
+
* are a JSON writer's business; a byte comparison would be red on a reformat and
|
|
1446
|
+
* would say nothing about which registration moved. Unparseable on EITHER side
|
|
1447
|
+
* is COULD_NOT_RUN, never a pass: a comparison that cannot be performed has not
|
|
1448
|
+
* produced a verdict.
|
|
1449
|
+
*/
|
|
1450
|
+
function compareSettings(ctx, root, ref) {
|
|
1451
|
+
// `root` arrives ALREADY VALIDATED — it is layerRoots['settings.json'][0], the
|
|
1452
|
+
// value validateLayerRoots RETURNED after lstat'ing it through the one symlink
|
|
1453
|
+
// rule and requiring it to be present. Taking the ROOT rather than a bare path
|
|
1454
|
+
// is what makes that unfakeable at the call site: there is no validated
|
|
1455
|
+
// settings.json path to pass except the one validation produced. This function
|
|
1456
|
+
// deliberately does not re-derive the path and does not restate the rule.
|
|
1457
|
+
const sourcePath = root.path;
|
|
1458
|
+
countComparison(ctx, 'settings.json', root.path);
|
|
1459
|
+
ctx.accountedFor.add('settings.json');
|
|
1460
|
+
const deployedPath = join(ctx.deployedRoot, 'settings.json');
|
|
1461
|
+
// Deployed side, the SAME symlink rule every other deployed path gets. Without
|
|
1462
|
+
// this call settings.json was exempt: only absence was tested, and readFileSync
|
|
1463
|
+
// then followed the link — a symlinked `.claude/settings.json` seeded with
|
|
1464
|
+
// correct content certified CLEAN while Claude Code read the permission layer
|
|
1465
|
+
// from an unmanaged file outside the tree.
|
|
1466
|
+
if (!deployedIsPlain(ctx, 'settings.json', 'settings.json', ref))
|
|
1467
|
+
return;
|
|
1468
|
+
// Same classifier for the rest: absent is a `missing` finding (exit 1),
|
|
1469
|
+
// unreadable is COULD_NOT_RUN (exit 2). Neither is green, and which one it is
|
|
1470
|
+
// is decided by the same rule as everywhere else rather than by existsSync.
|
|
1471
|
+
if (statOrAbsent(deployedPath, 'deployed tree entry') === null) {
|
|
1472
|
+
ctx.mismatches.push({ path: 'settings.json', layer: 'settings.json', ref, kind: 'missing' });
|
|
1473
|
+
return;
|
|
1474
|
+
}
|
|
1475
|
+
let sourceJson;
|
|
1476
|
+
let deployedJson;
|
|
1477
|
+
try {
|
|
1478
|
+
sourceJson = JSON.parse(readFileSync(sourcePath, 'utf-8'));
|
|
1479
|
+
}
|
|
1480
|
+
catch (err) {
|
|
1481
|
+
bail(`source settings.json is not valid JSON (${err instanceof Error ? err.message : String(err)})`);
|
|
1482
|
+
}
|
|
1483
|
+
try {
|
|
1484
|
+
deployedJson = JSON.parse(readFileSync(deployedPath, 'utf-8'));
|
|
1485
|
+
}
|
|
1486
|
+
catch (err) {
|
|
1487
|
+
bail(`deployed .claude/settings.json is not valid JSON (${err instanceof Error ? err.message : String(err)})`);
|
|
1488
|
+
}
|
|
1489
|
+
if (jsonDeepEqual(sourceJson, deployedJson))
|
|
1490
|
+
return;
|
|
1491
|
+
const keys = differingTopLevelKeys(sourceJson, deployedJson);
|
|
1492
|
+
ctx.mismatches.push({
|
|
1493
|
+
path: 'settings.json',
|
|
1494
|
+
layer: 'settings.json',
|
|
1495
|
+
ref,
|
|
1496
|
+
kind: 'differs',
|
|
1497
|
+
detail: keys.length > 0 ? `differing top-level key(s): ${keys.join(', ')}` : 'parsed JSON differs',
|
|
1498
|
+
});
|
|
1499
|
+
}
|
|
1500
|
+
/**
|
|
1501
|
+
* The exit code the verdict maps to.
|
|
1502
|
+
*
|
|
1503
|
+
* One override: a run whose source came from MX_BUNDLED_CONFIG_DIR never exits
|
|
1504
|
+
* 0. Whoever set that variable chose what "correct" means, so a CLEAN result
|
|
1505
|
+
* says the deployment matches a directory someone named — not that it matches
|
|
1506
|
+
* the project's source. That is a NOT-VERIFIED answer, and NOT VERIFIED is 2.
|
|
1507
|
+
* A DRIFTED result keeps exit 1: a mismatch found against any source is still a
|
|
1508
|
+
* real finding.
|
|
1509
|
+
*/
|
|
1510
|
+
export function fidelityExitCode(result) {
|
|
1511
|
+
const code = FIDELITY_EXIT[result.verdict];
|
|
1512
|
+
if (result.sourceOverridden && code === 0)
|
|
1513
|
+
return FIDELITY_EXIT.COULD_NOT_RUN;
|
|
1514
|
+
return code;
|
|
1515
|
+
}
|
|
1516
|
+
/**
|
|
1517
|
+
* `settings.json 1, hooks 44, rules 4, agents 26, skills 13, commands 6`
|
|
1518
|
+
*
|
|
1519
|
+
* EVERY zero is annotated, and the annotation says WHICH zero it is:
|
|
1520
|
+
* • `rules 0 (absent from source)` — no source root at all, nothing to
|
|
1521
|
+
* compare. Benign.
|
|
1522
|
+
* • `rules 0 (source root present, contributed nothing)` — a root that exists
|
|
1523
|
+
* and produced no comparison, so a deployed file in that layer was never
|
|
1524
|
+
* checked against anything.
|
|
1525
|
+
* The annotation used to cover only the first, which is inverted from what a
|
|
1526
|
+
* security reader needs: the benign state was labelled and the dangerous one
|
|
1527
|
+
* printed as a bare 0. An attacker who empties an optional source directory
|
|
1528
|
+
* rather than removing it leaves their deployed tamper with no counterpart, and
|
|
1529
|
+
* that run printed `rules 0` with nothing to distinguish it from a consumer who
|
|
1530
|
+
* simply ships no rules. Required layers cannot reach either state — the
|
|
1531
|
+
* coverage floor bails first — so in practice this is optional layers only.
|
|
1532
|
+
*
|
|
1533
|
+
* EXPORTED because it is the ONE rendering of the per-layer line. start.ts built
|
|
1534
|
+
* its own — `FIDELITY_LAYERS.map((l) => \`${l} ${result.perLayer[l]}\`)` — so on
|
|
1535
|
+
* the same result doctor printed `rules 0 (source root present, contributed
|
|
1536
|
+
* nothing)` and session start printed a bare `rules 0`, which is the exact
|
|
1537
|
+
* string the annotation was added to eliminate. Same defect shape as the symlink
|
|
1538
|
+
* rule: a second per-site copy of a rule that must be stated once.
|
|
1539
|
+
*/
|
|
1540
|
+
export function perLayerSummary(result) {
|
|
1541
|
+
// COULD_NOT_RUN SAYS NOTHING PER LAYER (round-7 SF-2). Both annotations below
|
|
1542
|
+
// are claims about a COMPLETED walk: "absent from source" and "source root
|
|
1543
|
+
// present" are only distinguishable once validateLayerRoots has probed every
|
|
1544
|
+
// root, and this function infers "present" from "not in absentOptionalLayers",
|
|
1545
|
+
// which is the zero value until then. On the realistic exploit — base `agents/`
|
|
1546
|
+
// deleted — the line printed six copies of `(source root present, contributed
|
|
1547
|
+
// nothing)`, INCLUDING for `agents`, whose absence is the reason the run
|
|
1548
|
+
// stopped. A false statement in the line a reader studies hardest. There is no
|
|
1549
|
+
// true per-layer statement to make about a run that stopped before the walk, so
|
|
1550
|
+
// the line is suppressed rather than reworded.
|
|
1551
|
+
if (result.verdict === 'COULD_NOT_RUN') {
|
|
1552
|
+
return 'not measured — the run stopped before the walk completed';
|
|
1553
|
+
}
|
|
1554
|
+
return FIDELITY_LAYERS.map((l) => {
|
|
1555
|
+
const n = result.perLayer[l] ?? 0;
|
|
1556
|
+
if (n > 0)
|
|
1557
|
+
return `${l} ${n}`;
|
|
1558
|
+
return result.absentOptionalLayers?.includes(l)
|
|
1559
|
+
? `${l} ${n} (absent from source)`
|
|
1560
|
+
: `${l} ${n} (source root present, contributed nothing)`;
|
|
1561
|
+
}).join(', ');
|
|
1562
|
+
}
|
|
1563
|
+
/**
|
|
1564
|
+
* The generator invocation to paste, DERIVED rather than hardcoded.
|
|
1565
|
+
*
|
|
1566
|
+
* The old line named `mx-agent-system/cli/scripts/generate-claude.mjs` and the
|
|
1567
|
+
* default configSource, neither of which is right in a consumer project: the
|
|
1568
|
+
* script lives wherever the CLI is installed, and a project that relocated its
|
|
1569
|
+
* agent-config needs `--config-source` or the command regenerates from a tree it
|
|
1570
|
+
* does not have. A command that cannot be pasted is worse than no command.
|
|
1571
|
+
*/
|
|
1572
|
+
function generatorCommand(result) {
|
|
1573
|
+
let script = 'mx-agent-system/cli/scripts/generate-claude.mjs';
|
|
1574
|
+
try {
|
|
1575
|
+
// dist/lib/config-fidelity.js → dist/lib → dist → <pkg>/scripts/…
|
|
1576
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
1577
|
+
const candidate = resolve(here, '..', '..', 'scripts', 'generate-claude.mjs');
|
|
1578
|
+
if (pathPresent(candidate, 'generator script'))
|
|
1579
|
+
script = candidate;
|
|
1580
|
+
}
|
|
1581
|
+
catch {
|
|
1582
|
+
/* keep the repo-relative default — this is a help string, never a verdict */
|
|
1583
|
+
}
|
|
1584
|
+
const configSourceFlag = result.configSource && result.configSource !== DEFAULT_CONFIG_SOURCE
|
|
1585
|
+
? ` --config-source ${result.configSource}`
|
|
1586
|
+
: '';
|
|
1587
|
+
return `node ${script} --repo-root <worktree>${configSourceFlag} --permission-from-git ${result.permissionRef}`;
|
|
1588
|
+
}
|
|
1589
|
+
/**
|
|
1590
|
+
* What a green line does NOT cover. Printed with every CLEAN result: a reader
|
|
1591
|
+
* seeing green from a check whose help says "assert deployed .claude/ matches
|
|
1592
|
+
* its agent-config source" will otherwise read it as clearance on the whole
|
|
1593
|
+
* permission layer, which it is not.
|
|
1594
|
+
*/
|
|
1595
|
+
function coverageCaveats(result) {
|
|
1596
|
+
const lines = [
|
|
1597
|
+
' NOT covered: CLAUDE.md / AGENTS.md (templated, not byte-comparable); file modes; ' +
|
|
1598
|
+
'files with no source counterpart OUTSIDE the layer directories — the top level of ' +
|
|
1599
|
+
`.claude/ (settings.local.json, scheduled_tasks.lock) — and any layer whose source root is ` +
|
|
1600
|
+
`absent entirely${result.absentOptionalLayers.length > 0
|
|
1601
|
+
? ` (on this run: ${result.absentOptionalLayers.join(', ')})`
|
|
1602
|
+
: ' (none on this run)'}. Inside ${REVERSE_INCLUSION_LAYERS.join('/, ')}/ inclusion is two-way whenever the source ` +
|
|
1603
|
+
'root is present, so a deployed file no source root mentions IS a finding.',
|
|
1604
|
+
];
|
|
1605
|
+
if (result.mode === 'repo') {
|
|
1606
|
+
lines.push(` Also NOT covered: cross-layer coherence — settings.json and hooks/ are read from ` +
|
|
1607
|
+
`${result.permissionRef} while the behavioral layers are read from ${result.behavioralRef}, ` +
|
|
1608
|
+
`so a hook registered at one ref and shipped at another is outside this comparison (#5422).`);
|
|
1609
|
+
}
|
|
1610
|
+
return lines;
|
|
1611
|
+
}
|
|
1612
|
+
/**
|
|
1613
|
+
* Human-readable lines for a terminal. Every drift line NAMES the ref it was
|
|
1614
|
+
* compared against — without it the reader cannot tell real drift from an
|
|
1615
|
+
* unmerged branch, which is the failure mode #5412 was originally diagnosed
|
|
1616
|
+
* with.
|
|
1617
|
+
*/
|
|
1618
|
+
export function describeConfigFidelity(result) {
|
|
1619
|
+
// Leads every result, before the verdict: if the source was chosen by an
|
|
1620
|
+
// environment variable, nothing below is a statement about the project's
|
|
1621
|
+
// source, and a reader must not have to reach the caveat after the green line.
|
|
1622
|
+
const overrideLines = result.sourceOverridden
|
|
1623
|
+
? [
|
|
1624
|
+
`Config fidelity: SOURCE OVERRIDDEN — the comparison source was supplied by ` +
|
|
1625
|
+
`${authorityLabel(result.sourceAuthority)} (${result.sourceDir}).`,
|
|
1626
|
+
" This is NOT a verification of the project's agent-config source — whoever named that " +
|
|
1627
|
+
'directory chose what "correct" means. Exit code is 2 (not verified).',
|
|
1628
|
+
]
|
|
1629
|
+
: [];
|
|
1630
|
+
// EVERY bundle run says which authority produced the line, not only the
|
|
1631
|
+
// overridden ones. A green line's meaning depends entirely on that: a
|
|
1632
|
+
// comparison against the installed package is a different claim from a
|
|
1633
|
+
// comparison against the project's own tree at a pinned git ref, and a reader
|
|
1634
|
+
// cannot recover which one they are looking at from the verdict.
|
|
1635
|
+
const modeLines = result.mode === 'bundle' && result.sourceAuthority !== 'unresolved'
|
|
1636
|
+
? [
|
|
1637
|
+
` Source authority: ${authorityLabel(result.sourceAuthority)} at ` +
|
|
1638
|
+
`${result.sourceDir || 'unresolved'} (mode: bundle). There is no git ref behind this ` +
|
|
1639
|
+
`source, so every layer was compared against that directory as it is on disk now.`,
|
|
1640
|
+
]
|
|
1641
|
+
: [];
|
|
1642
|
+
if (result.verdict === 'COULD_NOT_RUN') {
|
|
1643
|
+
return [
|
|
1644
|
+
...overrideLines,
|
|
1645
|
+
`Config fidelity: COULD_NOT_RUN — ${result.reason ?? 'unknown reason'}.`,
|
|
1646
|
+
' Fidelity was NOT verified. This is not a pass.',
|
|
1647
|
+
...modeLines,
|
|
1648
|
+
];
|
|
1649
|
+
}
|
|
1650
|
+
if (result.verdict === 'CLEAN') {
|
|
1651
|
+
// The headline must not say OK when the comparison was against a source
|
|
1652
|
+
// someone else named: the exit code is 2, and a reader scanning the terminal
|
|
1653
|
+
// reads the word, not the exit code.
|
|
1654
|
+
const headline = result.sourceOverridden
|
|
1655
|
+
? `Config fidelity: comparison matched, but NOT VERIFIED — ${result.filesCompared} source file(s) ` +
|
|
1656
|
+
`match .claude/, measured against a source this run did not choose.`
|
|
1657
|
+
: `Config fidelity: OK — ${result.filesCompared} source file(s) match .claude/ ` +
|
|
1658
|
+
`(permission layer vs ${result.permissionRef}, behavioral layers vs ${result.behavioralRef}).`;
|
|
1659
|
+
return [
|
|
1660
|
+
...overrideLines,
|
|
1661
|
+
headline,
|
|
1662
|
+
// Per layer, so "0 hooks compared" is READ rather than inferred from a
|
|
1663
|
+
// total that another layer could have supplied on its own.
|
|
1664
|
+
` Compared per layer: ${perLayerSummary(result)}.`,
|
|
1665
|
+
...modeLines,
|
|
1666
|
+
...coverageCaveats(result),
|
|
1667
|
+
];
|
|
1668
|
+
}
|
|
1669
|
+
// TWO POPULATIONS, COUNTED SEPARATELY (round-8 SF-3). `mismatches` holds
|
|
1670
|
+
// forward-pass findings about SOURCE files (missing/differs) AND reverse-pass
|
|
1671
|
+
// `unaccounted` findings, which are DEPLOYED files with no source counterpart
|
|
1672
|
+
// and were never part of `filesCompared`. Counting all of them against
|
|
1673
|
+
// "of M source file(s)" produced an impossible ratio: 20 planted deployed
|
|
1674
|
+
// rules against an 11-file source printed `DRIFT — 20 of 11 source file(s)`.
|
|
1675
|
+
const sourceFindings = result.mismatches.filter((m) => m.kind !== 'unaccounted').length;
|
|
1676
|
+
const unaccounted = result.mismatches.length - sourceFindings;
|
|
1677
|
+
const headline = `Config fidelity: DRIFT — ${sourceFindings} of ${result.filesCompared} source file(s) ` +
|
|
1678
|
+
`do not match what is deployed in .claude/` +
|
|
1679
|
+
(unaccounted > 0
|
|
1680
|
+
? `; ${unaccounted} deployed file(s) unaccounted for (no source counterpart):`
|
|
1681
|
+
: ':');
|
|
1682
|
+
const lines = [
|
|
1683
|
+
...overrideLines,
|
|
1684
|
+
headline,
|
|
1685
|
+
// The per-layer line is printed on a DRIFTED run too. It used to appear on
|
|
1686
|
+
// CLEAN only, so on the run a reader is most likely to study, the annotation
|
|
1687
|
+
// saying which layers contributed nothing was invisible — and "3 files
|
|
1688
|
+
// drifted" reads very differently when a whole layer alongside them
|
|
1689
|
+
// contributed zero comparisons.
|
|
1690
|
+
` Compared per layer: ${perLayerSummary(result)}.`,
|
|
1691
|
+
...modeLines,
|
|
1692
|
+
];
|
|
1693
|
+
for (const m of result.mismatches) {
|
|
1694
|
+
// A reverse-inclusion finding names NO ref (round-7 SF-5): it was never
|
|
1695
|
+
// compared against one, and `deployed differs from source@origin/main` for a
|
|
1696
|
+
// file no source root mentions sends the reader to diff against a ref where
|
|
1697
|
+
// there is nothing to find.
|
|
1698
|
+
if (m.kind === 'unaccounted') {
|
|
1699
|
+
lines.push(` ${m.path} — ${m.detail ?? 'deployed file has no source counterpart'} ` +
|
|
1700
|
+
`(deployed-side finding; no source ref to compare against)`);
|
|
1701
|
+
continue;
|
|
1702
|
+
}
|
|
1703
|
+
const what = m.kind === 'missing' ? 'not deployed' : 'deployed differs';
|
|
1704
|
+
lines.push(` ${m.path} — ${what} from source@${m.ref}${m.detail ? ` (${m.detail})` : ''}`);
|
|
1705
|
+
}
|
|
1706
|
+
// The remedy differs by mode, and a command that cannot be pasted is worse
|
|
1707
|
+
// than none: in bundle mode there is no git ref to pin the permission layer to.
|
|
1708
|
+
lines.push(result.mode === 'repo'
|
|
1709
|
+
? ` Regenerate: ${generatorCommand(result)}`
|
|
1710
|
+
: ` Regenerate from the CLI bundle: mx-agent start (or reinstall the CLI if the bundle is stale)`);
|
|
1711
|
+
return lines;
|
|
1712
|
+
}
|
|
1713
|
+
//# sourceMappingURL=config-fidelity.js.map
|