MCPcopy Create free account
hub / github.com/Noumena-Network/code / executePreCompactHooks

Function executePreCompactHooks

src/utils/hooks.ts:3965–4029  ·  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

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

Callers 3

compactViaReactiveFunction · 0.85
compactConversationFunction · 0.85

Calls 2

createBaseHookInputFunction · 0.85
executeHooksOutsideREPLFunction · 0.85

Tested by

no test coverage detected