MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / executePreCompactHooks

Function executePreCompactHooks

source code/utils/hooks.ts:3963–4027  ·  view source on GitHub ↗
(
  compactData: {
    trigger: 'manual' | 'auto'
    customInstructions: string | null
  },
  signal?: AbortSignal,
  timeoutMs: number = TOOL_HOOK_EXECUTION_TIMEOUT_MS,
)

Source from the content-addressed store, hash-verified

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

Callers 3

compactViaReactiveFunction · 0.85
compactConversationFunction · 0.85

Calls 2

createBaseHookInputFunction · 0.85
executeHooksOutsideREPLFunction · 0.85

Tested by

no test coverage detected