@mariozechner/pi-coding-agent 0.30.1 → 0.31.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 (301) hide show
  1. package/CHANGELOG.md +251 -2
  2. package/README.md +105 -84
  3. package/dist/cli/args.d.ts.map +1 -1
  4. package/dist/cli/args.js +5 -1
  5. package/dist/cli/args.js.map +1 -1
  6. package/dist/cli/file-processor.d.ts +3 -3
  7. package/dist/cli/file-processor.d.ts.map +1 -1
  8. package/dist/cli/file-processor.js +7 -10
  9. package/dist/cli/file-processor.js.map +1 -1
  10. package/dist/config.d.ts +9 -0
  11. package/dist/config.d.ts.map +1 -1
  12. package/dist/config.js +18 -0
  13. package/dist/config.js.map +1 -1
  14. package/dist/core/agent-session.d.ts +73 -34
  15. package/dist/core/agent-session.d.ts.map +1 -1
  16. package/dist/core/agent-session.js +464 -210
  17. package/dist/core/agent-session.js.map +1 -1
  18. package/dist/core/auth-storage.d.ts +2 -7
  19. package/dist/core/auth-storage.d.ts.map +1 -1
  20. package/dist/core/auth-storage.js +4 -52
  21. package/dist/core/auth-storage.js.map +1 -1
  22. package/dist/core/bash-executor.d.ts +2 -2
  23. package/dist/core/bash-executor.d.ts.map +1 -1
  24. package/dist/core/bash-executor.js +2 -2
  25. package/dist/core/bash-executor.js.map +1 -1
  26. package/dist/core/compaction/branch-summarization.d.ts +84 -0
  27. package/dist/core/compaction/branch-summarization.d.ts.map +1 -0
  28. package/dist/core/compaction/branch-summarization.js +233 -0
  29. package/dist/core/compaction/branch-summarization.js.map +1 -0
  30. package/dist/core/{compaction.d.ts → compaction/compaction.d.ts} +38 -19
  31. package/dist/core/compaction/compaction.d.ts.map +1 -0
  32. package/dist/core/compaction/compaction.js +558 -0
  33. package/dist/core/compaction/compaction.js.map +1 -0
  34. package/dist/core/compaction/index.d.ts +7 -0
  35. package/dist/core/compaction/index.d.ts.map +1 -0
  36. package/dist/core/compaction/index.js +7 -0
  37. package/dist/core/compaction/index.js.map +1 -0
  38. package/dist/core/compaction/utils.d.ts +35 -0
  39. package/dist/core/compaction/utils.d.ts.map +1 -0
  40. package/dist/core/compaction/utils.js +138 -0
  41. package/dist/core/compaction/utils.js.map +1 -0
  42. package/dist/core/custom-tools/index.d.ts +2 -1
  43. package/dist/core/custom-tools/index.d.ts.map +1 -1
  44. package/dist/core/custom-tools/index.js +1 -0
  45. package/dist/core/custom-tools/index.js.map +1 -1
  46. package/dist/core/custom-tools/loader.d.ts.map +1 -1
  47. package/dist/core/custom-tools/loader.js +13 -80
  48. package/dist/core/custom-tools/loader.js.map +1 -1
  49. package/dist/core/custom-tools/types.d.ts +84 -59
  50. package/dist/core/custom-tools/types.d.ts.map +1 -1
  51. package/dist/core/custom-tools/types.js.map +1 -1
  52. package/dist/core/custom-tools/wrapper.d.ts +15 -0
  53. package/dist/core/custom-tools/wrapper.d.ts.map +1 -0
  54. package/dist/core/custom-tools/wrapper.js +23 -0
  55. package/dist/core/custom-tools/wrapper.js.map +1 -0
  56. package/dist/core/exec.d.ts +29 -0
  57. package/dist/core/exec.d.ts.map +1 -0
  58. package/dist/core/exec.js +71 -0
  59. package/dist/core/exec.js.map +1 -0
  60. package/dist/core/export-html/index.d.ts +17 -0
  61. package/dist/core/export-html/index.d.ts.map +1 -0
  62. package/dist/core/export-html/index.js +171 -0
  63. package/dist/core/export-html/index.js.map +1 -0
  64. package/dist/core/export-html/template.css +781 -0
  65. package/dist/core/export-html/template.html +54 -0
  66. package/dist/core/export-html/template.js +1185 -0
  67. package/dist/core/export-html/vendor/highlight.min.js +1213 -0
  68. package/dist/core/export-html/vendor/marked.min.js +6 -0
  69. package/dist/core/hooks/index.d.ts +4 -4
  70. package/dist/core/hooks/index.d.ts.map +1 -1
  71. package/dist/core/hooks/index.js +3 -3
  72. package/dist/core/hooks/index.js.map +1 -1
  73. package/dist/core/hooks/loader.d.ts +40 -5
  74. package/dist/core/hooks/loader.d.ts.map +1 -1
  75. package/dist/core/hooks/loader.js +43 -10
  76. package/dist/core/hooks/loader.js.map +1 -1
  77. package/dist/core/hooks/runner.d.ts +94 -18
  78. package/dist/core/hooks/runner.d.ts.map +1 -1
  79. package/dist/core/hooks/runner.js +199 -120
  80. package/dist/core/hooks/runner.js.map +1 -1
  81. package/dist/core/hooks/tool-wrapper.d.ts +1 -1
  82. package/dist/core/hooks/tool-wrapper.d.ts.map +1 -1
  83. package/dist/core/hooks/tool-wrapper.js +36 -19
  84. package/dist/core/hooks/tool-wrapper.js.map +1 -1
  85. package/dist/core/hooks/types.d.ts +407 -96
  86. package/dist/core/hooks/types.d.ts.map +1 -1
  87. package/dist/core/hooks/types.js.map +1 -1
  88. package/dist/core/index.d.ts +4 -3
  89. package/dist/core/index.d.ts.map +1 -1
  90. package/dist/core/index.js.map +1 -1
  91. package/dist/core/messages.d.ts +44 -12
  92. package/dist/core/messages.d.ts.map +1 -1
  93. package/dist/core/messages.js +82 -34
  94. package/dist/core/messages.js.map +1 -1
  95. package/dist/core/model-registry.d.ts +5 -5
  96. package/dist/core/model-registry.d.ts.map +1 -1
  97. package/dist/core/model-registry.js +7 -7
  98. package/dist/core/model-registry.js.map +1 -1
  99. package/dist/core/model-resolver.d.ts +7 -7
  100. package/dist/core/model-resolver.d.ts.map +1 -1
  101. package/dist/core/model-resolver.js +45 -14
  102. package/dist/core/model-resolver.js.map +1 -1
  103. package/dist/core/sdk.d.ts +7 -10
  104. package/dist/core/sdk.d.ts.map +1 -1
  105. package/dist/core/sdk.js +88 -32
  106. package/dist/core/sdk.js.map +1 -1
  107. package/dist/core/session-manager.d.ts +202 -36
  108. package/dist/core/session-manager.d.ts.map +1 -1
  109. package/dist/core/session-manager.js +565 -133
  110. package/dist/core/session-manager.js.map +1 -1
  111. package/dist/core/settings-manager.d.ts +9 -3
  112. package/dist/core/settings-manager.d.ts.map +1 -1
  113. package/dist/core/settings-manager.js +13 -12
  114. package/dist/core/settings-manager.js.map +1 -1
  115. package/dist/core/system-prompt.d.ts.map +1 -1
  116. package/dist/core/system-prompt.js +6 -3
  117. package/dist/core/system-prompt.js.map +1 -1
  118. package/dist/core/tools/bash.d.ts +1 -1
  119. package/dist/core/tools/bash.d.ts.map +1 -1
  120. package/dist/core/tools/bash.js.map +1 -1
  121. package/dist/core/tools/edit-diff.d.ts +33 -0
  122. package/dist/core/tools/edit-diff.d.ts.map +1 -0
  123. package/dist/core/tools/edit-diff.js +171 -0
  124. package/dist/core/tools/edit-diff.js.map +1 -0
  125. package/dist/core/tools/edit.d.ts +7 -1
  126. package/dist/core/tools/edit.d.ts.map +1 -1
  127. package/dist/core/tools/edit.js +20 -95
  128. package/dist/core/tools/edit.js.map +1 -1
  129. package/dist/core/tools/find.d.ts +1 -1
  130. package/dist/core/tools/find.d.ts.map +1 -1
  131. package/dist/core/tools/find.js.map +1 -1
  132. package/dist/core/tools/grep.d.ts +1 -1
  133. package/dist/core/tools/grep.d.ts.map +1 -1
  134. package/dist/core/tools/grep.js.map +1 -1
  135. package/dist/core/tools/index.d.ts +1 -1
  136. package/dist/core/tools/index.d.ts.map +1 -1
  137. package/dist/core/tools/index.js.map +1 -1
  138. package/dist/core/tools/ls.d.ts +1 -1
  139. package/dist/core/tools/ls.d.ts.map +1 -1
  140. package/dist/core/tools/ls.js.map +1 -1
  141. package/dist/core/tools/read.d.ts +1 -1
  142. package/dist/core/tools/read.d.ts.map +1 -1
  143. package/dist/core/tools/read.js.map +1 -1
  144. package/dist/core/tools/write.d.ts +1 -1
  145. package/dist/core/tools/write.d.ts.map +1 -1
  146. package/dist/core/tools/write.js.map +1 -1
  147. package/dist/index.d.ts +8 -7
  148. package/dist/index.d.ts.map +1 -1
  149. package/dist/index.js +5 -5
  150. package/dist/index.js.map +1 -1
  151. package/dist/main.d.ts.map +1 -1
  152. package/dist/main.js +25 -25
  153. package/dist/main.js.map +1 -1
  154. package/dist/migrations.d.ts +28 -0
  155. package/dist/migrations.d.ts.map +1 -0
  156. package/dist/migrations.js +125 -0
  157. package/dist/migrations.js.map +1 -0
  158. package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
  159. package/dist/modes/interactive/components/assistant-message.js +3 -4
  160. package/dist/modes/interactive/components/assistant-message.js.map +1 -1
  161. package/dist/modes/interactive/components/bash-execution.d.ts +1 -1
  162. package/dist/modes/interactive/components/bash-execution.d.ts.map +1 -1
  163. package/dist/modes/interactive/components/bash-execution.js +6 -2
  164. package/dist/modes/interactive/components/bash-execution.js.map +1 -1
  165. package/dist/modes/interactive/components/bordered-loader.d.ts +12 -0
  166. package/dist/modes/interactive/components/bordered-loader.d.ts.map +1 -0
  167. package/dist/modes/interactive/components/bordered-loader.js +30 -0
  168. package/dist/modes/interactive/components/bordered-loader.js.map +1 -0
  169. package/dist/modes/interactive/components/branch-summary-message.d.ts +14 -0
  170. package/dist/modes/interactive/components/branch-summary-message.d.ts.map +1 -0
  171. package/dist/modes/interactive/components/branch-summary-message.js +35 -0
  172. package/dist/modes/interactive/components/branch-summary-message.js.map +1 -0
  173. package/dist/modes/interactive/components/compaction-summary-message.d.ts +14 -0
  174. package/dist/modes/interactive/components/compaction-summary-message.d.ts.map +1 -0
  175. package/dist/modes/interactive/components/compaction-summary-message.js +36 -0
  176. package/dist/modes/interactive/components/compaction-summary-message.js.map +1 -0
  177. package/dist/modes/interactive/components/dynamic-border.d.ts +5 -1
  178. package/dist/modes/interactive/components/dynamic-border.d.ts.map +1 -1
  179. package/dist/modes/interactive/components/dynamic-border.js +5 -1
  180. package/dist/modes/interactive/components/dynamic-border.js.map +1 -1
  181. package/dist/modes/interactive/components/footer.d.ts +12 -6
  182. package/dist/modes/interactive/components/footer.d.ts.map +1 -1
  183. package/dist/modes/interactive/components/footer.js +57 -25
  184. package/dist/modes/interactive/components/footer.js.map +1 -1
  185. package/dist/modes/interactive/components/hook-editor.d.ts +15 -0
  186. package/dist/modes/interactive/components/hook-editor.d.ts.map +1 -0
  187. package/dist/modes/interactive/components/hook-editor.js +95 -0
  188. package/dist/modes/interactive/components/hook-editor.js.map +1 -0
  189. package/dist/modes/interactive/components/hook-message.d.ts +18 -0
  190. package/dist/modes/interactive/components/hook-message.d.ts.map +1 -0
  191. package/dist/modes/interactive/components/hook-message.js +80 -0
  192. package/dist/modes/interactive/components/hook-message.js.map +1 -0
  193. package/dist/modes/interactive/components/model-selector.d.ts +3 -3
  194. package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
  195. package/dist/modes/interactive/components/model-selector.js +1 -1
  196. package/dist/modes/interactive/components/model-selector.js.map +1 -1
  197. package/dist/modes/interactive/components/tool-execution.d.ts +15 -2
  198. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  199. package/dist/modes/interactive/components/tool-execution.js +70 -21
  200. package/dist/modes/interactive/components/tool-execution.js.map +1 -1
  201. package/dist/modes/interactive/components/tree-selector.d.ts +52 -0
  202. package/dist/modes/interactive/components/tree-selector.d.ts.map +1 -0
  203. package/dist/modes/interactive/components/tree-selector.js +745 -0
  204. package/dist/modes/interactive/components/tree-selector.js.map +1 -0
  205. package/dist/modes/interactive/components/user-message-selector.d.ts +3 -3
  206. package/dist/modes/interactive/components/user-message-selector.d.ts.map +1 -1
  207. package/dist/modes/interactive/components/user-message-selector.js +1 -1
  208. package/dist/modes/interactive/components/user-message-selector.js.map +1 -1
  209. package/dist/modes/interactive/components/user-message.d.ts +1 -1
  210. package/dist/modes/interactive/components/user-message.d.ts.map +1 -1
  211. package/dist/modes/interactive/components/user-message.js +2 -5
  212. package/dist/modes/interactive/components/user-message.js.map +1 -1
  213. package/dist/modes/interactive/interactive-mode.d.ts +29 -12
  214. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  215. package/dist/modes/interactive/interactive-mode.js +589 -208
  216. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  217. package/dist/modes/interactive/theme/dark.json +13 -1
  218. package/dist/modes/interactive/theme/light.json +13 -1
  219. package/dist/modes/interactive/theme/theme-schema.json +34 -0
  220. package/dist/modes/interactive/theme/theme.d.ts +20 -2
  221. package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
  222. package/dist/modes/interactive/theme/theme.js +135 -2
  223. package/dist/modes/interactive/theme/theme.js.map +1 -1
  224. package/dist/modes/print-mode.d.ts +3 -3
  225. package/dist/modes/print-mode.d.ts.map +1 -1
  226. package/dist/modes/print-mode.js +26 -20
  227. package/dist/modes/print-mode.js.map +1 -1
  228. package/dist/modes/rpc/rpc-client.d.ts +13 -10
  229. package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
  230. package/dist/modes/rpc/rpc-client.js +11 -10
  231. package/dist/modes/rpc/rpc-client.js.map +1 -1
  232. package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
  233. package/dist/modes/rpc/rpc-mode.js +88 -35
  234. package/dist/modes/rpc/rpc-mode.js.map +1 -1
  235. package/dist/modes/rpc/rpc-types.d.ts +30 -11
  236. package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
  237. package/dist/modes/rpc/rpc-types.js.map +1 -1
  238. package/dist/utils/shell.d.ts +4 -2
  239. package/dist/utils/shell.d.ts.map +1 -1
  240. package/dist/utils/shell.js +36 -7
  241. package/dist/utils/shell.js.map +1 -1
  242. package/dist/utils/tools-manager.d.ts +1 -1
  243. package/dist/utils/tools-manager.d.ts.map +1 -1
  244. package/dist/utils/tools-manager.js +2 -2
  245. package/dist/utils/tools-manager.js.map +1 -1
  246. package/docs/compaction.md +388 -0
  247. package/docs/custom-tools.md +146 -43
  248. package/docs/extension-loading.md +1004 -0
  249. package/docs/hooks.md +562 -596
  250. package/docs/rpc.md +33 -19
  251. package/docs/sdk.md +93 -21
  252. package/docs/session-tree-plan.md +441 -0
  253. package/docs/session.md +172 -21
  254. package/docs/skills.md +2 -0
  255. package/docs/theme.md +31 -2
  256. package/docs/tree.md +197 -0
  257. package/docs/tui.md +343 -0
  258. package/examples/README.md +1 -9
  259. package/examples/custom-tools/hello/index.ts +4 -3
  260. package/examples/custom-tools/question/index.ts +4 -4
  261. package/examples/custom-tools/subagent/index.ts +7 -6
  262. package/examples/custom-tools/todo/index.ts +11 -5
  263. package/examples/hooks/README.md +29 -71
  264. package/examples/hooks/auto-commit-on-exit.ts +8 -9
  265. package/examples/hooks/confirm-destructive.ts +29 -30
  266. package/examples/hooks/custom-compaction.ts +20 -21
  267. package/examples/hooks/dirty-repo-guard.ts +41 -40
  268. package/examples/hooks/file-trigger.ts +10 -5
  269. package/examples/hooks/git-checkpoint.ts +16 -12
  270. package/examples/hooks/handoff.ts +150 -0
  271. package/examples/hooks/permission-gate.ts +1 -1
  272. package/examples/hooks/protected-paths.ts +1 -1
  273. package/examples/hooks/qna.ts +119 -0
  274. package/examples/hooks/snake.ts +343 -0
  275. package/examples/hooks/status-line.ts +40 -0
  276. package/examples/sdk/01-minimal.ts +1 -1
  277. package/examples/sdk/02-custom-model.ts +1 -1
  278. package/examples/sdk/03-custom-prompt.ts +1 -1
  279. package/examples/sdk/04-skills.ts +1 -1
  280. package/examples/sdk/05-tools.ts +4 -4
  281. package/examples/sdk/06-hooks.ts +1 -1
  282. package/examples/sdk/07-context-files.ts +1 -1
  283. package/examples/sdk/08-slash-commands.ts +6 -1
  284. package/examples/sdk/09-api-keys-and-oauth.ts +1 -1
  285. package/examples/sdk/10-settings.ts +1 -1
  286. package/examples/sdk/11-sessions.ts +1 -1
  287. package/examples/sdk/12-full-control.ts +4 -7
  288. package/package.json +6 -6
  289. package/dist/core/compaction.d.ts.map +0 -1
  290. package/dist/core/compaction.js +0 -412
  291. package/dist/core/compaction.js.map +0 -1
  292. package/dist/core/export-html.d.ts +0 -23
  293. package/dist/core/export-html.d.ts.map +0 -1
  294. package/dist/core/export-html.js +0 -1185
  295. package/dist/core/export-html.js.map +0 -1
  296. package/dist/modes/interactive/components/compaction.d.ts +0 -15
  297. package/dist/modes/interactive/components/compaction.d.ts.map +0 -1
  298. package/dist/modes/interactive/components/compaction.js +0 -41
  299. package/dist/modes/interactive/components/compaction.js.map +0 -1
  300. package/docs/hooks-v2.md +0 -385
  301. package/docs/session-tree.md +0 -452
