@uncarved/jade 0.1.3 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (455) hide show
  1. package/README.md +161 -150
  2. package/bin/jade.js +14 -25
  3. package/dist/api.d.ts +266 -0
  4. package/dist/api.js +38 -0
  5. package/dist/api.js.map +1 -0
  6. package/dist/config.d.ts +13 -32
  7. package/dist/config.js +39 -121
  8. package/dist/config.js.map +1 -1
  9. package/dist/fetch.d.ts +20 -0
  10. package/dist/fetch.js +190 -0
  11. package/dist/fetch.js.map +1 -0
  12. package/dist/hash.d.ts +2 -0
  13. package/dist/hash.js +42 -0
  14. package/dist/hash.js.map +1 -0
  15. package/dist/host.d.ts +71 -0
  16. package/dist/host.js +400 -0
  17. package/dist/host.js.map +1 -0
  18. package/dist/index.d.ts +11 -30
  19. package/dist/index.js +11 -30
  20. package/dist/index.js.map +1 -1
  21. package/dist/install.d.ts +78 -0
  22. package/dist/install.js +292 -0
  23. package/dist/install.js.map +1 -0
  24. package/dist/main.d.ts +1 -2
  25. package/dist/main.js +160 -1362
  26. package/dist/main.js.map +1 -1
  27. package/dist/manifest.d.ts +23 -0
  28. package/dist/manifest.js +159 -0
  29. package/dist/manifest.js.map +1 -0
  30. package/dist/membrane.d.ts +33 -0
  31. package/dist/membrane.js +140 -0
  32. package/dist/membrane.js.map +1 -0
  33. package/dist/remote.d.ts +10 -0
  34. package/dist/remote.js +292 -0
  35. package/dist/remote.js.map +1 -0
  36. package/dist/rescue.d.ts +10 -0
  37. package/dist/rescue.js +216 -0
  38. package/dist/rescue.js.map +1 -0
  39. package/dist/resolve.d.ts +34 -0
  40. package/dist/resolve.js +178 -0
  41. package/dist/resolve.js.map +1 -0
  42. package/dist/rpc.d.ts +26 -0
  43. package/dist/rpc.js +144 -0
  44. package/dist/rpc.js.map +1 -0
  45. package/dist/secrets.d.ts +12 -0
  46. package/dist/secrets.js +125 -0
  47. package/dist/secrets.js.map +1 -0
  48. package/dist/session.d.ts +45 -0
  49. package/dist/session.js +401 -0
  50. package/dist/session.js.map +1 -0
  51. package/dist/source.d.ts +12 -0
  52. package/dist/source.js +72 -0
  53. package/dist/source.js.map +1 -0
  54. package/dist/state.d.ts +37 -0
  55. package/dist/state.js +93 -0
  56. package/dist/state.js.map +1 -0
  57. package/dist/update.d.ts +2 -0
  58. package/dist/update.js +6 -3
  59. package/dist/update.js.map +1 -1
  60. package/package.json +10 -8
  61. package/plugins/approval/index.ts +311 -0
  62. package/plugins/approval/plugin.json +22 -0
  63. package/{src/plugins → plugins/approval}/policy.ts +45 -104
  64. package/{src/plugins → plugins/approval}/review.ts +62 -16
  65. package/plugins/ask/index.ts +159 -0
  66. package/plugins/ask/plugin.json +8 -0
  67. package/plugins/budget/index.ts +38 -0
  68. package/plugins/budget/plugin.json +13 -0
  69. package/{src/plugins → plugins/checks}/checks.ts +48 -38
  70. package/plugins/checks/index.ts +158 -0
  71. package/plugins/checks/plugin.json +14 -0
  72. package/plugins/checks/project.ts +81 -0
  73. package/plugins/commands/index.ts +76 -0
  74. package/plugins/commands/plugin.json +7 -0
  75. package/{src/plugins → plugins/compact}/compact.ts +80 -39
  76. package/plugins/compact/index.ts +115 -0
  77. package/plugins/compact/plugin.json +17 -0
  78. package/plugins/compact/style.ts +17 -0
  79. package/plugins/continue/index.ts +58 -0
  80. package/plugins/continue/plugin.json +13 -0
  81. package/{src/ui → plugins/fs}/diff.ts +2 -2
  82. package/{src/tools → plugins/fs}/fs.ts +89 -46
  83. package/{src/tools → plugins/fs}/grep.ts +36 -8
  84. package/plugins/fs/index.ts +37 -0
  85. package/plugins/fs/plugin.json +7 -0
  86. package/{src/ui → plugins/fs}/renderers.ts +25 -70
  87. package/plugins/fs/style.ts +18 -0
  88. package/plugins/fs/sys.ts +81 -0
  89. package/plugins/keys/index.ts +53 -0
  90. package/plugins/keys/plugin.json +7 -0
  91. package/plugins/mcp/index.ts +192 -0
  92. package/{src → plugins/mcp}/mcp.ts +32 -32
  93. package/plugins/mcp/plugin.json +7 -0
  94. package/plugins/mcp/project.ts +93 -0
  95. package/plugins/memory/index.ts +105 -0
  96. package/{src → plugins/memory}/memory.ts +20 -2
  97. package/plugins/memory/notes.ts +43 -0
  98. package/plugins/memory/plugin.json +7 -0
  99. package/plugins/memory/style.ts +17 -0
  100. package/plugins/mentions/attach.ts +127 -0
  101. package/plugins/mentions/index.ts +99 -0
  102. package/plugins/mentions/plugin.json +7 -0
  103. package/plugins/mentions/style.ts +17 -0
  104. package/plugins/models/config.ts +53 -0
  105. package/plugins/models/configure.ts +455 -0
  106. package/plugins/models/context.ts +32 -0
  107. package/plugins/models/index.ts +213 -0
  108. package/plugins/models/plugin.json +8 -0
  109. package/{src → plugins/models}/provider.ts +16 -119
  110. package/plugins/models/saved.ts +94 -0
  111. package/plugins/modes/index.ts +222 -0
  112. package/plugins/modes/plugin.json +9 -0
  113. package/plugins/plugins/index.ts +38 -0
  114. package/plugins/plugins/plugin.json +7 -0
  115. package/plugins/print/index.ts +160 -0
  116. package/plugins/print/plugin.json +8 -0
  117. package/plugins/prompts/index.ts +111 -0
  118. package/plugins/prompts/plugin.json +8 -0
  119. package/plugins/prompts/prompts.ts +258 -0
  120. package/plugins/prompts/results.ts +63 -0
  121. package/plugins/prompts/sys.ts +84 -0
  122. package/plugins/renderers/index.ts +78 -0
  123. package/plugins/renderers/plugin.json +7 -0
  124. package/plugins/repeats/index.ts +165 -0
  125. package/plugins/repeats/plugin.json +6 -0
  126. package/plugins/schedule/cron.ts +74 -0
  127. package/plugins/schedule/index.ts +292 -0
  128. package/plugins/schedule/plugin.json +13 -0
  129. package/plugins/schedule/store.ts +149 -0
  130. package/plugins/scratch/index.ts +31 -0
  131. package/plugins/scratch/plugin.json +7 -0
  132. package/plugins/screenshot/index.ts +40 -0
  133. package/plugins/screenshot/plugin.json +7 -0
  134. package/plugins/screenshot/sys.ts +84 -0
  135. package/{src/tools/screenshot.ts → plugins/screenshot/tool.ts} +6 -6
  136. package/plugins/sessions/index.ts +148 -0
  137. package/plugins/sessions/plugin.json +8 -0
  138. package/plugins/shell/index.ts +33 -0
  139. package/plugins/shell/plugin.json +17 -0
  140. package/plugins/shell/renderers.ts +45 -0
  141. package/plugins/shell/service.ts +44 -0
  142. package/{src/tools → plugins/shell}/shell.ts +31 -20
  143. package/{src → plugins/shell}/sys.ts +2 -43
  144. package/plugins/skills/index.ts +96 -0
  145. package/plugins/skills/plugin.json +7 -0
  146. package/plugins/skills/project.ts +49 -0
  147. package/{src → plugins/skills}/skills.ts +4 -11
  148. package/plugins/suggest/index.ts +286 -0
  149. package/plugins/suggest/plugin.json +18 -0
  150. package/plugins/task/index.ts +168 -0
  151. package/plugins/task/plugin.json +15 -0
  152. package/plugins/task/style.ts +17 -0
  153. package/plugins/task/subagent.ts +343 -0
  154. package/plugins/todo/index.ts +93 -0
  155. package/plugins/todo/plugin.json +7 -0
  156. package/{src/ui → plugins/tui}/editor.ts +3 -0
  157. package/plugins/tui/frontend.ts +619 -0
  158. package/plugins/tui/index.ts +37 -0
  159. package/plugins/tui/mentions.ts +153 -0
  160. package/plugins/tui/plugin.json +10 -0
  161. package/{src/ui → plugins/tui}/render.ts +8 -2
  162. package/{src/ui → plugins/tui}/screen.ts +8 -3
  163. package/{src/ui → plugins/tui}/transcript.ts +79 -100
  164. package/{src/ui/tui.tsx → plugins/tui/tui.ts} +360 -392
  165. package/plugins/tui/vendor.ts +16 -0
  166. package/{src/tools → plugins/undo}/checkpoint.ts +45 -60
  167. package/plugins/undo/index.ts +143 -0
  168. package/plugins/undo/notes.ts +43 -0
  169. package/plugins/undo/plugin.json +7 -0
  170. package/plugins/undo/style.ts +17 -0
  171. package/plugins/update/index.ts +40 -0
  172. package/plugins/update/plugin.json +13 -0
  173. package/plugins/web/env.ts +78 -0
  174. package/plugins/web/index.ts +133 -0
  175. package/plugins/web/plugin.json +15 -0
  176. package/plugins/web/renderers.ts +11 -0
  177. package/{src/tools → plugins/web}/web.ts +64 -31
  178. package/plugins-dist/approval/index.js +287 -0
  179. package/plugins-dist/approval/plugin.json +28 -0
  180. package/{dist/plugins → plugins-dist/approval}/policy.js +41 -85
  181. package/{dist/plugins → plugins-dist/approval}/review.js +56 -10
  182. package/{dist/plugins → plugins-dist/approval}/schema.js +0 -1
  183. package/plugins-dist/ask/index.js +145 -0
  184. package/plugins-dist/ask/plugin.json +12 -0
  185. package/plugins-dist/budget/index.js +37 -0
  186. package/plugins-dist/budget/plugin.json +15 -0
  187. package/{dist/plugins → plugins-dist/checks}/checks.js +46 -35
  188. package/plugins-dist/checks/index.js +150 -0
  189. package/plugins-dist/checks/plugin.json +21 -0
  190. package/plugins-dist/checks/project.js +76 -0
  191. package/plugins-dist/commands/index.js +33 -0
  192. package/plugins-dist/commands/plugin.json +9 -0
  193. package/{dist/plugins → plugins-dist/compact}/compact.js +58 -34
  194. package/plugins-dist/compact/index.js +100 -0
  195. package/plugins-dist/compact/plugin.json +25 -0
  196. package/plugins-dist/compact/style.js +14 -0
  197. package/plugins-dist/continue/index.js +57 -0
  198. package/plugins-dist/continue/plugin.json +15 -0
  199. package/{dist/ui → plugins-dist/fs}/diff.js +2 -3
  200. package/{dist/tools → plugins-dist/fs}/fs.js +82 -46
  201. package/{dist/tools → plugins-dist/fs}/grep.js +36 -11
  202. package/plugins-dist/fs/index.js +39 -0
  203. package/plugins-dist/fs/plugin.json +10 -0
  204. package/{dist/ui → plugins-dist/fs}/renderers.js +24 -61
  205. package/plugins-dist/fs/style.js +15 -0
  206. package/plugins-dist/fs/sys.js +54 -0
  207. package/plugins-dist/keys/index.js +36 -0
  208. package/plugins-dist/keys/plugin.json +9 -0
  209. package/plugins-dist/mcp/index.js +187 -0
  210. package/{dist → plugins-dist/mcp}/mcp.js +34 -30
  211. package/plugins-dist/mcp/plugin.json +12 -0
  212. package/plugins-dist/mcp/project.js +90 -0
  213. package/plugins-dist/memory/index.js +94 -0
  214. package/{dist → plugins-dist/memory}/memory.js +21 -3
  215. package/plugins-dist/memory/notes.js +36 -0
  216. package/plugins-dist/memory/plugin.json +11 -0
  217. package/plugins-dist/memory/style.js +14 -0
  218. package/plugins-dist/mentions/attach.js +120 -0
  219. package/plugins-dist/mentions/index.js +87 -0
  220. package/plugins-dist/mentions/plugin.json +9 -0
  221. package/plugins-dist/mentions/style.js +14 -0
  222. package/plugins-dist/models/config.js +53 -0
  223. package/plugins-dist/models/configure.js +415 -0
  224. package/plugins-dist/models/context.js +27 -0
  225. package/plugins-dist/models/index.js +181 -0
  226. package/plugins-dist/models/plugin.json +14 -0
  227. package/{dist → plugins-dist/models}/provider.js +18 -81
  228. package/plugins-dist/models/saved.js +80 -0
  229. package/plugins-dist/modes/index.js +190 -0
  230. package/plugins-dist/modes/plugin.json +18 -0
  231. package/plugins-dist/plugins/index.js +37 -0
  232. package/plugins-dist/plugins/plugin.json +10 -0
  233. package/plugins-dist/print/index.js +172 -0
  234. package/plugins-dist/print/plugin.json +14 -0
  235. package/plugins-dist/prompts/index.js +85 -0
  236. package/plugins-dist/prompts/plugin.json +13 -0
  237. package/plugins-dist/prompts/prompts.js +231 -0
  238. package/plugins-dist/prompts/results.js +60 -0
  239. package/plugins-dist/prompts/sys.js +58 -0
  240. package/plugins-dist/renderers/index.js +36 -0
  241. package/plugins-dist/renderers/plugin.json +9 -0
  242. package/plugins-dist/repeats/index.js +165 -0
  243. package/plugins-dist/repeats/plugin.json +6 -0
  244. package/plugins-dist/schedule/cron.js +67 -0
  245. package/plugins-dist/schedule/index.js +281 -0
  246. package/plugins-dist/schedule/plugin.json +16 -0
  247. package/plugins-dist/schedule/store.js +125 -0
  248. package/plugins-dist/scratch/index.js +26 -0
  249. package/plugins-dist/scratch/plugin.json +10 -0
  250. package/plugins-dist/screenshot/index.js +35 -0
  251. package/plugins-dist/screenshot/plugin.json +11 -0
  252. package/plugins-dist/screenshot/sys.js +76 -0
  253. package/{dist/tools/screenshot.js → plugins-dist/screenshot/tool.js} +5 -4
  254. package/plugins-dist/sessions/index.js +136 -0
  255. package/plugins-dist/sessions/plugin.json +12 -0
  256. package/plugins-dist/shell/index.js +33 -0
  257. package/plugins-dist/shell/plugin.json +19 -0
  258. package/plugins-dist/shell/renderers.js +40 -0
  259. package/plugins-dist/shell/service.js +29 -0
  260. package/{dist/tools → plugins-dist/shell}/shell.js +31 -22
  261. package/{dist → plugins-dist/shell}/sys.js +2 -43
  262. package/plugins-dist/skills/index.js +90 -0
  263. package/plugins-dist/skills/plugin.json +12 -0
  264. package/plugins-dist/skills/project.js +47 -0
  265. package/{dist → plugins-dist/skills}/skills.js +3 -7
  266. package/plugins-dist/suggest/index.js +282 -0
  267. package/plugins-dist/suggest/plugin.json +23 -0
  268. package/plugins-dist/task/index.js +152 -0
  269. package/plugins-dist/task/plugin.json +23 -0
  270. package/plugins-dist/task/style.js +14 -0
  271. package/plugins-dist/task/subagent.js +284 -0
  272. package/{dist/tools/todo.js → plugins-dist/todo/index.js} +31 -9
  273. package/plugins-dist/todo/plugin.json +9 -0
  274. package/{dist/ui → plugins-dist/tui}/editor.js +3 -1
  275. package/plugins-dist/tui/frontend.js +609 -0
  276. package/{dist → plugins-dist/tui}/history.js +0 -1
  277. package/plugins-dist/tui/index.js +21 -0
  278. package/{dist/ui → plugins-dist/tui}/markdown.js +0 -1
  279. package/plugins-dist/tui/mentions.js +153 -0
  280. package/plugins-dist/tui/plugin.json +25 -0
  281. package/{dist/ui → plugins-dist/tui}/render.js +7 -3
  282. package/{dist/ui → plugins-dist/tui}/screen.js +6 -2
  283. package/{dist/ui → plugins-dist/tui}/transcript.js +79 -99
  284. package/{dist/ui → plugins-dist/tui}/tui.js +185 -54
  285. package/plugins-dist/tui/vendor.js +13822 -0
  286. package/{dist/tools → plugins-dist/undo}/checkpoint.js +48 -55
  287. package/plugins-dist/undo/index.js +143 -0
  288. package/plugins-dist/undo/notes.js +36 -0
  289. package/plugins-dist/undo/plugin.json +9 -0
  290. package/plugins-dist/undo/style.js +14 -0
  291. package/plugins-dist/update/index.js +34 -0
  292. package/plugins-dist/update/plugin.json +15 -0
  293. package/plugins-dist/web/env.js +80 -0
  294. package/plugins-dist/web/index.js +124 -0
  295. package/plugins-dist/web/plugin.json +21 -0
  296. package/plugins-dist/web/renderers.js +7 -0
  297. package/{dist/tools → plugins-dist/web}/web.js +56 -29
  298. package/sdk/python/__pycache__/jade_plugin.cpython-312.pyc +0 -0
  299. package/sdk/python/jade_plugin.py +380 -0
  300. package/src/api.ts +298 -0
  301. package/src/config.ts +32 -134
  302. package/src/fetch.ts +216 -0
  303. package/src/hash.ts +39 -0
  304. package/src/host.ts +429 -0
  305. package/src/index.ts +23 -30
  306. package/src/install.ts +355 -0
  307. package/src/main.ts +156 -1387
  308. package/src/manifest.ts +160 -0
  309. package/src/membrane.ts +142 -0
  310. package/src/remote.ts +288 -0
  311. package/src/rescue.ts +217 -0
  312. package/src/resolve.ts +199 -0
  313. package/src/rpc.ts +144 -0
  314. package/src/secrets.ts +122 -0
  315. package/src/session.ts +458 -0
  316. package/src/source.ts +83 -0
  317. package/src/state.ts +120 -0
  318. package/src/update.ts +265 -262
  319. package/LICENSE +0 -21
  320. package/dist/commands.d.ts +0 -50
  321. package/dist/commands.js +0 -126
  322. package/dist/commands.js.map +0 -1
  323. package/dist/context.d.ts +0 -17
  324. package/dist/context.js +0 -53
  325. package/dist/context.js.map +0 -1
  326. package/dist/distro.d.ts +0 -141
  327. package/dist/distro.js +0 -462
  328. package/dist/distro.js.map +0 -1
  329. package/dist/history.d.ts +0 -10
  330. package/dist/history.js.map +0 -1
  331. package/dist/mcp.d.ts +0 -114
  332. package/dist/mcp.js.map +0 -1
  333. package/dist/memory.d.ts +0 -19
  334. package/dist/memory.js.map +0 -1
  335. package/dist/mentions.d.ts +0 -35
  336. package/dist/mentions.js +0 -130
  337. package/dist/mentions.js.map +0 -1
  338. package/dist/plugin-cli.d.ts +0 -16
  339. package/dist/plugin-cli.js +0 -294
  340. package/dist/plugin-cli.js.map +0 -1
  341. package/dist/plugins/budget.d.ts +0 -9
  342. package/dist/plugins/budget.js +0 -30
  343. package/dist/plugins/budget.js.map +0 -1
  344. package/dist/plugins/builtins.d.ts +0 -10
  345. package/dist/plugins/builtins.js +0 -25
  346. package/dist/plugins/builtins.js.map +0 -1
  347. package/dist/plugins/checks.d.ts +0 -71
  348. package/dist/plugins/checks.js.map +0 -1
  349. package/dist/plugins/compact.d.ts +0 -26
  350. package/dist/plugins/compact.js.map +0 -1
  351. package/dist/plugins/core.d.ts +0 -47
  352. package/dist/plugins/core.js +0 -229
  353. package/dist/plugins/core.js.map +0 -1
  354. package/dist/plugins/host.d.ts +0 -52
  355. package/dist/plugins/host.js +0 -115
  356. package/dist/plugins/host.js.map +0 -1
  357. package/dist/plugins/install.d.ts +0 -68
  358. package/dist/plugins/install.js +0 -377
  359. package/dist/plugins/install.js.map +0 -1
  360. package/dist/plugins/loader.d.ts +0 -410
  361. package/dist/plugins/loader.js +0 -407
  362. package/dist/plugins/loader.js.map +0 -1
  363. package/dist/plugins/policy.d.ts +0 -98
  364. package/dist/plugins/policy.js.map +0 -1
  365. package/dist/plugins/prompts.d.ts +0 -43
  366. package/dist/plugins/prompts.js +0 -284
  367. package/dist/plugins/prompts.js.map +0 -1
  368. package/dist/plugins/repeats.d.ts +0 -16
  369. package/dist/plugins/repeats.js +0 -151
  370. package/dist/plugins/repeats.js.map +0 -1
  371. package/dist/plugins/review.d.ts +0 -18
  372. package/dist/plugins/review.js.map +0 -1
  373. package/dist/plugins/schema.d.ts +0 -2
  374. package/dist/plugins/schema.js.map +0 -1
  375. package/dist/plugins/sessions.d.ts +0 -7
  376. package/dist/plugins/sessions.js +0 -110
  377. package/dist/plugins/sessions.js.map +0 -1
  378. package/dist/provider.d.ts +0 -165
  379. package/dist/provider.js.map +0 -1
  380. package/dist/session-lifecycle.d.ts +0 -61
  381. package/dist/session-lifecycle.js +0 -167
  382. package/dist/session-lifecycle.js.map +0 -1
  383. package/dist/session-scope.d.ts +0 -53
  384. package/dist/session-scope.js +0 -116
  385. package/dist/session-scope.js.map +0 -1
  386. package/dist/sessions.d.ts +0 -28
  387. package/dist/sessions.js +0 -73
  388. package/dist/sessions.js.map +0 -1
  389. package/dist/skills.d.ts +0 -37
  390. package/dist/skills.js.map +0 -1
  391. package/dist/sys.d.ts +0 -51
  392. package/dist/sys.js.map +0 -1
  393. package/dist/tools/ask.d.ts +0 -11
  394. package/dist/tools/ask.js +0 -62
  395. package/dist/tools/ask.js.map +0 -1
  396. package/dist/tools/checkpoint.d.ts +0 -43
  397. package/dist/tools/checkpoint.js.map +0 -1
  398. package/dist/tools/fs.d.ts +0 -39
  399. package/dist/tools/fs.js.map +0 -1
  400. package/dist/tools/grep.d.ts +0 -6
  401. package/dist/tools/grep.js.map +0 -1
  402. package/dist/tools/screenshot.d.ts +0 -15
  403. package/dist/tools/screenshot.js.map +0 -1
  404. package/dist/tools/shell.d.ts +0 -55
  405. package/dist/tools/shell.js.map +0 -1
  406. package/dist/tools/task.d.ts +0 -39
  407. package/dist/tools/task.js +0 -117
  408. package/dist/tools/task.js.map +0 -1
  409. package/dist/tools/todo.d.ts +0 -10
  410. package/dist/tools/todo.js.map +0 -1
  411. package/dist/tools/web.d.ts +0 -53
  412. package/dist/tools/web.js.map +0 -1
  413. package/dist/ui/configure.d.ts +0 -20
  414. package/dist/ui/configure.js +0 -447
  415. package/dist/ui/configure.js.map +0 -1
  416. package/dist/ui/diff.d.ts +0 -20
  417. package/dist/ui/diff.js.map +0 -1
  418. package/dist/ui/editor.d.ts +0 -41
  419. package/dist/ui/editor.js.map +0 -1
  420. package/dist/ui/markdown.d.ts +0 -22
  421. package/dist/ui/markdown.js.map +0 -1
  422. package/dist/ui/render.d.ts +0 -14
  423. package/dist/ui/render.js.map +0 -1
  424. package/dist/ui/renderers.d.ts +0 -8
  425. package/dist/ui/renderers.js.map +0 -1
  426. package/dist/ui/screen.d.ts +0 -118
  427. package/dist/ui/screen.js.map +0 -1
  428. package/dist/ui/transcript.d.ts +0 -46
  429. package/dist/ui/transcript.js.map +0 -1
  430. package/dist/ui/tui.d.ts +0 -47
  431. package/dist/ui/tui.js.map +0 -1
  432. package/src/commands.ts +0 -144
  433. package/src/context.ts +0 -64
  434. package/src/distro.ts +0 -577
  435. package/src/mentions.ts +0 -135
  436. package/src/plugin-cli.ts +0 -278
  437. package/src/plugins/budget.ts +0 -37
  438. package/src/plugins/builtins.ts +0 -34
  439. package/src/plugins/core.ts +0 -257
  440. package/src/plugins/host.ts +0 -146
  441. package/src/plugins/install.ts +0 -429
  442. package/src/plugins/loader.ts +0 -742
  443. package/src/plugins/prompts.ts +0 -327
  444. package/src/plugins/repeats.ts +0 -157
  445. package/src/plugins/sessions.ts +0 -109
  446. package/src/session-lifecycle.ts +0 -194
  447. package/src/session-scope.ts +0 -135
  448. package/src/sessions.ts +0 -78
  449. package/src/tools/ask.ts +0 -72
  450. package/src/tools/task.ts +0 -149
  451. package/src/tools/todo.ts +0 -67
  452. package/src/ui/configure.ts +0 -471
  453. /package/{src/plugins → plugins/approval}/schema.ts +0 -0
  454. /package/{src → plugins/tui}/history.ts +0 -0
  455. /package/{src/ui → plugins/tui}/markdown.ts +0 -0
