@ashx-j/lunr 0.1.0 → 0.1.2

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 (869) hide show
  1. package/dist/builtin-extensions/ashxj-spinners.d.ts +1 -1
  2. package/dist/builtin-extensions/ashxj-spinners.d.ts.map +1 -1
  3. package/dist/builtin-extensions/ashxj-spinners.js.map +1 -1
  4. package/dist/builtin-extensions/ashxj-thinking.d.ts +5 -5
  5. package/dist/builtin-extensions/ashxj-thinking.d.ts.map +1 -1
  6. package/dist/builtin-extensions/ashxj-thinking.js +3 -3
  7. package/dist/builtin-extensions/ashxj-thinking.js.map +1 -1
  8. package/dist/builtin-extensions/ashxj-tui.d.ts +2 -2
  9. package/dist/builtin-extensions/ashxj-tui.d.ts.map +1 -1
  10. package/dist/builtin-extensions/ashxj-tui.js +2 -2
  11. package/dist/builtin-extensions/ashxj-tui.js.map +1 -1
  12. package/dist/builtin-extensions/lunr-cron.d.ts +1 -1
  13. package/dist/builtin-extensions/lunr-cron.d.ts.map +1 -1
  14. package/dist/builtin-extensions/lunr-cron.js.map +1 -1
  15. package/dist/builtin-extensions/lunr-local-providers/index.d.ts +1 -1
  16. package/dist/builtin-extensions/lunr-local-providers/index.d.ts.map +1 -1
  17. package/dist/builtin-extensions/lunr-local-providers/index.js.map +1 -1
  18. package/dist/builtin-extensions/lunr-local-providers/local-servers.d.ts +1 -1
  19. package/dist/builtin-extensions/lunr-local-providers/local-servers.d.ts.map +1 -1
  20. package/dist/builtin-extensions/lunr-local-providers/local-servers.js.map +1 -1
  21. package/dist/builtin-extensions/lunr-plan-tools.d.ts +1 -1
  22. package/dist/builtin-extensions/lunr-plan-tools.d.ts.map +1 -1
  23. package/dist/builtin-extensions/lunr-plan-tools.js +1 -1
  24. package/dist/builtin-extensions/lunr-plan-tools.js.map +1 -1
  25. package/dist/builtin-extensions/lunr-skill-creator/index.d.ts +1 -1
  26. package/dist/builtin-extensions/lunr-skill-creator/index.d.ts.map +1 -1
  27. package/dist/builtin-extensions/lunr-skill-creator/index.js.map +1 -1
  28. package/dist/builtin-extensions/lunr-todos.d.ts +1 -1
  29. package/dist/builtin-extensions/lunr-todos.d.ts.map +1 -1
  30. package/dist/builtin-extensions/lunr-todos.js +1 -1
  31. package/dist/builtin-extensions/lunr-todos.js.map +1 -1
  32. package/dist/builtin-extensions/narumiruna-pi-goal/src/accounting.d.ts.map +1 -1
  33. package/dist/builtin-extensions/narumiruna-pi-goal/src/accounting.js.map +1 -1
  34. package/dist/builtin-extensions/narumiruna-pi-goal/src/goal.d.ts +1 -1
  35. package/dist/builtin-extensions/narumiruna-pi-goal/src/goal.d.ts.map +1 -1
  36. package/dist/builtin-extensions/narumiruna-pi-goal/src/goal.js.map +1 -1
  37. package/dist/builtin-extensions/narumiruna-pi-goal/src/runtime.d.ts +2 -2
  38. package/dist/builtin-extensions/narumiruna-pi-goal/src/runtime.d.ts.map +1 -1
  39. package/dist/builtin-extensions/narumiruna-pi-goal/src/runtime.js +1 -1
  40. package/dist/builtin-extensions/narumiruna-pi-goal/src/runtime.js.map +1 -1
  41. package/dist/builtin-extensions/pi-intercom/index.d.ts +1 -1
  42. package/dist/builtin-extensions/pi-intercom/index.d.ts.map +1 -1
  43. package/dist/builtin-extensions/pi-intercom/index.js +2 -2
  44. package/dist/builtin-extensions/pi-intercom/index.js.map +1 -1
  45. package/dist/builtin-extensions/pi-intercom/ui/compose.d.ts +2 -2
  46. package/dist/builtin-extensions/pi-intercom/ui/compose.d.ts.map +1 -1
  47. package/dist/builtin-extensions/pi-intercom/ui/compose.js +1 -1
  48. package/dist/builtin-extensions/pi-intercom/ui/compose.js.map +1 -1
  49. package/dist/builtin-extensions/pi-intercom/ui/inline-message.d.ts +2 -2
  50. package/dist/builtin-extensions/pi-intercom/ui/inline-message.d.ts.map +1 -1
  51. package/dist/builtin-extensions/pi-intercom/ui/inline-message.js +1 -1
  52. package/dist/builtin-extensions/pi-intercom/ui/inline-message.js.map +1 -1
  53. package/dist/builtin-extensions/pi-intercom/ui/session-list.d.ts +2 -2
  54. package/dist/builtin-extensions/pi-intercom/ui/session-list.d.ts.map +1 -1
  55. package/dist/builtin-extensions/pi-intercom/ui/session-list.js +1 -1
  56. package/dist/builtin-extensions/pi-intercom/ui/session-list.js.map +1 -1
  57. package/dist/builtin-extensions/pi-lsp-extension/bemol-extension/index.d.ts +1 -1
  58. package/dist/builtin-extensions/pi-lsp-extension/bemol-extension/index.d.ts.map +1 -1
  59. package/dist/builtin-extensions/pi-lsp-extension/bemol-extension/index.js.map +1 -1
  60. package/dist/builtin-extensions/pi-lsp-extension/src/index.d.ts +1 -1
  61. package/dist/builtin-extensions/pi-lsp-extension/src/index.d.ts.map +1 -1
  62. package/dist/builtin-extensions/pi-lsp-extension/src/index.js +1 -1
  63. package/dist/builtin-extensions/pi-lsp-extension/src/index.js.map +1 -1
  64. package/dist/builtin-extensions/pi-lsp-extension/src/tools/code-actions.d.ts +1 -1
  65. package/dist/builtin-extensions/pi-lsp-extension/src/tools/code-actions.d.ts.map +1 -1
  66. package/dist/builtin-extensions/pi-lsp-extension/src/tools/code-actions.js +1 -1
  67. package/dist/builtin-extensions/pi-lsp-extension/src/tools/code-actions.js.map +1 -1
  68. package/dist/builtin-extensions/pi-lsp-extension/src/tools/code-overview.d.ts +1 -1
  69. package/dist/builtin-extensions/pi-lsp-extension/src/tools/code-overview.d.ts.map +1 -1
  70. package/dist/builtin-extensions/pi-lsp-extension/src/tools/code-overview.js +1 -1
  71. package/dist/builtin-extensions/pi-lsp-extension/src/tools/code-overview.js.map +1 -1
  72. package/dist/builtin-extensions/pi-lsp-extension/src/tools/code-rewrite.d.ts +1 -1
  73. package/dist/builtin-extensions/pi-lsp-extension/src/tools/code-rewrite.d.ts.map +1 -1
  74. package/dist/builtin-extensions/pi-lsp-extension/src/tools/code-rewrite.js.map +1 -1
  75. package/dist/builtin-extensions/pi-lsp-extension/src/tools/code-search.d.ts +1 -1
  76. package/dist/builtin-extensions/pi-lsp-extension/src/tools/code-search.d.ts.map +1 -1
  77. package/dist/builtin-extensions/pi-lsp-extension/src/tools/code-search.js.map +1 -1
  78. package/dist/builtin-extensions/pi-lsp-extension/src/tools/completions.d.ts +1 -1
  79. package/dist/builtin-extensions/pi-lsp-extension/src/tools/completions.d.ts.map +1 -1
  80. package/dist/builtin-extensions/pi-lsp-extension/src/tools/completions.js +1 -1
  81. package/dist/builtin-extensions/pi-lsp-extension/src/tools/completions.js.map +1 -1
  82. package/dist/builtin-extensions/pi-lsp-extension/src/tools/definition.d.ts +1 -1
  83. package/dist/builtin-extensions/pi-lsp-extension/src/tools/definition.d.ts.map +1 -1
  84. package/dist/builtin-extensions/pi-lsp-extension/src/tools/definition.js +1 -1
  85. package/dist/builtin-extensions/pi-lsp-extension/src/tools/definition.js.map +1 -1
  86. package/dist/builtin-extensions/pi-lsp-extension/src/tools/diagnostics.d.ts +1 -1
  87. package/dist/builtin-extensions/pi-lsp-extension/src/tools/diagnostics.d.ts.map +1 -1
  88. package/dist/builtin-extensions/pi-lsp-extension/src/tools/diagnostics.js +1 -1
  89. package/dist/builtin-extensions/pi-lsp-extension/src/tools/diagnostics.js.map +1 -1
  90. package/dist/builtin-extensions/pi-lsp-extension/src/tools/hover.d.ts +1 -1
  91. package/dist/builtin-extensions/pi-lsp-extension/src/tools/hover.d.ts.map +1 -1
  92. package/dist/builtin-extensions/pi-lsp-extension/src/tools/hover.js +1 -1
  93. package/dist/builtin-extensions/pi-lsp-extension/src/tools/hover.js.map +1 -1
  94. package/dist/builtin-extensions/pi-lsp-extension/src/tools/references.d.ts +1 -1
  95. package/dist/builtin-extensions/pi-lsp-extension/src/tools/references.d.ts.map +1 -1
  96. package/dist/builtin-extensions/pi-lsp-extension/src/tools/references.js +1 -1
  97. package/dist/builtin-extensions/pi-lsp-extension/src/tools/references.js.map +1 -1
  98. package/dist/builtin-extensions/pi-lsp-extension/src/tools/rename.d.ts +1 -1
  99. package/dist/builtin-extensions/pi-lsp-extension/src/tools/rename.d.ts.map +1 -1
  100. package/dist/builtin-extensions/pi-lsp-extension/src/tools/rename.js +1 -1
  101. package/dist/builtin-extensions/pi-lsp-extension/src/tools/rename.js.map +1 -1
  102. package/dist/builtin-extensions/pi-lsp-extension/src/tools/symbols.d.ts +1 -1
  103. package/dist/builtin-extensions/pi-lsp-extension/src/tools/symbols.d.ts.map +1 -1
  104. package/dist/builtin-extensions/pi-lsp-extension/src/tools/symbols.js +1 -1
  105. package/dist/builtin-extensions/pi-lsp-extension/src/tools/symbols.js.map +1 -1
  106. package/dist/builtin-extensions/pi-mcp-adapter/commands.d.ts +1 -1
  107. package/dist/builtin-extensions/pi-mcp-adapter/commands.d.ts.map +1 -1
  108. package/dist/builtin-extensions/pi-mcp-adapter/commands.js.map +1 -1
  109. package/dist/builtin-extensions/pi-mcp-adapter/direct-tools.d.ts +1 -1
  110. package/dist/builtin-extensions/pi-mcp-adapter/direct-tools.d.ts.map +1 -1
  111. package/dist/builtin-extensions/pi-mcp-adapter/direct-tools.js.map +1 -1
  112. package/dist/builtin-extensions/pi-mcp-adapter/elicitation-handler.d.ts +1 -1
  113. package/dist/builtin-extensions/pi-mcp-adapter/elicitation-handler.d.ts.map +1 -1
  114. package/dist/builtin-extensions/pi-mcp-adapter/elicitation-handler.js.map +1 -1
  115. package/dist/builtin-extensions/pi-mcp-adapter/index.d.ts +1 -1
  116. package/dist/builtin-extensions/pi-mcp-adapter/index.d.ts.map +1 -1
  117. package/dist/builtin-extensions/pi-mcp-adapter/index.js.map +1 -1
  118. package/dist/builtin-extensions/pi-mcp-adapter/init.d.ts +1 -1
  119. package/dist/builtin-extensions/pi-mcp-adapter/init.d.ts.map +1 -1
  120. package/dist/builtin-extensions/pi-mcp-adapter/init.js.map +1 -1
  121. package/dist/builtin-extensions/pi-mcp-adapter/mcp-panel.d.ts.map +1 -1
  122. package/dist/builtin-extensions/pi-mcp-adapter/mcp-panel.js +1 -1
  123. package/dist/builtin-extensions/pi-mcp-adapter/mcp-panel.js.map +1 -1
  124. package/dist/builtin-extensions/pi-mcp-adapter/mcp-setup-panel.d.ts.map +1 -1
  125. package/dist/builtin-extensions/pi-mcp-adapter/mcp-setup-panel.js +1 -1
  126. package/dist/builtin-extensions/pi-mcp-adapter/mcp-setup-panel.js.map +1 -1
  127. package/dist/builtin-extensions/pi-mcp-adapter/panel-keys.d.ts.map +1 -1
  128. package/dist/builtin-extensions/pi-mcp-adapter/panel-keys.js +1 -1
  129. package/dist/builtin-extensions/pi-mcp-adapter/panel-keys.js.map +1 -1
  130. package/dist/builtin-extensions/pi-mcp-adapter/proxy-modes.d.ts +1 -1
  131. package/dist/builtin-extensions/pi-mcp-adapter/proxy-modes.d.ts.map +1 -1
  132. package/dist/builtin-extensions/pi-mcp-adapter/proxy-modes.js.map +1 -1
  133. package/dist/builtin-extensions/pi-mcp-adapter/sampling-handler.d.ts +2 -2
  134. package/dist/builtin-extensions/pi-mcp-adapter/sampling-handler.d.ts.map +1 -1
  135. package/dist/builtin-extensions/pi-mcp-adapter/sampling-handler.js +1 -1
  136. package/dist/builtin-extensions/pi-mcp-adapter/sampling-handler.js.map +1 -1
  137. package/dist/builtin-extensions/pi-mcp-adapter/state.d.ts +1 -1
  138. package/dist/builtin-extensions/pi-mcp-adapter/state.d.ts.map +1 -1
  139. package/dist/builtin-extensions/pi-mcp-adapter/state.js.map +1 -1
  140. package/dist/builtin-extensions/pi-mcp-adapter/tool-result-renderer.d.ts +2 -2
  141. package/dist/builtin-extensions/pi-mcp-adapter/tool-result-renderer.d.ts.map +1 -1
  142. package/dist/builtin-extensions/pi-mcp-adapter/tool-result-renderer.js +1 -1
  143. package/dist/builtin-extensions/pi-mcp-adapter/tool-result-renderer.js.map +1 -1
  144. package/dist/builtin-extensions/pi-mcp-adapter/types.d.ts +1 -1
  145. package/dist/builtin-extensions/pi-mcp-adapter/types.d.ts.map +1 -1
  146. package/dist/builtin-extensions/pi-mcp-adapter/types.js.map +1 -1
  147. package/dist/builtin-extensions/pi-mcp-adapter/utils.d.ts +1 -1
  148. package/dist/builtin-extensions/pi-mcp-adapter/utils.d.ts.map +1 -1
  149. package/dist/builtin-extensions/pi-mcp-adapter/utils.js.map +1 -1
  150. package/dist/builtin-extensions/pi-ollama-cloud/index.d.ts +1 -1
  151. package/dist/builtin-extensions/pi-ollama-cloud/index.d.ts.map +1 -1
  152. package/dist/builtin-extensions/pi-ollama-cloud/index.js.map +1 -1
  153. package/dist/builtin-extensions/pi-ollama-cloud/models.d.ts +1 -1
  154. package/dist/builtin-extensions/pi-ollama-cloud/models.d.ts.map +1 -1
  155. package/dist/builtin-extensions/pi-ollama-cloud/models.generated.d.ts +1 -1
  156. package/dist/builtin-extensions/pi-ollama-cloud/models.generated.d.ts.map +1 -1
  157. package/dist/builtin-extensions/pi-ollama-cloud/models.generated.js.map +1 -1
  158. package/dist/builtin-extensions/pi-ollama-cloud/models.js.map +1 -1
  159. package/dist/builtin-extensions/pi-ollama-cloud/thinking-levels.d.ts +1 -1
  160. package/dist/builtin-extensions/pi-ollama-cloud/thinking-levels.d.ts.map +1 -1
  161. package/dist/builtin-extensions/pi-ollama-cloud/thinking-levels.js.map +1 -1
  162. package/dist/builtin-extensions/pi-prompt-template-model/deterministic-renderer.d.ts +2 -2
  163. package/dist/builtin-extensions/pi-prompt-template-model/deterministic-renderer.d.ts.map +1 -1
  164. package/dist/builtin-extensions/pi-prompt-template-model/deterministic-renderer.js +1 -1
  165. package/dist/builtin-extensions/pi-prompt-template-model/deterministic-renderer.js.map +1 -1
  166. package/dist/builtin-extensions/pi-prompt-template-model/index.d.ts +1 -1
  167. package/dist/builtin-extensions/pi-prompt-template-model/index.d.ts.map +1 -1
  168. package/dist/builtin-extensions/pi-prompt-template-model/index.js.map +1 -1
  169. package/dist/builtin-extensions/pi-prompt-template-model/loop-utils.d.ts +1 -1
  170. package/dist/builtin-extensions/pi-prompt-template-model/loop-utils.d.ts.map +1 -1
  171. package/dist/builtin-extensions/pi-prompt-template-model/loop-utils.js.map +1 -1
  172. package/dist/builtin-extensions/pi-prompt-template-model/model-selection.d.ts +1 -1
  173. package/dist/builtin-extensions/pi-prompt-template-model/model-selection.d.ts.map +1 -1
  174. package/dist/builtin-extensions/pi-prompt-template-model/model-selection.js.map +1 -1
  175. package/dist/builtin-extensions/pi-prompt-template-model/notifications.d.ts +1 -1
  176. package/dist/builtin-extensions/pi-prompt-template-model/notifications.d.ts.map +1 -1
  177. package/dist/builtin-extensions/pi-prompt-template-model/notifications.js.map +1 -1
  178. package/dist/builtin-extensions/pi-prompt-template-model/prompt-execution.d.ts +1 -1
  179. package/dist/builtin-extensions/pi-prompt-template-model/prompt-execution.d.ts.map +1 -1
  180. package/dist/builtin-extensions/pi-prompt-template-model/prompt-execution.js.map +1 -1
  181. package/dist/builtin-extensions/pi-prompt-template-model/prompt-loader.d.ts +1 -1
  182. package/dist/builtin-extensions/pi-prompt-template-model/prompt-loader.d.ts.map +1 -1
  183. package/dist/builtin-extensions/pi-prompt-template-model/prompt-loader.js +1 -1
  184. package/dist/builtin-extensions/pi-prompt-template-model/prompt-loader.js.map +1 -1
  185. package/dist/builtin-extensions/pi-prompt-template-model/skill-loaded-renderer.d.ts +2 -2
  186. package/dist/builtin-extensions/pi-prompt-template-model/skill-loaded-renderer.d.ts.map +1 -1
  187. package/dist/builtin-extensions/pi-prompt-template-model/skill-loaded-renderer.js +1 -1
  188. package/dist/builtin-extensions/pi-prompt-template-model/skill-loaded-renderer.js.map +1 -1
  189. package/dist/builtin-extensions/pi-prompt-template-model/subagent-renderer.d.ts +2 -2
  190. package/dist/builtin-extensions/pi-prompt-template-model/subagent-renderer.d.ts.map +1 -1
  191. package/dist/builtin-extensions/pi-prompt-template-model/subagent-renderer.js +1 -1
  192. package/dist/builtin-extensions/pi-prompt-template-model/subagent-renderer.js.map +1 -1
  193. package/dist/builtin-extensions/pi-prompt-template-model/subagent-step.d.ts +3 -3
  194. package/dist/builtin-extensions/pi-prompt-template-model/subagent-step.d.ts.map +1 -1
  195. package/dist/builtin-extensions/pi-prompt-template-model/subagent-step.js +1 -1
  196. package/dist/builtin-extensions/pi-prompt-template-model/subagent-step.js.map +1 -1
  197. package/dist/builtin-extensions/pi-prompt-template-model/subagent-widget.d.ts +2 -2
  198. package/dist/builtin-extensions/pi-prompt-template-model/subagent-widget.d.ts.map +1 -1
  199. package/dist/builtin-extensions/pi-prompt-template-model/subagent-widget.js +1 -1
  200. package/dist/builtin-extensions/pi-prompt-template-model/subagent-widget.js.map +1 -1
  201. package/dist/builtin-extensions/pi-prompt-template-model/tool-manager.d.ts +1 -1
  202. package/dist/builtin-extensions/pi-prompt-template-model/tool-manager.d.ts.map +1 -1
  203. package/dist/builtin-extensions/pi-prompt-template-model/tool-manager.js +1 -1
  204. package/dist/builtin-extensions/pi-prompt-template-model/tool-manager.js.map +1 -1
  205. package/dist/builtin-extensions/pi-subagents/src/agents/agent-management.d.ts +2 -2
  206. package/dist/builtin-extensions/pi-subagents/src/agents/agent-management.d.ts.map +1 -1
  207. package/dist/builtin-extensions/pi-subagents/src/agents/agent-management.js.map +1 -1
  208. package/dist/builtin-extensions/pi-subagents/src/extension/control-notices.d.ts +1 -1
  209. package/dist/builtin-extensions/pi-subagents/src/extension/control-notices.d.ts.map +1 -1
  210. package/dist/builtin-extensions/pi-subagents/src/extension/control-notices.js.map +1 -1
  211. package/dist/builtin-extensions/pi-subagents/src/extension/fanout-child.d.ts +1 -1
  212. package/dist/builtin-extensions/pi-subagents/src/extension/fanout-child.d.ts.map +1 -1
  213. package/dist/builtin-extensions/pi-subagents/src/extension/fanout-child.js.map +1 -1
  214. package/dist/builtin-extensions/pi-subagents/src/extension/index.d.ts +1 -1
  215. package/dist/builtin-extensions/pi-subagents/src/extension/index.d.ts.map +1 -1
  216. package/dist/builtin-extensions/pi-subagents/src/extension/index.js +2 -2
  217. package/dist/builtin-extensions/pi-subagents/src/extension/index.js.map +1 -1
  218. package/dist/builtin-extensions/pi-subagents/src/extension/rpc.d.ts +2 -2
  219. package/dist/builtin-extensions/pi-subagents/src/extension/rpc.d.ts.map +1 -1
  220. package/dist/builtin-extensions/pi-subagents/src/extension/rpc.js.map +1 -1
  221. package/dist/builtin-extensions/pi-subagents/src/extension/steering-notices.d.ts +1 -1
  222. package/dist/builtin-extensions/pi-subagents/src/extension/steering-notices.d.ts.map +1 -1
  223. package/dist/builtin-extensions/pi-subagents/src/extension/steering-notices.js.map +1 -1
  224. package/dist/builtin-extensions/pi-subagents/src/intercom/native-supervisor-channel.d.ts +1 -1
  225. package/dist/builtin-extensions/pi-subagents/src/intercom/native-supervisor-channel.d.ts.map +1 -1
  226. package/dist/builtin-extensions/pi-subagents/src/intercom/native-supervisor-channel.js.map +1 -1
  227. package/dist/builtin-extensions/pi-subagents/src/profiles/profiles.d.ts +1 -1
  228. package/dist/builtin-extensions/pi-subagents/src/profiles/profiles.d.ts.map +1 -1
  229. package/dist/builtin-extensions/pi-subagents/src/profiles/profiles.js.map +1 -1
  230. package/dist/builtin-extensions/pi-subagents/src/runs/background/async-execution.d.ts +1 -1
  231. package/dist/builtin-extensions/pi-subagents/src/runs/background/async-execution.d.ts.map +1 -1
  232. package/dist/builtin-extensions/pi-subagents/src/runs/background/async-execution.js.map +1 -1
  233. package/dist/builtin-extensions/pi-subagents/src/runs/background/async-job-tracker.d.ts +1 -1
  234. package/dist/builtin-extensions/pi-subagents/src/runs/background/async-job-tracker.d.ts.map +1 -1
  235. package/dist/builtin-extensions/pi-subagents/src/runs/background/async-job-tracker.js.map +1 -1
  236. package/dist/builtin-extensions/pi-subagents/src/runs/background/auto-drain.d.ts +1 -1
  237. package/dist/builtin-extensions/pi-subagents/src/runs/background/auto-drain.d.ts.map +1 -1
  238. package/dist/builtin-extensions/pi-subagents/src/runs/background/auto-drain.js.map +1 -1
  239. package/dist/builtin-extensions/pi-subagents/src/runs/background/fleet-view.d.ts +1 -1
  240. package/dist/builtin-extensions/pi-subagents/src/runs/background/fleet-view.d.ts.map +1 -1
  241. package/dist/builtin-extensions/pi-subagents/src/runs/background/fleet-view.js.map +1 -1
  242. package/dist/builtin-extensions/pi-subagents/src/runs/background/notify.d.ts +1 -1
  243. package/dist/builtin-extensions/pi-subagents/src/runs/background/notify.d.ts.map +1 -1
  244. package/dist/builtin-extensions/pi-subagents/src/runs/background/notify.js.map +1 -1
  245. package/dist/builtin-extensions/pi-subagents/src/runs/background/run-status.d.ts +1 -1
  246. package/dist/builtin-extensions/pi-subagents/src/runs/background/run-status.d.ts.map +1 -1
  247. package/dist/builtin-extensions/pi-subagents/src/runs/background/run-status.js.map +1 -1
  248. package/dist/builtin-extensions/pi-subagents/src/runs/background/scheduled-runs.d.ts +2 -2
  249. package/dist/builtin-extensions/pi-subagents/src/runs/background/scheduled-runs.d.ts.map +1 -1
  250. package/dist/builtin-extensions/pi-subagents/src/runs/background/scheduled-runs.js.map +1 -1
  251. package/dist/builtin-extensions/pi-subagents/src/runs/background/subagent-runner.d.ts.map +1 -1
  252. package/dist/builtin-extensions/pi-subagents/src/runs/background/subagent-runner.js.map +1 -1
  253. package/dist/builtin-extensions/pi-subagents/src/runs/background/subagent-wait.d.ts +1 -1
  254. package/dist/builtin-extensions/pi-subagents/src/runs/background/subagent-wait.d.ts.map +1 -1
  255. package/dist/builtin-extensions/pi-subagents/src/runs/background/subagent-wait.js.map +1 -1
  256. package/dist/builtin-extensions/pi-subagents/src/runs/background/wait-tool.d.ts +1 -1
  257. package/dist/builtin-extensions/pi-subagents/src/runs/background/wait-tool.d.ts.map +1 -1
  258. package/dist/builtin-extensions/pi-subagents/src/runs/background/wait-tool.js.map +1 -1
  259. package/dist/builtin-extensions/pi-subagents/src/runs/foreground/async-steering-action.d.ts +1 -1
  260. package/dist/builtin-extensions/pi-subagents/src/runs/foreground/async-steering-action.d.ts.map +1 -1
  261. package/dist/builtin-extensions/pi-subagents/src/runs/foreground/async-steering-action.js.map +1 -1
  262. package/dist/builtin-extensions/pi-subagents/src/runs/foreground/chain-clarify.d.ts +2 -2
  263. package/dist/builtin-extensions/pi-subagents/src/runs/foreground/chain-clarify.d.ts.map +1 -1
  264. package/dist/builtin-extensions/pi-subagents/src/runs/foreground/chain-clarify.js +1 -1
  265. package/dist/builtin-extensions/pi-subagents/src/runs/foreground/chain-clarify.js.map +1 -1
  266. package/dist/builtin-extensions/pi-subagents/src/runs/foreground/chain-execution.d.ts +2 -2
  267. package/dist/builtin-extensions/pi-subagents/src/runs/foreground/chain-execution.d.ts.map +1 -1
  268. package/dist/builtin-extensions/pi-subagents/src/runs/foreground/chain-execution.js.map +1 -1
  269. package/dist/builtin-extensions/pi-subagents/src/runs/foreground/execution.d.ts.map +1 -1
  270. package/dist/builtin-extensions/pi-subagents/src/runs/foreground/execution.js.map +1 -1
  271. package/dist/builtin-extensions/pi-subagents/src/runs/foreground/subagent-executor.d.ts +2 -2
  272. package/dist/builtin-extensions/pi-subagents/src/runs/foreground/subagent-executor.d.ts.map +1 -1
  273. package/dist/builtin-extensions/pi-subagents/src/runs/foreground/subagent-executor.js.map +1 -1
  274. package/dist/builtin-extensions/pi-subagents/src/runs/shared/completion-guard.d.ts +1 -1
  275. package/dist/builtin-extensions/pi-subagents/src/runs/shared/completion-guard.d.ts.map +1 -1
  276. package/dist/builtin-extensions/pi-subagents/src/runs/shared/completion-guard.js.map +1 -1
  277. package/dist/builtin-extensions/pi-subagents/src/runs/shared/pi-spawn.d.ts +1 -1
  278. package/dist/builtin-extensions/pi-subagents/src/runs/shared/pi-spawn.d.ts.map +1 -1
  279. package/dist/builtin-extensions/pi-subagents/src/runs/shared/pi-spawn.js +1 -1
  280. package/dist/builtin-extensions/pi-subagents/src/runs/shared/pi-spawn.js.map +1 -1
  281. package/dist/builtin-extensions/pi-subagents/src/runs/shared/single-output.d.ts +1 -1
  282. package/dist/builtin-extensions/pi-subagents/src/runs/shared/single-output.d.ts.map +1 -1
  283. package/dist/builtin-extensions/pi-subagents/src/runs/shared/single-output.js.map +1 -1
  284. package/dist/builtin-extensions/pi-subagents/src/runs/shared/subagent-prompt-runtime.d.ts +1 -1
  285. package/dist/builtin-extensions/pi-subagents/src/runs/shared/subagent-prompt-runtime.d.ts.map +1 -1
  286. package/dist/builtin-extensions/pi-subagents/src/runs/shared/subagent-prompt-runtime.js.map +1 -1
  287. package/dist/builtin-extensions/pi-subagents/src/shared/child-transcript.d.ts +1 -1
  288. package/dist/builtin-extensions/pi-subagents/src/shared/child-transcript.d.ts.map +1 -1
  289. package/dist/builtin-extensions/pi-subagents/src/shared/child-transcript.js.map +1 -1
  290. package/dist/builtin-extensions/pi-subagents/src/shared/fork-context.d.ts.map +1 -1
  291. package/dist/builtin-extensions/pi-subagents/src/shared/fork-context.js +1 -1
  292. package/dist/builtin-extensions/pi-subagents/src/shared/fork-context.js.map +1 -1
  293. package/dist/builtin-extensions/pi-subagents/src/shared/types.d.ts +3 -3
  294. package/dist/builtin-extensions/pi-subagents/src/shared/types.d.ts.map +1 -1
  295. package/dist/builtin-extensions/pi-subagents/src/shared/types.js.map +1 -1
  296. package/dist/builtin-extensions/pi-subagents/src/shared/utils.d.ts +1 -1
  297. package/dist/builtin-extensions/pi-subagents/src/shared/utils.d.ts.map +1 -1
  298. package/dist/builtin-extensions/pi-subagents/src/shared/utils.js +1 -1
  299. package/dist/builtin-extensions/pi-subagents/src/shared/utils.js.map +1 -1
  300. package/dist/builtin-extensions/pi-subagents/src/slash/prompt-workflows.d.ts +1 -1
  301. package/dist/builtin-extensions/pi-subagents/src/slash/prompt-workflows.d.ts.map +1 -1
  302. package/dist/builtin-extensions/pi-subagents/src/slash/prompt-workflows.js.map +1 -1
  303. package/dist/builtin-extensions/pi-subagents/src/slash/slash-bridge.d.ts +2 -2
  304. package/dist/builtin-extensions/pi-subagents/src/slash/slash-bridge.d.ts.map +1 -1
  305. package/dist/builtin-extensions/pi-subagents/src/slash/slash-bridge.js.map +1 -1
  306. package/dist/builtin-extensions/pi-subagents/src/slash/slash-commands.d.ts +1 -1
  307. package/dist/builtin-extensions/pi-subagents/src/slash/slash-commands.d.ts.map +1 -1
  308. package/dist/builtin-extensions/pi-subagents/src/slash/slash-commands.js +2 -2
  309. package/dist/builtin-extensions/pi-subagents/src/slash/slash-commands.js.map +1 -1
  310. package/dist/builtin-extensions/pi-subagents/src/slash/slash-live-state.d.ts +1 -1
  311. package/dist/builtin-extensions/pi-subagents/src/slash/slash-live-state.d.ts.map +1 -1
  312. package/dist/builtin-extensions/pi-subagents/src/slash/slash-live-state.js.map +1 -1
  313. package/dist/builtin-extensions/pi-subagents/src/tui/fleet.d.ts +2 -2
  314. package/dist/builtin-extensions/pi-subagents/src/tui/fleet.d.ts.map +1 -1
  315. package/dist/builtin-extensions/pi-subagents/src/tui/fleet.js +1 -1
  316. package/dist/builtin-extensions/pi-subagents/src/tui/fleet.js.map +1 -1
  317. package/dist/builtin-extensions/pi-subagents/src/tui/render-helpers.d.ts +1 -1
  318. package/dist/builtin-extensions/pi-subagents/src/tui/render-helpers.d.ts.map +1 -1
  319. package/dist/builtin-extensions/pi-subagents/src/tui/render-helpers.js +1 -1
  320. package/dist/builtin-extensions/pi-subagents/src/tui/render-helpers.js.map +1 -1
  321. package/dist/builtin-extensions/pi-subagents/src/tui/render.d.ts +3 -3
  322. package/dist/builtin-extensions/pi-subagents/src/tui/render.d.ts.map +1 -1
  323. package/dist/builtin-extensions/pi-subagents/src/tui/render.js +2 -2
  324. package/dist/builtin-extensions/pi-subagents/src/tui/render.js.map +1 -1
  325. package/dist/builtin-extensions/pi-subagents/src/watchdog/model-selection.d.ts +1 -1
  326. package/dist/builtin-extensions/pi-subagents/src/watchdog/model-selection.d.ts.map +1 -1
  327. package/dist/builtin-extensions/pi-subagents/src/watchdog/model-selection.js.map +1 -1
  328. package/dist/builtin-extensions/pi-subagents/src/watchdog/register-child.d.ts +1 -1
  329. package/dist/builtin-extensions/pi-subagents/src/watchdog/register-child.d.ts.map +1 -1
  330. package/dist/builtin-extensions/pi-subagents/src/watchdog/register-child.js.map +1 -1
  331. package/dist/builtin-extensions/pi-subagents/src/watchdog/register-main.d.ts +1 -1
  332. package/dist/builtin-extensions/pi-subagents/src/watchdog/register-main.d.ts.map +1 -1
  333. package/dist/builtin-extensions/pi-subagents/src/watchdog/register-main.js +1 -1
  334. package/dist/builtin-extensions/pi-subagents/src/watchdog/register-main.js.map +1 -1
  335. package/dist/builtin-extensions/pi-subagents/src/watchdog/render.d.ts +1 -1
  336. package/dist/builtin-extensions/pi-subagents/src/watchdog/render.d.ts.map +1 -1
  337. package/dist/builtin-extensions/pi-subagents/src/watchdog/render.js +1 -1
  338. package/dist/builtin-extensions/pi-subagents/src/watchdog/render.js.map +1 -1
  339. package/dist/builtin-extensions/pi-subagents/src/watchdog/review.d.ts +3 -3
  340. package/dist/builtin-extensions/pi-subagents/src/watchdog/review.d.ts.map +1 -1
  341. package/dist/builtin-extensions/pi-subagents/src/watchdog/review.js +3 -3
  342. package/dist/builtin-extensions/pi-subagents/src/watchdog/review.js.map +1 -1
  343. package/dist/builtin-extensions/pi-subagents/src/watchdog/runtime.d.ts +1 -1
  344. package/dist/builtin-extensions/pi-subagents/src/watchdog/runtime.d.ts.map +1 -1
  345. package/dist/builtin-extensions/pi-subagents/src/watchdog/runtime.js.map +1 -1
  346. package/dist/builtin-extensions/pi-subagents/src/watchdog/tool-actions.d.ts +2 -2
  347. package/dist/builtin-extensions/pi-subagents/src/watchdog/tool-actions.d.ts.map +1 -1
  348. package/dist/builtin-extensions/pi-subagents/src/watchdog/tool-actions.js.map +1 -1
  349. package/dist/builtin-extensions/pi-tps.d.ts +1 -1
  350. package/dist/builtin-extensions/pi-tps.d.ts.map +1 -1
  351. package/dist/builtin-extensions/pi-tps.js.map +1 -1
  352. package/dist/builtin-extensions/pi-web-access/gemini-search.d.ts +1 -1
  353. package/dist/builtin-extensions/pi-web-access/gemini-search.d.ts.map +1 -1
  354. package/dist/builtin-extensions/pi-web-access/gemini-search.js.map +1 -1
  355. package/dist/builtin-extensions/pi-web-access/index.d.ts +1 -1
  356. package/dist/builtin-extensions/pi-web-access/index.d.ts.map +1 -1
  357. package/dist/builtin-extensions/pi-web-access/index.js +2 -2
  358. package/dist/builtin-extensions/pi-web-access/index.js.map +1 -1
  359. package/dist/builtin-extensions/pi-web-access/openai-search.d.ts +1 -1
  360. package/dist/builtin-extensions/pi-web-access/openai-search.d.ts.map +1 -1
  361. package/dist/builtin-extensions/pi-web-access/openai-search.js +1 -1
  362. package/dist/builtin-extensions/pi-web-access/openai-search.js.map +1 -1
  363. package/dist/builtin-extensions/pi-web-access/storage.d.ts +1 -1
  364. package/dist/builtin-extensions/pi-web-access/storage.d.ts.map +1 -1
  365. package/dist/builtin-extensions/pi-web-access/storage.js.map +1 -1
  366. package/dist/builtin-extensions/pi-web-access/summary-review.d.ts +1 -1
  367. package/dist/builtin-extensions/pi-web-access/summary-review.d.ts.map +1 -1
  368. package/dist/builtin-extensions/pi-web-access/summary-review.js +1 -1
  369. package/dist/builtin-extensions/pi-web-access/summary-review.js.map +1 -1
  370. package/dist/bun/cli.d.ts.map +1 -1
  371. package/dist/bun/cli.js +1 -1
  372. package/dist/bun/cli.js.map +1 -1
  373. package/dist/bun/register-bedrock.d.ts.map +1 -1
  374. package/dist/bun/register-bedrock.js +2 -2
  375. package/dist/bun/register-bedrock.js.map +1 -1
  376. package/dist/catalog/models.json +1 -1
  377. package/dist/catalog/providers/opencode-go.json +1 -1
  378. package/dist/catalog/providers/openrouter.json +1 -1
  379. package/dist/catalog/providers/qwen-token-plan-cn.json +1 -1
  380. package/dist/catalog/providers/qwen-token-plan.json +1 -1
  381. package/dist/catalog/publication.json +3 -3
  382. package/dist/cli/args.d.ts +1 -1
  383. package/dist/cli/args.d.ts.map +1 -1
  384. package/dist/cli/args.js.map +1 -1
  385. package/dist/cli/config-selector.d.ts.map +1 -1
  386. package/dist/cli/config-selector.js +1 -1
  387. package/dist/cli/config-selector.js.map +1 -1
  388. package/dist/cli/file-processor.d.ts +1 -1
  389. package/dist/cli/file-processor.d.ts.map +1 -1
  390. package/dist/cli/file-processor.js.map +1 -1
  391. package/dist/cli/initial-message.d.ts +1 -1
  392. package/dist/cli/initial-message.d.ts.map +1 -1
  393. package/dist/cli/initial-message.js.map +1 -1
  394. package/dist/cli/list-models.d.ts.map +1 -1
  395. package/dist/cli/list-models.js +1 -1
  396. package/dist/cli/list-models.js.map +1 -1
  397. package/dist/cli/session-picker.d.ts.map +1 -1
  398. package/dist/cli/session-picker.js +1 -1
  399. package/dist/cli/session-picker.js.map +1 -1
  400. package/dist/cli/startup-ui.d.ts +1 -1
  401. package/dist/cli/startup-ui.d.ts.map +1 -1
  402. package/dist/cli/startup-ui.js +2 -2
  403. package/dist/cli/startup-ui.js.map +1 -1
  404. package/dist/config.d.ts.map +1 -1
  405. package/dist/config.js +1 -1
  406. package/dist/config.js.map +1 -1
  407. package/dist/core/agent-session-services.d.ts +2 -2
  408. package/dist/core/agent-session-services.d.ts.map +1 -1
  409. package/dist/core/agent-session-services.js.map +1 -1
  410. package/dist/core/agent-session.d.ts +2 -2
  411. package/dist/core/agent-session.d.ts.map +1 -1
  412. package/dist/core/agent-session.js +1 -1
  413. package/dist/core/agent-session.js.map +1 -1
  414. package/dist/core/auth-storage.d.ts +1 -1
  415. package/dist/core/auth-storage.d.ts.map +1 -1
  416. package/dist/core/auth-storage.js.map +1 -1
  417. package/dist/core/cache-stats.d.ts +1 -1
  418. package/dist/core/cache-stats.d.ts.map +1 -1
  419. package/dist/core/cache-stats.js.map +1 -1
  420. package/dist/core/catalog-merge.d.ts +1 -1
  421. package/dist/core/catalog-merge.d.ts.map +1 -1
  422. package/dist/core/catalog-merge.js +7 -1
  423. package/dist/core/catalog-merge.js.map +1 -1
  424. package/dist/core/compaction/branch-summarization.d.ts +2 -2
  425. package/dist/core/compaction/branch-summarization.d.ts.map +1 -1
  426. package/dist/core/compaction/branch-summarization.js +1 -1
  427. package/dist/core/compaction/branch-summarization.js.map +1 -1
  428. package/dist/core/compaction/compaction.d.ts +2 -2
  429. package/dist/core/compaction/compaction.d.ts.map +1 -1
  430. package/dist/core/compaction/compaction.js +1 -1
  431. package/dist/core/compaction/compaction.js.map +1 -1
  432. package/dist/core/compaction/utils.d.ts +2 -2
  433. package/dist/core/compaction/utils.d.ts.map +1 -1
  434. package/dist/core/compaction/utils.js.map +1 -1
  435. package/dist/core/context-breakdown.d.ts +1 -1
  436. package/dist/core/context-breakdown.d.ts.map +1 -1
  437. package/dist/core/context-breakdown.js.map +1 -1
  438. package/dist/core/defaults.d.ts +1 -1
  439. package/dist/core/defaults.d.ts.map +1 -1
  440. package/dist/core/defaults.js.map +1 -1
  441. package/dist/core/export-html/index.d.ts +1 -1
  442. package/dist/core/export-html/index.d.ts.map +1 -1
  443. package/dist/core/export-html/index.js.map +1 -1
  444. package/dist/core/export-html/tool-renderer.d.ts.map +1 -1
  445. package/dist/core/export-html/tool-renderer.js.map +1 -1
  446. package/dist/core/extensions/loader.d.ts.map +1 -1
  447. package/dist/core/extensions/loader.js +25 -25
  448. package/dist/core/extensions/loader.js.map +1 -1
  449. package/dist/core/extensions/runner.d.ts +3 -3
  450. package/dist/core/extensions/runner.d.ts.map +1 -1
  451. package/dist/core/extensions/runner.js.map +1 -1
  452. package/dist/core/extensions/types.d.ts +5 -5
  453. package/dist/core/extensions/types.d.ts.map +1 -1
  454. package/dist/core/extensions/types.js.map +1 -1
  455. package/dist/core/extensions/wrapper.d.ts +1 -1
  456. package/dist/core/extensions/wrapper.d.ts.map +1 -1
  457. package/dist/core/extensions/wrapper.js.map +1 -1
  458. package/dist/core/grok-cli-auth.d.ts +32 -0
  459. package/dist/core/grok-cli-auth.d.ts.map +1 -0
  460. package/dist/core/grok-cli-auth.js +218 -0
  461. package/dist/core/grok-cli-auth.js.map +1 -0
  462. package/dist/core/keybindings.d.ts +2 -2
  463. package/dist/core/keybindings.d.ts.map +1 -1
  464. package/dist/core/keybindings.js +1 -1
  465. package/dist/core/keybindings.js.map +1 -1
  466. package/dist/core/live-catalog.d.ts +1 -1
  467. package/dist/core/live-catalog.d.ts.map +1 -1
  468. package/dist/core/live-catalog.js.map +1 -1
  469. package/dist/core/messages.d.ts +3 -3
  470. package/dist/core/messages.d.ts.map +1 -1
  471. package/dist/core/messages.js.map +1 -1
  472. package/dist/core/model-registry.d.ts +1 -1
  473. package/dist/core/model-registry.d.ts.map +1 -1
  474. package/dist/core/model-registry.js.map +1 -1
  475. package/dist/core/model-resolver.d.ts +2 -2
  476. package/dist/core/model-resolver.d.ts.map +1 -1
  477. package/dist/core/model-resolver.js +1 -1
  478. package/dist/core/model-resolver.js.map +1 -1
  479. package/dist/core/model-runtime.d.ts +10 -1
  480. package/dist/core/model-runtime.d.ts.map +1 -1
  481. package/dist/core/model-runtime.js +24 -5
  482. package/dist/core/model-runtime.js.map +1 -1
  483. package/dist/core/models-store.d.ts +1 -1
  484. package/dist/core/models-store.d.ts.map +1 -1
  485. package/dist/core/models-store.js.map +1 -1
  486. package/dist/core/official-catalog.d.ts +1 -1
  487. package/dist/core/official-catalog.d.ts.map +1 -1
  488. package/dist/core/official-catalog.js.map +1 -1
  489. package/dist/core/provider-attribution.d.ts +1 -1
  490. package/dist/core/provider-attribution.d.ts.map +1 -1
  491. package/dist/core/provider-attribution.js.map +1 -1
  492. package/dist/core/provider-composer.d.ts +1 -1
  493. package/dist/core/provider-composer.d.ts.map +1 -1
  494. package/dist/core/provider-composer.js +2 -2
  495. package/dist/core/provider-composer.js.map +1 -1
  496. package/dist/core/runtime-credentials.d.ts +1 -1
  497. package/dist/core/runtime-credentials.d.ts.map +1 -1
  498. package/dist/core/runtime-credentials.js.map +1 -1
  499. package/dist/core/sdk.d.ts +3 -3
  500. package/dist/core/sdk.d.ts.map +1 -1
  501. package/dist/core/sdk.js +3 -3
  502. package/dist/core/sdk.js.map +1 -1
  503. package/dist/core/session-manager.d.ts +2 -2
  504. package/dist/core/session-manager.d.ts.map +1 -1
  505. package/dist/core/session-manager.js +1 -1
  506. package/dist/core/session-manager.js.map +1 -1
  507. package/dist/core/settings-manager.d.ts +2 -2
  508. package/dist/core/settings-manager.d.ts.map +1 -1
  509. package/dist/core/settings-manager.js.map +1 -1
  510. package/dist/core/subscriptions.d.ts +1 -1
  511. package/dist/core/subscriptions.d.ts.map +1 -1
  512. package/dist/core/subscriptions.js.map +1 -1
  513. package/dist/core/tools/bash.d.ts +1 -1
  514. package/dist/core/tools/bash.d.ts.map +1 -1
  515. package/dist/core/tools/bash.js +1 -1
  516. package/dist/core/tools/bash.js.map +1 -1
  517. package/dist/core/tools/edit.d.ts +2 -2
  518. package/dist/core/tools/edit.d.ts.map +1 -1
  519. package/dist/core/tools/edit.js +1 -1
  520. package/dist/core/tools/edit.js.map +1 -1
  521. package/dist/core/tools/find.d.ts +1 -1
  522. package/dist/core/tools/find.d.ts.map +1 -1
  523. package/dist/core/tools/find.js +1 -1
  524. package/dist/core/tools/find.js.map +1 -1
  525. package/dist/core/tools/grep.d.ts +1 -1
  526. package/dist/core/tools/grep.d.ts.map +1 -1
  527. package/dist/core/tools/grep.js +1 -1
  528. package/dist/core/tools/grep.js.map +1 -1
  529. package/dist/core/tools/index.d.ts +1 -1
  530. package/dist/core/tools/index.d.ts.map +1 -1
  531. package/dist/core/tools/index.js.map +1 -1
  532. package/dist/core/tools/ls.d.ts +1 -1
  533. package/dist/core/tools/ls.d.ts.map +1 -1
  534. package/dist/core/tools/ls.js +1 -1
  535. package/dist/core/tools/ls.js.map +1 -1
  536. package/dist/core/tools/read.d.ts +1 -1
  537. package/dist/core/tools/read.d.ts.map +1 -1
  538. package/dist/core/tools/read.js +1 -1
  539. package/dist/core/tools/read.js.map +1 -1
  540. package/dist/core/tools/render-utils.d.ts +1 -1
  541. package/dist/core/tools/render-utils.d.ts.map +1 -1
  542. package/dist/core/tools/render-utils.js +1 -1
  543. package/dist/core/tools/render-utils.js.map +1 -1
  544. package/dist/core/tools/tool-definition-wrapper.d.ts +1 -1
  545. package/dist/core/tools/tool-definition-wrapper.d.ts.map +1 -1
  546. package/dist/core/tools/tool-definition-wrapper.js.map +1 -1
  547. package/dist/core/tools/write.d.ts +1 -1
  548. package/dist/core/tools/write.d.ts.map +1 -1
  549. package/dist/core/tools/write.js +1 -1
  550. package/dist/core/tools/write.js.map +1 -1
  551. package/dist/core/usage-adapters/openai-codex.d.ts.map +1 -1
  552. package/dist/core/usage-adapters/openai-codex.js.map +1 -1
  553. package/dist/core/usage-adapters/xai.d.ts.map +1 -1
  554. package/dist/core/usage-adapters/xai.js +4 -0
  555. package/dist/core/usage-adapters/xai.js.map +1 -1
  556. package/dist/core/usage-history.d.ts.map +1 -1
  557. package/dist/core/usage-history.js.map +1 -1
  558. package/dist/core/usage-service.d.ts +11 -1
  559. package/dist/core/usage-service.d.ts.map +1 -1
  560. package/dist/core/usage-service.js +45 -9
  561. package/dist/core/usage-service.js.map +1 -1
  562. package/dist/core/user-models.d.ts +1 -1
  563. package/dist/core/user-models.d.ts.map +1 -1
  564. package/dist/core/user-models.js.map +1 -1
  565. package/dist/gateway/agent-bridge.d.ts +3 -3
  566. package/dist/gateway/agent-bridge.d.ts.map +1 -1
  567. package/dist/gateway/agent-bridge.js.map +1 -1
  568. package/dist/gateway/commands.d.ts.map +1 -1
  569. package/dist/gateway/commands.js.map +1 -1
  570. package/dist/gateway/cron.d.ts.map +1 -1
  571. package/dist/gateway/cron.js.map +1 -1
  572. package/dist/main.d.ts.map +1 -1
  573. package/dist/main.js +1 -1
  574. package/dist/main.js.map +1 -1
  575. package/dist/modes/interactive/components/armin.d.ts +1 -1
  576. package/dist/modes/interactive/components/armin.d.ts.map +1 -1
  577. package/dist/modes/interactive/components/armin.js.map +1 -1
  578. package/dist/modes/interactive/components/assistant-message.d.ts +2 -2
  579. package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
  580. package/dist/modes/interactive/components/assistant-message.js +1 -1
  581. package/dist/modes/interactive/components/assistant-message.js.map +1 -1
  582. package/dist/modes/interactive/components/bash-execution.d.ts +1 -1
  583. package/dist/modes/interactive/components/bash-execution.d.ts.map +1 -1
  584. package/dist/modes/interactive/components/bash-execution.js +1 -1
  585. package/dist/modes/interactive/components/bash-execution.js.map +1 -1
  586. package/dist/modes/interactive/components/boot-screen.d.ts +1 -1
  587. package/dist/modes/interactive/components/boot-screen.d.ts.map +1 -1
  588. package/dist/modes/interactive/components/boot-screen.js +1 -1
  589. package/dist/modes/interactive/components/boot-screen.js.map +1 -1
  590. package/dist/modes/interactive/components/bordered-loader.d.ts +1 -1
  591. package/dist/modes/interactive/components/bordered-loader.d.ts.map +1 -1
  592. package/dist/modes/interactive/components/bordered-loader.js +1 -1
  593. package/dist/modes/interactive/components/bordered-loader.js.map +1 -1
  594. package/dist/modes/interactive/components/branch-summary-message.d.ts +1 -1
  595. package/dist/modes/interactive/components/branch-summary-message.d.ts.map +1 -1
  596. package/dist/modes/interactive/components/branch-summary-message.js +1 -1
  597. package/dist/modes/interactive/components/branch-summary-message.js.map +1 -1
  598. package/dist/modes/interactive/components/compaction-summary-message.d.ts +1 -1
  599. package/dist/modes/interactive/components/compaction-summary-message.d.ts.map +1 -1
  600. package/dist/modes/interactive/components/compaction-summary-message.js +1 -1
  601. package/dist/modes/interactive/components/compaction-summary-message.js.map +1 -1
  602. package/dist/modes/interactive/components/config-selector.d.ts +1 -1
  603. package/dist/modes/interactive/components/config-selector.d.ts.map +1 -1
  604. package/dist/modes/interactive/components/config-selector.js +1 -1
  605. package/dist/modes/interactive/components/config-selector.js.map +1 -1
  606. package/dist/modes/interactive/components/countdown-timer.d.ts +1 -1
  607. package/dist/modes/interactive/components/countdown-timer.d.ts.map +1 -1
  608. package/dist/modes/interactive/components/countdown-timer.js.map +1 -1
  609. package/dist/modes/interactive/components/custom-editor.d.ts +1 -1
  610. package/dist/modes/interactive/components/custom-editor.d.ts.map +1 -1
  611. package/dist/modes/interactive/components/custom-editor.js +1 -1
  612. package/dist/modes/interactive/components/custom-editor.js.map +1 -1
  613. package/dist/modes/interactive/components/custom-entry.d.ts +1 -1
  614. package/dist/modes/interactive/components/custom-entry.d.ts.map +1 -1
  615. package/dist/modes/interactive/components/custom-entry.js +1 -1
  616. package/dist/modes/interactive/components/custom-entry.js.map +1 -1
  617. package/dist/modes/interactive/components/custom-message.d.ts +1 -1
  618. package/dist/modes/interactive/components/custom-message.d.ts.map +1 -1
  619. package/dist/modes/interactive/components/custom-message.js +1 -1
  620. package/dist/modes/interactive/components/custom-message.js.map +1 -1
  621. package/dist/modes/interactive/components/daxnuts.d.ts +1 -1
  622. package/dist/modes/interactive/components/daxnuts.d.ts.map +1 -1
  623. package/dist/modes/interactive/components/daxnuts.js.map +1 -1
  624. package/dist/modes/interactive/components/dynamic-border.d.ts +1 -1
  625. package/dist/modes/interactive/components/dynamic-border.d.ts.map +1 -1
  626. package/dist/modes/interactive/components/dynamic-border.js.map +1 -1
  627. package/dist/modes/interactive/components/earendil-announcement.d.ts +1 -1
  628. package/dist/modes/interactive/components/earendil-announcement.d.ts.map +1 -1
  629. package/dist/modes/interactive/components/earendil-announcement.js +1 -1
  630. package/dist/modes/interactive/components/earendil-announcement.js.map +1 -1
  631. package/dist/modes/interactive/components/extension-editor.d.ts +1 -1
  632. package/dist/modes/interactive/components/extension-editor.d.ts.map +1 -1
  633. package/dist/modes/interactive/components/extension-editor.js +1 -1
  634. package/dist/modes/interactive/components/extension-editor.js.map +1 -1
  635. package/dist/modes/interactive/components/extension-input.d.ts +1 -1
  636. package/dist/modes/interactive/components/extension-input.d.ts.map +1 -1
  637. package/dist/modes/interactive/components/extension-input.js +1 -1
  638. package/dist/modes/interactive/components/extension-input.js.map +1 -1
  639. package/dist/modes/interactive/components/extension-selector.d.ts +1 -1
  640. package/dist/modes/interactive/components/extension-selector.d.ts.map +1 -1
  641. package/dist/modes/interactive/components/extension-selector.js +1 -1
  642. package/dist/modes/interactive/components/extension-selector.js.map +1 -1
  643. package/dist/modes/interactive/components/first-time-setup.d.ts +1 -1
  644. package/dist/modes/interactive/components/first-time-setup.d.ts.map +1 -1
  645. package/dist/modes/interactive/components/first-time-setup.js +1 -1
  646. package/dist/modes/interactive/components/first-time-setup.js.map +1 -1
  647. package/dist/modes/interactive/components/footer.d.ts +1 -1
  648. package/dist/modes/interactive/components/footer.d.ts.map +1 -1
  649. package/dist/modes/interactive/components/footer.js +1 -1
  650. package/dist/modes/interactive/components/footer.js.map +1 -1
  651. package/dist/modes/interactive/components/injected-prompt-message.d.ts +1 -1
  652. package/dist/modes/interactive/components/injected-prompt-message.d.ts.map +1 -1
  653. package/dist/modes/interactive/components/injected-prompt-message.js +1 -1
  654. package/dist/modes/interactive/components/injected-prompt-message.js.map +1 -1
  655. package/dist/modes/interactive/components/keybinding-hints.d.ts +1 -1
  656. package/dist/modes/interactive/components/keybinding-hints.d.ts.map +1 -1
  657. package/dist/modes/interactive/components/keybinding-hints.js +1 -1
  658. package/dist/modes/interactive/components/keybinding-hints.js.map +1 -1
  659. package/dist/modes/interactive/components/login-dialog.d.ts +2 -2
  660. package/dist/modes/interactive/components/login-dialog.d.ts.map +1 -1
  661. package/dist/modes/interactive/components/login-dialog.js +1 -1
  662. package/dist/modes/interactive/components/login-dialog.js.map +1 -1
  663. package/dist/modes/interactive/components/model-selector.d.ts +2 -2
  664. package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
  665. package/dist/modes/interactive/components/model-selector.js +2 -2
  666. package/dist/modes/interactive/components/model-selector.js.map +1 -1
  667. package/dist/modes/interactive/components/oauth-selector.d.ts +2 -2
  668. package/dist/modes/interactive/components/oauth-selector.d.ts.map +1 -1
  669. package/dist/modes/interactive/components/oauth-selector.js +1 -1
  670. package/dist/modes/interactive/components/oauth-selector.js.map +1 -1
  671. package/dist/modes/interactive/components/processes-selector.d.ts +1 -1
  672. package/dist/modes/interactive/components/processes-selector.d.ts.map +1 -1
  673. package/dist/modes/interactive/components/processes-selector.js +1 -1
  674. package/dist/modes/interactive/components/processes-selector.js.map +1 -1
  675. package/dist/modes/interactive/components/scoped-models-selector.d.ts +2 -2
  676. package/dist/modes/interactive/components/scoped-models-selector.d.ts.map +1 -1
  677. package/dist/modes/interactive/components/scoped-models-selector.js +1 -1
  678. package/dist/modes/interactive/components/scoped-models-selector.js.map +1 -1
  679. package/dist/modes/interactive/components/session-selector-search.d.ts.map +1 -1
  680. package/dist/modes/interactive/components/session-selector-search.js +1 -1
  681. package/dist/modes/interactive/components/session-selector-search.js.map +1 -1
  682. package/dist/modes/interactive/components/session-selector.d.ts +1 -1
  683. package/dist/modes/interactive/components/session-selector.d.ts.map +1 -1
  684. package/dist/modes/interactive/components/session-selector.js +1 -1
  685. package/dist/modes/interactive/components/session-selector.js.map +1 -1
  686. package/dist/modes/interactive/components/settings-selector.d.ts +3 -3
  687. package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
  688. package/dist/modes/interactive/components/settings-selector.js +1 -1
  689. package/dist/modes/interactive/components/settings-selector.js.map +1 -1
  690. package/dist/modes/interactive/components/show-images-selector.d.ts +1 -1
  691. package/dist/modes/interactive/components/show-images-selector.d.ts.map +1 -1
  692. package/dist/modes/interactive/components/show-images-selector.js +1 -1
  693. package/dist/modes/interactive/components/show-images-selector.js.map +1 -1
  694. package/dist/modes/interactive/components/skill-invocation-message.d.ts +1 -1
  695. package/dist/modes/interactive/components/skill-invocation-message.d.ts.map +1 -1
  696. package/dist/modes/interactive/components/skill-invocation-message.js +1 -1
  697. package/dist/modes/interactive/components/skill-invocation-message.js.map +1 -1
  698. package/dist/modes/interactive/components/status-indicator.d.ts +1 -1
  699. package/dist/modes/interactive/components/status-indicator.d.ts.map +1 -1
  700. package/dist/modes/interactive/components/status-indicator.js +1 -1
  701. package/dist/modes/interactive/components/status-indicator.js.map +1 -1
  702. package/dist/modes/interactive/components/theme-selector.d.ts +1 -1
  703. package/dist/modes/interactive/components/theme-selector.d.ts.map +1 -1
  704. package/dist/modes/interactive/components/theme-selector.js +1 -1
  705. package/dist/modes/interactive/components/theme-selector.js.map +1 -1
  706. package/dist/modes/interactive/components/thinking-selector.d.ts +2 -2
  707. package/dist/modes/interactive/components/thinking-selector.d.ts.map +1 -1
  708. package/dist/modes/interactive/components/thinking-selector.js +1 -1
  709. package/dist/modes/interactive/components/thinking-selector.js.map +1 -1
  710. package/dist/modes/interactive/components/thinking-summary.d.ts +1 -1
  711. package/dist/modes/interactive/components/thinking-summary.d.ts.map +1 -1
  712. package/dist/modes/interactive/components/thinking-summary.js.map +1 -1
  713. package/dist/modes/interactive/components/thinking-tail.d.ts +1 -1
  714. package/dist/modes/interactive/components/thinking-tail.d.ts.map +1 -1
  715. package/dist/modes/interactive/components/thinking-tail.js +1 -1
  716. package/dist/modes/interactive/components/thinking-tail.js.map +1 -1
  717. package/dist/modes/interactive/components/tool-execution.d.ts +1 -1
  718. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  719. package/dist/modes/interactive/components/tool-execution.js +1 -1
  720. package/dist/modes/interactive/components/tool-execution.js.map +1 -1
  721. package/dist/modes/interactive/components/tree-selector.d.ts +1 -1
  722. package/dist/modes/interactive/components/tree-selector.d.ts.map +1 -1
  723. package/dist/modes/interactive/components/tree-selector.js +1 -1
  724. package/dist/modes/interactive/components/tree-selector.js.map +1 -1
  725. package/dist/modes/interactive/components/trust-selector.d.ts +1 -1
  726. package/dist/modes/interactive/components/trust-selector.d.ts.map +1 -1
  727. package/dist/modes/interactive/components/trust-selector.js +1 -1
  728. package/dist/modes/interactive/components/trust-selector.js.map +1 -1
  729. package/dist/modes/interactive/components/usage-view.d.ts.map +1 -1
  730. package/dist/modes/interactive/components/usage-view.js +1 -1
  731. package/dist/modes/interactive/components/usage-view.js.map +1 -1
  732. package/dist/modes/interactive/components/user-message-selector.d.ts +1 -1
  733. package/dist/modes/interactive/components/user-message-selector.d.ts.map +1 -1
  734. package/dist/modes/interactive/components/user-message-selector.js +1 -1
  735. package/dist/modes/interactive/components/user-message-selector.js.map +1 -1
  736. package/dist/modes/interactive/components/user-message.d.ts +1 -1
  737. package/dist/modes/interactive/components/user-message.d.ts.map +1 -1
  738. package/dist/modes/interactive/components/user-message.js +1 -1
  739. package/dist/modes/interactive/components/user-message.js.map +1 -1
  740. package/dist/modes/interactive/components/visual-truncate.d.ts.map +1 -1
  741. package/dist/modes/interactive/components/visual-truncate.js +1 -1
  742. package/dist/modes/interactive/components/visual-truncate.js.map +1 -1
  743. package/dist/modes/interactive/interactive-mode.d.ts +1 -1
  744. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  745. package/dist/modes/interactive/interactive-mode.js +29 -4
  746. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  747. package/dist/modes/interactive/smooth-streaming.d.ts +1 -1
  748. package/dist/modes/interactive/smooth-streaming.d.ts.map +1 -1
  749. package/dist/modes/interactive/smooth-streaming.js.map +1 -1
  750. package/dist/modes/interactive/theme/theme-controller.d.ts +1 -1
  751. package/dist/modes/interactive/theme/theme-controller.d.ts.map +1 -1
  752. package/dist/modes/interactive/theme/theme-controller.js.map +1 -1
  753. package/dist/modes/interactive/theme/theme.d.ts +2 -2
  754. package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
  755. package/dist/modes/interactive/theme/theme.js +2 -2
  756. package/dist/modes/interactive/theme/theme.js.map +1 -1
  757. package/dist/modes/print-mode.d.ts +1 -1
  758. package/dist/modes/print-mode.d.ts.map +1 -1
  759. package/dist/modes/print-mode.js.map +1 -1
  760. package/dist/modes/rpc/rpc-client.d.ts +2 -2
  761. package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
  762. package/dist/modes/rpc/rpc-client.js.map +1 -1
  763. package/dist/modes/rpc/rpc-types.d.ts +2 -2
  764. package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
  765. package/dist/modes/rpc/rpc-types.js.map +1 -1
  766. package/examples/extensions/auto-commit-on-exit.ts +1 -1
  767. package/examples/extensions/bash-spawn-hook.ts +2 -2
  768. package/examples/extensions/bookmark.ts +1 -1
  769. package/examples/extensions/border-status-editor.ts +3 -3
  770. package/examples/extensions/built-in-tool-renderer.ts +3 -3
  771. package/examples/extensions/claude-rules.ts +1 -1
  772. package/examples/extensions/commands.ts +1 -1
  773. package/examples/extensions/confirm-destructive.ts +1 -1
  774. package/examples/extensions/custom-compaction.ts +3 -3
  775. package/examples/extensions/custom-footer.ts +3 -3
  776. package/examples/extensions/custom-header.ts +2 -2
  777. package/examples/extensions/custom-provider-anthropic/index.ts +2 -2
  778. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  779. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  780. package/examples/extensions/custom-provider-gitlab-duo/index.ts +2 -2
  781. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  782. package/examples/extensions/custom-provider-gitlab-duo/test.ts +1 -1
  783. package/examples/extensions/dirty-repo-guard.ts +1 -1
  784. package/examples/extensions/doom-overlay/doom-component.ts +2 -2
  785. package/examples/extensions/doom-overlay/doom-keys.ts +1 -1
  786. package/examples/extensions/doom-overlay/index.ts +1 -1
  787. package/examples/extensions/dynamic-resources/index.ts +1 -1
  788. package/examples/extensions/dynamic-tools.ts +1 -1
  789. package/examples/extensions/entry-renderer.ts +2 -2
  790. package/examples/extensions/event-bus.ts +1 -1
  791. package/examples/extensions/file-trigger.ts +1 -1
  792. package/examples/extensions/git-checkpoint.ts +1 -1
  793. package/examples/extensions/git-merge-and-resolve.ts +1 -1
  794. package/examples/extensions/github-issue-autocomplete.ts +2 -2
  795. package/examples/extensions/gondolin/index.ts +2 -2
  796. package/examples/extensions/gondolin/package-lock.json +2 -2
  797. package/examples/extensions/gondolin/package.json +1 -1
  798. package/examples/extensions/handoff.ts +4 -4
  799. package/examples/extensions/hello.ts +2 -2
  800. package/examples/extensions/hidden-thinking-label.ts +1 -1
  801. package/examples/extensions/inline-bash.ts +1 -1
  802. package/examples/extensions/input-transform-streaming.ts +1 -1
  803. package/examples/extensions/input-transform.ts +1 -1
  804. package/examples/extensions/interactive-shell.ts +1 -1
  805. package/examples/extensions/kimi-deferred-tools.ts +1 -1
  806. package/examples/extensions/mac-system-theme.ts +1 -1
  807. package/examples/extensions/message-renderer.ts +2 -2
  808. package/examples/extensions/minimal-mode.ts +3 -3
  809. package/examples/extensions/modal-editor.ts +2 -2
  810. package/examples/extensions/model-status.ts +1 -1
  811. package/examples/extensions/notify.ts +1 -1
  812. package/examples/extensions/overlay-qa-tests.ts +3 -3
  813. package/examples/extensions/overlay-test.ts +2 -2
  814. package/examples/extensions/permission-gate.ts +1 -1
  815. package/examples/extensions/pirate.ts +1 -1
  816. package/examples/extensions/plan-mode/index.ts +4 -4
  817. package/examples/extensions/preset.ts +4 -4
  818. package/examples/extensions/project-trust.ts +1 -1
  819. package/examples/extensions/prompt-customizer.ts +1 -1
  820. package/examples/extensions/protected-paths.ts +1 -1
  821. package/examples/extensions/provider-payload.ts +1 -1
  822. package/examples/extensions/qna.ts +3 -3
  823. package/examples/extensions/question.ts +2 -2
  824. package/examples/extensions/questionnaire.ts +2 -2
  825. package/examples/extensions/rainbow-editor.ts +1 -1
  826. package/examples/extensions/reload-runtime.ts +1 -1
  827. package/examples/extensions/rpc-demo.ts +1 -1
  828. package/examples/extensions/sandbox/index.ts +2 -2
  829. package/examples/extensions/send-user-message.ts +1 -1
  830. package/examples/extensions/session-name.ts +1 -1
  831. package/examples/extensions/shutdown-command.ts +1 -1
  832. package/examples/extensions/snake.ts +2 -2
  833. package/examples/extensions/space-invaders.ts +2 -2
  834. package/examples/extensions/ssh.ts +2 -2
  835. package/examples/extensions/status-line.ts +1 -1
  836. package/examples/extensions/structured-output.ts +2 -2
  837. package/examples/extensions/subagent/agents.ts +1 -1
  838. package/examples/extensions/subagent/index.ts +5 -5
  839. package/examples/extensions/summarize.ts +4 -4
  840. package/examples/extensions/system-prompt-header.ts +1 -1
  841. package/examples/extensions/tic-tac-toe.ts +3 -3
  842. package/examples/extensions/timed-confirm.ts +1 -1
  843. package/examples/extensions/titlebar-spinner.ts +1 -1
  844. package/examples/extensions/todo.ts +3 -3
  845. package/examples/extensions/tool-override.ts +2 -2
  846. package/examples/extensions/tools.ts +3 -3
  847. package/examples/extensions/trigger-compact.ts +1 -1
  848. package/examples/extensions/truncated-tool.ts +3 -3
  849. package/examples/extensions/widget-placement.ts +1 -1
  850. package/examples/extensions/with-deps/index.ts +1 -1
  851. package/examples/extensions/with-deps/package-lock.json +2 -2
  852. package/examples/extensions/with-deps/package.json +1 -1
  853. package/examples/extensions/working-indicator.ts +1 -1
  854. package/examples/extensions/working-message-test.ts +1 -1
  855. package/examples/rpc-extension-ui.ts +1 -1
  856. package/examples/sdk/01-minimal.ts +1 -1
  857. package/examples/sdk/02-custom-model.ts +2 -2
  858. package/examples/sdk/03-custom-prompt.ts +1 -1
  859. package/examples/sdk/04-skills.ts +1 -1
  860. package/examples/sdk/05-tools.ts +1 -1
  861. package/examples/sdk/06-extensions.ts +2 -2
  862. package/examples/sdk/07-context-files.ts +1 -1
  863. package/examples/sdk/08-prompt-templates.ts +1 -1
  864. package/examples/sdk/09-api-keys-and-oauth.ts +1 -1
  865. package/examples/sdk/10-settings.ts +1 -1
  866. package/examples/sdk/11-sessions.ts +1 -1
  867. package/examples/sdk/12-full-control.ts +2 -2
  868. package/examples/sdk/13-session-runtime.ts +1 -1
  869. package/package.json +4 -4
