Skip to content

Commit 0732d3c

Browse files
committed
chore(wheelhouse): cascade template@6fc377f4
Auto-applied by socket-wheelhouse sync-scaffolding into cascade-socket-addon-55418. 605 file(s) touched: - .claude/hooks/fleet/_shared/README.md - .claude/hooks/fleet/_shared/acorn/README.md - .claude/hooks/fleet/_shared/acorn/acorn-bindgen.cjs - .claude/hooks/fleet/_shared/acorn/acorn-sync.mts - .claude/hooks/fleet/_shared/acorn/acorn.wasm - .claude/hooks/fleet/_shared/acorn/index.mts - .claude/hooks/fleet/_shared/fleet-repos.mts - .claude/hooks/fleet/_shared/foreign-paths.mts - .claude/hooks/fleet/_shared/hook-env.mts - .claude/hooks/fleet/_shared/markers.mts - .claude/hooks/fleet/_shared/payload.mts - .claude/hooks/fleet/_shared/shell-command.mts - .claude/hooks/fleet/_shared/stop-reminder.mts - .claude/hooks/fleet/_shared/test/fleet-repos.test.mts - .claude/hooks/fleet/_shared/test/foreign-paths.test.mts - .claude/hooks/fleet/_shared/test/shell-command.test.mts - .claude/hooks/fleet/_shared/test/transcript.test.mts - .claude/hooks/fleet/_shared/token-patterns.mts - .claude/hooks/fleet/_shared/transcript.mts - .claude/hooks/fleet/_shared/wheelhouse-root.mts ... and 585 more
1 parent ac2fbd3 commit 0732d3c

605 files changed

