@uncarved/jade 0.1.3 → 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 (450) hide show
  1. package/bin/jade.js +5 -27
  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 -30
  18. package/dist/index.js +11 -30
  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 +159 -1362
  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 +2 -0
  57. package/dist/update.js +6 -3
  58. package/dist/update.js.map +1 -1
  59. package/package.json +10 -8
  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 -100
  63. package/{src/plugins → plugins/approval}/review.ts +62 -16
  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 +48 -38
  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 +73 -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 +2 -2
  81. package/{src/tools → plugins/fs}/fs.ts +19 -42
  82. package/{src/tools → plugins/fs}/grep.ts +1 -1
  83. package/plugins/fs/index.ts +34 -0
  84. package/plugins/fs/plugin.json +7 -0
  85. package/{src/ui → plugins/fs}/renderers.ts +25 -70
  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 +16 -119
  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 +31 -20
  141. package/{src → plugins/shell}/sys.ts +2 -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 +3 -0
  155. package/plugins/tui/frontend.ts +596 -0
  156. package/plugins/tui/index.ts +37 -0
  157. package/plugins/tui/mentions.ts +113 -0
  158. package/plugins/tui/plugin.json +10 -0
  159. package/{src/ui → plugins/tui}/render.ts +8 -2
  160. package/{src/ui → plugins/tui}/screen.ts +8 -3
  161. package/{src/ui → plugins/tui}/transcript.ts +74 -99
  162. package/{src/ui/tui.tsx → plugins/tui/tui.ts} +358 -387
  163. package/{src/tools → plugins/undo}/checkpoint.ts +21 -60
  164. package/plugins/undo/index.ts +139 -0
  165. package/plugins/undo/notes.ts +43 -0
  166. package/plugins/undo/plugin.json +7 -0
  167. package/plugins/undo/style.ts +17 -0
  168. package/plugins/update/index.ts +40 -0
  169. package/plugins/update/plugin.json +13 -0
  170. package/plugins/web/env.ts +78 -0
  171. package/plugins/web/index.ts +133 -0
  172. package/plugins/web/plugin.json +15 -0
  173. package/plugins/web/renderers.ts +11 -0
  174. package/{src/tools → plugins/web}/web.ts +58 -26
  175. package/plugins-dist/approval/index.js +271 -0
  176. package/plugins-dist/approval/plugin.json +24 -0
  177. package/{dist/plugins → plugins-dist/approval}/policy.js +15 -81
  178. package/{dist/plugins → plugins-dist/approval}/review.js +56 -10
  179. package/{dist/plugins → plugins-dist/approval}/schema.js +0 -1
  180. package/plugins-dist/ask/index.js +145 -0
  181. package/plugins-dist/ask/plugin.json +12 -0
  182. package/plugins-dist/budget/index.js +37 -0
  183. package/plugins-dist/budget/plugin.json +15 -0
  184. package/{dist/plugins → plugins-dist/checks}/checks.js +46 -35
  185. package/plugins-dist/checks/index.js +150 -0
  186. package/plugins-dist/checks/plugin.json +21 -0
  187. package/plugins-dist/checks/project.js +76 -0
  188. package/plugins-dist/commands/index.js +33 -0
  189. package/plugins-dist/commands/plugin.json +9 -0
  190. package/{dist/plugins → plugins-dist/compact}/compact.js +51 -33
  191. package/plugins-dist/compact/index.js +100 -0
  192. package/plugins-dist/compact/plugin.json +25 -0
  193. package/plugins-dist/compact/style.js +14 -0
  194. package/plugins-dist/continue/index.js +57 -0
  195. package/plugins-dist/continue/plugin.json +15 -0
  196. package/{dist/ui → plugins-dist/fs}/diff.js +2 -3
  197. package/{dist/tools → plugins-dist/fs}/fs.js +17 -42
  198. package/{dist/tools → plugins-dist/fs}/grep.js +1 -2
  199. package/plugins-dist/fs/index.js +36 -0
  200. package/plugins-dist/fs/plugin.json +10 -0
  201. package/{dist/ui → plugins-dist/fs}/renderers.js +24 -61
  202. package/plugins-dist/fs/style.js +15 -0
  203. package/plugins-dist/fs/sys.js +54 -0
  204. package/plugins-dist/keys/index.js +36 -0
  205. package/plugins-dist/keys/plugin.json +9 -0
  206. package/plugins-dist/mcp/index.js +187 -0
  207. package/{dist → plugins-dist/mcp}/mcp.js +34 -30
  208. package/plugins-dist/mcp/plugin.json +12 -0
  209. package/plugins-dist/mcp/project.js +90 -0
  210. package/plugins-dist/memory/index.js +94 -0
  211. package/{dist → plugins-dist/memory}/memory.js +21 -3
  212. package/plugins-dist/memory/notes.js +36 -0
  213. package/plugins-dist/memory/plugin.json +11 -0
  214. package/plugins-dist/memory/style.js +14 -0
  215. package/plugins-dist/mentions/attach.js +120 -0
  216. package/plugins-dist/mentions/index.js +69 -0
  217. package/plugins-dist/mentions/plugin.json +9 -0
  218. package/plugins-dist/mentions/style.js +14 -0
  219. package/plugins-dist/models/config.js +53 -0
  220. package/plugins-dist/models/configure.js +415 -0
  221. package/plugins-dist/models/context.js +27 -0
  222. package/plugins-dist/models/index.js +167 -0
  223. package/plugins-dist/models/plugin.json +14 -0
  224. package/{dist → plugins-dist/models}/provider.js +18 -81
  225. package/plugins-dist/models/saved.js +80 -0
  226. package/plugins-dist/modes/index.js +190 -0
  227. package/plugins-dist/modes/plugin.json +18 -0
  228. package/plugins-dist/plugins/index.js +37 -0
  229. package/plugins-dist/plugins/plugin.json +10 -0
  230. package/plugins-dist/print/index.js +153 -0
  231. package/plugins-dist/print/plugin.json +14 -0
  232. package/plugins-dist/prompts/index.js +57 -0
  233. package/plugins-dist/prompts/plugin.json +13 -0
  234. package/plugins-dist/prompts/prompts.js +227 -0
  235. package/plugins-dist/prompts/sys.js +46 -0
  236. package/plugins-dist/renderers/index.js +36 -0
  237. package/plugins-dist/renderers/plugin.json +9 -0
  238. package/plugins-dist/repeats/index.js +165 -0
  239. package/plugins-dist/repeats/plugin.json +6 -0
  240. package/plugins-dist/schedule/cron.js +67 -0
  241. package/plugins-dist/schedule/index.js +281 -0
  242. package/plugins-dist/schedule/plugin.json +16 -0
  243. package/plugins-dist/schedule/store.js +125 -0
  244. package/plugins-dist/scratch/index.js +26 -0
  245. package/plugins-dist/scratch/plugin.json +10 -0
  246. package/plugins-dist/screenshot/index.js +35 -0
  247. package/plugins-dist/screenshot/plugin.json +11 -0
  248. package/plugins-dist/screenshot/sys.js +76 -0
  249. package/{dist/tools/screenshot.js → plugins-dist/screenshot/tool.js} +5 -4
  250. package/plugins-dist/sessions/index.js +136 -0
  251. package/plugins-dist/sessions/plugin.json +12 -0
  252. package/plugins-dist/shell/index.js +33 -0
  253. package/plugins-dist/shell/plugin.json +19 -0
  254. package/plugins-dist/shell/renderers.js +40 -0
  255. package/plugins-dist/shell/service.js +29 -0
  256. package/{dist/tools → plugins-dist/shell}/shell.js +31 -22
  257. package/{dist → plugins-dist/shell}/sys.js +2 -43
  258. package/plugins-dist/skills/index.js +90 -0
  259. package/plugins-dist/skills/plugin.json +12 -0
  260. package/plugins-dist/skills/project.js +47 -0
  261. package/{dist → plugins-dist/skills}/skills.js +3 -7
  262. package/plugins-dist/suggest/index.js +282 -0
  263. package/plugins-dist/suggest/plugin.json +23 -0
  264. package/plugins-dist/task/index.js +151 -0
  265. package/plugins-dist/task/plugin.json +23 -0
  266. package/plugins-dist/task/style.js +14 -0
  267. package/plugins-dist/task/subagent.js +208 -0
  268. package/{dist/tools/todo.js → plugins-dist/todo/index.js} +29 -7
  269. package/plugins-dist/todo/plugin.json +9 -0
  270. package/{dist/ui → plugins-dist/tui}/editor.js +3 -1
  271. package/plugins-dist/tui/frontend.js +586 -0
  272. package/{dist → plugins-dist/tui}/history.js +0 -1
  273. package/plugins-dist/tui/index.js +21 -0
  274. package/{dist/ui → plugins-dist/tui}/markdown.js +0 -1
  275. package/plugins-dist/tui/mentions.js +115 -0
  276. package/plugins-dist/tui/plugin.json +25 -0
  277. package/{dist/ui → plugins-dist/tui}/render.js +7 -3
  278. package/{dist/ui → plugins-dist/tui}/screen.js +6 -2
  279. package/{dist/ui → plugins-dist/tui}/transcript.js +76 -98
  280. package/{dist/ui → plugins-dist/tui}/tui.js +185 -53
  281. package/{dist/tools → plugins-dist/undo}/checkpoint.js +21 -55
  282. package/plugins-dist/undo/index.js +140 -0
  283. package/plugins-dist/undo/notes.js +36 -0
  284. package/plugins-dist/undo/plugin.json +9 -0
  285. package/plugins-dist/undo/style.js +14 -0
  286. package/plugins-dist/update/index.js +34 -0
  287. package/plugins-dist/update/plugin.json +15 -0
  288. package/plugins-dist/web/env.js +80 -0
  289. package/plugins-dist/web/index.js +124 -0
  290. package/plugins-dist/web/plugin.json +21 -0
  291. package/plugins-dist/web/renderers.js +7 -0
  292. package/{dist/tools → plugins-dist/web}/web.js +50 -24
  293. package/sdk/python/__pycache__/jade_plugin.cpython-312.pyc +0 -0
  294. package/sdk/python/jade_plugin.py +380 -0
  295. package/src/api.ts +298 -0
  296. package/src/config.ts +32 -134
  297. package/src/fetch.ts +216 -0
  298. package/src/hash.ts +39 -0
  299. package/src/host.ts +429 -0
  300. package/src/index.ts +23 -30
  301. package/src/install.ts +355 -0
  302. package/src/main.ts +155 -1387
  303. package/src/manifest.ts +160 -0
  304. package/src/membrane.ts +142 -0
  305. package/src/remote.ts +288 -0
  306. package/src/rescue.ts +217 -0
  307. package/src/resolve.ts +199 -0
  308. package/src/rpc.ts +144 -0
  309. package/src/secrets.ts +122 -0
  310. package/src/session.ts +458 -0
  311. package/src/source.ts +83 -0
  312. package/src/state.ts +120 -0
  313. package/src/update.ts +265 -262
  314. package/LICENSE +0 -21
  315. package/README.md +0 -204
  316. package/dist/commands.d.ts +0 -50
  317. package/dist/commands.js +0 -126
  318. package/dist/commands.js.map +0 -1
  319. package/dist/context.d.ts +0 -17
  320. package/dist/context.js +0 -53
  321. package/dist/context.js.map +0 -1
  322. package/dist/distro.d.ts +0 -141
  323. package/dist/distro.js +0 -462
  324. package/dist/distro.js.map +0 -1
  325. package/dist/history.d.ts +0 -10
  326. package/dist/history.js.map +0 -1
  327. package/dist/mcp.d.ts +0 -114
  328. package/dist/mcp.js.map +0 -1
  329. package/dist/memory.d.ts +0 -19
  330. package/dist/memory.js.map +0 -1
  331. package/dist/mentions.d.ts +0 -35
  332. package/dist/mentions.js +0 -130
  333. package/dist/mentions.js.map +0 -1
  334. package/dist/plugin-cli.d.ts +0 -16
  335. package/dist/plugin-cli.js +0 -294
  336. package/dist/plugin-cli.js.map +0 -1
  337. package/dist/plugins/budget.d.ts +0 -9
  338. package/dist/plugins/budget.js +0 -30
  339. package/dist/plugins/budget.js.map +0 -1
  340. package/dist/plugins/builtins.d.ts +0 -10
  341. package/dist/plugins/builtins.js +0 -25
  342. package/dist/plugins/builtins.js.map +0 -1
  343. package/dist/plugins/checks.d.ts +0 -71
  344. package/dist/plugins/checks.js.map +0 -1
  345. package/dist/plugins/compact.d.ts +0 -26
  346. package/dist/plugins/compact.js.map +0 -1
  347. package/dist/plugins/core.d.ts +0 -47
  348. package/dist/plugins/core.js +0 -229
  349. package/dist/plugins/core.js.map +0 -1
  350. package/dist/plugins/host.d.ts +0 -52
  351. package/dist/plugins/host.js +0 -115
  352. package/dist/plugins/host.js.map +0 -1
  353. package/dist/plugins/install.d.ts +0 -68
  354. package/dist/plugins/install.js +0 -377
  355. package/dist/plugins/install.js.map +0 -1
  356. package/dist/plugins/loader.d.ts +0 -410
  357. package/dist/plugins/loader.js +0 -407
  358. package/dist/plugins/loader.js.map +0 -1
  359. package/dist/plugins/policy.d.ts +0 -98
  360. package/dist/plugins/policy.js.map +0 -1
  361. package/dist/plugins/prompts.d.ts +0 -43
  362. package/dist/plugins/prompts.js +0 -284
  363. package/dist/plugins/prompts.js.map +0 -1
  364. package/dist/plugins/repeats.d.ts +0 -16
  365. package/dist/plugins/repeats.js +0 -151
  366. package/dist/plugins/repeats.js.map +0 -1
  367. package/dist/plugins/review.d.ts +0 -18
  368. package/dist/plugins/review.js.map +0 -1
  369. package/dist/plugins/schema.d.ts +0 -2
  370. package/dist/plugins/schema.js.map +0 -1
  371. package/dist/plugins/sessions.d.ts +0 -7
  372. package/dist/plugins/sessions.js +0 -110
  373. package/dist/plugins/sessions.js.map +0 -1
  374. package/dist/provider.d.ts +0 -165
  375. package/dist/provider.js.map +0 -1
  376. package/dist/session-lifecycle.d.ts +0 -61
  377. package/dist/session-lifecycle.js +0 -167
  378. package/dist/session-lifecycle.js.map +0 -1
  379. package/dist/session-scope.d.ts +0 -53
  380. package/dist/session-scope.js +0 -116
  381. package/dist/session-scope.js.map +0 -1
  382. package/dist/sessions.d.ts +0 -28
  383. package/dist/sessions.js +0 -73
  384. package/dist/sessions.js.map +0 -1
  385. package/dist/skills.d.ts +0 -37
  386. package/dist/skills.js.map +0 -1
  387. package/dist/sys.d.ts +0 -51
  388. package/dist/sys.js.map +0 -1
  389. package/dist/tools/ask.d.ts +0 -11
  390. package/dist/tools/ask.js +0 -62
  391. package/dist/tools/ask.js.map +0 -1
  392. package/dist/tools/checkpoint.d.ts +0 -43
  393. package/dist/tools/checkpoint.js.map +0 -1
  394. package/dist/tools/fs.d.ts +0 -39
  395. package/dist/tools/fs.js.map +0 -1
  396. package/dist/tools/grep.d.ts +0 -6
  397. package/dist/tools/grep.js.map +0 -1
  398. package/dist/tools/screenshot.d.ts +0 -15
  399. package/dist/tools/screenshot.js.map +0 -1
  400. package/dist/tools/shell.d.ts +0 -55
  401. package/dist/tools/shell.js.map +0 -1
  402. package/dist/tools/task.d.ts +0 -39
  403. package/dist/tools/task.js +0 -117
  404. package/dist/tools/task.js.map +0 -1
  405. package/dist/tools/todo.d.ts +0 -10
  406. package/dist/tools/todo.js.map +0 -1
  407. package/dist/tools/web.d.ts +0 -53
  408. package/dist/tools/web.js.map +0 -1
  409. package/dist/ui/configure.d.ts +0 -20
  410. package/dist/ui/configure.js +0 -447
  411. package/dist/ui/configure.js.map +0 -1
  412. package/dist/ui/diff.d.ts +0 -20
  413. package/dist/ui/diff.js.map +0 -1
  414. package/dist/ui/editor.d.ts +0 -41
  415. package/dist/ui/editor.js.map +0 -1
  416. package/dist/ui/markdown.d.ts +0 -22
  417. package/dist/ui/markdown.js.map +0 -1
  418. package/dist/ui/render.d.ts +0 -14
  419. package/dist/ui/render.js.map +0 -1
  420. package/dist/ui/renderers.d.ts +0 -8
  421. package/dist/ui/renderers.js.map +0 -1
  422. package/dist/ui/screen.d.ts +0 -118
  423. package/dist/ui/screen.js.map +0 -1
  424. package/dist/ui/transcript.d.ts +0 -46
  425. package/dist/ui/transcript.js.map +0 -1
  426. package/dist/ui/tui.d.ts +0 -47
  427. package/dist/ui/tui.js.map +0 -1
  428. package/src/commands.ts +0 -144
  429. package/src/context.ts +0 -64
  430. package/src/distro.ts +0 -577
  431. package/src/mentions.ts +0 -135
  432. package/src/plugin-cli.ts +0 -278
  433. package/src/plugins/budget.ts +0 -37
  434. package/src/plugins/builtins.ts +0 -34
  435. package/src/plugins/core.ts +0 -257
  436. package/src/plugins/host.ts +0 -146
  437. package/src/plugins/install.ts +0 -429
  438. package/src/plugins/loader.ts +0 -742
  439. package/src/plugins/prompts.ts +0 -327
  440. package/src/plugins/repeats.ts +0 -157
  441. package/src/plugins/sessions.ts +0 -109
  442. package/src/session-lifecycle.ts +0 -194
  443. package/src/session-scope.ts +0 -135
  444. package/src/sessions.ts +0 -78
  445. package/src/tools/ask.ts +0 -72
  446. package/src/tools/task.ts +0 -149
  447. package/src/ui/configure.ts +0 -471
  448. /package/{src/plugins → plugins/approval}/schema.ts +0 -0
  449. /package/{src → plugins/tui}/history.ts +0 -0
  450. /package/{src/ui → plugins/tui}/markdown.ts +0 -0
