@memnexus-ai/mx-agent-cli 0.1.291 → 0.1.293

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.
Files changed (50) hide show
  1. package/dist/__tests__/config-fidelity-unreadable-fixture.d.ts +32 -0
  2. package/dist/__tests__/config-fidelity-unreadable-fixture.d.ts.map +1 -0
  3. package/dist/__tests__/config-fidelity-unreadable-fixture.js +37 -0
  4. package/dist/__tests__/config-fidelity-unreadable-fixture.js.map +1 -0
  5. package/dist/__tests__/config-fidelity.test.d.ts +16 -0
  6. package/dist/__tests__/config-fidelity.test.d.ts.map +1 -0
  7. package/dist/__tests__/config-fidelity.test.js +2546 -0
  8. package/dist/__tests__/config-fidelity.test.js.map +1 -0
  9. package/dist/__tests__/doctor-config-fidelity.test.d.ts +19 -0
  10. package/dist/__tests__/doctor-config-fidelity.test.d.ts.map +1 -0
  11. package/dist/__tests__/doctor-config-fidelity.test.js +324 -0
  12. package/dist/__tests__/doctor-config-fidelity.test.js.map +1 -0
  13. package/dist/__tests__/doctor-framework-version.test.d.ts +2 -0
  14. package/dist/__tests__/doctor-framework-version.test.d.ts.map +1 -0
  15. package/dist/__tests__/doctor-framework-version.test.js +146 -0
  16. package/dist/__tests__/doctor-framework-version.test.js.map +1 -0
  17. package/dist/__tests__/mx-agent-cli-pin-validation.test.d.ts +2 -0
  18. package/dist/__tests__/mx-agent-cli-pin-validation.test.d.ts.map +1 -0
  19. package/dist/__tests__/mx-agent-cli-pin-validation.test.js +256 -0
  20. package/dist/__tests__/mx-agent-cli-pin-validation.test.js.map +1 -0
  21. package/dist/__tests__/mx-agent-cli-version-pin.test.d.ts +2 -0
  22. package/dist/__tests__/mx-agent-cli-version-pin.test.d.ts.map +1 -0
  23. package/dist/__tests__/mx-agent-cli-version-pin.test.js +290 -0
  24. package/dist/__tests__/mx-agent-cli-version-pin.test.js.map +1 -0
  25. package/dist/commands/doctor.d.ts +64 -7
  26. package/dist/commands/doctor.d.ts.map +1 -1
  27. package/dist/commands/doctor.js +122 -9
  28. package/dist/commands/doctor.js.map +1 -1
  29. package/dist/commands/new.d.ts.map +1 -1
  30. package/dist/commands/new.js +15 -1
  31. package/dist/commands/new.js.map +1 -1
  32. package/dist/commands/start.d.ts.map +1 -1
  33. package/dist/commands/start.js +56 -0
  34. package/dist/commands/start.js.map +1 -1
  35. package/dist/index.d.ts.map +1 -1
  36. package/dist/index.js +33 -9
  37. package/dist/index.js.map +1 -1
  38. package/dist/lib/config-fidelity.d.ts +500 -0
  39. package/dist/lib/config-fidelity.d.ts.map +1 -0
  40. package/dist/lib/config-fidelity.js +1713 -0
  41. package/dist/lib/config-fidelity.js.map +1 -0
  42. package/dist/lib/framework-version.d.ts +144 -0
  43. package/dist/lib/framework-version.d.ts.map +1 -0
  44. package/dist/lib/framework-version.js +270 -0
  45. package/dist/lib/framework-version.js.map +1 -0
  46. package/dist/lib/templates.d.ts +26 -0
  47. package/dist/lib/templates.d.ts.map +1 -1
  48. package/dist/lib/templates.js +81 -3
  49. package/dist/lib/templates.js.map +1 -1
  50. package/package.json +1 -1
