@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
package/src/update.ts CHANGED
@@ -1,262 +1,265 @@
1
- // 新版本提示和 jade update:查 npm 上的最新版本,按 jade 的安装方式(npm 或 bun 全局安装)升级。
2
- // 启动时的检查每天最多一次,结果缓存在 $JADE_HOME/update-check.json,查不到时什么也不说
3
-
4
- import { spawn } from "node:child_process";
5
- import { closeSync, openSync, realpathSync } from "node:fs";
6
- import { mkdir, open, readFile, rm, stat, writeFile } from "node:fs/promises";
7
- import path from "node:path";
8
- import { fileURLToPath } from "node:url";
9
- import { npmCommand, VERSION, which } from "./sys.ts";
10
-
11
- export const PACKAGE = "@uncarved/jade";
12
- const LATEST_URL = `https://registry.npmjs.org/${PACKAGE}/latest`;
13
- const CHECK_EVERY_MS = 24 * 60 * 60 * 1000;
14
- const TIMEOUT_MS = 5000;
15
- /** 后台升级最多跑这么久;锁文件比这更旧就当作上次升级的进程已经不在了 */
16
- const INSTALL_TIMEOUT_MS = 10 * 60 * 1000;
17
- /** 同一个版本升级失败后,隔这么久才再自动试 */
18
- const RETRY_FAILED_MS = 24 * 60 * 60 * 1000;
19
-
20
- /** 比较 x.y.z 版本号:a 比 b 新时为 true。带预发布后缀的只比主版本号,主版本号相同时正式版算更新 */
21
- export function isNewer(a: string, b: string): boolean {
22
- const parse = (v: string) => {
23
- const [core, pre] = v.trim().replace(/^v/, "").split("-", 2);
24
- return { parts: core!.split(".").map((n) => Number.parseInt(n, 10) || 0), pre: pre !== undefined };
25
- };
26
- const x = parse(a);
27
- const y = parse(b);
28
- for (let i = 0; i < 3; i++) {
29
- const d = (x.parts[i] ?? 0) - (y.parts[i] ?? 0);
30
- if (d) return d > 0;
31
- }
32
- return !x.pre && y.pre;
33
- }
34
-
35
- /** 从 npm registry 读最新版本号;网络不通、超时或返回不对时 reject */
36
- export async function fetchLatest(signal?: AbortSignal): Promise<string> {
37
- const res = await fetch(LATEST_URL, {
38
- headers: { accept: "application/json" },
39
- signal: signal ? AbortSignal.any([signal, AbortSignal.timeout(TIMEOUT_MS)]) : AbortSignal.timeout(TIMEOUT_MS),
40
- });
41
- if (!res.ok) throw new Error(`npm registry answered ${res.status}`);
42
- const { version } = (await res.json()) as { version?: unknown };
43
- if (typeof version !== "string" || !/^\d+\.\d+\.\d+/.test(version)) throw new Error("npm registry gave no version");
44
- return version;
45
- }
46
-
47
- interface CheckCache {
48
- checkedAt: number;
49
- latest: string;
50
- }
51
-
52
- /**
53
- * 启动时用:有比当前更新的版本时返回它的版本号。距上次查询不到一天时用缓存,不发请求;
54
- * JADE_UPDATE_CHECK=off 时不查。任何错误都当作没有新版本
55
- */
56
- export async function newerVersion(home: string, opts: { now?: number; current?: string; latest?: () => Promise<string> } = {}): Promise<string | undefined> {
57
- if (/^(0|off|false|no)$/i.test(process.env.JADE_UPDATE_CHECK?.trim() ?? "")) return undefined;
58
- const now = opts.now ?? Date.now();
59
- const current = opts.current ?? VERSION;
60
- const file = path.join(home, "update-check.json");
61
- let cache: CheckCache | undefined;
62
- try {
63
- const c = JSON.parse(await readFile(file, "utf8")) as Partial<CheckCache>;
64
- if (typeof c.checkedAt === "number" && typeof c.latest === "string") cache = c as CheckCache;
65
- } catch {}
66
- if (!cache || now - cache.checkedAt >= CHECK_EVERY_MS || now < cache.checkedAt) {
67
- try {
68
- cache = { checkedAt: now, latest: await (opts.latest ?? fetchLatest)() };
69
- } catch {
70
- return undefined;
71
- }
72
- await mkdir(home, { recursive: true })
73
- .then(() => writeFile(file, JSON.stringify(cache) + "\n"))
74
- .catch(() => {});
75
- }
76
- return isNewer(cache.latest, current) ? cache.latest : undefined;
77
- }
78
-
79
- export type Install = { kind: "npm" | "bun" | "pnpm" | "yarn"; dir: string } | { kind: "dev"; dir: string };
80
-
81
- /**
82
- * 看 jade 的包目录(解析符号链接后)在哪:不在 node_modules 里就是仓库里的开发版或 npm link;
83
- * 在 bun、pnpm、yarn 的全局目录里按对应工具算,其余按 npm 算
84
- */
85
- export function detectInstall(dir: string = packageDir()): Install {
86
- const p = dir.replace(/\\/g, "/");
87
- if (!/\/node_modules\//.test(p)) return { kind: "dev", dir };
88
- if (/\/\.bun\/install\/global\//.test(p)) return { kind: "bun", dir };
89
- if (/\/pnpm\/|\/\.pnpm\//.test(p)) return { kind: "pnpm", dir };
90
- if (/\/yarn\/global\//i.test(p)) return { kind: "yarn", dir };
91
- return { kind: "npm", dir };
92
- }
93
-
94
- /** jade 的包根目录:src/update.ts 和 dist/update.js 都在它下面一层 */
95
- function packageDir(): string {
96
- const dir = fileURLToPath(new URL("..", import.meta.url));
97
- try {
98
- return realpathSync.native(dir);
99
- } catch {
100
- return path.resolve(dir);
101
- }
102
- }
103
-
104
- /** 给用户看的升级命令 */
105
- export function upgradeHint(kind: Install["kind"] = detectInstall().kind): string {
106
- const spec = `${PACKAGE}@latest`;
107
- if (kind === "bun") return `bun add -g ${spec}`;
108
- if (kind === "pnpm") return `pnpm add -g ${spec}`;
109
- if (kind === "yarn") return `yarn global add ${spec}`;
110
- return `npm install -g ${spec}`;
111
- }
112
-
113
- /** 实际执行的升级命令;找不到对应的程序时为 undefined */
114
- function upgradeCommand(kind: Install["kind"]): string[] | undefined {
115
- const spec = `${PACKAGE}@latest`;
116
- if (kind === "npm") {
117
- const npm = npmCommand();
118
- return npm && [...npm, "install", "-g", spec];
119
- }
120
- const bin = which(process.platform === "win32" && kind !== "bun" ? `${kind}.cmd` : kind);
121
- if (!bin) return undefined;
122
- if (kind === "bun") return [bin, "add", "-g", spec];
123
- if (kind === "pnpm") return [bin, "add", "-g", spec];
124
- return [bin, "global", "add", spec];
125
- }
126
-
127
- /** jade update:返回退出码。输出直接写到终端,安装命令的输出也直接显示 */
128
- export async function updateCli(args: string[]): Promise<number> {
129
- if (args.includes("-h") || args.includes("--help")) {
130
- console.log(`Usage: jade update [--check]\n\n Upgrade jade to the latest version on npm.\n --check only report whether a newer version exists`);
131
- return 0;
132
- }
133
- const unknown = args.find((a) => a !== "--check");
134
- if (unknown) {
135
- console.error(`jade update: unknown option ${unknown}`);
136
- return 2;
137
- }
138
- let latest: string;
139
- try {
140
- latest = await fetchLatest();
141
- } catch (err) {
142
- console.error(`jade update: could not reach the npm registry: ${err instanceof Error ? err.message : String(err)}`);
143
- return 1;
144
- }
145
- if (!isNewer(latest, VERSION)) {
146
- console.log(`jade ${VERSION} is up to date${latest !== VERSION ? ` (npm has ${latest})` : ""}.`);
147
- return 0;
148
- }
149
- const install = detectInstall();
150
- if (args.includes("--check")) {
151
- console.log(`jade ${latest} is available (you have ${VERSION}). Run: ${install.kind === "dev" ? upgradeHint("npm") : upgradeHint(install.kind)}`);
152
- return 0;
153
- }
154
- if (install.kind === "dev") {
155
- console.error(`jade update: this jade runs from ${install.dir}, not from a global install (a checkout or npm link); update it with git, or install the package with: ${upgradeHint("npm")}`);
156
- return 1;
157
- }
158
- const cmd = upgradeCommand(install.kind);
159
- if (!cmd) {
160
- console.error(`jade update: ${install.kind} was not found; run: ${upgradeHint(install.kind)}`);
161
- return 1;
162
- }
163
- console.log(`Updating jade ${VERSION} → ${latest} with ${install.kind}…`);
164
- const code = await new Promise<number | null>((resolve) => {
165
- const child = spawn(cmd[0]!, cmd.slice(1), { stdio: "inherit" });
166
- child.on("error", () => resolve(-1));
167
- child.on("exit", (c) => resolve(c));
168
- });
169
- if (code !== 0) {
170
- console.error(`jade update: ${install.kind} failed${code === -1 ? " to start" : ` (exit ${code})`}. Run it yourself: ${upgradeHint(install.kind)}`);
171
- return 1;
172
- }
173
- console.log(`jade ${latest} is installed.`);
174
- return 0;
175
- }
176
-
177
- const off = (v: string | undefined) => /^(0|off|false|no)$/i.test(v?.trim() ?? "");
178
-
179
- /** 自动升级是否打开:JADE_AUTO_UPDATE=off 关闭;JADE_UPDATE_CHECK=off 时连检查都不做 */
180
- export function autoUpdateEnabled(): boolean {
181
- return !off(process.env.JADE_AUTO_UPDATE) && !off(process.env.JADE_UPDATE_CHECK);
182
- }
183
-
184
- export type AutoUpdateResult =
185
- /** 装好了,下次启动生效 */
186
- | { status: "installed" }
187
- /** 别的 jade 正在升级,或者这个版本不久前刚失败过:这次不试 */
188
- | { status: "skipped"; why: "busy" | "failed-recently" | "unsupported" }
189
- | { status: "failed"; log: string };
190
-
191
- interface Attempt {
192
- version: string;
193
- at: number;
194
- ok: boolean;
195
- }
196
-
197
- /**
198
- * 在后台把 jade 升级到 latest。安装进程和 jade 脱离:jade 先退出时它照常装完,不会留下装了一半的包。
199
- * 多个 jade 同时启动时用 $JADE_HOME/update.lock 保证只有一个在装;输出写进 $JADE_HOME/update.log
200
- */
201
- export async function autoUpdate(home: string, latest: string, opts: { install?: Install; command?: string[] } = {}): Promise<AutoUpdateResult> {
202
- const install = opts.install ?? detectInstall();
203
- if (install.kind === "dev") return { status: "skipped", why: "unsupported" };
204
- const cmd = opts.command ?? upgradeCommand(install.kind);
205
- if (!cmd) return { status: "skipped", why: "unsupported" };
206
-
207
- const attemptFile = path.join(home, "update-attempt.json");
208
- const last = await readFile(attemptFile, "utf8")
209
- .then((t) => JSON.parse(t) as Attempt)
210
- .catch(() => undefined);
211
- if (last && !last.ok && last.version === latest && Date.now() - last.at < RETRY_FAILED_MS) return { status: "skipped", why: "failed-recently" };
212
-
213
- await mkdir(home, { recursive: true });
214
- const lock = path.join(home, "update.lock");
215
- if (!(await takeLock(lock))) return { status: "skipped", why: "busy" };
216
-
217
- const log = path.join(home, "update.log");
218
- let ok = false;
219
- try {
220
- const fd = openSync(log, "w");
221
- try {
222
- ok = await new Promise<boolean>((resolve) => {
223
- const child = spawn(cmd[0]!, cmd.slice(1), { stdio: ["ignore", fd, fd], detached: true, windowsHide: true });
224
- const timer = setTimeout(() => resolve(false), INSTALL_TIMEOUT_MS);
225
- timer.unref();
226
- child.on("error", () => resolve(false));
227
- child.on("exit", (code) => {
228
- clearTimeout(timer);
229
- resolve(code === 0);
230
- });
231
- // jade 退出时不等它,它自己装完
232
- child.unref();
233
- });
234
- } finally {
235
- closeSync(fd);
236
- }
237
- } catch {
238
- ok = false;
239
- } finally {
240
- await rm(lock, { force: true }).catch(() => {});
241
- }
242
- await writeFile(attemptFile, JSON.stringify({ version: latest, at: Date.now(), ok } satisfies Attempt) + "\n").catch(() => {});
243
- return ok ? { status: "installed" } : { status: "failed", log };
244
- }
245
-
246
- /** 新建锁文件;已经有了且不算太旧时返回 false,太旧的(上次的进程不在了)删掉重来 */
247
- async function takeLock(lock: string): Promise<boolean> {
248
- for (let i = 0; i < 2; i++) {
249
- try {
250
- const h = await open(lock, "wx");
251
- await h.writeFile(String(process.pid));
252
- await h.close();
253
- return true;
254
- } catch (err) {
255
- if ((err as NodeJS.ErrnoException).code !== "EEXIST") return false;
256
- const age = await stat(lock).then((s) => Date.now() - s.mtimeMs, () => 0);
257
- if (age < INSTALL_TIMEOUT_MS) return false;
258
- await rm(lock, { force: true }).catch(() => {});
259
- }
260
- }
261
- return false;
262
- }
1
+ // jade 本身的升级:查 npm 上的最新版本,按 jade 的安装方式(npm、bun、pnpm、yarn 全局安装)升级。
2
+ // jade update 直接用这里(核心命令,插件坏了也能升级);启动时的检查和后台升级在 jade/update 插件里,也用这里。
3
+ // 启动时的检查每天最多一次,结果缓存在 $JADE_HOME/update-check.json,查不到时什么也不说
4
+
5
+ import { spawn } from "node:child_process";
6
+ import { closeSync, openSync, readFileSync, realpathSync } from "node:fs";
7
+ import { mkdir, open, readFile, rm, stat, writeFile } from "node:fs/promises";
8
+ import path from "node:path";
9
+ import { fileURLToPath } from "node:url";
10
+ import { npmCommand, which } from "./fetch.ts";
11
+
12
+ export const PACKAGE = "@uncarved/jade";
13
+ /** 正在运行的 jade 的版本 */
14
+ export const VERSION: string = JSON.parse(readFileSync(path.join(packageDir(), "package.json"), "utf8")).version;
15
+ const LATEST_URL = `https://registry.npmjs.org/${PACKAGE}/latest`;
16
+ const CHECK_EVERY_MS = 24 * 60 * 60 * 1000;
17
+ const TIMEOUT_MS = 5000;
18
+ /** 后台升级最多跑这么久;锁文件比这更旧就当作上次升级的进程已经不在了 */
19
+ const INSTALL_TIMEOUT_MS = 10 * 60 * 1000;
20
+ /** 同一个版本升级失败后,隔这么久才再自动试 */
21
+ const RETRY_FAILED_MS = 24 * 60 * 60 * 1000;
22
+
23
+ /** 比较 x.y.z 版本号:a 比 b 新时为 true。带预发布后缀的只比主版本号,主版本号相同时正式版算更新 */
24
+ export function isNewer(a: string, b: string): boolean {
25
+ const parse = (v: string) => {
26
+ const [core, pre] = v.trim().replace(/^v/, "").split("-", 2);
27
+ return { parts: core!.split(".").map((n) => Number.parseInt(n, 10) || 0), pre: pre !== undefined };
28
+ };
29
+ const x = parse(a);
30
+ const y = parse(b);
31
+ for (let i = 0; i < 3; i++) {
32
+ const d = (x.parts[i] ?? 0) - (y.parts[i] ?? 0);
33
+ if (d) return d > 0;
34
+ }
35
+ return !x.pre && y.pre;
36
+ }
37
+
38
+ /** 从 npm registry 读最新版本号;网络不通、超时或返回不对时 reject */
39
+ export async function fetchLatest(signal?: AbortSignal): Promise<string> {
40
+ const res = await fetch(LATEST_URL, {
41
+ headers: { accept: "application/json" },
42
+ signal: signal ? AbortSignal.any([signal, AbortSignal.timeout(TIMEOUT_MS)]) : AbortSignal.timeout(TIMEOUT_MS),
43
+ });
44
+ if (!res.ok) throw new Error(`npm registry answered ${res.status}`);
45
+ const { version } = (await res.json()) as { version?: unknown };
46
+ if (typeof version !== "string" || !/^\d+\.\d+\.\d+/.test(version)) throw new Error("npm registry gave no version");
47
+ return version;
48
+ }
49
+
50
+ interface CheckCache {
51
+ checkedAt: number;
52
+ latest: string;
53
+ }
54
+
55
+ /**
56
+ * 启动时用:有比当前更新的版本时返回它的版本号。距上次查询不到一天时用缓存,不发请求;
57
+ * JADE_UPDATE_CHECK=off 时不查。任何错误都当作没有新版本
58
+ */
59
+ export async function newerVersion(home: string, opts: { now?: number; current?: string; latest?: () => Promise<string> } = {}): Promise<string | undefined> {
60
+ if (/^(0|off|false|no)$/i.test(process.env.JADE_UPDATE_CHECK?.trim() ?? "")) return undefined;
61
+ const now = opts.now ?? Date.now();
62
+ const current = opts.current ?? VERSION;
63
+ const file = path.join(home, "update-check.json");
64
+ let cache: CheckCache | undefined;
65
+ try {
66
+ const c = JSON.parse(await readFile(file, "utf8")) as Partial<CheckCache>;
67
+ if (typeof c.checkedAt === "number" && typeof c.latest === "string") cache = c as CheckCache;
68
+ } catch {}
69
+ if (!cache || now - cache.checkedAt >= CHECK_EVERY_MS || now < cache.checkedAt) {
70
+ try {
71
+ cache = { checkedAt: now, latest: await (opts.latest ?? fetchLatest)() };
72
+ } catch {
73
+ return undefined;
74
+ }
75
+ await mkdir(home, { recursive: true })
76
+ .then(() => writeFile(file, JSON.stringify(cache) + "\n"))
77
+ .catch(() => {});
78
+ }
79
+ return isNewer(cache.latest, current) ? cache.latest : undefined;
80
+ }
81
+
82
+ export type Install = { kind: "npm" | "bun" | "pnpm" | "yarn"; dir: string } | { kind: "dev"; dir: string };
83
+
84
+ /**
85
+ * 看 jade 的包目录(解析符号链接后)在哪:不在 node_modules 里就是仓库里的开发版或 npm link;
86
+ * 在 bun、pnpm、yarn 的全局目录里按对应工具算,其余按 npm 算
87
+ */
88
+ export function detectInstall(dir: string = packageDir()): Install {
89
+ const p = dir.replace(/\\/g, "/");
90
+ if (!/\/node_modules\//.test(p)) return { kind: "dev", dir };
91
+ if (/\/\.bun\/install\/global\//.test(p)) return { kind: "bun", dir };
92
+ if (/\/pnpm\/|\/\.pnpm\//.test(p)) return { kind: "pnpm", dir };
93
+ if (/\/yarn\/global\//i.test(p)) return { kind: "yarn", dir };
94
+ return { kind: "npm", dir };
95
+ }
96
+
97
+ /** jade 的包根目录:src/update.ts 和 dist/update.js 都在它下面一层 */
98
+ function packageDir(): string {
99
+ const dir = fileURLToPath(new URL("..", import.meta.url));
100
+ try {
101
+ return realpathSync.native(dir);
102
+ } catch {
103
+ return path.resolve(dir);
104
+ }
105
+ }
106
+
107
+ /** 给用户看的升级命令 */
108
+ export function upgradeHint(kind: Install["kind"] = detectInstall().kind): string {
109
+ const spec = `${PACKAGE}@latest`;
110
+ if (kind === "bun") return `bun add -g ${spec}`;
111
+ if (kind === "pnpm") return `pnpm add -g ${spec}`;
112
+ if (kind === "yarn") return `yarn global add ${spec}`;
113
+ return `npm install -g ${spec}`;
114
+ }
115
+
116
+ /** 实际执行的升级命令;找不到对应的程序时为 undefined */
117
+ function upgradeCommand(kind: Install["kind"]): string[] | undefined {
118
+ const spec = `${PACKAGE}@latest`;
119
+ if (kind === "npm") {
120
+ const npm = npmCommand();
121
+ return npm && [...npm, "install", "-g", spec];
122
+ }
123
+ const bin = which(process.platform === "win32" && kind !== "bun" ? `${kind}.cmd` : kind);
124
+ if (!bin) return undefined;
125
+ if (kind === "bun") return [bin, "add", "-g", spec];
126
+ if (kind === "pnpm") return [bin, "add", "-g", spec];
127
+ return [bin, "global", "add", spec];
128
+ }
129
+
130
+ /** jade update:返回退出码。输出直接写到终端,安装命令的输出也直接显示 */
131
+ export async function updateCli(args: string[]): Promise<number> {
132
+ if (args.includes("-h") || args.includes("--help")) {
133
+ console.log(`Usage: jade update [--check]\n\n Upgrade jade to the latest version on npm.\n --check only report whether a newer version exists`);
134
+ return 0;
135
+ }
136
+ const unknown = args.find((a) => a !== "--check");
137
+ if (unknown) {
138
+ console.error(`jade update: unknown option ${unknown}`);
139
+ return 2;
140
+ }
141
+ let latest: string;
142
+ try {
143
+ latest = await fetchLatest();
144
+ } catch (err) {
145
+ console.error(`jade update: could not reach the npm registry: ${err instanceof Error ? err.message : String(err)}`);
146
+ return 1;
147
+ }
148
+ if (!isNewer(latest, VERSION)) {
149
+ console.log(`jade ${VERSION} is up to date${latest !== VERSION ? ` (npm has ${latest})` : ""}.`);
150
+ return 0;
151
+ }
152
+ const install = detectInstall();
153
+ if (args.includes("--check")) {
154
+ console.log(`jade ${latest} is available (you have ${VERSION}). Run: ${install.kind === "dev" ? upgradeHint("npm") : upgradeHint(install.kind)}`);
155
+ return 0;
156
+ }
157
+ if (install.kind === "dev") {
158
+ console.error(`jade update: this jade runs from ${install.dir}, not from a global install (a checkout or npm link); update it with git, or install the package with: ${upgradeHint("npm")}`);
159
+ return 1;
160
+ }
161
+ const cmd = upgradeCommand(install.kind);
162
+ if (!cmd) {
163
+ console.error(`jade update: ${install.kind} was not found; run: ${upgradeHint(install.kind)}`);
164
+ return 1;
165
+ }
166
+ console.log(`Updating jade ${VERSION} → ${latest} with ${install.kind}…`);
167
+ const code = await new Promise<number | null>((resolve) => {
168
+ const child = spawn(cmd[0]!, cmd.slice(1), { stdio: "inherit" });
169
+ child.on("error", () => resolve(-1));
170
+ child.on("exit", (c) => resolve(c));
171
+ });
172
+ if (code !== 0) {
173
+ console.error(`jade update: ${install.kind} failed${code === -1 ? " to start" : ` (exit ${code})`}. Run it yourself: ${upgradeHint(install.kind)}`);
174
+ return 1;
175
+ }
176
+ console.log(`jade ${latest} is installed.`);
177
+ return 0;
178
+ }
179
+
180
+ const off = (v: string | undefined) => /^(0|off|false|no)$/i.test(v?.trim() ?? "");
181
+
182
+ /** 自动升级是否打开:JADE_AUTO_UPDATE=off 关闭;JADE_UPDATE_CHECK=off 时连检查都不做 */
183
+ export function autoUpdateEnabled(): boolean {
184
+ return !off(process.env.JADE_AUTO_UPDATE) && !off(process.env.JADE_UPDATE_CHECK);
185
+ }
186
+
187
+ export type AutoUpdateResult =
188
+ /** 装好了,下次启动生效 */
189
+ | { status: "installed" }
190
+ /** 别的 jade 正在升级,或者这个版本不久前刚失败过:这次不试 */
191
+ | { status: "skipped"; why: "busy" | "failed-recently" | "unsupported" }
192
+ | { status: "failed"; log: string };
193
+
194
+ interface Attempt {
195
+ version: string;
196
+ at: number;
197
+ ok: boolean;
198
+ }
199
+
200
+ /**
201
+ * 在后台把 jade 升级到 latest。安装进程和 jade 脱离:jade 先退出时它照常装完,不会留下装了一半的包。
202
+ * 多个 jade 同时启动时用 $JADE_HOME/update.lock 保证只有一个在装;输出写进 $JADE_HOME/update.log
203
+ */
204
+ export async function autoUpdate(home: string, latest: string, opts: { install?: Install; command?: string[] } = {}): Promise<AutoUpdateResult> {
205
+ const install = opts.install ?? detectInstall();
206
+ if (install.kind === "dev") return { status: "skipped", why: "unsupported" };
207
+ const cmd = opts.command ?? upgradeCommand(install.kind);
208
+ if (!cmd) return { status: "skipped", why: "unsupported" };
209
+
210
+ const attemptFile = path.join(home, "update-attempt.json");
211
+ const last = await readFile(attemptFile, "utf8")
212
+ .then((t) => JSON.parse(t) as Attempt)
213
+ .catch(() => undefined);
214
+ if (last && !last.ok && last.version === latest && Date.now() - last.at < RETRY_FAILED_MS) return { status: "skipped", why: "failed-recently" };
215
+
216
+ await mkdir(home, { recursive: true });
217
+ const lock = path.join(home, "update.lock");
218
+ if (!(await takeLock(lock))) return { status: "skipped", why: "busy" };
219
+
220
+ const log = path.join(home, "update.log");
221
+ let ok = false;
222
+ try {
223
+ const fd = openSync(log, "w");
224
+ try {
225
+ ok = await new Promise<boolean>((resolve) => {
226
+ const child = spawn(cmd[0]!, cmd.slice(1), { stdio: ["ignore", fd, fd], detached: true, windowsHide: true });
227
+ const timer = setTimeout(() => resolve(false), INSTALL_TIMEOUT_MS);
228
+ timer.unref();
229
+ child.on("error", () => resolve(false));
230
+ child.on("exit", (code) => {
231
+ clearTimeout(timer);
232
+ resolve(code === 0);
233
+ });
234
+ // jade 退出时不等它,它自己装完
235
+ child.unref();
236
+ });
237
+ } finally {
238
+ closeSync(fd);
239
+ }
240
+ } catch {
241
+ ok = false;
242
+ } finally {
243
+ await rm(lock, { force: true }).catch(() => {});
244
+ }
245
+ await writeFile(attemptFile, JSON.stringify({ version: latest, at: Date.now(), ok } satisfies Attempt) + "\n").catch(() => {});
246
+ return ok ? { status: "installed" } : { status: "failed", log };
247
+ }
248
+
249
+ /** 新建锁文件;已经有了且不算太旧时返回 false,太旧的(上次的进程不在了)删掉重来 */
250
+ async function takeLock(lock: string): Promise<boolean> {
251
+ for (let i = 0; i < 2; i++) {
252
+ try {
253
+ const h = await open(lock, "wx");
254
+ await h.writeFile(String(process.pid));
255
+ await h.close();
256
+ return true;
257
+ } catch (err) {
258
+ if ((err as NodeJS.ErrnoException).code !== "EEXIST") return false;
259
+ const age = await stat(lock).then((s) => Date.now() - s.mtimeMs, () => 0);
260
+ if (age < INSTALL_TIMEOUT_MS) return false;
261
+ await rm(lock, { force: true }).catch(() => {});
262
+ }
263
+ }
264
+ return false;
265
+ }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 MochiNek0
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
@@ -1,50 +0,0 @@
1
- import type { Jade } from "./distro.ts";
2
- import type { CommandInfo } from "./ui/screen.ts";
3
- export interface CustomCommand {
4
- name: string;
5
- description: string;
6
- /** 参数提示,显示在菜单里 */
7
- args?: string;
8
- body: string;
9
- /** 文件的绝对路径 */
10
- file: string;
11
- layer: "user" | "project";
12
- /** 来自哪个插件 */
13
- plugin?: string;
14
- }
15
- /** 解析一个命令文件 */
16
- export declare function parseCommand(name: string, text: string, file: string, layer: CustomCommand["layer"]): CustomCommand;
17
- /** 把参数填进命令正文,得到要发给模型的消息 */
18
- export declare function expandCommand(cmd: Pick<CustomCommand, "body">, args: string): string;
19
- /** 读取用户层和项目层的命令;root 是仓库根目录(不在仓库里时等于 cwd) */
20
- export declare function loadCommands(opts: {
21
- home: string;
22
- root: string;
23
- cwd: string;
24
- /** 插件带的 commands 目录,优先级低于同一层的 commands 目录 */
25
- plugins?: {
26
- plugin: string;
27
- dir: string;
28
- layer: CustomCommand["layer"];
29
- }[];
30
- }): Promise<CustomCommand[]>;
31
- /** 从仓库根目录到工作目录的每一级目录,远的在前;工作目录不在仓库里时只有工作目录 */
32
- export declare function projectDirs(root: string, cwd: string): string[];
33
- /**
34
- * 斜杠命令同名时谁生效:宿主命令 > 内置插件的命令 > 自定义命令和 skill > 第三方插件(第三方之间先到先得)。
35
- * 内置插件和第三方插件之间的先后由 createJade 定(jade.commands 里内置插件优先;内置插件被代替或停用时,第三方插件可以用它的命令名);
36
- * 这里再让第三方插件给宿主命令、自定义命令和 skill 让位。返回菜单里内置插件的和第三方插件的命令,以及被忽略的命令的警告
37
- */
38
- export declare function pluginMenu(commands: Jade["commands"], taken: {
39
- host: Set<string>;
40
- custom: {
41
- has(name: string): boolean;
42
- };
43
- skill: {
44
- has(name: string): boolean;
45
- };
46
- }): {
47
- builtin: CommandInfo[];
48
- plugins: CommandInfo[];
49
- warnings: string[];
50
- };