nolo-cli 0.143.0-alpha.1 → 0.145.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (455) hide show
  1. package/README.md +2 -0
  2. package/{_executeModel-QK43QR2R.js → _executeModel-M3FASQ2Z.js} +18 -17
  3. package/{agentDeleteCommand-SE4WUIRR.js → agentDeleteCommand-K7GCEEVS.js} +10 -9
  4. package/{agentEmailCommands-LW5JMYH2.js → agentEmailCommands-MNXRO36L.js} +24 -23
  5. package/{agentListCommands-LGZG2OQR.js → agentListCommands-KMZR6VVM.js} +12 -11
  6. package/{agentMachineCommands-BNOXYSPZ.js → agentMachineCommands-75TIBYDY.js} +10 -9
  7. package/{agentProviderCommands-AOG3OZJA.js → agentProviderCommands-TWB6E5WD.js} +1 -1
  8. package/{agentRecordCommands-W5ZXPHZV.js → agentRecordCommands-RDO5L3N4.js} +23 -22
  9. package/{agentRunCommand-VRLCL57M.js → agentRunCommand-FVJJPL27.js} +23 -22
  10. package/{agentRuntimeLocal-VOQ3UYZB.js → agentRuntimeLocal-DAK7RCER.js} +8 -7
  11. package/{agentSlice-4AK24F5F.js → agentSlice-6MRJR2BJ.js} +1 -1
  12. package/{appDeleteCommands-XWAIUHTN.js → appDeleteCommands-JMMXK3XT.js} +11 -10
  13. package/{appDeployCommands-CBJJCUMG.js → appDeployCommands-JFU6GALI.js} +11 -10
  14. package/{appDeployStatusCommands-LTTZTJQS.js → appDeployStatusCommands-AXTZ4GAN.js} +11 -10
  15. package/{appGetCommands-QHUB7MFF.js → appGetCommands-CR2W3DCM.js} +11 -10
  16. package/{appListCommands-HINIDJE7.js → appListCommands-2TV6P3EU.js} +11 -10
  17. package/{authCommand-LARLQ3GC.js → authCommand-UBJ4EWYZ.js} +6 -6
  18. package/{authCommands-GBIFZWD3.js → authCommands-H6WKKCRW.js} +1 -1
  19. package/{builtinSkillRegistry-AFPSTTAU.js → builtinSkillRegistry-ZMF6YGNO.js} +4 -3
  20. package/{chatQueueReduxAdapter-KIQ3FQ62.js → chatQueueReduxAdapter-CDOHVTSE.js} +2 -2
  21. package/{chromeCommands-NKU3OWKH.js → chromeCommands-2N6MEWRU.js} +94 -23
  22. package/{chromeOpsCommands-OQDJGD4Y.js → chromeOpsCommands-IXRLN57H.js} +4 -3
  23. package/{chunk-7MUSNQ6E.js → chunk-27ONFIEY.js} +20 -2
  24. package/{chunk-OZ6V53WV.js → chunk-2EE5UD3N.js} +1 -1
  25. package/{chunk-44QZPYLI.js → chunk-2SYTUTLI.js} +92 -20
  26. package/{chunk-DID5AVGT.js → chunk-2TKVOEQF.js} +11 -10
  27. package/chunk-5J3PYNUP.js +255 -0
  28. package/{chunk-OUOJE2P2.js → chunk-5XYFIDFU.js} +5 -5
  29. package/{chunk-WTUVMKSQ.js → chunk-62XHRZG4.js} +2 -2
  30. package/{chunk-WC6A2Q7S.js → chunk-6TPOEJMQ.js} +5 -2
  31. package/{chunk-RRMAZ2BI.js → chunk-7NANRWL4.js} +1 -1
  32. package/{chunk-44F6KKUE.js → chunk-7YAK46ML.js} +3 -3
  33. package/{chunk-NOGH7HCP.js → chunk-A6FNUMCF.js} +47 -6
  34. package/{chunk-OFYHCA6W.js → chunk-AATZZAZE.js} +1 -1
  35. package/{chunk-KUPDS66Q.js → chunk-ANX7Z7Z2.js} +8 -8
  36. package/{chunk-J5H6SUOW.js → chunk-B2XUQXQX.js} +2 -2
  37. package/{chunk-A5MB5RIT.js → chunk-CCOXTK3I.js} +1 -1
  38. package/chunk-GNMAFAIS.js +29 -0
  39. package/{chunk-GZQNKKDG.js → chunk-HKBFZONG.js} +1 -1
  40. package/{chunk-7LLWEG6F.js → chunk-I44MDY73.js} +3 -3
  41. package/{chunk-QDT5T7MK.js → chunk-I4OPU5TK.js} +1 -1
  42. package/{chunk-VPFEPRME.js → chunk-IVZJWTDI.js} +3 -0
  43. package/{chunk-CTGZO35O.js → chunk-JLQKV2ZJ.js} +2 -2
  44. package/{chunk-PQVOC2CZ.js → chunk-M2YBIBBS.js} +1 -1
  45. package/{chunk-ZOI6KA4N.js → chunk-M76SRQ3H.js} +34 -22
  46. package/{chunk-K25DK52L.js → chunk-OKSJZ4UU.js} +21 -223
  47. package/{chunk-U5QTKTZE.js → chunk-P6GMCCAT.js} +1 -1
  48. package/{chunk-L6RB42ZR.js → chunk-QFZM5BFI.js} +3 -3
  49. package/{chunk-GH4MH73K.js → chunk-RHDOQWXZ.js} +175 -17
  50. package/{chunk-M6NK74VP.js → chunk-S5XGT6GB.js} +1 -1
  51. package/{chunk-KUWT3C2P.js → chunk-T76D3OYX.js} +1 -1
  52. package/{chunk-MXRUAINC.js → chunk-UMB7CHAY.js} +3 -3
  53. package/{chunk-VVUSRF5D.js → chunk-VJ4FUWPC.js} +3 -3
  54. package/{chunk-T36EFAW7.js → chunk-VZVTPDPL.js} +3 -3
  55. package/{chunk-AAROOKLX.js → chunk-X2QRZXZH.js} +1 -1
  56. package/{chunk-WYYO2YOL.js → chunk-XNXNHAAP.js} +1 -1
  57. package/{chunk-O6OSWFZQ.js → chunk-XUWRURDF.js} +6 -0
  58. package/{chunk-DOBBRISY.js → chunk-Y6XHJ4JJ.js} +22 -10
  59. package/{chunk-W247GBSQ.js → chunk-YU2THNST.js} +1 -1
  60. package/{chunk-OY5IJI2N.js → chunk-YUNJN43V.js} +23 -3
  61. package/{commandRegistry-DETYXF5I.js → commandRegistry-ZF6YXQWV.js} +76 -65
  62. package/{contentThunks-6QBTPLWT.js → contentThunks-6Y6ATG3A.js} +3 -3
  63. package/{createAgentAutomationAction-TZVIJTZ7.js → createAgentAutomationAction-OQTLA2FC.js} +3 -3
  64. package/{createDialogAction-KTDAEA42.js → createDialogAction-IF5EZMBD.js} +6 -5
  65. package/{createPageAction-4RASVDAU.js → createPageAction-GU766R3L.js} +3 -3
  66. package/{dialogCommands-GY7LRERG.js → dialogCommands-QV7XAX2V.js} +11 -10
  67. package/{dialogSlice-J24APUGG.js → dialogSlice-CVHMDSVV.js} +2 -2
  68. package/{docCreateCommands-T7KII3WP.js → docCreateCommands-FSBANQTO.js} +10 -9
  69. package/{docDeleteCommands-SQ26EFE6.js → docDeleteCommands-4IR4YSGU.js} +11 -10
  70. package/{docReadCommands-I6NA2ZKV.js → docReadCommands-4EYPGUE3.js} +10 -9
  71. package/{docStore-SPOGE7K3.js → docStore-RQOWPNON.js} +1 -1
  72. package/{docUpdateCommands-IG43SZ6U.js → docUpdateCommands-RW2BYLSE.js} +10 -9
  73. package/{handleSendMessageAction-I2IN64DS.js → handleSendMessageAction-UDTPG5WK.js} +4 -3
  74. package/index.js +4 -4
  75. package/{machineCommands-U7VABJPW.js → machineCommands-WBQ4TCPD.js} +22 -21
  76. package/{machineWsRunDispatch-ZNU6LRNG.js → machineWsRunDispatch-7DNDXUOS.js} +22 -21
  77. package/node_modules/abstract-level/CHANGELOG.md +150 -0
  78. package/node_modules/abstract-level/LICENSE +21 -0
  79. package/node_modules/abstract-level/README.md +1957 -0
  80. package/node_modules/abstract-level/UPGRADING.md +669 -0
  81. package/node_modules/abstract-level/abstract-chained-batch.js +397 -0
  82. package/node_modules/abstract-level/abstract-iterator.js +404 -0
  83. package/node_modules/abstract-level/abstract-level.js +1127 -0
  84. package/node_modules/abstract-level/abstract-snapshot.js +84 -0
  85. package/node_modules/abstract-level/index.d.ts +52 -0
  86. package/node_modules/abstract-level/index.js +9 -0
  87. package/node_modules/abstract-level/lib/abstract-sublevel-iterator.js +141 -0
  88. package/node_modules/abstract-level/lib/abstract-sublevel.js +290 -0
  89. package/node_modules/abstract-level/lib/common.js +33 -0
  90. package/node_modules/abstract-level/lib/default-chained-batch.js +29 -0
  91. package/node_modules/abstract-level/lib/default-kv-iterator.js +74 -0
  92. package/node_modules/abstract-level/lib/deferred-iterator.js +110 -0
  93. package/node_modules/abstract-level/lib/deferred-queue.js +84 -0
  94. package/node_modules/abstract-level/lib/errors.js +21 -0
  95. package/node_modules/abstract-level/lib/event-monitor.js +30 -0
  96. package/node_modules/abstract-level/lib/hooks.js +78 -0
  97. package/node_modules/abstract-level/lib/prefixes.js +21 -0
  98. package/node_modules/abstract-level/lib/prewrite-batch.js +96 -0
  99. package/node_modules/abstract-level/lib/range-options.js +26 -0
  100. package/node_modules/abstract-level/package.json +66 -0
  101. package/node_modules/abstract-level/test/async-iterator-test.js +132 -0
  102. package/node_modules/abstract-level/test/batch-test.js +214 -0
  103. package/node_modules/abstract-level/test/chained-batch-test.js +315 -0
  104. package/node_modules/abstract-level/test/clear-range-test.js +262 -0
  105. package/node_modules/abstract-level/test/clear-test.js +110 -0
  106. package/node_modules/abstract-level/test/common.js +90 -0
  107. package/node_modules/abstract-level/test/deferred-open-test.js +209 -0
  108. package/node_modules/abstract-level/test/del-test.js +65 -0
  109. package/node_modules/abstract-level/test/encoding-buffer-test.js +336 -0
  110. package/node_modules/abstract-level/test/encoding-custom-test.js +92 -0
  111. package/node_modules/abstract-level/test/encoding-decode-error-test.js +85 -0
  112. package/node_modules/abstract-level/test/encoding-json-test.js +75 -0
  113. package/node_modules/abstract-level/test/encoding-test.js +130 -0
  114. package/node_modules/abstract-level/test/events/write.js +132 -0
  115. package/node_modules/abstract-level/test/factory-test.js +36 -0
  116. package/node_modules/abstract-level/test/get-many-test.js +157 -0
  117. package/node_modules/abstract-level/test/get-sync-test.js +61 -0
  118. package/node_modules/abstract-level/test/get-test.js +83 -0
  119. package/node_modules/abstract-level/test/has-many-test.js +144 -0
  120. package/node_modules/abstract-level/test/has-test.js +81 -0
  121. package/node_modules/abstract-level/test/hooks/newsub.js +57 -0
  122. package/node_modules/abstract-level/test/hooks/postopen.js +229 -0
  123. package/node_modules/abstract-level/test/hooks/prewrite.js +816 -0
  124. package/node_modules/abstract-level/test/hooks/shared.js +38 -0
  125. package/node_modules/abstract-level/test/index.js +86 -0
  126. package/node_modules/abstract-level/test/iterator-explicit-snapshot-test.js +393 -0
  127. package/node_modules/abstract-level/test/iterator-no-snapshot-test.js +49 -0
  128. package/node_modules/abstract-level/test/iterator-range-test.js +277 -0
  129. package/node_modules/abstract-level/test/iterator-seek-test.js +335 -0
  130. package/node_modules/abstract-level/test/iterator-snapshot-test.js +56 -0
  131. package/node_modules/abstract-level/test/iterator-test.js +621 -0
  132. package/node_modules/abstract-level/test/manifest-test.js +21 -0
  133. package/node_modules/abstract-level/test/open-create-if-missing-test.js +39 -0
  134. package/node_modules/abstract-level/test/open-error-if-exists-test.js +25 -0
  135. package/node_modules/abstract-level/test/open-test.js +263 -0
  136. package/node_modules/abstract-level/test/put-get-del-test.js +97 -0
  137. package/node_modules/abstract-level/test/put-test.js +70 -0
  138. package/node_modules/abstract-level/test/self/abstract-iterator-test.js +182 -0
  139. package/node_modules/abstract-level/test/self/async-iterator-test.js +242 -0
  140. package/node_modules/abstract-level/test/self/attach-resource-test.js +74 -0
  141. package/node_modules/abstract-level/test/self/defer-test.js +140 -0
  142. package/node_modules/abstract-level/test/self/deferred-iterator-test.js +314 -0
  143. package/node_modules/abstract-level/test/self/deferred-operations-test.js +86 -0
  144. package/node_modules/abstract-level/test/self/deferred-queue-test.js +93 -0
  145. package/node_modules/abstract-level/test/self/encoding-test.js +391 -0
  146. package/node_modules/abstract-level/test/self/errors-test.js +11 -0
  147. package/node_modules/abstract-level/test/self/iterator-test.js +1050 -0
  148. package/node_modules/abstract-level/test/self/sublevel-test.js +1039 -0
  149. package/node_modules/abstract-level/test/self.js +905 -0
  150. package/node_modules/abstract-level/test/sublevel-test.js +209 -0
  151. package/node_modules/abstract-level/test/traits/closed.js +42 -0
  152. package/node_modules/abstract-level/test/traits/index.js +4 -0
  153. package/node_modules/abstract-level/test/traits/open.js +62 -0
  154. package/node_modules/abstract-level/test/util.js +275 -0
  155. package/node_modules/abstract-level/types/abstract-chained-batch.d.ts +124 -0
  156. package/node_modules/abstract-level/types/abstract-iterator.d.ts +241 -0
  157. package/node_modules/abstract-level/types/abstract-level.d.ts +636 -0
  158. package/node_modules/abstract-level/types/abstract-snapshot.d.ts +30 -0
  159. package/node_modules/abstract-level/types/abstract-sublevel.d.ts +76 -0
  160. package/node_modules/abstract-level/types/interfaces.d.ts +43 -0
  161. package/node_modules/base64-js/LICENSE +21 -0
  162. package/node_modules/base64-js/README.md +34 -0
  163. package/node_modules/base64-js/base64js.min.js +1 -0
  164. package/node_modules/base64-js/index.d.ts +3 -0
  165. package/node_modules/base64-js/index.js +150 -0
  166. package/node_modules/base64-js/package.json +47 -0
  167. package/node_modules/browser-level/CHANGELOG.md +44 -0
  168. package/node_modules/browser-level/LICENSE +21 -0
  169. package/node_modules/browser-level/README.md +124 -0
  170. package/node_modules/browser-level/UPGRADING.md +143 -0
  171. package/node_modules/browser-level/index.d.ts +108 -0
  172. package/node_modules/browser-level/index.js +323 -0
  173. package/node_modules/browser-level/iterator.js +239 -0
  174. package/node_modules/browser-level/package.json +48 -0
  175. package/node_modules/browser-level/util/clear.js +38 -0
  176. package/node_modules/browser-level/util/deserialize.js +17 -0
  177. package/node_modules/browser-level/util/key-range.js +20 -0
  178. package/node_modules/buffer/AUTHORS.md +73 -0
  179. package/node_modules/buffer/LICENSE +21 -0
  180. package/node_modules/buffer/README.md +410 -0
  181. package/node_modules/buffer/index.d.ts +194 -0
  182. package/node_modules/buffer/index.js +2106 -0
  183. package/node_modules/buffer/package.json +93 -0
  184. package/node_modules/classic-level/CHANGELOG.md +115 -0
  185. package/node_modules/classic-level/LICENSE +21 -0
  186. package/node_modules/classic-level/README.md +274 -0
  187. package/node_modules/classic-level/UPGRADING.md +131 -0
  188. package/node_modules/classic-level/binding.cc +2652 -0
  189. package/node_modules/classic-level/binding.gyp +71 -0
  190. package/node_modules/classic-level/binding.js +1 -0
  191. package/node_modules/classic-level/chained-batch.js +35 -0
  192. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/LICENSE +27 -0
  193. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/Makefile +424 -0
  194. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/build_detect_platform +256 -0
  195. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/db/autocompact_test.cc +118 -0
  196. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/db/builder.cc +88 -0
  197. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/db/builder.h +34 -0
  198. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/db/c.cc +595 -0
  199. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/db/c_test.c +390 -0
  200. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/db/corruption_test.cc +374 -0
  201. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/db/db_bench.cc +1020 -0
  202. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/db/db_impl.cc +1568 -0
  203. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/db/db_impl.h +212 -0
  204. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/db/db_iter.cc +317 -0
  205. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/db/db_iter.h +28 -0
  206. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/db/db_test.cc +2158 -0
  207. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/db/dbformat.cc +140 -0
  208. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/db/dbformat.h +230 -0
  209. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/db/dbformat_test.cc +112 -0
  210. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/db/dumpfile.cc +225 -0
  211. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/db/fault_injection_test.cc +554 -0
  212. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/db/filename.cc +144 -0
  213. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/db/filename.h +85 -0
  214. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/db/filename_test.cc +123 -0
  215. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/db/leveldbutil.cc +64 -0
  216. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/db/log_format.h +35 -0
  217. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/db/log_reader.cc +284 -0
  218. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/db/log_reader.h +113 -0
  219. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/db/log_test.cc +591 -0
  220. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/db/log_writer.cc +112 -0
  221. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/db/log_writer.h +54 -0
  222. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/db/memtable.cc +145 -0
  223. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/db/memtable.h +89 -0
  224. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/db/recovery_test.cc +324 -0
  225. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/db/repair.cc +461 -0
  226. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/db/skiplist.h +384 -0
  227. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/db/skiplist_test.cc +378 -0
  228. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/db/snapshot.h +67 -0
  229. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/db/table_cache.cc +127 -0
  230. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/db/table_cache.h +61 -0
  231. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/db/version_edit.cc +266 -0
  232. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/db/version_edit.h +107 -0
  233. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/db/version_edit_test.cc +46 -0
  234. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/db/version_set.cc +1535 -0
  235. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/db/version_set.h +399 -0
  236. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/db/version_set_test.cc +179 -0
  237. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/db/write_batch.cc +147 -0
  238. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/db/write_batch_internal.h +50 -0
  239. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/db/write_batch_test.cc +120 -0
  240. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/helpers/memenv/memenv.cc +398 -0
  241. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/helpers/memenv/memenv.h +20 -0
  242. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/helpers/memenv/memenv_test.cc +241 -0
  243. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/include/leveldb/c.h +290 -0
  244. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/include/leveldb/cache.h +110 -0
  245. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/include/leveldb/comparator.h +63 -0
  246. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/include/leveldb/db.h +164 -0
  247. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/include/leveldb/dumpfile.h +25 -0
  248. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/include/leveldb/env.h +351 -0
  249. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/include/leveldb/filter_policy.h +70 -0
  250. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/include/leveldb/iterator.h +100 -0
  251. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/include/leveldb/options.h +213 -0
  252. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/include/leveldb/slice.h +109 -0
  253. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/include/leveldb/status.h +112 -0
  254. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/include/leveldb/table.h +85 -0
  255. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/include/leveldb/table_builder.h +92 -0
  256. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/include/leveldb/value_sink.h +26 -0
  257. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/include/leveldb/write_batch.h +64 -0
  258. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/issues/issue178_test.cc +92 -0
  259. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/issues/issue200_test.cc +59 -0
  260. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/port/atomic_pointer.h +242 -0
  261. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/port/port.h +21 -0
  262. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/port/port_example.h +141 -0
  263. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/port/port_posix.cc +53 -0
  264. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/port/port_posix.h +156 -0
  265. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/port/port_posix_sse.cc +129 -0
  266. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/port/thread_annotations.h +60 -0
  267. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/port/win/stdint.h +24 -0
  268. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/table/block.cc +268 -0
  269. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/table/block.h +44 -0
  270. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/table/block_builder.cc +109 -0
  271. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/table/block_builder.h +57 -0
  272. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/table/filter_block.cc +111 -0
  273. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/table/filter_block.h +68 -0
  274. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/table/filter_block_test.cc +128 -0
  275. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/table/format.cc +144 -0
  276. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/table/format.h +108 -0
  277. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/table/iterator.cc +67 -0
  278. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/table/iterator_wrapper.h +66 -0
  279. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/table/merger.cc +197 -0
  280. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/table/merger.h +26 -0
  281. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/table/table.cc +285 -0
  282. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/table/table_builder.cc +270 -0
  283. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/table/table_test.cc +876 -0
  284. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/table/two_level_iterator.cc +182 -0
  285. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/table/two_level_iterator.h +34 -0
  286. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/util/arena.cc +68 -0
  287. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/util/arena.h +68 -0
  288. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/util/arena_test.cc +68 -0
  289. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/util/bloom.cc +95 -0
  290. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/util/bloom_test.cc +162 -0
  291. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/util/cache.cc +405 -0
  292. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/util/cache_test.cc +226 -0
  293. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/util/coding.cc +194 -0
  294. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/util/coding.h +104 -0
  295. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/util/coding_test.cc +196 -0
  296. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/util/comparator.cc +81 -0
  297. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/util/crc32c.cc +350 -0
  298. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/util/crc32c.h +45 -0
  299. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/util/crc32c_test.cc +72 -0
  300. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/util/env.cc +100 -0
  301. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/util/env_posix.cc +695 -0
  302. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/util/env_posix_test.cc +66 -0
  303. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/util/env_posix_test_helper.h +28 -0
  304. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/util/env_test.cc +106 -0
  305. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/util/filter_policy.cc +11 -0
  306. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/util/hash.cc +52 -0
  307. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/util/hash.h +19 -0
  308. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/util/hash_test.cc +54 -0
  309. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/util/histogram.cc +139 -0
  310. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/util/histogram.h +42 -0
  311. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/util/logging.cc +72 -0
  312. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/util/logging.h +43 -0
  313. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/util/mutexlock.h +41 -0
  314. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/util/options.cc +30 -0
  315. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/util/posix_logger.h +98 -0
  316. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/util/random.h +64 -0
  317. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/util/status.cc +75 -0
  318. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/util/testharness.cc +77 -0
  319. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/util/testharness.h +138 -0
  320. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/util/testutil.cc +51 -0
  321. package/node_modules/classic-level/deps/leveldb/leveldb-1.20/util/testutil.h +63 -0
  322. package/node_modules/classic-level/deps/leveldb/leveldb.gyp +282 -0
  323. package/node_modules/classic-level/deps/leveldb/patches/001-value-sink.patch +164 -0
  324. package/node_modules/classic-level/deps/leveldb/port-libuv/atomic_pointer_win.h +48 -0
  325. package/node_modules/classic-level/deps/leveldb/port-libuv/env_win.cc +692 -0
  326. package/node_modules/classic-level/deps/leveldb/port-libuv/port_uv.cc +36 -0
  327. package/node_modules/classic-level/deps/leveldb/port-libuv/port_uv.h +157 -0
  328. package/node_modules/classic-level/deps/leveldb/port-libuv/port_uv.h.bak +153 -0
  329. package/node_modules/classic-level/deps/leveldb/port-libuv/stdint-msvc2008.h +247 -0
  330. package/node_modules/classic-level/deps/leveldb/port-libuv/uv_condvar.h +45 -0
  331. package/node_modules/classic-level/deps/leveldb/port-libuv/uv_condvar_posix.cc +139 -0
  332. package/node_modules/classic-level/deps/leveldb/port-libuv/win_logger.cc +79 -0
  333. package/node_modules/classic-level/deps/leveldb/port-libuv/win_logger.h +28 -0
  334. package/node_modules/classic-level/deps/snappy/freebsd/config.h +135 -0
  335. package/node_modules/classic-level/deps/snappy/freebsd/snappy-stubs-public.h +100 -0
  336. package/node_modules/classic-level/deps/snappy/linux/config.h +135 -0
  337. package/node_modules/classic-level/deps/snappy/linux/snappy-stubs-public.h +100 -0
  338. package/node_modules/classic-level/deps/snappy/mac/config.h +137 -0
  339. package/node_modules/classic-level/deps/snappy/mac/snappy-stubs-public.h +100 -0
  340. package/node_modules/classic-level/deps/snappy/openbsd/config.h +135 -0
  341. package/node_modules/classic-level/deps/snappy/openbsd/snappy-stubs-public.h +100 -0
  342. package/node_modules/classic-level/deps/snappy/snappy/COPYING +54 -0
  343. package/node_modules/classic-level/deps/snappy/snappy/cmake/SnappyConfig.cmake +1 -0
  344. package/node_modules/classic-level/deps/snappy/snappy/cmake/config.h.in +62 -0
  345. package/node_modules/classic-level/deps/snappy/snappy/snappy-c.cc +90 -0
  346. package/node_modules/classic-level/deps/snappy/snappy/snappy-c.h +138 -0
  347. package/node_modules/classic-level/deps/snappy/snappy/snappy-internal.h +224 -0
  348. package/node_modules/classic-level/deps/snappy/snappy/snappy-sinksource.cc +104 -0
  349. package/node_modules/classic-level/deps/snappy/snappy/snappy-sinksource.h +182 -0
  350. package/node_modules/classic-level/deps/snappy/snappy/snappy-stubs-internal.cc +42 -0
  351. package/node_modules/classic-level/deps/snappy/snappy/snappy-stubs-internal.h +561 -0
  352. package/node_modules/classic-level/deps/snappy/snappy/snappy-stubs-public.h.in +94 -0
  353. package/node_modules/classic-level/deps/snappy/snappy/snappy-test.cc +612 -0
  354. package/node_modules/classic-level/deps/snappy/snappy/snappy-test.h +573 -0
  355. package/node_modules/classic-level/deps/snappy/snappy/snappy.cc +1515 -0
  356. package/node_modules/classic-level/deps/snappy/snappy/snappy.h +203 -0
  357. package/node_modules/classic-level/deps/snappy/snappy/snappy_unittest.cc +1410 -0
  358. package/node_modules/classic-level/deps/snappy/snappy.gyp +119 -0
  359. package/node_modules/classic-level/deps/snappy/solaris/config.h +135 -0
  360. package/node_modules/classic-level/deps/snappy/solaris/snappy-stubs-public.h +100 -0
  361. package/node_modules/classic-level/deps/snappy/win32/config.h +29 -0
  362. package/node_modules/classic-level/deps/snappy/win32/snappy-stubs-public.h +100 -0
  363. package/node_modules/classic-level/index.d.ts +343 -0
  364. package/node_modules/classic-level/index.js +311 -0
  365. package/node_modules/classic-level/iterator.js +122 -0
  366. package/node_modules/classic-level/package.json +70 -0
  367. package/node_modules/classic-level/prebuilds/android-arm/classic-level.armv7.node +0 -0
  368. package/node_modules/classic-level/prebuilds/android-arm64/classic-level.armv8.node +0 -0
  369. package/node_modules/classic-level/prebuilds/darwin-x64+arm64/classic-level.node +0 -0
  370. package/node_modules/classic-level/prebuilds/linux-arm/classic-level.armv6.node +0 -0
  371. package/node_modules/classic-level/prebuilds/linux-arm/classic-level.armv7.node +0 -0
  372. package/node_modules/classic-level/prebuilds/linux-arm64/classic-level.armv8.node +0 -0
  373. package/node_modules/classic-level/prebuilds/linux-x64/classic-level.musl.node +0 -0
  374. package/node_modules/classic-level/prebuilds/linux-x64/classic-level.node +0 -0
  375. package/node_modules/classic-level/prebuilds/win32-ia32/classic-level.node +0 -0
  376. package/node_modules/classic-level/prebuilds/win32-x64/classic-level.node +0 -0
  377. package/node_modules/ieee754/LICENSE +11 -0
  378. package/node_modules/ieee754/README.md +51 -0
  379. package/node_modules/ieee754/index.d.ts +10 -0
  380. package/node_modules/ieee754/index.js +85 -0
  381. package/node_modules/ieee754/package.json +52 -0
  382. package/node_modules/is-buffer/LICENSE +21 -0
  383. package/node_modules/is-buffer/README.md +54 -0
  384. package/node_modules/is-buffer/index.d.ts +2 -0
  385. package/node_modules/is-buffer/index.js +11 -0
  386. package/node_modules/is-buffer/package.json +65 -0
  387. package/node_modules/level/CHANGELOG.md +532 -0
  388. package/node_modules/level/LICENSE +21 -0
  389. package/node_modules/level/README.md +107 -0
  390. package/node_modules/level/UPGRADING.md +413 -0
  391. package/node_modules/level/browser.js +1 -0
  392. package/node_modules/level/index.d.ts +75 -0
  393. package/node_modules/level/index.js +1 -0
  394. package/node_modules/level/package.json +62 -0
  395. package/node_modules/level-supports/CHANGELOG.md +140 -0
  396. package/node_modules/level-supports/LICENSE +21 -0
  397. package/node_modules/level-supports/README.md +276 -0
  398. package/node_modules/level-supports/index.d.ts +137 -0
  399. package/node_modules/level-supports/index.js +26 -0
  400. package/node_modules/level-supports/package.json +46 -0
  401. package/node_modules/level-supports/test/cloneable.js +26 -0
  402. package/node_modules/level-supports/test/index.js +24 -0
  403. package/node_modules/level-supports/test/self.js +86 -0
  404. package/node_modules/level-supports/test/shape.js +23 -0
  405. package/node_modules/level-transcoder/CHANGELOG.md +15 -0
  406. package/node_modules/level-transcoder/LICENSE +21 -0
  407. package/node_modules/level-transcoder/README.md +214 -0
  408. package/node_modules/level-transcoder/UPGRADING.md +13 -0
  409. package/node_modules/level-transcoder/index.d.ts +27 -0
  410. package/node_modules/level-transcoder/index.js +158 -0
  411. package/node_modules/level-transcoder/lib/encoding.d.ts +158 -0
  412. package/node_modules/level-transcoder/lib/encoding.js +105 -0
  413. package/node_modules/level-transcoder/lib/encodings.d.ts +9 -0
  414. package/node_modules/level-transcoder/lib/encodings.js +135 -0
  415. package/node_modules/level-transcoder/lib/formats.d.ts +13 -0
  416. package/node_modules/level-transcoder/lib/formats.js +111 -0
  417. package/node_modules/level-transcoder/lib/text-endec.d.ts +6 -0
  418. package/node_modules/level-transcoder/lib/text-endec.js +19 -0
  419. package/node_modules/level-transcoder/package.json +46 -0
  420. package/node_modules/maybe-combine-errors/LICENSE.md +21 -0
  421. package/node_modules/maybe-combine-errors/README.md +94 -0
  422. package/node_modules/maybe-combine-errors/index.js +60 -0
  423. package/node_modules/maybe-combine-errors/package.json +33 -0
  424. package/node_modules/module-error/CHANGELOG.md +23 -0
  425. package/node_modules/module-error/LICENSE +21 -0
  426. package/node_modules/module-error/README.md +89 -0
  427. package/node_modules/module-error/index.d.ts +18 -0
  428. package/node_modules/module-error/index.js +22 -0
  429. package/node_modules/module-error/package.json +36 -0
  430. package/node_modules/napi-macros/LICENSE +21 -0
  431. package/node_modules/napi-macros/README.md +277 -0
  432. package/node_modules/napi-macros/index.js +1 -0
  433. package/node_modules/napi-macros/napi-macros.h +255 -0
  434. package/node_modules/napi-macros/package.json +22 -0
  435. package/node_modules/node-gyp-build/LICENSE +21 -0
  436. package/node_modules/node-gyp-build/README.md +58 -0
  437. package/node_modules/node-gyp-build/SECURITY.md +5 -0
  438. package/node_modules/node-gyp-build/bin.js +84 -0
  439. package/node_modules/node-gyp-build/build-test.js +19 -0
  440. package/node_modules/node-gyp-build/index.js +6 -0
  441. package/node_modules/node-gyp-build/node-gyp-build.js +207 -0
  442. package/node_modules/node-gyp-build/optional.js +7 -0
  443. package/node_modules/node-gyp-build/package.json +43 -0
  444. package/package.json +6 -3
  445. package/{providerPresetApply-7XEHTODR.js → providerPresetApply-XTEXOH7X.js} +3 -3
  446. package/{providerRegistry-GNV4FFSA.js → providerRegistry-ADYDSLKR.js} +3 -3
  447. package/{readlineWorkspace-46KDFUHN.js → readlineWorkspace-LO6ZLFTO.js} +1381 -1317
  448. package/{runAgentClientLoop-CQWLWU4W.js → runAgentClientLoop-KAYGKVTK.js} +16 -15
  449. package/{runtimeDoctorCommands-3USD722U.js → runtimeDoctorCommands-ID23PNNZ.js} +28 -0
  450. package/{spaceCommands-TSBC5UWP.js → spaceCommands-FA6RCZ2Y.js} +10 -9
  451. package/{streamAgentChatTurn-XD5JEJXA.js → streamAgentChatTurn-DFNDU2UY.js} +17 -16
  452. package/{tools-5NAJJTFN.js → tools-6HKH75NT.js} +13 -12
  453. package/{tuiSummaryLlmCaller-7KLLDP22.js → tuiSummaryLlmCaller-CFFVXQWX.js} +2 -2
  454. package/{updateCommands-XYMGOKF4.js → updateCommands-4EHDLF5J.js} +1 -1
  455. package/{updateDialogTitleAction-IKZPJCRA.js → updateDialogTitleAction-FFSYTLBC.js} +3 -3