@@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,EAAE,qBAAqB,GAAG,SAAS,CAAC,GAAG,IAAI,CAAC;IAEzG;;;;OAIG;IACH,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,UAAU,EAAE,GAAG,IAAI,CAAC;CACrD;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 { AppMessage, Attachment } from \"@mariozechner/pi-agent-core\";\nimport type { ImageContent, Model, TextContent, ToolResultMessage } from \"@mariozechner/pi-ai\";\nimport type { CutPointResult } from \"../compaction.js\";\nimport type { CompactionEntry, SessionEntry } from \"../session-manager.js\";\nimport type {\n\tBashToolDetails,\n\tFindToolDetails,\n\tGrepToolDetails,\n\tLsToolDetails,\n\tReadToolDetails,\n} from \"../tools/index.js\";\n\n// ============================================================================\n// Execution Context\n// ============================================================================\n\n/**\n * Result of executing a command via ctx.exec()\n */\nexport interface ExecResult {\n\tstdout: string;\n\tstderr: string;\n\tcode: number;\n\t/** True if the process was killed due to signal or timeout */\n\tkilled?: boolean;\n}\n\nexport interface ExecOptions {\n\t/** AbortSignal to cancel the process */\n\tsignal?: AbortSignal;\n\t/** Timeout in milliseconds */\n\ttimeout?: number;\n}\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 | null>;\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 null if cancelled\n\t */\n\tinput(title: string, placeholder?: string): Promise<string | null>;\n\n\t/**\n\t * Show a notification to the user.\n\t */\n\tnotify(message: string, type?: \"info\" | \"warning\" | \"error\"): void;\n}\n\n/**\n * Context passed to hook event handlers.\n */\nexport interface HookEventContext {\n\t/** Execute a command and return stdout/stderr/code */\n\texec(command: string, args: string[], options?: ExecOptions): Promise<ExecResult>;\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/** Path to session file, or null if --no-session */\n\tsessionFile: string | null;\n}\n\n// ============================================================================\n// Events\n// ============================================================================\n\n/**\n * Base fields shared by all session events.\n */\ninterface SessionEventBase {\n\ttype: \"session\";\n\t/** All session entries (including pre-compaction history) */\n\tentries: SessionEntry[];\n\t/** Current session file path, or null in --no-session mode */\n\tsessionFile: string | null;\n\t/** Previous session file path, or null for \"start\" and \"new\" */\n\tpreviousSessionFile: string | null;\n}\n\n/**\n * Event data for session events.\n * Discriminated union based on reason.\n *\n * Lifecycle:\n * - start: Initial session load\n * - before_switch / switch: Session switch (e.g., /resume command)\n * - before_new / new: New session (e.g., /new command)\n * - before_branch / branch: Session branch (e.g., /branch command)\n * - before_compact / compact: Before/after context compaction\n * - shutdown: Process exit (SIGINT/SIGTERM)\n *\n * \"before_*\" events fire before the action and can be cancelled via SessionEventResult.\n * Other events fire after the action completes.\n */\nexport type SessionEvent =\n\t| (SessionEventBase & {\n\t\t\treason: \"start\" | \"switch\" | \"new\" | \"before_switch\" | \"before_new\" | \"shutdown\";\n\t })\n\t| (SessionEventBase & {\n\t\t\treason: \"branch\" | \"before_branch\";\n\t\t\t/** Index of the turn to branch from */\n\t\t\ttargetTurnIndex: number;\n\t })\n\t| (SessionEventBase & {\n\t\t\treason: \"before_compact\";\n\t\t\tcutPoint: CutPointResult;\n\t\t\t/** Summary from previous compaction, if any. Include this in your summary to preserve context. */\n\t\t\tpreviousSummary?: string;\n\t\t\t/** Messages that will be summarized and discarded */\n\t\t\tmessagesToSummarize: AppMessage[];\n\t\t\t/** Messages that will be kept after the summary (recent turns) */\n\t\t\tmessagesToKeep: AppMessage[];\n\t\t\ttokensBefore: number;\n\t\t\tcustomInstructions?: string;\n\t\t\tmodel: Model<any>;\n\t\t\t/** Resolve API key for any model (checks settings, OAuth, env vars) */\n\t\t\tresolveApiKey: (model: Model<any>) => Promise<string | undefined>;\n\t\t\t/** Abort signal - hooks should pass this to LLM calls and check it periodically */\n\t\t\tsignal: AbortSignal;\n\t })\n\t| (SessionEventBase & {\n\t\t\treason: \"compact\";\n\t\t\tcompactionEntry: CompactionEntry;\n\t\t\ttokensBefore: number;\n\t\t\t/** Whether the compaction entry was provided by a hook */\n\t\t\tfromHook: boolean;\n\t });\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: AppMessage[];\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: AppMessage;\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: 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| 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 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 session event handlers.\n * Allows hooks to cancel \"before_*\" actions.\n */\nexport interface SessionEventResult {\n\t/** If true, cancel the pending action (switch, clear, or branch) */\n\tcancel?: boolean;\n\t/** If true (for before_branch only), skip restoring conversation to branch point while still creating the branched session file */\n\tskipConversationRestore?: boolean;\n\t/** Custom compaction entry (for before_compact event) */\n\tcompactionEntry?: CompactionEntry;\n}\n\n// ============================================================================\n// Hook API\n// ============================================================================\n\n/**\n * Handler function type for each event.\n */\nexport type HookHandler<E, R = void> = (event: E, ctx: HookEventContext) => Promise<R>;\n\n/**\n * HookAPI passed to hook factory functions.\n * Hooks use pi.on() to subscribe to events and pi.send() to inject messages.\n */\nexport interface HookAPI {\n\t// biome-ignore lint/suspicious/noConfusingVoidType: void allows handlers to not return anything\n\ton(event: \"session\", handler: HookHandler<SessionEvent, SessionEventResult | void>): 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 | undefined>): void;\n\ton(event: \"tool_result\", handler: HookHandler<ToolResultEvent, ToolResultEventResult | undefined>): void;\n\n\t/**\n\t * Send a message to the agent.\n\t * If the agent is streaming, the message is queued.\n\t * If the agent is idle, a new agent loop is started.\n\t */\n\tsend(text: string, attachments?: Attachment[]): 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}\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,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxG,OAAO,KAAK,EAAE,SAAS,EAAE,GAAG,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,KAA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ks 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\thasQueuedMessages(): 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 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 */\n\tsendMessage<T = unknown>(\n\t\tmessage: Pick<HookMessage<T>, \"customType\" | \"content\" | \"display\" | \"details\">,\n\t\ttriggerTurn?: boolean,\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 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/core/hooks/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAoRH,mEAAmE;AACnE,MAAM,UAAU,gBAAgB,CAAC,CAAkB,EAA4B;IAC9E,OAAO,CAAC,CAAC,QAAQ,KAAK,MAAM,CAAC;AAAA,CAC7B;AACD,MAAM,UAAU,gBAAgB,CAAC,CAAkB,EAA4B;IAC9E,OAAO,CAAC,CAAC,QAAQ,KAAK,MAAM,CAAC;AAAA,CAC7B;AACD,MAAM,UAAU,gBAAgB,CAAC,CAAkB,EAA4B;IAC9E,OAAO,CAAC,CAAC,QAAQ,KAAK,MAAM,CAAC;AAAA,CAC7B;AACD,MAAM,UAAU,iBAAiB,CAAC,CAAkB,EAA6B;IAChF,OAAO,CAAC,CAAC,QAAQ,KAAK,OAAO,CAAC;AAAA,CAC9B;AACD,MAAM,UAAU,gBAAgB,CAAC,CAAkB,EAA4B;IAC9E,OAAO,CAAC,CAAC,QAAQ,KAAK,MAAM,CAAC;AAAA,CAC7B;AACD,MAAM,UAAU,gBAAgB,CAAC,CAAkB,EAA4B;IAC9E,OAAO,CAAC,CAAC,QAAQ,KAAK,MAAM,CAAC;AAAA,CAC7B;AACD,MAAM,UAAU,cAAc,CAAC,CAAkB,EAA0B;IAC1E,OAAO,CAAC,CAAC,QAAQ,KAAK,IAAI,CAAC;AAAA,CAC3B","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 { AppMessage, Attachment } from \"@mariozechner/pi-agent-core\";\nimport type { ImageContent, Model, TextContent, ToolResultMessage } from \"@mariozechner/pi-ai\";\nimport type { CutPointResult } from \"../compaction.js\";\nimport type { CompactionEntry, SessionEntry } from \"../session-manager.js\";\nimport type {\n\tBashToolDetails,\n\tFindToolDetails,\n\tGrepToolDetails,\n\tLsToolDetails,\n\tReadToolDetails,\n} from \"../tools/index.js\";\n\n// ============================================================================\n// Execution Context\n// ============================================================================\n\n/**\n * Result of executing a command via ctx.exec()\n */\nexport interface ExecResult {\n\tstdout: string;\n\tstderr: string;\n\tcode: number;\n\t/** True if the process was killed due to signal or timeout */\n\tkilled?: boolean;\n}\n\nexport interface ExecOptions {\n\t/** AbortSignal to cancel the process */\n\tsignal?: AbortSignal;\n\t/** Timeout in milliseconds */\n\ttimeout?: number;\n}\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 | null>;\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 null if cancelled\n\t */\n\tinput(title: string, placeholder?: string): Promise<string | null>;\n\n\t/**\n\t * Show a notification to the user.\n\t */\n\tnotify(message: string, type?: \"info\" | \"warning\" | \"error\"): void;\n}\n\n/**\n * Context passed to hook event handlers.\n */\nexport interface HookEventContext {\n\t/** Execute a command and return stdout/stderr/code */\n\texec(command: string, args: string[], options?: ExecOptions): Promise<ExecResult>;\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/** Path to session file, or null if --no-session */\n\tsessionFile: string | null;\n}\n\n// ============================================================================\n// Events\n// ============================================================================\n\n/**\n * Base fields shared by all session events.\n */\ninterface SessionEventBase {\n\ttype: \"session\";\n\t/** All session entries (including pre-compaction history) */\n\tentries: SessionEntry[];\n\t/** Current session file path, or null in --no-session mode */\n\tsessionFile: string | null;\n\t/** Previous session file path, or null for \"start\" and \"new\" */\n\tpreviousSessionFile: string | null;\n}\n\n/**\n * Event data for session events.\n * Discriminated union based on reason.\n *\n * Lifecycle:\n * - start: Initial session load\n * - before_switch / switch: Session switch (e.g., /resume command)\n * - before_new / new: New session (e.g., /new command)\n * - before_branch / branch: Session branch (e.g., /branch command)\n * - before_compact / compact: Before/after context compaction\n * - shutdown: Process exit (SIGINT/SIGTERM)\n *\n * \"before_*\" events fire before the action and can be cancelled via SessionEventResult.\n * Other events fire after the action completes.\n */\nexport type SessionEvent =\n\t| (SessionEventBase & {\n\t\t\treason: \"start\" | \"switch\" | \"new\" | \"before_switch\" | \"before_new\" | \"shutdown\";\n\t })\n\t| (SessionEventBase & {\n\t\t\treason: \"branch\" | \"before_branch\";\n\t\t\t/** Index of the turn to branch from */\n\t\t\ttargetTurnIndex: number;\n\t })\n\t| (SessionEventBase & {\n\t\t\treason: \"before_compact\";\n\t\t\tcutPoint: CutPointResult;\n\t\t\t/** Summary from previous compaction, if any. Include this in your summary to preserve context. */\n\t\t\tpreviousSummary?: string;\n\t\t\t/** Messages that will be summarized and discarded */\n\t\t\tmessagesToSummarize: AppMessage[];\n\t\t\t/** Messages that will be kept after the summary (recent turns) */\n\t\t\tmessagesToKeep: AppMessage[];\n\t\t\ttokensBefore: number;\n\t\t\tcustomInstructions?: string;\n\t\t\tmodel: Model<any>;\n\t\t\t/** Resolve API key for any model (checks settings, OAuth, env vars) */\n\t\t\tresolveApiKey: (model: Model<any>) => Promise<string | undefined>;\n\t\t\t/** Abort signal - hooks should pass this to LLM calls and check it periodically */\n\t\t\tsignal: AbortSignal;\n\t })\n\t| (SessionEventBase & {\n\t\t\treason: \"compact\";\n\t\t\tcompactionEntry: CompactionEntry;\n\t\t\ttokensBefore: number;\n\t\t\t/** Whether the compaction entry was provided by a hook */\n\t\t\tfromHook: boolean;\n\t });\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: AppMessage[];\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: AppMessage;\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: 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| 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 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 session event handlers.\n * Allows hooks to cancel \"before_*\" actions.\n */\nexport interface SessionEventResult {\n\t/** If true, cancel the pending action (switch, clear, or branch) */\n\tcancel?: boolean;\n\t/** If true (for before_branch only), skip restoring conversation to branch point while still creating the branched session file */\n\tskipConversationRestore?: boolean;\n\t/** Custom compaction entry (for before_compact event) */\n\tcompactionEntry?: CompactionEntry;\n}\n\n// ============================================================================\n// Hook API\n// ============================================================================\n\n/**\n * Handler function type for each event.\n */\nexport type HookHandler<E, R = void> = (event: E, ctx: HookEventContext) => Promise<R>;\n\n/**\n * HookAPI passed to hook factory functions.\n * Hooks use pi.on() to subscribe to events and pi.send() to inject messages.\n */\nexport interface HookAPI {\n\t// biome-ignore lint/suspicious/noConfusingVoidType: void allows handlers to not return anything\n\ton(event: \"session\", handler: HookHandler<SessionEvent, SessionEventResult | void>): 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 | undefined>): void;\n\ton(event: \"tool_result\", handler: HookHandler<ToolResultEvent, ToolResultEventResult | undefined>): void;\n\n\t/**\n\t * Send a message to the agent.\n\t * If the agent is streaming, the message is queued.\n\t * If the agent is idle, a new agent loop is started.\n\t */\n\tsend(text: string, attachments?: Attachment[]): 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}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/core/hooks/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AA8dH,mEAAmE;AACnE,MAAM,UAAU,gBAAgB,CAAC,CAAkB,EAA4B;IAC9E,OAAO,CAAC,CAAC,QAAQ,KAAK,MAAM,CAAC;AAAA,CAC7B;AACD,MAAM,UAAU,gBAAgB,CAAC,CAAkB,EAA4B;IAC9E,OAAO,CAAC,CAAC,QAAQ,KAAK,MAAM,CAAC;AAAA,CAC7B;AACD,MAAM,UAAU,gBAAgB,CAAC,CAAkB,EAA4B;IAC9E,OAAO,CAAC,CAAC,QAAQ,KAAK,MAAM,CAAC;AAAA,CAC7B;AACD,MAAM,UAAU,iBAAiB,CAAC,CAAkB,EAA6B;IAChF,OAAO,CAAC,CAAC,QAAQ,KAAK,OAAO,CAAC;AAAA,CAC9B;AACD,MAAM,UAAU,gBAAgB,CAAC,CAAkB,EAA4B;IAC9E,OAAO,CAAC,CAAC,QAAQ,KAAK,MAAM,CAAC;AAAA,CAC7B;AACD,MAAM,UAAU,gBAAgB,CAAC,CAAkB,EAA4B;IAC9E,OAAO,CAAC,CAAC,QAAQ,KAAK,MAAM,CAAC;AAAA,CAC7B;AACD,MAAM,UAAU,cAAc,CAAC,CAAkB,EAA0B;IAC1E,OAAO,CAAC,CAAC,QAAQ,KAAK,IAAI,CAAC;AAAA,CAC3B","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\thasQueuedMessages(): 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 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 */\n\tsendMessage<T = unknown>(\n\t\tmessage: Pick<HookMessage<T>, \"customType\" | \"content\" | \"display\" | \"details\">,\n\t\ttriggerTurn?: boolean,\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,8 +1,9 @@
1
1
  /**
2
2
  * Core modules shared between all run modes.
3
3
  */
