@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,222 @@
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
+
10
+ import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
11
+ import path from "node:path";
12
+ import type { Tool } from "uncarved";
13
+ import { definePlugin, type UI } from "../../src/api.ts";
14
+ import type { Approval } from "../approval/index.ts";
15
+ import type { Commands } from "../commands/index.ts";
16
+ import type { Keys } from "../keys/index.ts";
17
+ import type { Prompts } from "../prompts/index.ts";
18
+
19
+ /** modes@1 */
20
+ export interface Modes {
21
+ current(): string;
22
+ list(): { name: string; description: string }[];
23
+ /** 换模式,从下一个工具调用起生效 */
24
+ set(mode: string): void;
25
+ /** 换到轮换顺序里的下一个 */
26
+ cycle(): string;
27
+ /** 模式变化时调用,返回取消订阅的函数;调用方关闭时自动取消 */
28
+ subscribe(fn: (mode: string) => void): () => void;
29
+ }
30
+
31
+ export const DESCRIPTIONS: Record<string, string> = {
32
+ ask: "ask before edits and commands",
33
+ auto: "edits in this directory and harmless commands run without asking; others still ask",
34
+ plan: "change nothing: research read-only and propose a plan",
35
+ readonly: "change nothing",
36
+ yolo: "never ask",
37
+ };
38
+ const CYCLE = ["ask", "auto", "plan"];
39
+
40
+ /** 计划模式时加进系统提示词的段落;不能问用户(-p、非终端)时没有 propose_plan,只让模型给出计划后停下 */
41
+ export function planNote(canPropose: boolean): string {
42
+ return (
43
+ "The session is in plan mode. Investigate with read-only tools (and the task tool for broad searches); do not try to modify files " +
44
+ "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. " +
45
+ "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), " +
46
+ "any open questions, and how you will verify the result. " +
47
+ (canPropose
48
+ ? "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), " +
49
+ "just answer and do not call propose_plan."
50
+ : "Then stop and wait for the user's approval.")
51
+ );
52
+ }
53
+
54
+ /** 批准计划之后工具结果里的那句 */
55
+ export const APPROVED_NOTE = "The user approved the plan. Implement it now.";
56
+ /** 没批准时工具结果里的那句 */
57
+ export const NOT_APPROVED = "The user did not approve the plan yet. End your turn and wait for their feedback.";
58
+
59
+ export const PROPOSE_PLAN = "propose_plan";
60
+
61
+ /** propose_plan:问用户要不要执行刚写好的计划,批准了就换到用户选的模式 */
62
+ export function proposePlanTool(approval: Approval, ui: UI): Tool {
63
+ return {
64
+ name: PROPOSE_PLAN,
65
+ description:
66
+ "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; " +
67
+ "call this only for a plan of changes to execute, not for questions, clarifications or answers that need nothing executed.",
68
+ inputSchema: { type: "object", properties: {}, additionalProperties: false },
69
+ // 不碰文件和进程:plan 模式下不用批准
70
+ effect: "read",
71
+ concurrency: "exclusive",
72
+ idempotent: false,
73
+ async execute(_input, ctx) {
74
+ if (approval.mode() !== "plan") return { content: "The session is not in plan mode; no approval is needed.", isError: true };
75
+ const choice = await ui.select(
76
+ {
77
+ title: "Execute this plan?",
78
+ options: [
79
+ { label: "Yes, in auto mode", value: "auto", hint: "edits and safe commands run without asking" },
80
+ { label: "Yes, and ask before each edit", value: "ask", hint: "mode ask" },
81
+ { label: "No, keep planning", value: "plan", hint: "type what to change" },
82
+ ],
83
+ },
84
+ ctx.signal,
85
+ );
86
+ ctx.signal.throwIfAborted();
87
+ if (choice !== "auto" && choice !== "ask") return { content: NOT_APPROVED };
88
+ setMode(approval, choice);
89
+ return { content: `${APPROVED_NOTE} (mode: ${choice})` };
90
+ },
91
+ };
92
+ }
93
+
94
+ /** 模式变化时通知前端和会话里的订阅者(模块每个进程只加载一次,进程级和会话级共用) */
95
+ const listeners = new Set<(mode: string) => void>();
96
+
97
+ /**
98
+ * 用户选的模式记在 $JADE_HOME/mode.json,下次启动接着用(比配置里的 mode 优先)。
99
+ * plan 是一次任务里的,yolo 不该悄悄带到下一次启动:这两个不记
100
+ */
101
+ const REMEMBERED = new Set(["ask", "auto", "readonly"]);
102
+ let modeFile: string | undefined;
103
+ /** 记下的模式只在第一个可交互的会话里恢复一次:jade -p 这类不能问用户的运行一直用配置的模式 */
104
+ let restored = false;
105
+
106
+ function readRemembered(file: string): string | undefined {
107
+ try {
108
+ const mode = (JSON.parse(readFileSync(file, "utf8")) as { mode?: unknown }).mode;
109
+ return typeof mode === "string" && REMEMBERED.has(mode) ? mode : undefined;
110
+ } catch {
111
+ return undefined;
112
+ }
113
+ }
114
+
115
+ function remember(mode: string): void {
116
+ if (!modeFile || !REMEMBERED.has(mode)) return;
117
+ try {
118
+ // 同步写:连按几次 Shift+Tab 时,文件里留下的一定是最后一次
119
+ mkdirSync(path.dirname(modeFile), { recursive: true });
120
+ writeFileSync(modeFile, `${JSON.stringify({ mode })}\n`);
121
+ } catch {
122
+ // 记不下只是下次从配置的模式开始
123
+ }
124
+ }
125
+
126
+ function setMode(approval: Approval, mode: string): void {
127
+ if (mode === approval.mode()) return;
128
+ approval.setMode(mode as ReturnType<Approval["mode"]>);
129
+ remember(mode);
130
+ for (const fn of [...listeners]) {
131
+ try {
132
+ fn(mode);
133
+ } catch {
134
+ // 订阅者的错误经过膜归它自己,不影响别的订阅者
135
+ }
136
+ }
137
+ }
138
+
139
+ export default definePlugin({
140
+ process(ctx) {
141
+ const approval = ctx.require<Approval>("approval@1");
142
+ modeFile = path.join(ctx.home, "mode.json");
143
+ restored = false;
144
+ const set = (mode: string) => setMode(approval, mode);
145
+ const cycle = () => {
146
+ const next = CYCLE[(CYCLE.indexOf(approval.mode()) + 1) % CYCLE.length]!;
147
+ set(next);
148
+ return next;
149
+ };
150
+ const list = () => Object.entries(DESCRIPTIONS).map(([name, description]) => ({ name, description }));
151
+
152
+ ctx.provide("modes@1", (caller): Modes => ({
153
+ current: () => approval.mode(),
154
+ list,
155
+ set,
156
+ cycle,
157
+ subscribe(fn) {
158
+ listeners.add(fn);
159
+ const off = () => void listeners.delete(fn);
160
+ caller.onDispose(off);
161
+ return off;
162
+ },
163
+ }));
164
+
165
+ ctx.service<Keys>("keys@1")?.register({ key: "shift+tab", description: "cycle ask/auto/plan", run: () => void cycle() });
166
+ ctx.service<Commands>("commands@1")?.register({
167
+ name: "mode",
168
+ args: `[${Object.keys(DESCRIPTIONS).join("|")}]`,
169
+ description: "show or change the permission mode",
170
+ instant: true,
171
+ async run(args, c) {
172
+ let want: string | undefined = args.trim() || undefined;
173
+ if (!want) {
174
+ want = await c.ui.select(
175
+ { title: "Permission mode", options: list().map((m) => ({ label: m.name, value: m.name, hint: m.name === approval.mode() ? "current" : m.description })) },
176
+ c.signal,
177
+ );
178
+ if (!want) return;
179
+ }
180
+ if (!(want in DESCRIPTIONS)) return `unknown mode ${want}; one of ${Object.keys(DESCRIPTIONS).join(", ")}`;
181
+ set(want);
182
+ return `mode: ${approval.mode()}`;
183
+ },
184
+ });
185
+ },
186
+
187
+ session(ctx) {
188
+ const approval = ctx.require<Approval>("approval@1");
189
+ const prompts = ctx.service<Prompts>("prompts@1");
190
+ const ui = ctx.service<UI>("ui@1");
191
+
192
+ if (!restored && ui?.interactive && modeFile) {
193
+ restored = true;
194
+ const saved = readRemembered(modeFile);
195
+ if (saved) setMode(approval, saved);
196
+ }
197
+
198
+ // 能问用户时才有 propose_plan;它只在 plan 模式下发给模型
199
+ const canPropose = !!ui?.interactive;
200
+ if (canPropose) ctx.kernel.tool(proposePlanTool(approval, ui!));
201
+ ctx.kernel.hook({
202
+ kind: "transform",
203
+ point: "context.build",
204
+ fn: (req) => (approval.mode() === "plan" ? req : { ...req, tools: req.tools.filter((t) => t.name !== PROPOSE_PLAN) }),
205
+ });
206
+
207
+ // 计划模式的说明跟着模式进出系统提示词
208
+ let note: (() => void) | undefined;
209
+ const sync = () => {
210
+ const plan = approval.mode() === "plan";
211
+ if (plan && !note && prompts) note = prompts.add({ text: planNote(canPropose), stable: false });
212
+ else if (!plan && note) {
213
+ note();
214
+ note = undefined;
215
+ }
216
+ };
217
+ sync();
218
+ const onChange = () => sync();
219
+ listeners.add(onChange);
220
+ ctx.effect(() => () => void listeners.delete(onChange));
221
+ },
222
+ });
@@ -0,0 +1,9 @@
1
+ {
2
+ "id": "jade/modes",
3
+ "version": "0.2.0",
4
+ "api": "^1",
5
+ "entry": "./index.ts",
6
+ "provides": ["modes@1"],
7
+ "requires": ["approval@1"],
8
+ "optional": ["keys@1", "commands@1", "prompts@1", "ui@1"]
9
+ }
@@ -0,0 +1,38 @@
1
+ // jade/plugins:/plugins 命令。列出这次启动里每个插件的状态和原因(failed、skipped、conflicted……),
2
+ // 以及每个服务由谁提供。数据来自核心自己的 jade@1 服务,和救援 CLI `jade plugins list` 是同一份状态。
3
+
4
+ import { definePlugin, type Jade } from "../../src/api.ts";
5
+ import type { Commands } from "../commands/index.ts";
6
+
7
+ export default definePlugin({
8
+ process(ctx) {
9
+ const commands = ctx.require<Commands>("commands@1");
10
+ const jade = ctx.require<Jade>("jade@1");
11
+
12
+ commands.register({
13
+ name: "plugins",
14
+ args: "[id]",
15
+ description: "every plugin's state and why it is not active, and who provides each service",
16
+ // 只读,不碰会话
17
+ instant: true,
18
+ run(args) {
19
+ const all = jade.plugins();
20
+ const query = args.trim();
21
+ if (query) {
22
+ const found = all.filter((p) => p.id === query || p.id?.endsWith(`/${query}`) || p.dir === query);
23
+ if (found.length === 0) return `No plugin matches ${query}. /plugins lists them all.`;
24
+ const lines = found.map((p) => `${p.id ?? p.dir}@${p.version ?? "?"} ${p.layer} ${p.state}${p.reason ? ` ${p.reason}` : ""}\n ${p.dir}`);
25
+ for (const s of jade.services().filter((s) => found.some((p) => p.id === s.provider))) lines.push(` provides ${s.service}`);
26
+ return lines.join("\n");
27
+ }
28
+
29
+ const lines = all.map((p) => `${p.id ?? p.dir}@${p.version ?? "?"} ${p.layer} ${p.state}${p.reason ? ` ${p.reason}` : ""}`);
30
+ const broken = all.filter((p) => p.state !== "active");
31
+ if (broken.length > 0) lines.push("", `${broken.length} of ${all.length} plugins are not active; /plugins <id> shows where one lives.`);
32
+ const services = jade.services();
33
+ if (services.length > 0) lines.push("", "services:", ...services.map((s) => ` ${s.service} ${s.provider}`));
34
+ return lines.join("\n");
35
+ },
36
+ });
37
+ },
38
+ });
@@ -0,0 +1,7 @@
1
+ {
2
+ "id": "jade/plugins",
3
+ "version": "0.1.0",
4
+ "api": "^1",
5
+ "entry": "./index.ts",
6
+ "requires": ["commands@1", "jade@1"]
7
+ }
@@ -0,0 +1,160 @@
1
+ // jade/print:jade -p "<prompt>" 跑一轮就退出。模型的回复写到 stdout,工具调用和提示写到 stderr。
2
+ // 不能向用户提问:ui@1 的 select 总是返回 undefined,要审批的调用由审批插件拒绝。
3
+
4
+ import type { Block, LogEvent, RuntimeNotice } from "uncarved";
5
+ import { definePlugin, type Frontend, type UI } from "../../src/api.ts";
6
+
7
+ const USAGE = `usage: jade -p <prompt> [--resume <session id>]
8
+ echo <prompt> | jade -p
9
+ cat <file> | jade -p - <prompt>
10
+
11
+ With "-", what comes in on stdin is added after the prompt (without a prompt, stdin is the prompt).
12
+
13
+ Runs one prompt and exits. The reply goes to stdout; tool calls and notices go to stderr.
14
+ Exit code: 0 when the turn ends normally, 1 on an error, 130 when interrupted.
15
+ jade's own commands (plugins, update, --safe): jade help`;
16
+
17
+ const ui: UI = {
18
+ interactive: false,
19
+ notify(message, level = "info") {
20
+ process.stderr.write(`${level === "info" ? "" : `[${level}] `}${message}\n`);
21
+ },
22
+ select: async () => undefined,
23
+ input: async () => undefined,
24
+ };
25
+
26
+ const frontend: Frontend = {
27
+ async run({ argv, sessions }) {
28
+ const args = parse(argv);
29
+ if (typeof args === "string") {
30
+ process.stderr.write(`${args}\n\n${USAGE}\n`);
31
+ return 2;
32
+ }
33
+ if (args.help) {
34
+ process.stdout.write(`${USAGE}\n`);
35
+ return 0;
36
+ }
37
+ // 有 prompt 参数时只在写了 "-" 时读 stdin:脚本启动 jade -p 时 stdin 常是没人关的管道,默认去读会一直等下去
38
+ const piped = args.stdin || (args.prompt === undefined && !process.stdin.isTTY) ? (await readStdin()).trim() : "";
39
+ const prompt = [args.prompt, piped].filter(Boolean).join("\n\n");
40
+ if (!prompt) {
41
+ process.stderr.write(`no prompt given\n\n${USAGE}\n`);
42
+ return 2;
43
+ }
44
+
45
+ let session: Awaited<ReturnType<typeof sessions.open>>;
46
+ try {
47
+ session = await sessions.open(args.resume ? { resume: args.resume } : {});
48
+ } catch (e) {
49
+ // 例如 --resume 的会话不存在:只说原因,不带插件名的包装
50
+ process.stderr.write(`jade: ${args.resume ? `could not resume ${args.resume}` : "could not start a session"}: ${errorText(e)}\n`);
51
+ return args.resume ? 2 : 1;
52
+ }
53
+ let ended: { reason: string; error?: string } | undefined;
54
+ let midLine = false;
55
+ const out = (text: string) => {
56
+ process.stdout.write(text);
57
+ midLine = !text.endsWith("\n");
58
+ };
59
+ /** 这次模型调用推送过文字增量;没推送的(不流式的服务),回复到了再一次写出 */
60
+ let streamed = false;
61
+ const unsubscribe = session.subscribe((n: RuntimeNotice) => {
62
+ if (n.type === "delta" && n.delta.kind === "text") {
63
+ streamed = true;
64
+ out(n.delta.text);
65
+ }
66
+ if (n.type !== "event") return;
67
+ const e = n.event as LogEvent;
68
+ if (e.type === "model.responded") {
69
+ const content = (e.data as { content: Block[] }).content;
70
+ if (!streamed) for (const b of content) if (b.kind === "text") out(b.text);
71
+ streamed = false;
72
+ if (midLine) out("\n");
73
+ for (const b of content) if (b.kind === "tool_use") process.stderr.write(`· ${b.name} ${summary(b.input)}\n`);
74
+ }
75
+ if (e.type === "tool.decided") {
76
+ const d = e.data as { decision: string; reason?: string };
77
+ if (d.decision === "deny") process.stderr.write(` denied${d.reason ? `: ${d.reason}` : ""}\n`);
78
+ }
79
+ if (e.type === "tool.completed") {
80
+ const d = e.data as { isError: boolean; content: Block[] };
81
+ if (d.isError) process.stderr.write(` failed: ${firstLine(d.content)}\n`);
82
+ }
83
+ if (e.type === "turn.ended") ended = e.data as { reason: string; error?: string };
84
+ });
85
+
86
+ const interrupt = () => session.abort(new Error("interrupted"));
87
+ process.once("SIGINT", interrupt);
88
+ let failure: unknown;
89
+ try {
90
+ if (args.resume) await session.recover();
91
+ await session.send({ kind: "message", content: [{ kind: "text", text: prompt, origin: { by: "user" }, trust: "trusted" }] });
92
+ await session.idle();
93
+ } catch (e) {
94
+ failure = e;
95
+ } finally {
96
+ process.off("SIGINT", interrupt);
97
+ unsubscribe();
98
+ }
99
+ if (midLine) out("\n");
100
+ process.stderr.write(`session ${session.id}\n`);
101
+ const end = ended as { reason: string; error?: string } | undefined;
102
+ if (end?.reason === "aborted") return 130;
103
+ if (failure !== undefined || end?.reason === "error") {
104
+ process.stderr.write(`error: ${failure !== undefined ? errorText(failure) : (end?.error ?? "the turn failed")}\n`);
105
+ return 1;
106
+ }
107
+ return 0;
108
+ },
109
+ };
110
+
111
+ export default definePlugin({
112
+ process(ctx) {
113
+ ctx.provide("ui@1", ui);
114
+ ctx.provide("frontend@1", frontend);
115
+ },
116
+ });
117
+
118
+ function parse(argv: readonly string[]): { prompt?: string; resume?: string; help?: boolean; stdin?: boolean } | string {
119
+ const out: { prompt?: string; resume?: string; help?: boolean; stdin?: boolean } = {};
120
+ const words: string[] = [];
121
+ for (let i = 0; i < argv.length; i++) {
122
+ const a = argv[i]!;
123
+ if (a === "-p" || a === "--print") continue;
124
+ if (a === "-h" || a === "--help") out.help = true;
125
+ else if (a === "-") out.stdin = true;
126
+ else if (a === "--resume") {
127
+ const id = argv[++i];
128
+ if (!id) return "--resume needs a session id";
129
+ out.resume = id;
130
+ } else if (a.startsWith("-")) return `unknown option ${a}`;
131
+ else words.push(a);
132
+ }
133
+ if (words.length > 0) out.prompt = words.join(" ");
134
+ return out;
135
+ }
136
+
137
+ async function readStdin(): Promise<string> {
138
+ const chunks: Buffer[] = [];
139
+ for await (const c of process.stdin) chunks.push(c as Buffer);
140
+ return Buffer.concat(chunks).toString("utf8");
141
+ }
142
+
143
+ /** 工具参数的一行摘要:常见的 path、command、pattern,其余是截断的 JSON */
144
+ function summary(input: unknown): string {
145
+ const i = input as Record<string, unknown> | null;
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
+
151
+ /** 经过膜的错误包成了 PluginError,带着插件名;用户要看的是原因 */
152
+ function errorText(e: unknown): string {
153
+ const cause = e instanceof Error && e.cause instanceof Error ? e.cause : e;
154
+ return cause instanceof Error ? cause.message : String(cause);
155
+ }
156
+
157
+ function firstLine(content: Block[]): string {
158
+ const text = content.find((b) => b.kind === "text");
159
+ return text && "text" in text ? text.text.split("\n")[0]! : "(no message)";
160
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "id": "jade/print",
3
+ "version": "0.2.0",
4
+ "api": "^1",
5
+ "entry": "./index.ts",
6
+ "provides": ["frontend@1", "ui@1"],
7
+ "frontend": { "name": "print", "flag": "-p" }
8
+ }
@@ -0,0 +1,111 @@
1
+ // jade/prompts:在 context.build 里生成系统提示词。其他插件经 prompts@1 往里加段落。
2
+ // 也负责内核不写的、给模型看的说明:内容为空的错误工具结果在投影里补一句原因(results.ts)。
3
+
4
+ import path from "node:path";
5
+ import type { ContentSource, LogEvent, SystemSegment } from "uncarved";
6
+ import { definePlugin, type UI } from "../../src/api.ts";
7
+ import type { Models } from "../models/index.ts";
8
+ import { allInstructions, environment, mainPrompt, realPath } from "./prompts.ts";
9
+ import { explainEmptyResults, whyEmpty, type Reasons, type Why } from "./results.ts";
10
+
11
+ /** prompts@1 */
12
+ export interface Prompts {
13
+ /**
14
+ * 往系统提示词里加一段,排在主体、环境信息和指令文件之后,返回撤销函数;调用方的作用域关闭时自动撤销。
15
+ * stable(默认 true)的段落排在 volatile 的前面:会变的段落放在后面,前面的才能命中提示缓存。
16
+ * 项目层插件加的段落标为不可信;untrusted 为 true 时也标为不可信(内容来自外部,例如 MCP 服务的说明、仓库里的 skill)
17
+ */
18
+ add(section: { text: string; stable?: boolean; untrusted?: boolean }): () => void;
19
+ }
20
+
21
+ interface Section {
22
+ plugin: string;
23
+ text: string;
24
+ stable: boolean;
25
+ trusted: boolean;
26
+ }
27
+
28
+ const ID = "jade/prompts";
29
+
30
+ /** 其他插件加的段落。模块每个进程只加载一次,进程级和会话级共用 */
31
+ const sections: Section[] = [];
32
+
33
+ function segment(text: string, trust: SystemSegment["trust"] = "trusted", stability: SystemSegment["stability"] = "stable", by = ID, source?: ContentSource): SystemSegment {
34
+ return { text, stability, origin: { by: "plugin", id: by, ...(source ? { source } : {}) }, trust };
35
+ }
36
+
37
+ /** 工作目录里的显示成相对路径,外面的显示绝对路径 */
38
+ function display(cwd: string, full: string): string {
39
+ const rel = path.relative(cwd, full);
40
+ const shown = rel && rel !== ".." && !rel.startsWith(`..${path.sep}`) && !path.isAbsolute(rel) ? rel : full;
41
+ return shown.split(path.sep).join("/");
42
+ }
43
+
44
+ export default definePlugin({
45
+ process(ctx) {
46
+ ctx.provide("prompts@1", (caller): Prompts => ({
47
+ add({ text, stable = true, untrusted = false }) {
48
+ if (typeof text !== "string" || !text) throw new Error("prompts.add: text must be a non-empty string");
49
+ const s: Section = { plugin: caller.plugin, text, stable, trusted: caller.layer !== "project" && untrusted !== true };
50
+ sections.push(s);
51
+ const remove = () => {
52
+ const i = sections.indexOf(s);
53
+ if (i !== -1) sections.splice(i, 1);
54
+ };
55
+ caller.onDispose(remove);
56
+ return remove;
57
+ },
58
+ }));
59
+ },
60
+
61
+ async session(ctx) {
62
+ const models = ctx.service<Models>("models@1");
63
+ const [env, instructions] = await Promise.all([environment(ctx.cwd), allInstructions(ctx.home, ctx.cwd)]);
64
+ const fixed = [segment(env), ...instructions.map((i) => segment(i.text, i.trust, "stable", ID, i.source))];
65
+ // 告诉用户读了哪些指令文件,否则看不出它们生效了
66
+ if (instructions.length > 0) ctx.service<UI>("ui@1")?.notify(`loaded instructions: ${instructions.map((i) => display(realPath(ctx.cwd), i.file)).join(", ")}`);
67
+
68
+ // 内容为空的错误工具结果补上说明(results.ts)。原因记在 derived 里;同一批里可能有几个,
69
+ // observe 并发执行、拿到的 derived 快照可能是旧的,所以在这里累积,每次记完整的一份。
70
+ // 运行时不等 observe:紧接着的模型调用投影时记录可能还没落盘,所以投影也看这份累积的。
71
+ // observe 在事件写入时就(以微任务)开始执行,早于之后的投影;下一轮之前记录一定已落盘,恢复会话时从 derived 读,
72
+ // 所以投影只取决于日志,每次相同
73
+ const reasonsKey = `${ID}/empty-results`;
74
+ let reasons: Record<string, Why> | undefined;
75
+ ctx.kernel.hook({
76
+ kind: "observe",
77
+ point: "event",
78
+ fn: async (e: LogEvent, hook) => {
79
+ const found = whyEmpty(e);
80
+ if (!found) return;
81
+ reasons ??= { ...((hook.derived[reasonsKey] as Reasons | undefined) ?? {}) };
82
+ reasons[found.toolUseId] = found.why;
83
+ await hook.record(reasonsKey, { ...reasons });
84
+ },
85
+ });
86
+ ctx.kernel.hook({
87
+ kind: "transform",
88
+ point: "context.project",
89
+ // 出错时跳过(不补说明),不让这一轮失败
90
+ optional: true,
91
+ fn: (messages, hook) => explainEmptyResults(messages, { ...(hook.derived[reasonsKey] as Reasons | undefined), ...reasons }, ID),
92
+ });
93
+
94
+ ctx.kernel.hook({
95
+ kind: "transform",
96
+ point: "context.build",
97
+ fn: (req) => {
98
+ const main = segment(mainPrompt(new Set(req.tools.map((t) => t.name))));
99
+ const model = models?.current();
100
+ // 说成"配置的模型":服务商的别名、路由背后实际回复的可能是别的模型
101
+ const modelLine = model?.model
102
+ ? [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.`)]
103
+ : [];
104
+ const extra = [...sections.filter((s) => s.stable), ...sections.filter((s) => !s.stable)].map((s) =>
105
+ segment(s.text, s.trusted ? "trusted" : "untrusted", s.stable ? "stable" : "volatile", s.plugin),
106
+ );
107
+ return { ...req, system: [main, ...fixed, ...modelLine, ...extra, ...req.system] };
108
+ },
109
+ });
110
+ },
111
+ });
@@ -0,0 +1,8 @@
1
+ {
2
+ "id": "jade/prompts",
3
+ "version": "0.4.0",
4
+ "api": "^1",
5
+ "entry": "./index.ts",
6
+ "provides": ["prompts@1"],
7
+ "optional": ["models@1", "ui@1"]
8
+ }