@opendesignai/harness 0.1.0-alpha.0 → 0.2.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.
- package/README.md +17 -12
- package/dist/cli.mjs +1438 -95
- package/dist/eslint-comments.d.mts +17 -1
- package/dist/eslint-comments.mjs +134 -2
- package/dist/plugin.d.mts +20 -4
- package/dist/plugin.mjs +429 -59
- package/docs/adopting.md +84 -17
- package/docs/baseline-move.md +56 -0
- package/docs/clones.md +51 -0
- package/docs/decisions/0003-agent-harness.md +37 -0
- package/docs/hooks.md +128 -0
- package/docs/ratchet.md +25 -9
- package/docs/rules/no-api-path-literal.md +1 -1
- package/docs/rules/no-cjk-literal.md +1 -1
- package/docs/rules/no-error-message-match.md +11 -3
- package/docs/rules/no-locale-branch.md +9 -5
- package/docs/rules/no-process-env.md +11 -1
- package/docs/rules/no-product-literal.md +6 -0
- package/docs/rules/no-raw-storage.md +4 -2
- package/docs/rules/no-shell-imports-product.md +4 -2
- package/docs/rules/no-swallowed-catch.md +5 -4
- package/docs/size.md +1 -0
- package/docs/unused.md +76 -0
- package/package.json +6 -4
- package/presets/rules/base.json +5 -3
package/docs/adopting.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Adopting od-harness in a repository
|
|
2
2
|
|
|
3
|
-
The goal of the adoption change: lint, size budget
|
|
3
|
+
The goal of the adoption change: lint, size budget, baseline ratchet and the incremental duplication (jscpd) and unused-code (knip) checks run in CI as the single required check `harness-gates / harness-gates`; all existing debt is frozen in baselines or tolerated by comparison with the base commit, and only new violations fail.
|
|
4
4
|
|
|
5
5
|
## 1. Install
|
|
6
6
|
|
|
@@ -11,7 +11,9 @@ pnpm add -D --save-exact @opendesignai/harness@alpha oxlint@1.96.0
|
|
|
11
11
|
# or: npm install -D --save-exact @opendesignai/harness@alpha oxlint@1.96.0
|
|
12
12
|
```
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
pnpm 12 checks every version it installs against `minimumReleaseAge` (1,440 minutes unless the repository sets it): a version published more recently needs an entry in `minimumReleaseAgeExclude` in `pnpm-workspace.yaml`, and CI's frozen install checks the lockfile against both. To adopt or upgrade to an od-harness release within that window, install the exact version and commit its entry, for example `"@opendesignai/harness@0.2.0-alpha.0"`. Under pnpm's built-in setting, which is not strict, `pnpm install` writes the entry itself; a repository that sets `minimumReleaseAge` approves it at pnpm's prompt or adds it by hand. The entry can go once the release is older than the window; the pnpm documentation describes these settings.
|
|
15
|
+
|
|
16
|
+
Releases are published to npm under the `opendesignai` organization with the `alpha` dist-tag, by the release workflow through npm trusted publishing ([README, Versioning](../README.md#versioning)). To try an unreleased change, run `pnpm pack` in an od-harness checkout and install the tarball it writes (never the checkout itself, which has `catalog:` and `workspace:` specifiers), for example `"@opendesignai/harness": "file:vendor/opendesignai-harness-0.1.0-alpha.0.tgz"`.
|
|
15
17
|
|
|
16
18
|
Add a `.node-version` file if the repository does not have one; CI sets up Node from it.
|
|
17
19
|
|
|
@@ -55,7 +57,7 @@ Create `.oxlintrc.json` at the repository root:
|
|
|
55
57
|
- The base preset reports unused disable directives as errors (`options.reportUnusedDisableDirectives`); there is no need to repeat it here.
|
|
56
58
|
- The base preset already turns `od/no-cjk-literal` off in tests and fixtures (`*.test.*`, `*.spec.*`, `__tests__/`, `__fixtures__/`, `fixtures/`). Exclude the repository's own i18n catalog, as `ignorePatterns` does above.
|
|
57
59
|
- Exemptions are `overrides` entries in this file. The file belongs to the platform owner (CODEOWNERS); every exemption is reviewed there, never inline.
|
|
58
|
-
- CODEOWNERS also gives the platform owner `package.json` (the harness version)
|
|
60
|
+
- CODEOWNERS also gives the platform owner `package.json` (the harness version), `.harness/config.json` and the knip configuration (step 3a). `od-harness ratchet` admits new rule IDs into an existing baseline only in a change that upgrades the harness, or whose `.oxlintrc.json` change turns those rules on, so this review is what guards the baselines ([ratchet](ratchet.md#why-a-config-or-version-change-admits-new-rule-ids)). With a pnpm catalog, `pnpm-workspace.yaml` holds the harness version: give it to the owner too. A new baseline file it admits only in the adoption change, without relying on review.
|
|
59
61
|
- Run Oxlint from the repository root: path options (`shell`, `product`) are relative to the working directory.
|
|
60
62
|
|
|
61
63
|
Add scripts:
|
|
@@ -65,11 +67,15 @@ Add scripts:
|
|
|
65
67
|
"scripts": {
|
|
66
68
|
"lint": "oxlint --deny-warnings",
|
|
67
69
|
"size": "od-harness size",
|
|
68
|
-
"ratchet": "od-harness ratchet --base origin/main"
|
|
70
|
+
"ratchet": "od-harness ratchet --base origin/main",
|
|
71
|
+
"clones": "od-harness clones --base origin/main",
|
|
72
|
+
"unused": "od-harness unused --base origin/main"
|
|
69
73
|
}
|
|
70
74
|
}
|
|
71
75
|
```
|
|
72
76
|
|
|
77
|
+
The scripts also tell knip that `oxlint` and `@opendesignai/harness` are in use, so `od-harness unused` does not report the two new devDependencies in the adoption change.
|
|
78
|
+
|
|
73
79
|
## 3. Clean up what cannot be baselined
|
|
74
80
|
|
|
75
81
|
Unused disable directives are reported as errors but cannot go into `oxlint-suppressions.json` (opengame had 44, openmotion 43). Run `oxlint --fix` (removes some) and delete the remaining reported comments by hand. This includes disable comments for rules the presets turn off, such as `oxlint-disable-line react/refs` without the `react-compiler` preset (3 in each of the two).
|
|
@@ -82,6 +88,60 @@ git grep -n -E '(eslint|oxlint)-disable(-next-line|-line)?[[:space:]]*(\*/|--|$)
|
|
|
82
88
|
|
|
83
89
|
Upstream `@eslint-community/eslint-plugin-eslint-comments` crashes under Oxlint 1.96.0 on such a comment in the first line of a file, which drops every `od/*` result for that file. The base preset therefore loads od-harness's wrapper of the plugin (`dist/eslint-comments.mjs`), which reports these comments on their own line instead; see [docs/upstream/oxc-negative-column.md](https://github.com/nexu-io/od-harness/blob/main/docs/upstream/oxc-negative-column.md).
|
|
84
90
|
|
|
91
|
+
## 3a. Configure the incremental checks
|
|
92
|
+
|
|
93
|
+
`od-harness clones` (jscpd) and `od-harness unused` (knip) keep no baseline: they compare the change with its base commit and fail only on what the change adds. Both tools are dependencies of od-harness; do not install them for the gates. In `gates.yml@v1` both gates are off by default: turn them on with `clones: true` and `unused: true` (step 5).
|
|
94
|
+
|
|
95
|
+
- **knip** runs with the repository's knip configuration at the root (`knip.json`, `package.json#knip`, …), on both sides. A repository that ran the maintainability report moves `.github/maintainability/knip.json` to `knip.json` at the root, in the adoption change, and removes the old report job. Without a configuration knip's defaults apply. Exemptions (`entry`, `ignore`, `ignoreDependencies`) live there, so the file belongs to the owner. Details: [unused](unused.md).
|
|
96
|
+
- **jscpd** runs with od-harness's settings (JavaScript and TypeScript, 12 lines and 80 tokens) and ignores only what `.harness/config.json` lists in `clones.ignore`: od-harness has no ignore list of its own, so without the file jscpd checks tests, fixtures, generated and vendored code too. A `.jscpd.json` is not read. Details: [clones](clones.md).
|
|
97
|
+
|
|
98
|
+
The two tools take their exclusions from different files, both owned by the platform owner (CODEOWNERS):
|
|
99
|
+
|
|
100
|
+
| Gate | What it leaves out is listed in | Not read by it |
|
|
101
|
+
| -------- | --------------------------------------------- | ---------------------- |
|
|
102
|
+
| `clones` | `clones.ignore` in `.harness/config.json` | the knip configuration |
|
|
103
|
+
| `unused` | the knip configuration (`entry`, `ignore`, …) | `.harness/config.json` |
|
|
104
|
+
|
|
105
|
+
Recommended `.harness/config.json`, to copy into the adoption change. It holds every glob of the maintainability report's `jscpd.json` (`.github`, `build`, `dist`, `fixtures`, `node_modules`, `template-library`, `templates`, `tests`, test and spec files, `*.d.ts`) and also leaves out coverage output, vendored code, minified files, `test/`, `__tests__/`, `__fixtures__/`, `__mocks__/` and generated code:
|
|
106
|
+
|
|
107
|
+
```json
|
|
108
|
+
{
|
|
109
|
+
"clones": {
|
|
110
|
+
"ignore": [
|
|
111
|
+
"**/node_modules/**",
|
|
112
|
+
"**/dist/**",
|
|
113
|
+
"**/build/**",
|
|
114
|
+
"**/coverage/**",
|
|
115
|
+
"**/vendor/**",
|
|
116
|
+
"**/*.d.ts",
|
|
117
|
+
"**/*.min.js",
|
|
118
|
+
"**/*.test.*",
|
|
119
|
+
"**/*.spec.*",
|
|
120
|
+
"**/__tests__/**",
|
|
121
|
+
"**/test/**",
|
|
122
|
+
"**/tests/**",
|
|
123
|
+
"**/__fixtures__/**",
|
|
124
|
+
"**/fixtures/**",
|
|
125
|
+
"**/__mocks__/**",
|
|
126
|
+
"**/generated/**",
|
|
127
|
+
"**/__generated__/**",
|
|
128
|
+
"**/*.generated.*",
|
|
129
|
+
"**/.github/**",
|
|
130
|
+
"**/template-library/**",
|
|
131
|
+
"**/templates/**"
|
|
132
|
+
]
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
A path listed there is not checked by `clones` at all: no clone in it fails, and no clone between it and other code. The owner decides what is added or removed, for example when a repository wants its tests checked too (remove the test globs) or has vendored code elsewhere (add its directory).
|
|
138
|
+
|
|
139
|
+
od-harness reads `.harness/config.json` from the directory it runs in, the `working-directory` of `gates.yml` (the repository root by default), as it reads the two baselines, and the globs are relative to that directory. Where the gates run in a package of a larger repository, the file goes into that package: a `.harness/config.json` anywhere else is not read, and jscpd then checks every file, tests and fixtures included.
|
|
140
|
+
|
|
141
|
+
Trial on openmotion and opengame (adoption change against the snapshot HEAD, both clean): `clones` scanned 2,018 and 1,917 files with 84 and 106 existing clones in about 3 s; `unused` found 640 and 464 existing findings in about 5 to 6 s, with `npm ci` done first.
|
|
142
|
+
|
|
143
|
+
A repository whose JavaScript and TypeScript files are all smaller than jscpd's 80 tokens (a new repository) gives jscpd nothing to scan, and `clones` stops with exit 2 ("jscpd scanned no file") instead of passing. Leave `clones` off in the workflow inputs (the default in `v1`) and turn it on in the first change that adds such code (owner-reviewed).
|
|
144
|
+
|
|
85
145
|
## 4. Generate the baselines (only if there is existing debt)
|
|
86
146
|
|
|
87
147
|
If `pnpm exec oxlint` and `pnpm exec od-harness size` already pass, skip this step: see [Adopting with zero debt](#adopting-with-zero-debt).
|
|
@@ -132,26 +192,33 @@ jobs:
|
|
|
132
192
|
harness-gates:
|
|
133
193
|
uses: nexu-io/od-harness/.github/workflows/gates.yml@v1
|
|
134
194
|
with:
|
|
195
|
+
clones: true # off by default in v1
|
|
196
|
+
unused: true # off by default in v1
|
|
135
197
|
commands: pnpm test # optional
|
|
136
198
|
```
|
|
137
199
|
|
|
200
|
+
Set `clones: true` and `unused: true` in the change that adopts or upgrades to a version of `@opendesignai/harness` that has these gates, together with the configuration of step 3a.
|
|
201
|
+
|
|
138
202
|
- The workflow picks pnpm (`pnpm-lock.yaml`) or `npm ci` (`package-lock.json`), sets up Node from `.node-version` and checks out the full history so `ratchet` can read the base commit.
|
|
139
|
-
- It
|
|
203
|
+
- It runs the gates that are on, in this order: `oxlint --deny-warnings`, `od-harness size`, then `od-harness ratchet`, `od-harness clones` and `od-harness unused`, each with `--base "$HARNESS_BASE_REF"`, through `pnpm exec` or `npx --no-install`. Then it runs each line of `commands` (for example `pnpm test`, or `npm test` with npm). Every command runs even after a failure, and the job fails if any failed. The install step comes first, so knip can load the repository's tool configurations.
|
|
140
204
|
- `HARNESS_BASE_REF` is the PR base, the merge-queue base, or the previous commit on push.
|
|
141
|
-
- Inputs: `lint`, `size
|
|
142
|
-
- Do not repeat `pnpm lint
|
|
205
|
+
- Inputs: `lint`, `size` and `ratchet` (booleans, default `true`); `clones` and `unused` (booleans, default `false` in `v1`, turned on as above; turning them on by default takes a new tag, `v2`); `commands` (default empty), `working-directory`, `node-version-file`, `fetch-depth` (keep `0`: `ratchet`, `clones` and `unused` read the base commit, and fail with exit code 2 when it is missing), `timeout-minutes`, `runs-on`. Turning a gate on or off is a change to this workflow file and goes through owner review.
|
|
206
|
+
- Do not repeat `pnpm lint` or any `od-harness` gate in `commands`: the gates already run them, from one definition in od-harness.
|
|
143
207
|
- Make the check `harness-gates / harness-gates` required in the branch ruleset.
|
|
144
208
|
- Reference the workflow by the git tag `v1` (`gates.yml@v1`), as above.
|
|
145
209
|
|
|
146
210
|
## Day to day
|
|
147
211
|
|
|
148
|
-
| Situation | What to do
|
|
149
|
-
| ------------------------------------- |
|
|
150
|
-
| Lint reports a new violation | Fix it. Do not add a disable comment (rejected) or touch the baseline (ratchet fails).
|
|
151
|
-
| You fixed existing debt | Run `oxlint --prune-suppressions` and commit the smaller `oxlint-suppressions.json`; CI fails until you do.
|
|
152
|
-
| A frozen file got smaller | Run `od-harness size --update` and commit; CI fails until you do.
|
|
153
|
-
| A frozen file must grow | Move code out of it instead.
|
|
154
|
-
| A file is deleted
|
|
155
|
-
|
|
|
156
|
-
|
|
|
157
|
-
|
|
|
212
|
+
| Situation | What to do |
|
|
213
|
+
| ------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
214
|
+
| Lint reports a new violation | Fix it. Do not add a disable comment (rejected) or touch the baseline (ratchet fails). |
|
|
215
|
+
| You fixed existing debt | Run `oxlint --prune-suppressions` and commit the smaller `oxlint-suppressions.json`; CI fails until you do. |
|
|
216
|
+
| A frozen file got smaller | Run `od-harness size --update` and commit; CI fails until you do. |
|
|
217
|
+
| A frozen file must grow | Move code out of it instead. |
|
|
218
|
+
| A file is deleted | Prune both baselines (`oxlint --prune-suppressions`, `od-harness size --update`). |
|
|
219
|
+
| A file or directory is moved | `git mv` (the move must be staged), fix the imports, then, before committing, `od-harness baseline move <old path> <new path>`; commit the baselines with the moved files in the same change. Each new file must still be its old file: a rename git sees (`git diff -M30% -l0`), nothing else counts. The move is reviewed with the change that makes it: `ratchet` lists each moved entry in its output, and where CODEOWNERS covers every path the owner reviews it like any other change. See [baseline move](baseline-move.md). |
|
|
220
|
+
| `od-harness clones` reports a clone | Extract the shared code instead of copying it. Generated or vendored code goes into `clones.ignore` (owner review); the marker text `jscpd:ignore-start` or `jscpd:ignore-end` on added or edited lines (in a comment, a string or code) of the files jscpd scans—`.es`, `.es6` and files without those extensions whose first line is a shebang that contains `node` included—and tracked files among them that `.gitignore` or `.ignore` excludes, fail the gate. |
|
|
221
|
+
| `od-harness unused` reports a finding | Delete the unused file, export or dependency, or use it. Code used where knip cannot see it is declared in the knip configuration (owner review); the tags `@public`, `@beta` and `@alias` in a comment (a block comment, or a line comment on a line of its own), and tracked files that `.gitignore` excludes, fail the gate. |
|
|
222
|
+
| Upgrading od-harness adds a rule | On an otherwise clean branch, run `oxlint --suppress-all` to baseline the new rule; `ratchet` accepts new rule IDs in the change that upgrades the harness. A repository without `oxlint-suppressions.json` fixes the violations instead; `ratchet` does not let it create one. |
|
|
223
|
+
| Upgrading od-harness turns a rule off | Run `oxlint --prune-suppressions` and delete the disable comments that became unused, in the upgrade change. |
|
|
224
|
+
| Turning on React Compiler | Extend `react-compiler` after `base` in the same change. Fix what it reports, or, in a repository that has `oxlint-suppressions.json`, baseline it there (`oxlint --suppress-all` on an otherwise clean branch); `ratchet` accepts the new rule IDs because this `.oxlintrc.json` change turns them on (it compares the effective configurations; an unrelated edit to `.oxlintrc.json` admits nothing). |
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# od-harness baseline move
|
|
2
|
+
|
|
3
|
+
Baselines are keyed by file path. When a file with frozen debt moves, its entries name a path that no longer exists, and the debt shows up again at the new path: Oxlint reports the violations, `od-harness size` reports the file as over budget, and `od-harness ratchet` rejects entries for paths the base does not have. `od-harness baseline move` takes the entries along with the files.
|
|
4
|
+
|
|
5
|
+
```text
|
|
6
|
+
od-harness baseline move <from> <to> [--suppressions <path>] [--base <ref>]
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
`<from>` and `<to>` are a file or a directory, relative to the directory od-harness runs in (the repository root), spelled like the baseline keys. `<to>` is the new path of `<from>`, not its new parent directory.
|
|
10
|
+
|
|
11
|
+
## Steps
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
git mv studio/src/motion/game packages/game/src # 1. move the files (staged)
|
|
15
|
+
# fix the imports of the moved files and of their importers
|
|
16
|
+
pnpm exec od-harness baseline move studio/src/motion/game packages/game/src # 2. move the entries
|
|
17
|
+
pnpm exec oxlint && pnpm exec od-harness size # 3. both pass again
|
|
18
|
+
git add -A && git commit # 4. one change: the files and the baselines
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
The command:
|
|
22
|
+
|
|
23
|
+
1. finds every entry under `<from>` in `oxlint-suppressions.json` and `.harness/size-baseline.json` and renames it to the same place under `<to>`;
|
|
24
|
+
2. refuses, and writes nothing, when an old path still exists (move the files first: debt never moves to a file while the old one stays), when a new path does not exist, when a new path already has entries of its own (a move never merges debt into a file), or when git does not see a new file as a rename of its old one (step 3);
|
|
25
|
+
3. checks that every new file is its old file moved, with the condition `ratchet` applies: `git diff -M30% -l0 <ref>` must pair each new file with its old one, over the whole change (git's default 50% similarity lowered to 30%; `-l0` lifts the limit on the number of files git compares, `diff.renameLimit`). `<ref>` is `--base`, by default `HEAD`, so the move must be staged (`git mv`, or `git add` of both paths) and not yet committed; untracked files are not compared. A new file that keeps less than 30% of the old content, or that git pairs with another old file, is not this move: the old debt is gone with the old file, so prune its entries (`oxlint --prune-suppressions`, `od-harness size --update`) and fix the violations of the new file, or split it;
|
|
26
|
+
4. checks that every rule's total in `oxlint-suppressions.json` and the sum of frozen lines in the size baseline are unchanged; the frozen line count of a file moves with it;
|
|
27
|
+
5. writes `oxlint-suppressions.json` the way Oxlint writes it (sorted, so `oxlint --prune-suppressions` leaves it unchanged) and the size baseline the way `od-harness size` writes it. It writes no other file: there is no record of the move besides the renamed entries.
|
|
28
|
+
|
|
29
|
+
`--base <ref>` checks a move that is committed already against the commit before it (for example `--base origin/main`). It is a pre-check only: the gate is `ratchet` against the PR base, which applies the same condition to the whole change.
|
|
30
|
+
|
|
31
|
+
Exit codes: 0 moved, 1 refused (the message says why and what to do), 2 usage error (no baseline here, a path outside the working directory, `<to>` inside `<from>`, an unknown `--base`).
|
|
32
|
+
|
|
33
|
+
Paths are compared with their exact spelling, so a case-only rename (`old.ts` → `Old.ts`) works on file systems that ignore case too.
|
|
34
|
+
|
|
35
|
+
## What `ratchet` accepts
|
|
36
|
+
|
|
37
|
+
`od-harness ratchet` accepts an entry for a file that the base commit does not have only as a move, and only when all of these hold:
|
|
38
|
+
|
|
39
|
+
- git sees the rename between the base and the working tree: `git diff -M30% -l0 <base>` over the whole change, so a file that was moved and also edited counts while it keeps at least 30% of its content, however many files the change moves;
|
|
40
|
+
- the old path had an entry in the same baseline at the base, and no longer exists (spelled exactly so);
|
|
41
|
+
- the moved entry is not larger than the old one, for every rule (suppressions) or in lines (size baseline);
|
|
42
|
+
- each old entry moves to one new file only.
|
|
43
|
+
|
|
44
|
+
Every rule's total must not grow, as for any change. Anything else is still a new file in the baseline and fails: deleting a file with debt and adding an unrelated one is not a move, also not with the owner's approval, and no file in the change can declare one. In the trial directory moves on openmotion and opengame, all 30 and 47 moved entries followed a rename git saw.
|
|
45
|
+
|
|
46
|
+
The 30% threshold: an unrelated file stays near 0%, even one with the same name or the same number of lines; a rewrite that keeps 14 of 40 lines is at 34%.
|
|
47
|
+
|
|
48
|
+
After `baseline move`, `od-harness size` judges a moved file that is over budget by its entry under the new path.
|
|
49
|
+
|
|
50
|
+
## Review
|
|
51
|
+
|
|
52
|
+
A baseline move is reviewed with the change that makes it. No file of its own records the move: `ratchet` accepts moved entries only for renames git sees, whatever a reviewer approves, and lists each one in its output (`baseline entry moved from …`, `frozen size moved from …`). In a repository whose CODEOWNERS covers every path (`* @owner`), the platform owner reviews it like any other change. The baselines themselves stay outside CODEOWNERS otherwise, so that changes that only shrink them need no owner.
|
|
53
|
+
|
|
54
|
+
## More baseline kinds
|
|
55
|
+
|
|
56
|
+
The command handles each baseline kind through one loader that lists its entry paths, renames them, and reports the totals a move must keep (`src/cli/baseline-move.ts`). A future kind, for example per-file stylelint counts, adds a loader there and a matching check in `ratchet`; the command and its refusals stay the same.
|
package/docs/clones.md
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# od-harness clones
|
|
2
|
+
|
|
3
|
+
No new duplicated code. `od-harness clones --base <ref>` runs [jscpd](https://github.com/kucherenko/jscpd) on the working tree and on the base commit (in CI: `"$HARNESS_BASE_REF"`, the PR base) and fails when this change adds a clone. Clones the base already has are tolerated; there is no baseline file to maintain.
|
|
4
|
+
|
|
5
|
+
```text
|
|
6
|
+
od-harness clones --base <ref>
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
Exit codes: 0 no new clone, 1 a new clone (or code hidden from jscpd, below), 2 usage or environment error (an unknown ref, jscpd failed, nothing was scanned).
|
|
10
|
+
|
|
11
|
+
## What counts
|
|
12
|
+
|
|
13
|
+
jscpd 5.4.3 (a dependency of od-harness, pinned) runs with these settings, the ones of the maintainability report openmotion and opengame ran before:
|
|
14
|
+
|
|
15
|
+
| Setting | Value |
|
|
16
|
+
| ------- | --------------------------------------------------------------------------------------------------------------- |
|
|
17
|
+
| formats | `javascript`, `typescript`, `jsx`, `tsx` |
|
|
18
|
+
| mode | `weak` (comments are not compared) |
|
|
19
|
+
| size | at least 12 lines and 80 tokens |
|
|
20
|
+
| ignored | only the globs in `clones.ignore` of `.harness/config.json`; od-harness ignores no path or file name of its own |
|
|
21
|
+
| git | files that `.gitignore` or an `.ignore` file excludes are not scanned (jscpd reads both), also tracked ones |
|
|
22
|
+
|
|
23
|
+
od-harness has no ignore list of its own: without `clones.ignore`, jscpd scans every JavaScript and TypeScript file that git does not ignore, tests, fixtures, generated and vendored code included. A repository lists what the gate does not check in `.harness/config.json`, which the platform owner reviews (CODEOWNERS): a listed path is not checked at all, and the owner decides what is added or removed. Start from the [recommended configuration](adopting.md#3a-configure-the-incremental-checks) (dependencies, built and vendored code, type declarations, minified files, tests, fixtures and mocks, generated code, and the extra globs of the maintainability report's `jscpd.json`).
|
|
24
|
+
|
|
25
|
+
Globs are relative to the directory od-harness runs in. A `.jscpd.json` in the repository is not read; the settings above and `clones.ignore` are the only configuration. `od-harness unused` does not read `clones.ignore`: what knip leaves out is set in the knip configuration ([unused](unused.md)).
|
|
26
|
+
|
|
27
|
+
## How "new" is decided
|
|
28
|
+
|
|
29
|
+
1. jscpd's own comparison (`--baseline-from-ref <base> --fail-on-new-clones 0`): it checks the base commit out in a temporary git worktree, scans it with the same settings and fingerprints every clone by the text of its two fragments. A clone whose fingerprint the base does not have, or has fewer times, is new. Line shifts and renamed files keep a clone's fingerprint.
|
|
30
|
+
2. od-harness then keeps only the new clones that touch lines this change adds or edits (from `git diff --text --find-renames <base>` over the files jscpd scans—the extensions below, and files without them whose first line is a shebang that contains `node`—and the files of new clones; untracked files count whole). `--text` reads every such file as text, so a `-diff` or `binary` attribute in `.gitattributes` does not hide its lines. jscpd pairs the copies of a fragment in scan order, so when a file with three or more copies moves, jscpd can pair the copies differently and report an old clone as new. Such re-paired clones in unchanged code are not counted; the summary says how many there were.
|
|
31
|
+
|
|
32
|
+
Consequences:
|
|
33
|
+
|
|
34
|
+
- Copying a function into a new or existing file fails.
|
|
35
|
+
- Editing code that is already duplicated, even a comment or whitespace inside the copied lines, gives the clone a new fingerprint: it counts as new. Deduplicate it in that change.
|
|
36
|
+
- Moving or renaming files does not create clones.
|
|
37
|
+
|
|
38
|
+
## How to fix a failure
|
|
39
|
+
|
|
40
|
+
The report names both copies (`src/a.ts:10-30 duplicates src/b.ts:5-25 (21 lines)`).
|
|
41
|
+
|
|
42
|
+
- **Fix**: extract the shared code into one function or module and call it from both places. Look for an existing implementation first (the capability index of the repository, if it has one).
|
|
43
|
+
- **Exemption**: generated or vendored code and fixtures are excluded through `clones.ignore` in `.harness/config.json`, which the platform owner reviews (CODEOWNERS).
|
|
44
|
+
- **Not an exemption**: the marker text `jscpd:ignore-start` / `jscpd:ignore-end`. jscpd honours the markers anywhere in a file's text (also in a string or code), so in a file jscpd scans with these formats—one with the extension `.js`, `.jsx`, `.mjs`, `.cjs`, `.es`, `.es6`, `.ts`, `.tsx`, `.mts` or `.cts`, or a file without such an extension whose first line is a shebang that contains `node` (such as `#!/usr/bin/env node`, `#!/usr/bin/node16` or `#!/usr/bin/env nodemon`)—any added or edited line that holds `jscpd:ignore-start` or `jscpd:ignore-end` fails, also a marker moved from elsewhere or an end marker that closes a start the base already has; the report names the files. Markers on lines the change does not touch are left alone.
|
|
45
|
+
- **Not an exemption either**: ignore rules. jscpd skips files that `.gitignore` or an `.ignore` file excludes, even tracked ones (`git add -f`). Among the files with those extensions or such a shebang, `od-harness clones` lists the tracked ones such rules exclude (`git ls-files --cached --ignored`, with `--exclude-standard` and with `--exclude-per-directory=.ignore`) and fails when the change adds or edits one of them, or edits a `.gitignore` or `.ignore` file anywhere in the repository (then every listed file counts, so ignoring the existing copy of a new clone fails too). Fix: change the rule so it no longer matches the file, or add a `!path` exception after it. A rule that excludes a parent directory (`dir/`) cannot be undone with `!path`, because git does not look inside an excluded directory: exclude its contents instead (`dir/*`), then add `!dir/file`. Generated or vendored code goes into `clones.ignore`, and a file listed there is not reported.
|
|
46
|
+
|
|
47
|
+
## Requirements
|
|
48
|
+
|
|
49
|
+
- The base commit must be in the clone: `gates.yml` checks out with `fetch-depth: 0`. A missing base is a usage error (exit 2), never a pass.
|
|
50
|
+
- jscpd adds a temporary git worktree to the repository during the run and removes it afterwards.
|
|
51
|
+
- jscpd ships prebuilt binaries for Linux, macOS and Windows (x64, arm64) as optional dependencies; npm and pnpm install the one for the platform.
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# 0003: One agent harness for Claude Code, Codex and Antigravity
|
|
2
|
+
|
|
3
|
+
- Status: Proposed. The platform owner decided the points below on 2026-12-04; this record lands with A4-1a and becomes Accepted when it merges.
|
|
4
|
+
- Scope: the hook program, the agent configuration that `od-harness init` generates, the managed block in `AGENTS.md`, and the skills that `init` installs.
|
|
5
|
+
- Evidence: live-machine probe G2 (`claude` 2.1.332, `agy` 1.5.21, `codex-cli` 0.171.0-alpha.13.2 static checks and `hooks/list`; Codex interactive hook trust pending live verification), 2026-12-04.
|
|
6
|
+
|
|
7
|
+
## Context
|
|
8
|
+
|
|
9
|
+
OpenDesign repositories are worked on with three coding agents: Claude Code, the OpenAI Codex CLI and the Google Antigravity CLI (`agy`). They differ in instruction files, hook events, decisions a hook can return, trust models and skill locations; [`docs/hooks.md`](../hooks.md) keeps the capability matrix with sources and empirical status. The only merge gate is CI (`harness-gates`). Agent-side guards give feedback earlier and stop the commands that CI cannot undo: bypassing git hooks, pushing to protected branches, publishing, rewriting baselines, destroying local work.
|
|
10
|
+
|
|
11
|
+
## Decision
|
|
12
|
+
|
|
13
|
+
1. **One hook program.** The package ships one hook entry, `@opendesignai/harness/hook`, called with `<agent> <event>`. `od-harness init` writes each agent's configuration into the repository only and never touches user-level settings. Every agent uses what it supports; CI alone decides whether a change merges. Each agent must at least deny the dangerous commands, run `od-harness verify --quick` before it stops, and keep its instruction chain within the size limits.
|
|
14
|
+
2. **Data-driven lists and zero-dependency parser.** The deny and ask lists, the gate files and the protected branches are data shared with `verify`. Integration branches (`main`, `master`, `release/*`, `cloud/main`, plus configurable `hooks.integrationBranches`, defaulting to `["pilot/mfe"]`) deny any push; other `pilot/*` branches ask (or degrade per agent) on ordinary pushes and deny force pushes, `+refspec` pushes and deletions. Shell commands are read by od-harness's own zero-dependency POSIX sh parser, not by `shell-quote`: it splits compound commands, unwraps wrappers, `bash -c`, `eval`, subshells, command substitutions and here-docs fed to shells, and checks redirection and write targets. When it cannot resolve a command, it matches keywords and denies on a deny keyword. Where an agent cannot ask reliably (Codex does not support `ask` on `PreToolUse`; Antigravity runs `ask` and `force_ask` calls unasked under `always-proceed`), the lists specify per agent whether such a call is denied or allowed with a notice.
|
|
15
|
+
3. **Fail closed on PreToolUse, except when the harness is missing.** A `PreToolUse` hook (`pre-bash`, `pre-edit`) that fails for any reason (exception, bad or oversize stdin, missing configuration, missing external tool, its own deadline) denies the call, and Claude Code `PreToolUse` hooks set `onFailure: "block"` so that a hook which cannot start blocks as well. Antigravity `PreToolUse` always emits an explicit `decision` (`"allow"` or `"deny"`), never `{}`. The one exception is a missing package, as in a fresh clone before `npm ci` / `pnpm install --frozen-lockfile`: Antigravity, and Claude Code with `onFailure: "block"`, would otherwise block every command, including the install. In that case the launcher (A4-1b) allows the call and reports that hooks are inactive; `node_modules/@opendesignai/harness/**` is classified as a D-class protected path, uninstalling `@opendesignai/harness` is denied, and removing `node_modules` recursively asks on Claude Code and denies on Codex and Antigravity. `Stop`, `PostToolUse`, `PreInvocation` and `SessionStart` hooks never block because of their own errors; they allow and emit a visible notice, so an agent is never trapped in a loop.
|
|
16
|
+
4. **Codex.** `.codex/hooks.json` holds one entry per event. Codex hashes each hook's command with its arguments, timeout, status message and matcher, but not the script contents, and keys the trust by the file's absolute path and the entry's position. Upgrading the harness therefore asks for no new trust as long as those fields and the order of the entries stay the same, so they are fixed before the first release that generates them. Codex skips a hook nobody has trusted without saying so; `od-harness doctor` reports the trust status. `.codex/rules/od-harness.rules` is generated by default: `git push` and `gh pr merge` prompt; `git reset --hard`, `git clean -f…` and `rm -rf .git` are forbidden, and the hook denies them as well, since prefix rules only see an argv prefix. Codex hook runtime behavior is implemented from official documentation and remains pending live-machine verification after interactive hook trust.
|
|
17
|
+
5. **Skills.** `.agents/skills/od-*/` is the canonical copy (`SKILL.md` and `references/`), read by Codex and agy. Claude Code reads nothing under `.agents/` (Claude Code 2.1.332), so `init` also writes `.claude/skills/od-*/SKILL.md`: a byte-identical copy of `SKILL.md` only. `references/` is not copied; `SKILL.md` links to its references by their `.agents/skills/od-*/references/…` path, which resolves from both copies. Both copies are committed, `init --check` keeps them identical to the installed package, and `.gitattributes` marks both `linguist-generated=true`. Generated hook and rule files are not marked, so their diffs stay expanded in review.
|
|
18
|
+
6. **No git hooks.** Agent hooks block bypassing existing local git hooks (`--no-verify`, `core.hooksPath`, `GIT_CONFIG_*`), but A4 does not install git hooks.
|
|
19
|
+
|
|
20
|
+
## Removing the Claude Code copy
|
|
21
|
+
|
|
22
|
+
The copy under `.claude/skills/` exists only because Claude Code does not read `.agents/skills/`. When Claude Code documents `.agents/skills/` as a skills location and the oldest Claude Code version od-harness supports reads it:
|
|
23
|
+
|
|
24
|
+
- the next od-harness minor release stops generating `.claude/skills/od-*` and states that Claude Code version in its release notes;
|
|
25
|
+
- `od-harness init` and `od-harness agents sync` delete each `.claude/skills/od-*` directory whose `SKILL.md` carries `metadata.generated-by: od-harness@…`, never any other directory, and remove the `.gitattributes` lines they added;
|
|
26
|
+
- `init --check` fails while such a directory remains, so a consumer removes it in the change that upgrades the harness;
|
|
27
|
+
- this record is updated with the Claude Code version and the od-harness release.
|
|
28
|
+
|
|
29
|
+
Checking the trigger is an item on the od-harness release checklist.
|
|
30
|
+
|
|
31
|
+
## Consequences
|
|
32
|
+
|
|
33
|
+
- Upgrading the harness changes behaviour without new Codex trust prompts. Review of `package.json`, the lockfile and exact version pins (CODEOWNERS), npm provenance, and a CI check that rejects `file:`, `link:` and git sources for the harness make up for trust that does not cover script content.
|
|
34
|
+
- Generated agent configuration can run commands on a teammate's machine, so `.claude/`, `.codex/`, `.agents/` (hooks, rules, plugins, `od-*` skills), `.gitattributes` and the instruction files are owned in CODEOWNERS, and the protected branches require code owner review.
|
|
35
|
+
- **Claude Code must be started from the repository root.** Claude Code reads the committed `.claude/settings.json` only from the directory it starts in; started in a subdirectory, it runs none of these hooks and ignores `permissions.deny`. `od-harness` does not generate `.claude/settings.local.json` (`--local` is not implemented); the managed block in `AGENTS.md` and `docs/hooks.md` document this requirement, and CI still checks every change.
|
|
36
|
+
- Claude Code users get the skills a release later than they could if symbolic links worked everywhere; a committed symbolic link becomes a text file on a default Windows checkout.
|
|
37
|
+
- An agent without hooks, or a person, is checked only by CI.
|
package/docs/hooks.md
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
# od-harness hooks
|
|
2
|
+
|
|
3
|
+
Pure stateless hook policy engine, zero-dependency POSIX shell analyzer, three-agent payload adapters, and fail-closed / fail-open runner (`src/hook/**`, A4-1a).
|
|
4
|
+
|
|
5
|
+
CI (`harness-gates`) remains the sole merge gate. Agent-side hooks provide immediate feedback and stop commands that CI cannot undo: bypassing git hooks, pushing to integration branches, publishing packages, rewriting baselines, or destroying local work.
|
|
6
|
+
|
|
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
|
+
|
|
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. |
|
|
15
|
+
|
|
16
|
+
## Three-agent capability and verification matrix
|
|
17
|
+
|
|
18
|
+
| Capability | Claude Code (`cc`, 2.1.332 — G2 verified) | Antigravity (`agy`, 1.5.21 — G2 verified) | Codex (`codex`, 0.171 — **pending live-machine verification**) |
|
|
19
|
+
| ----------------------------- | -------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
20
|
+
| `PreToolUse` shell tool | `Bash` (`tool_input.command`) | `run_command` (`toolCall.args.CommandLine`) | `Bash` (`tool_input.command`) _(per official docs)_ |
|
|
21
|
+
| `PreToolUse` edit tools | `Edit`, `Write`, `NotebookEdit` | `write_file`, `edit_file` | `apply_patch` (`tool_input.command`) _(per official docs)_ |
|
|
22
|
+
| Compound command delivery | Single full command string | Single full command string | Single full command string _(per official docs)_ |
|
|
23
|
+
| `PreToolUse` allow output | Empty stdout, exit 0 | Explicit `{"decision":"allow"}` (**never** `{}` — G2 proved `{}` denies with empty reason) | Empty stdout, exit 0 _(per official docs)_ |
|
|
24
|
+
| `PreToolUse` deny output | `hookSpecificOutput.permissionDecision: "deny"` | `{"decision":"deny","reason":"…"}` | `hookSpecificOutput.permissionDecision: "deny"` _(per official docs)_ |
|
|
25
|
+
| `PreToolUse` `ask` support | Supported (`permissionDecision: "ask"`) | **Not emitted.** G2 proved `ask`/`force_ask` auto-allow under `always-proceed` and `force_ask` aborts headless `request-review`. Degraded per rule table (`deny` or `allow` + `reason`). | **Not emitted.** Official docs state `permissionDecision: "ask"` marks the hook failed and continues the tool call. Degraded per rule table (`deny` or `allow-with-notice` via `systemMessage` + `additionalContext`). |
|
|
26
|
+
| `PreToolUse` failure behavior | Default fail-open; `onFailure: "block"` blocks on crash/timeout (verified). Script wraps in `try/catch` → deny JSON. | Runtime itself fails closed on exit≠0, exception, timeout, bad JSON, or `{}`. Script wraps in `try/catch` → explicit deny JSON with readable reason. | `onFailure` unsupported on 0.171; script `try/catch` → deny JSON is the primary guard _(runtime failure behavior pending live verification)_. |
|
|
27
|
+
| `Stop` loop-guard field | `stop_hook_active` (verified) | `executionNum > 0` (**not** `continuationActive`, which G2 showed remains `false` on continuation) | `stop_hook_active` _(per official docs; pending live verification)_ |
|
|
28
|
+
| `Stop` block output | `{"decision":"block","reason":"…"}` | `{"decision":"continue","reason":"…"}` | `{"decision":"block","reason":"…"}` _(per official docs)_ |
|
|
29
|
+
| `PostToolUse` feedback | `systemMessage` + `additionalContext` | `overwriteResult` (G2 proved payload includes original `result`) | `systemMessage` + `additionalContext` _(per official docs)_ |
|
|
30
|
+
| Subdirectory startup | `.claude/settings.json` **not loaded** (must start at repo root) | Loads root `.agents/hooks.json`; hook process cwd is `<repo>/.agents` | _Pending live verification_; `hooks/list` shows linked worktrees share primary checkout `.codex/hooks.json` |
|
|
31
|
+
|
|
32
|
+
## Protected branches and tags
|
|
33
|
+
|
|
34
|
+
- **Integration branches (any push denied across all agents):**
|
|
35
|
+
- Built-in: `main`, `master`, `release/*`, `cloud/main`.
|
|
36
|
+
- Configurable: `hooks.integrationBranches`, which defaults to `["pilot/mfe"]`.
|
|
37
|
+
- **Other `pilot/*` branches (two-tier policy):**
|
|
38
|
+
- Ordinary push (e.g. `git push origin pilot/b3-ts7`): `ask` on Claude Code, `allow-with-notice` on Codex (paired with `.codex/rules/od-harness.rules` `prompt`) and Antigravity.
|
|
39
|
+
- Force push (`-f`, `--force`, `--force-with-lease`, `+refspec`) or deletion (`--delete`, `-d`, `:pilot/...`): `deny` across all three agents.
|
|
40
|
+
- **Release tags (`v*`):** Pushing or deleting `refs/tags/v*` or `v<digit>*`, and `git tag -f v*` / `git tag -d v*`, are `deny` across all three agents. Ordinary branches starting with `v` (e.g. `verify-fix`) are not treated as tags.
|
|
41
|
+
|
|
42
|
+
## Protected files
|
|
43
|
+
|
|
44
|
+
Paths are normalized (POSIX `/` and Windows `\` separators, `.` and `..` resolution, case-insensitive comparison on `darwin` and `win32`) against realpath-resolved `repoRoot` and `cwd` supplied by the caller.
|
|
45
|
+
|
|
46
|
+
### D-class (denied through every channel: shell and edit tools)
|
|
47
|
+
|
|
48
|
+
- Lint & size baselines: `oxlint-suppressions.json`, `.harness/size-baseline.json`
|
|
49
|
+
- 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
|
+
- Git internals: `.git/**` (and `.git`)
|
|
51
|
+
- Installed harness package: `node_modules/@opendesignai/harness/**` (and nested `**/node_modules/@opendesignai/harness/**`)
|
|
52
|
+
- Optional repository additions: `hooks.denyFiles`
|
|
53
|
+
|
|
54
|
+
### G-class (edit tools: `ask` on Claude Code, `allow-with-notice` on Codex & Antigravity; shell writes: `deny` on all agents)
|
|
55
|
+
|
|
56
|
+
- `.oxlintrc.json`, `.harness/config.json`, knip configuration (`knip.json`, `knip.config.*`, etc.)
|
|
57
|
+
- `.github/**`
|
|
58
|
+
- `package.json`, lockfiles (`package-lock.json`, `pnpm-lock.yaml`, `yarn.lock`, `bun.lock`, `bun.lockb`), `pnpm-workspace.yaml`
|
|
59
|
+
- `.gitattributes`
|
|
60
|
+
- `.claude/settings.json`, `.claude/settings.local.json`, `.agents/plugins/**`
|
|
61
|
+
- `AGENTS.md` (for edit tools, gated **only** when the edit touches `<!-- od-harness:begin … -->` / `<!-- od-harness:end -->` or overwrites the whole file; shell writes to `AGENTS.md` are always denied)
|
|
62
|
+
- Repository additions in `hooks.gateFiles`
|
|
63
|
+
|
|
64
|
+
### Explicit allowlist
|
|
65
|
+
|
|
66
|
+
- `oxlint --prune-suppressions` (unless combined with `--suppress*`)
|
|
67
|
+
- `od-harness size --update`
|
|
68
|
+
- `od-harness baseline move`
|
|
69
|
+
- `npm ci`
|
|
70
|
+
- `pnpm install --frozen-lockfile` / `pnpm i --frozen-lockfile`
|
|
71
|
+
|
|
72
|
+
## Complete rule matrix
|
|
73
|
+
|
|
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` |
|
|
100
|
+
|
|
101
|
+
## Shell parser and opaque fallback
|
|
102
|
+
|
|
103
|
+
`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
|
+
|
|
105
|
+
- **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`.
|
|
108
|
+
- **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`).
|
|
110
|
+
|
|
111
|
+
## Fail-closed and fail-open error contract (`defineHook`)
|
|
112
|
+
|
|
113
|
+
All handlers are registered through `defineHook()` in `src/hook/define.ts`:
|
|
114
|
+
|
|
115
|
+
- **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
|
+
- **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
|
+
- **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.
|
|
118
|
+
- **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
|
+
|
|
120
|
+
## Items pending Codex live-machine verification
|
|
121
|
+
|
|
122
|
+
During G2 (`codex-cli 0.171.0-alpha.13.2`), non-interactive `codex exec` cannot grant per-hook trust (project hooks remain `untrusted` and are silently skipped until approved in the interactive `/hooks` TUI). The Codex adapter in `src/hook/adapters/` is therefore implemented from official documentation (`codex_hooks.md`) and requires live-machine verification (G2 §6.1 & §2.3) for:
|
|
123
|
+
|
|
124
|
+
1. Exact `PreToolUse` / `PostToolUse` / `Stop` / `SessionStart` stdin payload field names and `cwd` behavior in root and subdirectory sessions.
|
|
125
|
+
2. Whether `PreToolUse` runtime errors (exit 1, uncaught exception, timeout, malformed JSON) fail open as documented.
|
|
126
|
+
3. Confirmation that `apply_patch` delivers patch text in `tool_input.command` and honors `permissionDecision: "deny"` and `additionalContext`.
|
|
127
|
+
4. `Stop` continuation behavior (`stop_hook_active` transition and `decision: "block"`).
|
|
128
|
+
5. Live session behavior of `.codex/rules/od-harness.rules` (`prompt` / `forbidden`) under `danger-full-access` + `approval_policy=never` vs `workspace-write` + `on-request`.
|