@@ -0,0 +1,15 @@
1
+ {
2
+ "id": "jade/continue",
3
+ "version": "0.2.0",
4
+ "api": "^1",
5
+ "entry": "./index.js",
6
+ "optional": [
7
+ "ui@1"
8
+ ],
9
+ "config": {
10
+ "maxContinues": {
11
+ "default": 3,
12
+ "description": "how many times in a row the model is asked to continue a reply cut off at the output token limit; 0 turns it off"
13
+ }
14
+ }
15
+ }
@@ -1,8 +1,8 @@
1
- // 按行比较两段文本,生成带行号和上下文的 unified diff,审批修改时显示。
1
+ // 按行比较两段文本,生成带行号和上下文的 unified diff:审批修改时的预览、对话里修改结果的展开内容。从旧 jade 的 ui/diff.ts 移植。
2
2
  //
3
3
  // 先去掉相同的开头和结尾,只对中间部分求最长公共子序列;中间部分太大时(整个文件重写)
4
4
  // 不再逐行比较,整段显示为删除加新增,避免占用大量内存和时间。
5
- import { dim, green, red } from "./screen.js";
5
+ import { dim, green, red } from "./style.js";
6
6
  /** LCS 表的上限:中间部分的行数乘积超过它就整段替换 */
7
7
  const MAX_CELLS = 4_000_000;
