@uncarved/jade 0.1.2 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (436) hide show
  1. package/bin/jade.js +5 -4
  2. package/dist/api.d.ts +266 -0
  3. package/dist/api.js +38 -0
  4. package/dist/api.js.map +1 -0
  5. package/dist/config.d.ts +13 -32
  6. package/dist/config.js +39 -121
  7. package/dist/config.js.map +1 -1
  8. package/dist/fetch.d.ts +20 -0
  9. package/dist/fetch.js +190 -0
  10. package/dist/fetch.js.map +1 -0
  11. package/dist/hash.d.ts +2 -0
  12. package/dist/hash.js +42 -0
  13. package/dist/hash.js.map +1 -0
  14. package/dist/host.d.ts +71 -0
  15. package/dist/host.js +400 -0
  16. package/dist/host.js.map +1 -0
  17. package/dist/index.d.ts +11 -28
  18. package/dist/index.js +11 -28
  19. package/dist/index.js.map +1 -1
  20. package/dist/install.d.ts +78 -0
  21. package/dist/install.js +292 -0
  22. package/dist/install.js.map +1 -0
  23. package/dist/main.d.ts +1 -2
  24. package/dist/main.js +156 -1223
  25. package/dist/main.js.map +1 -1
  26. package/dist/manifest.d.ts +23 -0
  27. package/dist/manifest.js +159 -0
  28. package/dist/manifest.js.map +1 -0
  29. package/dist/membrane.d.ts +33 -0
  30. package/dist/membrane.js +140 -0
  31. package/dist/membrane.js.map +1 -0
  32. package/dist/remote.d.ts +10 -0
  33. package/dist/remote.js +292 -0
  34. package/dist/remote.js.map +1 -0
  35. package/dist/rescue.d.ts +10 -0
  36. package/dist/rescue.js +216 -0
  37. package/dist/rescue.js.map +1 -0
  38. package/dist/resolve.d.ts +34 -0
  39. package/dist/resolve.js +178 -0
  40. package/dist/resolve.js.map +1 -0
  41. package/dist/rpc.d.ts +26 -0
  42. package/dist/rpc.js +144 -0
  43. package/dist/rpc.js.map +1 -0
  44. package/dist/secrets.d.ts +12 -0
  45. package/dist/secrets.js +125 -0
  46. package/dist/secrets.js.map +1 -0
  47. package/dist/session.d.ts +45 -0
  48. package/dist/session.js +401 -0
  49. package/dist/session.js.map +1 -0
  50. package/dist/source.d.ts +12 -0
  51. package/dist/source.js +72 -0
  52. package/dist/source.js.map +1 -0
  53. package/dist/state.d.ts +37 -0
  54. package/dist/state.js +93 -0
  55. package/dist/state.js.map +1 -0
  56. package/dist/update.d.ts +55 -0
  57. package/dist/update.js +258 -0
  58. package/dist/update.js.map +1 -0
  59. package/package.json +12 -9
  60. package/plugins/approval/index.ts +297 -0
  61. package/plugins/approval/plugin.json +18 -0
  62. package/{src/plugins → plugins/approval}/policy.ts +21 -84
  63. package/plugins/approval/review.ts +192 -0
  64. package/plugins/ask/index.ts +159 -0
  65. package/plugins/ask/plugin.json +8 -0
  66. package/plugins/budget/index.ts +38 -0
  67. package/plugins/budget/plugin.json +13 -0
  68. package/{src/plugins → plugins/checks}/checks.ts +68 -39
  69. package/plugins/checks/index.ts +158 -0
  70. package/plugins/checks/plugin.json +14 -0
  71. package/plugins/checks/project.ts +81 -0
  72. package/plugins/commands/index.ts +76 -0
  73. package/plugins/commands/plugin.json +7 -0
  74. package/{src/plugins → plugins/compact}/compact.ts +112 -38
  75. package/plugins/compact/index.ts +115 -0
  76. package/plugins/compact/plugin.json +17 -0
  77. package/plugins/compact/style.ts +17 -0
  78. package/plugins/continue/index.ts +58 -0
  79. package/plugins/continue/plugin.json +13 -0
  80. package/{src/ui → plugins/fs}/diff.ts +3 -4
  81. package/{src/tools → plugins/fs}/fs.ts +64 -46
  82. package/{src/tools → plugins/fs}/grep.ts +4 -3
  83. package/plugins/fs/index.ts +34 -0
  84. package/plugins/fs/plugin.json +7 -0
  85. package/plugins/fs/renderers.ts +138 -0
  86. package/plugins/fs/style.ts +18 -0
  87. package/plugins/fs/sys.ts +81 -0
  88. package/plugins/keys/index.ts +53 -0
  89. package/plugins/keys/plugin.json +7 -0
  90. package/plugins/mcp/index.ts +192 -0
  91. package/{src → plugins/mcp}/mcp.ts +32 -32
  92. package/plugins/mcp/plugin.json +7 -0
  93. package/plugins/mcp/project.ts +93 -0
  94. package/plugins/memory/index.ts +105 -0
  95. package/{src → plugins/memory}/memory.ts +20 -2
  96. package/plugins/memory/notes.ts +43 -0
  97. package/plugins/memory/plugin.json +7 -0
  98. package/plugins/memory/style.ts +17 -0
  99. package/plugins/mentions/attach.ts +127 -0
  100. package/plugins/mentions/index.ts +79 -0
  101. package/plugins/mentions/plugin.json +7 -0
  102. package/plugins/mentions/style.ts +17 -0
  103. package/plugins/models/config.ts +53 -0
  104. package/plugins/models/configure.ts +455 -0
  105. package/plugins/models/context.ts +32 -0
  106. package/plugins/models/index.ts +198 -0
  107. package/plugins/models/plugin.json +8 -0
  108. package/{src → plugins/models}/provider.ts +23 -27
  109. package/plugins/models/saved.ts +94 -0
  110. package/plugins/modes/index.ts +222 -0
  111. package/plugins/modes/plugin.json +9 -0
  112. package/plugins/plugins/index.ts +38 -0
  113. package/plugins/plugins/plugin.json +7 -0
  114. package/plugins/print/index.ts +142 -0
  115. package/plugins/print/plugin.json +8 -0
  116. package/plugins/prompts/index.ts +83 -0
  117. package/plugins/prompts/plugin.json +8 -0
  118. package/plugins/prompts/prompts.ts +253 -0
  119. package/plugins/prompts/sys.ts +72 -0
  120. package/plugins/renderers/index.ts +78 -0
  121. package/plugins/renderers/plugin.json +7 -0
  122. package/plugins/repeats/index.ts +165 -0
  123. package/plugins/repeats/plugin.json +6 -0
  124. package/plugins/schedule/cron.ts +74 -0
  125. package/plugins/schedule/index.ts +292 -0
  126. package/plugins/schedule/plugin.json +13 -0
  127. package/plugins/schedule/store.ts +149 -0
  128. package/plugins/scratch/index.ts +31 -0
  129. package/plugins/scratch/plugin.json +7 -0
  130. package/plugins/screenshot/index.ts +40 -0
  131. package/plugins/screenshot/plugin.json +7 -0
  132. package/plugins/screenshot/sys.ts +84 -0
  133. package/{src/tools/screenshot.ts → plugins/screenshot/tool.ts} +6 -6
  134. package/plugins/sessions/index.ts +148 -0
  135. package/plugins/sessions/plugin.json +8 -0
  136. package/plugins/shell/index.ts +33 -0
  137. package/plugins/shell/plugin.json +17 -0
  138. package/plugins/shell/renderers.ts +45 -0
  139. package/plugins/shell/service.ts +44 -0
  140. package/{src/tools → plugins/shell}/shell.ts +36 -21
  141. package/{src → plugins/shell}/sys.ts +19 -43
  142. package/plugins/skills/index.ts +96 -0
  143. package/plugins/skills/plugin.json +7 -0
  144. package/plugins/skills/project.ts +49 -0
  145. package/{src → plugins/skills}/skills.ts +4 -11
  146. package/plugins/suggest/index.ts +286 -0
  147. package/plugins/suggest/plugin.json +18 -0
  148. package/plugins/task/index.ts +167 -0
  149. package/plugins/task/plugin.json +15 -0
  150. package/plugins/task/style.ts +17 -0
  151. package/plugins/task/subagent.ts +257 -0
  152. package/{src/tools/todo.ts → plugins/todo/index.ts} +33 -7
  153. package/plugins/todo/plugin.json +7 -0
  154. package/{src/ui → plugins/tui}/editor.ts +53 -1
  155. package/plugins/tui/frontend.ts +596 -0
  156. package/plugins/tui/index.ts +37 -0
  157. package/{src/ui → plugins/tui}/markdown.ts +258 -219
  158. package/plugins/tui/mentions.ts +113 -0
  159. package/plugins/tui/plugin.json +10 -0
  160. package/plugins/tui/render.ts +67 -0
  161. package/plugins/tui/screen.ts +268 -0
  162. package/{src/ui → plugins/tui}/transcript.ts +179 -111
  163. package/{src/ui/tui.tsx → plugins/tui/tui.ts} +684 -418
  164. package/{src/tools → plugins/undo}/checkpoint.ts +21 -60
  165. package/plugins/undo/index.ts +139 -0
  166. package/plugins/undo/notes.ts +43 -0
  167. package/plugins/undo/plugin.json +7 -0
  168. package/plugins/undo/style.ts +17 -0
  169. package/plugins/update/index.ts +40 -0
  170. package/plugins/update/plugin.json +13 -0
  171. package/plugins/web/env.ts +78 -0
  172. package/plugins/web/index.ts +133 -0
  173. package/plugins/web/plugin.json +15 -0
  174. package/plugins/web/renderers.ts +11 -0
  175. package/plugins/web/web.ts +713 -0
  176. package/plugins-dist/approval/index.js +271 -0
  177. package/plugins-dist/approval/plugin.json +24 -0
  178. package/{dist/plugins → plugins-dist/approval}/policy.js +15 -65
  179. package/plugins-dist/approval/review.js +176 -0
  180. package/{dist/plugins → plugins-dist/approval}/schema.js +0 -1
  181. package/plugins-dist/ask/index.js +145 -0
  182. package/plugins-dist/ask/plugin.json +12 -0
  183. package/plugins-dist/budget/index.js +37 -0
  184. package/plugins-dist/budget/plugin.json +15 -0
  185. package/{dist/plugins → plugins-dist/checks}/checks.js +65 -34
  186. package/plugins-dist/checks/index.js +150 -0
  187. package/plugins-dist/checks/plugin.json +21 -0
  188. package/plugins-dist/checks/project.js +76 -0
  189. package/plugins-dist/commands/index.js +33 -0
  190. package/plugins-dist/commands/plugin.json +9 -0
  191. package/{dist/plugins → plugins-dist/compact}/compact.js +95 -33
  192. package/plugins-dist/compact/index.js +100 -0
  193. package/plugins-dist/compact/plugin.json +25 -0
  194. package/plugins-dist/compact/style.js +14 -0
  195. package/plugins-dist/continue/index.js +57 -0
  196. package/plugins-dist/continue/plugin.json +15 -0
  197. package/{dist/ui → plugins-dist/fs}/diff.js +3 -5
  198. package/{dist/tools → plugins-dist/fs}/fs.js +62 -46
  199. package/{dist/tools → plugins-dist/fs}/grep.js +4 -4
  200. package/plugins-dist/fs/index.js +36 -0
  201. package/plugins-dist/fs/plugin.json +10 -0
  202. package/plugins-dist/fs/renderers.js +132 -0
  203. package/plugins-dist/fs/style.js +15 -0
  204. package/plugins-dist/fs/sys.js +54 -0
  205. package/plugins-dist/keys/index.js +36 -0
  206. package/plugins-dist/keys/plugin.json +9 -0
  207. package/plugins-dist/mcp/index.js +187 -0
  208. package/{dist → plugins-dist/mcp}/mcp.js +34 -30
  209. package/plugins-dist/mcp/plugin.json +12 -0
  210. package/plugins-dist/mcp/project.js +90 -0
  211. package/plugins-dist/memory/index.js +94 -0
  212. package/{dist → plugins-dist/memory}/memory.js +21 -3
  213. package/plugins-dist/memory/notes.js +36 -0
  214. package/plugins-dist/memory/plugin.json +11 -0
  215. package/plugins-dist/memory/style.js +14 -0
  216. package/plugins-dist/mentions/attach.js +120 -0
  217. package/plugins-dist/mentions/index.js +69 -0
  218. package/plugins-dist/mentions/plugin.json +9 -0
  219. package/plugins-dist/mentions/style.js +14 -0
  220. package/plugins-dist/models/config.js +53 -0
  221. package/plugins-dist/models/configure.js +415 -0
  222. package/plugins-dist/models/context.js +27 -0
  223. package/plugins-dist/models/index.js +167 -0
  224. package/plugins-dist/models/plugin.json +14 -0
  225. package/{dist → plugins-dist/models}/provider.js +22 -19
  226. package/plugins-dist/models/saved.js +80 -0
  227. package/plugins-dist/modes/index.js +190 -0
  228. package/plugins-dist/modes/plugin.json +18 -0
  229. package/plugins-dist/plugins/index.js +37 -0
  230. package/plugins-dist/plugins/plugin.json +10 -0
  231. package/plugins-dist/print/index.js +153 -0
  232. package/plugins-dist/print/plugin.json +14 -0
  233. package/plugins-dist/prompts/index.js +57 -0
  234. package/plugins-dist/prompts/plugin.json +13 -0
  235. package/plugins-dist/prompts/prompts.js +227 -0
  236. package/plugins-dist/prompts/sys.js +46 -0
  237. package/plugins-dist/renderers/index.js +36 -0
  238. package/plugins-dist/renderers/plugin.json +9 -0
  239. package/plugins-dist/repeats/index.js +165 -0
  240. package/plugins-dist/repeats/plugin.json +6 -0
  241. package/plugins-dist/schedule/cron.js +67 -0
  242. package/plugins-dist/schedule/index.js +281 -0
  243. package/plugins-dist/schedule/plugin.json +16 -0
  244. package/plugins-dist/schedule/store.js +125 -0
  245. package/plugins-dist/scratch/index.js +26 -0
  246. package/plugins-dist/scratch/plugin.json +10 -0
  247. package/plugins-dist/screenshot/index.js +35 -0
  248. package/plugins-dist/screenshot/plugin.json +11 -0
  249. package/plugins-dist/screenshot/sys.js +76 -0
  250. package/{dist/tools/screenshot.js → plugins-dist/screenshot/tool.js} +5 -4
  251. package/plugins-dist/sessions/index.js +136 -0
  252. package/plugins-dist/sessions/plugin.json +12 -0
  253. package/plugins-dist/shell/index.js +33 -0
  254. package/plugins-dist/shell/plugin.json +19 -0
  255. package/plugins-dist/shell/renderers.js +40 -0
  256. package/plugins-dist/shell/service.js +29 -0
  257. package/{dist/tools → plugins-dist/shell}/shell.js +36 -23
  258. package/{dist → plugins-dist/shell}/sys.js +20 -44
  259. package/plugins-dist/skills/index.js +90 -0
  260. package/plugins-dist/skills/plugin.json +12 -0
  261. package/plugins-dist/skills/project.js +47 -0
  262. package/{dist → plugins-dist/skills}/skills.js +3 -7
  263. package/plugins-dist/suggest/index.js +282 -0
  264. package/plugins-dist/suggest/plugin.json +23 -0
  265. package/plugins-dist/task/index.js +151 -0
  266. package/plugins-dist/task/plugin.json +23 -0
  267. package/plugins-dist/task/style.js +14 -0
  268. package/plugins-dist/task/subagent.js +208 -0
  269. package/{dist/tools/todo.js → plugins-dist/todo/index.js} +29 -7
  270. package/plugins-dist/todo/plugin.json +9 -0
  271. package/{dist/ui → plugins-dist/tui}/editor.js +53 -2
  272. package/plugins-dist/tui/frontend.js +586 -0
  273. package/{dist → plugins-dist/tui}/history.js +0 -1
  274. package/plugins-dist/tui/index.js +21 -0
  275. package/{dist/ui → plugins-dist/tui}/markdown.js +57 -20
  276. package/plugins-dist/tui/mentions.js +115 -0
  277. package/plugins-dist/tui/plugin.json +25 -0
  278. package/plugins-dist/tui/render.js +61 -0
  279. package/plugins-dist/tui/screen.js +201 -0
  280. package/{dist/ui → plugins-dist/tui}/transcript.js +179 -111
  281. package/{dist/ui → plugins-dist/tui}/tui.js +484 -101
  282. package/{dist/tools → plugins-dist/undo}/checkpoint.js +21 -55
  283. package/plugins-dist/undo/index.js +140 -0
  284. package/plugins-dist/undo/notes.js +36 -0
  285. package/plugins-dist/undo/plugin.json +9 -0
  286. package/plugins-dist/undo/style.js +14 -0
  287. package/plugins-dist/update/index.js +34 -0
  288. package/plugins-dist/update/plugin.json +15 -0
  289. package/plugins-dist/web/env.js +80 -0
  290. package/plugins-dist/web/index.js +124 -0
  291. package/plugins-dist/web/plugin.json +21 -0
  292. package/plugins-dist/web/renderers.js +7 -0
  293. package/plugins-dist/web/web.js +660 -0
  294. package/sdk/python/__pycache__/jade_plugin.cpython-312.pyc +0 -0
  295. package/sdk/python/jade_plugin.py +380 -0
  296. package/src/api.ts +298 -0
  297. package/src/config.ts +32 -134
  298. package/src/fetch.ts +216 -0
  299. package/src/hash.ts +39 -0
  300. package/src/host.ts +429 -0
  301. package/src/index.ts +23 -28
  302. package/src/install.ts +355 -0
  303. package/src/main.ts +152 -1263
  304. package/src/manifest.ts +160 -0
  305. package/src/membrane.ts +142 -0
  306. package/src/remote.ts +288 -0
  307. package/src/rescue.ts +217 -0
  308. package/src/resolve.ts +199 -0
  309. package/src/rpc.ts +144 -0
  310. package/src/secrets.ts +122 -0
  311. package/src/session.ts +458 -0
  312. package/src/source.ts +83 -0
  313. package/src/state.ts +120 -0
  314. package/src/update.ts +265 -0
  315. package/LICENSE +0 -21
  316. package/README.md +0 -198
  317. package/dist/commands.d.ts +0 -30
  318. package/dist/commands.js +0 -106
  319. package/dist/commands.js.map +0 -1
  320. package/dist/context.d.ts +0 -17
  321. package/dist/context.js +0 -53
  322. package/dist/context.js.map +0 -1
  323. package/dist/distro.d.ts +0 -104
  324. package/dist/distro.js +0 -312
  325. package/dist/distro.js.map +0 -1
  326. package/dist/history.d.ts +0 -10
  327. package/dist/history.js.map +0 -1
  328. package/dist/mcp.d.ts +0 -114
  329. package/dist/mcp.js.map +0 -1
  330. package/dist/memory.d.ts +0 -19
  331. package/dist/memory.js.map +0 -1
  332. package/dist/mentions.d.ts +0 -35
  333. package/dist/mentions.js +0 -130
  334. package/dist/mentions.js.map +0 -1
  335. package/dist/plugin-cli.d.ts +0 -16
  336. package/dist/plugin-cli.js +0 -251
  337. package/dist/plugin-cli.js.map +0 -1
  338. package/dist/plugins/budget.d.ts +0 -9
  339. package/dist/plugins/budget.js +0 -30
  340. package/dist/plugins/budget.js.map +0 -1
  341. package/dist/plugins/builtins.d.ts +0 -10
  342. package/dist/plugins/builtins.js +0 -22
  343. package/dist/plugins/builtins.js.map +0 -1
  344. package/dist/plugins/checks.d.ts +0 -70
  345. package/dist/plugins/checks.js.map +0 -1
  346. package/dist/plugins/compact.d.ts +0 -26
  347. package/dist/plugins/compact.js.map +0 -1
  348. package/dist/plugins/core.d.ts +0 -42
  349. package/dist/plugins/core.js +0 -190
  350. package/dist/plugins/core.js.map +0 -1
  351. package/dist/plugins/install.d.ts +0 -68
  352. package/dist/plugins/install.js +0 -377
  353. package/dist/plugins/install.js.map +0 -1
  354. package/dist/plugins/loader.d.ts +0 -182
  355. package/dist/plugins/loader.js +0 -253
  356. package/dist/plugins/loader.js.map +0 -1
  357. package/dist/plugins/policy.d.ts +0 -96
  358. package/dist/plugins/policy.js.map +0 -1
  359. package/dist/plugins/prompts.d.ts +0 -38
  360. package/dist/plugins/prompts.js +0 -196
  361. package/dist/plugins/prompts.js.map +0 -1
  362. package/dist/plugins/repeats.d.ts +0 -9
  363. package/dist/plugins/repeats.js +0 -90
  364. package/dist/plugins/repeats.js.map +0 -1
  365. package/dist/plugins/review.d.ts +0 -16
  366. package/dist/plugins/review.js +0 -92
  367. package/dist/plugins/review.js.map +0 -1
  368. package/dist/plugins/schema.d.ts +0 -2
  369. package/dist/plugins/schema.js.map +0 -1
  370. package/dist/provider.d.ts +0 -111
  371. package/dist/provider.js.map +0 -1
  372. package/dist/sessions.d.ts +0 -22
  373. package/dist/sessions.js +0 -53
  374. package/dist/sessions.js.map +0 -1
  375. package/dist/skills.d.ts +0 -37
  376. package/dist/skills.js.map +0 -1
  377. package/dist/sys.d.ts +0 -48
  378. package/dist/sys.js.map +0 -1
  379. package/dist/tools/checkpoint.d.ts +0 -43
  380. package/dist/tools/checkpoint.js.map +0 -1
  381. package/dist/tools/fs.d.ts +0 -35
  382. package/dist/tools/fs.js.map +0 -1
  383. package/dist/tools/grep.d.ts +0 -6
  384. package/dist/tools/grep.js.map +0 -1
  385. package/dist/tools/screenshot.d.ts +0 -15
  386. package/dist/tools/screenshot.js.map +0 -1
  387. package/dist/tools/shell.d.ts +0 -55
  388. package/dist/tools/shell.js.map +0 -1
  389. package/dist/tools/task.d.ts +0 -35
  390. package/dist/tools/task.js +0 -89
  391. package/dist/tools/task.js.map +0 -1
  392. package/dist/tools/todo.d.ts +0 -10
  393. package/dist/tools/todo.js.map +0 -1
  394. package/dist/tools/web.d.ts +0 -23
  395. package/dist/tools/web.js +0 -426
  396. package/dist/tools/web.js.map +0 -1
  397. package/dist/ui/configure.d.ts +0 -20
  398. package/dist/ui/configure.js +0 -378
  399. package/dist/ui/configure.js.map +0 -1
  400. package/dist/ui/diff.d.ts +0 -20
  401. package/dist/ui/diff.js.map +0 -1
  402. package/dist/ui/editor.d.ts +0 -33
  403. package/dist/ui/editor.js.map +0 -1
  404. package/dist/ui/markdown.d.ts +0 -17
  405. package/dist/ui/markdown.js.map +0 -1
  406. package/dist/ui/render.d.ts +0 -15
  407. package/dist/ui/render.js +0 -94
  408. package/dist/ui/render.js.map +0 -1
  409. package/dist/ui/screen.d.ts +0 -98
  410. package/dist/ui/screen.js +0 -108
  411. package/dist/ui/screen.js.map +0 -1
  412. package/dist/ui/transcript.d.ts +0 -33
  413. package/dist/ui/transcript.js.map +0 -1
  414. package/dist/ui/tui.d.ts +0 -45
  415. package/dist/ui/tui.js.map +0 -1
  416. package/src/commands.ts +0 -120
  417. package/src/context.ts +0 -64
  418. package/src/distro.ts +0 -400
  419. package/src/mentions.ts +0 -135
  420. package/src/plugin-cli.ts +0 -239
  421. package/src/plugins/budget.ts +0 -37
  422. package/src/plugins/builtins.ts +0 -31
  423. package/src/plugins/core.ts +0 -217
  424. package/src/plugins/install.ts +0 -429
  425. package/src/plugins/loader.ts +0 -386
  426. package/src/plugins/prompts.ts +0 -234
  427. package/src/plugins/repeats.ts +0 -96
  428. package/src/plugins/review.ts +0 -109
  429. package/src/sessions.ts +0 -61
  430. package/src/tools/task.ts +0 -109
  431. package/src/tools/web.ts +0 -451
  432. package/src/ui/configure.ts +0 -408
  433. package/src/ui/render.ts +0 -83
  434. package/src/ui/screen.ts +0 -169
  435. /package/{src/plugins → plugins/approval}/schema.ts +0 -0
  436. /package/{src → plugins/tui}/history.ts +0 -0