4
- export { AgentSession, type AgentSessionConfig, type AgentSessionEvent, type AgentSessionEventListener, type CompactionResult, type ModelCycleResult, type PromptOptions, type SessionStats, } from "./agent-session.js";
4
+ export { AgentSession, type AgentSessionConfig, type AgentSessionEvent, type AgentSessionEventListener, type ModelCycleResult, type PromptOptions, type SessionStats, } from "./agent-session.js";
5
5
  export { type BashExecutorOptions, type BashResult, executeBash } from "./bash-executor.js";
6
- export { type CustomAgentTool, type CustomToolFactory, type CustomToolsLoadResult, discoverAndLoadCustomTools, type ExecResult, type LoadedCustomTool, loadCustomTools, type RenderResultOptions, type ToolAPI, type ToolUIContext, } from "./custom-tools/index.js";
7
- export { type HookAPI, type HookError, type HookEvent, type HookEventContext, type HookFactory, HookRunner, type HookUIContext, loadHooks, } from "./hooks/index.js";
6
+ export type { CompactionResult } from "./compaction/index.js";
7
+ export { type CustomTool, type CustomToolAPI, type CustomToolFactory, type CustomToolsLoadResult, type CustomToolUIContext, discoverAndLoadCustomTools, type ExecResult, type LoadedCustomTool, loadCustomTools, type RenderResultOptions, } from "./custom-tools/index.js";
8
+ export { type HookAPI, type HookContext, type HookError, type HookEvent, type HookFactory, HookRunner, type HookUIContext, loadHooks, } from "./hooks/index.js";
8
9
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACN,YAAY,EACZ,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EACtB,KAAK,yBAAyB,EAC9B,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EACrB,KAAK,aAAa,EAClB,KAAK,YAAY,GACjB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,KAAK,mBAAmB,EAAE,KAAK,UAAU,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAC5F,OAAO,EACN,KAAK,eAAe,EACpB,KAAK,iBAAiB,EACtB,KAAK,qBAAqB,EAC1B,0BAA0B,EAC1B,KAAK,UAAU,EACf,KAAK,gBAAgB,EACrB,eAAe,EACf,KAAK,mBAAmB,EACxB,KAAK,OAAO,EACZ,KAAK,aAAa,GAClB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACN,KAAK,OAAO,EACZ,KAAK,SAAS,EACd,KAAK,SAAS,EACd,KAAK,gBAAgB,EACrB,KAAK,WAAW,EAChB,UAAU,EACV,KAAK,aAAa,EAClB,SAAS,GACT,MAAM,kBAAkB,CAAC","sourcesContent":["/**\n * Core modules shared between all run modes.\n */\n\nexport {\n\tAgentSession,\n\ttype AgentSessionConfig,\n\ttype AgentSessionEvent,\n\ttype AgentSessionEventListener,\n\ttype CompactionResult,\n\ttype ModelCycleResult,\n\ttype PromptOptions,\n\ttype SessionStats,\n} from \"./agent-session.js\";\nexport { type BashExecutorOptions, type BashResult, executeBash } from \"./bash-executor.js\";\nexport {\n\ttype CustomAgentTool,\n\ttype CustomToolFactory,\n\ttype CustomToolsLoadResult,\n\tdiscoverAndLoadCustomTools,\n\ttype ExecResult,\n\ttype LoadedCustomTool,\n\tloadCustomTools,\n\ttype RenderResultOptions,\n\ttype ToolAPI,\n\ttype ToolUIContext,\n} from \"./custom-tools/index.js\";\nexport {\n\ttype HookAPI,\n\ttype HookError,\n\ttype HookEvent,\n\ttype HookEventContext,\n\ttype HookFactory,\n\tHookRunner,\n\ttype HookUIContext,\n\tloadHooks,\n} from \"./hooks/index.js\";\n"]}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACN,YAAY,EACZ,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EACtB,KAAK,yBAAyB,EAC9B,KAAK,gBAAgB,EACrB,KAAK,aAAa,EAClB,KAAK,YAAY,GACjB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,KAAK,mBAAmB,EAAE,KAAK,UAAU,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAC5F,YAAY,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,EACN,KAAK,UAAU,EACf,KAAK,aAAa,EAClB,KAAK,iBAAiB,EACtB,KAAK,qBAAqB,EAC1B,KAAK,mBAAmB,EACxB,0BAA0B,EAC1B,KAAK,UAAU,EACf,KAAK,gBAAgB,EACrB,eAAe,EACf,KAAK,mBAAmB,GACxB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACN,KAAK,OAAO,EACZ,KAAK,WAAW,EAChB,KAAK,SAAS,EACd,KAAK,SAAS,EACd,KAAK,WAAW,EAChB,UAAU,EACV,KAAK,aAAa,EAClB,SAAS,GACT,MAAM,kBAAkB,CAAC","sourcesContent":["/**\n * Core modules shared between all run modes.\n */\n\nexport {\n\tAgentSession,\n\ttype AgentSessionConfig,\n\ttype AgentSessionEvent,\n\ttype AgentSessionEventListener,\n\ttype ModelCycleResult,\n\ttype PromptOptions,\n\ttype SessionStats,\n} from \"./agent-session.js\";\nexport { type BashExecutorOptions, type BashResult, executeBash } from \"./bash-executor.js\";\nexport type { CompactionResult } from \"./compaction/index.js\";\nexport {\n\ttype CustomTool,\n\ttype CustomToolAPI,\n\ttype CustomToolFactory,\n\ttype CustomToolsLoadResult,\n\ttype CustomToolUIContext,\n\tdiscoverAndLoadCustomTools,\n\ttype ExecResult,\n\ttype LoadedCustomTool,\n\tloadCustomTools,\n\ttype RenderResultOptions,\n} from \"./custom-tools/index.js\";\nexport {\n\ttype HookAPI,\n\ttype HookContext,\n\ttype HookError,\n\ttype HookEvent,\n\ttype HookFactory,\n\tHookRunner,\n\ttype HookUIContext,\n\tloadHooks,\n} from \"./hooks/index.js\";\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACN,YAAY,GAQZ,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAA6C,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAC5F,OAAO,EAIN,0BAA0B,EAG1B,eAAe,GAIf,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAMN,UAAU,EAEV,SAAS,GACT,MAAM,kBAAkB,CAAC","sourcesContent":["/**\n * Core modules shared between all run modes.\n */\n\nexport {\n\tAgentSession,\n\ttype AgentSessionConfig,\n\ttype AgentSessionEvent,\n\ttype AgentSessionEventListener,\n\ttype CompactionResult,\n\ttype ModelCycleResult,\n\ttype PromptOptions,\n\ttype SessionStats,\n} from \"./agent-session.js\";\nexport { type BashExecutorOptions, type BashResult, executeBash } from \"./bash-executor.js\";\nexport {\n\ttype CustomAgentTool,\n\ttype CustomToolFactory,\n\ttype CustomToolsLoadResult,\n\tdiscoverAndLoadCustomTools,\n\ttype ExecResult,\n\ttype LoadedCustomTool,\n\tloadCustomTools,\n\ttype RenderResultOptions,\n\ttype ToolAPI,\n\ttype ToolUIContext,\n} from \"./custom-tools/index.js\";\nexport {\n\ttype HookAPI,\n\ttype HookError,\n\ttype HookEvent,\n\ttype HookEventContext,\n\ttype HookFactory,\n\tHookRunner,\n\ttype HookUIContext,\n\tloadHooks,\n} from \"./hooks/index.js\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACN,YAAY,GAOZ,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAA6C,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAE5F,OAAO,EAMN,0BAA0B,EAG1B,eAAe,GAEf,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAMN,UAAU,EAEV,SAAS,GACT,MAAM,kBAAkB,CAAC","sourcesContent":["/**\n * Core modules shared between all run modes.\n */\n\nexport {\n\tAgentSession,\n\ttype AgentSessionConfig,\n\ttype AgentSessionEvent,\n\ttype AgentSessionEventListener,\n\ttype ModelCycleResult,\n\ttype PromptOptions,\n\ttype SessionStats,\n} from \"./agent-session.js\";\nexport { type BashExecutorOptions, type BashResult, executeBash } from \"./bash-executor.js\";\nexport type { CompactionResult } from \"./compaction/index.js\";\nexport {\n\ttype CustomTool,\n\ttype CustomToolAPI,\n\ttype CustomToolFactory,\n\ttype CustomToolsLoadResult,\n\ttype CustomToolUIContext,\n\tdiscoverAndLoadCustomTools,\n\ttype ExecResult,\n\ttype LoadedCustomTool,\n\tloadCustomTools,\n\ttype RenderResultOptions,\n} from \"./custom-tools/index.js\";\nexport {\n\ttype HookAPI,\n\ttype HookContext,\n\ttype HookError,\n\ttype HookEvent,\n\ttype HookFactory,\n\tHookRunner,\n\ttype HookUIContext,\n\tloadHooks,\n} from \"./hooks/index.js\";\n"]}
@@ -1,11 +1,15 @@
1
1
  /**
2
2
  * Custom message types and transformers for the coding agent.
3
3
  *
4
- * Extends the base AppMessage type with coding-agent specific message types,
4
+ * Extends the base AgentMessage type with coding-agent specific message types,
5
5
  * and provides a transformer to convert them to LLM-compatible messages.
6
6
  */