@@ -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,43 +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
- scratch?: string;
60
- /**
61
- * 还没记进日志的模式:运行中切换模式时日志正被这一轮占着写不进去,宿主先放在这里让关卡立即按它判断,
62
- * 这一轮结束后再记进日志。关卡的每个决定都记在 tool.decided 里,所以不影响重建(I-5)
63
- */
64
- pendingMode?: () => Mode | undefined;
65
- /**
66
- * auto 模式下,规则判断不了、本来要问用户的调用交给它审:返回 allow 就不问,ask 照常问用户。
67
- * 不给时 auto 模式只比 ask 多了"工作目录里的改动不问"
68
- */
69
- review?: (call: GatedToolCall, signal: AbortSignal) => Promise<GateResult & { usage?: Usage }>;
49
+ /** 工作目录之外、和工作目录同样对待的目录(读、写、命令参数),例如会话的临时目录 */
50
+ writeRoots?: string[];
70
51
  }
71
52
 
72
- /** 审查要调用模型,内核默认 30 秒的 hook 时限不够(超时按拒绝处理);审查自己会更早放弃并改为问用户 */
73
- const REVIEW_HOOK_TIMEOUT_MS = 120_000;
74
-
75
53
  export interface Policy {
76
- plugin: Plugin;
77
- /** 当前设置:日志里记录的,没有就是默认值 */
78
- settings(derived: Readonly<Record<string, unknown>>): PolicySettings;
79
54
  /** 给"总是允许"一个默认规则:bash 取命令的前两个词,工作目录之外的路径取所在目录,URL 取主机,其他取工具名 */
80
55
  ruleFor(call: { name: string; input: unknown }): AllowRule;
81
56
  decide(call: GatedToolCall, settings: PolicySettings): GateResult;
57
+ /** 工具参数里的相对路径换成绝对路径,日志里记下的、关卡判断的都是确定的路径 */
58
+ absolutePath(input: unknown): unknown;
82
59
  }
