Skip to content

ci(agents): adopt Bun-style agent guardrails — hooks, comment-cop, PR template - #5501

Merged
viktormarinho merged 1 commit into
mainfrom
viktormarinho/aprendizados-bun
Jul 31, 2026
Merged

viktormarinho merged 1 commit into
mainfrom
viktormarinho/aprendizados-bun

Conversation

@viktormarinho

@viktormarinho viktormarinho commented Jul 31, 2026 •

Copy link
Copy Markdown
Contributor

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 push to main/master → deny with a corrective message
    • bare bun test from the repo root (runs the whole monorepo suite) → deny, suggests bun test <path>
    • edits to 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): runs biome format --write on 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 the claude label (label already created on the repo).
  • comment-cop.yml: on claude-labeled PRs, scans the diff via the GitHub API for added multi-line comment blocks in apps/, 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 makes pull_request_target safe here (property preserved from Bun's original).

PR template

  • New section: "How did you verify your code works?" — Bun's two-question anti-slop philosophy.

How did you verify your code works?

  • pre-guard.js: exercised with simulated hook JSON on stdin — deny on git push origin main (incl. env-prefix evasion FOO=1 git push origin main), deny on bare bun test at repo root, pass on git push -u origin claude/foo and bun test apps/api/src/foo.test.ts, ask on knip.jsonc edit, silent on normal edits.
  • post-edit-format.js: fed a deliberately misformatted .ts file through the hook; Biome rewrote it (quotes/spacing/semicolons).
  • comment-cop parser: extracted groupsFromPatch and 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.
  • Both workflow YAMLs parse (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

  • The claude label was already created on the repo.
  • comment-cop/auto-label only start firing after this lands on main.
  • No new dependencies; hooks are zero-dependency Bun scripts.

🤖 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

    • .claude hooks
      • PreToolUse: deny git push to main/master; deny bare bun test from repo root; ask on knip config edits.
      • PostToolUse: run Biome format on edited files (fail-open).
    • GitHub workflows
      • auto-label-claude-prs.yml: PRs with the "🤖 Generated with" line get the claude label.
      • comment-cop.yml: on claude-labeled PRs, scans diffs in apps/, 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).
    • PR template: adds "How did you verify your code works?" section.
  • Migration

    • No new dependencies; hooks are Bun scripts using local Biome.
    • claude label already exists.
    • Workflows start after this lands on main.

Written for commit a202b69. Summary will update on new commits.

Review in cubic

… 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]>
@github-actions github-actions Bot added the claude PR authored by a coding agent label Jul 31, 2026
@viktormarinho
viktormarinho enabled auto-merge (squash) July 31, 2026 16:21
@viktormarinho
viktormarinho merged commit ee9dab3 into main Jul 31, 2026
31 of 32 checks passed
@viktormarinho
viktormarinho deleted the viktormarinho/aprendizados-bun branch July 31, 2026 16:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

claude PR authored by a coding agent

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant