@uncarved/jade 0.1.2 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (436) hide show
  1. package/bin/jade.js +5 -4
  2. package/dist/api.d.ts +266 -0
  3. package/dist/api.js +38 -0
  4. package/dist/api.js.map +1 -0
  5. package/dist/config.d.ts +13 -32
  6. package/dist/config.js +39 -121
  7. package/dist/config.js.map +1 -1
  8. package/dist/fetch.d.ts +20 -0
  9. package/dist/fetch.js +190 -0
  10. package/dist/fetch.js.map +1 -0
  11. package/dist/hash.d.ts +2 -0
  12. package/dist/hash.js +42 -0
  13. package/dist/hash.js.map +1 -0
  14. package/dist/host.d.ts +71 -0
  15. package/dist/host.js +400 -0
  16. package/dist/host.js.map +1 -0
  17. package/dist/index.d.ts +11 -28
  18. package/dist/index.js +11 -28
  19. package/dist/index.js.map +1 -1
  20. package/dist/install.d.ts +78 -0
  21. package/dist/install.js +292 -0
  22. package/dist/install.js.map +1 -0
  23. package/dist/main.d.ts +1 -2
  24. package/dist/main.js +156 -1223
  25. package/dist/main.js.map +1 -1
  26. package/dist/manifest.d.ts +23 -0
  27. package/dist/manifest.js +159 -0
  28. package/dist/manifest.js.map +1 -0
  29. package/dist/membrane.d.ts +33 -0
  30. package/dist/membrane.js +140 -0
  31. package/dist/membrane.js.map +1 -0
  32. package/dist/remote.d.ts +10 -0
  33. package/dist/remote.js +292 -0
  34. package/dist/remote.js.map +1 -0
  35. package/dist/rescue.d.ts +10 -0
  36. package/dist/rescue.js +216 -0
  37. package/dist/rescue.js.map +1 -0
  38. package/dist/resolve.d.ts +34 -0
  39. package/dist/resolve.js +178 -0
  40. package/dist/resolve.js.map +1 -0
  41. package/dist/rpc.d.ts +26 -0
  42. package/dist/rpc.js +144 -0
  43. package/dist/rpc.js.map +1 -0
  44. package/dist/secrets.d.ts +12 -0
  45. package/dist/secrets.js +125 -0
  46. package/dist/secrets.js.map +1 -0
  47. package/dist/session.d.ts +45 -0
  48. package/dist/session.js +401 -0
  49. package/dist/session.js.map +1 -0
  50. package/dist/source.d.ts +12 -0
  51. package/dist/source.js +72 -0
  52. package/dist/source.js.map +1 -0
  53. package/dist/state.d.ts +37 -0
  54. package/dist/state.js +93 -0
  55. package/dist/state.js.map +1 -0
  56. package/dist/update.d.ts +55 -0
  57. package/dist/update.js +258 -0
  58. package/dist/update.js.map +1 -0
  59. package/package.json +12 -9
  60. package/plugins/approval/index.ts +297 -0
  61. package/plugins/approval/plugin.json +18 -0
  62. package/{src/plugins → plugins/approval}/policy.ts +21 -84
  63. package/plugins/approval/review.ts +192 -0
  64. package/plugins/ask/index.ts +159 -0
  65. package/plugins/ask/plugin.json +8 -0
  66. package/plugins/budget/index.ts +38 -0
  67. package/plugins/budget/plugin.json +13 -0
  68. package/{src/plugins → plugins/checks}/checks.ts +68 -39
  69. package/plugins/checks/index.ts +158 -0
  70. package/plugins/checks/plugin.json +14 -0
  71. package/plugins/checks/project.ts +81 -0
  72. package/plugins/commands/index.ts +76 -0
  73. package/plugins/commands/plugin.json +7 -0
  74. package/{src/plugins → plugins/compact}/compact.ts +112 -38
  75. package/plugins/compact/index.ts +115 -0
  76. package/plugins/compact/plugin.json +17 -0
  77. package/plugins/compact/style.ts +17 -0
  78. package/plugins/continue/index.ts +58 -0
  79. package/plugins/continue/plugin.json +13 -0
  80. package/{src/ui → plugins/fs}/diff.ts +3 -4
  81. package/{src/tools → plugins/fs}/fs.ts +64 -46
  82. package/{src/tools → plugins/fs}/grep.ts +4 -3
  83. package/plugins/fs/index.ts +34 -0
  84. package/plugins/fs/plugin.json +7 -0
  85. package/plugins/fs/renderers.ts +138 -0
  86. package/plugins/fs/style.ts +18 -0
  87. package/plugins/fs/sys.ts +81 -0
  88. package/plugins/keys/index.ts +53 -0
  89. package/plugins/keys/plugin.json +7 -0
  90. package/plugins/mcp/index.ts +192 -0
  91. package/{src → plugins/mcp}/mcp.ts +32 -32
  92. package/plugins/mcp/plugin.json +7 -0
  93. package/plugins/mcp/project.ts +93 -0
  94. package/plugins/memory/index.ts +105 -0
  95. package/{src → plugins/memory}/memory.ts +20 -2
  96. package/plugins/memory/notes.ts +43 -0
  97. package/plugins/memory/plugin.json +7 -0
  98. package/plugins/memory/style.ts +17 -0
  99. package/plugins/mentions/attach.ts +127 -0
  100. package/plugins/mentions/index.ts +79 -0
  101. package/plugins/mentions/plugin.json +7 -0
  102. package/plugins/mentions/style.ts +17 -0
  103. package/plugins/models/config.ts +53 -0
  104. package/plugins/models/configure.ts +455 -0
  105. package/plugins/models/context.ts +32 -0
  106. package/plugins/models/index.ts +198 -0
  107. package/plugins/models/plugin.json +8 -0
  108. package/{src → plugins/models}/provider.ts +23 -27
  109. package/plugins/models/saved.ts +94 -0
  110. package/plugins/modes/index.ts +222 -0
  111. package/plugins/modes/plugin.json +9 -0
  112. package/plugins/plugins/index.ts +38 -0
  113. package/plugins/plugins/plugin.json +7 -0
  114. package/plugins/print/index.ts +142 -0
  115. package/plugins/print/plugin.json +8 -0
  116. package/plugins/prompts/index.ts +83 -0
  117. package/plugins/prompts/plugin.json +8 -0
  118. package/plugins/prompts/prompts.ts +253 -0
  119. package/plugins/prompts/sys.ts +72 -0
  120. package/plugins/renderers/index.ts +78 -0
  121. package/plugins/renderers/plugin.json +7 -0
  122. package/plugins/repeats/index.ts +165 -0
  123. package/plugins/repeats/plugin.json +6 -0
  124. package/plugins/schedule/cron.ts +74 -0
  125. package/plugins/schedule/index.ts +292 -0
  126. package/plugins/schedule/plugin.json +13 -0
  127. package/plugins/schedule/store.ts +149 -0
  128. package/plugins/scratch/index.ts +31 -0
  129. package/plugins/scratch/plugin.json +7 -0
  130. package/plugins/screenshot/index.ts +40 -0
  131. package/plugins/screenshot/plugin.json +7 -0
  132. package/plugins/screenshot/sys.ts +84 -0
  133. package/{src/tools/screenshot.ts → plugins/screenshot/tool.ts} +6 -6
  134. package/plugins/sessions/index.ts +148 -0
  135. package/plugins/sessions/plugin.json +8 -0
  136. package/plugins/shell/index.ts +33 -0
  137. package/plugins/shell/plugin.json +17 -0
  138. package/plugins/shell/renderers.ts +45 -0
  139. package/plugins/shell/service.ts +44 -0
  140. package/{src/tools → plugins/shell}/shell.ts +36 -21
  141. package/{src → plugins/shell}/sys.ts +19 -43
  142. package/plugins/skills/index.ts +96 -0
  143. package/plugins/skills/plugin.json +7 -0
  144. package/plugins/skills/project.ts +49 -0
  145. package/{src → plugins/skills}/skills.ts +4 -11
  146. package/plugins/suggest/index.ts +286 -0
  147. package/plugins/suggest/plugin.json +18 -0
  148. package/plugins/task/index.ts +167 -0
  149. package/plugins/task/plugin.json +15 -0
  150. package/plugins/task/style.ts +17 -0
  151. package/plugins/task/subagent.ts +257 -0
  152. package/{src/tools/todo.ts → plugins/todo/index.ts} +33 -7
  153. package/plugins/todo/plugin.json +7 -0
  154. package/{src/ui → plugins/tui}/editor.ts +53 -1
  155. package/plugins/tui/frontend.ts +596 -0
  156. package/plugins/tui/index.ts +37 -0
  157. package/{src/ui → plugins/tui}/markdown.ts +258 -219
  158. package/plugins/tui/mentions.ts +113 -0
  159. package/plugins/tui/plugin.json +10 -0
  160. package/plugins/tui/render.ts +67 -0
  161. package/plugins/tui/screen.ts +268 -0
  162. package/{src/ui → plugins/tui}/transcript.ts +179 -111
  163. package/{src/ui/tui.tsx → plugins/tui/tui.ts} +684 -418
  164. package/{src/tools → plugins/undo}/checkpoint.ts +21 -60
  165. package/plugins/undo/index.ts +139 -0
  166. package/plugins/undo/notes.ts +43 -0
  167. package/plugins/undo/plugin.json +7 -0
  168. package/plugins/undo/style.ts +17 -0
  169. package/plugins/update/index.ts +40 -0
  170. package/plugins/update/plugin.json +13 -0
  171. package/plugins/web/env.ts +78 -0
  172. package/plugins/web/index.ts +133 -0
  173. package/plugins/web/plugin.json +15 -0
  174. package/plugins/web/renderers.ts +11 -0
  175. package/plugins/web/web.ts +713 -0
  176. package/plugins-dist/approval/index.js +271 -0
  177. package/plugins-dist/approval/plugin.json +24 -0
  178. package/{dist/plugins → plugins-dist/approval}/policy.js +15 -65
  179. package/plugins-dist/approval/review.js +176 -0
  180. package/{dist/plugins → plugins-dist/approval}/schema.js +0 -1
  181. package/plugins-dist/ask/index.js +145 -0
  182. package/plugins-dist/ask/plugin.json +12 -0
  183. package/plugins-dist/budget/index.js +37 -0
  184. package/plugins-dist/budget/plugin.json +15 -0
  185. package/{dist/plugins → plugins-dist/checks}/checks.js +65 -34
  186. package/plugins-dist/checks/index.js +150 -0
  187. package/plugins-dist/checks/plugin.json +21 -0
  188. package/plugins-dist/checks/project.js +76 -0
  189. package/plugins-dist/commands/index.js +33 -0
  190. package/plugins-dist/commands/plugin.json +9 -0
  191. package/{dist/plugins → plugins-dist/compact}/compact.js +95 -33
  192. package/plugins-dist/compact/index.js +100 -0
  193. package/plugins-dist/compact/plugin.json +25 -0
  194. package/plugins-dist/compact/style.js +14 -0
  195. package/plugins-dist/continue/index.js +57 -0
  196. package/plugins-dist/continue/plugin.json +15 -0
  197. package/{dist/ui → plugins-dist/fs}/diff.js +3 -5
  198. package/{dist/tools → plugins-dist/fs}/fs.js +62 -46
  199. package/{dist/tools → plugins-dist/fs}/grep.js +4 -4
  200. package/plugins-dist/fs/index.js +36 -0
  201. package/plugins-dist/fs/plugin.json +10 -0
  202. package/plugins-dist/fs/renderers.js +132 -0
  203. package/plugins-dist/fs/style.js +15 -0
  204. package/plugins-dist/fs/sys.js +54 -0
  205. package/plugins-dist/keys/index.js +36 -0
  206. package/plugins-dist/keys/plugin.json +9 -0
  207. package/plugins-dist/mcp/index.js +187 -0
  208. package/{dist → plugins-dist/mcp}/mcp.js +34 -30
  209. package/plugins-dist/mcp/plugin.json +12 -0
  210. package/plugins-dist/mcp/project.js +90 -0
  211. package/plugins-dist/memory/index.js +94 -0
  212. package/{dist → plugins-dist/memory}/memory.js +21 -3
  213. package/plugins-dist/memory/notes.js +36 -0
  214. package/plugins-dist/memory/plugin.json +11 -0
  215. package/plugins-dist/memory/style.js +14 -0
  216. package/plugins-dist/mentions/attach.js +120 -0
  217. package/plugins-dist/mentions/index.js +69 -0
  218. package/plugins-dist/mentions/plugin.json +9 -0
  219. package/plugins-dist/mentions/style.js +14 -0
  220. package/plugins-dist/models/config.js +53 -0
  221. package/plugins-dist/models/configure.js +415 -0
  222. package/plugins-dist/models/context.js +27 -0
  223. package/plugins-dist/models/index.js +167 -0
  224. package/plugins-dist/models/plugin.json +14 -0
  225. package/{dist → plugins-dist/models}/provider.js +22 -19
  226. package/plugins-dist/models/saved.js +80 -0
  227. package/plugins-dist/modes/index.js +190 -0
  228. package/plugins-dist/modes/plugin.json +18 -0
  229. package/plugins-dist/plugins/index.js +37 -0
  230. package/plugins-dist/plugins/plugin.json +10 -0
  231. package/plugins-dist/print/index.js +153 -0
  232. package/plugins-dist/print/plugin.json +14 -0
  233. package/plugins-dist/prompts/index.js +57 -0
  234. package/plugins-dist/prompts/plugin.json +13 -0
  235. package/plugins-dist/prompts/prompts.js +227 -0
  236. package/plugins-dist/prompts/sys.js +46 -0
  237. package/plugins-dist/renderers/index.js +36 -0
  238. package/plugins-dist/renderers/plugin.json +9 -0
  239. package/plugins-dist/repeats/index.js +165 -0
  240. package/plugins-dist/repeats/plugin.json +6 -0
  241. package/plugins-dist/schedule/cron.js +67 -0
  242. package/plugins-dist/schedule/index.js +281 -0
  243. package/plugins-dist/schedule/plugin.json +16 -0
  244. package/plugins-dist/schedule/store.js +125 -0
  245. package/plugins-dist/scratch/index.js +26 -0
  246. package/plugins-dist/scratch/plugin.json +10 -0
  247. package/plugins-dist/screenshot/index.js +35 -0
  248. package/plugins-dist/screenshot/plugin.json +11 -0
  249. package/plugins-dist/screenshot/sys.js +76 -0
  250. package/{dist/tools/screenshot.js → plugins-dist/screenshot/tool.js} +5 -4
  251. package/plugins-dist/sessions/index.js +136 -0
  252. package/plugins-dist/sessions/plugin.json +12 -0
  253. package/plugins-dist/shell/index.js +33 -0
  254. package/plugins-dist/shell/plugin.json +19 -0
  255. package/plugins-dist/shell/renderers.js +40 -0
  256. package/plugins-dist/shell/service.js +29 -0
  257. package/{dist/tools → plugins-dist/shell}/shell.js +36 -23
  258. package/{dist → plugins-dist/shell}/sys.js +20 -44
  259. package/plugins-dist/skills/index.js +90 -0
  260. package/plugins-dist/skills/plugin.json +12 -0
  261. package/plugins-dist/skills/project.js +47 -0
  262. package/{dist → plugins-dist/skills}/skills.js +3 -7
  263. package/plugins-dist/suggest/index.js +282 -0
  264. package/plugins-dist/suggest/plugin.json +23 -0
  265. package/plugins-dist/task/index.js +151 -0
  266. package/plugins-dist/task/plugin.json +23 -0
  267. package/plugins-dist/task/style.js +14 -0
  268. package/plugins-dist/task/subagent.js +208 -0
  269. package/{dist/tools/todo.js → plugins-dist/todo/index.js} +29 -7
  270. package/plugins-dist/todo/plugin.json +9 -0
  271. package/{dist/ui → plugins-dist/tui}/editor.js +53 -2
  272. package/plugins-dist/tui/frontend.js +586 -0
  273. package/{dist → plugins-dist/tui}/history.js +0 -1
  274. package/plugins-dist/tui/index.js +21 -0
  275. package/{dist/ui → plugins-dist/tui}/markdown.js +57 -20
  276. package/plugins-dist/tui/mentions.js +115 -0
  277. package/plugins-dist/tui/plugin.json +25 -0
  278. package/plugins-dist/tui/render.js +61 -0
  279. package/plugins-dist/tui/screen.js +201 -0
  280. package/{dist/ui → plugins-dist/tui}/transcript.js +179 -111
  281. package/{dist/ui → plugins-dist/tui}/tui.js +484 -101
  282. package/{dist/tools → plugins-dist/undo}/checkpoint.js +21 -55
  283. package/plugins-dist/undo/index.js +140 -0
  284. package/plugins-dist/undo/notes.js +36 -0
  285. package/plugins-dist/undo/plugin.json +9 -0
  286. package/plugins-dist/undo/style.js +14 -0
  287. package/plugins-dist/update/index.js +34 -0
  288. package/plugins-dist/update/plugin.json +15 -0
  289. package/plugins-dist/web/env.js +80 -0
  290. package/plugins-dist/web/index.js +124 -0
  291. package/plugins-dist/web/plugin.json +21 -0
  292. package/plugins-dist/web/renderers.js +7 -0
  293. package/plugins-dist/web/web.js +660 -0
  294. package/sdk/python/__pycache__/jade_plugin.cpython-312.pyc +0 -0
  295. package/sdk/python/jade_plugin.py +380 -0
  296. package/src/api.ts +298 -0
  297. package/src/config.ts +32 -134
  298. package/src/fetch.ts +216 -0
  299. package/src/hash.ts +39 -0
  300. package/src/host.ts +429 -0
  301. package/src/index.ts +23 -28
  302. package/src/install.ts +355 -0
  303. package/src/main.ts +152 -1263
  304. package/src/manifest.ts +160 -0
  305. package/src/membrane.ts +142 -0
  306. package/src/remote.ts +288 -0
  307. package/src/rescue.ts +217 -0
  308. package/src/resolve.ts +199 -0
  309. package/src/rpc.ts +144 -0
  310. package/src/secrets.ts +122 -0
  311. package/src/session.ts +458 -0
  312. package/src/source.ts +83 -0
  313. package/src/state.ts +120 -0
  314. package/src/update.ts +265 -0
  315. package/LICENSE +0 -21
  316. package/README.md +0 -198
  317. package/dist/commands.d.ts +0 -30
  318. package/dist/commands.js +0 -106
  319. package/dist/commands.js.map +0 -1
  320. package/dist/context.d.ts +0 -17
  321. package/dist/context.js +0 -53
  322. package/dist/context.js.map +0 -1
  323. package/dist/distro.d.ts +0 -104
  324. package/dist/distro.js +0 -312
  325. package/dist/distro.js.map +0 -1
  326. package/dist/history.d.ts +0 -10
  327. package/dist/history.js.map +0 -1
  328. package/dist/mcp.d.ts +0 -114
  329. package/dist/mcp.js.map +0 -1
  330. package/dist/memory.d.ts +0 -19
  331. package/dist/memory.js.map +0 -1
  332. package/dist/mentions.d.ts +0 -35
  333. package/dist/mentions.js +0 -130
  334. package/dist/mentions.js.map +0 -1
  335. package/dist/plugin-cli.d.ts +0 -16
  336. package/dist/plugin-cli.js +0 -251
  337. package/dist/plugin-cli.js.map +0 -1
  338. package/dist/plugins/budget.d.ts +0 -9
  339. package/dist/plugins/budget.js +0 -30
  340. package/dist/plugins/budget.js.map +0 -1
  341. package/dist/plugins/builtins.d.ts +0 -10
  342. package/dist/plugins/builtins.js +0 -22
  343. package/dist/plugins/builtins.js.map +0 -1
  344. package/dist/plugins/checks.d.ts +0 -70
  345. package/dist/plugins/checks.js.map +0 -1
  346. package/dist/plugins/compact.d.ts +0 -26
  347. package/dist/plugins/compact.js.map +0 -1
  348. package/dist/plugins/core.d.ts +0 -42
  349. package/dist/plugins/core.js +0 -190
  350. package/dist/plugins/core.js.map +0 -1
  351. package/dist/plugins/install.d.ts +0 -68
  352. package/dist/plugins/install.js +0 -377
  353. package/dist/plugins/install.js.map +0 -1
  354. package/dist/plugins/loader.d.ts +0 -182
  355. package/dist/plugins/loader.js +0 -253
  356. package/dist/plugins/loader.js.map +0 -1
  357. package/dist/plugins/policy.d.ts +0 -96
  358. package/dist/plugins/policy.js.map +0 -1
  359. package/dist/plugins/prompts.d.ts +0 -38
  360. package/dist/plugins/prompts.js +0 -196
  361. package/dist/plugins/prompts.js.map +0 -1
  362. package/dist/plugins/repeats.d.ts +0 -9
  363. package/dist/plugins/repeats.js +0 -90
  364. package/dist/plugins/repeats.js.map +0 -1
  365. package/dist/plugins/review.d.ts +0 -16
  366. package/dist/plugins/review.js +0 -92
  367. package/dist/plugins/review.js.map +0 -1
  368. package/dist/plugins/schema.d.ts +0 -2
  369. package/dist/plugins/schema.js.map +0 -1
  370. package/dist/provider.d.ts +0 -111
  371. package/dist/provider.js.map +0 -1
  372. package/dist/sessions.d.ts +0 -22
  373. package/dist/sessions.js +0 -53
  374. package/dist/sessions.js.map +0 -1
  375. package/dist/skills.d.ts +0 -37
  376. package/dist/skills.js.map +0 -1
  377. package/dist/sys.d.ts +0 -48
  378. package/dist/sys.js.map +0 -1
  379. package/dist/tools/checkpoint.d.ts +0 -43
  380. package/dist/tools/checkpoint.js.map +0 -1
  381. package/dist/tools/fs.d.ts +0 -35
  382. package/dist/tools/fs.js.map +0 -1
  383. package/dist/tools/grep.d.ts +0 -6
  384. package/dist/tools/grep.js.map +0 -1
  385. package/dist/tools/screenshot.d.ts +0 -15
  386. package/dist/tools/screenshot.js.map +0 -1
  387. package/dist/tools/shell.d.ts +0 -55
  388. package/dist/tools/shell.js.map +0 -1
  389. package/dist/tools/task.d.ts +0 -35
  390. package/dist/tools/task.js +0 -89
  391. package/dist/tools/task.js.map +0 -1
  392. package/dist/tools/todo.d.ts +0 -10
  393. package/dist/tools/todo.js.map +0 -1
  394. package/dist/tools/web.d.ts +0 -23
  395. package/dist/tools/web.js +0 -426
  396. package/dist/tools/web.js.map +0 -1
  397. package/dist/ui/configure.d.ts +0 -20
  398. package/dist/ui/configure.js +0 -378
  399. package/dist/ui/configure.js.map +0 -1
  400. package/dist/ui/diff.d.ts +0 -20
  401. package/dist/ui/diff.js.map +0 -1
  402. package/dist/ui/editor.d.ts +0 -33
  403. package/dist/ui/editor.js.map +0 -1
  404. package/dist/ui/markdown.d.ts +0 -17
  405. package/dist/ui/markdown.js.map +0 -1
  406. package/dist/ui/render.d.ts +0 -15
  407. package/dist/ui/render.js +0 -94
  408. package/dist/ui/render.js.map +0 -1
  409. package/dist/ui/screen.d.ts +0 -98
  410. package/dist/ui/screen.js +0 -108
  411. package/dist/ui/screen.js.map +0 -1
  412. package/dist/ui/transcript.d.ts +0 -33
  413. package/dist/ui/transcript.js.map +0 -1
  414. package/dist/ui/tui.d.ts +0 -45
  415. package/dist/ui/tui.js.map +0 -1
  416. package/src/commands.ts +0 -120
  417. package/src/context.ts +0 -64
  418. package/src/distro.ts +0 -400
  419. package/src/mentions.ts +0 -135
  420. package/src/plugin-cli.ts +0 -239
  421. package/src/plugins/budget.ts +0 -37
  422. package/src/plugins/builtins.ts +0 -31
  423. package/src/plugins/core.ts +0 -217
  424. package/src/plugins/install.ts +0 -429
  425. package/src/plugins/loader.ts +0 -386
  426. package/src/plugins/prompts.ts +0 -234
  427. package/src/plugins/repeats.ts +0 -96
  428. package/src/plugins/review.ts +0 -109
  429. package/src/sessions.ts +0 -61
  430. package/src/tools/task.ts +0 -109
  431. package/src/tools/web.ts +0 -451
  432. package/src/ui/configure.ts +0 -408
  433. package/src/ui/render.ts +0 -83
  434. package/src/ui/screen.ts +0 -169
  435. /package/{src/plugins → plugins/approval}/schema.ts +0 -0
  436. /package/{src → plugins/tui}/history.ts +0 -0
