@uncarved/jade 0.1.3 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (455) hide show
  1. package/README.md +161 -150
  2. package/bin/jade.js +14 -25
  3. package/dist/api.d.ts +266 -0
  4. package/dist/api.js +38 -0
  5. package/dist/api.js.map +1 -0
  6. package/dist/config.d.ts +13 -32
  7. package/dist/config.js +39 -121
  8. package/dist/config.js.map +1 -1
  9. package/dist/fetch.d.ts +20 -0
  10. package/dist/fetch.js +190 -0
  11. package/dist/fetch.js.map +1 -0
  12. package/dist/hash.d.ts +2 -0
  13. package/dist/hash.js +42 -0
  14. package/dist/hash.js.map +1 -0
  15. package/dist/host.d.ts +71 -0
  16. package/dist/host.js +400 -0
  17. package/dist/host.js.map +1 -0
  18. package/dist/index.d.ts +11 -30
  19. package/dist/index.js +11 -30
  20. package/dist/index.js.map +1 -1
  21. package/dist/install.d.ts +78 -0
  22. package/dist/install.js +292 -0
  23. package/dist/install.js.map +1 -0
  24. package/dist/main.d.ts +1 -2
  25. package/dist/main.js +160 -1362
  26. package/dist/main.js.map +1 -1
  27. package/dist/manifest.d.ts +23 -0
  28. package/dist/manifest.js +159 -0
  29. package/dist/manifest.js.map +1 -0
  30. package/dist/membrane.d.ts +33 -0
  31. package/dist/membrane.js +140 -0
  32. package/dist/membrane.js.map +1 -0
  33. package/dist/remote.d.ts +10 -0
  34. package/dist/remote.js +292 -0
  35. package/dist/remote.js.map +1 -0
  36. package/dist/rescue.d.ts +10 -0
  37. package/dist/rescue.js +216 -0
  38. package/dist/rescue.js.map +1 -0
  39. package/dist/resolve.d.ts +34 -0
  40. package/dist/resolve.js +178 -0
  41. package/dist/resolve.js.map +1 -0
  42. package/dist/rpc.d.ts +26 -0
  43. package/dist/rpc.js +144 -0
  44. package/dist/rpc.js.map +1 -0
  45. package/dist/secrets.d.ts +12 -0
  46. package/dist/secrets.js +125 -0
  47. package/dist/secrets.js.map +1 -0
  48. package/dist/session.d.ts +45 -0
  49. package/dist/session.js +401 -0
  50. package/dist/session.js.map +1 -0
  51. package/dist/source.d.ts +12 -0
  52. package/dist/source.js +72 -0
  53. package/dist/source.js.map +1 -0
  54. package/dist/state.d.ts +37 -0
  55. package/dist/state.js +93 -0
  56. package/dist/state.js.map +1 -0
  57. package/dist/update.d.ts +2 -0
  58. package/dist/update.js +6 -3
  59. package/dist/update.js.map +1 -1
  60. package/package.json +10 -8
  61. package/plugins/approval/index.ts +311 -0
  62. package/plugins/approval/plugin.json +22 -0
  63. package/{src/plugins → plugins/approval}/policy.ts +45 -104
  64. package/{src/plugins → plugins/approval}/review.ts +62 -16
  65. package/plugins/ask/index.ts +159 -0
  66. package/plugins/ask/plugin.json +8 -0
  67. package/plugins/budget/index.ts +38 -0
  68. package/plugins/budget/plugin.json +13 -0
  69. package/{src/plugins → plugins/checks}/checks.ts +48 -38
  70. package/plugins/checks/index.ts +158 -0
  71. package/plugins/checks/plugin.json +14 -0
  72. package/plugins/checks/project.ts +81 -0
  73. package/plugins/commands/index.ts +76 -0
  74. package/plugins/commands/plugin.json +7 -0
  75. package/{src/plugins → plugins/compact}/compact.ts +80 -39
  76. package/plugins/compact/index.ts +115 -0
  77. package/plugins/compact/plugin.json +17 -0
  78. package/plugins/compact/style.ts +17 -0
  79. package/plugins/continue/index.ts +58 -0
  80. package/plugins/continue/plugin.json +13 -0
  81. package/{src/ui → plugins/fs}/diff.ts +2 -2
  82. package/{src/tools → plugins/fs}/fs.ts +89 -46
  83. package/{src/tools → plugins/fs}/grep.ts +36 -8
  84. package/plugins/fs/index.ts +37 -0
  85. package/plugins/fs/plugin.json +7 -0
  86. package/{src/ui → plugins/fs}/renderers.ts +25 -70
  87. package/plugins/fs/style.ts +18 -0
  88. package/plugins/fs/sys.ts +81 -0
  89. package/plugins/keys/index.ts +53 -0
  90. package/plugins/keys/plugin.json +7 -0
  91. package/plugins/mcp/index.ts +192 -0
  92. package/{src → plugins/mcp}/mcp.ts +32 -32
  93. package/plugins/mcp/plugin.json +7 -0
  94. package/plugins/mcp/project.ts +93 -0
  95. package/plugins/memory/index.ts +105 -0
  96. package/{src → plugins/memory}/memory.ts +20 -2
  97. package/plugins/memory/notes.ts +43 -0
  98. package/plugins/memory/plugin.json +7 -0
  99. package/plugins/memory/style.ts +17 -0
  100. package/plugins/mentions/attach.ts +127 -0
  101. package/plugins/mentions/index.ts +99 -0
  102. package/plugins/mentions/plugin.json +7 -0
  103. package/plugins/mentions/style.ts +17 -0
  104. package/plugins/models/config.ts +53 -0
  105. package/plugins/models/configure.ts +455 -0
  106. package/plugins/models/context.ts +32 -0
  107. package/plugins/models/index.ts +213 -0
  108. package/plugins/models/plugin.json +8 -0
  109. package/{src → plugins/models}/provider.ts +16 -119
  110. package/plugins/models/saved.ts +94 -0
  111. package/plugins/modes/index.ts +222 -0
  112. package/plugins/modes/plugin.json +9 -0
  113. package/plugins/plugins/index.ts +38 -0
  114. package/plugins/plugins/plugin.json +7 -0
  115. package/plugins/print/index.ts +160 -0
  116. package/plugins/print/plugin.json +8 -0
  117. package/plugins/prompts/index.ts +111 -0
  118. package/plugins/prompts/plugin.json +8 -0
  119. package/plugins/prompts/prompts.ts +258 -0
  120. package/plugins/prompts/results.ts +63 -0
  121. package/plugins/prompts/sys.ts +84 -0
  122. package/plugins/renderers/index.ts +78 -0
  123. package/plugins/renderers/plugin.json +7 -0
  124. package/plugins/repeats/index.ts +165 -0
  125. package/plugins/repeats/plugin.json +6 -0
  126. package/plugins/schedule/cron.ts +74 -0
  127. package/plugins/schedule/index.ts +292 -0
  128. package/plugins/schedule/plugin.json +13 -0
  129. package/plugins/schedule/store.ts +149 -0
  130. package/plugins/scratch/index.ts +31 -0
  131. package/plugins/scratch/plugin.json +7 -0
  132. package/plugins/screenshot/index.ts +40 -0
  133. package/plugins/screenshot/plugin.json +7 -0
  134. package/plugins/screenshot/sys.ts +84 -0
  135. package/{src/tools/screenshot.ts → plugins/screenshot/tool.ts} +6 -6
  136. package/plugins/sessions/index.ts +148 -0
  137. package/plugins/sessions/plugin.json +8 -0
  138. package/plugins/shell/index.ts +33 -0
  139. package/plugins/shell/plugin.json +17 -0
  140. package/plugins/shell/renderers.ts +45 -0
  141. package/plugins/shell/service.ts +44 -0
  142. package/{src/tools → plugins/shell}/shell.ts +31 -20
  143. package/{src → plugins/shell}/sys.ts +2 -43
  144. package/plugins/skills/index.ts +96 -0
  145. package/plugins/skills/plugin.json +7 -0
  146. package/plugins/skills/project.ts +49 -0
  147. package/{src → plugins/skills}/skills.ts +4 -11
  148. package/plugins/suggest/index.ts +286 -0
  149. package/plugins/suggest/plugin.json +18 -0
  150. package/plugins/task/index.ts +168 -0
  151. package/plugins/task/plugin.json +15 -0
  152. package/plugins/task/style.ts +17 -0
  153. package/plugins/task/subagent.ts +343 -0
  154. package/plugins/todo/index.ts +93 -0
  155. package/plugins/todo/plugin.json +7 -0
  156. package/{src/ui → plugins/tui}/editor.ts +3 -0
  157. package/plugins/tui/frontend.ts +619 -0
  158. package/plugins/tui/index.ts +37 -0
  159. package/plugins/tui/mentions.ts +153 -0
  160. package/plugins/tui/plugin.json +10 -0
  161. package/{src/ui → plugins/tui}/render.ts +8 -2
  162. package/{src/ui → plugins/tui}/screen.ts +8 -3
  163. package/{src/ui → plugins/tui}/transcript.ts +79 -100
  164. package/{src/ui/tui.tsx → plugins/tui/tui.ts} +360 -392
  165. package/plugins/tui/vendor.ts +16 -0
  166. package/{src/tools → plugins/undo}/checkpoint.ts +45 -60
  167. package/plugins/undo/index.ts +143 -0
  168. package/plugins/undo/notes.ts +43 -0
  169. package/plugins/undo/plugin.json +7 -0
  170. package/plugins/undo/style.ts +17 -0
  171. package/plugins/update/index.ts +40 -0
  172. package/plugins/update/plugin.json +13 -0
  173. package/plugins/web/env.ts +78 -0
  174. package/plugins/web/index.ts +133 -0
  175. package/plugins/web/plugin.json +15 -0
  176. package/plugins/web/renderers.ts +11 -0
  177. package/{src/tools → plugins/web}/web.ts +64 -31
  178. package/plugins-dist/approval/index.js +287 -0
  179. package/plugins-dist/approval/plugin.json +28 -0
  180. package/{dist/plugins → plugins-dist/approval}/policy.js +41 -85
  181. package/{dist/plugins → plugins-dist/approval}/review.js +56 -10
  182. package/{dist/plugins → plugins-dist/approval}/schema.js +0 -1
  183. package/plugins-dist/ask/index.js +145 -0
  184. package/plugins-dist/ask/plugin.json +12 -0
  185. package/plugins-dist/budget/index.js +37 -0
  186. package/plugins-dist/budget/plugin.json +15 -0
  187. package/{dist/plugins → plugins-dist/checks}/checks.js +46 -35
  188. package/plugins-dist/checks/index.js +150 -0
  189. package/plugins-dist/checks/plugin.json +21 -0
  190. package/plugins-dist/checks/project.js +76 -0
  191. package/plugins-dist/commands/index.js +33 -0
  192. package/plugins-dist/commands/plugin.json +9 -0
  193. package/{dist/plugins → plugins-dist/compact}/compact.js +58 -34
  194. package/plugins-dist/compact/index.js +100 -0
  195. package/plugins-dist/compact/plugin.json +25 -0
  196. package/plugins-dist/compact/style.js +14 -0
  197. package/plugins-dist/continue/index.js +57 -0
  198. package/plugins-dist/continue/plugin.json +15 -0
  199. package/{dist/ui → plugins-dist/fs}/diff.js +2 -3
  200. package/{dist/tools → plugins-dist/fs}/fs.js +82 -46
  201. package/{dist/tools → plugins-dist/fs}/grep.js +36 -11
  202. package/plugins-dist/fs/index.js +39 -0
  203. package/plugins-dist/fs/plugin.json +10 -0
  204. package/{dist/ui → plugins-dist/fs}/renderers.js +24 -61
  205. package/plugins-dist/fs/style.js +15 -0
  206. package/plugins-dist/fs/sys.js +54 -0
  207. package/plugins-dist/keys/index.js +36 -0
  208. package/plugins-dist/keys/plugin.json +9 -0
  209. package/plugins-dist/mcp/index.js +187 -0
  210. package/{dist → plugins-dist/mcp}/mcp.js +34 -30
  211. package/plugins-dist/mcp/plugin.json +12 -0
  212. package/plugins-dist/mcp/project.js +90 -0
  213. package/plugins-dist/memory/index.js +94 -0
  214. package/{dist → plugins-dist/memory}/memory.js +21 -3
  215. package/plugins-dist/memory/notes.js +36 -0
  216. package/plugins-dist/memory/plugin.json +11 -0
  217. package/plugins-dist/memory/style.js +14 -0
  218. package/plugins-dist/mentions/attach.js +120 -0
  219. package/plugins-dist/mentions/index.js +87 -0
  220. package/plugins-dist/mentions/plugin.json +9 -0
  221. package/plugins-dist/mentions/style.js +14 -0
  222. package/plugins-dist/models/config.js +53 -0
  223. package/plugins-dist/models/configure.js +415 -0
  224. package/plugins-dist/models/context.js +27 -0
  225. package/plugins-dist/models/index.js +181 -0
  226. package/plugins-dist/models/plugin.json +14 -0
  227. package/{dist → plugins-dist/models}/provider.js +18 -81
  228. package/plugins-dist/models/saved.js +80 -0
  229. package/plugins-dist/modes/index.js +190 -0
  230. package/plugins-dist/modes/plugin.json +18 -0
  231. package/plugins-dist/plugins/index.js +37 -0
  232. package/plugins-dist/plugins/plugin.json +10 -0
  233. package/plugins-dist/print/index.js +172 -0
  234. package/plugins-dist/print/plugin.json +14 -0
  235. package/plugins-dist/prompts/index.js +85 -0
  236. package/plugins-dist/prompts/plugin.json +13 -0
  237. package/plugins-dist/prompts/prompts.js +231 -0
  238. package/plugins-dist/prompts/results.js +60 -0
  239. package/plugins-dist/prompts/sys.js +58 -0
  240. package/plugins-dist/renderers/index.js +36 -0
  241. package/plugins-dist/renderers/plugin.json +9 -0
  242. package/plugins-dist/repeats/index.js +165 -0
  243. package/plugins-dist/repeats/plugin.json +6 -0
  244. package/plugins-dist/schedule/cron.js +67 -0
  245. package/plugins-dist/schedule/index.js +281 -0
  246. package/plugins-dist/schedule/plugin.json +16 -0
  247. package/plugins-dist/schedule/store.js +125 -0
  248. package/plugins-dist/scratch/index.js +26 -0
  249. package/plugins-dist/scratch/plugin.json +10 -0
  250. package/plugins-dist/screenshot/index.js +35 -0
  251. package/plugins-dist/screenshot/plugin.json +11 -0
  252. package/plugins-dist/screenshot/sys.js +76 -0
  253. package/{dist/tools/screenshot.js → plugins-dist/screenshot/tool.js} +5 -4
  254. package/plugins-dist/sessions/index.js +136 -0
  255. package/plugins-dist/sessions/plugin.json +12 -0
  256. package/plugins-dist/shell/index.js +33 -0
  257. package/plugins-dist/shell/plugin.json +19 -0
  258. package/plugins-dist/shell/renderers.js +40 -0
  259. package/plugins-dist/shell/service.js +29 -0
  260. package/{dist/tools → plugins-dist/shell}/shell.js +31 -22
  261. package/{dist → plugins-dist/shell}/sys.js +2 -43
  262. package/plugins-dist/skills/index.js +90 -0
  263. package/plugins-dist/skills/plugin.json +12 -0
  264. package/plugins-dist/skills/project.js +47 -0
  265. package/{dist → plugins-dist/skills}/skills.js +3 -7
  266. package/plugins-dist/suggest/index.js +282 -0
  267. package/plugins-dist/suggest/plugin.json +23 -0
  268. package/plugins-dist/task/index.js +152 -0
  269. package/plugins-dist/task/plugin.json +23 -0
  270. package/plugins-dist/task/style.js +14 -0
  271. package/plugins-dist/task/subagent.js +284 -0
  272. package/{dist/tools/todo.js → plugins-dist/todo/index.js} +31 -9
  273. package/plugins-dist/todo/plugin.json +9 -0
  274. package/{dist/ui → plugins-dist/tui}/editor.js +3 -1
  275. package/plugins-dist/tui/frontend.js +609 -0
  276. package/{dist → plugins-dist/tui}/history.js +0 -1
  277. package/plugins-dist/tui/index.js +21 -0
  278. package/{dist/ui → plugins-dist/tui}/markdown.js +0 -1
  279. package/plugins-dist/tui/mentions.js +153 -0
  280. package/plugins-dist/tui/plugin.json +25 -0
  281. package/{dist/ui → plugins-dist/tui}/render.js +7 -3
  282. package/{dist/ui → plugins-dist/tui}/screen.js +6 -2
  283. package/{dist/ui → plugins-dist/tui}/transcript.js +79 -99
  284. package/{dist/ui → plugins-dist/tui}/tui.js +185 -54
  285. package/plugins-dist/tui/vendor.js +13822 -0
  286. package/{dist/tools → plugins-dist/undo}/checkpoint.js +48 -55
  287. package/plugins-dist/undo/index.js +143 -0
  288. package/plugins-dist/undo/notes.js +36 -0
  289. package/plugins-dist/undo/plugin.json +9 -0
  290. package/plugins-dist/undo/style.js +14 -0
  291. package/plugins-dist/update/index.js +34 -0
  292. package/plugins-dist/update/plugin.json +15 -0
  293. package/plugins-dist/web/env.js +80 -0
  294. package/plugins-dist/web/index.js +124 -0
  295. package/plugins-dist/web/plugin.json +21 -0
  296. package/plugins-dist/web/renderers.js +7 -0
  297. package/{dist/tools → plugins-dist/web}/web.js +56 -29
  298. package/sdk/python/__pycache__/jade_plugin.cpython-312.pyc +0 -0
  299. package/sdk/python/jade_plugin.py +380 -0
  300. package/src/api.ts +298 -0
  301. package/src/config.ts +32 -134
  302. package/src/fetch.ts +216 -0
  303. package/src/hash.ts +39 -0
  304. package/src/host.ts +429 -0
  305. package/src/index.ts +23 -30
  306. package/src/install.ts +355 -0
  307. package/src/main.ts +156 -1387
  308. package/src/manifest.ts +160 -0
  309. package/src/membrane.ts +142 -0
  310. package/src/remote.ts +288 -0
  311. package/src/rescue.ts +217 -0
  312. package/src/resolve.ts +199 -0
  313. package/src/rpc.ts +144 -0
  314. package/src/secrets.ts +122 -0
  315. package/src/session.ts +458 -0
  316. package/src/source.ts +83 -0
  317. package/src/state.ts +120 -0
  318. package/src/update.ts +265 -262
  319. package/LICENSE +0 -21
  320. package/dist/commands.d.ts +0 -50
  321. package/dist/commands.js +0 -126
  322. package/dist/commands.js.map +0 -1
  323. package/dist/context.d.ts +0 -17
  324. package/dist/context.js +0 -53
  325. package/dist/context.js.map +0 -1
  326. package/dist/distro.d.ts +0 -141
  327. package/dist/distro.js +0 -462
  328. package/dist/distro.js.map +0 -1
  329. package/dist/history.d.ts +0 -10
  330. package/dist/history.js.map +0 -1
  331. package/dist/mcp.d.ts +0 -114
  332. package/dist/mcp.js.map +0 -1
  333. package/dist/memory.d.ts +0 -19
  334. package/dist/memory.js.map +0 -1
  335. package/dist/mentions.d.ts +0 -35
  336. package/dist/mentions.js +0 -130
  337. package/dist/mentions.js.map +0 -1
  338. package/dist/plugin-cli.d.ts +0 -16
  339. package/dist/plugin-cli.js +0 -294
  340. package/dist/plugin-cli.js.map +0 -1
  341. package/dist/plugins/budget.d.ts +0 -9
  342. package/dist/plugins/budget.js +0 -30
  343. package/dist/plugins/budget.js.map +0 -1
  344. package/dist/plugins/builtins.d.ts +0 -10
  345. package/dist/plugins/builtins.js +0 -25
  346. package/dist/plugins/builtins.js.map +0 -1
  347. package/dist/plugins/checks.d.ts +0 -71
  348. package/dist/plugins/checks.js.map +0 -1
  349. package/dist/plugins/compact.d.ts +0 -26
  350. package/dist/plugins/compact.js.map +0 -1
  351. package/dist/plugins/core.d.ts +0 -47
  352. package/dist/plugins/core.js +0 -229
  353. package/dist/plugins/core.js.map +0 -1
  354. package/dist/plugins/host.d.ts +0 -52
  355. package/dist/plugins/host.js +0 -115
  356. package/dist/plugins/host.js.map +0 -1
  357. package/dist/plugins/install.d.ts +0 -68
  358. package/dist/plugins/install.js +0 -377
  359. package/dist/plugins/install.js.map +0 -1
  360. package/dist/plugins/loader.d.ts +0 -410
  361. package/dist/plugins/loader.js +0 -407
  362. package/dist/plugins/loader.js.map +0 -1
  363. package/dist/plugins/policy.d.ts +0 -98
  364. package/dist/plugins/policy.js.map +0 -1
  365. package/dist/plugins/prompts.d.ts +0 -43
  366. package/dist/plugins/prompts.js +0 -284
  367. package/dist/plugins/prompts.js.map +0 -1
  368. package/dist/plugins/repeats.d.ts +0 -16
  369. package/dist/plugins/repeats.js +0 -151
  370. package/dist/plugins/repeats.js.map +0 -1
  371. package/dist/plugins/review.d.ts +0 -18
  372. package/dist/plugins/review.js.map +0 -1
  373. package/dist/plugins/schema.d.ts +0 -2
  374. package/dist/plugins/schema.js.map +0 -1
  375. package/dist/plugins/sessions.d.ts +0 -7
  376. package/dist/plugins/sessions.js +0 -110
  377. package/dist/plugins/sessions.js.map +0 -1
  378. package/dist/provider.d.ts +0 -165
  379. package/dist/provider.js.map +0 -1
  380. package/dist/session-lifecycle.d.ts +0 -61
  381. package/dist/session-lifecycle.js +0 -167
  382. package/dist/session-lifecycle.js.map +0 -1
  383. package/dist/session-scope.d.ts +0 -53
  384. package/dist/session-scope.js +0 -116
  385. package/dist/session-scope.js.map +0 -1
  386. package/dist/sessions.d.ts +0 -28
  387. package/dist/sessions.js +0 -73
  388. package/dist/sessions.js.map +0 -1
  389. package/dist/skills.d.ts +0 -37
  390. package/dist/skills.js.map +0 -1
  391. package/dist/sys.d.ts +0 -51
  392. package/dist/sys.js.map +0 -1
  393. package/dist/tools/ask.d.ts +0 -11
  394. package/dist/tools/ask.js +0 -62
  395. package/dist/tools/ask.js.map +0 -1
  396. package/dist/tools/checkpoint.d.ts +0 -43
  397. package/dist/tools/checkpoint.js.map +0 -1
  398. package/dist/tools/fs.d.ts +0 -39
  399. package/dist/tools/fs.js.map +0 -1
  400. package/dist/tools/grep.d.ts +0 -6
  401. package/dist/tools/grep.js.map +0 -1
  402. package/dist/tools/screenshot.d.ts +0 -15
  403. package/dist/tools/screenshot.js.map +0 -1
  404. package/dist/tools/shell.d.ts +0 -55
  405. package/dist/tools/shell.js.map +0 -1
  406. package/dist/tools/task.d.ts +0 -39
  407. package/dist/tools/task.js +0 -117
  408. package/dist/tools/task.js.map +0 -1
  409. package/dist/tools/todo.d.ts +0 -10
  410. package/dist/tools/todo.js.map +0 -1
  411. package/dist/tools/web.d.ts +0 -53
  412. package/dist/tools/web.js.map +0 -1
  413. package/dist/ui/configure.d.ts +0 -20
  414. package/dist/ui/configure.js +0 -447
  415. package/dist/ui/configure.js.map +0 -1
  416. package/dist/ui/diff.d.ts +0 -20
  417. package/dist/ui/diff.js.map +0 -1
  418. package/dist/ui/editor.d.ts +0 -41
  419. package/dist/ui/editor.js.map +0 -1
  420. package/dist/ui/markdown.d.ts +0 -22
  421. package/dist/ui/markdown.js.map +0 -1
  422. package/dist/ui/render.d.ts +0 -14
  423. package/dist/ui/render.js.map +0 -1
  424. package/dist/ui/renderers.d.ts +0 -8
  425. package/dist/ui/renderers.js.map +0 -1
  426. package/dist/ui/screen.d.ts +0 -118
  427. package/dist/ui/screen.js.map +0 -1
  428. package/dist/ui/transcript.d.ts +0 -46
  429. package/dist/ui/transcript.js.map +0 -1
  430. package/dist/ui/tui.d.ts +0 -47
  431. package/dist/ui/tui.js.map +0 -1
  432. package/src/commands.ts +0 -144
  433. package/src/context.ts +0 -64
  434. package/src/distro.ts +0 -577
  435. package/src/mentions.ts +0 -135
  436. package/src/plugin-cli.ts +0 -278
  437. package/src/plugins/budget.ts +0 -37
  438. package/src/plugins/builtins.ts +0 -34
  439. package/src/plugins/core.ts +0 -257
  440. package/src/plugins/host.ts +0 -146
  441. package/src/plugins/install.ts +0 -429
  442. package/src/plugins/loader.ts +0 -742
  443. package/src/plugins/prompts.ts +0 -327
  444. package/src/plugins/repeats.ts +0 -157
  445. package/src/plugins/sessions.ts +0 -109
  446. package/src/session-lifecycle.ts +0 -194
  447. package/src/session-scope.ts +0 -135
  448. package/src/sessions.ts +0 -78
  449. package/src/tools/ask.ts +0 -72
  450. package/src/tools/task.ts +0 -149
  451. package/src/tools/todo.ts +0 -67
  452. package/src/ui/configure.ts +0 -471
  453. /package/{src/plugins → plugins/approval}/schema.ts +0 -0
  454. /package/{src → plugins/tui}/history.ts +0 -0
  455. /package/{src/ui → plugins/tui}/markdown.ts +0 -0
