(
compactData: {
trigger: 'manual' | 'auto'
customInstructions: string | null
},
signal?: AbortSignal,
timeoutMs: number = TOOL_HOOK_EXECUTION_TIMEOUT_MS,
)
| 4054 | * @returns Object with optional newCustomInstructions and userDisplayMessage |
| 4055 | */ |
| 4056 | export async function executePreCompactHooks( |
| 4057 | compactData: { |
| 4058 | trigger: 'manual' | 'auto' |
| 4059 | customInstructions: string | null |
| 4060 | }, |
| 4061 | signal?: AbortSignal, |
| 4062 | timeoutMs: number = TOOL_HOOK_EXECUTION_TIMEOUT_MS, |
| 4063 | ): Promise<{ |
| 4064 | newCustomInstructions?: string |
| 4065 | userDisplayMessage?: string |
| 4066 | }> { |
| 4067 | const hookInput: PreCompactHookInput = { |
| 4068 | ...createBaseHookInput(undefined), |
| 4069 | hook_event_name: 'PreCompact', |
| 4070 | trigger: compactData.trigger, |
| 4071 | custom_instructions: compactData.customInstructions, |
| 4072 | } |
| 4073 | |
| 4074 | const results = await executeHooksOutsideREPL({ |
| 4075 | hookInput, |
| 4076 | matchQuery: compactData.trigger, |
| 4077 | signal, |
| 4078 | timeoutMs, |
| 4079 | }) |
| 4080 | |
| 4081 | if (results.length === 0) { |
| 4082 | return {} |
| 4083 | } |
| 4084 | |
| 4085 | // Extract custom instructions from successful hooks with non-empty output |
| 4086 | const successfulOutputs = results |
| 4087 | .filter(result => result.succeeded && result.output.trim().length > 0) |
| 4088 | .map(result => result.output.trim()) |
| 4089 | |
| 4090 | // Build user display messages with command info |
| 4091 | const displayMessages: string[] = [] |
| 4092 | for (const result of results) { |
| 4093 | if (result.succeeded) { |
| 4094 | if (result.output.trim()) { |
| 4095 | displayMessages.push( |
| 4096 | `PreCompact [${result.command}] completed successfully: ${result.output.trim()}`, |
| 4097 | ) |
| 4098 | } else { |
| 4099 | displayMessages.push( |
| 4100 | `PreCompact [${result.command}] completed successfully`, |
| 4101 | ) |
| 4102 | } |
| 4103 | } else { |
| 4104 | if (result.output.trim()) { |
| 4105 | displayMessages.push( |
| 4106 | `PreCompact [${result.command}] failed: ${result.output.trim()}`, |
| 4107 | ) |
| 4108 | } else { |
| 4109 | displayMessages.push(`PreCompact [${result.command}] failed`) |
| 4110 | } |
| 4111 | } |
| 4112 | } |
| 4113 |
no test coverage detected