Skip to content
Français

defineCopilotHook

import { defineCopilotHook } from "@elie-laloum/outpost/core";

Declare a native Copilot lifecycle hook for its CLI harness. Select a documented event and supply either a host callback or a sandbox command. Callback results are checked against that event’s native schema before delivery. COPILOT_HOME must match the sandbox home. userPromptSubmitted command output is ignored; use userPromptTransformed to rewrite the prompt.

Complete example and detailed rules.

The fields below cover all variants; the signature specifies their allowed combinations.

  • optionsRequired
    CopilotHookOptions<Phase>
    Native Copilot event, optional matcher and deadline, and exactly one host callback or sandbox command.
  • options.onRequired
    Phase
    Native event name; determines the event payload and permitted response.
  • options.nameOptional
    string | undefined
    Optional diagnostic name; defaults to the native event name.
  • options.matcherOptional
    string | undefined
    Native matcher, interpreted by the selected CLI. Omit it to receive every occurrence supported by that event.
  • options.timeoutMsOptional
    number | undefined
    Positive callback or command deadline in milliseconds; defaults to 30000, at most 600000. Native event time limits still apply.
  • options.commandVariant-dependent
    HookCommand | undefined
    Executable invoked inside the sandbox with native JSON on stdin. Stdout, stderr and exit status retain the CLI’s native meaning. Mutually exclusive with run.
  • options.runVariant-dependent
    undefined | (context: AgentHookContext & { readonly event: CopilotHookEvents[Phase]; }) => void | CopilotHookDecisions[Phase] | Promise<void | CopilotHookDecisions[Phase]>
    Host callback receiving the native event, a borrowed sandbox and cancellation signal. Return nothing to preserve native behavior; return only decisions supported by this event. Mutually exclusive with command.

CopilotHook<Phase>

export declare function defineCopilotHook<Phase extends CopilotHookPhase>(
  options: CopilotHookOptions<Phase>,
): CopilotHook<Phase>;