@greppleai/grip 0.0.0-stage → 0.0.1

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 (1057) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/README.md +725 -2
  3. package/dist/bun/cli.d.ts +3 -0
  4. package/dist/bun/cli.d.ts.map +1 -0
  5. package/dist/bun/cli.js +11 -0
  6. package/dist/bun/cli.js.map +1 -0
  7. package/dist/bun/register-bedrock.d.ts +2 -0
  8. package/dist/bun/register-bedrock.d.ts.map +1 -0
  9. package/dist/bun/register-bedrock.js +4 -0
  10. package/dist/bun/register-bedrock.js.map +1 -0
  11. package/dist/bun/restore-sandbox-env.d.ts +13 -0
  12. package/dist/bun/restore-sandbox-env.d.ts.map +1 -0
  13. package/dist/bun/restore-sandbox-env.js +32 -0
  14. package/dist/bun/restore-sandbox-env.js.map +1 -0
  15. package/dist/cli/args.d.ts +70 -0
  16. package/dist/cli/args.d.ts.map +1 -0
  17. package/dist/cli/args.js +441 -0
  18. package/dist/cli/args.js.map +1 -0
  19. package/dist/cli/config-selector.d.ts +14 -0
  20. package/dist/cli/config-selector.d.ts.map +1 -0
  21. package/dist/cli/config-selector.js +31 -0
  22. package/dist/cli/config-selector.js.map +1 -0
  23. package/dist/cli/file-processor.d.ts +15 -0
  24. package/dist/cli/file-processor.d.ts.map +1 -0
  25. package/dist/cli/file-processor.js +60 -0
  26. package/dist/cli/file-processor.js.map +1 -0
  27. package/dist/cli/initial-message.d.ts +18 -0
  28. package/dist/cli/initial-message.d.ts.map +1 -0
  29. package/dist/cli/initial-message.js +22 -0
  30. package/dist/cli/initial-message.js.map +1 -0
  31. package/dist/cli/list-models.d.ts +9 -0
  32. package/dist/cli/list-models.d.ts.map +1 -0
  33. package/dist/cli/list-models.js +98 -0
  34. package/dist/cli/list-models.js.map +1 -0
  35. package/dist/cli/session-picker.d.ts +9 -0
  36. package/dist/cli/session-picker.d.ts.map +1 -0
  37. package/dist/cli/session-picker.js +35 -0
  38. package/dist/cli/session-picker.js.map +1 -0
  39. package/dist/cli.d.ts +3 -0
  40. package/dist/cli.d.ts.map +1 -0
  41. package/dist/cli.js +14 -0
  42. package/dist/cli.js.map +1 -0
  43. package/dist/config.d.ts +82 -0
  44. package/dist/config.d.ts.map +1 -0
  45. package/dist/config.js +406 -0
  46. package/dist/config.js.map +1 -0
  47. package/dist/core/agent-session.d.ts +970 -0
  48. package/dist/core/agent-session.d.ts.map +1 -0
  49. package/dist/core/agent-session.js +5176 -0
  50. package/dist/core/agent-session.js.map +1 -0
  51. package/dist/core/auth-guidance.d.ts +5 -0
  52. package/dist/core/auth-guidance.d.ts.map +1 -0
  53. package/dist/core/auth-guidance.js +21 -0
  54. package/dist/core/auth-guidance.js.map +1 -0
  55. package/dist/core/auth-storage.d.ts +150 -0
  56. package/dist/core/auth-storage.d.ts.map +1 -0
  57. package/dist/core/auth-storage.js +557 -0
  58. package/dist/core/auth-storage.js.map +1 -0
  59. package/dist/core/bash-executor.d.ts +26 -0
  60. package/dist/core/bash-executor.d.ts.map +1 -0
  61. package/dist/core/bash-executor.js +99 -0
  62. package/dist/core/bash-executor.js.map +1 -0
  63. package/dist/core/compaction/branch-summarization.d.ts +83 -0
  64. package/dist/core/compaction/branch-summarization.d.ts.map +1 -0
  65. package/dist/core/compaction/branch-summarization.js +220 -0
  66. package/dist/core/compaction/branch-summarization.js.map +1 -0
  67. package/dist/core/compaction/compaction.d.ts +65 -0
  68. package/dist/core/compaction/compaction.d.ts.map +1 -0
  69. package/dist/core/compaction/compaction.js +550 -0
  70. package/dist/core/compaction/compaction.js.map +1 -0
  71. package/dist/core/compaction/compression-detection-ledger.d.ts +34 -0
  72. package/dist/core/compaction/compression-detection-ledger.d.ts.map +1 -0
  73. package/dist/core/compaction/compression-detection-ledger.js +52 -0
  74. package/dist/core/compaction/compression-detection-ledger.js.map +1 -0
  75. package/dist/core/compaction/compression-detector.d.ts +71 -0
  76. package/dist/core/compaction/compression-detector.d.ts.map +1 -0
  77. package/dist/core/compaction/compression-detector.js +407 -0
  78. package/dist/core/compaction/compression-detector.js.map +1 -0
  79. package/dist/core/compaction/compression-economics.d.ts +55 -0
  80. package/dist/core/compaction/compression-economics.d.ts.map +1 -0
  81. package/dist/core/compaction/compression-economics.js +151 -0
  82. package/dist/core/compaction/compression-economics.js.map +1 -0
  83. package/dist/core/compaction/utils.d.ts +28 -0
  84. package/dist/core/compaction/utils.d.ts.map +1 -0
  85. package/dist/core/compaction/utils.js +165 -0
  86. package/dist/core/compaction/utils.js.map +1 -0
  87. package/dist/core/defaults.d.ts +3 -0
  88. package/dist/core/defaults.d.ts.map +1 -0
  89. package/dist/core/defaults.js +2 -0
  90. package/dist/core/defaults.js.map +1 -0
  91. package/dist/core/diagnostics.d.ts +18 -0
  92. package/dist/core/diagnostics.d.ts.map +1 -0
  93. package/dist/core/diagnostics.js +2 -0
  94. package/dist/core/diagnostics.js.map +1 -0
  95. package/dist/core/event-bus.d.ts +9 -0
  96. package/dist/core/event-bus.d.ts.map +1 -0
  97. package/dist/core/event-bus.js +25 -0
  98. package/dist/core/event-bus.js.map +1 -0
  99. package/dist/core/exec.d.ts +29 -0
  100. package/dist/core/exec.d.ts.map +1 -0
  101. package/dist/core/exec.js +75 -0
  102. package/dist/core/exec.js.map +1 -0
  103. package/dist/core/export-html/ansi-to-html.d.ts +22 -0
  104. package/dist/core/export-html/ansi-to-html.d.ts.map +1 -0
  105. package/dist/core/export-html/ansi-to-html.js +245 -0
  106. package/dist/core/export-html/ansi-to-html.js.map +1 -0
  107. package/dist/core/export-html/index.d.ts +21 -0
  108. package/dist/core/export-html/index.d.ts.map +1 -0
  109. package/dist/core/export-html/index.js +230 -0
  110. package/dist/core/export-html/index.js.map +1 -0
  111. package/dist/core/export-html/template.css +1066 -0
  112. package/dist/core/export-html/template.html +55 -0
  113. package/dist/core/export-html/template.js +1864 -0
  114. package/dist/core/export-html/tool-renderer.d.ts +32 -0
  115. package/dist/core/export-html/tool-renderer.d.ts.map +1 -0
  116. package/dist/core/export-html/tool-renderer.js +108 -0
  117. package/dist/core/export-html/tool-renderer.js.map +1 -0
  118. package/dist/core/export-html/vendor/highlight.min.js +1213 -0
  119. package/dist/core/export-html/vendor/marked.min.js +78 -0
  120. package/dist/core/extensions/loader.d.ts +24 -0
  121. package/dist/core/extensions/loader.d.ts.map +1 -0
  122. package/dist/core/extensions/loader.js +613 -0
  123. package/dist/core/extensions/loader.js.map +1 -0
  124. package/dist/core/extensions/runner.d.ts +160 -0
  125. package/dist/core/extensions/runner.d.ts.map +1 -0
  126. package/dist/core/extensions/runner.js +962 -0
  127. package/dist/core/extensions/runner.js.map +1 -0
  128. package/dist/core/extensions/types.d.ts +1311 -0
  129. package/dist/core/extensions/types.d.ts.map +1 -0
  130. package/dist/core/extensions/types.js +51 -0
  131. package/dist/core/extensions/types.js.map +1 -0
  132. package/dist/core/extensions/wrapper.d.ts +20 -0
  133. package/dist/core/extensions/wrapper.d.ts.map +1 -0
  134. package/dist/core/extensions/wrapper.js +22 -0
  135. package/dist/core/extensions/wrapper.js.map +1 -0
  136. package/dist/core/footer-data-provider.d.ts +52 -0
  137. package/dist/core/footer-data-provider.d.ts.map +1 -0
  138. package/dist/core/footer-data-provider.js +318 -0
  139. package/dist/core/footer-data-provider.js.map +1 -0
  140. package/dist/core/grip-agent.d.ts +240 -0
  141. package/dist/core/grip-agent.d.ts.map +1 -0
  142. package/dist/core/grip-agent.js +1243 -0
  143. package/dist/core/grip-agent.js.map +1 -0
  144. package/dist/core/grip-manifest.d.ts +9 -0
  145. package/dist/core/grip-manifest.d.ts.map +1 -0
  146. package/dist/core/grip-manifest.js +25 -0
  147. package/dist/core/grip-manifest.js.map +1 -0
  148. package/dist/core/hooks/aggregate.d.ts +5 -0
  149. package/dist/core/hooks/aggregate.d.ts.map +1 -0
  150. package/dist/core/hooks/aggregate.js +226 -0
  151. package/dist/core/hooks/aggregate.js.map +1 -0
  152. package/dist/core/hooks/config.d.ts +14 -0
  153. package/dist/core/hooks/config.d.ts.map +1 -0
  154. package/dist/core/hooks/config.js +372 -0
  155. package/dist/core/hooks/config.js.map +1 -0
  156. package/dist/core/hooks/executor.d.ts +12 -0
  157. package/dist/core/hooks/executor.d.ts.map +1 -0
  158. package/dist/core/hooks/executor.js +708 -0
  159. package/dist/core/hooks/executor.js.map +1 -0
  160. package/dist/core/hooks/index.d.ts +9 -0
  161. package/dist/core/hooks/index.d.ts.map +1 -0
  162. package/dist/core/hooks/index.js +14 -0
  163. package/dist/core/hooks/index.js.map +1 -0
  164. package/dist/core/hooks/matcher.d.ts +10 -0
  165. package/dist/core/hooks/matcher.d.ts.map +1 -0
  166. package/dist/core/hooks/matcher.js +70 -0
  167. package/dist/core/hooks/matcher.js.map +1 -0
  168. package/dist/core/hooks/trust-store.d.ts +38 -0
  169. package/dist/core/hooks/trust-store.d.ts.map +1 -0
  170. package/dist/core/hooks/trust-store.js +167 -0
  171. package/dist/core/hooks/trust-store.js.map +1 -0
  172. package/dist/core/hooks/types.d.ts +234 -0
  173. package/dist/core/hooks/types.d.ts.map +1 -0
  174. package/dist/core/hooks/types.js +52 -0
  175. package/dist/core/hooks/types.js.map +1 -0
  176. package/dist/core/http-dispatcher.d.ts +21 -0
  177. package/dist/core/http-dispatcher.d.ts.map +1 -0
  178. package/dist/core/http-dispatcher.js +82 -0
  179. package/dist/core/http-dispatcher.js.map +1 -0
  180. package/dist/core/instruction-resource-loader.d.ts +81 -0
  181. package/dist/core/instruction-resource-loader.d.ts.map +1 -0
  182. package/dist/core/instruction-resource-loader.js +574 -0
  183. package/dist/core/instruction-resource-loader.js.map +1 -0
  184. package/dist/core/keybindings.d.ts +399 -0
  185. package/dist/core/keybindings.d.ts.map +1 -0
  186. package/dist/core/keybindings.js +299 -0
  187. package/dist/core/keybindings.js.map +1 -0
  188. package/dist/core/lsp/abort.d.ts +3 -0
  189. package/dist/core/lsp/abort.d.ts.map +1 -0
  190. package/dist/core/lsp/abort.js +28 -0
  191. package/dist/core/lsp/abort.js.map +1 -0
  192. package/dist/core/lsp/client.d.ts +108 -0
  193. package/dist/core/lsp/client.d.ts.map +1 -0
  194. package/dist/core/lsp/client.js +586 -0
  195. package/dist/core/lsp/client.js.map +1 -0
  196. package/dist/core/lsp/config-loader.d.ts +44 -0
  197. package/dist/core/lsp/config-loader.d.ts.map +1 -0
  198. package/dist/core/lsp/config-loader.js +223 -0
  199. package/dist/core/lsp/config-loader.js.map +1 -0
  200. package/dist/core/lsp/config.d.ts +134 -0
  201. package/dist/core/lsp/config.d.ts.map +1 -0
  202. package/dist/core/lsp/config.js +682 -0
  203. package/dist/core/lsp/config.js.map +1 -0
  204. package/dist/core/lsp/diagnostics.d.ts +18 -0
  205. package/dist/core/lsp/diagnostics.d.ts.map +1 -0
  206. package/dist/core/lsp/diagnostics.js +311 -0
  207. package/dist/core/lsp/diagnostics.js.map +1 -0
  208. package/dist/core/lsp/file-sync.d.ts +58 -0
  209. package/dist/core/lsp/file-sync.d.ts.map +1 -0
  210. package/dist/core/lsp/file-sync.js +432 -0
  211. package/dist/core/lsp/file-sync.js.map +1 -0
  212. package/dist/core/lsp/integration.d.ts +62 -0
  213. package/dist/core/lsp/integration.d.ts.map +1 -0
  214. package/dist/core/lsp/integration.js +145 -0
  215. package/dist/core/lsp/integration.js.map +1 -0
  216. package/dist/core/lsp/language-map.d.ts +54 -0
  217. package/dist/core/lsp/language-map.d.ts.map +1 -0
  218. package/dist/core/lsp/language-map.js +300 -0
  219. package/dist/core/lsp/language-map.js.map +1 -0
  220. package/dist/core/lsp/manager.d.ts +120 -0
  221. package/dist/core/lsp/manager.d.ts.map +1 -0
  222. package/dist/core/lsp/manager.js +636 -0
  223. package/dist/core/lsp/manager.js.map +1 -0
  224. package/dist/core/lsp/navigation.d.ts +32 -0
  225. package/dist/core/lsp/navigation.d.ts.map +1 -0
  226. package/dist/core/lsp/navigation.js +327 -0
  227. package/dist/core/lsp/navigation.js.map +1 -0
  228. package/dist/core/lsp/portable-path.d.ts +18 -0
  229. package/dist/core/lsp/portable-path.d.ts.map +1 -0
  230. package/dist/core/lsp/portable-path.js +83 -0
  231. package/dist/core/lsp/portable-path.js.map +1 -0
  232. package/dist/core/lsp/refactor.d.ts +32 -0
  233. package/dist/core/lsp/refactor.d.ts.map +1 -0
  234. package/dist/core/lsp/refactor.js +519 -0
  235. package/dist/core/lsp/refactor.js.map +1 -0
  236. package/dist/core/lsp/transport.d.ts +39 -0
  237. package/dist/core/lsp/transport.d.ts.map +1 -0
  238. package/dist/core/lsp/transport.js +261 -0
  239. package/dist/core/lsp/transport.js.map +1 -0
  240. package/dist/core/messages.d.ts +34 -0
  241. package/dist/core/messages.d.ts.map +1 -0
  242. package/dist/core/messages.js +140 -0
  243. package/dist/core/messages.js.map +1 -0
  244. package/dist/core/model-registry.d.ts +148 -0
  245. package/dist/core/model-registry.d.ts.map +1 -0
  246. package/dist/core/model-registry.js +812 -0
  247. package/dist/core/model-registry.js.map +1 -0
  248. package/dist/core/model-resolver.d.ts +115 -0
  249. package/dist/core/model-resolver.d.ts.map +1 -0
  250. package/dist/core/model-resolver.js +498 -0
  251. package/dist/core/model-resolver.js.map +1 -0
  252. package/dist/core/output-guard.d.ts +7 -0
  253. package/dist/core/output-guard.d.ts.map +1 -0
  254. package/dist/core/output-guard.js +89 -0
  255. package/dist/core/output-guard.js.map +1 -0
  256. package/dist/core/package-manager.d.ts +209 -0
  257. package/dist/core/package-manager.d.ts.map +1 -0
  258. package/dist/core/package-manager.js +2341 -0
  259. package/dist/core/package-manager.js.map +1 -0
  260. package/dist/core/prompt-templates.d.ts +57 -0
  261. package/dist/core/prompt-templates.d.ts.map +1 -0
  262. package/dist/core/prompt-templates.js +353 -0
  263. package/dist/core/prompt-templates.js.map +1 -0
  264. package/dist/core/provider-display-names.d.ts +2 -0
  265. package/dist/core/provider-display-names.d.ts.map +1 -0
  266. package/dist/core/provider-display-names.js +33 -0
  267. package/dist/core/provider-display-names.js.map +1 -0
  268. package/dist/core/remote-workspace-protocol/contract.d.ts +456 -0
  269. package/dist/core/remote-workspace-protocol/contract.d.ts.map +1 -0
  270. package/dist/core/remote-workspace-protocol/contract.js +809 -0
  271. package/dist/core/remote-workspace-protocol/contract.js.map +1 -0
  272. package/dist/core/remote-workspace-protocol/session.d.ts +247 -0
  273. package/dist/core/remote-workspace-protocol/session.d.ts.map +1 -0
  274. package/dist/core/remote-workspace-protocol/session.js +1839 -0
  275. package/dist/core/remote-workspace-protocol/session.js.map +1 -0
  276. package/dist/core/resolve-config-value.d.ts +32 -0
  277. package/dist/core/resolve-config-value.d.ts.map +1 -0
  278. package/dist/core/resolve-config-value.js +257 -0
  279. package/dist/core/resolve-config-value.js.map +1 -0
  280. package/dist/core/resource-loader.d.ts +200 -0
  281. package/dist/core/resource-loader.d.ts.map +1 -0
  282. package/dist/core/resource-loader.js +1209 -0
  283. package/dist/core/resource-loader.js.map +1 -0
  284. package/dist/core/rules.d.ts +40 -0
  285. package/dist/core/rules.d.ts.map +1 -0
  286. package/dist/core/rules.js +57 -0
  287. package/dist/core/rules.js.map +1 -0
  288. package/dist/core/sandbox/command.d.ts +27 -0
  289. package/dist/core/sandbox/command.d.ts.map +1 -0
  290. package/dist/core/sandbox/command.js +124 -0
  291. package/dist/core/sandbox/command.js.map +1 -0
  292. package/dist/core/sandbox/docker.d.ts +169 -0
  293. package/dist/core/sandbox/docker.d.ts.map +1 -0
  294. package/dist/core/sandbox/docker.js +633 -0
  295. package/dist/core/sandbox/docker.js.map +1 -0
  296. package/dist/core/sandbox/lima.d.ts +38 -0
  297. package/dist/core/sandbox/lima.d.ts.map +1 -0
  298. package/dist/core/sandbox/lima.js +324 -0
  299. package/dist/core/sandbox/lima.js.map +1 -0
  300. package/dist/core/session/constants.d.ts +2 -0
  301. package/dist/core/session/constants.d.ts.map +1 -0
  302. package/dist/core/session/constants.js +2 -0
  303. package/dist/core/session/constants.js.map +1 -0
  304. package/dist/core/session/context-metadata.d.ts +5 -0
  305. package/dist/core/session/context-metadata.d.ts.map +1 -0
  306. package/dist/core/session/context-metadata.js +55 -0
  307. package/dist/core/session/context-metadata.js.map +1 -0
  308. package/dist/core/session/context.d.ts +14 -0
  309. package/dist/core/session/context.d.ts.map +1 -0
  310. package/dist/core/session/context.js +117 -0
  311. package/dist/core/session/context.js.map +1 -0
  312. package/dist/core/session/ids.d.ts +9 -0
  313. package/dist/core/session/ids.d.ts.map +1 -0
  314. package/dist/core/session/ids.js +21 -0
  315. package/dist/core/session/ids.js.map +1 -0
  316. package/dist/core/session/in-memory-session-manager.d.ts +17 -0
  317. package/dist/core/session/in-memory-session-manager.d.ts.map +1 -0
  318. package/dist/core/session/in-memory-session-manager.js +40 -0
  319. package/dist/core/session/in-memory-session-manager.js.map +1 -0
  320. package/dist/core/session/in-memory-session.d.ts +7 -0
  321. package/dist/core/session/in-memory-session.d.ts.map +1 -0
  322. package/dist/core/session/in-memory-session.js +11 -0
  323. package/dist/core/session/in-memory-session.js.map +1 -0
  324. package/dist/core/session/jsonl-errors.d.ts +36 -0
  325. package/dist/core/session/jsonl-errors.d.ts.map +1 -0
  326. package/dist/core/session/jsonl-errors.js +49 -0
  327. package/dist/core/session/jsonl-errors.js.map +1 -0
  328. package/dist/core/session/jsonl-helpers.d.ts +20 -0
  329. package/dist/core/session/jsonl-helpers.d.ts.map +1 -0
  330. package/dist/core/session/jsonl-helpers.js +21 -0
  331. package/dist/core/session/jsonl-helpers.js.map +1 -0
  332. package/dist/core/session/local-session-manager.d.ts +30 -0
  333. package/dist/core/session/local-session-manager.d.ts.map +1 -0
  334. package/dist/core/session/local-session-manager.js +205 -0
  335. package/dist/core/session/local-session-manager.js.map +1 -0
  336. package/dist/core/session/local-session.d.ts +9 -0
  337. package/dist/core/session/local-session.d.ts.map +1 -0
  338. package/dist/core/session/local-session.js +15 -0
  339. package/dist/core/session/local-session.js.map +1 -0
  340. package/dist/core/session/migrations.d.ts +11 -0
  341. package/dist/core/session/migrations.d.ts.map +1 -0
  342. package/dist/core/session/migrations.js +78 -0
  343. package/dist/core/session/migrations.js.map +1 -0
  344. package/dist/core/session/remote-session-client.d.ts +83 -0
  345. package/dist/core/session/remote-session-client.d.ts.map +1 -0
  346. package/dist/core/session/remote-session-client.js +224 -0
  347. package/dist/core/session/remote-session-client.js.map +1 -0
  348. package/dist/core/session/remote-session-manager.d.ts +32 -0
  349. package/dist/core/session/remote-session-manager.d.ts.map +1 -0
  350. package/dist/core/session/remote-session-manager.js +124 -0
  351. package/dist/core/session/remote-session-manager.js.map +1 -0
  352. package/dist/core/session/remote-session.d.ts +20 -0
  353. package/dist/core/session/remote-session.d.ts.map +1 -0
  354. package/dist/core/session/remote-session.js +33 -0
  355. package/dist/core/session/remote-session.js.map +1 -0
  356. package/dist/core/session/session-manager.d.ts +18 -0
  357. package/dist/core/session/session-manager.d.ts.map +1 -0
  358. package/dist/core/session/session-manager.js +2 -0
  359. package/dist/core/session/session-manager.js.map +1 -0
  360. package/dist/core/session/session.d.ts +140 -0
  361. package/dist/core/session/session.d.ts.map +1 -0
  362. package/dist/core/session/session.js +461 -0
  363. package/dist/core/session/session.js.map +1 -0
  364. package/dist/core/session/stores/in-memory-session-store.d.ts +39 -0
  365. package/dist/core/session/stores/in-memory-session-store.d.ts.map +1 -0
  366. package/dist/core/session/stores/in-memory-session-store.js +168 -0
  367. package/dist/core/session/stores/in-memory-session-store.js.map +1 -0
  368. package/dist/core/session/stores/jsonl-session-store.d.ts +97 -0
  369. package/dist/core/session/stores/jsonl-session-store.d.ts.map +1 -0
  370. package/dist/core/session/stores/jsonl-session-store.js +1140 -0
  371. package/dist/core/session/stores/jsonl-session-store.js.map +1 -0
  372. package/dist/core/session/stores/remote-session-store.d.ts +44 -0
  373. package/dist/core/session/stores/remote-session-store.d.ts.map +1 -0
  374. package/dist/core/session/stores/remote-session-store.js +159 -0
  375. package/dist/core/session/stores/remote-session-store.js.map +1 -0
  376. package/dist/core/session/stores/session-store.d.ts +42 -0
  377. package/dist/core/session/stores/session-store.d.ts.map +1 -0
  378. package/dist/core/session/stores/session-store.js +2 -0
  379. package/dist/core/session/stores/session-store.js.map +1 -0
  380. package/dist/core/session/types.d.ts +141 -0
  381. package/dist/core/session/types.d.ts.map +1 -0
  382. package/dist/core/session/types.js +2 -0
  383. package/dist/core/session/types.js.map +1 -0
  384. package/dist/core/session/usage-ledger.d.ts +18 -0
  385. package/dist/core/session/usage-ledger.d.ts.map +1 -0
  386. package/dist/core/session/usage-ledger.js +68 -0
  387. package/dist/core/session/usage-ledger.js.map +1 -0
  388. package/dist/core/session-cwd.d.ts +19 -0
  389. package/dist/core/session-cwd.d.ts.map +1 -0
  390. package/dist/core/session-cwd.js +38 -0
  391. package/dist/core/session-cwd.js.map +1 -0
  392. package/dist/core/settings-manager.d.ts +318 -0
  393. package/dist/core/settings-manager.d.ts.map +1 -0
  394. package/dist/core/settings-manager.js +991 -0
  395. package/dist/core/settings-manager.js.map +1 -0
  396. package/dist/core/skills.d.ts +40 -0
  397. package/dist/core/skills.d.ts.map +1 -0
  398. package/dist/core/skills.js +57 -0
  399. package/dist/core/skills.js.map +1 -0
  400. package/dist/core/slash-commands.d.ts +15 -0
  401. package/dist/core/slash-commands.d.ts.map +1 -0
  402. package/dist/core/slash-commands.js +36 -0
  403. package/dist/core/slash-commands.js.map +1 -0
  404. package/dist/core/source-info.d.ts +26 -0
  405. package/dist/core/source-info.d.ts.map +1 -0
  406. package/dist/core/source-info.js +27 -0
  407. package/dist/core/source-info.js.map +1 -0
  408. package/dist/core/system-prompt.d.ts +32 -0
  409. package/dist/core/system-prompt.d.ts.map +1 -0
  410. package/dist/core/system-prompt.js +131 -0
  411. package/dist/core/system-prompt.js.map +1 -0
  412. package/dist/core/telemetry.d.ts +3 -0
  413. package/dist/core/telemetry.d.ts.map +1 -0
  414. package/dist/core/telemetry.js +9 -0
  415. package/dist/core/telemetry.js.map +1 -0
  416. package/dist/core/timings.d.ts +10 -0
  417. package/dist/core/timings.d.ts.map +1 -0
  418. package/dist/core/timings.js +41 -0
  419. package/dist/core/timings.js.map +1 -0
  420. package/dist/core/tools/bash.d.ts +51 -0
  421. package/dist/core/tools/bash.d.ts.map +1 -0
  422. package/dist/core/tools/bash.js +310 -0
  423. package/dist/core/tools/bash.js.map +1 -0
  424. package/dist/core/tools/compress-context.d.ts +27 -0
  425. package/dist/core/tools/compress-context.d.ts.map +1 -0
  426. package/dist/core/tools/compress-context.js +142 -0
  427. package/dist/core/tools/compress-context.js.map +1 -0
  428. package/dist/core/tools/edit-diff.d.ts +82 -0
  429. package/dist/core/tools/edit-diff.d.ts.map +1 -0
  430. package/dist/core/tools/edit-diff.js +327 -0
  431. package/dist/core/tools/edit-diff.js.map +1 -0
  432. package/dist/core/tools/edit.d.ts +50 -0
  433. package/dist/core/tools/edit.d.ts.map +1 -0
  434. package/dist/core/tools/edit.js +324 -0
  435. package/dist/core/tools/edit.js.map +1 -0
  436. package/dist/core/tools/file-mutation-queue.d.ts +6 -0
  437. package/dist/core/tools/file-mutation-queue.d.ts.map +1 -0
  438. package/dist/core/tools/file-mutation-queue.js +60 -0
  439. package/dist/core/tools/file-mutation-queue.js.map +1 -0
  440. package/dist/core/tools/find.d.ts +22 -0
  441. package/dist/core/tools/find.d.ts.map +1 -0
  442. package/dist/core/tools/find.js +268 -0
  443. package/dist/core/tools/find.js.map +1 -0
  444. package/dist/core/tools/grep.d.ts +27 -0
  445. package/dist/core/tools/grep.d.ts.map +1 -0
  446. package/dist/core/tools/grep.js +332 -0
  447. package/dist/core/tools/grep.js.map +1 -0
  448. package/dist/core/tools/hash-store.d.ts +12 -0
  449. package/dist/core/tools/hash-store.d.ts.map +1 -0
  450. package/dist/core/tools/hash-store.js +48 -0
  451. package/dist/core/tools/hash-store.js.map +1 -0
  452. package/dist/core/tools/hashline/apply.d.ts +40 -0
  453. package/dist/core/tools/hashline/apply.d.ts.map +1 -0
  454. package/dist/core/tools/hashline/apply.js +261 -0
  455. package/dist/core/tools/hashline/apply.js.map +1 -0
  456. package/dist/core/tools/hashline/hash.d.ts +56 -0
  457. package/dist/core/tools/hashline/hash.d.ts.map +1 -0
  458. package/dist/core/tools/hashline/hash.js +196 -0
  459. package/dist/core/tools/hashline/hash.js.map +1 -0
  460. package/dist/core/tools/hashline/parse.d.ts +8 -0
  461. package/dist/core/tools/hashline/parse.d.ts.map +1 -0
  462. package/dist/core/tools/hashline/parse.js +41 -0
  463. package/dist/core/tools/hashline/parse.js.map +1 -0
  464. package/dist/core/tools/hashline/resolve.d.ts +51 -0
  465. package/dist/core/tools/hashline/resolve.d.ts.map +1 -0
  466. package/dist/core/tools/hashline/resolve.js +187 -0
  467. package/dist/core/tools/hashline/resolve.js.map +1 -0
  468. package/dist/core/tools/hashline-utils.d.ts +6 -0
  469. package/dist/core/tools/hashline-utils.d.ts.map +1 -0
  470. package/dist/core/tools/hashline-utils.js +23 -0
  471. package/dist/core/tools/hashline-utils.js.map +1 -0
  472. package/dist/core/tools/index.d.ts +36 -0
  473. package/dist/core/tools/index.d.ts.map +1 -0
  474. package/dist/core/tools/index.js +141 -0
  475. package/dist/core/tools/index.js.map +1 -0
  476. package/dist/core/tools/ls.d.ts +21 -0
  477. package/dist/core/tools/ls.d.ts.map +1 -0
  478. package/dist/core/tools/ls.js +156 -0
  479. package/dist/core/tools/ls.js.map +1 -0
  480. package/dist/core/tools/operations.d.ts +201 -0
  481. package/dist/core/tools/operations.d.ts.map +1 -0
  482. package/dist/core/tools/operations.js +697 -0
  483. package/dist/core/tools/operations.js.map +1 -0
  484. package/dist/core/tools/output-accumulator.d.ts +54 -0
  485. package/dist/core/tools/output-accumulator.d.ts.map +1 -0
  486. package/dist/core/tools/output-accumulator.js +184 -0
  487. package/dist/core/tools/output-accumulator.js.map +1 -0
  488. package/dist/core/tools/path-utils.d.ts +9 -0
  489. package/dist/core/tools/path-utils.d.ts.map +1 -0
  490. package/dist/core/tools/path-utils.js +99 -0
  491. package/dist/core/tools/path-utils.js.map +1 -0
  492. package/dist/core/tools/read.d.ts +32 -0
  493. package/dist/core/tools/read.d.ts.map +1 -0
  494. package/dist/core/tools/read.js +318 -0
  495. package/dist/core/tools/read.js.map +1 -0
  496. package/dist/core/tools/render-utils.d.ts +33 -0
  497. package/dist/core/tools/render-utils.d.ts.map +1 -0
  498. package/dist/core/tools/render-utils.js +61 -0
  499. package/dist/core/tools/render-utils.js.map +1 -0
  500. package/dist/core/tools/replace-diff.d.ts +16 -0
  501. package/dist/core/tools/replace-diff.d.ts.map +1 -0
  502. package/dist/core/tools/replace-diff.js +117 -0
  503. package/dist/core/tools/replace-diff.js.map +1 -0
  504. package/dist/core/tools/replace-normalize.d.ts +2 -0
  505. package/dist/core/tools/replace-normalize.d.ts.map +1 -0
  506. package/dist/core/tools/replace-normalize.js +73 -0
  507. package/dist/core/tools/replace-normalize.js.map +1 -0
  508. package/dist/core/tools/replace-render.d.ts +51 -0
  509. package/dist/core/tools/replace-render.d.ts.map +1 -0
  510. package/dist/core/tools/replace-render.js +162 -0
  511. package/dist/core/tools/replace-render.js.map +1 -0
  512. package/dist/core/tools/runtime.d.ts +2 -0
  513. package/dist/core/tools/runtime.d.ts.map +1 -0
  514. package/dist/core/tools/runtime.js +6 -0
  515. package/dist/core/tools/runtime.js.map +1 -0
  516. package/dist/core/tools/session-history.d.ts +55 -0
  517. package/dist/core/tools/session-history.d.ts.map +1 -0
  518. package/dist/core/tools/session-history.js +649 -0
  519. package/dist/core/tools/session-history.js.map +1 -0
  520. package/dist/core/tools/subagent-agents.d.ts +29 -0
  521. package/dist/core/tools/subagent-agents.d.ts.map +1 -0
  522. package/dist/core/tools/subagent-agents.js +223 -0
  523. package/dist/core/tools/subagent-agents.js.map +1 -0
  524. package/dist/core/tools/subagent.d.ts +185 -0
  525. package/dist/core/tools/subagent.d.ts.map +1 -0
  526. package/dist/core/tools/subagent.js +1309 -0
  527. package/dist/core/tools/subagent.js.map +1 -0
  528. package/dist/core/tools/tool-definition-wrapper.d.ts +14 -0
  529. package/dist/core/tools/tool-definition-wrapper.d.ts.map +1 -0
  530. package/dist/core/tools/tool-definition-wrapper.js +34 -0
  531. package/dist/core/tools/tool-definition-wrapper.js.map +1 -0
  532. package/dist/core/tools/truncate.d.ts +39 -0
  533. package/dist/core/tools/truncate.d.ts.map +1 -0
  534. package/dist/core/tools/truncate.js +215 -0
  535. package/dist/core/tools/truncate.js.map +1 -0
  536. package/dist/core/tools/websearch.d.ts +33 -0
  537. package/dist/core/tools/websearch.d.ts.map +1 -0
  538. package/dist/core/tools/websearch.js +341 -0
  539. package/dist/core/tools/websearch.js.map +1 -0
  540. package/dist/core/tools/workspace-tool-host.d.ts +102 -0
  541. package/dist/core/tools/workspace-tool-host.d.ts.map +1 -0
  542. package/dist/core/tools/workspace-tool-host.js +348 -0
  543. package/dist/core/tools/workspace-tool-host.js.map +1 -0
  544. package/dist/core/tools/write.d.ts +16 -0
  545. package/dist/core/tools/write.d.ts.map +1 -0
  546. package/dist/core/tools/write.js +204 -0
  547. package/dist/core/tools/write.js.map +1 -0
  548. package/dist/core/workspace-identity.d.ts +7 -0
  549. package/dist/core/workspace-identity.d.ts.map +1 -0
  550. package/dist/core/workspace-identity.js +2 -0
  551. package/dist/core/workspace-identity.js.map +1 -0
  552. package/dist/daemon/command.d.ts +6 -0
  553. package/dist/daemon/command.d.ts.map +1 -0
  554. package/dist/daemon/command.js +58 -0
  555. package/dist/daemon/command.js.map +1 -0
  556. package/dist/daemon/config.d.ts +43 -0
  557. package/dist/daemon/config.d.ts.map +1 -0
  558. package/dist/daemon/config.js +304 -0
  559. package/dist/daemon/config.js.map +1 -0
  560. package/dist/daemon/help.d.ts +2 -0
  561. package/dist/daemon/help.d.ts.map +1 -0
  562. package/dist/daemon/help.js +42 -0
  563. package/dist/daemon/help.js.map +1 -0
  564. package/dist/daemon/lsp-config.d.ts +4 -0
  565. package/dist/daemon/lsp-config.d.ts.map +1 -0
  566. package/dist/daemon/lsp-config.js +155 -0
  567. package/dist/daemon/lsp-config.js.map +1 -0
  568. package/dist/daemon/security.d.ts +19 -0
  569. package/dist/daemon/security.d.ts.map +1 -0
  570. package/dist/daemon/security.js +175 -0
  571. package/dist/daemon/security.js.map +1 -0
  572. package/dist/daemon/server.d.ts +20 -0
  573. package/dist/daemon/server.d.ts.map +1 -0
  574. package/dist/daemon/server.js +400 -0
  575. package/dist/daemon/server.js.map +1 -0
  576. package/dist/daemon/workspace-runtime.d.ts +46 -0
  577. package/dist/daemon/workspace-runtime.d.ts.map +1 -0
  578. package/dist/daemon/workspace-runtime.js +673 -0
  579. package/dist/daemon/workspace-runtime.js.map +1 -0
  580. package/dist/index.d.ts +109 -0
  581. package/dist/index.d.ts.map +1 -0
  582. package/dist/index.js +107 -0
  583. package/dist/index.js.map +1 -0
  584. package/dist/main.d.ts +39 -0
  585. package/dist/main.d.ts.map +1 -0
  586. package/dist/main.js +763 -0
  587. package/dist/main.js.map +1 -0
  588. package/dist/migrations.d.ts +35 -0
  589. package/dist/migrations.d.ts.map +1 -0
  590. package/dist/migrations.js +412 -0
  591. package/dist/migrations.js.map +1 -0
  592. package/dist/modes/interactive/components/assistant-message.d.ts +29 -0
  593. package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -0
  594. package/dist/modes/interactive/components/assistant-message.js +149 -0
  595. package/dist/modes/interactive/components/assistant-message.js.map +1 -0
  596. package/dist/modes/interactive/components/bash-execution.d.ts +36 -0
  597. package/dist/modes/interactive/components/bash-execution.d.ts.map +1 -0
  598. package/dist/modes/interactive/components/bash-execution.js +173 -0
  599. package/dist/modes/interactive/components/bash-execution.js.map +1 -0
  600. package/dist/modes/interactive/components/bordered-loader.d.ts +18 -0
  601. package/dist/modes/interactive/components/bordered-loader.d.ts.map +1 -0
  602. package/dist/modes/interactive/components/bordered-loader.js +54 -0
  603. package/dist/modes/interactive/components/bordered-loader.js.map +1 -0
  604. package/dist/modes/interactive/components/branch-summary-message.d.ts +16 -0
  605. package/dist/modes/interactive/components/branch-summary-message.d.ts.map +1 -0
  606. package/dist/modes/interactive/components/branch-summary-message.js +44 -0
  607. package/dist/modes/interactive/components/branch-summary-message.js.map +1 -0
  608. package/dist/modes/interactive/components/compaction-summary-message.d.ts +16 -0
  609. package/dist/modes/interactive/components/compaction-summary-message.d.ts.map +1 -0
  610. package/dist/modes/interactive/components/compaction-summary-message.js +45 -0
  611. package/dist/modes/interactive/components/compaction-summary-message.js.map +1 -0
  612. package/dist/modes/interactive/components/config-selector.d.ts +74 -0
  613. package/dist/modes/interactive/components/config-selector.d.ts.map +1 -0
  614. package/dist/modes/interactive/components/config-selector.js +514 -0
  615. package/dist/modes/interactive/components/config-selector.js.map +1 -0
  616. package/dist/modes/interactive/components/countdown-timer.d.ts +14 -0
  617. package/dist/modes/interactive/components/countdown-timer.d.ts.map +1 -0
  618. package/dist/modes/interactive/components/countdown-timer.js +33 -0
  619. package/dist/modes/interactive/components/countdown-timer.js.map +1 -0
  620. package/dist/modes/interactive/components/custom-editor.d.ts +25 -0
  621. package/dist/modes/interactive/components/custom-editor.d.ts.map +1 -0
  622. package/dist/modes/interactive/components/custom-editor.js +85 -0
  623. package/dist/modes/interactive/components/custom-editor.js.map +1 -0
  624. package/dist/modes/interactive/components/custom-message.d.ts +20 -0
  625. package/dist/modes/interactive/components/custom-message.d.ts.map +1 -0
  626. package/dist/modes/interactive/components/custom-message.js +80 -0
  627. package/dist/modes/interactive/components/custom-message.js.map +1 -0
  628. package/dist/modes/interactive/components/diff.d.ts +12 -0
  629. package/dist/modes/interactive/components/diff.d.ts.map +1 -0
  630. package/dist/modes/interactive/components/diff.js +118 -0
  631. package/dist/modes/interactive/components/diff.js.map +1 -0
  632. package/dist/modes/interactive/components/dynamic-border.d.ts +15 -0
  633. package/dist/modes/interactive/components/dynamic-border.d.ts.map +1 -0
  634. package/dist/modes/interactive/components/dynamic-border.js +21 -0
  635. package/dist/modes/interactive/components/dynamic-border.js.map +1 -0
  636. package/dist/modes/interactive/components/extension-editor.d.ts +22 -0
  637. package/dist/modes/interactive/components/extension-editor.d.ts.map +1 -0
  638. package/dist/modes/interactive/components/extension-editor.js +128 -0
  639. package/dist/modes/interactive/components/extension-editor.js.map +1 -0
  640. package/dist/modes/interactive/components/extension-input.d.ts +23 -0
  641. package/dist/modes/interactive/components/extension-input.d.ts.map +1 -0
  642. package/dist/modes/interactive/components/extension-input.js +61 -0
  643. package/dist/modes/interactive/components/extension-input.js.map +1 -0
  644. package/dist/modes/interactive/components/extension-selector.d.ts +26 -0
  645. package/dist/modes/interactive/components/extension-selector.d.ts.map +1 -0
  646. package/dist/modes/interactive/components/extension-selector.js +83 -0
  647. package/dist/modes/interactive/components/extension-selector.js.map +1 -0
  648. package/dist/modes/interactive/components/footer.d.ts +36 -0
  649. package/dist/modes/interactive/components/footer.d.ts.map +1 -0
  650. package/dist/modes/interactive/components/footer.js +227 -0
  651. package/dist/modes/interactive/components/footer.js.map +1 -0
  652. package/dist/modes/interactive/components/hook-execution.d.ts +19 -0
  653. package/dist/modes/interactive/components/hook-execution.d.ts.map +1 -0
  654. package/dist/modes/interactive/components/hook-execution.js +184 -0
  655. package/dist/modes/interactive/components/hook-execution.js.map +1 -0
  656. package/dist/modes/interactive/components/keybinding-hints.d.ts +13 -0
  657. package/dist/modes/interactive/components/keybinding-hints.d.ts.map +1 -0
  658. package/dist/modes/interactive/components/keybinding-hints.js +36 -0
  659. package/dist/modes/interactive/components/keybinding-hints.js.map +1 -0
  660. package/dist/modes/interactive/components/login-dialog.d.ts +55 -0
  661. package/dist/modes/interactive/components/login-dialog.d.ts.map +1 -0
  662. package/dist/modes/interactive/components/login-dialog.js +176 -0
  663. package/dist/modes/interactive/components/login-dialog.js.map +1 -0
  664. package/dist/modes/interactive/components/markdown-transform.d.ts +4 -0
  665. package/dist/modes/interactive/components/markdown-transform.d.ts.map +1 -0
  666. package/dist/modes/interactive/components/markdown-transform.js +19 -0
  667. package/dist/modes/interactive/components/markdown-transform.js.map +1 -0
  668. package/dist/modes/interactive/components/mermaid.d.ts +14 -0
  669. package/dist/modes/interactive/components/mermaid.d.ts.map +1 -0
  670. package/dist/modes/interactive/components/mermaid.js +228 -0
  671. package/dist/modes/interactive/components/mermaid.js.map +1 -0
  672. package/dist/modes/interactive/components/model-selector.d.ts +52 -0
  673. package/dist/modes/interactive/components/model-selector.d.ts.map +1 -0
  674. package/dist/modes/interactive/components/model-selector.js +296 -0
  675. package/dist/modes/interactive/components/model-selector.js.map +1 -0
  676. package/dist/modes/interactive/components/oauth-selector.d.ts +33 -0
  677. package/dist/modes/interactive/components/oauth-selector.d.ts.map +1 -0
  678. package/dist/modes/interactive/components/oauth-selector.js +165 -0
  679. package/dist/modes/interactive/components/oauth-selector.js.map +1 -0
  680. package/dist/modes/interactive/components/scoped-models-selector.d.ts +50 -0
  681. package/dist/modes/interactive/components/scoped-models-selector.d.ts.map +1 -0
  682. package/dist/modes/interactive/components/scoped-models-selector.js +300 -0
  683. package/dist/modes/interactive/components/scoped-models-selector.js.map +1 -0
  684. package/dist/modes/interactive/components/session-selector-search.d.ts +22 -0
  685. package/dist/modes/interactive/components/session-selector-search.d.ts.map +1 -0
  686. package/dist/modes/interactive/components/session-selector-search.js +144 -0
  687. package/dist/modes/interactive/components/session-selector-search.js.map +1 -0
  688. package/dist/modes/interactive/components/session-selector.d.ts +108 -0
  689. package/dist/modes/interactive/components/session-selector.d.ts.map +1 -0
  690. package/dist/modes/interactive/components/session-selector.js +835 -0
  691. package/dist/modes/interactive/components/session-selector.js.map +1 -0
  692. package/dist/modes/interactive/components/settings-selector.d.ts +81 -0
  693. package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -0
  694. package/dist/modes/interactive/components/settings-selector.js +455 -0
  695. package/dist/modes/interactive/components/settings-selector.js.map +1 -0
  696. package/dist/modes/interactive/components/show-images-selector.d.ts +10 -0
  697. package/dist/modes/interactive/components/show-images-selector.d.ts.map +1 -0
  698. package/dist/modes/interactive/components/show-images-selector.js +39 -0
  699. package/dist/modes/interactive/components/show-images-selector.js.map +1 -0
  700. package/dist/modes/interactive/components/skill-invocation-message.d.ts +17 -0
  701. package/dist/modes/interactive/components/skill-invocation-message.d.ts.map +1 -0
  702. package/dist/modes/interactive/components/skill-invocation-message.js +47 -0
  703. package/dist/modes/interactive/components/skill-invocation-message.js.map +1 -0
  704. package/dist/modes/interactive/components/theme-selector.d.ts +11 -0
  705. package/dist/modes/interactive/components/theme-selector.d.ts.map +1 -0
  706. package/dist/modes/interactive/components/theme-selector.js +50 -0
  707. package/dist/modes/interactive/components/theme-selector.js.map +1 -0
  708. package/dist/modes/interactive/components/thinking-selector.d.ts +11 -0
  709. package/dist/modes/interactive/components/thinking-selector.d.ts.map +1 -0
  710. package/dist/modes/interactive/components/thinking-selector.js +51 -0
  711. package/dist/modes/interactive/components/thinking-selector.js.map +1 -0
  712. package/dist/modes/interactive/components/tool-execution.d.ts +67 -0
  713. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -0
  714. package/dist/modes/interactive/components/tool-execution.js +306 -0
  715. package/dist/modes/interactive/components/tool-execution.js.map +1 -0
  716. package/dist/modes/interactive/components/tree-selector.d.ts +127 -0
  717. package/dist/modes/interactive/components/tree-selector.d.ts.map +1 -0
  718. package/dist/modes/interactive/components/tree-selector.js +1098 -0
  719. package/dist/modes/interactive/components/tree-selector.js.map +1 -0
  720. package/dist/modes/interactive/components/user-message-selector.d.ts +30 -0
  721. package/dist/modes/interactive/components/user-message-selector.d.ts.map +1 -0
  722. package/dist/modes/interactive/components/user-message-selector.js +114 -0
  723. package/dist/modes/interactive/components/user-message-selector.js.map +1 -0
  724. package/dist/modes/interactive/components/user-message.d.ts +16 -0
  725. package/dist/modes/interactive/components/user-message.d.ts.map +1 -0
  726. package/dist/modes/interactive/components/user-message.js +49 -0
  727. package/dist/modes/interactive/components/user-message.js.map +1 -0
  728. package/dist/modes/interactive/components/visual-truncate.d.ts +24 -0
  729. package/dist/modes/interactive/components/visual-truncate.d.ts.map +1 -0
  730. package/dist/modes/interactive/components/visual-truncate.js +33 -0
  731. package/dist/modes/interactive/components/visual-truncate.js.map +1 -0
  732. package/dist/modes/interactive/interactive-mode.d.ts +557 -0
  733. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -0
  734. package/dist/modes/interactive/interactive-mode.js +5859 -0
  735. package/dist/modes/interactive/interactive-mode.js.map +1 -0
  736. package/dist/modes/interactive/theme/dark.json +86 -0
  737. package/dist/modes/interactive/theme/light.json +85 -0
  738. package/dist/modes/interactive/theme/theme-schema.json +335 -0
  739. package/dist/modes/interactive/theme/theme.d.ts +106 -0
  740. package/dist/modes/interactive/theme/theme.d.ts.map +1 -0
  741. package/dist/modes/interactive/theme/theme.js +1030 -0
  742. package/dist/modes/interactive/theme/theme.js.map +1 -0
  743. package/dist/modes/json-event.d.ts +28 -0
  744. package/dist/modes/json-event.d.ts.map +1 -0
  745. package/dist/modes/json-event.js +12 -0
  746. package/dist/modes/json-event.js.map +1 -0
  747. package/dist/modes/print-mode.d.ts +29 -0
  748. package/dist/modes/print-mode.d.ts.map +1 -0
  749. package/dist/modes/print-mode.js +142 -0
  750. package/dist/modes/print-mode.js.map +1 -0
  751. package/dist/modes/rpc/jsonl.d.ts +17 -0
  752. package/dist/modes/rpc/jsonl.d.ts.map +1 -0
  753. package/dist/modes/rpc/jsonl.js +49 -0
  754. package/dist/modes/rpc/jsonl.js.map +1 -0
  755. package/dist/modes/rpc/rpc-client.d.ts +321 -0
  756. package/dist/modes/rpc/rpc-client.d.ts.map +1 -0
  757. package/dist/modes/rpc/rpc-client.js +755 -0
  758. package/dist/modes/rpc/rpc-client.js.map +1 -0
  759. package/dist/modes/rpc/rpc-mode.d.ts +20 -0
  760. package/dist/modes/rpc/rpc-mode.d.ts.map +1 -0
  761. package/dist/modes/rpc/rpc-mode.js +963 -0
  762. package/dist/modes/rpc/rpc-mode.js.map +1 -0
  763. package/dist/modes/rpc/rpc-types.d.ts +652 -0
  764. package/dist/modes/rpc/rpc-types.d.ts.map +1 -0
  765. package/dist/modes/rpc/rpc-types.js +8 -0
  766. package/dist/modes/rpc/rpc-types.js.map +1 -0
  767. package/dist/package-manager-cli.d.ts +4 -0
  768. package/dist/package-manager-cli.d.ts.map +1 -0
  769. package/dist/package-manager-cli.js +488 -0
  770. package/dist/package-manager-cli.js.map +1 -0
  771. package/dist/utils/ansi.d.ts +2 -0
  772. package/dist/utils/ansi.d.ts.map +1 -0
  773. package/dist/utils/ansi.js +25 -0
  774. package/dist/utils/ansi.js.map +1 -0
  775. package/dist/utils/changelog.d.ts +23 -0
  776. package/dist/utils/changelog.d.ts.map +1 -0
  777. package/dist/utils/changelog.js +74 -0
  778. package/dist/utils/changelog.js.map +1 -0
  779. package/dist/utils/child-process.d.ts +15 -0
  780. package/dist/utils/child-process.d.ts.map +1 -0
  781. package/dist/utils/child-process.js +88 -0
  782. package/dist/utils/child-process.js.map +1 -0
  783. package/dist/utils/clipboard-image.d.ts +13 -0
  784. package/dist/utils/clipboard-image.d.ts.map +1 -0
  785. package/dist/utils/clipboard-image.js +248 -0
  786. package/dist/utils/clipboard-image.js.map +1 -0
  787. package/dist/utils/clipboard-native.d.ts +11 -0
  788. package/dist/utils/clipboard-native.d.ts.map +1 -0
  789. package/dist/utils/clipboard-native.js +20 -0
  790. package/dist/utils/clipboard-native.js.map +1 -0
  791. package/dist/utils/clipboard.d.ts +4 -0
  792. package/dist/utils/clipboard.d.ts.map +1 -0
  793. package/dist/utils/clipboard.js +171 -0
  794. package/dist/utils/clipboard.js.map +1 -0
  795. package/dist/utils/deprecation.d.ts +4 -0
  796. package/dist/utils/deprecation.d.ts.map +1 -0
  797. package/dist/utils/deprecation.js +13 -0
  798. package/dist/utils/deprecation.js.map +1 -0
  799. package/dist/utils/directory-completions.d.ts +5 -0
  800. package/dist/utils/directory-completions.d.ts.map +1 -0
  801. package/dist/utils/directory-completions.js +64 -0
  802. package/dist/utils/directory-completions.js.map +1 -0
  803. package/dist/utils/exif-orientation.d.ts +6 -0
  804. package/dist/utils/exif-orientation.d.ts.map +1 -0
  805. package/dist/utils/exif-orientation.js +166 -0
  806. package/dist/utils/exif-orientation.js.map +1 -0
  807. package/dist/utils/frontmatter.d.ts +8 -0
  808. package/dist/utils/frontmatter.d.ts.map +1 -0
  809. package/dist/utils/frontmatter.js +26 -0
  810. package/dist/utils/frontmatter.js.map +1 -0
  811. package/dist/utils/fs-watch.d.ts +5 -0
  812. package/dist/utils/fs-watch.d.ts.map +1 -0
  813. package/dist/utils/fs-watch.js +25 -0
  814. package/dist/utils/fs-watch.js.map +1 -0
  815. package/dist/utils/git.d.ts +27 -0
  816. package/dist/utils/git.d.ts.map +1 -0
  817. package/dist/utils/git.js +237 -0
  818. package/dist/utils/git.js.map +1 -0
  819. package/dist/utils/grip-user-agent.d.ts +2 -0
  820. package/dist/utils/grip-user-agent.d.ts.map +1 -0
  821. package/dist/utils/grip-user-agent.js +5 -0
  822. package/dist/utils/grip-user-agent.js.map +1 -0
  823. package/dist/utils/html.d.ts +7 -0
  824. package/dist/utils/html.d.ts.map +1 -0
  825. package/dist/utils/html.js +40 -0
  826. package/dist/utils/html.js.map +1 -0
  827. package/dist/utils/image-convert.d.ts +12 -0
  828. package/dist/utils/image-convert.d.ts.map +1 -0
  829. package/dist/utils/image-convert.js +43 -0
  830. package/dist/utils/image-convert.js.map +1 -0
  831. package/dist/utils/image-process.d.ts +18 -0
  832. package/dist/utils/image-process.d.ts.map +1 -0
  833. package/dist/utils/image-process.js +83 -0
  834. package/dist/utils/image-process.js.map +1 -0
  835. package/dist/utils/image-resize-core.d.ts +30 -0
  836. package/dist/utils/image-resize-core.d.ts.map +1 -0
  837. package/dist/utils/image-resize-core.js +133 -0
  838. package/dist/utils/image-resize-core.js.map +1 -0
  839. package/dist/utils/image-resize-worker.d.ts +2 -0
  840. package/dist/utils/image-resize-worker.d.ts.map +1 -0
  841. package/dist/utils/image-resize-worker.js +31 -0
  842. package/dist/utils/image-resize-worker.js.map +1 -0
  843. package/dist/utils/image-resize.d.ts +19 -0
  844. package/dist/utils/image-resize.d.ts.map +1 -0
  845. package/dist/utils/image-resize.js +81 -0
  846. package/dist/utils/image-resize.js.map +1 -0
  847. package/dist/utils/json.d.ts +3 -0
  848. package/dist/utils/json.d.ts.map +1 -0
  849. package/dist/utils/json.js +7 -0
  850. package/dist/utils/json.js.map +1 -0
  851. package/dist/utils/mime.d.ts +3 -0
  852. package/dist/utils/mime.d.ts.map +1 -0
  853. package/dist/utils/mime.js +110 -0
  854. package/dist/utils/mime.js.map +1 -0
  855. package/dist/utils/open-browser.d.ts +9 -0
  856. package/dist/utils/open-browser.d.ts.map +1 -0
  857. package/dist/utils/open-browser.js +22 -0
  858. package/dist/utils/open-browser.js.map +1 -0
  859. package/dist/utils/paths.d.ts +31 -0
  860. package/dist/utils/paths.d.ts.map +1 -0
  861. package/dist/utils/paths.js +87 -0
  862. package/dist/utils/paths.js.map +1 -0
  863. package/dist/utils/photon.d.ts +22 -0
  864. package/dist/utils/photon.d.ts.map +1 -0
  865. package/dist/utils/photon.js +125 -0
  866. package/dist/utils/photon.js.map +1 -0
  867. package/dist/utils/shell.d.ts +28 -0
  868. package/dist/utils/shell.d.ts.map +1 -0
  869. package/dist/utils/shell.js +188 -0
  870. package/dist/utils/shell.js.map +1 -0
  871. package/dist/utils/sleep.d.ts +5 -0
  872. package/dist/utils/sleep.d.ts.map +1 -0
  873. package/dist/utils/sleep.js +17 -0
  874. package/dist/utils/sleep.js.map +1 -0
  875. package/dist/utils/syntax-highlight.d.ts +12 -0
  876. package/dist/utils/syntax-highlight.d.ts.map +1 -0
  877. package/dist/utils/syntax-highlight.js +125 -0
  878. package/dist/utils/syntax-highlight.js.map +1 -0
  879. package/dist/utils/tools-manager.d.ts +5 -0
  880. package/dist/utils/tools-manager.d.ts.map +1 -0
  881. package/dist/utils/tools-manager.js +329 -0
  882. package/dist/utils/tools-manager.js.map +1 -0
  883. package/dist/utils/version-check.d.ts +14 -0
  884. package/dist/utils/version-check.d.ts.map +1 -0
  885. package/dist/utils/version-check.js +91 -0
  886. package/dist/utils/version-check.js.map +1 -0
  887. package/dist/utils/windows-self-update.d.ts +3 -0
  888. package/dist/utils/windows-self-update.d.ts.map +1 -0
  889. package/dist/utils/windows-self-update.js +77 -0
  890. package/dist/utils/windows-self-update.js.map +1 -0
  891. package/docs/compaction.md +408 -0
  892. package/docs/custom-provider.md +714 -0
  893. package/docs/daemon-architecture.md +399 -0
  894. package/docs/daemon.md +110 -0
  895. package/docs/development.md +72 -0
  896. package/docs/docs.json +164 -0
  897. package/docs/extensions.md +2745 -0
  898. package/docs/hooks.md +85 -0
  899. package/docs/images/doom-extension.png +0 -0
  900. package/docs/images/exy.png +0 -0
  901. package/docs/images/interactive-mode.png +0 -0
  902. package/docs/images/tree-view.png +0 -0
  903. package/docs/index.md +81 -0
  904. package/docs/json.md +89 -0
  905. package/docs/keybindings.md +230 -0
  906. package/docs/lsp.md +499 -0
  907. package/docs/migrating-to-grip.md +18 -0
  908. package/docs/models.md +496 -0
  909. package/docs/packages.md +228 -0
  910. package/docs/prompt-templates.md +88 -0
  911. package/docs/providers.md +251 -0
  912. package/docs/quickstart.md +167 -0
  913. package/docs/rpc.md +1492 -0
  914. package/docs/rules.md +117 -0
  915. package/docs/sandbox.md +181 -0
  916. package/docs/sdk.md +360 -0
  917. package/docs/session-format.md +414 -0
  918. package/docs/sessions.md +137 -0
  919. package/docs/settings.md +371 -0
  920. package/docs/shell-aliases.md +13 -0
  921. package/docs/skills.md +246 -0
  922. package/docs/terminal-setup.md +112 -0
  923. package/docs/termux.md +129 -0
  924. package/docs/themes.md +295 -0
  925. package/docs/tmux.md +61 -0
  926. package/docs/tui.md +918 -0
  927. package/docs/usage.md +304 -0
  928. package/docs/windows.md +17 -0
  929. package/examples/README.md +31 -0
  930. package/examples/daemon-docker/Dockerfile +43 -0
  931. package/examples/daemon-docker/README.md +45 -0
  932. package/examples/extensions/README.md +208 -0
  933. package/examples/extensions/auto-commit-on-exit.ts +46 -0
  934. package/examples/extensions/bash-spawn-hook.ts +30 -0
  935. package/examples/extensions/bookmark.ts +50 -0
  936. package/examples/extensions/border-status-editor.ts +145 -0
  937. package/examples/extensions/built-in-tool-renderer.ts +259 -0
  938. package/examples/extensions/claude-rules.ts +86 -0
  939. package/examples/extensions/commands.ts +82 -0
  940. package/examples/extensions/confirm-destructive.ts +59 -0
  941. package/examples/extensions/custom-compaction.ts +131 -0
  942. package/examples/extensions/custom-footer.ts +79 -0
  943. package/examples/extensions/custom-header.ts +73 -0
  944. package/examples/extensions/custom-provider-anthropic/index.ts +707 -0
  945. package/examples/extensions/custom-provider-anthropic/package-lock.json +24 -0
  946. package/examples/extensions/custom-provider-anthropic/package.json +19 -0
  947. package/examples/extensions/custom-provider-gitlab-duo/index.ts +402 -0
  948. package/examples/extensions/custom-provider-gitlab-duo/package.json +16 -0
  949. package/examples/extensions/custom-provider-gitlab-duo/test.ts +104 -0
  950. package/examples/extensions/dirty-repo-guard.ts +59 -0
  951. package/examples/extensions/doom-overlay/README.md +46 -0
  952. package/examples/extensions/doom-overlay/doom/build/doom.js +21 -0
  953. package/examples/extensions/doom-overlay/doom/build/doom.wasm +0 -0
  954. package/examples/extensions/doom-overlay/doom/build.sh +152 -0
  955. package/examples/extensions/doom-overlay/doom/doomgeneric_pi.c +72 -0
  956. package/examples/extensions/doom-overlay/doom-component.ts +133 -0
  957. package/examples/extensions/doom-overlay/doom-engine.ts +173 -0
  958. package/examples/extensions/doom-overlay/doom-keys.ts +104 -0
  959. package/examples/extensions/doom-overlay/index.ts +74 -0
  960. package/examples/extensions/doom-overlay/wad-finder.ts +51 -0
  961. package/examples/extensions/dynamic-resources/RULES.md +8 -0
  962. package/examples/extensions/dynamic-resources/SKILL.md +8 -0
  963. package/examples/extensions/dynamic-resources/dynamic.json +79 -0
  964. package/examples/extensions/dynamic-resources/dynamic.md +5 -0
  965. package/examples/extensions/dynamic-resources/index.ts +16 -0
  966. package/examples/extensions/dynamic-tools.ts +74 -0
  967. package/examples/extensions/event-bus.ts +43 -0
  968. package/examples/extensions/file-trigger.ts +41 -0
  969. package/examples/extensions/git-checkpoint.ts +53 -0
  970. package/examples/extensions/git-merge-and-resolve.ts +125 -0
  971. package/examples/extensions/github-issue-autocomplete.ts +191 -0
  972. package/examples/extensions/handoff.ts +191 -0
  973. package/examples/extensions/hello.ts +26 -0
  974. package/examples/extensions/hidden-thinking-label.ts +53 -0
  975. package/examples/extensions/inline-bash.ts +104 -0
  976. package/examples/extensions/input-transform.ts +43 -0
  977. package/examples/extensions/interactive-shell.ts +194 -0
  978. package/examples/extensions/mac-system-theme.ts +47 -0
  979. package/examples/extensions/message-renderer.ts +59 -0
  980. package/examples/extensions/minimal-mode.ts +428 -0
  981. package/examples/extensions/modal-editor.ts +86 -0
  982. package/examples/extensions/model-status.ts +31 -0
  983. package/examples/extensions/notify.ts +55 -0
  984. package/examples/extensions/overlay-qa-tests.ts +1374 -0
  985. package/examples/extensions/overlay-test.ts +171 -0
  986. package/examples/extensions/permission-gate.ts +34 -0
  987. package/examples/extensions/pirate.ts +47 -0
  988. package/examples/extensions/plan-mode/README.md +65 -0
  989. package/examples/extensions/plan-mode/index.ts +346 -0
  990. package/examples/extensions/plan-mode/utils.ts +172 -0
  991. package/examples/extensions/preset.ts +426 -0
  992. package/examples/extensions/prompt-customizer.ts +97 -0
  993. package/examples/extensions/protected-paths.ts +29 -0
  994. package/examples/extensions/provider-payload.ts +18 -0
  995. package/examples/extensions/qna.ts +125 -0
  996. package/examples/extensions/question.ts +294 -0
  997. package/examples/extensions/questionnaire.ts +459 -0
  998. package/examples/extensions/rainbow-editor.ts +88 -0
  999. package/examples/extensions/reload-runtime.ts +37 -0
  1000. package/examples/extensions/rpc-demo.ts +118 -0
  1001. package/examples/extensions/sandbox/index.ts +320 -0
  1002. package/examples/extensions/sandbox/package-lock.json +92 -0
  1003. package/examples/extensions/sandbox/package.json +19 -0
  1004. package/examples/extensions/send-user-message.ts +97 -0
  1005. package/examples/extensions/session-name.ts +27 -0
  1006. package/examples/extensions/shutdown-command.ts +63 -0
  1007. package/examples/extensions/snake.ts +381 -0
  1008. package/examples/extensions/space-invaders.ts +597 -0
  1009. package/examples/extensions/status-line.ts +32 -0
  1010. package/examples/extensions/structured-output.ts +65 -0
  1011. package/examples/extensions/subagent/README.md +175 -0
  1012. package/examples/extensions/subagent/agents/planner.md +37 -0
  1013. package/examples/extensions/subagent/agents/reviewer.md +35 -0
  1014. package/examples/extensions/subagent/agents/scout.md +50 -0
  1015. package/examples/extensions/subagent/agents/worker.md +24 -0
  1016. package/examples/extensions/subagent/agents.ts +126 -0
  1017. package/examples/extensions/subagent/index.ts +1083 -0
  1018. package/examples/extensions/subagent/prompts/implement-and-review.md +10 -0
  1019. package/examples/extensions/subagent/prompts/implement.md +10 -0
  1020. package/examples/extensions/subagent/prompts/scout-and-plan.md +9 -0
  1021. package/examples/extensions/summarize.ts +186 -0
  1022. package/examples/extensions/system-prompt-header.ts +17 -0
  1023. package/examples/extensions/tic-tac-toe.ts +1091 -0
  1024. package/examples/extensions/timed-confirm.ts +70 -0
  1025. package/examples/extensions/titlebar-spinner.ts +58 -0
  1026. package/examples/extensions/todo.ts +306 -0
  1027. package/examples/extensions/tool-override.ts +144 -0
  1028. package/examples/extensions/tools.ts +141 -0
  1029. package/examples/extensions/trigger-compact.ts +50 -0
  1030. package/examples/extensions/truncated-tool.ts +200 -0
  1031. package/examples/extensions/widget-placement.ts +9 -0
  1032. package/examples/extensions/with-deps/index.ts +32 -0
  1033. package/examples/extensions/with-deps/package-lock.json +31 -0
  1034. package/examples/extensions/with-deps/package.json +22 -0
  1035. package/examples/extensions/working-indicator.ts +123 -0
  1036. package/examples/extensions/working-message-test.ts +25 -0
  1037. package/examples/remote-session-server/README.md +71 -0
  1038. package/examples/remote-session-server/server.ts +353 -0
  1039. package/examples/rpc-extension-ui.ts +642 -0
  1040. package/examples/sandbox-docker/Dockerfile +274 -0
  1041. package/examples/sandbox-docker/README.md +88 -0
  1042. package/examples/sdk/01-minimal.ts +27 -0
  1043. package/examples/sdk/02-custom-model.ts +54 -0
  1044. package/examples/sdk/03-custom-prompt.ts +76 -0
  1045. package/examples/sdk/04-skills.ts +60 -0
  1046. package/examples/sdk/05-tools.ts +55 -0
  1047. package/examples/sdk/06-extensions.ts +94 -0
  1048. package/examples/sdk/07-context-files.ts +47 -0
  1049. package/examples/sdk/08-prompt-templates.ts +56 -0
  1050. package/examples/sdk/09-api-keys-and-oauth.ts +50 -0
  1051. package/examples/sdk/10-settings.ts +58 -0
  1052. package/examples/sdk/11-sessions.ts +54 -0
  1053. package/examples/sdk/12-full-control.ts +79 -0
  1054. package/examples/sdk/13-session-runtime.ts +49 -0
  1055. package/examples/sdk/README.md +94 -0
  1056. package/npm-shrinkwrap.json +1878 -0
  1057. package/package.json +102 -5