@@ -0,0 +1,290 @@
1
+ /**
2
+ * The mx-agent CLI version pin has ONE source (#5371, A5).
3
+ *
4
+ * `.devcontainer/mx-agent-cli-version.pin` holds the version; post-create installs
5
+ * exactly it and REFUSES rather than falling back to `@latest`; post-start re-pins a
6
+ * drifted container instead of auto-updating it; the new-project scaffold writes a
7
+ * pin and a pinned bootstrap; and `mx-agent doctor` reports running-vs-pinned
8
+ * WITHOUT touching the exit code.
9
+ *
10
+ * Modelled on runtime-codex-version-pin.test.ts, which guards the same mechanism for
11
+ * `@openai/codex`. The assertions are deliberately shaped the same way — on the
12
+ * assignment LINE rather than a bare substring, so a typo like
13
+ * `mx-agent-cli-version.pinn` fails instead of passing on a superstring match.
14
+ *
15
+ * Every case here was mutation-checked: each was made to fail by reverting the
16
+ * behaviour it asserts before being accepted.
17
+ */
18
+ import { describe, it, expect } from 'vitest';
19
+ import { spawnSync } from 'child_process';
20
+ import { mkdtempSync, readFileSync, rmSync, writeFileSync } from 'fs';
21
+ import { tmpdir } from 'os';
22
+ import { join } from 'path';
23
+ import { mkdirSync } from 'fs';
24
+ import { checkPinAgainstRegistry, collectFrameworkVersion, describePinRegistryStatus, parsePinnedVersion, pinAssignments, readPinnedCliVersion, runningCliVersion, describeFrameworkVersion, } from '../lib/framework-version.js';
25
+ import { newProjectMxAgentCliVersionPinTemplate, newProjectPostCreateShTemplate, } from '../lib/templates.js';
26
+ const REPO_ROOT = join(__dirname, '..', '..', '..', '..');
27
+ const VERSION_PIN = join(REPO_ROOT, '.devcontainer', 'mx-agent-cli-version.pin');
28
+ const POST_CREATE = join(REPO_ROOT, '.devcontainer', 'post-create.sh');
29
+ const POST_START = join(REPO_ROOT, '.devcontainer', 'post-start.sh');
30
+ const REBUILD_DOC = join(REPO_ROOT, '.devcontainer', 'REBUILD.md');
31
+ /** The exact path both devcontainer scripts must read the pin from. */
32
+ const PIN_ASSIGNMENT = /MX_AGENT_CLI_VERSION_FILE="\$\(dirname "\$0"\)\/mx-agent-cli-version\.pin"/;
33
+ function pinnedVersion() {
34
+ const match = readFileSync(VERSION_PIN, 'utf-8').match(/^MX_AGENT_CLI_VERSION=(.+)$/m);
35
+ expect(match).not.toBeNull();
36
+ return match[1].trim();
37
+ }
38
+ describe('mx-agent-cli version pin — single source', () => {
39
+ it('the pin file declares a concrete version', () => {
40
+ expect(pinnedVersion()).toMatch(/^\d+\.\d+\.\d+$/);
41
+ });
42
+ it('the pin names a version that was actually published, not the stale committed one', () => {
43
+ // package.json in this repo is deliberately behind the registry: CI resolves the
44
+ // real version at publish time and never commits back. A pin copied from
45
+ // package.json would name 0.1.72 and every container would install a March
46
+ // release. This asserts the two are NOT the same string — the cheap, offline
47
+ // form of "read it with npm view".
48
+ const pkg = JSON.parse(readFileSync(join(__dirname, '..', '..', 'package.json'), 'utf-8'));
49
+ expect(pinnedVersion()).not.toBe(pkg.version);
50
+ });
51
+ });
52
+ describe('mx-agent-cli version pin — the devcontainer honours it', () => {
53
+ it('post-create installs the pinned version, not @latest', () => {
54
+ const text = readFileSync(POST_CREATE, 'utf-8');
55
+ const installLines = text.split('\n').filter((l) => l.includes('npm install -g'));
56
+ expect(installLines.join('\n')).toContain('@memnexus-ai/mx-agent-cli@${MX_AGENT_CLI_VERSION}');
57
+ // Scoped to the install lines: "@latest" also appears in the refusal message
58
+ // explaining why the pin exists, which is not a defect.
59
+ expect(installLines.join('\n')).not.toMatch(/@memnexus-ai\/mx-agent-cli@latest/);
60
+ });
61
+ it('post-create sources the single-source pin file', () => {
62
+ expect(readFileSync(POST_CREATE, 'utf-8')).toMatch(PIN_ASSIGNMENT);
63
+ });
64
+ it('post-create REFUSES and exits non-zero when the pin is missing', () => {
65
+ const text = readFileSync(POST_CREATE, 'utf-8');
66
+ const guard = text.slice(text.indexOf('MX_AGENT_CLI_VERSION_FILE'), text.indexOf('Installing pinned global CLIs'));
67
+ expect(guard).toMatch(/if \[ -z "\$\{MX_AGENT_CLI_VERSION:-\}" \]/);
68
+ expect(guard).toMatch(/exit 1/);
69
+ });
70
+ it('the install banner names the version it is actually installing', () => {
71
+ // The old banner said "Installing pinned global CLIs" while installing three of
72
+ // four packages at @latest. Whatever it claims to pin, it must print.
73
+ const banner = readFileSync(POST_CREATE, 'utf-8')
74
+ .split('\n')
75
+ .find((l) => l.includes('Installing pinned global CLIs'));
76
+ expect(banner).toBeDefined();
77
+ expect(banner).toContain('mx-agent-cli@${MX_AGENT_CLI_VERSION}');
78
+ });
79
+ it('post-start re-pins mx-agent-cli and does NOT auto-update it to latest', () => {
80
+ const text = readFileSync(POST_START, 'utf-8');
81
+ expect(text).toContain('@memnexus-ai/mx-agent-cli@${MX_AGENT_CLI_VERSION}');
82
+ // This is the #5371 defect itself: an unattended @latest install on every
83
+ // container start, which is why a hand-pinned version could not survive a restart.
84
+ expect(text).not.toMatch(/npm_global_update\s+@memnexus-ai\/mx-agent-cli@latest/);
85
+ });
86
+ it('post-start sources the single-source pin file', () => {
87
+ expect(readFileSync(POST_START, 'utf-8')).toMatch(PIN_ASSIGNMENT);
88
+ });
89
+ it('post-start warns and installs NOTHING when the pin file is absent', () => {
90
+ const text = readFileSync(POST_START, 'utf-8');
91
+ expect(text).toMatch(/mx-agent-cli version pin NOT enforced/);
92
+ // Non-blocking by design (it runs unattended on every container start), so the
93
+ // refusal is "do not change the installed version", never a fallback to @latest.
94
+ expect(text).not.toMatch(/npm install -g @memnexus-ai\/mx-agent-cli@latest/);
95
+ });
96
+ it('REBUILD.md no longer claims mx-agent-cli is installed at @latest', () => {
97
+ const doc = readFileSync(REBUILD_DOC, 'utf-8');
98
+ expect(doc).toContain('mx-agent-cli-version.pin');
99
+ expect(doc).not.toMatch(/`@memnexus-ai\/mx-agent-cli`,\n\s*`@memnexus-ai\/mx-guard`, `@openai\/codex`, `@memnexus-ai\/cli` \(all `@latest`\)/);
100
+ });
101
+ });
102
+ describe('new-project scaffold — the generated bootstrap is pinned', () => {
103
+ it('the generated post-create installs a pinned version, never @latest', () => {
104
+ const script = newProjectPostCreateShTemplate('demo');
105
+ const installLines = script.split('\n').filter((l) => l.includes('npm install -g'));
106
+ const cliLines = installLines.filter((l) => l.includes('mx-agent-cli'));
107
+ expect(cliLines.length).toBe(1);
108
+ expect(cliLines[0]).toContain('@memnexus-ai/mx-agent-cli@${MX_AGENT_CLI_VERSION}');
109
+ expect(cliLines[0]).not.toMatch(/mx-agent-cli(@latest)?\s+--registry/);
110
+ });
111
+ it('the generated post-create refuses when the generated pin is missing', () => {
112
+ const script = newProjectPostCreateShTemplate('demo');
113
+ expect(script).toMatch(PIN_ASSIGNMENT);
114
+ expect(script).toMatch(/if \[ -z "\$\{MX_AGENT_CLI_VERSION:-\}" \]/);
115
+ const guard = script.slice(script.indexOf('MX_AGENT_CLI_VERSION_FILE'));
116
+ expect(guard.slice(0, guard.indexOf('npm install -g'))).toMatch(/exit 1/);
117
+ });
118
+ it('the generated pin file is parseable by the same parser doctor uses', () => {
119
+ const pin = newProjectMxAgentCliVersionPinTemplate('1.2.3');
120
+ expect(parsePinnedVersion(pin)).toBe('1.2.3');
121
+ });
122
+ it('the generated guard actually refuses at runtime, and installs the pin when present', () => {
123
+ // The other cases in this block read the script as text. This one RUNS the guard
124
+ // block, because the escaping in a TypeScript template literal producing shell is
125
+ // exactly where a `\${` typo turns a refusal into an unpinned install that reads
126
+ // fine on the page. `npm install` is replaced by an echo so nothing is fetched.
127
+ const dir = mkdtempSync(join(tmpdir(), 'mx-gen-postcreate-'));
128
+ try {
129
+ const script = newProjectPostCreateShTemplate('demo');
130
+ const start = script.indexOf('MX_AGENT_CLI_VERSION_FILE=');
131
+ const guard = script
132
+ .slice(start, script.indexOf('\n', script.indexOf('mx-agent-cli@${MX_AGENT_CLI_VERSION}')))
133
+ .replace('npm install -g', 'echo INSTALL');
134
+ writeFileSync(join(dir, 'probe.sh'), guard + '\n');
135
+ const missing = spawnSync('bash', [join(dir, 'probe.sh')], { encoding: 'utf-8' });
136
+ expect(missing.status).toBe(1);
137
+ expect(missing.stdout).not.toContain('INSTALL');
138
+ writeFileSync(join(dir, 'mx-agent-cli-version.pin'), newProjectMxAgentCliVersionPinTemplate('1.2.3'));
139
+ const present = spawnSync('bash', [join(dir, 'probe.sh')], { encoding: 'utf-8' });
140
+ expect(present.status).toBe(0);
141
+ expect(present.stdout).toContain('@memnexus-ai/mx-agent-cli@1.2.3');
142
+ }
143
+ finally {
144
+ rmSync(dir, { recursive: true, force: true });
145
+ }
146
+ });
147
+ it('the scaffold pins the version of the CLI doing the scaffolding', () => {
148
+ // new.ts passes runningCliVersion() in; this asserts that value is a usable
149
+ // concrete version rather than null or a range.
150
+ const v = runningCliVersion();
151
+ expect(v).toMatch(/^\d+\.\d+\.\d+/);
152
+ expect(parsePinnedVersion(newProjectMxAgentCliVersionPinTemplate(v))).toBe(v);
153
+ });
154
+ });
155
+ describe('pin parser — matches what the shell would do', () => {
156
+ it('reads the assignment', () => {
157
+ expect(parsePinnedVersion('# comment\nMX_AGENT_CLI_VERSION=0.1.291\n')).toBe('0.1.291');
158
+ });
159
+ it('ignores a commented-out assignment, exactly as `.`-sourcing would', () => {
160
+ expect(parsePinnedVersion('#MX_AGENT_CLI_VERSION=9.9.9\n')).toBeNull();
161
+ });
162
+ it('refuses a range or a dist-tag — a pin that is not a version is not a pin', () => {
163
+ expect(parsePinnedVersion('MX_AGENT_CLI_VERSION=latest\n')).toBeNull();
164
+ expect(parsePinnedVersion('MX_AGENT_CLI_VERSION=^1.2.3\n')).toBeNull();
165
+ expect(parsePinnedVersion('MX_AGENT_CLI_VERSION=1.2\n')).toBeNull();
166
+ expect(parsePinnedVersion('MX_AGENT_CLI_VERSION=\n')).toBeNull();
167
+ });
168
+ it('accepts a prerelease', () => {
169
+ expect(parsePinnedVersion('MX_AGENT_CLI_VERSION=1.2.3-rc.1\n')).toBe('1.2.3-rc.1');
170
+ });
171
+ it('REFUSES a file with two assignments instead of silently reporting the first', () => {
172
+ // The parser used to return the FIRST match while `.`-sourcing honours the
173
+ // LAST. A two-line pin file therefore made doctor report 0.1.291 while the
174
+ // devcontainer installed line 2 — the report concealing the very value it
175
+ // exists to surface. Two assignments is now NOT a pin.
176
+ const text = 'MX_AGENT_CLI_VERSION=0.1.291\nMX_AGENT_CLI_VERSION=0.1.999\n';
177
+ expect(pinAssignments(text)).toEqual(['0.1.291', '0.1.999']);
178
+ expect(parsePinnedVersion(text)).toBeNull();
179
+ });
180
+ it('the refusal names the LAST value, because that is the one the shell would install', () => {
181
+ const dir = mkdtempSync(join(tmpdir(), 'mx-pin-multi-'));
182
+ try {
183
+ mkdirSync(join(dir, '.devcontainer'));
184
+ writeFileSync(join(dir, '.devcontainer', 'mx-agent-cli-version.pin'), 'MX_AGENT_CLI_VERSION=0.1.291\nMX_AGENT_CLI_VERSION=https://evil.example/p.tgz\n');
185
+ const r = readPinnedCliVersion(dir);
186
+ expect(r.version).toBeNull();
187
+ expect(r.error).toMatch(/2 MX_AGENT_CLI_VERSION assignments/);
188
+ expect(r.error).toMatch(/evil\.example/);
189
+ // Not the misleading message: the file has lines, it has too many.
190
+ expect(r.error).not.toMatch(/no parseable/);
191
+ }
192
+ finally {
193
+ rmSync(dir, { recursive: true, force: true });
194
+ }
195
+ });
196
+ it('reports a missing pin file as an absence, not a crash', () => {
197
+ const r = readPinnedCliVersion('/nonexistent-project-root-for-tests');
198
+ expect(r.version).toBeNull();
199
+ expect(r.error).toMatch(/no pin file/);
200
+ });
201
+ });
202
+ describe('pin vs REGISTRY — is the pinned version still the right one to be on?', () => {
203
+ // Nothing else watches the pin: dependabot reads npm manifests and no workflow
204
+ // references a `.pin` file, so a withdrawn or long-superseded pin reads as a
205
+ // clean MATCH. Every case here injects the reader — no test touches the network.
206
+ const registryJson = (latest, versions) => JSON.stringify({ 'dist-tags.latest': latest, versions });
207
+ it('says nothing when there is no pin — there is nothing to compare', () => {
208
+ expect(checkPinAgainstRegistry(null, () => registryJson('9.9.9', ['9.9.9']))).toBeNull();
209
+ });
210
+ it('names the newer published version when the pin is behind', () => {
211
+ const s = checkPinAgainstRegistry('0.1.291', () => registryJson('0.1.400', ['0.1.291', '0.1.400']));
212
+ expect(s.error).toBeNull();
213
+ expect(s.latest).toBe('0.1.400');
214
+ expect(s.pinnedIsPublished).toBe(true);
215
+ const lines = describePinRegistryStatus('0.1.291', s).join('\n');
216
+ expect(lines).toContain('behind latest 0.1.400');
217
+ });
218
+ it('flags a pin that is no longer published at all', () => {
219
+ const s = checkPinAgainstRegistry('0.1.291', () => registryJson('0.1.400', ['0.1.400']));
220
+ expect(s.pinnedIsPublished).toBe(false);
221
+ const lines = describePinRegistryStatus('0.1.291', s).join('\n');
222
+ expect(lines).toMatch(/NOT published/);
223
+ expect(lines).toMatch(/E404/);
224
+ });
225
+ it('is quiet when the pin is the latest published version', () => {
226
+ const s = checkPinAgainstRegistry('0.1.400', () => registryJson('0.1.400', ['0.1.291', '0.1.400']));
227
+ const lines = describePinRegistryStatus('0.1.400', s).join('\n');
228
+ expect(lines).toContain('is the latest published version');
229
+ expect(lines).not.toMatch(/behind|NOT published/);
230
+ });
231
+ it('degrades to a printed line when the registry is unreachable — never a throw', () => {
232
+ const s = checkPinAgainstRegistry('0.1.291', () => {
233
+ throw new Error('getaddrinfo ENOTFOUND registry.npmjs.org');
234
+ });
235
+ expect(s.error).toMatch(/ENOTFOUND/);
236
+ expect(s.latest).toBeNull();
237
+ const lines = describePinRegistryStatus('0.1.291', s).join('\n');
238
+ expect(lines).toContain('not checked');
239
+ expect(lines).toContain('does not affect the exit code');
240
+ });
241
+ it('degrades the same way on unparseable output', () => {
242
+ const s = checkPinAgainstRegistry('0.1.291', () => 'npm ERR! code E403');
243
+ expect(s.error).not.toBeNull();
244
+ expect(describePinRegistryStatus('0.1.291', s).join('\n')).toContain('not checked');
245
+ });
246
+ it('honours the documented opt-out without calling the reader', () => {
247
+ process.env.MX_AGENT_DOCTOR_NO_NETWORK = '1';
248
+ try {
249
+ let called = false;
250
+ const s = checkPinAgainstRegistry('0.1.291', () => {
251
+ called = true;
252
+ return registryJson('0.1.400', ['0.1.400']);
253
+ });
254
+ expect(called).toBe(false);
255
+ expect(s.error).toMatch(/MX_AGENT_DOCTOR_NO_NETWORK/);
256
+ // Skipped is SAID, not silently treated as a pass.
257
+ expect(describePinRegistryStatus('0.1.291', s).join('\n')).toContain('not checked');
258
+ }
259
+ finally {
260
+ delete process.env.MX_AGENT_DOCTOR_NO_NETWORK;
261
+ }
262
+ });
263
+ });
264
+ describe('framework version report', () => {
265
+ it('this repo reports a status derived from both numbers', () => {
266
+ const r = collectFrameworkVersion(REPO_ROOT);
267
+ expect(r.pinned).toBe(pinnedVersion());
268
+ expect(r.running).toBe(runningCliVersion());
269
+ expect(r.status).toBe(r.running === r.pinned ? 'MATCH' : 'MISMATCH');
270
+ });
271
+ it('describes a mismatch by naming both versions and the remedy', () => {
272
+ const lines = describeFrameworkVersion({
273
+ running: '0.1.72',
274
+ pinned: '0.1.291',
275
+ pinPath: '/p/.devcontainer/mx-agent-cli-version.pin',
276
+ pinError: null,
277
+ status: 'MISMATCH',
278
+ });
279
+ expect(lines[0]).toContain('MISMATCH');
280
+ expect(lines[0]).toContain('0.1.72');
281
+ expect(lines[0]).toContain('0.1.291');
282
+ expect(lines.join('\n')).toContain('npm install -g @memnexus-ai/mx-agent-cli@0.1.291');
283
+ });
284
+ it('says NOT PINNED when no pin file exists, instead of reporting a pass', () => {
285
+ const r = collectFrameworkVersion('/nonexistent-project-root-for-tests');
286
+ expect(r.status).toBe('NO_PIN');
287
+ expect(describeFrameworkVersion(r).join('\n')).toContain('NOT PINNED');
288
+ });
289
+ });
290
+ //# sourceMappingURL=mx-agent-cli-version-pin.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mx-agent-cli-version-pin.test.js","sourceRoot":"","sources":["../../src/__tests__/mx-agent-cli-version-pin.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,IAAI,CAAC;AACtE,OAAO,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC;AAC5B,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAC/B,OAAO,EACL,uBAAuB,EACvB,uBAAuB,EACvB,yBAAyB,EACzB,kBAAkB,EAClB,cAAc,EACd,oBAAoB,EACpB,iBAAiB,EACjB,wBAAwB,GACzB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EACL,sCAAsC,EACtC,8BAA8B,GAC/B,MAAM,qBAAqB,CAAC;AAE7B,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,EAAE,IAAI,EAA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AAI,CAAC,CAAC,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC;IACzE,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -6,13 +6,26 @@
6
6
  * (#4498). Read-only: it reads /proc, /sys and statfs, and writes exactly one
7
7
  * file — the last-reading cache under ~/.mx-agent/doctor-last-reading/.
8
8
  *
9
- * ADVISORY ONLY — THE EXIT CODE IS ALWAYS 0.
10
- * Do not put this command in an `&&` chain, a CI gate, or a startup blocker. The
11
- * failure it detects is host-side and cannot be fixed from inside the container,
12
- * so a non-zero exit would be permanently red on every machine that has not
13
- * applied the host fix. Everyone would learn to ignore it — which is the exact
14
- * failure mode this command exists to prevent (nobody checked anything on
15
- * 2026-07-24 until the editor had been frozen for two days).
9
+ * THE VM CHECKS ARE ADVISORY AND NEVER SET A NON-ZERO EXIT CODE.
10
+ * Do not read a VM check as a gate. The failure it detects is host-side and
11
+ * cannot be fixed from inside the container, so a non-zero exit would be
12
+ * permanently red on every machine that has not applied the host fix. Everyone
13
+ * would learn to ignore it — which is the exact failure mode this command exists
14
+ * to prevent (nobody checked anything on 2026-07-24 until the editor had been
15
+ * frozen for two days).
16
+ *
17
+ * ONE CHECK DOES OWN THE EXIT CODE: CONFIG FIDELITY (#5412, A2).
18
+ * `mx-agent doctor` is the primary surface for the deployed-vs-source agent-config
19
+ * assertion in config-fidelity.ts, and that check is fail-CLOSED by design:
20
+ * 0 — deployed `.claude/` matches its source
21
+ * 1 — drift, with every mismatching path, its layer and the ref it was compared against
22
+ * 2 — fidelity could not be determined (source unresolvable, origin/<base>
23
+ * unavailable, settings.json unparseable). Never reported as a pass.
24
+ * The two contracts do not conflict because they cover different conditions: a VM
25
+ * condition is host-side and unfixable from here, while config drift is
26
+ * in-container, actionable, and is the entire framework/consumer seam after the
27
+ * extraction. Nothing else contributes to the exit code: a FAIL on swap sizing
28
+ * or OOM kills still exits 0, exactly as before.
16
29
  *
17
30
  * DELTA-BASED BY DEFAULT.
18
31
  * Steady state is quiet. The command is loud only when a measured number has
@@ -73,6 +86,8 @@
73
86
  * without checking it. Re-run those three commands before editing these lines.
74
87
  */
75
88
  import { type DoctorCheck, type DoctorReading, type Regression } from '../lib/vm-health.js';
89
+ import { type ConfigFidelityResult } from '../lib/config-fidelity.js';
90
+ import { type FrameworkVersionReport, type PinRegistryStatus } from '../lib/framework-version.js';
76
91
  /**
77
92
  * Which path is running the checks.
78
93
  *
@@ -98,6 +113,23 @@ export interface DoctorOptions {
98
113
  json?: boolean;
99
114
  /** Override the last-reading cache path (test seam). */
100
115
  readingPath?: string;
116
+ /**
117
+ * Worktree whose `.claude/` is checked for config fidelity. Defaults to
118
+ * CLAUDE_WORKTREE_PATH, then cwd. Only consulted in 'interactive' mode.
119
+ */
120
+ worktreePath?: string;
121
+ /** Base branch the deployed permission layer is pinned to. Default 'main'. */
122
+ baseBranch?: string;
123
+ /**
124
+ * Explicit agent-config source dir for the fidelity check (test seam).
125
+ *
126
+ * Exists because the alternative — steering the source with
127
+ * MX_BUNDLED_CONFIG_DIR — is the exact capability the checker now refuses to
128
+ * honour above the project's own tree, and a test that depends on an
129
+ * environment override cannot exercise the resolution order the field uses.
130
+ * Passing it in-process keeps the decision at the call site.
131
+ */
132
+ sourceDir?: string;
101
133
  }
102
134
  export interface AgentFootprint {
103
135
  sessions: number;
@@ -134,6 +166,31 @@ export interface DoctorResult {
134
166
  previous: DoctorReading | null;
135
167
  /** True when the host-side remedy applies to what we measured. */
136
168
  remedyApplies: boolean;
169
+ /**
170
+ * Deployed-vs-source agent-config fidelity (#5412). Null in 'startup' mode:
171
+ * the session-start path runs its own report-only fidelity check in start.ts
172
+ * (before the hook heal, so the heal cannot erase the evidence), and this
173
+ * check reads git and a few hundred files — cost the startup path should pay
174
+ * exactly once, in the place that owns it.
175
+ */
176
+ fidelity: ConfigFidelityResult | null;
177
+ /**
178
+ * Running-vs-pinned mx-agent CLI version (#5371). Null in 'startup' mode for
179
+ * the same reason as `fidelity`: it reads a file on the workspace filesystem,
180
+ * and the session-start path deliberately avoids workspace I/O it cannot bound
181
+ * (see checkDisk). It is a REPORT — nothing here reaches process.exitCode.
182
+ */
183
+ frameworkVersion: FrameworkVersionReport | null;
184
+ /**
185
+ * Pinned-vs-REGISTRY (#5371 security review). The report above compares running
186
+ * against pinned and would call a withdrawn or long-superseded pin a clean
187
+ * MATCH; nothing else in the repo watches the pin (dependabot reads npm
188
+ * manifests, and no workflow references a `.pin` file). Null in 'startup' mode
189
+ * and whenever there is no pin to compare. ADVISORY: one bounded `npm view`,
190
+ * every failure degrades to a printed "not checked" line, and nothing here
191
+ * reaches process.exitCode. Skip with MX_AGENT_DOCTOR_NO_NETWORK=1.
192
+ */
193
+ pinRegistry: PinRegistryStatus | null;
137
194
  }
138
195
  /**
139
196
  * Run every check and assemble the result. Exported so tests and future callers
@@ -1 +1 @@
1
- {"version":3,"file":"doctor.d.ts","sourceRoot":"","sources":["../../src/commands/doctor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyEG;AAGH,OAAO,EA4BL,KAAK,WAAW,EAChB,KAAK,aAAa,EAClB,KAAK,UAAU,EAEhB,MAAM,qBAAqB,CAAC;AAE7B;;;;;;GAMG;AACH,MAAM,MAAM,aAAa,GAAG,aAAa,GAAG,SAAS,CAAC;AAEtD,MAAM,WAAW,aAAa;IAC5B;;;;;;;;OAQG;IACH,IAAI,EAAE,aAAa,CAAC;IACpB,0EAA0E;IAC1E,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,gEAAgE;IAChE,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,wDAAwD;IACxD,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AA2MD,MAAM,WAAW,cAAc;IAC7B,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAA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AMG;IACH,QAAQ,EAAE,oBAAoB,GAAG,IAAI,CAAC;IACtC;;;;;OAKG;IACH,gBAAgB,EAAE,sBAAsB,GAAG,IAAI,CAAC;IAChD;;;;;;;;OAQG;IACH,WAAW,EAAE,iBAAiB,GAAG,IAAI,CAAC;CACvC;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,aAAa,GAAG,YAAY,CAyExE;AAID;;;;;;;;;;GAUG;AACH,eAAO,MAAM,0BAA0B,QAAiB,CAAC;AAEzD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,2BAA2B,CAAC,GAAG,SAAa,EAAE,IAAI,SAAsB,GAAG,OAAO,CAWjG;AA6BD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,6BAA6B,CAAC,CAAC,EAAE,UAAU,GAAG,MAAM,CAEnE;AAED,wBAAgB,qBAAqB,CAAC,OAAO,GAAE;IAAE,GAAG,CAAC,EAAE,MAAM,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAA;CAAO,GAAG,UAAU,EAAE,CAQxG;AAuED,wBAAgB,SAAS,CAAC,OAAO,EAAE,aAAa,GAAG,IAAI,CAwEtD"}
@@ -6,13 +6,26 @@
6
6
  * (#4498). Read-only: it reads /proc, /sys and statfs, and writes exactly one
7
7
  * file — the last-reading cache under ~/.mx-agent/doctor-last-reading/.
8
8
  *
9
- * ADVISORY ONLY — THE EXIT CODE IS ALWAYS 0.
10
- * Do not put this command in an `&&` chain, a CI gate, or a startup blocker. The
11
- * failure it detects is host-side and cannot be fixed from inside the container,
12
- * so a non-zero exit would be permanently red on every machine that has not
13
- * applied the host fix. Everyone would learn to ignore it — which is the exact
14
- * failure mode this command exists to prevent (nobody checked anything on
15
- * 2026-07-24 until the editor had been frozen for two days).
9
+ * THE VM CHECKS ARE ADVISORY AND NEVER SET A NON-ZERO EXIT CODE.
10
+ * Do not read a VM check as a gate. The failure it detects is host-side and
11
+ * cannot be fixed from inside the container, so a non-zero exit would be
12
+ * permanently red on every machine that has not applied the host fix. Everyone
13
+ * would learn to ignore it — which is the exact failure mode this command exists
14
+ * to prevent (nobody checked anything on 2026-07-24 until the editor had been
15
+ * frozen for two days).
16
+ *
17
+ * ONE CHECK DOES OWN THE EXIT CODE: CONFIG FIDELITY (#5412, A2).
18
+ * `mx-agent doctor` is the primary surface for the deployed-vs-source agent-config
19
+ * assertion in config-fidelity.ts, and that check is fail-CLOSED by design:
20
+ * 0 — deployed `.claude/` matches its source
21
+ * 1 — drift, with every mismatching path, its layer and the ref it was compared against
22
+ * 2 — fidelity could not be determined (source unresolvable, origin/<base>
23
+ * unavailable, settings.json unparseable). Never reported as a pass.
24
+ * The two contracts do not conflict because they cover different conditions: a VM
25
+ * condition is host-side and unfixable from here, while config drift is
26
+ * in-container, actionable, and is the entire framework/consumer seam after the
27
+ * extraction. Nothing else contributes to the exit code: a FAIL on swap sizing
28
+ * or OOM kills still exits 0, exactly as before.
16
29
  *
17
30
  * DELTA-BASED BY DEFAULT.
18
31
  * Steady state is quiet. The command is loud only when a measured number has
@@ -74,6 +87,9 @@
74
87
  */
75
88
  import chalk from 'chalk';
76
89
  import { MAX_BOUNDED_PIDS, RECOMMENDED_SWAP_KB, REMEDY_DOC_PATH, SWAPPINESS_REMEDY, SWAP_DRAIN_CAVEAT, SWAP_DRAIN_COMMAND, WSLCONFIG_REMEDY, boundPids, collectCgroupMemoryLimit, collectDisk, collectDmesg, collectInotifyCaps, collectInotifyUsage, collectMeminfo, collectProcesses, collectProcessesByPid, collectUptimeSeconds, collectVmstat, describeOomEventTime, detectRegressions, doctorReadingPath, formatBytes, formatKb, loadLastReading, parseOomEvents, pgrepPids, saveReading, } from '../lib/vm-health.js';
90
+ import { checkConfigFidelity, describeConfigFidelity, fidelityExitCode, } from '../lib/config-fidelity.js';
91
+ import { checkPinAgainstRegistry, collectFrameworkVersion, describeFrameworkVersion, describePinRegistryStatus, } from '../lib/framework-version.js';
92
+ import { loadProjectConfig, resolveProjectConfig } from '../lib/project-config.js';
77
93
  /** WARN when either inotify counter exceeds this share of its cap. */
78
94
  const INOTIFY_WARN_FRACTION = 0.5;
79
95
  /** WARN when a filesystem has less than this share free. */
@@ -502,7 +518,37 @@ export function collectDoctorResult(options) {
502
518
  const previous = loadLastReading(readingPath);
503
519
  const regressions = detectRegressions(previous, reading);
504
520
  saveReading(reading, readingPath);
521
+ let fidelity = null;
522
+ let frameworkVersion = null;
523
+ let pinRegistry = null;
524
+ if (mode === 'interactive') {
525
+ const worktreePath = options.worktreePath ?? process.env.CLAUDE_WORKTREE_PATH ?? process.cwd();
526
+ frameworkVersion = collectFrameworkVersion(worktreePath);
527
+ // Interactive ONLY, like the two checks above, and for a stronger reason: this
528
+ // one leaves the machine. It is bounded (5 s) and fail-open, but the
529
+ // session-start path must never wait on a registry.
530
+ pinRegistry = checkPinAgainstRegistry(frameworkVersion.pinned);
531
+ // configSource is a documented field of mx-agent.config.json, and a consumer
532
+ // that sets it (e.g. 'config/agents') is the post-extraction shape. Without
533
+ // threading it the check compares the wrong tree — or, where no bundle
534
+ // resolves, degrades to a permanent COULD_NOT_RUN — and either way stops
535
+ // being an assertion about that project's config.
536
+ const projectCfg = resolveProjectConfig(loadProjectConfig(worktreePath));
537
+ fidelity = checkConfigFidelity(worktreePath, {
538
+ // Untrusted (mx-agent.config.json is checked-in and agent-editable).
539
+ // checkConfigFidelity sanitizes it with isolation-probe's safeConfigSource
540
+ // before it reaches any path join or git pathspec — deliberately at that
541
+ // one choke point rather than here, so this call site and start.ts's
542
+ // cannot drift apart on what the field is allowed to say.
543
+ configSource: projectCfg.configSource,
544
+ ...(options.baseBranch ? { baseBranch: options.baseBranch } : {}),
545
+ ...(options.sourceDir ? { sourceDir: options.sourceDir } : {}),
546
+ });
547
+ }
505
548
  return {
549
+ fidelity,
550
+ frameworkVersion,
551
+ pinRegistry,
506
552
  timestamp: reading.timestamp,
507
553
  checks,
508
554
  regressions,
@@ -638,10 +684,63 @@ function printRemedy(changed) {
638
684
  // tempting.
639
685
  console.log(chalk.yellow(` Warning: ${SWAP_DRAIN_CAVEAT}`));
640
686
  }
687
+ /**
688
+ * Print the config fidelity section and return the exit code it demands.
689
+ *
690
+ * The renderer NEVER heals and never rewrites anything: a checker that repairs
691
+ * what it found erases its own evidence, and the heal already has an owner
692
+ * (verifyAndHealHooks). It prints the paths and the refs and stops.
693
+ */
694
+ function reportFidelity(result) {
695
+ if (!result)
696
+ return 0;
697
+ const lines = describeConfigFidelity(result);
698
+ console.log();
699
+ // COLOUR FROM THE EXIT CODE, NOT FROM THE VERDICT. A CLEAN comparison against
700
+ // a source someone else named exits 2, and painting it from `verdict` printed
701
+ // the SOURCE OVERRIDDEN warning in green bold followed by a green line — a
702
+ // human scanning the terminal sees green and stops reading, while `$?` says
703
+ // NOT VERIFIED. One input, so the two can never disagree again.
704
+ const code = fidelityExitCode(result);
705
+ const paint = code === 0 ? chalk.green : code === 1 ? chalk.red : chalk.yellow;
706
+ console.log(paint.bold(lines[0]));
707
+ for (const line of lines.slice(1))
708
+ console.log(paint(line));
709
+ return code;
710
+ }
711
+ /**
712
+ * Print the framework version report. Returns NOTHING, deliberately — compare
713
+ * with reportFidelity above, which returns the exit code it demands. A mismatch
714
+ * here is a real condition worth colouring yellow, but it must not move `$?`:
715
+ * doctor's exit code is the config-fidelity verdict alone (file header), and a
716
+ * second contributor makes 1 ambiguous between "config drifted from source" and
717
+ * "container is a release behind".
718
+ */
719
+ function reportFrameworkVersion(report, registry) {
720
+ if (!report)
721
+ return;
722
+ const lines = describeFrameworkVersion(report);
723
+ const paint = report.status === 'MATCH' ? chalk.dim : report.status === 'MISMATCH' ? chalk.yellow : chalk.dim;
724
+ console.log();
725
+ console.log(report.status === 'MISMATCH' ? paint.bold(lines[0]) : paint(lines[0]));
726
+ for (const line of lines.slice(1))
727
+ console.log(paint(line));
728
+ // The pin-vs-registry advisory, painted from its own condition rather than the
729
+ // running-vs-pinned status: a container can MATCH its pin perfectly while the
730
+ // pin names a version npm no longer serves. Still returns nothing — same
731
+ // exit-code contract as the block above.
732
+ const regLines = describePinRegistryStatus(report.pinned, registry);
733
+ const regPaint = registry && !registry.error && registry.pinnedIsPublished === false ? chalk.yellow : chalk.dim;
734
+ for (const line of regLines)
735
+ console.log(regPaint(line));
736
+ }
641
737
  export function runDoctor(options) {
642
738
  const result = collectDoctorResult(options);
643
739
  if (options.json) {
644
740
  console.log(JSON.stringify(result, null, 2));
741
+ // The exit code is the fidelity verdict in --json too: a machine reading the
742
+ // JSON and a shell reading `$?` must not get different answers.
743
+ process.exitCode = result.fidelity ? fidelityExitCode(result.fidelity) : 0;
645
744
  return;
646
745
  }
647
746
  const counts = { OK: 0, WARN: 0, FAIL: 0, UNAVAILABLE: 0 };
@@ -678,11 +777,25 @@ export function runDoctor(options) {
678
777
  }
679
778
  if (result.remedyApplies)
680
779
  printRemedy(result.regressions.length > 0);
780
+ // The ONLY exit-code assignment in this command, and it comes from the
781
+ // fail-closed fidelity assertion — never from a VM check. See the file header.
782
+ //
783
+ // ASSIGNED HERE, not after the summary lines below: every console.log between
784
+ // this point and the end of the function can throw EPIPE (`mx-agent doctor |
785
+ // head` closes the pipe), and an assignment placed after them leaves the
786
+ // process exiting 0 with drift detected — the check silently reporting a pass.
787
+ const fidelityExit = reportFidelity(result.fidelity);
788
+ process.exitCode = fidelityExit;
789
+ // AFTER the assignment above, on purpose. This section is advisory and prints
790
+ // several lines; printing it first would put more EPIPE-capable console.logs
791
+ // between the start of the function and the only exit-code assignment, which
792
+ // is the failure the comment above exists to prevent.
793
+ reportFrameworkVersion(result.frameworkVersion, result.pinRegistry);
681
794
  console.log();
682
795
  console.log(chalk.dim(` ${result.checks.length} checks: ${counts.OK} OK, ${counts.WARN} WARN, ${counts.FAIL} FAIL, ${counts.UNAVAILABLE} unavailable.` +
683
796
  (options.verbose ? '' : ' Run --verbose for every number.')));
684
- console.log(chalk.dim(' Advisory only: this command always exits 0. Do not use it as a gate.'));
797
+ console.log(chalk.dim(' VM checks are advisory and never set the exit code. The exit code is the config fidelity verdict ' +
798
+ '(0 match, 1 drift, 2 could not determine).'));
685
799
  console.log();
686
- // Deliberately no process.exitCode assignment. See the file header.
687
800
  }
688
801
  //# sourceMappingURL=doctor.js.map