@uncarved/jade 0.1.2 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (436) hide show
  1. package/bin/jade.js +5 -4
  2. package/dist/api.d.ts +266 -0
  3. package/dist/api.js +38 -0
  4. package/dist/api.js.map +1 -0
  5. package/dist/config.d.ts +13 -32
  6. package/dist/config.js +39 -121
  7. package/dist/config.js.map +1 -1
  8. package/dist/fetch.d.ts +20 -0
  9. package/dist/fetch.js +190 -0
  10. package/dist/fetch.js.map +1 -0
  11. package/dist/hash.d.ts +2 -0
  12. package/dist/hash.js +42 -0
  13. package/dist/hash.js.map +1 -0
  14. package/dist/host.d.ts +71 -0
  15. package/dist/host.js +400 -0
  16. package/dist/host.js.map +1 -0
  17. package/dist/index.d.ts +11 -28
  18. package/dist/index.js +11 -28
  19. package/dist/index.js.map +1 -1
  20. package/dist/install.d.ts +78 -0
  21. package/dist/install.js +292 -0
  22. package/dist/install.js.map +1 -0
  23. package/dist/main.d.ts +1 -2
  24. package/dist/main.js +156 -1223
  25. package/dist/main.js.map +1 -1
  26. package/dist/manifest.d.ts +23 -0
  27. package/dist/manifest.js +159 -0
  28. package/dist/manifest.js.map +1 -0
  29. package/dist/membrane.d.ts +33 -0
  30. package/dist/membrane.js +140 -0
  31. package/dist/membrane.js.map +1 -0
  32. package/dist/remote.d.ts +10 -0
  33. package/dist/remote.js +292 -0
  34. package/dist/remote.js.map +1 -0
  35. package/dist/rescue.d.ts +10 -0
  36. package/dist/rescue.js +216 -0
  37. package/dist/rescue.js.map +1 -0
  38. package/dist/resolve.d.ts +34 -0
  39. package/dist/resolve.js +178 -0
  40. package/dist/resolve.js.map +1 -0
  41. package/dist/rpc.d.ts +26 -0
  42. package/dist/rpc.js +144 -0
  43. package/dist/rpc.js.map +1 -0
  44. package/dist/secrets.d.ts +12 -0
  45. package/dist/secrets.js +125 -0
  46. package/dist/secrets.js.map +1 -0
  47. package/dist/session.d.ts +45 -0
  48. package/dist/session.js +401 -0
  49. package/dist/session.js.map +1 -0
  50. package/dist/source.d.ts +12 -0
  51. package/dist/source.js +72 -0
  52. package/dist/source.js.map +1 -0
  53. package/dist/state.d.ts +37 -0
  54. package/dist/state.js +93 -0
  55. package/dist/state.js.map +1 -0
  56. package/dist/update.d.ts +55 -0
  57. package/dist/update.js +258 -0
  58. package/dist/update.js.map +1 -0
  59. package/package.json +12 -9
  60. package/plugins/approval/index.ts +297 -0
  61. package/plugins/approval/plugin.json +18 -0
  62. package/{src/plugins → plugins/approval}/policy.ts +21 -84
  63. package/plugins/approval/review.ts +192 -0
  64. package/plugins/ask/index.ts +159 -0
  65. package/plugins/ask/plugin.json +8 -0
  66. package/plugins/budget/index.ts +38 -0
  67. package/plugins/budget/plugin.json +13 -0
  68. package/{src/plugins → plugins/checks}/checks.ts +68 -39
  69. package/plugins/checks/index.ts +158 -0
  70. package/plugins/checks/plugin.json +14 -0
  71. package/plugins/checks/project.ts +81 -0
  72. package/plugins/commands/index.ts +76 -0
  73. package/plugins/commands/plugin.json +7 -0
  74. package/{src/plugins → plugins/compact}/compact.ts +112 -38
  75. package/plugins/compact/index.ts +115 -0
  76. package/plugins/compact/plugin.json +17 -0
  77. package/plugins/compact/style.ts +17 -0
  78. package/plugins/continue/index.ts +58 -0
  79. package/plugins/continue/plugin.json +13 -0
  80. package/{src/ui → plugins/fs}/diff.ts +3 -4
  81. package/{src/tools → plugins/fs}/fs.ts +64 -46
  82. package/{src/tools → plugins/fs}/grep.ts +4 -3
  83. package/plugins/fs/index.ts +34 -0
  84. package/plugins/fs/plugin.json +7 -0
  85. package/plugins/fs/renderers.ts +138 -0
  86. package/plugins/fs/style.ts +18 -0
  87. package/plugins/fs/sys.ts +81 -0
  88. package/plugins/keys/index.ts +53 -0
  89. package/plugins/keys/plugin.json +7 -0
  90. package/plugins/mcp/index.ts +192 -0
  91. package/{src → plugins/mcp}/mcp.ts +32 -32
  92. package/plugins/mcp/plugin.json +7 -0
  93. package/plugins/mcp/project.ts +93 -0
  94. package/plugins/memory/index.ts +105 -0
  95. package/{src → plugins/memory}/memory.ts +20 -2
  96. package/plugins/memory/notes.ts +43 -0
  97. package/plugins/memory/plugin.json +7 -0
  98. package/plugins/memory/style.ts +17 -0
  99. package/plugins/mentions/attach.ts +127 -0
  100. package/plugins/mentions/index.ts +79 -0
  101. package/plugins/mentions/plugin.json +7 -0
  102. package/plugins/mentions/style.ts +17 -0
  103. package/plugins/models/config.ts +53 -0
  104. package/plugins/models/configure.ts +455 -0
  105. package/plugins/models/context.ts +32 -0
  106. package/plugins/models/index.ts +198 -0
  107. package/plugins/models/plugin.json +8 -0
  108. package/{src → plugins/models}/provider.ts +23 -27
  109. package/plugins/models/saved.ts +94 -0
  110. package/plugins/modes/index.ts +222 -0
  111. package/plugins/modes/plugin.json +9 -0
  112. package/plugins/plugins/index.ts +38 -0
  113. package/plugins/plugins/plugin.json +7 -0
  114. package/plugins/print/index.ts +142 -0
  115. package/plugins/print/plugin.json +8 -0
  116. package/plugins/prompts/index.ts +83 -0
  117. package/plugins/prompts/plugin.json +8 -0
  118. package/plugins/prompts/prompts.ts +253 -0
  119. package/plugins/prompts/sys.ts +72 -0
  120. package/plugins/renderers/index.ts +78 -0
  121. package/plugins/renderers/plugin.json +7 -0
  122. package/plugins/repeats/index.ts +165 -0
  123. package/plugins/repeats/plugin.json +6 -0
  124. package/plugins/schedule/cron.ts +74 -0
  125. package/plugins/schedule/index.ts +292 -0
  126. package/plugins/schedule/plugin.json +13 -0
  127. package/plugins/schedule/store.ts +149 -0
  128. package/plugins/scratch/index.ts +31 -0
  129. package/plugins/scratch/plugin.json +7 -0
  130. package/plugins/screenshot/index.ts +40 -0
  131. package/plugins/screenshot/plugin.json +7 -0
  132. package/plugins/screenshot/sys.ts +84 -0
  133. package/{src/tools/screenshot.ts → plugins/screenshot/tool.ts} +6 -6
  134. package/plugins/sessions/index.ts +148 -0
  135. package/plugins/sessions/plugin.json +8 -0
  136. package/plugins/shell/index.ts +33 -0
  137. package/plugins/shell/plugin.json +17 -0
  138. package/plugins/shell/renderers.ts +45 -0
  139. package/plugins/shell/service.ts +44 -0
  140. package/{src/tools → plugins/shell}/shell.ts +36 -21
  141. package/{src → plugins/shell}/sys.ts +19 -43
  142. package/plugins/skills/index.ts +96 -0
  143. package/plugins/skills/plugin.json +7 -0
  144. package/plugins/skills/project.ts +49 -0
  145. package/{src → plugins/skills}/skills.ts +4 -11
  146. package/plugins/suggest/index.ts +286 -0
  147. package/plugins/suggest/plugin.json +18 -0
  148. package/plugins/task/index.ts +167 -0
  149. package/plugins/task/plugin.json +15 -0
  150. package/plugins/task/style.ts +17 -0
  151. package/plugins/task/subagent.ts +257 -0
  152. package/{src/tools/todo.ts → plugins/todo/index.ts} +33 -7
  153. package/plugins/todo/plugin.json +7 -0
  154. package/{src/ui → plugins/tui}/editor.ts +53 -1
  155. package/plugins/tui/frontend.ts +596 -0
  156. package/plugins/tui/index.ts +37 -0
  157. package/{src/ui → plugins/tui}/markdown.ts +258 -219
  158. package/plugins/tui/mentions.ts +113 -0
  159. package/plugins/tui/plugin.json +10 -0
  160. package/plugins/tui/render.ts +67 -0
  161. package/plugins/tui/screen.ts +268 -0
  162. package/{src/ui → plugins/tui}/transcript.ts +179 -111
  163. package/{src/ui/tui.tsx → plugins/tui/tui.ts} +684 -418
  164. package/{src/tools → plugins/undo}/checkpoint.ts +21 -60
  165. package/plugins/undo/index.ts +139 -0
  166. package/plugins/undo/notes.ts +43 -0
  167. package/plugins/undo/plugin.json +7 -0
  168. package/plugins/undo/style.ts +17 -0
  169. package/plugins/update/index.ts +40 -0
  170. package/plugins/update/plugin.json +13 -0
  171. package/plugins/web/env.ts +78 -0
  172. package/plugins/web/index.ts +133 -0
  173. package/plugins/web/plugin.json +15 -0
  174. package/plugins/web/renderers.ts +11 -0
  175. package/plugins/web/web.ts +713 -0
  176. package/plugins-dist/approval/index.js +271 -0
  177. package/plugins-dist/approval/plugin.json +24 -0
  178. package/{dist/plugins → plugins-dist/approval}/policy.js +15 -65
  179. package/plugins-dist/approval/review.js +176 -0
  180. package/{dist/plugins → plugins-dist/approval}/schema.js +0 -1
  181. package/plugins-dist/ask/index.js +145 -0
  182. package/plugins-dist/ask/plugin.json +12 -0
  183. package/plugins-dist/budget/index.js +37 -0
  184. package/plugins-dist/budget/plugin.json +15 -0
  185. package/{dist/plugins → plugins-dist/checks}/checks.js +65 -34
  186. package/plugins-dist/checks/index.js +150 -0
  187. package/plugins-dist/checks/plugin.json +21 -0
  188. package/plugins-dist/checks/project.js +76 -0
  189. package/plugins-dist/commands/index.js +33 -0
  190. package/plugins-dist/commands/plugin.json +9 -0
  191. package/{dist/plugins → plugins-dist/compact}/compact.js +95 -33
  192. package/plugins-dist/compact/index.js +100 -0
  193. package/plugins-dist/compact/plugin.json +25 -0
  194. package/plugins-dist/compact/style.js +14 -0
  195. package/plugins-dist/continue/index.js +57 -0
  196. package/plugins-dist/continue/plugin.json +15 -0
  197. package/{dist/ui → plugins-dist/fs}/diff.js +3 -5
  198. package/{dist/tools → plugins-dist/fs}/fs.js +62 -46
  199. package/{dist/tools → plugins-dist/fs}/grep.js +4 -4
  200. package/plugins-dist/fs/index.js +36 -0
  201. package/plugins-dist/fs/plugin.json +10 -0
  202. package/plugins-dist/fs/renderers.js +132 -0
  203. package/plugins-dist/fs/style.js +15 -0
  204. package/plugins-dist/fs/sys.js +54 -0
  205. package/plugins-dist/keys/index.js +36 -0
  206. package/plugins-dist/keys/plugin.json +9 -0
  207. package/plugins-dist/mcp/index.js +187 -0
  208. package/{dist → plugins-dist/mcp}/mcp.js +34 -30
  209. package/plugins-dist/mcp/plugin.json +12 -0
  210. package/plugins-dist/mcp/project.js +90 -0
  211. package/plugins-dist/memory/index.js +94 -0
  212. package/{dist → plugins-dist/memory}/memory.js +21 -3
  213. package/plugins-dist/memory/notes.js +36 -0
  214. package/plugins-dist/memory/plugin.json +11 -0
  215. package/plugins-dist/memory/style.js +14 -0
  216. package/plugins-dist/mentions/attach.js +120 -0
  217. package/plugins-dist/mentions/index.js +69 -0
  218. package/plugins-dist/mentions/plugin.json +9 -0
  219. package/plugins-dist/mentions/style.js +14 -0
  220. package/plugins-dist/models/config.js +53 -0
  221. package/plugins-dist/models/configure.js +415 -0
  222. package/plugins-dist/models/context.js +27 -0
  223. package/plugins-dist/models/index.js +167 -0
  224. package/plugins-dist/models/plugin.json +14 -0
  225. package/{dist → plugins-dist/models}/provider.js +22 -19
  226. package/plugins-dist/models/saved.js +80 -0
  227. package/plugins-dist/modes/index.js +190 -0
  228. package/plugins-dist/modes/plugin.json +18 -0
  229. package/plugins-dist/plugins/index.js +37 -0
  230. package/plugins-dist/plugins/plugin.json +10 -0
  231. package/plugins-dist/print/index.js +153 -0
  232. package/plugins-dist/print/plugin.json +14 -0
  233. package/plugins-dist/prompts/index.js +57 -0
  234. package/plugins-dist/prompts/plugin.json +13 -0
  235. package/plugins-dist/prompts/prompts.js +227 -0
  236. package/plugins-dist/prompts/sys.js +46 -0
  237. package/plugins-dist/renderers/index.js +36 -0
  238. package/plugins-dist/renderers/plugin.json +9 -0
  239. package/plugins-dist/repeats/index.js +165 -0
  240. package/plugins-dist/repeats/plugin.json +6 -0
  241. package/plugins-dist/schedule/cron.js +67 -0
  242. package/plugins-dist/schedule/index.js +281 -0
  243. package/plugins-dist/schedule/plugin.json +16 -0
  244. package/plugins-dist/schedule/store.js +125 -0
  245. package/plugins-dist/scratch/index.js +26 -0
  246. package/plugins-dist/scratch/plugin.json +10 -0
  247. package/plugins-dist/screenshot/index.js +35 -0
  248. package/plugins-dist/screenshot/plugin.json +11 -0
  249. package/plugins-dist/screenshot/sys.js +76 -0
  250. package/{dist/tools/screenshot.js → plugins-dist/screenshot/tool.js} +5 -4
  251. package/plugins-dist/sessions/index.js +136 -0
  252. package/plugins-dist/sessions/plugin.json +12 -0
  253. package/plugins-dist/shell/index.js +33 -0
  254. package/plugins-dist/shell/plugin.json +19 -0
  255. package/plugins-dist/shell/renderers.js +40 -0
  256. package/plugins-dist/shell/service.js +29 -0
  257. package/{dist/tools → plugins-dist/shell}/shell.js +36 -23
  258. package/{dist → plugins-dist/shell}/sys.js +20 -44
  259. package/plugins-dist/skills/index.js +90 -0
  260. package/plugins-dist/skills/plugin.json +12 -0
  261. package/plugins-dist/skills/project.js +47 -0
  262. package/{dist → plugins-dist/skills}/skills.js +3 -7
  263. package/plugins-dist/suggest/index.js +282 -0
  264. package/plugins-dist/suggest/plugin.json +23 -0
  265. package/plugins-dist/task/index.js +151 -0
  266. package/plugins-dist/task/plugin.json +23 -0
  267. package/plugins-dist/task/style.js +14 -0
  268. package/plugins-dist/task/subagent.js +208 -0
  269. package/{dist/tools/todo.js → plugins-dist/todo/index.js} +29 -7
  270. package/plugins-dist/todo/plugin.json +9 -0
  271. package/{dist/ui → plugins-dist/tui}/editor.js +53 -2
  272. package/plugins-dist/tui/frontend.js +586 -0
  273. package/{dist → plugins-dist/tui}/history.js +0 -1
  274. package/plugins-dist/tui/index.js +21 -0
  275. package/{dist/ui → plugins-dist/tui}/markdown.js +57 -20
  276. package/plugins-dist/tui/mentions.js +115 -0
  277. package/plugins-dist/tui/plugin.json +25 -0
  278. package/plugins-dist/tui/render.js +61 -0
  279. package/plugins-dist/tui/screen.js +201 -0
  280. package/{dist/ui → plugins-dist/tui}/transcript.js +179 -111
  281. package/{dist/ui → plugins-dist/tui}/tui.js +484 -101
  282. package/{dist/tools → plugins-dist/undo}/checkpoint.js +21 -55
  283. package/plugins-dist/undo/index.js +140 -0
  284. package/plugins-dist/undo/notes.js +36 -0
  285. package/plugins-dist/undo/plugin.json +9 -0
  286. package/plugins-dist/undo/style.js +14 -0
  287. package/plugins-dist/update/index.js +34 -0
  288. package/plugins-dist/update/plugin.json +15 -0
  289. package/plugins-dist/web/env.js +80 -0
  290. package/plugins-dist/web/index.js +124 -0
  291. package/plugins-dist/web/plugin.json +21 -0
  292. package/plugins-dist/web/renderers.js +7 -0
  293. package/plugins-dist/web/web.js +660 -0
  294. package/sdk/python/__pycache__/jade_plugin.cpython-312.pyc +0 -0
  295. package/sdk/python/jade_plugin.py +380 -0
  296. package/src/api.ts +298 -0
  297. package/src/config.ts +32 -134
  298. package/src/fetch.ts +216 -0
  299. package/src/hash.ts +39 -0
  300. package/src/host.ts +429 -0
  301. package/src/index.ts +23 -28
  302. package/src/install.ts +355 -0
  303. package/src/main.ts +152 -1263
  304. package/src/manifest.ts +160 -0
  305. package/src/membrane.ts +142 -0
  306. package/src/remote.ts +288 -0
  307. package/src/rescue.ts +217 -0
  308. package/src/resolve.ts +199 -0
  309. package/src/rpc.ts +144 -0
  310. package/src/secrets.ts +122 -0
  311. package/src/session.ts +458 -0
  312. package/src/source.ts +83 -0
  313. package/src/state.ts +120 -0
  314. package/src/update.ts +265 -0
  315. package/LICENSE +0 -21
  316. package/README.md +0 -198
  317. package/dist/commands.d.ts +0 -30
  318. package/dist/commands.js +0 -106
  319. package/dist/commands.js.map +0 -1
  320. package/dist/context.d.ts +0 -17
  321. package/dist/context.js +0 -53
  322. package/dist/context.js.map +0 -1
  323. package/dist/distro.d.ts +0 -104
  324. package/dist/distro.js +0 -312
  325. package/dist/distro.js.map +0 -1
  326. package/dist/history.d.ts +0 -10
  327. package/dist/history.js.map +0 -1
  328. package/dist/mcp.d.ts +0 -114
  329. package/dist/mcp.js.map +0 -1
  330. package/dist/memory.d.ts +0 -19
  331. package/dist/memory.js.map +0 -1
  332. package/dist/mentions.d.ts +0 -35
  333. package/dist/mentions.js +0 -130
  334. package/dist/mentions.js.map +0 -1
  335. package/dist/plugin-cli.d.ts +0 -16
  336. package/dist/plugin-cli.js +0 -251
  337. package/dist/plugin-cli.js.map +0 -1
  338. package/dist/plugins/budget.d.ts +0 -9
  339. package/dist/plugins/budget.js +0 -30
  340. package/dist/plugins/budget.js.map +0 -1
  341. package/dist/plugins/builtins.d.ts +0 -10
  342. package/dist/plugins/builtins.js +0 -22
  343. package/dist/plugins/builtins.js.map +0 -1
  344. package/dist/plugins/checks.d.ts +0 -70
  345. package/dist/plugins/checks.js.map +0 -1
  346. package/dist/plugins/compact.d.ts +0 -26
  347. package/dist/plugins/compact.js.map +0 -1
  348. package/dist/plugins/core.d.ts +0 -42
  349. package/dist/plugins/core.js +0 -190
  350. package/dist/plugins/core.js.map +0 -1
  351. package/dist/plugins/install.d.ts +0 -68
  352. package/dist/plugins/install.js +0 -377
  353. package/dist/plugins/install.js.map +0 -1
  354. package/dist/plugins/loader.d.ts +0 -182
  355. package/dist/plugins/loader.js +0 -253
  356. package/dist/plugins/loader.js.map +0 -1
  357. package/dist/plugins/policy.d.ts +0 -96
  358. package/dist/plugins/policy.js.map +0 -1
  359. package/dist/plugins/prompts.d.ts +0 -38
  360. package/dist/plugins/prompts.js +0 -196
  361. package/dist/plugins/prompts.js.map +0 -1
  362. package/dist/plugins/repeats.d.ts +0 -9
  363. package/dist/plugins/repeats.js +0 -90
  364. package/dist/plugins/repeats.js.map +0 -1
  365. package/dist/plugins/review.d.ts +0 -16
  366. package/dist/plugins/review.js +0 -92
  367. package/dist/plugins/review.js.map +0 -1
  368. package/dist/plugins/schema.d.ts +0 -2
  369. package/dist/plugins/schema.js.map +0 -1
  370. package/dist/provider.d.ts +0 -111
  371. package/dist/provider.js.map +0 -1
  372. package/dist/sessions.d.ts +0 -22
  373. package/dist/sessions.js +0 -53
  374. package/dist/sessions.js.map +0 -1
  375. package/dist/skills.d.ts +0 -37
  376. package/dist/skills.js.map +0 -1
  377. package/dist/sys.d.ts +0 -48
  378. package/dist/sys.js.map +0 -1
  379. package/dist/tools/checkpoint.d.ts +0 -43
  380. package/dist/tools/checkpoint.js.map +0 -1
  381. package/dist/tools/fs.d.ts +0 -35
  382. package/dist/tools/fs.js.map +0 -1
  383. package/dist/tools/grep.d.ts +0 -6
  384. package/dist/tools/grep.js.map +0 -1
  385. package/dist/tools/screenshot.d.ts +0 -15
  386. package/dist/tools/screenshot.js.map +0 -1
  387. package/dist/tools/shell.d.ts +0 -55
  388. package/dist/tools/shell.js.map +0 -1
  389. package/dist/tools/task.d.ts +0 -35
  390. package/dist/tools/task.js +0 -89
  391. package/dist/tools/task.js.map +0 -1
  392. package/dist/tools/todo.d.ts +0 -10
  393. package/dist/tools/todo.js.map +0 -1
  394. package/dist/tools/web.d.ts +0 -23
  395. package/dist/tools/web.js +0 -426
  396. package/dist/tools/web.js.map +0 -1
  397. package/dist/ui/configure.d.ts +0 -20
  398. package/dist/ui/configure.js +0 -378
  399. package/dist/ui/configure.js.map +0 -1
  400. package/dist/ui/diff.d.ts +0 -20
  401. package/dist/ui/diff.js.map +0 -1
  402. package/dist/ui/editor.d.ts +0 -33
  403. package/dist/ui/editor.js.map +0 -1
  404. package/dist/ui/markdown.d.ts +0 -17
  405. package/dist/ui/markdown.js.map +0 -1
  406. package/dist/ui/render.d.ts +0 -15
  407. package/dist/ui/render.js +0 -94
  408. package/dist/ui/render.js.map +0 -1
  409. package/dist/ui/screen.d.ts +0 -98
  410. package/dist/ui/screen.js +0 -108
  411. package/dist/ui/screen.js.map +0 -1
  412. package/dist/ui/transcript.d.ts +0 -33
  413. package/dist/ui/transcript.js.map +0 -1
  414. package/dist/ui/tui.d.ts +0 -45
  415. package/dist/ui/tui.js.map +0 -1
  416. package/src/commands.ts +0 -120
  417. package/src/context.ts +0 -64
  418. package/src/distro.ts +0 -400
  419. package/src/mentions.ts +0 -135
  420. package/src/plugin-cli.ts +0 -239
  421. package/src/plugins/budget.ts +0 -37
  422. package/src/plugins/builtins.ts +0 -31
  423. package/src/plugins/core.ts +0 -217
  424. package/src/plugins/install.ts +0 -429
  425. package/src/plugins/loader.ts +0 -386
  426. package/src/plugins/prompts.ts +0 -234
  427. package/src/plugins/repeats.ts +0 -96
  428. package/src/plugins/review.ts +0 -109
  429. package/src/sessions.ts +0 -61
  430. package/src/tools/task.ts +0 -109
  431. package/src/tools/web.ts +0 -451
  432. package/src/ui/configure.ts +0 -408
  433. package/src/ui/render.ts +0 -83
  434. package/src/ui/screen.ts +0 -169
  435. /package/{src/plugins → plugins/approval}/schema.ts +0 -0
  436. /package/{src → plugins/tui}/history.ts +0 -0
