-
Notifications
You must be signed in to change notification settings - Fork 60
chore(hooks+claude+oxfmt+kind-config): hooks-mts + sweeper + CLAUDE.md restructure + oxfmt JSDoc + logger-guard + auth-rotation-reminder + kind config #1286
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 2 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
1f4e25b
chore(hooks): path-guard + token-guard + .sh→.mts conversion
jdalton 51abd38
fix(hooks): address Bugbot findings on pre-commit + token-guard
jdalton 97c3e2b
fix(token-guard): block || / && shell-conditional redaction bypass
jdalton d309900
fix(token-guard): block ;-separator redaction bypass in segment matcher
jdalton aa927eb
fix(hooks): address Bugbot review on #1286
jdalton 5995270
feat(.claude): add stale-process-sweeper Stop hook
jdalton 1c88d87
docs(claude): restructure CLAUDE.md to fleet-canonical + project-spec…
jdalton b209165
chore(oxfmt): enable JSDoc formatting
jdalton 3703e2f
chore(claude+hooks+xport): sync fleet-canonical updates from socket-r…
jdalton 9b615d9
feat(.claude): add logger-guard + auth-rotation-reminder hooks
jdalton 55cef29
chore: enable blockExoticSubdeps + sync .mjs->.mts script refs + soak…
jdalton 8baf631
chore(deps): bump @socketsecurity/lib catalog 5.24.0 → 5.26.1
jdalton a308c4b
chore: adopt socket-repo-template kind config + schema
jdalton 29551cc
chore: add @sinclair/typebox + sync emit-schema scripts
jdalton 5f3cb8c
fix(iocraft+test): bundled-node_modules fallback + drop dist/cli.js →…
jdalton f75ca93
chore: sync power-state helper from socket-repo-template@c23dfef
jdalton File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| # path-guard | ||
|
|
||
| Claude Code `PreToolUse` hook that refuses `Edit`/`Write` tool calls that would *construct* a multi-segment build/output path inline in a `.mts` or `.cts` file. Mandatory across the Socket fleet — every repo ships this file byte-for-byte via `scripts/sync-scaffolding.mjs`. | ||
|
|
||
| **Mantra: 1 path, 1 reference.** | ||
|
|
||
| Construct a path *once* in the canonical `paths.mts` (or a build-infra helper); reference the computed value everywhere else. | ||
|
|
||
| ## What it blocks | ||
|
|
||
| | Rule | Example | Fix | | ||
| |------|---------|-----| | ||
| | **A** — Multi-stage path constructed inline | `path.join(PKG, 'build', mode, 'out', 'Final', name)` | Construct in the package's `scripts/paths.mts` (or use `getFinalBinaryPath` from `build-infra/lib/paths`); import the computed value here | | ||
| | **B** — Cross-package path traversal | `path.join(PKG, '..', 'lief-builder', 'build', ...)` | Add `lief-builder: workspace:*` as a dep; import its `paths.mts` via the workspace `exports` field | | ||
|
|
||
| The hook fires on `Edit` and `Write` tool calls when the target path ends in `.mts` or `.cts`. Other extensions (`.ts`, `.mjs`, `.js`, `.yml`, `.json`, `.md`) pass through — TS path code lives in `.mts` per CLAUDE.md, and other file types are covered by the `scripts/check-paths.mts` gate at commit time. | ||
|
|
||
| ## What it allows | ||
|
|
||
| - Edits to a `paths.mts` (canonical constructor — every package's source of truth). | ||
| - Edits to `scripts/check-paths.mts` (the gate, which legitimately enumerates patterns). | ||
| - Edits to this hook's own files (the test suite has to enumerate the same patterns). | ||
| - Edits to `scripts/check-consistency.mts` (existing path-scanning gate). | ||
| - `path.join` calls with a single stage segment (e.g. `path.join(packageRoot, 'build', 'temp')`) — that's a one-off helper path, not a multi-stage build output. | ||
| - `path.join` calls with no stage segments at all (most general-purpose joins). | ||
| - Any string concatenation that doesn't go through `path.join` — the hook is regex-based and intentionally narrow; the gate runs a deeper scan at commit time. | ||
|
|
||
| ## Stage segments the hook recognizes | ||
|
|
||
| These come from `build-infra/lib/constants.mts` `BUILD_STAGES` plus the lowercase directory-name siblings used by some builders: | ||
|
|
||
| `Final`, `Release`, `Stripped`, `Compressed`, `Optimized`, `Synced`, `wasm`, `downloaded` | ||
|
|
||
| Two or more in the same `path.join` call (or one stage + one of `'build'`/`'out'` + one mode `'dev'`/`'prod'`) triggers Rule A. | ||
|
|
||
| ## Known sibling packages (for Rule B) | ||
|
|
||
| The hook recognizes Rule B traversals only when the next segment after `..` is a known fleet package name: | ||
|
|
||
| `binflate`, `binject`, `binpress`, `bin-infra`, `build-infra`, `codet5-models-builder`, `curl-builder`, `iocraft-builder`, `ink-builder`, `libpq-builder`, `lief-builder`, `minilm-builder`, `models`, `napi-go`, `node-smol-builder`, `onnxruntime-builder`, `opentui-builder`, `stubs-builder`, `ultraviolet-builder`, `yoga-layout-builder` | ||
|
|
||
| When a new package joins the workspace, add it here. | ||
|
|
||
| ## Control flow | ||
|
|
||
| The hook reads the tool-use payload from stdin, type-checks `tool_name === 'Edit'` or `'Write'`, filters to `.mts`/`.cts` files, and runs `check(source)`. Any rule violation `throw`s a typed `BlockError`; a single top-level `try/catch` in `main()` writes the block message to stderr and sets `process.exitCode = 2`. | ||
|
|
||
| Hook bugs fail **open** — a crash in the hook writes a log line and returns exit 0 so legitimate work isn't blocked on a bad deploy. The companion `scripts/check-paths.mts` gate runs a thorough whole-repo scan at `pnpm check` time, catching anything the hook misses. | ||
|
|
||
| ## Testing | ||
|
|
||
| ```bash | ||
| pnpm --filter hook-path-guard test | ||
| ``` | ||
|
|
||
| Adding a new detection pattern: update `STAGE_SEGMENTS` (or `KNOWN_SIBLING_PACKAGES`) in `index.mts`, add a positive and negative test in `test/path-guard.test.mts`. | ||
|
|
||
| ## Updating across the fleet | ||
|
|
||
| This file is in `IDENTICAL_FILES` in `scripts/sync-scaffolding.mjs` (in `socket-repo-template`). After editing, run from `socket-repo-template`: | ||
|
|
||
| ```bash | ||
| node scripts/sync-scaffolding.mjs --all --fix | ||
| ``` | ||
|
|
||
| to propagate the change to every fleet repo. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.