@@ -0,0 +1,2745 @@
1
+ > Grip can create extensions. Ask it to build one for your use case.
2
+
3
+ # Extensions
4
+
5
+ Extensions are TypeScript modules that extend Grip's behavior. They can subscribe to lifecycle events, register custom tools callable by the LLM, add commands, and more.
6
+
7
+ > **Placement for /reload:** Put extensions in `~/.grip/agent/extensions/` (global) or `.grip/extensions/` (project-local) for auto-discovery. Use `grip -e ./path.ts` only for quick tests. Extensions in auto-discovered locations can be hot-reloaded with `/reload`.
8
+
9
+ **Key capabilities:**
10
+ - **Custom tools** - Register tools the LLM can call via `pi.registerTool()`
11
+ - **Event interception** - Block or modify tool calls, inject context, customize compaction
12
+ - **User interaction** - Prompt users via `ctx.ui` (select, confirm, input, notify)
13
+ - **Custom UI components** - Full TUI components with keyboard input via `ctx.ui.custom()` for complex interactions
14
+ - **Custom commands** - Register commands like `/mycommand` via `pi.registerCommand()`
15
+ - **Session persistence** - Store state that survives restarts via `pi.appendEntry()`
16
+ - **Custom rendering** - Control how tool calls/results and messages appear in TUI
17
+ - **Markdown transformation** - Transform interactive user and assistant Markdown before terminal rendering
18
+ **Example use cases:**
19
+ - Permission gates (confirm before `rm -rf`, `sudo`, etc.)
20
+ - Git checkpointing (stash at each turn, restore on branch)
21
+ - Path protection (block writes to `.env`, `node_modules/`)
22
+ - Custom compaction (summarize conversation your way)
23
+ - Conversation summaries (see `summarize.ts` example)
24
+ - Interactive tools (questions, wizards, custom dialogs)
25
+ - Stateful tools (todo lists, connection pools)
26
+ - External integrations (file watchers, webhooks, CI triggers)
27
+ - Games while you wait (see `snake.ts` example)
28
+
29
+ See [examples/extensions/](../examples/extensions/) for working implementations.
30
+
31
+ ## Table of Contents
32
+
33
+ - [Quick Start](#quick-start)
34
+ - [Extension Locations](#extension-locations)
35
+ - [Available Imports](#available-imports)
36
+ - [Writing an Extension](#writing-an-extension)
37
+ - [Extension Styles](#extension-styles)
38
+ - [Events](#events)
39
+ - [Lifecycle Overview](#lifecycle-overview)
40
+ - [Resource Events](#resource-events)
41
+ - [Session Events](#session-events)
42
+ - [Agent Events](#agent-events)
43
+ - [Model Events](#model-events)
44
+ - [Tool Events](#tool-events)
45
+ - [ExtensionContext](#extensioncontext)
46
+ - [LSP runtime](#ctxgetlspstatus--ctxconfigurelsp)
47
+ - [ExtensionCommandContext](#extensioncommandcontext)
48
+ - [ExtensionAPI Methods](#extensionapi-methods)
49
+ - [State Management](#state-management)
50
+ - [Custom Tools](#custom-tools)
51
+ - [Custom UI](#custom-ui)
52
+ - [Error Handling](#error-handling)
53
+ - [Mode Behavior](#mode-behavior)
54
+ - [Examples Reference](#examples-reference)
55
+
56
+ ## Quick Start
57
+
58
+ Create `~/.grip/agent/extensions/my-extension.ts`:
59
+
60
+ ```typescript
61
+ import type { ExtensionAPI } from "@greppleai/grip";
62
+ import { Type } from "typebox";
63
+
64
+ export default function (pi: ExtensionAPI) {
65
+ // React to events
66
+ pi.on("session_start", async (_event, ctx) => {
67
+ ctx.ui.notify("Extension loaded!", "info");
68
+ });
69
+
70
+ pi.on("tool_call", async (event, ctx) => {
71
+ if (event.toolName === "bash" && event.input.command?.includes("rm -rf")) {
72
+ const ok = await ctx.ui.confirm("Dangerous!", "Allow rm -rf?");
73
+ if (!ok) return { block: true, reason: "Blocked by user" };
74
+ }
75
+ });
76
+
77
+ // Register a custom tool
78
+ pi.registerTool({
79
+ name: "greet",
80
+ label: "Greet",
81
+ description: "Greet someone by name",
82
+ parameters: Type.Object({
83
+ name: Type.String({ description: "Name to greet" }),
84
+ }),
85
+ async execute(toolCallId, params, signal, onUpdate, ctx) {
86
+ return {
87
+ content: [{ type: "text", text: `Hello, ${params.name}!` }],
88
+ details: {},
89
+ };
90
+ },
91
+ });
92
+
93
+ // Register a command
94
+ pi.registerCommand("hello", {
95
+ description: "Say hello",
96
+ handler: async (args, ctx) => {
97
+ ctx.ui.notify(`Hello ${args || "world"}!`, "info");
98
+ },
99
+ });
100
+ }
101
+ ```
102
+
103
+ Test with `--extension` (or `-e`) flag:
104
+
105
+ ```bash
106
+ grip -e ./my-extension.ts
107
+ ```
108
+
109
+ ## Extension Locations
110
+
111
+ > **Security:** Extensions run with your full system permissions and can execute arbitrary code. Only install from sources you trust.
112
+
113
+ Extensions are auto-discovered from:
114
+
115
+ | Location | Scope |
116
+ |----------|-------|
117
+ | `~/.grip/agent/extensions/*.ts` | Global (all projects) |
118
+ | `~/.grip/agent/extensions/*/index.ts` | Global (subdirectory) |
119
+ | `.grip/extensions/*.ts` | Project-local |
120
+ | `.grip/extensions/*/index.ts` | Project-local (subdirectory) |
121
+
122
+ Additional paths via `settings.json`:
123
+
124
+ ```json
125
+ {
126
+ "packages": [
127
+ "npm:@foo/bar@1.0.0",
128
+ "git:github.com/user/repo@v1"
129
+ ],
130
+ "extensions": [
131
+ "/path/to/local/extension.ts",
132
+ "/path/to/local/extension/dir"
133
+ ]
134
+ }
135
+ ```
136
+
137
+ To share extensions via npm or git as Grip packages, see [packages.md](packages.md).
138
+
139
+ ## Available Imports
140
+
141
+ | Package | Purpose |
142
+ |---------|---------|
143
+ | `@greppleai/grip` | Extension types (`ExtensionAPI`, `ExtensionContext`, events) |
144
+ | `typebox` | Schema definitions for tool parameters |
145
+ | `@greppleai/grip-ai` | AI utilities (`StringEnum` for Google-compatible enums) |
146
+ | `@greppleai/grip-tui` | TUI components for custom rendering |
147
+
148
+ npm dependencies work too. Add a `package.json` next to your extension (or in a parent directory), run `npm install`, and imports from `node_modules/` are resolved automatically.
149
+
150
+ For distributed Grip packages installed with `grip install` (npm or git), runtime deps must be in `dependencies`. Package installation uses production installs (`npm install --omit=dev`) by default, so `devDependencies` are not available at runtime; when `npmCommand` is configured, git packages use plain `install` for compatibility with wrappers.
151
+
152
+ Node.js built-ins (`node:fs`, `node:path`, etc.) are also available.
153
+
154
+ ## Writing an Extension
155
+
156
+ An extension exports a default factory function that receives `ExtensionAPI`. The factory can be synchronous or asynchronous:
157
+
158
+ ```typescript
159
+ import type { ExtensionAPI } from "@greppleai/grip";
160
+
161
+ export default function (pi: ExtensionAPI) {
162
+ // Subscribe to events
163
+ pi.on("event_name", async (event, ctx) => {
164
+ // ctx.ui for user interaction
165
+ const ok = await ctx.ui.confirm("Title", "Are you sure?");
166
+ ctx.ui.notify("Done!", "info");
167
+ ctx.ui.setStatus("my-ext", "Processing..."); // Footer status
168
+ ctx.ui.setWidget("my-ext", ["Line 1", "Line 2"]); // Widget above editor (default)
169
+ });
170
+
171
+ // Register tools, commands, shortcuts, flags
172
+ pi.registerTool({ ... });
173
+ pi.registerCommand("name", { ... });
174
+ pi.registerShortcut("ctrl+x", { ... });
175
+ pi.registerFlag("my-flag", { ... });
176
+ }
177
+ ```
178
+
179
+ Extensions are loaded via [jiti](https://github.com/unjs/jiti), so TypeScript works without compilation.
180
+
181
+ If the factory returns a `Promise`, Grip awaits it before continuing startup. That means async initialization completes before `session_start`, before `resources_discover`, and before provider registrations queued via `pi.registerProvider()` are flushed.
182
+
183
+ ### Async factory functions
184
+
185
+ Use an async factory for one-time startup work such as fetching remote configuration or dynamically discovering available models.
186
+
187
+ ```typescript
188
+ import type { ExtensionAPI } from "@greppleai/grip";
189
+
190
+ export default async function (pi: ExtensionAPI) {
191
+ const response = await fetch("http://localhost:1234/v1/models");
192
+ const payload = (await response.json()) as {
193
+ data: Array<{
194
+ id: string;
195
+ name?: string;
196
+ context_window?: number;
197
+ max_tokens?: number;
198
+ }>;
199
+ };
200
+
201
+ pi.registerProvider("local-openai", {
202
+ baseUrl: "http://localhost:1234/v1",
203
+ apiKey: "$LOCAL_OPENAI_API_KEY",
204
+ api: "openai-completions",
205
+ models: payload.data.map((model) => ({
206
+ id: model.id,
207
+ name: model.name ?? model.id,
208
+ reasoning: false,
209
+ input: ["text"],
210
+ cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
211
+ contextWindow: model.context_window ?? 128000,
212
+ maxTokens: model.max_tokens ?? 4096,
213
+ })),
214
+ });
215
+ }
216
+ ```
217
+
218
+ This pattern makes the fetched models available during normal startup and to `grip --list-models`.
219
+
220
+ ### Extension Styles
221
+
222
+ **Single file** - simplest, for small extensions:
223
+
224
+ ```
225
+ ~/.grip/agent/extensions/
226
+ └── my-extension.ts
227
+ ```
228
+
229
+ **Directory with index.ts** - for multi-file extensions:
230
+
231
+ ```
232
+ ~/.grip/agent/extensions/
233
+ └── my-extension/
234
+ ├── index.ts # Entry point (exports default function)
235
+ ├── tools.ts # Helper module
236
+ └── utils.ts # Helper module
237
+ ```
238
+
239
+ **Package with dependencies** - for extensions that need npm packages:
240
+
241
+ ```
242
+ ~/.grip/agent/extensions/
243
+ └── my-extension/
244
+ ├── package.json # Declares dependencies and entry points
245
+ ├── package-lock.json
246
+ ├── node_modules/ # After npm install
247
+ └── src/
248
+ └── index.ts
249
+ ```
250
+
251
+ ```json
252
+ // package.json
253
+ {
254
+ "name": "my-extension",
255
+ "dependencies": {
256
+ "zod": "^3.0.0",
257
+ "chalk": "^5.0.0"
258
+ },
259
+ "grip": {
260
+ "extensions": ["./src/index.ts"]
261
+ }
262
+ }
263
+ ```
264
+
265
+ Run `npm install` in the extension directory, then imports from `node_modules/` work automatically.
266
+
267
+ ## Events
268
+
269
+ ### Lifecycle Overview
270
+
271
+ ```
272
+ grip starts
273
+ │
274
+ ├─► session_start { reason: "startup" }
275
+ └─► resources_discover { reason: "startup" }
276
+ │
277
+ ▼
278
+ user sends prompt ─────────────────────────────────────────┐
279
+ │ │
280
+ ├─► (extension commands checked first, bypass if found) │
281
+ ├─► input (can intercept, transform, or handle) │
282
+ ├─► (skill/template expansion if not handled) │
283
+ ├─► before_agent_start (can inject message, modify system prompt)
284
+ ├─► agent_start │
285
+ ├─► message_start / message_update / message_end │
286
+ │ │
287
+ │ ┌─── turn (repeats while LLM calls tools) ───┐ │
288
+ │ │ │ │
289
+ │ ├─► turn_start │ │
290
+ │ ├─► context (can modify messages) │ │
291
+ │ ├─► before_provider_headers (can mutate model-provider headers)
292
+ │ ├─► before_provider_request (can inspect or replace payload)
293
+ │ ├─► after_provider_response (status + headers, before stream consume)
294
+ │ │ │ │
295
+ │ │ LLM responds, may call tools: │ │
296
+ │ │ ├─► tool_execution_start │ │
297
+ │ │ ├─► tool_call (can block) │ │
298
+ │ │ ├─► tool_execution_update │ │
299
+ │ │ ├─► tool_result (can modify) │ │
300
+ │ │ └─► tool_execution_end │ │
301
+ │ │ │ │
302
+ │ └─► turn_end │ │
303
+ │ │
304
+ ├─► agent_end (one low-level run; may retry/compact/continue) │
305
+ └─► agent_settled (no automatic continuation remains) │
306
+ │
307
+ user sends another prompt ◄─────────────────────────────────┘
308
+
309
+ /new (new session) or /resume (switch session)
310
+ ├─► session_before_switch (can cancel)
311
+ ├─► session_shutdown
312
+ ├─► session_start { reason: "new" | "resume", previousSessionReference? }
313
+ └─► resources_discover { reason: "startup" }
314
+
315
+ /fork or /clone
316
+ ├─► session_before_fork (can cancel)
317
+ ├─► session_shutdown
318
+ ├─► session_start { reason: "fork", previousSessionReference }
319
+ └─► resources_discover { reason: "startup" }
320
+
321
+ /compact or auto-compaction
322
+ ├─► session_before_compact (can cancel or customize)
323
+ └─► session_compact
324
+
325
+ /tree navigation
326
+ ├─► session_before_tree (can cancel or customize)
327
+ └─► session_tree
328
+
329
+ /model or Ctrl+P (model selection/cycling)
330
+ ├─► thinking_level_select (if model change changes/clamps thinking level)
331
+ └─► model_select
332
+
333
+ thinking level changes (settings, keybinding, pi.setThinkingLevel())
334
+ └─► thinking_level_select
335
+
336
+ exit (Ctrl+C, Ctrl+D, SIGHUP, SIGTERM)
337
+ └─► session_shutdown
338
+ ```
339
+
340
+ ### Resource Events
341
+
342
+ #### resources_discover
343
+
344
+ Fired after `session_start` so extensions can contribute additional skill, rule, prompt, and theme paths.
345
+ The startup path uses `reason: "startup"`. Reload uses `reason: "reload"`.
346
+
347
+ ```typescript
348
+ pi.on("resources_discover", async (event, _ctx) => {
349
+ // event.cwd - current working directory
350
+ // event.reason - "startup" | "reload"
351
+ return {
352
+ skillPaths: ["/path/to/skills"],
353
+ rulePaths: ["/path/to/rules"],
354
+ promptPaths: ["/path/to/prompts"],
355
+ themePaths: ["/path/to/themes"],
356
+ };
357
+ });
358
+ ```
359
+
360
+ ### Session Events
361
+
362
+ See [Session Format](session-format.md) for session storage internals, active `Session` APIs, and `SessionManager` lifecycle APIs.
363
+
364
+ #### session_start
365
+
366
+ Fired when a session is started, loaded, or reloaded.
367
+
368
+ ```typescript
369
+ pi.on("session_start", async (event, ctx) => {
370
+ // event.reason - "startup" | "reload" | "new" | "resume" | "fork"
371
+ // event.previousSessionReference - present for "new", "resume", and "fork"
372
+ // event.previousSessionFile - deprecated alias for local-file-oriented compatibility
373
+ ctx.ui.notify(`Session: ${ctx.session.getSessionReference() ?? "ephemeral"}`, "info");
374
+ });
375
+ ```
376
+
377
+ #### session_before_switch
378
+
379
+ Fired before starting a new session (`/new`) or switching sessions (`/resume`).
380
+
381
+ ```typescript
382
+ pi.on("session_before_switch", async (event, ctx) => {
383
+ // event.reason - "new" or "resume"
384
+ // event.targetSessionReference - session we're switching to (only for "resume")
385
+ // event.targetSessionFile - deprecated alias for local-file-oriented compatibility
386
+
387
+ if (event.reason === "new") {
388
+ const ok = await ctx.ui.confirm("Clear?", "Delete all messages?");
389
+ if (!ok) return { cancel: true };
390
+ }
391
+ });
392
+ ```
393
+
394
+ After a successful switch or new-session action, Grip emits `session_shutdown` for the old extension instance, reloads and rebinds extensions for the new session, then emits `session_start` with `reason: "new" | "resume"` and `previousSessionReference`.
395
+ Do cleanup work in `session_shutdown`, then reestablish any in-memory state in `session_start`.
396
+
397
+ #### session_before_fork
398
+
399
+ Fired when forking via `/fork` or cloning via `/clone`.
400
+
401
+ ```typescript
402
+ pi.on("session_before_fork", async (event, ctx) => {
403
+ // event.entryId - ID of the selected entry
404
+ // event.position - "before" for /fork, "at" for /clone
405
+ return { cancel: true }; // Cancel fork/clone
406
+ // OR
407
+ return { skipConversationRestore: true }; // Reserved for future conversation restore control
408
+ });
409
+ ```
410
+
411
+ After a successful fork or clone, Grip emits `session_shutdown` for the old extension instance, reloads and rebinds extensions for the new session, then emits `session_start` with `reason: "fork"` and `previousSessionReference`.
412
+ Do cleanup work in `session_shutdown`, then reestablish any in-memory state in `session_start`.
413
+
414
+ #### session_before_compact / session_compact
415
+
416
+ Fired on compaction. See [compaction.md](compaction.md) for details.
417
+
418
+ ```typescript
419
+ pi.on("session_before_compact", async (event, ctx) => {
420
+ const { preparation, branchEntries, customInstructions, signal } = event;
421
+
422
+ // Cancel:
423
+ return { cancel: true };
424
+
425
+ // Custom summary:
426
+ return {
427
+ compaction: {
428
+ summary: "...",
429
+ firstKeptEntryId: preparation.firstKeptEntryId,
430
+ tokensBefore: preparation.tokensBefore,
431
+ }
432
+ };
433
+ });
434
+
435
+ pi.on("session_compact", async (event, ctx) => {
436
+ // event.compactionEntry - the saved compaction
437
+ // event.fromExtension - whether extension provided it
438
+ });
439
+ ```
440
+
441
+ #### session_before_tree / session_tree
442
+
443
+ Fired on `/tree` navigation. See [Sessions](sessions.md) for tree navigation concepts.
444
+
445
+ ```typescript
446
+ pi.on("session_before_tree", async (event, ctx) => {
447
+ const { preparation, signal } = event;
448
+ return { cancel: true };
449
+ // OR provide custom summary:
450
+ return { summary: { summary: "...", details: {} } };
451
+ });
452
+
453
+ pi.on("session_tree", async (event, ctx) => {
454
+ // event.newLeafId, oldLeafId, summaryEntry, fromExtension
455
+ });
456
+ ```
457
+
458
+ #### session_shutdown
459
+
460
+ Fired before an extension runtime is torn down.
461
+
462
+ ```typescript
463
+ pi.on("session_shutdown", async (event, ctx) => {
464
+ // event.reason - "quit" | "reload" | "new" | "resume" | "fork"
465
+ // event.targetSessionReference - destination session for session replacement flows
466
+ // event.targetSessionFile - deprecated alias for local-file-oriented compatibility
467
+ // Cleanup, save state, etc.
468
+ });
469
+ ```
470
+
471
+ ### Agent Events
472
+
473
+ #### before_agent_start
474
+
475
+ Fired after user submits prompt, before agent loop. Can inject a message and/or modify the system prompt.
476
+
477
+ ```typescript
478
+ pi.on("before_agent_start", async (event, ctx) => {
479
+ // event.prompt - user's prompt text
480
+ // event.images - attached images (if any)
481
+ // event.systemPrompt - current chained system prompt for this handler
482
+ // (includes changes from earlier before_agent_start handlers)
483
+ // event.systemPromptOptions - structured options used to build the system prompt
484
+ // .customPrompt - any custom system prompt (from --system-prompt, SYSTEM.md, or custom templates)
485
+ // .selectedTools - tools currently active in the prompt
486
+ // .toolSnippets - one-line descriptions for each tool
487
+ // .promptGuidelines - custom guideline bullets
488
+ // .appendSystemPrompt - text from --append-system-prompt flags
489
+ // .cwd - working directory
490
+ // .contextFiles - AGENTS.md files and other loaded context files
491
+ // .skills - loaded skills
492
+
493
+ return {
494
+ // Inject a persistent message (stored in session, sent to LLM)
495
+ message: {
496
+ customType: "my-extension",
497
+ content: "Additional context for the LLM",
498
+ display: true,
499
+ },
500
+ // Replace the system prompt for this turn (chained across extensions)
501
+ systemPrompt: event.systemPrompt + "\n\nExtra instructions for this turn...",
502
+ };
503
+ });
504
+ ```
505
+
506
+ The `systemPromptOptions` field gives extensions access to the same structured data Grip uses to build the system prompt. This lets you inspect what Grip has loaded — custom prompts, guidelines, tool snippets, context files, skills — without re-discovering resources or re-parsing flags. Use it when your extension needs to make deep, informed changes to the system prompt while respecting user-provided configuration.
507
+
508
+ Inside `before_agent_start`, `event.systemPrompt` and `ctx.getSystemPrompt()` both reflect the chained system prompt as of the current handler. Later `before_agent_start` handlers can still modify it again.
509
+
510
+ #### agent_start / agent_end / agent_settled
511
+
512
+ `agent_start` and `agent_end` describe a low-level Agent run. Grip may still retry, compact, or process queued follow-ups after `agent_end`. `agent_settled` is the AgentSession-level boundary after all automatic continuation and session-owned work has completed.
513
+
514
+ ```typescript
515
+ pi.on("agent_start", async (_event, ctx) => {});
516
+
517
+ pi.on("agent_end", async (event, ctx) => {
518
+ // event.messages - messages from this low-level run
519
+ });
520
+
521
+ pi.on("agent_settled", async (_event, ctx) => {
522
+ // Safe for status integrations that need the full logical-run boundary.
523
+ });
524
+ ```
525
+
526
+ #### turn_start / turn_end
527
+
528
+ Fired for each turn (one LLM response + tool calls).
529
+
530
+ ```typescript
531
+ pi.on("turn_start", async (event, ctx) => {
532
+ // event.turnIndex, event.timestamp
533
+ });
534
+
535
+ pi.on("turn_end", async (event, ctx) => {
536
+ // event.turnIndex, event.message, event.toolResults
537
+ });
538
+ ```
539
+
540
+ #### message_start / message_update / message_end
541
+
542
+ Fired for message lifecycle updates.
543
+
544
+ - `message_start` and `message_end` fire for user, assistant, and toolResult messages.
545
+ - `message_update` fires for assistant streaming updates.
546
+ - `message_end` handlers can return `{ message }` to replace the finalized message. The replacement must keep the same `role`.
547
+
548
+ ```typescript
549
+ pi.on("message_start", async (event, ctx) => {
550
+ // event.message
551
+ });
552
+
553
+ pi.on("message_update", async (event, ctx) => {
554
+ // event.message
555
+ // event.assistantMessageEvent (token-by-token stream event)
556
+ });
557
+
558
+ pi.on("message_end", async (event, ctx) => {
559
+ if (event.message.role !== "assistant") return;
560
+
561
+ return {
562
+ message: {
563
+ ...event.message,
564
+ usage: {
565
+ ...event.message.usage,
566
+ cost: {
567
+ ...event.message.usage.cost,
568
+ total: 0.123,
569
+ },
570
+ },
571
+ },
572
+ };
573
+ });
574
+ ```
575
+
576
+ #### tool_execution_start / tool_execution_update / tool_execution_end
577
+
578
+ Fired for tool execution lifecycle updates.
579
+
580
+ In parallel tool mode:
581
+ - `tool_execution_start` is emitted in assistant source order during the preflight phase
582
+ - `tool_execution_update` events may interleave across tools
583
+ - `tool_execution_end` is emitted in tool completion order after each tool is finalized
584
+ - final `toolResult` message events are still emitted later in assistant source order
585
+
586
+ ```typescript
587
+ pi.on("tool_execution_start", async (event, ctx) => {
588
+ // event.toolCallId, event.toolName, event.args
589
+ });
590
+
591
+ pi.on("tool_execution_update", async (event, ctx) => {
592
+ // event.toolCallId, event.toolName, event.args, event.partialResult
593
+ });
594
+
595
+ pi.on("tool_execution_end", async (event, ctx) => {
596
+ // event.toolCallId, event.toolName, event.result, event.isError
597
+ });
598
+ ```
599
+
600
+ #### context
601
+
602
+ Fired before each LLM call. Modify messages non-destructively. See [Session Format](session-format.md) for message types.
603
+
604
+ ```typescript
605
+ pi.on("context", async (event, ctx) => {
606
+ // event.messages - deep copy, safe to modify
607
+ const filtered = event.messages.filter(m => !shouldPrune(m));
608
+ return { messages: filtered };
609
+ });
610
+ ```
611
+
612
+ #### before_provider_headers
613
+
614
+ Fired after model-provider headers are assembled from attribution, provider/model configuration, and per-request options. Use it to add tracing, session-correlation, or tenant-routing headers, override existing values, or suppress a provider/API default.
615
+
616
+ Handlers share and mutate `event.headers` in extension load order. Set a key to a string to add or override it, or to `null` to delete it. Handler return values are ignored, so returning a replacement object cannot accidentally discard authentication or attribution headers.
617
+
618
+ ```typescript
619
+ pi.on("before_provider_headers", (event, ctx) => {
620
+ event.headers["x-session-id"] = ctx.session.getSessionId();
621
+ event.headers["X-OpenRouter-Title"] = null;
622
+ });
623
+ ```
624
+
625
+ The event contains only headers destined for the model provider. Tool-backend transport state and credentials—including daemon bearer tokens—are never copied into it. A model API key remains a separate stream option unless that model/provider configuration explicitly creates an HTTP header such as `authHeader`.
626
+
627
+ The hook runs once for each coding-agent provider stream invocation. Session-level retries and separate compaction/branch requests invoke it again for their new request; provider-internal retries reuse the already-mutated headers.
628
+
629
+ #### before_provider_request
630
+
631
+ Fired after the provider-specific payload is built, right before the request is sent. Handlers run in extension load order. Returning `undefined` keeps the payload unchanged. Returning any other value replaces the payload for later handlers and for the actual request.
632
+
633
+ This hook can rewrite provider-level system instructions or remove them entirely. Those payload-level changes are not reflected by `ctx.getSystemPrompt()`, which reports Grip's system prompt string rather than the final serialized provider payload.
634
+
635
+ ```typescript
636
+ pi.on("before_provider_request", (event, ctx) => {
637
+ console.log(JSON.stringify(event.payload, null, 2));
638
+
639
+ // Optional: replace payload
640
+ // return { ...event.payload, temperature: 0 };
641
+ });
642
+ ```
643
+
644
+ This is mainly useful for debugging provider serialization and cache behavior.
645
+
646
+ #### after_provider_response
647
+
648
+ Fired after an HTTP response is received and before its stream body is consumed. Handlers run in extension load order.
649
+
650
+ ```typescript
651
+ pi.on("after_provider_response", (event, ctx) => {
652
+ // event.status - HTTP status code
653
+ // event.headers - normalized response headers
654
+ if (event.status === 429) {
655
+ console.log("rate limited", event.headers["retry-after"]);
656
+ }
657
+ });
658
+ ```
659
+
660
+ Header availability depends on provider and transport. Providers that abstract HTTP responses may not expose headers.
661
+
662
+ ### Model Events
663
+
664
+ #### model_select
665
+
666
+ Fired when the model changes via `/model` command, model cycling (`Ctrl+P`), or session restore.
667
+
668
+ ```typescript
669
+ pi.on("model_select", async (event, ctx) => {
670
+ // event.model - newly selected model
671
+ // event.previousModel - previous model (undefined if first selection)
672
+ // event.source - "set" | "cycle" | "restore"
673
+
674
+ const prev = event.previousModel
675
+ ? `${event.previousModel.provider}/${event.previousModel.id}`
676
+ : "none";
677
+ const next = `${event.model.provider}/${event.model.id}`;
678
+
679
+ ctx.ui.notify(`Model changed (${event.source}): ${prev} -> ${next}`, "info");
680
+ });
681
+ ```
682
+
683
+ Use this to update UI elements (status bars, footers) or perform model-specific initialization when the active model changes.
684
+
685
+ #### thinking_level_select
686
+
687
+ Fired when the thinking level changes. This is notification-only; handler return values are ignored.
688
+
689
+ ```typescript
690
+ pi.on("thinking_level_select", async (event, ctx) => {
691
+ // event.level - newly selected thinking level
692
+ // event.previousLevel - previous thinking level
693
+
694
+ ctx.ui.setStatus("thinking", `thinking: ${event.level}`);
695
+ });
696
+ ```
697
+
698
+ Use this to update extension UI when `pi.setThinkingLevel()`, model changes, or built-in thinking-level controls change the active thinking level.
699
+
700
+ ### Tool Events
701
+
702
+ #### tool_call
703
+
704
+ Fired after `tool_execution_start`, before the tool executes. **Can block.** Use `isToolCallEventType` to narrow and get typed inputs.
705
+
706
+ Before `tool_call` runs, Grip waits for previously emitted Agent events to finish draining through `AgentSession`. This means `ctx.session` is up to date through the current assistant tool-calling message.
707
+
708
+ In the default parallel tool execution mode, sibling tool calls from the same assistant message are preflighted sequentially, then executed concurrently. `tool_call` is not guaranteed to see sibling tool results from that same assistant message in `ctx.session`.
709
+
710
+ `event.input` is mutable. Mutate it in place to patch tool arguments before execution.
711
+
712
+ Behavior guarantees:
713
+ - Mutations to `event.input` affect the actual tool execution
714
+ - Later `tool_call` handlers see mutations made by earlier handlers
715
+ - No re-validation is performed after your mutation
716
+ - Return values from `tool_call` control blocking via `{ block: true, reason?: string, terminate?: boolean }`
717
+ - `terminate` only applies to a blocked call; the agent stops early only when every finalized result in the batch is terminating
718
+
719
+ ```typescript
720
+ import { isToolCallEventType } from "@greppleai/grip";
721
+
722
+ pi.on("tool_call", async (event, ctx) => {
723
+ // event.toolName - "bash", "read", "write", "edit", etc.
724
+ // event.toolCallId
725
+ // event.input - tool parameters (mutable)
726
+
727
+ // Built-in tools: no type params needed
728
+ if (isToolCallEventType("bash", event)) {
729
+ // event.input is { command: string; timeout?: number }
730
+ event.input.command = `source ~/.profile\n${event.input.command}`;
731
+
732
+ if (event.input.command.includes("rm -rf")) {
733
+ return { block: true, reason: "Dangerous command", terminate: true };
734
+ }
735
+ }
736
+
737
+ if (isToolCallEventType("read", event)) {
738
+ // event.input is { path: string; offset?: number; limit?: number }
739
+ console.log(`Reading: ${event.input.path}`);
740
+ }
741
+ });
742
+ ```
743
+
744
+ #### Typing custom tool input
745
+
746
+ Custom tools should export their input type:
747
+
748
+ ```typescript
749
+ // my-extension.ts
750
+ export type MyToolInput = Static<typeof myToolSchema>;
751
+ ```
752
+
753
+ Use `isToolCallEventType` with explicit type parameters:
754
+
755
+ ```typescript
756
+ import { isToolCallEventType } from "@greppleai/grip";
757
+ import type { MyToolInput } from "my-extension";
758
+
759
+ pi.on("tool_call", (event) => {
760
+ if (isToolCallEventType<"my_tool", MyToolInput>("my_tool", event)) {
761
+ event.input.action; // typed
762
+ }
763
+ });
764
+ ```
765
+
766
+ #### tool_result
767
+
768
+ Fired after tool execution finishes and before `tool_execution_end` plus the final tool result message events are emitted. **Can modify result.**
769
+
770
+ In parallel tool mode, `tool_result` and `tool_execution_end` may interleave in tool completion order, while final `toolResult` message events are still emitted later in assistant source order.
771
+
772
+ `tool_result` handlers chain like middleware:
773
+ - Handlers run in extension load order
774
+ - Each handler sees the latest result after previous handler changes
775
+ - Handlers can return partial patches (`content`, `details`, or `isError`); omitted fields keep their current values
776
+
777
+ Use `ctx.signal` for nested async work inside the handler. This lets Esc cancel model calls, `fetch()`, and other abort-aware operations started by the extension.
778
+
779
+ ```typescript
780
+ import { isBashToolResult } from "@greppleai/grip";
781
+
782
+ pi.on("tool_result", async (event, ctx) => {
783
+ // event.toolName, event.toolCallId, event.input
784
+ // event.content, event.details, event.isError
785
+
786
+ if (isBashToolResult(event)) {
787
+ // event.details is typed as BashToolDetails
788
+ }
789
+
790
+ const response = await fetch("https://example.com/summarize", {
791
+ method: "POST",
792
+ body: JSON.stringify({ content: event.content }),
793
+ signal: ctx.signal,
794
+ });
795
+
796
+ // Modify result:
797
+ return { content: [...], details: {...}, isError: false };
798
+ });
799
+ ```
800
+
801
+ ### User Bash Events
802
+
803
+ #### user_bash
804
+
805
+ Fired when user executes `!` or `!!` commands. **Can intercept.**
806
+
807
+ ```typescript
808
+ import { createLocalBashOperations } from "@greppleai/grip";
809
+
810
+ pi.on("user_bash", (event, ctx) => {
811
+ // event.command - the bash command
812
+ // event.excludeFromContext - true if !! prefix
813
+ // event.cwd - working directory
814
+
815
+ // Option 1: Provide custom operations (e.g., a service adapter)
816
+ return { operations: remoteBashOps };
817
+
818
+ // Option 2: Wrap Grip's built-in local bash backend
819
+ const local = createLocalBashOperations();
820
+ return {
821
+ operations: {
822
+ exec(command, cwd, options) {
823
+ return local.exec(`source ~/.profile\n${command}`, cwd, options);
824
+ }
825
+ }
826
+ };
827
+
828
+ // Option 3: Full replacement - return result directly
829
+ return { result: { output: "...", exitCode: 0, cancelled: false, truncated: false } };
830
+ });
831
+ ```
832
+
833
+ ### Input Events
834
+
835
+ #### input
836
+
837
+ Fired when user input is received, after extension commands are checked but before skill and template expansion. The event sees the raw input text, so `/skill:foo` and `/template` are not yet expanded.
838
+
839
+ **Processing order:**
840
+ 1. Extension commands (`/cmd`) checked first - if found, handler runs and input event is skipped
841
+ 2. `input` event fires - can intercept, transform, or handle
842
+ 3. If not handled: skill/rule commands (`/skill:name`, `/rule:name`) expanded to their content
843
+ 4. If not handled: prompt templates (`/template`) expanded to template content
844
+ 5. Agent processing begins (`before_agent_start`, etc.)
845
+
846
+ ```typescript
847
+ pi.on("input", async (event, ctx) => {
848
+ // event.text - raw input (before skill/template expansion)
849
+ // event.images - attached images, if any
850
+ // event.source - "interactive" (typed), "rpc" (API), or "extension" (via sendUserMessage)
851
+
852
+ // Transform: rewrite input before expansion
853
+ if (event.text.startsWith("?quick "))
854
+ return { action: "transform", text: `Respond briefly: ${event.text.slice(7)}` };
855
+
856
+ // Handle: respond without LLM (extension shows its own feedback)
857
+ if (event.text === "ping") {
858
+ ctx.ui.notify("pong", "info");
859
+ return { action: "handled" };
860
+ }
861
+
862
+ // Route by source: skip processing for extension-injected messages
863
+ if (event.source === "extension") return { action: "continue" };
864
+
865
+ // Intercept skill/rule commands before expansion
866
+ if (event.text.startsWith("/skill:") || event.text.startsWith("/rule:")) {
867
+ // Could transform, block, or let pass through
868
+ }
869
+
870
+ return { action: "continue" }; // Default: pass through to expansion
871
+ });
872
+ ```
873
+
874
+ **Results:**
875
+ - `continue` - pass through unchanged (default if handler returns nothing)
876
+ - `transform` - modify text/images, then continue to expansion
877
+ - `handled` - skip agent entirely (first handler to return this wins)
878
+
879
+ Transforms chain across handlers. See [input-transform.ts](../examples/extensions/input-transform.ts).
880
+
881
+ ## ExtensionContext
882
+
883
+ All handlers receive `ctx: ExtensionContext`.
884
+
885
+ ### ctx.ui
886
+
887
+ UI methods for user interaction. See [Custom UI](#custom-ui) for full details.
888
+
889
+ ### ctx.hasUI
890
+
891
+ `false` in print mode (`-p`) and JSON mode. `true` in interactive and RPC mode. In RPC mode, dialog methods (`select`, `confirm`, `input`, `editor`) work via the extension UI sub-protocol, and fire-and-forget methods (`notify`, `setStatus`, `setWidget`, `setTitle`, `setEditorText`) emit requests to the client. Some TUI-specific methods are no-ops or return defaults (see [rpc.md](rpc.md#extension-ui-protocol)).
892
+
893
+ ### ctx.cwd
894
+
895
+ Current working directory.
896
+
897
+ ### ctx.toolOperations / ctx.getToolBackendInfo() / ctx.execToolBackend()
898
+
899
+ Backend-aware file and shell operations for extensions. These APIs use the same active backend as Grip's built-in tools: local by default, or a remote daemon when configured.
900
+
901
+ Use these APIs for extension tools and extension-owned automation that reads files, writes files, lists directories, or executes shell commands. This is the only safe way for extension tools to run shell commands because it preserves Grip's active execution boundary. Direct local process APIs (`child_process`, `pi.exec`, shell libraries, etc.) bypass the configured tool backend and will run on the local machine even when Grip tools are remote.
902
+
903
+ ```typescript
904
+ pi.registerTool({
905
+ name: "repo_status",
906
+ label: "Repo status",
907
+ description: "Show git status using the active Grip tool backend",
908
+ parameters: Type.Object({}),
909
+ async execute(_toolCallId, _params, _signal, _onUpdate, ctx) {
910
+ const backend = ctx.getToolBackendInfo();
911
+ const result = await ctx.execToolBackend("git status --short", {
912
+ signal: ctx.signal,
913
+ timeout: 30,
914
+ });
915
+
916
+ return {
917
+ content: [{ type: "text", text: result.output || `(no output from ${backend.type})` }],
918
+ };
919
+ },
920
+ });
921
+ ```
922
+
923
+ `ctx.execToolBackend(command, options)` executes a shell command string through `ctx.toolOperations` and returns `BashResult`:
924
+
925
+ ```typescript
926
+ {
927
+ output: string; // combined stdout/stderr, sanitized and possibly truncated
928
+ exitCode?: number; // undefined when cancelled
929
+ cancelled: boolean;
930
+ truncated: boolean;
931
+ fullOutputPath?: string;
932
+ }
933
+ ```
934
+
935
+ Options:
936
+
937
+ - `cwd` - working directory; defaults to the active backend cwd
938
+ - `signal` - abort signal
939
+ - `timeout` - timeout in seconds
940
+ - `onChunk` - streaming output callback
941
+
942
+ Use `ctx.toolOperations` directly when you need backend-aware file operations such as `readFile`, `writeFile`, `stat`, `readdir`, `glob`, or `grep`.
943
+
944
+ ### ctx.getLspStatus() / ctx.configureLsp()
945
+
946
+ Normal Grip extensions share the single `AgentSession`-owned LSP runtime. Inspect it without creating a parallel manager:
947
+
948
+ ```typescript
949
+ pi.on("session_start", async (_event, ctx) => {
950
+ const status = ctx.getLspStatus();
951
+ console.log(status.owner, status.enabled, status.servers);
952
+
953
+ if (!status.enabled) {
954
+ await ctx.configureLsp({
955
+ servers: [
956
+ {
957
+ id: "attached-typescript",
958
+ selectors: [{ languageId: "typescript", pattern: "**/*.ts" }],
959
+ transport: { type: "tcp", host: "127.0.0.1", port: 2087 },
960
+ lifecycle: { type: "attached" },
961
+ workspace: { type: "session" },
962
+ },
963
+ ],
964
+ });
965
+ }
966
+ });
967
+ ```
968
+
969
+ `getLspStatus()` returns `owner`, the resolved configuration, and per-server/workspace-instance status including lifecycle ownership, shutdown mode, capabilities, diagnostics count, stderr, synchronization errors, and transport/request errors. The current runner observes live AgentSession status. If reload or session replacement supersedes a runner, its `session_shutdown` callback observes the latest LSP configuration and exact manager that runner owned, including successful intermediate `configureLsp()` calls, rather than the replacement or its original bind-time state. `configureLsp()` validates one complete replacement layer, resolves relative paths from `ctx.cwd`, and replaces the current session runtime. Old contexts become stale after reload or session replacement and cannot mutate the replacement runtime. LSP tool cancellation propagates through routing, lazy startup, synchronization, unavailable-reason resolution, and server requests.
970
+
971
+ Do not call `registerLspLifecycleHandlers()` inside `AgentSession`; it is a deprecated alias retained for compatibility. Extension hosts without `AgentSession` should migrate to `registerStandaloneLspLifecycleHandlers()`, which registers one tool set per `ExtensionAPI` and unregisters it if ownership moves to AgentSession. In normal Grip, use the context APIs above. See [Language Server Protocol](lsp.md#extensions-and-status) for status, lifecycle, and migration details.
972
+
973
+ ### ctx.session
974
+
975
+ Read-only access to active session state. See [Session Format](session-format.md) for the full `Session` API and entry types.
976
+
977
+ For `tool_call`, this state is synchronized through the current assistant message before handlers run. In parallel tool execution mode it is still not guaranteed to include sibling tool results from the same assistant message.
978
+
979
+ ```typescript
980
+ ctx.session.getEntries() // All entries
981
+ ctx.session.getBranch() // Current branch
982
+ ctx.session.getLeafId() // Current leaf entry ID
983
+ ```
984
+
985
+ ### ctx.modelRegistry / ctx.model
986
+
987
+ Access to models and API keys.
988
+
989
+ ### ctx.signal
990
+
991
+ The current agent abort signal, or `undefined` when no agent turn is active.
992
+
993
+ Use this for abort-aware nested work started by extension handlers, for example:
994
+ - `fetch(..., { signal: ctx.signal })`
995
+ - model calls that accept `signal`
996
+ - file or process helpers that accept `AbortSignal`
997
+
998
+ `ctx.signal` is typically defined during active turn events such as `tool_call`, `tool_result`, `message_update`, and `turn_end`.
999
+ It is usually `undefined` in idle or non-turn contexts such as session events, extension commands, and shortcuts fired while Grip is idle.
1000
+
1001
+ ```typescript
1002
+ pi.on("tool_result", async (event, ctx) => {
1003
+ const response = await fetch("https://example.com/api", {
1004
+ method: "POST",
1005
+ body: JSON.stringify(event),
1006
+ signal: ctx.signal,
1007
+ });
1008
+
1009
+ const data = await response.json();
1010
+ return { details: data };
1011
+ });
1012
+ ```
1013
+
1014
+ ### ctx.isIdle() / ctx.abort() / ctx.hasPendingMessages()
1015
+
1016
+ `ctx.isIdle()` is true only after Agent work, retries, compaction, queued continuations, pending bash, runtime/LSP synchronization, awaited remote operations, and blocking child subagent calls have settled. It remains false while settled callbacks are being delivered.
1017
+
1018
+ ### ctx.shutdown()
1019
+
1020
+ Request a graceful shutdown of Grip.
1021
+
1022
+ - **Interactive mode:** Deferred until the agent becomes idle (after processing all queued steering and follow-up messages).
1023
+ - **RPC mode:** Deferred until the next idle state (after completing the current command response, when waiting for the next command).
1024
+ - **Print mode:** No-op. The process exits automatically when all prompts are processed.
1025
+
1026
+ Emits `session_shutdown` event to all extensions before exiting. Available in all contexts (event handlers, tools, commands, shortcuts).
1027
+
1028
+ ```typescript
1029
+ pi.on("tool_call", (event, ctx) => {
1030
+ if (isFatal(event.input)) {
1031
+ ctx.shutdown();
1032
+ }
1033
+ });
1034
+ ```
1035
+
1036
+ ### ctx.getContextUsage()
1037
+
1038
+ Returns current context usage for the active model. Uses last assistant usage when available, then estimates tokens for trailing messages.
1039
+
1040
+ ```typescript
1041
+ const usage = ctx.getContextUsage();
1042
+ if (usage && usage.tokens > 100_000) {
1043
+ // ...
1044
+ }
1045
+ ```
1046
+
1047
+ ### ctx.compact()
1048
+
1049
+ Trigger compaction without awaiting completion. Use `onComplete` and `onError` for follow-up actions.
1050
+
1051
+ ```typescript
1052
+ ctx.compact({
1053
+ customInstructions: "Focus on recent changes",
1054
+ onComplete: (result) => {
1055
+ ctx.ui.notify("Compaction completed", "info");
1056
+ },
1057
+ onError: (error) => {
1058
+ ctx.ui.notify(`Compaction failed: ${error.message}`, "error");
1059
+ },
1060
+ });
1061
+ ```
1062
+
1063
+ ### ctx.getSystemPrompt()
1064
+
1065
+ Returns Grip's current system prompt string.
1066
+
1067
+ - During `before_agent_start`, this reflects chained system-prompt changes made so far for the current turn.
1068
+ - It does not include later `context` message mutations.
1069
+ - It does not include `before_provider_request` payload rewrites.
1070
+ - If later-loaded extensions run after yours, they can still change what is ultimately sent.
1071
+
1072
+ ```typescript
1073
+ pi.on("before_agent_start", (event, ctx) => {
1074
+ const prompt = ctx.getSystemPrompt();
1075
+ console.log(`System prompt length: ${prompt.length}`);
1076
+ });
1077
+ ```
1078
+
1079
+ ## ExtensionCommandContext
1080
+
1081
+ Command handlers receive `ExtensionCommandContext`, which extends `ExtensionContext` with session control methods. These are only available in commands because they can deadlock if called from event handlers.
1082
+
1083
+ ### ctx.waitForIdle()
1084
+
1085
+ Wait for the full AgentSession lifecycle to settle, including retries, compaction, queued continuations, pending bash, runtime synchronization, and callback-started work:
1086
+
1087
+ ```typescript
1088
+ pi.registerCommand("my-cmd", {
1089
+ handler: async (args, ctx) => {
1090
+ await ctx.waitForIdle();
1091
+ // Session-owned work and settlement callbacks are complete.
1092
+ },
1093
+ });
1094
+ ```
1095
+
1096
+ Do not await the same session's idle barrier from an event, tool, compaction, lifecycle, or settled callback that is itself part of that barrier. Grip rejects such same-barrier waits instead of deadlocking; start work and return, or schedule the wait after the callback returns.
1097
+
1098
+ ### ctx.newSession(options?)
1099
+
1100
+ Create a new session:
1101
+
1102
+ ```typescript
1103
+ const parentSession = ctx.session.getSessionReference();
1104
+ const kickoff = "Continue in the replacement session";
1105
+
1106
+ const result = await ctx.newSession({
1107
+ parentSession,
1108
+ setup: async (session) => {
1109
+ session.appendMessage({
1110
+ role: "user",
1111
+ content: [{ type: "text", text: "Context from previous session..." }],
1112
+ timestamp: Date.now(),
1113
+ });
1114
+ },
1115
+ withSession: async (ctx) => {
1116
+ // Use only the replacement-session ctx here.
1117
+ await ctx.sendUserMessage(kickoff);
1118
+ },
1119
+ });
1120
+
1121
+ if (result.cancelled) {
1122
+ // An extension cancelled the new session
1123
+ }
1124
+ ```
1125
+
1126
+ Options:
1127
+ - `parentSession`: parent session file to record in the new session header
1128
+ - `setup`: mutate the new active `Session` before `withSession` runs
1129
+ - `withSession`: run post-switch work against a fresh replacement-session context. Do not use captured old `pi` / command `ctx`; see [Session replacement lifecycle and footguns](#session-replacement-lifecycle-and-footguns).
1130
+
1131
+ ### ctx.fork(entryId, options?)
1132
+
1133
+ Fork from a specific entry, creating a new session file:
1134
+
1135
+ ```typescript
1136
+ const result = await ctx.fork("entry-id-123", {
1137
+ withSession: async (ctx) => {
1138
+ // Use only the replacement-session ctx here.
1139
+ ctx.ui.notify("Now in the forked session", "info");
1140
+ },
1141
+ });
1142
+ if (result.cancelled) {
1143
+ // An extension cancelled the fork
1144
+ }
1145
+
1146
+ const cloneResult = await ctx.fork("entry-id-456", { position: "at" });
1147
+ if (cloneResult.cancelled) {
1148
+ // An extension cancelled the clone
1149
+ }
1150
+ ```
1151
+
1152
+ Options:
1153
+ - `position`: `"before"` (default) forks before the selected user message, restoring that prompt into the editor
1154
+ - `position`: `"at"` duplicates the active path through the selected entry without restoring editor text
1155
+ - `withSession`: run post-switch work against a fresh replacement-session context. Do not use captured old `pi` / command `ctx`; see [Session replacement lifecycle and footguns](#session-replacement-lifecycle-and-footguns).
1156
+
1157
+ ### ctx.navigateTree(targetId, options?)
1158
+
1159
+ Navigate to a different point in the session tree:
1160
+
1161
+ ```typescript
1162
+ const result = await ctx.navigateTree("entry-id-456", {
1163
+ summarize: true,
1164
+ customInstructions: "Focus on error handling changes",
1165
+ replaceInstructions: false, // true = replace default prompt entirely
1166
+ label: "review-checkpoint",
1167
+ });
1168
+ ```
1169
+
1170
+ Options:
1171
+ - `summarize`: Whether to generate a summary of the abandoned branch
1172
+ - `customInstructions`: Custom instructions for the summarizer
1173
+ - `replaceInstructions`: If true, `customInstructions` replaces the default prompt instead of being appended
1174
+ - `label`: Label to attach to the branch summary entry (or target entry if not summarizing)
1175
+
1176
+ ### ctx.switchSession(sessionPath, options?)
1177
+
1178
+ Switch to a different session file:
1179
+
1180
+ ```typescript
1181
+ const result = await ctx.switchSession("/path/to/session.jsonl", {
1182
+ withSession: async (ctx) => {
1183
+ await ctx.sendUserMessage("Resume work in the replacement session");
1184
+ },
1185
+ });
1186
+ if (result.cancelled) {
1187
+ // An extension cancelled the switch via session_before_switch
1188
+ }
1189
+ ```
1190
+
1191
+ Options:
1192
+ - `withSession`: run post-switch work against a fresh replacement-session context. Do not use captured old `pi` / command `ctx`; see [Session replacement lifecycle and footguns](#session-replacement-lifecycle-and-footguns).
1193
+
1194
+ To discover available sessions, create a `LocalSessionManager` and call `list()` or `listAll()`:
1195
+
1196
+ ```typescript
1197
+ import { LocalSessionManager } from "@greppleai/grip";
1198
+
1199
+ pi.registerCommand("switch", {
1200
+ description: "Switch to another session",
1201
+ handler: async (args, ctx) => {
1202
+ const sessions = await new LocalSessionManager({ cwd: ctx.cwd }).list();
1203
+ if (sessions.length === 0) return;
1204
+ const choice = await ctx.ui.select(
1205
+ "Pick session:",
1206
+ sessions.map(s => s.reference),
1207
+ );
1208
+ if (choice) {
1209
+ await ctx.switchSession(choice, {
1210
+ withSession: async (ctx) => {
1211
+ ctx.ui.notify("Switched session", "info");
1212
+ },
1213
+ });
1214
+ }
1215
+ },
1216
+ });
1217
+ ```
1218
+
1219
+ ### Session replacement lifecycle and footguns
1220
+
1221
+ `withSession` receives a fresh `ReplacedSessionContext`, which extends `ExtensionCommandContext` with async `sendMessage()` and `sendUserMessage()` helpers bound to the replacement session.
1222
+
1223
+ Lifecycle and footguns:
1224
+ - `withSession` runs only after the old session has emitted `session_shutdown`, the old runtime has been torn down, the replacement session has been rebound, and the new extension instance has already received `session_start`.
1225
+ - The callback still executes in the original closure, not inside the new extension instance. That means your old extension instance may already have run its shutdown cleanup before `withSession` starts.
1226
+ - Captured old `pi` / old command `ctx` session-bound objects are stale after replacement and will throw if used. Use only the `ctx` passed to `withSession` for session-bound work.
1227
+ - Previously extracted raw objects are still your responsibility. For example, if you capture `const oldSession = ctx.session` before replacement, `oldSession` is still the old `Session` object. Do not reuse it after replacement.
1228
+ - Code in `withSession` should assume any state invalidated by your `session_shutdown` handler is already gone. Only capture plain data that survives shutdown cleanly, such as strings, ids, and serialized config.
1229
+
1230
+ Safe pattern:
1231
+
1232
+ ```typescript
1233
+ pi.registerCommand("handoff", {
1234
+ handler: async (_args, ctx) => {
1235
+ const kickoff = "Continue from the replacement session";
1236
+ await ctx.newSession({
1237
+ withSession: async (ctx) => {
1238
+ await ctx.sendUserMessage(kickoff);
1239
+ },
1240
+ });
1241
+ },
1242
+ });
1243
+ ```
1244
+
1245
+ Unsafe pattern:
1246
+
1247
+ ```typescript
1248
+ pi.registerCommand("handoff", {
1249
+ handler: async (_args, ctx) => {
1250
+ const oldSession = ctx.session;
1251
+ await ctx.newSession({
1252
+ withSession: async (_ctx) => {
1253
+ // stale old objects: do not do this
1254
+ oldSession.getSessionReference();
1255
+ pi.sendUserMessage("wrong");
1256
+ },
1257
+ });
1258
+ },
1259
+ });
1260
+ ```
1261
+
1262
+ ### ctx.reload()
1263
+
1264
+ Run the same reload flow as `/reload`.
1265
+
1266
+ ```typescript
1267
+ pi.registerCommand("reload-runtime", {
1268
+ description: "Reload hooks, extensions, skills, rules, prompts, and themes",
1269
+ handler: async (_args, ctx) => {
1270
+ await ctx.reload();
1271
+ return;
1272
+ },
1273
+ });
1274
+ ```
1275
+
1276
+ Important behavior:
1277
+ - `await ctx.reload()` emits `session_shutdown` for the current extension runtime
1278
+ - It refreshes file-backed hook configuration without emitting hook `SessionEnd` or `SessionStart` events, then reloads resources and emits extension `session_start` with `reason: "reload"` and `resources_discover` with reason `"reload"`
1279
+ - The currently running command handler still continues in the old call frame
1280
+ - Code after `await ctx.reload()` still runs from the pre-reload version
1281
+ - Code after `await ctx.reload()` must not assume old in-memory extension state is still valid
1282
+ - After the handler returns, future commands/events/tool calls use the new extension version
1283
+
1284
+ For predictable behavior, treat reload as terminal for that handler (`await ctx.reload(); return;`).
1285
+
1286
+ Tools run with `ExtensionContext`, so they cannot call `ctx.reload()` directly. Use a command as the reload entrypoint, then expose a tool that queues that command as a follow-up user message.
1287
+
1288
+ Example tool the LLM can call to trigger reload:
1289
+
1290
+ ```typescript
1291
+ import type { ExtensionAPI } from "@greppleai/grip";
1292
+ import { Type } from "typebox";
1293
+
1294
+ export default function (pi: ExtensionAPI) {
1295
+ pi.registerCommand("reload-runtime", {
1296
+ description: "Reload hooks, extensions, skills, rules, prompts, and themes",
1297
+ handler: async (_args, ctx) => {
1298
+ await ctx.reload();
1299
+ return;
1300
+ },
1301
+ });
1302
+
1303
+ pi.registerTool({
1304
+ name: "reload_runtime",
1305
+ label: "Reload Runtime",
1306
+ description: "Reload extensions, skills, rules, prompts, and themes",
1307
+ parameters: Type.Object({}),
1308
+ async execute() {
1309
+ pi.sendUserMessage("/reload-runtime", { deliverAs: "followUp" });
1310
+ return {
1311
+ content: [{ type: "text", text: "Queued /reload-runtime as a follow-up command." }],
1312
+ };
1313
+ },
1314
+ });
1315
+ }
1316
+ ```
1317
+
1318
+ ## ExtensionAPI Methods
1319
+
1320
+ ### pi.on(event, handler)
1321
+
1322
+ Subscribe to events. See [Events](#events) for event types and return values.
1323
+
1324
+ ### pi.registerTool(definition)
1325
+
1326
+ Register a custom tool callable by the LLM. See [Custom Tools](#custom-tools) for full details.
1327
+
1328
+ `pi.registerTool()` works both during extension load and after startup. You can call it inside `session_start`, command handlers, or other event handlers. New tools are refreshed immediately in the same session, so they appear in `pi.getAllTools()` and are callable by the LLM without `/reload`.
1329
+
1330
+ Use `pi.setActiveTools()` to enable or disable tools (including dynamically added tools) at runtime.
1331
+
1332
+ Use `promptSnippet` to opt a custom tool into a one-line entry in `Available tools`, and `promptGuidelines` to append tool-specific bullets to the default `Guidelines` section when the tool is active.
1333
+
1334
+ **Important:** `promptGuidelines` bullets are appended flat to the `Guidelines` section with no tool name prefix. Each guideline must name the tool it refers to — avoid "Use this tool when..." because the LLM cannot tell which tool "this" means. Write "Use my_tool when..." instead.
1335
+
1336
+ See [dynamic-tools.ts](../examples/extensions/dynamic-tools.ts) for a full example.
1337
+
1338
+ ```typescript
1339
+ import { Type } from "typebox";
1340
+ import { StringEnum } from "@greppleai/grip-ai";
1341
+
1342
+ pi.registerTool({
1343
+ name: "my_tool",
1344
+ label: "My Tool",
1345
+ description: "What this tool does",
1346
+ promptSnippet: "Summarize or transform text according to action",
1347
+ promptGuidelines: ["Use my_tool when the user asks to summarize previously generated text."],
1348
+ parameters: Type.Object({
1349
+ action: StringEnum(["list", "add"] as const),
1350
+ text: Type.Optional(Type.String()),
1351
+ }),
1352
+ prepareArguments(args) {
1353
+ // Optional compatibility shim. Runs before schema validation.
1354
+ // Return the current schema shape, for example to fold legacy fields
1355
+ // into the modern parameter object.
1356
+ return args;
1357
+ },
1358
+
1359
+ async execute(toolCallId, params, signal, onUpdate, ctx) {
1360
+ // Stream progress
1361
+ onUpdate?.({ content: [{ type: "text", text: "Working..." }] });
1362
+
1363
+ return {
1364
+ content: [{ type: "text", text: "Done" }],
1365
+ details: { result: "..." },
1366
+ };
1367
+ },
1368
+
1369
+ // Optional: Custom rendering
1370
+ renderCall(args, theme, context) { ... },
1371
+ renderResult(result, options, theme, context) { ... },
1372
+ });
1373
+ ```
1374
+
1375
+ ### pi.sendMessage(message, options?)
1376
+
1377
+ Inject a custom message into the session.
1378
+
1379
+ ```typescript
1380
+ pi.sendMessage({
1381
+ customType: "my-extension",
1382
+ content: "Message text",
1383
+ display: true,
1384
+ details: { ... },
1385
+ }, {
1386
+ triggerTurn: true,
1387
+ deliverAs: "steer",
1388
+ });
1389
+ ```
1390
+
1391
+ **Options:**
1392
+ - `deliverAs` - Delivery mode:
1393
+ - `"steer"` (default) - Queues the message while streaming. Delivered after the current assistant turn finishes executing its tool calls, before the next LLM call.
1394
+ - `"followUp"` - Waits for agent to finish. Delivered only when agent has no more tool calls.
1395
+ - `"nextTurn"` - Queued for next user prompt. Does not interrupt or trigger anything.
1396
+ - `triggerTurn: true` - If agent is idle, trigger an LLM response immediately. Only applies to `"steer"` and `"followUp"` modes (ignored for `"nextTurn"`).
1397
+
1398
+ ### pi.sendUserMessage(content, options?)
1399
+
1400
+ Send a user message to the agent. Unlike `sendMessage()` which sends custom messages, this sends an actual user message that appears as if typed by the user. Always triggers a turn.
1401
+
1402
+ ```typescript
1403
+ // Simple text message
1404
+ pi.sendUserMessage("What is 2+2?");
1405
+
1406
+ // With content array (text + images)
1407
+ pi.sendUserMessage([
1408
+ { type: "text", text: "Describe this image:" },
1409
+ { type: "image", source: { type: "base64", mediaType: "image/png", data: "..." } },
1410
+ ]);
1411
+
1412
+ // During streaming - must specify delivery mode
1413
+ pi.sendUserMessage("Focus on error handling", { deliverAs: "steer" });
1414
+ pi.sendUserMessage("And then summarize", { deliverAs: "followUp" });
1415
+ ```
1416
+
1417
+ **Options:**
1418
+ - `deliverAs` - Required when agent is streaming:
1419
+ - `"steer"` - Queues the message for delivery after the current assistant turn finishes executing its tool calls
1420
+ - `"followUp"` - Waits for agent to finish all tools
1421
+
1422
+ When not streaming, the message is sent immediately and triggers a new turn. When streaming without `deliverAs`, throws an error.
1423
+
1424
+ See [send-user-message.ts](../examples/extensions/send-user-message.ts) for a complete example.
1425
+
1426
+ ### pi.appendEntry(customType, data?)
1427
+
1428
+ Persist extension state (does NOT participate in LLM context).
1429
+
1430
+ ```typescript
1431
+ pi.appendEntry("my-state", { count: 42 });
1432
+
1433
+ // Restore on reload
1434
+ pi.on("session_start", async (_event, ctx) => {
1435
+ for (const entry of ctx.session.getEntries()) {
1436
+ if (entry.type === "custom" && entry.customType === "my-state") {
1437
+ // Reconstruct from entry.data
1438
+ }
1439
+ }
1440
+ });
1441
+ ```
1442
+
1443
+ ### pi.setSessionName(name)
1444
+
1445
+ Set the session display name (shown in session selector instead of first message).
1446
+
1447
+ ```typescript
1448
+ pi.setSessionName("Refactor auth module");
1449
+ ```
1450
+
1451
+ ### pi.getSessionName()
1452
+
1453
+ Get the current session name, if set.
1454
+
1455
+ ```typescript
1456
+ const name = pi.getSessionName();
1457
+ if (name) {
1458
+ console.log(`Session: ${name}`);
1459
+ }
1460
+ ```
1461
+
1462
+ ### pi.setLabel(entryId, label)
1463
+
1464
+ Set or clear a label on an entry. Labels are user-defined markers for bookmarking and navigation (shown in `/tree` selector).
1465
+
1466
+ ```typescript
1467
+ // Set a label
1468
+ pi.setLabel(entryId, "checkpoint-before-refactor");
1469
+
1470
+ // Clear a label
1471
+ pi.setLabel(entryId, undefined);
1472
+
1473
+ // Read labels via the active session
1474
+ const label = ctx.session.getLabel(entryId);
1475
+ ```
1476
+
1477
+ Labels persist in the session and survive restarts. Use them to mark important points (turns, checkpoints) in the conversation tree.
1478
+
1479
+ ### pi.registerCommand(name, options)
1480
+
1481
+ Register a command.
1482
+
1483
+ If multiple extensions register the same command name, Grip keeps them all and assigns numeric invocation suffixes in load order, for example `/review:1` and `/review:2`.
1484
+
1485
+ ```typescript
1486
+ pi.registerCommand("stats", {
1487
+ description: "Show session statistics",
1488
+ handler: async (args, ctx) => {
1489
+ const count = ctx.session.getEntries().length;
1490
+ ctx.ui.notify(`${count} entries`, "info");
1491
+ }
1492
+ });
1493
+ ```
1494
+
1495
+ Optional: add argument auto-completion for `/command ...`:
1496
+
1497
+ ```typescript
1498
+ import type { AutocompleteItem } from "@greppleai/grip-tui";
1499
+
1500
+ pi.registerCommand("deploy", {
1501
+ description: "Deploy to an environment",
1502
+ getArgumentCompletions: (prefix: string): AutocompleteItem[] | null => {
1503
+ const envs = ["dev", "staging", "prod"];
1504
+ const items = envs.map((e) => ({ value: e, label: e }));
1505
+ const filtered = items.filter((i) => i.value.startsWith(prefix));
1506
+ return filtered.length > 0 ? filtered : null;
1507
+ },
1508
+ handler: async (args, ctx) => {
1509
+ ctx.ui.notify(`Deploying: ${args}`, "info");
1510
+ },
1511
+ });
1512
+ ```
1513
+
1514
+ ### pi.registerSkill(skill) / pi.registerRule(rule) / pi.registerPrompt(prompt)
1515
+
1516
+ Register local extension-hosted skills, rules, or prompt templates. These stay on the local agent host even when built-in tools use a remote daemon.
1517
+
1518
+ Provide either `filePath` (relative to the extension file directory) or inline `content`. Inline content is available to `/skill:name`, `/rule:name`, and `/prompt-name` expansion.
1519
+
1520
+ ```typescript
1521
+ pi.registerSkill({
1522
+ name: "agent-pod-tools",
1523
+ description: "Use for agent pod maintenance workflows",
1524
+ filePath: "./skills/agent-pod-tools/SKILL.md",
1525
+ });
1526
+
1527
+ pi.registerRule({
1528
+ name: "company-policy",
1529
+ description: "Mandatory policy for release tasks",
1530
+ content: "Only publish after the release checklist is complete.",
1531
+ });
1532
+
1533
+ pi.registerPrompt({
1534
+ name: "release-summary",
1535
+ description: "Draft a release summary",
1536
+ argumentHint: "<version>",
1537
+ content: "Summarize the release changes for $ARGUMENTS.",
1538
+ });
1539
+ ```
1540
+
1541
+ Use `pi.registerPrompts([...])` to register multiple prompt templates at once.
1542
+
1543
+ ### pi.getCommands()
1544
+
1545
+ Get the slash commands available for invocation via `prompt` in the current session. Includes extension commands, prompt templates, skill commands, and rule commands.
1546
+ The list matches the RPC `get_commands` ordering: extensions first, then templates, then skills.
1547
+
1548
+ ```typescript
1549
+ const commands = pi.getCommands();
1550
+ const bySource = commands.filter((command) => command.source === "extension");
1551
+ const userScoped = commands.filter((command) => command.sourceInfo.scope === "user");
1552
+ ```
1553
+
1554
+ Each entry has this shape:
1555
+
1556
+ ```typescript
1557
+ {
1558
+ name: string; // Invokable command name without the leading slash. May be suffixed like "review:1"
1559
+ description?: string;
1560
+ source: "extension" | "prompt" | "skill";
1561
+ sourceInfo: {
1562
+ path: string;
1563
+ source: string;
1564
+ scope: "user" | "project" | "temporary";
1565
+ origin: "package" | "top-level";
1566
+ baseDir?: string;
1567
+ };
1568
+ }
1569
+ ```
1570
+
1571
+ Use `sourceInfo` as the canonical provenance field. Do not infer ownership from command names or from ad hoc path parsing.
1572
+
1573
+ Built-in interactive commands (like `/model` and `/settings`) are not included here. They are handled only in interactive
1574
+ mode and would not execute if sent via `prompt`.
1575
+
1576
+ ### pi.registerMessageRenderer(customType, renderer)
1577
+
1578
+ Register a custom TUI renderer for messages with your `customType`. See [Custom UI](#custom-ui).
1579
+
1580
+ ### pi.registerMarkdownTransformer(transformer)
1581
+
1582
+ Register one synchronous, display-only Markdown transformer for this extension. Registering again replaces that extension's previous transformer.
1583
+
1584
+ ```typescript
1585
+ pi.registerMarkdownTransformer((markdown, context) => {
1586
+ if (context.messageType === "assistant" && !context.isStreaming) {
1587
+ return markdown.replaceAll("TODO", "**TODO**");
1588
+ }
1589
+ return markdown;
1590
+ });
1591
+ ```
1592
+
1593
+ The context contains:
1594
+
1595
+ - `messageType`: `"user"`, `"assistant"`, or `"assistant-thinking"`
1596
+ - `isStreaming`: whether the assistant message is still streaming
1597
+ - `availableWidth`: the exact terminal content width after Markdown horizontal padding
1598
+
1599
+ Transformers run only for ordinary interactive transcript user, assistant, and visible assistant-thinking Markdown, including restored messages and the user portion of skill invocations. They do not mutate messages or affect model context, sessions, custom messages, summaries, print/JSON/RPC output, or HTML export.
1600
+
1601
+ Ordering is fixed: Grip's built-in Mermaid transformer runs first, then extension transformers run in extension load order, then tab normalization, Marked parsing (including LaTeX), and terminal wrapping. Each extension receives the previous transformer's string. Throws and non-string results are ignored without stopping later transformers. Width, streaming/final state, settings, theme, reload, and session changes invalidate or rebuild transcript rendering as needed.
1602
+
1603
+ Captured extension APIs become stale after reload or session replacement; calling `registerMarkdownTransformer()` on a stale API throws under the same lifecycle rules as other registration methods.
1604
+
1605
+ ### pi.registerShortcut(shortcut, options)
1606
+
1607
+ Register a keyboard shortcut. See [keybindings.md](keybindings.md) for the shortcut format and built-in keybindings.
1608
+
1609
+ ```typescript
1610
+ pi.registerShortcut("ctrl+shift+p", {
1611
+ description: "Toggle plan mode",
1612
+ handler: async (ctx) => {
1613
+ ctx.ui.notify("Toggled!");
1614
+ },
1615
+ });
1616
+ ```
1617
+
1618
+ ### pi.registerFlag(name, options)
1619
+
1620
+ Register a CLI flag.
1621
+
1622
+ ```typescript
1623
+ pi.registerFlag("plan", {
1624
+ description: "Start in plan mode",
1625
+ type: "boolean",
1626
+ default: false,
1627
+ });
1628
+
1629
+ // Check value
1630
+ if (pi.getFlag("plan")) {
1631
+ // Plan mode enabled
1632
+ }
1633
+ ```
1634
+
1635
+ ### pi.exec(command, args, options?)
1636
+
1637
+ Execute a local process with argv. This API is local-only and legacy-compatible. It does not use Grip's active tool backend and does not honor remote daemon sandboxing.
1638
+
1639
+ Do not use `pi.exec` from extension tools or backend-sensitive automation. Use `ctx.execToolBackend()` from handlers/tools that receive `ExtensionContext` so shell commands execute in the same local/remote environment as built-in Grip tools.
1640
+
1641
+ ```typescript
1642
+ // Local-only process execution. Avoid for extension tools.
1643
+ const result = await pi.exec("git", ["status"], { signal, timeout: 5000 });
1644
+ // result.stdout, result.stderr, result.code, result.killed
1645
+ ```
1646
+
1647
+ ### pi.getActiveTools() / pi.getAllTools() / pi.setActiveTools(names)
1648
+
1649
+ Manage active tools. This works for both built-in tools and dynamically registered tools.
1650
+
1651
+ ```typescript
1652
+ const active = pi.getActiveTools();
1653
+ const all = pi.getAllTools();
1654
+ // [{
1655
+ // name: "read",
1656
+ // description: "Read file contents...",
1657
+ // parameters: ...,
1658
+ // sourceInfo: { path: "<builtin:read>", source: "builtin", scope: "temporary", origin: "top-level" }
1659
+ // }, ...]
1660
+ const names = all.map(t => t.name);
1661
+ const builtinTools = all.filter((t) => t.sourceInfo.source === "builtin");
1662
+ const extensionTools = all.filter((t) => t.sourceInfo.source !== "builtin" && t.sourceInfo.source !== "sdk");
1663
+ pi.setActiveTools(["read", "bash"]); // Switch to read-only
1664
+ ```
1665
+
1666
+ `pi.getAllTools()` returns `name`, `description`, `parameters`, and `sourceInfo`.
1667
+
1668
+ Typical `sourceInfo.source` values:
1669
+ - `builtin` for built-in tools
1670
+ - `sdk` for tools passed via `GripAgent.create({ customTools })`
1671
+ - extension source metadata for tools registered by extensions
1672
+
1673
+ ### pi.setModel(model)
1674
+
1675
+ Set the current model. Returns `false` if no API key is available for the model. See [models.md](models.md) for configuring custom models.
1676
+
1677
+ ```typescript
1678
+ const model = ctx.modelRegistry.find("anthropic", "claude-sonnet-4-5");
1679
+ if (model) {
1680
+ const success = await pi.setModel(model);
1681
+ if (!success) {
1682
+ ctx.ui.notify("No API key for this model", "error");
1683
+ }
1684
+ }
1685
+ ```
1686
+
1687
+ ### pi.getThinkingLevel() / pi.setThinkingLevel(level)
1688
+
1689
+ Get or set the thinking level. Level is clamped to model capabilities (non-reasoning models always use "off"). Changes emit `thinking_level_select`.
1690
+
1691
+ ```typescript
1692
+ const current = pi.getThinkingLevel(); // "off" | "minimal" | "low" | "medium" | "high" | "xhigh"
1693
+ pi.setThinkingLevel("high");
1694
+ ```
1695
+
1696
+ ### pi.events
1697
+
1698
+ Shared event bus for communication between extensions:
1699
+
1700
+ ```typescript
1701
+ pi.events.on("my:event", (data) => { ... });
1702
+ pi.events.emit("my:event", { ... });
1703
+ ```
1704
+
1705
+ ### pi.registerProvider(name, config)
1706
+
1707
+ Register or override a model provider dynamically. Useful for proxies, custom endpoints, or team-wide model configurations.
1708
+
1709
+ Calls made during the extension factory function are queued and applied once the runner initialises. Calls made after that — for example from a command handler following a user setup flow — take effect immediately without requiring a `/reload`.
1710
+
1711
+ If you need to discover models from a remote endpoint, prefer an async extension factory over deferring the fetch to `session_start`. Grip waits for the factory before startup continues, so the registered models are available immediately, including to `grip --list-models`.
1712
+
1713
+ ```typescript
1714
+ // Register a new provider with custom models
1715
+ pi.registerProvider("my-proxy", {
1716
+ name: "My Proxy",
1717
+ baseUrl: "https://proxy.example.com",
1718
+ apiKey: "$PROXY_API_KEY", // env var reference
1719
+ api: "anthropic-messages",
1720
+ models: [
1721
+ {
1722
+ id: "claude-sonnet-4-20250514",
1723
+ name: "Claude 4 Sonnet (proxy)",
1724
+ reasoning: false,
1725
+ input: ["text", "image"],
1726
+ cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
1727
+ contextWindow: 200000,
1728
+ maxTokens: 16384
1729
+ }
1730
+ ]
1731
+ });
1732
+
1733
+ // Override baseUrl for an existing provider (keeps all models)
1734
+ pi.registerProvider("anthropic", {
1735
+ baseUrl: "https://proxy.example.com"
1736
+ });
1737
+
1738
+ // Register provider with OAuth support for /login
1739
+ pi.registerProvider("corporate-ai", {
1740
+ baseUrl: "https://ai.corp.com",
1741
+ api: "openai-responses",
1742
+ models: [...],
1743
+ oauth: {
1744
+ name: "Corporate AI (SSO)",
1745
+ async login(callbacks) {
1746
+ // Custom OAuth flow
1747
+ callbacks.onAuth({ url: "https://sso.corp.com/..." });
1748
+ const code = await callbacks.onPrompt({ message: "Enter code:" });
1749
+ return { refresh: code, access: code, expires: Date.now() + 3600000 };
1750
+ },
1751
+ async refreshToken(credentials) {
1752
+ // Refresh logic
1753
+ return credentials;
1754
+ },
1755
+ getApiKey(credentials) {
1756
+ return credentials.access;
1757
+ }
1758
+ }
1759
+ });
1760
+ ```
1761
+
1762
+ **Config options:**
1763
+ - `name` - Display name for the provider in UI such as `/login`.
1764
+ - `baseUrl` - API endpoint URL. Required when defining models.
1765
+ - `apiKey` - API key literal, environment interpolation (`$ENV_VAR` or `${ENV_VAR}`), or leading `!command`. Required when defining models (unless `oauth` provided). `$$` escapes `$`, and `$!` escapes a literal `!` without triggering command execution.
1766
+ - `api` - API type: `"anthropic-messages"`, `"openai-completions"`, `"openai-responses"`, etc.
1767
+ - `headers` - Custom headers to include in requests.
1768
+ - `authHeader` - If true, adds `Authorization: Bearer` header automatically.
1769
+ - `models` - Array of model definitions. If provided, replaces all existing models for this provider. Model definitions can set `baseUrl` to override the provider endpoint for that model.
1770
+ - `oauth` - OAuth provider config for `/login` support. When provided, the provider appears in the login menu.
1771
+ - `streamSimple` - Custom streaming implementation for non-standard APIs.
1772
+
1773
+ See [custom-provider.md](custom-provider.md) for advanced topics: custom streaming APIs, OAuth details, model definition reference.
1774
+
1775
+ ### pi.unregisterProvider(name)
1776
+
1777
+ Remove a previously registered provider and its models. Built-in models that were overridden by the provider are restored. Has no effect if the provider was not registered.
1778
+
1779
+ Like `registerProvider`, this takes effect immediately when called after the initial load phase, so a `/reload` is not required.
1780
+
1781
+ ```typescript
1782
+ pi.registerCommand("my-setup-teardown", {
1783
+ description: "Remove the custom proxy provider",
1784
+ handler: async (_args, _ctx) => {
1785
+ pi.unregisterProvider("my-proxy");
1786
+ },
1787
+ });
1788
+ ```
1789
+
1790
+ ## State Management
1791
+
1792
+ Extensions with state should store it in tool result `details` for proper branching support:
1793
+
1794
+ ```typescript
1795
+ export default function (pi: ExtensionAPI) {
1796
+ let items: string[] = [];
1797
+
1798
+ // Reconstruct state from session
1799
+ pi.on("session_start", async (_event, ctx) => {
1800
+ items = [];
1801
+ for (const entry of ctx.session.getBranch()) {
1802
+ if (entry.type === "message" && entry.message.role === "toolResult") {
1803
+ if (entry.message.toolName === "my_tool") {
1804
+ items = entry.message.details?.items ?? [];
1805
+ }
1806
+ }
1807
+ }
1808
+ });
1809
+
1810
+ pi.registerTool({
1811
+ name: "my_tool",
1812
+ // ...
1813
+ async execute(toolCallId, params, signal, onUpdate, ctx) {
1814
+ items.push("new item");
1815
+ return {
1816
+ content: [{ type: "text", text: "Added" }],
1817
+ details: { items: [...items] }, // Store for reconstruction
1818
+ };
1819
+ },
1820
+ });
1821
+ }
1822
+ ```
1823
+
1824
+ ## Custom Tools
1825
+
1826
+ Register tools the LLM can call via `pi.registerTool()`. Tools appear in the system prompt and can have custom rendering.
1827
+
1828
+ Use `promptSnippet` for a short one-line entry in the `Available tools` section in the default system prompt. If omitted, custom tools are left out of that section.
1829
+
1830
+ Use `promptGuidelines` to add tool-specific bullets to the default system prompt `Guidelines` section. These bullets are included only while the tool is active (for example, after `pi.setActiveTools([...])`).
1831
+
1832
+ **Important:** `promptGuidelines` bullets are appended flat to the `Guidelines` section with no tool name prefix or grouping. Each guideline must name the tool it refers to — avoid "Use this tool when..." because the LLM cannot tell which tool "this" means. Write "Use my_tool when..." instead.
1833
+
1834
+ Note: Some models are idiots and include the @ prefix in tool path arguments. Built-in tools strip a leading @ before resolving paths. If your custom tool accepts a path, normalize a leading @ as well.
1835
+
1836
+ If your custom tool mutates files, use `withFileMutationQueue()` so it participates in the same per-file queue as built-in `edit` and `write`. This matters because tool calls run in parallel by default. Without the queue, two tools can read the same old file contents, compute different updates, and then whichever write lands last overwrites the other.
1837
+
1838
+ Example failure case: your custom tool edits `foo.ts` while built-in `edit` also changes `foo.ts` in the same assistant turn. If your tool does not participate in the queue, both can read the original `foo.ts`, apply separate changes, and one of those changes is lost.
1839
+
1840
+ Pass the real target file path to `withFileMutationQueue()`, not the raw user argument. Resolve it to an absolute path first, relative to `ctx.cwd` or your tool's working directory. For existing files, the helper canonicalizes through `realpath()`, so symlink aliases for the same file share one queue. For new files, it falls back to the resolved absolute path because there is nothing to `realpath()` yet.
1841
+
1842
+ Queue the entire mutation window on that target path. That includes read-modify-write logic, not just the final write.
1843
+
1844
+ ```typescript
1845
+ import { withFileMutationQueue } from "@greppleai/grip";
1846
+ import { mkdir, readFile, writeFile } from "node:fs/promises";
1847
+ import { dirname, resolve } from "node:path";
1848
+
1849
+ async execute(_toolCallId, params, _signal, _onUpdate, ctx) {
1850
+ const absolutePath = resolve(ctx.cwd, params.path);
1851
+
1852
+ return withFileMutationQueue(absolutePath, async () => {
1853
+ await mkdir(dirname(absolutePath), { recursive: true });
1854
+ const current = await readFile(absolutePath, "utf8");
1855
+ const next = current.replace(params.oldText, params.newText);
1856
+ await writeFile(absolutePath, next, "utf8");
1857
+
1858
+ return {
1859
+ content: [{ type: "text", text: `Updated ${params.path}` }],
1860
+ details: {},
1861
+ };
1862
+ });
1863
+ }
1864
+ ```
1865
+
1866
+ ### Tool Definition
1867
+
1868
+ ```typescript
1869
+ import { Type } from "typebox";
1870
+ import { StringEnum } from "@greppleai/grip-ai";
1871
+ import { Text } from "@greppleai/grip-tui";
1872
+
1873
+ pi.registerTool({
1874
+ name: "my_tool",
1875
+ label: "My Tool",
1876
+ description: "What this tool does (shown to LLM)",
1877
+ promptSnippet: "List or add items in the project todo list",
1878
+ promptGuidelines: [
1879
+ "Use my_tool for todo planning instead of direct file edits when the user asks for a task list."
1880
+ ],
1881
+ parameters: Type.Object({
1882
+ action: StringEnum(["list", "add"] as const), // Use StringEnum for Google compatibility
1883
+ text: Type.Optional(Type.String()),
1884
+ }),
1885
+ prepareArguments(args) {
1886
+ if (!args || typeof args !== "object") return args;
1887
+ const input = args as { action?: string; oldAction?: string };
1888
+ if (typeof input.oldAction === "string" && input.action === undefined) {
1889
+ return { ...input, action: input.oldAction };
1890
+ }
1891
+ return args;
1892
+ },
1893
+
1894
+ async execute(toolCallId, params, signal, onUpdate, ctx) {
1895
+ // Check for cancellation
1896
+ if (signal?.aborted) {
1897
+ return { content: [{ type: "text", text: "Cancelled" }] };
1898
+ }
1899
+
1900
+ // Stream progress updates
1901
+ onUpdate?.({
1902
+ content: [{ type: "text", text: "Working..." }],
1903
+ details: { progress: 50 },
1904
+ });
1905
+
1906
+ // Run commands through the active Grip tool backend (local or remote daemon)
1907
+ const result = await ctx.execToolBackend("some-command", { signal });
1908
+
1909
+ // Return result
1910
+ return {
1911
+ content: [{ type: "text", text: "Done" }], // Sent to LLM
1912
+ details: { data: result }, // For rendering & state
1913
+ // Optional: stop after this tool batch when every finalized tool result
1914
+ // in the batch also returns terminate: true.
1915
+ terminate: true,
1916
+ };
1917
+ },
1918
+
1919
+ // Optional: Custom rendering
1920
+ renderCall(args, theme, context) { ... },
1921
+ renderResult(result, options, theme, context) { ... },
1922
+ });
1923
+ ```
1924
+
1925
+ **Signaling errors:** To mark a tool execution as failed (sets `isError: true` on the result and reports it to the LLM), throw an error from `execute`. Returning a value never sets the error flag regardless of what properties you include in the return object.
1926
+
1927
+ **Early termination:** Return `terminate: true` from `execute()` to hint that the automatic follow-up LLM call should be skipped after the current tool batch. This only takes effect when every finalized tool result in that batch is terminating. See [examples/extensions/structured-output.ts](../examples/extensions/structured-output.ts) for a minimal example where the agent ends on a final structured-output tool call.
1928
+
1929
+ ```typescript
1930
+ // Correct: throw to signal an error
1931
+ async execute(toolCallId, params) {
1932
+ if (!isValid(params.input)) {
1933
+ throw new Error(`Invalid input: ${params.input}`);
1934
+ }
1935
+ return { content: [{ type: "text", text: "OK" }], details: {} };
1936
+ }
1937
+ ```
1938
+
1939
+ **Important:** Use `StringEnum` from `@greppleai/grip-ai` for string enums. `Type.Union`/`Type.Literal` doesn't work with Google's API.
1940
+
1941
+ **Argument preparation:** `prepareArguments(args)` is optional. If defined, it runs before schema validation and before `execute()`. Use it to mimic an older accepted input shape when Grip resumes an older session whose stored tool call arguments no longer match the current schema. Return the object you want validated against `parameters`. Keep the public schema strict. Do not add deprecated compatibility fields to `parameters` just to keep old resumed sessions working.
1942
+
1943
+ Example: an older session may contain an `edit` tool call with top-level `oldText` and `newText`, while the current schema only accepts `edits: [{ oldText, newText }]`.
1944
+
1945
+ ```typescript
1946
+ pi.registerTool({
1947
+ name: "edit",
1948
+ label: "Edit",
1949
+ description: "Edit a single file using exact text replacement",
1950
+ parameters: Type.Object({
1951
+ path: Type.String(),
1952
+ edits: Type.Array(
1953
+ Type.Object({
1954
+ oldText: Type.String(),
1955
+ newText: Type.String(),
1956
+ }),
1957
+ ),
1958
+ }),
1959
+ prepareArguments(args) {
1960
+ if (!args || typeof args !== "object") return args;
1961
+
1962
+ const input = args as {
1963
+ path?: string;
1964
+ edits?: Array<{ oldText: string; newText: string }>;
1965
+ oldText?: unknown;
1966
+ newText?: unknown;
1967
+ };
1968
+
1969
+ if (typeof input.oldText !== "string" || typeof input.newText !== "string") {
1970
+ return args;
1971
+ }
1972
+
1973
+ return {
1974
+ ...input,
1975
+ edits: [...(input.edits ?? []), { oldText: input.oldText, newText: input.newText }],
1976
+ };
1977
+ },
1978
+ async execute(toolCallId, params, signal, onUpdate, ctx) {
1979
+ // params now matches the current schema
1980
+ return {
1981
+ content: [{ type: "text", text: `Applying ${params.edits.length} edit block(s)` }],
1982
+ details: {},
1983
+ };
1984
+ },
1985
+ });
1986
+ ```
1987
+
1988
+ ### Overriding Built-in Tools
1989
+
1990
+ Extensions can override built-in tools (`read`, `bash`, `edit`, `write`, `grep`, `find`, `ls`, `websearch`, `session_search`, `session_entry_get`, `subagent`, `subagent_runs`, `create_subagent`, and `lsp_*`) by registering a tool with the same name. Interactive mode displays a warning when this happens.
1991
+
1992
+ ```bash
1993
+ # Extension's read tool replaces built-in read
1994
+ grip -e ./tool-override.ts
1995
+ ```
1996
+
1997
+ Alternatively, use `--no-builtin-tools` to start without any built-in tools while keeping extension tools enabled:
1998
+ ```bash
1999
+ # No built-in tools, only extension tools
2000
+ grip --no-builtin-tools -e ./my-extension.ts
2001
+ ```
2002
+
2003
+ See [examples/extensions/tool-override.ts](../examples/extensions/tool-override.ts) for a complete example that overrides `read` with logging and access control.
2004
+
2005
+ **Rendering:** Built-in renderer inheritance is resolved per slot. Execution override and rendering override are independent. If your override omits `renderCall`, the built-in `renderCall` is used. If your override omits `renderResult`, the built-in `renderResult` is used. If your override omits both, the built-in renderer is used automatically (syntax highlighting, diffs, etc.). This lets you wrap built-in tools for logging or access control without reimplementing the UI.
2006
+
2007
+ **Prompt metadata:** `promptSnippet` and `promptGuidelines` are not inherited from the built-in tool. If your override should keep those prompt instructions, define them on the override explicitly.
2008
+
2009
+ **Your implementation must match the exact result shape**, including the `details` type. The UI and session logic depend on these shapes for rendering and state tracking.
2010
+
2011
+ Built-in tool implementations:
2012
+ - [read.ts](../src/core/tools/read.ts) - `ReadToolDetails`
2013
+ - [bash.ts](../src/core/tools/bash.ts) - `BashToolDetails`
2014
+ - [edit.ts](../src/core/tools/edit.ts)
2015
+ - [write.ts](../src/core/tools/write.ts)
2016
+ - [grep.ts](../src/core/tools/grep.ts) - `GrepToolDetails`
2017
+ - [find.ts](../src/core/tools/find.ts) - `FindToolDetails`
2018
+ - [ls.ts](../src/core/tools/ls.ts) - `LsToolDetails`
2019
+ - [session-history.ts](../src/core/tools/session-history.ts) - `SessionSearchToolDetails`, `SessionEntryGetToolDetails`
2020
+
2021
+ ### Remote Execution
2022
+
2023
+ Built-in tools use `ToolOperations`, allowing SDK hosts to provide custom local or remote implementations. Grip's built-in remote implementation connects to `grip --daemon`:
2024
+
2025
+ ```typescript
2026
+ import { createRemoteToolOperations } from "@greppleai/grip";
2027
+
2028
+ const operations = await createRemoteToolOperations("ws://127.0.0.1:8787/grip/workspace", {
2029
+ token: process.env.GRIP_REMOTE_TOKEN,
2030
+ });
2031
+ ```
2032
+
2033
+ **Operations interfaces:** `ReadOperations`, `WriteOperations`, `EditOperations`, `BashOperations`, `LsOperations`, `GrepOperations`, `FindOperations`
2034
+
2035
+ For `user_bash`, extensions can reuse Grip's local shell backend via `createLocalBashOperations()` instead of reimplementing local process spawning, shell resolution, and process-tree termination.
2036
+
2037
+ The bash tool also supports a spawn hook to adjust the command, cwd, or env before execution:
2038
+
2039
+ ```typescript
2040
+ import { createBashTool } from "@greppleai/grip";
2041
+
2042
+ const bashTool = createBashTool(cwd, {
2043
+ spawnHook: ({ command, cwd, env }) => ({
2044
+ command: `source ~/.profile\n${command}`,
2045
+ cwd: `/mnt/sandbox${cwd}`,
2046
+ env: { ...env, CI: "1" },
2047
+ }),
2048
+ });
2049
+ ```
2050
+ Remote execution is built in through daemon connections. Use `grip --remote ws://host:port/grip/workspace`, or start with `grip --remote-deferred --remote-cwd /path` and configure the daemon later via RPC or `/sandbox --attach <ws://url/grip/workspace>`. Connecting a deferred backend reloads project instruction resources from that backend.
2051
+
2052
+ Extensions always load in the orchestrating Grip process. `grip --daemon` does not discover or execute user, package, or project Grip extensions and does not provide a reduced or fake `ExtensionContext`. Local extension hooks still wrap remote tool calls once, and backend-aware extension code can use `ctx.toolOperations` or `ctx.execToolBackend()` against the borrowed daemon connection. Direct Node filesystem or process APIs remain local.
2053
+
2054
+ ### Output Truncation
2055
+
2056
+ **Tools MUST truncate their output** to avoid overwhelming the LLM context. Large outputs can cause:
2057
+ - Context overflow errors (prompt too long)
2058
+ - Compaction failures
2059
+ - Degraded model performance
2060
+
2061
+ The built-in limit is **50KB** (~10k tokens) and **2000 lines**, whichever is hit first. Use the exported truncation utilities:
2062
+
2063
+ ```typescript
2064
+ import {
2065
+ truncateHead, // Keep first N lines/bytes (good for file reads, search results)
2066
+ truncateTail, // Keep last N lines/bytes (good for logs, command output)
2067
+ truncateLine, // Truncate a single line to maxBytes with ellipsis
2068
+ formatSize, // Human-readable size (e.g., "50KB", "1.5MB")
2069
+ DEFAULT_MAX_BYTES, // 50KB
2070
+ DEFAULT_MAX_LINES, // 2000
2071
+ } from "@greppleai/grip";
2072
+
2073
+ async execute(toolCallId, params, signal, onUpdate, ctx) {
2074
+ const output = await runCommand();
2075
+
2076
+ // Apply truncation
2077
+ const truncation = truncateHead(output, {
2078
+ maxLines: DEFAULT_MAX_LINES,
2079
+ maxBytes: DEFAULT_MAX_BYTES,
2080
+ });
2081
+
2082
+ let result = truncation.content;
2083
+
2084
+ if (truncation.truncated) {
2085
+ // Write full output to temp file
2086
+ const tempFile = writeTempFile(output);
2087
+
2088
+ // Inform the LLM where to find complete output
2089
+ result += `\n\n[Output truncated: ${truncation.outputLines} of ${truncation.totalLines} lines`;
2090
+ result += ` (${formatSize(truncation.outputBytes)} of ${formatSize(truncation.totalBytes)}).`;
2091
+ result += ` Full output saved to: ${tempFile}]`;
2092
+ }
2093
+
2094
+ return { content: [{ type: "text", text: result }] };
2095
+ }
2096
+ ```
2097
+
2098
+ **Key points:**
2099
+ - Use `truncateHead` for content where the beginning matters (search results, file reads)
2100
+ - Use `truncateTail` for content where the end matters (logs, command output)
2101
+ - Always inform the LLM when output is truncated and where to find the full version
2102
+ - Document the truncation limits in your tool's description
2103
+
2104
+ See [examples/extensions/truncated-tool.ts](../examples/extensions/truncated-tool.ts) for a complete example wrapping `rg` (ripgrep) with proper truncation.
2105
+
2106
+ ### Multiple Tools
2107
+
2108
+ One extension can register multiple tools with shared state:
2109
+
2110
+ ```typescript
2111
+ export default function (pi: ExtensionAPI) {
2112
+ let connection = null;
2113
+
2114
+ pi.registerTool({ name: "db_connect", ... });
2115
+ pi.registerTool({ name: "db_query", ... });
2116
+ pi.registerTool({ name: "db_close", ... });
2117
+
2118
+ pi.on("session_shutdown", async () => {
2119
+ connection?.close();
2120
+ });
2121
+ }
2122
+ ```
2123
+
2124
+ ### Custom Rendering
2125
+
2126
+ Tools can provide `renderCall` and `renderResult` for custom TUI display. See [tui.md](tui.md) for the full component API and [tool-execution.ts](../src/modes/interactive/components/tool-execution.ts) for how tool rows are composed.
2127
+
2128
+ By default, tool output is wrapped in a `Box` that handles padding and background. A defined `renderCall` or `renderResult` must return a `Component`. If a slot renderer is not defined, `tool-execution.ts` uses fallback rendering for that slot.
2129
+
2130
+ Set `renderShell: "self"` when the tool should render its own shell instead of using the default `Box`. This is useful for tools that need complete control over framing or background behavior, for example large previews that must stay visually stable after the tool settles.
2131
+
2132
+ ```typescript
2133
+ pi.registerTool({
2134
+ name: "my_tool",
2135
+ label: "My Tool",
2136
+ description: "Custom shell example",
2137
+ parameters: Type.Object({}),
2138
+ renderShell: "self",
2139
+ async execute() {
2140
+ return { content: [{ type: "text", text: "ok" }], details: undefined };
2141
+ },
2142
+ renderCall(args, theme, context) {
2143
+ return new Text(theme.fg("accent", "my custom shell"), 0, 0);
2144
+ },
2145
+ });
2146
+ ```
2147
+
2148
+ `renderCall` and `renderResult` each receive a `context` object with:
2149
+ - `args` - the current tool call arguments
2150
+ - `state` - shared row-local state across `renderCall` and `renderResult`
2151
+ - `lastComponent` - the previously returned component for that slot, if any
2152
+ - `invalidate()` - request a rerender of this tool row
2153
+ - `toolCallId`, `cwd`, `executionStarted`, `argsComplete`, `isPartial`, `expanded`, `showImages`, `isError`
2154
+
2155
+ Use `context.state` for cross-slot shared state. Keep slot-local caches on the returned component instance when you want to reuse and mutate the same component across renders.
2156
+
2157
+ #### renderCall
2158
+
2159
+ Renders the tool call or header:
2160
+
2161
+ ```typescript
2162
+ import { Text } from "@greppleai/grip-tui";
2163
+
2164
+ renderCall(args, theme, context) {
2165
+ const text = (context.lastComponent as Text | undefined) ?? new Text("", 0, 0);
2166
+ let content = theme.fg("toolTitle", theme.bold("my_tool "));
2167
+ content += theme.fg("muted", args.action);
2168
+ if (args.text) {
2169
+ content += " " + theme.fg("dim", `"${args.text}"`);
2170
+ }
2171
+ text.setText(content);
2172
+ return text;
2173
+ }
2174
+ ```
2175
+
2176
+ #### renderResult
2177
+
2178
+ Renders the tool result or output:
2179
+
2180
+ ```typescript
2181
+ renderResult(result, { expanded, isPartial }, theme, context) {
2182
+ if (isPartial) {
2183
+ return new Text(theme.fg("warning", "Processing..."), 0, 0);
2184
+ }
2185
+
2186
+ if (result.details?.error) {
2187
+ return new Text(theme.fg("error", `Error: ${result.details.error}`), 0, 0);
2188
+ }
2189
+
2190
+ let text = theme.fg("success", "✓ Done");
2191
+ if (expanded && result.details?.items) {
2192
+ for (const item of result.details.items) {
2193
+ text += "\n " + theme.fg("dim", item);
2194
+ }
2195
+ }
2196
+ return new Text(text, 0, 0);
2197
+ }
2198
+ ```
2199
+
2200
+ If a slot intentionally has no visible content, return an empty `Component` such as an empty `Container`.
2201
+
2202
+ #### Keybinding Hints
2203
+
2204
+ Use `keyHint()` to display keybinding hints that respect the active keybinding configuration:
2205
+
2206
+ ```typescript
2207
+ import { keyHint } from "@greppleai/grip";
2208
+
2209
+ renderResult(result, { expanded }, theme, context) {
2210
+ let text = theme.fg("success", "✓ Done");
2211
+ if (!expanded) {
2212
+ text += ` (${keyHint("app.tools.expand", "to expand")})`;
2213
+ }
2214
+ return new Text(text, 0, 0);
2215
+ }
2216
+ ```
2217
+
2218
+ Available functions:
2219
+ - `keyHint(keybinding, description)` - Formats a configured keybinding id such as `"app.tools.expand"` or `"tui.select.confirm"`
2220
+ - `keyText(keybinding)` - Returns the raw configured key text for a keybinding id
2221
+ - `rawKeyHint(key, description)` - Format a raw key string
2222
+
2223
+ Use namespaced keybinding ids:
2224
+ - Coding-agent ids use the `app.*` namespace, for example `app.tools.expand`, `app.editor.external`, `app.session.rename`
2225
+ - Shared TUI ids use the `tui.*` namespace, for example `tui.select.confirm`, `tui.select.cancel`, `tui.input.tab`
2226
+
2227
+ For the exhaustive list of keybinding ids and defaults, see [keybindings.md](keybindings.md). `keybindings.json` uses those same namespaced ids.
2228
+
2229
+ Custom editors and `ctx.ui.custom()` components receive `keybindings: KeybindingsManager` as an injected argument. They should use that injected manager directly instead of calling `getKeybindings()` or `setKeybindings()`.
2230
+
2231
+ #### Best Practices
2232
+
2233
+ - Use `Text` with padding `(0, 0)`. The default Box handles padding.
2234
+ - Use `\n` for multi-line content.
2235
+ - Handle `isPartial` for streaming progress.
2236
+ - Support `expanded` for detail on demand.
2237
+ - Keep default view compact.
2238
+ - Read `context.args` in `renderResult` instead of copying args into `context.state`.
2239
+ - Use `context.state` only for data that must be shared across call and result slots.
2240
+ - Reuse `context.lastComponent` when the same component instance can be updated in place.
2241
+ - Use `renderShell: "self"` only when the default boxed shell gets in the way. In self-shell mode the tool is responsible for its own framing, padding, and background.
2242
+
2243
+ #### Fallback
2244
+
2245
+ If a slot renderer is not defined or throws:
2246
+ - `renderCall`: Shows the tool name
2247
+ - `renderResult`: Shows raw text from `content`
2248
+
2249
+ ## Custom UI
2250
+
2251
+ Extensions can interact with users via `ctx.ui` methods and customize how messages/tools render.
2252
+
2253
+ **For custom components, see [tui.md](tui.md)** which has copy-paste patterns for:
2254
+ - Selection dialogs (SelectList)
2255
+ - Async operations with cancel (BorderedLoader)
2256
+ - Settings toggles (SettingsList)
2257
+ - Status indicators (setStatus)
2258
+ - Working message, visibility, and indicator during streaming (`setWorkingMessage`, `setWorkingVisible`, `setWorkingIndicator`)
2259
+ - Widgets above/below editor (setWidget)
2260
+ - Autocomplete providers layered on top of built-in slash/path completion (addAutocompleteProvider)
2261
+ - Custom footers (setFooter)
2262
+
2263
+ ### Dialogs
2264
+
2265
+ ```typescript
2266
+ // Select from options
2267
+ const choice = await ctx.ui.select("Pick one:", ["A", "B", "C"]);
2268
+
2269
+ // Confirm dialog
2270
+ const ok = await ctx.ui.confirm("Delete?", "This cannot be undone");
2271
+
2272
+ // Text input
2273
+ const name = await ctx.ui.input("Name:", "placeholder");
2274
+
2275
+ // Multi-line editor
2276
+ const text = await ctx.ui.editor("Edit:", "prefilled text");
2277
+
2278
+ // Notification (non-blocking)
2279
+ ctx.ui.notify("Done!", "info"); // "info" | "warning" | "error"
2280
+ ```
2281
+
2282
+ #### Timed Dialogs with Countdown
2283
+
2284
+ Dialogs support a `timeout` option that auto-dismisses with a live countdown display:
2285
+
2286
+ ```typescript
2287
+ // Dialog shows "Title (5s)" → "Title (4s)" → ... → auto-dismisses at 0
2288
+ const confirmed = await ctx.ui.confirm(
2289
+ "Timed Confirmation",
2290
+ "This dialog will auto-cancel in 5 seconds. Confirm?",
2291
+ { timeout: 5000 }
2292
+ );
2293
+
2294
+ if (confirmed) {
2295
+ // User confirmed
2296
+ } else {
2297
+ // User cancelled or timed out
2298
+ }
2299
+ ```
2300
+
2301
+ **Return values on timeout:**
2302
+ - `select()` returns `undefined`
2303
+ - `confirm()` returns `false`
2304
+ - `input()` returns `undefined`
2305
+
2306
+ #### Manual Dismissal with AbortSignal
2307
+
2308
+ For more control (e.g., to distinguish timeout from user cancel), use `AbortSignal`:
2309
+
2310
+ ```typescript
2311
+ const controller = new AbortController();
2312
+ const timeoutId = setTimeout(() => controller.abort(), 5000);
2313
+
2314
+ const confirmed = await ctx.ui.confirm(
2315
+ "Timed Confirmation",
2316
+ "This dialog will auto-cancel in 5 seconds. Confirm?",
2317
+ { signal: controller.signal }
2318
+ );
2319
+
2320
+ clearTimeout(timeoutId);
2321
+
2322
+ if (confirmed) {
2323
+ // User confirmed
2324
+ } else if (controller.signal.aborted) {
2325
+ // Dialog timed out
2326
+ } else {
2327
+ // User cancelled (pressed Escape or selected "No")
2328
+ }
2329
+ ```
2330
+
2331
+ See [examples/extensions/timed-confirm.ts](../examples/extensions/timed-confirm.ts) for complete examples.
2332
+
2333
+ ### Widgets, Status, and Footer
2334
+
2335
+ ```typescript
2336
+ // Status in footer (persistent until cleared)
2337
+ ctx.ui.setStatus("my-ext", "Processing...");
2338
+ ctx.ui.setStatus("my-ext", undefined); // Clear
2339
+
2340
+ // Working loader (shown during streaming)
2341
+ ctx.ui.setWorkingMessage("Thinking deeply...");
2342
+ ctx.ui.setWorkingMessage(); // Restore default
2343
+ ctx.ui.setWorkingVisible(false); // Hide the built-in working loader row entirely
2344
+ ctx.ui.setWorkingVisible(true); // Show the built-in working loader row
2345
+
2346
+ // Working indicator (shown during streaming)
2347
+ ctx.ui.setWorkingIndicator({ frames: [ctx.ui.theme.fg("accent", "●")] }); // Static dot
2348
+ ctx.ui.setWorkingIndicator({
2349
+ frames: [
2350
+ ctx.ui.theme.fg("dim", "·"),
2351
+ ctx.ui.theme.fg("muted", "•"),
2352
+ ctx.ui.theme.fg("accent", "●"),
2353
+ ctx.ui.theme.fg("muted", "•"),
2354
+ ],
2355
+ intervalMs: 120,
2356
+ });
2357
+ ctx.ui.setWorkingIndicator({ frames: [] }); // Hide indicator
2358
+ ctx.ui.setWorkingIndicator(); // Restore default spinner
2359
+
2360
+ // Widget above editor (default)
2361
+ ctx.ui.setWidget("my-widget", ["Line 1", "Line 2"]);
2362
+ // Widget below editor
2363
+ ctx.ui.setWidget("my-widget", ["Line 1", "Line 2"], { placement: "belowEditor" });
2364
+ ctx.ui.setWidget("my-widget", (tui, theme) => new Text(theme.fg("accent", "Custom"), 0, 0));
2365
+ ctx.ui.setWidget("my-widget", undefined); // Clear
2366
+
2367
+ // Custom footer (replaces built-in footer entirely)
2368
+ ctx.ui.setFooter((tui, theme) => ({
2369
+ render(width) { return [theme.fg("dim", "Custom footer")]; },
2370
+ invalidate() {},
2371
+ }));
2372
+ ctx.ui.setFooter(undefined); // Restore built-in footer
2373
+
2374
+ // Terminal title
2375
+ ctx.ui.setTitle("grip - my-project");
2376
+
2377
+ // Editor text
2378
+ ctx.ui.setEditorText("Prefill text");
2379
+ const current = ctx.ui.getEditorText();
2380
+
2381
+ // Paste into editor (triggers paste handling, including collapse for large content)
2382
+ ctx.ui.pasteToEditor("pasted content");
2383
+
2384
+ // Stack custom autocomplete behavior on top of the built-in provider
2385
+ ctx.ui.addAutocompleteProvider((current) => ({
2386
+ async getSuggestions(lines, line, col, options) {
2387
+ const beforeCursor = (lines[line] ?? "").slice(0, col);
2388
+ const match = beforeCursor.match(/(?:^|[ \t])#([^\s#]*)$/);
2389
+ if (!match) {
2390
+ return current.getSuggestions(lines, line, col, options);
2391
+ }
2392
+
2393
+ return {
2394
+ prefix: `#${match[1] ?? ""}`,
2395
+ items: [{ value: "#2983", label: "#2983", description: "Extension API for autocomplete" }],
2396
+ };
2397
+ },
2398
+ applyCompletion(lines, line, col, item, prefix) {
2399
+ return current.applyCompletion(lines, line, col, item, prefix);
2400
+ },
2401
+ shouldTriggerFileCompletion(lines, line, col) {
2402
+ return current.shouldTriggerFileCompletion?.(lines, line, col) ?? true;
2403
+ },
2404
+ }));
2405
+
2406
+ // Tool output expansion
2407
+ const wasExpanded = ctx.ui.getToolsExpanded();
2408
+ ctx.ui.setToolsExpanded(true);
2409
+ ctx.ui.setToolsExpanded(wasExpanded);
2410
+
2411
+ // Custom editor (vim mode, emacs mode, etc.)
2412
+ ctx.ui.setEditorComponent((tui, theme, keybindings) => new VimEditor(tui, theme, keybindings));
2413
+ const currentEditor = ctx.ui.getEditorComponent();
2414
+ ctx.ui.setEditorComponent((tui, theme, keybindings) =>
2415
+ new WrappedEditor(tui, theme, keybindings, currentEditor?.(tui, theme, keybindings))
2416
+ );
2417
+ ctx.ui.setEditorComponent(undefined); // Restore default editor
2418
+
2419
+ // Theme management (see themes.md for creating themes)
2420
+ const themes = ctx.ui.getAllThemes(); // [{ name: "dark", path: "/..." | undefined }, ...]
2421
+ const lightTheme = ctx.ui.getTheme("light"); // Load without switching
2422
+ const result = ctx.ui.setTheme("light"); // Switch by name
2423
+ if (!result.success) {
2424
+ ctx.ui.notify(`Failed: ${result.error}`, "error");
2425
+ }
2426
+ ctx.ui.setTheme(lightTheme!); // Or switch by Theme object
2427
+ ctx.ui.theme.fg("accent", "styled text"); // Access current theme
2428
+ ```
2429
+
2430
+ Custom working-indicator frames are rendered verbatim. If you want colors, add them to the frame strings yourself, for example with `ctx.ui.theme.fg(...)`.
2431
+
2432
+ ### Autocomplete Providers
2433
+
2434
+ Use `ctx.ui.addAutocompleteProvider()` to stack custom autocomplete logic on top of the built-in slash-command and path provider.
2435
+
2436
+ Typical pattern:
2437
+
2438
+ - inspect the text before the cursor
2439
+ - return your own suggestions when your extension-specific syntax matches
2440
+ - otherwise delegate to `current.getSuggestions(...)`
2441
+ - delegate `applyCompletion(...)` unless you need custom insertion behavior
2442
+
2443
+ ```typescript
2444
+ pi.on("session_start", (_event, ctx) => {
2445
+ ctx.ui.addAutocompleteProvider((current) => ({
2446
+ async getSuggestions(lines, cursorLine, cursorCol, options) {
2447
+ const line = lines[cursorLine] ?? "";
2448
+ const beforeCursor = line.slice(0, cursorCol);
2449
+ const match = beforeCursor.match(/(?:^|[ \t])#([^\s#]*)$/);
2450
+ if (!match) {
2451
+ return current.getSuggestions(lines, cursorLine, cursorCol, options);
2452
+ }
2453
+
2454
+ return {
2455
+ prefix: `#${match[1] ?? ""}`,
2456
+ items: [
2457
+ { value: "#2983", label: "#2983", description: "Extension API for registering custom @ autocomplete providers" },
2458
+ { value: "#2753", label: "#2753", description: "Reload stale resource settings" },
2459
+ ],
2460
+ };
2461
+ },
2462
+
2463
+ applyCompletion(lines, cursorLine, cursorCol, item, prefix) {
2464
+ return current.applyCompletion(lines, cursorLine, cursorCol, item, prefix);
2465
+ },
2466
+
2467
+ shouldTriggerFileCompletion(lines, cursorLine, cursorCol) {
2468
+ return current.shouldTriggerFileCompletion?.(lines, cursorLine, cursorCol) ?? true;
2469
+ },
2470
+ }));
2471
+ });
2472
+ ```
2473
+
2474
+ See [github-issue-autocomplete.ts](../examples/extensions/github-issue-autocomplete.ts) for a complete example that preloads the latest open GitHub issues with `gh issue list` and filters them locally for fast `#...` completion. It requires GitHub CLI (`gh`) and a GitHub repository checkout.
2475
+
2476
+ ### Custom Components
2477
+
2478
+ For complex UI, use `ctx.ui.custom()`. This temporarily replaces the editor with your component until `done()` is called:
2479
+
2480
+ ```typescript
2481
+ import { Text, Component } from "@greppleai/grip-tui";
2482
+
2483
+ const result = await ctx.ui.custom<boolean>((tui, theme, keybindings, done) => {
2484
+ const text = new Text("Press Enter to confirm, Escape to cancel", 1, 1);
2485
+
2486
+ text.onKey = (key) => {
2487
+ if (key === "return") done(true);
2488
+ if (key === "escape") done(false);
2489
+ return true;
2490
+ };
2491
+
2492
+ return text;
2493
+ });
2494
+
2495
+ if (result) {
2496
+ // User pressed Enter
2497
+ }
2498
+ ```
2499
+
2500
+ The callback receives:
2501
+ - `tui` - TUI instance (for screen dimensions, focus management)
2502
+ - `theme` - Current theme for styling
2503
+ - `keybindings` - App keybinding manager (for checking shortcuts)
2504
+ - `done(value)` - Call to close component and return value
2505
+
2506
+ See [tui.md](tui.md) for the full component API.
2507
+
2508
+ #### Overlay Mode (Experimental)
2509
+
2510
+ Pass `{ overlay: true }` to render the component as a floating modal on top of existing content, without clearing the screen:
2511
+
2512
+ ```typescript
2513
+ const result = await ctx.ui.custom<string | null>(
2514
+ (tui, theme, keybindings, done) => new MyOverlayComponent({ onClose: done }),
2515
+ { overlay: true }
2516
+ );
2517
+ ```
2518
+
2519
+ For advanced positioning (anchors, margins, percentages, responsive visibility), pass `overlayOptions`. Use `onHandle` to control visibility programmatically:
2520
+
2521
+ ```typescript
2522
+ const result = await ctx.ui.custom<string | null>(
2523
+ (tui, theme, keybindings, done) => new MyOverlayComponent({ onClose: done }),
2524
+ {
2525
+ overlay: true,
2526
+ overlayOptions: { anchor: "top-right", width: "50%", margin: 2 },
2527
+ onHandle: (handle) => { /* handle.setHidden(true/false) */ }
2528
+ }
2529
+ );
2530
+ ```
2531
+
2532
+ See [tui.md](tui.md) for the full `OverlayOptions` API and [overlay-qa-tests.ts](../examples/extensions/overlay-qa-tests.ts) for examples.
2533
+
2534
+ ### Custom Editor
2535
+
2536
+ Replace the main input editor with a custom implementation (vim mode, emacs mode, etc.):
2537
+
2538
+ ```typescript
2539
+ import { CustomEditor, type ExtensionAPI } from "@greppleai/grip";
2540
+ import { matchesKey } from "@greppleai/grip-tui";
2541
+
2542
+ class VimEditor extends CustomEditor {
2543
+ private mode: "normal" | "insert" = "insert";
2544
+
2545
+ handleInput(data: string): void {
2546
+ if (matchesKey(data, "escape") && this.mode === "insert") {
2547
+ this.mode = "normal";
2548
+ return;
2549
+ }
2550
+ if (this.mode === "normal" && data === "i") {
2551
+ this.mode = "insert";
2552
+ return;
2553
+ }
2554
+ super.handleInput(data); // App keybindings + text editing
2555
+ }
2556
+ }
2557
+
2558
+ export default function (pi: ExtensionAPI) {
2559
+ pi.on("session_start", (_event, ctx) => {
2560
+ ctx.ui.setEditorComponent((_tui, theme, keybindings) =>
2561
+ new VimEditor(theme, keybindings)
2562
+ );
2563
+ });
2564
+ }
2565
+ ```
2566
+
2567
+ **Key points:**
2568
+ - Extend `CustomEditor` (not base `Editor`) to get app keybindings (escape to abort, ctrl+d, model switching)
2569
+ - Call `super.handleInput(data)` for keys you don't handle
2570
+ - Factory receives `theme` and `keybindings` from the app
2571
+ - Use `ctx.ui.getEditorComponent()` before `setEditorComponent()` to wrap the previously configured custom editor
2572
+ - Pass `undefined` to restore default: `ctx.ui.setEditorComponent(undefined)`
2573
+
2574
+ To compose with another extension that already replaced the editor, capture the previous factory before setting yours:
2575
+
2576
+ ```typescript
2577
+ const previous = ctx.ui.getEditorComponent();
2578
+ ctx.ui.setEditorComponent((tui, theme, keybindings) =>
2579
+ new MyEditor(tui, theme, keybindings, { base: previous?.(tui, theme, keybindings) })
2580
+ );
2581
+ ```
2582
+
2583
+ See [tui.md](tui.md) Pattern 7 for a complete example with mode indicator.
2584
+
2585
+ ### Message Rendering
2586
+
2587
+ Register a custom renderer for messages with your `customType`:
2588
+
2589
+ ```typescript
2590
+ import { Text } from "@greppleai/grip-tui";
2591
+
2592
+ pi.registerMessageRenderer("my-extension", (message, options, theme) => {
2593
+ const { expanded } = options;
2594
+ let text = theme.fg("accent", `[${message.customType}] `);
2595
+ text += message.content;
2596
+
2597
+ if (expanded && message.details) {
2598
+ text += "\n" + theme.fg("dim", JSON.stringify(message.details, null, 2));
2599
+ }
2600
+
2601
+ return new Text(text, 0, 0);
2602
+ });
2603
+ ```
2604
+
2605
+ Messages are sent via `pi.sendMessage()`:
2606
+
2607
+ ```typescript
2608
+ pi.sendMessage({
2609
+ customType: "my-extension", // Matches registerMessageRenderer
2610
+ content: "Status update",
2611
+ display: true, // Show in TUI
2612
+ details: { ... }, // Available in renderer
2613
+ });
2614
+ ```
2615
+
2616
+ ### Theme Colors
2617
+
2618
+ All render functions receive a `theme` object. See [themes.md](themes.md) for creating custom themes and the full color palette.
2619
+
2620
+ ```typescript
2621
+ // Foreground colors
2622
+ theme.fg("toolTitle", text) // Tool names
2623
+ theme.fg("accent", text) // Highlights
2624
+ theme.fg("success", text) // Success (green)
2625
+ theme.fg("error", text) // Errors (red)
2626
+ theme.fg("warning", text) // Warnings (yellow)
2627
+ theme.fg("muted", text) // Secondary text
2628
+ theme.fg("dim", text) // Tertiary text
2629
+
2630
+ // Text styles
2631
+ theme.bold(text)
2632
+ theme.italic(text)
2633
+ theme.strikethrough(text)
2634
+ ```
2635
+
2636
+ For syntax highlighting in custom tool renderers:
2637
+
2638
+ ```typescript
2639
+ import { highlightCode, getLanguageFromPath } from "@greppleai/grip";
2640
+
2641
+ // Highlight code with explicit language
2642
+ const highlighted = highlightCode("const x = 1;", "typescript", theme);
2643
+
2644
+ // Auto-detect language from file path
2645
+ const lang = getLanguageFromPath("/path/to/file.rs"); // "rust"
2646
+ const highlighted = highlightCode(code, lang, theme);
2647
+ ```
2648
+
2649
+ ## Error Handling
2650
+
2651
+ - Extension errors are logged, agent continues
2652
+ - `tool_call` errors block the tool (fail-safe)
2653
+ - Tool `execute` errors must be signaled by throwing; the thrown error is caught, reported to the LLM with `isError: true`, and execution continues
2654
+
2655
+ ## Mode Behavior
2656
+
2657
+ | Mode | UI Methods | Notes |
2658
+ |------|-----------|-------|
2659
+ | Interactive | Full TUI | Normal operation |
2660
+ | RPC (`--mode rpc`) | JSON protocol | Host handles UI, see [rpc.md](rpc.md) |
2661
+ | JSON (`--mode json`) | No-op | Event stream to stdout, see [json.md](json.md) |
2662
+ | Print (`-p`) | No-op | Extensions run but can't prompt |
2663
+
2664
+ In non-interactive modes, check `ctx.hasUI` before using UI methods.
2665
+
2666
+ ## Examples Reference
2667
+
2668
+ All examples in [examples/extensions/](../examples/extensions/).
2669
+
2670
+ | Example | Description | Key APIs |
2671
+ |---------|-------------|----------|
2672
+ | **Tools** |||
2673
+ | `hello.ts` | Minimal tool registration | `registerTool` |
2674
+ | `question.ts` | Tool with user interaction | `registerTool`, `ui.select` |
2675
+ | `questionnaire.ts` | Multi-step wizard tool | `registerTool`, `ui.custom` |
2676
+ | `todo.ts` | Stateful tool with persistence | `registerTool`, `appendEntry`, `renderResult`, session events |
2677
+ | `dynamic-tools.ts` | Register tools after startup and during commands | `registerTool`, `session_start`, `registerCommand` |
2678
+ | `structured-output.ts` | Final structured-output tool with `terminate: true` | `registerTool`, terminating tool results |
2679
+ | `truncated-tool.ts` | Output truncation example | `registerTool`, `truncateHead` |
2680
+ | `tool-override.ts` | Override built-in read tool | `registerTool` (same name as built-in) |
2681
+ | **Commands** |||
2682
+ | `pirate.ts` | Modify system prompt per-turn | `registerCommand`, `before_agent_start` |
2683
+ | `summarize.ts` | Conversation summary command | `registerCommand`, `ui.custom` |
2684
+ | `handoff.ts` | Cross-provider model handoff | `registerCommand`, `ui.editor`, `ui.custom` |
2685
+ | `qna.ts` | Q&A with custom UI | `registerCommand`, `ui.custom`, `setEditorText` |
2686
+ | `send-user-message.ts` | Inject user messages | `registerCommand`, `sendUserMessage` |
2687
+ | `reload-runtime.ts` | Reload command and LLM tool handoff | `registerCommand`, `ctx.reload()`, `sendUserMessage` |
2688
+ | `shutdown-command.ts` | Graceful shutdown command | `registerCommand`, `shutdown()` |
2689
+ | **Events & Gates** |||
2690
+ | `permission-gate.ts` | Block dangerous commands | `on("tool_call")`, `ui.confirm` |
2691
+ | `protected-paths.ts` | Block writes to specific paths | `on("tool_call")` |
2692
+ | `confirm-destructive.ts` | Confirm session changes | `on("session_before_switch")`, `on("session_before_fork")` |
2693
+ | `dirty-repo-guard.ts` | Warn on dirty git repo | `on("session_before_*")`, `exec` |
2694
+ | `input-transform.ts` | Transform user input | `on("input")` |
2695
+ | `model-status.ts` | React to model changes | `on("model_select")`, `setStatus` |
2696
+ | `provider-payload.ts` | Inspect payloads and provider response headers | `on("before_provider_request")`, `on("after_provider_response")` |
2697
+ | `system-prompt-header.ts` | Display system prompt info | `on("agent_start")`, `getSystemPrompt` |
2698
+ | `claude-rules.ts` | Load rules from files | `on("session_start")`, `on("before_agent_start")` |
2699
+ | `prompt-customizer.ts` | Add context-aware tool guidance using `systemPromptOptions` | `on("before_agent_start")`, `BuildSystemPromptOptions` |
2700
+ | `file-trigger.ts` | File watcher triggers messages | `sendMessage` |
2701
+ | **Compaction & Sessions** |||
2702
+ | `custom-compaction.ts` | Custom compaction summary | `on("session_before_compact")` |
2703
+ | `trigger-compact.ts` | Trigger compaction manually | `compact()` |
2704
+ | `git-checkpoint.ts` | Git stash on turns | `on("turn_start")`, `on("session_before_fork")`, `exec` |
2705
+ | `git-merge-and-resolve.ts` | Fetch, merge, and resolve conflicts | `on("agent_end")`, `exec`, `sendUserMessage` |
2706
+ | `auto-commit-on-exit.ts` | Commit on shutdown | `on("session_shutdown")`, `exec` |
2707
+ | **UI Components** |||
2708
+ | `status-line.ts` | Footer status indicator | `setStatus`, session events |
2709
+ | `working-indicator.ts` | Customize the streaming working indicator | `setWorkingIndicator`, `registerCommand` |
2710
+ | `github-issue-autocomplete.ts` | Add `#1234` issue completions on top of built-in autocomplete by preloading recent open issues from `gh issue list` | `addAutocompleteProvider`, `on("session_start")`, `exec` |
2711
+ | `custom-footer.ts` | Replace footer entirely | `registerCommand`, `setFooter` |
2712
+ | `custom-header.ts` | Replace startup header | `on("session_start")`, `setHeader` |
2713
+ | `modal-editor.ts` | Vim-style modal editor | `setEditorComponent`, `CustomEditor` |
2714
+ | `rainbow-editor.ts` | Custom editor styling | `setEditorComponent` |
2715
+ | `widget-placement.ts` | Widget above/below editor | `setWidget` |
2716
+ | `overlay-test.ts` | Overlay components | `ui.custom` with overlay options |
2717
+ | `overlay-qa-tests.ts` | Comprehensive overlay tests | `ui.custom`, all overlay options |
2718
+ | `notify.ts` | Simple notifications | `ui.notify` |
2719
+ | `timed-confirm.ts` | Dialogs with timeout | `ui.confirm` with timeout/signal |
2720
+ | `mac-system-theme.ts` | Auto-switch theme | `setTheme`, `exec` |
2721
+ | **Complex Extensions** |||
2722
+ | `plan-mode/` | Full plan mode implementation | All event types, `registerCommand`, `registerShortcut`, `registerFlag`, `setStatus`, `setWidget`, `sendMessage`, `setActiveTools` |
2723
+ | `preset.ts` | Saveable presets (model, tools, thinking) | `registerCommand`, `registerShortcut`, `registerFlag`, `setModel`, `setActiveTools`, `setThinkingLevel`, `appendEntry` |
2724
+ | `tools.ts` | Toggle tools on/off UI | `registerCommand`, `setActiveTools`, `SettingsList`, session events |
2725
+ | **Remote & Sandbox** |||
2726
+ | `interactive-shell.ts` | Persistent shell session | `on("user_bash")` |
2727
+ | `sandbox/` | Sandboxed tool execution | Tool operations |
2728
+ | `subagent/` | Spawn sub-agents | `registerTool`, `exec` |
2729
+ | **Games** |||
2730
+ | `snake.ts` | Snake game | `registerCommand`, `ui.custom`, keyboard handling |
2731
+ | `space-invaders.ts` | Space Invaders game | `registerCommand`, `ui.custom` |
2732
+ | `doom-overlay/` | Doom in overlay | `ui.custom` with overlay |
2733
+ | **Providers** |||
2734
+ | `custom-provider-anthropic/` | Custom Anthropic proxy | `registerProvider` |
2735
+ | `custom-provider-gitlab-duo/` | GitLab Duo integration | `registerProvider` with OAuth |
2736
+ | **Messages & Communication** |||
2737
+ | `message-renderer.ts` | Custom message rendering | `registerMessageRenderer`, `sendMessage` |
2738
+ | `event-bus.ts` | Inter-extension events | `pi.events` |
2739
+ | **Session Metadata** |||
2740
+ | `session-name.ts` | Name sessions for selector | `setSessionName`, `getSessionName` |
2741
+ | `bookmark.ts` | Bookmark entries for /tree | `setLabel` |
2742
+ | **Misc** |||
2743
+ | `inline-bash.ts` | Inline bash in tool calls | `on("tool_call")` |
2744
+ | `bash-spawn-hook.ts` | Adjust bash command, cwd, and env before execution | `createBashTool`, `spawnHook` |
2745
+ | `with-deps/` | Extension with npm dependencies | Package structure with `package.json` |