@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,408 +0,0 @@
1
- // /model:选服务、填地址和密钥、选模型、改输出上限、思考力度和上下文窗口。配置写进 $JADE_HOME/.env。
2
- // 配置过的服务和模型都记在 $JADE_HOME/models.json 里:同一个服务(类型、地址、密钥都相同)下的模型放在一起,
3
- // 每个模型带自己的设置。/model 可以直接切回去,换了服务或地址之前的也不会丢。
4
-
5
- import { hasProvider, parseTokens, readSavedServices, updateEnvFile, writeSavedServices, type SavedModel, type SavedService } from "../config.ts";
6
- import { EFFORTS, listModels, providerInfo, providerKind, rpmFromEnv, visionFromEnv, type ProviderKind } from "../provider.ts";
7
- import { shortPath } from "./render.ts";
8
- import { dim, green, red, type Screen } from "./screen.ts";
9
-
10
- export interface ConfigureOptions {
11
- screen: Screen;
12
- envFile: string;
13
- /** 保存过的服务和模型($JADE_HOME/models.json) */
14
- modelsFile: string;
15
- /** 按新的环境变量换上 provider、更新上下文窗口;配置不完整时抛出 */
16
- apply(): Promise<void>;
17
- /** 当前的上下文窗口(显示用) */
18
- contextWindow(): number;
19
- /** 配置成功后更新状态栏 */
20
- onApplied(): void;
21
- }
22
-
23
- export interface Configure {
24
- /** 选服务、填地址和密钥、选模型;返回是否配置成功 */
25
- provider(): Promise<boolean>;
26
- /** /model [name] */
27
- model(arg: string | undefined): Promise<void>;
28
- }
29
-
30
- const PROVIDERS: Array<{ kind: ProviderKind; label: string; hint: string }> = [
31
- { kind: "openai-compat", label: "OpenAI-compatible service", hint: "any /chat/completions endpoint" },
32
- { kind: "openai", label: "OpenAI", hint: "Responses API" },
33
- { kind: "anthropic", label: "Anthropic", hint: "Claude" },
34
- ];
35
-
36
- const MODEL_KEY: Record<ProviderKind, string> = { "openai-compat": "OPENAI_COMPAT_MODEL", openai: "OPENAI_MODEL", anthropic: "ANTHROPIC_MODEL" };
37
- const KEY_KEY: Record<ProviderKind, string> = { "openai-compat": "OPENAI_COMPAT_API_KEY", openai: "OPENAI_API_KEY", anthropic: "ANTHROPIC_API_KEY" };
38
- const URL_KEY: Record<ProviderKind, string> = { "openai-compat": "OPENAI_COMPAT_BASE_URL", openai: "OPENAI_BASE_URL", anthropic: "ANTHROPIC_BASE_URL" };
39
-
40
- /** 每个模型自己的设置:切换模型时一起换掉 */
41
- const MODEL_SETTINGS = ["JADE_MAX_TOKENS", "JADE_EFFORT", "JADE_CONTEXT_WINDOW", "JADE_RPM", "JADE_VISION"];
42
-
43
- /** JADE_VISION 设成了什么;没设或写错时 undefined */
44
- function visionSetting(): boolean | undefined {
45
- if (!process.env.JADE_VISION?.trim()) return undefined;
46
- try {
47
- return visionFromEnv({ JADE_VISION: process.env.JADE_VISION });
48
- } catch {
49
- return undefined;
50
- }
51
- }
52
-
53
- function visionHint(kind: ProviderKind): string {
54
- const v = visionSetting();
55
- return v === undefined ? `${kind === "openai-compat" ? "no" : "yes"} (default)` : v ? "yes" : "no";
56
- }
57
-
58
- /** 一个服务包含的变量 */
59
- const serviceKeys = (kind: ProviderKind) => [
60
- "JADE_PROVIDER",
61
- URL_KEY[kind],
62
- KEY_KEY[kind],
63
- ...(kind === "openai-compat" ? ["OPENAI_COMPAT_EXTRA_BODY"] : []),
64
- ];
65
-
66
- type Env = Record<string, string | undefined>;
67
-
68
- const pick = (env: Env, keys: string[]) => {
69
- const out: Record<string, string> = {};
70
- for (const k of keys) if (env[k] !== undefined) out[k] = env[k]!;
71
- return out;
72
- };
73
-
74
- /** 服务的类型、地址和密钥都相同的算同一个;配置无效时返回 undefined */
75
- function serviceId(env: Env): string | undefined {
76
- try {
77
- const i = providerInfo(env);
78
- return `${i.kind}|${i.baseURL ?? ""}|${env[KEY_KEY[i.kind]] ?? ""}`;
79
- } catch {
80
- return undefined;
81
- }
82
- }
83
-
84
- /** 选择列表里服务的说明:类型和地址的主机名 */
85
- function describeService(s: SavedService): string {
86
- const i = providerInfo(s.env);
87
- let host = i.baseURL ?? "";
88
- try {
89
- host = new URL(host).host;
90
- } catch {}
91
- return [i.kind, host].filter(Boolean).join(" · ");
92
- }
93
-
94
- /** 输入的 token 数:空表示不设;写错时报告并返回 false */
95
- function tokensInput(screen: Screen, name: string, text: string): boolean {
96
- if (!text) return true;
97
- try {
98
- parseTokens(name, text);
99
- return true;
100
- } catch (err) {
101
- screen.log(red(errorText(err)));
102
- return false;
103
- }
104
- }
105
-
106
- /** 选择列表里一组模型的说明:前几个名字 */
107
- function modelNames(models: SavedModel[]): string {
108
- const names = models.slice(0, 3).map((m) => m.name).join(", ");
109
- return models.length > 3 ? `${names} +${models.length - 3}` : names;
110
- }
111
-
112
- /** 主菜单里设置那一项的简要说明,例如 "64K out · 1M ctx · images" */
113
- function settingsSummary(kind: ProviderKind, contextWindow: number): string {
114
- const env = process.env;
115
- const images = visionSetting() ?? kind !== "openai-compat";
116
- return [
117
- env.JADE_MAX_TOKENS && `${env.JADE_MAX_TOKENS} out`,
118
- env.JADE_EFFORT && `${env.JADE_EFFORT} effort`,
119
- `${env.JADE_CONTEXT_WINDOW ?? contextWindow} ctx`,
120
- env.JADE_RPM && `${env.JADE_RPM}/min`,
121
- images ? "images" : "no images",
122
- ]
123
- .filter(Boolean)
124
- .join(" · ");
125
- }
126
-
127
- const errorText = (err: unknown) => (err instanceof Error ? err.message : String(err));
128
-
129
- export function configurator(opts: ConfigureOptions): Configure {
130
- const { screen, envFile, modelsFile } = opts;
131
-
132
- /** 保存过的、有效的服务,最近用过的在前 */
133
- const savedServices = async () => (await readSavedServices(modelsFile)).filter((s) => serviceId(s.env) !== undefined);
134
-
135
- /**
136
- * 把当前的服务和模型记下来,都放到最前面。
137
- * replacing:换了密钥的那个服务原来的 id,它下面的模型归到新的密钥下
138
- */
139
- async function remember(replacing?: string) {
140
- if (!hasProvider()) return;
141
- const id = serviceId(process.env);
142
- const model = providerInfo().model;
143
- if (!id || !model) return;
144
- const kind = providerKind();
145
- const services = await savedServices();
146
- const old = services.filter((s) => serviceId(s.env) === id || (replacing !== undefined && serviceId(s.env) === replacing));
147
- const models = old.flatMap((s) => s.models).filter((m, i, all) => m.name !== model && all.findIndex((x) => x.name === m.name) === i);
148
- const service: SavedService = {
149
- env: { ...pick(process.env, serviceKeys(kind)), JADE_PROVIDER: kind },
150
- models: [{ name: model, settings: pick(process.env, MODEL_SETTINGS) }, ...models],
151
- };
152
- await writeSavedServices(modelsFile, [service, ...services.filter((s) => !old.includes(s))]);
153
- }
154
-
155
- /** 保存配置并换上新的 provider;失败时报告原因,旧的 provider 继续用 */
156
- async function applyConfig(updates: Record<string, string | undefined>, replacing?: string): Promise<boolean> {
157
- await updateEnvFile(envFile, updates);
158
- try {
159
- await opts.apply();
160
- } catch (err) {
161
- screen.log(red(`Saved to ${shortPath(envFile)}, but the configuration is incomplete: ${errorText(err)}`));
162
- return false;
163
- }
164
- const info = providerInfo();
165
- opts.onApplied();
166
- await remember(replacing).catch((err) => screen.log(red(`Could not save the model list to ${shortPath(modelsFile)}: ${errorText(err)}`)));
167
- screen.log(green(`Model: ${info.model} (${info.kind}${info.baseURL ? `, ${info.baseURL}` : ""}). Saved to ${shortPath(envFile)}.`));
168
- return true;
169
- }
170
-
171
- /** 换成保存过的服务 s 上的模型 m:服务的变量和模型的设置写进 .env,模型没设的设置删掉 */
172
- function useSaved(s: SavedService, m: SavedModel): Promise<boolean> {
173
- const kind = providerKind(s.env);
174
- const updates: Record<string, string | undefined> = {};
175
- for (const k of serviceKeys(kind)) updates[k] = s.env[k];
176
- for (const k of MODEL_SETTINGS) updates[k] = m.settings[k];
177
- updates.JADE_PROVIDER = kind;
178
- updates[MODEL_KEY[kind]] = m.name;
179
- return applyConfig(updates);
180
- }
181
-
182
- /**
183
- * 在当前的服务上换成 model:用过的带上它自己的设置;新的模型沿用输出上限和思考力度,
184
- * 上下文窗口不沿用(不同模型差别很大),按模型名推断
185
- */
186
- async function switchModel(model: string): Promise<boolean> {
187
- const id = serviceId(process.env);
188
- const service = (await savedServices()).find((s) => serviceId(s.env) === id);
189
- const saved = service?.models.find((m) => m.name === model);
190
- if (service && saved) return useSaved(service, saved);
191
- return applyConfig({ [MODEL_KEY[providerKind()]]: model, JADE_CONTEXT_WINDOW: undefined });
192
- }
193
-
194
- /** 选模型:服务能列出模型时从列表里选,否则手动输入 */
195
- async function chooseModel(env: Env, current: string | undefined, saved: string[] = []): Promise<string | undefined> {
196
- const models = await listModels(env);
197
- if (models.length > 0) {
198
- const OTHER = "\0other";
199
- const picked = await screen.select(
200
- "Choose a model",
201
- [
202
- ...models.map((m) => ({ label: m, value: m, hint: m === current ? "current" : saved.includes(m) ? "saved" : undefined })),
203
- { label: "Enter a name…", value: OTHER },
204
- ],
205
- );
206
- if (picked !== OTHER) return picked;
207
- }
208
- return (await screen.input("Model name", { initial: current })) || undefined;
209
- }
210
-
211
- async function configureProvider(): Promise<boolean> {
212
- const current = hasProvider() ? providerInfo() : undefined;
213
- const currentId = hasProvider() ? serviceId(process.env) : undefined;
214
- const kind = await screen.select(
215
- "Which service should jade use?",
216
- PROVIDERS.map((p) => ({ label: p.label, value: p.kind, hint: p.kind === current?.kind ? `${p.hint} · current` : p.hint })),
217
- );
218
- if (!kind) return false;
219
- const same = kind === current?.kind;
220
-
221
- let baseURL: string | undefined = process.env[URL_KEY[kind]];
222
- if (kind !== "anthropic") {
223
- const fallback = kind === "openai" ? "https://api.openai.com/v1" : "";
224
- const answer = await screen.input("Base URL", { initial: baseURL ?? fallback, placeholder: "https://example.com/v1" });
225
- if (answer === undefined) return false;
226
- if (kind === "openai-compat" && !answer) {
227
- screen.log(red("A base URL is required."));
228
- return false;
229
- }
230
- baseURL = answer || undefined;
231
- }
232
-
233
- // 已知的密钥:当前服务的,或者保存过的同一个地址的服务的(最近用过的那个)
234
- const sameAddress = (env: Env) => {
235
- const i = providerInfo(env);
236
- return i.kind === kind && (i.baseURL ?? "") === (providerInfo({ JADE_PROVIDER: kind, [URL_KEY[kind]]: baseURL }).baseURL ?? "");
237
- };
238
- const services = await savedServices();
239
- const known = current && sameAddress(process.env) ? process.env[KEY_KEY[kind]] : services.find((s) => sameAddress(s.env))?.env[KEY_KEY[kind]];
240
- const answer = await screen.input("API key", {
241
- mask: true,
242
- placeholder: known ? "leave empty to keep the saved key" : kind === "openai-compat" ? "leave empty if the service needs none" : "",
243
- });
244
- if (answer === undefined) return false;
245
- const key = answer || known;
246
-
247
- const serviceEnv: Env = { JADE_PROVIDER: kind, [URL_KEY[kind]]: baseURL, [KEY_KEY[kind]]: key };
248
- if (kind === "openai-compat") {
249
- // 额外的请求参数跟着服务走:同一个服务保留,换了服务用保存过的那份
250
- const saved = services.find((s) => serviceId(s.env) === serviceId(serviceEnv));
251
- serviceEnv.OPENAI_COMPAT_EXTRA_BODY = saved ? saved.env.OPENAI_COMPAT_EXTRA_BODY : sameAddress(process.env) ? process.env.OPENAI_COMPAT_EXTRA_BODY : undefined;
252
- }
253
- const target = services.find((s) => serviceId(s.env) === serviceId(serviceEnv));
254
- const model = await chooseModel({ ...process.env, ...serviceEnv }, same ? current?.model : undefined, target?.models.map((m) => m.name));
255
- if (!model) return false;
256
-
257
- // 用过的模型带上它自己的设置
258
- const saved = target?.models.find((m) => m.name === model);
259
- if (target && saved) return useSaved({ ...target, env: { ...target.env, ...pick(serviceEnv, serviceKeys(kind)) } }, saved);
260
-
261
- const updates: Record<string, string | undefined> = { ...serviceEnv, [MODEL_KEY[kind]]: model, JADE_CONTEXT_WINDOW: undefined };
262
- // 思考力度的取值每种服务不同
263
- if (!same) updates.JADE_EFFORT = undefined;
264
- // 其他服务常常默认只给 4096 个输出 token,带思考的模型很容易用完
265
- if (kind !== "anthropic" && !process.env.JADE_MAX_TOKENS) {
266
- const max = await screen.input("Output limit per reply in tokens, e.g. 32000, 64K (empty for the service default)", { initial: "32K" });
267
- if (max === undefined || !tokensInput(screen, "Output limit", max)) return false;
268
- if (max) updates.JADE_MAX_TOKENS = max;
269
- }
270
- // 同一个地址只换了密钥:原来的服务下的模型归到新的密钥下
271
- const rekeyed = same && currentId !== undefined && sameAddress(process.env) && key !== process.env[KEY_KEY[kind]];
272
- return applyConfig(updates, rekeyed ? currentId : undefined);
273
- }
274
-
275
- async function configureModel(arg: string | undefined) {
276
- const info = providerInfo();
277
- // 之前只有 .env 时配置的模型也记下来,之后换了不会丢
278
- await remember().catch(() => {});
279
- const currentId = serviceId(process.env);
280
- const services = await savedServices();
281
- /** 保存过的、不是当前的模型,按服务分组:当前服务的在前 */
282
- const others = [...services.filter((s) => serviceId(s.env) === currentId), ...services.filter((s) => serviceId(s.env) !== currentId)].flatMap((s) =>
283
- s.models.filter((m) => !(serviceId(s.env) === currentId && m.name === info.model)).map((m) => ({ service: s, model: m })),
284
- );
285
- if (arg) {
286
- // 保存过的模型按名字切换(当前服务的优先),否则换当前服务的模型
287
- const saved = others.find((o) => o.model.name === arg);
288
- return void (await (saved ? useSaved(saved.service, saved.model) : switchModel(arg)));
289
- }
290
- // 主菜单只管切换:保存过的模型全部直接列出(当前的在最前,然后是同一服务的),选中就换;
291
- // 添加模型、当前模型的设置、删除各占一项,细节进子菜单再看。模型多于 10 个时可以打字筛选
292
- const here = describeService({ env: process.env as Record<string, string>, models: [] });
293
- const multi = services.length > 1;
294
- const action = await screen.select<string>("Switch model", [
295
- { label: info.model, value: "current", hint: multi ? `current · ${here}` : "current" },
296
- ...others.map((o, i) => ({ label: o.model.name, value: `saved:${i}`, hint: multi ? describeService(o.service) : undefined })),
297
- { label: "Add a model…", value: "add", hint: "from this service or another one" },
298
- { label: `Settings for ${info.model}…`, value: "settings", hint: settingsSummary(info.kind, opts.contextWindow()) },
299
- ...(others.length ? [{ label: "Remove a saved model…", value: "forget" }] : []),
300
- ]);
301
- if (action?.startsWith("saved:")) {
302
- const o = others[Number(action.slice(6))]!;
303
- await useSaved(o.service, o.model);
304
- } else if (action === "add") {
305
- const where = await screen.select<string>("Add a model from", [
306
- { label: "This service", value: "model", hint: here },
307
- { label: "Another service…", value: "provider", hint: "or change this one's base URL / API key" },
308
- ]);
309
- if (where === "model") {
310
- const saved = services.find((s) => serviceId(s.env) === currentId)?.models.map((m) => m.name);
311
- const model = await chooseModel(process.env, info.model, saved);
312
- if (model && model !== info.model) await switchModel(model);
313
- } else if (where === "provider") await configureProvider();
314
- } else if (action === "settings") await configureSettings();
315
- else if (action === "forget") {
316
- const owners = services.filter((s) => others.some((o) => o.service === s));
317
- const gone = await pickSaved(owners, "Remove a model from which service?", (s, m) => !(serviceId(s.env) === currentId && m.name === info.model));
318
- if (!gone) return;
319
- const id = serviceId(gone.service.env);
320
- // 服务下没有模型了就连服务(和它的密钥)一起删掉
321
- const rest = (await savedServices())
322
- .map((s) => (serviceId(s.env) === id ? { ...s, models: s.models.filter((m) => m.name !== gone.model.name) } : s))
323
- .filter((s) => s.models.length > 0);
324
- await writeSavedServices(modelsFile, rest);
325
- screen.log(dim(`Removed ${gone.model.name} (${describeService(gone.service)}).`));
326
- }
327
- }
328
-
329
- /** 当前模型自己的设置(切换模型时跟着换):输出上限、思考力度、上下文窗口、限速、能不能看图 */
330
- async function configureSettings() {
331
- const info = providerInfo();
332
- const efforts = EFFORTS[info.kind];
333
- const action = await screen.select<string>(`Settings for ${info.model}`, [
334
- { label: "Output limit per reply", value: "max", hint: process.env.JADE_MAX_TOKENS ? `${process.env.JADE_MAX_TOKENS} tokens` : "service default" },
335
- ...(efforts
336
- ? [{ label: "Reasoning effort", value: "effort", hint: process.env.JADE_EFFORT ?? (info.kind === "anthropic" ? "high (default)" : "service default") }]
337
- : []),
338
- { label: "Context window", value: "window", hint: `${opts.contextWindow()} tokens${process.env.JADE_CONTEXT_WINDOW ? "" : " (default)"}` },
339
- { label: "Requests per minute", value: "rpm", hint: process.env.JADE_RPM ? `${process.env.JADE_RPM}/min` : "no limit (slows down after being rate limited)" },
340
- { label: "Can see images", value: "vision", hint: visionHint(info.kind) },
341
- ]);
342
- if (action === "max") {
343
- const max = await screen.input("Output limit per reply in tokens, e.g. 32000, 64K (empty for the service default)", { initial: process.env.JADE_MAX_TOKENS ?? "32K" });
344
- if (max !== undefined && tokensInput(screen, "Output limit", max)) await applyConfig({ JADE_MAX_TOKENS: max || undefined });
345
- } else if (action === "effort" && efforts) {
346
- const DEFAULT = "\0default";
347
- const effort = await screen.select("Reasoning effort", [
348
- ...efforts.map((e) => ({ label: e, value: e, hint: e === process.env.JADE_EFFORT ? "current" : undefined })),
349
- { label: "Default", value: DEFAULT, hint: info.kind === "anthropic" ? "high" : "service default" },
350
- ]);
351
- if (effort !== undefined) await applyConfig({ JADE_EFFORT: effort === DEFAULT ? undefined : effort });
352
- } else if (action === "rpm") {
353
- const n = await screen.input("Requests per minute, e.g. 20 for most free models (empty for no limit)", { initial: process.env.JADE_RPM ?? "" });
354
- if (n === undefined) return;
355
- try {
356
- rpmFromEnv({ JADE_RPM: n });
357
- } catch (err) {
358
- return screen.log(red(errorText(err)));
359
- }
360
- await applyConfig({ JADE_RPM: n.trim() || undefined });
361
- } else if (action === "vision") {
362
- const DEFAULT = "\0default";
363
- const current = visionSetting();
364
- const choice = await screen.select("Can this model see images (screenshots, image files)?", [
365
- { label: "Yes", value: "on", hint: current === true ? "current" : "the screenshot tool becomes available" },
366
- { label: "No", value: "off", hint: current === false ? "current" : "images are replaced with a note" },
367
- { label: "Default", value: DEFAULT, hint: info.kind === "openai-compat" ? "no for compatible services" : "yes" },
368
- ]);
369
- if (choice === undefined) return;
370
- // 换了 provider 立即生效:图片发不发、截图工具给不给模型都在每次请求时按它判断,不用重启
371
- if (await applyConfig({ JADE_VISION: choice === DEFAULT ? undefined : choice })) {
372
- screen.log(dim(visionFromEnv() ? "Images and screenshots will be sent to the model." : "Images will be replaced with a note; the screenshot tool is hidden."));
373
- }
374
- } else if (action === "window") {
375
- const n = await screen.input("Context window in tokens, e.g. 128000, 512K, 1M (empty to infer it from the model name, or 128K if unknown)", {
376
- initial: process.env.JADE_CONTEXT_WINDOW ?? "",
377
- });
378
- if (n !== undefined && tokensInput(screen, "Context window", n)) await applyConfig({ JADE_CONTEXT_WINDOW: n || undefined });
379
- }
380
- }
381
-
382
- /**
383
- * 从几个服务里选一个保存过的模型:只有一个服务时直接列它的模型,否则先选服务。
384
- * keep 过滤可选的模型;取消时返回 undefined
385
- */
386
- async function pickSaved(
387
- from: SavedService[],
388
- title: string,
389
- keep: (s: SavedService, m: SavedModel) => boolean = () => true,
390
- ): Promise<{ service: SavedService; model: SavedModel } | undefined> {
391
- const groups = from.map((s) => ({ service: s, models: s.models.filter((m) => keep(s, m)) })).filter((g) => g.models.length > 0);
392
- const group =
393
- groups.length === 1
394
- ? groups[0]
395
- : await screen.select(
396
- title,
397
- groups.map((g) => ({ label: describeService(g.service), value: g, hint: modelNames(g.models) })),
398
- );
399
- if (!group) return undefined;
400
- const model = await screen.select(
401
- `Model (${describeService(group.service)})`,
402
- group.models.map((m) => ({ label: m.name, value: m })),
403
- );
404
- return model && { service: group.service, model };
405
- }
406
-
407
- return { provider: configureProvider, model: configureModel };
408
- }
package/src/ui/render.ts DELETED
@@ -1,83 +0,0 @@
1
- // 宿主显示用的纯函数:工具调用的一行摘要、审批时的预览、折叠的工具结果。不依赖运行时和界面状态。
2
-
3
- import { readFile } from "node:fs/promises";
4
- import os from "node:os";
5
- import path from "node:path";
6
- import type { PendingCall } from "uncarved";
7
- import { applyEditsToText, display, type Edit } from "../tools/fs.ts";
8
- import { renderDiff } from "./diff.ts";
9
- import { dim, green, red, yellow } from "./screen.ts";
10
-
11
- export const clip = (s: string, n: number) => (s.length > n ? s.slice(0, n) + "…" : s);
12
-
13
- /** 家目录下的路径显示成 ~/… */
14
- export function shortPath(p: string): string {
15
- const rel = path.relative(os.homedir(), p);
16
- const shown = rel && !rel.startsWith("..") && !path.isAbsolute(rel) ? `~/${rel}` : rel === "" ? "~" : p;
17
- return shown.split(path.sep).join("/");
18
- }
19
-
20
- /** 工具调用的一行摘要,显示在工具名后面的括号里 */
21
- export function summarize(cwd: string, name: string, input: unknown): string {
22
- const i = (input ?? {}) as Record<string, unknown>;
23
- if (name === "bash") return clip(String(i.command ?? "").split("\n")[0]!, 120);
24
- if (name === "task") return String(i.description ?? "");
25
- if (name === "bash_output" || name === "kill_shell") return String(i.id ?? "");
26
- if (name === "todo_write") return `${Array.isArray(i.todos) ? i.todos.length : 0} items`;
27
- if (name === "web_fetch") return clip(String(i.url ?? ""), 120);
28
- if (name === "web_search") return clip(String(i.query ?? ""), 120);
29
- if (name === "memory") return `${i.action} ${i.scope}: ${clip(String(i.text ?? ""), 120)}`;
30
- const where = typeof i.path === "string" ? display(cwd, i.path) : "";
31
- if (name === "multi_edit") return `${where}, ${Array.isArray(i.edits) ? i.edits.length : 0} edits`;
32
- if (name === "grep" || name === "glob") return `${i.pattern}${where && where !== "." ? ` in ${where}` : ""}`;
33
- return where || clip(JSON.stringify(input), 120);
34
- }
35
-
36
- /** summarize 省略了内容时(目前只有多行或很长的 bash 命令),调用行展开后先显示完整的参数 */
37
- export function callDetails(name: string, input: unknown): string | undefined {
38
- if (name !== "bash") return undefined;
39
- const command = String(((input ?? {}) as Record<string, unknown>).command ?? "");
40
- const lines = command.split("\n");
41
- if (lines.length === 1 && lines[0]!.length <= 120) return undefined;
42
- return detailsOf(lines.map((l, i) => `${i === 0 ? "$" : " "} ${l}`), dim, 200);
43
- }
44
-
45
- /**
46
- * 审批时显示的内容:修改显示成带行号和上下文的 diff(读出文件、按工具的规则算出修改后的内容),
47
- * 命令显示命令本身。文件读不了、替换不成立时退回到只显示参数里的新旧文本
48
- */
49
- export async function preview(c: PendingCall, cwd: string): Promise<string> {
50
- const i = (c.input ?? {}) as Record<string, unknown>;
51
- const lines = (s: string, mark: string, color: (s: string) => string, max = 30) => {
52
- const all = s.split("\n");
53
- const shown = all.slice(0, max).map((l) => color(`${mark} ${l}`));
54
- if (all.length > max) shown.push(dim(` … ${all.length - max} more lines`));
55
- return shown.join("\n");
56
- };
57
- const raw = (e: Record<string, unknown>) => `${lines(String(e.old_string ?? ""), "-", red)}\n${lines(String(e.new_string ?? ""), "+", green)}`;
58
- const file = typeof i.path === "string" ? path.resolve(cwd, i.path) : undefined;
59
- const current = file ? await readFile(file, "utf8").catch(() => undefined) : undefined;
60
- if (c.name === "edit_file" || (c.name === "multi_edit" && Array.isArray(i.edits))) {
61
- const edits = (c.name === "edit_file" ? [i] : i.edits) as unknown as Edit[];
62
- const fallback = () => edits.map((e) => raw(e as unknown as Record<string, unknown>)).join(dim("\n ⋯\n"));
63
- if (current === undefined) return fallback();
64
- const r = applyEditsToText(current, edits, display(cwd, file!));
65
- if (typeof r === "string") return `${fallback()}\n${yellow(` (this edit will fail: ${clip(r, 200)})`)}`;
66
- return renderDiff(current, r.text);
67
- }
68
- if (c.name === "write_file") {
69
- const content = String(i.content ?? "");
70
- if (current !== undefined) return `${dim(" overwrites the existing file:")}\n${renderDiff(current, content)}`;
71
- return lines(content, "+", green, 20);
72
- }
73
- if (c.name === "bash") return lines(String(i.command ?? ""), "$", (s) => s);
74
- if (c.name === "memory") return `${i.action === "remove" ? red("- ") : green("+ ")}${String(i.text ?? "")}`;
75
- return dim(clip(JSON.stringify(c.input, null, 2), 2000));
76
- }
77
-
78
- /** 工具结果展开后的内容:缩进的全部行,超过 max 行时截断 */
79
- export function detailsOf(lines: string[], color: (s: string) => string, max: number): string {
80
- const body = lines.slice(0, max).map((l) => color(` ${l}`));
81
- if (lines.length > max) body.push(dim(` … ${lines.length - max} more lines`));
82
- return body.join("\n");
83
- }
package/src/ui/screen.ts DELETED
@@ -1,169 +0,0 @@
1
- // 宿主的输出与交互接口。两种实现:
2
- // - 终端界面(tui.tsx):全屏,标题在顶部,对话在中间自己滚动,输入框、状态栏固定在底部,运行中也能输入
3
- // - 纯文本(这里):-p 和非交互运行时使用,逐行输出,提问用 readline
4
-
5
- import { createInterface, type Interface } from "node:readline/promises";
6
-
7
- export interface Choice<T> {
8
- label: string;
9
- value: T;
10
- /** 选项后面的灰色说明 */
11
- hint?: string;
12
- }
13
-
14
- export interface StatusInfo {
15
- cwd: string;
16
- branch?: string;
17
- model: string;
18
- mode: string;
19
- session?: string;
20
- /** 上一次请求的上下文用量,limit 是模型的上下文窗口 */
21
- context?: { used: number; limit: number; /** 超过这个 token 数会自动压缩 */ compactAt?: number };
22
- /** 本会话累计的用量(含子 Agent 和压缩) */
23
- spent?: { input: number; output: number };
24
- /** 上一次请求的输入中命中缓存的比例(0–1);服务不报告缓存用量时为 undefined */
25
- cache?: number;
26
- /** 输出速度(token/秒):live 为 true 时是正在输出的这次回复按字数估的,否则是上一次回复按服务端报的用量算的 */
27
- speed?: { tps: number; live?: boolean };
28
- }
29
-
30
- export interface CommandInfo {
31
- name: string;
32
- args?: string;
33
- about: string;
34
- }
35
-
36
- export interface Screen {
37
- /** 能向用户提问;为 false 时 select / input 直接返回 undefined */
38
- readonly interactive: boolean;
39
- /**
40
- * 追加已经完成的输出,可以带 ANSI 颜色。
41
- * details:折叠起来的完整内容,终端界面里点击 text 展开;纯文本输出不显示。
42
- * id:之后用 amend 给这一项补充内容(工具调用的结果);终端界面里这一项收起时只占一行
43
- */
44
- log(text: string, opts?: { details?: string; id?: string }): void;
45
- /**
46
- * 给之前用 id 记下的一项补充内容:终端界面里接在那一项后面合成一项(details 替换原来的),
47
- * 纯文本输出另起一行缩进显示。找不到那一项时也是另起一行
48
- */
49
- amend(id: string, text: string, opts?: { details?: string }): void;
50
- /**
51
- * 正在运行的工具 id 的一行进度(已经排好版);undefined 表示工具结束了。
52
- * 终端界面只在对话最后显示每个工具最新的一行,结束时去掉;纯文本输出逐行打印。
53
- * output 表示是工具自己的输出,纯文本输出里每个工具最多打印 20 行
54
- */
55
- progress(id: string, line: string | undefined, opts?: { output?: boolean }): void;
56
- /** 流式输出模型的正文或思考 */
57
- stream(kind: "text" | "thinking", text: string): void;
58
- /** 结束当前的流式块 */
59
- endStream(): void;
60
- /** 正在进行的活动;undefined 表示空闲 */
61
- busy(label: string | undefined): void;
62
- status(info: Partial<StatusInfo>): void;
63
- /** 排队等待发送的输入 */
64
- queued(items: string[]): void;
65
- /** 让用户从几项里选一项;取消时返回 undefined */
66
- select<T>(title: string, choices: Choice<T>[], opts?: { body?: string }): Promise<T | undefined>;
67
- /** 让用户输入一行;取消时返回 undefined */
68
- input(title: string, opts?: { initial?: string; mask?: boolean; placeholder?: string }): Promise<string | undefined>;
69
- /** 清空已经显示的对话(开始新会话时) */
70
- clear(): void;
71
- close(): Promise<void>;
72
- }
73
-
74
- // ---------- 颜色 ----------
75
-
76
- const colors = Boolean(process.stdout.isTTY);
77
- const paint = (code: string) => (s: string) => (colors ? `\x1b[${code}m${s}\x1b[0m` : s);
78
- export const dim = paint("2");
79
- export const red = paint("31");
80
- export const green = paint("32");
81
- export const yellow = paint("33");
82
- export const cyan = paint("36");
83
- export const bold = paint("1");
84
- export const italic = paint("3");
85
- export const underline = paint("4");
86
- export const strike = paint("9");
87
-
88
- // ---------- 纯文本实现 ----------
89
-
90
- const MAX_OUTPUT_LINES = 20;
91
-
92
- export function plainScreen(opts: { interactive: boolean }): Screen {
93
- let atLineStart = true;
94
- let streaming: "text" | "thinking" | undefined;
95
- let rl: Interface | undefined;
96
- /** 每个工具已经打印了多少行输出 */
97
- const outputLines = new Map<string, number>();
98
-
99
- const write = (s: string) => {
100
- if (!s) return;
101
- process.stdout.write(s);
102
- atLineStart = s.endsWith("\n");
103
- };
104
- const line = (s: string) => {
105
- if (!atLineStart) write("\n");
106
- write(s + "\n");
107
- };
108
- const ask = async (q: string) => {
109
- rl ??= createInterface({ input: process.stdin, output: process.stdout, terminal: true });
110
- return (await rl.question(q)).trim();
111
- };
112
-
113
- return {
114
- interactive: opts.interactive,
115
- log: (text) => {
116
- streaming = undefined;
117
- line(text);
118
- },
119
- amend: (_id, text) => {
120
- streaming = undefined;
121
- line(` ${text}`);
122
- },
123
- progress: (id, text, o) => {
124
- if (text === undefined) return void outputLines.delete(id);
125
- streaming = undefined;
126
- if (o?.output) {
127
- const shown = outputLines.get(id) ?? 0;
128
- if (shown > MAX_OUTPUT_LINES) return;
129
- outputLines.set(id, shown + 1);
130
- if (shown === MAX_OUTPUT_LINES) return line(dim(" │ …"));
131
- }
132
- line(text);
133
- },
134
- stream: (kind, text) => {
135
- if (kind !== streaming) {
136
- // 不少模型的正文以空行开头;整块都是换行时等下一块
137
- if (kind === "text") text = text.replace(/^\n+/, "");
138
- if (!text) return;
139
- if (kind === "thinking") line(dim("thinking…"));
140
- else if (!atLineStart) write("\n");
141
- streaming = kind;
142
- }
143
- write(kind === "thinking" ? dim(text) : text);
144
- },
145
- endStream: () => {
146
- streaming = undefined;
147
- if (!atLineStart) write("\n");
148
- },
149
- busy: () => {},
150
- status: () => {},
151
- queued: () => {},
152
- async select(title, choices, o) {
153
- if (!opts.interactive) return undefined;
154
- line(yellow(title));
155
- if (o?.body) line(o.body);
156
- choices.forEach((c, i) => line(` ${i + 1}. ${c.label}${c.hint ? dim(` ${c.hint}`) : ""}`));
157
- const n = Number(await ask(`Choose 1-${choices.length} (empty to cancel): `));
158
- return Number.isInteger(n) && n >= 1 && n <= choices.length ? choices[n - 1]!.value : undefined;
159
- },
160
- async input(title, o) {
161
- if (!opts.interactive) return undefined;
162
- return (await ask(`${title}${o?.initial ? ` [${o.initial}]` : ""}: `)) || o?.initial || "";
163
- },
164
- clear: () => {},
165
- async close() {
166
- rl?.close();
167
- },
168
- };
169
- }
File without changes
File without changes