checkchange 0.4.0 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,56 +1,330 @@
1
- # checkchange
2
- Independent, deterministic evidence and verification layer for AI-assisted software development.
1
+ # CheckChange
3
2
 
4
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
5
- [![Node: 24](https://img.shields.io/badge/Node-24-green.svg)](.nvmrc)
3
+ **Independent, deterministic evidence for AI-assisted software development.**
6
4
 
7
- ## Install
5
+ AI coding tools can make a lot of software changes very quickly. That's useful, but it also creates a new question:
8
6
 
9
- Verified from-source (registry install available **after npm publish** — gated on `npm view checkchange version` returning 2xx):
7
+ **How do we independently check the change without simply asking another AI what it thinks?**
8
+
9
+ That's what CheckChange is for.
10
+
11
+ CheckChange looks at the functions changed in a Git repository and uses measurable evidence such as complexity, test coverage, coverage attribution, and deterministic CRAP calculations to produce evidence about the change.
12
+
13
+ It is not trying to decide whether the code is correct. It is not another AI code reviewer. It gives developers, CI systems, and other tools something concrete to look at.
14
+
15
+
16
+ ---
17
+
18
+ ## What it does
19
+
20
+ At a high level:
21
+
22
+ ```text
23
+ Git change
24
+ ↓
25
+ Changed functions
26
+ ↓
27
+ Complexity + coverage
28
+ ↓
29
+ Coverage attribution
30
+ ↓
31
+ CRAP calculation
32
+ ↓
33
+ Deterministic rules
34
+ ↓
35
+ Evidence
36
+ ```
37
+
38
+ The result tells you what CheckChange was able to establish about the change, rather than pretending that missing evidence is the same thing as good evidence.
39
+
40
+ For example, a changed function might produce:
41
+
42
+ ```text
43
+ Complexity
44
+ 12 → 17
45
+
46
+ Coverage
47
+ 84% → 61%
48
+
49
+ CRAP
50
+ increased
51
+
52
+ Result
53
+ WARN
54
+ ```
55
+
56
+ That does **not** mean the function is defective. It means there is evidence worth looking at.
57
+
58
+ CheckChange is intended to be used as:
59
+
60
+ - a developer-side check
61
+ - a CI step
62
+ - a pull-request signal
63
+ - an input to another automated system
64
+ - an independent verification step after an AI coding agent makes a change
65
+
66
+ The important part is the separation:
67
+
68
+ ```text
69
+ AI coding agent
70
+ |
71
+ | makes a change
72
+ v
73
+ CheckChange
74
+ |
75
+ | produces evidence
76
+ v
77
+ Human / CI / downstream system
78
+ |
79
+ v
80
+ decision
81
+ ```
82
+
83
+ The system that made the change does not get to decide whether the evidence is sufficient.
84
+
85
+ ---
86
+
87
+ ## What CheckChange is not
88
+
89
+ CheckChange does **not** claim to:
90
+
91
+ - prove that code is correct
92
+ - predict defects
93
+ - replace human code review
94
+ - replace testing
95
+ - certify production readiness
96
+ - provide a universal software-quality score
97
+
98
+ A `PASS` means the available evidence satisfied the applicable deterministic rules.
99
+
100
+ A `WARN` means the evidence crossed a condition worth investigating.
101
+
102
+ An `INCOMPLETE` or `NOT_EVALUATED` result means CheckChange could not establish everything needed for a meaningful evaluation.
103
+
104
+ Those are evidence states, not judgments about whether the software is ultimately good or bad.
105
+
106
+ ---
107
+
108
+ # Install
109
+
110
+ The package is published on npm as `checkchange`.
111
+
112
+ Current registry version: **0.4.1**
113
+
114
+ ### npm
10
115
 
11
116
  ```bash
117
+ npm install -g checkchange
118
+ checkchange --help
119
+ ```
120
+
121
+ Or use it without installing globally:
122
+
123
+ ```bash
124
+ npx checkchange check --base main --json
125
+ ```
126
+
127
+ ### pnpm
128
+
129
+ ```bash
130
+ pnpm add -g checkchange
131
+ ```
132
+
133
+ Or:
134
+
135
+ ```bash
136
+ pnpm dlx checkchange check --base main --json
137
+ ```
138
+
139
+ ### From source
140
+
141
+ ```bash
142
+ git clone https://github.com/victor-petropoulos/CheckChange.git
143
+ cd CheckChange
144
+
12
145
  corepack enable
13
146
  pnpm install --frozen-lockfile
14
147
  pnpm run build
148
+
149
+ node dist/cli.js check --base main --json
15
150
  ```
16
151
 
152
+ ---
153
+
154
+ # Requirements
155
+
156
+ - Node **24**
157
+ - pnpm **11.17.0**
158
+ - Git
159
+
160
+ The repository includes an `.nvmrc` and the required pnpm version is specified in `package.json`.
161
+
162
+ For repositories using the Python analysis path, Python 3 plus the relevant testing/coverage tooling may also be required.
163
+
164
+ ---
165
+
166
+ # Quickstart
167
+
168
+ If you are working from a source checkout:
169
+
17
170
  ```bash
18
- # after npm publish only:
19
- npm install -g checkchange
171
+ pnpm install
172
+ pnpm run build
173
+ ```
174
+
175
+ Then run:
176
+
177
+ ```bash
178
+ node dist/cli.js check --base main --json
20
179
  ```
21
180
 
22
- > **Warning:** Git URL install is not supported. `prepare` runs `pnpm run build` (needs pnpm + TypeScript toolchain). The npm registry tarball ships prebuilt `dist/cli.js`; from-source always builds.
181
+ If CheckChange is installed globally:
182
+
183
+ ```bash
184
+ checkchange check --base main --json
185
+ ```
23
186
 
24
- ## Quickstart (<30s)
187
+ You can also run the project's own test suite with:
25
188
 
26
189
  ```bash
27
190
  pnpm exec vitest run --coverage
28
191
  ```
29
192
 
30
- ```text
31
- Test Files 122 passed (122)
32
- Tests 872 passed (872)
193
+ ---
194
+
195
+ # Basic usage
33
196
 
34
- % Coverage report from v8
35
- All files | 86.47 | 78.74 | 90.16 | 88.42 |
197
+ The three most common starting points are:
198
+
199
+ ```bash
200
+ checkchange check --base main --json
36
201
  ```
37
202
 
203
+ Analyze the changes relative to `main` and produce machine-readable evidence.
204
+
38
205
  ```bash
39
- node dist/cli.js check --base main --json
206
+ checkchange check --crap-threshold 25 --format github
207
+ ```
208
+
209
+ Run the analysis with a custom CRAP threshold and GitHub-oriented output.
210
+
211
+ ```bash
212
+ checkchange check --auto-coverage --verbose
213
+ ```
214
+
215
+ Allow CheckChange to detect/configure the appropriate coverage path and show additional diagnostic information.
216
+
217
+ ---
218
+
219
+ # Commands
220
+
221
+ | Command | Purpose |
222
+ |---|---|
223
+ | `check` | Analyze changed functions and produce evidence |
224
+ | `doctor` | Check runtime and repository prerequisites |
225
+ | `prepare-repo` | Detect, plan, approve, install, and verify test/coverage tooling |
226
+ | `explain` | Explain the rationale behind a result |
227
+ | `trace` | Show the evidence trace for a function |
228
+ | `delta` | Compare evidence between two states |
229
+
230
+ Run:
231
+
232
+ ```bash
233
+ checkchange --help
234
+ ```
235
+
236
+ for the current command and option list.
237
+
238
+ ---
239
+
240
+ # Configuration
241
+
242
+ Some of the most useful options are:
243
+
244
+ | Option | Description | Default |
245
+ |---|---|---|
246
+ | `--base <ref>` | Git base reference for the change | auto-detect |
247
+ | `--crap-threshold <n>` | CRAP warning threshold | `30` |
248
+ | `--coverage-file <path>` | Explicit coverage file | auto-detect |
249
+ | `--format <github\|junit\|sarif>` | CI output format | none |
250
+ | `--json` | Produce machine-readable evidence | off |
251
+ | `--verbose` | Show additional diagnostics | off |
252
+ | `--auto-coverage` | Attempt automatic coverage setup | off |
253
+
254
+ The base reference is automatically detected when `--base` is not supplied.
255
+
256
+ Provider configuration can be supplied explicitly or discovered from the repository.
257
+
258
+ ---
259
+
260
+ # Supported languages and coverage
261
+
262
+ The current implementation supports analysis for:
263
+
264
+ - TypeScript
265
+ - JavaScript
266
+ - Python
267
+
268
+ Coverage can be supplied through the supported coverage paths, including Istanbul-compatible coverage and LCOV.
269
+
270
+ CheckChange also supports CI-oriented output formats:
271
+
272
+ ```text
273
+ github
274
+ junit
275
+ sarif
40
276
  ```
41
277
 
278
+ The supported provider/configuration surface is intentionally narrower than "anything that can produce a coverage report." Check the current documentation before assuming a particular repository or coverage setup is supported.
279
+
280
+ ---
281
+
282
+ # How the analysis works
283
+
284
+ The current pipeline is roughly:
285
+
286
+ 1. **Git diff**
287
+ Determine what changed relative to the selected base.
288
+
289
+ 2. **Changed functions**
290
+ Identify the functions affected by the change.
291
+
292
+ 3. **Complexity**
293
+ Measure complexity using the appropriate provider.
294
+
295
+ 4. **Coverage**
296
+ Find available test-coverage evidence.
297
+
298
+ 5. **Attribution**
299
+ Associate coverage evidence with the changed functions.
300
+
301
+ 6. **CRAP calculation**
302
+ Combine complexity and coverage into the deterministic CRAP signal.
303
+
304
+ 7. **Rules**
305
+ Apply the project's deterministic rules and thresholds.
306
+
307
+ 8. **Evidence**
308
+ Produce the structured evidence result.
309
+
310
+ 9. **Output**
311
+ Present the result for a developer, CI system, or another machine.
312
+
313
+ The evidence output includes information about completeness and provenance so that a number is not presented without context.
314
+
315
+ ---
316
+
317
+ # Example
318
+
319
+ A typical machine-readable result looks roughly like:
320
+
42
321
  ```json
43
322
  {
44
323
  "schemaVersion": "0.5",
45
324
  "analysis": {
46
- "base": "2ca94cddb9c2f91a1a56cd6e065d34f4ca1c8de0",
325
+ "base": "<resolved-base-sha>",
47
326
  "target": "current"
48
327
  },
49
- "capabilities": {
50
- "git": "available",
51
- "complexity": "unavailable",
52
- "coverageArtifact": "unavailable"
53
- },
54
328
  "changedFunctions": [],
55
329
  "ruleResults": [],
56
330
  "policy": {
@@ -62,89 +336,195 @@ node dist/cli.js check --base main --json
62
336
  }
63
337
  ```
64
338
 
65
- `diagnostics.lineage` and `diagnostics.quality` follow; omitted above for brevity. A clean
66
- checkout has no changed functions, so `changedFunctions` is empty and the gate is not evaluated.
339
+ The exact output depends on the repository and evidence available.
340
+
341
+ For example, a clean checkout may have no changed functions. In that case there is nothing to evaluate and `NOT_EVALUATED` is a valid result.
342
+
343
+ You can use:
67
344
 
68
345
  ```bash
69
- node dist/cli.js doctor
346
+ checkchange doctor
70
347
  ```
71
348
 
349
+ to see why a repository is or is not ready for analysis.
350
+
351
+ Example:
352
+
72
353
  ```text
73
354
  gitExecutable: ok
74
355
  gitRepo: ok
75
356
  defaultBase: ok (origin/main)
357
+
76
358
  providerAvailability: no-changed-files
77
- ↳ no changed files detected against the base — stage a change and re-run (`git status` / `git diff --stat`). An empty diff is a valid stop: there is nothing to assess.
359
+ ↳ no changed files detected against the base
360
+
78
361
  coverageArtifact: present
79
362
  ```
80
363
 
81
- ## Usage
364
+ ---
82
365
 
83
- Three canonical examples (verbatim from `src/help.ts:75-77`):
366
+ # Why the evidence matters
367
+
368
+ One of the design goals of CheckChange is to distinguish **"we measured it"** from **"we don't have enough evidence."**
369
+
370
+ For example:
371
+
372
+ ```text
373
+ Coverage: 72%
374
+ ```
375
+
376
+ is less useful than:
377
+
378
+ ```text
379
+ Coverage: 72%
380
+ Evidence: ATTRIBUTED
381
+ Provider: LCOV
382
+ ```
383
+
384
+ And that is still different from:
385
+
386
+ ```text
387
+ Coverage: unavailable
388
+ Completeness: INCOMPLETE
389
+ ```
390
+
391
+ The goal is to make those distinctions visible rather than hide them behind a single score.
392
+
393
+ ---
394
+
395
+ # Deterministic by design
396
+
397
+ The core evidence pipeline does not use an LLM to decide whether a change looks risky.
398
+
399
+ Given the same relevant inputs and CheckChange version, the goal is reproducible evidence.
400
+
401
+ That makes the output suitable for:
402
+
403
+ - CI
404
+ - automated workflows
405
+ - comparison between runs
406
+ - downstream AI systems
407
+ - human review
408
+
409
+ An AI system can consume the evidence if that's useful. CheckChange itself does not need to become another AI reviewer.
410
+
411
+ ---
412
+
413
+ # CI
414
+
415
+ CheckChange can produce output intended for CI systems, including:
84
416
 
85
417
  ```bash
86
- checkchange check --base main --json
418
+ checkchange check --format github
87
419
  ```
88
420
 
89
421
  ```bash
90
- checkchange check --crap-threshold 25 --format github
422
+ checkchange check --format junit
91
423
  ```
92
424
 
93
425
  ```bash
94
- checkchange check --auto-coverage --verbose
426
+ checkchange check --format sarif
95
427
  ```
96
428
 
97
- Primary subcommands (`src/cli.ts:17`):
429
+ Machine-readable JSON is also available:
98
430
 
99
- | Command | Purpose |
100
- |---------|---------|
101
- | `check` | Analyze changed functions, emit PASS/WARN/FAIL with evidence |
102
- | `doctor` | Verify runtime prerequisites (Node, pnpm, coverage, git) |
103
- | `prepare-repo` | Bootstrap test runners & coverage tooling (detect → plan → approve → install → verify) |
104
- | `explain` | Show rule rationale for a given verdict |
105
- | `trace` | Print evidence trace for a specific function |
106
- | `delta` | Compare evidence between two refs |
431
+ ```bash
432
+ checkchange check --json
433
+ ```
434
+
435
+ This makes it possible to use the same evidence both for human-facing development workflows and automated pipelines.
436
+
437
+ ---
438
+
439
+ # Dependencies and external tools
440
+
441
+ CheckChange uses a small number of external packages and tools for its analysis.
442
+
443
+ The main runtime requirements are:
444
+
445
+ - Node 24
446
+ - pnpm 11.17.0
447
+ - Git
448
+
449
+ The supported analysis paths also use packages for TypeScript/JavaScript complexity and coverage processing, along with Python tooling where the Python analysis path is used.
107
450
 
108
- Supported languages: TypeScript, JavaScript, Python (`src/cli.ts:22`).
451
+ For the authoritative dependency versions and provider details, see `package.json` and the project documentation.
109
452
 
110
- ## How it works
453
+ ---
111
454
 
112
- Eight-stage pipeline (git → complexity → coverage → attribution → crapCalc → rules → evidence):
455
+ # Development
113
456
 
114
- 1. **Git diff** — enumerate changed functions since `--base` (default: `origin/HEAD` → `main`/`master`)
115
- 2. **Complexity** — per-function CRAP via `crap-typescript` (TS/JS) or `radon` (Python)
116
- 3. **Coverage** — map LCOV/istanbul lines to changed functions (`src/coverage-providers/lcovProvider.ts`)
117
- 4. **Attribution** — case-insensitive suffix match to provider-lowercased paths (`src/attribution.ts:91`)
118
- 5. **crapCalc** — combine complexity + coverage → CRAP score (`src/crapCalc.ts:5`)
119
- 6. **Rules** — INV-01..04 evaluated against thresholds (`src/evidence.ts:828`)
120
- 7. **Evidence** — schema 0.5 (`src/evidence.ts:644`, `src/delta.ts:35`)
121
- 8. **Output** — human-readable summary by default; JSON via `--json`, or `--format github|junit|sarif` for CI annotations
457
+ Install dependencies:
122
458
 
123
- Default CRAP threshold: **30** (`src/help.ts:49`, `src/help.ts:66`).
459
+ ```bash
460
+ pnpm install
461
+ ```
124
462
 
125
- Test suite: **122 test files**, 872 tests (`pnpm exec vitest run --coverage` in a clean clone). Hand-written specs live in `src/` (8) and `test/` (55); the run also picks up compiled `dist/` specs and spike suites.
463
+ Run tests:
126
464
 
127
- ## Configuration
465
+ ```bash
466
+ pnpm test
467
+ ```
468
+
469
+ Run the TypeScript compiler:
470
+
471
+ ```bash
472
+ npx tsc --noEmit
473
+ ```
474
+
475
+ Build:
476
+
477
+ ```bash
478
+ pnpm run build
479
+ ```
128
480
 
129
- Key options (`src/help.ts` for full list):
481
+ Before making changes, check the repository's development documentation and current project status. CheckChange has a fairly deliberate evidence contract, and changes to evidence semantics should not be treated like ordinary refactoring.
130
482
 
131
- | Flag | Description | Default |
132
- |------|-------------|---------|
133
- | `--base <ref>` | Git base ref for diff | auto-detect |
134
- | `--crap-threshold <n>` | CRAP WARN threshold | 30 |
135
- | `--coverage-file <path>` | Explicit LCOV/istanbul path | auto-detect |
136
- | `--format <github\|junit\|sarif>` | Output format; JSON is the `--json` flag | none |
483
+ ---
137
484
 
138
- Provider config precedence: explicit `--provider-config <path>` > repo-root `./checkchange.providers.json` > builtin providers.
485
+ # Contributing
486
+
487
+ Issues and pull requests are welcome.
488
+
489
+ If you want to contribute, please keep the project's core ideas in mind:
490
+
491
+ - evidence should be deterministic where practical
492
+ - provenance should remain visible
493
+ - incomplete evidence should not be disguised as complete evidence
494
+ - technical behavior should be reproducible
495
+ - evidence and interpretation should remain separate
496
+ - new capabilities should be justified by actual use cases
497
+
498
+ The repository contains additional architecture, contract, testing, experiment, and development documentation.
499
+
500
+ ---
501
+
502
+ # Where this is going
503
+
504
+ The immediate goal is not to turn CheckChange into a giant platform.
505
+
506
+ The more interesting question is whether an independent evidence layer becomes genuinely useful as AI-assisted development becomes more common.
507
+
508
+ The basic model is:
509
+
510
+ ```text
511
+ AI writes
512
+ ↓
513
+ CheckChange checks the change
514
+ ↓
515
+ Evidence
516
+ ↓
517
+ Human / CI / another system decides what to do
518
+ ```
139
519
 
140
- ## Contributing
520
+ If that turns out to be useful, there is plenty more we can build around it.
141
521
 
142
- Contributions via GitHub issues and pull requests.
522
+ ---
143
523
 
144
- ## License
524
+ # License
145
525
 
146
- MIT — see [LICENSE](LICENSE:1-3).
526
+ MIT — see [`LICENSE`](LICENSE).
147
527
 
148
- ## Changelog
528
+ # Changelog
149
529
 
150
- See [CHANGELOG.md](CHANGELOG.md).
530
+ See [`CHANGELOG.md`](CHANGELOG.md).
@@ -1,5 +1,5 @@
1
1
  export declare const crapCalcProvenance: {
2
2
  readonly tool: "checkchange";
3
- readonly version: "0.4.0";
3
+ readonly version: "0.4.2";
4
4
  };
5
5
  export declare function calculateCrap(cc: number, coveragePercent: number | null): number | null;
package/dist/crapCalc.js CHANGED
@@ -1,6 +1,6 @@
1
1
  // Provenance for the crapCalc lineage stage. Self tool version tracks package.json
2
2
  // (matches existing hard-coded '0.5.0' style for the core package).
3
- export const crapCalcProvenance = { tool: 'checkchange', version: '0.4.0' };
3
+ export const crapCalcProvenance = { tool: 'checkchange', version: '0.4.2' };
4
4
  export function calculateCrap(cc, coveragePercent) {
5
5
  if (coveragePercent == null) {
6
6
  return null;
@@ -31,7 +31,7 @@ export interface DiagnosticLineageEntry {
31
31
  }
32
32
  export declare const evidenceProvenance: {
33
33
  readonly tool: "checkchange";
34
- readonly version: "0.4.0";
34
+ readonly version: "0.4.2";
35
35
  };
36
36
  export interface EvidenceOutput {
37
37
  schemaVersion: string;
package/dist/evidence.js CHANGED
@@ -19,7 +19,7 @@ import * as path from 'path';
19
19
  import { loadProviderConfig, deriveRegistry, builtinConfig, createGenericCommandProvider } from './providers/index.js';
20
20
  const requireFromEvidence = createRequire(import.meta.url);
21
21
  // Self provenance; version mirrors package.json (existing codebase style hard-codes '0.5.0').
22
- export const evidenceProvenance = { tool: 'checkchange', version: '0.4.0' };
22
+ export const evidenceProvenance = { tool: 'checkchange', version: '0.4.2' };
23
23
  function sha256Hex(content) {
24
24
  return createHash('sha256').update(content).digest('hex');
25
25
  }
@@ -21,7 +21,6 @@ export interface ProviderEntry {
21
21
  export interface ProviderConfig {
22
22
  version: number;
23
23
  providers: ProviderEntry[];
24
- allowlist?: string[];
25
24
  }
26
25
  export interface ResolvedProvider {
27
26
  language: string;
@@ -47,11 +47,9 @@ export function builtinConfig() {
47
47
  language: 'python',
48
48
  extensions: PY_EXTENSIONS,
49
49
  coverageFiles: ['.coverage', 'coverage.xml', 'coverage.json', 'coverage/coverage-final.json'],
50
- coverageCmd: 'coverage json -o {out}',
51
50
  testRunners: [PYTEST_RUNNER],
52
51
  },
53
52
  ],
54
- allowlist: ['./checkchange.providers.json', './.checkchange/providers.json'],
55
53
  };
56
54
  }
57
55
  // ---- Config loading ----
@@ -82,6 +80,24 @@ function validateInstallField(install, i, j) {
82
80
  if (!Array.isArray(install.packages))
83
81
  throw new Error(`config: providers[${i}].testRunners[${j}].install.packages must be an array`);
84
82
  }
83
+ // BEHAVIOR CHANGE: providers[].coverageCmd moves from silently-ignored to REJECTED at load.
84
+ // It was declared (ProviderEntry.coverageCmd) and mapped (deriveRegistry) but never executed —
85
+ // nothing in src/ spawns it. Exact error text:
86
+ // config: providers[<i>].coverageCmd not supported (never executed); remove the key
87
+ // Option (a) taken: reject at validateConfig (the schema choke point for both file-based load
88
+ // paths, :166 + :187) and strip builtinConfig's own copy, since the builtin path :189 bypasses
89
+ // validateConfig. deriveRegistry stays a pure mapper. Any present value rejects, including an
90
+ // explicit `coverageCmd: null` — the operator wrote the key, so tell them to delete it rather
91
+ // than silently accept a field the tool ignores.
92
+ // Migration: delete coverageCmd from checkchange.providers.json / .checkchange/providers.json.
93
+ // The same change removed the dead `allowlist` field (zero readers; it duplicated
94
+ // REPO_ROOT_NAMES below). JSON configs carrying it still load unchanged, so no migration.
95
+ // ponytail: own function to match validateTestRunner/validateInstallField above.
96
+ function rejectCoverageCmd(entry, i) {
97
+ if (entry.coverageCmd !== undefined) {
98
+ throw new Error(`config: providers[${i}].coverageCmd not supported (never executed); remove the key`);
99
+ }
100
+ }
85
101
  function validateConfig(raw) {
86
102
  if (!isRecord(raw))
87
103
  throw new Error('config: not an object');
@@ -96,6 +112,7 @@ function validateConfig(raw) {
96
112
  throw new Error(`config: providers[${i}].language missing`);
97
113
  if (!Array.isArray(entry.extensions))
98
114
  throw new Error(`config: providers[${i}].extensions missing`);
115
+ rejectCoverageCmd(entry, i);
99
116
  if (entry.testRunners !== undefined) {
100
117
  if (!Array.isArray(entry.testRunners))
101
118
  throw new Error(`config: providers[${i}].testRunners not an array`);
@@ -98,8 +98,10 @@ export declare function executeInstallPlan(plan: InstallPlan[], options: Prepare
98
98
  * Flush config pins (provider install specs) to disk after a successful install.
99
99
  * Reads the existing config file (JSON.parse if present, else empty {}), merges
100
100
  * pin provider entries by language → testRunner name (updating `install` on match,
101
- * appending otherwise), and writes atomically via tmp file + rename.
102
- * Returns the config-file keys that were written.
101
+ * appending otherwise), and writes atomically via a pid-suffixed tmp file created
102
+ * with O_EXCL + rename, after a realpath containment check against cwd (the sync
103
+ * mirror of the hardened pattern in src/cache.ts writeEntry()). Returns the
104
+ * config-file keys that were written.
103
105
  */
104
106
  export declare function flushConfigUpdates(plan: InstallPlan[], cwd: string): string[];
105
107
  /** Per self-analyzer probe result. */
@@ -330,12 +330,45 @@ export async function executeInstallPlan(plan, options) {
330
330
  ok: !actions.some((r) => r.status === 'failed'),
331
331
  };
332
332
  }
333
+ /**
334
+ * Containment guard, sync mirror of cache.ts isWithin(): the candidate must
335
+ * realpath inside root. Best-effort, not a proof — the realpath arm and the
336
+ * write that follows are separate operations, so a swap between them is not
337
+ * covered. The lexical fallback is what keeps the check usable BEFORE the
338
+ * config file exists (first flush into a fresh repo).
339
+ */
340
+ function resolvesWithin(candidate, root) {
341
+ let realCandidate = candidate;
342
+ let realRoot = root;
343
+ try {
344
+ realCandidate = fs.realpathSync(candidate);
345
+ realRoot = fs.realpathSync(root);
346
+ }
347
+ catch {
348
+ // one of the two does not resolve yet — fall back to the lexical check
349
+ }
350
+ const rel = path.relative(realRoot, realCandidate);
351
+ return !rel.startsWith('..') && !path.isAbsolute(rel);
352
+ }
353
+ /** Unlink that never throws. unlink does not follow symlinks, so this frees a
354
+ * tmp slot without ever touching a link target. A stale tmp costs one skipped
355
+ * write, never a crash. */
356
+ function unlinkQuiet(p) {
357
+ try {
358
+ fs.unlinkSync(p);
359
+ }
360
+ catch {
361
+ // best effort
362
+ }
363
+ }
333
364
  /**
334
365
  * Flush config pins (provider install specs) to disk after a successful install.
335
366
  * Reads the existing config file (JSON.parse if present, else empty {}), merges
336
367
  * pin provider entries by language → testRunner name (updating `install` on match,
337
- * appending otherwise), and writes atomically via tmp file + rename.
338
- * Returns the config-file keys that were written.
368
+ * appending otherwise), and writes atomically via a pid-suffixed tmp file created
369
+ * with O_EXCL + rename, after a realpath containment check against cwd (the sync
370
+ * mirror of the hardened pattern in src/cache.ts writeEntry()). Returns the
371
+ * config-file keys that were written.
339
372
  */
340
373
  export function flushConfigUpdates(plan, cwd) {
341
374
  const written = new Set();
@@ -350,6 +383,10 @@ export function flushConfigUpdates(plan, cwd) {
350
383
  if (!pinProviders?.length)
351
384
  continue;
352
385
  const configPath = path.resolve(cwd, configKey);
386
+ // Containment BEFORE any I/O: a symlink holding configPath (or a swapped
387
+ // cwd) would otherwise be read through and then clobbered by the rename.
388
+ if (!resolvesWithin(configPath, cwd))
389
+ continue;
353
390
  let existing;
354
391
  try {
355
392
  existing = JSON.parse(fs.readFileSync(configPath, 'utf8'));
@@ -381,9 +418,31 @@ export function flushConfigUpdates(plan, cwd) {
381
418
  existingProviders.push(pinProvider);
382
419
  }
383
420
  }
384
- const tmpPath = `${configPath}.tmp`;
385
- fs.writeFileSync(tmpPath, JSON.stringify(existing, null, 2));
386
- fs.renameSync(tmpPath, configPath);
421
+ // Atomic write. The tmp name is pid-suffixed so concurrent flushes do not
422
+ // share a slot, and `flag: 'wx'` (O_EXCL) makes the create fail EEXIST
423
+ // rather than write THROUGH anything already holding that name — a planted
424
+ // symlink's target is therefore never modified. On any failure the name is
425
+ // unlinked so a later flush retries on a clean slot, the key is left out of
426
+ // `written`, and a console.warn names the failure — an absent JSON entry alone
427
+ // was not enough, since the human path prints nothing about the config write.
428
+ const tmpPath = `${configPath}.tmp.${process.pid}`;
429
+ try {
430
+ fs.writeFileSync(tmpPath, JSON.stringify(existing, null, 2), { flag: 'wx' });
431
+ // Re-check both endpoints after the write, before the rename overwrites.
432
+ if (!resolvesWithin(tmpPath, cwd) || !resolvesWithin(configPath, cwd)) {
433
+ unlinkQuiet(tmpPath);
434
+ continue;
435
+ }
436
+ fs.renameSync(tmpPath, configPath);
437
+ }
438
+ catch (err) {
439
+ unlinkQuiet(tmpPath);
440
+ // Never silent: the caller derives its exit code from install.ok alone,
441
+ // so a swallowed failure here would leave the operator believing the
442
+ // provider pin was recorded when it was not.
443
+ console.warn(`prepare-repo: could not write ${configKey} via ${tmpPath}: ${err instanceof Error ? err.message : String(err)}`);
444
+ continue;
445
+ }
387
446
  written.add(configKey);
388
447
  }
389
448
  }
package/dist/rules.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { ChangedFunction } from './evidence.js';
2
2
  export declare const rulesProvenance: {
3
3
  readonly tool: "checkchange";
4
- readonly version: "0.4.0";
4
+ readonly version: "0.4.2";
5
5
  };
6
6
  export interface RuleResult {
7
7
  ruleId: string;
package/dist/rules.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // Provenance for the rules lineage stage. Self tool version tracks package.json.
2
- export const rulesProvenance = { tool: 'checkchange', version: '0.4.0' };
2
+ export const rulesProvenance = { tool: 'checkchange', version: '0.4.2' };
3
3
  /**
4
4
  * Evaluate changed functions against the high-CRAP rule.
5
5
  * @param changed Array of changed functions
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "checkchange",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
4
4
  "license": "MIT",
5
5
  "packageManager": "pnpm@11.17.0",
6
6
  "type": "module",