83
60
 
84
61
  /** 白名单命令里会写文件或执行其他程序的参数 */
@@ -431,8 +408,6 @@ function real(p: string): string {
431
408
  }
432
409
 
433
410
  export function policy(opts: PolicyOptions): Policy {
434
- const id = opts.id ?? "jade/policy";
435
- const defaults: PolicySettings = { mode: opts.mode ?? "ask", rules: [] };
436
411
  /** p 在 base 目录里 */
437
412
  const within = (base: string, p: string) => {
438
413
  // 按真实路径比较:目录里指向外面的符号链接也算外面
@@ -440,7 +415,7 @@ export function policy(opts: PolicyOptions): Policy {
440
415
  // 只有 ".." 这一段才表示上级目录,名为 "..foo" 的目录仍在里面
441
416
  return rel !== ".." && !rel.startsWith(`..${path.sep}`) && !path.isAbsolute(rel);
442
417
  };
443
- const inside = (p: string) => within(opts.cwd, p) || (opts.scratch !== undefined && within(opts.scratch, p));
418
+ const inside = (p: string) => within(opts.cwd, p) || (opts.writeRoots ?? []).some((r) => within(r, p));
444
419
  /** glob 的 pattern 是绝对路径或含 ".." 段时,匹配范围会超出 path */
445
420
  const globEscapes = (pattern: string) => path.isAbsolute(pattern) || pattern.split(/[\\/]/).includes("..");
446
421
  /** 以 "." 或 "[" 开头的通配段可能匹配到 ".."(取决于 bash 版本和选项),按越界处理 */
@@ -491,30 +466,14 @@ export function policy(opts: PolicyOptions): Policy {
491
466
  }
492
467
  return outside ? "outside" : "inside";
493
468
  };
494
- /**
495
- * auto 模式下审查放行过的"工具 + 主机",本会话里之后访问同一个主机不再审。
496
- * URL 带出数据要对方主机由攻击者控制,审查已经认可了这个主机,再逐个 URL 审收益很小、每次却要多等一次模型。
497
- * 只在内存里:恢复会话后重新审一次;每个决定照样记在 tool.decided 里(I-5)
498
- */
499
- const reviewedSites = new Set<string>();
500
- const reviewedSite = (call: GatedToolCall) => {
501
- const url = (call.input as { url?: unknown } | null)?.url;
502
- const host = call.tool.effect === "read" && typeof url === "string" ? hostOf(url) : undefined;
503
- return host ? `${call.name} ${host}` : undefined;
504
- };
505
469
  /** 把 classifyBash 的结果变成决定 */
506
470
  const bashGate = (r: "inside" | "outside" | undefined): GateResult | undefined =>
507
471
  r === undefined ? undefined : { decision: r === "outside" ? "ask" : "allow" };
508
472
 
509
- const self: Policy = {
510
- settings(derived) {
511
- const stored = structuredClone((derived[POLICY_KEY] as PolicySettings | undefined) ?? defaults);
512
- // 旧版本记下的模式:auto-edit 并进了 auto;readonly 不再给用户选,换成同样不改东西的 plan
513
- const legacy = stored.mode as string;
514
- if (legacy === "auto-edit") stored.mode = "auto";
515
- else if (legacy === "readonly" && derived[POLICY_KEY] !== undefined) stored.mode = "plan";
516
- const pending = opts.pendingMode?.();
517
- 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) };
518
477
  },
