Add configurable hook context spill limits (#34393)

## What changed

- Add `additionalContextLimit` to command hook configuration for events that can emit `additionalContext`.
- Apply the limit independently to each hook's context before it is sent to the model. Unset values retain the 2,500-token default, while `0` disables spilling for that hook.
- Expose configured limits through app-server hook and requirements responses, and show them in the TUI hooks browser.

## Testing

- Cover JSON and TOML parsing, discovery and hashing, per-hook spilling behavior, app-server responses, and TUI rendering.

GitOrigin-RevId: 55ddc2dbbdf9067dceee3e1968c03617bbf6bcea
This commit is contained in:
Andrei Eternal
2026-07-20 18:46:02 +00:00
committed by copyberry
parent bd92b056dd
commit e4836f998d
37 changed files with 679 additions and 85 deletions
@@ -484,6 +484,13 @@ pub enum ConfiguredHookHandler {
#[serde(rename = "statusMessage")]
#[ts(rename = "statusMessage")]
status_message: Option<String>,
/// Approximate token threshold for spilling this hook's `additionalContext` to disk.
/// `null` uses 2,500 tokens; `0` disables spilling for this hook. The threshold is
/// evaluated against the original context; a spilled preview also includes recovery
/// metadata.
#[serde(rename = "additionalContextLimit")]
#[ts(rename = "additionalContextLimit")]
additional_context_limit: Option<usize>,
},
#[serde(rename = "prompt")]
#[ts(rename = "prompt")]
@@ -519,6 +519,9 @@ pub struct HookMetadata {
pub command: Option<String>,
pub timeout_sec: u64,
pub status_message: Option<String>,
/// Configured `additionalContext` spill threshold.
/// `null` uses 2,500 tokens; `0` disables spilling.
pub additional_context_limit: Option<usize>,
pub source_path: AbsolutePathBuf,
pub source: HookSource,
pub plugin_id: Option<String>,