Repository navigation
ci(agents): adopt Bun-style agent guardrails — hooks, comment-cop, PR template - #5501
Merged
Merged
Conversation
… template Imported from studying oven-sh/bun's agent-development setup: - .claude/hooks/pre-guard.js (PreToolUse): denies `git push` to main and bare `bun test` from the repo root with corrective messages; escalates knip config edits to the human via "ask" (Gotcha #6, with an escape hatch for legitimate edits like new workspace entries). - .claude/hooks/post-edit-format.js (PostToolUse): runs Biome format on each edited file, fail-open — removes the "pure-format follow-up PR" class entirely. - PR template: adds "How did you verify your code works?" section. - auto-label-claude-prs.yml: labels agent-authored PRs (detected by the "🤖 Generated with" signature) with `claude`. - comment-cop.yml: on claude-labeled PRs, flags added multi-line comment blocks in apps/, packages/, plugins/ per the CLAUDE.md rule that a paragraph justifying a workaround means the code is wrong. Marker-based dedupe, auto-resolves threads when the block disappears, JSDoc blocks skipped, never checks out PR code (pull_request_target-safe). 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What is this contribution about?
Imports the transferable agent-development practices from studying oven-sh/bun's repo automation. Bun's recurring move: every important rule exists twice — as prose in CLAUDE.md (teaches) and as a hook/workflow (guarantees). This PR adds the mechanism layer for rules our CLAUDE.md already states:
Claude Code hooks (
.claude/hooks/)pre-guard.js(PreToolUse on Bash/Edit/Write):git pushto main/master → deny with a corrective messagebun testfrom the repo root (runs the whole monorepo suite) → deny, suggestsbun test <path>knip.jsonc/knip.config.*→ ask (escalates to the human, citing Gotcha fix: avoid creating anynous #6, with an escape hatch for legitimate edits like new workspace entry points)post-edit-format.js(PostToolUse): runsbiome format --writeon each edited file, fail-open. Removes the "pure-format follow-up" class (e.g. fix(decopilot): stream user prompt to other thread viewers #4461).GitHub automation (
.github/workflows/)auto-label-claude-prs.yml: PRs whose body carries the "🤖 Generated with" signature get theclaudelabel (label already created on the repo).comment-cop.yml: onclaude-labeled PRs, scans the diff via the GitHub API for added multi-line comment blocks inapps/,packages/,plugins/and posts a line review quoting our CLAUDE.md rule ("a comment that takes a paragraph to justify a workaround is a signal the code is wrong"). Marker-based dedupe, auto-resolves its threads when the flagged block disappears from the diff, skips JSDoc blocks. Never checks out PR code — that's what makespull_request_targetsafe here (property preserved from Bun's original).PR template
How did you verify your code works?
pre-guard.js: exercised with simulated hook JSON on stdin — deny ongit push origin main(incl. env-prefix evasionFOO=1 git push origin main), deny on barebun testat repo root, pass ongit push -u origin claude/fooandbun test apps/api/src/foo.test.ts, ask onknip.jsoncedit, silent on normal edits.post-edit-format.js: fed a deliberately misformatted.tsfile through the hook; Biome rewrote it (quotes/spacing/semicolons).comment-copparser: extractedgroupsFromPatchand ran it against a synthetic patch — the 2-line workaround paragraph is flagged with correct line numbers; JSDoc block and single-line comment are skipped.Bun.YAML) with the expected jobs. The workflows themselves only take effect once on main (pull_request_target), so end-to-end firing can't be tested from this branch.Migration Notes
claudelabel was already created on the repo.comment-cop/auto-labelonly start firing after this lands on main.🤖 Generated with Claude Code
Summary by cubic
Adds Bun-style agent guardrails: pre-hooks that block risky commands, post-hooks that auto-format edits, and a workflow that flags workaround-heavy comments. Also updates the PR template to require concrete verification steps.
New Features
.claudehooksgit pushto main/master; deny barebun testfrom repo root; ask onknipconfig edits.auto-label-claude-prs.yml: PRs with the "🤖 Generated with" line get theclaudelabel.comment-cop.yml: onclaude-labeled PRs, scans diffs inapps/,packages/,plugins/for added multi-line comment blocks; skips JSDoc; dedupes via markers; auto-resolves when blocks are removed; uses API-only calls (pull_request_target-safe).Migration
claudelabel already exists.main.Written for commit a202b69. Summary will update on new commits.