@@ -1,15 +1,16 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
1
  // 终端界面(Ink):全屏(备用屏幕缓冲区)分三块——顶部标题(版本、模型、目录),中间是对话,
3
2
  // 自己滚动(滚轮、PgUp/PgDn),底部固定显示运行状态、排队的消息、输入框(或对话框)和状态栏。
4
3
  // 运行中也能输入:提交的内容由宿主决定立即执行还是排队。
4
+ //
5
+ // 不用 JSX:插件以 .ts 源码加载,Node 的类型剥离不处理 .tsx,所以组件用 createElement(h)写。
5
6
  import { writeSync } from "node:fs";
6
7
  import { Box, render, Text, useBoxMetrics, useCursor, useInput, usePaste, useWindowSize, } from "ink";
7
- import { useEffect, useReducer, useRef, useState, useSyncExternalStore, } from "react";
8
+ import { createContext, createElement as h, useContext, useEffect, useReducer, useRef, useState, useSyncExternalStore, } from "react";
8
9
  import stringWidth from "string-width";
9
10
  import wrapAnsi from "wrap-ansi";
10
- import { mentionAt, mentionText, rankPaths } from "../mentions.js";
11
- import { edit, empty, layout } from "./editor.js";
12
- import { markdownStream } from "./markdown.js";
11
+ import { mentionAt, mentionText, rankPaths } from "./mentions.js";
12
+ import { charWidth, edit, empty, layout, moveRow, offsetAt } from "./editor.js";
13
+ import { expandTabs, markdownStream } from "./markdown.js";
13
14
  import { dim, } from "./screen.js";