@@ -0,0 +1,16 @@
1
+ // ink 和 react 只经这里导入。构建时 scripts/build-plugins.mjs 把编译出的 vendor.js 连同依赖打成一个文件:
2
+ // 逐个解析 ink 和它拉进来的整个 es-toolkit/compat 要约 470ms,打包后约 120ms(docs/review.md #28)。
3
+ // 两者必须打在同一个文件里,否则 ink 和界面各用一份 react,hooks 会失效。
4
+ // 只用到类型的从 "ink"/"react" 直接 import type,不经这里。
5
+
6
+ export { Box, render, Text, useBoxMetrics, useCursor, useInput, usePaste, useWindowSize } from "ink";
7
+ export {
8
+ createContext,
9
+ createElement,
10
+ useContext,
11
+ useEffect,
12
+ useReducer,
13
+ useRef,
14
+ useState,
15
+ useSyncExternalStore,
16
+ } from "react";
@@ -1,20 +1,13 @@
1
- // 文件快照:write_file / edit_file 写入前保存原内容,宿主的 /undo 用它恢复。
1
+ // 文件快照:write_file / edit_file / multi_edit 执行前保存原内容,/undo 用它恢复。从旧 jade 的 tools/checkpoint.ts 移植。
2
2
  //
3
- // 快照放在 <dir>/<sessionId>/<toolUseId>.json,不进日志:文件可能很大,而撤销是宿主的操作,不影响插件决策。
4
- // 哪些修改已经撤销由宿主用 Runtime.record 记在日志里(UNDO_KEY),恢复会话后仍然有效。
3
+ // 快照放在 <dir>/<sessionId>/<toolUseId>.json,不进日志:文件可能很大,而撤销是用户的操作,不影响插件决策。
4
+ // 哪些修改已经撤销记在同一个目录的 undone.json 里(命令拿不到会话日志),恢复会话后仍然有效。
5
5
 
