fix(plugins): expose effective context budget in hooks

Add optional context budget/source/reference metadata to plugin hook contexts plus llm_output and sanitized model_call_* hook events.

Thread the existing resolved context-window info through Pi embedded runs, CLI harness runs, and Codex app-server hook emission so plugins can observe the effective budget after agent/model/config caps.

Document the metadata and cover the CLI, Pi, Codex app-server, and model-call paths with focused tests.

Fixes #64327.
This commit is contained in:
Val Alexander
2026-05-14 17:51:53 -05:00
committed by GitHub
parent 4004c9342d
commit eb4e20ca1d
16 changed files with 199 additions and 5 deletions

View File

@@ -196,8 +196,20 @@ export type PluginHookAgentContext = {
messageProvider?: string;
trigger?: string;
channelId?: string;
/** Resolved effective context-token budget after model/config/agent caps. */
contextTokenBudget?: number;
/** Source that supplied the resolved context-token budget. */
contextWindowSource?: PluginHookContextWindowSource;
/** Native/configured reference window when a lower cap wins. */
contextWindowReferenceTokens?: number;
};
export type PluginHookContextWindowSource =
| "model"
| "modelsConfig"
| "agentContextTokens"
| "default";
export type PluginHookBeforeAgentReplyEvent = {
cleanedBody: string;
};
@@ -229,6 +241,12 @@ export type PluginHookModelCallBaseEvent = {
model: string;
api?: string;
transport?: string;
/** Resolved effective context-token budget after model/config/agent caps. */
contextTokenBudget?: number;
/** Source that supplied the resolved context-token budget. */
contextWindowSource?: PluginHookContextWindowSource;
/** Native/configured reference window when a lower cap wins. */
contextWindowReferenceTokens?: number;
};
export type PluginHookModelCallStartedEvent = PluginHookModelCallBaseEvent;
@@ -249,6 +267,12 @@ export type PluginHookLlmOutputEvent = {
sessionId: string;
provider: string;
model: string;
/** Resolved effective context-token budget after model/config/agent caps. */
contextTokenBudget?: number;
/** Source that supplied the resolved context-token budget. */
contextWindowSource?: PluginHookContextWindowSource;
/** Native/configured reference window when a lower cap wins. */
contextWindowReferenceTokens?: number;
/**
* Fully resolved provider/model ref used for the call.
*