@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
package/src/distro.ts DELETED
@@ -1,577 +0,0 @@
1
- // 组装发行版:内核之外的功能都是插件。内置插件(见 plugins/builtins.ts)和第三方插件用同一套接口,
2
- // 在这里拼成一份插件清单。宿主(main.ts)和测试都通过这里创建,内核本身不知道这些插件的存在。
3
- //
4
- // 用户可以停用内置插件($JADE_HOME/plugins.json),第三方插件可以在 plugin.json 里用 replaces 代替内置插件;jade/policy 两者都不行。
5
-
6
- import path from "node:path";
7
- import { checkCompat, definePlugin, subsetPlugin, type LogStore, type ModelRequest, type Plugin, type Provider, type Tool } from "uncarved";
8
- import { budget } from "./plugins/budget.ts";
9
- import { BUILTINS, BUILTIN_IDS, REQUIRED_IDS } from "./plugins/builtins.ts";
10
- import { checks as checksPlugin, type ApproveCheck, type Check, type Checks } from "./plugins/checks.ts";
11
- import { checksCommand, compactCommand, mcpCommand, mcpInstructions, memoryCommand, searchCommand, skillsCommand, withCounter, withSystem } from "./plugins/core.ts";
12
- import { Memory, memoryTool } from "./memory.ts";
13
- import { mcpTools, type McpClient } from "./mcp.ts";
14
- import { skillTool, skillsPrompt, type Skill } from "./skills.ts";
15
- import { compactor, type Compactor } from "./plugins/compact.ts";
16
- import { COMMAND_NAME, DISPOSE_TIMEOUT_MS, JADE_VERSION, KEY_SPEC, RESERVED_KEYS, type HostContext, type HostInput, type PluginKey, type ToolRenderer, type JadePlugin, type LoadedPlugin, type PluginCommand } from "./plugins/loader.ts";
17
- import { policy, type AllowRule, type Mode, type Policy, type PolicyOptions } from "./plugins/policy.ts";
18
- import { prompts, realPath, repoRoot } from "./plugins/prompts.ts";
19
- import { repeats } from "./plugins/repeats.ts";
20
- import { sessionsPlugin, undoPlugin } from "./plugins/sessions.ts";
21
- import { fsTools } from "./tools/fs.ts";
22
- import { Checkpoints } from "./tools/checkpoint.ts";
23
- import { shellTools } from "./tools/shell.ts";
24
- import { taskTool, type ApproveSubagent, type SubagentControl } from "./tools/task.ts";
25
- import { todoTool } from "./tools/todo.ts";
26
- import { askUserTool, type AskUser } from "./tools/ask.ts";
27
- import { webTools } from "./tools/web.ts";
28
- import { screenshotTool } from "./tools/screenshot.ts";
29
- import { askRenderers, fsRenderers, memoryRenderers, shellRenderers, taskRenderers, todoRenderers, webRenderers } from "./ui/renderers.ts";
30
- import { visionFromEnv } from "./provider.ts";
31
-
32
- const READ_ONLY = new Set(["read_file", "list_dir", "glob", "grep"]);
33
- /** 子 Agent 也执行的第三方插件 hook */
34
- const TOOL_HOOKS: ReadonlySet<string> = new Set(["tool.gate", "tool.before", "tool.after"]);
35
- /** 子 Agent 一轮最多调用模型的次数(子 Agent 的提示词里写的是同一个数) */
36
- const SUBAGENT_STEPS = 40;
37
-
38
- export interface JadeOptions {
39
- cwd: string;
40
- /** 用户层配置目录 */
41
- home: string;
42
- store: LogStore;
43
- provider: Provider;
44
- mode?: Mode;
45
- /** 已经通过 loadProjectPlugin 确认过的项目层插件,原样加入 */
46
- projectPlugins?: Plugin[];
47
- /** 用 loadPlugin 加载的第三方插件(用户层和项目层),每次 createJade 创建一套新实例 */
48
- extensions?: LoadedPlugin[];
49
- /** 停用的内置插件的 id(第三方插件由宿主在加载前按 id 筛掉,见 resolvePlugins) */
50
- disabled?: Iterable<string>;
51
- /** 压缩阈值;传函数时每次投影前取值 */
52
- compactTokens?: number | (() => number);
53
- maxSteps?: number;
54
- /** 当前配置的模型,写进主 Agent 的系统提示词(见 prompts 的 model);每次请求时取 */
55
- model?: () => { name: string; via: string } | undefined;
56
- /** 会话的临时目录:写进提示词让模型把临时文件放这里;关卡按工作目录对待,修改前不用先读 */
57
- scratch?: string;
58
- /** 测试用 */
59
- today?: string;
60
- /** 读取搜索服务配置用,默认 process.env;测试用 */
61
- env?: Record<string, string | undefined>;
62
- /** web 工具用的 fetch;测试用 */
63
- fetch?: typeof fetch;
64
- /** web 工具解析主机名用;测试用 */
65
- lookup?: (hostname: string) => Promise<string[]>;
66
- /** 截图用的浏览器;不给时按 JADE_BROWSER 和常见安装位置找,null 表示不提供截图工具 */
67
- browser?: string | null;
68
- /** ask_user 工具向用户提问;不给就不提供这个工具 */
69
- askUser?: AskUser;
70
- /** 子 Agent 要用户批准的调用(例如 web_fetch)交给宿主;不给就拒绝 */
71
- approveSubagent?: ApproveSubagent;
72
- /** 子 Agent 也遵守的"总是允许"规则(主会话的),每次判断时取 */
73
- sharedRules?: () => AllowRule[];
74
- /** 运行中切换、还没记进日志的权限模式(见 PolicyOptions.pendingMode) */
75
- pendingMode?: () => Mode | undefined;
76
- /** auto 模式下审查规则判断不了的调用(见 PolicyOptions.review);不给时 auto 模式不审查 */
77
- review?: PolicyOptions["review"];
78
- /**
79
- * 编辑后检查的命令第一次运行前由宿主确认;不给就不做编辑后检查。
80
- * 检查会执行仓库里的代码,所以不能默认放行
81
- */
82
- approveCheck?: ApproveCheck;
83
- /** /checks 显示一条检查是否已经确认过 */
84
- checkConfirmed?: (check: Check) => Promise<boolean>;
85
- /** 没有 approveCheck 时 /checks 给出的原因 */
86
- checksUnavailable?: string;
87
- /** 已连接的 MCP 服务,它们的工具加进主会话(声明只读的也给子 Agent) */
88
- mcp?: McpClient[];
89
- /** loadSkills 找到的 skill */
90
- skills?: Skill[];
91
- /** 插件用 ctx.status 设置状态栏上自己的那一段;plugin 是插件的 id,text 为 undefined 时去掉 */
92
- onStatus?(plugin: string, text: string | undefined): void;
93
- /** 终端界面的输入框,给用户层插件的 ctx.input(多一个参数:调用的插件的 id);-p 时没有 */
94
- input?: HostInput;
95
- /** 用户层插件的 ctx.send:替用户提交一行;plugin 是插件的 id。-p 时没有 */
96
- send?(plugin: string, text: string): void;
97
- /** 插件的 ctx.signal:这套实例的会话结束时中止(见 SessionScope);不给时永不中止 */
98
- signal?: AbortSignal;
99
- }
100
-
101
- export interface BuiltinState {
102
- id: string;
103
- about: string;
104
- required?: boolean;
105
- /** on:加载了;disabled:用户停用;replaced:被第三方插件代替 */
106
- state: "on" | "disabled" | "replaced";
107
- /** 代替它的插件 */
108
- by?: string;
109
- }
110
-
111
- export interface Jade {
112
- plugins: Plugin[];
113
- policy: Policy;
114
- /** jade/compact 停用或被代替时没有 */
115
- compact?: Compactor;
116
- /** write_file / edit_file 写入前的快照,供 /undo */
117
- checkpoints: Checkpoints;
118
- /** 跨会话的记忆;jade/memory 停用或被代替时没有 */
119
- memory?: Memory;
120
- /** 编辑后检查;没有 shell、宿主没给 approveCheck、jade/checks 停用时为 undefined */
121
- checks?: Checks;
122
- /** 每个内置插件的状态 */
123
- builtins: BuiltinState[];
124
- /** 成功加入本会话的第三方插件实例 */
125
- extensions: Extension[];
126
- /** 插件(内置的和第三方的)提供的斜杠命令,按小写的名字 */
127
- commands: Map<string, { plugin: string; command: PluginCommand; builtin: boolean }>;
128
- /** 第三方插件为自己的工具注册的显示方式,按工具名 */
129
- renderers: Map<string, { plugin: string; renderer: ToolRenderer }>;
130
- /** 第三方插件的快捷键,按 KEY_SPEC 的写法(小写) */
131
- keys: Map<string, { plugin: string; key: PluginKey }>;
132
- /** 主会话的工具;宿主用 read_file / list_dir 读取 @ 引用的文件 */
133
- tools: Tool[];
134
- /**
135
- * 不再用这套实例时调用(在 shutdown 和会话收尾之后):调用第三方插件的 dispose,同时进行、各自限时。
136
- * 只执行一次;返回要告诉用户的问题
137
- */
138
- dispose(): Promise<string[]>;
139
- /** 宿主退出时调用:杀掉后台 shell */
140
- shutdown(): void;
141
- /** 启动时要告诉用户的问题,例如找不到 shell */
142
- warnings: string[];
143
- }
144
-
145
- /**
146
- * 加入本会话的一个第三方插件实例,和 jade 从它上面检查过、留下的扩展点。jade 只用这里的,不改写实例:
147
- * 进程外插件的实例是在会话之间共用的进程对象(它的快捷键和命令每套单独生成,见 LoadedPlugin.adapters),
148
- * 项目层插件的实例是内核认的那个对象(宪法 7.1)。不合格的扩展点不在这里,并且已经给出警告
149
- */
150
- export interface Extension {
151
- source: LoadedPlugin;
152
- plugin: JadePlugin;
153
- commands: PluginCommand[];
154
- keys: PluginKey[];
155
- renderers: ToolRenderer[];
156
- }
157
-
158
- export async function createJade(opts: JadeOptions): Promise<Jade> {
159
- const { cwd, store, provider } = opts;
160
- const skills = opts.skills ?? [];
161
- const mcp = opts.mcp ?? [];
162
- const warnings: string[] = [];
163
-
164
- const disabled = new Set(opts.disabled ?? []);
165
- for (const id of REQUIRED_IDS) {
166
- if (disabled.has(id)) {
167
- warnings.push(`${id} cannot be disabled (it decides which tool calls need your approval); it stays on`);
168
- disabled.delete(id);
169
- }
170
- }
171
- const off = (id: string) => disabled.has(id);
172
-
173
- const checkpoints = new Checkpoints(path.join(opts.home, "checkpoints"));
174
- // run 也给插件和编辑后检查用,所以 jade/shell 停用时也创建,只是不把工具交给模型
175
- const shell = shellTools({ cwd });
176
- const root = await repoRoot(cwd);
177
- const host: HostContext = { jade: JADE_VERSION, cwd: realPath(cwd), root: realPath(root), home: opts.home, definePlugin, run: shell.run, complete: completer(provider), status: (plugin, text) => opts.onStatus?.(plugin, text), checkpoints, input: opts.input, send: opts.send, signal: opts.signal ?? new AbortController().signal };
178
-
179
- // 第三方插件先创建:要先知道它们代替哪些内置插件
180
- const made = await createExtensions(opts.extensions ?? [], host, warnings);
181
-
182
- // ---------- 内置插件(jade/prompts 最后创建:它要知道最终有哪些工具) ----------
183
- const built = new Map<string, JadePlugin>();
184
- const add = (p: JadePlugin) => built.set(p.id, p);
185
-
186
- const pol = policy({ cwd, mode: opts.mode, pendingMode: opts.pendingMode, review: opts.review, readRoots: off("jade/skills") ? [] : skills.map((x) => x.dir), scratch: opts.scratch });
187
- add(pol.plugin);
188
- // 占位,组装完成后换成真正的提示词插件
189
- if (!off("jade/prompts")) add({ id: "jade/prompts", version: "0.3.0", kernel: "^0.1" });
190
-
191
- // 文件工具据此判断读取和修改是不是同一次回复里发出的
192
- const responses = { calls: 0 };
193
- if (!off("jade/fs")) add(withCounter({ id: "jade/fs", version: "0.1.0", kernel: "^0.1", tools: fsTools(cwd, { checkpoints, responses, scratch: opts.scratch }), renderers: fsRenderers(cwd) }, responses));
194
- if (!off("jade/shell")) add({ id: "jade/shell", version: "0.1.0", kernel: "^0.1", tools: shell.tools, renderers: shellRenderers });
195
- let web: Tool[] = [];
196
- let hasScreenshot = false;
197
- if (!off("jade/web")) {
198
- try {
199
- web = webTools({ env: opts.env, fetch: opts.fetch, lookup: opts.lookup }).tools;
200
- } catch (err) {
201
- warnings.push(`web tools are disabled: ${err instanceof Error ? err.message : String(err)}`);
202
- }
203
- // 截图只在模型能看图片时有用,否则截图到了模型那里只剩占位说明。/model 运行中会换模型、改 JADE_VISION,
204
- // 所以找到浏览器就注册,每次请求前按当时的设置决定发不发给模型,不用重启
205
- const canSee = () => {
206
- try {
207
- return visionFromEnv(opts.env ?? process.env);
208
- } catch {
209
- // 写错的 JADE_VISION 在创建 provider 时报错
210
- return false;
211
- }
212
- };
213
- const shot = opts.browser !== null ? screenshotTool({ cwd, browser: opts.browser, env: opts.env, available: canSee }) : undefined;
214
- hasScreenshot = shot !== undefined;
215
- add({
216
- id: "jade/web",
217
- version: "0.2.0",
218
- kernel: "^0.1",
219
- tools: shot ? [...web, shot] : web,
220
- renderers: webRenderers,
221
- commands: [searchCommand({ envFile: path.join(opts.home, ".env"), env: opts.env })],
222
- ...(shot
223
- ? {
224
- needs: ["transform:context.build"],
225
- hooks: [
226
- {
227
- kind: "transform",
228
- point: "context.build",
229
- fn: (req: ModelRequest) => (canSee() ? req : { ...req, tools: req.tools.filter((t) => t.name !== shot.name) }),
230
- },
231
- ],
232
- }
233
- : {}),
234
- });
235
- }
236
- if (!off("jade/todo")) add({ id: "jade/todo", version: "0.1.0", kernel: "^0.1", tools: [todoTool()], renderers: todoRenderers });
237
- if (!off("jade/ask") && opts.askUser) add({ id: "jade/ask", version: "0.1.0", kernel: "^0.1", tools: [askUserTool(opts.askUser)], renderers: askRenderers });
238
-
239
- let memory: Memory | undefined;
240
- if (!off("jade/memory")) {
241
- memory = new Memory(opts.home, root);
242
- const text = await memory.prompt();
243
- add(withSystem({ id: "jade/memory", version: "0.1.0", kernel: "^0.1", tools: [memoryTool(memory)], commands: [memoryCommand(memory)], renderers: memoryRenderers }, text ? [{ text, trust: "trusted" }] : []));
244
- }
245
-
246
- /** 最终加载了的内置插件,子 Agent 据此决定给哪些工具;组装完成后才填上 */
247
- const kept = new Set<string>();
248
- /** 子 Agent 的提示词,组装完成后生成 */
249
- const subSystem: { plugin?: Plugin } = {};
250
- /** 第三方插件(项目层和用户层),组装完成后填上 */
251
- let thirdParty: Plugin[] = [];
252
- if (!off("jade/task")) {
253
- const subagentPlugins = subagent(opts, subSystem, () => ({
254
- fs: kept.has("jade/fs"),
255
- web: kept.has("jade/web") ? web : [],
256
- mcp: kept.has("jade/mcp") ? mcp : [],
257
- extensions: thirdParty,
258
- }));
259
- add({ id: "jade/task", version: "0.1.0", kernel: "^0.1", tools: [taskTool({ store, provider, plugins: subagentPlugins, approve: opts.approveSubagent })], renderers: taskRenderers });
260
- }
261
-
262
- if (!off("jade/skills")) {
263
- const list = skillsPrompt(skills);
264
- // 有随仓库分发的 skill 时这段是 untrusted
265
- const trust = skills.every((x) => x.layer === "user") ? "trusted" : "untrusted";
266
- add(
267
- withSystem(
268
- { id: "jade/skills", version: "0.1.0", kernel: "^0.1", tools: skills.length ? [skillTool(skills)] : [], commands: [skillsCommand(skills, { cwd, home: opts.home })] },
269
- list ? [{ text: list, trust }] : [],
270
- ),
271
- );
272
- }
273
- if (!off("jade/mcp")) {
274
- add(withSystem({ id: "jade/mcp", version: "0.1.0", kernel: "^0.1", tools: mcpTools(mcp), commands: [mcpCommand(mcp, { cwd, home: opts.home })] }, mcpInstructions(mcp)));
275
- }
276
-
277
- let checks: Checks | undefined;
278
- if (!off("jade/checks")) {
279
- checks =
280
- shell.run && opts.approveCheck
281
- ? checksPlugin({ cwd: realPath(cwd), root: realPath(root), home: opts.home, run: shell.run, approve: opts.approveCheck })
282
- : undefined;
283
- const command = checksCommand(checks, {
284
- cwd,
285
- home: opts.home,
286
- changed: async (sessionId) => [...new Set((await checkpoints.list(sessionId)).map((c) => c.path))],
287
- confirmed: opts.checkConfirmed,
288
- unavailable: opts.checksUnavailable ?? (shell.run ? "Edit-time checks are turned off." : "Edit-time checks need a shell; see the warning at startup."),
289
- });
290
- add(checks ? { ...checks.plugin, commands: [command] } : { id: "jade/checks", version: "0.1.0", kernel: "^0.1", commands: [command] });
291
- }
292
- let compact: Compactor | undefined;
293
- if (!off("jade/compact")) {
294
- compact = compactor({ provider, thresholdTokens: opts.compactTokens });
295
- add({ ...compact.plugin, commands: [compactCommand(compact)] });
296
- }
297
- if (!off("jade/budget")) add(budget({ maxSteps: opts.maxSteps }));
298
- if (!off("jade/sessions")) add(sessionsPlugin());
299
- if (!off("jade/undo")) add(undoPlugin(host));
300
- if (!off("jade/repeats")) {
301
- // 自己数回复次数:不依赖 jade/fs 是否加载
302
- const own = { calls: 0 };
303
- add(withCounter(repeats({ responses: own, cwd }), own));
304
- }
305
-
306
- // ---------- 代替关系:被代替的内置插件让位,代替者的工具名可以和它重复 ----------
307
- // 代替关系写在清单里(plugin.json 的 replaces),不看实例
308
- const claims = (m: Extension) => (m.source.info.replaces ?? []).filter((id) => BUILTIN_IDS.has(id) && !REQUIRED_IDS.has(id) && built.has(id));
309
- for (const { source, plugin } of made) {
310
- for (const id of source.info.replaces ?? []) {
311
- if (REQUIRED_IDS.has(id)) warnings.push(`plugin ${plugin.id} (${source.layer}): cannot replace ${id}; add a gate hook to make approvals stricter instead`);
312
- else if (!BUILTIN_IDS.has(id)) warnings.push(`plugin ${plugin.id} (${source.layer}): replaces unknown built-in plugin ${id}`);
313
- }
314
- }
315
- // 从"全部声明都生效"开始;被拒绝的插件声明的代替撤销,内置插件回来之后可能又拒绝别的插件,直到不再变化
316
- let replaced = new Set(made.flatMap(claims));
317
- let result: ReturnType<typeof accept>;
318
- for (;;) {
319
- result = accept(made, [...built.values()].filter((p) => !replaced.has(p.id)));
320
- const next = new Set(result.accepted.flatMap(claims));
321
- if (next.size === replaced.size) break;
322
- replaced = next;
323
- }
324
- warnings.push(...result.rejected);
325
- const added = result.accepted;
326
- // 被拒绝的实例不会再用:现在就收尾
327
- for (const m of made) {
328
- if (added.includes(m)) continue;
329
- const w = await disposeInstance(m.source, m.plugin);
330
- if (w) warnings.push(w);
331
- }
332
- let disposing: Promise<string[]> | undefined;
333
- const builtin = [...built.values()].filter((p) => !replaced.has(p.id));
334
- for (const p of builtin) kept.add(p.id);
335
-
336
- const allTools = [...builtin, ...added.map((a) => a.plugin)].flatMap((p) => p.tools ?? []);
337
- const toolNames = new Set(allTools.map((t) => t.name));
338
- const webNames = kept.has("jade/web") ? web.map((t) => t.name) : [];
339
- const at = builtin.findIndex((p) => p.id === "jade/prompts");
340
- // 子 Agent 的提示词和主 Agent 的同时生成:两者都要跑几个 git 命令
341
- const subPrompts = kept.has("jade/task") ? prompts({ cwd, home: opts.home, role: "subagent", today: opts.today, web: webNames }) : undefined;
342
- if (at >= 0) {
343
- builtin[at] = await prompts({
344
- cwd,
345
- home: opts.home,
346
- today: opts.today,
347
- // bash 由别的插件提供时不知道它用什么 shell,不写
348
- shell: toolNames.has("bash") ? (kept.has("jade/shell") ? (shell.executable ?? null) : undefined) : null,
349
- web: webNames,
350
- screenshot: hasScreenshot,
351
- checks: kept.has("jade/checks") && Boolean(checks),
352
- scratch: opts.scratch,
353
- tools: toolNames,
354
- model: opts.model,
355
- });
356
- }
357
- if (subPrompts) subSystem.plugin = await subPrompts;
358
-
359
- const builtins: BuiltinState[] = BUILTINS.map((b) => {
360
- if (kept.has(b.id)) return { ...b, state: "on" as const };
361
- const by = added.find((a) => claims(a).includes(b.id))?.plugin.id;
362
- return by ? { ...b, state: "replaced" as const, by } : { ...b, state: "disabled" as const };
363
- });
364
-
365
- thirdParty = [...(opts.projectPlugins ?? []), ...added.map((a) => a.plugin)];
366
- const plugins = [...builtin, ...thirdParty];
367
- const commands = new Map<string, { plugin: string; command: PluginCommand; builtin: boolean }>();
368
- const owners = [
369
- ...(builtin as JadePlugin[]).map((p) => ({ id: p.id, commands: p.commands ?? [], builtin: BUILTIN_IDS.has(p.id) })),
370
- ...added.map((a) => ({ id: a.plugin.id, commands: a.commands, builtin: false })),
371
- ];
372
- for (const p of owners) {
373
- for (const c of p.commands) {
374
- const taken = commands.get(c.name.toLowerCase());
375
- if (taken) warnings.push(`plugin ${p.id}: command /${c.name} is ignored: plugin ${taken.plugin} already provides it`);
376
- else commands.set(c.name.toLowerCase(), { plugin: p.id, command: c, builtin: p.builtin });
377
- }
378
- }
379
- const keys = new Map<string, { plugin: string; key: PluginKey }>();
380
- for (const { plugin, keys: own } of added) {
381
- for (const k of own) {
382
- const taken = keys.get(k.key);
383
- if (taken) warnings.push(`plugin ${plugin.id}: key ${k.key} is ignored: plugin ${taken.plugin} already uses it`);
384
- else keys.set(k.key, { plugin: plugin.id, key: k });
385
- }
386
- }
387
- if (shell.unavailable && kept.has("jade/shell")) warnings.push(shell.unavailable);
388
- return {
389
- plugins,
390
- policy: pol,
391
- compact: kept.has("jade/compact") ? compact : undefined,
392
- checkpoints,
393
- memory: kept.has("jade/memory") ? memory : undefined,
394
- checks: kept.has("jade/checks") ? checks : undefined,
395
- builtins,
396
- extensions: added,
397
- commands,
398
- keys,
399
- renderers: new Map(
400
- [...(builtin as JadePlugin[]).map((p) => ({ id: p.id, renderers: p.renderers ?? [] })), ...added.map((a) => ({ id: a.plugin.id, renderers: a.renderers }))].flatMap((p) =>
401
- p.renderers.map((r) => [r.tool, { plugin: p.id, renderer: r }] as const),
402
- ),
403
- ),
404
- dispose: () => (disposing ??= Promise.all(added.map(({ source, plugin }) => disposeInstance(source, plugin))).then((ws) => ws.filter((w): w is string => w !== undefined))),
405
- tools: allTools,
406
- shutdown: shell.shutdown,
407
- warnings,
408
- };
409
- }
410
-
411
- /**
412
- * 创建第三方插件的实例。有问题的插件跳过并给出警告,而不是让整个 jade 起不来:工厂出错、内核不兼容、命令格式不对。
413
- * 只带内容(skills、命令、MCP 配置)的插件没有实例,由宿主处理
414
- */
415
- async function createExtensions(sources: LoadedPlugin[], host: HostContext, warnings: string[]): Promise<Extension[]> {
416
- const out: Extension[] = [];
417
- /** 创建了却不用的实例也要收尾 */
418
- const discard = async (source: LoadedPlugin, plugin: JadePlugin) => {
419
- const w = await disposeInstance(source, plugin);
420
- if (w) warnings.push(w);
421
- };
422
- for (const source of sources) {
423
- if (!source.create) continue;
424
- const where = `plugin ${source.id} (${source.layer})`;
425
- let created: JadePlugin | undefined;
426
- try {
427
- created = await source.create(host);
428
- // 清单里的 id 决定了停用、重复检查和状态栏,实例不能换成别的
429
- if (created.id !== source.id) throw new Error(`its id ${JSON.stringify(created.id)} does not match "id" in plugin.json (use ctx.definePlugin, which fills it in)`);
430
- checkCompat(created);
431
- } catch (err) {
432
- warnings.push(`${where} is skipped: ${err instanceof Error ? err.message : String(err)}`);
433
- if (created) await discard(source, created);
434
- continue;
435
- }
436
- const plugin = created;
437
- // disposeInstance 只调用函数:不合格的不用删
438
- if (plugin.dispose !== undefined && typeof plugin.dispose !== "function") warnings.push(`${where}: dispose is ignored: it must be a function`);
439
- if ("replaces" in plugin) warnings.push(`${where}: replaces is ignored: write it in plugin.json instead ("replaces": ["jade/…"])`);
440
- // 进程外插件的快捷键和命令按清单为这一套生成;模块插件的就在实例上
441
- const parts = source.adapters ? source.adapters(host) : plugin;
442
- const commands = listOf(parts.commands).filter((c): c is PluginCommand => {
443
- const ok = Boolean(c) && typeof c.name === "string" && COMMAND_NAME.test(c.name) && typeof c.run === "function";
444
- if (!ok) warnings.push(`${where}: command ${JSON.stringify(c?.name)} is ignored: it needs a name of letters, digits, - and _, and a run function`);
445
- return ok;
446
- });
447
- // 模型服务不属于某套插件实例:改成在模块里导出(export const providers),加载时就注册。jade 不读实例上的 providers
448
- if ("providers" in plugin) warnings.push(`${where}: providers is ignored: export it from the plugin module instead (export const providers = [...])`);
449
- const keys = listOf(parts.keys).flatMap((k): PluginKey[] => {
450
- const key = typeof k?.key === "string" ? k.key.toLowerCase() : undefined;
451
- if (key !== undefined && KEY_SPEC.test(key) && !RESERVED_KEYS.has(key) && typeof k.run === "function") return [{ key, description: k.description, run: (ctx) => k.run(ctx) }];
452
- warnings.push(`${where}: key ${JSON.stringify(k?.key)} is ignored: it needs a run function and a key like ctrl+<letter> or alt+<letter or digit> that jade does not use itself`);
453
- return [];
454
- });
455
- const own = new Set((plugin.tools ?? []).map((t) => t.name));
456
- const seen = new Set<string>();
457
- // 只认自己的工具:别的工具的显示(尤其是审批时的预览)不能由插件改
458
- const renderers = listOf(plugin.renderers).filter((r) => {
459
- const tool = r?.tool;
460
- const fields = r as unknown as Record<string, unknown> | undefined;
461
- const fns = Boolean(fields) && ["summary", "details", "preview", "before", "result"].every((k) => fields![k] === undefined || typeof fields![k] === "function");
462
- let why: string | undefined;
463
- if (typeof tool !== "string" || !fns) why = "it needs a tool name, and summary, details, preview, before and result must be functions";
464
- else if (!own.has(tool)) why = "a plugin can only render its own tools";
465
- else if (seen.has(tool)) why = "the tool already has a renderer";
466
- if (why) warnings.push(`${where}: renderer for ${JSON.stringify(tool)} is ignored: ${why}`);
467
- else seen.add(tool!);
468
- return !why;
469
- });
470
- // jade 不再提供的扩展点:写了也不起作用,提示一次
471
- for (const gone of REMOVED) if (gone in plugin) warnings.push(`${where}: ${gone} is ignored: jade does not offer it to plugins`);
472
- out.push({ source, plugin, commands, keys, renderers });
473
- }
474
- return out;
475
- }
476
-
477
- /** 去掉了的扩展点(见 docs/design/jade-plugin-lifecycle.md 第 9 节) */
478
- const REMOVED = ["responder", "suggest", "beforeSend"] as const;
479
-
480
- /** 插件给的列表:没给时为空;给的不是数组时当作一个不合格的项,好让上面提示 */
481
- function listOf<T>(v: T[] | undefined): T[] {
482
- return v === undefined ? [] : Array.isArray(v) ? v : [undefined as T];
483
- }
484
-
485
- /**
486
- * 调用第三方插件实例的 dispose,限时 DISPOSE_TIMEOUT_MS;返回要告诉用户的问题,没有时 undefined。
487
- * 进程外插件的进程在会话之间共用,不在这里结束(见 LoadedPlugin.close)
488
- */
489
- async function disposeInstance(source: LoadedPlugin, plugin: JadePlugin): Promise<string | undefined> {
490
- if (source.kind === "process" || typeof plugin.dispose !== "function") return undefined;
491
- const where = `plugin ${source.id} (${source.layer})`;
492
- let timer: ReturnType<typeof setTimeout> | undefined;
493
- const timeout = new Promise<"timeout">((resolve) => {
494
- timer = setTimeout(() => resolve("timeout"), DISPOSE_TIMEOUT_MS);
495
- });
496
- try {
497
- const result = await Promise.race([Promise.resolve().then(() => plugin.dispose!()), timeout]);
498
- return result === "timeout" ? `${where}: dispose did not finish within ${DISPOSE_TIMEOUT_MS / 1000}s` : undefined;
499
- } catch (err) {
500
- return `${where}: dispose failed: ${err instanceof Error ? err.message : String(err)}`;
501
- } finally {
502
- clearTimeout(timer);
503
- }
504
- }
505
-
506
- /** 按顺序检查第三方插件的 id 和工具名不和已有的(留下的内置插件、排在前面的第三方插件)重复 */
507
- function accept(made: Extension[], existing: Plugin[]) {
508
- const ids = new Set(existing.map((p) => p.id));
509
- const toolNames = new Set(existing.flatMap((p) => (p.tools ?? []).map((t) => t.name)));
510
- const accepted: typeof made = [];
511
- const rejected: string[] = [];
512
- for (const m of made) {
513
- const where = `plugin ${m.source.id} (${m.source.layer})`;
514
- if (ids.has(m.plugin.id)) {
515
- rejected.push(`${where} is skipped: another plugin already has the id ${m.plugin.id}`);
516
- continue;
517
- }
518
- // jade、jade/… 留给内置插件:会话里记的键按 id 划分(jade/undo 的撤销记录等),代替内置插件用 replaces,不用它的 id
519
- if (m.plugin.id === "jade" || m.plugin.id.startsWith("jade/")) {
520
- rejected.push(`${where} is skipped: the id ${m.plugin.id} is reserved for jade's built-in plugins (use "replaces" in plugin.json to stand in for one)`);
521
- continue;
522
- }
523
- const clash = (m.plugin.tools ?? []).find((t) => toolNames.has(t.name));
524
- if (clash) {
525
- rejected.push(`${where} is skipped: tool ${clash.name} already exists`);
526
- continue;
527
- }
528
- ids.add(m.plugin.id);
529
- for (const t of m.plugin.tools ?? []) toolNames.add(t.name);
530
- accepted.push(m);
531
- }
532
- return { accepted, rejected };
533
- }
534
-
535
- /** 子 Agent 的插件:只读工具(含 web 工具)、子 Agent 提示词、只读策略(加上主会话的规则)、压缩、步数上限。每次调用返回新实例 */
536
- function subagent(
537
- opts: JadeOptions,
538
- system: { plugin?: Plugin },
539
- available: () => { fs: boolean; web: Tool[]; mcp: McpClient[]; extensions: Plugin[] },
540
- ): (control: SubagentControl) => Plugin[] {
541
- // 有哪些工具要到组装完成才知道,所以每次调用时再取
542
- return (control) => {
543
- const { fs, web, mcp, extensions } = available();
544
- const tools: Plugin = {
545
- id: "jade/tools-readonly",
546
- version: "0.1.0",
547
- kernel: "^0.1",
548
- tools: [...(fs ? fsTools(opts.cwd).filter((t) => READ_ONLY.has(t.name)) : []), ...web, ...mcpTools(mcp, { readOnly: true })],
549
- };
550
- const pol = policy({ cwd: opts.cwd, mode: "readonly", id: "jade/policy-subagent", rules: opts.sharedRules });
551
- // 大范围调研时读的文件多:没有压缩会撑爆上下文,前面的调研全部白做
552
- const compact = compactor({ provider: opts.provider, thresholdTokens: opts.compactTokens, id: "jade/compact-subagent" }).plugin;
553
- const steps = budget({ maxSteps: () => (control.wrapUp ? 1 : SUBAGENT_STEPS), id: "jade/budget-subagent" });
554
- // 第三方插件只带工具级的 hook(拦截、改写参数、给结果脱敏),子 Agent 读到的内容也经过它们;
555
- // 不带它们的工具、提示词和 observe hook(例如按轮次触发的功能不该被子 Agent 触发)
556
- const tooling = extensions
557
- .map((p) => subsetPlugin(p, { tools: () => false, hooks: (h) => TOOL_HOOKS.has(h.point) }))
558
- .filter((p) => p.hooks?.length);
559
- return [tools, ...(system.plugin ? [system.plugin] : []), pol.plugin, compact, steps, ...tooling];
560
- };
561
- }
562
-
563
- /** 插件上下文的 complete:用会话的 provider 发一次不带工具的请求 */
564
- function completer(provider: Provider): HostContext["complete"] {
565
- const origin = { by: "plugin", id: "jade/extension" } as const;
566
- return async (req, signal) => {
567
- const res = await provider.complete(
568
- {
569
- system: req.system ? [{ text: req.system, stability: "stable", origin, trust: "trusted" }] : [],
570
- messages: [{ role: "user", content: [{ kind: "text", text: req.prompt, origin, trust: "untrusted" }] }],
571
- tools: [],
572
- },
573
- { signal, onDelta: req.onText && ((d) => void (d.kind === "text" && req.onText!(d.text))) },
574
- );
575
- return { text: res.content.flatMap((b) => (b.kind === "text" ? [b.text] : [])).join(""), model: res.model, usage: res.usage };
576
- };
577
- }