@earendil-works/pi-coding-agent 0.85.0 → 0.86.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (544) hide show
  1. package/CHANGELOG.md +104 -0
  2. package/README.md +2 -3
  3. package/dist/bun/cli.d.ts +3 -1
  4. package/dist/bun/cli.d.ts.map +1 -1
  5. package/dist/bun/cli.js +3 -12
  6. package/dist/bun/cli.js.map +1 -1
  7. package/dist/bun/sandbox-env-setup.d.ts +2 -0
  8. package/dist/bun/sandbox-env-setup.d.ts.map +1 -0
  9. package/dist/bun/sandbox-env-setup.js +4 -0
  10. package/dist/bun/sandbox-env-setup.js.map +1 -0
  11. package/dist/bundle/chunks/anthropic-messages-MYU5ZMRF.js +6 -0
  12. package/dist/bundle/chunks/azure-openai-responses-HUSQ3GP2.js +2 -0
  13. package/dist/bundle/chunks/bedrock-converse-stream.js +47 -38
  14. package/dist/bundle/chunks/chunk-7IOYH2SY.js +2 -0
  15. package/dist/bundle/chunks/chunk-7YM6BE7Y.js +1561 -0
  16. package/dist/bundle/chunks/chunk-A3JYRWB6.js +2 -0
  17. package/dist/bundle/chunks/chunk-DTD7JQ7Y.js +42 -0
  18. package/dist/bundle/chunks/chunk-FUXEF6JQ.js +44 -0
  19. package/dist/bundle/chunks/{chunk-IDDQWTHI.js → chunk-RCZIEVGO.js} +10 -1
  20. package/dist/bundle/chunks/chunk-S7SZN6Z3.js +2 -0
  21. package/dist/bundle/chunks/chunk-WIUZI2CJ.js +11 -0
  22. package/dist/bundle/chunks/github-copilot.js +1 -1
  23. package/dist/bundle/chunks/google-generative-ai-IMS5EK2Y.js +2 -0
  24. package/dist/bundle/chunks/google-vertex-O4YJEQUW.js +2 -0
  25. package/dist/bundle/chunks/jiti-loader-C3NU2SDH.js +21 -0
  26. package/dist/bundle/chunks/jiti-static-loader-E6ANQD5T.js +2 -0
  27. package/dist/bundle/chunks/mistral-conversations-NOSQHBEY.js +5 -0
  28. package/dist/bundle/chunks/{node-EM5FIVUN.js → node-O3RIBJRH.js} +1 -1
  29. package/dist/bundle/chunks/openai-codex-responses-QDSOTBBO.js +10 -0
  30. package/dist/bundle/chunks/openai-completions-KQPOPEVM.js +7 -0
  31. package/dist/bundle/chunks/openai-responses-HWEUZ6WZ.js +2 -0
  32. package/dist/bundle/chunks/{pi-messages-EGZIFQGG.js → pi-messages-GFKBWJHZ.js} +1 -1
  33. package/dist/bundle/chunks/virtual-modules-XW5APVUE.js +2 -0
  34. package/dist/bundle/cli.js +1 -1
  35. package/dist/bundle/index.js +1 -1
  36. package/dist/bundle/rpc-entry.js +1 -1
  37. package/dist/cli/args.d.ts.map +1 -1
  38. package/dist/cli/args.js +0 -2
  39. package/dist/cli/args.js.map +1 -1
  40. package/dist/cli/session-picker.d.ts +1 -1
  41. package/dist/cli/session-picker.d.ts.map +1 -1
  42. package/dist/cli/session-picker.js.map +1 -1
  43. package/dist/cli/setup.d.ts +2 -0
  44. package/dist/cli/setup.d.ts.map +1 -0
  45. package/dist/cli/setup.js +12 -0
  46. package/dist/cli/setup.js.map +1 -0
  47. package/dist/cli.d.ts.map +1 -1
  48. package/dist/cli.js +3 -25
  49. package/dist/cli.js.map +1 -1
  50. package/dist/config.d.ts.map +1 -1
  51. package/dist/config.js +1 -1
  52. package/dist/config.js.map +1 -1
  53. package/dist/core/agent-session.d.ts +56 -6
  54. package/dist/core/agent-session.d.ts.map +1 -1
  55. package/dist/core/agent-session.js +293 -155
  56. package/dist/core/agent-session.js.map +1 -1
  57. package/dist/core/bug-report-upload.d.ts +12 -0
  58. package/dist/core/bug-report-upload.d.ts.map +1 -0
  59. package/dist/core/bug-report-upload.js +22 -0
  60. package/dist/core/bug-report-upload.js.map +1 -0
  61. package/dist/core/bug-report.d.ts +176 -0
  62. package/dist/core/bug-report.d.ts.map +1 -0
  63. package/dist/core/bug-report.js +292 -0
  64. package/dist/core/bug-report.js.map +1 -0
  65. package/dist/core/cache-stats.d.ts.map +1 -1
  66. package/dist/core/cache-stats.js +12 -1
  67. package/dist/core/cache-stats.js.map +1 -1
  68. package/dist/core/cache-warmer.d.ts +102 -0
  69. package/dist/core/cache-warmer.d.ts.map +1 -0
  70. package/dist/core/cache-warmer.js +342 -0
  71. package/dist/core/cache-warmer.js.map +1 -0
  72. package/dist/core/compaction/branch-summarization.d.ts.map +1 -1
  73. package/dist/core/compaction/branch-summarization.js +2 -2
  74. package/dist/core/compaction/branch-summarization.js.map +1 -1
  75. package/dist/core/compaction/compaction.d.ts +2 -2
  76. package/dist/core/compaction/compaction.d.ts.map +1 -1
  77. package/dist/core/compaction/compaction.js +11 -12
  78. package/dist/core/compaction/compaction.js.map +1 -1
  79. package/dist/core/crash-log.d.ts +22 -0
  80. package/dist/core/crash-log.d.ts.map +1 -0
  81. package/dist/core/crash-log.js +71 -0
  82. package/dist/core/crash-log.js.map +1 -0
  83. package/dist/core/experimental.d.ts +0 -4
  84. package/dist/core/experimental.d.ts.map +1 -1
  85. package/dist/core/experimental.js +0 -4
  86. package/dist/core/experimental.js.map +1 -1
  87. package/dist/core/extensions/index.d.ts +1 -1
  88. package/dist/core/extensions/index.d.ts.map +1 -1
  89. package/dist/core/extensions/index.js.map +1 -1
  90. package/dist/core/extensions/jiti-loader.d.ts +2 -0
  91. package/dist/core/extensions/jiti-loader.d.ts.map +1 -0
  92. package/dist/core/extensions/jiti-loader.js +4 -0
  93. package/dist/core/extensions/jiti-loader.js.map +1 -0
  94. package/dist/core/extensions/jiti-static-loader.d.ts +2 -0
  95. package/dist/core/extensions/jiti-static-loader.d.ts.map +1 -0
  96. package/dist/core/extensions/jiti-static-loader.js +4 -0
  97. package/dist/core/extensions/jiti-static-loader.js.map +1 -0
  98. package/dist/core/extensions/loader.d.ts.map +1 -1
  99. package/dist/core/extensions/loader.js +38 -51
  100. package/dist/core/extensions/loader.js.map +1 -1
  101. package/dist/core/extensions/runner.d.ts +10 -7
  102. package/dist/core/extensions/runner.d.ts.map +1 -1
  103. package/dist/core/extensions/runner.js +85 -67
  104. package/dist/core/extensions/runner.js.map +1 -1
  105. package/dist/core/extensions/types.d.ts +60 -50
  106. package/dist/core/extensions/types.d.ts.map +1 -1
  107. package/dist/core/extensions/types.js.map +1 -1
  108. package/dist/core/extensions/virtual-modules.d.ts +3 -0
  109. package/dist/core/extensions/virtual-modules.d.ts.map +1 -0
  110. package/dist/core/extensions/virtual-modules.js +38 -0
  111. package/dist/core/extensions/virtual-modules.js.map +1 -0
  112. package/dist/core/extensions/wrapper.d.ts.map +1 -1
  113. package/dist/core/extensions/wrapper.js +1 -20
  114. package/dist/core/extensions/wrapper.js.map +1 -1
  115. package/dist/core/index.d.ts +2 -1
  116. package/dist/core/index.d.ts.map +1 -1
  117. package/dist/core/index.js.map +1 -1
  118. package/dist/core/keybindings.d.ts +6 -1
  119. package/dist/core/keybindings.d.ts.map +1 -1
  120. package/dist/core/keybindings.js +5 -1
  121. package/dist/core/keybindings.js.map +1 -1
  122. package/dist/core/messages.d.ts.map +1 -1
  123. package/dist/core/messages.js +1 -0
  124. package/dist/core/messages.js.map +1 -1
  125. package/dist/core/model-config.d.ts +101 -20
  126. package/dist/core/model-config.d.ts.map +1 -1
  127. package/dist/core/model-config.js +25 -18
  128. package/dist/core/model-config.js.map +1 -1
  129. package/dist/core/model-registry.d.ts +5 -1
  130. package/dist/core/model-registry.d.ts.map +1 -1
  131. package/dist/core/model-registry.js +8 -0
  132. package/dist/core/model-registry.js.map +1 -1
  133. package/dist/core/model-resolver.d.ts.map +1 -1
  134. package/dist/core/model-resolver.js +1 -1
  135. package/dist/core/model-resolver.js.map +1 -1
  136. package/dist/core/model-runtime.d.ts.map +1 -1
  137. package/dist/core/model-runtime.js +5 -3
  138. package/dist/core/model-runtime.js.map +1 -1
  139. package/dist/core/provider-composer.d.ts +3 -2
  140. package/dist/core/provider-composer.d.ts.map +1 -1
  141. package/dist/core/provider-composer.js +2 -0
  142. package/dist/core/provider-composer.js.map +1 -1
  143. package/dist/core/radius.d.ts +3 -0
  144. package/dist/core/radius.d.ts.map +1 -1
  145. package/dist/core/radius.js +6 -0
  146. package/dist/core/radius.js.map +1 -1
  147. package/dist/core/sdk.d.ts.map +1 -1
  148. package/dist/core/sdk.js +60 -38
  149. package/dist/core/sdk.js.map +1 -1
  150. package/dist/core/session-export.d.ts +6 -2
  151. package/dist/core/session-export.d.ts.map +1 -1
  152. package/dist/core/session-export.js +14 -13
  153. package/dist/core/session-export.js.map +1 -1
  154. package/dist/core/session-manager.d.ts +29 -6
  155. package/dist/core/session-manager.d.ts.map +1 -1
  156. package/dist/core/session-manager.js +159 -96
  157. package/dist/core/session-manager.js.map +1 -1
  158. package/dist/core/settings-manager.d.ts +20 -4
  159. package/dist/core/settings-manager.d.ts.map +1 -1
  160. package/dist/core/settings-manager.js +43 -7
  161. package/dist/core/settings-manager.js.map +1 -1
  162. package/dist/core/slash-commands.d.ts.map +1 -1
  163. package/dist/core/slash-commands.js +1 -0
  164. package/dist/core/slash-commands.js.map +1 -1
  165. package/dist/core/system-prompt.d.ts +49 -6
  166. package/dist/core/system-prompt.d.ts.map +1 -1
  167. package/dist/core/system-prompt.js +121 -92
  168. package/dist/core/system-prompt.js.map +1 -1
  169. package/dist/core/tools/bash.d.ts +2 -1
  170. package/dist/core/tools/bash.d.ts.map +1 -1
  171. package/dist/core/tools/bash.js +10 -4
  172. package/dist/core/tools/bash.js.map +1 -1
  173. package/dist/core/tools/edit.d.ts.map +1 -1
  174. package/dist/core/tools/edit.js +1 -2
  175. package/dist/core/tools/edit.js.map +1 -1
  176. package/dist/core/tools/read.d.ts.map +1 -1
  177. package/dist/core/tools/read.js +1 -2
  178. package/dist/core/tools/read.js.map +1 -1
  179. package/dist/core/tools/renderers/bash.d.ts.map +1 -1
  180. package/dist/core/tools/renderers/bash.js +9 -1
  181. package/dist/core/tools/renderers/bash.js.map +1 -1
  182. package/dist/core/tools/write.d.ts.map +1 -1
  183. package/dist/core/tools/write.js +1 -2
  184. package/dist/core/tools/write.js.map +1 -1
  185. package/dist/core/usage-totals.d.ts +1 -1
  186. package/dist/core/usage-totals.d.ts.map +1 -1
  187. package/dist/core/usage-totals.js +5 -1
  188. package/dist/core/usage-totals.js.map +1 -1
  189. package/dist/extensions/llama/client.d.ts +2 -0
  190. package/dist/extensions/llama/client.d.ts.map +1 -1
  191. package/dist/extensions/llama/client.js +7 -3
  192. package/dist/extensions/llama/client.js.map +1 -1
  193. package/dist/extensions/llama/provider.d.ts.map +1 -1
  194. package/dist/extensions/llama/provider.js +20 -5
  195. package/dist/extensions/llama/provider.js.map +1 -1
  196. package/dist/index.d.ts +3 -2
  197. package/dist/index.d.ts.map +1 -1
  198. package/dist/index.js.map +1 -1
  199. package/dist/main.d.ts.map +1 -1
  200. package/dist/main.js +13 -131
  201. package/dist/main.js.map +1 -1
  202. package/dist/migrations.d.ts.map +1 -1
  203. package/dist/migrations.js +2 -2
  204. package/dist/migrations.js.map +1 -1
  205. package/dist/modes/interactive/bug-report.d.ts +14 -0
  206. package/dist/modes/interactive/bug-report.d.ts.map +1 -0
  207. package/dist/modes/interactive/bug-report.js +209 -0
  208. package/dist/modes/interactive/bug-report.js.map +1 -0
  209. package/dist/modes/interactive/chat-viewport.d.ts.map +1 -1
  210. package/dist/modes/interactive/chat-viewport.js +1 -1
  211. package/dist/modes/interactive/chat-viewport.js.map +1 -1
  212. package/dist/modes/interactive/components/branch-summary-message.d.ts.map +1 -1
  213. package/dist/modes/interactive/components/branch-summary-message.js +12 -5
  214. package/dist/modes/interactive/components/branch-summary-message.js.map +1 -1
  215. package/dist/modes/interactive/components/compaction-summary-message.d.ts.map +1 -1
  216. package/dist/modes/interactive/components/compaction-summary-message.js +12 -5
  217. package/dist/modes/interactive/components/compaction-summary-message.js.map +1 -1
  218. package/dist/modes/interactive/components/custom-editor.d.ts +3 -3
  219. package/dist/modes/interactive/components/custom-editor.d.ts.map +1 -1
  220. package/dist/modes/interactive/components/custom-editor.js.map +1 -1
  221. package/dist/modes/interactive/components/extension-input.d.ts +2 -0
  222. package/dist/modes/interactive/components/extension-input.d.ts.map +1 -1
  223. package/dist/modes/interactive/components/extension-input.js +6 -0
  224. package/dist/modes/interactive/components/extension-input.js.map +1 -1
  225. package/dist/modes/interactive/components/extension-selector.d.ts +1 -0
  226. package/dist/modes/interactive/components/extension-selector.d.ts.map +1 -1
  227. package/dist/modes/interactive/components/extension-selector.js +4 -0
  228. package/dist/modes/interactive/components/extension-selector.js.map +1 -1
  229. package/dist/modes/interactive/components/footer.d.ts.map +1 -1
  230. package/dist/modes/interactive/components/footer.js +4 -1
  231. package/dist/modes/interactive/components/footer.js.map +1 -1
  232. package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
  233. package/dist/modes/interactive/components/model-selector.js +5 -5
  234. package/dist/modes/interactive/components/model-selector.js.map +1 -1
  235. package/dist/modes/interactive/components/scoped-models-selector.d.ts.map +1 -1
  236. package/dist/modes/interactive/components/scoped-models-selector.js +8 -8
  237. package/dist/modes/interactive/components/scoped-models-selector.js.map +1 -1
  238. package/dist/modes/interactive/components/session-selector.d.ts +5 -5
  239. package/dist/modes/interactive/components/session-selector.d.ts.map +1 -1
  240. package/dist/modes/interactive/components/session-selector.js +74 -48
  241. package/dist/modes/interactive/components/session-selector.js.map +1 -1
  242. package/dist/modes/interactive/components/settings-selector.d.ts +3 -1
  243. package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
  244. package/dist/modes/interactive/components/settings-selector.js +11 -0
  245. package/dist/modes/interactive/components/settings-selector.js.map +1 -1
  246. package/dist/modes/interactive/components/skill-invocation-message.d.ts.map +1 -1
  247. package/dist/modes/interactive/components/skill-invocation-message.js +11 -4
  248. package/dist/modes/interactive/components/skill-invocation-message.js.map +1 -1
  249. package/dist/modes/interactive/components/status-indicator.d.ts +2 -2
  250. package/dist/modes/interactive/components/status-indicator.d.ts.map +1 -1
  251. package/dist/modes/interactive/components/status-indicator.js +7 -7
  252. package/dist/modes/interactive/components/status-indicator.js.map +1 -1
  253. package/dist/modes/interactive/components/thinking-selector.d.ts.map +1 -1
  254. package/dist/modes/interactive/components/thinking-selector.js +4 -4
  255. package/dist/modes/interactive/components/thinking-selector.js.map +1 -1
  256. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  257. package/dist/modes/interactive/components/tool-execution.js +18 -9
  258. package/dist/modes/interactive/components/tool-execution.js.map +1 -1
  259. package/dist/modes/interactive/components/tree-selector.d.ts.map +1 -1
  260. package/dist/modes/interactive/components/tree-selector.js +2 -0
  261. package/dist/modes/interactive/components/tree-selector.js.map +1 -1
  262. package/dist/modes/interactive/interactive-mode.d.ts +13 -1
  263. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  264. package/dist/modes/interactive/interactive-mode.js +220 -84
  265. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  266. package/dist/modes/interactive/session-share.d.ts +2 -0
  267. package/dist/modes/interactive/session-share.d.ts.map +1 -1
  268. package/dist/modes/interactive/session-share.js +8 -4
  269. package/dist/modes/interactive/session-share.js.map +1 -1
  270. package/dist/modes/interactive/tui-renderer.d.ts.map +1 -1
  271. package/dist/modes/interactive/tui-renderer.js +2 -2
  272. package/dist/modes/interactive/tui-renderer.js.map +1 -1
  273. package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
  274. package/dist/modes/rpc/rpc-mode.js +2 -2
  275. package/dist/modes/rpc/rpc-mode.js.map +1 -1
  276. package/dist/utils/clipboard-command.d.ts +7 -0
  277. package/dist/utils/clipboard-command.d.ts.map +1 -0
  278. package/dist/utils/clipboard-command.js +45 -0
  279. package/dist/utils/clipboard-command.js.map +1 -0
  280. package/dist/utils/clipboard-image.d.ts.map +1 -1
  281. package/dist/utils/clipboard-image.js +52 -69
  282. package/dist/utils/clipboard-image.js.map +1 -1
  283. package/dist/utils/clipboard.d.ts.map +1 -1
  284. package/dist/utils/clipboard.js +61 -125
  285. package/dist/utils/clipboard.js.map +1 -1
  286. package/dist/utils/zip.d.ts +7 -0
  287. package/dist/utils/zip.d.ts.map +1 -0
  288. package/dist/utils/zip.js +60 -0
  289. package/dist/utils/zip.js.map +1 -0
  290. package/docs/compaction.md +39 -13
  291. package/docs/containerization.md +45 -0
  292. package/docs/custom-provider.md +22 -13
  293. package/docs/development.md +23 -4
  294. package/docs/docs.json +4 -0
  295. package/docs/environment-variables.md +3 -2
  296. package/docs/extensions.md +57 -43
  297. package/docs/json.md +4 -4
  298. package/docs/keybindings.md +2 -1
  299. package/docs/models.md +34 -3
  300. package/docs/providers.md +2 -2
  301. package/docs/sdk.md +4 -2
  302. package/docs/security.md +1 -1
  303. package/docs/session-format.md +82 -40
  304. package/docs/sessions.md +27 -0
  305. package/docs/settings.md +60 -1
  306. package/docs/termux.md +0 -1
  307. package/docs/tui.md +2 -2
  308. package/docs/usage.md +1 -0
  309. package/examples/extensions/README.md +0 -1
  310. package/examples/extensions/custom-provider-anthropic/index.ts +18 -12
  311. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  312. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  313. package/examples/extensions/custom-provider-gitlab-duo/index.ts +2 -2
  314. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  315. package/examples/extensions/gondolin/package-lock.json +2 -2
  316. package/examples/extensions/gondolin/package.json +1 -1
  317. package/examples/extensions/prompt-customizer.ts +19 -67
  318. package/examples/extensions/sandbox/package-lock.json +2 -2
  319. package/examples/extensions/sandbox/package.json +1 -1
  320. package/examples/extensions/with-deps/package-lock.json +2 -2
  321. package/examples/extensions/with-deps/package.json +1 -1
  322. package/npm-shrinkwrap.json +425 -778
  323. package/package.json +22 -27
  324. package/dist/bundle/chunks/anthropic-messages-QAQLEQIY.js +0 -6
  325. package/dist/bundle/chunks/azure-openai-responses-Q7MJBRE6.js +0 -2
  326. package/dist/bundle/chunks/chunk-2KVJKXS2.js +0 -50
  327. package/dist/bundle/chunks/chunk-AXIIZGTV.js +0 -2
  328. package/dist/bundle/chunks/chunk-EQ6DR6XK.js +0 -5
  329. package/dist/bundle/chunks/chunk-GMWCTUPB.js +0 -2
  330. package/dist/bundle/chunks/chunk-LZKJTKCT.js +0 -2
  331. package/dist/bundle/chunks/chunk-OUXLLA64.js +0 -11
  332. package/dist/bundle/chunks/chunk-R7UUJ4C2.js +0 -42
  333. package/dist/bundle/chunks/chunk-UAQELI3K.js +0 -2
  334. package/dist/bundle/chunks/chunk-WBE4J4AU.js +0 -9
  335. package/dist/bundle/chunks/chunk-WZB2R5YO.js +0 -1558
  336. package/dist/bundle/chunks/google-generative-ai-BSMTYDAM.js +0 -2
  337. package/dist/bundle/chunks/google-vertex-5C3HASOJ.js +0 -2
  338. package/dist/bundle/chunks/mistral-conversations-4M6BZBX6.js +0 -5
  339. package/dist/bundle/chunks/openai-codex-responses-YJOO52RW.js +0 -10
  340. package/dist/bundle/chunks/openai-completions-QOT3QX7D.js +0 -7
  341. package/dist/bundle/chunks/openai-responses-U7LNPQN4.js +0 -2
  342. package/dist/bundle/client.js +0 -2
  343. package/dist/bundle/coordinator.js +0 -3
  344. package/dist/cli/experimental/cli.d.ts +0 -10
  345. package/dist/cli/experimental/cli.d.ts.map +0 -1
  346. package/dist/cli/experimental/cli.js +0 -9
  347. package/dist/cli/experimental/cli.js.map +0 -1
  348. package/dist/cli/experimental/command-options.d.ts +0 -28
  349. package/dist/cli/experimental/command-options.d.ts.map +0 -1
  350. package/dist/cli/experimental/command-options.js +0 -84
  351. package/dist/cli/experimental/command-options.js.map +0 -1
  352. package/dist/cli/experimental/command.d.ts +0 -70
  353. package/dist/cli/experimental/command.d.ts.map +0 -1
  354. package/dist/cli/experimental/command.js +0 -144
  355. package/dist/cli/experimental/command.js.map +0 -1
  356. package/dist/cli/experimental/commands/client.d.ts +0 -19
  357. package/dist/cli/experimental/commands/client.d.ts.map +0 -1
  358. package/dist/cli/experimental/commands/client.js +0 -63
  359. package/dist/cli/experimental/commands/client.js.map +0 -1
  360. package/dist/cli/experimental/commands/server.d.ts +0 -17
  361. package/dist/cli/experimental/commands/server.d.ts.map +0 -1
  362. package/dist/cli/experimental/commands/server.js +0 -44
  363. package/dist/cli/experimental/commands/server.js.map +0 -1
  364. package/dist/client/index.d.ts +0 -2
  365. package/dist/client/index.d.ts.map +0 -1
  366. package/dist/client/index.js +0 -2
  367. package/dist/client/index.js.map +0 -1
  368. package/dist/experimental/client-runtime.d.ts +0 -43
  369. package/dist/experimental/client-runtime.d.ts.map +0 -1
  370. package/dist/experimental/client-runtime.js +0 -183
  371. package/dist/experimental/client-runtime.js.map +0 -1
  372. package/dist/experimental/client-tui-chat.d.ts +0 -14
  373. package/dist/experimental/client-tui-chat.d.ts.map +0 -1
  374. package/dist/experimental/client-tui-chat.js +0 -171
  375. package/dist/experimental/client-tui-chat.js.map +0 -1
  376. package/dist/experimental/client-tui.d.ts +0 -37
  377. package/dist/experimental/client-tui.d.ts.map +0 -1
  378. package/dist/experimental/client-tui.js +0 -702
  379. package/dist/experimental/client-tui.js.map +0 -1
  380. package/dist/experimental/client.d.ts +0 -25
  381. package/dist/experimental/client.d.ts.map +0 -1
  382. package/dist/experimental/client.js +0 -99
  383. package/dist/experimental/client.js.map +0 -1
  384. package/dist/experimental/coordinator-entry.d.ts +0 -3
  385. package/dist/experimental/coordinator-entry.d.ts.map +0 -1
  386. package/dist/experimental/coordinator-entry.js +0 -11
  387. package/dist/experimental/coordinator-entry.js.map +0 -1
  388. package/dist/experimental/coordinator.d.ts +0 -38
  389. package/dist/experimental/coordinator.d.ts.map +0 -1
  390. package/dist/experimental/coordinator.js +0 -570
  391. package/dist/experimental/coordinator.js.map +0 -1
  392. package/dist/experimental/mini/main.d.ts +0 -7
  393. package/dist/experimental/mini/main.d.ts.map +0 -1
  394. package/dist/experimental/mini/main.js +0 -21
  395. package/dist/experimental/mini/main.js.map +0 -1
  396. package/dist/experimental/mini/server/entry.d.ts +0 -3
  397. package/dist/experimental/mini/server/entry.d.ts.map +0 -1
  398. package/dist/experimental/mini/server/entry.js +0 -11
  399. package/dist/experimental/mini/server/entry.js.map +0 -1
  400. package/dist/experimental/mini/server/run.d.ts +0 -13
  401. package/dist/experimental/mini/server/run.d.ts.map +0 -1
  402. package/dist/experimental/mini/server/run.js +0 -150
  403. package/dist/experimental/mini/server/run.js.map +0 -1
  404. package/dist/experimental/mini/shared/protocol.d.ts +0 -127
  405. package/dist/experimental/mini/shared/protocol.d.ts.map +0 -1
  406. package/dist/experimental/mini/shared/protocol.js +0 -13
  407. package/dist/experimental/mini/shared/protocol.js.map +0 -1
  408. package/dist/experimental/mini/shared/rpc.d.ts +0 -49
  409. package/dist/experimental/mini/shared/rpc.d.ts.map +0 -1
  410. package/dist/experimental/mini/shared/rpc.js +0 -171
  411. package/dist/experimental/mini/shared/rpc.js.map +0 -1
  412. package/dist/experimental/mini/shared/transport.d.ts +0 -35
  413. package/dist/experimental/mini/shared/transport.d.ts.map +0 -1
  414. package/dist/experimental/mini/shared/transport.js +0 -94
  415. package/dist/experimental/mini/shared/transport.js.map +0 -1
  416. package/dist/experimental/mini/tui/run.d.ts +0 -9
  417. package/dist/experimental/mini/tui/run.d.ts.map +0 -1
  418. package/dist/experimental/mini/tui/run.js +0 -62
  419. package/dist/experimental/mini/tui/run.js.map +0 -1
  420. package/dist/experimental/mini/tui/session.d.ts +0 -26
  421. package/dist/experimental/mini/tui/session.d.ts.map +0 -1
  422. package/dist/experimental/mini/tui/session.js +0 -94
  423. package/dist/experimental/mini/tui/session.js.map +0 -1
  424. package/dist/experimental/mini/tui/view.d.ts +0 -10
  425. package/dist/experimental/mini/tui/view.d.ts.map +0 -1
  426. package/dist/experimental/mini/tui/view.js +0 -459
  427. package/dist/experimental/mini/tui/view.js.map +0 -1
  428. package/dist/experimental/mini/worker/entry.d.ts +0 -3
  429. package/dist/experimental/mini/worker/entry.d.ts.map +0 -1
  430. package/dist/experimental/mini/worker/entry.js +0 -10
  431. package/dist/experimental/mini/worker/entry.js.map +0 -1
  432. package/dist/experimental/mini/worker/lane-service.d.ts +0 -44
  433. package/dist/experimental/mini/worker/lane-service.d.ts.map +0 -1
  434. package/dist/experimental/mini/worker/lane-service.js +0 -97
  435. package/dist/experimental/mini/worker/lane-service.js.map +0 -1
  436. package/dist/experimental/mini/worker/models-service.d.ts +0 -19
  437. package/dist/experimental/mini/worker/models-service.d.ts.map +0 -1
  438. package/dist/experimental/mini/worker/models-service.js +0 -136
  439. package/dist/experimental/mini/worker/models-service.js.map +0 -1
  440. package/dist/experimental/mini/worker/run.d.ts +0 -14
  441. package/dist/experimental/mini/worker/run.d.ts.map +0 -1
  442. package/dist/experimental/mini/worker/run.js +0 -88
  443. package/dist/experimental/mini/worker/run.js.map +0 -1
  444. package/dist/experimental/plugin.d.ts +0 -4
  445. package/dist/experimental/plugin.d.ts.map +0 -1
  446. package/dist/experimental/plugin.js +0 -4
  447. package/dist/experimental/plugin.js.map +0 -1
  448. package/dist/experimental/plugins/bundled.d.ts +0 -7
  449. package/dist/experimental/plugins/bundled.d.ts.map +0 -1
  450. package/dist/experimental/plugins/bundled.js +0 -48
  451. package/dist/experimental/plugins/bundled.js.map +0 -1
  452. package/dist/experimental/plugins/package.d.ts +0 -18
  453. package/dist/experimental/plugins/package.d.ts.map +0 -1
  454. package/dist/experimental/plugins/package.js +0 -113
  455. package/dist/experimental/plugins/package.js.map +0 -1
  456. package/dist/experimental/process.d.ts +0 -20
  457. package/dist/experimental/process.d.ts.map +0 -1
  458. package/dist/experimental/process.js +0 -85
  459. package/dist/experimental/process.js.map +0 -1
  460. package/dist/experimental/radius-auth.d.ts +0 -17
  461. package/dist/experimental/radius-auth.d.ts.map +0 -1
  462. package/dist/experimental/radius-auth.js +0 -52
  463. package/dist/experimental/radius-auth.js.map +0 -1
  464. package/dist/experimental/radius-relay.d.ts +0 -90
  465. package/dist/experimental/radius-relay.d.ts.map +0 -1
  466. package/dist/experimental/radius-relay.js +0 -582
  467. package/dist/experimental/radius-relay.js.map +0 -1
  468. package/dist/experimental/server.d.ts +0 -75
  469. package/dist/experimental/server.d.ts.map +0 -1
  470. package/dist/experimental/server.js +0 -682
  471. package/dist/experimental/server.js.map +0 -1
  472. package/dist/experimental/services/agent-controller-provider.d.ts +0 -4
  473. package/dist/experimental/services/agent-controller-provider.d.ts.map +0 -1
  474. package/dist/experimental/services/agent-controller-provider.js +0 -84
  475. package/dist/experimental/services/agent-controller-provider.js.map +0 -1
  476. package/dist/experimental/services/agent-controller.d.ts +0 -57
  477. package/dist/experimental/services/agent-controller.d.ts.map +0 -1
  478. package/dist/experimental/services/agent-controller.js +0 -3
  479. package/dist/experimental/services/agent-controller.js.map +0 -1
  480. package/dist/experimental/services/connection.d.ts +0 -40
  481. package/dist/experimental/services/connection.d.ts.map +0 -1
  482. package/dist/experimental/services/connection.js +0 -300
  483. package/dist/experimental/services/connection.js.map +0 -1
  484. package/dist/experimental/services/models-provider.d.ts +0 -16
  485. package/dist/experimental/services/models-provider.d.ts.map +0 -1
  486. package/dist/experimental/services/models-provider.js +0 -116
  487. package/dist/experimental/services/models-provider.js.map +0 -1
  488. package/dist/experimental/services/models.d.ts +0 -36
  489. package/dist/experimental/services/models.d.ts.map +0 -1
  490. package/dist/experimental/services/models.js +0 -3
  491. package/dist/experimental/services/models.js.map +0 -1
  492. package/dist/experimental/services/plugins.d.ts +0 -16
  493. package/dist/experimental/services/plugins.d.ts.map +0 -1
  494. package/dist/experimental/services/plugins.js +0 -4
  495. package/dist/experimental/services/plugins.js.map +0 -1
  496. package/dist/experimental/services/presentation-ui.d.ts +0 -13
  497. package/dist/experimental/services/presentation-ui.d.ts.map +0 -1
  498. package/dist/experimental/services/presentation-ui.js +0 -3
  499. package/dist/experimental/services/presentation-ui.js.map +0 -1
  500. package/dist/experimental/services/server.d.ts +0 -19
  501. package/dist/experimental/services/server.d.ts.map +0 -1
  502. package/dist/experimental/services/server.js +0 -104
  503. package/dist/experimental/services/server.js.map +0 -1
  504. package/dist/experimental/services/sessions.d.ts +0 -28
  505. package/dist/experimental/services/sessions.d.ts.map +0 -1
  506. package/dist/experimental/services/sessions.js +0 -4
  507. package/dist/experimental/services/sessions.js.map +0 -1
  508. package/dist/experimental/services/slash-commands-provider.d.ts +0 -14
  509. package/dist/experimental/services/slash-commands-provider.d.ts.map +0 -1
  510. package/dist/experimental/services/slash-commands-provider.js +0 -200
  511. package/dist/experimental/services/slash-commands-provider.js.map +0 -1
  512. package/dist/experimental/services/slash-commands.d.ts +0 -24
  513. package/dist/experimental/services/slash-commands.d.ts.map +0 -1
  514. package/dist/experimental/services/slash-commands.js +0 -3
  515. package/dist/experimental/services/slash-commands.js.map +0 -1
  516. package/dist/experimental/services/transcript-provider.d.ts +0 -12
  517. package/dist/experimental/services/transcript-provider.d.ts.map +0 -1
  518. package/dist/experimental/services/transcript-provider.js +0 -109
  519. package/dist/experimental/services/transcript-provider.js.map +0 -1
  520. package/dist/experimental/services/transcript.d.ts +0 -13
  521. package/dist/experimental/services/transcript.d.ts.map +0 -1
  522. package/dist/experimental/services/transcript.js +0 -3
  523. package/dist/experimental/services/transcript.js.map +0 -1
  524. package/dist/experimental/services/worker.d.ts +0 -28
  525. package/dist/experimental/services/worker.d.ts.map +0 -1
  526. package/dist/experimental/services/worker.js +0 -107
  527. package/dist/experimental/services/worker.js.map +0 -1
  528. package/dist/experimental/session-worker-manager.d.ts +0 -24
  529. package/dist/experimental/session-worker-manager.d.ts.map +0 -1
  530. package/dist/experimental/session-worker-manager.js +0 -691
  531. package/dist/experimental/session-worker-manager.js.map +0 -1
  532. package/dist/experimental/session-worker.d.ts +0 -188
  533. package/dist/experimental/session-worker.d.ts.map +0 -1
  534. package/dist/experimental/session-worker.js +0 -785
  535. package/dist/experimental/session-worker.js.map +0 -1
  536. package/dist/experimental/source-resolver.d.ts +0 -2
  537. package/dist/experimental/source-resolver.d.ts.map +0 -1
  538. package/dist/experimental/source-resolver.js +0 -71
  539. package/dist/experimental/source-resolver.js.map +0 -1
  540. package/dist/utils/clipboard-native.d.ts +0 -11
  541. package/dist/utils/clipboard-native.d.ts.map +0 -1
  542. package/dist/utils/clipboard-native.js +0 -20
  543. package/dist/utils/clipboard-native.js.map +0 -1
  544. package/examples/extensions/kimi-deferred-tools.ts +0 -61
