@code-yeongyu/senpi 2026.8.28 → 2026.8.30-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 (380) hide show
  1. package/CHANGELOG.md +196 -0
  2. package/dist/cli/args.d.ts +2 -0
  3. package/dist/cli/args.d.ts.map +1 -1
  4. package/dist/cli/args.js +4 -0
  5. package/dist/cli/args.js.map +1 -1
  6. package/dist/core/agent-session-services.d.ts.map +1 -1
  7. package/dist/core/agent-session-services.js +2 -0
  8. package/dist/core/agent-session-services.js.map +1 -1
  9. package/dist/core/agent-session.d.ts +50 -1
  10. package/dist/core/agent-session.d.ts.map +1 -1
  11. package/dist/core/agent-session.js +330 -29
  12. package/dist/core/agent-session.js.map +1 -1
  13. package/dist/core/auth-storage.d.ts +1 -0
  14. package/dist/core/auth-storage.d.ts.map +1 -1
  15. package/dist/core/auth-storage.js +3 -0
  16. package/dist/core/auth-storage.js.map +1 -1
  17. package/dist/core/bash-executor.d.ts.map +1 -1
  18. package/dist/core/bash-executor.js +155 -37
  19. package/dist/core/bash-executor.js.map +1 -1
  20. package/dist/core/compaction/compaction-execution.d.ts +14 -0
  21. package/dist/core/compaction/compaction-execution.d.ts.map +1 -0
  22. package/dist/core/compaction/compaction-execution.js +121 -0
  23. package/dist/core/compaction/compaction-execution.js.map +1 -0
  24. package/dist/core/compaction/compaction-settings.d.ts +17 -0
  25. package/dist/core/compaction/compaction-settings.d.ts.map +1 -0
  26. package/dist/core/compaction/compaction-settings.js +17 -0
  27. package/dist/core/compaction/compaction-settings.js.map +1 -0
  28. package/dist/core/compaction/compaction.d.ts +13 -26
  29. package/dist/core/compaction/compaction.d.ts.map +1 -1
  30. package/dist/core/compaction/compaction.js +7 -136
  31. package/dist/core/compaction/compaction.js.map +1 -1
  32. package/dist/core/compaction/ideal-compaction-settings.d.ts +9 -0
  33. package/dist/core/compaction/ideal-compaction-settings.d.ts.map +1 -0
  34. package/dist/core/compaction/ideal-compaction-settings.js +7 -0
  35. package/dist/core/compaction/ideal-compaction-settings.js.map +1 -0
  36. package/dist/core/compaction-settings-access.d.ts +19 -0
  37. package/dist/core/compaction-settings-access.d.ts.map +1 -0
  38. package/dist/core/compaction-settings-access.js +10 -0
  39. package/dist/core/compaction-settings-access.js.map +1 -0
  40. package/dist/core/compaction-settings-resolver.d.ts +22 -0
  41. package/dist/core/compaction-settings-resolver.d.ts.map +1 -0
  42. package/dist/core/compaction-settings-resolver.js +46 -0
  43. package/dist/core/compaction-settings-resolver.js.map +1 -0
  44. package/dist/core/credential-accounts.d.ts.map +1 -1
  45. package/dist/core/credential-accounts.js +45 -21
  46. package/dist/core/credential-accounts.js.map +1 -1
  47. package/dist/core/credential-pool/classify.d.ts +6 -1
  48. package/dist/core/credential-pool/classify.d.ts.map +1 -1
  49. package/dist/core/credential-pool/classify.js +22 -5
  50. package/dist/core/credential-pool/classify.js.map +1 -1
  51. package/dist/core/credential-pool/env-slots.d.ts.map +1 -1
  52. package/dist/core/credential-pool/env-slots.js +2 -0
  53. package/dist/core/credential-pool/env-slots.js.map +1 -1
  54. package/dist/core/credential-pool/failover.d.ts +8 -0
  55. package/dist/core/credential-pool/failover.d.ts.map +1 -1
  56. package/dist/core/credential-pool/failover.js +24 -6
  57. package/dist/core/credential-pool/failover.js.map +1 -1
  58. package/dist/core/credential-pool/rotation-stream.d.ts +13 -2
  59. package/dist/core/credential-pool/rotation-stream.d.ts.map +1 -1
  60. package/dist/core/credential-pool/rotation-stream.js +97 -10
  61. package/dist/core/credential-pool/rotation-stream.js.map +1 -1
  62. package/dist/core/extensions/builtin/compaction/context-pipeline.d.ts +17 -0
  63. package/dist/core/extensions/builtin/compaction/context-pipeline.d.ts.map +1 -0
  64. package/dist/core/extensions/builtin/compaction/context-pipeline.js +28 -0
  65. package/dist/core/extensions/builtin/compaction/context-pipeline.js.map +1 -0
  66. package/dist/core/extensions/builtin/compaction/deterministic-fallback.d.ts +8 -2
  67. package/dist/core/extensions/builtin/compaction/deterministic-fallback.d.ts.map +1 -1
  68. package/dist/core/extensions/builtin/compaction/deterministic-fallback.js +163 -48
  69. package/dist/core/extensions/builtin/compaction/deterministic-fallback.js.map +1 -1
  70. package/dist/core/extensions/builtin/compaction/emergency-prune.d.ts +17 -0
  71. package/dist/core/extensions/builtin/compaction/emergency-prune.d.ts.map +1 -0
  72. package/dist/core/extensions/builtin/compaction/emergency-prune.js +64 -0
  73. package/dist/core/extensions/builtin/compaction/emergency-prune.js.map +1 -0
  74. package/dist/core/extensions/builtin/compaction/extension-wiring.d.ts +27 -0
  75. package/dist/core/extensions/builtin/compaction/extension-wiring.d.ts.map +1 -0
  76. package/dist/core/extensions/builtin/compaction/extension-wiring.js +84 -0
  77. package/dist/core/extensions/builtin/compaction/extension-wiring.js.map +1 -0
  78. package/dist/core/extensions/builtin/compaction/idle.d.ts +1 -0
  79. package/dist/core/extensions/builtin/compaction/idle.d.ts.map +1 -1
  80. package/dist/core/extensions/builtin/compaction/idle.js +13 -2
  81. package/dist/core/extensions/builtin/compaction/idle.js.map +1 -1
  82. package/dist/core/extensions/builtin/compaction/index.d.ts +1 -1
  83. package/dist/core/extensions/builtin/compaction/index.d.ts.map +1 -1
  84. package/dist/core/extensions/builtin/compaction/index.js +121 -147
  85. package/dist/core/extensions/builtin/compaction/index.js.map +1 -1
  86. package/dist/core/extensions/builtin/compaction/log.d.ts +1 -1
  87. package/dist/core/extensions/builtin/compaction/log.d.ts.map +1 -1
  88. package/dist/core/extensions/builtin/compaction/log.js +2 -0
  89. package/dist/core/extensions/builtin/compaction/log.js.map +1 -1
  90. package/dist/core/extensions/builtin/compaction/model-selection.d.ts +14 -0
  91. package/dist/core/extensions/builtin/compaction/model-selection.d.ts.map +1 -0
  92. package/dist/core/extensions/builtin/compaction/model-selection.js +37 -0
  93. package/dist/core/extensions/builtin/compaction/model-selection.js.map +1 -0
  94. package/dist/core/extensions/builtin/compaction/openai-remote-dependencies.d.ts +9 -0
  95. package/dist/core/extensions/builtin/compaction/openai-remote-dependencies.d.ts.map +1 -0
  96. package/dist/core/extensions/builtin/compaction/openai-remote-dependencies.js +2 -0
  97. package/dist/core/extensions/builtin/compaction/openai-remote-dependencies.js.map +1 -0
  98. package/dist/core/extensions/builtin/compaction/openai-remote.d.ts +3 -6
  99. package/dist/core/extensions/builtin/compaction/openai-remote.d.ts.map +1 -1
  100. package/dist/core/extensions/builtin/compaction/openai-remote.js.map +1 -1
  101. package/dist/core/extensions/builtin/compaction/orchestration.d.ts +56 -0
  102. package/dist/core/extensions/builtin/compaction/orchestration.d.ts.map +1 -0
  103. package/dist/core/extensions/builtin/compaction/orchestration.js +136 -0
  104. package/dist/core/extensions/builtin/compaction/orchestration.js.map +1 -0
  105. package/dist/core/extensions/builtin/compaction/policy.d.ts +5 -2
  106. package/dist/core/extensions/builtin/compaction/policy.d.ts.map +1 -1
  107. package/dist/core/extensions/builtin/compaction/policy.js +43 -26
  108. package/dist/core/extensions/builtin/compaction/policy.js.map +1 -1
  109. package/dist/core/extensions/builtin/compaction/retained-message-safety.d.ts.map +1 -1
  110. package/dist/core/extensions/builtin/compaction/retained-message-safety.js +31 -8
  111. package/dist/core/extensions/builtin/compaction/retained-message-safety.js.map +1 -1
  112. package/dist/core/extensions/builtin/compaction/speculation-lead.d.ts +8 -0
  113. package/dist/core/extensions/builtin/compaction/speculation-lead.d.ts.map +1 -0
  114. package/dist/core/extensions/builtin/compaction/speculation-lead.js +17 -0
  115. package/dist/core/extensions/builtin/compaction/speculation-lead.js.map +1 -0
  116. package/dist/core/extensions/builtin/compaction/speculative-job.d.ts +22 -0
  117. package/dist/core/extensions/builtin/compaction/speculative-job.d.ts.map +1 -0
  118. package/dist/core/extensions/builtin/compaction/speculative-job.js +16 -0
  119. package/dist/core/extensions/builtin/compaction/speculative-job.js.map +1 -0
  120. package/dist/core/extensions/builtin/compaction/speculative-summary.d.ts +22 -0
  121. package/dist/core/extensions/builtin/compaction/speculative-summary.d.ts.map +1 -0
  122. package/dist/core/extensions/builtin/compaction/speculative-summary.js +131 -0
  123. package/dist/core/extensions/builtin/compaction/speculative-summary.js.map +1 -0
  124. package/dist/core/extensions/builtin/compaction/speculative.d.ts +8 -13
  125. package/dist/core/extensions/builtin/compaction/speculative.d.ts.map +1 -1
  126. package/dist/core/extensions/builtin/compaction/speculative.js +7 -196
  127. package/dist/core/extensions/builtin/compaction/speculative.js.map +1 -1
  128. package/dist/core/extensions/builtin/compaction/token-budget-reminder.d.ts +18 -0
  129. package/dist/core/extensions/builtin/compaction/token-budget-reminder.d.ts.map +1 -0
  130. package/dist/core/extensions/builtin/compaction/token-budget-reminder.js +18 -0
  131. package/dist/core/extensions/builtin/compaction/token-budget-reminder.js.map +1 -0
  132. package/dist/core/extensions/builtin/compaction/tool-admission.d.ts +36 -0
  133. package/dist/core/extensions/builtin/compaction/tool-admission.d.ts.map +1 -0
  134. package/dist/core/extensions/builtin/compaction/tool-admission.js +92 -0
  135. package/dist/core/extensions/builtin/compaction/tool-admission.js.map +1 -0
  136. package/dist/core/extensions/builtin/cursor-cli-oauth/stream.d.ts.map +1 -1
  137. package/dist/core/extensions/builtin/cursor-cli-oauth/stream.js +8 -28
  138. package/dist/core/extensions/builtin/cursor-cli-oauth/stream.js.map +1 -1
  139. package/dist/core/extensions/builtin/goal/index.d.ts.map +1 -1
  140. package/dist/core/extensions/builtin/goal/index.js +7 -0
  141. package/dist/core/extensions/builtin/goal/index.js.map +1 -1
  142. package/dist/core/extensions/builtin/permission-system/external-dir.d.ts.map +1 -1
  143. package/dist/core/extensions/builtin/permission-system/external-dir.js +15 -5
  144. package/dist/core/extensions/builtin/permission-system/external-dir.js.map +1 -1
  145. package/dist/core/extensions/builtin/permission-system/parsers.d.ts.map +1 -1
  146. package/dist/core/extensions/builtin/permission-system/parsers.js +16 -1
  147. package/dist/core/extensions/builtin/permission-system/parsers.js.map +1 -1
  148. package/dist/core/extensions/builtin/service-tier.d.ts.map +1 -1
  149. package/dist/core/extensions/builtin/service-tier.js +13 -0
  150. package/dist/core/extensions/builtin/service-tier.js.map +1 -1
  151. package/dist/core/extensions/builtin/terminal/extension.d.ts.map +1 -1
  152. package/dist/core/extensions/builtin/terminal/extension.js +4 -2
  153. package/dist/core/extensions/builtin/terminal/extension.js.map +1 -1
  154. package/dist/core/extensions/builtin/terminal/manager.d.ts +5 -0
  155. package/dist/core/extensions/builtin/terminal/manager.d.ts.map +1 -1
  156. package/dist/core/extensions/builtin/terminal/manager.js +31 -3
  157. package/dist/core/extensions/builtin/terminal/manager.js.map +1 -1
  158. package/dist/core/extensions/builtin/terminal/monitor-permission.d.ts +8 -0
  159. package/dist/core/extensions/builtin/terminal/monitor-permission.d.ts.map +1 -0
  160. package/dist/core/extensions/builtin/terminal/monitor-permission.js +16 -0
  161. package/dist/core/extensions/builtin/terminal/monitor-permission.js.map +1 -0
  162. package/dist/core/extensions/builtin/terminal/monitor-registry.d.ts +13 -0
  163. package/dist/core/extensions/builtin/terminal/monitor-registry.d.ts.map +1 -1
  164. package/dist/core/extensions/builtin/terminal/monitor-registry.js +403 -3
  165. package/dist/core/extensions/builtin/terminal/monitor-registry.js.map +1 -1
  166. package/dist/core/extensions/builtin/terminal/session-bundle.d.ts.map +1 -1
  167. package/dist/core/extensions/builtin/terminal/session-bundle.js +1 -0
  168. package/dist/core/extensions/builtin/terminal/session-bundle.js.map +1 -1
  169. package/dist/core/extensions/builtin/terminal/tools/kill-bash.d.ts.map +1 -1
  170. package/dist/core/extensions/builtin/terminal/tools/kill-bash.js +5 -2
  171. package/dist/core/extensions/builtin/terminal/tools/kill-bash.js.map +1 -1
  172. package/dist/core/extensions/builtin/terminal/tools/monitor.d.ts +4 -0
  173. package/dist/core/extensions/builtin/terminal/tools/monitor.d.ts.map +1 -1
  174. package/dist/core/extensions/builtin/terminal/tools/monitor.js +40 -2
  175. package/dist/core/extensions/builtin/terminal/tools/monitor.js.map +1 -1
  176. package/dist/core/model-config-schema.d.ts +4 -4
  177. package/dist/core/model-resolver.js +2 -2
  178. package/dist/core/model-resolver.js.map +1 -1
  179. package/dist/core/model-runtime.d.ts +2 -0
  180. package/dist/core/model-runtime.d.ts.map +1 -1
  181. package/dist/core/model-runtime.js +74 -37
  182. package/dist/core/model-runtime.js.map +1 -1
  183. package/dist/core/retry-fallback/chains.d.ts +23 -1
  184. package/dist/core/retry-fallback/chains.d.ts.map +1 -1
  185. package/dist/core/retry-fallback/chains.js +59 -3
  186. package/dist/core/retry-fallback/chains.js.map +1 -1
  187. package/dist/core/retry-fallback/controller.d.ts.map +1 -1
  188. package/dist/core/retry-fallback/controller.js +9 -2
  189. package/dist/core/retry-fallback/controller.js.map +1 -1
  190. package/dist/core/retry-fallback/settings.d.ts.map +1 -1
  191. package/dist/core/retry-fallback/settings.js +9 -0
  192. package/dist/core/retry-fallback/settings.js.map +1 -1
  193. package/dist/core/retry-fallback/validate.js +1 -1
  194. package/dist/core/retry-fallback/validate.js.map +1 -1
  195. package/dist/core/sdk.js +1 -1
  196. package/dist/core/sdk.js.map +1 -1
  197. package/dist/core/session-manager.d.ts +9 -0
  198. package/dist/core/session-manager.d.ts.map +1 -1
  199. package/dist/core/session-manager.js +40 -0
  200. package/dist/core/session-manager.js.map +1 -1
  201. package/dist/core/settings-manager.d.ts +15 -85
  202. package/dist/core/settings-manager.d.ts.map +1 -1
  203. package/dist/core/settings-manager.js +15 -17
  204. package/dist/core/settings-manager.js.map +1 -1
  205. package/dist/core/settings-public-types.d.ts +11 -0
  206. package/dist/core/settings-public-types.d.ts.map +1 -0
  207. package/dist/core/settings-public-types.js +2 -0
  208. package/dist/core/settings-public-types.js.map +1 -0
  209. package/dist/core/settings-shapes.d.ts +36 -0
  210. package/dist/core/settings-shapes.d.ts.map +1 -0
  211. package/dist/core/settings-shapes.js +2 -0
  212. package/dist/core/settings-shapes.js.map +1 -0
  213. package/dist/core/shared-host-policy.d.ts +6 -0
  214. package/dist/core/shared-host-policy.d.ts.map +1 -0
  215. package/dist/core/shared-host-policy.js +7 -0
  216. package/dist/core/shared-host-policy.js.map +1 -0
  217. package/dist/core/terminal-settings.d.ts +22 -0
  218. package/dist/core/terminal-settings.d.ts.map +1 -0
  219. package/dist/core/terminal-settings.js +2 -0
  220. package/dist/core/terminal-settings.js.map +1 -0
  221. package/dist/core/tools/bash.d.ts.map +1 -1
  222. package/dist/core/tools/bash.js +97 -15
  223. package/dist/core/tools/bash.js.map +1 -1
  224. package/dist/core/tools/index.d.ts +1 -0
  225. package/dist/core/tools/index.d.ts.map +1 -1
  226. package/dist/core/tools/index.js +8 -0
  227. package/dist/core/tools/index.js.map +1 -1
  228. package/dist/core/tools/output-accumulator.d.ts +1 -1
  229. package/dist/core/tools/output-accumulator.d.ts.map +1 -1
  230. package/dist/core/tools/output-accumulator.js +76 -34
  231. package/dist/core/tools/output-accumulator.js.map +1 -1
  232. package/dist/main.d.ts +7 -0
  233. package/dist/main.d.ts.map +1 -1
  234. package/dist/main.js +27 -6
  235. package/dist/main.js.map +1 -1
  236. package/dist/modes/interactive/components/favorite-models-selector.d.ts.map +1 -1
  237. package/dist/modes/interactive/components/favorite-models-selector.js +2 -2
  238. package/dist/modes/interactive/components/favorite-models-selector.js.map +1 -1
  239. package/dist/modes/interactive/components/footer.d.ts +7 -0
  240. package/dist/modes/interactive/components/footer.d.ts.map +1 -1
  241. package/dist/modes/interactive/components/footer.js +34 -8
  242. package/dist/modes/interactive/components/footer.js.map +1 -1
  243. package/dist/modes/interactive/grok/chrome.d.ts +2 -0
  244. package/dist/modes/interactive/grok/chrome.d.ts.map +1 -1
  245. package/dist/modes/interactive/grok/chrome.js.map +1 -1
  246. package/dist/modes/interactive/interactive-host-runtime.d.ts +121 -1
  247. package/dist/modes/interactive/interactive-host-runtime.d.ts.map +1 -1
  248. package/dist/modes/interactive/interactive-host-runtime.js +606 -45
  249. package/dist/modes/interactive/interactive-host-runtime.js.map +1 -1
  250. package/dist/modes/interactive/interactive-mode.d.ts +7 -0
  251. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  252. package/dist/modes/interactive/interactive-mode.js +390 -239
  253. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  254. package/dist/modes/rpc/connection-handler.d.ts +8 -1
  255. package/dist/modes/rpc/connection-handler.d.ts.map +1 -1
  256. package/dist/modes/rpc/connection-handler.js +268 -63
  257. package/dist/modes/rpc/connection-handler.js.map +1 -1
  258. package/dist/modes/rpc/host-ensure.d.ts +19 -0
  259. package/dist/modes/rpc/host-ensure.d.ts.map +1 -1
  260. package/dist/modes/rpc/host-ensure.js +79 -15
  261. package/dist/modes/rpc/host-ensure.js.map +1 -1
  262. package/dist/modes/rpc/host-lifecycle.d.ts +29 -0
  263. package/dist/modes/rpc/host-lifecycle.d.ts.map +1 -1
  264. package/dist/modes/rpc/host-lifecycle.js +96 -25
  265. package/dist/modes/rpc/host-lifecycle.js.map +1 -1
  266. package/dist/modes/rpc/host-watchdog.d.ts +2 -0
  267. package/dist/modes/rpc/host-watchdog.d.ts.map +1 -1
  268. package/dist/modes/rpc/host-watchdog.js +23 -12
  269. package/dist/modes/rpc/host-watchdog.js.map +1 -1
  270. package/dist/modes/rpc/multi-session-host.js +20 -8
  271. package/dist/modes/rpc/multi-session-host.js.map +1 -1
  272. package/dist/modes/rpc/rpc-client.d.ts +91 -16
  273. package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
  274. package/dist/modes/rpc/rpc-client.js +131 -37
  275. package/dist/modes/rpc/rpc-client.js.map +1 -1
  276. package/dist/modes/rpc/rpc-input-validation.d.ts +1 -0
  277. package/dist/modes/rpc/rpc-input-validation.d.ts.map +1 -1
  278. package/dist/modes/rpc/rpc-input-validation.js +66 -0
  279. package/dist/modes/rpc/rpc-input-validation.js.map +1 -1
  280. package/dist/modes/rpc/rpc-mode.d.ts +3 -1
  281. package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
  282. package/dist/modes/rpc/rpc-mode.js +3 -1
  283. package/dist/modes/rpc/rpc-mode.js.map +1 -1
  284. package/dist/modes/rpc/rpc-types.d.ts +248 -3
  285. package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
  286. package/dist/modes/rpc/rpc-types.js.map +1 -1
  287. package/dist/modes/rpc/session-binding.d.ts +1 -0
  288. package/dist/modes/rpc/session-binding.d.ts.map +1 -1
  289. package/dist/modes/rpc/session-binding.js +21 -1
  290. package/dist/modes/rpc/session-binding.js.map +1 -1
  291. package/dist/modes/rpc/session-command-router.d.ts +22 -0
  292. package/dist/modes/rpc/session-command-router.d.ts.map +1 -1
  293. package/dist/modes/rpc/session-command-router.js +148 -16
  294. package/dist/modes/rpc/session-command-router.js.map +1 -1
  295. package/dist/modes/rpc/session-event-writer.d.ts +4 -0
  296. package/dist/modes/rpc/session-event-writer.d.ts.map +1 -1
  297. package/dist/modes/rpc/session-event-writer.js +58 -7
  298. package/dist/modes/rpc/session-event-writer.js.map +1 -1
  299. package/dist/modes/rpc/session-extension-ui-requests.d.ts +1 -0
  300. package/dist/modes/rpc/session-extension-ui-requests.d.ts.map +1 -1
  301. package/dist/modes/rpc/session-extension-ui-requests.js +5 -0
  302. package/dist/modes/rpc/session-extension-ui-requests.js.map +1 -1
  303. package/dist/modes/rpc/session-registry.d.ts +17 -2
  304. package/dist/modes/rpc/session-registry.d.ts.map +1 -1
  305. package/dist/modes/rpc/session-registry.js +67 -4
  306. package/dist/modes/rpc/session-registry.js.map +1 -1
  307. package/dist/modes/rpc/socket-event-fanout.d.ts +22 -0
  308. package/dist/modes/rpc/socket-event-fanout.d.ts.map +1 -0
  309. package/dist/modes/rpc/socket-event-fanout.js +84 -0
  310. package/dist/modes/rpc/socket-event-fanout.js.map +1 -0
  311. package/docs/rpc.md +55 -2
  312. package/docs/settings.md +34 -0
  313. package/docs/windows.md +2 -0
  314. package/node_modules/@code-yeongyu/senpi-codemode/CHANGELOG.md +74 -0
  315. package/node_modules/@code-yeongyu/senpi-codemode/package.json +4 -4
  316. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/worker-indirect-eval.js +139 -90
  317. package/node_modules/@code-yeongyu/senpi-codemode/src/prompt/eval-prompt.ts +4 -4
  318. package/node_modules/@earendil-works/pi-agent-core/dist/agent-loop.d.ts.map +1 -1
  319. package/node_modules/@earendil-works/pi-agent-core/dist/agent-loop.js +6 -3
  320. package/node_modules/@earendil-works/pi-agent-core/dist/agent-loop.js.map +1 -1
  321. package/node_modules/@earendil-works/pi-agent-core/dist/harness/env/nodejs.d.ts.map +1 -1
  322. package/node_modules/@earendil-works/pi-agent-core/dist/harness/env/nodejs.js +40 -20
  323. package/node_modules/@earendil-works/pi-agent-core/dist/harness/env/nodejs.js.map +1 -1
  324. package/node_modules/@earendil-works/pi-agent-core/dist/harness/types.d.ts +3 -3
  325. package/node_modules/@earendil-works/pi-agent-core/dist/harness/types.d.ts.map +1 -1
  326. package/node_modules/@earendil-works/pi-agent-core/dist/harness/types.js.map +1 -1
  327. package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/shell-output.d.ts +1 -1
  328. package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/shell-output.d.ts.map +1 -1
  329. package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/shell-output.js +28 -9
  330. package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/shell-output.js.map +1 -1
  331. package/node_modules/@earendil-works/pi-agent-core/package.json +3 -3
  332. package/node_modules/@earendil-works/pi-ai/dist/api/anthropic-messages.d.ts.map +1 -1
  333. package/node_modules/@earendil-works/pi-ai/dist/api/anthropic-messages.js +67 -38
  334. package/node_modules/@earendil-works/pi-ai/dist/api/anthropic-messages.js.map +1 -1
  335. package/node_modules/@earendil-works/pi-ai/dist/api/cursor-agent/measure.d.ts +20 -0
  336. package/node_modules/@earendil-works/pi-ai/dist/api/cursor-agent/measure.d.ts.map +1 -0
  337. package/node_modules/@earendil-works/pi-ai/dist/api/cursor-agent/measure.js +443 -0
  338. package/node_modules/@earendil-works/pi-ai/dist/api/cursor-agent/measure.js.map +1 -0
  339. package/node_modules/@earendil-works/pi-ai/dist/api/cursor-agent.d.ts +2 -0
  340. package/node_modules/@earendil-works/pi-ai/dist/api/cursor-agent.d.ts.map +1 -1
  341. package/node_modules/@earendil-works/pi-ai/dist/api/cursor-agent.js +2 -0
  342. package/node_modules/@earendil-works/pi-ai/dist/api/cursor-agent.js.map +1 -1
  343. package/node_modules/@earendil-works/pi-ai/dist/api/openai-completions.js +1 -1
  344. package/node_modules/@earendil-works/pi-ai/dist/api/openai-completions.js.map +1 -1
  345. package/node_modules/@earendil-works/pi-ai/dist/index.d.ts +1 -0
  346. package/node_modules/@earendil-works/pi-ai/dist/index.d.ts.map +1 -1
  347. package/node_modules/@earendil-works/pi-ai/dist/index.js +1 -0
  348. package/node_modules/@earendil-works/pi-ai/dist/index.js.map +1 -1
  349. package/node_modules/@earendil-works/pi-ai/dist/providers/data/.manifest.json +1 -1
  350. package/node_modules/@earendil-works/pi-ai/dist/providers/data/amazon-bedrock.json +1 -1
  351. package/node_modules/@earendil-works/pi-ai/dist/providers/data/baseten.json +1 -1
  352. package/node_modules/@earendil-works/pi-ai/dist/providers/data/cloudflare-ai-gateway.json +1 -1
  353. package/node_modules/@earendil-works/pi-ai/dist/providers/data/cloudflare-workers-ai.json +1 -1
  354. package/node_modules/@earendil-works/pi-ai/dist/providers/data/fireworks.json +1 -1
  355. package/node_modules/@earendil-works/pi-ai/dist/providers/data/huggingface.json +1 -1
  356. package/node_modules/@earendil-works/pi-ai/dist/providers/data/nvidia.json +1 -1
  357. package/node_modules/@earendil-works/pi-ai/dist/providers/data/opencode-go.json +1 -1
  358. package/node_modules/@earendil-works/pi-ai/dist/providers/data/opencode.json +1 -1
  359. package/node_modules/@earendil-works/pi-ai/dist/providers/data/openrouter.json +1 -1
  360. package/node_modules/@earendil-works/pi-ai/dist/providers/data/together.json +1 -1
  361. package/node_modules/@earendil-works/pi-ai/dist/providers/data/vercel-ai-gateway.json +1 -1
  362. package/node_modules/@earendil-works/pi-ai/dist/providers/data/zai-coding-cn.json +1 -1
  363. package/node_modules/@earendil-works/pi-ai/dist/providers/data/zai.json +1 -1
  364. package/node_modules/@earendil-works/pi-ai/package.json +2 -2
  365. package/node_modules/@earendil-works/pi-pty/package.json +1 -1
  366. package/node_modules/@earendil-works/pi-telemetry/package.json +1 -1
  367. package/node_modules/@earendil-works/pi-tui/dist/components/editor.d.ts +7 -0
  368. package/node_modules/@earendil-works/pi-tui/dist/components/editor.d.ts.map +1 -1
  369. package/node_modules/@earendil-works/pi-tui/dist/components/editor.js +5 -0
  370. package/node_modules/@earendil-works/pi-tui/dist/components/editor.js.map +1 -1
  371. package/node_modules/@earendil-works/pi-tui/dist/mux.d.ts +1 -1
  372. package/node_modules/@earendil-works/pi-tui/dist/mux.d.ts.map +1 -1
  373. package/node_modules/@earendil-works/pi-tui/dist/mux.js +2 -2
  374. package/node_modules/@earendil-works/pi-tui/dist/mux.js.map +1 -1
  375. package/node_modules/@earendil-works/pi-tui/dist/terminal.d.ts +1 -0
  376. package/node_modules/@earendil-works/pi-tui/dist/terminal.d.ts.map +1 -1
  377. package/node_modules/@earendil-works/pi-tui/dist/terminal.js +19 -0
  378. package/node_modules/@earendil-works/pi-tui/dist/terminal.js.map +1 -1
  379. package/node_modules/@earendil-works/pi-tui/package.json +1 -1
  380. package/package.json +7 -7
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/tools/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAON,cAAc,EACd,wBAAwB,EACxB,yBAAyB,GACzB,MAAM,WAAW,CAAC;AACnB,OAAO,EACN,cAAc,EACd,wBAAwB,GAKxB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EACN,cAAc,EACd,wBAAwB,GAKxB,MAAM,WAAW,CAAC;AACnB,OAAO,EACN,cAAc,EACd,wBAAwB,GAKxB,MAAM,WAAW,CAAC;AACnB,OAAO,EACN,YAAY,EACZ,sBAAsB,GAKtB,MAAM,SAAS,CAAC;AACjB,OAAO,EACN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UAAU,CAAC;QACpE,IAAI,EAAE,wBAAwB,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,CAAC;QAClD,KAAK,EAAE,yBAAyB,CAAC,GAAG,EAAE,OAAO,EAAE,KAAK,CAAC;QACrD,IAAI,EAAE,wBAAwB,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,CAAC;QAClD,IAAI,EAAE,wBAAwB,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,CAAC;QAClD,EAAE,EAAE,sBAAsB,CAAC,GAAG,EAAE,OAAO,EAAE,EAAE,CAAC;KAC5C,CAAC;AACH,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,GAAW,EAAE,OAAsB;IACpE,OAAO;QACN,cAAc,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,CAAC;QAClC,cAAc,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,CAAC;QAClC,cAAc,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,CAAC;QAClC,eAAe,CAAC,GAAG,EAAE,OAAO,EAAE,KAAK,CAAC;KACpC,CAAC;AACH,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,GAAW,EAAE,OAAsB;IACtE,OAAO;QACN,cAAc,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,CAAC;QAClC,cAAc,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,CAAC;QAClC,cAAc,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,CAAC;QAClC,YAAY,CAAC,GAAG,EAAE,OAAO,EAAE,EAAE,CAAC;KAC9B,CAAC;AACH,CAAC","sourcesContent":["export {\n\ttype BashOperations,\n\ttype BashSpawnContext,\n\ttype BashSpawnHook,\n\ttype BashToolDetails,\n\ttype BashToolInput,\n\ttype BashToolOptions,\n\tcreateBashTool,\n\tcreateBashToolDefinition,\n\tcreateLocalBashOperations,\n} from \"./bash.ts\";\nexport {\n\tcreateEditTool,\n\tcreateEditToolDefinition,\n\ttype EditOperations,\n\ttype EditToolDetails,\n\ttype EditToolInput,\n\ttype EditToolOptions,\n} from \"./edit.ts\";\nexport { withFileMutationQueue } from \"./file-mutation-queue.ts\";\nexport {\n\tcreateFindTool,\n\tcreateFindToolDefinition,\n\ttype FindOperations,\n\ttype FindToolDetails,\n\ttype FindToolInput,\n\ttype FindToolOptions,\n} from \"./find.ts\";\nexport {\n\tcreateGrepTool,\n\tcreateGrepToolDefinition,\n\ttype GrepOperations,\n\ttype GrepToolDetails,\n\ttype GrepToolInput,\n\ttype GrepToolOptions,\n} from \"./grep.ts\";\nexport {\n\tcreateLsTool,\n\tcreateLsToolDefinition,\n\ttype LsOperations,\n\ttype LsToolDetails,\n\ttype LsToolInput,\n\ttype LsToolOptions,\n} from \"./ls.ts\";\nexport {\n\tcreateLocalPowerShellOperations,\n\tcreatePowerShellTool,\n\tcreatePowerShellToolDefinition,\n\ttype PowerShellOperations,\n\ttype PowerShellSpawnContext,\n\ttype PowerShellSpawnHook,\n\ttype PowerShellToolDetails,\n\ttype PowerShellToolInput,\n\ttype PowerShellToolOptions,\n} from \"./powershell.ts\";\nexport {\n\tcreateReadTool,\n\tcreateReadToolDefinition,\n\ttype ReadOperations,\n\ttype ReadToolDetails,\n\ttype ReadToolInput,\n\ttype ReadToolOptions,\n} from \"./read.ts\";\nexport {\n\tDEFAULT_MAX_BYTES,\n\tDEFAULT_MAX_LINES,\n\tformatSize,\n\ttype TruncationOptions,\n\ttype TruncationResult,\n\ttruncateHead,\n\ttruncateLine,\n\ttruncateTail,\n} from \"./truncate.ts\";\nexport {\n\tcreateWriteTool,\n\tcreateWriteToolDefinition,\n\ttype WriteOperations,\n\ttype WriteToolInput,\n\ttype WriteToolOptions,\n} from \"./write.ts\";\n\nimport type { AgentTool } from \"@earendil-works/pi-agent-core\";\nimport type { ToolDefinition } from \"../extensions/types.ts\";\nimport { type BashToolOptions, createBashTool, createBashToolDefinition } from \"./bash.ts\";\nimport { createEditTool, createEditToolDefinition, type EditToolOptions } from \"./edit.ts\";\nimport { createFindTool, createFindToolDefinition, type FindToolOptions } from \"./find.ts\";\nimport { createGrepTool, createGrepToolDefinition, type GrepToolOptions } from \"./grep.ts\";\nimport { createLsTool, createLsToolDefinition, type LsToolOptions } from \"./ls.ts\";\nimport { createPowerShellToolDefinition, type PowerShellToolOptions } from \"./powershell.ts\";\nimport { createReadTool, createReadToolDefinition, type ReadToolOptions } from \"./read.ts\";\nimport { createWriteTool, createWriteToolDefinition, type WriteToolOptions } from \"./write.ts\";\n\nexport type Tool = AgentTool<any>;\nexport type ToolDef = ToolDefinition<any, any>;\nexport type ToolName = \"read\" | \"bash\" | \"powershell\" | \"edit\" | \"write\" | \"grep\" | \"find\" | \"ls\";\nexport const allToolNames: Set<ToolName> = new Set([\n\t\"read\",\n\t\"bash\",\n\t\"powershell\",\n\t\"edit\",\n\t\"write\",\n\t\"grep\",\n\t\"find\",\n\t\"ls\",\n]);\n\nexport interface ToolsOptions {\n\tread?: ReadToolOptions;\n\tbash?: BashToolOptions;\n\tpowershell?: PowerShellToolOptions;\n\twrite?: WriteToolOptions;\n\tedit?: EditToolOptions;\n\tgrep?: GrepToolOptions;\n\tfind?: FindToolOptions;\n\tls?: LsToolOptions;\n}\n\nexport function createAllToolDefinitions(cwd: string, options?: ToolsOptions): Record<ToolName, ToolDef> {\n\treturn {\n\t\tread: createReadToolDefinition(cwd, options?.read),\n\t\tbash: createBashToolDefinition(cwd, options?.bash),\n\t\tpowershell: createPowerShellToolDefinition(cwd, options?.powershell),\n\t\tedit: createEditToolDefinition(cwd, options?.edit),\n\t\twrite: createWriteToolDefinition(cwd, options?.write),\n\t\tgrep: createGrepToolDefinition(cwd, options?.grep),\n\t\tfind: createFindToolDefinition(cwd, options?.find),\n\t\tls: createLsToolDefinition(cwd, options?.ls),\n\t};\n}\n\nexport function createCodingTools(cwd: string, options?: ToolsOptions): Tool[] {\n\treturn [\n\t\tcreateReadTool(cwd, options?.read),\n\t\tcreateBashTool(cwd, options?.bash),\n\t\tcreateEditTool(cwd, options?.edit),\n\t\tcreateWriteTool(cwd, options?.write),\n\t];\n}\n\nexport function createReadOnlyTools(cwd: string, options?: ToolsOptions): Tool[] {\n\treturn [\n\t\tcreateReadTool(cwd, options?.read),\n\t\tcreateGrepTool(cwd, options?.grep),\n\t\tcreateFindTool(cwd, options?.find),\n\t\tcreateLsTool(cwd, options?.ls),\n\t];\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/tools/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAON,cAAc,EACd,wBAAwB,EACxB,yBAAyB,GACzB,MAAM,WAAW,CAAC;AACnB,OAAO,EACN,cAAc,EACd,wBAAwB,GAKxB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EACN,cAAc,EACd,wBAAwB,GAKxB,MAAM,WAAW,CAAC;AACnB,OAAO,EACN,cAAc,EACd,wBAAwB,GAKxB,MAAM,WAAW,CAAC;AACnB,OAAO,EACN,YAAY,EACZ,sBAAsB,GAKtB,MAAM,SAAS,CAAC;AACjB,OAAO,EACN,+BAA+B,EAC/B,oBAAoB,EACpB,8BAA8B,GAO9B,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACN,cAAc,EACd,wBAAwB,GAKxB,MAAM,WAAW,CAAC;AACnB,OAAO,EACN,iBAAiB,EACjB,iBAAiB,EACjB,UAAU,EAGV,YAAY,EACZ,YAAY,EACZ,YAAY,GACZ,MAAM,eAAe,CAAC;AACvB,OAAO,EACN,eAAe,EACf,yBAAyB,GAIzB,MAAM,YAAY,CAAC;AAIpB,OAAO,EAAwB,cAAc,EAAE,wBAAwB,EAAE,MAAM,WAAW,CAAC;AAC3F,OAAO,EAAE,cAAc,EAAE,wBAAwB,EAAwB,MAAM,WAAW,CAAC;AAC3F,OAAO,EAAE,cAAc,EAAE,wBAAwB,EAAwB,MAAM,WAAW,CAAC;AAC3F,OAAO,EAAE,cAAc,EAAE,wBAAwB,EAAw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AAC;KAC5C,CAAC;AACH,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,GAAW,EAAE,OAAsB;IACpE,OAAO;QACN,cAAc,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,CAAC;QAClC,cAAc,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,CAAC;QAClC,cAAc,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,CAAC;QAClC,eAAe,CAAC,GAAG,EAAE,OAAO,EAAE,KAAK,CAAC;KACpC,CAAC;AACH,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,GAAW,EAAE,OAAsB;IACtE,OAAO;QACN,cAAc,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,CAAC;QAClC,cAAc,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,CAAC;QAClC,cAAc,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,CAAC;QAClC,YAAY,CAAC,GAAG,EAAE,OAAO,EAAE,EAAE,CAAC;KAC9B,CAAC;AACH,CAAC","sourcesContent":["export {\n\ttype BashOperations,\n\ttype BashSpawnContext,\n\ttype BashSpawnHook,\n\ttype BashToolDetails,\n\ttype BashToolInput,\n\ttype BashToolOptions,\n\tcreateBashTool,\n\tcreateBashToolDefinition,\n\tcreateLocalBashOperations,\n} from \"./bash.ts\";\nexport {\n\tcreateEditTool,\n\tcreateEditToolDefinition,\n\ttype EditOperations,\n\ttype EditToolDetails,\n\ttype EditToolInput,\n\ttype EditToolOptions,\n} from \"./edit.ts\";\nexport { withFileMutationQueue } from \"./file-mutation-queue.ts\";\nexport {\n\tcreateFindTool,\n\tcreateFindToolDefinition,\n\ttype FindOperations,\n\ttype FindToolDetails,\n\ttype FindToolInput,\n\ttype FindToolOptions,\n} from \"./find.ts\";\nexport {\n\tcreateGrepTool,\n\tcreateGrepToolDefinition,\n\ttype GrepOperations,\n\ttype GrepToolDetails,\n\ttype GrepToolInput,\n\ttype GrepToolOptions,\n} from \"./grep.ts\";\nexport {\n\tcreateLsTool,\n\tcreateLsToolDefinition,\n\ttype LsOperations,\n\ttype LsToolDetails,\n\ttype LsToolInput,\n\ttype LsToolOptions,\n} from \"./ls.ts\";\nexport {\n\tcreateLocalPowerShellOperations,\n\tcreatePowerShellTool,\n\tcreatePowerShellToolDefinition,\n\ttype PowerShellOperations,\n\ttype PowerShellSpawnContext,\n\ttype PowerShellSpawnHook,\n\ttype PowerShellToolDetails,\n\ttype PowerShellToolInput,\n\ttype PowerShellToolOptions,\n} from \"./powershell.ts\";\nexport {\n\tcreateReadTool,\n\tcreateReadToolDefinition,\n\ttype ReadOperations,\n\ttype ReadToolDetails,\n\ttype ReadToolInput,\n\ttype ReadToolOptions,\n} from \"./read.ts\";\nexport {\n\tDEFAULT_MAX_BYTES,\n\tDEFAULT_MAX_LINES,\n\tformatSize,\n\ttype TruncationOptions,\n\ttype TruncationResult,\n\ttruncateHead,\n\ttruncateLine,\n\ttruncateTail,\n} from \"./truncate.ts\";\nexport {\n\tcreateWriteTool,\n\tcreateWriteToolDefinition,\n\ttype WriteOperations,\n\ttype WriteToolInput,\n\ttype WriteToolOptions,\n} from \"./write.ts\";\n\nimport type { AgentTool } from \"@earendil-works/pi-agent-core\";\nimport type { ToolDefinition } from \"../extensions/types.ts\";\nimport { type BashToolOptions, createBashTool, createBashToolDefinition } from \"./bash.ts\";\nimport { createEditTool, createEditToolDefinition, type EditToolOptions } from \"./edit.ts\";\nimport { createFindTool, createFindToolDefinition, type FindToolOptions } from \"./find.ts\";\nimport { createGrepTool, createGrepToolDefinition, type GrepToolOptions } from \"./grep.ts\";\nimport { createLsTool, createLsToolDefinition, type LsToolOptions } from \"./ls.ts\";\nimport { createPowerShellToolDefinition, type PowerShellToolOptions } from \"./powershell.ts\";\nimport { createReadTool, createReadToolDefinition, type ReadToolOptions } from \"./read.ts\";\nimport { createWriteTool, createWriteToolDefinition, type WriteToolOptions } from \"./write.ts\";\n\nexport type Tool = AgentTool<any>;\nexport type ToolDef = ToolDefinition<any, any>;\nexport type ToolName = \"read\" | \"bash\" | \"powershell\" | \"edit\" | \"write\" | \"grep\" | \"find\" | \"ls\";\nexport const allToolNames: Set<ToolName> = new Set([\n\t\"read\",\n\t\"bash\",\n\t\"powershell\",\n\t\"edit\",\n\t\"write\",\n\t\"grep\",\n\t\"find\",\n\t\"ls\",\n]);\n\n// TEMPORARY: tools listed here are built and stay resolvable through getRegisteredTool, but are\n// withheld from the MODEL-facing surface - they are dropped from the prompt-bearing tool\n// definitions and from the active tool names, so the model can neither see nor call them.\n// Programmatic callers that resolve a tool by name (notably the Cursor exec bridge, which drives\n// its own native read/bash/grep/ls frames regardless of what the request advertised) keep working.\n// `grep` is withheld while search routing is evaluated; restoring it is deleting the entry from\n// this set. Keep this set empty in the steady state.\nexport const temporarilyDisabledToolNames: ReadonlySet<string> = new Set<ToolName>([\"grep\"]);\n\nexport interface ToolsOptions {\n\tread?: ReadToolOptions;\n\tbash?: BashToolOptions;\n\tpowershell?: PowerShellToolOptions;\n\twrite?: WriteToolOptions;\n\tedit?: EditToolOptions;\n\tgrep?: GrepToolOptions;\n\tfind?: FindToolOptions;\n\tls?: LsToolOptions;\n}\n\nexport function createAllToolDefinitions(cwd: string, options?: ToolsOptions): Record<ToolName, ToolDef> {\n\treturn {\n\t\tread: createReadToolDefinition(cwd, options?.read),\n\t\tbash: createBashToolDefinition(cwd, options?.bash),\n\t\tpowershell: createPowerShellToolDefinition(cwd, options?.powershell),\n\t\tedit: createEditToolDefinition(cwd, options?.edit),\n\t\twrite: createWriteToolDefinition(cwd, options?.write),\n\t\tgrep: createGrepToolDefinition(cwd, options?.grep),\n\t\tfind: createFindToolDefinition(cwd, options?.find),\n\t\tls: createLsToolDefinition(cwd, options?.ls),\n\t};\n}\n\nexport function createCodingTools(cwd: string, options?: ToolsOptions): Tool[] {\n\treturn [\n\t\tcreateReadTool(cwd, options?.read),\n\t\tcreateBashTool(cwd, options?.bash),\n\t\tcreateEditTool(cwd, options?.edit),\n\t\tcreateWriteTool(cwd, options?.write),\n\t];\n}\n\nexport function createReadOnlyTools(cwd: string, options?: ToolsOptions): Tool[] {\n\treturn [\n\t\tcreateReadTool(cwd, options?.read),\n\t\tcreateGrepTool(cwd, options?.grep),\n\t\tcreateFindTool(cwd, options?.find),\n\t\tcreateLsTool(cwd, options?.ls),\n\t];\n}\n"]}
@@ -33,7 +33,6 @@ export declare class OutputAccumulator {
33
33
  private tempFilePath;
34
34
  private tempFileStream;
35
35
  private tempFileError;
36
- private tempFileErrorListener;
37
36
  constructor(options?: OutputAccumulatorOptions);
38
37
  append(data: Buffer): void;
39
38
  appendText(text: string): void;
@@ -47,6 +46,7 @@ export declare class OutputAccumulator {
47
46
  private getSnapshotText;
48
47
  private shouldUseTempFile;
49
48
  private ensureTempFile;
49
+ removeTempFile(): Promise<void>;
50
50
  private takeTempFileStream;
51
51
  }
52
52
  //# sourceMappingURL=output-accumulator.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"output-accumulator.d.ts","sourceRoot":"","sources":["../../../src/core/tools/output-accumulator.ts"],"names":[],"mappings":"AAKA,OAAO,EAAwC,KAAK,gBAAgB,EAAgB,MAAM,eAAe,CAAC;AAE1G,MAAM,WAAW,wBAAwB;IACxC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,cAAc,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,cAAc;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,gBAAgB,CAAC;IAC7B,cAAc,CAAC,EAAE,MAAM,CAAC;CACxB;AAWD;;;;;;GAMG;AACH,qBAAa,iBAAiB;IAC7B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAClC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAClC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAS;IACxC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAqB;IAC7C,OAAO,CAAC,QAAQ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, and terminal cleanup.
1
2
  import { randomBytes } from "node:crypto";
2
3
  import { createWriteStream } from "node:fs";
4
+ import { rm } from "node:fs/promises";
3
5
  import { tmpdir } from "node:os";
4
6
  import { join } from "node:path";
5
7
  import { TailWindow } from "./tail-window.js";
@@ -111,39 +113,72 @@ export class OutputAccumulator {
111
113
  return;
112
114
  }
113
115
  if (this.tempFileError) {
114
- if (this.tempFileErrorListener)
115
- stream.off("error", this.tempFileErrorListener);
116
- stream.destroy();
116
+ await new Promise((resolve) => {
117
+ if (stream.closed) {
118
+ resolve();
119
+ return;
120
+ }
121
+ stream.once("close", resolve);
122
+ stream.destroy();
123
+ });
124
+ try {
125
+ await this.removeTempFile();
126
+ }
127
+ catch (unlinkError) {
128
+ throw new AggregateError([this.tempFileError, unlinkError], "Output spill cleanup failed");
129
+ }
117
130
  throw this.tempFileError;
118
131
  }
119
- await new Promise((resolve, reject) => {
120
- let settled = false;
121
- const cleanup = () => {
122
- stream.off("error", onError);
123
- if (this.tempFileErrorListener)
124
- stream.off("error", this.tempFileErrorListener);
125
- stream.off("close", onClose);
126
- };
127
- const settle = (error) => {
128
- if (settled)
129
- return;
130
- settled = true;
131
- cleanup();
132
- if (error)
133
- reject(error);
134
- else
135
- resolve();
136
- };
137
- const onError = (error) => {
138
- this.tempFileError ??= error;
139
- };
140
- const onClose = () => {
141
- settle(this.tempFileError);
142
- };
143
- stream.on("error", onError);
144
- stream.once("close", onClose);
145
- stream.end();
146
- });
132
+ try {
133
+ await new Promise((resolve, reject) => {
134
+ let finished = false;
135
+ let closed = false;
136
+ let streamError;
137
+ const settle = () => {
138
+ if (!closed) {
139
+ return;
140
+ }
141
+ stream.off("finish", onFinish);
142
+ stream.off("error", onError);
143
+ stream.off("close", onClose);
144
+ if (streamError) {
145
+ reject(streamError);
146
+ }
147
+ else if (finished) {
148
+ resolve();
149
+ }
150
+ else {
151
+ reject(new Error("Output spill stream closed before finish"));
152
+ }
153
+ };
154
+ const onError = (error) => {
155
+ streamError ??= error;
156
+ };
157
+ const onFinish = () => {
158
+ finished = true;
159
+ };
160
+ const onClose = () => {
161
+ closed = true;
162
+ if (!finished && !stream.destroyed) {
163
+ stream.destroy();
164
+ }
165
+ settle();
166
+ };
167
+ stream.once("error", onError);
168
+ stream.once("finish", onFinish);
169
+ stream.once("close", onClose);
170
+ stream.end();
171
+ });
172
+ }
173
+ catch (error) {
174
+ try {
175
+ await this.removeTempFile();
176
+ }
177
+ catch (unlinkError) {
178
+ throw new AggregateError([error, unlinkError], "Output spill cleanup failed");
179
+ }
180
+ throw error;
181
+ }
147
182
  }