7
- import type { AppMessage } from "@mariozechner/pi-agent-core";
8
- import type { Message } from "@mariozechner/pi-ai";
7
+ import type { AgentMessage } from "@mariozechner/pi-agent-core";
8
+ import type { ImageContent, Message, TextContent } from "@mariozechner/pi-ai";
9
+ export declare const COMPACTION_SUMMARY_PREFIX = "The conversation history before this point was compacted into the following summary:\n\n<summary>\n";
10
+ export declare const COMPACTION_SUMMARY_SUFFIX = "\n</summary>";
11
+ export declare const BRANCH_SUMMARY_PREFIX = "The following is a summary of a branch that this conversation came back from:\n\n<summary>\n";
12
+ export declare const BRANCH_SUMMARY_SUFFIX = "</summary>";
9
13
  /**
10
14
  * Message type for bash executions via the ! command.
11
15
  */
@@ -13,31 +17,59 @@ export interface BashExecutionMessage {
13
17
  role: "bashExecution";
14
18
  command: string;
15
19
  output: string;
16
- exitCode: number | null;
20
+ exitCode: number | undefined;
17
21
  cancelled: boolean;
18
22
  truncated: boolean;
19
23
  fullOutputPath?: string;
20
24
  timestamp: number;
21
25
  }
26
+ /**
27
+ * Message type for hook-injected messages via sendMessage().
28
+ * These are custom messages that hooks can inject into the conversation.
29
+ */
30
+ export interface HookMessage<T = unknown> {
31
+ role: "hookMessage";
32
+ customType: string;
33
+ content: string | (TextContent | ImageContent)[];
34
+ display: boolean;
35
+ details?: T;
36
+ timestamp: number;
37
+ }
38
+ export interface BranchSummaryMessage {
39
+ role: "branchSummary";
40
+ summary: string;
41
+ fromId: string;
42
+ timestamp: number;
43
+ }
44
+ export interface CompactionSummaryMessage {
45
+ role: "compactionSummary";
46
+ summary: string;
47
+ tokensBefore: number;
48
+ timestamp: number;
49
+ }
22
50
  declare module "@mariozechner/pi-agent-core" {
23
- interface CustomMessages {
51
+ interface CustomAgentMessages {
24
52
  bashExecution: BashExecutionMessage;
53
+ hookMessage: HookMessage;
54
+ branchSummary: BranchSummaryMessage;
55
+ compactionSummary: CompactionSummaryMessage;
25
56
  }
26
57
  }
27
- /**
28
- * Type guard for BashExecutionMessage.
29
- */
30
- export declare function isBashExecutionMessage(msg: AppMessage | Message): msg is BashExecutionMessage;
31
58
  /**
32
59
  * Convert a BashExecutionMessage to user message text for LLM context.
33
60
  */
34
61
  export declare function bashExecutionToText(msg: BashExecutionMessage): string;
62
+ export declare function createBranchSummaryMessage(summary: string, fromId: string, timestamp: string): BranchSummaryMessage;
63
+ export declare function createCompactionSummaryMessage(summary: string, tokensBefore: number, timestamp: string): CompactionSummaryMessage;
64
+ /** Convert CustomMessageEntry to AgentMessage format */
65
+ export declare function createHookMessage(customType: string, content: string | (TextContent | ImageContent)[], display: boolean, details: unknown | undefined, timestamp: string): HookMessage;
35
66
  /**
36
- * Transform AppMessages (including custom types) to LLM-compatible Messages.
67
+ * Transform AgentMessages (including custom types) to LLM-compatible Messages.
37
68
  *
38
69
  * This is used by:
39
- * - Agent's messageTransformer option (for prompt calls)
70
+ * - Agent's transormToLlm option (for prompt calls and queued messages)
40
71
  * - Compaction's generateSummary (for summarization)
72
+ * - Custom hooks and tools
41
73
  */
42
- export declare function messageTransformer(messages: AppMessage[]): Message[];
74
+ export declare function convertToLlm(messages: AgentMessage[]): Message[];
43
75
  //# sourceMappingURL=messages.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../src/core/messages.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAMnD;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACpC,IAAI,EAAE,eAAe,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,SAAS,EAAE,OAAO,CAAC;IACnB,SAAS,EAAE,OAAO,CAAC;IACnB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,SAAS,EAAE,MAAM,CAAC;CAClB;AAGD,OAAO,QAAQ,6BAA6B,CAAC,CAAC;IAC7C,UAAU,cAAc;QACvB,aAAa,EAAE,oBAAoB,CAAC;KACpC;CACD;AAMD;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,UAAU,GAAG,OAAO,GAAG,GAAG,IAAI,oBAAoB,CAE7F;AAMD;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,oBAAoB,GAAG,MAAM,CAgBrE;AAMD;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,UAAU,EAAE,GAAG,OAAO,EAAE,CAmBpE","sourcesContent":["/**\n * Custom message types and transformers for the coding agent.\n *\n * Extends the base AppMessage type with coding-agent specific message types,\n * and provides a transformer to convert them to LLM-compatible messages.\n */\n\nimport type { AppMessage } from \"@mariozechner/pi-agent-core\";\nimport type { Message } from \"@mariozechner/pi-ai\";\n\n// ============================================================================\n// Custom Message Types\n// ============================================================================\n\n/**\n * Message type for bash executions via the ! command.\n */\nexport interface BashExecutionMessage {\n\trole: \"bashExecution\";\n\tcommand: string;\n\toutput: string;\n\texitCode: number | null;\n\tcancelled: boolean;\n\ttruncated: boolean;\n\tfullOutputPath?: string;\n\ttimestamp: number;\n}\n\n// Extend CustomMessages via declaration merging\ndeclare module \"@mariozechner/pi-agent-core\" {\n\tinterface CustomMessages {\n\t\tbashExecution: BashExecutionMessage;\n\t}\n}\n\n// ============================================================================\n// Type Guards\n// ============================================================================\n\n/**\n * Type guard for BashExecutionMessage.\n */\nexport function isBashExecutionMessage(msg: AppMessage | Message): msg is BashExecutionMessage {\n\treturn (msg as BashExecutionMessage).role === \"bashExecution\";\n}\n\n// ============================================================================\n// Message Formatting\n// ============================================================================\n\n/**\n * Convert a BashExecutionMessage to user message text for LLM context.\n */\nexport function bashExecutionToText(msg: BashExecutionMessage): string {\n\tlet text = `Ran \\`${msg.command}\\`\\n`;\n\tif (msg.output) {\n\t\ttext += `\\`\\`\\`\\n${msg.output}\\n\\`\\`\\``;\n\t} else {\n\t\ttext += \"(no output)\";\n\t}\n\tif (msg.cancelled) {\n\t\ttext += \"\\n\\n(command cancelled)\";\n\t} else if (msg.exitCode !== null && msg.exitCode !== 0) {\n\t\ttext += `\\n\\nCommand exited with code ${msg.exitCode}`;\n\t}\n\tif (msg.truncated && msg.fullOutputPath) {\n\t\ttext += `\\n\\n[Output truncated. Full output: ${msg.fullOutputPath}]`;\n\t}\n\treturn text;\n}\n\n// ============================================================================\n// Message Transformer\n// ============================================================================\n\n/**\n * Transform AppMessages (including custom types) to LLM-compatible Messages.\n *\n * This is used by:\n * - Agent's messageTransformer option (for prompt calls)\n * - Compaction's generateSummary (for summarization)\n */\nexport function messageTransformer(messages: AppMessage[]): Message[] {\n\treturn messages\n\t\t.map((m): Message | null => {\n\t\t\tif (isBashExecutionMessage(m)) {\n\t\t\t\t// Convert bash execution to user message\n\t\t\t\treturn {\n\t\t\t\t\trole: \"user\",\n\t\t\t\t\tcontent: [{ type: \"text\", text: bashExecutionToText(m) }],\n\t\t\t\t\ttimestamp: m.timestamp,\n\t\t\t\t};\n\t\t\t}\n\t\t\t// Pass through standard LLM roles\n\t\t\tif (m.role === \"user\" || m.role === \"assistant\" || m.role === \"toolResult\") {\n\t\t\t\treturn m as Message;\n\t\t\t}\n\t\t\t// Filter out unknown message types\n\t\t\treturn null;\n\t\t})\n\t\t.filter((m): m is Message => m !== null);\n}\n"]}
1
+ {"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../src/core/messages.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAE9E,eAAO,MAAM,yBAAyB,wGAGrC,CAAC;AAEF,eAAO,MAAM,yBAAyB,iBAC3B,CAAC;AAEZ,eAAO,MAAM,qBAAqB,iGAGjC,CAAC;AAEF,eAAO,MAAM,qBAAqB,eAAe,CAAC;AAElD;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACpC,IAAI,EAAE,eAAe,CAAC;IACtB,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AED,wBAAgB,8BAA8B,CAC7C,OAAO,EAAE,MAAM,EACf,YAAY,EAAE,MAAM,EACpB,SAAS,EAAE,MAAM,GACf,wBAAwB,CAO1B;AAED,wDAAwD;AACxD,wBAAgB,iBAAiB,CAChC,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,MAAM,GAAG,CAAC,WAAW,GAAG,YAAY,CAAC,EAAE,EAChD,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,OAAO,GAAG,SAAS,EAC5B,SAAS,EAAE,MAAM,GACf,WAAW,CASb;AAED;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,QAAQ,EAAE,YAAY,EAAE,GAAG,OAAO,EAAE,CA2ChE","sourcesContent":["/**\n * Custom message types and transformers for the coding agent.\n *\n * Extends the base AgentMessage type with coding-agent specific message types,\n * and provides a transformer to convert them to LLM-compatible messages.\n */\n\nimport type { AgentMessage } from \"@mariozechner/pi-agent-core\";\nimport type { ImageContent, Message, TextContent } from \"@mariozechner/pi-ai\";\n\nexport const COMPACTION_SUMMARY_PREFIX = `The conversation history before this point was compacted into the following summary:\n\n<summary>\n`;\n\nexport const COMPACTION_SUMMARY_SUFFIX = `\n</summary>`;\n\nexport const BRANCH_SUMMARY_PREFIX = `The following is a summary of a branch that this conversation came back from:\n\n<summary>\n`;\n\nexport const BRANCH_SUMMARY_SUFFIX = `</summary>`;\n\n/**\n * Message type for bash executions via the ! command.\n */\nexport interface BashExecutionMessage {\n\trole: \"bashExecution\";\n\tcommand: string;\n\toutput: string;\n\texitCode: number | undefined;\n\tcancelled: boolean;\n\ttruncated: boolean;\n\tfullOutputPath?: string;\n\ttimestamp: number;\n}\n\n/**\n * Message type for hook-injected messages via sendMessage().\n * These are custom messages that hooks can inject into the conversation.\n */\nexport interface HookMessage<T = unknown> {\n\trole: \"hookMessage\";\n\tcustomType: string;\n\tcontent: string | (TextContent | ImageContent)[];\n\tdisplay: boolean;\n\tdetails?: T;\n\ttimestamp: number;\n}\n\nexport interface BranchSummaryMessage {\n\trole: \"branchSummary\";\n\tsummary: string;\n\tfromId: string;\n\ttimestamp: number;\n}\n\nexport interface CompactionSummaryMessage {\n\trole: \"compactionSummary\";\n\tsummary: string;\n\ttokensBefore: number;\n\ttimestamp: number;\n}\n\n// Extend CustomAgentMessages via declaration merging\ndeclare module \"@mariozechner/pi-agent-core\" {\n\tinterface CustomAgentMessages {\n\t\tbashExecution: BashExecutionMessage;\n\t\thookMessage: HookMessage;\n\t\tbranchSummary: BranchSummaryMessage;\n\t\tcompactionSummary: CompactionSummaryMessage;\n\t}\n}\n\n/**\n * Convert a BashExecutionMessage to user message text for LLM context.\n */\nexport function bashExecutionToText(msg: BashExecutionMessage): string {\n\tlet text = `Ran \\`${msg.command}\\`\\n`;\n\tif (msg.output) {\n\t\ttext += `\\`\\`\\`\\n${msg.output}\\n\\`\\`\\``;\n\t} else {\n\t\ttext += \"(no output)\";\n\t}\n\tif (msg.cancelled) {\n\t\ttext += \"\\n\\n(command cancelled)\";\n\t} else if (msg.exitCode !== null && msg.exitCode !== undefined && msg.exitCode !== 0) {\n\t\ttext += `\\n\\nCommand exited with code ${msg.exitCode}`;\n\t}\n\tif (msg.truncated && msg.fullOutputPath) {\n\t\ttext += `\\n\\n[Output truncated. Full output: ${msg.fullOutputPath}]`;\n\t}\n\treturn text;\n}\n\nexport function createBranchSummaryMessage(summary: string, fromId: string, timestamp: string): BranchSummaryMessage {\n\treturn {\n\t\trole: \"branchSummary\",\n\t\tsummary,\n\t\tfromId,\n\t\ttimestamp: new Date(timestamp).getTime(),\n\t};\n}\n\nexport function createCompactionSummaryMessage(\n\tsummary: string,\n\ttokensBefore: number,\n\ttimestamp: string,\n): CompactionSummaryMessage {\n\treturn {\n\t\trole: \"compactionSummary\",\n\t\tsummary: summary,\n\t\ttokensBefore,\n\t\ttimestamp: new Date(timestamp).getTime(),\n\t};\n}\n\n/** Convert CustomMessageEntry to AgentMessage format */\nexport function createHookMessage(\n\tcustomType: string,\n\tcontent: string | (TextContent | ImageContent)[],\n\tdisplay: boolean,\n\tdetails: unknown | undefined,\n\ttimestamp: string,\n): HookMessage {\n\treturn {\n\t\trole: \"hookMessage\",\n\t\tcustomType,\n\t\tcontent,\n\t\tdisplay,\n\t\tdetails,\n\t\ttimestamp: new Date(timestamp).getTime(),\n\t};\n}\n\n/**\n * Transform AgentMessages (including custom types) to LLM-compatible Messages.\n *\n * This is used by:\n * - Agent's transormToLlm option (for prompt calls and queued messages)\n * - Compaction's generateSummary (for summarization)\n * - Custom hooks and tools\n */\nexport function convertToLlm(messages: AgentMessage[]): Message[] {\n\treturn messages\n\t\t.map((m): Message | undefined => {\n\t\t\tswitch (m.role) {\n\t\t\t\tcase \"bashExecution\":\n\t\t\t\t\treturn {\n\t\t\t\t\t\trole: \"user\",\n\t\t\t\t\t\tcontent: [{ type: \"text\", text: bashExecutionToText(m) }],\n\t\t\t\t\t\ttimestamp: m.timestamp,\n\t\t\t\t\t};\n\t\t\t\tcase \"hookMessage\": {\n\t\t\t\t\tconst content = typeof m.content === \"string\" ? [{ type: \"text\" as const, text: m.content }] : m.content;\n\t\t\t\t\treturn {\n\t\t\t\t\t\trole: \"user\",\n\t\t\t\t\t\tcontent,\n\t\t\t\t\t\ttimestamp: m.timestamp,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\tcase \"branchSummary\":\n\t\t\t\t\treturn {\n\t\t\t\t\t\trole: \"user\",\n\t\t\t\t\t\tcontent: [{ type: \"text\" as const, text: BRANCH_SUMMARY_PREFIX + m.summary + BRANCH_SUMMARY_SUFFIX }],\n\t\t\t\t\t\ttimestamp: m.timestamp,\n\t\t\t\t\t};\n\t\t\t\tcase \"compactionSummary\":\n\t\t\t\t\treturn {\n\t\t\t\t\t\trole: \"user\",\n\t\t\t\t\t\tcontent: [\n\t\t\t\t\t\t\t{ type: \"text\" as const, text: COMPACTION_SUMMARY_PREFIX + m.summary + COMPACTION_SUMMARY_SUFFIX },\n\t\t\t\t\t\t],\n\t\t\t\t\t\ttimestamp: m.timestamp,\n\t\t\t\t\t};\n\t\t\t\tcase \"user\":\n\t\t\t\tcase \"assistant\":\n\t\t\t\tcase \"toolResult\":\n\t\t\t\t\treturn m;\n\t\t\t\tdefault:\n\t\t\t\t\t// biome-ignore lint/correctness/noSwitchDeclarations: fine\n\t\t\t\t\tconst _exhaustiveCheck: never = m;\n\t\t\t\t\treturn undefined;\n\t\t\t}\n\t\t})\n\t\t.filter((m) => m !== undefined);\n}\n"]}
@@ -1,21 +1,20 @@
1
1
  /**
2
2
  * Custom message types and transformers for the coding agent.
3
3
  *
4
- * Extends the base AppMessage type with coding-agent specific message types,
4
+ * Extends the base AgentMessage type with coding-agent specific message types,
5
5
  * and provides a transformer to convert them to LLM-compatible messages.
6
6
  */
7
- // ============================================================================
8
- // Type Guards
9
- // ============================================================================
10
- /**
11
- * Type guard for BashExecutionMessage.
12
- */
13
- export function isBashExecutionMessage(msg) {
14
- return msg.role === "bashExecution";
15
- }
16
- // ============================================================================
17
- // Message Formatting
18
- // ============================================================================
7
+ export const COMPACTION_SUMMARY_PREFIX = `The conversation history before this point was compacted into the following summary:
8
+
9
+ <summary>
10
+ `;
11
+ export const COMPACTION_SUMMARY_SUFFIX = `
12
+ </summary>`;
13
+ export const BRANCH_SUMMARY_PREFIX = `The following is a summary of a branch that this conversation came back from:
14
+
15
+ <summary>
16
+ `;
17
+ export const BRANCH_SUMMARY_SUFFIX = `</summary>`;
19
18
  /**
20
19
  * Convert a BashExecutionMessage to user message text for LLM context.
21
20
  */
@@ -30,7 +29,7 @@ export function bashExecutionToText(msg) {
30
29
  if (msg.cancelled) {
31
30
  text += "\n\n(command cancelled)";
32
31
  }
33
- else if (msg.exitCode !== null && msg.exitCode !== 0) {
32
+ else if (msg.exitCode !== null && msg.exitCode !== undefined && msg.exitCode !== 0) {
34
33
  text += `\n\nCommand exited with code ${msg.exitCode}`;
35
34
  }
36
35
  if (msg.truncated && msg.fullOutputPath) {
@@ -38,34 +37,83 @@ export function bashExecutionToText(msg) {
38
37
  }
39
38
  return text;
40
39
  }
41
- // ============================================================================
42
- // Message Transformer
43
- // ============================================================================
40
+ export function createBranchSummaryMessage(summary, fromId, timestamp) {
41
+ return {
42
+ role: "branchSummary",
43
+ summary,
44
+ fromId,
45
+ timestamp: new Date(timestamp).getTime(),
46
+ };
47
+ }
48
+ export function createCompactionSummaryMessage(summary, tokensBefore, timestamp) {
49
+ return {
50
+ role: "compactionSummary",
51
+ summary: summary,
52
+ tokensBefore,
53
+ timestamp: new Date(timestamp).getTime(),
54
+ };
55
+ }
56
+ /** Convert CustomMessageEntry to AgentMessage format */
57
+ export function createHookMessage(customType, content, display, details, timestamp) {
58
+ return {
59
+ role: "hookMessage",
60
+ customType,
61
+ content,
62
+ display,
63
+ details,
64
+ timestamp: new Date(timestamp).getTime(),
65
+ };
66
+ }
44
67
  /**
45
- * Transform AppMessages (including custom types) to LLM-compatible Messages.
68
+ * Transform AgentMessages (including custom types) to LLM-compatible Messages.
46
69
  *
47
70
  * This is used by:
48
- * - Agent's messageTransformer option (for prompt calls)
71
+ * - Agent's transormToLlm option (for prompt calls and queued messages)
49
72
  * - Compaction's generateSummary (for summarization)
73
+ * - Custom hooks and tools
50
74
  */
51
- export function messageTransformer(messages) {
75
+ export function convertToLlm(messages) {
52
76
  return messages
53
77
  .map((m) => {
54
- if (isBashExecutionMessage(m)) {
55
- // Convert bash execution to user message
56
- return {
57
- role: "user",
58
- content: [{ type: "text", text: bashExecutionToText(m) }],
59
- timestamp: m.timestamp,
60
- };
61
- }
62
- // Pass through standard LLM roles
63
- if (m.role === "user" || m.role === "assistant" || m.role === "toolResult") {
64
- return m;
78
+ switch (m.role) {
79
+ case "bashExecution":
80
+ return {
81
+ role: "user",
82
+ content: [{ type: "text", text: bashExecutionToText(m) }],
83
+ timestamp: m.timestamp,
84
+ };
85
+ case "hookMessage": {
86
+ const content = typeof m.content === "string" ? [{ type: "text", text: m.content }] : m.content;
87
+ return {
88
+ role: "user",
89
+ content,
90
+ timestamp: m.timestamp,
91
+ };
92
+ }
93
+ case "branchSummary":
94
+ return {
95
+ role: "user",
96
+ content: [{ type: "text", text: BRANCH_SUMMARY_PREFIX + m.summary + BRANCH_SUMMARY_SUFFIX }],
97
+ timestamp: m.timestamp,
98
+ };
99
+ case "compactionSummary":
100
+ return {
101
+ role: "user",
102
+ content: [
103
+ { type: "text", text: COMPACTION_SUMMARY_PREFIX + m.summary + COMPACTION_SUMMARY_SUFFIX },
104
+ ],
105
+ timestamp: m.timestamp,
106
+ };
107
+ case "user":
108
+ case "assistant":
109
+ case "toolResult":
110
+ return m;
111
+ default:
112
+ // biome-ignore lint/correctness/noSwitchDeclarations: fine
113
+ const _exhaustiveCheck = m;
114
+ return undefined;
65
115
  }
66
- // Filter out unknown message types
67
- return null;
68
116
  })
69
- .filter((m) => m !== null);
117
+ .filter((m) => m !== undefined);
70
118
  }
71
119
  //# sourceMappingURL=messages.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"messages.js","sourceRoot":"","sources":["../../src/core/messages.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AA8BH,+EAA+E;AAC/E,cAAc;AACd,+EAA+E;AAE/E;;GAEG;AACH,MAAM,UAAU,sBAAsB,CAAC,GAAyB,EAA+B;IAC9F,OAAQ,GAA4B,CAAC,IAAI,KAAK,eAAe,CAAC;AAAA,CAC9D;AAED,+EAA+E;AAC/E,qBAAqB;AACrB,+EAA+E;AAE/E;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAAC,GAAyB,EAAU;IACtE,IAAI,IAAI,GAAG,SAAS,GAAG,CAAC,OAAO,MAAM,CAAC;IACtC,IAAI,GAAG,CAAC,MAAM,EAAE,CAAC;QAChB,IAAI,IAAI,WAAW,GAAG,CAAC,MAAM,UAAU,CAAC;IACzC,CAAC;SAAM,CAAC;QACP,IAAI,IAAI,aAAa,CAAC;IACvB,CAAC;IACD,IAAI,GAAG,CAAC,SAAS,EAAE,CAAC;QACnB,IAAI,IAAI,yBAAyB,CAAC;IACnC,CAAC;SAAM,IAAI,GAAG,CAAC,QAAQ,KAAK,IAAI,IAAI,GAAG,CAAC,QAAQ,KAAK,CAAC,EAAE,CAAC;QACxD,IAAI,IAAI,gCAAgC,GAAG,CAAC,QAAQ,EAAE,CAAC;IACxD,CAAC;IACD,IAAI,GAAG,CAAC,SAAS,IAAI,GAAG,CAAC,cAAc,EAAE,CAAC;QACzC,IAAI,IAAI,uCAAuC,GAAG,CAAC,cAAc,GAAG,CAAC;IACtE,CAAC;IACD,OAAO,IAAI,CAAC;AAAA,CACZ;AAED,+EAA+E;AAC/E,sBAAsB;AACtB,+EAA+E;AAE/E;;;;;;GAMG;AACH,MAAM,UAAU,kBAAkB,CAAC,QAAsB,EAAa;IACrE,OAAO,QAAQ;SACb,GAAG,CAAC,CAAC,CAAC,EAAkB,EAAE,CAAC;QAC3B,IAAI,sBAAsB,CAAC,CAAC,CAAC,EAAE,CAAC;YAC/B,yCAAyC;YACzC,OAAO;gBACN,IAAI,EAAE,MAAM;gBACZ,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,mBAAmB,CAAC,CAAC,CAAC,EAAE,CAAC;gBACzD,SAAS,EAAE,CAAC,CAAC,SAAS;aACtB,CAAC;QACH,CAAC;QACD,kCAAkC;QAClC,IAAI,CAAC,CAAC,IAAI,KAAK,MAAM,IAAI,CAAC,CAAC,IAAI,KAAK,WAAW,IAAI,CAAC,CAAC,IAAI,KAAK,YAAY,EAAE,CAAC;YAC5E,OAAO,CAAY,CAAC;QACrB,CAAC;QACD,mCAAmC;QACnC,OAAO,IAAI,CAAC;IAAA,CACZ,CAAC;SACD,MAAM,CAAC,CAAC,CAAC,EAAgB,EAAE,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC;AAAA,CAC1C","sourcesContent":["/**\n * Custom message types and transformers for the coding agent.\n *\n * Extends the base AppMessage type with coding-agent specific message types,\n * and provides a transformer to convert them to LLM-compatible messages.\n */\n\nimport type { AppMessage } from \"@mariozechner/pi-agent-core\";\nimport type { Message } from \"@mariozechner/pi-ai\";\n\n// ============================================================================\n// Custom Message Types\n// ============================================================================\n\n/**\n * Message type for bash executions via the ! command.\n */\nexport interface BashExecutionMessage {\n\trole: \"bashExecution\";\n\tcommand: string;\n\toutput: string;\n\texitCode: number | null;\n\tcancelled: boolean;\n\ttruncated: boolean;\n\tfullOutputPath?: string;\n\ttimestamp: number;\n}\n\n// Extend CustomMessages via declaration merging\ndeclare module \"@mariozechner/pi-agent-core\" {\n\tinterface CustomMessages {\n\t\tbashExecution: BashExecutionMessage;\n\t}\n}\n\n// ============================================================================\n// Type Guards\n// ============================================================================\n\n/**\n * Type guard for BashExecutionMessage.\n */\nexport function isBashExecutionMessage(msg: AppMessage | Message): msg is BashExecutionMessage {\n\treturn (msg as BashExecutionMessage).role === \"bashExecution\";\n}\n\n// ============================================================================\n// Message Formatting\n// ============================================================================\n\n/**\n * Convert a BashExecutionMessage to user message text for LLM context.\n */\nexport function bashExecutionToText(msg: BashExecutionMessage): string {\n\tlet text = `Ran \\`${msg.command}\\`\\n`;\n\tif (msg.output) {\n\t\ttext += `\\`\\`\\`\\n${msg.output}\\n\\`\\`\\``;\n\t} else {\n\t\ttext += \"(no output)\";\n\t}\n\tif (msg.cancelled) {\n\t\ttext += \"\\n\\n(command cancelled)\";\n\t} else if (msg.exitCode !== null && msg.exitCode !== 0) {\n\t\ttext += `\\n\\nCommand exited with code ${msg.exitCode}`;\n\t}\n\tif (msg.truncated && msg.fullOutputPath) {\n\t\ttext += `\\n\\n[Output truncated. Full output: ${msg.fullOutputPath}]`;\n\t}\n\treturn text;\n}\n\n// ============================================================================\n// Message Transformer\n// ============================================================================\n\n/**\n * Transform AppMessages (including custom types) to LLM-compatible Messages.\n *\n * This is used by:\n * - Agent's messageTransformer option (for prompt calls)\n * - Compaction's generateSummary (for summarization)\n */\nexport function messageTransformer(messages: AppMessage[]): Message[] {\n\treturn messages\n\t\t.map((m): Message | null => {\n\t\t\tif (isBashExecutionMessage(m)) {\n\t\t\t\t// Convert bash execution to user message\n\t\t\t\treturn {\n\t\t\t\t\trole: \"user\",\n\t\t\t\t\tcontent: [{ type: \"text\", text: bashExecutionToText(m) }],\n\t\t\t\t\ttimestamp: m.timestamp,\n\t\t\t\t};\n\t\t\t}\n\t\t\t// Pass through standard LLM roles\n\t\t\tif (m.role === \"user\" || m.role === \"assistant\" || m.role === \"toolResult\") {\n\t\t\t\treturn m as Message;\n\t\t\t}\n\t\t\t// Filter out unknown message types\n\t\t\treturn null;\n\t\t})\n\t\t.filter((m): m is Message => m !== null);\n}\n"]}
1
+ {"version":3,"file":"messages.js","sourceRoot":"","sources":["../../src/core/messages.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,MAAM,CAAC,MAAM,yBAAyB,GAAG;;;CAGxC,CAAC;AAEF,MAAM,CAAC,MAAM,yBAAyB,GAAG;WAC9B,CAAC;AAEZ,MAAM,CAAC,MAAM,qBAAqB,GAAG;;;CAGpC,CAAC;AAEF,MAAM,CAAC,MAAM,qBAAqB,GAAG,YAAY,CAAC;AAqDlD;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAAC,GAAyB,EAAU;IACtE,IAAI,IAAI,GAAG,SAAS,GAAG,CAAC,OAAO,MAAM,CAAC;IACtC,IAAI,GAAG,CAAC,MAAM,EAAE,CAAC;QAChB,IAAI,IAAI,WAAW,GAAG,CAAC,MAAM,UAAU,CAAC;IACzC,CAAC;SAAM,CAAC;QACP,IAAI,IAAI,aAAa,CAAC;IACvB,CAAC;IACD,IAAI,GAAG,CAAC,SAAS,EAAE,CAAC;QACnB,IAAI,IAAI,yBAAyB,CAAC;IACnC,CAAC;SAAM,IAAI,GAAG,CAAC,QAAQ,KAAK,IAAI,IAAI,GAAG,CAAC,QAAQ,KAAK,SAAS,IAAI,GAAG,CAAC,QAAQ,KAAK,CAAC,EAAE,CAAC;QACtF,IAAI,IAAI,gCAAgC,GAAG,CAAC,QAAQ,EAAE,CAAC;IACxD,CAA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zD,SAAS,EAAE,CAAC,CAAC,SAAS;iBACtB,CAAC;YACH,KAAK,aAAa,EAAE,CAAC;gBACpB,MAAM,OAAO,GAAG,OAAO,CAAC,CAAC,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;gBACzG,OAAO;oBACN,IAAI,EAAE,MAAM;oBACZ,OAAO;oBACP,SAAS,EAAE,CAAC,CAAC,SAAS;iBACtB,CAAC;YACH,CAAC;YACD,KAAK,eAAe;gBACnB,OAAO;oBACN,IAAI,EAAE,MAAM;oBACZ,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,qBAAqB,GAAG,CAAC,CAAC,OAAO,GAAG,qBAAqB,EAAE,CAAC;oBACrG,SAAS,EAAE,CAAC,CAAC,SAAS;iBACtB,CAAC;YACH,KAAK,mBAAmB;gBACvB,OAAO;oBACN,IAAI,EAAE,MAAM;oBACZ,OAAO,EAAE;wBACR,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,yBAAyB,GAAG,CAAC,CAAC,OAAO,GAAG,yBAAyB,EAAE;qBAClG;oBACD,SAAS,EAAE,CAAC,CAAC,SAAS;iBACtB,CAAC;YACH,KAAK,MAAM,CAAC;YACZ,KAAK,WAAW,CAAC;YACjB,KAAK,YAAY;gBAChB,OAAO,CAAC,CAAC;YACV;gBACC,2DAA2D;gBAC3D,MAAM,gBAAgB,GAAU,CAAC,CAAC;gBAClC,OAAO,SAAS,CAAC;QACnB,CAAC;IAAA,CACD,CAAC;SACD,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC;AAAA,CACjC","sourcesContent":["/**\n * Custom message types and transformers for the coding agent.\n *\n * Extends the base AgentMessage type with coding-agent specific message types,\n * and provides a transformer to convert them to LLM-compatible messages.\n */\n\nimport type { AgentMessage } from \"@mariozechner/pi-agent-core\";\nimport type { ImageContent, Message, TextContent } from \"@mariozechner/pi-ai\";\n\nexport const COMPACTION_SUMMARY_PREFIX = `The conversation history before this point was compacted into the following summary:\n\n<summary>\n`;\n\nexport const COMPACTION_SUMMARY_SUFFIX = `\n</summary>`;\n\nexport const BRANCH_SUMMARY_PREFIX = `The following is a summary of a branch that this conversation came back from:\n\n<summary>\n`;\n\nexport const BRANCH_SUMMARY_SUFFIX = `</summary>`;\n\n/**\n * Message type for bash executions via the ! command.\n */\nexport interface BashExecutionMessage {\n\trole: \"bashExecution\";\n\tcommand: string;\n\toutput: string;\n\texitCode: number | undefined;\n\tcancelled: boolean;\n\ttruncated: boolean;\n\tfullOutputPath?: string;\n\ttimestamp: number;\n}\n\n/**\n * Message type for hook-injected messages via sendMessage().\n * These are custom messages that hooks can inject into the conversation.\n */\nexport interface HookMessage<T = unknown> {\n\trole: \"hookMessage\";\n\tcustomType: string;\n\tcontent: string | (TextContent | ImageContent)[];\n\tdisplay: boolean;\n\tdetails?: T;\n\ttimestamp: number;\n}\n\nexport interface BranchSummaryMessage {\n\trole: \"branchSummary\";\n\tsummary: string;\n\tfromId: string;\n\ttimestamp: number;\n}\n\nexport interface CompactionSummaryMessage {\n\trole: \"compactionSummary\";\n\tsummary: string;\n\ttokensBefore: number;\n\ttimestamp: number;\n}\n\n// Extend CustomAgentMessages via declaration merging\ndeclare module \"@mariozechner/pi-agent-core\" {\n\tinterface CustomAgentMessages {\n\t\tbashExecution: BashExecutionMessage;\n\t\thookMessage: HookMessage;\n\t\tbranchSummary: BranchSummaryMessage;\n\t\tcompactionSummary: CompactionSummaryMessage;\n\t}\n}\n\n/**\n * Convert a BashExecutionMessage to user message text for LLM context.\n */\nexport function bashExecutionToText(msg: BashExecutionMessage): string {\n\tlet text = `Ran \\`${msg.command}\\`\\n`;\n\tif (msg.output) {\n\t\ttext += `\\`\\`\\`\\n${msg.output}\\n\\`\\`\\``;\n\t} else {\n\t\ttext += \"(no output)\";\n\t}\n\tif (msg.cancelled) {\n\t\ttext += \"\\n\\n(command cancelled)\";\n\t} else if (msg.exitCode !== null && msg.exitCode !== undefined && msg.exitCode !== 0) {\n\t\ttext += `\\n\\nCommand exited with code ${msg.exitCode}`;\n\t}\n\tif (msg.truncated && msg.fullOutputPath) {\n\t\ttext += `\\n\\n[Output truncated. Full output: ${msg.fullOutputPath}]`;\n\t}\n\treturn text;\n}\n\nexport function createBranchSummaryMessage(summary: string, fromId: string, timestamp: string): BranchSummaryMessage {\n\treturn {\n\t\trole: \"branchSummary\",\n\t\tsummary,\n\t\tfromId,\n\t\ttimestamp: new Date(timestamp).getTime(),\n\t};\n}\n\nexport function createCompactionSummaryMessage(\n\tsummary: string,\n\ttokensBefore: number,\n\ttimestamp: string,\n): CompactionSummaryMessage {\n\treturn {\n\t\trole: \"compactionSummary\",\n\t\tsummary: summary,\n\t\ttokensBefore,\n\t\ttimestamp: new Date(timestamp).getTime(),\n\t};\n}\n\n/** Convert CustomMessageEntry to AgentMessage format */\nexport function createHookMessage(\n\tcustomType: string,\n\tcontent: string | (TextContent | ImageContent)[],\n\tdisplay: boolean,\n\tdetails: unknown | undefined,\n\ttimestamp: string,\n): HookMessage {\n\treturn {\n\t\trole: \"hookMessage\",\n\t\tcustomType,\n\t\tcontent,\n\t\tdisplay,\n\t\tdetails,\n\t\ttimestamp: new Date(timestamp).getTime(),\n\t};\n}\n\n/**\n * Transform AgentMessages (including custom types) to LLM-compatible Messages.\n *\n * This is used by:\n * - Agent's transormToLlm option (for prompt calls and queued messages)\n * - Compaction's generateSummary (for summarization)\n * - Custom hooks and tools\n */\nexport function convertToLlm(messages: AgentMessage[]): Message[] {\n\treturn messages\n\t\t.map((m): Message | undefined => {\n\t\t\tswitch (m.role) {\n\t\t\t\tcase \"bashExecution\":\n\t\t\t\t\treturn {\n\t\t\t\t\t\trole: \"user\",\n\t\t\t\t\t\tcontent: [{ type: \"text\", text: bashExecutionToText(m) }],\n\t\t\t\t\t\ttimestamp: m.timestamp,\n\t\t\t\t\t};\n\t\t\t\tcase \"hookMessage\": {\n\t\t\t\t\tconst content = typeof m.content === \"string\" ? [{ type: \"text\" as const, text: m.content }] : m.content;\n\t\t\t\t\treturn {\n\t\t\t\t\t\trole: \"user\",\n\t\t\t\t\t\tcontent,\n\t\t\t\t\t\ttimestamp: m.timestamp,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\tcase \"branchSummary\":\n\t\t\t\t\treturn {\n\t\t\t\t\t\trole: \"user\",\n\t\t\t\t\t\tcontent: [{ type: \"text\" as const, text: BRANCH_SUMMARY_PREFIX + m.summary + BRANCH_SUMMARY_SUFFIX }],\n\t\t\t\t\t\ttimestamp: m.timestamp,\n\t\t\t\t\t};\n\t\t\t\tcase \"compactionSummary\":\n\t\t\t\t\treturn {\n\t\t\t\t\t\trole: \"user\",\n\t\t\t\t\t\tcontent: [\n\t\t\t\t\t\t\t{ type: \"text\" as const, text: COMPACTION_SUMMARY_PREFIX + m.summary + COMPACTION_SUMMARY_SUFFIX },\n\t\t\t\t\t\t],\n\t\t\t\t\t\ttimestamp: m.timestamp,\n\t\t\t\t\t};\n\t\t\t\tcase \"user\":\n\t\t\t\tcase \"assistant\":\n\t\t\t\tcase \"toolResult\":\n\t\t\t\t\treturn m;\n\t\t\t\tdefault:\n\t\t\t\t\t// biome-ignore lint/correctness/noSwitchDeclarations: fine\n\t\t\t\t\tconst _exhaustiveCheck: never = m;\n\t\t\t\t\treturn undefined;\n\t\t\t}\n\t\t})\n\t\t.filter((m) => m !== undefined);\n}\n"]}