519
478
  ruleFor(call) {
520
479
  if (call.name === "bash") return bashRule(String((call.input as { command?: unknown }).command ?? ""));
@@ -555,7 +514,7 @@ export function policy(opts: PolicyOptions): Policy {
555
514
  if (r.host !== undefined) return network && hostOf(input.url!) === r.host;
556
515
  return !outside;
557
516
  };
558
- const allRules = [...rules, ...(opts.rules?.() ?? [])];
517
+ const allRules = rules;
559
518
  const ruled = allRules.some(covers);
560
519
  /** 复合命令里的一条简单命令被 bash 规则覆盖 */
561
520
  const ruledWords = (words: Word[]) =>
@@ -583,7 +542,7 @@ export function policy(opts: PolicyOptions): Policy {
583
542
  decision: "deny",
584
543
  reason:
585
544
  mode === "plan"
586
- ? `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).`
587
546
  : `The session is in read-only mode, so ${call.name} is not allowed. Describe the change instead of making it.`,
588
547
  };
589
548
  }
@@ -593,43 +552,5 @@ export function policy(opts: PolicyOptions): Policy {
593
552
  const gate = isBash ? bashGate(classifyBash(command, { edits: mode === "auto", ruled: ruledWords })) : undefined;
594
553
  return gate ?? { decision: "ask" };
595
554
  },