Lines changed: 61064 additions & 302 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# `.claude/hooks/_shared/`
2+
3+
Helper modules shared across multiple hooks under `.claude/hooks/`. **Not a deployable hook** — has no `index.mts` entry point and no Claude Code hook lifecycle wiring.
4+
5+
## What lives here
6+
7+
- **`shell-command.mts`** — Tokenizes a Bash command string with `shell-quote` into discrete `Command`s (`binary`, `args`, leading env `assignments`, plus `viaVariable` / `viaEval` indirection flags). Exposes `parseCommands`, `findInvocation`, `commandsFor`, `invocationHasFlag`, and `hasOpaqueInvocation`. Used by every structure-sensitive Bash guard (`codex-no-write-guard`, `release-workflow-guard`, `no-empty-commit-guard`, the git-detection guards, …) so a forbidden invocation is matched on the actual parsed command — `$(…)` / `$VAR` / `eval` indirection is seen rather than evaded, and a quoted mention inside an `echo` or `-m` body can't false-trigger.
8+
9+
- **`hook-env.mts`**`isHookDisabled(slug)` and `hookLog(slug, ...lines)`. Standardizes the `SOCKET_<UPPER_SLUG>_DISABLED` env-var convention every hook supports plus the `[<slug>] <line>` stderr prefix shape. Use these in new hooks so every hook gets a uniform kill switch + output format for free.
10+
11+
- **`markers.mts`** — Shared sentinel constants for bypass phrases the user can type to override a hook (`Allow <name> bypass`, etc.).
12+
13+
- **`payload.mts`**`ToolCallPayload` and `ToolInput` types for the PreToolUse JSON payload, plus `readCommand` / `readFilePath` / `readWriteContent` narrowing helpers. **Use this instead of re-declaring `tool_input` types per-hook** — the fleet had 7 hand-rolled variants before this module landed.
14+
15+
- **`stop-reminder.mts`**`runStopReminder(config)` scaffold for Stop hooks that are pure pattern-sweep over the last assistant turn. Reduces a typical pattern-only hook from 100-200 LOC to ~50. Pass `patterns: [{label, regex, why}, ...]` and `closingHint`; the scaffold handles stdin parse, transcript walk, code-fence strip, per-hit snippet extraction, and stderr emit.
16+
17+
- **`token-patterns.mts`** — Canonical catalog of secret-bearing env-var key names (Socket, LLM providers, GitHub, Linear, Notion, AWS, Stripe, …). Used by `token-guard` (Bash) and `no-token-in-dotenv-guard` (Edit/Write) for the same shape detection.
18+
19+
- **`transcript.mts`**`readStdin()` for hook payloads, plus `readLastAssistantText()` and `readLastAssistantToolUses()` for walking the Claude Code session transcript JSONL. Tolerates the harness's 3 historical schema variants in one place so a schema bump is a one-file fix.
20+
21+
- **`wheelhouse-root.mts`** — Walks up from `cwd` to find the local `socket-wheelhouse` checkout (used by hooks that need wheelhouse-relative paths, e.g. `new-hook-claude-md-guard`, `drift-check-reminder`).
22+
23+
## When to reach for what (new hook quick-reference)
24+
25+
- Writing a **Stop hook** that just emits a reminder when patterns match? → `import { runStopReminder } from '../_shared/stop-reminder.mts'`. See `comment-tone-reminder` or `excuse-detector` for the shape.
26+
27+
- Writing a **PreToolUse hook** that inspects a tool call's input? → `import { ToolCallPayload, readCommand, readFilePath } from '../_shared/payload.mts'`. Saves you the `typeof === 'string'` guard.
28+
29+
- Detecting whether a Bash command really invokes some binary/subcommand (and want `$(…)` / `$VAR` / quoted-mention false positives handled)? → `import { commandsFor, findInvocation } from '../_shared/shell-command.mts'`.
30+
31+
- Want a kill switch for your hook? → `import { isHookDisabled, hookLog } from '../_shared/hook-env.mts'`. The hook is enabled by default and `SOCKET_<UPPER_SLUG>_DISABLED=1` opts out — same shape across the fleet.
32+
33+
- Need to scan secret-bearing env-var names? → `import { ALL_TOKEN_KEY_PATTERNS } from '../_shared/token-patterns.mts'`.
34+
35+
## Adding to `_shared/`
36+
37+
A module belongs in `_shared/` when:
38+
39+
1. Two or more hooks under `.claude/hooks/*/index.mts` need the same parsing / matching / IO logic.
40+
2. The logic is self-contained — no Claude Code hook lifecycle (`process.stdin`, exit codes, blocking semantics).
41+
3. Test coverage lives in `_shared/test/` alongside the helper.
42+
43+
If only one hook uses it, keep it inline in that hook's directory. If three or more hooks need it across `.claude/hooks/` AND `.git-hooks/`, escalate it to `_helpers.mts` (the cross-boundary shared module) instead.
44+
45+
## Not a hook
46+
47+
The `audit-claude` script and the sync-scaffolding `every-hook-has-test` check skip `_shared/` because it carries no `index.mts`. Future contributors who add an `index.mts` here are mis-using the directory — the file should live in a sibling `<hook-name>/` directory instead.
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# acorn — shared wasm parser for fleet hooks
2+
3+
Vendored from
4+
[`@ultrathink/acorn-monorepo`](https://github.com/SocketDev/ultrathink/tree/main/packages/acorn)'s
5+
Rust → WebAssembly prod build (path:
6+
`packages/acorn/lang/rust/build/prod/darwin-arm64/wasm/out/Final/`).
7+
Pending `@ultrathink/acorn` ship to the npm registry, fleet hooks
8+
that need AST-aware analysis `import` from here.
9+
10+
## Provenance
11+
12+
The three vendored files come straight from the ultrathink prod build:
13+
14+
- `acorn.wasm` — compiled Rust acorn parser, ~3.3 MB.
15+
- `acorn-bindgen.cjs` — wasm-bindgen JS glue.
16+
- `acorn-sync.mts` — sync ESM loader (no top-level await,
17+
`WebAssembly.Instance` constructed at module import).
18+
19+
The artifact is rebuilt in ultrathink with `pnpm run
20+
build:wasm:node:release` from `packages/acorn/lang/rust`.
21+
22+
## Refreshing
23+
24+
Hooks importing this directory don't need to do anything special —
25+
the cascade keeps the files byte-identical with the ultrathink
26+
canonical source. To pull a newer build:
27+
28+
```bash
29+
# Inside socket-wheelhouse (the canonical source for fleet template):
30+
node scripts/refresh-vendored-acorn.mts
31+
```
32+
33+
The script reads from
34+
`$ULTRATHINK_ROOT/packages/acorn/lang/rust/build/prod/darwin-arm64/wasm/out/Final/`,
35+
copies the three files into this directory, and updates this README's
36+
"Last refreshed" line.
37+
38+
Last refreshed: 2026-05-20 (ultrathink build dated 2026-05-20).
39+
40+
## Public surface
41+
42+
`template/.claude/hooks/fleet/_shared/acorn/index.mts` is the canonical
43+
import path for fleet hooks. It re-exports a narrow `tryParse` /
44+
`walkSimple` / `findBareCallsTo` surface — see the module's JSDoc for
45+
the parse-failure tolerance + visitor patterns hook authors rely on.
46+
47+
Don't import `acorn-sync.mts` directly from hooks; the `index.mts`
48+
wrapper provides the failure-handling + visitor adapters every hook
49+
needs.
50+
51+
## Why vendor instead of `import 'acorn'`
52+
53+
- **No JS parser in the npm dep graph.** Hooks fire on every Edit/Write.
54+
A 3-5 MB JS bundle in `node_modules` adds startup latency and Socket-
55+
score risk on every fleet repo.
56+
- **AST parity with the lint plugin.** Both surfaces (oxlint via plugin
57+
- hook via this loader) use the same acorn semantics — the rules can
58+
share visitor logic without divergence between commit-time and
59+
edit-time.
60+
- **wasm sandbox.** The parser runs in WebAssembly with no filesystem
61+
/ network access — even a malicious source file under analysis can't
62+
reach the host.
63+
64+
Retire this directory once `@ultrathink/acorn` ships and the wheelhouse
65+
catalog can pin it.

0 commit comments

Comments
 (0)