@blundergoat/gruff-ts 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. package/CHANGELOG.md +82 -0
  2. package/CONTRIBUTING.md +32 -25
  3. package/README.md +49 -50
  4. package/SECURITY.md +18 -31
  5. package/UPGRADING.md +101 -0
  6. package/bin/gruff-ts +3 -0
  7. package/docs/README.md +11 -10
  8. package/docs/agent-hook.md +32 -35
  9. package/docs/ci-integration.md +38 -24
  10. package/docs/configuration.md +160 -89
  11. package/docs/dashboard.md +12 -13
  12. package/docs/output-formats.md +100 -25
  13. package/docs/philosophy.md +2 -2
  14. package/docs/reports-and-ci.md +14 -172
  15. package/docs/rules.md +126 -98
  16. package/package.json +10 -8
  17. package/src/analyser.ts +817 -323
  18. package/src/baseline-file.ts +867 -0
  19. package/src/baseline-identity.ts +463 -0
  20. package/src/baseline-options.ts +139 -34
  21. package/src/baseline.ts +62 -68
  22. package/src/blocks.ts +512 -336
  23. package/src/changed-regions.ts +380 -79
  24. package/src/check-ignore.ts +28 -13
  25. package/src/class-rules.ts +445 -436
  26. package/src/cli-program.ts +915 -172
  27. package/src/cli.ts +9 -3
  28. package/src/comment-rules.ts +236 -418
  29. package/src/comment-scanner.ts +339 -47
  30. package/src/complexity-metrics.ts +111 -35
  31. package/src/config-load-error.ts +17 -8
  32. package/src/config-parse.ts +291 -98
  33. package/src/config-preservation.ts +81 -26
  34. package/src/config.ts +751 -223
  35. package/src/constants.ts +7 -6
  36. package/src/context-doc-rules.ts +182 -54
  37. package/src/dashboard.ts +88 -23
  38. package/src/dead-code-rules.ts +153 -74
  39. package/src/discovery.ts +493 -140
  40. package/src/doc-rules.ts +602 -126
  41. package/src/duplicate-test-group-rules.ts +359 -0
  42. package/src/findings-helpers.ts +134 -109
  43. package/src/findings.ts +47 -27
  44. package/src/fixture-purpose-rules.ts +194 -50
  45. package/src/github-actions-event-guards.ts +331 -0
  46. package/src/github-actions-rules.ts +328 -121
  47. package/src/hook-contract.ts +681 -255
  48. package/src/init-config.ts +163 -118
  49. package/src/inline-suppressions.ts +340 -0
  50. package/src/limit-band.ts +56 -0
  51. package/src/line-rules.ts +331 -468
  52. package/src/migrate-config.ts +670 -0
  53. package/src/naming-pushers.ts +32 -127
  54. package/src/parsed-script.ts +868 -314
  55. package/src/pillar-summary.ts +56 -40
  56. package/src/profiles.ts +86 -74
  57. package/src/project-config-rules.ts +324 -140
  58. package/src/project-rules.ts +237 -115
  59. package/src/public-exports.ts +102 -38
  60. package/src/report-html.ts +217 -85
  61. package/src/report-renderers.ts +821 -203
  62. package/src/rule-list.ts +166 -46
  63. package/src/rules.ts +100 -104
  64. package/src/safety-rules.ts +191 -132
  65. package/src/scoring.ts +249 -55
  66. package/src/security-flow-rules.ts +791 -115
  67. package/src/selectors.ts +169 -0
  68. package/src/sensitive-data-rules.ts +460 -387
  69. package/src/sensitive-exclusions.ts +435 -0
  70. package/src/source-text.ts +378 -104
  71. package/src/static-analysis-redundant-rules.ts +298 -41
  72. package/src/test-block-rules.ts +343 -253
  73. package/src/text-scans.ts +62 -11
  74. package/src/types.ts +220 -71
  75. package/tsconfig.json +2 -1
  76. package/src/process-exec-metadata.ts +0 -163
  77. package/src/test-fixtures.ts +0 -671