148
183
  getLastLineBytes() {
149
184
  return this.currentLineBytes;
@@ -189,15 +224,22 @@ export class OutputAccumulator {
189
224
  }
190
225
  this.tempFilePath = defaultTempFilePath(this.tempFilePrefix);
191
226
  this.tempFileStream = createWriteStream(this.tempFilePath);
192
- this.tempFileErrorListener = (error) => {
227
+ this.tempFileStream.on("error", (error) => {
193
228
  this.tempFileError ??= error;
194
- };
195
- this.tempFileStream.on("error", this.tempFileErrorListener);
229
+ });
196
230
  for (const chunk of this.rawChunks) {
197
231
  this.tempFileStream.write(chunk);
198
232
  }
199
233
  this.rawChunks = [];
200
234
  }
235
+ async removeTempFile() {
236
+ if (!this.tempFilePath) {
237
+ return;
238
+ }
239
+ const path = this.tempFilePath;
240
+ await rm(path, { force: true });
241
+ this.tempFilePath = undefined;
242
+ }
201
243
  takeTempFileStream() {
202
244
  const stream = this.tempFileStream;
203
245
  this.tempFileStream = undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"output-accumulator.js","sourceRoot":"","sources":["../../../src/core/tools/output-accumulator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,iBAAiB,EAAoB,MAAM,SAAS,CAAC;AAC9D,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAA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AC,aAAa,KAAK,KAAK,CAAC;QAC9B,CAAC,CAAC;QACF,IAAI,CAAC,cAAc,CAAC,EAAE,CAAC,OAAO,EAAE,IAAI,CAAC,qBAAqB,CAAC,CAAC;QAC5D,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;YACpC,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAClC,CAAC;QACD,IAAI,CAAC,SAAS,GAAG,EAAE,CAAC;IACrB,CAAC;IAEO,kBAAkB;QACzB,MAAM,MAAM,GAAG,IAAI,CAAC,cAAc,CAAC;QACnC,IAAI,CAAC,cAAc,GAAG,SAAS,CAAC;QAChC,OAAO,MAAM,CAAC;IACf,CAAC;CACD","sourcesContent":["import { randomBytes } from \"node:crypto\";\nimport { createWriteStream, type WriteStream } from \"node:fs\";\nimport { tmpdir } from \"node:os\";\nimport { join } from \"node:path\";\nimport { TailWindow } from \"./tail-window.ts\";\nimport { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, type TruncationResult, truncateTail } from \"./truncate.ts\";\n\nexport interface OutputAccumulatorOptions {\n\tmaxLines?: number;\n\tmaxBytes?: number;\n\ttempFilePrefix?: string;\n}\n\nexport interface OutputSnapshot {\n\tcontent: string;\n\ttruncation: TruncationResult;\n\tfullOutputPath?: string;\n}\n\nfunction defaultTempFilePath(prefix: string): string {\n\tconst id = randomBytes(8).toString(\"hex\");\n\treturn join(tmpdir(), `${prefix}-${id}.log`);\n}\n\nfunction byteLength(text: string): number {\n\treturn Buffer.byteLength(text, \"utf-8\");\n}\n\n/**\n * Incrementally tracks streaming output with bounded memory.\n *\n * Appends decode chunks with a streaming UTF-8 decoder, keeps only a decoded\n * tail for display snapshots, and opens a temp file when the full output needs\n * to be preserved.\n */\nexport class OutputAccumulator {\n\tprivate readonly maxLines: number;\n\tprivate readonly maxBytes: number;\n\tprivate readonly tempFilePrefix: string;\n\tprivate readonly decoder = new TextDecoder();\n\tprivate readonly tail: TailWindow;\n\n\tprivate rawChunks: Array<Buffer | string> = [];\n\tprivate totalRawBytes = 0;\n\tprivate totalDecodedBytes = 0;\n\tprivate completedLines = 0;\n\tprivate totalLines = 0;\n\tprivate currentLineBytes = 0;\n\tprivate hasOpenLine = false;\n\tprivate finished = false;\n\n\tprivate tempFilePath: string | undefined;\n\tprivate tempFileStream: WriteStream | undefined;\n\tprivate tempFileError: Error | undefined;\n\tprivate tempFileErrorListener: ((error: Error) => void) | undefined;\n\n\tconstructor(options: OutputAccumulatorOptions = {}) {\n\t\tthis.maxLines = options.maxLines ?? DEFAULT_MAX_LINES;\n\t\tthis.maxBytes = options.maxBytes ?? DEFAULT_MAX_BYTES;\n\t\tthis.tempFilePrefix = options.tempFilePrefix ?? \"pi-output\";\n\t\tthis.tail = new TailWindow(Math.max(this.maxBytes * 2, 1));\n\t}\n\n\tappend(data: Buffer): void {\n\t\tif (this.finished) {\n\t\t\tthrow new Error(\"Cannot append to a finished output accumulator\");\n\t\t}\n\n\t\tconst text = this.decoder.decode(data, { stream: true });\n\t\tthis.totalRawBytes += data.length;\n\t\tthis.appendDecodedText(text, byteLength(text));\n\n\t\tif (this.tempFileStream || this.shouldUseTempFile()) {\n\t\t\tthis.ensureTempFile();\n\t\t\tthis.tempFileStream?.write(data);\n\t\t} else if (data.length > 0) {\n\t\t\tthis.rawChunks.push(data);\n\t\t}\n\t}\n\n\tappendText(text: string): void {\n\t\tif (this.finished) {\n\t\t\tthrow new Error(\"Cannot append to a finished output accumulator\");\n\t\t}\n\t\tif (text.length === 0) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst bytes = byteLength(text);\n\t\tthis.totalRawBytes += bytes;\n\t\tthis.appendDecodedText(text, bytes);\n\n\t\tif (this.tempFileStream || this.shouldUseTempFile()) {\n\t\t\tthis.ensureTempFile();\n\t\t\tthis.tempFileStream?.write(text);\n\t\t} else {\n\t\t\tthis.rawChunks.push(text);\n\t\t}\n\t}\n\n\tfinish(): void {\n\t\tif (this.finished) {\n\t\t\treturn;\n\t\t}\n\t\tthis.finished = true;\n\t\tconst finalText = this.decoder.decode();\n\t\tthis.appendDecodedText(finalText, byteLength(finalText));\n\t\tif (this.shouldUseTempFile()) {\n\t\t\tthis.ensureTempFile();\n\t\t}\n\t}\n\n\tsnapshot(options: { persistIfTruncated?: boolean } = {}): OutputSnapshot {\n\t\tconst tailTruncation = truncateTail(this.getSnapshotText(), {\n\t\t\tmaxLines: this.maxLines,\n\t\t\tmaxBytes: this.maxBytes,\n\t\t});\n\t\tconst truncated = this.totalLines > this.maxLines || this.totalDecodedBytes > this.maxBytes;\n\t\tconst truncatedBy = truncated\n\t\t\t? (tailTruncation.truncatedBy ?? (this.totalDecodedBytes > this.maxBytes ? \"bytes\" : \"lines\"))\n\t\t\t: null;\n\t\tconst truncation: TruncationResult = {\n\t\t\t...tailTruncation,\n\t\t\ttruncated,\n\t\t\ttruncatedBy,\n\t\t\ttotalLines: this.totalLines,\n\t\t\ttotalBytes: this.totalDecodedBytes,\n\t\t\tmaxLines: this.maxLines,\n\t\t\tmaxBytes: this.maxBytes,\n\t\t};\n\n\t\tif (options.persistIfTruncated && truncation.truncated) {\n\t\t\tthis.ensureTempFile();\n\t\t}\n\n\t\treturn {\n\t\t\tcontent: truncation.content,\n\t\t\ttruncation,\n\t\t\tfullOutputPath: this.tempFilePath,\n\t\t};\n\t}\n\n\tasync closeTempFile(): Promise<void> {\n\t\tconst stream = this.takeTempFileStream();\n\t\tif (!stream) {\n\t\t\treturn;\n\t\t}\n\t\tif (this.tempFileError) {\n\t\t\tif (this.tempFileErrorListener) stream.off(\"error\", this.tempFileErrorListener);\n\t\t\tstream.destroy();\n\t\t\tthrow this.tempFileError;\n\t\t}\n\n\t\tawait new Promise<void>((resolve, reject) => {\n\t\t\tlet settled = false;\n\t\t\tconst cleanup = () => {\n\t\t\t\tstream.off(\"error\", onError);\n\t\t\t\tif (this.tempFileErrorListener) stream.off(\"error\", this.tempFileErrorListener);\n\t\t\t\tstream.off(\"close\", onClose);\n\t\t\t};\n\t\t\tconst settle = (error?: Error) => {\n\t\t\t\tif (settled) return;\n\t\t\t\tsettled = true;\n\t\t\t\tcleanup();\n\t\t\t\tif (error) reject(error);\n\t\t\t\telse resolve();\n\t\t\t};\n\t\t\tconst onError = (error: Error) => {\n\t\t\t\tthis.tempFileError ??= error;\n\t\t\t};\n\t\t\tconst onClose = () => {\n\t\t\t\tsettle(this.tempFileError);\n\t\t\t};\n\t\t\tstream.on(\"error\", onError);\n\t\t\tstream.once(\"close\", onClose);\n\t\t\tstream.end();\n\t\t});\n\t}\n\n\tgetLastLineBytes(): number {\n\t\treturn this.currentLineBytes;\n\t}\n\n\tprivate appendDecodedText(text: string, bytes: number): void {\n\t\tif (text.length === 0) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.totalDecodedBytes += bytes;\n\t\tthis.tail.append(text, bytes, !this.hasOpenLine);\n\n\t\tlet newlines = 0;\n\t\tlet lastNewline = -1;\n\t\tfor (let i = text.indexOf(\"\\n\"); i !== -1; i = text.indexOf(\"\\n\", i + 1)) {\n\t\t\tnewlines++;\n\t\t\tlastNewline = i;\n\t\t}\n\t\tif (newlines === 0) {\n\t\t\tthis.currentLineBytes += bytes;\n\t\t\tthis.hasOpenLine = true;\n\t\t} else {\n\t\t\tthis.completedLines += newlines;\n\t\t\tconst tail = text.slice(lastNewline + 1);\n\t\t\tthis.currentLineBytes = byteLength(tail);\n\t\t\tthis.hasOpenLine = tail.length > 0;\n\t\t}\n\t\tthis.totalLines = this.completedLines + (this.hasOpenLine ? 1 : 0);\n\t}\n\n\tprivate getSnapshotText(): string {\n\t\tconst text = this.tail.text();\n\t\tif (this.tail.startsAtLineBoundary) {\n\t\t\treturn text;\n\t\t}\n\n\t\tconst firstNewline = text.indexOf(\"\\n\");\n\t\treturn firstNewline === -1 ? text : text.slice(firstNewline + 1);\n\t}\n\n\tprivate shouldUseTempFile(): boolean {\n\t\treturn (\n\t\t\tthis.totalRawBytes > this.maxBytes || this.totalDecodedBytes > this.maxBytes || this.totalLines > this.maxLines\n\t\t);\n\t}\n\n\tprivate ensureTempFile(): void {\n\t\tif (this.tempFilePath) {\n\t\t\treturn;\n\t\t}\n\t\tthis.tempFilePath = defaultTempFilePath(this.tempFilePrefix);\n\t\tthis.tempFileStream = createWriteStream(this.tempFilePath);\n\t\tthis.tempFileErrorListener = (error) => {\n\t\t\tthis.tempFileError ??= error;\n\t\t};\n\t\tthis.tempFileStream.on(\"error\", this.tempFileErrorListener);\n\t\tfor (const chunk of this.rawChunks) {\n\t\t\tthis.tempFileStream.write(chunk);\n\t\t}\n\t\tthis.rawChunks = [];\n\t}\n\n\tprivate takeTempFileStream(): WriteStream | undefined {\n\t\tconst stream = this.tempFileStream;\n\t\tthis.tempFileStream = undefined;\n\t\treturn stream;\n\t}\n}\n"]}
1
+ {"version":3,"file":"output-accumulator.js","sourceRoot":"","sources":["../../../src/core/tools/output-accumulator.ts"],"names":[],"mappings":"AAAA,uHAAuH;AACvH,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,iBAAiB,EAAoB,MAAM,SAAS,CAAC;AAC9D,OAAO,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAyB,YAAY,EAAE,MAAM,eAAe,CAAC;AAc1G,SAAS,mBAAmB,CAAC,MAAc;IAC1C,MAAM,EAAE,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC1C,OAAO,IAAI,CAAC,MAAM,EAAE,EAAE,GAAG,MAAM,IAAI,EAAE,MAAM,CAAC,CAAC;AAC9C,CAAC;AAED,SAAS,UAAU,CAAC,IAAY;IA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ACnC,IAAI,CAAC,cAAc,GAAG,SAAS,CAAC;QAChC,OAAO,MAAM,CAAC;IACf,CAAC;CACD","sourcesContent":["// allow: SIZE_OK - one cohesive streaming-output state machine owns decoding, truncation, spill, and terminal cleanup.\nimport { randomBytes } from \"node:crypto\";\nimport { createWriteStream, type WriteStream } from \"node:fs\";\nimport { rm } from \"node:fs/promises\";\nimport { tmpdir } from \"node:os\";\nimport { join } from \"node:path\";\nimport { TailWindow } from \"./tail-window.ts\";\nimport { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, type TruncationResult, truncateTail } from \"./truncate.ts\";\n\nexport interface OutputAccumulatorOptions {\n\tmaxLines?: number;\n\tmaxBytes?: number;\n\ttempFilePrefix?: string;\n}\n\nexport interface OutputSnapshot {\n\tcontent: string;\n\ttruncation: TruncationResult;\n\tfullOutputPath?: string;\n}\n\nfunction defaultTempFilePath(prefix: string): string {\n\tconst id = randomBytes(8).toString(\"hex\");\n\treturn join(tmpdir(), `${prefix}-${id}.log`);\n}\n\nfunction byteLength(text: string): number {\n\treturn Buffer.byteLength(text, \"utf-8\");\n}\n\n/**\n * Incrementally tracks streaming output with bounded memory.\n *\n * Appends decode chunks with a streaming UTF-8 decoder, keeps only a decoded\n * tail for display snapshots, and opens a temp file when the full output needs\n * to be preserved.\n */\nexport class OutputAccumulator {\n\tprivate readonly maxLines: number;\n\tprivate readonly maxBytes: number;\n\tprivate readonly tempFilePrefix: string;\n\tprivate readonly decoder = new TextDecoder();\n\tprivate readonly tail: TailWindow;\n\n\tprivate rawChunks: Array<Buffer | string> = [];\n\tprivate totalRawBytes = 0;\n\tprivate totalDecodedBytes = 0;\n\tprivate completedLines = 0;\n\tprivate totalLines = 0;\n\tprivate currentLineBytes = 0;\n\tprivate hasOpenLine = false;\n\tprivate finished = false;\n\n\tprivate tempFilePath: string | undefined;\n\tprivate tempFileStream: WriteStream | undefined;\n\tprivate tempFileError: Error | undefined;\n\n\tconstructor(options: OutputAccumulatorOptions = {}) {\n\t\tthis.maxLines = options.maxLines ?? DEFAULT_MAX_LINES;\n\t\tthis.maxBytes = options.maxBytes ?? DEFAULT_MAX_BYTES;\n\t\tthis.tempFilePrefix = options.tempFilePrefix ?? \"pi-output\";\n\t\tthis.tail = new TailWindow(Math.max(this.maxBytes * 2, 1));\n\t}\n\n\tappend(data: Buffer): void {\n\t\tif (this.finished) {\n\t\t\tthrow new Error(\"Cannot append to a finished output accumulator\");\n\t\t}\n\n\t\tconst text = this.decoder.decode(data, { stream: true });\n\t\tthis.totalRawBytes += data.length;\n\t\tthis.appendDecodedText(text, byteLength(text));\n\n\t\tif (this.tempFileStream || this.shouldUseTempFile()) {\n\t\t\tthis.ensureTempFile();\n\t\t\tthis.tempFileStream?.write(data);\n\t\t} else if (data.length > 0) {\n\t\t\tthis.rawChunks.push(data);\n\t\t}\n\t}\n\n\tappendText(text: string): void {\n\t\tif (this.finished) {\n\t\t\tthrow new Error(\"Cannot append to a finished output accumulator\");\n\t\t}\n\t\tif (text.length === 0) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst bytes = byteLength(text);\n\t\tthis.totalRawBytes += bytes;\n\t\tthis.appendDecodedText(text, bytes);\n\n\t\tif (this.tempFileStream || this.shouldUseTempFile()) {\n\t\t\tthis.ensureTempFile();\n\t\t\tthis.tempFileStream?.write(text);\n\t\t} else {\n\t\t\tthis.rawChunks.push(text);\n\t\t}\n\t}\n\n\tfinish(): void {\n\t\tif (this.finished) {\n\t\t\treturn;\n\t\t}\n\t\tthis.finished = true;\n\t\tconst finalText = this.decoder.decode();\n\t\tthis.appendDecodedText(finalText, byteLength(finalText));\n\t\tif (this.shouldUseTempFile()) {\n\t\t\tthis.ensureTempFile();\n\t\t}\n\t}\n\n\tsnapshot(options: { persistIfTruncated?: boolean } = {}): OutputSnapshot {\n\t\tconst tailTruncation = truncateTail(this.getSnapshotText(), {\n\t\t\tmaxLines: this.maxLines,\n\t\t\tmaxBytes: this.maxBytes,\n\t\t});\n\t\tconst truncated = this.totalLines > this.maxLines || this.totalDecodedBytes > this.maxBytes;\n\t\tconst truncatedBy = truncated\n\t\t\t? (tailTruncation.truncatedBy ?? (this.totalDecodedBytes > this.maxBytes ? \"bytes\" : \"lines\"))\n\t\t\t: null;\n\t\tconst truncation: TruncationResult = {\n\t\t\t...tailTruncation,\n\t\t\ttruncated,\n\t\t\ttruncatedBy,\n\t\t\ttotalLines: this.totalLines,\n\t\t\ttotalBytes: this.totalDecodedBytes,\n\t\t\tmaxLines: this.maxLines,\n\t\t\tmaxBytes: this.maxBytes,\n\t\t};\n\n\t\tif (options.persistIfTruncated && truncation.truncated) {\n\t\t\tthis.ensureTempFile();\n\t\t}\n\n\t\treturn {\n\t\t\tcontent: truncation.content,\n\t\t\ttruncation,\n\t\t\tfullOutputPath: this.tempFilePath,\n\t\t};\n\t}\n\n\tasync closeTempFile(): Promise<void> {\n\t\tconst stream = this.takeTempFileStream();\n\t\tif (!stream) {\n\t\t\treturn;\n\t\t}\n\t\tif (this.tempFileError) {\n\t\t\tawait new Promise<void>((resolve) => {\n\t\t\t\tif (stream.closed) {\n\t\t\t\t\tresolve();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tstream.once(\"close\", resolve);\n\t\t\t\tstream.destroy();\n\t\t\t});\n\t\t\ttry {\n\t\t\t\tawait this.removeTempFile();\n\t\t\t} catch (unlinkError) {\n\t\t\t\tthrow new AggregateError([this.tempFileError, unlinkError], \"Output spill cleanup failed\");\n\t\t\t}\n\t\t\tthrow this.tempFileError;\n\t\t}\n\n\t\ttry {\n\t\t\tawait new Promise<void>((resolve, reject) => {\n\t\t\t\tlet finished = false;\n\t\t\t\tlet closed = false;\n\t\t\t\tlet streamError: Error | undefined;\n\t\t\t\tconst settle = () => {\n\t\t\t\t\tif (!closed) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tstream.off(\"finish\", onFinish);\n\t\t\t\t\tstream.off(\"error\", onError);\n\t\t\t\t\tstream.off(\"close\", onClose);\n\t\t\t\t\tif (streamError) {\n\t\t\t\t\t\treject(streamError);\n\t\t\t\t\t} else if (finished) {\n\t\t\t\t\t\tresolve();\n\t\t\t\t\t} else {\n\t\t\t\t\t\treject(new Error(\"Output spill stream closed before finish\"));\n\t\t\t\t\t}\n\t\t\t\t};\n\t\t\t\tconst onError = (error: Error) => {\n\t\t\t\t\tstreamError ??= error;\n\t\t\t\t};\n\t\t\t\tconst onFinish = () => {\n\t\t\t\t\tfinished = true;\n\t\t\t\t};\n\t\t\t\tconst onClose = () => {\n\t\t\t\t\tclosed = true;\n\t\t\t\t\tif (!finished && !stream.destroyed) {\n\t\t\t\t\t\tstream.destroy();\n\t\t\t\t\t}\n\t\t\t\t\tsettle();\n\t\t\t\t};\n\t\t\t\tstream.once(\"error\", onError);\n\t\t\t\tstream.once(\"finish\", onFinish);\n\t\t\t\tstream.once(\"close\", onClose);\n\t\t\t\tstream.end();\n\t\t\t});\n\t\t} catch (error) {\n\t\t\ttry {\n\t\t\t\tawait this.removeTempFile();\n\t\t\t} catch (unlinkError) {\n\t\t\t\tthrow new AggregateError([error, unlinkError], \"Output spill cleanup failed\");\n\t\t\t}\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\tgetLastLineBytes(): number {\n\t\treturn this.currentLineBytes;\n\t}\n\n\tprivate appendDecodedText(text: string, bytes: number): void {\n\t\tif (text.length === 0) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.totalDecodedBytes += bytes;\n\t\tthis.tail.append(text, bytes, !this.hasOpenLine);\n\n\t\tlet newlines = 0;\n\t\tlet lastNewline = -1;\n\t\tfor (let i = text.indexOf(\"\\n\"); i !== -1; i = text.indexOf(\"\\n\", i + 1)) {\n\t\t\tnewlines++;\n\t\t\tlastNewline = i;\n\t\t}\n\t\tif (newlines === 0) {\n\t\t\tthis.currentLineBytes += bytes;\n\t\t\tthis.hasOpenLine = true;\n\t\t} else {\n\t\t\tthis.completedLines += newlines;\n\t\t\tconst tail = text.slice(lastNewline + 1);\n\t\t\tthis.currentLineBytes = byteLength(tail);\n\t\t\tthis.hasOpenLine = tail.length > 0;\n\t\t}\n\t\tthis.totalLines = this.completedLines + (this.hasOpenLine ? 1 : 0);\n\t}\n\n\tprivate getSnapshotText(): string {\n\t\tconst text = this.tail.text();\n\t\tif (this.tail.startsAtLineBoundary) {\n\t\t\treturn text;\n\t\t}\n\n\t\tconst firstNewline = text.indexOf(\"\\n\");\n\t\treturn firstNewline === -1 ? text : text.slice(firstNewline + 1);\n\t}\n\n\tprivate shouldUseTempFile(): boolean {\n\t\treturn (\n\t\t\tthis.totalRawBytes > this.maxBytes || this.totalDecodedBytes > this.maxBytes || this.totalLines > this.maxLines\n\t\t);\n\t}\n\n\tprivate ensureTempFile(): void {\n\t\tif (this.tempFilePath) {\n\t\t\treturn;\n\t\t}\n\t\tthis.tempFilePath = defaultTempFilePath(this.tempFilePrefix);\n\t\tthis.tempFileStream = createWriteStream(this.tempFilePath);\n\t\tthis.tempFileStream.on(\"error\", (error) => {\n\t\t\tthis.tempFileError ??= error;\n\t\t});\n\t\tfor (const chunk of this.rawChunks) {\n\t\t\tthis.tempFileStream.write(chunk);\n\t\t}\n\t\tthis.rawChunks = [];\n\t}\n\n\tasync removeTempFile(): Promise<void> {\n\t\tif (!this.tempFilePath) {\n\t\t\treturn;\n\t\t}\n\t\tconst path = this.tempFilePath;\n\t\tawait rm(path, { force: true });\n\t\tthis.tempFilePath = undefined;\n\t}\n\n\tprivate takeTempFileStream(): WriteStream | undefined {\n\t\tconst stream = this.tempFileStream;\n\t\tthis.tempFileStream = undefined;\n\t\treturn stream;\n\t}\n}\n"]}
package/dist/main.d.ts CHANGED
@@ -14,6 +14,13 @@ export declare function collectExtensionLoadDiagnostics(errors: readonly {
14
14
  path: string;
15
15
  error: string;
16
16
  }[]): AgentSessionRuntimeDiagnostic[];
17
+ /**
18
+ * Interactive launches auto-title by default; every other app mode (RPC with or
19
+ * without `--multi-session`, print, json, app-server) opts in with
20
+ * `--auto-title-sessions`. Sessions resumed with existing context messages are
21
+ * never retitled, whatever the mode or flag.
22
+ */
23
+ export declare function resolveAutoTitleSessions(appMode: AppMode, parsed: Args, hasContextMessages: boolean): boolean;
17
24
  export declare function createSessionManager(parsed: Args, cwd: string, sessionDir: string | undefined, settingsManager: SettingsManager, appMode: AppMode): Promise<SessionManager>;
18
25
  export interface MainOptions {
19
26
  extensionFactories?: InlineExtension[];
@@ -1 +1 @@
1
- {"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":"AACA;;;;;GAKG;AAOH,OAAO,EAAE,KAAK,IAAI,EAAyD,MAAM,eAAe,CAAC;AAgCjG,OAAO,EACN,KAAK,6BAA6B,EAGlC,MAAM,kCAAkC,CAAC;AAM1C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAUlE,OAAO,EAAE,KAAK,OAAO,EAAyB,MAAM,yBAAyB,CAAC;AAQ9E,OAAO,EAAwB,cAAc,EAAE,MAAM,2BAA2B,CAAC;AACjF,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AA0D7D,wBAAgB,+BAA+B,CAC9C,MAAM,EAAE,SAAS;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,EAAE,GAChD,6BAA6B,EAAE,CAKjC;AA2RD,wBAAsB,oBAAoB,CACzC,MAAM,EAAE,IAAI,EACZ,GAAG,EAAE,MAAM,EACX,UAAU,EAAE,MAAM,GAAG,SAAS,EAC9B,eAAe,EAAE,eAAe,EAChC,OAAO,EAAE,OAAO,GACd,OAAO,CAAC,cAAc,CAAC,CAoGzB;AA0HD,MAAM,WAAW,WAAW;IAC3B,kBAAkB,CAAC,EAAE,eAAe,EAAE,CAAC;CACvC;AAED;;;GAGG;AACH,wBAAgB,yBAAyB,CAAC,eAAe,EAAE,eAAe,GAAG,IAAI,CAYhF;AAED,wBAAsB,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,EA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rusted } from "./core/project-trust.js";
38
38
  import { formatMissingSessionCwdPrompt, getMissingSessionCwdIssue, MissingSessionCwdError, } from "./core/session-cwd.js";
39
39
  import { assertValidSessionId, SessionManager } from "./core/session-manager.js";
40
40
  import { SettingsManager } from "./core/settings-manager.js";
41
+ import { shouldJoinSharedHost } from "./core/shared-host-policy.js";
41
42
  import { printTimings, resetTimings, time } from "./core/timings.js";
42
43
  import { hasTrustRequiringProjectResources, ProjectTrustStore } from "./core/trust-manager.js";
43
44
  import { builtInExtensions } from "./extensions/index.js";
@@ -46,7 +47,7 @@ import { runMigrations, showDeprecationWarnings } from "./migrations.js";
46
47
  import { createInteractiveHostRuntime } from "./modes/interactive/interactive-host-runtime.js";
47
48
  import { initTheme, stopThemeWatcher } from "./modes/interactive/theme/theme.js";
48
49
  import { runPrintMode } from "./modes/print-mode.js";
49
- import { parseSupervisorArgs, runHostSupervisor } from "./modes/rpc/host-lifecycle.js";
50
+ import { findInternalSupervisorArgs, parseSupervisorArgs, runHostSupervisor } from "./modes/rpc/host-lifecycle.js";
50
51
  import { runMultiSessionHost } from "./modes/rpc/multi-session-host.js";
51
52
  import { runRpcMode } from "./modes/rpc/rpc-mode.js";
52
53
  import { handleConfigCommand, handlePackageCommand } from "./package-manager-cli.js";
@@ -125,6 +126,15 @@ function toPrintOutputMode(appMode) {
125
126
  function toProjectTrustMode(appMode) {
126
127
  return appMode === "app-server" ? "print" : appMode;
127
128
  }
129
+ /**
130
+ * Interactive launches auto-title by default; every other app mode (RPC with or
131
+ * without `--multi-session`, print, json, app-server) opts in with
132
+ * `--auto-title-sessions`. Sessions resumed with existing context messages are
133
+ * never retitled, whatever the mode or flag.
134
+ */
135
+ export function resolveAutoTitleSessions(appMode, parsed, hasContextMessages) {
136
+ return (appMode === "interactive" || parsed.autoTitleSessions === true) && !hasContextMessages;
137
+ }
128
138
  function isPlainRuntimeMetadataCommand(parsed) {
129
139
  return (!parsed.print &&
130
140
  parsed.mode === undefined &&
@@ -530,10 +540,15 @@ export async function main(args, options) {
530
540
  return;
531
541
  }
532
542
  // Internal launch surface used by bundled/rebranded runtimes. It is deliberately
533
- // not accepted by parseArgs, so existing CLI modes remain unchanged.
534
- if (args[0] === "--internal-rpc-host-supervisor") {
535
- const launch = parseSupervisorArgs(args.slice(1));
543
+ // not accepted by parseArgs, so existing CLI modes remain unchanged. A rebranded
544
+ // wrapper may prepend its own `--extension <dir>` before forwarding argv, so the
545
+ // route is matched through the bounded scan rather than at argv[0] alone.
546
+ const supervisorArgs = findInternalSupervisorArgs(args);
547
+ if (supervisorArgs) {
548
+ const launch = parseSupervisorArgs(supervisorArgs);
536
549
  if (!launch) {
550
+ // Fail closed: an internal protocol fault must never fall through to the
551
+ // public parser and surface as a confusing "Unknown option" error.
537
552
  console.error("invalid internal RPC host supervisor arguments");
538
553
  process.exit(2);
539
554
  }
@@ -842,7 +857,7 @@ export async function main(args, options) {
842
857
  excludeTools: sessionOptions.excludeTools,
843
858
  noTools: sessionOptions.noTools,
844
859
  customTools: sessionOptions.customTools,
845
- autoTitleSessions: appMode === "interactive" && !sessionManager.hasContextMessages(),
860
+ autoTitleSessions: resolveAutoTitleSessions(appMode, parsed, sessionManager.hasContextMessages()),
846
861
  });
847
862
  const cliThinkingOverride = runtimeParsed.thinking !== undefined || cliThinkingFromModel;
848
863
  if (created.session.model && cliThinkingOverride) {
@@ -881,7 +896,13 @@ export async function main(args, options) {
881
896
  });
882
897
  time("createAgentSessionRuntime");
883
898
  let selectedRuntime = runtime;
884
- if (appMode === "interactive" && !isTruthyEnvFlag(envValue("DISABLE_SHARED_HOST"))) {
899
+ if (isTruthyEnvFlag(envValue("DISABLE_SHARED_HOST"))) {
900
+ console.error(chalk.yellow("DISABLE_SHARED_HOST is obsolete: the shared session host is now off by default. Enable the experimental.sharedHost setting (or set the brand-prefixed ENABLE_SHARED_HOST=1 env flag) to opt in."));
901
+ }
902
+ if (shouldJoinSharedHost(appMode, {
903
+ enableEnv: isTruthyEnvFlag(envValue("ENABLE_SHARED_HOST")),
904
+ settingEnabled: runtime.services.settingsManager.getExperimentalSharedHost(),
905
+ })) {
885
906
  const socket = envValue("RPC_SOCKET") ?? resolve(agentDir, "rpc", "rpc.sock");
886
907
  selectedRuntime = await createInteractiveHostRuntime(runtime, {
887
908
  socket,