Skip to content

Fix local-dev hooks path resolution for non-Claude agents#745

Merged
pfleidi merged 7 commits intomainfrom
fix/local-dev-agent-hooks
Mar 23, 2026
Merged

Fix local-dev hooks path resolution for non-Claude agents#745
pfleidi merged 7 commits intomainfrom
fix/local-dev-agent-hooks

Conversation

@pfleidi
Copy link
Copy Markdown
Contributor

@pfleidi pfleidi commented Mar 21, 2026

Summary

  • Switch local-dev hook command prefixes for Gemini CLI, Cursor, Factory AI Droid, Copilot CLI, and OpenCode from agent-specific *_PROJECT_DIR variables to $(git rev-parse --show-toplevel) so hooks resolve the repo root correctly at runtime regardless of checkout location.
  • Harden the OpenCode plugin hook execution path by invoking hook commands through sh -c with Bun spawn APIs and wrapping event handling in a top-level safety try/catch, ensuring shell substitution works and plugin errors remain non-fatal.
  • Update agent docs, generated plugin/config fixtures, and unit/integration expectations to match the new local-dev command format and hook detection prefixes.

Why

  • Only Claude Code reliably exposes a project-root environment variable. Other agents can run without equivalent vars, causing local-dev hooks to resolve paths incorrectly or fail in some environments.
  • Resolving the root dynamically via Git makes hook behavior portable and consistent across agents while keeping production entire hooks ... paths unchanged.

Testing

  • Existing hook unit/integration tests were updated to assert the new command prefix and continue to validate idempotent install/detection behavior.

Please note: --local-dev is a feature specific to this repository and shouldn't be used outside of developing this CLI. I therefore ignored all legacy commands using AGENT_PROJECT_DIR since they simply didn't work.

pfleidi added 5 commits March 20, 2026 16:38
Entire-Checkpoint: 1d414313029f
Entire-Checkpoint: 4fec5565b45f
- Ensure hooks don't crash the agent
- Allow `git ref-parse ...` to be used as entire cmd
@pfleidi pfleidi requested a review from a team as a code owner March 21, 2026 00:08
Copilot AI review requested due to automatic review settings March 21, 2026 00:08
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates how local-dev hook commands resolve the repository root for non-Claude agents by switching from agent-specific *_PROJECT_DIR environment variables to $(git rev-parse --show-toplevel), and adjusts the OpenCode Bun plugin to execute hook commands via sh -c so command substitution works.

Changes:

  • Replace non-Claude local-dev hook prefixes with go run $(git rev-parse --show-toplevel)/... across multiple agents and fixtures.
  • Update OpenCode plugin hook execution to use Bun spawn APIs + sh -c, and add top-level event safety try/catch.
  • Update docs and Go unit/integration tests to assert the new local-dev command format.

Reviewed changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
docs/architecture/agent-guide.md Updates guidance/examples for local-dev hook command prefixing.
cmd/entire/cli/integration_test/agent_test.go Updates integration assertions for new local-dev prefix.
cmd/entire/cli/agent/opencode/hooks_test.go Updates OpenCode install test to expect new local-dev command.
cmd/entire/cli/agent/opencode/hooks.go Switches OpenCode local-dev ENTIRE_CMD to git rev-parse based path.
cmd/entire/cli/agent/opencode/entire_plugin.ts Updates plugin template to run hooks via Bun.spawn + sh -c and add safety try/catch.
cmd/entire/cli/agent/geminicli/hooks_test.go Updates Gemini hook command expectations for new local-dev prefix.
cmd/entire/cli/agent/geminicli/hooks.go Switches Gemini local-dev prefix + detection prefix to git rev-parse.
cmd/entire/cli/agent/factoryaidroid/hooks_test.go Updates Factory AI Droid hook command expectations for new local-dev prefix.
cmd/entire/cli/agent/factoryaidroid/hooks.go Switches Factory AI Droid local-dev prefix + detection prefix to git rev-parse.
cmd/entire/cli/agent/cursor/hooks_test.go Updates Cursor hook command expectation for new local-dev prefix.
cmd/entire/cli/agent/cursor/hooks.go Switches Cursor local-dev prefix + detection prefix to git rev-parse.
cmd/entire/cli/agent/copilotcli/hooks_test.go Updates Copilot CLI hook command expectation for new local-dev prefix.
cmd/entire/cli/agent/copilotcli/hooks.go Switches Copilot CLI local-dev prefix + detection prefix to git rev-parse.
cmd/entire/cli/agent/copilotcli/AGENT.md Updates Copilot CLI docs for new detection prefix string.
.opencode/plugins/entire.ts Updates generated OpenCode plugin fixture to new local-dev ENTIRE_CMD + spawn behavior.
.gemini/settings.json Updates generated Gemini settings fixture to new local-dev command prefix.

Prevents word-splitting when the repo root path contains spaces.
Without quoting, the shell splits the expanded path into multiple
arguments, breaking `go run` invocations for all non-Claude agents.

Entire-Checkpoint: 01186addddb4
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 16 out of 16 changed files in this pull request and generated 2 comments.

@pfleidi pfleidi merged commit 901a2c9 into main Mar 23, 2026
3 checks passed
@pfleidi pfleidi deleted the fix/local-dev-agent-hooks branch March 23, 2026 17:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants