ds4 icon indicating copy to clipboard operation
ds4 copied to clipboard

agent: add before-response and after-response hooks

Open Berserk-hub150 opened this issue 3 months ago • 1 comments

Closes #440

Summary

Add optional command hooks to ds4-agent, allowing external commands to run before and after each assistant response.

Hooks are disabled by default and do not change normal agent behavior unless explicitly configured.

CLI options

--before-response-hook CMD
--after-response-hook CMD
--hook-timeout SEC

Features

  • Execute a command before a response starts
  • Execute a command after a response finishes
  • Pass structured JSON events through stdin
  • Support configurable hook timeouts
  • Terminate the hook process group after a timeout
  • Report hook failures to stderr
  • Preserve the active agent session when a hook fails
  • Include response metadata, token counts, interruption status and tool-call status

Documentation and examples

  • Hook lifecycle and security documentation
  • JSON event schema
  • Shell and PowerShell examples
  • HTTP callback example using curl
  • JSONL logging example
  • Regression checklist

Validation

The following commands completed successfully in the gcc:14-bookworm Docker image:

make -f GNUmakefile test-hooks
make -f GNUmakefile cpu

Test result:

ds4 hook tests: ok

The complete CPU build succeeded.

A full make test was also attempted, but the Linux test target requires CUDA nvcc, which is not included in the CPU-only gcc:14-bookworm image.

Berserk-hub150 avatar Aug 05 '26 16:08 Berserk-hub150

@antirez, before you spend time reviewing the full implementation, is the wrapper-based integration through GNUmakefile and ds4_agent_with_hooks.c acceptable for this project, or would you prefer the hooks to be integrated directly into ds4_agent.c and the main Makefile?

Berserk-hub150 avatar Aug 05 '26 19:08 Berserk-hub150