@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
@@ -0,0 +1,140 @@
1
+ // jade/undo:/undo 把模型上一轮改过的文件恢复原样(再执行一次撤销更早的一轮)。
2
+ //
3
+ // jade/fs 不再保存检查点,这里自己观察:tool.before 在 write_file / edit_file / multi_edit 执行前记下文件原来的内容,
4
+ // tool.after 在执行成功后记下新内容的哈希,存成快照(checkpoint.ts)。tool.before 在审批之前执行,
5
+ // 所以等用户批准期间别人对文件的改动会算进"原来的内容"。
6
+ import { readFile } from "node:fs/promises";
7
+ import { realpathSync } from "node:fs";
8
+ import path from "node:path";
9
+ import { definePlugin } from "../../dist/api.js";
10
+ import { Checkpoints, lastTurnChanges, sha256 } from "./checkpoint.js";
11
+ import { Notes } from "./notes.js";
12
+ import { dim, green } from "./style.js";
13
+ /** 会改文件、参数里有 path 的工具 */
14
+ export const WRITE_TOOLS = new Set(["write_file", "edit_file", "multi_edit"]);
15
+ const notes = new Notes();
16
+ /** 显示用:工作目录内的路径用相对形式,统一为正斜杠 */
17
+ function display(cwd, full) {
18
+ const rel = path.relative(cwd, full);
19
+ const shown = rel && rel !== ".." && !rel.startsWith(`..${path.sep}`) && !path.isAbsolute(rel) ? rel : full;
20
+ return shown.split(path.sep).join("/");
21
+ }
22
+ function realPath(p) {
23
+ try {
24
+ return realpathSync.native(p);
25
+ }
26
+ catch {
27
+ return path.resolve(p);
28
+ }
29
+ }
30
+ /** 文件现在的内容;不存在时 null */
31
+ async function contentOf(file) {
32
+ try {
33
+ return await readFile(file, "utf8");
34
+ }
35
+ catch (e) {
36
+ if (e.code === "ENOENT")
37
+ return null;
38
+ throw e;
39
+ }
40
+ }
41
+ export default definePlugin({
42
+ process(ctx) {
43
+ const checkpoints = new Checkpoints(path.join(ctx.home, "checkpoints"));
44
+ const cwd = realPath(ctx.cwd);
45
+ ctx.service("commands@1")?.register({
46
+ name: "undo",
47
+ description: "restore every file the agent changed in its last turn (run again to go further back)",
48
+ async run(_args, { sessions, ui, signal }) {
49
+ const s = sessions.current;
50
+ if (!s)
51
+ return "No session is open.";
52
+ const undone = await checkpoints.undone(s.id);
53
+ const cps = lastTurnChanges(s.state.messages, await checkpoints.list(s.id), undone);
54
+ if (cps.length === 0)
55
+ return dim("Nothing to undo.");
56
+ /** 文件 → 这一轮最早的快照(恢复成它的 before);cps 是最新的在前 */
57
+ const files = new Map();
58
+ for (const cp of cps)
59
+ files.set(cp.path, cp);
60
+ // 恢复前就算好显示的名字:恢复时会删掉 agent 新建的文件。文件可能已经不在了(agent 删掉的):解析它所在的目录
61
+ const shown = new Map([...files.keys()].map((p) => [p, display(cwd, path.join(realPath(path.dirname(p)), path.basename(p)))]));
62
+ const show = (p) => shown.get(p) ?? display(cwd, p);
63
+ // 只有最新一次写入之后的内容能和文件现在的样子比较
64
+ const latest = new Map();
65
+ for (const cp of cps)
66
+ if (!latest.has(cp.path))
67
+ latest.set(cp.path, cp);
68
+ const changed = [];
69
+ for (const cp of latest.values())
70
+ if (!(await checkpoints.unchangedSince(cp)))
71
+ changed.push(show(cp.path));
72
+ const list = [...files.values()].map((cp) => ` ${cp.before === null ? "delete " : "restore"} ${show(cp.path)}`).join("\n");
73
+ if (files.size > 1 || changed.length > 0) {
74
+ const ok = await ui.select({
75
+ title: changed.length > 0
76
+ ? `${changed.join(", ")} changed since the agent wrote ${changed.length > 1 ? "them" : "it"}. Undo anyway and discard those changes too?`
77
+ : `Undo the agent's last turn of changes (${files.size} files)?`,
78
+ detail: list,
79
+ options: [
80
+ { label: "No", value: "no" },
81
+ { label: changed.length > 0 ? "Yes, undo anyway" : "Yes, undo", value: "yes" },
82
+ ],
83
+ }, signal);
84
+ if (ok !== "yes")
85
+ return;
86
+ }
87
+ // 最新的先恢复:同一个文件最后恢复成这一轮最早的 before
88
+ for (const cp of cps)
89
+ await checkpoints.restore(cp);
90
+ await checkpoints.markUndone(s.id, cps.map((c) => c.toolUseId));
91
+ const what = [...files.values()].map((cp) => cp.before === null ? `deleted ${show(cp.path)} (you had created it)` : `restored ${show(cp.path)} to its content before your changes`);
92
+ notes.add(s.id, `The user undid your changes from your last turn: ${what.join("; ")}. Read these files again before changing them.`);
93
+ return green(`Undid ${cps.length} change${cps.length > 1 ? "s" : ""} from the last turn:`) + "\n" + dim(list);
94
+ },
95
+ });
96
+ },
97
+ session(ctx) {
98
+ const checkpoints = new Checkpoints(path.join(ctx.home, "checkpoints"));
99
+ const sessionId = ctx.session.id;
100
+ /** toolUseId → 执行前的内容,执行成功后存成快照 */
101
+ const before = new Map();
102
+ ctx.kernel.hook({
103
+ kind: "transform",
104
+ point: "tool.before",
105
+ // 排在 jade/approval 把路径换成绝对路径之后;出错时只是没有快照,不影响工具执行
106
+ order: 50,
107
+ optional: true,
108
+ fn: async (call) => {
109
+ if (!WRITE_TOOLS.has(call.name))
110
+ return;
111
+ const p = call.input?.path;
112
+ if (typeof p !== "string")
113
+ return;
114
+ const full = path.resolve(ctx.cwd, p);
115
+ before.set(call.toolUseId, { tool: call.name, path: full, before: await contentOf(full) });
116
+ },
117
+ });
118
+ ctx.kernel.hook({
119
+ kind: "transform",
120
+ point: "tool.after",
121
+ optional: true,
122
+ fn: async (out) => {
123
+ const snap = before.get(out.call.toolUseId);
124
+ if (!snap)
125
+ return;
126
+ before.delete(out.call.toolUseId);
127
+ if (out.isError)
128
+ return;
129
+ const after = await contentOf(snap.path);
130
+ // 内容没变(例如同样的内容重复写入)不算修改
131
+ if (after === snap.before)
132
+ return;
133
+ await checkpoints.save(sessionId, { toolUseId: out.call.toolUseId, ...snap, afterHash: sha256(after ?? "") });
134
+ },
135
+ });
136
+ // 被拒绝、被中断的调用不经过 tool.after:一轮结束时还留着的都不会再用到,不然整个文件的内容一直占着内存
137
+ ctx.kernel.hook({ kind: "observe", point: "event", fn: (e) => void (e.type === "turn.ended" && before.clear()) });
138
+ ctx.kernel.hook(notes.hook(sessionId, ctx.plugin, ctx.plugin));
139
+ },
140
+ });
@@ -0,0 +1,36 @@
1
+ // 给模型的说明([Note from jade]):命令里做的事(例如用户撤销了模型改的文件)要让模型知道,
2
+ // 但命令拿不到会话日志,也不该替用户发一条消息。所以先记下来,下一次请求模型时在 context.project 里
3
+ // 附在最后一条消息后面,并用 ctx.record 写进日志(derived):之后的投影、恢复的会话里它都在同一个位置。
4
+ // 插件之间不共享代码,jade/memory 里也有一份。
5
+ export class Notes {
6
+ /** 会话 → 还没交给模型的说明 */
7
+ #pending = new Map();
8
+ add(sessionId, text) {
9
+ this.#pending.set(sessionId, [...(this.#pending.get(sessionId) ?? []), text]);
10
+ }
11
+ /** 会话里的 context.project hook;key 是 derived 里的键 */
12
+ hook(sessionId, plugin, key) {
13
+ return {
14
+ kind: "transform",
15
+ point: "context.project",
16
+ order: -40,
17
+ fn: async (messages, ctx) => {
18
+ let state = ctx.derived[key] ?? {};
19
+ const fresh = this.#pending.get(sessionId);
20
+ if (fresh?.length && messages.length > 0) {
21
+ const at = String(messages.length - 1);
22
+ state = { ...state, [at]: [...(state[at] ?? []), ...fresh] };
23
+ await ctx.record(key, state);
24
+ this.#pending.delete(sessionId);
25
+ }
26
+ return messages.map((m, i) => {
27
+ const notes = state[i];
28
+ if (!notes?.length || m.role !== "user")
29
+ return m;
30
+ const blocks = notes.map((text) => ({ kind: "text", text: `[Note from jade] ${text}`, origin: { by: "plugin", id: plugin }, trust: "trusted" }));
31
+ return { ...m, content: [...m.content, ...blocks] };
32
+ });
33
+ },
34
+ };
35
+ }
36
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "id": "jade/undo",
3
+ "version": "0.2.0",
4
+ "api": "^1",
5
+ "entry": "./index.js",
6
+ "optional": [
7
+ "commands@1"
8
+ ]
9
+ }
@@ -0,0 +1,14 @@
1
+ // 显示用的小工具:截断和 ANSI 颜色。插件之间不共享代码(只能共享类型),所以这里也有一份(同 jade/fs 的 style.ts)。
2
+ export const clip = (s, n) => (s.length > n ? s.slice(0, n) + "…" : s);
3
+ // 设了 NO_COLOR(非空)或标准输出不是终端时不输出颜色,见 https://no-color.org
4
+ const colors = Boolean(process.stdout.isTTY) && !process.env.NO_COLOR;
5
+ /**
6
+ * 每种样式用自己的关闭码,不用 \x1b[0m 全部重置:外面套着别的样式时,后面的文字仍保持外层样式。
7
+ * 里面出现同一个关闭码(例如 dim 里套 bold,两者都用 22 关闭)时紧接着重新打开外层的样式
8
+ */
9
+ const paint = (open, close) => (s) => colors ? `\x1b[${open}m${s.replaceAll(`\x1b[${close}m`, `\x1b[${close}m\x1b[${open}m`)}\x1b[${close}m` : s;
10
+ export const dim = paint("2", "22");
11
+ export const red = paint("31", "39");
12
+ export const green = paint("32", "39");
13
+ export const yellow = paint("33", "39");
14
+ export const bold = paint("1", "22");
@@ -0,0 +1,34 @@
1
+ // jade/update:启动时(每天最多一次)查 npm 上有没有更新的 jade,有就在后台升级,下次启动生效;
2
+ // 配置 auto 为 false 或 JADE_AUTO_UPDATE=off 时只提示。仓库里的开发版和 npm link 既不提示也不升级。
3
+ // 查询和升级都用核心的 src/update.ts,和 jade update 是同一套;不想要它就 jade plugins disable jade/update。
4
+ import { definePlugin } from "../../dist/api.js";
5
+ import { autoUpdate, autoUpdateEnabled, detectInstall, newerVersion, VERSION } from "../../dist/update.js";
6
+ /** 查一次,按结果提示;出什么错都不打扰用户 */
7
+ export async function checkForUpdate(o) {
8
+ const install = o.install ?? detectInstall();
9
+ if (install.kind === "dev")
10
+ return;
11
+ const latest = await newerVersion(o.home, o.latest ? { latest: o.latest } : {}).catch(() => undefined);
12
+ if (!latest)
13
+ return;
14
+ const manual = () => o.notify(`jade ${latest} is available (you have ${VERSION}); run jade update`);
15
+ if (!o.auto || !autoUpdateEnabled())
16
+ return manual();
17
+ const result = await autoUpdate(o.home, latest, { install, ...(o.command ? { command: o.command } : {}) }).catch(() => undefined);
18
+ if (result?.status === "installed")
19
+ o.notify(`jade ${latest} was installed in the background; restart jade to use it`);
20
+ else if (result?.status === "failed")
21
+ o.notify(`automatic update to jade ${latest} failed (see ${result.log}); run jade update`, "warning");
22
+ else if (result?.status !== "skipped" || result.why !== "busy")
23
+ manual();
24
+ }
25
+ export default definePlugin({
26
+ process(ctx) {
27
+ const ui = ctx.service("ui@1");
28
+ // 不能提问的前端(jade -p)是脚本在用,不提示也不升级
29
+ if (!ui?.interactive)
30
+ return;
31
+ // 作用域关闭后 ui 失效,再提示会抛错:那时也没人看了
32
+ void checkForUpdate({ home: ctx.home, auto: ctx.config.auto !== false, notify: (m, level) => ui.notify(m, level) }).catch(() => { });
33
+ },
34
+ });
@@ -0,0 +1,15 @@
1
+ {
2
+ "id": "jade/update",
3
+ "version": "0.1.0",
4
+ "api": "^1",
5
+ "entry": "./index.js",
6
+ "optional": [
7
+ "ui@1"
8
+ ],
9
+ "config": {
10
+ "auto": {
11
+ "default": true,
12
+ "description": "install a newer jade in the background (it takes effect on the next launch); false only tells you about it. $JADE_AUTO_UPDATE=off still works, and $JADE_UPDATE_CHECK=off turns the check off"
13
+ }
14
+ }
15
+ }
@@ -0,0 +1,80 @@
1
+ // 搜索服务的 API key:shell 里的环境变量 + $JADE_HOME/.env(shell 里已经设置的优先),和 jade/models 读同一个文件。
2
+ // 从旧 jade 的 config.ts 复制:插件之间不共享代码,jade/models 也有一份 parseEnv。
3
+ import { mkdir, readFile, writeFile } from "node:fs/promises";
4
+ import path from "node:path";
5
+ /** 解析 KEY=VALUE 格式:忽略空行和 # 注释,允许 export 前缀,去掉成对的引号(双引号里的 \n 换成换行) */
6
+ export function parseEnv(text) {
7
+ const out = {};
8
+ for (const raw of text.split(/\r?\n/)) {
9
+ const m = /^\s*(?:export\s+)?([A-Za-z_][A-Za-z0-9_]*)\s*=\s*(.*?)\s*$/.exec(raw);
10
+ if (!m)
11
+ continue;
12
+ let value = m[2];
13
+ const quote = value[0];
14
+ if ((quote === '"' || quote === "'") && value.length >= 2 && value.endsWith(quote)) {
15
+ value = value.slice(1, -1);
16
+ if (quote === '"')
17
+ value = value.replaceAll("\\n", "\n");
18
+ }
19
+ else {
20
+ // 未加引号的值里,空白之后的 # 是注释
21
+ value = value.replace(/\s+#.*$/, "");
22
+ }
23
+ out[m[1]] = value;
24
+ }
25
+ return out;
26
+ }
27
+ /** 配置文件里的变量,env 里已有的优先;文件不存在时就是 env */
28
+ export async function envWithFile(file, env = process.env) {
29
+ let text = "";
30
+ try {
31
+ text = await readFile(file, "utf8");
32
+ }
33
+ catch {
34
+ // 没有配置文件
35
+ }
36
+ return { ...parseEnv(text), ...Object.fromEntries(Object.entries(env).filter(([, v]) => v !== undefined)) };
37
+ }
38
+ /**
39
+ * 改写配置文件里的变量:已有的行原地替换,没有的追加在末尾,值为 undefined 的删除;注释和其他行保持不变。
40
+ * 同时更新 env,让改动在本次运行中生效
41
+ */
42
+ export async function updateEnvFile(file, updates, env) {
43
+ let text = "";
44
+ try {
45
+ text = await readFile(file, "utf8");
46
+ }
47
+ catch {
48
+ // 还没有配置文件
49
+ }
50
+ const lines = text ? text.replace(/\r?\n$/, "").split(/\r?\n/) : [];
51
+ const out = [];
52
+ const written = new Set();
53
+ for (const raw of lines) {
54
+ const key = /^\s*(?:export\s+)?([A-Za-z_][A-Za-z0-9_]*)\s*=/.exec(raw)?.[1];
55
+ if (!key || !(key in updates)) {
56
+ out.push(raw);
57
+ continue;
58
+ }
59
+ // 同一个键出现多次时只保留第一处
60
+ const value = updates[key];
61
+ if (value !== undefined && !written.has(key))
62
+ out.push(format(key, value));
63
+ written.add(key);
64
+ }
65
+ for (const [key, value] of Object.entries(updates)) {
66
+ if (value !== undefined && !written.has(key))
67
+ out.push(format(key, value));
68
+ }
69
+ await mkdir(path.dirname(file), { recursive: true });
70
+ await writeFile(file, out.join("\n") + "\n");
71
+ for (const [key, value] of Object.entries(updates)) {
72
+ if (value === undefined)
73
+ delete env[key];
74
+ else
75
+ env[key] = value;
76
+ }
77
+ }
78
+ function format(key, value) {
79
+ return /[\s#"']/.test(value) ? `${key}="${value.replaceAll("\n", "\\n")}"` : `${key}=${value}`;
80
+ }
@@ -0,0 +1,124 @@
1
+ // jade/web:web_fetch、web_search 工具和 /search 命令。
2
+ //
3
+ // 搜索服务的 API key 在 shell 的环境变量或 $JADE_HOME/.env 里(和 jade/models 同一个文件),/search 写进这个文件。
4
+ // web_search 总是注册,但只在配置了搜索服务时发给模型(context.build 里去掉):这样 /search 设置之后当前会话立即能用,
5
+ // 不用重开会话;会话的工具清单在创建时就定了。
6
+ import path from "node:path";
7
+ import { definePlugin } from "../../dist/api.js";
8
+ import { envWithFile, updateEnvFile } from "./env.js";
9
+ import { webRenderers } from "./renderers.js";
10
+ import { parseOrder, parseResults, SEARCH_PROVIDERS, webTools } from "./web.js";
11
+ // 设了 NO_COLOR(非空)或标准输出不是终端时不输出颜色,见 https://no-color.org
12
+ const colors = Boolean(process.stdout.isTTY) && !process.env.NO_COLOR;
13
+ const dim = (s) => (colors ? `\x1b[2m${s}\x1b[22m` : s);
14
+ const green = (s) => (colors ? `\x1b[32m${s}\x1b[39m` : s);
15
+ /**
16
+ * API key 所在的环境:每次开会话时重新读,/search 改了之后原地更新。模块每个进程只加载一次,进程级的命令和会话级的工具共用
17
+ */
18
+ let keys;
19
+ /** 撤销当前会话里"web_search 没打开"的提示词段落;/search 打开搜索后调用 */
20
+ let offNote;
21
+ const envFile = (ctx) => path.join(ctx.home, ".env");
22
+ /** 配置项,旧 jade 的环境变量 JADE_SEARCH、JADE_SEARCH_RESULTS 仍然有效(配置项优先);不合法时抛错 */
23
+ function settings(ctx, env) {
24
+ const fromConfig = ctx.config.search !== undefined && ctx.config.search !== null;
25
+ const order = parseOrder(fromConfig ? ctx.config.search : env.JADE_SEARCH, fromConfig ? "jade/web config search" : "JADE_SEARCH");
26
+ const counted = ctx.config.results !== undefined && ctx.config.results !== null;
27
+ const results = parseResults(counted ? ctx.config.results : env.JADE_SEARCH_RESULTS, counted ? "jade/web config results" : "JADE_SEARCH_RESULTS");
28
+ return { ...(order ? { order } : {}), results };
29
+ }
30
+ export default definePlugin({
31
+ process(ctx) {
32
+ const renderers = ctx.service("renderers@1");
33
+ if (renderers)
34
+ for (const r of webRenderers)
35
+ renderers.tool(r);
36
+ ctx.service("commands@1")?.register({
37
+ name: "search",
38
+ description: "set up web search services (TinyFish, AnySearch, Tavily, Exa, Firecrawl, Jina)",
39
+ async run(_args, c) {
40
+ const file = envFile(ctx);
41
+ const env = (keys ??= await envWithFile(file));
42
+ const on = SEARCH_PROVIDERS.filter((p) => env[p.env]);
43
+ const name = await c.ui.select({
44
+ title: on.length ? `Web search is on (${on.map((p) => p.name).join(", ")}; tried in order, the next one takes over on failure)` : "Web search is off",
45
+ options: SEARCH_PROVIDERS.map((p) => ({ label: `${p.name}${env[p.env] ? " ✓" : ""}`, value: p.name, hint: p.signup })),
46
+ }, c.signal);
47
+ const p = SEARCH_PROVIDERS.find((x) => x.name === name);
48
+ if (!p)
49
+ return;
50
+ // shell 里的变量盖过文件:改文件只在这个会话里看起来生效,下一个会话又变回 shell 里的值
51
+ if (process.env[p.env])
52
+ return `${p.env} is set in your shell environment, which takes precedence over ${file}; change or unset it there.`;
53
+ if (env[p.env]) {
54
+ const choice = await c.ui.select({
55
+ title: p.name,
56
+ options: [
57
+ { label: "Change the API key…", value: "set" },
58
+ { label: "Remove", value: "off", hint: `removes ${p.env} from ${file}` },
59
+ ],
60
+ }, c.signal);
61
+ if (!choice)
62
+ return;
63
+ if (choice === "off") {
64
+ await updateEnvFile(file, { [p.env]: undefined }, env);
65
+ return dim(`${p.name} removed.${on.length > 1 ? "" : " Web search is off."}`);
66
+ }
67
+ }
68
+ const key = (await c.ui.input({ title: `${p.name} API key`, mask: true }, c.signal))?.trim();
69
+ if (!key)
70
+ return;
71
+ await updateEnvFile(file, { [p.env]: key }, env);
72
+ offNote?.();
73
+ offNote = undefined;
74
+ return green(`Web search is on with ${p.name}: web_search uses it, and web_fetch falls back to it when a page cannot be fetched directly.`);
75
+ },
76
+ });
77
+ },
78
+ async session(ctx) {
79
+ const env = (keys = await envWithFile(envFile(ctx)));
80
+ let opts;
81
+ try {
82
+ opts = settings(ctx, env);
83
+ }
84
+ catch (e) {
85
+ // 写错的配置不让 web_fetch 也用不了:搜索按默认设置
86
+ ctx.service("ui@1")?.notify(`${e.message}; using the default search settings`, "warning");
87
+ opts = { results: parseResults(undefined, "") };
88
+ }
89
+ // keys 换成新的对象(新会话、/search 之前)时也取当前的那个
90
+ const web = webTools({ ...opts, env: () => keys ?? env });
91
+ for (const tool of web.tools)
92
+ ctx.kernel.tool(tool);
93
+ // 子 Agent(jade/task)也能查网页:另一套实例;web_search 只在配置了搜索服务时给它。
94
+ // web_fetch 带 url 参数,子 Agent 每次都要问用户(URL 能把读到的内容带出去)。
95
+ // jade/task 被隔离时它的服务已失效:子 Agent 没有 web 工具,web 工具本身照常
96
+ try {
97
+ const task = ctx.service("task@1");
98
+ if (task) {
99
+ const sub = webTools({ ...opts, env: () => keys ?? env });
100
+ for (const tool of sub.tools)
101
+ task.tool(tool, tool.name === "web_search" ? { when: () => sub.search().length > 0 } : {});
102
+ }
103
+ }
104
+ catch { }
105
+ ctx.kernel.hook({
106
+ kind: "transform",
107
+ point: "context.build",
108
+ fn: (req) => (web.search().length ? req : { ...req, tools: req.tools.filter((t) => t.name !== "web_search") }),
109
+ });
110
+ // 没有搜索时告诉模型用户可以打开它;有搜索时不用说
111
+ offNote = undefined;
112
+ if (web.search().length === 0 && ctx.service("commands@1")) {
113
+ const remove = ctx.service("prompts@1")?.add({ text: "- web_search is off; if you need to search the web, the user can turn it on with /search." });
114
+ if (remove) {
115
+ offNote = remove;
116
+ // 会话关闭时段落随作用域撤销,这里只忘掉它
117
+ await ctx.effect(() => () => {
118
+ if (offNote === remove)
119
+ offNote = undefined;
120
+ });
121
+ }
122
+ }
123
+ },
124
+ });
@@ -0,0 +1,21 @@
1
+ {
2
+ "id": "jade/web",
3
+ "version": "0.3.0",
4
+ "api": "^1",
5
+ "entry": "./index.js",
6
+ "optional": [
7
+ "ui@1",
8
+ "commands@1",
9
+ "prompts@1",
10
+ "renderers@1",
11
+ "task@1"
12
+ ],
13
+ "config": {
14
+ "search": {
15
+ "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"
16
+ },
17
+ "results": {
18
+ "description": "results per web_search, 1-20, default 10; $JADE_SEARCH_RESULTS still works"
19
+ }
20
+ }
21
+ }
@@ -0,0 +1,7 @@
1
+ // web_fetch、web_search 在对话里怎么显示(登记到 renderers@1)。从旧 jade 的 ui/renderers.ts 移植。
2
+ const clip = (s, n) => (s.length > n ? s.slice(0, n) + "…" : s);
3
+ const args = (input) => (input !== null && typeof input === "object" ? input : {});
4
+ export const webRenderers = [
5
+ { tool: "web_fetch", summary: (input) => clip(String(args(input).url ?? ""), 120) },
6
+ { tool: "web_search", summary: (input) => clip(String(args(input).query ?? ""), 120) },
7
+ ];
@@ -8,7 +8,9 @@
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
  import { lookup as dnsLookup } from "node:dns/promises";
13
15
  import { isIP } from "node:net";
14
16
  import { Parser } from "htmlparser2";
@@ -28,13 +30,13 @@ const MAX_RESULTS = 20;
28
30
  const USER_AGENT = "Mozilla/5.0 (compatible; jade/0.1; +https://github.com/MochiNek0/uncarved)";
29
31
  const defaultLookup = async (hostname) => (await dnsLookup(hostname, { all: true })).map((a) => a.address);
30
32
  export function webTools(opts = {}) {
31
- const env = opts.env ?? process.env;
33
+ const env = typeof opts.env === "function" ? opts.env : () => opts.env ?? process.env;
32
34
  const fetchImpl = opts.fetch ?? fetch;
33
- const services = backends(env, fetchImpl);
34
- const tools = [webFetchTool(fetchImpl, opts.lookup ?? defaultLookup, services.filter((s) => s.read))];
35
- if (services.length)
36
- tools.push(webSearchTool(services, resultCount(env)));
37
- return { tools };
35
+ if (opts.order)
36
+ checkOrder(opts.order);
37
+ const services = () => backends(env(), opts.order, fetchImpl);
38
+ const tools = [webFetchTool(fetchImpl, opts.lookup ?? defaultLookup, () => services().filter((s) => s.read)), webSearchTool(services, opts.results ?? DEFAULT_RESULTS)];
39
+ return { tools, search: () => services().map((s) => s.name) };
38
40
  }
39
41
  /** 网页正文少于这么多字符时算 thin */
40
42
  const THIN_CHARS = 200;
@@ -89,7 +91,7 @@ function webFetchTool(fetchImpl, lookup, readers) {
89
91
  // 直接下载被拦、出错或只拿到 JS 外壳时,交给能读网页的服务;404 这类明确的结果直接返回
90
92
  const failures = [];
91
93
  if ("content" in direct ? direct.retry : direct.thin) {
92
- for (const r of readers) {
94
+ for (const r of readers()) {
93
95
  try {
94
96
  page = { at: Date.now(), url: target.href, via: r.name, text: await r.read(target.href, signal) };
95
97
  break;
@@ -550,29 +552,51 @@ export const SEARCH_PROVIDERS = [
550
552
  },
551
553
  ];
552
554
  /**
553
- * 配置了 key 的服务,按调用顺序。JADE_SEARCH 是逗号分隔的服务名,决定顺序和范围(没 key 的跳过);
554
- * 不设时用所有配了 key 的服务,按 SEARCH_PROVIDERS 的顺序
555
+ * 配置了 key 的服务,按调用顺序。order 是服务名,决定顺序和范围(没 key 的跳过);
556
+ * 不给时用所有配了 key 的服务,按 SEARCH_PROVIDERS 的顺序
557
+ */
558
+ function backends(env, order, fetchImpl) {
559
+ const list = order?.length ? order.map((n) => SEARCH_PROVIDERS.find((p) => p.name === n)) : SEARCH_PROVIDERS;
560
+ return list.flatMap((p) => (env[p.env] ? [p.make(env[p.env], fetchImpl)] : []));
561
+ }
562
+ function checkOrder(order) {
563
+ const unknown = order.filter((n) => !SEARCH_PROVIDERS.some((p) => p.name === n));
564
+ if (unknown.length)
565
+ throw new Error(`unknown search service ${unknown.join(", ")}; choose from ${SEARCH_PROVIDERS.map((p) => p.name).join(", ")}`);
566
+ }
567
+ /**
568
+ * 配置项 search(或旧 jade 的 JADE_SEARCH):逗号分隔的服务名或服务名的数组。不设时返回 undefined;
569
+ * 不认识的服务名抛错,错误信息里带来源 label
555
570
  */
556
- function backends(env, fetchImpl) {
557
- const named = env.JADE_SEARCH?.split(",").map((s) => s.trim().toLowerCase()).filter(Boolean);
558
- const unknown = named?.filter((n) => !SEARCH_PROVIDERS.some((p) => p.name === n));
559
- if (unknown?.length)
560
- throw new Error(`JADE_SEARCH: unknown service ${unknown.join(", ")}; choose from ${SEARCH_PROVIDERS.map((p) => p.name).join(", ")}`);
561
- const order = named?.length ? named.map((n) => SEARCH_PROVIDERS.find((p) => p.name === n)) : SEARCH_PROVIDERS;
562
- return order.flatMap((p) => (env[p.env] ? [p.make(env[p.env], fetchImpl)] : []));
571
+ export function parseOrder(value, label) {
572
+ if (value === undefined || value === null || value === "")
573
+ return undefined;
574
+ const list = typeof value === "string" ? value.split(",") : Array.isArray(value) && value.every((v) => typeof v === "string") ? value : undefined;
575
+ if (!list)
576
+ throw new Error(`${label} must be a comma-separated list of search services, got ${JSON.stringify(value)}`);
577
+ const named = list.map((s) => s.trim().toLowerCase()).filter(Boolean);
578
+ try {
579
+ checkOrder(named);
580
+ }
581
+ catch (e) {
582
+ throw new Error(`${label}: ${e.message}`);
583
+ }
584
+ return named.length ? named : undefined;
563
585
  }
564
- /** JADE_SEARCH_RESULTS:每次搜索返回的条数 */
565
- function resultCount(env) {
566
- const raw = env.JADE_SEARCH_RESULTS?.trim();
567
- if (!raw)
586
+ /** 配置项 results(或旧 jade 的 JADE_SEARCH_RESULTS):每次搜索返回的条数,1 到 MAX_RESULTS */
587
+ export function parseResults(value, label) {
588
+ const raw = typeof value === "string" ? value.trim() : value;
589
+ if (raw === undefined || raw === null || raw === "")
568
590
  return DEFAULT_RESULTS;
569
591
  const n = Number(raw);
570
592
  if (!Number.isInteger(n) || n < 1 || n > MAX_RESULTS)
571
- throw new Error(`JADE_SEARCH_RESULTS must be an integer from 1 to ${MAX_RESULTS}, got ${JSON.stringify(raw)}`);
593
+ throw new Error(`${label} must be an integer from 1 to ${MAX_RESULTS}, got ${JSON.stringify(value)}`);
572
594
  return n;
573
595
  }
574
596
  // ---------- web_search ----------
575
- function webSearchTool(services, count) {
597
+ /** 没有配置搜索服务时调用 web_search 的结果(正常情况下这时 web_search 不发给模型) */
598
+ export const SEARCH_OFF = "Web search is not set up. The user can turn it on with the /search command.";
599
+ function webSearchTool(live, count) {
576
600
  return {
577
601
  name: "web_search",
578
602
  description: `Search the web and return the top ${count} results with title, URL and a snippet. ` +
@@ -590,6 +614,9 @@ function webSearchTool(services, count) {
590
614
  const { query } = input;
591
615
  if (!query.trim())
592
616
  return { content: "query must not be empty", isError: true };
617
+ const services = live();
618
+ if (!services.length)
619
+ return { content: SEARCH_OFF, isError: true };
593
620
  // 按顺序试,出错或没有结果时换下一个
594
621
  const failures = [];
595
622
  let failed = false;
@@ -631,4 +658,3 @@ function errorText(err) {
631
658
  return `${err.message} (${detail})`;
632
659
  }
633
660
  const clip = (s, n) => (s.length > n ? s.slice(0, n) + "…" : s);
634
- //# sourceMappingURL=web.js.map