@uncarved/jade 0.1.3 → 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 (450) hide show
  1. package/bin/jade.js +5 -27
  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 -30
  18. package/dist/index.js +11 -30
  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 +159 -1362
  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 +2 -0
  57. package/dist/update.js +6 -3
  58. package/dist/update.js.map +1 -1
  59. package/package.json +10 -8
  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 -100
  63. package/{src/plugins → plugins/approval}/review.ts +62 -16
  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 +48 -38
  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 +73 -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 +2 -2
  81. package/{src/tools → plugins/fs}/fs.ts +19 -42
  82. package/{src/tools → plugins/fs}/grep.ts +1 -1
  83. package/plugins/fs/index.ts +34 -0
  84. package/plugins/fs/plugin.json +7 -0
  85. package/{src/ui → plugins/fs}/renderers.ts +25 -70
  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 +16 -119
  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 +31 -20
  141. package/{src → plugins/shell}/sys.ts +2 -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 +3 -0
  155. package/plugins/tui/frontend.ts +596 -0
  156. package/plugins/tui/index.ts +37 -0
  157. package/plugins/tui/mentions.ts +113 -0
  158. package/plugins/tui/plugin.json +10 -0
  159. package/{src/ui → plugins/tui}/render.ts +8 -2
  160. package/{src/ui → plugins/tui}/screen.ts +8 -3
  161. package/{src/ui → plugins/tui}/transcript.ts +74 -99
  162. package/{src/ui/tui.tsx → plugins/tui/tui.ts} +358 -387
  163. package/{src/tools → plugins/undo}/checkpoint.ts +21 -60
  164. package/plugins/undo/index.ts +139 -0
  165. package/plugins/undo/notes.ts +43 -0
  166. package/plugins/undo/plugin.json +7 -0
  167. package/plugins/undo/style.ts +17 -0
  168. package/plugins/update/index.ts +40 -0
  169. package/plugins/update/plugin.json +13 -0
  170. package/plugins/web/env.ts +78 -0
  171. package/plugins/web/index.ts +133 -0
  172. package/plugins/web/plugin.json +15 -0
  173. package/plugins/web/renderers.ts +11 -0
  174. package/{src/tools → plugins/web}/web.ts +58 -26
  175. package/plugins-dist/approval/index.js +271 -0
  176. package/plugins-dist/approval/plugin.json +24 -0
  177. package/{dist/plugins → plugins-dist/approval}/policy.js +15 -81
  178. package/{dist/plugins → plugins-dist/approval}/review.js +56 -10
  179. package/{dist/plugins → plugins-dist/approval}/schema.js +0 -1
  180. package/plugins-dist/ask/index.js +145 -0
  181. package/plugins-dist/ask/plugin.json +12 -0
  182. package/plugins-dist/budget/index.js +37 -0
  183. package/plugins-dist/budget/plugin.json +15 -0
  184. package/{dist/plugins → plugins-dist/checks}/checks.js +46 -35
  185. package/plugins-dist/checks/index.js +150 -0
  186. package/plugins-dist/checks/plugin.json +21 -0
  187. package/plugins-dist/checks/project.js +76 -0
  188. package/plugins-dist/commands/index.js +33 -0
  189. package/plugins-dist/commands/plugin.json +9 -0
  190. package/{dist/plugins → plugins-dist/compact}/compact.js +51 -33
  191. package/plugins-dist/compact/index.js +100 -0
  192. package/plugins-dist/compact/plugin.json +25 -0
  193. package/plugins-dist/compact/style.js +14 -0
  194. package/plugins-dist/continue/index.js +57 -0
  195. package/plugins-dist/continue/plugin.json +15 -0
  196. package/{dist/ui → plugins-dist/fs}/diff.js +2 -3
  197. package/{dist/tools → plugins-dist/fs}/fs.js +17 -42
  198. package/{dist/tools → plugins-dist/fs}/grep.js +1 -2
  199. package/plugins-dist/fs/index.js +36 -0
  200. package/plugins-dist/fs/plugin.json +10 -0
  201. package/{dist/ui → plugins-dist/fs}/renderers.js +24 -61
  202. package/plugins-dist/fs/style.js +15 -0
  203. package/plugins-dist/fs/sys.js +54 -0
  204. package/plugins-dist/keys/index.js +36 -0
  205. package/plugins-dist/keys/plugin.json +9 -0
  206. package/plugins-dist/mcp/index.js +187 -0
  207. package/{dist → plugins-dist/mcp}/mcp.js +34 -30
  208. package/plugins-dist/mcp/plugin.json +12 -0
  209. package/plugins-dist/mcp/project.js +90 -0
  210. package/plugins-dist/memory/index.js +94 -0
  211. package/{dist → plugins-dist/memory}/memory.js +21 -3
  212. package/plugins-dist/memory/notes.js +36 -0
  213. package/plugins-dist/memory/plugin.json +11 -0
  214. package/plugins-dist/memory/style.js +14 -0
  215. package/plugins-dist/mentions/attach.js +120 -0
  216. package/plugins-dist/mentions/index.js +69 -0
  217. package/plugins-dist/mentions/plugin.json +9 -0
  218. package/plugins-dist/mentions/style.js +14 -0
  219. package/plugins-dist/models/config.js +53 -0
  220. package/plugins-dist/models/configure.js +415 -0
  221. package/plugins-dist/models/context.js +27 -0
  222. package/plugins-dist/models/index.js +167 -0
  223. package/plugins-dist/models/plugin.json +14 -0
  224. package/{dist → plugins-dist/models}/provider.js +18 -81
  225. package/plugins-dist/models/saved.js +80 -0
  226. package/plugins-dist/modes/index.js +190 -0
  227. package/plugins-dist/modes/plugin.json +18 -0
  228. package/plugins-dist/plugins/index.js +37 -0
  229. package/plugins-dist/plugins/plugin.json +10 -0
  230. package/plugins-dist/print/index.js +153 -0
  231. package/plugins-dist/print/plugin.json +14 -0
  232. package/plugins-dist/prompts/index.js +57 -0
  233. package/plugins-dist/prompts/plugin.json +13 -0
  234. package/plugins-dist/prompts/prompts.js +227 -0
  235. package/plugins-dist/prompts/sys.js +46 -0
  236. package/plugins-dist/renderers/index.js +36 -0
  237. package/plugins-dist/renderers/plugin.json +9 -0
  238. package/plugins-dist/repeats/index.js +165 -0
  239. package/plugins-dist/repeats/plugin.json +6 -0
  240. package/plugins-dist/schedule/cron.js +67 -0
  241. package/plugins-dist/schedule/index.js +281 -0
  242. package/plugins-dist/schedule/plugin.json +16 -0
  243. package/plugins-dist/schedule/store.js +125 -0
  244. package/plugins-dist/scratch/index.js +26 -0
  245. package/plugins-dist/scratch/plugin.json +10 -0
  246. package/plugins-dist/screenshot/index.js +35 -0
  247. package/plugins-dist/screenshot/plugin.json +11 -0
  248. package/plugins-dist/screenshot/sys.js +76 -0
  249. package/{dist/tools/screenshot.js → plugins-dist/screenshot/tool.js} +5 -4
  250. package/plugins-dist/sessions/index.js +136 -0
  251. package/plugins-dist/sessions/plugin.json +12 -0
  252. package/plugins-dist/shell/index.js +33 -0
  253. package/plugins-dist/shell/plugin.json +19 -0
  254. package/plugins-dist/shell/renderers.js +40 -0
  255. package/plugins-dist/shell/service.js +29 -0
  256. package/{dist/tools → plugins-dist/shell}/shell.js +31 -22
  257. package/{dist → plugins-dist/shell}/sys.js +2 -43
  258. package/plugins-dist/skills/index.js +90 -0
  259. package/plugins-dist/skills/plugin.json +12 -0
  260. package/plugins-dist/skills/project.js +47 -0
  261. package/{dist → plugins-dist/skills}/skills.js +3 -7
  262. package/plugins-dist/suggest/index.js +282 -0
  263. package/plugins-dist/suggest/plugin.json +23 -0
  264. package/plugins-dist/task/index.js +151 -0
  265. package/plugins-dist/task/plugin.json +23 -0
  266. package/plugins-dist/task/style.js +14 -0
  267. package/plugins-dist/task/subagent.js +208 -0
  268. package/{dist/tools/todo.js → plugins-dist/todo/index.js} +29 -7
  269. package/plugins-dist/todo/plugin.json +9 -0
  270. package/{dist/ui → plugins-dist/tui}/editor.js +3 -1
  271. package/plugins-dist/tui/frontend.js +586 -0
  272. package/{dist → plugins-dist/tui}/history.js +0 -1
  273. package/plugins-dist/tui/index.js +21 -0
  274. package/{dist/ui → plugins-dist/tui}/markdown.js +0 -1
  275. package/plugins-dist/tui/mentions.js +115 -0
  276. package/plugins-dist/tui/plugin.json +25 -0
  277. package/{dist/ui → plugins-dist/tui}/render.js +7 -3
  278. package/{dist/ui → plugins-dist/tui}/screen.js +6 -2
  279. package/{dist/ui → plugins-dist/tui}/transcript.js +76 -98
  280. package/{dist/ui → plugins-dist/tui}/tui.js +185 -53
  281. package/{dist/tools → plugins-dist/undo}/checkpoint.js +21 -55
  282. package/plugins-dist/undo/index.js +140 -0
  283. package/plugins-dist/undo/notes.js +36 -0
  284. package/plugins-dist/undo/plugin.json +9 -0
  285. package/plugins-dist/undo/style.js +14 -0
  286. package/plugins-dist/update/index.js +34 -0
  287. package/plugins-dist/update/plugin.json +15 -0
  288. package/plugins-dist/web/env.js +80 -0
  289. package/plugins-dist/web/index.js +124 -0
  290. package/plugins-dist/web/plugin.json +21 -0
  291. package/plugins-dist/web/renderers.js +7 -0
  292. package/{dist/tools → plugins-dist/web}/web.js +50 -24
  293. package/sdk/python/__pycache__/jade_plugin.cpython-312.pyc +0 -0
  294. package/sdk/python/jade_plugin.py +380 -0
  295. package/src/api.ts +298 -0
  296. package/src/config.ts +32 -134
  297. package/src/fetch.ts +216 -0
  298. package/src/hash.ts +39 -0
  299. package/src/host.ts +429 -0
  300. package/src/index.ts +23 -30
  301. package/src/install.ts +355 -0
  302. package/src/main.ts +155 -1387
  303. package/src/manifest.ts +160 -0
  304. package/src/membrane.ts +142 -0
  305. package/src/remote.ts +288 -0
  306. package/src/rescue.ts +217 -0
  307. package/src/resolve.ts +199 -0
  308. package/src/rpc.ts +144 -0
  309. package/src/secrets.ts +122 -0
  310. package/src/session.ts +458 -0
  311. package/src/source.ts +83 -0
  312. package/src/state.ts +120 -0
  313. package/src/update.ts +265 -262
  314. package/LICENSE +0 -21
  315. package/README.md +0 -204
  316. package/dist/commands.d.ts +0 -50
  317. package/dist/commands.js +0 -126
  318. package/dist/commands.js.map +0 -1
  319. package/dist/context.d.ts +0 -17
  320. package/dist/context.js +0 -53
  321. package/dist/context.js.map +0 -1
  322. package/dist/distro.d.ts +0 -141
  323. package/dist/distro.js +0 -462
  324. package/dist/distro.js.map +0 -1
  325. package/dist/history.d.ts +0 -10
  326. package/dist/history.js.map +0 -1
  327. package/dist/mcp.d.ts +0 -114
  328. package/dist/mcp.js.map +0 -1
  329. package/dist/memory.d.ts +0 -19
  330. package/dist/memory.js.map +0 -1
  331. package/dist/mentions.d.ts +0 -35
  332. package/dist/mentions.js +0 -130
  333. package/dist/mentions.js.map +0 -1
  334. package/dist/plugin-cli.d.ts +0 -16
  335. package/dist/plugin-cli.js +0 -294
  336. package/dist/plugin-cli.js.map +0 -1
  337. package/dist/plugins/budget.d.ts +0 -9
  338. package/dist/plugins/budget.js +0 -30
  339. package/dist/plugins/budget.js.map +0 -1
  340. package/dist/plugins/builtins.d.ts +0 -10
  341. package/dist/plugins/builtins.js +0 -25
  342. package/dist/plugins/builtins.js.map +0 -1
  343. package/dist/plugins/checks.d.ts +0 -71
  344. package/dist/plugins/checks.js.map +0 -1
  345. package/dist/plugins/compact.d.ts +0 -26
  346. package/dist/plugins/compact.js.map +0 -1
  347. package/dist/plugins/core.d.ts +0 -47
  348. package/dist/plugins/core.js +0 -229
  349. package/dist/plugins/core.js.map +0 -1
  350. package/dist/plugins/host.d.ts +0 -52
  351. package/dist/plugins/host.js +0 -115
  352. package/dist/plugins/host.js.map +0 -1
  353. package/dist/plugins/install.d.ts +0 -68
  354. package/dist/plugins/install.js +0 -377
  355. package/dist/plugins/install.js.map +0 -1
  356. package/dist/plugins/loader.d.ts +0 -410
  357. package/dist/plugins/loader.js +0 -407
  358. package/dist/plugins/loader.js.map +0 -1
  359. package/dist/plugins/policy.d.ts +0 -98
  360. package/dist/plugins/policy.js.map +0 -1
  361. package/dist/plugins/prompts.d.ts +0 -43
  362. package/dist/plugins/prompts.js +0 -284
  363. package/dist/plugins/prompts.js.map +0 -1
  364. package/dist/plugins/repeats.d.ts +0 -16
  365. package/dist/plugins/repeats.js +0 -151
  366. package/dist/plugins/repeats.js.map +0 -1
  367. package/dist/plugins/review.d.ts +0 -18
  368. package/dist/plugins/review.js.map +0 -1
  369. package/dist/plugins/schema.d.ts +0 -2
  370. package/dist/plugins/schema.js.map +0 -1
  371. package/dist/plugins/sessions.d.ts +0 -7
  372. package/dist/plugins/sessions.js +0 -110
  373. package/dist/plugins/sessions.js.map +0 -1
  374. package/dist/provider.d.ts +0 -165
  375. package/dist/provider.js.map +0 -1
  376. package/dist/session-lifecycle.d.ts +0 -61
  377. package/dist/session-lifecycle.js +0 -167
  378. package/dist/session-lifecycle.js.map +0 -1
  379. package/dist/session-scope.d.ts +0 -53
  380. package/dist/session-scope.js +0 -116
  381. package/dist/session-scope.js.map +0 -1
  382. package/dist/sessions.d.ts +0 -28
  383. package/dist/sessions.js +0 -73
  384. package/dist/sessions.js.map +0 -1
  385. package/dist/skills.d.ts +0 -37
  386. package/dist/skills.js.map +0 -1
  387. package/dist/sys.d.ts +0 -51
  388. package/dist/sys.js.map +0 -1
  389. package/dist/tools/ask.d.ts +0 -11
  390. package/dist/tools/ask.js +0 -62
  391. package/dist/tools/ask.js.map +0 -1
  392. package/dist/tools/checkpoint.d.ts +0 -43
  393. package/dist/tools/checkpoint.js.map +0 -1
  394. package/dist/tools/fs.d.ts +0 -39
  395. package/dist/tools/fs.js.map +0 -1
  396. package/dist/tools/grep.d.ts +0 -6
  397. package/dist/tools/grep.js.map +0 -1
  398. package/dist/tools/screenshot.d.ts +0 -15
  399. package/dist/tools/screenshot.js.map +0 -1
  400. package/dist/tools/shell.d.ts +0 -55
  401. package/dist/tools/shell.js.map +0 -1
  402. package/dist/tools/task.d.ts +0 -39
  403. package/dist/tools/task.js +0 -117
  404. package/dist/tools/task.js.map +0 -1
  405. package/dist/tools/todo.d.ts +0 -10
  406. package/dist/tools/todo.js.map +0 -1
  407. package/dist/tools/web.d.ts +0 -53
  408. package/dist/tools/web.js.map +0 -1
  409. package/dist/ui/configure.d.ts +0 -20
  410. package/dist/ui/configure.js +0 -447
  411. package/dist/ui/configure.js.map +0 -1
  412. package/dist/ui/diff.d.ts +0 -20
  413. package/dist/ui/diff.js.map +0 -1
  414. package/dist/ui/editor.d.ts +0 -41
  415. package/dist/ui/editor.js.map +0 -1
  416. package/dist/ui/markdown.d.ts +0 -22
  417. package/dist/ui/markdown.js.map +0 -1
  418. package/dist/ui/render.d.ts +0 -14
  419. package/dist/ui/render.js.map +0 -1
  420. package/dist/ui/renderers.d.ts +0 -8
  421. package/dist/ui/renderers.js.map +0 -1
  422. package/dist/ui/screen.d.ts +0 -118
  423. package/dist/ui/screen.js.map +0 -1
  424. package/dist/ui/transcript.d.ts +0 -46
  425. package/dist/ui/transcript.js.map +0 -1
  426. package/dist/ui/tui.d.ts +0 -47
  427. package/dist/ui/tui.js.map +0 -1
  428. package/src/commands.ts +0 -144
  429. package/src/context.ts +0 -64
  430. package/src/distro.ts +0 -577
  431. package/src/mentions.ts +0 -135
  432. package/src/plugin-cli.ts +0 -278
  433. package/src/plugins/budget.ts +0 -37
  434. package/src/plugins/builtins.ts +0 -34
  435. package/src/plugins/core.ts +0 -257
  436. package/src/plugins/host.ts +0 -146
  437. package/src/plugins/install.ts +0 -429
  438. package/src/plugins/loader.ts +0 -742
  439. package/src/plugins/prompts.ts +0 -327
  440. package/src/plugins/repeats.ts +0 -157
  441. package/src/plugins/sessions.ts +0 -109
  442. package/src/session-lifecycle.ts +0 -194
  443. package/src/session-scope.ts +0 -135
  444. package/src/sessions.ts +0 -78
  445. package/src/tools/ask.ts +0 -72
  446. package/src/tools/task.ts +0 -149
  447. package/src/ui/configure.ts +0 -471
  448. /package/{src/plugins → plugins/approval}/schema.ts +0 -0
  449. /package/{src → plugins/tui}/history.ts +0 -0
  450. /package/{src/ui → plugins/tui}/markdown.ts +0 -0
