@uncarved/jade 0.1.3 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (455) hide show
  1. package/README.md +161 -150
  2. package/bin/jade.js +14 -25
  3. package/dist/api.d.ts +266 -0
  4. package/dist/api.js +38 -0
  5. package/dist/api.js.map +1 -0
  6. package/dist/config.d.ts +13 -32
  7. package/dist/config.js +39 -121
  8. package/dist/config.js.map +1 -1
  9. package/dist/fetch.d.ts +20 -0
  10. package/dist/fetch.js +190 -0
  11. package/dist/fetch.js.map +1 -0
  12. package/dist/hash.d.ts +2 -0
  13. package/dist/hash.js +42 -0
  14. package/dist/hash.js.map +1 -0
  15. package/dist/host.d.ts +71 -0
  16. package/dist/host.js +400 -0
  17. package/dist/host.js.map +1 -0
  18. package/dist/index.d.ts +11 -30
  19. package/dist/index.js +11 -30
  20. package/dist/index.js.map +1 -1
  21. package/dist/install.d.ts +78 -0
  22. package/dist/install.js +292 -0
  23. package/dist/install.js.map +1 -0
  24. package/dist/main.d.ts +1 -2
  25. package/dist/main.js +160 -1362
  26. package/dist/main.js.map +1 -1
  27. package/dist/manifest.d.ts +23 -0
  28. package/dist/manifest.js +159 -0
  29. package/dist/manifest.js.map +1 -0
  30. package/dist/membrane.d.ts +33 -0
  31. package/dist/membrane.js +140 -0
  32. package/dist/membrane.js.map +1 -0
  33. package/dist/remote.d.ts +10 -0
  34. package/dist/remote.js +292 -0
  35. package/dist/remote.js.map +1 -0
  36. package/dist/rescue.d.ts +10 -0
  37. package/dist/rescue.js +216 -0
  38. package/dist/rescue.js.map +1 -0
  39. package/dist/resolve.d.ts +34 -0
  40. package/dist/resolve.js +178 -0
  41. package/dist/resolve.js.map +1 -0
  42. package/dist/rpc.d.ts +26 -0
  43. package/dist/rpc.js +144 -0
  44. package/dist/rpc.js.map +1 -0
  45. package/dist/secrets.d.ts +12 -0
  46. package/dist/secrets.js +125 -0
  47. package/dist/secrets.js.map +1 -0
  48. package/dist/session.d.ts +45 -0
  49. package/dist/session.js +401 -0
  50. package/dist/session.js.map +1 -0
  51. package/dist/source.d.ts +12 -0
  52. package/dist/source.js +72 -0
  53. package/dist/source.js.map +1 -0
  54. package/dist/state.d.ts +37 -0
  55. package/dist/state.js +93 -0
  56. package/dist/state.js.map +1 -0
  57. package/dist/update.d.ts +2 -0
  58. package/dist/update.js +6 -3
  59. package/dist/update.js.map +1 -1
  60. package/package.json +10 -8
  61. package/plugins/approval/index.ts +311 -0
  62. package/plugins/approval/plugin.json +22 -0
  63. package/{src/plugins → plugins/approval}/policy.ts +45 -104
  64. package/{src/plugins → plugins/approval}/review.ts +62 -16
  65. package/plugins/ask/index.ts +159 -0
  66. package/plugins/ask/plugin.json +8 -0
  67. package/plugins/budget/index.ts +38 -0
  68. package/plugins/budget/plugin.json +13 -0
  69. package/{src/plugins → plugins/checks}/checks.ts +48 -38
  70. package/plugins/checks/index.ts +158 -0
  71. package/plugins/checks/plugin.json +14 -0
  72. package/plugins/checks/project.ts +81 -0
  73. package/plugins/commands/index.ts +76 -0
  74. package/plugins/commands/plugin.json +7 -0
  75. package/{src/plugins → plugins/compact}/compact.ts +80 -39
  76. package/plugins/compact/index.ts +115 -0
  77. package/plugins/compact/plugin.json +17 -0
  78. package/plugins/compact/style.ts +17 -0
  79. package/plugins/continue/index.ts +58 -0
  80. package/plugins/continue/plugin.json +13 -0
  81. package/{src/ui → plugins/fs}/diff.ts +2 -2
  82. package/{src/tools → plugins/fs}/fs.ts +89 -46
  83. package/{src/tools → plugins/fs}/grep.ts +36 -8
  84. package/plugins/fs/index.ts +37 -0
  85. package/plugins/fs/plugin.json +7 -0
  86. package/{src/ui → plugins/fs}/renderers.ts +25 -70
  87. package/plugins/fs/style.ts +18 -0
  88. package/plugins/fs/sys.ts +81 -0
  89. package/plugins/keys/index.ts +53 -0
  90. package/plugins/keys/plugin.json +7 -0
  91. package/plugins/mcp/index.ts +192 -0
  92. package/{src → plugins/mcp}/mcp.ts +32 -32
  93. package/plugins/mcp/plugin.json +7 -0
  94. package/plugins/mcp/project.ts +93 -0
  95. package/plugins/memory/index.ts +105 -0
  96. package/{src → plugins/memory}/memory.ts +20 -2
  97. package/plugins/memory/notes.ts +43 -0
  98. package/plugins/memory/plugin.json +7 -0
  99. package/plugins/memory/style.ts +17 -0
  100. package/plugins/mentions/attach.ts +127 -0
  101. package/plugins/mentions/index.ts +99 -0
  102. package/plugins/mentions/plugin.json +7 -0
  103. package/plugins/mentions/style.ts +17 -0
  104. package/plugins/models/config.ts +53 -0
  105. package/plugins/models/configure.ts +455 -0
  106. package/plugins/models/context.ts +32 -0
  107. package/plugins/models/index.ts +213 -0
  108. package/plugins/models/plugin.json +8 -0
  109. package/{src → plugins/models}/provider.ts +16 -119
  110. package/plugins/models/saved.ts +94 -0
  111. package/plugins/modes/index.ts +222 -0
  112. package/plugins/modes/plugin.json +9 -0
  113. package/plugins/plugins/index.ts +38 -0
  114. package/plugins/plugins/plugin.json +7 -0
  115. package/plugins/print/index.ts +160 -0
  116. package/plugins/print/plugin.json +8 -0
  117. package/plugins/prompts/index.ts +111 -0
  118. package/plugins/prompts/plugin.json +8 -0
  119. package/plugins/prompts/prompts.ts +258 -0
  120. package/plugins/prompts/results.ts +63 -0
  121. package/plugins/prompts/sys.ts +84 -0
  122. package/plugins/renderers/index.ts +78 -0
  123. package/plugins/renderers/plugin.json +7 -0
  124. package/plugins/repeats/index.ts +165 -0
  125. package/plugins/repeats/plugin.json +6 -0
  126. package/plugins/schedule/cron.ts +74 -0
  127. package/plugins/schedule/index.ts +292 -0
  128. package/plugins/schedule/plugin.json +13 -0
  129. package/plugins/schedule/store.ts +149 -0
  130. package/plugins/scratch/index.ts +31 -0
  131. package/plugins/scratch/plugin.json +7 -0
  132. package/plugins/screenshot/index.ts +40 -0
  133. package/plugins/screenshot/plugin.json +7 -0
  134. package/plugins/screenshot/sys.ts +84 -0
  135. package/{src/tools/screenshot.ts → plugins/screenshot/tool.ts} +6 -6
  136. package/plugins/sessions/index.ts +148 -0
  137. package/plugins/sessions/plugin.json +8 -0
  138. package/plugins/shell/index.ts +33 -0
  139. package/plugins/shell/plugin.json +17 -0
  140. package/plugins/shell/renderers.ts +45 -0
  141. package/plugins/shell/service.ts +44 -0
  142. package/{src/tools → plugins/shell}/shell.ts +31 -20
  143. package/{src → plugins/shell}/sys.ts +2 -43
  144. package/plugins/skills/index.ts +96 -0
  145. package/plugins/skills/plugin.json +7 -0
  146. package/plugins/skills/project.ts +49 -0
  147. package/{src → plugins/skills}/skills.ts +4 -11
  148. package/plugins/suggest/index.ts +286 -0
  149. package/plugins/suggest/plugin.json +18 -0
  150. package/plugins/task/index.ts +168 -0
  151. package/plugins/task/plugin.json +15 -0
  152. package/plugins/task/style.ts +17 -0
  153. package/plugins/task/subagent.ts +343 -0
  154. package/plugins/todo/index.ts +93 -0
  155. package/plugins/todo/plugin.json +7 -0
  156. package/{src/ui → plugins/tui}/editor.ts +3 -0
  157. package/plugins/tui/frontend.ts +619 -0
  158. package/plugins/tui/index.ts +37 -0
  159. package/plugins/tui/mentions.ts +153 -0
  160. package/plugins/tui/plugin.json +10 -0
  161. package/{src/ui → plugins/tui}/render.ts +8 -2
  162. package/{src/ui → plugins/tui}/screen.ts +8 -3
  163. package/{src/ui → plugins/tui}/transcript.ts +79 -100
  164. package/{src/ui/tui.tsx → plugins/tui/tui.ts} +360 -392
  165. package/plugins/tui/vendor.ts +16 -0
  166. package/{src/tools → plugins/undo}/checkpoint.ts +45 -60
  167. package/plugins/undo/index.ts +143 -0
  168. package/plugins/undo/notes.ts +43 -0
  169. package/plugins/undo/plugin.json +7 -0
  170. package/plugins/undo/style.ts +17 -0
  171. package/plugins/update/index.ts +40 -0
  172. package/plugins/update/plugin.json +13 -0
  173. package/plugins/web/env.ts +78 -0
  174. package/plugins/web/index.ts +133 -0
  175. package/plugins/web/plugin.json +15 -0
  176. package/plugins/web/renderers.ts +11 -0
  177. package/{src/tools → plugins/web}/web.ts +64 -31
  178. package/plugins-dist/approval/index.js +287 -0
  179. package/plugins-dist/approval/plugin.json +28 -0
  180. package/{dist/plugins → plugins-dist/approval}/policy.js +41 -85
  181. package/{dist/plugins → plugins-dist/approval}/review.js +56 -10
  182. package/{dist/plugins → plugins-dist/approval}/schema.js +0 -1
  183. package/plugins-dist/ask/index.js +145 -0
  184. package/plugins-dist/ask/plugin.json +12 -0
  185. package/plugins-dist/budget/index.js +37 -0
  186. package/plugins-dist/budget/plugin.json +15 -0
  187. package/{dist/plugins → plugins-dist/checks}/checks.js +46 -35
  188. package/plugins-dist/checks/index.js +150 -0
  189. package/plugins-dist/checks/plugin.json +21 -0
  190. package/plugins-dist/checks/project.js +76 -0
  191. package/plugins-dist/commands/index.js +33 -0
  192. package/plugins-dist/commands/plugin.json +9 -0
  193. package/{dist/plugins → plugins-dist/compact}/compact.js +58 -34
  194. package/plugins-dist/compact/index.js +100 -0
  195. package/plugins-dist/compact/plugin.json +25 -0
  196. package/plugins-dist/compact/style.js +14 -0
  197. package/plugins-dist/continue/index.js +57 -0
  198. package/plugins-dist/continue/plugin.json +15 -0
  199. package/{dist/ui → plugins-dist/fs}/diff.js +2 -3
  200. package/{dist/tools → plugins-dist/fs}/fs.js +82 -46
  201. package/{dist/tools → plugins-dist/fs}/grep.js +36 -11
  202. package/plugins-dist/fs/index.js +39 -0
  203. package/plugins-dist/fs/plugin.json +10 -0
  204. package/{dist/ui → plugins-dist/fs}/renderers.js +24 -61
  205. package/plugins-dist/fs/style.js +15 -0
  206. package/plugins-dist/fs/sys.js +54 -0
  207. package/plugins-dist/keys/index.js +36 -0
  208. package/plugins-dist/keys/plugin.json +9 -0
  209. package/plugins-dist/mcp/index.js +187 -0
  210. package/{dist → plugins-dist/mcp}/mcp.js +34 -30
  211. package/plugins-dist/mcp/plugin.json +12 -0
  212. package/plugins-dist/mcp/project.js +90 -0
  213. package/plugins-dist/memory/index.js +94 -0
  214. package/{dist → plugins-dist/memory}/memory.js +21 -3
  215. package/plugins-dist/memory/notes.js +36 -0
  216. package/plugins-dist/memory/plugin.json +11 -0
  217. package/plugins-dist/memory/style.js +14 -0
  218. package/plugins-dist/mentions/attach.js +120 -0
  219. package/plugins-dist/mentions/index.js +87 -0
  220. package/plugins-dist/mentions/plugin.json +9 -0
  221. package/plugins-dist/mentions/style.js +14 -0
  222. package/plugins-dist/models/config.js +53 -0
  223. package/plugins-dist/models/configure.js +415 -0
  224. package/plugins-dist/models/context.js +27 -0
  225. package/plugins-dist/models/index.js +181 -0
  226. package/plugins-dist/models/plugin.json +14 -0
  227. package/{dist → plugins-dist/models}/provider.js +18 -81
  228. package/plugins-dist/models/saved.js +80 -0
  229. package/plugins-dist/modes/index.js +190 -0
  230. package/plugins-dist/modes/plugin.json +18 -0
  231. package/plugins-dist/plugins/index.js +37 -0
  232. package/plugins-dist/plugins/plugin.json +10 -0
  233. package/plugins-dist/print/index.js +172 -0
  234. package/plugins-dist/print/plugin.json +14 -0
  235. package/plugins-dist/prompts/index.js +85 -0
  236. package/plugins-dist/prompts/plugin.json +13 -0
  237. package/plugins-dist/prompts/prompts.js +231 -0
  238. package/plugins-dist/prompts/results.js +60 -0
  239. package/plugins-dist/prompts/sys.js +58 -0
  240. package/plugins-dist/renderers/index.js +36 -0
  241. package/plugins-dist/renderers/plugin.json +9 -0
  242. package/plugins-dist/repeats/index.js +165 -0
  243. package/plugins-dist/repeats/plugin.json +6 -0
  244. package/plugins-dist/schedule/cron.js +67 -0
  245. package/plugins-dist/schedule/index.js +281 -0
  246. package/plugins-dist/schedule/plugin.json +16 -0
  247. package/plugins-dist/schedule/store.js +125 -0
  248. package/plugins-dist/scratch/index.js +26 -0
  249. package/plugins-dist/scratch/plugin.json +10 -0
  250. package/plugins-dist/screenshot/index.js +35 -0
  251. package/plugins-dist/screenshot/plugin.json +11 -0
  252. package/plugins-dist/screenshot/sys.js +76 -0
  253. package/{dist/tools/screenshot.js → plugins-dist/screenshot/tool.js} +5 -4
  254. package/plugins-dist/sessions/index.js +136 -0
  255. package/plugins-dist/sessions/plugin.json +12 -0
  256. package/plugins-dist/shell/index.js +33 -0
  257. package/plugins-dist/shell/plugin.json +19 -0
  258. package/plugins-dist/shell/renderers.js +40 -0
  259. package/plugins-dist/shell/service.js +29 -0
  260. package/{dist/tools → plugins-dist/shell}/shell.js +31 -22
  261. package/{dist → plugins-dist/shell}/sys.js +2 -43
  262. package/plugins-dist/skills/index.js +90 -0
  263. package/plugins-dist/skills/plugin.json +12 -0
  264. package/plugins-dist/skills/project.js +47 -0
  265. package/{dist → plugins-dist/skills}/skills.js +3 -7
  266. package/plugins-dist/suggest/index.js +282 -0
  267. package/plugins-dist/suggest/plugin.json +23 -0
  268. package/plugins-dist/task/index.js +152 -0
  269. package/plugins-dist/task/plugin.json +23 -0
  270. package/plugins-dist/task/style.js +14 -0
  271. package/plugins-dist/task/subagent.js +284 -0
  272. package/{dist/tools/todo.js → plugins-dist/todo/index.js} +31 -9
  273. package/plugins-dist/todo/plugin.json +9 -0
  274. package/{dist/ui → plugins-dist/tui}/editor.js +3 -1
  275. package/plugins-dist/tui/frontend.js +609 -0
  276. package/{dist → plugins-dist/tui}/history.js +0 -1
  277. package/plugins-dist/tui/index.js +21 -0
  278. package/{dist/ui → plugins-dist/tui}/markdown.js +0 -1
  279. package/plugins-dist/tui/mentions.js +153 -0
  280. package/plugins-dist/tui/plugin.json +25 -0
  281. package/{dist/ui → plugins-dist/tui}/render.js +7 -3
  282. package/{dist/ui → plugins-dist/tui}/screen.js +6 -2
  283. package/{dist/ui → plugins-dist/tui}/transcript.js +79 -99
  284. package/{dist/ui → plugins-dist/tui}/tui.js +185 -54
  285. package/plugins-dist/tui/vendor.js +13822 -0
  286. package/{dist/tools → plugins-dist/undo}/checkpoint.js +48 -55
  287. package/plugins-dist/undo/index.js +143 -0
  288. package/plugins-dist/undo/notes.js +36 -0
  289. package/plugins-dist/undo/plugin.json +9 -0
  290. package/plugins-dist/undo/style.js +14 -0
  291. package/plugins-dist/update/index.js +34 -0
  292. package/plugins-dist/update/plugin.json +15 -0
  293. package/plugins-dist/web/env.js +80 -0
  294. package/plugins-dist/web/index.js +124 -0
  295. package/plugins-dist/web/plugin.json +21 -0
  296. package/plugins-dist/web/renderers.js +7 -0
  297. package/{dist/tools → plugins-dist/web}/web.js +56 -29
  298. package/sdk/python/__pycache__/jade_plugin.cpython-312.pyc +0 -0
  299. package/sdk/python/jade_plugin.py +380 -0
  300. package/src/api.ts +298 -0
  301. package/src/config.ts +32 -134
  302. package/src/fetch.ts +216 -0
  303. package/src/hash.ts +39 -0
  304. package/src/host.ts +429 -0
  305. package/src/index.ts +23 -30
  306. package/src/install.ts +355 -0
  307. package/src/main.ts +156 -1387
  308. package/src/manifest.ts +160 -0
  309. package/src/membrane.ts +142 -0
  310. package/src/remote.ts +288 -0
  311. package/src/rescue.ts +217 -0
  312. package/src/resolve.ts +199 -0
  313. package/src/rpc.ts +144 -0
  314. package/src/secrets.ts +122 -0
  315. package/src/session.ts +458 -0
  316. package/src/source.ts +83 -0
  317. package/src/state.ts +120 -0
  318. package/src/update.ts +265 -262
  319. package/LICENSE +0 -21
  320. package/dist/commands.d.ts +0 -50
  321. package/dist/commands.js +0 -126
  322. package/dist/commands.js.map +0 -1
  323. package/dist/context.d.ts +0 -17
  324. package/dist/context.js +0 -53
  325. package/dist/context.js.map +0 -1
  326. package/dist/distro.d.ts +0 -141
  327. package/dist/distro.js +0 -462
  328. package/dist/distro.js.map +0 -1
  329. package/dist/history.d.ts +0 -10
  330. package/dist/history.js.map +0 -1
  331. package/dist/mcp.d.ts +0 -114
  332. package/dist/mcp.js.map +0 -1
  333. package/dist/memory.d.ts +0 -19
  334. package/dist/memory.js.map +0 -1
  335. package/dist/mentions.d.ts +0 -35
  336. package/dist/mentions.js +0 -130
  337. package/dist/mentions.js.map +0 -1
  338. package/dist/plugin-cli.d.ts +0 -16
  339. package/dist/plugin-cli.js +0 -294
  340. package/dist/plugin-cli.js.map +0 -1
  341. package/dist/plugins/budget.d.ts +0 -9
  342. package/dist/plugins/budget.js +0 -30
  343. package/dist/plugins/budget.js.map +0 -1
  344. package/dist/plugins/builtins.d.ts +0 -10
  345. package/dist/plugins/builtins.js +0 -25
  346. package/dist/plugins/builtins.js.map +0 -1
  347. package/dist/plugins/checks.d.ts +0 -71
  348. package/dist/plugins/checks.js.map +0 -1
  349. package/dist/plugins/compact.d.ts +0 -26
  350. package/dist/plugins/compact.js.map +0 -1
  351. package/dist/plugins/core.d.ts +0 -47
  352. package/dist/plugins/core.js +0 -229
  353. package/dist/plugins/core.js.map +0 -1
  354. package/dist/plugins/host.d.ts +0 -52
  355. package/dist/plugins/host.js +0 -115
  356. package/dist/plugins/host.js.map +0 -1
  357. package/dist/plugins/install.d.ts +0 -68
  358. package/dist/plugins/install.js +0 -377
  359. package/dist/plugins/install.js.map +0 -1
  360. package/dist/plugins/loader.d.ts +0 -410
  361. package/dist/plugins/loader.js +0 -407
  362. package/dist/plugins/loader.js.map +0 -1
  363. package/dist/plugins/policy.d.ts +0 -98
  364. package/dist/plugins/policy.js.map +0 -1
  365. package/dist/plugins/prompts.d.ts +0 -43
  366. package/dist/plugins/prompts.js +0 -284
  367. package/dist/plugins/prompts.js.map +0 -1
  368. package/dist/plugins/repeats.d.ts +0 -16
  369. package/dist/plugins/repeats.js +0 -151
  370. package/dist/plugins/repeats.js.map +0 -1
  371. package/dist/plugins/review.d.ts +0 -18
  372. package/dist/plugins/review.js.map +0 -1
  373. package/dist/plugins/schema.d.ts +0 -2
  374. package/dist/plugins/schema.js.map +0 -1
  375. package/dist/plugins/sessions.d.ts +0 -7
  376. package/dist/plugins/sessions.js +0 -110
  377. package/dist/plugins/sessions.js.map +0 -1
  378. package/dist/provider.d.ts +0 -165
  379. package/dist/provider.js.map +0 -1
  380. package/dist/session-lifecycle.d.ts +0 -61
  381. package/dist/session-lifecycle.js +0 -167
  382. package/dist/session-lifecycle.js.map +0 -1
  383. package/dist/session-scope.d.ts +0 -53
  384. package/dist/session-scope.js +0 -116
  385. package/dist/session-scope.js.map +0 -1
  386. package/dist/sessions.d.ts +0 -28
  387. package/dist/sessions.js +0 -73
  388. package/dist/sessions.js.map +0 -1
  389. package/dist/skills.d.ts +0 -37
  390. package/dist/skills.js.map +0 -1
  391. package/dist/sys.d.ts +0 -51
  392. package/dist/sys.js.map +0 -1
  393. package/dist/tools/ask.d.ts +0 -11
  394. package/dist/tools/ask.js +0 -62
  395. package/dist/tools/ask.js.map +0 -1
  396. package/dist/tools/checkpoint.d.ts +0 -43
  397. package/dist/tools/checkpoint.js.map +0 -1
  398. package/dist/tools/fs.d.ts +0 -39
  399. package/dist/tools/fs.js.map +0 -1
  400. package/dist/tools/grep.d.ts +0 -6
  401. package/dist/tools/grep.js.map +0 -1
  402. package/dist/tools/screenshot.d.ts +0 -15
  403. package/dist/tools/screenshot.js.map +0 -1
  404. package/dist/tools/shell.d.ts +0 -55
  405. package/dist/tools/shell.js.map +0 -1
  406. package/dist/tools/task.d.ts +0 -39
  407. package/dist/tools/task.js +0 -117
  408. package/dist/tools/task.js.map +0 -1
  409. package/dist/tools/todo.d.ts +0 -10
  410. package/dist/tools/todo.js.map +0 -1
  411. package/dist/tools/web.d.ts +0 -53
  412. package/dist/tools/web.js.map +0 -1
  413. package/dist/ui/configure.d.ts +0 -20
  414. package/dist/ui/configure.js +0 -447
  415. package/dist/ui/configure.js.map +0 -1
  416. package/dist/ui/diff.d.ts +0 -20
  417. package/dist/ui/diff.js.map +0 -1
  418. package/dist/ui/editor.d.ts +0 -41
  419. package/dist/ui/editor.js.map +0 -1
  420. package/dist/ui/markdown.d.ts +0 -22
  421. package/dist/ui/markdown.js.map +0 -1
  422. package/dist/ui/render.d.ts +0 -14
  423. package/dist/ui/render.js.map +0 -1
  424. package/dist/ui/renderers.d.ts +0 -8
  425. package/dist/ui/renderers.js.map +0 -1
  426. package/dist/ui/screen.d.ts +0 -118
  427. package/dist/ui/screen.js.map +0 -1
  428. package/dist/ui/transcript.d.ts +0 -46
  429. package/dist/ui/transcript.js.map +0 -1
  430. package/dist/ui/tui.d.ts +0 -47
  431. package/dist/ui/tui.js.map +0 -1
  432. package/src/commands.ts +0 -144
  433. package/src/context.ts +0 -64
  434. package/src/distro.ts +0 -577
  435. package/src/mentions.ts +0 -135
  436. package/src/plugin-cli.ts +0 -278
  437. package/src/plugins/budget.ts +0 -37
  438. package/src/plugins/builtins.ts +0 -34
  439. package/src/plugins/core.ts +0 -257
  440. package/src/plugins/host.ts +0 -146
  441. package/src/plugins/install.ts +0 -429
  442. package/src/plugins/loader.ts +0 -742
  443. package/src/plugins/prompts.ts +0 -327
  444. package/src/plugins/repeats.ts +0 -157
  445. package/src/plugins/sessions.ts +0 -109
  446. package/src/session-lifecycle.ts +0 -194
  447. package/src/session-scope.ts +0 -135
  448. package/src/sessions.ts +0 -78
  449. package/src/tools/ask.ts +0 -72
  450. package/src/tools/task.ts +0 -149
  451. package/src/tools/todo.ts +0 -67
  452. package/src/ui/configure.ts +0 -471
  453. /package/{src/plugins → plugins/approval}/schema.ts +0 -0
  454. /package/{src → plugins/tui}/history.ts +0 -0
  455. /package/{src/ui → plugins/tui}/markdown.ts +0 -0
