Skip to content

Persistent Context Across Sessions for Every Agent – Captures everything your agent does during sessions, compresses it with AI, and injects relevant context back into future sessions. Works with Claude Code, OpenClaw, Codex, Gemini, Hermes, Copilot, OpenCode + More

3.5 KB
Raw Blame
export interface NormalizedHookInput {
  sessionId: string;
  cwd: string;
  platform?: string;   
  prompt?: string;
  toolName?: string;
  /** Exact host tool name before normalization, retained for configured exclusions. */
  nativeToolName?: string;
  toolInput?: unknown;
  toolResponse?: unknown;
  /**
   * Provider-assigned id for THIS tool call. Already honoured downstream (the
   * pending_messages dedupe index and the durable `tool_uses` side index both
   * key on it); adapters simply never forwarded it from the hook payload, so
   * only the transcript-watch path populated it. Optional everywhere: a
   * platform that omits it still ingests, it just cannot be de-duplicated.
   */
  toolUseId?: string;
  transcriptPath?: string;
  /** Claude Code SubagentStop only: the finished subagent's own transcript (agent_transcript_path). */
  agentTranscriptPath?: string;
  lastAssistantMessage?: string;
  reason?: string;
  turnId?: string;
  /** Codex only; the Claude Code adapter deliberately leaves it unset (see claude-code.ts). */
  stopHookActive?: boolean;
  permissionMode?: string;
  model?: string;
  sessionSource?: 'startup' | 'resume' | 'clear' | 'compact' | 'fork';
  /**
   * Claude Code SessionStart only: the file claude-mem's session-start card
   * will read the terminal banner from (src/shared/session-start-card-slot.ts).
   * Set when the card can draw; the context hook then writes the banner there
   * and sends a one-line systemMessage.
   */
  sessionStartCardFile?: string;
  /** Raw hook event name from the payload (e.g. Kimi binds both Stop and PreCompact to the same internal event — handlers use this to tell them apart). */
  hookEventName?: string;
  filePath?: string;
  edits?: unknown[];
  agentId?: string;
  /**
   * Text the human actually submitted, when the host can tell.
   *
   * Qwen Code sends `submitted_prompt` and fires `UserPromptSubmit` for
   * supported model invocations, which on the core/headless path also covers
   * ToolResult and Hook sends. Those carry no user text, and the host's own
   * guidance is that absence of the field means "unavailable" rather than
   * "fall back to prompt". Three states, all meaningful:
   *
   *   - `undefined` - the host did not send the field; legacy handling stands
   *   - `string`   - the host sent real user-submitted text
   *   - `null`     - the host sent the field with no text: not a user turn
   */
  submittedPrompt?: string | null;
  agentType?: string;    
  /**
   * When the event happened at its source. Unset for a live hook: it happened
   * now, and the handler stamps the hook's clock. The transcript watcher sets
   * the line's own timestamp, or null when the line carries none. Lets the
   * worker tell new work in a deleted session from content that predates the
   * deletion (SessionStore.isBeforeSessionDeletion).
   */
  eventOccurredAtEpochMs?: number | null;
}

export interface HookResult {
  continue?: boolean;
  suppressOutput?: boolean;
  hookSpecificOutput?: {
    hookEventName: string;
    additionalContext: string;
    permissionDecision?: 'allow' | 'deny';
    permissionDecisionReason?: string;
    updatedInput?: Record<string, unknown>;
  };
  systemMessage?: string;
  decision?: 'block' | 'approve';
  reason?: string;
  exitCode?: number;
}

export interface PlatformAdapter {
  normalizeInput(raw: unknown): NormalizedHookInput;
  formatOutput(result: HookResult): unknown;
}

export interface EventHandler {
  execute(input: NormalizedHookInput): Promise<HookResult>;
}