@uncarved/jade 0.1.3 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (450) hide show
  1. package/bin/jade.js +5 -27
  2. package/dist/api.d.ts +266 -0
  3. package/dist/api.js +38 -0
  4. package/dist/api.js.map +1 -0
  5. package/dist/config.d.ts +13 -32
  6. package/dist/config.js +39 -121
  7. package/dist/config.js.map +1 -1
  8. package/dist/fetch.d.ts +20 -0
  9. package/dist/fetch.js +190 -0
  10. package/dist/fetch.js.map +1 -0
  11. package/dist/hash.d.ts +2 -0
  12. package/dist/hash.js +42 -0
  13. package/dist/hash.js.map +1 -0
  14. package/dist/host.d.ts +71 -0
  15. package/dist/host.js +400 -0
  16. package/dist/host.js.map +1 -0
  17. package/dist/index.d.ts +11 -30
  18. package/dist/index.js +11 -30
  19. package/dist/index.js.map +1 -1
  20. package/dist/install.d.ts +78 -0
  21. package/dist/install.js +292 -0
  22. package/dist/install.js.map +1 -0
  23. package/dist/main.d.ts +1 -2
  24. package/dist/main.js +159 -1362
  25. package/dist/main.js.map +1 -1
  26. package/dist/manifest.d.ts +23 -0
  27. package/dist/manifest.js +159 -0
  28. package/dist/manifest.js.map +1 -0
  29. package/dist/membrane.d.ts +33 -0
  30. package/dist/membrane.js +140 -0
  31. package/dist/membrane.js.map +1 -0
  32. package/dist/remote.d.ts +10 -0
  33. package/dist/remote.js +292 -0
  34. package/dist/remote.js.map +1 -0
  35. package/dist/rescue.d.ts +10 -0
  36. package/dist/rescue.js +216 -0
  37. package/dist/rescue.js.map +1 -0
  38. package/dist/resolve.d.ts +34 -0
  39. package/dist/resolve.js +178 -0
  40. package/dist/resolve.js.map +1 -0
  41. package/dist/rpc.d.ts +26 -0
  42. package/dist/rpc.js +144 -0
  43. package/dist/rpc.js.map +1 -0
  44. package/dist/secrets.d.ts +12 -0
  45. package/dist/secrets.js +125 -0
  46. package/dist/secrets.js.map +1 -0
  47. package/dist/session.d.ts +45 -0
  48. package/dist/session.js +401 -0
  49. package/dist/session.js.map +1 -0
  50. package/dist/source.d.ts +12 -0
  51. package/dist/source.js +72 -0
  52. package/dist/source.js.map +1 -0
  53. package/dist/state.d.ts +37 -0
  54. package/dist/state.js +93 -0
  55. package/dist/state.js.map +1 -0
  56. package/dist/update.d.ts +2 -0
  57. package/dist/update.js +6 -3
  58. package/dist/update.js.map +1 -1
  59. package/package.json +10 -8
  60. package/plugins/approval/index.ts +297 -0
  61. package/plugins/approval/plugin.json +18 -0
  62. package/{src/plugins → plugins/approval}/policy.ts +21 -100
  63. package/{src/plugins → plugins/approval}/review.ts +62 -16
  64. package/plugins/ask/index.ts +159 -0
  65. package/plugins/ask/plugin.json +8 -0
  66. package/plugins/budget/index.ts +38 -0
  67. package/plugins/budget/plugin.json +13 -0
  68. package/{src/plugins → plugins/checks}/checks.ts +48 -38
  69. package/plugins/checks/index.ts +158 -0
  70. package/plugins/checks/plugin.json +14 -0
  71. package/plugins/checks/project.ts +81 -0
  72. package/plugins/commands/index.ts +76 -0
  73. package/plugins/commands/plugin.json +7 -0
  74. package/{src/plugins → plugins/compact}/compact.ts +73 -38
  75. package/plugins/compact/index.ts +115 -0
  76. package/plugins/compact/plugin.json +17 -0
  77. package/plugins/compact/style.ts +17 -0
  78. package/plugins/continue/index.ts +58 -0
  79. package/plugins/continue/plugin.json +13 -0
  80. package/{src/ui → plugins/fs}/diff.ts +2 -2
  81. package/{src/tools → plugins/fs}/fs.ts +19 -42
  82. package/{src/tools → plugins/fs}/grep.ts +1 -1
  83. package/plugins/fs/index.ts +34 -0
  84. package/plugins/fs/plugin.json +7 -0
  85. package/{src/ui → plugins/fs}/renderers.ts +25 -70
  86. package/plugins/fs/style.ts +18 -0
  87. package/plugins/fs/sys.ts +81 -0
  88. package/plugins/keys/index.ts +53 -0
  89. package/plugins/keys/plugin.json +7 -0
  90. package/plugins/mcp/index.ts +192 -0
  91. package/{src → plugins/mcp}/mcp.ts +32 -32
  92. package/plugins/mcp/plugin.json +7 -0
  93. package/plugins/mcp/project.ts +93 -0
  94. package/plugins/memory/index.ts +105 -0
  95. package/{src → plugins/memory}/memory.ts +20 -2
  96. package/plugins/memory/notes.ts +43 -0
  97. package/plugins/memory/plugin.json +7 -0
  98. package/plugins/memory/style.ts +17 -0
  99. package/plugins/mentions/attach.ts +127 -0
  100. package/plugins/mentions/index.ts +79 -0
  101. package/plugins/mentions/plugin.json +7 -0
  102. package/plugins/mentions/style.ts +17 -0
  103. package/plugins/models/config.ts +53 -0
  104. package/plugins/models/configure.ts +455 -0
  105. package/plugins/models/context.ts +32 -0
  106. package/plugins/models/index.ts +198 -0
  107. package/plugins/models/plugin.json +8 -0
  108. package/{src → plugins/models}/provider.ts +16 -119
  109. package/plugins/models/saved.ts +94 -0
  110. package/plugins/modes/index.ts +222 -0
  111. package/plugins/modes/plugin.json +9 -0
  112. package/plugins/plugins/index.ts +38 -0
  113. package/plugins/plugins/plugin.json +7 -0
  114. package/plugins/print/index.ts +142 -0
  115. package/plugins/print/plugin.json +8 -0
  116. package/plugins/prompts/index.ts +83 -0
  117. package/plugins/prompts/plugin.json +8 -0
  118. package/plugins/prompts/prompts.ts +253 -0
  119. package/plugins/prompts/sys.ts +72 -0
  120. package/plugins/renderers/index.ts +78 -0
  121. package/plugins/renderers/plugin.json +7 -0
  122. package/plugins/repeats/index.ts +165 -0
  123. package/plugins/repeats/plugin.json +6 -0
  124. package/plugins/schedule/cron.ts +74 -0
  125. package/plugins/schedule/index.ts +292 -0
  126. package/plugins/schedule/plugin.json +13 -0
  127. package/plugins/schedule/store.ts +149 -0
  128. package/plugins/scratch/index.ts +31 -0
  129. package/plugins/scratch/plugin.json +7 -0
  130. package/plugins/screenshot/index.ts +40 -0
  131. package/plugins/screenshot/plugin.json +7 -0
  132. package/plugins/screenshot/sys.ts +84 -0
  133. package/{src/tools/screenshot.ts → plugins/screenshot/tool.ts} +6 -6
  134. package/plugins/sessions/index.ts +148 -0
  135. package/plugins/sessions/plugin.json +8 -0
  136. package/plugins/shell/index.ts +33 -0
  137. package/plugins/shell/plugin.json +17 -0
  138. package/plugins/shell/renderers.ts +45 -0
  139. package/plugins/shell/service.ts +44 -0
  140. package/{src/tools → plugins/shell}/shell.ts +31 -20
  141. package/{src → plugins/shell}/sys.ts +2 -43
  142. package/plugins/skills/index.ts +96 -0
  143. package/plugins/skills/plugin.json +7 -0
  144. package/plugins/skills/project.ts +49 -0
  145. package/{src → plugins/skills}/skills.ts +4 -11
  146. package/plugins/suggest/index.ts +286 -0
  147. package/plugins/suggest/plugin.json +18 -0
  148. package/plugins/task/index.ts +167 -0
  149. package/plugins/task/plugin.json +15 -0
  150. package/plugins/task/style.ts +17 -0
  151. package/plugins/task/subagent.ts +257 -0
  152. package/{src/tools/todo.ts → plugins/todo/index.ts} +33 -7
  153. package/plugins/todo/plugin.json +7 -0
  154. package/{src/ui → plugins/tui}/editor.ts +3 -0
  155. package/plugins/tui/frontend.ts +596 -0
  156. package/plugins/tui/index.ts +37 -0
  157. package/plugins/tui/mentions.ts +113 -0
  158. package/plugins/tui/plugin.json +10 -0
  159. package/{src/ui → plugins/tui}/render.ts +8 -2
  160. package/{src/ui → plugins/tui}/screen.ts +8 -3
  161. package/{src/ui → plugins/tui}/transcript.ts +74 -99
  162. package/{src/ui/tui.tsx → plugins/tui/tui.ts} +358 -387
  163. package/{src/tools → plugins/undo}/checkpoint.ts +21 -60
  164. package/plugins/undo/index.ts +139 -0
  165. package/plugins/undo/notes.ts +43 -0
  166. package/plugins/undo/plugin.json +7 -0
  167. package/plugins/undo/style.ts +17 -0
  168. package/plugins/update/index.ts +40 -0
  169. package/plugins/update/plugin.json +13 -0
  170. package/plugins/web/env.ts +78 -0
  171. package/plugins/web/index.ts +133 -0
  172. package/plugins/web/plugin.json +15 -0
  173. package/plugins/web/renderers.ts +11 -0
  174. package/{src/tools → plugins/web}/web.ts +58 -26
  175. package/plugins-dist/approval/index.js +271 -0
  176. package/plugins-dist/approval/plugin.json +24 -0
  177. package/{dist/plugins → plugins-dist/approval}/policy.js +15 -81
  178. package/{dist/plugins → plugins-dist/approval}/review.js +56 -10
  179. package/{dist/plugins → plugins-dist/approval}/schema.js +0 -1
  180. package/plugins-dist/ask/index.js +145 -0
  181. package/plugins-dist/ask/plugin.json +12 -0
  182. package/plugins-dist/budget/index.js +37 -0
  183. package/plugins-dist/budget/plugin.json +15 -0
  184. package/{dist/plugins → plugins-dist/checks}/checks.js +46 -35
  185. package/plugins-dist/checks/index.js +150 -0
  186. package/plugins-dist/checks/plugin.json +21 -0
  187. package/plugins-dist/checks/project.js +76 -0
  188. package/plugins-dist/commands/index.js +33 -0
  189. package/plugins-dist/commands/plugin.json +9 -0
  190. package/{dist/plugins → plugins-dist/compact}/compact.js +51 -33
  191. package/plugins-dist/compact/index.js +100 -0
  192. package/plugins-dist/compact/plugin.json +25 -0
  193. package/plugins-dist/compact/style.js +14 -0
  194. package/plugins-dist/continue/index.js +57 -0
  195. package/plugins-dist/continue/plugin.json +15 -0
  196. package/{dist/ui → plugins-dist/fs}/diff.js +2 -3
  197. package/{dist/tools → plugins-dist/fs}/fs.js +17 -42
  198. package/{dist/tools → plugins-dist/fs}/grep.js +1 -2
  199. package/plugins-dist/fs/index.js +36 -0
  200. package/plugins-dist/fs/plugin.json +10 -0
  201. package/{dist/ui → plugins-dist/fs}/renderers.js +24 -61
  202. package/plugins-dist/fs/style.js +15 -0
  203. package/plugins-dist/fs/sys.js +54 -0
  204. package/plugins-dist/keys/index.js +36 -0
  205. package/plugins-dist/keys/plugin.json +9 -0
  206. package/plugins-dist/mcp/index.js +187 -0
  207. package/{dist → plugins-dist/mcp}/mcp.js +34 -30
  208. package/plugins-dist/mcp/plugin.json +12 -0
  209. package/plugins-dist/mcp/project.js +90 -0
  210. package/plugins-dist/memory/index.js +94 -0
  211. package/{dist → plugins-dist/memory}/memory.js +21 -3
  212. package/plugins-dist/memory/notes.js +36 -0
  213. package/plugins-dist/memory/plugin.json +11 -0
  214. package/plugins-dist/memory/style.js +14 -0
  215. package/plugins-dist/mentions/attach.js +120 -0
  216. package/plugins-dist/mentions/index.js +69 -0
  217. package/plugins-dist/mentions/plugin.json +9 -0
  218. package/plugins-dist/mentions/style.js +14 -0
  219. package/plugins-dist/models/config.js +53 -0
  220. package/plugins-dist/models/configure.js +415 -0
  221. package/plugins-dist/models/context.js +27 -0
  222. package/plugins-dist/models/index.js +167 -0
  223. package/plugins-dist/models/plugin.json +14 -0
  224. package/{dist → plugins-dist/models}/provider.js +18 -81
  225. package/plugins-dist/models/saved.js +80 -0
  226. package/plugins-dist/modes/index.js +190 -0
  227. package/plugins-dist/modes/plugin.json +18 -0
  228. package/plugins-dist/plugins/index.js +37 -0
  229. package/plugins-dist/plugins/plugin.json +10 -0
  230. package/plugins-dist/print/index.js +153 -0
  231. package/plugins-dist/print/plugin.json +14 -0
  232. package/plugins-dist/prompts/index.js +57 -0
  233. package/plugins-dist/prompts/plugin.json +13 -0
  234. package/plugins-dist/prompts/prompts.js +227 -0
  235. package/plugins-dist/prompts/sys.js +46 -0
  236. package/plugins-dist/renderers/index.js +36 -0
  237. package/plugins-dist/renderers/plugin.json +9 -0
  238. package/plugins-dist/repeats/index.js +165 -0
  239. package/plugins-dist/repeats/plugin.json +6 -0
  240. package/plugins-dist/schedule/cron.js +67 -0
  241. package/plugins-dist/schedule/index.js +281 -0
  242. package/plugins-dist/schedule/plugin.json +16 -0
  243. package/plugins-dist/schedule/store.js +125 -0
  244. package/plugins-dist/scratch/index.js +26 -0
  245. package/plugins-dist/scratch/plugin.json +10 -0
  246. package/plugins-dist/screenshot/index.js +35 -0
  247. package/plugins-dist/screenshot/plugin.json +11 -0
  248. package/plugins-dist/screenshot/sys.js +76 -0
  249. package/{dist/tools/screenshot.js → plugins-dist/screenshot/tool.js} +5 -4
  250. package/plugins-dist/sessions/index.js +136 -0
  251. package/plugins-dist/sessions/plugin.json +12 -0
  252. package/plugins-dist/shell/index.js +33 -0
  253. package/plugins-dist/shell/plugin.json +19 -0
  254. package/plugins-dist/shell/renderers.js +40 -0
  255. package/plugins-dist/shell/service.js +29 -0
  256. package/{dist/tools → plugins-dist/shell}/shell.js +31 -22
  257. package/{dist → plugins-dist/shell}/sys.js +2 -43
  258. package/plugins-dist/skills/index.js +90 -0
  259. package/plugins-dist/skills/plugin.json +12 -0
  260. package/plugins-dist/skills/project.js +47 -0
  261. package/{dist → plugins-dist/skills}/skills.js +3 -7
  262. package/plugins-dist/suggest/index.js +282 -0
  263. package/plugins-dist/suggest/plugin.json +23 -0
  264. package/plugins-dist/task/index.js +151 -0
  265. package/plugins-dist/task/plugin.json +23 -0
  266. package/plugins-dist/task/style.js +14 -0
  267. package/plugins-dist/task/subagent.js +208 -0
  268. package/{dist/tools/todo.js → plugins-dist/todo/index.js} +29 -7
  269. package/plugins-dist/todo/plugin.json +9 -0
  270. package/{dist/ui → plugins-dist/tui}/editor.js +3 -1
  271. package/plugins-dist/tui/frontend.js +586 -0
  272. package/{dist → plugins-dist/tui}/history.js +0 -1
  273. package/plugins-dist/tui/index.js +21 -0
  274. package/{dist/ui → plugins-dist/tui}/markdown.js +0 -1
  275. package/plugins-dist/tui/mentions.js +115 -0
  276. package/plugins-dist/tui/plugin.json +25 -0
  277. package/{dist/ui → plugins-dist/tui}/render.js +7 -3
  278. package/{dist/ui → plugins-dist/tui}/screen.js +6 -2
  279. package/{dist/ui → plugins-dist/tui}/transcript.js +76 -98
  280. package/{dist/ui → plugins-dist/tui}/tui.js +185 -53
  281. package/{dist/tools → plugins-dist/undo}/checkpoint.js +21 -55
  282. package/plugins-dist/undo/index.js +140 -0
  283. package/plugins-dist/undo/notes.js +36 -0
  284. package/plugins-dist/undo/plugin.json +9 -0
  285. package/plugins-dist/undo/style.js +14 -0
  286. package/plugins-dist/update/index.js +34 -0
  287. package/plugins-dist/update/plugin.json +15 -0
  288. package/plugins-dist/web/env.js +80 -0
  289. package/plugins-dist/web/index.js +124 -0
  290. package/plugins-dist/web/plugin.json +21 -0
  291. package/plugins-dist/web/renderers.js +7 -0
  292. package/{dist/tools → plugins-dist/web}/web.js +50 -24
  293. package/sdk/python/__pycache__/jade_plugin.cpython-312.pyc +0 -0
  294. package/sdk/python/jade_plugin.py +380 -0
  295. package/src/api.ts +298 -0
  296. package/src/config.ts +32 -134
  297. package/src/fetch.ts +216 -0
  298. package/src/hash.ts +39 -0
  299. package/src/host.ts +429 -0
  300. package/src/index.ts +23 -30
  301. package/src/install.ts +355 -0
  302. package/src/main.ts +155 -1387
  303. package/src/manifest.ts +160 -0
  304. package/src/membrane.ts +142 -0
  305. package/src/remote.ts +288 -0
  306. package/src/rescue.ts +217 -0
  307. package/src/resolve.ts +199 -0
  308. package/src/rpc.ts +144 -0
  309. package/src/secrets.ts +122 -0
  310. package/src/session.ts +458 -0
  311. package/src/source.ts +83 -0
  312. package/src/state.ts +120 -0
  313. package/src/update.ts +265 -262
  314. package/LICENSE +0 -21
  315. package/README.md +0 -204
  316. package/dist/commands.d.ts +0 -50
  317. package/dist/commands.js +0 -126
  318. package/dist/commands.js.map +0 -1
  319. package/dist/context.d.ts +0 -17
  320. package/dist/context.js +0 -53
  321. package/dist/context.js.map +0 -1
  322. package/dist/distro.d.ts +0 -141
  323. package/dist/distro.js +0 -462
  324. package/dist/distro.js.map +0 -1
  325. package/dist/history.d.ts +0 -10
  326. package/dist/history.js.map +0 -1
  327. package/dist/mcp.d.ts +0 -114
  328. package/dist/mcp.js.map +0 -1
  329. package/dist/memory.d.ts +0 -19
  330. package/dist/memory.js.map +0 -1
  331. package/dist/mentions.d.ts +0 -35
  332. package/dist/mentions.js +0 -130
  333. package/dist/mentions.js.map +0 -1
  334. package/dist/plugin-cli.d.ts +0 -16
  335. package/dist/plugin-cli.js +0 -294
  336. package/dist/plugin-cli.js.map +0 -1
  337. package/dist/plugins/budget.d.ts +0 -9
  338. package/dist/plugins/budget.js +0 -30
  339. package/dist/plugins/budget.js.map +0 -1
  340. package/dist/plugins/builtins.d.ts +0 -10
  341. package/dist/plugins/builtins.js +0 -25
  342. package/dist/plugins/builtins.js.map +0 -1
  343. package/dist/plugins/checks.d.ts +0 -71
  344. package/dist/plugins/checks.js.map +0 -1
  345. package/dist/plugins/compact.d.ts +0 -26
  346. package/dist/plugins/compact.js.map +0 -1
  347. package/dist/plugins/core.d.ts +0 -47
  348. package/dist/plugins/core.js +0 -229
  349. package/dist/plugins/core.js.map +0 -1
  350. package/dist/plugins/host.d.ts +0 -52
  351. package/dist/plugins/host.js +0 -115
  352. package/dist/plugins/host.js.map +0 -1
  353. package/dist/plugins/install.d.ts +0 -68
  354. package/dist/plugins/install.js +0 -377
  355. package/dist/plugins/install.js.map +0 -1
  356. package/dist/plugins/loader.d.ts +0 -410
  357. package/dist/plugins/loader.js +0 -407
  358. package/dist/plugins/loader.js.map +0 -1
  359. package/dist/plugins/policy.d.ts +0 -98
  360. package/dist/plugins/policy.js.map +0 -1
  361. package/dist/plugins/prompts.d.ts +0 -43
  362. package/dist/plugins/prompts.js +0 -284
  363. package/dist/plugins/prompts.js.map +0 -1
  364. package/dist/plugins/repeats.d.ts +0 -16
  365. package/dist/plugins/repeats.js +0 -151
  366. package/dist/plugins/repeats.js.map +0 -1
  367. package/dist/plugins/review.d.ts +0 -18
  368. package/dist/plugins/review.js.map +0 -1
  369. package/dist/plugins/schema.d.ts +0 -2
  370. package/dist/plugins/schema.js.map +0 -1
  371. package/dist/plugins/sessions.d.ts +0 -7
  372. package/dist/plugins/sessions.js +0 -110
  373. package/dist/plugins/sessions.js.map +0 -1
  374. package/dist/provider.d.ts +0 -165
  375. package/dist/provider.js.map +0 -1
  376. package/dist/session-lifecycle.d.ts +0 -61
  377. package/dist/session-lifecycle.js +0 -167
  378. package/dist/session-lifecycle.js.map +0 -1
  379. package/dist/session-scope.d.ts +0 -53
  380. package/dist/session-scope.js +0 -116
  381. package/dist/session-scope.js.map +0 -1
  382. package/dist/sessions.d.ts +0 -28
  383. package/dist/sessions.js +0 -73
  384. package/dist/sessions.js.map +0 -1
  385. package/dist/skills.d.ts +0 -37
  386. package/dist/skills.js.map +0 -1
  387. package/dist/sys.d.ts +0 -51
  388. package/dist/sys.js.map +0 -1
  389. package/dist/tools/ask.d.ts +0 -11
  390. package/dist/tools/ask.js +0 -62
  391. package/dist/tools/ask.js.map +0 -1
  392. package/dist/tools/checkpoint.d.ts +0 -43
  393. package/dist/tools/checkpoint.js.map +0 -1
  394. package/dist/tools/fs.d.ts +0 -39
  395. package/dist/tools/fs.js.map +0 -1
  396. package/dist/tools/grep.d.ts +0 -6
  397. package/dist/tools/grep.js.map +0 -1
  398. package/dist/tools/screenshot.d.ts +0 -15
  399. package/dist/tools/screenshot.js.map +0 -1
  400. package/dist/tools/shell.d.ts +0 -55
  401. package/dist/tools/shell.js.map +0 -1
  402. package/dist/tools/task.d.ts +0 -39
  403. package/dist/tools/task.js +0 -117
  404. package/dist/tools/task.js.map +0 -1
  405. package/dist/tools/todo.d.ts +0 -10
  406. package/dist/tools/todo.js.map +0 -1
  407. package/dist/tools/web.d.ts +0 -53
  408. package/dist/tools/web.js.map +0 -1
  409. package/dist/ui/configure.d.ts +0 -20
  410. package/dist/ui/configure.js +0 -447
  411. package/dist/ui/configure.js.map +0 -1
  412. package/dist/ui/diff.d.ts +0 -20
  413. package/dist/ui/diff.js.map +0 -1
  414. package/dist/ui/editor.d.ts +0 -41
  415. package/dist/ui/editor.js.map +0 -1
  416. package/dist/ui/markdown.d.ts +0 -22
  417. package/dist/ui/markdown.js.map +0 -1
  418. package/dist/ui/render.d.ts +0 -14
  419. package/dist/ui/render.js.map +0 -1
  420. package/dist/ui/renderers.d.ts +0 -8
  421. package/dist/ui/renderers.js.map +0 -1
  422. package/dist/ui/screen.d.ts +0 -118
  423. package/dist/ui/screen.js.map +0 -1
  424. package/dist/ui/transcript.d.ts +0 -46
  425. package/dist/ui/transcript.js.map +0 -1
  426. package/dist/ui/tui.d.ts +0 -47
  427. package/dist/ui/tui.js.map +0 -1
  428. package/src/commands.ts +0 -144
  429. package/src/context.ts +0 -64
  430. package/src/distro.ts +0 -577
  431. package/src/mentions.ts +0 -135
  432. package/src/plugin-cli.ts +0 -278
  433. package/src/plugins/budget.ts +0 -37
  434. package/src/plugins/builtins.ts +0 -34
  435. package/src/plugins/core.ts +0 -257
  436. package/src/plugins/host.ts +0 -146
  437. package/src/plugins/install.ts +0 -429
  438. package/src/plugins/loader.ts +0 -742
  439. package/src/plugins/prompts.ts +0 -327
  440. package/src/plugins/repeats.ts +0 -157
  441. package/src/plugins/sessions.ts +0 -109
  442. package/src/session-lifecycle.ts +0 -194
  443. package/src/session-scope.ts +0 -135
  444. package/src/sessions.ts +0 -78
  445. package/src/tools/ask.ts +0 -72
  446. package/src/tools/task.ts +0 -149
  447. package/src/ui/configure.ts +0 -471
  448. /package/{src/plugins → plugins/approval}/schema.ts +0 -0
  449. /package/{src → plugins/tui}/history.ts +0 -0
  450. /package/{src/ui → plugins/tui}/markdown.ts +0 -0
