(
compactData: {
trigger: 'manual' | 'auto'
customInstructions: string | null
},
signal?: AbortSignal,
timeoutMs: number = TOOL_HOOK_EXECUTION_TIMEOUT_MS,
)
| 3959 | * @returns Object with optional newCustomInstructions and userDisplayMessage |
| 3960 | */ |
| 3961 | export async function executePreCompactHooks( |
| 3962 | compactData: { |
| 3963 | trigger: 'manual' | 'auto' |
| 3964 | customInstructions: string | null |
| 3965 | }, |
| 3966 | signal?: AbortSignal, |
| 3967 | timeoutMs: number = TOOL_HOOK_EXECUTION_TIMEOUT_MS, |
| 3968 | ): Promise<{ |
| 3969 | newCustomInstructions?: string |
| 3970 | userDisplayMessage?: string |
| 3971 | }> { |
| 3972 | const hookInput: PreCompactHookInput = { |
| 3973 | ...createBaseHookInput(undefined), |
| 3974 | hook_event_name: 'PreCompact', |
| 3975 | trigger: compactData.trigger, |
| 3976 | custom_instructions: compactData.customInstructions, |
| 3977 | } |
| 3978 | |
| 3979 | const results = await executeHooksOutsideREPL({ |
| 3980 | hookInput, |
| 3981 | matchQuery: compactData.trigger, |
| 3982 | signal, |
| 3983 | timeoutMs, |
| 3984 | }) |
| 3985 | |
| 3986 | if (results.length === 0) { |
| 3987 | return {} |
| 3988 | } |
| 3989 | |
| 3990 | // Extract custom instructions from successful hooks with non-empty output |
| 3991 | const successfulOutputs = results |
| 3992 | .filter(result => result.succeeded && result.output.trim().length > 0) |
| 3993 | .map(result => result.output.trim()) |
| 3994 | |
| 3995 | // Build user display messages with command info |
| 3996 | const displayMessages: string[] = [] |
| 3997 | for (const result of results) { |
| 3998 | if (result.succeeded) { |
| 3999 | if (result.output.trim()) { |
| 4000 | displayMessages.push( |
| 4001 | `PreCompact [${result.command}] completed successfully: ${result.output.trim()}`, |
| 4002 | ) |
| 4003 | } else { |
| 4004 | displayMessages.push( |
| 4005 | `PreCompact [${result.command}] completed successfully`, |
| 4006 | ) |
| 4007 | } |
| 4008 | } else { |
| 4009 | if (result.output.trim()) { |
| 4010 | displayMessages.push( |
| 4011 | `PreCompact [${result.command}] failed: ${result.output.trim()}`, |
| 4012 | ) |
| 4013 | } else { |
| 4014 | displayMessages.push(`PreCompact [${result.command}] failed`) |
| 4015 | } |
| 4016 | } |
| 4017 | } |
| 4018 |
no test coverage detected