package/UPGRADING.md ADDED
@@ -0,0 +1,101 @@
1
+ # Upgrading
2
+
3
+ How to move a project between `gruff-ts` releases, what each upgrade changes, and how to roll back if the timing is wrong.
4
+
5
+ ## What stays stable within a minor line (`0.5.x`)
6
+
7
+ - Rule IDs keep their meaning and are never renamed or repurposed mid-line.
8
+ - Config filenames and documented keys stay compatible.
9
+ - Exit codes for `--fail-on` stay fixed.
10
+ - Output schema versions bump only on a minor release.
11
+
12
+ ## What breaks in `0.6.0`
13
+
14
+ `0.6.0` is a coordinated family release: the same contract breaks land across all five gruff ports at once, so a polyglot repo only migrates once.
15
+
16
+ ### Machine contracts and CLI behavior
17
+
18
+ - **Node.js 22.12 or newer is required** - `engines` moves from `>=22` to `>=22.12.0` because the CLI's argument parser, Commander 15, requires it. Update Node.js within the 22 line, or move to 24 or 26.
19
+ - **JSON envelopes move from v2 to v3** - `analyse` and `report --format=json` emit `gruff.analysis.v3`; `summary --format=json` emits `gruff.summary.v3` (the same shape without top-level `findings`, so `--top` affects text output only). Update consumers to gate on `schemaVersion`, read `file` instead of `filePath`, read `score.composite.{score,grade}`, and read `paths.details` instead of `paths.skipped`. See the full mapping in [Output Formats](docs/output-formats.md).
20
+ - **Agent-hook envelope moves to `gruff.hook.v2`** - `contractVersion` bumps and the envelope adds two required keys: `run` (mode, scope, operands, `analysedFiles`, applied baseline) and `suppressions` (audit rows). Exit codes are fixed at `0` (nothing hit a requested gate), `1` (an explicit `--fail-on`, `--fail-on-new`, or `--fail-on-diagnostics` gate tripped), and `2` (the run could not complete). Consumers that read only the keys they need keep working; schema validators must accept the two new keys.
21
+ - **`list-rules --format=json` adopts the family rule shape** - Each rule uses `id` (was `ruleId`), `defaultSeverity` (was `severity`), and a named `thresholds` map (was scalar `threshold`). `list-rules <id> --format=json` publishes the same shape under `rule`. Analysis findings still carry `ruleId`.
22
+ - **`summary` exits `0` by default** - `summary`'s default `--fail-on` moves from `advisory` to `none`. CI jobs that expect `summary` to fail on findings must pass `--fail-on advisory` (or another severity) or set `failOn.summary` in `.gruff-ts.yaml`. Configs generated by an earlier `init` already pin `summary: advisory`.
23
+ - **`report --no-baseline` is removed** - `report` never applied baselines, so `--no-baseline` was a silent no-op and now exits `2`. Remove it from `report` commands; `analyse` and `summary` keep the flag.
24
+ - **Invalid ranges and unusable baselines exit `2`** - An empty (`--changed-ranges=`) or malformed `--changed-ranges` value exits `2` with a `changed-region` diagnostic and no findings instead of silently scanning the whole repo or crashing. Callers computing dynamic ranges should skip the run when the range is empty. Missing, malformed, or 0.5 `--baseline` files exit `2` with a `baseline-error` diagnostic instead of exit `1`.
25
+
26
+ ### Configuration and validation
27
+
28
+ - **Per-command exit gates move from `minimumSeverity:` to `failOn:`** - `minimumSeverity:` is now a single display floor (`advisory`, `warning`, or `error`) that filters printed output without changing scores or exit codes. A 0.5 per-command map under `minimumSeverity:` exits `2` until renamed to `failOn:` (keeping `analyse`, `summary`, and `report`, rejecting `dashboard`).
29
+ - **`allowlists.secretPreviews` and unknown rule keys are rejected** - `allowlists.secretPreviews` is removed because reports use fixed category markers unconditionally. Inside `rules.<id>`, only `enabled`, `severity`, `threshold`, and `options` are accepted; any other key (including `thresholds:`) exits `2`.
30
+ - **Tracking tokens come from config** - Workflow-specific references (ADR numbers, milestone IDs, task paths) no longer count automatically as tracking or rationale. Add regexes under `allowlists.trackingTokens` for `docs.todo-without-tracking`, `modernisation.ts-comment-without-rationale`, and `waste.swallowed-catch`.
31
+ - **`gruff-ts migrate-config` handles 0.5 configs automatically** - Run `gruff-ts migrate-config --config <old> --output <new>` to rename `minimumSeverity:`, strip all retired rules, allowlist keys, `secretPreviews`, and retired `sensitiveExclusions:`, and validate the output before writing.
32
+
33
+ ### Baselines, identities, and SARIF
34
+
35
+ - **Baselines move to `gruff.baseline.v3` with line-free identities** - Each row stores a line-free SHA-256 identity (`symbol#ordinal` or a digit-normalised message) plus an accepted count, so line shifts stop expiring reviews and same-named declarations stay separate. `0.5` baselines fail closed with exit `2`; migrate them with `--migrate-baseline`.
36
+ - **Sensitive-data findings can no longer be baselined** - Baselines record secret counts under `sensitive.counts` without storing rows or paths, and hand-written rows cannot suppress a secret. Replace baselined secrets with reason-bearing entries under `sensitiveExclusions:`.
37
+ - **SARIF `partialFingerprints.gruffFingerprint` switches to the durable identity** - Existing code-scanning alerts close and reopen once on upgrade, then survive ordinary edits. Sensitive-data findings publish no `partialFingerprints` so alerts are not grouped under a durable key.
38
+
39
+ ### Scoring
40
+
41
+ - **Normalized confidence-weighted scoring** - Pillar scores now use `floor + (100 - floor) / (1 + density / densityScale)` over evaluated script files, so repo size no longer drags down grades. Error weight rises from `8` to `12`, advisory weight drops from `1.5` to `1`, and findings weigh by confidence (`0.5` low, `0.75` medium, `1.0` high).
42
+ - **`score.pillars[]` lists every rule-backed pillar and composites can be `null`** - Every pillar now appears with `applicable` and `grade`, and `score.composite.{score,grade}` return `null` (`Composite: n/a (nothing evaluated)`) when zero scripts were evaluated instead of reporting `100` / `A`.
43
+
44
+ ### Rules, defaults, and discovery
45
+
46
+ - **40 low-precision rules are removed (ADR-021)** - Removed after the 0.6.0 precision measurement:
47
+ - Complexity & design: `complexity.cognitive`, `design.deep-relative-import`
48
+ - Documentation: `docs.magic-threshold-without-rationale`, `docs.stale-comment`, `docs.useless-docblock`
49
+ - Modernisation: `modernisation.loose-equality`, `modernisation.nullish-coalescing-candidate`, `modernisation.object-spread-candidate`, `modernisation.optional-chaining-candidate`, `modernisation.public-property`
50
+ - Naming: `naming.acronym-case`, `naming.boolean-prefix`, `naming.generic-function`, `naming.generic-parameter`, `naming.hungarian-notation`, `naming.inconsistent-casing`, `naming.negative-boolean`
51
+ - Security & sensitive data: `security.floating-promise`, `security.github-actions-broad-permissions`, `security.insecure-random`, `security.process-exec`, `security.proto-access`, `security.risky-lifecycle-script`, `sensitive-data.hardcoded-env-value`, `sensitive-data.high-entropy-string`
52
+ - Test quality: `test-quality.conditional-logic`, `test-quality.exception-type-only`, `test-quality.magic-number-assertion`, `test-quality.mock-only-test`, `test-quality.no-assertions`, `test-quality.no-throw-only-test`, `test-quality.only-skip`, `test-quality.sleep-in-test`, `test-quality.snapshot-only-test`
53
+ - Maintainability (`waste.*`): `waste.commented-out-code`, `waste.console-log`, `waste.empty-function`, `waste.redundant-boolean-cast`, `waste.redundant-variable`, `waste.unused-parameter`
54
+ - Their seven allowlist keys are also removed: `acceptedBooleanNames`, `acceptedCasingPairs`, `bannedGenericNames`, `booleanPrefixes`, `hungarianPrefixes`, `knownAcronyms`, `negativeBooleanAllowed`.
55
+ - Any config, `sensitiveExclusions:` entry, or `--include-rule`/`--exclude-rule` flag naming a retired ID exits `2`. Use `gruff-ts migrate-config` to prune old configs automatically, or `gruff-ts init --force` to reset to defaults. Baseline rows for retired rules still load and report as resolved. `docs.missing-why-for-complex-code` keeps a fixed cognitive-complexity trigger of 15, and ESLint `no-console`, `eqeqeq`, and `no-unused-vars` comments no longer suppress anything.
56
+ - **12 rules are off by default (ADR-021)** - `complexity.cyclomatic`, `docs.missing-invariant-doc`, `docs.missing-side-effect-doc`, `security.inner-html`, `security.open-redirect-candidate`, `security.path-traversal-candidate`, `security.unsafe-deserialization`, `sensitive-data.aws-access-key`, `sensitive-data.database-url-password`, `sensitive-data.jwt-token`, `waste.swallowed-catch`, and `waste.useless-return` require `rules.<id>.enabled: true`. Older `init`-generated configs already set `enabled: true` and keep them on; narrowing `--include-rule` to disabled rules exits `2`.
57
+ - **Every `sensitive-data.*` rule defaults to `warning` and detects AWS `ASIA` tokens** - All eight surviving sensitive-data rules move from `error` to `warning` (use `--fail-on=warning` or per-rule `severity: error` to keep failing builds on them), and `sensitive-data.aws-access-key` now reports temporary `ASIA` session keys alongside `AKIA` keys.
58
+ - **Security and sensitive-data rules skip test, fixture, and example paths** - Files under `test`, `tests`, `__tests__`, `spec`, `testdata`, `fixtures`, or `examples` (any case) or named like a test are skipped with counted `source: "built-in"` audit rows. Real secrets or unsafe calls inside those paths are no longer reported.
59
+ - **JSDoc tag rules require `/** ... */` contracts across non-test callables** - File overviews and section dividers no longer count as function docblocks, and `everyCallable` is on by default for `docs.missing-param-tag` and `docs.missing-return-tag`. On non-test source (skipping test files while keeping fixture directories checked), both rules require `/** ... */` blocks with described tags rather than `//` or `/* */` comments, `docs.missing-return-tag` requires described `@returns` on every checked callable including `void` (excluding constructors and setters), `docs.stale-param-tag` covers all non-test `everyCallable` targets (accepting destructured object and dotted-key tags), and undocumented public methods of exported classes report as `docs.missing-exported-function-doc` (`warning`). Set `everyCallable: false` on both rules to keep the earlier export-only scope.
60
+ - **Default discovery follows the family fallback policy** - Non-VCS fallbacks defer to any governing `.gitignore` and match at any depth, committed control metadata stays scannable, explicit file arguments bypass Git and fallback exclusions, VCS internals remain blocked even with `--include-ignored`, and vendored directories, `dist`, and `.min.` files are skipped by default. `cache`, `generated`, `target`, and `tmp` are no longer skipped by default; add them to `paths.ignore` if Git does not already ignore them.
61
+
62
+ ## Upgrade workflow (`0.5.x` -> `0.6.0`)
63
+
64
+ 1. Check which breaks above affect your project. A repo with no committed baseline and no hand-written config is mostly affected by the rule and default changes.
65
+ 2. Upgrade the package:
66
+
67
+ ```bash
68
+ npm install --save-dev @blundergoat/gruff-ts@^0.6
69
+ ```
70
+
71
+ 3. Migrate or regenerate your config (if you have one):
72
+ - Keep surviving overrides: `npx gruff-ts migrate-config --config .gruff-ts.yaml --output .gruff-ts.060.yaml` (use a fresh filename with the same extension; YAML stays YAML and JSON stays JSON), inspect the diff, then replace `.gruff-ts.yaml`.
73
+ - Reset to shipped defaults: `npx gruff-ts init --force` (preserves `paths.ignore`, `failOn:`, and valid `sensitiveExclusions:`).
74
+ 4. Migrate your baseline (if you have one) instead of regenerating it from scratch:
75
+
76
+ ```bash
77
+ npx gruff-ts analyse --migrate-baseline gruff-baseline.json --generate-baseline gruff-baseline.060.json --fail-on=none
78
+ ```
79
+
80
+ This writes a separate file and leaves your `0.5` baseline untouched.
81
+ 5. Run `npx gruff-ts summary . --baseline gruff-baseline.060.json` and compare finding counts against your previous run (passing `--baseline` avoids auto-loading the incompatible `0.5` `gruff-baseline.json`). Once satisfied, back up the `0.5` file if you need a rollback path and move `gruff-baseline.060.json` into `gruff-baseline.json`.
82
+
83
+ ## Limitations
84
+
85
+ - `0.5` baselines cannot be read directly by `0.6.0`; migrate them with `--migrate-baseline` rather than hand-editing.
86
+ - Sensitive-data findings cannot be baselined; move any previously baselined sample secret to a reason-bearing `sensitiveExclusions:` entry.
87
+ - Finding identities change once at `0.6.0`, so reviewed findings look new until baseline migration runs.
88
+
89
+ ## Rolling back
90
+
91
+ If now is not the right time to upgrade, pin the `0.5` line:
92
+
93
+ ```bash
94
+ npm install --save-dev @blundergoat/gruff-ts@~0.5
95
+ ```
96
+
97
+ Keep your original `0.5` config and baseline files - `0.5` still reads them, and `0.6.0`'s migration commands will still convert them when you return.
98
+
99
+ ## Reporting an upgrade regression
100
+
101
+ Open an issue at <https://github.com/blundergoat/gruff-ts/issues> with the versions you moved between, the command you ran, and the finding that changed. Any finding that shifted without a listed break above is a regression, not an upgrade cost.
package/bin/gruff-ts CHANGED
@@ -16,6 +16,9 @@ PACKAGE_DIR="$SCRIPT_DIR/.."
16
16
 
