@opendesignai/harness 0.2.0-alpha.0 → 0.4.0-alpha.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 (39) hide show
  1. package/README.md +90 -44
  2. package/dist/THIRD-PARTY-LICENSES.md +63 -0
  3. package/dist/child-env-cPBUueQI.mjs +17 -0
  4. package/dist/cli.mjs +4916 -209
  5. package/dist/config.d.mts +68 -0
  6. package/dist/config.mjs +12 -0
  7. package/dist/eslint-comments.mjs +1679 -4
  8. package/dist/hook.d.mts +19 -0
  9. package/dist/hook.mjs +9843 -0
  10. package/dist/plugin.d.mts +1 -1
  11. package/dist/plugin.mjs +283 -27
  12. package/dist/report.d.mts +40 -0
  13. package/dist/report.mjs +34 -0
  14. package/docs/adopting.md +107 -11
  15. package/docs/agent-setup.md +21 -0
  16. package/docs/agents.md +42 -0
  17. package/docs/comments.md +33 -0
  18. package/docs/decisions/0001-oxlint.md +28 -1
  19. package/docs/decisions/0002-react-compiler-rules.md +39 -0
  20. package/docs/decisions/0004-type-aware-rules.md +43 -0
  21. package/docs/decisions/0005-test-weakening-rules.md +28 -0
  22. package/docs/diagnostics.md +58 -0
  23. package/docs/hooks.md +152 -36
  24. package/docs/ratchet.md +23 -21
  25. package/docs/rules/no-commented-out-code.md +47 -0
  26. package/docs/rules/no-swallowed-catch.md +18 -7
  27. package/docs/size.md +3 -1
  28. package/docs/verify.md +80 -0
  29. package/package.json +30 -6
  30. package/presets/react-compiler.json +2 -1
  31. package/presets/rules/base.json +5 -0
  32. package/presets/strict-types.json +5 -0
  33. package/presets/testing.json +22 -0
  34. package/presets/type-aware.json +69 -0
  35. package/skills/od-feature-intake/SKILL.md +22 -0
  36. package/skills/od-pre-pr-review/SKILL.md +46 -0
  37. package/dist/cli.d.mts +0 -1
  38. package/dist/eslint-comments.d.mts +0 -40
  39. package/dist/paths-DBoYPrGy.mjs +0 -59
package/docs/hooks.md CHANGED
@@ -6,12 +6,64 @@ CI (`harness-gates`) remains the sole merge gate. Agent-side hooks provide immed
6
6
 
7
7
  > **Prerequisite for Claude Code:** Always start Claude Code from the **repository root**. Claude Code reads committed `.claude/settings.json` only from the session's primary startup directory; when started inside a subdirectory, committed hooks and `permissions.deny` do not load at all (verified on Claude Code 2.1.332 in live probe G2). `od-harness` does not generate `.claude/settings.local.json` (`--local` is not implemented).
8
8
 
9
- ## Scope of A4-1a vs A4-1b
10
-
11
- | Layer | Status | Contents |
12
- | -------------------------------------- | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
13
- | **A4-1a (this module, `src/hook/**`)** | Implemented | Zero-dependency POSIX sh lexer/parser/expander, wrapper stripping, protected-path classification (pure string/realpath-relative), 24-row policy matrix and keyword fallback, three-agent stdin normalization and stdout rendering, `defineHook` fail-closed / fail-open wrapper. Zero I/O, zero subprocesses, zero new dependencies. |
14
- | **A4-1b (runtime wiring)** | Planned | `dist/hook.mjs` bundle entry and `exports["./hook"]`, cross-platform launcher with missing-package guard, `.harness/config.json` loading, per-agent repository root resolution, git resolution for bare `git push`, post-edit lint feedback (`overwriteResult` on Antigravity), and Stop verification state machine. |
9
+ ## Runtime and configuration
10
+
11
+ Import `hookCommand(agent, event)` from `@opendesignai/harness/hook` to build a command
12
+ handler for Claude Code (`cc`), Codex (`codex`), or Antigravity (`agy`). Use `pre-bash`
13
+ for shell calls, `pre-edit` for edits, `post-tool` for both, and `session-start` and
14
+ `stop` for their respective events. Antigravity can also use `pre-invocation` to
15
+ deliver feedback when a post-tool payload omits the original result. Claude Code
16
+ uses an argv-based command with `onFailure: "block"` on pre-tool events. Codex and
17
+ Antigravity use a shell command that starts Node. The launcher permits dependency
18
+ installation in a fresh clone and reports load failures separately.
19
+
20
+ | Event | Claude Code timeout / internal deadline | Codex and Antigravity timeout / internal deadline |
21
+ | ---------------------- | --------------------------------------- | ------------------------------------------------- |
22
+ | `pre-bash`, `pre-edit` | 5 s / 4 s | 10 s / 8 s |
23
+ | `stop` | 180 s / 170 s | 180 s / 170 s |
24
+
25
+ The `timeout` field in `.codex/hooks.json` is part of the Codex hook trust hash.
26
+ Changing it after the first release requires users to trust the hook again.
27
+
28
+ The runtime reads `.harness/config.json` at the resolved repository root.
29
+
30
+ ```json
31
+ {
32
+ "hooks": {
33
+ "integrationBranches": ["pilot/mfe"],
34
+ "gateFiles": ["scripts/check-*.mjs"],
35
+ "denyFiles": [".harness/generated/**"],
36
+ "stopCommand": ["pnpm", "run", "check"]
37
+ },
38
+ "verify": {
39
+ "base": "origin/main"
40
+ }
41
+ }
42
+ ```
43
+
44
+ `hooks.stopCommand` is optional. It runs as an executable and argv from the repository
45
+ root. Use exit 0 for success, exit 1 for findings, and exit 2 for an environment
46
+ error. Stop runs the command after a session changes tracked or untracked files,
47
+ including changes the session committed. It compares with the merge base of
48
+ `OD_HARNESS_BASE`, `verify.base`, or `origin/main`, in that order. Hook continuation
49
+ flags and a saved fingerprint prevent repeated blocks for the same findings.
50
+ Stop keeps a combined 64 KiB tail of the check's stdout and stderr for feedback.
51
+
52
+ Claude Code resolves policy from `CLAUDE_PROJECT_DIR` and uses both sets of policy
53
+ patterns in a linked worktree. Codex uses the Git root of the payload's working
54
+ directory. Antigravity prefers the parent of the hook's `.agents` directory and
55
+ warns when it differs from the session's Git root. Static edit targets and shell
56
+ writes also check symlink destinations.
57
+
58
+ After a shell call, the hook compares protected files against the pre-tool
59
+ snapshot. Git configuration snapshots compare security-sensitive settings such
60
+ as aliases, hooks, includes and push configuration. Ordinary updates to branch
61
+ tracking metadata pass without a warning. After an edit, the hook runs the
62
+ local Oxlint with the repository root `.oxlintrc.json` when present and uses the
63
+ bulk baseline and changed lines to identify excess diagnostics. Antigravity
64
+ appends diagnostics and a reminder for each applicable ancestor `AGENTS.md`
65
+ below the repository root, once per directory, to the original tool result. Session state is stored in the user's private
66
+ temporary directory.
15
67
 
16
68
  ## Three-agent capability and verification matrix
17
69
 