@@ -1,4 +1,7 @@
1
1
  import "./chunk-M3JEW6N6.js";
2
+ import {
3
+ resolveAuthGuidanceState
4
+ } from "./chunk-GNMAFAIS.js";
2
5
  import {
3
6
  formatQuotaSummary,
4
7
  listFavoriteAgentIdsAcrossServers,
@@ -6,7 +9,7 @@ import {
6
9
  listRemoteAgents,
7
10
  listRemoteAgentsAcrossServers,
8
11
  normalizeListedAgent
9
- } from "./chunk-7LLWEG6F.js";
12
+ } from "./chunk-I44MDY73.js";
10
13
  import {
11
14
  refreshSubscriptionQuotas
12
15
  } from "./chunk-U4STABYN.js";
@@ -73,7 +76,7 @@ import {
73
76
  wrapTextToLines,
74
77
  wrapTranscriptLine,
75
78
  wrapTranscriptLineWithLayout
76
- } from "./chunk-DOBBRISY.js";
79
+ } from "./chunk-Y6XHJ4JJ.js";
77
80
  import "./chunk-VJVNU77E.js";
78
81
  import "./chunk-BIDGLJQ3.js";
79
82
  import {
@@ -85,9 +88,9 @@ import {
85
88
  readTimestamp,
86
89
  setCliLocale,
87
90
  t
88
- } from "./chunk-ZOI6KA4N.js";
89
- import "./chunk-QDT5T7MK.js";
90
- import "./chunk-OY5IJI2N.js";
91
+ } from "./chunk-M76SRQ3H.js";
92
+ import "./chunk-I4OPU5TK.js";
93
+ import "./chunk-YUNJN43V.js";
91
94
  import "./chunk-62IL3KQV.js";
92
95
  import {
93
96
  getReadableCliDb
@@ -95,25 +98,25 @@ import {
95
98
  import {
96
99
  defaultOpenBrowser,
97
100
  saveTokenLogin
98
- } from "./chunk-VPFEPRME.js";
101
+ } from "./chunk-IVZJWTDI.js";
99
102
  import "./chunk-ESHYE7WU.js";
100
103
  import {
101
104
  isScheduledDialog,
102
105
  normalizeDialogRecord,
103
106
  readDialogSnapshot,
104
107
  sortDialogs
105
- } from "./chunk-KUWT3C2P.js";
108
+ } from "./chunk-T76D3OYX.js";
106
109
  import "./chunk-ID4G2MAR.js";
107
110
  import {
108
111
  listUserRecordsFromServers,
109
112
  readLiveDbRecordAfterTombstoneMerge
110
- } from "./chunk-W247GBSQ.js";
113
+ } from "./chunk-YU2THNST.js";
111
114
  import "./chunk-EADNWBAZ.js";
112
115
  import {
113
116
  deleteDbRecord,
114
117
  queryUserRecords,
115
118
  readDbRecord
116
- } from "./chunk-RRMAZ2BI.js";
119
+ } from "./chunk-7NANRWL4.js";
117
120
  import "./chunk-OTGFTBLI.js";
118
121
  import {
119
122
  NOLO_DEFAULT_AGENT_KEY,
@@ -139,13 +142,13 @@ import "./chunk-ATNTHIZI.js";
139
142
  import "./chunk-JEXVIMYZ.js";
140
143
  import {
141
144
  prepareTools
142
- } from "./chunk-44F6KKUE.js";
145
+ } from "./chunk-7YAK46ML.js";
143
146
  import {
144
147
  buildResponseGuidelines
145
148
  } from "./chunk-EOARMOVD.js";
146
149
  import "./chunk-HS7MLR74.js";
147
- import "./chunk-K25DK52L.js";
148
- import "./chunk-OZ6V53WV.js";
150
+ import "./chunk-OKSJZ4UU.js";
151
+ import "./chunk-2EE5UD3N.js";
149
152
  import "./chunk-5UTFL4QJ.js";
150
153
  import "./chunk-KQHGZWSV.js";
151
154
  import "./chunk-GOMR6S5Z.js";
@@ -163,12 +166,12 @@ import {
163
166
  runShowsLogTail,
164
167
  shortRunId
165
168
  } from "./chunk-L4KXQ6QP.js";
166
- import "./chunk-T36EFAW7.js";
169
+ import "./chunk-VZVTPDPL.js";
167
170
  import "./chunk-HNRASX3X.js";
168
171
  import "./chunk-YRRASA5Q.js";
169
172
  import "./chunk-63W5N6P3.js";
170
173
  import "./chunk-VF4K2QE6.js";
171
- import "./chunk-WTUVMKSQ.js";
174
+ import "./chunk-62XHRZG4.js";
172
175
  import "./chunk-Z7IZQF56.js";
173
176
  import "./chunk-XPRWFQQK.js";
174
177
  import {
@@ -178,15 +181,15 @@ import {
178
181
  } from "./chunk-YPREESF4.js";
179
182
  import "./chunk-BJUDYFV5.js";
180
183
  import "./chunk-MEYIRKDN.js";
181
- import "./chunk-GZQNKKDG.js";
184
+ import "./chunk-HKBFZONG.js";
182
185
  import "./chunk-ZJ7UHBJS.js";
183
186
  import {
184
187
  extractReferenceKeysFromMessage
185
- } from "./chunk-KUPDS66Q.js";
188
+ } from "./chunk-ANX7Z7Z2.js";
186
189
  import "./chunk-MC4XLIJ7.js";
187
190
  import "./chunk-YYLHWIW6.js";
188
191
  import "./chunk-6O4IK4V2.js";
189
- import "./chunk-MXRUAINC.js";
192
+ import "./chunk-UMB7CHAY.js";
190
193
  import "./chunk-D76D3RTR.js";
191
194
  import "./chunk-5RGU3J7P.js";
192
195
  import "./chunk-M76ECQRD.js";
@@ -201,10 +204,10 @@ import {
201
204
  buildSkillDiscoveryContextBlock,
202
205
  buildSkillDiscoveryContextLayer
203
206
  } from "./chunk-E4MARS3Q.js";
204
- import "./chunk-J5H6SUOW.js";
207
+ import "./chunk-B2XUQXQX.js";
205
208
  import {
206
209
  expandEnabledPacks
207
- } from "./chunk-WC6A2Q7S.js";
210
+ } from "./chunk-6TPOEJMQ.js";
208
211
  import "./chunk-AUDNYVRC.js";
209
212
  import "./chunk-KHCLMKZZ.js";
210
213
  import {
@@ -213,10 +216,10 @@ import {
213
216
  formatToolOverflowMarker,
214
217
  getProcessRegistry,
215
218
  readCommandActionGatePayload
216
- } from "./chunk-GH4MH73K.js";
217
- import "./chunk-U5QTKTZE.js";
219
+ } from "./chunk-RHDOQWXZ.js";
220
+ import "./chunk-P6GMCCAT.js";
218
221
  import "./chunk-ZNFJWEN4.js";
219
- import "./chunk-NOGH7HCP.js";
222
+ import "./chunk-A6FNUMCF.js";
220
223
  import "./chunk-GMZLP5DV.js";
221
224
  import "./chunk-I4A26N52.js";
222
225
  import "./chunk-5ZUL4CUO.js";
@@ -228,16 +231,16 @@ import {
228
231
  buildIdentityBlock,
229
232
  buildRuntimeGuidanceBlocks,
230
233
  resolveToolGuidedSections
231
- } from "./chunk-CTGZO35O.js";
234
+ } from "./chunk-JLQKV2ZJ.js";
232
235
  import "./chunk-PUOC4YRO.js";
233
236
  import "./chunk-RGNEEJ3Y.js";
234
237
  import {
235
238
  isQuotaExhaustedError
236
239
  } from "./chunk-H6A6X4EK.js";
