@opendesignai/harness 0.0.0-stage → 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/LICENSE +201 -0
- package/README.md +132 -2
- package/dist/cli.d.mts +1 -0
- package/dist/cli.mjs +1723 -0
- package/dist/eslint-comments.d.mts +40 -0
- package/dist/eslint-comments.mjs +182 -0
- package/dist/paths-DBoYPrGy.mjs +59 -0
- package/dist/plugin.d.mts +41 -0
- package/dist/plugin.mjs +1410 -0
- package/docs/adopting.md +224 -0
- package/docs/baseline-move.md +56 -0
- package/docs/clones.md +51 -0
- package/docs/decisions/0001-oxlint.md +74 -0
- package/docs/decisions/0002-react-compiler-rules.md +34 -0
- package/docs/decisions/0003-agent-harness.md +37 -0
- package/docs/hooks.md +128 -0
- package/docs/ratchet.md +65 -0
- package/docs/rules/no-api-path-literal.md +35 -0
- package/docs/rules/no-cjk-literal.md +38 -0
- package/docs/rules/no-constant-flag.md +33 -0
- package/docs/rules/no-error-message-match.md +63 -0
- package/docs/rules/no-locale-branch.md +55 -0
- package/docs/rules/no-process-env.md +37 -0
- package/docs/rules/no-product-literal.md +41 -0
- package/docs/rules/no-raw-fetch.md +33 -0
- package/docs/rules/no-raw-storage.md +43 -0
- package/docs/rules/no-shell-imports-product.md +48 -0
- package/docs/rules/no-swallowed-catch.md +76 -0
- package/docs/rules/no-window-bus.md +35 -0
- package/docs/size.md +52 -0
- package/docs/unused.md +76 -0
- package/package.json +75 -3
- package/presets/base.json +7 -0
- package/presets/platform-boundary.json +4 -0
- package/presets/product.json +4 -0
- package/presets/react-compiler.json +13 -0
- package/presets/rules/base.json +49 -0
- package/presets/rules/platform-boundary.json +6 -0
- package/presets/rules/product.json +5 -0
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`.
|
package/docs/ratchet.md
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# od-harness ratchet
|
|
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).
|
|
4
|
+
|
|
5
|
+
It fails when:
|
|
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. |
|
|
15
|
+
|
|
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
|
+
|
|
18
|
+
Paths are read relative to the directory `ratchet` runs in, both in the working tree and at the base commit, so it works from a `working-directory` inside a larger repository. `package.json` is read there too, so the adoption change adds `@opendesignai/harness` to the `package.json` of that directory (the `working-directory` of `gates.yml`, which also holds the lockfile).
|
|
19
|
+
|
|
20
|
+
## Moved files
|
|
21
|
+
|
|
22
|
+
Entries may follow a file to a new path; [`od-harness baseline move`](baseline-move.md) rewrites them. `ratchet` accepts an entry for a path the base does not have as a move only when:
|
|
23
|
+
|
|
24
|
+
- git sees the rename between the base and the working tree: `git diff -M30% -l0 <base>`, over the whole change, at 30% similarity or more (below git's default of 50%, so a file that was also edited still counts) and without git's limit on the number of files it compares (`diff.renameLimit`). Nothing else makes a file a move: an unrelated new file never takes over the debt of a deleted one;
|
|
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
|
+
- 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
|
+
|
|
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.
|
|
29
|
+
|
|
30
|
+
## Why a config or version change admits new rule IDs
|
|
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.
|
|
37
|
+
|
|
38
|
+
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
|
+
|
|
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:
|
|
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.
|
|
44
|
+
|
|
45
|
+
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
|
+
|
|
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.
|
|
48
|
+
|
|
49
|
+
## Options
|
|
50
|
+
|
|
51
|
+
```text
|
|
52
|
+
--base <ref> required; any commit-ish (sha, branch, tag)
|
|
53
|
+
--suppressions <path> default: oxlint-suppressions.json
|
|
54
|
+
--lint-config <path> default: .oxlintrc.json
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Exit codes: 0 pass, 1 a check failed, 2 usage error (for example an unknown ref; check out with `fetch-depth: 0`).
|
|
58
|
+
|
|
59
|
+
## How to fix a failure
|
|
60
|
+
|
|
61
|
+
- **A rule's total grew**: restore `oxlint-suppressions.json` from the base, fix the violations Oxlint reports, then run `oxlint --prune-suppressions` (it can only shrink the file). Never run `oxlint --suppress-all` to get a change through.
|
|
62
|
+
- **Stale entry**: run `oxlint --prune-suppressions` or `od-harness size --update`.
|
|
63
|
+
- **New file in the baseline**: restore the entries from the base, fix the violations in the new file, then run `oxlint --prune-suppressions`. For a moved file, run `od-harness baseline move <old path> <new path>` instead; if the move is not accepted, the message names the condition that failed.
|
|
64
|
+
- **New baseline file**: delete it and fix what `oxlint` or `od-harness size` reports. `oxlint --suppress-all` and `od-harness size --init` are for the adoption change only.
|
|
65
|
+
- **Size baseline loosened**: restore the entry and move code out of the file.
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# od/no-api-path-literal
|
|
2
|
+
|
|
3
|
+
Preset: `base`
|
|
4
|
+
|
|
5
|
+
## What it reports
|
|
6
|
+
|
|
7
|
+
String literals, template literals (by their first fixed part) and JSX attribute strings that start with an API path prefix:
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
const url = "/motion-api/games/" + id;
|
|
11
|
+
const play = `/motion-api/games/${id}/play/index.html`;
|
|
12
|
+
path.replace(/^\/api\//, "/motion-api/");
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
The bare prefix (`"/api"`) also counts. Module specifiers, type-only literals (including the type of `x as …` and `x satisfies …`), literals in ambient declarations (`declare …`, which emit no code) and regular expressions are not reported.
|
|
16
|
+
|
|
17
|
+
## Why
|
|
18
|
+
|
|
19
|
+
Hand-written API paths scatter knowledge of the backend layout across the UI. When a prefix or parameter changes (`rev`, `gameStartup`), every copy has to be found by hand; `'/motion-api/'` literals outside the client went from 33 to 73 in opengame.
|
|
20
|
+
|
|
21
|
+
## How to fix
|
|
22
|
+
|
|
23
|
+
Build URLs with a helper in the API client (add one if missing) and call the helper.
|
|
24
|
+
|
|
25
|
+
## Exemptions
|
|
26
|
+
|
|
27
|
+
The API client layer, and server code that defines the routes, are exempted with an `overrides` entry in the lint config (owner review). Inline disable comments are rejected; existing debt stays in `oxlint-suppressions.json` and may only shrink.
|
|
28
|
+
|
|
29
|
+
## Options
|
|
30
|
+
|
|
31
|
+
```json
|
|
32
|
+
["error", { "prefixes": ["/api/", "/motion-api/"], "client": "studio/src/api" }]
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
`prefixes` defaults to the value shown; `client` only changes the message text.
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# od/no-cjk-literal
|
|
2
|
+
|
|
3
|
+
Preset: `base`
|
|
4
|
+
|
|
5
|
+
## What it reports
|
|
6
|
+
|
|
7
|
+
String literals, template literals and JSX text that contain Chinese, Japanese or Korean characters (Han, Hiragana, Katakana, Hangul):
|
|
8
|
+
|
|
9
|
+
```tsx
|
|
10
|
+
const title = "标题";
|
|
11
|
+
throw new Error("请求失败");
|
|
12
|
+
return <span>中文</span>;
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Comments, module specifiers and type-only literals (including the type of `x as { "标题"(): void }` and `satisfies`) are not reported, nor are literals in ambient declarations (`declare const`, `declare class`, `declare module`, `declare global`), which emit no code. CJK punctuation alone (`,。`) is not reported.
|
|
16
|
+
|
|
17
|
+
## Why
|
|
18
|
+
|
|
19
|
+
Copy hard-coded in source skips translation review and cannot follow the user's locale; logs and errors in Chinese are unreadable for part of the team and for most tooling. opengame had 1,597 such literals.
|
|
20
|
+
|
|
21
|
+
## How to fix
|
|
22
|
+
|
|
23
|
+
Move user-facing copy into the i18n catalog (every supported locale) and render it with `t("<key>")`. Write logs, error messages and identifiers in English.
|
|
24
|
+
|
|
25
|
+
## Exemptions
|
|
26
|
+
|
|
27
|
+
Tests and fixtures are excluded by the base preset: `**/*.test.*`, `**/*.spec.*`, `**/__tests__/**`, `**/__fixtures__/**` and `**/fixtures/**`. i18n catalogs differ per repository, so each repository excludes its own in the lint config (`ignorePatterns` or an `overrides` entry, owner review), as do test helpers outside those patterns. Inline disable comments are rejected; existing debt stays in `oxlint-suppressions.json` and may only shrink.
|
|
28
|
+
|
|
29
|
+
## Options
|
|
30
|
+
|
|
31
|
+
```json
|
|
32
|
+
[
|
|
33
|
+
"error",
|
|
34
|
+
{ "pattern": "[\\p{Script=Han}\\p{Script=Hiragana}\\p{Script=Katakana}\\p{Script=Hangul}]" }
|
|
35
|
+
]
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
`pattern` is a regular expression evaluated with the `u` flag.
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# od/no-constant-flag
|
|
2
|
+
|
|
3
|
+
Preset: `base`
|
|
4
|
+
|
|
5
|
+
## What it reports
|
|
6
|
+
|
|
7
|
+
A module-level `const` whose name reads like a feature toggle and whose value is a boolean literal (`true`, `false`, `!0`, `!1`, optionally `as const`):
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
const trailersEnabled = false;
|
|
11
|
+
export const SHOW_STARTER_GIFT_BAR = true;
|
|
12
|
+
const NEW_NAV_ENABLED = !0;
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Default name pattern: `…Enabled`, `…Disabled`, `…Flag`, `…_ENABLED`, `…_DISABLED`, `…_FLAG`, `ENABLE_…`, `DISABLE_…`, `FEATURE_…`, `FF_…`, `SHOW_…`, `HIDE_…`, `USE_…`, `enable…`, `disable…`, `show…`, `hide…`. `let` declarations and constants inside functions are not reported.
|
|
16
|
+
|
|
17
|
+
## Why
|
|
18
|
+
|
|
19
|
+
A hard-coded toggle has no owner or expiry, cannot be switched per environment, and its dead branch stays in the bundle. New entries and replaced navigation items should go through the flag registry instead.
|
|
20
|
+
|
|
21
|
+
## How to fix
|
|
22
|
+
|
|
23
|
+
Register the flag in the feature-flag registry (owner, expiry date, default off) and read it from there. If the decision is final, delete the constant and the branch it guards.
|
|
24
|
+
|
|
25
|
+
## Exemptions
|
|
26
|
+
|
|
27
|
+
None inline: disable comments are rejected. A constant that is not a toggle should be renamed so it does not read like one. The rule has almost no existing debt (one or two hits per repository), so it is meant to block from day one.
|
|
28
|
+
|
|
29
|
+
## Options
|
|
30
|
+
|
|
31
|
+
```json
|
|
32
|
+
["error", { "pattern": "<regular expression for the name, anchored automatically>" }]
|
|
33
|
+
```
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# od/no-error-message-match
|
|
2
|
+
|
|
3
|
+
Preset: `base`
|
|
4
|
+
|
|
5
|
+
## What it reports
|
|
6
|
+
|
|
7
|
+
Decisions that depend on the wording of an error message:
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
if (msg.includes("timed out")) …
|
|
11
|
+
if (err.message.startsWith("fetch failed")) …
|
|
12
|
+
if (/socket hang up/i.test(err.message)) …
|
|
13
|
+
if (error.message === "Not found") …
|
|
14
|
+
const lower = String(error).toLowerCase();
|
|
15
|
+
if (lower.includes("econnreset")) …
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
An expression holds error message text when it is:
|
|
19
|
+
|
|
20
|
+
- a `.message` member (`err.message`, `error?.message`);
|
|
21
|
+
- an identifier matching `identifierPattern` (default, case-insensitive: `msg`, `errMsg`, `errorMessage`, `errText`, `errorText`, …);
|
|
22
|
+
- `String(e)` where `e` matches `errorPattern` (default `e`, `err`, `error`, `ex`, `exc`, `exception`, `cause`);
|
|
23
|
+
- a call to a function named like a message getter (`getErrorMessage(e)`, `archiveErrorMessage(error)`, `errorText(err)`);
|
|
24
|
+
- `toLowerCase()` / `trim()` / similar on any of the above, `x ?? ""`, or a conditional with such a branch;
|
|
25
|
+
- unless `trackAliases` is `false`, an alias in the same file:
|
|
26
|
+
- a variable initialised from any of the above, in any order (`const lower = text.toLowerCase()` may come before `const text = err.message`);
|
|
27
|
+
- a parameter of a same-file function that some call passes message text to (`isOutage(lower)` makes `lower` in `function isOutage(lower: string)` message text);
|
|
28
|
+
- a destructured field with the name of such a variable **only** when it is destructured from a call that receives an `errorPattern` identifier (`const { text } = errorFields(e)` when the file has `const text = err.message`); destructuring from unrelated objects (`const { text } = labels`) and imported bindings never fall back by name.
|
|
29
|
+
|
|
30
|
+
Aliases follow scopes: a variable declared with something else (`const lower = name.toLowerCase()` in another function) is not message text because another variable of that name is, and neither is a parameter that no call passes message text to.
|
|
31
|
+
|
|
32
|
+
Reported: `includes` / `startsWith` / `endsWith` / `indexOf` / `match` / `search` with a string or regex literal, `regex.test(message)`, and equality with a non-empty string literal. Equality with `""` (`guard.message !== ""`, `x.message === ''`) checks whether there is a message, not its wording, and is not reported.
|
|
33
|
+
|
|
34
|
+
A `.message` member counts whatever its object is called. Error text travels as `failure.message`, `detail.message`, `event.message` (an `ErrorEvent`) or `normalized.message`; limiting the rule to `catch` parameters and `errorPattern` names would silently stop reporting those.
|
|
35
|
+
|
|
36
|
+
## Why
|
|
37
|
+
|
|
38
|
+
The producer of the error does not know anyone depends on its wording. When it is reworded the branch, or the telemetry attribution built on it, silently stops matching. opengame's `tracking/tool-fields.ts` alone attributes errors through 121 such `includes` calls on gateway error text.
|
|
39
|
+
|
|
40
|
+
## How to fix
|
|
41
|
+
|
|
42
|
+
Give the error a stable machine-readable signal at the source (an error `code`, a typed error class checked with `instanceof`, or a structured result) and branch on that.
|
|
43
|
+
|
|
44
|
+
## Exemptions
|
|
45
|
+
|
|
46
|
+
Adapters for third-party errors that expose nothing but text belong in one module that maps them to codes; that module is exempted with an `overrides` entry in the lint config (owner review). Inline disable comments are rejected; existing debt stays in `oxlint-suppressions.json` and may only shrink.
|
|
47
|
+
|
|
48
|
+
## Options
|
|
49
|
+
|
|
50
|
+
```json
|
|
51
|
+
[
|
|
52
|
+
"error",
|
|
53
|
+
{
|
|
54
|
+
"identifierPattern": "^(?:msg|err(?:or)?_?(?:msg|message|text))$",
|
|
55
|
+
"errorPattern": "^(?:e|err|error|ex|exc|exception|cause)$",
|
|
56
|
+
"trackAliases": true
|
|
57
|
+
}
|
|
58
|
+
]
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Limits
|
|
62
|
+
|
|
63
|
+
The rule has no type information, so a `message` field of an object that is not an error is still reported when compared with a non-empty string (`prompt.message === "Save?"`). A plain `message` or `text` identifier is not treated as error text unless it is assigned from one (chat messages are common). Alias tracking is per file and follows scopes, falling back by name only for fields destructured from a call passed an `errorPattern` identifier.
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# od/no-locale-branch
|
|
2
|
+
|
|
3
|
+
Preset: `base`
|
|
4
|
+
|
|
5
|
+
## What it reports
|
|
6
|
+
|
|
7
|
+
A conditional (`? :` or `if`) whose test is derived from the locale and where either branch contains non-empty copy (a string literal, a template literal or JSX text):
|
|
8
|
+
|
|
9
|
+
```tsx
|
|
10
|
+
const title = isZh ? "标题" : "Title";
|
|
11
|
+
const greeting = locale === "zh-CN" ? `你好 ${name}` : `Hello ${name}`;
|
|
12
|
+
if (useI18n().locale.startsWith("zh")) { … "…" … }
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
"Derived from the locale" means, looking through `!`, `&&`, `||`, parentheses and TypeScript wrappers:
|
|
16
|
+
|
|
17
|
+
1. an identifier matching `aliasPattern` (default `^is(Zh|Chinese|Cn|CN|En|English)$`);
|
|
18
|
+
2. an equality comparison between a value that mentions `locale` (an identifier or a `.locale` member such as `useI18n().locale`) and a fixed value: a literal, a template without expressions, a constant name (`DEFAULT_LOCALE`, `Locale.ZhCN`), an imported binding or member on one (`zhCN`, `locales.zhCN`), or a same-file `const` bound to a string;
|
|
19
|
+
3. `startsWith` / `endsWith` / `includes` matching the locale with something fixed: such a value matched against a fixed value (`locale.startsWith("zh")`, `locale.startsWith(ZH_PREFIX)`), or looked up in a list that can be read in the file (`["zh-CN", "zh-TW"].includes(locale)`, `"zh-CN,zh-TW".includes(locale)`, or a same-file `const` bound to either);
|
|
20
|
+
4. a same-file `const`/`let` alias of any of the above (`const zh = locale.startsWith("zh")`, declared before or after its use), unless `trackAliases` is `false`. Aliases follow scopes: a same-named variable in another function, or a parameter that shadows the alias, is not the alias.
|
|
21
|
+
|
|
22
|
+
A bare mention such as `/^zh/.test(locale)` does not count, nor does comparing two local/parameter values that are not fixed (`next === locale`, `value !== locale`, `locale === settings.locale`): that asks whether they are the same locale, whatever it is, and picks no language.
|
|
23
|
+
|
|
24
|
+
The same holds for matching (3): `supported.includes(locale)`, `SUPPORTED_LOCALES.includes(locale)` (an imported or computed list, whose content the rule cannot read), `locale.startsWith(prefix)`, `path.endsWith(locale)` and a template with expressions are not reported. Nor are comparisons that do not ask which locale it is: its type or length (`typeof locale === "string"`, `locale.length === 2`), whether there is one (`locale === ""`, `locale != null`; a call compared with `null`, such as `locale.match(/^zh/) !== null`, still counts), and a position in a list that cannot be read (`supported.indexOf(locale) === 0`).
|
|
25
|
+
|
|
26
|
+
Comparing with **any** imported value (or member on an imported binding) counts as a locale branch—even if the import holds a mutable value such as `currentLocale`—because copy should come from the i18n catalog (`t()`) or a locale-keyed table rather than a branch on locale.
|
|
27
|
+
|
|
28
|
+
## Why
|
|
29
|
+
|
|
30
|
+
Branching on the locale hard-codes one translation per branch, skips translation review and breaks as soon as a third locale exists. The `isZh` alias is the main way around name-based checks (zh branches grew from 59 to 1,023 after the switch), which is why aliases are tracked.
|
|
31
|
+
|
|
32
|
+
## How to fix
|
|
33
|
+
|
|
34
|
+
Move the copy into the i18n catalog for every supported locale and render it with `t()`:
|
|
35
|
+
|
|
36
|
+
```tsx
|
|
37
|
+
const { t } = useI18n();
|
|
38
|
+
const title = t("studio.header.title");
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Values that are not copy (URLs, number formats) go into a locale-keyed table read by key, not into a branch.
|
|
42
|
+
|
|
43
|
+
## Exemptions
|
|
44
|
+
|
|
45
|
+
Inline `eslint-disable` / `oxlint-disable` comments for `od/*` rules are rejected by `eslint-comments/no-restricted-disable`. Existing debt is recorded in `oxlint-suppressions.json` when the repository adopts the rule and may only shrink. A file that legitimately needs locale branches is exempted with an `overrides` entry in the lint config, which the owner reviews.
|
|
46
|
+
|
|
47
|
+
## Options
|
|
48
|
+
|
|
49
|
+
```json
|
|
50
|
+
["error", { "trackAliases": true, "aliasPattern": "^is(Zh|Chinese|Cn|CN|En|English)$" }]
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Limits
|
|
54
|
+
|
|
55
|
+
Only values named `locale`, `.locale` members and the aliases above are followed: `navigator.language` or `userLocale === "zh"` is not seen, and `switch (locale)` is not checked. Alias tracking is per file and follows scopes. Ported from the prototype of the linter evaluation ([ADR 0001](../decisions/0001-oxlint.md)), where ESLint and Oxlint reported identical lines on opengame (399) and openmotion (73).
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# od/no-process-env
|
|
2
|
+
|
|
3
|
+
Preset: `base`
|
|
4
|
+
|
|
5
|
+
## What it reports
|
|
6
|
+
|
|
7
|
+
Reading `process.env` from the process object, in any of these forms:
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
process.env.PORT; // also process["env"]
|
|
11
|
+
globalThis.process.env.PORT; // also window.process, self.process, global.process
|
|
12
|
+
import { env } from "node:process"; // also "process", `env as e`, and `export { env } from`
|
|
13
|
+
import process from "node:process"; // then process.env; also `import * as p from "process"`
|
|
14
|
+
const { env } = process; // also `{ env: e }` and `({ env } = process)`
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
A local `process` (a parameter or variable) and a `process` imported from another module are not reported, nor are other members of `process` (`process.argv`).
|
|
18
|
+
|
|
19
|
+
## Why
|
|
20
|
+
|
|
21
|
+
Scattered `process.env.X` reads give a variable no declared type, default, owner or documentation, and each call site parses it differently. The opengame backend reads 95 distinct variables from 50 files, 22 of them added in the measured window.
|
|
22
|
+
|
|
23
|
+
## How to fix
|
|
24
|
+
|
|
25
|
+
Declare each variable once in the env registry module (name, type, default, description) and import the typed value from there.
|
|
26
|
+
|
|
27
|
+
## Exemptions
|
|
28
|
+
|
|
29
|
+
The env registry module is exempted with an `overrides` entry in the lint config, as are build scripts and config files if the repository decides so (owner review). Inline disable comments are rejected; existing debt stays in `oxlint-suppressions.json` and may only shrink.
|
|
30
|
+
|
|
31
|
+
## Options
|
|
32
|
+
|
|
33
|
+
```json
|
|
34
|
+
["error", { "registry": "shared/env.ts" }]
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
`registry` only changes the message text.
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# od/no-product-literal
|
|
2
|
+
|
|
3
|
+
Presets: `platform-boundary`, `product`
|
|
4
|
+
|
|
5
|
+
## What it reports
|
|
6
|
+
|
|
7
|
+
Code that branches on product identity:
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
if (product === "opengame") …
|
|
11
|
+
const brand = currentProductId() === "opengame" ? "OpenGame" : "OpenMotion";
|
|
12
|
+
switch (scheme) { case "openmotion": … }
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Reported: equality comparisons (`===`, `!==`, `==`, `!=`) where one side is a product id literal or a call to a product-id accessor, and `case` clauses with a product id. Plain strings, arrays and object keys are not reported.
|
|
16
|
+
|
|
17
|
+
## Why
|
|
18
|
+
|
|
19
|
+
Platform code must work for any product without naming one. Each `=== "opengame"` is a place that silently does the wrong thing for the next product and keeps product knowledge in the shell.
|
|
20
|
+
|
|
21
|
+
## How to fix
|
|
22
|
+
|
|
23
|
+
Describe the difference in the product manifest (`open-design.json`) or the product registry and read it from there, or check a capability. Brand names, URLs and feature differences are manifest data.
|
|
24
|
+
|
|
25
|
+
## Exemptions
|
|
26
|
+
|
|
27
|
+
The product registry or identity module that maps ids to manifests can be exempted with an `overrides` entry in the lint config (owner review). Inline disable comments are rejected; existing debt stays in `oxlint-suppressions.json` and may only shrink.
|
|
28
|
+
|
|
29
|
+
## Options
|
|
30
|
+
|
|
31
|
+
```json
|
|
32
|
+
["error", { "products": ["opengame", "openmotion"], "accessors": ["currentProductId"] }]
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Both default to the values shown. Setting an option replaces its default.
|
|
36
|
+
|
|
37
|
+
`products` defaults to the full product names, because the short ids `game` and `motion` are also ordinary words in product code. In a platform repository the short ids are product identities too (manifest `name`, `/api/<name>/`), so list them explicitly:
|
|
38
|
+
|
|
39
|
+
```json
|
|
40
|
+
["error", { "products": ["opengame", "openmotion", "game", "motion"] }]
|
|
41
|
+
```
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# od/no-raw-fetch
|
|
2
|
+
|
|
3
|
+
Preset: `base`
|
|
4
|
+
|
|
5
|
+
## What it reports
|
|
6
|
+
|
|
7
|
+
Calls to the global `fetch()`, including `window.fetch()`, `globalThis.fetch()` and `self.fetch()`. A local or imported `fetch` (for example from `undici`) and methods named `fetch` on other objects are not reported.
|
|
8
|
+
|
|
9
|
+
## Why
|
|
10
|
+
|
|
11
|
+
Raw `fetch` bypasses the API client: no shared base URL, auth refresh, error mapping, retries or telemetry. In opengame raw `fetch(` went from 59 to 70 call sites while the client existed.
|
|
12
|
+
|
|
13
|
+
## How to fix
|
|
14
|
+
|
|
15
|
+
Call the endpoint through the typed API client. If the endpoint is missing there, add a typed function for it in the client first.
|
|
16
|
+
|
|
17
|
+
## Exemptions
|
|
18
|
+
|
|
19
|
+
The API client layer itself (and server code that talks to upstream services, if the repository decides so) is exempted with an `overrides` entry in the lint config:
|
|
20
|
+
|
|
21
|
+
```json
|
|
22
|
+
{ "files": ["studio/src/api/**", "gateway/**"], "rules": { "od/no-raw-fetch": "off" } }
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Inline disable comments are rejected; existing debt stays in `oxlint-suppressions.json` and may only shrink.
|
|
26
|
+
|
|
27
|
+
## Options
|
|
28
|
+
|
|
29
|
+
```json
|
|
30
|
+
["error", { "client": "studio/src/api/client.ts" }]
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
`client` only changes the message text.
|