14
15
  /**
15
16
  * 界面可用的尺寸:宽度比终端少一列。
@@ -20,10 +21,21 @@ function useScreenSize() {
20
21
  const { columns, rows } = useWindowSize();
21
22
  return { columns: Math.max(1, columns - 1), rows };
22
23
  }
24
+ /** 按键写成 "ctrl+g"、"alt+v"(小写);别的键返回 undefined */
25
+ function keySpec(input, key) {
26
+ if (input.length !== 1)
27
+ return undefined;
28
+ const c = input.toLowerCase();
29
+ if (key.ctrl && !key.meta && /^[a-z]$/.test(c))
30
+ return `ctrl+${c}`;
31
+ if (key.meta && !key.ctrl && /^[a-z0-9]$/.test(c))
32
+ return `alt+${c}`;
33
+ return undefined;
34
+ }
23
35
  /** 对话最多保留这么多行(折行前),超出时丢掉最早的一段 */
24
36
  const MAX_LINES = 10_000;
25
- /** 按显示宽度折行,保留颜色;每一项是屏幕上的一行 */
26
- const wrap = (text, width) => wrapAnsi(text, width, { hard: true, trim: false }).split("\n");
37
+ /** 按显示宽度折行,保留颜色;每一项是屏幕上的一行。制表符先换成空格:按 0 列算宽度会对不齐、超宽 */
38
+ const wrap = (text, width) => wrapAnsi(expandTabs(text), width, { hard: true, trim: false }).split("\n");
27
39
  /** Markdown 排好的一行折成屏幕上的行 */
28
40
  const mdRows = (l, width) => typeof l === "string" ? wrap(l, width) : l.render(width);
29
41
  /** 按宽度截成一行,截掉了内容时以 … 结尾;留出两列给 … 和展开标记 */
