(
compactData: {
trigger: 'manual' | 'auto'
customInstructions: string | null
},
signal?: AbortSignal,
timeoutMs: number = TOOL_HOOK_EXECUTION_TIMEOUT_MS,
)
| 4118 | * @returns Object with optional newCustomInstructions and userDisplayMessage |
| 4119 | */ |
| 4120 | export async function executePreCompactHooks( |
| 4121 | compactData: { |
| 4122 | trigger: 'manual' | 'auto' |
| 4123 | customInstructions: string | null |
| 4124 | }, |
| 4125 | signal?: AbortSignal, |
| 4126 | timeoutMs: number = TOOL_HOOK_EXECUTION_TIMEOUT_MS, |
| 4127 | ): Promise<{ |
| 4128 | newCustomInstructions?: string |
| 4129 | userDisplayMessage?: string |
| 4130 | }> { |
| 4131 | const hookInput: PreCompactHookInput = { |
| 4132 | ...createBaseHookInput(undefined), |
| 4133 | hook_event_name: 'PreCompact', |
| 4134 | trigger: compactData.trigger, |
| 4135 | custom_instructions: compactData.customInstructions, |
| 4136 | } |
| 4137 | |
| 4138 | const results = await executeHooksOutsideREPL({ |
| 4139 | hookInput, |
| 4140 | matchQuery: compactData.trigger, |
| 4141 | signal, |
| 4142 | timeoutMs, |
| 4143 | }) |
| 4144 | |
| 4145 | if (results.length === 0) { |
| 4146 | return {} |
| 4147 | } |
| 4148 | |
| 4149 | // Extract custom instructions from successful hooks with non-empty output |
| 4150 | const successfulOutputs = results |
| 4151 | .filter(result => result.succeeded && result.output.trim().length > 0) |
| 4152 | .map(result => result.output.trim()) |
| 4153 | |
| 4154 | // Build user display messages with command info |
| 4155 | const displayMessages: string[] = [] |
| 4156 | for (const result of results) { |
| 4157 | if (result.succeeded) { |
| 4158 | if (result.output.trim()) { |
| 4159 | displayMessages.push( |
| 4160 | `PreCompact [${result.command}] completed successfully: ${result.output.trim()}`, |
| 4161 | ) |
| 4162 | } else { |
| 4163 | displayMessages.push( |
| 4164 | `PreCompact [${result.command}] completed successfully`, |
| 4165 | ) |
| 4166 | } |
| 4167 | } else { |
| 4168 | if (result.output.trim()) { |
| 4169 | displayMessages.push( |
| 4170 | `PreCompact [${result.command}] failed: ${result.output.trim()}`, |
| 4171 | ) |
| 4172 | } else { |
| 4173 | displayMessages.push(`PreCompact [${result.command}] failed`) |
| 4174 | } |
| 4175 | } |
| 4176 | } |
| 4177 |
no test coverage detected