596
- plugin: {
597
- id,
598
- version: "0.3.0",
599
- kernel: "^0.1",
600
- // log:emit:auto 模式的审查把用掉的 token 记进日志
601
- needs: ["transform:tool.before", "gate:tool.gate", "log:emit"],
602
- hooks: [
603
- {
604
- kind: "transform",
605
- point: "tool.before",
606
- // 让日志里的 tool.decided 记录的是确定的绝对路径,关卡也按它判断
607
- fn: (call) => {
608
- const input = call.input as { path?: unknown } | null;
609
- if (!input || typeof input !== "object" || typeof input.path !== "string") return;
610
- return { ...call, input: { ...input, path: path.resolve(opts.cwd, input.path) } };
611
- },
612
- },
613
- {
614
- kind: "gate",
615
- point: "tool.gate",
616
- timeoutMs: REVIEW_HOOK_TIMEOUT_MS,
617
- fn: async (call, ctx) => {
618
- const settings = self.settings(ctx.derived);
619
- const result = self.decide(call, settings);
620
- // 决定记在 tool.decided 里(I-5),重建时不会再审一遍
621
- if (settings.mode !== "auto" || result.decision !== "ask" || !opts.review) return result;
622
- const site = reviewedSite(call);
623
- if (site && reviewedSites.has(site)) return { decision: "allow", reason: `${hostOf(String((call.input as { url: string }).url))} was already approved in this session` };
624
- const { usage, ...verdict } = await opts.review(call, ctx.signal);
625
- // 审查调用不经过 model.responded,用量只能记在这里(和压缩一样),界面据此计入会话用量
626
- if (usage) await ctx.emit("reviewed", { toolUseId: call.toolUseId, usage });
627
- if (site && verdict.decision === "allow") reviewedSites.add(site);
628
- return verdict;
629
- },
630
- },
631
- ],
632
- },
633
555
  };
634
- return self;
635
556
  }
@@ -1,31 +1,38 @@
1
1
  // auto 模式的审查:规则判断不了、本来要问用户的工具调用,先让模型按用户的请求判断有没有风险。
2
2
  // 只会放行或者转给用户,不会替用户拒绝;审查出错、超时、回答看不懂时都转给用户。
3
3
  // 审查的结论作为关卡决定记在 tool.decided 里(I-5),恢复会话、重建时不会再审一遍。
4
+ //
5
+ // 从旧 jade 的 plugins/review.ts 移植:模型从 models@1 取(不再由宿主传入),会话消息由 approval 的
6
+ // context.build hook 抄一份。
4
7
 
5
8
  import { readFile } from "node:fs/promises";
6
9
  import path from "node:path";
7
- import type { GatedToolCall, GateResult, Message, Provider, Usage } from "uncarved";
10
+ import type { GatedToolCall, GateResult, Message, ModelRequest, Usage } from "uncarved";
11
+ import type { Models } from "../models/index.ts";
8
12
 
9
13
  /** 审查的结论,加上这次审查用掉的 token(计入会话用量) */
10
14
  export type Review = GateResult & { usage?: Usage };
11
15
 
12
16
  export interface ReviewOptions {
13
- provider: Provider;
17
+ /** 用当前配置的模型(models@1) */
18
+ models: Models;
14
19
  cwd: string;
15
- /** 会话的临时目录,和工作目录一样对待 */
16
- scratch?: string;
20
+ /** 经 approval.allowWrite 登记、和工作目录同样对待的目录(例如会话的临时目录),每次审查时取 */
21
+ writeRoots?: () => readonly string[];
17
22
  /** 当前会话的消息:从里面取用户最近的请求 */
18
23
  messages: () => readonly Message[];
19
24
  /** 审查最多等多久,默认 60 秒;超时后转给用户 */
20
25
  timeoutMs?: number;
26
+ /** 第一次请求多久还没有任何输出就放弃、重发一次,默认 20 秒 */
27
+ startTimeoutMs?: number;
21
28
  }
