@uncarved/jade 0.1.3 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (450) hide show
  1. package/bin/jade.js +5 -27
  2. package/dist/api.d.ts +266 -0
  3. package/dist/api.js +38 -0
  4. package/dist/api.js.map +1 -0
  5. package/dist/config.d.ts +13 -32
  6. package/dist/config.js +39 -121
  7. package/dist/config.js.map +1 -1
  8. package/dist/fetch.d.ts +20 -0
  9. package/dist/fetch.js +190 -0
  10. package/dist/fetch.js.map +1 -0
  11. package/dist/hash.d.ts +2 -0
  12. package/dist/hash.js +42 -0
  13. package/dist/hash.js.map +1 -0
  14. package/dist/host.d.ts +71 -0
  15. package/dist/host.js +400 -0
  16. package/dist/host.js.map +1 -0
  17. package/dist/index.d.ts +11 -30
  18. package/dist/index.js +11 -30
  19. package/dist/index.js.map +1 -1
  20. package/dist/install.d.ts +78 -0
  21. package/dist/install.js +292 -0
  22. package/dist/install.js.map +1 -0
  23. package/dist/main.d.ts +1 -2
  24. package/dist/main.js +159 -1362
  25. package/dist/main.js.map +1 -1
  26. package/dist/manifest.d.ts +23 -0
  27. package/dist/manifest.js +159 -0
  28. package/dist/manifest.js.map +1 -0
  29. package/dist/membrane.d.ts +33 -0
  30. package/dist/membrane.js +140 -0
  31. package/dist/membrane.js.map +1 -0
  32. package/dist/remote.d.ts +10 -0
  33. package/dist/remote.js +292 -0
  34. package/dist/remote.js.map +1 -0
  35. package/dist/rescue.d.ts +10 -0
  36. package/dist/rescue.js +216 -0
  37. package/dist/rescue.js.map +1 -0
  38. package/dist/resolve.d.ts +34 -0
  39. package/dist/resolve.js +178 -0
  40. package/dist/resolve.js.map +1 -0
  41. package/dist/rpc.d.ts +26 -0
  42. package/dist/rpc.js +144 -0
  43. package/dist/rpc.js.map +1 -0
  44. package/dist/secrets.d.ts +12 -0
  45. package/dist/secrets.js +125 -0
  46. package/dist/secrets.js.map +1 -0
  47. package/dist/session.d.ts +45 -0
  48. package/dist/session.js +401 -0
  49. package/dist/session.js.map +1 -0
  50. package/dist/source.d.ts +12 -0
  51. package/dist/source.js +72 -0
  52. package/dist/source.js.map +1 -0
  53. package/dist/state.d.ts +37 -0
  54. package/dist/state.js +93 -0
  55. package/dist/state.js.map +1 -0
  56. package/dist/update.d.ts +2 -0
  57. package/dist/update.js +6 -3
  58. package/dist/update.js.map +1 -1
  59. package/package.json +10 -8
  60. package/plugins/approval/index.ts +297 -0
  61. package/plugins/approval/plugin.json +18 -0
  62. package/{src/plugins → plugins/approval}/policy.ts +21 -100
  63. package/{src/plugins → plugins/approval}/review.ts +62 -16
  64. package/plugins/ask/index.ts +159 -0
  65. package/plugins/ask/plugin.json +8 -0
  66. package/plugins/budget/index.ts +38 -0
  67. package/plugins/budget/plugin.json +13 -0
  68. package/{src/plugins → plugins/checks}/checks.ts +48 -38
  69. package/plugins/checks/index.ts +158 -0
  70. package/plugins/checks/plugin.json +14 -0
  71. package/plugins/checks/project.ts +81 -0
  72. package/plugins/commands/index.ts +76 -0
  73. package/plugins/commands/plugin.json +7 -0
  74. package/{src/plugins → plugins/compact}/compact.ts +73 -38
  75. package/plugins/compact/index.ts +115 -0
  76. package/plugins/compact/plugin.json +17 -0
  77. package/plugins/compact/style.ts +17 -0
  78. package/plugins/continue/index.ts +58 -0
  79. package/plugins/continue/plugin.json +13 -0
  80. package/{src/ui → plugins/fs}/diff.ts +2 -2
  81. package/{src/tools → plugins/fs}/fs.ts +19 -42
  82. package/{src/tools → plugins/fs}/grep.ts +1 -1
  83. package/plugins/fs/index.ts +34 -0
  84. package/plugins/fs/plugin.json +7 -0
  85. package/{src/ui → plugins/fs}/renderers.ts +25 -70
  86. package/plugins/fs/style.ts +18 -0
  87. package/plugins/fs/sys.ts +81 -0
  88. package/plugins/keys/index.ts +53 -0
  89. package/plugins/keys/plugin.json +7 -0
  90. package/plugins/mcp/index.ts +192 -0
  91. package/{src → plugins/mcp}/mcp.ts +32 -32
  92. package/plugins/mcp/plugin.json +7 -0
  93. package/plugins/mcp/project.ts +93 -0
  94. package/plugins/memory/index.ts +105 -0
  95. package/{src → plugins/memory}/memory.ts +20 -2
  96. package/plugins/memory/notes.ts +43 -0
  97. package/plugins/memory/plugin.json +7 -0
  98. package/plugins/memory/style.ts +17 -0
  99. package/plugins/mentions/attach.ts +127 -0
  100. package/plugins/mentions/index.ts +79 -0
  101. package/plugins/mentions/plugin.json +7 -0
  102. package/plugins/mentions/style.ts +17 -0
  103. package/plugins/models/config.ts +53 -0
  104. package/plugins/models/configure.ts +455 -0
  105. package/plugins/models/context.ts +32 -0
  106. package/plugins/models/index.ts +198 -0
  107. package/plugins/models/plugin.json +8 -0
  108. package/{src → plugins/models}/provider.ts +16 -119
  109. package/plugins/models/saved.ts +94 -0
  110. package/plugins/modes/index.ts +222 -0
  111. package/plugins/modes/plugin.json +9 -0
  112. package/plugins/plugins/index.ts +38 -0
  113. package/plugins/plugins/plugin.json +7 -0
  114. package/plugins/print/index.ts +142 -0
  115. package/plugins/print/plugin.json +8 -0
  116. package/plugins/prompts/index.ts +83 -0
  117. package/plugins/prompts/plugin.json +8 -0
  118. package/plugins/prompts/prompts.ts +253 -0
  119. package/plugins/prompts/sys.ts +72 -0
  120. package/plugins/renderers/index.ts +78 -0
  121. package/plugins/renderers/plugin.json +7 -0
  122. package/plugins/repeats/index.ts +165 -0
  123. package/plugins/repeats/plugin.json +6 -0
  124. package/plugins/schedule/cron.ts +74 -0
  125. package/plugins/schedule/index.ts +292 -0
  126. package/plugins/schedule/plugin.json +13 -0
  127. package/plugins/schedule/store.ts +149 -0
  128. package/plugins/scratch/index.ts +31 -0
  129. package/plugins/scratch/plugin.json +7 -0
  130. package/plugins/screenshot/index.ts +40 -0
  131. package/plugins/screenshot/plugin.json +7 -0
  132. package/plugins/screenshot/sys.ts +84 -0
  133. package/{src/tools/screenshot.ts → plugins/screenshot/tool.ts} +6 -6
  134. package/plugins/sessions/index.ts +148 -0
  135. package/plugins/sessions/plugin.json +8 -0
  136. package/plugins/shell/index.ts +33 -0
  137. package/plugins/shell/plugin.json +17 -0
  138. package/plugins/shell/renderers.ts +45 -0
  139. package/plugins/shell/service.ts +44 -0
  140. package/{src/tools → plugins/shell}/shell.ts +31 -20
  141. package/{src → plugins/shell}/sys.ts +2 -43
  142. package/plugins/skills/index.ts +96 -0
  143. package/plugins/skills/plugin.json +7 -0
  144. package/plugins/skills/project.ts +49 -0
  145. package/{src → plugins/skills}/skills.ts +4 -11
  146. package/plugins/suggest/index.ts +286 -0
  147. package/plugins/suggest/plugin.json +18 -0
  148. package/plugins/task/index.ts +167 -0
  149. package/plugins/task/plugin.json +15 -0
  150. package/plugins/task/style.ts +17 -0
  151. package/plugins/task/subagent.ts +257 -0
  152. package/{src/tools/todo.ts → plugins/todo/index.ts} +33 -7
  153. package/plugins/todo/plugin.json +7 -0
  154. package/{src/ui → plugins/tui}/editor.ts +3 -0
  155. package/plugins/tui/frontend.ts +596 -0
  156. package/plugins/tui/index.ts +37 -0
  157. package/plugins/tui/mentions.ts +113 -0
  158. package/plugins/tui/plugin.json +10 -0
  159. package/{src/ui → plugins/tui}/render.ts +8 -2
  160. package/{src/ui → plugins/tui}/screen.ts +8 -3
  161. package/{src/ui → plugins/tui}/transcript.ts +74 -99
  162. package/{src/ui/tui.tsx → plugins/tui/tui.ts} +358 -387
  163. package/{src/tools → plugins/undo}/checkpoint.ts +21 -60
  164. package/plugins/undo/index.ts +139 -0
  165. package/plugins/undo/notes.ts +43 -0
  166. package/plugins/undo/plugin.json +7 -0
  167. package/plugins/undo/style.ts +17 -0
  168. package/plugins/update/index.ts +40 -0
  169. package/plugins/update/plugin.json +13 -0
  170. package/plugins/web/env.ts +78 -0
  171. package/plugins/web/index.ts +133 -0
  172. package/plugins/web/plugin.json +15 -0
  173. package/plugins/web/renderers.ts +11 -0
  174. package/{src/tools → plugins/web}/web.ts +58 -26
  175. package/plugins-dist/approval/index.js +271 -0
  176. package/plugins-dist/approval/plugin.json +24 -0
  177. package/{dist/plugins → plugins-dist/approval}/policy.js +15 -81
  178. package/{dist/plugins → plugins-dist/approval}/review.js +56 -10
  179. package/{dist/plugins → plugins-dist/approval}/schema.js +0 -1
  180. package/plugins-dist/ask/index.js +145 -0
  181. package/plugins-dist/ask/plugin.json +12 -0
  182. package/plugins-dist/budget/index.js +37 -0
  183. package/plugins-dist/budget/plugin.json +15 -0
  184. package/{dist/plugins → plugins-dist/checks}/checks.js +46 -35
  185. package/plugins-dist/checks/index.js +150 -0
  186. package/plugins-dist/checks/plugin.json +21 -0
  187. package/plugins-dist/checks/project.js +76 -0
  188. package/plugins-dist/commands/index.js +33 -0
  189. package/plugins-dist/commands/plugin.json +9 -0
  190. package/{dist/plugins → plugins-dist/compact}/compact.js +51 -33
  191. package/plugins-dist/compact/index.js +100 -0
  192. package/plugins-dist/compact/plugin.json +25 -0
  193. package/plugins-dist/compact/style.js +14 -0
  194. package/plugins-dist/continue/index.js +57 -0
  195. package/plugins-dist/continue/plugin.json +15 -0
  196. package/{dist/ui → plugins-dist/fs}/diff.js +2 -3
  197. package/{dist/tools → plugins-dist/fs}/fs.js +17 -42
  198. package/{dist/tools → plugins-dist/fs}/grep.js +1 -2
  199. package/plugins-dist/fs/index.js +36 -0
  200. package/plugins-dist/fs/plugin.json +10 -0
  201. package/{dist/ui → plugins-dist/fs}/renderers.js +24 -61
  202. package/plugins-dist/fs/style.js +15 -0
  203. package/plugins-dist/fs/sys.js +54 -0
  204. package/plugins-dist/keys/index.js +36 -0
  205. package/plugins-dist/keys/plugin.json +9 -0
  206. package/plugins-dist/mcp/index.js +187 -0
  207. package/{dist → plugins-dist/mcp}/mcp.js +34 -30
  208. package/plugins-dist/mcp/plugin.json +12 -0
  209. package/plugins-dist/mcp/project.js +90 -0
  210. package/plugins-dist/memory/index.js +94 -0
  211. package/{dist → plugins-dist/memory}/memory.js +21 -3
  212. package/plugins-dist/memory/notes.js +36 -0
  213. package/plugins-dist/memory/plugin.json +11 -0
  214. package/plugins-dist/memory/style.js +14 -0
  215. package/plugins-dist/mentions/attach.js +120 -0
  216. package/plugins-dist/mentions/index.js +69 -0
  217. package/plugins-dist/mentions/plugin.json +9 -0
  218. package/plugins-dist/mentions/style.js +14 -0
  219. package/plugins-dist/models/config.js +53 -0
  220. package/plugins-dist/models/configure.js +415 -0
  221. package/plugins-dist/models/context.js +27 -0
  222. package/plugins-dist/models/index.js +167 -0
  223. package/plugins-dist/models/plugin.json +14 -0
  224. package/{dist → plugins-dist/models}/provider.js +18 -81
  225. package/plugins-dist/models/saved.js +80 -0
  226. package/plugins-dist/modes/index.js +190 -0
  227. package/plugins-dist/modes/plugin.json +18 -0
  228. package/plugins-dist/plugins/index.js +37 -0
  229. package/plugins-dist/plugins/plugin.json +10 -0
  230. package/plugins-dist/print/index.js +153 -0
  231. package/plugins-dist/print/plugin.json +14 -0
  232. package/plugins-dist/prompts/index.js +57 -0
  233. package/plugins-dist/prompts/plugin.json +13 -0
  234. package/plugins-dist/prompts/prompts.js +227 -0
  235. package/plugins-dist/prompts/sys.js +46 -0
  236. package/plugins-dist/renderers/index.js +36 -0
  237. package/plugins-dist/renderers/plugin.json +9 -0
  238. package/plugins-dist/repeats/index.js +165 -0
  239. package/plugins-dist/repeats/plugin.json +6 -0
  240. package/plugins-dist/schedule/cron.js +67 -0
  241. package/plugins-dist/schedule/index.js +281 -0
  242. package/plugins-dist/schedule/plugin.json +16 -0
  243. package/plugins-dist/schedule/store.js +125 -0
  244. package/plugins-dist/scratch/index.js +26 -0
  245. package/plugins-dist/scratch/plugin.json +10 -0
  246. package/plugins-dist/screenshot/index.js +35 -0
  247. package/plugins-dist/screenshot/plugin.json +11 -0
  248. package/plugins-dist/screenshot/sys.js +76 -0
  249. package/{dist/tools/screenshot.js → plugins-dist/screenshot/tool.js} +5 -4
  250. package/plugins-dist/sessions/index.js +136 -0
  251. package/plugins-dist/sessions/plugin.json +12 -0
  252. package/plugins-dist/shell/index.js +33 -0
  253. package/plugins-dist/shell/plugin.json +19 -0
  254. package/plugins-dist/shell/renderers.js +40 -0
  255. package/plugins-dist/shell/service.js +29 -0
  256. package/{dist/tools → plugins-dist/shell}/shell.js +31 -22
  257. package/{dist → plugins-dist/shell}/sys.js +2 -43
  258. package/plugins-dist/skills/index.js +90 -0
  259. package/plugins-dist/skills/plugin.json +12 -0
  260. package/plugins-dist/skills/project.js +47 -0
  261. package/{dist → plugins-dist/skills}/skills.js +3 -7
  262. package/plugins-dist/suggest/index.js +282 -0
  263. package/plugins-dist/suggest/plugin.json +23 -0
  264. package/plugins-dist/task/index.js +151 -0
  265. package/plugins-dist/task/plugin.json +23 -0
  266. package/plugins-dist/task/style.js +14 -0
  267. package/plugins-dist/task/subagent.js +208 -0
  268. package/{dist/tools/todo.js → plugins-dist/todo/index.js} +29 -7
  269. package/plugins-dist/todo/plugin.json +9 -0
  270. package/{dist/ui → plugins-dist/tui}/editor.js +3 -1
  271. package/plugins-dist/tui/frontend.js +586 -0
  272. package/{dist → plugins-dist/tui}/history.js +0 -1
  273. package/plugins-dist/tui/index.js +21 -0
  274. package/{dist/ui → plugins-dist/tui}/markdown.js +0 -1
  275. package/plugins-dist/tui/mentions.js +115 -0
  276. package/plugins-dist/tui/plugin.json +25 -0
  277. package/{dist/ui → plugins-dist/tui}/render.js +7 -3
  278. package/{dist/ui → plugins-dist/tui}/screen.js +6 -2
  279. package/{dist/ui → plugins-dist/tui}/transcript.js +76 -98
  280. package/{dist/ui → plugins-dist/tui}/tui.js +185 -53
  281. package/{dist/tools → plugins-dist/undo}/checkpoint.js +21 -55
  282. package/plugins-dist/undo/index.js +140 -0
  283. package/plugins-dist/undo/notes.js +36 -0
  284. package/plugins-dist/undo/plugin.json +9 -0
  285. package/plugins-dist/undo/style.js +14 -0
  286. package/plugins-dist/update/index.js +34 -0
  287. package/plugins-dist/update/plugin.json +15 -0
  288. package/plugins-dist/web/env.js +80 -0
  289. package/plugins-dist/web/index.js +124 -0
  290. package/plugins-dist/web/plugin.json +21 -0
  291. package/plugins-dist/web/renderers.js +7 -0
  292. package/{dist/tools → plugins-dist/web}/web.js +50 -24
  293. package/sdk/python/__pycache__/jade_plugin.cpython-312.pyc +0 -0
  294. package/sdk/python/jade_plugin.py +380 -0
  295. package/src/api.ts +298 -0
  296. package/src/config.ts +32 -134
  297. package/src/fetch.ts +216 -0
  298. package/src/hash.ts +39 -0
  299. package/src/host.ts +429 -0
  300. package/src/index.ts +23 -30
  301. package/src/install.ts +355 -0
  302. package/src/main.ts +155 -1387
  303. package/src/manifest.ts +160 -0
  304. package/src/membrane.ts +142 -0
  305. package/src/remote.ts +288 -0
  306. package/src/rescue.ts +217 -0
  307. package/src/resolve.ts +199 -0
  308. package/src/rpc.ts +144 -0
  309. package/src/secrets.ts +122 -0
  310. package/src/session.ts +458 -0
  311. package/src/source.ts +83 -0
  312. package/src/state.ts +120 -0
  313. package/src/update.ts +265 -262
  314. package/LICENSE +0 -21
  315. package/README.md +0 -204
  316. package/dist/commands.d.ts +0 -50
  317. package/dist/commands.js +0 -126
  318. package/dist/commands.js.map +0 -1
  319. package/dist/context.d.ts +0 -17
  320. package/dist/context.js +0 -53
  321. package/dist/context.js.map +0 -1
  322. package/dist/distro.d.ts +0 -141
  323. package/dist/distro.js +0 -462
  324. package/dist/distro.js.map +0 -1
  325. package/dist/history.d.ts +0 -10
  326. package/dist/history.js.map +0 -1
  327. package/dist/mcp.d.ts +0 -114
  328. package/dist/mcp.js.map +0 -1
  329. package/dist/memory.d.ts +0 -19
  330. package/dist/memory.js.map +0 -1
  331. package/dist/mentions.d.ts +0 -35
  332. package/dist/mentions.js +0 -130
  333. package/dist/mentions.js.map +0 -1
  334. package/dist/plugin-cli.d.ts +0 -16
  335. package/dist/plugin-cli.js +0 -294
  336. package/dist/plugin-cli.js.map +0 -1
  337. package/dist/plugins/budget.d.ts +0 -9
  338. package/dist/plugins/budget.js +0 -30
  339. package/dist/plugins/budget.js.map +0 -1
  340. package/dist/plugins/builtins.d.ts +0 -10
  341. package/dist/plugins/builtins.js +0 -25
  342. package/dist/plugins/builtins.js.map +0 -1
  343. package/dist/plugins/checks.d.ts +0 -71
  344. package/dist/plugins/checks.js.map +0 -1
  345. package/dist/plugins/compact.d.ts +0 -26
  346. package/dist/plugins/compact.js.map +0 -1
  347. package/dist/plugins/core.d.ts +0 -47
  348. package/dist/plugins/core.js +0 -229
  349. package/dist/plugins/core.js.map +0 -1
  350. package/dist/plugins/host.d.ts +0 -52
  351. package/dist/plugins/host.js +0 -115
  352. package/dist/plugins/host.js.map +0 -1
  353. package/dist/plugins/install.d.ts +0 -68
  354. package/dist/plugins/install.js +0 -377
  355. package/dist/plugins/install.js.map +0 -1
  356. package/dist/plugins/loader.d.ts +0 -410
  357. package/dist/plugins/loader.js +0 -407
  358. package/dist/plugins/loader.js.map +0 -1
  359. package/dist/plugins/policy.d.ts +0 -98
  360. package/dist/plugins/policy.js.map +0 -1
  361. package/dist/plugins/prompts.d.ts +0 -43
  362. package/dist/plugins/prompts.js +0 -284
  363. package/dist/plugins/prompts.js.map +0 -1
  364. package/dist/plugins/repeats.d.ts +0 -16
  365. package/dist/plugins/repeats.js +0 -151
  366. package/dist/plugins/repeats.js.map +0 -1
  367. package/dist/plugins/review.d.ts +0 -18
  368. package/dist/plugins/review.js.map +0 -1
  369. package/dist/plugins/schema.d.ts +0 -2
  370. package/dist/plugins/schema.js.map +0 -1
  371. package/dist/plugins/sessions.d.ts +0 -7
  372. package/dist/plugins/sessions.js +0 -110
  373. package/dist/plugins/sessions.js.map +0 -1
  374. package/dist/provider.d.ts +0 -165
  375. package/dist/provider.js.map +0 -1
  376. package/dist/session-lifecycle.d.ts +0 -61
  377. package/dist/session-lifecycle.js +0 -167
  378. package/dist/session-lifecycle.js.map +0 -1
  379. package/dist/session-scope.d.ts +0 -53
  380. package/dist/session-scope.js +0 -116
  381. package/dist/session-scope.js.map +0 -1
  382. package/dist/sessions.d.ts +0 -28
  383. package/dist/sessions.js +0 -73
  384. package/dist/sessions.js.map +0 -1
  385. package/dist/skills.d.ts +0 -37
  386. package/dist/skills.js.map +0 -1
  387. package/dist/sys.d.ts +0 -51
  388. package/dist/sys.js.map +0 -1
  389. package/dist/tools/ask.d.ts +0 -11
  390. package/dist/tools/ask.js +0 -62
  391. package/dist/tools/ask.js.map +0 -1
  392. package/dist/tools/checkpoint.d.ts +0 -43
  393. package/dist/tools/checkpoint.js.map +0 -1
  394. package/dist/tools/fs.d.ts +0 -39
  395. package/dist/tools/fs.js.map +0 -1
  396. package/dist/tools/grep.d.ts +0 -6
  397. package/dist/tools/grep.js.map +0 -1
  398. package/dist/tools/screenshot.d.ts +0 -15
  399. package/dist/tools/screenshot.js.map +0 -1
  400. package/dist/tools/shell.d.ts +0 -55
  401. package/dist/tools/shell.js.map +0 -1
  402. package/dist/tools/task.d.ts +0 -39
  403. package/dist/tools/task.js +0 -117
  404. package/dist/tools/task.js.map +0 -1
  405. package/dist/tools/todo.d.ts +0 -10
  406. package/dist/tools/todo.js.map +0 -1
  407. package/dist/tools/web.d.ts +0 -53
  408. package/dist/tools/web.js.map +0 -1
  409. package/dist/ui/configure.d.ts +0 -20
  410. package/dist/ui/configure.js +0 -447
  411. package/dist/ui/configure.js.map +0 -1
  412. package/dist/ui/diff.d.ts +0 -20
  413. package/dist/ui/diff.js.map +0 -1
  414. package/dist/ui/editor.d.ts +0 -41
  415. package/dist/ui/editor.js.map +0 -1
  416. package/dist/ui/markdown.d.ts +0 -22
  417. package/dist/ui/markdown.js.map +0 -1
  418. package/dist/ui/render.d.ts +0 -14
  419. package/dist/ui/render.js.map +0 -1
  420. package/dist/ui/renderers.d.ts +0 -8
  421. package/dist/ui/renderers.js.map +0 -1
  422. package/dist/ui/screen.d.ts +0 -118
  423. package/dist/ui/screen.js.map +0 -1
  424. package/dist/ui/transcript.d.ts +0 -46
  425. package/dist/ui/transcript.js.map +0 -1
  426. package/dist/ui/tui.d.ts +0 -47
  427. package/dist/ui/tui.js.map +0 -1
  428. package/src/commands.ts +0 -144
  429. package/src/context.ts +0 -64
  430. package/src/distro.ts +0 -577
  431. package/src/mentions.ts +0 -135
  432. package/src/plugin-cli.ts +0 -278
  433. package/src/plugins/budget.ts +0 -37
  434. package/src/plugins/builtins.ts +0 -34
  435. package/src/plugins/core.ts +0 -257
  436. package/src/plugins/host.ts +0 -146
  437. package/src/plugins/install.ts +0 -429
  438. package/src/plugins/loader.ts +0 -742
  439. package/src/plugins/prompts.ts +0 -327
  440. package/src/plugins/repeats.ts +0 -157
  441. package/src/plugins/sessions.ts +0 -109
  442. package/src/session-lifecycle.ts +0 -194
  443. package/src/session-scope.ts +0 -135
  444. package/src/sessions.ts +0 -78
  445. package/src/tools/ask.ts +0 -72
  446. package/src/tools/task.ts +0 -149
  447. package/src/ui/configure.ts +0 -471
  448. /package/{src/plugins → plugins/approval}/schema.ts +0 -0
  449. /package/{src → plugins/tui}/history.ts +0 -0
  450. /package/{src/ui → plugins/tui}/markdown.ts +0 -0
