@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
@@ -1,429 +0,0 @@
1
- // 插件的安装、更新、卸载(jade plugin …)。
2
- //
3
- // 来源有三种:
4
- // - git:https://…、git@…、github:user/repo、user/repo(本地没有这个路径时),可以用 #ref 指定分支、tag 或提交;
5
- // - npm:包名(可以带 @版本)、npm:<任意 bun add 认识的写法>、本地的 .tgz;
6
- // - 本地目录:复制过来;--link 时只建一个链接,方便开发插件。
7
- // 先下载到插件目录里的 .staging-* 临时目录(以 . 开头,发现插件时会跳过),检查确实是插件、装好依赖之后再改名就位,
8
- // 失败时不会留下装了一半的插件。安装记录在插件目录的 .installed.json 里,jade plugin update 按记录重新下载。
9
- //
10
- // 安装不执行插件的代码;插件的 package.json 有 dependencies 时安装依赖(Bun 下用 bun,Node 下用 npm,都不运行安装脚本)。
11
-
12
- import { execFile } from "node:child_process";
13
- import { randomBytes } from "node:crypto";
14
- import { cp, lstat, mkdir, readdir, readFile, rename, rm, rmdir, stat, symlink, unlink, writeFile } from "node:fs/promises";
15
- import path from "node:path";
16
- import { inspectPlugin, type PluginInfo } from "./loader.ts";
17
- import { npmCommand } from "../sys.ts";
18
-
19
- export type SourceKind = "git" | "npm" | "local";
20
-
21
- export interface PluginSource {
22
- kind: SourceKind;
23
- /** git:仓库地址;npm:交给 bun add 的写法;local:绝对路径 */
24
- location: string;
25
- /** git 的分支、tag 或提交 */
26
- ref?: string;
27
- }
28
-
29
- export interface InstallRecord {
30
- /** 用户写的来源(本地路径换成了绝对路径) */
31
- source: string;
32
- kind: SourceKind | "link";
33
- /** 只安装来源里的这个子目录 */
34
- subdir?: string;
35
- /** git:安装的提交 */
36
- commit?: string;
37
- version?: string;
38
- installedAt: string;
39
- updatedAt?: string;
40
- }
41
-
42
- export interface InstallOptions {
43
- /** 插件目录:$JADE_HOME/plugins 或 <仓库>/.jade/plugins */
44
- pluginsDir: string;
45
- /** 解析相对路径用 */
46
- cwd: string;
47
- /** 安装后的目录名,默认取插件声明的 name、包名或仓库名 */
48
- name?: string;
49
- subdir?: string;
50
- /** 本地目录:建链接而不是复制 */
51
- link?: boolean;
52
- /** 已经有同名插件时替换它 */
53
- force?: boolean;
54
- /** 进度(正在下载、正在安装依赖) */
55
- log?: (text: string) => void;
56
- }
57
-
58
- export interface Installed {
59
- name: string;
60
- dir: string;
61
- record: InstallRecord;
62
- info: PluginInfo;
63
- }
64
-
65
- /** 插件目录名 */
66
- export const PLUGIN_NAME = /^[a-z0-9][a-z0-9._-]*$/;
67
- const RECORDS = ".installed.json";
68
-
69
- /** 识别来源的种类 */
70
- export async function parseSource(spec: string, cwd: string): Promise<PluginSource> {
71
- const s = spec.trim();
72
- if (!s) throw new Error("no plugin source given");
73
- if (s.startsWith("npm:")) return { kind: "npm", location: s.slice(4) };
74
- const [base, ref] = splitRef(s);
75
- if (/^github:/.test(base)) return { kind: "git", location: `https://github.com/${base.slice(7).replace(/\.git$/, "")}.git`, ref };
76
- if (/^gitlab:/.test(base)) return { kind: "git", location: `https://gitlab.com/${base.slice(7).replace(/\.git$/, "")}.git`, ref };
77
- if (/^git\+/.test(base)) return { kind: "git", location: base.slice(4), ref };
78
- if (/^(git@|ssh:\/\/|git:\/\/)/.test(base)) return { kind: "git", location: base, ref };
79
- if (/^https?:\/\//.test(base)) {
80
- if (/\.(tgz|tar\.gz)$/.test(base)) return { kind: "npm", location: s };
81
- return { kind: "git", location: base, ref };
82
- }
83
- const local = path.resolve(cwd, s.replace(/^~(?=$|[\\/])/, process.env.HOME ?? process.env.USERPROFILE ?? "~"));
84
- const info = await stat(local).catch(() => undefined);
85
- if (info?.isDirectory()) return { kind: "local", location: local };
86
- if (info?.isFile()) {
87
- if (/\.(tgz|tar\.gz)$/.test(local)) return { kind: "npm", location: local };
88
- throw new Error(`${s} is a file; give a plugin directory, a .tgz package, a git URL or an npm package`);
89
- }
90
- // user/repo:本地没有这个路径时按 GitHub 仓库处理(npm 的包名不含 /,带作用域的以 @ 开头)
91
- if (/^[\w.-]+\/[\w.-]+$/.test(base) && !s.startsWith(".")) {
92
- return { kind: "git", location: `https://github.com/${base.replace(/\.git$/, "")}.git`, ref };
93
- }
94
- if (/^(\.|\/|[a-zA-Z]:[\\/])/.test(s)) throw new Error(`${s} does not exist`);
95
- return { kind: "npm", location: s };
96
- }
97
-
98
- /** "url#ref" 拆成两部分 */
99
- function splitRef(s: string): [string, string | undefined] {
100
- const i = s.lastIndexOf("#");
101
- return i > 0 ? [s.slice(0, i), s.slice(i + 1) || undefined] : [s, undefined];
102
- }
103
-
104
- export async function addPlugin(spec: string, opts: InstallOptions): Promise<Installed> {
105
- const source = await parseSource(spec, opts.cwd);
106
- await mkdir(opts.pluginsDir, { recursive: true });
107
-
108
- if (opts.link) {
109
- if (source.kind !== "local") throw new Error("--link only works with a local directory");
110
- const dir = opts.subdir ? inSubdir(source.location, opts.subdir) : source.location;
111
- const info = await inspectPlugin(dir);
112
- const name = pickName(opts.name, info, dir);
113
- const target = path.join(opts.pluginsDir, name);
114
- await makeRoom(target, name, opts.force);
115
- await symlink(dir, target, process.platform === "win32" ? "junction" : "dir");
116
- const record: InstallRecord = { source: dir, kind: "link", installedAt: now(), ...(info.version ? { version: info.version } : {}) };
117
- await saveRecord(opts.pluginsDir, name, record);
118
- return { name, dir: target, record, info };
119
- }
120
-
121
- const staging = path.join(opts.pluginsDir, `.staging-${randomBytes(4).toString("hex")}`);
122
- try {
123
- const fetched = await fetchInto(source, staging, opts.subdir, opts.log);
124
- const name = pickName(opts.name, fetched.info, opts.subdir ?? nameHint(source));
125
- const target = path.join(opts.pluginsDir, name);
126
- await makeRoom(target, name, opts.force);
127
- await rename(fetched.dir, target);
128
- const record: InstallRecord = {
129
- source: source.kind === "local" ? source.location : spec.trim(),
130
- kind: source.kind,
131
- ...(opts.subdir ? { subdir: opts.subdir } : {}),
132
- ...(fetched.commit ? { commit: fetched.commit } : {}),
133
- ...(fetched.info.version ? { version: fetched.info.version } : {}),
134
- installedAt: now(),
135
- };
136
- await saveRecord(opts.pluginsDir, name, record);
137
- return { name, dir: target, record, info: fetched.info };
138
- } finally {
139
- await rm(staging, { recursive: true, force: true }).catch(() => {});
140
- }
141
- }
142
-
143
- export interface UpdateResult {
144
- name: string;
145
- status: "updated" | "current" | "linked" | "unmanaged" | "failed";
146
- from?: string;
147
- to?: string;
148
- error?: string;
149
- }
150
-
151
- /** 按安装记录重新下载;没给名字时更新这个插件目录里所有用 jade plugin add 装的插件 */
152
- export async function updatePlugins(names: string[], opts: Omit<InstallOptions, "name" | "subdir" | "link" | "force">): Promise<UpdateResult[]> {
153
- const records = await readRecords(opts.pluginsDir);
154
- const targets = names.length ? names : Object.keys(records).sort();
155
- const out: UpdateResult[] = [];
156
- for (const name of targets) {
157
- const rec = records[name];
158
- const target = path.join(opts.pluginsDir, name);
159
- if (!rec) {
160
- const exists = await stat(target).catch(() => undefined);
161
- out.push({ name, status: exists ? "unmanaged" : "failed", ...(exists ? {} : { error: "not installed" }) });
162
- continue;
163
- }
164
- if (rec.kind === "link") {
165
- out.push({ name, status: "linked" });
166
- continue;
167
- }
168
- const staging = path.join(opts.pluginsDir, `.staging-${randomBytes(4).toString("hex")}`);
169
- try {
170
- opts.log?.(`${name}: fetching ${rec.source}`);
171
- const source = await parseSource(rec.source, opts.cwd);
172
- const fetched = await fetchInto(source, staging, rec.subdir, opts.log);
173
- const from = rec.commit?.slice(0, 7) ?? rec.version;
174
- const to = fetched.commit?.slice(0, 7) ?? fetched.info.version;
175
- // git 看提交,npm 看版本;本地目录每次都重新复制
176
- const same = rec.kind === "git" ? rec.commit === fetched.commit : rec.kind === "npm" ? rec.version !== undefined && rec.version === fetched.info.version : false;
177
- if (same && (await stat(target).catch(() => undefined))) {
178
- out.push({ name, status: "current", to });
179
- continue;
180
- }
181
- const old = path.join(opts.pluginsDir, `.old-${randomBytes(4).toString("hex")}`);
182
- const had = Boolean(await lstat(target).catch(() => undefined));
183
- if (had) await rename(target, old);
184
- try {
185
- await rename(fetched.dir, target);
186
- } catch (err) {
187
- if (had) await rename(old, target).catch(() => {});
188
- throw err;
189
- }
190
- if (had) await removeDir(old);
191
- const next: InstallRecord = {
192
- ...rec,
193
- ...(fetched.commit ? { commit: fetched.commit } : {}),
194
- ...(fetched.info.version ? { version: fetched.info.version } : {}),
195
- updatedAt: now(),
196
- };
197
- await saveRecord(opts.pluginsDir, name, next);
198
- out.push({ name, status: "updated", from, to });
199
- } catch (err) {
200
- out.push({ name, status: "failed", error: err instanceof Error ? err.message : String(err) });
201
- } finally {
202
- await rm(staging, { recursive: true, force: true }).catch(() => {});
203
- }
204
- }
205
- return out;
206
- }
207
-
208
- /** 删除插件目录(链接只删链接本身)和安装记录;不存在时返回 false */
209
- export async function removePlugin(name: string, pluginsDir: string): Promise<boolean> {
210
- if (!PLUGIN_NAME.test(name)) throw new Error(`invalid plugin name ${JSON.stringify(name)}`);
211
- const target = path.join(pluginsDir, name);
212
- const existed = Boolean(await lstat(target).catch(() => undefined));
213
- if (existed) await removeDir(target);
214
- const records = await readRecords(pluginsDir);
215
- const recorded = name in records;
216
- if (recorded) {
217
- delete records[name];
218
- await writeRecords(pluginsDir, records);
219
- }
220
- return existed || recorded;
221
- }
222
-
223
- export async function readRecords(pluginsDir: string): Promise<Record<string, InstallRecord>> {
224
- try {
225
- const json = JSON.parse(await readFile(path.join(pluginsDir, RECORDS), "utf8"));
226
- return typeof json?.plugins === "object" && json.plugins !== null ? json.plugins : {};
227
- } catch {
228
- return {};
229
- }
230
- }
231
-
232
- async function writeRecords(pluginsDir: string, records: Record<string, InstallRecord>) {
233
- const sorted = Object.fromEntries(Object.entries(records).sort(([a], [b]) => a.localeCompare(b)));
234
- await writeFile(path.join(pluginsDir, RECORDS), `${JSON.stringify({ plugins: sorted }, null, 2)}\n`);
235
- }
236
-
237
- async function saveRecord(pluginsDir: string, name: string, record: InstallRecord) {
238
- const records = await readRecords(pluginsDir);
239
- records[name] = record;
240
- await writeRecords(pluginsDir, records);
241
- }
242
-
243
- // ---------- 下载 ----------
244
-
245
- /** 下载到 staging 里,返回插件目录(staging 里的某个子目录) */
246
- async function fetchInto(source: PluginSource, staging: string, subdir: string | undefined, log?: (text: string) => void) {
247
- await mkdir(staging, { recursive: true });
248
- let root: string;
249
- let commit: string | undefined;
250
- if (source.kind === "git") {
251
- root = path.join(staging, "repo");
252
- log?.(`cloning ${source.location}${source.ref ? ` (${source.ref})` : ""}`);
253
- try {
254
- await run("git", ["clone", "--depth", "1", ...(source.ref ? ["--branch", source.ref] : []), "--", source.location, root], staging);
255
- } catch (err) {
256
- // --branch 不认提交哈希:完整克隆后再切过去
257
- if (!source.ref) throw err;
258
- await rm(root, { recursive: true, force: true });
259
- await run("git", ["clone", "--", source.location, root], staging);
260
- await run("git", ["checkout", "--detach", source.ref], root);
261
- }
262
- commit = (await run("git", ["rev-parse", "HEAD"], root)).trim();
263
- await rm(path.join(root, ".git"), { recursive: true, force: true });
264
- } else if (source.kind === "npm") {
265
- const work = path.join(staging, "npm");
266
- await mkdir(work);
267
- await writeFile(path.join(work, "package.json"), JSON.stringify({ name: "jade-plugin-download", private: true }));
268
- log?.(`downloading ${source.location}`);
269
- const pm = packageManager();
270
- await run(pm.cmd, [...pm.prefix, ...pm.add(source.location)], work);
271
- const deps = Object.keys((JSON.parse(await readFile(path.join(work, "package.json"), "utf8")).dependencies ?? {}) as Record<string, string>);
272
- if (deps.length !== 1) throw new Error(`could not tell which package ${source.location} installed`);
273
- root = path.join(staging, "package");
274
- // 包的依赖装在外层的 node_modules 里,复制过去之后重新安装
275
- await cp(path.join(work, "node_modules", deps[0]!), root, { recursive: true, dereference: true });
276
- // bun 在包目录里留下的标记,不属于插件
277
- await rm(path.join(root, ".bun-tag"), { force: true });
278
- await rm(work, { recursive: true, force: true });
279
- } else {
280
- root = path.join(staging, "local");
281
- log?.(`copying ${source.location}`);
282
- await cp(source.location, root, {
283
- recursive: true,
284
- filter: (src) => !/[\\/](node_modules|\.git)$/.test(src),
285
- });
286
- }
287
- const dir = subdir ? inSubdir(root, subdir) : root;
288
- const info = await inspectPlugin(dir);
289
- await installDependencies(dir, log);
290
- return { dir, commit, info };
291
- }
292
-
293
- async function installDependencies(dir: string, log?: (text: string) => void) {
294
- let pkg: { dependencies?: Record<string, string> };
295
- try {
296
- pkg = JSON.parse(await readFile(path.join(dir, "package.json"), "utf8"));
297
- } catch {
298
- return;
299
- }
300
- if (!pkg.dependencies || Object.keys(pkg.dependencies).length === 0) return;
301
- log?.("installing dependencies");
302
- const pm = packageManager();
303
- await run(pm.cmd, [...pm.prefix, ...pm.install], dir);
304
- }
305
-
306
- function inSubdir(root: string, subdir: string): string {
307
- const full = path.resolve(root, subdir);
308
- const rel = path.relative(root, full);
309
- if (rel === ".." || rel.startsWith(`..${path.sep}`) || path.isAbsolute(rel)) throw new Error(`--path ${subdir} points outside the source`);
310
- return full;
311
- }
312
-
313
- function nameHint(source: PluginSource): string {
314
- if (source.kind === "npm") return source.location.replace(/^(@[^/]+\/)?/, "").replace(/@.*$/, "").replace(/\.(tgz|tar\.gz)$/, "");
315
- return source.location.replace(/[\\/]+$/, "").replace(/\.git$/, "");
316
- }
317
-
318
- /** --name,否则插件声明的名字,否则来源的最后一段;整理成合法的目录名 */
319
- function pickName(given: string | undefined, info: PluginInfo, hint: string): string {
320
- if (given !== undefined) {
321
- if (!PLUGIN_NAME.test(given)) throw new Error(`--name may only contain lowercase letters, digits, '.', '_' and '-'`);
322
- return given;
323
- }
324
- const raw = info.name ?? path.basename(hint);
325
- const name = raw
326
- .toLowerCase()
327
- .replace(/^@[^/]+\//, "")
328
- .replace(/[^a-z0-9._-]+/g, "-")
329
- .replace(/^[^a-z0-9]+/, "")
330
- .replace(/-+$/, "");
331
- if (!PLUGIN_NAME.test(name)) throw new Error(`cannot derive a directory name from ${JSON.stringify(raw)}; pass --name`);
332
- return name;
333
- }
334
-
335
- async function makeRoom(target: string, name: string, force?: boolean) {
336
- if (!(await lstat(target).catch(() => undefined))) return;
337
- if (!force) throw new Error(`plugin ${name} is already installed (${target}); use jade plugin update, or --force to replace it`);
338
- await removeDir(target);
339
- }
340
-
341
- /** 链接(包括 Windows 的 junction)只删链接本身,不碰它指向的目录 */
342
- async function removeDir(p: string) {
343
- const info = await lstat(p);
344
- if (info.isSymbolicLink()) {
345
- await unlink(p).catch(() => rmdir(p));
346
- return;
347
- }
348
- await rm(p, { recursive: true, force: true });
349
- }
350
-
351
- const now = () => new Date().toISOString();
352
-
353
- interface PackageManager {
354
- cmd: string;
355
- /** 放在子命令前面的参数(npm 的 CLI 脚本路径) */
356
- prefix: string[];
357
- add(spec: string): string[];
358
- install: string[];
359
- }
360
-
361
- /** 跑在 Bun 下用 bun 自己;跑在 Node 下用 npm(Windows 上的 npm.cmd 不能直接执行,用 node 运行 npm 的 CLI 脚本) */
362
- function packageManager(): PackageManager {
363
- if (process.versions.bun) {
364
- return { cmd: process.execPath, prefix: [], add: (spec) => ["add", "--ignore-scripts", spec], install: ["install", "--production"] };
365
- }
366
- const npm = npmCommand();
367
- if (!npm) throw new Error("npm was not found; it is needed to install plugins from npm or plugins with dependencies");
368
- const quiet = ["--ignore-scripts", "--no-audit", "--no-fund", "--loglevel=error"];
369
- return { cmd: npm[0]!, prefix: npm.slice(1), add: (spec) => ["install", ...quiet, spec], install: ["install", "--omit=dev", ...quiet] };
370
- }
371
-
372
- function run(cmd: string, args: string[], cwd: string): Promise<string> {
373
- return new Promise((resolve, reject) => {
374
- execFile(cmd, args, { cwd, windowsHide: true, maxBuffer: 16 * 1024 * 1024, env: { ...process.env, GIT_TERMINAL_PROMPT: "0" } }, (err, stdout, stderr) => {
375
- if (err) {
376
- const detail = `${stderr || stdout}`.trim().split(/\r?\n/).slice(-6).join("\n");
377
- const missing = (err as NodeJS.ErrnoException).code === "ENOENT";
378
- const name = args[0]?.endsWith(".js") ? `npm ${args[1]}` : `${path.basename(cmd)} ${args[0]}`;
379
- reject(new Error(missing ? `${cmd} is not installed or not on PATH` : `${name} failed${detail ? `:\n${detail}` : ""}`));
380
- } else resolve(stdout);
381
- });
382
- });
383
- }
384
-
385
- // ---------- 启用、停用 ----------
386
-
387
- /** $JADE_HOME/plugins.json:只有用户层能停用插件,仓库不能停用用户的插件或内置插件 */
388
- export interface PluginSettings {
389
- /** 停用的插件:内置插件的 id(jade/web),或者插件的目录名 */
390
- disabled: string[];
391
- }
392
-
393
- export async function readPluginSettings(home: string): Promise<PluginSettings> {
394
- try {
395
- const json = JSON.parse(await readFile(path.join(home, "plugins.json"), "utf8"));
396
- const disabled = Array.isArray(json?.disabled) ? json.disabled.filter((x: unknown): x is string => typeof x === "string") : [];
397
- return { disabled };
398
- } catch {
399
- return { disabled: [] };
400
- }
401
- }
402
-
403
- export async function setDisabled(home: string, name: string, disabled: boolean): Promise<boolean> {
404
- const s = await readPluginSettings(home);
405
- const has = s.disabled.includes(name);
406
- if (has === disabled) return false;
407
- const next = disabled ? [...s.disabled, name].sort() : s.disabled.filter((x) => x !== name);
408
- await mkdir(home, { recursive: true });
409
- let json: Record<string, unknown> = {};
410
- try {
411
- json = JSON.parse(await readFile(path.join(home, "plugins.json"), "utf8"));
412
- } catch {
413
- // 不存在或格式不对时重写
414
- }
415
- await writeFile(path.join(home, "plugins.json"), `${JSON.stringify({ ...json, disabled: next }, null, 2)}\n`);
416
- return true;
417
- }
418
-
419
- /** 插件目录里的子目录名(不含 . 开头的临时目录) */
420
- export async function installedNames(pluginsDir: string): Promise<string[]> {
421
- try {
422
- const names = (await readdir(pluginsDir)).filter((n) => !n.startsWith("."));
423
- const out: string[] = [];
424
- for (const n of names.sort()) if ((await stat(path.join(pluginsDir, n)).catch(() => undefined))?.isDirectory()) out.push(n);
425
- return out;
426
- } catch {
427
- return [];
428
- }
429
- }