@@ -0,0 +1,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
+ });
@@ -2,10 +2,11 @@
2
2
  //
3
3
  // 两个范围:user(所有项目通用,$JADE_HOME/MEMORY.md)和 project(这个仓库,$JADE_HOME/projects/<key>/MEMORY.md)。
4
4
  // 都放在配置目录而不是仓库里:不会被提交,也不会被别人的仓库带进来。
5
- // 文件是 Markdown 列表,一行一条,用户可以直接编辑。会话开始时由 prompts 插件读进系统提示词,
6
- // 模型用 memory 工具增删,用户用 /memory 查看和管理。
5
+ // 文件是 Markdown 列表,一行一条,用户可以直接编辑。会话开始时经 prompts@1 读进系统提示词,
6
+ // 模型用 memory 工具增删,用户用 /memory 查看和管理。从旧 jade 的 memory.ts 移植,文件位置和格式不变。
7
7
 
8
8
  import { createHash } from "node:crypto";
9
+ import { existsSync, realpathSync } from "node:fs";
9
10
  import { mkdir, readFile, writeFile } from "node:fs/promises";
10
11
  import path from "node:path";
11
12
  import type { Tool } from "uncarved";
@@ -96,6 +97,23 @@ export function projectKey(root: string): string {
96
97
  return `${readable}-${createHash("sha256").update(full.toLowerCase()).digest("hex").slice(0, 8)}`;
97
98
  }