@@ -0,0 +1,81 @@
1
+ // 跨运行时的进程和 glob:只用 Node 的标准库,Bun 和 Node ≥22.18 下走同一套代码。
2
+
3
+ import { spawn as nodeSpawn } from "node:child_process";
4
+ import picomatch from "picomatch";
5
+
6
+ type Stdio = "pipe" | "ignore";
7
+
8
+ export interface Proc {
9
+ pid: number;
10
+ /** stdout 为 "pipe" 时才有;Node 的 Readable 可以直接 for await 读出 Uint8Array */
11
+ stdout: AsyncIterable<Uint8Array>;
12
+ stderr: AsyncIterable<Uint8Array>;
13
+ /** 进程退出时 resolve 退出码;被信号杀掉时为 null */
14
+ exited: Promise<number | null>;
15
+ kill(): void;
16
+ }
17
+
18
+ export interface SpawnOptions {
19
+ cwd?: string;
20
+ stdout?: Stdio;
21
+ stderr?: Stdio;
22
+ /** POSIX 上自成进程组,便于连同子进程一起杀掉 */
23
+ detached?: boolean;
24
+ /** 子进程的环境变量,默认继承 process.env */
25
+ env?: NodeJS.ProcessEnv;
26
+ }
27
+
28
+ const EMPTY: AsyncIterable<Uint8Array> = { async *[Symbol.asyncIterator]() {} };
29
+
30
+ /**
31
+ * 启动进程,等到确实启动了才返回。程序不存在(ENOENT)等启动错误会 reject,
32
+ * 调用方用 try/catch 判断"没装",和 Bun.spawn 同步抛错的用法一致
33
+ */
34
+ export function spawn(cmd: string[], opts: SpawnOptions = {}): Promise<Proc> {
35
+ const child = nodeSpawn(cmd[0]!, cmd.slice(1), {
36
+ cwd: opts.cwd,
37
+ stdio: ["ignore", opts.stdout ?? "pipe", opts.stderr ?? "pipe"],
38
+ detached: opts.detached ?? false,
39
+ env: opts.env,
40
+ // Windows 上不弹出控制台窗口
41
+ windowsHide: true,
42
+ });
43
+ const exited = new Promise<number | null>((resolve) => child.once("exit", (code) => resolve(code)));
44
+ return new Promise((resolve, reject) => {
45
+ child.once("error", reject);
46
+ child.once("spawn", () => {
47
+ child.off("error", reject);
48
+ // 启动之后的错误(例如 kill 一个已经退出的进程)不应该变成未处理的异常
49
+ child.on("error", () => {});
50
+ resolve({
51
+ pid: child.pid!,
52
+ stdout: child.stdout ?? EMPTY,
53
+ stderr: child.stderr ?? EMPTY,
54
+ exited,
55
+ kill: () => void child.kill(),
56
+ });
57
+ });
58
+ });
59
+ }
60
+
61
+ /** 运行一条命令,返回 stdout 文本和退出码;启动失败时 reject */
62
+ export async function run(cmd: string[], opts: { cwd?: string } = {}): Promise<{ code: number | null; stdout: string }> {
63
+ const proc = await spawn(cmd, { cwd: opts.cwd, stderr: "ignore" });
64
+ const [stdout, code] = await Promise.all([text(proc.stdout), proc.exited]);
65
+ return { code, stdout };
66
+ }
67
+
68
+ export async function text(stream: AsyncIterable<Uint8Array>): Promise<string> {
69
+ const decoder = new TextDecoder();
70
+ let out = "";
71
+ for await (const chunk of stream) out += decoder.decode(chunk, { stream: true });
72
+ return out + decoder.decode();
73
+ }
74
+
75
+ /**
76
+ * 编译 glob,返回匹配函数。路径用正斜杠、相对于搜索根目录。
77
+ * 和原先的 Bun.Glob#match 一致:* 也匹配点开头的文件,反斜杠是转义符而不是分隔符
78
+ */
79
+ export function globMatcher(pattern: string): (rel: string) => boolean {
80
+ return picomatch(pattern, { dot: true, windows: false });
81
+ }
@@ -0,0 +1,53 @@
1
+ // jade/keys:快捷键的注册表。前端在输入框有焦点时按下自己不用的键,查这里找到插件的处理函数。
2
+
3
+ import { definePlugin } from "../../src/api.ts";
4
+
5
+ /** "ctrl+<字母>"、"alt+<字母或数字>" 或 "shift+tab" */
6
+ export const KEY_SPEC = /^(ctrl\+[a-z]|alt\+[a-z0-9]|shift\+tab)$/;
7
+ /**
8
+ * 前端自己用的键,插件不能用:编辑(ctrl+a/e/d/w/u/k,按词移动的 alt+f/b)、搜索历史(ctrl+r)、重画(ctrl+l)、展开(ctrl+o)、
9
+ * 中断和退出(ctrl+c),以及终端里等同于退格、Tab、回车的 ctrl+h/i/j/m
10
+ */
11
+ export const RESERVED_KEYS: ReadonlySet<string> = new Set([..."acdehijklmoruw"].map((c) => `ctrl+${c}`).concat("alt+f", "alt+b"));
12
+
13
+ export interface Key {
14
+ /** 见 KEY_SPEC,不分大小写 */
15
+ key: string;
16
+ /** /help 里显示 */
17
+ description?: string;
18
+ /** 按下时调用;出错时前端显示警告。上一次还没执行完时再按,会再调用一次 */
19
+ run(ctx: { key: string; signal: AbortSignal }): void | Promise<void>;
20
+ }
21
+
22
+ export interface Keys {
23
+ /** 注册一个键,返回撤销函数。键不合法、是保留键或已被占用时抛错 */
24
+ register(key: Key): () => void;
25
+ /** 前端按下一个自己不用的键时查找;找到了由前端执行 run,出错时显示警告 */
26
+ get(key: string): { key: Key; plugin: string } | undefined;
27
+ list(): { key: string; description?: string; plugin: string }[];
28
+ }
29
+
30
+ const registry = new Map<string, { key: Key; plugin: string }>();
31
+
32
+ export default definePlugin({
33
+ process(ctx) {
34
+ ctx.provide("keys@1", (caller): Keys => ({
35
+ register(key) {
36
+ const spec = String(key?.key ?? "").toLowerCase();
37
+ if (!KEY_SPEC.test(spec)) throw new Error(`invalid key ${JSON.stringify(key?.key)}: use ctrl+<letter>, alt+<letter or digit> or shift+tab`);
38
+ if (RESERVED_KEYS.has(spec)) throw new Error(`key ${spec} is reserved by the frontend`);
39
+ const taken = registry.get(spec);
40
+ if (taken) throw new Error(`key ${spec} is already registered by ${taken.plugin}`);
41
+ const entry = { key, plugin: caller.plugin };
42
+ registry.set(spec, entry);
43
+ const revoke = () => {
44
+ if (registry.get(spec) === entry) registry.delete(spec);
45
+ };
46
+ caller.onDispose(revoke);
47
+ return revoke;
48
+ },
49
+ get: (spec) => registry.get(spec.toLowerCase()),
50
+ list: () => [...registry.entries()].map(([k, { key, plugin }]) => ({ key: k, ...(key.description ? { description: key.description } : {}), plugin })).sort((a, b) => a.key.localeCompare(b.key)),
51
+ }));
52
+ },
53
+ });
@@ -0,0 +1,7 @@
1
+ {
2
+ "id": "jade/keys",
3
+ "version": "0.1.0",
4
+ "api": "^1",
5
+ "entry": "./index.ts",
6
+ "provides": ["keys@1"]
7
+ }
@@ -0,0 +1,192 @@
1
+ // jade/mcp:配置的 MCP 服务的工具交给模型(声明只读的也经 task@1 交给子 Agent);/mcp 查看状态、重连。
2
+ //
3
+ // 服务是进程级的资源:第一个会话打开时读配置、确认项目层的服务、连接,之后各会话共用;进程退出时(进程作用域关闭)全部关掉。
4
+ // 一个会话里的工具列表不变(否则提示缓存失效):第一个会话最多等 STARTUP_WAIT_MS,没连上的在后台接着连,
5
+ // 它们的工具从下一个会话(/clear)开始提供。不能交互时(-p)只有这一个会话,照常等到每个服务连上或超时。
6
+ // 服务进程退出后,下一次调用它的工具时重新连接一次。
7
+
8
+ import path from "node:path";
9
+ import { definePlugin, type ProcessContext, type UI } from "../../src/api.ts";
10
+ import type { Commands } from "../commands/index.ts";
11
+ import type { Prompts } from "../prompts/index.ts";
12
+ import type { Task } from "../task/index.ts";
13
+ import { describeServer, loadMcpConfig, McpClient, mcpTools, mcpTrustHash } from "./mcp.ts";
14
+ import { bold, clip, dim, display, green, realPath, red, repoRoot, TrustFile, yellow } from "./project.ts";
15
+
16
+ const ID = "jade/mcp";
17
+ /** 第一个会话最多等 MCP 服务连接这么久(能交互时),没连上的在后台接着连 */
18
+ const STARTUP_WAIT_MS = 5000;
19
+
20
+ const errorText = (err: unknown) => (err instanceof Error ? err.message : String(err));
21
+
22
+ /** 本进程的 MCP 服务 */
23
+ class Servers {
24
+ clients: McpClient[] = [];
25
+ readonly #ctx: ProcessContext;
26
+ #started?: Promise<void>;
27
+ #closing = false;
28
+
29
+ constructor(ctx: ProcessContext) {
30
+ this.#ctx = ctx;
31
+ }
32
+
33
+ /** 用到时才取:ui@1 的提供者可能排在后面激活(3.3) */
34
+ ui(): UI | undefined {
35
+ try {
36
+ return this.#ctx.service<UI>("ui@1");
37
+ } catch {
38
+ return undefined;
39
+ }
40
+ }
41
+
42
+ notify(text: string, level: "info" | "warning" | "error" = "info"): void {
43
+ if (this.#closing) return;
44
+ try {
45
+ this.ui()?.notify(text, level);
46
+ } catch {
47
+ // 前端已经关了
48
+ }
49
+ }
50
+
51
+ /** 第一次调用时读配置、确认、连接;之后等同一次。失败时关掉已经建的连接,下次调用重来,免得一次失败让 MCP 一直用不了 */
52
+ start(): Promise<void> {
53
+ this.#started ??= this.#start().catch(async (e: unknown) => {
54
+ await Promise.all(this.clients.splice(0).map((c) => c.close().catch(() => {})));
55
+ this.#started = undefined;
56
+ throw e;
57
+ });
58
+ return this.#started;
59
+ }
60
+
61
+ async #start(): Promise<void> {
62
+ const ctx = this.#ctx;
63
+ const cwd = realPath(ctx.cwd);
64
+ const root = realPath(repoRoot(cwd));
65
+ const trust = new TrustFile(path.join(ctx.home, "trust.jsonl"));
66
+ const { servers, warnings } = await loadMcpConfig({ home: ctx.home, root, cwd });
67
+ for (const w of warnings) this.notify(`${ID}: ${w}`, "warning");
68
+ const ui = this.ui();
69
+ const connecting: Promise<unknown>[] = [];
70
+ for (const entry of servers) {
71
+ if (entry.config.disabled) continue;
72
+ if (entry.layer === "project") {
73
+ // 项目层的服务随仓库分发,启动它就是执行仓库指定的命令:第一次启动前(配置变了也算)请用户确认
74
+ const hash = mcpTrustHash(root, entry);
75
+ if (!(await trust.has(hash))) {
76
+ const ok = ui?.interactive
77
+ ? (await ui.select(
78
+ {
79
+ title: `MCP server "${entry.name}" from ${display(cwd, entry.file)} is new or changed. Start it?`,
80
+ detail: `${entry.config.command !== undefined ? "runs" : "connects to"}: ${describeServer(entry.config)}`,
81
+ options: [
82
+ { label: "No", value: "no" },
83
+ { label: "Yes, start it", value: "yes" },
84
+ ],
85
+ },
86
+ ctx.signal,
87
+ )) === "yes"
88
+ : false;
89
+ if (!ok) {
90
+ this.notify(`[skipped] MCP server ${entry.name}: not confirmed${ui?.interactive ? "" : " (run jade interactively in this directory once to confirm it)"}`, "warning");
91
+ continue;
92
+ }
93
+ await trust.add(hash, entry.file);
94
+ }
95
+ }
96
+ const client = new McpClient(entry, {
97
+ cwd,
98
+ onDisconnect: (c, why) => this.notify(`MCP server ${c.name} disconnected: ${why}. jade reconnects on its next tool call; /mcp shows details`, "warning"),
99
+ });
100
+ this.clients.push(client);
101
+ connecting.push(client.connect().catch((err) => this.notify(`MCP server ${client.name} is unavailable: ${errorText(err)}`, "warning")));
102
+ }
103
+ if (this.clients.length === 0) return;
104
+ const all = Promise.all(connecting);
105
+ let timer: ReturnType<typeof setTimeout> | undefined;
106
+ if (ui?.interactive) await Promise.race([all, new Promise<void>((resolve) => (timer = setTimeout(resolve, STARTUP_WAIT_MS)))]);
107
+ else await all;
108
+ clearTimeout(timer);
109
+ for (const c of this.clients.filter((x) => x.status === "connecting")) {
110
+ this.notify(`MCP server ${c.name} is still starting; its tools are available from the next session (/clear) once it is connected`);
111
+ void c.connect().then(
112
+ () => this.notify(`MCP server ${c.name} connected; its tools are available from the next session (/clear)`),
113
+ () => {},
114
+ );
115
+ }
116
+ }
117
+
118
+ async close(): Promise<void> {
119
+ this.#closing = true;
120
+ await Promise.all(this.clients.map((c) => c.close().catch(() => {})));
121
+ }
122
+ }
123
+
124
+ /** 服务在初始化时给出的使用说明,放进系统提示词。来自外部,标为不可信 */
125
+ function instructions(clients: McpClient[]): string[] {
126
+ return clients
127
+ .filter((c) => c.status === "connected" && c.instructions)
128
+ .map((c) => `# Instructions from the MCP server "${c.name}" (about its mcp__${c.name}__* tools)
129
+
130
+ ${c.instructions}`);
131
+ }
132
+
133
+ /** 当前进程的服务;process() 里创建,session() 里用 */
134
+ let current: Servers | undefined;
135
+
136
+ export default definePlugin({
137
+ async process(ctx) {
138
+ const servers = new Servers(ctx);
139
+ current = servers;
140
+ // 后台资源:进程作用域关闭时关掉所有服务(服务本身到第一个会话打开时才启动)
141
+ await ctx.effect(() => () => servers.close());
142
+
143
+ ctx.service<Commands>("commands@1")?.register({
144
+ name: "mcp",
145
+ args: "[reconnect <name>]",
146
+ description: "MCP servers: status and tools",
147
+ instant: true,
148
+ async run(args) {
149
+ await servers.start();
150
+ const clients = servers.clients;
151
+ const words = args.trim().split(/\s+/).filter(Boolean);
152
+ if (words[0] === "reconnect") {
153
+ const c = clients.find((x) => x.name === words[1]);
154
+ if (!c) return red(`usage: /mcp reconnect <name>; servers: ${clients.map((x) => x.name).join(", ") || "(none)"}`);
155
+ await c.close();
156
+ try {
157
+ await c.connect();
158
+ return green(`${c.name} connected, ${c.tools.length} tools; new tools are available from the next session (/clear)`);
159
+ } catch (err) {
160
+ return red(`${c.name}: ${errorText(err)}`);
161
+ }
162
+ }
163
+ if (words.length > 0) return red("usage: /mcp [reconnect <name>]");
164
+ if (clients.length === 0) {
165
+ return dim(`(no MCP servers) configure them in ${display(ctx.cwd, path.join(ctx.home, "mcp.json"))}, .mcp.json or .jade/mcp.json`);
166
+ }
167
+ const lines: string[] = [];
168
+ for (const c of clients) {
169
+ const state = c.status === "connected" ? green("connected") : c.status === "failed" ? red("failed") : yellow(c.status);
170
+ const info = c.serverInfo?.name ? ` · ${c.serverInfo.name}${c.serverInfo.version ? ` ${c.serverInfo.version}` : ""}` : "";
171
+ lines.push(`${bold(c.name)} ${state} ${dim(`${c.entry.layer} · ${display(ctx.cwd, c.entry.file)} · ${describeServer(c.entry.config)}${info}`)}`);
172
+ if (c.error) lines.push(red(` ${c.error}`));
173
+ if (c.tools.length) lines.push(` tools ${c.tools.map((t) => `${t.name}${t.annotations?.readOnlyHint ? dim(" (read)") : ""}`).join(", ")}`);
174
+ if (c.status === "failed" && c.stderr.length) lines.push(dim(c.stderr.map((l) => ` │ ${clip(l, 200)}`).join("\n")));
175
+ }
176
+ return lines.join("\n");
177
+ },
178
+ });
179
+ },
180
+
181
+ async session(ctx) {
182
+ const servers = current;
183
+ if (!servers) return;
184
+ await servers.start();
185
+ for (const tool of mcpTools(servers.clients)) ctx.kernel.tool(tool);
186
+ // 子 Agent(jade/task)只拿声明了只读(readOnlyHint)的工具:另一套实例,和 jade/fs 一样
187
+ const task = ctx.service<Task>("task@1");
188
+ if (task) for (const tool of mcpTools(servers.clients, { readOnly: true })) task.tool(tool);
189
+ const prompts = ctx.service<Prompts>("prompts@1");
190
+ for (const text of instructions(servers.clients)) prompts?.add({ text, untrusted: true });
191
+ },
192
+ });
@@ -3,22 +3,31 @@
3
3
  // 配置兼容 Claude Code 的 .mcp.json:{ "mcpServers": { "<name>": { command, args, env } | { type: "http", url, headers } } }。