8
8
  const splitLines = (s) => {
@@ -138,4 +138,3 @@ export function renderDiff(before, after, maxLines = 60, lines = diffLines(befor
138
138
  out.push(dim(` ${green(`+${added}`)} ${red(`-${removed}`)}`));
139
139
  return out.join("\n");
140
140
  }
141
- //# sourceMappingURL=diff.js.map
@@ -1,16 +1,14 @@
1
1
  // 文件工具:read_file / write_file / edit_file / list_dir / glob,以及 grep(见 grep.ts)。
2
2
  //
3
- // 路径可以是相对路径(相对于工作目录)或绝对路径。policy 插件在 tool.before 里把它们统一成绝对路径,
4
- // 再由关卡判断是否在工作目录内;工具本身不做权限判断。
3
+ // 路径可以是相对路径(相对于工作目录)或绝对路径。工具本身不做权限判断:那是审批插件的事。
5
4
  //
6
5
  // 修改已有文件之前必须先读过它,且读过之后文件没有被别人(用户、bash 命令)改过,
7
6
  // 否则模型是按过时的内容在改,会覆盖掉别人的修改。和修改在同一次回复里发出的读取不算:
8
7
  // 那次修改的内容是模型看到读取结果之前就写好的。
9
8
  import { mkdir, readdir, readFile, stat, writeFile } from "node:fs/promises";
10
9
  import path from "node:path";
11
- import { sha256 } from "./checkpoint.js";
12
10
  import { grepTool } from "./grep.js";
13
- import { globMatcher, run } from "../sys.js";
11
+ import { globMatcher, run } from "./sys.js";
14
12
  const MAX_LINES = 2000;
15
13
  const MAX_LINE_CHARS = 2000;
16
14
  /** 一次 read_file 返回的文本上限(约 25k token) */
@@ -38,26 +36,51 @@ export function display(cwd, full) {
38
36
  const shown = rel && rel !== ".." && !rel.startsWith(`..${path.sep}`) && !path.isAbsolute(rel) ? rel : full;
39
37
  return shown.split(path.sep).join("/");
40
38
  }
39
+ /** 本会话读过、写过的文件 */
40
+ export class SeenFiles {
41
+ files = new Map();
42
+ /** 因为压缩而失效的文件:再改时说明原因,而不是说"没读过" */
43
+ dropped = new Set();
44
+ /**
45
+ * 压缩或清理之后,模型看不到当初读到(写入)的内容了,但 mtime 和 size 没变,修改仍会放行;
46
+ * write_file 可能凭摘要里的记忆写出整个文件。这里按最终的投影检查:那次调用已被总结掉(投影里没有它的 tool_use),
47
+ * 或者结果已被清理(tool_result 里没有工具自己给的内容,只剩插件的占位说明),就当作没读过
48
+ */
49
+ prune(projection) {
50
+ const uses = new Set();
51
+ const cleared = new Set();
52
+ for (const m of projection) {
53
+ for (const b of m.content) {
54
+ if (b.kind === "tool_use")
55
+ uses.add(b.id);
56
+ else if (b.kind === "tool_result" && !b.content.some((c) => c.origin.by === "tool"))
57
+ cleared.add(b.toolUseId);
58
+ }
59
+ }
60
+ for (const [full, s] of this.files) {
61
+ if (s.id === undefined || (uses.has(s.id) && !cleared.has(s.id)))
62
+ continue;
63
+ this.files.delete(full);
64
+ this.dropped.add(full);
65
+ }
66
+ }
67
+ }
41
68
  export function fsTools(cwd, opts = {}) {
42
69
  const at = (p) => resolveIn(cwd, p);
43
- const seen = new Map();
44
- const inScratch = (full) => {
45
- if (opts.scratch === undefined)
46
- return false;
47
- const rel = path.relative(opts.scratch, full);
48
- return rel !== "" && rel !== ".." && !rel.startsWith(`..${path.sep}`) && !path.isAbsolute(rel);
49
- };
50
- /** 文件没变时保留更早的 call:之前的回复里读过,这次回复里又读一遍,不影响修改 */
51
- const remember = async (ctx, full, info, text, call) => {
70
+ const tracked = opts.seen ?? new SeenFiles();
71
+ const seen = tracked.files;
72
+ /**
73
+ * 文件没变时保留更早的 call:之前的回复里读过,这次回复里又读一遍,不影响修改。
74
+ * id 为 undefined 表示沿用原来的(edit_file)
75
+ */
76
+ const remember = (full, info, call, id) => {
52
77
  const s = seen.get(full);
53
78
  const same = s !== undefined && s.mtimeMs === info.mtimeMs && s.size === info.size;
54
- seen.set(full, { mtimeMs: info.mtimeMs, size: info.size, call: same ? Math.min(s.call, call) : call });
55
- await opts.checkpoints?.markSeen(ctx.sessionId, full, sha256(text));
79
+ seen.set(full, { mtimeMs: info.mtimeMs, size: info.size, call: same ? Math.min(s.call, call) : call, id: id ?? s?.id });
80
+ tracked.dropped.delete(full);
56
81
  };
57
82
  /** 不能修改已有文件的原因;可以修改时返回 undefined。text 是文件现在的内容 */
58
- const staleness = async (ctx, full, info, text) => {
59
- if (inScratch(full))
60
- return undefined;
83
+ const staleness = (full, info) => {
61
84
  const shown = display(cwd, full);
62
85
  const modified = `${shown} has been modified since it was last read (by the user or a command). Read it again before changing it.`;
63
86
  const s = seen.get(full);
@@ -69,17 +92,10 @@ export function fsTools(cwd, opts = {}) {
69
92
  }
70
93
  return undefined;
71
94
  }
72
- // 恢复的会话:之前的进程里读过或写过
73
- const hash = await opts.checkpoints?.seenHash(ctx.sessionId, full);
74
- if (hash === undefined)
75
- return `${shown} exists but has not been read in this session. Read it with read_file before changing it.`;
76
- if (hash !== sha256(text))
77
- return modified;
78
- seen.set(full, { mtimeMs: info.mtimeMs, size: info.size, call: -1 });
79
- return undefined;
80
- };
81
- const checkpoint = async (ctx, tool, full, before, after) => {
82
- await opts.checkpoints?.save(ctx.sessionId, { toolUseId: ctx.toolUseId, tool, path: full, before, afterHash: sha256(after) });
95
+ if (tracked.dropped.has(full)) {
96
+ return `The earlier read of ${shown} was compacted out of the conversation, so its content is no longer in context. Read it again before changing it.`;
97
+ }
98
+ return `${shown} exists but has not been read in this session. Read it with read_file before changing it.`;
83
99
  };
84
100
  const readFileTool = {
85
101
  name: "read_file",
@@ -131,7 +147,7 @@ export function fsTools(cwd, opts = {}) {
131
147
  return { content: `${display(cwd, full)} is a binary file (${buf.length} bytes) and cannot be shown as text`, isError: true };
132
148
  }
133
149
  const text = buf.toString("utf8");
134
- await remember(ctx, full, info, text, opts.responses?.calls ?? -1);
150
+ remember(full, info, opts.responses?.calls ?? -1, ctx?.toolUseId);
135
151
  if (text.length === 0)
136
152
  return { content: "(empty file)" };
137
153
  const lines = text.split(/\r?\n/);
@@ -183,21 +199,19 @@ export function fsTools(cwd, opts = {}) {
183
199
  const before = info ? await readFile(full, "utf8") : null;
184
200
  // read_file 不显示换行风格和 BOM:覆盖已有文件时沿用原来的,否则整个文件每一行都算改了
185
201
  const content = before === null ? given : keepStyle(before, given);
186
- const problem = info && before !== null && before !== content ? await staleness(ctx, full, info, before) : undefined;
202
+ const problem = info && before !== null && before !== content ? staleness(full, info) : undefined;
187
203
  if (problem)
188
204
  return { content: problem, isError: true };
189
205
  await mkdir(path.dirname(full), { recursive: true });
190
206
  await writeFile(full, content);
191
- await remember(ctx, full, await stat(full), content, -1);
192
- if (before !== content)
193
- await checkpoint(ctx, "write_file", full, before, content);
207
+ remember(full, await stat(full), -1, ctx?.toolUseId);
194
208
  // 和 read_file 一样数行:末尾的换行不算多出一行
195
209
  const lines = content === "" ? 0 : content.split(/\r?\n/).length - (/\r?\n$/.test(content) ? 1 : 0);
196
210
  return { content: `Wrote ${lines} lines to ${display(cwd, full)}` };
197
211
  },
198
212
  };
199
213
  /** edit_file 和 multi_edit 共用:检查文件能否修改,按顺序应用全部替换,全部成功才写入 */
200
- const applyEdits = async (ctx, tool, p, edits) => {
214
+ const applyEdits = async (p, edits) => {
201
215
  const full = at(p);
202
216
  const shown = display(cwd, full);
203
217
  const info = await statOrUndefined(full);
@@ -205,7 +219,7 @@ export function fsTools(cwd, opts = {}) {
205
219
  return { content: seen.has(full) ? `${shown} no longer exists` : `${shown} does not exist; use write_file to create it`, isError: true };
206
220
  }
207
221
  const text = await readFile(full, "utf8");
208
- const problem = await staleness(ctx, full, info, text);
222
+ const problem = staleness(full, info);
209
223
  if (problem)
210
224
  return { content: problem, isError: true };
211
225
  let next = text;
@@ -218,8 +232,7 @@ export function fsTools(cwd, opts = {}) {
218
232
  total += r.count;
219
233
  }
220
234
  await writeFile(full, next);
221
- await remember(ctx, full, await stat(full), next, -1);
222
- await checkpoint(ctx, tool, full, text, next);
235
+ remember(full, await stat(full), -1, undefined);
223
236
  return { content: `Edited ${shown} (${total} replacement${total === 1 ? "" : "s"})` };
224
237
  };
225
238
  const editFileTool = {
@@ -237,9 +250,9 @@ export function fsTools(cwd, opts = {}) {
237
250
  concurrency: "exclusive",
238
251
  // 第二次执行时 old_string 可能已经不存在,或者被替换两次
239
252
  idempotent: false,
240
- async execute(input, ctx) {
253
+ async execute(input) {
241
254
  const { path: p, ...edit } = input;
242
- return applyEdits(ctx, "edit_file", p, [edit]);
255
+ return applyEdits(p, [edit]);
243
256
  },
244
257
  };
245
258
  const multiEditTool = {
@@ -266,11 +279,11 @@ export function fsTools(cwd, opts = {}) {
266
279
  effect: "write",
267
280
  concurrency: "exclusive",
268
281
  idempotent: false,
269
- async execute(input, ctx) {
282
+ async execute(input) {
270
283
  const { path: p, edits } = input;
271
284
  if (edits.length === 0)
272
285
  return { content: "edits must not be empty", isError: true };
273
- return applyEdits(ctx, "multi_edit", p, edits);
286
+ return applyEdits(p, edits);
274
287
  },
275
288
  };
276
289
  const listDirTool = {
@@ -289,6 +302,7 @@ export function fsTools(cwd, opts = {}) {
289
302
  const globTool = {
290
303
  name: "glob",
291
304
  description: `Find files by glob pattern (e.g. "src/**/*.ts"), relative to path (default: the working directory). ` +
305
+ `Unlike grep's include, "*.ts" matches only directly under path; use "**/*.ts" for any depth. ` +
292
306
  `Skips files ignored by git, .git and node_modules. Returns at most ${MAX_GLOB} paths.`,
293
307
  inputSchema: {
294
308
  type: "object",
@@ -320,8 +334,9 @@ export function fsTools(cwd, opts = {}) {
320
334
  out.push(display(cwd, path.join(root, rel)));
321
335
  }
322
336
  out.sort();
337
+ // 和 grep 的 include 不同,不含 / 的模式只匹配第一层:模型常按 grep 的习惯写
323
338
  if (out.length === 0)
324
- return { content: "No files matched" };
339
+ return { content: pattern.includes("/") || pattern.startsWith("**") ? "No files matched" : `No files matched. "${pattern}" only matches directly under ${p === "." ? "the working directory" : p}; use "**/${pattern}" to search at any depth.` };
325
340
  return { content: out.join("\n") + (more ? `\n(more than ${MAX_GLOB} matches; narrow the pattern)` : "") };
326
341
  },
327
342
  };
@@ -365,19 +380,41 @@ function replaceIn(text, { old_string, new_string, replace_all }, shown) {
365
380
  const count = text.match(pattern)?.length ?? 0;
366
381
  if (count === 0)
367
382
  return `old_string not found in ${shown}${nearMiss(text, old_string)}`;
368
- if (count > 1 && !replace_all)
369
- return `old_string occurs ${count} times in ${shown}; add context to make it unique or set replace_all`;
383
+ if (count > 1 && !replace_all) {
384
+ return `old_string occurs ${count} times in ${shown} (${linesOf(text, pattern, 5)}); add context to make it unique or set replace_all`;
385
+ }
370
386
  // new_string 的换行沿用被替换那段的;那段只有一行时沿用整个文件的,单行改成多行也不会混进 LF
371
387
  const fileEol = eolOf(text, "\n");
372
388
  const to = (matched) => (new_string.includes("\r\n") ? new_string : new_string.replaceAll("\n", eolOf(matched, fileEol)));
373
389
  // 用函数作替换值,new_string 里的 $& $1 等不会被当成替换模式
374
390
  return { text: text.replace(replace_all ? pattern : new RegExp(pattern.source), to), count: replace_all ? count : 1 };
375
391
  }
392
+ /** pattern 前 max 处匹配所在的行号,例如 "lines 3, 17, 40" */
393
+ function linesOf(text, pattern, max) {
394
+ const found = [];
395
+ let line = 1;
396
+ let from = 0;
397
+ for (const m of text.matchAll(new RegExp(pattern.source, "g"))) {
398
+ for (let i = from; i < m.index; i++)
399
+ if (text.charCodeAt(i) === 10)
400
+ line++;
401
+ from = m.index;
402
+ found.push(line);
403
+ if (found.length === max)
404
+ break;
405
+ }
406
+ return `line${found.length > 1 ? "s" : ""} ${found.join(", ")}${found.length === max ? ", …" : ""}`;
407
+ }
376
408
  /**
377
409
  * old_string 找不到时帮模型定位:忽略空白后能匹配到哪几行,或者第一行出现在哪里。
378
410
  * 只给提示,不自动按模糊匹配修改:那样可能改错地方
379
411
  */
380
412
  export function nearMiss(text, needle) {
413
+ // 最常见的一种:把 read_file 每行开头的行号和制表符一起抄进来了
414
+ const raw = needle.split(/\r?\n/).filter((l) => l.trim() !== "");
415
+ if (raw.length > 0 && raw.every((l) => /^\s*\d+\t/.test(l))) {
416
+ return ". It seems to include read_file's line-number prefixes (the number and tab at the start of each line); they are not part of the file. Remove them and keep the rest exactly";
417
+ }
381
418
  const norm = (l) => l.trim().replace(/\s+/g, " ");
382
419
  const lines = text.split(/\r?\n/).map(norm);
383
420
  const want = needle.split(/\r?\n/).map(norm);
@@ -455,4 +492,3 @@ async function* walk(dir, signal) {
455
492
  }
456
493
  }
457
494
  }
458
- //# sourceMappingURL=fs.js.map
@@ -6,7 +6,7 @@
6
6
  import { readFile, stat } from "node:fs/promises";
7
7
  import path from "node:path";
8
8
  import { display, listFiles, statOrUndefined } from "./fs.js";
9
- import { globMatcher, spawn, text } from "../sys.js";
9
+ import { globMatcher, spawn, text } from "./sys.js";
10
10
  const MAX_MATCHES = 200;
11
11
  const MAX_FILES = 500;
12
12
  const MAX_CONTEXT = 10;
@@ -196,6 +196,32 @@ async function ripgrep(rg, s) {
196
196
  }
197
197
  }
198
198
  // ---------- JS ----------
199
+ /** 同时读几个文件。逐个等 stat、readFile 时,几万个文件的仓库要好几秒(多数时间花在等 IO 上) */
200
+ const READ_AHEAD = 16;
201
+ /** 读出可以搜的文本;不存在(git 列出的文件可能已在工作区删除)、太大、二进制的返回 undefined */
202
+ async function readSearchable(file) {
203
+ const info = await statOrUndefined(file);
204
+ if (!info?.isFile() || info.size > MAX_FILE_BYTES)
205
+ return undefined;
206
+ const buf = await readFile(file).catch(() => undefined);
207
+ return buf && !buf.includes(0) ? buf : undefined;
208
+ }
209
+ /** 按 items 的顺序产出 fn 的结果,最多 n 个同时进行;调用方提前停止时,已经开始的读取随它结束 */
210
+ async function* ordered(items, n, fn) {
211
+ const pending = [];
212
+ for await (const item of items) {
213
+ const result = fn(item);
214
+ // 先挂上处理,免得提前停止时没人等的 Promise 报 unhandled rejection
215
+ result.catch(() => { });
216
+ pending.push({ item, result });
217
+ if (pending.length >= n) {
218
+ const head = pending.shift();
219
+ yield [head.item, await head.result];
220
+ }
221
+ }
222
+ for (const p of pending)
223
+ yield [p.item, await p.result];
224
+ }
199
225
  async function jsGrep(s) {
200
226
  // 和 ripgrep 的 --glob 一致:不含 / 的模式("*.ts")匹配任意深度的文件名
201
227
  const filter = s.include ? globMatcher(s.include.includes("/") ? s.include : `**/${s.include}`) : undefined;
@@ -204,17 +230,17 @@ async function jsGrep(s) {
204
230
  const single = (await stat(s.root)).isFile();
205
231
  const candidates = single ? [s.root] : await listFiles(s.root, s.signal);
206
232
  const sorted = Array.isArray(candidates) ? [...candidates].sort() : candidates;
207
- for await (const file of sorted) {
233
+ const wanted = async function* () {
234
+ for await (const file of sorted) {
235
+ if (filter && !single && !filter(path.relative(s.root, file).split(path.sep).join("/")))
236
+ continue;
237
+ yield file;
238
+ }
239
+ };
240
+ for await (const [file, buf] of ordered(wanted(), READ_AHEAD, readSearchable)) {
208
241
  s.signal.throwIfAborted();
209
- if (filter && !single && !filter(path.relative(s.root, file).split(path.sep).join("/")))
210
- continue;
211
- // git 列出的文件可能已在工作区删除
212
- const info = await statOrUndefined(file);
213
- if (!info?.isFile() || info.size > MAX_FILE_BYTES)
242
+ if (!buf)
214
243
  continue;
215
- const buf = await readFile(file);
216
- if (buf.includes(0))
217
- continue; // 二进制文件
218
244
  const all = buf.toString("utf8").split(/\r?\n/);
219
245
  if (all.at(-1) === "")
220
246
  all.pop();
@@ -241,4 +267,3 @@ async function jsGrep(s) {
241
267
  }
242
268
  return { files, truncated: false };
243
269
  }
244
- //# sourceMappingURL=grep.js.map
@@ -0,0 +1,39 @@
1
+ // jade/fs:文件工具 read_file、write_file、edit_file、multi_edit、list_dir、glob、grep。
2
+ import { definePlugin } from "../../dist/api.js";
3
+ import { fsTools, SeenFiles } from "./fs.js";
4
+ import { fsRenderers } from "./renderers.js";
5
+ export default definePlugin({
6
+ process(ctx) {
7
+ // 显示方式和会话无关,登记一次留到进程结束;没有 renderers@1(例如 print)时用前端的默认显示
8
+ const renderers = ctx.service("renderers@1");
9
+ if (renderers)
10
+ for (const r of fsRenderers(ctx.cwd))
11
+ renderers.tool(r);
12
+ },
13
+ session(ctx) {
14
+ // 数模型调用的次数:同一次回复里先读后改的,改的内容是看到读取结果之前写好的。
15
+ // 同时按最终发给模型的消息让被压缩(jade/compact 总结或清理)掉的读取失效:那些文件要重新读才能改
16
+ const responses = { calls: 0 };
17
+ const seen = new SeenFiles();
18
+ ctx.kernel.hook({
19
+ kind: "transform",
20
+ point: "model.before",
21
+ fn: (request) => {
22
+ responses.calls++;
23
+ seen.prune(request.messages);
24
+ },
25
+ });
26
+ for (const tool of fsTools(ctx.cwd, { responses, seen }))
27
+ ctx.kernel.tool(tool);
28
+ // 子 Agent(jade/task)的只读工具:另一套实例,子 Agent 读过的文件不算主会话读过
29
+ // jade/task 被隔离时它的服务已失效:子 Agent 没有文件工具,文件工具本身照常
30
+ try {
31
+ const task = ctx.service("task@1");
32
+ if (task)
33
+ for (const tool of fsTools(ctx.cwd))
34
+ if (tool.effect === "read")
35
+ task.tool(tool);
36
+ }
37
+ catch { }
38
+ },
39
+ });
@@ -0,0 +1,10 @@
1
+ {
2
+ "id": "jade/fs",
3
+ "version": "0.2.0",
4
+ "api": "^1",
5
+ "entry": "./index.js",
6
+ "optional": [
7
+ "renderers@1",
8
+ "task@1"
9
+ ]
10
+ }
@@ -1,14 +1,21 @@
1
- // jade 自己的工具怎么显示:和插件一样用 ToolRenderer(见 plugins/loader.ts),由提供这些工具的内置插件带上。
2
- // 没有 renderer 的工具、renderer 没给的部分用 transcript 的默认显示。
1
+ // 文件工具在对话和审批里怎么显示(登记到 renderers@1)。从旧 jade 的 ui/renderers.ts 移植,去掉了检查点。
2
+ //
3
+ // 审批插件的 tool.before 把 path 换成了绝对路径,审批预览、before、result 拿到的都是绝对路径;
4
+ // 显示时用 display 换回工作目录内的相对路径。没有登记 renderer 的部分用前端的默认显示。
3
5
  import { readFileSync } from "node:fs";
4
6
  import { readFile } from "node:fs/promises";
5
7
  import path from "node:path";
6
- import { applyEditsToText, display } from "../tools/fs.js";
7
8
  import { diffLines, diffStats, renderDiff } from "./diff.js";
8
- import { clip } from "./render.js";
9
- import { dim, green, red, yellow } from "./screen.js";
10
- const args = (input) => (input ?? {});
11
- const pathOf = (cwd, i) => (typeof i.path === "string" ? display(cwd, i.path) : "");
9
+ import { applyEditsToText, display } from "./fs.js";
10
+ import { clip, dim, green, red, yellow } from "./style.js";
11
+ const args = (input) => (input !== null && typeof input === "object" ? input : {});
12
+ /** 显示用的路径;工作目录本身显示成 "."(display 对它给的是绝对路径,审批插件会把 "." 换成工作目录) */
13
+ function pathOf(cwd, i) {
14
+ if (typeof i.path !== "string")
15
+ return "";
16
+ const full = path.resolve(cwd, i.path);
17
+ return path.relative(cwd, full) === "" ? "." : display(cwd, full);
18
+ }
12
19
  /** 预览里的多行文字:每行前面加上标记,最多 max 行 */
13
20
  function marked(s, mark, color, max = 30) {
14
21
  const all = s.split("\n");
@@ -17,7 +24,7 @@ function marked(s, mark, color, max = 30) {
17
24
  shown.push(dim(` … ${all.length - max} more lines`));
18
25
  return shown.join("\n");
19
26
  }
20
- /** 折叠内容里的多行文字(缩进由 transcript 加),最多 max 行 */
27
+ /** 折叠内容里的多行文字(缩进由前端加),最多 max 行 */
21
28
  function capped(lines, color, max) {
22
29
  const shown = lines.slice(0, max).map(color);
23
30
  if (lines.length > max)
@@ -57,7 +64,7 @@ const MAX_DIFF_LINES = 400;
57
64
  const MAX_RESULT_LINES = 2000;
58
65
  /**
59
66
  * 执行前后的差异。在工具执行之前调用(读的是修改前的文件),同步读文件:
60
- * 执行前的事件通知是同步的,等异步读完文件可能已经改了。替换不成立时返回 undefined
67
+ * 执行前的通知是同步的,等异步读完文件可能已经改了。替换不成立时返回 undefined
61
68
  */
62
69
  function fileDiff(cwd, tool, input) {
63
70
  const i = args(input);
@@ -103,67 +110,23 @@ function fileRenderer(cwd, tool, summary) {
103
110
  };
104
111
  }
105
112
  export function fsRenderers(cwd) {
113
+ // 默认摘要是 path 参数,审批插件换成绝对路径后太长:统一换回相对路径
114
+ const where = (input) => pathOf(cwd, args(input));
106
115
  const search = (input) => {
107
116
  const i = args(input);
108
- const where = pathOf(cwd, i);
109
- return `${i.pattern}${where && where !== "." ? ` in ${where}` : ""}`;
117
+ const at = pathOf(cwd, i);
118
+ return `${i.pattern}${at && at !== "." ? ` in ${at}` : ""}`;
110
119
  };
111
120
  return [
112
- fileRenderer(cwd, "edit_file"),
121
+ { tool: "read_file", summary: where },
122
+ { tool: "list_dir", summary: where },
123
+ fileRenderer(cwd, "edit_file", where),
113
124
  fileRenderer(cwd, "multi_edit", (input) => {
114
125
  const i = args(input);
115
126
  return `${pathOf(cwd, i)}, ${Array.isArray(i.edits) ? i.edits.length : 0} edits`;
116
127
  }),
117
- fileRenderer(cwd, "write_file"),
128
+ fileRenderer(cwd, "write_file", where),
118
129
  { tool: "grep", summary: search },
119
130
  { tool: "glob", summary: search },
120
131
  ];
121
132
  }
122
- // ---------- 其他内置工具 ----------
123
- export const shellRenderers = [
124
- {
125
- tool: "bash",
126
- summary: (input) => clip(String(args(input).command ?? "").split("\n")[0], 120),
127
- // 摘要省略了内容时(多行或很长的命令),展开后先显示完整的命令
128
- details: (input) => {
129
- const lines = String(args(input).command ?? "").split("\n");
130
- if (lines.length === 1 && lines[0].length <= 120)
131
- return undefined;
132
- return capped(lines.map((l, i) => `${i === 0 ? "$" : " "} ${l}`), dim, 200);
133
- },
134
- preview: (input) => marked(String(args(input).command ?? ""), "$", (s) => s),
135
- },
136
- { tool: "bash_output", summary: (input) => String(args(input).id ?? "") },
137
- { tool: "kill_shell", summary: (input) => String(args(input).id ?? "") },
138
- ];
139
- export const webRenderers = [
140
- { tool: "web_fetch", summary: (input) => clip(String(args(input).url ?? ""), 120) },
141
- { tool: "web_search", summary: (input) => clip(String(args(input).query ?? ""), 120) },
142
- ];
143
- export const todoRenderers = [
144
- { tool: "todo_write", summary: (input) => `${Array.isArray(args(input).todos) ? args(input).todos.length : 0} items` },
145
- ];
146
- export const askRenderers = [
147
- {
148
- tool: "ask_user",
149
- summary: (input) => {
150
- const q = args(input).questions;
151
- return Array.isArray(q) && q.length === 1 ? clip(String(q[0]?.question ?? ""), 120) : `${Array.isArray(q) ? q.length : 0} questions`;
152
- },
153
- },
154
- ];
155
- export const memoryRenderers = [
156
- {
157
- tool: "memory",
158
- summary: (input) => {
159
- const i = args(input);
160
- return `${i.action} ${i.scope}: ${clip(String(i.text ?? ""), 120)}`;
161
- },
162
- preview: (input) => {
163
- const i = args(input);
164
- return `${i.action === "remove" ? red("- ") : green("+ ")}${String(i.text ?? "")}`;
165
- },
166
- },
167
- ];
168
- export const taskRenderers = [{ tool: "task", summary: (input) => String(args(input).description ?? "") }];
169
- //# sourceMappingURL=renderers.js.map
@@ -0,0 +1,15 @@
1
+ // 显示用的小工具:截断和 ANSI 颜色。从旧 jade 的 ui/render.ts、ui/screen.ts 复制过来:
2
+ // 插件之间不共享代码(只能共享类型),所以 shell 插件也有一份。
3
+ export const clip = (s, n) => (s.length > n ? s.slice(0, n) + "…" : s);
4
+ // 设了 NO_COLOR(非空)或标准输出不是终端时不输出颜色,见 https://no-color.org
5
+ const colors = Boolean(process.stdout.isTTY) && !process.env.NO_COLOR;
6
+ /**
7
+ * 每种样式用自己的关闭码,不用 \x1b[0m 全部重置:外面套着别的样式时,后面的文字仍保持外层样式。
8
+ * 里面出现同一个关闭码(例如 dim 里套 bold,两者都用 22 关闭)时紧接着重新打开外层的样式
9
+ */
10
+ const paint = (open, close) => (s) => colors ? `\x1b[${open}m${s.replaceAll(`\x1b[${close}m`, `\x1b[${close}m\x1b[${open}m`)}\x1b[${close}m` : s;
11
+ export const dim = paint("2", "22");
12
+ export const red = paint("31", "39");
13
+ export const green = paint("32", "39");
14
+ export const yellow = paint("33", "39");
15
+ export const bold = paint("1", "22");
@@ -0,0 +1,54 @@
1
+ // 跨运行时的进程和 glob:只用 Node 的标准库,Bun 和 Node ≥22.18 下走同一套代码。
2
+ import { spawn as nodeSpawn } from "node:child_process";
3
+ import picomatch from "picomatch";
4
+ const EMPTY = { async *[Symbol.asyncIterator]() { } };
5
+ /**
6
+ * 启动进程,等到确实启动了才返回。程序不存在(ENOENT)等启动错误会 reject,
7
+ * 调用方用 try/catch 判断"没装",和 Bun.spawn 同步抛错的用法一致
8
+ */
9
+ export function spawn(cmd, opts = {}) {
10
+ const child = nodeSpawn(cmd[0], cmd.slice(1), {
11
+ cwd: opts.cwd,
12
+ stdio: ["ignore", opts.stdout ?? "pipe", opts.stderr ?? "pipe"],
13
+ detached: opts.detached ?? false,
14
+ env: opts.env,
15
+ // Windows 上不弹出控制台窗口
16
+ windowsHide: true,
17
+ });
18
+ const exited = new Promise((resolve) => child.once("exit", (code) => resolve(code)));
19
+ return new Promise((resolve, reject) => {
20
+ child.once("error", reject);
21
+ child.once("spawn", () => {
22
+ child.off("error", reject);
23
+ // 启动之后的错误(例如 kill 一个已经退出的进程)不应该变成未处理的异常
24
+ child.on("error", () => { });
25
+ resolve({
26
+ pid: child.pid,
27
+ stdout: child.stdout ?? EMPTY,
28
+ stderr: child.stderr ?? EMPTY,
29
+ exited,
30
+ kill: () => void child.kill(),
31
+ });
32
+ });
33
+ });
34
+ }
35
+ /** 运行一条命令,返回 stdout 文本和退出码;启动失败时 reject */
36
+ export async function run(cmd, opts = {}) {
37
+ const proc = await spawn(cmd, { cwd: opts.cwd, stderr: "ignore" });
38
+ const [stdout, code] = await Promise.all([text(proc.stdout), proc.exited]);
39
+ return { code, stdout };
40
+ }
41
+ export async function text(stream) {
42
+ const decoder = new TextDecoder();
43
+ let out = "";
44
+ for await (const chunk of stream)
45
+ out += decoder.decode(chunk, { stream: true });
46
+ return out + decoder.decode();
47
+ }
48
+ /**
49
+ * 编译 glob,返回匹配函数。路径用正斜杠、相对于搜索根目录。
50
+ * 和原先的 Bun.Glob#match 一致:* 也匹配点开头的文件,反斜杠是转义符而不是分隔符
51
+ */
52
+ export function globMatcher(pattern) {
53
+ return picomatch(pattern, { dot: true, windows: false });
54
+ }
@@ -0,0 +1,36 @@
1
+ // jade/keys:快捷键的注册表。前端在输入框有焦点时按下自己不用的键,查这里找到插件的处理函数。
2
+ import { definePlugin } from "../../dist/api.js";
3
+ /** "ctrl+<字母>"、"alt+<字母或数字>" 或 "shift+tab" */
4
+ export const KEY_SPEC = /^(ctrl\+[a-z]|alt\+[a-z0-9]|shift\+tab)$/;
5
+ /**
6
+ * 前端自己用的键,插件不能用:编辑(ctrl+a/e/d/w/u/k,按词移动的 alt+f/b)、搜索历史(ctrl+r)、重画(ctrl+l)、展开(ctrl+o)、
7
+ * 中断和退出(ctrl+c),以及终端里等同于退格、Tab、回车的 ctrl+h/i/j/m
8
+ */
9
+ export const RESERVED_KEYS = new Set([..."acdehijklmoruw"].map((c) => `ctrl+${c}`).concat("alt+f", "alt+b"));
10
+ const registry = new Map();
11
+ export default definePlugin({
12
+ process(ctx) {
13
+ ctx.provide("keys@1", (caller) => ({
14
+ register(key) {
15
+ const spec = String(key?.key ?? "").toLowerCase();
16
+ if (!KEY_SPEC.test(spec))
17
+ throw new Error(`invalid key ${JSON.stringify(key?.key)}: use ctrl+<letter>, alt+<letter or digit> or shift+tab`);
18
+ if (RESERVED_KEYS.has(spec))
19
+ throw new Error(`key ${spec} is reserved by the frontend`);
20
+ const taken = registry.get(spec);
21
+ if (taken)
22
+ throw new Error(`key ${spec} is already registered by ${taken.plugin}`);
23
+ const entry = { key, plugin: caller.plugin };
24
+ registry.set(spec, entry);
25
+ const revoke = () => {
26
+ if (registry.get(spec) === entry)
27
+ registry.delete(spec);
28
+ };
29
+ caller.onDispose(revoke);
30
+ return revoke;
31
+ },
32
+ get: (spec) => registry.get(spec.toLowerCase()),
33
+ list: () => [...registry.entries()].map(([k, { key, plugin }]) => ({ key: k, ...(key.description ? { description: key.description } : {}), plugin })).sort((a, b) => a.key.localeCompare(b.key)),
34
+ }));
35
+ },
36
+ });
@@ -0,0 +1,9 @@
1
+ {
2
+ "id": "jade/keys",
3
+ "version": "0.1.0",
4
+ "api": "^1",
5
+ "entry": "./index.js",
6
+ "provides": [
7
+ "keys@1"
8
+ ]
9
+ }