17
17
  if [ -f "$PACKAGE_DIR/node_modules/tsx/dist/loader.mjs" ]; then
18
18
  TSX_LOADER="$PACKAGE_DIR/node_modules/tsx/dist/loader.mjs"
19
+ elif [ -f "$PACKAGE_DIR/../../tsx/dist/loader.mjs" ]; then
20
+ # A scoped install lives at node_modules/@blundergoat/gruff-ts, so npm hoists tsx two levels up, not one.
21
+ TSX_LOADER="$PACKAGE_DIR/../../tsx/dist/loader.mjs"
19
22
  elif [ -f "$PACKAGE_DIR/../tsx/dist/loader.mjs" ]; then
20
23
  TSX_LOADER="$PACKAGE_DIR/../tsx/dist/loader.mjs"
21
24
  else
package/docs/README.md CHANGED
@@ -1,21 +1,22 @@
1
1
  # gruff-ts docs
2
2
 
3
- Use these docs with the top-level README for the stable user-facing surface.
3
+ Reference guides for the `gruff-ts` CLI, configuration, rules, and reports.
4
4
 
5
5
  ## Core Docs
6
6
 
7
- - [Philosophy](philosophy.md) - what gruff-ts optimises for and why it governs AI-generated code for human sign-off.
8
- - [Coding-agent hook](agent-hook.md) - wiring gruff-ts as a forcing function on agent output: changed-region scans, gate levels, and CI.
9
- - [Configuration](configuration.md) - config discovery, schema, allowlists, and rule overrides.
10
- - [Rules](rules.md) - rule IDs, severities, thresholds, and remediation guidance.
7
+ - [Philosophy](philosophy.md) - why `gruff-ts` optimises for the human reviewing AI-generated code.
8
+ - [Coding-agent hook](agent-hook.md) - wiring `gruff-ts` onto agent edits with changed-region scans, gate levels, and CI.
9
+ - [Configuration](configuration.md) - config discovery, schema, profiles, ignore rules, allowlists, and `sensitiveExclusions`.
10
+ - [Rules](rules.md) - the full rule catalogue grouped by pillar, with defaults, thresholds, and confidence evidence.
11
11
  - [Output Formats](output-formats.md) - text, JSON, HTML, Markdown, GitHub annotations, hotspot, and SARIF.