4
4
  // 读取顺序(同名时后面的覆盖前面的):
5
5
  // $JADE_HOME/mcp.json(用户层)、<仓库根目录>/.mcp.json、仓库根目录到工作目录每一级的 .jade/mcp.json(项目层)。
6
- // 项目层的服务随仓库分发,启动它就是执行仓库指定的命令,所以第一次启动前要用户确认(按配置内容记录)。
6
+ // 项目层的服务随仓库分发,启动它就是执行仓库指定的命令,所以第一次启动前要用户确认(按配置内容记录,见 index.ts)。
7
7
  //
8
8
  // 传输:stdio(一行一条 JSON-RPC 消息)和 Streamable HTTP(POST,回复是 JSON 或 SSE)。旧的 HTTP+SSE 传输不支持。
9
- // 服务在 jade 启动时连接,各会话共用;进程退出后,下一次调用工具时重新连接一次。
9
+ // 从旧 jade 的 src/mcp.ts 移植;旧 jade 的"插件自带 MCP 配置"(PluginBundle)没有移植:新的插件宿主没有内容包的概念。
10
10
 
11
11
  import { spawn, type ChildProcess } from "node:child_process";
12
12
  import { createHash } from "node:crypto";
13
- import { statSync } from "node:fs";
13
+ import { readFileSync, statSync } from "node:fs";
14
14
  import { readFile } from "node:fs/promises";