22
29
 
23
30
  const SYSTEM =
24
31
  "You review actions that an AI coding agent wants to take on the user's computer, so the user does not have to approve each one by hand. " +
25
32
  "Decide whether the action can run without asking the user.\n\n" +
26
33
  "Answer allow when the action is a reasonable step toward what the user asked for and its effects are limited and recoverable, for example: " +
27
- "reading files or system information that is not secret; creating or changing files inside the working directory or the scratch directory; " +
28
- "running the project's builds, tests, linters, formatters, scripts or small inline scripts that only read data or write inside the working directory; " +
34
+ "reading files or system information that is not secret; creating or changing files inside the working directory or the other writable directories listed; " +
35
+ "running the project's builds, tests, linters, formatters, scripts or small inline scripts that only read data or write inside those directories; " +
29
36
  "installing the dependencies the project already declares; network requests that only fetch public data and do not send local files, code or secrets.\n\n" +
30
37
  "Answer ask when the action could: delete or overwrite data that cannot easily be restored (rm -rf outside build output, git reset --hard, git clean, git push --force, dropping databases); " +
31
38
  "change things outside the working directory or global/system state (global installs, system settings, services, scheduled tasks, registry, permissions, shell profiles); " +
@@ -101,15 +108,22 @@ export function parseVerdict(text: string): GateResult | undefined {
101
108
  return undefined;
102
109
  }
103
110
 
