dal-code 1.0.24 → 1.0.26

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 (591) hide show
  1. package/CHANGELOG.md +42 -0
  2. package/NOTICE +7 -0
  3. package/dal-docs/README.md +109 -0
  4. package/dal-docs/extensions.md +98 -0
  5. package/dal-docs/keybindings.md +40 -0
  6. package/dal-docs/packages.md +62 -0
  7. package/dal-docs/prompt-templates.md +42 -0
  8. package/dal-docs/settings.md +86 -0
  9. package/dal-docs/skills.md +65 -0
  10. package/dal-docs/themes.md +44 -0
  11. package/dist/cli/args.d.ts +59 -0
  12. package/dist/cli/args.js +14 -14
  13. package/dist/config.d.ts +63 -0
  14. package/dist/config.js +1 -1
  15. package/dist/core/agent-session-runtime.d.ts +74 -0
  16. package/dist/core/agent-session-services.d.ts +50 -0
  17. package/dist/core/agent-session-services.js +1 -1
  18. package/dist/core/agent-session.d.ts +422 -0
  19. package/dist/core/agent-session.js +8 -7
  20. package/dist/core/auth-storage.d.ts +56 -0
  21. package/dist/core/background-processes.d.ts +73 -0
  22. package/dist/core/background-processes.js +7 -0
  23. package/dist/core/bash-executor.d.ts +13 -0
  24. package/dist/core/cache-warmer.d.ts +60 -0
  25. package/dist/core/compaction/branch-summarization.d.ts +43 -0
  26. package/dist/core/compaction/compaction.d.ts +62 -0
  27. package/dist/core/compaction/index.d.ts +3 -0
  28. package/dist/core/compaction/utils.d.ts +16 -0
  29. package/dist/core/diagnostics.d.ts +14 -0
  30. package/dist/core/event-bus.d.ts +8 -0
  31. package/dist/core/exec.d.ts +12 -0
  32. package/dist/core/extensions/index.d.ts +8 -0
  33. package/dist/core/extensions/loader.d.ts +13 -0
  34. package/dist/core/extensions/loader.js +1 -1
  35. package/dist/core/extensions/permission-surface.js +1 -1
  36. package/dist/core/extensions/runner.d.ts +165 -0
  37. package/dist/core/extensions/runner.js +1 -1
  38. package/dist/core/extensions/types.d.ts +1003 -0
  39. package/dist/core/extensions/wrapper.d.ts +5 -0
  40. package/dist/core/footer-data-provider.d.ts +46 -0
  41. package/dist/core/host-capabilities.d.ts +50 -0
  42. package/dist/core/host-capabilities.js +2 -0
  43. package/dist/core/keybindings.d.ts +525 -0
  44. package/dist/core/messages.d.ts +50 -0
  45. package/dist/core/model-config.d.ts +1212 -0
  46. package/dist/core/model-registry.d.ts +41 -0
  47. package/dist/core/model-resolver.d.ts +67 -0
  48. package/dist/core/model-resolver.js +1 -1
  49. package/dist/core/model-runtime.d.ts +101 -0
  50. package/dist/core/model-runtime.js +2 -2
  51. package/dist/core/package-manager.d.ts +213 -0
  52. package/dist/core/package-manager.js +2 -2
  53. package/dist/core/permissions/rules.d.ts +45 -0
  54. package/dist/core/permissions/rules.js +1 -0
  55. package/dist/core/permissions/shell-words.js +2 -0
  56. package/dist/core/permissions/tool-policy.d.ts +46 -0
  57. package/dist/core/permissions/tool-policy.js +1 -0
  58. package/dist/core/project-map.d.ts +18 -0
  59. package/dist/core/prompt-templates.d.ts +24 -0
  60. package/dist/core/provider-composer.d.ts +55 -0
  61. package/dist/core/remote-catalog-provider.js +1 -1
  62. package/dist/core/resolve-config-value.d.ts +11 -0
  63. package/dist/core/resource-loader.d.ts +220 -0
  64. package/dist/core/resource-loader.js +1 -1
  65. package/dist/core/sandbox/availability.d.ts +9 -0
  66. package/dist/core/sandbox/availability.js +1 -0
  67. package/dist/core/sandbox/denial.d.ts +25 -0
  68. package/dist/core/sandbox/denial.js +3 -0
  69. package/dist/core/sandbox/index.d.ts +5 -0
  70. package/dist/core/sandbox/index.js +1 -0
  71. package/dist/core/sandbox/policy.d.ts +66 -0
  72. package/dist/core/sandbox/policy.js +1 -0
  73. package/dist/core/sandbox/runtime.d.ts +31 -0
  74. package/dist/core/sandbox/runtime.js +1 -0
  75. package/dist/core/sandbox/shell-sandbox.d.ts +119 -0
  76. package/dist/core/sandbox/shell-sandbox.js +5 -0
  77. package/dist/core/sdk.d.ts +43 -0
  78. package/dist/core/sdk.js +1 -1
  79. package/dist/core/session-manager.d.ts +208 -0
  80. package/dist/core/settings-manager.d.ts +368 -0
  81. package/dist/core/settings-manager.js +1 -1
  82. package/dist/core/skills.d.ts +33 -0
  83. package/dist/core/slash-commands.d.ts +14 -0
  84. package/dist/core/source-info.d.ts +17 -0
  85. package/dist/core/system-prompt.d.ts +39 -0
  86. package/dist/core/system-prompt.js +15 -11
  87. package/dist/core/tools/bash.d.ts +89 -0
  88. package/dist/core/tools/bash.js +16 -14
  89. package/dist/core/tools/edit-diff.d.ts +44 -0
  90. package/dist/core/tools/edit.d.ts +48 -0
  91. package/dist/core/tools/file-mutation-queue.d.ts +1 -0
  92. package/dist/core/tools/find.d.ts +34 -0
  93. package/dist/core/tools/find.js +11 -11
  94. package/dist/core/tools/grep.d.ts +34 -0
  95. package/dist/core/tools/grep.js +10 -10
  96. package/dist/core/tools/index.d.ts +43 -0
  97. package/dist/core/tools/index.js +1 -1
  98. package/dist/core/tools/ls.d.ts +33 -0
  99. package/dist/core/tools/ls.js +6 -6
  100. package/dist/core/tools/powershell.d.ts +17 -0
  101. package/dist/core/tools/powershell.js +2 -2
  102. package/dist/core/tools/process.d.ts +26 -0
  103. package/dist/core/tools/process.js +22 -0
  104. package/dist/core/tools/read.d.ts +33 -0
  105. package/dist/core/tools/read.js +15 -15
  106. package/dist/core/tools/renderers/bash.d.ts +3 -0
  107. package/dist/core/tools/renderers/edit.d.ts +15 -0
  108. package/dist/core/tools/renderers/find.d.ts +2 -0
  109. package/dist/core/tools/renderers/grep.d.ts +2 -0
  110. package/dist/core/tools/renderers/index.d.ts +13 -0
  111. package/dist/core/tools/renderers/ls.d.ts +2 -0
  112. package/dist/core/tools/renderers/read.d.ts +3 -0
  113. package/dist/core/tools/renderers/read.js +8 -8
  114. package/dist/core/tools/renderers/write.d.ts +2 -0
  115. package/dist/core/tools/truncate.d.ts +27 -0
  116. package/dist/core/tools/write.d.ts +24 -0
  117. package/dist/core/trust-manager.d.ts +28 -0
  118. package/dist/core/trust-manager.js +2 -2
  119. package/dist/dal/builtins.js +2 -2
  120. package/dist/dal/child-env.d.ts +12 -0
  121. package/dist/dal/child-env.js +1 -0
  122. package/dist/dal/hooks/activity.d.ts +17 -0
  123. package/dist/dal/hooks/activity.js +1 -0
  124. package/dist/dal/hooks/config.d.ts +47 -0
  125. package/dist/dal/hooks/config.js +1 -0
  126. package/dist/dal/hooks/events.d.ts +43 -0
  127. package/dist/dal/hooks/events.js +4 -0
  128. package/dist/dal/hooks/extension.d.ts +3 -0
  129. package/dist/dal/hooks/extension.js +4 -0
  130. package/dist/dal/hooks/index.d.ts +5 -0
  131. package/dist/dal/hooks/index.js +1 -0
  132. package/dist/dal/hooks/runner.d.ts +57 -0
  133. package/dist/dal/hooks/runner.js +1 -0
  134. package/dist/dal/manifest.d.ts +32 -0
  135. package/dist/dal/manifest.js +1 -0
  136. package/dist/dal/safety-net.js +1 -0
  137. package/dist/index.d.ts +44 -0
  138. package/dist/index.js +1 -1
  139. package/dist/main.d.ts +9 -0
  140. package/dist/main.js +4 -4
  141. package/dist/modes/acp/acp-mode.d.ts +2 -0
  142. package/dist/modes/index.d.ts +7 -0
  143. package/dist/modes/interactive/components/armin.d.ts +30 -0
  144. package/dist/modes/interactive/components/assistant-message.d.ts +26 -0
  145. package/dist/modes/interactive/components/bash-execution.d.ts +22 -0
  146. package/dist/modes/interactive/components/bordered-loader.d.ts +14 -0
  147. package/dist/modes/interactive/components/branch-summary-message.d.ts +11 -0
  148. package/dist/modes/interactive/components/compaction-summary-message.d.ts +11 -0
  149. package/dist/modes/interactive/components/config-selector.js +1 -1
  150. package/dist/modes/interactive/components/custom-editor.d.ts +21 -0
  151. package/dist/modes/interactive/components/custom-message.d.ts +17 -0
  152. package/dist/modes/interactive/components/daxnuts.d.ts +17 -0
  153. package/dist/modes/interactive/components/diff.d.ts +4 -0
  154. package/dist/modes/interactive/components/dynamic-border.d.ts +12 -0
  155. package/dist/modes/interactive/components/extension-editor.d.ts +19 -0
  156. package/dist/modes/interactive/components/extension-input.d.ts +21 -0
  157. package/dist/modes/interactive/components/extension-selector.d.ts +22 -0
  158. package/dist/modes/interactive/components/first-time-setup.d.ts +23 -0
  159. package/dist/modes/interactive/components/footer.d.ts +18 -0
  160. package/dist/modes/interactive/components/footer.js +1 -1
  161. package/dist/modes/interactive/components/index.d.ts +33 -0
  162. package/dist/modes/interactive/components/keybinding-hints.d.ts +9 -0
  163. package/dist/modes/interactive/components/login-dialog.d.ts +27 -0
  164. package/dist/modes/interactive/components/model-selector.d.ts +81 -0
  165. package/dist/modes/interactive/components/oauth-selector.d.ts +29 -0
  166. package/dist/modes/interactive/components/scoped-models-selector.d.ts +39 -0
  167. package/dist/modes/interactive/components/session-selector-search.d.ts +20 -0
  168. package/dist/modes/interactive/components/session-selector.d.ts +88 -0
  169. package/dist/modes/interactive/components/settings-selector.d.ts +92 -0
  170. package/dist/modes/interactive/components/show-images-selector.d.ts +6 -0
  171. package/dist/modes/interactive/components/skill-invocation-message.d.ts +11 -0
  172. package/dist/modes/interactive/components/status-indicator.d.ts +44 -0
  173. package/dist/modes/interactive/components/theme-selector.d.ts +7 -0
  174. package/dist/modes/interactive/components/thinking-selector.d.ts +19 -0
  175. package/dist/modes/interactive/components/tool-execution.d.ts +76 -0
  176. package/dist/modes/interactive/components/tree-selector.d.ts +65 -0
  177. package/dist/modes/interactive/components/trust-selector.d.ts +22 -0
  178. package/dist/modes/interactive/components/user-message-selector.d.ts +23 -0
  179. package/dist/modes/interactive/components/user-message.d.ts +14 -0
  180. package/dist/modes/interactive/components/visual-truncate.d.ts +5 -0
  181. package/dist/modes/interactive/interactive-mode.d.ts +326 -0
  182. package/dist/modes/interactive/theme/theme-json.d.ts +257 -0
  183. package/dist/modes/interactive/theme/theme.d.ts +106 -0
  184. package/dist/modes/interactive/tui-renderer.d.ts +18 -0
  185. package/dist/modes/json-event.d.ts +26 -0
  186. package/dist/modes/print-mode.d.ts +9 -0
  187. package/dist/modes/print-mode.js +6 -4
  188. package/dist/modes/rpc/rpc-client.d.ts +142 -0
  189. package/dist/modes/rpc/rpc-client.js +4 -1
  190. package/dist/modes/rpc/rpc-mode.d.ts +3 -0
  191. package/dist/modes/rpc/rpc-mode.js +1 -1
  192. package/dist/modes/rpc/rpc-types.d.ts +565 -0
  193. package/dist/node_modules/@dalcode/dal-bridge/package.json +2 -2
  194. package/dist/node_modules/@dalcode/dal-bridge/src/ask-user.js +12 -0
  195. package/dist/node_modules/@dalcode/dal-bridge/src/client.js +1 -1
  196. package/dist/node_modules/@dalcode/dal-bridge/src/index.js +1 -1
  197. package/dist/node_modules/@dalcode/dal-gateway/package.json +2 -2
  198. package/dist/node_modules/@dalcode/dal-gateway/src/index.js +1 -1
  199. package/dist/node_modules/@dalcode/dal-guard/package.json +5 -4
  200. package/dist/node_modules/@dalcode/dal-guard/src/hooks.js +1 -0
  201. package/dist/node_modules/@dalcode/dal-guard/src/index.js +1 -1
  202. package/dist/node_modules/@dalcode/dal-halo/package.json +1 -1
  203. package/dist/node_modules/@dalcode/dal-interactive/LICENSE +21 -0
  204. package/dist/node_modules/@dalcode/dal-interactive/package.json +33 -0
  205. package/dist/node_modules/@dalcode/dal-interactive/src/handoff.js +28 -0
  206. package/dist/node_modules/@dalcode/dal-interactive/src/index.js +1 -0
  207. package/dist/node_modules/@dalcode/dal-interactive/src/interactive-shell.js +1 -0
  208. package/dist/node_modules/@dalcode/dal-interactive/src/questionnaire.js +3 -0
  209. package/dist/node_modules/@dalcode/dal-lang/package.json +3 -3
  210. package/dist/node_modules/@dalcode/dal-lsp/package.json +3 -3
  211. package/dist/node_modules/@dalcode/dal-lsp/src/client.js +3 -3
  212. package/dist/node_modules/@dalcode/dal-mcp/package.json +5 -5
  213. package/dist/node_modules/@dalcode/dal-mcp/src/command-parser.d.ts +19 -0
  214. package/dist/node_modules/@dalcode/dal-mcp/src/config-edit.d.ts +19 -0
  215. package/dist/node_modules/@dalcode/dal-mcp/src/config.d.ts +9 -0
  216. package/dist/node_modules/@dalcode/dal-mcp/src/http-client.d.ts +16 -0
  217. package/dist/node_modules/@dalcode/dal-mcp/src/stdio-client.d.ts +22 -0
  218. package/dist/node_modules/@dalcode/dal-mcp/src/stdio-client.js +2 -2
  219. package/dist/node_modules/@dalcode/dal-mcp/src/types.d.ts +30 -0
  220. package/dist/node_modules/@dalcode/dal-office/package.json +2 -2
  221. package/dist/node_modules/@dalcode/dal-office/src/extract/csv.d.ts +3 -0
  222. package/dist/node_modules/@dalcode/dal-office/src/extract/csv.js +1 -1
  223. package/dist/node_modules/@dalcode/dal-office/src/extract/ooxml.js +1 -1
  224. package/dist/node_modules/@dalcode/dal-office/src/index.d.ts +11 -0
  225. package/dist/node_modules/@dalcode/dal-office/src/index.js +1 -1
  226. package/dist/node_modules/@dalcode/dal-office/src/paths.d.ts +3 -0
  227. package/dist/node_modules/@dalcode/dal-office/src/render/chart.js +1 -1
  228. package/dist/node_modules/@dalcode/dal-office/src/render/docx.d.ts +19 -0
  229. package/dist/node_modules/@dalcode/dal-office/src/render/pptx.d.ts +40 -0
  230. package/dist/node_modules/@dalcode/dal-office/src/render/pptx.js +2 -2
  231. package/dist/node_modules/@dalcode/dal-office/src/render/thumbnails.d.ts +19 -0
  232. package/dist/node_modules/@dalcode/dal-office/src/render/thumbnails.js +1 -0
  233. package/dist/node_modules/@dalcode/dal-office/src/render/xlsx.d.ts +14 -0
  234. package/dist/node_modules/@dalcode/dal-office/src/scratchpad.d.ts +16 -0
  235. package/dist/node_modules/@dalcode/dal-office/src/themes.d.ts +13 -0
  236. package/dist/node_modules/@dalcode/dal-office/src/tools/docx-edit.js +10 -0
  237. package/dist/node_modules/@dalcode/dal-office/src/tools/edit-shared.js +1 -0
  238. package/dist/node_modules/@dalcode/dal-office/src/tools/pptx-edit.js +9 -0
  239. package/dist/node_modules/@dalcode/dal-office/src/tools/read-file.js +4 -2
  240. package/dist/node_modules/@dalcode/dal-office/src/tools/xlsx-edit.js +5 -0
  241. package/dist/node_modules/@dalcode/dal-pi-kit/dist/i18n.js +2 -2
  242. package/dist/node_modules/@dalcode/dal-pi-kit/package.json +1 -1
  243. package/dist/node_modules/@dalcode/dal-pi-kit/src/i18n.js +2 -2
  244. package/dist/node_modules/@dalcode/dal-plugins/package.json +2 -2
  245. package/dist/node_modules/@dalcode/dal-review/LICENSE +21 -0
  246. package/dist/node_modules/@dalcode/dal-review/package.json +34 -0
  247. package/dist/node_modules/@dalcode/dal-review/src/args.d.ts +13 -0
  248. package/dist/node_modules/@dalcode/dal-review/src/args.js +1 -0
  249. package/dist/node_modules/@dalcode/dal-review/src/core.d.ts +6 -0
  250. package/dist/node_modules/@dalcode/dal-review/src/core.js +1 -0
  251. package/dist/node_modules/@dalcode/dal-review/src/findings.d.ts +23 -0
  252. package/dist/node_modules/@dalcode/dal-review/src/findings.js +4 -0
  253. package/dist/node_modules/@dalcode/dal-review/src/index.js +1 -0
  254. package/dist/node_modules/@dalcode/dal-review/src/prompt.d.ts +3 -0
  255. package/dist/node_modules/@dalcode/dal-review/src/prompt.js +29 -0
  256. package/dist/node_modules/@dalcode/dal-review/src/runner.d.ts +91 -0
  257. package/dist/node_modules/@dalcode/dal-review/src/runner.js +2 -0
  258. package/dist/node_modules/@dalcode/dal-review/src/targets.d.ts +33 -0
  259. package/dist/node_modules/@dalcode/dal-review/src/targets.js +17 -0
  260. package/dist/node_modules/@dalcode/dal-review/src/types.d.ts +94 -0
  261. package/dist/node_modules/@dalcode/dal-review/src/types.js +1 -0
  262. package/dist/node_modules/@dalcode/dal-rewind/package.json +2 -2
  263. package/dist/node_modules/@dalcode/dal-rewind/src/core.d.ts +61 -0
  264. package/dist/node_modules/@dalcode/dal-router/package.json +4 -4
  265. package/dist/node_modules/@dalcode/dal-router/src/config.d.ts +50 -0
  266. package/dist/node_modules/@dalcode/dal-router/src/jev.d.ts +51 -0
  267. package/dist/node_modules/@dalcode/dal-router/src/pool.d.ts +6 -0
  268. package/dist/node_modules/@dalcode/dal-router/src/router.d.ts +32 -0
  269. package/dist/node_modules/@dalcode/dal-router/src/runtime.d.ts +37 -0
  270. package/dist/node_modules/@dalcode/dal-skills/package.json +3 -3
  271. package/dist/node_modules/@dalcode/dal-skills/src/discover.js +4 -4
  272. package/dist/node_modules/@dalcode/dal-skills/src/index.js +9 -9
  273. package/dist/node_modules/@dalcode/dal-subagent/package.json +5 -5
  274. package/dist/node_modules/@dalcode/dal-subagent/src/agents.js +2 -2
  275. package/dist/node_modules/@dalcode/dal-subagent/src/index.js +12 -12
  276. package/dist/node_modules/@dalcode/dal-subagent/src/process-runner.js +3 -3
  277. package/dist/node_modules/@dalcode/dal-telemetry/package.json +2 -2
  278. package/dist/node_modules/@dalcode/dal-terminal/LICENSE +21 -0
  279. package/dist/node_modules/@dalcode/dal-terminal/package.json +33 -0
  280. package/dist/node_modules/@dalcode/dal-terminal/src/contract.d.ts +60 -0
  281. package/dist/node_modules/@dalcode/dal-terminal/src/contract.js +7 -0
  282. package/dist/node_modules/@dalcode/dal-terminal/src/index.js +6 -0
  283. package/dist/node_modules/@dalcode/dal-tool-catalog/package.json +2 -2
  284. package/dist/node_modules/@dalcode/dal-tool-catalog/src/groups.js +1 -1
  285. package/dist/node_modules/@dalcode/dal-web/package.json +3 -3
  286. package/dist/node_modules/@dalcode/dal-web/src/config.js +2 -2
  287. package/dist/node_modules/@dalcode/dal-web/src/index.js +4 -4
  288. package/dist/node_modules/@dalcode/dal-web/src/search.js +4 -4
  289. package/dist/node_modules/@dalcode/dal-workflow/package.json +2 -2
  290. package/dist/node_modules/@dalcode/dal-workflow/src/index.js +4 -4
  291. package/dist/node_modules/@dalcode/dal-workflow/src/plan-mode.js +13 -13
  292. package/dist/node_modules/@dalcode/deepailab/package.json +3 -3
  293. package/dist/node_modules/@dalcode/deepailab/src/index.js +3 -3
  294. package/dist/node_modules/@dalcode/deepailab/src/model-defaults.js +1 -1
  295. package/dist/node_modules/@earendil-works/chord/dist/api.d.ts +21 -0
  296. package/dist/node_modules/@earendil-works/chord/dist/context/index.d.ts +12 -0
  297. package/dist/node_modules/@earendil-works/chord/dist/delta/index.d.ts +127 -0
  298. package/dist/node_modules/@earendil-works/chord/dist/index.d.ts +8 -0
  299. package/dist/node_modules/@earendil-works/chord/dist/json.d.ts +2 -0
  300. package/dist/node_modules/@earendil-works/chord/dist/services/errors.d.ts +16 -0
  301. package/dist/node_modules/@earendil-works/chord/dist/services/provider.d.ts +32 -0
  302. package/dist/node_modules/@earendil-works/chord/dist/services/state-codec.d.ts +12 -0
  303. package/dist/node_modules/@earendil-works/chord/dist/services/wire.d.ts +59 -0
  304. package/dist/node_modules/@earendil-works/chord/dist/state/draft.d.ts +13 -0
  305. package/dist/node_modules/@earendil-works/chord/dist/types.d.ts +188 -0
  306. package/dist/node_modules/@earendil-works/chord/package.json +1 -1
  307. package/dist/node_modules/@earendil-works/pi-agent-core/dist/agent-loop.d.ts +11 -0
  308. package/dist/node_modules/@earendil-works/pi-agent-core/dist/agent-loop.js +1 -1
  309. package/dist/node_modules/@earendil-works/pi-agent-core/dist/agent.d.ts +80 -0
  310. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/agent-harness.d.ts +711 -0
  311. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/compaction/branch-summarization.d.ts +44 -0
  312. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/compaction/compaction.d.ts +80 -0
  313. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/compaction/utils.d.ts +15 -0
  314. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/context.d.ts +6 -0
  315. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/events.d.ts +22 -0
  316. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/execution/effect-gate.d.ts +17 -0
  317. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/hooks.d.ts +34 -0
  318. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/messages.d.ts +50 -0
  319. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/prompt-templates.d.ts +28 -0
  320. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/result.d.ts +132 -0
  321. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/runtime/harness.d.ts +56 -0
  322. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/runtime/lane.d.ts +94 -0
  323. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/runtime/reducer.d.ts +3 -0
  324. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/runtime/types.d.ts +99 -0
  325. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/commit.d.ts +52 -0
  326. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/fork-policy.d.ts +19 -0
  327. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/fork.d.ts +13 -0
  328. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/index.d.ts +10 -0
  329. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl/index.d.ts +3 -0
  330. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl/repo.d.ts +33 -0
  331. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl/storage.d.ts +37 -0
  332. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl/types.d.ts +36 -0
  333. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/memory.d.ts +46 -0
  334. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/mutation-line.d.ts +6 -0
  335. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/session.d.ts +75 -0
  336. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/types.d.ts +473 -0
  337. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/values.d.ts +94 -0
  338. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/skills.d.ts +26 -0
  339. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/system-prompt.d.ts +2 -0
  340. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/telemetry.d.ts +1495 -0
  341. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/tools/bash.d.ts +26 -0
  342. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/tools/edit.d.ts +18 -0
  343. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/tools/index.d.ts +5 -0
  344. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/tools/read.d.ts +32 -0
  345. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/tools/tool-context.d.ts +4 -0
  346. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/tools/write.d.ts +10 -0
  347. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/types.d.ts +185 -0
  348. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/output-capture.d.ts +22 -0
  349. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/shell-output.d.ts +22 -0
  350. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/truncate.d.ts +28 -0
  351. package/dist/node_modules/@earendil-works/pi-agent-core/dist/index.d.ts +27 -0
  352. package/dist/node_modules/@earendil-works/pi-agent-core/dist/proxy.d.ts +61 -0
  353. package/dist/node_modules/@earendil-works/pi-agent-core/dist/search/index.d.ts +28 -0
  354. package/dist/node_modules/@earendil-works/pi-agent-core/dist/stream-fn.d.ts +3 -0
  355. package/dist/node_modules/@earendil-works/pi-agent-core/dist/types.d.ts +150 -0
  356. package/dist/node_modules/@earendil-works/pi-agent-core/package.json +4 -4
  357. package/dist/node_modules/@earendil-works/pi-ai/dist/api/anthropic-messages.d.ts +18 -0
  358. package/dist/node_modules/@earendil-works/pi-ai/dist/api/anthropic-messages.lazy.d.ts +2 -0
  359. package/dist/node_modules/@earendil-works/pi-ai/dist/api/azure-openai-responses.d.ts +13 -0
  360. package/dist/node_modules/@earendil-works/pi-ai/dist/api/azure-openai-responses.lazy.d.ts +2 -0
  361. package/dist/node_modules/@earendil-works/pi-ai/dist/api/bedrock-converse-stream.d.ts +18 -0
  362. package/dist/node_modules/@earendil-works/pi-ai/dist/api/bedrock-converse-stream.lazy.d.ts +3 -0
  363. package/dist/node_modules/@earendil-works/pi-ai/dist/api/google-generative-ai.d.ts +12 -0
  364. package/dist/node_modules/@earendil-works/pi-ai/dist/api/google-generative-ai.lazy.d.ts +2 -0
  365. package/dist/node_modules/@earendil-works/pi-ai/dist/api/google-shared.d.ts +24 -0
  366. package/dist/node_modules/@earendil-works/pi-ai/dist/api/google-vertex.d.ts +14 -0
  367. package/dist/node_modules/@earendil-works/pi-ai/dist/api/google-vertex.lazy.d.ts +2 -0
  368. package/dist/node_modules/@earendil-works/pi-ai/dist/api/lazy.d.ts +8 -0
  369. package/dist/node_modules/@earendil-works/pi-ai/dist/api/mistral-conversations.d.ts +15 -0
  370. package/dist/node_modules/@earendil-works/pi-ai/dist/api/mistral-conversations.lazy.d.ts +2 -0
  371. package/dist/node_modules/@earendil-works/pi-ai/dist/api/openai-codex-responses.d.ts +30 -0
  372. package/dist/node_modules/@earendil-works/pi-ai/dist/api/openai-codex-responses.lazy.d.ts +2 -0
  373. package/dist/node_modules/@earendil-works/pi-ai/dist/api/openai-completions.d.ts +24 -0
  374. package/dist/node_modules/@earendil-works/pi-ai/dist/api/openai-completions.lazy.d.ts +2 -0
  375. package/dist/node_modules/@earendil-works/pi-ai/dist/api/openai-responses.d.ts +10 -0
  376. package/dist/node_modules/@earendil-works/pi-ai/dist/api/openai-responses.lazy.d.ts +2 -0
  377. package/dist/node_modules/@earendil-works/pi-ai/dist/api/pi-messages.d.ts +85 -0
  378. package/dist/node_modules/@earendil-works/pi-ai/dist/api/pi-messages.lazy.d.ts +2 -0
  379. package/dist/node_modules/@earendil-works/pi-ai/dist/auth/context.d.ts +2 -0
  380. package/dist/node_modules/@earendil-works/pi-ai/dist/auth/credential-store.d.ts +10 -0
  381. package/dist/node_modules/@earendil-works/pi-ai/dist/auth/helpers.d.ts +8 -0
  382. package/dist/node_modules/@earendil-works/pi-ai/dist/auth/resolve.d.ts +20 -0
  383. package/dist/node_modules/@earendil-works/pi-ai/dist/auth/types.d.ts +127 -0
  384. package/dist/node_modules/@earendil-works/pi-ai/dist/cli.js +0 -0
  385. package/dist/node_modules/@earendil-works/pi-ai/dist/compat/extension-oauth-types.d.ts +34 -0
  386. package/dist/node_modules/@earendil-works/pi-ai/dist/compat.d.ts +47 -0
  387. package/dist/node_modules/@earendil-works/pi-ai/dist/env-api-keys.d.ts +9 -0
  388. package/dist/node_modules/@earendil-works/pi-ai/dist/image-models.d.ts +9 -0
  389. package/dist/node_modules/@earendil-works/pi-ai/dist/image-models.generated.d.ts +829 -0
  390. package/dist/node_modules/@earendil-works/pi-ai/dist/images-api-registry.d.ts +13 -0
  391. package/dist/node_modules/@earendil-works/pi-ai/dist/images-models.d.ts +37 -0
  392. package/dist/node_modules/@earendil-works/pi-ai/dist/images.d.ts +3 -0
  393. package/dist/node_modules/@earendil-works/pi-ai/dist/index.d.ts +38 -0
  394. package/dist/node_modules/@earendil-works/pi-ai/dist/legacy-api-aliases.d.ts +25 -0
  395. package/dist/node_modules/@earendil-works/pi-ai/dist/model-catalog.d.ts +16 -0
  396. package/dist/node_modules/@earendil-works/pi-ai/dist/models-store.d.ts +21 -0
  397. package/dist/node_modules/@earendil-works/pi-ai/dist/models.d.ts +97 -0
  398. package/dist/node_modules/@earendil-works/pi-ai/dist/models.generated.d.ts +84 -0
  399. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/all.d.ts +18 -0
  400. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/amazon-bedrock.models.d.ts +3 -0
  401. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/ant-ling.models.d.ts +3 -0
  402. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/anthropic.models.d.ts +3 -0
  403. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/azure-openai-responses.models.d.ts +3 -0
  404. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/baseten.models.d.ts +3 -0
  405. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/cerebras.models.d.ts +3 -0
  406. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/cloudflare-ai-gateway.models.d.ts +3 -0
  407. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/cloudflare-workers-ai.models.d.ts +3 -0
  408. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/.manifest.json +1 -1
  409. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/azure-openai-responses.json +1 -1
  410. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/openai.json +1 -1
  411. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/opencode-go.json +1 -1
  412. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/openrouter.json +1 -1
  413. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/radius.json +1 -1
  414. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/deepseek.models.d.ts +3 -0
  415. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/faux.d.ts +100 -0
  416. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/fireworks.models.d.ts +3 -0
  417. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/github-copilot.models.d.ts +3 -0
  418. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/google-vertex.models.d.ts +3 -0
  419. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/google.models.d.ts +3 -0
  420. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/groq.models.d.ts +3 -0
  421. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/huggingface.models.d.ts +3 -0
  422. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/images/register-builtins.d.ts +3 -0
  423. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/kimi-coding.models.d.ts +3 -0
  424. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/meta.models.d.ts +3 -0
  425. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/minimax-cn.models.d.ts +3 -0
  426. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/minimax.models.d.ts +3 -0
  427. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/mistral.models.d.ts +3 -0
  428. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/moonshotai-cn.models.d.ts +3 -0
  429. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/moonshotai.models.d.ts +3 -0
  430. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/nvidia.models.d.ts +3 -0
  431. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/openai-codex.models.d.ts +3 -0
  432. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/openai.models.d.ts +3 -0
  433. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/opencode-go.models.d.ts +3 -0
  434. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/opencode.models.d.ts +3 -0
  435. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/openrouter.models.d.ts +3 -0
  436. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/qwen-token-plan-cn.models.d.ts +3 -0
  437. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/qwen-token-plan-individual.models.d.ts +3 -0
  438. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/qwen-token-plan.models.d.ts +3 -0
  439. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/radius.d.ts +7 -0
  440. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/radius.models.d.ts +3 -0
  441. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/together.models.d.ts +3 -0
  442. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/vercel-ai-gateway.models.d.ts +3 -0
  443. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/xai.models.d.ts +3 -0
  444. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/xiaomi-token-plan-ams.models.d.ts +3 -0
  445. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/xiaomi-token-plan-cn.models.d.ts +3 -0
  446. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/xiaomi-token-plan-sgp.models.d.ts +3 -0
  447. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/xiaomi.models.d.ts +3 -0
  448. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/zai-coding-cn.models.d.ts +3 -0
  449. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/zai.models.d.ts +3 -0
  450. package/dist/node_modules/@earendil-works/pi-ai/dist/session-resources.d.ts +3 -0
  451. package/dist/node_modules/@earendil-works/pi-ai/dist/types.d.ts +502 -0
  452. package/dist/node_modules/@earendil-works/pi-ai/dist/utils/assistant-message-frame.d.ts +63 -0
  453. package/dist/node_modules/@earendil-works/pi-ai/dist/utils/diagnostics.d.ts +19 -0
  454. package/dist/node_modules/@earendil-works/pi-ai/dist/utils/event-stream.d.ts +19 -0
  455. package/dist/node_modules/@earendil-works/pi-ai/dist/utils/json-parse.d.ts +3 -0
  456. package/dist/node_modules/@earendil-works/pi-ai/dist/utils/overflow.d.ts +4 -0
  457. package/dist/node_modules/@earendil-works/pi-ai/dist/utils/retry.d.ts +16 -0
  458. package/dist/node_modules/@earendil-works/pi-ai/dist/utils/text.d.ts +6 -0
  459. package/dist/node_modules/@earendil-works/pi-ai/dist/utils/transcript.d.ts +29 -0
  460. package/dist/node_modules/@earendil-works/pi-ai/dist/utils/typebox-helpers.d.ts +5 -0
  461. package/dist/node_modules/@earendil-works/pi-ai/dist/utils/uuid.d.ts +1 -0
  462. package/dist/node_modules/@earendil-works/pi-ai/dist/utils/validation.d.ts +3 -0
  463. package/dist/node_modules/@earendil-works/pi-ai/package.json +2 -2
  464. package/dist/node_modules/@earendil-works/pi-client/package.json +3 -3
  465. package/dist/node_modules/@earendil-works/pi-coding-agent/LICENSE +21 -0
  466. package/dist/node_modules/@earendil-works/pi-coding-agent/index.d.ts +1 -0
  467. package/dist/node_modules/@earendil-works/pi-coding-agent/index.js +1 -0
  468. package/dist/node_modules/@earendil-works/pi-coding-agent/package.json +15 -0
  469. package/dist/node_modules/@earendil-works/pi-protocol/package.json +2 -2
  470. package/dist/node_modules/@earendil-works/pi-server/package.json +5 -5
  471. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/package.json +3 -3
  472. package/dist/node_modules/@earendil-works/pi-telemetry/dist/index.d.ts +200 -0
  473. package/dist/node_modules/@earendil-works/pi-telemetry/dist/memory.d.ts +20 -0
  474. package/dist/node_modules/@earendil-works/pi-telemetry/dist/noop.d.ts +2 -0
  475. package/dist/node_modules/@earendil-works/pi-telemetry/package.json +1 -1
  476. package/dist/node_modules/@earendil-works/pi-tui/dist/autocomplete.d.ts +55 -0
  477. package/dist/node_modules/@earendil-works/pi-tui/dist/components/box.d.ts +20 -0
  478. package/dist/node_modules/@earendil-works/pi-tui/dist/components/cancellable-loader.d.ts +9 -0
  479. package/dist/node_modules/@earendil-works/pi-tui/dist/components/editor.d.ts +151 -0
  480. package/dist/node_modules/@earendil-works/pi-tui/dist/components/h-stack.d.ts +6 -0
  481. package/dist/node_modules/@earendil-works/pi-tui/dist/components/image.d.ts +25 -0
  482. package/dist/node_modules/@earendil-works/pi-tui/dist/components/input.d.ts +43 -0
  483. package/dist/node_modules/@earendil-works/pi-tui/dist/components/loader.d.ts +28 -0
  484. package/dist/node_modules/@earendil-works/pi-tui/dist/components/markdown.d.ts +61 -0
  485. package/dist/node_modules/@earendil-works/pi-tui/dist/components/mouse-region.d.ts +10 -0
  486. package/dist/node_modules/@earendil-works/pi-tui/dist/components/scroll-view.d.ts +61 -0
  487. package/dist/node_modules/@earendil-works/pi-tui/dist/components/select-list.d.ts +52 -0
  488. package/dist/node_modules/@earendil-works/pi-tui/dist/components/settings-list.d.ts +50 -0
  489. package/dist/node_modules/@earendil-works/pi-tui/dist/components/spacer.d.ts +8 -0
  490. package/dist/node_modules/@earendil-works/pi-tui/dist/components/stack.d.ts +35 -0
  491. package/dist/node_modules/@earendil-works/pi-tui/dist/components/text.d.ts +15 -0
  492. package/dist/node_modules/@earendil-works/pi-tui/dist/components/truncated-text.d.ts +9 -0
  493. package/dist/node_modules/@earendil-works/pi-tui/dist/components/v-stack.d.ts +7 -0
  494. package/dist/node_modules/@earendil-works/pi-tui/dist/editor-component.d.ts +17 -0
  495. package/dist/node_modules/@earendil-works/pi-tui/dist/fuzzy.d.ts +6 -0
  496. package/dist/node_modules/@earendil-works/pi-tui/dist/index.d.ts +32 -0
  497. package/dist/node_modules/@earendil-works/pi-tui/dist/keybindings.d.ts +329 -0
  498. package/dist/node_modules/@earendil-works/pi-tui/dist/keys.d.ts +101 -0
  499. package/dist/node_modules/@earendil-works/pi-tui/dist/latex.d.ts +4 -0
  500. package/dist/node_modules/@earendil-works/pi-tui/dist/layout-node.d.ts +41 -0
  501. package/dist/node_modules/@earendil-works/pi-tui/dist/native-platform.d.ts +13 -0
  502. package/dist/node_modules/@earendil-works/pi-tui/dist/stdin-buffer.d.ts +30 -0
  503. package/dist/node_modules/@earendil-works/pi-tui/dist/terminal-colors.d.ts +9 -0
  504. package/dist/node_modules/@earendil-works/pi-tui/dist/terminal-image.d.ts +82 -0
  505. package/dist/node_modules/@earendil-works/pi-tui/dist/terminal.d.ts +76 -0
  506. package/dist/node_modules/@earendil-works/pi-tui/dist/tui-alt-screen.d.ts +138 -0
  507. package/dist/node_modules/@earendil-works/pi-tui/dist/tui-main-screen.d.ts +32 -0
  508. package/dist/node_modules/@earendil-works/pi-tui/dist/tui.d.ts +252 -0
  509. package/dist/node_modules/@earendil-works/pi-tui/dist/utils.d.ts +38 -0
  510. package/dist/node_modules/@earendil-works/pi-tui/package.json +1 -1
  511. package/dist/package-manager-cli.js +32 -32
  512. package/dist/sdk/index.d.ts +18 -0
  513. package/dist/sdk/index.js +1 -0
  514. package/dist/sdk/mcp.d.ts +8 -0
  515. package/dist/sdk/mcp.js +1 -0
  516. package/dist/sdk/office.d.ts +1 -0
  517. package/dist/sdk/office.js +1 -0
  518. package/dist/sdk/review.d.ts +1 -0
  519. package/dist/sdk/review.js +1 -0
  520. package/dist/sdk/rewind.d.ts +1 -0
  521. package/dist/sdk/rewind.js +1 -0
  522. package/dist/sdk/router.d.ts +6 -0
  523. package/dist/sdk/router.js +1 -0
  524. package/dist/sdk/subagents.d.ts +8 -0
  525. package/dist/sdk/subagents.js +1 -0
  526. package/dist/utils/clipboard.d.ts +2 -0
  527. package/dist/utils/frontmatter.d.ts +7 -0
  528. package/dist/utils/image-convert.d.ts +5 -0
  529. package/dist/utils/image-resize-core.d.ts +16 -0
  530. package/dist/utils/image-resize.d.ts +4 -0
  531. package/dist/utils/mime.d.ts +2 -0
  532. package/dist/utils/shell.d.ts +20 -0
  533. package/dist/utils/shell.js +3 -3
  534. package/dist/utils/version-check.d.ts +20 -0
  535. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  536. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  537. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  538. package/examples/extensions/gondolin/package-lock.json +2 -2
  539. package/examples/extensions/gondolin/package.json +1 -1
  540. package/examples/extensions/sandbox/index.ts +6 -0
  541. package/examples/extensions/sandbox/package-lock.json +2 -2
  542. package/examples/extensions/sandbox/package.json +1 -1
  543. package/examples/extensions/with-deps/package-lock.json +2 -2
  544. package/examples/extensions/with-deps/package.json +1 -1
  545. package/npm-shrinkwrap.json +75 -5
  546. package/package.json +27 -1
  547. package/dist/bun/register-bedrock.js +0 -1
  548. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/reducer.js +0 -1
  549. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl/errors.js +0 -1
  550. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl-repo.js +0 -1
  551. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl-storage.js +0 -5
  552. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl.js +0 -1
  553. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/memory-repo.js +0 -1
  554. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/memory-storage.js +0 -1
  555. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/repo-utils.js +0 -1
  556. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/state.js +0 -1
  557. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/testing/conformance.js +0 -1
  558. package/dist/node_modules/@earendil-works/pi-agent-core/dist/search/scanning.js +0 -1
  559. package/dist/node_modules/@earendil-works/pi-ai/dist/api/cloudflare-gateway-binding.js +0 -1
  560. package/dist/node_modules/@earendil-works/pi-ai/dist/utils/deferred-tools.js +0 -1
  561. package/dist/node_modules/@earendil-works/pi-client/dist/session-handle.js +0 -1
  562. package/dist/node_modules/@earendil-works/pi-client/dist/state.js +0 -1
  563. package/dist/node_modules/@earendil-works/pi-server/dist/cli.js +0 -16
  564. package/dist/node_modules/@earendil-works/pi-server/dist/config.js +0 -1
  565. package/dist/node_modules/@earendil-works/pi-server/dist/handler.js +0 -1
  566. package/dist/node_modules/@earendil-works/pi-server/dist/ipc/client.js +0 -2
  567. package/dist/node_modules/@earendil-works/pi-server/dist/ipc/protocol.js +0 -2
  568. package/dist/node_modules/@earendil-works/pi-server/dist/ipc/server.js +0 -3
  569. package/dist/node_modules/@earendil-works/pi-server/dist/protocol.js +0 -1
  570. package/dist/node_modules/@earendil-works/pi-server/dist/radius.js +0 -1
  571. package/dist/node_modules/@earendil-works/pi-server/dist/rpc-process.js +0 -4
  572. package/dist/node_modules/@earendil-works/pi-server/dist/serve.js +0 -1
  573. package/dist/node_modules/@earendil-works/pi-server/dist/sessions.js +0 -1
  574. package/dist/node_modules/@earendil-works/pi-server/dist/snapshots.js +0 -1
  575. package/dist/node_modules/@earendil-works/pi-server/dist/storage.js +0 -1
  576. package/dist/node_modules/@earendil-works/pi-server/dist/supervisor.js +0 -1
  577. package/dist/node_modules/@earendil-works/pi-server/dist/testing/service.js +0 -1
  578. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/branch-cache.js +0 -7
  579. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/search-backend.js +0 -36
  580. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/branch-entries.js +0 -25
  581. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/branch-tips.js +0 -2
  582. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/entries.js +0 -7
  583. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/facts.js +0 -20
  584. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/lanes.js +0 -26
  585. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/records.js +0 -9
  586. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/session-sequences.js +0 -1
  587. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/session-stats.js +0 -10
  588. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/sessions.js +0 -29
  589. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/writer-leases.js +0 -14
  590. package/dist/server/create-harness.js +0 -1
  591. package/dist/utils/clipboard-native.js +0 -1
