@mariozechner/pi-coding-agent 0.32.3 → 0.34.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (102) hide show
  1. package/CHANGELOG.md +56 -1
  2. package/README.md +76 -3
  3. package/dist/cli/args.d.ts +5 -1
  4. package/dist/cli/args.d.ts.map +1 -1
  5. package/dist/cli/args.js +18 -1
  6. package/dist/cli/args.js.map +1 -1
  7. package/dist/core/agent-session.d.ts +24 -1
  8. package/dist/core/agent-session.d.ts.map +1 -1
  9. package/dist/core/agent-session.js +65 -9
  10. package/dist/core/agent-session.js.map +1 -1
  11. package/dist/core/bash-executor.d.ts.map +1 -1
  12. package/dist/core/bash-executor.js +2 -1
  13. package/dist/core/bash-executor.js.map +1 -1
  14. package/dist/core/custom-tools/loader.d.ts.map +1 -1
  15. package/dist/core/custom-tools/loader.js +1 -0
  16. package/dist/core/custom-tools/loader.js.map +1 -1
  17. package/dist/core/export-html/template.css +34 -4
  18. package/dist/core/export-html/template.js +17 -4
  19. package/dist/core/hooks/index.d.ts +1 -1
  20. package/dist/core/hooks/index.d.ts.map +1 -1
  21. package/dist/core/hooks/index.js.map +1 -1
  22. package/dist/core/hooks/loader.d.ts +56 -1
  23. package/dist/core/hooks/loader.d.ts.map +1 -1
  24. package/dist/core/hooks/loader.js +54 -2
  25. package/dist/core/hooks/loader.js.map +1 -1
  26. package/dist/core/hooks/runner.d.ts +33 -5
  27. package/dist/core/hooks/runner.d.ts.map +1 -1
  28. package/dist/core/hooks/runner.js +100 -9
  29. package/dist/core/hooks/runner.js.map +1 -1
  30. package/dist/core/hooks/types.d.ts +135 -3
  31. package/dist/core/hooks/types.d.ts.map +1 -1
  32. package/dist/core/hooks/types.js.map +1 -1
  33. package/dist/core/keybindings.d.ts +59 -0
  34. package/dist/core/keybindings.d.ts.map +1 -0
  35. package/dist/core/keybindings.js +149 -0
  36. package/dist/core/keybindings.js.map +1 -0
  37. package/dist/core/sdk.d.ts +3 -0
  38. package/dist/core/sdk.d.ts.map +1 -1
  39. package/dist/core/sdk.js +102 -27
  40. package/dist/core/sdk.js.map +1 -1
  41. package/dist/index.d.ts +1 -1
  42. package/dist/index.d.ts.map +1 -1
  43. package/dist/index.js +1 -1
  44. package/dist/index.js.map +1 -1
  45. package/dist/main.d.ts.map +1 -1
  46. package/dist/main.js +32 -7
  47. package/dist/main.js.map +1 -1
  48. package/dist/modes/interactive/components/custom-editor.d.ts +13 -12
  49. package/dist/modes/interactive/components/custom-editor.d.ts.map +1 -1
  50. package/dist/modes/interactive/components/custom-editor.js +50 -68
  51. package/dist/modes/interactive/components/custom-editor.js.map +1 -1
  52. package/dist/modes/interactive/components/hook-editor.d.ts.map +1 -1
  53. package/dist/modes/interactive/components/hook-editor.js +5 -4
  54. package/dist/modes/interactive/components/hook-editor.js.map +1 -1
  55. package/dist/modes/interactive/components/hook-input.d.ts.map +1 -1
  56. package/dist/modes/interactive/components/hook-input.js +4 -3
  57. package/dist/modes/interactive/components/hook-input.js.map +1 -1
  58. package/dist/modes/interactive/components/hook-selector.d.ts.map +1 -1
  59. package/dist/modes/interactive/components/hook-selector.js +6 -5
  60. package/dist/modes/interactive/components/hook-selector.js.map +1 -1
  61. package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
  62. package/dist/modes/interactive/components/model-selector.js +6 -5
  63. package/dist/modes/interactive/components/model-selector.js.map +1 -1
  64. package/dist/modes/interactive/components/oauth-selector.d.ts.map +1 -1
  65. package/dist/modes/interactive/components/oauth-selector.js +6 -5
  66. package/dist/modes/interactive/components/oauth-selector.js.map +1 -1
  67. package/dist/modes/interactive/components/session-selector.d.ts.map +1 -1
  68. package/dist/modes/interactive/components/session-selector.js +6 -9
  69. package/dist/modes/interactive/components/session-selector.js.map +1 -1
  70. package/dist/modes/interactive/components/tree-selector.d.ts.map +1 -1
  71. package/dist/modes/interactive/components/tree-selector.js +14 -15
  72. package/dist/modes/interactive/components/tree-selector.js.map +1 -1
  73. package/dist/modes/interactive/components/user-message-selector.d.ts.map +1 -1
  74. package/dist/modes/interactive/components/user-message-selector.js +6 -11
  75. package/dist/modes/interactive/components/user-message-selector.js.map +1 -1
  76. package/dist/modes/interactive/interactive-mode.d.ts +34 -1
  77. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  78. package/dist/modes/interactive/interactive-mode.js +300 -64
  79. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  80. package/dist/modes/interactive/theme/theme.d.ts +1 -0
  81. package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
  82. package/dist/modes/interactive/theme/theme.js +3 -0
  83. package/dist/modes/interactive/theme/theme.js.map +1 -1
  84. package/dist/modes/print-mode.d.ts.map +1 -1
  85. package/dist/modes/print-mode.js +3 -0
  86. package/dist/modes/print-mode.js.map +1 -1
  87. package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
  88. package/dist/modes/rpc/rpc-mode.js +16 -0
  89. package/dist/modes/rpc/rpc-mode.js.map +1 -1
  90. package/dist/modes/rpc/rpc-types.d.ts +6 -0
  91. package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
  92. package/dist/modes/rpc/rpc-types.js.map +1 -1
  93. package/docs/hooks.md +114 -4
  94. package/docs/tui.md +18 -15
  95. package/examples/custom-tools/subagent/README.md +2 -2
  96. package/examples/hooks/README.md +3 -0
  97. package/examples/hooks/pirate.ts +44 -0
  98. package/examples/hooks/plan-mode.ts +548 -0
  99. package/examples/hooks/snake.ts +7 -7
  100. package/examples/hooks/todo/index.ts +2 -2
  101. package/examples/hooks/tools.ts +145 -0
  102. package/package.json +5 -4