12
- - [CI Integration](ci-integration.md) - GitHub Actions, SARIF upload, baselines, and diff scans.
13
- - [Dashboard](dashboard.md) - local dashboard flags and safety model.
12
+ - [CI Integration](ci-integration.md) - GitHub Actions workflows, SARIF upload, baselines, and diff scans.
13
+ - [Dashboard](dashboard.md) - local browser dashboard options and loopback safety model.
14
+ - [Upgrading](../UPGRADING.md) - `0.6.0` breaking changes, migration commands, and rollback steps.
14
15
 
15
- ## Extra Docs
16
+ ## Maintainer Docs
16
17
 
17
- - [Reports And CI](reports-and-ci.md) - combined reporting and CI details retained for existing links.
18
+ - [Releasing](releasing.md) - maintainer release checklist (excluded from the npm package; also readable on [GitHub](https://github.com/blundergoat/gruff-ts/blob/main/docs/releasing.md)).
18
19
 
19
20
  ## Shared Contract
20
21
 
21
- `gruff-ts` follows the cross-language naming and CLI expectations shared across the gruff family (`gruff-go`, `gruff-php`, `gruff-py`, `gruff-rs`). It keeps its `summary` analysis flags as documented extensions while also supporting the common `--format` and `--top` summary surface.
22
+ `gruff-ts` shares rule naming, JSON schemas, and CLI conventions with the sibling gruff ports (`gruff-go`, `gruff-php`, `gruff-py`, `gruff-rs`). Its `summary` also accepts the analysis flags, such as `--diff` and `--baseline`, as a gruff-ts extension to the shared `--format` and `--top` options.
@@ -1,44 +1,41 @@
1
1
  # Using gruff-ts As A Coding-Agent Hook
2
2
 
3
- gruff-ts is built to govern AI-generated code (see [Philosophy](philosophy.md) for the why). This page is the practical how: wiring it in so it acts as a forcing function on an agent's output, before a human is asked to review.
3
+ `gruff-ts` governs AI-generated code (see [Philosophy](philosophy.md) for the reasoning). This guide shows how to wire it in as a forcing function on an agent's edits before a human reviews the diff.
4
4
 
5
5
  ## The model
6
6
 
7
- A coding agent will rewrite code until the checks pass. gruff-ts turns that into leverage: run it on the agent's change and gate on the result, so the agent has to resolve findings - add the missing doc comment, cut the unverifiable branching, drop the unsafe call, replace the mock-only test - before the change reaches you. What lands is already shaped for sign-off.
7
+ A coding agent will keep iterating until the checks pass. Running `gruff-ts` on the agent's diff turns that loop into leverage: the agent has to resolve findings - add the missing doc comment, simplify tangled branching, drop the unsafe call, replace the tautological test - before handing the change to you.
8
8
 
9
9
  For CI-style gates, `analyse` owns the exit code:
10
10
 
11
- - `0` - no finding met the `--fail-on` level; the change passes.
12
- - `1` - at least one finding met `--fail-on`; the agent must fix and re-run.
13
- - `2` - fatal (bad input, parse or config error); stop and surface it.
11
+ - `0` - no finding met `--fail-on`; the change passes.
12
+ - `1` - at least one finding met `--fail-on`; the agent must fix it and re-run.
13
+ - `2` - fatal error (missing input, parse failure, or bad config); stop and surface it.
14
14
 
15
- For editor or PostToolUse feedback, use the analyser-owned hook contract instead:
15
+ For editor or PostToolUse feedback, use the `hook` subcommand instead:
16
16
 
17
17
  ```bash
18
18
  gruff-ts hook --format json --changed-ranges "12-40,88-90" src/foo.ts
19
19
  gruff-ts hook --capabilities --format json
20
20
  ```
21
21
 
22
- `hook` emits `gruff.hook.v1` JSON with normalized `file`, `scope`, `suppressed.count`,
23
- `ignored.paths`, non-null `remediation`, stable identities, and machine-readable threshold
24
- metadata. Hook mode is advisory: findings exit `0`; config failures are returned in
25
- `config.error` and exit `2`.
26
-
27
- Parse and read diagnostics are file-scoped and reported in-band via the additive
28
- `diagnostics` array (`{ type, message, file, line }`): a full scan carries every
29
- analysed file's diagnostics, a `--diff`/`--since` run carries only diagnostics
30
- from changed target files, and `--changed-ranges` carries every diagnostic of
31
- each requested file (a syntax error breaks parsing of the whole file, so ranges
32
- never filter diagnostics). The default hook exit stays `0` with diagnostics
33
- in-band; pass the explicit consumer request flag `--fail-on-diagnostics` to exit
34
- `2` when relevant diagnostics exist. The capability handshake advertises this via
35
- `supports.diagnostics` and `flags.failOnDiagnostics` - the capability is a
36
- producer advertisement only and never changes behavior by itself. Fatal failures
37
- (analysis could not run at all) keep operational-error exit `2` semantics.
22
+ `hook` outputs `gruff.hook.v2` JSON: a nine-key envelope (`contractVersion`, `analyzer`, `run`, `findings`, `diagnostics`, `suppressed`, `suppressions`, `ignored`, and `config`) with normalized `file` and `scope` per finding, non-null `remediation`, stable identities, and machine-readable threshold metadata.
23
+
24
+ Hook mode is advisory by default (`--fail-on none`): it reports findings and exits `0`. Only an explicit gate flag blocks the edit, so `hook` uses its own exit codes:
25
+
26
+ | Code | Meaning |
27
+ | --- | --- |
28
+ | `0` | Nothing hit a requested gate. The default `--fail-on none` exits `0` regardless of finding severity. |
29
+ | `1` | A published finding met `--fail-on`, a finding was new against the baseline under `--fail-on-new`, or `--fail-on-diagnostics` saw a relevant diagnostic. |
30
+ | `2` | The run could not complete. A config error also populates `config.error`; an unusable baseline or invalid changed range appears as a fatal entry in `diagnostics`. |
31
+
32
+ Pair `--fail-on-new` with `--baseline <path>`. A missing baseline, or an input file that is missing or unreadable, exits `2` with a fatal diagnostic.
33
+
34
+ Parse diagnostics appear in-band in `diagnostics` (`{ type, message, file, line }`). Full scans include diagnostics from every analysed file, `--diff`/`--since` runs include only changed files, and `--changed-ranges` includes every diagnostic for each requested file (a syntax error breaks parsing for the whole file, so line ranges never hide it). By default `hook` still exits `0` when parse diagnostics are present; pass `--fail-on-diagnostics` to exit `1` instead. The capabilities payload advertises this through `supports.diagnostics` and `flags.failOnDiagnostics` (advertisement only - it never changes behavior on its own).
38
35
 
39
36
  ## Scan the change, not the repo
40
37
 
41
- > **Goal:** govern only the code the agent changed, not the whole repo - so the agent resolves findings in its own diff and a clean change is never blocked by pre-existing findings elsewhere.
38
+ > **Goal:** govern only the code the agent changed, so the agent fixes its own diff without getting blocked by unrelated backlog elsewhere in the repo.
42
39
 
43
40
  Gate the agent on what it actually touched:
44
41
 
@@ -59,13 +56,13 @@ npx gruff-ts analyse --changed-ranges "12-40,88-90" src/foo.ts --fail-on=warning
59
56
  git diff | npx gruff-ts analyse --diff - --fail-on=warning
60
57
  ```
61
58
 
62
- Changed-region scans keep only findings attributable to the changed hunk, its enclosing symbol, or a project relationship that includes the requested file, so the agent fixes its own work instead of inheriting the whole backlog. In `hook` mode, whole-file metrics such as `size.file-length` are omitted under changed-region attribution and counted in `suppressed.count`; they return only in full-scan hook output or when `--baseline` / `--diff` shows their stable identity is new. Circular-import findings can appear as project-scope findings when the requested file participates in the SCC; they keep the canonical SCC anchor rather than re-anchoring to the edited file. In `analyse`, use `--changed-scope file` for CI jobs that intentionally want every finding from a touched file.
59
+ Changed-region scans keep only findings tied to the changed hunk, its enclosing symbol, or a project relationship touching the requested file. In `hook` mode, whole-file rules like `size.file-length` stay suppressed under changed-region attribution (counted in `suppressed.count`) and appear only in full scans or when `--baseline` / `--diff` shows their identity is new. Circular-import findings still appear when a requested file joins a strongly connected component (SCC), keeping the canonical SCC anchor rather than moving to the edited file. In `analyse`, pass `--changed-scope file` when a CI job wants every finding from touched files.
63
60
 
64
61
  ## Respect the project's ignore policy
65
62
 
66
- A hook passes the agent's changed files directly, so the project's `paths.ignore` must hold for those explicit paths too - otherwise the agent burns loops "fixing" generated or vendored code the project deliberately excludes. Config `paths.ignore` is authoritative in every invocation (explicit operand, diff, changed-region): a matching path produces no findings and is listed in the report's `paths.skipped` with its `source` and `pattern`. `--include-ignored` opts into git/default ignores only and never overrides `paths.ignore`.
63
+ Hooks pass changed file paths directly, so `paths.ignore` must hold for explicit paths too - otherwise the agent wastes cycles editing generated or vendored files the repo intentionally skips. `paths.ignore` applies in every mode (explicit operands, diffs, and changed regions); skipped files produce no findings and appear in `paths.details` with their `source` and `pattern`. `--include-ignored` opts into Git and default ignores only and never overrides `paths.ignore`.
67
64
 
68
- To pre-filter a changed-file list before scanning, ask gruff which paths it would skip - it shares the same engine as `analyse` and runs no analysis:
65
+ To pre-filter changed files before scanning, use `check-ignore` - it shares the exact same ignore engine as `analyse` and runs no analysis:
69
66
 
70
67
  ```bash
71
68
  # Which of the agent's changed files would gruff skip?
@@ -75,19 +72,19 @@ gruff-ts check-ignore $CHANGED_FILES --format json
75
72
 
76
73
  ## Picking the gate level
77
74
 
78
- `--fail-on` sets the bar the agent must clear. Built-in defaults are `advisory` for `analyse` and `summary`, `none` for `report`; raise or lower per surface:
75
+ `--fail-on` sets the bar the agent must clear. Defaults are `advisory` for `analyse` and `none` for `summary`, `report`, and `hook`:
79
76
 
80
77
  | Level | Use it as the agent gate when |
81
78
  | --- | --- |
82
- | `error` | You only want to block the highest-severity issues (committed secrets, `eval`, disabled TLS). Minimal friction. |
83
- | `warning` | Recommended default. Blocks the security and correctness tier plus the verifiability signals (complexity, missing exported-API docs, weak tests) while leaving advisories as nudges. |
84
- | `advisory` | Strictest. Every finding is friction the agent must clear. Best when you want maximum legibility pressure and can tolerate more agent rework. |
79
+ | `error` | You only want to block the highest-severity issues (`eval`, `new Function`, disabled TLS verification, `javascript:` URLs, remote install scripts, oversized files). Minimal friction, though `sensitive-data.*` findings default to `warning` and will not trip this gate. |
80
+ | `warning` | Recommended default. Blocks security, sensitive-data, correctness, and key verifiability checks (missing exported-API docs, weak tests) while leaving advisories as nudges. |
81
+ | `advisory` | Strictest. Every finding blocks until resolved. Best when you want full legibility pressure and can accept extra agent turns. |
85
82
 
86
- Per-command levels can be pinned in `.gruff-ts.yaml` via the `minimumSeverity:` block (see [Configuration](configuration.md)); precedence is CLI flag > config > built-in default.
83
+ You can pin per-command levels in `.gruff-ts.yaml` under `failOn:` (see [Configuration](configuration.md)); precedence is CLI flag > config > built-in default.
87
84
 
88
85
  ## Fix, do not suppress
89
86
 
90
- Baselines exist for legacy adoption, not agent governance. Suppressing an agent's findings defeats the purpose: the goal is code a human can verify, and a baseline hides exactly the things they would check. Gate the agent on its diff (above) rather than baselining its output; if you must scope a run, scope it by changed region, not by suppression.
87
+ Baselines exist for legacy adoption, not agent governance. Baselining an agent's new output hides the exact signals a human reviewer needs. Scope the hook by changed region (above) instead of suppressing findings.
91
88
 
92
89
  ## In CI
93
90
 
@@ -95,10 +92,10 @@ Baselines exist for legacy adoption, not agent governance. Suppressing an agent'
95
92
  # Annotate the PR and fail the job on warning-or-higher findings
96
93
  npx gruff-ts analyse . --since origin/main --format=github --fail-on=warning
97
94
 
98
- # Security-only gate that ignores any adoption baseline
99
- npx gruff-ts analyse . --no-baseline --fail-on=error
95
+ # Security and secret gate that ignores any adoption baseline
96
+ npx gruff-ts analyse . --no-baseline --include-pillar security,sensitive-data --fail-on=warning
100
97
  ```
101
98
 
102
99
  ## Why the doc-comment pressure is deliberate
103
100
 
104
- The documentation pillar is strict on purpose - a doc comment is expected even on a private one-liner. An agent that states intent, usage, contract, and failure behaviour in prose gives you a second, independent description to check the code against, and a mismatch between the comment and the code is itself a signal the change needs a closer look. Treat documentation findings as part of the verifiability gate, not as optional polish.
101
+ Treat doc findings as part of the verifiability gate, not optional polish: a doc comment gives the reviewer a second statement of intent to check against the code. [Philosophy](philosophy.md) explains why that applies even to a private one-liner.
@@ -1,6 +1,6 @@
1
1
  # CI Integration
2
2
 
3
- gruff-ts is designed to run as a deterministic CI quality gate.
3
+ `gruff-ts` runs cleanly as a deterministic CI quality gate, producing identical findings across repeated runs.
4
4
 
5
5
  ## GitHub Actions
6
6
 
@@ -12,67 +12,81 @@ on: [push, pull_request]
12
12
  jobs:
13
13
  analyse:
14
14
  runs-on: ubuntu-latest
15
+ permissions:
16
+ security-events: write # required by upload-sarif
17
+ actions: read # private repositories only
18
+ contents: read # private repositories only
15
19
  steps:
16
20
  - uses: actions/checkout@v4
17
21
  - uses: actions/setup-node@v4
18
22
  with:
19
23
  node-version: "22"
20
24
  - run: npm ci
21
- - run: ./bin/gruff-ts analyse src --format=sarif --fail-on=none > gruff-ts.sarif
22
- - uses: github/codeql-action/upload-sarif@v3
25
+ - run: npx gruff-ts analyse src --format=sarif --fail-on=none > gruff-ts.sarif
26
+ - uses: github/codeql-action/upload-sarif@v4
23
27
  with:
24
28
  sarif_file: gruff-ts.sarif
25
29
  ```
26
30
 
27
31
  ## Quality Gate
28
32
 
29
- For blocking jobs, choose the lowest severity that should fail the build:
33
+ Pick the lowest severity that should fail the build:
30
34
 
31
35
  ```sh
32
- ./bin/gruff-ts analyse src --fail-on=warning
36
+ npx gruff-ts analyse src --fail-on=warning
33
37
  ```
34
38
 
35
- Use `--fail-on=none` when the job should only publish reports.
39
+ Use `--fail-on=none` when the job should upload reports without failing the build. Because all `sensitive-data.*` rules default to `warning`, use `--fail-on=warning` (not `error`) when you want secret findings to block CI.
36
40
 
37
41
  ## Baselines
38
42
 
39
- Generate an adoption baseline after reviewing current findings:
43
+ Generate an adoption baseline after reviewing existing findings:
40
44
 
41
45
  ```sh
42
- ./bin/gruff-ts analyse src --generate-baseline gruff-baseline.json --fail-on=none
46
+ npx gruff-ts analyse src --generate-baseline gruff-baseline.json --fail-on=none
43
47
  ```
44
48
 
45
- Future scans auto-apply `gruff-baseline.json` when present. Use
46
- `--no-baseline` to audit the full unsuppressed result.
49
+ Future scans pick up `gruff-baseline.json` automatically. Pass `--no-baseline` when you want a full unsuppressed audit.
50
+
51
+ Review a baseline diff before committing it: every row it adds hides findings.
47
52
 
48
53
  ## Diff Scans
49
54
 
50
- TypeScript supports working-tree, staged, unstaged, and base-ref diff scans:
55
+ `gruff-ts` supports working-tree, staged, unstaged, and base-ref diff scans:
51
56
 
52
57
  ```sh
53
- ./bin/gruff-ts analyse src --diff=working-tree --format=github --fail-on=warning
54
- ./bin/gruff-ts analyse src --diff=origin/main --format=json --fail-on=none
58
+ npx gruff-ts analyse src --diff=working-tree --format=github --fail-on=warning
59
+ npx gruff-ts analyse src --diff=origin/main --format=json --fail-on=none
55
60
  ```
56
61
 
62
+ ## Score History
63
+
64
+ Append each run's scores to a JSON file to track the trend:
65
+
66
+ ```sh
67
+ npx gruff-ts analyse . --history-file .gruff-history.json --fail-on=none
68
+ ```
69
+
70
+ History needs a valid full scan. `--diff`, `--diff-base`, `--since`,
71
+ `--changed-ranges`, `--include-rule`, `--exclude-rule`, `--include-pillar`, or
72
+ `--exclude-pillar` makes the run exit `2` before anything is written, and so
73
+ does an invalid baseline or another run-invalidating diagnostic. Display-only
74
+ flags such as `--show-rule` and `--min-severity` are fine. History files are local
75
+ artifacts; commit them only if your project wants trend data in version control.
76
+
57
77
  ## Ignored Paths
58
78
 
59
- Config `paths.ignore` is authoritative in every invocation mode - a matching
60
- path is excluded and produces no findings whether it is reached by a directory
61
- walk, passed explicitly, or touched by a diff. Each excluded path is reported in
62
- `paths.skipped` with its `source` and `pattern`. `--include-ignored` affects
63
- git-ignored and default-ignored paths only; it never overrides `paths.ignore`.
79
+ `paths.ignore` in `.gruff-ts.yaml` applies in every mode: directory walks, explicit file paths, and diff scans. Skipped files appear in `paths.details` with their `source` (`config`, `gitignore`, or `default`), and `config` rows include the matching `pattern`. `--include-ignored` opts into Git-ignored and default-ignored paths only; it never overrides `paths.ignore`.
64
80
 
65
- `check-ignore` answers "would gruff skip this path?" without running a scan,
66
- mirroring `git check-ignore` exit codes (0 = at least one ignored, 1 = none,
67
- 2 = error) - useful in a pre-scan hook step to drop out-of-scope changed files:
81
+ Use `check-ignore` in pre-scan scripts or hooks to see which paths `gruff-ts` would skip without running analysis (exit codes mirror `git check-ignore`: `0` = at least one ignored, `1` = none, `2` = error):
68
82
 
69
83
  ```sh
70
- ./bin/gruff-ts check-ignore src/generated/client.ts src/app.ts --format json
84
+ npx gruff-ts check-ignore src/generated/client.ts src/app.ts --format json
71
85
  ```
72
86
 
73
- ## Check
87
+ ## Contributing Checkout Gate
74
88
 
75
- Run the local TypeScript gate before release:
89
+ When working inside this repository, run the local check suite before opening a PR:
76
90
 
77
91
  ```sh
78
92
  npm run check