@@ -1,3 +1,3 @@
1
- var gt=Object.defineProperty;var m=(c,t)=>gt(c,"name",{value:t,configurable:!0});import{createHash as dt}from"node:crypto";import{chmodSync as yt,existsSync as f,globSync as Pt,mkdirSync as D,readdirSync as F,readFileSync as T,rmSync as b,statSync as C,writeFileSync as z}from"node:fs";import{homedir as wt}from"node:os";function Y(){if(process.platform!=="linux"||Object.keys(process.env).length>0)return process.env;try{const c=T("/proc/self/environ","utf-8"),t={};for(const e of c.split("\0")){const s=e.indexOf("=");s>0&&(t[e.slice(0,s)]=e.slice(s+1))}return t}catch{return process.env}}m(Y,"getEnv");import{basename as x,dirname as k,join as h,relative as S,resolve as v,sep as W}from"node:path";import G from"ignore";import{minimatch as j}from"minimatch";import{gt as et,maxSatisfying as kt,rcompare as St,satisfies as vt,valid as Mt,validRange as Ct}from"semver";import{CONFIG_DIR_NAME as I,isOfficialExtensionsPackage as Nt}from"../config.js";import{spawnProcess as st,spawnProcessSync as Et}from"../utils/child-process.js";import{parseGitUrl as Ft}from"../utils/git.js";import{isOfflineModeEnabled as N}from"../utils/offline.js";import{canonicalizePath as bt,isLocalPath as jt,markPathIgnoredByCloudSync as xt,resolvePath as H}from"../utils/paths.js";import{stripBom as nt}from"../utils/text.js";import{isStdoutTakenOver as Gt}from"./output-guard.js";import{findNearestPiManifest as It,readPiManifest as U}from"./pi-manifest.js";const M=1e4,rt=4,$t=4,At=Symbol.for("dalcode.packageManager.npmArgsHook");function Rt(c){return Mt(c??"")!==null}m(Rt,"isExactNpmVersion");function Dt(c){return c?Ct(c)??void 0:void 0}m(Dt,"getNpmVersionRange");function it(c){return c.origin==="package"?4:(c.scope==="project"?0:2)+(c.source==="local"?0:1)}m(it,"resourcePrecedenceRank");const L=["extensions","skills","prompts","themes"],Tt={extensions:/\.(ts|js)$/,skills:/\.md$/,prompts:/\.md$/,themes:/\.json$/},Wt=[".gitignore",".ignore",".fdignore"];function y(c){return c.split(W).join("/")}m(y,"toPosixPath");function q(){return process.env.HOME||wt()}m(q,"getHomeDir");function Ht(c){const t=h(c,"tmp","extensions");return D(t,{recursive:!0,mode:448}),yt(t,448),t}m(Ht,"getExtensionTempFolder");function Ut(c,t){const e=c.trim();if(!e||e.startsWith("#")&&!e.startsWith("\\#"))return null;let s=c,n=!1;s.startsWith("!")?(n=!0,s=s.slice(1)):s.startsWith("\\!")&&(s=s.slice(1)),s.startsWith("/")&&(s=s.slice(1));const r=t?`${t}${s}`:s;return n?`!${r}`:r}m(Ut,"prefixIgnorePattern");function $(c,t,e){const s=S(e,t),n=s?`${y(s)}/`:"";for(const r of Wt){const i=h(t,r);if(f(i))try{const a=T(i,"utf-8").split(/\r?\n/).map(l=>Ut(l,n)).filter(l=>!!l);a.length>0&&c.add(a)}catch{}}}m($,"addIgnoreRules");function Lt(c){return c.startsWith("!")||c.startsWith("+")||c.startsWith("-")||c.includes("*")||c.includes("?")}m(Lt,"isPattern");function Q(c){return c.startsWith("!")||c.startsWith("+")||c.startsWith("-")}m(Q,"isOverridePattern");function Ot(c){return c.includes("*")||c.includes("?")}m(Ot,"hasGlobPattern");function _t(c,t){return Pt(c,{cwd:t}).map(e=>v(t,e)).filter(e=>S(t,e).split(W).every(s=>s===".."||!s.startsWith("."))).sort((e,s)=>e<s?-1:e>s?1:0)}m(_t,"expandPackageGlob");function Bt(c){const t=[],e=[];for(const s of c)Lt(s)?e.push(s):t.push(s);return{plain:t,patterns:e}}m(Bt,"splitPatterns");function ot(c,t,e=!0,s,n){const r=[];if(!f(c))return r;const i=n??c,o=s??G();$(o,c,i);try{const a=F(c,{withFileTypes:!0});for(const l of a){if(l.name.startsWith(".")||e&&l.name==="node_modules")continue;const p=h(c,l.name);let u=l.isDirectory(),g=l.isFile();if(l.isSymbolicLink())try{const w=C(p);u=w.isDirectory(),g=w.isFile()}catch{continue}const P=y(S(i,p)),d=u?`${P}/`:P;o.ignores(d)||(u?r.push(...ot(p,t,e,o,i)):g&&t.test(l.name)&&r.push(p))}}catch{}return r}m(ot,"collectFiles");function X(c,t,e,s){const n=[];if(!f(c))return n;const r=s??c,i=e??G();$(i,c,r);try{const o=F(c,{withFileTypes:!0});for(const a of o){if(a.name!=="SKILL.md")continue;const l=h(c,a.name);let p=a.isFile();if(a.isSymbolicLink())try{p=C(l).isFile()}catch{continue}const u=y(S(r,l));if(p&&!i.ignores(u))return n.push(l),n}for(const a of o){if(a.name.startsWith(".")||a.name==="node_modules")continue;const l=h(c,a.name);let p=a.isDirectory(),u=a.isFile();if(a.isSymbolicLink())try{const d=C(l);p=d.isDirectory(),u=d.isFile()}catch{continue}const g=y(S(r,l));if(u&&a.name.endsWith(".md")&&!i.ignores(g)&&(t==="pi"&&c===r||t==="agents"&&c!==r)){n.push(l);continue}p&&(i.ignores(`${g}/`)||n.push(...X(l,t,i,r)))}}catch{}return n}m(X,"collectSkillEntries");function O(c,t){return X(c,t)}m(O,"collectAutoSkillEntries");function Vt(c){let t=v(c);for(;;){if(f(h(t,".git")))return t;const e=k(t);if(e===t)return null;t=e}}m(Vt,"findGitRepoRoot");function Jt(c){const t=[],e=v(c),s=Vt(e);let n=e;for(;t.push(h(n,".agents","skills")),!(s&&n===s);){const r=k(n);if(r===n)break;n=r}return t}m(Jt,"collectAncestorAgentsSkillDirs");function at(c){const t=[];if(!f(c))return t;const e=G();$(e,c,c);try{const s=F(c,{withFileTypes:!0});for(const n of s){if(n.name.startsWith(".")||n.name==="node_modules")continue;const r=h(c,n.name);let i=n.isFile();if(n.isSymbolicLink())try{i=C(r).isFile()}catch{continue}const o=y(S(c,r));e.ignores(o)||i&&n.name.endsWith(".md")&&t.push(r)}}catch{}return t}m(at,"collectAutoPromptEntries");function ct(c){const t=[];if(!f(c))return t;const e=G();$(e,c,c);try{const s=F(c,{withFileTypes:!0});for(const n of s){if(n.name.startsWith(".")||n.name==="node_modules")continue;const r=h(c,n.name);let i=n.isFile();if(n.isSymbolicLink())try{i=C(r).isFile()}catch{continue}const o=y(S(c,r));e.ignores(o)||i&&n.name.endsWith(".json")&&t.push(r)}}catch{}return t}m(ct,"collectAutoThemeEntries");function lt(c){const t=h(c,"package.json");if(f(t)){const n=U(t);if(n?.extensions?.length){const r=[];for(const i of n.extensions){const o=v(c,i);f(o)&&r.push(o)}if(r.length>0)return r}}const e=h(c,"index.ts"),s=h(c,"index.js");return f(e)?[e]:f(s)?[s]:null}m(lt,"resolveExtensionEntries");function Z(c){const t=[];if(!f(c))return t;const e=lt(c);if(e)return e;const s=G();$(s,c,c);try{const n=F(c,{withFileTypes:!0});for(const r of n){if(r.name.startsWith(".")||r.name==="node_modules")continue;const i=h(c,r.name);let o=r.isDirectory(),a=r.isFile();if(r.isSymbolicLink())try{const u=C(i);o=u.isDirectory(),a=u.isFile()}catch{continue}const l=y(S(c,i)),p=o?`${l}/`:l;if(!s.ignores(p)){if(a&&(r.name.endsWith(".ts")||r.name.endsWith(".js")))t.push(i);else if(o){const u=lt(i);u&&t.push(...u)}}}}catch{}return t}m(Z,"collectAutoExtensionEntries");function _(c,t){return t==="skills"?X(c,"pi"):t==="extensions"?Z(c):ot(c,Tt[t])}m(_,"collectResourceFiles");function B(c,t,e){const s=y(S(e,c)),n=x(c),r=y(c),i=n==="SKILL.md",o=i?k(c):void 0,a=i?y(S(e,o)):void 0,l=i?x(o):void 0,p=i?y(o):void 0;return t.some(u=>{const g=y(u);return j(s,g)||j(n,g)||j(r,g)?!0:i?j(a,g)||j(l,g)||j(p,g):!1})}m(B,"matchesAnyPattern");function Kt(c){const t=c.startsWith("./")||c.startsWith(".\\")?c.slice(2):c;return y(t)}m(Kt,"normalizeExactPattern");function A(c,t,e){if(t.length===0)return!1;const s=y(S(e,c)),n=x(c),r=y(c),i=n==="SKILL.md",o=i?k(c):void 0,a=i?y(S(e,o)):void 0,l=i?y(o):void 0;return t.some(p=>{const u=Kt(p);return u===s||u===r?!0:i?u===a||u===l:!1})}m(A,"matchesAnyExactPattern");function zt(c){return c.filter(t=>t.startsWith("!")||t.startsWith("+")||t.startsWith("-"))}m(zt,"getOverridePatterns");function Yt(c,t,e){const s=zt(t),n=s.filter(a=>a.startsWith("!")).map(a=>a.slice(1)),r=s.filter(a=>a.startsWith("+")).map(a=>a.slice(1)),i=s.filter(a=>a.startsWith("-")).map(a=>a.slice(1));let o=!0;return n.length>0&&B(c,n,e)&&(o=!1),r.length>0&&A(c,r,e)&&(o=!0),i.length>0&&A(c,i,e)&&(o=!1),o}m(Yt,"isEnabledByOverrides");function V(c,t,e){const s=[],n=[],r=[],i=[];for(const a of t)a.startsWith("+")?r.push(a.slice(1)):a.startsWith("-")?i.push(a.slice(1)):a.startsWith("!")?n.push(a.slice(1)):s.push(a);let o;if(s.length===0?o=[...c]:o=c.filter(a=>B(a,s,e)),n.length>0&&(o=o.filter(a=>!B(a,n,e))),r.length>0)for(const a of c)!o.includes(a)&&A(a,r,e)&&o.push(a);return i.length>0&&(o=o.filter(a=>!A(a,i,e))),new Set(o)}m(V,"applyPatterns");function qt(c,t,e){const s=new Map;for(const n of t){const r=n.slice(n.startsWith("+")||n.startsWith("-")||n.startsWith("!")?1:0),i=!n.startsWith("-")&&!n.startsWith("!"),o=n.startsWith("+")||n.startsWith("-");for(const a of c)(o?A(a,[r],e):B(a,[r],e))&&s.set(a,i)}return s}m(qt,"applyAutoloadDisabledPatterns");class fe{static{m(this,"DefaultPackageManager")}cwd;agentDir;settingsManager;globalNpmRoot;globalNpmRootCommandKey;progressCallback;constructor(t){this.cwd=H(t.cwd),this.agentDir=H(t.agentDir),this.settingsManager=t.settingsManager}setProgressCallback(t){this.progressCallback=t}addSourceToSettings(t,e){const s=e?.local?"project":"user",r=(s==="project"?this.settingsManager.getProjectSettings():this.settingsManager.getGlobalSettings()).packages??[],i=this.normalizePackageSourceForSettings(t,s),o=m(p=>{const u=e?.resolvedCommit;return!u&&!p?i:typeof p=="string"||p===void 0?u?{source:i,resolvedCommit:u}:i:u?{...p,source:i,resolvedCommit:u}:{...p,source:i}},"toEntry"),a=r.findIndex(p=>this.packageSourcesMatch(p,t,s));if(a!==-1){const p=r[a];if(this.getPackageSourceString(p)===i&&!e?.resolvedCommit)return!1;const u=[...r];return u[a]=o(p),s==="project"?this.settingsManager.setProjectPackages(u):this.settingsManager.setPackages(u),!0}const l=[...r,o()];return s==="project"?this.settingsManager.setProjectPackages(l):this.settingsManager.setPackages(l),!0}removeSourceFromSettings(t,e){const s=e?.local?"project":"user",r=(s==="project"?this.settingsManager.getProjectSettings():this.settingsManager.getGlobalSettings()).packages??[],i=r.filter(a=>!this.packageSourcesMatch(a,t,s));return i.length!==r.length?(s==="project"?this.settingsManager.setProjectPackages(i):this.settingsManager.setPackages(i),!0):!1}getInstalledPath(t,e){const s=this.parseSource(t);if(s.type==="npm"){const n=this.getNpmInstallPath(s,e);return f(n)?n:void 0}if(s.type==="git"){const n=this.getGitInstallPath(s,e);return f(n)?n:void 0}if(s.type==="local"){const n=this.getBaseDirForScope(e),r=this.resolvePathFromBase(s.path,n);return f(r)?r:void 0}}readDeclaredPermissions(t){if(!t)return;const s=It(t)?.manifest.permissions;return s&&s.length>0?[...s]:void 0}async readGitHead(t){if(t)try{const s=(await this.runCommandCapture("git",["rev-parse","HEAD"],{cwd:t,timeoutMs:M})).trim();return/^[0-9a-f]{7,40}$/i.test(s)?s:void 0}catch{return}}getStoredResolvedCommit(t,e){const s=e==="project"?this.settingsManager.getProjectSettings().packages??[]:this.settingsManager.getGlobalSettings().packages??[];for(const n of s)if(typeof n!="string"&&this.packageSourcesMatch(n,t,e))return n.resolvedCommit}emitProgress(t){this.progressCallback?.(t)}async withProgress(t,e,s,n){this.emitProgress({type:"start",action:t,source:e,message:s});try{await n(),this.emitProgress({type:"complete",action:t,source:e})}catch(r){const i=r instanceof Error?r.message:String(r);throw this.emitProgress({type:"error",action:t,source:e,message:i}),r}}async resolve(t){const e=this.createAccumulator(),s=this.settingsManager.getGlobalSettings(),n=this.settingsManager.getProjectSettings(),r=[];for(const l of n.packages??[])r.push({pkg:l,scope:"project"});for(const l of s.packages??[])r.push({pkg:l,scope:"user"});const i=this.dedupePackages(r);await this.resolvePackageSources(i,e,t);const o=this.agentDir,a=h(this.cwd,I);for(const l of L){const p=this.getTargetMap(e,l),u=s[l]??[],g=n[l]??[];this.resolveLocalEntries(g,l,p,{source:"local",scope:"project",origin:"top-level"},a),this.resolveLocalEntries(u,l,p,{source:"local",scope:"user",origin:"top-level"},o)}return this.addAutoDiscoveredResources(e,s,n,o,a),this.toResolvedPaths(e)}async resolveExtensionSources(t,e){const s=this.createAccumulator(),n=e?.temporary?"temporary":e?.local?"project":"user",r=t.map(i=>({pkg:i,scope:n}));return await this.resolvePackageSources(r,s),this.toResolvedPaths(s)}listConfiguredPackages(){const t=this.settingsManager.getGlobalSettings(),e=this.settingsManager.getProjectSettings(),s=[];for(const n of t.packages??[]){const r=typeof n=="string"?n:n.source,i=this.getInstalledPath(r,"user");s.push({source:r,scope:"user",filtered:typeof n=="object",installedPath:i,resolvedCommit:typeof n=="object"?n.resolvedCommit:void 0,permissions:this.readDeclaredPermissions(i)})}for(const n of e.packages??[]){const r=typeof n=="string"?n:n.source,i=this.getInstalledPath(r,"project");s.push({source:r,scope:"project",filtered:typeof n=="object",installedPath:i,resolvedCommit:typeof n=="object"?n.resolvedCommit:void 0,permissions:this.readDeclaredPermissions(i)})}return s}async install(t,e){const s=this.parseSource(t),n=e?.local?"project":"user";this.assertProjectTrustedForScope(n),await this.withProgress("install",t,`Installing ${t}...`,async()=>{if(s.type==="npm"){await this.installNpm(s,n,!1);return}if(s.type==="git"){await this.installGit(s,n);return}if(s.type==="local"){const r=this.resolvePath(s.path);if(!f(r))throw new Error(`Path does not exist: ${r}`);return}throw new Error(`Unsupported install source: ${t}`)})}async installAndPersist(t,e){await this.install(t,e);const s=e?.local?"project":"user",n=this.getInstalledPath(t,s),r=await this.readGitHead(n);this.addSourceToSettings(t,{...e,resolvedCommit:r})}async remove(t,e){const s=this.parseSource(t),n=e?.local?"project":"user";this.assertProjectTrustedForScope(n),await this.withProgress("remove",t,`Removing ${t}...`,async()=>{if(s.type==="npm"){await this.uninstallNpm(s,n);return}if(s.type==="git"){await this.removeGit(s,n);return}if(s.type!=="local")throw new Error(`Unsupported remove source: ${t}`)})}async removeAndPersist(t,e){return await this.remove(t,e),this.removeSourceFromSettings(t,e)}async update(t,e){const s=e?.latest===!0,n=this.settingsManager.getGlobalSettings(),r=this.settingsManager.getProjectSettings(),i=t?this.getPackageIdentity(t):void 0;let o=!1;const a=[];for(const l of n.packages??[]){const p=typeof l=="string"?l:l.source;i&&this.getPackageIdentity(p,"user")!==i||(o=!0,a.push({source:p,scope:"user"}))}for(const l of r.packages??[]){const p=typeof l=="string"?l:l.source;i&&this.getPackageIdentity(p,"project")!==i||(o=!0,a.push({source:p,scope:"project"}))}if(t&&!o)throw new Error(this.buildNoMatchingPackageMessage(t,[...n.packages??[],...r.packages??[]]));await this.updateConfiguredSources(a,s)}async updateConfiguredSources(t,e=!1){if(N()||t.length===0)return;const s=[],n=[];for(const p of t){const u=this.parseSource(p.source);if(u.type==="npm")u.pinned||s.push({...p,parsed:u});else if(u.type==="git"){const g=this.getStoredResolvedCommit(p.source,p.scope);if(!u.ref&&g&&!e)continue;n.push({...p,parsed:u})}}const r=s.map(p=>async()=>({entry:p,shouldUpdate:await this.shouldUpdateNpmSource(p.parsed,p.scope)})),i=await this.runWithConcurrency(r,rt),o=[],a=[];for(const p of i)p.shouldUpdate&&(p.entry.scope==="user"?o.push(p.entry):a.push(p.entry));const l=[];if(o.length>0&&l.push(this.updateNpmBatch(o,"user")),a.length>0&&l.push(this.updateNpmBatch(a,"project")),n.length>0){const p=n.map(u=>async()=>this.withProgress("update",u.source,`Updating ${u.source}...`,async()=>{if(await this.updateGit(u.parsed,u.scope),!this.getStoredResolvedCommit(u.source,u.scope))return;const P=this.getInstalledPath(u.source,u.scope),d=await this.readGitHead(P);d&&this.addSourceToSettings(u.source,{local:u.scope==="project",resolvedCommit:d})}));l.push(this.runWithConcurrency(p,$t).then(()=>{}))}await Promise.all(l)}async shouldUpdateNpmSource(t,e){const s=this.getManagedNpmInstallPath(t,e),n=f(s)?this.getInstalledNpmVersion(s):void 0;if(!n)return!0;try{const r=await this.getLatestNpmVersion(t.version?t.spec:t.name,t.range);return et(r,n)}catch{return!0}}async updateNpmBatch(t,e){if(t.length===0)return;const s=t.length===1?t[0].source:`${e} npm packages`,n=t.length===1?`Updating ${t[0].source}...`:`Updating ${e} npm packages...`,r=t.map(i=>i.parsed.version?i.parsed.spec:`${i.parsed.name}@latest`);await this.withProgress("update",s,n,async()=>{await this.installNpmBatch(r,e)})}async installNpmBatch(t,e){const s=this.getNpmInstallRoot(e,!1);this.ensureNpmProject(s),await this.runNpmCommand(this.getNpmInstallArgs(t,s))}async checkForAvailableUpdates(){if(N())return[];const t=this.settingsManager.getGlobalSettings(),e=this.settingsManager.getProjectSettings(),s=[];for(const o of e.packages??[])s.push({pkg:o,scope:"project"});for(const o of t.packages??[])s.push({pkg:o,scope:"user"});const r=this.dedupePackages(s).filter(o=>o.scope!=="temporary").map(o=>async()=>{const a=typeof o.pkg=="string"?o.pkg:o.pkg.source,l=this.parseSource(a);if(l.type==="local"||l.pinned)return;if(l.type==="npm"){const g=this.getNpmInstallPath(l,o.scope);return!f(g)||!await this.npmHasAvailableUpdate(l,g)?void 0:{source:a,displayName:l.name,type:"npm",scope:o.scope}}const p=this.getGitInstallPath(l,o.scope);if(!(!f(p)||!await this.gitHasAvailableUpdate(p)))return{source:a,displayName:`${l.host}/${l.path}`,type:"git",scope:o.scope}});return(await this.runWithConcurrency(r,rt)).filter(o=>o!==void 0)}async resolvePackageSources(t,e,s){for(const{pkg:n,scope:r}of t){const i=typeof n=="string"?n:n.source,o=typeof n=="object"?n:void 0,a=this.findAutoloadDeltaBase(n,r,t),l=a?.source??i,p=a?.scope??r,u=this.parseSource(l),g={source:i,scope:r,origin:"package"};if(u.type==="local"){const d=this.getBaseDirForScope(p);this.resolveLocalExtensionSource(u,e,o,g,d);continue}const P=m(async()=>{if(N())return!1;if(!s)return await this.installParsedSource(u,p),!0;const d=await s(l);if(d==="skip")return!1;if(d==="error")throw new Error(`Missing source: ${l}`);return await this.installParsedSource(u,p),!0},"installMissing");if(u.type==="npm"){let d=this.getNpmInstallPath(u,p);if(!f(d)||!await this.installedNpmMatchesConfiguredVersion(u,d)){if(!await P())continue;d=this.getNpmInstallPath(u,p)}g.baseDir=d,this.collectPackageResources(d,e,o,g);continue}if(u.type==="git"){const d=this.getGitInstallPath(u,p);if(f(d))p==="temporary"&&!u.pinned&&!N()&&await this.refreshTemporaryGitSource(u,l);else if(!await P())continue;g.baseDir=d,this.collectPackageResources(d,e,o,g)}}}findAutoloadDeltaBase(t,e,s){if(e!=="project"||typeof t!="object"||t.autoload!==!1)return;const n=this.getPackageIdentity(t.source,e),r=s.find(i=>i.scope==="user"&&this.getPackageIdentity(this.getPackageSourceString(i.pkg),"user")===n);return r?{source:this.getPackageSourceString(r.pkg),scope:"user"}:void 0}resolveLocalExtensionSource(t,e,s,n,r){const i=this.resolvePathFromBase(t.path,r);if(f(i))try{const o=C(i);if(o.isFile()){n.baseDir=k(i),this.addResource(e.extensions,i,n,!0);return}o.isDirectory()&&(n.baseDir=i,this.collectPackageResources(i,e,s,n)||this.addResource(e.extensions,i,n,!0))}catch{return}}async installParsedSource(t,e){if(t.type==="npm"){await this.installNpm(t,e,e==="temporary");return}if(t.type==="git"){await this.installGit(t,e);return}}getPackageSourceString(t){return typeof t=="string"?t:t.source}getSourceMatchKeyForInput(t){const e=this.parseSource(t);return e.type==="npm"?`npm:${e.name}`:e.type==="git"?`git:${e.host}/${e.path}`:`local:${this.resolvePath(e.path)}`}getSourceMatchKeyForSettings(t,e){const s=this.parseSource(t);if(s.type==="npm")return`npm:${s.name}`;if(s.type==="git")return`git:${s.host}/${s.path}`;const n=this.getBaseDirForScope(e);return`local:${this.resolvePathFromBase(s.path,n)}`}buildNoMatchingPackageMessage(t,e){const s=this.findSuggestedConfiguredSource(t,e);return s?`No matching package found for ${t}. Did you mean ${s}?`:`No matching package found for ${t}`}findSuggestedConfiguredSource(t,e){const s=t.trim(),n=new Set;for(const r of e){const i=this.getPackageSourceString(r),o=this.parseSource(i);if(o.type==="npm"){(s===o.name||s===o.spec)&&n.add(i);continue}if(o.type==="git"){const a=`${o.host}/${o.path}`,l=o.ref?`${a}@${o.ref}`:void 0;(s===a||l&&s===l)&&n.add(i)}}return n.values().next().value}packageSourcesMatch(t,e,s){const n=this.getSourceMatchKeyForSettings(this.getPackageSourceString(t),s),r=this.getSourceMatchKeyForInput(e);return n===r}normalizePackageSourceForSettings(t,e){const s=this.parseSource(t);if(s.type!=="local")return t;const n=this.getBaseDirForScope(e),r=this.resolvePath(s.path);return S(n,r)||"."}parseSource(t){if(t.startsWith("npm:")){const s=t.slice(4).trim(),{name:n,version:r}=this.parseNpmSpec(s);return{type:"npm",spec:s,name:n,version:r,range:Dt(r),pinned:Rt(r)}}if(jt(t))return{type:"local",path:t};const e=Ft(t);return e||{type:"local",path:t}}async installedNpmMatchesConfiguredVersion(t,e){const s=this.getInstalledNpmVersion(e);return s?t.range?vt(s,t.range):!0:!1}async npmHasAvailableUpdate(t,e){if(N())return!1;const s=this.getInstalledNpmVersion(e);if(!s)return!1;try{const n=await this.getLatestNpmVersion(t.version?t.spec:t.name,t.range);return et(n,s)}catch{return!1}}getInstalledNpmVersion(t){const e=h(t,"package.json");if(f(e))try{const s=T(e,"utf-8");return JSON.parse(nt(s)).version}catch{return}}async getLatestNpmVersion(t,e){const s=this.getNpmCommand(),n=await this.applyNpmArgsHook(["view",t,"version","--json"],this.cwd),i=(await this.runCommandCapture(s.command,[...s.args,...n],{cwd:this.cwd,timeoutMs:M})).trim();if(!i)throw new Error("Empty response from npm view");const o=JSON.parse(i);if(typeof o=="string")return o;if(Array.isArray(o)){const a=o.filter(p=>typeof p=="string"&&p.length>0),l=e?kt(a,e):[...a].sort(St)[0];if(l)return l}throw new Error("Unexpected response from npm view")}async gitHasAvailableUpdate(t){if(N())return!1;try{const e=await this.runCommandCapture("git",["rev-parse","HEAD"],{cwd:t,timeoutMs:M}),s=await this.getRemoteGitHead(t);return e.trim()!==s.trim()}catch{return!1}}async getRemoteGitHead(t){const e=await this.getGitUpstreamRef(t);if(e){const i=(await this.runGitRemoteCommand(t,["ls-remote","origin",e])).match(/^([0-9a-f]{40})\s+/m);if(i?.[1])return i[1]}const n=(await this.runGitRemoteCommand(t,["ls-remote","origin","HEAD"])).match(/^([0-9a-f]{40})\s+HEAD$/m);if(!n?.[1])throw new Error("Failed to determine remote HEAD");return n[1]}async getLocalGitUpdateTarget(t){try{const s=(await this.runCommandCapture("git",["rev-parse","--abbrev-ref","@{upstream}"],{cwd:t,timeoutMs:M})).trim();if(!s.startsWith("origin/"))throw new Error(`Unsupported upstream remote: ${s}`);const n=s.slice(7);if(!n)throw new Error("Missing upstream branch name");return{ref:"@{upstream}",head:await this.runCommandCapture("git",["rev-parse","@{upstream}"],{cwd:t,timeoutMs:M}),fetchArgs:["fetch","--prune","--no-tags","origin",`+refs/heads/${n}:refs/remotes/origin/${n}`]}}catch{await this.runCommand("git",["remote","set-head","origin","-a"],{cwd:t}).catch(()=>{});const e=await this.runCommandCapture("git",["rev-parse","origin/HEAD"],{cwd:t,timeoutMs:M}),n=(await this.runCommandCapture("git",["symbolic-ref","refs/remotes/origin/HEAD"],{cwd:t,timeoutMs:M}).catch(()=>"")).trim().replace(/^refs\/remotes\/origin\//,"");return n?{ref:"origin/HEAD",head:e,fetchArgs:["fetch","--prune","--no-tags","origin",`+refs/heads/${n}:refs/remotes/origin/${n}`]}:{ref:"origin/HEAD",head:e,fetchArgs:["fetch","--prune","--no-tags","origin","+HEAD:refs/remotes/origin/HEAD"]}}}async getGitUpstreamRef(t){try{const s=(await this.runCommandCapture("git",["rev-parse","--abbrev-ref","@{upstream}"],{cwd:t,timeoutMs:M})).trim();if(!s.startsWith("origin/"))return;const n=s.slice(7);return n?`refs/heads/${n}`:void 0}catch{return}}runGitRemoteCommand(t,e){return this.runCommandCapture("git",e,{cwd:t,timeoutMs:M,env:{GIT_TERMINAL_PROMPT:"0"}})}async runWithConcurrency(t,e){if(t.length===0)return[];const s=new Array(t.length);let n=0;const r=Math.max(1,Math.min(e,t.length)),i=m(async()=>{for(;;){const o=n;if(n+=1,o>=t.length)return;s[o]=await t[o]()}},"worker");return await Promise.all(Array.from({length:r},()=>i())),s}getPackageIdentity(t,e){const s=this.parseSource(t);if(s.type==="npm")return`npm:${s.name}`;if(s.type==="git")return`git:${s.host}/${s.path}`;if(e){const n=this.getBaseDirForScope(e);return`local:${this.resolvePathFromBase(s.path,n)}`}return`local:${this.resolvePath(s.path)}`}dedupePackages(t){const e=[],s=new Map;for(const n of t){const r=this.getPackageIdentity(this.getPackageSourceString(n.pkg),n.scope),i=s.get(r);if(i===void 0){s.set(r,e.length),e.push(n);continue}const o=e[i];o?.scope==="project"&&n.scope==="user"?typeof o.pkg=="object"&&o.pkg.autoload===!1&&e.push(n):n.scope==="project"&&(e[i]=n)}return e}parseNpmSpec(t){const e=t.match(/^(@?[^@]+(?:\/[^@]+)?)(?:@(.+))?$/);if(!e)return{name:t};const s=e[1]??t,n=e[2];return{name:s,version:n}}assertProjectTrustedForScope(t){if(t==="project"&&!this.settingsManager.isProjectTrusted())throw new Error("Project is not trusted; refusing to access project package storage")}getNpmCommand(){const t=this.settingsManager.getNpmCommand();if(!t||t.length===0)return{command:"npm",args:[]};const[e,...s]=t;if(!e)throw new Error("Invalid npmCommand: first array entry must be a non-empty command");return{command:e,args:s}}getPackageManagerName(){const t=this.getNpmCommand(),e=[t.command,...t.args],s=e.lastIndexOf("--"),n=s>=0?e[s+1]:t.command;return n?x(n).replace(/\.(cmd|exe)$/i,""):""}async runNpmCommand(t,e){const s=this.getNpmCommand(),n=await this.applyNpmArgsHook(t,e?.cwd);await this.runCommand(s.command,[...s.args,...n],e)}async applyNpmArgsHook(t,e){const s=globalThis[At];return typeof s!="function"?t:s(t,{cwd:e,packageManager:this.getPackageManagerName()})}getGitDependencyInstallArgs(){const t=this.settingsManager.getNpmCommand();return t&&t.length>0?["install"]:["install","--omit=dev"]}runNpmCommandSync(t){const e=this.getNpmCommand();return this.runCommandSync(e.command,[...e.args,...t])}getNpmInstallArgs(t,e){const s=this.getPackageManagerName();return s==="bun"?["install",...t,"--cwd",e,"--omit=peer"]:s==="pnpm"?["install",...t,"--prefix",e,"--config.auto-install-peers=false","--config.strict-peer-dependencies=false","--config.strict-dep-builds=false"]:["install",...t,"--prefix",e,"--legacy-peer-deps"]}async installNpm(t,e,s){const n=this.getNpmInstallRoot(e,s);this.ensureNpmProject(n),await this.runNpmCommand(this.getNpmInstallArgs([t.spec],n))}async uninstallNpm(t,e){const s=this.getNpmInstallRoot(e,!1);if(!f(s))return;const n=this.getPackageManagerName();if(n==="bun"){await this.runNpmCommand(["uninstall",t.name,"--cwd",s]);return}const r=["uninstall",t.name,"--prefix",s];n!=="pnpm"&&r.push("--legacy-peer-deps"),await this.runNpmCommand(r)}async installGit(t,e){const s=this.getGitInstallPath(t,e);if(f(s)){if(t.ref){await this.ensureGitRef(s,["fetch","origin",t.ref],"FETCH_HEAD");return}const r=await this.getLocalGitUpdateTarget(s);await this.ensureGitRef(s,r.fetchArgs,r.ref);return}const n=this.getGitInstallRoot(e);n&&this.ensureGitIgnore(n),D(k(s),{recursive:!0}),b(this.getGitUpdateMarkerPath(s),{force:!0});try{await this.runCommand("git",["clone",t.repo,s]),t.ref&&await this.runCommand("git",["checkout",t.ref],{cwd:s});const r=h(s,"package.json");f(r)&&await this.runNpmCommand(this.getGitDependencyInstallArgs(),{cwd:s})}catch(r){throw b(s,{recursive:!0,force:!0}),this.pruneEmptyGitParents(s,n),r}}async updateGit(t,e){const s=this.getGitInstallPath(t,e);if(!f(s)){await this.installGit(t,e);return}if(t.ref){await this.ensureGitRef(s,["fetch","origin",t.ref],"FETCH_HEAD");return}const n=await this.getLocalGitUpdateTarget(s);await this.ensureGitRef(s,n.fetchArgs,n.ref)}hasMissingGitDependencies(t){const e=h(t,"package.json");if(!f(e))return!1;try{const s=JSON.parse(nt(T(e,"utf-8")));if(!s.dependencies||typeof s.dependencies!="object"||Array.isArray(s.dependencies))return!1;const n=v(t,"node_modules");return Object.keys(s.dependencies).some(r=>{const i=v(n,r);return i.startsWith(`${n}${W}`)?!f(i):!1})}catch{return!1}}async repairMissingGitDependencies(t){this.hasMissingGitDependencies(t)&&await this.runNpmCommand(this.getGitDependencyInstallArgs(),{cwd:t})}getGitUpdateMarkerPath(t){return h(k(t),`.${x(t)}.pi-update-incomplete`)}async cleanAndInstallGitDependencies(t,e){try{await this.runCommand("git",["clean","-fdx"],{cwd:t})}catch(n){throw await this.repairMissingGitDependencies(t).catch(()=>{}),n}const s=h(t,"package.json");f(s)&&await this.runNpmCommand(this.getGitDependencyInstallArgs(),{cwd:t}),b(e,{force:!0})}async ensureGitRef(t,e,s){await this.runCommand("git",e,{cwd:t});const n=await this.runCommandCapture("git",["rev-parse","HEAD"],{cwd:t,timeoutMs:M}),r=`${s}^{commit}`,i=await this.runCommandCapture("git",["rev-parse",r],{cwd:t,timeoutMs:M}),o=this.getGitUpdateMarkerPath(t);if(n.trim()===i.trim()){f(o)?await this.cleanAndInstallGitDependencies(t,o):await this.repairMissingGitDependencies(t);return}z(o,"","utf-8"),await this.runCommand("git",["reset","--hard",r],{cwd:t}),await this.cleanAndInstallGitDependencies(t,o)}async refreshTemporaryGitSource(t,e){if(!N())try{await this.withProgress("pull",e,`Refreshing ${e}...`,async()=>{await this.updateGit(t,"temporary")})}catch{}}async removeGit(t,e){const s=this.getGitInstallPath(t,e);b(s,{recursive:!0,force:!0}),b(this.getGitUpdateMarkerPath(s),{force:!0}),this.pruneEmptyGitParents(s,this.getGitInstallRoot(e))}pruneEmptyGitParents(t,e){if(!e)return;const s=v(e);let n=k(t);for(;n.startsWith(s)&&n!==s;){if(!f(n)){n=k(n);continue}if(F(n).length>0)break;try{b(n,{recursive:!0,force:!0})}catch{break}n=k(n)}}ensureNpmProject(t){f(t)||D(t,{recursive:!0}),xt(t),this.ensureGitIgnore(t);const e=h(t,"package.json");f(e)||z(e,JSON.stringify({name:"pi-extensions",private:!0},null,2),"utf-8")}ensureGitIgnore(t){f(t)||D(t,{recursive:!0});const e=h(t,".gitignore");f(e)||z(e,`*
1
+ var gt=Object.defineProperty;var m=(c,t)=>gt(c,"name",{value:t,configurable:!0});import{createHash as dt}from"node:crypto";import{chmodSync as yt,existsSync as f,globSync as Pt,mkdirSync as W,readdirSync as I,readFileSync as H,rmSync as j,statSync as N,writeFileSync as z}from"node:fs";import{homedir as wt}from"node:os";function Y(){if(process.platform!=="linux"||Object.keys(process.env).length>0)return process.env;try{const c=H("/proc/self/environ","utf-8"),t={};for(const e of c.split("\0")){const s=e.indexOf("=");s>0&&(t[e.slice(0,s)]=e.slice(s+1))}return t}catch{return process.env}}m(Y,"getEnv");import{basename as A,dirname as w,join as h,relative as k,resolve as S,sep as U}from"node:path";import D from"ignore";import{minimatch as x}from"minimatch";import{gt as et,maxSatisfying as kt,rcompare as St,satisfies as vt,valid as Mt,validRange as Ct}from"semver";import{CONFIG_DIR_NAME as $,isOfficialExtensionsPackage as Nt,SHARED_SKILL_CONFIG_DIRS as st}from"../config.js";import{spawnProcess as nt,spawnProcessSync as Et}from"../utils/child-process.js";import{parseGitUrl as Ft}from"../utils/git.js";import{isOfflineModeEnabled as F}from"../utils/offline.js";import{canonicalizePath as bt,isLocalPath as It,markPathIgnoredByCloudSync as jt,resolvePath as L}from"../utils/paths.js";import{stripBom as rt}from"../utils/text.js";import{isStdoutTakenOver as xt}from"./output-guard.js";import{findNearestPiManifest as Gt,readPiManifest as _}from"./pi-manifest.js";const C=1e4,it=4,At=4,Dt=Symbol.for("dalcode.packageManager.npmArgsHook");function $t(c){return Mt(c??"")!==null}m($t,"isExactNpmVersion");function Rt(c){return c?Ct(c)??void 0:void 0}m(Rt,"getNpmVersionRange");function ot(c){return c.origin==="package"?4:(c.scope==="project"?0:2)+(c.source==="local"?0:1)}m(ot,"resourcePrecedenceRank");const O=["extensions","skills","prompts","themes"],Tt={extensions:/\.(ts|js)$/,skills:/\.md$/,prompts:/\.md$/,themes:/\.json$/},Wt=[".gitignore",".ignore",".fdignore"];function y(c){return c.split(U).join("/")}m(y,"toPosixPath");function q(){return process.env.HOME||wt()}m(q,"getHomeDir");function Ht(c){const t=h(c,"tmp","extensions");return W(t,{recursive:!0,mode:448}),yt(t,448),t}m(Ht,"getExtensionTempFolder");function Ut(c,t){const e=c.trim();if(!e||e.startsWith("#")&&!e.startsWith("\\#"))return null;let s=c,n=!1;s.startsWith("!")?(n=!0,s=s.slice(1)):s.startsWith("\\!")&&(s=s.slice(1)),s.startsWith("/")&&(s=s.slice(1));const r=t?`${t}${s}`:s;return n?`!${r}`:r}m(Ut,"prefixIgnorePattern");function R(c,t,e){const s=k(e,t),n=s?`${y(s)}/`:"";for(const r of Wt){const i=h(t,r);if(f(i))try{const a=H(i,"utf-8").split(/\r?\n/).map(l=>Ut(l,n)).filter(l=>!!l);a.length>0&&c.add(a)}catch{}}}m(R,"addIgnoreRules");function Lt(c){return c.startsWith("!")||c.startsWith("+")||c.startsWith("-")||c.includes("*")||c.includes("?")}m(Lt,"isPattern");function Q(c){return c.startsWith("!")||c.startsWith("+")||c.startsWith("-")}m(Q,"isOverridePattern");function _t(c){return c.includes("*")||c.includes("?")}m(_t,"hasGlobPattern");function Ot(c,t){return Pt(c,{cwd:t}).map(e=>S(t,e)).filter(e=>k(t,e).split(U).every(s=>s===".."||!s.startsWith("."))).sort((e,s)=>e<s?-1:e>s?1:0)}m(Ot,"expandPackageGlob");function Bt(c){const t=[],e=[];for(const s of c)Lt(s)?e.push(s):t.push(s);return{plain:t,patterns:e}}m(Bt,"splitPatterns");function at(c,t,e=!0,s,n){const r=[];if(!f(c))return r;const i=n??c,o=s??D();R(o,c,i);try{const a=I(c,{withFileTypes:!0});for(const l of a){if(l.name.startsWith(".")||e&&l.name==="node_modules")continue;const p=h(c,l.name);let u=l.isDirectory(),g=l.isFile();if(l.isSymbolicLink())try{const b=N(p);u=b.isDirectory(),g=b.isFile()}catch{continue}const P=y(k(i,p)),d=u?`${P}/`:P;o.ignores(d)||(u?r.push(...at(p,t,e,o,i)):g&&t.test(l.name)&&r.push(p))}}catch{}return r}m(at,"collectFiles");function X(c,t,e,s){const n=[];if(!f(c))return n;const r=s??c,i=e??D();R(i,c,r);try{const o=I(c,{withFileTypes:!0});for(const a of o){if(a.name!=="SKILL.md")continue;const l=h(c,a.name);let p=a.isFile();if(a.isSymbolicLink())try{p=N(l).isFile()}catch{continue}const u=y(k(r,l));if(p&&!i.ignores(u))return n.push(l),n}for(const a of o){if(a.name.startsWith(".")||a.name==="node_modules")continue;const l=h(c,a.name);let p=a.isDirectory(),u=a.isFile();if(a.isSymbolicLink())try{const d=N(l);p=d.isDirectory(),u=d.isFile()}catch{continue}const g=y(k(r,l));if(u&&a.name.endsWith(".md")&&!i.ignores(g)&&(t==="pi"&&c===r||t==="agents"&&c!==r)){n.push(l);continue}p&&(i.ignores(`${g}/`)||n.push(...X(l,t,i,r)))}}catch{}return n}m(X,"collectSkillEntries");function B(c,t){return X(c,t)}m(B,"collectAutoSkillEntries");function Vt(c){let t=S(c);for(;;){if(f(h(t,".git")))return t;const e=w(t);if(e===t)return null;t=e}}m(Vt,"findGitRepoRoot");function Kt(c=q()){return st.map(t=>h(c,t,"skills"))}m(Kt,"userSharedSkillDirs");function Jt(c){const t=[],e=S(c),s=Vt(e);let n=e;for(;;){for(const i of st)t.push(h(n,i,"skills"));if(s&&n===s)break;const r=w(n);if(r===n)break;n=r}return t}m(Jt,"collectAncestorAgentsSkillDirs");function ct(c){const t=[];if(!f(c))return t;const e=D();R(e,c,c);try{const s=I(c,{withFileTypes:!0});for(const n of s){if(n.name.startsWith(".")||n.name==="node_modules")continue;const r=h(c,n.name);let i=n.isFile();if(n.isSymbolicLink())try{i=N(r).isFile()}catch{continue}const o=y(k(c,r));e.ignores(o)||i&&n.name.endsWith(".md")&&t.push(r)}}catch{}return t}m(ct,"collectAutoPromptEntries");function lt(c){const t=[];if(!f(c))return t;const e=D();R(e,c,c);try{const s=I(c,{withFileTypes:!0});for(const n of s){if(n.name.startsWith(".")||n.name==="node_modules")continue;const r=h(c,n.name);let i=n.isFile();if(n.isSymbolicLink())try{i=N(r).isFile()}catch{continue}const o=y(k(c,r));e.ignores(o)||i&&n.name.endsWith(".json")&&t.push(r)}}catch{}return t}m(lt,"collectAutoThemeEntries");function ut(c){const t=h(c,"package.json");if(f(t)){const n=_(t);if(n?.extensions?.length){const r=[];for(const i of n.extensions){const o=S(c,i);f(o)&&r.push(o)}if(r.length>0)return r}}const e=h(c,"index.ts"),s=h(c,"index.js");return f(e)?[e]:f(s)?[s]:null}m(ut,"resolveExtensionEntries");function Z(c){const t=[];if(!f(c))return t;const e=ut(c);if(e)return e;const s=D();R(s,c,c);try{const n=I(c,{withFileTypes:!0});for(const r of n){if(r.name.startsWith(".")||r.name==="node_modules")continue;const i=h(c,r.name);let o=r.isDirectory(),a=r.isFile();if(r.isSymbolicLink())try{const u=N(i);o=u.isDirectory(),a=u.isFile()}catch{continue}const l=y(k(c,i)),p=o?`${l}/`:l;if(!s.ignores(p)){if(a&&(r.name.endsWith(".ts")||r.name.endsWith(".js")))t.push(i);else if(o){const u=ut(i);u&&t.push(...u)}}}}catch{}return t}m(Z,"collectAutoExtensionEntries");function V(c,t){return t==="skills"?X(c,"pi"):t==="extensions"?Z(c):at(c,Tt[t])}m(V,"collectResourceFiles");function K(c,t,e){const s=y(k(e,c)),n=A(c),r=y(c),i=n==="SKILL.md",o=i?w(c):void 0,a=i?y(k(e,o)):void 0,l=i?A(o):void 0,p=i?y(o):void 0;return t.some(u=>{const g=y(u);return x(s,g)||x(n,g)||x(r,g)?!0:i?x(a,g)||x(l,g)||x(p,g):!1})}m(K,"matchesAnyPattern");function zt(c){const t=c.startsWith("./")||c.startsWith(".\\")?c.slice(2):c;return y(t)}m(zt,"normalizeExactPattern");function T(c,t,e){if(t.length===0)return!1;const s=y(k(e,c)),n=A(c),r=y(c),i=n==="SKILL.md",o=i?w(c):void 0,a=i?y(k(e,o)):void 0,l=i?y(o):void 0;return t.some(p=>{const u=zt(p);return u===s||u===r?!0:i?u===a||u===l:!1})}m(T,"matchesAnyExactPattern");function Yt(c){return c.filter(t=>t.startsWith("!")||t.startsWith("+")||t.startsWith("-"))}m(Yt,"getOverridePatterns");function qt(c,t,e){const s=Yt(t),n=s.filter(a=>a.startsWith("!")).map(a=>a.slice(1)),r=s.filter(a=>a.startsWith("+")).map(a=>a.slice(1)),i=s.filter(a=>a.startsWith("-")).map(a=>a.slice(1));let o=!0;return n.length>0&&K(c,n,e)&&(o=!1),r.length>0&&T(c,r,e)&&(o=!0),i.length>0&&T(c,i,e)&&(o=!1),o}m(qt,"isEnabledByOverrides");function J(c,t,e){const s=[],n=[],r=[],i=[];for(const a of t)a.startsWith("+")?r.push(a.slice(1)):a.startsWith("-")?i.push(a.slice(1)):a.startsWith("!")?n.push(a.slice(1)):s.push(a);let o;if(s.length===0?o=[...c]:o=c.filter(a=>K(a,s,e)),n.length>0&&(o=o.filter(a=>!K(a,n,e))),r.length>0)for(const a of c)!o.includes(a)&&T(a,r,e)&&o.push(a);return i.length>0&&(o=o.filter(a=>!T(a,i,e))),new Set(o)}m(J,"applyPatterns");function Qt(c,t,e){const s=new Map;for(const n of t){const r=n.slice(n.startsWith("+")||n.startsWith("-")||n.startsWith("!")?1:0),i=!n.startsWith("-")&&!n.startsWith("!"),o=n.startsWith("+")||n.startsWith("-");for(const a of c)(o?T(a,[r],e):K(a,[r],e))&&s.set(a,i)}return s}m(Qt,"applyAutoloadDisabledPatterns");class me{static{m(this,"DefaultPackageManager")}cwd;agentDir;settingsManager;globalNpmRoot;globalNpmRootCommandKey;progressCallback;constructor(t){this.cwd=L(t.cwd),this.agentDir=L(t.agentDir),this.settingsManager=t.settingsManager}setProgressCallback(t){this.progressCallback=t}addSourceToSettings(t,e){const s=e?.local?"project":"user",r=(s==="project"?this.settingsManager.getProjectSettings():this.settingsManager.getGlobalSettings()).packages??[],i=this.normalizePackageSourceForSettings(t,s),o=m(p=>{const u=e?.resolvedCommit;return!u&&!p?i:typeof p=="string"||p===void 0?u?{source:i,resolvedCommit:u}:i:u?{...p,source:i,resolvedCommit:u}:{...p,source:i}},"toEntry"),a=r.findIndex(p=>this.packageSourcesMatch(p,t,s));if(a!==-1){const p=r[a];if(this.getPackageSourceString(p)===i&&!e?.resolvedCommit)return!1;const u=[...r];return u[a]=o(p),s==="project"?this.settingsManager.setProjectPackages(u):this.settingsManager.setPackages(u),!0}const l=[...r,o()];return s==="project"?this.settingsManager.setProjectPackages(l):this.settingsManager.setPackages(l),!0}removeSourceFromSettings(t,e){const s=e?.local?"project":"user",r=(s==="project"?this.settingsManager.getProjectSettings():this.settingsManager.getGlobalSettings()).packages??[],i=r.filter(a=>!this.packageSourcesMatch(a,t,s));return i.length!==r.length?(s==="project"?this.settingsManager.setProjectPackages(i):this.settingsManager.setPackages(i),!0):!1}getInstalledPath(t,e){const s=this.parseSource(t);if(s.type==="npm"){const n=this.getNpmInstallPath(s,e);return f(n)?n:void 0}if(s.type==="git"){const n=this.getGitInstallPath(s,e);return f(n)?n:void 0}if(s.type==="local"){const n=this.getBaseDirForScope(e),r=this.resolvePathFromBase(s.path,n);return f(r)?r:void 0}}readDeclaredPermissions(t){if(!t)return;const s=Gt(t)?.manifest.permissions;return s&&s.length>0?[...s]:void 0}async readGitHead(t){if(t)try{const s=(await this.runCommandCapture("git",["rev-parse","HEAD"],{cwd:t,timeoutMs:C})).trim();return/^[0-9a-f]{7,40}$/i.test(s)?s:void 0}catch{return}}getStoredResolvedCommit(t,e){const s=e==="project"?this.settingsManager.getProjectSettings().packages??[]:this.settingsManager.getGlobalSettings().packages??[];for(const n of s)if(typeof n!="string"&&this.packageSourcesMatch(n,t,e))return n.resolvedCommit}emitProgress(t){this.progressCallback?.(t)}async withProgress(t,e,s,n){this.emitProgress({type:"start",action:t,source:e,message:s});try{await n(),this.emitProgress({type:"complete",action:t,source:e})}catch(r){const i=r instanceof Error?r.message:String(r);throw this.emitProgress({type:"error",action:t,source:e,message:i}),r}}async resolve(t){const e=this.createAccumulator(),s=this.settingsManager.getGlobalSettings(),n=this.settingsManager.getProjectSettings(),r=[];for(const l of n.packages??[])r.push({pkg:l,scope:"project"});for(const l of s.packages??[])r.push({pkg:l,scope:"user"});const i=this.dedupePackages(r);await this.resolvePackageSources(i,e,t);const o=this.agentDir,a=h(this.cwd,$);for(const l of O){const p=this.getTargetMap(e,l),u=s[l]??[],g=n[l]??[];this.resolveLocalEntries(g,l,p,{source:"local",scope:"project",origin:"top-level"},a),this.resolveLocalEntries(u,l,p,{source:"local",scope:"user",origin:"top-level"},o)}return this.addAutoDiscoveredResources(e,s,n,o,a),this.toResolvedPaths(e)}async resolveExtensionSources(t,e){const s=this.createAccumulator(),n=e?.temporary?"temporary":e?.local?"project":"user",r=t.map(i=>({pkg:i,scope:n}));return await this.resolvePackageSources(r,s),this.toResolvedPaths(s)}listConfiguredPackages(){const t=this.settingsManager.getGlobalSettings(),e=this.settingsManager.getProjectSettings(),s=[];for(const n of t.packages??[]){const r=typeof n=="string"?n:n.source,i=this.getInstalledPath(r,"user");s.push({source:r,scope:"user",filtered:typeof n=="object",installedPath:i,resolvedCommit:typeof n=="object"?n.resolvedCommit:void 0,permissions:this.readDeclaredPermissions(i)})}for(const n of e.packages??[]){const r=typeof n=="string"?n:n.source,i=this.getInstalledPath(r,"project");s.push({source:r,scope:"project",filtered:typeof n=="object",installedPath:i,resolvedCommit:typeof n=="object"?n.resolvedCommit:void 0,permissions:this.readDeclaredPermissions(i)})}return s}async install(t,e){const s=this.parseSource(t),n=e?.local?"project":"user";this.assertProjectTrustedForScope(n),await this.withProgress("install",t,`Installing ${t}...`,async()=>{if(s.type==="npm"){await this.installNpm(s,n,!1);return}if(s.type==="git"){await this.installGit(s,n);return}if(s.type==="local"){const r=this.resolvePath(s.path);if(!f(r))throw new Error(`Path does not exist: ${r}`);return}throw new Error(`Unsupported install source: ${t}`)})}async installAndPersist(t,e){await this.install(t,e);const s=e?.local?"project":"user",n=this.getInstalledPath(t,s),r=await this.readGitHead(n);this.addSourceToSettings(t,{...e,resolvedCommit:r})}async remove(t,e){const s=this.parseSource(t),n=e?.local?"project":"user";this.assertProjectTrustedForScope(n),await this.withProgress("remove",t,`Removing ${t}...`,async()=>{if(s.type==="npm"){await this.uninstallNpm(s,n);return}if(s.type==="git"){await this.removeGit(s,n);return}if(s.type!=="local")throw new Error(`Unsupported remove source: ${t}`)})}async removeAndPersist(t,e){return await this.remove(t,e),this.removeSourceFromSettings(t,e)}async update(t,e){const s=e?.latest===!0,n=this.settingsManager.getGlobalSettings(),r=this.settingsManager.getProjectSettings(),i=t?this.getPackageIdentity(t):void 0;let o=!1;const a=[];for(const l of n.packages??[]){const p=typeof l=="string"?l:l.source;i&&this.getPackageIdentity(p,"user")!==i||(o=!0,a.push({source:p,scope:"user"}))}for(const l of r.packages??[]){const p=typeof l=="string"?l:l.source;i&&this.getPackageIdentity(p,"project")!==i||(o=!0,a.push({source:p,scope:"project"}))}if(t&&!o)throw new Error(this.buildNoMatchingPackageMessage(t,[...n.packages??[],...r.packages??[]]));await this.updateConfiguredSources(a,s)}async updateConfiguredSources(t,e=!1){if(F()||t.length===0)return;const s=[],n=[];for(const p of t){const u=this.parseSource(p.source);if(u.type==="npm")u.pinned||s.push({...p,parsed:u});else if(u.type==="git"){const g=this.getStoredResolvedCommit(p.source,p.scope);if(!u.ref&&g&&!e)continue;n.push({...p,parsed:u})}}const r=s.map(p=>async()=>({entry:p,shouldUpdate:await this.shouldUpdateNpmSource(p.parsed,p.scope)})),i=await this.runWithConcurrency(r,it),o=[],a=[];for(const p of i)p.shouldUpdate&&(p.entry.scope==="user"?o.push(p.entry):a.push(p.entry));const l=[];if(o.length>0&&l.push(this.updateNpmBatch(o,"user")),a.length>0&&l.push(this.updateNpmBatch(a,"project")),n.length>0){const p=n.map(u=>async()=>this.withProgress("update",u.source,`Updating ${u.source}...`,async()=>{if(await this.updateGit(u.parsed,u.scope),!this.getStoredResolvedCommit(u.source,u.scope))return;const P=this.getInstalledPath(u.source,u.scope),d=await this.readGitHead(P);d&&this.addSourceToSettings(u.source,{local:u.scope==="project",resolvedCommit:d})}));l.push(this.runWithConcurrency(p,At).then(()=>{}))}await Promise.all(l)}async shouldUpdateNpmSource(t,e){const s=this.getManagedNpmInstallPath(t,e),n=f(s)?this.getInstalledNpmVersion(s):void 0;if(!n)return!0;try{const r=await this.getLatestNpmVersion(t.version?t.spec:t.name,t.range);return et(r,n)}catch{return!0}}async updateNpmBatch(t,e){if(t.length===0)return;const s=t.length===1?t[0].source:`${e} npm packages`,n=t.length===1?`Updating ${t[0].source}...`:`Updating ${e} npm packages...`,r=t.map(i=>i.parsed.version?i.parsed.spec:`${i.parsed.name}@latest`);await this.withProgress("update",s,n,async()=>{await this.installNpmBatch(r,e)})}async installNpmBatch(t,e){const s=this.getNpmInstallRoot(e,!1);this.ensureNpmProject(s),await this.runNpmCommand(this.getNpmInstallArgs(t,s))}async checkForAvailableUpdates(){if(F())return[];const t=this.settingsManager.getGlobalSettings(),e=this.settingsManager.getProjectSettings(),s=[];for(const o of e.packages??[])s.push({pkg:o,scope:"project"});for(const o of t.packages??[])s.push({pkg:o,scope:"user"});const r=this.dedupePackages(s).filter(o=>o.scope!=="temporary").map(o=>async()=>{const a=typeof o.pkg=="string"?o.pkg:o.pkg.source,l=this.parseSource(a);if(l.type==="local"||l.pinned)return;if(l.type==="npm"){const g=this.getNpmInstallPath(l,o.scope);return!f(g)||!await this.npmHasAvailableUpdate(l,g)?void 0:{source:a,displayName:l.name,type:"npm",scope:o.scope}}const p=this.getGitInstallPath(l,o.scope);if(!(!f(p)||!await this.gitHasAvailableUpdate(p)))return{source:a,displayName:`${l.host}/${l.path}`,type:"git",scope:o.scope}});return(await this.runWithConcurrency(r,it)).filter(o=>o!==void 0)}async resolvePackageSources(t,e,s){for(const{pkg:n,scope:r}of t){const i=typeof n=="string"?n:n.source,o=typeof n=="object"?n:void 0,a=this.findAutoloadDeltaBase(n,r,t),l=a?.source??i,p=a?.scope??r,u=this.parseSource(l),g={source:i,scope:r,origin:"package"};if(u.type==="local"){const d=this.getBaseDirForScope(p);this.resolveLocalExtensionSource(u,e,o,g,d);continue}const P=m(async()=>{if(F())return!1;if(!s)return await this.installParsedSource(u,p),!0;const d=await s(l);if(d==="skip")return!1;if(d==="error")throw new Error(`Missing source: ${l}`);return await this.installParsedSource(u,p),!0},"installMissing");if(u.type==="npm"){let d=this.getNpmInstallPath(u,p);if(!f(d)||!await this.installedNpmMatchesConfiguredVersion(u,d)){if(!await P())continue;d=this.getNpmInstallPath(u,p)}g.baseDir=d,this.collectPackageResources(d,e,o,g);continue}if(u.type==="git"){const d=this.getGitInstallPath(u,p);if(f(d))p==="temporary"&&!u.pinned&&!F()&&await this.refreshTemporaryGitSource(u,l);else if(!await P())continue;g.baseDir=d,this.collectPackageResources(d,e,o,g)}}}findAutoloadDeltaBase(t,e,s){if(e!=="project"||typeof t!="object"||t.autoload!==!1)return;const n=this.getPackageIdentity(t.source,e),r=s.find(i=>i.scope==="user"&&this.getPackageIdentity(this.getPackageSourceString(i.pkg),"user")===n);return r?{source:this.getPackageSourceString(r.pkg),scope:"user"}:void 0}resolveLocalExtensionSource(t,e,s,n,r){const i=this.resolvePathFromBase(t.path,r);if(f(i))try{const o=N(i);if(o.isFile()){n.baseDir=w(i),this.addResource(e.extensions,i,n,!0);return}o.isDirectory()&&(n.baseDir=i,this.collectPackageResources(i,e,s,n)||this.addResource(e.extensions,i,n,!0))}catch{return}}async installParsedSource(t,e){if(t.type==="npm"){await this.installNpm(t,e,e==="temporary");return}if(t.type==="git"){await this.installGit(t,e);return}}getPackageSourceString(t){return typeof t=="string"?t:t.source}getSourceMatchKeyForInput(t){const e=this.parseSource(t);return e.type==="npm"?`npm:${e.name}`:e.type==="git"?`git:${e.host}/${e.path}`:`local:${this.resolvePath(e.path)}`}getSourceMatchKeyForSettings(t,e){const s=this.parseSource(t);if(s.type==="npm")return`npm:${s.name}`;if(s.type==="git")return`git:${s.host}/${s.path}`;const n=this.getBaseDirForScope(e);return`local:${this.resolvePathFromBase(s.path,n)}`}buildNoMatchingPackageMessage(t,e){const s=this.findSuggestedConfiguredSource(t,e);return s?`No matching package found for ${t}. Did you mean ${s}?`:`No matching package found for ${t}`}findSuggestedConfiguredSource(t,e){const s=t.trim(),n=new Set;for(const r of e){const i=this.getPackageSourceString(r),o=this.parseSource(i);if(o.type==="npm"){(s===o.name||s===o.spec)&&n.add(i);continue}if(o.type==="git"){const a=`${o.host}/${o.path}`,l=o.ref?`${a}@${o.ref}`:void 0;(s===a||l&&s===l)&&n.add(i)}}return n.values().next().value}packageSourcesMatch(t,e,s){const n=this.getSourceMatchKeyForSettings(this.getPackageSourceString(t),s),r=this.getSourceMatchKeyForInput(e);return n===r}normalizePackageSourceForSettings(t,e){const s=this.parseSource(t);if(s.type!=="local")return t;const n=this.getBaseDirForScope(e),r=this.resolvePath(s.path);return k(n,r)||"."}parseSource(t){if(t.startsWith("npm:")){const s=t.slice(4).trim(),{name:n,version:r}=this.parseNpmSpec(s);return{type:"npm",spec:s,name:n,version:r,range:Rt(r),pinned:$t(r)}}if(It(t))return{type:"local",path:t};const e=Ft(t);return e||{type:"local",path:t}}async installedNpmMatchesConfiguredVersion(t,e){const s=this.getInstalledNpmVersion(e);return s?t.range?vt(s,t.range):!0:!1}async npmHasAvailableUpdate(t,e){if(F())return!1;const s=this.getInstalledNpmVersion(e);if(!s)return!1;try{const n=await this.getLatestNpmVersion(t.version?t.spec:t.name,t.range);return et(n,s)}catch{return!1}}getInstalledNpmVersion(t){const e=h(t,"package.json");if(f(e))try{const s=H(e,"utf-8");return JSON.parse(rt(s)).version}catch{return}}async getLatestNpmVersion(t,e){const s=this.getNpmCommand(),n=await this.applyNpmArgsHook(["view",t,"version","--json"],this.cwd),i=(await this.runCommandCapture(s.command,[...s.args,...n],{cwd:this.cwd,timeoutMs:C})).trim();if(!i)throw new Error("Empty response from npm view");const o=JSON.parse(i);if(typeof o=="string")return o;if(Array.isArray(o)){const a=o.filter(p=>typeof p=="string"&&p.length>0),l=e?kt(a,e):[...a].sort(St)[0];if(l)return l}throw new Error("Unexpected response from npm view")}async gitHasAvailableUpdate(t){if(F())return!1;try{const e=await this.runCommandCapture("git",["rev-parse","HEAD"],{cwd:t,timeoutMs:C}),s=await this.getRemoteGitHead(t);return e.trim()!==s.trim()}catch{return!1}}async getRemoteGitHead(t){const e=await this.getGitUpstreamRef(t);if(e){const i=(await this.runGitRemoteCommand(t,["ls-remote","origin",e])).match(/^([0-9a-f]{40})\s+/m);if(i?.[1])return i[1]}const n=(await this.runGitRemoteCommand(t,["ls-remote","origin","HEAD"])).match(/^([0-9a-f]{40})\s+HEAD$/m);if(!n?.[1])throw new Error("Failed to determine remote HEAD");return n[1]}async getLocalGitUpdateTarget(t){try{const s=(await this.runCommandCapture("git",["rev-parse","--abbrev-ref","@{upstream}"],{cwd:t,timeoutMs:C})).trim();if(!s.startsWith("origin/"))throw new Error(`Unsupported upstream remote: ${s}`);const n=s.slice(7);if(!n)throw new Error("Missing upstream branch name");return{ref:"@{upstream}",head:await this.runCommandCapture("git",["rev-parse","@{upstream}"],{cwd:t,timeoutMs:C}),fetchArgs:["fetch","--prune","--no-tags","origin",`+refs/heads/${n}:refs/remotes/origin/${n}`]}}catch{await this.runCommand("git",["remote","set-head","origin","-a"],{cwd:t}).catch(()=>{});const e=await this.runCommandCapture("git",["rev-parse","origin/HEAD"],{cwd:t,timeoutMs:C}),n=(await this.runCommandCapture("git",["symbolic-ref","refs/remotes/origin/HEAD"],{cwd:t,timeoutMs:C}).catch(()=>"")).trim().replace(/^refs\/remotes\/origin\//,"");return n?{ref:"origin/HEAD",head:e,fetchArgs:["fetch","--prune","--no-tags","origin",`+refs/heads/${n}:refs/remotes/origin/${n}`]}:{ref:"origin/HEAD",head:e,fetchArgs:["fetch","--prune","--no-tags","origin","+HEAD:refs/remotes/origin/HEAD"]}}}async getGitUpstreamRef(t){try{const s=(await this.runCommandCapture("git",["rev-parse","--abbrev-ref","@{upstream}"],{cwd:t,timeoutMs:C})).trim();if(!s.startsWith("origin/"))return;const n=s.slice(7);return n?`refs/heads/${n}`:void 0}catch{return}}runGitRemoteCommand(t,e){return this.runCommandCapture("git",e,{cwd:t,timeoutMs:C,env:{GIT_TERMINAL_PROMPT:"0"}})}async runWithConcurrency(t,e){if(t.length===0)return[];const s=new Array(t.length);let n=0;const r=Math.max(1,Math.min(e,t.length)),i=m(async()=>{for(;;){const o=n;if(n+=1,o>=t.length)return;s[o]=await t[o]()}},"worker");return await Promise.all(Array.from({length:r},()=>i())),s}getPackageIdentity(t,e){const s=this.parseSource(t);if(s.type==="npm")return`npm:${s.name}`;if(s.type==="git")return`git:${s.host}/${s.path}`;if(e){const n=this.getBaseDirForScope(e);return`local:${this.resolvePathFromBase(s.path,n)}`}return`local:${this.resolvePath(s.path)}`}dedupePackages(t){const e=[],s=new Map;for(const n of t){const r=this.getPackageIdentity(this.getPackageSourceString(n.pkg),n.scope),i=s.get(r);if(i===void 0){s.set(r,e.length),e.push(n);continue}const o=e[i];o?.scope==="project"&&n.scope==="user"?typeof o.pkg=="object"&&o.pkg.autoload===!1&&e.push(n):n.scope==="project"&&(e[i]=n)}return e}parseNpmSpec(t){const e=t.match(/^(@?[^@]+(?:\/[^@]+)?)(?:@(.+))?$/);if(!e)return{name:t};const s=e[1]??t,n=e[2];return{name:s,version:n}}assertProjectTrustedForScope(t){if(t==="project"&&!this.settingsManager.isProjectTrusted())throw new Error("Project is not trusted; refusing to access project package storage")}getNpmCommand(){const t=this.settingsManager.getNpmCommand();if(!t||t.length===0)return{command:"npm",args:[]};const[e,...s]=t;if(!e)throw new Error("Invalid npmCommand: first array entry must be a non-empty command");return{command:e,args:s}}getPackageManagerName(){const t=this.getNpmCommand(),e=[t.command,...t.args],s=e.lastIndexOf("--"),n=s>=0?e[s+1]:t.command;return n?A(n).replace(/\.(cmd|exe)$/i,""):""}async runNpmCommand(t,e){const s=this.getNpmCommand(),n=await this.applyNpmArgsHook(t,e?.cwd);await this.runCommand(s.command,[...s.args,...n],e)}async applyNpmArgsHook(t,e){const s=globalThis[Dt];return typeof s!="function"?t:s(t,{cwd:e,packageManager:this.getPackageManagerName()})}getGitDependencyInstallArgs(){const t=this.settingsManager.getNpmCommand();return t&&t.length>0?["install"]:["install","--omit=dev"]}runNpmCommandSync(t){const e=this.getNpmCommand();return this.runCommandSync(e.command,[...e.args,...t])}getNpmInstallArgs(t,e){const s=this.getPackageManagerName();return s==="bun"?["install",...t,"--cwd",e,"--omit=peer"]:s==="pnpm"?["install",...t,"--prefix",e,"--config.auto-install-peers=false","--config.strict-peer-dependencies=false","--config.strict-dep-builds=false"]:["install",...t,"--prefix",e,"--legacy-peer-deps"]}async installNpm(t,e,s){const n=this.getNpmInstallRoot(e,s);this.ensureNpmProject(n),await this.runNpmCommand(this.getNpmInstallArgs([t.spec],n))}async uninstallNpm(t,e){const s=this.getNpmInstallRoot(e,!1);if(!f(s))return;const n=this.getPackageManagerName();if(n==="bun"){await this.runNpmCommand(["uninstall",t.name,"--cwd",s]);return}const r=["uninstall",t.name,"--prefix",s];n!=="pnpm"&&r.push("--legacy-peer-deps"),await this.runNpmCommand(r)}async installGit(t,e){const s=this.getGitInstallPath(t,e);if(f(s)){if(t.ref){await this.ensureGitRef(s,["fetch","origin",t.ref],"FETCH_HEAD");return}const r=await this.getLocalGitUpdateTarget(s);await this.ensureGitRef(s,r.fetchArgs,r.ref);return}const n=this.getGitInstallRoot(e);n&&this.ensureGitIgnore(n),W(w(s),{recursive:!0}),j(this.getGitUpdateMarkerPath(s),{force:!0});try{await this.runCommand("git",["clone",t.repo,s]),t.ref&&await this.runCommand("git",["checkout",t.ref],{cwd:s});const r=h(s,"package.json");f(r)&&await this.runNpmCommand(this.getGitDependencyInstallArgs(),{cwd:s})}catch(r){throw j(s,{recursive:!0,force:!0}),this.pruneEmptyGitParents(s,n),r}}async updateGit(t,e){const s=this.getGitInstallPath(t,e);if(!f(s)){await this.installGit(t,e);return}if(t.ref){await this.ensureGitRef(s,["fetch","origin",t.ref],"FETCH_HEAD");return}const n=await this.getLocalGitUpdateTarget(s);await this.ensureGitRef(s,n.fetchArgs,n.ref)}hasMissingGitDependencies(t){const e=h(t,"package.json");if(!f(e))return!1;try{const s=JSON.parse(rt(H(e,"utf-8")));if(!s.dependencies||typeof s.dependencies!="object"||Array.isArray(s.dependencies))return!1;const n=S(t,"node_modules");return Object.keys(s.dependencies).some(r=>{const i=S(n,r);return i.startsWith(`${n}${U}`)?!f(i):!1})}catch{return!1}}async repairMissingGitDependencies(t){this.hasMissingGitDependencies(t)&&await this.runNpmCommand(this.getGitDependencyInstallArgs(),{cwd:t})}getGitUpdateMarkerPath(t){return h(w(t),`.${A(t)}.pi-update-incomplete`)}async cleanAndInstallGitDependencies(t,e){try{await this.runCommand("git",["clean","-fdx"],{cwd:t})}catch(n){throw await this.repairMissingGitDependencies(t).catch(()=>{}),n}const s=h(t,"package.json");f(s)&&await this.runNpmCommand(this.getGitDependencyInstallArgs(),{cwd:t}),j(e,{force:!0})}async ensureGitRef(t,e,s){await this.runCommand("git",e,{cwd:t});const n=await this.runCommandCapture("git",["rev-parse","HEAD"],{cwd:t,timeoutMs:C}),r=`${s}^{commit}`,i=await this.runCommandCapture("git",["rev-parse",r],{cwd:t,timeoutMs:C}),o=this.getGitUpdateMarkerPath(t);if(n.trim()===i.trim()){f(o)?await this.cleanAndInstallGitDependencies(t,o):await this.repairMissingGitDependencies(t);return}z(o,"","utf-8"),await this.runCommand("git",["reset","--hard",r],{cwd:t}),await this.cleanAndInstallGitDependencies(t,o)}async refreshTemporaryGitSource(t,e){if(!F())try{await this.withProgress("pull",e,`Refreshing ${e}...`,async()=>{await this.updateGit(t,"temporary")})}catch{}}async removeGit(t,e){const s=this.getGitInstallPath(t,e);j(s,{recursive:!0,force:!0}),j(this.getGitUpdateMarkerPath(s),{force:!0}),this.pruneEmptyGitParents(s,this.getGitInstallRoot(e))}pruneEmptyGitParents(t,e){if(!e)return;const s=S(e);let n=w(t);for(;n.startsWith(s)&&n!==s;){if(!f(n)){n=w(n);continue}if(I(n).length>0)break;try{j(n,{recursive:!0,force:!0})}catch{break}n=w(n)}}ensureNpmProject(t){f(t)||W(t,{recursive:!0}),jt(t),this.ensureGitIgnore(t);const e=h(t,"package.json");f(e)||z(e,JSON.stringify({name:"pi-extensions",private:!0},null,2),"utf-8")}ensureGitIgnore(t){f(t)||W(t,{recursive:!0});const e=h(t,".gitignore");f(e)||z(e,`*
2
2
  !.gitignore
3
- `,"utf-8")}getNpmInstallRoot(t,e){return e?this.getTemporaryDir("npm"):t==="project"?(this.assertProjectTrustedForScope(t),h(this.cwd,I,"npm")):h(this.agentDir,"npm")}getGlobalNpmRoot(){const t=this.getNpmCommand(),e=[t.command,...t.args].join("\0");if(this.globalNpmRoot&&this.globalNpmRootCommandKey===e)return this.globalNpmRoot;if(this.getPackageManagerName()==="bun"){const s=this.runNpmCommandSync(["pm","bin","-g"]).trim();this.globalNpmRoot=h(k(s),"install","global","node_modules")}else this.globalNpmRoot=this.runNpmCommandSync(["root","-g"]).trim();return this.globalNpmRootCommandKey=e,this.globalNpmRoot}getPnpmGlobalPackagePath(t){if(this.getPackageManagerName()!=="pnpm")return;const e=this.runNpmCommandSync(["list","-g","--depth","0","--json"]),s=JSON.parse(e);for(const n of s){const r=n.dependencies?.[t]?.path;if(r)return r}}getManagedNpmInstallPath(t,e){return e==="temporary"?h(this.getTemporaryDir("npm"),"node_modules",t.name):e==="project"?(this.assertProjectTrustedForScope(e),h(this.cwd,I,"npm","node_modules",t.name)):h(this.agentDir,"npm","node_modules",t.name)}getLegacyGlobalNpmInstallPath(t){try{return this.getPnpmGlobalPackagePath(t.name)??h(this.getGlobalNpmRoot(),t.name)}catch{return}}getNpmInstallPath(t,e){const s=this.getManagedNpmInstallPath(t,e);if(e!=="user"||f(s))return s;const n=this.getLegacyGlobalNpmInstallPath(t);return n&&f(n)?n:s}getGitInstallPath(t,e){if(e==="temporary")return this.getTemporaryDir(`git-${t.host}`,t.path);const s=this.getGitInstallRoot(e);if(!s)throw new Error("Missing git install root");return this.resolveManagedPath(s,t.host,t.path)}getGitInstallRoot(t){if(t!=="temporary")return t==="project"?(this.assertProjectTrustedForScope(t),h(this.cwd,I,"git")):h(this.agentDir,"git")}getTemporaryDir(t,e){const s=this.resolveManagedPath(Ht(this.agentDir),t),n=dt("sha256").update(`${t}-${e??""}`).digest("hex").slice(0,8);return this.resolveManagedPath(s,n,e??"")}resolveManagedPath(t,...e){const s=v(t),n=v(s,...e);if(n!==s&&!n.startsWith(`${s}${W}`))throw new Error(`Refusing to use path outside package install root: ${n}`);return n}getBaseDirForScope(t){return t==="project"?(this.assertProjectTrustedForScope(t),h(this.cwd,I)):t==="user"?this.agentDir:this.cwd}resolvePath(t){return H(t,this.cwd,{homeDir:q(),trim:!0})}resolvePathFromBase(t,e){return H(t,e,{homeDir:q(),trim:!0})}collectPackageResources(t,e,s,n){if(Nt(t))return!0;if(s){for(const o of L){const a=s[o],l=this.getTargetMap(e,o);s.autoload===!1?this.applyPackageDeltaFilter(t,a??[],o,l,n):a!==void 0?this.applyPackageFilter(t,a,o,l,n):this.collectDefaultResources(t,o,l,n)}return!0}const r=U(h(t,"package.json"));if(r){for(const o of L){const a=r[o];this.addManifestEntries(a,t,o,this.getTargetMap(e,o),n)}return!0}let i=!1;for(const o of L){const a=h(t,o);if(f(a)){const l=_(a,o);for(const p of l)this.addResource(this.getTargetMap(e,o),p,n,!0);i=!0}}return i}collectDefaultResources(t,e,s,n){const i=U(h(t,"package.json"))?.[e];if(i){this.addManifestEntries(i,t,e,s,n);return}const o=h(t,e);if(f(o)){const a=_(o,e);for(const l of a)this.addResource(s,l,n,!0)}}applyPackageFilter(t,e,s,n,r){const{allFiles:i}=this.collectManifestFiles(t,s);if(e.length===0){for(const a of i)this.addResource(n,a,r,!1);return}const o=V(i,e,t);for(const a of i){const l=o.has(a);this.addResource(n,a,r,l)}}applyPackageDeltaFilter(t,e,s,n,r){if(e.length===0)return;const{allFiles:i}=this.collectManifestFiles(t,s),o=qt(i,e,t);for(const[a,l]of o)this.addResource(n,a,r,l)}collectManifestFiles(t,e){const n=U(h(t,"package.json"))?.[e];if(n&&n.length>0){const o=this.collectFilesFromManifestEntries(n,t,e),a=n.filter(Q),l=a.length>0?V(o,a,t):new Set(o);return{allFiles:Array.from(l),enabledByManifest:l}}const r=h(t,e);if(!f(r))return{allFiles:[],enabledByManifest:new Set};const i=_(r,e);return{allFiles:i,enabledByManifest:new Set(i)}}addManifestEntries(t,e,s,n,r){if(!t)return;const i=this.collectFilesFromManifestEntries(t,e,s),o=t.filter(Q),a=V(i,o,e);for(const l of i)a.has(l)&&this.addResource(n,l,r,!0)}collectFilesFromManifestEntries(t,e,s){const r=t.filter(i=>!Q(i)).flatMap(i=>Ot(i)?_t(i,e):[v(e,i)]);return this.collectFilesFromPaths(r,s)}resolveLocalEntries(t,e,s,n,r){if(t.length===0)return;const{plain:i,patterns:o}=Bt(t),a=i.map(u=>this.resolvePathFromBase(u,r)),l=this.collectFilesFromPaths(a,e),p=V(l,o,r);for(const u of l)this.addResource(s,u,n,p.has(u))}addAutoDiscoveredResources(t,e,s,n,r){const i={source:"auto",scope:"user",origin:"top-level",baseDir:n},o={source:"auto",scope:"project",origin:"top-level",baseDir:r},a={extensions:e.extensions??[],skills:e.skills??[],prompts:e.prompts??[],themes:e.themes??[]},l={extensions:s.extensions??[],skills:s.skills??[],prompts:s.prompts??[],themes:s.themes??[]},p={extensions:h(n,"extensions"),skills:h(n,"skills"),prompts:h(n,"prompts"),themes:h(n,"themes")},u={extensions:h(r,"extensions"),skills:h(r,"skills"),prompts:h(r,"prompts"),themes:h(r,"themes")},g=h(q(),".agents","skills"),P=this.settingsManager.isProjectTrusted(),d=P?Jt(this.cwd).filter(E=>v(E)!==v(g)):[],w=m((E,R,K,pt,ht)=>{const ft=this.getTargetMap(t,E);for(const tt of R){const mt=Yt(tt,pt,ht);this.addResource(ft,tt,K,mt)}},"addResources");P&&(w("extensions",Z(u.extensions),o,l.extensions,r),w("skills",O(u.skills,"pi"),o,l.skills,r));for(const E of d){const R=k(E),K={...o,baseDir:R};w("skills",O(E,"agents"),K,l.skills,R)}P&&(w("prompts",at(u.prompts),o,l.prompts,r),w("themes",ct(u.themes),o,l.themes,r)),w("extensions",Z(p.extensions),i,a.extensions,n),w("skills",O(p.skills,"pi"),i,a.skills,n);const J=k(g),ut={...i,baseDir:J};w("skills",O(g,"agents"),ut,a.skills,J),w("prompts",at(p.prompts),i,a.prompts,n),w("themes",ct(p.themes),i,a.themes,n)}collectFilesFromPaths(t,e){const s=[];for(const n of t)if(f(n))try{const r=C(n);r.isFile()?s.push(n):r.isDirectory()&&s.push(..._(n,e))}catch{}return s}getTargetMap(t,e){switch(e){case"extensions":return t.extensions;case"skills":return t.skills;case"prompts":return t.prompts;case"themes":return t.themes;default:throw new Error(`Unknown resource type: ${e}`)}}addResource(t,e,s,n){e&&(t.has(e)||t.set(e,{metadata:s,enabled:n}))}createAccumulator(){return{extensions:new Map,skills:new Map,prompts:new Map,themes:new Map}}toResolvedPaths(t){const e=m(s=>{const n=Array.from(s.entries()).map(([i,{metadata:o,enabled:a}])=>({path:i,enabled:a,metadata:o}));n.sort((i,o)=>it(i.metadata)-it(o.metadata));const r=new Set;return n.filter(i=>{const o=bt(i.path);return r.has(o)?!1:(r.add(o),!0)})},"mapToResolved");return{extensions:e(t.extensions),skills:e(t.skills),prompts:e(t.prompts),themes:e(t.themes)}}spawnCommand(t,e,s){const n=Y();return st(t,e,{cwd:s?.cwd,stdio:Gt()?["ignore",2,2]:"inherit",env:n})}spawnCaptureCommand(t,e,s){const n=Y(),r=s?.env?{...n,...s.env}:n;return st(t,e,{cwd:s?.cwd,stdio:["ignore","pipe","pipe"],env:r})}runCommandCapture(t,e,s){return new Promise((n,r)=>{const i=this.spawnCaptureCommand(t,e,s);let o="",a="",l=!1;const p=typeof s?.timeoutMs=="number"?setTimeout(()=>{l=!0,i.kill()},s.timeoutMs):void 0;i.stdout?.on("data",u=>{o+=u.toString()}),i.stderr?.on("data",u=>{a+=u.toString()}),i.once("error",u=>{p&&clearTimeout(p),r(u)}),i.once("close",(u,g)=>{if(p&&clearTimeout(p),l){r(new Error(`${t} ${e.join(" ")} timed out after ${s?.timeoutMs}ms`));return}if(u===0){n(o.trim());return}const P=u===null?`signal ${g??"unknown"}`:`code ${u}`;r(new Error(`${t} ${e.join(" ")} failed with ${P}: ${a||o}`))})})}runCommand(t,e,s){return new Promise((n,r)=>{const i=this.spawnCommand(t,e,s);i.on("error",r),i.on("exit",o=>{o===0?n():r(new Error(`${t} ${e.join(" ")} failed with code ${o}`))})})}runCommandSync(t,e){const s=Y(),n=Et(t,e,{stdio:["ignore","pipe","pipe"],encoding:"utf-8",env:s});if(n.error||n.status!==0)throw new Error(`Failed to run ${t} ${e.join(" ")}: ${n.error?.message||n.stderr||n.stdout}`);return(n.stdout||n.stderr||"").trim()}}export{fe as DefaultPackageManager,At as NPM_ARGS_HOOK_SLOT,Ht as getExtensionTempFolder};
3
+ `,"utf-8")}getNpmInstallRoot(t,e){return e?this.getTemporaryDir("npm"):t==="project"?(this.assertProjectTrustedForScope(t),h(this.cwd,$,"npm")):h(this.agentDir,"npm")}getGlobalNpmRoot(){const t=this.getNpmCommand(),e=[t.command,...t.args].join("\0");if(this.globalNpmRoot&&this.globalNpmRootCommandKey===e)return this.globalNpmRoot;if(this.getPackageManagerName()==="bun"){const s=this.runNpmCommandSync(["pm","bin","-g"]).trim();this.globalNpmRoot=h(w(s),"install","global","node_modules")}else this.globalNpmRoot=this.runNpmCommandSync(["root","-g"]).trim();return this.globalNpmRootCommandKey=e,this.globalNpmRoot}getPnpmGlobalPackagePath(t){if(this.getPackageManagerName()!=="pnpm")return;const e=this.runNpmCommandSync(["list","-g","--depth","0","--json"]),s=JSON.parse(e);for(const n of s){const r=n.dependencies?.[t]?.path;if(r)return r}}getManagedNpmInstallPath(t,e){return e==="temporary"?h(this.getTemporaryDir("npm"),"node_modules",t.name):e==="project"?(this.assertProjectTrustedForScope(e),h(this.cwd,$,"npm","node_modules",t.name)):h(this.agentDir,"npm","node_modules",t.name)}getLegacyGlobalNpmInstallPath(t){try{return this.getPnpmGlobalPackagePath(t.name)??h(this.getGlobalNpmRoot(),t.name)}catch{return}}getNpmInstallPath(t,e){const s=this.getManagedNpmInstallPath(t,e);if(e!=="user"||f(s))return s;const n=this.getLegacyGlobalNpmInstallPath(t);return n&&f(n)?n:s}getGitInstallPath(t,e){if(e==="temporary")return this.getTemporaryDir(`git-${t.host}`,t.path);const s=this.getGitInstallRoot(e);if(!s)throw new Error("Missing git install root");return this.resolveManagedPath(s,t.host,t.path)}getGitInstallRoot(t){if(t!=="temporary")return t==="project"?(this.assertProjectTrustedForScope(t),h(this.cwd,$,"git")):h(this.agentDir,"git")}getTemporaryDir(t,e){const s=this.resolveManagedPath(Ht(this.agentDir),t),n=dt("sha256").update(`${t}-${e??""}`).digest("hex").slice(0,8);return this.resolveManagedPath(s,n,e??"")}resolveManagedPath(t,...e){const s=S(t),n=S(s,...e);if(n!==s&&!n.startsWith(`${s}${U}`))throw new Error(`Refusing to use path outside package install root: ${n}`);return n}getBaseDirForScope(t){return t==="project"?(this.assertProjectTrustedForScope(t),h(this.cwd,$)):t==="user"?this.agentDir:this.cwd}resolvePath(t){return L(t,this.cwd,{homeDir:q(),trim:!0})}resolvePathFromBase(t,e){return L(t,e,{homeDir:q(),trim:!0})}collectPackageResources(t,e,s,n){if(Nt(t))return!0;if(s){for(const o of O){const a=s[o],l=this.getTargetMap(e,o);s.autoload===!1?this.applyPackageDeltaFilter(t,a??[],o,l,n):a!==void 0?this.applyPackageFilter(t,a,o,l,n):this.collectDefaultResources(t,o,l,n)}return!0}const r=_(h(t,"package.json"));if(r){for(const o of O){const a=r[o];this.addManifestEntries(a,t,o,this.getTargetMap(e,o),n)}return!0}let i=!1;for(const o of O){const a=h(t,o);if(f(a)){const l=V(a,o);for(const p of l)this.addResource(this.getTargetMap(e,o),p,n,!0);i=!0}}return i}collectDefaultResources(t,e,s,n){const i=_(h(t,"package.json"))?.[e];if(i){this.addManifestEntries(i,t,e,s,n);return}const o=h(t,e);if(f(o)){const a=V(o,e);for(const l of a)this.addResource(s,l,n,!0)}}applyPackageFilter(t,e,s,n,r){const{allFiles:i}=this.collectManifestFiles(t,s);if(e.length===0){for(const a of i)this.addResource(n,a,r,!1);return}const o=J(i,e,t);for(const a of i){const l=o.has(a);this.addResource(n,a,r,l)}}applyPackageDeltaFilter(t,e,s,n,r){if(e.length===0)return;const{allFiles:i}=this.collectManifestFiles(t,s),o=Qt(i,e,t);for(const[a,l]of o)this.addResource(n,a,r,l)}collectManifestFiles(t,e){const n=_(h(t,"package.json"))?.[e];if(n&&n.length>0){const o=this.collectFilesFromManifestEntries(n,t,e),a=n.filter(Q),l=a.length>0?J(o,a,t):new Set(o);return{allFiles:Array.from(l),enabledByManifest:l}}const r=h(t,e);if(!f(r))return{allFiles:[],enabledByManifest:new Set};const i=V(r,e);return{allFiles:i,enabledByManifest:new Set(i)}}addManifestEntries(t,e,s,n,r){if(!t)return;const i=this.collectFilesFromManifestEntries(t,e,s),o=t.filter(Q),a=J(i,o,e);for(const l of i)a.has(l)&&this.addResource(n,l,r,!0)}collectFilesFromManifestEntries(t,e,s){const r=t.filter(i=>!Q(i)).flatMap(i=>_t(i)?Ot(i,e):[S(e,i)]);return this.collectFilesFromPaths(r,s)}resolveLocalEntries(t,e,s,n,r){if(t.length===0)return;const{plain:i,patterns:o}=Bt(t),a=i.map(u=>this.resolvePathFromBase(u,r)),l=this.collectFilesFromPaths(a,e),p=J(l,o,r);for(const u of l)this.addResource(s,u,n,p.has(u))}addAutoDiscoveredResources(t,e,s,n,r){const i={source:"auto",scope:"user",origin:"top-level",baseDir:n},o={source:"auto",scope:"project",origin:"top-level",baseDir:r},a={extensions:e.extensions??[],skills:e.skills??[],prompts:e.prompts??[],themes:e.themes??[]},l={extensions:s.extensions??[],skills:s.skills??[],prompts:s.prompts??[],themes:s.themes??[]},p={extensions:h(n,"extensions"),skills:h(n,"skills"),prompts:h(n,"prompts"),themes:h(n,"themes")},u={extensions:h(r,"extensions"),skills:h(r,"skills"),prompts:h(r,"prompts"),themes:h(r,"themes")},g=Kt(),P=new Set(g.map(M=>S(M))),d=this.settingsManager.isProjectTrusted(),b=d?Jt(this.cwd).filter(M=>!P.has(S(M))):[],v=m((M,E,G,pt,ht)=>{const ft=this.getTargetMap(t,M);for(const tt of E){const mt=qt(tt,pt,ht);this.addResource(ft,tt,G,mt)}},"addResources");d&&(v("extensions",Z(u.extensions),o,l.extensions,r),v("skills",B(u.skills,"pi"),o,l.skills,r));for(const M of b){const E=w(M),G={...o,baseDir:E};v("skills",B(M,"agents"),G,l.skills,E)}d&&(v("prompts",ct(u.prompts),o,l.prompts,r),v("themes",lt(u.themes),o,l.themes,r)),v("extensions",Z(p.extensions),i,a.extensions,n),v("skills",B(p.skills,"pi"),i,a.skills,n);for(const M of g){const E=w(M),G={...i,baseDir:E};v("skills",B(M,"agents"),G,a.skills,E)}v("prompts",ct(p.prompts),i,a.prompts,n),v("themes",lt(p.themes),i,a.themes,n)}collectFilesFromPaths(t,e){const s=[];for(const n of t)if(f(n))try{const r=N(n);r.isFile()?s.push(n):r.isDirectory()&&s.push(...V(n,e))}catch{}return s}getTargetMap(t,e){switch(e){case"extensions":return t.extensions;case"skills":return t.skills;case"prompts":return t.prompts;case"themes":return t.themes;default:throw new Error(`Unknown resource type: ${e}`)}}addResource(t,e,s,n){e&&(t.has(e)||t.set(e,{metadata:s,enabled:n}))}createAccumulator(){return{extensions:new Map,skills:new Map,prompts:new Map,themes:new Map}}toResolvedPaths(t){const e=m(s=>{const n=Array.from(s.entries()).map(([i,{metadata:o,enabled:a}])=>({path:i,enabled:a,metadata:o}));n.sort((i,o)=>ot(i.metadata)-ot(o.metadata));const r=new Set;return n.filter(i=>{const o=bt(i.path);return r.has(o)?!1:(r.add(o),!0)})},"mapToResolved");return{extensions:e(t.extensions),skills:e(t.skills),prompts:e(t.prompts),themes:e(t.themes)}}spawnCommand(t,e,s){const n=Y();return nt(t,e,{cwd:s?.cwd,stdio:xt()?["ignore",2,2]:"inherit",env:n})}spawnCaptureCommand(t,e,s){const n=Y(),r=s?.env?{...n,...s.env}:n;return nt(t,e,{cwd:s?.cwd,stdio:["ignore","pipe","pipe"],env:r})}runCommandCapture(t,e,s){return new Promise((n,r)=>{const i=this.spawnCaptureCommand(t,e,s);let o="",a="",l=!1;const p=typeof s?.timeoutMs=="number"?setTimeout(()=>{l=!0,i.kill()},s.timeoutMs):void 0;i.stdout?.on("data",u=>{o+=u.toString()}),i.stderr?.on("data",u=>{a+=u.toString()}),i.once("error",u=>{p&&clearTimeout(p),r(u)}),i.once("close",(u,g)=>{if(p&&clearTimeout(p),l){r(new Error(`${t} ${e.join(" ")} timed out after ${s?.timeoutMs}ms`));return}if(u===0){n(o.trim());return}const P=u===null?`signal ${g??"unknown"}`:`code ${u}`;r(new Error(`${t} ${e.join(" ")} failed with ${P}: ${a||o}`))})})}runCommand(t,e,s){return new Promise((n,r)=>{const i=this.spawnCommand(t,e,s);i.on("error",r),i.on("exit",o=>{o===0?n():r(new Error(`${t} ${e.join(" ")} failed with code ${o}`))})})}runCommandSync(t,e){const s=Y(),n=Et(t,e,{stdio:["ignore","pipe","pipe"],encoding:"utf-8",env:s});if(n.error||n.status!==0)throw new Error(`Failed to run ${t} ${e.join(" ")}: ${n.error?.message||n.stderr||n.stdout}`);return(n.stdout||n.stderr||"").trim()}}export{me as DefaultPackageManager,Dt as NPM_ARGS_HOOK_SLOT,Ht as getExtensionTempFolder};
@@ -0,0 +1,45 @@
1
+ export type PermissionBehavior = "allow" | "deny" | "ask";
2
+ export type PermissionRuleSource = "user" | "project";
3
+ export interface PermissionRule {
4
+ readonly text: string;
5
+ readonly toolName: string;
6
+ readonly content?: string;
7
+ readonly source: PermissionRuleSource;
8
+ }
9
+ export interface PermissionRuleSet {
10
+ readonly allow: readonly PermissionRule[];
11
+ readonly deny: readonly PermissionRule[];
12
+ readonly ask: readonly PermissionRule[];
13
+ }
14
+ export interface RuleCall {
15
+ readonly toolName: string;
16
+ readonly input: Record<string, unknown>;
17
+ readonly cwd: string;
18
+ }
19
+ export interface RuleVerdict {
20
+ readonly behavior: PermissionBehavior;
21
+ readonly rule: string;
22
+ readonly source: PermissionRuleSource;
23
+ }
24
+ export type ReadOnlySegment = (segment: string) => boolean;
25
+ export declare const EMPTY_RULE_SET: PermissionRuleSet;
26
+ export declare function parsePermissionRule(text: string, source: PermissionRuleSource): PermissionRule | undefined;
27
+ export declare function buildRuleSet(sources: {
28
+ user?: {
29
+ allow?: unknown;
30
+ deny?: unknown;
31
+ ask?: unknown;
32
+ };
33
+ project?: {
34
+ allow?: unknown;
35
+ deny?: unknown;
36
+ ask?: unknown;
37
+ };
38
+ }): PermissionRuleSet;
39
+ export declare function targetPathOf(call: RuleCall): string | undefined;
40
+ export declare function pathPatternMatches(pattern: string, absolutePath: string, cwd: string): boolean;
41
+ export declare function matchPermissionRules(rules: PermissionRuleSet, call: RuleCall, readOnly: ReadOnlySegment): RuleVerdict | undefined;
42
+ export declare function readDenyPatterns(rules: PermissionRuleSet): Array<{
43
+ pattern: string;
44
+ rule: string;
45
+ }>;
@@ -0,0 +1 @@
1
+ var _=Object.defineProperty;var o=(n,e)=>_(n,"name",{value:e,configurable:!0});import{homedir as b}from"node:os";import{resolve as p,sep as h}from"node:path";import{resolveToCwd as R}from"../tools/path-utils.js";import{simpleCommands as N,unwrapCommand as W}from"./shell-words.js";const Z={allow:[],deny:[],ask:[]};function P(n,e){const t=n.trim();if(t.length===0||t.length>2e3)return;const r=t.indexOf("("),i=(r===-1?t:t.slice(0,r)).trim();if(!/^(?:\*|[A-Za-z_][A-Za-z0-9_.*-]*)$/.test(i))return;if(r===-1)return{text:t,toolName:i,source:e};if(!t.endsWith(")"))return;const s=t.slice(r+1,-1);if(s.trim().length!==0)return{text:t,toolName:i,content:s,source:e}}o(P,"parsePermissionRule");function Y(n){const e=o(t=>{const r=[];for(const i of["user","project"]){const s=n[i]?.[t];if(Array.isArray(s))for(const f of s){if(typeof f!="string")continue;const u=P(f,i);u&&r.push(u)}}return r},"collect");return{allow:e("allow"),deny:e("deny"),ask:e("ask")}}o(Y,"buildRuleSet");const E=new Set(["read","grep","find","ls","lsp"]);function a(n){switch(n.toolName){case"bash":case"powershell":return"bash";case"process":return n.input.action==="start"?"bash":"other";case"edit":return"edit";case"write":return"write";default:return E.has(n.toolName)?"read":"other"}}o(a,"familyOf");const O={Grep:"grep",Glob:"find",LS:"ls"};function m(n,e){const t=e.toolName;if(n==="*"||n===t)return!0;const r=a(e);switch(n){case"Bash":return r==="bash";case"Edit":case"MultiEdit":return r==="edit"||r==="write";case"Write":return r==="write";case"Read":return r==="read"}if(n.startsWith("mcp__")&&t.startsWith("mcp__")){const i=n.split("__"),s=t.split("__");return s.length>=3&&i[1]===s[1]?i.length===2||i.length===3&&i[2]==="*":!1}return O[n]===t}o(m,"ruleToolMatches");function S(n){for(let e=0;e<n.length;e++){if(n[e]!=="*")continue;let t=0;for(let r=e-1;r>=0&&n[r]==="\\";r--)t++;if(t%2===0)return!0}return!1}o(S,"hasUnescapedStar");function w(n){const e=/^(.+):\*$/.exec(n)?.[1];return e!==void 0?{type:"prefix",prefix:e}:S(n)?{type:"wildcard",pattern:n}:{type:"exact",command:n}}o(w,"parseShellPattern");function k(n,e){const t=n.trim();let r="",i=0;for(let s=0;s<t.length;s++){const f=t[s];f==="\\"&&(t[s+1]==="*"||t[s+1]==="\\")?(r+=`\\${t[s+1]}`,s++):f==="*"?(r+=".*",i++):r+=f.replace(/[.+?^${}()|[\]\\'"]/g,"\\$&")}return i===1&&r.endsWith(" .*")&&(r=`${r.slice(0,-3)}( .*)?`),new RegExp(`^${r}$`,"s").test(e)}o(k,"wildcardMatches");function c(n,e){const t=w(n);switch(t.type){case"exact":return t.command===e;case"prefix":return e===t.prefix||e.startsWith(`${t.prefix} `);case"wildcard":return k(t.pattern,e)}}o(c,"shellPatternMatches");const g=/\$\(|`|<\(|>\(/;function M(n){const e=n.words.map(f=>f.value),t=W(e);let r=t.words;if(t.opaque)for(r=r.slice(1);r[0]?.startsWith("-");)r=r.slice(1);const i=r.join(" "),s=e.join(" ");return{text:s,...i!==s&&i.length>0?{unwrapped:i}:{},redirects:n.redirects,dynamic:n.words.some(f=>f.dynamic)}}o(M,"segmentOf");function x(n){return n.split(g).flatMap(e=>N(e)).map(M).filter(e=>e.text.length>0)}o(x,"segmentsOf");function y(n){return typeof n.input.command=="string"?n.input.command.trim():""}o(y,"commandOf");function v(n,e){return e.length===0?!1:c(n,e)?!0:x(e).some(t=>c(n,t.text)||t.unwrapped!==void 0&&c(n,t.unwrapped))}o(v,"shellRuleHits");function A(n,e,t){if(e.length===0)return;const r=n.find(f=>{const u=w(f.content);return u.type==="exact"&&u.command===e});if(r)return r;if(g.test(e))return;const i=x(e);if(i.length===0)return;let s;for(const f of i){if(f.redirects||f.dynamic)return;const u=n.find($=>c($.content,f.text));if(u){s??=u;continue}if(!t(f.text))return}return s}o(A,"shellAllowRule");function d(n){return h==="/"?n:n.split(h).join("/")}o(d,"toSlashes");function j(n){let e="";for(let t=0;t<n.length;t++){const r=n[t];r==="*"?n[t+1]==="*"?n[t+2]==="/"?(e+="(?:.*/)?",t+=2):(e+=".*",t+=1):e+="[^/]*":r==="?"?e+="[^/]":e+=r.replace(/[.+^${}()|[\]\\]/g,"\\$&")}return new RegExp(`^${e}$`,process.platform==="win32"||process.platform==="darwin"?"i":"")}o(j,"globToRegExp");function U(n,e){let t=n.trim();if(t.endsWith("/")&&(t+="**"),t.startsWith("//"))return t.slice(1);if(t==="~"||t.startsWith("~/"))return d(b())+t.slice(1);const r=d(p(e)).replace(/\/$/,"");if(t.startsWith("/"))return r+t;const i=t.startsWith("./")?t.slice(2):t;return i.includes("/")?`${r}/${i}`:`${r}/**/${i}`}o(U,"absoluteGlob");function C(n){for(const e of["file_path","path","filePath"]){const t=n.input[e];if(typeof t=="string"&&t.length>0)return t}if(n.toolName==="grep"||n.toolName==="find"||n.toolName==="ls")return"."}o(C,"targetPathOf");function L(n,e,t){const r=j(U(n,t));let i=d(p(e));for(;;){if(r.test(i)||r.test(`${i}/`))return!0;const s=i.slice(0,i.lastIndexOf("/"));if(s.length===0||s===i)return!1;i=s}}o(L,"pathPatternMatches");function T(n,e){const t=C(e);return t===void 0?!1:L(n,R(t,e.cwd),e.cwd)}o(T,"pathRuleMatches");function D(n){for(const e of["command","file_path","path","filePath","url","query"]){const t=n.input[e];if(typeof t=="string"&&t.length>0)return t}}o(D,"contentOf");function l(n,e){if(!m(n.toolName,e))return!1;if(n.content===void 0)return!0;switch(a(e)){case"bash":return v(n.content,y(e));case"edit":case"write":case"read":return T(n.content,e);default:{const t=D(e);return t!==void 0&&c(n.content,t)}}}o(l,"ruleHits");function G(n,e,t){const r=n.filter(s=>m(s.toolName,e)),i=r.find(s=>s.content===void 0);return i||(a(e)==="bash"?A(r,y(e),t):r.find(s=>l(s,e)))}o(G,"allowingRule");function F(n,e,t){const r=n.deny.find(f=>l(f,e));if(r)return{behavior:"deny",rule:r.text,source:r.source};const i=n.ask.find(f=>l(f,e));if(i)return{behavior:"ask",rule:i.text,source:i.source};const s=G(n.allow,e,t);return s?{behavior:"allow",rule:s.text,source:s.source}:void 0}o(F,"matchPermissionRules");function J(n){return n.deny.filter(e=>e.toolName==="Read"&&e.content!==void 0).map(e=>({pattern:e.content,rule:e.text}))}o(J,"readDenyPatterns");export{Z as EMPTY_RULE_SET,Y as buildRuleSet,F as matchPermissionRules,P as parsePermissionRule,L as pathPatternMatches,J as readDenyPatterns,C as targetPathOf};
@@ -0,0 +1,2 @@
1
+ var a=Object.defineProperty;var f=(e,t)=>a(e,"name",{value:t,configurable:!0});function h(e){const t=[];let n="",i=!1,r=!1;const u=f(()=>{r&&t.push({kind:"word",word:{value:n,dynamic:i}}),n="",i=!1,r=!1},"flush");for(let s=0;s<e.length;s++){const l=e[s];if(l==="\\"&&s+1<e.length){n+=e[++s],r=!0;continue}if(l==="'"){const o=e.indexOf("'",s+1);n+=e.slice(s+1,o===-1?void 0:o),s=o===-1?e.length:o,r=!0;continue}if(l==='"'){for(s++;s<e.length&&e[s]!=='"';)e[s]==="\\"&&s+1<e.length&&'"\\$`'.includes(e[s+1])?s++:(e[s]==="$"||e[s]==="`")&&(i=!0),n+=e[s],s++;r=!0;continue}if(l==="$"||l==="`"){i=!0,n+=l,r=!0;continue}if(/\s/.test(l)){if(l===`
2
+ `){u(),t.push({kind:"separator"});continue}u();continue}if(l===";"||l==="|"||l==="("||l===")"){u(),t.push({kind:"separator"});continue}if(l==="&"){if(e[s+1]===">"){u(),s+=e[s+2]===">"?2:1,t.push({kind:"redirectOut"});continue}u(),t.push({kind:"separator"});continue}if(l===">"||l==="<"){if(r&&/^\d+$/.test(n)&&!i&&(n="",r=!1),u(),l==="<"){t.push({kind:"redirectOther"});continue}if((e[s+1]===">"||e[s+1]==="|")&&s++,e[s+1]==="&"){s++,t.push({kind:"redirectOther"});continue}t.push({kind:"redirectOut"});continue}n+=l,r=!0}return u(),t}f(h,"tokenize");function x(e){const t=[];let n=[],i=!1;const r=f(()=>{(n.length>0||i)&&t.push({words:n,redirects:i}),n=[],i=!1},"end");for(const u of h(e))u.kind==="separator"?r():u.kind==="word"?n.push(u.word):i=!0;return r(),t}f(x,"simpleCommands");const d=/^[A-Za-z_][A-Za-z0-9_]*=/,p=new Set(["sudo","doas","su","pkexec","runas"]);function k(e,t,n){let i=0;for(;i<e.length;){const r=e[i];if(r==="--")return i+1;if(!r.startsWith("-")||r==="-")return i;if(t.has(r)){i++;continue}if(n.has(r)){i+=2;continue}const u=r.indexOf("=");if(r.startsWith("--")&&u>0&&n.has(r.slice(0,u))){i++;continue}if(!r.startsWith("--")&&r.length>2&&n.has(r.slice(0,2))){i++;continue}return}return i}f(k,"skipOptions");function c(e,t,n){const i=new Set(e),r=new Set(t);return u=>{const s=k(u,i,r);if(s===void 0)return;const l=u.slice(s),o=n?n(l):l;return o===void 0?void 0:{rest:o}}}f(c,"readWith");const w=new Map([["env",e=>{let t=0,n=!1;for(;t<e.length;){const i=e[t];if(i==="--"){t++;break}if(d.test(i))n=!0;else if(i==="-u"||i==="--unset")t++;else if(!(i==="-i"||i==="-"||i==="--ignore-environment"||i==="-0"||i==="--null"||i==="-v"||i==="--debug"||i.startsWith("--unset=")||/^-u./.test(i))){if(i.startsWith("-"))return;break}t++}for(;t<e.length&&d.test(e[t]);)n=!0,t++;return{rest:e.slice(t),setsEnvironment:n}}],["command",e=>{let t=0,n=!1;for(;t<e.length&&/^-[pvV]+$/.test(e[t]);t++)n||=/[vV]/.test(e[t]);return{rest:n?["type",...e.slice(t)]:e.slice(t)}}],["builtin",e=>({rest:e})],["nohup",e=>({rest:e})],["time",c(["-p","-l","-h"],[])],["nice",e=>{let t=0;for(;t<e.length;){const n=e[t];if(n==="-n"||n==="--adjustment")t+=2;else if(/^-n?-?\d+$/.test(n)||n.startsWith("--adjustment="))t++;else if(n==="--"){t++;break}else{if(n.startsWith("-"))return;break}}return{rest:e.slice(t)}}],["timeout",c(["--preserve-status","--foreground","-v","--verbose"],["-s","--signal","-k","--kill-after"],e=>e.length>0?e.slice(1):void 0)],["xargs",c(["-0","--null","-r","--no-run-if-empty","-t","--verbose","-x","--exit","-p","--interactive","-o","--open-tty","-i","-e","-l"],["-I","-L","-n","-P","-s","-d","-E","-a","--arg-file","--delimiter","--max-args","--max-lines","--max-procs","--max-chars","--replace","--eof"],e=>e.length>0?e:["echo"])],["caffeinate",c(["-d","-i","-m","-s","-u"],["-t","-w"])],["stdbuf",c([],["-i","-o","-e","--input","--output","--error"])],["exec",c(["-c","-l","-cl","-lc"],["-a"])]]);function g(e){let t=e,n=!1;for(;;){const i=t[0];if(i===void 0)return{words:t,setsEnvironment:n,opaque:!1};if(d.test(i)){n=!0,t=t.slice(1);continue}const r=i.slice(i.lastIndexOf("/")+1);if(p.has(r))return{words:t,setsEnvironment:n,opaque:!0};const u=w.get(r);if(!u)return{words:t,setsEnvironment:n,opaque:!1};const s=u(t.slice(1));if(!s)return{words:t,setsEnvironment:n,opaque:!0};n||=s.setsEnvironment===!0,t=s.rest}}f(g,"unwrapCommand");export{x as simpleCommands,h as tokenize,g as unwrapCommand};
@@ -0,0 +1,46 @@
1
+ import type { ExtensionContext } from "../extensions/types.ts";
2
+ import { type PermissionRuleSet, type RuleCall, type RuleVerdict } from "./rules.ts";
3
+ export interface PermissionAskRequest {
4
+ toolCallId: string;
5
+ toolName: string;
6
+ input: Record<string, unknown>;
7
+ cwd: string;
8
+ rule: string;
9
+ source: RuleVerdict["source"];
10
+ }
11
+ export type PermissionAskHandler = (request: PermissionAskRequest, ctx: ExtensionContext) => Promise<{
12
+ approved: boolean;
13
+ message?: string;
14
+ } | undefined> | {
15
+ approved: boolean;
16
+ message?: string;
17
+ } | undefined;
18
+ export declare function registerPermissionAskHandler(handler: PermissionAskHandler): () => void;
19
+ export declare function permissionAskHandlers(): readonly PermissionAskHandler[];
20
+ export interface ReadGuard {
21
+ readonly deniedPaths: readonly string[];
22
+ readonly deniedPatterns: ReadonlyArray<{
23
+ pattern: string;
24
+ rule: string;
25
+ }>;
26
+ readonly cwd: string;
27
+ }
28
+ export declare function setProcessReadGuard(guard: ReadGuard | undefined): void;
29
+ export declare function readAccessDenial(absolutePath: string, guard?: ReadGuard | undefined): string | undefined;
30
+ export type ToolPolicyDecision = {
31
+ behavior: "deny";
32
+ reason: string;
33
+ } | {
34
+ behavior: "ask";
35
+ rule: string;
36
+ source: RuleVerdict["source"];
37
+ } | undefined;
38
+ export declare function evaluateToolPolicy(call: RuleCall, options: {
39
+ rules: PermissionRuleSet;
40
+ readGuard?: ReadGuard;
41
+ }): ToolPolicyDecision;
42
+ export declare function buildReadGuard(options: {
43
+ cwd: string;
44
+ rules: PermissionRuleSet;
45
+ protectedReads?: readonly string[];
46
+ }): ReadGuard | undefined;
@@ -0,0 +1 @@
1
+ var m=Object.defineProperty;var t=(e,n)=>m(e,"name",{value:n,configurable:!0});import{existsSync as h,realpathSync as p}from"node:fs";import{isAbsolute as y,relative as b,resolve as v}from"node:path";import{isReadOnlyBashCommand as R}from"../tools/bash-read-only.js";import{resolveToCwd as k}from"../tools/path-utils.js";import{matchPermissionRules as S,pathPatternMatches as g,readDenyPatterns as w,targetPathOf as x}from"./rules.js";const d=Symbol.for("dal.permissions.askHandlers"),a=globalThis;a[d]instanceof Set||(a[d]=new Set);const c=a[d];function O(e){return c.add(e),()=>{c.delete(e)}}t(O,"registerPermissionAskHandler");function j(){return[...c]}t(j,"permissionAskHandlers");let u;function B(e){u=e}t(B,"setProcessReadGuard");function l(e,n){const r=b(n,e);return r===""||!r.startsWith("..")&&!y(r)}t(l,"isWithin");function f(e){try{return h(e)?p(e):e}catch{return e}}t(f,"realpathOrSelf");function P(e,n=u){if(!n)return;const r=[...new Set([v(e),f(e)])];for(const s of n.deniedPaths){const o=f(s);if(r.some(i=>l(i,s)||l(i,o)))return`Reading ${e} is blocked: it is a protected credential location (${s}). The sandbox keeps it unreadable for every tool.`}for(const{pattern:s,rule:o}of n.deniedPatterns)if(r.some(i=>g(s,i,n.cwd)))return`Reading ${e} is blocked by the permission rule ${o}.`}t(P,"readAccessDenial");const A=new Set(["read","grep","find","ls","lsp"]);function C(e,n){if(A.has(e.toolName)&&n.readGuard){const s=x(e);if(s!==void 0){const o=P(k(s,e.cwd),n.readGuard);if(o)return{behavior:"deny",reason:o}}}const r=S(n.rules,e,R);if(r?.behavior==="deny")return{behavior:"deny",reason:`Blocked by the permission rule ${r.rule} (${r.source==="user"?"~/.dal/agent/settings.json":".dal/settings.json"}).`};if(r?.behavior==="ask")return{behavior:"ask",rule:r.rule,source:r.source}}t(C,"evaluateToolPolicy");function L(e){const n=w(e.rules),r=e.protectedReads??[];if(!(r.length===0&&n.length===0))return{cwd:e.cwd,deniedPaths:r,deniedPatterns:n}}t(L,"buildReadGuard");export{L as buildReadGuard,C as evaluateToolPolicy,j as permissionAskHandlers,P as readAccessDenial,O as registerPermissionAskHandler,B as setProcessReadGuard};
@@ -0,0 +1,18 @@
1
+ export declare const DEFAULT_MAP_MAX_DEPTH = 2;
2
+ export declare const DEFAULT_MAP_MAX_ENTRIES = 80;
3
+ export interface ProjectMapOptions {
4
+ maxDepth?: number;
5
+ maxEntries?: number;
6
+ }
7
+ export interface ProjectMap {
8
+ root: string;
9
+ directories: string[];
10
+ files: string[];
11
+ truncated: boolean;
12
+ maxDepth: number;
13
+ maxEntries: number;
14
+ }
15
+ export declare function buildProjectMap(root: string, options?: ProjectMapOptions): ProjectMap;
16
+ export declare function formatProjectMapCollapsed(map: ProjectMap): string;
17
+ export declare function formatProjectMapExpanded(map: ProjectMap): string;
18
+ export declare function formatProjectMapPrompt(map: ProjectMap): string;
@@ -0,0 +1,24 @@
1
+ import type { ResourceDiagnostic } from "./diagnostics.ts";
2
+ import { type SourceInfo } from "./source-info.ts";
3
+ export interface PromptTemplate {
4
+ name: string;
5
+ description: string;
6
+ argumentHint?: string;
7
+ content: string;
8
+ sourceInfo: SourceInfo;
9
+ filePath: string;
10
+ }
11
+ export declare function parseCommandArgs(argsString: string): string[];
12
+ export declare function substituteArgs(content: string, args: string[]): string;
13
+ export interface LoadPromptTemplatesOptions {
14
+ cwd: string;
15
+ agentDir: string;
16
+ promptPaths: string[];
17
+ includeDefaults: boolean;
18
+ }
19
+ export interface LoadPromptTemplatesResult {
20
+ templates: PromptTemplate[];
21
+ diagnostics: ResourceDiagnostic[];
22
+ }
23
+ export declare function loadPromptTemplates(options: LoadPromptTemplatesOptions): LoadPromptTemplatesResult;
24
+ export declare function expandPromptTemplate(text: string, templates: PromptTemplate[]): string;
@@ -0,0 +1,55 @@
1
+ import { type Api, type AssistantMessageEventStream, type Model, type OAuthCredentials, type OAuthLoginCallbacks, type Provider, type ProviderHeaders, type RefreshModelsContext, type SimpleStreamOptions, type TranscriptContext } from "@earendil-works/pi-ai";
2
+ import type { ModelConfig, ModelsJsonProvider } from "./model-config.ts";
3
+ import { clearConfigValueCache } from "./resolve-config-value.ts";
4
+ export interface ExtensionOAuthConfig {
5
+ name: string;
6
+ isSubscription?: boolean;
7
+ usesCallbackServer?: boolean;
8
+ login(callbacks: OAuthLoginCallbacks): Promise<OAuthCredentials>;
9
+ refreshToken(credentials: OAuthCredentials, signal: AbortSignal): Promise<OAuthCredentials>;
10
+ getApiKey(credentials: OAuthCredentials): string;
11
+ modifyModels?(models: Model<Api>[], credentials: OAuthCredentials): Model<Api>[];
12
+ }
13
+ export interface ProviderConfigInput {
14
+ name?: string;
15
+ baseUrl?: string;
16
+ apiKey?: string;
17
+ api?: Api;
18
+ streamSimple?: (model: Model<Api>, context: TranscriptContext, options?: SimpleStreamOptions) => AssistantMessageEventStream;
19
+ headers?: Record<string, string>;
20
+ authHeader?: boolean;
21
+ oauth?: ExtensionOAuthConfig;
22
+ models?: Array<{
23
+ id: string;
24
+ name: string;
25
+ api?: Api;
26
+ baseUrl?: string;
27
+ reasoning: boolean;
28
+ thinkingLevelMap?: Model<Api>["thinkingLevelMap"];
29
+ input: ("text" | "image")[];
30
+ inputLimits?: Model<Api>["inputLimits"];
31
+ cost: Model<Api>["cost"];
32
+ promptCache?: Model<Api>["promptCache"];
33
+ contextWindow: number;
34
+ maxTokens: number;
35
+ samplingParams?: Record<string, unknown>;
36
+ headers?: Record<string, string>;
37
+ compat?: Model<Api>["compat"];
38
+ }>;
39
+ refreshModels?(context: RefreshModelsContext): Promise<NonNullable<ProviderConfigInput["models"]>>;
40
+ }
41
+ export type AuthStatus = {
42
+ configured: boolean;
43
+ source?: "stored" | "runtime" | "environment" | "fallback" | "models_json_key" | "models_json_command";
44
+ label?: string;
45
+ };
46
+ export declare const clearApiKeyCache: typeof clearConfigValueCache;
47
+ export declare function validateExtensionProvider(providerId: string, base: Provider | undefined, modelsConfig: ModelsJsonProvider | undefined, extension: ProviderConfigInput): void;
48
+ export declare function composeModelProvider(providerId: string, base: Provider | undefined, modelConfig: ModelConfig, extension: ProviderConfigInput | undefined, onRefreshedModels?: (models: NonNullable<ProviderConfigInput["models"]>) => void): Provider;
49
+ export declare function resolveConfiguredModelHeaders(model: Model<Api>, config: ModelsJsonProvider | undefined, extension: ProviderConfigInput | undefined, env?: Record<string, string>): Record<string, string> | undefined;
50
+ export interface CompatibilityRequestConfig {
51
+ headers?: ProviderHeaders;
52
+ authHeader: boolean;
53
+ }
54
+ export declare function resolveCompatibilityRequestConfig(model: Model<Api>, config: ModelsJsonProvider | undefined, extension: ProviderConfigInput | undefined): CompatibilityRequestConfig;
55
+ export declare function configuredRequestAuthStatus(config: ModelsJsonProvider | undefined, extension: ProviderConfigInput | undefined): AuthStatus | undefined;
@@ -1 +1 @@
1
- var w=Object.defineProperty;var d=(t,e)=>w(t,"name",{value:e,configurable:!0});import{VERSION as A}from"../config.js";import{fetchWithRetry as b}from"../utils/management-http.js";import{getPiUserAgent as E}from"../utils/pi-user-agent.js";const T="https://pi.dev",_=4e3,R=14400*1e3;function O(t,e){const r=[...t];for(const i of e){const s=r.findIndex(o=>o.id===i.id);s>=0?r[s]=i:r.push(i)}return r}d(O,"mergeModels");function L(t,e){const r=Array.isArray(e)?e:typeof e=="object"&&e!==null&&"models"in e&&Array.isArray(e.models)?e.models:typeof e=="object"&&e!==null?Object.values(e):void 0;if(!r)throw new Error(`Invalid model catalog for provider "${t}"`);return r.filter(i=>typeof i=="object"&&i!==null&&"id"in i).map(i=>({...i,provider:t}))}d(L,"parseCatalog");function p(t,e){return t?e!==void 0&&(t.lastModified===void 0||t.lastModified<=e)?[]:t.models:[]}d(p,"remoteModels");function N(t,e=T,r){let i=[];return{...t,getModels:d(()=>O(t.getModels(),i),"getModels"),refreshModels:d(async s=>{const o=s.stored,c=p(o,r).filter(M=>M.provider===t.id);if(!await s.publish({update:d(()=>{i=c},"update")})||!s.allowNetwork||s.signal.aborted||!s.force&&o?.checkedAt!==void 0&&o.lastModified!==void 0&&Date.now()-o.checkedAt<R)return;const f=o?.models.length?o.etag:void 0,m=new URL(`/api/models/providers/${encodeURIComponent(t.id)}`,e),n=await b(m,{headers:{accept:"application/json","User-Agent":E(A),...f?{"if-none-match":f}:{}},signal:s.signal},{attemptTimeoutMs:_});if(s.signal.aborted)return;const a=Date.now();if(n.status===304&&o){await s.publish({persist:{...o,checkedAt:a}});return}if(n.status===404||n.status===501){await s.publish({persist:{...o??{models:[]},checkedAt:a,lastModified:0,etag:void 0}});return}if(!n.ok)throw await s.publish({persist:{...o??{models:[]},checkedAt:a}}),new Error(`Model catalog request failed for ${t.id}: ${n.status}`);const g=L(t.id,await n.json()),l=Date.parse(n.headers.get("last-modified")??"");if(s.signal.aborted)return;const u={models:g,checkedAt:a,lastModified:Number.isNaN(l)?0:l,etag:n.headers.get("etag")??void 0},h=p(u,r);await s.publish({persist:u,update:d(()=>{i=h},"update")})},"refreshModels")}}d(N,"withRemoteCatalog");export{R as REMOTE_CATALOG_REFRESH_INTERVAL_MS,N as withRemoteCatalog};
1
+ var A=Object.defineProperty;var d=(e,t)=>A(e,"name",{value:t,configurable:!0});import{APP_NAME as w,VERSION as E}from"../config.js";import{fetchWithRetry as b}from"../utils/management-http.js";import{getPiUserAgent as T}from"../utils/pi-user-agent.js";const _="https://pi.dev",R=4e3,O=14400*1e3;function U(e,t){const r=[...e];for(const i of t){const s=r.findIndex(o=>o.id===i.id);s>=0?r[s]=i:r.push(i)}return r}d(U,"mergeModels");function C(e,t){const r=Array.isArray(t)?t:typeof t=="object"&&t!==null&&"models"in t&&Array.isArray(t.models)?t.models:typeof t=="object"&&t!==null?Object.values(t):void 0;if(!r)throw new Error(`Invalid model catalog for provider "${e}"`);return r.filter(i=>typeof i=="object"&&i!==null&&"id"in i).map(i=>({...i,provider:e}))}d(C,"parseCatalog");function p(e,t){return e?t!==void 0&&(e.lastModified===void 0||e.lastModified<=t)?[]:e.models:[]}d(p,"remoteModels");function S(e=w){return e==="pi"?_:void 0}d(S,"getDefaultCatalogBaseUrl");function k(e,t,r){let i=[];return{...e,getModels:d(()=>U(e.getModels(),i),"getModels"),refreshModels:d(async s=>{const o=s.stored,c=p(o,r).filter(M=>M.provider===e.id);if(!await s.publish({update:d(()=>{i=c},"update")})||!s.allowNetwork||s.signal.aborted||!s.force&&o?.checkedAt!==void 0&&o.lastModified!==void 0&&Date.now()-o.checkedAt<O)return;const f=o?.models.length?o.etag:void 0,m=new URL(`/api/models/providers/${encodeURIComponent(e.id)}`,t),n=await b(m,{headers:{accept:"application/json","User-Agent":T(E),...f?{"if-none-match":f}:{}},signal:s.signal},{attemptTimeoutMs:R});if(s.signal.aborted)return;const a=Date.now();if(n.status===304&&o){await s.publish({persist:{...o,checkedAt:a}});return}if(n.status===404||n.status===501){await s.publish({persist:{...o??{models:[]},checkedAt:a,lastModified:0,etag:void 0}});return}if(!n.ok)throw await s.publish({persist:{...o??{models:[]},checkedAt:a}}),new Error(`Model catalog request failed for ${e.id}: ${n.status}`);const g=C(e.id,await n.json()),l=Date.parse(n.headers.get("last-modified")??"");if(s.signal.aborted)return;const u={models:g,checkedAt:a,lastModified:Number.isNaN(l)?0:l,etag:n.headers.get("etag")??void 0},h=p(u,r);await s.publish({persist:u,update:d(()=>{i=h},"update")})},"refreshModels")}}d(k,"withRemoteCatalog");export{O as REMOTE_CATALOG_REFRESH_INTERVAL_MS,S as getDefaultCatalogBaseUrl,k as withRemoteCatalog};
@@ -0,0 +1,11 @@
1
+ export declare function getConfigValueEnvVarName(config: string): string | undefined;
2
+ export declare function getConfigValueEnvVarNames(config: string): string[];
3
+ export declare function getMissingConfigValueEnvVarNames(config: string, env?: Record<string, string>): string[];
4
+ export declare function isCommandConfigValue(config: string): boolean;
5
+ export declare function isConfigValueConfigured(config: string, env?: Record<string, string>): boolean;
6
+ export declare function resolveConfigValue(config: string, env?: Record<string, string>): string | undefined;
7
+ export declare function resolveConfigValueUncached(config: string, env?: Record<string, string>): string | undefined;
8
+ export declare function resolveConfigValueOrThrow(config: string, description: string, env?: Record<string, string>): string;
9
+ export declare function resolveHeaders(headers: Record<string, string> | undefined, env?: Record<string, string>): Record<string, string> | undefined;
10
+ export declare function resolveHeadersOrThrow(headers: Record<string, string> | undefined, description: string, env?: Record<string, string>): Record<string, string> | undefined;
11
+ export declare function clearConfigValueCache(): void;