1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
//! The tool-use filter seam.
//!
//! `ToolUseHook` is THE extension point for the tool-use batch between
//! model output and tool dispatch: `TurnRunner` calls it here, and the
//! concrete filter policies (`DedupFilter`, `DenyAllFilter`,
//! `FilterChain`) in this crate implement it directly. Defining the trait
//! next to both its consumer (the driver) and its policies (the filters)
//! keeps the seam, its only consumer, and its implementations together.
//!
//! ## Minimum invariant, not a policy
//!
//! This crate ships **no opinion** in the trait: the only built-in impl is
//! `PassthroughHook` — a zero-sized type that admits every call unchanged.
//! That is the literal absence of behavior, the minimum the trait requires
//! to be callable.
//!
//! Specific filter policies (dedup by `(tool_name, arguments)`,
//! approval-rewrites-amount, kill-switch denial, etc.) are host concerns;
//! the driver applies whatever hook the caller plugged via
//! `TurnRunner::with_hook(_, _, your_hook)`; `TurnRunner::new()` defaults
//! to `PassthroughHook`.
use async_trait;
use crateUnknownOutcomePolicy;
use ToolResultPayload;
use ;
// This trait is deliberately NOT a `causa_kernel::ports` item:
// a port there is a host-facing contract third parties implement against
// the facts crate alone. The hook's sole consumer is this crate's driver,
// so the contract lives with the driver.
/// One explicit per-call unknown-outcome decision —
/// host decision / checkpoint data attached to a precomputed result whose
/// status is `UnknownOutcome`, not a result envelope: the recorded result
/// is committed verbatim either way. Where a decision set is a *new* host
/// input (hook, `BatchDecision::Reject`, resume), entries may be omitted —
/// the missing ones resolve through [`UnknownOutcomeConfig`](crate::config::UnknownOutcomeConfig)
/// by the executed tool name. Where it is a checkpoint
/// ([`PreparedApproval`](crate::driver::PreparedApproval)), it must
/// exactly cover the saved `UnknownOutcome` results.
/// Context supplied to every hook invocation.
///
/// `control: &CallControl` exposes the bounded attempt / call cancellation
/// so a filter can `select!` on user-approval responses.
/// Result of a hook pass.
///
/// Invariant: `rejected` must reuse the original `payload.call_id` from
/// the input batch; forging a new id would make `append_tool_results`
/// reject the entry with `UnpairedToolResult`. `to_execute` may rewrite
/// `arguments` (open `FilterResult` — approval can rewrite, defer, split).
///
/// `rejected` carries the recorded results only. A host precomputing an
/// `UnknownOutcome` result may pin its continuation action in
/// `unknown_decisions`; entries may be omitted and the driver then resolves
/// through its unknown-outcome configuration by the executed tool name.
/// Rejections with any other status take no action and need no entry.
/// The tool-use filter seam this component exposes.
///
/// Filters in `causa_runtime::filter` (`FilterChain` and friends)
/// implement this trait. The driver calls `hook.apply(calls, ctx).await`
/// between receiving the model's `ToolCallPayload` batch and dispatching
/// it to `ToolExecutor`.
/// Zero-sized hook that admits every call unchanged — the literal
/// absence of behavior, not a policy.
///
/// `TurnRunner::new()` defaults to this hook: callers who want a filter
/// chain opt in via `TurnRunner::with_hook(_, _, filter_chain)`.
/// Concrete filter policies (dedup, approval, kill-switch) are host
/// concerns and live in `causa_runtime::filter` or beyond.
;