@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,15 @@
1
+ {
2
+ "id": "jade/web",
3
+ "version": "0.3.0",
4
+ "api": "^1",
5
+ "entry": "./index.ts",
6
+ "optional": ["ui@1", "commands@1", "prompts@1", "renderers@1", "task@1"],
7
+ "config": {
8
+ "search": {
9
+ "description": "search services to use, in order: a list or comma-separated names (tinyfish, anysearch, tavily, exa, firecrawl, jina); default: every service with an API key. Keys are read from the environment and $JADE_HOME/.env (/search sets them). $JADE_SEARCH still works"
10
+ },
11
+ "results": {
12
+ "description": "results per web_search, 1-20, default 10; $JADE_SEARCH_RESULTS still works"
13
+ }
14
+ }
15
+ }
@@ -0,0 +1,11 @@
1
+ // web_fetch、web_search 在对话里怎么显示(登记到 renderers@1)。从旧 jade 的 ui/renderers.ts 移植。
2
+
3
+ import type { ToolRenderer } from "../renderers/index.ts";
4
+
5
+ const clip = (s: string, n: number) => (s.length > n ? s.slice(0, n) + "…" : s);
6
+ const args = (input: unknown) => (input !== null && typeof input === "object" ? input : {}) as Record<string, unknown>;
7
+
8
+ export const webRenderers: ToolRenderer[] = [
9
+ { tool: "web_fetch", summary: (input) => clip(String(args(input).url ?? ""), 120) },
10
+ { tool: "web_search", summary: (input) => clip(String(args(input).query ?? ""), 120) },
11
+ ];
@@ -8,12 +8,14 @@
8
8
  // web_fetch 拒绝 localhost 和内网地址:网页里的提示注入不能借它去访问本机的服务。
9
9
  // 主机名要先解析,解析出的地址也要检查,否则 127.0.0.1.nip.io 这类域名就能绕过。
10
10
  // 检查和 fetch 各自解析一次,DNS 重绑定仍有很小的窗口;要彻底杜绝需要按解析出的 IP 连接。
11
- // web_search 只在配置了搜索服务时提供,否则模型每次调用都会失败。
11
+ // web_search 只在配置了搜索服务时发给模型(见 index.ts),否则模型每次调用都会失败。
12
+ //
13
+ // 从旧 jade 的 tools/web.ts 移植。服务的 key 每次调用时取(search()),/search 改了 key 当前会话立即用上,不用重开会话。
12
14
 
13
15
  import { lookup as dnsLookup } from "node:dns/promises";
14
16
  import { isIP } from "node:net";
15
- import { Parser } from "htmlparser2";
16
17
  import type { Block, Tool } from "uncarved";
18
+ import type { Env } from "./env.ts";
17
19
 
18
20
  /** 一次返回的最多字符数,更长的用 offset 分页 */
19
21
  const MAX_CHARS = 30_000;
@@ -31,8 +33,12 @@ const MAX_RESULTS = 20;
31
33
  const USER_AGENT = "Mozilla/5.0 (compatible; jade/0.1; +https://github.com/MochiNek0/uncarved)";
32
34
 
