@uncarved/jade 0.1.2 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (436) hide show
  1. package/bin/jade.js +5 -4
  2. package/dist/api.d.ts +266 -0
  3. package/dist/api.js +38 -0
  4. package/dist/api.js.map +1 -0
  5. package/dist/config.d.ts +13 -32
  6. package/dist/config.js +39 -121
  7. package/dist/config.js.map +1 -1
  8. package/dist/fetch.d.ts +20 -0
  9. package/dist/fetch.js +190 -0
  10. package/dist/fetch.js.map +1 -0
  11. package/dist/hash.d.ts +2 -0
  12. package/dist/hash.js +42 -0
  13. package/dist/hash.js.map +1 -0
  14. package/dist/host.d.ts +71 -0
  15. package/dist/host.js +400 -0
  16. package/dist/host.js.map +1 -0
  17. package/dist/index.d.ts +11 -28
  18. package/dist/index.js +11 -28
  19. package/dist/index.js.map +1 -1
  20. package/dist/install.d.ts +78 -0
  21. package/dist/install.js +292 -0
  22. package/dist/install.js.map +1 -0
  23. package/dist/main.d.ts +1 -2
  24. package/dist/main.js +156 -1223
  25. package/dist/main.js.map +1 -1
  26. package/dist/manifest.d.ts +23 -0
  27. package/dist/manifest.js +159 -0
  28. package/dist/manifest.js.map +1 -0
  29. package/dist/membrane.d.ts +33 -0
  30. package/dist/membrane.js +140 -0
  31. package/dist/membrane.js.map +1 -0
  32. package/dist/remote.d.ts +10 -0
  33. package/dist/remote.js +292 -0
  34. package/dist/remote.js.map +1 -0
  35. package/dist/rescue.d.ts +10 -0
  36. package/dist/rescue.js +216 -0
  37. package/dist/rescue.js.map +1 -0
  38. package/dist/resolve.d.ts +34 -0
  39. package/dist/resolve.js +178 -0
  40. package/dist/resolve.js.map +1 -0
  41. package/dist/rpc.d.ts +26 -0
  42. package/dist/rpc.js +144 -0
  43. package/dist/rpc.js.map +1 -0
  44. package/dist/secrets.d.ts +12 -0
  45. package/dist/secrets.js +125 -0
  46. package/dist/secrets.js.map +1 -0
  47. package/dist/session.d.ts +45 -0
  48. package/dist/session.js +401 -0
  49. package/dist/session.js.map +1 -0
  50. package/dist/source.d.ts +12 -0
  51. package/dist/source.js +72 -0
  52. package/dist/source.js.map +1 -0
  53. package/dist/state.d.ts +37 -0
  54. package/dist/state.js +93 -0
  55. package/dist/state.js.map +1 -0
  56. package/dist/update.d.ts +55 -0
  57. package/dist/update.js +258 -0
  58. package/dist/update.js.map +1 -0
  59. package/package.json +12 -9
  60. package/plugins/approval/index.ts +297 -0
  61. package/plugins/approval/plugin.json +18 -0
  62. package/{src/plugins → plugins/approval}/policy.ts +21 -84
  63. package/plugins/approval/review.ts +192 -0
  64. package/plugins/ask/index.ts +159 -0
  65. package/plugins/ask/plugin.json +8 -0
  66. package/plugins/budget/index.ts +38 -0
  67. package/plugins/budget/plugin.json +13 -0
  68. package/{src/plugins → plugins/checks}/checks.ts +68 -39
  69. package/plugins/checks/index.ts +158 -0
  70. package/plugins/checks/plugin.json +14 -0
  71. package/plugins/checks/project.ts +81 -0
  72. package/plugins/commands/index.ts +76 -0
  73. package/plugins/commands/plugin.json +7 -0
  74. package/{src/plugins → plugins/compact}/compact.ts +112 -38
  75. package/plugins/compact/index.ts +115 -0
  76. package/plugins/compact/plugin.json +17 -0
  77. package/plugins/compact/style.ts +17 -0
  78. package/plugins/continue/index.ts +58 -0
  79. package/plugins/continue/plugin.json +13 -0
  80. package/{src/ui → plugins/fs}/diff.ts +3 -4
  81. package/{src/tools → plugins/fs}/fs.ts +64 -46
  82. package/{src/tools → plugins/fs}/grep.ts +4 -3
  83. package/plugins/fs/index.ts +34 -0
  84. package/plugins/fs/plugin.json +7 -0
  85. package/plugins/fs/renderers.ts +138 -0
  86. package/plugins/fs/style.ts +18 -0
  87. package/plugins/fs/sys.ts +81 -0
  88. package/plugins/keys/index.ts +53 -0
  89. package/plugins/keys/plugin.json +7 -0
  90. package/plugins/mcp/index.ts +192 -0
  91. package/{src → plugins/mcp}/mcp.ts +32 -32
  92. package/plugins/mcp/plugin.json +7 -0
  93. package/plugins/mcp/project.ts +93 -0
  94. package/plugins/memory/index.ts +105 -0
  95. package/{src → plugins/memory}/memory.ts +20 -2
  96. package/plugins/memory/notes.ts +43 -0
  97. package/plugins/memory/plugin.json +7 -0
  98. package/plugins/memory/style.ts +17 -0
  99. package/plugins/mentions/attach.ts +127 -0
  100. package/plugins/mentions/index.ts +79 -0
  101. package/plugins/mentions/plugin.json +7 -0
  102. package/plugins/mentions/style.ts +17 -0
  103. package/plugins/models/config.ts +53 -0
  104. package/plugins/models/configure.ts +455 -0
  105. package/plugins/models/context.ts +32 -0
  106. package/plugins/models/index.ts +198 -0
  107. package/plugins/models/plugin.json +8 -0
  108. package/{src → plugins/models}/provider.ts +23 -27
  109. package/plugins/models/saved.ts +94 -0
  110. package/plugins/modes/index.ts +222 -0
  111. package/plugins/modes/plugin.json +9 -0
  112. package/plugins/plugins/index.ts +38 -0
  113. package/plugins/plugins/plugin.json +7 -0
  114. package/plugins/print/index.ts +142 -0
  115. package/plugins/print/plugin.json +8 -0
  116. package/plugins/prompts/index.ts +83 -0
  117. package/plugins/prompts/plugin.json +8 -0
  118. package/plugins/prompts/prompts.ts +253 -0
  119. package/plugins/prompts/sys.ts +72 -0
  120. package/plugins/renderers/index.ts +78 -0
  121. package/plugins/renderers/plugin.json +7 -0
  122. package/plugins/repeats/index.ts +165 -0
  123. package/plugins/repeats/plugin.json +6 -0
  124. package/plugins/schedule/cron.ts +74 -0
  125. package/plugins/schedule/index.ts +292 -0
  126. package/plugins/schedule/plugin.json +13 -0
  127. package/plugins/schedule/store.ts +149 -0
  128. package/plugins/scratch/index.ts +31 -0
  129. package/plugins/scratch/plugin.json +7 -0
  130. package/plugins/screenshot/index.ts +40 -0
  131. package/plugins/screenshot/plugin.json +7 -0
  132. package/plugins/screenshot/sys.ts +84 -0
  133. package/{src/tools/screenshot.ts → plugins/screenshot/tool.ts} +6 -6
  134. package/plugins/sessions/index.ts +148 -0
  135. package/plugins/sessions/plugin.json +8 -0
  136. package/plugins/shell/index.ts +33 -0
  137. package/plugins/shell/plugin.json +17 -0
  138. package/plugins/shell/renderers.ts +45 -0
  139. package/plugins/shell/service.ts +44 -0
  140. package/{src/tools → plugins/shell}/shell.ts +36 -21
  141. package/{src → plugins/shell}/sys.ts +19 -43
  142. package/plugins/skills/index.ts +96 -0
  143. package/plugins/skills/plugin.json +7 -0
  144. package/plugins/skills/project.ts +49 -0
  145. package/{src → plugins/skills}/skills.ts +4 -11
  146. package/plugins/suggest/index.ts +286 -0
  147. package/plugins/suggest/plugin.json +18 -0
  148. package/plugins/task/index.ts +167 -0
  149. package/plugins/task/plugin.json +15 -0
  150. package/plugins/task/style.ts +17 -0
  151. package/plugins/task/subagent.ts +257 -0
  152. package/{src/tools/todo.ts → plugins/todo/index.ts} +33 -7
  153. package/plugins/todo/plugin.json +7 -0
  154. package/{src/ui → plugins/tui}/editor.ts +53 -1
  155. package/plugins/tui/frontend.ts +596 -0
  156. package/plugins/tui/index.ts +37 -0
  157. package/{src/ui → plugins/tui}/markdown.ts +258 -219
  158. package/plugins/tui/mentions.ts +113 -0
  159. package/plugins/tui/plugin.json +10 -0
  160. package/plugins/tui/render.ts +67 -0
  161. package/plugins/tui/screen.ts +268 -0
  162. package/{src/ui → plugins/tui}/transcript.ts +179 -111
  163. package/{src/ui/tui.tsx → plugins/tui/tui.ts} +684 -418
  164. package/{src/tools → plugins/undo}/checkpoint.ts +21 -60
  165. package/plugins/undo/index.ts +139 -0
  166. package/plugins/undo/notes.ts +43 -0
  167. package/plugins/undo/plugin.json +7 -0
  168. package/plugins/undo/style.ts +17 -0
  169. package/plugins/update/index.ts +40 -0
  170. package/plugins/update/plugin.json +13 -0
  171. package/plugins/web/env.ts +78 -0
  172. package/plugins/web/index.ts +133 -0
  173. package/plugins/web/plugin.json +15 -0
  174. package/plugins/web/renderers.ts +11 -0
  175. package/plugins/web/web.ts +713 -0
  176. package/plugins-dist/approval/index.js +271 -0
  177. package/plugins-dist/approval/plugin.json +24 -0
  178. package/{dist/plugins → plugins-dist/approval}/policy.js +15 -65
  179. package/plugins-dist/approval/review.js +176 -0
  180. package/{dist/plugins → plugins-dist/approval}/schema.js +0 -1
  181. package/plugins-dist/ask/index.js +145 -0
  182. package/plugins-dist/ask/plugin.json +12 -0
  183. package/plugins-dist/budget/index.js +37 -0
  184. package/plugins-dist/budget/plugin.json +15 -0
  185. package/{dist/plugins → plugins-dist/checks}/checks.js +65 -34
  186. package/plugins-dist/checks/index.js +150 -0
  187. package/plugins-dist/checks/plugin.json +21 -0
  188. package/plugins-dist/checks/project.js +76 -0
  189. package/plugins-dist/commands/index.js +33 -0
  190. package/plugins-dist/commands/plugin.json +9 -0
  191. package/{dist/plugins → plugins-dist/compact}/compact.js +95 -33
  192. package/plugins-dist/compact/index.js +100 -0
  193. package/plugins-dist/compact/plugin.json +25 -0
  194. package/plugins-dist/compact/style.js +14 -0
  195. package/plugins-dist/continue/index.js +57 -0
  196. package/plugins-dist/continue/plugin.json +15 -0
  197. package/{dist/ui → plugins-dist/fs}/diff.js +3 -5
  198. package/{dist/tools → plugins-dist/fs}/fs.js +62 -46
  199. package/{dist/tools → plugins-dist/fs}/grep.js +4 -4
  200. package/plugins-dist/fs/index.js +36 -0
  201. package/plugins-dist/fs/plugin.json +10 -0
  202. package/plugins-dist/fs/renderers.js +132 -0
  203. package/plugins-dist/fs/style.js +15 -0
  204. package/plugins-dist/fs/sys.js +54 -0
  205. package/plugins-dist/keys/index.js +36 -0
  206. package/plugins-dist/keys/plugin.json +9 -0
  207. package/plugins-dist/mcp/index.js +187 -0
  208. package/{dist → plugins-dist/mcp}/mcp.js +34 -30
  209. package/plugins-dist/mcp/plugin.json +12 -0
  210. package/plugins-dist/mcp/project.js +90 -0
  211. package/plugins-dist/memory/index.js +94 -0
  212. package/{dist → plugins-dist/memory}/memory.js +21 -3
  213. package/plugins-dist/memory/notes.js +36 -0
  214. package/plugins-dist/memory/plugin.json +11 -0
  215. package/plugins-dist/memory/style.js +14 -0
  216. package/plugins-dist/mentions/attach.js +120 -0
  217. package/plugins-dist/mentions/index.js +69 -0
  218. package/plugins-dist/mentions/plugin.json +9 -0
  219. package/plugins-dist/mentions/style.js +14 -0
  220. package/plugins-dist/models/config.js +53 -0
  221. package/plugins-dist/models/configure.js +415 -0
  222. package/plugins-dist/models/context.js +27 -0
  223. package/plugins-dist/models/index.js +167 -0
  224. package/plugins-dist/models/plugin.json +14 -0
  225. package/{dist → plugins-dist/models}/provider.js +22 -19
  226. package/plugins-dist/models/saved.js +80 -0
  227. package/plugins-dist/modes/index.js +190 -0
  228. package/plugins-dist/modes/plugin.json +18 -0
  229. package/plugins-dist/plugins/index.js +37 -0
  230. package/plugins-dist/plugins/plugin.json +10 -0
  231. package/plugins-dist/print/index.js +153 -0
  232. package/plugins-dist/print/plugin.json +14 -0
  233. package/plugins-dist/prompts/index.js +57 -0
  234. package/plugins-dist/prompts/plugin.json +13 -0
  235. package/plugins-dist/prompts/prompts.js +227 -0
  236. package/plugins-dist/prompts/sys.js +46 -0
  237. package/plugins-dist/renderers/index.js +36 -0
  238. package/plugins-dist/renderers/plugin.json +9 -0
  239. package/plugins-dist/repeats/index.js +165 -0
  240. package/plugins-dist/repeats/plugin.json +6 -0
  241. package/plugins-dist/schedule/cron.js +67 -0
  242. package/plugins-dist/schedule/index.js +281 -0
  243. package/plugins-dist/schedule/plugin.json +16 -0
  244. package/plugins-dist/schedule/store.js +125 -0
  245. package/plugins-dist/scratch/index.js +26 -0
  246. package/plugins-dist/scratch/plugin.json +10 -0
  247. package/plugins-dist/screenshot/index.js +35 -0
  248. package/plugins-dist/screenshot/plugin.json +11 -0
  249. package/plugins-dist/screenshot/sys.js +76 -0
  250. package/{dist/tools/screenshot.js → plugins-dist/screenshot/tool.js} +5 -4
  251. package/plugins-dist/sessions/index.js +136 -0
  252. package/plugins-dist/sessions/plugin.json +12 -0
  253. package/plugins-dist/shell/index.js +33 -0
  254. package/plugins-dist/shell/plugin.json +19 -0
  255. package/plugins-dist/shell/renderers.js +40 -0
  256. package/plugins-dist/shell/service.js +29 -0
  257. package/{dist/tools → plugins-dist/shell}/shell.js +36 -23
  258. package/{dist → plugins-dist/shell}/sys.js +20 -44
  259. package/plugins-dist/skills/index.js +90 -0
  260. package/plugins-dist/skills/plugin.json +12 -0
  261. package/plugins-dist/skills/project.js +47 -0
  262. package/{dist → plugins-dist/skills}/skills.js +3 -7
  263. package/plugins-dist/suggest/index.js +282 -0
  264. package/plugins-dist/suggest/plugin.json +23 -0
  265. package/plugins-dist/task/index.js +151 -0
  266. package/plugins-dist/task/plugin.json +23 -0
  267. package/plugins-dist/task/style.js +14 -0
  268. package/plugins-dist/task/subagent.js +208 -0
  269. package/{dist/tools/todo.js → plugins-dist/todo/index.js} +29 -7
  270. package/plugins-dist/todo/plugin.json +9 -0
  271. package/{dist/ui → plugins-dist/tui}/editor.js +53 -2
  272. package/plugins-dist/tui/frontend.js +586 -0
  273. package/{dist → plugins-dist/tui}/history.js +0 -1
  274. package/plugins-dist/tui/index.js +21 -0
  275. package/{dist/ui → plugins-dist/tui}/markdown.js +57 -20
  276. package/plugins-dist/tui/mentions.js +115 -0
  277. package/plugins-dist/tui/plugin.json +25 -0
  278. package/plugins-dist/tui/render.js +61 -0
  279. package/plugins-dist/tui/screen.js +201 -0
  280. package/{dist/ui → plugins-dist/tui}/transcript.js +179 -111
  281. package/{dist/ui → plugins-dist/tui}/tui.js +484 -101
  282. package/{dist/tools → plugins-dist/undo}/checkpoint.js +21 -55
  283. package/plugins-dist/undo/index.js +140 -0
  284. package/plugins-dist/undo/notes.js +36 -0
  285. package/plugins-dist/undo/plugin.json +9 -0
  286. package/plugins-dist/undo/style.js +14 -0
  287. package/plugins-dist/update/index.js +34 -0
  288. package/plugins-dist/update/plugin.json +15 -0
  289. package/plugins-dist/web/env.js +80 -0
  290. package/plugins-dist/web/index.js +124 -0
  291. package/plugins-dist/web/plugin.json +21 -0
  292. package/plugins-dist/web/renderers.js +7 -0
  293. package/plugins-dist/web/web.js +660 -0
  294. package/sdk/python/__pycache__/jade_plugin.cpython-312.pyc +0 -0
  295. package/sdk/python/jade_plugin.py +380 -0
  296. package/src/api.ts +298 -0
  297. package/src/config.ts +32 -134
  298. package/src/fetch.ts +216 -0
  299. package/src/hash.ts +39 -0
  300. package/src/host.ts +429 -0
  301. package/src/index.ts +23 -28
  302. package/src/install.ts +355 -0
  303. package/src/main.ts +152 -1263
  304. package/src/manifest.ts +160 -0
  305. package/src/membrane.ts +142 -0
  306. package/src/remote.ts +288 -0
  307. package/src/rescue.ts +217 -0
  308. package/src/resolve.ts +199 -0
  309. package/src/rpc.ts +144 -0
  310. package/src/secrets.ts +122 -0
  311. package/src/session.ts +458 -0
  312. package/src/source.ts +83 -0
  313. package/src/state.ts +120 -0
  314. package/src/update.ts +265 -0
  315. package/LICENSE +0 -21
  316. package/README.md +0 -198
  317. package/dist/commands.d.ts +0 -30
  318. package/dist/commands.js +0 -106
  319. package/dist/commands.js.map +0 -1
  320. package/dist/context.d.ts +0 -17
  321. package/dist/context.js +0 -53
  322. package/dist/context.js.map +0 -1
  323. package/dist/distro.d.ts +0 -104
  324. package/dist/distro.js +0 -312
  325. package/dist/distro.js.map +0 -1
  326. package/dist/history.d.ts +0 -10
  327. package/dist/history.js.map +0 -1
  328. package/dist/mcp.d.ts +0 -114
  329. package/dist/mcp.js.map +0 -1
  330. package/dist/memory.d.ts +0 -19
  331. package/dist/memory.js.map +0 -1
  332. package/dist/mentions.d.ts +0 -35
  333. package/dist/mentions.js +0 -130
  334. package/dist/mentions.js.map +0 -1
  335. package/dist/plugin-cli.d.ts +0 -16
  336. package/dist/plugin-cli.js +0 -251
  337. package/dist/plugin-cli.js.map +0 -1
  338. package/dist/plugins/budget.d.ts +0 -9
  339. package/dist/plugins/budget.js +0 -30
  340. package/dist/plugins/budget.js.map +0 -1
  341. package/dist/plugins/builtins.d.ts +0 -10
  342. package/dist/plugins/builtins.js +0 -22
  343. package/dist/plugins/builtins.js.map +0 -1
  344. package/dist/plugins/checks.d.ts +0 -70
  345. package/dist/plugins/checks.js.map +0 -1
  346. package/dist/plugins/compact.d.ts +0 -26
  347. package/dist/plugins/compact.js.map +0 -1
  348. package/dist/plugins/core.d.ts +0 -42
  349. package/dist/plugins/core.js +0 -190
  350. package/dist/plugins/core.js.map +0 -1
  351. package/dist/plugins/install.d.ts +0 -68
  352. package/dist/plugins/install.js +0 -377
  353. package/dist/plugins/install.js.map +0 -1
  354. package/dist/plugins/loader.d.ts +0 -182
  355. package/dist/plugins/loader.js +0 -253
  356. package/dist/plugins/loader.js.map +0 -1
  357. package/dist/plugins/policy.d.ts +0 -96
  358. package/dist/plugins/policy.js.map +0 -1
  359. package/dist/plugins/prompts.d.ts +0 -38
  360. package/dist/plugins/prompts.js +0 -196
  361. package/dist/plugins/prompts.js.map +0 -1
  362. package/dist/plugins/repeats.d.ts +0 -9
  363. package/dist/plugins/repeats.js +0 -90
  364. package/dist/plugins/repeats.js.map +0 -1
  365. package/dist/plugins/review.d.ts +0 -16
  366. package/dist/plugins/review.js +0 -92
  367. package/dist/plugins/review.js.map +0 -1
  368. package/dist/plugins/schema.d.ts +0 -2
  369. package/dist/plugins/schema.js.map +0 -1
  370. package/dist/provider.d.ts +0 -111
  371. package/dist/provider.js.map +0 -1
  372. package/dist/sessions.d.ts +0 -22
  373. package/dist/sessions.js +0 -53
  374. package/dist/sessions.js.map +0 -1
  375. package/dist/skills.d.ts +0 -37
  376. package/dist/skills.js.map +0 -1
  377. package/dist/sys.d.ts +0 -48
  378. package/dist/sys.js.map +0 -1
  379. package/dist/tools/checkpoint.d.ts +0 -43
  380. package/dist/tools/checkpoint.js.map +0 -1
  381. package/dist/tools/fs.d.ts +0 -35
  382. package/dist/tools/fs.js.map +0 -1
  383. package/dist/tools/grep.d.ts +0 -6
  384. package/dist/tools/grep.js.map +0 -1
  385. package/dist/tools/screenshot.d.ts +0 -15
  386. package/dist/tools/screenshot.js.map +0 -1
  387. package/dist/tools/shell.d.ts +0 -55
  388. package/dist/tools/shell.js.map +0 -1
  389. package/dist/tools/task.d.ts +0 -35
  390. package/dist/tools/task.js +0 -89
  391. package/dist/tools/task.js.map +0 -1
  392. package/dist/tools/todo.d.ts +0 -10
  393. package/dist/tools/todo.js.map +0 -1
  394. package/dist/tools/web.d.ts +0 -23
  395. package/dist/tools/web.js +0 -426
  396. package/dist/tools/web.js.map +0 -1
  397. package/dist/ui/configure.d.ts +0 -20
  398. package/dist/ui/configure.js +0 -378
  399. package/dist/ui/configure.js.map +0 -1
  400. package/dist/ui/diff.d.ts +0 -20
  401. package/dist/ui/diff.js.map +0 -1
  402. package/dist/ui/editor.d.ts +0 -33
  403. package/dist/ui/editor.js.map +0 -1
  404. package/dist/ui/markdown.d.ts +0 -17
  405. package/dist/ui/markdown.js.map +0 -1
  406. package/dist/ui/render.d.ts +0 -15
  407. package/dist/ui/render.js +0 -94
  408. package/dist/ui/render.js.map +0 -1
  409. package/dist/ui/screen.d.ts +0 -98
  410. package/dist/ui/screen.js +0 -108
  411. package/dist/ui/screen.js.map +0 -1
  412. package/dist/ui/transcript.d.ts +0 -33
  413. package/dist/ui/transcript.js.map +0 -1
  414. package/dist/ui/tui.d.ts +0 -45
  415. package/dist/ui/tui.js.map +0 -1
  416. package/src/commands.ts +0 -120
  417. package/src/context.ts +0 -64
  418. package/src/distro.ts +0 -400
  419. package/src/mentions.ts +0 -135
  420. package/src/plugin-cli.ts +0 -239
  421. package/src/plugins/budget.ts +0 -37
  422. package/src/plugins/builtins.ts +0 -31
  423. package/src/plugins/core.ts +0 -217
  424. package/src/plugins/install.ts +0 -429
  425. package/src/plugins/loader.ts +0 -386
  426. package/src/plugins/prompts.ts +0 -234
  427. package/src/plugins/repeats.ts +0 -96
  428. package/src/plugins/review.ts +0 -109
  429. package/src/sessions.ts +0 -61
  430. package/src/tools/task.ts +0 -109
  431. package/src/tools/web.ts +0 -451
  432. package/src/ui/configure.ts +0 -408
  433. package/src/ui/render.ts +0 -83
  434. package/src/ui/screen.ts +0 -169
  435. /package/{src/plugins → plugins/approval}/schema.ts +0 -0
  436. /package/{src → plugins/tui}/history.ts +0 -0