98
99
 
100
+ /** git 仓库的根目录(往上找 .git);不在仓库里时是 cwd 本身。和旧 jade 的 git rev-parse 结果相同,项目记忆的位置不变 */
101
+ export function projectRoot(cwd: string): string {
102
+ let dir = path.resolve(cwd);
103
+ for (;;) {
104
+ if (existsSync(path.join(dir, ".git"))) {
105
+ try {
106
+ return realpathSync.native(dir);
107
+ } catch {
108
+ return dir;
109
+ }
110
+ }
111
+ const up = path.dirname(dir);
112
+ if (up === dir) return path.resolve(cwd);
113
+ dir = up;
114
+ }
115
+ }
116
+
99
117
  export function memoryTool(memory: Memory): Tool {
100
118
  return {
101
119
  name: "memory",
@@ -0,0 +1,43 @@
1
+ // 给模型的说明([Note from jade]):命令里做的事(例如用户删掉了一条记忆)要让模型知道,
2
+ // 但命令拿不到会话日志,也不该替用户发一条消息。所以先记下来,下一次请求模型时在 context.project 里
3
+ // 附在最后一条消息后面,并用 ctx.record 写进日志(derived):之后的投影、恢复的会话里它都在同一个位置。
4
+ // 插件之间不共享代码,jade/undo 里也有一份。
5
+
6
+ import type { Block, LocalHookSpec, Message } from "uncarved";
7
+
8
+ /** derived 里:消息的下标 → 附在它后面的说明 */
9
+ type NotesState = Record<string, string[]>;
10
+
11
+ export class Notes {
12
+ /** 会话 → 还没交给模型的说明 */
13
+ readonly #pending = new Map<string, string[]>();
14
+
15
+ add(sessionId: string, text: string): void {
16
+ this.#pending.set(sessionId, [...(this.#pending.get(sessionId) ?? []), text]);
17
+ }
18
+
19
+ /** 会话里的 context.project hook;key 是 derived 里的键 */
20
+ hook(sessionId: string, plugin: string, key: string): LocalHookSpec {
21
+ return {
22
+ kind: "transform",
23
+ point: "context.project",
24
+ order: -40,
25
+ fn: async (messages, ctx) => {
26
+ let state = (ctx.derived[key] as NotesState | undefined) ?? {};
27
+ const fresh = this.#pending.get(sessionId);
28
+ if (fresh?.length && messages.length > 0) {
29
+ const at = String(messages.length - 1);
30
+ state = { ...state, [at]: [...(state[at] ?? []), ...fresh] };
31
+ await ctx.record(key, state);
32
+ this.#pending.delete(sessionId);
33
+ }
34
+ return messages.map((m, i): Message => {
35
+ const notes = state[i];
36
+ if (!notes?.length || m.role !== "user") return m;
37
+ const blocks: Block[] = notes.map((text) => ({ kind: "text", text: `[Note from jade] ${text}`, origin: { by: "plugin", id: plugin }, trust: "trusted" }));
38
+ return { ...m, content: [...m.content, ...blocks] };
39
+ });
40
+ },
41
+ };
42
+ }
43
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "id": "jade/memory",
3
+ "version": "0.2.0",
4
+ "api": "^1",
5
+ "entry": "./index.ts",
6
+ "optional": ["prompts@1", "commands@1", "renderers@1"]
7
+ }