@@ -0,0 +1,115 @@
1
+ // jade/compact:历史接近上下文窗口时压缩投影(见 compact.ts);/compact 让下一次请求前总结一次;
2
+ // 请求因为超出上下文窗口失败时,压缩后用 { kind: "retry" } 重试一次(session.afterTurn,设计 4.3)。
3
+
4
+ import type { LogEvent } from "uncarved";
5
+ import { definePlugin, type UI } from "../../src/api.ts";
6
+ import type { Commands } from "../commands/index.ts";
7
+ import type { Models } from "../models/index.ts";
8
+ import type { Renderers } from "../renderers/index.ts";
9
+ import { compactor, compactThreshold, isContextOverflow, parseTokens } from "./compact.ts";
10
+ import { dim } from "./style.ts";
11
+
12
+ /** 认不出窗口时的阈值 */
13
+ const FALLBACK_THRESHOLD = 120_000;
14
+ /** Claude 默认的回复上限,阈值要给它留出位置 */
15
+ const ANTHROPIC_REPLY_TOKENS = 64_000;
16
+ /** 总结要调用模型,比 hook 默认的 30 秒长 */
17
+ const SUMMARY_TIMEOUT_MS = 300_000;
18
+
19
+ /** compact@1 */
20
+ export interface Compact {
21
+ /** 历史超过这么多 token 时自动压缩(界面显示用) */
22
+ threshold(): number;
23
+ }
24
+
25
+ /** 自动压缩的阈值:配置的 thresholdTokens,否则按当前模型的上下文窗口算 */
26
+ function thresholdFor(config: Record<string, unknown>, models: Models): () => number {
27
+ const configured = parseTokens(config.thresholdTokens);
28
+ return () => {
29
+ if (configured) return configured;
30
+ const m = models.current();
31
+ // 别的模型插件可能不给窗口(或给错)
32
+ if (!m || !(typeof m.contextWindow === "number" && m.contextWindow > 0)) return FALLBACK_THRESHOLD;
33
+ return compactThreshold(m.contextWindow, m.kind === "anthropic" ? ANTHROPIC_REPLY_TOKENS : 0);
34
+ };
35
+ }
36
+
37
+ /** /compact 请求过的会话:下一次投影时无论是否超过阈值都总结一次 */
38
+ const requested = new Set<string>();
39
+
40
+ export default definePlugin({
41
+ process(ctx) {
42
+ ctx.provide("compact@1", { threshold: thresholdFor(ctx.config, ctx.require<Models>("models@1")) } satisfies Compact);
43
+ const commands = ctx.service<Commands>("commands@1");
44
+ commands?.register({
45
+ name: "compact",
46
+ description: "compact the history before the next request",
47
+ run(_args, c) {
48
+ const s = c.sessions.current;
49
+ if (!s) return "No session is open.";
50
+ requested.add(s.id);
51
+ return dim("History will be compacted before the next request.");
52
+ },
53
+ });
54
+ const renderers = ctx.service<Renderers>("renderers@1");
55
+ if (renderers) {
56
+ renderers.event({
57
+ event: "compacted",
58
+ render: (data) => {
59
+ const d = data as { from: number; upTo: number; before: number };
60
+ return { line: dim(`[compacted ${d.upTo - d.from} messages, ~${d.before} tokens before]`) };
61
+ },
62
+ });
63
+ renderers.event({ event: "trimmed", render: (data) => ({ line: dim(`[cleared old tool output, ~${(data as { saved: number }).saved} tokens]`) }) });
64
+ }
65
+ },
66
+
67
+ session(ctx) {
68
+ const models = ctx.require<Models>("models@1");
69
+ const configured = parseTokens(ctx.config.thresholdTokens);
70
+ const keepTokens = parseTokens(ctx.config.keepTokens);
71
+ const threshold = thresholdFor(ctx.config, models);
72
+ const c = compactor({ complete: (req, o) => models.complete(req, o), threshold, keepTokens, id: ctx.plugin });
73
+ const id = ctx.session.id;
74
+
75
+ ctx.kernel.hook({
76
+ kind: "transform",
77
+ point: "context.project",
78
+ // 排在其他改投影的插件(例如 jade/mentions 附上引用的文件)之后:估算的是最终的投影
79
+ order: 100,
80
+ timeoutMs: SUMMARY_TIMEOUT_MS,
81
+ fn: (messages, hook) => {
82
+ if (requested.delete(id)) c.request();
83
+ return c.project(messages, hook);
84
+ },
85
+ });
86
+
87
+ // 上下文溢出后压缩重试,每次用户输入只重试一次
88
+ let retried = false;
89
+ ctx.kernel.hook({
90
+ kind: "observe",
91
+ point: "event",
92
+ fn: (e: LogEvent) => {
93
+ c.observe(e);
94
+ if (e.type === "input.received" && (e.data as { kind: string }).kind === "message") retried = false;
95
+ if (e.type !== "turn.ended") return;
96
+ const d = (e as LogEvent<"turn.ended">).data;
97
+ if (d.reason !== "error" || retried || !isContextOverflow(d.error)) return;
98
+ retried = true;
99
+ c.request();
100
+ const ui = ctx.service<UI>("ui@1");
101
+ const window = models.current()?.contextWindow;
102
+ ui?.notify(
103
+ "the request exceeded the model's context window; compacting the history and retrying" +
104
+ (configured || !window ? "" : ` (jade assumed a ${window}-token window; set the real one with JADE_CONTEXT_WINDOW)`),
105
+ "warning",
106
+ );
107
+ // 不能在这里等 send:它要等这一轮结束,而这一轮在等这个 hook
108
+ ctx.session.afterTurn(() => {
109
+ ctx.session.send({ kind: "retry" }).catch((err: unknown) => ctx.signal.aborted || ui?.notify(`retry after compaction failed: ${err instanceof Error ? err.message : String(err)}`, "error"));
110
+ });
111
+ },
112
+ });
113
+ },
114
+ });
115
+
@@ -0,0 +1,17 @@
1
+ {
2
+ "id": "jade/compact",
3
+ "version": "0.3.0",
4
+ "api": "^1",
5
+ "entry": "./index.ts",
6
+ "provides": ["compact@1"],
7
+ "requires": ["models@1"],
8
+ "optional": ["commands@1", "renderers@1", "ui@1"],
9
+ "config": {
10
+ "thresholdTokens": {
11
+ "description": "compact when the history reaches this many tokens (a number or e.g. \"120k\"); default: 80% of the model's context window, leaving room for the reply"
12
+ },
13
+ "keepTokens": {
14
+ "description": "after compacting, keep about this many tokens of the most recent messages verbatim; default 30% of the threshold"
15
+ }
16
+ }
17
+ }
@@ -0,0 +1,17 @@
1
+ // 显示用的小工具:截断和 ANSI 颜色。插件之间不共享代码(只能共享类型),所以这里也有一份(同 jade/fs 的 style.ts)。
2
+
3
+ export const clip = (s: string, n: number) => (s.length > n ? s.slice(0, n) + "…" : s);
4
+
5
+ // 设了 NO_COLOR(非空)或标准输出不是终端时不输出颜色,见 https://no-color.org
6
+ const colors = Boolean(process.stdout.isTTY) && !process.env.NO_COLOR;
7
+ /**
8
+ * 每种样式用自己的关闭码,不用 \x1b[0m 全部重置:外面套着别的样式时,后面的文字仍保持外层样式。
9
+ * 里面出现同一个关闭码(例如 dim 里套 bold,两者都用 22 关闭)时紧接着重新打开外层的样式
10
+ */
11
+ const paint = (open: string, close: string) => (s: string) =>
12
+ colors ? `\x1b[${open}m${s.replaceAll(`\x1b[${close}m`, `\x1b[${close}m\x1b[${open}m`)}\x1b[${close}m` : s;
13
+ export const dim = paint("2", "22");
14
+ export const red = paint("31", "39");
15
+ export const green = paint("32", "39");
16
+ export const yellow = paint("33", "39");
17
+ export const bold = paint("1", "22");
@@ -0,0 +1,58 @@
1
+ // jade/continue:模型的回复被输出上限截断(这一轮以 max_tokens 结束)时,让模型接着做,而不是把半截任务丢给用户。
2
+ //
3
+ // 从 turn.ended 事件知道这一轮怎么结束的(observe event),在 session.afterTurn 里用 session.send 发一条 [Note from jade]。
4
+ // 每次用户输入之后最多续写 maxContinues 次。从旧 jade 的 plugins/turns.ts 的 continueTurns 移植。
5
+ //
6
+ // 旧 jade 的"上下文溢出后压缩重试"不在这里:不压缩就重试只会再溢出一次,整件事归 jade/compact。
7
+
8
+ import type { Block, UserInput } from "uncarved";
9
+ import { definePlugin, type UI } from "../../src/api.ts";
10
+
11
+ export const DEFAULT_CONTINUES = 3;
12
+ export const CONTINUE_NOTE =
13
+ "Your previous reply was cut off because it reached the output token limit. Continue from where you stopped. " +
14
+ "If you were writing a large file or edit, split it into several smaller write_file/edit_file calls.";
15
+
16
+ export default definePlugin({
17
+ session(ctx) {
18
+ const ui = ctx.service<UI>("ui@1");
19
+ const raw = ctx.config.maxContinues;
20
+ let max = DEFAULT_CONTINUES;
21
+ if (typeof raw === "number" && Number.isInteger(raw) && raw >= 0) max = raw;
22
+ else if (raw !== undefined) ui?.notify(`jade/continue: maxContinues must be a non-negative integer, got ${JSON.stringify(raw)}; using ${DEFAULT_CONTINUES}`, "warning");
23
+
24
+ /** 这次用户输入之后已经续写了几次 */
25
+ let count = 0;
26
+ /** 我们发出、还没收到的续写;收到它不算用户的新输入 */
27
+ let pending: Block | undefined;
28
+
29
+ const note = (): Block => ({ kind: "text", text: `[Note from jade] ${CONTINUE_NOTE}`, origin: { by: "plugin", id: ctx.plugin }, trust: "trusted" });
30
+
31
+ ctx.kernel.hook({
32
+ kind: "observe",
33
+ point: "event",
34
+ fn: (e) => {
35
+ if (e.type === "input.received") {
36
+ const input = e.data as UserInput;
37
+ // 用户(或别的插件替用户)发的新消息:重新计数。/retry、审批不算新输入
38
+ if (input.kind !== "message") return;
39
+ const ours = pending !== undefined && input.content.length === 1 && input.content[0]!.kind === "text" && input.content[0]!.origin.by === "plugin" && input.content[0]!.origin.id === ctx.plugin;
40
+ if (ours) pending = undefined;
41
+ else count = 0;
42
+ return;
43
+ }
44
+ if (e.type !== "turn.ended") return;
45
+ if ((e.data as { reason?: unknown }).reason !== "max_tokens" || count >= max) return;
46
+ count++;
47
+ const n = count;
48
+ // 本轮完全结束之后再发:现在发会排在本轮之后,但 send 要等本轮结束,不能在 hook 里等
49
+ ctx.session.afterTurn(() => {
50
+ ui?.notify(`[asking the model to continue (${n}/${max})]`);
51
+ pending = note();
52
+ // 不能 await:afterTurn 跑完之后会话才处理排队的输入。出错时前端从 turn.ended 显示原因
53
+ ctx.session.send({ kind: "message", content: [pending] }).catch(() => {});
54
+ });
55
+ },
56
+ });
57
+ },
58
+ });
@@ -0,0 +1,13 @@
1
+ {
2
+ "id": "jade/continue",
3
+ "version": "0.2.0",
4
+ "api": "^1",
5
+ "entry": "./index.ts",
6
+ "optional": ["ui@1"],
7
+ "config": {
8
+ "maxContinues": {
9
+ "default": 3,
10
+ "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"
11
+ }
12
+ }
13
+ }
@@ -1,9 +1,9 @@
1
- // 按行比较两段文本,生成带行号和上下文的 unified diff,审批修改时显示。
1
+ // 按行比较两段文本,生成带行号和上下文的 unified diff:审批修改时的预览、对话里修改结果的展开内容。从旧 jade 的 ui/diff.ts 移植。
2
2
  //
3
3
  // 先去掉相同的开头和结尾,只对中间部分求最长公共子序列;中间部分太大时(整个文件重写)
4
4
  // 不再逐行比较,整段显示为删除加新增,避免占用大量内存和时间。
5
5
 
6
- import { dim, green, red } from "./screen.ts";
6
+ import { dim, green, red } from "./style.ts";
7
7
 
8
8
  export type DiffLine = { kind: " " | "-" | "+"; text: string; /** 旧文件里的行号(删除、相同) */ old?: number; /** 新文件里的行号(新增、相同) */ new?: number };
9
9
 
@@ -1,7 +1,6 @@
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
  // 否则模型是按过时的内容在改,会覆盖掉别人的修改。和修改在同一次回复里发出的读取不算:
@@ -11,9 +10,8 @@ import type { Stats } from "node:fs";
11
10
  import { mkdir, readdir, readFile, stat, writeFile } from "node:fs/promises";
12
11
  import path from "node:path";
13
12
  import type { Block, Tool } from "uncarved";
14
- import { sha256, type Checkpoints } from "./checkpoint.ts";
15
13
  import { grepTool } from "./grep.ts";
16
- import { globMatcher, run } from "../sys.ts";
14
+ import { globMatcher, run } from "./sys.ts";
17
15
 
18
16
  const MAX_LINES = 2000;
19
17
  const MAX_LINE_CHARS = 2000;
@@ -47,17 +45,13 @@ export function display(cwd: string, full: string): string {
47
45
  }
48
46
 
49
47
  export interface FsOptions {
50
- /** 给了就在每次写入前保存原内容,供撤销;也用它记下读过的文件,恢复会话后不用重新读 */
51
- checkpoints?: Checkpoints;
52
- /** 模型调用的次数,每次调用模型前加一(见 distro 的 model.before hook)。不给就不检查同一次回复里的先读后改 */
48
+ /** 模型调用的次数,每次调用模型前加一(见 index.ts 的 model.before hook)。不给就不检查同一次回复里的先读后改 */
53
49
  responses?: { readonly calls: number };
54
50
  /** grep 用的 ripgrep,默认 "rg";null 表示不用(测试) */
55
51
  rg?: string | null;
56
- /** 会话的临时目录:里面的文件只有模型自己会写(包括它跑的命令生成的),修改前不用先读 */
57
- scratch?: string;
58
52
  }
59
53
 
60
- /** 读过或写过的文件当时的样子;只在本进程内有效,恢复的会话靠 checkpoints 里记的 sha256 */
54
+ /** 读过或写过的文件当时的样子;只在本会话、本进程内有效,恢复的会话要重新读 */
61
55
  interface Seen {
62
56
  mtimeMs: number;
63
57
  size: number;
@@ -68,21 +62,14 @@ interface Seen {
68
62
  export function fsTools(cwd: string, opts: FsOptions = {}): Tool[] {
69
63
  const at = (p: unknown) => resolveIn(cwd, p as string);
70
64
  const seen = new Map<string, Seen>();
71
- const inScratch = (full: string) => {
72
- if (opts.scratch === undefined) return false;
73
- const rel = path.relative(opts.scratch, full);
74
- return rel !== "" && rel !== ".." && !rel.startsWith(`..${path.sep}`) && !path.isAbsolute(rel);
75
- };
76
65
  /** 文件没变时保留更早的 call:之前的回复里读过,这次回复里又读一遍,不影响修改 */
77
- const remember = async (ctx: { sessionId: string }, full: string, info: Stats, text: string, call: number) => {
66
+ const remember = (full: string, info: Stats, call: number) => {
78
67
  const s = seen.get(full);
79
68
  const same = s !== undefined && s.mtimeMs === info.mtimeMs && s.size === info.size;
80
69
  seen.set(full, { mtimeMs: info.mtimeMs, size: info.size, call: same ? Math.min(s.call, call) : call });
81
- await opts.checkpoints?.markSeen(ctx.sessionId, full, sha256(text));
82
70
  };
83
71
  /** 不能修改已有文件的原因;可以修改时返回 undefined。text 是文件现在的内容 */
84
- const staleness = async (ctx: { sessionId: string }, full: string, info: Stats, text: string): Promise<string | undefined> => {
85
- if (inScratch(full)) return undefined;
72
+ const staleness = (full: string, info: Stats): string | undefined => {
86
73
  const shown = display(cwd, full);
87
74
  const modified = `${shown} has been modified since it was last read (by the user or a command). Read it again before changing it.`;
88
75
  const s = seen.get(full);
@@ -93,15 +80,7 @@ export function fsTools(cwd: string, opts: FsOptions = {}): Tool[] {
93
80
  }
94
81
  return undefined;
95
82
  }
96
- // 恢复的会话:之前的进程里读过或写过
97
- const hash = await opts.checkpoints?.seenHash(ctx.sessionId, full);
98
- if (hash === undefined) return `${shown} exists but has not been read in this session. Read it with read_file before changing it.`;
99
- if (hash !== sha256(text)) return modified;
100
- seen.set(full, { mtimeMs: info.mtimeMs, size: info.size, call: -1 });
101
- return undefined;
102
- };
103
- const checkpoint = async (ctx: { sessionId: string; toolUseId: string }, tool: string, full: string, before: string | null, after: string) => {
104
- await opts.checkpoints?.save(ctx.sessionId, { toolUseId: ctx.toolUseId, tool, path: full, before, afterHash: sha256(after) });
83
+ return `${shown} exists but has not been read in this session. Read it with read_file before changing it.`;
105
84
  };
106
85
 
107
86
  const readFileTool: Tool = {
@@ -119,7 +98,7 @@ export function fsTools(cwd: string, opts: FsOptions = {}): Tool[] {
119
98
  effect: "read",
120
99
  concurrency: "safe",
121
100
  idempotent: true,
122
- async execute(input, ctx) {
101
+ async execute(input) {
123
102
  const { path: p, offset = 1, limit = MAX_LINES } = input as { path: string; offset?: number; limit?: number };
124
103
  if (limit < 1) return { content: "limit must be at least 1", isError: true };
125
104
  const full = at(p);
@@ -151,7 +130,7 @@ export function fsTools(cwd: string, opts: FsOptions = {}): Tool[] {
151
130
  return { content: `${display(cwd, full)} is a binary file (${buf.length} bytes) and cannot be shown as text`, isError: true };
152
131
  }
153
132
  const text = buf.toString("utf8");
154
- await remember(ctx, full, info, text, opts.responses?.calls ?? -1);
133
+ remember(full, info, opts.responses?.calls ?? -1);
155
134
  if (text.length === 0) return { content: "(empty file)" };
156
135
  const lines = text.split(/\r?\n/);
157
136
  if (lines.at(-1) === "") lines.pop();
@@ -191,7 +170,7 @@ export function fsTools(cwd: string, opts: FsOptions = {}): Tool[] {
191
170
  concurrency: "exclusive",
192
171
  // 写入完整内容,重复执行结果相同
193
172
  idempotent: true,
194
- async execute(input, ctx) {
173
+ async execute(input) {
195
174
  const { path: p, content: given } = input as { path: string; content: string };
196
175
  const full = at(p);
197
176
  const info = await statOrUndefined(full);
@@ -200,12 +179,11 @@ export function fsTools(cwd: string, opts: FsOptions = {}): Tool[] {
200
179
  const before = info ? await readFile(full, "utf8") : null;
201
180
  // read_file 不显示换行风格和 BOM:覆盖已有文件时沿用原来的,否则整个文件每一行都算改了
202
181
  const content = before === null ? given : keepStyle(before, given);
203
- const problem = info && before !== null && before !== content ? await staleness(ctx, full, info, before) : undefined;
182
+ const problem = info && before !== null && before !== content ? staleness(full, info) : undefined;
204
183
  if (problem) return { content: problem, isError: true };
205
184
  await mkdir(path.dirname(full), { recursive: true });
206
185
  await writeFile(full, content);
207
- await remember(ctx, full, await stat(full), content, -1);
208
- if (before !== content) await checkpoint(ctx, "write_file", full, before, content);
186
+ remember(full, await stat(full), -1);
209
187
  // 和 read_file 一样数行:末尾的换行不算多出一行
210
188
  const lines = content === "" ? 0 : content.split(/\r?\n/).length - (/\r?\n$/.test(content) ? 1 : 0);
211
189
  return { content: `Wrote ${lines} lines to ${display(cwd, full)}` };
@@ -213,7 +191,7 @@ export function fsTools(cwd: string, opts: FsOptions = {}): Tool[] {
213
191
  };
214
192
 
215
193
  /** edit_file 和 multi_edit 共用:检查文件能否修改,按顺序应用全部替换,全部成功才写入 */
216
- const applyEdits = async (ctx: { sessionId: string; toolUseId: string }, tool: string, p: string, edits: Edit[]) => {
194
+ const applyEdits = async (p: string, edits: Edit[]) => {
217
195
  const full = at(p);
218
196
  const shown = display(cwd, full);
219
197
  const info = await statOrUndefined(full);
@@ -221,7 +199,7 @@ export function fsTools(cwd: string, opts: FsOptions = {}): Tool[] {
221
199
  return { content: seen.has(full) ? `${shown} no longer exists` : `${shown} does not exist; use write_file to create it`, isError: true };
222
200
  }
223
201
  const text = await readFile(full, "utf8");
224
- const problem = await staleness(ctx, full, info, text);
202
+ const problem = staleness(full, info);
225
203
  if (problem) return { content: problem, isError: true };
226
204
  let next = text;
227
205
  let total = 0;
@@ -232,8 +210,7 @@ export function fsTools(cwd: string, opts: FsOptions = {}): Tool[] {
232
210
  total += r.count;
233
211
  }
234
212
  await writeFile(full, next);
235
- await remember(ctx, full, await stat(full), next, -1);
236
- await checkpoint(ctx, tool, full, text, next);
213
+ remember(full, await stat(full), -1);
237
214
  return { content: `Edited ${shown} (${total} replacement${total === 1 ? "" : "s"})` };
238
215
  };
239
216
 
@@ -253,9 +230,9 @@ export function fsTools(cwd: string, opts: FsOptions = {}): Tool[] {
253
230
  concurrency: "exclusive",
254
231
  // 第二次执行时 old_string 可能已经不存在,或者被替换两次
255
232
  idempotent: false,
256
- async execute(input, ctx) {
233
+ async execute(input) {
257
234
  const { path: p, ...edit } = input as { path: string } & Edit;
258
- return applyEdits(ctx, "edit_file", p, [edit]);
235
+ return applyEdits(p, [edit]);
259
236
  },
260
237
  };
261
238
 
@@ -284,10 +261,10 @@ export function fsTools(cwd: string, opts: FsOptions = {}): Tool[] {
284
261
  effect: "write",
285
262
  concurrency: "exclusive",
286
263
  idempotent: false,
287
- async execute(input, ctx) {
264
+ async execute(input) {
288
265
  const { path: p, edits } = input as { path: string; edits: Edit[] };
289
266
  if (edits.length === 0) return { content: "edits must not be empty", isError: true };
290
- return applyEdits(ctx, "multi_edit", p, edits);
267
+ return applyEdits(p, edits);
291
268
  },
292
269
  };
293
270
 
@@ -8,7 +8,7 @@ import { readFile, stat } from "node:fs/promises";
8
8
  import path from "node:path";
9
9
  import type { Tool } from "uncarved";
10
10
  import { display, listFiles, statOrUndefined } from "./fs.ts";
11
- import { globMatcher, spawn, text, type Proc } from "../sys.ts";
11
+ import { globMatcher, spawn, text, type Proc } from "./sys.ts";
12
12
 
13
13
  const MAX_MATCHES = 200;
14
14
  const MAX_FILES = 500;
@@ -0,0 +1,34 @@
1
+ // jade/fs:文件工具 read_file、write_file、edit_file、multi_edit、list_dir、glob、grep。
2
+
3
+ import { definePlugin } from "../../src/api.ts";
4
+ import type { Renderers } from "../renderers/index.ts";
5
+ import type { Task } from "../task/index.ts";
6
+ import { fsTools } from "./fs.ts";
7
+ import { fsRenderers } from "./renderers.ts";
8
+
9
+ export default definePlugin({
10
+ process(ctx) {
11
+ // 显示方式和会话无关,登记一次留到进程结束;没有 renderers@1(例如 print)时用前端的默认显示
12
+ const renderers = ctx.service<Renderers>("renderers@1");
13
+ if (renderers) for (const r of fsRenderers(ctx.cwd)) renderers.tool(r);
14
+ },
15
+
16
+ session(ctx) {
17
+ // 数模型调用的次数:同一次回复里先读后改的,改的内容是看到读取结果之前写好的
18
+ const responses = { calls: 0 };
19
+ ctx.kernel.hook({
20
+ kind: "transform",
21
+ point: "model.before",
22
+ fn: () => {
23
+ responses.calls++;
24
+ },
25
+ });
26
+ for (const tool of fsTools(ctx.cwd, { responses })) ctx.kernel.tool(tool);
27
+ // 子 Agent(jade/task)的只读工具:另一套实例,子 Agent 读过的文件不算主会话读过
28
+ // jade/task 被隔离时它的服务已失效:子 Agent 没有文件工具,文件工具本身照常
29
+ try {
30
+ const task = ctx.service<Task>("task@1");
31
+ if (task) for (const tool of fsTools(ctx.cwd)) if (tool.effect === "read") task.tool(tool);
32
+ } catch {}
33
+ },
34
+ });
@@ -0,0 +1,7 @@
1
+ {
2
+ "id": "jade/fs",
3
+ "version": "0.2.0",
4
+ "api": "^1",
5
+ "entry": "./index.ts",
6
+ "optional": ["renderers@1", "task@1"]
7
+ }
@@ -1,18 +1,24 @@
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
 
4
6
  import { readFileSync } from "node:fs";
5
7
  import { readFile } from "node:fs/promises";
6
8
  import path from "node:path";
7
- import type { ToolRenderer } from "../plugins/loader.ts";
8
- import { applyEditsToText, display, type Edit } from "../tools/fs.ts";
9
+ import type { ToolRenderer } from "../renderers/index.ts";
9
10
  import { diffLines, diffStats, renderDiff } from "./diff.ts";
10
- import { clip } from "./render.ts";
11
- import { dim, green, red, yellow } from "./screen.ts";
11
+ import { applyEditsToText, display, type Edit } from "./fs.ts";
12
+ import { clip, dim, green, red, yellow } from "./style.ts";
12
13
 
13
14
  type Args = Record<string, unknown>;
14
- const args = (input: unknown) => (input ?? {}) as Args;
15
- const pathOf = (cwd: string, i: Args) => (typeof i.path === "string" ? display(cwd, i.path) : "");
15
+ const args = (input: unknown) => (input !== null && typeof input === "object" ? input : {}) as Args;
16
+ /** 显示用的路径;工作目录本身显示成 "."(display 对它给的是绝对路径,审批插件会把 "." 换成工作目录) */
17
+ function pathOf(cwd: string, i: Args): string {
18
+ if (typeof i.path !== "string") return "";
19
+ const full = path.resolve(cwd, i.path);
20
+ return path.relative(cwd, full) === "" ? "." : display(cwd, full);
21
+ }
16
22
 
17
23
  /** 预览里的多行文字:每行前面加上标记,最多 max 行 */
18
24
  function marked(s: string, mark: string, color: (s: string) => string, max = 30): string {
@@ -22,15 +28,13 @@ function marked(s: string, mark: string, color: (s: string) => string, max = 30)
22
28
  return shown.join("\n");
23
29
  }
24
30
 
25
- /** 折叠内容里的多行文字(缩进由 transcript 加),最多 max 行 */
31
+ /** 折叠内容里的多行文字(缩进由前端加),最多 max 行 */
26
32
  function capped(lines: string[], color: (s: string) => string, max: number): string {
27
33
  const shown = lines.slice(0, max).map(color);
28
34
  if (lines.length > max) shown.push(dim(`… ${lines.length - max} more lines`));
29
35
  return shown.join("\n");
30
36
  }
31
37
 
32
- // ---------- 文件 ----------
33
-
34
38
  type FileTool = "edit_file" | "multi_edit" | "write_file";
35
39
  const editsOf = (tool: FileTool, i: Args) => (tool === "edit_file" ? [i] : Array.isArray(i.edits) ? i.edits : []) as unknown as Edit[];
36
40
 
@@ -70,7 +74,7 @@ const MAX_RESULT_LINES = 2000;
70
74
 
71
75
  /**
72
76
  * 执行前后的差异。在工具执行之前调用(读的是修改前的文件),同步读文件:
73
- * 执行前的事件通知是同步的,等异步读完文件可能已经改了。替换不成立时返回 undefined
77
+ * 执行前的通知是同步的,等异步读完文件可能已经改了。替换不成立时返回 undefined
74
78
  */
75
79
  function fileDiff(cwd: string, tool: FileTool, input: unknown): FileDiff | undefined {
76
80
  const i = args(input);
@@ -95,7 +99,7 @@ function fileDiff(cwd: string, tool: FileTool, input: unknown): FileDiff | undef
95
99
  }
96
100
 
97
101
  /** 修改文件的工具:预览是 diff;结果行后面是增删的行数,展开看完整的 diff */
98
- function fileRenderer(cwd: string, tool: FileTool, summary?: (input: unknown) => string): ToolRenderer {
102
+ function fileRenderer(cwd: string, tool: FileTool, summary: (input: unknown) => string): ToolRenderer {
99
103
  return {
100
104
  tool,
101
105
  summary,
@@ -112,72 +116,23 @@ function fileRenderer(cwd: string, tool: FileTool, summary?: (input: unknown) =>
112
116
  }
113
117
 
114
118
  export function fsRenderers(cwd: string): ToolRenderer[] {
119
+ // 默认摘要是 path 参数,审批插件换成绝对路径后太长:统一换回相对路径
120
+ const where = (input: unknown) => pathOf(cwd, args(input));
115
121
  const search = (input: unknown) => {
116
122
  const i = args(input);
117
- const where = pathOf(cwd, i);
118
- return `${i.pattern}${where && where !== "." ? ` in ${where}` : ""}`;
123
+ const at = pathOf(cwd, i);
124
+ return `${i.pattern}${at && at !== "." ? ` in ${at}` : ""}`;
119
125
  };
120
126
  return [
121
- fileRenderer(cwd, "edit_file"),
127
+ { tool: "read_file", summary: where },
128
+ { tool: "list_dir", summary: where },
129
+ fileRenderer(cwd, "edit_file", where),
122
130
  fileRenderer(cwd, "multi_edit", (input) => {
123
131
  const i = args(input);
124
132
  return `${pathOf(cwd, i)}, ${Array.isArray(i.edits) ? i.edits.length : 0} edits`;
125
133
  }),
126
- fileRenderer(cwd, "write_file"),
134
+ fileRenderer(cwd, "write_file", where),
127
135
  { tool: "grep", summary: search },
128
136
  { tool: "glob", summary: search },
129
137
  ];
130
138
  }
131
-
132
- // ---------- 其他内置工具 ----------
133
-
134
- export const shellRenderers: ToolRenderer[] = [
135
- {
136
- tool: "bash",
137
- summary: (input) => clip(String(args(input).command ?? "").split("\n")[0]!, 120),
138
- // 摘要省略了内容时(多行或很长的命令),展开后先显示完整的命令
139
- details: (input) => {
140
- const lines = String(args(input).command ?? "").split("\n");
141
- if (lines.length === 1 && lines[0]!.length <= 120) return undefined;
142
- return capped(lines.map((l, i) => `${i === 0 ? "$" : " "} ${l}`), dim, 200);
143
- },
144
- preview: (input) => marked(String(args(input).command ?? ""), "$", (s) => s),
145
- },
146
- { tool: "bash_output", summary: (input) => String(args(input).id ?? "") },
147
- { tool: "kill_shell", summary: (input) => String(args(input).id ?? "") },
148
- ];
149
-
150
- export const webRenderers: ToolRenderer[] = [
151
- { tool: "web_fetch", summary: (input) => clip(String(args(input).url ?? ""), 120) },
152
- { tool: "web_search", summary: (input) => clip(String(args(input).query ?? ""), 120) },
153
- ];
154
-
155
- export const todoRenderers: ToolRenderer[] = [
156
- { tool: "todo_write", summary: (input) => `${Array.isArray(args(input).todos) ? (args(input).todos as unknown[]).length : 0} items` },
157
- ];
158
-
159
- export const askRenderers: ToolRenderer[] = [
160
- {
161
- tool: "ask_user",
162
- summary: (input) => {
163
- const q = args(input).questions;
164
- return Array.isArray(q) && q.length === 1 ? clip(String(q[0]?.question ?? ""), 120) : `${Array.isArray(q) ? q.length : 0} questions`;
165
- },
166
- },
167
- ];
168
-
169
- export const memoryRenderers: ToolRenderer[] = [
170
- {
171
- tool: "memory",
172
- summary: (input) => {
173
- const i = args(input);
174
- return `${i.action} ${i.scope}: ${clip(String(i.text ?? ""), 120)}`;
175
- },
176
- preview: (input) => {
177
- const i = args(input);
178
- return `${i.action === "remove" ? red("- ") : green("+ ")}${String(i.text ?? "")}`;
179
- },
180
- },
181
- ];
182
-
183
- export const taskRenderers: ToolRenderer[] = [{ tool: "task", summary: (input) => String(args(input).description ?? "") }];
@@ -0,0 +1,18 @@
1
+ // 显示用的小工具:截断和 ANSI 颜色。从旧 jade 的 ui/render.ts、ui/screen.ts 复制过来:
2
+ // 插件之间不共享代码(只能共享类型),所以 shell 插件也有一份。
3
+
4
+ export const clip = (s: string, n: number) => (s.length > n ? s.slice(0, n) + "…" : s);
5
+
6
+ // 设了 NO_COLOR(非空)或标准输出不是终端时不输出颜色,见 https://no-color.org
7
+ const colors = Boolean(process.stdout.isTTY) && !process.env.NO_COLOR;
8
+ /**
9
+ * 每种样式用自己的关闭码,不用 \x1b[0m 全部重置:外面套着别的样式时,后面的文字仍保持外层样式。
10
+ * 里面出现同一个关闭码(例如 dim 里套 bold,两者都用 22 关闭)时紧接着重新打开外层的样式
11
+ */
12
+ const paint = (open: string, close: string) => (s: string) =>
13
+ colors ? `\x1b[${open}m${s.replaceAll(`\x1b[${close}m`, `\x1b[${close}m\x1b[${open}m`)}\x1b[${close}m` : s;
14
+ export const dim = paint("2", "22");
15
+ export const red = paint("31", "39");
16
+ export const green = paint("32", "39");
17
+ export const yellow = paint("33", "39");
18
+ export const bold = paint("1", "22");