@eminent337/aery 0.1.63 → 0.1.65

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 (626) hide show
  1. package/docs/custom-provider.md +1 -1
  2. package/docs/extensions.md +18 -18
  3. package/docs/index.md +5 -5
  4. package/docs/json.md +1 -1
  5. package/docs/keybindings.md +2 -2
  6. package/docs/models.md +2 -2
  7. package/docs/packages.md +13 -13
  8. package/docs/providers.md +5 -5
  9. package/docs/quickstart.md +19 -19
  10. package/docs/rpc.md +3 -3
  11. package/docs/sdk.md +1 -1
  12. package/docs/session-format.md +3 -3
  13. package/docs/sessions.md +10 -10
  14. package/docs/settings.md +4 -4
  15. package/docs/skills.md +2 -2
  16. package/docs/terminal-setup.md +6 -6
  17. package/docs/termux.md +3 -3
  18. package/docs/themes.md +3 -3
  19. package/docs/tmux.md +1 -1
  20. package/docs/tui.md +2 -2
  21. package/docs/usage.md +33 -33
  22. package/examples/extensions/README.md +3 -3
  23. package/examples/extensions/antigravity-image-gen.ts +6 -6
  24. package/examples/extensions/auto-commit-on-exit.ts +1 -1
  25. package/examples/extensions/bash-spawn-hook.ts +1 -1
  26. package/examples/extensions/built-in-tool-renderer.ts +1 -1
  27. package/examples/extensions/claude-rules.ts +1 -1
  28. package/examples/extensions/commands.ts +1 -1
  29. package/examples/extensions/custom-compaction.ts +1 -1
  30. package/examples/extensions/custom-header.ts +2 -2
  31. package/examples/extensions/custom-provider-anthropic/index.ts +2 -2
  32. package/examples/extensions/custom-provider-gitlab-duo/index.ts +2 -2
  33. package/examples/extensions/custom-provider-qwen-cli/index.ts +1 -1
  34. package/examples/extensions/doom-overlay/README.md +2 -2
  35. package/examples/extensions/doom-overlay/doom/build.sh +2 -2
  36. package/examples/extensions/doom-overlay/index.ts +1 -1
  37. package/examples/extensions/hidden-thinking-label.ts +1 -1
  38. package/examples/extensions/inline-bash.ts +2 -2
  39. package/examples/extensions/input-transform.ts +3 -3
  40. package/examples/extensions/interactive-shell.ts +1 -1
  41. package/examples/extensions/mac-system-theme.ts +2 -2
  42. package/examples/extensions/minimal-mode.ts +1 -1
  43. package/examples/extensions/modal-editor.ts +1 -1
  44. package/examples/extensions/model-status.ts +1 -1
  45. package/examples/extensions/overlay-qa-tests.ts +1 -1
  46. package/examples/extensions/overlay-test.ts +1 -1
  47. package/examples/extensions/pirate.ts +1 -1
  48. package/examples/extensions/preset.ts +12 -6
  49. package/examples/extensions/prompt-customizer.ts +1 -1
  50. package/examples/extensions/provider-payload.ts +1 -1
  51. package/examples/extensions/rainbow-editor.ts +1 -1
  52. package/examples/extensions/rpc-demo.ts +1 -1
  53. package/examples/extensions/sandbox/index.ts +8 -8
  54. package/examples/extensions/shutdown-command.ts +5 -5
  55. package/examples/extensions/ssh.ts +2 -2
  56. package/examples/extensions/subagent/README.md +13 -13
  57. package/examples/extensions/subagent/agents.ts +1 -1
  58. package/examples/extensions/subagent/index.ts +5 -5
  59. package/examples/extensions/titlebar-spinner.ts +1 -1
  60. package/examples/extensions/tool-override.ts +2 -2
  61. package/examples/extensions/tools.ts +1 -1
  62. package/examples/extensions/truncated-tool.ts +1 -1
  63. package/examples/extensions/working-indicator.ts +4 -4
  64. package/examples/extensions/working-message-test.ts +1 -1
  65. package/examples/sdk/01-minimal.ts +1 -1
  66. package/examples/sdk/03-custom-prompt.ts +1 -1
  67. package/examples/sdk/04-skills.ts +1 -1
  68. package/examples/sdk/06-extensions.ts +2 -2
  69. package/examples/sdk/08-prompt-templates.ts +1 -1
  70. package/examples/sdk/09-api-keys-and-oauth.ts +2 -2
  71. package/examples/sdk/README.md +1 -1
  72. package/package.json +3 -3
  73. package/dist/bun/cli.d.ts +0 -3
  74. package/dist/bun/cli.d.ts.map +0 -1
  75. package/dist/bun/cli.js +0 -8
  76. package/dist/bun/cli.js.map +0 -1
  77. package/dist/bun/register-bedrock.d.ts +0 -2
  78. package/dist/bun/register-bedrock.d.ts.map +0 -1
  79. package/dist/bun/register-bedrock.js +0 -4
  80. package/dist/bun/register-bedrock.js.map +0 -1
  81. package/dist/bun/restore-sandbox-env.d.ts +0 -13
  82. package/dist/bun/restore-sandbox-env.d.ts.map +0 -1
  83. package/dist/bun/restore-sandbox-env.js +0 -32
  84. package/dist/bun/restore-sandbox-env.js.map +0 -1
  85. package/dist/cli/args.d.ts +0 -53
  86. package/dist/cli/args.d.ts.map +0 -1
  87. package/dist/cli/args.js +0 -329
  88. package/dist/cli/args.js.map +0 -1
  89. package/dist/cli/config-selector.d.ts +0 -14
  90. package/dist/cli/config-selector.d.ts.map +0 -1
  91. package/dist/cli/config-selector.js +0 -31
  92. package/dist/cli/config-selector.js.map +0 -1
  93. package/dist/cli/file-processor.d.ts +0 -15
  94. package/dist/cli/file-processor.d.ts.map +0 -1
  95. package/dist/cli/file-processor.js +0 -83
  96. package/dist/cli/file-processor.js.map +0 -1
  97. package/dist/cli/initial-message.d.ts +0 -18
  98. package/dist/cli/initial-message.d.ts.map +0 -1
  99. package/dist/cli/initial-message.js +0 -22
  100. package/dist/cli/initial-message.js.map +0 -1
  101. package/dist/cli/list-models.d.ts +0 -9
  102. package/dist/cli/list-models.d.ts.map +0 -1
  103. package/dist/cli/list-models.js +0 -98
  104. package/dist/cli/list-models.js.map +0 -1
  105. package/dist/cli/session-picker.d.ts +0 -9
  106. package/dist/cli/session-picker.d.ts.map +0 -1
  107. package/dist/cli/session-picker.js +0 -35
  108. package/dist/cli/session-picker.js.map +0 -1
  109. package/dist/cli.d.ts +0 -3
  110. package/dist/cli.d.ts.map +0 -1
  111. package/dist/cli.js +0 -19
  112. package/dist/cli.js.map +0 -1
  113. package/dist/config.d.ts +0 -86
  114. package/dist/config.d.ts.map +0 -1
  115. package/dist/config.js +0 -332
  116. package/dist/config.js.map +0 -1
  117. package/dist/core/agent-session-runtime.d.ts +0 -117
  118. package/dist/core/agent-session-runtime.d.ts.map +0 -1
  119. package/dist/core/agent-session-runtime.js +0 -300
  120. package/dist/core/agent-session-runtime.js.map +0 -1
  121. package/dist/core/agent-session-services.d.ts +0 -86
  122. package/dist/core/agent-session-services.d.ts.map +0 -1
  123. package/dist/core/agent-session-services.js +0 -117
  124. package/dist/core/agent-session-services.js.map +0 -1
  125. package/dist/core/agent-session.d.ts +0 -595
  126. package/dist/core/agent-session.d.ts.map +0 -1
  127. package/dist/core/agent-session.js +0 -2520
  128. package/dist/core/agent-session.js.map +0 -1
  129. package/dist/core/auth-guidance.d.ts +0 -5
  130. package/dist/core/auth-guidance.d.ts.map +0 -1
  131. package/dist/core/auth-guidance.js +0 -21
  132. package/dist/core/auth-guidance.js.map +0 -1
  133. package/dist/core/auth-storage.d.ts +0 -141
  134. package/dist/core/auth-storage.d.ts.map +0 -1
  135. package/dist/core/auth-storage.js +0 -441
  136. package/dist/core/auth-storage.js.map +0 -1
  137. package/dist/core/bash-executor.d.ts +0 -32
  138. package/dist/core/bash-executor.d.ts.map +0 -1
  139. package/dist/core/bash-executor.js +0 -111
  140. package/dist/core/bash-executor.js.map +0 -1
  141. package/dist/core/compaction/branch-summarization.d.ts +0 -88
  142. package/dist/core/compaction/branch-summarization.d.ts.map +0 -1
  143. package/dist/core/compaction/branch-summarization.js +0 -243
  144. package/dist/core/compaction/branch-summarization.js.map +0 -1
  145. package/dist/core/compaction/compaction.d.ts +0 -121
  146. package/dist/core/compaction/compaction.d.ts.map +0 -1
  147. package/dist/core/compaction/compaction.js +0 -615
  148. package/dist/core/compaction/compaction.js.map +0 -1
  149. package/dist/core/compaction/index.d.ts +0 -7
  150. package/dist/core/compaction/index.d.ts.map +0 -1
  151. package/dist/core/compaction/index.js +0 -7
  152. package/dist/core/compaction/index.js.map +0 -1
  153. package/dist/core/compaction/utils.d.ts +0 -38
  154. package/dist/core/compaction/utils.d.ts.map +0 -1
  155. package/dist/core/compaction/utils.js +0 -153
  156. package/dist/core/compaction/utils.js.map +0 -1
  157. package/dist/core/defaults.d.ts +0 -3
  158. package/dist/core/defaults.d.ts.map +0 -1
  159. package/dist/core/defaults.js +0 -2
  160. package/dist/core/defaults.js.map +0 -1
  161. package/dist/core/diagnostics.d.ts +0 -15
  162. package/dist/core/diagnostics.d.ts.map +0 -1
  163. package/dist/core/diagnostics.js +0 -2
  164. package/dist/core/diagnostics.js.map +0 -1
  165. package/dist/core/event-bus.d.ts +0 -9
  166. package/dist/core/event-bus.d.ts.map +0 -1
  167. package/dist/core/event-bus.js +0 -25
  168. package/dist/core/event-bus.js.map +0 -1
  169. package/dist/core/exec.d.ts +0 -29
  170. package/dist/core/exec.d.ts.map +0 -1
  171. package/dist/core/exec.js +0 -75
  172. package/dist/core/exec.js.map +0 -1
  173. package/dist/core/export-html/ansi-to-html.d.ts +0 -22
  174. package/dist/core/export-html/ansi-to-html.d.ts.map +0 -1
  175. package/dist/core/export-html/ansi-to-html.js +0 -249
  176. package/dist/core/export-html/ansi-to-html.js.map +0 -1
  177. package/dist/core/export-html/index.d.ts +0 -37
  178. package/dist/core/export-html/index.d.ts.map +0 -1
  179. package/dist/core/export-html/index.js +0 -224
  180. package/dist/core/export-html/index.js.map +0 -1
  181. package/dist/core/export-html/template.css +0 -1022
  182. package/dist/core/export-html/template.html +0 -55
  183. package/dist/core/export-html/template.js +0 -1770
  184. package/dist/core/export-html/tool-renderer.d.ts +0 -34
  185. package/dist/core/export-html/tool-renderer.d.ts.map +0 -1
  186. package/dist/core/export-html/tool-renderer.js +0 -108
  187. package/dist/core/export-html/tool-renderer.js.map +0 -1
  188. package/dist/core/export-html/vendor/highlight.min.js +0 -1213
  189. package/dist/core/export-html/vendor/marked.min.js +0 -6
  190. package/dist/core/extensions/index.d.ts +0 -12
  191. package/dist/core/extensions/index.d.ts.map +0 -1
  192. package/dist/core/extensions/index.js +0 -9
  193. package/dist/core/extensions/index.js.map +0 -1
  194. package/dist/core/extensions/loader.d.ts +0 -25
  195. package/dist/core/extensions/loader.d.ts.map +0 -1
  196. package/dist/core/extensions/loader.js +0 -476
  197. package/dist/core/extensions/loader.js.map +0 -1
  198. package/dist/core/extensions/runner.d.ts +0 -158
  199. package/dist/core/extensions/runner.d.ts.map +0 -1
  200. package/dist/core/extensions/runner.js +0 -784
  201. package/dist/core/extensions/runner.js.map +0 -1
  202. package/dist/core/extensions/types.d.ts +0 -1153
  203. package/dist/core/extensions/types.d.ts.map +0 -1
  204. package/dist/core/extensions/types.js +0 -45
  205. package/dist/core/extensions/types.js.map +0 -1
  206. package/dist/core/extensions/wrapper.d.ts +0 -20
  207. package/dist/core/extensions/wrapper.d.ts.map +0 -1
  208. package/dist/core/extensions/wrapper.js +0 -22
  209. package/dist/core/extensions/wrapper.js.map +0 -1
  210. package/dist/core/footer-data-provider.d.ts +0 -52
  211. package/dist/core/footer-data-provider.d.ts.map +0 -1
  212. package/dist/core/footer-data-provider.js +0 -310
  213. package/dist/core/footer-data-provider.js.map +0 -1
  214. package/dist/core/index.d.ts +0 -12
  215. package/dist/core/index.d.ts.map +0 -1
  216. package/dist/core/index.js +0 -12
  217. package/dist/core/index.js.map +0 -1
  218. package/dist/core/keybindings.d.ts +0 -353
  219. package/dist/core/keybindings.d.ts.map +0 -1
  220. package/dist/core/keybindings.js +0 -295
  221. package/dist/core/keybindings.js.map +0 -1
  222. package/dist/core/messages.d.ts +0 -77
  223. package/dist/core/messages.d.ts.map +0 -1
  224. package/dist/core/messages.js +0 -123
  225. package/dist/core/messages.js.map +0 -1
  226. package/dist/core/model-registry.d.ts +0 -144
  227. package/dist/core/model-registry.d.ts.map +0 -1
  228. package/dist/core/model-registry.js +0 -699
  229. package/dist/core/model-registry.js.map +0 -1
  230. package/dist/core/model-resolver.d.ts +0 -110
  231. package/dist/core/model-resolver.d.ts.map +0 -1
  232. package/dist/core/model-resolver.js +0 -489
  233. package/dist/core/model-resolver.js.map +0 -1
  234. package/dist/core/output-guard.d.ts +0 -6
  235. package/dist/core/output-guard.d.ts.map +0 -1
  236. package/dist/core/output-guard.js +0 -59
  237. package/dist/core/output-guard.js.map +0 -1
  238. package/dist/core/package-manager.d.ts +0 -199
  239. package/dist/core/package-manager.d.ts.map +0 -1
  240. package/dist/core/package-manager.js +0 -1974
  241. package/dist/core/package-manager.js.map +0 -1
  242. package/dist/core/prompt-templates.d.ts +0 -52
  243. package/dist/core/prompt-templates.d.ts.map +0 -1
  244. package/dist/core/prompt-templates.js +0 -250
  245. package/dist/core/prompt-templates.js.map +0 -1
  246. package/dist/core/resolve-config-value.d.ts +0 -23
  247. package/dist/core/resolve-config-value.d.ts.map +0 -1
  248. package/dist/core/resolve-config-value.js +0 -126
  249. package/dist/core/resolve-config-value.js.map +0 -1
  250. package/dist/core/resource-loader.d.ts +0 -194
  251. package/dist/core/resource-loader.d.ts.map +0 -1
  252. package/dist/core/resource-loader.js +0 -727
  253. package/dist/core/resource-loader.js.map +0 -1
  254. package/dist/core/sdk.d.ts +0 -107
  255. package/dist/core/sdk.d.ts.map +0 -1
  256. package/dist/core/sdk.js +0 -274
  257. package/dist/core/sdk.js.map +0 -1
  258. package/dist/core/session-cwd.d.ts +0 -19
  259. package/dist/core/session-cwd.d.ts.map +0 -1
  260. package/dist/core/session-cwd.js +0 -38
  261. package/dist/core/session-cwd.js.map +0 -1
  262. package/dist/core/session-manager.d.ts +0 -333
  263. package/dist/core/session-manager.d.ts.map +0 -1
  264. package/dist/core/session-manager.js +0 -1109
  265. package/dist/core/session-manager.js.map +0 -1
  266. package/dist/core/settings-manager.d.ts +0 -261
  267. package/dist/core/settings-manager.d.ts.map +0 -1
  268. package/dist/core/settings-manager.js +0 -782
  269. package/dist/core/settings-manager.js.map +0 -1
  270. package/dist/core/skills.d.ts +0 -60
  271. package/dist/core/skills.d.ts.map +0 -1
  272. package/dist/core/skills.js +0 -404
  273. package/dist/core/skills.js.map +0 -1
  274. package/dist/core/slash-commands.d.ts +0 -14
  275. package/dist/core/slash-commands.d.ts.map +0 -1
  276. package/dist/core/slash-commands.js +0 -25
  277. package/dist/core/slash-commands.js.map +0 -1
  278. package/dist/core/source-info.d.ts +0 -18
  279. package/dist/core/source-info.d.ts.map +0 -1
  280. package/dist/core/source-info.js +0 -19
  281. package/dist/core/source-info.js.map +0 -1
  282. package/dist/core/system-prompt.d.ts +0 -28
  283. package/dist/core/system-prompt.d.ts.map +0 -1
  284. package/dist/core/system-prompt.js +0 -120
  285. package/dist/core/system-prompt.js.map +0 -1
  286. package/dist/core/telemetry.d.ts +0 -3
  287. package/dist/core/telemetry.d.ts.map +0 -1
  288. package/dist/core/telemetry.js +0 -9
  289. package/dist/core/telemetry.js.map +0 -1
  290. package/dist/core/timings.d.ts +0 -8
  291. package/dist/core/timings.d.ts.map +0 -1
  292. package/dist/core/timings.js +0 -31
  293. package/dist/core/timings.js.map +0 -1
  294. package/dist/core/tools/bash.d.ts +0 -68
  295. package/dist/core/tools/bash.d.ts.map +0 -1
  296. package/dist/core/tools/bash.js +0 -355
  297. package/dist/core/tools/bash.js.map +0 -1
  298. package/dist/core/tools/edit-diff.d.ts +0 -85
  299. package/dist/core/tools/edit-diff.d.ts.map +0 -1
  300. package/dist/core/tools/edit-diff.js +0 -338
  301. package/dist/core/tools/edit-diff.js.map +0 -1
  302. package/dist/core/tools/edit.d.ts +0 -49
  303. package/dist/core/tools/edit.d.ts.map +0 -1
  304. package/dist/core/tools/edit.js +0 -324
  305. package/dist/core/tools/edit.js.map +0 -1
  306. package/dist/core/tools/file-mutation-queue.d.ts +0 -6
  307. package/dist/core/tools/file-mutation-queue.d.ts.map +0 -1
  308. package/dist/core/tools/file-mutation-queue.js +0 -37
  309. package/dist/core/tools/file-mutation-queue.js.map +0 -1
  310. package/dist/core/tools/find.d.ts +0 -35
  311. package/dist/core/tools/find.d.ts.map +0 -1
  312. package/dist/core/tools/find.js +0 -298
  313. package/dist/core/tools/find.js.map +0 -1
  314. package/dist/core/tools/grep.d.ts +0 -37
  315. package/dist/core/tools/grep.d.ts.map +0 -1
  316. package/dist/core/tools/grep.js +0 -304
  317. package/dist/core/tools/grep.js.map +0 -1
  318. package/dist/core/tools/index.d.ts +0 -40
  319. package/dist/core/tools/index.d.ts.map +0 -1
  320. package/dist/core/tools/index.js +0 -112
  321. package/dist/core/tools/index.js.map +0 -1
  322. package/dist/core/tools/ls.d.ts +0 -37
  323. package/dist/core/tools/ls.d.ts.map +0 -1
  324. package/dist/core/tools/ls.js +0 -169
  325. package/dist/core/tools/ls.js.map +0 -1
  326. package/dist/core/tools/path-utils.d.ts +0 -8
  327. package/dist/core/tools/path-utils.d.ts.map +0 -1
  328. package/dist/core/tools/path-utils.js +0 -81
  329. package/dist/core/tools/path-utils.js.map +0 -1
  330. package/dist/core/tools/read.d.ts +0 -35
  331. package/dist/core/tools/read.d.ts.map +0 -1
  332. package/dist/core/tools/read.js +0 -232
  333. package/dist/core/tools/read.js.map +0 -1
  334. package/dist/core/tools/render-utils.d.ts +0 -21
  335. package/dist/core/tools/render-utils.d.ts.map +0 -1
  336. package/dist/core/tools/render-utils.js +0 -49
  337. package/dist/core/tools/render-utils.js.map +0 -1
  338. package/dist/core/tools/tool-definition-wrapper.d.ts +0 -14
  339. package/dist/core/tools/tool-definition-wrapper.d.ts.map +0 -1
  340. package/dist/core/tools/tool-definition-wrapper.js +0 -34
  341. package/dist/core/tools/tool-definition-wrapper.js.map +0 -1
  342. package/dist/core/tools/truncate.d.ts +0 -70
  343. package/dist/core/tools/truncate.d.ts.map +0 -1
  344. package/dist/core/tools/truncate.js +0 -205
  345. package/dist/core/tools/truncate.js.map +0 -1
  346. package/dist/core/tools/write.d.ts +0 -26
  347. package/dist/core/tools/write.d.ts.map +0 -1
  348. package/dist/core/tools/write.js +0 -213
  349. package/dist/core/tools/write.js.map +0 -1
  350. package/dist/index.d.ts +0 -28
  351. package/dist/index.d.ts.map +0 -1
  352. package/dist/index.js +0 -41
  353. package/dist/index.js.map +0 -1
  354. package/dist/main.d.ts +0 -12
  355. package/dist/main.d.ts.map +0 -1
  356. package/dist/main.js +0 -589
  357. package/dist/main.js.map +0 -1
  358. package/dist/migrations.d.ts +0 -33
  359. package/dist/migrations.d.ts.map +0 -1
  360. package/dist/migrations.js +0 -281
  361. package/dist/migrations.js.map +0 -1
  362. package/dist/modes/index.d.ts +0 -9
  363. package/dist/modes/index.d.ts.map +0 -1
  364. package/dist/modes/index.js +0 -8
  365. package/dist/modes/index.js.map +0 -1
  366. package/dist/modes/interactive/assets/clankolas.png +0 -0
  367. package/dist/modes/interactive/components/armin.d.ts +0 -34
  368. package/dist/modes/interactive/components/armin.d.ts.map +0 -1
  369. package/dist/modes/interactive/components/armin.js +0 -333
  370. package/dist/modes/interactive/components/armin.js.map +0 -1
  371. package/dist/modes/interactive/components/assistant-message.d.ts +0 -20
  372. package/dist/modes/interactive/components/assistant-message.d.ts.map +0 -1
  373. package/dist/modes/interactive/components/assistant-message.js +0 -121
  374. package/dist/modes/interactive/components/assistant-message.js.map +0 -1
  375. package/dist/modes/interactive/components/bash-execution.d.ts +0 -34
  376. package/dist/modes/interactive/components/bash-execution.d.ts.map +0 -1
  377. package/dist/modes/interactive/components/bash-execution.js +0 -175
  378. package/dist/modes/interactive/components/bash-execution.js.map +0 -1
  379. package/dist/modes/interactive/components/bordered-loader.d.ts +0 -16
  380. package/dist/modes/interactive/components/bordered-loader.d.ts.map +0 -1
  381. package/dist/modes/interactive/components/bordered-loader.js +0 -54
  382. package/dist/modes/interactive/components/bordered-loader.js.map +0 -1
  383. package/dist/modes/interactive/components/branch-summary-message.d.ts +0 -16
  384. package/dist/modes/interactive/components/branch-summary-message.d.ts.map +0 -1
  385. package/dist/modes/interactive/components/branch-summary-message.js +0 -44
  386. package/dist/modes/interactive/components/branch-summary-message.js.map +0 -1
  387. package/dist/modes/interactive/components/compaction-summary-message.d.ts +0 -16
  388. package/dist/modes/interactive/components/compaction-summary-message.d.ts.map +0 -1
  389. package/dist/modes/interactive/components/compaction-summary-message.js +0 -45
  390. package/dist/modes/interactive/components/compaction-summary-message.js.map +0 -1
  391. package/dist/modes/interactive/components/config-selector.d.ts +0 -71
  392. package/dist/modes/interactive/components/config-selector.d.ts.map +0 -1
  393. package/dist/modes/interactive/components/config-selector.js +0 -481
  394. package/dist/modes/interactive/components/config-selector.js.map +0 -1
  395. package/dist/modes/interactive/components/countdown-timer.d.ts +0 -14
  396. package/dist/modes/interactive/components/countdown-timer.d.ts.map +0 -1
  397. package/dist/modes/interactive/components/countdown-timer.js +0 -33
  398. package/dist/modes/interactive/components/countdown-timer.js.map +0 -1
  399. package/dist/modes/interactive/components/custom-editor.d.ts +0 -21
  400. package/dist/modes/interactive/components/custom-editor.d.ts.map +0 -1
  401. package/dist/modes/interactive/components/custom-editor.js +0 -70
  402. package/dist/modes/interactive/components/custom-editor.js.map +0 -1
  403. package/dist/modes/interactive/components/custom-message.d.ts +0 -20
  404. package/dist/modes/interactive/components/custom-message.d.ts.map +0 -1
  405. package/dist/modes/interactive/components/custom-message.js +0 -79
  406. package/dist/modes/interactive/components/custom-message.js.map +0 -1
  407. package/dist/modes/interactive/components/daxnuts.d.ts +0 -23
  408. package/dist/modes/interactive/components/daxnuts.d.ts.map +0 -1
  409. package/dist/modes/interactive/components/daxnuts.js +0 -140
  410. package/dist/modes/interactive/components/daxnuts.js.map +0 -1
  411. package/dist/modes/interactive/components/diff.d.ts +0 -12
  412. package/dist/modes/interactive/components/diff.d.ts.map +0 -1
  413. package/dist/modes/interactive/components/diff.js +0 -133
  414. package/dist/modes/interactive/components/diff.js.map +0 -1
  415. package/dist/modes/interactive/components/dynamic-border.d.ts +0 -15
  416. package/dist/modes/interactive/components/dynamic-border.d.ts.map +0 -1
  417. package/dist/modes/interactive/components/dynamic-border.js +0 -21
  418. package/dist/modes/interactive/components/dynamic-border.js.map +0 -1
  419. package/dist/modes/interactive/components/earendil-announcement.d.ts +0 -5
  420. package/dist/modes/interactive/components/earendil-announcement.d.ts.map +0 -1
  421. package/dist/modes/interactive/components/earendil-announcement.js +0 -40
  422. package/dist/modes/interactive/components/earendil-announcement.js.map +0 -1
  423. package/dist/modes/interactive/components/extension-editor.d.ts +0 -20
  424. package/dist/modes/interactive/components/extension-editor.d.ts.map +0 -1
  425. package/dist/modes/interactive/components/extension-editor.js +0 -111
  426. package/dist/modes/interactive/components/extension-editor.js.map +0 -1
  427. package/dist/modes/interactive/components/extension-input.d.ts +0 -23
  428. package/dist/modes/interactive/components/extension-input.d.ts.map +0 -1
  429. package/dist/modes/interactive/components/extension-input.js +0 -61
  430. package/dist/modes/interactive/components/extension-input.js.map +0 -1
  431. package/dist/modes/interactive/components/extension-selector.d.ts +0 -24
  432. package/dist/modes/interactive/components/extension-selector.d.ts.map +0 -1
  433. package/dist/modes/interactive/components/extension-selector.js +0 -78
  434. package/dist/modes/interactive/components/extension-selector.js.map +0 -1
  435. package/dist/modes/interactive/components/footer.d.ts +0 -27
  436. package/dist/modes/interactive/components/footer.d.ts.map +0 -1
  437. package/dist/modes/interactive/components/footer.js +0 -201
  438. package/dist/modes/interactive/components/footer.js.map +0 -1
  439. package/dist/modes/interactive/components/index.d.ts +0 -32
  440. package/dist/modes/interactive/components/index.d.ts.map +0 -1
  441. package/dist/modes/interactive/components/index.js +0 -33
  442. package/dist/modes/interactive/components/index.js.map +0 -1
  443. package/dist/modes/interactive/components/keybinding-hints.d.ts +0 -8
  444. package/dist/modes/interactive/components/keybinding-hints.d.ts.map +0 -1
  445. package/dist/modes/interactive/components/keybinding-hints.js +0 -22
  446. package/dist/modes/interactive/components/keybinding-hints.js.map +0 -1
  447. package/dist/modes/interactive/components/login-dialog.d.ts +0 -46
  448. package/dist/modes/interactive/components/login-dialog.d.ts.map +0 -1
  449. package/dist/modes/interactive/components/login-dialog.js +0 -158
  450. package/dist/modes/interactive/components/login-dialog.js.map +0 -1
  451. package/dist/modes/interactive/components/model-selector.d.ts +0 -47
  452. package/dist/modes/interactive/components/model-selector.d.ts.map +0 -1
  453. package/dist/modes/interactive/components/model-selector.js +0 -278
  454. package/dist/modes/interactive/components/model-selector.js.map +0 -1
  455. package/dist/modes/interactive/components/oauth-selector.d.ts +0 -29
  456. package/dist/modes/interactive/components/oauth-selector.d.ts.map +0 -1
  457. package/dist/modes/interactive/components/oauth-selector.js +0 -141
  458. package/dist/modes/interactive/components/oauth-selector.js.map +0 -1
  459. package/dist/modes/interactive/components/scoped-models-selector.d.ts +0 -42
  460. package/dist/modes/interactive/components/scoped-models-selector.d.ts.map +0 -1
  461. package/dist/modes/interactive/components/scoped-models-selector.js +0 -290
  462. package/dist/modes/interactive/components/scoped-models-selector.js.map +0 -1
  463. package/dist/modes/interactive/components/session-selector-search.d.ts +0 -23
  464. package/dist/modes/interactive/components/session-selector-search.d.ts.map +0 -1
  465. package/dist/modes/interactive/components/session-selector-search.js +0 -155
  466. package/dist/modes/interactive/components/session-selector-search.js.map +0 -1
  467. package/dist/modes/interactive/components/session-selector.d.ts +0 -96
  468. package/dist/modes/interactive/components/session-selector.d.ts.map +0 -1
  469. package/dist/modes/interactive/components/session-selector.js +0 -861
  470. package/dist/modes/interactive/components/session-selector.js.map +0 -1
  471. package/dist/modes/interactive/components/settings-selector.d.ts +0 -67
  472. package/dist/modes/interactive/components/settings-selector.d.ts.map +0 -1
  473. package/dist/modes/interactive/components/settings-selector.js +0 -373
  474. package/dist/modes/interactive/components/settings-selector.js.map +0 -1
  475. package/dist/modes/interactive/components/show-images-selector.d.ts +0 -10
  476. package/dist/modes/interactive/components/show-images-selector.d.ts.map +0 -1
  477. package/dist/modes/interactive/components/show-images-selector.js +0 -39
  478. package/dist/modes/interactive/components/show-images-selector.js.map +0 -1
  479. package/dist/modes/interactive/components/skill-invocation-message.d.ts +0 -17
  480. package/dist/modes/interactive/components/skill-invocation-message.d.ts.map +0 -1
  481. package/dist/modes/interactive/components/skill-invocation-message.js +0 -47
  482. package/dist/modes/interactive/components/skill-invocation-message.js.map +0 -1
  483. package/dist/modes/interactive/components/theme-selector.d.ts +0 -11
  484. package/dist/modes/interactive/components/theme-selector.d.ts.map +0 -1
  485. package/dist/modes/interactive/components/theme-selector.js +0 -50
  486. package/dist/modes/interactive/components/theme-selector.js.map +0 -1
  487. package/dist/modes/interactive/components/thinking-selector.d.ts +0 -11
  488. package/dist/modes/interactive/components/thinking-selector.d.ts.map +0 -1
  489. package/dist/modes/interactive/components/thinking-selector.js +0 -51
  490. package/dist/modes/interactive/components/thinking-selector.js.map +0 -1
  491. package/dist/modes/interactive/components/tool-execution.d.ts +0 -63
  492. package/dist/modes/interactive/components/tool-execution.d.ts.map +0 -1
  493. package/dist/modes/interactive/components/tool-execution.js +0 -295
  494. package/dist/modes/interactive/components/tool-execution.js.map +0 -1
  495. package/dist/modes/interactive/components/tree-selector.d.ts +0 -89
  496. package/dist/modes/interactive/components/tree-selector.d.ts.map +0 -1
  497. package/dist/modes/interactive/components/tree-selector.js +0 -1092
  498. package/dist/modes/interactive/components/tree-selector.js.map +0 -1
  499. package/dist/modes/interactive/components/user-message-selector.d.ts +0 -30
  500. package/dist/modes/interactive/components/user-message-selector.d.ts.map +0 -1
  501. package/dist/modes/interactive/components/user-message-selector.js +0 -114
  502. package/dist/modes/interactive/components/user-message-selector.js.map +0 -1
  503. package/dist/modes/interactive/components/user-message.d.ts +0 -10
  504. package/dist/modes/interactive/components/user-message.d.ts.map +0 -1
  505. package/dist/modes/interactive/components/user-message.js +0 -29
  506. package/dist/modes/interactive/components/user-message.js.map +0 -1
  507. package/dist/modes/interactive/components/visual-truncate.d.ts +0 -24
  508. package/dist/modes/interactive/components/visual-truncate.d.ts.map +0 -1
  509. package/dist/modes/interactive/components/visual-truncate.js +0 -33
  510. package/dist/modes/interactive/components/visual-truncate.js.map +0 -1
  511. package/dist/modes/interactive/interactive-mode.d.ts +0 -359
  512. package/dist/modes/interactive/interactive-mode.d.ts.map +0 -1
  513. package/dist/modes/interactive/interactive-mode.js +0 -4573
  514. package/dist/modes/interactive/interactive-mode.js.map +0 -1
  515. package/dist/modes/interactive/theme/aery.json +0 -84
  516. package/dist/modes/interactive/theme/catppuccin-mocha.json +0 -81
  517. package/dist/modes/interactive/theme/dark.json +0 -85
  518. package/dist/modes/interactive/theme/dracula.json +0 -81
  519. package/dist/modes/interactive/theme/light.json +0 -84
  520. package/dist/modes/interactive/theme/nord.json +0 -81
  521. package/dist/modes/interactive/theme/theme-schema.json +0 -335
  522. package/dist/modes/interactive/theme/theme.d.ts +0 -81
  523. package/dist/modes/interactive/theme/theme.d.ts.map +0 -1
  524. package/dist/modes/interactive/theme/theme.js +0 -975
  525. package/dist/modes/interactive/theme/theme.js.map +0 -1
  526. package/dist/modes/interactive/theme/tokyo-night.json +0 -81
  527. package/dist/modes/print-mode.d.ts +0 -28
  528. package/dist/modes/print-mode.d.ts.map +0 -1
  529. package/dist/modes/print-mode.js +0 -131
  530. package/dist/modes/print-mode.js.map +0 -1
  531. package/dist/modes/rpc/jsonl.d.ts +0 -17
  532. package/dist/modes/rpc/jsonl.d.ts.map +0 -1
  533. package/dist/modes/rpc/jsonl.js +0 -49
  534. package/dist/modes/rpc/jsonl.js.map +0 -1
  535. package/dist/modes/rpc/rpc-client.d.ts +0 -224
  536. package/dist/modes/rpc/rpc-client.d.ts.map +0 -1
  537. package/dist/modes/rpc/rpc-client.js +0 -410
  538. package/dist/modes/rpc/rpc-client.js.map +0 -1
  539. package/dist/modes/rpc/rpc-mode.d.ts +0 -20
  540. package/dist/modes/rpc/rpc-mode.d.ts.map +0 -1
  541. package/dist/modes/rpc/rpc-mode.js +0 -597
  542. package/dist/modes/rpc/rpc-mode.js.map +0 -1
  543. package/dist/modes/rpc/rpc-types.d.ts +0 -419
  544. package/dist/modes/rpc/rpc-types.d.ts.map +0 -1
  545. package/dist/modes/rpc/rpc-types.js +0 -8
  546. package/dist/modes/rpc/rpc-types.js.map +0 -1
  547. package/dist/package-manager-cli.d.ts +0 -4
  548. package/dist/package-manager-cli.d.ts.map +0 -1
  549. package/dist/package-manager-cli.js +0 -468
  550. package/dist/package-manager-cli.js.map +0 -1
  551. package/dist/utils/aery-user-agent.d.ts +0 -2
  552. package/dist/utils/aery-user-agent.d.ts.map +0 -1
  553. package/dist/utils/aery-user-agent.js +0 -5
  554. package/dist/utils/aery-user-agent.js.map +0 -1
  555. package/dist/utils/changelog.d.ts +0 -21
  556. package/dist/utils/changelog.d.ts.map +0 -1
  557. package/dist/utils/changelog.js +0 -87
  558. package/dist/utils/changelog.js.map +0 -1
  559. package/dist/utils/child-process.d.ts +0 -11
  560. package/dist/utils/child-process.d.ts.map +0 -1
  561. package/dist/utils/child-process.js +0 -78
  562. package/dist/utils/child-process.js.map +0 -1
  563. package/dist/utils/clipboard-image.d.ts +0 -11
  564. package/dist/utils/clipboard-image.d.ts.map +0 -1
  565. package/dist/utils/clipboard-image.js +0 -245
  566. package/dist/utils/clipboard-image.js.map +0 -1
  567. package/dist/utils/clipboard-native.d.ts +0 -8
  568. package/dist/utils/clipboard-native.d.ts.map +0 -1
  569. package/dist/utils/clipboard-native.js +0 -14
  570. package/dist/utils/clipboard-native.js.map +0 -1
  571. package/dist/utils/clipboard.d.ts +0 -2
  572. package/dist/utils/clipboard.d.ts.map +0 -1
  573. package/dist/utils/clipboard.js +0 -110
  574. package/dist/utils/clipboard.js.map +0 -1
  575. package/dist/utils/exif-orientation.d.ts +0 -5
  576. package/dist/utils/exif-orientation.d.ts.map +0 -1
  577. package/dist/utils/exif-orientation.js +0 -158
  578. package/dist/utils/exif-orientation.js.map +0 -1
  579. package/dist/utils/frontmatter.d.ts +0 -8
  580. package/dist/utils/frontmatter.d.ts.map +0 -1
  581. package/dist/utils/frontmatter.js +0 -26
  582. package/dist/utils/frontmatter.js.map +0 -1
  583. package/dist/utils/fs-watch.d.ts +0 -5
  584. package/dist/utils/fs-watch.d.ts.map +0 -1
  585. package/dist/utils/fs-watch.js +0 -25
  586. package/dist/utils/fs-watch.js.map +0 -1
  587. package/dist/utils/git.d.ts +0 -26
  588. package/dist/utils/git.d.ts.map +0 -1
  589. package/dist/utils/git.js +0 -163
  590. package/dist/utils/git.js.map +0 -1
  591. package/dist/utils/image-convert.d.ts +0 -9
  592. package/dist/utils/image-convert.d.ts.map +0 -1
  593. package/dist/utils/image-convert.js +0 -39
  594. package/dist/utils/image-convert.js.map +0 -1
  595. package/dist/utils/image-resize.d.ts +0 -36
  596. package/dist/utils/image-resize.d.ts.map +0 -1
  597. package/dist/utils/image-resize.js +0 -137
  598. package/dist/utils/image-resize.js.map +0 -1
  599. package/dist/utils/mime.d.ts +0 -2
  600. package/dist/utils/mime.d.ts.map +0 -1
  601. package/dist/utils/mime.js +0 -26
  602. package/dist/utils/mime.js.map +0 -1
  603. package/dist/utils/paths.d.ts +0 -14
  604. package/dist/utils/paths.d.ts.map +0 -1
  605. package/dist/utils/paths.js +0 -34
  606. package/dist/utils/paths.js.map +0 -1
  607. package/dist/utils/photon.d.ts +0 -21
  608. package/dist/utils/photon.d.ts.map +0 -1
  609. package/dist/utils/photon.js +0 -121
  610. package/dist/utils/photon.js.map +0 -1
  611. package/dist/utils/shell.d.ts +0 -30
  612. package/dist/utils/shell.d.ts.map +0 -1
  613. package/dist/utils/shell.js +0 -190
  614. package/dist/utils/shell.js.map +0 -1
  615. package/dist/utils/sleep.d.ts +0 -5
  616. package/dist/utils/sleep.d.ts.map +0 -1
  617. package/dist/utils/sleep.js +0 -17
  618. package/dist/utils/sleep.js.map +0 -1
  619. package/dist/utils/tools-manager.d.ts +0 -3
  620. package/dist/utils/tools-manager.d.ts.map +0 -1
  621. package/dist/utils/tools-manager.js +0 -256
  622. package/dist/utils/tools-manager.js.map +0 -1
  623. package/dist/utils/version-check.d.ts +0 -7
  624. package/dist/utils/version-check.d.ts.map +0 -1
  625. package/dist/utils/version-check.js +0 -70
  626. package/dist/utils/version-check.js.map +0 -1