@@ -1 +1 @@
1
- {"version":3,"file":"subscriptions.js","sourceRoot":"","sources":["../../src/core/subscriptions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAA2B,sBAAsB,EAAE,0BAA0B,EAAE,MAAM,mBAAmB,CAAC;AAChH,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAkBpD,MAAM,OAAO,mBAAmB;IACvB,IAAI,GAAqB,EAAE,CAAC;IAC5B,MAAM,GAAG,KAAK,CAAC;IACf,OAAO,CAAqB;IAC5B,WAAW,CAAkB;IACrC,2EAA2E;IACnE,KAAK,GAAqB,OAAO,CAAC,OAAO,EAAE,CAAC;IACpD,qEAAqE;IACrE,oEAAoE;IAC5D,eAAe,GAAG,IAAI,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AAM,CAAC,EAAE,CAAC,CAAC;YACjD,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;YAC/C,IAAI,CAAC,IAAI;gBAAE,OAAO;YAClB,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;YAC1D,IAAI,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,cAAc,KAAK,SAAS,IAAI,MAAM,CAAC,SAAS,KAAK,SAAS,CAAC;gBAAE,OAAO;YAC/F,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC;gBACrC,IAAI,KAAK,CAAC,EAAE,KAAK,EAAE;oBAAE,OAAO,KAAK,CAAC;gBAClC,MAAM,EAAE,cAAc,EAAE,eAAe,EAAE,SAAS,EAAE,UAAU,EAAE,GAAG,IAAI,EAAE,GAAG,KAAK,CAAC;gBAClF,OAAO,IAAI,CAAC;YAAA,CACZ,CAAC,CAAC;YACH,IAAI,CAAC,IAAI,GAAG,EAAE,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC,UAAU,CAAC,EAAE,EAAE,GAAG,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC;YAC9D,MAAM,IAAI,CAAC,OAAO,EAAE,CAAC;QAAA,CACrB,CAAC,CAAC;IAAA,CACH;CACD","sourcesContent":["/**\n * lunr: multi-subscription API-key pools per provider.\n *\n * The pool lives in subscriptions.json next to auth.json; auth.json always\n * holds the ACTIVE credential, so rotation is just mirroring the chosen pool\n * key into auth.json via AuthStorage.modify. Persistence reuses the\n * AuthStorage backend classes (proper-lockfile guarded read-modify-write,\n * mode 0600) pointed at the subscriptions.json path.\n *\n * Raw keys are never logged or embedded in error messages — errors refer to\n * provider and key ids only.\n */\n\nimport type { Credential, CredentialStore } from \"@earendil-works/pi-ai\";\nimport { join } from \"path\";\nimport { getAgentDir } from \"../config.ts\";\nimport { type AuthStorageBackend, FileAuthStorageBackend, InMemoryAuthStorageBackend } from \"./auth-storage.ts\";\nimport { parseResetTimeMs } from \"./usage-limit.ts\";\n\nexport interface SubEntry {\n\tid: string;\n\tname: string;\n\tkey: string;\n\taddedAt: number;\n\texhaustedUntil?: number;\n\tlastError?: string;\n}\n\ninterface ProviderPool {\n\tactive: string;\n\tkeys: SubEntry[];\n}\n\ntype SubscriptionData = Record<string, ProviderPool>;\n\nexport class SubscriptionManager {\n\tprivate data: SubscriptionData = {};\n\tprivate loaded = false;\n\tprivate storage: AuthStorageBackend;\n\tprivate authStorage: CredentialStore;\n\t// In-process write queue so mutations serialize even before the file lock.\n\tprivate queue: Promise<unknown> = Promise.resolve();\n\t// Per-provider ids of keys exhausted without a parseable reset time.\n\t// Process-local on purpose: infinite exhaustion is never persisted.\n\tprivate memoryExhausted = new Map<string, Set<string>>();\n\n\tprivate constructor(authStorage: CredentialStore, storage: AuthStorageBackend) {\n\t\tthis.authStorage = authStorage;\n\t\tthis.storage = storage;\n\t}\n\n\tstatic create(authStorage: CredentialStore, path?: string): SubscriptionManager {\n\t\treturn new SubscriptionManager(\n\t\t\tauthStorage,\n\t\t\tnew FileAuthStorageBackend(path ?? join(getAgentDir(), \"subscriptions.json\")),\n\t\t);\n\t}\n\n\tstatic fromStorage(authStorage: CredentialStore, storage: AuthStorageBackend): SubscriptionManager {\n\t\treturn new SubscriptionManager(authStorage, storage);\n\t}\n\n\tstatic inMemory(authStorage: CredentialStore, data: SubscriptionData = {}): SubscriptionManager {\n\t\tconst storage = new InMemoryAuthStorageBackend();\n\t\tstorage.withLock(() => ({ result: undefined, next: JSON.stringify(data, null, 2) }));\n\t\treturn SubscriptionManager.fromStorage(authStorage, storage);\n\t}\n\n\tprivate parseStorageData(content: string | undefined): SubscriptionData {\n\t\tif (!content) {\n\t\t\treturn {};\n\t\t}\n\t\treturn JSON.parse(content) as SubscriptionData;\n\t}\n\n\tprivate ensureLoaded(): void {\n\t\tif (this.loaded) return;\n\t\tthis.loaded = true;\n\t\tlet content: string | undefined;\n\t\ttry {\n\t\t\tthis.storage.withLock((current) => {\n\t\t\t\tcontent = current;\n\t\t\t\treturn { result: undefined };\n\t\t\t});\n\t\t\tthis.data = this.parseStorageData(content);\n\t\t} catch {\n\t\t\t// Preserve the empty snapshot; a malformed file is never overwritten by a load.\n\t\t}\n\t}\n\n\tprivate enqueue<T>(fn: () => Promise<T>): Promise<T> {\n\t\tconst next = this.queue.then(fn);\n\t\tthis.queue = next.catch(() => {});\n\t\treturn next;\n\t}\n\n\tprivate persist(): Promise<void> {\n\t\treturn this.storage.withLockAsync(async () => ({\n\t\t\tresult: undefined,\n\t\t\tnext: JSON.stringify(this.data, null, 2),\n\t\t}));\n\t}\n\n\t/** Raw stored credential read via the modify path (returning undefined leaves it unchanged). */\n\tprivate async readRawCredential(providerId: string): Promise<Credential | undefined> {\n\t\tlet current: Credential | undefined;\n\t\tawait this.authStorage.modify(providerId, async (credential) => {\n\t\t\tcurrent = credential;\n\t\t\treturn undefined;\n\t\t});\n\t\treturn current;\n\t}\n\n\t/**\n\t * Pool for a provider, lazy-importing an existing stored api_key credential\n\t * as \"Sub 1\" on first access. OAuth credentials are not imported.\n\t */\n\tprivate async ensurePool(providerId: string): Promise<ProviderPool | undefined> {\n\t\tthis.ensureLoaded();\n\t\tconst existing = this.data[providerId];\n\t\tif (existing) return existing;\n\n\t\tconst credential = await this.readRawCredential(providerId);\n\t\tif (credential?.type !== \"api_key\" || credential.key === undefined) return undefined;\n\n\t\tconst pool: ProviderPool = {\n\t\t\tactive: \"1\",\n\t\t\tkeys: [{ id: \"1\", name: \"Sub 1\", key: credential.key, addedAt: Date.now() }],\n\t\t};\n\t\tthis.data = { ...this.data, [providerId]: pool };\n\t\tawait this.persist();\n\t\treturn pool;\n\t}\n\n\tprivate nextId(pool: ProviderPool): string {\n\t\tlet max = 0;\n\t\tfor (const entry of pool.keys) {\n\t\t\tconst numeric = Number.parseInt(entry.id, 10);\n\t\t\tif (Number.isFinite(numeric) && numeric > max) max = numeric;\n\t\t}\n\t\treturn String(max + 1);\n\t}\n\n\tprivate async mirrorActive(providerId: string, key: string): Promise<void> {\n\t\tawait this.authStorage.modify(providerId, async () => ({ type: \"api_key\", key }));\n\t}\n\n\tasync list(providerId: string): Promise<SubEntry[]> {\n\t\treturn this.enqueue(async () => {\n\t\t\tconst pool = await this.ensurePool(providerId);\n\t\t\treturn pool ? [...pool.keys] : [];\n\t\t});\n\t}\n\n\tasync getActive(providerId: string): Promise<SubEntry | undefined> {\n\t\treturn this.enqueue(async () => {\n\t\t\tconst pool = await this.ensurePool(providerId);\n\t\t\treturn pool?.keys.find((entry) => entry.id === pool.active);\n\t\t});\n\t}\n\n\tasync addKey(providerId: string, key: string, name?: string): Promise<SubEntry> {\n\t\treturn this.enqueue(async () => {\n\t\t\tthis.ensureLoaded();\n\t\t\tconst pool = await this.ensurePool(providerId);\n\t\t\tconst id = pool ? this.nextId(pool) : \"1\";\n\t\t\tconst entry: SubEntry = { id, name: name ?? `Sub ${id}`, key, addedAt: Date.now() };\n\t\t\tconst keys = [...(pool?.keys ?? []), entry];\n\t\t\tthis.data = { ...this.data, [providerId]: { active: id, keys } };\n\t\t\tawait this.persist();\n\t\t\tawait this.mirrorActive(providerId, key);\n\t\t\treturn entry;\n\t\t});\n\t}\n\n\tasync removeKey(providerId: string, id: string): Promise<void> {\n\t\treturn this.enqueue(async () => {\n\t\t\tconst pool = await this.ensurePool(providerId);\n\t\t\tif (!pool || !pool.keys.some((entry) => entry.id === id)) return;\n\n\t\t\tconst keys = pool.keys.filter((entry) => entry.id !== id);\n\t\t\tthis.memoryExhausted.get(providerId)?.delete(id);\n\n\t\t\tif (keys.length === 0) {\n\t\t\t\tconst data = { ...this.data };\n\t\t\t\tdelete data[providerId];\n\t\t\t\tthis.data = data;\n\t\t\t\tawait this.persist();\n\t\t\t\tawait this.authStorage.delete(providerId);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tlet active = pool.active;\n\t\t\tif (active === id) {\n\t\t\t\tactive = keys[0]?.id ?? active;\n\t\t\t\tthis.data = { ...this.data, [providerId]: { active, keys } };\n\t\t\t\tawait this.persist();\n\t\t\t\tconst promoted = keys.find((entry) => entry.id === active);\n\t\t\t\tif (promoted) await this.mirrorActive(providerId, promoted.key);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tthis.data = { ...this.data, [providerId]: { active, keys } };\n\t\t\tawait this.persist();\n\t\t});\n\t}\n\n\tasync renameKey(providerId: string, id: string, name: string): Promise<void> {\n\t\treturn this.enqueue(async () => {\n\t\t\tconst pool = await this.ensurePool(providerId);\n\t\t\tif (!pool) return;\n\t\t\tconst keys = pool.keys.map((entry) => (entry.id === id ? { ...entry, name } : entry));\n\t\t\tthis.data = { ...this.data, [providerId]: { ...pool, keys } };\n\t\t\tawait this.persist();\n\t\t});\n\t}\n\n\tasync setActive(providerId: string, id: string): Promise<void> {\n\t\treturn this.enqueue(async () => {\n\t\t\tconst pool = await this.ensurePool(providerId);\n\t\t\tconst entry = pool?.keys.find((candidate) => candidate.id === id);\n\t\t\tif (!pool || !entry) return;\n\t\t\tthis.data = { ...this.data, [providerId]: { ...pool, active: id } };\n\t\t\tawait this.persist();\n\t\t\tawait this.mirrorActive(providerId, entry.key);\n\t\t});\n\t}\n\n\t/**\n\t * Mark the active key exhausted and rotate to the next non-exhausted key in\n\t * round-robin order. A parseable reset time is persisted as exhaustedUntil;\n\t * otherwise the exhaustion is process-local only. Returns the new active key,\n\t * or null when no non-exhausted alternative exists (current key stays active).\n\t */\n\tasync rotateOnFailure(providerId: string, errorMessage: string, now: number = Date.now()): Promise<SubEntry | null> {\n\t\treturn this.enqueue(async () => {\n\t\t\tconst pool = await this.ensurePool(providerId);\n\t\t\tif (!pool) return null;\n\t\t\tconst currentIndex = pool.keys.findIndex((entry) => entry.id === pool.active);\n\t\t\tif (currentIndex === -1) return null;\n\t\t\tconst current = pool.keys[currentIndex];\n\t\t\tif (!current) return null;\n\n\t\t\tconst resetAt = parseResetTimeMs(errorMessage);\n\t\t\tlet keys = pool.keys;\n\t\t\tif (resetAt !== undefined && resetAt > now) {\n\t\t\t\tkeys = pool.keys.map((entry) =>\n\t\t\t\t\tentry.id === current.id ? { ...entry, exhaustedUntil: resetAt, lastError: errorMessage } : entry,\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tconst set = this.memoryExhausted.get(providerId) ?? new Set<string>();\n\t\t\t\tset.add(current.id);\n\t\t\t\tthis.memoryExhausted.set(providerId, set);\n\t\t\t}\n\n\t\t\tconst isExhausted = (entry: SubEntry): boolean =>\n\t\t\t\tthis.memoryExhausted.get(providerId)?.has(entry.id) === true ||\n\t\t\t\t(entry.exhaustedUntil !== undefined && entry.exhaustedUntil > now);\n\n\t\t\tfor (let offset = 1; offset < keys.length; offset++) {\n\t\t\t\tconst candidate = keys[(currentIndex + offset) % keys.length];\n\t\t\t\tif (!candidate || isExhausted(candidate)) continue;\n\t\t\t\tthis.data = { ...this.data, [providerId]: { active: candidate.id, keys } };\n\t\t\t\tawait this.persist();\n\t\t\t\tawait this.mirrorActive(providerId, candidate.key);\n\t\t\t\treturn candidate;\n\t\t\t}\n\n\t\t\t// No alternative: keep the (now-exhausted) current key active, but still\n\t\t\t// persist its exhaustion state when a reset time was recorded.\n\t\t\tif (keys !== pool.keys) {\n\t\t\t\tthis.data = { ...this.data, [providerId]: { ...pool, keys } };\n\t\t\t\tawait this.persist();\n\t\t\t}\n\t\t\treturn null;\n\t\t});\n\t}\n\n\t/** Manual reactivate: clears persisted and process-local exhaustion for a key. */\n\tasync clearExhaustion(providerId: string, id: string): Promise<void> {\n\t\treturn this.enqueue(async () => {\n\t\t\tthis.memoryExhausted.get(providerId)?.delete(id);\n\t\t\tconst pool = await this.ensurePool(providerId);\n\t\t\tif (!pool) return;\n\t\t\tconst target = pool.keys.find((entry) => entry.id === id);\n\t\t\tif (!target || (target.exhaustedUntil === undefined && target.lastError === undefined)) return;\n\t\t\tconst keys = pool.keys.map((entry) => {\n\t\t\t\tif (entry.id !== id) return entry;\n\t\t\t\tconst { exhaustedUntil: _exhaustedUntil, lastError: _lastError, ...rest } = entry;\n\t\t\t\treturn rest;\n\t\t\t});\n\t\t\tthis.data = { ...this.data, [providerId]: { ...pool, keys } };\n\t\t\tawait this.persist();\n\t\t});\n\t}\n}\n"]}
1
+ {"version":3,"file":"subscriptions.js","sourceRoot":"","sources":["../../src/core/subscriptions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAA2B,sBAAsB,EAAE,0BAA0B,EAAE,MAAM,mBAAmB,CAAC;AAChH,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAkBpD,MAAM,OAAO,mBAAmB;IACvB,IAAI,GAAqB,EAAE,CAAC;IAC5B,MAAM,GAAG,KAAK,CAAC;IACf,OAAO,CAAqB;IAC5B,WAAW,CAAkB;IACrC,2EAA2E;IACnE,KAAK,GAAqB,OAAO,CAAC,OAAO,EAAE,CAAC;IACpD,qEAAqE;IACrE,oEAAoE;IAC5D,eAAe,GAAG,IAAI,GAAG,EAAuB,CAAC;IAEzD,YAAoB,WAA4B,EAAE,OAA2B,EAAE;QAC9E,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IAAA,CACvB;IAED,MAAM,CAAC,MAAM,CAAC,WAA4B,EAAE,IAAa,EAAuB;QAC/E,OAAO,IAAI,mBAAmB,CAC7B,WAAW,EACX,IAAI,sBAAsB,CAAC,IAAI,IAAI,IAAI,CAAC,WAAW,EAAE,EAAE,oBAAoB,CAAC,CAAC,CAC7E,CAAC;IAAA,CACF;IAED,MAAM,CAAC,WAAW,CAAC,WAA4B,EA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M,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC;gBACrC,IAAI,KAAK,CAAC,EAAE,KAAK,EAAE;oBAAE,OAAO,KAAK,CAAC;gBAClC,MAAM,EAAE,cAAc,EAAE,eAAe,EAAE,SAAS,EAAE,UAAU,EAAE,GAAG,IAAI,EAAE,GAAG,KAAK,CAAC;gBAClF,OAAO,IAAI,CAAC;YAAA,CACZ,CAAC,CAAC;YACH,IAAI,CAAC,IAAI,GAAG,EAAE,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC,UAAU,CAAC,EAAE,EAAE,GAAG,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC;YAC9D,MAAM,IAAI,CAAC,OAAO,EAAE,CAAC;QAAA,CACrB,CAAC,CAAC;IAAA,CACH;CACD","sourcesContent":["/**\n * lunr: multi-subscription API-key pools per provider.\n *\n * The pool lives in subscriptions.json next to auth.json; auth.json always\n * holds the ACTIVE credential, so rotation is just mirroring the chosen pool\n * key into auth.json via AuthStorage.modify. Persistence reuses the\n * AuthStorage backend classes (proper-lockfile guarded read-modify-write,\n * mode 0600) pointed at the subscriptions.json path.\n *\n * Raw keys are never logged or embedded in error messages — errors refer to\n * provider and key ids only.\n */\n\nimport type { Credential, CredentialStore } from \"@ashx-j/lunr-ai\";\nimport { join } from \"path\";\nimport { getAgentDir } from \"../config.ts\";\nimport { type AuthStorageBackend, FileAuthStorageBackend, InMemoryAuthStorageBackend } from \"./auth-storage.ts\";\nimport { parseResetTimeMs } from \"./usage-limit.ts\";\n\nexport interface SubEntry {\n\tid: string;\n\tname: string;\n\tkey: string;\n\taddedAt: number;\n\texhaustedUntil?: number;\n\tlastError?: string;\n}\n\ninterface ProviderPool {\n\tactive: string;\n\tkeys: SubEntry[];\n}\n\ntype SubscriptionData = Record<string, ProviderPool>;\n\nexport class SubscriptionManager {\n\tprivate data: SubscriptionData = {};\n\tprivate loaded = false;\n\tprivate storage: AuthStorageBackend;\n\tprivate authStorage: CredentialStore;\n\t// In-process write queue so mutations serialize even before the file lock.\n\tprivate queue: Promise<unknown> = Promise.resolve();\n\t// Per-provider ids of keys exhausted without a parseable reset time.\n\t// Process-local on purpose: infinite exhaustion is never persisted.\n\tprivate memoryExhausted = new Map<string, Set<string>>();\n\n\tprivate constructor(authStorage: CredentialStore, storage: AuthStorageBackend) {\n\t\tthis.authStorage = authStorage;\n\t\tthis.storage = storage;\n\t}\n\n\tstatic create(authStorage: CredentialStore, path?: string): SubscriptionManager {\n\t\treturn new SubscriptionManager(\n\t\t\tauthStorage,\n\t\t\tnew FileAuthStorageBackend(path ?? join(getAgentDir(), \"subscriptions.json\")),\n\t\t);\n\t}\n\n\tstatic fromStorage(authStorage: CredentialStore, storage: AuthStorageBackend): SubscriptionManager {\n\t\treturn new SubscriptionManager(authStorage, storage);\n\t}\n\n\tstatic inMemory(authStorage: CredentialStore, data: SubscriptionData = {}): SubscriptionManager {\n\t\tconst storage = new InMemoryAuthStorageBackend();\n\t\tstorage.withLock(() => ({ result: undefined, next: JSON.stringify(data, null, 2) }));\n\t\treturn SubscriptionManager.fromStorage(authStorage, storage);\n\t}\n\n\tprivate parseStorageData(content: string | undefined): SubscriptionData {\n\t\tif (!content) {\n\t\t\treturn {};\n\t\t}\n\t\treturn JSON.parse(content) as SubscriptionData;\n\t}\n\n\tprivate ensureLoaded(): void {\n\t\tif (this.loaded) return;\n\t\tthis.loaded = true;\n\t\tlet content: string | undefined;\n\t\ttry {\n\t\t\tthis.storage.withLock((current) => {\n\t\t\t\tcontent = current;\n\t\t\t\treturn { result: undefined };\n\t\t\t});\n\t\t\tthis.data = this.parseStorageData(content);\n\t\t} catch {\n\t\t\t// Preserve the empty snapshot; a malformed file is never overwritten by a load.\n\t\t}\n\t}\n\n\tprivate enqueue<T>(fn: () => Promise<T>): Promise<T> {\n\t\tconst next = this.queue.then(fn);\n\t\tthis.queue = next.catch(() => {});\n\t\treturn next;\n\t}\n\n\tprivate persist(): Promise<void> {\n\t\treturn this.storage.withLockAsync(async () => ({\n\t\t\tresult: undefined,\n\t\t\tnext: JSON.stringify(this.data, null, 2),\n\t\t}));\n\t}\n\n\t/** Raw stored credential read via the modify path (returning undefined leaves it unchanged). */\n\tprivate async readRawCredential(providerId: string): Promise<Credential | undefined> {\n\t\tlet current: Credential | undefined;\n\t\tawait this.authStorage.modify(providerId, async (credential) => {\n\t\t\tcurrent = credential;\n\t\t\treturn undefined;\n\t\t});\n\t\treturn current;\n\t}\n\n\t/**\n\t * Pool for a provider, lazy-importing an existing stored api_key credential\n\t * as \"Sub 1\" on first access. OAuth credentials are not imported.\n\t */\n\tprivate async ensurePool(providerId: string): Promise<ProviderPool | undefined> {\n\t\tthis.ensureLoaded();\n\t\tconst existing = this.data[providerId];\n\t\tif (existing) return existing;\n\n\t\tconst credential = await this.readRawCredential(providerId);\n\t\tif (credential?.type !== \"api_key\" || credential.key === undefined) return undefined;\n\n\t\tconst pool: ProviderPool = {\n\t\t\tactive: \"1\",\n\t\t\tkeys: [{ id: \"1\", name: \"Sub 1\", key: credential.key, addedAt: Date.now() }],\n\t\t};\n\t\tthis.data = { ...this.data, [providerId]: pool };\n\t\tawait this.persist();\n\t\treturn pool;\n\t}\n\n\tprivate nextId(pool: ProviderPool): string {\n\t\tlet max = 0;\n\t\tfor (const entry of pool.keys) {\n\t\t\tconst numeric = Number.parseInt(entry.id, 10);\n\t\t\tif (Number.isFinite(numeric) && numeric > max) max = numeric;\n\t\t}\n\t\treturn String(max + 1);\n\t}\n\n\tprivate async mirrorActive(providerId: string, key: string): Promise<void> {\n\t\tawait this.authStorage.modify(providerId, async () => ({ type: \"api_key\", key }));\n\t}\n\n\tasync list(providerId: string): Promise<SubEntry[]> {\n\t\treturn this.enqueue(async () => {\n\t\t\tconst pool = await this.ensurePool(providerId);\n\t\t\treturn pool ? [...pool.keys] : [];\n\t\t});\n\t}\n\n\tasync getActive(providerId: string): Promise<SubEntry | undefined> {\n\t\treturn this.enqueue(async () => {\n\t\t\tconst pool = await this.ensurePool(providerId);\n\t\t\treturn pool?.keys.find((entry) => entry.id === pool.active);\n\t\t});\n\t}\n\n\tasync addKey(providerId: string, key: string, name?: string): Promise<SubEntry> {\n\t\treturn this.enqueue(async () => {\n\t\t\tthis.ensureLoaded();\n\t\t\tconst pool = await this.ensurePool(providerId);\n\t\t\tconst id = pool ? this.nextId(pool) : \"1\";\n\t\t\tconst entry: SubEntry = { id, name: name ?? `Sub ${id}`, key, addedAt: Date.now() };\n\t\t\tconst keys = [...(pool?.keys ?? []), entry];\n\t\t\tthis.data = { ...this.data, [providerId]: { active: id, keys } };\n\t\t\tawait this.persist();\n\t\t\tawait this.mirrorActive(providerId, key);\n\t\t\treturn entry;\n\t\t});\n\t}\n\n\tasync removeKey(providerId: string, id: string): Promise<void> {\n\t\treturn this.enqueue(async () => {\n\t\t\tconst pool = await this.ensurePool(providerId);\n\t\t\tif (!pool || !pool.keys.some((entry) => entry.id === id)) return;\n\n\t\t\tconst keys = pool.keys.filter((entry) => entry.id !== id);\n\t\t\tthis.memoryExhausted.get(providerId)?.delete(id);\n\n\t\t\tif (keys.length === 0) {\n\t\t\t\tconst data = { ...this.data };\n\t\t\t\tdelete data[providerId];\n\t\t\t\tthis.data = data;\n\t\t\t\tawait this.persist();\n\t\t\t\tawait this.authStorage.delete(providerId);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tlet active = pool.active;\n\t\t\tif (active === id) {\n\t\t\t\tactive = keys[0]?.id ?? active;\n\t\t\t\tthis.data = { ...this.data, [providerId]: { active, keys } };\n\t\t\t\tawait this.persist();\n\t\t\t\tconst promoted = keys.find((entry) => entry.id === active);\n\t\t\t\tif (promoted) await this.mirrorActive(providerId, promoted.key);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tthis.data = { ...this.data, [providerId]: { active, keys } };\n\t\t\tawait this.persist();\n\t\t});\n\t}\n\n\tasync renameKey(providerId: string, id: string, name: string): Promise<void> {\n\t\treturn this.enqueue(async () => {\n\t\t\tconst pool = await this.ensurePool(providerId);\n\t\t\tif (!pool) return;\n\t\t\tconst keys = pool.keys.map((entry) => (entry.id === id ? { ...entry, name } : entry));\n\t\t\tthis.data = { ...this.data, [providerId]: { ...pool, keys } };\n\t\t\tawait this.persist();\n\t\t});\n\t}\n\n\tasync setActive(providerId: string, id: string): Promise<void> {\n\t\treturn this.enqueue(async () => {\n\t\t\tconst pool = await this.ensurePool(providerId);\n\t\t\tconst entry = pool?.keys.find((candidate) => candidate.id === id);\n\t\t\tif (!pool || !entry) return;\n\t\t\tthis.data = { ...this.data, [providerId]: { ...pool, active: id } };\n\t\t\tawait this.persist();\n\t\t\tawait this.mirrorActive(providerId, entry.key);\n\t\t});\n\t}\n\n\t/**\n\t * Mark the active key exhausted and rotate to the next non-exhausted key in\n\t * round-robin order. A parseable reset time is persisted as exhaustedUntil;\n\t * otherwise the exhaustion is process-local only. Returns the new active key,\n\t * or null when no non-exhausted alternative exists (current key stays active).\n\t */\n\tasync rotateOnFailure(providerId: string, errorMessage: string, now: number = Date.now()): Promise<SubEntry | null> {\n\t\treturn this.enqueue(async () => {\n\t\t\tconst pool = await this.ensurePool(providerId);\n\t\t\tif (!pool) return null;\n\t\t\tconst currentIndex = pool.keys.findIndex((entry) => entry.id === pool.active);\n\t\t\tif (currentIndex === -1) return null;\n\t\t\tconst current = pool.keys[currentIndex];\n\t\t\tif (!current) return null;\n\n\t\t\tconst resetAt = parseResetTimeMs(errorMessage);\n\t\t\tlet keys = pool.keys;\n\t\t\tif (resetAt !== undefined && resetAt > now) {\n\t\t\t\tkeys = pool.keys.map((entry) =>\n\t\t\t\t\tentry.id === current.id ? { ...entry, exhaustedUntil: resetAt, lastError: errorMessage } : entry,\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tconst set = this.memoryExhausted.get(providerId) ?? new Set<string>();\n\t\t\t\tset.add(current.id);\n\t\t\t\tthis.memoryExhausted.set(providerId, set);\n\t\t\t}\n\n\t\t\tconst isExhausted = (entry: SubEntry): boolean =>\n\t\t\t\tthis.memoryExhausted.get(providerId)?.has(entry.id) === true ||\n\t\t\t\t(entry.exhaustedUntil !== undefined && entry.exhaustedUntil > now);\n\n\t\t\tfor (let offset = 1; offset < keys.length; offset++) {\n\t\t\t\tconst candidate = keys[(currentIndex + offset) % keys.length];\n\t\t\t\tif (!candidate || isExhausted(candidate)) continue;\n\t\t\t\tthis.data = { ...this.data, [providerId]: { active: candidate.id, keys } };\n\t\t\t\tawait this.persist();\n\t\t\t\tawait this.mirrorActive(providerId, candidate.key);\n\t\t\t\treturn candidate;\n\t\t\t}\n\n\t\t\t// No alternative: keep the (now-exhausted) current key active, but still\n\t\t\t// persist its exhaustion state when a reset time was recorded.\n\t\t\tif (keys !== pool.keys) {\n\t\t\t\tthis.data = { ...this.data, [providerId]: { ...pool, keys } };\n\t\t\t\tawait this.persist();\n\t\t\t}\n\t\t\treturn null;\n\t\t});\n\t}\n\n\t/** Manual reactivate: clears persisted and process-local exhaustion for a key. */\n\tasync clearExhaustion(providerId: string, id: string): Promise<void> {\n\t\treturn this.enqueue(async () => {\n\t\t\tthis.memoryExhausted.get(providerId)?.delete(id);\n\t\t\tconst pool = await this.ensurePool(providerId);\n\t\t\tif (!pool) return;\n\t\t\tconst target = pool.keys.find((entry) => entry.id === id);\n\t\t\tif (!target || (target.exhaustedUntil === undefined && target.lastError === undefined)) return;\n\t\t\tconst keys = pool.keys.map((entry) => {\n\t\t\t\tif (entry.id !== id) return entry;\n\t\t\t\tconst { exhaustedUntil: _exhaustedUntil, lastError: _lastError, ...rest } = entry;\n\t\t\t\treturn rest;\n\t\t\t});\n\t\t\tthis.data = { ...this.data, [providerId]: { ...pool, keys } };\n\t\t\tawait this.persist();\n\t\t});\n\t}\n}\n"]}
@@ -1,4 +1,4 @@
1
- import type { AgentTool } from "@earendil-works/pi-agent-core";
1
+ import type { AgentTool } from "@ashx-j/lunr-agent";
2
2
  import { type Static, Type } from "typebox";
3
3
  import type { ToolDefinition } from "../extensions/types.ts";
4
4
  import { type TruncationResult } from "./truncate.ts";
@@ -1 +1 @@
1
- {"version":3,"file":"bash.d.ts","sourceRoot":"","sources":["../../../src/core/tools/bash.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAG/D,OAAO,EAAE,KAAK,MAAM,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAY5C,OAAO,KAAK,EAAE,cAAc,EAA2B,MAAM,wBAAwB,CAAC;AAKtF,OAAO,EAAoD,KAAK,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAkBxG,QAAA,MAAM,UAAU;;;EAGd,CAAC;AAEH,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,OAAO,UAAU,CAAC,CAAC;AAEtD,MAAM,WAAW,eAAe;IAC/B,UAAU,CAAC,EAAE,gBAAgB,CAAC;IAC9B,cAAc,CAAC,EAAE,MAAM,CAAC;CACxB;AAED;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC9B;;;;;;OAMG;IACH,IAAI,EAAE,CACL,OAAO,EAAE,MAAM,EACf,GAAG,EAAE,MAAM,EACX,OAAO,EAAE;QACR,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;QAC/B,MAAM,CAAC,EAAE,WAAW,CAAC;QACrB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,GAAG,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC;KACxB,KACG,OAAO,CAAC;QAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,CAAC,CAAC;CAC1C;AAED;;;;;GAKG;AACH,wBAAgB,yBAAyB,CAAC,OAAO,CAAC,EAAE;IAAE,SAAS,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,cAAc,CAiF9G;AAED,MAAM,WAAW,gBAAgB;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC,UAAU,CAAC;CACvB;AAED,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,EAAE,gBAAgB,KAAK,gBAAgB,CAAC;AAO5E,MAAM,WAAW,eAAe;IAC/B,oEAAoE;IACpE,UAAU,CAAC,EAAE,cAAc,CAAC;IAC5B,mFAAmF;IACnF,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,iDAAiD;IACjD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,2DAA2D;IAC3D,SAAS,CAAC,EAAE,aAAa,CAAC;CAC1B;AAKD,KAAK,eAAe,GAAG;IACtB,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,QAAQ,EAAE,MAAM,CAAC,OAAO,GAAG,SAAS,CAAC;CACrC,CAAC;AAmHF,wBAAgB,wBAAwB,CACvC,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE,eAAe,GACvB,cAAc,CAAC,OAAO,UAAU,EAAE,eAAe,GAAG,SAAS,EAAE,eAAe,CAAC,CA2LjF;AAED,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,SAAS,CAAC,OAAO,UAAU,CAAC,CAEnG","sourcesContent":["import { constants } from \"node:fs\";\nimport { access as fsAccess } from \"node:fs/promises\";\nimport type { AgentTool } from \"@earendil-works/pi-agent-core\";\nimport { Container, Text, truncateToWidth } from \"@earendil-works/pi-tui\";\nimport { spawn } from \"child_process\";\nimport { type Static, Type } from \"typebox\";\nimport { keyHint } from \"../../modes/interactive/components/keybinding-hints.ts\";\nimport { truncateToVisualLines } from \"../../modes/interactive/components/visual-truncate.ts\";\nimport { theme } from \"../../modes/interactive/theme/theme.ts\";\nimport { waitForChildProcess } from \"../../utils/child-process.ts\";\nimport {\n\tgetShellConfig,\n\tgetShellEnv,\n\tkillProcessTree,\n\ttrackDetachedChildPid,\n\tuntrackDetachedChildPid,\n} from \"../../utils/shell.ts\";\nimport type { ToolDefinition, ToolRenderResultOptions } from \"../extensions/types.ts\";\nimport { markExited as markProcessExited, register as registerProcess } from \"../process-registry.ts\";\nimport { OutputAccumulator } from \"./output-accumulator.ts\";\nimport { getTextOutput, invalidArgText, str, toolStatusDotFromContext } from \"./render-utils.ts\";\nimport { wrapToolDefinition } from \"./tool-definition-wrapper.ts\";\nimport { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, formatSize, type TruncationResult } from \"./truncate.ts\";\n\nconst MAX_TIMEOUT_MS = 2_147_483_647;\nconst MAX_TIMEOUT_SECONDS = MAX_TIMEOUT_MS / 1000;\n\nfunction resolveTimeoutMs(timeout: number | undefined): number | undefined {\n\tif (timeout === undefined) return undefined;\n\tif (!Number.isFinite(timeout) || timeout <= 0) {\n\t\tthrow new Error(\"Invalid timeout: must be a finite number of seconds\");\n\t}\n\n\tconst timeoutMs = timeout * 1000;\n\tif (timeoutMs > MAX_TIMEOUT_MS) {\n\t\tthrow new Error(`Invalid timeout: maximum is ${MAX_TIMEOUT_SECONDS} seconds`);\n\t}\n\treturn timeoutMs;\n}\n\nconst bashSchema = Type.Object({\n\tcommand: Type.String({ description: \"Bash command to execute\" }),\n\ttimeout: Type.Optional(Type.Number({ description: \"Timeout in seconds (optional, no default timeout)\" })),\n});\n\nexport type BashToolInput = Static<typeof bashSchema>;\n\nexport interface BashToolDetails {\n\ttruncation?: TruncationResult;\n\tfullOutputPath?: string;\n}\n\n/**\n * Pluggable operations for the bash tool.\n * Override these to delegate command execution to remote systems (for example SSH).\n */\nexport interface BashOperations {\n\t/**\n\t * Execute a command and stream output.\n\t * @param command The command to execute\n\t * @param cwd Working directory\n\t * @param options Execution options\n\t * @returns Promise resolving to exit code (null if killed)\n\t */\n\texec: (\n\t\tcommand: string,\n\t\tcwd: string,\n\t\toptions: {\n\t\t\tonData: (data: Buffer) => void;\n\t\t\tsignal?: AbortSignal;\n\t\t\ttimeout?: number;\n\t\t\tenv?: NodeJS.ProcessEnv;\n\t\t},\n\t) => Promise<{ exitCode: number | null }>;\n}\n\n/**\n * Create bash operations using pi's built-in local shell execution backend.\n *\n * This is useful for extensions that intercept user_bash and still want pi's\n * standard local shell behavior while wrapping or rewriting commands.\n */\nexport function createLocalBashOperations(options?: { shellPath?: string; sessionId?: string }): BashOperations {\n\treturn {\n\t\texec: async (command, cwd, { onData, signal, timeout, env }) => {\n\t\t\tconst timeoutMs = resolveTimeoutMs(timeout);\n\t\t\tif (signal?.aborted) {\n\t\t\t\tthrow new Error(\"aborted\");\n\t\t\t}\n\t\t\tconst shellConfig = getShellConfig(options?.shellPath);\n\t\t\ttry {\n\t\t\t\tawait fsAccess(cwd, constants.F_OK);\n\t\t\t} catch {\n\t\t\t\tthrow new Error(`Working directory does not exist: ${cwd}\\nCannot execute bash commands.`);\n\t\t\t}\n\n\t\t\tconst commandFromStdin = shellConfig.commandTransport === \"stdin\";\n\t\t\tconst child = spawn(shellConfig.shell, commandFromStdin ? shellConfig.args : [...shellConfig.args, command], {\n\t\t\t\tcwd,\n\t\t\t\tdetached: process.platform !== \"win32\",\n\t\t\t\tenv: env ?? getShellEnv(),\n\t\t\t\tstdio: [commandFromStdin ? \"pipe\" : \"ignore\", \"pipe\", \"pipe\"],\n\t\t\t\twindowsHide: true,\n\t\t\t});\n\t\t\tif (commandFromStdin) {\n\t\t\t\tchild.stdin?.on(\"error\", () => {});\n\t\t\t\tchild.stdin?.end(command);\n\t\t\t}\n\t\t\tif (child.pid) trackDetachedChildPid(child.pid);\n\t\t\t// lunr: register the process for /processes tracking.\n\t\t\tif (child.pid) {\n\t\t\t\ttry {\n\t\t\t\t\tregisterProcess(child.pid, command, cwd, options?.sessionId);\n\t\t\t\t} catch {}\n\t\t\t}\n\t\t\tlet timedOut = false;\n\t\t\tlet timeoutHandle: NodeJS.Timeout | undefined;\n\t\t\tconst onAbort = () => {\n\t\t\t\tif (child.pid) killProcessTree(child.pid);\n\t\t\t};\n\n\t\t\ttry {\n\t\t\t\t// Set timeout if provided.\n\t\t\t\tif (timeoutMs !== undefined) {\n\t\t\t\t\ttimeoutHandle = setTimeout(() => {\n\t\t\t\t\t\ttimedOut = true;\n\t\t\t\t\t\tif (child.pid) killProcessTree(child.pid);\n\t\t\t\t\t}, timeoutMs);\n\t\t\t\t}\n\t\t\t\t// Stream stdout and stderr.\n\t\t\t\tchild.stdout?.on(\"data\", onData);\n\t\t\t\tchild.stderr?.on(\"data\", onData);\n\t\t\t\t// Handle abort signal by killing the entire process tree.\n\t\t\t\tif (signal) {\n\t\t\t\t\tif (signal.aborted) onAbort();\n\t\t\t\t\telse signal.addEventListener(\"abort\", onAbort, { once: true });\n\t\t\t\t}\n\t\t\t\t// Handle shell spawn errors and wait for the process to terminate without hanging\n\t\t\t\t// on inherited stdio handles held by detached descendants.\n\t\t\t\tconst exitCode = await waitForChildProcess(child);\n\t\t\t\tif (signal?.aborted) {\n\t\t\t\t\tthrow new Error(\"aborted\");\n\t\t\t\t}\n\t\t\t\tif (timedOut) {\n\t\t\t\t\tthrow new Error(`timeout:${timeout}`);\n\t\t\t\t}\n\t\t\t\treturn { exitCode };\n\t\t\t} finally {\n\t\t\t\tif (child.pid) untrackDetachedChildPid(child.pid);\n\t\t\t\t// lunr: unregister from /processes if the process has exited; keep it if still\n\t\t\t\t// alive (detached/backgrounded dev servers survive the shell call).\n\t\t\t\tif (child.pid) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\t// lunr: keep finished processes visible briefly so /processes can show\n\t\t\t\t\t\t// their exit state; markExited deletes trivial fast commands immediately.\n\t\t\t\t\t\tmarkProcessExited(child.pid, child.exitCode);\n\t\t\t\t\t} catch {}\n\t\t\t\t}\n\t\t\t\tif (timeoutHandle) clearTimeout(timeoutHandle);\n\t\t\t\tif (signal) signal.removeEventListener(\"abort\", onAbort);\n\t\t\t}\n\t\t},\n\t};\n}\n\nexport interface BashSpawnContext {\n\tcommand: string;\n\tcwd: string;\n\tenv: NodeJS.ProcessEnv;\n}\n\nexport type BashSpawnHook = (context: BashSpawnContext) => BashSpawnContext;\n\nfunction resolveSpawnContext(command: string, cwd: string, spawnHook?: BashSpawnHook): BashSpawnContext {\n\tconst baseContext: BashSpawnContext = { command, cwd, env: { ...getShellEnv() } };\n\treturn spawnHook ? spawnHook(baseContext) : baseContext;\n}\n\nexport interface BashToolOptions {\n\t/** Custom operations for command execution. Default: local shell */\n\toperations?: BashOperations;\n\t/** Command prefix prepended to every command (for example shell setup commands) */\n\tcommandPrefix?: string;\n\t/** Optional explicit shell path from settings */\n\tshellPath?: string;\n\t/** Hook to adjust command, cwd, or env before execution */\n\tspawnHook?: BashSpawnHook;\n}\n\nconst BASH_PREVIEW_LINES = 5;\nconst BASH_UPDATE_THROTTLE_MS = 100;\n\ntype BashRenderState = {\n\tstartedAt: number | undefined;\n\tendedAt: number | undefined;\n\tinterval: NodeJS.Timeout | undefined;\n};\n\ntype BashResultRenderState = {\n\tcachedWidth: number | undefined;\n\tcachedLines: string[] | undefined;\n\tcachedSkipped: number | undefined;\n};\n\nclass BashResultRenderComponent extends Container {\n\tstate: BashResultRenderState = {\n\t\tcachedWidth: undefined,\n\t\tcachedLines: undefined,\n\t\tcachedSkipped: undefined,\n\t};\n}\n\nfunction formatDuration(ms: number): string {\n\treturn `${(ms / 1000).toFixed(1)}s`;\n}\n\n// lunr: slim header — collapsed calls show only the first line of the command,\n// capped at this many chars; an ellipsis marks either kind of truncation.\nconst MAX_COLLAPSED_COMMAND_CHARS = 100;\n\nfunction formatBashCall(\n\targs: { command?: string; timeout?: number } | undefined,\n\toptions?: { expanded?: boolean; compact?: boolean },\n): string {\n\tconst command = str(args?.command);\n\tconst timeout = args?.timeout as number | undefined;\n\t// lunr: compact-by-default — the timeout suffix is noise on a one-line header;\n\t// it stays visible while streaming and in the expanded view.\n\tconst timeoutSuffix = timeout && !options?.compact ? theme.fg(\"muted\", ` (timeout ${timeout}s)`) : \"\";\n\tlet commandDisplay = command === null ? invalidArgText(theme) : command ? command : theme.fg(\"toolOutput\", \"...\");\n\tif (!options?.expanded && command) {\n\t\tconst firstLine = command.split(\"\\n\")[0];\n\t\tconst capped = firstLine.length > MAX_COLLAPSED_COMMAND_CHARS;\n\t\tconst base = capped ? firstLine.slice(0, MAX_COLLAPSED_COMMAND_CHARS) : firstLine;\n\t\tcommandDisplay = capped || base.length < command.length ? `${base} …` : base;\n\t}\n\treturn theme.fg(\"toolTitle\", theme.bold(`$ ${commandDisplay}`)) + timeoutSuffix;\n}\n\nfunction rebuildBashResultRenderComponent(\n\tcomponent: BashResultRenderComponent,\n\tresult: {\n\t\tcontent: Array<{ type: string; text?: string; data?: string; mimeType?: string }>;\n\t\tdetails?: BashToolDetails;\n\t},\n\toptions: ToolRenderResultOptions,\n\tshowImages: boolean,\n\tstartedAt: number | undefined,\n\tendedAt: number | undefined,\n\t// lunr: compact-by-default — finished, successful, non-expanded calls skip the\n\t// output preview and the \"Took\" footer (duration moves into the call header).\n\tcompact = false,\n): void {\n\tconst state = component.state;\n\tcomponent.clear();\n\n\tlet output = getTextOutput(result as any, showImages).trim();\n\tconst truncation = result.details?.truncation;\n\tconst fullOutputPath = result.details?.fullOutputPath;\n\tif (!options.isPartial && truncation?.truncated && fullOutputPath && output.endsWith(\"]\")) {\n\t\tconst footerStart = output.lastIndexOf(\"\\n\\n[\");\n\t\tif (footerStart !== -1 && output.slice(footerStart).includes(fullOutputPath)) {\n\t\t\toutput = output.slice(0, footerStart).trimEnd();\n\t\t}\n\t}\n\n\tif (!compact && output) {\n\t\tconst styledOutput = output\n\t\t\t.split(\"\\n\")\n\t\t\t.map((line) => theme.fg(\"toolOutput\", line))\n\t\t\t.join(\"\\n\");\n\n\t\tif (options.expanded) {\n\t\t\tcomponent.addChild(new Text(`\\n${styledOutput}`, 0, 0));\n\t\t} else {\n\t\t\tcomponent.addChild({\n\t\t\t\trender: (width: number) => {\n\t\t\t\t\tif (state.cachedLines === undefined || state.cachedWidth !== width) {\n\t\t\t\t\t\tconst preview = truncateToVisualLines(styledOutput, BASH_PREVIEW_LINES, width);\n\t\t\t\t\t\tstate.cachedLines = preview.visualLines;\n\t\t\t\t\t\tstate.cachedSkipped = preview.skippedCount;\n\t\t\t\t\t\tstate.cachedWidth = width;\n\t\t\t\t\t}\n\t\t\t\t\tif (state.cachedSkipped && state.cachedSkipped > 0) {\n\t\t\t\t\t\tconst hint =\n\t\t\t\t\t\t\ttheme.fg(\"muted\", `... (${state.cachedSkipped} earlier lines,`) +\n\t\t\t\t\t\t\t` ${keyHint(\"app.tools.expand\", \"to expand\")}${theme.fg(\"muted\", \")\")}`;\n\t\t\t\t\t\treturn [\"\", truncateToWidth(hint, width, \"...\"), ...(state.cachedLines ?? [])];\n\t\t\t\t\t}\n\t\t\t\t\treturn [\"\", ...(state.cachedLines ?? [])];\n\t\t\t\t},\n\t\t\t\tinvalidate: () => {\n\t\t\t\t\tstate.cachedWidth = undefined;\n\t\t\t\t\tstate.cachedLines = undefined;\n\t\t\t\t\tstate.cachedSkipped = undefined;\n\t\t\t\t},\n\t\t\t});\n\t\t}\n\t}\n\n\t// lunr: the truncation/full-output notice is intentionally NOT rendered in\n\t// the TUI — the model still gets it in the result text (formatOutput), and\n\t// the temp-log path is noise on screen.\n\n\tif (!compact && startedAt !== undefined) {\n\t\tconst label = options.isPartial ? \"Elapsed\" : \"Took\";\n\t\tconst endTime = endedAt ?? Date.now();\n\t\tcomponent.addChild(new Text(`\\n${theme.fg(\"muted\", `${label} ${formatDuration(endTime - startedAt)}`)}`, 0, 0));\n\t}\n}\n\nexport function createBashToolDefinition(\n\tcwd: string,\n\toptions?: BashToolOptions,\n): ToolDefinition<typeof bashSchema, BashToolDetails | undefined, BashRenderState> {\n\tconst ops = options?.operations ?? createLocalBashOperations({ shellPath: options?.shellPath });\n\tconst commandPrefix = options?.commandPrefix;\n\tconst spawnHook = options?.spawnHook;\n\treturn {\n\t\tname: \"bash\",\n\t\tlabel: \"bash\",\n\t\tdescription: `Execute a bash command in the current working directory. Returns stdout and stderr. Output is truncated to last ${DEFAULT_MAX_LINES} lines or ${DEFAULT_MAX_BYTES / 1024}KB (whichever is hit first). If truncated, full output is saved to a temp file. Optionally provide a timeout in seconds.`,\n\t\tpromptSnippet: \"Execute bash commands (ls, grep, find, etc.)\",\n\t\tparameters: bashSchema,\n\t\tasync execute(\n\t\t\t_toolCallId,\n\t\t\t{ command, timeout }: { command: string; timeout?: number },\n\t\t\tsignal?: AbortSignal,\n\t\t\tonUpdate?,\n\t\t\t_ctx?,\n\t\t) {\n\t\t\tconst resolvedCommand = commandPrefix ? `${commandPrefix}\\n${command}` : command;\n\t\t\tconst spawnContext = resolveSpawnContext(resolvedCommand, cwd, spawnHook);\n\t\t\tconst output = new OutputAccumulator({ tempFilePrefix: \"lunr-bash\" }); // lunr: renamed from pi-bash\n\t\t\tlet acceptingOutput = true;\n\t\t\tlet updateTimer: NodeJS.Timeout | undefined;\n\t\t\tlet updateDirty = false;\n\t\t\tlet lastUpdateAt = 0;\n\n\t\t\tconst emitOutputUpdate = () => {\n\t\t\t\tif (!onUpdate || !updateDirty) return;\n\t\t\t\tupdateDirty = false;\n\t\t\t\tlastUpdateAt = Date.now();\n\t\t\t\tconst snapshot = output.snapshot({ persistIfTruncated: true });\n\t\t\t\tonUpdate({\n\t\t\t\t\tcontent: [{ type: \"text\", text: snapshot.content || \"\" }],\n\t\t\t\t\tdetails: {\n\t\t\t\t\t\ttruncation: snapshot.truncation.truncated ? snapshot.truncation : undefined,\n\t\t\t\t\t\tfullOutputPath: snapshot.fullOutputPath,\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t};\n\n\t\t\tconst clearUpdateTimer = () => {\n\t\t\t\tif (updateTimer) {\n\t\t\t\t\tclearTimeout(updateTimer);\n\t\t\t\t\tupdateTimer = undefined;\n\t\t\t\t}\n\t\t\t};\n\n\t\t\tconst scheduleOutputUpdate = () => {\n\t\t\t\tif (!onUpdate) return;\n\t\t\t\tupdateDirty = true;\n\t\t\t\tconst delay = BASH_UPDATE_THROTTLE_MS - (Date.now() - lastUpdateAt);\n\t\t\t\tif (delay <= 0) {\n\t\t\t\t\tclearUpdateTimer();\n\t\t\t\t\temitOutputUpdate();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tupdateTimer ??= setTimeout(() => {\n\t\t\t\t\tupdateTimer = undefined;\n\t\t\t\t\temitOutputUpdate();\n\t\t\t\t}, delay);\n\t\t\t};\n\n\t\t\tif (onUpdate) {\n\t\t\t\tonUpdate({ content: [], details: undefined });\n\t\t\t}\n\n\t\t\tconst handleData = (data: Buffer) => {\n\t\t\t\tif (!acceptingOutput) return;\n\t\t\t\toutput.append(data);\n\t\t\t\tscheduleOutputUpdate();\n\t\t\t};\n\n\t\t\tconst finishOutput = async () => {\n\t\t\t\tacceptingOutput = false;\n\t\t\t\toutput.finish();\n\t\t\t\tclearUpdateTimer();\n\t\t\t\temitOutputUpdate();\n\t\t\t\tconst snapshot = output.snapshot({ persistIfTruncated: true });\n\t\t\t\tawait output.closeTempFile();\n\t\t\t\treturn snapshot;\n\t\t\t};\n\n\t\t\tconst formatOutput = (snapshot: Awaited<ReturnType<typeof finishOutput>>, emptyText = \"(no output)\") => {\n\t\t\t\tconst truncation = snapshot.truncation;\n\t\t\t\tlet text = snapshot.content || emptyText;\n\t\t\t\tlet details: BashToolDetails | undefined;\n\t\t\t\tif (truncation.truncated) {\n\t\t\t\t\tdetails = { truncation, fullOutputPath: snapshot.fullOutputPath };\n\t\t\t\t\tconst startLine = truncation.totalLines - truncation.outputLines + 1;\n\t\t\t\t\tconst endLine = truncation.totalLines;\n\t\t\t\t\tif (truncation.lastLinePartial) {\n\t\t\t\t\t\tconst lastLineSize = formatSize(output.getLastLineBytes());\n\t\t\t\t\t\ttext += `\\n\\n[Showing last ${formatSize(truncation.outputBytes)} of line ${endLine} (line is ${lastLineSize}). Full output: ${snapshot.fullOutputPath}]`;\n\t\t\t\t\t} else if (truncation.truncatedBy === \"lines\") {\n\t\t\t\t\t\ttext += `\\n\\n[Showing lines ${startLine}-${endLine} of ${truncation.totalLines}. Full output: ${snapshot.fullOutputPath}]`;\n\t\t\t\t\t} else {\n\t\t\t\t\t\ttext += `\\n\\n[Showing lines ${startLine}-${endLine} of ${truncation.totalLines} (${formatSize(DEFAULT_MAX_BYTES)} limit). Full output: ${snapshot.fullOutputPath}]`;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn { text, details };\n\t\t\t};\n\n\t\t\tconst appendStatus = (text: string, status: string) => `${text ? `${text}\\n\\n` : \"\"}${status}`;\n\n\t\t\ttry {\n\t\t\t\tlet exitCode: number | null;\n\t\t\t\ttry {\n\t\t\t\t\tconst result = await ops.exec(spawnContext.command, spawnContext.cwd, {\n\t\t\t\t\t\tonData: handleData,\n\t\t\t\t\t\tsignal,\n\t\t\t\t\t\ttimeout,\n\t\t\t\t\t\tenv: spawnContext.env,\n\t\t\t\t\t});\n\t\t\t\t\texitCode = result.exitCode;\n\t\t\t\t} catch (err) {\n\t\t\t\t\tconst snapshot = await finishOutput();\n\t\t\t\t\tconst { text } = formatOutput(snapshot, \"\");\n\t\t\t\t\tif (err instanceof Error && err.message === \"aborted\") {\n\t\t\t\t\t\tthrow new Error(appendStatus(text, \"Command aborted\"));\n\t\t\t\t\t}\n\t\t\t\t\tif (err instanceof Error && err.message.startsWith(\"timeout:\")) {\n\t\t\t\t\t\tconst timeoutSecs = err.message.split(\":\")[1];\n\t\t\t\t\t\tthrow new Error(appendStatus(text, `Command timed out after ${timeoutSecs} seconds`));\n\t\t\t\t\t}\n\t\t\t\t\tthrow err;\n\t\t\t\t}\n\n\t\t\t\tconst snapshot = await finishOutput();\n\t\t\t\tconst { text: outputText, details } = formatOutput(snapshot);\n\t\t\t\tif (exitCode !== 0 && exitCode !== null) {\n\t\t\t\t\tthrow new Error(appendStatus(outputText, `Command exited with code ${exitCode}`));\n\t\t\t\t}\n\t\t\t\treturn { content: [{ type: \"text\", text: outputText }], details };\n\t\t\t} finally {\n\t\t\t\tclearUpdateTimer();\n\t\t\t}\n\t\t},\n\t\trenderCall(args, _theme, context) {\n\t\t\tconst state = context.state;\n\t\t\tif (context.executionStarted && state.startedAt === undefined) {\n\t\t\t\tstate.startedAt = Date.now();\n\t\t\t\tstate.endedAt = undefined;\n\t\t\t}\n\t\t\t// lunr: compact-by-default — stamp endedAt here too: renderCall runs before\n\t\t\t// renderResult on the final update, and the header needs the duration.\n\t\t\tif (!context.isPartial && state.startedAt !== undefined) {\n\t\t\t\tstate.endedAt ??= Date.now();\n\t\t\t}\n\t\t\t// lunr: compact-by-default — a finished, successful, non-expanded call\n\t\t\t// renders as a single slim header line with the duration folded in.\n\t\t\tconst compact = !context.isPartial && !context.expanded && !context.isError;\n\t\t\tlet header = `${toolStatusDotFromContext(context, theme)} ${formatBashCall(args, { expanded: context.expanded, compact })}`;\n\t\t\tif (compact && state.startedAt !== undefined && state.endedAt !== undefined) {\n\t\t\t\theader += theme.fg(\"muted\", ` — Took ${formatDuration(state.endedAt - state.startedAt)}`);\n\t\t\t}\n\t\t\tconst text = (context.lastComponent as Text | undefined) ?? new Text(\"\", 0, 0);\n\t\t\ttext.setText(header);\n\t\t\treturn text;\n\t\t},\n\t\trenderResult(result, options, _theme, context) {\n\t\t\tconst state = context.state;\n\t\t\tif (state.startedAt !== undefined && options.isPartial && !state.interval) {\n\t\t\t\tstate.interval = setInterval(() => context.invalidate(), 1000);\n\t\t\t}\n\t\t\tif (!options.isPartial || context.isError) {\n\t\t\t\tstate.endedAt ??= Date.now();\n\t\t\t\tif (state.interval) {\n\t\t\t\t\tclearInterval(state.interval);\n\t\t\t\t\tstate.interval = undefined;\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst component =\n\t\t\t\t(context.lastComponent as BashResultRenderComponent | undefined) ?? new BashResultRenderComponent();\n\t\t\t// lunr: compact-by-default — suppresses the output preview + \"Took\" footer.\n\t\t\tconst compact = !options.isPartial && !options.expanded && !context.isError;\n\t\t\trebuildBashResultRenderComponent(\n\t\t\t\tcomponent,\n\t\t\t\tresult as any,\n\t\t\t\toptions,\n\t\t\t\tcontext.showImages,\n\t\t\t\tstate.startedAt,\n\t\t\t\tstate.endedAt,\n\t\t\t\tcompact,\n\t\t\t);\n\t\t\tcomponent.invalidate();\n\t\t\treturn component;\n\t\t},\n\t};\n}\n\nexport function createBashTool(cwd: string, options?: BashToolOptions): AgentTool<typeof bashSchema> {\n\treturn wrapToolDefinition(createBashToolDefinition(cwd, options));\n}\n"]}
1
+ {"version":3,"file":"bash.d.ts","sourceRoot":"","sources":["../../../src/core/tools/bash.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAG/D,OAAO,EAAE,KAAK,MAAM,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAY5C,OAAO,KAAK,EAAE,cAAc,EAA2B,MAAM,wBAAwB,CAAC;AAKtF,OAAO,EAAoD,KAAK,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAkBxG,QAAA,MAAM,UAAU;;;EAGd,CAAC;AAEH,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,OAAO,UAAU,CAAC,CAAC;AAEtD,MAAM,WAAW,eAAe;IAC/B,UAAU,CAAC,EAAE,gBAAgB,CAAC;IAC9B,cAAc,CAAC,EAAE,MAAM,CAAC;CACxB;AAED;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC9B;;;;;;OAMG;IACH,IAAI,EAAE,CACL,OAAO,EAAE,MAAM,EACf,GAAG,EAAE,MAAM,EACX,OAAO,EAAE;QACR,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;QAC/B,MAAM,CAAC,EAAE,WAAW,CAAC;QACrB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,GAAG,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC;KACxB,KACG,OAAO,CAAC;QAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,CAAC,CAAC;CAC1C;AAED;;;;;GAKG;AACH,wBAAgB,yBAAyB,CAAC,OAAO,CAAC,EAAE;IAAE,SAAS,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,cAAc,CAiF9G;AAED,MAAM,WAAW,gBAAgB;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC,UAAU,CAAC;CACvB;AAED,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,EAAE,gBAAgB,KAAK,gBAAgB,CAAC;AAO5E,MAAM,WAAW,eAAe;IAC/B,oEAAoE;IACpE,UAAU,CAAC,EAAE,cAAc,CAAC;IAC5B,mFAAmF;IACnF,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,iDAAiD;IACjD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,2DAA2D;IAC3D,SAAS,CAAC,EAAE,aAAa,CAAC;CAC1B;AAKD,KAAK,eAAe,GAAG;IACtB,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,QAAQ,EAAE,MAAM,CAAC,OAAO,GAAG,SAAS,CAAC;CACrC,CAAC;AAmHF,wBAAgB,wBAAwB,CACvC,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE,eAAe,GACvB,cAAc,CAAC,OAAO,UAAU,EAAE,eAAe,GAAG,SAAS,EAAE,eAAe,CAAC,CA2LjF;AAED,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,SAAS,CAAC,OAAO,UAAU,CAAC,CAEnG","sourcesContent":["import { constants } from \"node:fs\";\nimport { access as fsAccess } from \"node:fs/promises\";\nimport type { AgentTool } from \"@ashx-j/lunr-agent\";\nimport { Container, Text, truncateToWidth } from \"@ashx-j/lunr-tui\";\nimport { spawn } from \"child_process\";\nimport { type Static, Type } from \"typebox\";\nimport { keyHint } from \"../../modes/interactive/components/keybinding-hints.ts\";\nimport { truncateToVisualLines } from \"../../modes/interactive/components/visual-truncate.ts\";\nimport { theme } from \"../../modes/interactive/theme/theme.ts\";\nimport { waitForChildProcess } from \"../../utils/child-process.ts\";\nimport {\n\tgetShellConfig,\n\tgetShellEnv,\n\tkillProcessTree,\n\ttrackDetachedChildPid,\n\tuntrackDetachedChildPid,\n} from \"../../utils/shell.ts\";\nimport type { ToolDefinition, ToolRenderResultOptions } from \"../extensions/types.ts\";\nimport { markExited as markProcessExited, register as registerProcess } from \"../process-registry.ts\";\nimport { OutputAccumulator } from \"./output-accumulator.ts\";\nimport { getTextOutput, invalidArgText, str, toolStatusDotFromContext } from \"./render-utils.ts\";\nimport { wrapToolDefinition } from \"./tool-definition-wrapper.ts\";\nimport { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, formatSize, type TruncationResult } from \"./truncate.ts\";\n\nconst MAX_TIMEOUT_MS = 2_147_483_647;\nconst MAX_TIMEOUT_SECONDS = MAX_TIMEOUT_MS / 1000;\n\nfunction resolveTimeoutMs(timeout: number | undefined): number | undefined {\n\tif (timeout === undefined) return undefined;\n\tif (!Number.isFinite(timeout) || timeout <= 0) {\n\t\tthrow new Error(\"Invalid timeout: must be a finite number of seconds\");\n\t}\n\n\tconst timeoutMs = timeout * 1000;\n\tif (timeoutMs > MAX_TIMEOUT_MS) {\n\t\tthrow new Error(`Invalid timeout: maximum is ${MAX_TIMEOUT_SECONDS} seconds`);\n\t}\n\treturn timeoutMs;\n}\n\nconst bashSchema = Type.Object({\n\tcommand: Type.String({ description: \"Bash command to execute\" }),\n\ttimeout: Type.Optional(Type.Number({ description: \"Timeout in seconds (optional, no default timeout)\" })),\n});\n\nexport type BashToolInput = Static<typeof bashSchema>;\n\nexport interface BashToolDetails {\n\ttruncation?: TruncationResult;\n\tfullOutputPath?: string;\n}\n\n/**\n * Pluggable operations for the bash tool.\n * Override these to delegate command execution to remote systems (for example SSH).\n */\nexport interface BashOperations {\n\t/**\n\t * Execute a command and stream output.\n\t * @param command The command to execute\n\t * @param cwd Working directory\n\t * @param options Execution options\n\t * @returns Promise resolving to exit code (null if killed)\n\t */\n\texec: (\n\t\tcommand: string,\n\t\tcwd: string,\n\t\toptions: {\n\t\t\tonData: (data: Buffer) => void;\n\t\t\tsignal?: AbortSignal;\n\t\t\ttimeout?: number;\n\t\t\tenv?: NodeJS.ProcessEnv;\n\t\t},\n\t) => Promise<{ exitCode: number | null }>;\n}\n\n/**\n * Create bash operations using pi's built-in local shell execution backend.\n *\n * This is useful for extensions that intercept user_bash and still want pi's\n * standard local shell behavior while wrapping or rewriting commands.\n */\nexport function createLocalBashOperations(options?: { shellPath?: string; sessionId?: string }): BashOperations {\n\treturn {\n\t\texec: async (command, cwd, { onData, signal, timeout, env }) => {\n\t\t\tconst timeoutMs = resolveTimeoutMs(timeout);\n\t\t\tif (signal?.aborted) {\n\t\t\t\tthrow new Error(\"aborted\");\n\t\t\t}\n\t\t\tconst shellConfig = getShellConfig(options?.shellPath);\n\t\t\ttry {\n\t\t\t\tawait fsAccess(cwd, constants.F_OK);\n\t\t\t} catch {\n\t\t\t\tthrow new Error(`Working directory does not exist: ${cwd}\\nCannot execute bash commands.`);\n\t\t\t}\n\n\t\t\tconst commandFromStdin = shellConfig.commandTransport === \"stdin\";\n\t\t\tconst child = spawn(shellConfig.shell, commandFromStdin ? shellConfig.args : [...shellConfig.args, command], {\n\t\t\t\tcwd,\n\t\t\t\tdetached: process.platform !== \"win32\",\n\t\t\t\tenv: env ?? getShellEnv(),\n\t\t\t\tstdio: [commandFromStdin ? \"pipe\" : \"ignore\", \"pipe\", \"pipe\"],\n\t\t\t\twindowsHide: true,\n\t\t\t});\n\t\t\tif (commandFromStdin) {\n\t\t\t\tchild.stdin?.on(\"error\", () => {});\n\t\t\t\tchild.stdin?.end(command);\n\t\t\t}\n\t\t\tif (child.pid) trackDetachedChildPid(child.pid);\n\t\t\t// lunr: register the process for /processes tracking.\n\t\t\tif (child.pid) {\n\t\t\t\ttry {\n\t\t\t\t\tregisterProcess(child.pid, command, cwd, options?.sessionId);\n\t\t\t\t} catch {}\n\t\t\t}\n\t\t\tlet timedOut = false;\n\t\t\tlet timeoutHandle: NodeJS.Timeout | undefined;\n\t\t\tconst onAbort = () => {\n\t\t\t\tif (child.pid) killProcessTree(child.pid);\n\t\t\t};\n\n\t\t\ttry {\n\t\t\t\t// Set timeout if provided.\n\t\t\t\tif (timeoutMs !== undefined) {\n\t\t\t\t\ttimeoutHandle = setTimeout(() => {\n\t\t\t\t\t\ttimedOut = true;\n\t\t\t\t\t\tif (child.pid) killProcessTree(child.pid);\n\t\t\t\t\t}, timeoutMs);\n\t\t\t\t}\n\t\t\t\t// Stream stdout and stderr.\n\t\t\t\tchild.stdout?.on(\"data\", onData);\n\t\t\t\tchild.stderr?.on(\"data\", onData);\n\t\t\t\t// Handle abort signal by killing the entire process tree.\n\t\t\t\tif (signal) {\n\t\t\t\t\tif (signal.aborted) onAbort();\n\t\t\t\t\telse signal.addEventListener(\"abort\", onAbort, { once: true });\n\t\t\t\t}\n\t\t\t\t// Handle shell spawn errors and wait for the process to terminate without hanging\n\t\t\t\t// on inherited stdio handles held by detached descendants.\n\t\t\t\tconst exitCode = await waitForChildProcess(child);\n\t\t\t\tif (signal?.aborted) {\n\t\t\t\t\tthrow new Error(\"aborted\");\n\t\t\t\t}\n\t\t\t\tif (timedOut) {\n\t\t\t\t\tthrow new Error(`timeout:${timeout}`);\n\t\t\t\t}\n\t\t\t\treturn { exitCode };\n\t\t\t} finally {\n\t\t\t\tif (child.pid) untrackDetachedChildPid(child.pid);\n\t\t\t\t// lunr: unregister from /processes if the process has exited; keep it if still\n\t\t\t\t// alive (detached/backgrounded dev servers survive the shell call).\n\t\t\t\tif (child.pid) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\t// lunr: keep finished processes visible briefly so /processes can show\n\t\t\t\t\t\t// their exit state; markExited deletes trivial fast commands immediately.\n\t\t\t\t\t\tmarkProcessExited(child.pid, child.exitCode);\n\t\t\t\t\t} catch {}\n\t\t\t\t}\n\t\t\t\tif (timeoutHandle) clearTimeout(timeoutHandle);\n\t\t\t\tif (signal) signal.removeEventListener(\"abort\", onAbort);\n\t\t\t}\n\t\t},\n\t};\n}\n\nexport interface BashSpawnContext {\n\tcommand: string;\n\tcwd: string;\n\tenv: NodeJS.ProcessEnv;\n}\n\nexport type BashSpawnHook = (context: BashSpawnContext) => BashSpawnContext;\n\nfunction resolveSpawnContext(command: string, cwd: string, spawnHook?: BashSpawnHook): BashSpawnContext {\n\tconst baseContext: BashSpawnContext = { command, cwd, env: { ...getShellEnv() } };\n\treturn spawnHook ? spawnHook(baseContext) : baseContext;\n}\n\nexport interface BashToolOptions {\n\t/** Custom operations for command execution. Default: local shell */\n\toperations?: BashOperations;\n\t/** Command prefix prepended to every command (for example shell setup commands) */\n\tcommandPrefix?: string;\n\t/** Optional explicit shell path from settings */\n\tshellPath?: string;\n\t/** Hook to adjust command, cwd, or env before execution */\n\tspawnHook?: BashSpawnHook;\n}\n\nconst BASH_PREVIEW_LINES = 5;\nconst BASH_UPDATE_THROTTLE_MS = 100;\n\ntype BashRenderState = {\n\tstartedAt: number | undefined;\n\tendedAt: number | undefined;\n\tinterval: NodeJS.Timeout | undefined;\n};\n\ntype BashResultRenderState = {\n\tcachedWidth: number | undefined;\n\tcachedLines: string[] | undefined;\n\tcachedSkipped: number | undefined;\n};\n\nclass BashResultRenderComponent extends Container {\n\tstate: BashResultRenderState = {\n\t\tcachedWidth: undefined,\n\t\tcachedLines: undefined,\n\t\tcachedSkipped: undefined,\n\t};\n}\n\nfunction formatDuration(ms: number): string {\n\treturn `${(ms / 1000).toFixed(1)}s`;\n}\n\n// lunr: slim header — collapsed calls show only the first line of the command,\n// capped at this many chars; an ellipsis marks either kind of truncation.\nconst MAX_COLLAPSED_COMMAND_CHARS = 100;\n\nfunction formatBashCall(\n\targs: { command?: string; timeout?: number } | undefined,\n\toptions?: { expanded?: boolean; compact?: boolean },\n): string {\n\tconst command = str(args?.command);\n\tconst timeout = args?.timeout as number | undefined;\n\t// lunr: compact-by-default — the timeout suffix is noise on a one-line header;\n\t// it stays visible while streaming and in the expanded view.\n\tconst timeoutSuffix = timeout && !options?.compact ? theme.fg(\"muted\", ` (timeout ${timeout}s)`) : \"\";\n\tlet commandDisplay = command === null ? invalidArgText(theme) : command ? command : theme.fg(\"toolOutput\", \"...\");\n\tif (!options?.expanded && command) {\n\t\tconst firstLine = command.split(\"\\n\")[0];\n\t\tconst capped = firstLine.length > MAX_COLLAPSED_COMMAND_CHARS;\n\t\tconst base = capped ? firstLine.slice(0, MAX_COLLAPSED_COMMAND_CHARS) : firstLine;\n\t\tcommandDisplay = capped || base.length < command.length ? `${base} …` : base;\n\t}\n\treturn theme.fg(\"toolTitle\", theme.bold(`$ ${commandDisplay}`)) + timeoutSuffix;\n}\n\nfunction rebuildBashResultRenderComponent(\n\tcomponent: BashResultRenderComponent,\n\tresult: {\n\t\tcontent: Array<{ type: string; text?: string; data?: string; mimeType?: string }>;\n\t\tdetails?: BashToolDetails;\n\t},\n\toptions: ToolRenderResultOptions,\n\tshowImages: boolean,\n\tstartedAt: number | undefined,\n\tendedAt: number | undefined,\n\t// lunr: compact-by-default — finished, successful, non-expanded calls skip the\n\t// output preview and the \"Took\" footer (duration moves into the call header).\n\tcompact = false,\n): void {\n\tconst state = component.state;\n\tcomponent.clear();\n\n\tlet output = getTextOutput(result as any, showImages).trim();\n\tconst truncation = result.details?.truncation;\n\tconst fullOutputPath = result.details?.fullOutputPath;\n\tif (!options.isPartial && truncation?.truncated && fullOutputPath && output.endsWith(\"]\")) {\n\t\tconst footerStart = output.lastIndexOf(\"\\n\\n[\");\n\t\tif (footerStart !== -1 && output.slice(footerStart).includes(fullOutputPath)) {\n\t\t\toutput = output.slice(0, footerStart).trimEnd();\n\t\t}\n\t}\n\n\tif (!compact && output) {\n\t\tconst styledOutput = output\n\t\t\t.split(\"\\n\")\n\t\t\t.map((line) => theme.fg(\"toolOutput\", line))\n\t\t\t.join(\"\\n\");\n\n\t\tif (options.expanded) {\n\t\t\tcomponent.addChild(new Text(`\\n${styledOutput}`, 0, 0));\n\t\t} else {\n\t\t\tcomponent.addChild({\n\t\t\t\trender: (width: number) => {\n\t\t\t\t\tif (state.cachedLines === undefined || state.cachedWidth !== width) {\n\t\t\t\t\t\tconst preview = truncateToVisualLines(styledOutput, BASH_PREVIEW_LINES, width);\n\t\t\t\t\t\tstate.cachedLines = preview.visualLines;\n\t\t\t\t\t\tstate.cachedSkipped = preview.skippedCount;\n\t\t\t\t\t\tstate.cachedWidth = width;\n\t\t\t\t\t}\n\t\t\t\t\tif (state.cachedSkipped && state.cachedSkipped > 0) {\n\t\t\t\t\t\tconst hint =\n\t\t\t\t\t\t\ttheme.fg(\"muted\", `... (${state.cachedSkipped} earlier lines,`) +\n\t\t\t\t\t\t\t` ${keyHint(\"app.tools.expand\", \"to expand\")}${theme.fg(\"muted\", \")\")}`;\n\t\t\t\t\t\treturn [\"\", truncateToWidth(hint, width, \"...\"), ...(state.cachedLines ?? [])];\n\t\t\t\t\t}\n\t\t\t\t\treturn [\"\", ...(state.cachedLines ?? [])];\n\t\t\t\t},\n\t\t\t\tinvalidate: () => {\n\t\t\t\t\tstate.cachedWidth = undefined;\n\t\t\t\t\tstate.cachedLines = undefined;\n\t\t\t\t\tstate.cachedSkipped = undefined;\n\t\t\t\t},\n\t\t\t});\n\t\t}\n\t}\n\n\t// lunr: the truncation/full-output notice is intentionally NOT rendered in\n\t// the TUI — the model still gets it in the result text (formatOutput), and\n\t// the temp-log path is noise on screen.\n\n\tif (!compact && startedAt !== undefined) {\n\t\tconst label = options.isPartial ? \"Elapsed\" : \"Took\";\n\t\tconst endTime = endedAt ?? Date.now();\n\t\tcomponent.addChild(new Text(`\\n${theme.fg(\"muted\", `${label} ${formatDuration(endTime - startedAt)}`)}`, 0, 0));\n\t}\n}\n\nexport function createBashToolDefinition(\n\tcwd: string,\n\toptions?: BashToolOptions,\n): ToolDefinition<typeof bashSchema, BashToolDetails | undefined, BashRenderState> {\n\tconst ops = options?.operations ?? createLocalBashOperations({ shellPath: options?.shellPath });\n\tconst commandPrefix = options?.commandPrefix;\n\tconst spawnHook = options?.spawnHook;\n\treturn {\n\t\tname: \"bash\",\n\t\tlabel: \"bash\",\n\t\tdescription: `Execute a bash command in the current working directory. Returns stdout and stderr. Output is truncated to last ${DEFAULT_MAX_LINES} lines or ${DEFAULT_MAX_BYTES / 1024}KB (whichever is hit first). If truncated, full output is saved to a temp file. Optionally provide a timeout in seconds.`,\n\t\tpromptSnippet: \"Execute bash commands (ls, grep, find, etc.)\",\n\t\tparameters: bashSchema,\n\t\tasync execute(\n\t\t\t_toolCallId,\n\t\t\t{ command, timeout }: { command: string; timeout?: number },\n\t\t\tsignal?: AbortSignal,\n\t\t\tonUpdate?,\n\t\t\t_ctx?,\n\t\t) {\n\t\t\tconst resolvedCommand = commandPrefix ? `${commandPrefix}\\n${command}` : command;\n\t\t\tconst spawnContext = resolveSpawnContext(resolvedCommand, cwd, spawnHook);\n\t\t\tconst output = new OutputAccumulator({ tempFilePrefix: \"lunr-bash\" }); // lunr: renamed from pi-bash\n\t\t\tlet acceptingOutput = true;\n\t\t\tlet updateTimer: NodeJS.Timeout | undefined;\n\t\t\tlet updateDirty = false;\n\t\t\tlet lastUpdateAt = 0;\n\n\t\t\tconst emitOutputUpdate = () => {\n\t\t\t\tif (!onUpdate || !updateDirty) return;\n\t\t\t\tupdateDirty = false;\n\t\t\t\tlastUpdateAt = Date.now();\n\t\t\t\tconst snapshot = output.snapshot({ persistIfTruncated: true });\n\t\t\t\tonUpdate({\n\t\t\t\t\tcontent: [{ type: \"text\", text: snapshot.content || \"\" }],\n\t\t\t\t\tdetails: {\n\t\t\t\t\t\ttruncation: snapshot.truncation.truncated ? snapshot.truncation : undefined,\n\t\t\t\t\t\tfullOutputPath: snapshot.fullOutputPath,\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t};\n\n\t\t\tconst clearUpdateTimer = () => {\n\t\t\t\tif (updateTimer) {\n\t\t\t\t\tclearTimeout(updateTimer);\n\t\t\t\t\tupdateTimer = undefined;\n\t\t\t\t}\n\t\t\t};\n\n\t\t\tconst scheduleOutputUpdate = () => {\n\t\t\t\tif (!onUpdate) return;\n\t\t\t\tupdateDirty = true;\n\t\t\t\tconst delay = BASH_UPDATE_THROTTLE_MS - (Date.now() - lastUpdateAt);\n\t\t\t\tif (delay <= 0) {\n\t\t\t\t\tclearUpdateTimer();\n\t\t\t\t\temitOutputUpdate();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tupdateTimer ??= setTimeout(() => {\n\t\t\t\t\tupdateTimer = undefined;\n\t\t\t\t\temitOutputUpdate();\n\t\t\t\t}, delay);\n\t\t\t};\n\n\t\t\tif (onUpdate) {\n\t\t\t\tonUpdate({ content: [], details: undefined });\n\t\t\t}\n\n\t\t\tconst handleData = (data: Buffer) => {\n\t\t\t\tif (!acceptingOutput) return;\n\t\t\t\toutput.append(data);\n\t\t\t\tscheduleOutputUpdate();\n\t\t\t};\n\n\t\t\tconst finishOutput = async () => {\n\t\t\t\tacceptingOutput = false;\n\t\t\t\toutput.finish();\n\t\t\t\tclearUpdateTimer();\n\t\t\t\temitOutputUpdate();\n\t\t\t\tconst snapshot = output.snapshot({ persistIfTruncated: true });\n\t\t\t\tawait output.closeTempFile();\n\t\t\t\treturn snapshot;\n\t\t\t};\n\n\t\t\tconst formatOutput = (snapshot: Awaited<ReturnType<typeof finishOutput>>, emptyText = \"(no output)\") => {\n\t\t\t\tconst truncation = snapshot.truncation;\n\t\t\t\tlet text = snapshot.content || emptyText;\n\t\t\t\tlet details: BashToolDetails | undefined;\n\t\t\t\tif (truncation.truncated) {\n\t\t\t\t\tdetails = { truncation, fullOutputPath: snapshot.fullOutputPath };\n\t\t\t\t\tconst startLine = truncation.totalLines - truncation.outputLines + 1;\n\t\t\t\t\tconst endLine = truncation.totalLines;\n\t\t\t\t\tif (truncation.lastLinePartial) {\n\t\t\t\t\t\tconst lastLineSize = formatSize(output.getLastLineBytes());\n\t\t\t\t\t\ttext += `\\n\\n[Showing last ${formatSize(truncation.outputBytes)} of line ${endLine} (line is ${lastLineSize}). Full output: ${snapshot.fullOutputPath}]`;\n\t\t\t\t\t} else if (truncation.truncatedBy === \"lines\") {\n\t\t\t\t\t\ttext += `\\n\\n[Showing lines ${startLine}-${endLine} of ${truncation.totalLines}. Full output: ${snapshot.fullOutputPath}]`;\n\t\t\t\t\t} else {\n\t\t\t\t\t\ttext += `\\n\\n[Showing lines ${startLine}-${endLine} of ${truncation.totalLines} (${formatSize(DEFAULT_MAX_BYTES)} limit). Full output: ${snapshot.fullOutputPath}]`;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn { text, details };\n\t\t\t};\n\n\t\t\tconst appendStatus = (text: string, status: string) => `${text ? `${text}\\n\\n` : \"\"}${status}`;\n\n\t\t\ttry {\n\t\t\t\tlet exitCode: number | null;\n\t\t\t\ttry {\n\t\t\t\t\tconst result = await ops.exec(spawnContext.command, spawnContext.cwd, {\n\t\t\t\t\t\tonData: handleData,\n\t\t\t\t\t\tsignal,\n\t\t\t\t\t\ttimeout,\n\t\t\t\t\t\tenv: spawnContext.env,\n\t\t\t\t\t});\n\t\t\t\t\texitCode = result.exitCode;\n\t\t\t\t} catch (err) {\n\t\t\t\t\tconst snapshot = await finishOutput();\n\t\t\t\t\tconst { text } = formatOutput(snapshot, \"\");\n\t\t\t\t\tif (err instanceof Error && err.message === \"aborted\") {\n\t\t\t\t\t\tthrow new Error(appendStatus(text, \"Command aborted\"));\n\t\t\t\t\t}\n\t\t\t\t\tif (err instanceof Error && err.message.startsWith(\"timeout:\")) {\n\t\t\t\t\t\tconst timeoutSecs = err.message.split(\":\")[1];\n\t\t\t\t\t\tthrow new Error(appendStatus(text, `Command timed out after ${timeoutSecs} seconds`));\n\t\t\t\t\t}\n\t\t\t\t\tthrow err;\n\t\t\t\t}\n\n\t\t\t\tconst snapshot = await finishOutput();\n\t\t\t\tconst { text: outputText, details } = formatOutput(snapshot);\n\t\t\t\tif (exitCode !== 0 && exitCode !== null) {\n\t\t\t\t\tthrow new Error(appendStatus(outputText, `Command exited with code ${exitCode}`));\n\t\t\t\t}\n\t\t\t\treturn { content: [{ type: \"text\", text: outputText }], details };\n\t\t\t} finally {\n\t\t\t\tclearUpdateTimer();\n\t\t\t}\n\t\t},\n\t\trenderCall(args, _theme, context) {\n\t\t\tconst state = context.state;\n\t\t\tif (context.executionStarted && state.startedAt === undefined) {\n\t\t\t\tstate.startedAt = Date.now();\n\t\t\t\tstate.endedAt = undefined;\n\t\t\t}\n\t\t\t// lunr: compact-by-default — stamp endedAt here too: renderCall runs before\n\t\t\t// renderResult on the final update, and the header needs the duration.\n\t\t\tif (!context.isPartial && state.startedAt !== undefined) {\n\t\t\t\tstate.endedAt ??= Date.now();\n\t\t\t}\n\t\t\t// lunr: compact-by-default — a finished, successful, non-expanded call\n\t\t\t// renders as a single slim header line with the duration folded in.\n\t\t\tconst compact = !context.isPartial && !context.expanded && !context.isError;\n\t\t\tlet header = `${toolStatusDotFromContext(context, theme)} ${formatBashCall(args, { expanded: context.expanded, compact })}`;\n\t\t\tif (compact && state.startedAt !== undefined && state.endedAt !== undefined) {\n\t\t\t\theader += theme.fg(\"muted\", ` — Took ${formatDuration(state.endedAt - state.startedAt)}`);\n\t\t\t}\n\t\t\tconst text = (context.lastComponent as Text | undefined) ?? new Text(\"\", 0, 0);\n\t\t\ttext.setText(header);\n\t\t\treturn text;\n\t\t},\n\t\trenderResult(result, options, _theme, context) {\n\t\t\tconst state = context.state;\n\t\t\tif (state.startedAt !== undefined && options.isPartial && !state.interval) {\n\t\t\t\tstate.interval = setInterval(() => context.invalidate(), 1000);\n\t\t\t}\n\t\t\tif (!options.isPartial || context.isError) {\n\t\t\t\tstate.endedAt ??= Date.now();\n\t\t\t\tif (state.interval) {\n\t\t\t\t\tclearInterval(state.interval);\n\t\t\t\t\tstate.interval = undefined;\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst component =\n\t\t\t\t(context.lastComponent as BashResultRenderComponent | undefined) ?? new BashResultRenderComponent();\n\t\t\t// lunr: compact-by-default — suppresses the output preview + \"Took\" footer.\n\t\t\tconst compact = !options.isPartial && !options.expanded && !context.isError;\n\t\t\trebuildBashResultRenderComponent(\n\t\t\t\tcomponent,\n\t\t\t\tresult as any,\n\t\t\t\toptions,\n\t\t\t\tcontext.showImages,\n\t\t\t\tstate.startedAt,\n\t\t\t\tstate.endedAt,\n\t\t\t\tcompact,\n\t\t\t);\n\t\t\tcomponent.invalidate();\n\t\t\treturn component;\n\t\t},\n\t};\n}\n\nexport function createBashTool(cwd: string, options?: BashToolOptions): AgentTool<typeof bashSchema> {\n\treturn wrapToolDefinition(createBashToolDefinition(cwd, options));\n}\n"]}
@@ -1,6 +1,6 @@
1
1
  import { constants } from "node:fs";
2
2
  import { access as fsAccess } from "node:fs/promises";
3
- import { Container, Text, truncateToWidth } from "@earendil-works/pi-tui";
3
+ import { Container, Text, truncateToWidth } from "@ashx-j/lunr-tui";
4
4
  import { spawn } from "child_process";
5
5
  import { Type } from "typebox";
6
6
  import { keyHint } from "../../modes/interactive/components/keybinding-hints.js";
@@ -1 +1 @@
1
- {"version":3,"file":"bash.js","sourceRoot":"","sources":["../../../src/core/tools/bash.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,MAAM,IAAI,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAEtD,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC1E,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAe,IAAI,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,wDAAwD,CAAC;AACjF,OAAO,EAAE,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,OAAO,KAAK,IAAI,CAAC,GAAG,EAAE,CAAC;gBAC7B,IAAI,KAAK,CAAC,QAAQ,EAAE,CAAC;oBACpB,aAAa,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;oBAC9B,KAAK,CAAC,QAAQ,GAAG,SAAS,CAAC;gBAC5B,CAAC;YACF,CAAC;YACD,MAAM,SAAS,GACb,OAAO,CAAC,aAAuD,IAAI,IAAI,yBAAyB,EAAE,CAAC;YACrG,8EAA4E;YAC5E,MAAM,OAAO,GAAG,CAAC,OAAO,CAAC,SAAS,IAAI,CAAC,OAAO,CAAC,QAAQ,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC;YAC5E,gCAAgC,CAC/B,SAAS,EACT,MAAa,EACb,OAAO,EACP,OAAO,CAAC,UAAU,EAClB,KAAK,CAAC,SAAS,EACf,KAAK,CAAC,OAAO,EACb,OAAO,CACP,CAAC;YACF,SAAS,CAAC,UAAU,EAAE,CAAC;YACvB,OAAO,SAAS,CAAC;QAAA,CACjB;KACD,CAAC;AAAA,CACF;AAED,MAAM,UAAU,cAAc,CAAC,GAAW,EAAE,OAAyB,EAAgC;IACpG,OAAO,kBAAkB,CAAC,wBAAwB,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC;AAAA,CAClE","sourcesContent":["import { constants } from \"node:fs\";\nimport { access as fsAccess } from \"node:fs/promises\";\nimport type { AgentTool } from \"@earendil-works/pi-agent-core\";\nimport { Container, Text, truncateToWidth } from \"@earendil-works/pi-tui\";\nimport { spawn } from \"child_process\";\nimport { type Static, Type } from \"typebox\";\nimport { keyHint } from \"../../modes/interactive/components/keybinding-hints.ts\";\nimport { truncateToVisualLines } from \"../../modes/interactive/components/visual-truncate.ts\";\nimport { theme } from \"../../modes/interactive/theme/theme.ts\";\nimport { waitForChildProcess } from \"../../utils/child-process.ts\";\nimport {\n\tgetShellConfig,\n\tgetShellEnv,\n\tkillProcessTree,\n\ttrackDetachedChildPid,\n\tuntrackDetachedChildPid,\n} from \"../../utils/shell.ts\";\nimport type { ToolDefinition, ToolRenderResultOptions } from \"../extensions/types.ts\";\nimport { markExited as markProcessExited, register as registerProcess } from \"../process-registry.ts\";\nimport { OutputAccumulator } from \"./output-accumulator.ts\";\nimport { getTextOutput, invalidArgText, str, toolStatusDotFromContext } from \"./render-utils.ts\";\nimport { wrapToolDefinition } from \"./tool-definition-wrapper.ts\";\nimport { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, formatSize, type TruncationResult } from \"./truncate.ts\";\n\nconst MAX_TIMEOUT_MS = 2_147_483_647;\nconst MAX_TIMEOUT_SECONDS = MAX_TIMEOUT_MS / 1000;\n\nfunction resolveTimeoutMs(timeout: number | undefined): number | undefined {\n\tif (timeout === undefined) return undefined;\n\tif (!Number.isFinite(timeout) || timeout <= 0) {\n\t\tthrow new Error(\"Invalid timeout: must be a finite number of seconds\");\n\t}\n\n\tconst timeoutMs = timeout * 1000;\n\tif (timeoutMs > MAX_TIMEOUT_MS) {\n\t\tthrow new Error(`Invalid timeout: maximum is ${MAX_TIMEOUT_SECONDS} seconds`);\n\t}\n\treturn timeoutMs;\n}\n\nconst bashSchema = Type.Object({\n\tcommand: Type.String({ description: \"Bash command to execute\" }),\n\ttimeout: Type.Optional(Type.Number({ description: \"Timeout in seconds (optional, no default timeout)\" })),\n});\n\nexport type BashToolInput = Static<typeof bashSchema>;\n\nexport interface BashToolDetails {\n\ttruncation?: TruncationResult;\n\tfullOutputPath?: string;\n}\n\n/**\n * Pluggable operations for the bash tool.\n * Override these to delegate command execution to remote systems (for example SSH).\n */\nexport interface BashOperations {\n\t/**\n\t * Execute a command and stream output.\n\t * @param command The command to execute\n\t * @param cwd Working directory\n\t * @param options Execution options\n\t * @returns Promise resolving to exit code (null if killed)\n\t */\n\texec: (\n\t\tcommand: string,\n\t\tcwd: string,\n\t\toptions: {\n\t\t\tonData: (data: Buffer) => void;\n\t\t\tsignal?: AbortSignal;\n\t\t\ttimeout?: number;\n\t\t\tenv?: NodeJS.ProcessEnv;\n\t\t},\n\t) => Promise<{ exitCode: number | null }>;\n}\n\n/**\n * Create bash operations using pi's built-in local shell execution backend.\n *\n * This is useful for extensions that intercept user_bash and still want pi's\n * standard local shell behavior while wrapping or rewriting commands.\n */\nexport function createLocalBashOperations(options?: { shellPath?: string; sessionId?: string }): BashOperations {\n\treturn {\n\t\texec: async (command, cwd, { onData, signal, timeout, env }) => {\n\t\t\tconst timeoutMs = resolveTimeoutMs(timeout);\n\t\t\tif (signal?.aborted) {\n\t\t\t\tthrow new Error(\"aborted\");\n\t\t\t}\n\t\t\tconst shellConfig = getShellConfig(options?.shellPath);\n\t\t\ttry {\n\t\t\t\tawait fsAccess(cwd, constants.F_OK);\n\t\t\t} catch {\n\t\t\t\tthrow new Error(`Working directory does not exist: ${cwd}\\nCannot execute bash commands.`);\n\t\t\t}\n\n\t\t\tconst commandFromStdin = shellConfig.commandTransport === \"stdin\";\n\t\t\tconst child = spawn(shellConfig.shell, commandFromStdin ? shellConfig.args : [...shellConfig.args, command], {\n\t\t\t\tcwd,\n\t\t\t\tdetached: process.platform !== \"win32\",\n\t\t\t\tenv: env ?? getShellEnv(),\n\t\t\t\tstdio: [commandFromStdin ? \"pipe\" : \"ignore\", \"pipe\", \"pipe\"],\n\t\t\t\twindowsHide: true,\n\t\t\t});\n\t\t\tif (commandFromStdin) {\n\t\t\t\tchild.stdin?.on(\"error\", () => {});\n\t\t\t\tchild.stdin?.end(command);\n\t\t\t}\n\t\t\tif (child.pid) trackDetachedChildPid(child.pid);\n\t\t\t// lunr: register the process for /processes tracking.\n\t\t\tif (child.pid) {\n\t\t\t\ttry {\n\t\t\t\t\tregisterProcess(child.pid, command, cwd, options?.sessionId);\n\t\t\t\t} catch {}\n\t\t\t}\n\t\t\tlet timedOut = false;\n\t\t\tlet timeoutHandle: NodeJS.Timeout | undefined;\n\t\t\tconst onAbort = () => {\n\t\t\t\tif (child.pid) killProcessTree(child.pid);\n\t\t\t};\n\n\t\t\ttry {\n\t\t\t\t// Set timeout if provided.\n\t\t\t\tif (timeoutMs !== undefined) {\n\t\t\t\t\ttimeoutHandle = setTimeout(() => {\n\t\t\t\t\t\ttimedOut = true;\n\t\t\t\t\t\tif (child.pid) killProcessTree(child.pid);\n\t\t\t\t\t}, timeoutMs);\n\t\t\t\t}\n\t\t\t\t// Stream stdout and stderr.\n\t\t\t\tchild.stdout?.on(\"data\", onData);\n\t\t\t\tchild.stderr?.on(\"data\", onData);\n\t\t\t\t// Handle abort signal by killing the entire process tree.\n\t\t\t\tif (signal) {\n\t\t\t\t\tif (signal.aborted) onAbort();\n\t\t\t\t\telse signal.addEventListener(\"abort\", onAbort, { once: true });\n\t\t\t\t}\n\t\t\t\t// Handle shell spawn errors and wait for the process to terminate without hanging\n\t\t\t\t// on inherited stdio handles held by detached descendants.\n\t\t\t\tconst exitCode = await waitForChildProcess(child);\n\t\t\t\tif (signal?.aborted) {\n\t\t\t\t\tthrow new Error(\"aborted\");\n\t\t\t\t}\n\t\t\t\tif (timedOut) {\n\t\t\t\t\tthrow new Error(`timeout:${timeout}`);\n\t\t\t\t}\n\t\t\t\treturn { exitCode };\n\t\t\t} finally {\n\t\t\t\tif (child.pid) untrackDetachedChildPid(child.pid);\n\t\t\t\t// lunr: unregister from /processes if the process has exited; keep it if still\n\t\t\t\t// alive (detached/backgrounded dev servers survive the shell call).\n\t\t\t\tif (child.pid) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\t// lunr: keep finished processes visible briefly so /processes can show\n\t\t\t\t\t\t// their exit state; markExited deletes trivial fast commands immediately.\n\t\t\t\t\t\tmarkProcessExited(child.pid, child.exitCode);\n\t\t\t\t\t} catch {}\n\t\t\t\t}\n\t\t\t\tif (timeoutHandle) clearTimeout(timeoutHandle);\n\t\t\t\tif (signal) signal.removeEventListener(\"abort\", onAbort);\n\t\t\t}\n\t\t},\n\t};\n}\n\nexport interface BashSpawnContext {\n\tcommand: string;\n\tcwd: string;\n\tenv: NodeJS.ProcessEnv;\n}\n\nexport type BashSpawnHook = (context: BashSpawnContext) => BashSpawnContext;\n\nfunction resolveSpawnContext(command: string, cwd: string, spawnHook?: BashSpawnHook): BashSpawnContext {\n\tconst baseContext: BashSpawnContext = { command, cwd, env: { ...getShellEnv() } };\n\treturn spawnHook ? spawnHook(baseContext) : baseContext;\n}\n\nexport interface BashToolOptions {\n\t/** Custom operations for command execution. Default: local shell */\n\toperations?: BashOperations;\n\t/** Command prefix prepended to every command (for example shell setup commands) */\n\tcommandPrefix?: string;\n\t/** Optional explicit shell path from settings */\n\tshellPath?: string;\n\t/** Hook to adjust command, cwd, or env before execution */\n\tspawnHook?: BashSpawnHook;\n}\n\nconst BASH_PREVIEW_LINES = 5;\nconst BASH_UPDATE_THROTTLE_MS = 100;\n\ntype BashRenderState = {\n\tstartedAt: number | undefined;\n\tendedAt: number | undefined;\n\tinterval: NodeJS.Timeout | undefined;\n};\n\ntype BashResultRenderState = {\n\tcachedWidth: number | undefined;\n\tcachedLines: string[] | undefined;\n\tcachedSkipped: number | undefined;\n};\n\nclass BashResultRenderComponent extends Container {\n\tstate: BashResultRenderState = {\n\t\tcachedWidth: undefined,\n\t\tcachedLines: undefined,\n\t\tcachedSkipped: undefined,\n\t};\n}\n\nfunction formatDuration(ms: number): string {\n\treturn `${(ms / 1000).toFixed(1)}s`;\n}\n\n// lunr: slim header — collapsed calls show only the first line of the command,\n// capped at this many chars; an ellipsis marks either kind of truncation.\nconst MAX_COLLAPSED_COMMAND_CHARS = 100;\n\nfunction formatBashCall(\n\targs: { command?: string; timeout?: number } | undefined,\n\toptions?: { expanded?: boolean; compact?: boolean },\n): string {\n\tconst command = str(args?.command);\n\tconst timeout = args?.timeout as number | undefined;\n\t// lunr: compact-by-default — the timeout suffix is noise on a one-line header;\n\t// it stays visible while streaming and in the expanded view.\n\tconst timeoutSuffix = timeout && !options?.compact ? theme.fg(\"muted\", ` (timeout ${timeout}s)`) : \"\";\n\tlet commandDisplay = command === null ? invalidArgText(theme) : command ? command : theme.fg(\"toolOutput\", \"...\");\n\tif (!options?.expanded && command) {\n\t\tconst firstLine = command.split(\"\\n\")[0];\n\t\tconst capped = firstLine.length > MAX_COLLAPSED_COMMAND_CHARS;\n\t\tconst base = capped ? firstLine.slice(0, MAX_COLLAPSED_COMMAND_CHARS) : firstLine;\n\t\tcommandDisplay = capped || base.length < command.length ? `${base} …` : base;\n\t}\n\treturn theme.fg(\"toolTitle\", theme.bold(`$ ${commandDisplay}`)) + timeoutSuffix;\n}\n\nfunction rebuildBashResultRenderComponent(\n\tcomponent: BashResultRenderComponent,\n\tresult: {\n\t\tcontent: Array<{ type: string; text?: string; data?: string; mimeType?: string }>;\n\t\tdetails?: BashToolDetails;\n\t},\n\toptions: ToolRenderResultOptions,\n\tshowImages: boolean,\n\tstartedAt: number | undefined,\n\tendedAt: number | undefined,\n\t// lunr: compact-by-default — finished, successful, non-expanded calls skip the\n\t// output preview and the \"Took\" footer (duration moves into the call header).\n\tcompact = false,\n): void {\n\tconst state = component.state;\n\tcomponent.clear();\n\n\tlet output = getTextOutput(result as any, showImages).trim();\n\tconst truncation = result.details?.truncation;\n\tconst fullOutputPath = result.details?.fullOutputPath;\n\tif (!options.isPartial && truncation?.truncated && fullOutputPath && output.endsWith(\"]\")) {\n\t\tconst footerStart = output.lastIndexOf(\"\\n\\n[\");\n\t\tif (footerStart !== -1 && output.slice(footerStart).includes(fullOutputPath)) {\n\t\t\toutput = output.slice(0, footerStart).trimEnd();\n\t\t}\n\t}\n\n\tif (!compact && output) {\n\t\tconst styledOutput = output\n\t\t\t.split(\"\\n\")\n\t\t\t.map((line) => theme.fg(\"toolOutput\", line))\n\t\t\t.join(\"\\n\");\n\n\t\tif (options.expanded) {\n\t\t\tcomponent.addChild(new Text(`\\n${styledOutput}`, 0, 0));\n\t\t} else {\n\t\t\tcomponent.addChild({\n\t\t\t\trender: (width: number) => {\n\t\t\t\t\tif (state.cachedLines === undefined || state.cachedWidth !== width) {\n\t\t\t\t\t\tconst preview = truncateToVisualLines(styledOutput, BASH_PREVIEW_LINES, width);\n\t\t\t\t\t\tstate.cachedLines = preview.visualLines;\n\t\t\t\t\t\tstate.cachedSkipped = preview.skippedCount;\n\t\t\t\t\t\tstate.cachedWidth = width;\n\t\t\t\t\t}\n\t\t\t\t\tif (state.cachedSkipped && state.cachedSkipped > 0) {\n\t\t\t\t\t\tconst hint =\n\t\t\t\t\t\t\ttheme.fg(\"muted\", `... (${state.cachedSkipped} earlier lines,`) +\n\t\t\t\t\t\t\t` ${keyHint(\"app.tools.expand\", \"to expand\")}${theme.fg(\"muted\", \")\")}`;\n\t\t\t\t\t\treturn [\"\", truncateToWidth(hint, width, \"...\"), ...(state.cachedLines ?? [])];\n\t\t\t\t\t}\n\t\t\t\t\treturn [\"\", ...(state.cachedLines ?? [])];\n\t\t\t\t},\n\t\t\t\tinvalidate: () => {\n\t\t\t\t\tstate.cachedWidth = undefined;\n\t\t\t\t\tstate.cachedLines = undefined;\n\t\t\t\t\tstate.cachedSkipped = undefined;\n\t\t\t\t},\n\t\t\t});\n\t\t}\n\t}\n\n\t// lunr: the truncation/full-output notice is intentionally NOT rendered in\n\t// the TUI — the model still gets it in the result text (formatOutput), and\n\t// the temp-log path is noise on screen.\n\n\tif (!compact && startedAt !== undefined) {\n\t\tconst label = options.isPartial ? \"Elapsed\" : \"Took\";\n\t\tconst endTime = endedAt ?? Date.now();\n\t\tcomponent.addChild(new Text(`\\n${theme.fg(\"muted\", `${label} ${formatDuration(endTime - startedAt)}`)}`, 0, 0));\n\t}\n}\n\nexport function createBashToolDefinition(\n\tcwd: string,\n\toptions?: BashToolOptions,\n): ToolDefinition<typeof bashSchema, BashToolDetails | undefined, BashRenderState> {\n\tconst ops = options?.operations ?? createLocalBashOperations({ shellPath: options?.shellPath });\n\tconst commandPrefix = options?.commandPrefix;\n\tconst spawnHook = options?.spawnHook;\n\treturn {\n\t\tname: \"bash\",\n\t\tlabel: \"bash\",\n\t\tdescription: `Execute a bash command in the current working directory. Returns stdout and stderr. Output is truncated to last ${DEFAULT_MAX_LINES} lines or ${DEFAULT_MAX_BYTES / 1024}KB (whichever is hit first). If truncated, full output is saved to a temp file. Optionally provide a timeout in seconds.`,\n\t\tpromptSnippet: \"Execute bash commands (ls, grep, find, etc.)\",\n\t\tparameters: bashSchema,\n\t\tasync execute(\n\t\t\t_toolCallId,\n\t\t\t{ command, timeout }: { command: string; timeout?: number },\n\t\t\tsignal?: AbortSignal,\n\t\t\tonUpdate?,\n\t\t\t_ctx?,\n\t\t) {\n\t\t\tconst resolvedCommand = commandPrefix ? `${commandPrefix}\\n${command}` : command;\n\t\t\tconst spawnContext = resolveSpawnContext(resolvedCommand, cwd, spawnHook);\n\t\t\tconst output = new OutputAccumulator({ tempFilePrefix: \"lunr-bash\" }); // lunr: renamed from pi-bash\n\t\t\tlet acceptingOutput = true;\n\t\t\tlet updateTimer: NodeJS.Timeout | undefined;\n\t\t\tlet updateDirty = false;\n\t\t\tlet lastUpdateAt = 0;\n\n\t\t\tconst emitOutputUpdate = () => {\n\t\t\t\tif (!onUpdate || !updateDirty) return;\n\t\t\t\tupdateDirty = false;\n\t\t\t\tlastUpdateAt = Date.now();\n\t\t\t\tconst snapshot = output.snapshot({ persistIfTruncated: true });\n\t\t\t\tonUpdate({\n\t\t\t\t\tcontent: [{ type: \"text\", text: snapshot.content || \"\" }],\n\t\t\t\t\tdetails: {\n\t\t\t\t\t\ttruncation: snapshot.truncation.truncated ? snapshot.truncation : undefined,\n\t\t\t\t\t\tfullOutputPath: snapshot.fullOutputPath,\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t};\n\n\t\t\tconst clearUpdateTimer = () => {\n\t\t\t\tif (updateTimer) {\n\t\t\t\t\tclearTimeout(updateTimer);\n\t\t\t\t\tupdateTimer = undefined;\n\t\t\t\t}\n\t\t\t};\n\n\t\t\tconst scheduleOutputUpdate = () => {\n\t\t\t\tif (!onUpdate) return;\n\t\t\t\tupdateDirty = true;\n\t\t\t\tconst delay = BASH_UPDATE_THROTTLE_MS - (Date.now() - lastUpdateAt);\n\t\t\t\tif (delay <= 0) {\n\t\t\t\t\tclearUpdateTimer();\n\t\t\t\t\temitOutputUpdate();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tupdateTimer ??= setTimeout(() => {\n\t\t\t\t\tupdateTimer = undefined;\n\t\t\t\t\temitOutputUpdate();\n\t\t\t\t}, delay);\n\t\t\t};\n\n\t\t\tif (onUpdate) {\n\t\t\t\tonUpdate({ content: [], details: undefined });\n\t\t\t}\n\n\t\t\tconst handleData = (data: Buffer) => {\n\t\t\t\tif (!acceptingOutput) return;\n\t\t\t\toutput.append(data);\n\t\t\t\tscheduleOutputUpdate();\n\t\t\t};\n\n\t\t\tconst finishOutput = async () => {\n\t\t\t\tacceptingOutput = false;\n\t\t\t\toutput.finish();\n\t\t\t\tclearUpdateTimer();\n\t\t\t\temitOutputUpdate();\n\t\t\t\tconst snapshot = output.snapshot({ persistIfTruncated: true });\n\t\t\t\tawait output.closeTempFile();\n\t\t\t\treturn snapshot;\n\t\t\t};\n\n\t\t\tconst formatOutput = (snapshot: Awaited<ReturnType<typeof finishOutput>>, emptyText = \"(no output)\") => {\n\t\t\t\tconst truncation = snapshot.truncation;\n\t\t\t\tlet text = snapshot.content || emptyText;\n\t\t\t\tlet details: BashToolDetails | undefined;\n\t\t\t\tif (truncation.truncated) {\n\t\t\t\t\tdetails = { truncation, fullOutputPath: snapshot.fullOutputPath };\n\t\t\t\t\tconst startLine = truncation.totalLines - truncation.outputLines + 1;\n\t\t\t\t\tconst endLine = truncation.totalLines;\n\t\t\t\t\tif (truncation.lastLinePartial) {\n\t\t\t\t\t\tconst lastLineSize = formatSize(output.getLastLineBytes());\n\t\t\t\t\t\ttext += `\\n\\n[Showing last ${formatSize(truncation.outputBytes)} of line ${endLine} (line is ${lastLineSize}). Full output: ${snapshot.fullOutputPath}]`;\n\t\t\t\t\t} else if (truncation.truncatedBy === \"lines\") {\n\t\t\t\t\t\ttext += `\\n\\n[Showing lines ${startLine}-${endLine} of ${truncation.totalLines}. Full output: ${snapshot.fullOutputPath}]`;\n\t\t\t\t\t} else {\n\t\t\t\t\t\ttext += `\\n\\n[Showing lines ${startLine}-${endLine} of ${truncation.totalLines} (${formatSize(DEFAULT_MAX_BYTES)} limit). Full output: ${snapshot.fullOutputPath}]`;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn { text, details };\n\t\t\t};\n\n\t\t\tconst appendStatus = (text: string, status: string) => `${text ? `${text}\\n\\n` : \"\"}${status}`;\n\n\t\t\ttry {\n\t\t\t\tlet exitCode: number | null;\n\t\t\t\ttry {\n\t\t\t\t\tconst result = await ops.exec(spawnContext.command, spawnContext.cwd, {\n\t\t\t\t\t\tonData: handleData,\n\t\t\t\t\t\tsignal,\n\t\t\t\t\t\ttimeout,\n\t\t\t\t\t\tenv: spawnContext.env,\n\t\t\t\t\t});\n\t\t\t\t\texitCode = result.exitCode;\n\t\t\t\t} catch (err) {\n\t\t\t\t\tconst snapshot = await finishOutput();\n\t\t\t\t\tconst { text } = formatOutput(snapshot, \"\");\n\t\t\t\t\tif (err instanceof Error && err.message === \"aborted\") {\n\t\t\t\t\t\tthrow new Error(appendStatus(text, \"Command aborted\"));\n\t\t\t\t\t}\n\t\t\t\t\tif (err instanceof Error && err.message.startsWith(\"timeout:\")) {\n\t\t\t\t\t\tconst timeoutSecs = err.message.split(\":\")[1];\n\t\t\t\t\t\tthrow new Error(appendStatus(text, `Command timed out after ${timeoutSecs} seconds`));\n\t\t\t\t\t}\n\t\t\t\t\tthrow err;\n\t\t\t\t}\n\n\t\t\t\tconst snapshot = await finishOutput();\n\t\t\t\tconst { text: outputText, details } = formatOutput(snapshot);\n\t\t\t\tif (exitCode !== 0 && exitCode !== null) {\n\t\t\t\t\tthrow new Error(appendStatus(outputText, `Command exited with code ${exitCode}`));\n\t\t\t\t}\n\t\t\t\treturn { content: [{ type: \"text\", text: outputText }], details };\n\t\t\t} finally {\n\t\t\t\tclearUpdateTimer();\n\t\t\t}\n\t\t},\n\t\trenderCall(args, _theme, context) {\n\t\t\tconst state = context.state;\n\t\t\tif (context.executionStarted && state.startedAt === undefined) {\n\t\t\t\tstate.startedAt = Date.now();\n\t\t\t\tstate.endedAt = undefined;\n\t\t\t}\n\t\t\t// lunr: compact-by-default — stamp endedAt here too: renderCall runs before\n\t\t\t// renderResult on the final update, and the header needs the duration.\n\t\t\tif (!context.isPartial && state.startedAt !== undefined) {\n\t\t\t\tstate.endedAt ??= Date.now();\n\t\t\t}\n\t\t\t// lunr: compact-by-default — a finished, successful, non-expanded call\n\t\t\t// renders as a single slim header line with the duration folded in.\n\t\t\tconst compact = !context.isPartial && !context.expanded && !context.isError;\n\t\t\tlet header = `${toolStatusDotFromContext(context, theme)} ${formatBashCall(args, { expanded: context.expanded, compact })}`;\n\t\t\tif (compact && state.startedAt !== undefined && state.endedAt !== undefined) {\n\t\t\t\theader += theme.fg(\"muted\", ` — Took ${formatDuration(state.endedAt - state.startedAt)}`);\n\t\t\t}\n\t\t\tconst text = (context.lastComponent as Text | undefined) ?? new Text(\"\", 0, 0);\n\t\t\ttext.setText(header);\n\t\t\treturn text;\n\t\t},\n\t\trenderResult(result, options, _theme, context) {\n\t\t\tconst state = context.state;\n\t\t\tif (state.startedAt !== undefined && options.isPartial && !state.interval) {\n\t\t\t\tstate.interval = setInterval(() => context.invalidate(), 1000);\n\t\t\t}\n\t\t\tif (!options.isPartial || context.isError) {\n\t\t\t\tstate.endedAt ??= Date.now();\n\t\t\t\tif (state.interval) {\n\t\t\t\t\tclearInterval(state.interval);\n\t\t\t\t\tstate.interval = undefined;\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst component =\n\t\t\t\t(context.lastComponent as BashResultRenderComponent | undefined) ?? new BashResultRenderComponent();\n\t\t\t// lunr: compact-by-default — suppresses the output preview + \"Took\" footer.\n\t\t\tconst compact = !options.isPartial && !options.expanded && !context.isError;\n\t\t\trebuildBashResultRenderComponent(\n\t\t\t\tcomponent,\n\t\t\t\tresult as any,\n\t\t\t\toptions,\n\t\t\t\tcontext.showImages,\n\t\t\t\tstate.startedAt,\n\t\t\t\tstate.endedAt,\n\t\t\t\tcompact,\n\t\t\t);\n\t\t\tcomponent.invalidate();\n\t\t\treturn component;\n\t\t},\n\t};\n}\n\nexport function createBashTool(cwd: string, options?: BashToolOptions): AgentTool<typeof bashSchema> {\n\treturn wrapToolDefinition(createBashToolDefinition(cwd, options));\n}\n"]}
1
+ {"version":3,"file":"bash.js","sourceRoot":"","sources":["../../../src/core/tools/bash.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,MAAM,IAAI,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAEtD,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC1E,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAe,IAAI,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,wDAAwD,CAAC;AACjF,OAAO,EAAE,qBAAqB,EAAE,MAAM,uDAAuD,CAAC;AAC9F,OAAO,EAAE,KAAK,EAAE,MAAM,wCAAwC,CAAC;AAC/D,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,EACN,cAAc,EACd,WAAW,EACX,eAAe,EACf,qBAAqB,EACrB,uBAAuB,GACvB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAAE,UAAU,IAAI,iBAAiB,EAAE,QAAQ,IAAI,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACtG,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,GAAG,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AACjG,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AACl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AAO,EACb,OAAO,CACP,CAAC;YACF,SAAS,CAAC,UAAU,EAAE,CAAC;YACvB,OAAO,SAAS,CAAC;QAAA,CACjB;KACD,CAAC;AAAA,CACF;AAED,MAAM,UAAU,cAAc,CAAC,GAAW,EAAE,OAAyB,EAAgC;IACpG,OAAO,kBAAkB,CAAC,wBAAwB,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC;AAAA,CAClE","sourcesContent":["import { constants } from \"node:fs\";\nimport { access as fsAccess } from \"node:fs/promises\";\nimport type { AgentTool } from \"@ashx-j/lunr-agent\";\nimport { Container, Text, truncateToWidth } from \"@ashx-j/lunr-tui\";\nimport { spawn } from \"child_process\";\nimport { type Static, Type } from \"typebox\";\nimport { keyHint } from \"../../modes/interactive/components/keybinding-hints.ts\";\nimport { truncateToVisualLines } from \"../../modes/interactive/components/visual-truncate.ts\";\nimport { theme } from \"../../modes/interactive/theme/theme.ts\";\nimport { waitForChildProcess } from \"../../utils/child-process.ts\";\nimport {\n\tgetShellConfig,\n\tgetShellEnv,\n\tkillProcessTree,\n\ttrackDetachedChildPid,\n\tuntrackDetachedChildPid,\n} from \"../../utils/shell.ts\";\nimport type { ToolDefinition, ToolRenderResultOptions } from \"../extensions/types.ts\";\nimport { markExited as markProcessExited, register as registerProcess } from \"../process-registry.ts\";\nimport { OutputAccumulator } from \"./output-accumulator.ts\";\nimport { getTextOutput, invalidArgText, str, toolStatusDotFromContext } from \"./render-utils.ts\";\nimport { wrapToolDefinition } from \"./tool-definition-wrapper.ts\";\nimport { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, formatSize, type TruncationResult } from \"./truncate.ts\";\n\nconst MAX_TIMEOUT_MS = 2_147_483_647;\nconst MAX_TIMEOUT_SECONDS = MAX_TIMEOUT_MS / 1000;\n\nfunction resolveTimeoutMs(timeout: number | undefined): number | undefined {\n\tif (timeout === undefined) return undefined;\n\tif (!Number.isFinite(timeout) || timeout <= 0) {\n\t\tthrow new Error(\"Invalid timeout: must be a finite number of seconds\");\n\t}\n\n\tconst timeoutMs = timeout * 1000;\n\tif (timeoutMs > MAX_TIMEOUT_MS) {\n\t\tthrow new Error(`Invalid timeout: maximum is ${MAX_TIMEOUT_SECONDS} seconds`);\n\t}\n\treturn timeoutMs;\n}\n\nconst bashSchema = Type.Object({\n\tcommand: Type.String({ description: \"Bash command to execute\" }),\n\ttimeout: Type.Optional(Type.Number({ description: \"Timeout in seconds (optional, no default timeout)\" })),\n});\n\nexport type BashToolInput = Static<typeof bashSchema>;\n\nexport interface BashToolDetails {\n\ttruncation?: TruncationResult;\n\tfullOutputPath?: string;\n}\n\n/**\n * Pluggable operations for the bash tool.\n * Override these to delegate command execution to remote systems (for example SSH).\n */\nexport interface BashOperations {\n\t/**\n\t * Execute a command and stream output.\n\t * @param command The command to execute\n\t * @param cwd Working directory\n\t * @param options Execution options\n\t * @returns Promise resolving to exit code (null if killed)\n\t */\n\texec: (\n\t\tcommand: string,\n\t\tcwd: string,\n\t\toptions: {\n\t\t\tonData: (data: Buffer) => void;\n\t\t\tsignal?: AbortSignal;\n\t\t\ttimeout?: number;\n\t\t\tenv?: NodeJS.ProcessEnv;\n\t\t},\n\t) => Promise<{ exitCode: number | null }>;\n}\n\n/**\n * Create bash operations using pi's built-in local shell execution backend.\n *\n * This is useful for extensions that intercept user_bash and still want pi's\n * standard local shell behavior while wrapping or rewriting commands.\n */\nexport function createLocalBashOperations(options?: { shellPath?: string; sessionId?: string }): BashOperations {\n\treturn {\n\t\texec: async (command, cwd, { onData, signal, timeout, env }) => {\n\t\t\tconst timeoutMs = resolveTimeoutMs(timeout);\n\t\t\tif (signal?.aborted) {\n\t\t\t\tthrow new Error(\"aborted\");\n\t\t\t}\n\t\t\tconst shellConfig = getShellConfig(options?.shellPath);\n\t\t\ttry {\n\t\t\t\tawait fsAccess(cwd, constants.F_OK);\n\t\t\t} catch {\n\t\t\t\tthrow new Error(`Working directory does not exist: ${cwd}\\nCannot execute bash commands.`);\n\t\t\t}\n\n\t\t\tconst commandFromStdin = shellConfig.commandTransport === \"stdin\";\n\t\t\tconst child = spawn(shellConfig.shell, commandFromStdin ? shellConfig.args : [...shellConfig.args, command], {\n\t\t\t\tcwd,\n\t\t\t\tdetached: process.platform !== \"win32\",\n\t\t\t\tenv: env ?? getShellEnv(),\n\t\t\t\tstdio: [commandFromStdin ? \"pipe\" : \"ignore\", \"pipe\", \"pipe\"],\n\t\t\t\twindowsHide: true,\n\t\t\t});\n\t\t\tif (commandFromStdin) {\n\t\t\t\tchild.stdin?.on(\"error\", () => {});\n\t\t\t\tchild.stdin?.end(command);\n\t\t\t}\n\t\t\tif (child.pid) trackDetachedChildPid(child.pid);\n\t\t\t// lunr: register the process for /processes tracking.\n\t\t\tif (child.pid) {\n\t\t\t\ttry {\n\t\t\t\t\tregisterProcess(child.pid, command, cwd, options?.sessionId);\n\t\t\t\t} catch {}\n\t\t\t}\n\t\t\tlet timedOut = false;\n\t\t\tlet timeoutHandle: NodeJS.Timeout | undefined;\n\t\t\tconst onAbort = () => {\n\t\t\t\tif (child.pid) killProcessTree(child.pid);\n\t\t\t};\n\n\t\t\ttry {\n\t\t\t\t// Set timeout if provided.\n\t\t\t\tif (timeoutMs !== undefined) {\n\t\t\t\t\ttimeoutHandle = setTimeout(() => {\n\t\t\t\t\t\ttimedOut = true;\n\t\t\t\t\t\tif (child.pid) killProcessTree(child.pid);\n\t\t\t\t\t}, timeoutMs);\n\t\t\t\t}\n\t\t\t\t// Stream stdout and stderr.\n\t\t\t\tchild.stdout?.on(\"data\", onData);\n\t\t\t\tchild.stderr?.on(\"data\", onData);\n\t\t\t\t// Handle abort signal by killing the entire process tree.\n\t\t\t\tif (signal) {\n\t\t\t\t\tif (signal.aborted) onAbort();\n\t\t\t\t\telse signal.addEventListener(\"abort\", onAbort, { once: true });\n\t\t\t\t}\n\t\t\t\t// Handle shell spawn errors and wait for the process to terminate without hanging\n\t\t\t\t// on inherited stdio handles held by detached descendants.\n\t\t\t\tconst exitCode = await waitForChildProcess(child);\n\t\t\t\tif (signal?.aborted) {\n\t\t\t\t\tthrow new Error(\"aborted\");\n\t\t\t\t}\n\t\t\t\tif (timedOut) {\n\t\t\t\t\tthrow new Error(`timeout:${timeout}`);\n\t\t\t\t}\n\t\t\t\treturn { exitCode };\n\t\t\t} finally {\n\t\t\t\tif (child.pid) untrackDetachedChildPid(child.pid);\n\t\t\t\t// lunr: unregister from /processes if the process has exited; keep it if still\n\t\t\t\t// alive (detached/backgrounded dev servers survive the shell call).\n\t\t\t\tif (child.pid) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\t// lunr: keep finished processes visible briefly so /processes can show\n\t\t\t\t\t\t// their exit state; markExited deletes trivial fast commands immediately.\n\t\t\t\t\t\tmarkProcessExited(child.pid, child.exitCode);\n\t\t\t\t\t} catch {}\n\t\t\t\t}\n\t\t\t\tif (timeoutHandle) clearTimeout(timeoutHandle);\n\t\t\t\tif (signal) signal.removeEventListener(\"abort\", onAbort);\n\t\t\t}\n\t\t},\n\t};\n}\n\nexport interface BashSpawnContext {\n\tcommand: string;\n\tcwd: string;\n\tenv: NodeJS.ProcessEnv;\n}\n\nexport type BashSpawnHook = (context: BashSpawnContext) => BashSpawnContext;\n\nfunction resolveSpawnContext(command: string, cwd: string, spawnHook?: BashSpawnHook): BashSpawnContext {\n\tconst baseContext: BashSpawnContext = { command, cwd, env: { ...getShellEnv() } };\n\treturn spawnHook ? spawnHook(baseContext) : baseContext;\n}\n\nexport interface BashToolOptions {\n\t/** Custom operations for command execution. Default: local shell */\n\toperations?: BashOperations;\n\t/** Command prefix prepended to every command (for example shell setup commands) */\n\tcommandPrefix?: string;\n\t/** Optional explicit shell path from settings */\n\tshellPath?: string;\n\t/** Hook to adjust command, cwd, or env before execution */\n\tspawnHook?: BashSpawnHook;\n}\n\nconst BASH_PREVIEW_LINES = 5;\nconst BASH_UPDATE_THROTTLE_MS = 100;\n\ntype BashRenderState = {\n\tstartedAt: number | undefined;\n\tendedAt: number | undefined;\n\tinterval: NodeJS.Timeout | undefined;\n};\n\ntype BashResultRenderState = {\n\tcachedWidth: number | undefined;\n\tcachedLines: string[] | undefined;\n\tcachedSkipped: number | undefined;\n};\n\nclass BashResultRenderComponent extends Container {\n\tstate: BashResultRenderState = {\n\t\tcachedWidth: undefined,\n\t\tcachedLines: undefined,\n\t\tcachedSkipped: undefined,\n\t};\n}\n\nfunction formatDuration(ms: number): string {\n\treturn `${(ms / 1000).toFixed(1)}s`;\n}\n\n// lunr: slim header — collapsed calls show only the first line of the command,\n// capped at this many chars; an ellipsis marks either kind of truncation.\nconst MAX_COLLAPSED_COMMAND_CHARS = 100;\n\nfunction formatBashCall(\n\targs: { command?: string; timeout?: number } | undefined,\n\toptions?: { expanded?: boolean; compact?: boolean },\n): string {\n\tconst command = str(args?.command);\n\tconst timeout = args?.timeout as number | undefined;\n\t// lunr: compact-by-default — the timeout suffix is noise on a one-line header;\n\t// it stays visible while streaming and in the expanded view.\n\tconst timeoutSuffix = timeout && !options?.compact ? theme.fg(\"muted\", ` (timeout ${timeout}s)`) : \"\";\n\tlet commandDisplay = command === null ? invalidArgText(theme) : command ? command : theme.fg(\"toolOutput\", \"...\");\n\tif (!options?.expanded && command) {\n\t\tconst firstLine = command.split(\"\\n\")[0];\n\t\tconst capped = firstLine.length > MAX_COLLAPSED_COMMAND_CHARS;\n\t\tconst base = capped ? firstLine.slice(0, MAX_COLLAPSED_COMMAND_CHARS) : firstLine;\n\t\tcommandDisplay = capped || base.length < command.length ? `${base} …` : base;\n\t}\n\treturn theme.fg(\"toolTitle\", theme.bold(`$ ${commandDisplay}`)) + timeoutSuffix;\n}\n\nfunction rebuildBashResultRenderComponent(\n\tcomponent: BashResultRenderComponent,\n\tresult: {\n\t\tcontent: Array<{ type: string; text?: string; data?: string; mimeType?: string }>;\n\t\tdetails?: BashToolDetails;\n\t},\n\toptions: ToolRenderResultOptions,\n\tshowImages: boolean,\n\tstartedAt: number | undefined,\n\tendedAt: number | undefined,\n\t// lunr: compact-by-default — finished, successful, non-expanded calls skip the\n\t// output preview and the \"Took\" footer (duration moves into the call header).\n\tcompact = false,\n): void {\n\tconst state = component.state;\n\tcomponent.clear();\n\n\tlet output = getTextOutput(result as any, showImages).trim();\n\tconst truncation = result.details?.truncation;\n\tconst fullOutputPath = result.details?.fullOutputPath;\n\tif (!options.isPartial && truncation?.truncated && fullOutputPath && output.endsWith(\"]\")) {\n\t\tconst footerStart = output.lastIndexOf(\"\\n\\n[\");\n\t\tif (footerStart !== -1 && output.slice(footerStart).includes(fullOutputPath)) {\n\t\t\toutput = output.slice(0, footerStart).trimEnd();\n\t\t}\n\t}\n\n\tif (!compact && output) {\n\t\tconst styledOutput = output\n\t\t\t.split(\"\\n\")\n\t\t\t.map((line) => theme.fg(\"toolOutput\", line))\n\t\t\t.join(\"\\n\");\n\n\t\tif (options.expanded) {\n\t\t\tcomponent.addChild(new Text(`\\n${styledOutput}`, 0, 0));\n\t\t} else {\n\t\t\tcomponent.addChild({\n\t\t\t\trender: (width: number) => {\n\t\t\t\t\tif (state.cachedLines === undefined || state.cachedWidth !== width) {\n\t\t\t\t\t\tconst preview = truncateToVisualLines(styledOutput, BASH_PREVIEW_LINES, width);\n\t\t\t\t\t\tstate.cachedLines = preview.visualLines;\n\t\t\t\t\t\tstate.cachedSkipped = preview.skippedCount;\n\t\t\t\t\t\tstate.cachedWidth = width;\n\t\t\t\t\t}\n\t\t\t\t\tif (state.cachedSkipped && state.cachedSkipped > 0) {\n\t\t\t\t\t\tconst hint =\n\t\t\t\t\t\t\ttheme.fg(\"muted\", `... (${state.cachedSkipped} earlier lines,`) +\n\t\t\t\t\t\t\t` ${keyHint(\"app.tools.expand\", \"to expand\")}${theme.fg(\"muted\", \")\")}`;\n\t\t\t\t\t\treturn [\"\", truncateToWidth(hint, width, \"...\"), ...(state.cachedLines ?? [])];\n\t\t\t\t\t}\n\t\t\t\t\treturn [\"\", ...(state.cachedLines ?? [])];\n\t\t\t\t},\n\t\t\t\tinvalidate: () => {\n\t\t\t\t\tstate.cachedWidth = undefined;\n\t\t\t\t\tstate.cachedLines = undefined;\n\t\t\t\t\tstate.cachedSkipped = undefined;\n\t\t\t\t},\n\t\t\t});\n\t\t}\n\t}\n\n\t// lunr: the truncation/full-output notice is intentionally NOT rendered in\n\t// the TUI — the model still gets it in the result text (formatOutput), and\n\t// the temp-log path is noise on screen.\n\n\tif (!compact && startedAt !== undefined) {\n\t\tconst label = options.isPartial ? \"Elapsed\" : \"Took\";\n\t\tconst endTime = endedAt ?? Date.now();\n\t\tcomponent.addChild(new Text(`\\n${theme.fg(\"muted\", `${label} ${formatDuration(endTime - startedAt)}`)}`, 0, 0));\n\t}\n}\n\nexport function createBashToolDefinition(\n\tcwd: string,\n\toptions?: BashToolOptions,\n): ToolDefinition<typeof bashSchema, BashToolDetails | undefined, BashRenderState> {\n\tconst ops = options?.operations ?? createLocalBashOperations({ shellPath: options?.shellPath });\n\tconst commandPrefix = options?.commandPrefix;\n\tconst spawnHook = options?.spawnHook;\n\treturn {\n\t\tname: \"bash\",\n\t\tlabel: \"bash\",\n\t\tdescription: `Execute a bash command in the current working directory. Returns stdout and stderr. Output is truncated to last ${DEFAULT_MAX_LINES} lines or ${DEFAULT_MAX_BYTES / 1024}KB (whichever is hit first). If truncated, full output is saved to a temp file. Optionally provide a timeout in seconds.`,\n\t\tpromptSnippet: \"Execute bash commands (ls, grep, find, etc.)\",\n\t\tparameters: bashSchema,\n\t\tasync execute(\n\t\t\t_toolCallId,\n\t\t\t{ command, timeout }: { command: string; timeout?: number },\n\t\t\tsignal?: AbortSignal,\n\t\t\tonUpdate?,\n\t\t\t_ctx?,\n\t\t) {\n\t\t\tconst resolvedCommand = commandPrefix ? `${commandPrefix}\\n${command}` : command;\n\t\t\tconst spawnContext = resolveSpawnContext(resolvedCommand, cwd, spawnHook);\n\t\t\tconst output = new OutputAccumulator({ tempFilePrefix: \"lunr-bash\" }); // lunr: renamed from pi-bash\n\t\t\tlet acceptingOutput = true;\n\t\t\tlet updateTimer: NodeJS.Timeout | undefined;\n\t\t\tlet updateDirty = false;\n\t\t\tlet lastUpdateAt = 0;\n\n\t\t\tconst emitOutputUpdate = () => {\n\t\t\t\tif (!onUpdate || !updateDirty) return;\n\t\t\t\tupdateDirty = false;\n\t\t\t\tlastUpdateAt = Date.now();\n\t\t\t\tconst snapshot = output.snapshot({ persistIfTruncated: true });\n\t\t\t\tonUpdate({\n\t\t\t\t\tcontent: [{ type: \"text\", text: snapshot.content || \"\" }],\n\t\t\t\t\tdetails: {\n\t\t\t\t\t\ttruncation: snapshot.truncation.truncated ? snapshot.truncation : undefined,\n\t\t\t\t\t\tfullOutputPath: snapshot.fullOutputPath,\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t};\n\n\t\t\tconst clearUpdateTimer = () => {\n\t\t\t\tif (updateTimer) {\n\t\t\t\t\tclearTimeout(updateTimer);\n\t\t\t\t\tupdateTimer = undefined;\n\t\t\t\t}\n\t\t\t};\n\n\t\t\tconst scheduleOutputUpdate = () => {\n\t\t\t\tif (!onUpdate) return;\n\t\t\t\tupdateDirty = true;\n\t\t\t\tconst delay = BASH_UPDATE_THROTTLE_MS - (Date.now() - lastUpdateAt);\n\t\t\t\tif (delay <= 0) {\n\t\t\t\t\tclearUpdateTimer();\n\t\t\t\t\temitOutputUpdate();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tupdateTimer ??= setTimeout(() => {\n\t\t\t\t\tupdateTimer = undefined;\n\t\t\t\t\temitOutputUpdate();\n\t\t\t\t}, delay);\n\t\t\t};\n\n\t\t\tif (onUpdate) {\n\t\t\t\tonUpdate({ content: [], details: undefined });\n\t\t\t}\n\n\t\t\tconst handleData = (data: Buffer) => {\n\t\t\t\tif (!acceptingOutput) return;\n\t\t\t\toutput.append(data);\n\t\t\t\tscheduleOutputUpdate();\n\t\t\t};\n\n\t\t\tconst finishOutput = async () => {\n\t\t\t\tacceptingOutput = false;\n\t\t\t\toutput.finish();\n\t\t\t\tclearUpdateTimer();\n\t\t\t\temitOutputUpdate();\n\t\t\t\tconst snapshot = output.snapshot({ persistIfTruncated: true });\n\t\t\t\tawait output.closeTempFile();\n\t\t\t\treturn snapshot;\n\t\t\t};\n\n\t\t\tconst formatOutput = (snapshot: Awaited<ReturnType<typeof finishOutput>>, emptyText = \"(no output)\") => {\n\t\t\t\tconst truncation = snapshot.truncation;\n\t\t\t\tlet text = snapshot.content || emptyText;\n\t\t\t\tlet details: BashToolDetails | undefined;\n\t\t\t\tif (truncation.truncated) {\n\t\t\t\t\tdetails = { truncation, fullOutputPath: snapshot.fullOutputPath };\n\t\t\t\t\tconst startLine = truncation.totalLines - truncation.outputLines + 1;\n\t\t\t\t\tconst endLine = truncation.totalLines;\n\t\t\t\t\tif (truncation.lastLinePartial) {\n\t\t\t\t\t\tconst lastLineSize = formatSize(output.getLastLineBytes());\n\t\t\t\t\t\ttext += `\\n\\n[Showing last ${formatSize(truncation.outputBytes)} of line ${endLine} (line is ${lastLineSize}). Full output: ${snapshot.fullOutputPath}]`;\n\t\t\t\t\t} else if (truncation.truncatedBy === \"lines\") {\n\t\t\t\t\t\ttext += `\\n\\n[Showing lines ${startLine}-${endLine} of ${truncation.totalLines}. Full output: ${snapshot.fullOutputPath}]`;\n\t\t\t\t\t} else {\n\t\t\t\t\t\ttext += `\\n\\n[Showing lines ${startLine}-${endLine} of ${truncation.totalLines} (${formatSize(DEFAULT_MAX_BYTES)} limit). Full output: ${snapshot.fullOutputPath}]`;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn { text, details };\n\t\t\t};\n\n\t\t\tconst appendStatus = (text: string, status: string) => `${text ? `${text}\\n\\n` : \"\"}${status}`;\n\n\t\t\ttry {\n\t\t\t\tlet exitCode: number | null;\n\t\t\t\ttry {\n\t\t\t\t\tconst result = await ops.exec(spawnContext.command, spawnContext.cwd, {\n\t\t\t\t\t\tonData: handleData,\n\t\t\t\t\t\tsignal,\n\t\t\t\t\t\ttimeout,\n\t\t\t\t\t\tenv: spawnContext.env,\n\t\t\t\t\t});\n\t\t\t\t\texitCode = result.exitCode;\n\t\t\t\t} catch (err) {\n\t\t\t\t\tconst snapshot = await finishOutput();\n\t\t\t\t\tconst { text } = formatOutput(snapshot, \"\");\n\t\t\t\t\tif (err instanceof Error && err.message === \"aborted\") {\n\t\t\t\t\t\tthrow new Error(appendStatus(text, \"Command aborted\"));\n\t\t\t\t\t}\n\t\t\t\t\tif (err instanceof Error && err.message.startsWith(\"timeout:\")) {\n\t\t\t\t\t\tconst timeoutSecs = err.message.split(\":\")[1];\n\t\t\t\t\t\tthrow new Error(appendStatus(text, `Command timed out after ${timeoutSecs} seconds`));\n\t\t\t\t\t}\n\t\t\t\t\tthrow err;\n\t\t\t\t}\n\n\t\t\t\tconst snapshot = await finishOutput();\n\t\t\t\tconst { text: outputText, details } = formatOutput(snapshot);\n\t\t\t\tif (exitCode !== 0 && exitCode !== null) {\n\t\t\t\t\tthrow new Error(appendStatus(outputText, `Command exited with code ${exitCode}`));\n\t\t\t\t}\n\t\t\t\treturn { content: [{ type: \"text\", text: outputText }], details };\n\t\t\t} finally {\n\t\t\t\tclearUpdateTimer();\n\t\t\t}\n\t\t},\n\t\trenderCall(args, _theme, context) {\n\t\t\tconst state = context.state;\n\t\t\tif (context.executionStarted && state.startedAt === undefined) {\n\t\t\t\tstate.startedAt = Date.now();\n\t\t\t\tstate.endedAt = undefined;\n\t\t\t}\n\t\t\t// lunr: compact-by-default — stamp endedAt here too: renderCall runs before\n\t\t\t// renderResult on the final update, and the header needs the duration.\n\t\t\tif (!context.isPartial && state.startedAt !== undefined) {\n\t\t\t\tstate.endedAt ??= Date.now();\n\t\t\t}\n\t\t\t// lunr: compact-by-default — a finished, successful, non-expanded call\n\t\t\t// renders as a single slim header line with the duration folded in.\n\t\t\tconst compact = !context.isPartial && !context.expanded && !context.isError;\n\t\t\tlet header = `${toolStatusDotFromContext(context, theme)} ${formatBashCall(args, { expanded: context.expanded, compact })}`;\n\t\t\tif (compact && state.startedAt !== undefined && state.endedAt !== undefined) {\n\t\t\t\theader += theme.fg(\"muted\", ` — Took ${formatDuration(state.endedAt - state.startedAt)}`);\n\t\t\t}\n\t\t\tconst text = (context.lastComponent as Text | undefined) ?? new Text(\"\", 0, 0);\n\t\t\ttext.setText(header);\n\t\t\treturn text;\n\t\t},\n\t\trenderResult(result, options, _theme, context) {\n\t\t\tconst state = context.state;\n\t\t\tif (state.startedAt !== undefined && options.isPartial && !state.interval) {\n\t\t\t\tstate.interval = setInterval(() => context.invalidate(), 1000);\n\t\t\t}\n\t\t\tif (!options.isPartial || context.isError) {\n\t\t\t\tstate.endedAt ??= Date.now();\n\t\t\t\tif (state.interval) {\n\t\t\t\t\tclearInterval(state.interval);\n\t\t\t\t\tstate.interval = undefined;\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst component =\n\t\t\t\t(context.lastComponent as BashResultRenderComponent | undefined) ?? new BashResultRenderComponent();\n\t\t\t// lunr: compact-by-default — suppresses the output preview + \"Took\" footer.\n\t\t\tconst compact = !options.isPartial && !options.expanded && !context.isError;\n\t\t\trebuildBashResultRenderComponent(\n\t\t\t\tcomponent,\n\t\t\t\tresult as any,\n\t\t\t\toptions,\n\t\t\t\tcontext.showImages,\n\t\t\t\tstate.startedAt,\n\t\t\t\tstate.endedAt,\n\t\t\t\tcompact,\n\t\t\t);\n\t\t\tcomponent.invalidate();\n\t\t\treturn component;\n\t\t},\n\t};\n}\n\nexport function createBashTool(cwd: string, options?: BashToolOptions): AgentTool<typeof bashSchema> {\n\treturn wrapToolDefinition(createBashToolDefinition(cwd, options));\n}\n"]}
@@ -1,5 +1,5 @@
1
- import type { AgentTool } from "@earendil-works/pi-agent-core";
2
- import { Box } from "@earendil-works/pi-tui";
1
+ import type { AgentTool } from "@ashx-j/lunr-agent";
2
+ import { Box } from "@ashx-j/lunr-tui";
3
3
  import { type Static, Type } from "typebox";
4
4
  import type { ToolDefinition } from "../extensions/types.ts";
5
5
  import { type EditDiffError, type EditDiffResult } from "./edit-diff.ts";
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AC5B;AAgDD,KAAK,uBAAuB,GAAG,GAAG,GAAG;IACpC,OAAO,CAAC,EAAE,WAAW,CAAC;IACtB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,YAAY,CAAC,EAAE,OAAO,CAAC;CACvB,CAAC;AAkJF,wBAAgB,wBAAwB,CACvC,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE,eAAe,GACvB,cAAc,CAAC,OAAO,UAAU,EAAE,eAAe,GAAG,SAAS,EAAE,eAAe,CAAC,CA6JjF;AAED,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,SAAS,CAAC,OAAO,UAAU,CAAC,CAEnG","sourcesContent":["import type { AgentTool } from \"@earendil-works/pi-agent-core\";\nimport { Box, Container, Spacer, Text } from \"@earendil-works/pi-tui\";\nimport { constants } from \"fs\";\nimport { access as fsAccess, readFile as fsReadFile, writeFile as fsWriteFile } from \"fs/promises\";\nimport { type Static, Type } from \"typebox\";\nimport { renderDiff } from \"../../modes/interactive/components/diff.ts\";\nimport type { Theme } from \"../../modes/interactive/theme/theme.ts\";\nimport type { ToolDefinition } from \"../extensions/types.ts\";\nimport {\n\tapplyEditsToNormalizedContent,\n\tcomputeEditsDiff,\n\tdetectLineEnding,\n\ttype Edit,\n\ttype EditDiffError,\n\ttype EditDiffResult,\n\tgenerateDiffString,\n\tgenerateUnifiedPatch,\n\tnormalizeToLF,\n\trestoreLineEndings,\n\tstripBom,\n} from \"./edit-diff.ts\";\nimport { withFileMutationQueue } from \"./file-mutation-queue.ts\";\nimport { resolveToCwd } from \"./path-utils.ts\";\nimport { renderToolPath, str, type ToolStatusDotState, toolStatusDot } from \"./render-utils.ts\";\nimport { wrapToolDefinition } from \"./tool-definition-wrapper.ts\";\n\ntype EditPreview = EditDiffResult | EditDiffError;\n\ntype EditRenderState = {\n\tcallComponent?: EditCallRenderComponent;\n};\n\nconst replaceEditSchema = Type.Object(\n\t{\n\t\toldText: Type.String({\n\t\t\tdescription:\n\t\t\t\t\"Exact text for one targeted replacement. It must be unique in the original file and must not overlap with any other edits[].oldText in the same call.\",\n\t\t}),\n\t\tnewText: Type.String({ description: \"Replacement text for this targeted edit.\" }),\n\t},\n\t{},\n);\n\nconst editSchema = Type.Object(\n\t{\n\t\tpath: Type.String({ description: \"Path to the file to edit (relative or absolute)\" }),\n\t\tedits: Type.Array(replaceEditSchema, {\n\t\t\tdescription:\n\t\t\t\t\"One or more targeted replacements. Each edit is matched against the original file, not incrementally. Do not include overlapping or nested edits. If two changes touch the same block or nearby lines, merge them into one edit instead.\",\n\t\t}),\n\t},\n\t{},\n);\n\nexport type EditToolInput = Static<typeof editSchema>;\ntype LegacyEditToolInput = EditToolInput & {\n\toldText?: unknown;\n\tnewText?: unknown;\n};\n\nexport interface EditToolDetails {\n\t/** Display-oriented diff of the changes made */\n\tdiff: string;\n\t/** Standard unified patch of the changes made */\n\tpatch: string;\n\t/** Line number of the first change in the new file (for editor navigation) */\n\tfirstChangedLine?: number;\n}\n\n/**\n * Pluggable operations for the edit tool.\n * Override these to delegate file editing to remote systems (for example SSH).\n */\nexport interface EditOperations {\n\t/** Read file contents as a Buffer */\n\treadFile: (absolutePath: string) => Promise<Buffer>;\n\t/** Write content to a file */\n\twriteFile: (absolutePath: string, content: string) => Promise<void>;\n\t/** Check if file is readable and writable (throw if not) */\n\taccess: (absolutePath: string) => Promise<void>;\n}\n\nconst defaultEditOperations: EditOperations = {\n\treadFile: (path) => fsReadFile(path),\n\twriteFile: (path, content) => fsWriteFile(path, content, \"utf-8\"),\n\taccess: (path) => fsAccess(path, constants.R_OK | constants.W_OK),\n};\n\nexport interface EditToolOptions {\n\t/** Custom operations for file editing. Default: local filesystem */\n\toperations?: EditOperations;\n}\n\nfunction prepareEditArguments(input: unknown): EditToolInput {\n\tif (!input || typeof input !== \"object\") {\n\t\treturn input as EditToolInput;\n\t}\n\n\tconst args = input as Record<string, unknown>;\n\n\t// Some models (Opus 4.6, GLM-5.1) send edits as a JSON string instead of an array\n\tif (typeof args.edits === \"string\") {\n\t\ttry {\n\t\t\tconst parsed = JSON.parse(args.edits);\n\t\t\tif (Array.isArray(parsed)) args.edits = parsed;\n\t\t} catch {}\n\t}\n\n\tconst legacy = args as LegacyEditToolInput;\n\tif (typeof legacy.oldText !== \"string\" || typeof legacy.newText !== \"string\") {\n\t\treturn args as EditToolInput;\n\t}\n\n\tconst edits = Array.isArray(legacy.edits) ? [...legacy.edits] : [];\n\tedits.push({ oldText: legacy.oldText, newText: legacy.newText });\n\tconst { oldText: _oldText, newText: _newText, ...rest } = legacy;\n\treturn { ...rest, edits } as EditToolInput;\n}\n\nfunction validateEditInput(input: EditToolInput): { path: string; edits: Edit[] } {\n\tif (!Array.isArray(input.edits) || input.edits.length === 0) {\n\t\tthrow new Error(\"Edit tool input is invalid. edits must contain at least one replacement.\");\n\t}\n\treturn { path: input.path, edits: input.edits };\n}\n\ntype RenderableEditArgs = {\n\tpath?: string;\n\tfile_path?: string;\n\tedits?: Edit[];\n\toldText?: string;\n\tnewText?: string;\n};\n\ntype EditToolResultLike = {\n\tcontent: Array<{ type: string; text?: string; data?: string; mimeType?: string }>;\n\tdetails?: EditToolDetails;\n};\n\ntype EditCallRenderComponent = Box & {\n\tpreview?: EditPreview;\n\tpreviewArgsKey?: string;\n\tpreviewPending?: boolean;\n\tsettledError?: boolean;\n};\n\nfunction createEditCallRenderComponent(): EditCallRenderComponent {\n\treturn Object.assign(new Box(1, 1, (text: string) => text), {\n\t\tpreview: undefined as EditPreview | undefined,\n\t\tpreviewArgsKey: undefined as string | undefined,\n\t\tpreviewPending: false,\n\t\tsettledError: false,\n\t});\n}\n\nfunction getEditCallRenderComponent(state: EditRenderState, lastComponent: unknown): EditCallRenderComponent {\n\tif (lastComponent instanceof Box) {\n\t\tconst component = lastComponent as EditCallRenderComponent;\n\t\tstate.callComponent = component;\n\t\treturn component;\n\t}\n\tif (state.callComponent) {\n\t\treturn state.callComponent;\n\t}\n\tconst component = createEditCallRenderComponent();\n\tstate.callComponent = component;\n\treturn component;\n}\n\nfunction getRenderablePreviewInput(args: RenderableEditArgs | undefined): { path: string; edits: Edit[] } | null {\n\tif (!args) {\n\t\treturn null;\n\t}\n\n\tconst path = typeof args.path === \"string\" ? args.path : typeof args.file_path === \"string\" ? args.file_path : null;\n\tif (!path) {\n\t\treturn null;\n\t}\n\n\tif (\n\t\tArray.isArray(args.edits) &&\n\t\targs.edits.length > 0 &&\n\t\targs.edits.every((edit) => typeof edit?.oldText === \"string\" && typeof edit?.newText === \"string\")\n\t) {\n\t\treturn { path, edits: args.edits };\n\t}\n\n\tif (typeof args.oldText === \"string\" && typeof args.newText === \"string\") {\n\t\treturn { path, edits: [{ oldText: args.oldText, newText: args.newText }] };\n\t}\n\n\treturn null;\n}\n\nfunction formatEditCall(args: RenderableEditArgs | undefined, theme: Theme, cwd: string): string {\n\tconst pathDisplay = renderToolPath(str(args?.file_path ?? args?.path), theme, cwd);\n\treturn `${theme.fg(\"toolTitle\", theme.bold(\"edit\"))} ${pathDisplay}`;\n}\n\nfunction formatEditResult(\n\targs: RenderableEditArgs | undefined,\n\tpreview: EditPreview | undefined,\n\tresult: EditToolResultLike,\n\ttheme: Theme,\n\tisError: boolean,\n): string | undefined {\n\tconst rawPath = str(args?.file_path ?? args?.path);\n\tconst previewDiff = preview && !(\"error\" in preview) ? preview.diff : undefined;\n\tconst previewError = preview && \"error\" in preview ? preview.error : undefined;\n\tif (isError) {\n\t\tconst errorText = result.content\n\t\t\t.filter((c) => c.type === \"text\")\n\t\t\t.map((c) => c.text || \"\")\n\t\t\t.join(\"\\n\");\n\t\tif (!errorText || errorText === previewError) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn theme.fg(\"error\", errorText);\n\t}\n\n\tconst resultDiff = result.details?.diff;\n\tif (resultDiff && resultDiff !== previewDiff) {\n\t\treturn renderDiff(resultDiff, { filePath: rawPath ?? undefined });\n\t}\n\n\treturn undefined;\n}\n\nfunction getEditHeaderBg(\n\tpreview: EditPreview | undefined,\n\tsettledError: boolean | undefined,\n\ttheme: Theme,\n): (text: string) => string {\n\tif (preview) {\n\t\tif (\"error\" in preview) {\n\t\t\treturn (text: string) => theme.bg(\"toolErrorBg\", text);\n\t\t}\n\t\treturn (text: string) => theme.bg(\"toolSuccessBg\", text);\n\t}\n\tif (settledError) {\n\t\treturn (text: string) => theme.bg(\"toolErrorBg\", text);\n\t}\n\treturn (text: string) => theme.bg(\"toolPendingBg\", text);\n}\n\nfunction buildEditCallComponent(\n\tcomponent: EditCallRenderComponent,\n\targs: RenderableEditArgs | undefined,\n\ttheme: Theme,\n\tcwd: string,\n\tdotState: ToolStatusDotState,\n\t// lunr: compact-by-default — finished, successful, non-expanded calls render\n\t// header-only; the diff preview stays while streaming and when expanded.\n\tcompact = false,\n): EditCallRenderComponent {\n\tcomponent.setBgFn(getEditHeaderBg(component.preview, component.settledError, theme));\n\tcomponent.clear();\n\tcomponent.addChild(new Text(`${toolStatusDot(dotState, theme)} ${formatEditCall(args, theme, cwd)}`, 0, 0));\n\n\tif (compact || !component.preview) {\n\t\treturn component;\n\t}\n\n\tconst body =\n\t\t\"error\" in component.preview ? theme.fg(\"error\", component.preview.error) : renderDiff(component.preview.diff);\n\tcomponent.addChild(new Spacer(1));\n\tcomponent.addChild(new Text(body, 0, 0));\n\treturn component;\n}\n\nfunction setEditPreview(\n\tcomponent: EditCallRenderComponent,\n\tpreview: EditPreview,\n\targsKey: string | undefined,\n): boolean {\n\tconst current = component.preview;\n\tconst changed =\n\t\tcurrent === undefined ||\n\t\t(\"error\" in current && \"error\" in preview\n\t\t\t? current.error !== preview.error\n\t\t\t: \"error\" in current !== \"error\" in preview) ||\n\t\t(!(\"error\" in current) &&\n\t\t\t!(\"error\" in preview) &&\n\t\t\t(current.diff !== preview.diff || current.firstChangedLine !== preview.firstChangedLine));\n\tcomponent.preview = preview;\n\tcomponent.previewArgsKey = argsKey;\n\tcomponent.previewPending = false;\n\treturn changed;\n}\n\nexport function createEditToolDefinition(\n\tcwd: string,\n\toptions?: EditToolOptions,\n): ToolDefinition<typeof editSchema, EditToolDetails | undefined, EditRenderState> {\n\tconst ops = options?.operations ?? defaultEditOperations;\n\treturn {\n\t\tname: \"edit\",\n\t\tlabel: \"edit\",\n\t\tdescription:\n\t\t\t\"Edit a single file using exact text replacement. Every edits[].oldText must match a unique, non-overlapping region of the original file. If two changes affect the same block or nearby lines, merge them into one edit instead of emitting overlapping edits. Do not include large unchanged regions just to connect distant changes.\",\n\t\tpromptSnippet:\n\t\t\t\"Make precise file edits with exact text replacement, including multiple disjoint edits in one call\",\n\t\tpromptGuidelines: [\n\t\t\t\"Use edit for precise changes (edits[].oldText must match exactly)\",\n\t\t\t\"When changing multiple separate locations in one file, use one edit call with multiple entries in edits[] instead of multiple edit calls\",\n\t\t\t\"Each edits[].oldText is matched against the original file, not after earlier edits are applied. Do not emit overlapping or nested edits. Merge nearby changes into one edit.\",\n\t\t\t\"Keep edits[].oldText as small as possible while still being unique in the file. Do not pad with large unchanged regions.\",\n\t\t],\n\t\tparameters: editSchema,\n\t\trenderShell: \"self\",\n\t\tprepareArguments: prepareEditArguments,\n\t\tasync execute(_toolCallId, input: EditToolInput, signal?: AbortSignal, _onUpdate?, _ctx?) {\n\t\t\tconst { path, edits } = validateEditInput(input);\n\t\t\tconst absolutePath = resolveToCwd(path, cwd);\n\n\t\t\treturn withFileMutationQueue(absolutePath, async () => {\n\t\t\t\t// Do not reject from an abort event listener here: that would release the\n\t\t\t\t// mutation queue while an in-flight filesystem operation may still finish.\n\t\t\t\t// Checking signal.aborted after each await observes the same aborts while\n\t\t\t\t// keeping the queue locked until the current operation has settled.\n\t\t\t\tconst throwIfAborted = (): void => {\n\t\t\t\t\tif (signal?.aborted) throw new Error(\"Operation aborted\");\n\t\t\t\t};\n\n\t\t\t\tthrowIfAborted();\n\n\t\t\t\t// Check if file exists.\n\t\t\t\ttry {\n\t\t\t\t\tawait ops.access(absolutePath);\n\t\t\t\t} catch (error: unknown) {\n\t\t\t\t\tthrowIfAborted();\n\t\t\t\t\tconst errorMessage =\n\t\t\t\t\t\terror instanceof Error && \"code\" in error ? `Error code: ${error.code}` : String(error);\n\t\t\t\t\tthrow new Error(`Could not edit file: ${path}. ${errorMessage}.`);\n\t\t\t\t}\n\t\t\t\tthrowIfAborted();\n\n\t\t\t\t// Read the file.\n\t\t\t\tconst buffer = await ops.readFile(absolutePath);\n\t\t\t\tconst rawContent = buffer.toString(\"utf-8\");\n\t\t\t\tthrowIfAborted();\n\n\t\t\t\t// Strip BOM before matching. The model will not include an invisible BOM in oldText.\n\t\t\t\tconst { bom, text: content } = stripBom(rawContent);\n\t\t\t\tconst originalEnding = detectLineEnding(content);\n\t\t\t\tconst normalizedContent = normalizeToLF(content);\n\t\t\t\tconst { baseContent, newContent } = applyEditsToNormalizedContent(normalizedContent, edits, path);\n\t\t\t\tthrowIfAborted();\n\n\t\t\t\tconst finalContent = bom + restoreLineEndings(newContent, originalEnding);\n\t\t\t\tawait ops.writeFile(absolutePath, finalContent);\n\t\t\t\tthrowIfAborted();\n\n\t\t\t\tconst diffResult = generateDiffString(baseContent, newContent);\n\t\t\t\tconst patch = generateUnifiedPatch(path, baseContent, newContent);\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttype: \"text\",\n\t\t\t\t\t\t\ttext: `Successfully replaced ${edits.length} block(s) in ${path}.`,\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t\tdetails: { diff: diffResult.diff, patch, firstChangedLine: diffResult.firstChangedLine },\n\t\t\t\t};\n\t\t\t});\n\t\t},\n\t\trenderCall(args, theme, context) {\n\t\t\tconst component = getEditCallRenderComponent(context.state, context.lastComponent);\n\t\t\tconst previewInput = getRenderablePreviewInput(args as RenderableEditArgs | undefined);\n\t\t\tconst argsKey = previewInput\n\t\t\t\t? JSON.stringify({ path: previewInput.path, edits: previewInput.edits })\n\t\t\t\t: undefined;\n\n\t\t\tif (component.previewArgsKey !== argsKey) {\n\t\t\t\tcomponent.preview = undefined;\n\t\t\t\tcomponent.previewArgsKey = argsKey;\n\t\t\t\tcomponent.previewPending = false;\n\t\t\t\tcomponent.settledError = false;\n\t\t\t}\n\n\t\t\tif (context.argsComplete && previewInput && !component.preview && !component.previewPending) {\n\t\t\t\tcomponent.previewPending = true;\n\t\t\t\tconst requestKey = argsKey;\n\t\t\t\tvoid computeEditsDiff(previewInput.path, previewInput.edits, context.cwd).then((preview) => {\n\t\t\t\t\tif (component.previewArgsKey === requestKey) {\n\t\t\t\t\t\tsetEditPreview(component, preview, requestKey);\n\t\t\t\t\t\tcontext.invalidate();\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\n\t\t\treturn buildEditCallComponent(\n\t\t\t\tcomponent,\n\t\t\t\targs,\n\t\t\t\ttheme,\n\t\t\t\tcontext.cwd,\n\t\t\t\tcontext.isPartial ? \"pending\" : context.isError ? \"error\" : \"success\",\n\t\t\t\t// lunr: compact-by-default\n\t\t\t\t!context.isPartial && !context.expanded && !context.isError,\n\t\t\t);\n\t\t},\n\t\trenderResult(result, _options, theme, context) {\n\t\t\tconst callComponent = context.state.callComponent;\n\t\t\tconst previewInput = getRenderablePreviewInput(context.args as RenderableEditArgs | undefined);\n\t\t\tconst argsKey = previewInput\n\t\t\t\t? JSON.stringify({ path: previewInput.path, edits: previewInput.edits })\n\t\t\t\t: undefined;\n\t\t\tconst typedResult = result as EditToolResultLike;\n\t\t\tconst resultDiff = !context.isError ? typedResult.details?.diff : undefined;\n\t\t\t// lunr: compact-by-default — header-only call, no result diff body.\n\t\t\tconst compact = !_options.isPartial && !_options.expanded && !context.isError;\n\t\t\tlet changed = false;\n\t\t\tif (callComponent) {\n\t\t\t\tif (typeof resultDiff === \"string\") {\n\t\t\t\t\tchanged =\n\t\t\t\t\t\tsetEditPreview(\n\t\t\t\t\t\t\tcallComponent,\n\t\t\t\t\t\t\t{ diff: resultDiff, firstChangedLine: typedResult.details?.firstChangedLine },\n\t\t\t\t\t\t\targsKey,\n\t\t\t\t\t\t) || changed;\n\t\t\t\t}\n\t\t\t\tif (callComponent.settledError !== context.isError) {\n\t\t\t\t\tcallComponent.settledError = context.isError;\n\t\t\t\t\tchanged = true;\n\t\t\t\t}\n\t\t\t\tif (changed || compact) {\n\t\t\t\t\tbuildEditCallComponent(\n\t\t\t\t\t\tcallComponent,\n\t\t\t\t\t\tcontext.args as RenderableEditArgs | undefined,\n\t\t\t\t\t\ttheme,\n\t\t\t\t\t\tcontext.cwd,\n\t\t\t\t\t\tcontext.isPartial ? \"pending\" : context.isError ? \"error\" : \"success\",\n\t\t\t\t\t\tcompact,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst output = compact\n\t\t\t\t? undefined\n\t\t\t\t: formatEditResult(context.args, callComponent?.preview, typedResult, theme, context.isError);\n\t\t\tconst component = (context.lastComponent as Container | undefined) ?? new Container();\n\t\t\tcomponent.clear();\n\t\t\tif (!output) {\n\t\t\t\treturn component;\n\t\t\t}\n\t\t\tcomponent.addChild(new Spacer(1));\n\t\t\tcomponent.addChild(new Text(output, 1, 0));\n\t\t\treturn component;\n\t\t},\n\t};\n}\n\nexport function createEditTool(cwd: string, options?: EditToolOptions): AgentTool<typeof editSchema> {\n\treturn wrapToolDefinition(createEditToolDefinition(cwd, options));\n}\n"]}
1
+ {"version":3,"file":"edit.d.ts","sourceRoot":"","sources":["../../../src/core/tools/edit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAE,GAAG,EAA2B,MAAM,wBAAwB,CAAC;AAGtE,OAAO,EAAE,KAAK,MAAM,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAG5C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,EAKN,KAAK,aAAa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6JjF;AAED,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,SAAS,CAAC,OAAO,UAAU,CAAC,CAEnG","sourcesContent":["import type { AgentTool } from \"@ashx-j/lunr-agent\";\nimport { Box, Container, Spacer, Text } from \"@ashx-j/lunr-tui\";\nimport { constants } from \"fs\";\nimport { access as fsAccess, readFile as fsReadFile, writeFile as fsWriteFile } from \"fs/promises\";\nimport { type Static, Type } from \"typebox\";\nimport { renderDiff } from \"../../modes/interactive/components/diff.ts\";\nimport type { Theme } from \"../../modes/interactive/theme/theme.ts\";\nimport type { ToolDefinition } from \"../extensions/types.ts\";\nimport {\n\tapplyEditsToNormalizedContent,\n\tcomputeEditsDiff,\n\tdetectLineEnding,\n\ttype Edit,\n\ttype EditDiffError,\n\ttype EditDiffResult,\n\tgenerateDiffString,\n\tgenerateUnifiedPatch,\n\tnormalizeToLF,\n\trestoreLineEndings,\n\tstripBom,\n} from \"./edit-diff.ts\";\nimport { withFileMutationQueue } from \"./file-mutation-queue.ts\";\nimport { resolveToCwd } from \"./path-utils.ts\";\nimport { renderToolPath, str, type ToolStatusDotState, toolStatusDot } from \"./render-utils.ts\";\nimport { wrapToolDefinition } from \"./tool-definition-wrapper.ts\";\n\ntype EditPreview = EditDiffResult | EditDiffError;\n\ntype EditRenderState = {\n\tcallComponent?: EditCallRenderComponent;\n};\n\nconst replaceEditSchema = Type.Object(\n\t{\n\t\toldText: Type.String({\n\t\t\tdescription:\n\t\t\t\t\"Exact text for one targeted replacement. It must be unique in the original file and must not overlap with any other edits[].oldText in the same call.\",\n\t\t}),\n\t\tnewText: Type.String({ description: \"Replacement text for this targeted edit.\" }),\n\t},\n\t{},\n);\n\nconst editSchema = Type.Object(\n\t{\n\t\tpath: Type.String({ description: \"Path to the file to edit (relative or absolute)\" }),\n\t\tedits: Type.Array(replaceEditSchema, {\n\t\t\tdescription:\n\t\t\t\t\"One or more targeted replacements. Each edit is matched against the original file, not incrementally. Do not include overlapping or nested edits. If two changes touch the same block or nearby lines, merge them into one edit instead.\",\n\t\t}),\n\t},\n\t{},\n);\n\nexport type EditToolInput = Static<typeof editSchema>;\ntype LegacyEditToolInput = EditToolInput & {\n\toldText?: unknown;\n\tnewText?: unknown;\n};\n\nexport interface EditToolDetails {\n\t/** Display-oriented diff of the changes made */\n\tdiff: string;\n\t/** Standard unified patch of the changes made */\n\tpatch: string;\n\t/** Line number of the first change in the new file (for editor navigation) */\n\tfirstChangedLine?: number;\n}\n\n/**\n * Pluggable operations for the edit tool.\n * Override these to delegate file editing to remote systems (for example SSH).\n */\nexport interface EditOperations {\n\t/** Read file contents as a Buffer */\n\treadFile: (absolutePath: string) => Promise<Buffer>;\n\t/** Write content to a file */\n\twriteFile: (absolutePath: string, content: string) => Promise<void>;\n\t/** Check if file is readable and writable (throw if not) */\n\taccess: (absolutePath: string) => Promise<void>;\n}\n\nconst defaultEditOperations: EditOperations = {\n\treadFile: (path) => fsReadFile(path),\n\twriteFile: (path, content) => fsWriteFile(path, content, \"utf-8\"),\n\taccess: (path) => fsAccess(path, constants.R_OK | constants.W_OK),\n};\n\nexport interface EditToolOptions {\n\t/** Custom operations for file editing. Default: local filesystem */\n\toperations?: EditOperations;\n}\n\nfunction prepareEditArguments(input: unknown): EditToolInput {\n\tif (!input || typeof input !== \"object\") {\n\t\treturn input as EditToolInput;\n\t}\n\n\tconst args = input as Record<string, unknown>;\n\n\t// Some models (Opus 4.6, GLM-5.1) send edits as a JSON string instead of an array\n\tif (typeof args.edits === \"string\") {\n\t\ttry {\n\t\t\tconst parsed = JSON.parse(args.edits);\n\t\t\tif (Array.isArray(parsed)) args.edits = parsed;\n\t\t} catch {}\n\t}\n\n\tconst legacy = args as LegacyEditToolInput;\n\tif (typeof legacy.oldText !== \"string\" || typeof legacy.newText !== \"string\") {\n\t\treturn args as EditToolInput;\n\t}\n\n\tconst edits = Array.isArray(legacy.edits) ? [...legacy.edits] : [];\n\tedits.push({ oldText: legacy.oldText, newText: legacy.newText });\n\tconst { oldText: _oldText, newText: _newText, ...rest } = legacy;\n\treturn { ...rest, edits } as EditToolInput;\n}\n\nfunction validateEditInput(input: EditToolInput): { path: string; edits: Edit[] } {\n\tif (!Array.isArray(input.edits) || input.edits.length === 0) {\n\t\tthrow new Error(\"Edit tool input is invalid. edits must contain at least one replacement.\");\n\t}\n\treturn { path: input.path, edits: input.edits };\n}\n\ntype RenderableEditArgs = {\n\tpath?: string;\n\tfile_path?: string;\n\tedits?: Edit[];\n\toldText?: string;\n\tnewText?: string;\n};\n\ntype EditToolResultLike = {\n\tcontent: Array<{ type: string; text?: string; data?: string; mimeType?: string }>;\n\tdetails?: EditToolDetails;\n};\n\ntype EditCallRenderComponent = Box & {\n\tpreview?: EditPreview;\n\tpreviewArgsKey?: string;\n\tpreviewPending?: boolean;\n\tsettledError?: boolean;\n};\n\nfunction createEditCallRenderComponent(): EditCallRenderComponent {\n\treturn Object.assign(new Box(1, 1, (text: string) => text), {\n\t\tpreview: undefined as EditPreview | undefined,\n\t\tpreviewArgsKey: undefined as string | undefined,\n\t\tpreviewPending: false,\n\t\tsettledError: false,\n\t});\n}\n\nfunction getEditCallRenderComponent(state: EditRenderState, lastComponent: unknown): EditCallRenderComponent {\n\tif (lastComponent instanceof Box) {\n\t\tconst component = lastComponent as EditCallRenderComponent;\n\t\tstate.callComponent = component;\n\t\treturn component;\n\t}\n\tif (state.callComponent) {\n\t\treturn state.callComponent;\n\t}\n\tconst component = createEditCallRenderComponent();\n\tstate.callComponent = component;\n\treturn component;\n}\n\nfunction getRenderablePreviewInput(args: RenderableEditArgs | undefined): { path: string; edits: Edit[] } | null {\n\tif (!args) {\n\t\treturn null;\n\t}\n\n\tconst path = typeof args.path === \"string\" ? args.path : typeof args.file_path === \"string\" ? args.file_path : null;\n\tif (!path) {\n\t\treturn null;\n\t}\n\n\tif (\n\t\tArray.isArray(args.edits) &&\n\t\targs.edits.length > 0 &&\n\t\targs.edits.every((edit) => typeof edit?.oldText === \"string\" && typeof edit?.newText === \"string\")\n\t) {\n\t\treturn { path, edits: args.edits };\n\t}\n\n\tif (typeof args.oldText === \"string\" && typeof args.newText === \"string\") {\n\t\treturn { path, edits: [{ oldText: args.oldText, newText: args.newText }] };\n\t}\n\n\treturn null;\n}\n\nfunction formatEditCall(args: RenderableEditArgs | undefined, theme: Theme, cwd: string): string {\n\tconst pathDisplay = renderToolPath(str(args?.file_path ?? args?.path), theme, cwd);\n\treturn `${theme.fg(\"toolTitle\", theme.bold(\"edit\"))} ${pathDisplay}`;\n}\n\nfunction formatEditResult(\n\targs: RenderableEditArgs | undefined,\n\tpreview: EditPreview | undefined,\n\tresult: EditToolResultLike,\n\ttheme: Theme,\n\tisError: boolean,\n): string | undefined {\n\tconst rawPath = str(args?.file_path ?? args?.path);\n\tconst previewDiff = preview && !(\"error\" in preview) ? preview.diff : undefined;\n\tconst previewError = preview && \"error\" in preview ? preview.error : undefined;\n\tif (isError) {\n\t\tconst errorText = result.content\n\t\t\t.filter((c) => c.type === \"text\")\n\t\t\t.map((c) => c.text || \"\")\n\t\t\t.join(\"\\n\");\n\t\tif (!errorText || errorText === previewError) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn theme.fg(\"error\", errorText);\n\t}\n\n\tconst resultDiff = result.details?.diff;\n\tif (resultDiff && resultDiff !== previewDiff) {\n\t\treturn renderDiff(resultDiff, { filePath: rawPath ?? undefined });\n\t}\n\n\treturn undefined;\n}\n\nfunction getEditHeaderBg(\n\tpreview: EditPreview | undefined,\n\tsettledError: boolean | undefined,\n\ttheme: Theme,\n): (text: string) => string {\n\tif (preview) {\n\t\tif (\"error\" in preview) {\n\t\t\treturn (text: string) => theme.bg(\"toolErrorBg\", text);\n\t\t}\n\t\treturn (text: string) => theme.bg(\"toolSuccessBg\", text);\n\t}\n\tif (settledError) {\n\t\treturn (text: string) => theme.bg(\"toolErrorBg\", text);\n\t}\n\treturn (text: string) => theme.bg(\"toolPendingBg\", text);\n}\n\nfunction buildEditCallComponent(\n\tcomponent: EditCallRenderComponent,\n\targs: RenderableEditArgs | undefined,\n\ttheme: Theme,\n\tcwd: string,\n\tdotState: ToolStatusDotState,\n\t// lunr: compact-by-default — finished, successful, non-expanded calls render\n\t// header-only; the diff preview stays while streaming and when expanded.\n\tcompact = false,\n): EditCallRenderComponent {\n\tcomponent.setBgFn(getEditHeaderBg(component.preview, component.settledError, theme));\n\tcomponent.clear();\n\tcomponent.addChild(new Text(`${toolStatusDot(dotState, theme)} ${formatEditCall(args, theme, cwd)}`, 0, 0));\n\n\tif (compact || !component.preview) {\n\t\treturn component;\n\t}\n\n\tconst body =\n\t\t\"error\" in component.preview ? theme.fg(\"error\", component.preview.error) : renderDiff(component.preview.diff);\n\tcomponent.addChild(new Spacer(1));\n\tcomponent.addChild(new Text(body, 0, 0));\n\treturn component;\n}\n\nfunction setEditPreview(\n\tcomponent: EditCallRenderComponent,\n\tpreview: EditPreview,\n\targsKey: string | undefined,\n): boolean {\n\tconst current = component.preview;\n\tconst changed =\n\t\tcurrent === undefined ||\n\t\t(\"error\" in current && \"error\" in preview\n\t\t\t? current.error !== preview.error\n\t\t\t: \"error\" in current !== \"error\" in preview) ||\n\t\t(!(\"error\" in current) &&\n\t\t\t!(\"error\" in preview) &&\n\t\t\t(current.diff !== preview.diff || current.firstChangedLine !== preview.firstChangedLine));\n\tcomponent.preview = preview;\n\tcomponent.previewArgsKey = argsKey;\n\tcomponent.previewPending = false;\n\treturn changed;\n}\n\nexport function createEditToolDefinition(\n\tcwd: string,\n\toptions?: EditToolOptions,\n): ToolDefinition<typeof editSchema, EditToolDetails | undefined, EditRenderState> {\n\tconst ops = options?.operations ?? defaultEditOperations;\n\treturn {\n\t\tname: \"edit\",\n\t\tlabel: \"edit\",\n\t\tdescription:\n\t\t\t\"Edit a single file using exact text replacement. Every edits[].oldText must match a unique, non-overlapping region of the original file. If two changes affect the same block or nearby lines, merge them into one edit instead of emitting overlapping edits. Do not include large unchanged regions just to connect distant changes.\",\n\t\tpromptSnippet:\n\t\t\t\"Make precise file edits with exact text replacement, including multiple disjoint edits in one call\",\n\t\tpromptGuidelines: [\n\t\t\t\"Use edit for precise changes (edits[].oldText must match exactly)\",\n\t\t\t\"When changing multiple separate locations in one file, use one edit call with multiple entries in edits[] instead of multiple edit calls\",\n\t\t\t\"Each edits[].oldText is matched against the original file, not after earlier edits are applied. Do not emit overlapping or nested edits. Merge nearby changes into one edit.\",\n\t\t\t\"Keep edits[].oldText as small as possible while still being unique in the file. Do not pad with large unchanged regions.\",\n\t\t],\n\t\tparameters: editSchema,\n\t\trenderShell: \"self\",\n\t\tprepareArguments: prepareEditArguments,\n\t\tasync execute(_toolCallId, input: EditToolInput, signal?: AbortSignal, _onUpdate?, _ctx?) {\n\t\t\tconst { path, edits } = validateEditInput(input);\n\t\t\tconst absolutePath = resolveToCwd(path, cwd);\n\n\t\t\treturn withFileMutationQueue(absolutePath, async () => {\n\t\t\t\t// Do not reject from an abort event listener here: that would release the\n\t\t\t\t// mutation queue while an in-flight filesystem operation may still finish.\n\t\t\t\t// Checking signal.aborted after each await observes the same aborts while\n\t\t\t\t// keeping the queue locked until the current operation has settled.\n\t\t\t\tconst throwIfAborted = (): void => {\n\t\t\t\t\tif (signal?.aborted) throw new Error(\"Operation aborted\");\n\t\t\t\t};\n\n\t\t\t\tthrowIfAborted();\n\n\t\t\t\t// Check if file exists.\n\t\t\t\ttry {\n\t\t\t\t\tawait ops.access(absolutePath);\n\t\t\t\t} catch (error: unknown) {\n\t\t\t\t\tthrowIfAborted();\n\t\t\t\t\tconst errorMessage =\n\t\t\t\t\t\terror instanceof Error && \"code\" in error ? `Error code: ${error.code}` : String(error);\n\t\t\t\t\tthrow new Error(`Could not edit file: ${path}. ${errorMessage}.`);\n\t\t\t\t}\n\t\t\t\tthrowIfAborted();\n\n\t\t\t\t// Read the file.\n\t\t\t\tconst buffer = await ops.readFile(absolutePath);\n\t\t\t\tconst rawContent = buffer.toString(\"utf-8\");\n\t\t\t\tthrowIfAborted();\n\n\t\t\t\t// Strip BOM before matching. The model will not include an invisible BOM in oldText.\n\t\t\t\tconst { bom, text: content } = stripBom(rawContent);\n\t\t\t\tconst originalEnding = detectLineEnding(content);\n\t\t\t\tconst normalizedContent = normalizeToLF(content);\n\t\t\t\tconst { baseContent, newContent } = applyEditsToNormalizedContent(normalizedContent, edits, path);\n\t\t\t\tthrowIfAborted();\n\n\t\t\t\tconst finalContent = bom + restoreLineEndings(newContent, originalEnding);\n\t\t\t\tawait ops.writeFile(absolutePath, finalContent);\n\t\t\t\tthrowIfAborted();\n\n\t\t\t\tconst diffResult = generateDiffString(baseContent, newContent);\n\t\t\t\tconst patch = generateUnifiedPatch(path, baseContent, newContent);\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttype: \"text\",\n\t\t\t\t\t\t\ttext: `Successfully replaced ${edits.length} block(s) in ${path}.`,\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t\tdetails: { diff: diffResult.diff, patch, firstChangedLine: diffResult.firstChangedLine },\n\t\t\t\t};\n\t\t\t});\n\t\t},\n\t\trenderCall(args, theme, context) {\n\t\t\tconst component = getEditCallRenderComponent(context.state, context.lastComponent);\n\t\t\tconst previewInput = getRenderablePreviewInput(args as RenderableEditArgs | undefined);\n\t\t\tconst argsKey = previewInput\n\t\t\t\t? JSON.stringify({ path: previewInput.path, edits: previewInput.edits })\n\t\t\t\t: undefined;\n\n\t\t\tif (component.previewArgsKey !== argsKey) {\n\t\t\t\tcomponent.preview = undefined;\n\t\t\t\tcomponent.previewArgsKey = argsKey;\n\t\t\t\tcomponent.previewPending = false;\n\t\t\t\tcomponent.settledError = false;\n\t\t\t}\n\n\t\t\tif (context.argsComplete && previewInput && !component.preview && !component.previewPending) {\n\t\t\t\tcomponent.previewPending = true;\n\t\t\t\tconst requestKey = argsKey;\n\t\t\t\tvoid computeEditsDiff(previewInput.path, previewInput.edits, context.cwd).then((preview) => {\n\t\t\t\t\tif (component.previewArgsKey === requestKey) {\n\t\t\t\t\t\tsetEditPreview(component, preview, requestKey);\n\t\t\t\t\t\tcontext.invalidate();\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\n\t\t\treturn buildEditCallComponent(\n\t\t\t\tcomponent,\n\t\t\t\targs,\n\t\t\t\ttheme,\n\t\t\t\tcontext.cwd,\n\t\t\t\tcontext.isPartial ? \"pending\" : context.isError ? \"error\" : \"success\",\n\t\t\t\t// lunr: compact-by-default\n\t\t\t\t!context.isPartial && !context.expanded && !context.isError,\n\t\t\t);\n\t\t},\n\t\trenderResult(result, _options, theme, context) {\n\t\t\tconst callComponent = context.state.callComponent;\n\t\t\tconst previewInput = getRenderablePreviewInput(context.args as RenderableEditArgs | undefined);\n\t\t\tconst argsKey = previewInput\n\t\t\t\t? JSON.stringify({ path: previewInput.path, edits: previewInput.edits })\n\t\t\t\t: undefined;\n\t\t\tconst typedResult = result as EditToolResultLike;\n\t\t\tconst resultDiff = !context.isError ? typedResult.details?.diff : undefined;\n\t\t\t// lunr: compact-by-default — header-only call, no result diff body.\n\t\t\tconst compact = !_options.isPartial && !_options.expanded && !context.isError;\n\t\t\tlet changed = false;\n\t\t\tif (callComponent) {\n\t\t\t\tif (typeof resultDiff === \"string\") {\n\t\t\t\t\tchanged =\n\t\t\t\t\t\tsetEditPreview(\n\t\t\t\t\t\t\tcallComponent,\n\t\t\t\t\t\t\t{ diff: resultDiff, firstChangedLine: typedResult.details?.firstChangedLine },\n\t\t\t\t\t\t\targsKey,\n\t\t\t\t\t\t) || changed;\n\t\t\t\t}\n\t\t\t\tif (callComponent.settledError !== context.isError) {\n\t\t\t\t\tcallComponent.settledError = context.isError;\n\t\t\t\t\tchanged = true;\n\t\t\t\t}\n\t\t\t\tif (changed || compact) {\n\t\t\t\t\tbuildEditCallComponent(\n\t\t\t\t\t\tcallComponent,\n\t\t\t\t\t\tcontext.args as RenderableEditArgs | undefined,\n\t\t\t\t\t\ttheme,\n\t\t\t\t\t\tcontext.cwd,\n\t\t\t\t\t\tcontext.isPartial ? \"pending\" : context.isError ? \"error\" : \"success\",\n\t\t\t\t\t\tcompact,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst output = compact\n\t\t\t\t? undefined\n\t\t\t\t: formatEditResult(context.args, callComponent?.preview, typedResult, theme, context.isError);\n\t\t\tconst component = (context.lastComponent as Container | undefined) ?? new Container();\n\t\t\tcomponent.clear();\n\t\t\tif (!output) {\n\t\t\t\treturn component;\n\t\t\t}\n\t\t\tcomponent.addChild(new Spacer(1));\n\t\t\tcomponent.addChild(new Text(output, 1, 0));\n\t\t\treturn component;\n\t\t},\n\t};\n}\n\nexport function createEditTool(cwd: string, options?: EditToolOptions): AgentTool<typeof editSchema> {\n\treturn wrapToolDefinition(createEditToolDefinition(cwd, options));\n}\n"]}
@@ -1,4 +1,4 @@
1
- import { Box, Container, Spacer, Text } from "@earendil-works/pi-tui";
1
+ import { Box, Container, Spacer, Text } from "@ashx-j/lunr-tui";
2
2
  import { constants } from "fs";
3
3
  import { access as fsAccess, readFile as fsReadFile, writeFile as fsWriteFile } from "fs/promises";
4
4
  import { Type } from "typebox";