15
15
  import path from "node:path";
16
16
  import type { Block, Tool } from "uncarved";
17
- import { projectDirs } from "./commands.ts";
18
- import { VERSION } from "./sys.ts";
17
+ import { projectDirs } from "./project.ts";
19
18
 
20
19
  export const PROTOCOL_VERSION = "2025-06-18";
21
- const CLIENT_INFO = { name: "jade", version: VERSION };
20
+ /** 告诉服务端的客户端版本:jade 的版本(和 jade/tui 一样从 apps/jade/package.json 读) */
21
+ const CLIENT_INFO = {
22
+ name: "jade",
23
+ version: (() => {
24
+ try {
25
+ return (JSON.parse(readFileSync(new URL("../../package.json", import.meta.url), "utf8")) as { version: string }).version;
26
+ } catch {
27
+ return "0.0.0";
28
+ }
29
+ })(),
30
+ };
22
31
  /** 一次工具调用结果里文本的上限,超过时保留开头 */
23
32
  const MAX_RESULT_CHARS = 60_000;
24
33
  const STDERR_LINES = 20;
@@ -49,8 +58,6 @@ export interface McpServerEntry {
49
58
  /** 配置文件的绝对路径 */
50
59
  file: string;
51
60
  config: McpServerConfig;
52
- /** 来自哪个插件 */
53
- plugin?: string;
54
61
  }
