@blundergoat/gruff-ts 0.4.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.
- package/CHANGELOG.md +123 -1
- package/CONTRIBUTING.md +32 -25
- package/README.md +55 -46
- package/SECURITY.md +18 -30
- package/UPGRADING.md +101 -0
- package/bin/gruff-ts +3 -0
- package/docs/README.md +11 -13
- package/docs/agent-hook.md +33 -24
- package/docs/ci-integration.md +38 -24
- package/docs/configuration.md +173 -71
- package/docs/dashboard.md +12 -13
- package/docs/output-formats.md +100 -25
- package/docs/philosophy.md +2 -2
- package/docs/reports-and-ci.md +14 -157
- package/docs/rules.md +140 -106
- package/package.json +10 -8
- package/src/analyser.ts +886 -282
- package/src/baseline-file.ts +867 -0
- package/src/baseline-identity.ts +463 -0
- package/src/baseline-options.ts +139 -34
- package/src/baseline.ts +85 -55
- package/src/blocks.ts +579 -364
- package/src/changed-regions.ts +414 -65
- package/src/check-ignore.ts +28 -13
- package/src/class-rules.ts +461 -302
- package/src/cli-program.ts +956 -166
- package/src/cli.ts +9 -2
- package/src/comment-rules.ts +277 -414
- package/src/comment-scanner.ts +363 -44
- package/src/complexity-metrics.ts +320 -0
- package/src/config-load-error.ts +17 -8
- package/src/config-parse.ts +291 -98
- package/src/config-preservation.ts +81 -26
- package/src/config.ts +778 -210
- package/src/constants.ts +7 -6
- package/src/context-doc-rules.ts +188 -61
- package/src/dashboard.ts +88 -23
- package/src/dead-code-rules.ts +153 -74
- package/src/discovery.ts +521 -148
- package/src/doc-rules.ts +592 -147
- package/src/duplicate-test-group-rules.ts +359 -0
- package/src/findings-helpers.ts +240 -89
- package/src/findings.ts +48 -24
- package/src/fixture-purpose-rules.ts +226 -48
- package/src/github-actions-event-guards.ts +331 -0
- package/src/github-actions-rules.ts +336 -106
- package/src/hook-contract.ts +708 -211
- package/src/init-config.ts +169 -114
- package/src/inline-suppressions.ts +340 -0
- package/src/limit-band.ts +56 -0
- package/src/line-rules.ts +331 -419
- package/src/migrate-config.ts +670 -0
- package/src/naming-pushers.ts +33 -107
- package/src/parsed-script.ts +1206 -0
- package/src/pillar-summary.ts +56 -40
- package/src/profiles.ts +97 -71
- package/src/project-config-rules.ts +335 -146
- package/src/project-rules.ts +237 -115
- package/src/public-exports.ts +284 -0
- package/src/report-html.ts +217 -85
- package/src/report-renderers.ts +864 -195
- package/src/rule-list.ts +166 -46
- package/src/rules.ts +100 -104
- package/src/safety-rules.ts +191 -132
- package/src/scoring.ts +255 -52
- package/src/security-flow-rules.ts +930 -109
- package/src/selectors.ts +169 -0
- package/src/sensitive-data-rules.ts +502 -375
- package/src/sensitive-exclusions.ts +435 -0
- package/src/source-text.ts +380 -148
- package/src/static-analysis-redundant-rules.ts +298 -41
- package/src/test-block-rules.ts +422 -228
- package/src/text-scans.ts +67 -9
- package/src/types.ts +222 -71
- package/tsconfig.json +2 -1
- package/src/process-exec-metadata.ts +0 -153
- package/src/test-fixtures.ts +0 -668
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,24 +1,22 @@
|
|
|
1
1
|
# gruff-ts docs
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Reference guides for the `gruff-ts` CLI, configuration, rules, and reports.
|
|
4
4
|
|
|
5
5
|
## Core Docs
|
|
6
6
|
|
|
7
|
-
- [Philosophy](philosophy.md) -
|
|
8
|
-
- [Coding-agent hook](agent-hook.md) - wiring gruff-ts
|
|
9
|
-
- [Configuration](configuration.md) - config discovery, schema, allowlists, and
|
|
10
|
-
- [Rules](rules.md) - rule
|
|
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
|
|
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
|
-
##
|
|
16
|
+
## Maintainer Docs
|
|
16
17
|
|
|
17
|
-
- [
|
|
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
|
-
|
|
22
|
-
[`../../CONTRACT.md`](../../CONTRACT.md). TypeScript keeps `summary` analysis
|
|
23
|
-
flags as documented extensions while also supporting the common `--format` and
|
|
24
|
-
`--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.
|
package/docs/agent-hook.md
CHANGED
|
@@ -1,34 +1,43 @@
|
|
|
1
1
|
# Using gruff-ts As A Coding-Agent Hook
|
|
2
2
|
|
|
3
|
-
gruff-ts
|
|
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
|
|
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
|
|
12
|
-
- `1` - at least one finding met `--fail-on`; the agent must fix and re-run.
|
|
13
|
-
- `2` - fatal (
|
|
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
|
|
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`
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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).
|
|
26
35
|
|
|
27
36
|
## Scan the change, not the repo
|
|
28
37
|
|
|
29
|
-
> **Goal:** govern only the code the agent changed,
|
|
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.
|
|
30
39
|
|
|
31
|
-
Gate the agent on what it actually touched
|
|
40
|
+
Gate the agent on what it actually touched:
|
|
32
41
|
|
|
33
42
|
```bash
|
|
34
43
|
# Uncommitted working-tree changes (typical agent loop)
|
|
@@ -47,13 +56,13 @@ npx gruff-ts analyse --changed-ranges "12-40,88-90" src/foo.ts --fail-on=warning
|
|
|
47
56
|
git diff | npx gruff-ts analyse --diff - --fail-on=warning
|
|
48
57
|
```
|
|
49
58
|
|
|
50
|
-
Changed-region scans keep only findings
|
|
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.
|
|
51
60
|
|
|
52
61
|
## Respect the project's ignore policy
|
|
53
62
|
|
|
54
|
-
|
|
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`.
|
|
55
64
|
|
|
56
|
-
To pre-filter
|
|
65
|
+
To pre-filter changed files before scanning, use `check-ignore` - it shares the exact same ignore engine as `analyse` and runs no analysis:
|
|
57
66
|
|
|
58
67
|
```bash
|
|
59
68
|
# Which of the agent's changed files would gruff skip?
|
|
@@ -63,19 +72,19 @@ gruff-ts check-ignore $CHANGED_FILES --format json
|
|
|
63
72
|
|
|
64
73
|
## Picking the gate level
|
|
65
74
|
|
|
66
|
-
`--fail-on` sets the bar the agent must clear.
|
|
75
|
+
`--fail-on` sets the bar the agent must clear. Defaults are `advisory` for `analyse` and `none` for `summary`, `report`, and `hook`:
|
|
67
76
|
|
|
68
77
|
| Level | Use it as the agent gate when |
|
|
69
78
|
| --- | --- |
|
|
70
|
-
| `error` | You only want to block the highest-severity issues (
|
|
71
|
-
| `warning` | Recommended default. Blocks
|
|
72
|
-
| `advisory` | Strictest. Every finding
|
|
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. |
|
|
73
82
|
|
|
74
|
-
|
|
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.
|
|
75
84
|
|
|
76
85
|
## Fix, do not suppress
|
|
77
86
|
|
|
78
|
-
Baselines exist for legacy adoption, not agent governance.
|
|
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.
|
|
79
88
|
|
|
80
89
|
## In CI
|
|
81
90
|
|
|
@@ -83,10 +92,10 @@ Baselines exist for legacy adoption, not agent governance. Suppressing an agent'
|
|
|
83
92
|
# Annotate the PR and fail the job on warning-or-higher findings
|
|
84
93
|
npx gruff-ts analyse . --since origin/main --format=github --fail-on=warning
|
|
85
94
|
|
|
86
|
-
# Security
|
|
87
|
-
npx gruff-ts analyse . --no-baseline --fail-on=
|
|
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
|
|
88
97
|
```
|
|
89
98
|
|
|
90
99
|
## Why the doc-comment pressure is deliberate
|
|
91
100
|
|
|
92
|
-
|
|
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.
|
package/docs/ci-integration.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# CI Integration
|
|
2
2
|
|
|
3
|
-
gruff-ts
|
|
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:
|
|
22
|
-
- uses: github/codeql-action/upload-sarif@
|
|
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
|
-
|
|
33
|
+
Pick the lowest severity that should fail the build:
|
|
30
34
|
|
|
31
35
|
```sh
|
|
32
|
-
|
|
36
|
+
npx gruff-ts analyse src --fail-on=warning
|
|
33
37
|
```
|
|
34
38
|
|
|
35
|
-
Use `--fail-on=none` when the job should
|
|
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
|
|
43
|
+
Generate an adoption baseline after reviewing existing findings:
|
|
40
44
|
|
|
41
45
|
```sh
|
|
42
|
-
|
|
46
|
+
npx gruff-ts analyse src --generate-baseline gruff-baseline.json --fail-on=none
|
|
43
47
|
```
|
|
44
48
|
|
|
45
|
-
Future scans
|
|
46
|
-
|
|
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
|
-
|
|
55
|
+
`gruff-ts` supports working-tree, staged, unstaged, and base-ref diff scans:
|
|
51
56
|
|
|
52
57
|
```sh
|
|
53
|
-
|
|
54
|
-
|
|
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
|
-
|
|
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`
|
|
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
|
-
|
|
84
|
+
npx gruff-ts check-ignore src/generated/client.ts src/app.ts --format json
|
|
71
85
|
```
|
|
72
86
|
|
|
73
|
-
##
|
|
87
|
+
## Contributing Checkout Gate
|
|
74
88
|
|
|
75
|
-
|
|
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
|