@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,90 @@
1
+ // jade/skills:skill 工具、系统提示词里的 skill 列表、/skills,以及每个 skill 一条 /<skill 名> 命令。
2
+ //
3
+ // 每个会话打开时重新查找 skill(/clear 之后能用上新装的)。随仓库分发的 skill(项目层)不用确认:
4
+ // 它只是给模型看的文字,不执行代码;和旧 jade 一样,列表里有项目层的 skill 时整段标为不可信。
5
+ import path from "node:path";
6
+ import { definePlugin } from "../../dist/api.js";
7
+ import { bold, clip, dim, display, realPath, repoRoot } from "./project.js";
8
+ import { loadSkills, skillsPrompt, skillTool } from "./skills.js";
9
+ const ID = "jade/skills";
10
+ /** /<skill> 发给模型的消息:让它先加载这个 skill */
11
+ export function skillMessage(name, args) {
12
+ return `Use the "${name}" skill${args.trim() ? ` for this: ${args.trim()}` : "."}`;
13
+ }
14
+ async function find(home, cwd) {
15
+ const here = realPath(cwd);
16
+ return loadSkills({ home, root: realPath(repoRoot(here)), cwd: here });
17
+ }
18
+ /** 最近一个会话找到的 skill,/skills 显示它 */
19
+ let latest;
20
+ /** 最近一个会话注册的 /<skill> 命令 → 撤销函数 */
21
+ const skillCommands = new Map();
22
+ /** 已经告诉过用户的警告:每个会话都会重新查找,同样的警告不重复说 */
23
+ const warned = new Set();
24
+ export default definePlugin({
25
+ process(ctx) {
26
+ latest = undefined;
27
+ skillCommands.clear();
28
+ ctx.service("commands@1")?.register({
29
+ name: "skills",
30
+ description: "skills the agent can use",
31
+ instant: true,
32
+ async run() {
33
+ const skills = latest ?? (await find(ctx.home, ctx.cwd)).skills;
34
+ if (skills.length === 0) {
35
+ return dim(`(no skills) put them in ${display(ctx.cwd, path.join(ctx.home, "skills"))}/<name>/SKILL.md or .jade/skills/<name>/SKILL.md`);
36
+ }
37
+ return skills
38
+ .map((sk) => `${bold(sk.name)} ${dim(`${sk.layer} · ${display(ctx.cwd, sk.dir)}`)}\n ${clip(sk.description.replace(/\s+/g, " "), 300)}`)
39
+ .join("\n");
40
+ },
41
+ });
42
+ },
43
+ async session(ctx) {
44
+ const { skills, warnings } = await find(ctx.home, ctx.cwd);
45
+ latest = skills;
46
+ const ui = ctx.service("ui@1");
47
+ for (const w of warnings) {
48
+ if (warned.has(w))
49
+ continue;
50
+ warned.add(w);
51
+ ui?.notify(`${ID}: ${w}`, "warning");
52
+ }
53
+ if (skills.length === 0)
54
+ return;
55
+ ctx.kernel.tool(skillTool(skills));
56
+ const text = skillsPrompt(skills);
57
+ // 读 skill 目录里的文件(脚本、参考资料)不用问;会话关闭时撤销
58
+ const approval = ctx.service("approval@1");
59
+ for (const sk of skills)
60
+ approval?.allowRead(sk.dir);
61
+ // 有随仓库分发的 skill 时整段不可信
62
+ ctx.service("prompts@1")?.add({ text, untrusted: !skills.every((s) => s.layer === "user") });
63
+ // skill 也可以当命令用:/<skill 名> [要做的事]。挂在会话作用域上,随会话撤销。
64
+ // 新会话在旧会话关闭之前打开:旧会话注册的同名命令先撤销,换成这个会话的。
65
+ // 名字已被别的插件的命令占用时让给它(会话级的注册总在进程级的命令之后)
66
+ const commands = ctx.service("commands@1");
67
+ if (commands) {
68
+ for (const sk of skills) {
69
+ const key = sk.name.toLowerCase();
70
+ const taken = commands.get(sk.name);
71
+ if (taken && taken.plugin !== ID)
72
+ continue;
73
+ if (taken)
74
+ skillCommands.get(key)?.();
75
+ try {
76
+ const revoke = commands.register({
77
+ name: sk.name,
78
+ args: "[task]",
79
+ description: `${clip(sk.description.replace(/\s+/g, " "), 80)} (skill)`,
80
+ run: (args) => ({ prompt: skillMessage(sk.name, args) }),
81
+ });
82
+ skillCommands.set(key, revoke);
83
+ }
84
+ catch {
85
+ // 名字不能当命令名(commands@1 的规则更严)或刚被占用:只是少一条快捷命令
86
+ }
87
+ }
88
+ }
89
+ },
90
+ });
@@ -0,0 +1,12 @@
1
+ {
2
+ "id": "jade/skills",
3
+ "version": "0.2.0",
4
+ "api": "^1",
5
+ "entry": "./index.js",
6
+ "optional": [
7
+ "ui@1",
8
+ "prompts@1",
9
+ "commands@1",
10
+ "approval@1"
11
+ ]
12
+ }
@@ -0,0 +1,47 @@
1
+ // 仓库目录、显示用的小工具。插件之间不共享代码(只能共享类型),jade/mcp、jade/checks 各有一份。
2
+ import { existsSync, realpathSync } from "node:fs";
3
+ import path from "node:path";
4
+ export function realPath(p) {
5
+ try {
6
+ return realpathSync.native(p);
7
+ }
8
+ catch {
9
+ return path.resolve(p);
10
+ }
11
+ }
12
+ /** git 仓库的根目录(往上找 .git,目录或文件都算);不在仓库里时是 cwd 本身 */
13
+ export function repoRoot(cwd) {
14
+ let d = path.resolve(cwd);
15
+ for (;;) {
16
+ if (existsSync(path.join(d, ".git")))
17
+ return d;
18
+ const parent = path.dirname(d);
19
+ if (parent === d)
20
+ return path.resolve(cwd);
21
+ d = parent;
22
+ }
23
+ }
24
+ /** 从仓库根目录到工作目录的每一级目录,远的在前;工作目录不在仓库里时只有工作目录 */
25
+ export function projectDirs(root, cwd) {
26
+ const rel = path.relative(root, cwd);
27
+ const inside = rel === "" || !(rel === ".." || rel.startsWith(`..${path.sep}`) || path.isAbsolute(rel));
28
+ if (!inside)
29
+ return [cwd];
30
+ const dirs = [root];
31
+ if (rel)
32
+ for (const seg of rel.split(path.sep))
33
+ dirs.push(path.join(dirs.at(-1), seg));
34
+ return dirs;
35
+ }
36
+ /** 工作目录里的显示成相对路径,外面的显示绝对路径 */
37
+ export function display(cwd, full) {
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
+ export const clip = (s, n) => (s.length > n ? s.slice(0, n) + "…" : s);
43
+ // 设了 NO_COLOR(非空)或标准输出不是终端时不输出颜色,见 https://no-color.org
44
+ const colors = Boolean(process.stdout.isTTY) && !process.env.NO_COLOR;
45
+ const paint = (open, close) => (s) => colors ? `\x1b[${open}m${s.replaceAll(`\x1b[${close}m`, `\x1b[${close}m\x1b[${open}m`)}\x1b[${close}m` : s;
46
+ export const dim = paint("2", "22");
47
+ export const bold = paint("1", "22");
@@ -11,22 +11,20 @@
11
11
  // 查找位置(同名时后面的覆盖前面的):
12
12
  // ~/.claude/skills、$JADE_HOME/skills(用户层);
13
13
  // 仓库根目录到工作目录每一级的 .claude/skills、.jade/skills(项目层)。
14
+ // 从旧 jade 的 src/skills.ts 移植;旧 jade 的"插件自带 skills 目录"(PluginBundle)没有移植:新的插件宿主没有内容包的概念。
14
15
  import { readdir, readFile, stat } from "node:fs/promises";
15
16
  import os from "node:os";
16
17
  import path from "node:path";
17
- import { projectDirs } from "./commands.js";
18
+ import { projectDirs } from "./project.js";
18
19
  const NAME = /^[a-z0-9][a-z0-9_-]*$/i;
19
20
  /** 系统提示词里每个描述的上限 */
20
21
  const MAX_DESCRIPTION = 400;
21
22
  /** skill 工具列出的目录内文件数上限 */
22
23
  const MAX_FILES = 60;
23
24
  export async function loadSkills(opts) {
24
- const fromPlugins = (layer) => (opts.plugins ?? []).filter((p) => p.layer === layer);
25
25
  const dirs = [
26
- ...fromPlugins("user"),
27
26
  { dir: path.join(opts.userHome ?? os.homedir(), ".claude", "skills"), layer: "user" },
28
27
  { dir: path.join(opts.home, "skills"), layer: "user" },
29
- ...fromPlugins("project"),
30
28
  ];
31
29
  for (const d of projectDirs(opts.root, opts.cwd)) {
32
30
  dirs.push({ dir: path.join(d, ".claude", "skills"), layer: "project" }, { dir: path.join(d, ".jade", "skills"), layer: "project" });
@@ -34,7 +32,7 @@ export async function loadSkills(opts) {
34
32
  const out = new Map();
35
33
  const warnings = [];
36
34
  const seen = new Set();
37
- for (const { dir, layer, plugin } of dirs) {
35
+ for (const { dir, layer } of dirs) {
38
36
  // JADE_HOME 就是 ~/.claude 之类的情况,同一个目录不读两次
39
37
  if (seen.has(path.resolve(dir)))
40
38
  continue;
@@ -76,7 +74,6 @@ export async function loadSkills(opts) {
76
74
  dir: skillDir,
77
75
  layer,
78
76
  overrides: prev?.dir,
79
- ...(plugin ? { plugin } : {}),
80
77
  });
81
78
  }
82
79
  }
@@ -176,4 +173,3 @@ async function listFiles(dir) {
176
173
  return [];
177
174
  }
178
175
  }
179
- //# sourceMappingURL=skills.js.map
@@ -0,0 +1,282 @@
1
+ // jade/suggest:每一轮正常结束后,预测用户下一条想发的消息,灰色显示在输入框里,Tab 或 → 接受。默认关着(enabled)。
2
+ //
3
+ // 模型经 models@1:配置 model 是 /model 保存过的模型名,不设时用会话的模型。
4
+ // /suggest 在 TUI 里开关、选模型,马上生效,记在 $JADE_HOME/state/suggest.json,盖过 config.json 里的 enabled 和 model。
5
+ // 对话从 context.project(每次请求模型前的消息)和 model.after(这一轮最后的回复)取,轮次结束从 turn.ended 事件知道。
6
+ // 从旧 jade 的 examples/plugins/suggest 移植;提示词、对话的整理和截取、回复的清理参考 dsh-ghost-prompt。
7
+ import { randomBytes } from "node:crypto";
8
+ import { mkdir, readFile, rename, writeFile } from "node:fs/promises";
9
+ import path from "node:path";
10
+ import { definePlugin } from "../../dist/api.js";
11
+ export const SYSTEM = [
12
+ "You predict the next message the USER will type to an AI coding assistant.",
13
+ "You are given the recent conversation. Write the single message the user is most likely to send next, exactly as they would type it.",
14
+ "Rules:",
15
+ '- Write from the user\'s point of view, addressed to the assistant (e.g. "run the tests", "commit this", "yes, go ahead").',
16
+ "- Match the language and tone the user has been writing in. If the user writes Chinese, answer in Chinese.",
17
+ "- Keep it short: one sentence, at most about 20 words or 40 CJK characters.",
18
+ "- Prefer the obvious next step: answering a question the assistant just asked, approving a proposed plan, verifying or continuing the work.",
19
+ "- Never repeat a request the user already made, and never invent facts, file names or numbers not in the conversation.",
20
+ "- If no next message is reasonably predictable, output exactly: NONE",
21
+ 'Output only the message text on one line. No quotes, no prefix like "User:", no explanation, no Markdown.',
22
+ ].join("\n");
23
+ /** 送给预测模型的最近对话(字符),从最新的往前取 */
24
+ const MAX_CONTEXT_CHARS = 8000;
25
+ /** 每条消息最多这么多字,超出时留头尾 */
26
+ const PER_MESSAGE_CHARS = 2400;
27
+ /** 一次预测的时限 */
28
+ const TIMEOUT_MS = 30_000;
29
+ /** 太长的消息留头和尾,中间最不要紧 */
30
+ function clip(text, max) {
31
+ if (text.length <= max)
32
+ return text;
33
+ const half = Math.floor((max - 5) / 2);
34
+ return `${text.slice(0, half)}\n…\n${text.slice(-half)}`;
35
+ }
36
+ /** 一条消息里给预测模型看的文字:用户消息只取用户自己打的字(工具结果、插件附的说明不算),回复里的工具调用只留名字 */
37
+ function textOf(m) {
38
+ const parts = [];
39
+ for (const b of m.content) {
40
+ if (b.kind === "text" && b.text.trim() && (m.role === "assistant" || b.origin.by === "user"))
41
+ parts.push(b.text.trim());
42
+ else if (b.kind === "tool_use" && m.role === "assistant")
43
+ parts.push(`[called tool: ${b.name}]`);
44
+ }
45
+ return parts.join("\n");
46
+ }
47
+ /** 整理成用户、助手交替的对话:没有文字的消息去掉,相邻同一方的合并(一轮里助手的几步并成一条) */
48
+ export function transcriptOf(messages) {
49
+ const out = [];
50
+ for (const m of messages) {
51
+ const text = textOf(m);
52
+ if (!text)
53
+ continue;
54
+ const last = out.at(-1);
55
+ if (last?.role === m.role)
56
+ last.text += `\n${text}`;
57
+ else
58
+ out.push({ role: m.role, text });
59
+ }
60
+ return out;
61
+ }
62
+ const frameLine = (e) => `<${e.role}>\n${clip(e.text, PER_MESSAGE_CHARS)}\n</${e.role}>`;
63
+ /** 从最新的往前放,放不下就停;最后一条总是放进去 */
64
+ export function frame(transcript, budget = MAX_CONTEXT_CHARS) {
65
+ const lines = [];
66
+ let used = 0;
67
+ for (let i = transcript.length - 1; i >= 0; i--) {
68
+ const line = frameLine(transcript[i]);
69
+ if (lines.length > 0 && used + line.length > budget)
70
+ break;
71
+ lines.unshift(line);
72
+ used += line.length;
73
+ }
74
+ return ["Recent conversation, oldest first:", "", lines.join("\n\n"), "", "Predict the user's next message."].join("\n");
75
+ }
76
+ const LEADING_PREFIX = /^(?:user|用户)\s*[::]\s*/i;
77
+ const LEADING_QUOTES = /^["'“”‘’`「『]+/;
78
+ const TRAILING_QUOTES = /["'“”‘’`」』]+$/;
79
+ /** 模型回复的第一行整理成建议:去掉 "User:" 前缀和包着的引号;NONE 或空的时候 undefined */
80
+ export function tidy(reply) {
81
+ let line = reply.trimStart().split(/\r?\n/)[0].trim().replace(LEADING_PREFIX, "");
82
+ if (LEADING_QUOTES.test(line))
83
+ line = line.replace(LEADING_QUOTES, "").replace(TRAILING_QUOTES, "").trim();
84
+ if (!line || /^none\.?$/i.test(line))
85
+ return undefined;
86
+ return line.length > 300 ? `${line.slice(0, 299)}…` : line;
87
+ }
88
+ /** process() 里读好、/suggest 改的设置,session() 里每次预测时读 */
89
+ let settings = { enabled: false, model: undefined };
90
+ /** 设置改了时通知每个会话(关掉时去掉已经显示的建议) */
91
+ const changed = new Set();
92
+ /** state/suggest.json 里 /suggest 记下的设置;没有、读不了或格式不对的键不算 */
93
+ async function readState(file) {
94
+ try {
95
+ const data = JSON.parse(await readFile(file, "utf8"));
96
+ return {
97
+ ...(typeof data.enabled === "boolean" ? { enabled: data.enabled } : {}),
98
+ // 空字符串表示用会话的模型
99
+ ...(typeof data.model === "string" ? { model: data.model.trim() || undefined } : {}),
100
+ };
101
+ }
102
+ catch {
103
+ return {};
104
+ }
105
+ }
106
+ async function writeState(file, s) {
107
+ await mkdir(path.dirname(file), { recursive: true });
108
+ const tmp = `${file}.${process.pid}.${randomBytes(4).toString("hex")}.tmp`;
109
+ await writeFile(tmp, `${JSON.stringify({ enabled: s.enabled, model: s.model ?? "" }, null, 2)}\n`);
110
+ await rename(tmp, file);
111
+ }
112
+ export default definePlugin({
113
+ async process(ctx) {
114
+ const file = path.join(ctx.home, "state", "suggest.json");
115
+ const raw = ctx.config.model;
116
+ if (raw !== undefined && typeof raw !== "string")
117
+ ctx.service("ui@1")?.notify(`jade/suggest: model must be a model name, got ${JSON.stringify(raw)}; using the session's model`, "warning");
118
+ settings = {
119
+ enabled: ctx.config.enabled === true,
120
+ model: typeof raw === "string" && raw.trim() ? raw.trim() : undefined,
121
+ ...(await readState(file)),
122
+ };
123
+ const models = ctx.require("models@1");
124
+ const describe = () => `suggestions are ${settings.enabled ? "on" : "off"}, predicted by ${settings.model ? `the saved model ${settings.model}` : "the session's model"}`;
125
+ const update = async (next) => {
126
+ settings = { ...settings, ...next };
127
+ for (const fn of changed)
128
+ fn();
129
+ await writeState(file, settings);
130
+ return `${describe()}.`;
131
+ };
132
+ ctx.service("commands@1")?.register({
133
+ name: "suggest",
134
+ args: "[on|off|model [name]]",
135
+ description: "predict your next message after each turn (one more model request per turn), and which model predicts",
136
+ // 只改插件自己的设置
137
+ instant: true,
138
+ async run(args, c) {
139
+ const [sub = "", ...rest] = args.trim().split(/\s+/);
140
+ if (sub === "on" || sub === "off")
141
+ return update({ enabled: sub === "on" });
142
+ if (sub === "model") {
143
+ const saved = (await models.saved?.()) ?? [];
144
+ let name = rest.join(" ");
145
+ if (!name) {
146
+ const SESSION = "\0session";
147
+ const picked = await c.ui.select({
148
+ title: "Which model predicts your next message?",
149
+ options: [
150
+ { label: "The session's model", value: SESSION },
151
+ ...saved.map((m) => ({ label: m, value: m, ...(m === settings.model ? { hint: "current" } : {}) })),
152
+ ],
153
+ }, c.signal);
154
+ if (picked === undefined)
155
+ return;
156
+ name = picked === SESSION ? undefined : picked;
157
+ }
158
+ else if (models.saved && !saved.includes(name)) {
159
+ return `${name} is not a model saved by /model. ${saved.length ? `Saved: ${saved.join(", ")}.` : "Add one with /model first."}`;
160
+ }
161
+ return update({ model: name });
162
+ }
163
+ if (sub)
164
+ return "usage: /suggest [on|off|model [name]]";
165
+ return `${describe()}. /suggest on|off turns them on or off; /suggest model picks the model.`;
166
+ },
167
+ });
168
+ },
169
+ session(ctx) {
170
+ const input = ctx.input;
171
+ // 没有输入框的前端(-p)用不上
172
+ if (!input)
173
+ return;
174
+ const models = ctx.require("models@1");
175
+ /** 最近一次发给模型的消息,加上这一轮最后的回复 */
176
+ let messages = [];
177
+ let reply;
178
+ /** 正在进行的预测:新的一次请求开始、会话结束时中止 */
179
+ let pending;
180
+ ctx.signal.addEventListener("abort", () => pending?.abort());
181
+ // /suggest off:停下正在进行的预测,去掉已经显示的建议
182
+ const onChange = () => {
183
+ if (settings.enabled)
184
+ return;
185
+ pending?.abort();
186
+ input.hint(undefined);
187
+ };
188
+ changed.add(onChange);
189
+ ctx.signal.addEventListener("abort", () => changed.delete(onChange));
190
+ /** 上一次提示过的错误:同样的错误每轮都提示太吵,成功一次后清掉 */
191
+ let warned;
192
+ const warn = (e) => {
193
+ const message = e instanceof Error ? e.message : String(e);
194
+ if (message === warned)
195
+ return;
196
+ warned = message;
197
+ ctx.service("ui@1")?.notify(`jade/suggest: prediction failed (${settings.model ? `model ${settings.model}` : "the session's model"}): ${message}`, "warning");
198
+ };
199
+ async function predict() {
200
+ if (!settings.enabled)
201
+ return;
202
+ const { model } = settings;
203
+ const transcript = transcriptOf([...messages, ...(reply ? [reply] : [])]);
204
+ // 用户还没说过话,或者最后不是助手的回复:没有可回答的
205
+ if (!transcript.some((e) => e.role === "user") || transcript.at(-1)?.role !== "assistant")
206
+ return;
207
+ pending?.abort();
208
+ const mine = (pending = new AbortController());
209
+ // 第一行完整了就停:建议只要一行,后面的都会丢掉
210
+ const firstLine = new AbortController();
211
+ let streamed = "";
212
+ const onDelta = (d) => {
213
+ if (d.kind === "reset")
214
+ streamed = "";
215
+ else if (d.kind === "text")
216
+ streamed += d.text;
217
+ if (/\S[^\n]*\n/.test(streamed))
218
+ firstLine.abort();
219
+ };
220
+ const origin = { by: "plugin", id: ctx.plugin };
221
+ const request = {
222
+ system: [{ text: SYSTEM, stability: "stable", origin, trust: "trusted" }],
223
+ messages: [{ role: "user", content: [{ kind: "text", text: frame(transcript), origin, trust: "trusted" }] }],
224
+ tools: [],
225
+ };
226
+ let text;
227
+ const timeout = AbortSignal.timeout(TIMEOUT_MS);
228
+ try {
229
+ const res = await models.complete(request, {
230
+ signal: AbortSignal.any([mine.signal, firstLine.signal, timeout]),
231
+ onDelta,
232
+ ...(model ? { model } : {}),
233
+ });
234
+ text = res.content.flatMap((b) => (b.kind === "text" ? [b.text] : [])).join("");
235
+ }
236
+ catch (e) {
237
+ // 第一行完整后自己停下的,用已经收到的
238
+ if (firstLine.signal.aborted && !mine.signal.aborted)
239
+ text = streamed;
240
+ else {
241
+ // 超时、被中止不打扰用户;模型出错(配置不对之类)说一次,否则开着却什么都不显示,看不出为什么
242
+ if (!mine.signal.aborted && !timeout.aborted && !ctx.signal.aborted)
243
+ warn(e);
244
+ return;
245
+ }
246
+ }
247
+ warned = undefined;
248
+ const hint = tidy(text);
249
+ if (hint && !mine.signal.aborted)
250
+ input.hint(hint);
251
+ }
252
+ ctx.kernel.hook({
253
+ // 每次请求模型前:记下这次发出的消息,不改它们。新的请求说明新的一轮(或下一步)开始了,之前的建议作废
254
+ kind: "transform",
255
+ point: "context.project",
256
+ optional: true,
257
+ fn: (msgs) => {
258
+ messages = msgs;
259
+ reply = undefined;
260
+ pending?.abort();
261
+ input.hint(undefined);
262
+ return undefined;
263
+ },
264
+ });
265
+ ctx.kernel.hook({
266
+ kind: "observe",
267
+ point: "model.after",
268
+ fn: (res) => {
269
+ reply = { role: "assistant", content: res.content };
270
+ },
271
+ });
272
+ ctx.kernel.hook({
273
+ // 这一轮正常结束(不是中断、出错或被截断)时预测。不 await:hook 有时限,预测在后台进行
274
+ kind: "observe",
275
+ point: "event",
276
+ fn: (e) => {
277
+ if (e.type === "turn.ended" && e.data.reason === "end")
278
+ void predict();
279
+ },
280
+ });
281
+ },
282
+ });
@@ -0,0 +1,23 @@
1
+ {
2
+ "id": "jade/suggest",
3
+ "version": "0.1.0",
4
+ "api": "^1",
5
+ "entry": "./index.js",
6
+ "requires": [
7
+ "models@1"
8
+ ],
9
+ "optional": [
10
+ "ui@1",
11
+ "commands@1"
12
+ ],
13
+ "config": {
14
+ "enabled": {
15
+ "default": false,
16
+ "description": "after each turn, predict your next message and show it in gray in the input box (Tab or → accepts it); each prediction is one more model request; /suggest on|off overrides it"
17
+ },
18
+ "model": {
19
+ "default": "",
20
+ "description": "the model that predicts, by a name saved with /model; empty uses the session's model; /suggest model overrides it"
21
+ }
22
+ }
23
+ }
@@ -0,0 +1,152 @@
1
+ // jade/task:task 工具,把调研交给只读的子 Agent(见 subagent.ts)。
2
+ //
3
+ // 子 Agent 用哪些工具:插件经 task@1 登记只读工具(jade/fs 登记 read_file、list_dir、glob、grep),
4
+ // 登记随登记者的作用域撤销。主会话里的工具对象是各插件私有的,子 Agent 拿到的是登记者另给的一份。
5
+ import { definePlugin } from "../../dist/api.js";
6
+ import { taskTool } from "./subagent.js";
7
+ import { clip, dim, red } from "./style.js";
8
+ const DEFAULT_MAX_STEPS = 40;
9
+ const MAX_DETAIL_LINES = 40;
10
+ /** 登记的只读工具,按登记顺序 */
11
+ const registry = [];
12
+ /** 这次启动子 Agent 时给它的工具:同名的取最后登记的那个,when 返回 false 或出错的不给 */
13
+ function available() {
14
+ const latest = new Map();
15
+ for (const r of registry) {
16
+ latest.delete(r.tool.name);
17
+ latest.set(r.tool.name, r);
18
+ }
19
+ return [...latest.values()].flatMap((r) => {
20
+ try {
21
+ return !r.when || r.when() ? [r.tool] : [];
22
+ }
23
+ catch {
24
+ return [];
25
+ }
26
+ });
27
+ }
28
+ /** 子 Agent 的审批一次问一个:并行的几个子 Agent 不同时弹对话框 */
29
+ let asking = Promise.resolve();
30
+ export default definePlugin({
31
+ process(ctx) {
32
+ ctx.provide("task@1", (caller) => ({
33
+ tool(tool, opts) {
34
+ if (typeof tool?.name !== "string" || typeof tool.execute !== "function")
35
+ throw new Error("task.tool: a tool needs a name and execute");
36
+ if (tool.effect !== "read")
37
+ throw new Error(`task.tool: ${tool.name} is not read-only (effect ${JSON.stringify(tool.effect)}); sub-agents only get read-only tools`);
38
+ // 同一个插件重复登记是正常的:换会话时新会话先登记,旧会话随后撤销它的那份;取最后登记的
39
+ const taken = registry.find((r) => r.tool.name === tool.name && r.plugin !== caller.plugin);
40
+ if (taken)
41
+ throw new Error(`task.tool: ${tool.name} is already registered by ${taken.plugin}`);
42
+ if (opts?.when !== undefined && typeof opts.when !== "function")
43
+ throw new Error("task.tool: when must be a function");
44
+ const entry = { tool, plugin: caller.plugin, ...(opts?.when ? { when: opts.when } : {}) };
45
+ registry.push(entry);
46
+ const revoke = () => {
47
+ const i = registry.indexOf(entry);
48
+ if (i !== -1)
49
+ registry.splice(i, 1);
50
+ };
51
+ caller.onDispose(revoke);
52
+ return revoke;
53
+ },
54
+ }));
55
+ const renderers = ctx.service("renderers@1");
56
+ if (renderers) {
57
+ // 运行中每个只有一行进度(标签、调用过几个工具、正在做什么),并行的几个靠标签分清;结束时把它调用过的工具放进结果的折叠内容里
58
+ const labels = new Map();
59
+ const steps = new Map();
60
+ const line = (id, what) => {
61
+ const n = steps.get(id)?.length ?? 0;
62
+ return dim(` ↳ ${labels.get(id) ?? "sub-agent"}${n ? ` (${n} tool call${n > 1 ? "s" : ""})` : ""} · ${what}`);
63
+ };
64
+ renderers.tool({
65
+ tool: "task",
66
+ summary: (input) => String(input?.description ?? ""),
67
+ progress(update, { toolUseId: id, summary }) {
68
+ const p = update;
69
+ if (p?.kind === "task-start") {
70
+ labels.set(id, p.description);
71
+ return line(id, "starting");
72
+ }
73
+ if (p?.kind === "task-model")
74
+ return line(id, "thinking");
75
+ if (p?.kind === "task-tool") {
76
+ const step = `${p.decision === "deny" ? "✗" : "·"} ${p.name}(${summary(p.name, p.input)})`;
77
+ steps.set(id, [...(steps.get(id) ?? []), step]);
78
+ return line(id, step);
79
+ }
80
+ return undefined;
81
+ },
82
+ result({ toolUseId: id, text, isError }) {
83
+ const sub = steps.get(id) ?? [];
84
+ steps.delete(id);
85
+ labels.delete(id);
86
+ // 没调用过工具时用默认的显示
87
+ if (!sub.length)
88
+ return undefined;
89
+ const lines = text.split("\n");
90
+ const shown = lines.slice(0, MAX_DETAIL_LINES).map((l) => (isError ? red(l) : l));
91
+ if (lines.length > MAX_DETAIL_LINES)
92
+ shown.push(dim(`… (${lines.length - MAX_DETAIL_LINES} more lines)`));
93
+ return {
94
+ line: isError ? red(clip(lines[0] ?? "", 200)) : dim(`${clip(lines[0] ?? "", 160)}${lines.length > 1 ? ` (+${lines.length - 1} lines)` : ""}`),
95
+ details: [dim(`sub-agent ran ${sub.length} tool call${sub.length > 1 ? "s" : ""}:`), ...sub.map((l) => dim(` ${l}`)), ...shown].join("\n"),
96
+ };
97
+ },
98
+ });
99
+ }
100
+ },
101
+ session(ctx) {
102
+ const models = ctx.require("models@1");
103
+ /** 跑完、还没记进日志的子 Agent 用量,按 task 调用的 toolUseId */
104
+ const usage = new Map();
105
+ const configured = ctx.config.maxSteps;
106
+ const maxSteps = typeof configured === "number" && Number.isInteger(configured) && configured > 0 ? configured : DEFAULT_MAX_STEPS;
107
+ const approve = (call, signal) => {
108
+ const ui = ctx.service("ui@1");
109
+ if (!ui?.interactive)
110
+ return Promise.resolve({ approved: false, reason: "Nobody can approve this action for a sub-agent. Report what you need instead." });
111
+ const ask = asking.then(async () => {
112
+ const choice = await ui.select({
113
+ title: `A sub-agent wants to ${call.why}. Allow it?`,
114
+ detail: `${call.name} ${clip(JSON.stringify(call.input), 2000)}`,
115
+ options: [
116
+ { label: "Yes", value: "yes" },
117
+ { label: "No", value: "no" },
118
+ ],
119
+ }, signal);
120
+ return choice === "yes" ? { approved: true } : { approved: false, reason: "The user denied this action." };
121
+ });
122
+ asking = ask.catch(() => { });
123
+ return ask;
124
+ };
125
+ ctx.kernel.tool(taskTool({
126
+ cwd: ctx.cwd,
127
+ provider: { id: ctx.plugin, complete: (req, o) => models.complete(req, o) },
128
+ tools: available,
129
+ maxSteps,
130
+ approve,
131
+ allowed: (call) => ctx.service("approval@1")?.allows(ctx.session.id, call) ?? false,
132
+ id: ctx.plugin,
133
+ usage: (toolUseId, u) => void usage.set(toolUseId, u),
134
+ contextWindow: () => models.current()?.contextWindow,
135
+ }));
136
+ // 子 Agent 的用量记成本插件的事件(和压缩、审查的用量一样),界面据此计入会话用量;只能在 hook 里记
137
+ ctx.kernel.hook({
138
+ kind: "transform",
139
+ point: "tool.after",
140
+ fn: async (outcome, hook) => {
141
+ const u = usage.get(outcome.call.toolUseId);
142
+ if (!u)
143
+ return undefined;
144
+ usage.delete(outcome.call.toolUseId);
145
+ await hook.emit("subagent", { toolUseId: outcome.call.toolUseId, usage: u });
146
+ return undefined;
147
+ },
148
+ });
149
+ // 被中断的调用不经过 tool.after,一轮结束时还留着的不会再用到
150
+ ctx.kernel.hook({ kind: "observe", point: "event", fn: (e) => void (e.type === "turn.ended" && usage.clear()) });
151
+ },
152
+ });