6
6
  import { createHash } from "node:crypto";
7
- import { appendFile, mkdir, readdir, readFile, rm, writeFile } from "node:fs/promises";
7
+ import { mkdir, readdir, readFile, rm, writeFile } from "node:fs/promises";
8
8
  import path from "node:path";
9
9
  import type { Message } from "uncarved";
10
10
 
11
- /** derived 中保存已撤销的 toolUseId 的键 */
12
- export const UNDO_KEY = "jade/undo";
13
-
14
- export interface UndoState {
15
- undone: string[];
16
- }
17
-
18
11
  export interface Checkpoint {
19
12
  toolUseId: string;
20
13
  tool: string;
@@ -32,8 +25,6 @@ export const sha256 = (s: string) => createHash("sha256").update(s).digest("hex"
32
25
 
33
26
  export class Checkpoints {
34
27
  readonly #dir: string;
35
- /** 会话 → 文件 → markSeen 记下的 sha256;第一次用到时从 seen.jsonl 读入 */
36
- readonly #seen = new Map<string, Promise<Map<string, string>>>();
37
28
 
38
29
  constructor(dir: string) {
39
30
  this.#dir = dir;
@@ -57,7 +48,7 @@ export class Checkpoints {
57
48
  }
58
49
  const out: Checkpoint[] = [];
59
50
  for (const n of names) {
60
- if (!n.endsWith(".json")) continue;
51
+ if (!n.endsWith(".json") || n === UNDONE) continue;
61
52
  try {
62
53
  out.push(JSON.parse(await readFile(path.join(dir, n), "utf8")) as Checkpoint);
63
54
  } catch {
@@ -67,54 +58,22 @@ export class Checkpoints {
67
58
  return out.sort((a, b) => b.at - a.at);
68
59
  }
69
60
 
70
- /**
71
- * 记下本会话读过或写过的文件当时内容的 sha256。fs 工具在内存里也记一份,
72
- * 这里的是给恢复的会话用的:之前的进程里读过、写过的文件,内容没变就不用再读一遍。
73
- * 追加到每个会话一个的 seen.jsonl,后面的记录覆盖前面的;内容没变的重复读取不再写
74
- */
75
- async markSeen(sessionId: string, file: string, hash: string): Promise<void> {
76
- const seen = await this.#seenOf(sessionId);
77
- if (seen.get(file) === hash) return;
78
- seen.set(file, hash);
79
- const dir = path.join(this.#dir, safe(sessionId));
80
- await mkdir(dir, { recursive: true });
81
- await appendFile(path.join(dir, "seen.jsonl"), JSON.stringify({ path: file, hash }) + "\n");
82
- }
83
-
84
- /** markSeen 记下的 sha256;没有记录返回 undefined */
85
- async seenHash(sessionId: string, file: string): Promise<string | undefined> {
86
- const hash = (await this.#seenOf(sessionId)).get(file);
87
- if (hash !== undefined) return hash;
88
- // 旧版本每个文件一个 seen/<sha256(path)>.json
61
+ /** 已经撤销的修改(toolUseId) */
62
+ async undone(sessionId: string): Promise<Set<string>> {
89
63
  try {
90
- const rec = JSON.parse(await readFile(path.join(this.#dir, safe(sessionId), "seen", `${sha256(file)}.json`), "utf8")) as { path: string; hash: string };
91
- return rec.path === file ? rec.hash : undefined;
64
+ const ids = JSON.parse(await readFile(path.join(this.#dir, safe(sessionId), UNDONE), "utf8")) as unknown;
65
+ return new Set(Array.isArray(ids) ? ids.filter((x): x is string => typeof x === "string") : []);
92
66
  } catch {
93
- return undefined;
67
+ return new Set();
94
68
  }
95
69
  }
96
70
 
97
- #seenOf(sessionId: string): Promise<Map<string, string>> {
98
- let seen = this.#seen.get(sessionId);
99
- if (!seen) {
100
- seen = readFile(path.join(this.#dir, safe(sessionId), "seen.jsonl"), "utf8").then(
101
- (text) => {
102
- const map = new Map<string, string>();
103
- for (const line of text.split("\n")) {
104
- try {
105
- const rec = JSON.parse(line) as { path: string; hash: string };
106
- map.set(rec.path, rec.hash);
107
- } catch {
108
- // 空行或写到一半的一行
109
- }
110
- }
111
- return map;
112
- },
113
- () => new Map<string, string>(),
114
- );
115
- this.#seen.set(sessionId, seen);
116
- }
117
- return seen;
71
+ async markUndone(sessionId: string, ids: Iterable<string>): Promise<void> {
72
+ const all = await this.undone(sessionId);
73
+ for (const id of ids) all.add(id);
74
+ const dir = path.join(this.#dir, safe(sessionId));
75
+ await mkdir(dir, { recursive: true });
76
+ await writeFile(path.join(dir, UNDONE), JSON.stringify([...all]));
118
77
  }
119
78
 
120
79
  /** 文件现在的内容是否还是这次写入的结果 */
@@ -136,9 +95,11 @@ export class Checkpoints {
136
95
  }
137
96
  }
138
97
 
98
+ const UNDONE = "undone.json";
99
+
139
100
  /**
140
- * 最近一轮还有没撤销的修改的快照(最新的在前)。一轮从一条用户消息开始;
141
- * 只有工具结果、或者只有宿主说明(例如自动续写的提示)的消息不算新的一轮。没有可撤销的返回空数组
101
+ * 最近一轮还有没撤销的修改的快照(最新的在前)。一轮从一条用户自己写的消息开始;
102
+ * 只有工具结果、或者只有插件、宿主加的说明(例如自动续写的提示)的消息不算新的一轮。没有可撤销的返回空数组
142
103
  */
143
104
  export function lastTurnChanges(messages: readonly Message[], checkpoints: readonly Checkpoint[], undone: ReadonlySet<string>): Checkpoint[] {
144
105
  const pending = checkpoints.filter((c) => !undone.has(c.toolUseId));
@@ -150,7 +111,7 @@ export function lastTurnChanges(messages: readonly Message[], checkpoints: reado
150
111
  for (const b of m.content) if (b.kind === "tool_use") ids.add(b.id);
151
112
  continue;
152
113
  }
153
- const startsTurn = m.content.some((b) => b.kind !== "tool_result" && b.origin.by !== "host");
114
+ const startsTurn = m.content.some((b) => b.kind !== "tool_result" && b.origin.by === "user");
154
115
  if (!startsTurn) continue;
155
116
  const hits = pending.filter((c) => ids.has(c.toolUseId));
156
117
  if (hits.length > 0) return hits;
@@ -160,5 +121,29 @@ export function lastTurnChanges(messages: readonly Message[], checkpoints: reado
160
121
  return pending.slice(0, 1);
161
122
  }
162
123
 
124
+ /**
125
+ * 一轮里调用过的工具名:含 toolUseId 的那一轮;不给时是最近一轮。
126
+ * 一轮从用户发的消息开始,到下一条用户消息之前(与 lastTurnChanges 的划分相同)
127
+ */
128
+ export function turnToolNames(messages: readonly Message[], toolUseId?: string): Set<string> {
129
+ let names = new Set<string>();
130
+ let found = toolUseId === undefined;
131
+ for (let i = messages.length - 1; i >= 0; i--) {
132
+ const m = messages[i]!;
133
+ if (m.role === "assistant") {
134
+ for (const b of m.content) {
135
+ if (b.kind !== "tool_use") continue;
136
+ names.add(b.name);
137
+ if (b.id === toolUseId) found = true;
138
+ }
139
+ continue;
140
+ }
141
+ if (!m.content.some((b) => b.kind !== "tool_result" && b.origin.by === "user")) continue;
142
+ if (found) return names;
143
+ names = new Set();
144
+ }
145
+ return found ? names : new Set();
146
+ }
147
+
163
148
  /** 会话和工具调用的 id 用作文件名 */
164
149
  const safe = (id: string) => id.replace(/[^A-Za-z0-9_.-]/g, "_");
@@ -0,0 +1,143 @@
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
+
7
+ import { readFile } from "node:fs/promises";
8
+ import { realpathSync } from "node:fs";
9
+ import path from "node:path";
10
+ import { definePlugin } from "../../src/api.ts";
11
+ import type { Commands } from "../commands/index.ts";
12
+ import { Checkpoints, lastTurnChanges, sha256, turnToolNames, type Checkpoint } from "./checkpoint.ts";
13
+ import { Notes } from "./notes.ts";
14
+ import { dim, green } from "./style.ts";
15
+
16
+ /** 会改文件、参数里有 path 的工具 */
17
+ export const WRITE_TOOLS = new Set(["write_file", "edit_file", "multi_edit"]);
18
+
19
+ /** shell 命令改了什么无从得知,撤销不了;这一轮跑过时提醒一句 */
20
+ const SHELL_NOTE = "This turn also ran shell commands; what they changed is not undone.";
21
+
22
+ const notes = new Notes();
23
+
24
+ /** 显示用:工作目录内的路径用相对形式,统一为正斜杠 */
25
+ function display(cwd: string, full: string): string {
26
+ const rel = path.relative(cwd, full);
27
+ const shown = rel && rel !== ".." && !rel.startsWith(`..${path.sep}`) && !path.isAbsolute(rel) ? rel : full;
28
+ return shown.split(path.sep).join("/");
29
+ }
30
+
31
+ function realPath(p: string): string {
32
+ try {
33
+ return realpathSync.native(p);
34
+ } catch {
35
+ return path.resolve(p);
36
+ }
37
+ }
38
+
39
+ /** 文件现在的内容;不存在时 null */
40
+ async function contentOf(file: string): Promise<string | null> {
41
+ try {
42
+ return await readFile(file, "utf8");
43
+ } catch (e) {
44
+ if ((e as NodeJS.ErrnoException).code === "ENOENT") return null;
45
+ throw e;
46
+ }
47
+ }
48
+
49
+ export default definePlugin({
50
+ process(ctx) {
51
+ const checkpoints = new Checkpoints(path.join(ctx.home, "checkpoints"));
52
+ const cwd = realPath(ctx.cwd);
53
+ ctx.service<Commands>("commands@1")?.register({
54
+ name: "undo",
55
+ description: "restore the files the agent wrote or edited in its last turn, not changes made by shell commands (run again to go further back)",
56
+ async run(_args, { sessions, ui, signal }) {
57
+ const s = sessions.current;
58
+ if (!s) return "No session is open.";
59
+ const undone = await checkpoints.undone(s.id);
60
+ const cps = lastTurnChanges(s.state.messages, await checkpoints.list(s.id), undone);
61
+ if (cps.length === 0) return dim(turnToolNames(s.state.messages).has("bash") ? `Nothing to undo. ${SHELL_NOTE}` : "Nothing to undo.");
62
+ const shellToo = turnToolNames(s.state.messages, cps[0]!.toolUseId).has("bash");
63
+ /** 文件 → 这一轮最早的快照(恢复成它的 before);cps 是最新的在前 */
64
+ const files = new Map<string, Checkpoint>();
65
+ for (const cp of cps) files.set(cp.path, cp);
66
+ // 恢复前就算好显示的名字:恢复时会删掉 agent 新建的文件。文件可能已经不在了(agent 删掉的):解析它所在的目录
67
+ const shown = new Map([...files.keys()].map((p) => [p, display(cwd, path.join(realPath(path.dirname(p)), path.basename(p)))]));
68
+ const show = (p: string) => shown.get(p) ?? display(cwd, p);
69
+ // 只有最新一次写入之后的内容能和文件现在的样子比较
70
+ const latest = new Map<string, Checkpoint>();
71
+ for (const cp of cps) if (!latest.has(cp.path)) latest.set(cp.path, cp);
72
+ const changed: string[] = [];
73
+ for (const cp of latest.values()) if (!(await checkpoints.unchangedSince(cp))) changed.push(show(cp.path));
74
+ const list = [...files.values()].map((cp) => ` ${cp.before === null ? "delete " : "restore"} ${show(cp.path)}`).join("\n");
75
+ if (files.size > 1 || changed.length > 0) {
76
+ const ok = await ui.select(
77
+ {
78
+ title:
79
+ changed.length > 0
80
+ ? `${changed.join(", ")} changed since the agent wrote ${changed.length > 1 ? "them" : "it"}. Undo anyway and discard those changes too?`
81
+ : `Undo the agent's last turn of changes (${files.size} files)?`,
82
+ detail: list,
83
+ options: [
84
+ { label: "No", value: "no" },
85
+ { label: changed.length > 0 ? "Yes, undo anyway" : "Yes, undo", value: "yes" },
86
+ ],
87
+ },
88
+ signal,
89
+ );
90
+ if (ok !== "yes") return;
91
+ }
92
+ // 最新的先恢复:同一个文件最后恢复成这一轮最早的 before
93
+ for (const cp of cps) await checkpoints.restore(cp);
94
+ await checkpoints.markUndone(s.id, cps.map((c) => c.toolUseId));
95
+ const what = [...files.values()].map((cp) =>
96
+ cp.before === null ? `deleted ${show(cp.path)} (you had created it)` : `restored ${show(cp.path)} to its content before your changes`,
97
+ );
98
+ notes.add(s.id, `The user undid your changes from your last turn: ${what.join("; ")}. Read these files again before changing them.`);
99
+ return green(`Undid ${cps.length} change${cps.length > 1 ? "s" : ""} from the last turn:`) + "\n" + dim(list) + (shellToo ? `\n${dim(SHELL_NOTE)}` : "");
100
+ },
101
+ });
102
+ },
103
+
104
+ session(ctx) {
105
+ const checkpoints = new Checkpoints(path.join(ctx.home, "checkpoints"));
106
+ const sessionId = ctx.session.id;
107
+ /** toolUseId → 执行前的内容,执行成功后存成快照 */
108
+ const before = new Map<string, { tool: string; path: string; before: string | null }>();
109
+
110
+ ctx.kernel.hook({
111
+ kind: "transform",
112
+ point: "tool.before",
113
+ // 排在 jade/approval 把路径换成绝对路径之后;出错时只是没有快照,不影响工具执行
114
+ order: 50,
115
+ optional: true,
116
+ fn: async (call) => {
117
+ if (!WRITE_TOOLS.has(call.name)) return;
118
+ const p = (call.input as { path?: unknown } | null)?.path;
119
+ if (typeof p !== "string") return;
120
+ const full = path.resolve(ctx.cwd, p);
121
+ before.set(call.toolUseId, { tool: call.name, path: full, before: await contentOf(full) });
122
+ },
123
+ });
124
+ ctx.kernel.hook({
125
+ kind: "transform",
126
+ point: "tool.after",
127
+ optional: true,
128
+ fn: async (out) => {
129
+ const snap = before.get(out.call.toolUseId);
130
+ if (!snap) return;
131
+ before.delete(out.call.toolUseId);
132
+ if (out.isError) return;
133
+ const after = await contentOf(snap.path);
134
+ // 内容没变(例如同样的内容重复写入)不算修改
135
+ if (after === snap.before) return;
136
+ await checkpoints.save(sessionId, { toolUseId: out.call.toolUseId, ...snap, afterHash: sha256(after ?? "") });
137
+ },
138
+ });
139
+ // 被拒绝、被中断的调用不经过 tool.after:一轮结束时还留着的都不会再用到,不然整个文件的内容一直占着内存
140
+ ctx.kernel.hook({ kind: "observe", point: "event", fn: (e) => void (e.type === "turn.ended" && before.clear()) });
141
+ ctx.kernel.hook(notes.hook(sessionId, ctx.plugin, ctx.plugin));
142
+ },
143
+ });
@@ -0,0 +1,43 @@
1
+ // 给模型的说明([Note from jade]):命令里做的事(例如用户撤销了模型改的文件)要让模型知道,
2
+ // 但命令拿不到会话日志,也不该替用户发一条消息。所以先记下来,下一次请求模型时在 context.project 里
3
+ // 附在最后一条消息后面,并用 ctx.record 写进日志(derived):之后的投影、恢复的会话里它都在同一个位置。
4
+ // 插件之间不共享代码,jade/memory 里也有一份。
5
+
6
+ import type { Block, LocalHookSpec, Message } from "uncarved";
7
+
8
+ /** derived 里:消息的下标 → 附在它后面的说明 */
9
+ type NotesState = Record<string, string[]>;
10
+
11
+ export class Notes {
12
+ /** 会话 → 还没交给模型的说明 */
13
+ readonly #pending = new Map<string, string[]>();
14
+
15
+ add(sessionId: string, text: string): void {
16
+ this.#pending.set(sessionId, [...(this.#pending.get(sessionId) ?? []), text]);
17
+ }
18
+
19
+ /** 会话里的 context.project hook;key 是 derived 里的键 */
20
+ hook(sessionId: string, plugin: string, key: string): LocalHookSpec {
21
+ return {
22
+ kind: "transform",
23
+ point: "context.project",
24
+ order: -40,
25
+ fn: async (messages, ctx) => {
26
+ let state = (ctx.derived[key] as NotesState | undefined) ?? {};
27
+ const fresh = this.#pending.get(sessionId);
28
+ if (fresh?.length && messages.length > 0) {
29
+ const at = String(messages.length - 1);
30
+ state = { ...state, [at]: [...(state[at] ?? []), ...fresh] };
31
+ await ctx.record(key, state);
32
+ this.#pending.delete(sessionId);
33
+ }
34
+ return messages.map((m, i): Message => {
35
+ const notes = state[i];
36
+ if (!notes?.length || m.role !== "user") return m;
37
+ const blocks: Block[] = notes.map((text) => ({ kind: "text", text: `[Note from jade] ${text}`, origin: { by: "plugin", id: plugin }, trust: "trusted" }));
38
+ return { ...m, content: [...m.content, ...blocks] };
39
+ });
40
+ },
41
+ };
42
+ }
43
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "id": "jade/undo",
3
+ "version": "0.2.0",
4
+ "api": "^1",
5
+ "entry": "./index.ts",
6
+ "optional": ["commands@1"]
7
+ }
@@ -0,0 +1,17 @@
1
+ // 显示用的小工具:截断和 ANSI 颜色。插件之间不共享代码(只能共享类型),所以这里也有一份(同 jade/fs 的 style.ts)。
2
+
3
+ export const clip = (s: string, n: number) => (s.length > n ? s.slice(0, n) + "…" : s);
4
+
5
+ // 设了 NO_COLOR(非空)或标准输出不是终端时不输出颜色,见 https://no-color.org
6
+ const colors = Boolean(process.stdout.isTTY) && !process.env.NO_COLOR;
7
+ /**
8
+ * 每种样式用自己的关闭码,不用 \x1b[0m 全部重置:外面套着别的样式时,后面的文字仍保持外层样式。
9
+ * 里面出现同一个关闭码(例如 dim 里套 bold,两者都用 22 关闭)时紧接着重新打开外层的样式
10
+ */
11
+ const paint = (open: string, close: string) => (s: string) =>
12
+ colors ? `\x1b[${open}m${s.replaceAll(`\x1b[${close}m`, `\x1b[${close}m\x1b[${open}m`)}\x1b[${close}m` : s;
13
+ export const dim = paint("2", "22");
14
+ export const red = paint("31", "39");
15
+ export const green = paint("32", "39");
16
+ export const yellow = paint("33", "39");
17
+ export const bold = paint("1", "22");
@@ -0,0 +1,40 @@
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
+
5
+ import { definePlugin, type UI } from "../../src/api.ts";
6
+ import { autoUpdate, autoUpdateEnabled, detectInstall, newerVersion, VERSION, type Install } from "../../src/update.ts";
7
+
8
+ export interface CheckOptions {
9
+ home: string;
10
+ auto: boolean;
11
+ notify: (message: string, level?: "info" | "warning") => void;
12
+ install?: Install;
13
+ /** 测试用 */
14
+ latest?: () => Promise<string>;
15
+ command?: string[];
16
+ }
17
+
18
+ /** 查一次,按结果提示;出什么错都不打扰用户 */
19
+ export async function checkForUpdate(o: CheckOptions): Promise<void> {
20
+ const install = o.install ?? detectInstall();
21
+ if (install.kind === "dev") return;
22
+ const latest = await newerVersion(o.home, o.latest ? { latest: o.latest } : {}).catch(() => undefined);
23
+ if (!latest) return;
24
+ const manual = () => o.notify(`jade ${latest} is available (you have ${VERSION}); run jade update`);
25
+ if (!o.auto || !autoUpdateEnabled()) return manual();
26
+ const result = await autoUpdate(o.home, latest, { install, ...(o.command ? { command: o.command } : {}) }).catch(() => undefined);
27
+ if (result?.status === "installed") o.notify(`jade ${latest} was installed in the background; restart jade to use it`);
28
+ else if (result?.status === "failed") o.notify(`automatic update to jade ${latest} failed (see ${result.log}); run jade update`, "warning");
29
+ else if (result?.status !== "skipped" || result.why !== "busy") manual();
30
+ }
31
+
32
+ export default definePlugin({
33
+ process(ctx) {
34
+ const ui = ctx.service<UI>("ui@1");
35
+ // 不能提问的前端(jade -p)是脚本在用,不提示也不升级
36
+ if (!ui?.interactive) return;
37
+ // 作用域关闭后 ui 失效,再提示会抛错:那时也没人看了
38
+ void checkForUpdate({ home: ctx.home, auto: ctx.config.auto !== false, notify: (m, level) => ui.notify(m, level) }).catch(() => {});
39
+ },
40
+ });
@@ -0,0 +1,13 @@
1
+ {
2
+ "id": "jade/update",
3
+ "version": "0.1.0",
4
+ "api": "^1",
5
+ "entry": "./index.ts",
6
+ "optional": ["ui@1"],
7
+ "config": {
8
+ "auto": {
9
+ "default": true,
10
+ "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"
11
+ }
12
+ }
13
+ }
@@ -0,0 +1,78 @@
1
+ // 搜索服务的 API key:shell 里的环境变量 + $JADE_HOME/.env(shell 里已经设置的优先),和 jade/models 读同一个文件。
2
+ // 从旧 jade 的 config.ts 复制:插件之间不共享代码,jade/models 也有一份 parseEnv。
3
+
4
+ import { mkdir, readFile, writeFile } from "node:fs/promises";
5
+ import path from "node:path";
6
+
7
+ export type Env = Record<string, string | undefined>;
8
+
9
+ /** 解析 KEY=VALUE 格式:忽略空行和 # 注释,允许 export 前缀,去掉成对的引号(双引号里的 \n 换成换行) */
10
+ export function parseEnv(text: string): Record<string, string> {
11
+ const out: Record<string, string> = {};
12
+ for (const raw of text.split(/\r?\n/)) {
13
+ const m = /^\s*(?:export\s+)?([A-Za-z_][A-Za-z0-9_]*)\s*=\s*(.*?)\s*$/.exec(raw);
14
+ if (!m) continue;
15
+ let value = m[2]!;
16
+ const quote = value[0];
17
+ if ((quote === '"' || quote === "'") && value.length >= 2 && value.endsWith(quote)) {
18
+ value = value.slice(1, -1);
19
+ if (quote === '"') value = value.replaceAll("\\n", "\n");
20
+ } else {
21
+ // 未加引号的值里,空白之后的 # 是注释
22
+ value = value.replace(/\s+#.*$/, "");
23
+ }
24
+ out[m[1]!] = value;
25
+ }
26
+ return out;
27
+ }
28
+
29
+ /** 配置文件里的变量,env 里已有的优先;文件不存在时就是 env */
30
+ export async function envWithFile(file: string, env: Env = process.env): Promise<Env> {
31
+ let text = "";
32
+ try {
33
+ text = await readFile(file, "utf8");
34
+ } catch {
35
+ // 没有配置文件
36
+ }
37
+ return { ...parseEnv(text), ...Object.fromEntries(Object.entries(env).filter(([, v]) => v !== undefined)) };
38
+ }
39
+
40
+ /**
41
+ * 改写配置文件里的变量:已有的行原地替换,没有的追加在末尾,值为 undefined 的删除;注释和其他行保持不变。
42
+ * 同时更新 env,让改动在本次运行中生效
43
+ */
44
+ export async function updateEnvFile(file: string, updates: Env, env: Env): Promise<void> {
45
+ let text = "";
46
+ try {
47
+ text = await readFile(file, "utf8");
48
+ } catch {
49
+ // 还没有配置文件
50
+ }
51
+ const lines = text ? text.replace(/\r?\n$/, "").split(/\r?\n/) : [];
52
+ const out: string[] = [];
53
+ const written = new Set<string>();
54
+ for (const raw of lines) {
55
+ const key = /^\s*(?:export\s+)?([A-Za-z_][A-Za-z0-9_]*)\s*=/.exec(raw)?.[1];
56
+ if (!key || !(key in updates)) {
57
+ out.push(raw);
58
+ continue;
59
+ }
60
+ // 同一个键出现多次时只保留第一处
61
+ const value = updates[key];
62
+ if (value !== undefined && !written.has(key)) 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)) out.push(format(key, value));
67
+ }
68
+ await mkdir(path.dirname(file), { recursive: true });
69
+ await writeFile(file, out.join("\n") + "\n");
70
+ for (const [key, value] of Object.entries(updates)) {
71
+ if (value === undefined) delete env[key];
72
+ else env[key] = value;
73
+ }
74
+ }
75
+
76
+ function format(key: string, value: string): string {
77
+ return /[\s#"']/.test(value) ? `${key}="${value.replaceAll("\n", "\\n")}"` : `${key}=${value}`;
78
+ }
@@ -0,0 +1,133 @@
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
+
7
+ import path from "node:path";
8
+ import { definePlugin, type ScopeContext, type UI } from "../../src/api.ts";
9
+ import type { Commands } from "../commands/index.ts";
10
+ import type { Prompts } from "../prompts/index.ts";
11
+ import type { Renderers } from "../renderers/index.ts";
12
+ import type { Task } from "../task/index.ts";
13
+ import { envWithFile, updateEnvFile, type Env } from "./env.ts";
14
+ import { webRenderers } from "./renderers.ts";
15
+ import { parseOrder, parseResults, SEARCH_PROVIDERS, webTools } from "./web.ts";
16
+
17
+ // 设了 NO_COLOR(非空)或标准输出不是终端时不输出颜色,见 https://no-color.org
18
+ const colors = Boolean(process.stdout.isTTY) && !process.env.NO_COLOR;
19
+ const dim = (s: string) => (colors ? `\x1b[2m${s}\x1b[22m` : s);
20
+ const green = (s: string) => (colors ? `\x1b[32m${s}\x1b[39m` : s);
21
+
22
+ /**
23
+ * API key 所在的环境:每次开会话时重新读,/search 改了之后原地更新。模块每个进程只加载一次,进程级的命令和会话级的工具共用
24
+ */
25
+ let keys: Env | undefined;
26
+ /** 撤销当前会话里"web_search 没打开"的提示词段落;/search 打开搜索后调用 */
27
+ let offNote: (() => void) | undefined;
28
+
29
+ const envFile = (ctx: ScopeContext) => path.join(ctx.home, ".env");
30
+
31
+ /** 配置项,旧 jade 的环境变量 JADE_SEARCH、JADE_SEARCH_RESULTS 仍然有效(配置项优先);不合法时抛错 */
32
+ function settings(ctx: ScopeContext, env: Env): { order?: string[]; results: number } {
33
+ const fromConfig = ctx.config.search !== undefined && ctx.config.search !== null;
34
+ const order = parseOrder(fromConfig ? ctx.config.search : env.JADE_SEARCH, fromConfig ? "jade/web config search" : "JADE_SEARCH");
35
+ const counted = ctx.config.results !== undefined && ctx.config.results !== null;
36
+ const results = parseResults(counted ? ctx.config.results : env.JADE_SEARCH_RESULTS, counted ? "jade/web config results" : "JADE_SEARCH_RESULTS");
37
+ return { ...(order ? { order } : {}), results };
38
+ }
39
+
40
+ export default definePlugin({
41
+ process(ctx) {
42
+ const renderers = ctx.service<Renderers>("renderers@1");
43
+ if (renderers) for (const r of webRenderers) renderers.tool(r);
44
+
45
+ ctx.service<Commands>("commands@1")?.register({
46
+ name: "search",
47
+ description: "set up web search services (TinyFish, AnySearch, Tavily, Exa, Firecrawl, Jina)",
48
+ async run(_args, c) {
49
+ const file = envFile(ctx);
50
+ const env = (keys ??= await envWithFile(file));
51
+ const on = SEARCH_PROVIDERS.filter((p) => env[p.env]);
52
+ const name = await c.ui.select(
53
+ {
54
+ 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",
55
+ options: SEARCH_PROVIDERS.map((p) => ({ label: `${p.name}${env[p.env] ? " ✓" : ""}`, value: p.name, hint: p.signup })),
56
+ },
57
+ c.signal,
58
+ );
59
+ const p = SEARCH_PROVIDERS.find((x) => x.name === name);
60
+ if (!p) return;
61
+ // shell 里的变量盖过文件:改文件只在这个会话里看起来生效,下一个会话又变回 shell 里的值
62
+ if (process.env[p.env]) return `${p.env} is set in your shell environment, which takes precedence over ${file}; change or unset it there.`;
63
+ if (env[p.env]) {
64
+ const choice = await c.ui.select(
65
+ {
66
+ title: p.name,
67
+ options: [
68
+ { label: "Change the API key…", value: "set" as const },
69
+ { label: "Remove", value: "off" as const, hint: `removes ${p.env} from ${file}` },
70
+ ],
71
+ },
72
+ c.signal,
73
+ );
74
+ if (!choice) return;
75
+ if (choice === "off") {
76
+ await updateEnvFile(file, { [p.env]: undefined }, env);
77
+ return dim(`${p.name} removed.${on.length > 1 ? "" : " Web search is off."}`);
78
+ }
79
+ }
80
+ const key = (await c.ui.input({ title: `${p.name} API key`, mask: true }, c.signal))?.trim();
81
+ if (!key) return;
82
+ await updateEnvFile(file, { [p.env]: key }, env);
83
+ offNote?.();
84
+ offNote = undefined;
85
+ 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.`);
86
+ },
87
+ });
88
+ },
89
+
90
+ async session(ctx) {
91
+ const env = (keys = await envWithFile(envFile(ctx)));
92
+ let opts: { order?: string[]; results: number };
93
+ try {
94
+ opts = settings(ctx, env);
95
+ } catch (e) {
96
+ // 写错的配置不让 web_fetch 也用不了:搜索按默认设置
97
+ ctx.service<UI>("ui@1")?.notify(`${(e as Error).message}; using the default search settings`, "warning");
98
+ opts = { results: parseResults(undefined, "") };
99
+ }
100
+ // keys 换成新的对象(新会话、/search 之前)时也取当前的那个
101
+ const web = webTools({ ...opts, env: () => keys ?? env });
102
+ for (const tool of web.tools) ctx.kernel.tool(tool);
103
+
104
+ // 子 Agent(jade/task)也能查网页:另一套实例;web_search 只在配置了搜索服务时给它。
105
+ // web_fetch 带 url 参数,子 Agent 每次都要问用户(URL 能把读到的内容带出去)。
106
+ // jade/task 被隔离时它的服务已失效:子 Agent 没有 web 工具,web 工具本身照常
107
+ try {
108
+ const task = ctx.service<Task>("task@1");
109
+ if (task) {
110
+ const sub = webTools({ ...opts, env: () => keys ?? env });
111
+ for (const tool of sub.tools) task.tool(tool, tool.name === "web_search" ? { when: () => sub.search().length > 0 } : {});
112
+ }
113
+ } catch {}
114
+
115
+ ctx.kernel.hook({
116
+ kind: "transform",
117
+ point: "context.build",
118
+ fn: (req) => (web.search().length ? req : { ...req, tools: req.tools.filter((t) => t.name !== "web_search") }),
119
+ });
120
+ // 没有搜索时告诉模型用户可以打开它;有搜索时不用说
121
+ offNote = undefined;
122
+ if (web.search().length === 0 && ctx.service<Commands>("commands@1")) {
123
+ const remove = ctx.service<Prompts>("prompts@1")?.add({ text: "- web_search is off; if you need to search the web, the user can turn it on with /search." });
124
+ if (remove) {
125
+ offNote = remove;
126
+ // 会话关闭时段落随作用域撤销,这里只忘掉它
127
+ await ctx.effect(() => () => {
128
+ if (offNote === remove) offNote = undefined;
129
+ });
130
+ }
131
+ }
132
+ },
133
+ });