@@ -1,1974 +0,0 @@
1
- import { spawn, spawnSync } from "node:child_process";
2
- import { createHash } from "node:crypto";
3
- import { existsSync, mkdirSync, readdirSync, readFileSync, rmSync, statSync, writeFileSync } from "node:fs";
4
- import { homedir, tmpdir } from "node:os";
5
- function getEnv() {
6
- if (process.platform !== "linux" || Object.keys(process.env).length > 0) {
7
- return process.env;
8
- }
9
- try {
10
- const data = readFileSync("/proc/self/environ", "utf-8");
11
- const env = {};
12
- for (const entry of data.split("\0")) {
13
- const idx = entry.indexOf("=");
14
- if (idx > 0) {
15
- env[entry.slice(0, idx)] = entry.slice(idx + 1);
16
- }
17
- }
18
- return env;
19
- }
20
- catch {
21
- return process.env;
22
- }
23
- }
24
- import { basename, dirname, join, relative, resolve, sep } from "node:path";
25
- import { globSync } from "glob";
26
- import ignore from "ignore";
27
- import { minimatch } from "minimatch";
28
- import { CONFIG_DIR_NAME } from "../config.js";
29
- import { parseGitUrl } from "../utils/git.js";
30
- import { canonicalizePath, isLocalPath } from "../utils/paths.js";
31
- import { isStdoutTakenOver } from "./output-guard.js";
32
- const NETWORK_TIMEOUT_MS = 10000;
33
- const UPDATE_CHECK_CONCURRENCY = 4;
34
- const GIT_UPDATE_CONCURRENCY = 4;
35
- function isOfflineModeEnabled() {
36
- const value = process.env.PI_OFFLINE;
37
- if (!value)
38
- return false;
39
- return value === "1" || value.toLowerCase() === "true" || value.toLowerCase() === "yes";
40
- }
41
- /**
42
- * Compute a numeric precedence rank for a resource based on its metadata.
43
- * Lower rank = higher precedence. Used to sort resolved resources so that
44
- * name-collision resolution ("first wins") produces the correct outcome.
45
- *
46
- * Precedence (highest to lowest):
47
- * 0 project + settings entry (source: "local", scope: "project")
48
- * 1 project + auto-discovered (source: "auto", scope: "project")
49
- * 2 user + settings entry (source: "local", scope: "user")
50
- * 3 user + auto-discovered (source: "auto", scope: "user")
51
- * 4 package resource (origin: "package")
52
- */
53
- function resourcePrecedenceRank(m) {
54
- if (m.origin === "package")
55
- return 4;
56
- const scopeBase = m.scope === "project" ? 0 : 2;
57
- return scopeBase + (m.source === "local" ? 0 : 1);
58
- }
59
- const RESOURCE_TYPES = ["extensions", "skills", "prompts", "themes"];
60
- const FILE_PATTERNS = {
61
- extensions: /\.(ts|js)$/,
62
- skills: /\.md$/,
63
- prompts: /\.md$/,
64
- themes: /\.json$/,
65
- };
66
- const IGNORE_FILE_NAMES = [".gitignore", ".ignore", ".fdignore"];
67
- function toPosixPath(p) {
68
- return p.split(sep).join("/");
69
- }
70
- function getHomeDir() {
71
- return process.env.HOME || homedir();
72
- }
73
- function prefixIgnorePattern(line, prefix) {
74
- const trimmed = line.trim();
75
- if (!trimmed)
76
- return null;
77
- if (trimmed.startsWith("#") && !trimmed.startsWith("\\#"))
78
- return null;
79
- let pattern = line;
80
- let negated = false;
81
- if (pattern.startsWith("!")) {
82
- negated = true;
83
- pattern = pattern.slice(1);
84
- }
85
- else if (pattern.startsWith("\\!")) {
86
- pattern = pattern.slice(1);
87
- }
88
- if (pattern.startsWith("/")) {
89
- pattern = pattern.slice(1);
90
- }
91
- const prefixed = prefix ? `${prefix}${pattern}` : pattern;
92
- return negated ? `!${prefixed}` : prefixed;
93
- }
94
- function addIgnoreRules(ig, dir, rootDir) {
95
- const relativeDir = relative(rootDir, dir);
96
- const prefix = relativeDir ? `${toPosixPath(relativeDir)}/` : "";
97
- for (const filename of IGNORE_FILE_NAMES) {
98
- const ignorePath = join(dir, filename);
99
- if (!existsSync(ignorePath))
100
- continue;
101
- try {
102
- const content = readFileSync(ignorePath, "utf-8");
103
- const patterns = content
104
- .split(/\r?\n/)
105
- .map((line) => prefixIgnorePattern(line, prefix))
106
- .filter((line) => Boolean(line));
107
- if (patterns.length > 0) {
108
- ig.add(patterns);
109
- }
110
- }
111
- catch { }
112
- }
113
- }
114
- function isPattern(s) {
115
- return s.startsWith("!") || s.startsWith("+") || s.startsWith("-") || s.includes("*") || s.includes("?");
116
- }
117
- function isOverridePattern(s) {
118
- return s.startsWith("!") || s.startsWith("+") || s.startsWith("-");
119
- }
120
- function hasGlobPattern(s) {
121
- return s.includes("*") || s.includes("?");
122
- }
123
- function splitPatterns(entries) {
124
- const plain = [];
125
- const patterns = [];
126
- for (const entry of entries) {
127
- if (isPattern(entry)) {
128
- patterns.push(entry);
129
- }
130
- else {
131
- plain.push(entry);
132
- }
133
- }
134
- return { plain, patterns };
135
- }
136
- function collectFiles(dir, filePattern, skipNodeModules = true, ignoreMatcher, rootDir) {
137
- const files = [];
138
- if (!existsSync(dir))
139
- return files;
140
- const root = rootDir ?? dir;
141
- const ig = ignoreMatcher ?? ignore();
142
- addIgnoreRules(ig, dir, root);
143
- try {
144
- const entries = readdirSync(dir, { withFileTypes: true });
145
- for (const entry of entries) {
146
- if (entry.name.startsWith("."))
147
- continue;
148
- if (skipNodeModules && entry.name === "node_modules")
149
- continue;
150
- const fullPath = join(dir, entry.name);
151
- let isDir = entry.isDirectory();
152
- let isFile = entry.isFile();
153
- if (entry.isSymbolicLink()) {
154
- try {
155
- const stats = statSync(fullPath);
156
- isDir = stats.isDirectory();
157
- isFile = stats.isFile();
158
- }
159
- catch {
160
- continue;
161
- }
162
- }
163
- const relPath = toPosixPath(relative(root, fullPath));
164
- const ignorePath = isDir ? `${relPath}/` : relPath;
165
- if (ig.ignores(ignorePath))
166
- continue;
167
- if (isDir) {
168
- files.push(...collectFiles(fullPath, filePattern, skipNodeModules, ig, root));
169
- }
170
- else if (isFile && filePattern.test(entry.name)) {
171
- files.push(fullPath);
172
- }
173
- }
174
- }
175
- catch {
176
- // Ignore errors
177
- }
178
- return files;
179
- }
180
- function collectSkillEntries(dir, mode, ignoreMatcher, rootDir) {
181
- const entries = [];
182
- if (!existsSync(dir))
183
- return entries;
184
- const root = rootDir ?? dir;
185
- const ig = ignoreMatcher ?? ignore();
186
- addIgnoreRules(ig, dir, root);
187
- try {
188
- const dirEntries = readdirSync(dir, { withFileTypes: true });
189
- for (const entry of dirEntries) {
190
- if (entry.name !== "SKILL.md") {
191
- continue;
192
- }
193
- const fullPath = join(dir, entry.name);
194
- let isFile = entry.isFile();
195
- if (entry.isSymbolicLink()) {
196
- try {
197
- isFile = statSync(fullPath).isFile();
198
- }
199
- catch {
200
- continue;
201
- }
202
- }
203
- const relPath = toPosixPath(relative(root, fullPath));
204
- if (isFile && !ig.ignores(relPath)) {
205
- entries.push(fullPath);
206
- return entries;
207
- }
208
- }
209
- for (const entry of dirEntries) {
210
- if (entry.name.startsWith("."))
211
- continue;
212
- if (entry.name === "node_modules")
213
- continue;
214
- const fullPath = join(dir, entry.name);
215
- let isDir = entry.isDirectory();
216
- let isFile = entry.isFile();
217
- if (entry.isSymbolicLink()) {
218
- try {
219
- const stats = statSync(fullPath);
220
- isDir = stats.isDirectory();
221
- isFile = stats.isFile();
222
- }
223
- catch {
224
- continue;
225
- }
226
- }
227
- const relPath = toPosixPath(relative(root, fullPath));
228
- if (mode === "aery" && dir === root && isFile && entry.name.endsWith(".md") && !ig.ignores(relPath)) {
229
- entries.push(fullPath);
230
- continue;
231
- }
232
- if (!isDir)
233
- continue;
234
- if (ig.ignores(`${relPath}/`))
235
- continue;
236
- entries.push(...collectSkillEntries(fullPath, mode, ig, root));
237
- }
238
- }
239
- catch {
240
- // Ignore errors
241
- }
242
- return entries;
243
- }
244
- function collectAutoSkillEntries(dir, mode) {
245
- return collectSkillEntries(dir, mode);
246
- }
247
- function findGitRepoRoot(startDir) {
248
- let dir = resolve(startDir);
249
- while (true) {
250
- if (existsSync(join(dir, ".git"))) {
251
- return dir;
252
- }
253
- const parent = dirname(dir);
254
- if (parent === dir) {
255
- return null;
256
- }
257
- dir = parent;
258
- }
259
- }
260
- function collectAncestorAgentsSkillDirs(startDir) {
261
- const skillDirs = [];
262
- const resolvedStartDir = resolve(startDir);
263
- const gitRepoRoot = findGitRepoRoot(resolvedStartDir);
264
- let dir = resolvedStartDir;
265
- while (true) {
266
- skillDirs.push(join(dir, ".agents", "skills"));
267
- if (gitRepoRoot && dir === gitRepoRoot) {
268
- break;
269
- }
270
- const parent = dirname(dir);
271
- if (parent === dir) {
272
- break;
273
- }
274
- dir = parent;
275
- }
276
- return skillDirs;
277
- }
278
- function collectAutoPromptEntries(dir) {
279
- const entries = [];
280
- if (!existsSync(dir))
281
- return entries;
282
- const ig = ignore();
283
- addIgnoreRules(ig, dir, dir);
284
- try {
285
- const dirEntries = readdirSync(dir, { withFileTypes: true });
286
- for (const entry of dirEntries) {
287
- if (entry.name.startsWith("."))
288
- continue;
289
- if (entry.name === "node_modules")
290
- continue;
291
- const fullPath = join(dir, entry.name);
292
- let isFile = entry.isFile();
293
- if (entry.isSymbolicLink()) {
294
- try {
295
- isFile = statSync(fullPath).isFile();
296
- }
297
- catch {
298
- continue;
299
- }
300
- }
301
- const relPath = toPosixPath(relative(dir, fullPath));
302
- if (ig.ignores(relPath))
303
- continue;
304
- if (isFile && entry.name.endsWith(".md")) {
305
- entries.push(fullPath);
306
- }
307
- }
308
- }
309
- catch {
310
- // Ignore errors
311
- }
312
- return entries;
313
- }
314
- function collectAutoThemeEntries(dir) {
315
- const entries = [];
316
- if (!existsSync(dir))
317
- return entries;
318
- const ig = ignore();
319
- addIgnoreRules(ig, dir, dir);
320
- try {
321
- const dirEntries = readdirSync(dir, { withFileTypes: true });
322
- for (const entry of dirEntries) {
323
- if (entry.name.startsWith("."))
324
- continue;
325
- if (entry.name === "node_modules")
326
- continue;
327
- const fullPath = join(dir, entry.name);
328
- let isFile = entry.isFile();
329
- if (entry.isSymbolicLink()) {
330
- try {
331
- isFile = statSync(fullPath).isFile();
332
- }
333
- catch {
334
- continue;
335
- }
336
- }
337
- const relPath = toPosixPath(relative(dir, fullPath));
338
- if (ig.ignores(relPath))
339
- continue;
340
- if (isFile && entry.name.endsWith(".json")) {
341
- entries.push(fullPath);
342
- }
343
- }
344
- }
345
- catch {
346
- // Ignore errors
347
- }
348
- return entries;
349
- }
350
- function readPiManifestFile(packageJsonPath) {
351
- try {
352
- const content = readFileSync(packageJsonPath, "utf-8");
353
- const pkg = JSON.parse(content);
354
- return pkg.aery ?? pkg.pi ?? null;
355
- }
356
- catch {
357
- return null;
358
- }
359
- }
360
- function resolveExtensionEntries(dir) {
361
- const packageJsonPath = join(dir, "package.json");
362
- if (existsSync(packageJsonPath)) {
363
- const manifest = readPiManifestFile(packageJsonPath);
364
- if (manifest?.extensions?.length) {
365
- const entries = [];
366
- for (const extPath of manifest.extensions) {
367
- const resolvedExtPath = resolve(dir, extPath);
368
- if (existsSync(resolvedExtPath)) {
369
- entries.push(resolvedExtPath);
370
- }
371
- }
372
- if (entries.length > 0) {
373
- return entries;
374
- }
375
- }
376
- }
377
- const indexTs = join(dir, "index.ts");
378
- const indexJs = join(dir, "index.js");
379
- if (existsSync(indexTs)) {
380
- return [indexTs];
381
- }
382
- if (existsSync(indexJs)) {
383
- return [indexJs];
384
- }
385
- return null;
386
- }
387
- function collectAutoExtensionEntries(dir) {
388
- const entries = [];
389
- if (!existsSync(dir))
390
- return entries;
391
- // First check if this directory itself has explicit extension entries (package.json or index)
392
- const rootEntries = resolveExtensionEntries(dir);
393
- if (rootEntries) {
394
- return rootEntries;
395
- }
396
- // Otherwise, discover extensions from directory contents
397
- const ig = ignore();
398
- addIgnoreRules(ig, dir, dir);
399
- try {
400
- const dirEntries = readdirSync(dir, { withFileTypes: true });
401
- for (const entry of dirEntries) {
402
- if (entry.name.startsWith("."))
403
- continue;
404
- if (entry.name === "node_modules")
405
- continue;
406
- const fullPath = join(dir, entry.name);
407
- let isDir = entry.isDirectory();
408
- let isFile = entry.isFile();
409
- if (entry.isSymbolicLink()) {
410
- try {
411
- const stats = statSync(fullPath);
412
- isDir = stats.isDirectory();
413
- isFile = stats.isFile();
414
- }
415
- catch {
416
- continue;
417
- }
418
- }
419
- const relPath = toPosixPath(relative(dir, fullPath));
420
- const ignorePath = isDir ? `${relPath}/` : relPath;
421
- if (ig.ignores(ignorePath))
422
- continue;
423
- if (isFile && (entry.name.endsWith(".ts") || entry.name.endsWith(".js"))) {
424
- entries.push(fullPath);
425
- }
426
- else if (isDir) {
427
- const resolvedEntries = resolveExtensionEntries(fullPath);
428
- if (resolvedEntries) {
429
- entries.push(...resolvedEntries);
430
- }
431
- }
432
- }
433
- }
434
- catch {
435
- // Ignore errors
436
- }
437
- return entries;
438
- }
439
- /**
440
- * Collect resource files from a directory based on resource type.
441
- * Extensions use smart discovery (index.ts in subdirs), others use recursive collection.
442
- */
443
- function collectResourceFiles(dir, resourceType) {
444
- if (resourceType === "skills") {
445
- return collectSkillEntries(dir, "aery");
446
- }
447
- if (resourceType === "extensions") {
448
- return collectAutoExtensionEntries(dir);
449
- }
450
- return collectFiles(dir, FILE_PATTERNS[resourceType]);
451
- }
452
- function matchesAnyPattern(filePath, patterns, baseDir) {
453
- const rel = toPosixPath(relative(baseDir, filePath));
454
- const name = basename(filePath);
455
- const filePathPosix = toPosixPath(filePath);
456
- const isSkillFile = name === "SKILL.md";
457
- const parentDir = isSkillFile ? dirname(filePath) : undefined;
458
- const parentRel = isSkillFile ? toPosixPath(relative(baseDir, parentDir)) : undefined;
459
- const parentName = isSkillFile ? basename(parentDir) : undefined;
460
- const parentDirPosix = isSkillFile ? toPosixPath(parentDir) : undefined;
461
- return patterns.some((pattern) => {
462
- const normalizedPattern = toPosixPath(pattern);
463
- if (minimatch(rel, normalizedPattern) ||
464
- minimatch(name, normalizedPattern) ||
465
- minimatch(filePathPosix, normalizedPattern)) {
466
- return true;
467
- }
468
- if (!isSkillFile)
469
- return false;
470
- return (minimatch(parentRel, normalizedPattern) ||
471
- minimatch(parentName, normalizedPattern) ||
472
- minimatch(parentDirPosix, normalizedPattern));
473
- });
474
- }
475
- function normalizeExactPattern(pattern) {
476
- const normalized = pattern.startsWith("./") || pattern.startsWith(".\\") ? pattern.slice(2) : pattern;
477
- return toPosixPath(normalized);
478
- }
479
- function matchesAnyExactPattern(filePath, patterns, baseDir) {
480
- if (patterns.length === 0)
481
- return false;
482
- const rel = toPosixPath(relative(baseDir, filePath));
483
- const name = basename(filePath);
484
- const filePathPosix = toPosixPath(filePath);
485
- const isSkillFile = name === "SKILL.md";
486
- const parentDir = isSkillFile ? dirname(filePath) : undefined;
487
- const parentRel = isSkillFile ? toPosixPath(relative(baseDir, parentDir)) : undefined;
488
- const parentDirPosix = isSkillFile ? toPosixPath(parentDir) : undefined;
489
- return patterns.some((pattern) => {
490
- const normalized = normalizeExactPattern(pattern);
491
- if (normalized === rel || normalized === filePathPosix) {
492
- return true;
493
- }
494
- if (!isSkillFile)
495
- return false;
496
- return normalized === parentRel || normalized === parentDirPosix;
497
- });
498
- }
499
- function getOverridePatterns(entries) {
500
- return entries.filter((pattern) => pattern.startsWith("!") || pattern.startsWith("+") || pattern.startsWith("-"));
501
- }
502
- function isEnabledByOverrides(filePath, patterns, baseDir) {
503
- const overrides = getOverridePatterns(patterns);
504
- const excludes = overrides.filter((pattern) => pattern.startsWith("!")).map((pattern) => pattern.slice(1));
505
- const forceIncludes = overrides.filter((pattern) => pattern.startsWith("+")).map((pattern) => pattern.slice(1));
506
- const forceExcludes = overrides.filter((pattern) => pattern.startsWith("-")).map((pattern) => pattern.slice(1));
507
- let enabled = true;
508
- if (excludes.length > 0 && matchesAnyPattern(filePath, excludes, baseDir)) {
509
- enabled = false;
510
- }
511
- if (forceIncludes.length > 0 && matchesAnyExactPattern(filePath, forceIncludes, baseDir)) {
512
- enabled = true;
513
- }
514
- if (forceExcludes.length > 0 && matchesAnyExactPattern(filePath, forceExcludes, baseDir)) {
515
- enabled = false;
516
- }
517
- return enabled;
518
- }
519
- /**
520
- * Apply patterns to paths and return a Set of enabled paths.
521
- * Pattern types:
522
- * - Plain patterns: include matching paths
523
- * - `!pattern`: exclude matching paths
524
- * - `+path`: force-include exact path (overrides exclusions)
525
- * - `-path`: force-exclude exact path (overrides force-includes)
526
- */
527
- function applyPatterns(allPaths, patterns, baseDir) {
528
- const includes = [];
529
- const excludes = [];
530
- const forceIncludes = [];
531
- const forceExcludes = [];
532
- for (const p of patterns) {
533
- if (p.startsWith("+")) {
534
- forceIncludes.push(p.slice(1));
535
- }
536
- else if (p.startsWith("-")) {
537
- forceExcludes.push(p.slice(1));
538
- }
539
- else if (p.startsWith("!")) {
540
- excludes.push(p.slice(1));
541
- }
542
- else {
543
- includes.push(p);
544
- }
545
- }
546
- // Step 1: Apply includes (or all if no includes)
547
- let result;
548
- if (includes.length === 0) {
549
- result = [...allPaths];
550
- }
551
- else {
552
- result = allPaths.filter((filePath) => matchesAnyPattern(filePath, includes, baseDir));
553
- }
554
- // Step 2: Apply excludes
555
- if (excludes.length > 0) {
556
- result = result.filter((filePath) => !matchesAnyPattern(filePath, excludes, baseDir));
557
- }
558
- // Step 3: Force-include (add back from allPaths, overriding exclusions)
559
- if (forceIncludes.length > 0) {
560
- for (const filePath of allPaths) {
561
- if (!result.includes(filePath) && matchesAnyExactPattern(filePath, forceIncludes, baseDir)) {
562
- result.push(filePath);
563
- }
564
- }
565
- }
566
- // Step 4: Force-exclude (remove even if included or force-included)
567
- if (forceExcludes.length > 0) {
568
- result = result.filter((filePath) => !matchesAnyExactPattern(filePath, forceExcludes, baseDir));
569
- }
570
- return new Set(result);
571
- }
572
- export class DefaultPackageManager {
573
- cwd;
574
- agentDir;
575
- settingsManager;
576
- globalNpmRoot;
577
- globalNpmRootCommandKey;
578
- progressCallback;
579
- constructor(options) {
580
- this.cwd = options.cwd;
581
- this.agentDir = options.agentDir;
582
- this.settingsManager = options.settingsManager;
583
- }
584
- setProgressCallback(callback) {
585
- this.progressCallback = callback;
586
- }
587
- addSourceToSettings(source, options) {
588
- const scope = options?.local ? "project" : "user";
589
- const currentSettings = scope === "project" ? this.settingsManager.getProjectSettings() : this.settingsManager.getGlobalSettings();
590
- const currentPackages = currentSettings.packages ?? [];
591
- const normalizedSource = this.normalizePackageSourceForSettings(source, scope);
592
- const exists = currentPackages.some((existing) => this.packageSourcesMatch(existing, source, scope));
593
- if (exists) {
594
- return false;
595
- }
596
- const nextPackages = [...currentPackages, normalizedSource];
597
- if (scope === "project") {
598
- this.settingsManager.setProjectPackages(nextPackages);
599
- }
600
- else {
601
- this.settingsManager.setPackages(nextPackages);
602
- }
603
- return true;
604
- }
605
- removeSourceFromSettings(source, options) {
606
- const scope = options?.local ? "project" : "user";
607
- const currentSettings = scope === "project" ? this.settingsManager.getProjectSettings() : this.settingsManager.getGlobalSettings();
608
- const currentPackages = currentSettings.packages ?? [];
609
- const nextPackages = currentPackages.filter((existing) => !this.packageSourcesMatch(existing, source, scope));
610
- const changed = nextPackages.length !== currentPackages.length;
611
- if (!changed) {
612
- return false;
613
- }
614
- if (scope === "project") {
615
- this.settingsManager.setProjectPackages(nextPackages);
616
- }
617
- else {
618
- this.settingsManager.setPackages(nextPackages);
619
- }
620
- return true;
621
- }
622
- getInstalledPath(source, scope) {
623
- const parsed = this.parseSource(source);
624
- if (parsed.type === "npm") {
625
- const path = this.getNpmInstallPath(parsed, scope);
626
- return existsSync(path) ? path : undefined;
627
- }
628
- if (parsed.type === "git") {
629
- const path = this.getGitInstallPath(parsed, scope);
630
- return existsSync(path) ? path : undefined;
631
- }
632
- if (parsed.type === "local") {
633
- const baseDir = this.getBaseDirForScope(scope);
634
- const path = this.resolvePathFromBase(parsed.path, baseDir);
635
- return existsSync(path) ? path : undefined;
636
- }
637
- return undefined;
638
- }
639
- emitProgress(event) {
640
- this.progressCallback?.(event);
641
- }
642
- async withProgress(action, source, message, operation) {
643
- this.emitProgress({ type: "start", action, source, message });
644
- try {
645
- await operation();
646
- this.emitProgress({ type: "complete", action, source });
647
- }
648
- catch (error) {
649
- const errorMessage = error instanceof Error ? error.message : String(error);
650
- this.emitProgress({ type: "error", action, source, message: errorMessage });
651
- throw error;
652
- }
653
- }
654
- async resolve(onMissing) {
655
- const accumulator = this.createAccumulator();
656
- const globalSettings = this.settingsManager.getGlobalSettings();
657
- const projectSettings = this.settingsManager.getProjectSettings();
658
- // Collect all packages with scope (project first so cwd resources win collisions)
659
- const allPackages = [];
660
- for (const pkg of projectSettings.packages ?? []) {
661
- allPackages.push({ pkg, scope: "project" });
662
- }
663
- for (const pkg of globalSettings.packages ?? []) {
664
- allPackages.push({ pkg, scope: "user" });
665
- }
666
- // Dedupe: project scope wins over global for same package identity
667
- const packageSources = this.dedupePackages(allPackages);
668
- await this.resolvePackageSources(packageSources, accumulator, onMissing);
669
- const globalBaseDir = this.agentDir;
670
- const projectBaseDir = join(this.cwd, CONFIG_DIR_NAME);
671
- for (const resourceType of RESOURCE_TYPES) {
672
- const target = this.getTargetMap(accumulator, resourceType);
673
- const globalEntries = (globalSettings[resourceType] ?? []);
674
- const projectEntries = (projectSettings[resourceType] ?? []);
675
- this.resolveLocalEntries(projectEntries, resourceType, target, {
676
- source: "local",
677
- scope: "project",
678
- origin: "top-level",
679
- }, projectBaseDir);
680
- this.resolveLocalEntries(globalEntries, resourceType, target, {
681
- source: "local",
682
- scope: "user",
683
- origin: "top-level",
684
- }, globalBaseDir);
685
- }
686
- this.addAutoDiscoveredResources(accumulator, globalSettings, projectSettings, globalBaseDir, projectBaseDir);
687
- return this.toResolvedPaths(accumulator);
688
- }
689
- async resolveExtensionSources(sources, options) {
690
- const accumulator = this.createAccumulator();
691
- const scope = options?.temporary ? "temporary" : options?.local ? "project" : "user";
692
- const packageSources = sources.map((source) => ({ pkg: source, scope }));
693
- await this.resolvePackageSources(packageSources, accumulator);
694
- return this.toResolvedPaths(accumulator);
695
- }
696
- listConfiguredPackages() {
697
- const globalSettings = this.settingsManager.getGlobalSettings();
698
- const projectSettings = this.settingsManager.getProjectSettings();
699
- const configuredPackages = [];
700
- for (const pkg of globalSettings.packages ?? []) {
701
- const source = typeof pkg === "string" ? pkg : pkg.source;
702
- configuredPackages.push({
703
- source,
704
- scope: "user",
705
- filtered: typeof pkg === "object",
706
- installedPath: this.getInstalledPath(source, "user"),
707
- });
708
- }
709
- for (const pkg of projectSettings.packages ?? []) {
710
- const source = typeof pkg === "string" ? pkg : pkg.source;
711
- configuredPackages.push({
712
- source,
713
- scope: "project",
714
- filtered: typeof pkg === "object",
715
- installedPath: this.getInstalledPath(source, "project"),
716
- });
717
- }
718
- return configuredPackages;
719
- }
720
- async install(source, options) {
721
- const parsed = this.parseSource(source);
722
- const scope = options?.local ? "project" : "user";
723
- await this.withProgress("install", source, `Installing ${source}...`, async () => {
724
- if (parsed.type === "npm") {
725
- await this.installNpm(parsed, scope, false);
726
- return;
727
- }
728
- if (parsed.type === "git") {
729
- await this.installGit(parsed, scope);
730
- return;
731
- }
732
- if (parsed.type === "local") {
733
- const resolved = this.resolvePath(parsed.path);
734
- if (!existsSync(resolved)) {
735
- throw new Error(`Path does not exist: ${resolved}`);
736
- }
737
- return;
738
- }
739
- throw new Error(`Unsupported install source: ${source}`);
740
- });
741
- }
742
- async installAndPersist(source, options) {
743
- await this.install(source, options);
744
- this.addSourceToSettings(source, options);
745
- }
746
- async remove(source, options) {
747
- const parsed = this.parseSource(source);
748
- const scope = options?.local ? "project" : "user";
749
- await this.withProgress("remove", source, `Removing ${source}...`, async () => {
750
- if (parsed.type === "npm") {
751
- await this.uninstallNpm(parsed, scope);
752
- return;
753
- }
754
- if (parsed.type === "git") {
755
- await this.removeGit(parsed, scope);
756
- return;
757
- }
758
- if (parsed.type === "local") {
759
- return;
760
- }
761
- throw new Error(`Unsupported remove source: ${source}`);
762
- });
763
- }
764
- async removeAndPersist(source, options) {
765
- await this.remove(source, options);
766
- return this.removeSourceFromSettings(source, options);
767
- }
768
- async update(source) {
769
- const globalSettings = this.settingsManager.getGlobalSettings();
770
- const projectSettings = this.settingsManager.getProjectSettings();
771
- const identity = source ? this.getPackageIdentity(source) : undefined;
772
- let matched = false;
773
- const updateSources = [];
774
- for (const pkg of globalSettings.packages ?? []) {
775
- const sourceStr = typeof pkg === "string" ? pkg : pkg.source;
776
- if (identity && this.getPackageIdentity(sourceStr, "user") !== identity)
777
- continue;
778
- matched = true;
779
- updateSources.push({ source: sourceStr, scope: "user" });
780
- }
781
- for (const pkg of projectSettings.packages ?? []) {
782
- const sourceStr = typeof pkg === "string" ? pkg : pkg.source;
783
- if (identity && this.getPackageIdentity(sourceStr, "project") !== identity)
784
- continue;
785
- matched = true;
786
- updateSources.push({ source: sourceStr, scope: "project" });
787
- }
788
- if (source && !matched) {
789
- throw new Error(this.buildNoMatchingPackageMessage(source, [
790
- ...(globalSettings.packages ?? []),
791
- ...(projectSettings.packages ?? []),
792
- ]));
793
- }
794
- await this.updateConfiguredSources(updateSources);
795
- }
796
- async updateConfiguredSources(sources) {
797
- if (isOfflineModeEnabled() || sources.length === 0) {
798
- return;
799
- }
800
- const npmCandidates = [];
801
- const gitCandidates = [];
802
- for (const entry of sources) {
803
- const parsed = this.parseSource(entry.source);
804
- if (parsed.type === "local" || parsed.pinned) {
805
- continue;
806
- }
807
- if (parsed.type === "npm") {
808
- npmCandidates.push({ ...entry, parsed });
809
- continue;
810
- }
811
- gitCandidates.push({ ...entry, parsed });
812
- }
813
- const npmCheckTasks = npmCandidates.map((entry) => async () => ({
814
- entry,
815
- shouldUpdate: await this.shouldUpdateNpmSource(entry.parsed, entry.scope),
816
- }));
817
- const npmCheckResults = await this.runWithConcurrency(npmCheckTasks, UPDATE_CHECK_CONCURRENCY);
818
- const userNpmUpdates = [];
819
- const projectNpmUpdates = [];
820
- for (const result of npmCheckResults) {
821
- if (!result.shouldUpdate) {
822
- continue;
823
- }
824
- if (result.entry.scope === "user") {
825
- userNpmUpdates.push(result.entry);
826
- }
827
- else {
828
- projectNpmUpdates.push(result.entry);
829
- }
830
- }
831
- const tasks = [];
832
- if (userNpmUpdates.length > 0) {
833
- tasks.push(this.updateNpmBatch(userNpmUpdates, "user"));
834
- }
835
- if (projectNpmUpdates.length > 0) {
836
- tasks.push(this.updateNpmBatch(projectNpmUpdates, "project"));
837
- }
838
- if (gitCandidates.length > 0) {
839
- const gitTasks = gitCandidates.map((entry) => async () => this.withProgress("update", entry.source, `Updating ${entry.source}...`, async () => {
840
- await this.updateGit(entry.parsed, entry.scope);
841
- }));
842
- tasks.push(this.runWithConcurrency(gitTasks, GIT_UPDATE_CONCURRENCY).then(() => { }));
843
- }
844
- await Promise.all(tasks);
845
- }
846
- async shouldUpdateNpmSource(source, scope) {
847
- const installedPath = this.getNpmInstallPath(source, scope);
848
- const installedVersion = existsSync(installedPath) ? this.getInstalledNpmVersion(installedPath) : undefined;
849
- if (!installedVersion) {
850
- return true;
851
- }
852
- try {
853
- const latestVersion = await this.getLatestNpmVersion(source.name);
854
- return latestVersion !== installedVersion;
855
- }
856
- catch {
857
- // Preserve existing update behavior when version lookup fails.
858
- return true;
859
- }
860
- }
861
- async updateNpmBatch(sources, scope) {
862
- if (sources.length === 0) {
863
- return;
864
- }
865
- const sourceLabel = sources.length === 1 ? sources[0].source : `${scope} npm packages`;
866
- const message = sources.length === 1 ? `Updating ${sources[0].source}...` : `Updating ${scope} npm packages...`;
867
- const specs = sources.map((entry) => `${entry.parsed.name}@latest`);
868
- await this.withProgress("update", sourceLabel, message, async () => {
869
- await this.installNpmBatch(specs, scope);
870
- });
871
- }
872
- async installNpmBatch(specs, scope) {
873
- if (scope === "user") {
874
- await this.runNpmCommand(["install", "-g", ...specs]);
875
- return;
876
- }
877
- const installRoot = this.getNpmInstallRoot(scope, false);
878
- this.ensureNpmProject(installRoot);
879
- await this.runNpmCommand(["install", ...specs, "--prefix", installRoot]);
880
- }
881
- async checkForAvailableUpdates() {
882
- if (isOfflineModeEnabled()) {
883
- return [];
884
- }
885
- const globalSettings = this.settingsManager.getGlobalSettings();
886
- const projectSettings = this.settingsManager.getProjectSettings();
887
- const allPackages = [];
888
- for (const pkg of projectSettings.packages ?? []) {
889
- allPackages.push({ pkg, scope: "project" });
890
- }
891
- for (const pkg of globalSettings.packages ?? []) {
892
- allPackages.push({ pkg, scope: "user" });
893
- }
894
- const packageSources = this.dedupePackages(allPackages);
895
- const checks = packageSources
896
- .filter((entry) => entry.scope !== "temporary")
897
- .map((entry) => async () => {
898
- const source = typeof entry.pkg === "string" ? entry.pkg : entry.pkg.source;
899
- const parsed = this.parseSource(source);
900
- if (parsed.type === "local" || parsed.pinned) {
901
- return undefined;
902
- }
903
- if (parsed.type === "npm") {
904
- const installedPath = this.getNpmInstallPath(parsed, entry.scope);
905
- if (!existsSync(installedPath)) {
906
- return undefined;
907
- }
908
- const hasUpdate = await this.npmHasAvailableUpdate(parsed, installedPath);
909
- if (!hasUpdate) {
910
- return undefined;
911
- }
912
- return {
913
- source,
914
- displayName: parsed.name,
915
- type: "npm",
916
- scope: entry.scope,
917
- };
918
- }
919
- const installedPath = this.getGitInstallPath(parsed, entry.scope);
920
- if (!existsSync(installedPath)) {
921
- return undefined;
922
- }
923
- const hasUpdate = await this.gitHasAvailableUpdate(installedPath);
924
- if (!hasUpdate) {
925
- return undefined;
926
- }
927
- return {
928
- source,
929
- displayName: `${parsed.host}/${parsed.path}`,
930
- type: "git",
931
- scope: entry.scope,
932
- };
933
- });
934
- const results = await this.runWithConcurrency(checks, UPDATE_CHECK_CONCURRENCY);
935
- return results.filter((result) => result !== undefined);
936
- }
937
- async resolvePackageSources(sources, accumulator, onMissing) {
938
- for (const { pkg, scope } of sources) {
939
- const sourceStr = typeof pkg === "string" ? pkg : pkg.source;
940
- const filter = typeof pkg === "object" ? pkg : undefined;
941
- const parsed = this.parseSource(sourceStr);
942
- const metadata = { source: sourceStr, scope, origin: "package" };
943
- if (parsed.type === "local") {
944
- const baseDir = this.getBaseDirForScope(scope);
945
- this.resolveLocalExtensionSource(parsed, accumulator, filter, metadata, baseDir);
946
- continue;
947
- }
948
- const installMissing = async () => {
949
- if (isOfflineModeEnabled()) {
950
- return false;
951
- }
952
- if (!onMissing) {
953
- await this.installParsedSource(parsed, scope);
954
- return true;
955
- }
956
- const action = await onMissing(sourceStr);
957
- if (action === "skip")
958
- return false;
959
- if (action === "error")
960
- throw new Error(`Missing source: ${sourceStr}`);
961
- await this.installParsedSource(parsed, scope);
962
- return true;
963
- };
964
- if (parsed.type === "npm") {
965
- const installedPath = this.getNpmInstallPath(parsed, scope);
966
- const needsInstall = !existsSync(installedPath) ||
967
- (parsed.pinned && !(await this.installedNpmMatchesPinnedVersion(parsed, installedPath)));
968
- if (needsInstall) {
969
- const installed = await installMissing();
970
- if (!installed)
971
- continue;
972
- }
973
- metadata.baseDir = installedPath;
974
- this.collectPackageResources(installedPath, accumulator, filter, metadata);
975
- continue;
976
- }
977
- if (parsed.type === "git") {
978
- const installedPath = this.getGitInstallPath(parsed, scope);
979
- if (!existsSync(installedPath)) {
980
- const installed = await installMissing();
981
- if (!installed)
982
- continue;
983
- }
984
- else if (scope === "temporary" && !parsed.pinned && !isOfflineModeEnabled()) {
985
- await this.refreshTemporaryGitSource(parsed, sourceStr);
986
- }
987
- metadata.baseDir = installedPath;
988
- this.collectPackageResources(installedPath, accumulator, filter, metadata);
989
- }
990
- }
991
- }
992
- resolveLocalExtensionSource(source, accumulator, filter, metadata, baseDir) {
993
- const resolved = this.resolvePathFromBase(source.path, baseDir);
994
- if (!existsSync(resolved)) {
995
- return;
996
- }
997
- try {
998
- const stats = statSync(resolved);
999
- if (stats.isFile()) {
1000
- metadata.baseDir = dirname(resolved);
1001
- this.addResource(accumulator.extensions, resolved, metadata, true);
1002
- return;
1003
- }
1004
- if (stats.isDirectory()) {
1005
- metadata.baseDir = resolved;
1006
- const resources = this.collectPackageResources(resolved, accumulator, filter, metadata);
1007
- if (!resources) {
1008
- this.addResource(accumulator.extensions, resolved, metadata, true);
1009
- }
1010
- }
1011
- }
1012
- catch {
1013
- return;
1014
- }
1015
- }
1016
- async installParsedSource(parsed, scope) {
1017
- if (parsed.type === "npm") {
1018
- await this.installNpm(parsed, scope, scope === "temporary");
1019
- return;
1020
- }
1021
- if (parsed.type === "git") {
1022
- await this.installGit(parsed, scope);
1023
- return;
1024
- }
1025
- }
1026
- getPackageSourceString(pkg) {
1027
- return typeof pkg === "string" ? pkg : pkg.source;
1028
- }
1029
- getSourceMatchKeyForInput(source) {
1030
- const parsed = this.parseSource(source);
1031
- if (parsed.type === "npm") {
1032
- return `npm:${parsed.name}`;
1033
- }
1034
- if (parsed.type === "git") {
1035
- return `git:${parsed.host}/${parsed.path}`;
1036
- }
1037
- return `local:${this.resolvePath(parsed.path)}`;
1038
- }
1039
- getSourceMatchKeyForSettings(source, scope) {
1040
- const parsed = this.parseSource(source);
1041
- if (parsed.type === "npm") {
1042
- return `npm:${parsed.name}`;
1043
- }
1044
- if (parsed.type === "git") {
1045
- return `git:${parsed.host}/${parsed.path}`;
1046
- }
1047
- const baseDir = this.getBaseDirForScope(scope);
1048
- return `local:${this.resolvePathFromBase(parsed.path, baseDir)}`;
1049
- }
1050
- buildNoMatchingPackageMessage(source, configuredPackages) {
1051
- const suggestion = this.findSuggestedConfiguredSource(source, configuredPackages);
1052
- if (!suggestion) {
1053
- return `No matching package found for ${source}`;
1054
- }
1055
- return `No matching package found for ${source}. Did you mean ${suggestion}?`;
1056
- }
1057
- findSuggestedConfiguredSource(source, configuredPackages) {
1058
- const trimmedSource = source.trim();
1059
- const suggestions = new Set();
1060
- for (const pkg of configuredPackages) {
1061
- const sourceStr = this.getPackageSourceString(pkg);
1062
- const parsed = this.parseSource(sourceStr);
1063
- if (parsed.type === "npm") {
1064
- if (trimmedSource === parsed.name || trimmedSource === parsed.spec) {
1065
- suggestions.add(sourceStr);
1066
- }
1067
- continue;
1068
- }
1069
- if (parsed.type === "git") {
1070
- const shorthand = `${parsed.host}/${parsed.path}`;
1071
- const shorthandWithRef = parsed.ref ? `${shorthand}@${parsed.ref}` : undefined;
1072
- if (trimmedSource === shorthand || (shorthandWithRef && trimmedSource === shorthandWithRef)) {
1073
- suggestions.add(sourceStr);
1074
- }
1075
- }
1076
- }
1077
- return suggestions.values().next().value;
1078
- }
1079
- packageSourcesMatch(existing, inputSource, scope) {
1080
- const left = this.getSourceMatchKeyForSettings(this.getPackageSourceString(existing), scope);
1081
- const right = this.getSourceMatchKeyForInput(inputSource);
1082
- return left === right;
1083
- }
1084
- normalizePackageSourceForSettings(source, scope) {
1085
- const parsed = this.parseSource(source);
1086
- if (parsed.type !== "local") {
1087
- return source;
1088
- }
1089
- const baseDir = this.getBaseDirForScope(scope);
1090
- const resolved = this.resolvePath(parsed.path);
1091
- const rel = relative(baseDir, resolved);
1092
- return rel || ".";
1093
- }
1094
- parseSource(source) {
1095
- if (source.startsWith("npm:")) {
1096
- const spec = source.slice("npm:".length).trim();
1097
- const { name, version } = this.parseNpmSpec(spec);
1098
- return {
1099
- type: "npm",
1100
- spec,
1101
- name,
1102
- pinned: Boolean(version),
1103
- };
1104
- }
1105
- if (isLocalPath(source)) {
1106
- return { type: "local", path: source };
1107
- }
1108
- // Try parsing as git URL
1109
- const gitParsed = parseGitUrl(source);
1110
- if (gitParsed) {
1111
- return gitParsed;
1112
- }
1113
- return { type: "local", path: source };
1114
- }
1115
- async installedNpmMatchesPinnedVersion(source, installedPath) {
1116
- const installedVersion = this.getInstalledNpmVersion(installedPath);
1117
- if (!installedVersion) {
1118
- return false;
1119
- }
1120
- const { version: pinnedVersion } = this.parseNpmSpec(source.spec);
1121
- if (!pinnedVersion) {
1122
- return true;
1123
- }
1124
- return installedVersion === pinnedVersion;
1125
- }
1126
- async npmHasAvailableUpdate(source, installedPath) {
1127
- if (isOfflineModeEnabled()) {
1128
- return false;
1129
- }
1130
- const installedVersion = this.getInstalledNpmVersion(installedPath);
1131
- if (!installedVersion) {
1132
- return false;
1133
- }
1134
- try {
1135
- const latestVersion = await this.getLatestNpmVersion(source.name);
1136
- return latestVersion !== installedVersion;
1137
- }
1138
- catch {
1139
- return false;
1140
- }
1141
- }
1142
- getInstalledNpmVersion(installedPath) {
1143
- const packageJsonPath = join(installedPath, "package.json");
1144
- if (!existsSync(packageJsonPath))
1145
- return undefined;
1146
- try {
1147
- const content = readFileSync(packageJsonPath, "utf-8");
1148
- const pkg = JSON.parse(content);
1149
- return pkg.version;
1150
- }
1151
- catch {
1152
- return undefined;
1153
- }
1154
- }
1155
- async getLatestNpmVersion(packageName) {
1156
- const npmCommand = this.getNpmCommand();
1157
- const stdout = await this.runCommandCapture(npmCommand.command, [...npmCommand.args, "view", packageName, "version", "--json"], { cwd: this.cwd, timeoutMs: NETWORK_TIMEOUT_MS });
1158
- const raw = stdout.trim();
1159
- if (!raw)
1160
- throw new Error("Empty response from npm view");
1161
- return JSON.parse(raw);
1162
- }
1163
- async gitHasAvailableUpdate(installedPath) {
1164
- if (isOfflineModeEnabled()) {
1165
- return false;
1166
- }
1167
- try {
1168
- const localHead = await this.runCommandCapture("git", ["rev-parse", "HEAD"], {
1169
- cwd: installedPath,
1170
- timeoutMs: NETWORK_TIMEOUT_MS,
1171
- });
1172
- const remoteHead = await this.getRemoteGitHead(installedPath);
1173
- return localHead.trim() !== remoteHead.trim();
1174
- }
1175
- catch {
1176
- return false;
1177
- }
1178
- }
1179
- async getRemoteGitHead(installedPath) {
1180
- const upstreamRef = await this.getGitUpstreamRef(installedPath);
1181
- if (upstreamRef) {
1182
- const remoteHead = await this.runGitRemoteCommand(installedPath, ["ls-remote", "origin", upstreamRef]);
1183
- const match = remoteHead.match(/^([0-9a-f]{40})\s+/m);
1184
- if (match?.[1]) {
1185
- return match[1];
1186
- }
1187
- }
1188
- const remoteHead = await this.runGitRemoteCommand(installedPath, ["ls-remote", "origin", "HEAD"]);
1189
- const match = remoteHead.match(/^([0-9a-f]{40})\s+HEAD$/m);
1190
- if (!match?.[1]) {
1191
- throw new Error("Failed to determine remote HEAD");
1192
- }
1193
- return match[1];
1194
- }
1195
- async getLocalGitUpdateTarget(installedPath) {
1196
- try {
1197
- const upstream = await this.runCommandCapture("git", ["rev-parse", "--abbrev-ref", "@{upstream}"], {
1198
- cwd: installedPath,
1199
- timeoutMs: NETWORK_TIMEOUT_MS,
1200
- });
1201
- const trimmedUpstream = upstream.trim();
1202
- if (!trimmedUpstream.startsWith("origin/")) {
1203
- throw new Error(`Unsupported upstream remote: ${trimmedUpstream}`);
1204
- }
1205
- const branch = trimmedUpstream.slice("origin/".length);
1206
- if (!branch) {
1207
- throw new Error("Missing upstream branch name");
1208
- }
1209
- const head = await this.runCommandCapture("git", ["rev-parse", "@{upstream}"], {
1210
- cwd: installedPath,
1211
- timeoutMs: NETWORK_TIMEOUT_MS,
1212
- });
1213
- return {
1214
- ref: "@{upstream}",
1215
- head,
1216
- fetchArgs: [
1217
- "fetch",
1218
- "--prune",
1219
- "--no-tags",
1220
- "origin",
1221
- `+refs/heads/${branch}:refs/remotes/origin/${branch}`,
1222
- ],
1223
- };
1224
- }
1225
- catch {
1226
- await this.runCommand("git", ["remote", "set-head", "origin", "-a"], { cwd: installedPath }).catch(() => { });
1227
- const head = await this.runCommandCapture("git", ["rev-parse", "origin/HEAD"], {
1228
- cwd: installedPath,
1229
- timeoutMs: NETWORK_TIMEOUT_MS,
1230
- });
1231
- const originHeadRef = await this.runCommandCapture("git", ["symbolic-ref", "refs/remotes/origin/HEAD"], {
1232
- cwd: installedPath,
1233
- timeoutMs: NETWORK_TIMEOUT_MS,
1234
- }).catch(() => "");
1235
- const branch = originHeadRef.trim().replace(/^refs\/remotes\/origin\//, "");
1236
- if (branch) {
1237
- return {
1238
- ref: "origin/HEAD",
1239
- head,
1240
- fetchArgs: [
1241
- "fetch",
1242
- "--prune",
1243
- "--no-tags",
1244
- "origin",
1245
- `+refs/heads/${branch}:refs/remotes/origin/${branch}`,
1246
- ],
1247
- };
1248
- }
1249
- return {
1250
- ref: "origin/HEAD",
1251
- head,
1252
- fetchArgs: ["fetch", "--prune", "--no-tags", "origin", "+HEAD:refs/remotes/origin/HEAD"],
1253
- };
1254
- }
1255
- }
1256
- async getGitUpstreamRef(installedPath) {
1257
- try {
1258
- const upstream = await this.runCommandCapture("git", ["rev-parse", "--abbrev-ref", "@{upstream}"], {
1259
- cwd: installedPath,
1260
- timeoutMs: NETWORK_TIMEOUT_MS,
1261
- });
1262
- const trimmed = upstream.trim();
1263
- if (!trimmed.startsWith("origin/")) {
1264
- return undefined;
1265
- }
1266
- const branch = trimmed.slice("origin/".length);
1267
- return branch ? `refs/heads/${branch}` : undefined;
1268
- }
1269
- catch {
1270
- return undefined;
1271
- }
1272
- }
1273
- runGitRemoteCommand(installedPath, args) {
1274
- return this.runCommandCapture("git", args, {
1275
- cwd: installedPath,
1276
- timeoutMs: NETWORK_TIMEOUT_MS,
1277
- env: {
1278
- GIT_TERMINAL_PROMPT: "0",
1279
- },
1280
- });
1281
- }
1282
- async runWithConcurrency(tasks, limit) {
1283
- if (tasks.length === 0) {
1284
- return [];
1285
- }
1286
- const results = new Array(tasks.length);
1287
- let nextIndex = 0;
1288
- const workerCount = Math.max(1, Math.min(limit, tasks.length));
1289
- const worker = async () => {
1290
- while (true) {
1291
- const index = nextIndex;
1292
- nextIndex += 1;
1293
- if (index >= tasks.length) {
1294
- return;
1295
- }
1296
- results[index] = await tasks[index]();
1297
- }
1298
- };
1299
- await Promise.all(Array.from({ length: workerCount }, () => worker()));
1300
- return results;
1301
- }
1302
- /**
1303
- * Get a unique identity for a package, ignoring version/ref.
1304
- * Used to detect when the same package is in both global and project settings.
1305
- * For git packages, uses normalized host/path to ensure SSH and HTTPS URLs
1306
- * for the same repository are treated as identical.
1307
- */
1308
- getPackageIdentity(source, scope) {
1309
- const parsed = this.parseSource(source);
1310
- if (parsed.type === "npm") {
1311
- return `npm:${parsed.name}`;
1312
- }
1313
- if (parsed.type === "git") {
1314
- // Use host/path for identity to normalize SSH and HTTPS
1315
- return `git:${parsed.host}/${parsed.path}`;
1316
- }
1317
- if (scope) {
1318
- const baseDir = this.getBaseDirForScope(scope);
1319
- return `local:${this.resolvePathFromBase(parsed.path, baseDir)}`;
1320
- }
1321
- return `local:${this.resolvePath(parsed.path)}`;
1322
- }
1323
- /**
1324
- * Dedupe packages: if same package identity appears in both global and project,
1325
- * keep only the project one (project wins).
1326
- */
1327
- dedupePackages(packages) {
1328
- const seen = new Map();
1329
- for (const entry of packages) {
1330
- const sourceStr = typeof entry.pkg === "string" ? entry.pkg : entry.pkg.source;
1331
- const identity = this.getPackageIdentity(sourceStr, entry.scope);
1332
- const existing = seen.get(identity);
1333
- if (!existing) {
1334
- seen.set(identity, entry);
1335
- }
1336
- else if (entry.scope === "project" && existing.scope === "user") {
1337
- // Project wins over user
1338
- seen.set(identity, entry);
1339
- }
1340
- // If existing is project and new is global, keep existing (project)
1341
- // If both are same scope, keep first one
1342
- }
1343
- return Array.from(seen.values());
1344
- }
1345
- parseNpmSpec(spec) {
1346
- const match = spec.match(/^(@?[^@]+(?:\/[^@]+)?)(?:@(.+))?$/);
1347
- if (!match) {
1348
- return { name: spec };
1349
- }
1350
- const name = match[1] ?? spec;
1351
- const version = match[2];
1352
- return { name, version };
1353
- }
1354
- getNpmCommand() {
1355
- const configuredCommand = this.settingsManager.getNpmCommand();
1356
- if (!configuredCommand || configuredCommand.length === 0) {
1357
- return { command: "npm", args: [] };
1358
- }
1359
- const [command, ...args] = configuredCommand;
1360
- if (!command) {
1361
- throw new Error("Invalid npmCommand: first array entry must be a non-empty command");
1362
- }
1363
- return { command, args };
1364
- }
1365
- async runNpmCommand(args, options) {
1366
- const npmCommand = this.getNpmCommand();
1367
- await this.runCommand(npmCommand.command, [...npmCommand.args, ...args], options);
1368
- }
1369
- getGitDependencyInstallArgs() {
1370
- const configuredCommand = this.settingsManager.getNpmCommand();
1371
- if (configuredCommand && configuredCommand.length > 0) {
1372
- return ["install"];
1373
- }
1374
- return ["install", "--omit=dev"];
1375
- }
1376
- runNpmCommandSync(args) {
1377
- const npmCommand = this.getNpmCommand();
1378
- return this.runCommandSync(npmCommand.command, [...npmCommand.args, ...args]);
1379
- }
1380
- async installNpm(source, scope, temporary) {
1381
- if (scope === "user" && !temporary) {
1382
- await this.runNpmCommand(["install", "-g", source.spec]);
1383
- return;
1384
- }
1385
- const installRoot = this.getNpmInstallRoot(scope, temporary);
1386
- this.ensureNpmProject(installRoot);
1387
- await this.runNpmCommand(["install", source.spec, "--prefix", installRoot]);
1388
- }
1389
- async uninstallNpm(source, scope) {
1390
- if (scope === "user") {
1391
- await this.runNpmCommand(["uninstall", "-g", source.name]);
1392
- return;
1393
- }
1394
- const installRoot = this.getNpmInstallRoot(scope, false);
1395
- if (!existsSync(installRoot)) {
1396
- return;
1397
- }
1398
- await this.runNpmCommand(["uninstall", source.name, "--prefix", installRoot]);
1399
- }
1400
- async installGit(source, scope) {
1401
- const targetDir = this.getGitInstallPath(source, scope);
1402
- if (existsSync(targetDir)) {
1403
- return;
1404
- }
1405
- const gitRoot = this.getGitInstallRoot(scope);
1406
- if (gitRoot) {
1407
- this.ensureGitIgnore(gitRoot);
1408
- }
1409
- mkdirSync(dirname(targetDir), { recursive: true });
1410
- await this.runCommand("git", ["clone", source.repo, targetDir]);
1411
- if (source.ref) {
1412
- await this.runCommand("git", ["checkout", source.ref], { cwd: targetDir });
1413
- }
1414
- const packageJsonPath = join(targetDir, "package.json");
1415
- if (existsSync(packageJsonPath)) {
1416
- await this.runNpmCommand(this.getGitDependencyInstallArgs(), { cwd: targetDir });
1417
- }
1418
- }
1419
- async updateGit(source, scope) {
1420
- const targetDir = this.getGitInstallPath(source, scope);
1421
- if (!existsSync(targetDir)) {
1422
- await this.installGit(source, scope);
1423
- return;
1424
- }
1425
- const target = await this.getLocalGitUpdateTarget(targetDir);
1426
- // Fetch only the ref we will reset to, avoiding unrelated branch/tag noise.
1427
- await this.runCommand("git", target.fetchArgs, { cwd: targetDir });
1428
- const localHead = await this.runCommandCapture("git", ["rev-parse", "HEAD"], {
1429
- cwd: targetDir,
1430
- timeoutMs: NETWORK_TIMEOUT_MS,
1431
- });
1432
- const refreshedTargetHead = await this.runCommandCapture("git", ["rev-parse", target.ref], {
1433
- cwd: targetDir,
1434
- timeoutMs: NETWORK_TIMEOUT_MS,
1435
- });
1436
- if (localHead.trim() === refreshedTargetHead.trim()) {
1437
- return;
1438
- }
1439
- await this.runCommand("git", ["reset", "--hard", target.ref], { cwd: targetDir });
1440
- // Clean untracked files (extensions should be pristine)
1441
- await this.runCommand("git", ["clean", "-fdx"], { cwd: targetDir });
1442
- const packageJsonPath = join(targetDir, "package.json");
1443
- if (existsSync(packageJsonPath)) {
1444
- await this.runNpmCommand(this.getGitDependencyInstallArgs(), { cwd: targetDir });
1445
- }
1446
- }
1447
- async refreshTemporaryGitSource(source, sourceStr) {
1448
- if (isOfflineModeEnabled()) {
1449
- return;
1450
- }
1451
- try {
1452
- await this.withProgress("pull", sourceStr, `Refreshing ${sourceStr}...`, async () => {
1453
- await this.updateGit(source, "temporary");
1454
- });
1455
- }
1456
- catch {
1457
- // Keep cached temporary checkout if refresh fails.
1458
- }
1459
- }
1460
- async removeGit(source, scope) {
1461
- const targetDir = this.getGitInstallPath(source, scope);
1462
- if (!existsSync(targetDir))
1463
- return;
1464
- rmSync(targetDir, { recursive: true, force: true });
1465
- this.pruneEmptyGitParents(targetDir, this.getGitInstallRoot(scope));
1466
- }
1467
- pruneEmptyGitParents(targetDir, installRoot) {
1468
- if (!installRoot)
1469
- return;
1470
- const resolvedRoot = resolve(installRoot);
1471
- let current = dirname(targetDir);
1472
- while (current.startsWith(resolvedRoot) && current !== resolvedRoot) {
1473
- if (!existsSync(current)) {
1474
- current = dirname(current);
1475
- continue;
1476
- }
1477
- const entries = readdirSync(current);
1478
- if (entries.length > 0) {
1479
- break;
1480
- }
1481
- try {
1482
- rmSync(current, { recursive: true, force: true });
1483
- }
1484
- catch {
1485
- break;
1486
- }
1487
- current = dirname(current);
1488
- }
1489
- }
1490
- ensureNpmProject(installRoot) {
1491
- if (!existsSync(installRoot)) {
1492
- mkdirSync(installRoot, { recursive: true });
1493
- }
1494
- this.ensureGitIgnore(installRoot);
1495
- const packageJsonPath = join(installRoot, "package.json");
1496
- if (!existsSync(packageJsonPath)) {
1497
- const pkgJson = { name: "aery-extensions", private: true };
1498
- writeFileSync(packageJsonPath, JSON.stringify(pkgJson, null, 2), "utf-8");
1499
- }
1500
- }
1501
- ensureGitIgnore(dir) {
1502
- if (!existsSync(dir)) {
1503
- mkdirSync(dir, { recursive: true });
1504
- }
1505
- const ignorePath = join(dir, ".gitignore");
1506
- if (!existsSync(ignorePath)) {
1507
- writeFileSync(ignorePath, "*\n!.gitignore\n", "utf-8");
1508
- }
1509
- }
1510
- getNpmInstallRoot(scope, temporary) {
1511
- if (temporary) {
1512
- return this.getTemporaryDir("npm");
1513
- }
1514
- if (scope === "project") {
1515
- return join(this.cwd, CONFIG_DIR_NAME, "npm");
1516
- }
1517
- return join(this.getGlobalNpmRoot(), "..");
1518
- }
1519
- getGlobalNpmRoot() {
1520
- const npmCommand = this.getNpmCommand();
1521
- const commandKey = [npmCommand.command, ...npmCommand.args].join("\0");
1522
- if (this.globalNpmRoot && this.globalNpmRootCommandKey === commandKey) {
1523
- return this.globalNpmRoot;
1524
- }
1525
- const isBunPackageManager = npmCommand.command === "bun";
1526
- if (isBunPackageManager) {
1527
- const binDir = this.runNpmCommandSync(["pm", "bin", "-g"]).trim();
1528
- this.globalNpmRoot = join(dirname(binDir), "install", "global", "node_modules");
1529
- }
1530
- else {
1531
- this.globalNpmRoot = this.runNpmCommandSync(["root", "-g"]).trim();
1532
- }
1533
- this.globalNpmRootCommandKey = commandKey;
1534
- return this.globalNpmRoot;
1535
- }
1536
- getNpmInstallPath(source, scope) {
1537
- if (scope === "temporary") {
1538
- return join(this.getTemporaryDir("npm"), "node_modules", source.name);
1539
- }
1540
- if (scope === "project") {
1541
- return join(this.cwd, CONFIG_DIR_NAME, "npm", "node_modules", source.name);
1542
- }
1543
- return join(this.getGlobalNpmRoot(), source.name);
1544
- }
1545
- getGitInstallPath(source, scope) {
1546
- if (scope === "temporary") {
1547
- return this.getTemporaryDir(`git-${source.host}`, source.path);
1548
- }
1549
- if (scope === "project") {
1550
- return join(this.cwd, CONFIG_DIR_NAME, "git", source.host, source.path);
1551
- }
1552
- return join(this.agentDir, "git", source.host, source.path);
1553
- }
1554
- getGitInstallRoot(scope) {
1555
- if (scope === "temporary") {
1556
- return undefined;
1557
- }
1558
- if (scope === "project") {
1559
- return join(this.cwd, CONFIG_DIR_NAME, "git");
1560
- }
1561
- return join(this.agentDir, "git");
1562
- }
1563
- getTemporaryDir(prefix, suffix) {
1564
- const hash = createHash("sha256")
1565
- .update(`${prefix}-${suffix ?? ""}`)
1566
- .digest("hex")
1567
- .slice(0, 8);
1568
- return join(tmpdir(), "aery-extensions", prefix, hash, suffix ?? "");
1569
- }
1570
- getBaseDirForScope(scope) {
1571
- if (scope === "project") {
1572
- return join(this.cwd, CONFIG_DIR_NAME);
1573
- }
1574
- if (scope === "user") {
1575
- return this.agentDir;
1576
- }
1577
- return this.cwd;
1578
- }
1579
- resolvePath(input) {
1580
- const trimmed = input.trim();
1581
- if (trimmed === "~")
1582
- return getHomeDir();
1583
- if (trimmed.startsWith("~/"))
1584
- return join(getHomeDir(), trimmed.slice(2));
1585
- if (trimmed.startsWith("~"))
1586
- return join(getHomeDir(), trimmed.slice(1));
1587
- return resolve(this.cwd, trimmed);
1588
- }
1589
- resolvePathFromBase(input, baseDir) {
1590
- const trimmed = input.trim();
1591
- if (trimmed === "~")
1592
- return getHomeDir();
1593
- if (trimmed.startsWith("~/"))
1594
- return join(getHomeDir(), trimmed.slice(2));
1595
- if (trimmed.startsWith("~"))
1596
- return join(getHomeDir(), trimmed.slice(1));
1597
- return resolve(baseDir, trimmed);
1598
- }
1599
- collectPackageResources(packageRoot, accumulator, filter, metadata) {
1600
- if (filter) {
1601
- for (const resourceType of RESOURCE_TYPES) {
1602
- const patterns = filter[resourceType];
1603
- const target = this.getTargetMap(accumulator, resourceType);
1604
- if (patterns !== undefined) {
1605
- this.applyPackageFilter(packageRoot, patterns, resourceType, target, metadata);
1606
- }
1607
- else {
1608
- this.collectDefaultResources(packageRoot, resourceType, target, metadata);
1609
- }
1610
- }
1611
- return true;
1612
- }
1613
- const manifest = this.readPiManifest(packageRoot);
1614
- if (manifest) {
1615
- for (const resourceType of RESOURCE_TYPES) {
1616
- const entries = manifest[resourceType];
1617
- this.addManifestEntries(entries, packageRoot, resourceType, this.getTargetMap(accumulator, resourceType), metadata);
1618
- }
1619
- return true;
1620
- }
1621
- let hasAnyDir = false;
1622
- for (const resourceType of RESOURCE_TYPES) {
1623
- const dir = join(packageRoot, resourceType);
1624
- if (existsSync(dir)) {
1625
- // Collect all files from the directory (all enabled by default)
1626
- const files = collectResourceFiles(dir, resourceType);
1627
- for (const f of files) {
1628
- this.addResource(this.getTargetMap(accumulator, resourceType), f, metadata, true);
1629
- }
1630
- hasAnyDir = true;
1631
- }
1632
- }
1633
- return hasAnyDir;
1634
- }
1635
- collectDefaultResources(packageRoot, resourceType, target, metadata) {
1636
- const manifest = this.readPiManifest(packageRoot);
1637
- const entries = manifest?.[resourceType];
1638
- if (entries) {
1639
- this.addManifestEntries(entries, packageRoot, resourceType, target, metadata);
1640
- return;
1641
- }
1642
- const dir = join(packageRoot, resourceType);
1643
- if (existsSync(dir)) {
1644
- // Collect all files from the directory (all enabled by default)
1645
- const files = collectResourceFiles(dir, resourceType);
1646
- for (const f of files) {
1647
- this.addResource(target, f, metadata, true);
1648
- }
1649
- }
1650
- }
1651
- applyPackageFilter(packageRoot, userPatterns, resourceType, target, metadata) {
1652
- const { allFiles } = this.collectManifestFiles(packageRoot, resourceType);
1653
- if (userPatterns.length === 0) {
1654
- // Empty array explicitly disables all resources of this type
1655
- for (const f of allFiles) {
1656
- this.addResource(target, f, metadata, false);
1657
- }
1658
- return;
1659
- }
1660
- // Apply user patterns
1661
- const enabledByUser = applyPatterns(allFiles, userPatterns, packageRoot);
1662
- for (const f of allFiles) {
1663
- const enabled = enabledByUser.has(f);
1664
- this.addResource(target, f, metadata, enabled);
1665
- }
1666
- }
1667
- /**
1668
- * Collect all files from a package for a resource type, applying manifest patterns.
1669
- * Returns { allFiles, enabledByManifest } where enabledByManifest is the set of files
1670
- * that pass the manifest's own patterns.
1671
- */
1672
- collectManifestFiles(packageRoot, resourceType) {
1673
- const manifest = this.readPiManifest(packageRoot);
1674
- const entries = manifest?.[resourceType];
1675
- if (entries && entries.length > 0) {
1676
- const allFiles = this.collectFilesFromManifestEntries(entries, packageRoot, resourceType);
1677
- const manifestPatterns = entries.filter(isOverridePattern);
1678
- const enabledByManifest = manifestPatterns.length > 0 ? applyPatterns(allFiles, manifestPatterns, packageRoot) : new Set(allFiles);
1679
- return { allFiles: Array.from(enabledByManifest), enabledByManifest };
1680
- }
1681
- const conventionDir = join(packageRoot, resourceType);
1682
- if (!existsSync(conventionDir)) {
1683
- return { allFiles: [], enabledByManifest: new Set() };
1684
- }
1685
- const allFiles = collectResourceFiles(conventionDir, resourceType);
1686
- return { allFiles, enabledByManifest: new Set(allFiles) };
1687
- }
1688
- readPiManifest(packageRoot) {
1689
- const packageJsonPath = join(packageRoot, "package.json");
1690
- if (!existsSync(packageJsonPath)) {
1691
- return null;
1692
- }
1693
- try {
1694
- const content = readFileSync(packageJsonPath, "utf-8");
1695
- const pkg = JSON.parse(content);
1696
- return pkg.aery ?? pkg.pi ?? null;
1697
- }
1698
- catch {
1699
- return null;
1700
- }
1701
- }
1702
- addManifestEntries(entries, root, resourceType, target, metadata) {
1703
- if (!entries)
1704
- return;
1705
- const allFiles = this.collectFilesFromManifestEntries(entries, root, resourceType);
1706
- const patterns = entries.filter(isOverridePattern);
1707
- const enabledPaths = applyPatterns(allFiles, patterns, root);
1708
- for (const f of allFiles) {
1709
- if (enabledPaths.has(f)) {
1710
- this.addResource(target, f, metadata, true);
1711
- }
1712
- }
1713
- }
1714
- collectFilesFromManifestEntries(entries, root, resourceType) {
1715
- const sourceEntries = entries.filter((entry) => !isOverridePattern(entry));
1716
- const resolved = sourceEntries.flatMap((entry) => {
1717
- if (!hasGlobPattern(entry)) {
1718
- return [resolve(root, entry)];
1719
- }
1720
- return globSync(entry, {
1721
- cwd: root,
1722
- absolute: true,
1723
- dot: false,
1724
- nodir: false,
1725
- }).map((match) => resolve(match));
1726
- });
1727
- return this.collectFilesFromPaths(resolved, resourceType);
1728
- }
1729
- resolveLocalEntries(entries, resourceType, target, metadata, baseDir) {
1730
- if (entries.length === 0)
1731
- return;
1732
- // Collect all files from plain entries (non-pattern entries)
1733
- const { plain, patterns } = splitPatterns(entries);
1734
- const resolvedPlain = plain.map((p) => this.resolvePathFromBase(p, baseDir));
1735
- const allFiles = this.collectFilesFromPaths(resolvedPlain, resourceType);
1736
- // Determine which files are enabled based on patterns
1737
- const enabledPaths = applyPatterns(allFiles, patterns, baseDir);
1738
- // Add all files with their enabled state
1739
- for (const f of allFiles) {
1740
- this.addResource(target, f, metadata, enabledPaths.has(f));
1741
- }
1742
- }
1743
- addAutoDiscoveredResources(accumulator, globalSettings, projectSettings, globalBaseDir, projectBaseDir) {
1744
- const userMetadata = {
1745
- source: "auto",
1746
- scope: "user",
1747
- origin: "top-level",
1748
- baseDir: globalBaseDir,
1749
- };
1750
- const projectMetadata = {
1751
- source: "auto",
1752
- scope: "project",
1753
- origin: "top-level",
1754
- baseDir: projectBaseDir,
1755
- };
1756
- const userOverrides = {
1757
- extensions: (globalSettings.extensions ?? []),
1758
- skills: (globalSettings.skills ?? []),
1759
- prompts: (globalSettings.prompts ?? []),
1760
- themes: (globalSettings.themes ?? []),
1761
- };
1762
- const projectOverrides = {
1763
- extensions: (projectSettings.extensions ?? []),
1764
- skills: (projectSettings.skills ?? []),
1765
- prompts: (projectSettings.prompts ?? []),
1766
- themes: (projectSettings.themes ?? []),
1767
- };
1768
- const userDirs = {
1769
- extensions: join(globalBaseDir, "extensions"),
1770
- skills: join(globalBaseDir, "skills"),
1771
- prompts: join(globalBaseDir, "prompts"),
1772
- themes: join(globalBaseDir, "themes"),
1773
- };
1774
- const projectDirs = {
1775
- extensions: join(projectBaseDir, "extensions"),
1776
- skills: join(projectBaseDir, "skills"),
1777
- prompts: join(projectBaseDir, "prompts"),
1778
- themes: join(projectBaseDir, "themes"),
1779
- };
1780
- const userAgentsSkillsDir = join(getHomeDir(), ".agents", "skills");
1781
- const projectAgentsSkillDirs = collectAncestorAgentsSkillDirs(this.cwd).filter((dir) => resolve(dir) !== resolve(userAgentsSkillsDir));
1782
- const addResources = (resourceType, paths, metadata, overrides, baseDir) => {
1783
- const target = this.getTargetMap(accumulator, resourceType);
1784
- for (const path of paths) {
1785
- const enabled = isEnabledByOverrides(path, overrides, baseDir);
1786
- this.addResource(target, path, metadata, enabled);
1787
- }
1788
- };
1789
- addResources("extensions", collectAutoExtensionEntries(projectDirs.extensions), projectMetadata, projectOverrides.extensions, projectBaseDir);
1790
- addResources("skills", [
1791
- ...collectAutoSkillEntries(projectDirs.skills, "aery"),
1792
- ...projectAgentsSkillDirs.flatMap((dir) => collectAutoSkillEntries(dir, "agents")),
1793
- ], projectMetadata, projectOverrides.skills, projectBaseDir);
1794
- addResources("prompts", collectAutoPromptEntries(projectDirs.prompts), projectMetadata, projectOverrides.prompts, projectBaseDir);
1795
- addResources("themes", collectAutoThemeEntries(projectDirs.themes), projectMetadata, projectOverrides.themes, projectBaseDir);
1796
- addResources("extensions", collectAutoExtensionEntries(userDirs.extensions), userMetadata, userOverrides.extensions, globalBaseDir);
1797
- addResources("skills", [
1798
- ...collectAutoSkillEntries(userDirs.skills, "aery"),
1799
- ...collectAutoSkillEntries(userAgentsSkillsDir, "agents"),
1800
- ], userMetadata, userOverrides.skills, globalBaseDir);
1801
- addResources("prompts", collectAutoPromptEntries(userDirs.prompts), userMetadata, userOverrides.prompts, globalBaseDir);
1802
- addResources("themes", collectAutoThemeEntries(userDirs.themes), userMetadata, userOverrides.themes, globalBaseDir);
1803
- }
1804
- collectFilesFromPaths(paths, resourceType) {
1805
- const files = [];
1806
- for (const p of paths) {
1807
- if (!existsSync(p))
1808
- continue;
1809
- try {
1810
- const stats = statSync(p);
1811
- if (stats.isFile()) {
1812
- files.push(p);
1813
- }
1814
- else if (stats.isDirectory()) {
1815
- files.push(...collectResourceFiles(p, resourceType));
1816
- }
1817
- }
1818
- catch {
1819
- // Ignore errors
1820
- }
1821
- }
1822
- return files;
1823
- }
1824
- getTargetMap(accumulator, resourceType) {
1825
- switch (resourceType) {
1826
- case "extensions":
1827
- return accumulator.extensions;
1828
- case "skills":
1829
- return accumulator.skills;
1830
- case "prompts":
1831
- return accumulator.prompts;
1832
- case "themes":
1833
- return accumulator.themes;
1834
- default:
1835
- throw new Error(`Unknown resource type: ${resourceType}`);
1836
- }
1837
- }
1838
- addResource(map, path, metadata, enabled) {
1839
- if (!path)
1840
- return;
1841
- if (!map.has(path)) {
1842
- map.set(path, { metadata, enabled });
1843
- }
1844
- }
1845
- createAccumulator() {
1846
- return {
1847
- extensions: new Map(),
1848
- skills: new Map(),
1849
- prompts: new Map(),
1850
- themes: new Map(),
1851
- };
1852
- }
1853
- toResolvedPaths(accumulator) {
1854
- const mapToResolved = (entries) => {
1855
- const resolved = Array.from(entries.entries()).map(([path, { metadata, enabled }]) => ({
1856
- path,
1857
- enabled,
1858
- metadata,
1859
- }));
1860
- resolved.sort((a, b) => resourcePrecedenceRank(a.metadata) - resourcePrecedenceRank(b.metadata));
1861
- const seen = new Set();
1862
- return resolved.filter((entry) => {
1863
- const canonicalPath = canonicalizePath(entry.path);
1864
- if (seen.has(canonicalPath))
1865
- return false;
1866
- seen.add(canonicalPath);
1867
- return true;
1868
- });
1869
- };
1870
- return {
1871
- extensions: mapToResolved(accumulator.extensions),
1872
- skills: mapToResolved(accumulator.skills),
1873
- prompts: mapToResolved(accumulator.prompts),
1874
- themes: mapToResolved(accumulator.themes),
1875
- };
1876
- }
1877
- shouldUseWindowsShell(command) {
1878
- if (process.platform !== "win32") {
1879
- return false;
1880
- }
1881
- const commandName = basename(command).toLowerCase();
1882
- return (commandName === "npm" ||
1883
- commandName === "npx" ||
1884
- commandName === "pnpm" ||
1885
- commandName === "yarn" ||
1886
- commandName === "yarnpkg" ||
1887
- commandName === "corepack" ||
1888
- commandName.endsWith(".cmd") ||
1889
- commandName.endsWith(".bat"));
1890
- }
1891
- spawnCommand(command, args, options) {
1892
- return spawn(command, args, {
1893
- cwd: options?.cwd,
1894
- stdio: isStdoutTakenOver() ? ["ignore", 2, 2] : "inherit",
1895
- shell: this.shouldUseWindowsShell(command),
1896
- env: getEnv(),
1897
- });
1898
- }
1899
- spawnCaptureCommand(command, args, options) {
1900
- const baseEnv = getEnv();
1901
- return spawn(command, args, {
1902
- cwd: options?.cwd,
1903
- stdio: ["ignore", "pipe", "pipe"],
1904
- shell: this.shouldUseWindowsShell(command),
1905
- env: options?.env ? { ...baseEnv, ...options.env } : baseEnv,
1906
- });
1907
- }
1908
- runCommandCapture(command, args, options) {
1909
- return new Promise((resolvePromise, reject) => {
1910
- const child = this.spawnCaptureCommand(command, args, options);
1911
- let stdout = "";
1912
- let stderr = "";
1913
- let timedOut = false;
1914
- const timeout = typeof options?.timeoutMs === "number"
1915
- ? setTimeout(() => {
1916
- timedOut = true;
1917
- child.kill();
1918
- }, options.timeoutMs)
1919
- : undefined;
1920
- child.stdout?.on("data", (data) => {
1921
- stdout += data.toString();
1922
- });
1923
- child.stderr?.on("data", (data) => {
1924
- stderr += data.toString();
1925
- });
1926
- child.once("error", (error) => {
1927
- if (timeout)
1928
- clearTimeout(timeout);
1929
- reject(error);
1930
- });
1931
- child.once("close", (code, signal) => {
1932
- if (timeout)
1933
- clearTimeout(timeout);
1934
- if (timedOut) {
1935
- reject(new Error(`${command} ${args.join(" ")} timed out after ${options?.timeoutMs}ms`));
1936
- return;
1937
- }
1938
- if (code === 0) {
1939
- resolvePromise(stdout.trim());
1940
- return;
1941
- }
1942
- const exitStatus = code === null ? `signal ${signal ?? "unknown"}` : `code ${code}`;
1943
- reject(new Error(`${command} ${args.join(" ")} failed with ${exitStatus}: ${stderr || stdout}`));
1944
- });
1945
- });
1946
- }
1947
- runCommand(command, args, options) {
1948
- return new Promise((resolvePromise, reject) => {
1949
- const child = this.spawnCommand(command, args, options);
1950
- child.on("error", reject);
1951
- child.on("exit", (code) => {
1952
- if (code === 0) {
1953
- resolvePromise();
1954
- }
1955
- else {
1956
- reject(new Error(`${command} ${args.join(" ")} failed with code ${code}`));
1957
- }
1958
- });
1959
- });
1960
- }
1961
- runCommandSync(command, args) {
1962
- const result = spawnSync(command, args, {
1963
- stdio: ["ignore", "pipe", "pipe"],
1964
- encoding: "utf-8",
1965
- shell: this.shouldUseWindowsShell(command),
1966
- env: getEnv(),
1967
- });
1968
- if (result.error || result.status !== 0) {
1969
- throw new Error(`Failed to run ${command} ${args.join(" ")}: ${result.error?.message || result.stderr || result.stdout}`);
1970
- }
1971
- return (result.stdout || result.stderr || "").trim();
1972
- }
1973
- }
1974
- //# sourceMappingURL=package-manager.js.map