Files
oh-my-pi/packages/agent/test
can1357 c29fe28dbb feat(agent): add beforeToolCall and afterToolCall hooks
Mirrors the pi-mono API surface so apps can preflight tool execution
(block or mutate validated args) and post-process tool results
(override content/details/isError) without wrapping tools.

- `AgentLoopConfig.beforeToolCall` runs after argument validation. Return
  `{ block: true, reason }` to short-circuit with a tool-error result.
  Mutations to `context.args` are forwarded to `tool.execute` without
  revalidation, matching pi-mono semantics.
- `AgentLoopConfig.afterToolCall` runs after execution and before
  `tool_execution_end` / tool-result message emission. Returned fields
  override the executed result; omitted fields fall through. Hook
  exceptions surface as tool errors and do not abort the batch.
- `Agent` exposes both hooks as public, reassignable fields so extension
  reloads can swap implementations mid-session.

Compatibility: fully additive. Both hooks default to undefined and the
loop behaves identically when neither is set. The internal
`executeToolCalls` signature was collapsed to `(context, message,
signal, stream, config)` -- it is not exported, so this is not a public
API change. Pi-mono's `terminate` field on `AfterToolCallResult` is
omitted because our `AgentToolResult` has no batch-level early-stop
contract.
2026-05-15 09:16:44 +02:00
..
2026-05-10 19:52:44 +02:00
2026-05-12 04:09:33 +02:00