@@ -0,0 +1,297 @@
1
+ // jade/approval:审批。tool.before 把路径统一成绝对路径,tool.gate 按模式和规则决定,要问时经 ui@1 问用户。
2
+ // auto 模式下规则判断不了、本来要问的调用先让模型审一次(review.ts):它只能放行或转给用户,不能替用户拒绝。
3
+ //
4
+ // 没有这个插件(停用、坏掉、被隔离)时,核心的兜底关卡拒绝所有非只读工具(第 7 节),所以这里出错不会放行。
5
+ // 用户选的"总是允许"记进日志(derived),恢复会话后仍然有效;模式是进程级的,来自配置,可以经 approval@1 改。
6
+
7
+ import path from "node:path";
8
+ import type { GatedToolCall, Message } from "uncarved";
9
+ import { definePlugin, type Caller, type SelectRequest, type UI } from "../../src/api.ts";
10
+ import type { Models } from "../models/index.ts";
11
+ import type { Renderers } from "../renderers/index.ts";
12
+ import { describeRule, MODES, policy, type AllowRule, type Mode } from "./policy.ts";
13
+ import { reviewer, type Review } from "./review.ts";
14
+
15
+ /** approval@1 */
16
+ export interface Approval {
17
+ mode(): Mode;
18
+ setMode(mode: Mode): void;
19
+ /** 读这个目录(绝对路径)里的文件不用问,例如 skill 的目录。返回撤销函数,调用方的作用域关闭时自动撤销。项目层插件不能用 */
20
+ allowRead(dir: string): () => void;
21
+ /** 这个目录(绝对路径)和工作目录同样对待:auto 模式下在里面改文件不用问,例如会话的临时目录。返回撤销函数,调用方的作用域关闭时自动撤销。项目层插件不能用 */
22
+ allowWrite(dir: string): () => void;
23
+ /**
24
+ * 登记一个审批渠道(例如聊天机器人):要问用户时,问题同时交给终端和所有渠道,先回答的算数,
25
+ * 其余的经 signal 收到中止。渠道返回 undefined、不认识的值或出错,算它不回答,不算拒绝;
26
+ * 终端里取消照旧算拒绝。有渠道时,不能提问的前端(-p)也会问。返回撤销函数,调用方的作用域关闭时自动撤销。
27
+ * 项目层插件不能用
28
+ */
29
+ addApprover(approver: Approver): () => void;
30
+ /**
31
+ * 这个只读调用(例如子 Agent 的)在会话 session 里能不能不问就执行:按该会话"总是允许"的规则、
32
+ * allowRead/allowWrite 登记的目录和 yolo 模式判断。会话不存在或不是只读调用时为 false
33
+ */
34
+ allows(session: string, call: GatedToolCall): boolean;
35
+ }
36
+
37
+ /** 审批的回答:允许一次、本会话里总是允许、拒绝 */
38
+ export type Answer = "once" | "always" | "deny";
39
+ export type Approver = (request: SelectRequest<Answer>, signal: AbortSignal) => Promise<Answer | undefined>;
40
+ const ANSWERS: readonly string[] = ["once", "always", "deny"] satisfies Answer[];
41
+
42
+ /** derived 里保存"总是允许"规则的键 */
43
+ const RULES_KEY = "jade/approval/rules";
44
+ /** 等用户回答的时限:内核要求 hook 有有限的超时,超时按拒绝处理 */
45
+ const ASK_TIMEOUT_MS = 24 * 60 * 60 * 1000;
46
+ const MAX_DETAIL_CHARS = 2000;
47
+ /** 等工具的审批预览的时限,过了就用默认的 detail */
48
+ const PREVIEW_TIMEOUT_MS = 5000;
49
+
50
+ /**
51
+ * 带 URL 的只读工具审查放行之后,完全相同的调用不再审查。不按主机记:同一主机上换一个路径或查询参数
52
+ * 就能把本地数据带出去,正是审查要拦的
53
+ */
54
+ const reviewedKey = (call: GatedToolCall): string | undefined => {
55
+ const url = (call.input as { url?: unknown } | null)?.url;
56
+ if (call.tool.effect !== "read" || typeof url !== "string") return undefined;
57
+ return `${call.name} ${JSON.stringify(call.input)}`;
58
+ };
59
+
60
+ let mode: Mode = "ask";
61
+ /** 配置里写错的模式:第一个会话打开时告诉用户(process 里可能还拿不到 ui@1:它的提供者可能排在后面激活) */
62
+ let badMode: string | undefined;
63
+ /** 经 allowRead 登记的目录;policy 每次判断时读它 */
64
+ const readRoots: string[] = [];
65
+ /** 经 allowWrite 登记的目录;policy 每次判断时读它 */
66
+ const writeRoots: string[] = [];
67
+ /** 经 addApprover 登记的审批渠道 */
68
+ const approvers = new Set<Approver>();
69
+ /** 打开着的会话:会话 id → 判断只读调用能不能不问就执行(allows) */
70
+ const sessionChecks = new Map<string, (call: GatedToolCall) => boolean>();
71
+
72
+ export default definePlugin({
73
+ process(ctx) {
74
+ const configured = ctx.config.mode;
75
+ if (typeof configured === "string" && (MODES as readonly string[]).includes(configured)) mode = configured as Mode;
76
+ else if (configured !== undefined) badMode = JSON.stringify(configured);
77
+ ctx.provide("approval@1", (caller): Approval => ({
78
+ mode: () => mode,
79
+ setMode(next: Mode) {
80
+ if (!(MODES as readonly string[]).includes(next)) throw new Error(`mode must be one of ${MODES.join(", ")}`);
81
+ mode = next;
82
+ },
83
+ allowRead: (dir: string) => allow(caller, "allowRead", readRoots, dir),
84
+ allowWrite: (dir: string) => allow(caller, "allowWrite", writeRoots, dir),
85
+ addApprover(approver: Approver) {
86
+ if (caller.layer === "project") throw new Error("approval.addApprover: project plugins cannot answer approvals");
87
+ if (typeof approver !== "function") throw new Error("approval.addApprover: approver must be a function");
88
+ approvers.add(approver);
89
+ const remove = () => void approvers.delete(approver);
90
+ caller.onDispose(remove);
91
+ return remove;
92
+ },
93
+ allows: (session: string, call: GatedToolCall) => call.tool?.effect === "read" && (sessionChecks.get(session)?.(call) ?? false),
94
+ }));
95
+ },
96
+
97
+ async session(ctx) {
98
+ const rules = policy({ cwd: ctx.cwd, readRoots, writeRoots });
99
+ const ui = ctx.service<UI>("ui@1");
100
+ if (badMode !== undefined) {
101
+ ui?.notify(`jade/approval: mode must be one of ${MODES.join(", ")}, got ${badMode}; using ask`, "warning");
102
+ badMode = undefined;
103
+ }
104
+ const renderers = ctx.service<Renderers>("renderers@1");
105
+ // auto 模式的审查用当前配置的模型;没有 models@1(模型插件被停用)或者配置里关掉时不做审查
106
+ const models = ctx.service<Models>("models@1");
107
+ const reviewing = models !== undefined && ctx.config.review !== false;
108
+ /** 最近一次请求里的消息:auto 模式的审查从中取用户最近的请求 */
109
+ const recent: { messages: readonly Message[] } = { messages: [] };
110
+ if (reviewing) {
111
+ ctx.kernel.hook({
112
+ kind: "transform",
113
+ point: "context.build",
114
+ fn: (req) => {
115
+ recent.messages = req.messages;
116
+ return req;
117
+ },
118
+ });
119
+ }
120
+ const review = reviewing ? reviewer({ models: models!, cwd: ctx.cwd, writeRoots: () => writeRoots, messages: () => recent.messages }) : undefined;
121
+ /** 本会话里审查过一次、放行了的调用 */
122
+ const reviewedCalls = new Set<string>();
123
+ let warned = false;
124
+ /** 本进程里刚选的"总是允许":并发的关卡拿到的 derived 是各自开始时的快照,可能还没有它 */
125
+ const added: AllowRule[] = [];
126
+ /** 一次只问一个问题;排在后面的问之前重新判断,前面刚选的"总是允许"可能已经覆盖它 */
127
+ let asking: Promise<unknown> = Promise.resolve();
128
+ /** 日志里记下的"总是允许"规则,每次调用工具前取一次:子 Agent 在工具执行期间经 allows 用它 */
129
+ let logged: AllowRule[] = [];
130
+ const id = ctx.session.id;
131
+ const check = (call: GatedToolCall) =>
132
+ rules.decide(call, { mode: mode === "yolo" ? "yolo" : "readonly", rules: [...logged, ...added] }).decision === "allow";
133
+ sessionChecks.set(id, check);
134
+ await ctx.effect(() => () => {
135
+ if (sessionChecks.get(id) === check) sessionChecks.delete(id);
136
+ });
137
+
138
+ ctx.kernel.hook({
139
+ kind: "transform",
140
+ point: "tool.before",
141
+ fn: (call, hook) => {
142
+ logged = (hook.derived[RULES_KEY] as AllowRule[] | undefined) ?? [];
143
+ return { ...call, input: rules.absolutePath(call.input) };
144
+ },
145
+ });
146
+ ctx.kernel.hook({
147
+ kind: "gate",
148
+ point: "tool.gate",
149
+ timeoutMs: ASK_TIMEOUT_MS,
150
+ fn: async (call, hook) => {
151
+ const saved = () => {
152
+ const logged = (hook.derived[RULES_KEY] as AllowRule[] | undefined) ?? [];
153
+ return [...logged, ...added.filter((r) => !logged.some((l) => JSON.stringify(l) === JSON.stringify(r)))];
154
+ };
155
+ const result = rules.decide(call, { mode, rules: saved() });
156
+ if (result.decision !== "ask") return result;
157
+ // auto 模式:规则判断不了、本来要问的调用先让模型审一次。审查只能放行或转给用户,不会替用户拒绝
158
+ let why: string | undefined;
159
+ if (review && mode === "auto") {
160
+ const key = reviewedKey(call);
161
+ if (key !== undefined && reviewedCalls.has(key)) return { decision: "allow", reason: "This exact call was already approved in this session." };
162
+ const verdict: Review = await review(call, hook.signal);
163
+ // 审查调用不经过 model.responded,用量只能记在这里,界面据此计入会话用量
164
+ if (verdict.usage) await hook.emit("reviewed", { toolUseId: call.toolUseId, usage: verdict.usage });
165
+ if (verdict.decision === "allow") {
166
+ if (key !== undefined) reviewedCalls.add(key);
167
+ return { decision: "allow", reason: verdict.reason };
168
+ }
169
+ why = verdict.reason;
170
+ }
171
+ if (!ui?.interactive && approvers.size === 0) {
172
+ if (!warned) {
173
+ warned = true;
174
+ ui?.notify(
175
+ `${call.name} needs approval, but this jade cannot ask. To let it make changes in the working directory, ` +
176
+ `set {"jade/approval": {"mode": "auto"}} in ${ctx.home}/config.json`,
177
+ "warning",
178
+ );
179
+ }
180
+ 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.` };
181
+ }
182
+ const turn = asking.then(async () => {
183
+ const again = rules.decide(call, { mode, rules: saved() });
184
+ if (again.decision !== "ask") return again;
185
+ const rule = rules.ruleFor(call);
186
+ const shown = (await preview(renderers, call)) ?? detail(call);
187
+ const answer = await ask(
188
+ ui,
189
+ {
190
+ title: `Allow ${call.name}?`,
191
+ // 审查转给用户的:先说为什么
192
+ detail: why ? `${why}\n\n${shown}` : shown,
193
+ options: [
194
+ { label: "Allow once", value: "once" },
195
+ { label: `Always allow ${describeRule(rule)} in this session`, value: "always" },
196
+ { label: "Deny", value: "deny" },
197
+ ],
198
+ },
199
+ hook.signal,
200
+ );
201
+ if (answer === "always") {
202
+ added.push(rule);
203
+ await hook.record(RULES_KEY, saved());
204
+ return { decision: "allow" as const };
205
+ }
206
+ if (answer === "once") return { decision: "allow" as const };
207
+ return { decision: "deny" as const, reason: "The user denied this tool call. Do not retry it unchanged: adjust, or ask what to do instead." };
208
+ });
209
+ asking = turn.catch(() => {});
210
+ return turn;
211
+ },
212
+ });
213
+ },
214
+ });
215
+
216
+ /** allowRead、allowWrite:把目录登记进 roots,调用方的作用域关闭时撤销 */
217
+ function allow(caller: Caller, name: string, roots: string[], dir: string): () => void {
218
+ if (caller.layer === "project") throw new Error(`approval.${name}: project plugins cannot widen what runs without asking`);
219
+ if (typeof dir !== "string" || !path.isAbsolute(dir)) throw new Error(`approval.${name}: dir must be an absolute path`);
220
+ const root = path.resolve(dir);
221
+ roots.push(root);
222
+ const remove = () => {
223
+ const i = roots.indexOf(root);
224
+ if (i !== -1) roots.splice(i, 1);
225
+ };
226
+ caller.onDispose(remove);
227
+ return remove;
228
+ }
229
+
230
+ /**
231
+ * 把问题同时交给终端(能提问时)和所有审批渠道,返回先到的回答,然后中止其余的。
232
+ * 终端里取消(undefined)算拒绝;渠道返回 undefined、不认识的值或出错算它不回答。都不回答时返回 undefined(拒绝)
233
+ */
234
+ async function ask(ui: UI | undefined, request: SelectRequest<Answer>, signal: AbortSignal): Promise<Answer | undefined> {
235
+ const done = new AbortController();
236
+ const stop = () => done.abort(signal.reason);
237
+ signal.addEventListener("abort", stop, { once: true });
238
+ try {
239
+ return await new Promise<Answer | undefined>((resolve, reject) => {
240
+ const channels: Promise<Answer | undefined | typeof NONE>[] = [];
241
+ if (ui?.interactive) channels.push(ui.select(request, done.signal).then((a) => (a !== undefined && ANSWERS.includes(a) ? a : "deny")));
242
+ for (const approver of approvers) {
243
+ channels.push(
244
+ Promise.resolve()
245
+ .then(() => approver(request, done.signal))
246
+ .then(
247
+ (a) => (typeof a === "string" && ANSWERS.includes(a) ? (a as Answer) : NONE),
248
+ () => NONE,
249
+ ),
250
+ );
251
+ }
252
+ let pending = channels.length;
253
+ if (pending === 0) return resolve(undefined);
254
+ for (const c of channels) {
255
+ c.then((a) => {
256
+ if (a !== NONE) resolve(a);
257
+ else if (--pending === 0) resolve(undefined);
258
+ }, reject);
259
+ }
260
+ });
261
+ } finally {
262
+ signal.removeEventListener("abort", stop);
263
+ done.abort(new Error("answered"));
264
+ }
265
+ }
266
+ const NONE = Symbol("no answer");
267
+
268
+ /**
269
+ * 工具自己登记的审批预览(例如文件修改的 diff)。没有登记、返回的不是文字、或者出错时返回 undefined,
270
+ * 用下面的 detail:预览是别的插件的代码,它坏了不能让审批卡住或失败
271
+ */
272
+ async function preview(renderers: Renderers | undefined, call: GatedToolCall): Promise<string | undefined> {
273
+ let timer: ReturnType<typeof setTimeout> | undefined;
274
+ try {
275
+ // 预览可能读文件、算 diff;一直不返回时也要能问用户
276
+ const late = new Promise<undefined>((resolve) => {
277
+ timer = setTimeout(() => resolve(undefined), PREVIEW_TIMEOUT_MS);
278
+ });
279
+ const text = await Promise.race([Promise.resolve(renderers?.forTool(call.name)?.renderer.preview?.(call.input)), late]);
280
+ return typeof text === "string" ? text : undefined;
281
+ } catch {
282
+ return undefined;
283
+ } finally {
284
+ clearTimeout(timer);
285
+ }
286
+ }
287
+
288
+ /** 给用户看的调用内容:命令、路径和要写的内容,太长的截断 */
289
+ function detail(call: GatedToolCall): string {
290
+ const input = call.input as Record<string, unknown> | null;
291
+ let text: string;
292
+ if (typeof input?.command === "string") text = input.command;
293
+ else if (typeof input?.path === "string" && typeof input.content === "string") text = `${input.path}\n\n${input.content}`;
294
+ else if (typeof input?.path === "string" && typeof input.old_string === "string") text = `${input.path}\n\n- ${input.old_string}\n+ ${String(input.new_string)}`;
295
+ else text = JSON.stringify(input, null, 2);
296
+ return text.length > MAX_DETAIL_CHARS ? `${text.slice(0, MAX_DETAIL_CHARS)}\n… (${text.length - MAX_DETAIL_CHARS} more characters)` : text;
297
+ }
@@ -0,0 +1,18 @@
1
+ {
2
+ "id": "jade/approval",
3
+ "version": "0.4.0",
4
+ "api": "^1",
5
+ "entry": "./index.ts",
6
+ "provides": ["approval@1"],
7
+ "optional": ["ui@1", "renderers@1", "models@1"],
8
+ "config": {
9
+ "mode": {
10
+ "default": "ask",
11
+ "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"
12
+ },
13
+ "review": {
14
+ "default": true,
15
+ "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"
16
+ }
17
+ }
18
+ }
@@ -1,23 +1,19 @@
1
- // 权限插件:tool.before 把路径统一成绝对路径,tool.gate 按模式、工具的 effect、路径和规则决定。
1
+ // 审批规则:按模式、工具的 effect、路径和"总是允许"的规则决定一次工具调用是放行、拒绝还是问用户。
2
+ // 纯判断,不碰界面和日志;那些在 index.ts。
2
3
  //
3
4
  // 带 url 参数的只读工具(web_fetch)也要问:网页里的提示注入可以让模型把读到的内容拼进 URL 发出去。
4
- //
5
- // 模式和"总是允许"的规则由宿主用 Runtime.record 写进日志(derived),关卡从 ctx.derived 读取:
6
- // 决定只依赖日志里的东西和调用本身,恢复会话后设置仍然有效。
7
5
 
8
6
  import { realpathSync, statSync } from "node:fs";
9
7
  import path from "node:path";
10
- import type { GatedToolCall, GateResult, Plugin, Usage } from "uncarved";
8
+ import type { GatedToolCall, GateResult } from "uncarved";
11
9
  import { validate } from "./schema.ts";
12
10
 
13
- /** 用户可以选的权限模式 */
14
- export const MODES = ["ask", "auto", "plan", "yolo"] as const;
11
+ /**
12
+ * 权限模式。ask:改东西先问;auto:工作目录里的改动和只建目录、碰文件的命令不问;
13
+ * plan:不改任何东西,拒绝时告诉模型先给出计划;readonly:不改任何东西(子 Agent 用);yolo:什么都不问
14
+ */
15
+ export const MODES = ["ask", "auto", "plan", "readonly", "yolo"] as const;
15
16
  export type Mode = (typeof MODES)[number];
16
- /** 关卡认识的模式:再加上只给子 Agent 用的 readonly */
17
- export type PolicyMode = Mode | "readonly";
18
-
19
- /** derived 中保存设置的键 */
20
- export const POLICY_KEY = "jade/policy";
21
17
 
22
18
  /**
23
19
  * 本会话内"总是允许"的规则。prefix、command 只用于 bash:prefix 匹配命令开头的整词,command 只匹配完全相同的命令。
@@ -42,41 +38,24 @@ export function describeRule(r: AllowRule): string {
42
38
  }
43
39
 
44
40
  export interface PolicySettings {
45
- mode: PolicyMode;
41
+ mode: Mode;
46
42
  rules: AllowRule[];
47
43
  }
48
44
 
49
45
  export interface PolicyOptions {
50
46
  cwd: string;
51
- /** 日志里还没有设置时使用 */
52
- mode?: PolicyMode;
53
- id?: string;
54
- /** 日志之外也要遵守的规则,每次判断时取(子 Agent 用主会话的规则) */
55
- rules?: () => AllowRule[];
56
- /** 工作目录之外也可以直接读取的目录(skill 的目录),只影响只读工具 */
47
+ /** 工作目录之外也可以直接读取的目录,只影响只读工具 */
57
48
  readRoots?: string[];
58
- /**
59
- * 还没记进日志的模式:运行中切换模式时日志正被这一轮占着写不进去,宿主先放在这里让关卡立即按它判断,
60
- * 这一轮结束后再记进日志。关卡的每个决定都记在 tool.decided 里,所以不影响重建(I-5)
61
- */
62
- pendingMode?: () => Mode | undefined;
63
- /**
64
- * auto 模式下,规则判断不了、本来要问用户的调用交给它审:返回 allow 就不问,ask 照常问用户。
65
- * 不给时 auto 模式只比 ask 多了"工作目录里的改动不问"
66
- */
67
- review?: (call: GatedToolCall, signal: AbortSignal) => Promise<GateResult & { usage?: Usage }>;
49
+ /** 工作目录之外、和工作目录同样对待的目录(读、写、命令参数),例如会话的临时目录 */
50
+ writeRoots?: string[];
68
51
  }
69
52
 
70
- /** 审查要调用模型,内核默认 30 秒的 hook 时限不够(超时按拒绝处理);审查自己会更早放弃并改为问用户 */
71
- const REVIEW_HOOK_TIMEOUT_MS = 120_000;
72
-
73
53
  export interface Policy {
74
- plugin: Plugin;
75
- /** 当前设置:日志里记录的,没有就是默认值 */
76
- settings(derived: Readonly<Record<string, unknown>>): PolicySettings;
77
54
  /** 给"总是允许"一个默认规则:bash 取命令的前两个词,工作目录之外的路径取所在目录,URL 取主机,其他取工具名 */
78
55
  ruleFor(call: { name: string; input: unknown }): AllowRule;
79
56
  decide(call: GatedToolCall, settings: PolicySettings): GateResult;
57
+ /** 工具参数里的相对路径换成绝对路径,日志里记下的、关卡判断的都是确定的路径 */
58
+ absolutePath(input: unknown): unknown;
80
59
  }
81
60
 
82
61
  /** 白名单命令里会写文件或执行其他程序的参数 */
@@ -429,8 +408,6 @@ function real(p: string): string {
429
408
  }
430
409
 
431
410
  export function policy(opts: PolicyOptions): Policy {
432
- const id = opts.id ?? "jade/policy";
433
- const defaults: PolicySettings = { mode: opts.mode ?? "ask", rules: [] };
434
411
  /** p 在 base 目录里 */
435
412
  const within = (base: string, p: string) => {
436
413
  // 按真实路径比较:目录里指向外面的符号链接也算外面
@@ -438,7 +415,7 @@ export function policy(opts: PolicyOptions): Policy {
438
415
  // 只有 ".." 这一段才表示上级目录,名为 "..foo" 的目录仍在里面
439
416
  return rel !== ".." && !rel.startsWith(`..${path.sep}`) && !path.isAbsolute(rel);
440
417
  };
441
- const inside = (p: string) => within(opts.cwd, p);
418
+ const inside = (p: string) => within(opts.cwd, p) || (opts.writeRoots ?? []).some((r) => within(r, p));
442
419
  /** glob 的 pattern 是绝对路径或含 ".." 段时,匹配范围会超出 path */
443
420
  const globEscapes = (pattern: string) => path.isAbsolute(pattern) || pattern.split(/[\\/]/).includes("..");
444
421
  /** 以 "." 或 "[" 开头的通配段可能匹配到 ".."(取决于 bash 版本和选项),按越界处理 */
@@ -493,15 +470,10 @@ export function policy(opts: PolicyOptions): Policy {
493
470
  const bashGate = (r: "inside" | "outside" | undefined): GateResult | undefined =>
494
471
  r === undefined ? undefined : { decision: r === "outside" ? "ask" : "allow" };
495
472
 
496
- const self: Policy = {
497
- settings(derived) {
498
- const stored = structuredClone((derived[POLICY_KEY] as PolicySettings | undefined) ?? defaults);
499
- // 旧版本记下的模式:auto-edit 并进了 auto;readonly 不再给用户选,换成同样不改东西的 plan
500
- const legacy = stored.mode as string;
501
- if (legacy === "auto-edit") stored.mode = "auto";
502
- else if (legacy === "readonly" && derived[POLICY_KEY] !== undefined) stored.mode = "plan";
503
- const pending = opts.pendingMode?.();
504
- return pending ? { ...stored, mode: pending } : stored;
473
+ return {
474
+ absolutePath(input) {
475
+ if (!input || typeof input !== "object" || typeof (input as { path?: unknown }).path !== "string") return input;
476
+ return { ...input, path: path.resolve(opts.cwd, (input as { path: string }).path) };
505
477
  },
506
478
  ruleFor(call) {
507
479
  if (call.name === "bash") return bashRule(String((call.input as { command?: unknown }).command ?? ""));
@@ -542,7 +514,7 @@ export function policy(opts: PolicyOptions): Policy {
542
514
  if (r.host !== undefined) return network && hostOf(input.url!) === r.host;
543
515
  return !outside;
544
516
  };
545
- const allRules = [...rules, ...(opts.rules?.() ?? [])];
517
+ const allRules = rules;
546
518
  const ruled = allRules.some(covers);
547
519
  /** 复合命令里的一条简单命令被 bash 规则覆盖 */
548
520
  const ruledWords = (words: Word[]) =>
@@ -570,7 +542,7 @@ export function policy(opts: PolicyOptions): Policy {
570
542
  decision: "deny",
571
543
  reason:
572
544
  mode === "plan"
573
- ? `The session is in plan mode, so ${call.name} is not allowed yet. Finish investigating, then present your plan and wait for the user to approve it.`
545
+ ? `The session is in plan mode, so ${call.name} is not allowed yet. Finish investigating, then present your plan for the user to approve as the plan mode instructions describe (with propose_plan when you have it).`
574
546
  : `The session is in read-only mode, so ${call.name} is not allowed. Describe the change instead of making it.`,
575
547
  };
576
548
  }
@@ -580,40 +552,5 @@ export function policy(opts: PolicyOptions): Policy {
580
552
  const gate = isBash ? bashGate(classifyBash(command, { edits: mode === "auto", ruled: ruledWords })) : undefined;
581
553
  return gate ?? { decision: "ask" };
582
554
  },
583
- plugin: {
584
- id,
585
- version: "0.3.0",
586
- kernel: "^0.1",
587
- // log:emit:auto 模式的审查把用掉的 token 记进日志
588
- needs: ["transform:tool.before", "gate:tool.gate", "log:emit"],
589
- hooks: [
590
- {
591
- kind: "transform",
592
- point: "tool.before",
593
- // 让日志里的 tool.decided 记录的是确定的绝对路径,关卡也按它判断
594
- fn: (call) => {
595
- const input = call.input as { path?: unknown } | null;
596
- if (!input || typeof input !== "object" || typeof input.path !== "string") return;
597
- return { ...call, input: { ...input, path: path.resolve(opts.cwd, input.path) } };
598
- },
599
- },
600
- {
601
- kind: "gate",
602
- point: "tool.gate",
603
- timeoutMs: REVIEW_HOOK_TIMEOUT_MS,
604
- fn: async (call, ctx) => {
605
- const settings = self.settings(ctx.derived);
606
- const result = self.decide(call, settings);
607
- // 决定记在 tool.decided 里(I-5),重建时不会再审一遍
608
- if (settings.mode !== "auto" || result.decision !== "ask" || !opts.review) return result;
609
- const { usage, ...verdict } = await opts.review(call, ctx.signal);
610
- // 审查调用不经过 model.responded,用量只能记在这里(和压缩一样),界面据此计入会话用量
611
- if (usage) await ctx.emit("reviewed", { toolUseId: call.toolUseId, usage });
612
- return verdict;
613
- },
614
- },
615
- ],
616
- },
617
555
  };
618
- return self;
619
556
  }