@@ -0,0 +1,90 @@
1
+ // 仓库目录、确认记录、显示用的小工具。插件之间不共享代码(只能共享类型),jade/skills、jade/checks 各有一份。
2
+ import { existsSync, realpathSync } from "node:fs";
3
+ import { appendFile, mkdir, readFile } from "node:fs/promises";
4
+ import path from "node:path";
5
+ export function realPath(p) {
6
+ try {
7
+ return realpathSync.native(p);
8
+ }
9
+ catch {
10
+ return path.resolve(p);
11
+ }
12
+ }
13
+ /** git 仓库的根目录(往上找 .git,目录或文件都算);不在仓库里时是 cwd 本身 */
14
+ export function repoRoot(cwd) {
15
+ let d = path.resolve(cwd);
16
+ for (;;) {
17
+ if (existsSync(path.join(d, ".git")))
18
+ return d;
19
+ const parent = path.dirname(d);
20
+ if (parent === d)
21
+ return path.resolve(cwd);
22
+ d = parent;
23
+ }
24
+ }
25
+ /** 从仓库根目录到工作目录的每一级目录,远的在前;工作目录不在仓库里时只有工作目录 */
26
+ export function projectDirs(root, cwd) {
27
+ const rel = path.relative(root, cwd);
28
+ const inside = rel === "" || !(rel === ".." || rel.startsWith(`..${path.sep}`) || path.isAbsolute(rel));
29
+ if (!inside)
30
+ return [cwd];
31
+ const dirs = [root];
32
+ if (rel)
33
+ for (const seg of rel.split(path.sep))
34
+ dirs.push(path.join(dirs.at(-1), seg));
35
+ return dirs;
36
+ }
37
+ /** 工作目录里的显示成相对路径,外面的显示绝对路径 */
38
+ export function display(cwd, full) {
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
+ * 用户确认过的东西(项目层的 MCP 服务),每行一条 { hash, path, at }。
45
+ * 和旧 jade 的 $JADE_HOME/trust.jsonl 同一个文件、同一种格式,旧 jade 里确认过的不用再确认
46
+ */
47
+ export class TrustFile {
48
+ file;
49
+ #known = new Set();
50
+ constructor(file) {
51
+ this.file = file;
52
+ }
53
+ async has(hash) {
54
+ if (this.#known.has(hash))
55
+ return true;
56
+ let text = "";
57
+ try {
58
+ text = await readFile(this.file, "utf8");
59
+ }
60
+ catch {
61
+ return false;
62
+ }
63
+ for (const line of text.split("\n")) {
64
+ try {
65
+ if (JSON.parse(line).hash === hash) {
66
+ this.#known.add(hash);
67
+ return true;
68
+ }
69
+ }
70
+ catch {
71
+ // 写到一半的行
72
+ }
73
+ }
74
+ return false;
75
+ }
76
+ async add(hash, where) {
77
+ await mkdir(path.dirname(this.file), { recursive: true });
78
+ await appendFile(this.file, `${JSON.stringify({ hash, path: where, at: new Date().toISOString() })}\n`);
79
+ this.#known.add(hash);
80
+ }
81
+ }
82
+ export const clip = (s, n) => (s.length > n ? s.slice(0, n) + "…" : s);
83
+ // 设了 NO_COLOR(非空)或标准输出不是终端时不输出颜色,见 https://no-color.org
84
+ const colors = Boolean(process.stdout.isTTY) && !process.env.NO_COLOR;
85
+ const paint = (open, close) => (s) => colors ? `\x1b[${open}m${s.replaceAll(`\x1b[${close}m`, `\x1b[${close}m\x1b[${open}m`)}\x1b[${close}m` : s;
86
+ export const dim = paint("2", "22");
87
+ export const red = paint("31", "39");
88
+ export const green = paint("32", "39");
89
+ export const yellow = paint("33", "39");
90
+ export const bold = paint("1", "22");
@@ -0,0 +1,94 @@
1
+ // jade/memory:跨会话的记忆(见 memory.ts)。memory 工具给模型增删,/memory 给用户查看和管理,
2
+ // 会话开始时经 prompts@1 把记忆放进系统提示词(会话中途的改动下一个会话才进提示词,这样提示缓存不失效;
3
+ // 用户在 /memory 里改了,下一次请求时附一条说明告诉模型)。
4
+ import { definePlugin } from "../../dist/api.js";
5
+ import { Memory, MEMORY_SCOPES, memoryTool, projectRoot } from "./memory.js";
6
+ import { Notes } from "./notes.js";
7
+ import { clip, dim, green, red } from "./style.js";
8
+ const notes = new Notes();
9
+ const args = (input) => (input ?? {});
10
+ export default definePlugin({
11
+ process(ctx) {
12
+ const memory = new Memory(ctx.home, projectRoot(ctx.cwd));
13
+ ctx.service("renderers@1")?.tool({
14
+ tool: "memory",
15
+ summary: (input) => {
16
+ const i = args(input);
17
+ return `${i.action} ${i.scope}: ${clip(String(i.text ?? ""), 120)}`;
18
+ },
19
+ preview: (input) => {
20
+ const i = args(input);
21
+ return `${i.action === "remove" ? red("- ") : green("+ ")}${String(i.text ?? "")}`;
22
+ },
23
+ });
24
+ ctx.service("commands@1")?.register({
25
+ name: "memory",
26
+ args: "[text]",
27
+ description: "see and remove what jade remembers across sessions, or remember text",
28
+ instant: true,
29
+ async run(input, { ui, sessions, signal }) {
30
+ const note = (text) => {
31
+ const id = sessions.current?.id;
32
+ if (id)
33
+ notes.add(id, text);
34
+ };
35
+ let text = input.trim();
36
+ if (!text) {
37
+ const entries = (await Promise.all(MEMORY_SCOPES.map(async (scope) => (await memory.list(scope)).map((t) => ({ scope, text: t }))))).flat();
38
+ if (!ui.interactive)
39
+ return entries.length ? entries.map((e) => `${e.scope}: ${e.text}`).join("\n") : "jade does not remember anything yet";
40
+ const choice = await ui.select({
41
+ title: entries.length ? "Memory: choose an entry to remove it, or add one" : "jade does not remember anything yet",
42
+ detail: dim(`user (all projects): ${memory.files.user}\nproject: ${memory.files.project}`),
43
+ options: [{ label: "Add a memory…", value: "add" }, ...entries.map((e, i) => ({ label: e.text, value: String(i), hint: e.scope }))],
44
+ }, signal);
45
+ if (!choice)
46
+ return;
47
+ if (choice !== "add") {
48
+ const entry = entries[Number(choice)];
49
+ const ok = await ui.select({
50
+ title: `Remove this ${entry.scope} memory?`,
51
+ detail: entry.text,
52
+ options: [
53
+ { label: "No", value: "no" },
54
+ { label: "Yes, remove it", value: "yes" },
55
+ ],
56
+ }, signal);
57
+ if (ok !== "yes")
58
+ return;
59
+ await memory.remove(entry.scope, entry.text);
60
+ note(`The user removed this ${entry.scope} memory, so stop following it: ${entry.text}`);
61
+ return green(`Removed from ${entry.scope} memory: ${entry.text}`);
62
+ }
63
+ text = (await ui.input({ title: "What should jade remember?", placeholder: "e.g. Reply in Chinese; run tests with bun test" }, signal)) ?? "";
64
+ if (!text.trim())
65
+ return;
66
+ }
67
+ const scope = ui.interactive
68
+ ? await ui.select({
69
+ title: "Remember it for",
70
+ options: [
71
+ { label: "All projects", value: "user", hint: "user memory" },
72
+ { label: "This project only", value: "project", hint: "project memory" },
73
+ ],
74
+ }, signal)
75
+ : "user";
76
+ if (!scope)
77
+ return;
78
+ const added = await memory.add(scope, text);
79
+ if (added)
80
+ note(`The user saved a ${scope} memory; follow it from now on: ${text.replace(/\s+/g, " ").trim()}`);
81
+ return added ? green(`Saved to ${scope} memory.`) : dim(`The ${scope} memory already has this.`);
82
+ },
83
+ });
84
+ },
85
+ async session(ctx) {
86
+ const memory = new Memory(ctx.home, projectRoot(ctx.cwd));
87
+ ctx.kernel.tool(memoryTool(memory));
88
+ ctx.kernel.hook(notes.hook(ctx.session.id, ctx.plugin, ctx.plugin));
89
+ const text = await memory.prompt();
90
+ // 段落随会话作用域撤销
91
+ if (text)
92
+ ctx.service("prompts@1")?.add({ text });
93
+ },
94
+ });
@@ -2,9 +2,10 @@
2
2
  //
3
3
  // 两个范围:user(所有项目通用,$JADE_HOME/MEMORY.md)和 project(这个仓库,$JADE_HOME/projects/<key>/MEMORY.md)。
4
4
  // 都放在配置目录而不是仓库里:不会被提交,也不会被别人的仓库带进来。
5
- // 文件是 Markdown 列表,一行一条,用户可以直接编辑。会话开始时由 prompts 插件读进系统提示词,
6
- // 模型用 memory 工具增删,用户用 /memory 查看和管理。
5
+ // 文件是 Markdown 列表,一行一条,用户可以直接编辑。会话开始时经 prompts@1 读进系统提示词,
6
+ // 模型用 memory 工具增删,用户用 /memory 查看和管理。从旧 jade 的 memory.ts 移植,文件位置和格式不变。
7
7
  import { createHash } from "node:crypto";
8
+ import { existsSync, realpathSync } from "node:fs";
8
9
  import { mkdir, readFile, writeFile } from "node:fs/promises";
9
10
  import path from "node:path";
10
11
  export const MEMORY_SCOPES = ["user", "project"];
@@ -89,6 +90,24 @@ export function projectKey(root) {
89
90
  const readable = full.replace(/[^A-Za-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(-60);
90
91
  return `${readable}-${createHash("sha256").update(full.toLowerCase()).digest("hex").slice(0, 8)}`;
91
92
  }
93
+ /** git 仓库的根目录(往上找 .git);不在仓库里时是 cwd 本身。和旧 jade 的 git rev-parse 结果相同,项目记忆的位置不变 */
94
+ export function projectRoot(cwd) {
95
+ let dir = path.resolve(cwd);
96
+ for (;;) {
97
+ if (existsSync(path.join(dir, ".git"))) {
98
+ try {
99
+ return realpathSync.native(dir);
100
+ }
101
+ catch {
102
+ return dir;
103
+ }
104
+ }
105
+ const up = path.dirname(dir);
106
+ if (up === dir)
107
+ return path.resolve(cwd);
108
+ dir = up;
109
+ }
110
+ }
92
111
  export function memoryTool(memory) {
93
112
  return {
94
113
  name: "memory",
@@ -126,4 +145,3 @@ export function memoryTool(memory) {
126
145
  },
127
146
  };
128
147
  }
129
- //# sourceMappingURL=memory.js.map
@@ -0,0 +1,36 @@
1
+ // 给模型的说明([Note from jade]):命令里做的事(例如用户删掉了一条记忆)要让模型知道,
2
+ // 但命令拿不到会话日志,也不该替用户发一条消息。所以先记下来,下一次请求模型时在 context.project 里
3
+ // 附在最后一条消息后面,并用 ctx.record 写进日志(derived):之后的投影、恢复的会话里它都在同一个位置。
4
+ // 插件之间不共享代码,jade/undo 里也有一份。
5
+ export class Notes {
6
+ /** 会话 → 还没交给模型的说明 */
7
+ #pending = new Map();
8
+ add(sessionId, text) {
9
+ this.#pending.set(sessionId, [...(this.#pending.get(sessionId) ?? []), text]);
10
+ }
11
+ /** 会话里的 context.project hook;key 是 derived 里的键 */
12
+ hook(sessionId, plugin, key) {
13
+ return {
14
+ kind: "transform",
15
+ point: "context.project",
16
+ order: -40,
17
+ fn: async (messages, ctx) => {
18
+ let state = ctx.derived[key] ?? {};
19
+ const fresh = this.#pending.get(sessionId);
20
+ if (fresh?.length && messages.length > 0) {
21
+ const at = String(messages.length - 1);
22
+ state = { ...state, [at]: [...(state[at] ?? []), ...fresh] };
23
+ await ctx.record(key, state);
24
+ this.#pending.delete(sessionId);
25
+ }
26
+ return messages.map((m, i) => {
27
+ const notes = state[i];
28
+ if (!notes?.length || m.role !== "user")
29
+ return m;
30
+ const blocks = notes.map((text) => ({ kind: "text", text: `[Note from jade] ${text}`, origin: { by: "plugin", id: plugin }, trust: "trusted" }));
31
+ return { ...m, content: [...m.content, ...blocks] };
32
+ });
33
+ },
34
+ };
35
+ }
36
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "id": "jade/memory",
3
+ "version": "0.2.0",
4
+ "api": "^1",
5
+ "entry": "./index.js",
6
+ "optional": [
7
+ "prompts@1",
8
+ "commands@1",
9
+ "renderers@1"
10
+ ]
11
+ }
@@ -0,0 +1,14 @@
1
+ // 显示用的小工具:截断和 ANSI 颜色。插件之间不共享代码(只能共享类型),所以这里也有一份(同 jade/fs 的 style.ts)。
2
+ export const clip = (s, n) => (s.length > n ? s.slice(0, n) + "…" : s);
3
+ // 设了 NO_COLOR(非空)或标准输出不是终端时不输出颜色,见 https://no-color.org
4
+ const colors = Boolean(process.stdout.isTTY) && !process.env.NO_COLOR;
5
+ /**
6
+ * 每种样式用自己的关闭码,不用 \x1b[0m 全部重置:外面套着别的样式时,后面的文字仍保持外层样式。
7
+ * 里面出现同一个关闭码(例如 dim 里套 bold,两者都用 22 关闭)时紧接着重新打开外层的样式
8
+ */
9
+ const paint = (open, close) => (s) => colors ? `\x1b[${open}m${s.replaceAll(`\x1b[${close}m`, `\x1b[${close}m\x1b[${open}m`)}\x1b[${close}m` : s;
10
+ export const dim = paint("2", "22");
11
+ export const red = paint("31", "39");
12
+ export const green = paint("32", "39");
13
+ export const yellow = paint("33", "39");
14
+ export const bold = paint("1", "22");
@@ -0,0 +1,120 @@
1
+ // 读取消息里 @ 引用的文件和目录。只有存在的路径才算引用,所以消息里普通的 @someone 原样保留。
2
+ //
3
+ // 旧 jade 用 read_file / list_dir 工具本身读取,读到的文件算作"读过";jade/fs 的工具是它会话里的私有对象,
4
+ // 别的插件拿不到,所以这里自己读,格式和 read_file、list_dir 返回的一样(带行号)。
5
+ import { readdir, readFile, stat } from "node:fs/promises";
6
+ import os from "node:os";
7
+ import path from "node:path";
8
+ /** @ 后面的路径:@"带 空格 的路径" 或者到空白为止 */
9
+ const MENTION = /(?<=^|\s)@(?:"([^"\n]+)"|([^\s"]+))/g;
10
+ const MAX_LINES = 2000;
11
+ const MAX_LINE_CHARS = 2000;
12
+ const MAX_READ_CHARS = 100_000;
13
+ const MAX_IMAGE_BYTES = 5_000_000;
14
+ const MAX_PDF_BYTES = 10_000_000;
15
+ /** 一条消息最多附上几个引用 */
16
+ const MAX_MENTIONS = 20;
17
+ const IMAGE_TYPES = {
18
+ ".png": "image/png",
19
+ ".jpg": "image/jpeg",
20
+ ".jpeg": "image/jpeg",
21
+ ".gif": "image/gif",
22
+ ".webp": "image/webp",
23
+ };
24
+ /** 消息里引用的路径,去重,按出现顺序;末尾的标点(句号、逗号……)不算路径 */
25
+ export function parseMentions(text) {
26
+ const out = [];
27
+ for (const m of text.matchAll(MENTION)) {
28
+ const p = m[1] ?? m[2].replace(/[.,;:!?)\]},。;:!?)】]+$/u, "");
29
+ if (p && !out.includes(p))
30
+ out.push(p);
31
+ }
32
+ return out;
33
+ }
34
+ /** 显示用:工作目录内的路径用相对形式,统一为正斜杠 */
35
+ export function display(cwd, full) {
36
+ const rel = path.relative(cwd, full);
37
+ const shown = rel && rel !== ".." && !rel.startsWith(`..${path.sep}`) && !path.isAbsolute(rel) ? rel : full;
38
+ return shown.split(path.sep).join("/");
39
+ }
40
+ /** 读取消息里引用的文件和目录 */
41
+ export async function attachMentions(text, opts) {
42
+ const out = { blocks: [], attached: [], failed: [] };
43
+ const origin = { by: "plugin", id: opts.plugin };
44
+ for (const p of parseMentions(text).slice(0, MAX_MENTIONS)) {
45
+ opts.signal?.throwIfAborted();
46
+ const full = path.resolve(opts.cwd, p.replace(/^~(?=$|[\\/])/, os.homedir()));
47
+ const info = await stat(full).catch(() => undefined);
48
+ if (!info)
49
+ continue;
50
+ const shown = display(opts.cwd, full);
51
+ try {
52
+ const dir = info.isDirectory();
53
+ const content = dir ? await listDir(full) : await readAny(full, shown, info.size);
54
+ if (typeof content === "object" && "error" in content) {
55
+ out.failed.push({ path: shown, reason: content.error });
56
+ continue;
57
+ }
58
+ const head = dir
59
+ ? `[Note from jade] The user referenced the directory ${shown}. Its entries, as list_dir returns them:`
60
+ : `[Note from jade] The user referenced the file ${shown}. Its content, as read_file returns it (read it with read_file before editing it):`;
61
+ out.blocks.push({ kind: "text", text: head, origin, trust: "trusted" });
62
+ if (typeof content === "string")
63
+ out.blocks.push({ kind: "text", text: content, origin, trust: "untrusted" });
64
+ else
65
+ out.blocks.push(content.block);
66
+ out.attached.push(shown);
67
+ }
68
+ catch (err) {
69
+ out.failed.push({ path: shown, reason: err instanceof Error ? err.message : String(err) });
70
+ }
71
+ }
72
+ return out;
73
+ async function readAny(full, shown, size) {
74
+ const ext = path.extname(full).toLowerCase();
75
+ const mediaType = IMAGE_TYPES[ext];
76
+ if (mediaType) {
77
+ if (size > MAX_IMAGE_BYTES)
78
+ return { error: `image is ${size} bytes; at most ${MAX_IMAGE_BYTES} can be attached` };
79
+ const data = (await readFile(full)).toString("base64");
80
+ return { block: { kind: "image", source: { type: "base64", media_type: mediaType, data }, origin, trust: "untrusted" } };
81
+ }
82
+ if (ext === ".pdf") {
83
+ if (size > MAX_PDF_BYTES)
84
+ return { error: `PDF is ${size} bytes; at most ${MAX_PDF_BYTES} can be attached` };
85
+ const data = (await readFile(full)).toString("base64");
86
+ return { block: { kind: "document", source: { type: "base64", media_type: "application/pdf", data }, origin, trust: "untrusted" } };
87
+ }
88
+ const buf = await readFile(full);
89
+ if (buf.subarray(0, 8000).includes(0))
90
+ return { error: `${shown} is a binary file (${buf.length} bytes) and cannot be shown as text` };
91
+ return numbered(buf.toString("utf8"));
92
+ }
93
+ }
94
+ /** 和 read_file 一样:每行前面是从 1 开始的行号和一个制表符,超长的截断 */
95
+ function numbered(text) {
96
+ if (text.length === 0)
97
+ return "(empty file)";
98
+ const lines = text.split(/\r?\n/);
99
+ if (lines.at(-1) === "")
100
+ lines.pop();
101
+ const slice = lines.slice(0, MAX_LINES);
102
+ const out = [];
103
+ let size = 0;
104
+ for (const [i, l] of slice.entries()) {
105
+ const row = `${i + 1}\t${l.length > MAX_LINE_CHARS ? `${l.slice(0, MAX_LINE_CHARS)}… [line truncated: ${l.length} characters]` : l}`;
106
+ if (out.length > 0 && size + row.length + 1 > MAX_READ_CHARS)
107
+ break;
108
+ out.push(row);
109
+ size += row.length + 1;
110
+ }
111
+ const body = out.join("\n");
112
+ if (out.length < lines.length)
113
+ return `${body}\n(showing lines 1-${out.length} of ${lines.length}; read_file with offset ${out.length + 1} for the rest)`;
114
+ return body;
115
+ }
116
+ async function listDir(full) {
117
+ const entries = await readdir(full, { withFileTypes: true });
118
+ const names = entries.map((e) => e.name + (e.isDirectory() ? "/" : "")).sort();
119
+ return names.length > 0 ? names.join("\n") : "(empty directory)";
120
+ }
@@ -0,0 +1,69 @@
1
+ // jade/mentions:用户消息里 @ 引用的文件和目录,内容随消息交给模型,模型不用再读一遍。
2
+ //
3
+ // 内核没有改写用户输入的扩展点:input.received 原样进日志。所以在 context.project 里把附件加到引用它的那条用户消息后面。
4
+ // 附件在消息之后第一次投影时读取,先用 ctx.record 写进日志(derived)再使用(I-5):之后每次投影都从 derived 里取,
5
+ // 文件之后变了也不影响已经发出的消息(提示缓存不失效),恢复会话后也一样。
6
+ // 输入框里 @ 的补全不在这里,在 jade/tui。
7
+ import { definePlugin } from "../../dist/api.js";
8
+ import { attachMentions } from "./attach.js";
9
+ import { clip, dim, yellow } from "./style.js";
10
+ /** 读文件的时限 */
11
+ const READ_TIMEOUT_MS = 30_000;
12
+ /** 用户自己写的文字;工具结果、插件加的说明不算 */
13
+ const userText = (m) => (m.role === "user" ? m.content.flatMap((b) => (b.kind === "text" && b.origin.by === "user" ? [b.text] : [])).join("\n") : "");
14
+ export default definePlugin({
15
+ process(ctx) {
16
+ const renderers = ctx.service("renderers@1");
17
+ renderers?.event({
18
+ event: "attached",
19
+ render: (data) => {
20
+ const d = data;
21
+ const lines = [
22
+ ...d.failed.map((f) => yellow(`[@${f.path} not attached: ${clip(f.reason, 200)}]`)),
23
+ ...(d.attached.length ? [dim(`[attached ${d.attached.map((p) => `@${p}`).join(", ")}]`)] : []),
24
+ ];
25
+ return lines.length ? { line: lines.join("\n") } : undefined;
26
+ },
27
+ });
28
+ },
29
+ session(ctx) {
30
+ const key = ctx.plugin;
31
+ /** 本进程里已经扫过的消息条数:没有 @ 的消息不用记进日志 */
32
+ let scanned = 0;
33
+ ctx.kernel.hook({
34
+ kind: "transform",
35
+ point: "context.project",
36
+ // 排在压缩之前:压缩估算的是带着附件的投影
37
+ order: -50,
38
+ // 出错时跳过(不附上),不让这一轮失败
39
+ optional: true,
40
+ timeoutMs: READ_TIMEOUT_MS + 5_000,
41
+ fn: async (messages, hook) => {
42
+ let state = hook.derived[key] ?? { upTo: 0, attached: {} };
43
+ const start = Math.max(state.upTo, scanned);
44
+ let changed = false;
45
+ if (messages.length > start) {
46
+ const attached = { ...state.attached };
47
+ const signal = AbortSignal.any([hook.signal, AbortSignal.timeout(READ_TIMEOUT_MS)]);
48
+ for (let i = start; i < messages.length; i++) {
49
+ const text = userText(messages[i]);
50
+ if (!text.includes("@"))
51
+ continue;
52
+ changed = true;
53
+ const refs = await attachMentions(text, { cwd: ctx.cwd, plugin: ctx.plugin, signal });
54
+ if (refs.blocks.length)
55
+ attached[i] = refs.blocks;
56
+ if (refs.attached.length || refs.failed.length)
57
+ await hook.emit("attached", { attached: refs.attached, failed: refs.failed });
58
+ }
59
+ state = { upTo: messages.length, attached };
60
+ // 处理过带 @ 的消息才记:之后的投影、恢复的会话都用这次读到的内容
61
+ if (changed)
62
+ await hook.record(key, state);
63
+ scanned = messages.length;
64
+ }
65
+ return messages.map((m, i) => (state.attached[i] ? { ...m, content: [...m.content, ...state.attached[i]] } : m));
66
+ },
67
+ });
68
+ },
69
+ });
@@ -0,0 +1,9 @@
1
+ {
2
+ "id": "jade/mentions",
3
+ "version": "0.2.0",
4
+ "api": "^1",
5
+ "entry": "./index.js",
6
+ "optional": [
7
+ "renderers@1"
8
+ ]
9
+ }
@@ -0,0 +1,14 @@
1
+ // 显示用的小工具:截断和 ANSI 颜色。插件之间不共享代码(只能共享类型),所以这里也有一份(同 jade/fs 的 style.ts)。
2
+ export const clip = (s, n) => (s.length > n ? s.slice(0, n) + "…" : s);
3
+ // 设了 NO_COLOR(非空)或标准输出不是终端时不输出颜色,见 https://no-color.org
4
+ const colors = Boolean(process.stdout.isTTY) && !process.env.NO_COLOR;
5
+ /**
6
+ * 每种样式用自己的关闭码,不用 \x1b[0m 全部重置:外面套着别的样式时,后面的文字仍保持外层样式。
7
+ * 里面出现同一个关闭码(例如 dim 里套 bold,两者都用 22 关闭)时紧接着重新打开外层的样式
8
+ */
9
+ const paint = (open, close) => (s) => colors ? `\x1b[${open}m${s.replaceAll(`\x1b[${close}m`, `\x1b[${close}m\x1b[${open}m`)}\x1b[${close}m` : s;
10
+ export const dim = paint("2", "22");
11
+ export const red = paint("31", "39");
12
+ export const green = paint("32", "39");
13
+ export const yellow = paint("33", "39");
14
+ export const bold = paint("1", "22");
@@ -0,0 +1,53 @@
1
+ // 模型配置:$JADE_HOME/.env(默认 ~/.jade/.env),和旧 jade 相同。shell 里已经设置的变量优先。
2
+ //
3
+ // 不读当前目录的 .env:那是被操作项目自己的配置,里面的 OPENAI_API_KEY 等会改掉模型选择。
4
+ import { readFile } from "node:fs/promises";
5
+ /** 解析 KEY=VALUE 格式:忽略空行和 # 注释,允许 export 前缀,去掉成对的引号(双引号里的 \n 换成换行) */
6
+ export function parseEnv(text) {
7
+ const out = {};
8
+ for (const raw of text.split(/\r?\n/)) {
9
+ const m = /^\s*(?:export\s+)?([A-Za-z_][A-Za-z0-9_]*)\s*=\s*(.*?)\s*$/.exec(raw);
10
+ if (!m)
11
+ continue;
12
+ let value = m[2];
13
+ const quote = value[0];
14
+ if ((quote === '"' || quote === "'") && value.length >= 2 && value.endsWith(quote)) {
15
+ value = value.slice(1, -1);
16
+ if (quote === '"')
17
+ value = value.replaceAll("\\n", "\n");
18
+ }
19
+ else {
20
+ // 未加引号的值里,空白之后的 # 是注释
21
+ value = value.replace(/\s+#.*$/, "");
22
+ }
23
+ out[m[1]] = value;
24
+ }
25
+ return out;
26
+ }
27
+ /** 配置文件里的变量,env 里已有的优先;文件不存在时就是 env */
28
+ export async function envWithFile(file, env = process.env) {
29
+ let text = "";
30
+ try {
31
+ text = await readFile(file, "utf8");
32
+ }
33
+ catch {
34
+ // 没有配置文件
35
+ }
36
+ return { ...parseEnv(text), ...Object.fromEntries(Object.entries(env).filter(([, v]) => v !== undefined)) };
37
+ }
38
+ /**
39
+ * token 数:整数,或者带 K(千)、M(百万)的写法,例如 32000、512K、1M、1.5M,不区分大小写,可以用 _ 分隔数字。
40
+ * 不是正整数时抛出,错误信息里带变量名 name
41
+ */
42
+ export function parseTokens(name, text) {
43
+ const m = /^\s*(\d+(?:\.\d+)?)\s*([km])?\s*$/i.exec(text.replaceAll("_", ""));
44
+ const unit = m?.[2] ? (m[2].toLowerCase() === "k" ? 1_000 : 1_000_000) : 1;
45
+ const n = m ? (unit === 1 ? Number(m[1]) : Math.round(Number(m[1]) * unit)) : NaN;
46
+ if (!Number.isInteger(n) || n <= 0)
47
+ throw new Error(`${name} must be a number of tokens such as 32000, 512K or 1M, got ${JSON.stringify(text)}`);
48
+ return n;
49
+ }
50
+ /** 至少配置了一种模型 */
51
+ export function hasProvider(env = process.env) {
52
+ return Boolean(env.JADE_PROVIDER || env.OPENAI_API_KEY || env.OPENAI_COMPAT_BASE_URL || env.ANTHROPIC_API_KEY);
53
+ }