@@ -231,7 +243,14 @@ class Store {
231
243
  this.#wrapped = [];
232
244
  this.#owners = [];
233
245
  this.#named.clear();
234
- this.update({ version: this.state.version + 1, live: undefined, progress: [], scroll: 0 }, true);
246
+ this.update({ version: this.state.version + 1, live: undefined, progress: [], scroll: 0, hint: undefined }, true);
247
+ }
248
+ /** 展开或收起最后一个可折叠的项(Ctrl+O);start、view 同 toggle */
249
+ toggleLatest(start, view) {
250
+ for (let r = this.#owners.length - 1; r >= 0; r--) {
251
+ if (foldable(this.#owners[r], this.#width))
252
+ return this.toggle(r, start, view);
253
+ }
235
254
  }
236
255
  /** 往上(正数)或往下滚 n 行,不超过 max */
237
256
  scrollBy(n, max) {
@@ -240,18 +259,40 @@ class Store {
240
259
  this.update({ scroll }, true);
241
260
  }
242
261
  }
243
- /** 开关鼠标事件上报(SGR 格式),用来接收滚轮和点击;开着时终端里选中文字要按住 Shift */
244
- const MOUSE_ON = "\x1b[?1000h\x1b[?1006h";
245
- const MOUSE_OFF = "\x1b[?1006l\x1b[?1000l";
262
+ /**
263
+ * 开关鼠标事件上报(SGR 格式),用来接收滚轮、点击和按住左键拖动(1002)。
264
+ * 开着时终端自己不再处理点击,所以对话区的文字由 jade 自己选中和复制(见 Selection)
265
+ */
266
+ const MOUSE_ON = "\x1b[?1000h\x1b[?1002h\x1b[?1006h";
267
+ const MOUSE_OFF = "\x1b[?1006l\x1b[?1002l\x1b[?1000l";
246
268
  /**
247
269
  * 光标样式:闪烁的竖线(DECSCUSR 5,再加上 ATT610 的"开始闪烁"给只认它的终端),一眼能看出输入框有焦点;
248
270
  * 退出时还原成终端自己的默认样式。光标什么时候显示仍由 Ink 管(只有输入框或输入对话框有焦点时才显示)
249
271
  */
250
272
  const CURSOR_BLINK = "\x1b[5 q\x1b[?12h";
251
273
  const CURSOR_RESET = "\x1b[0 q";
274
+ /** 工作超过这么久后结束,或者这时弹出要用户选择的对话框,用户多半去做别的了:提醒一下 */
275
+ const NOTIFY_AFTER = 10_000;
276
+ /** 支持 OSC 9 桌面通知的终端;其他终端只响铃(不认识的 OSC 9 在有的终端里会弹别的东西) */
277
+ const OSC9_TERMINALS = new Set(["iTerm.app", "WezTerm", "ghostty"]);
278
+ /** 响铃,支持的终端再发一条桌面通知。JADE_NOTIFY=off 关闭 */
279
+ function notifier(stdout, env = process.env) {
280
+ if (env.JADE_NOTIFY === "off")
281
+ return () => { };
282
+ const osc9 = OSC9_TERMINALS.has(env.TERM_PROGRAM ?? "");
283
+ return (message) => stdout.write(osc9 ? `\x1b]9;jade: ${message.replace(/[\x00-\x1f\x7f]/g, " ")}\x07` : "\x07");
284
+ }
252
285
  export function tuiScreen(opts) {
253
286
  const stdout = opts.io?.stdout ?? process.stdout;
254
287
  const store = new Store(opts.status);
288
+ const draft = {};
289
+ const notify = notifier(stdout);
290
+ /** 已经工作了很久(见 NOTIFY_AFTER) */
291
+ const longBusy = () => {
292
+ const since = store.state.busy?.since;
293
+ return since !== undefined && Date.now() - since >= NOTIFY_AFTER;
294
+ };
295
+ let doneTimer;
255
296
  /**
256
297
  * 正在进行的思考:一开始就作为一项放进对话(可以点击展开),之后的增量攒起来,每隔一小段时间改写一次那一项。
257
298
  * 收起时只占一行,显示模型最新想到了哪里;结束时换成用了多久
@@ -293,27 +334,42 @@ export function tuiScreen(opts) {
293
334
  const rest = all ? "" : lines.pop();
294
335
  if (all && lines.at(-1) === "")
295
336
  lines.pop();
296
- appendMd(lines.flatMap((l) => md.push(l)));
337
+ appendMd(lines.flatMap((l) => md.push(expandTabs(l))));
297
338
  if (all) {
298
339
  appendMd(md.flush());
299
340
  md = markdownStream();
300
341
  }
301
342
  store.update({ live: rest || !all ? { text: rest, pending: md.pending() } : undefined });
302
343
  };
303
- const ask = (dialog) => new Promise((resolve) => {
344
+ /** signal 中止时关掉对话框,返回 undefined */
345
+ const ask = (dialog, signal) => new Promise((resolve) => {
346
+ if (signal?.aborted)
347
+ return resolve(undefined);
348
+ const close = () => d.resolve(undefined);
304
349
  const d = {
305
350
  ...dialog,
306
351
  resolve: (v) => {
352
+ signal?.removeEventListener("abort", close);
307
353
  store.update({ dialogs: store.state.dialogs.filter((x) => x !== d) }, true);
308
354
  resolve(v);
309
355
  },
310
356
  };
357
+ signal?.addEventListener("abort", close, { once: true });
311
358
  store.update({ dialogs: [...store.state.dialogs, d] }, true);
312
359
  });
313
360
  // 切到备用屏幕后光标还停在原来的位置(不少终端不会自动归位),Ink 从那里往下画第一帧会让屏幕滚动,
314
361
  // 之后每帧只重写变化的行,整个界面就错位了。所以先自己切过去、清屏、把光标移到左上角
315
362
  stdout.write("\x1b[?1049h\x1b[2J\x1b[H");
316
- const instance = render(_jsx(App, { store: store, version: opts.version, commands: opts.commands, handlers: opts.handlers, history: opts.history ?? [] }), {
363
+ const commands = opts.commands;
364
+ const instance = render(h(App, {
365
+ store,
366
+ copy: (text) => void stdout.write(osc52(text)),
367
+ version: opts.version,
368
+ commands: typeof commands === "function" ? commands : () => commands,
369
+ handlers: opts.handlers,
370
+ history: opts.history ?? [],
371
+ draft,
372
+ }), {
317
373
  exitOnCtrlC: false,
318
374
  alternateScreen: true,
319
375
  // 全屏每帧只重写变化的行
@@ -391,10 +447,16 @@ export function tuiScreen(opts) {
391
447
  },
392
448
  busy(label) {
393
449
  const current = store.state.busy;
394
- if (label === undefined)
450
+ if (label === undefined) {
451
+ // 稍等一下再提醒:排队的消息接着开始时(马上又 busy)不算结束
452
+ if (longBusy())
453
+ doneTimer ??= setTimeout(() => notify("done"), 300);
395
454
  store.update({ busy: undefined });
396
- else
397
- store.update({ busy: { label, since: current?.since ?? Date.now() } });
455
+ return;
456
+ }
457
+ clearTimeout(doneTimer);
458
+ doneTimer = undefined;
459
+ store.update({ busy: { label, since: current?.since ?? Date.now() } });
398
460
  },
399
461
  status(info) {
400
462
  store.update({ status: { ...store.state.status, ...info } });
@@ -402,19 +464,32 @@ export function tuiScreen(opts) {
402
464
  queued(items) {
403
465
  store.update({ queued: [...items] });
404
466
  },
405
- select: (title, choices, o) => ask({
406
- kind: "select",
407
- title,
408
- body: o?.body,
409
- choices: choices,
410
- resolve: () => { },
411
- }),
412
- input: (title, o) => ask({
467
+ draft: {
468
+ text: () => draft.current?.get() ?? "",
469
+ insert: (text) => draft.current?.apply((s) => edit.insert(s, text.replace(/\r\n?/g, "\n"))),
470
+ set: (text) => {
471
+ const value = text.replace(/\r\n?/g, "\n");
472
+ draft.current?.apply(() => ({ value, cursor: value.length }));
473
+ },
474
+ hint: (text) => store.update({ hint: text ? text.replace(/\r\n?/g, "\n") : undefined }),
475
+ },
476
+ select: (title, choices, o) => {
477
+ if (longBusy())
478
+ notify(title);
479
+ return ask({
480
+ kind: "select",
481
+ title,
482
+ body: o?.body,
483
+ choices: choices,
484
+ resolve: () => { },
485
+ }, o?.signal);
486
+ },
487
+ input: (title, { signal, ...o } = {}) => ask({
413
488
  kind: "input",
414
489
  title,
415
490
  ...o,
416
491
  resolve: () => { },
417
- }),
492
+ }, signal),
418
493
  clear() {
419
494
  clearTimeout(thinking?.timer);
420
495
  thinking = undefined;
@@ -422,6 +497,7 @@ export function tuiScreen(opts) {
422
497
  store.clear();
423
498
  },
424
499
  async close() {
500
+ clearTimeout(doneTimer);
425
501
  flushLive(true);
426
502
  store.update({ live: undefined, busy: undefined, progress: [] }, true);
427
503
  // 等最后一帧画完再卸载;卸载时 Ink 退出备用屏幕
@@ -438,8 +514,84 @@ export function tuiScreen(opts) {
438
514
  * SGR 鼠标事件(Ink 去掉了开头的 ESC):按钮号、列、行(从 1 开始),M 是按下、m 是松开。
439
515
  * 按钮号去掉 Shift/Alt/Ctrl 位后 0 是左键,64 是滚轮向上,65 向下
440
516
  */
441
- const MOUSE = /^\[<(\d+);\d+;(\d+)([Mm])$/;
517
+ const MOUSE = /^\[<(\d+);(\d+);(\d+)([Mm])$/;
518
+ /** 解析鼠标事件:button 是去掉 Shift/Alt/Ctrl 位的按钮号,press 表示按下;x、y 是屏幕上的列和行(从 0 开始) */
519
+ function mouseEvent(input) {
520
+ const m = MOUSE.exec(input);
521
+ if (!m)
522
+ return undefined;
523
+ return { button: Number(m[1]) & ~0b11100, press: m[4] === "M", x: Number(m[2]) - 1, y: Number(m[3]) - 1 };
524
+ }
442
525
  const WHEEL_LINES = 3;
526
+ /** 按住左键拖动时的按钮号(左键 0 加上移动位 32) */
527
+ const DRAG = 32;
528
+ /** "已复制"的提示显示多久 */
529
+ const COPIED_MS = 2000;
530
+ const same = (a, b) => a.row === b.row && a.col === b.col;
531
+ /** 第 row 行选中的列 [from, to);这一行不在选区里时 undefined */
532
+ function selectedCols(s, row) {
533
+ const { anchor: a, focus: f } = s;
534
+ const [first, last] = a.row < f.row || (a.row === f.row && a.col <= f.col) ? [a, f] : [f, a];
535
+ if (row < first.row || row > last.row)
536
+ return undefined;
537
+ return [row === first.row ? first.col : 0, row === last.row ? last.col + 1 : Infinity];
538
+ }
539
+ /** ANSI 转义序列(CSI,和以 BEL 或 ST 结束的 OSC,例如超链接) */
540
+ const ANSI = /\x1b\[[0-?]*[ -/]*[@-~]|\x1b\][^\x07\x1b]*(?:\x07|\x1b\\)/y;
541
+ const INVERSE = "\x1b[7m";
542
+ const INVERSE_OFF = "\x1b[27m";
543
+ /**
544
+ * 逐个走过一行里的字符:visit 收到每个字符和它是否落在列 [from, to) 里(宽字符跨进去一半也算)。
545
+ * 转义序列原样交给 escape
546
+ */
547
+ function walk(line, from, to, visit, escape) {
548
+ let col = 0;
549
+ for (let i = 0; i < line.length;) {
550
+ ANSI.lastIndex = i;
551
+ const m = ANSI.exec(line);
552
+ if (m) {
553
+ escape?.(m[0]);
554
+ i += m[0].length;
555
+ continue;
556
+ }
557
+ const ch = String.fromCodePoint(line.codePointAt(i));
558
+ const w = charWidth(ch);
559
+ visit(ch, col < to && col + Math.max(w, 1) > from);
560
+ col += w;
561
+ i += ch.length;
562
+ }
563
+ }
564
+ /** 给一行里选中的部分加上反色;中间的转义序列可能关掉反色,之后重新打开 */
565
+ function highlight(line, from, to) {
566
+ let out = "";
567
+ let on = false;
568
+ walk(line, from, to, (ch, inside) => {
569
+ if (inside !== on)
570
+ out += inside ? INVERSE : INVERSE_OFF;
571
+ on = inside;
572
+ out += ch;
573
+ }, (seq) => (out += seq + (on ? INVERSE : "")));
574
+ return out + (on ? INVERSE_OFF : "");
575
+ }
576
+ /** 选中的纯文字:每行去掉行尾空白,用换行连起来(自动折行的地方也是换行) */
577
+ function selectedText(s, row) {
578
+ const lines = [];
579
+ const { anchor: a, focus: f } = s;
580
+ for (let r = Math.min(a.row, f.row); r <= Math.max(a.row, f.row); r++) {
581
+ const [from, to] = selectedCols(s, r);
582
+ let text = "";
583
+ walk(row(r) ?? "", from, to, (ch, inside) => void (inside && (text += ch)));
584
+ lines.push(text.trimEnd());
585
+ }
586
+ return lines.join("\n");
587
+ }
588
+ /** OSC 52:让终端把文字放进系统剪贴板(Windows Terminal、iTerm2、kitty、WezTerm 等支持) */
589
+ const osc52 = (text) => `\x1b]52;c;${Buffer.from(text, "utf8").toString("base64")}\x07`;
590
+ /**
591
+ * 输入框和对话框用:有选中的文字时 Ctrl+C 只取消选中(很多人选完习惯按 Ctrl+C 复制),
592
+ * 不中断模型、不清空输入、不取消对话框
593
+ */
594
+ const SelectionContext = createContext({ active: () => false, clear: () => { } });
443
595
  /** 终端矮于这么多行时标题只占一行 */
444
596
  const COMPACT_ROWS = 24;
445
597
  /**
@@ -447,7 +599,7 @@ const COMPACT_ROWS = 24;
447
599
  * 超出的部分被裁掉,输入框的边框和状态栏就显示不全了
448
600
  */
449
601
  const roomFor = (rows, max) => Math.max(3, Math.min(max, Math.floor((rows - 10) / 2)));
450
- function App({ store, version, commands, handlers, history, }) {
602
+ function App({ store, copy, version, commands, handlers, history, draft, }) {
451
603
  const state = useSyncExternalStore(store.subscribe, store.get);
452
604
  const dialog = state.dialogs[0];
453
605
  // 运行中每 100ms 整体重画一次,推动转圈动画。不能让 Spinner 自己重画:
@@ -485,11 +637,41 @@ function App({ store, version, commands, handlers, history, }) {
485
637
  ...live.slice(Math.max(0, start - done.length), Math.max(0, end - done.length)),
486
638
  ];
487
639
  const page = Math.max(1, view - 2);
640
+ // 选中文字:按下左键记下位置,拖动时更新,松开时复制;点一下(没拖动)还是展开或收起那一项。
641
+ // 几个事件可能在同一块输入里连着到达,来不及重画,所以另外用 ref 记着最新的值
642
+ const [selection, setSelectionState] = useState();
643
+ const selected = useRef(undefined);
644
+ const pressed = useRef(undefined);
645
+ const setSelection = (s) => {
646
+ selected.current = s;
647
+ setSelectionState(s);
648
+ };
649
+ const [selectionApi] = useState(() => ({ active: () => selected.current !== undefined, clear: () => setSelection(undefined) }));
650
+ // 宽度变了,行重新折过,原来的位置对不上了
651
+ useEffect(() => setSelection(undefined), [width]);
652
+ const rowAt = (i) => (i < done.length ? done[i] : live[i - done.length]);
653
+ // 复制之后在输入框下面提示一会儿
654
+ const [copied, setCopied] = useState();
655
+ const copiedTimer = useRef(undefined);
656
+ useEffect(() => () => clearTimeout(copiedTimer.current), []);
657
+ const copySelection = (s) => {
658
+ const text = selectedText(s, rowAt);
659
+ copy(text);
660
+ clearTimeout(copiedTimer.current);
661
+ setCopied(`Copied ${[...text].length} characters to the clipboard`);
662
+ copiedTimer.current = setTimeout(() => setCopied(undefined), COPIED_MS);
663
+ };
488
664
  // Ink 增量渲染只用相对光标移动,第一帧起点一旦偏了(启动时终端尺寸还没稳定、窗口缩放、别的输出插进来),
489
- // 之后每帧都会画错行。启动后、尺寸变化后和按 Ctrl+L 时让一帧比终端高,Ink 会清屏从左上角整帧重画(包在同步输出里),下一帧再恢复
665
+ // 之后每帧都会画错行。尺寸变化后和按 Ctrl+L 时让一帧比终端高,Ink 会清屏从左上角整帧重画(包在同步输出里),下一帧再恢复。
666
+ // 启动时不重画:第一帧之前已经清屏、光标在左上角;这两次清屏在不支持同步输出的终端上(Windows 上常见)看得出闪一下
490
667
  const [redraws, setRedraws] = useState(0);
491
668
  const [repaint, setRepaint] = useState(false);
669
+ const mounted = useRef(false);
492
670
  useEffect(() => {
671
+ if (!mounted.current) {
672
+ mounted.current = true;
673
+ return;
674
+ }
493
675
  const t = setTimeout(() => setRepaint(true), 100);
494
676
  return () => clearTimeout(t);
495
677
  }, [columns, rows, redraws]);
@@ -503,21 +685,49 @@ function App({ store, version, commands, handlers, history, }) {
503
685
  useInput((input, key) => {
504
686
  if (key.ctrl && input === "l")
505
687
  return setRedraws((n) => n + 1);
506
- const mouse = MOUSE.exec(input);
688
+ // 展开或收起最近的一项(工具结果、思考、检查报告),鼠标点不了时也能看完整内容
689
+ if (key.ctrl && input === "o")
690
+ return store.toggleLatest(start, view);
691
+ const mouse = mouseEvent(input);
507
692
  if (mouse) {
508
- const button = Number(mouse[1]) & ~0b11100;
509
- if (button === 64)
693
+ // 对话区里的位置;clamp 时拖出对话区停在第一行或最后一行,否则在对话区外返回 undefined
694
+ const at = (clamp) => {
695
+ const i = mouse.y - top;
696
+ if (!clamp && (i < 0 || i >= shown.length))
697
+ return undefined;
698
+ return { row: start + Math.min(Math.max(i, 0), shown.length - 1), col: Math.max(0, mouse.x - 1) };
699
+ };
700
+ if (mouse.button === 64)
510
701
  store.scrollBy(WHEEL_LINES, max);
511
- else if (button === 65)
702
+ else if (mouse.button === 65)
512
703
  store.scrollBy(-WHEEL_LINES, max);
513
- else if (button === 0 && mouse[3] === "M") {
514
- // 点在对话区里已经完成的输出上:展开或收起那一项
515
- const i = Number(mouse[2]) - 1 - top;
516
- if (i >= 0 && i < shown.length && start + i < done.length)
517
- store.toggle(start + i, start, view);
704
+ else if (mouse.button === 0 && mouse.press) {
705
+ if (selected.current)
706
+ setSelection(undefined);
707
+ pressed.current = at(false);
708
+ }
709
+ else if (mouse.button === DRAG && pressed.current) {
710
+ setSelection({ anchor: pressed.current, focus: at(true) });
711
+ }
712
+ else if (mouse.button === 0 && !mouse.press && pressed.current) {
713
+ const p = pressed.current;
714
+ pressed.current = undefined;
715
+ const s = selected.current;
716
+ if (s && !same(s.anchor, s.focus))
717
+ copySelection(s);
718
+ else {
719
+ if (s)
720
+ setSelection(undefined);
721
+ // 点在对话区里已经完成的输出上:展开或收起那一项
722
+ if (p.row < done.length)
723
+ store.toggle(p.row, start, view);
724
+ }
518
725
  }
519
726
  return;
520
727
  }
728
+ // 按别的键取消选中;Ctrl+C 由输入框和对话框处理(见 SelectionContext)
729
+ if (selected.current && !(key.ctrl && input === "c"))
730
+ setSelection(undefined);
521
731
  // 选择框自己用 PgUp/PgDn 翻选项
522
732
  if (dialog?.kind === "select")
523
733
  return;
@@ -533,7 +743,44 @@ function App({ store, version, commands, handlers, history, }) {
533
743
  // 总高度要比终端少一行,否则 Ink 认为输出占满了屏幕,每帧清屏重画。
534
744
  // 重画那一帧上下各垫一行空白:终端把顶上那行滚出去后,看到的和平时逐行一样,所以不会闪。
535
745
  // 只做纵向裁剪:每行都已按宽度折好或截断,横向裁剪会让 Ink 每帧对每一行再切一遍 ANSI 字符串
536
- return (_jsx(Box, { flexDirection: "column", width: columns, height: repaint ? rows + 1 : Math.max(1, rows - 1), paddingY: repaint ? 1 : 0, overflowY: "hidden", children: _jsxs(Box, { flexDirection: "column", flexGrow: 1, overflowY: "hidden", children: [_jsx(Header, { status: state.status, version: version, compact: rows < COMPACT_ROWS }), _jsxs(Box, { ref: ref, flexDirection: "column", flexGrow: 1, flexShrink: 1, flexBasis: 0, overflowY: "hidden", paddingX: 1, children: [shown.map((l, i) => (_jsx(Text, { wrap: "truncate-end", children: l || " " }, i))), scrolled ? (_jsx(Text, { dimColor: true, wrap: "truncate-end", children: `── ↓ ${scroll} more lines · wheel / PgDn to scroll · ctrl+end to jump to the bottom ──` })) : null] }), _jsxs(Box, { flexDirection: "column", flexShrink: 0, children: [state.busy && !dialog ? (_jsx(Spinner, { label: state.busy.label, since: state.busy.since })) : null, state.queued.map((q, i) => (_jsxs(Text, { dimColor: true, wrap: "truncate-end", children: [" ↳ queued: ", q.replace(/\s+/g, " ")] }, i))), dialog ? (dialog.kind === "select" ? (_jsx(SelectDialog, { dialog: dialog }, dialogKey(dialog))) : (_jsx(InputDialog, { dialog: dialog }, dialogKey(dialog)))) : null, _jsx(Prompt, { commands: commands, handlers: handlers, history: history, busy: Boolean(state.busy), active: !dialog, onSubmit: () => store.scrollBy(-max, max) }), _jsx(StatusBar, { status: state.status, width: Math.max(10, columns - 2) })] })] }) }));
746
+ return h(SelectionContext.Provider, { value: selectionApi }, h(Box, {
747
+ flexDirection: "column",
748
+ width: columns,
749
+ height: repaint ? rows + 1 : Math.max(1, rows - 1),
750
+ paddingY: repaint ? 1 : 0,
751
+ overflowY: "hidden",
752
+ },
753
+ // 垫的空白放在外层:里面这层在重画那一帧和平时一样高,对话区的 top(相对父节点)不变,点击换算的行号不会差一行
754
+ h(Box, { flexDirection: "column", flexGrow: 1, overflowY: "hidden" }, h(Header, { status: state.status, version, compact: rows < COMPACT_ROWS }), h(Box, {
755
+ ref,
756
+ flexDirection: "column",
757
+ flexGrow: 1,
758
+ flexShrink: 1,
759
+ flexBasis: 0,
760
+ overflowY: "hidden",
761
+ paddingX: 1,
762
+ }, shown.map((l, i) => {
763
+ const cols = selection && selectedCols(selection, start + i);
764
+ return h(Text, { key: i, wrap: "truncate-end" }, cols ? highlight(l || " ", ...cols) : l || " ");
765
+ }), scrolled
766
+ ? h(Text, { dimColor: true, wrap: "truncate-end" }, `── ↓ ${scroll} more lines · wheel / PgDn to scroll · ctrl+end to jump to the bottom ──`)
767
+ : null), h(Box, { flexDirection: "column", flexShrink: 0 }, state.busy && !dialog ? h(Spinner, { label: state.busy.label, since: state.busy.since }) : null, state.queued.map((q, i) => h(Text, { key: i, dimColor: true, wrap: "truncate-end" }, " ↳ queued: ", q.replace(/\s+/g, " "))), dialog
768
+ ? dialog.kind === "select"
769
+ ? h(SelectDialog, { key: dialogKey(dialog), dialog })
770
+ : h(InputDialog, { key: dialogKey(dialog), dialog })
771
+ : null, h(Prompt, {
772
+ commands,
773
+ handlers,
774
+ history,
775
+ bridge: draft,
776
+ hint: state.hint,
777
+ onHintDone: () => store.update({ hint: undefined }),
778
+ busy: Boolean(state.busy),
779
+ queued: state.queued.length > 0,
780
+ active: !dialog,
781
+ onSubmit: () => store.scrollBy(-max, max),
782
+ flash: copied,
783
+ }), h(StatusBar, { status: state.status, width: Math.max(10, columns - 2) })))));
537
784
  }
538
785
  const JADE = "#00a86b";
539
786
  const SHINE = "#b6f2d4";
@@ -542,13 +789,21 @@ const SHINE = "#b6f2d4";
542
789
  * 每个字符上下两个像素;眼睛是玉上挖空的两格,左上角一点高光让它看起来像玉
543
790
  */
544
791
  function Bot() {
545
- return (_jsxs(Box, { flexDirection: "column", flexShrink: 0, marginRight: 2, children: [_jsxs(Text, { color: JADE, children: [" ▄", _jsx(Text, { color: SHINE, backgroundColor: JADE, children: "\u2584" }), "████▄"] }), _jsx(Text, { color: JADE, children: "\u2588\u2588 \u2588\u2588\u2588 \u2588\u2588" }), _jsx(Text, { color: JADE, children: "\u2580\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2580" })] }));
792
+ return h(Box, { flexDirection: "column", flexShrink: 0, marginRight: 2 }, h(Text, { color: JADE }, " ▄", h(Text, { color: SHINE, backgroundColor: JADE }, "▄"), "████▄"), h(Text, { color: JADE }, "██ ███ ██"), h(Text, { color: JADE }, "▀███████▀"));
546
793
  }
547
794
  function Header({ status, version, compact, }) {
548
795
  const { columns } = useScreenSize();
796
+ // 模型 · 目录 (分支)
797
+ const where = [
798
+ h(Text, { key: "model", color: "cyan" }, status.model),
799
+ h(Text, { key: "sep", dimColor: true }, " · "),
800
+ h(Text, { key: "cwd" }, status.cwd),
801
+ status.branch ? h(Text, { key: "branch", color: "magenta" }, ` (${status.branch})`) : null,
802
+ ];
803
+ const name = h(Text, { key: "name", color: "cyan", bold: true }, "jade");
549
804
  if (compact)
550
- return (_jsx(Box, { flexShrink: 0, paddingX: 1, children: _jsxs(Text, { wrap: "truncate-end", children: [_jsx(Text, { color: "cyan", bold: true, children: "jade" }), _jsx(Text, { dimColor: true, children: " \u00B7 " }), _jsx(Text, { color: "cyan", children: status.model }), _jsx(Text, { dimColor: true, children: " \u00B7 " }), _jsx(Text, { children: status.cwd }), status.branch ? (_jsxs(Text, { color: "magenta", children: [" (", status.branch, ")"] })) : null] }) }));
551
- return (_jsxs(Box, { flexShrink: 0, borderStyle: "round", borderColor: "cyan", paddingX: 1, children: [columns >= 50 ? _jsx(Bot, {}) : null, _jsxs(Box, { flexDirection: "column", flexGrow: 1, flexShrink: 1, children: [_jsxs(Text, { wrap: "truncate-end", children: [_jsx(Text, { color: "cyan", bold: true, children: "jade" }), _jsxs(Text, { dimColor: true, children: [" v", version] }), status.session ? (_jsx(Text, { dimColor: true, children: ` · session ${status.session}` })) : null] }), _jsxs(Text, { wrap: "truncate-end", children: [_jsx(Text, { color: "cyan", children: status.model }), _jsx(Text, { dimColor: true, children: " \u00B7 " }), _jsx(Text, { children: status.cwd }), status.branch ? (_jsxs(Text, { color: "magenta", children: [" (", status.branch, ")"] })) : null] }), _jsx(Text, { dimColor: true, wrap: "truncate-end", children: "/help for commands \u00B7 @ to attach files" })] })] }));
805
+ return h(Box, { flexShrink: 0, paddingX: 1 }, h(Text, { wrap: "truncate-end" }, name, h(Text, { key: "dot", dimColor: true }, " · "), ...where));
806
+ return h(Box, { flexShrink: 0, borderStyle: "round", borderColor: "cyan", paddingX: 1 }, columns >= 50 ? h(Bot) : null, h(Box, { flexDirection: "column", flexGrow: 1, flexShrink: 1 }, h(Text, { wrap: "truncate-end" }, name, h(Text, { dimColor: true }, ` v${version}`), status.session ? h(Text, { dimColor: true }, ` · session ${status.session}`) : null), h(Text, { wrap: "truncate-end" }, ...where), h(Text, { dimColor: true, wrap: "truncate-end" }, "/help for commands · @ to attach files")));
552
807
  }
553
808
  const dialogIds = new WeakMap();
554
809
  let dialogCounter = 0;
@@ -562,7 +817,7 @@ const FRAMES = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "
562
817
  function Spinner({ label, since }) {
563
818
  const now = Date.now();
564
819
  const seconds = Math.floor((now - since) / 1000);
565
- return (_jsx(Box, { marginTop: 1, children: _jsxs(Text, { wrap: "truncate-end", children: [_jsxs(Text, { color: "cyan", children: [FRAMES[Math.floor(now / 100) % FRAMES.length], " "] }), _jsxs(Text, { children: [label, "\u2026 "] }), _jsxs(Text, { dimColor: true, children: ["(", seconds, "s \u00B7 esc to interrupt)"] })] }) }));
820
+ return h(Box, { marginTop: 1 }, h(Text, { wrap: "truncate-end" }, h(Text, { color: "cyan" }, `${FRAMES[Math.floor(now / 100) % FRAMES.length]} `), h(Text, null, `${label}… `), h(Text, { dimColor: true }, `(${seconds}s · esc to interrupt)`)));
566
821
  }
567
822
  /** 在 width 列里放下尽量多的内容(保持原来的顺序) */
568
823
  export function fitSegments(segments, width) {
@@ -639,21 +894,23 @@ function StatusBar({ status, width }) {
639
894
  },
640
895
  ]
641
896
  : []),
897
+ // 插件的段落:比提示晚、比缓存早去掉
898
+ ...(status.plugins ?? []).map((p) => ({ text: p.text, dropAt: 7.5, dim: true })),
642
899
  {
643
- text: "PgUp/PgDn scroll · click ▸ to expand · shift+drag to select",
644
- short: "click ▸ to expand",
900
+ text: "PgUp/PgDn scroll · click ▸ or ctrl+o to expand · drag to select and copy",
901
+ short: "ctrl+o to expand",
645
902
  shortAt: 10,
646
903
  dropAt: 9,
647
904
  dim: true,
648
905
  },
649
906
  ];
650
907
  const shown = fitSegments(segments, width);
651
- return (_jsx(Box, { paddingX: 1, children: _jsx(Text, { wrap: "truncate-end", children: shown.map((s, i) => (_jsxs(Text, { children: [i ? _jsx(Text, { dimColor: true, children: " \u00B7 " }) : null, _jsx(Text, { color: s.color, dimColor: s.dim, children: s.text })] }, i))) }) }));
908
+ return h(Box, { paddingX: 1 }, h(Text, { wrap: "truncate-end" }, shown.map((s, i) => h(Text, { key: i }, i ? h(Text, { dimColor: true }, " · ") : null, h(Text, { color: s.color, dimColor: s.dim }, s.text)))));
652
909
  }
653
910
  /** 一行提示:按宽度选第一个放得下的写法,都放不下时用最后一个并截断 */
654
911
  function Hint({ variants, width }) {
655
912
  const text = variants.find((v) => stringWidth(v) <= width) ?? variants.at(-1);
656
- return (_jsx(Text, { dimColor: true, wrap: "truncate-end", children: text }));
913
+ return h(Text, { dimColor: true, wrap: "truncate-end" }, text);
657
914
  }
658
915
  const tokens = (n) => n >= 1_000_000
659
916
  ? `${(n / 1_000_000).toFixed(n >= 10_000_000 ? 0 : 1)}M`
@@ -692,6 +949,10 @@ function editKey(s, input, key) {
692
949
  return edit.del(s);
693
950
  if (key.ctrl && input === "w")
694
951
  return edit.deleteWord(s);
952
+ if (key.meta && !key.ctrl && input === "f")
953
+ return edit.wordRight(s);
954
+ if (key.meta && !key.ctrl && input === "b")
955
+ return edit.wordLeft(s);
695
956
  if (key.ctrl && input === "u")
696
957
  return edit.killBefore(s);
697
958
  if (key.ctrl && input === "k")
@@ -716,7 +977,7 @@ function editKey(s, input, key) {
716
977
  return text ? edit.insert(s, text) : undefined;
717
978
  }
718
979
  /** 渲染可编辑文本并把终端光标放到输入位置(输入法的候选框跟着它) */
719
- function EditableText({ state, width, prefix, mask, placeholder, active, maxRows = Infinity, }) {
980
+ function EditableText({ state, width, prefix, mask, placeholder, active, maxRows = Infinity, place, }) {
720
981
  const ref = useRef(null);
721
982
  // 只用来在布局变化后重画一次、重新计算光标位置;它给的是相对父元素的坐标,光标要的是相对整个输出
722
983
  const metrics = useBoxMetrics(ref);
@@ -740,6 +1001,8 @@ function EditableText({ state, width, prefix, mask, placeholder, active, maxRows
740
1001
  ? origin(ref.current)
741
1002
  : undefined;
742
1003
  const position = at && { x: at.x + prefix.length + col, y: at.y + row };
1004
+ if (place)
1005
+ place.current = at && { x: at.x + prefix.length, y: at.y, first, rows: rows.length };
743
1006
  const [, recheck] = useReducer((n) => n + 1, 0);
744
1007
  useEffect(() => {
745
1008
  if (!at || !ref.current)
@@ -748,11 +1011,9 @@ function EditableText({ state, width, prefix, mask, placeholder, active, maxRows
748
1011
  if (now.x !== at.x || now.y !== at.y)
749
1012
  recheck();
750
1013
  });
751
- return (_jsxs(Box, { ref: ref, flexDirection: "column", children: [active ? _jsx(CursorAt, { position: position }) : null, state.value === "" && placeholder ? (_jsxs(Text, { wrap: "truncate-end", children: [_jsx(Text, { color: "cyan", children: prefix }), _jsx(Text, { dimColor: true, children: placeholder })] })) : (rows.map((r, i) => (_jsxs(Text, { wrap: "truncate-end", children: [_jsx(Text, { color: "cyan", children: first + i === 0
752
- ? prefix
753
- : i === 0
754
- ? "↑".padEnd(prefix.length)
755
- : " ".repeat(prefix.length) }), r] }, first + i))))] }));
1014
+ return h(Box, { ref, flexDirection: "column" }, active ? h(CursorAt, { position }) : null, state.value === "" && placeholder
1015
+ ? h(Text, { wrap: "truncate-end" }, h(Text, { color: "cyan" }, prefix), h(Text, { dimColor: true }, placeholder))
1016
+ : rows.map((r, i) => h(Text, { key: first + i, wrap: "truncate-end" }, h(Text, { color: "cyan" }, first + i === 0 ? prefix : i === 0 ? "↑".padEnd(prefix.length) : " ".repeat(prefix.length)), r)));
756
1017
  }
757
1018
  /**
758
1019
  * 终端光标只有一个,每个 useCursor 每次提交都会设一遍。没有焦点的输入框(弹出输入框时下面的主输入框)
@@ -773,7 +1034,8 @@ function origin(node) {
773
1034
  }
774
1035
  return { x, y };
775
1036
  }
776
- function Prompt({ commands, handlers, history: initial, busy, active, onSubmit, }) {
1037
+ function Prompt({ commands, handlers, history: initial, bridge, hint, onHintDone, busy, queued, active, onSubmit, flash, }) {
1038
+ const selection = useContext(SelectionContext);
777
1039
  const [current, setState] = useLive(empty);
778
1040
  const [getSelected, setSelected] = useLive(0);
779
1041
  const [getNotice, setNotice] = useLive(undefined);
@@ -782,7 +1044,12 @@ function Prompt({ commands, handlers, history: initial, busy, active, onSubmit,
782
1044
  const browsing = useRef(-1);
783
1045
  const draft = useRef("");
784
1046
  const lastCtrlC = useRef(0);
1047
+ const lastEsc = useRef(0);
1048
+ /** 输入框文字在屏幕上的位置,点击时换算光标位置用(见 EditableText 的 place) */
1049
+ const place = useRef(undefined);
785
1050
  const { columns, rows } = useScreenSize();
1051
+ /** 输入框里文字的宽度:边框、内边距和前面的 "› " 之外 */
1052
+ const textWidth = Math.max(10, columns - 5) - 2;
786
1053
  /** 补全菜单、搜索结果最多显示几项;输入框最多几行 */
787
1054
  const menuRows = roomFor(rows, MENTION_ROWS);
788
1055
  const inputRows = roomFor(rows, 10);
@@ -793,7 +1060,7 @@ function Prompt({ commands, handlers, history: initial, busy, active, onSubmit,
793
1060
  // Ctrl+R 搜索历史:结果新的在前,index 是选中的那条
794
1061
  const [getSearch, setSearch] = useLive(undefined);
795
1062
  const usageOf = (c) => `/${c.name}${c.args ? ` ${c.args}` : ""}`;
796
- const column = Math.max(...commands.map((c) => usageOf(c).length)) + 2;
1063
+ const column = Math.max(...commands().map((c) => usageOf(c).length)) + 2;
797
1064
  /** 由最新的输入算出补全菜单和搜索结果;渲染和按键处理都用它 */
798
1065
  const derive = () => {
799
1066
  const state = current();
@@ -805,7 +1072,7 @@ function Prompt({ commands, handlers, history: initial, busy, active, onSubmit,
805
1072
  history.current[history.current.length - 1 - browsing.current];
806
1073
  const naming = !recalled && state.value.startsWith("/") && !/\s/.test(state.value);
807
1074
  const matches = naming
808
- ? commands.filter((c) => `/${c.name}`.startsWith(state.value))
1075
+ ? commands().filter((c) => `/${c.name}`.startsWith(state.value))
809
1076
  : [];
810
1077
  const pick = matches[Math.min(selected, matches.length - 1)];
811
1078
  // @ 引用:光标处正在输入的路径和补全候选
@@ -861,23 +1128,39 @@ function Prompt({ commands, handlers, history: initial, busy, active, onSubmit,
861
1128
  const first = around(hit, results.length, menuRows);
862
1129
  const firstMatch = around(Math.max(0, matches.indexOf(pick)), matches.length, menuRows);
863
1130
  const firstFound = around(Math.max(0, found.indexOf(file)), found.length, menuRows);
1131
+ /** 提示只在空闲、输入框为空、没有在搜索历史时显示,也只有这时能接受 */
1132
+ const hinting = () => hint !== undefined && !busy && current().value === "" && !getSearch();
864
1133
  const set = (s) => {
1134
+ // 用户开始打字(或者插件改了输入框):提示作废
1135
+ if (s.value && hint !== undefined)
1136
+ onHintDone();
865
1137
  setState(s);
866
1138
  setSelected(0);
867
1139
  setNotice(undefined);
1140
+ lastEsc.current = 0;
868
1141
  };
869
- const submit = (text) => {
870
- if (!text.trim())
871
- return;
1142
+ const remember = (text) => {
872
1143
  history.current = [
873
1144
  ...history.current.filter((h) => h !== text),
874
1145
  text,
875
1146
  ].slice(-100);
876
1147
  browsing.current = -1;
1148
+ };
1149
+ const submit = (text) => {
1150
+ if (!text.trim())
1151
+ return;
1152
+ remember(text);
877
1153
  set(empty);
878
1154
  onSubmit();
879
1155
  handlers.submit(text);
880
1156
  };
1157
+ /** 清空输入;清掉的内容放进(本次运行的)历史,按 ↑ 能找回来 */
1158
+ const discard = () => {
1159
+ const text = current().value;
1160
+ if (text.trim())
1161
+ remember(text);
1162
+ set(empty);
1163
+ };
881
1164
  /** 用选中的路径替换正在输入的 @ 引用;目录不加空格,接着补全里面的文件 */
882
1165
  const complete = (p) => {
883
1166
  const { state, mention } = derive();
@@ -889,6 +1172,7 @@ function Prompt({ commands, handlers, history: initial, busy, active, onSubmit,
889
1172
  cursor: mention.start + text.length,
890
1173
  });
891
1174
  };
1175
+ bridge.current = { get: () => current().value, apply: (f) => set(f(current())) };
892
1176
  const recall = (i) => {
893
1177
  browsing.current = i;
894
1178
  const value = i === -1
@@ -938,6 +1222,8 @@ function Prompt({ commands, handlers, history: initial, busy, active, onSubmit,
938
1222
  setSearch({ query: s.query + text, index: 0 });
939
1223
  };
940
1224
  useInput((input, key) => {
1225
+ if (key.ctrl && input === "c" && selection.active())
1226
+ return selection.clear();
941
1227
  const search = getSearch();
942
1228
  if (search)
943
1229
  return searchKey(search, input, key);
@@ -950,7 +1236,7 @@ function Prompt({ commands, handlers, history: initial, busy, active, onSubmit,
950
1236
  if (busy)
951
1237
  return handlers.interrupt();
952
1238
  if (state.value)
953
- return set(empty);
1239
+ return discard();
954
1240
  if (Date.now() - lastCtrlC.current < 2000)
955
1241
  return handlers.exit();
956
1242
  lastCtrlC.current = Date.now();
@@ -959,7 +1245,28 @@ function Prompt({ commands, handlers, history: initial, busy, active, onSubmit,
959
1245
  if (key.escape) {
960
1246
  if (busy)
961
1247
  return handlers.interrupt();
962
- return set(empty);
1248
+ if (!state.value)
1249
+ return;
1250
+ // 误按一下 Esc 不清掉写了半天的内容:连按两次才清空
1251
+ if (Date.now() - lastEsc.current < 1500)
1252
+ return discard();
1253
+ setNotice("Press Esc again to clear the input");
1254
+ lastEsc.current = Date.now();
1255
+ return;
1256
+ }
1257
+ // 点击输入框里的文字:光标移到点的位置
1258
+ const mouse = mouseEvent(input);
1259
+ if (mouse) {
1260
+ const at = place.current;
1261
+ if (!at || mouse.button !== 0 || !mouse.press)
1262
+ return;
1263
+ const row = mouse.y - at.y;
1264
+ if (row < 0 || row >= at.rows)
1265
+ return;
1266
+ const cursor = offsetAt(state.value, textWidth, at.first + row, mouse.x - at.x);
1267
+ if (cursor !== undefined)
1268
+ setState({ ...state, cursor });
1269
+ return;
963
1270
  }
964
1271
  // 文字和回车在同一块里到达(输入很快时终端可能合并):插入文字后发送
965
1272
  if (!key.ctrl &&
@@ -981,6 +1288,12 @@ function Prompt({ commands, handlers, history: initial, busy, active, onSubmit,
981
1288
  return complete(file);
982
1289
  return submit(state.value.trim());
983
1290
  }
1291
+ // Tab 或 →:把提示变成输入框里的文字,接着可以改
1292
+ if (((key.tab && !key.shift) || key.rightArrow) && hinting()) {
1293
+ onHintDone();
1294
+ browsing.current = -1;
1295
+ return set({ value: hint, cursor: hint.length });
1296
+ }
984
1297
  if (key.tab && key.shift)
985
1298
  return handlers.cycleMode?.();
986
1299
  if (key.tab) {
@@ -998,8 +1311,15 @@ function Prompt({ commands, handlers, history: initial, busy, active, onSubmit,
998
1311
  const { menu, selected } = derive();
999
1312
  if (menu)
1000
1313
  return setSelected((selected - 1 + menu) % menu);
1001
- if (!edit.onFirstLine(state))
1002
- return setState(edit.up(state));
1314
+ // 按折行后的屏幕行移动:一大段没有换行的文字也能上下走,到了第一行才翻历史
1315
+ const up = moveRow(state, textWidth, -1);
1316
+ if (up)
1317
+ return setState(up);
1318
+ // 先取回排队的消息,取完了再翻历史
1319
+ if (handlers.unqueue?.()) {
1320
+ browsing.current = -1;
1321
+ return;
1322
+ }
1003
1323
  if (browsing.current + 1 < history.current.length) {
1004
1324
  if (browsing.current === -1)
1005
1325
  draft.current = state.value;
@@ -1011,42 +1331,90 @@ function Prompt({ commands, handlers, history: initial, busy, active, onSubmit,
1011
1331
  const { menu, selected } = derive();
1012
1332
  if (menu)
1013
1333
  return setSelected((selected + 1) % menu);
1014
- if (!edit.onLastLine(state))
1015
- return setState(edit.down(state));
1334
+ const down = moveRow(state, textWidth, 1);
1335
+ if (down)
1336
+ return setState(down);
1016
1337
  if (browsing.current >= 0)
1017
1338
  recall(browsing.current - 1);
1018
1339
  return;
1019
1340
  }
1341
+ const spec = keySpec(input, key);
1342
+ if (spec && handlers.key?.(spec))
1343
+ return;
1020
1344
  const next = editKey(state, input, key);
1021
1345
  if (next)
1022
1346
  set(next);
1023
1347
  }, { isActive: active });
1024
1348
  // 对话框打开时隐藏但不卸载,输入到一半的内容和历史都保留
1025
- return (_jsxs(Box, { flexDirection: "column", marginTop: 1, display: active ? "flex" : "none", children: [_jsx(Box, { borderStyle: "round", borderColor: busy ? "gray" : "cyan", paddingX: 1, children: search ? (_jsx(EditableText, { state: { value: search.query, cursor: search.query.length }, width: Math.max(10, columns - 5), prefix: "search history\u203A ", placeholder: "type to filter", active: active, maxRows: inputRows })) : (_jsx(EditableText, { state: state, width: Math.max(10, columns - 5), prefix: "\u203A ", placeholder: busy
1349
+ return h(Box, { flexDirection: "column", marginTop: 1, display: active ? "flex" : "none" }, h(Box, { borderStyle: "round", borderColor: busy ? "gray" : "cyan", paddingX: 1 }, search
1350
+ ? h(EditableText, {
1351
+ state: { value: search.query, cursor: search.query.length },
1352
+ width: Math.max(10, columns - 5),
1353
+ prefix: "search history› ",
1354
+ placeholder: "type to filter",
1355
+ active,
1356
+ maxRows: inputRows,
1357
+ })
1358
+ : h(EditableText, {
1359
+ state,
1360
+ width: Math.max(10, columns - 5),
1361
+ prefix: "› ",
1362
+ placeholder: hinting()
1363
+ ? hintLine(hint)
1364
+ : queued
1365
+ ? "↑ to edit queued messages · esc to interrupt"
1366
+ : busy
1026
1367
  ? "Type to queue a message · esc to interrupt"
1027
1368
  : columns >= 70
1028
1369
  ? "Message jade · / commands · @ files · ↑ or ctrl+r for history"
1029
- : "Message jade · / commands · @ files", active: active, maxRows: inputRows })) }), search ? (_jsxs(Box, { flexDirection: "column", paddingX: 2, children: [results.length ? (results.slice(first, first + menuRows).map((h, i) => {
1030
- const on = first + i === hit;
1031
- return (_jsxs(Text, { wrap: "truncate-end", color: on ? "cyan" : undefined, bold: on, children: [on ? "❯ " : " ", h.replace(/\s*\n\s*/g, " ⏎ ")] }, first + i));
1032
- })) : (_jsx(Text, { dimColor: true, children: " no match" })), _jsx(Hint, { width: hintWidth, variants: [
1033
- " ↑↓ or ctrl+r select · enter/tab put in the input · esc cancel",
1034
- " ↑↓ select · enter use · esc cancel",
1035
- ] })] })) : matches.length ? (_jsxs(Box, { flexDirection: "column", paddingX: 2, children: [matches.slice(firstMatch, firstMatch + menuRows).map((c) => {
1036
- const on = c === pick;
1037
- return (_jsxs(Text, { wrap: "truncate-end", children: [_jsxs(Text, { color: on ? "cyan" : undefined, bold: on, children: [on ? "❯ " : " ", usageOf(c).padEnd(column)] }), _jsx(Text, { dimColor: true, children: c.about })] }, c.name));
1038
- }), _jsx(Hint, { width: hintWidth, variants: [
1039
- ` ↑↓ select · enter run · tab complete${matches.length > menuRows ? ` · ${matches.length} commands` : ""}`,
1040
- " ↑↓ · enter run · tab complete",
1041
- ] })] })) : found.length ? (_jsxs(Box, { flexDirection: "column", paddingX: 2, children: [found.slice(firstFound, firstFound + menuRows).map((p) => {
1042
- const on = p === file;
1043
- return (_jsxs(Text, { wrap: "truncate-middle", color: on ? "cyan" : p.endsWith("/") ? "blue" : undefined, bold: on, children: [on ? "❯ " : " ", p] }, p));
1044
- }), _jsx(Hint, { width: hintWidth, variants: [
1045
- " ↑↓ select · enter/tab insert the path · the file's content is sent with the message",
1046
- " ↑↓ select · enter/tab insert the path",
1047
- " ↑↓ · enter insert",
1048
- ] })] })) : notice ? (_jsxs(Text, { color: "yellow", children: [" ", notice] })) : null] }));
1370
+ : "Message jade · / commands · @ files",
1371
+ active,
1372
+ maxRows: inputRows,
1373
+ place,
1374
+ })), search
1375
+ ? h(Box, { flexDirection: "column", paddingX: 2 }, results.length
1376
+ ? results.slice(first, first + menuRows).map((item, i) => {
1377
+ const on = first + i === hit;
1378
+ return h(Text, { key: first + i, wrap: "truncate-end", color: on ? "cyan" : undefined, bold: on }, on ? "❯ " : " ", item.replace(/\s*\n\s*/g, " ⏎ "));
1379
+ })
1380
+ : h(Text, { dimColor: true }, " no match"), h(Hint, {
1381
+ width: hintWidth,
1382
+ variants: [" ↑↓ or ctrl+r select · enter/tab put in the input · esc cancel", " ↑↓ select · enter use · esc cancel"],
1383
+ }))
1384
+ : matches.length
1385
+ ? h(Box, { flexDirection: "column", paddingX: 2 }, matches.slice(firstMatch, firstMatch + menuRows).map((c) => {
1386
+ const on = c === pick;
1387
+ return h(Text, { key: c.name, wrap: "truncate-end" }, h(Text, { color: on ? "cyan" : undefined, bold: on }, on ? "❯ " : " ", usageOf(c).padEnd(column)), h(Text, { dimColor: true }, c.about));
1388
+ }), h(Hint, {
1389
+ width: hintWidth,
1390
+ variants: [
1391
+ ` ↑↓ select · enter run · tab complete${matches.length > menuRows ? ` · ${matches.length} commands` : ""}`,
1392
+ " ↑↓ · enter run · tab complete",
1393
+ ],
1394
+ }))
1395
+ : found.length
1396
+ ? h(Box, { flexDirection: "column", paddingX: 2 }, found.slice(firstFound, firstFound + menuRows).map((p) => {
1397
+ const on = p === file;
1398
+ return h(Text, { key: p, wrap: "truncate-middle", color: on ? "cyan" : p.endsWith("/") ? "blue" : undefined, bold: on }, on ? "❯ " : " ", p);
1399
+ }), h(Hint, {
1400
+ width: hintWidth,
1401
+ variants: [
1402
+ " ↑↓ select · enter/tab insert the path · the file's content is sent with the message",
1403
+ " ↑↓ select · enter/tab insert the path",
1404
+ " ↑↓ · enter insert",
1405
+ ],
1406
+ }))
1407
+ : notice
1408
+ ? h(Text, { color: "yellow" }, ` ${notice}`)
1409
+ : null,
1410
+ // 压在输入框上边框的右边,不占行,出现和消失时下面的内容不跳
1411
+ flash ? h(Box, { position: "absolute", top: 0, right: 2 }, h(Text, { color: "green" }, ` ${flash} `)) : null);
1049
1412
  }
1413
+ /** 提示在输入框里只显示第一行,后面还有时加 … */
1414
+ const hintLine = (hint) => {
1415
+ const [first, ...rest] = hint.split("\n");
1416
+ return `${first}${rest.length ? " …" : ""}`;
1417
+ };
1050
1418
  /** @ 补全最多显示几项 */
1051
1419
  const MENTION_ROWS = 8;
1052
1420
  /** 长列表只显示 size 项时,为了让第 selected 项在中间附近,从第几项开始显示 */
@@ -1058,6 +1426,7 @@ const VISIBLE = 10;
1058
1426
  /** 选项多于这么多时可以打字筛选(这时 j/k 和数字键不再是快捷键) */
1059
1427
  const FILTER_FROM = 10;
1060
1428
  function SelectDialog({ dialog, }) {
1429
+ const selection = useContext(SelectionContext);
1061
1430
  const [getSelected, setSelected] = useLive(0);
1062
1431
  const [getQuery, setQuery] = useLive("");
1063
1432
  const { rows, columns } = useScreenSize();
@@ -1075,16 +1444,16 @@ function SelectDialog({ dialog, }) {
1075
1444
  const selected = Math.min(getSelected(), Math.max(0, n - 1));
1076
1445
  // 终端矮时少显示几项,加上预览一起不超过终端的高度
1077
1446
  const visible = roomFor(rows, VISIBLE);
1078
- // 预览(例如要写入的文件)过长时截断:整个界面高过终端时 Ink 会每帧清屏重画
1079
- const lines = dialog.body?.split("\n") ?? [];
1447
+ // 预览(例如要写入的文件)过长时截断:整个界面高过终端时 Ink 会每帧清屏重画,底部的选项和提示也会被裁掉。
1448
+ // 按折行后的屏幕行数截断(一行长代码会占好几行),每一行单独显示、不再折行
1449
+ const lines = !dialog.body ? [] : wrap(dialog.body, Math.max(1, columns - 4));
1080
1450
  const room = Math.max(3, rows - Math.min(n, visible) - 16);
1081
1451
  const body = lines.length > room
1082
- ? [
1083
- ...lines.slice(0, room),
1084
- dim(`… ${lines.length - room} more lines`),
1085
- ].join("\n")
1086
- : dialog.body;
1452
+ ? [...lines.slice(0, room - 1), dim(`… ${lines.length - room + 1} more lines`)]
1453
+ : lines;
1087
1454
  useInput((input, key) => {
1455
+ if (key.ctrl && input === "c" && selection.active())
1456
+ return selection.clear();
1088
1457
  const items = filtered();
1089
1458
  const n = items.length;
1090
1459
  const selected = Math.min(getSelected(), Math.max(0, n - 1));
@@ -1127,14 +1496,20 @@ function SelectDialog({ dialog, }) {
1127
1496
  });
1128
1497
  // 选项多时只显示选中项附近的一段
1129
1498
  const start = around(selected, n, visible);
1130
- return (_jsxs(Box, { flexDirection: "column", borderStyle: "round", borderColor: "yellow", paddingX: 1, marginTop: 1, children: [_jsx(Text, { bold: true, wrap: "truncate-end", children: dialog.title }), body ? _jsx(Text, { children: body }) : null, filtering ? (_jsxs(Text, { wrap: "truncate-end", children: [_jsx(Text, { color: "cyan", children: "filter\u203A " }), query ? (_jsx(Text, { children: query })) : (_jsxs(Text, { dimColor: true, children: ["type to filter ", dialog.choices.length, " items"] }))] })) : null, _jsxs(Box, { flexDirection: "column", marginTop: filtering ? 0 : 1, children: [start > 0 ? _jsxs(Text, { dimColor: true, children: [" \u2191 ", start, " more"] }) : null, n === 0 ? _jsx(Text, { dimColor: true, children: " no match" }) : null, items.slice(start, start + visible).map(({ c, i }, j) => {
1131
- const on = start + j === selected;
1132
- return (_jsxs(Text, { wrap: "truncate-end", children: [_jsxs(Text, { color: on ? "cyan" : undefined, bold: on, children: [on ? "❯ " : " ", filtering ? "" : `${i + 1}. `, c.label] }), c.hint ? _jsxs(Text, { dimColor: true, children: [" ", c.hint] }) : null] }, i));
1133
- }), start + visible < n ? (_jsxs(Text, { dimColor: true, children: [" \u2193 ", n - start - visible, " more"] })) : null] }), _jsx(Hint, { width: Math.max(10, columns - 4), variants: filtering
1134
- ? ["↑↓ select · type to filter · enter confirm · esc clear/cancel", "↑↓ · enter · esc"]
1135
- : ["↑↓ select · enter confirm · esc cancel", "↑↓ · enter · esc"] })] }));
1499
+ return h(Box, { flexDirection: "column", borderStyle: "round", borderColor: "yellow", paddingX: 1, marginTop: 1 }, h(Text, { bold: true, wrap: "truncate-end" }, dialog.title), body.map((l, i) => h(Text, { key: i, wrap: "truncate-end" }, l || " ")), filtering
1500
+ ? h(Text, { wrap: "truncate-end" }, h(Text, { color: "cyan" }, "filter› "), query ? h(Text, null, query) : h(Text, { dimColor: true }, `type to filter ${dialog.choices.length} items`))
1501
+ : null, h(Box, { flexDirection: "column", marginTop: filtering ? 0 : 1 }, start > 0 ? h(Text, { dimColor: true }, ` ↑ ${start} more`) : null, n === 0 ? h(Text, { dimColor: true }, " no match") : null, items.slice(start, start + visible).map(({ c, i }, j) => {
1502
+ const on = start + j === selected;
1503
+ return h(Text, { key: i, wrap: "truncate-end" }, h(Text, { color: on ? "cyan" : undefined, bold: on }, on ? "❯ " : " ", filtering ? "" : `${i + 1}. `, c.label), c.hint ? h(Text, { dimColor: true }, ` ${c.hint}`) : null);
1504
+ }), start + visible < n ? h(Text, { dimColor: true }, ` ↓ ${n - start - visible} more`) : null), h(Hint, {
1505
+ width: Math.max(10, columns - 4),
1506
+ variants: filtering
1507
+ ? ["↑↓ select · type to filter · enter confirm · esc clear/cancel", "↑↓ · enter · esc"]
1508
+ : ["↑↓ select · enter confirm · esc cancel", "↑↓ · enter · esc"],
1509
+ }));
1136
1510
  }
1137
1511
  function InputDialog({ dialog, }) {
1512
+ const selection = useContext(SelectionContext);
1138
1513
  const initial = dialog.initial ?? "";
1139
1514
  const [current, setState] = useLive({
1140
1515
  value: initial,
@@ -1144,6 +1519,8 @@ function InputDialog({ dialog, }) {
1144
1519
  const { columns } = useScreenSize();
1145
1520
  usePaste((text) => setState(edit.insert(current(), text.replace(/\r?\n/g, ""))));
1146
1521
  useInput((input, key) => {
1522
+ if (key.ctrl && input === "c" && selection.active())
1523
+ return selection.clear();
1147
1524
  const state = current();
1148
1525
  if (key.return)
1149
1526
  return dialog.resolve(state.value.trim());
@@ -1153,6 +1530,12 @@ function InputDialog({ dialog, }) {
1153
1530
  if (next)
1154
1531
  setState(next);
1155
1532
  });
1156
- return (_jsxs(Box, { flexDirection: "column", borderStyle: "round", borderColor: "yellow", paddingX: 1, marginTop: 1, children: [_jsx(Text, { bold: true, children: dialog.title }), _jsx(EditableText, { state: state, width: Math.max(10, columns - 6), prefix: "\u203A ", mask: dialog.mask, placeholder: dialog.placeholder, active: true }), _jsx(Text, { dimColor: true, children: "enter confirm \u00B7 esc cancel" })] }));
1533
+ return h(Box, { flexDirection: "column", borderStyle: "round", borderColor: "yellow", paddingX: 1, marginTop: 1 }, h(Text, { bold: true }, dialog.title), h(EditableText, {
1534
+ state,
1535
+ width: Math.max(10, columns - 6),
1536
+ prefix: "› ",
1537
+ mask: dialog.mask,
1538
+ placeholder: dialog.placeholder,
1539
+ active: true,
1540
+ }), h(Text, { dimColor: true }, "enter confirm · esc cancel"));
1157
1541
  }
1158
- //# sourceMappingURL=tui.js.map