@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
@@ -146,37 +146,10 @@ function sleep(ms, signal) {
146
146
  }
147
147
  export const PROVIDER_KINDS = ["openai-compat", "openai", "anthropic"];
148
148
  export const isBuiltinKind = (kind) => PROVIDER_KINDS.includes(kind);
149
- export const SETTING_ENV = /^[A-Z][A-Z0-9_]*$/;
150
- export const PROVIDER_KIND = /^[a-z0-9][a-z0-9_-]*$/i;
151
- /** 插件注册的服务;只在启动时注册一次,整个进程共用 */
152
- const plugged = new Map();
153
- /** 注册插件提供的服务;返回要告诉用户的问题(名字不合法、和内置的或先注册的重名) */
154
- export function registerProviders(list) {
155
- const warnings = [];
156
- for (const { plugin, def } of list) {
157
- const kind = def.kind;
158
- const taken = plugged.get(kind);
159
- if (isBuiltinKind(kind))
160
- warnings.push(`plugin ${plugin}: provider ${kind} is ignored: it is a built-in provider`);
161
- else if (taken)
162
- warnings.push(`plugin ${plugin}: provider ${kind} is ignored: plugin ${taken.plugin} already provides it`);
163
- else
164
- plugged.set(kind, { plugin, def });
165
- }
166
- return warnings;
167
- }
168
- /** JADE_PROVIDER 选的服务由哪个插件提供;内置的或没有插件提供时 undefined */
169
- export function pluginProvider(kind) {
170
- return plugged.get(kind);
171
- }
172
- /** 注册了的插件服务,按注册顺序 */
173
- export function pluginProviders() {
174
- return [...plugged.values()];
175
- }
176
- /** 测试用 */
177
- export function clearProviders() {
178
- plugged.clear();
179
- }
149
+ /** 每种内置服务的模型名、密钥、地址各放在哪个环境变量里 */
150
+ export const MODEL_KEY = { "openai-compat": "OPENAI_COMPAT_MODEL", openai: "OPENAI_MODEL", anthropic: "ANTHROPIC_MODEL" };
151
+ export const KEY_KEY = { "openai-compat": "OPENAI_COMPAT_API_KEY", openai: "OPENAI_API_KEY", anthropic: "ANTHROPIC_API_KEY" };
152
+ export const URL_KEY = { "openai-compat": "OPENAI_COMPAT_BASE_URL", openai: "OPENAI_BASE_URL", anthropic: "ANTHROPIC_BASE_URL" };
180
153
  /** JADE_EFFORT 可取的值;openai-compat 没有统一的字段,用 OPENAI_COMPAT_EXTRA_BODY 自己设 */