@@ -145,6 +145,11 @@ function sleep(ms, signal) {
145
145
  });
146
146
  }
147
147
  export const PROVIDER_KINDS = ["openai-compat", "openai", "anthropic"];
148
+ export const isBuiltinKind = (kind) => PROVIDER_KINDS.includes(kind);
149
+ /** 每种内置服务的模型名、密钥、地址各放在哪个环境变量里 */
150
+ export const MODEL_KEY = { "openai-compat": "OPENAI_COMPAT_MODEL", openai: "OPENAI_MODEL", anthropic: "ANTHROPIC_MODEL" };
151
+ export const KEY_KEY = { "openai-compat": "OPENAI_COMPAT_API_KEY", openai: "OPENAI_API_KEY", anthropic: "ANTHROPIC_API_KEY" };
152
+ export const URL_KEY = { "openai-compat": "OPENAI_COMPAT_BASE_URL", openai: "OPENAI_BASE_URL", anthropic: "ANTHROPIC_BASE_URL" };
148
153
  /** JADE_EFFORT 可取的值;openai-compat 没有统一的字段,用 OPENAI_COMPAT_EXTRA_BODY 自己设 */
149
154
  export const EFFORTS = {
150
155
  anthropic: ["low", "medium", "high", "xhigh", "max"],
@@ -181,7 +186,7 @@ export function idleTimeoutFromEnv(env = process.env) {
181
186
  export function visionFromEnv(env = process.env) {
182
187
  const text = env.JADE_VISION?.trim().toLowerCase();
183
188
  if (!text)
184
- return providerKind(env) !== "openai-compat";
189
+ return providerKind(env) === "openai" || providerKind(env) === "anthropic";
185
190
  if (["1", "true", "on", "yes"].includes(text))
186
191
  return true;
187
192
  if (["0", "false", "off", "no"].includes(text))
@@ -194,6 +199,8 @@ export function effortFromEnv(env = process.env) {
194
199
  if (!effort)
195
200
  return undefined;
196
201
  const kind = providerKind(env);
202
+ if (!isBuiltinKind(kind))
203
+ return effort;
197
204
  const allowed = EFFORTS[kind];
198
205
  if (!allowed)
199
206
  throw new Error(`JADE_EFFORT is not supported for the ${kind} provider; set it in OPENAI_COMPAT_EXTRA_BODY instead`);
@@ -201,15 +208,11 @@ export function effortFromEnv(env = process.env) {
201
208
  throw new Error(`JADE_EFFORT must be one of ${allowed.join(", ")} for the ${kind} provider, got ${JSON.stringify(effort)}`);
202
209
  return effort;
203
210
  }
204
- /** JADE_PROVIDER 指定时用它;否则按 OPENAI_API_KEY、OPENAI_COMPAT_BASE_URL、ANTHROPIC_API_KEY 的顺序 */
211
+ /** JADE_PROVIDER 指定时用它;否则按 OPENAI_API_KEY、OPENAI_COMPAT_BASE_URL、ANTHROPIC_API_KEY 的顺序。不认识的名字原样返回,创建时报错 */
205
212
  export function providerKind(env = process.env) {
206
213
  const named = env.JADE_PROVIDER;
207
- if (named) {
208
- if (!PROVIDER_KINDS.includes(named)) {
209
- throw new Error(`JADE_PROVIDER must be one of ${PROVIDER_KINDS.join(", ")}, got ${JSON.stringify(named)}`);
210
- }
214
+ if (named)
211
215
  return named;
212
- }
213
216
  if (env.OPENAI_API_KEY)
214
217
  return "openai";
215
218
  if (env.OPENAI_COMPAT_BASE_URL)
@@ -240,6 +243,8 @@ export function providerInfo(env = process.env) {
240
243
  */
241
244
  export async function providerFromEnv(env = process.env) {
242
245
  const kind = providerKind(env);
246
+ if (!isBuiltinKind(kind))
247
+ throw new Error(`JADE_PROVIDER must be one of ${PROVIDER_KINDS.join(", ")}, got ${JSON.stringify(kind)}`);
243
248
  const maxTokens = env.JADE_MAX_TOKENS ? parseTokens("JADE_MAX_TOKENS", env.JADE_MAX_TOKENS) : undefined;
244
249
  const effort = effortFromEnv(env);
245
250
  // 写错时在这里就报错,不等到第一次请求
@@ -279,21 +284,20 @@ export async function providerFromEnv(env = process.env) {
279
284
  });
280
285
  }
281
286
  const { anthropicProvider } = await import("@uncarved/provider-anthropic");
282
- return anthropicProvider({ model: env.ANTHROPIC_MODEL, effort: (effort ?? "high"), maxTokens });
283
- }
284
- export function switchable(initial) {
285
- let current = initial;
286
- return {
287
- id: "switchable",
288
- set: (next) => {
289
- current = next;
290
- },
291
- complete: (request, options) => current.complete(request, options),
292
- };
287
+ // 地址和密钥从 env 取,不让 SDK 自己读 process.env:ctx.complete 指定的保存过的模型,env 不是 process.env
288
+ return anthropicProvider({
289
+ apiKey: env.ANTHROPIC_API_KEY,
290
+ baseURL: env.ANTHROPIC_BASE_URL ?? "https://api.anthropic.com",
291
+ model: env.ANTHROPIC_MODEL,
292
+ effort: (effort ?? "high"),
293
+ maxTokens,
294
+ });
293
295
  }
294
296
  /** 服务提供的模型列表;不支持或出错时返回空数组 */
295
297
  export async function listModels(env = process.env, fetchImpl = fetch) {
296
298
  const kind = providerKind(env);
299
+ if (!isBuiltinKind(kind))
300
+ return [];
297
301
  const info = providerInfo(env);
298
302
  const base = (info.baseURL ?? "https://api.anthropic.com").replace(/\/$/, "");
299
303
  const headers = kind === "anthropic"
@@ -327,4 +331,3 @@ function jsonObject(name, text) {
327
331
  throw new Error(`${name} must be a JSON object, got ${text}`);
328
332
  return value;
329
333
  }
330
- //# sourceMappingURL=provider.js.map
@@ -0,0 +1,80 @@
1
+ // 保存过的模型:$JADE_HOME/models.json。同一个服务(类型、地址、密钥都相同)只存一份,下面是在它上面用过的模型,
2
+ // 每个模型带自己的设置(输出上限、思考力度、上下文窗口)。.env 里始终是当前用的那一个,这里记着用过的全部,
3
+ // /model 可以切回去。
4
+ import { mkdir, readFile, writeFile } from "node:fs/promises";
5
+ import path from "node:path";
6
+ /** 每个模型自己的设置:切换模型时一起换掉 */
7
+ export const MODEL_SETTINGS = ["JADE_MAX_TOKENS", "JADE_EFFORT", "JADE_CONTEXT_WINDOW", "JADE_RPM", "JADE_VISION"];
8
+ const strings = (v) => typeof v === "object" && v !== null ? Object.fromEntries(Object.entries(v).filter(([, x]) => typeof x === "string")) : {};
9
+ /** 读不了或格式不对时返回空数组 */
10
+ export async function readSavedServices(file) {
11
+ try {
12
+ const data = JSON.parse(await readFile(file, "utf8"));
13
+ if (!Array.isArray(data.services))
14
+ return [];
15
+ return data.services.flatMap((raw) => {
16
+ const s = raw;
17
+ if (!s || !Array.isArray(s.models))
18
+ return [];
19
+ const models = s.models.flatMap((m) => {
20
+ const name = m?.name;
21
+ return typeof name === "string" && name ? [{ name, settings: strings(m.settings) }] : [];
22
+ });
23
+ return models.length ? [{ env: strings(s.env), models }] : [];
24
+ });
25
+ }
26
+ catch {
27
+ return [];
28
+ }
29
+ }
30
+ export async function writeSavedServices(file, services) {
31
+ await mkdir(path.dirname(file), { recursive: true });
32
+ // 里面有 API 密钥
33
+ await writeFile(file, JSON.stringify({ services }, null, 2) + "\n", { mode: 0o600 });
34
+ }
35
+ /**
36
+ * 改写配置文件里的变量:已有的行原地替换,没有的追加在末尾,值为 undefined 的删除;注释和其他行保持不变。
37
+ * 同时更新 env,让改动在本次运行中生效
38
+ */
39
+ export async function updateEnvFile(file, updates, env) {
40
+ let text = "";
41
+ try {
42
+ text = await readFile(file, "utf8");
43
+ }
44
+ catch {
45
+ // 还没有配置文件
46
+ }
47
+ const lines = text ? text.replace(/\r?\n$/, "").split(/\r?\n/) : [];
48
+ const out = [];
49
+ const written = new Set();
50
+ for (const raw of lines) {
51
+ const key = /^\s*(?:export\s+)?([A-Za-z_][A-Za-z0-9_]*)\s*=/.exec(raw)?.[1];
52
+ if (!key || !(key in updates)) {
53
+ out.push(raw);
54
+ continue;
55
+ }
56
+ // 同一个键出现多次时只保留第一处
57
+ const value = updates[key];
58
+ if (value !== undefined && !written.has(key))
59
+ out.push(format(key, value));
60
+ written.add(key);
61
+ }
62
+ for (const [key, value] of Object.entries(updates)) {
63
+ if (value !== undefined && !written.has(key))
64
+ out.push(format(key, value));
65
+ }
66
+ await mkdir(path.dirname(file), { recursive: true });
67
+ await writeFile(file, out.join("\n") + "\n");
68
+ for (const [key, value] of Object.entries(updates)) {
69
+ if (value === undefined)
70
+ delete env[key];
71
+ else
72
+ env[key] = value;
73
+ }
74
+ }
75
+ function format(key, value) {
76
+ if (!/[\s#"']/.test(value))
77
+ return `${key}=${value}`;
78
+ // 单引号里的内容原样读回(引号、反斜杠都不转义);只有换行要用双引号里的 \n
79
+ return value.includes("\n") ? `${key}="${value.replaceAll("\n", "\\n")}"` : `${key}='${value}'`;
80
+ }
@@ -0,0 +1,190 @@
1
+ // jade/modes:权限模式的切换。模式本身归 jade/approval(approval@1),这里提供切换方式和给前端显示的状态:
2
+ // Shift+Tab 在 ask → auto → plan 之间轮换,/mode 查看或选择,modes@1 让前端显示当前模式、在模式变化时更新。
3
+ //
4
+ // 计划模式的两件事也在这里:
5
+ // - 在 plan 模式时经 prompts@1 往系统提示词里加一段,告诉模型先给计划、不要改东西(切出去时去掉)
6
+ // - propose_plan 工具:模型写好要执行的计划后调用它,问用户要不要执行;批准了就换模式,工具结果告诉模型开始做。
7
+ // 由模型声明"这是要执行的计划",追问、回答问题、只要计划本身(比如健身计划)的回复不会被当成计划去问。
8
+ // 用户的选择在工具结果里,会话日志里看得到
9
+ import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
10
+ import path from "node:path";
11
+ import { definePlugin } from "../../dist/api.js";
12
+ export const DESCRIPTIONS = {
13
+ ask: "ask before edits and commands",
14
+ auto: "edits in this directory and harmless commands run without asking; others still ask",
15
+ plan: "change nothing: research read-only and propose a plan",
16
+ readonly: "change nothing",
17
+ yolo: "never ask",
18
+ };
19
+ const CYCLE = ["ask", "auto", "plan"];
20
+ /** 计划模式时加进系统提示词的段落;不能问用户(-p、非终端)时没有 propose_plan,只让模型给出计划后停下 */
21
+ export function planNote(canPropose) {
22
+ return ("The session is in plan mode. Investigate with read-only tools (and the task tool for broad searches); do not try to modify files " +
23
+ "or run commands that change anything, such calls are denied. If the request is unclear in a way that changes the plan, ask the user first. " +
24
+ "When the task needs changes made (files edited, commands run), reply with a concise, concrete plan: the steps in order (for code, the files to change and how), " +
25
+ "any open questions, and how you will verify the result. " +
26
+ (canPropose
27
+ ? "Then call propose_plan so the user can approve it. If nothing needs to be executed (a question, or the plan itself is the answer the user wants), " +
28
+ "just answer and do not call propose_plan."
29
+ : "Then stop and wait for the user's approval."));
30
+ }
31
+ /** 批准计划之后工具结果里的那句 */
32
+ export const APPROVED_NOTE = "The user approved the plan. Implement it now.";
33
+ /** 没批准时工具结果里的那句 */
34
+ export const NOT_APPROVED = "The user did not approve the plan yet. End your turn and wait for their feedback.";
35
+ export const PROPOSE_PLAN = "propose_plan";
36
+ /** propose_plan:问用户要不要执行刚写好的计划,批准了就换到用户选的模式 */
37
+ export function proposePlanTool(approval, ui) {
38
+ return {
39
+ name: PROPOSE_PLAN,
40
+ description: "In plan mode, ask the user to approve the plan you just wrote in your reply, and wait for the answer. Write the full plan in your reply text first; " +
41
+ "call this only for a plan of changes to execute, not for questions, clarifications or answers that need nothing executed.",
42
+ inputSchema: { type: "object", properties: {}, additionalProperties: false },
43
+ // 不碰文件和进程:plan 模式下不用批准
44
+ effect: "read",
45
+ concurrency: "exclusive",
46
+ idempotent: false,
47
+ async execute(_input, ctx) {
48
+ if (approval.mode() !== "plan")
49
+ return { content: "The session is not in plan mode; no approval is needed.", isError: true };
50
+ const choice = await ui.select({
51
+ title: "Execute this plan?",
52
+ options: [
53
+ { label: "Yes, in auto mode", value: "auto", hint: "edits and safe commands run without asking" },
54
+ { label: "Yes, and ask before each edit", value: "ask", hint: "mode ask" },
55
+ { label: "No, keep planning", value: "plan", hint: "type what to change" },
56
+ ],
57
+ }, ctx.signal);
58
+ ctx.signal.throwIfAborted();
59
+ if (choice !== "auto" && choice !== "ask")
60
+ return { content: NOT_APPROVED };
61
+ setMode(approval, choice);
62
+ return { content: `${APPROVED_NOTE} (mode: ${choice})` };
63
+ },
64
+ };
65
+ }
66
+ /** 模式变化时通知前端和会话里的订阅者(模块每个进程只加载一次,进程级和会话级共用) */
67
+ const listeners = new Set();
68
+ /**
69
+ * 用户选的模式记在 $JADE_HOME/mode.json,下次启动接着用(比配置里的 mode 优先)。
70
+ * plan 是一次任务里的,yolo 不该悄悄带到下一次启动:这两个不记
71
+ */
72
+ const REMEMBERED = new Set(["ask", "auto", "readonly"]);
73
+ let modeFile;
74
+ /** 记下的模式只在第一个可交互的会话里恢复一次:jade -p 这类不能问用户的运行一直用配置的模式 */
75
+ let restored = false;
76
+ function readRemembered(file) {
77
+ try {
78
+ const mode = JSON.parse(readFileSync(file, "utf8")).mode;
79
+ return typeof mode === "string" && REMEMBERED.has(mode) ? mode : undefined;
80
+ }
81
+ catch {
82
+ return undefined;
83
+ }
84
+ }
85
+ function remember(mode) {
86
+ if (!modeFile || !REMEMBERED.has(mode))
87
+ return;
88
+ try {
89
+ // 同步写:连按几次 Shift+Tab 时,文件里留下的一定是最后一次
90
+ mkdirSync(path.dirname(modeFile), { recursive: true });
91
+ writeFileSync(modeFile, `${JSON.stringify({ mode })}\n`);
92
+ }
93
+ catch {
94
+ // 记不下只是下次从配置的模式开始
95
+ }
96
+ }
97
+ function setMode(approval, mode) {
98
+ if (mode === approval.mode())
99
+ return;
100
+ approval.setMode(mode);
101
+ remember(mode);
102
+ for (const fn of [...listeners]) {
103
+ try {
104
+ fn(mode);
105
+ }
106
+ catch {
107
+ // 订阅者的错误经过膜归它自己,不影响别的订阅者
108
+ }
109
+ }
110
+ }
111
+ export default definePlugin({
112
+ process(ctx) {
113
+ const approval = ctx.require("approval@1");
114
+ modeFile = path.join(ctx.home, "mode.json");
115
+ restored = false;
116
+ const set = (mode) => setMode(approval, mode);
117
+ const cycle = () => {
118
+ const next = CYCLE[(CYCLE.indexOf(approval.mode()) + 1) % CYCLE.length];
119
+ set(next);
120
+ return next;
121
+ };
122
+ const list = () => Object.entries(DESCRIPTIONS).map(([name, description]) => ({ name, description }));
123
+ ctx.provide("modes@1", (caller) => ({
124
+ current: () => approval.mode(),
125
+ list,
126
+ set,
127
+ cycle,
128
+ subscribe(fn) {
129
+ listeners.add(fn);
130
+ const off = () => void listeners.delete(fn);
131
+ caller.onDispose(off);
132
+ return off;
133
+ },
134
+ }));
135
+ ctx.service("keys@1")?.register({ key: "shift+tab", description: "cycle ask/auto/plan", run: () => void cycle() });
136
+ ctx.service("commands@1")?.register({
137
+ name: "mode",
138
+ args: `[${Object.keys(DESCRIPTIONS).join("|")}]`,
139
+ description: "show or change the permission mode",
140
+ instant: true,
141
+ async run(args, c) {
142
+ let want = args.trim() || undefined;
143
+ if (!want) {
144
+ want = await c.ui.select({ title: "Permission mode", options: list().map((m) => ({ label: m.name, value: m.name, hint: m.name === approval.mode() ? "current" : m.description })) }, c.signal);
145
+ if (!want)
146
+ return;
147
+ }
148
+ if (!(want in DESCRIPTIONS))
149
+ return `unknown mode ${want}; one of ${Object.keys(DESCRIPTIONS).join(", ")}`;
150
+ set(want);
151
+ return `mode: ${approval.mode()}`;
152
+ },
153
+ });
154
+ },
155
+ session(ctx) {
156
+ const approval = ctx.require("approval@1");
157
+ const prompts = ctx.service("prompts@1");
158
+ const ui = ctx.service("ui@1");
159
+ if (!restored && ui?.interactive && modeFile) {
160
+ restored = true;
161
+ const saved = readRemembered(modeFile);
162
+ if (saved)
163
+ setMode(approval, saved);
164
+ }
165
+ // 能问用户时才有 propose_plan;它只在 plan 模式下发给模型
166
+ const canPropose = !!ui?.interactive;
167
+ if (canPropose)
168
+ ctx.kernel.tool(proposePlanTool(approval, ui));
169
+ ctx.kernel.hook({
170
+ kind: "transform",
171
+ point: "context.build",
172
+ fn: (req) => (approval.mode() === "plan" ? req : { ...req, tools: req.tools.filter((t) => t.name !== PROPOSE_PLAN) }),
173
+ });
174
+ // 计划模式的说明跟着模式进出系统提示词
175
+ let note;
176
+ const sync = () => {
177
+ const plan = approval.mode() === "plan";
178
+ if (plan && !note && prompts)
179
+ note = prompts.add({ text: planNote(canPropose), stable: false });
180
+ else if (!plan && note) {
181
+ note();
182
+ note = undefined;
183
+ }
184
+ };
185
+ sync();
186
+ const onChange = () => sync();
187
+ listeners.add(onChange);
188
+ ctx.effect(() => () => void listeners.delete(onChange));
189
+ },
190
+ });
@@ -0,0 +1,18 @@
1
+ {
2
+ "id": "jade/modes",
3
+ "version": "0.2.0",
4
+ "api": "^1",
5
+ "entry": "./index.js",
6
+ "provides": [
7
+ "modes@1"
8
+ ],
9
+ "requires": [
10
+ "approval@1"
11
+ ],
12
+ "optional": [
13
+ "keys@1",
14
+ "commands@1",
15
+ "prompts@1",
16
+ "ui@1"
17
+ ]
18
+ }
@@ -0,0 +1,37 @@
1
+ // jade/plugins:/plugins 命令。列出这次启动里每个插件的状态和原因(failed、skipped、conflicted……),
2
+ // 以及每个服务由谁提供。数据来自核心自己的 jade@1 服务,和救援 CLI `jade plugins list` 是同一份状态。
3
+ import { definePlugin } from "../../dist/api.js";
4
+ export default definePlugin({
5
+ process(ctx) {
6
+ const commands = ctx.require("commands@1");
7
+ const jade = ctx.require("jade@1");
8
+ commands.register({
9
+ name: "plugins",
10
+ args: "[id]",
11
+ description: "every plugin's state and why it is not active, and who provides each service",
12
+ // 只读,不碰会话
13
+ instant: true,
14
+ run(args) {
15
+ const all = jade.plugins();
16
+ const query = args.trim();
17
+ if (query) {
18
+ const found = all.filter((p) => p.id === query || p.id?.endsWith(`/${query}`) || p.dir === query);
19
+ if (found.length === 0)
20
+ return `No plugin matches ${query}. /plugins lists them all.`;
21
+ const lines = found.map((p) => `${p.id ?? p.dir}@${p.version ?? "?"} ${p.layer} ${p.state}${p.reason ? ` ${p.reason}` : ""}\n ${p.dir}`);
22
+ for (const s of jade.services().filter((s) => found.some((p) => p.id === s.provider)))
23
+ lines.push(` provides ${s.service}`);
24
+ return lines.join("\n");
25
+ }
26
+ const lines = all.map((p) => `${p.id ?? p.dir}@${p.version ?? "?"} ${p.layer} ${p.state}${p.reason ? ` ${p.reason}` : ""}`);
27
+ const broken = all.filter((p) => p.state !== "active");
28
+ if (broken.length > 0)
29
+ lines.push("", `${broken.length} of ${all.length} plugins are not active; /plugins <id> shows where one lives.`);
30
+ const services = jade.services();
31
+ if (services.length > 0)
32
+ lines.push("", "services:", ...services.map((s) => ` ${s.service} ${s.provider}`));
33
+ return lines.join("\n");
34
+ },
35
+ });
36
+ },
37
+ });
@@ -0,0 +1,10 @@
1
+ {
2
+ "id": "jade/plugins",
3
+ "version": "0.1.0",
4
+ "api": "^1",
5
+ "entry": "./index.js",
6
+ "requires": [
7
+ "commands@1",
8
+ "jade@1"
9
+ ]
10
+ }
@@ -0,0 +1,153 @@
1
+ // jade/print:jade -p "<prompt>" 跑一轮就退出。模型的回复写到 stdout,工具调用和提示写到 stderr。
2
+ // 不能向用户提问:ui@1 的 select 总是返回 undefined,要审批的调用由审批插件拒绝。
3
+ import { definePlugin } from "../../dist/api.js";
4
+ const USAGE = `usage: jade -p <prompt> [--resume <session id>]
5
+ echo <prompt> | jade -p
6
+
7
+ Runs one prompt and exits. The reply goes to stdout; tool calls and notices go to stderr.
8
+ Exit code: 0 when the turn ends normally, 1 on an error, 130 when interrupted.`;
9
+ const ui = {
10
+ interactive: false,
11
+ notify(message, level = "info") {
12
+ process.stderr.write(`${level === "info" ? "" : `[${level}] `}${message}\n`);
13
+ },
14
+ select: async () => undefined,
15
+ input: async () => undefined,
16
+ };
17
+ const frontend = {
18
+ async run({ argv, sessions }) {
19
+ const args = parse(argv);
20
+ if (typeof args === "string") {
21
+ process.stderr.write(`${args}\n\n${USAGE}\n`);
22
+ return 2;
23
+ }
24
+ if (args.help) {
25
+ process.stdout.write(`${USAGE}\n`);
26
+ return 0;
27
+ }
28
+ const prompt = args.prompt ?? (process.stdin.isTTY ? "" : (await readStdin()).trim());
29
+ if (!prompt) {
30
+ process.stderr.write(`no prompt given\n\n${USAGE}\n`);
31
+ return 2;
32
+ }
33
+ const session = await sessions.open(args.resume ? { resume: args.resume } : {});
34
+ let ended;
35
+ let midLine = false;
36
+ const out = (text) => {
37
+ process.stdout.write(text);
38
+ midLine = !text.endsWith("\n");
39
+ };
40
+ /** 这次模型调用推送过文字增量;没推送的(不流式的服务),回复到了再一次写出 */
41
+ let streamed = false;
42
+ const unsubscribe = session.subscribe((n) => {
43
+ if (n.type === "delta" && n.delta.kind === "text") {
44
+ streamed = true;
45
+ out(n.delta.text);
46
+ }
47
+ if (n.type !== "event")
48
+ return;
49
+ const e = n.event;
50
+ if (e.type === "model.responded") {
51
+ const content = e.data.content;
52
+ if (!streamed)
53
+ for (const b of content)
54
+ if (b.kind === "text")
55
+ out(b.text);
56
+ streamed = false;
57
+ if (midLine)
58
+ out("\n");
59
+ for (const b of content)
60
+ if (b.kind === "tool_use")
61
+ process.stderr.write(`· ${b.name} ${summary(b.input)}\n`);
62
+ }
63
+ if (e.type === "tool.decided") {
64
+ const d = e.data;
65
+ if (d.decision === "deny")
66
+ process.stderr.write(` denied${d.reason ? `: ${d.reason}` : ""}\n`);
67
+ }
68
+ if (e.type === "tool.completed") {
69
+ const d = e.data;
70
+ if (d.isError)
71
+ process.stderr.write(` failed: ${firstLine(d.content)}\n`);
72
+ }
73
+ if (e.type === "turn.ended")
74
+ ended = e.data;
75
+ });
76
+ const interrupt = () => session.abort(new Error("interrupted"));
77
+ process.once("SIGINT", interrupt);
78
+ let failure;
79
+ try {
80
+ if (args.resume)
81
+ await session.recover();
82
+ await session.send({ kind: "message", content: [{ kind: "text", text: prompt, origin: { by: "user" }, trust: "trusted" }] });
83
+ await session.idle();
84
+ }
85
+ catch (e) {
86
+ failure = e;
87
+ }
88
+ finally {
89
+ process.off("SIGINT", interrupt);
90
+ unsubscribe();
91
+ }
92
+ if (midLine)
93
+ out("\n");
94
+ process.stderr.write(`session ${session.id}\n`);
95
+ const end = ended;
96
+ if (end?.reason === "aborted")
97
+ return 130;
98
+ if (failure !== undefined || end?.reason === "error") {
99
+ // 模型服务的错误经过膜时包成了 PluginError,用户要看的是原因
100
+ const cause = failure instanceof Error && failure.cause instanceof Error ? failure.cause : failure;
101
+ process.stderr.write(`error: ${cause instanceof Error ? cause.message : (end?.error ?? String(cause ?? "the turn failed"))}\n`);
102
+ return 1;
103
+ }
104
+ return 0;
105
+ },
106
+ };
107
+ export default definePlugin({
108
+ process(ctx) {
109
+ ctx.provide("ui@1", ui);
110
+ ctx.provide("frontend@1", frontend);
111
+ },
112
+ });
113
+ function parse(argv) {
114
+ const out = {};
115
+ const words = [];
116
+ for (let i = 0; i < argv.length; i++) {
117
+ const a = argv[i];
118
+ if (a === "-p" || a === "--print")
119
+ continue;
120
+ if (a === "-h" || a === "--help")
121
+ out.help = true;
122
+ else if (a === "--resume") {
123
+ const id = argv[++i];
124
+ if (!id)
125
+ return "--resume needs a session id";
126
+ out.resume = id;
127
+ }
128
+ else if (a.startsWith("-"))
129
+ return `unknown option ${a}`;
130
+ else
131
+ words.push(a);
132
+ }
133
+ if (words.length > 0)
134
+ out.prompt = words.join(" ");
135
+ return out;
136
+ }
137
+ async function readStdin() {
138
+ const chunks = [];
139
+ for await (const c of process.stdin)
140
+ chunks.push(c);
141
+ return Buffer.concat(chunks).toString("utf8");
142
+ }
143
+ /** 工具参数的一行摘要:常见的 path、command、pattern,其余是截断的 JSON */
144
+ function summary(input) {
145
+ const i = input;
146
+ const s = typeof i?.command === "string" ? i.command : typeof i?.path === "string" ? i.path : typeof i?.pattern === "string" ? i.pattern : JSON.stringify(input);
147
+ const line = (s ?? "").split("\n")[0];
148
+ return line.length > 120 ? `${line.slice(0, 120)}…` : line;
149
+ }
150
+ function firstLine(content) {
151
+ const text = content.find((b) => b.kind === "text");
152
+ return text && "text" in text ? text.text.split("\n")[0] : "(no message)";
153
+ }
@@ -0,0 +1,14 @@
1
+ {
2
+ "id": "jade/print",
3
+ "version": "0.2.0",
4
+ "api": "^1",
5
+ "entry": "./index.js",
6
+ "provides": [
7
+ "frontend@1",
8
+ "ui@1"
9
+ ],
10
+ "frontend": {
11
+ "name": "print",
12
+ "flag": "-p"
13
+ }
14
+ }
@@ -0,0 +1,57 @@
1
+ // jade/prompts:在 context.build 里生成系统提示词。其他插件经 prompts@1 往里加段落。
2
+ import path from "node:path";
3
+ import { definePlugin } from "../../dist/api.js";
4
+ import { allInstructions, environment, mainPrompt, realPath } from "./prompts.js";
5
+ const ID = "jade/prompts";
6
+ /** 其他插件加的段落。模块每个进程只加载一次,进程级和会话级共用 */
7
+ const sections = [];
8
+ function segment(text, trust = "trusted", stability = "stable", by = ID, source) {
9
+ return { text, stability, origin: { by: "plugin", id: by, ...(source ? { source } : {}) }, trust };
10
+ }
11
+ /** 工作目录里的显示成相对路径,外面的显示绝对路径 */
12
+ function display(cwd, full) {
13
+ const rel = path.relative(cwd, full);
14
+ const shown = rel && rel !== ".." && !rel.startsWith(`..${path.sep}`) && !path.isAbsolute(rel) ? rel : full;
15
+ return shown.split(path.sep).join("/");
16
+ }
17
+ export default definePlugin({
18
+ process(ctx) {
19
+ ctx.provide("prompts@1", (caller) => ({
20
+ add({ text, stable = true, untrusted = false }) {
21
+ if (typeof text !== "string" || !text)
22
+ throw new Error("prompts.add: text must be a non-empty string");
23
+ const s = { plugin: caller.plugin, text, stable, trusted: caller.layer !== "project" && untrusted !== true };
24
+ sections.push(s);
25
+ const remove = () => {
26
+ const i = sections.indexOf(s);
27
+ if (i !== -1)
28
+ sections.splice(i, 1);
29
+ };
30
+ caller.onDispose(remove);
31
+ return remove;
32
+ },
33
+ }));
34
+ },
35
+ async session(ctx) {
36
+ const models = ctx.service("models@1");
37
+ const [env, instructions] = await Promise.all([environment(ctx.cwd), allInstructions(ctx.home, ctx.cwd)]);
38
+ const fixed = [segment(env), ...instructions.map((i) => segment(i.text, i.trust, "stable", ID, i.source))];
39
+ // 告诉用户读了哪些指令文件,否则看不出它们生效了
40
+ if (instructions.length > 0)
41
+ ctx.service("ui@1")?.notify(`loaded instructions: ${instructions.map((i) => display(realPath(ctx.cwd), i.file)).join(", ")}`);
42
+ ctx.kernel.hook({
43
+ kind: "transform",
44
+ point: "context.build",
45
+ fn: (req) => {
46
+ const main = segment(mainPrompt(new Set(req.tools.map((t) => t.name))));
47
+ const model = models?.current();
48
+ // 说成"配置的模型":服务商的别名、路由背后实际回复的可能是别的模型
49
+ const modelLine = model?.model
50
+ ? [segment(`Jade is configured to use the model "${model.model}" via ${model.via}. If the user asks which model you are, answer with this rather than guessing from your training.`)]
51
+ : [];
52
+ const extra = [...sections.filter((s) => s.stable), ...sections.filter((s) => !s.stable)].map((s) => segment(s.text, s.trusted ? "trusted" : "untrusted", s.stable ? "stable" : "volatile", s.plugin));
53
+ return { ...req, system: [main, ...fixed, ...modelLine, ...extra, ...req.system] };
54
+ },
55
+ });
56
+ },
57
+ });