237
- import "./chunk-M6NK74VP.js";
240
+ import "./chunk-S5XGT6GB.js";
238
241
  import {
239
242
  resolvePlatformAuthToken
240
- } from "./chunk-7MUSNQ6E.js";
243
+ } from "./chunk-27ONFIEY.js";
241
244
  import {
242
245
  DEFAULT_CONTEXT_WINDOW,
243
246
  getModelContextWindow,
@@ -281,7 +284,8 @@ import {
281
284
  } from "./chunk-2GRGFCF6.js";
282
285
  import {
283
286
  canonicalizeToolNames
284
- } from "./chunk-O6OSWFZQ.js";
287
+ } from "./chunk-XUWRURDF.js";
288
+ import "./chunk-5J3PYNUP.js";
285
289
  import {
286
290
  getProcessRingBuffer,
287
291
  resolveDefaultLogPath
@@ -289,7 +293,7 @@ import {
289
293
  import {
290
294
  checkForCliUpdate,
291
295
  runSelfUpdateDetailed
292
- } from "./chunk-44QZPYLI.js";
296
+ } from "./chunk-2SYTUTLI.js";
293
297
  import {
294
298
  parseUserIdFromAuthToken,
295
299
  resolveAuthToken,
@@ -4310,10 +4314,10 @@ function findAgentCatalogEntry(entries, rawTarget) {
4310
4314
  }
4311
4315
 
4312
4316
  // packages/cli/tui/pasteImage.ts
4313
- import { readFileSync, statSync } from "node:fs";
4317
+ import { readFileSync, statSync as statSync2 } from "node:fs";
4314
4318
  import { readFile, stat } from "node:fs/promises";
4315
- import { homedir } from "node:os";
4316
- import { isAbsolute, resolve } from "node:path";
4319
+ import { homedir as homedir2 } from "node:os";
4320
+ import { isAbsolute, resolve as resolve2 } from "node:path";
4317
4321
 
4318
4322
  // packages/cli/tui/compressImage.ts
4319
4323
  var MAX_IMAGE_DIMENSION = 1568;
@@ -4511,1398 +4515,1412 @@ async function compressImage(input, mime, options = {}) {
4511
4515
  }
4512
4516
  }
4513
4517
 
4514
- // packages/cli/tui/pasteImage.ts
4515
- var IMAGE_EXTENSIONS = ["png", "jpg", "jpeg", "gif", "webp"];
4516
- var IMAGE_EXTENSION_SET = new Set(IMAGE_EXTENSIONS.map((ext) => ext.toLowerCase()));
4517
- var MIME_BY_EXTENSION = {
4518
- png: "image/png",
4519
- jpg: "image/jpeg",
4520
- jpeg: "image/jpeg",
4521
- gif: "image/gif",
4522
- webp: "image/webp"
4523
- };
4524
- var DEFAULT_MAX_IMAGE_BYTES = 4 * 1024 * 1024;
4525
- var ImageReadError = class extends Error {
4526
- code;
4527
- path;
4528
- constructor(code, path, message) {
4529
- super(message);
4530
- this.code = code;
4531
- this.path = path;
4532
- this.name = "ImageReadError";
4518
+ // packages/cli/tui/sessionInput.ts
4519
+ import { readdirSync, statSync } from "node:fs";
4520
+ import { homedir } from "node:os";
4521
+ import { resolve } from "node:path";
4522
+ var PASTE_TOKEN_PREFIX = "\0PASTE\0";
4523
+ function applyTuiInputKey(buffer, sequence, key = {}, cursorPos, options) {
4524
+ const seq = sequence ?? "";
4525
+ const curPos = Math.max(0, Math.min(buffer.length, cursorPos ?? buffer.length));
4526
+ const pasteStore = options?.pasteStore;
4527
+ if (seq.startsWith(PASTE_TOKEN_PREFIX)) {
4528
+ const rawPayload = seq.slice(PASTE_TOKEN_PREFIX.length);
4529
+ const normalized = rawPayload.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
4530
+ const insertAt2 = snapCursorOutsidePasteChip(buffer, curPos);
4531
+ if (pasteStore && shouldCollapsePaste(normalized)) {
4532
+ const { placeholder } = allocateCollapsedPaste(pasteStore, normalized);
4533
+ const nextBuf3 = buffer.slice(0, insertAt2) + placeholder + buffer.slice(insertAt2);
4534
+ return { buffer: nextBuf3, cursorPos: insertAt2 + placeholder.length };
4535
+ }
4536
+ const nextBuf2 = buffer.slice(0, insertAt2) + normalized + buffer.slice(insertAt2);
4537
+ return { buffer: nextBuf2, cursorPos: insertAt2 + normalized.length };
4533
4538
  }
4534
- };
4535
- function extnameOf(path) {
4536
- const slash = Math.max(path.lastIndexOf("/"), path.lastIndexOf("\\"));
4537
- const base = slash >= 0 ? path.slice(slash + 1) : path;
4538
- const dot = base.lastIndexOf(".");
4539
- if (dot <= 0) return "";
4540
- return base.slice(dot + 1).toLowerCase();
4541
- }
4542
- function basenameOf(path) {
4543
- const slash = Math.max(path.lastIndexOf("/"), path.lastIndexOf("\\"));
4544
- return slash >= 0 ? path.slice(slash + 1) : path;
4545
- }
4546
- function isWslEnvironment() {
4547
- if (process.env.WSL_DISTRO_NAME) return true;
4548
- try {
4549
- const version2 = readFileSync("/proc/version", "utf8");
4550
- return /microsoft/i.test(version2);
4551
- } catch {
4552
- return false;
4539
+ if (seq === "" || key.ctrl && key.name === "c") {
4540
+ return { buffer, cursorPos: curPos, abort: true };
4553
4541
  }
4554
- }
4555
- var WINDOWS_DRIVE_RE = /^([a-zA-Z]):[\\/](.*)$/s;
4556
- function mapWindowsPathToWsl(rawPath) {
4557
- const m = WINDOWS_DRIVE_RE.exec(rawPath);
4558
- if (!m) return rawPath;
4559
- const drive = m[1].toLowerCase();
4560
- const rest = m[2].replace(/[\\/]+/g, "/");
4561
- return `/mnt/${drive}/${rest}`.replace(/\/+/g, "/");
4562
- }
4563
- function fileUriToPath(rawPath) {
4564
- if (!/^file:\/\//i.test(rawPath)) return null;
4565
- const rest = rawPath.slice("file://".length);
4566
- const slash = rest.indexOf("/");
4567
- if (slash < 0) return null;
4568
- const pathPart = rest.slice(slash);
4569
- try {
4570
- return decodeURIComponent(pathPart);
4571
- } catch {
4572
- return pathPart;
4542
+ if (seq === "\f" || key.ctrl && key.name === "l") {
4543
+ return { buffer, cursorPos: curPos, redraw: true };
4573
4544
  }
4574
- }
4575
- function resolveImageSource(rawPath, cwd) {
4576
- let candidate = rawPath.trim();
4577
- if (!candidate) return candidate;
4578
- if (candidate === "~") return homedir();
4579
- if (candidate.startsWith("~/") || candidate.startsWith("~\\")) {
4580
- return homedir() + candidate.slice(1);
4545
+ if (seq === "" || key.ctrl && key.name === "o") {
4546
+ return { buffer, cursorPos: curPos };
4581
4547
  }
4582
- if (isAbsolute(candidate)) return candidate;
4583
- return resolve(cwd, candidate);
4584
- }
4585
- function isImagePath(path) {
4586
- return IMAGE_EXTENSION_SET.has(extnameOf(path));
4587
- }
4588
- function isReadableFilePath(path) {
4589
- try {
4590
- statSync(path);
4591
- return true;
4592
- } catch {
4593
- return false;
4548
+ if (seq === "\x1B[13;2~" || seq === "\x1B[27;2;13~" || seq === "\x1B\r" || key.shift && (key.name === "enter" || key.name === "return") || seq === "\n" || key.ctrl && key.name === "j") {
4549
+ const insertAt2 = snapCursorOutsidePasteChip(buffer, curPos);
4550
+ const nextBuf2 = buffer.slice(0, insertAt2) + "\n" + buffer.slice(insertAt2);
4551
+ return { buffer: nextBuf2, cursorPos: insertAt2 + 1 };
4594
4552
  }
4595
- }
4596
- function detectImagePaths(line, cwd, opts = {}) {
4597
- const wsl = opts.wsl ?? isWslEnvironment();
4598
- const tokens = tokenizePasteLine(line);
4599
- const out = [];
4600
- for (const token of tokens) {
4601
- if (!token.raw) continue;
4602
- let candidate = token.decoded;
4603
- const uriPath = fileUriToPath(candidate);
4604
- if (uriPath !== null) candidate = uriPath;
4605
- if (wsl) candidate = mapWindowsPathToWsl(candidate);
4606
- const resolved = resolveImageSource(candidate, cwd);
4607
- if (!isImagePath(resolved)) continue;
4608
- if (!isReadableFilePath(resolved)) {
4609
- out.push({ raw: token.raw, resolvedPath: resolved, unreadable: true });
4610
- continue;
4553
+ if (key.name === "enter" || key.name === "return" || seq === "\r") {
4554
+ return { buffer: "", cursorPos: 0, submit: buffer };
4555
+ }
4556
+ if (isLeftArrowSequence(seq, key)) {
4557
+ const span = findCollapsedPasteSpanAt(buffer, curPos, { preferLeft: true });
4558
+ if (span && curPos > span.start && curPos <= span.end) {
4559
+ return { buffer, cursorPos: span.start };
4611
4560
  }
4612
- out.push({ raw: token.raw, resolvedPath: resolved });
4561
+ return { buffer, cursorPos: Math.max(0, curPos - 1) };
4613
4562
  }
4614
- return out;
4615
- }
4616
- function detectFileReferences(line, cwd, opts = {}) {
4617
- const wsl = opts.wsl ?? isWslEnvironment();
4618
- const excluded = new Set(opts.exclude ?? []);
4619
- const out = [];
4620
- const seen = /* @__PURE__ */ new Set();
4621
- for (const token of tokenizePasteLine(line)) {
4622
- if (!token.raw || excluded.has(token.raw)) continue;
4623
- let candidate = token.decoded;
4624
- const uriPath = fileUriToPath(candidate);
4625
- if (uriPath !== null) candidate = uriPath;
4626
- if (wsl) candidate = mapWindowsPathToWsl(candidate);
4627
- if (candidate.startsWith("~")) candidate = resolveImageSource(candidate, cwd);
4628
- const looksLikePath = /[/\\]/.test(candidate) || candidate.startsWith("~") || /^[a-zA-Z]:/.test(candidate);
4629
- if (!looksLikePath) continue;
4630
- const ext = extnameOf(candidate);
4631
- if (!/^[a-z0-9]{1,8}$/.test(ext)) continue;
4632
- if (IMAGE_EXTENSION_SET.has(ext)) continue;
4633
- const resolved = resolveImageSource(candidate, cwd);
4634
- if (excluded.has(resolved) || seen.has(resolved)) continue;
4635
- if (!isReadableFilePath(resolved)) continue;
4636
- try {
4637
- if (!statSync(resolved).isFile()) continue;
4638
- } catch {
4639
- continue;
4563
+ if (isRightArrowSequence(seq, key)) {
4564
+ const span = findCollapsedPasteSpanAt(buffer, curPos);
4565
+ if (span && curPos >= span.start && curPos < span.end) {
4566
+ return { buffer, cursorPos: span.end };
4640
4567
  }
4641
- seen.add(resolved);
4642
- out.push({ raw: token.raw, resolvedPath: resolved });
4568
+ return { buffer, cursorPos: Math.min(buffer.length, curPos + 1) };
4643
4569
  }
4644
- return out;
4645
- }
4646
- function tokenizePasteLine(line) {
4647
- const tokens = [];
4648
- let rawBuf = "";
4649
- let decBuf = "";
4650
- let quote = null;
4651
- const push = () => {
4652
- if (rawBuf.length > 0) {
4653
- tokens.push({ raw: rawBuf, decoded: decBuf });
4654
- rawBuf = "";
4655
- decBuf = "";
4570
+ if (isHomeSequence(seq, key)) {
4571
+ return { buffer, cursorPos: 0 };
4572
+ }
4573
+ if (isEndSequence(seq, key)) {
4574
+ return { buffer, cursorPos: buffer.length };
4575
+ }
4576
+ if (isDeleteWordSequence(seq, key)) {
4577
+ if (curPos === 0) return { buffer, cursorPos: curPos };
4578
+ const pasteSpan = findCollapsedPasteSpanAt(buffer, curPos, {
4579
+ preferLeft: true
4580
+ });
4581
+ if (pasteSpan && (curPos === pasteSpan.end || curPos > pasteSpan.start && curPos < pasteSpan.end)) {
4582
+ return removePasteSpan(buffer, pasteSpan, pasteStore);
4656
4583
  }
4657
- };
4658
- for (let i = 0; i < line.length; i++) {
4659
- const ch = line[i];
4660
- const next = line[i + 1];
4661
- if (quote) {
4662
- if (ch === "\\" && next !== void 0) {
4663
- rawBuf += ch + next;
4664
- decBuf += next;
4665
- i++;
4666
- continue;
4667
- }
4668
- if (ch === quote) {
4669
- quote = null;
4670
- rawBuf += ch;
4671
- continue;
4584
+ const cutIdx = findWordStartLeft(buffer, curPos);
4585
+ return deleteBufferRange(buffer, cutIdx, curPos, pasteStore);
4586
+ }
4587
+ if (isKillToLineStartSequence(seq, key)) {
4588
+ if (curPos === 0) return { buffer, cursorPos: curPos };
4589
+ const lineStart = buffer.lastIndexOf("\n", curPos - 1) + 1;
4590
+ return deleteBufferRange(buffer, lineStart, curPos, pasteStore);
4591
+ }
4592
+ if (isKillToLineEndSequence(seq, key)) {
4593
+ const nlIdx = buffer.indexOf("\n", curPos);
4594
+ const lineEnd = nlIdx === -1 ? buffer.length : nlIdx;
4595
+ return deleteBufferRange(buffer, curPos, lineEnd, pasteStore);
4596
+ }
4597
+ if (isBackspaceSequence(seq, key)) {
4598
+ if (curPos > 0) {
4599
+ const pasteSpan = findCollapsedPasteSpanAt(buffer, curPos, {
4600
+ preferLeft: true
4601
+ });
4602
+ if (pasteSpan && (curPos === pasteSpan.end || curPos > pasteSpan.start && curPos < pasteSpan.end)) {
4603
+ return removePasteSpan(buffer, pasteSpan, pasteStore);
4672
4604
  }
4673
- rawBuf += ch;
4674
- decBuf += ch;
4675
- continue;
4676
- }
4677
- if (ch === "\\" && next !== void 0 && /\s/.test(next)) {
4678
- rawBuf += ch + next;
4679
- decBuf += next;
4680
- i++;
4681
- continue;
4605
+ const nextBuf2 = buffer.slice(0, curPos - 1) + buffer.slice(curPos);
4606
+ return { buffer: nextBuf2, cursorPos: curPos - 1 };
4682
4607
  }
4683
- if (ch === "\\" && next === "\\") {
4684
- rawBuf += "\\\\";
4685
- decBuf += "\\";
4686
- i++;
4687
- continue;
4608
+ return { buffer, cursorPos: curPos };
4609
+ }
4610
+ if (isForwardDeleteSequence(seq, key)) {
4611
+ if (curPos < buffer.length) {
4612
+ const pasteSpan = findCollapsedPasteSpanAt(buffer, curPos);
4613
+ if (pasteSpan && (curPos === pasteSpan.start || curPos > pasteSpan.start && curPos < pasteSpan.end)) {
4614
+ return removePasteSpan(buffer, pasteSpan, pasteStore);
4615
+ }
4616
+ const nextBuf2 = buffer.slice(0, curPos) + buffer.slice(curPos + 1);
4617
+ return { buffer: nextBuf2, cursorPos: curPos };
4688
4618
  }
4689
- if (ch === '"' || ch === "'") {
4690
- quote = ch;
4691
- rawBuf += ch;
4692
- continue;
4619
+ if (curPos > 0) {
4620
+ const nextBuf2 = buffer.slice(0, curPos - 1);
4621
+ return { buffer: nextBuf2, cursorPos: curPos - 1 };
4693
4622
  }
4694
- if (/\s/.test(ch)) {
4695
- push();
4696
- continue;
4697
- }
4698
- rawBuf += ch;
4699
- decBuf += ch;
4700
- }
4701
- push();
4702
- return tokens;
4703
- }
4704
- async function readImageAsDataUrl(absolutePath, options = {}) {
4705
- const maxBytes = options.maxBytes ?? DEFAULT_MAX_IMAGE_BYTES;
4706
- let stats;
4707
- try {
4708
- stats = await stat(absolutePath);
4709
- } catch (error) {
4710
- throw classifyFsError(error, absolutePath);
4711
- }
4712
- if (stats.isDirectory()) {
4713
- throw new ImageReadError(
4714
- "is-directory",
4715
- absolutePath,
4716
- `path is a directory, not an image: ${absolutePath}`
4717
- );
4718
- }
4719
- const ext = extnameOf(absolutePath);
4720
- if (!ext || !IMAGE_EXTENSION_SET.has(ext)) {
4721
- throw new ImageReadError(
4722
- "unsupported-extension",
4723
- absolutePath,
4724
- `unsupported image extension: .${ext || "(none)"}`
4725
- );
4623
+ return { buffer, cursorPos: curPos };
4726
4624
  }
4727
- let buffer;
4728
- try {
4729
- buffer = await readFile(absolutePath);
4730
- } catch (error) {
4731
- throw classifyFsError(error, absolutePath);
4625
+ if (seq === " " || key.name === "tab") {
4626
+ if (options?.cwd) {
4627
+ const pathCandidates = completeSlashCommand(buffer, options.cwd);
4628
+ if (pathCandidates.length === 1) {
4629
+ const [only] = pathCandidates;
4630
+ return { buffer: only, cursorPos: only.length };
4631
+ }
4632
+ if (pathCandidates.length > 1) {
4633
+ return { buffer, cursorPos: curPos };
4634
+ }
4635
+ }
4636
+ const completed = completeSlashPrefix(buffer) ?? buffer;
4637
+ return { buffer: completed, cursorPos: completed.length };
4732
4638
  }
4733
- const rawMime = MIME_BY_EXTENSION[ext];
4734
- const compressResult = await compressImage(buffer, rawMime);
4735
- const finalBuffer = compressResult.buffer;
4736
- const finalMime = compressResult.mime;
4737
- const finalSizeBytes = finalBuffer.byteLength;
4738
- if (finalSizeBytes > maxBytes) {
4739
- throw new ImageReadError(
4740
- "too-large",
4741
- absolutePath,
4742
- `image too large: ${formatBytes(finalSizeBytes)} (limit ${formatBytes(maxBytes)})`
4743
- );
4639
+ if (!seq || key.ctrl || key.meta || seq.startsWith("\x1B")) {
4640
+ return { buffer, cursorPos: curPos };
4744
4641
  }
4745
- return buildAttachedImage({
4746
- buffer: finalBuffer,
4747
- mime: finalMime,
4748
- filename: basenameOf(absolutePath),
4749
- sourcePath: absolutePath,
4750
- originalSizeBytes: compressResult.compressed ? compressResult.originalBytes : void 0
4751
- });
4642
+ const insertAt = snapCursorOutsidePasteChip(buffer, curPos);
4643
+ const nextBuf = buffer.slice(0, insertAt) + seq + buffer.slice(insertAt);
4644
+ return { buffer: nextBuf, cursorPos: insertAt + seq.length };
4752
4645
  }
4753
- function classifyFsError(error, path) {
4754
- const code = error?.code;
4755
- const message = toErrorMessage(error);
4756
- switch (code) {
4757
- case "ENOENT":
4758
- return new ImageReadError("not-found", path, `image not found: ${path}`);
4759
- case "EACCES":
4760
- case "EPERM":
4761
- return new ImageReadError(
4762
- "permission-denied",
4763
- path,
4764
- `cannot read image (permission denied): ${path}`
4765
- );
4766
- case "EISDIR":
4767
- return new ImageReadError(
4768
- "is-directory",
4769
- path,
4770
- `path is a directory, not an image: ${path}`
4771
- );
4772
- default:
4773
- return new ImageReadError("io-error", path, `failed to read image: ${message}`);
4774
- }
4646
+ function snapCursorOutsidePasteChip(buffer, pos) {
4647
+ const span = findCollapsedPasteSpanAt(buffer, pos);
4648
+ if (span && pos > span.start && pos < span.end) return span.end;
4649
+ return pos;
4775
4650
  }
4776
- function buildAttachedImage(params) {
4777
- const sizeBytes = params.buffer.byteLength;
4778
- const base64 = Buffer.from(params.buffer).toString("base64");
4779
- const dataUrl = `data:${params.mime};base64,${base64}`;
4780
- return {
4781
- dataUrl,
4782
- mime: params.mime,
4783
- filename: params.filename,
4784
- sizeBytes,
4785
- sourcePath: params.sourcePath,
4786
- ...typeof params.originalSizeBytes === "number" && params.originalSizeBytes > sizeBytes ? { originalSizeBytes: params.originalSizeBytes } : {}
4787
- };
4651
+ function isLeftArrowSequence(seq, key) {
4652
+ if (key.name === "left") return true;
4653
+ if (seq === "\x1B[D" || seq === "\x1B[1;2D" || seq === "\x1B[1;5D" || seq === "\x1BOD") return true;
4654
+ return false;
4788
4655
  }
4789
- function describeImageSize(img, options = {}) {
4790
- const isCompressed = typeof img.originalSizeBytes === "number" && img.originalSizeBytes > img.sizeBytes;
4791
- const core = isCompressed ? `${formatBytes(img.sizeBytes)} (\u5DF2\u538B\u7F29 ${formatBytes(img.originalSizeBytes)} \u2192 ${formatBytes(img.sizeBytes)})` : formatBytes(img.sizeBytes);
4792
- return options.prefix ? `Size: ${core}` : core;
4656
+ function isRightArrowSequence(seq, key) {
4657
+ if (key.name === "right") return true;
4658
+ if (seq === "\x1B[C" || seq === "\x1B[1;2C" || seq === "\x1B[1;5C" || seq === "\x1BOC") return true;
4659
+ return false;
4793
4660
  }
4794
- function formatBytes(bytes) {
4795
- if (bytes < 1024) return `${bytes} B`;
4796
- if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
4797
- return `${(bytes / 1024 / 1024).toFixed(1)} MB`;
4661
+ function isHomeSequence(seq, key) {
4662
+ if (key.name === "home") return true;
4663
+ if (key.ctrl && key.name === "a") return true;
4664
+ if (seq === "" || seq === "\x1B[H" || seq === "\x1B[1~" || seq === "\x1B[7~" || seq === "\x1BOH") return true;
4665
+ return false;
4798
4666
  }
4799
- function summarizeAttachment(img) {
4800
- const colorEnabled = resolveCliColorEnabled();
4801
- const sizeText = describeImageSize(img, { prefix: true });
4802
- const titleRaw = "\u{1F4F7} [Attached Image]";
4803
- const nameRaw = `Name: ${img.filename}`;
4804
- const boxWidth = Math.max(40, titleRaw.length + 4, nameRaw.length + 4, sizeText.length + 4);
4805
- const border = "\u250C" + "\u2500".repeat(boxWidth - 2) + "\u2510";
4806
- const bottom = "\u2514" + "\u2500".repeat(boxWidth - 2) + "\u2518";
4807
- const padLine = (content) => {
4808
- const padded = content.padEnd(boxWidth - 4, " ");
4809
- return `\u2502 ${padded} \u2502`;
4810
- };
4811
- const title = padLine(titleRaw);
4812
- const name = padLine(nameRaw);
4813
- const size = padLine(sizeText);
4814
- const text = [
4815
- border,
4816
- title,
4817
- name,
4818
- size,
4819
- bottom
4820
- ].join("\n");
4821
- return themeText(text, "chrome", colorEnabled);
4667
+ function isEndSequence(seq, key) {
4668
+ if (key.name === "end") return true;
4669
+ if (key.ctrl && key.name === "e") return true;
4670
+ if (seq === "" || seq === "\x1B[F" || seq === "\x1B[4~" || seq === "\x1B[8~" || seq === "\x1BOF") return true;
4671
+ return false;
4822
4672
  }
4823
- function formatComposerAttachmentLine(images) {
4824
- if (images.length === 0) return null;
4825
- const head = images.slice(0, 2).map((img) => `\u{1F4CE} ${img.filename} (${formatBytes(img.sizeBytes)})`);
4826
- const extra = images.length - head.length;
4827
- return extra > 0 ? `${head.join(", ")} +${extra}` : head.join(", ");
4673
+ function removePasteSpan(buffer, span, pasteStore) {
4674
+ if (pasteStore) releaseCollapsedPaste(pasteStore, span.id);
4675
+ const nextBuf = buffer.slice(0, span.start) + buffer.slice(span.end);
4676
+ return { buffer: nextBuf, cursorPos: span.start };
4828
4677
  }
4829
- function popLastAttachedImage(images) {
4830
- if (images.length === 0) return { handled: false, images };
4831
- return {
4832
- handled: true,
4833
- images: images.slice(0, -1),
4834
- removed: images[images.length - 1]
4835
- };
4678
+ function deleteBufferRange(buffer, start, end, pasteStore) {
4679
+ if (start >= end) return { buffer, cursorPos: start };
4680
+ const range = expandRangeToCollapsedPasteChips(buffer, start, end);
4681
+ releasePastesInRange(buffer, range.start, range.end, pasteStore);
4682
+ const nextBuf = buffer.slice(0, range.start) + buffer.slice(range.end);
4683
+ return { buffer: nextBuf, cursorPos: range.start };
4836
4684
  }
4837
- function mergeAttachedImages(existing, incoming) {
4838
- if (incoming.length === 0) return existing;
4839
- if (existing.length === 0) return [...incoming];
4840
- const incomingByPath = /* @__PURE__ */ new Map();
4841
- for (const img of incoming) incomingByPath.set(img.sourcePath, img);
4842
- const out = [];
4843
- const seen = /* @__PURE__ */ new Set();
4844
- for (const img of existing) {
4845
- if (seen.has(img.sourcePath)) continue;
4846
- const override = incomingByPath.get(img.sourcePath);
4847
- out.push(override ?? img);
4848
- seen.add(img.sourcePath);
4849
- }
4850
- for (const img of incoming) {
4851
- if (seen.has(img.sourcePath)) continue;
4852
- out.push(img);
4853
- seen.add(img.sourcePath);
4685
+ function releasePastesInRange(buffer, start, end, pasteStore) {
4686
+ if (!pasteStore || start >= end) return;
4687
+ const slice = buffer.slice(start, end);
4688
+ COLLAPSED_PASTE_PLACEHOLDER_RE.lastIndex = 0;
4689
+ let match;
4690
+ while ((match = COLLAPSED_PASTE_PLACEHOLDER_RE.exec(slice)) !== null) {
4691
+ releaseCollapsedPaste(pasteStore, Number(match[1]));
4854
4692
  }
4855
- return out;
4856
4693
  }
4857
- async function readImagePaths(paths, options = {}) {
4858
- const resolve4 = options.resolve ?? ((p) => p);
4859
- const reportedFailures = /* @__PURE__ */ new Set();
4860
- const images = [];
4861
- const failures = [];
4862
- for (const raw of paths) {
4863
- const absolute = resolve4(raw);
4864
- try {
4865
- const img = await readImageAsDataUrl(absolute, {
4866
- ...options.maxBytes !== void 0 ? { maxBytes: options.maxBytes } : {}
4867
- });
4868
- images.push(img);
4869
- options.onSuccess?.(img);
4870
- } catch (error) {
4871
- const err = error instanceof Error ? error : new Error(String(error));
4872
- if (!reportedFailures.has(absolute)) {
4873
- reportedFailures.add(absolute);
4874
- failures.push(absolute);
4875
- options.onFailure?.(absolute, err);
4876
- }
4877
- }
4694
+ var CJK_CHAR = /[\u4e00-\u9fff\u3000-\u303f\uff00-\uffef]/;
4695
+ function findWordStartLeft(buffer, curPos) {
4696
+ let i = curPos;
4697
+ while (i > 0 && /\s/.test(buffer[i - 1])) i--;
4698
+ if (i === 0) return 0;
4699
+ const spanAtCursor = findCollapsedPasteSpanAt(buffer, i, {
4700
+ preferLeft: true
4701
+ });
4702
+ if (spanAtCursor && (i === spanAtCursor.end || i > spanAtCursor.start && i < spanAtCursor.end)) {
4703
+ return spanAtCursor.start;
4878
4704
  }
4879
- return { images, failures };
4705
+ if (CJK_CHAR.test(buffer[i - 1])) return i - 1;
4706
+ while (i > 0 && !/\s/.test(buffer[i - 1]) && !CJK_CHAR.test(buffer[i - 1])) {
4707
+ const span = findCollapsedPasteSpanAt(buffer, i, { preferLeft: true });
4708
+ if (span && i === span.end) break;
4709
+ i--;
4710
+ }
4711
+ return i;
4880
4712
  }
4881
- async function resolveAttachmentImageUrls({
4882
- actionImagePaths,
4883
- attachedImages,
4884
- onFailure
4885
- }) {
4886
- const pathsToRead = [
4887
- ...actionImagePaths ?? [],
4888
- ...attachedImages.map((img) => img.sourcePath)
4889
- ];
4890
- let imageUrls = [];
4891
- if (pathsToRead.length > 0) {
4892
- const readResult = await readImagePaths(pathsToRead, {
4893
- onFailure
4894
- });
4895
- imageUrls = readResult.images.map((img) => img.dataUrl);
4713
+ function isDeleteWordSequence(seq, key) {
4714
+ if (key.ctrl && key.name === "w") return true;
4715
+ if ((key.ctrl || key.meta) && key.name === "backspace") return true;
4716
+ if (seq === "" || seq === "\x1B\x7F") return true;
4717
+ return false;
4718
+ }
4719
+ function isKillToLineStartSequence(seq, key) {
4720
+ if (key.ctrl && key.name === "u") return true;
4721
+ if (seq === "") return true;
4722
+ return false;
4723
+ }
4724
+ function isKillToLineEndSequence(seq, key) {
4725
+ if (key.ctrl && key.name === "k") return true;
4726
+ if (seq === "\v") return true;
4727
+ return false;
4728
+ }
4729
+ function isBackspaceSequence(seq, key) {
4730
+ if (key.name === "backspace") return true;
4731
+ if (seq === "\b" || seq === "\x7F") return true;
4732
+ return /^\x1b\[27;\d+;8~$/.test(seq);
4733
+ }
4734
+ function isForwardDeleteSequence(seq, key) {
4735
+ if (key.name === "delete") return true;
4736
+ return /^\x1b\[3(?:;\d+)*~$/.test(seq);
4737
+ }
4738
+ var SLASH_COMMANDS = [
4739
+ "/help",
4740
+ "/new",
4741
+ "/clear",
4742
+ "/compact",
4743
+ "/theme",
4744
+ "/context",
4745
+ "/ctx",
4746
+ "/credits",
4747
+ "/links",
4748
+ "/cd",
4749
+ "/runtime",
4750
+ "/auto",
4751
+ "/switch",
4752
+ "/agent",
4753
+ "/agents",
4754
+ "/history",
4755
+ "/resume",
4756
+ "/lang",
4757
+ "/copy",
4758
+ "/paste",
4759
+ "/mouse",
4760
+ "/math",
4761
+ "/doc",
4762
+ "/skill",
4763
+ "/customize",
4764
+ "/login",
4765
+ "/profile",
4766
+ "/update",
4767
+ "/version",
4768
+ "/logs",
4769
+ "/tasks",
4770
+ "/jobs",
4771
+ "/procs",
4772
+ "/stop",
4773
+ "/exit",
4774
+ "/quit"
4775
+ ];
4776
+ function completeSlashPrefix(buffer) {
4777
+ if (!buffer.startsWith("/") || /\s/.test(buffer)) return null;
4778
+ const matches = SLASH_COMMANDS.filter((cmd) => cmd.startsWith(buffer));
4779
+ if (matches.length === 0) return null;
4780
+ if (matches.length === 1) {
4781
+ return `${matches[0]} `;
4896
4782
  }
4897
- return { imageUrls };
4783
+ let prefix = matches[0];
4784
+ for (const cmd of matches) {
4785
+ while (!cmd.startsWith(prefix)) prefix = prefix.slice(0, -1);
4786
+ }
4787
+ return prefix.length > buffer.length ? prefix : null;
4788
+ }
4789
+ function completeSlashCommand(buffer, cwd) {
4790
+ if (!buffer.startsWith("/")) return [];
4791
+ const trimmed = buffer.trim();
4792
+ if (cwd && buffer.startsWith("/cd ")) {
4793
+ const prefix = buffer.slice("/cd ".length);
4794
+ return completeCdPathCandidates(prefix, cwd);
4795
+ }
4796
+ if (trimmed.includes(" ")) return [];
4797
+ return SLASH_COMMANDS.filter((cmd) => cmd.startsWith(trimmed) && cmd !== trimmed);
4798
+ }
4799
+ function completeCdPathCandidates(prefix, cwd) {
4800
+ const lastSlash = prefix.lastIndexOf("/");
4801
+ const head = lastSlash >= 0 ? prefix.slice(0, lastSlash + 1) : "";
4802
+ const baseName = lastSlash >= 0 ? prefix.slice(lastSlash + 1) : prefix;
4803
+ let dirPath;
4804
+ if (head === "~" || head === "~/" || head === "~\\") {
4805
+ dirPath = homedir();
4806
+ } else if (head.startsWith("~/") || head.startsWith("~\\")) {
4807
+ dirPath = resolve(homedir(), head.slice(2));
4808
+ } else {
4809
+ dirPath = head.startsWith("/") ? head : resolve(cwd, head);
4810
+ }
4811
+ let entries;
4812
+ try {
4813
+ entries = readdirSync(dirPath, { withFileTypes: true });
4814
+ } catch {
4815
+ return [];
4816
+ }
4817
+ const hiddenRequested = baseName.startsWith(".");
4818
+ const names = entries.filter((e) => {
4819
+ if (e.isDirectory()) return true;
4820
+ if (!e.isSymbolicLink()) return false;
4821
+ try {
4822
+ return statSync(resolve(dirPath, e.name)).isDirectory();
4823
+ } catch {
4824
+ return false;
4825
+ }
4826
+ }).map((e) => e.name).filter((name) => {
4827
+ if (!name.startsWith(baseName)) return false;
4828
+ return hiddenRequested || !name.startsWith(".");
4829
+ }).sort();
4830
+ return names.map((name) => `/cd ${head}${name}/`);
4831
+ }
4832
+ function isLikelySlashCommand(input) {
4833
+ const trimmed = input.trim();
4834
+ if (!trimmed.startsWith("/")) return false;
4835
+ const spaceIdx = trimmed.search(/\s/);
4836
+ const firstToken = spaceIdx === -1 ? trimmed : trimmed.slice(0, spaceIdx);
4837
+ return /^\/[a-zA-Z_][a-zA-Z0-9._:-]*$/.test(firstToken);
4838
+ }
4839
+ function stripImageTokens(input, hints) {
4840
+ if (hints.length === 0) return input;
4841
+ let out = input;
4842
+ for (const hint of hints) {
4843
+ if (!hint.raw) continue;
4844
+ const escaped = hint.raw.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
4845
+ out = out.replace(new RegExp(escaped, "g"), "");
4846
+ }
4847
+ return compactWhitespace(out);
4898
4848
  }
4899
4849
 
4900
- // packages/cli/tui/clipboardImage.ts
4901
- import { createHash } from "node:crypto";
4902
- import { mkdirSync } from "node:fs";
4903
- import { readdir, stat as stat2, unlink, writeFile } from "node:fs/promises";
4904
- import { tmpdir } from "node:os";
4905
- import { join } from "node:path";
4906
- var ClipboardImageError = class extends Error {
4850
+ // packages/cli/tui/pasteImage.ts
4851
+ var IMAGE_EXTENSIONS = ["png", "jpg", "jpeg", "gif", "webp"];
4852
+ var IMAGE_EXTENSION_SET = new Set(IMAGE_EXTENSIONS.map((ext) => ext.toLowerCase()));
4853
+ var MIME_BY_EXTENSION = {
4854
+ png: "image/png",
4855
+ jpg: "image/jpeg",
4856
+ jpeg: "image/jpeg",
4857
+ gif: "image/gif",
4858
+ webp: "image/webp"
4859
+ };
4860
+ var DEFAULT_MAX_IMAGE_BYTES = 4 * 1024 * 1024;
4861
+ var ImageReadError = class extends Error {
4907
4862
  code;
4908
- constructor(code, message) {
4863
+ path;
4864
+ constructor(code, path, message) {
4909
4865
  super(message);
4910
4866
  this.code = code;
4911
- this.name = "ClipboardImageError";
4867
+ this.path = path;
4868
+ this.name = "ImageReadError";
4912
4869
  }
4913
4870
  };
4914
- var DEFAULT_CLIPBOARD_TIMEOUT_MS = 3e4;
4915
- var CLIPBOARD_TEMP_DIR_NAME = "nolo-clipboard";
4916
- function getDefaultClipboardTempDir() {
4917
- return join(tmpdir(), CLIPBOARD_TEMP_DIR_NAME);
4871
+ function extnameOf(path) {
4872
+ const slash = Math.max(path.lastIndexOf("/"), path.lastIndexOf("\\"));
4873
+ const base = slash >= 0 ? path.slice(slash + 1) : path;
4874
+ const dot = base.lastIndexOf(".");
4875
+ if (dot <= 0) return "";
4876
+ return base.slice(dot + 1).toLowerCase();
4918
4877
  }
4919
- var CLIPBOARD_SWEEP_MAX_AGE_MS = 24 * 60 * 60 * 1e3;
4920
- var CLIPBOARD_SWEEP_FILE_RE = /^clip-[0-9a-f]{8,}\.(png|jpg|jpeg|gif|webp)$/;
4921
- async function sweepStaleClipboardFiles(tempDir, opts = {}) {
4878
+ function basenameOf(path) {
4879
+ const slash = Math.max(path.lastIndexOf("/"), path.lastIndexOf("\\"));
4880
+ return slash >= 0 ? path.slice(slash + 1) : path;
4881
+ }
4882
+ function isWslEnvironment() {
4883
+ if (process.env.WSL_DISTRO_NAME) return true;
4922
4884
  try {
4923
- const maxAgeMs = opts.maxAgeMs ?? CLIPBOARD_SWEEP_MAX_AGE_MS;
4924
- const now = opts.now ?? Date.now();
4925
- const entries = await readdir(tempDir);
4926
- let removed = 0;
4927
- for (const name of entries) {
4928
- if (!CLIPBOARD_SWEEP_FILE_RE.test(name)) continue;
4929
- try {
4930
- const fullPath = join(tempDir, name);
4931
- const stats = await stat2(fullPath);
4932
- if (stats.mtimeMs >= now - maxAgeMs) continue;
4933
- await unlink(fullPath);
4934
- removed += 1;
4935
- } catch {
4936
- }
4937
- }
4938
- return removed;
4885
+ const version2 = readFileSync("/proc/version", "utf8");
4886
+ return /microsoft/i.test(version2);
4939
4887
  } catch {
4940
- return 0;
4888
+ return false;
4941
4889
  }
4942
4890
  }
4943
- function isRemoteSession(env = process.env) {
4944
- return Boolean(env.SSH_CONNECTION || env.SSH_TTY || env.SSH_CLIENT);
4891
+ var WINDOWS_DRIVE_RE = /^([a-zA-Z]):[\\/](.*)$/s;
4892
+ function mapWindowsPathToWsl(rawPath) {
4893
+ const m = WINDOWS_DRIVE_RE.exec(rawPath);
4894
+ if (!m) return rawPath;
4895
+ const drive = m[1].toLowerCase();
4896
+ const rest = m[2].replace(/[\\/]+/g, "/");
4897
+ return `/mnt/${drive}/${rest}`.replace(/\/+/g, "/");
4945
4898
  }
4946
- function getClipboardImageCommand(deps = {}) {
4947
- const env = deps.env ?? process.env;
4948
- const platform = deps.platform ?? process.platform;
4949
- const which = deps.which ?? Bun.which;
4950
- if (isRemoteSession(env)) {
4951
- throw new ClipboardImageError(
4952
- "remote-session",
4953
- "\u8FDC\u7A0B\u4F1A\u8BDD\u65E0\u6CD5\u8BFB\u53D6\u672C\u5730\u526A\u8D34\u677F\uFF0C\u8BF7\u62D6\u5165\u56FE\u7247\u6587\u4EF6\u6216\u76F4\u63A5\u8F93\u5165\u56FE\u7247\u8DEF\u5F84"
4954
- );
4899
+ function fileUriToPath(rawPath) {
4900
+ if (!/^file:\/\//i.test(rawPath)) return null;
4901
+ const rest = rawPath.slice("file://".length);
4902
+ const slash = rest.indexOf("/");
4903
+ if (slash < 0) return null;
4904
+ const pathPart = rest.slice(slash);
4905
+ try {
4906
+ return decodeURIComponent(pathPart);
4907
+ } catch {
4908
+ return pathPart;
4955
4909
  }
4956
- if (platform === "darwin") {
4957
- const pngpaste = which("pngpaste");
4958
- if (pngpaste) {
4959
- return { command: [pngpaste, "-"], outputFormat: "raw" };
4960
- }
4961
- const osascript = which("osascript");
4962
- if (!osascript) {
4963
- throw new ClipboardImageError(
4964
- "binary-missing",
4965
- "\u672A\u627E\u5230 pngpaste\uFF0C\u4E5F\u672A\u627E\u5230\u7CFB\u7EDF\u81EA\u5E26\u7684 osascript\uFF0C\u65E0\u6CD5\u8BFB\u53D6\u526A\u8D34\u677F\u56FE\u50CF\u3002\u8BF7\u8FD0\u884C brew install pngpaste \u5B89\u88C5\uFF0C\u6216\u76F4\u63A5\u62D6\u5165\u56FE\u7247\u6587\u4EF6/\u8F93\u5165\u56FE\u7247\u8DEF\u5F84"
4966
- );
4967
- }
4968
- return {
4969
- command: [osascript, "-e", "the clipboard as \xABclass PNGf\xBB"],
4970
- outputFormat: "osascript-hex"
4971
- };
4910
+ }
4911
+ function resolveImageSource(rawPath, cwd) {
4912
+ let candidate = rawPath.trim();
4913
+ if (!candidate) return candidate;
4914
+ if (candidate === "~") return homedir2();
4915
+ if (candidate.startsWith("~/") || candidate.startsWith("~\\")) {
4916
+ return homedir2() + candidate.slice(1);
4972
4917
  }
4973
- if (platform === "win32") {
4974
- const ps = which("powershell.exe") || which("powershell") || which("pwsh.exe") || which("pwsh");
4975
- if (!ps) {
4976
- throw new ClipboardImageError(
4977
- "binary-missing",
4978
- "\u672A\u627E\u5230 PowerShell\uFF0C\u65E0\u6CD5\u4ECE\u7CFB\u7EDF\u526A\u8D34\u677F\u8BFB\u53D6\u56FE\u50CF\uFF0C\u8BF7\u76F4\u63A5\u62D6\u5165\u56FE\u7247\u6587\u4EF6\u6216\u8F93\u5165\u56FE\u7247\u8DEF\u5F84"
4979
- );
4980
- }
4981
- return {
4982
- command: [
4983
- ps,
4984
- "-NoProfile",
4985
- "-NonInteractive",
4986
- "-Command",
4987
- "$img = Get-Clipboard -Format Image; if ($img) { $ms = New-Object System.IO.MemoryStream; $img.Save($ms, [System.Drawing.Imaging.ImageFormat]::Png); [Console]::OpenStandardOutput().Write($ms.ToArray(), 0, $ms.Length) }"
4988
- ],
4989
- outputFormat: "raw"
4990
- };
4918
+ if (isAbsolute(candidate)) return candidate;
4919
+ return resolve2(cwd, candidate);
4920
+ }
4921
+ function isImagePath(path) {
4922
+ return IMAGE_EXTENSION_SET.has(extnameOf(path));
4923
+ }
4924
+ function isReadableFilePath(path) {
4925
+ try {
4926
+ statSync2(path);
4927
+ return true;
4928
+ } catch {
4929
+ return false;
4991
4930
  }
4992
- if (platform === "linux") {
4993
- const isWayland = Boolean(env.WAYLAND_DISPLAY);
4994
- if (isWayland) {
4995
- const wlPaste2 = which("wl-paste");
4996
- if (!wlPaste2) {
4997
- throw new ClipboardImageError(
4998
- "binary-missing",
4999
- "\u672A\u627E\u5230 wl-paste\uFF0C\u8BF7\u5B89\u88C5 wl-clipboard (\u4F8B\u5982 sudo apt install wl-clipboard)\uFF0C\u6216\u76F4\u63A5\u62D6\u5165\u56FE\u7247\u6587\u4EF6/\u8F93\u5165\u56FE\u7247\u8DEF\u5F84"
5000
- );
5001
- }
5002
- return { command: [wlPaste2, "--type", "image/png"], outputFormat: "raw" };
5003
- }
5004
- const xclip = which("xclip");
5005
- if (xclip) {
5006
- return {
5007
- command: [xclip, "-selection", "clipboard", "-t", "image/png", "-o"],
5008
- outputFormat: "raw"
5009
- };
5010
- }
5011
- const wlPaste = which("wl-paste");
5012
- if (wlPaste) {
5013
- return { command: [wlPaste, "--type", "image/png"], outputFormat: "raw" };
4931
+ }
4932
+ function detectImagePaths(line, cwd, opts = {}) {
4933
+ const wsl = opts.wsl ?? isWslEnvironment();
4934
+ const tokens = tokenizePasteLine(line);
4935
+ const out = [];
4936
+ for (const token of tokens) {
4937
+ if (!token.raw) continue;
4938
+ let candidate = token.decoded;
4939
+ const uriPath = fileUriToPath(candidate);
4940
+ if (uriPath !== null) candidate = uriPath;
4941
+ if (wsl) candidate = mapWindowsPathToWsl(candidate);
4942
+ const resolved = resolveImageSource(candidate, cwd);
4943
+ if (!isImagePath(resolved)) continue;
4944
+ if (!isReadableFilePath(resolved)) {
4945
+ out.push({ raw: token.raw, resolvedPath: resolved, unreadable: true });
4946
+ continue;
5014
4947
  }
5015
- throw new ClipboardImageError(
5016
- "binary-missing",
5017
- "\u672A\u627E\u5230 xclip\uFF0C\u8BF7\u5B89\u88C5 xclip (\u4F8B\u5982 sudo apt install xclip)\uFF0C\u6216\u76F4\u63A5\u62D6\u5165\u56FE\u7247\u6587\u4EF6/\u8F93\u5165\u56FE\u7247\u8DEF\u5F84"
5018
- );
4948
+ out.push({ raw: token.raw, resolvedPath: resolved });
5019
4949
  }
5020
- throw new ClipboardImageError(
5021
- "unsupported-platform",
5022
- `\u5F53\u524D\u64CD\u4F5C\u7CFB\u7EDF\u6682\u4E0D\u652F\u6301\u526A\u8D34\u677F\u56FE\u50CF\u8BFB\u53D6: ${platform}`
5023
- );
4950
+ return out;
5024
4951
  }
5025
- var OSASCRIPT_EMPTY_CLIPBOARD_MESSAGE = "\u526A\u8D34\u677F\u4E2D\u6CA1\u6709\u56FE\u50CF\u6570\u636E\u3002\u53EF\u76F4\u63A5\u62D6\u5165\u56FE\u7247\u6587\u4EF6\u3001\u8F93\u5165\u56FE\u7247\u8DEF\u5F84\uFF0C\u6216\u8FD0\u884C brew install pngpaste \u4EE5\u652F\u6301\u66F4\u591A\u56FE\u7247\u683C\u5F0F";
5026
- function decodeOsascriptPngHex(text) {
5027
- const match = /PNGf\s*([0-9A-Fa-f]*)/.exec(text);
5028
- if (!match) return { kind: "empty" };
5029
- const hex = match[1] ?? "";
5030
- const tail = text.slice(match.index + match[0].length).replace(/[\s»]*$/, "");
5031
- if (tail.length > 0) return { kind: "invalid" };
5032
- if (hex.length === 0) return { kind: "empty" };
5033
- if (hex.length % 2 !== 0) return { kind: "invalid" };
5034
- const bytes = new Uint8Array(hex.length / 2);
5035
- for (let i = 0; i < bytes.length; i += 1) {
5036
- bytes[i] = Number.parseInt(hex.slice(i * 2, i * 2 + 2), 16);
4952
+ function detectFileReferences(line, cwd, opts = {}) {
4953
+ const wsl = opts.wsl ?? isWslEnvironment();
4954
+ const excluded = new Set(opts.exclude ?? []);
4955
+ const out = [];
4956
+ const seen = /* @__PURE__ */ new Set();
4957
+ for (const token of tokenizePasteLine(line)) {
4958
+ if (!token.raw || excluded.has(token.raw)) continue;
4959
+ let candidate = token.decoded;
4960
+ const uriPath = fileUriToPath(candidate);
4961
+ if (uriPath !== null) candidate = uriPath;
4962
+ if (wsl) candidate = mapWindowsPathToWsl(candidate);
4963
+ if (candidate.startsWith("~")) candidate = resolveImageSource(candidate, cwd);
4964
+ const looksLikePath = /[/\\]/.test(candidate) || candidate.startsWith("~") || /^[a-zA-Z]:/.test(candidate);
4965
+ if (!looksLikePath) continue;
4966
+ const ext = extnameOf(candidate);
4967
+ if (!/^[a-z0-9]{1,8}$/.test(ext)) continue;
4968
+ if (IMAGE_EXTENSION_SET.has(ext)) continue;
4969
+ const resolved = resolveImageSource(candidate, cwd);
4970
+ if (excluded.has(resolved) || seen.has(resolved)) continue;
4971
+ if (!isReadableFilePath(resolved)) continue;
4972
+ try {
4973
+ if (!statSync2(resolved).isFile()) continue;
4974
+ } catch {
4975
+ continue;
4976
+ }
4977
+ seen.add(resolved);
4978
+ out.push({ raw: token.raw, resolvedPath: resolved });
5037
4979
  }
5038
- return { kind: "bytes", bytes };
4980
+ return out;
5039
4981
  }
5040
- async function readClipboardImage(deps = {}) {
5041
- const env = deps.env ?? process.env;
5042
- const platform = deps.platform ?? process.platform;
5043
- const which = deps.which ?? Bun.which;
5044
- const spawn = deps.spawn ?? Bun.spawn;
5045
- const maxBytes = deps.maxBytes ?? DEFAULT_MAX_IMAGE_BYTES;
5046
- const timeoutMs = deps.timeoutMs ?? DEFAULT_CLIPBOARD_TIMEOUT_MS;
5047
- const tempDir = deps.tempDir ?? getDefaultClipboardTempDir();
5048
- const { command, outputFormat } = getClipboardImageCommand({
5049
- env,
5050
- platform,
5051
- which
5052
- });
5053
- let stdoutBuf;
5054
- try {
5055
- const proc = spawn(command, {
5056
- stdin: "ignore",
5057
- stdout: "pipe",
5058
- stderr: "pipe"
5059
- });
5060
- let timeout;
5061
- const timeoutPromise = new Promise((_, reject) => {
5062
- timeout = setTimeout(() => {
5063
- proc.kill();
5064
- reject(
5065
- new ClipboardImageError(
5066
- "read-failed",
5067
- "\u8BFB\u53D6\u526A\u8D34\u677F\u8D85\u65F6\uFF0C\u526A\u8D34\u677F\u540E\u7AEF\u53EF\u80FD\u65E0\u54CD\u5E94"
5068
- )
5069
- );
5070
- }, timeoutMs);
5071
- });
5072
- try {
5073
- const [stdoutArrayBuffer, stderrText, exitCode] = await Promise.race([
5074
- Promise.all([
5075
- new Response(proc.stdout).arrayBuffer(),
5076
- new Response(proc.stderr).text(),
5077
- proc.exited
5078
- ]),
5079
- timeoutPromise
5080
- ]);
5081
- if (exitCode !== 0 || stdoutArrayBuffer.byteLength === 0) {
5082
- if (outputFormat === "osascript-hex") {
5083
- throw new ClipboardImageError(
5084
- "empty-clipboard",
5085
- OSASCRIPT_EMPTY_CLIPBOARD_MESSAGE + (stderrText.trim() ? `: ${stderrText.trim()}` : "")
5086
- );
5087
- }
5088
- throw new ClipboardImageError(
5089
- "empty-clipboard",
5090
- "\u526A\u8D34\u677F\u4E2D\u6CA1\u6709\u56FE\u50CF\u6570\u636E\uFF0C\u8BF7\u76F4\u63A5\u62D6\u5165\u56FE\u7247\u6587\u4EF6\u6216\u8F93\u5165\u56FE\u7247\u8DEF\u5F84" + (stderrText.trim() ? `: ${stderrText.trim()}` : "")
5091
- );
4982
+ function tokenizePasteLine(line) {
4983
+ const tokens = [];
4984
+ let rawBuf = "";
4985
+ let decBuf = "";
4986
+ let quote = null;
4987
+ const push = () => {
4988
+ if (rawBuf.length > 0) {
4989
+ tokens.push({ raw: rawBuf, decoded: decBuf });
4990
+ rawBuf = "";
4991
+ decBuf = "";
4992
+ }
4993
+ };
4994
+ for (let i = 0; i < line.length; i++) {
4995
+ const ch = line[i];
4996
+ const next = line[i + 1];
4997
+ if (quote) {
4998
+ if (ch === "\\" && next !== void 0) {
4999
+ rawBuf += ch + next;
5000
+ decBuf += next;
5001
+ i++;
5002
+ continue;
5092
5003
  }
5093
- stdoutBuf = new Uint8Array(stdoutArrayBuffer);
5094
- } finally {
5095
- clearTimeout(timeout);
5004
+ if (ch === quote) {
5005
+ quote = null;
5006
+ rawBuf += ch;
5007
+ continue;
5008
+ }
5009
+ rawBuf += ch;
5010
+ decBuf += ch;
5011
+ continue;
5096
5012
  }
5097
- } catch (err) {
5098
- if (err instanceof ClipboardImageError) {
5099
- throw err;
5013
+ if (ch === "\\" && next !== void 0 && /\s/.test(next)) {
5014
+ rawBuf += ch + next;
5015
+ decBuf += next;
5016
+ i++;
5017
+ continue;
5100
5018
  }
5101
- throw new ClipboardImageError(
5102
- "read-failed",
5103
- `\u8BFB\u53D6\u526A\u8D34\u677F\u56FE\u50CF\u5931\u8D25: ${err instanceof Error ? err.message : String(err)}`
5104
- );
5105
- }
5106
- if (outputFormat === "osascript-hex") {
5107
- const text = Buffer.from(stdoutBuf).toString("utf8");
5108
- const decoded = decodeOsascriptPngHex(text);
5109
- if (decoded.kind === "empty") {
5110
- throw new ClipboardImageError(
5111
- "empty-clipboard",
5112
- OSASCRIPT_EMPTY_CLIPBOARD_MESSAGE
5113
- );
5019
+ if (ch === "\\" && next === "\\") {
5020
+ rawBuf += "\\\\";
5021
+ decBuf += "\\";
5022
+ i++;
5023
+ continue;
5114
5024
  }
5115
- if (decoded.kind === "invalid") {
5116
- throw new ClipboardImageError(
5117
- "read-failed",
5118
- "\u526A\u8D34\u677F\u56FE\u50CF\u6570\u636E\u65E0\u6CD5\u89E3\u6790\uFF08hex \u7F16\u7801\u635F\u574F\uFF09\uFF0C\u8BF7\u91CD\u65B0\u590D\u5236\u56FE\u7247\u540E\u91CD\u8BD5\uFF0C\u6216\u76F4\u63A5\u62D6\u5165\u56FE\u7247\u6587\u4EF6/\u8F93\u5165\u56FE\u7247\u8DEF\u5F84"
5119
- );
5025
+ if (ch === '"' || ch === "'") {
5026
+ quote = ch;
5027
+ rawBuf += ch;
5028
+ continue;
5120
5029
  }
5121
- stdoutBuf = decoded.bytes;
5030
+ if (/\s/.test(ch)) {
5031
+ push();
5032
+ continue;
5033
+ }
5034
+ rawBuf += ch;
5035
+ decBuf += ch;
5122
5036
  }
5123
- const compressResult = await compressImage(stdoutBuf, "image/png");
5124
- const finalBuf = compressResult.buffer;
5125
- const finalMime = compressResult.mime;
5126
- const finalSizeBytes = finalBuf.byteLength;
5127
- if (finalSizeBytes > maxBytes) {
5128
- throw new ClipboardImageError(
5129
- "too-large",
5130
- `\u526A\u8D34\u677F\u56FE\u50CF\u8FC7\u5927: ${formatBytes(finalSizeBytes)} (\u4E0A\u9650 ${formatBytes(maxBytes)})`
5131
- );
5037
+ push();
5038
+ return tokens;
5039
+ }
5040
+ async function readImageAsDataUrl(absolutePath, options = {}) {
5041
+ const maxBytes = options.maxBytes ?? DEFAULT_MAX_IMAGE_BYTES;
5042
+ let stats;
5043
+ try {
5044
+ stats = await stat(absolutePath);
5045
+ } catch (error) {
5046
+ throw classifyFsError(error, absolutePath);
5047
+ }
5048
+ if (stats.isDirectory()) {
5049
+ throw new ImageReadError(
5050
+ "is-directory",
5051
+ absolutePath,
5052
+ `path is a directory, not an image: ${absolutePath}`
5053
+ );
5054
+ }
5055
+ const ext = extnameOf(absolutePath);
5056
+ if (!ext || !IMAGE_EXTENSION_SET.has(ext)) {
5057
+ throw new ImageReadError(
5058
+ "unsupported-extension",
5059
+ absolutePath,
5060
+ `unsupported image extension: .${ext || "(none)"}`
5061
+ );
5062
+ }
5063
+ let buffer;
5064
+ try {
5065
+ buffer = await readFile(absolutePath);
5066
+ } catch (error) {
5067
+ throw classifyFsError(error, absolutePath);
5068
+ }
5069
+ const rawMime = MIME_BY_EXTENSION[ext];
5070
+ const compressResult = await compressImage(buffer, rawMime);
5071
+ const finalBuffer = compressResult.buffer;
5072
+ const finalMime = compressResult.mime;
5073
+ const finalSizeBytes = finalBuffer.byteLength;
5074
+ if (finalSizeBytes > maxBytes) {
5075
+ throw new ImageReadError(
5076
+ "too-large",
5077
+ absolutePath,
5078
+ `image too large: ${formatBytes(finalSizeBytes)} (limit ${formatBytes(maxBytes)})`
5079
+ );
5132
5080
  }
5133
- const hash = createHash("sha256").update(finalBuf).digest("hex").slice(0, 12);
5134
- const ext = mimeToExtension(finalMime);
5135
- const filename = `clip-${hash}.${ext}`;
5136
- mkdirSync(tempDir, { recursive: true });
5137
- const filePath = join(tempDir, filename);
5138
- await writeFile(filePath, finalBuf);
5139
5081
  return buildAttachedImage({
5140
- buffer: finalBuf,
5082
+ buffer: finalBuffer,
5141
5083
  mime: finalMime,
5142
- filename,
5143
- sourcePath: filePath,
5084
+ filename: basenameOf(absolutePath),
5085
+ sourcePath: absolutePath,
5144
5086
  originalSizeBytes: compressResult.compressed ? compressResult.originalBytes : void 0
5145
5087
  });
5146
5088
  }
5147
-
5148
- // packages/cli/tui/pasteFlow.ts
5149
- function isTextFallbackEligibleCode(code) {
5150
- return code === "empty-clipboard" || code === "binary-missing" || code === "unsupported-platform";
5089
+ function classifyFsError(error, path) {
5090
+ const code = error?.code;
5091
+ const message = toErrorMessage(error);
5092
+ switch (code) {
5093
+ case "ENOENT":
5094
+ return new ImageReadError("not-found", path, `image not found: ${path}`);
5095
+ case "EACCES":
5096
+ case "EPERM":
5097
+ return new ImageReadError(
5098
+ "permission-denied",
5099
+ path,
5100
+ `cannot read image (permission denied): ${path}`
5101
+ );
5102
+ case "EISDIR":
5103
+ return new ImageReadError(
5104
+ "is-directory",
5105
+ path,
5106
+ `path is a directory, not an image: ${path}`
5107
+ );
5108
+ default:
5109
+ return new ImageReadError("io-error", path, `failed to read image: ${message}`);
5110
+ }
5151
5111
  }
5152
- function errorCodeOf(error) {
5153
- if (typeof error !== "object" || error === null) return void 0;
5154
- const code = error.code;
5155
- return code === void 0 || code === null ? void 0 : String(code);
5112
+ function buildAttachedImage(params) {
5113
+ const sizeBytes = params.buffer.byteLength;
5114
+ const base64 = Buffer.from(params.buffer).toString("base64");
5115
+ const dataUrl = `data:${params.mime};base64,${base64}`;
5116
+ return {
5117
+ dataUrl,
5118
+ mime: params.mime,
5119
+ filename: params.filename,
5120
+ sizeBytes,
5121
+ sourcePath: params.sourcePath,
5122
+ ...typeof params.originalSizeBytes === "number" && params.originalSizeBytes > sizeBytes ? { originalSizeBytes: params.originalSizeBytes } : {}
5123
+ };
5156
5124
  }
5157
- function messageOf(error) {
5158
- return error instanceof Error ? error.message : String(error);
5125
+ function describeImageSize(img, options = {}) {
5126
+ const isCompressed = typeof img.originalSizeBytes === "number" && img.originalSizeBytes > img.sizeBytes;
5127
+ const core = isCompressed ? `${formatBytes(img.sizeBytes)} (\u5DF2\u538B\u7F29 ${formatBytes(img.originalSizeBytes)} \u2192 ${formatBytes(img.sizeBytes)})` : formatBytes(img.sizeBytes);
5128
+ return options.prefix ? `Size: ${core}` : core;
5159
5129
  }
5160
- async function resolveClipboardPaste(deps) {
5161
- try {
5162
- const image = await deps.readImage();
5163
- return { kind: "image", image };
5164
- } catch (imageError) {
5165
- const code = errorCodeOf(imageError);
5166
- if (!isTextFallbackEligibleCode(code)) {
5167
- return {
5168
- kind: "error",
5169
- code: code ?? "read-failed",
5170
- message: messageOf(imageError)
5171
- };
5172
- }
5173
- let text;
5174
- try {
5175
- text = await deps.readText();
5176
- } catch (textError) {
5177
- return {
5178
- kind: "error",
5179
- code: "text-read-failed",
5180
- message: `${messageOf(textError)} (${messageOf(imageError)})`
5181
- };
5182
- }
5183
- if (text.length > 0) {
5184
- return { kind: "text", text };
5185
- }
5186
- return { kind: "empty", message: messageOf(imageError) };
5187
- }
5130
+ function formatBytes(bytes) {
5131
+ if (bytes < 1024) return `${bytes} B`;
5132
+ if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
5133
+ return `${(bytes / 1024 / 1024).toFixed(1)} MB`;
5188
5134
  }
5189
- function shouldApplyPastedResult(snapshot, current) {
5190
- if (current.sessionEnded) return false;
5191
- return snapshot.epoch === current.epoch;
5135
+ function summarizeAttachment(img) {
5136
+ const colorEnabled = resolveCliColorEnabled();
5137
+ const sizeText = describeImageSize(img, { prefix: true });
5138
+ const titleRaw = "\u{1F4F7} [Attached Image]";
5139
+ const nameRaw = `Name: ${img.filename}`;
5140
+ const boxWidth = Math.max(40, titleRaw.length + 4, nameRaw.length + 4, sizeText.length + 4);
5141
+ const border = "\u250C" + "\u2500".repeat(boxWidth - 2) + "\u2510";
5142
+ const bottom = "\u2514" + "\u2500".repeat(boxWidth - 2) + "\u2518";
5143
+ const padLine = (content) => {
5144
+ const padded = content.padEnd(boxWidth - 4, " ");
5145
+ return `\u2502 ${padded} \u2502`;
5146
+ };
5147
+ const title = padLine(titleRaw);
5148
+ const name = padLine(nameRaw);
5149
+ const size = padLine(sizeText);
5150
+ const text = [
5151
+ border,
5152
+ title,
5153
+ name,
5154
+ size,
5155
+ bottom
5156
+ ].join("\n");
5157
+ return themeText(text, "chrome", colorEnabled);
5192
5158
  }
5193
-
5194
- // packages/cli/tui/clipboard.ts
5195
- function osc52SetClipboard(text, output) {
5196
- const payload = Buffer.from(text, "utf8").toString("base64");
5197
- output.write(`\x1B]52;c;${payload}\x07`);
5159
+ function formatComposerAttachmentLine(images) {
5160
+ if (images.length === 0) return null;
5161
+ const head = images.slice(0, 2).map((img) => `\u{1F4CE} ${img.filename} (${formatBytes(img.sizeBytes)})`);
5162
+ const extra = images.length - head.length;
5163
+ return extra > 0 ? `${head.join(", ")} +${extra}` : head.join(", ");
5198
5164
  }
5199
- async function writeClipboard(text, target) {
5200
- if (target.transport === "system") {
5201
- await target.systemWrite(text);
5202
- return;
5203
- }
5204
- if (target.transport === "osc52") {
5205
- osc52SetClipboard(text, target.output);
5206
- return;
5207
- }
5208
- throw new Error(
5209
- "Client clipboard is unavailable in a non-interactive remote session."
5210
- );
5165
+ function popLastAttachedImage(images) {
5166
+ if (images.length === 0) return { handled: false, images };
5167
+ return {
5168
+ handled: true,
5169
+ images: images.slice(0, -1),
5170
+ removed: images[images.length - 1]
5171
+ };
5211
5172
  }
5212
-
5213
- // packages/cli/tui/gitStatus.ts
5214
- import { execFile, execSync } from "node:child_process";
5215
- function parseStatusOutput(branch, status) {
5216
- if (!status) {
5217
- return { branch, modified: 0, untracked: 0 };
5173
+ function mergeAttachedImages(existing, incoming) {
5174
+ if (incoming.length === 0) return existing;
5175
+ if (existing.length === 0) return [...incoming];
5176
+ const incomingByPath = /* @__PURE__ */ new Map();
5177
+ for (const img of incoming) incomingByPath.set(img.sourcePath, img);
5178
+ const out = [];
5179
+ const seen = /* @__PURE__ */ new Set();
5180
+ for (const img of existing) {
5181
+ if (seen.has(img.sourcePath)) continue;
5182
+ const override = incomingByPath.get(img.sourcePath);
5183
+ out.push(override ?? img);
5184
+ seen.add(img.sourcePath);
5218
5185
  }
5219
- let modified = 0;
5220
- let untracked = 0;
5221
- for (const line of status.split("\n")) {
5222
- if (!line) continue;
5223
- const flag = line[0];
5224
- if (flag === "?") untracked += 1;
5225
- else modified += 1;
5186
+ for (const img of incoming) {
5187
+ if (seen.has(img.sourcePath)) continue;
5188
+ out.push(img);
5189
+ seen.add(img.sourcePath);
5226
5190
  }
5227
- return { branch, modified, untracked };
5228
- }
5229
- function execFileUtf8(file, args, cwd) {
5230
- return new Promise((resolve4, reject) => {
5231
- execFile(
5232
- file,
5233
- args,
5234
- { cwd, encoding: "utf8", timeout: 2e3 },
5235
- (err, stdout) => {
5236
- if (err) {
5237
- reject(err);
5238
- return;
5239
- }
5240
- resolve4(typeof stdout === "string" ? stdout : String(stdout ?? ""));
5241
- }
5242
- );
5243
- });
5191
+ return out;
5244
5192
  }
5245
- function detectGitStatusAsync(cwd) {
5246
- return (async () => {
5193
+ async function readImagePaths(paths, options = {}) {
5194
+ const resolve4 = options.resolve ?? ((p) => p);
5195
+ const reportedFailures = /* @__PURE__ */ new Set();
5196
+ const images = [];
5197
+ const failures = [];
5198
+ for (const raw of paths) {
5199
+ const absolute = resolve4(raw);
5247
5200
  try {
5248
- const branch = (await execFileUtf8("git", ["rev-parse", "--abbrev-ref", "HEAD"], cwd)).trim();
5249
- if (!branch) return void 0;
5250
- const status = (await execFileUtf8("git", ["status", "--porcelain"], cwd)).trim();
5251
- return parseStatusOutput(branch, status);
5252
- } catch {
5253
- return void 0;
5201
+ const img = await readImageAsDataUrl(absolute, {
5202
+ ...options.maxBytes !== void 0 ? { maxBytes: options.maxBytes } : {}
5203
+ });
5204
+ images.push(img);
5205
+ options.onSuccess?.(img);
5206
+ } catch (error) {
5207
+ const err = error instanceof Error ? error : new Error(String(error));
5208
+ if (!reportedFailures.has(absolute)) {
5209
+ reportedFailures.add(absolute);
5210
+ failures.push(absolute);
5211
+ options.onFailure?.(absolute, err);
5212
+ }
5254
5213
  }
5255
- })();
5214
+ }
5215
+ return { images, failures };
5256
5216
  }
5257
-
5258
- // packages/cli/tui/sessionRender.ts
5259
- function formatCwd(cwd) {
5260
- const parts = cwd.split(/[/\\]/);
5261
- return parts.pop() || cwd;
5217
+ async function resolveAttachmentImageUrls({
5218
+ actionImagePaths,
5219
+ attachedImages,
5220
+ onFailure
5221
+ }) {
5222
+ const pathsToRead = [
5223
+ ...actionImagePaths ?? [],
5224
+ ...attachedImages.map((img) => img.sourcePath)
5225
+ ];
5226
+ let imageUrls = [];
5227
+ if (pathsToRead.length > 0) {
5228
+ const readResult = await readImagePaths(pathsToRead, {
5229
+ onFailure
5230
+ });
5231
+ imageUrls = readResult.images.map((img) => img.dataUrl);
5232
+ }
5233
+ return { imageUrls };
5262
5234
  }
5263
- function formatElapsedSeconds(totalSeconds) {
5264
- if (totalSeconds < 60) return `${totalSeconds}s`;
5265
- const minutes = Math.floor(totalSeconds / 60);
5266
- const seconds = totalSeconds % 60;
5267
- if (minutes < 60) return `${minutes}m ${seconds}s`;
5268
- const hours = Math.floor(minutes / 60);
5269
- const mins = minutes % 60;
5270
- return `${hours}h ${mins}m`;
5235
+ function detectSubmittedImagePaths(text, cwd, opts = {}) {
5236
+ const trimmed = text.trim();
5237
+ const hints = detectImagePaths(trimmed, cwd, opts);
5238
+ const readableHints = hints.filter((hint) => !hint.unreadable);
5239
+ const unreadableHints = hints.filter((hint) => hint.unreadable);
5240
+ const stripped = stripImageTokens(trimmed, readableHints);
5241
+ return {
5242
+ hints,
5243
+ imagePaths: readableHints.map((hint) => hint.resolvedPath),
5244
+ unreadableHints,
5245
+ message: stripped.length > 0 ? stripped : trimmed
5246
+ };
5271
5247
  }
5272
- function renderComposerTokenChip(tokens, fallbackContextWindow, estimatedContextTokens) {
5273
- const cw = tokens?.contextWindow ?? fallbackContextWindow;
5274
- if (!cw) {
5275
- return "context: \u2014";
5248
+
5249
+ // packages/cli/tui/clipboardImage.ts
5250
+ import { createHash } from "node:crypto";
5251
+ import { mkdirSync } from "node:fs";
5252
+ import { readdir, stat as stat2, unlink, writeFile } from "node:fs/promises";
5253
+ import { tmpdir } from "node:os";
5254
+ import { join } from "node:path";
5255
+ var ClipboardImageError = class extends Error {
5256
+ code;
5257
+ constructor(code, message) {
5258
+ super(message);
5259
+ this.code = code;
5260
+ this.name = "ClipboardImageError";
5276
5261
  }
5277
- const used = tokens ? tokens.input + tokens.output : Math.max(0, estimatedContextTokens ?? 0);
5278
- const pct = Math.min(100, used / cw * 100);
5279
- const pctText = pct > 0 && pct < 10 ? pct.toFixed(1) : Math.round(pct).toString();
5280
- return `context: ${pctText}% (${formatTokenCount(used)}/${formatTokenCount(cw)})`;
5262
+ };
5263
+ var DEFAULT_CLIPBOARD_TIMEOUT_MS = 3e4;
5264
+ var CLIPBOARD_TEMP_DIR_NAME = "nolo-clipboard";
5265
+ function getDefaultClipboardTempDir() {
5266
+ return join(tmpdir(), CLIPBOARD_TEMP_DIR_NAME);
5281
5267
  }
5282
- function resolveStatusLineCredits(state) {
5283
- const base = state.dialogCreditsBase;
5284
- const session = state.sessionCredits;
5285
- const live = state.liveTurnCredits;
5286
- if (base === void 0 && session === void 0 && live === void 0) {
5287
- return void 0;
5268
+ var CLIPBOARD_SWEEP_MAX_AGE_MS = 24 * 60 * 60 * 1e3;
5269
+ var CLIPBOARD_SWEEP_FILE_RE = /^clip-[0-9a-f]{8,}\.(png|jpg|jpeg|gif|webp)$/;
5270
+ async function sweepStaleClipboardFiles(tempDir, opts = {}) {
5271
+ try {
5272
+ const maxAgeMs = opts.maxAgeMs ?? CLIPBOARD_SWEEP_MAX_AGE_MS;
5273
+ const now = opts.now ?? Date.now();
5274
+ const entries = await readdir(tempDir);
5275
+ let removed = 0;
5276
+ for (const name of entries) {
5277
+ if (!CLIPBOARD_SWEEP_FILE_RE.test(name)) continue;
5278
+ try {
5279
+ const fullPath = join(tempDir, name);
5280
+ const stats = await stat2(fullPath);
5281
+ if (stats.mtimeMs >= now - maxAgeMs) continue;
5282
+ await unlink(fullPath);
5283
+ removed += 1;
5284
+ } catch {
5285
+ }
5286
+ }
5287
+ return removed;
5288
+ } catch {
5289
+ return 0;
5288
5290
  }
5289
- return (base ?? 0) + (session ?? 0) + (live ?? 0);
5290
5291
  }
5291
- function renderStatusLine(state, maxWidth) {
5292
- const colorEnabled = resolveCliColorEnabled();
5293
- const sep = themeText(" \xB7 ", "chrome", colorEnabled);
5294
- const agentDisplayName = state.agentName;
5295
- const modeSuffix = state.modeLabel && state.modeLabel !== "auto" ? ` \xB7 ${state.modeLabel}` : "";
5296
- const agentLabel = `\u2726 ${agentDisplayName}${modeSuffix}`;
5297
- const agentSegment = themeText(agentLabel, "accent", colorEnabled);
5298
- const cwdSegment = themeText(`\u{1F4C1} ${formatCwd(state.cwd)}`, "info", colorEnabled);
5299
- const parts = [agentSegment, cwdSegment];
5300
- if (state.gitStatus) {
5301
- const { branch, modified, untracked } = state.gitStatus;
5302
- const branchText = themeText(`\u2442 ${branch}`, "warning", colorEnabled);
5303
- const modifiedText = modified > 0 ? ` ${themeText(`*${modified}`, "danger", colorEnabled)}` : "";
5304
- const untrackedText = untracked > 0 ? ` ${themeText(`?${untracked}`, "muted", colorEnabled)}` : "";
5305
- parts.push(`${branchText}${modifiedText}${untrackedText}`);
5306
- }
5307
- const credits = resolveStatusLineCredits(state);
5308
- const tokenSegment = themeText(
5309
- renderComposerTokenChip(
5310
- state.turnTokens,
5311
- state.contextWindow,
5312
- state.estimatedContextTokens
5313
- ),
5314
- "muted",
5315
- colorEnabled
5316
- );
5317
- const creditsSegment = credits !== void 0 && credits > 0 ? themeText(formatCreditsChip(credits), "muted", colorEnabled) : "";
5318
- parts.push(tokenSegment);
5319
- if (creditsSegment) parts.push(creditsSegment);
5320
- const runningTaskCount = getProcessRegistry().listBackground().filter((p) => p.status === "running").length;
5321
- if (runningTaskCount > 0) {
5322
- parts.push(themeText(`\u2699 ${runningTaskCount} running`, "info", colorEnabled));
5323
- }
5324
- const pendingProcessCount = state.pendingProcessNotices?.length ?? 0;
5325
- if (pendingProcessCount > 0) {
5326
- parts.push(themeText(`\u2699 ${pendingProcessCount} finished`, "info", colorEnabled));
5292
+ function isRemoteSession(env = process.env) {
5293
+ return Boolean(env.SSH_CONNECTION || env.SSH_TTY || env.SSH_CLIENT);
5294
+ }
5295
+ function getClipboardImageCommand(deps = {}) {
5296
+ const env = deps.env ?? process.env;
5297
+ const platform = deps.platform ?? process.platform;
5298
+ const which = deps.which ?? Bun.which;
5299
+ if (isRemoteSession(env)) {
5300
+ throw new ClipboardImageError(
5301
+ "remote-session",
5302
+ "\u8FDC\u7A0B\u4F1A\u8BDD\u65E0\u6CD5\u8BFB\u53D6\u672C\u5730\u526A\u8D34\u677F\uFF0C\u8BF7\u62D6\u5165\u56FE\u7247\u6587\u4EF6\u6216\u76F4\u63A5\u8F93\u5165\u56FE\u7247\u8DEF\u5F84"
5303
+ );
5327
5304
  }
5328
- if (state.autoConfirm === true) {
5329
- parts.push(themeText("\u23F5 auto", "warning", colorEnabled));
5305
+ if (platform === "darwin") {
5306
+ const pngpaste = which("pngpaste");
5307
+ if (pngpaste) {
5308
+ return { command: [pngpaste, "-"], outputFormat: "raw" };
5309
+ }
5310
+ const osascript = which("osascript");
5311
+ if (!osascript) {
5312
+ throw new ClipboardImageError(
5313
+ "binary-missing",
5314
+ "\u672A\u627E\u5230 pngpaste\uFF0C\u4E5F\u672A\u627E\u5230\u7CFB\u7EDF\u81EA\u5E26\u7684 osascript\uFF0C\u65E0\u6CD5\u8BFB\u53D6\u526A\u8D34\u677F\u56FE\u50CF\u3002\u8BF7\u8FD0\u884C brew install pngpaste \u5B89\u88C5\uFF0C\u6216\u76F4\u63A5\u62D6\u5165\u56FE\u7247\u6587\u4EF6/\u8F93\u5165\u56FE\u7247\u8DEF\u5F84"
5315
+ );
5316
+ }
5317
+ return {
5318
+ command: [osascript, "-e", "the clipboard as \xABclass PNGf\xBB"],
5319
+ outputFormat: "osascript-hex"
5320
+ };
5330
5321
  }
5331
- let visibleParts = parts;
5332
- if (maxWidth && maxWidth > 0) {
5333
- const widthOf = (segments) => displayWidth(stripAnsi(segments.join(" \xB7 "))) + 2;
5334
- for (const optional of [cwdSegment, agentSegment, tokenSegment, creditsSegment]) {
5335
- if (!optional) continue;
5336
- if (widthOf(visibleParts) <= maxWidth) break;
5337
- visibleParts = visibleParts.filter((part) => part !== optional);
5322
+ if (platform === "win32") {
5323
+ const ps = which("powershell.exe") || which("powershell") || which("pwsh.exe") || which("pwsh");
5324
+ if (!ps) {
5325
+ throw new ClipboardImageError(
5326
+ "binary-missing",
5327
+ "\u672A\u627E\u5230 PowerShell\uFF0C\u65E0\u6CD5\u4ECE\u7CFB\u7EDF\u526A\u8D34\u677F\u8BFB\u53D6\u56FE\u50CF\uFF0C\u8BF7\u76F4\u63A5\u62D6\u5165\u56FE\u7247\u6587\u4EF6\u6216\u8F93\u5165\u56FE\u7247\u8DEF\u5F84"
5328
+ );
5338
5329
  }
5339
- if (widthOf(visibleParts) > maxWidth && state.gitStatus) {
5340
- const gitIndex = visibleParts.findIndex((part) => stripAnsi(part).startsWith("\u2442 "));
5341
- if (gitIndex >= 0) {
5342
- const { modified, untracked } = state.gitStatus;
5343
- const compactDirty = themeText(
5344
- `\u2442${modified > 0 ? ` *${modified}` : ""}${untracked > 0 ? ` ?${untracked}` : ""}`,
5345
- "warning",
5346
- colorEnabled
5330
+ return {
5331
+ command: [
5332
+ ps,
5333
+ "-NoProfile",
5334
+ "-NonInteractive",
5335
+ "-Command",
5336
+ "$img = Get-Clipboard -Format Image; if ($img) { $ms = New-Object System.IO.MemoryStream; $img.Save($ms, [System.Drawing.Imaging.ImageFormat]::Png); [Console]::OpenStandardOutput().Write($ms.ToArray(), 0, $ms.Length) }"
5337
+ ],
5338
+ outputFormat: "raw"
5339
+ };
5340
+ }
5341
+ if (platform === "linux") {
5342
+ const isWayland = Boolean(env.WAYLAND_DISPLAY);
5343
+ if (isWayland) {
5344
+ const wlPaste2 = which("wl-paste");
5345
+ if (!wlPaste2) {
5346
+ throw new ClipboardImageError(
5347
+ "binary-missing",
5348
+ "\u672A\u627E\u5230 wl-paste\uFF0C\u8BF7\u5B89\u88C5 wl-clipboard (\u4F8B\u5982 sudo apt install wl-clipboard)\uFF0C\u6216\u76F4\u63A5\u62D6\u5165\u56FE\u7247\u6587\u4EF6/\u8F93\u5165\u56FE\u7247\u8DEF\u5F84"
5347
5349
  );
5348
- visibleParts = visibleParts.with(gitIndex, compactDirty);
5349
5350
  }
5351
+ return { command: [wlPaste2, "--type", "image/png"], outputFormat: "raw" };
5350
5352
  }
5351
- if (widthOf(visibleParts) > maxWidth) {
5352
- const emergency = [];
5353
- if (state.autoConfirm === true) {
5354
- emergency.push(themeText("\u23F5", "warning", colorEnabled));
5355
- }
5356
- const runningTotal = runningTaskCount;
5357
- if (runningTotal > 0) {
5358
- emergency.push(themeText(`\u2699${runningTotal}`, "info", colorEnabled));
5359
- }
5360
- if (state.gitStatus) {
5361
- const { modified, untracked } = state.gitStatus;
5362
- emergency.push(themeText(
5363
- `\u2442${modified > 0 ? `*${modified}` : ""}${untracked > 0 ? `?${untracked}` : ""}`,
5364
- "warning",
5365
- colorEnabled
5366
- ));
5367
- }
5368
- if (creditsSegment) {
5369
- emergency.push(themeText(formatCreditsChip(credits ?? 0, { compact: true }), "muted", colorEnabled));
5370
- }
5371
- visibleParts = [emergency.join(" ")];
5353
+ const xclip = which("xclip");
5354
+ if (xclip) {
5355
+ return {
5356
+ command: [xclip, "-selection", "clipboard", "-t", "image/png", "-o"],
5357
+ outputFormat: "raw"
5358
+ };
5359
+ }
5360
+ const wlPaste = which("wl-paste");
5361
+ if (wlPaste) {
5362
+ return { command: [wlPaste, "--type", "image/png"], outputFormat: "raw" };
5372
5363
  }
5364
+ throw new ClipboardImageError(
5365
+ "binary-missing",
5366
+ "\u672A\u627E\u5230 xclip\uFF0C\u8BF7\u5B89\u88C5 xclip (\u4F8B\u5982 sudo apt install xclip)\uFF0C\u6216\u76F4\u63A5\u62D6\u5165\u56FE\u7247\u6587\u4EF6/\u8F93\u5165\u56FE\u7247\u8DEF\u5F84"
5367
+ );
5373
5368
  }
5374
- const body = visibleParts.join(sep);
5375
- const surface = colorEnabled ? surfaceBackgroundSequence() : "";
5376
- if (!surface) return body;
5377
- return `${surface} ${body} \x1B[49m`;
5369
+ throw new ClipboardImageError(
5370
+ "unsupported-platform",
5371
+ `\u5F53\u524D\u64CD\u4F5C\u7CFB\u7EDF\u6682\u4E0D\u652F\u6301\u526A\u8D34\u677F\u56FE\u50CF\u8BFB\u53D6: ${platform}`
5372
+ );
5378
5373
  }
5379
- function buildPlainScene(isDark, frame = 0, maxFrames = 0) {
5380
- let skyLine = null;
5381
- if (isDark === true) {
5382
- const star1 = frame % 6 < 3 ? "\u2726" : "\u22C6";
5383
- const star2 = frame % 4 < 2 ? "\u22C6" : "\xB7";
5384
- const star3 = frame % 5 < 2 ? "\xB7" : "\u2726";
5385
- skyLine = ` ${star1} \u263E ${star2} ${star3}`;
5386
- } else if (isDark === false) {
5387
- skyLine = ` \u2600`;
5388
- }
5389
- const wavePattern = "_.~^~.";
5390
- const longWave = wavePattern.repeat(10);
5391
- const offset = frame % wavePattern.length;
5392
- const wave = longWave.slice(offset, offset + 25);
5393
- return [
5394
- ...skyLine ? [skyLine] : [],
5395
- " \u2571\u2572 \u2588\u2584 \u2588 \u2584\u2580\u2580\u2584 \u2588 \u2584\u2580\u2580\u2584",
5396
- " \u2571 \u2572 \u2571\u2572 \u2588 \u2580\u2588 \u2588 \u2588 \u2588 \u2588 \u2588",
5397
- " \u2571 \u2572\u2571 \u2572 \u2580 \u2580 \u2580\u2580 \u2580\u2580\u2580\u2580 \u2580\u2580",
5398
- ` \u2571 \u2660 \u2572 ${wave}`,
5399
- " \u2581\u2581\u2581\u2581\u2581\u2581\u2571 \u2660 \u2660 \u2572\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581"
5400
- ].join("\n");
5401
- }
5402
- function buildColoredScene(isDark, frame = 0, maxFrames = 0) {
5403
- const pk = themeColorSequence("chrome");
5404
- const sk = themeColorSequence("warning");
5405
- const tr = themeColorSequence("success");
5406
- const wv = themeColorSequence("info");
5407
- const ac = themeColorSequence("accent");
5408
- const mu = themeColorSequence("muted");
5409
- const r = "\x1B[39m";
5410
- const b = "\x1B[1m";
5411
- const rs = "\x1B[0m";
5412
- let skyLine = null;
5413
- if (isDark === true) {
5414
- const star1 = frame % 6 < 3 ? "\u2726" : "\u22C6";
5415
- const star2 = frame % 4 < 2 ? "\u22C6" : "\xB7";
5416
- const star3 = frame % 5 < 2 ? "\xB7" : "\u2726";
5417
- skyLine = ` ${mu}${star1}${r} ${sk}\u263E${r} ${mu}${star2}${r} ${mu}${star3}${r}`;
5418
- } else if (isDark === false) {
5419
- skyLine = ` ${sk}\u2600${r}`;
5420
- }
5421
- const wavePattern = "_.~^~.";
5422
- const longWave = wavePattern.repeat(10);
5423
- const offset = frame % wavePattern.length;
5424
- const wave = longWave.slice(offset, offset + 25);
5425
- const waveStr = `${wv}${wave.slice(0, 20)}${r}${mu}${wave.slice(20, 25)}${r}`;
5426
- const line1 = "\u2588\u2584 \u2588 \u2584\u2580\u2580\u2584 \u2588 \u2584\u2580\u2580\u2584";
5427
- const line2 = "\u2588 \u2580\u2588 \u2588 \u2588 \u2588 \u2588 \u2588";
5428
- const line3 = "\u2580 \u2580 \u2580\u2580 \u2580\u2580\u2580\u2580 \u2580\u2580";
5429
- const sweepEndFrame = maxFrames > 3 ? maxFrames - 3 : maxFrames;
5430
- const sweepLen = maxFrames === 0 ? 21 : Math.min(21, Math.floor(frame / sweepEndFrame * 21));
5431
- const colorLine = (str, bold) => {
5432
- const active = str.slice(0, sweepLen);
5433
- const dimmed = str.slice(sweepLen);
5434
- return `${bold ? b : ""}${ac}${active}${r}${mu}${dimmed}${r}${bold ? rs : ""}`;
5435
- };
5436
- const nolo1 = colorLine(line1, true);
5437
- const nolo2 = colorLine(line2, false);
5438
- const nolo3 = colorLine(line3, false);
5439
- return [
5440
- ...skyLine ? [skyLine] : [],
5441
- ` ${pk}\u2571\u2572${r} ${nolo1}`,
5442
- ` ${pk}\u2571 \u2572 \u2571\u2572${r} ${nolo2}`,
5443
- ` ${pk}\u2571 \u2572\u2571 \u2572${r} ${nolo3}`,
5444
- ` ${pk}\u2571${r} ${tr}\u2660${r} ${pk}\u2572${r} ${waveStr}`,
5445
- ` ${pk}\u2581\u2581\u2581\u2581\u2581\u2581\u2571${r} ${tr}\u2660${r} ${tr}\u2660${r} ${pk}\u2572\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581${r}`
5446
- ].join("\n");
5447
- }
5448
- function renderWelcome(state, frame = 0, maxFrames = 0, columns) {
5449
- const colorEnabled = resolveCliColorEnabled();
5450
- const brightnessSignal = resolveTuiBrightnessSignal();
5451
- const isDark = brightnessSignal === null ? null : brightnessSignal === "dark";
5452
- let sceneArt = colorEnabled ? buildColoredScene(isDark, frame, maxFrames) : buildPlainScene(isDark, frame, maxFrames);
5453
- if (typeof columns === "number" && columns > 0) {
5454
- const widestSceneCol = sceneArt.split("\n").reduce((max, line) => Math.max(max, displayWidth(stripAnsi(line))), 0);
5455
- if (columns < widestSceneCol) sceneArt = "";
5456
- }
5457
- const noloLabel = themeText("nolo", "accent", colorEnabled);
5458
- const versionLine = `${noloLabel}${state.cliVersion ? ` ${state.cliVersion}` : ""} | server ${state.serverUrl}`;
5459
- const updateLine = state.updateAvailable ? themeText(
5460
- t("updateAvailable", state.updateAvailable.latestVersion),
5461
- "accent",
5462
- colorEnabled
5463
- ) : null;
5464
- const body = sceneArt ? [sceneArt, versionLine, ...updateLine ? [updateLine] : [], dailyWelcomeTip(), ""] : [versionLine, ...updateLine ? [updateLine] : [], dailyWelcomeTip(), ""];
5465
- return body.join("\n");
5466
- }
5467
- function renderPrompt(_state) {
5468
- return t("promptLabel");
5469
- }
5470
- function renderTuiHelp(colorEnabled = resolveCliColorEnabled()) {
5471
- const text = t("helpText");
5472
- if (!colorEnabled) {
5473
- return text;
5474
- }
5475
- const lines = text.split("\n");
5476
- const commandRegex = /^(\s+)(\/\S+(?:\s+\S+)*?)(\s{2,})(.+)$/;
5477
- const sectionRegex = /^\S.+[::]$/;
5478
- return lines.map((line) => {
5479
- if (!line.trim()) {
5480
- return line;
5481
- }
5482
- if (sectionRegex.test(line)) {
5483
- return renderDialogTitle(line, colorEnabled);
5484
- }
5485
- const match = line.match(commandRegex);
5486
- if (match) {
5487
- const [, indent, cmd, spacing, desc] = match;
5488
- return `${indent}${themeText(cmd, "accent", colorEnabled)}${spacing}${themeText(desc, "muted", colorEnabled)}`;
5489
- }
5490
- return themeText(line, "muted", colorEnabled);
5491
- }).join("\n");
5492
- }
5493
- function renderCreditsDebug(state, colorEnabled = resolveCliColorEnabled()) {
5494
- const credits = resolveStatusLineCredits(state);
5495
- const lines = [
5496
- "[credits debug] \u79EF\u5206\u94FE\u8DEF\u771F\u503C",
5497
- `\u2022 dialogCreditsBase : ${state.dialogCreditsBase?.toFixed(4) ?? "undefined\uFF08\u670D\u52A1\u7AEF\u57FA\u6570\u672A seed\u2014\u2014/pick \u540E\u9996\u6B21\u8BFB\u53D6\u5931\u8D25\u6216\u670D\u52A1\u7AEF\u672A\u5199 totalCost\uFF09"}`,
5498
- `\u2022 sessionCredits : ${state.sessionCredits?.toFixed(4) ?? "undefined\uFF08\u672C\u4F1A\u8BDD\u8FD8\u6CA1\u6709\u5E73\u53F0\u8BA1\u8D39\u8F6E\uFF09"}`,
5499
- `\u2022 \u72B6\u6001\u884C\u663E\u793A : ${credits !== void 0 && credits > 0 ? formatCreditsChip(credits) : "\uFF08\u65E0 \u26A1\u2014\u2014\u4E24\u6BB5\u5408\u8BA1\u4E3A 0/undefined\uFF09"}`,
5500
- `\u2022 turnTokens.credits: ${state.turnTokens?.credits?.toFixed(4) ?? "undefined"}\uFF08\u672C\u8F6E\u6700\u540E\u4E00\u6B21\u8C03\u7528\u7684\u6298\u7B97\u503C\uFF0C\u4EC5\u4F9B\u53C2\u8003\uFF0C\u4E0D\u8FDB\u72B6\u6001\u884C\uFF09`,
5501
- `\u2022 contextWindow : ${state.contextWindow ?? "unknown"}`,
5502
- '\u2022 \u5224\u5B9A\u53E3\u5F84\uFF1A\u53EA\u6709 billing_unit === "credits" \u7684\u5E73\u53F0\u8BA1\u8D39\u5E27\u624D\u7D2F\u8BA1\uFF1B\u81EA\u6709 API / \u8BA2\u9605\u5236\u6052\u4E3A undefined\u3002',
5503
- "\u2022 \u82E5\u521A\u8DD1\u5B8C\u5E73\u53F0\u8BA1\u8D39\u8F6E\u4ECD\u65E0 \u26A1\uFF1A\u68C0\u67E5 runAgentTurn \u8FD4\u56DE\u662F\u5426\u5E26 turnCredits\uFF08foldLocalResultForTui \u767D\u540D\u5355\uFF09\u3002"
5504
- ];
5505
- return lines.map((line) => colorEnabled ? themeText(line, "chrome") : line).join("\n");
5506
- }
5507
- function renderContextPanel(state, colorEnabled = resolveCliColorEnabled()) {
5508
- const docs = state.attachedDocs.length ? state.attachedDocs.join(", ") : "none";
5509
- const skills = state.attachedSkills.length ? state.attachedSkills.join(", ") : "none";
5510
- const labels = [
5511
- t("contextFieldAgent"),
5512
- t("contextFieldTokens"),
5513
- t("contextFieldDialog"),
5514
- t("contextFieldDocs"),
5515
- t("contextFieldSkills"),
5516
- t("contextFieldProfile"),
5517
- t("contextFieldRuntime"),
5518
- t("contextFieldServer")
5519
- ];
5520
- let maxW = 0;
5521
- for (const l of labels) {
5522
- const w = displayWidth(l);
5523
- if (w > maxW) maxW = w;
5374
+ var OSASCRIPT_EMPTY_CLIPBOARD_MESSAGE = "\u526A\u8D34\u677F\u4E2D\u6CA1\u6709\u56FE\u50CF\u6570\u636E\u3002\u53EF\u76F4\u63A5\u62D6\u5165\u56FE\u7247\u6587\u4EF6\u3001\u8F93\u5165\u56FE\u7247\u8DEF\u5F84\uFF0C\u6216\u8FD0\u884C brew install pngpaste \u4EE5\u652F\u6301\u66F4\u591A\u56FE\u7247\u683C\u5F0F";
5375
+ function decodeOsascriptPngHex(text) {
5376
+ const match = /PNGf\s*([0-9A-Fa-f]*)/.exec(text);
5377
+ if (!match) return { kind: "empty" };
5378
+ const hex = match[1] ?? "";
5379
+ const tail = text.slice(match.index + match[0].length).replace(/[\s»]*$/, "");
5380
+ if (tail.length > 0) return { kind: "invalid" };
5381
+ if (hex.length === 0) return { kind: "empty" };
5382
+ if (hex.length % 2 !== 0) return { kind: "invalid" };
5383
+ const bytes = new Uint8Array(hex.length / 2);
5384
+ for (let i = 0; i < bytes.length; i += 1) {
5385
+ bytes[i] = Number.parseInt(hex.slice(i * 2, i * 2 + 2), 16);
5524
5386
  }
5525
- const targetWidth = maxW >= 9 ? maxW + 1 : 9;
5526
- const padLabel = (raw) => {
5527
- const w = displayWidth(raw);
5528
- const padding = " ".repeat(Math.max(0, targetWidth - w));
5529
- return raw + padding;
5530
- };
5531
- const field = (rawLabel, value) => `${themeText(padLabel(rawLabel), "muted", colorEnabled)}${value}`;
5532
- const next = (command, description) => ` ${themeText(command, "accent", colorEnabled)}${themeText(description, "muted", colorEnabled)}`;
5533
- const titleText = t("contextTitle");
5534
- const heading = colorEnabled ? [renderDialogTitle(titleText, true)] : [titleText, "\u2500".repeat(displayWidth(titleText))];
5535
- return [
5536
- ...heading,
5537
- field(labels[0], `${state.agentName} (${state.agentKey})`),
5538
- field(labels[1], renderTokenStatus(state.turnTokens)),
5539
- field(
5540
- labels[2],
5541
- state.dialogKey ?? (state.dialogId ? "unavailable" : state.dialogLabel)
5542
- ),
5543
- field(labels[3], docs),
5544
- field(labels[4], skills),
5545
- field(labels[5], state.profileName),
5546
- field(labels[6], state.runtimeMode),
5547
- field(labels[7], state.serverUrl),
5548
- "",
5549
- themeText(t("contextNext"), "chrome", colorEnabled),
5550
- next("/agents ", ` ${t("contextNextAgents")}`),
5551
- next("/doc attach <doc> ", ` ${t("contextNextDoc")}`),
5552
- next("/skill attach <ref>", ` ${t("contextNextSkill")}`),
5553
- next("/new ", ` ${t("contextNextNew")}`),
5554
- next("/clear ", ` ${t("contextNextClear")}`)
5555
- ].join("\n");
5556
- }
5557
- function renderKnownAgents(colorEnabled = resolveCliColorEnabled()) {
5558
- return [
5559
- renderDialogTitle(t("agentsTitle"), colorEnabled),
5560
- ...resolveCatalogPlatformAgents().map(
5561
- (agent, index) => ` ${themeText(String(index + 1), "chrome", colorEnabled)} ${themeText(
5562
- agent.name.padEnd(11),
5563
- "accent",
5564
- colorEnabled
5565
- )} ${themeText(agent.description ?? "", "muted", colorEnabled)}`
5566
- ),
5567
- "",
5568
- themeText(
5569
- t("agentsTip"),
5570
- "muted",
5571
- colorEnabled
5572
- )
5573
- ].join("\n");
5387
+ return { kind: "bytes", bytes };
5574
5388
  }
5575
-
5576
- // packages/cli/tui/sessionInput.ts
5577
- import { readdirSync, statSync as statSync2 } from "node:fs";
5578
- import { homedir as homedir2 } from "node:os";
5579
- import { resolve as resolve2 } from "node:path";
5580
- var PASTE_TOKEN_PREFIX = "\0PASTE\0";
5581
- function applyTuiInputKey(buffer, sequence, key = {}, cursorPos, options) {
5582
- const seq = sequence ?? "";
5583
- const curPos = Math.max(0, Math.min(buffer.length, cursorPos ?? buffer.length));
5584
- const pasteStore = options?.pasteStore;
5585
- if (seq.startsWith(PASTE_TOKEN_PREFIX)) {
5586
- const rawPayload = seq.slice(PASTE_TOKEN_PREFIX.length);
5587
- const normalized = rawPayload.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
5588
- const insertAt2 = snapCursorOutsidePasteChip(buffer, curPos);
5589
- if (pasteStore && shouldCollapsePaste(normalized)) {
5590
- const { placeholder } = allocateCollapsedPaste(pasteStore, normalized);
5591
- const nextBuf3 = buffer.slice(0, insertAt2) + placeholder + buffer.slice(insertAt2);
5592
- return { buffer: nextBuf3, cursorPos: insertAt2 + placeholder.length };
5593
- }
5594
- const nextBuf2 = buffer.slice(0, insertAt2) + normalized + buffer.slice(insertAt2);
5595
- return { buffer: nextBuf2, cursorPos: insertAt2 + normalized.length };
5596
- }
5597
- if (seq === "" || key.ctrl && key.name === "c") {
5598
- return { buffer, cursorPos: curPos, abort: true };
5599
- }
5600
- if (seq === "\f" || key.ctrl && key.name === "l") {
5601
- return { buffer, cursorPos: curPos, redraw: true };
5602
- }
5603
- if (seq === "" || key.ctrl && key.name === "o") {
5604
- return { buffer, cursorPos: curPos };
5605
- }
5606
- if (seq === "\x1B[13;2~" || seq === "\x1B[27;2;13~" || seq === "\x1B\r" || key.shift && (key.name === "enter" || key.name === "return") || seq === "\n" || key.ctrl && key.name === "j") {
5607
- const insertAt2 = snapCursorOutsidePasteChip(buffer, curPos);
5608
- const nextBuf2 = buffer.slice(0, insertAt2) + "\n" + buffer.slice(insertAt2);
5609
- return { buffer: nextBuf2, cursorPos: insertAt2 + 1 };
5610
- }
5611
- if (key.name === "enter" || key.name === "return" || seq === "\r") {
5612
- return { buffer: "", cursorPos: 0, submit: buffer };
5613
- }
5614
- if (isLeftArrowSequence(seq, key)) {
5615
- const span = findCollapsedPasteSpanAt(buffer, curPos, { preferLeft: true });
5616
- if (span && curPos > span.start && curPos <= span.end) {
5617
- return { buffer, cursorPos: span.start };
5618
- }
5619
- return { buffer, cursorPos: Math.max(0, curPos - 1) };
5620
- }
5621
- if (isRightArrowSequence(seq, key)) {
5622
- const span = findCollapsedPasteSpanAt(buffer, curPos);
5623
- if (span && curPos >= span.start && curPos < span.end) {
5624
- return { buffer, cursorPos: span.end };
5625
- }
5626
- return { buffer, cursorPos: Math.min(buffer.length, curPos + 1) };
5627
- }
5628
- if (isHomeSequence(seq, key)) {
5629
- return { buffer, cursorPos: 0 };
5630
- }
5631
- if (isEndSequence(seq, key)) {
5632
- return { buffer, cursorPos: buffer.length };
5633
- }
5634
- if (isDeleteWordSequence(seq, key)) {
5635
- if (curPos === 0) return { buffer, cursorPos: curPos };
5636
- const pasteSpan = findCollapsedPasteSpanAt(buffer, curPos, {
5637
- preferLeft: true
5389
+ async function readClipboardImage(deps = {}) {
5390
+ const env = deps.env ?? process.env;
5391
+ const platform = deps.platform ?? process.platform;
5392
+ const which = deps.which ?? Bun.which;
5393
+ const spawn = deps.spawn ?? Bun.spawn;
5394
+ const maxBytes = deps.maxBytes ?? DEFAULT_MAX_IMAGE_BYTES;
5395
+ const timeoutMs = deps.timeoutMs ?? DEFAULT_CLIPBOARD_TIMEOUT_MS;
5396
+ const tempDir = deps.tempDir ?? getDefaultClipboardTempDir();
5397
+ const { command, outputFormat } = getClipboardImageCommand({
5398
+ env,
5399
+ platform,
5400
+ which
5401
+ });
5402
+ let stdoutBuf;
5403
+ try {
5404
+ const proc = spawn(command, {
5405
+ stdin: "ignore",
5406
+ stdout: "pipe",
5407
+ stderr: "pipe"
5638
5408
  });
5639
- if (pasteSpan && (curPos === pasteSpan.end || curPos > pasteSpan.start && curPos < pasteSpan.end)) {
5640
- return removePasteSpan(buffer, pasteSpan, pasteStore);
5641
- }
5642
- const cutIdx = findWordStartLeft(buffer, curPos);
5643
- return deleteBufferRange(buffer, cutIdx, curPos, pasteStore);
5644
- }
5645
- if (isKillToLineStartSequence(seq, key)) {
5646
- if (curPos === 0) return { buffer, cursorPos: curPos };
5647
- const lineStart = buffer.lastIndexOf("\n", curPos - 1) + 1;
5648
- return deleteBufferRange(buffer, lineStart, curPos, pasteStore);
5649
- }
5650
- if (isKillToLineEndSequence(seq, key)) {
5651
- const nlIdx = buffer.indexOf("\n", curPos);
5652
- const lineEnd = nlIdx === -1 ? buffer.length : nlIdx;
5653
- return deleteBufferRange(buffer, curPos, lineEnd, pasteStore);
5654
- }
5655
- if (isBackspaceSequence(seq, key)) {
5656
- if (curPos > 0) {
5657
- const pasteSpan = findCollapsedPasteSpanAt(buffer, curPos, {
5658
- preferLeft: true
5659
- });
5660
- if (pasteSpan && (curPos === pasteSpan.end || curPos > pasteSpan.start && curPos < pasteSpan.end)) {
5661
- return removePasteSpan(buffer, pasteSpan, pasteStore);
5662
- }
5663
- const nextBuf2 = buffer.slice(0, curPos - 1) + buffer.slice(curPos);
5664
- return { buffer: nextBuf2, cursorPos: curPos - 1 };
5665
- }
5666
- return { buffer, cursorPos: curPos };
5667
- }
5668
- if (isForwardDeleteSequence(seq, key)) {
5669
- if (curPos < buffer.length) {
5670
- const pasteSpan = findCollapsedPasteSpanAt(buffer, curPos);
5671
- if (pasteSpan && (curPos === pasteSpan.start || curPos > pasteSpan.start && curPos < pasteSpan.end)) {
5672
- return removePasteSpan(buffer, pasteSpan, pasteStore);
5409
+ let timeout;
5410
+ const timeoutPromise = new Promise((_, reject) => {
5411
+ timeout = setTimeout(() => {
5412
+ proc.kill();
5413
+ reject(
5414
+ new ClipboardImageError(
5415
+ "read-failed",
5416
+ "\u8BFB\u53D6\u526A\u8D34\u677F\u8D85\u65F6\uFF0C\u526A\u8D34\u677F\u540E\u7AEF\u53EF\u80FD\u65E0\u54CD\u5E94"
5417
+ )
5418
+ );
5419
+ }, timeoutMs);
5420
+ });
5421
+ try {
5422
+ const [stdoutArrayBuffer, stderrText, exitCode] = await Promise.race([
5423
+ Promise.all([
5424
+ new Response(proc.stdout).arrayBuffer(),
5425
+ new Response(proc.stderr).text(),
5426
+ proc.exited
5427
+ ]),
5428
+ timeoutPromise
5429
+ ]);
5430
+ if (exitCode !== 0 || stdoutArrayBuffer.byteLength === 0) {
5431
+ if (outputFormat === "osascript-hex") {
5432
+ throw new ClipboardImageError(
5433
+ "empty-clipboard",
5434
+ OSASCRIPT_EMPTY_CLIPBOARD_MESSAGE + (stderrText.trim() ? `: ${stderrText.trim()}` : "")
5435
+ );
5436
+ }
5437
+ throw new ClipboardImageError(
5438
+ "empty-clipboard",
5439
+ "\u526A\u8D34\u677F\u4E2D\u6CA1\u6709\u56FE\u50CF\u6570\u636E\uFF0C\u8BF7\u76F4\u63A5\u62D6\u5165\u56FE\u7247\u6587\u4EF6\u6216\u8F93\u5165\u56FE\u7247\u8DEF\u5F84" + (stderrText.trim() ? `: ${stderrText.trim()}` : "")
5440
+ );
5673
5441
  }
5674
- const nextBuf2 = buffer.slice(0, curPos) + buffer.slice(curPos + 1);
5675
- return { buffer: nextBuf2, cursorPos: curPos };
5442
+ stdoutBuf = new Uint8Array(stdoutArrayBuffer);
5443
+ } finally {
5444
+ clearTimeout(timeout);
5676
5445
  }
5677
- if (curPos > 0) {
5678
- const nextBuf2 = buffer.slice(0, curPos - 1);
5679
- return { buffer: nextBuf2, cursorPos: curPos - 1 };
5446
+ } catch (err) {
5447
+ if (err instanceof ClipboardImageError) {
5448
+ throw err;
5680
5449
  }
5681
- return { buffer, cursorPos: curPos };
5450
+ throw new ClipboardImageError(
5451
+ "read-failed",
5452
+ `\u8BFB\u53D6\u526A\u8D34\u677F\u56FE\u50CF\u5931\u8D25: ${err instanceof Error ? err.message : String(err)}`
5453
+ );
5682
5454
  }
5683
- if (seq === " " || key.name === "tab") {
5684
- if (options?.cwd) {
5685
- const pathCandidates = completeSlashCommand(buffer, options.cwd);
5686
- if (pathCandidates.length === 1) {
5687
- const [only] = pathCandidates;
5688
- return { buffer: only, cursorPos: only.length };
5689
- }
5690
- if (pathCandidates.length > 1) {
5691
- return { buffer, cursorPos: curPos };
5692
- }
5455
+ if (outputFormat === "osascript-hex") {
5456
+ const text = Buffer.from(stdoutBuf).toString("utf8");
5457
+ const decoded = decodeOsascriptPngHex(text);
5458
+ if (decoded.kind === "empty") {
5459
+ throw new ClipboardImageError(
5460
+ "empty-clipboard",
5461
+ OSASCRIPT_EMPTY_CLIPBOARD_MESSAGE
5462
+ );
5693
5463
  }
5694
- const completed = completeSlashPrefix(buffer) ?? buffer;
5695
- return { buffer: completed, cursorPos: completed.length };
5464
+ if (decoded.kind === "invalid") {
5465
+ throw new ClipboardImageError(
5466
+ "read-failed",
5467
+ "\u526A\u8D34\u677F\u56FE\u50CF\u6570\u636E\u65E0\u6CD5\u89E3\u6790\uFF08hex \u7F16\u7801\u635F\u574F\uFF09\uFF0C\u8BF7\u91CD\u65B0\u590D\u5236\u56FE\u7247\u540E\u91CD\u8BD5\uFF0C\u6216\u76F4\u63A5\u62D6\u5165\u56FE\u7247\u6587\u4EF6/\u8F93\u5165\u56FE\u7247\u8DEF\u5F84"
5468
+ );
5469
+ }
5470
+ stdoutBuf = decoded.bytes;
5696
5471
  }
5697
- if (!seq || key.ctrl || key.meta || seq.startsWith("\x1B")) {
5698
- return { buffer, cursorPos: curPos };
5472
+ const compressResult = await compressImage(stdoutBuf, "image/png");
5473
+ const finalBuf = compressResult.buffer;
5474
+ const finalMime = compressResult.mime;
5475
+ const finalSizeBytes = finalBuf.byteLength;
5476
+ if (finalSizeBytes > maxBytes) {
5477
+ throw new ClipboardImageError(
5478
+ "too-large",
5479
+ `\u526A\u8D34\u677F\u56FE\u50CF\u8FC7\u5927: ${formatBytes(finalSizeBytes)} (\u4E0A\u9650 ${formatBytes(maxBytes)})`
5480
+ );
5699
5481
  }
5700
- const insertAt = snapCursorOutsidePasteChip(buffer, curPos);
5701
- const nextBuf = buffer.slice(0, insertAt) + seq + buffer.slice(insertAt);
5702
- return { buffer: nextBuf, cursorPos: insertAt + seq.length };
5703
- }
5704
- function snapCursorOutsidePasteChip(buffer, pos) {
5705
- const span = findCollapsedPasteSpanAt(buffer, pos);
5706
- if (span && pos > span.start && pos < span.end) return span.end;
5707
- return pos;
5482
+ const hash = createHash("sha256").update(finalBuf).digest("hex").slice(0, 12);
5483
+ const ext = mimeToExtension(finalMime);
5484
+ const filename = `clip-${hash}.${ext}`;
5485
+ mkdirSync(tempDir, { recursive: true });
5486
+ const filePath = join(tempDir, filename);
5487
+ await writeFile(filePath, finalBuf);
5488
+ return buildAttachedImage({
5489
+ buffer: finalBuf,
5490
+ mime: finalMime,
5491
+ filename,
5492
+ sourcePath: filePath,
5493
+ originalSizeBytes: compressResult.compressed ? compressResult.originalBytes : void 0
5494
+ });
5708
5495
  }
5709
- function isLeftArrowSequence(seq, key) {
5710
- if (key.name === "left") return true;
5711
- if (seq === "\x1B[D" || seq === "\x1B[1;2D" || seq === "\x1B[1;5D" || seq === "\x1BOD") return true;
5712
- return false;
5496
+
5497
+ // packages/cli/tui/pasteFlow.ts
5498
+ function isTextFallbackEligibleCode(code) {
5499
+ return code === "empty-clipboard" || code === "binary-missing" || code === "unsupported-platform";
5713
5500
  }
5714
- function isRightArrowSequence(seq, key) {
5715
- if (key.name === "right") return true;
5716
- if (seq === "\x1B[C" || seq === "\x1B[1;2C" || seq === "\x1B[1;5C" || seq === "\x1BOC") return true;
5717
- return false;
5501
+ function errorCodeOf(error) {
5502
+ if (typeof error !== "object" || error === null) return void 0;
5503
+ const code = error.code;
5504
+ return code === void 0 || code === null ? void 0 : String(code);
5718
5505
  }
5719
- function isHomeSequence(seq, key) {
5720
- if (key.name === "home") return true;
5721
- if (key.ctrl && key.name === "a") return true;
5722
- if (seq === "" || seq === "\x1B[H" || seq === "\x1B[1~" || seq === "\x1B[7~" || seq === "\x1BOH") return true;
5723
- return false;
5506
+ function messageOf(error) {
5507
+ return error instanceof Error ? error.message : String(error);
5724
5508
  }
5725
- function isEndSequence(seq, key) {
5726
- if (key.name === "end") return true;
5727
- if (key.ctrl && key.name === "e") return true;
5728
- if (seq === "" || seq === "\x1B[F" || seq === "\x1B[4~" || seq === "\x1B[8~" || seq === "\x1BOF") return true;
5729
- return false;
5509
+ async function resolveClipboardPaste(deps) {
5510
+ try {
5511
+ const image = await deps.readImage();
5512
+ return { kind: "image", image };
5513
+ } catch (imageError) {
5514
+ const code = errorCodeOf(imageError);
5515
+ if (!isTextFallbackEligibleCode(code)) {
5516
+ return {
5517
+ kind: "error",
5518
+ code: code ?? "read-failed",
5519
+ message: messageOf(imageError)
5520
+ };
5521
+ }
5522
+ let text;
5523
+ try {
5524
+ text = await deps.readText();
5525
+ } catch (textError) {
5526
+ return {
5527
+ kind: "error",
5528
+ code: "text-read-failed",
5529
+ message: `${messageOf(textError)} (${messageOf(imageError)})`
5530
+ };
5531
+ }
5532
+ if (text.length > 0) {
5533
+ return { kind: "text", text };
5534
+ }
5535
+ return { kind: "empty", message: messageOf(imageError) };
5536
+ }
5730
5537
  }
5731
- function removePasteSpan(buffer, span, pasteStore) {
5732
- if (pasteStore) releaseCollapsedPaste(pasteStore, span.id);
5733
- const nextBuf = buffer.slice(0, span.start) + buffer.slice(span.end);
5734
- return { buffer: nextBuf, cursorPos: span.start };
5538
+ function shouldApplyPastedResult(snapshot, current) {
5539
+ if (current.sessionEnded) return false;
5540
+ return snapshot.epoch === current.epoch;
5735
5541
  }
5736
- function deleteBufferRange(buffer, start, end, pasteStore) {
5737
- if (start >= end) return { buffer, cursorPos: start };
5738
- const range = expandRangeToCollapsedPasteChips(buffer, start, end);
5739
- releasePastesInRange(buffer, range.start, range.end, pasteStore);
5740
- const nextBuf = buffer.slice(0, range.start) + buffer.slice(range.end);
5741
- return { buffer: nextBuf, cursorPos: range.start };
5542
+
5543
+ // packages/cli/tui/clipboard.ts
5544
+ function osc52SetClipboard(text, output) {
5545
+ const payload = Buffer.from(text, "utf8").toString("base64");
5546
+ output.write(`\x1B]52;c;${payload}\x07`);
5742
5547
  }
5743
- function releasePastesInRange(buffer, start, end, pasteStore) {
5744
- if (!pasteStore || start >= end) return;
5745
- const slice = buffer.slice(start, end);
5746
- COLLAPSED_PASTE_PLACEHOLDER_RE.lastIndex = 0;
5747
- let match;
5748
- while ((match = COLLAPSED_PASTE_PLACEHOLDER_RE.exec(slice)) !== null) {
5749
- releaseCollapsedPaste(pasteStore, Number(match[1]));
5548
+ async function writeClipboard(text, target) {
5549
+ if (target.transport === "system") {
5550
+ await target.systemWrite(text);
5551
+ return;
5552
+ }
5553
+ if (target.transport === "osc52") {
5554
+ osc52SetClipboard(text, target.output);
5555
+ return;
5750
5556
  }
5557
+ throw new Error(
5558
+ "Client clipboard is unavailable in a non-interactive remote session."
5559
+ );
5751
5560
  }
5752
- var CJK_CHAR = /[\u4e00-\u9fff\u3000-\u303f\uff00-\uffef]/;
5753
- function findWordStartLeft(buffer, curPos) {
5754
- let i = curPos;
5755
- while (i > 0 && /\s/.test(buffer[i - 1])) i--;
5756
- if (i === 0) return 0;
5757
- const spanAtCursor = findCollapsedPasteSpanAt(buffer, i, {
5758
- preferLeft: true
5759
- });
5760
- if (spanAtCursor && (i === spanAtCursor.end || i > spanAtCursor.start && i < spanAtCursor.end)) {
5761
- return spanAtCursor.start;
5561
+
5562
+ // packages/cli/tui/gitStatus.ts
5563
+ import { execFile, execSync } from "node:child_process";
5564
+ function parseStatusOutput(branch, status) {
5565
+ if (!status) {
5566
+ return { branch, modified: 0, untracked: 0 };
5762
5567
  }
5763
- if (CJK_CHAR.test(buffer[i - 1])) return i - 1;
5764
- while (i > 0 && !/\s/.test(buffer[i - 1]) && !CJK_CHAR.test(buffer[i - 1])) {
5765
- const span = findCollapsedPasteSpanAt(buffer, i, { preferLeft: true });
5766
- if (span && i === span.end) break;
5767
- i--;
5568
+ let modified = 0;
5569
+ let untracked = 0;
5570
+ for (const line of status.split("\n")) {
5571
+ if (!line) continue;
5572
+ const flag = line[0];
5573
+ if (flag === "?") untracked += 1;
5574
+ else modified += 1;
5768
5575
  }
5769
- return i;
5576
+ return { branch, modified, untracked };
5770
5577
  }
5771
- function isDeleteWordSequence(seq, key) {
5772
- if (key.ctrl && key.name === "w") return true;
5773
- if ((key.ctrl || key.meta) && key.name === "backspace") return true;
5774
- if (seq === "" || seq === "\x1B\x7F") return true;
5775
- return false;
5578
+ function execFileUtf8(file, args, cwd) {
5579
+ return new Promise((resolve4, reject) => {
5580
+ execFile(
5581
+ file,
5582
+ args,
5583
+ { cwd, encoding: "utf8", timeout: 2e3 },
5584
+ (err, stdout) => {
5585
+ if (err) {
5586
+ reject(err);
5587
+ return;
5588
+ }
5589
+ resolve4(typeof stdout === "string" ? stdout : String(stdout ?? ""));
5590
+ }
5591
+ );
5592
+ });
5776
5593
  }
5777
- function isKillToLineStartSequence(seq, key) {
5778
- if (key.ctrl && key.name === "u") return true;
5779
- if (seq === "") return true;
5780
- return false;
5594
+ function detectGitStatusAsync(cwd) {
5595
+ return (async () => {
5596
+ try {
5597
+ const branch = (await execFileUtf8("git", ["rev-parse", "--abbrev-ref", "HEAD"], cwd)).trim();
5598
+ if (!branch) return void 0;
5599
+ const status = (await execFileUtf8("git", ["status", "--porcelain"], cwd)).trim();
5600
+ return parseStatusOutput(branch, status);
5601
+ } catch {
5602
+ return void 0;
5603
+ }
5604
+ })();
5781
5605
  }
5782
- function isKillToLineEndSequence(seq, key) {
5783
- if (key.ctrl && key.name === "k") return true;
5784
- if (seq === "\v") return true;
5785
- return false;
5606
+
5607
+ // packages/cli/tui/sessionRender.ts
5608
+ function formatCwd(cwd) {
5609
+ const parts = cwd.split(/[/\\]/);
5610
+ return parts.pop() || cwd;
5786
5611
  }
5787
- function isBackspaceSequence(seq, key) {
5788
- if (key.name === "backspace") return true;
5789
- if (seq === "\b" || seq === "\x7F") return true;
5790
- return /^\x1b\[27;\d+;8~$/.test(seq);
5612
+ function formatElapsedSeconds(totalSeconds) {
5613
+ if (totalSeconds < 60) return `${totalSeconds}s`;
5614
+ const minutes = Math.floor(totalSeconds / 60);
5615
+ const seconds = totalSeconds % 60;
5616
+ if (minutes < 60) return `${minutes}m ${seconds}s`;
5617
+ const hours = Math.floor(minutes / 60);
5618
+ const mins = minutes % 60;
5619
+ return `${hours}h ${mins}m`;
5791
5620
  }
5792
- function isForwardDeleteSequence(seq, key) {
5793
- if (key.name === "delete") return true;
5794
- return /^\x1b\[3(?:;\d+)*~$/.test(seq);
5621
+ function renderComposerTokenChip(tokens, fallbackContextWindow, estimatedContextTokens) {
5622
+ const cw = tokens?.contextWindow ?? fallbackContextWindow;
5623
+ if (!cw) {
5624
+ return "context: \u2014";
5625
+ }
5626
+ const used = tokens ? tokens.input + tokens.output : Math.max(0, estimatedContextTokens ?? 0);
5627
+ const pct = Math.min(100, used / cw * 100);
5628
+ const pctText = pct > 0 && pct < 10 ? pct.toFixed(1) : Math.round(pct).toString();
5629
+ return `context: ${pctText}% (${formatTokenCount(used)}/${formatTokenCount(cw)})`;
5795
5630
  }
5796
- var SLASH_COMMANDS = [
5797
- "/help",
5798
- "/new",
5799
- "/clear",
5800
- "/compact",
5801
- "/theme",
5802
- "/context",
5803
- "/ctx",
5804
- "/credits",
5805
- "/links",
5806
- "/cd",
5807
- "/runtime",
5808
- "/auto",
5809
- "/switch",
5810
- "/agent",
5811
- "/agents",
5812
- "/history",
5813
- "/resume",
5814
- "/lang",
5815
- "/copy",
5816
- "/paste",
5817
- "/mouse",
5818
- "/math",
5819
- "/doc",
5820
- "/skill",
5821
- "/customize",
5822
- "/login",
5823
- "/profile",
5824
- "/update",
5825
- "/version",
5826
- "/logs",
5827
- "/tasks",
5828
- "/jobs",
5829
- "/procs",
5830
- "/stop",
5831
- "/exit",
5832
- "/quit"
5833
- ];
5834
- function completeSlashPrefix(buffer) {
5835
- if (!buffer.startsWith("/") || /\s/.test(buffer)) return null;
5836
- const matches = SLASH_COMMANDS.filter((cmd) => cmd.startsWith(buffer));
5837
- if (matches.length === 0) return null;
5838
- if (matches.length === 1) {
5839
- return `${matches[0]} `;
5631
+ function resolveStatusLineCredits(state) {
5632
+ const base = state.dialogCreditsBase;
5633
+ const session = state.sessionCredits;
5634
+ const live = state.liveTurnCredits;
5635
+ if (base === void 0 && session === void 0 && live === void 0) {
5636
+ return void 0;
5840
5637
  }
5841
- let prefix = matches[0];
5842
- for (const cmd of matches) {
5843
- while (!cmd.startsWith(prefix)) prefix = prefix.slice(0, -1);
5638
+ return (base ?? 0) + (session ?? 0) + (live ?? 0);
5639
+ }
5640
+ function renderStatusLine(state, maxWidth) {
5641
+ const colorEnabled = resolveCliColorEnabled();
5642
+ const sep = themeText(" \xB7 ", "chrome", colorEnabled);
5643
+ const agentDisplayName = state.agentName;
5644
+ const modeSuffix = state.modeLabel && state.modeLabel !== "auto" ? ` \xB7 ${state.modeLabel}` : "";
5645
+ const agentLabel = `\u2726 ${agentDisplayName}${modeSuffix}`;
5646
+ const agentSegment = themeText(agentLabel, "accent", colorEnabled);
5647
+ const cwdSegment = themeText(`\u{1F4C1} ${formatCwd(state.cwd)}`, "info", colorEnabled);
5648
+ const parts = [agentSegment, cwdSegment];
5649
+ if (state.gitStatus) {
5650
+ const { branch, modified, untracked } = state.gitStatus;
5651
+ const branchText = themeText(`\u2442 ${branch}`, "warning", colorEnabled);
5652
+ const modifiedText = modified > 0 ? ` ${themeText(`*${modified}`, "danger", colorEnabled)}` : "";
5653
+ const untrackedText = untracked > 0 ? ` ${themeText(`?${untracked}`, "muted", colorEnabled)}` : "";
5654
+ parts.push(`${branchText}${modifiedText}${untrackedText}`);
5655
+ }
5656
+ const credits = resolveStatusLineCredits(state);
5657
+ const tokenSegment = themeText(
5658
+ renderComposerTokenChip(
5659
+ state.turnTokens,
5660
+ state.contextWindow,
5661
+ state.estimatedContextTokens
5662
+ ),
5663
+ "muted",
5664
+ colorEnabled
5665
+ );
5666
+ const creditsSegment = credits !== void 0 && credits > 0 ? themeText(formatCreditsChip(credits), "muted", colorEnabled) : "";
5667
+ parts.push(tokenSegment);
5668
+ if (creditsSegment) parts.push(creditsSegment);
5669
+ const runningTaskCount = getProcessRegistry().listBackground().filter((p) => p.status === "running").length;
5670
+ if (runningTaskCount > 0) {
5671
+ parts.push(themeText(`\u2699 ${runningTaskCount} running`, "info", colorEnabled));
5672
+ }
5673
+ const pendingProcessCount = state.pendingProcessNotices?.length ?? 0;
5674
+ if (pendingProcessCount > 0) {
5675
+ parts.push(themeText(`\u2699 ${pendingProcessCount} finished`, "info", colorEnabled));
5676
+ }
5677
+ if (state.autoConfirm === true) {
5678
+ parts.push(themeText("\u23F5 auto", "warning", colorEnabled));
5679
+ }
5680
+ let visibleParts = parts;
5681
+ if (maxWidth && maxWidth > 0) {
5682
+ const widthOf = (segments) => displayWidth(stripAnsi(segments.join(" \xB7 "))) + 2;
5683
+ for (const optional of [cwdSegment, agentSegment, tokenSegment, creditsSegment]) {
5684
+ if (!optional) continue;
5685
+ if (widthOf(visibleParts) <= maxWidth) break;
5686
+ visibleParts = visibleParts.filter((part) => part !== optional);
5687
+ }
5688
+ if (widthOf(visibleParts) > maxWidth && state.gitStatus) {
5689
+ const gitIndex = visibleParts.findIndex((part) => stripAnsi(part).startsWith("\u2442 "));
5690
+ if (gitIndex >= 0) {
5691
+ const { modified, untracked } = state.gitStatus;
5692
+ const compactDirty = themeText(
5693
+ `\u2442${modified > 0 ? ` *${modified}` : ""}${untracked > 0 ? ` ?${untracked}` : ""}`,
5694
+ "warning",
5695
+ colorEnabled
5696
+ );
5697
+ visibleParts = visibleParts.with(gitIndex, compactDirty);
5698
+ }
5699
+ }
5700
+ if (widthOf(visibleParts) > maxWidth) {
5701
+ const emergency = [];
5702
+ if (state.autoConfirm === true) {
5703
+ emergency.push(themeText("\u23F5", "warning", colorEnabled));
5704
+ }
5705
+ const runningTotal = runningTaskCount;
5706
+ if (runningTotal > 0) {
5707
+ emergency.push(themeText(`\u2699${runningTotal}`, "info", colorEnabled));
5708
+ }
5709
+ if (state.gitStatus) {
5710
+ const { modified, untracked } = state.gitStatus;
5711
+ emergency.push(themeText(
5712
+ `\u2442${modified > 0 ? `*${modified}` : ""}${untracked > 0 ? `?${untracked}` : ""}`,
5713
+ "warning",
5714
+ colorEnabled
5715
+ ));
5716
+ }
5717
+ if (creditsSegment) {
5718
+ emergency.push(themeText(formatCreditsChip(credits ?? 0, { compact: true }), "muted", colorEnabled));
5719
+ }
5720
+ visibleParts = [emergency.join(" ")];
5721
+ }
5844
5722
  }
5845
- return prefix.length > buffer.length ? prefix : null;
5723
+ const body = visibleParts.join(sep);
5724
+ const surface = colorEnabled ? surfaceBackgroundSequence() : "";
5725
+ if (!surface) return body;
5726
+ return `${surface} ${body} \x1B[49m`;
5846
5727
  }
5847
- function completeSlashCommand(buffer, cwd) {
5848
- if (!buffer.startsWith("/")) return [];
5849
- const trimmed = buffer.trim();
5850
- if (cwd && buffer.startsWith("/cd ")) {
5851
- const prefix = buffer.slice("/cd ".length);
5852
- return completeCdPathCandidates(prefix, cwd);
5728
+ function buildPlainScene(isDark, frame = 0, maxFrames = 0) {
5729
+ let skyLine = null;
5730
+ if (isDark === true) {
5731
+ const star1 = frame % 6 < 3 ? "\u2726" : "\u22C6";
5732
+ const star2 = frame % 4 < 2 ? "\u22C6" : "\xB7";
5733
+ const star3 = frame % 5 < 2 ? "\xB7" : "\u2726";
5734
+ skyLine = ` ${star1} \u263E ${star2} ${star3}`;
5735
+ } else if (isDark === false) {
5736
+ skyLine = ` \u2600`;
5853
5737
  }
5854
- if (trimmed.includes(" ")) return [];
5855
- return SLASH_COMMANDS.filter((cmd) => cmd.startsWith(trimmed) && cmd !== trimmed);
5738
+ const wavePattern = "_.~^~.";
5739
+ const longWave = wavePattern.repeat(10);
5740
+ const offset = frame % wavePattern.length;
5741
+ const wave = longWave.slice(offset, offset + 25);
5742
+ return [
5743
+ ...skyLine ? [skyLine] : [],
5744
+ " \u2571\u2572 \u2588\u2584 \u2588 \u2584\u2580\u2580\u2584 \u2588 \u2584\u2580\u2580\u2584",
5745
+ " \u2571 \u2572 \u2571\u2572 \u2588 \u2580\u2588 \u2588 \u2588 \u2588 \u2588 \u2588",
5746
+ " \u2571 \u2572\u2571 \u2572 \u2580 \u2580 \u2580\u2580 \u2580\u2580\u2580\u2580 \u2580\u2580",
5747
+ ` \u2571 \u2660 \u2572 ${wave}`,
5748
+ " \u2581\u2581\u2581\u2581\u2581\u2581\u2571 \u2660 \u2660 \u2572\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581"
5749
+ ].join("\n");
5856
5750
  }
5857
- function completeCdPathCandidates(prefix, cwd) {
5858
- const lastSlash = prefix.lastIndexOf("/");
5859
- const head = lastSlash >= 0 ? prefix.slice(0, lastSlash + 1) : "";
5860
- const baseName = lastSlash >= 0 ? prefix.slice(lastSlash + 1) : prefix;
5861
- let dirPath;
5862
- if (head === "~" || head === "~/" || head === "~\\") {
5863
- dirPath = homedir2();
5864
- } else if (head.startsWith("~/") || head.startsWith("~\\")) {
5865
- dirPath = resolve2(homedir2(), head.slice(2));
5866
- } else {
5867
- dirPath = head.startsWith("/") ? head : resolve2(cwd, head);
5751
+ function buildColoredScene(isDark, frame = 0, maxFrames = 0) {
5752
+ const pk = themeColorSequence("chrome");
5753
+ const sk = themeColorSequence("warning");
5754
+ const tr = themeColorSequence("success");
5755
+ const wv = themeColorSequence("info");
5756
+ const ac = themeColorSequence("accent");
5757
+ const mu = themeColorSequence("muted");
5758
+ const r = "\x1B[39m";
5759
+ const b = "\x1B[1m";
5760
+ const rs = "\x1B[0m";
5761
+ let skyLine = null;
5762
+ if (isDark === true) {
5763
+ const star1 = frame % 6 < 3 ? "\u2726" : "\u22C6";
5764
+ const star2 = frame % 4 < 2 ? "\u22C6" : "\xB7";
5765
+ const star3 = frame % 5 < 2 ? "\xB7" : "\u2726";
5766
+ skyLine = ` ${mu}${star1}${r} ${sk}\u263E${r} ${mu}${star2}${r} ${mu}${star3}${r}`;
5767
+ } else if (isDark === false) {
5768
+ skyLine = ` ${sk}\u2600${r}`;
5868
5769
  }
5869
- let entries;
5870
- try {
5871
- entries = readdirSync(dirPath, { withFileTypes: true });
5872
- } catch {
5873
- return [];
5770
+ const wavePattern = "_.~^~.";
5771
+ const longWave = wavePattern.repeat(10);
5772
+ const offset = frame % wavePattern.length;
5773
+ const wave = longWave.slice(offset, offset + 25);
5774
+ const waveStr = `${wv}${wave.slice(0, 20)}${r}${mu}${wave.slice(20, 25)}${r}`;
5775
+ const line1 = "\u2588\u2584 \u2588 \u2584\u2580\u2580\u2584 \u2588 \u2584\u2580\u2580\u2584";
5776
+ const line2 = "\u2588 \u2580\u2588 \u2588 \u2588 \u2588 \u2588 \u2588";
5777
+ const line3 = "\u2580 \u2580 \u2580\u2580 \u2580\u2580\u2580\u2580 \u2580\u2580";
5778
+ const sweepEndFrame = maxFrames > 3 ? maxFrames - 3 : maxFrames;
5779
+ const sweepLen = maxFrames === 0 ? 21 : Math.min(21, Math.floor(frame / sweepEndFrame * 21));
5780
+ const colorLine = (str, bold) => {
5781
+ const active = str.slice(0, sweepLen);
5782
+ const dimmed = str.slice(sweepLen);
5783
+ return `${bold ? b : ""}${ac}${active}${r}${mu}${dimmed}${r}${bold ? rs : ""}`;
5784
+ };
5785
+ const nolo1 = colorLine(line1, true);
5786
+ const nolo2 = colorLine(line2, false);
5787
+ const nolo3 = colorLine(line3, false);
5788
+ return [
5789
+ ...skyLine ? [skyLine] : [],
5790
+ ` ${pk}\u2571\u2572${r} ${nolo1}`,
5791
+ ` ${pk}\u2571 \u2572 \u2571\u2572${r} ${nolo2}`,
5792
+ ` ${pk}\u2571 \u2572\u2571 \u2572${r} ${nolo3}`,
5793
+ ` ${pk}\u2571${r} ${tr}\u2660${r} ${pk}\u2572${r} ${waveStr}`,
5794
+ ` ${pk}\u2581\u2581\u2581\u2581\u2581\u2581\u2571${r} ${tr}\u2660${r} ${tr}\u2660${r} ${pk}\u2572\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581${r}`
5795
+ ].join("\n");
5796
+ }
5797
+ function renderWelcome(state, frame = 0, maxFrames = 0, columns) {
5798
+ const colorEnabled = resolveCliColorEnabled();
5799
+ const brightnessSignal = resolveTuiBrightnessSignal();
5800
+ const isDark = brightnessSignal === null ? null : brightnessSignal === "dark";
5801
+ let sceneArt = colorEnabled ? buildColoredScene(isDark, frame, maxFrames) : buildPlainScene(isDark, frame, maxFrames);
5802
+ if (typeof columns === "number" && columns > 0) {
5803
+ const widestSceneCol = sceneArt.split("\n").reduce((max, line) => Math.max(max, displayWidth(stripAnsi(line))), 0);
5804
+ if (columns < widestSceneCol) sceneArt = "";
5874
5805
  }
5875
- const hiddenRequested = baseName.startsWith(".");
5876
- const names = entries.filter((e) => {
5877
- if (e.isDirectory()) return true;
5878
- if (!e.isSymbolicLink()) return false;
5879
- try {
5880
- return statSync2(resolve2(dirPath, e.name)).isDirectory();
5881
- } catch {
5882
- return false;
5806
+ const noloLabel = themeText("nolo", "accent", colorEnabled);
5807
+ const versionLine = `${noloLabel}${state.cliVersion ? ` ${state.cliVersion}` : ""} | server ${state.serverUrl}`;
5808
+ const updateLine = state.updateAvailable ? themeText(
5809
+ t("updateAvailable", state.updateAvailable.latestVersion),
5810
+ "accent",
5811
+ colorEnabled
5812
+ ) : null;
5813
+ const authGuidanceLine = state.showAuthGuidance ? t("welcomeAuthGuidance") : null;
5814
+ const body = sceneArt ? [sceneArt, versionLine, ...updateLine ? [updateLine] : [], ...authGuidanceLine ? [authGuidanceLine] : [], dailyWelcomeTip(), ""] : [versionLine, ...updateLine ? [updateLine] : [], ...authGuidanceLine ? [authGuidanceLine] : [], dailyWelcomeTip(), ""];
5815
+ return body.join("\n");
5816
+ }
5817
+ function renderPrompt(_state) {
5818
+ return t("promptLabel");
5819
+ }
5820
+ function renderTuiHelp(colorEnabled = resolveCliColorEnabled()) {
5821
+ const text = t("helpText");
5822
+ if (!colorEnabled) {
5823
+ return text;
5824
+ }
5825
+ const lines = text.split("\n");
5826
+ const commandRegex = /^(\s+)(\/\S+(?:\s+\S+)*?)(\s{2,})(.+)$/;
5827
+ const sectionRegex = /^\S.+[::]$/;
5828
+ return lines.map((line) => {
5829
+ if (!line.trim()) {
5830
+ return line;
5883
5831
  }
5884
- }).map((e) => e.name).filter((name) => {
5885
- if (!name.startsWith(baseName)) return false;
5886
- return hiddenRequested || !name.startsWith(".");
5887
- }).sort();
5888
- return names.map((name) => `/cd ${head}${name}/`);
5832
+ if (sectionRegex.test(line)) {
5833
+ return renderDialogTitle(line, colorEnabled);
5834
+ }
5835
+ const match = line.match(commandRegex);
5836
+ if (match) {
5837
+ const [, indent, cmd, spacing, desc] = match;
5838
+ return `${indent}${themeText(cmd, "accent", colorEnabled)}${spacing}${themeText(desc, "muted", colorEnabled)}`;
5839
+ }
5840
+ return themeText(line, "muted", colorEnabled);
5841
+ }).join("\n");
5889
5842
  }
5890
- function isLikelySlashCommand(input) {
5891
- const trimmed = input.trim();
5892
- if (!trimmed.startsWith("/")) return false;
5893
- const spaceIdx = trimmed.search(/\s/);
5894
- const firstToken = spaceIdx === -1 ? trimmed : trimmed.slice(0, spaceIdx);
5895
- return /^\/[a-zA-Z_][a-zA-Z0-9._:-]*$/.test(firstToken);
5843
+ function renderCreditsDebug(state, colorEnabled = resolveCliColorEnabled()) {
5844
+ const credits = resolveStatusLineCredits(state);
5845
+ const lines = [
5846
+ "[credits debug] \u79EF\u5206\u94FE\u8DEF\u771F\u503C",
5847
+ `\u2022 dialogCreditsBase : ${state.dialogCreditsBase?.toFixed(4) ?? "undefined\uFF08\u670D\u52A1\u7AEF\u57FA\u6570\u672A seed\u2014\u2014/pick \u540E\u9996\u6B21\u8BFB\u53D6\u5931\u8D25\u6216\u670D\u52A1\u7AEF\u672A\u5199 totalCost\uFF09"}`,
5848
+ `\u2022 sessionCredits : ${state.sessionCredits?.toFixed(4) ?? "undefined\uFF08\u672C\u4F1A\u8BDD\u8FD8\u6CA1\u6709\u5E73\u53F0\u8BA1\u8D39\u8F6E\uFF09"}`,
5849
+ `\u2022 \u72B6\u6001\u884C\u663E\u793A : ${credits !== void 0 && credits > 0 ? formatCreditsChip(credits) : "\uFF08\u65E0 \u26A1\u2014\u2014\u4E24\u6BB5\u5408\u8BA1\u4E3A 0/undefined\uFF09"}`,
5850
+ `\u2022 turnTokens.credits: ${state.turnTokens?.credits?.toFixed(4) ?? "undefined"}\uFF08\u672C\u8F6E\u6700\u540E\u4E00\u6B21\u8C03\u7528\u7684\u6298\u7B97\u503C\uFF0C\u4EC5\u4F9B\u53C2\u8003\uFF0C\u4E0D\u8FDB\u72B6\u6001\u884C\uFF09`,
5851
+ `\u2022 contextWindow : ${state.contextWindow ?? "unknown"}`,
5852
+ '\u2022 \u5224\u5B9A\u53E3\u5F84\uFF1A\u53EA\u6709 billing_unit === "credits" \u7684\u5E73\u53F0\u8BA1\u8D39\u5E27\u624D\u7D2F\u8BA1\uFF1B\u81EA\u6709 API / \u8BA2\u9605\u5236\u6052\u4E3A undefined\u3002',
5853
+ "\u2022 \u82E5\u521A\u8DD1\u5B8C\u5E73\u53F0\u8BA1\u8D39\u8F6E\u4ECD\u65E0 \u26A1\uFF1A\u68C0\u67E5 runAgentTurn \u8FD4\u56DE\u662F\u5426\u5E26 turnCredits\uFF08foldLocalResultForTui \u767D\u540D\u5355\uFF09\u3002"
5854
+ ];
5855
+ return lines.map((line) => colorEnabled ? themeText(line, "chrome") : line).join("\n");
5896
5856
  }
5897
- function stripImageTokens(input, hints) {
5898
- if (hints.length === 0) return input;
5899
- let out = input;
5900
- for (const hint of hints) {
5901
- if (!hint.raw) continue;
5902
- const escaped = hint.raw.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
5903
- out = out.replace(new RegExp(escaped, "g"), "");
5857
+ function renderContextPanel(state, colorEnabled = resolveCliColorEnabled()) {
5858
+ const docs = state.attachedDocs.length ? state.attachedDocs.join(", ") : "none";
5859
+ const skills = state.attachedSkills.length ? state.attachedSkills.join(", ") : "none";
5860
+ const labels = [
5861
+ t("contextFieldAgent"),
5862
+ t("contextFieldTokens"),
5863
+ t("contextFieldDialog"),
5864
+ t("contextFieldDocs"),
5865
+ t("contextFieldSkills"),
5866
+ t("contextFieldProfile"),
5867
+ t("contextFieldRuntime"),
5868
+ t("contextFieldServer")
5869
+ ];
5870
+ let maxW = 0;
5871
+ for (const l of labels) {
5872
+ const w = displayWidth(l);
5873
+ if (w > maxW) maxW = w;
5904
5874
  }
5905
- return compactWhitespace(out);
5875
+ const targetWidth = maxW >= 9 ? maxW + 1 : 9;
5876
+ const padLabel = (raw) => {
5877
+ const w = displayWidth(raw);
5878
+ const padding = " ".repeat(Math.max(0, targetWidth - w));
5879
+ return raw + padding;
5880
+ };
5881
+ const field = (rawLabel, value) => `${themeText(padLabel(rawLabel), "muted", colorEnabled)}${value}`;
5882
+ const next = (command, description) => ` ${themeText(command, "accent", colorEnabled)}${themeText(description, "muted", colorEnabled)}`;
5883
+ const titleText = t("contextTitle");
5884
+ const heading = colorEnabled ? [renderDialogTitle(titleText, true)] : [titleText, "\u2500".repeat(displayWidth(titleText))];
5885
+ return [
5886
+ ...heading,
5887
+ field(labels[0], `${state.agentName} (${state.agentKey})`),
5888
+ field(labels[1], renderTokenStatus(state.turnTokens)),
5889
+ field(
5890
+ labels[2],
5891
+ state.dialogKey ?? (state.dialogId ? "unavailable" : state.dialogLabel)
5892
+ ),
5893
+ field(labels[3], docs),
5894
+ field(labels[4], skills),
5895
+ field(labels[5], state.profileName),
5896
+ field(labels[6], state.runtimeMode),
5897
+ field(labels[7], state.serverUrl),
5898
+ "",
5899
+ themeText(t("contextNext"), "chrome", colorEnabled),
5900
+ next("/agents ", ` ${t("contextNextAgents")}`),
5901
+ next("/doc attach <doc> ", ` ${t("contextNextDoc")}`),
5902
+ next("/skill attach <ref>", ` ${t("contextNextSkill")}`),
5903
+ next("/new ", ` ${t("contextNextNew")}`),
5904
+ next("/clear ", ` ${t("contextNextClear")}`)
5905
+ ].join("\n");
5906
+ }
5907
+ function renderKnownAgents(colorEnabled = resolveCliColorEnabled()) {
5908
+ return [
5909
+ renderDialogTitle(t("agentsTitle"), colorEnabled),
5910
+ ...resolveCatalogPlatformAgents().map(
5911
+ (agent, index) => ` ${themeText(String(index + 1), "chrome", colorEnabled)} ${themeText(
5912
+ agent.name.padEnd(11),
5913
+ "accent",
5914
+ colorEnabled
5915
+ )} ${themeText(agent.description ?? "", "muted", colorEnabled)}`
5916
+ ),
5917
+ "",
5918
+ themeText(
5919
+ t("agentsTip"),
5920
+ "muted",
5921
+ colorEnabled
5922
+ )
5923
+ ].join("\n");
5906
5924
  }
5907
5925
 
5908
5926
  // packages/cli/tui/conversationLinks.ts
@@ -6181,6 +6199,7 @@ function createInitialTuiState(env = process.env) {
6181
6199
  dialogOwnerId,
6182
6200
  dialogLabel: dialogEnvValue ?? "new",
6183
6201
  profileName: asOptionalTrimmedString(env.NOLO_PROFILE) ?? "local",
6202
+ showAuthGuidance: resolveAuthGuidanceState(env).guidanceNeeded,
6184
6203
  serverUrl: (env.NOLO_SERVER || env.BASE_URL || DEFAULT_TUI_SERVER_URL).replace(
6185
6204
  /\/+$/,
6186
6205
  ""
@@ -6252,12 +6271,9 @@ function handleTuiInput(input, state, historyTurns) {
6252
6271
  };
6253
6272
  }
6254
6273
  if (!isLikelySlashCommand(trimmed)) {
6255
- const hints = detectImagePaths(trimmed, state.cwd);
6256
- const readableHints = hints.filter((hint) => !hint.unreadable);
6257
- const unreadableHints = hints.filter((hint) => hint.unreadable);
6258
- const stripped = stripImageTokens(trimmed, readableHints);
6259
- const finalMessage = stripped.length > 0 ? stripped : trimmed;
6260
- const imagePaths = readableHints.map((hint) => hint.resolvedPath);
6274
+ const detected = detectSubmittedImagePaths(trimmed, state.cwd);
6275
+ const { hints, unreadableHints, imagePaths } = detected;
6276
+ const finalMessage = detected.message;
6261
6277
  const fileRefs = detectFileReferences(trimmed, state.cwd, {
6262
6278
  exclude: hints.map((hint) => hint.resolvedPath)
6263
6279
  });
@@ -6744,13 +6760,6 @@ ${t("autoUsage")}`
6744
6760
  output: t("customizeHint")
6745
6761
  };
6746
6762
  case "/login": {
6747
- if (!argText) {
6748
- return {
6749
- nextState: state,
6750
- output: `${t("loginHint")}
6751
- ${t("loginTuiStart")}`
6752
- };
6753
- }
6754
6763
  return {
6755
6764
  nextState: state,
6756
6765
  output: "",
@@ -8054,10 +8063,14 @@ function projectChatQueueStatus({
8054
8063
  function createChatQueueTuiBinding(runTurn) {
8055
8064
  const runtime = createChatQueueRuntime();
8056
8065
  let preemptArmed = null;
8057
- const resolveSubmit = ({ text, isRunning }) => {
8066
+ const resolveSubmit = ({
8067
+ text,
8068
+ isRunning,
8069
+ attachmentCount = 0
8070
+ }) => {
8058
8071
  return resolveChatSendDecision({
8059
8072
  text,
8060
- imagePreviewCount: 0,
8073
+ imagePreviewCount: attachmentCount,
8061
8074
  pendingFileCount: 0,
8062
8075
  isSendBlocked: false,
8063
8076
  canMultiImg: true,
@@ -8143,13 +8156,17 @@ function createChatQueueTuiBinding(runTurn) {
8143
8156
  preemptArmed = "stop";
8144
8157
  return true;
8145
8158
  };
8146
- const snapshotAndClearQueue = () => {
8159
+ const snapshotAndClearQueueWithImages = () => {
8147
8160
  const status = runtime.getState();
8148
8161
  if (status.queue.length === 0) return null;
8149
8162
  const merged = status.queue.map((req) => req.text).join("\n");
8163
+ const imagePaths = [
8164
+ ...new Set(status.queue.flatMap((req) => req.imagePaths ?? []))
8165
+ ];
8150
8166
  runtime.send({ type: "clear" });
8151
- return merged;
8167
+ return { text: merged, imagePaths };
8152
8168
  };
8169
+ const snapshotAndClearQueue = () => snapshotAndClearQueueWithImages()?.text ?? null;
8153
8170
  const clear = () => {
8154
8171
  runtime.send({ type: "clear" });
8155
8172
  };
@@ -8173,6 +8190,7 @@ function createChatQueueTuiBinding(runTurn) {
8173
8190
  preemptForDrain,
8174
8191
  preemptForStop,
8175
8192
  snapshotAndClearQueue,
8193
+ snapshotAndClearQueueWithImages,
8176
8194
  clear,
8177
8195
  recoverStaleRunning,
8178
8196
  getStatus,
@@ -9497,10 +9515,30 @@ async function runOneAgentTurn(ctx, inputMsg, imageUrls, actionGateHandler, conf
9497
9515
  }
9498
9516
  }
9499
9517
  }
9518
+ async function runDrainedQueueTurn(ctx, req, actionGateHandler, confirmDestructiveAction, runTurn = runOneAgentTurn) {
9519
+ let imageUrls = [];
9520
+ if (req.imagePaths && req.imagePaths.length > 0) {
9521
+ try {
9522
+ ({ imageUrls } = await resolveAttachmentImageUrls({
9523
+ actionImagePaths: req.imagePaths,
9524
+ attachedImages: [],
9525
+ onFailure: (_path, err) => ctx.output.write(`[nolo] image skipped: ${err.message}
9526
+ `)
9527
+ }));
9528
+ } catch (err) {
9529
+ ctx.output.write(
9530
+ `[nolo] image skipped: ${err instanceof Error ? err.message : String(err)}
9531
+ `
9532
+ );
9533
+ imageUrls = [];
9534
+ }
9535
+ }
9536
+ return runTurn(ctx, req, imageUrls, actionGateHandler, confirmDestructiveAction);
9537
+ }
9500
9538
  function ensureChatQueueBinding(ctx, actionGateHandler, confirmDestructiveAction) {
9501
9539
  if (ctx.chatQueueBinding) return ctx.chatQueueBinding;
9502
- ctx.chatQueueBinding = createChatQueueTuiBinding(async (text) => {
9503
- return runOneAgentTurn(ctx, text, [], actionGateHandler, confirmDestructiveAction);
9540
+ ctx.chatQueueBinding = createChatQueueTuiBinding(async (req) => {
9541
+ return runDrainedQueueTurn(ctx, req, actionGateHandler, confirmDestructiveAction);
9504
9542
  });
9505
9543
  return ctx.chatQueueBinding;
9506
9544
  }
@@ -10712,6 +10750,7 @@ ${stderrText.trim()}
10712
10750
  );
10713
10751
  if (outcome.status === "success") {
10714
10752
  env.AUTH_TOKEN = outcome.token;
10753
+ host.state = { ...host.state, showAuthGuidance: false };
10715
10754
  }
10716
10755
  }
10717
10756
  if (result.action?.type === "chat") {
@@ -11829,6 +11868,7 @@ ${err.message}` : ""}`
11829
11868
  });
11830
11869
  if (outcome.status === "success") {
11831
11870
  env.AUTH_TOKEN = outcome.token;
11871
+ state = { ...state, showAuthGuidance: false };
11832
11872
  }
11833
11873
  } else if (res.action) {
11834
11874
  output.write(
@@ -11863,12 +11903,19 @@ ${hint}` : hint;
11863
11903
  return;
11864
11904
  }
11865
11905
  const flushCount = chatQueueBinding.queueLength();
11866
- const merged = chatQueueBinding.snapshotAndClearQueue();
11867
- if (!merged) return;
11906
+ const flushed = chatQueueBinding.snapshotAndClearQueueWithImages();
11907
+ if (!flushed) return;
11908
+ const merged = flushed.text;
11868
11909
  const draftIncluded = !busy && buffer.trim() !== "";
11869
11910
  const fullText = draftIncluded ? `${buffer}
11870
11911
  ${merged}` : merged;
11871
- chatQueueBinding.enqueue(fullText);
11912
+ chatQueueBinding.enqueue(
11913
+ flushed.imagePaths.length > 0 ? {
11914
+ event: { kind: "user", text: fullText },
11915
+ text: fullText,
11916
+ imagePaths: flushed.imagePaths
11917
+ } : fullText
11918
+ );
11872
11919
  const totalCount = flushCount + (draftIncluded ? 1 : 0);
11873
11920
  emitCommandOutput(
11874
11921
  t(busy ? "flushQueuedBusyHint" : "flushQueuedIdleHint", String(totalCount))
@@ -12067,16 +12114,33 @@ ${merged}` : merged;
12067
12114
  }
12068
12115
  const { actionGateHandler, confirmDestructiveAction } = buildInteractiveTurnHandlers();
12069
12116
  const binding = ensureChatQueueBinding(turnCtx, actionGateHandler, confirmDestructiveAction);
12117
+ const busyImages = detectSubmittedImagePaths(submittedText, state.cwd);
12070
12118
  const decision = binding.resolveSubmit({
12071
12119
  text: submittedText,
12072
- isRunning: true
12120
+ isRunning: true,
12121
+ attachmentCount: state.attachedImages.length
12073
12122
  });
12074
12123
  if (decision.kind === "queue-text") {
12075
- binding.enqueue(decision.text);
12124
+ if (busyImages.imagePaths.length > 0) {
12125
+ const message = busyImages.message.trim();
12126
+ binding.enqueue({
12127
+ event: { kind: "user", text: message },
12128
+ text: message,
12129
+ imagePaths: busyImages.imagePaths
12130
+ });
12131
+ } else {
12132
+ binding.enqueue(decision.text);
12133
+ }
12076
12134
  buffer = "";
12077
12135
  cursorPos = 0;
12078
12136
  fixedInput.repaint(buffer, cursorPos);
12079
12137
  } else if (decision.kind === "queue-blocked") {
12138
+ if (state.attachedImages.length > 0) {
12139
+ emitCommandOutput(
12140
+ `[nolo] ${t("busyAttachmentsBlocked", String(state.attachedImages.length))}`
12141
+ );
12142
+ if (fixedInput.active) fixedInput.repaint(buffer, cursorPos);
12143
+ }
12080
12144
  } else if (decision.kind === "noop" && !submittedText.trim() && binding.queueLength() > 0) {
12081
12145
  preemptAndAbortForDrain(binding, activeTurnAbort);
12082
12146
  }