Skip to content

feat(hooks): run configured shell commands at agent hook points - #676

Merged
edenreich merged 3 commits into
mainfrom
feat/270-command-hooks
Jun 28, 2026
Merged

edenreich merged 3 commits into
mainfrom
feat/270-command-hooks

Conversation

@edenreich

Copy link
Copy Markdown
Contributor

Summary

Adds command hooks (#270): the executable sibling of #669's system reminders. Shell commands listed in a dedicated .infer/hooks.yaml run at the pre-defined agent-loop hook points (primarily post_session, "agent finished generating") for deterministic post-processing — gofmt, lint, test, notify. Feature-flagged, off by default.

# .infer/hooks.yaml
enabled: false
hooks:
  - name: gofmt
    hook: post_session
    command: "gofmt -w ."
    timeout: 30   # seconds; 0 -> default 30

Stacked on #675 — merge order matters

This branch is stacked on feat/669-flexible-system-reminders (PR #675), so the base of this PR is that branch, not main — the diff here is only #270's additive changes. #270 builds directly on #669's domain.HookPoint catalog + dispatchHooks seam, which are not on main yet.

Merge #675 (reminders) first, then this. Once #675 lands on main, this PR retargets to main (or rebase --onto main) and merges. Kept as a draft until then. Zero conflicts at every step — every change is additive at the existing seam.

What it does

  • One additive line per agent. dispatchHooks gains a RunCommandHooks(...) call next to injectDueReminders, in both the event-driven chat agent (internal/agent/agent_utils.go) and the headless infer agent loop (cmd/agent.go). Nothing [FEATURE] Flexible system reminders: multiple reminders across the agent loop #669 wrote is modified.
  • Allow-list gated, secure-by-default. Each command runs only if it passes the existing per-mode bash allow-list (config.IsBashCommandAllowed) — the same matcher a model-proposed command faces, so hooks open no new bypass. An off-list command is skipped and reported (hook_command_skipped + the rejection hint), never run. Authorize a command via tools.bash.mode.*.allow or INFER_TOOLS_BASH_ALLOW_APPEND.
  • One audited chokepoint. Both agents call the single shared agent.RunCommandHooks, so the gate and observability cannot drift between chat and headless.
  • Fire-and-observe (v1). Commands run synchronously under their timeout, receive a JSON context on stdin (hook, turn, session id), and emit a hook_command stream event (exit code, duration, truncated output). Output is not fed back into the conversation; stdout/exit-code feedback is a later iteration.
  • Config: dedicated hooks.yaml mirroring reminders.yaml (split-by-concern), INFER_HOOKS_ENABLED master-switch override, generated by infer init, validated in Config.Validate.

Verification

  • task build, full task test (no failures), go test -race ./internal/agent/... ./cmd/... ./config/... (clean), task lint (0 issues)
  • New tests: config truth-table (effective/CommandsDue/Validate/round-trip), the shared runner (allow-listed exec, off-list skip + hint, disabled no-op, timeout), and a headless security test proving an off-list command does not run unattended
  • go run . init generates .infer/hooks.yaml in the documented shape; task mocks:generate adds only FakeHookCommandProvider; [FEATURE] Flexible system reminders: multiple reminders across the agent loop #669's reminder tests still pass

Closes #270

Base automatically changed from feat/669-flexible-system-reminders to main June 28, 2026 10:44
Command hooks are the executable sibling of #669's system reminders: shell commands listed in a dedicated hooks.yaml run at the pre-defined agent-loop hook points (primarily post_session) for deterministic post-processing such as gofmt, lint, or notify. Off by default.

Each command is gated on the existing per-mode bash allow-list, so hooks open no new bypass of secure-by-default; an off-list command is skipped and reported, never run. A single shared runner, agent.RunCommandHooks, is the one chokepoint both the event-driven chat agent and the headless infer agent call, so the gate and observability cannot drift between them. v1 is fire-and-observe: each run emits a hook_command stream event and is logged, but output is not fed back into the conversation.
@edenreich
edenreich force-pushed the feat/270-command-hooks branch from 304d190 to 7d43dbd Compare June 28, 2026 10:47
@edenreich
edenreich marked this pull request as ready for review June 28, 2026 10:48
@edenreich
edenreich requested a review from a team as a code owner June 28, 2026 10:48
infer drives any project, not just Go ones, so a default gofmt hook (even disabled) is inappropriate. DefaultHooksConfig now ships empty; the generated hooks.yaml carries the example commented out so the shape stays discoverable without anything running until the user opts in and allow-lists a command.
@inference-gateway-maintainer inference-gateway-maintainer Bot moved this to Todo in 2026 Jun 28, 2026
@edenreich
edenreich merged commit 990f2c0 into main Jun 28, 2026
1 check passed
@edenreich
edenreich deleted the feat/270-command-hooks branch June 28, 2026 11:57
inference-gateway-releaser Bot added a commit that referenced this pull request Jun 28, 2026
## [0.125.0](v0.124.1...v0.125.0) (2026-06-28)

### 🚀 Features

* **reminders:** configurable reminders on a shared hook-point catalog ([#675](#675)) ([179cad1](179cad1)), closes [#270](#270) [#669](#669) [#270](#270) [#525](#525) [#270](#270)
* **channels:** retain inbound voice/audio recordings with bounded cleanup ([#671](#671)) ([8fd29ce](8fd29ce))
* **hooks:** run configured shell commands at agent hook points ([#676](#676)) ([990f2c0](990f2c0)), closes [#270](#270) [#675](#675) [#675](#675) [#270](#270) [#675](#675) [#675](#675) [#669](#669) [#270](#270)

### 🐛 Bug Fixes

* **agent:** keep the internal completion check out of channel replies ([#672](#672)) ([96b166c](96b166c))
* **docs:** replace em dashes with hyphens for consistency in SKILL.md and configuration-reference.md ([1c9196d](1c9196d))

### ♻️ Code Refactoring

* dead-code cleanup, Go 1.26 modernization, width-aware truncation, race testing ([#667](#667)) ([7a97f3b](7a97f3b))
* interfaces, fix context propagation, and reduce delays ([#666](#666)) ([1a93ff8](1a93ff8))

### 📚 Documentation

* **skills:** add charm v2 skills (bubbletea, lipgloss, bubbles) ([#664](#664)) ([c7242c7](c7242c7)), closes [#657](#657) [#663](#663)
* **skills:** add Go skills adapted from spf13/go-skills ([#665](#665)) ([971ac23](971ac23))
* **skills:** add go-concurrency skill ([#663](#663)) ([c77ac33](c77ac33)), closes [#657](#657)

### ✅ Tests

* relax TestSessionID_Age_Recent upper bound to tolerate slow CI ([#673](#673)) ([9cfe203](9cfe203)), closes [#671](#671)
@inference-gateway-releaser

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 0.125.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@inference-gateway-releaser inference-gateway-releaser Bot added the released Shipped in a release label Jun 28, 2026
@edenreich edenreich moved this from Todo to Done in 2026 Jun 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released Shipped in a release

Projects

No open projects
Status: Done

Development

Successfully merging this pull request may close these issues.

[FEATURE] Implement Hooks

1 participant