111
+ /** 经过膜的调用出错时包着插件的名字和调用点;用户要看的是原因 */
112
+ function reasonOf(err: unknown): string {
113
+ const e = err instanceof Error && err.name === "PluginError" && err.cause instanceof Error ? err.cause : err;
114
+ return clip(e instanceof Error ? e.message : String(e), 200);
115
+ }
116
+
104
117
  export function reviewer(opts: ReviewOptions): (call: GatedToolCall, signal: AbortSignal) => Promise<Review> {
105
118
  return async (call, signal) => {
106
119
  const messages = opts.messages();
107
120
  const { user, agent } = context(messages);
108
121
  const command = (call.input as { command?: unknown } | null)?.command;
109
122
  const files = typeof command === "string" ? await agentFiles(messages, opts.cwd, command) : [];
123
+ const origin = { by: "plugin" as const, id: "jade/approval" };
110
124
  const prompt = [
111
125
  `Working directory: ${opts.cwd}`,
112
- ...(opts.scratch ? [`Scratch directory (the agent's temporary files): ${opts.scratch}`] : []),
126
+ ...(opts.writeRoots?.() ?? []).map((d) => `Also writable like the working directory: ${d}`),
113
127
  `Platform: ${process.platform}`,
114
128
  "",
115
129
  "<user-requests>",
@@ -126,21 +140,53 @@ export function reviewer(opts: ReviewOptions): (call: GatedToolCall, signal: Abo
126
140
  `input: ${clip(JSON.stringify(call.input, null, 2), 6000)}`,
127
141
  "</action>",
128
142
  ].join("\n");
143
+ const request: ModelRequest = {
144
+ system: [{ text: SYSTEM, stability: "stable", origin, trust: "trusted" }],
145
+ messages: [{ role: "user", content: [{ kind: "text", text: prompt, origin, trust: "untrusted" }] }],
146
+ tools: [],
147
+ };
148
+ const totalMs = opts.timeoutMs ?? 60_000;
149
+ // 不用 AbortSignal.timeout:它的定时器不让进程保持运行,没有别的事在跑时(例如测试里)就永远等不到它
150
+ const expired = new AbortController();
151
+ const deadline = setTimeout(() => expired.abort(new Error("timed out")), totalMs);
152
+ const total = AbortSignal.any([signal, expired.signal]);
153
+ // 共享的模型服务有时让请求排很久的队才开始处理(实测同一个请求 3 秒到 90 多秒),一旦开始几秒内就答完。
154
+ // 所以第一次请求 startTimeoutMs 内还没有任何输出就放弃,重发一次;重发的那次只受总时限约束
155
+ let started = false;
156
+ let retried = false;
157
+ const waiting = new AbortController();
158
+ const timer = setTimeout(() => waiting.abort(), opts.startTimeoutMs ?? 20_000);
159
+ const onDelta = () => {
160
+ started = true;
161
+ clearTimeout(timer);
162
+ };
129
163
  try {
130
- const res = await opts.provider.complete(
131
- {
132
- system: [{ text: SYSTEM, stability: "stable", origin: { by: "plugin", id: "jade/policy" }, trust: "trusted" }],
133
- messages: [{ role: "user", content: [{ kind: "text", text: prompt, origin: { by: "plugin", id: "jade/policy" }, trust: "untrusted" }] }],
134
- tools: [],
135
- },
136
- { signal: AbortSignal.any([signal, AbortSignal.timeout(opts.timeoutMs ?? 60_000)]) },
137
- );
164
+ let res;
165
+ try {
166
+ res = await opts.models.complete(request, { signal: AbortSignal.any([total, waiting.signal]), onDelta });
167
+ } catch (err) {
168
+ if (!waiting.signal.aborted || total.aborted) throw err;
169
+ retried = true;
170
+ res = await opts.models.complete(request, { signal: total, onDelta });
171
+ }
138
172
  const text = res.content.flatMap((b) => (b.kind === "text" ? [b.text] : [])).join("\n");
139
173
  return { ...(parseVerdict(text) ?? { decision: "ask", reason: "The automatic review gave no clear answer." }), usage: res.usage };
140
174
  } catch (err) {
141
175
  // 用户中断:照样交回去,关卡的结果不会再被用到
142
176
  if (signal.aborted) throw err;
143
- return { decision: "ask", reason: `The automatic review failed: ${clip(err instanceof Error ? err.message : String(err), 200)}` };
177
+ if (total.aborted) {
178
+ const s = Math.round(totalMs / 1000);
179
+ return {
180
+ decision: "ask",
181
+ reason: started
182
+ ? `The automatic review timed out: the model service started answering but did not finish within ${s}s.`
183
+ : `The automatic review timed out: the model service did not start answering within ${s}s${retried ? ", also after a retry" : ""}.`,
184
+ };
185
+ }
186
+ return { decision: "ask", reason: `The automatic review failed: ${reasonOf(err)}` };
187
+ } finally {
188
+ clearTimeout(timer);
189
+ clearTimeout(deadline);
144
190
  }
145
191
  };
146
192
  }
@@ -0,0 +1,159 @@
1
+ // jade/ask:ask_user 工具。模型拿不准、而答案会改变它要做的事时,先问用户再动手。
2
+ //
3
+ // 每个问题给几个选项让用户选,也可以自己输入回答。对话框经 ui@1,不再由宿主私下传入。
4
+ // 前端不能提问(-p、非终端)时不提供这个工具,提示词里也就不会提到它(jade/prompts 按工具是否存在取舍)。
5
+ // 从旧 jade 的 tools/ask.ts 和 main.ts 的 askUser 移植。
6
+
7
+ import type { Tool } from "uncarved";
8
+ import { definePlugin, type UI } from "../../src/api.ts";
9
+ import type { Renderers, ToolRenderer } from "../renderers/index.ts";
10
+
11
+ export interface Question {
12
+ question: string;
13
+ options: { label: string; description?: string }[];
14
+ }
15
+
16
+ /** 问用户:每个问题一个回答;用户取消时返回 undefined */
17
+ export type AskUser = (questions: Question[], signal: AbortSignal) => Promise<string[] | undefined>;
18
+
19
+ const MAX_QUESTIONS = 4;
20
+ /** 选项的值是序号,"其他" 的值不会和它重复 */
21
+ const OTHER = "other";
22
+
23
+ export const DISMISSED =
24
+ "The user dismissed the questions without answering. Do not ask again: proceed with your best judgment and state your assumptions, or end your turn.";
25
+
26
+ /** 回到上一个问题 */
27
+ const BACK = "back";
28
+
29
+ /**
30
+ * 用 ui@1 逐个问题让用户选一项,或者选"其他"自己输入。第二个问题起可以回到上一个问题改答案(已经答过的选项标着);
31
+ * 自己输入时取消回到这个问题的选项。选项对话框取消就算没有回答。signal 中止时抛出
32
+ */
33
+ export function askVia(ui: UI): AskUser {
34
+ return async (questions, signal) => {
35
+ if (!ui.interactive) return undefined;
36
+ const answers: string[] = [];
37
+ let i = 0;
38
+ while (i < questions.length) {
39
+ const q = questions[i]!;
40
+ const previous = answers[i];
41
+ const typed = previous !== undefined && !q.options.some((o) => o.label === previous) ? previous : undefined;
42
+ const hint = (description: string | undefined, chosen: boolean) => {
43
+ const text = [description, chosen ? "your answer" : undefined].filter(Boolean).join(" · ");
44
+ return text ? { hint: text } : {};
45
+ };
46
+ const title = questions.length > 1 ? `${q.question} (${i + 1}/${questions.length})` : q.question;
47
+ const choice = await ui.select(
48
+ {
49
+ title,
50
+ options: [
51
+ ...q.options.map((o, k) => ({ label: o.label, value: String(k), ...hint(o.description, o.label === previous) })),
52
+ { label: "Other (type your answer)", value: OTHER, ...(typed ? { hint: `your answer: ${typed}` } : {}) },
53
+ ...(i > 0 ? [{ label: "← Previous question", value: BACK }] : []),
54
+ ],
55
+ },
56
+ signal,
57
+ );
58
+ signal.throwIfAborted();
59
+ if (choice === undefined) return undefined;
60
+ if (choice === BACK) {
61
+ i--;
62
+ continue;
63
+ }
64
+ const answer = choice === OTHER ? (await ui.input({ title: q.question, ...(typed ? { initial: typed } : {}) }, signal))?.trim() : q.options[Number(choice)]?.label;
65
+ signal.throwIfAborted();
66
+ // 自己输入时取消或什么都没写:回到这个问题重新选
67
+ if (!answer) continue;
68
+ answers[i] = answer;
69
+ i++;
70
+ }
71
+ return answers;
72
+ };
73
+ }
74
+
75
+ export function askUserTool(ask: AskUser): Tool {
76
+ return {
77
+ name: "ask_user",
78
+ description:
79
+ "Ask the user one to four questions and wait for the answers. Use it before starting work when the request is ambiguous in a way that changes what you would do " +
80
+ "(scope, approach, a trade-off or preference only the user can decide). Do not ask about things you can find out from the code, docs or tools, " +
81
+ "or that have a sensible default (pick it and say so). Each question offers 2-4 options; the user can also type their own answer. " +
82
+ "Put your recommended option first.",
83
+ inputSchema: {
84
+ type: "object",
85
+ properties: {
86
+ questions: {
87
+ type: "array",
88
+ items: {
89
+ type: "object",
90
+ properties: {
91
+ question: { type: "string", description: "The complete question, ending with a question mark" },
92
+ // 模型常给每个问题加一个短标题,名字不定;收下但不用,免得整个调用被拒
93
+ label: { type: "string", description: "Optional short tag; not shown" },
94
+ header: { type: "string", description: "Optional short tag; not shown" },
95
+ options: {
96
+ type: "array",
97
+ items: {
98
+ type: "object",
99
+ properties: {
100
+ label: { type: "string", description: "1-5 words" },
101
+ description: { type: "string", description: "What choosing it means, trade-offs" },
102
+ },
103
+ required: ["label"],
104
+ additionalProperties: false,
105
+ },
106
+ },
107
+ },
108
+ required: ["question", "options"],
109
+ additionalProperties: false,
110
+ },
111
+ },
112
+ },
113
+ required: ["questions"],
114
+ additionalProperties: false,
115
+ },
116
+ // 不碰文件和进程:所有模式(包括 plan)都不用批准
117
+ effect: "read",
118
+ concurrency: "exclusive",
119
+ idempotent: false,
120
+ async execute(input, ctx) {
121
+ const questions = (input as { questions?: unknown }).questions as Question[] | undefined;
122
+ if (!Array.isArray(questions) || questions.length === 0 || questions.length > MAX_QUESTIONS) return { content: `questions must have 1-${MAX_QUESTIONS} items`, isError: true };
123
+ const bad = questions.find((q) => !Array.isArray(q?.options) || q.options.length < 2 || q.options.length > 4);
124
+ if (bad) return { content: `each question needs 2-4 options ("${bad.question}" has ${Array.isArray(bad.options) ? bad.options.length : 0})`, isError: true };
125
+ const answers = await ask(questions, ctx.signal);
126
+ if (answers === undefined) return { content: DISMISSED };
127
+ return { content: questions.map((q, i) => `Q: ${q.question}\nA: ${answers[i] ?? "(no answer)"}`).join("\n\n") };
128
+ },
129
+ };
130
+ }
131
+
132
+ const clip = (s: string, n: number) => (s.length > n ? s.slice(0, n) + "…" : s);
133
+ const args = (input: unknown) => (input !== null && typeof input === "object" ? input : {}) as Record<string, unknown>;
134
+
135
+ export const askRenderer: ToolRenderer = {
136
+ tool: "ask_user",
137
+ summary: (input) => {
138
+ const q = args(input).questions;
139
+ return Array.isArray(q) && q.length === 1 ? clip(String((q[0] as { question?: unknown })?.question ?? ""), 120) : `${Array.isArray(q) ? q.length : 0} questions`;
140
+ },
141
+ // 结果显示用户的回答(旧 jade 每答一题在对话里记一行"问题 → 回答")
142
+ result: ({ text, isError }) => {
143
+ if (isError) return undefined;
144
+ if (text === DISMISSED) return { line: "dismissed" };
145
+ const pairs = [...text.matchAll(/^Q: (.*)\nA: (.*)$/gm)].map((m) => ({ q: m[1]!, a: m[2]! }));
146
+ if (!pairs.length) return undefined;
147
+ return { line: clip(pairs.map((p) => p.a).join(" · "), 200), ...(pairs.length > 1 ? { details: pairs.map((p) => `${p.q} → ${p.a}`).join("\n") } : {}) };
148
+ },
149
+ };
150
+
151
+ export default definePlugin({
152
+ process(ctx) {
153
+ ctx.service<Renderers>("renderers@1")?.tool(askRenderer);
154
+ },
155
+ session(ctx) {
156
+ const ui = ctx.require<UI>("ui@1");
157
+ if (ui.interactive) ctx.kernel.tool(askUserTool(askVia(ui)));
158
+ },
159
+ });
@@ -0,0 +1,8 @@
1
+ {
2
+ "id": "jade/ask",
3
+ "version": "0.2.0",
4
+ "api": "^1",
5
+ "entry": "./index.ts",
6
+ "requires": ["ui@1"],
7
+ "optional": ["renderers@1"]
8
+ }
@@ -0,0 +1,38 @@
1
+ // jade/budget:一轮里模型回复的次数达到上限就停下(turn.continue 关卡拒绝,这一轮以 stopped 结束)。
2
+ // 从旧 jade 的 plugins/budget.ts 移植;上限来自配置 maxSteps。
3
+
4
+ import type { State } from "uncarved";
5
+ import { definePlugin, type UI } from "../../src/api.ts";
6
+
7
+ const DEFAULT_STEPS = 100;
8
+
9
+ /** 本轮(最近一条用户输入之后)模型已经回复了几次 */
10
+ export function stepsThisTurn(s: State): number {
11
+ let steps = 0;
12
+ for (let i = s.messages.length - 1; i >= 0; i--) {
13
+ const m = s.messages[i]!;
14
+ if (m.role === "assistant") steps++;
15
+ else if (m.content.some((b) => b.kind !== "tool_result")) break;
16
+ }
17
+ return steps;
18
+ }
19
+
20
+ export default definePlugin({
21
+ session(ctx) {
22
+ const raw = ctx.config.maxSteps;
23
+ let max = DEFAULT_STEPS;
24
+ if (typeof raw === "number" && Number.isInteger(raw) && raw > 0) max = raw;
25
+ else if (raw !== undefined) ctx.service<UI>("ui@1")?.notify(`jade/budget: maxSteps must be a positive integer, got ${JSON.stringify(raw)}; using ${DEFAULT_STEPS}`, "warning");
26
+
27
+ ctx.kernel.hook({
28
+ kind: "gate",
29
+ point: "turn.continue",
30
+ fn: async (s, hook) => {
31
+ if (stepsThisTurn(s) < max) return { decision: "abstain" };
32
+ // 告诉用户为什么停下(前端把 <插件 id>/notice 显示成一行)
33
+ await hook.emit("notice", { text: `stopped after ${max} model responses in this turn (config maxSteps); send a message to continue`, level: "warning" });
34
+ return { decision: "deny" };
35
+ },
36
+ });
37
+ },
38
+ });
@@ -0,0 +1,13 @@
1
+ {
2
+ "id": "jade/budget",
3
+ "version": "0.2.0",
4
+ "api": "^1",
5
+ "entry": "./index.ts",
6
+ "optional": ["ui@1"],
7
+ "config": {
8
+ "maxSteps": {
9
+ "default": 100,
10
+ "description": "the most model responses in one turn (after one user message); the turn stops when it is reached"
11
+ }
12
+ }
13
+ }