package/src/mentions.ts DELETED
@@ -1,135 +0,0 @@
1
- // @ 引用文件:输入框里打 @ 时补全路径,发送时把引用的文件内容随消息一起交给模型。
2
- //
3
- // 内容用 read_file / list_dir 工具本身读取,格式和模型自己读到的一样(带行号),
4
- // 而且算作"读过":模型可以直接修改引用的文件,不用先再读一遍。
5
- // 只有存在的路径才算引用,所以消息里普通的 @someone 原样保留。
6
-
7
- import { stat } from "node:fs/promises";
8
- import os from "node:os";
9
- import path from "node:path";
10
- import type { Block, Tool, ToolContext } from "uncarved";
11
- import { display, listFiles } from "./tools/fs.ts";
12
-
13
- /** 补全用的候选最多这么多个(文件加目录) */
14
- const MAX_CANDIDATES = 20_000;
15
-
16
- /** @ 后面的路径:@"带 空格 的路径" 或者到空白为止 */
17
- const MENTION = /(?<=^|\s)@(?:"([^"\n]+)"|([^\s"]+))/g;
18
-
19
- /** 光标正在输入的 @ 引用:@ 的下标和已经输入的部分;不在引用里时返回 undefined */
20
- export function mentionAt(value: string, cursor: number): { start: number; query: string } | undefined {
21
- const m = /(?:^|\s)@("?[^\s"]*)$/.exec(value.slice(0, cursor));
22
- if (!m) return undefined;
23
- return { start: cursor - m[1]!.length - 1, query: m[1]!.replace(/^"/, "") };
24
- }
25
-
26
- /** 补全后的文本:@ 引用加一个空格,含空白的路径加引号 */
27
- export const mentionText = (p: string) => (/\s/.test(p) ? `@"${p}"` : `@${p}`);
28
-
29
- /** 消息里引用的路径,去重,按出现顺序;末尾的标点(句号、逗号……)不算路径 */
30
- export function parseMentions(text: string): string[] {
31
- const out: string[] = [];
32
- for (const m of text.matchAll(MENTION)) {
33
- const p = m[1] ?? m[2]!.replace(/[.,;:!?)\]},。;:!?)】]+$/u, "");
34
- if (p && !out.includes(p)) out.push(p);
35
- }
36
- return out;
37
- }
38
-
39
- /**
40
- * 按 query 给候选路径排序:文件名以 query 开头的最前,其次文件名包含、路径包含,
41
- * 最后是按顺序出现 query 每个字符的模糊匹配;同一档里短的在前
42
- */
43
- export function rankPaths(paths: string[], query: string, limit: number): string[] {
44
- const q = query.toLowerCase().replaceAll("\\", "/");
45
- if (!q) return paths.filter((p) => !p.slice(0, -1).includes("/")).slice(0, limit);
46
- const scored: { p: string; score: number }[] = [];
47
- for (const p of paths) {
48
- const lower = p.toLowerCase();
49
- const base = lower.replace(/\/$/, "").split("/").pop()!;
50
- let score: number;
51
- if (lower.startsWith(q)) score = 0;
52
- else if (base.startsWith(q)) score = 1;
53
- else if (base.includes(q)) score = 2;
54
- else if (lower.includes(q)) score = 3;
55
- else if (subsequence(lower, q)) score = 4;
56
- else continue;
57
- scored.push({ p, score });
58
- }
59
- scored.sort((a, b) => a.score - b.score || a.p.length - b.p.length || a.p.localeCompare(b.p));
60
- return scored.slice(0, limit).map((s) => s.p);
61
- }
62
-
63
- function subsequence(text: string, q: string): boolean {
64
- let i = 0;
65
- for (const ch of text) if (ch === q[i] && ++i === q.length) return true;
66
- return false;
67
- }
68
-
69
- /** 补全的候选:工作目录里未被 git 忽略的文件和它们所在的目录(目录以 / 结尾),相对路径、正斜杠 */
70
- export async function mentionCandidates(cwd: string): Promise<string[]> {
71
- const files: string[] = [];
72
- const dirs = new Set<string>();
73
- for await (const full of await listFiles(cwd, AbortSignal.timeout(5000))) {
74
- const rel = display(cwd, full);
75
- files.push(rel);
76
- for (let i = rel.lastIndexOf("/"); i > 0; i = rel.lastIndexOf("/", i - 1)) {
77
- const dir = rel.slice(0, i + 1);
78
- if (dirs.has(dir)) break;
79
- dirs.add(dir);
80
- }
81
- if (files.length + dirs.size >= MAX_CANDIDATES) break;
82
- }
83
- return [...dirs, ...files];
84
- }
85
-
86
- export interface Attachments {
87
- /** 随消息发出的内容 */
88
- blocks: Block[];
89
- /** 附上了的路径(显示用) */
90
- attached: string[];
91
- /** 存在但读不了的 */
92
- failed: { path: string; reason: string }[];
93
- }
94
-
95
- /** 读取消息里引用的文件和目录;tools 里要有 read_file 和 list_dir */
96
- export async function attachMentions(text: string, opts: { cwd: string; tools: Tool[]; sessionId: string; signal: AbortSignal }): Promise<Attachments> {
97
- const out: Attachments = { blocks: [], attached: [], failed: [] };
98
- const tool = (name: string) => opts.tools.find((t) => t.name === name);
99
- let n = 0;
100
- for (const p of parseMentions(text)) {
101
- const full = path.resolve(opts.cwd, p.replace(/^~(?=$|[\\/])/, os.homedir()));
102
- const info = await stat(full).catch(() => undefined);
103
- if (!info) continue;
104
- const name = info.isDirectory() ? "list_dir" : "read_file";
105
- const t = tool(name);
106
- if (!t) continue;
107
- const ctx: ToolContext = {
108
- sessionId: opts.sessionId,
109
- toolUseId: `mention-${Date.now()}-${n++}`,
110
- signal: opts.signal,
111
- parent: { sessionId: opts.sessionId, eventId: "" },
112
- progress: () => {},
113
- };
114
- const shown = display(opts.cwd, full);
115
- try {
116
- const r = await t.execute({ path: full }, ctx);
117
- if (r.isError) {
118
- out.failed.push({ path: shown, reason: typeof r.content === "string" ? r.content : "could not be read" });
119
- continue;
120
- }
121
- const what = name === "list_dir" ? "the directory" : "the file";
122
- const head = `[Note from jade] The user referenced ${what} ${shown}. Its content, as ${name} returns it:`;
123
- out.blocks.push({ kind: "text", text: head, origin: { by: "host" }, trust: "trusted" });
124
- out.blocks.push(
125
- ...(typeof r.content === "string"
126
- ? [{ kind: "text" as const, text: r.content, origin: { by: "tool" as const, name }, trust: "untrusted" as const }]
127
- : r.content),
128
- );
129
- out.attached.push(shown);
130
- } catch (err) {
131
- out.failed.push({ path: shown, reason: err instanceof Error ? err.message : String(err) });
132
- }
133
- }
134
- return out;
135
- }
package/src/plugin-cli.ts DELETED
@@ -1,239 +0,0 @@
1
- // jade plugin …:安装、更新、卸载、停用插件。在会话外运行,不需要配置模型。
2
-
3
- import { readdir, readFile } from "node:fs/promises";
4
- import path from "node:path";
5
- import { hashDir, type TrustStore } from "uncarved";
6
- import { BUILTINS, BUILTIN_IDS, REQUIRED_IDS } from "./plugins/builtins.ts";
7
- import {
8
- addPlugin,
9
- installedNames,
10
- readPluginSettings,
11
- readRecords,
12
- removePlugin,
13
- setDisabled,
14
- updatePlugins,
15
- type InstallRecord,
16
- } from "./plugins/install.ts";
17
- import { inspectPlugin, type PluginInfo } from "./plugins/loader.ts";
18
- import { bold, dim, green, red, yellow } from "./ui/screen.ts";
19
-
20
- export const PLUGIN_HELP = `Usage: jade plugin <command>
21
-
22
- list built-in and installed plugins
23
- add <source> [options] install a plugin
24
- <source>: a git URL (https://…, git@…, github:user/repo, user/repo; #branch, #tag or #commit),
25
- an npm package (name, name@version, @scope/name, npm:<spec>, a .tgz file),
26
- or a local directory
27
- --project install into <repository>/.jade/plugins instead of $JADE_HOME/plugins
28
- --name <name> directory name (default: the plugin's name)
29
- --path <dir> use this subdirectory of the source (for repositories with several plugins)
30
- --link local directory: link it instead of copying (for plugin development)
31
- --force replace a plugin with the same name
32
- update [name…] [--project] fetch again what jade plugin add installed (all of them when no name is given)
33
- remove <name> [--project] delete an installed plugin
34
- disable <name|id> stop loading a plugin, or a built-in plugin such as jade/web
35
- enable <name|id> undo disable
36
-
37
- Plugins are loaded when jade starts; restart running sessions to pick up changes.`;
38
-
39
- export interface PluginCliOptions {
40
- home: string;
41
- cwd: string;
42
- /** 仓库根目录(--project 用) */
43
- root: string;
44
- /** --project 安装的插件代码已经由用户看过,写进确认记录 */
45
- trust: TrustStore;
46
- out?: (text: string) => void;
47
- err?: (text: string) => void;
48
- }
49
-
50
- /** 返回退出码 */
51
- export async function pluginCli(argv: string[], o: PluginCliOptions): Promise<number> {
52
- const out = o.out ?? ((t: string) => console.log(t));
53
- const err = o.err ?? ((t: string) => console.error(t));
54
- const [sub, ...rest] = argv;
55
- const flags = { project: false, link: false, force: false } as { project: boolean; link: boolean; force: boolean; name?: string; path?: string };
56
- const args: string[] = [];
57
- for (let i = 0; i < rest.length; i++) {
58
- const a = rest[i]!;
59
- const value = () => {
60
- const v = rest[++i];
61
- if (v === undefined) throw new UsageError(`${a} needs a value`);
62
- return v;
63
- };
64
- if (a === "--project") flags.project = true;
65
- else if (a === "--link") flags.link = true;
66
- else if (a === "--force" || a === "-f") flags.force = true;
67
- else if (a === "--name") flags.name = value();
68
- else if (a === "--path") flags.path = value();
69
- else if (a === "-h" || a === "--help") {
70
- out(PLUGIN_HELP);
71
- return 0;
72
- } else if (a.startsWith("-")) throw new UsageError(`unknown option ${a}`);
73
- else args.push(a);
74
- }
75
- const userDir = path.join(o.home, "plugins");
76
- const projectDir = path.join(o.root, ".jade", "plugins");
77
- const dir = flags.project ? projectDir : userDir;
78
- const log = (t: string) => err(dim(t));
79
-
80
- switch (sub) {
81
- case undefined:
82
- case "help":
83
- case "-h":
84
- case "--help":
85
- out(PLUGIN_HELP);
86
- return 0;
87
- case "list":
88
- case "ls":
89
- await list(o, out);
90
- return 0;
91
- case "add":
92
- case "install": {
93
- if (args.length !== 1) throw new UsageError("usage: jade plugin add <source> [--project] [--name <name>] [--path <dir>] [--link] [--force]");
94
- const r = await addPlugin(args[0]!, { pluginsDir: dir, cwd: o.cwd, name: flags.name, subdir: flags.path, link: flags.link, force: flags.force, log });
95
- if (flags.project && r.info.kind === "module") await trustProject(r.dir, o.trust);
96
- out(green(`Installed ${bold(r.name)}${r.info.version ? ` ${r.info.version}` : ""} into ${r.dir}`) + dim(` (${origin(r.record)})`));
97
- for (const line of await provides(r.dir, r.info)) out(` ${line}`);
98
- if (r.info.bundle.unsupported.length) out(yellow(` jade does not support the plugin's ${r.info.bundle.unsupported.join(" and ")} yet; they are ignored`));
99
- if (flags.project) out(dim(" Commit .jade/plugins to share it; others confirm it the first time jade loads it."));
100
- out(dim("Restart jade to load it."));
101
- return 0;
102
- }
103
- case "update":
104
- case "upgrade": {
105
- const results = await updatePlugins(args, { pluginsDir: dir, cwd: o.cwd, log });
106
- if (results.length === 0) out(dim(`No plugins were installed with jade plugin add in ${dir}.`));
107
- let failed = false;
108
- for (const r of results) {
109
- if (r.status === "updated") {
110
- out(green(`${r.name}: updated${r.from || r.to ? ` ${r.from ?? "?"} → ${r.to ?? "?"}` : ""}`));
111
- if (flags.project) {
112
- const info = await inspectPlugin(path.join(dir, r.name)).catch(() => undefined);
113
- if (info?.kind === "module") await trustProject(path.join(dir, r.name), o.trust);
114
- }
115
- } else if (r.status === "current") out(`${r.name}: up to date${r.to ? ` (${r.to})` : ""}`);
116
- else if (r.status === "linked") out(dim(`${r.name}: linked to a local directory; nothing to fetch`));
117
- else if (r.status === "unmanaged") out(dim(`${r.name}: not installed with jade plugin add; update it by hand`));
118
- else {
119
- failed = true;
120
- err(red(`${r.name}: ${r.error}`));
121
- }
122
- }
123
- if (results.some((r) => r.status === "updated")) out(dim("Restart jade to load the new versions."));
124
- return failed ? 1 : 0;
125
- }
126
- case "remove":
127
- case "rm":
128
- case "uninstall": {
129
- if (args.length !== 1) throw new UsageError("usage: jade plugin remove <name> [--project]");
130
- if (!(await removePlugin(args[0]!, dir))) {
131
- err(red(`plugin ${args[0]} is not installed in ${dir}`));
132
- return 1;
133
- }
134
- await setDisabled(o.home, args[0]!, false);
135
- out(green(`Removed ${args[0]}.`));
136
- return 0;
137
- }
138
- case "disable":
139
- case "enable": {
140
- if (args.length !== 1) throw new UsageError(`usage: jade plugin ${sub} <name|id>`);
141
- const name = args[0]!;
142
- if (sub === "disable" && REQUIRED_IDS.has(name)) {
143
- err(red(`${name} cannot be disabled: it decides which tool calls need your approval. Plugins can only make it stricter, with gate hooks.`));
144
- return 1;
145
- }
146
- if (!BUILTIN_IDS.has(name) && !(await knownPlugin(o, name)) && sub === "disable") {
147
- err(yellow(`note: no built-in or installed plugin is called ${name}; it is disabled anyway in case it is a plugin id`));
148
- }
149
- const changed = await setDisabled(o.home, name, sub === "disable");
150
- out(changed ? green(`${name} ${sub}d.`) + dim(" Restart jade to apply it.") : dim(`${name} is already ${sub}d.`));
151
- return 0;
152
- }
153
- default:
154
- throw new UsageError(`unknown command ${sub}`);
155
- }
156
- }
157
-
158
- export class UsageError extends Error {}
159
-
160
- async function list(o: PluginCliOptions, out: (t: string) => void) {
161
- const { disabled } = await readPluginSettings(o.home);
162
- const off = new Set(disabled);
163
- out(bold("Built-in") + dim(" (jade plugin disable <id> turns one off)"));
164
- const width = Math.max(...BUILTINS.map((b) => b.id.length)) + 2;
165
- for (const b of BUILTINS) {
166
- const state = b.required ? dim(" required") : off.has(b.id) ? yellow(" disabled") : "";
167
- out(` ${b.id.padEnd(width)}${dim(b.about)}${state}`);
168
- }
169
- for (const [title, dir] of [
170
- ["User", path.join(o.home, "plugins")],
171
- ["Project", path.join(o.root, ".jade", "plugins")],
172
- ] as const) {
173
- const names = await installedNames(dir);
174
- out("");
175
- out(bold(title) + dim(` ${dir}`));
176
- if (names.length === 0) {
177
- out(dim(" (none)"));
178
- continue;
179
- }
180
- const records = await readRecords(dir);
181
- for (const name of names) {
182
- const rec = records[name];
183
- let info: PluginInfo | undefined;
184
- let problem: string | undefined;
185
- try {
186
- info = await inspectPlugin(path.join(dir, name));
187
- } catch (e) {
188
- problem = e instanceof Error ? e.message : String(e);
189
- }
190
- const version = info?.version ?? rec?.version;
191
- const state = off.has(name) ? yellow(" disabled") : problem ? red(` broken: ${problem}`) : "";
192
- out(` ${bold(name)}${version ? ` ${version}` : ""}${info ? dim(` ${info.kind}`) : ""}${rec ? dim(` · ${origin(rec)}`) : dim(" · copied by hand")}${state}`);
193
- if (info?.description) out(dim(` ${info.description}`));
194
- if (info) for (const line of await provides(path.join(dir, name), info)) out(dim(` ${line}`));
195
- }
196
- }
197
- }
198
-
199
- function origin(rec: InstallRecord): string {
200
- if (rec.kind === "link") return `linked to ${rec.source}`;
201
- const at = rec.commit ? `@${rec.commit.slice(0, 7)}` : "";
202
- return `${rec.source}${rec.subdir ? ` (${rec.subdir})` : ""}${at}`;
203
- }
204
-
205
- /** 插件带了哪些东西(代码的工具和 hook 要加载后才知道,这里只说它是什么形式) */
206
- async function provides(dir: string, info: PluginInfo): Promise<string[]> {
207
- const lines: string[] = [];
208
- if (info.kind === "module") lines.push(`code: ${info.entry}`);
209
- if (info.kind === "process") lines.push(`process: ${[info.json.command, ...(info.json.args ?? [])].join(" ")}`);
210
- const skills: string[] = [];
211
- for (const d of info.bundle.skills) {
212
- for (const n of await readdir(d).catch(() => [] as string[])) {
213
- if (await readFile(path.join(d, n, "SKILL.md")).then(() => true, () => false)) skills.push(n);
214
- }
215
- }
216
- if (skills.length) lines.push(`skills: ${skills.sort().join(", ")}`);
217
- const commands: string[] = [];
218
- for (const d of info.bundle.commands) for (const n of await readdir(d).catch(() => [] as string[])) if (n.endsWith(".md")) commands.push(`/${n.slice(0, -3)}`);
219
- if (commands.length) lines.push(`commands: ${commands.sort().join(", ")}`);
220
- if (info.bundle.mcp) {
221
- let servers = info.bundle.mcp.servers;
222
- if (servers === undefined) servers = await readFile(info.bundle.mcp.file, "utf8").then((t) => JSON.parse(t)?.mcpServers, () => undefined);
223
- const names = servers && typeof servers === "object" ? Object.keys(servers) : [];
224
- lines.push(`MCP servers: ${names.length ? names.join(", ") : path.relative(dir, info.bundle.mcp.file)}`);
225
- }
226
- return lines;
227
- }
228
-
229
- async function knownPlugin(o: PluginCliOptions, name: string): Promise<boolean> {
230
- for (const dir of [path.join(o.home, "plugins"), path.join(o.root, ".jade", "plugins")]) if ((await installedNames(dir)).includes(name)) return true;
231
- return false;
232
- }
233
-
234
- /** 自己用 --project 装的插件不用在启动时再确认一次(别人拉取仓库后第一次加载时仍要确认) */
235
- async function trustProject(dir: string, trust: TrustStore) {
236
- const root = path.resolve(dir);
237
- const { hash } = await hashDir(root);
238
- if (!(await trust.has(hash))) await trust.add({ hash, path: root, at: new Date().toISOString() });
239
- }
@@ -1,37 +0,0 @@
1
- // 预算插件:一轮里模型调用次数超过上限就停下(turn.continue)。
2
-
3
- import type { Plugin, State } from "uncarved";
4
-
5
- export interface BudgetOptions {
6
- /** 一轮最多调用模型的次数,默认 100 */
7
- maxSteps?: number;
8
- id?: string;
9
- }
10
-
11
- /** 本轮(最近一条用户输入之后)模型已经回复了几次 */
12
- export function stepsThisTurn(s: State): number {
13
- let steps = 0;
14
- for (let i = s.messages.length - 1; i >= 0; i--) {
15
- const m = s.messages[i]!;
16
- if (m.role === "assistant") steps++;
17
- else if (m.content.some((b) => b.kind !== "tool_result")) break;
18
- }
19
- return steps;
20
- }
21
-
22
- export function budget(opts: BudgetOptions = {}): Plugin {
23
- const max = opts.maxSteps ?? 100;
24
- return {
25
- id: opts.id ?? "jade/budget",
26
- version: "0.1.0",
27
- kernel: "^0.1",
28
- needs: ["gate:turn.continue"],
29
- hooks: [
30
- {
31
- kind: "gate",
32
- point: "turn.continue",
33
- fn: (s) => (stepsThisTurn(s) >= max ? { decision: "deny" } : { decision: "abstain" }),
34
- },
35
- ],
36
- };
37
- }
@@ -1,31 +0,0 @@
1
- // jade 自带的插件。内核之外的功能都以插件的形式提供,和第三方插件用同一套接口:
2
- // 每个都可以在 $JADE_HOME/plugins.json 里停用(jade plugin disable <id>),
3
- // 或者由第三方插件用 replaces 代替。jade/policy 负责审批,不能停用或代替,第三方插件只能用 gate hook 让它更严格。
4
-
5
- export interface BuiltinInfo {
6
- id: string;
7
- /** 提供什么(jade plugin list、/plugins 显示) */
8
- about: string;
9
- /** 不能停用或代替 */
10
- required?: boolean;
11
- }
12
-
13
- export const BUILTINS: readonly BuiltinInfo[] = [
14
- { id: "jade/policy", about: "permission modes and approvals", required: true },
15
- { id: "jade/prompts", about: "system prompt, environment, AGENTS.md / CLAUDE.md instructions" },
16
- { id: "jade/fs", about: "read_file, write_file, edit_file, multi_edit, list_dir, glob, grep" },
17
- { id: "jade/shell", about: "bash, bash_output, kill_shell" },
18
- { id: "jade/web", about: "web_fetch, web_search" },
19
- { id: "jade/todo", about: "todo_write" },
20
- { id: "jade/memory", about: "memory tool, memories in the system prompt, /memory" },
21
- { id: "jade/task", about: "task tool (read-only sub-agents)" },
22
- { id: "jade/skills", about: "skill tool, skill list in the system prompt, /skills" },
23
- { id: "jade/mcp", about: "tools of the MCP servers, /mcp" },
24
- { id: "jade/checks", about: "project checks after edits, /checks" },
25
- { id: "jade/compact", about: "compacts the history near the context limit, /compact" },
26
- { id: "jade/budget", about: "limits the steps of a turn" },
27
- { id: "jade/repeats", about: "rejects calls repeated in one response, warns about repeated failures" },
28
- ];
29
-
30
- export const BUILTIN_IDS: ReadonlySet<string> = new Set(BUILTINS.map((b) => b.id));
31
- export const REQUIRED_IDS: ReadonlySet<string> = new Set(BUILTINS.filter((b) => b.required).map((b) => b.id));
@@ -1,217 +0,0 @@
1
- // 内置插件里和界面有关的部分:/memory、/skills、/mcp、/checks、/compact 这些斜杠命令,
2
- // 以及把一段系统提示词、一个"第几次回复"计数器挂到插件上的小工具。
3
- // 命令用的是第三方插件同样的 PluginCommand 接口(ctx.ui 交互、ctx.note 告诉模型),停用插件时命令也一起消失。
4
-
5
- import path from "node:path";
6
- import type { HookSpec, SystemSegment, Trust } from "uncarved";
7
- import type { Check, Checks } from "./checks.ts";
8
- import type { Compactor } from "./compact.ts";
9
- import type { JadePlugin, PluginCommand } from "./loader.ts";
10
- import { MEMORY_SCOPES, type Memory, type MemoryScope } from "../memory.ts";
11
- import { describeServer, type McpClient } from "../mcp.ts";
12
- import type { Skill } from "../skills.ts";
13
- import { display } from "../tools/fs.ts";
14
- import { clip } from "../ui/render.ts";
15
- import { bold, dim, green, red, yellow } from "../ui/screen.ts";
16
-
17
- /** 给插件加一个 context.build hook,把这些段落接在已有的系统提示词后面 */
18
- export function withSystem<T extends JadePlugin>(plugin: T, parts: { text: string; trust: Trust }[]): T {
19
- if (parts.length === 0) return plugin;
20
- const segments: SystemSegment[] = parts.map(({ text, trust }) => ({ text, trust, stability: "stable", origin: { by: "plugin", id: plugin.id } }));
21
- return addHook(plugin, { kind: "transform", point: "context.build", fn: (req) => ({ ...req, system: [...req.system, ...segments] }) });
22
- }
23
-
24
- /** 每次请求模型前加一:工具据此判断两个调用是不是同一次回复里发出的 */
25
- export function withCounter<T extends JadePlugin>(plugin: T, counter: { calls: number }): T {
26
- return addHook(plugin, {
27
- kind: "transform",
28
- point: "model.before",
29
- fn: () => {
30
- counter.calls++;
31
- },
32
- });
33
- }
34
-
35
- function addHook<T extends JadePlugin>(plugin: T, hook: HookSpec): T {
36
- const need = `${hook.kind}:${hook.point}`;
37
- return { ...plugin, hooks: [...(plugin.hooks ?? []), hook], needs: [...new Set([...(plugin.needs ?? []), need])] };
38
- }
39
-
40
- // ---------- /memory ----------
41
-
42
- export function memoryCommand(memory: Memory): PluginCommand {
43
- return {
44
- name: "memory",
45
- args: "[text]",
46
- description: "see and remove what jade remembers across sessions, or remember text",
47
- instant: true,
48
- async run(args, { ui, note }) {
49
- let text = args.trim();
50
- if (!text) {
51
- const entries = (await Promise.all(MEMORY_SCOPES.map(async (scope) => (await memory.list(scope)).map((t) => ({ scope, text: t }))))).flat();
52
- if (!ui.interactive) return entries.length ? entries.map((e) => `${e.scope}: ${e.text}`).join("\n") : "jade does not remember anything yet";
53
- const choice = await ui.select<{ scope: MemoryScope; text: string } | "add">(
54
- entries.length ? "Memory: choose an entry to remove it, or add one" : "jade does not remember anything yet",
55
- [{ label: "Add a memory…", value: "add" as const }, ...entries.map((e) => ({ label: e.text, value: e, hint: e.scope }))],
56
- { body: dim(`user (all projects): ${memory.files.user}\nproject: ${memory.files.project}`) },
57
- );
58
- if (!choice) return;
59
- if (choice !== "add") {
60
- const ok = await ui.select(
61
- `Remove this ${choice.scope} memory?`,
62
- [
63
- { label: "No", value: false },
64
- { label: "Yes, remove it", value: true },
65
- ],
66
- { body: choice.text },
67
- );
68
- if (!ok) return;
69
- await memory.remove(choice.scope, choice.text);
70
- note(`The user removed this ${choice.scope} memory, so stop following it: ${choice.text}`);
71
- return green(`Removed from ${choice.scope} memory: ${choice.text}`);
72
- }
73
- text = (await ui.input("What should jade remember?", { placeholder: "e.g. Reply in Chinese; run tests with bun test" })) ?? "";
74
- if (!text) return;
75
- }
76
- const scope = await ui.select<MemoryScope>("Remember it for", [
77
- { label: "All projects", value: "user", hint: "user memory" },
78
- { label: "This project only", value: "project", hint: "project memory" },
79
- ]);
80
- if (!scope) return;
81
- const added = await memory.add(scope, text);
82
- if (added) note(`The user saved a ${scope} memory; follow it from now on: ${text}`);
83
- return added ? green(`Saved to ${scope} memory.`) : dim(`The ${scope} memory already has this.`);
84
- },
85
- };
86
- }
87
-
88
- // ---------- /skills ----------
89
-
90
- export function skillsCommand(skills: Skill[], opts: { cwd: string; home: string }): PluginCommand {
91
- return {
92
- name: "skills",
93
- description: "skills the agent can use",
94
- instant: true,
95
- run() {
96
- if (skills.length === 0) {
97
- return dim(`(no skills) put them in ${display(opts.cwd, path.join(opts.home, "skills"))}/<name>/SKILL.md or .jade/skills/<name>/SKILL.md`);
98
- }
99
- return skills
100
- .map((sk) => {
101
- const from = sk.plugin ? `plugin ${sk.plugin}` : sk.layer;
102
- return `${bold(sk.name)} ${dim(`${from} · ${display(opts.cwd, sk.dir)}`)}\n ${clip(sk.description.replace(/\s+/g, " "), 300)}`;
103
- })
104
- .join("\n");
105
- },
106
- };
107
- }
108
-
109
- // ---------- /mcp ----------
110
-
111
- export function mcpCommand(clients: McpClient[], opts: { cwd: string; home: string }): PluginCommand {
112
- return {
113
- name: "mcp",
114
- args: "[reconnect <name>]",
115
- description: "MCP servers: status and tools",
116
- instant: true,
117
- async run(args) {
118
- const words = args.trim().split(/\s+/).filter(Boolean);
119
- if (words[0] === "reconnect") {
120
- const c = clients.find((x) => x.name === words[1]);
121
- if (!c) return red(`usage: /mcp reconnect <name>; servers: ${clients.map((x) => x.name).join(", ") || "(none)"}`);
122
- await c.close();
123
- try {
124
- await c.connect();
125
- return green(`${c.name} connected, ${c.tools.length} tools`);
126
- } catch (err) {
127
- return red(`${c.name}: ${err instanceof Error ? err.message : String(err)}`);
128
- }
129
- }
130
- if (clients.length === 0) {
131
- return dim(`(no MCP servers) configure them in ${display(opts.cwd, path.join(opts.home, "mcp.json"))}, .mcp.json or .jade/mcp.json`);
132
- }
133
- const lines: string[] = [];
134
- for (const c of clients) {
135
- const state = c.status === "connected" ? green("connected") : c.status === "failed" ? red("failed") : yellow(c.status);
136
- const info = c.serverInfo?.name ? ` · ${c.serverInfo.name}${c.serverInfo.version ? ` ${c.serverInfo.version}` : ""}` : "";
137
- const from = c.entry.plugin ? `plugin ${c.entry.plugin}` : `${c.entry.layer} · ${display(opts.cwd, c.entry.file)}`;
138
- lines.push(`${bold(c.name)} ${state} ${dim(`${from} · ${describeServer(c.entry.config)}${info}`)}`);
139
- if (c.error) lines.push(red(` ${c.error}`));
140
- if (c.tools.length) {
141
- lines.push(` tools ${c.tools.map((t) => `${t.name}${t.annotations?.readOnlyHint ? dim(" (read)") : ""}`).join(", ")}`);
142
- }
143
- if (c.status === "failed" && c.stderr.length) lines.push(dim(c.stderr.map((l) => ` │ ${clip(l, 200)}`).join("\n")));
144
- }
145
- return lines.join("\n");
146
- },
147
- };
148
- }
149
-
150
- /** MCP 服务在初始化时给出的使用说明,放进系统提示词(来自外部,untrusted) */
151
- export function mcpInstructions(clients: McpClient[]): { text: string; trust: Trust }[] {
152
- return clients
153
- .filter((c) => c.status === "connected" && c.instructions)
154
- .map((c) => ({ text: `# Instructions from the MCP server "${c.name}" (about its mcp__${c.name}__* tools)\n\n${c.instructions}`, trust: "untrusted" as const }));
155
- }
156
-
157
- // ---------- /checks ----------
158
-
159
- export interface ChecksCommandOptions {
160
- cwd: string;
161
- home: string;
162
- /** 本会话改过的文件 */
163
- changed(sessionId: string): Promise<string[]>;
164
- /** 这条检查命令用户是否已经确认过 */
165
- confirmed?(check: Check): Promise<boolean>;
166
- /** 没有检查时的原因 */
167
- unavailable?: string;
168
- }
169
-
170
- export function checksCommand(checks: Checks | undefined, opts: ChecksCommandOptions): PluginCommand {
171
- return {
172
- name: "checks",
173
- args: "[on|off]",
174
- description: "checks jade runs after the agent edits files (type checker, linter)",
175
- instant: true,
176
- async run(args, { sessionId }) {
177
- if (!checks) return dim(opts.unavailable ?? "Edit-time checks are not available.");
178
- const arg = args.trim();
179
- if (arg === "on" || arg === "off") {
180
- checks.enabled = arg === "on";
181
- if (arg === "on") checks.reset();
182
- return `checks: ${arg}`;
183
- }
184
- if (arg) return red("usage: /checks [on|off]");
185
- const files = await opts.changed(sessionId);
186
- const found = await checks.resolve(files);
187
- const lines = [`Edit-time checks are ${checks.enabled ? "on" : "off"} in this session.`];
188
- if (found.length > 0) {
189
- lines.push("For the files changed in this session:");
190
- for (const c of found) {
191
- const pending = opts.confirmed && !(await opts.confirmed(c)) ? ", not confirmed yet" : "";
192
- lines.push(` ${bold(c.name)} ${dim(`in ${display(opts.cwd, c.cwd) || "."}${pending}`)}\n ${dim(c.command)}`);
193
- }
194
- } else lines.push(dim(files.length ? "No checks apply to the files changed in this session." : "No files changed in this session yet."));
195
- lines.push(
196
- dim(
197
- "Detected per file: TypeScript (nearest tsconfig.json + the project's typescript), Python (ruff), Go (go vet).\n" +
198
- `Add your own in .jade/checks.json or ${path.join(opts.home, "checks.json")}; JADE_CHECKS=off turns them off.`,
199
- ),
200
- );
201
- return lines.join("\n");
202
- },
203
- };
204
- }
205
-
206
- // ---------- /compact ----------
207
-
208
- export function compactCommand(compact: Compactor): PluginCommand {
209
- return {
210
- name: "compact",
211
- description: "compact the history before the next request",
212
- run() {
213
- compact.request();
214
- return dim("History will be compacted before the next request.");
215
- },
216
- };
217
- }