@@ -48,7 +100,7 @@ Paths are normalized (POSIX `/` and Windows `\` separators, `.` and `..` resolut
48
100
  - Lint & size baselines: `oxlint-suppressions.json`, `.harness/size-baseline.json`
49
101
  - Generated agent configuration & skills: `.codex/hooks.json`, `.codex/rules/od-harness.rules`, `.agents/hooks.json`, `.agents/rules/od-*.md`, `.agents/skills/od-*/**`, `.claude/skills/od-*/**`
50
102
  - Git internals: `.git/**` (and `.git`)
51
- - Installed harness package: `node_modules/@opendesignai/harness/**` (and nested `**/node_modules/@opendesignai/harness/**`)
103
+ - Installed harness package: `node_modules/@opendesignai/harness/**` (and nested `**/node_modules/@opendesignai/harness/**`), plus the copy in pnpm's virtual store that the `node_modules/@opendesignai/harness` link points to: `node_modules/.pnpm/@opendesignai+harness@*/**`
52
104
  - Optional repository additions: `hooks.denyFiles`
53
105
 
54
106
  ### G-class (edit tools: `ask` on Claude Code, `allow-with-notice` on Codex & Antigravity; shell writes: `deny` on all agents)
@@ -69,44 +121,107 @@ Paths are normalized (POSIX `/` and Windows `\` separators, `.` and `..` resolut
69
121
  - `npm ci`
70
122
  - `pnpm install --frozen-lockfile` / `pnpm i --frozen-lockfile`
71
123
 
124
+ The allowlist does not cover installs that leave out devDependencies (`npm ci --omit=dev`, `pnpm install --frozen-lockfile --prod`): they remove the harness and fall under row 23. The hook reads the effective installation options and exported values. For example, `npm_config_omit=optional npm ci` retains development dependencies. The pnpm `clean` and `purge` built-ins remove `node_modules`. When a package defines a script of the invoked name, the hook checks its body.
125
+
72
126
  ## Complete rule matrix
73
127
 
74
- | Row | Category | Examples | `cc` | `codex` | `agy` |
75
- | --- | ------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------- | ---------------------------- | ---------------------------- |
76
- | 1 | Bypass git hooks | `git commit --no-verify` / `-n` / `-anm`; `git push --no-verify`; `git -c core.hooksPath=…`; `git config core.hooksPath …`; `git --config-env=core.hooksPath=…` | `deny` | `deny` | `deny` |
77
- | 2 | Git config via env | `GIT_CONFIG_COUNT`, `GIT_CONFIG_KEY_<n>`, `GIT_CONFIG_VALUE_<n>`, `GIT_CONFIG_PARAMETERS`, `GIT_CONFIG_GLOBAL`, `GIT_CONFIG_SYSTEM`, `GIT_CONFIG` in any assignment (`X=1 cmd`, `env`, `export`, `declare -x`, `typeset -x`, `set -a`). (`GIT_DIR`/`GIT_WORK_TREE`/`GIT_INDEX_FILE`/`GIT_EXEC_PATH`: `ask` / `deny` / `deny`.) | `deny` | `deny` | `deny` |
78
- | 3 | Non-allowlisted `git -c` | Any key outside `color.*`, `core.pager`, `advice.*`, `user.name`, `user.email`, or any `--config-env` | `deny` | `deny` | `deny` |
79
- | 4 | Push to integration branch | `main`, `master`, `release/*`, `cloud/main`, `hooks.integrationBranches` (default `pilot/mfe`) — any push, force, or delete | `deny` | `deny` | `deny` |
80
- | 5 | Push other `pilot/*` | `git push origin pilot/b3-ts7` | `ask` | `allow-with-notice` | `allow-with-notice` |
81
- | 6 | Force push / delete `pilot/*` | `git push -f origin pilot/b3-ts7`, `+HEAD:pilot/x`, `--delete pilot/x`, `:pilot/x` | `deny` | `deny` | `deny` |
82
- | 7 | Bare `git push` | `git push`, `git push origin`, `git push -u origin HEAD`, `git push origin @` (evaluated against rows 4–6, 8 when A4-1b resolves targets; otherwise unresolved) | `ask` | `allow-with-notice` | `allow-with-notice` |
83
- | 7b | Push all / mirror / tags | `git push --all`, `--branches`, `--mirror`, `--tags`, `--follow-tags` | `deny` | `deny` | `deny` |
84
- | 8 | Force push ordinary branch | `git push -f`, `--force-with-lease`, `+refspec` on feature branch | `ask` | `allow-with-notice` | `allow-with-notice` |
85
- | 9 | Publish & release tags | `npm`/`pnpm`/`yarn` `publish`; `npm dist-tag`/`unpublish`/`deprecate`; push `v*` tag; `git tag -f v1` | `deny` | `deny` | `deny` |
86
- | 10 | Merge or approve PR | `gh pr merge`, `gh pr merge --auto`, `gh pr review --approve` | `ask` | `allow-with-notice` | `deny` |
87
- | 11 | Bypass merge rules | `gh pr merge --admin`, `--bypass*`, `gh api` mutating rulesets or branch protection | `deny` | `deny` | `deny` |
88
- | 12 | `gh api` writes | Sensitive GraphQL mutations (`mergePullRequest`, `enablePullRequestAutoMerge`, `createCommitOnBranch`, `updateRef(s)`, `deleteRef`, `*BranchProtectionRule`, `*Ruleset`, `addPullRequestReview` with `APPROVE`, `dismissPullRequestReview`, `updatePullRequestBranch`) and sensitive REST write endpoints (`rulesets`, `branches/*/protection`, `pulls/*/merge`, `merges`, `git/refs`, `contents/`, `environments`, `actions/(secrets\|variables\|permissions)`, `collaborators`, `hooks`) → `deny`; other GraphQL mutations, unreadable queries (`@file`, `--input -`), or other REST writes → gated | `deny` / `ask` | `deny` / `allow-with-notice` | `deny` / `allow-with-notice` |
89
- | 13 | Trigger workflow | `gh workflow run`, `gh run rerun` | `ask` | `allow-with-notice` | `deny` |
90
- | 14 | Write baselines | `oxlint --suppress*` (including via `npx`, `pnpm exec`, `npm run … --`), `od-harness size --init` | `deny` | `deny` | `deny` |
91
- | 15 | Local irreversible destructive | `git reset --hard`, `git clean -f*`, `git checkout -- .`, `git restore .`, `git stash drop`/`clear`, `git reflog expire`, `git gc --prune=now`, `rm -r` on repo root (`rm -rf .git` also hits D-class `.git` → `deny` across all three agents) | `ask` | `deny` | `deny` |
92
- | 16 | Shell write to D/G files | Redirections (`>`, `>>`, `>\|`, `&>`, `<>`), `tee`, `cp`, `mv` (src & dst), `install`, `ln`, `rm`, `touch`, `truncate`, `dd of=`, `sed -i`, `perl -i`, `git checkout <rev> -- <path>`, `git restore --source`, `curl -o`, `wget -O`, inline scripts (`node -e`, `python -c`, `perl -e`, `ruby -e`, `deno eval`, `bun -e`). Opaque bulk writes covering repo root (`git apply`, `patch`, `unzip`, `tar -x`) → `ask` / `deny` / `deny`. | `deny` | `deny` | `deny` |
93
- | 17 | Edit tool on D-class file | `Edit`, `Write`, `NotebookEdit`, `apply_patch`, `write_file`, `edit_file` targeting D-class | `deny` | `deny` | `deny` |
94
- | 18 | Edit tool on G-class file | Same edit tools targeting G-class (`AGENTS.md` only when managed block is touched) | `ask` | `allow-with-notice` | `allow-with-notice` |
95
- | 19 | Package manager dep mutations | `npm install <pkg>`, `npm i -D`, `npm uninstall`, `npm pkg set`, `pnpm add`/`remove`/`update`, `yarn add`/`remove`/`upgrade` | `ask` | `allow-with-notice` | `allow-with-notice` |
96
- | 20 | Regenerate harness | `od-harness init`, `od-harness agents sync` (without `--check`) | `ask` | `allow-with-notice` | `allow-with-notice` |
97
- | 21 | Pipe to interpreter | `… \| sh`, `… \| bash` when upstream is not static `echo`/`printf` | `deny` | `deny` | `deny` |
98
- | 22 | Opaque / unparseable | Unrecognized syntax, dynamic command name, dynamic `eval`/`bash -c`, depth > 8: deny keyword → `deny`; ask keyword → `cc: ask`, `codex/agy: deny`; neither → allow + log notice | keyword | keyword | keyword |
99
- | 23 | Disable harness itself | `npm uninstall` / `pnpm remove` `@opendesignai/harness` → `deny` (all); `rm -r node_modules` → `ask` / `deny` / `deny` (`rm -rf node_modules/@opendesignai/harness` hits row 16 `deny`) | `deny` / `ask` | `deny` | `deny` |
128
+ | Row | Category | Examples | `cc` | `codex` | `agy` |
129
+ | --- | ------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------- | ---------------------------- | ---------------------------- |
130
+ | 1 | Bypass git hooks | `git commit --no-verify` / `-n` / `-anm` / `-nm wip` (a value-taking letter ends a cluster, so `git commit -m"fix: …"` is not `-n`); `git push --no-verify`; `git -c core.hooksPath=…`; `git config core.hooksPath …`; `git --config-env=core.hooksPath=…`. Subcommand long options match any prefix git accepts (`--no-verif`, `--no-ver`) | `deny` | `deny` | `deny` |
131
+ | 2 | Git config via env | `GIT_CONFIG_COUNT`, `GIT_CONFIG_KEY_<n>`, `GIT_CONFIG_VALUE_<n>`, `GIT_CONFIG_PARAMETERS`, `GIT_CONFIG_GLOBAL`, `GIT_CONFIG_SYSTEM`, `GIT_CONFIG` in any assignment (`X=1 cmd`, `env`, `arch -e`, `export`, `declare -x`, `typeset -x`, `set -a`). (`GIT_DIR`/`GIT_WORK_TREE`/`GIT_INDEX_FILE`/`GIT_EXEC_PATH` and their option forms `git --git-dir`, `--work-tree`, `--exec-path=<dir>`: `ask` / `deny` / `deny`.) | `deny` | `deny` | `deny` |
132
+ | 3 | Non-allowlisted `git -c` | Any key outside `color.*`, `core.pager`, `advice.*`, `user.name`, `user.email`, or any `--config-env` | `deny` | `deny` | `deny` |
133
+ | 4 | Push to integration branch | `main`, `master`, `release/*`, `cloud/main`, `hooks.integrationBranches` (default `pilot/mfe`) — any push, force, or delete; also a refspec whose source is dynamic but whose destination is static (`"$(git rev-parse HEAD):refs/heads/main"`), and a dynamic destination whose static text names `pilot/` or an integration branch. Destinations are read as git matches them: `HEAD:heads/main`, `HEAD:refs/heads/main` and `heads/main` without a colon name `main` (`HEAD:heads-up/x` does not) | `deny` | `deny` | `deny` |
134
+ | 5 | Push other `pilot/*` | `git push origin pilot/b3-ts7` | `ask` | `allow-with-notice` | `allow-with-notice` |
135
+ | 6 | Force push / delete `pilot/*` | `git push -f origin pilot/b3-ts7`, `+HEAD:pilot/x`, `--delete pilot/x` (also `--delet`), `:pilot/x`, and `"$SRC:pilot/x"` (a dynamic source may be empty or `+…`) | `deny` | `deny` | `deny` |
136
+ | 7 | Bare `git push` | `git push`, `git push origin`, `git push -u origin HEAD`, `git push origin @` (evaluated against rows 4–6, 8 when A4-1b resolves targets; otherwise unresolved) | `ask` | `allow-with-notice` | `allow-with-notice` |
137
+ | 7b | Push all / mirror / tags | `git push --all`, `--branches`, `--mirror`, `--tags`, `--follow-tags` and their abbreviations (`--al`, `--m`, `--ta`); `--prune`; wildcard refspecs (`refs/heads/*:refs/heads/*`, `+refs/heads/*:…`, `refs/tags/*:refs/tags/*`) | `deny` | `deny` | `deny` |
138
+ | 8 | Force push ordinary branch | `git push -f`, `--force-with-lease` (also `--force-wi`), `+refspec` on feature branch | `ask` | `allow-with-notice` | `allow-with-notice` |
139
+ | 9 | Publish & release tags | `npm`/`pnpm`/`yarn` `publish`; `npm dist-tag`/`unpublish`/`deprecate`; push `v*` tag (`v1`, `tags/v1`, `refs/tags/v1`, `HEAD:tags/v1`); `git tag -f v1` / `--delet v1`; `gh release create v*` | `deny` | `deny` | `deny` |
140
+ | 10 | Merge or approve PR | `gh pr merge`, `gh pr merge --auto`, `gh pr review --approve` | `ask` | `allow-with-notice` | `deny` |
141
+ | 11 | Bypass merge rules | `gh pr merge --admin` (also `--admin=<anything but false>`), `--bypass*`, `gh api` mutating rulesets or branch protection | `deny` | `deny` | `deny` |
142
+ | 12 | `gh api` writes | Sensitive GraphQL mutations (`mergePullRequest`, `enablePullRequestAutoMerge`, `createCommitOnBranch`, `updateRef(s)`, `deleteRef`, `*BranchProtectionRule`, `*Ruleset`, `addPullRequestReview` with `APPROVE`, `dismissPullRequestReview`, `updatePullRequestBranch`) and sensitive REST write endpoints (`rulesets`, `branches/*/protection`, `pulls/*/merge`, `merges`, `git/refs`, `contents/`, `environments`, `actions/(secrets\|variables\|permissions)`, `collaborators`, `hooks`) → `deny`; other GraphQL mutations, unreadable queries (`@file`, `--input -`), or other REST writes → gated | `deny` / `ask` | `deny` / `allow-with-notice` | `deny` / `allow-with-notice` |
143
+ | 13 | Trigger workflow | `gh workflow run`, `gh run rerun` | `ask` | `allow-with-notice` | `deny` |
144
+ | 14 | Write baselines | `oxlint --suppress*` (including via `npx`, `pnpm exec`, `pnpm <bin>` / `yarn <bin>`, `npm run … --`), `od-harness size --init` | `deny` | `deny` | `deny` |
145
+ | 15 | Local irreversible destructive | `git reset --hard` (also `--har`, `--h`), `git clean -f*` (also `--forc`), `git checkout -- .`, `git restore .`, `git stash drop`/`clear`, `git reflog expire`, `git gc --prune=now` / `--prune=all`, `git prune --expire now`, `rm -r` on repo root or a glob that covers it (`rm -rf *`, `rm -rf .g*`), `find . -delete`. `rm -rf .git` also hits D-class `.git` and is `deny` on all three agents: intentionally stricter than plan row 15 for Claude Code (owner decision on review I6) | `ask` | `deny` | `deny` |
146
+ | 16 | Shell write to D/G files | Redirections (`>`, `>>`, `>\|`, `&>`, `<>`), `tee`, `cp`, `mv` (src & dst), `install`, `ln`, `rm`, `touch`, `truncate`, `dd of=`, `sed -i`, `perl -i`, `rsync`, `ditto`, GNU `g`-prefixed tools (`gsed`, `gcp`, …), `python -m json.tool <in> <out>`, `git checkout <rev> -- <path>`, `git restore --source`, `git rm`, `git mv`, `find -delete` / `find -exec … {}` (with the paths `find` can be shown to match), `curl -o`, `wget -O`, inline scripts that call a file-writing API (`node -e`, `python -c`, `perl -e`, `ruby -e`, `deno eval`, `bun -e`, and here-docs or here-strings fed to these interpreters). Targets with brace expressions are expanded (`touch .github/workflows/{a,b}.yml`, `mv package.json{,.bak}`); targets with an unquoted glob are denied when some protected path matches the glob (`> oxlint-suppressions.jso[n]`, `rm -rf .g*`, `mv *.json /tmp/`). Opaque bulk writes covering repo root (`git apply`, `patch`, `unzip`, `tar -x`) → `ask` / `deny` / `deny`. | `deny` | `deny` | `deny` |
147
+ | 17 | Edit tool on D-class file | `Edit`, `Write`, `MultiEdit`, `NotebookEdit`, `apply_patch`, `write_file`, `edit_file` targeting D-class (whether the agent routes the call to `pre-edit` or `pre-bash`) | `deny` | `deny` | `deny` |
148
+ | 18 | Edit tool on G-class file | Same edit tools targeting G-class (`AGENTS.md` only when managed block is touched) | `ask` | `allow-with-notice` | `allow-with-notice` |
149
+ | 19 | Package manager dep mutations | `npm install <pkg>`, `npm i -D`, `npm uninstall`, `npm pkg set`, `pnpm add`/`remove`/`update`, `yarn add`/`remove`/`upgrade`; npm and pnpm aliases and npm abbreviations count as the command they stand for (`npm add`, `npm isntall`, `pnpm rm`, `npm unpub`) | `ask` | `allow-with-notice` | `allow-with-notice` |
150
+ | 20 | Regenerate harness | `od-harness init`, `od-harness agents sync` (without `--check`) | `ask` | `allow-with-notice` | `allow-with-notice` |
151
+ | 21 | Pipe to interpreter | `… \| sh`, `… \| bash`, `… \| (bash)`, `… \| { sh; }`, `… \| source /dev/stdin`, `bash <(…)`, `source <(…)`, `bash < <(…)` when the program is not the output of a static `echo`/`printf` | `deny` | `deny` | `deny` |
152
+ | 22 | Opaque / unparseable | Unrecognized syntax, dynamic command name, dynamic `eval`/`bash -c`, dynamic `git`/`gh`/package-manager subcommand (`git $(printf push) …`), inline code that starts a process (`os.system`, `child_process`, `subprocess`, backticks), a glob in the command name (`g* push`), a word after a wrapper that its options do not explain (`timeout --unknown 9 …`), depth > 8: deny keyword → `deny`; ask keyword → `cc: ask`, `codex/agy: deny`; neither → allow + log notice. More than 256 nested wrappers → `deny` on all three agents | keyword | keyword | keyword |
153
+ | 23 | Disable harness itself | `npm uninstall` / `pnpm remove` `@opendesignai/harness` → `deny` (all); `rm -r node_modules` or `node_modules/.pnpm`, installs without devDependencies (`npm ci --omit=dev`, `npm install --production`, `pnpm install --prod`/`-P`, `yarn --production`, `NODE_ENV=production npm ci`) and `npm prune` / `pnpm prune --prod` → `ask` / `deny` / `deny`. Also `deny` (all): `npm pkg delete`/`set` on the harness or a whole dependency map (`npm pkg delete devDependencies`) and installs that put another package under the harness name (`npm i @opendesignai/harness@npm:left-pad`, `…@file:…`, `…@link:…`, git and URL specs). Also `ask` / `deny` / `deny`: `npm config set omit dev`, `npm set production=true`, `pnpm config set production true`, writes of `omit=dev`, `production=true` or `only=prod` to an `.npmrc` or `npmrc` file (`echo omit=dev >> .npmrc`, here-docs, `… \| tee -a .npmrc`), and `npm_config_omit=dev` or `NODE_ENV=production` set with `export`, `declare -x` or under `set -a` before an install. `rm -rf node_modules/@opendesignai/harness` and the pnpm store copy `node_modules/.pnpm/@opendesignai+harness@*` hit row 16 `deny` | `deny` / `ask` | `deny` | `deny` |
100
154
 
101
155
  ## Shell parser and opaque fallback
102
156
 
103
157
  `src/hook/shell/` implements a zero-dependency POSIX sh lexer, recursive-descent parser, and static analyzer that classifies commands without executing or evaluating them:
104
158
 
105
159
  - **Lexing & quoting:** single quotes, double quotes, ANSI-C `$'...'` escapes (`\xHH`, `\uHHHH`, `\NNN`, etc.), backslash escapes, comments, redirections (`>`, `>>`, `>|`, `<>`, `&>`, `&>>`, `<<`, `<<-`, `<<<`, `n>&m`), command substitutions `$(...)` and backticks, arithmetic expansions `$((...))`, parameter expansions `${...}`, and process substitutions `<(...)` / `>(...)`.
106
- - **Static resolution & unwrapping:** propagates static variable assignments (`G=git; $G push`), tracks static `cd` with isolated subshell scopes, inspects aliases and function bodies conservatively, recursively unwraps `bash -c`/`sh -c`/`zsh -c`/`eval`, here-docs/here-strings fed to shells, and static `echo`/`printf | sh` up to depth 8.
107
- - **Wrapper stripping:** unwraps `env`, `sudo`, `doas`, `time`, `nice`, `nohup`, `timeout`, `stdbuf`, `command` (skipping read-only `-v`/`-V`), `builtin`, `exec`, `noglob`, `nocorrect`, `xargs`, `find … -exec`/`-execdir`/`-ok`, `watch`, `setsid`, `flock`, `ionice`, `caffeinate`, `npx`, `bunx`, `corepack`, `pnpm exec`/`dlx`/`x`, `npm exec`, and `yarn dlx`/`exec`.
160
+ - **Static resolution & unwrapping:** propagates static variable assignments (`G=git; $G push`), tracks static `cd` with isolated subshell scopes, tracks the exported environment (`export`, `declare -x`, `typeset -x`, `set -a`, `export -n`, `unset`) so later commands see it (`export npm_config_omit=dev; npm ci`), inspects aliases and function bodies conservatively, recursively unwraps `bash -c`/`sh -c`/`zsh -c`/`eval`, here-docs/here-strings fed to shells, and static `echo`/`printf | sh` up to depth 8.
161
+ - **Command names:** compared by basename, lowercase and without `.exe` (`GIT`, `/usr/bin/Git`, `Gh`, `RM` resolve to `git`, `gh`, `rm` on the case-insensitive file systems of macOS and Windows; no Linux system ships an upper-case `GIT`). Homebrew's `g`-prefixed GNU tools (`gsed`, `gcp`, `gmv`, `grm`, `gtee`, …) are read as the plain tool. A command word that contains whitespace (`npx 'git push origin main'`, `"$CMD"`) is parsed as a script.
162
+ - **Long options:** git subcommand options, GNU `env` options and the like match any prefix the tool accepts, because git's parse-options and `getopt_long` take unambiguous abbreviations (`git push --delet`, `--force-wi`, `--al`, `--m`; `git commit --no-verif`; `git reset --har`). A prefix of a dangerous option is read as that option even when the tool would reject it as ambiguous; such a command does not run anyway. git's own global options (`-C`, `--git-dir`, …) take no abbreviations and are matched exactly. In a short-option cluster a value-taking letter ends the cluster, as in git's parse-options: `git commit -nm wip` sets `-n`, while in `git commit -m"fix: …"` and `-Fnotes.txt` the rest of the word is the value.
163
+ - **Package-manager commands:** npm and pnpm subcommands are resolved the way npm 11 and pnpm 12 do before the rules run: aliases (`npm add`, `npm rm`, `npm x`, `npm c`, `pnpm rm`, `pnpm un`, `pnpm i`, `pnpm c`), and for npm the unique prefixes its `abbrev` lookup accepts (`npm unpub`, `npm publ`, `npm unin`, `npm isntall`). A prefix npm itself rejects as ambiguous (`npm p`, `npm d`) is read as the most dangerous command it may stand for (`publish`, `dist-tag`). A direct npm usage query such as `npm dist-tags --help` is read-only. Leading options such as `--before <date>` and `-L <location>` consume their value before subcommand lookup. pnpm takes no abbreviations; `pnpm r` and `pnpm x`, which pnpm 12 rejects, are still read as `remove` and `exec`.
164
+ - **Expansion:** an unquoted variable bound to a static value with whitespace is split into words (`X='git push origin main'; $X`). `sh -c '<script>' a b c` binds `$0`, `$1`, …, `"$@"` inside the script, and `set -- a b c` binds them in the current script. `${VAR:-word}` / `${VAR-word}` with `VAR` unset is also analyzed with its literal default (`git push origin "${BRANCH:-pilot/mfe}"`, `eval "git ${X:-pu}sh origin main"`).
165
+ - **Braces and globs:** brace expressions are expanded statically as bash and zsh do (`{a,b}`, `{1..3}`, `{01..10..2}`, `{a..e}`, nested and adjacent groups) into up to 64 words; past that, the word is read with each brace expression as `*`. A word with an unquoted `*`, `?` or `[...]` is not static, because what it expands to depends on the files present: as a command name it is opaque (row 22); as a write, removal, move or redirection target it is compared with the protected patterns, and denied when some protected path matches both (a `*` here also matches a leading `.`, as under `dotglob`); as a push refspec it is dynamic. A known directory prefix, including the current `$PWD`, participates in the comparison. `packages/*/package.json` does not intersect the root manifest. Benign globs stay allowed (`ls src/*`, `rm -f *.log`, `git add src/*.ts`, `cp -r templates/* .`).
166
+ - **Wrapper stripping:** unwraps `env` (including `-S`/`--split-string` scripts in every spelling: `-S'…'`, `-iS'…'`, `--split-string=…`, and BSD `-P <path>`), `sudo`, `doas`, `time`, `nice`, `nohup`, `timeout`, `stdbuf`, `command` (skipping read-only `-v`/`-V`), `builtin`, `exec`, `noglob`, `nocorrect`, `xargs`, `watch`, `setsid`, `flock`, `ionice`, `caffeinate`, `arch` (including `-e NAME=value`), `npx`, `bunx`, `uvx`, `uv run`, `corepack`, `pnpm exec`/`dlx`/`x` (including shell mode `-c`/`--shell-mode`), `npm exec`/`npm x` (including `-c`), and `yarn dlx`/`exec`. `pnpm <bin>` and `yarn <bin>` (a first argument that is not a pnpm/yarn command, such as `pnpm oxlint --suppress-all`) are analyzed as running that binary as well as the package-manager command. Each wrapper's own options are read the way the tool reads them: short-option clusters with attached or separate values (`nice -n5`, `nice -5`, `timeout -sKILL 5`, `ionice -c3`, `stdbuf -oL`, `sudo -u root -g wheel`, `xargs -n1 -P4`), GNU `xargs -l` with an optional attached line count, long options with `=` or a separate value and their unambiguous prefixes (`nice --adj=5`, `timeout --kill-after 1 5`), and `--`. `sudo -s` / `-i` (and `--shell`, `--login`) without a command run a shell, which reads a here-doc or here-string as its program. After a wrapper, a word that starts with `-` or is all digits and that the wrapper's options do not explain (`timeout --unknown 9 git …`) is skipped, and the whole command also goes through the keyword fallback. Up to 256 nested wrappers are unwrapped; a longer chain is denied as opaque.
167
+ - **Commands run by other commands:** `find … -exec`/`-execdir`/`-ok` subcommands, with `{}` replaced by the paths the expression can be shown to match (each starting point under `-maxdepth 0` or without filtering tests, and `<start>/<name>` for literal `-name` values, literal `-path` values); `find -delete` is analyzed as `rm -rf` of the same paths, so `find . -name '*.log' -delete` stays allowed. `git rebase -x/--exec`, `git bisect run` and `git submodule foreach` commands. `bash --rcfile <file> -c …` and `--init-file`.
168
+ - **Programs fed to a shell:** `-c` scripts; here-docs and here-strings on `sh`/`bash`/… and on `source`/`.` reading `/dev/stdin`; process substitutions `bash <(…)`, `source <(…)`, `bash < <(…)`; pipelines into a shell, `source /dev/stdin`, or a subshell or group whose first command is a shell reading stdin (`… | (bash)`, `… | { sh; }`). A static `echo`/`printf` program is parsed; anything else is row 21.
169
+ - **Inline interpreter code** (`node -e`, `python -c`, `perl -e`, `ruby -e`, `deno eval`, `bun -e`, and here-docs or here-strings fed to `python`, `python -`, `node`, `perl`, `ruby`, `bun`): the code counts as a shell write only when it calls a file-writing API (`writeFile`, `open(…, 'w')`, `write_text`, `os.remove`, `shutil.copy`, `File.write`, `unlink`, `>` modes, …) and names a protected path. Explicit read flags such as Node's `fs.constants.O_RDONLY` and Ruby's `r:UTF-8` are recognized. Perl `sysopen` supplies its path after the handle, and Python `logging.basicConfig` supplies it through `filename`. Code that starts a process (`os.system`, `subprocess`, `child_process`, `exec*`, `spawn*`, backticks, `%x`, `qx`) goes through the keyword fallback, and its string literals, and lists of string literals joined with spaces (`subprocess.run(['git', 'push', 'origin', 'main'])`, `spawnSync('git', ['push', …])`), are parsed as commands.
108
170
  - **Opaque fallback & Windows PowerShell:** commands that cannot be resolved statically (or non-POSIX syntax such as zsh `=(...)` or PowerShell/cmd) fall back to keyword matching (`DENY_KEYWORDS` and `ASK_KEYWORDS`) plus PowerShell destructive/write idioms (`Remove-Item -Recurse … .git`, `Set-Content`, `Out-File`, `Add-Content`). For `eval` with partially dynamic arguments (e.g. `eval "git" $UNSET_VAR "push" origin main`), the analyzer evaluates both the opaque keyword fallback and the static-token projection so obvious protected actions still hit structured rules.
109
- - **Static analysis boundaries:** because `pre-bash` classifies commands without evaluating shell expansions or running interpreters, obfuscations that assemble tokens only at runtime — such as parameter-default word splitting (`eval "git ${X:-pu}sh origin main"`), runtime string concatenation inside inline scripts (`python3 -c "open('.oxlint'+'rc.json','w')"`), or writes performed inside external script files (`node scripts/custom.mjs`) — are inherent boundaries of static pre-execution analysis. Those cases are backstopped by A4-1b's post-execution D-class file hash verification (`PostToolUse` + `Stop`) and ultimately enforced by CI (`harness-gates`).
171
+ - **Dynamic write targets:** when a write target is not static (`> "$OUT"`), the hook looks for a protected path name only in the simple command that writes and in the assignments its variables came from (`F=$(echo .oxlintrc.json); echo x > "$F"`, `for f in .oxlintrc.json …`, `read F <<< …`), not in the rest of the compound command (owner decision on review I5). `cat package.json | jq -r .version > "$OUT"` is allowed; `git diff -- package.json > "$OUT"` is still denied because the writing command names `package.json`.
172
+ - **Static analysis boundaries:** because `pre-bash` classifies commands without evaluating shell expansions or running interpreters, obfuscations that assemble tokens only at runtime — such as runtime string concatenation inside inline scripts (`python3 -c "open('.oxlint'+'rc.json','w')"`, `getattr(os, 'sys' + 'tem')`), commands a nested script reads from an outer here-string (`bash -c 'source /dev/stdin' <<< '…'`), or writes performed inside external script files (`node scripts/custom.mjs`, `source script.sh`) — are inherent boundaries of static pre-execution analysis. The command families the hook deliberately does not chase (other interpreters, constant propagation, file-writing commands it does not model) are listed under [Known limits](#known-limits). Those cases are backstopped by the runtime's post-execution D-class file hash verification (`PostToolUse` + `Stop`) and the server-side controls listed there, and ultimately enforced by CI (`harness-gates`).
173
+
174
+ `git prune` can immediately delete unreachable objects and falls under row 15. Its `--dry-run` and `-n` previews are allowed. For `git clean`, `-e` consumes its exclude pattern even inside a short option cluster.
175
+
176
+ ### Accepted false positives
177
+
178
+ The owner decisions keep these strict readings; each errs toward denying:
179
+
180
+ - A dynamic write target in a command that itself names a protected file (`git diff -- package.json > "$OUT"`): `deny`.
181
+ - Inline code that both calls a file-writing API and mentions a protected path, even when it writes elsewhere (`node -e "fs.writeFileSync('v.txt', require('./package.json').version)"`): `deny`.
182
+ - Inline code that starts a process and contains an ask keyword (`push`, `merge`, `package.json`, …) in any string: `ask` on Claude Code, `deny` on Codex and Antigravity.
183
+ - `git --git-dir=…` / `--work-tree=…` / `--exec-path=…`, even for read-only subcommands: `ask` / `deny` / `deny`.
184
+ - A git option prefix that git itself would reject as ambiguous (`git push --d origin pilot/x`, `git commit --no-v`) is read as the dangerous option.
185
+ - A refspec with a dynamic source and a `pilot/*` destination (`"$SRC:pilot/x"`): `deny`, since the source may be empty (a deletion) or start with `+`.
186
+ - `npm prune` without flags: row 23 (`ask` / `deny` / `deny`).
187
+ - `rm -rf .git` on Claude Code: `deny`, stricter than plan row 15 (`ask`), because `.git` is D-class (owner decision on review I6).
188
+
189
+ ## Known limits
190
+
191
+ The hook stops the common ways of writing a dangerous command. Three families of commands are left to server-side controls instead (owner decision of 12-05 on review round 4): chasing them would mean modeling more languages and runtime state than a pre-execution check can carry. Commands in these families may be allowed by the hook. Their review cases are kept in `test/hook/review-r4.test.ts` as TODO tests, labeled with the family.
192
+
193
+ What backstops them:
194
+
195
+ - **Branch rulesets** on GitHub guard the integration branches, `pilot/*` and the `v*` release tags (pushes, force pushes, deletions, and merges without the required code owner review), whatever command sent them.
196
+ - **npm publish environment approval:** packages are published only by the release workflow through npm trusted publishing in the `npm` environment, and approval on that environment gates each publish.
197
+ - **CI gates (`harness-gates`):** lint and size baselines may only shrink (`od-harness ratchet`), and changes to protected files (gate files, baselines, generated agent configuration, `package.json` and the lockfile) need code owner review ([ADR 0003](decisions/0003-agent-harness.md)).
198
+
199
+ ### Other interpreters and pass-through channels (review I3)
200
+
201
+ Commands run through a language or tool whose programs the analyzer does not parse, or handed to git or `gh` in a setting that runs them later:
202
+
203
+ - `awk 'BEGIN{system("git push origin main")}'`, `tcsh -c 'git push origin main'`, `expect -c 'spawn git push origin main; expect eof'`, `printf 'x:\n\tgit push origin main\n' | make -f - x`, `python3 -c "os.execlp('git','git','push','origin','main')"`.
204
+ - `GIT_EDITOR='git push origin main;:' git commit --allow-empty`, `gh alias set --shell p 'git push origin main' && gh p`, `git send-pack <remote> HEAD:refs/heads/main`.
205
+
206
+ Backstop: branch rulesets (pushes and merges), npm publish environment approval (publishing).
207
+
208
+ ### Constant propagation and argument binding (review I2)
209
+
210
+ Values the analyzer would have to compute, or bind to a command's arguments, before it could see the target:
211
+
212
+ - `B=pilot/mfeX; git push origin "HEAD:${B%X}"` (parameter operators other than defaults), `read -r b <<< pilot/mfe; git push origin "HEAD:$b"`, `IFS=,; X='git,push,origin,main'; $X`.
213
+ - `f() { git push origin "HEAD:$1"; }; f main` (function arguments), `echo main | xargs -I{} git push origin HEAD:{}` (words `xargs` reads from stdin).
214
+
215
+ Backstop: branch rulesets.
216
+
217
+ ### File-writing commands the hook does not model (review I4)
218
+
219
+ Commands that write files through an option, a program or stdin that the row 16 list does not cover:
220
+
221
+ - `sort -o .oxlintrc.json /tmp/new.json`, `uniq /tmp/new.json oxlint-suppressions.json`, `ex -sc '%s/error/off/|x' .oxlintrc.json`, BSD `sed -I` (`sed -I.bak 's/1/2/' .harness/config.json`).
222
+ - Writes inside a program: `sed -n 'w .oxlintrc.json' /tmp/new.json`, `awk '{print > ".oxlintrc.json"}' /tmp/new.json`; and targets read from stdin: `xargs -I{} cp /tmp/new.json {} <<< .oxlintrc.json`.
223
+
224
+ Backstop: the CI gates (baseline ratchet, code owner review of protected files), and A4-1b's post-execution hash check of D-class files.
110
225
 
111
226
  ## Fail-closed and fail-open error contract (`defineHook`)
112
227
 
@@ -115,6 +230,7 @@ All handlers are registered through `defineHook()` in `src/hook/define.ts`:
115
230
  - **PreToolUse (`pre-bash`, `pre-edit`) fails closed:** any error — synchronous throw, async rejection, empty/invalid/non-object/oversize (> 1 MiB) stdin, unreadable config, missing dependency (e.g. `git` not in PATH), or internal deadline expiration (`4s` for cc, `8s` for codex/agy) — emits an explicit `deny` response (`permissionDecision: "deny"` for cc/codex; `{"decision":"deny","reason":"…"}` for agy). Unknown agent/event routes also fail closed.
116
231
  - **Non-PreToolUse (`stop`, `post-tool`, `session-start`, `pre-invocation`) fails open with notice:** errors never emit `block` or `continue` (which would trap the agent in a loop); they emit an allow response plus a visible warning (`systemMessage` on cc/codex, `injectSteps` or stderr warning on agy).
117
232
  - **Single emission & EPIPE safety:** fallback failure outputs are pre-built at registration time; `emit()` runs at most once even if both deadline and rejection occur, and catches stdout `EPIPE` errors cleanly.
233
+ - **Routing by tool:** `pre-bash` and `pre-edit` both evaluate a call by its tool, not by the event it arrived on: a shell tool (`Bash`, `run_command`) is checked as a command and an edit tool (`Edit`, `Write`, `MultiEdit`, `NotebookEdit`, `apply_patch`, `write_file`, `edit_file`) by its targets, so an agent configuration that routes `Write` to `pre-bash` still denies a D-class target. A missing command or target on a known tool fails closed on either event; other tools are allowed (explicitly on Antigravity).
118
234
  - **Missing-package exception (A4-1b):** the launcher distinguishes "harness package not yet installed" from runtime errors and allows with a visible notice so a fresh clone is not deadlocked before `npm ci` / `pnpm install --frozen-lockfile`.
119
235
 
120
236
  ## Items pending Codex live-machine verification
package/docs/ratchet.md CHANGED
@@ -1,17 +1,17 @@
1
1
  # od-harness ratchet
2
2
 
3
- Baselines may only shrink. `od-harness ratchet --base <ref>` compares the working tree with the base commit (in CI: `"$HARNESS_BASE_REF"`, the PR base).
3
+ `od-harness ratchet --base <ref>` compares the working tree with the base commit (in CI: `"$HARNESS_BASE_REF"`, the PR base). For a local run, `od-harness ratchet --merge-base origin/main` compares with the commit the branch left `origin/main` at (below).
4
4
 
5
5
  It fails when:
6
6
 
7
- | Check | Fails when |
8
- | ---------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
9
- | `oxlint-suppressions.json`, per rule | the total count of any rule ID grew (summed over all files). Debt may move between files as long as the total does not grow. |
10
- | `oxlint-suppressions.json`, new rule IDs | a rule appears that the base did not have, unless the same change upgrades `@opendesignai/harness` or its `.oxlintrc.json` change turns that rule on ([below](#why-a-config-or-version-change-admits-new-rule-ids); both owner-reviewed). |
11
- | `oxlint-suppressions.json`, new files | an entry names a file that the base commit does not have. New files do not get a baseline, also not in the adoption change or together with a new rule ID. A moved file keeps the entry of its old path ([moved files](#moved-files)). |
12
- | both baselines, stale entries | an entry names a file that no longer exists. |
13
- | `.harness/size-baseline.json` | an entry was raised, or a file was added (except a [moved file](#moved-files)). |
14
- | both baselines, new baseline file | the base commit has no such file, unless the same change adds `@opendesignai/harness` to `package.json` (the adoption change). Upgrading the harness or changing `.oxlintrc.json` does not count. |
7
+ | Check | Fails when |
8
+ | --------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
9
+ | `oxlint-suppressions.json`, existing rule IDs | a rule's total count across all files grows from a positive count at the base, unless the same change upgrades `@opendesignai/harness` ([below](#why-a-config-or-version-change-admits-new-rule-ids)). |
10
+ | `oxlint-suppressions.json`, new rule IDs | a rule appears that the base did not have, unless the harness version declaration changes or `.oxlintrc.json` turns that rule on ([below](#why-a-config-or-version-change-admits-new-rule-ids), both owner-reviewed). |
11
+ | `oxlint-suppressions.json`, new files | an entry names a file that the base commit does not have. New files do not get a baseline, also not in the adoption change or together with a new rule ID. A moved file keeps the entry of its old path ([moved files](#moved-files)). |
12
+ | both baselines, stale entries | an entry names a file that no longer exists. |
13
+ | `.harness/size-baseline.json` | an entry was raised, or a file was added (except a [moved file](#moved-files)). |
14
+ | both baselines, new baseline file | the base commit has no such file, unless the same change adds `@opendesignai/harness` to `package.json` (the adoption change). Upgrading the harness or changing `.oxlintrc.json` does not count. |
15
15
 
16
16
  A baseline file may only appear in the adoption change: the change that adds `@opendesignai/harness` to `package.json`, where the base lists it in neither `dependencies` nor `devDependencies`. Then the comparison with the base is skipped and reported. Any later change that creates `oxlint-suppressions.json` or `.harness/size-baseline.json` fails, also one that upgrades the harness or changes `.oxlintrc.json`: a repository that was adopted without a baseline (no existing debt) keeps it that way, and the violations an upgrade or a config change brings are fixed in that change instead of frozen. This does not depend on review, so it holds even when a change is merged without the owner's approval, as long as the caller's workflow keeps `ratchet` on (turning a gate off is a reviewed workflow change).
17
17
 
@@ -25,36 +25,38 @@ Entries may follow a file to a new path; [`od-harness baseline move`](baseline-m
25
25
  - the old path had an entry in the same baseline at the base and no longer exists (spelled exactly so, also on file systems that ignore case);
26
26
  - the moved entry holds no more than the old one did (per rule, or in lines), and each old entry moves to one file only.
27
27
 
28
- The rule totals are compared as always, so a move never lets a total grow. Accepted moves are listed in the output (`baseline entry moved from …`, `frozen size moved from …`); rejected ones say which condition failed.
28
+ The same rule total checks apply to moves. Accepted moves are listed in the output (`baseline entry moved from …`, `frozen size moved from …`); rejected ones say which condition failed.
29
29
 
30
30
  ## Why a config or version change admits new rule IDs
31
31
 
32
- A rule ID may enter the baseline only in the change that turns the rule on: an owner-reviewed upgrade of `@opendesignai/harness` or change to `.oxlintrc.json`.
33
-
34
- - **The harness version changed** (`dependencies` or `devDependencies` of `package.json`; for a pnpm catalog reference, `catalog:`, the harness entries of the nearest `pnpm-workspace.yaml`): every new rule ID is admitted. Which rules an upgrade turns on cannot be told in CI (below).
35
- - **Otherwise, `.oxlintrc.json` changed**: a new rule ID is admitted only when this change turns that rule on. The rule is on in the change's effective configuration, at the top level or in an override, and its settings differ from the base's: another severity or other options, or an override with other `files`. An unrelated edit (an `ignorePatterns` entry, another rule) admits nothing, and neither does restating a rule that a preset or a category already turns on.
36
- - **Neither changed**: no new rule ID is admitted.
32
+ - **The harness version increased.** Existing rule totals may grow only when both versions resolve to exact SemVer versions and the new version is higher, including prerelease precedence. A minor or major release can make an existing rule report more, so the upgrade can include the resulting suppressions for existing files. Ratchet reports the old and new totals and versions.
33
+ - **The harness version declaration changed.** This admits every new rule ID.
34
+ - **Otherwise, `.oxlintrc.json` can admit a new rule ID.** The rule must be on in the change's effective configuration, at the top level or in an override, and its settings must differ from the base's in severity, options or override `files`. An unrelated edit (an `ignorePatterns` entry, another rule) admits nothing, and neither does restating a rule that a preset or a category already turns on.
37
35
 
38
36
  The effective configurations come from Oxlint 1.96.0: `oxlint -c <file> --print-config` prints a configuration file with `extends` resolved and categories expanded into rules; `overrides` keep their globs, so an override counts by its `files` and settings. For the base, `ratchet` writes the base commit to a temporary directory (as `unused` does) and links the working tree's `node_modules` into it, so the base's `.oxlintrc.json` extends the installed presets and loads the installed plugins. That is exact because the harness version did not change. If Oxlint cannot print either configuration (it cannot load a plugin, or it is not installed), `ratchet` compares the rule settings written in the two files instead, and says so in the output; then only rules the change sets itself are admitted. Only the file `--lint-config` names counts: nested `.oxlintrc.json` files are separate configurations, which Oxlint prints separately.
39
37
 
40
- An upgrade keeps the broader condition: CI installs the change's dependencies only, so the base's configuration would be read with the new harness's presets, a rule the upgrade adds would look enabled at the base already, and the upgrade could not baseline it. Narrowing that case needs the rule list of every harness version in the package ([Next steps](../README.md#next-steps)). Two things keep the remaining room from becoming a way around the gate:
38
+ In an effective configuration where `options.typeAware` is unset or false, type-aware rules count as off at the top level and in overrides. When either side has type-aware linting off, `ratchet` reads the rule metadata once from `oxlint --rules --format json` to identify those rules. Enabling `options.typeAware` can therefore admit a type-aware rule that a category already listed as enabled. It must still be enabled in the change's effective configuration. If the metadata command fails, `ratchet` reports an environment error.
39
+
40
+ CI installs the change's dependencies only. Reading the base's configuration with the new harness's presets would make a rule added by the upgrade look enabled at the base. Identifying which rule IDs an upgrade adds needs the rule list of every harness version in the package ([Next steps](../README.md#next-steps)).
41
41
 
42
- - new files never enter a baseline (above), so new code cannot hide debt behind a new rule ID;
43
- - `.oxlintrc.json`, `package.json` and `pnpm-workspace.yaml` belong to the platform owner in CODEOWNERS, so every change that admits a new rule ID is reviewed by the owner.
42
+ New files are excluded from baselines in both version and configuration changes. `.oxlintrc.json`, `package.json` and `pnpm-workspace.yaml` belong to the platform owner in CODEOWNERS. The owner reviews the changes to version declarations and lint configuration that affect baselines.
44
43
 
45
44
  This condition does not admit a new baseline file: only the adoption change may create one (above), so a repository without baselines cannot gain one through a config change or an upgrade, reviewed or not.
46
45
 
47
- The version is read from `dependencies` or `devDependencies` in `package.json`. With a pnpm catalog (`"catalog:"`), the lines that name `@opendesignai/harness` in the nearest `pnpm-workspace.yaml` (from the working directory up to the repository root) are compared as well, so a catalog upgrade counts as a version change. Only the change that adds the harness to `package.json` is the adoption change, also with a catalog.
46
+ Ratchet reads the version declaration from `dependencies` or `devDependencies` in `package.json`. To compare SemVer versions, it resolves the referenced catalog in the nearest `pnpm-workspace.yaml` on each side. For new rule IDs, it also checks for changes to the lines that name `@opendesignai/harness` in the working tree's nearest `pnpm-workspace.yaml` and the same path at the base. Only the change that adds the harness to `package.json` is the adoption change, also with a catalog.
48
47
 
49
48
  ## Options
50
49
 
51
50
  ```text
52
- --base <ref> required; any commit-ish (sha, branch, tag)
51
+ --base <ref> any commit-ish (sha, branch, tag); this or --merge-base is required
52
+ --merge-base <ref> for local runs: compare with `git merge-base HEAD <ref>`
53
53
  --suppressions <path> default: oxlint-suppressions.json
54
54
  --lint-config <path> default: .oxlintrc.json
55
55
  ```
56
56
 
57
- Exit codes: 0 pass, 1 a check failed, 2 usage error (for example an unknown ref; check out with `fetch-depth: 0`).
57
+ `--merge-base <ref>` works like od-platform's `check-api --merge-base`: the base is `git merge-base HEAD <ref>`, so commits that landed on `<ref>` after the branch left it (a baseline that shrank there) do not show up as growth. When `<ref>` does not resolve (not fetched) or HEAD and `<ref>` share no history (a shallow clone), the check is skipped with a warning and exit code 0. CI passes `--base` (gates.yml), which never skips.
58
+
59
+ Exit code 0 means the check passed or `--merge-base` skipped it. Exit code 1 means the check failed. Exit code 2 means a usage or environment error. Usage errors, such as combining `--base` and `--merge-base`, print the diagnostic and help text. Environment errors print one line, for example when `--base` cannot resolve (check out with `fetch-depth: 0`), the command runs outside a git work tree, or a baseline is malformed. The base's `oxlint-suppressions.json` is read leniently so a change can repair it. A file that maps to anything but an object in that baseline counts as having no entries. An entry for a new file is reported whatever its counts, also `"count": 0`.
58
60
 
59
61
  ## How to fix a failure
60
62
 
@@ -0,0 +1,47 @@
1
+ # od/no-commented-out-code
2
+
3
+ Preset: `base`
4
+
5
+ ## What it reports
6
+
7
+ The rule checks standalone block comments and runs of consecutive standalone `//` comments. It reports once per block or run when its contents parse as TSX and contain recognizable code. It tries the contents as written, inside an async function, inside a class, and as JSX children.
8
+
9
+ ```tsx
10
+ // const oldValue = readCache();
11
+ // cache.write(oldValue);
12
+
13
+ /*
14
+ return await loadDraft();
15
+ */
16
+
17
+ const preview = (
18
+ <main>
19
+ {/* <LegacyPreview /> */}
20
+ <Preview />
21
+ </main>
22
+ );
23
+ ```
24
+
25
+ Declarations, control flow, `await`, constructor calls, and member calls are signals. A semicolon can distinguish `save()` or `count = 2` from prose such as `MAX(col)` or `audioRow = 2`. Simple prose such as `return early` and plain HTML illustrations such as `<div>Text</div>` are skipped.
26
+
27
+ ## Why
28
+
29
+ Inactive code makes it harder to see what runs and can become stale as the surrounding code changes. Git keeps the previous version available.
30
+
31
+ ## How to fix
32
+
33
+ Delete the commented-out code. Use git history to recover old code. Move examples into documentation or tests.
34
+
35
+ ## Exemptions
36
+
37
+ The rule skips trailing comments, JSDoc including `@example` blocks, URL-led comments, and tooling directives such as `eslint-disable`, `@ts-expect-error` and `fail-open:`. Tooling directives also separate adjacent comment runs.
38
+
39
+ For a file that needs to keep commented-out code, use an owner-reviewed `overrides` entry in the lint config. The `base` preset rejects inline disables for `od/*`.
40
+
41
+ ## Options
42
+
43
+ This rule has no options.
44
+
45
+ ## Limits
46
+
47
+ The rule can miss a code fragment if prose in the same block or run prevents it from parsing. A standalone formula, constructor signature, or syntax example can also parse as code and be reported.
@@ -4,21 +4,30 @@ Preset: `base`
4
4
 
5
5
  ## What it reports
6
6
 
7
- - An empty `catch` block. Comments, `;` and empty blocks do not count as handling.
8
- - A rejection handler, `.catch(handler)` or the second argument of `.then(onFulfilled, handler)`, that has an empty body or only produces a constant: a literal (`null`, `false`, `0`, `""`, `"none"`), `undefined`, `void …`, a template literal without expressions, `{}` or `[]`, or no value at all (`return;`).
7
+ - A `catch` block that is empty or only returns a constant, including when the return is inside nested blocks. Comments, `;` and empty blocks do not count as handling.
8
+ - A rejection handler, `.catch(handler)` or the second argument of `.then(onFulfilled, handler)`, that has an empty body or only produces a constant.
9
+
10
+ Reported constants include `null`, booleans, numbers, `undefined`, `void …`, empty string and template literals, `{}`, `[]` and a bare `return;`.
9
11
 
10
12
  ```ts
11
13
  try {
12
14
  await save();
13
15
  } catch {}
16
+ try {
17
+ return JSON.parse(text);
18
+ } catch {
19
+ return null;
20
+ }
14
21
  const state = await readState().catch(() => null);
15
22
  const config = await load().then(parse, () => ({}));
16
23
  ```
17
24
 
18
25
  Not reported:
19
26
 
27
+ - a probe with exactly two statements in `try`: a direct call (optionally `await`ed) followed by `return true`. Its `catch` must contain exactly one statement, `return false`. Assignments, increments, decrements, function expressions, arrow functions and chained calls anywhere in the call expression disqualify the probe. Plain helper calls in arguments are allowed, as in `await access(path.join(dir, file))`;
28
+ - non-empty string literals such as `'retry' as const` and non-empty template literals without interpolations, in both catch blocks and promise rejection handlers;
20
29
  - a `try` block that only calls cleanup functions (`close`, `cancel`, `abort`, `destroy`, `dispose`, `release`, `rm`, `unlink`, `removeItem`, …), and `.catch()` / `.then()` on such a call: `body.cancel().catch(() => {})`;
21
- - handlers that use the error or return a real fallback value (`.catch(() => defaultConfig)`);
30
+ - catch blocks and handlers that use the error or return a real fallback value (`.catch(() => defaultConfig)`, `catch (e) { return toResult(e); }`);
22
31
  - a handler marked with a `// fail-open: <reason>` comment inside it, or on the line of (or just above) the `catch`.
23
32
 
24
33
  ## Why
@@ -27,14 +36,14 @@ Swallowed errors make failures invisible: a failed write followed by "success" U
27
36
 
28
37
  ## How to fix
29
38
 
30
- Log with context and report to telemetry, return an explicit error result, or rethrow. If the caller can genuinely proceed, say why in code:
39
+ Log with context and report to telemetry, return an explicit error result, or rethrow.
31
40
 
32
41
  ```ts
33
42
  try {
34
- await warmCache();
43
+ await save();
35
44
  } catch (error) {
36
- // fail-open: the cache only speeds up the first paint; the page loads without it
37
- logger.warn("cache warm-up failed", { error });
45
+ logger.error("save failed", { error });
46
+ telemetry.captureException(error);
38
47
  }
39
48
  ```
40
49
 
@@ -73,4 +82,6 @@ try {
73
82
 
74
83
  ## Limits
75
84
 
85
+ Calls with side effects such as `writeFile`, `addAsset`, or `postMessage` can have the same syntax as a probe. Check what those calls do during code review.
86
+
76
87
  The rule cannot judge whether a returned fallback is correct (`.catch(() => game)` after a failed write is still a swallowed failure); that stays a review item.
package/docs/size.md CHANGED
@@ -7,7 +7,7 @@ File size budget: a file should be small enough for a person or an agent to read
7
7
  | Source (`.ts`, `.tsx`, `.js`, `.jsx`, `.mjs`, `.cjs`, `.mts`, `.cts`) | 800 lines |
8
8
  | Tests (`*.test.*`, `*.spec.*`, `__tests__/`) and stylesheets (`.css`) | 1,500 lines |
9
9
 
10
- Files are those git tracks plus untracked files that are not ignored. Lines are counted like `wc -l` (a last line without a newline counts too).
10
+ Files are those git tracks plus untracked files that are not ignored. Only regular files count: symbolic links (to a file or a directory) and submodules are skipped. Lines are counted like `wc -l` (a last line without a newline counts too).
11
11
 
12
12
  - **Which files count as tests**: only the name decides. A file matching `*.test.*` or `*.spec.*`, or inside a `__tests__/` directory, gets 1,500 lines. Helpers in `test/` or `tests/` directories (`test/helpers.ts`, `tests/setup.ts`) are not test files by this rule and get 800 lines like other source.
13
13
  - **Which files are not counted**: every other extension. Stylesheets other than `.css` (`.scss`, `.less`), single-file components (`.vue`, `.svelte`), and `.json`, `.md`, `.html` and similar files have no budget. Generated or vendored sources with a counted extension can be excluded (see below).
@@ -50,3 +50,5 @@ Generated or vendored sources can be excluded in `.harness/config.json` (owner r
50
50
  ```
51
51
 
52
52
  Patterns are repo-relative: `dir/` matches a directory, globs support `**`, `*` and `?`. A file that is not valid JSON fails with exit code 2 and the parse error.
53
+
54
+ Exit code 0 means the check passed and 1 means it failed. Exit code 2 means a usage or environment error. Usage errors print the diagnostic and help text. Environment errors print one line, for example when the command runs outside a git work tree or `.harness/size-baseline.json` or `.harness/config.json` is malformed.