33
35
  export interface WebOptions {
34
- /** 默认 process.env */
35
- env?: Record<string, string | undefined>;
36
+ /** API key 所在的环境,每次调用时取;默认 process.env */
37
+ env?: Env | (() => Env);
38
+ /** 用哪些搜索服务、按什么顺序(服务名);不给时用所有配了 key 的服务,按 SEARCH_PROVIDERS 的顺序 */
39
+ order?: string[];
40
+ /** 每次搜索返回的条数,默认 DEFAULT_RESULTS */
41
+ results?: number;
36
42
  /** 测试用 */
37
43
  fetch?: typeof fetch;
38
44
  /** 主机名解析出的地址;测试用 */
@@ -42,17 +48,19 @@ export interface WebOptions {
42
48
  const defaultLookup = async (hostname: string) => (await dnsLookup(hostname, { all: true })).map((a) => a.address);
43
49
 
44
50
  export interface WebTools {
45
- /** web_fetch,以及配置了搜索服务时的 web_search;JADE_SEARCH / JADE_SEARCH_RESULTS 不合法时抛错 */
51
+ /** web_fetch 和 web_search;没有配置搜索服务时 web_search 返回错误,不应发给模型 */
46
52
  tools: Tool[];
53
+ /** 当前配了 key 的搜索服务名,按调用顺序 */
54
+ search(): string[];
47
55
  }
48
56
 
49
57
  export function webTools(opts: WebOptions = {}): WebTools {
50
- const env = opts.env ?? process.env;
58
+ const env = typeof opts.env === "function" ? opts.env : () => (opts.env as Env | undefined) ?? process.env;
51
59
  const fetchImpl = opts.fetch ?? fetch;
52
- const services = backends(env, fetchImpl);
53
- const tools = [webFetchTool(fetchImpl, opts.lookup ?? defaultLookup, services.filter((s) => s.read))];
54
- if (services.length) tools.push(webSearchTool(services, resultCount(env)));
55
- return { tools };
60
+ if (opts.order) checkOrder(opts.order);
61
+ const services = () => backends(env(), opts.order, fetchImpl);
62
+ const tools = [webFetchTool(fetchImpl, opts.lookup ?? defaultLookup, () => services().filter((s) => s.read)), webSearchTool(services, opts.results ?? DEFAULT_RESULTS)];
63
+ return { tools, search: () => services().map((s) => s.name) };
56
64
  }
57
65
 
58
66
  // ---------- web_fetch ----------
@@ -78,7 +86,7 @@ const THIN_CHARS = 200;
78
86
  type Lookup = (hostname: string) => Promise<string[]>;
79
87
 
80
88
  /** readers:能读网页的搜索服务;直接下载不成功时按顺序试 */
81
- function webFetchTool(fetchImpl: typeof fetch, lookup: Lookup, readers: Backend[]): Tool {
89
+ function webFetchTool(fetchImpl: typeof fetch, lookup: Lookup, readers: () => Backend[]): Tool {
82
90
  const cache = new Map<string, Page>();
83
91
  return {
84
92
  name: "web_fetch",
@@ -124,7 +132,7 @@ function webFetchTool(fetchImpl: typeof fetch, lookup: Lookup, readers: Backend[
124
132
  // 直接下载被拦、出错或只拿到 JS 外壳时,交给能读网页的服务;404 这类明确的结果直接返回
125
133
  const failures: string[] = [];
126
134
  if ("content" in direct ? direct.retry : direct.thin) {
127
- for (const r of readers) {
135
+ for (const r of readers()) {
128
136
  try {
129
137
  page = { at: Date.now(), url: target.href, via: r.name, text: await r.read!(target.href, signal) };
130
138
  break;
@@ -220,7 +228,7 @@ async function download(fetchImpl: typeof fetch, lookup: Lookup, target: URL, si
220
228
  if (!res.ok) {
221
229
  const body = await res.text().catch(() => "");
222
230
  return {
223
- content: `HTTP ${res.status} ${res.statusText} from ${url.href}${body ? `\n${clip(htmlToMarkdown(body).text || body, 1000)}` : ""}`,
231
+ content: `HTTP ${res.status} ${res.statusText} from ${url.href}${body ? `\n${clip((await htmlToMarkdown(body)).text || body, 1000)}` : ""}`,
224
232
  isError: true,
225
233
  retry: res.status === 403 || res.status === 429 || res.status >= 500,
226
234
  };
@@ -241,7 +249,7 @@ async function download(fetchImpl: typeof fetch, lookup: Lookup, target: URL, si
241
249
  const charset = /charset=([^;]+)/i.exec(res.headers.get("content-type") ?? "")?.[1]?.trim();
242
250
  const raw = decode(buf, charset);
243
251
  if (type === "text/html" || type === "application/xhtml+xml" || (!type && /^\s*<(!doctype|html)/i.test(raw))) {
244
- const { title, text } = htmlToMarkdown(raw, url.href);
252
+ const { title, text } = await htmlToMarkdown(raw, url.href);
245
253
  return { at: Date.now(), url: url.href, title, text, thin: text.length < THIN_CHARS };
246
254
  }
247
255
  if (type.startsWith("text/") || /json|xml|javascript|yaml|toml/.test(type) || !type) {
@@ -294,9 +302,11 @@ const BLOCKS = new Set(["p", "div", "section", "article", "main", "header", "ul"
294
302
 
295
303
  /**
296
304
  * 用 htmlparser2 把网页转成 markdown 风格的文本:标题、段落、列表、链接、代码块,去掉脚本、样式和导航。
297
- * 不追求还原排版,只要模型能读。Node 和 Bun 都能用(Bun 的 HTMLRewriter 在 Node 里没有)
305
+ * 不追求还原排版,只要模型能读。Node 和 Bun 都能用(Bun 的 HTMLRewriter 在 Node 里没有)。
306
+ * htmlparser2 第一次用到时才加载:导入要几十毫秒,每次启动都付不值得
298
307
  */
299
- export function htmlToMarkdown(html: string, base?: string): { title?: string; text: string } {
308
+ export async function htmlToMarkdown(html: string, base?: string): Promise<{ title?: string; text: string }> {
309
+ const { Parser } = await import("htmlparser2");
300
310
  const out: string[] = [];
301
311
  let skip = 0;
302
312
  let pre = 0;
@@ -599,29 +609,51 @@ export const SEARCH_PROVIDERS: SearchProvider[] = [
599
609
  ];
600
610
 
601
611
  /**
602
- * 配置了 key 的服务,按调用顺序。JADE_SEARCH 是逗号分隔的服务名,决定顺序和范围(没 key 的跳过);
603
- * 不设时用所有配了 key 的服务,按 SEARCH_PROVIDERS 的顺序
612
+ * 配置了 key 的服务,按调用顺序。order 是服务名,决定顺序和范围(没 key 的跳过);
613
+ * 不给时用所有配了 key 的服务,按 SEARCH_PROVIDERS 的顺序
604
614
  */
605
- function backends(env: Record<string, string | undefined>, fetchImpl: typeof fetch): Backend[] {
606
- const named = env.JADE_SEARCH?.split(",").map((s) => s.trim().toLowerCase()).filter(Boolean);
607
- const unknown = named?.filter((n) => !SEARCH_PROVIDERS.some((p) => p.name === n));
608
- if (unknown?.length) throw new Error(`JADE_SEARCH: unknown service ${unknown.join(", ")}; choose from ${SEARCH_PROVIDERS.map((p) => p.name).join(", ")}`);
609
- const order = named?.length ? named.map((n) => SEARCH_PROVIDERS.find((p) => p.name === n)!) : SEARCH_PROVIDERS;
610
- return order.flatMap((p) => (env[p.env] ? [p.make(env[p.env]!, fetchImpl)] : []));
615
+ function backends(env: Env, order: string[] | undefined, fetchImpl: typeof fetch): Backend[] {
616
+ const list = order?.length ? order.map((n) => SEARCH_PROVIDERS.find((p) => p.name === n)!) : SEARCH_PROVIDERS;
617
+ return list.flatMap((p) => (env[p.env] ? [p.make(env[p.env]!, fetchImpl)] : []));
618
+ }
619
+
620
+ function checkOrder(order: string[]): void {
621
+ const unknown = order.filter((n) => !SEARCH_PROVIDERS.some((p) => p.name === n));
622
+ if (unknown.length) throw new Error(`unknown search service ${unknown.join(", ")}; choose from ${SEARCH_PROVIDERS.map((p) => p.name).join(", ")}`);
611
623
  }
612
624
 
613
- /** JADE_SEARCH_RESULTS:每次搜索返回的条数 */
614
- function resultCount(env: Record<string, string | undefined>): number {
615
- const raw = env.JADE_SEARCH_RESULTS?.trim();
616
- if (!raw) return DEFAULT_RESULTS;
625
+ /**
626
+ * 配置项 search(或旧 jade 的 JADE_SEARCH):逗号分隔的服务名或服务名的数组。不设时返回 undefined;
627
+ * 不认识的服务名抛错,错误信息里带来源 label
628
+ */
629
+ export function parseOrder(value: unknown, label: string): string[] | undefined {
630
+ if (value === undefined || value === null || value === "") return undefined;
631
+ const list = typeof value === "string" ? value.split(",") : Array.isArray(value) && value.every((v) => typeof v === "string") ? (value as string[]) : undefined;
632
+ if (!list) throw new Error(`${label} must be a comma-separated list of search services, got ${JSON.stringify(value)}`);
633
+ const named = list.map((s) => s.trim().toLowerCase()).filter(Boolean);
634
+ try {
635
+ checkOrder(named);
636
+ } catch (e) {
637
+ throw new Error(`${label}: ${(e as Error).message}`);
638
+ }
639
+ return named.length ? named : undefined;
640
+ }
641
+
642
+ /** 配置项 results(或旧 jade 的 JADE_SEARCH_RESULTS):每次搜索返回的条数,1 到 MAX_RESULTS */
643
+ export function parseResults(value: unknown, label: string): number {
644
+ const raw = typeof value === "string" ? value.trim() : value;
645
+ if (raw === undefined || raw === null || raw === "") return DEFAULT_RESULTS;
617
646
  const n = Number(raw);
618
- if (!Number.isInteger(n) || n < 1 || n > MAX_RESULTS) throw new Error(`JADE_SEARCH_RESULTS must be an integer from 1 to ${MAX_RESULTS}, got ${JSON.stringify(raw)}`);
647
+ if (!Number.isInteger(n) || n < 1 || n > MAX_RESULTS) throw new Error(`${label} must be an integer from 1 to ${MAX_RESULTS}, got ${JSON.stringify(value)}`);
619
648
  return n;
620
649
  }
621
650
 
622
651
  // ---------- web_search ----------
623
652
 
624
- function webSearchTool(services: Backend[], count: number): Tool {
653
+ /** 没有配置搜索服务时调用 web_search 的结果(正常情况下这时 web_search 不发给模型) */
654
+ export const SEARCH_OFF = "Web search is not set up. The user can turn it on with the /search command.";
655
+
656
+ function webSearchTool(live: () => Backend[], count: number): Tool {
625
657
  return {
626
658
  name: "web_search",
627
659
  description:
@@ -639,6 +671,8 @@ function webSearchTool(services: Backend[], count: number): Tool {
639
671
  async execute(input, { signal }) {
640
672
  const { query } = input as { query: string };
641
673
  if (!query.trim()) return { content: "query must not be empty", isError: true };
674
+ const services = live();
675
+ if (!services.length) return { content: SEARCH_OFF, isError: true };
642
676
  // 按顺序试,出错或没有结果时换下一个
643
677
  const failures: string[] = [];
644
678
  let failed = false;
@@ -678,4 +712,3 @@ function errorText(err: unknown): string {
678
712
  }
679
713
 
680
714
  const clip = (s: string, n: number) => (s.length > n ? s.slice(0, n) + "…" : s);
681
-
@@ -0,0 +1,287 @@
1
+ // jade/approval:审批。tool.before 把路径统一成绝对路径,tool.gate 按模式和规则决定,要问时经 ui@1 问用户。
2
+ // auto 模式下规则判断不了、本来要问的调用先让模型审一次(review.ts):它只能放行或转给用户,不能替用户拒绝。
3
+ //
4
+ // 没有这个插件(停用、坏掉、被隔离)时,核心的兜底关卡拒绝所有非只读工具(第 7 节),所以这里出错不会放行。
5
+ // 用户选的"总是允许"记进日志(derived),恢复会话后仍然有效;模式是进程级的,来自配置,可以经 approval@1 改。
6
+ import path from "node:path";
7
+ import { definePlugin } from "../../dist/api.js";
8
+ import { describeRule, MODES, policy } from "./policy.js";
9
+ import { reviewer } from "./review.js";
10
+ const ANSWERS = ["once", "always", "deny"];
11
+ /** derived 里保存"总是允许"规则的键 */
12
+ const RULES_KEY = "jade/approval/rules";
13
+ /** 等用户回答的默认时限:内核要求 hook 有有限的超时,超时按拒绝处理。配置 askTimeoutMinutes 可以改 */
14
+ const ASK_TIMEOUT_MS = 24 * 60 * 60 * 1000;
15
+ /** askTimeoutMinutes 的上限:内核的定时器最长约 24.8 天 */
16
+ const MAX_ASK_TIMEOUT_MINUTES = 7 * 24 * 60;
17
+ const MAX_DETAIL_CHARS = 2000;
18
+ /** 等工具的审批预览的时限,过了就用默认的 detail */
19
+ const PREVIEW_TIMEOUT_MS = 5000;
20
+ /**
21
+ * 带 URL 的只读工具审查放行之后,完全相同的调用不再审查。不按主机记:同一主机上换一个路径或查询参数
22
+ * 就能把本地数据带出去,正是审查要拦的
23
+ */
24
+ const reviewedKey = (call) => {
25
+ const url = call.input?.url;
26
+ if (call.tool.effect !== "read" || typeof url !== "string")
27
+ return undefined;
28
+ return `${call.name} ${JSON.stringify(call.input)}`;
29
+ };
30
+ let mode = "ask";
31
+ /** 配置里写错的模式:第一个会话打开时告诉用户(process 里可能还拿不到 ui@1:它的提供者可能排在后面激活) */
32
+ let badMode;
33
+ let askTimeoutMs = ASK_TIMEOUT_MS;
34
+ /** 配置里写错的 askTimeoutMinutes,和 badMode 一样在第一个会话打开时告诉用户 */
35
+ let badTimeout;
36
+ /** 经 allowRead 登记的目录;policy 每次判断时读它 */
37
+ const readRoots = [];
38
+ /** 经 allowWrite 登记的目录;policy 每次判断时读它 */
39
+ const writeRoots = [];
40
+ /** 经 addApprover 登记的审批渠道 */
41
+ const approvers = new Set();
42
+ /** 打开着的会话:会话 id → 判断只读调用能不能不问就执行(allows) */
43
+ const sessionChecks = new Map();
44
+ export default definePlugin({
45
+ process(ctx) {
46
+ const configured = ctx.config.mode;
47
+ if (typeof configured === "string" && MODES.includes(configured))
48
+ mode = configured;
49
+ else if (configured !== undefined)
50
+ badMode = JSON.stringify(configured);
51
+ const minutes = ctx.config.askTimeoutMinutes;
52
+ askTimeoutMs = ASK_TIMEOUT_MS;
53
+ badTimeout = undefined;
54
+ if (typeof minutes === "number" && Number.isFinite(minutes) && minutes > 0 && minutes <= MAX_ASK_TIMEOUT_MINUTES)
55
+ askTimeoutMs = minutes * 60_000;
56
+ else if (minutes !== undefined)
57
+ badTimeout = JSON.stringify(minutes);
58
+ ctx.provide("approval@1", (caller) => ({
59
+ mode: () => mode,
60
+ setMode(next) {
61
+ if (!MODES.includes(next))
62
+ throw new Error(`mode must be one of ${MODES.join(", ")}`);
63
+ mode = next;
64
+ },
65
+ allowRead: (dir) => allow(caller, "allowRead", readRoots, dir),
66
+ allowWrite: (dir) => allow(caller, "allowWrite", writeRoots, dir),
67
+ addApprover(approver) {
68
+ if (caller.layer === "project")
69
+ throw new Error("approval.addApprover: project plugins cannot answer approvals");
70
+ if (typeof approver !== "function")
71
+ throw new Error("approval.addApprover: approver must be a function");
72
+ approvers.add(approver);
73
+ const remove = () => void approvers.delete(approver);
74
+ caller.onDispose(remove);
75
+ return remove;
76
+ },
77
+ allows: (session, call) => call.tool?.effect === "read" && (sessionChecks.get(session)?.(call) ?? false),
78
+ }));
79
+ },
80
+ async session(ctx) {
81
+ const rules = policy({ cwd: ctx.cwd, readRoots, writeRoots });
82
+ const ui = ctx.service("ui@1");
83
+ if (badMode !== undefined) {
84
+ ui?.notify(`jade/approval: mode must be one of ${MODES.join(", ")}, got ${badMode}; using ask`, "warning");
85
+ badMode = undefined;
86
+ }
87
+ if (badTimeout !== undefined) {
88
+ ui?.notify(`jade/approval: askTimeoutMinutes must be a number of minutes between 0 and ${MAX_ASK_TIMEOUT_MINUTES}, got ${badTimeout}; using 24 hours`, "warning");
89
+ badTimeout = undefined;
90
+ }
91
+ const renderers = ctx.service("renderers@1");
92
+ // auto 模式的审查用当前配置的模型;没有 models@1(模型插件被停用)或者配置里关掉时不做审查
93
+ const models = ctx.service("models@1");
94
+ const reviewing = models !== undefined && ctx.config.review !== false;
95
+ /** 最近一次请求里的消息:auto 模式的审查从中取用户最近的请求 */
96
+ const recent = { messages: [] };
97
+ if (reviewing) {
98
+ ctx.kernel.hook({
99
+ kind: "transform",
100
+ point: "context.build",
101
+ fn: (req) => {
102
+ recent.messages = req.messages;
103
+ return req;
104
+ },
105
+ });
106
+ }
107
+ const review = reviewing ? reviewer({ models: models, cwd: ctx.cwd, writeRoots: () => writeRoots, messages: () => recent.messages }) : undefined;
108
+ /** 本会话里审查过一次、放行了的调用 */
109
+ const reviewedCalls = new Set();
110
+ let warned = false;
111
+ /** 本进程里刚选的"总是允许":并发的关卡拿到的 derived 是各自开始时的快照,可能还没有它 */
112
+ const added = [];
113
+ /** 一次只问一个问题;排在后面的问之前重新判断,前面刚选的"总是允许"可能已经覆盖它 */
114
+ let asking = Promise.resolve();
115
+ /** 日志里记下的"总是允许"规则,每次调用工具前取一次:子 Agent 在工具执行期间经 allows 用它 */
116
+ let logged = [];
117
+ const id = ctx.session.id;
118
+ const check = (call) => rules.decide(call, { mode: mode === "yolo" ? "yolo" : "readonly", rules: [...logged, ...added] }).decision === "allow";
119
+ sessionChecks.set(id, check);
120
+ await ctx.effect(() => () => {
121
+ if (sessionChecks.get(id) === check)
122
+ sessionChecks.delete(id);
123
+ });
124
+ ctx.kernel.hook({
125
+ kind: "transform",
126
+ point: "tool.before",
127
+ fn: (call, hook) => {
128
+ logged = hook.derived[RULES_KEY] ?? [];
129
+ return { ...call, input: rules.absolutePath(call.input) };
130
+ },
131
+ });
132
+ ctx.kernel.hook({
133
+ kind: "gate",
134
+ point: "tool.gate",
135
+ timeoutMs: askTimeoutMs,
136
+ fn: async (call, hook) => {
137
+ const saved = () => {
138
+ const logged = hook.derived[RULES_KEY] ?? [];
139
+ return [...logged, ...added.filter((r) => !logged.some((l) => JSON.stringify(l) === JSON.stringify(r)))];
140
+ };
141
+ const result = rules.decide(call, { mode, rules: saved() });
142
+ if (result.decision !== "ask")
143
+ return result;
144
+ // auto 模式:规则判断不了、本来要问的调用先让模型审一次。审查只能放行或转给用户,不会替用户拒绝
145
+ let why;
146
+ if (review && mode === "auto") {
147
+ const key = reviewedKey(call);
148
+ if (key !== undefined && reviewedCalls.has(key))
149
+ return { decision: "allow", reason: "This exact call was already approved in this session." };
150
+ const verdict = await review(call, hook.signal);
151
+ // 审查调用不经过 model.responded,用量只能记在这里,界面据此计入会话用量
152
+ if (verdict.usage)
153
+ await hook.emit("reviewed", { toolUseId: call.toolUseId, usage: verdict.usage });
154
+ if (verdict.decision === "allow") {
155
+ if (key !== undefined)
156
+ reviewedCalls.add(key);
157
+ return { decision: "allow", reason: verdict.reason };
158
+ }
159
+ why = verdict.reason;
160
+ }
161
+ if (!ui?.interactive && approvers.size === 0) {
162
+ if (!warned) {
163
+ warned = true;
164
+ ui?.notify(`${call.name} needs approval, but this jade cannot ask. To let it make changes in the working directory, ` +
165
+ `set {"jade/approval": {"mode": "auto"}} in ${ctx.home}/config.json`, "warning");
166
+ }
167
+ return { decision: "deny", reason: `${call.name} needs the user's approval, but nobody can approve it in this non-interactive run. Do not retry it; tell the user what you wanted to do.` };
168
+ }
169
+ const turn = asking.then(async () => {
170
+ const again = rules.decide(call, { mode, rules: saved() });
171
+ if (again.decision !== "ask")
172
+ return again;
173
+ const rule = rules.ruleFor(call);
174
+ const shown = (await preview(renderers, call)) ?? detail(call);
175
+ const answer = await ask(ui, {
176
+ title: `Allow ${call.name}?`,
177
+ // 审查转给用户的:先说为什么
178
+ detail: why ? `${why}\n\n${shown}` : shown,
179
+ options: [
180
+ { label: "Allow once", value: "once" },
181
+ { label: `Always allow ${describeRule(rule)} in this session`, value: "always" },
182
+ { label: "Deny", value: "deny" },
183
+ ],
184
+ }, hook.signal);
185
+ if (answer === "always") {
186
+ added.push(rule);
187
+ await hook.record(RULES_KEY, saved());
188
+ return { decision: "allow" };
189
+ }
190
+ if (answer === "once")
191
+ return { decision: "allow" };
192
+ return { decision: "deny", reason: "The user denied this tool call. Do not retry it unchanged: adjust, or ask what to do instead." };
193
+ });
194
+ asking = turn.catch(() => { });
195
+ return turn;
196
+ },
197
+ });
198
+ },
199
+ });
200
+ /** allowRead、allowWrite:把目录登记进 roots,调用方的作用域关闭时撤销 */
201
+ function allow(caller, name, roots, dir) {
202
+ if (caller.layer === "project")
203
+ throw new Error(`approval.${name}: project plugins cannot widen what runs without asking`);
204
+ if (typeof dir !== "string" || !path.isAbsolute(dir))
205
+ throw new Error(`approval.${name}: dir must be an absolute path`);
206
+ const root = path.resolve(dir);
207
+ roots.push(root);
208
+ const remove = () => {
209
+ const i = roots.indexOf(root);
210
+ if (i !== -1)
211
+ roots.splice(i, 1);
212
+ };
213
+ caller.onDispose(remove);
214
+ return remove;
215
+ }
216
+ /**
217
+ * 把问题同时交给终端(能提问时)和所有审批渠道,返回先到的回答,然后中止其余的。
218
+ * 终端里取消(undefined)算拒绝;渠道返回 undefined、不认识的值或出错算它不回答。都不回答时返回 undefined(拒绝)
219
+ */
220
+ async function ask(ui, request, signal) {
221
+ const done = new AbortController();
222
+ const stop = () => done.abort(signal.reason);
223
+ signal.addEventListener("abort", stop, { once: true });
224
+ try {
225
+ return await new Promise((resolve, reject) => {
226
+ const channels = [];
227
+ if (ui?.interactive)
228
+ channels.push(ui.select(request, done.signal).then((a) => (a !== undefined && ANSWERS.includes(a) ? a : "deny")));
229
+ for (const approver of approvers) {
230
+ channels.push(Promise.resolve()
231
+ .then(() => approver(request, done.signal))
232
+ .then((a) => (typeof a === "string" && ANSWERS.includes(a) ? a : NONE), () => NONE));
233
+ }
234
+ let pending = channels.length;
235
+ if (pending === 0)
236
+ return resolve(undefined);
237
+ for (const c of channels) {
238
+ c.then((a) => {
239
+ if (a !== NONE)
240
+ resolve(a);
241
+ else if (--pending === 0)
242
+ resolve(undefined);
243
+ }, reject);
244
+ }
245
+ });
246
+ }
247
+ finally {
248
+ signal.removeEventListener("abort", stop);
249
+ done.abort(new Error("answered"));
250
+ }
251
+ }
252
+ const NONE = Symbol("no answer");
253
+ /**
254
+ * 工具自己登记的审批预览(例如文件修改的 diff)。没有登记、返回的不是文字、或者出错时返回 undefined,
255
+ * 用下面的 detail:预览是别的插件的代码,它坏了不能让审批卡住或失败
256
+ */
257
+ async function preview(renderers, call) {
258
+ let timer;
259
+ try {
260
+ // 预览可能读文件、算 diff;一直不返回时也要能问用户
261
+ const late = new Promise((resolve) => {
262
+ timer = setTimeout(() => resolve(undefined), PREVIEW_TIMEOUT_MS);
263
+ });
264
+ const text = await Promise.race([Promise.resolve(renderers?.forTool(call.name)?.renderer.preview?.(call.input)), late]);
265
+ return typeof text === "string" ? text : undefined;
266
+ }
267
+ catch {
268
+ return undefined;
269
+ }
270
+ finally {
271
+ clearTimeout(timer);
272
+ }
273
+ }
274
+ /** 给用户看的调用内容:命令、路径和要写的内容,太长的截断 */
275
+ function detail(call) {
276
+ const input = call.input;
277
+ let text;
278
+ if (typeof input?.command === "string")
279
+ text = input.command;
280
+ else if (typeof input?.path === "string" && typeof input.content === "string")
281
+ text = `${input.path}\n\n${input.content}`;
282
+ else if (typeof input?.path === "string" && typeof input.old_string === "string")
283
+ text = `${input.path}\n\n- ${input.old_string}\n+ ${String(input.new_string)}`;
284
+ else
285
+ text = JSON.stringify(input, null, 2);
286
+ return text.length > MAX_DETAIL_CHARS ? `${text.slice(0, MAX_DETAIL_CHARS)}\n… (${text.length - MAX_DETAIL_CHARS} more characters)` : text;
287
+ }
@@ -0,0 +1,28 @@
1
+ {
2
+ "id": "jade/approval",
3
+ "version": "0.4.0",
4
+ "api": "^1",
5
+ "entry": "./index.js",
6
+ "provides": [
7
+ "approval@1"
8
+ ],
9
+ "optional": [
10
+ "ui@1",
11
+ "renderers@1",
12
+ "models@1"
13
+ ],
14
+ "config": {
15
+ "mode": {
16
+ "default": "ask",
17
+ "description": "ask: ask before changes; auto: changes inside the working directory and harmless commands go through; plan: change nothing, present a plan; readonly: change nothing; yolo: never ask"
18
+ },
19
+ "askTimeoutMinutes": {
20
+ "default": 1440,
21
+ "description": "how long to wait for an answer to an approval question before denying the call (at most 10080, one week)"
22
+ },
23
+ "review": {
24
+ "default": true,
25
+ "description": "in auto mode, let the model review the calls the rules cannot decide (it can only allow or pass them to you); false turns the review off"
26
+ }
27
+ }
28
+ }