@@ -1 +1 @@
1
- {"version":3,"file":"clipboard-image.js","sourceRoot":"","sources":["../../src/utils/clipboard-image.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAC9C,OAAO,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC;AAC5B,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAE5B,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAOzC,MAAM,0BAA0B,GAAG,CAAC,WAAW,EAAE,YAAY,EAAE,YAAY,EAAE,WAAW,CAAU,CAAC;AAEnG,MAAM,uBAAuB,GAAG,IAAI,CAAC;AACrC,MAAM,uBAAuB,GAAG,IAAI,CAAC;AACrC,MAAM,6BAA6B,GAAG,IAAI,CAAC;AAC3C,MAAM,wBAAwB,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC;AAElD,MAAM,UAAU,gBAAgB,CAAC,GAAG,GAAsB,OAAO,CAAC,GAAG,EAAW;IAC/E,OAAO,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,IAAI,GAAG,CAAC,gBAAgB,KAAK,SAAS,CAAC;AAAA,CAC1E;AAED,SAAS,YAAY,CAAC,QAAgB,EAAU;IAC/C,OAAO,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,WAAW,EAAE,IAAI,QAAQ,CAAC,WAAW,EAAE,CAAC;AAAA,CAC9E;AAED,MAAM,UAAU,yBAAyB,CAAC,QAAgB,EAAiB;IAC1E,QAAQ,YAAY,CAAC,QAAQ,CAAC,EAAE,CAA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,CAAC;AAAA,CACb","sourcesContent":["import { spawnSync } from \"child_process\";\nimport { randomUUID } from \"crypto\";\nimport { readFileSync, unlinkSync } from \"fs\";\nimport { tmpdir } from \"os\";\nimport { join } from \"path\";\n\nimport { clipboard } from \"./clipboard-native.ts\";\nimport { loadPhoton } from \"./photon.ts\";\n\nexport type ClipboardImage = {\n\tbytes: Uint8Array;\n\tmimeType: string;\n};\n\nconst SUPPORTED_IMAGE_MIME_TYPES = [\"image/png\", \"image/jpeg\", \"image/webp\", \"image/gif\"] as const;\n\nconst DEFAULT_LIST_TIMEOUT_MS = 1000;\nconst DEFAULT_READ_TIMEOUT_MS = 3000;\nconst DEFAULT_POWERSHELL_TIMEOUT_MS = 5000;\nconst DEFAULT_MAX_BUFFER_BYTES = 50 * 1024 * 1024;\n\nexport function isWaylandSession(env: NodeJS.ProcessEnv = process.env): boolean {\n\treturn Boolean(env.WAYLAND_DISPLAY) || env.XDG_SESSION_TYPE === \"wayland\";\n}\n\nfunction baseMimeType(mimeType: string): string {\n\treturn mimeType.split(\";\")[0]?.trim().toLowerCase() ?? mimeType.toLowerCase();\n}\n\nexport function extensionForImageMimeType(mimeType: string): string | null {\n\tswitch (baseMimeType(mimeType)) {\n\t\tcase \"image/png\":\n\t\t\treturn \"png\";\n\t\tcase \"image/jpeg\":\n\t\t\treturn \"jpg\";\n\t\tcase \"image/webp\":\n\t\t\treturn \"webp\";\n\t\tcase \"image/gif\":\n\t\t\treturn \"gif\";\n\t\tdefault:\n\t\t\treturn null;\n\t}\n}\n\nfunction selectPreferredImageMimeType(mimeTypes: string[]): string | null {\n\tconst normalized = mimeTypes\n\t\t.map((t) => t.trim())\n\t\t.filter(Boolean)\n\t\t.map((t) => ({ raw: t, base: baseMimeType(t) }));\n\n\tfor (const preferred of SUPPORTED_IMAGE_MIME_TYPES) {\n\t\tconst match = normalized.find((t) => t.base === preferred);\n\t\tif (match) {\n\t\t\treturn match.raw;\n\t\t}\n\t}\n\n\tconst anyImage = normalized.find((t) => t.base.startsWith(\"image/\"));\n\treturn anyImage?.raw ?? null;\n}\n\nfunction isSupportedImageMimeType(mimeType: string): boolean {\n\tconst base = baseMimeType(mimeType);\n\treturn SUPPORTED_IMAGE_MIME_TYPES.some((t) => t === base);\n}\n\n/**\n * Convert unsupported image formats to PNG using Photon.\n * Returns null if conversion is unavailable or fails.\n */\nasync function convertToPng(bytes: Uint8Array): Promise<Uint8Array | null> {\n\tconst photon = await loadPhoton();\n\tif (!photon) {\n\t\treturn null;\n\t}\n\n\ttry {\n\t\tconst image = photon.PhotonImage.new_from_byteslice(bytes);\n\t\ttry {\n\t\t\treturn image.get_bytes();\n\t\t} finally {\n\t\t\timage.free();\n\t\t}\n\t} catch {\n\t\treturn null;\n\t}\n}\n\nfunction runCommand(\n\tcommand: string,\n\targs: string[],\n\toptions?: { timeoutMs?: number; maxBufferBytes?: number; env?: NodeJS.ProcessEnv },\n): { stdout: Buffer; ok: boolean } {\n\tconst timeoutMs = options?.timeoutMs ?? DEFAULT_READ_TIMEOUT_MS;\n\tconst maxBufferBytes = options?.maxBufferBytes ?? DEFAULT_MAX_BUFFER_BYTES;\n\n\tconst result = spawnSync(command, args, {\n\t\ttimeout: timeoutMs,\n\t\tmaxBuffer: maxBufferBytes,\n\t\tenv: options?.env,\n\t});\n\n\tif (result.error) {\n\t\treturn { ok: false, stdout: Buffer.alloc(0) };\n\t}\n\n\tif (result.status !== 0) {\n\t\treturn { ok: false, stdout: Buffer.alloc(0) };\n\t}\n\n\tconst stdout = Buffer.isBuffer(result.stdout)\n\t\t? result.stdout\n\t\t: Buffer.from(result.stdout ?? \"\", typeof result.stdout === \"string\" ? \"utf-8\" : undefined);\n\n\treturn { ok: true, stdout };\n}\n\nfunction readClipboardImageViaWlPaste(): ClipboardImage | null {\n\tconst list = runCommand(\"wl-paste\", [\"--list-types\"], { timeoutMs: DEFAULT_LIST_TIMEOUT_MS });\n\tif (!list.ok) {\n\t\treturn null;\n\t}\n\n\tconst types = list.stdout\n\t\t.toString(\"utf-8\")\n\t\t.split(/\\r?\\n/)\n\t\t.map((t) => t.trim())\n\t\t.filter(Boolean);\n\n\tconst selectedType = selectPreferredImageMimeType(types);\n\tif (!selectedType) {\n\t\treturn null;\n\t}\n\n\tconst data = runCommand(\"wl-paste\", [\"--type\", selectedType, \"--no-newline\"]);\n\tif (!data.ok || data.stdout.length === 0) {\n\t\treturn null;\n\t}\n\n\treturn { bytes: data.stdout, mimeType: baseMimeType(selectedType) };\n}\n\nfunction isWSL(env: NodeJS.ProcessEnv = process.env): boolean {\n\tif (env.WSL_DISTRO_NAME || env.WSLENV) {\n\t\treturn true;\n\t}\n\n\ttry {\n\t\tconst release = readFileSync(\"/proc/version\", \"utf-8\");\n\t\treturn /microsoft|wsl/i.test(release);\n\t} catch {\n\t\treturn false;\n\t}\n}\n\n/**\n * On WSL, the Linux clipboard (Wayland/X11) does not receive image data from\n * Windows screenshots (Win+Shift+S). PowerShell can access the Windows clipboard\n * directly, so we use it as a fallback.\n */\nfunction readClipboardImageViaPowerShell(): ClipboardImage | null {\n\tconst tmpFile = join(tmpdir(), `pi-wsl-clip-${randomUUID()}.png`);\n\n\ttry {\n\t\tconst winPathResult = runCommand(\"wslpath\", [\"-w\", tmpFile], { timeoutMs: DEFAULT_LIST_TIMEOUT_MS });\n\t\tif (!winPathResult.ok) {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst winPath = winPathResult.stdout.toString(\"utf-8\").trim();\n\t\tif (!winPath) {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst psQuotedWinPath = winPath.replaceAll(\"'\", \"''\");\n\t\tconst psScript = [\n\t\t\t\"Add-Type -AssemblyName System.Windows.Forms\",\n\t\t\t\"Add-Type -AssemblyName System.Drawing\",\n\t\t\t`$path = '${psQuotedWinPath}'`,\n\t\t\t\"$img = [System.Windows.Forms.Clipboard]::GetImage()\",\n\t\t\t\"if ($img) { $img.Save($path, [System.Drawing.Imaging.ImageFormat]::Png); Write-Output 'ok' } else { Write-Output 'empty' }\",\n\t\t].join(\"; \");\n\n\t\tconst result = runCommand(\"powershell.exe\", [\"-NoProfile\", \"-Command\", psScript], {\n\t\t\ttimeoutMs: DEFAULT_POWERSHELL_TIMEOUT_MS,\n\t\t});\n\t\tif (!result.ok) {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst output = result.stdout.toString(\"utf-8\").trim();\n\t\tif (output !== \"ok\") {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst bytes = readFileSync(tmpFile);\n\t\tif (bytes.length === 0) {\n\t\t\treturn null;\n\t\t}\n\n\t\treturn { bytes: new Uint8Array(bytes), mimeType: \"image/png\" };\n\t} catch {\n\t\treturn null;\n\t} finally {\n\t\ttry {\n\t\t\tunlinkSync(tmpFile);\n\t\t} catch {\n\t\t\t// Ignore cleanup errors.\n\t\t}\n\t}\n}\n\nfunction readClipboardImageViaXclip(): ClipboardImage | null {\n\tconst targets = runCommand(\"xclip\", [\"-selection\", \"clipboard\", \"-t\", \"TARGETS\", \"-o\"], {\n\t\ttimeoutMs: DEFAULT_LIST_TIMEOUT_MS,\n\t});\n\n\tlet candidateTypes: string[] = [];\n\tif (targets.ok) {\n\t\tcandidateTypes = targets.stdout\n\t\t\t.toString(\"utf-8\")\n\t\t\t.split(/\\r?\\n/)\n\t\t\t.map((t) => t.trim())\n\t\t\t.filter(Boolean);\n\t}\n\n\tconst preferred = candidateTypes.length > 0 ? selectPreferredImageMimeType(candidateTypes) : null;\n\tconst tryTypes = preferred ? [preferred, ...SUPPORTED_IMAGE_MIME_TYPES] : [...SUPPORTED_IMAGE_MIME_TYPES];\n\n\tfor (const mimeType of tryTypes) {\n\t\tconst data = runCommand(\"xclip\", [\"-selection\", \"clipboard\", \"-t\", mimeType, \"-o\"]);\n\t\tif (data.ok && data.stdout.length > 0) {\n\t\t\treturn { bytes: data.stdout, mimeType: baseMimeType(mimeType) };\n\t\t}\n\t}\n\n\treturn null;\n}\n\nasync function readClipboardImageViaNativeClipboard(): Promise<ClipboardImage | null> {\n\tif (!clipboard || !clipboard.hasImage()) {\n\t\treturn null;\n\t}\n\n\tconst imageData = await clipboard.getImageBinary();\n\tif (!imageData || imageData.length === 0) {\n\t\treturn null;\n\t}\n\n\tconst bytes = imageData instanceof Uint8Array ? imageData : Uint8Array.from(imageData);\n\treturn { bytes, mimeType: \"image/png\" };\n}\n\nexport async function readClipboardImage(options?: {\n\tenv?: NodeJS.ProcessEnv;\n\tplatform?: NodeJS.Platform;\n}): Promise<ClipboardImage | null> {\n\tconst env = options?.env ?? process.env;\n\tconst platform = options?.platform ?? process.platform;\n\n\tif (env.TERMUX_VERSION) {\n\t\treturn null;\n\t}\n\n\tlet image: ClipboardImage | null = null;\n\n\tif (platform === \"linux\") {\n\t\tconst wsl = isWSL(env);\n\t\tconst wayland = isWaylandSession(env);\n\n\t\tif (wayland || wsl) {\n\t\t\timage = readClipboardImageViaWlPaste() ?? readClipboardImageViaXclip();\n\t\t}\n\n\t\tif (!image && wsl) {\n\t\t\timage = readClipboardImageViaPowerShell();\n\t\t}\n\n\t\tif (!image && !wayland) {\n\t\t\timage = (await readClipboardImageViaNativeClipboard()) ?? readClipboardImageViaXclip();\n\t\t}\n\t} else {\n\t\timage = await readClipboardImageViaNativeClipboard();\n\t}\n\n\tif (!image) {\n\t\treturn null;\n\t}\n\n\t// Convert unsupported formats (e.g., BMP from WSLg) to PNG\n\tif (!isSupportedImageMimeType(image.mimeType)) {\n\t\tconst pngBytes = await convertToPng(image.bytes);\n\t\tif (!pngBytes) {\n\t\t\treturn null;\n\t\t}\n\t\treturn { bytes: pngBytes, mimeType: \"image/png\" };\n\t}\n\n\treturn image;\n}\n"]}
1
+ {"version":3,"file":"clipboard-image.js","sourceRoot":"","sources":["../../src/utils/clipboard-image.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,UAAU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,CAAC;QACvB,IAAI,gBAAgB,CAAC,GAAG,CAAC,IAAI,GAAG,EAAE,CAAC;YAClC,KAAK,GAAG,MAAM,4BAA4B,EAAE,CAAC;QAC9C,CAAC;QACD,IAAI,KAAK,KAAK,SAAS;YAAE,KAAK,GAAG,MAAM,0BAA0B,EAAE,CAAC;QACpE,0EAA0E;QAC1E,IAAI,CAAC,KAAK,IAAI,GAAG;YAAE,KAAK,GAAG,CAAC,MAAM,+BAA+B,EAAE,CAAC,IAAI,KAAK,CAAC;QAC9E,IAAI,KAAK,KAAK,SAAS;YAAE,KAAK,GAAG,MAAM,oCAAoC,EAAE,CAAC;IAC/E,CAAC;SAAM,CAAC;QACP,KAAK,GAAG,MAAM,oCAAoC,EAAE,CAAC;IACtD,CAAC;IAED,IAAI,CAAC,KAAK,EAAE,CAAC;QACZ,OAAO,IAAI,CAAC;IACb,CAAC;IAED,6EAA6E;IAC7E,IAAI,CAAC,wBAAwB,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC/C,MAAM,QAAQ,GAAG,MAAM,YAAY,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACjD,IAAI,CAAC,QAAQ,EAAE,CAAC;YACf,OAAO,IAAI,CAAC;QACb,CAAC;QACD,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,WAAW,EAAE,CAAC;IACnD,CAAC;IAED,OAAO,KAAK,CAAC;AAAA,CACb","sourcesContent":["import { getNativeClipboard } from \"@earendil-works/pi-tui\";\nimport { randomUUID } from \"crypto\";\nimport { readFileSync, unlinkSync } from \"fs\";\nimport { tmpdir } from \"os\";\nimport { join } from \"path\";\n\nimport { runClipboardCommand } from \"./clipboard-command.ts\";\nimport { detectSupportedImageMimeType } from \"./mime.ts\";\nimport { loadPhoton } from \"./photon.ts\";\n\nexport type ClipboardImage = {\n\tbytes: Uint8Array;\n\tmimeType: string;\n};\n\nconst SUPPORTED_IMAGE_MIME_TYPES = [\"image/png\", \"image/jpeg\", \"image/webp\", \"image/gif\"] as const;\n\nconst DEFAULT_LIST_TIMEOUT_MS = 1000;\nconst DEFAULT_POWERSHELL_TIMEOUT_MS = 5000;\n\nexport function isWaylandSession(env: NodeJS.ProcessEnv = process.env): boolean {\n\treturn Boolean(env.WAYLAND_DISPLAY) || env.XDG_SESSION_TYPE === \"wayland\";\n}\n\nfunction baseMimeType(mimeType: string): string {\n\treturn mimeType.split(\";\")[0]?.trim().toLowerCase() ?? mimeType.toLowerCase();\n}\n\nexport function extensionForImageMimeType(mimeType: string): string | null {\n\tswitch (baseMimeType(mimeType)) {\n\t\tcase \"image/png\":\n\t\t\treturn \"png\";\n\t\tcase \"image/jpeg\":\n\t\t\treturn \"jpg\";\n\t\tcase \"image/webp\":\n\t\t\treturn \"webp\";\n\t\tcase \"image/gif\":\n\t\t\treturn \"gif\";\n\t\tdefault:\n\t\t\treturn null;\n\t}\n}\n\nfunction selectPreferredImageMimeType(mimeTypes: string[]): string | null {\n\tconst normalized = mimeTypes\n\t\t.map((t) => t.trim())\n\t\t.filter(Boolean)\n\t\t.map((t) => ({ raw: t, base: baseMimeType(t) }));\n\n\tfor (const preferred of SUPPORTED_IMAGE_MIME_TYPES) {\n\t\tconst match = normalized.find((t) => t.base === preferred);\n\t\tif (match) {\n\t\t\treturn match.raw;\n\t\t}\n\t}\n\n\tconst anyImage = normalized.find((t) => t.base.startsWith(\"image/\"));\n\treturn anyImage?.raw ?? null;\n}\n\nfunction isSupportedImageMimeType(mimeType: string): boolean {\n\tconst base = baseMimeType(mimeType);\n\treturn SUPPORTED_IMAGE_MIME_TYPES.some((t) => t === base);\n}\n\n/**\n * Convert unsupported image formats to PNG using Photon.\n * Returns null if conversion is unavailable or fails.\n */\nasync function convertToPng(bytes: Uint8Array): Promise<Uint8Array | null> {\n\tconst photon = await loadPhoton();\n\tif (!photon) {\n\t\treturn null;\n\t}\n\n\ttry {\n\t\tconst image = photon.PhotonImage.new_from_byteslice(bytes);\n\t\ttry {\n\t\t\treturn image.get_bytes();\n\t\t} finally {\n\t\t\timage.free();\n\t\t}\n\t} catch {\n\t\treturn null;\n\t}\n}\n\n// Undefined means the backend failed; null means it has no image. An empty\n// Wayland clipboard must not fall through to stale X11 clipboard contents.\nasync function readClipboardImageViaWlPaste(): Promise<ClipboardImage | null | undefined> {\n\tconst list = await runClipboardCommand(\"wl-paste\", [\"--list-types\"], { timeoutMs: DEFAULT_LIST_TIMEOUT_MS });\n\tif (list === undefined) return undefined;\n\n\tconst types = list\n\t\t.toString(\"utf-8\")\n\t\t.split(/\\r?\\n/)\n\t\t.map((t) => t.trim())\n\t\t.filter(Boolean);\n\n\tconst selectedType = selectPreferredImageMimeType(types);\n\tif (!selectedType) {\n\t\treturn null;\n\t}\n\n\tconst data = await runClipboardCommand(\"wl-paste\", [\"--type\", selectedType, \"--no-newline\"]);\n\tif (data === undefined) return undefined;\n\tif (data.length === 0) return null;\n\n\treturn { bytes: data, mimeType: baseMimeType(selectedType) };\n}\n\nfunction isWSL(env: NodeJS.ProcessEnv = process.env): boolean {\n\tif (env.WSL_DISTRO_NAME || env.WSLENV) {\n\t\treturn true;\n\t}\n\n\ttry {\n\t\tconst release = readFileSync(\"/proc/version\", \"utf-8\");\n\t\treturn /microsoft|wsl/i.test(release);\n\t} catch {\n\t\treturn false;\n\t}\n}\n\n/**\n * On WSL, the Linux clipboard (Wayland/X11) does not receive image data from\n * Windows screenshots (Win+Shift+S). PowerShell can access the Windows clipboard\n * directly, so we use it as a fallback.\n */\nasync function readClipboardImageViaPowerShell(): Promise<ClipboardImage | null> {\n\tconst tmpFile = join(tmpdir(), `pi-wsl-clip-${randomUUID()}.png`);\n\n\ttry {\n\t\tconst winPathResult = await runClipboardCommand(\"wslpath\", [\"-w\", tmpFile], {\n\t\t\ttimeoutMs: DEFAULT_LIST_TIMEOUT_MS,\n\t\t});\n\t\tif (winPathResult === undefined) {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst winPath = winPathResult.toString(\"utf-8\").trim();\n\t\tif (!winPath) {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst psQuotedWinPath = winPath.replaceAll(\"'\", \"''\");\n\t\tconst psScript = [\n\t\t\t\"Add-Type -AssemblyName System.Windows.Forms\",\n\t\t\t\"Add-Type -AssemblyName System.Drawing\",\n\t\t\t`$path = '${psQuotedWinPath}'`,\n\t\t\t\"$img = [System.Windows.Forms.Clipboard]::GetImage()\",\n\t\t\t\"if ($img) { $img.Save($path, [System.Drawing.Imaging.ImageFormat]::Png); Write-Output 'ok' } else { Write-Output 'empty' }\",\n\t\t].join(\"; \");\n\n\t\tconst result = await runClipboardCommand(\"powershell.exe\", [\"-NoProfile\", \"-Command\", psScript], {\n\t\t\ttimeoutMs: DEFAULT_POWERSHELL_TIMEOUT_MS,\n\t\t});\n\t\tif (result === undefined) {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst output = result.toString(\"utf-8\").trim();\n\t\tif (output !== \"ok\") {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst bytes = readFileSync(tmpFile);\n\t\tif (bytes.length === 0) {\n\t\t\treturn null;\n\t\t}\n\n\t\treturn { bytes: new Uint8Array(bytes), mimeType: \"image/png\" };\n\t} catch {\n\t\treturn null;\n\t} finally {\n\t\ttry {\n\t\t\tunlinkSync(tmpFile);\n\t\t} catch {\n\t\t\t// Ignore cleanup errors.\n\t\t}\n\t}\n}\n\nasync function readClipboardImageViaXclip(): Promise<ClipboardImage | null | undefined> {\n\tconst targets = await runClipboardCommand(\"xclip\", [\"-selection\", \"clipboard\", \"-t\", \"TARGETS\", \"-o\"], {\n\t\ttimeoutMs: DEFAULT_LIST_TIMEOUT_MS,\n\t});\n\n\tlet candidateTypes: string[] = [];\n\tif (targets !== undefined) {\n\t\tcandidateTypes = targets\n\t\t\t.toString(\"utf-8\")\n\t\t\t.split(/\\r?\\n/)\n\t\t\t.map((t) => t.trim())\n\t\t\t.filter(Boolean);\n\t}\n\n\tconst preferred = selectPreferredImageMimeType(candidateTypes);\n\tif (targets !== undefined && !preferred) return null;\n\tconst tryTypes = new Set(preferred ? [preferred, ...SUPPORTED_IMAGE_MIME_TYPES] : SUPPORTED_IMAGE_MIME_TYPES);\n\n\tfor (const mimeType of tryTypes) {\n\t\tconst data = await runClipboardCommand(\"xclip\", [\"-selection\", \"clipboard\", \"-t\", mimeType, \"-o\"]);\n\t\tif (data !== undefined && data.length > 0) {\n\t\t\treturn { bytes: data, mimeType: baseMimeType(mimeType) };\n\t\t}\n\t}\n\n\treturn undefined;\n}\n\nasync function readClipboardImageViaNativeClipboard(): Promise<ClipboardImage | null | undefined> {\n\tconst bytes = await getNativeClipboard()?.getImage();\n\tif (bytes === undefined) return undefined;\n\tif (!bytes?.length) return null;\n\treturn { bytes, mimeType: detectSupportedImageMimeType(bytes) ?? \"application/octet-stream\" };\n}\n\nexport async function readClipboardImage(options?: {\n\tenv?: NodeJS.ProcessEnv;\n\tplatform?: NodeJS.Platform;\n}): Promise<ClipboardImage | null> {\n\tconst env = options?.env ?? process.env;\n\tconst platform = options?.platform ?? process.platform;\n\n\tif (env.TERMUX_VERSION) {\n\t\treturn null;\n\t}\n\n\tlet image: ClipboardImage | null | undefined;\n\n\tif (platform === \"linux\") {\n\t\tconst wsl = isWSL(env);\n\t\tif (isWaylandSession(env) || wsl) {\n\t\t\timage = await readClipboardImageViaWlPaste();\n\t\t}\n\t\tif (image === undefined) image = await readClipboardImageViaXclip();\n\t\t// Preserve Linux's empty/unavailable distinction if Windows has no image.\n\t\tif (!image && wsl) image = (await readClipboardImageViaPowerShell()) ?? image;\n\t\tif (image === undefined) image = await readClipboardImageViaNativeClipboard();\n\t} else {\n\t\timage = await readClipboardImageViaNativeClipboard();\n\t}\n\n\tif (!image) {\n\t\treturn null;\n\t}\n\n\t// Convert unsupported formats (e.g., Windows DIB data wrapped as BMP) to PNG\n\tif (!isSupportedImageMimeType(image.mimeType)) {\n\t\tconst pngBytes = await convertToPng(image.bytes);\n\t\tif (!pngBytes) {\n\t\t\treturn null;\n\t\t}\n\t\treturn { bytes: pngBytes, mimeType: \"image/png\" };\n\t}\n\n\treturn image;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"clipboard.d.ts","sourceRoot":"","sources":["../../src/utils/clipboard.ts"],"names":[],"mappings":"AAmDA,iDAAiD;AACjD,wBAAsB,iBAAiB,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAkBhE;AAED,wBAAsB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAsGjE","sourcesContent":["import { type ExecFileSyncOptionsWithStringEncoding, execFileSync, execSync, spawn } from \"child_process\";\nimport { platform } from \"os\";\nimport { isWaylandSession } from \"./clipboard-image.ts\";\nimport { clipboard } from \"./clipboard-native.ts\";\n\ntype NativeClipboardExecOptions = {\n\tinput: string;\n\ttimeout: number;\n\tstdio: [\"pipe\", \"ignore\", \"ignore\"];\n};\n\nfunction copyToX11Clipboard(options: NativeClipboardExecOptions): void {\n\ttry {\n\t\texecSync(\"xclip -selection clipboard\", options);\n\t} catch {\n\t\texecSync(\"xsel --clipboard --input\", options);\n\t}\n}\n\nconst MAX_OSC52_ENCODED_LENGTH = 100_000;\n\nfunction isRemoteSession(env: NodeJS.ProcessEnv = process.env): boolean {\n\treturn Boolean(env.SSH_CONNECTION || env.SSH_CLIENT || env.MOSH_CONNECTION);\n}\n\nfunction emitOsc52(text: string): boolean {\n\tconst encoded = Buffer.from(text).toString(\"base64\");\n\tif (encoded.length > MAX_OSC52_ENCODED_LENGTH) {\n\t\treturn false;\n\t}\n\tprocess.stdout.write(`\\x1b]52;c;${encoded}\\x07`);\n\treturn true;\n}\n\ntype ClipboardReadResult = { ok: true; text: string | null } | { ok: false };\n\nconst READ_CLIPBOARD_OPTIONS: ExecFileSyncOptionsWithStringEncoding = {\n\tencoding: \"utf8\",\n\tmaxBuffer: 50 * 1024 * 1024,\n\ttimeout: 5000,\n};\n\nfunction readWaylandClipboardText(): ClipboardReadResult {\n\ttry {\n\t\tconst text = execFileSync(\"wl-paste\", [\"--no-newline\", \"--type\", \"text\"], READ_CLIPBOARD_OPTIONS);\n\t\treturn { ok: true, text: text || null };\n\t} catch {\n\t\treturn { ok: false };\n\t}\n}\n\n/** Read plain text from the system clipboard. */\nexport async function readClipboardText(): Promise<string | null> {\n\tif (platform() === \"linux\" && isWaylandSession() && process.env.WAYLAND_DISPLAY) {\n\t\tconst result = readWaylandClipboardText();\n\t\tif (result.ok) {\n\t\t\treturn result.text;\n\t\t}\n\t}\n\n\tif (!clipboard) {\n\t\treturn null;\n\t}\n\n\ttry {\n\t\tconst text = await clipboard.getText();\n\t\treturn text || null;\n\t} catch {\n\t\treturn null;\n\t}\n}\n\nexport async function copyToClipboard(text: string): Promise<void> {\n\tlet copied = false;\n\n\tconst p = platform();\n\n\t// Prefer direct clipboard writes. Emitting OSC 52 first can make terminals\n\t// write the same native clipboard concurrently with the addon, and very large\n\t// OSC 52 payloads can desynchronize terminal rendering.\n\t//\n\t// On Linux, skip the native addon. The underlying `clipboard-rs` crate is\n\t// X11-only and does not retain selection ownership after `set_text`\n\t// resolves, so on Wayland-only compositors (Hyprland, Niri, ...) and even\n\t// some X11 sessions the call resolves successfully without populating the\n\t// clipboard. The platform tools below (wl-copy, xclip, xsel) properly\n\t// daemonize and keep ownership.\n\ttry {\n\t\tif (clipboard && p !== \"linux\") {\n\t\t\tawait clipboard.setText(text);\n\t\t\tcopied = true;\n\t\t}\n\t} catch {\n\t\t// Fall through to platform-specific clipboard tools.\n\t}\n\n\tconst remote = isRemoteSession();\n\tif (copied && !remote) {\n\t\treturn;\n\t}\n\n\tconst options: NativeClipboardExecOptions = { input: text, timeout: 5000, stdio: [\"pipe\", \"ignore\", \"ignore\"] };\n\n\tif (!copied) {\n\t\ttry {\n\t\t\tif (p === \"darwin\") {\n\t\t\t\texecSync(\"pbcopy\", options);\n\t\t\t\tcopied = true;\n\t\t\t} else if (p === \"win32\") {\n\t\t\t\texecSync(\"clip\", options);\n\t\t\t\tcopied = true;\n\t\t\t} else {\n\t\t\t\t// Linux. Try Termux, Wayland, or X11 clipboard tools.\n\t\t\t\tif (process.env.TERMUX_VERSION) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\texecSync(\"termux-clipboard-set\", options);\n\t\t\t\t\t\tcopied = true;\n\t\t\t\t\t} catch {\n\t\t\t\t\t\t// Fall back to Wayland or X11 tools.\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (!copied) {\n\t\t\t\t\tconst hasWaylandDisplay = Boolean(process.env.WAYLAND_DISPLAY);\n\t\t\t\t\tconst hasX11Display = Boolean(process.env.DISPLAY);\n\t\t\t\t\tconst isWayland = isWaylandSession();\n\t\t\t\t\tif (isWayland && hasWaylandDisplay) {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t// Verify wl-copy exists (spawn errors are async and won't be caught)\n\t\t\t\t\t\t\texecSync(\"which wl-copy\", { stdio: \"ignore\" });\n\t\t\t\t\t\t\t// wl-copy with execSync hangs due to fork behavior; use spawn instead.\n\t\t\t\t\t\t\t// Await the exit code and only claim success on a clean exit, so a\n\t\t\t\t\t\t\t// failed wl-copy falls through to the xclip/OSC 52 fallbacks.\n\t\t\t\t\t\t\tconst wlCopyExit = await new Promise<number>((resolve) => {\n\t\t\t\t\t\t\t\tconst proc = spawn(\"wl-copy\", [], { stdio: [\"pipe\", \"ignore\", \"ignore\"] });\n\t\t\t\t\t\t\t\tproc.on(\"error\", () => resolve(1));\n\t\t\t\t\t\t\t\tproc.on(\"close\", (code) => resolve(code ?? 1));\n\t\t\t\t\t\t\t\tproc.stdin.on(\"error\", () => {\n\t\t\t\t\t\t\t\t\t// Ignore EPIPE errors if wl-copy exits early\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\tproc.stdin.write(text);\n\t\t\t\t\t\t\t\tproc.stdin.end();\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\tif (wlCopyExit === 0) {\n\t\t\t\t\t\t\t\tcopied = true;\n\t\t\t\t\t\t\t} else if (hasX11Display) {\n\t\t\t\t\t\t\t\tcopyToX11Clipboard(options);\n\t\t\t\t\t\t\t\tcopied = true;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\tif (hasX11Display) {\n\t\t\t\t\t\t\t\tcopyToX11Clipboard(options);\n\t\t\t\t\t\t\t\tcopied = true;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (hasX11Display) {\n\t\t\t\t\t\tcopyToX11Clipboard(options);\n\t\t\t\t\t\tcopied = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t} catch {\n\t\t\t// Fall through to OSC 52 fallback.\n\t\t}\n\t}\n\n\tif (remote || !copied) {\n\t\tconst osc52Copied = emitOsc52(text);\n\t\tcopied = copied || osc52Copied;\n\t}\n\n\tif (!copied) {\n\t\tthrow new Error(\"Failed to copy to clipboard\");\n\t}\n}\n"]}
1
+ {"version":3,"file":"clipboard.d.ts","sourceRoot":"","sources":["../../src/utils/clipboard.ts"],"names":[],"mappings":"AAmBA,iDAAiD;AACjD,wBAAsB,iBAAiB,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAkBhE;AAED,wBAAsB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAkDjE","sourcesContent":["import { platform } from \"node:os\";\nimport { getNativeClipboard } from \"@earendil-works/pi-tui\";\nimport { runClipboardCommand } from \"./clipboard-command.ts\";\n\nconst MAX_OSC52_ENCODED_LENGTH = 100_000;\n\nfunction isRemoteSession(env: NodeJS.ProcessEnv = process.env): boolean {\n\treturn Boolean(env.SSH_CONNECTION || env.SSH_CLIENT || env.MOSH_CONNECTION);\n}\n\nfunction emitOsc52(text: string): boolean {\n\tconst encoded = Buffer.from(text).toString(\"base64\");\n\tif (encoded.length > MAX_OSC52_ENCODED_LENGTH) {\n\t\treturn false;\n\t}\n\tprocess.stdout.write(`\\x1b]52;c;${encoded}\\x07`);\n\treturn true;\n}\n\n/** Read plain text from the system clipboard. */\nexport async function readClipboardText(): Promise<string | null> {\n\tif (platform() === \"linux\") {\n\t\tconst commands: [string, string[]][] = [];\n\t\tif (process.env.TERMUX_VERSION) commands.push([\"termux-clipboard-get\", []]);\n\t\tif (process.env.WAYLAND_DISPLAY) commands.push([\"wl-paste\", [\"--no-newline\", \"--type\", \"text\"]]);\n\t\tif (process.env.DISPLAY) {\n\t\t\tcommands.push([\"xclip\", [\"-selection\", \"clipboard\", \"-out\"]], [\"xsel\", [\"--clipboard\", \"--output\"]]);\n\t\t}\n\t\tfor (const [command, args] of commands) {\n\t\t\tconst bytes = await runClipboardCommand(command, args, { timeoutMs: 5000 });\n\t\t\tif (bytes !== undefined) return bytes.toString(\"utf8\") || null;\n\t\t}\n\t}\n\ttry {\n\t\treturn (await getNativeClipboard()?.getText()) || null;\n\t} catch {\n\t\treturn null;\n\t}\n}\n\nexport async function copyToClipboard(text: string): Promise<void> {\n\tconst p = platform();\n\tlet copied = false;\n\t// Direct writes precede OSC 52 so the terminal cannot race the native writer.\n\t// Linux tools retain clipboard selection ownership after this call returns.\n\tif (p !== \"linux\") {\n\t\ttry {\n\t\t\tconst clipboard = getNativeClipboard();\n\t\t\tif (clipboard?.setText) {\n\t\t\t\tawait clipboard.setText(text);\n\t\t\t\tcopied = true;\n\t\t\t}\n\t\t} catch {\n\t\t\t// Try platform commands next.\n\t\t}\n\t}\n\tif (!copied) {\n\t\tconst commands: [string, string[]][] = [];\n\t\tif (p === \"darwin\") commands.push([\"pbcopy\", []]);\n\t\telse if (p === \"win32\") commands.push([\"clip\", []]);\n\t\telse {\n\t\t\tif (process.env.TERMUX_VERSION) commands.push([\"termux-clipboard-set\", []]);\n\t\t\tif (process.env.WAYLAND_DISPLAY) commands.push([\"wl-copy\", []]);\n\t\t\tif (process.env.DISPLAY) {\n\t\t\t\tcommands.push([\"xclip\", [\"-selection\", \"clipboard\"]], [\"xsel\", [\"--clipboard\", \"--input\"]]);\n\t\t\t}\n\t\t}\n\t\tfor (const [command, args] of commands) {\n\t\t\tif ((await runClipboardCommand(command, args, { input: text, timeoutMs: 5000 })) !== undefined) {\n\t\t\t\tcopied = true;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\tif (isRemoteSession()) copied = emitOsc52(text) || copied;\n\tif (!copied) {\n\t\tif (p === \"linux\") {\n\t\t\tif (process.env.TERMUX_VERSION) {\n\t\t\t\tthrow new Error(\"Clipboard unavailable: install the Termux:API app and `termux-api` package\");\n\t\t\t}\n\t\t\tif (process.env.WAYLAND_DISPLAY) {\n\t\t\t\tthrow new Error(\"Clipboard unavailable: install `wl-clipboard` (`wl-copy`) or check Wayland access\");\n\t\t\t}\n\t\t\tif (process.env.DISPLAY) {\n\t\t\t\tthrow new Error(\"Clipboard unavailable: install `xclip` or `xsel`, or check X11 access\");\n\t\t\t}\n\t\t\tthrow new Error(\"Clipboard unavailable: no Wayland or X11 display detected\");\n\t\t}\n\t\tthrow new Error(\"Clipboard unavailable\");\n\t}\n}\n"]}
@@ -1,15 +1,6 @@
1
- import { execFileSync, execSync, spawn } from "child_process";
2
- import { platform } from "os";
3
- import { isWaylandSession } from "./clipboard-image.js";
4
- import { clipboard } from "./clipboard-native.js";
5
- function copyToX11Clipboard(options) {
6
- try {
7
- execSync("xclip -selection clipboard", options);
8
- }
9
- catch {
10
- execSync("xsel --clipboard --input", options);
11
- }
12
- }
1
+ import { platform } from "node:os";
2
+ import { getNativeClipboard } from "@earendil-works/pi-tui";
3
+ import { runClipboardCommand } from "./clipboard-command.js";
13
4
  const MAX_OSC52_ENCODED_LENGTH = 100_000;
14
5
  function isRemoteSession(env = process.env) {
15
6
  return Boolean(env.SSH_CONNECTION || env.SSH_CLIENT || env.MOSH_CONNECTION);
@@ -22,140 +13,85 @@ function emitOsc52(text) {
22
13
  process.stdout.write(`\x1b]52;c;${encoded}\x07`);
23
14
  return true;
24
15
  }
25
- const READ_CLIPBOARD_OPTIONS = {
26
- encoding: "utf8",
27
- maxBuffer: 50 * 1024 * 1024,
28
- timeout: 5000,
29
- };
30
- function readWaylandClipboardText() {
31
- try {
32
- const text = execFileSync("wl-paste", ["--no-newline", "--type", "text"], READ_CLIPBOARD_OPTIONS);
33
- return { ok: true, text: text || null };
34
- }
35
- catch {
36
- return { ok: false };
37
- }
38
- }
39
16
  /** Read plain text from the system clipboard. */
40
17
  export async function readClipboardText() {
41
- if (platform() === "linux" && isWaylandSession() && process.env.WAYLAND_DISPLAY) {
42
- const result = readWaylandClipboardText();
43
- if (result.ok) {
44
- return result.text;
18
+ if (platform() === "linux") {
19
+ const commands = [];
20
+ if (process.env.TERMUX_VERSION)
21
+ commands.push(["termux-clipboard-get", []]);
22
+ if (process.env.WAYLAND_DISPLAY)
23
+ commands.push(["wl-paste", ["--no-newline", "--type", "text"]]);
24
+ if (process.env.DISPLAY) {
25
+ commands.push(["xclip", ["-selection", "clipboard", "-out"]], ["xsel", ["--clipboard", "--output"]]);
26
+ }
27
+ for (const [command, args] of commands) {
28
+ const bytes = await runClipboardCommand(command, args, { timeoutMs: 5000 });
29
+ if (bytes !== undefined)
30
+ return bytes.toString("utf8") || null;
45
31
  }
46
- }
47
- if (!clipboard) {
48
- return null;
49
32
  }
50
33
  try {
51
- const text = await clipboard.getText();
52
- return text || null;
34
+ return (await getNativeClipboard()?.getText()) || null;
53
35
  }
54
36
  catch {
55
37
  return null;
56
38
  }
57
39
  }
58
40
  export async function copyToClipboard(text) {
59
- let copied = false;
60
41
  const p = platform();
61
- // Prefer direct clipboard writes. Emitting OSC 52 first can make terminals
62
- // write the same native clipboard concurrently with the addon, and very large
63
- // OSC 52 payloads can desynchronize terminal rendering.
64
- //
65
- // On Linux, skip the native addon. The underlying `clipboard-rs` crate is
66
- // X11-only and does not retain selection ownership after `set_text`
67
- // resolves, so on Wayland-only compositors (Hyprland, Niri, ...) and even
68
- // some X11 sessions the call resolves successfully without populating the
69
- // clipboard. The platform tools below (wl-copy, xclip, xsel) properly
70
- // daemonize and keep ownership.
71
- try {
72
- if (clipboard && p !== "linux") {
73
- await clipboard.setText(text);
74
- copied = true;
75
- }
76
- }
77
- catch {
78
- // Fall through to platform-specific clipboard tools.
79
- }
80
- const remote = isRemoteSession();
81
- if (copied && !remote) {
82
- return;
83
- }
84
- const options = { input: text, timeout: 5000, stdio: ["pipe", "ignore", "ignore"] };
85
- if (!copied) {
42
+ let copied = false;
43
+ // Direct writes precede OSC 52 so the terminal cannot race the native writer.
44
+ // Linux tools retain clipboard selection ownership after this call returns.
45
+ if (p !== "linux") {
86
46
  try {
87
- if (p === "darwin") {
88
- execSync("pbcopy", options);
47
+ const clipboard = getNativeClipboard();
48
+ if (clipboard?.setText) {
49
+ await clipboard.setText(text);
89
50
  copied = true;
90
51
  }
91
- else if (p === "win32") {
92
- execSync("clip", options);
93
- copied = true;
94
- }
95
- else {
96
- // Linux. Try Termux, Wayland, or X11 clipboard tools.
97
- if (process.env.TERMUX_VERSION) {
98
- try {
99
- execSync("termux-clipboard-set", options);
100
- copied = true;
101
- }
102
- catch {
103
- // Fall back to Wayland or X11 tools.
104
- }
105
- }
106
- if (!copied) {
107
- const hasWaylandDisplay = Boolean(process.env.WAYLAND_DISPLAY);
108
- const hasX11Display = Boolean(process.env.DISPLAY);
109
- const isWayland = isWaylandSession();
110
- if (isWayland && hasWaylandDisplay) {
111
- try {
112
- // Verify wl-copy exists (spawn errors are async and won't be caught)
113
- execSync("which wl-copy", { stdio: "ignore" });
114
- // wl-copy with execSync hangs due to fork behavior; use spawn instead.
115
- // Await the exit code and only claim success on a clean exit, so a
116
- // failed wl-copy falls through to the xclip/OSC 52 fallbacks.
117
- const wlCopyExit = await new Promise((resolve) => {
118
- const proc = spawn("wl-copy", [], { stdio: ["pipe", "ignore", "ignore"] });
119
- proc.on("error", () => resolve(1));
120
- proc.on("close", (code) => resolve(code ?? 1));
121
- proc.stdin.on("error", () => {
122
- // Ignore EPIPE errors if wl-copy exits early
123
- });
124
- proc.stdin.write(text);
125
- proc.stdin.end();
126
- });
127
- if (wlCopyExit === 0) {
128
- copied = true;
129
- }
130
- else if (hasX11Display) {
131
- copyToX11Clipboard(options);
132
- copied = true;
133
- }
134
- }
135
- catch {
136
- if (hasX11Display) {
137
- copyToX11Clipboard(options);
138
- copied = true;
139
- }
140
- }
141
- }
142
- else if (hasX11Display) {
143
- copyToX11Clipboard(options);
144
- copied = true;
145
- }
146
- }
147
- }
148
52
  }
149
53
  catch {
150
- // Fall through to OSC 52 fallback.
54
+ // Try platform commands next.
151
55
  }
152
56
  }
153
- if (remote || !copied) {
154
- const osc52Copied = emitOsc52(text);
155
- copied = copied || osc52Copied;
57
+ if (!copied) {
58
+ const commands = [];
59
+ if (p === "darwin")
60
+ commands.push(["pbcopy", []]);
61
+ else if (p === "win32")
62
+ commands.push(["clip", []]);
63
+ else {
64
+ if (process.env.TERMUX_VERSION)
65
+ commands.push(["termux-clipboard-set", []]);
66
+ if (process.env.WAYLAND_DISPLAY)
67
+ commands.push(["wl-copy", []]);
68
+ if (process.env.DISPLAY) {
69
+ commands.push(["xclip", ["-selection", "clipboard"]], ["xsel", ["--clipboard", "--input"]]);
70
+ }
71
+ }
72
+ for (const [command, args] of commands) {
73
+ if ((await runClipboardCommand(command, args, { input: text, timeoutMs: 5000 })) !== undefined) {
74
+ copied = true;
75
+ break;
76
+ }
77
+ }
156
78
  }
79
+ if (isRemoteSession())
80
+ copied = emitOsc52(text) || copied;
157
81
  if (!copied) {
158
- throw new Error("Failed to copy to clipboard");
82
+ if (p === "linux") {
83
+ if (process.env.TERMUX_VERSION) {
84
+ throw new Error("Clipboard unavailable: install the Termux:API app and `termux-api` package");
85
+ }
86
+ if (process.env.WAYLAND_DISPLAY) {
87
+ throw new Error("Clipboard unavailable: install `wl-clipboard` (`wl-copy`) or check Wayland access");
88
+ }
89
+ if (process.env.DISPLAY) {
90
+ throw new Error("Clipboard unavailable: install `xclip` or `xsel`, or check X11 access");
91
+ }
92
+ throw new Error("Clipboard unavailable: no Wayland or X11 display detected");
93
+ }
94
+ throw new Error("Clipboard unavailable");
159
95
  }
160
96
  }
161
97
  //# sourceMappingURL=clipboard.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"clipboard.js","sourceRoot":"","sources":["../../src/utils/clipboard.ts"],"names":[],"mappings":"AAAA,OAAO,EAA8C,YAAY,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAC1G,OAAO,EAAE,QAAQ,EAAE,MAAM,IAAI,CAAC;AAC9B,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAQlD,SAAS,kBAAkB,CAAC,OAAmC,EAAQ;IACtE,IAAI,CAAC;QACJ,QAAQ,CAAC,4BAA4B,EAAE,OAAO,CAAC,CAAC;IACjD,CAAC;IAAC,MAAM,CAAC;QACR,QAAQ,CAAC,0BAA0B,EAAE,OAAO,CAAC,CAAC;IAC/C,CAAC;AAAA,CACD;AAED,MAAM,wBAAwB,GAAG,OAAO,CAAC;AAEzC,SAAS,eAAe,CAAC,GAAG,GAAsB,OAAO,CAAC,GAAG,EAAW;IACvE,OAAO,OAAO,CAAC,GAAG,CAAC,cAAc,IAAI,GAAG,CAAC,UAAU,IAAI,GAAG,CAAC,eAAe,CAAC,CAAC;AAAA,CAC5E;AAED,SAAS,SAAS,CAAC,IAAY,EAAW;IACzC,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IACrD,IAAI,OAAO,CAAC,MAAM,GAAG,wBAAwB,EAAE,CAAC;QAC/C,OAAO,KAAK,CAAC;IACd,CAAC;IACD,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,aAAa,OAAO,MAAM,CAAC,CAAC;IACjD,OAAO,IAAI,CAAC;AAAA,CACZ;AAID,MAAM,sBAAsB,GAA0C;IACrE,Q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,CAAC;4BACf,CAAC;wBACF,CAAC;wBAAC,MAAM,CAAC;4BACR,IAAI,aAAa,EAAE,CAAC;gCACnB,kBAAkB,CAAC,OAAO,CAAC,CAAC;gCAC5B,MAAM,GAAG,IAAI,CAAC;4BACf,CAAC;wBACF,CAAC;oBACF,CAAC;yBAAM,IAAI,aAAa,EAAE,CAAC;wBAC1B,kBAAkB,CAAC,OAAO,CAAC,CAAC;wBAC5B,MAAM,GAAG,IAAI,CAAC;oBACf,CAAC;gBACF,CAAC;YACF,CAAC;QACF,CAAC;QAAC,MAAM,CAAC;YACR,mCAAmC;QACpC,CAAC;IACF,CAAC;IAED,IAAI,MAAM,IAAI,CAAC,MAAM,EAAE,CAAC;QACvB,MAAM,WAAW,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC;QACpC,MAAM,GAAG,MAAM,IAAI,WAAW,CAAC;IAChC,CAAC;IAED,IAAI,CAAC,MAAM,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;IAChD,CAAC;AAAA,CACD","sourcesContent":["import { type ExecFileSyncOptionsWithStringEncoding, execFileSync, execSync, spawn } from \"child_process\";\nimport { platform } from \"os\";\nimport { isWaylandSession } from \"./clipboard-image.ts\";\nimport { clipboard } from \"./clipboard-native.ts\";\n\ntype NativeClipboardExecOptions = {\n\tinput: string;\n\ttimeout: number;\n\tstdio: [\"pipe\", \"ignore\", \"ignore\"];\n};\n\nfunction copyToX11Clipboard(options: NativeClipboardExecOptions): void {\n\ttry {\n\t\texecSync(\"xclip -selection clipboard\", options);\n\t} catch {\n\t\texecSync(\"xsel --clipboard --input\", options);\n\t}\n}\n\nconst MAX_OSC52_ENCODED_LENGTH = 100_000;\n\nfunction isRemoteSession(env: NodeJS.ProcessEnv = process.env): boolean {\n\treturn Boolean(env.SSH_CONNECTION || env.SSH_CLIENT || env.MOSH_CONNECTION);\n}\n\nfunction emitOsc52(text: string): boolean {\n\tconst encoded = Buffer.from(text).toString(\"base64\");\n\tif (encoded.length > MAX_OSC52_ENCODED_LENGTH) {\n\t\treturn false;\n\t}\n\tprocess.stdout.write(`\\x1b]52;c;${encoded}\\x07`);\n\treturn true;\n}\n\ntype ClipboardReadResult = { ok: true; text: string | null } | { ok: false };\n\nconst READ_CLIPBOARD_OPTIONS: ExecFileSyncOptionsWithStringEncoding = {\n\tencoding: \"utf8\",\n\tmaxBuffer: 50 * 1024 * 1024,\n\ttimeout: 5000,\n};\n\nfunction readWaylandClipboardText(): ClipboardReadResult {\n\ttry {\n\t\tconst text = execFileSync(\"wl-paste\", [\"--no-newline\", \"--type\", \"text\"], READ_CLIPBOARD_OPTIONS);\n\t\treturn { ok: true, text: text || null };\n\t} catch {\n\t\treturn { ok: false };\n\t}\n}\n\n/** Read plain text from the system clipboard. */\nexport async function readClipboardText(): Promise<string | null> {\n\tif (platform() === \"linux\" && isWaylandSession() && process.env.WAYLAND_DISPLAY) {\n\t\tconst result = readWaylandClipboardText();\n\t\tif (result.ok) {\n\t\t\treturn result.text;\n\t\t}\n\t}\n\n\tif (!clipboard) {\n\t\treturn null;\n\t}\n\n\ttry {\n\t\tconst text = await clipboard.getText();\n\t\treturn text || null;\n\t} catch {\n\t\treturn null;\n\t}\n}\n\nexport async function copyToClipboard(text: string): Promise<void> {\n\tlet copied = false;\n\n\tconst p = platform();\n\n\t// Prefer direct clipboard writes. Emitting OSC 52 first can make terminals\n\t// write the same native clipboard concurrently with the addon, and very large\n\t// OSC 52 payloads can desynchronize terminal rendering.\n\t//\n\t// On Linux, skip the native addon. The underlying `clipboard-rs` crate is\n\t// X11-only and does not retain selection ownership after `set_text`\n\t// resolves, so on Wayland-only compositors (Hyprland, Niri, ...) and even\n\t// some X11 sessions the call resolves successfully without populating the\n\t// clipboard. The platform tools below (wl-copy, xclip, xsel) properly\n\t// daemonize and keep ownership.\n\ttry {\n\t\tif (clipboard && p !== \"linux\") {\n\t\t\tawait clipboard.setText(text);\n\t\t\tcopied = true;\n\t\t}\n\t} catch {\n\t\t// Fall through to platform-specific clipboard tools.\n\t}\n\n\tconst remote = isRemoteSession();\n\tif (copied && !remote) {\n\t\treturn;\n\t}\n\n\tconst options: NativeClipboardExecOptions = { input: text, timeout: 5000, stdio: [\"pipe\", \"ignore\", \"ignore\"] };\n\n\tif (!copied) {\n\t\ttry {\n\t\t\tif (p === \"darwin\") {\n\t\t\t\texecSync(\"pbcopy\", options);\n\t\t\t\tcopied = true;\n\t\t\t} else if (p === \"win32\") {\n\t\t\t\texecSync(\"clip\", options);\n\t\t\t\tcopied = true;\n\t\t\t} else {\n\t\t\t\t// Linux. Try Termux, Wayland, or X11 clipboard tools.\n\t\t\t\tif (process.env.TERMUX_VERSION) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\texecSync(\"termux-clipboard-set\", options);\n\t\t\t\t\t\tcopied = true;\n\t\t\t\t\t} catch {\n\t\t\t\t\t\t// Fall back to Wayland or X11 tools.\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (!copied) {\n\t\t\t\t\tconst hasWaylandDisplay = Boolean(process.env.WAYLAND_DISPLAY);\n\t\t\t\t\tconst hasX11Display = Boolean(process.env.DISPLAY);\n\t\t\t\t\tconst isWayland = isWaylandSession();\n\t\t\t\t\tif (isWayland && hasWaylandDisplay) {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t// Verify wl-copy exists (spawn errors are async and won't be caught)\n\t\t\t\t\t\t\texecSync(\"which wl-copy\", { stdio: \"ignore\" });\n\t\t\t\t\t\t\t// wl-copy with execSync hangs due to fork behavior; use spawn instead.\n\t\t\t\t\t\t\t// Await the exit code and only claim success on a clean exit, so a\n\t\t\t\t\t\t\t// failed wl-copy falls through to the xclip/OSC 52 fallbacks.\n\t\t\t\t\t\t\tconst wlCopyExit = await new Promise<number>((resolve) => {\n\t\t\t\t\t\t\t\tconst proc = spawn(\"wl-copy\", [], { stdio: [\"pipe\", \"ignore\", \"ignore\"] });\n\t\t\t\t\t\t\t\tproc.on(\"error\", () => resolve(1));\n\t\t\t\t\t\t\t\tproc.on(\"close\", (code) => resolve(code ?? 1));\n\t\t\t\t\t\t\t\tproc.stdin.on(\"error\", () => {\n\t\t\t\t\t\t\t\t\t// Ignore EPIPE errors if wl-copy exits early\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\tproc.stdin.write(text);\n\t\t\t\t\t\t\t\tproc.stdin.end();\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\tif (wlCopyExit === 0) {\n\t\t\t\t\t\t\t\tcopied = true;\n\t\t\t\t\t\t\t} else if (hasX11Display) {\n\t\t\t\t\t\t\t\tcopyToX11Clipboard(options);\n\t\t\t\t\t\t\t\tcopied = true;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\tif (hasX11Display) {\n\t\t\t\t\t\t\t\tcopyToX11Clipboard(options);\n\t\t\t\t\t\t\t\tcopied = true;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (hasX11Display) {\n\t\t\t\t\t\tcopyToX11Clipboard(options);\n\t\t\t\t\t\tcopied = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t} catch {\n\t\t\t// Fall through to OSC 52 fallback.\n\t\t}\n\t}\n\n\tif (remote || !copied) {\n\t\tconst osc52Copied = emitOsc52(text);\n\t\tcopied = copied || osc52Copied;\n\t}\n\n\tif (!copied) {\n\t\tthrow new Error(\"Failed to copy to clipboard\");\n\t}\n}\n"]}
1
+ {"version":3,"file":"clipboard.js","sourceRoot":"","sources":["../../src/utils/clipboard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAE7D,MAAM,wBAAwB,GAAG,OAAO,CAAC;AAEzC,SAAS,eAAe,CAAC,GAAG,G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K,CAAC,2DAA2D,CAAC,CAAC;QAC9E,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC;IAC1C,CAAC;AAAA,CACD","sourcesContent":["import { platform } from \"node:os\";\nimport { getNativeClipboard } from \"@earendil-works/pi-tui\";\nimport { runClipboardCommand } from \"./clipboard-command.ts\";\n\nconst MAX_OSC52_ENCODED_LENGTH = 100_000;\n\nfunction isRemoteSession(env: NodeJS.ProcessEnv = process.env): boolean {\n\treturn Boolean(env.SSH_CONNECTION || env.SSH_CLIENT || env.MOSH_CONNECTION);\n}\n\nfunction emitOsc52(text: string): boolean {\n\tconst encoded = Buffer.from(text).toString(\"base64\");\n\tif (encoded.length > MAX_OSC52_ENCODED_LENGTH) {\n\t\treturn false;\n\t}\n\tprocess.stdout.write(`\\x1b]52;c;${encoded}\\x07`);\n\treturn true;\n}\n\n/** Read plain text from the system clipboard. */\nexport async function readClipboardText(): Promise<string | null> {\n\tif (platform() === \"linux\") {\n\t\tconst commands: [string, string[]][] = [];\n\t\tif (process.env.TERMUX_VERSION) commands.push([\"termux-clipboard-get\", []]);\n\t\tif (process.env.WAYLAND_DISPLAY) commands.push([\"wl-paste\", [\"--no-newline\", \"--type\", \"text\"]]);\n\t\tif (process.env.DISPLAY) {\n\t\t\tcommands.push([\"xclip\", [\"-selection\", \"clipboard\", \"-out\"]], [\"xsel\", [\"--clipboard\", \"--output\"]]);\n\t\t}\n\t\tfor (const [command, args] of commands) {\n\t\t\tconst bytes = await runClipboardCommand(command, args, { timeoutMs: 5000 });\n\t\t\tif (bytes !== undefined) return bytes.toString(\"utf8\") || null;\n\t\t}\n\t}\n\ttry {\n\t\treturn (await getNativeClipboard()?.getText()) || null;\n\t} catch {\n\t\treturn null;\n\t}\n}\n\nexport async function copyToClipboard(text: string): Promise<void> {\n\tconst p = platform();\n\tlet copied = false;\n\t// Direct writes precede OSC 52 so the terminal cannot race the native writer.\n\t// Linux tools retain clipboard selection ownership after this call returns.\n\tif (p !== \"linux\") {\n\t\ttry {\n\t\t\tconst clipboard = getNativeClipboard();\n\t\t\tif (clipboard?.setText) {\n\t\t\t\tawait clipboard.setText(text);\n\t\t\t\tcopied = true;\n\t\t\t}\n\t\t} catch {\n\t\t\t// Try platform commands next.\n\t\t}\n\t}\n\tif (!copied) {\n\t\tconst commands: [string, string[]][] = [];\n\t\tif (p === \"darwin\") commands.push([\"pbcopy\", []]);\n\t\telse if (p === \"win32\") commands.push([\"clip\", []]);\n\t\telse {\n\t\t\tif (process.env.TERMUX_VERSION) commands.push([\"termux-clipboard-set\", []]);\n\t\t\tif (process.env.WAYLAND_DISPLAY) commands.push([\"wl-copy\", []]);\n\t\t\tif (process.env.DISPLAY) {\n\t\t\t\tcommands.push([\"xclip\", [\"-selection\", \"clipboard\"]], [\"xsel\", [\"--clipboard\", \"--input\"]]);\n\t\t\t}\n\t\t}\n\t\tfor (const [command, args] of commands) {\n\t\t\tif ((await runClipboardCommand(command, args, { input: text, timeoutMs: 5000 })) !== undefined) {\n\t\t\t\tcopied = true;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\tif (isRemoteSession()) copied = emitOsc52(text) || copied;\n\tif (!copied) {\n\t\tif (p === \"linux\") {\n\t\t\tif (process.env.TERMUX_VERSION) {\n\t\t\t\tthrow new Error(\"Clipboard unavailable: install the Termux:API app and `termux-api` package\");\n\t\t\t}\n\t\t\tif (process.env.WAYLAND_DISPLAY) {\n\t\t\t\tthrow new Error(\"Clipboard unavailable: install `wl-clipboard` (`wl-copy`) or check Wayland access\");\n\t\t\t}\n\t\t\tif (process.env.DISPLAY) {\n\t\t\t\tthrow new Error(\"Clipboard unavailable: install `xclip` or `xsel`, or check X11 access\");\n\t\t\t}\n\t\t\tthrow new Error(\"Clipboard unavailable: no Wayland or X11 display detected\");\n\t\t}\n\t\tthrow new Error(\"Clipboard unavailable\");\n\t}\n}\n"]}
@@ -0,0 +1,7 @@
1
+ interface ZipEntry {
2
+ name: string;
3
+ data: string | Uint8Array;
4
+ }
5
+ export declare function writeZipArchive(filePath: string, entries: readonly ZipEntry[]): Promise<void>;
6
+ export {};
7
+ //# sourceMappingURL=zip.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"zip.d.ts","sourceRoot":"","sources":["../../src/utils/zip.ts"],"names":[],"mappings":"AAGA,UAAU,QAAQ;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,GAAG,UAAU,CAAC;CAC1B;AA+DD,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,QAAQ,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAE7F","sourcesContent":["import { writeFile } from \"node:fs/promises\";\nimport { crc32, deflateRawSync } from \"node:zlib\";\n\ninterface ZipEntry {\n\tname: string;\n\tdata: string | Uint8Array;\n}\n\nfunction dosDateTime(date: Date): { time: number; day: number } {\n\treturn {\n\t\ttime: (date.getHours() << 11) | (date.getMinutes() << 5) | (date.getSeconds() >> 1),\n\t\tday: ((Math.max(1980, date.getFullYear()) - 1980) << 9) | ((date.getMonth() + 1) << 5) | date.getDate(),\n\t};\n}\n\n/** Create the small, classic ZIP archives used by bug reports. */\nfunction createZipArchive(entries: readonly ZipEntry[]): Buffer {\n\tconst files: Buffer[] = [];\n\tconst directory: Buffer[] = [];\n\tconst { time, day } = dosDateTime(new Date());\n\tlet offset = 0;\n\n\tfor (const entry of entries) {\n\t\tconst name = Buffer.from(entry.name);\n\t\tconst data = typeof entry.data === \"string\" ? Buffer.from(entry.data) : Buffer.from(entry.data);\n\t\tconst compressed = deflateRawSync(data);\n\t\tconst checksum = crc32(data);\n\n\t\tconst local = Buffer.alloc(30);\n\t\tlocal.writeUInt32LE(0x04034b50, 0);\n\t\tlocal.writeUInt16LE(20, 4);\n\t\tlocal.writeUInt16LE(0x0800, 6);\n\t\tlocal.writeUInt16LE(8, 8);\n\t\tlocal.writeUInt16LE(time, 10);\n\t\tlocal.writeUInt16LE(day, 12);\n\t\tlocal.writeUInt32LE(checksum, 14);\n\t\tlocal.writeUInt32LE(compressed.length, 18);\n\t\tlocal.writeUInt32LE(data.length, 22);\n\t\tlocal.writeUInt16LE(name.length, 26);\n\n\t\tconst central = Buffer.alloc(46);\n\t\tcentral.writeUInt32LE(0x02014b50, 0);\n\t\tcentral.writeUInt16LE(20, 4);\n\t\tcentral.writeUInt16LE(20, 6);\n\t\tcentral.writeUInt16LE(0x0800, 8);\n\t\tcentral.writeUInt16LE(8, 10);\n\t\tcentral.writeUInt16LE(time, 12);\n\t\tcentral.writeUInt16LE(day, 14);\n\t\tcentral.writeUInt32LE(checksum, 16);\n\t\tcentral.writeUInt32LE(compressed.length, 20);\n\t\tcentral.writeUInt32LE(data.length, 24);\n\t\tcentral.writeUInt16LE(name.length, 28);\n\t\tcentral.writeUInt32LE(offset, 42);\n\n\t\tfiles.push(local, name, compressed);\n\t\tdirectory.push(central, name);\n\t\toffset += local.length + name.length + compressed.length;\n\t}\n\n\tconst centralDirectory = Buffer.concat(directory);\n\tconst end = Buffer.alloc(22);\n\tend.writeUInt32LE(0x06054b50, 0);\n\tend.writeUInt16LE(entries.length, 8);\n\tend.writeUInt16LE(entries.length, 10);\n\tend.writeUInt32LE(centralDirectory.length, 12);\n\tend.writeUInt32LE(offset, 16);\n\treturn Buffer.concat([...files, centralDirectory, end]);\n}\n\nexport function writeZipArchive(filePath: string, entries: readonly ZipEntry[]): Promise<void> {\n\treturn writeFile(filePath, createZipArchive(entries));\n}\n"]}
@@ -0,0 +1,60 @@
1
+ import { writeFile } from "node:fs/promises";
2
+ import { crc32, deflateRawSync } from "node:zlib";
3
+ function dosDateTime(date) {
4
+ return {
5
+ time: (date.getHours() << 11) | (date.getMinutes() << 5) | (date.getSeconds() >> 1),
6
+ day: ((Math.max(1980, date.getFullYear()) - 1980) << 9) | ((date.getMonth() + 1) << 5) | date.getDate(),
7
+ };
8
+ }
9
+ /** Create the small, classic ZIP archives used by bug reports. */
10
+ function createZipArchive(entries) {
11
+ const files = [];
12
+ const directory = [];
13
+ const { time, day } = dosDateTime(new Date());
14
+ let offset = 0;
15
+ for (const entry of entries) {
16
+ const name = Buffer.from(entry.name);
17
+ const data = typeof entry.data === "string" ? Buffer.from(entry.data) : Buffer.from(entry.data);
18
+ const compressed = deflateRawSync(data);
19
+ const checksum = crc32(data);
20
+ const local = Buffer.alloc(30);
21
+ local.writeUInt32LE(0x04034b50, 0);
22
+ local.writeUInt16LE(20, 4);
23
+ local.writeUInt16LE(0x0800, 6);
24
+ local.writeUInt16LE(8, 8);
25
+ local.writeUInt16LE(time, 10);
26
+ local.writeUInt16LE(day, 12);
27
+ local.writeUInt32LE(checksum, 14);
28
+ local.writeUInt32LE(compressed.length, 18);
29
+ local.writeUInt32LE(data.length, 22);
30
+ local.writeUInt16LE(name.length, 26);
31
+ const central = Buffer.alloc(46);
32
+ central.writeUInt32LE(0x02014b50, 0);
33
+ central.writeUInt16LE(20, 4);
34
+ central.writeUInt16LE(20, 6);
35
+ central.writeUInt16LE(0x0800, 8);
36
+ central.writeUInt16LE(8, 10);
37
+ central.writeUInt16LE(time, 12);
38
+ central.writeUInt16LE(day, 14);
39
+ central.writeUInt32LE(checksum, 16);
40
+ central.writeUInt32LE(compressed.length, 20);
41
+ central.writeUInt32LE(data.length, 24);
42
+ central.writeUInt16LE(name.length, 28);
43
+ central.writeUInt32LE(offset, 42);
44
+ files.push(local, name, compressed);
45
+ directory.push(central, name);
46
+ offset += local.length + name.length + compressed.length;
47
+ }
48
+ const centralDirectory = Buffer.concat(directory);
49
+ const end = Buffer.alloc(22);
50
+ end.writeUInt32LE(0x06054b50, 0);
51
+ end.writeUInt16LE(entries.length, 8);
52
+ end.writeUInt16LE(entries.length, 10);
53
+ end.writeUInt32LE(centralDirectory.length, 12);
54
+ end.writeUInt32LE(offset, 16);
55
+ return Buffer.concat([...files, centralDirectory, end]);
56
+ }
57
+ export function writeZipArchive(filePath, entries) {
58
+ return writeFile(filePath, createZipArchive(entries));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AC,MAAM,CAAC,CAAC,GAAG,KAAK,EAAE,gBAAgB,EAAE,GAAG,CAAC,CAAC,CAAC;AAAA,CACxD;AAED,MAAM,UAAU,eAAe,CAAC,QAAgB,EAAE,OAA4B,EAAiB;IAC9F,OAAO,SAAS,CAAC,QAAQ,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAAC;AAAA,CACtD","sourcesContent":["import { writeFile } from \"node:fs/promises\";\nimport { crc32, deflateRawSync } from \"node:zlib\";\n\ninterface ZipEntry {\n\tname: string;\n\tdata: string | Uint8Array;\n}\n\nfunction dosDateTime(date: Date): { time: number; day: number } {\n\treturn {\n\t\ttime: (date.getHours() << 11) | (date.getMinutes() << 5) | (date.getSeconds() >> 1),\n\t\tday: ((Math.max(1980, date.getFullYear()) - 1980) << 9) | ((date.getMonth() + 1) << 5) | date.getDate(),\n\t};\n}\n\n/** Create the small, classic ZIP archives used by bug reports. */\nfunction createZipArchive(entries: readonly ZipEntry[]): Buffer {\n\tconst files: Buffer[] = [];\n\tconst directory: Buffer[] = [];\n\tconst { time, day } = dosDateTime(new Date());\n\tlet offset = 0;\n\n\tfor (const entry of entries) {\n\t\tconst name = Buffer.from(entry.name);\n\t\tconst data = typeof entry.data === \"string\" ? Buffer.from(entry.data) : Buffer.from(entry.data);\n\t\tconst compressed = deflateRawSync(data);\n\t\tconst checksum = crc32(data);\n\n\t\tconst local = Buffer.alloc(30);\n\t\tlocal.writeUInt32LE(0x04034b50, 0);\n\t\tlocal.writeUInt16LE(20, 4);\n\t\tlocal.writeUInt16LE(0x0800, 6);\n\t\tlocal.writeUInt16LE(8, 8);\n\t\tlocal.writeUInt16LE(time, 10);\n\t\tlocal.writeUInt16LE(day, 12);\n\t\tlocal.writeUInt32LE(checksum, 14);\n\t\tlocal.writeUInt32LE(compressed.length, 18);\n\t\tlocal.writeUInt32LE(data.length, 22);\n\t\tlocal.writeUInt16LE(name.length, 26);\n\n\t\tconst central = Buffer.alloc(46);\n\t\tcentral.writeUInt32LE(0x02014b50, 0);\n\t\tcentral.writeUInt16LE(20, 4);\n\t\tcentral.writeUInt16LE(20, 6);\n\t\tcentral.writeUInt16LE(0x0800, 8);\n\t\tcentral.writeUInt16LE(8, 10);\n\t\tcentral.writeUInt16LE(time, 12);\n\t\tcentral.writeUInt16LE(day, 14);\n\t\tcentral.writeUInt32LE(checksum, 16);\n\t\tcentral.writeUInt32LE(compressed.length, 20);\n\t\tcentral.writeUInt32LE(data.length, 24);\n\t\tcentral.writeUInt16LE(name.length, 28);\n\t\tcentral.writeUInt32LE(offset, 42);\n\n\t\tfiles.push(local, name, compressed);\n\t\tdirectory.push(central, name);\n\t\toffset += local.length + name.length + compressed.length;\n\t}\n\n\tconst centralDirectory = Buffer.concat(directory);\n\tconst end = Buffer.alloc(22);\n\tend.writeUInt32LE(0x06054b50, 0);\n\tend.writeUInt16LE(entries.length, 8);\n\tend.writeUInt16LE(entries.length, 10);\n\tend.writeUInt32LE(centralDirectory.length, 12);\n\tend.writeUInt32LE(offset, 16);\n\treturn Buffer.concat([...files, centralDirectory, end]);\n}\n\nexport function writeZipArchive(filePath: string, entries: readonly ZipEntry[]): Promise<void> {\n\treturn writeFile(filePath, createZipArchive(entries));\n}\n"]}
@@ -2,12 +2,12 @@
2
2
 
3
3
  LLMs have limited context windows. When conversations grow too long, Pi uses compaction to summarize older content while preserving recent work. This page covers both auto-compaction and branch summarization.
4
4
 
5
- **Source files** ([pi-mono](https://github.com/earendil-works/pi-mono)):
6
- - [`packages/coding-agent/src/core/compaction/compaction.ts`](https://github.com/earendil-works/pi-mono/blob/main/packages/coding-agent/src/core/compaction/compaction.ts) - Auto-compaction logic
7
- - [`packages/coding-agent/src/core/compaction/branch-summarization.ts`](https://github.com/earendil-works/pi-mono/blob/main/packages/coding-agent/src/core/compaction/branch-summarization.ts) - Branch summarization
8
- - [`packages/coding-agent/src/core/compaction/utils.ts`](https://github.com/earendil-works/pi-mono/blob/main/packages/coding-agent/src/core/compaction/utils.ts) - Shared utilities (file tracking, serialization)
9
- - [`packages/coding-agent/src/core/session-manager.ts`](https://github.com/earendil-works/pi-mono/blob/main/packages/coding-agent/src/core/session-manager.ts) - Entry types (`CompactionEntry`, `BranchSummaryEntry`)
10
- - [`packages/coding-agent/src/core/extensions/types.ts`](https://github.com/earendil-works/pi-mono/blob/main/packages/coding-agent/src/core/extensions/types.ts) - Extension event types
5
+ **Source files** ([pi](https://github.com/earendil-works/pi)):
6
+ - [`packages/coding-agent/src/core/compaction/compaction.ts`](https://github.com/earendil-works/pi/blob/main/packages/coding-agent/src/core/compaction/compaction.ts) - Auto-compaction logic
7
+ - [`packages/coding-agent/src/core/compaction/branch-summarization.ts`](https://github.com/earendil-works/pi/blob/main/packages/coding-agent/src/core/compaction/branch-summarization.ts) - Branch summarization
8
+ - [`packages/coding-agent/src/core/compaction/utils.ts`](https://github.com/earendil-works/pi/blob/main/packages/coding-agent/src/core/compaction/utils.ts) - Shared utilities (file tracking, serialization)
9
+ - [`packages/coding-agent/src/core/session-manager.ts`](https://github.com/earendil-works/pi/blob/main/packages/coding-agent/src/core/session-manager.ts) - Entry types (`CompactionEntry`, `BranchSummaryEntry`)
10
+ - [`packages/coding-agent/src/core/extensions/types.ts`](https://github.com/earendil-works/pi/blob/main/packages/coding-agent/src/core/extensions/types.ts) - Extension event types
11
11
 
12
12
  For TypeScript definitions in your project, inspect `node_modules/@earendil-works/pi-coding-agent/dist/`.
13
13
 
@@ -120,7 +120,7 @@ Never cut at tool results (they must stay with their tool call).
120
120
 
121
121
  ### CompactionEntry Structure
122
122
 
123
- Defined in [`session-manager.ts`](https://github.com/earendil-works/pi-mono/blob/main/packages/coding-agent/src/core/session-manager.ts):
123
+ Defined in [`session-manager.ts`](https://github.com/earendil-works/pi/blob/main/packages/coding-agent/src/core/session-manager.ts):
124
124
 
125
125
  ```typescript
126
126
  interface CompactionEntry<T = unknown> {
@@ -145,7 +145,7 @@ interface CompactionDetails {
145
145
 
146
146
  Extensions can store any JSON-serializable data in `details`. The default compaction tracks file operations, but custom extension implementations can use their own structure. Generated and extension-provided summaries store their LLM `usage` when available so session totals include summarization work.
147
147
 
148
- See [`prepareCompaction()`](https://github.com/earendil-works/pi-mono/blob/main/packages/coding-agent/src/core/compaction/compaction.ts) and [`compact()`](https://github.com/earendil-works/pi-mono/blob/main/packages/coding-agent/src/core/compaction/compaction.ts) for the implementation. For direct programmatic summarization, `generateSummary()` returns the summary text and `generateSummaryWithUsage()` returns `{ text, usage }`.
148
+ See [`prepareCompaction()`](https://github.com/earendil-works/pi/blob/main/packages/coding-agent/src/core/compaction/compaction.ts) and [`compact()`](https://github.com/earendil-works/pi/blob/main/packages/coding-agent/src/core/compaction/compaction.ts) for the implementation. For direct programmatic summarization, `generateSummary()` returns the summary text and `generateSummaryWithUsage()` returns `{ text, usage }`.
149
149
 
150
150
  ## Branch Summarization
151
151
 
@@ -188,7 +188,7 @@ This means file tracking accumulates across multiple compactions or nested branc
188
188
 
189
189
  ### BranchSummaryEntry Structure
190
190
 
191
- Defined in [`session-manager.ts`](https://github.com/earendil-works/pi-mono/blob/main/packages/coding-agent/src/core/session-manager.ts):
191
+ Defined in [`session-manager.ts`](https://github.com/earendil-works/pi/blob/main/packages/coding-agent/src/core/session-manager.ts):
192
192
 
193
193
  ```typescript
194
194
  interface BranchSummaryEntry<T = unknown> {
@@ -212,7 +212,7 @@ interface BranchSummaryDetails {
212
212
 
213
213
  Same as compaction, extensions can store custom data in `details`.
214
214
 
215
- See [`collectEntriesForBranchSummary()`](https://github.com/earendil-works/pi-mono/blob/main/packages/coding-agent/src/core/compaction/branch-summarization.ts), [`prepareBranchEntries()`](https://github.com/earendil-works/pi-mono/blob/main/packages/coding-agent/src/core/compaction/branch-summarization.ts), and [`generateBranchSummary()`](https://github.com/earendil-works/pi-mono/blob/main/packages/coding-agent/src/core/compaction/branch-summarization.ts) for the implementation.
215
+ See [`collectEntriesForBranchSummary()`](https://github.com/earendil-works/pi/blob/main/packages/coding-agent/src/core/compaction/branch-summarization.ts), [`prepareBranchEntries()`](https://github.com/earendil-works/pi/blob/main/packages/coding-agent/src/core/compaction/branch-summarization.ts), and [`generateBranchSummary()`](https://github.com/earendil-works/pi/blob/main/packages/coding-agent/src/core/compaction/branch-summarization.ts) for the implementation.
216
216
 
217
217
  ## Summary Format
218
218
 
@@ -256,7 +256,7 @@ path/to/changed.ts
256
256
 
257
257
  ### Message Serialization
258
258
 
259
- Before summarization, messages are serialized to text via [`serializeConversation()`](https://github.com/earendil-works/pi-mono/blob/main/packages/coding-agent/src/core/compaction/utils.ts):
259
+ Before summarization, messages are serialized to text via [`serializeConversation()`](https://github.com/earendil-works/pi/blob/main/packages/coding-agent/src/core/compaction/utils.ts):
260
260
 
261
261
  ```
262
262
  [User]: What they said
@@ -272,7 +272,7 @@ Tool results are truncated to 2000 characters during serialization. Content beyo
272
272
 
273
273
  ## Custom Summarization via Extensions
274
274
 
275
- Extensions can intercept and customize both compaction and branch summarization. See [`extensions/types.ts`](https://github.com/earendil-works/pi-mono/blob/main/packages/coding-agent/src/core/extensions/types.ts) for event type definitions.
275
+ Extensions can intercept and customize both compaction and branch summarization. See [`extensions/types.ts`](https://github.com/earendil-works/pi/blob/main/packages/coding-agent/src/core/extensions/types.ts) for event type definitions.
276
276
 
277
277
  ### session_before_compact
278
278
 
@@ -288,7 +288,7 @@ pi.on("session_before_compact", async (event, ctx) => {
288
288
  // preparation.fileOps - extracted file operations
289
289
  // preparation.tokensBefore - context tokens before compaction
290
290
  // preparation.firstKeptEntryId - where kept messages start
291
- // preparation.settings - compaction settings
291
+ // preparation.settings - effective settings after applying model overrides
292
292
 
293
293
  // branchEntries - all entries on current branch (for custom state)
294
294
  // reason - "manual" (/compact), "threshold", or "overflow"
@@ -416,3 +416,29 @@ Configure compaction in `~/.pi/agent/settings.json` or `<project-dir>/.pi/settin
416
416
  | `keepRecentTokens` | `20000` | Recent tokens to keep (not summarized) |
417
417
 
418
418
  Disable auto-compaction with `"enabled": false`. You can still compact manually with `/compact`.
419
+
420
+ ### Per-model overrides
421
+
422
+ Use `compaction.modelOverrides` to tune token budgets for different models:
423
+
424
+ ```json
425
+ {
426
+ "compaction": {
427
+ "reserveTokens": 16384,
428
+ "keepRecentTokens": 20000,
429
+ "modelOverrides": {
430
+ "some-provider/big-model": {
431
+ "reserveTokens": 400000
432
+ }
433
+ }
434
+ }
435
+ }
436
+ ```
437
+
438
+ For a model with a 1M context window, this override triggers compaction above 600K tokens and keeps the ordinary 20000 recent tokens. Other models retain the ordinary 16384-token reserve. `reserveTokens` also influences summarization output limits, capped by the model's maximum output tokens; it is not solely a trigger threshold.
439
+
440
+ Keys are exact, case-sensitive `provider/modelId` values, including any slashes within the model ID. Each `reserveTokens` and `keepRecentTokens` value falls back independently from the model override to the ordinary setting to the built-in default. Values must be non-negative safe integers. Invalid values in the matching model override produce an error when read; only omitted fields fall back to the ordinary setting. Model override entries must be objects. Invalid ordinary token settings produce an error when read, even if the active model has a valid override. Only omitted ordinary values use built-in defaults. `enabled` remains global, not model-specific.
441
+
442
+ These resolved values are used for manual compaction, all automatic threshold checks, overflow recovery, and extension-visible `preparation.settings`. Model switches affect subsequent checks and compactions without changing ordinary settings. Compaction already in progress uses the model and settings captured for that operation. Branch summarization settings are unaffected.
443
+
444
+ Overrides work in both global and project settings. The files merge recursively before lookup, so a global model-specific value beats a project-wide fallback; a project must override that model entry to change it. See [settings.md](settings.md#per-model-compaction-overrides) for details.