@@ -1 +1 @@
1
- {"version":3,"file":"runner.js","sourceRoot":"","sources":["../../../src/core/hooks/runner.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,EAAE,KAAK,EAAE,MAAM,wCAAwC,CAAC;AAmC/D,mDAAmD;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEzC,oDAAoD;AACpD,MAA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,GAAG,CAAC,CAAC;oBACjE,IAAI,CAAC,SAAS,CAAC;wBACd,QAAQ,EAAE,IAAI,CAAC,IAAI;wBACnB,KAAK,EAAE,oBAAoB;wBAC3B,KAAK,EAAE,OAAO;qBACd,CAAC,CAAC;gBACJ,CAAC;YACF,CAAC;QACF,CAAC;QAED,OAAO,MAAM,CAAC;IAAA,CACd;CACD","sourcesContent":["/**\n * Hook runner - executes hooks and manages their lifecycle.\n */\n\nimport type { AgentMessage } from \"@mariozechner/pi-agent-core\";\nimport type { Model } from \"@mariozechner/pi-ai\";\nimport { theme } from \"../../modes/interactive/theme/theme.js\";\nimport type { ModelRegistry } from \"../model-registry.js\";\nimport type { SessionManager } from \"../session-manager.js\";\nimport type {\n\tAppendEntryHandler,\n\tBranchHandler,\n\tLoadedHook,\n\tNavigateTreeHandler,\n\tNewSessionHandler,\n\tSendMessageHandler,\n} from \"./loader.js\";\nimport type {\n\tBeforeAgentStartEvent,\n\tBeforeAgentStartEventResult,\n\tContextEvent,\n\tContextEventResult,\n\tHookCommandContext,\n\tHookContext,\n\tHookError,\n\tHookEvent,\n\tHookMessageRenderer,\n\tHookUIContext,\n\tRegisteredCommand,\n\tSessionBeforeCompactResult,\n\tSessionBeforeTreeResult,\n\tToolCallEvent,\n\tToolCallEventResult,\n\tToolResultEventResult,\n} from \"./types.js\";\n\n/**\n * Listener for hook errors.\n */\nexport type HookErrorListener = (error: HookError) => void;\n\n// Re-export execCommand for backward compatibility\nexport { execCommand } from \"../exec.js\";\n\n/** No-op UI context used when no UI is available */\nconst noOpUIContext: HookUIContext = {\n\tselect: async () => undefined,\n\tconfirm: async () => false,\n\tinput: async () => undefined,\n\tnotify: () => {},\n\tsetStatus: () => {},\n\tcustom: async () => undefined as never,\n\tsetEditorText: () => {},\n\tgetEditorText: () => \"\",\n\teditor: async () => undefined,\n\tget theme() {\n\t\treturn theme;\n\t},\n};\n\n/**\n * HookRunner executes hooks and manages event emission.\n */\nexport class HookRunner {\n\tprivate hooks: LoadedHook[];\n\tprivate uiContext: HookUIContext;\n\tprivate hasUI: boolean;\n\tprivate cwd: string;\n\tprivate sessionManager: SessionManager;\n\tprivate modelRegistry: ModelRegistry;\n\tprivate errorListeners: Set<HookErrorListener> = new Set();\n\tprivate getModel: () => Model<any> | undefined = () => undefined;\n\tprivate isIdleFn: () => boolean = () => true;\n\tprivate waitForIdleFn: () => Promise<void> = async () => {};\n\tprivate abortFn: () => void = () => {};\n\tprivate hasPendingMessagesFn: () => boolean = () => false;\n\tprivate newSessionHandler: NewSessionHandler = async () => ({ cancelled: false });\n\tprivate branchHandler: BranchHandler = async () => ({ cancelled: false });\n\tprivate navigateTreeHandler: NavigateTreeHandler = async () => ({ cancelled: false });\n\n\tconstructor(hooks: LoadedHook[], cwd: string, sessionManager: SessionManager, modelRegistry: ModelRegistry) {\n\t\tthis.hooks = hooks;\n\t\tthis.uiContext = noOpUIContext;\n\t\tthis.hasUI = false;\n\t\tthis.cwd = cwd;\n\t\tthis.sessionManager = sessionManager;\n\t\tthis.modelRegistry = modelRegistry;\n\t}\n\n\t/**\n\t * Initialize HookRunner with all required context.\n\t * Modes call this once the agent session is fully set up.\n\t */\n\tinitialize(options: {\n\t\t/** Function to get the current model */\n\t\tgetModel: () => Model<any> | undefined;\n\t\t/** Handler for hooks to send messages */\n\t\tsendMessageHandler: SendMessageHandler;\n\t\t/** Handler for hooks to append entries */\n\t\tappendEntryHandler: AppendEntryHandler;\n\t\t/** Handler for creating new sessions (for HookCommandContext) */\n\t\tnewSessionHandler?: NewSessionHandler;\n\t\t/** Handler for branching sessions (for HookCommandContext) */\n\t\tbranchHandler?: BranchHandler;\n\t\t/** Handler for navigating session tree (for HookCommandContext) */\n\t\tnavigateTreeHandler?: NavigateTreeHandler;\n\t\t/** Function to check if agent is idle */\n\t\tisIdle?: () => boolean;\n\t\t/** Function to wait for agent to be idle */\n\t\twaitForIdle?: () => Promise<void>;\n\t\t/** Function to abort current operation (fire-and-forget) */\n\t\tabort?: () => void;\n\t\t/** Function to check if there are queued messages */\n\t\thasPendingMessages?: () => boolean;\n\t\t/** UI context for interactive prompts */\n\t\tuiContext?: HookUIContext;\n\t\t/** Whether UI is available */\n\t\thasUI?: boolean;\n\t}): void {\n\t\tthis.getModel = options.getModel;\n\t\tthis.isIdleFn = options.isIdle ?? (() => true);\n\t\tthis.waitForIdleFn = options.waitForIdle ?? (async () => {});\n\t\tthis.abortFn = options.abort ?? (() => {});\n\t\tthis.hasPendingMessagesFn = options.hasPendingMessages ?? (() => false);\n\t\t// Store session handlers for HookCommandContext\n\t\tif (options.newSessionHandler) {\n\t\t\tthis.newSessionHandler = options.newSessionHandler;\n\t\t}\n\t\tif (options.branchHandler) {\n\t\t\tthis.branchHandler = options.branchHandler;\n\t\t}\n\t\tif (options.navigateTreeHandler) {\n\t\t\tthis.navigateTreeHandler = options.navigateTreeHandler;\n\t\t}\n\t\t// Set per-hook handlers for pi.sendMessage() and pi.appendEntry()\n\t\tfor (const hook of this.hooks) {\n\t\t\thook.setSendMessageHandler(options.sendMessageHandler);\n\t\t\thook.setAppendEntryHandler(options.appendEntryHandler);\n\t\t}\n\t\tthis.uiContext = options.uiContext ?? noOpUIContext;\n\t\tthis.hasUI = options.hasUI ?? false;\n\t}\n\n\t/**\n\t * Get the UI context (set by mode).\n\t */\n\tgetUIContext(): HookUIContext | null {\n\t\treturn this.uiContext;\n\t}\n\n\t/**\n\t * Get whether UI is available.\n\t */\n\tgetHasUI(): boolean {\n\t\treturn this.hasUI;\n\t}\n\n\t/**\n\t * Get the paths of all loaded hooks.\n\t */\n\tgetHookPaths(): string[] {\n\t\treturn this.hooks.map((h) => h.path);\n\t}\n\n\t/**\n\t * Subscribe to hook errors.\n\t * @returns Unsubscribe function\n\t */\n\tonError(listener: HookErrorListener): () => void {\n\t\tthis.errorListeners.add(listener);\n\t\treturn () => this.errorListeners.delete(listener);\n\t}\n\n\t/**\n\t * Emit an error to all listeners.\n\t */\n\t/**\n\t * Emit an error to all error listeners.\n\t */\n\temitError(error: HookError): void {\n\t\tfor (const listener of this.errorListeners) {\n\t\t\tlistener(error);\n\t\t}\n\t}\n\n\t/**\n\t * Check if any hooks have handlers for the given event type.\n\t */\n\thasHandlers(eventType: string): boolean {\n\t\tfor (const hook of this.hooks) {\n\t\t\tconst handlers = hook.handlers.get(eventType);\n\t\t\tif (handlers && handlers.length > 0) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t}\n\n\t/**\n\t * Get a message renderer for the given customType.\n\t * Returns the first renderer found across all hooks, or undefined if none.\n\t */\n\tgetMessageRenderer(customType: string): HookMessageRenderer | undefined {\n\t\tfor (const hook of this.hooks) {\n\t\t\tconst renderer = hook.messageRenderers.get(customType);\n\t\t\tif (renderer) {\n\t\t\t\treturn renderer;\n\t\t\t}\n\t\t}\n\t\treturn undefined;\n\t}\n\n\t/**\n\t * Get all registered commands from all hooks.\n\t */\n\tgetRegisteredCommands(): RegisteredCommand[] {\n\t\tconst commands: RegisteredCommand[] = [];\n\t\tfor (const hook of this.hooks) {\n\t\t\tfor (const command of hook.commands.values()) {\n\t\t\t\tcommands.push(command);\n\t\t\t}\n\t\t}\n\t\treturn commands;\n\t}\n\n\t/**\n\t * Get a registered command by name.\n\t * Returns the first command found across all hooks, or undefined if none.\n\t */\n\tgetCommand(name: string): RegisteredCommand | undefined {\n\t\tfor (const hook of this.hooks) {\n\t\t\tconst command = hook.commands.get(name);\n\t\t\tif (command) {\n\t\t\t\treturn command;\n\t\t\t}\n\t\t}\n\t\treturn undefined;\n\t}\n\n\t/**\n\t * Create the event context for handlers.\n\t */\n\tprivate createContext(): HookContext {\n\t\treturn {\n\t\t\tui: this.uiContext,\n\t\t\thasUI: this.hasUI,\n\t\t\tcwd: this.cwd,\n\t\t\tsessionManager: this.sessionManager,\n\t\t\tmodelRegistry: this.modelRegistry,\n\t\t\tmodel: this.getModel(),\n\t\t\tisIdle: () => this.isIdleFn(),\n\t\t\tabort: () => this.abortFn(),\n\t\t\thasPendingMessages: () => this.hasPendingMessagesFn(),\n\t\t};\n\t}\n\n\t/**\n\t * Create the command context for slash command handlers.\n\t * Extends HookContext with session control methods that are only safe in commands.\n\t */\n\tcreateCommandContext(): HookCommandContext {\n\t\treturn {\n\t\t\t...this.createContext(),\n\t\t\twaitForIdle: () => this.waitForIdleFn(),\n\t\t\tnewSession: (options) => this.newSessionHandler(options),\n\t\t\tbranch: (entryId) => this.branchHandler(entryId),\n\t\t\tnavigateTree: (targetId, options) => this.navigateTreeHandler(targetId, options),\n\t\t};\n\t}\n\n\t/**\n\t * Check if event type is a session \"before_*\" event that can be cancelled.\n\t */\n\tprivate isSessionBeforeEvent(\n\t\ttype: string,\n\t): type is \"session_before_switch\" | \"session_before_branch\" | \"session_before_compact\" | \"session_before_tree\" {\n\t\treturn (\n\t\t\ttype === \"session_before_switch\" ||\n\t\t\ttype === \"session_before_branch\" ||\n\t\t\ttype === \"session_before_compact\" ||\n\t\t\ttype === \"session_before_tree\"\n\t\t);\n\t}\n\n\t/**\n\t * Emit an event to all hooks.\n\t * Returns the result from session before_* / tool_result events (if any handler returns one).\n\t */\n\tasync emit(\n\t\tevent: HookEvent,\n\t): Promise<SessionBeforeCompactResult | SessionBeforeTreeResult | ToolResultEventResult | undefined> {\n\t\tconst ctx = this.createContext();\n\t\tlet result: SessionBeforeCompactResult | SessionBeforeTreeResult | ToolResultEventResult | undefined;\n\n\t\tfor (const hook of this.hooks) {\n\t\t\tconst handlers = hook.handlers.get(event.type);\n\t\t\tif (!handlers || handlers.length === 0) continue;\n\n\t\t\tfor (const handler of handlers) {\n\t\t\t\ttry {\n\t\t\t\t\tconst handlerResult = await handler(event, ctx);\n\n\t\t\t\t\t// For session before_* events, capture the result (for cancellation)\n\t\t\t\t\tif (this.isSessionBeforeEvent(event.type) && handlerResult) {\n\t\t\t\t\t\tresult = handlerResult as SessionBeforeCompactResult | SessionBeforeTreeResult;\n\t\t\t\t\t\t// If cancelled, stop processing further hooks\n\t\t\t\t\t\tif (result.cancel) {\n\t\t\t\t\t\t\treturn result;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\t// For tool_result events, capture the result\n\t\t\t\t\tif (event.type === \"tool_result\" && handlerResult) {\n\t\t\t\t\t\tresult = handlerResult as ToolResultEventResult;\n\t\t\t\t\t}\n\t\t\t\t} catch (err) {\n\t\t\t\t\tconst message = err instanceof Error ? err.message : String(err);\n\t\t\t\t\tthis.emitError({\n\t\t\t\t\t\thookPath: hook.path,\n\t\t\t\t\t\tevent: event.type,\n\t\t\t\t\t\terror: message,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn result;\n\t}\n\n\t/**\n\t * Emit a tool_call event to all hooks.\n\t * No timeout - user prompts can take as long as needed.\n\t * Errors are thrown (not swallowed) so caller can block on failure.\n\t */\n\tasync emitToolCall(event: ToolCallEvent): Promise<ToolCallEventResult | undefined> {\n\t\tconst ctx = this.createContext();\n\t\tlet result: ToolCallEventResult | undefined;\n\n\t\tfor (const hook of this.hooks) {\n\t\t\tconst handlers = hook.handlers.get(\"tool_call\");\n\t\t\tif (!handlers || handlers.length === 0) continue;\n\n\t\t\tfor (const handler of handlers) {\n\t\t\t\t// No timeout - let user take their time\n\t\t\t\tconst handlerResult = await handler(event, ctx);\n\n\t\t\t\tif (handlerResult) {\n\t\t\t\t\tresult = handlerResult as ToolCallEventResult;\n\t\t\t\t\t// If blocked, stop processing further hooks\n\t\t\t\t\tif (result.block) {\n\t\t\t\t\t\treturn result;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn result;\n\t}\n\n\t/**\n\t * Emit a context event to all hooks.\n\t * Handlers are chained - each gets the previous handler's output (if any).\n\t * Returns the final modified messages, or the original if no modifications.\n\t *\n\t * Note: Messages are already deep-copied by the caller (pi-ai preprocessor).\n\t */\n\tasync emitContext(messages: AgentMessage[]): Promise<AgentMessage[]> {\n\t\tconst ctx = this.createContext();\n\t\tlet currentMessages = messages;\n\n\t\tfor (const hook of this.hooks) {\n\t\t\tconst handlers = hook.handlers.get(\"context\");\n\t\t\tif (!handlers || handlers.length === 0) continue;\n\n\t\t\tfor (const handler of handlers) {\n\t\t\t\ttry {\n\t\t\t\t\tconst event: ContextEvent = { type: \"context\", messages: currentMessages };\n\t\t\t\t\tconst handlerResult = await handler(event, ctx);\n\n\t\t\t\t\tif (handlerResult && (handlerResult as ContextEventResult).messages) {\n\t\t\t\t\t\tcurrentMessages = (handlerResult as ContextEventResult).messages!;\n\t\t\t\t\t}\n\t\t\t\t} catch (err) {\n\t\t\t\t\tconst message = err instanceof Error ? err.message : String(err);\n\t\t\t\t\tthis.emitError({\n\t\t\t\t\t\thookPath: hook.path,\n\t\t\t\t\t\tevent: \"context\",\n\t\t\t\t\t\terror: message,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn currentMessages;\n\t}\n\n\t/**\n\t * Emit before_agent_start event to all hooks.\n\t * Returns the first message to inject (if any handler returns one).\n\t */\n\tasync emitBeforeAgentStart(\n\t\tprompt: string,\n\t\timages?: import(\"@mariozechner/pi-ai\").ImageContent[],\n\t): Promise<BeforeAgentStartEventResult | undefined> {\n\t\tconst ctx = this.createContext();\n\t\tlet result: BeforeAgentStartEventResult | undefined;\n\n\t\tfor (const hook of this.hooks) {\n\t\t\tconst handlers = hook.handlers.get(\"before_agent_start\");\n\t\t\tif (!handlers || handlers.length === 0) continue;\n\n\t\t\tfor (const handler of handlers) {\n\t\t\t\ttry {\n\t\t\t\t\tconst event: BeforeAgentStartEvent = { type: \"before_agent_start\", prompt, images };\n\t\t\t\t\tconst handlerResult = await handler(event, ctx);\n\n\t\t\t\t\t// Take the first message returned\n\t\t\t\t\tif (handlerResult && (handlerResult as BeforeAgentStartEventResult).message && !result) {\n\t\t\t\t\t\tresult = handlerResult as BeforeAgentStartEventResult;\n\t\t\t\t\t}\n\t\t\t\t} catch (err) {\n\t\t\t\t\tconst message = err instanceof Error ? err.message : String(err);\n\t\t\t\t\tthis.emitError({\n\t\t\t\t\t\thookPath: hook.path,\n\t\t\t\t\t\tevent: \"before_agent_start\",\n\t\t\t\t\t\terror: message,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn result;\n\t}\n}\n"]}
1
+ {"version":3,"file":"runner.js","sourceRoot":"","sources":["../../../src/core/hooks/runner.ts"],"names":[],"mappings":"AAAA;;GAEG;AAKH,OAAO,EAAE,KAAK,EAAE,MAAM,wCAAwC,CAAC;AA2C/D,mDAAmD;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEzC,oDAAoD;AACpD,MAAM,aAAa,GAAkB;IACpC,MAAM,EAAE,KAAK,IAAI,EAAE,CAAC,SAAS;IAC7B,OAAO,EAAE,KAAK,IAAI,EAAE,CAAC,KAAK;IAC1B,KAAK,EAAE,KAAK,IAAI,EAAE,CAAC,SAAS;IAC5B,MAAM,EAAE,GAAG,EAAE,CAAC,EAAC,CAAC;IAChB,SAAS,EAAE,GAAG,EAAE,CAAC,EAAC,CAAC;IACnB,SAAS,EAAE,GAAG,EAAE,CAAC,EAAC,CAAC;IACnB,MAAM,EAAE,KAAK,IAAI,EAAE,CAAC,SAAkB;IACtC,aAAa,EAAE,GAAG,EAAE,CAAC,EAAC,CAAC;IACvB,aAAa,EAAE,GAAG,EAAE,CAAC,EAAE;IACvB,MAAM,EAAE,KAAK,IAAI,EAAE,CAAC,SAAS;IAC7B,IAAI,KAAK,GAAG;QACX,OAAO,KAAK,CAAC;IAAA,CACb;CACD,CAAC;AAEF;;GAEG;AACH,MAAM,OAAO,UAAU;IACd,KAAK,CAAe;IACpB,SAAS,CAAgB;IACzB,KAAK,CAAU;IACf,GAAG,CAAS;IACZ,cAAc,CAAiB;IAC/B,aAAa,CAAgB;IAC7B,cAAc,GAA2B,IAAI,GAAG,EAAE,CAAC;IACnD,QAAQ,GAAiC,GAAG,EAAE,CAAC,SAAS,CAAC;I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;QAED,OAAO,SAAS,CAAC;IAAA,CACjB;CACD","sourcesContent":["/**\n * Hook runner - executes hooks and manages their lifecycle.\n */\n\nimport type { AgentMessage } from \"@mariozechner/pi-agent-core\";\nimport type { ImageContent, Model } from \"@mariozechner/pi-ai\";\nimport type { KeyId } from \"@mariozechner/pi-tui\";\nimport { theme } from \"../../modes/interactive/theme/theme.js\";\nimport type { ModelRegistry } from \"../model-registry.js\";\nimport type { SessionManager } from \"../session-manager.js\";\nimport type {\n\tAppendEntryHandler,\n\tBranchHandler,\n\tHookFlag,\n\tHookShortcut,\n\tLoadedHook,\n\tNavigateTreeHandler,\n\tNewSessionHandler,\n\tSendMessageHandler,\n} from \"./loader.js\";\nimport type {\n\tBeforeAgentStartEvent,\n\tBeforeAgentStartEventResult,\n\tContextEvent,\n\tContextEventResult,\n\tHookCommandContext,\n\tHookContext,\n\tHookError,\n\tHookEvent,\n\tHookMessageRenderer,\n\tHookUIContext,\n\tRegisteredCommand,\n\tSessionBeforeCompactResult,\n\tSessionBeforeTreeResult,\n\tToolCallEvent,\n\tToolCallEventResult,\n\tToolResultEventResult,\n} from \"./types.js\";\n\n/** Combined result from all before_agent_start handlers (internal) */\ninterface BeforeAgentStartCombinedResult {\n\tmessages?: NonNullable<BeforeAgentStartEventResult[\"message\"]>[];\n\tsystemPromptAppend?: string;\n}\n\n/**\n * Listener for hook errors.\n */\nexport type HookErrorListener = (error: HookError) => void;\n\n// Re-export execCommand for backward compatibility\nexport { execCommand } from \"../exec.js\";\n\n/** No-op UI context used when no UI is available */\nconst noOpUIContext: HookUIContext = {\n\tselect: async () => undefined,\n\tconfirm: async () => false,\n\tinput: async () => undefined,\n\tnotify: () => {},\n\tsetStatus: () => {},\n\tsetWidget: () => {},\n\tcustom: async () => undefined as never,\n\tsetEditorText: () => {},\n\tgetEditorText: () => \"\",\n\teditor: async () => undefined,\n\tget theme() {\n\t\treturn theme;\n\t},\n};\n\n/**\n * HookRunner executes hooks and manages event emission.\n */\nexport class HookRunner {\n\tprivate hooks: LoadedHook[];\n\tprivate uiContext: HookUIContext;\n\tprivate hasUI: boolean;\n\tprivate cwd: string;\n\tprivate sessionManager: SessionManager;\n\tprivate modelRegistry: ModelRegistry;\n\tprivate errorListeners: Set<HookErrorListener> = new Set();\n\tprivate getModel: () => Model<any> | undefined = () => undefined;\n\tprivate isIdleFn: () => boolean = () => true;\n\tprivate waitForIdleFn: () => Promise<void> = async () => {};\n\tprivate abortFn: () => void = () => {};\n\tprivate hasPendingMessagesFn: () => boolean = () => false;\n\tprivate newSessionHandler: NewSessionHandler = async () => ({ cancelled: false });\n\tprivate branchHandler: BranchHandler = async () => ({ cancelled: false });\n\tprivate navigateTreeHandler: NavigateTreeHandler = async () => ({ cancelled: false });\n\n\tconstructor(hooks: LoadedHook[], cwd: string, sessionManager: SessionManager, modelRegistry: ModelRegistry) {\n\t\tthis.hooks = hooks;\n\t\tthis.uiContext = noOpUIContext;\n\t\tthis.hasUI = false;\n\t\tthis.cwd = cwd;\n\t\tthis.sessionManager = sessionManager;\n\t\tthis.modelRegistry = modelRegistry;\n\t}\n\n\t/**\n\t * Initialize HookRunner with all required context.\n\t * Modes call this once the agent session is fully set up.\n\t */\n\tinitialize(options: {\n\t\t/** Function to get the current model */\n\t\tgetModel: () => Model<any> | undefined;\n\t\t/** Handler for hooks to send messages */\n\t\tsendMessageHandler: SendMessageHandler;\n\t\t/** Handler for hooks to append entries */\n\t\tappendEntryHandler: AppendEntryHandler;\n\t\t/** Handler for getting current active tools */\n\t\tgetActiveToolsHandler: () => string[];\n\t\t/** Handler for getting all configured tools */\n\t\tgetAllToolsHandler: () => string[];\n\t\t/** Handler for setting active tools */\n\t\tsetActiveToolsHandler: (toolNames: string[]) => void;\n\t\t/** Handler for creating new sessions (for HookCommandContext) */\n\t\tnewSessionHandler?: NewSessionHandler;\n\t\t/** Handler for branching sessions (for HookCommandContext) */\n\t\tbranchHandler?: BranchHandler;\n\t\t/** Handler for navigating session tree (for HookCommandContext) */\n\t\tnavigateTreeHandler?: NavigateTreeHandler;\n\t\t/** Function to check if agent is idle */\n\t\tisIdle?: () => boolean;\n\t\t/** Function to wait for agent to be idle */\n\t\twaitForIdle?: () => Promise<void>;\n\t\t/** Function to abort current operation (fire-and-forget) */\n\t\tabort?: () => void;\n\t\t/** Function to check if there are queued messages */\n\t\thasPendingMessages?: () => boolean;\n\t\t/** UI context for interactive prompts */\n\t\tuiContext?: HookUIContext;\n\t\t/** Whether UI is available */\n\t\thasUI?: boolean;\n\t}): void {\n\t\tthis.getModel = options.getModel;\n\t\tthis.isIdleFn = options.isIdle ?? (() => true);\n\t\tthis.waitForIdleFn = options.waitForIdle ?? (async () => {});\n\t\tthis.abortFn = options.abort ?? (() => {});\n\t\tthis.hasPendingMessagesFn = options.hasPendingMessages ?? (() => false);\n\t\t// Store session handlers for HookCommandContext\n\t\tif (options.newSessionHandler) {\n\t\t\tthis.newSessionHandler = options.newSessionHandler;\n\t\t}\n\t\tif (options.branchHandler) {\n\t\t\tthis.branchHandler = options.branchHandler;\n\t\t}\n\t\tif (options.navigateTreeHandler) {\n\t\t\tthis.navigateTreeHandler = options.navigateTreeHandler;\n\t\t}\n\t\t// Set per-hook handlers for pi.sendMessage(), pi.appendEntry(), pi.getActiveTools(), pi.getAllTools(), pi.setActiveTools()\n\t\tfor (const hook of this.hooks) {\n\t\t\thook.setSendMessageHandler(options.sendMessageHandler);\n\t\t\thook.setAppendEntryHandler(options.appendEntryHandler);\n\t\t\thook.setGetActiveToolsHandler(options.getActiveToolsHandler);\n\t\t\thook.setGetAllToolsHandler(options.getAllToolsHandler);\n\t\t\thook.setSetActiveToolsHandler(options.setActiveToolsHandler);\n\t\t}\n\t\tthis.uiContext = options.uiContext ?? noOpUIContext;\n\t\tthis.hasUI = options.hasUI ?? false;\n\t}\n\n\t/**\n\t * Get the UI context (set by mode).\n\t */\n\tgetUIContext(): HookUIContext | null {\n\t\treturn this.uiContext;\n\t}\n\n\t/**\n\t * Get whether UI is available.\n\t */\n\tgetHasUI(): boolean {\n\t\treturn this.hasUI;\n\t}\n\n\t/**\n\t * Get the paths of all loaded hooks.\n\t */\n\tgetHookPaths(): string[] {\n\t\treturn this.hooks.map((h) => h.path);\n\t}\n\n\t/**\n\t * Get all CLI flags registered by hooks.\n\t */\n\tgetFlags(): Map<string, HookFlag> {\n\t\tconst allFlags = new Map<string, HookFlag>();\n\t\tfor (const hook of this.hooks) {\n\t\t\tfor (const [name, flag] of hook.flags) {\n\t\t\t\tallFlags.set(name, flag);\n\t\t\t}\n\t\t}\n\t\treturn allFlags;\n\t}\n\n\t/**\n\t * Set a flag value (after CLI parsing).\n\t */\n\tsetFlagValue(name: string, value: boolean | string): void {\n\t\tfor (const hook of this.hooks) {\n\t\t\tif (hook.flags.has(name)) {\n\t\t\t\thook.setFlagValue(name, value);\n\t\t\t}\n\t\t}\n\t}\n\n\t// Built-in shortcuts that hooks should not override\n\tprivate static readonly RESERVED_SHORTCUTS = new Set([\n\t\t\"ctrl+c\",\n\t\t\"ctrl+d\",\n\t\t\"ctrl+z\",\n\t\t\"ctrl+k\",\n\t\t\"ctrl+p\",\n\t\t\"ctrl+l\",\n\t\t\"ctrl+o\",\n\t\t\"ctrl+t\",\n\t\t\"ctrl+g\",\n\t\t\"shift+tab\",\n\t\t\"shift+ctrl+p\",\n\t\t\"alt+enter\",\n\t\t\"escape\",\n\t\t\"enter\",\n\t]);\n\n\t/**\n\t * Get all keyboard shortcuts registered by hooks.\n\t * When multiple hooks register the same shortcut, the last one wins.\n\t * Conflicts with built-in shortcuts are skipped with a warning.\n\t * Conflicts between hooks are logged as warnings.\n\t */\n\tgetShortcuts(): Map<KeyId, HookShortcut> {\n\t\tconst allShortcuts = new Map<KeyId, HookShortcut>();\n\t\tfor (const hook of this.hooks) {\n\t\t\tfor (const [key, shortcut] of hook.shortcuts) {\n\t\t\t\t// Normalize to lowercase for comparison (KeyId is string at runtime)\n\t\t\t\tconst normalizedKey = key.toLowerCase() as KeyId;\n\n\t\t\t\t// Check for built-in shortcut conflicts\n\t\t\t\tif (HookRunner.RESERVED_SHORTCUTS.has(normalizedKey)) {\n\t\t\t\t\tconsole.warn(\n\t\t\t\t\t\t`Hook shortcut '${key}' from ${shortcut.hookPath} conflicts with built-in shortcut. Skipping.`,\n\t\t\t\t\t);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tconst existing = allShortcuts.get(normalizedKey);\n\t\t\t\tif (existing) {\n\t\t\t\t\t// Log conflict between hooks - last one wins\n\t\t\t\t\tconsole.warn(\n\t\t\t\t\t\t`Hook shortcut conflict: '${key}' registered by both ${existing.hookPath} and ${shortcut.hookPath}. Using ${shortcut.hookPath}.`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tallShortcuts.set(normalizedKey, shortcut);\n\t\t\t}\n\t\t}\n\t\treturn allShortcuts;\n\t}\n\n\t/**\n\t * Subscribe to hook errors.\n\t * @returns Unsubscribe function\n\t */\n\tonError(listener: HookErrorListener): () => void {\n\t\tthis.errorListeners.add(listener);\n\t\treturn () => this.errorListeners.delete(listener);\n\t}\n\n\t/**\n\t * Emit an error to all listeners.\n\t */\n\t/**\n\t * Emit an error to all error listeners.\n\t */\n\temitError(error: HookError): void {\n\t\tfor (const listener of this.errorListeners) {\n\t\t\tlistener(error);\n\t\t}\n\t}\n\n\t/**\n\t * Check if any hooks have handlers for the given event type.\n\t */\n\thasHandlers(eventType: string): boolean {\n\t\tfor (const hook of this.hooks) {\n\t\t\tconst handlers = hook.handlers.get(eventType);\n\t\t\tif (handlers && handlers.length > 0) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t}\n\n\t/**\n\t * Get a message renderer for the given customType.\n\t * Returns the first renderer found across all hooks, or undefined if none.\n\t */\n\tgetMessageRenderer(customType: string): HookMessageRenderer | undefined {\n\t\tfor (const hook of this.hooks) {\n\t\t\tconst renderer = hook.messageRenderers.get(customType);\n\t\t\tif (renderer) {\n\t\t\t\treturn renderer;\n\t\t\t}\n\t\t}\n\t\treturn undefined;\n\t}\n\n\t/**\n\t * Get all registered commands from all hooks.\n\t */\n\tgetRegisteredCommands(): RegisteredCommand[] {\n\t\tconst commands: RegisteredCommand[] = [];\n\t\tfor (const hook of this.hooks) {\n\t\t\tfor (const command of hook.commands.values()) {\n\t\t\t\tcommands.push(command);\n\t\t\t}\n\t\t}\n\t\treturn commands;\n\t}\n\n\t/**\n\t * Get a registered command by name.\n\t * Returns the first command found across all hooks, or undefined if none.\n\t */\n\tgetCommand(name: string): RegisteredCommand | undefined {\n\t\tfor (const hook of this.hooks) {\n\t\t\tconst command = hook.commands.get(name);\n\t\t\tif (command) {\n\t\t\t\treturn command;\n\t\t\t}\n\t\t}\n\t\treturn undefined;\n\t}\n\n\t/**\n\t * Create the event context for handlers.\n\t */\n\tprivate createContext(): HookContext {\n\t\treturn {\n\t\t\tui: this.uiContext,\n\t\t\thasUI: this.hasUI,\n\t\t\tcwd: this.cwd,\n\t\t\tsessionManager: this.sessionManager,\n\t\t\tmodelRegistry: this.modelRegistry,\n\t\t\tmodel: this.getModel(),\n\t\t\tisIdle: () => this.isIdleFn(),\n\t\t\tabort: () => this.abortFn(),\n\t\t\thasPendingMessages: () => this.hasPendingMessagesFn(),\n\t\t};\n\t}\n\n\t/**\n\t * Create the command context for slash command handlers.\n\t * Extends HookContext with session control methods that are only safe in commands.\n\t */\n\tcreateCommandContext(): HookCommandContext {\n\t\treturn {\n\t\t\t...this.createContext(),\n\t\t\twaitForIdle: () => this.waitForIdleFn(),\n\t\t\tnewSession: (options) => this.newSessionHandler(options),\n\t\t\tbranch: (entryId) => this.branchHandler(entryId),\n\t\t\tnavigateTree: (targetId, options) => this.navigateTreeHandler(targetId, options),\n\t\t};\n\t}\n\n\t/**\n\t * Check if event type is a session \"before_*\" event that can be cancelled.\n\t */\n\tprivate isSessionBeforeEvent(\n\t\ttype: string,\n\t): type is \"session_before_switch\" | \"session_before_branch\" | \"session_before_compact\" | \"session_before_tree\" {\n\t\treturn (\n\t\t\ttype === \"session_before_switch\" ||\n\t\t\ttype === \"session_before_branch\" ||\n\t\t\ttype === \"session_before_compact\" ||\n\t\t\ttype === \"session_before_tree\"\n\t\t);\n\t}\n\n\t/**\n\t * Emit an event to all hooks.\n\t * Returns the result from session before_* / tool_result events (if any handler returns one).\n\t */\n\tasync emit(\n\t\tevent: HookEvent,\n\t): Promise<SessionBeforeCompactResult | SessionBeforeTreeResult | ToolResultEventResult | undefined> {\n\t\tconst ctx = this.createContext();\n\t\tlet result: SessionBeforeCompactResult | SessionBeforeTreeResult | ToolResultEventResult | undefined;\n\n\t\tfor (const hook of this.hooks) {\n\t\t\tconst handlers = hook.handlers.get(event.type);\n\t\t\tif (!handlers || handlers.length === 0) continue;\n\n\t\t\tfor (const handler of handlers) {\n\t\t\t\ttry {\n\t\t\t\t\tconst handlerResult = await handler(event, ctx);\n\n\t\t\t\t\t// For session before_* events, capture the result (for cancellation)\n\t\t\t\t\tif (this.isSessionBeforeEvent(event.type) && handlerResult) {\n\t\t\t\t\t\tresult = handlerResult as SessionBeforeCompactResult | SessionBeforeTreeResult;\n\t\t\t\t\t\t// If cancelled, stop processing further hooks\n\t\t\t\t\t\tif (result.cancel) {\n\t\t\t\t\t\t\treturn result;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\t// For tool_result events, capture the result\n\t\t\t\t\tif (event.type === \"tool_result\" && handlerResult) {\n\t\t\t\t\t\tresult = handlerResult as ToolResultEventResult;\n\t\t\t\t\t}\n\t\t\t\t} catch (err) {\n\t\t\t\t\tconst message = err instanceof Error ? err.message : String(err);\n\t\t\t\t\tconst stack = err instanceof Error ? err.stack : undefined;\n\t\t\t\t\tthis.emitError({\n\t\t\t\t\t\thookPath: hook.path,\n\t\t\t\t\t\tevent: event.type,\n\t\t\t\t\t\terror: message,\n\t\t\t\t\t\tstack,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn result;\n\t}\n\n\t/**\n\t * Emit a tool_call event to all hooks.\n\t * No timeout - user prompts can take as long as needed.\n\t * Errors are thrown (not swallowed) so caller can block on failure.\n\t */\n\tasync emitToolCall(event: ToolCallEvent): Promise<ToolCallEventResult | undefined> {\n\t\tconst ctx = this.createContext();\n\t\tlet result: ToolCallEventResult | undefined;\n\n\t\tfor (const hook of this.hooks) {\n\t\t\tconst handlers = hook.handlers.get(\"tool_call\");\n\t\t\tif (!handlers || handlers.length === 0) continue;\n\n\t\t\tfor (const handler of handlers) {\n\t\t\t\t// No timeout - let user take their time\n\t\t\t\tconst handlerResult = await handler(event, ctx);\n\n\t\t\t\tif (handlerResult) {\n\t\t\t\t\tresult = handlerResult as ToolCallEventResult;\n\t\t\t\t\t// If blocked, stop processing further hooks\n\t\t\t\t\tif (result.block) {\n\t\t\t\t\t\treturn result;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn result;\n\t}\n\n\t/**\n\t * Emit a context event to all hooks.\n\t * Handlers are chained - each gets the previous handler's output (if any).\n\t * Returns the final modified messages, or the original if no modifications.\n\t *\n\t * Messages are deep-copied before passing to hooks, so mutations are safe.\n\t */\n\tasync emitContext(messages: AgentMessage[]): Promise<AgentMessage[]> {\n\t\tconst ctx = this.createContext();\n\t\tlet currentMessages = structuredClone(messages);\n\n\t\tfor (const hook of this.hooks) {\n\t\t\tconst handlers = hook.handlers.get(\"context\");\n\t\t\tif (!handlers || handlers.length === 0) continue;\n\n\t\t\tfor (const handler of handlers) {\n\t\t\t\ttry {\n\t\t\t\t\tconst event: ContextEvent = { type: \"context\", messages: currentMessages };\n\t\t\t\t\tconst handlerResult = await handler(event, ctx);\n\n\t\t\t\t\tif (handlerResult && (handlerResult as ContextEventResult).messages) {\n\t\t\t\t\t\tcurrentMessages = (handlerResult as ContextEventResult).messages!;\n\t\t\t\t\t}\n\t\t\t\t} catch (err) {\n\t\t\t\t\tconst message = err instanceof Error ? err.message : String(err);\n\t\t\t\t\tconst stack = err instanceof Error ? err.stack : undefined;\n\t\t\t\t\tthis.emitError({\n\t\t\t\t\t\thookPath: hook.path,\n\t\t\t\t\t\tevent: \"context\",\n\t\t\t\t\t\terror: message,\n\t\t\t\t\t\tstack,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn currentMessages;\n\t}\n\n\t/**\n\t * Emit before_agent_start event to all hooks.\n\t * Returns combined result: all messages and all systemPromptAppend strings concatenated.\n\t */\n\tasync emitBeforeAgentStart(\n\t\tprompt: string,\n\t\timages?: ImageContent[],\n\t): Promise<BeforeAgentStartCombinedResult | undefined> {\n\t\tconst ctx = this.createContext();\n\t\tconst messages: NonNullable<BeforeAgentStartEventResult[\"message\"]>[] = [];\n\t\tconst systemPromptAppends: string[] = [];\n\n\t\tfor (const hook of this.hooks) {\n\t\t\tconst handlers = hook.handlers.get(\"before_agent_start\");\n\t\t\tif (!handlers || handlers.length === 0) continue;\n\n\t\t\tfor (const handler of handlers) {\n\t\t\t\ttry {\n\t\t\t\t\tconst event: BeforeAgentStartEvent = { type: \"before_agent_start\", prompt, images };\n\t\t\t\t\tconst handlerResult = await handler(event, ctx);\n\n\t\t\t\t\tif (handlerResult) {\n\t\t\t\t\t\tconst result = handlerResult as BeforeAgentStartEventResult;\n\t\t\t\t\t\t// Collect all messages\n\t\t\t\t\t\tif (result.message) {\n\t\t\t\t\t\t\tmessages.push(result.message);\n\t\t\t\t\t\t}\n\t\t\t\t\t\t// Collect all systemPromptAppend strings\n\t\t\t\t\t\tif (result.systemPromptAppend) {\n\t\t\t\t\t\t\tsystemPromptAppends.push(result.systemPromptAppend);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t} catch (err) {\n\t\t\t\t\tconst message = err instanceof Error ? err.message : String(err);\n\t\t\t\t\tconst stack = err instanceof Error ? err.stack : undefined;\n\t\t\t\t\tthis.emitError({\n\t\t\t\t\t\thookPath: hook.path,\n\t\t\t\t\t\tevent: \"before_agent_start\",\n\t\t\t\t\t\terror: message,\n\t\t\t\t\t\tstack,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Return combined result\n\t\tif (messages.length > 0 || systemPromptAppends.length > 0) {\n\t\t\treturn {\n\t\t\t\tmessages: messages.length > 0 ? messages : undefined,\n\t\t\t\tsystemPromptAppend: systemPromptAppends.length > 0 ? systemPromptAppends.join(\"\\n\\n\") : undefined,\n\t\t\t};\n\t\t}\n\n\t\treturn undefined;\n\t}\n}\n"]}
@@ -5,8 +5,8 @@
5
5
  * and interact with the user via UI primitives.
6
6
  */
7
7
  import type { AgentMessage } from "@mariozechner/pi-agent-core";
8
- import type { ImageContent, Message, Model, TextContent, ToolResultMessage } from "@mariozechner/pi-ai";
9
- import type { Component, TUI } from "@mariozechner/pi-tui";
8
+ import type { ImageContent, Model, TextContent, ToolResultMessage } from "@mariozechner/pi-ai";
9
+ import type { Component, KeyId, TUI } from "@mariozechner/pi-tui";
10
10
  import type { Theme } from "../../modes/interactive/theme/theme.js";
11
11
  import type { CompactionPreparation, CompactionResult } from "../compaction/index.js";
12
12
  import type { ExecOptions, ExecResult } from "../exec.js";
@@ -52,6 +52,52 @@ export interface HookUIContext {
52
52
  * @param text - Status text to display, or undefined to clear
53
53
  */
54
54
  setStatus(key: string, text: string | undefined): void;
55
+ /**
56
+ * Set a widget to display in the status area (above the editor, below "Working..." indicator).
57
+ * Supports multi-line content. Pass undefined to clear.
58
+ * Text can include ANSI escape codes for styling.
59
+ *
60
+ * Accepts either an array of styled strings, or a factory function that creates a Component.
61
+ *
62
+ * @param key - Unique key to identify this widget (e.g., hook name)
63
+ * @param content - Array of lines to display, or undefined to clear
64
+ *
65
+ * @example
66
+ * // Show a todo list with styled strings
67
+ * ctx.ui.setWidget("plan-todos", [
68
+ * theme.fg("accent", "Plan Progress:"),
69
+ * "☑ " + theme.fg("muted", theme.strikethrough("Step 1: Read files")),
70
+ * "☐ Step 2: Modify code",
71
+ * "☐ Step 3: Run tests",
72
+ * ]);
73
+ *
74
+ * // Clear the widget
75
+ * ctx.ui.setWidget("plan-todos", undefined);
76
+ */
77
+ setWidget(key: string, content: string[] | undefined): void;
78
+ /**
79
+ * Set a custom component as a widget (above the editor, below "Working..." indicator).
80
+ * Unlike custom(), this does NOT take keyboard focus - the editor remains focused.
81
+ * Pass undefined to clear the widget.
82
+ *
83
+ * The component should implement render(width) and optionally dispose().
84
+ * Components are rendered inline without taking focus - they cannot handle keyboard input.
85
+ *
86
+ * @param key - Unique key to identify this widget (e.g., hook name)
87
+ * @param content - Factory function that creates the component, or undefined to clear
88
+ *
89
+ * @example
90
+ * // Show a custom progress component
91
+ * ctx.ui.setWidget("my-progress", (tui, theme) => {
92
+ * return new MyProgressComponent(tui, theme);
93
+ * });
94
+ *
95
+ * // Clear the widget
96
+ * ctx.ui.setWidget("my-progress", undefined);
97
+ */
98
+ setWidget(key: string, content: ((tui: TUI, theme: Theme) => Component & {
99
+ dispose?(): void;
100
+ }) | undefined): void;
55
101
  /**
56
102
  * Show a custom component with keyboard focus.
57
103
  * The factory receives TUI, theme, and a done() callback to close the component.
@@ -421,7 +467,7 @@ export type HookEvent = SessionEvent | ContextEvent | BeforeAgentStartEvent | Ag
421
467
  */
422
468
  export interface ContextEventResult {
423
469
  /** Modified messages to send instead of the original */
424
- messages?: Message[];
470
+ messages?: AgentMessage[];
425
471
  }
426
472
  /**
427
473
  * Return type for tool_call event handlers.
@@ -452,6 +498,8 @@ export interface ToolResultEventResult {
452
498
  export interface BeforeAgentStartEventResult {
453
499
  /** Message to inject into context (persisted to session, visible in TUI) */
454
500
  message?: Pick<HookMessage, "customType" | "content" | "display" | "details">;
501
+ /** Text to append to the system prompt for this agent run */
502
+ systemPromptAppend?: string;
455
503
  }
456
504
  /** Return type for session_before_switch handlers */
457
505
  export interface SessionBeforeSwitchResult {
@@ -612,6 +660,89 @@ export interface HookAPI {
612
660
  * Supports timeout and abort signal.
613
661
  */
614
662
  exec(command: string, args: string[], options?: ExecOptions): Promise<ExecResult>;
663
+ /**
664
+ * Get the list of currently active tool names.
665
+ * @returns Array of tool names (e.g., ["read", "bash", "edit", "write"])
666
+ */
667
+ getActiveTools(): string[];
668
+ /**
669
+ * Get all configured tools (built-in via --tools or default, plus custom tools).
670
+ * @returns Array of all tool names
671
+ */
672
+ getAllTools(): string[];
673
+ /**
674
+ * Set the active tools by name.
675
+ * Both built-in and custom tools can be enabled/disabled.
676
+ * Changes take effect on the next agent turn.
677
+ * Note: This will invalidate prompt caching for the next request.
678
+ *
679
+ * @param toolNames - Array of tool names to enable (e.g., ["read", "bash", "grep", "find", "ls"])
680
+ *
681
+ * @example
682
+ * // Switch to read-only mode (plan mode)
683
+ * pi.setActiveTools(["read", "bash", "grep", "find", "ls"]);
684
+ *
685
+ * // Restore full access
686
+ * pi.setActiveTools(["read", "bash", "edit", "write"]);
687
+ */
688
+ setActiveTools(toolNames: string[]): void;
689
+ /**
690
+ * Register a CLI flag for this hook.
691
+ * Flags are parsed from command line and values accessible via getFlag().
692
+ *
693
+ * @param name - Flag name (will be --name on CLI)
694
+ * @param options - Flag configuration
695
+ *
696
+ * @example
697
+ * pi.registerFlag("plan", {
698
+ * description: "Start in plan mode (read-only)",
699
+ * type: "boolean",
700
+ * });
701
+ */
702
+ registerFlag(name: string, options: {
703
+ /** Description shown in --help */
704
+ description?: string;
705
+ /** Flag type: boolean (--flag) or string (--flag value) */
706
+ type: "boolean" | "string";
707
+ /** Default value */
708
+ default?: boolean | string;
709
+ }): void;
710
+ /**
711
+ * Get the value of a CLI flag registered by this hook.
712
+ * Returns undefined if flag was not provided and has no default.
713
+ *
714
+ * @param name - Flag name (without --)
715
+ * @returns Flag value, or undefined
716
+ *
717
+ * @example
718
+ * if (pi.getFlag("plan")) {
719
+ * // plan mode enabled
720
+ * }
721
+ */
722
+ getFlag(name: string): boolean | string | undefined;
723
+ /**
724
+ * Register a keyboard shortcut for this hook.
725
+ * The handler is called when the shortcut is pressed in interactive mode.
726
+ *
727
+ * @param shortcut - Key identifier (e.g., Key.shift("p"), "ctrl+x")
728
+ * @param options - Shortcut configuration
729
+ *
730
+ * @example
731
+ * import { Key } from "@mariozechner/pi-tui";
732
+ *
733
+ * pi.registerShortcut(Key.shift("p"), {
734
+ * description: "Toggle plan mode",
735
+ * handler: async (ctx) => {
736
+ * // toggle plan mode
737
+ * },
738
+ * });
739
+ */
740
+ registerShortcut(shortcut: KeyId, options: {
741
+ /** Description shown in help */
742
+ description?: string;
743
+ /** Handler called when shortcut is pressed */
744
+ handler: (ctx: HookContext) => Promise<void> | void;
745
+ }): void;
615
746
  }
616
747
  /**
617
748
  * Hook factory function type.
@@ -625,5 +756,6 @@ export interface HookError {
625
756
  hookPath: string;
626
757
  event: string;
627
758
  error: string;
759
+ stack?: string;
628
760
  }
629
761
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/core/hooks/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxG,OAAO,KAAK,EAAE,SAAS,EAAE,GAAG,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,wCAAwC,CAAC;AACpE,OAAO,KAAK,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AACtF,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC1D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,KAAK,EACX,kBAAkB,EAClB,eAAe,EACf,sBAAsB,EACtB,YAAY,EACZ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,CAAC;QAAC,SAAS,CAAC,EAAE,OAAO,GAAG,UAAU,CAAA;KAAE,GACnE,IAAI,CAAC;IAER;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACH,WAAW,CAAC,CAAC,GAAG,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC;IAE7D;;;;OAIG;IACH,uBAAuB,CAAC,CAAC,GAAG,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,mBAAmB,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;IAEjG;;;OAGG;IACH,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE;QAAE,WAAW,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,iBAAiB,CAAC,SAAS,CAAC,CAAA;KAAE,GAAG,IAAI,CAAC;IAE9G;;;OAGG;IACH,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;CAClF;AAED;;;GAGG;AACH,MAAM,MAAM,WAAW,GAAG,CAAC,EAAE,EAAE,OAAO,KAAK,IAAI,CAAC;AAMhD;;GAEG;AACH,MAAM,WAAW,SAAS;IACzB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACd","sourcesContent":["/**\n * Hook system types.\n *\n * Hooks are TypeScript modules that can subscribe to agent lifecycle events\n * and interact with the user via UI primitives.\n */\n\nimport type { AgentMessage } from \"@mariozechner/pi-agent-core\";\nimport type { ImageContent, Message, Model, TextContent, ToolResultMessage } from \"@mariozechner/pi-ai\";\nimport type { Component, TUI } from \"@mariozechner/pi-tui\";\nimport type { Theme } from \"../../modes/interactive/theme/theme.js\";\nimport type { CompactionPreparation, CompactionResult } from \"../compaction/index.js\";\nimport type { ExecOptions, ExecResult } from \"../exec.js\";\nimport type { HookMessage } from \"../messages.js\";\nimport type { ModelRegistry } from \"../model-registry.js\";\nimport type {\n\tBranchSummaryEntry,\n\tCompactionEntry,\n\tReadonlySessionManager,\n\tSessionEntry,\n\tSessionManager,\n} from \"../session-manager.js\";\n\nimport type { EditToolDetails } from \"../tools/edit.js\";\nimport type {\n\tBashToolDetails,\n\tFindToolDetails,\n\tGrepToolDetails,\n\tLsToolDetails,\n\tReadToolDetails,\n} from \"../tools/index.js\";\n\n// Re-export for backward compatibility\nexport type { ExecOptions, ExecResult } from \"../exec.js\";\n\n/**\n * UI context for hooks to request interactive UI from the harness.\n * Each mode (interactive, RPC, print) provides its own implementation.\n */\nexport interface HookUIContext {\n\t/**\n\t * Show a selector and return the user's choice.\n\t * @param title - Title to display\n\t * @param options - Array of string options\n\t * @returns Selected option string, or null if cancelled\n\t */\n\tselect(title: string, options: string[]): Promise<string | undefined>;\n\n\t/**\n\t * Show a confirmation dialog.\n\t * @returns true if confirmed, false if cancelled\n\t */\n\tconfirm(title: string, message: string): Promise<boolean>;\n\n\t/**\n\t * Show a text input dialog.\n\t * @returns User input, or undefined if cancelled\n\t */\n\tinput(title: string, placeholder?: string): Promise<string | undefined>;\n\n\t/**\n\t * Show a notification to the user.\n\t */\n\tnotify(message: string, type?: \"info\" | \"warning\" | \"error\"): void;\n\n\t/**\n\t * Set status text in the footer/status bar.\n\t * Pass undefined as text to clear the status for this key.\n\t * Text can include ANSI escape codes for styling.\n\t * Note: Newlines, tabs, and carriage returns are replaced with spaces.\n\t * The combined status line is truncated to terminal width.\n\t * @param key - Unique key to identify this status (e.g., hook name)\n\t * @param text - Status text to display, or undefined to clear\n\t */\n\tsetStatus(key: string, text: string | undefined): void;\n\n\t/**\n\t * Show a custom component with keyboard focus.\n\t * The factory receives TUI, theme, and a done() callback to close the component.\n\t * Can be async for fire-and-forget work (don't await the work, just start it).\n\t *\n\t * @param factory - Function that creates the component. Call done() when finished.\n\t * @returns Promise that resolves with the value passed to done()\n\t *\n\t * @example\n\t * // Sync factory\n\t * const result = await ctx.ui.custom((tui, theme, done) => {\n\t * const component = new MyComponent(tui, theme);\n\t * component.onFinish = (value) => done(value);\n\t * return component;\n\t * });\n\t *\n\t * // Async factory with fire-and-forget work\n\t * const result = await ctx.ui.custom(async (tui, theme, done) => {\n\t * const loader = new CancellableLoader(tui, theme.fg(\"accent\"), theme.fg(\"muted\"), \"Working...\");\n\t * loader.onAbort = () => done(null);\n\t * doWork(loader.signal).then(done); // Don't await - fire and forget\n\t * return loader;\n\t * });\n\t */\n\tcustom<T>(\n\t\tfactory: (\n\t\t\ttui: TUI,\n\t\t\ttheme: Theme,\n\t\t\tdone: (result: T) => void,\n\t\t) => (Component & { dispose?(): void }) | Promise<Component & { dispose?(): void }>,\n\t): Promise<T>;\n\n\t/**\n\t * Set the text in the core input editor.\n\t * Use this to pre-fill the input box with generated content (e.g., prompt templates, extracted questions).\n\t * @param text - Text to set in the editor\n\t */\n\tsetEditorText(text: string): void;\n\n\t/**\n\t * Get the current text from the core input editor.\n\t * @returns Current editor text\n\t */\n\tgetEditorText(): string;\n\n\t/**\n\t * Show a multi-line editor for text editing.\n\t * Supports Ctrl+G to open external editor ($VISUAL or $EDITOR).\n\t * @param title - Title describing what is being edited\n\t * @param prefill - Optional initial text\n\t * @returns Edited text, or undefined if cancelled (Escape)\n\t */\n\teditor(title: string, prefill?: string): Promise<string | undefined>;\n\n\t/**\n\t * Get the current theme for styling text with ANSI codes.\n\t * Use theme.fg() and theme.bg() to style status text.\n\t *\n\t * @example\n\t * const theme = ctx.ui.theme;\n\t * ctx.ui.setStatus(\"my-hook\", theme.fg(\"success\", \"✓\") + \" Ready\");\n\t */\n\treadonly theme: Theme;\n}\n\n/**\n * Context passed to hook event handlers.\n * For command handlers, see HookCommandContext which extends this with session control methods.\n */\nexport interface HookContext {\n\t/** UI methods for user interaction */\n\tui: HookUIContext;\n\t/** Whether UI is available (false in print mode) */\n\thasUI: boolean;\n\t/** Current working directory */\n\tcwd: string;\n\t/** Session manager (read-only) - use pi.sendMessage()/pi.appendEntry() for writes */\n\tsessionManager: ReadonlySessionManager;\n\t/** Model registry - use for API key resolution and model retrieval */\n\tmodelRegistry: ModelRegistry;\n\t/** Current model (may be undefined if no model is selected yet) */\n\tmodel: Model<any> | undefined;\n\t/** Whether the agent is idle (not streaming) */\n\tisIdle(): boolean;\n\t/** Abort the current agent operation (fire-and-forget, does not wait) */\n\tabort(): void;\n\t/** Whether there are queued messages waiting to be processed */\n\thasPendingMessages(): boolean;\n}\n\n/**\n * Extended context for slash command handlers.\n * Includes session control methods that are only safe in user-initiated commands.\n *\n * These methods are not available in event handlers because they can cause\n * deadlocks when called from within the agent loop (e.g., tool_call, context events).\n */\nexport interface HookCommandContext extends HookContext {\n\t/** Wait for the agent to finish streaming */\n\twaitForIdle(): Promise<void>;\n\n\t/**\n\t * Start a new session, optionally with a setup callback to initialize it.\n\t * The setup callback receives a writable SessionManager for the new session.\n\t *\n\t * @param options.parentSession - Path to parent session for lineage tracking\n\t * @param options.setup - Async callback to initialize the new session (e.g., append messages)\n\t * @returns Object with `cancelled: true` if a hook cancelled the new session\n\t *\n\t * @example\n\t * // Handoff: summarize current session and start fresh with context\n\t * await ctx.newSession({\n\t * parentSession: ctx.sessionManager.getSessionFile(),\n\t * setup: async (sm) => {\n\t * sm.appendMessage({ role: \"user\", content: [{ type: \"text\", text: summary }] });\n\t * }\n\t * });\n\t */\n\tnewSession(options?: {\n\t\tparentSession?: string;\n\t\tsetup?: (sessionManager: SessionManager) => Promise<void>;\n\t}): Promise<{ cancelled: boolean }>;\n\n\t/**\n\t * Branch from a specific entry, creating a new session file.\n\t *\n\t * @param entryId - ID of the entry to branch from\n\t * @returns Object with `cancelled: true` if a hook cancelled the branch\n\t */\n\tbranch(entryId: string): Promise<{ cancelled: boolean }>;\n\n\t/**\n\t * Navigate to a different point in the session tree (in-place).\n\t *\n\t * @param targetId - ID of the entry to navigate to\n\t * @param options.summarize - Whether to summarize the abandoned branch\n\t * @returns Object with `cancelled: true` if a hook cancelled the navigation\n\t */\n\tnavigateTree(targetId: string, options?: { summarize?: boolean }): Promise<{ cancelled: boolean }>;\n}\n\n// ============================================================================\n// Session Events\n// ============================================================================\n\n/** Fired on initial session load */\nexport interface SessionStartEvent {\n\ttype: \"session_start\";\n}\n\n/** Fired before switching to another session (can be cancelled) */\nexport interface SessionBeforeSwitchEvent {\n\ttype: \"session_before_switch\";\n\t/** Reason for the switch */\n\treason: \"new\" | \"resume\";\n\t/** Session file we're switching to (only for \"resume\") */\n\ttargetSessionFile?: string;\n}\n\n/** Fired after switching to another session */\nexport interface SessionSwitchEvent {\n\ttype: \"session_switch\";\n\t/** Reason for the switch */\n\treason: \"new\" | \"resume\";\n\t/** Session file we came from */\n\tpreviousSessionFile: string | undefined;\n}\n\n/** Fired before branching a session (can be cancelled) */\nexport interface SessionBeforeBranchEvent {\n\ttype: \"session_before_branch\";\n\t/** ID of the entry to branch from */\n\tentryId: string;\n}\n\n/** Fired after branching a session */\nexport interface SessionBranchEvent {\n\ttype: \"session_branch\";\n\tpreviousSessionFile: string | undefined;\n}\n\n/** Fired before context compaction (can be cancelled or customized) */\nexport interface SessionBeforeCompactEvent {\n\ttype: \"session_before_compact\";\n\t/** Compaction preparation with messages to summarize, file ops, previous summary, etc. */\n\tpreparation: CompactionPreparation;\n\t/** Branch entries (root to current leaf). Use to inspect custom state or previous compactions. */\n\tbranchEntries: SessionEntry[];\n\t/** Optional user-provided instructions for the summary */\n\tcustomInstructions?: string;\n\t/** Abort signal - hooks should pass this to LLM calls and check it periodically */\n\tsignal: AbortSignal;\n}\n\n/** Fired after context compaction */\nexport interface SessionCompactEvent {\n\ttype: \"session_compact\";\n\tcompactionEntry: CompactionEntry;\n\t/** Whether the compaction entry was provided by a hook */\n\tfromHook: boolean;\n}\n\n/** Fired on process exit (SIGINT/SIGTERM) */\nexport interface SessionShutdownEvent {\n\ttype: \"session_shutdown\";\n}\n\n/** Preparation data for tree navigation (used by session_before_tree event) */\nexport interface TreePreparation {\n\t/** Node being switched to */\n\ttargetId: string;\n\t/** Current active leaf (being abandoned), null if no current position */\n\toldLeafId: string | null;\n\t/** Common ancestor of target and old leaf, null if no common ancestor */\n\tcommonAncestorId: string | null;\n\t/** Entries to summarize (old leaf back to common ancestor or compaction) */\n\tentriesToSummarize: SessionEntry[];\n\t/** Whether user chose to summarize */\n\tuserWantsSummary: boolean;\n}\n\n/** Fired before navigating to a different node in the session tree (can be cancelled) */\nexport interface SessionBeforeTreeEvent {\n\ttype: \"session_before_tree\";\n\t/** Preparation data for the navigation */\n\tpreparation: TreePreparation;\n\t/** Abort signal - honors Escape during summarization (model available via ctx.model) */\n\tsignal: AbortSignal;\n}\n\n/** Fired after navigating to a different node in the session tree */\nexport interface SessionTreeEvent {\n\ttype: \"session_tree\";\n\t/** The new active leaf, null if navigated to before first entry */\n\tnewLeafId: string | null;\n\t/** Previous active leaf, null if there was no position */\n\toldLeafId: string | null;\n\t/** Branch summary entry if one was created */\n\tsummaryEntry?: BranchSummaryEntry;\n\t/** Whether summary came from hook */\n\tfromHook?: boolean;\n}\n\n/** Union of all session event types */\nexport type SessionEvent =\n\t| SessionStartEvent\n\t| SessionBeforeSwitchEvent\n\t| SessionSwitchEvent\n\t| SessionBeforeBranchEvent\n\t| SessionBranchEvent\n\t| SessionBeforeCompactEvent\n\t| SessionCompactEvent\n\t| SessionShutdownEvent\n\t| SessionBeforeTreeEvent\n\t| SessionTreeEvent;\n\n/**\n * Event data for context event.\n * Fired before each LLM call, allowing hooks to modify context non-destructively.\n * Original session messages are NOT modified - only the messages sent to the LLM are affected.\n */\nexport interface ContextEvent {\n\ttype: \"context\";\n\t/** Messages about to be sent to the LLM (deep copy, safe to modify) */\n\tmessages: AgentMessage[];\n}\n\n/**\n * Event data for before_agent_start event.\n * Fired after user submits a prompt but before the agent loop starts.\n * Allows hooks to inject context that will be persisted and visible in TUI.\n */\nexport interface BeforeAgentStartEvent {\n\ttype: \"before_agent_start\";\n\t/** The user's prompt text */\n\tprompt: string;\n\t/** Any images attached to the prompt */\n\timages?: ImageContent[];\n}\n\n/**\n * Event data for agent_start event.\n * Fired when an agent loop starts (once per user prompt).\n */\nexport interface AgentStartEvent {\n\ttype: \"agent_start\";\n}\n\n/**\n * Event data for agent_end event.\n */\nexport interface AgentEndEvent {\n\ttype: \"agent_end\";\n\tmessages: AgentMessage[];\n}\n\n/**\n * Event data for turn_start event.\n */\nexport interface TurnStartEvent {\n\ttype: \"turn_start\";\n\tturnIndex: number;\n\ttimestamp: number;\n}\n\n/**\n * Event data for turn_end event.\n */\nexport interface TurnEndEvent {\n\ttype: \"turn_end\";\n\tturnIndex: number;\n\tmessage: AgentMessage;\n\ttoolResults: ToolResultMessage[];\n}\n\n/**\n * Event data for tool_call event.\n * Fired before a tool is executed. Hooks can block execution.\n */\nexport interface ToolCallEvent {\n\ttype: \"tool_call\";\n\t/** Tool name (e.g., \"bash\", \"edit\", \"write\") */\n\ttoolName: string;\n\t/** Tool call ID */\n\ttoolCallId: string;\n\t/** Tool input parameters */\n\tinput: Record<string, unknown>;\n}\n\n/**\n * Base interface for tool_result events.\n */\ninterface ToolResultEventBase {\n\ttype: \"tool_result\";\n\t/** Tool call ID */\n\ttoolCallId: string;\n\t/** Tool input parameters */\n\tinput: Record<string, unknown>;\n\t/** Full content array (text and images) */\n\tcontent: (TextContent | ImageContent)[];\n\t/** Whether the tool execution was an error */\n\tisError: boolean;\n}\n\n/** Tool result event for bash tool */\nexport interface BashToolResultEvent extends ToolResultEventBase {\n\ttoolName: \"bash\";\n\tdetails: BashToolDetails | undefined;\n}\n\n/** Tool result event for read tool */\nexport interface ReadToolResultEvent extends ToolResultEventBase {\n\ttoolName: \"read\";\n\tdetails: ReadToolDetails | undefined;\n}\n\n/** Tool result event for edit tool */\nexport interface EditToolResultEvent extends ToolResultEventBase {\n\ttoolName: \"edit\";\n\tdetails: EditToolDetails | undefined;\n}\n\n/** Tool result event for write tool */\nexport interface WriteToolResultEvent extends ToolResultEventBase {\n\ttoolName: \"write\";\n\tdetails: undefined;\n}\n\n/** Tool result event for grep tool */\nexport interface GrepToolResultEvent extends ToolResultEventBase {\n\ttoolName: \"grep\";\n\tdetails: GrepToolDetails | undefined;\n}\n\n/** Tool result event for find tool */\nexport interface FindToolResultEvent extends ToolResultEventBase {\n\ttoolName: \"find\";\n\tdetails: FindToolDetails | undefined;\n}\n\n/** Tool result event for ls tool */\nexport interface LsToolResultEvent extends ToolResultEventBase {\n\ttoolName: \"ls\";\n\tdetails: LsToolDetails | undefined;\n}\n\n/** Tool result event for custom/unknown tools */\nexport interface CustomToolResultEvent extends ToolResultEventBase {\n\ttoolName: string;\n\tdetails: unknown;\n}\n\n/**\n * Event data for tool_result event.\n * Fired after a tool is executed. Hooks can modify the result.\n * Use toolName to discriminate and get typed details.\n */\nexport type ToolResultEvent =\n\t| BashToolResultEvent\n\t| ReadToolResultEvent\n\t| EditToolResultEvent\n\t| WriteToolResultEvent\n\t| GrepToolResultEvent\n\t| FindToolResultEvent\n\t| LsToolResultEvent\n\t| CustomToolResultEvent;\n\n// Type guards for narrowing ToolResultEvent to specific tool types\nexport function isBashToolResult(e: ToolResultEvent): e is BashToolResultEvent {\n\treturn e.toolName === \"bash\";\n}\nexport function isReadToolResult(e: ToolResultEvent): e is ReadToolResultEvent {\n\treturn e.toolName === \"read\";\n}\nexport function isEditToolResult(e: ToolResultEvent): e is EditToolResultEvent {\n\treturn e.toolName === \"edit\";\n}\nexport function isWriteToolResult(e: ToolResultEvent): e is WriteToolResultEvent {\n\treturn e.toolName === \"write\";\n}\nexport function isGrepToolResult(e: ToolResultEvent): e is GrepToolResultEvent {\n\treturn e.toolName === \"grep\";\n}\nexport function isFindToolResult(e: ToolResultEvent): e is FindToolResultEvent {\n\treturn e.toolName === \"find\";\n}\nexport function isLsToolResult(e: ToolResultEvent): e is LsToolResultEvent {\n\treturn e.toolName === \"ls\";\n}\n\n/**\n * Union of all hook event types.\n */\nexport type HookEvent =\n\t| SessionEvent\n\t| ContextEvent\n\t| BeforeAgentStartEvent\n\t| AgentStartEvent\n\t| AgentEndEvent\n\t| TurnStartEvent\n\t| TurnEndEvent\n\t| ToolCallEvent\n\t| ToolResultEvent;\n\n// ============================================================================\n// Event Results\n// ============================================================================\n\n/**\n * Return type for context event handlers.\n * Allows hooks to modify messages before they're sent to the LLM.\n */\nexport interface ContextEventResult {\n\t/** Modified messages to send instead of the original */\n\tmessages?: Message[];\n}\n\n/**\n * Return type for tool_call event handlers.\n * Allows hooks to block tool execution.\n */\nexport interface ToolCallEventResult {\n\t/** If true, block the tool from executing */\n\tblock?: boolean;\n\t/** Reason for blocking (returned to LLM as error) */\n\treason?: string;\n}\n\n/**\n * Return type for tool_result event handlers.\n * Allows hooks to modify tool results.\n */\nexport interface ToolResultEventResult {\n\t/** Replacement content array (text and images) */\n\tcontent?: (TextContent | ImageContent)[];\n\t/** Replacement details */\n\tdetails?: unknown;\n\t/** Override isError flag */\n\tisError?: boolean;\n}\n\n/**\n * Return type for before_agent_start event handlers.\n * Allows hooks to inject context before the agent runs.\n */\nexport interface BeforeAgentStartEventResult {\n\t/** Message to inject into context (persisted to session, visible in TUI) */\n\tmessage?: Pick<HookMessage, \"customType\" | \"content\" | \"display\" | \"details\">;\n}\n\n/** Return type for session_before_switch handlers */\nexport interface SessionBeforeSwitchResult {\n\t/** If true, cancel the switch */\n\tcancel?: boolean;\n}\n\n/** Return type for session_before_branch handlers */\nexport interface SessionBeforeBranchResult {\n\t/**\n\t * If true, abort the branch entirely. No new session file is created,\n\t * conversation stays unchanged.\n\t */\n\tcancel?: boolean;\n\t/**\n\t * If true, the branch proceeds (new session file created, session state updated)\n\t * but the in-memory conversation is NOT rewound to the branch point.\n\t *\n\t * Use case: git-checkpoint hook that restores code state separately.\n\t * The hook handles state restoration itself, so it doesn't want the\n\t * agent's conversation to be rewound (which would lose recent context).\n\t *\n\t * - `cancel: true` → nothing happens, user stays in current session\n\t * - `skipConversationRestore: true` → branch happens, but messages stay as-is\n\t * - neither → branch happens AND messages rewind to branch point (default)\n\t */\n\tskipConversationRestore?: boolean;\n}\n\n/** Return type for session_before_compact handlers */\nexport interface SessionBeforeCompactResult {\n\t/** If true, cancel the compaction */\n\tcancel?: boolean;\n\t/** Custom compaction result - SessionManager adds id/parentId */\n\tcompaction?: CompactionResult;\n}\n\n/** Return type for session_before_tree handlers */\nexport interface SessionBeforeTreeResult {\n\t/** If true, cancel the navigation entirely */\n\tcancel?: boolean;\n\t/**\n\t * Custom summary (skips default summarizer).\n\t * Only used if preparation.userWantsSummary is true.\n\t */\n\tsummary?: {\n\t\tsummary: string;\n\t\tdetails?: unknown;\n\t};\n}\n\n// ============================================================================\n// Hook API\n// ============================================================================\n\n/**\n * Handler function type for each event.\n * Handlers can return R, undefined, or void (bare return statements).\n */\n// biome-ignore lint/suspicious/noConfusingVoidType: void allows bare return statements in handlers\nexport type HookHandler<E, R = undefined> = (event: E, ctx: HookContext) => Promise<R | void> | R | void;\n\nexport interface HookMessageRenderOptions {\n\t/** Whether the view is expanded */\n\texpanded: boolean;\n}\n\n/**\n * Renderer for hook messages.\n * Hooks register these to provide custom TUI rendering for their message types.\n */\nexport type HookMessageRenderer<T = unknown> = (\n\tmessage: HookMessage<T>,\n\toptions: HookMessageRenderOptions,\n\ttheme: Theme,\n) => Component | undefined;\n\n/**\n * Command registration options.\n */\nexport interface RegisteredCommand {\n\tname: string;\n\tdescription?: string;\n\n\thandler: (args: string, ctx: HookCommandContext) => Promise<void>;\n}\n\n/**\n * HookAPI passed to hook factory functions.\n * Hooks use pi.on() to subscribe to events and pi.sendMessage() to inject messages.\n */\nexport interface HookAPI {\n\t// Session events\n\ton(event: \"session_start\", handler: HookHandler<SessionStartEvent>): void;\n\ton(event: \"session_before_switch\", handler: HookHandler<SessionBeforeSwitchEvent, SessionBeforeSwitchResult>): void;\n\ton(event: \"session_switch\", handler: HookHandler<SessionSwitchEvent>): void;\n\ton(event: \"session_before_branch\", handler: HookHandler<SessionBeforeBranchEvent, SessionBeforeBranchResult>): void;\n\ton(event: \"session_branch\", handler: HookHandler<SessionBranchEvent>): void;\n\ton(\n\t\tevent: \"session_before_compact\",\n\t\thandler: HookHandler<SessionBeforeCompactEvent, SessionBeforeCompactResult>,\n\t): void;\n\ton(event: \"session_compact\", handler: HookHandler<SessionCompactEvent>): void;\n\ton(event: \"session_shutdown\", handler: HookHandler<SessionShutdownEvent>): void;\n\ton(event: \"session_before_tree\", handler: HookHandler<SessionBeforeTreeEvent, SessionBeforeTreeResult>): void;\n\ton(event: \"session_tree\", handler: HookHandler<SessionTreeEvent>): void;\n\n\t// Context and agent events\n\ton(event: \"context\", handler: HookHandler<ContextEvent, ContextEventResult>): void;\n\ton(event: \"before_agent_start\", handler: HookHandler<BeforeAgentStartEvent, BeforeAgentStartEventResult>): void;\n\ton(event: \"agent_start\", handler: HookHandler<AgentStartEvent>): void;\n\ton(event: \"agent_end\", handler: HookHandler<AgentEndEvent>): void;\n\ton(event: \"turn_start\", handler: HookHandler<TurnStartEvent>): void;\n\ton(event: \"turn_end\", handler: HookHandler<TurnEndEvent>): void;\n\ton(event: \"tool_call\", handler: HookHandler<ToolCallEvent, ToolCallEventResult>): void;\n\ton(event: \"tool_result\", handler: HookHandler<ToolResultEvent, ToolResultEventResult>): void;\n\n\t/**\n\t * Send a custom message to the session. Creates a CustomMessageEntry that\n\t * participates in LLM context and can be displayed in the TUI.\n\t *\n\t * Use this when you want the LLM to see the message content.\n\t * For hook state that should NOT be sent to the LLM, use appendEntry() instead.\n\t *\n\t * @param message - The message to send\n\t * @param message.customType - Identifier for your hook (used for filtering on reload)\n\t * @param message.content - Message content (string or TextContent/ImageContent array)\n\t * @param message.display - Whether to show in TUI (true = styled display, false = hidden)\n\t * @param message.details - Optional hook-specific metadata (not sent to LLM)\n\t * @param options.triggerTurn - If true and agent is idle, triggers a new LLM turn. Default: false.\n\t * If agent is streaming, message is queued and triggerTurn is ignored.\n\t * @param options.deliverAs - How to deliver when agent is streaming. Default: \"steer\".\n\t * - \"steer\": Interrupt mid-run, delivered after current tool execution.\n\t * - \"followUp\": Wait until agent finishes all work before delivery.\n\t */\n\tsendMessage<T = unknown>(\n\t\tmessage: Pick<HookMessage<T>, \"customType\" | \"content\" | \"display\" | \"details\">,\n\t\toptions?: { triggerTurn?: boolean; deliverAs?: \"steer\" | \"followUp\" },\n\t): void;\n\n\t/**\n\t * Append a custom entry to the session for hook state persistence.\n\t * Creates a CustomEntry that does NOT participate in LLM context.\n\t *\n\t * Use this to store hook-specific data that should persist across session reloads\n\t * but should NOT be sent to the LLM. On reload, scan session entries for your\n\t * customType to reconstruct hook state.\n\t *\n\t * For messages that SHOULD be sent to the LLM, use sendMessage() instead.\n\t *\n\t * @param customType - Identifier for your hook (used for filtering on reload)\n\t * @param data - Hook-specific data to persist (must be JSON-serializable)\n\t *\n\t * @example\n\t * // Store permission state\n\t * pi.appendEntry(\"permissions\", { level: \"full\", grantedAt: Date.now() });\n\t *\n\t * // On reload, reconstruct state from entries\n\t * pi.on(\"session\", async (event, ctx) => {\n\t * if (event.reason === \"start\") {\n\t * const entries = event.sessionManager.getEntries();\n\t * const myEntries = entries.filter(e => e.type === \"custom\" && e.customType === \"permissions\");\n\t * // Reconstruct state from myEntries...\n\t * }\n\t * });\n\t */\n\tappendEntry<T = unknown>(customType: string, data?: T): void;\n\n\t/**\n\t * Register a custom renderer for CustomMessageEntry with a specific customType.\n\t * The renderer is called when rendering the entry in the TUI.\n\t * Return nothing to use the default renderer.\n\t */\n\tregisterMessageRenderer<T = unknown>(customType: string, renderer: HookMessageRenderer<T>): void;\n\n\t/**\n\t * Register a custom slash command.\n\t * Handler receives HookCommandContext with session control methods.\n\t */\n\tregisterCommand(name: string, options: { description?: string; handler: RegisteredCommand[\"handler\"] }): void;\n\n\t/**\n\t * Execute a shell command and return stdout/stderr/code.\n\t * Supports timeout and abort signal.\n\t */\n\texec(command: string, args: string[], options?: ExecOptions): Promise<ExecResult>;\n}\n\n/**\n * Hook factory function type.\n * Hooks export a default function that receives the HookAPI.\n */\nexport type HookFactory = (pi: HookAPI) => void;\n\n// ============================================================================\n// Errors\n// ============================================================================\n\n/**\n * Error emitted when a hook fails.\n */\nexport interface HookError {\n\thookPath: string;\n\tevent: string;\n\terror: string;\n}\n"]}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/core/hooks/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,YAAY,EAAE,KAAK,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAC/F,OAAO,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,sBAAsB,CAAC;AAClE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,wCAAwC,CAAC;AACpE,OAAO,KAAK,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AACtF,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC1D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,KAAK,EACX,kBAAkB,EAClB,eAAe,EACf,sBAAsB,EACtB,YAAY,EACZ,cAAc,EACd,MAAM,uBAAuB,CAAC;AAE/B,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,KAAK,EACX,eAAe,EACf,eAAe,EACf,eAAe,EACf,aAAa,EACb,eAAe,EACf,MAAM,mBAAmB,CAAC;AAG3B,YAAY,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE1D;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC7B;;;;;OAKG;IACH,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE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,CAAC;IAER;;;;;;;;;;;OAWG;IACH,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,GAAG,MAAM,GAAG,SAAS,CAAC;IAEpD;;;;;;;;;;;;;;;;OAgBG;IACH,gBAAgB,CACf,QAAQ,EAAE,KAAK,EACf,OAAO,EAAE;QACR,gCAAgC;QAChC,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,8CAA8C;QAC9C,OAAO,EAAE,CAAC,GAAG,EAAE,WAAW,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;KACpD,GACC,IAAI,CAAC;CACR;AAED;;;GAGG;AACH,MAAM,MAAM,WAAW,GAAG,CAAC,EAAE,EAAE,OAAO,KAAK,IAAI,CAAC;AAMhD;;GAEG;AACH,MAAM,WAAW,SAAS;IACzB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;CACf","sourcesContent":["/**\n * Hook system types.\n *\n * Hooks are TypeScript modules that can subscribe to agent lifecycle events\n * and interact with the user via UI primitives.\n */\n\nimport type { AgentMessage } from \"@mariozechner/pi-agent-core\";\nimport type { ImageContent, Model, TextContent, ToolResultMessage } from \"@mariozechner/pi-ai\";\nimport type { Component, KeyId, TUI } from \"@mariozechner/pi-tui\";\nimport type { Theme } from \"../../modes/interactive/theme/theme.js\";\nimport type { CompactionPreparation, CompactionResult } from \"../compaction/index.js\";\nimport type { ExecOptions, ExecResult } from \"../exec.js\";\nimport type { HookMessage } from \"../messages.js\";\nimport type { ModelRegistry } from \"../model-registry.js\";\nimport type {\n\tBranchSummaryEntry,\n\tCompactionEntry,\n\tReadonlySessionManager,\n\tSessionEntry,\n\tSessionManager,\n} from \"../session-manager.js\";\n\nimport type { EditToolDetails } from \"../tools/edit.js\";\nimport type {\n\tBashToolDetails,\n\tFindToolDetails,\n\tGrepToolDetails,\n\tLsToolDetails,\n\tReadToolDetails,\n} from \"../tools/index.js\";\n\n// Re-export for backward compatibility\nexport type { ExecOptions, ExecResult } from \"../exec.js\";\n\n/**\n * UI context for hooks to request interactive UI from the harness.\n * Each mode (interactive, RPC, print) provides its own implementation.\n */\nexport interface HookUIContext {\n\t/**\n\t * Show a selector and return the user's choice.\n\t * @param title - Title to display\n\t * @param options - Array of string options\n\t * @returns Selected option string, or null if cancelled\n\t */\n\tselect(title: string, options: string[]): Promise<string | undefined>;\n\n\t/**\n\t * Show a confirmation dialog.\n\t * @returns true if confirmed, false if cancelled\n\t */\n\tconfirm(title: string, message: string): Promise<boolean>;\n\n\t/**\n\t * Show a text input dialog.\n\t * @returns User input, or undefined if cancelled\n\t */\n\tinput(title: string, placeholder?: string): Promise<string | undefined>;\n\n\t/**\n\t * Show a notification to the user.\n\t */\n\tnotify(message: string, type?: \"info\" | \"warning\" | \"error\"): void;\n\n\t/**\n\t * Set status text in the footer/status bar.\n\t * Pass undefined as text to clear the status for this key.\n\t * Text can include ANSI escape codes for styling.\n\t * Note: Newlines, tabs, and carriage returns are replaced with spaces.\n\t * The combined status line is truncated to terminal width.\n\t * @param key - Unique key to identify this status (e.g., hook name)\n\t * @param text - Status text to display, or undefined to clear\n\t */\n\tsetStatus(key: string, text: string | undefined): void;\n\n\t/**\n\t * Set a widget to display in the status area (above the editor, below \"Working...\" indicator).\n\t * Supports multi-line content. Pass undefined to clear.\n\t * Text can include ANSI escape codes for styling.\n\t *\n\t * Accepts either an array of styled strings, or a factory function that creates a Component.\n\t *\n\t * @param key - Unique key to identify this widget (e.g., hook name)\n\t * @param content - Array of lines to display, or undefined to clear\n\t *\n\t * @example\n\t * // Show a todo list with styled strings\n\t * ctx.ui.setWidget(\"plan-todos\", [\n\t * theme.fg(\"accent\", \"Plan Progress:\"),\n\t * \"☑ \" + theme.fg(\"muted\", theme.strikethrough(\"Step 1: Read files\")),\n\t * \"☐ Step 2: Modify code\",\n\t * \"☐ Step 3: Run tests\",\n\t * ]);\n\t *\n\t * // Clear the widget\n\t * ctx.ui.setWidget(\"plan-todos\", undefined);\n\t */\n\tsetWidget(key: string, content: string[] | undefined): void;\n\n\t/**\n\t * Set a custom component as a widget (above the editor, below \"Working...\" indicator).\n\t * Unlike custom(), this does NOT take keyboard focus - the editor remains focused.\n\t * Pass undefined to clear the widget.\n\t *\n\t * The component should implement render(width) and optionally dispose().\n\t * Components are rendered inline without taking focus - they cannot handle keyboard input.\n\t *\n\t * @param key - Unique key to identify this widget (e.g., hook name)\n\t * @param content - Factory function that creates the component, or undefined to clear\n\t *\n\t * @example\n\t * // Show a custom progress component\n\t * ctx.ui.setWidget(\"my-progress\", (tui, theme) => {\n\t * return new MyProgressComponent(tui, theme);\n\t * });\n\t *\n\t * // Clear the widget\n\t * ctx.ui.setWidget(\"my-progress\", undefined);\n\t */\n\tsetWidget(key: string, content: ((tui: TUI, theme: Theme) => Component & { dispose?(): void }) | undefined): void;\n\n\t/**\n\t * Show a custom component with keyboard focus.\n\t * The factory receives TUI, theme, and a done() callback to close the component.\n\t * Can be async for fire-and-forget work (don't await the work, just start it).\n\t *\n\t * @param factory - Function that creates the component. Call done() when finished.\n\t * @returns Promise that resolves with the value passed to done()\n\t *\n\t * @example\n\t * // Sync factory\n\t * const result = await ctx.ui.custom((tui, theme, done) => {\n\t * const component = new MyComponent(tui, theme);\n\t * component.onFinish = (value) => done(value);\n\t * return component;\n\t * });\n\t *\n\t * // Async factory with fire-and-forget work\n\t * const result = await ctx.ui.custom(async (tui, theme, done) => {\n\t * const loader = new CancellableLoader(tui, theme.fg(\"accent\"), theme.fg(\"muted\"), \"Working...\");\n\t * loader.onAbort = () => done(null);\n\t * doWork(loader.signal).then(done); // Don't await - fire and forget\n\t * return loader;\n\t * });\n\t */\n\tcustom<T>(\n\t\tfactory: (\n\t\t\ttui: TUI,\n\t\t\ttheme: Theme,\n\t\t\tdone: (result: T) => void,\n\t\t) => (Component & { dispose?(): void }) | Promise<Component & { dispose?(): void }>,\n\t): Promise<T>;\n\n\t/**\n\t * Set the text in the core input editor.\n\t * Use this to pre-fill the input box with generated content (e.g., prompt templates, extracted questions).\n\t * @param text - Text to set in the editor\n\t */\n\tsetEditorText(text: string): void;\n\n\t/**\n\t * Get the current text from the core input editor.\n\t * @returns Current editor text\n\t */\n\tgetEditorText(): string;\n\n\t/**\n\t * Show a multi-line editor for text editing.\n\t * Supports Ctrl+G to open external editor ($VISUAL or $EDITOR).\n\t * @param title - Title describing what is being edited\n\t * @param prefill - Optional initial text\n\t * @returns Edited text, or undefined if cancelled (Escape)\n\t */\n\teditor(title: string, prefill?: string): Promise<string | undefined>;\n\n\t/**\n\t * Get the current theme for styling text with ANSI codes.\n\t * Use theme.fg() and theme.bg() to style status text.\n\t *\n\t * @example\n\t * const theme = ctx.ui.theme;\n\t * ctx.ui.setStatus(\"my-hook\", theme.fg(\"success\", \"✓\") + \" Ready\");\n\t */\n\treadonly theme: Theme;\n}\n\n/**\n * Context passed to hook event handlers.\n * For command handlers, see HookCommandContext which extends this with session control methods.\n */\nexport interface HookContext {\n\t/** UI methods for user interaction */\n\tui: HookUIContext;\n\t/** Whether UI is available (false in print mode) */\n\thasUI: boolean;\n\t/** Current working directory */\n\tcwd: string;\n\t/** Session manager (read-only) - use pi.sendMessage()/pi.appendEntry() for writes */\n\tsessionManager: ReadonlySessionManager;\n\t/** Model registry - use for API key resolution and model retrieval */\n\tmodelRegistry: ModelRegistry;\n\t/** Current model (may be undefined if no model is selected yet) */\n\tmodel: Model<any> | undefined;\n\t/** Whether the agent is idle (not streaming) */\n\tisIdle(): boolean;\n\t/** Abort the current agent operation (fire-and-forget, does not wait) */\n\tabort(): void;\n\t/** Whether there are queued messages waiting to be processed */\n\thasPendingMessages(): boolean;\n}\n\n/**\n * Extended context for slash command handlers.\n * Includes session control methods that are only safe in user-initiated commands.\n *\n * These methods are not available in event handlers because they can cause\n * deadlocks when called from within the agent loop (e.g., tool_call, context events).\n */\nexport interface HookCommandContext extends HookContext {\n\t/** Wait for the agent to finish streaming */\n\twaitForIdle(): Promise<void>;\n\n\t/**\n\t * Start a new session, optionally with a setup callback to initialize it.\n\t * The setup callback receives a writable SessionManager for the new session.\n\t *\n\t * @param options.parentSession - Path to parent session for lineage tracking\n\t * @param options.setup - Async callback to initialize the new session (e.g., append messages)\n\t * @returns Object with `cancelled: true` if a hook cancelled the new session\n\t *\n\t * @example\n\t * // Handoff: summarize current session and start fresh with context\n\t * await ctx.newSession({\n\t * parentSession: ctx.sessionManager.getSessionFile(),\n\t * setup: async (sm) => {\n\t * sm.appendMessage({ role: \"user\", content: [{ type: \"text\", text: summary }] });\n\t * }\n\t * });\n\t */\n\tnewSession(options?: {\n\t\tparentSession?: string;\n\t\tsetup?: (sessionManager: SessionManager) => Promise<void>;\n\t}): Promise<{ cancelled: boolean }>;\n\n\t/**\n\t * Branch from a specific entry, creating a new session file.\n\t *\n\t * @param entryId - ID of the entry to branch from\n\t * @returns Object with `cancelled: true` if a hook cancelled the branch\n\t */\n\tbranch(entryId: string): Promise<{ cancelled: boolean }>;\n\n\t/**\n\t * Navigate to a different point in the session tree (in-place).\n\t *\n\t * @param targetId - ID of the entry to navigate to\n\t * @param options.summarize - Whether to summarize the abandoned branch\n\t * @returns Object with `cancelled: true` if a hook cancelled the navigation\n\t */\n\tnavigateTree(targetId: string, options?: { summarize?: boolean }): Promise<{ cancelled: boolean }>;\n}\n\n// ============================================================================\n// Session Events\n// ============================================================================\n\n/** Fired on initial session load */\nexport interface SessionStartEvent {\n\ttype: \"session_start\";\n}\n\n/** Fired before switching to another session (can be cancelled) */\nexport interface SessionBeforeSwitchEvent {\n\ttype: \"session_before_switch\";\n\t/** Reason for the switch */\n\treason: \"new\" | \"resume\";\n\t/** Session file we're switching to (only for \"resume\") */\n\ttargetSessionFile?: string;\n}\n\n/** Fired after switching to another session */\nexport interface SessionSwitchEvent {\n\ttype: \"session_switch\";\n\t/** Reason for the switch */\n\treason: \"new\" | \"resume\";\n\t/** Session file we came from */\n\tpreviousSessionFile: string | undefined;\n}\n\n/** Fired before branching a session (can be cancelled) */\nexport interface SessionBeforeBranchEvent {\n\ttype: \"session_before_branch\";\n\t/** ID of the entry to branch from */\n\tentryId: string;\n}\n\n/** Fired after branching a session */\nexport interface SessionBranchEvent {\n\ttype: \"session_branch\";\n\tpreviousSessionFile: string | undefined;\n}\n\n/** Fired before context compaction (can be cancelled or customized) */\nexport interface SessionBeforeCompactEvent {\n\ttype: \"session_before_compact\";\n\t/** Compaction preparation with messages to summarize, file ops, previous summary, etc. */\n\tpreparation: CompactionPreparation;\n\t/** Branch entries (root to current leaf). Use to inspect custom state or previous compactions. */\n\tbranchEntries: SessionEntry[];\n\t/** Optional user-provided instructions for the summary */\n\tcustomInstructions?: string;\n\t/** Abort signal - hooks should pass this to LLM calls and check it periodically */\n\tsignal: AbortSignal;\n}\n\n/** Fired after context compaction */\nexport interface SessionCompactEvent {\n\ttype: \"session_compact\";\n\tcompactionEntry: CompactionEntry;\n\t/** Whether the compaction entry was provided by a hook */\n\tfromHook: boolean;\n}\n\n/** Fired on process exit (SIGINT/SIGTERM) */\nexport interface SessionShutdownEvent {\n\ttype: \"session_shutdown\";\n}\n\n/** Preparation data for tree navigation (used by session_before_tree event) */\nexport interface TreePreparation {\n\t/** Node being switched to */\n\ttargetId: string;\n\t/** Current active leaf (being abandoned), null if no current position */\n\toldLeafId: string | null;\n\t/** Common ancestor of target and old leaf, null if no common ancestor */\n\tcommonAncestorId: string | null;\n\t/** Entries to summarize (old leaf back to common ancestor or compaction) */\n\tentriesToSummarize: SessionEntry[];\n\t/** Whether user chose to summarize */\n\tuserWantsSummary: boolean;\n}\n\n/** Fired before navigating to a different node in the session tree (can be cancelled) */\nexport interface SessionBeforeTreeEvent {\n\ttype: \"session_before_tree\";\n\t/** Preparation data for the navigation */\n\tpreparation: TreePreparation;\n\t/** Abort signal - honors Escape during summarization (model available via ctx.model) */\n\tsignal: AbortSignal;\n}\n\n/** Fired after navigating to a different node in the session tree */\nexport interface SessionTreeEvent {\n\ttype: \"session_tree\";\n\t/** The new active leaf, null if navigated to before first entry */\n\tnewLeafId: string | null;\n\t/** Previous active leaf, null if there was no position */\n\toldLeafId: string | null;\n\t/** Branch summary entry if one was created */\n\tsummaryEntry?: BranchSummaryEntry;\n\t/** Whether summary came from hook */\n\tfromHook?: boolean;\n}\n\n/** Union of all session event types */\nexport type SessionEvent =\n\t| SessionStartEvent\n\t| SessionBeforeSwitchEvent\n\t| SessionSwitchEvent\n\t| SessionBeforeBranchEvent\n\t| SessionBranchEvent\n\t| SessionBeforeCompactEvent\n\t| SessionCompactEvent\n\t| SessionShutdownEvent\n\t| SessionBeforeTreeEvent\n\t| SessionTreeEvent;\n\n/**\n * Event data for context event.\n * Fired before each LLM call, allowing hooks to modify context non-destructively.\n * Original session messages are NOT modified - only the messages sent to the LLM are affected.\n */\nexport interface ContextEvent {\n\ttype: \"context\";\n\t/** Messages about to be sent to the LLM (deep copy, safe to modify) */\n\tmessages: AgentMessage[];\n}\n\n/**\n * Event data for before_agent_start event.\n * Fired after user submits a prompt but before the agent loop starts.\n * Allows hooks to inject context that will be persisted and visible in TUI.\n */\nexport interface BeforeAgentStartEvent {\n\ttype: \"before_agent_start\";\n\t/** The user's prompt text */\n\tprompt: string;\n\t/** Any images attached to the prompt */\n\timages?: ImageContent[];\n}\n\n/**\n * Event data for agent_start event.\n * Fired when an agent loop starts (once per user prompt).\n */\nexport interface AgentStartEvent {\n\ttype: \"agent_start\";\n}\n\n/**\n * Event data for agent_end event.\n */\nexport interface AgentEndEvent {\n\ttype: \"agent_end\";\n\tmessages: AgentMessage[];\n}\n\n/**\n * Event data for turn_start event.\n */\nexport interface TurnStartEvent {\n\ttype: \"turn_start\";\n\tturnIndex: number;\n\ttimestamp: number;\n}\n\n/**\n * Event data for turn_end event.\n */\nexport interface TurnEndEvent {\n\ttype: \"turn_end\";\n\tturnIndex: number;\n\tmessage: AgentMessage;\n\ttoolResults: ToolResultMessage[];\n}\n\n/**\n * Event data for tool_call event.\n * Fired before a tool is executed. Hooks can block execution.\n */\nexport interface ToolCallEvent {\n\ttype: \"tool_call\";\n\t/** Tool name (e.g., \"bash\", \"edit\", \"write\") */\n\ttoolName: string;\n\t/** Tool call ID */\n\ttoolCallId: string;\n\t/** Tool input parameters */\n\tinput: Record<string, unknown>;\n}\n\n/**\n * Base interface for tool_result events.\n */\ninterface ToolResultEventBase {\n\ttype: \"tool_result\";\n\t/** Tool call ID */\n\ttoolCallId: string;\n\t/** Tool input parameters */\n\tinput: Record<string, unknown>;\n\t/** Full content array (text and images) */\n\tcontent: (TextContent | ImageContent)[];\n\t/** Whether the tool execution was an error */\n\tisError: boolean;\n}\n\n/** Tool result event for bash tool */\nexport interface BashToolResultEvent extends ToolResultEventBase {\n\ttoolName: \"bash\";\n\tdetails: BashToolDetails | undefined;\n}\n\n/** Tool result event for read tool */\nexport interface ReadToolResultEvent extends ToolResultEventBase {\n\ttoolName: \"read\";\n\tdetails: ReadToolDetails | undefined;\n}\n\n/** Tool result event for edit tool */\nexport interface EditToolResultEvent extends ToolResultEventBase {\n\ttoolName: \"edit\";\n\tdetails: EditToolDetails | undefined;\n}\n\n/** Tool result event for write tool */\nexport interface WriteToolResultEvent extends ToolResultEventBase {\n\ttoolName: \"write\";\n\tdetails: undefined;\n}\n\n/** Tool result event for grep tool */\nexport interface GrepToolResultEvent extends ToolResultEventBase {\n\ttoolName: \"grep\";\n\tdetails: GrepToolDetails | undefined;\n}\n\n/** Tool result event for find tool */\nexport interface FindToolResultEvent extends ToolResultEventBase {\n\ttoolName: \"find\";\n\tdetails: FindToolDetails | undefined;\n}\n\n/** Tool result event for ls tool */\nexport interface LsToolResultEvent extends ToolResultEventBase {\n\ttoolName: \"ls\";\n\tdetails: LsToolDetails | undefined;\n}\n\n/** Tool result event for custom/unknown tools */\nexport interface CustomToolResultEvent extends ToolResultEventBase {\n\ttoolName: string;\n\tdetails: unknown;\n}\n\n/**\n * Event data for tool_result event.\n * Fired after a tool is executed. Hooks can modify the result.\n * Use toolName to discriminate and get typed details.\n */\nexport type ToolResultEvent =\n\t| BashToolResultEvent\n\t| ReadToolResultEvent\n\t| EditToolResultEvent\n\t| WriteToolResultEvent\n\t| GrepToolResultEvent\n\t| FindToolResultEvent\n\t| LsToolResultEvent\n\t| CustomToolResultEvent;\n\n// Type guards for narrowing ToolResultEvent to specific tool types\nexport function isBashToolResult(e: ToolResultEvent): e is BashToolResultEvent {\n\treturn e.toolName === \"bash\";\n}\nexport function isReadToolResult(e: ToolResultEvent): e is ReadToolResultEvent {\n\treturn e.toolName === \"read\";\n}\nexport function isEditToolResult(e: ToolResultEvent): e is EditToolResultEvent {\n\treturn e.toolName === \"edit\";\n}\nexport function isWriteToolResult(e: ToolResultEvent): e is WriteToolResultEvent {\n\treturn e.toolName === \"write\";\n}\nexport function isGrepToolResult(e: ToolResultEvent): e is GrepToolResultEvent {\n\treturn e.toolName === \"grep\";\n}\nexport function isFindToolResult(e: ToolResultEvent): e is FindToolResultEvent {\n\treturn e.toolName === \"find\";\n}\nexport function isLsToolResult(e: ToolResultEvent): e is LsToolResultEvent {\n\treturn e.toolName === \"ls\";\n}\n\n/**\n * Union of all hook event types.\n */\nexport type HookEvent =\n\t| SessionEvent\n\t| ContextEvent\n\t| BeforeAgentStartEvent\n\t| AgentStartEvent\n\t| AgentEndEvent\n\t| TurnStartEvent\n\t| TurnEndEvent\n\t| ToolCallEvent\n\t| ToolResultEvent;\n\n// ============================================================================\n// Event Results\n// ============================================================================\n\n/**\n * Return type for context event handlers.\n * Allows hooks to modify messages before they're sent to the LLM.\n */\nexport interface ContextEventResult {\n\t/** Modified messages to send instead of the original */\n\tmessages?: AgentMessage[];\n}\n\n/**\n * Return type for tool_call event handlers.\n * Allows hooks to block tool execution.\n */\nexport interface ToolCallEventResult {\n\t/** If true, block the tool from executing */\n\tblock?: boolean;\n\t/** Reason for blocking (returned to LLM as error) */\n\treason?: string;\n}\n\n/**\n * Return type for tool_result event handlers.\n * Allows hooks to modify tool results.\n */\nexport interface ToolResultEventResult {\n\t/** Replacement content array (text and images) */\n\tcontent?: (TextContent | ImageContent)[];\n\t/** Replacement details */\n\tdetails?: unknown;\n\t/** Override isError flag */\n\tisError?: boolean;\n}\n\n/**\n * Return type for before_agent_start event handlers.\n * Allows hooks to inject context before the agent runs.\n */\nexport interface BeforeAgentStartEventResult {\n\t/** Message to inject into context (persisted to session, visible in TUI) */\n\tmessage?: Pick<HookMessage, \"customType\" | \"content\" | \"display\" | \"details\">;\n\t/** Text to append to the system prompt for this agent run */\n\tsystemPromptAppend?: string;\n}\n\n/** Return type for session_before_switch handlers */\nexport interface SessionBeforeSwitchResult {\n\t/** If true, cancel the switch */\n\tcancel?: boolean;\n}\n\n/** Return type for session_before_branch handlers */\nexport interface SessionBeforeBranchResult {\n\t/**\n\t * If true, abort the branch entirely. No new session file is created,\n\t * conversation stays unchanged.\n\t */\n\tcancel?: boolean;\n\t/**\n\t * If true, the branch proceeds (new session file created, session state updated)\n\t * but the in-memory conversation is NOT rewound to the branch point.\n\t *\n\t * Use case: git-checkpoint hook that restores code state separately.\n\t * The hook handles state restoration itself, so it doesn't want the\n\t * agent's conversation to be rewound (which would lose recent context).\n\t *\n\t * - `cancel: true` → nothing happens, user stays in current session\n\t * - `skipConversationRestore: true` → branch happens, but messages stay as-is\n\t * - neither → branch happens AND messages rewind to branch point (default)\n\t */\n\tskipConversationRestore?: boolean;\n}\n\n/** Return type for session_before_compact handlers */\nexport interface SessionBeforeCompactResult {\n\t/** If true, cancel the compaction */\n\tcancel?: boolean;\n\t/** Custom compaction result - SessionManager adds id/parentId */\n\tcompaction?: CompactionResult;\n}\n\n/** Return type for session_before_tree handlers */\nexport interface SessionBeforeTreeResult {\n\t/** If true, cancel the navigation entirely */\n\tcancel?: boolean;\n\t/**\n\t * Custom summary (skips default summarizer).\n\t * Only used if preparation.userWantsSummary is true.\n\t */\n\tsummary?: {\n\t\tsummary: string;\n\t\tdetails?: unknown;\n\t};\n}\n\n// ============================================================================\n// Hook API\n// ============================================================================\n\n/**\n * Handler function type for each event.\n * Handlers can return R, undefined, or void (bare return statements).\n */\n// biome-ignore lint/suspicious/noConfusingVoidType: void allows bare return statements in handlers\nexport type HookHandler<E, R = undefined> = (event: E, ctx: HookContext) => Promise<R | void> | R | void;\n\nexport interface HookMessageRenderOptions {\n\t/** Whether the view is expanded */\n\texpanded: boolean;\n}\n\n/**\n * Renderer for hook messages.\n * Hooks register these to provide custom TUI rendering for their message types.\n */\nexport type HookMessageRenderer<T = unknown> = (\n\tmessage: HookMessage<T>,\n\toptions: HookMessageRenderOptions,\n\ttheme: Theme,\n) => Component | undefined;\n\n/**\n * Command registration options.\n */\nexport interface RegisteredCommand {\n\tname: string;\n\tdescription?: string;\n\n\thandler: (args: string, ctx: HookCommandContext) => Promise<void>;\n}\n\n/**\n * HookAPI passed to hook factory functions.\n * Hooks use pi.on() to subscribe to events and pi.sendMessage() to inject messages.\n */\nexport interface HookAPI {\n\t// Session events\n\ton(event: \"session_start\", handler: HookHandler<SessionStartEvent>): void;\n\ton(event: \"session_before_switch\", handler: HookHandler<SessionBeforeSwitchEvent, SessionBeforeSwitchResult>): void;\n\ton(event: \"session_switch\", handler: HookHandler<SessionSwitchEvent>): void;\n\ton(event: \"session_before_branch\", handler: HookHandler<SessionBeforeBranchEvent, SessionBeforeBranchResult>): void;\n\ton(event: \"session_branch\", handler: HookHandler<SessionBranchEvent>): void;\n\ton(\n\t\tevent: \"session_before_compact\",\n\t\thandler: HookHandler<SessionBeforeCompactEvent, SessionBeforeCompactResult>,\n\t): void;\n\ton(event: \"session_compact\", handler: HookHandler<SessionCompactEvent>): void;\n\ton(event: \"session_shutdown\", handler: HookHandler<SessionShutdownEvent>): void;\n\ton(event: \"session_before_tree\", handler: HookHandler<SessionBeforeTreeEvent, SessionBeforeTreeResult>): void;\n\ton(event: \"session_tree\", handler: HookHandler<SessionTreeEvent>): void;\n\n\t// Context and agent events\n\ton(event: \"context\", handler: HookHandler<ContextEvent, ContextEventResult>): void;\n\ton(event: \"before_agent_start\", handler: HookHandler<BeforeAgentStartEvent, BeforeAgentStartEventResult>): void;\n\ton(event: \"agent_start\", handler: HookHandler<AgentStartEvent>): void;\n\ton(event: \"agent_end\", handler: HookHandler<AgentEndEvent>): void;\n\ton(event: \"turn_start\", handler: HookHandler<TurnStartEvent>): void;\n\ton(event: \"turn_end\", handler: HookHandler<TurnEndEvent>): void;\n\ton(event: \"tool_call\", handler: HookHandler<ToolCallEvent, ToolCallEventResult>): void;\n\ton(event: \"tool_result\", handler: HookHandler<ToolResultEvent, ToolResultEventResult>): void;\n\n\t/**\n\t * Send a custom message to the session. Creates a CustomMessageEntry that\n\t * participates in LLM context and can be displayed in the TUI.\n\t *\n\t * Use this when you want the LLM to see the message content.\n\t * For hook state that should NOT be sent to the LLM, use appendEntry() instead.\n\t *\n\t * @param message - The message to send\n\t * @param message.customType - Identifier for your hook (used for filtering on reload)\n\t * @param message.content - Message content (string or TextContent/ImageContent array)\n\t * @param message.display - Whether to show in TUI (true = styled display, false = hidden)\n\t * @param message.details - Optional hook-specific metadata (not sent to LLM)\n\t * @param options.triggerTurn - If true and agent is idle, triggers a new LLM turn. Default: false.\n\t * If agent is streaming, message is queued and triggerTurn is ignored.\n\t * @param options.deliverAs - How to deliver when agent is streaming. Default: \"steer\".\n\t * - \"steer\": Interrupt mid-run, delivered after current tool execution.\n\t * - \"followUp\": Wait until agent finishes all work before delivery.\n\t */\n\tsendMessage<T = unknown>(\n\t\tmessage: Pick<HookMessage<T>, \"customType\" | \"content\" | \"display\" | \"details\">,\n\t\toptions?: { triggerTurn?: boolean; deliverAs?: \"steer\" | \"followUp\" },\n\t): void;\n\n\t/**\n\t * Append a custom entry to the session for hook state persistence.\n\t * Creates a CustomEntry that does NOT participate in LLM context.\n\t *\n\t * Use this to store hook-specific data that should persist across session reloads\n\t * but should NOT be sent to the LLM. On reload, scan session entries for your\n\t * customType to reconstruct hook state.\n\t *\n\t * For messages that SHOULD be sent to the LLM, use sendMessage() instead.\n\t *\n\t * @param customType - Identifier for your hook (used for filtering on reload)\n\t * @param data - Hook-specific data to persist (must be JSON-serializable)\n\t *\n\t * @example\n\t * // Store permission state\n\t * pi.appendEntry(\"permissions\", { level: \"full\", grantedAt: Date.now() });\n\t *\n\t * // On reload, reconstruct state from entries\n\t * pi.on(\"session\", async (event, ctx) => {\n\t * if (event.reason === \"start\") {\n\t * const entries = event.sessionManager.getEntries();\n\t * const myEntries = entries.filter(e => e.type === \"custom\" && e.customType === \"permissions\");\n\t * // Reconstruct state from myEntries...\n\t * }\n\t * });\n\t */\n\tappendEntry<T = unknown>(customType: string, data?: T): void;\n\n\t/**\n\t * Register a custom renderer for CustomMessageEntry with a specific customType.\n\t * The renderer is called when rendering the entry in the TUI.\n\t * Return nothing to use the default renderer.\n\t */\n\tregisterMessageRenderer<T = unknown>(customType: string, renderer: HookMessageRenderer<T>): void;\n\n\t/**\n\t * Register a custom slash command.\n\t * Handler receives HookCommandContext with session control methods.\n\t */\n\tregisterCommand(name: string, options: { description?: string; handler: RegisteredCommand[\"handler\"] }): void;\n\n\t/**\n\t * Execute a shell command and return stdout/stderr/code.\n\t * Supports timeout and abort signal.\n\t */\n\texec(command: string, args: string[], options?: ExecOptions): Promise<ExecResult>;\n\n\t/**\n\t * Get the list of currently active tool names.\n\t * @returns Array of tool names (e.g., [\"read\", \"bash\", \"edit\", \"write\"])\n\t */\n\tgetActiveTools(): string[];\n\n\t/**\n\t * Get all configured tools (built-in via --tools or default, plus custom tools).\n\t * @returns Array of all tool names\n\t */\n\tgetAllTools(): string[];\n\n\t/**\n\t * Set the active tools by name.\n\t * Both built-in and custom tools can be enabled/disabled.\n\t * Changes take effect on the next agent turn.\n\t * Note: This will invalidate prompt caching for the next request.\n\t *\n\t * @param toolNames - Array of tool names to enable (e.g., [\"read\", \"bash\", \"grep\", \"find\", \"ls\"])\n\t *\n\t * @example\n\t * // Switch to read-only mode (plan mode)\n\t * pi.setActiveTools([\"read\", \"bash\", \"grep\", \"find\", \"ls\"]);\n\t *\n\t * // Restore full access\n\t * pi.setActiveTools([\"read\", \"bash\", \"edit\", \"write\"]);\n\t */\n\tsetActiveTools(toolNames: string[]): void;\n\n\t/**\n\t * Register a CLI flag for this hook.\n\t * Flags are parsed from command line and values accessible via getFlag().\n\t *\n\t * @param name - Flag name (will be --name on CLI)\n\t * @param options - Flag configuration\n\t *\n\t * @example\n\t * pi.registerFlag(\"plan\", {\n\t * description: \"Start in plan mode (read-only)\",\n\t * type: \"boolean\",\n\t * });\n\t */\n\tregisterFlag(\n\t\tname: string,\n\t\toptions: {\n\t\t\t/** Description shown in --help */\n\t\t\tdescription?: string;\n\t\t\t/** Flag type: boolean (--flag) or string (--flag value) */\n\t\t\ttype: \"boolean\" | \"string\";\n\t\t\t/** Default value */\n\t\t\tdefault?: boolean | string;\n\t\t},\n\t): void;\n\n\t/**\n\t * Get the value of a CLI flag registered by this hook.\n\t * Returns undefined if flag was not provided and has no default.\n\t *\n\t * @param name - Flag name (without --)\n\t * @returns Flag value, or undefined\n\t *\n\t * @example\n\t * if (pi.getFlag(\"plan\")) {\n\t * // plan mode enabled\n\t * }\n\t */\n\tgetFlag(name: string): boolean | string | undefined;\n\n\t/**\n\t * Register a keyboard shortcut for this hook.\n\t * The handler is called when the shortcut is pressed in interactive mode.\n\t *\n\t * @param shortcut - Key identifier (e.g., Key.shift(\"p\"), \"ctrl+x\")\n\t * @param options - Shortcut configuration\n\t *\n\t * @example\n\t * import { Key } from \"@mariozechner/pi-tui\";\n\t *\n\t * pi.registerShortcut(Key.shift(\"p\"), {\n\t * description: \"Toggle plan mode\",\n\t * handler: async (ctx) => {\n\t * // toggle plan mode\n\t * },\n\t * });\n\t */\n\tregisterShortcut(\n\t\tshortcut: KeyId,\n\t\toptions: {\n\t\t\t/** Description shown in help */\n\t\t\tdescription?: string;\n\t\t\t/** Handler called when shortcut is pressed */\n\t\t\thandler: (ctx: HookContext) => Promise<void> | void;\n\t\t},\n\t): void;\n}\n\n/**\n * Hook factory function type.\n * Hooks export a default function that receives the HookAPI.\n */\nexport type HookFactory = (pi: HookAPI) => void;\n\n// ============================================================================\n// Errors\n// ============================================================================\n\n/**\n * Error emitted when a hook fails.\n */\nexport interface HookError {\n\thookPath: string;\n\tevent: string;\n\terror: string;\n\tstack?: string;\n}\n"]}