feat(minder): add a Claude Code PreToolUse policy hook
Description
This adds a hidden, experimental glab minder policy pre-tool-use command for Claude Code's PreToolUse hook, for https://gitlab.com/gitlab-org/gitlab/-/work_items/634679. The command reads the hook event on standard input, resolves the GitLab project from the event's cwd, and matches the tool call against the policy snapshot that glab stores for that project. It makes no network call. Bash commands and file paths are matched with their normalised forms, and MCP tool calls are matched on the server, the tool, and the input. It prints a deny or ask in the format Claude Code reads, and it always exits 0. It stays silent when the folder has no Git remote, glab is not logged in to the host, or the project has no snapshot. Any other failure, such as an unreadable configuration, a remote that does not parse, or a snapshot that cannot be read, allows the call and prints one line on standard error. gaig gets an ErrNoRemote error so the hook can tell a missing remote from a failure. A message the developer sees and an audit event for these failures are tracked in https://gitlab.com/gitlab-org/gitlab/-/work_items/641335. When the snapshot is more than a day old, the command still enforces it and writes a warning to standard error.
The command group is named policy rather than hook, because glab minder forwards glab minder hook to the agent-client binary. The final name is still to be decided before glab minder setup writes it into Claude Code settings. The command is only under glab minder, not the legacy glab govern. Telemetry and the update check skip it, because it runs before every tool call.
Known limits:
- Glob calls are not matched, and Grep calls are only matched when they have a path.
- Only the origin remote identifies the project.
It is stacked on !4472. Fetching the snapshot at session start, installing the hook with glab minder setup, and support for other agents are left for follow-up MRs.
How has this been tested?
Table-driven tests run the command through cmdtest.SetupCmdForTest with an isolated configuration directory and a mocked git call. They cover the deny, ask, and no-decision outputs and the precedence between them. They also cover each file tool's operation, MCP calls, ignored tools and events, path normalisation, file names in another case, the stale snapshot warning, skipped rules, the case without any snapshot, and each fail-open case, including which ones print a line on standard error. gaig tests cover a missing remote, a host glab is not logged in to, a remote that does not parse, git failing, missing or timing out, and hosts that cannot be read. Telemetry tests check that the hook sends no telemetry and skips the update check. I also ran the built binary against a local snapshot to check a command substitution, a quoted pattern, and a file name in another case.