55
62
 
56
63
  /** MCP 服务声明的工具 */
@@ -72,37 +79,30 @@ export async function loadMcpConfig(opts: {
72
79
  root: string;
73
80
  cwd: string;
74
81
  env?: Record<string, string | undefined>;
75
- /** 插件带的 MCP 配置,优先级最低。配置里的 ${JADE_PLUGIN_DIR}(或 ${CLAUDE_PLUGIN_ROOT})换成插件目录 */
76
- plugins?: { plugin: string; dir: string; layer: McpServerEntry["layer"]; file: string; servers?: unknown }[];
77
82
  }): Promise<{ servers: McpServerEntry[]; warnings: string[] }> {
78
- const base = opts.env ?? process.env;
79
- const files: { file: string; layer: McpServerEntry["layer"]; plugin?: string; dir?: string; servers?: unknown }[] = [
80
- ...(opts.plugins ?? []),
83
+ const env = opts.env ?? process.env;
84
+ const files: { file: string; layer: McpServerEntry["layer"] }[] = [
81
85
  { file: path.join(opts.home, "mcp.json"), layer: "user" },
82
86
  { file: path.join(opts.root, ".mcp.json"), layer: "project" },
83
87
  ...projectDirs(opts.root, opts.cwd).map((d) => ({ file: path.join(d, ".jade", "mcp.json"), layer: "project" as const })),
84
88
  ];
85
89
  const out = new Map<string, McpServerEntry>();
86
90
  const warnings: string[] = [];
87
- for (const { file, layer, plugin, dir, servers: inline } of files) {
88
- const env = dir ? { ...base, JADE_PLUGIN_DIR: dir, CLAUDE_PLUGIN_ROOT: dir } : base;
89
- let servers = inline;
90
- if (servers === undefined) {
91
- let text: string;
92
- try {
93
- text = await readFile(file, "utf8");
94
- } catch {
95
- continue;
96
- }
97
- let json: { mcpServers?: unknown };
98
- try {
99
- json = JSON.parse(text);
100
- } catch (err) {
101
- warnings.push(`${file}: ${err instanceof Error ? err.message : String(err)}`);
102
- continue;
103
- }
104
- servers = json?.mcpServers;
91
+ for (const { file, layer } of files) {
92
+ let text: string;
93
+ try {
94
+ text = await readFile(file, "utf8");
95
+ } catch {
96
+ continue;
97
+ }
98
+ let json: { mcpServers?: unknown };
99
+ try {
100
+ json = JSON.parse(text);
101
+ } catch (err) {
102
+ warnings.push(`${file}: ${err instanceof Error ? err.message : String(err)}`);
103
+ continue;
105
104
  }
105
+ const servers = json?.mcpServers;
106
106
  if (typeof servers !== "object" || servers === null || Array.isArray(servers)) {
107
107
  warnings.push(`${file}: expected { "mcpServers": { ... } }`);
108
108
  continue;
@@ -127,7 +127,7 @@ export async function loadMcpConfig(opts: {
127
127
  continue;
128
128
  }
129
129
  if (config.cwd && !path.isAbsolute(config.cwd)) config.cwd = path.resolve(path.dirname(file), config.cwd);
130
- out.set(name, { name, layer, file, config, ...(plugin ? { plugin } : {}) });
130
+ out.set(name, { name, layer, file, config });
131
131
  }
132
132
  }
133
133
  return { servers: [...out.values()], warnings };
@@ -0,0 +1,7 @@
1
+ {
2
+ "id": "jade/mcp",
3
+ "version": "0.2.0",
4
+ "api": "^1",
5
+ "entry": "./index.ts",
6
+ "optional": ["ui@1", "commands@1", "prompts@1", "task@1"]
7
+ }
@@ -0,0 +1,93 @@
1
+ // 仓库目录、确认记录、显示用的小工具。插件之间不共享代码(只能共享类型),jade/skills、jade/checks 各有一份。
2
+
3
+ import { existsSync, realpathSync } from "node:fs";
4
+ import { appendFile, mkdir, readFile } from "node:fs/promises";
5
+ import path from "node:path";
6
+
7
+ export function realPath(p: string): string {
8
+ try {
9
+ return realpathSync.native(p);
10
+ } catch {
11
+ return path.resolve(p);
12
+ }
13
+ }
14
+
15
+ /** git 仓库的根目录(往上找 .git,目录或文件都算);不在仓库里时是 cwd 本身 */
16
+ export function repoRoot(cwd: string): string {
17
+ let d = path.resolve(cwd);
18
+ for (;;) {
19
+ if (existsSync(path.join(d, ".git"))) return d;
20
+ const parent = path.dirname(d);
21
+ if (parent === d) return path.resolve(cwd);
22
+ d = parent;
23
+ }
24
+ }
25
+
26
+ /** 从仓库根目录到工作目录的每一级目录,远的在前;工作目录不在仓库里时只有工作目录 */
27
+ export function projectDirs(root: string, cwd: string): string[] {
28
+ const rel = path.relative(root, cwd);
29
+ const inside = rel === "" || !(rel === ".." || rel.startsWith(`..${path.sep}`) || path.isAbsolute(rel));
30
+ if (!inside) return [cwd];
31
+ const dirs = [root];
32
+ if (rel) for (const seg of rel.split(path.sep)) dirs.push(path.join(dirs.at(-1)!, seg));
33
+ return dirs;
34
+ }
35
+
36
+ /** 工作目录里的显示成相对路径,外面的显示绝对路径 */
37
+ export function display(cwd: string, full: string): string {
38
+ const rel = path.relative(cwd, full);
39
+ const shown = rel && rel !== ".." && !rel.startsWith(`..${path.sep}`) && !path.isAbsolute(rel) ? rel : full;
40
+ return shown.split(path.sep).join("/");
41
+ }
42
+
43
+ /**
44
+ * 用户确认过的东西(项目层的 MCP 服务),每行一条 { hash, path, at }。
45
+ * 和旧 jade 的 $JADE_HOME/trust.jsonl 同一个文件、同一种格式,旧 jade 里确认过的不用再确认
46
+ */
47
+ export class TrustFile {
48
+ readonly file: string;
49
+ #known = new Set<string>();
50
+
51
+ constructor(file: string) {
52
+ this.file = file;
53
+ }
54
+
55
+ async has(hash: string): Promise<boolean> {
56
+ if (this.#known.has(hash)) return true;
57
+ let text = "";
58
+ try {
59
+ text = await readFile(this.file, "utf8");
60
+ } catch {
61
+ return false;
62
+ }
63
+ for (const line of text.split("\n")) {
64
+ try {
65
+ if ((JSON.parse(line) as { hash?: unknown }).hash === hash) {
66
+ this.#known.add(hash);
67
+ return true;
68
+ }
69
+ } catch {
70
+ // 写到一半的行
71
+ }
72
+ }
73
+ return false;
74
+ }
75
+
76
+ async add(hash: string, where: string): Promise<void> {
77
+ await mkdir(path.dirname(this.file), { recursive: true });
78
+ await appendFile(this.file, `${JSON.stringify({ hash, path: where, at: new Date().toISOString() })}\n`);
79
+ this.#known.add(hash);
80
+ }
81
+ }
82
+
83
+ export const clip = (s: string, n: number) => (s.length > n ? s.slice(0, n) + "…" : s);
84
+
85
+ // 设了 NO_COLOR(非空)或标准输出不是终端时不输出颜色,见 https://no-color.org
86
+ const colors = Boolean(process.stdout.isTTY) && !process.env.NO_COLOR;
87
+ const paint = (open: string, close: string) => (s: string) =>
88
+ colors ? `\x1b[${open}m${s.replaceAll(`\x1b[${close}m`, `\x1b[${close}m\x1b[${open}m`)}\x1b[${close}m` : s;
89
+ export const dim = paint("2", "22");
90
+ export const red = paint("31", "39");
91
+ export const green = paint("32", "39");
92
+ export const yellow = paint("33", "39");
93
+ export const bold = paint("1", "22");
@@ -0,0 +1,105 @@
1
+ // jade/memory:跨会话的记忆(见 memory.ts)。memory 工具给模型增删,/memory 给用户查看和管理,
2
+ // 会话开始时经 prompts@1 把记忆放进系统提示词(会话中途的改动下一个会话才进提示词,这样提示缓存不失效;
3
+ // 用户在 /memory 里改了,下一次请求时附一条说明告诉模型)。
4
+
5
+ import { definePlugin } from "../../src/api.ts";
6
+ import type { Commands } from "../commands/index.ts";
7
+ import type { Prompts } from "../prompts/index.ts";
8
+ import type { Renderers } from "../renderers/index.ts";
9
+ import { Memory, MEMORY_SCOPES, memoryTool, projectRoot, type MemoryScope } from "./memory.ts";
10
+ import { Notes } from "./notes.ts";
11
+ import { clip, dim, green, red } from "./style.ts";
12
+
13
+ const notes = new Notes();
14
+
15
+ const args = (input: unknown) => (input ?? {}) as { action?: string; scope?: string; text?: string };
16
+
17
+ export default definePlugin({
18
+ process(ctx) {
19
+ const memory = new Memory(ctx.home, projectRoot(ctx.cwd));
20
+
21
+ ctx.service<Renderers>("renderers@1")?.tool({
22
+ tool: "memory",
23
+ summary: (input) => {
24
+ const i = args(input);
25
+ return `${i.action} ${i.scope}: ${clip(String(i.text ?? ""), 120)}`;
26
+ },
27
+ preview: (input) => {
28
+ const i = args(input);
29
+ return `${i.action === "remove" ? red("- ") : green("+ ")}${String(i.text ?? "")}`;
30
+ },
31
+ });
32
+
33
+ ctx.service<Commands>("commands@1")?.register({
34
+ name: "memory",
35
+ args: "[text]",
36
+ description: "see and remove what jade remembers across sessions, or remember text",
37
+ instant: true,
38
+ async run(input, { ui, sessions, signal }) {
39
+ const note = (text: string) => {
40
+ const id = sessions.current?.id;
41
+ if (id) notes.add(id, text);
42
+ };
43
+ let text = input.trim();
44
+ if (!text) {
45
+ const entries = (await Promise.all(MEMORY_SCOPES.map(async (scope) => (await memory.list(scope)).map((t) => ({ scope, text: t }))))).flat();
46
+ if (!ui.interactive) return entries.length ? entries.map((e) => `${e.scope}: ${e.text}`).join("\n") : "jade does not remember anything yet";
47
+ const choice = await ui.select(
48
+ {
49
+ title: entries.length ? "Memory: choose an entry to remove it, or add one" : "jade does not remember anything yet",
50
+ detail: dim(`user (all projects): ${memory.files.user}\nproject: ${memory.files.project}`),
51
+ options: [{ label: "Add a memory…", value: "add" }, ...entries.map((e, i) => ({ label: e.text, value: String(i), hint: e.scope }))],
52
+ },
53
+ signal,
54
+ );
55
+ if (!choice) return;
56
+ if (choice !== "add") {
57
+ const entry = entries[Number(choice)]!;
58
+ const ok = await ui.select(
59
+ {
60
+ title: `Remove this ${entry.scope} memory?`,
61
+ detail: entry.text,
62
+ options: [
63
+ { label: "No", value: "no" },
64
+ { label: "Yes, remove it", value: "yes" },
65
+ ],
66
+ },
67
+ signal,
68
+ );
69
+ if (ok !== "yes") return;
70
+ await memory.remove(entry.scope, entry.text);
71
+ note(`The user removed this ${entry.scope} memory, so stop following it: ${entry.text}`);
72
+ return green(`Removed from ${entry.scope} memory: ${entry.text}`);
73
+ }
74
+ text = (await ui.input({ title: "What should jade remember?", placeholder: "e.g. Reply in Chinese; run tests with bun test" }, signal)) ?? "";
75
+ if (!text.trim()) return;
76
+ }
77
+ const scope = ui.interactive
78
+ ? await ui.select<MemoryScope>(
79
+ {
80
+ title: "Remember it for",
81
+ options: [
82
+ { label: "All projects", value: "user", hint: "user memory" },
83
+ { label: "This project only", value: "project", hint: "project memory" },
84
+ ],
85
+ },
86
+ signal,
87
+ )
88
+ : "user";
89
+ if (!scope) return;
90
+ const added = await memory.add(scope, text);
91
+ if (added) note(`The user saved a ${scope} memory; follow it from now on: ${text.replace(/\s+/g, " ").trim()}`);
92
+ return added ? green(`Saved to ${scope} memory.`) : dim(`The ${scope} memory already has this.`);
93
+ },
94
+ });
95
+ },
96
+
97
+ async session(ctx) {
98
+ const memory = new Memory(ctx.home, projectRoot(ctx.cwd));
99
+ ctx.kernel.tool(memoryTool(memory));
100
+ ctx.kernel.hook(notes.hook(ctx.session.id, ctx.plugin, ctx.plugin));
101
+ const text = await memory.prompt();
102
+ // 段落随会话作用域撤销
103
+ if (text) ctx.service<Prompts>("prompts@1")?.add({ text });
104
+ },
105
+ });