181
154
  export const EFFORTS = {
182
155
  anthropic: ["low", "medium", "high", "xhigh", "max"],
@@ -212,7 +185,6 @@ export function idleTimeoutFromEnv(env = process.env) {
212
185
  */
213
186
  export function visionFromEnv(env = process.env) {
214
187
  const text = env.JADE_VISION?.trim().toLowerCase();
215
- // 插件的服务也算不能看:不知道它的模型支不支持
216
188
  if (!text)
217
189
  return providerKind(env) === "openai" || providerKind(env) === "anthropic";
218
190
  if (["1", "true", "on", "yes"].includes(text))
@@ -227,7 +199,6 @@ export function effortFromEnv(env = process.env) {
227
199
  if (!effort)
228
200
  return undefined;
229
201
  const kind = providerKind(env);
230
- // 插件的服务自己从 env 里读、自己检查
231
202
  if (!isBuiltinKind(kind))
232
203
  return effort;
233
204
  const allowed = EFFORTS[kind];
@@ -237,11 +208,7 @@ export function effortFromEnv(env = process.env) {
237
208
  throw new Error(`JADE_EFFORT must be one of ${allowed.join(", ")} for the ${kind} provider, got ${JSON.stringify(effort)}`);
238
209
  return effort;
239
210
  }
240
- /** JADE_PROVIDER 指定时用它;否则按 OPENAI_API_KEY、OPENAI_COMPAT_BASE_URL、ANTHROPIC_API_KEY 的顺序 */
241
- /**
242
- * 当前配置的服务:内置的三种之一,或者 JADE_PROVIDER 写的插件服务的名字。
243
- * 写了没有插件提供的名字时也原样返回(插件可能还没加载),创建 provider 时才报错
244
- */
211
+ /** JADE_PROVIDER 指定时用它;否则按 OPENAI_API_KEY、OPENAI_COMPAT_BASE_URL、ANTHROPIC_API_KEY 的顺序。不认识的名字原样返回,创建时报错 */
245
212
  export function providerKind(env = process.env) {
246
213
  const named = env.JADE_PROVIDER;
247
214
  if (named)
@@ -259,18 +226,7 @@ export function providerInfo(env = process.env) {
259
226
  return { kind, model: env.OPENAI_MODEL ?? "gpt-5", baseURL: env.OPENAI_BASE_URL ?? "https://api.openai.com/v1" };
260
227
  if (kind === "openai-compat")
261
228
  return { kind, model: env.OPENAI_COMPAT_MODEL ?? "", baseURL: env.OPENAI_COMPAT_BASE_URL };
262
- if (kind === "anthropic")
263
- return { kind, model: env.ANTHROPIC_MODEL ?? "claude-opus-5-5", baseURL: env.ANTHROPIC_BASE_URL };
264
- return { kind, model: pluginModel(kind, env) };
265
- }
266
- /** 插件服务的模型名;插件还没注册或出错时为空 */
267
- function pluginModel(kind, env) {
268
- try {
269
- return String(plugged.get(kind)?.def.model(env) ?? "");
270
- }
271
- catch {
272
- return "";
273
- }
229
+ return { kind, model: env.ANTHROPIC_MODEL ?? "claude-opus-5-5", baseURL: env.ANTHROPIC_BASE_URL };
274
230
  }
275
231
  /**
276
232
  * 按环境变量创建,服务由 providerKind 决定:
@@ -287,21 +243,8 @@ function pluginModel(kind, env) {
287
243
  */
288
244
  export async function providerFromEnv(env = process.env) {
289
245
  const kind = providerKind(env);
290
- if (!isBuiltinKind(kind)) {
291
- const found = plugged.get(kind);
292
- if (!found) {
293
- const all = [...PROVIDER_KINDS, ...plugged.keys()];
294
- throw new Error(`JADE_PROVIDER must be one of ${all.join(", ")}, got ${JSON.stringify(kind)} (no plugin provides it)`);
295
- }
296
- // 限速、空闲超时这些 jade 自己的设置写错时同样在这里报错。空闲超时只对 OpenAI 和 OpenAI 兼容服务生效(见 README),
297
- // 插件的服务要用的话自己从 env 读
298
- rpmFromEnv(env);
299
- idleTimeoutFromEnv(env);
300
- const made = await found.def.create(env);
301
- if (!made || typeof made.complete !== "function")
302
- throw new Error(`plugin ${found.plugin}: provider ${kind} must return an object with a complete function`);
303
- return made;
304
- }
246
+ if (!isBuiltinKind(kind))
247
+ throw new Error(`JADE_PROVIDER must be one of ${PROVIDER_KINDS.join(", ")}, got ${JSON.stringify(kind)}`);
305
248
  const maxTokens = env.JADE_MAX_TOKENS ? parseTokens("JADE_MAX_TOKENS", env.JADE_MAX_TOKENS) : undefined;
306
249
  const effort = effortFromEnv(env);
307
250
  // 写错时在这里就报错,不等到第一次请求
@@ -341,25 +284,20 @@ export async function providerFromEnv(env = process.env) {
341
284
  });
342
285
  }
343
286
  const { anthropicProvider } = await import("@uncarved/provider-anthropic");
344
- return anthropicProvider({ model: env.ANTHROPIC_MODEL, effort: (effort ?? "high"), maxTokens });
345
- }
346
- export function switchable(initial) {
347
- let current = initial;
348
- return {
349
- id: "switchable",
350
- set: (next) => {
351
- current = next;
352
- },
353
- complete: (request, options) => current.complete(request, options),
354
- };
287
+ // 地址和密钥从 env 取,不让 SDK 自己读 process.env:ctx.complete 指定的保存过的模型,env 不是 process.env
288
+ return anthropicProvider({
289
+ apiKey: env.ANTHROPIC_API_KEY,
290
+ baseURL: env.ANTHROPIC_BASE_URL ?? "https://api.anthropic.com",
291
+ model: env.ANTHROPIC_MODEL,
292
+ effort: (effort ?? "high"),
293
+ maxTokens,
294
+ });
355
295
  }
356
296
  /** 服务提供的模型列表;不支持或出错时返回空数组 */
357
297
  export async function listModels(env = process.env, fetchImpl = fetch) {
358
298
  const kind = providerKind(env);
359
- if (!isBuiltinKind(kind)) {
360
- const list = plugged.get(kind)?.def.listModels;
361
- return list ? list(env).then((m) => (Array.isArray(m) ? m.filter((x) => typeof x === "string") : []), () => []) : [];
362
- }
299
+ if (!isBuiltinKind(kind))
300
+ return [];
363
301
  const info = providerInfo(env);
364
302
  const base = (info.baseURL ?? "https://api.anthropic.com").replace(/\/$/, "");
365
303
  const headers = kind === "anthropic"
@@ -393,4 +331,3 @@ function jsonObject(name, text) {
393
331
  throw new Error(`${name} must be a JSON object, got ${text}`);
394
332
  return value;
395
333
  }
396
- //# sourceMappingURL=provider.js.map
@@ -0,0 +1,80 @@
1
+ // 保存过的模型:$JADE_HOME/models.json。同一个服务(类型、地址、密钥都相同)只存一份,下面是在它上面用过的模型,
2
+ // 每个模型带自己的设置(输出上限、思考力度、上下文窗口)。.env 里始终是当前用的那一个,这里记着用过的全部,
3
+ // /model 可以切回去。
4
+ import { mkdir, readFile, writeFile } from "node:fs/promises";
5
+ import path from "node:path";
6
+ /** 每个模型自己的设置:切换模型时一起换掉 */
7
+ export const MODEL_SETTINGS = ["JADE_MAX_TOKENS", "JADE_EFFORT", "JADE_CONTEXT_WINDOW", "JADE_RPM", "JADE_VISION"];
8
+ const strings = (v) => typeof v === "object" && v !== null ? Object.fromEntries(Object.entries(v).filter(([, x]) => typeof x === "string")) : {};
9
+ /** 读不了或格式不对时返回空数组 */
10
+ export async function readSavedServices(file) {
11
+ try {
12
+ const data = JSON.parse(await readFile(file, "utf8"));
13
+ if (!Array.isArray(data.services))
14
+ return [];
15
+ return data.services.flatMap((raw) => {
16
+ const s = raw;
17
+ if (!s || !Array.isArray(s.models))
18
+ return [];
19
+ const models = s.models.flatMap((m) => {
20
+ const name = m?.name;
21
+ return typeof name === "string" && name ? [{ name, settings: strings(m.settings) }] : [];
22
+ });
23
+ return models.length ? [{ env: strings(s.env), models }] : [];
24
+ });
25
+ }
26
+ catch {
27
+ return [];
28
+ }
29
+ }
30
+ export async function writeSavedServices(file, services) {
31
+ await mkdir(path.dirname(file), { recursive: true });
32
+ // 里面有 API 密钥
33
+ await writeFile(file, JSON.stringify({ services }, null, 2) + "\n", { mode: 0o600 });
34
+ }
35
+ /**
36
+ * 改写配置文件里的变量:已有的行原地替换,没有的追加在末尾,值为 undefined 的删除;注释和其他行保持不变。
37
+ * 同时更新 env,让改动在本次运行中生效
38
+ */
39
+ export async function updateEnvFile(file, updates, env) {
40
+ let text = "";
41
+ try {
42
+ text = await readFile(file, "utf8");
43
+ }
44
+ catch {
45
+ // 还没有配置文件
46
+ }
47
+ const lines = text ? text.replace(/\r?\n$/, "").split(/\r?\n/) : [];
48
+ const out = [];
49
+ const written = new Set();
50
+ for (const raw of lines) {
51
+ const key = /^\s*(?:export\s+)?([A-Za-z_][A-Za-z0-9_]*)\s*=/.exec(raw)?.[1];
52
+ if (!key || !(key in updates)) {
53
+ out.push(raw);
54
+ continue;
55
+ }
56
+ // 同一个键出现多次时只保留第一处
57
+ const value = updates[key];
58
+ if (value !== undefined && !written.has(key))
59
+ out.push(format(key, value));
60
+ written.add(key);
61
+ }
62
+ for (const [key, value] of Object.entries(updates)) {
63
+ if (value !== undefined && !written.has(key))
64
+ out.push(format(key, value));
65
+ }
66
+ await mkdir(path.dirname(file), { recursive: true });
67
+ await writeFile(file, out.join("\n") + "\n");
68
+ for (const [key, value] of Object.entries(updates)) {
69
+ if (value === undefined)
70
+ delete env[key];
71
+ else
72
+ env[key] = value;
73
+ }
74
+ }
75
+ function format(key, value) {
76
+ if (!/[\s#"']/.test(value))
77
+ return `${key}=${value}`;
78
+ // 单引号里的内容原样读回(引号、反斜杠都不转义);只有换行要用双引号里的 \n
79
+ return value.includes("\n") ? `${key}="${value.replaceAll("\n", "\\n")}"` : `${key}='${value}'`;
80
+ }
@@ -0,0 +1,190 @@
1
+ // jade/modes:权限模式的切换。模式本身归 jade/approval(approval@1),这里提供切换方式和给前端显示的状态:
2
+ // Shift+Tab 在 ask → auto → plan 之间轮换,/mode 查看或选择,modes@1 让前端显示当前模式、在模式变化时更新。
3
+ //
4
+ // 计划模式的两件事也在这里:
5
+ // - 在 plan 模式时经 prompts@1 往系统提示词里加一段,告诉模型先给计划、不要改东西(切出去时去掉)
6
+ // - propose_plan 工具:模型写好要执行的计划后调用它,问用户要不要执行;批准了就换模式,工具结果告诉模型开始做。
7
+ // 由模型声明"这是要执行的计划",追问、回答问题、只要计划本身(比如健身计划)的回复不会被当成计划去问。
8
+ // 用户的选择在工具结果里,会话日志里看得到
9
+ import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
10
+ import path from "node:path";
11
+ import { definePlugin } from "../../dist/api.js";
12
+ export const DESCRIPTIONS = {
13
+ ask: "ask before edits and commands",
14
+ auto: "edits in this directory and harmless commands run without asking; others still ask",
15
+ plan: "change nothing: research read-only and propose a plan",
16
+ readonly: "change nothing",
17
+ yolo: "never ask",
18
+ };
19
+ const CYCLE = ["ask", "auto", "plan"];
20
+ /** 计划模式时加进系统提示词的段落;不能问用户(-p、非终端)时没有 propose_plan,只让模型给出计划后停下 */
21
+ export function planNote(canPropose) {
22
+ return ("The session is in plan mode. Investigate with read-only tools (and the task tool for broad searches); do not try to modify files " +
23
+ "or run commands that change anything, such calls are denied. If the request is unclear in a way that changes the plan, ask the user first. " +
24
+ "When the task needs changes made (files edited, commands run), reply with a concise, concrete plan: the steps in order (for code, the files to change and how), " +
25
+ "any open questions, and how you will verify the result. " +
26
+ (canPropose
27
+ ? "Then call propose_plan so the user can approve it. If nothing needs to be executed (a question, or the plan itself is the answer the user wants), " +
28
+ "just answer and do not call propose_plan."
29
+ : "Then stop and wait for the user's approval."));
30
+ }
31
+ /** 批准计划之后工具结果里的那句 */
32
+ export const APPROVED_NOTE = "The user approved the plan. Implement it now.";
33
+ /** 没批准时工具结果里的那句 */
34
+ export const NOT_APPROVED = "The user did not approve the plan yet. End your turn and wait for their feedback.";
35
+ export const PROPOSE_PLAN = "propose_plan";
36
+ /** propose_plan:问用户要不要执行刚写好的计划,批准了就换到用户选的模式 */
37
+ export function proposePlanTool(approval, ui) {
38
+ return {
39
+ name: PROPOSE_PLAN,
40
+ description: "In plan mode, ask the user to approve the plan you just wrote in your reply, and wait for the answer. Write the full plan in your reply text first; " +
41
+ "call this only for a plan of changes to execute, not for questions, clarifications or answers that need nothing executed.",
42
+ inputSchema: { type: "object", properties: {}, additionalProperties: false },
43
+ // 不碰文件和进程:plan 模式下不用批准
44
+ effect: "read",
45
+ concurrency: "exclusive",
46
+ idempotent: false,
47
+ async execute(_input, ctx) {
48
+ if (approval.mode() !== "plan")
49
+ return { content: "The session is not in plan mode; no approval is needed.", isError: true };
50
+ const choice = await ui.select({
51
+ title: "Execute this plan?",
52
+ options: [
53
+ { label: "Yes, in auto mode", value: "auto", hint: "edits and safe commands run without asking" },
54
+ { label: "Yes, and ask before each edit", value: "ask", hint: "mode ask" },
55
+ { label: "No, keep planning", value: "plan", hint: "type what to change" },
56
+ ],
57
+ }, ctx.signal);
58
+ ctx.signal.throwIfAborted();
59
+ if (choice !== "auto" && choice !== "ask")
60
+ return { content: NOT_APPROVED };
61
+ setMode(approval, choice);
62
+ return { content: `${APPROVED_NOTE} (mode: ${choice})` };
63
+ },
64
+ };
65
+ }
66
+ /** 模式变化时通知前端和会话里的订阅者(模块每个进程只加载一次,进程级和会话级共用) */
67
+ const listeners = new Set();
68
+ /**
69
+ * 用户选的模式记在 $JADE_HOME/mode.json,下次启动接着用(比配置里的 mode 优先)。
70
+ * plan 是一次任务里的,yolo 不该悄悄带到下一次启动:这两个不记
71
+ */
72
+ const REMEMBERED = new Set(["ask", "auto", "readonly"]);
73
+ let modeFile;
74
+ /** 记下的模式只在第一个可交互的会话里恢复一次:jade -p 这类不能问用户的运行一直用配置的模式 */
75
+ let restored = false;
76
+ function readRemembered(file) {
77
+ try {
78
+ const mode = JSON.parse(readFileSync(file, "utf8")).mode;
79
+ return typeof mode === "string" && REMEMBERED.has(mode) ? mode : undefined;
80
+ }
81
+ catch {
82
+ return undefined;
83
+ }
84
+ }
85
+ function remember(mode) {
86
+ if (!modeFile || !REMEMBERED.has(mode))
87
+ return;
88
+ try {
89
+ // 同步写:连按几次 Shift+Tab 时,文件里留下的一定是最后一次
90
+ mkdirSync(path.dirname(modeFile), { recursive: true });
91
+ writeFileSync(modeFile, `${JSON.stringify({ mode })}\n`);
92
+ }
93
+ catch {
94
+ // 记不下只是下次从配置的模式开始
95
+ }
96
+ }
97
+ function setMode(approval, mode) {
98
+ if (mode === approval.mode())
99
+ return;
100
+ approval.setMode(mode);
101
+ remember(mode);
102
+ for (const fn of [...listeners]) {
103
+ try {
104
+ fn(mode);
105
+ }
106
+ catch {
107
+ // 订阅者的错误经过膜归它自己,不影响别的订阅者
108
+ }
109
+ }
110
+ }
111
+ export default definePlugin({
112
+ process(ctx) {
113
+ const approval = ctx.require("approval@1");
114
+ modeFile = path.join(ctx.home, "mode.json");
115
+ restored = false;
116
+ const set = (mode) => setMode(approval, mode);
117
+ const cycle = () => {
118
+ const next = CYCLE[(CYCLE.indexOf(approval.mode()) + 1) % CYCLE.length];
119
+ set(next);
120
+ return next;
121
+ };
122
+ const list = () => Object.entries(DESCRIPTIONS).map(([name, description]) => ({ name, description }));
123
+ ctx.provide("modes@1", (caller) => ({
124
+ current: () => approval.mode(),
125
+ list,
126
+ set,
127
+ cycle,
128
+ subscribe(fn) {
129
+ listeners.add(fn);
130
+ const off = () => void listeners.delete(fn);
131
+ caller.onDispose(off);
132
+ return off;
133
+ },
134
+ }));
135
+ ctx.service("keys@1")?.register({ key: "shift+tab", description: "cycle ask/auto/plan", run: () => void cycle() });
136
+ ctx.service("commands@1")?.register({
137
+ name: "mode",
138
+ args: `[${Object.keys(DESCRIPTIONS).join("|")}]`,
139
+ description: "show or change the permission mode",
140
+ instant: true,
141
+ async run(args, c) {
142
+ let want = args.trim() || undefined;
143
+ if (!want) {
144
+ want = await c.ui.select({ title: "Permission mode", options: list().map((m) => ({ label: m.name, value: m.name, hint: m.name === approval.mode() ? "current" : m.description })) }, c.signal);
145
+ if (!want)
146
+ return;
147
+ }
148
+ if (!(want in DESCRIPTIONS))
149
+ return `unknown mode ${want}; one of ${Object.keys(DESCRIPTIONS).join(", ")}`;
150
+ set(want);
151
+ return `mode: ${approval.mode()}`;
152
+ },
153
+ });
154
+ },
155
+ session(ctx) {
156
+ const approval = ctx.require("approval@1");
157
+ const prompts = ctx.service("prompts@1");
158
+ const ui = ctx.service("ui@1");
159
+ if (!restored && ui?.interactive && modeFile) {
160
+ restored = true;
161
+ const saved = readRemembered(modeFile);
162
+ if (saved)
163
+ setMode(approval, saved);
164
+ }
165
+ // 能问用户时才有 propose_plan;它只在 plan 模式下发给模型
166
+ const canPropose = !!ui?.interactive;
167
+ if (canPropose)
168
+ ctx.kernel.tool(proposePlanTool(approval, ui));
169
+ ctx.kernel.hook({
170
+ kind: "transform",
171
+ point: "context.build",
172
+ fn: (req) => (approval.mode() === "plan" ? req : { ...req, tools: req.tools.filter((t) => t.name !== PROPOSE_PLAN) }),
173
+ });
174
+ // 计划模式的说明跟着模式进出系统提示词
175
+ let note;
176
+ const sync = () => {
177
+ const plan = approval.mode() === "plan";
178
+ if (plan && !note && prompts)
179
+ note = prompts.add({ text: planNote(canPropose), stable: false });
180
+ else if (!plan && note) {
181
+ note();
182
+ note = undefined;
183
+ }
184
+ };
185
+ sync();
186
+ const onChange = () => sync();
187
+ listeners.add(onChange);
188
+ ctx.effect(() => () => void listeners.delete(onChange));
189
+ },
190
+ });
@@ -0,0 +1,18 @@
1
+ {
2
+ "id": "jade/modes",
3
+ "version": "0.2.0",
4
+ "api": "^1",
5
+ "entry": "./index.js",
6
+ "provides": [
7
+ "modes@1"
8
+ ],
9
+ "requires": [
10
+ "approval@1"
11
+ ],
12
+ "optional": [
13
+ "keys@1",
14
+ "commands@1",
15
+ "prompts@1",
16
+ "ui@1"
17
+ ]
18
+ }
@@ -0,0 +1,37 @@
1
+ // jade/plugins:/plugins 命令。列出这次启动里每个插件的状态和原因(failed、skipped、conflicted……),
2
+ // 以及每个服务由谁提供。数据来自核心自己的 jade@1 服务,和救援 CLI `jade plugins list` 是同一份状态。
3
+ import { definePlugin } from "../../dist/api.js";
4
+ export default definePlugin({
5
+ process(ctx) {
6
+ const commands = ctx.require("commands@1");
7
+ const jade = ctx.require("jade@1");
8
+ commands.register({
9
+ name: "plugins",
10
+ args: "[id]",
11
+ description: "every plugin's state and why it is not active, and who provides each service",
12
+ // 只读,不碰会话
13
+ instant: true,
14
+ run(args) {
15
+ const all = jade.plugins();
16
+ const query = args.trim();
17
+ if (query) {
18
+ const found = all.filter((p) => p.id === query || p.id?.endsWith(`/${query}`) || p.dir === query);
19
+ if (found.length === 0)
20
+ return `No plugin matches ${query}. /plugins lists them all.`;
21
+ const lines = found.map((p) => `${p.id ?? p.dir}@${p.version ?? "?"} ${p.layer} ${p.state}${p.reason ? ` ${p.reason}` : ""}\n ${p.dir}`);
22
+ for (const s of jade.services().filter((s) => found.some((p) => p.id === s.provider)))
23
+ lines.push(` provides ${s.service}`);
24
+ return lines.join("\n");
25
+ }
26
+ const lines = all.map((p) => `${p.id ?? p.dir}@${p.version ?? "?"} ${p.layer} ${p.state}${p.reason ? ` ${p.reason}` : ""}`);
27
+ const broken = all.filter((p) => p.state !== "active");
28
+ if (broken.length > 0)
29
+ lines.push("", `${broken.length} of ${all.length} plugins are not active; /plugins <id> shows where one lives.`);
30
+ const services = jade.services();
31
+ if (services.length > 0)
32
+ lines.push("", "services:", ...services.map((s) => ` ${s.service} ${s.provider}`));
33
+ return lines.join("\n");
34
+ },
35
+ });
36
+ },
37
+ });
@@ -0,0 +1,10 @@
1
+ {
2
+ "id": "jade/plugins",
3
+ "version": "0.1.0",
4
+ "api": "^1",
5
+ "entry": "./index.js",
6
+ "requires": [
7
+ "commands@1",
8
+ "jade@1"
9
+ ]
10
+ }
@@ -0,0 +1,172 @@
1
+ // jade/print:jade -p "<prompt>" 跑一轮就退出。模型的回复写到 stdout,工具调用和提示写到 stderr。
2
+ // 不能向用户提问:ui@1 的 select 总是返回 undefined,要审批的调用由审批插件拒绝。
3
+ import { definePlugin } from "../../dist/api.js";
4
+ const USAGE = `usage: jade -p <prompt> [--resume <session id>]
5
+ echo <prompt> | jade -p
6
+ cat <file> | jade -p - <prompt>
7
+
8
+ With "-", what comes in on stdin is added after the prompt (without a prompt, stdin is the prompt).
9
+
10
+ Runs one prompt and exits. The reply goes to stdout; tool calls and notices go to stderr.
11
+ Exit code: 0 when the turn ends normally, 1 on an error, 130 when interrupted.
12
+ jade's own commands (plugins, update, --safe): jade help`;
13
+ const ui = {
14
+ interactive: false,
15
+ notify(message, level = "info") {
16
+ process.stderr.write(`${level === "info" ? "" : `[${level}] `}${message}\n`);
17
+ },
18
+ select: async () => undefined,
19
+ input: async () => undefined,
20
+ };
21
+ const frontend = {
22
+ async run({ argv, sessions }) {
23
+ const args = parse(argv);
24
+ if (typeof args === "string") {
25
+ process.stderr.write(`${args}\n\n${USAGE}\n`);
26
+ return 2;
27
+ }
28
+ if (args.help) {
29
+ process.stdout.write(`${USAGE}\n`);
30
+ return 0;
31
+ }
32
+ // 有 prompt 参数时只在写了 "-" 时读 stdin:脚本启动 jade -p 时 stdin 常是没人关的管道,默认去读会一直等下去
33
+ const piped = args.stdin || (args.prompt === undefined && !process.stdin.isTTY) ? (await readStdin()).trim() : "";
34
+ const prompt = [args.prompt, piped].filter(Boolean).join("\n\n");
35
+ if (!prompt) {
36
+ process.stderr.write(`no prompt given\n\n${USAGE}\n`);
37
+ return 2;
38
+ }
39
+ let session;
40
+ try {
41
+ session = await sessions.open(args.resume ? { resume: args.resume } : {});
42
+ }
43
+ catch (e) {
44
+ // 例如 --resume 的会话不存在:只说原因,不带插件名的包装
45
+ process.stderr.write(`jade: ${args.resume ? `could not resume ${args.resume}` : "could not start a session"}: ${errorText(e)}\n`);
46
+ return args.resume ? 2 : 1;
47
+ }
48
+ let ended;
49
+ let midLine = false;
50
+ const out = (text) => {
51
+ process.stdout.write(text);
52
+ midLine = !text.endsWith("\n");
53
+ };
54
+ /** 这次模型调用推送过文字增量;没推送的(不流式的服务),回复到了再一次写出 */
55
+ let streamed = false;
56
+ const unsubscribe = session.subscribe((n) => {
57
+ if (n.type === "delta" && n.delta.kind === "text") {
58
+ streamed = true;
59
+ out(n.delta.text);
60
+ }
61
+ if (n.type !== "event")
62
+ return;
63
+ const e = n.event;
64
+ if (e.type === "model.responded") {
65
+ const content = e.data.content;
66
+ if (!streamed)
67
+ for (const b of content)
68
+ if (b.kind === "text")
69
+ out(b.text);
70
+ streamed = false;
71
+ if (midLine)
72
+ out("\n");
73
+ for (const b of content)
74
+ if (b.kind === "tool_use")
75
+ process.stderr.write(`· ${b.name} ${summary(b.input)}\n`);
76
+ }
77
+ if (e.type === "tool.decided") {
78
+ const d = e.data;
79
+ if (d.decision === "deny")
80
+ process.stderr.write(` denied${d.reason ? `: ${d.reason}` : ""}\n`);
81
+ }
82
+ if (e.type === "tool.completed") {
83
+ const d = e.data;
84
+ if (d.isError)
85
+ process.stderr.write(` failed: ${firstLine(d.content)}\n`);
86
+ }
87
+ if (e.type === "turn.ended")
88
+ ended = e.data;
89
+ });
90
+ const interrupt = () => session.abort(new Error("interrupted"));
91
+ process.once("SIGINT", interrupt);
92
+ let failure;
93
+ try {
94
+ if (args.resume)
95
+ await session.recover();
96
+ await session.send({ kind: "message", content: [{ kind: "text", text: prompt, origin: { by: "user" }, trust: "trusted" }] });
97
+ await session.idle();
98
+ }
99
+ catch (e) {
100
+ failure = e;
101
+ }
102
+ finally {
103
+ process.off("SIGINT", interrupt);
104
+ unsubscribe();
105
+ }
106
+ if (midLine)
107
+ out("\n");
108
+ process.stderr.write(`session ${session.id}\n`);
109
+ const end = ended;
110
+ if (end?.reason === "aborted")
111
+ return 130;
112
+ if (failure !== undefined || end?.reason === "error") {
113
+ process.stderr.write(`error: ${failure !== undefined ? errorText(failure) : (end?.error ?? "the turn failed")}\n`);
114
+ return 1;
115
+ }
116
+ return 0;
117
+ },
118
+ };
119
+ export default definePlugin({
120
+ process(ctx) {
121
+ ctx.provide("ui@1", ui);
122
+ ctx.provide("frontend@1", frontend);
123
+ },
124
+ });
125
+ function parse(argv) {
126
+ const out = {};
127
+ const words = [];
128
+ for (let i = 0; i < argv.length; i++) {
129
+ const a = argv[i];
130
+ if (a === "-p" || a === "--print")
131
+ continue;
132
+ if (a === "-h" || a === "--help")
133
+ out.help = true;
134
+ else if (a === "-")
135
+ out.stdin = true;
136
+ else if (a === "--resume") {
137
+ const id = argv[++i];
138
+ if (!id)
139
+ return "--resume needs a session id";
140
+ out.resume = id;
141
+ }
142
+ else if (a.startsWith("-"))
143
+ return `unknown option ${a}`;
144
+ else
145
+ words.push(a);
146
+ }
147
+ if (words.length > 0)
148
+ out.prompt = words.join(" ");
149
+ return out;
150
+ }
151
+ async function readStdin() {
152
+ const chunks = [];
153
+ for await (const c of process.stdin)
154
+ chunks.push(c);
155
+ return Buffer.concat(chunks).toString("utf8");
156
+ }
157
+ /** 工具参数的一行摘要:常见的 path、command、pattern,其余是截断的 JSON */
158
+ function summary(input) {
159
+ const i = input;
160
+ const s = typeof i?.command === "string" ? i.command : typeof i?.path === "string" ? i.path : typeof i?.pattern === "string" ? i.pattern : JSON.stringify(input);
161
+ const line = (s ?? "").split("\n")[0];
162
+ return line.length > 120 ? `${line.slice(0, 120)}…` : line;
163
+ }
164
+ /** 经过膜的错误包成了 PluginError,带着插件名;用户要看的是原因 */
165
+ function errorText(e) {
166
+ const cause = e instanceof Error && e.cause instanceof Error ? e.cause : e;
167
+ return cause instanceof Error ? cause.message : String(cause);
168
+ }
169
+ function firstLine(content) {
170
+ const text = content.find((b) => b.kind === "text");
171
+ return text && "text" in text ? text.text.split("\n")[0] : "(no message)";
172
+ }