dal-code 1.0.44 → 1.0.46

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 (780) hide show
  1. package/CHANGELOG.md +103 -0
  2. package/NOTICE +66 -1
  3. package/PRIVACY.md +159 -102
  4. package/dal-docs/README.md +1 -1
  5. package/dal-docs/keybindings.md +1 -0
  6. package/dal-docs/settings.md +5 -0
  7. package/dist/bun/register-bedrock.js +1 -0
  8. package/dist/cli/args.js +2 -2
  9. package/dist/cli/auth-check.js +1 -1
  10. package/dist/cli/auth-command.js +6 -5
  11. package/dist/cli/credential-print.js +1 -1
  12. package/dist/cli/experimental/auth.js +1 -0
  13. package/dist/cli/experimental/cli.js +1 -0
  14. package/dist/cli/experimental/command-options.js +1 -0
  15. package/dist/cli/experimental/command.js +1 -0
  16. package/dist/cli/experimental/commands/client.js +1 -0
  17. package/dist/cli/experimental/commands/pi.js +1 -0
  18. package/dist/cli/experimental/commands/server.js +1 -0
  19. package/dist/cli/experimental/transport-address.js +1 -0
  20. package/dist/cli/list-models.js +2 -2
  21. package/dist/cli/piped-stdin.js +2 -0
  22. package/dist/cli/startup-diagnostics.js +1 -0
  23. package/dist/client/index.js +1 -0
  24. package/dist/client/remote-session.js +1 -0
  25. package/dist/client/transcript.js +1 -0
  26. package/dist/config.d.ts +1 -0
  27. package/dist/config.js +1 -1
  28. package/dist/core/agent-log.d.ts +6 -0
  29. package/dist/core/agent-log.js +3 -0
  30. package/dist/core/agent-session-runtime.js +1 -1
  31. package/dist/core/agent-session-services.d.ts +0 -1
  32. package/dist/core/agent-session-services.js +1 -1
  33. package/dist/core/agent-session.d.ts +20 -3
  34. package/dist/core/agent-session.js +8 -8
  35. package/dist/core/auth-storage.js +1 -1
  36. package/dist/core/background-processes.js +7 -7
  37. package/dist/core/client-identity.js +1 -0
  38. package/dist/core/compaction/branch-summarization.js +3 -3
  39. package/dist/core/compaction/compaction.d.ts +2 -2
  40. package/dist/core/compaction/compaction.js +11 -9
  41. package/dist/core/compaction-backoff.js +1 -0
  42. package/dist/core/dal-session-headers.js +1 -0
  43. package/dist/core/export-html/index.js +2 -2
  44. package/dist/core/export-html/template.html +1 -0
  45. package/dist/core/export-html/template.js +35 -35
  46. package/dist/core/export-html/vendor/marked-cjk-friendly.min.js +6 -0
  47. package/dist/core/export-html/vendor/marked.min.js +30 -29
  48. package/dist/core/extensions/loader.js +1 -1
  49. package/dist/core/extensions/runner.d.ts +6 -0
  50. package/dist/core/extensions/runner.js +1 -1
  51. package/dist/core/extensions/types.d.ts +6 -1
  52. package/dist/core/extensions/virtual-modules.js +1 -1
  53. package/dist/core/http-dispatcher.js +1 -1
  54. package/dist/core/key-id-schema.js +1 -0
  55. package/dist/core/keybindings-schema.js +1 -0
  56. package/dist/core/keybindings.d.ts +5 -0
  57. package/dist/core/keybindings.js +1 -1
  58. package/dist/core/model-config.d.ts +1805 -102
  59. package/dist/core/model-config.js +4 -4
  60. package/dist/core/model-identity.js +2 -0
  61. package/dist/core/model-resolver.d.ts +30 -10
  62. package/dist/core/model-resolver.js +1 -1
  63. package/dist/core/model-runtime.d.ts +3 -0
  64. package/dist/core/model-runtime.js +2 -2
  65. package/dist/core/package-manager.d.ts +7 -0
  66. package/dist/core/package-manager.js +2 -2
  67. package/dist/core/permissions/shell-words.d.ts +26 -0
  68. package/dist/core/project-trust.js +2 -2
  69. package/dist/core/prompt-templates.js +2 -2
  70. package/dist/core/provider-attribution.js +1 -1
  71. package/dist/core/provider-composer.d.ts +2 -1
  72. package/dist/core/provider-composer.js +1 -1
  73. package/dist/core/remote-catalog-provider.js +1 -1
  74. package/dist/core/resource-loader.js +1 -1
  75. package/dist/core/sandbox/bwrap-placeholders.js +1 -1
  76. package/dist/core/sandbox/index.d.ts +1 -1
  77. package/dist/core/sandbox/index.js +1 -1
  78. package/dist/core/sandbox/libreoffice.js +1 -0
  79. package/dist/core/sandbox/policy.d.ts +4 -0
  80. package/dist/core/sandbox/policy.js +1 -1
  81. package/dist/core/sandbox/runtime.d.ts +3 -0
  82. package/dist/core/sandbox/runtime.js +1 -1
  83. package/dist/core/sandbox/shell-sandbox.d.ts +2 -0
  84. package/dist/core/sandbox/shell-sandbox.js +6 -6
  85. package/dist/core/sandbox/windows.js +4 -4
  86. package/dist/core/sdk.js +1 -1
  87. package/dist/core/session-manager.d.ts +1 -0
  88. package/dist/core/session-manager.js +12 -12
  89. package/dist/core/session-stall-monitor.d.ts +41 -0
  90. package/dist/core/session-stall-monitor.js +2 -0
  91. package/dist/core/settings-defaults.js +1 -0
  92. package/dist/core/settings-manager.d.ts +9 -0
  93. package/dist/core/settings-manager.js +1 -1
  94. package/dist/core/settings-schema.d.ts +231 -0
  95. package/dist/core/settings-schema.js +1 -0
  96. package/dist/core/stall-watchdog.d.ts +55 -0
  97. package/dist/core/stall-watchdog.js +1 -0
  98. package/dist/core/system-prompt.js +10 -10
  99. package/dist/core/tools/bash-read-only.d.ts +1 -0
  100. package/dist/core/tools/bash.d.ts +1 -0
  101. package/dist/core/tools/bash.js +14 -14
  102. package/dist/core/tools/edit.d.ts +1 -1
  103. package/dist/core/tools/edit.js +3 -3
  104. package/dist/core/tools/grep.js +1 -1
  105. package/dist/core/tools/path-utils.d.ts +1 -0
  106. package/dist/core/tools/path-utils.js +1 -1
  107. package/dist/core/tools/read.js +12 -12
  108. package/dist/core/tools/render-utils.d.ts +40 -0
  109. package/dist/core/tools/render-utils.js +7 -7
  110. package/dist/core/tools/renderers/read.js +8 -8
  111. package/dist/core/trust-manager.js +1 -1
  112. package/dist/core/workspace-lock.d.ts +6 -2
  113. package/dist/core/workspace-lock.js +3 -3
  114. package/dist/dal/builtins.js +2 -2
  115. package/dist/dal/extension-compat.js +4 -4
  116. package/dist/dal/hooks/config.d.ts +5 -1
  117. package/dist/dal/hooks/config.js +1 -1
  118. package/dist/dal/hooks/extension.js +3 -3
  119. package/dist/dal/hooks/index.d.ts +1 -1
  120. package/dist/dal/hooks/index.js +1 -1
  121. package/dist/dal/i18n.js +1 -1
  122. package/dist/dal/manifest.d.ts +1 -0
  123. package/dist/dal/manifest.js +1 -1
  124. package/dist/dal/safety-net.js +3 -1
  125. package/dist/extensions/codemode/execute.js +22 -15
  126. package/dist/extensions/codemode/index.js +1 -1
  127. package/dist/extensions/codemode/renderer.js +6 -6
  128. package/dist/extensions/codemode/tool.d.ts +2 -3
  129. package/dist/extensions/codemode/tool.js +9 -12
  130. package/dist/extensions/mcp/cli.js +4 -4
  131. package/dist/extensions/mcp/config.js +2 -2
  132. package/dist/extensions/mcp/index.js +12 -12
  133. package/dist/extensions/mcp/oauth.js +2 -2
  134. package/dist/extensions/mcp/resources.d.ts +0 -5
  135. package/dist/extensions/mcp/resources.js +1 -1
  136. package/dist/extensions/mcp/runtime.d.ts +1 -4
  137. package/dist/extensions/mcp/runtime.js +3 -3
  138. package/dist/extensions/mcp/tools.js +7 -7
  139. package/dist/extensions/tool-search/tool.js +3 -3
  140. package/dist/index.d.ts +7 -3
  141. package/dist/index.js +1 -1
  142. package/dist/main.js +4 -4
  143. package/dist/migrations.js +3 -5
  144. package/dist/modes/interactive/components/daxnuts.js +1 -0
  145. package/dist/modes/interactive/components/settings-selector.d.ts +3 -1
  146. package/dist/modes/interactive/components/settings-selector.js +1 -1
  147. package/dist/modes/interactive/components/status-indicator.d.ts +1 -1
  148. package/dist/modes/interactive/components/status-indicator.js +1 -1
  149. package/dist/modes/interactive/components/tree-selector.js +1 -1
  150. package/dist/modes/interactive/external-editor.js +1 -1
  151. package/dist/modes/interactive/interactive-mode.d.ts +7 -7
  152. package/dist/modes/interactive/interactive-mode.js +26 -26
  153. package/dist/modes/interactive/session-share.js +2 -2
  154. package/dist/modes/interactive/theme/dark.json +1 -1
  155. package/dist/modes/interactive/theme/light.json +1 -1
  156. package/dist/modes/interactive/theme/theme-json.js +4 -4
  157. package/dist/modes/interactive/theme/theme-schema.d.ts +18 -0
  158. package/dist/modes/interactive/theme/theme-schema.js +12 -0
  159. package/dist/modes/interactive/theme/theme-schema.json +2 -7
  160. package/dist/modes/interactive/theme/theme-tokens.d.ts +255 -0
  161. package/dist/modes/interactive/theme/theme-tokens.js +1 -0
  162. package/dist/modes/interactive/theme/theme.d.ts +7 -10
  163. package/dist/modes/interactive/theme/theme.js +5 -5
  164. package/dist/modes/print-mode.d.ts +1 -0
  165. package/dist/modes/print-mode.js +8 -7
  166. package/dist/modes/rpc/rpc-client.d.ts +5 -1
  167. package/dist/modes/rpc/rpc-client.js +3 -3
  168. package/dist/modes/rpc/rpc-mode.js +1 -1
  169. package/dist/modes/rpc/rpc-types.d.ts +20 -0
  170. package/dist/node_modules/@dalcode/dal-advisor/package.json +3 -3
  171. package/dist/node_modules/@dalcode/dal-advisor/src/index.js +8 -8
  172. package/dist/node_modules/@dalcode/dal-awake/package.json +2 -2
  173. package/dist/node_modules/@dalcode/dal-bridge/package.json +2 -2
  174. package/dist/node_modules/@dalcode/dal-capabilities/package.json +4 -4
  175. package/dist/node_modules/@dalcode/dal-capabilities/src/catalogue.js +1 -1
  176. package/dist/node_modules/@dalcode/dal-capabilities/src/index.js +9 -9
  177. package/dist/node_modules/@dalcode/dal-capabilities/src/match.js +1 -1
  178. package/dist/node_modules/@dalcode/dal-capabilities/src/state.js +3 -3
  179. package/dist/node_modules/@dalcode/dal-codeindex/package.json +34 -0
  180. package/dist/node_modules/@dalcode/dal-codeindex/src/extract.js +3 -0
  181. package/dist/node_modules/@dalcode/dal-codeindex/src/format.js +11 -0
  182. package/dist/node_modules/@dalcode/dal-codeindex/src/index.js +4 -0
  183. package/dist/node_modules/@dalcode/dal-codeindex/src/indexer.js +1 -0
  184. package/dist/node_modules/@dalcode/dal-codeindex/src/languages.js +176 -0
  185. package/dist/node_modules/@dalcode/dal-codeindex/src/project.js +1 -0
  186. package/dist/node_modules/@dalcode/dal-codeindex/src/query.js +2 -0
  187. package/dist/node_modules/@dalcode/dal-codeindex/src/runtime.js +1 -0
  188. package/dist/node_modules/@dalcode/dal-codeindex/src/scan.js +1 -0
  189. package/dist/node_modules/@dalcode/dal-codeindex/src/semantic.js +2 -0
  190. package/dist/node_modules/@dalcode/dal-codeindex/src/sqlite.js +1 -0
  191. package/dist/node_modules/@dalcode/dal-codeindex/src/store.js +33 -0
  192. package/dist/node_modules/@dalcode/dal-codeindex/src/worker.js +1 -0
  193. package/dist/node_modules/@dalcode/dal-compat/package.json +2 -2
  194. package/dist/node_modules/@dalcode/dal-dap/package.json +2 -2
  195. package/dist/node_modules/@dalcode/dal-dap/src/install.js +2 -2
  196. package/dist/node_modules/@dalcode/dal-gateway/package.json +2 -2
  197. package/dist/node_modules/@dalcode/dal-goal/package.json +3 -3
  198. package/dist/node_modules/@dalcode/dal-guard/package.json +5 -4
  199. package/dist/node_modules/@dalcode/dal-guard/src/credentials.js +7 -1
  200. package/dist/node_modules/@dalcode/dal-guard/src/edit-anchor-core.js +25 -23
  201. package/dist/node_modules/@dalcode/dal-guard/src/edit-anchor.js +4 -4
  202. package/dist/node_modules/@dalcode/dal-guard/src/index.js +4 -2
  203. package/dist/node_modules/@dalcode/dal-guard/src/mode.js +2 -2
  204. package/dist/node_modules/@dalcode/dal-guard/src/policy.js +1 -0
  205. package/dist/node_modules/@dalcode/dal-guard/src/session-files.js +1 -0
  206. package/dist/node_modules/@dalcode/dal-guard/src/suspicion.js +1 -0
  207. package/dist/node_modules/@dalcode/dal-guard/src/workspace.js +2 -2
  208. package/dist/node_modules/@dalcode/dal-halo/package.json +1 -1
  209. package/dist/node_modules/@dalcode/dal-interactive/package.json +2 -2
  210. package/dist/node_modules/@dalcode/dal-lang/package.json +3 -3
  211. package/dist/node_modules/@dalcode/dal-learn/package.json +4 -2
  212. package/dist/node_modules/@dalcode/dal-learn/src/engine.js +4 -4
  213. package/dist/node_modules/@dalcode/dal-learn/src/index.js +15 -14
  214. package/dist/node_modules/@dalcode/dal-learn/src/revisions.js +3 -0
  215. package/dist/node_modules/@dalcode/dal-learn/src/safety.js +1 -1
  216. package/dist/node_modules/@dalcode/dal-learn/src/skill-evolution.js +14 -14
  217. package/dist/node_modules/@dalcode/dal-lsp/package.json +5 -3
  218. package/dist/node_modules/@dalcode/dal-lsp/src/config.js +1 -1
  219. package/dist/node_modules/@dalcode/dal-lsp/src/index.js +14 -11
  220. package/dist/node_modules/@dalcode/dal-lsp/src/managed.js +1 -0
  221. package/dist/node_modules/@dalcode/dal-mcp/package.json +8 -5
  222. package/dist/node_modules/@dalcode/dal-mcp/src/child-env.js +3 -0
  223. package/dist/node_modules/@dalcode/dal-mcp/src/http-client.d.ts +9 -27
  224. package/dist/node_modules/@dalcode/dal-mcp/src/http-client.js +1 -2
  225. package/dist/node_modules/@dalcode/dal-mcp/src/index.js +17 -17
  226. package/dist/node_modules/@dalcode/dal-mcp/src/protocol-client.d.ts +38 -0
  227. package/dist/node_modules/@dalcode/dal-mcp/src/protocol-client.js +1 -0
  228. package/dist/node_modules/@dalcode/dal-mcp/src/proxy.js +6 -6
  229. package/dist/node_modules/@dalcode/dal-mcp/src/resources.js +1 -0
  230. package/dist/node_modules/@dalcode/dal-mcp/src/stdio-client.d.ts +10 -18
  231. package/dist/node_modules/@dalcode/dal-mcp/src/stdio-client.js +4 -5
  232. package/dist/node_modules/@dalcode/dal-mcp/src/types.d.ts +50 -5
  233. package/dist/node_modules/@dalcode/dal-mcp/src/types.js +1 -1
  234. package/dist/node_modules/@dalcode/dal-office/package.json +3 -2
  235. package/dist/node_modules/@dalcode/dal-office/src/extract/cell.js +1 -0
  236. package/dist/node_modules/@dalcode/dal-office/src/extract/index.js +2 -2
  237. package/dist/node_modules/@dalcode/dal-office/src/extract/ooxml.js +4 -4
  238. package/dist/node_modules/@dalcode/dal-office/src/extract/pdf.js +4 -4
  239. package/dist/node_modules/@dalcode/dal-office/src/facts.d.ts +15 -0
  240. package/dist/node_modules/@dalcode/dal-office/src/facts.js +4 -0
  241. package/dist/node_modules/@dalcode/dal-office/src/index.js +1 -1
  242. package/dist/node_modules/@dalcode/dal-office/src/lazy.js +1 -0
  243. package/dist/node_modules/@dalcode/dal-office/src/{index.d.ts → office.d.ts} +4 -5
  244. package/dist/node_modules/@dalcode/dal-office/src/office.js +1 -0
  245. package/dist/node_modules/@dalcode/dal-office/src/render/capture.d.ts +21 -0
  246. package/dist/node_modules/@dalcode/dal-office/src/render/capture.js +13 -0
  247. package/dist/node_modules/@dalcode/dal-office/src/render/chart.d.ts +15 -0
  248. package/dist/node_modules/@dalcode/dal-office/src/render/chart.js +3 -3
  249. package/dist/node_modules/@dalcode/dal-office/src/render/docx.d.ts +4 -0
  250. package/dist/node_modules/@dalcode/dal-office/src/render/docx.js +1 -1
  251. package/dist/node_modules/@dalcode/dal-office/src/render/pptx.d.ts +10 -0
  252. package/dist/node_modules/@dalcode/dal-office/src/render/pptx.js +4 -3
  253. package/dist/node_modules/@dalcode/dal-office/src/render/table-layout.js +1 -0
  254. package/dist/node_modules/@dalcode/dal-office/src/render/xlsx-chart.d.ts +24 -0
  255. package/dist/node_modules/@dalcode/dal-office/src/render/xlsx-chart.js +1 -0
  256. package/dist/node_modules/@dalcode/dal-office/src/render/xlsx.d.ts +9 -0
  257. package/dist/node_modules/@dalcode/dal-office/src/render/xlsx.js +1 -1
  258. package/dist/node_modules/@dalcode/dal-office/src/scratchpad.d.ts +2 -0
  259. package/dist/node_modules/@dalcode/dal-office/src/scratchpad.js +1 -1
  260. package/dist/node_modules/@dalcode/dal-office/src/table-stats.js +2 -0
  261. package/dist/node_modules/@dalcode/dal-office/src/themes.d.ts +2 -0
  262. package/dist/node_modules/@dalcode/dal-office/src/themes.js +1 -1
  263. package/dist/node_modules/@dalcode/dal-office/src/tools/chart-generate.js +4 -3
  264. package/dist/node_modules/@dalcode/dal-office/src/tools/doc-generate.js +2 -3
  265. package/dist/node_modules/@dalcode/dal-office/src/tools/docx-edit.js +5 -5
  266. package/dist/node_modules/@dalcode/dal-office/src/tools/drawio-generate.js +2 -3
  267. package/dist/node_modules/@dalcode/dal-office/src/tools/md-generate.js +2 -3
  268. package/dist/node_modules/@dalcode/dal-office/src/tools/ppt-generate.js +5 -2
  269. package/dist/node_modules/@dalcode/dal-office/src/tools/ppt-plan.js +4 -2
  270. package/dist/node_modules/@dalcode/dal-office/src/tools/pptx-edit.js +5 -5
  271. package/dist/node_modules/@dalcode/dal-office/src/tools/read-file.js +4 -3
  272. package/dist/node_modules/@dalcode/dal-office/src/tools/render-page.js +4 -0
  273. package/dist/node_modules/@dalcode/dal-office/src/tools/sheet-generate.js +3 -3
  274. package/dist/node_modules/@dalcode/dal-office/src/tools/xlsx-edit.js +3 -3
  275. package/dist/node_modules/@dalcode/dal-pi-kit/dist/i18n.js +19 -13
  276. package/dist/node_modules/@dalcode/dal-pi-kit/dist/index.js +1 -1
  277. package/dist/node_modules/@dalcode/dal-pi-kit/dist/project-size.js +1 -0
  278. package/dist/node_modules/@dalcode/dal-pi-kit/dist/session-scope.js +1 -0
  279. package/dist/node_modules/@dalcode/dal-pi-kit/package.json +1 -1
  280. package/dist/node_modules/@dalcode/dal-pi-kit/src/i18n.js +19 -13
  281. package/dist/node_modules/@dalcode/dal-pi-kit/src/index.js +1 -1
  282. package/dist/node_modules/@dalcode/dal-pi-kit/src/project-size.js +1 -0
  283. package/dist/node_modules/@dalcode/dal-pi-kit/src/session-scope.js +1 -0
  284. package/dist/node_modules/@dalcode/dal-plugins/package.json +4 -5
  285. package/dist/node_modules/@dalcode/dal-plugins/src/brand.js +1 -1
  286. package/dist/node_modules/@dalcode/dal-plugins/src/index.js +10 -10
  287. package/dist/node_modules/@dalcode/dal-plugins/src/manage.js +7 -7
  288. package/dist/node_modules/@dalcode/dal-recall/package.json +2 -2
  289. package/dist/node_modules/@dalcode/dal-recall/src/index.js +1 -1
  290. package/dist/node_modules/@dalcode/dal-remote/package.json +2 -2
  291. package/dist/node_modules/@dalcode/dal-review/package.json +3 -3
  292. package/dist/node_modules/@dalcode/dal-rewind/package.json +2 -2
  293. package/dist/node_modules/@dalcode/dal-rewind/src/commands.js +1 -1
  294. package/dist/node_modules/@dalcode/dal-rewind/src/core.d.ts +2 -1
  295. package/dist/node_modules/@dalcode/dal-rewind/src/core.js +8 -8
  296. package/dist/node_modules/@dalcode/dal-rewind/src/index.js +1 -1
  297. package/dist/node_modules/@dalcode/dal-rewind/src/state.js +1 -1
  298. package/dist/node_modules/@dalcode/dal-router/package.json +13 -10
  299. package/dist/node_modules/@dalcode/dal-router/src/advisor.js +1 -1
  300. package/dist/node_modules/@dalcode/dal-router/src/commands.js +8 -8
  301. package/dist/node_modules/@dalcode/dal-router/src/config.d.ts +12 -34
  302. package/dist/node_modules/@dalcode/dal-router/src/config.js +2 -2
  303. package/dist/node_modules/@dalcode/dal-router/src/index.js +2 -4
  304. package/dist/node_modules/@dalcode/dal-router/src/notice.js +1 -0
  305. package/dist/node_modules/@dalcode/dal-router/src/roles/changes.js +5 -0
  306. package/dist/node_modules/@dalcode/dal-router/src/roles/deliverables.js +4 -0
  307. package/dist/node_modules/@dalcode/dal-router/src/roles/index.js +15 -0
  308. package/dist/node_modules/@dalcode/dal-router/src/roles/models.d.ts +50 -0
  309. package/dist/node_modules/@dalcode/dal-router/src/roles/models.js +1 -0
  310. package/dist/node_modules/@dalcode/dal-router/src/roles/planner.js +4 -0
  311. package/dist/node_modules/@dalcode/dal-router/src/roles/prompts.js +42 -0
  312. package/dist/node_modules/@dalcode/dal-router/src/roles/signals.js +2 -0
  313. package/dist/node_modules/@dalcode/dal-router/src/runtime.d.ts +3 -13
  314. package/dist/node_modules/@dalcode/dal-router/src/runtime.js +1 -1
  315. package/dist/node_modules/@dalcode/dal-router/src/subagent.js +1 -1
  316. package/dist/node_modules/@dalcode/dal-router/src/task-shape.d.ts +8 -0
  317. package/dist/node_modules/@dalcode/dal-router/src/task-shape.js +1 -0
  318. package/dist/node_modules/@dalcode/dal-rtk/package.json +2 -2
  319. package/dist/node_modules/@dalcode/dal-skills/package.json +4 -3
  320. package/dist/node_modules/@dalcode/dal-skills/src/bundled/chart-design/SKILL.md +35 -0
  321. package/dist/node_modules/@dalcode/dal-skills/src/bundled/dal-slides/SKILL.md +82 -0
  322. package/dist/node_modules/@dalcode/dal-skills/src/bundled/diagram-design/SKILL.md +7 -5
  323. package/dist/node_modules/@dalcode/dal-skills/src/bundled/poster-design/SKILL.md +8 -6
  324. package/dist/node_modules/@dalcode/dal-skills/src/bundled/print-design/SKILL.md +21 -8
  325. package/dist/node_modules/@dalcode/dal-skills/src/bundled/visual-kit/diagram.html +1 -1
  326. package/dist/node_modules/@dalcode/dal-skills/src/bundled/visual-kit/mindmap.html +1 -1
  327. package/dist/node_modules/@dalcode/dal-skills/src/bundled/visual-kit/posters/event-poster.html +1 -1
  328. package/dist/node_modules/@dalcode/dal-skills/src/bundled/visual-kit/posters/poster.css +1 -1
  329. package/dist/node_modules/@dalcode/dal-skills/src/bundled/visual-kit/posters/square-card.html +1 -1
  330. package/dist/node_modules/@dalcode/dal-skills/src/bundled/visual-kit/posters/wechat-cover.html +1 -1
  331. package/dist/node_modules/@dalcode/dal-skills/src/bundled/visual-kit/posters/xhs-card.html +1 -1
  332. package/dist/node_modules/@dalcode/dal-skills/src/bundled/visual-kit/posters/xhs-cover.html +8 -5
  333. package/dist/node_modules/@dalcode/dal-skills/src/bundled/visual-kit/print/letter.html +1 -1
  334. package/dist/node_modules/@dalcode/dal-skills/src/bundled/visual-kit/print/report.html +1 -1
  335. package/dist/node_modules/@dalcode/dal-skills/src/bundled/visual-kit/print/resume.html +7 -3
  336. package/dist/node_modules/@dalcode/dal-skills/src/bundled/web-design/SKILL.md +4 -4
  337. package/dist/node_modules/@dalcode/dal-skills/src/bundled.js +1 -1
  338. package/dist/node_modules/@dalcode/dal-skills/src/catalog.js +3 -2
  339. package/dist/node_modules/@dalcode/dal-skills/src/client.js +1 -1
  340. package/dist/node_modules/@dalcode/dal-skills/src/hint.js +1 -0
  341. package/dist/node_modules/@dalcode/dal-skills/src/index.js +13 -14
  342. package/dist/node_modules/@dalcode/dal-skills/src/packages.js +3 -3
  343. package/dist/node_modules/@dalcode/dal-skills/src/search.js +1 -1
  344. package/dist/node_modules/@dalcode/dal-statusline/package.json +2 -2
  345. package/dist/node_modules/@dalcode/dal-structured/package.json +2 -2
  346. package/dist/node_modules/@dalcode/dal-subagent/package.json +5 -5
  347. package/dist/node_modules/@dalcode/dal-subagent/src/background.js +10 -10
  348. package/dist/node_modules/@dalcode/dal-subagent/src/index.js +18 -20
  349. package/dist/node_modules/@dalcode/dal-telemetry/package.json +3 -3
  350. package/dist/node_modules/@dalcode/dal-terminal/package.json +2 -2
  351. package/dist/node_modules/@dalcode/dal-tool-catalog/package.json +2 -2
  352. package/dist/node_modules/@dalcode/dal-tool-catalog/src/groups.js +1 -1
  353. package/dist/node_modules/@dalcode/dal-tool-catalog/src/index.js +4 -4
  354. package/dist/node_modules/@dalcode/dal-usage/package.json +2 -2
  355. package/dist/node_modules/@dalcode/dal-web/package.json +3 -3
  356. package/dist/node_modules/@dalcode/dal-workflow/LICENSE +27 -0
  357. package/dist/node_modules/@dalcode/dal-workflow/package.json +2 -2
  358. package/dist/node_modules/@dalcode/dal-workflow/src/announce-check.js +3 -1
  359. package/dist/node_modules/@dalcode/dal-workflow/src/deliverable-scope.js +1 -0
  360. package/dist/node_modules/@dalcode/dal-workflow/src/index.js +4 -4
  361. package/dist/node_modules/@dalcode/dal-workflow/src/plan-mode.js +13 -13
  362. package/dist/node_modules/@dalcode/dal-workflow/src/test-proof-note.js +3 -0
  363. package/dist/node_modules/@dalcode/dal-workflow/src/todo-snapshot.js +2 -0
  364. package/dist/node_modules/@dalcode/dal-workflow/src/todo.js +3 -3
  365. package/dist/node_modules/@dalcode/dal-workflow/src/truncation-check.js +1 -0
  366. package/dist/node_modules/@dalcode/dal-workflow/src/working-contract.js +1 -1
  367. package/dist/node_modules/@dalcode/deepailab/package.json +3 -3
  368. package/dist/node_modules/@dalcode/deepailab/src/index.js +3 -3
  369. package/dist/node_modules/@earendil-works/pi-agent-core/README.md +5 -0
  370. package/dist/node_modules/@earendil-works/pi-agent-core/dist/agent-loop.d.ts +2 -1
  371. package/dist/node_modules/@earendil-works/pi-agent-core/dist/agent-loop.js +1 -1
  372. package/dist/node_modules/@earendil-works/pi-agent-core/dist/agent.d.ts +3 -1
  373. package/dist/node_modules/@earendil-works/pi-agent-core/dist/agent.js +1 -1
  374. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/agent-harness.js +1 -0
  375. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/compaction/branch-summarization.js +37 -0
  376. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/compaction/compaction.js +104 -0
  377. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/compaction/utils.js +16 -0
  378. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/config.js +1 -0
  379. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/context.js +1 -0
  380. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/env/nodejs.js +10 -0
  381. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/events.js +1 -0
  382. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/execution/assistant.js +1 -0
  383. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/execution/effect-gate.js +1 -0
  384. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/execution/tools.js +1 -0
  385. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/hooks.js +1 -0
  386. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/messages.js +17 -0
  387. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/pico3/bash.js +1 -0
  388. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/pico3/bounded.js +1 -0
  389. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/pico3/chord.js +1 -0
  390. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/pico3/context.js +1 -0
  391. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/pico3/harness.js +1 -0
  392. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/pico3/hooks.js +1 -0
  393. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/pico3/index.js +1 -0
  394. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/pico3/jsonl.js +4 -0
  395. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/pico3/kinds/collapse.js +3 -0
  396. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/pico3/kinds/entries.js +1 -0
  397. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/pico3/kinds/frames.js +1 -0
  398. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/pico3/kinds/generation.js +1 -0
  399. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/pico3/kinds/job.js +1 -0
  400. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/pico3/kinds/plugin.js +1 -0
  401. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/pico3/kinds/post-tools.js +1 -0
  402. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/pico3/kinds/task-api.js +1 -0
  403. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/pico3/kinds/tool.js +3 -0
  404. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/pico3/membrane.js +1 -0
  405. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/pico3/memory.js +1 -0
  406. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/pico3/scheduler.js +1 -0
  407. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/pico3/session.js +1 -0
  408. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/pico3/system.js +8 -0
  409. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/pico3/types.js +1 -0
  410. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/pico3/view.js +1 -0
  411. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/prompt-templates.js +5 -0
  412. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/reducer.js +1 -0
  413. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/result.js +1 -0
  414. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/runtime/drive/boundary.js +1 -0
  415. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/runtime/drive/checkpoint.js +1 -0
  416. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/runtime/drive/deferred.js +1 -0
  417. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/runtime/drive/generation.js +1 -0
  418. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/runtime/drive/reconcile.js +1 -0
  419. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/runtime/drive/recovery.js +1 -0
  420. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/runtime/drive/response.js +1 -0
  421. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/runtime/drive/retry.js +1 -0
  422. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/runtime/drive/structural.js +1 -0
  423. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/runtime/drive/terminal.js +1 -0
  424. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/runtime/drive/tool-placement.js +1 -0
  425. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/runtime/drive/tools.js +1 -0
  426. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/runtime/drive.js +1 -0
  427. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/runtime/harness.js +1 -0
  428. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/runtime/index.js +1 -0
  429. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/runtime/lane.js +1 -0
  430. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/runtime/progress.js +1 -0
  431. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/runtime/reducer.js +1 -0
  432. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/runtime/restore.js +1 -0
  433. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/runtime/transcript.js +1 -0
  434. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/runtime/types.js +1 -0
  435. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/commit.js +1 -0
  436. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/context.js +1 -0
  437. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/fork-policy.js +1 -0
  438. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/fork.js +1 -0
  439. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/in-memory-storage-state.js +1 -0
  440. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/index.js +1 -0
  441. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl/codec.js +1 -0
  442. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl/errors.js +1 -0
  443. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl/fork.js +1 -0
  444. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl/index.js +1 -0
  445. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl/io.js +3 -0
  446. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl/legacy-v3.js +1 -0
  447. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl/repo.js +1 -0
  448. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl/storage.js +8 -0
  449. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl/types.js +1 -0
  450. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl-repo.js +1 -0
  451. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl-storage.js +5 -0
  452. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl.js +1 -0
  453. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/memory-repo.js +1 -0
  454. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/memory-storage.js +1 -0
  455. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/memory.js +1 -0
  456. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/mutation-line.js +1 -0
  457. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/repo-utils.js +1 -0
  458. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/session.js +1 -0
  459. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/state.js +1 -0
  460. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/testing/benchmark/datasets.js +1 -0
  461. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/testing/benchmark/session-repo.js +1 -0
  462. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/testing/benchmark/storage.js +1 -0
  463. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/testing/conformance/session-repo.js +1 -0
  464. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/testing/conformance/storage.js +1 -0
  465. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/testing/conformance.js +1 -0
  466. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/testing/gating-storage.js +1 -0
  467. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/testing/index.js +1 -0
  468. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/testing/instrumented-storage.js +1 -0
  469. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/testing/storage-decorator.js +1 -0
  470. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/types.js +1 -0
  471. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/values.js +1 -0
  472. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/skills.js +10 -0
  473. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/system-prompt.js +2 -0
  474. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/telemetry.js +1 -0
  475. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/tools/bash.js +12 -0
  476. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/tools/edit-diff.js +16 -0
  477. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/tools/edit.js +1 -0
  478. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/tools/file-mutation-queue.js +1 -0
  479. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/tools/image.js +1 -0
  480. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/tools/index.js +1 -0
  481. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/tools/path-utils.js +1 -0
  482. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/tools/read.js +14 -0
  483. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/tools/write.js +1 -0
  484. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/types.js +1 -0
  485. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/adaptive-publisher.js +1 -0
  486. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/output-capture.js +5 -0
  487. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/shell-output.js +1 -0
  488. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/truncate.js +5 -0
  489. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/usage.js +1 -0
  490. package/dist/node_modules/@earendil-works/pi-agent-core/dist/node.js +1 -0
  491. package/dist/node_modules/@earendil-works/pi-agent-core/dist/search/scanning.js +1 -0
  492. package/dist/node_modules/@earendil-works/pi-agent-core/dist/types.d.ts +2 -0
  493. package/dist/node_modules/@earendil-works/pi-agent-core/package.json +2 -2
  494. package/dist/node_modules/@earendil-works/pi-ai/README.md +83 -37
  495. package/dist/node_modules/@earendil-works/pi-ai/dist/api/anthropic-messages.js +5 -5
  496. package/dist/node_modules/@earendil-works/pi-ai/dist/api/azure-openai-responses.js +1 -1
  497. package/dist/node_modules/@earendil-works/pi-ai/dist/api/bedrock-converse-stream.js +1 -1
  498. package/dist/node_modules/@earendil-works/pi-ai/dist/api/classifier-shared.js +1 -1
  499. package/dist/node_modules/@earendil-works/pi-ai/dist/api/cloudflare-gateway-binding.js +1 -0
  500. package/dist/node_modules/@earendil-works/pi-ai/dist/api/cloudflare-workers-ai-system-one.js +1 -1
  501. package/dist/node_modules/@earendil-works/pi-ai/dist/api/google-generative-ai.js +1 -1
  502. package/dist/node_modules/@earendil-works/pi-ai/dist/api/google-shared.js +2 -2
  503. package/dist/node_modules/@earendil-works/pi-ai/dist/api/google-vertex.js +1 -1
  504. package/dist/node_modules/@earendil-works/pi-ai/dist/api/lazy.d.ts +6 -2
  505. package/dist/node_modules/@earendil-works/pi-ai/dist/api/lazy.js +1 -1
  506. package/dist/node_modules/@earendil-works/pi-ai/dist/api/llama-cpp-classify.js +5 -5
  507. package/dist/node_modules/@earendil-works/pi-ai/dist/api/mistral-conversations.js +4 -4
  508. package/dist/node_modules/@earendil-works/pi-ai/dist/api/openai-codex-responses.js +6 -6
  509. package/dist/node_modules/@earendil-works/pi-ai/dist/api/openai-completions.js +5 -5
  510. package/dist/node_modules/@earendil-works/pi-ai/dist/api/openai-responses-shared.js +11 -6
  511. package/dist/node_modules/@earendil-works/pi-ai/dist/api/openai-responses.js +3 -2
  512. package/dist/node_modules/@earendil-works/pi-ai/dist/api/openrouter-images.js +1 -1
  513. package/dist/node_modules/@earendil-works/pi-ai/dist/api/pi-messages.js +4 -4
  514. package/dist/node_modules/@earendil-works/pi-ai/dist/api/simple-options.js +1 -1
  515. package/dist/node_modules/@earendil-works/pi-ai/dist/api/system-one-shared.js +1 -1
  516. package/dist/node_modules/@earendil-works/pi-ai/dist/api/typesafe-system-one.js +1 -1
  517. package/dist/node_modules/@earendil-works/pi-ai/dist/auth/oauth/oauth-page.js +74 -0
  518. package/dist/node_modules/@earendil-works/pi-ai/dist/cli.js +0 -0
  519. package/dist/node_modules/@earendil-works/pi-ai/dist/image-models.generated.js +1 -0
  520. package/dist/node_modules/@earendil-works/pi-ai/dist/images-models.js +1 -0
  521. package/dist/node_modules/@earendil-works/pi-ai/dist/index.d.ts +2 -1
  522. package/dist/node_modules/@earendil-works/pi-ai/dist/index.js +1 -1
  523. package/dist/node_modules/@earendil-works/pi-ai/dist/models.d.ts +5 -0
  524. package/dist/node_modules/@earendil-works/pi-ai/dist/models.js +1 -1
  525. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/azure-openai-responses.js +1 -0
  526. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/azure-openai-responses.models.js +1 -0
  527. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/compat-schema.d.ts +539 -0
  528. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/compat-schema.js +1 -0
  529. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/.manifest.json +1 -1
  530. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/amazon-bedrock.json +1 -1
  531. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/anthropic.json +1 -1
  532. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/azure.json +1 -1
  533. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/baseten.json +1 -1
  534. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/cerebras.json +1 -1
  535. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/cloudflare-ai-gateway.json +1 -1
  536. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/cloudflare-workers-ai.json +1 -1
  537. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/fireworks.json +1 -1
  538. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/github-copilot.json +1 -1
  539. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/google.json +1 -1
  540. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/groq.json +1 -1
  541. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/huggingface.json +1 -1
  542. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/kimi-coding.json +1 -1
  543. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/minimax-cn.json +1 -1
  544. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/minimax.json +1 -1
  545. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/mistral.json +1 -1
  546. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/moonshotai-cn.json +1 -1
  547. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/nvidia.json +1 -1
  548. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/openai-codex.json +1 -1
  549. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/openai.json +1 -1
  550. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/opencode-go.json +1 -1
  551. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/opencode.json +1 -1
  552. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/openrouter.json +1 -1
  553. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/qwen-token-plan-cn.json +1 -1
  554. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/qwen-token-plan.json +1 -1
  555. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/radius.json +1 -1
  556. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/together.json +1 -1
  557. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/typesafe.json +1 -1
  558. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/vercel-ai-gateway.json +1 -1
  559. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/xai.json +1 -1
  560. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/xiaomi-token-plan-ams.json +1 -1
  561. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/xiaomi-token-plan-cn.json +1 -1
  562. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/xiaomi-token-plan-sgp.json +1 -1
  563. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/xiaomi.json +1 -1
  564. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/kimi-coding.js +1 -1
  565. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/model-schema.d.ts +90 -0
  566. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/model-schema.js +1 -0
  567. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/openrouter-api.js +1 -0
  568. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/openrouter-images.js +1 -0
  569. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/openrouter.js +1 -1
  570. package/dist/node_modules/@earendil-works/pi-ai/dist/telemetry.d.ts +286 -0
  571. package/dist/node_modules/@earendil-works/pi-ai/dist/telemetry.js +1 -0
  572. package/dist/node_modules/@earendil-works/pi-ai/dist/types.d.ts +23 -148
  573. package/dist/node_modules/@earendil-works/pi-ai/dist/utils/deferred-tools.js +1 -0
  574. package/dist/node_modules/@earendil-works/pi-ai/dist/utils/event-stream.d.ts +4 -0
  575. package/dist/node_modules/@earendil-works/pi-ai/dist/utils/event-stream.js +1 -1
  576. package/dist/node_modules/@earendil-works/pi-ai/dist/utils/identity.d.ts +27 -0
  577. package/dist/node_modules/@earendil-works/pi-ai/dist/utils/identity.js +1 -0
  578. package/dist/node_modules/@earendil-works/pi-ai/dist/utils/overflow.js +1 -1
  579. package/dist/node_modules/@earendil-works/pi-ai/dist/utils/provider-retry.js +1 -1
  580. package/dist/node_modules/@earendil-works/pi-ai/dist/utils/retry.js +1 -1
  581. package/dist/node_modules/@earendil-works/pi-ai/dist/utils/transcript.d.ts +3 -2
  582. package/dist/node_modules/@earendil-works/pi-ai/dist/utils/transcript.js +2 -2
  583. package/dist/node_modules/@earendil-works/pi-ai/dist/utils/version.d.ts +1 -0
  584. package/dist/node_modules/@earendil-works/pi-ai/dist/utils/version.js +1 -0
  585. package/dist/node_modules/@earendil-works/pi-ai/package.json +2 -2
  586. package/dist/node_modules/@earendil-works/pi-codemode/README.md +195 -11
  587. package/dist/node_modules/@earendil-works/pi-codemode/dist/cloudflare.js +1 -0
  588. package/dist/node_modules/@earendil-works/pi-codemode/dist/declarations.d.ts +0 -2
  589. package/dist/node_modules/@earendil-works/pi-codemode/dist/declarations.js +9 -84
  590. package/dist/node_modules/@earendil-works/pi-codemode/dist/index.d.ts +5 -2
  591. package/dist/node_modules/@earendil-works/pi-codemode/dist/index.js +1 -1
  592. package/dist/node_modules/@earendil-works/pi-codemode/dist/portable.js +1 -0
  593. package/dist/node_modules/@earendil-works/pi-codemode/dist/runtime/execution.d.ts +29 -0
  594. package/dist/node_modules/@earendil-works/pi-codemode/dist/runtime/execution.js +1 -0
  595. package/dist/node_modules/@earendil-works/pi-codemode/dist/runtime/host.d.ts +3 -16
  596. package/dist/node_modules/@earendil-works/pi-codemode/dist/runtime/host.js +1 -1
  597. package/dist/node_modules/@earendil-works/pi-codemode/dist/runtime/inline.d.ts +13 -0
  598. package/dist/node_modules/@earendil-works/pi-codemode/dist/runtime/inline.js +1 -0
  599. package/dist/node_modules/@earendil-works/pi-codemode/dist/runtime/prelude-source.js +14 -6
  600. package/dist/node_modules/@earendil-works/pi-codemode/dist/runtime/protocol.d.ts +72 -0
  601. package/dist/node_modules/@earendil-works/pi-codemode/dist/runtime/protocol.js +1 -1
  602. package/dist/node_modules/@earendil-works/pi-codemode/dist/runtime/remote.d.ts +32 -0
  603. package/dist/node_modules/@earendil-works/pi-codemode/dist/runtime/remote.js +1 -0
  604. package/dist/node_modules/@earendil-works/pi-codemode/dist/runtime/vm.js +3 -0
  605. package/dist/node_modules/@earendil-works/pi-codemode/dist/runtime/worker.js +1 -3
  606. package/dist/node_modules/@earendil-works/pi-codemode/dist/source.js +4 -3
  607. package/dist/node_modules/@earendil-works/pi-codemode/dist/types.d.ts +51 -1
  608. package/dist/node_modules/@earendil-works/pi-codemode/package.json +14 -2
  609. package/dist/node_modules/@earendil-works/pi-coding-agent/package.json +1 -1
  610. package/dist/node_modules/@earendil-works/pi-mcp/CHANGELOG.md +15 -0
  611. package/dist/node_modules/@earendil-works/pi-mcp/dist/client.js +1 -1
  612. package/dist/node_modules/@earendil-works/pi-mcp/dist/index.d.ts +1 -1
  613. package/dist/node_modules/@earendil-works/pi-mcp/dist/oauth/errors.d.ts +2 -2
  614. package/dist/node_modules/@earendil-works/pi-mcp/dist/oauth/errors.js +1 -1
  615. package/dist/node_modules/@earendil-works/pi-mcp/dist/oauth/flow.js +1 -1
  616. package/dist/node_modules/@earendil-works/pi-mcp/dist/protocol/content.d.ts +1 -1
  617. package/dist/node_modules/@earendil-works/pi-mcp/dist/transports/streamable-http.d.ts +2 -2
  618. package/dist/node_modules/@earendil-works/pi-mcp/dist/transports/streamable-http.js +4 -4
  619. package/dist/node_modules/@earendil-works/pi-mcp/dist/transports/transport.d.ts +4 -1
  620. package/dist/node_modules/@earendil-works/pi-mcp/package.json +1 -1
  621. package/dist/node_modules/@earendil-works/pi-telemetry/README.md +167 -21
  622. package/dist/node_modules/@earendil-works/pi-telemetry/dist/index.d.ts +77 -2
  623. package/dist/node_modules/@earendil-works/pi-telemetry/dist/index.js +1 -1
  624. package/dist/node_modules/@earendil-works/pi-telemetry/dist/memory.d.ts +35 -2
  625. package/dist/node_modules/@earendil-works/pi-telemetry/dist/memory.js +1 -1
  626. package/dist/node_modules/@earendil-works/pi-telemetry/dist/metrics.d.ts +70 -0
  627. package/dist/node_modules/@earendil-works/pi-telemetry/dist/metrics.js +1 -0
  628. package/dist/node_modules/@earendil-works/pi-telemetry/dist/noop.d.ts +5 -2
  629. package/dist/node_modules/@earendil-works/pi-telemetry/dist/noop.js +1 -1
  630. package/dist/node_modules/@earendil-works/pi-telemetry/dist/render.js +2 -0
  631. package/dist/node_modules/@earendil-works/pi-telemetry/dist/testing/conformance.js +1 -1
  632. package/dist/node_modules/@earendil-works/pi-telemetry/package.json +6 -1
  633. package/dist/node_modules/@earendil-works/pi-tui/README.md +5 -3
  634. package/dist/node_modules/@earendil-works/pi-tui/dist/autocomplete.js +2 -2
  635. package/dist/node_modules/@earendil-works/pi-tui/dist/components/editor.js +6 -6
  636. package/dist/node_modules/@earendil-works/pi-tui/dist/components/input.js +2 -2
  637. package/dist/node_modules/@earendil-works/pi-tui/dist/components/markdown.js +8 -7
  638. package/dist/node_modules/@earendil-works/pi-tui/dist/index.d.ts +1 -1
  639. package/dist/node_modules/@earendil-works/pi-tui/dist/index.js +1 -1
  640. package/dist/node_modules/@earendil-works/pi-tui/dist/keys.js +5 -5
  641. package/dist/node_modules/@earendil-works/pi-tui/dist/stdin-buffer.d.ts +3 -0
  642. package/dist/node_modules/@earendil-works/pi-tui/dist/stdin-buffer.js +1 -1
  643. package/dist/node_modules/@earendil-works/pi-tui/dist/terminal-image.js +1 -1
  644. package/dist/node_modules/@earendil-works/pi-tui/dist/terminal.d.ts +3 -0
  645. package/dist/node_modules/@earendil-works/pi-tui/dist/terminal.js +1 -1
  646. package/dist/node_modules/@earendil-works/pi-tui/dist/tui-alt-screen.d.ts +2 -0
  647. package/dist/node_modules/@earendil-works/pi-tui/dist/tui-alt-screen.js +4 -4
  648. package/dist/node_modules/@earendil-works/pi-tui/dist/tui-main-screen.js +1 -1
  649. package/dist/node_modules/@earendil-works/pi-tui/dist/tui.d.ts +7 -0
  650. package/dist/node_modules/@earendil-works/pi-tui/dist/tui.js +2 -2
  651. package/dist/node_modules/@earendil-works/pi-tui/dist/utils.js +1 -1
  652. package/dist/node_modules/@earendil-works/pi-tui/package.json +3 -2
  653. package/dist/package-manager-cli.js +9 -9
  654. package/dist/sdk/index.d.ts +3 -3
  655. package/dist/sdk/index.js +1 -1
  656. package/dist/sdk/office.d.ts +1 -1
  657. package/dist/sdk/office.js +1 -1
  658. package/dist/sdk/rewind.d.ts +1 -1
  659. package/dist/sdk/rewind.js +1 -1
  660. package/dist/sdk/router.d.ts +4 -4
  661. package/dist/sdk/router.js +1 -1
  662. package/dist/server/create-harness.js +1 -0
  663. package/dist/utils/clipboard-command.js +1 -1
  664. package/dist/utils/clipboard-native.js +1 -0
  665. package/dist/utils/clipboard.js +1 -1
  666. package/dist/utils/output-files.js +1 -1
  667. package/dist/utils/pi-user-agent.js +1 -1
  668. package/dist/utils/shell.js +2 -2
  669. package/dist/utils/temp-files.js +1 -0
  670. package/dist/utils/tools-manager.js +1 -1
  671. package/docs/security.md +24 -7
  672. package/examples/README.md +0 -3
  673. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  674. package/examples/extensions/dynamic-resources/dynamic.json +1 -1
  675. package/examples/extensions/gondolin/package-lock.json +2 -2
  676. package/examples/extensions/gondolin/package.json +1 -1
  677. package/examples/extensions/minimal-mode.ts +4 -5
  678. package/examples/extensions/overlay-test.ts +2 -2
  679. package/examples/extensions/sandbox/package-lock.json +2 -2
  680. package/examples/extensions/sandbox/package.json +1 -1
  681. package/examples/extensions/subagent/index.ts +4 -6
  682. package/examples/extensions/with-deps/package-lock.json +2 -2
  683. package/examples/extensions/with-deps/package.json +1 -1
  684. package/npm-shrinkwrap.json +22 -460
  685. package/package.json +7 -12
  686. package/dist/modes/interactive/theme/theme-json.d.ts +0 -75
  687. package/dist/node_modules/@dalcode/dal-guard/src/review.js +0 -3
  688. package/dist/node_modules/@dalcode/dal-office/src/scenes.js +0 -1
  689. package/dist/node_modules/@dalcode/dal-plugins/src/rank.js +0 -4
  690. package/dist/node_modules/@dalcode/dal-router/src/assist.js +0 -4
  691. package/dist/node_modules/@dalcode/dal-router/src/compact-defer.js +0 -3
  692. package/dist/node_modules/@dalcode/dal-router/src/jev.d.ts +0 -52
  693. package/dist/node_modules/@dalcode/dal-router/src/jev.js +0 -5
  694. package/dist/node_modules/@dalcode/dal-router/src/router.d.ts +0 -32
  695. package/dist/node_modules/@dalcode/dal-router/src/router.js +0 -1
  696. package/dist/node_modules/@dalcode/dal-router/src/services.js +0 -1
  697. package/dist/node_modules/@dalcode/dal-subagent/src/role-pick.js +0 -2
  698. package/dist/node_modules/@earendil-works/chord/README.md +0 -264
  699. package/dist/node_modules/@earendil-works/chord/dist/api.js +0 -1
  700. package/dist/node_modules/@earendil-works/chord/dist/bundler.js +0 -1
  701. package/dist/node_modules/@earendil-works/chord/dist/context/index.js +0 -1
  702. package/dist/node_modules/@earendil-works/chord/dist/delta/apply-immutable-trusted.js +0 -1
  703. package/dist/node_modules/@earendil-works/chord/dist/delta/diff.js +0 -1
  704. package/dist/node_modules/@earendil-works/chord/dist/delta/index.js +0 -1
  705. package/dist/node_modules/@earendil-works/chord/dist/delta/revision-validator.js +0 -1
  706. package/dist/node_modules/@earendil-works/chord/dist/delta/tracker.js +0 -1
  707. package/dist/node_modules/@earendil-works/chord/dist/facets/host.js +0 -1
  708. package/dist/node_modules/@earendil-works/chord/dist/facets/loader.js +0 -1
  709. package/dist/node_modules/@earendil-works/chord/dist/index.js +0 -1
  710. package/dist/node_modules/@earendil-works/chord/dist/json.js +0 -1
  711. package/dist/node_modules/@earendil-works/chord/dist/node/bundle-loader.js +0 -2
  712. package/dist/node_modules/@earendil-works/chord/dist/node/bundle.js +0 -4
  713. package/dist/node_modules/@earendil-works/chord/dist/node/manifest.js +0 -1
  714. package/dist/node_modules/@earendil-works/chord/dist/node/package.js +0 -1
  715. package/dist/node_modules/@earendil-works/chord/dist/node.js +0 -1
  716. package/dist/node_modules/@earendil-works/chord/dist/services/consumer.js +0 -1
  717. package/dist/node_modules/@earendil-works/chord/dist/services/errors.js +0 -1
  718. package/dist/node_modules/@earendil-works/chord/dist/services/handle.js +0 -1
  719. package/dist/node_modules/@earendil-works/chord/dist/services/instances.js +0 -1
  720. package/dist/node_modules/@earendil-works/chord/dist/services/loopback.js +0 -1
  721. package/dist/node_modules/@earendil-works/chord/dist/services/provider.js +0 -1
  722. package/dist/node_modules/@earendil-works/chord/dist/services/state-codec.js +0 -1
  723. package/dist/node_modules/@earendil-works/chord/dist/services/state-internals.js +0 -1
  724. package/dist/node_modules/@earendil-works/chord/dist/services/state.js +0 -1
  725. package/dist/node_modules/@earendil-works/chord/dist/services/wire.js +0 -1
  726. package/dist/node_modules/@earendil-works/chord/package.json +0 -62
  727. package/dist/node_modules/@earendil-works/chord/src/delta/README.md +0 -191
  728. package/dist/node_modules/@earendil-works/pi-ai/dist/utils/assistant-message-frame.d.ts +0 -63
  729. package/dist/node_modules/@earendil-works/pi-client/CHANGELOG.md +0 -45
  730. package/dist/node_modules/@earendil-works/pi-client/LICENSE +0 -21
  731. package/dist/node_modules/@earendil-works/pi-client/README.md +0 -72
  732. package/dist/node_modules/@earendil-works/pi-client/dist/client.js +0 -1
  733. package/dist/node_modules/@earendil-works/pi-client/dist/connection.js +0 -1
  734. package/dist/node_modules/@earendil-works/pi-client/dist/errors.js +0 -1
  735. package/dist/node_modules/@earendil-works/pi-client/dist/index.js +0 -1
  736. package/dist/node_modules/@earendil-works/pi-client/dist/promise.js +0 -1
  737. package/dist/node_modules/@earendil-works/pi-client/dist/types.js +0 -0
  738. package/dist/node_modules/@earendil-works/pi-client/dist/unix.js +0 -1
  739. package/dist/node_modules/@earendil-works/pi-client/package.json +0 -46
  740. package/dist/node_modules/@earendil-works/pi-protocol/LICENSE +0 -21
  741. package/dist/node_modules/@earendil-works/pi-protocol/README.md +0 -41
  742. package/dist/node_modules/@earendil-works/pi-protocol/dist/cbor/decoder.js +0 -1
  743. package/dist/node_modules/@earendil-works/pi-protocol/dist/cbor/encoder.js +0 -1
  744. package/dist/node_modules/@earendil-works/pi-protocol/dist/cbor/index.js +0 -1
  745. package/dist/node_modules/@earendil-works/pi-protocol/dist/cbor/options.js +0 -1
  746. package/dist/node_modules/@earendil-works/pi-protocol/dist/codec.js +0 -1
  747. package/dist/node_modules/@earendil-works/pi-protocol/dist/framing.js +0 -1
  748. package/dist/node_modules/@earendil-works/pi-protocol/dist/index.js +0 -1
  749. package/dist/node_modules/@earendil-works/pi-protocol/dist/protocol.js +0 -1
  750. package/dist/node_modules/@earendil-works/pi-protocol/dist/schemas.js +0 -1
  751. package/dist/node_modules/@earendil-works/pi-protocol/package.json +0 -39
  752. package/dist/node_modules/@earendil-works/pi-server/CHANGELOG.md +0 -81
  753. package/dist/node_modules/@earendil-works/pi-server/LICENSE +0 -21
  754. package/dist/node_modules/@earendil-works/pi-server/README.md +0 -63
  755. package/dist/node_modules/@earendil-works/pi-server/dist/connection.js +0 -1
  756. package/dist/node_modules/@earendil-works/pi-server/dist/errors.js +0 -1
  757. package/dist/node_modules/@earendil-works/pi-server/dist/index.js +0 -1
  758. package/dist/node_modules/@earendil-works/pi-server/dist/listener.js +0 -0
  759. package/dist/node_modules/@earendil-works/pi-server/dist/server.js +0 -1
  760. package/dist/node_modules/@earendil-works/pi-server/dist/session-router.js +0 -1
  761. package/dist/node_modules/@earendil-works/pi-server/dist/testing/client.js +0 -1
  762. package/dist/node_modules/@earendil-works/pi-server/dist/testing/host.js +0 -1
  763. package/dist/node_modules/@earendil-works/pi-server/dist/testing/index.js +0 -1
  764. package/dist/node_modules/@earendil-works/pi-server/dist/testing/server.js +0 -1
  765. package/dist/node_modules/@earendil-works/pi-server/dist/transports/unix/address.js +0 -1
  766. package/dist/node_modules/@earendil-works/pi-server/dist/transports/unix/index.js +0 -1
  767. package/dist/node_modules/@earendil-works/pi-server/dist/transports/unix/listener.js +0 -1
  768. package/dist/node_modules/@earendil-works/pi-server/dist/transports/unix/preset.js +0 -1
  769. package/dist/node_modules/@earendil-works/pi-server/dist/transports/unix/types.js +0 -0
  770. package/dist/node_modules/@earendil-works/pi-server/dist/types.js +0 -0
  771. package/dist/node_modules/@earendil-works/pi-server/package.json +0 -45
  772. package/examples/plugins/pi-example-plugin/README.md +0 -38
  773. package/examples/plugins/pi-example-plugin/package.json +0 -10
  774. package/examples/plugins/pi-example-plugin/src/contract.ts +0 -13
  775. package/examples/plugins/pi-example-plugin/src/session.ts +0 -24
  776. package/examples/plugins/pi-example-plugin/src/tui.ts +0 -31
  777. /package/dist/node_modules/{@earendil-works/chord → @dalcode/dal-codeindex}/LICENSE +0 -0
  778. /package/dist/node_modules/@earendil-works/{chord/dist → pi-agent-core/dist/harness/session/testing}/types.js +0 -0
  779. /package/dist/node_modules/@earendil-works/{chord/dist/delta/draft.js → pi-agent-core/dist/harness/tools/tool-context.js} +0 -0
  780. /package/dist/node_modules/@earendil-works/{pi-client/dist/transport.js → pi-agent-core/dist/search/index.js} +0 -0
@@ -0,0 +1,26 @@
1
+ export interface Word {
2
+ readonly value: string;
3
+ readonly dynamic: boolean;
4
+ }
5
+ export type Token = {
6
+ readonly kind: "word";
7
+ readonly word: Word;
8
+ } | {
9
+ readonly kind: "separator";
10
+ } | {
11
+ readonly kind: "redirectOut";
12
+ } | {
13
+ readonly kind: "redirectOther";
14
+ };
15
+ export declare function tokenize(command: string): Token[];
16
+ export interface SimpleCommand {
17
+ readonly words: readonly Word[];
18
+ readonly redirects: boolean;
19
+ }
20
+ export declare function simpleCommands(command: string): SimpleCommand[];
21
+ export interface UnwrappedCommand {
22
+ readonly words: readonly string[];
23
+ readonly setsEnvironment: boolean;
24
+ readonly opaque: boolean;
25
+ }
26
+ export declare function unwrapCommand(words: readonly string[]): UnwrappedCommand;
@@ -1,4 +1,4 @@
1
- var a=Object.defineProperty;var c=(e,t)=>a(e,"name",{value:t,configurable:!0});import{APP_NAME as o,CONFIG_DIR_NAME as i}from"../config.js";import{emitProjectTrustEvent as l}from"./extensions/runner.js";import{getProjectTrustOptions as d,hasTrustRequiringProjectResources as f}from"./trust-manager.js";function j(e){return`Trust project folder?
1
+ var o=Object.defineProperty;var c=(e,t)=>o(e,"name",{value:t,configurable:!0});import{APP_NAME as a,CONFIG_DIR_NAME as i}from"../config.js";import{emitProjectTrustEvent as f}from"./extensions/runner.js";import{SETTINGS_DEFAULTS as l}from"./settings-defaults.js";import{getProjectTrustOptions as d,hasTrustRequiringProjectResources as j}from"./trust-manager.js";function T(e){return`Trust project folder?
2
2
  ${e}
3
3
 
4
- This allows ${o} to load ${i} settings and resources, install missing project packages, and execute project extensions.`}c(j,"formatProjectTrustPrompt");async function m(e,t){const r=d(e,{includeSessionOnly:!0}),s=await t.ui.select(j(e),r.map(u=>u.label));return r.find(u=>u.label===s)}c(m,"selectProjectTrustOption");function P(e,t){t.updates.length>0&&e.setMany(t.updates)}c(P,"saveProjectTrustPromptResult");async function y(e){if(e.trustOverride!==void 0)return e.trustOverride;if(!f(e.cwd))return!0;if(e.extensionsResult){const{result:s,errors:u}=await l(e.extensionsResult,{type:"project_trust",cwd:e.cwd},e.projectTrustContext);for(const n of u)e.onExtensionError?.(`Extension "${n.extensionPath}" project_trust error: ${n.error}`);if(s){const n=s.trusted==="yes";return s.remember===!0&&e.trustStore.set(e.cwd,n),n}}const t=e.trustStore.get(e.cwd);if(t!==null)return t;switch(e.defaultProjectTrust??"ask"){case"always":return!0;case"never":return!1;case"ask":break}if(!e.projectTrustContext.hasUI)return!1;const r=await m(e.cwd,e.projectTrustContext);return r!==void 0?(P(e.trustStore,r),r.trusted):!1}c(y,"resolveProjectTrusted");export{y as resolveProjectTrusted};
4
+ This allows ${a} to load ${i} settings and resources, install missing project packages, and execute project extensions.`}c(T,"formatProjectTrustPrompt");async function m(e,t){const r=d(e,{includeSessionOnly:!0}),s=await t.ui.select(T(e),r.map(u=>u.label));return r.find(u=>u.label===s)}c(m,"selectProjectTrustOption");function P(e,t){t.updates.length>0&&e.setMany(t.updates)}c(P,"saveProjectTrustPromptResult");async function y(e){if(e.trustOverride!==void 0)return e.trustOverride;if(!j(e.cwd))return!0;if(e.extensionsResult){const{result:s,errors:u}=await f(e.extensionsResult,{type:"project_trust",cwd:e.cwd},e.projectTrustContext);for(const n of u)e.onExtensionError?.(`Extension "${n.extensionPath}" project_trust error: ${n.error}`);if(s){const n=s.trusted==="yes";return s.remember===!0&&e.trustStore.set(e.cwd,n),n}}const t=e.trustStore.get(e.cwd);if(t!==null)return t;switch(e.defaultProjectTrust??l.defaultProjectTrust){case"always":return!0;case"never":return!1;case"ask":break}if(!e.projectTrustContext.hasUI)return!1;const r=await m(e.cwd,e.projectTrustContext);return r!==void 0?(P(e.trustStore,r),r.trusted):!1}c(y,"resolveProjectTrusted");export{y as resolveProjectTrusted};
@@ -1,2 +1,2 @@
1
- var N=Object.defineProperty;var f=(t,r)=>N(t,"name",{value:r,configurable:!0});import{existsSync as A,readdirSync as R,readFileSync as $,statSync as y}from"fs";import{basename as j,dirname as T,join as b,resolve as w,sep as E}from"path";import{CONFIG_DIR_NAME as G}from"../config.js";import{parseFrontmatter as M}from"../utils/frontmatter.js";import{resolvePath as D}from"../utils/paths.js";import{createSyntheticSourceInfo as S}from"./source-info.js";function U(t){const r=[];let e="",o=null;for(let s=0;s<t.length;s++){const n=t[s];o?n===o?o=null:e+=n:n==='"'||n==="'"?o=n:/\s/.test(n)?e&&(r.push(e),e=""):e+=n}return e&&r.push(e),r}f(U,"parseCommandArgs");function W(t,r){const e=r.join(" ");return t.replace(/\$\{(\d+|ARGUMENTS|@):-([^}]*)\}|\$\{@:(\d+)(?::(\d+))?\}|\$(ARGUMENTS|@|\d+)/g,(o,s,n,i,m,p)=>{if(s){const c=s==="@"||s==="ARGUMENTS"?e:r[parseInt(s,10)-1];return c||n}if(i){let c=parseInt(i,10)-1;if(c<0&&(c=0),m){const g=parseInt(m,10);return r.slice(c,c+g).join(" ")}return r.slice(c).join(" ")}if(p==="ARGUMENTS"||p==="@")return e;const l=parseInt(p,10)-1;return r[l]??""})}f(W,"substituteArgs");function I(t,r){const e=[];let o;try{o=$(t,"utf-8")}catch(l){const c=l instanceof Error?l.message:"failed to read prompt template file";return e.push({type:"warning",message:c,path:t}),{template:null,diagnostics:e}}let s,n;try{({frontmatter:s,body:n}=M(o))}catch(l){const c=l instanceof Error?l.message:"failed to parse prompt template file";return e.push({type:"warning",message:c,path:t}),{template:null,diagnostics:e}}const i=j(t).replace(/\.md$/,"");let m=typeof s.description=="string"?s.description:"";if(!m){const l=n.split(`
2
- `).find(c=>c.trim());l&&(m=l.slice(0,60),l.length>60&&(m+="..."))}const p=typeof s["argument-hint"]=="string"?s["argument-hint"]:void 0;return{template:{name:i,description:m,...p&&{argumentHint:p},content:n,sourceInfo:r,filePath:t},diagnostics:e}}f(I,"loadTemplateFromFile");function F(t,r){const e=[],o=[];if(!A(t))return{templates:e,diagnostics:o};try{const s=R(t,{withFileTypes:!0});for(const n of s){const i=b(t,n.name);let m=n.isFile();if(n.isSymbolicLink())try{m=y(i).isFile()}catch{continue}if(m&&n.name.endsWith(".md")){const p=I(i,r(i));p.template&&e.push(p.template),o.push(...p.diagnostics)}}}catch{return{templates:e,diagnostics:o}}return{templates:e,diagnostics:o}}f(F,"loadTemplatesFromDir");function O(t){const r=D(t.cwd),e=D(t.agentDir),o=t.promptPaths,s=t.includeDefaults,n=[],i=[],m=f(a=>{n.push(...a.templates),i.push(...a.diagnostics)},"addResult"),p=b(e,"prompts"),l=w(r,G,"prompts"),c=f((a,d)=>{const u=w(d);if(a===u)return!0;const h=u.endsWith(E)?u:`${u}${E}`;return a.startsWith(h)},"isUnderPath"),g=f(a=>c(a,p)?S(a,{source:"local",scope:"user",baseDir:p}):c(a,l)?S(a,{source:"local",scope:"project",baseDir:l}):S(a,{source:"local",baseDir:y(a).isDirectory()?a:T(a)}),"getSourceInfo");s&&(m(F(p,g)),m(F(l,g)));for(const a of o){const d=D(a,r,{trim:!0});if(A(d))try{const u=y(d);if(u.isDirectory())m(F(d,g));else if(u.isFile()&&d.endsWith(".md")){const h=I(d,g(d));h.template&&n.push(h.template),i.push(...h.diagnostics)}}catch(u){const h=u instanceof Error?u.message:"failed to read prompt template path";i.push({type:"warning",message:h,path:d})}}return{templates:n,diagnostics:i}}f(O,"loadPromptTemplates");function Q(t,r){if(!t.startsWith("/"))return t;const e=t.match(/^\/([^\s]+)(?:\s+([\s\S]*))?$/);if(!e)return t;const o=e[1],s=e[2]??"",n=r.find(i=>i.name===o);if(n){const i=U(s);return W(n.content,i)}return t}f(Q,"expandPromptTemplate");export{Q as expandPromptTemplate,O as loadPromptTemplates,U as parseCommandArgs,W as substituteArgs};
1
+ var j=Object.defineProperty;var f=(t,o)=>j(t,"name",{value:o,configurable:!0});import{existsSync as A,readdirSync as N,readFileSync as R,statSync as y}from"fs";import{basename as T,dirname as $,join as b,resolve as w,sep as E}from"path";import{CONFIG_DIR_NAME as G,getProjectPromptsDir as M}from"../config.js";import{parseFrontmatter as U}from"../utils/frontmatter.js";import{resolvePath as D}from"../utils/paths.js";import{createSyntheticSourceInfo as S}from"./source-info.js";function W(t){const o=[];let e="",i=!1,n=null;for(let s=0;s<t.length;s++){const r=t[s];n?r===n?n=null:e+=r:r==='"'||r==="'"?(n=r,i=!0):/\s/.test(r)?i&&(o.push(e),e="",i=!1):(e+=r,i=!0)}return i&&o.push(e),o}f(W,"parseCommandArgs");function x(t,o){const e=o.join(" ");return t.replace(/\$\{(\d+|ARGUMENTS|@):-([^}]*)\}|\$\{@:(\d+)(?::(\d+))?\}|\$(ARGUMENTS|@|\d+)/g,(i,n,s,r,m,p)=>{if(n){const c=n==="@"||n==="ARGUMENTS"?e:o[parseInt(n,10)-1];return c||s}if(r){let c=parseInt(r,10)-1;if(c<0&&(c=0),m){const g=parseInt(m,10);return o.slice(c,c+g).join(" ")}return o.slice(c).join(" ")}if(p==="ARGUMENTS"||p==="@")return e;const l=parseInt(p,10)-1;return o[l]??""})}f(x,"substituteArgs");function I(t,o){const e=[];let i;try{i=R(t,"utf-8")}catch(l){const c=l instanceof Error?l.message:"failed to read prompt template file";return e.push({type:"warning",message:c,path:t}),{template:null,diagnostics:e}}let n,s;try{({frontmatter:n,body:s}=U(i))}catch(l){const c=l instanceof Error?l.message:"failed to parse prompt template file";return e.push({type:"warning",message:c,path:t}),{template:null,diagnostics:e}}const r=T(t).replace(/\.md$/,"");let m=typeof n.description=="string"?n.description:"";if(!m){const l=s.split(`
2
+ `).find(c=>c.trim());l&&(m=l.slice(0,60),l.length>60&&(m+="..."))}const p=typeof n["argument-hint"]=="string"?n["argument-hint"]:void 0;return{template:{name:r,description:m,...p&&{argumentHint:p},content:s,sourceInfo:o,filePath:t},diagnostics:e}}f(I,"loadTemplateFromFile");function F(t,o){const e=[],i=[];if(!A(t))return{templates:e,diagnostics:i};try{const n=N(t,{withFileTypes:!0});for(const s of n){const r=b(t,s.name);let m=s.isFile();if(s.isSymbolicLink())try{m=y(r).isFile()}catch{continue}if(m&&s.name.endsWith(".md")){const p=I(r,o(r));p.template&&e.push(p.template),i.push(...p.diagnostics)}}}catch{return{templates:e,diagnostics:i}}return{templates:e,diagnostics:i}}f(F,"loadTemplatesFromDir");function O(t){const o=D(t.cwd),e=D(t.agentDir),i=t.promptPaths,n=t.includeDefaults,s=[],r=[],m=f(a=>{s.push(...a.templates),r.push(...a.diagnostics)},"addResult"),p=b(e,"prompts"),l=M(w(o,G)),c=f((a,d)=>{const u=w(d);if(a===u)return!0;const h=u.endsWith(E)?u:`${u}${E}`;return a.startsWith(h)},"isUnderPath"),g=f(a=>c(a,p)?S(a,{source:"local",scope:"user",baseDir:p}):c(a,l)?S(a,{source:"local",scope:"project",baseDir:l}):S(a,{source:"local",baseDir:y(a).isDirectory()?a:$(a)}),"getSourceInfo");n&&(m(F(p,g)),m(F(l,g)));for(const a of i){const d=D(a,o,{trim:!0});if(A(d))try{const u=y(d);if(u.isDirectory())m(F(d,g));else if(u.isFile()&&d.endsWith(".md")){const h=I(d,g(d));h.template&&s.push(h.template),r.push(...h.diagnostics)}}catch(u){const h=u instanceof Error?u.message:"failed to read prompt template path";r.push({type:"warning",message:h,path:d})}}return{templates:s,diagnostics:r}}f(O,"loadPromptTemplates");function Q(t,o){if(!t.startsWith("/"))return t;const e=t.match(/^\/([^\s]+)(?:\s+([\s\S]*))?$/);if(!e)return t;const i=e[1],n=e[2]??"",s=o.find(r=>r.name===i);if(s){const r=W(n);return x(s.content,r)}return t}f(Q,"expandPromptTemplate");export{Q as expandPromptTemplate,O as loadPromptTemplates,W as parseCommandArgs,x as substituteArgs};
@@ -1 +1 @@
1
- var u=Object.defineProperty;var n=(e,r)=>u(e,"name",{value:r,configurable:!0});import{isInstallTelemetryEnabled as s}from"./telemetry.js";const c="openrouter.ai",f="integrate.api.nvidia.com",l="api.cloudflare.com",p="gateway.ai.cloudflare.com",O="opencode.ai";function i(e,r){try{return new URL(e).hostname===r}catch{return!1}}n(i,"matchesHost");function g(e){return e.provider==="openrouter"||e.baseUrl.includes(c)}n(g,"isOpenRouterModel");function A(e){return e.provider==="nvidia"||i(e.baseUrl,f)}n(A,"isNvidiaNimModel");function E(e){return e.provider==="cloudflare-workers-ai"||e.provider==="cloudflare-ai-gateway"||i(e.baseUrl,l)||i(e.baseUrl,p)}n(E,"isCloudflareModel");function S(e,r){if(s(r)){if(g(e))return{"HTTP-Referer":"https://deepailab.ai","X-OpenRouter-Title":"dal","X-OpenRouter-Categories":"cli-agent"};if(A(e))return{"X-BILLING-INVOKE-ORIGIN":"dal"};if(E(e))return{"User-Agent":"dal-coding-agent"}}}n(S,"getDefaultAttributionHeaders");const _=new Set(["deepailab","dalcode-gateway"]),D="x-dal-session-id";function I(e,r){if(!_.has(e.provider))return;const t=process.env.DALCODE_SESSION_ID||r;return t?{[D]:t}:void 0}n(I,"getDalSessionHeaders");function R(e,r){const t=I(e,r);if(t)return t;if(r&&!(e.provider!=="opencode"&&e.provider!=="opencode-go"&&!i(e.baseUrl,O)))return{"x-opencode-session":r,"x-opencode-client":"dal"}}n(R,"getSessionHeaders");function H(e,r,t,...d){const o={...R(e,t),...S(e,r)};for(const a of d)a&&Object.assign(o,a);return Object.keys(o).length>0?o:void 0}n(H,"mergeProviderAttributionHeaders");export{D as DAL_SESSION_HEADER,H as mergeProviderAttributionHeaders};
1
+ var c=Object.defineProperty;var n=(e,r)=>c(e,"name",{value:r,configurable:!0});import{isInstallTelemetryEnabled as d}from"./telemetry.js";const s="openrouter.ai",f="integrate.api.nvidia.com",l="api.cloudflare.com",p="gateway.ai.cloudflare.com",O="opencode.ai";function t(e,r){try{return new URL(e).hostname===r}catch{return!1}}n(t,"matchesHost");function g(e){return e.provider==="openrouter"||e.baseUrl.includes(s)}n(g,"isOpenRouterModel");function b(e){return e.provider==="nvidia"||t(e.baseUrl,f)}n(b,"isNvidiaNimModel");function T(e){return e.provider==="cloudflare-workers-ai"||e.provider==="cloudflare-ai-gateway"||t(e.baseUrl,l)||t(e.baseUrl,p)}n(T,"isCloudflareModel");function v(e,r){if(d(r)){if(g(e))return{"HTTP-Referer":"https://deepailab.ai","X-OpenRouter-Title":"dal","X-OpenRouter-Categories":"cli-agent"};if(b(e))return{"X-BILLING-INVOKE-ORIGIN":"dal"};if(T(e))return{"User-Agent":"dal-coding-agent"}}}n(v,"getDefaultAttributionHeaders");function A(e,r){if(r&&!(e.provider!=="opencode"&&e.provider!=="opencode-go"&&!t(e.baseUrl,O)))return{"x-opencode-session":r,"x-opencode-client":"dal"}}n(A,"getSessionHeaders");function R(e,r,a,...u){const i={...A(e,a),...v(e,r)};for(const o of u)o&&Object.assign(i,o);return Object.keys(i).length>0?i:void 0}n(R,"mergeProviderAttributionHeaders");export{R as mergeProviderAttributionHeaders};
@@ -1,4 +1,4 @@
1
- import { type AnyModel, type Api, type AssistantMessageEventStream, type ClassifierApi, type ImageApi, type Model, type OAuthCredentials, type OAuthLoginCallbacks, type Provider, type ProviderClassifier, type ProviderHeaders, type ProviderImages, type RefreshModelsContext, type SimpleStreamOptions, type TranscriptContext } from "@earendil-works/pi-ai";
1
+ import { type AnyModel, type Api, type AssistantMessageEventStream, type ClassifierApi, type ClassifierModel, type ImageApi, type Model, type OAuthCredentials, type OAuthLoginCallbacks, type Provider, type ProviderClassifier, type ProviderHeaders, type ProviderImages, type RefreshModelsContext, type SimpleStreamOptions, type TranscriptContext } from "@earendil-works/pi-ai";
2
2
  import type { ModelConfig, ModelsJsonProvider } from "./model-config.ts";
3
3
  import { clearConfigValueCache } from "./resolve-config-value.ts";
4
4
  export interface ExtensionOAuthConfig {
@@ -41,6 +41,7 @@ export interface ProviderClassifierModelConfig extends ProviderModelConfigBase {
41
41
  type: "classifier";
42
42
  api?: ClassifierApi;
43
43
  contextWindow: number;
44
+ compat?: ClassifierModel<ClassifierApi>["compat"];
44
45
  }
45
46
  export type ProviderModelConfig = ProviderChatModelConfig | ProviderImageModelConfig | ProviderClassifierModelConfig;
46
47
  export interface ProviderConfigInput {
@@ -1 +1 @@
1
- var B=Object.defineProperty;var i=(r,e)=>B(r,"name",{value:e,configurable:!0});import{isModelType as y,lazyStream as V}from"@earendil-works/pi-ai";import{getApiProvider as q}from"@earendil-works/pi-ai/compat";import{classifierErrorResult as N,imageErrorResult as b}from"@earendil-works/pi-ai/utils/model-operations";import{clearConfigValueCache as x,getConfigValueEnvVarNames as C,isCommandConfigValue as W,isConfigValueConfigured as F,resolveConfigValueOrThrow as J,resolveHeadersOrThrow as M}from"./resolve-config-value.js";const ce=x;function U(r){return r?r.getAllModels?.()??r.getModels():[]}i(U,"getAllProviderModels");function T(r,e){if(!e)return r;const a={...r,...e},t=r,n=e,o=a;for(const l of["openRouterRouting","vercelGatewayRouting","chatTemplateKwargs","chatTemplateArgs"]){const h=t?.[l],f=n[l];(typeof h=="object"&&h!==null||typeof f=="object"&&f!==null)&&(o[l]={...h,...f})}return a}i(T,"mergeCompat");function G(r,e){return e?{...r,...e,images:e.images?{...r?.images,...e.images,resize:e.images.resize?{...r?.images?.resize,...e.images.resize}:r?.images?.resize}:r?.images}:r}i(G,"mergeInputLimits");function Q(r,e){if(!e)return r;const a={...r};for(const t of["off","minimal","low","medium","high","xhigh","max"]){const n=e[t];n&&(a[t]={...r?.[t],...n})}return a}i(Q,"mergeSamplingParamsByThinkingLevel");function X(r,e){return{...r,name:e.name??r.name,reasoning:e.reasoning??r.reasoning,thinkingLevelMap:e.thinkingLevelMap?{...r.thinkingLevelMap,...e.thinkingLevelMap}:r.thinkingLevelMap,input:e.input??r.input,inputLimits:G(r.inputLimits,e.inputLimits),cost:e.cost?{input:e.cost.input??r.cost.input,output:e.cost.output??r.cost.output,cacheRead:e.cost.cacheRead??r.cost.cacheRead,cacheWrite:e.cost.cacheWrite??r.cost.cacheWrite,tiers:e.cost.tiers??r.cost.tiers}:r.cost,promptCache:e.promptCache?{...r.promptCache,...e.promptCache}:r.promptCache,contextWindow:e.contextWindow??r.contextWindow,maxTokens:e.maxTokens??r.maxTokens,samplingParams:e.samplingParams?{...r.samplingParams,...e.samplingParams}:r.samplingParams,samplingParamsByThinkingLevel:Q(r.samplingParamsByThinkingLevel,e.samplingParamsByThinkingLevel),compat:T(r.compat,e.compat)}}i(X,"applyModelOverride");function Y(r,e,a,t){const n=e.api??a.api??t?.api;if(!n)throw new Error(`Provider ${r}, model ${e.id}: no "api" specified. Set at provider or model level.`);const o=e.baseUrl??a.baseUrl??t?.baseUrl;if(!o)throw new Error(`Provider ${r}: "baseUrl" is required when defining custom models.`);if(e.contextWindow!==void 0&&e.contextWindow<=0)throw new Error(`Provider ${r}, model ${e.id}: invalid contextWindow`);if(e.maxTokens!==void 0&&e.maxTokens<=0)throw new Error(`Provider ${r}, model ${e.id}: invalid maxTokens`);return{id:e.id,name:e.name??e.id,api:n,provider:r,baseUrl:o,reasoning:e.reasoning??!1,thinkingLevelMap:e.thinkingLevelMap,input:e.input??["text"],inputLimits:e.inputLimits,cost:e.cost??{input:0,output:0,cacheRead:0,cacheWrite:0},promptCache:e.promptCache,contextWindow:e.contextWindow??128e3,maxTokens:e.maxTokens??16384,samplingParams:e.samplingParams,samplingParamsByThinkingLevel:e.samplingParamsByThinkingLevel,headers:void 0,compat:T(a.compat,e.compat)}}i(Y,"modelFromJson");function Z(r,e,a){const t=r.filter(n=>y(n,"chat"));return t.find(n=>n.id===e)??(a?t.find(n=>n.api===a):void 0)??t.find(n=>n.api==="openai-completions")??t[0]}i(Z,"findModelDefaults");function I(r,e){const a=e.type??"chat",t=r.filter(n=>y(n,a));return t.find(n=>n.id===e.id)??(e.api?t.find(n=>n.api===e.api):void 0)??(a==="chat"?t.find(n=>n.api==="openai-completions"):void 0)??t[0]}i(I,"findExtensionModelDefaults");function ee(r,e,a,t){const n=t.type??"chat",o=I(e,t),l=t.api??(n==="chat"?a.api:void 0)??o?.api;if(!l)throw new Error(`Provider ${r}, model ${t.id}: no "api" specified. Set it at model level${n==="chat"?" or provider level":""}.`);const h=t.baseUrl??a.baseUrl??o?.baseUrl;if(!h)throw new Error(`Provider ${r}: "baseUrl" is required when defining custom models.`);return t.type==="image"?{...t,api:l,provider:r,baseUrl:h,headers:void 0}:t.type==="classifier"?{...t,api:l,provider:r,baseUrl:h,headers:void 0}:{...t,api:l,provider:r,baseUrl:h,headers:void 0}}i(ee,"extensionModelFromDefinition");function L(r,e,a){if(!a)return[...e];if(a.oauth&&!a.baseUrl)throw new Error(`Provider ${r}: "baseUrl" is required when "oauth" is set.`);const t=a.modelOverrides&&Object.keys(a.modelOverrides).length>0;if(!a.models?.length&&!a.baseUrl&&!a.headers&&!a.compat&&!t&&!a.apiKey&&!a.oauth&&a.authHeader===void 0)throw new Error(`Provider ${r}: must specify "baseUrl", "headers", "compat", "modelOverrides", or "models".`);const n=e.map(o=>{const l=a.oauth==="radius"?o.baseUrl:a.baseUrl??o.baseUrl;return y(o,"chat")?{...o,baseUrl:l,compat:T(o.compat,a.compat)}:{...o,baseUrl:l}});for(const o of a.models??[]){const l=n.findIndex(c=>y(c,"chat")&&c.id===o.id),h=Z(n,o.id,o.api??a.api),f=Y(r,o,a,h);l>=0?n[l]=f:n.push(f)}return n}i(L,"applyModelsJson");function H(r,e,a){return a?a.models?a.models.map(t=>ee(r,e,a,t)):a.baseUrl?e.map(t=>({...t,baseUrl:a.baseUrl})):[...e]:[...e]}i(H,"applyExtension");function re(r){return{name:r.name,isSubscription:r.isSubscription,login:i(async e=>({...await r.login({onAuth:i(t=>e.notify({type:"auth_url",...t}),"onAuth"),onDeviceCode:i(t=>e.notify({type:"device_code",...t}),"onDeviceCode"),onPrompt:i(t=>e.prompt({type:"text",...t}),"onPrompt"),onProgress:i(t=>e.notify({type:"progress",message:t}),"onProgress"),onManualCodeInput:i(()=>e.prompt({type:"manual_code",message:"Paste the authorization code"}),"onManualCodeInput"),onSelect:i(t=>e.prompt({type:"select",...t}),"onSelect"),signal:e.signal}),type:"oauth"}),"login"),refresh:i(async(e,a)=>({...await r.refreshToken(e,a),type:"oauth"}),"refresh"),toAuth:i(async e=>({apiKey:r.getApiKey(e)}),"toAuth")}}i(re,"adaptOAuth");function j(r,e,a){let t=r.headers||e?{...r.headers,...e}:void 0;if(a){if(!r.apiKey)throw new Error("authHeader requires a resolved API key");t={...t,Authorization:`Bearer ${r.apiKey}`}}return{...r,headers:t}}i(j,"withConfiguredAuth");function D(r,e){return e?.apiKey??r?.apiKey}i(D,"configuredApiKey");function O(r,e){if(!(!r?.headers&&!e?.headers))return{...r?.headers,...e?.headers}}i(O,"configuredHeaders");async function R(r,e,a){const t={...a};for(const n of new Set(r.flatMap(C))){if(t[n]!==void 0)continue;const o=await e.env(n);o!==void 0&&(t[n]=o)}return Object.keys(t).length>0?t:void 0}i(R,"configContextEnv");function te(r,e,a,t){const n=e?.auth.apiKey,o=D(a,t),l=t?.oauth??e?.auth.oauth;if(!n&&o===void 0&&l)return;const h=O(a,t),f=t?.authHeader??a?.authHeader??!1;return{name:n?.name??"API key",login:n?.login??(async c=>({type:"api_key",key:await c.prompt({type:"secret",message:"Enter API key"})})),check:i(async c=>{if(c.credential){if(n?.check)return n.check(c);if(c.credential.key)return{type:"api_key",source:"stored credential"};const m=await n?.resolve(c);return m?{type:"api_key",source:m.source}:void 0}if(o!==void 0){if(W(o))return{type:"api_key",source:"configured API key"};const m=C(o);for(const k of m)if(await c.ctx.env(k)===void 0)return;return{type:"api_key",source:"configured API key"}}if(n?.check)return n.check(c);const d=await n?.resolve(c);return d?{type:"api_key",source:d.source}:void 0},"check"),resolve:i(async c=>{let d;if(c.credential)d=n?await n.resolve(c):c.credential.key?{auth:{apiKey:c.credential.key},env:c.credential.env,source:"stored credential"}:void 0;else if(o!==void 0){const w=await R([o],c.ctx),P=J(o,`API key for provider "${r}"`,w);d=n?await n.resolve({...c,credential:{type:"api_key",key:P}}):{auth:{apiKey:P},source:"configured API key"}}else d=await n?.resolve(c);if(!d)return;const m={...c.credential?.env??{},...d.env??{}},k=await R(Object.values(h??{}),c.ctx,m),v=M(h,`provider "${r}"`,k);return{...d,auth:j(d.auth,v,f)}},"resolve")}}i(te,"composeApiKeyAuth");function ae(r,e,a,t){const n=t?.oauth?re(t.oauth):e?.auth.oauth;if(!n)return;const o=O(a,t),l=t?.authHeader??a?.authHeader??!1;return{...n,toAuth:i(async h=>{const f=await n.toAuth(h),c=h.env,d=M(o,`provider "${r}"`,typeof c=="object"&&c!==null?c:void 0);return j(f,d,l)},"toAuth")}}i(ae,"composeOAuthAuth");function z(r,e,a){const t=y(r,"chat")?e?.models?.find(l=>l.id===r.id):void 0,n=a?.models?.find(l=>(l.type??"chat")===(r.type??"chat")&&l.id===r.id),o={...y(r,"chat")?e?.modelOverrides?.[r.id]?.headers:void 0,...t?.headers,...n?.headers};return Object.keys(o).length>0?o:void 0}i(z,"rawModelHeaders");function le(r,e,a,t){if(t.streamSimple&&!t.api)throw new Error(`Provider ${r}: "api" is required when registering streamSimple.`);H(r,L(r,U(e),a),t)}i(le,"validateExtensionProvider");function pe(r,e,a,t,n){const o=a.getProvider(r);let l,h;const f=i(()=>t&&h?{...t,models:h}:t,"currentExtension"),c=i(()=>{let s=H(r,L(r,U(e),o),f());return l&&t?.oauth?.modifyModels&&(s=[...t.oauth.modifyModels(s.filter(u=>y(u,"chat")),l),...s.filter(u=>!y(u,"chat"))]),s.map(u=>{const p=o?.modelOverrides?.[u.id];return p&&y(u,"chat")?X(u,p):u})},"getAllModels");c();const d=te(r,e,o,t),m=ae(r,e,o,t);if(!d&&!m)throw new Error(`Provider ${r}: no authentication method configured.`);const k=i(s=>e?.supportsApi?.(s.api)??e?.getModels().some(u=>u.api===s.api)??!1,"supportsBaseApi"),v=i((s,u,p,g)=>V(s,async()=>{if(t?.streamSimple&&s.api===t.api)return t.streamSimple(s,u,p);if(e&&k(s))return g?e.streamSimple(s,u,p):e.stream(s,u,p);const E=q(s.api);if(!E)throw new Error(`No API provider registered for api: ${s.api}`);return g?E.streamSimple(s,u,p):E.stream(s,u,p)}),"streamWith"),w={id:r,name:t?.name??o?.name??e?.name??t?.oauth?.name??r,baseUrl:t?.baseUrl??o?.baseUrl??e?.baseUrl,headers:e?.headers,auth:{...d?{apiKey:d}:{},...m?{oauth:m}:{}},getModels:i(()=>c().filter(s=>y(s,"chat")),"getModels"),getAllModels:c,refreshModels:e?.refreshModels||t?.refreshModels||t?.oauth?.modifyModels?async s=>{await e?.refreshModels?.(s);let u;if(t?.refreshModels&&(u=await t.refreshModels(s)),s.signal.aborted)return;const p=s.credential?.type==="oauth"?s.credential:void 0;await s.publish({update:i(()=>{u&&(H(r,L(r,U(e),o),{...t,models:u}),h=u,n?.(u)),l=p},"update")})}:void 0,filterModels:e?.filterModels?(s,u)=>e.filterModels(s,u):void 0,filterAllModels:e?.filterAllModels?(s,u)=>e.filterAllModels(s,u):void 0,stream:i((s,u,p)=>v(s,u,p,!1),"stream"),streamSimple:i((s,u,p)=>v(s,u,p,!0),"streamSimple")},P=e?.fetchDeferred;P&&(w.fetchDeferred=(s,u,p)=>P(s,u,p));const K=e?.cancelDeferred;K&&(w.cancelDeferred=(s,u,p)=>K(s,u,p));const S=t?.images,A=e?.generateImages;(A||Object.keys(S??{}).length>0)&&(w.generateImages=(s,u,p)=>{const g=S?.[s.api];return g?g.generateImages(s,u,p):A?A(s,u,p):Promise.resolve(b(s,new Error(`Provider ${r} has no image implementation for "${s.api}"`)))});const _=t?.classifiers,$=e?.classify;return($||Object.keys(_??{}).length>0)&&(w.classify=(s,u,p)=>{const g=_?.[s.api];return g?g.classify(s,u,p):$?$(s,u,p):Promise.resolve(N(s,new Error(`Provider ${r} has no classifier implementation for "${s.api}"`)))}),w}i(pe,"composeModelProvider");function he(r,e,a,t){return M(z(r,e,a),`model "${r.provider}/${r.id}"`,t)}i(he,"resolveConfiguredModelHeaders");function de(r,e,a){const t=M({...O(e,a),...z(r,e,a)},`model "${r.provider}/${r.id}"`);return{headers:r.headers||t?{...r.headers,...t}:void 0,authHeader:a?.authHeader??e?.authHeader??!1}}i(de,"resolveCompatibilityRequestConfig");function fe(r,e){const a=D(r,e);if(a===void 0)return;if(W(a))return{configured:!0,source:"models_json_command"};const t=C(a);return t.length>0?F(a)?{configured:!0,source:"environment",label:t.join(", ")}:{configured:!1}:{configured:!0,source:e?.apiKey!==void 0?"fallback":"models_json_key"}}i(fe,"configuredRequestAuthStatus");export{ce as clearApiKeyCache,pe as composeModelProvider,fe as configuredRequestAuthStatus,de as resolveCompatibilityRequestConfig,he as resolveConfiguredModelHeaders,le as validateExtensionProvider};
1
+ var B=Object.defineProperty;var u=(r,e)=>B(r,"name",{value:e,configurable:!0});import{isModelType as m,lazyStream as V}from"@earendil-works/pi-ai";import{getApiProvider as q}from"@earendil-works/pi-ai/compat";import{classifierErrorResult as N,imageErrorResult as b}from"@earendil-works/pi-ai/utils/model-operations";import{clearConfigValueCache as x,getConfigValueEnvVarNames as C,isCommandConfigValue as W,isConfigValueConfigured as F,resolveConfigValueOrThrow as J,resolveHeadersOrThrow as M}from"./resolve-config-value.js";const ce=x;function U(r){return r?r.getAllModels?.()??r.getModels():[]}u(U,"getAllProviderModels");function T(r,e){if(!e)return r;const a={...r,...e},t=r,n=e,i=a;for(const l of["openRouterRouting","vercelGatewayRouting","chatTemplateKwargs","chatTemplateArgs"]){const h=t?.[l],f=n[l];(typeof h=="object"&&h!==null||typeof f=="object"&&f!==null)&&(i[l]={...h,...f})}return a}u(T,"mergeCompat");function G(r,e){return e?{...r,...e,images:e.images?{...r?.images,...e.images,resize:e.images.resize?{...r?.images?.resize,...e.images.resize}:r?.images?.resize}:r?.images}:r}u(G,"mergeInputLimits");function Q(r,e){if(!e)return r;const a={...r};for(const t of["off","minimal","low","medium","high","xhigh","max"]){const n=e[t];n&&(a[t]={...r?.[t],...n})}return a}u(Q,"mergeSamplingParamsByThinkingLevel");function X(r,e){return{...r,name:e.name??r.name,reasoning:e.reasoning??r.reasoning,thinkingLevelMap:e.thinkingLevelMap?{...r.thinkingLevelMap,...e.thinkingLevelMap}:r.thinkingLevelMap,input:e.input??r.input,inputLimits:G(r.inputLimits,e.inputLimits),cost:e.cost?{input:e.cost.input??r.cost.input,output:e.cost.output??r.cost.output,cacheRead:e.cost.cacheRead??r.cost.cacheRead,cacheWrite:e.cost.cacheWrite??r.cost.cacheWrite,tiers:e.cost.tiers??r.cost.tiers}:r.cost,promptCache:e.promptCache?{...r.promptCache,...e.promptCache}:r.promptCache,contextWindow:e.contextWindow??r.contextWindow,maxTokens:e.maxTokens??r.maxTokens,samplingParams:e.samplingParams?{...r.samplingParams,...e.samplingParams}:r.samplingParams,samplingParamsByThinkingLevel:Q(r.samplingParamsByThinkingLevel,e.samplingParamsByThinkingLevel),compat:T(r.compat,e.compat)}}u(X,"applyModelOverride");function Y(r,e,a,t){const n=e.api??a.api??t?.api;if(!n)throw new Error(`Provider ${r}, model ${e.id}: no "api" specified. Set at provider or model level.`);const i=e.baseUrl??a.baseUrl??t?.baseUrl;if(!i)throw new Error(`Provider ${r}: "baseUrl" is required when defining custom models.`);if(e.contextWindow!==void 0&&e.contextWindow<=0)throw new Error(`Provider ${r}, model ${e.id}: invalid contextWindow`);if(e.maxTokens!==void 0&&e.maxTokens<=0)throw new Error(`Provider ${r}, model ${e.id}: invalid maxTokens`);return{id:e.id,name:e.name??e.id,api:n,provider:r,baseUrl:i,reasoning:e.reasoning??!1,thinkingLevelMap:e.thinkingLevelMap,input:e.input??["text"],inputLimits:e.inputLimits,cost:e.cost??{input:0,output:0,cacheRead:0,cacheWrite:0},promptCache:e.promptCache,contextWindow:e.contextWindow??128e3,maxTokens:e.maxTokens??16384,samplingParams:e.samplingParams,samplingParamsByThinkingLevel:e.samplingParamsByThinkingLevel,headers:void 0,compat:T(a.compat,e.compat)}}u(Y,"modelFromJson");function Z(r,e,a){const t=r.filter(n=>m(n,"chat"));return t.find(n=>n.id===e)??(a?t.find(n=>n.api===a):void 0)??t.find(n=>n.api==="openai-completions")??t[0]}u(Z,"findModelDefaults");function I(r,e){const a=e.type??"chat",t=r.filter(n=>m(n,a));return t.find(n=>n.id===e.id)??(e.api?t.find(n=>n.api===e.api):void 0)??(a==="chat"?t.find(n=>n.api==="openai-completions"):void 0)??t[0]}u(I,"findExtensionModelDefaults");function ee(r,e,a,t){const n=t.type??"chat",i=I(e,t),l=t.api??(n==="chat"?a.api:void 0)??i?.api;if(!l)throw new Error(`Provider ${r}, model ${t.id}: no "api" specified. Set it at model level${n==="chat"?" or provider level":""}.`);const h=t.baseUrl??a.baseUrl??i?.baseUrl;if(!h)throw new Error(`Provider ${r}: "baseUrl" is required when defining custom models.`);return t.type==="image"?{...t,api:l,provider:r,baseUrl:h,headers:void 0}:t.type==="classifier"?{...t,api:l,provider:r,baseUrl:h,headers:void 0}:{...t,api:l,provider:r,baseUrl:h,headers:void 0}}u(ee,"extensionModelFromDefinition");function L(r,e,a){if(!a)return[...e];if(a.oauth&&!a.baseUrl)throw new Error(`Provider ${r}: "baseUrl" is required when "oauth" is set.`);const t=a.modelOverrides&&Object.keys(a.modelOverrides).length>0;if(!a.models?.length&&!a.baseUrl&&!a.headers&&!a.compat&&!t&&!a.apiKey&&!a.oauth&&a.authHeader===void 0)throw new Error(`Provider ${r}: must specify "baseUrl", "headers", "compat", "modelOverrides", or "models".`);const n=e.map(i=>{const l=a.oauth==="radius"?i.baseUrl:a.baseUrl??i.baseUrl;return m(i,"chat")?{...i,baseUrl:l,compat:T(i.compat,a.compat)}:m(i,"classifier")&&a.compat?{...i,baseUrl:l,compat:{...i.compat,...a.compat}}:{...i,baseUrl:l}});for(const i of a.models??[]){const l=n.findIndex(c=>m(c,"chat")&&c.id===i.id),h=Z(n,i.id,i.api??a.api),f=Y(r,i,a,h);l>=0?n[l]=f:n.push(f)}return n}u(L,"applyModelsJson");function H(r,e,a){return a?a.models?a.models.map(t=>ee(r,e,a,t)):a.baseUrl?e.map(t=>({...t,baseUrl:a.baseUrl})):[...e]:[...e]}u(H,"applyExtension");function re(r){return{name:r.name,isSubscription:r.isSubscription,login:u(async e=>({...await r.login({onAuth:u(t=>e.notify({type:"auth_url",...t}),"onAuth"),onDeviceCode:u(t=>e.notify({type:"device_code",...t}),"onDeviceCode"),onPrompt:u(t=>e.prompt({type:"text",...t}),"onPrompt"),onProgress:u(t=>e.notify({type:"progress",message:t}),"onProgress"),onManualCodeInput:u(()=>e.prompt({type:"manual_code",message:"Paste the authorization code"}),"onManualCodeInput"),onSelect:u(t=>e.prompt({type:"select",...t}),"onSelect"),signal:e.signal}),type:"oauth"}),"login"),refresh:u(async(e,a)=>({...await r.refreshToken(e,a),type:"oauth"}),"refresh"),toAuth:u(async e=>({apiKey:r.getApiKey(e)}),"toAuth")}}u(re,"adaptOAuth");function j(r,e,a){let t=r.headers||e?{...r.headers,...e}:void 0;if(a){if(!r.apiKey)throw new Error("authHeader requires a resolved API key");t={...t,Authorization:`Bearer ${r.apiKey}`}}return{...r,headers:t}}u(j,"withConfiguredAuth");function D(r,e){return e?.apiKey??r?.apiKey}u(D,"configuredApiKey");function O(r,e){if(!(!r?.headers&&!e?.headers))return{...r?.headers,...e?.headers}}u(O,"configuredHeaders");async function R(r,e,a){const t={...a};for(const n of new Set(r.flatMap(C))){if(t[n]!==void 0)continue;const i=await e.env(n);i!==void 0&&(t[n]=i)}return Object.keys(t).length>0?t:void 0}u(R,"configContextEnv");function te(r,e,a,t){const n=e?.auth.apiKey,i=D(a,t),l=t?.oauth??e?.auth.oauth;if(!n&&i===void 0&&l)return;const h=O(a,t),f=t?.authHeader??a?.authHeader??!1;return{name:n?.name??"API key",login:n?.login??(async c=>({type:"api_key",key:await c.prompt({type:"secret",message:"Enter API key"})})),check:u(async c=>{if(c.credential){if(n?.check)return n.check(c);if(c.credential.key)return{type:"api_key",source:"stored credential"};const y=await n?.resolve(c);return y?{type:"api_key",source:y.source}:void 0}if(i!==void 0){if(W(i))return{type:"api_key",source:"configured API key"};const y=C(i);for(const k of y)if(await c.ctx.env(k)===void 0)return;return{type:"api_key",source:"configured API key"}}if(n?.check)return n.check(c);const d=await n?.resolve(c);return d?{type:"api_key",source:d.source}:void 0},"check"),resolve:u(async c=>{let d;if(c.credential)d=n?await n.resolve(c):c.credential.key?{auth:{apiKey:c.credential.key},env:c.credential.env,source:"stored credential"}:void 0;else if(i!==void 0){const w=await R([i],c.ctx),P=J(i,`API key for provider "${r}"`,w);d=n?await n.resolve({...c,credential:{type:"api_key",key:P}}):{auth:{apiKey:P},source:"configured API key"}}else d=await n?.resolve(c);if(!d)return;const y={...c.credential?.env??{},...d.env??{}},k=await R(Object.values(h??{}),c.ctx,y),v=M(h,`provider "${r}"`,k);return{...d,auth:j(d.auth,v,f)}},"resolve")}}u(te,"composeApiKeyAuth");function ae(r,e,a,t){const n=t?.oauth?re(t.oauth):e?.auth.oauth;if(!n)return;const i=O(a,t),l=t?.authHeader??a?.authHeader??!1;return{...n,toAuth:u(async h=>{const f=await n.toAuth(h),c=h.env,d=M(i,`provider "${r}"`,typeof c=="object"&&c!==null?c:void 0);return j(f,d,l)},"toAuth")}}u(ae,"composeOAuthAuth");function z(r,e,a){const t=m(r,"chat")?e?.models?.find(l=>l.id===r.id):void 0,n=a?.models?.find(l=>(l.type??"chat")===(r.type??"chat")&&l.id===r.id),i={...m(r,"chat")?e?.modelOverrides?.[r.id]?.headers:void 0,...t?.headers,...n?.headers};return Object.keys(i).length>0?i:void 0}u(z,"rawModelHeaders");function le(r,e,a,t){if(t.streamSimple&&!t.api)throw new Error(`Provider ${r}: "api" is required when registering streamSimple.`);H(r,L(r,U(e),a),t)}u(le,"validateExtensionProvider");function pe(r,e,a,t,n){const i=a.getProvider(r);let l,h;const f=u(()=>t&&h?{...t,models:h}:t,"currentExtension"),c=u(()=>{let s=H(r,L(r,U(e),i),f());return l&&t?.oauth?.modifyModels&&(s=[...t.oauth.modifyModels(s.filter(o=>m(o,"chat")),l),...s.filter(o=>!m(o,"chat"))]),s.map(o=>{const p=i?.modelOverrides?.[o.id];return p&&m(o,"chat")?X(o,p):o})},"getAllModels");c();const d=te(r,e,i,t),y=ae(r,e,i,t);if(!d&&!y)throw new Error(`Provider ${r}: no authentication method configured.`);const k=u(s=>e?.supportsApi?.(s.api)??e?.getModels().some(o=>o.api===s.api)??!1,"supportsBaseApi"),v=u((s,o,p,g)=>V(s,async()=>{if(t?.streamSimple&&s.api===t.api)return t.streamSimple(s,o,p);if(e&&k(s))return g?e.streamSimple(s,o,p):e.stream(s,o,p);const E=q(s.api);if(!E)throw new Error(`No API provider registered for api: ${s.api}`);return g?E.streamSimple(s,o,p):E.stream(s,o,p)}),"streamWith"),w={id:r,name:t?.name??i?.name??e?.name??t?.oauth?.name??r,baseUrl:t?.baseUrl??i?.baseUrl??e?.baseUrl,headers:e?.headers,auth:{...d?{apiKey:d}:{},...y?{oauth:y}:{}},getModels:u(()=>c().filter(s=>m(s,"chat")),"getModels"),getAllModels:c,refreshModels:e?.refreshModels||t?.refreshModels||t?.oauth?.modifyModels?async s=>{await e?.refreshModels?.(s);let o;if(t?.refreshModels&&(o=await t.refreshModels(s)),s.signal.aborted)return;const p=s.credential?.type==="oauth"?s.credential:void 0;await s.publish({update:u(()=>{o&&(H(r,L(r,U(e),i),{...t,models:o}),h=o,n?.(o)),l=p},"update")})}:void 0,filterModels:e?.filterModels?(s,o)=>e.filterModels(s,o):void 0,filterAllModels:e?.filterAllModels?(s,o)=>e.filterAllModels(s,o):void 0,stream:u((s,o,p)=>v(s,o,p,!1),"stream"),streamSimple:u((s,o,p)=>v(s,o,p,!0),"streamSimple")},P=e?.fetchDeferred;P&&(w.fetchDeferred=(s,o,p)=>P(s,o,p));const K=e?.cancelDeferred;K&&(w.cancelDeferred=(s,o,p)=>K(s,o,p));const S=t?.images,A=e?.generateImages;(A||Object.keys(S??{}).length>0)&&(w.generateImages=(s,o,p)=>{const g=S?.[s.api];return g?g.generateImages(s,o,p):A?A(s,o,p):Promise.resolve(b(s,new Error(`Provider ${r} has no image implementation for "${s.api}"`)))});const _=t?.classifiers,$=e?.classify;return($||Object.keys(_??{}).length>0)&&(w.classify=(s,o,p)=>{const g=_?.[s.api];return g?g.classify(s,o,p):$?$(s,o,p):Promise.resolve(N(s,new Error(`Provider ${r} has no classifier implementation for "${s.api}"`)))}),w}u(pe,"composeModelProvider");function he(r,e,a,t){return M(z(r,e,a),`model "${r.provider}/${r.id}"`,t)}u(he,"resolveConfiguredModelHeaders");function de(r,e,a){const t=M({...O(e,a),...z(r,e,a)},`model "${r.provider}/${r.id}"`);return{headers:r.headers||t?{...r.headers,...t}:void 0,authHeader:a?.authHeader??e?.authHeader??!1}}u(de,"resolveCompatibilityRequestConfig");function fe(r,e){const a=D(r,e);if(a===void 0)return;if(W(a))return{configured:!0,source:"models_json_command"};const t=C(a);return t.length>0?F(a)?{configured:!0,source:"environment",label:t.join(", ")}:{configured:!1}:{configured:!0,source:e?.apiKey!==void 0?"fallback":"models_json_key"}}u(fe,"configuredRequestAuthStatus");export{ce as clearApiKeyCache,pe as composeModelProvider,fe as configuredRequestAuthStatus,de as resolveCompatibilityRequestConfig,he as resolveConfiguredModelHeaders,le as validateExtensionProvider};
@@ -1 +1 @@
1
- var T=Object.defineProperty;var o=(e,t)=>T(e,"name",{value:t,configurable:!0});import{getModelType as w,isModelType as _}from"@earendil-works/pi-ai";import{APP_NAME as b,VERSION as y}from"../config.js";import{fetchWithRetry as R}from"../utils/management-http.js";import{getPiUserAgent as O}from"../utils/pi-user-agent.js";const C="https://pi.dev",L=4e3,S=14400*1e3,c=["chat","image","classifier"];function U(e){return e.type===void 0||typeof e.type=="string"&&c.includes(e.type)}o(U,"isSupportedModelType");function g(e,t){const n=new Map;for(const s of[...e,...t])n.set(`${w(s)}\0${s.id}`,s);return[...n.values()]}o(g,"mergeModels");function j(e,t){const n=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(!n)throw new Error(`Invalid model catalog for provider "${e}"`);return n.filter(s=>typeof s=="object"&&s!==null&&"id"in s).filter(U).map(s=>({...s,provider:e}))}o(j,"parseCatalog");function m(e,t){return e?t!==void 0&&(e.lastModified===void 0||e.lastModified<=t)?[]:e.models:[]}o(m,"remoteModels");function I(e=b){return e==="pi"?C:void 0}o(I,"getDefaultCatalogBaseUrl");function B(e,t,n){let s=[];return{...e,getModels:o(()=>g(e.getModels(),s.filter(i=>_(i,"chat"))),"getModels"),getAllModels:o(()=>g(e.getAllModels?.()??e.getModels(),s),"getAllModels"),refreshModels:o(async i=>{const r=i.stored,M=m(r,n).filter(E=>E.provider===e.id);if(!await i.publish({update:o(()=>{s=M},"update")})||!i.allowNetwork||i.signal.aborted||!i.force&&r?.checkedAt!==void 0&&r.lastModified!==void 0&&Date.now()-r.checkedAt<S)return;const l=r&&r.models.length>0?r.etag:void 0,f=new URL(`/api/models/providers/${encodeURIComponent(e.id)}`,t);f.searchParams.set("types",c.join(","));const d=await R(f,{headers:{accept:"application/json","User-Agent":O(y),...l?{"if-none-match":l}:{}},signal:i.signal},{attemptTimeoutMs:L});if(i.signal.aborted)return;const a=Date.now();if(d.status===304&&r){await i.publish({persist:{...r,checkedAt:a}});return}if(d.status===404||d.status===501){await i.publish({persist:{...r??{models:[]},checkedAt:a,lastModified:0,etag:void 0}});return}if(!d.ok)throw await i.publish({persist:{...r??{models:[]},checkedAt:a}}),new Error(`Model catalog request failed for ${e.id}: ${d.status}`);const h=j(e.id,await d.json()),u=Date.parse(d.headers.get("last-modified")??"");if(i.signal.aborted)return;const p={models:h,checkedAt:a,lastModified:Number.isNaN(u)?0:u,etag:d.headers.get("etag")??void 0},A=m(p,n);await i.publish({persist:p,update:o(()=>{s=A},"update")})},"refreshModels")}}o(B,"withRemoteCatalog");export{c as REMOTE_CATALOG_MODEL_TYPES,S as REMOTE_CATALOG_REFRESH_INTERVAL_MS,I as getDefaultCatalogBaseUrl,B as withRemoteCatalog};
1
+ var T=Object.defineProperty;var i=(e,t)=>T(e,"name",{value:t,configurable:!0});import{getModelType as y,isModelType as M}from"@earendil-works/pi-ai";import{APP_NAME as _,VERSION as R}from"../config.js";import{fetchWithRetry as C}from"../utils/management-http.js";import{getPiUserAgent as O}from"../utils/pi-user-agent.js";const N="https://pi.dev",k=4e3,L=14400*1e3,m=["chat","image","classifier"];function P(e){return e.type===void 0||typeof e.type=="string"&&m.includes(e.type)}i(P,"isSupportedModelType");function g(e,t){const r=new Map;for(const o of[...e,...t])r.set(`${y(o)}\0${o.id}`,o);return[...r.values()]}i(g,"mergeModels");function S(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(o=>typeof o=="object"&&o!==null&&"id"in o).filter(P).map(o=>({...o,provider:e}))}i(S,"parseCatalog");async function h(e,t){const r=Date.parse(t.headers.get("last-modified")??"");return{models:S(e,await t.json()),lastModified:Number.isNaN(r)?0:r,etag:t.headers.get("etag")??void 0}}i(h,"readCatalog");function w(e,t){return t===void 0||e!==void 0&&e>t}i(w,"isNewer");function A(e,t){return e&&w(e.lastModified,t)?e.models:[]}i(A,"remoteModels");function b(e,t,r,o){const s=new URL(`/api/models/providers/${encodeURIComponent(e)}`,t);return s.searchParams.set("types",m.join(",")),C(s,{headers:{accept:"application/json","User-Agent":O(R),...o?{"if-none-match":o}:{}},signal:r},{attemptTimeoutMs:k})}i(b,"requestCatalog");function q(e=_){return e==="pi"?N:void 0}i(q,"getDefaultCatalogBaseUrl");function z(e,t,r){let o=[];return{...e,getModels:i(()=>g(e.getModels(),o.filter(s=>M(s,"chat"))),"getModels"),getAllModels:i(()=>g(e.getAllModels?.()??e.getModels(),o),"getAllModels"),refreshModels:i(async s=>{const a=s.stored,u=A(a,r).filter(E=>E.provider===e.id);if(!await s.publish({update:i(()=>{o=u},"update")})||!s.allowNetwork||s.signal.aborted||!s.force&&a?.checkedAt!==void 0&&a.lastModified!==void 0&&Date.now()-a.checkedAt<L)return;const n=a&&a.models.length>0?a.etag:void 0,l=await b(e.id,t,s.signal,n);if(s.signal.aborted)return;const f=Date.now();if(l.status===304&&a){await s.publish({persist:{...a,checkedAt:f}});return}if(l.status===404||l.status===501){await s.publish({persist:{...a??{models:[]},checkedAt:f,lastModified:0,etag:void 0}});return}if(!l.ok)throw await s.publish({persist:{...a??{models:[]},checkedAt:f}}),new Error(`Model catalog request failed for ${e.id}: ${l.status}`);const c=await h(e.id,l);if(s.signal.aborted)return;const d={...c,checkedAt:f},p=A(d,r);await s.publish({persist:d,update:i(()=>{o=p},"update")})},"refreshModels")}}i(z,"withRemoteCatalog");function G(e,t,r,o){let s=[];const a=i(()=>e.getAllModels?.()??e.getModels(),"builtinModels"),u=i(()=>s.length>0?s:a(),"getAllModels");return{...e,getModels:i(()=>u().filter(n=>M(n,"chat")),"getModels"),getAllModels:u,refreshModels:i(async n=>{const l=(n.stored?.models??[]).filter(d=>d.provider===e.id);if(!await n.publish({update:i(()=>{s=l},"update")})||!n.allowNetwork||n.signal.aborted)return;let f=[];if(r!==void 0){const d=await b(e.id,r,n.signal);if(n.signal.aborted)return;if(d.status!==404&&d.status!==501){if(!d.ok)throw new Error(`Model catalog request failed for ${e.id}: ${d.status}`);const p=await h(e.id,d);w(p.lastModified,o)&&(f=p.models)}}const c=await t(g(a(),f),n);n.signal.aborted||await n.publish({persist:{models:c,checkedAt:Date.now()},update:i(()=>{s=c},"update")})},"refreshModels")}}i(G,"withPersonalizedCatalog");export{m as REMOTE_CATALOG_MODEL_TYPES,L as REMOTE_CATALOG_REFRESH_INTERVAL_MS,q as getDefaultCatalogBaseUrl,G as withPersonalizedCatalog,z as withRemoteCatalog};
@@ -1 +1 @@
1
- var lt=Object.defineProperty;var P=(c,t)=>lt(c,"name",{value:t,configurable:!0});import{existsSync as f,readdirSync as ct,readFileSync as $,statSync as T}from"node:fs";import{basename as mt,dirname as Q,join as p,resolve as y,sep as b}from"node:path";import{detectCapabilities as pt,getTerminalColorMode as dt}from"@earendil-works/pi-tui";import V from"chalk";import{APP_NAME as ut,CONFIG_DIR_NAME as v,getExamplesPath as ft,getPackageDir as Pt}from"../config.js";import{dalBuiltinExtensionPaths as gt}from"../dal/builtins.js";import{applyCommunityEnv as xt,hostDependenciesOf as Z,installedHostCopies as St,isAdaptablePackage as yt,tryEnsurePackageAdapted as wt}from"../dal/extension-compat.js";import{fill as A,t as S}from"../dal/i18n.js";import{loadThemeFromPath as vt}from"../modes/interactive/theme/theme.js";import{canonicalizePath as M,isLocalPath as j,resolvePath as w}from"../utils/paths.js";import{stripBom as W}from"../utils/text.js";import{createEventBus as kt}from"./event-bus.js";import{clearExtensionCache as Et,createExtensionRuntime as Dt,loadExtensionFromFactory as tt,loadExtensionsCached as et}from"./extensions/loader.js";import{findGitPaths as Ft}from"./footer-data-provider.js";import{DefaultPackageManager as Tt}from"./package-manager.js";import{loadPromptTemplates as bt}from"./prompt-templates.js";import{SettingsManager as Mt}from"./settings-manager.js";import{loadSkills as It}from"./skills.js";import{BUILTIN_PATH_PREFIX as k,createSourceInfo as I,getSyntheticPathSource as Ot,isSyntheticPath as N}from"./source-info.js";import{resetTimings as Rt}from"./timings.js";function st(c,t,n){let s;try{s=Pt()}catch{s=void 0}xt({agentDir:n.agentDir,packageDir:s});const i=[],e=new Map;for(const o of c){const a=t.get(o);a?.packageRoot&&!e.has(a.packageRoot)&&e.set(a.packageRoot,a)}for(const[o,a]of e){const l=p(o,"package.json");if(!f(l))continue;JSON.parse(W($(l,"utf-8"))),yt(o,a.source,n)&&wt(o);const h=St(o,Z(o));if(h.length===0)continue;const g=Z(o).filter(x=>h.some(d=>d.endsWith(p(...x.split("/")))));i.push({path:l,warning:A(S('\u6269\u5C55\u5305\u5728 dependencies \u91CC\u81EA\u5E26\u4E86 DAL \u5DF2\u63D0\u4F9B\u7684\u5E93\uFF08{names}\uFF09\uFF0C\u8FD9\u4E9B\u526F\u672C\u4F1A\u548C DAL \u81EA\u5DF1\u7684\u91CD\u590D\u52A0\u8F7D\u3002\u8BF7\u628A\u5B83\u4EEC\u6539\u5230 peerDependencies\uFF0C\u7248\u672C\u5199 "*"\u3002'),{names:g.join(", ")})})}return i}P(st,"prepareExtensionPackages");function B(c,t){c.warnings=[...new Map([...c.warnings??[],...t].map(n=>[n.path,n])).values()]}P(B,"mergeExtensionWarnings");function it(c){return typeof c!="function"&&c.builtin===!0}P(it,"isBuiltinExtension");let nt;function Ct(c){return nt??=new Set(gt().map(t=>y(t))),nt.has(y(c))}P(Ct,"isDalBundledExtensionPath");function ot(c,t){const n=P(i=>[...[...i.tools.keys()].map(e=>`tool:${e}`),...[...i.commands.keys()].map(e=>`command:${e}`),...[...i.flags.keys()].map(e=>`flag:${e}`)],"names"),s=new Map(c.filter(i=>!i.replaceable).flatMap(i=>n(i).map(e=>[e,i])));return c.filter(i=>{if(!i.replaceable)return!0;const e=n(i).map(o=>({name:o,extension:s.get(o)})).find(o=>o.extension!==void 0);if(!e)return!0;if(i.path.startsWith(k)&&!Ct(e.extension.path)){const o=i.path.slice(k.length),[a,l]=e.name.split(":",2),h=a==="command"?`/${l}`:a==="flag"?`--${l}`:l;t?.push({path:i.path,warning:A(S("\u6269\u5C55 {path} \u6CE8\u518C\u4E86{kind} `{name}`\uFF0C\u6240\u4EE5\u5185\u7F6E\u6269\u5C55 `{builtin}` \u6CA1\u6709\u52A0\u8F7D\u3002\u8981\u4F7F\u7528 `{builtin}`\uFF0C\u8FD0\u884C `{app} config`\uFF0C\u5728\u5185\u7F6E\u6269\u5C55\u91CC\u786E\u8BA4\u5B83\u5DF2\u542F\u7528\uFF0C\u7136\u540E\u505C\u7528\u6216\u79FB\u9664\u8FD9\u4E2A\u6269\u5C55\u3002\u4E24\u8005\u6700\u597D\u53EA\u4FDD\u7559\u4E00\u4E2A\u3002"),{path:e.extension.path,kind:a==="command"?S("\u4E00\u4E2A\u547D\u4EE4"):a==="flag"?S("\u4E00\u4E2A\u53C2\u6570"):S("\u4E00\u4E2A\u5DE5\u5177"),name:h,builtin:o,app:ut})})}return!1})}P(ot,"omitReplacedExtensions");function at(c,t){if(c){if(f(c))try{return W($(c,"utf-8"))}catch(n){return console.error(V.yellow(A(S("\u8B66\u544A\uFF1A\u65E0\u6CD5\u8BFB\u53D6{what}\u6587\u4EF6 {path}\uFF1A{error}"),{what:t,path:c,error:String(n)}))),c}return c}}P(at,"resolvePromptInput");function L(c){const t=["AGENTS.override.md","AGENTS.md","AGENTS.MD","CLAUDE.md","CLAUDE.MD"];for(const n of t){const s=p(c,n);if(f(s))try{if(!T(s).isFile())continue;return{path:s,content:W($(s,"utf-8"))}}catch(i){console.error(V.yellow(A(S("\u8B66\u544A\uFF1A\u65E0\u6CD5\u8BFB\u53D6 {path}\uFF1A{error}"),{path:s,error:String(i)})))}}return null}P(L,"loadContextFileFromDir");function At(c){const t=Ft(c);if(!t)return;const n=M(t.commonGitDir),s=M(t.repoDir),i=Q(n);if(!s.startsWith(`${i}${b}`)||M(p(i,".git"))!==n)return;const e=L(s);return e?p(i,mt(e.path)):void 0}P(At,"findShadowedContextFile");function Bt(c){const t=w(c.cwd),n=w(c.agentDir),s=[],i=new Set,e=L(n);e&&(s.push(e),i.add(e.path));const o=[],a=At(t);let l=t;for(;;){const h=L(l),g=a!==void 0&&M(h?.path??"")===a;h&&!g&&!i.has(h.path)&&(o.unshift(h),i.add(h.path));const x=Q(l);if(x===l)break;l=x}return s.push(...o),s}P(Bt,"loadProjectContextFiles");class ie{static{P(this,"DefaultResourceLoader")}cwd;agentDir;settingsManager;eventBus;packageManager;additionalExtensionPaths;additionalSkillPaths;additionalPromptTemplatePaths;additionalThemePaths;extensionFactories;builtinExtensions;noExtensions;disabledBuiltinExtensions;noSkills;noPromptTemplates;noThemes;noContextFiles;systemPromptSource;appendSystemPromptSource;extensionsOverride;skillsOverride;promptsOverride;themesOverride;agentsFilesOverride;systemPromptOverride;appendSystemPromptOverride;extensionsResult;skills;skillDiagnostics;prompts;promptDiagnostics;themes;themeDiagnostics;agentsFiles;systemPrompt;systemPromptSourcePath;appendSystemPrompt;appendSystemPromptSourcePaths;lastSkillPaths;extensionSkillSourceInfos;extensionPromptSourceInfos;extensionThemeSourceInfos;resourceMetadataByPath;lastPromptPaths;lastThemePaths;loaded;constructor(t){this.cwd=w(t.cwd),this.agentDir=w(t.agentDir),this.settingsManager=t.settingsManager??Mt.create(this.cwd,this.agentDir),this.eventBus=t.eventBus??kt();const n=t.extensionFactories??[];this.extensionFactories=n.filter(s=>!it(s)),this.builtinExtensions=new Map(n.filter(it).map(s=>[s.name,s])),this.packageManager=new Tt({cwd:this.cwd,agentDir:this.agentDir,settingsManager:this.settingsManager,builtinExtensions:[...this.builtinExtensions.keys()]}),this.additionalExtensionPaths=t.additionalExtensionPaths??[],this.additionalSkillPaths=t.additionalSkillPaths??[],this.additionalPromptTemplatePaths=t.additionalPromptTemplatePaths??[],this.additionalThemePaths=t.additionalThemePaths??[],this.noExtensions=t.noExtensions??!1,this.disabledBuiltinExtensions=new Set(t.disabledBuiltinExtensions),this.noSkills=t.noSkills??!1,this.noPromptTemplates=t.noPromptTemplates??!1,this.noThemes=t.noThemes??!1,this.noContextFiles=t.noContextFiles??!1,this.systemPromptSource=t.systemPrompt,this.appendSystemPromptSource=t.appendSystemPrompt,this.extensionsOverride=t.extensionsOverride,this.skillsOverride=t.skillsOverride,this.promptsOverride=t.promptsOverride,this.themesOverride=t.themesOverride,this.agentsFilesOverride=t.agentsFilesOverride,this.systemPromptOverride=t.systemPromptOverride,this.appendSystemPromptOverride=t.appendSystemPromptOverride,this.extensionsResult={extensions:[],errors:[],runtime:Dt()},this.skills=[],this.skillDiagnostics=[],this.prompts=[],this.promptDiagnostics=[],this.themes=[],this.themeDiagnostics=[],this.agentsFiles=[],this.appendSystemPrompt=[],this.appendSystemPromptSourcePaths=[],this.lastSkillPaths=[],this.extensionSkillSourceInfos=new Map,this.extensionPromptSourceInfos=new Map,this.extensionThemeSourceInfos=new Map,this.resourceMetadataByPath=new Map,this.lastPromptPaths=[],this.lastThemePaths=[],this.loaded=!1}getExtensions(){return this.extensionsResult}getSkills(){return{skills:this.skills,diagnostics:this.skillDiagnostics}}getPrompts(){return{prompts:this.prompts,diagnostics:this.promptDiagnostics}}getThemes(){return{themes:this.themes,diagnostics:this.themeDiagnostics}}getAgentsFiles(){return{agentsFiles:this.agentsFiles}}getSystemPrompt(){return this.systemPrompt}getSystemPromptSource(){return this.systemPromptSourcePath?{path:this.systemPromptSourcePath}:void 0}getAppendSystemPrompt(){return this.appendSystemPrompt}getAppendSystemPromptSources(){return this.appendSystemPromptSourcePaths.map(t=>({path:t}))}extendResources(t){const n=this.normalizeExtensionPaths(t.skillPaths??[]),s=this.normalizeExtensionPaths(t.promptPaths??[]),i=this.normalizeExtensionPaths(t.themePaths??[]);for(const e of n)this.extensionSkillSourceInfos.set(e.path,I(e.path,e.metadata));for(const e of s)this.extensionPromptSourceInfos.set(e.path,I(e.path,e.metadata));for(const e of i)this.extensionThemeSourceInfos.set(e.path,I(e.path,e.metadata));n.length>0&&(this.lastSkillPaths=this.mergePaths(this.lastSkillPaths,n.map(e=>e.path)),this.updateSkillsFromPaths(this.lastSkillPaths,this.resourceMetadataByPath)),s.length>0&&(this.lastPromptPaths=this.mergePaths(this.lastPromptPaths,s.map(e=>e.path)),this.updatePromptsFromPaths(this.lastPromptPaths,this.resourceMetadataByPath)),i.length>0&&(this.lastThemePaths=this.mergePaths(this.lastThemePaths,i.map(e=>e.path)),this.updateThemesFromPaths(this.lastThemePaths,this.resourceMetadataByPath))}async loadProjectTrustExtensions(){return this.settingsManager.setProjectTrusted(!1),await this.settingsManager.reload(),this.loadCurrentExtensionSet({includeInlineFactories:!0})}async reload(t){Rt("extensions"),this.loaded&&Et();let n;if(t?.resolveProjectTrust){n=await this.loadProjectTrustExtensions();const r=await t.resolveProjectTrust({extensionsResult:n});this.settingsManager.setProjectTrusted(r)}await this.settingsManager.reload();const s=await this.packageManager.resolve(),i=await this.packageManager.resolveExtensionSources(this.additionalExtensionPaths,{temporary:!0});this.resourceMetadataByPath=new Map;const e=this.resourceMetadataByPath;this.extensionSkillSourceInfos=new Map,this.extensionPromptSourceInfos=new Map,this.extensionThemeSourceInfos=new Map;const o=P(r=>{for(const m of r)e.has(m.path)||e.set(m.path,m.metadata);return r.filter(m=>m.enabled)},"getEnabledResources"),a=P(r=>o(r).map(m=>m.path),"getEnabledPaths"),l=a(s.extensions),h=o(s.skills),g=a(s.prompts),x=a(s.themes),d=h.map(r=>this.mapSkillPath(r,e));for(const r of i.extensions)e.has(r.path)||e.set(r.path,{source:"cli",scope:"temporary",origin:"top-level"});for(const r of i.skills)e.has(r.path)||e.set(r.path,{source:"cli",scope:"temporary",origin:"top-level"});const u=a(i.extensions),E=a(i.skills),z=a(i.prompts),U=a(i.themes),G=(this.noExtensions?u:this.mergePaths(u,l)).filter(r=>!r.startsWith(k)||!this.disabledBuiltinExtensions.has(r.slice(k.length))),rt=st(G,e,{agentDir:this.agentDir,cwd:this.cwd}),O=await this.loadFinalExtensionSet(G,n);B(O,rt);for(const r of this.additionalExtensionPaths)if(j(r)){const m=this.resolveResourcePath(r);f(m)||O.errors.push({path:m,error:`Extension path does not exist: ${m}`})}this.extensionsResult=this.extensionsOverride?this.extensionsOverride(O):O,this.applyExtensionSourceInfo(this.extensionsResult.extensions,e);const D=p(ft(),"skills"),_=!this.noSkills&&f(D)?[D]:[];_.length>0&&!e.has(D)&&e.set(D,{source:"auto",scope:"user",origin:"top-level",baseDir:D});const Y=this.noSkills?this.mergePaths(E,this.additionalSkillPaths):this.mergePaths([...E,...d,..._],this.additionalSkillPaths);this.lastSkillPaths=Y,this.updateSkillsFromPaths(Y,e);for(const r of this.additionalSkillPaths)if(j(r)){const m=this.resolveResourcePath(r);!f(m)&&!this.skillDiagnostics.some(F=>F.path===m)&&this.skillDiagnostics.push({type:"error",message:"Skill path does not exist",path:m})}const H=this.noPromptTemplates?this.mergePaths(z,this.additionalPromptTemplatePaths):this.mergePaths([...z,...g],this.additionalPromptTemplatePaths);this.lastPromptPaths=H,this.updatePromptsFromPaths(H,e);for(const r of this.additionalPromptTemplatePaths)if(j(r)){const m=this.resolveResourcePath(r);!f(m)&&!this.promptDiagnostics.some(F=>F.path===m)&&this.promptDiagnostics.push({type:"error",message:"Prompt template path does not exist",path:m})}const J=this.noThemes?this.mergePaths(U,this.additionalThemePaths):this.mergePaths([...U,...x],this.additionalThemePaths);this.lastThemePaths=J,this.updateThemesFromPaths(J,e);for(const r of this.additionalThemePaths){const m=this.resolveResourcePath(r);!f(m)&&!this.themeDiagnostics.some(F=>F.path===m)&&this.themeDiagnostics.push({type:"error",message:"Theme path does not exist",path:m})}const K={agentsFiles:this.noContextFiles?[]:Bt({cwd:this.cwd,agentDir:this.agentDir})},ht=this.agentsFilesOverride?this.agentsFilesOverride(K):K;this.agentsFiles=ht.agentsFiles;const R=this.systemPromptSource??this.discoverSystemPromptFile(),X=at(R,S("\u7CFB\u7EDF\u63D0\u793A\u8BCD"));this.systemPrompt=this.systemPromptOverride?this.systemPromptOverride(X):X,this.systemPromptSourcePath=R&&f(R)?w(R):void 0;let C=this.appendSystemPromptSource;if(!C){const r=this.discoverAppendSystemPromptFile();C=r?[r]:[]}const q=C.map(r=>at(r,S("\u8FFD\u52A0\u7684\u7CFB\u7EDF\u63D0\u793A\u8BCD"))).filter(r=>r!==void 0);this.appendSystemPrompt=this.appendSystemPromptOverride?this.appendSystemPromptOverride(q):q,this.appendSystemPromptSourcePaths=C.filter(r=>f(r)).map(r=>w(r)),this.loaded=!0}async loadCurrentExtensionSet(t){const n=await this.packageManager.resolve(),s=await this.packageManager.resolveExtensionSources(this.additionalExtensionPaths,{temporary:!0}),i=n.extensions.filter(d=>d.enabled).map(d=>d.path),e=s.extensions.filter(d=>d.enabled).map(d=>d.path),o=(this.noExtensions?e:this.mergePaths(e,i)).filter(d=>!d.startsWith(k)),a=new Map([...n.extensions,...s.extensions].map(d=>[d.path,d.metadata])),l=st(o,a,{agentDir:this.agentDir,cwd:this.cwd}),h=await et(o,this.cwd,this.eventBus);if(B(h,l),!t.includeInlineFactories)return h;const g=await this.loadExtensionFactories(h.runtime);h.extensions.push(...g.extensions),h.errors.push(...g.errors);const x=[];return h.extensions=ot(h.extensions,x),B(h,x),h}resolveExtensionLoadPath(t){return N(t)?t:w(t,this.cwd,{normalizeUnicodeSpaces:!0})}async loadExtensionPaths(t,n){const s=P(e=>e.startsWith(k),"isBuiltinPath"),i=await et(t.filter(e=>!s(e)),this.cwd,this.eventBus,n);for(const e of t.filter(s)){const o=this.builtinExtensions.get(e.slice(k.length));if(!o){i.errors.push({path:e,error:`Unknown built-in extension: ${e}`});continue}try{const a=await tt(o.factory,this.cwd,this.eventBus,i.runtime,e);a.hidden=!0,a.replaceable=o.replaceable===!0,i.extensions.push(a)}catch(a){i.errors.push({path:e,error:a instanceof Error?a.message:"failed to load extension"})}}return i}async loadFinalExtensionSet(t,n){const s=n?.extensions??[],i=new Map(s.filter(u=>!u.path.startsWith("<inline:")).map(u=>[u.resolvedPath,u])),e=new Set((n?.errors??[]).map(u=>this.resolveExtensionLoadPath(u.path))),o=t.filter(u=>{const E=this.resolveExtensionLoadPath(u);return!i.has(E)&&!e.has(E)}),a=await this.loadExtensionPaths(o,n?.runtime),l=new Map(i);for(const u of a.extensions)l.set(u.resolvedPath,u);const h=n?{extensions:s.filter(u=>u.path.startsWith("<inline:")),errors:[]}:await this.loadExtensionFactories(a.runtime),g=t.map(u=>l.get(this.resolveExtensionLoadPath(u))).filter(u=>u!==void 0);g.push(...h.extensions);const x=[],d={extensions:ot(g,x),errors:[...n?.errors??[],...a.errors,...h.errors],warnings:[...n?.warnings??[],...a.warnings??[]],runtime:a.runtime};return B(d,x),this.addExtensionConflictDiagnostics(d),d}addExtensionConflictDiagnostics(t){const n=this.detectExtensionConflicts(t.extensions);for(const s of n)t.errors.push({path:s.path,error:s.message})}mapSkillPath(t,n){if(t.metadata.source!=="auto"&&t.metadata.origin!=="package")return t.path;try{if(!T(t.path).isDirectory())return t.path}catch{return t.path}const s=p(t.path,"SKILL.md");return f(s)?(n.has(s)||n.set(s,t.metadata),s):t.path}normalizeExtensionPaths(t){return t.map(n=>{const s=n.metadata.baseDir?{...n.metadata,baseDir:this.resolveResourcePath(n.metadata.baseDir)}:n.metadata;return{path:this.resolveResourcePath(n.path),metadata:s}})}updateSkillsFromPaths(t,n){let s;this.noSkills&&t.length===0?s={skills:[],diagnostics:[]}:s=It({cwd:this.cwd,agentDir:this.agentDir,skillPaths:t,includeDefaults:!1});const i=this.skillsOverride?this.skillsOverride(s):s;this.skills=i.skills.map(e=>({...e,sourceInfo:this.findSourceInfoForPath(e.filePath,this.extensionSkillSourceInfos,n)??e.sourceInfo??this.getDefaultSourceInfoForPath(e.filePath)})),this.skillDiagnostics=i.diagnostics}updatePromptsFromPaths(t,n){let s;if(this.noPromptTemplates&&t.length===0)s={prompts:[],diagnostics:[]};else{const e=bt({cwd:this.cwd,agentDir:this.agentDir,promptPaths:t,includeDefaults:!1}),o=this.dedupePrompts(e.templates);s={prompts:o.prompts,diagnostics:[...e.diagnostics,...o.diagnostics]}}const i=this.promptsOverride?this.promptsOverride(s):s;this.prompts=i.prompts.map(e=>({...e,sourceInfo:this.findSourceInfoForPath(e.filePath,this.extensionPromptSourceInfos,n)??e.sourceInfo??this.getDefaultSourceInfoForPath(e.filePath)})),this.promptDiagnostics=i.diagnostics}updateThemesFromPaths(t,n){let s;if(this.noThemes&&t.length===0)s={themes:[],diagnostics:[]};else{const e=dt({...pt(()=>!1),...this.settingsManager.getTerminalCapabilityOverrides()}),o=this.loadThemes(t,!1,e),a=this.dedupeThemes(o.themes);s={themes:a.themes,diagnostics:[...o.diagnostics,...a.diagnostics]}}const i=this.themesOverride?this.themesOverride(s):s;this.themes=i.themes.map(e=>{const o=e.sourcePath;return e.sourceInfo=o?this.findSourceInfoForPath(o,this.extensionThemeSourceInfos,n)??e.sourceInfo??this.getDefaultSourceInfoForPath(o):e.sourceInfo,e}),this.themeDiagnostics=i.diagnostics}applyExtensionSourceInfo(t,n){for(const s of t){s.sourceInfo=this.findSourceInfoForPath(s.path,void 0,n)??this.getDefaultSourceInfoForPath(s.path);for(const i of s.commands.values())i.sourceInfo=s.sourceInfo;for(const i of s.tools.values())i.sourceInfo=s.sourceInfo}}findSourceInfoForPath(t,n,s){if(!t)return;if(N(t))return this.getDefaultSourceInfoForPath(t);const i=y(t);if(n)for(const[e,o]of n.entries()){const a=y(e);if(i===a||i.startsWith(`${a}${b}`))return{...o,path:t}}if(s){const e=s.get(i)??s.get(t);if(e)return I(t,e);for(const[o,a]of s.entries()){const l=y(o);if(i===l||i.startsWith(`${l}${b}`))return I(t,a)}}}getDefaultSourceInfoForPath(t){const n=Ot(t);if(n)return{path:t,source:n,scope:"temporary",origin:"top-level"};const s=y(t),i=[p(this.agentDir,"skills"),p(this.agentDir,"prompts"),p(this.agentDir,"themes"),p(this.agentDir,"extensions")],e=[p(this.cwd,v,"skills"),p(this.cwd,v,"prompts"),p(this.cwd,v,"themes"),p(this.cwd,v,"extensions")];for(const o of i)if(this.isUnderPath(s,o))return{path:t,source:"local",scope:"user",origin:"top-level",baseDir:o};for(const o of e)if(this.isUnderPath(s,o))return{path:t,source:"local",scope:"project",origin:"top-level",baseDir:o};return{path:t,source:"local",scope:"temporary",origin:"top-level",baseDir:T(s).isDirectory()?s:y(s,"..")}}mergePaths(t,n){const s=[],i=new Set;for(const e of[...t,...n]){const o=this.resolveResourcePath(e),a=M(o);i.has(a)||(i.add(a),s.push(o))}return s}resolveResourcePath(t){return N(t)?t:w(t,this.cwd,{trim:!0})}loadThemes(t,n,s){const i=[],e=[];if(n){const o=[p(this.agentDir,"themes"),p(this.cwd,v,"themes")];for(const a of o)this.loadThemesFromDir(a,i,e,s)}for(const o of t){const a=this.resolveResourcePath(o);if(!f(a)){e.push({type:"warning",message:"theme path does not exist",path:a});continue}try{const l=T(a);l.isDirectory()?this.loadThemesFromDir(a,i,e,s):l.isFile()&&a.endsWith(".json")?this.loadThemeFromFile(a,i,e,s):e.push({type:"warning",message:"theme path is not a json file",path:a})}catch(l){const h=l instanceof Error?l.message:"failed to read theme path";e.push({type:"warning",message:h,path:a})}}return{themes:i,diagnostics:e}}loadThemesFromDir(t,n,s,i){if(f(t))try{const e=ct(t,{withFileTypes:!0});for(const o of e){let a=o.isFile();if(o.isSymbolicLink())try{a=T(p(t,o.name)).isFile()}catch{continue}a&&o.name.endsWith(".json")&&this.loadThemeFromFile(p(t,o.name),n,s,i)}}catch(e){const o=e instanceof Error?e.message:"failed to read theme directory";s.push({type:"warning",message:o,path:t})}}loadThemeFromFile(t,n,s,i){try{n.push(vt(t,i))}catch(e){const o=e instanceof Error?e.message:"failed to load theme";s.push({type:"warning",message:o,path:t})}}async loadExtensionFactories(t){const n=[],s=[];for(const[i,e]of this.extensionFactories.entries()){const o=typeof e!="function",a=o?e.factory:e,l=`<inline:${o?e.name:i+1}>`;try{const h=await tt(a,this.cwd,this.eventBus,t,l);h.hidden=o&&e.hidden,h.replaceable=o&&e.replaceable===!0,n.push(h)}catch(h){const g=h instanceof Error?h.message:"failed to load extension";s.push({path:l,error:g})}}return{extensions:n,errors:s}}dedupePrompts(t){const n=new Map,s=[];for(const i of t){const e=n.get(i.name);e?s.push({type:"collision",message:`name "/${i.name}" collision`,path:i.filePath,collision:{resourceType:"prompt",name:i.name,winnerPath:e.filePath,loserPath:i.filePath}}):n.set(i.name,i)}return{prompts:Array.from(n.values()),diagnostics:s}}dedupeThemes(t){const n=new Map,s=[];for(const i of t){const e=i.name??"unnamed",o=n.get(e);o?s.push({type:"collision",message:`name "${e}" collision`,path:i.sourcePath,collision:{resourceType:"theme",name:e,winnerPath:o.sourcePath??"<builtin>",loserPath:i.sourcePath??"<builtin>"}}):n.set(e,i)}return{themes:Array.from(n.values()),diagnostics:s}}discoverSystemPromptFile(){const t=p(this.cwd,v,"SYSTEM.md");if(this.settingsManager.isProjectTrusted()&&f(t))return t;const n=p(this.agentDir,"SYSTEM.md");if(f(n))return n}discoverAppendSystemPromptFile(){const t=p(this.cwd,v,"APPEND_SYSTEM.md");if(this.settingsManager.isProjectTrusted()&&f(t))return t;const n=p(this.agentDir,"APPEND_SYSTEM.md");if(f(n))return n}isUnderPath(t,n){const s=y(n);if(t===s)return!0;const i=s.endsWith(b)?s:`${s}${b}`;return t.startsWith(i)}detectExtensionConflicts(t){const n=[],s=new Map,i=new Map;for(const e of t){for(const o of e.tools.keys()){const a=s.get(o);a&&a!==e.path?n.push({path:e.path,message:`Tool "${o}" conflicts with ${a}`}):s.set(o,e.path)}for(const o of e.flags.keys()){const a=i.get(o);a&&a!==e.path?n.push({path:e.path,message:`Flag "--${o}" conflicts with ${a}`}):i.set(o,e.path)}}return n}}export{ie as DefaultResourceLoader,it as isBuiltinExtension,Bt as loadProjectContextFiles};
1
+ var ct=Object.defineProperty;var P=(c,t)=>ct(c,"name",{value:t,configurable:!0});import{existsSync as f,readdirSync as mt,readFileSync as $,statSync as T}from"node:fs";import{basename as Q,dirname as V,join as m,resolve as y,sep as b}from"node:path";import{detectCapabilities as pt,getTerminalColorMode as dt}from"@earendil-works/pi-tui";import Z from"chalk";import{APP_NAME as ut,CONFIG_DIR_NAME as v,getExamplesPath as ft,getPackageDir as Pt,getProjectPromptsDir as gt}from"../config.js";import{dalBuiltinExtensionPaths as xt}from"../dal/builtins.js";import{applyCommunityEnv as St,hostDependenciesOf as tt,installedHostCopies as yt,isAdaptablePackage as wt,tryEnsurePackageAdapted as vt}from"../dal/extension-compat.js";import{fill as A,t as S}from"../dal/i18n.js";import{loadThemeFromPath as kt}from"../modes/interactive/theme/theme.js";import{canonicalizePath as M,isLocalPath as j,resolvePath as w}from"../utils/paths.js";import{stripBom as W}from"../utils/text.js";import{createEventBus as Et}from"./event-bus.js";import{clearExtensionCache as Dt,createExtensionRuntime as Ft,loadExtensionFromFactory as et,loadExtensionsCached as st}from"./extensions/loader.js";import{findGitPaths as Tt}from"./footer-data-provider.js";import{DefaultPackageManager as bt}from"./package-manager.js";import{loadPromptTemplates as Mt}from"./prompt-templates.js";import{SettingsManager as It}from"./settings-manager.js";import{loadSkills as Ot}from"./skills.js";import{BUILTIN_PATH_PREFIX as k,createSourceInfo as I,getSyntheticPathSource as Rt,isSyntheticPath as N}from"./source-info.js";import{resetTimings as Ct}from"./timings.js";function it(c,t,n){let s;try{s=Pt()}catch{s=void 0}St({agentDir:n.agentDir,packageDir:s});const i=[],e=new Map;for(const o of c){const a=t.get(o);a?.packageRoot&&!e.has(a.packageRoot)&&e.set(a.packageRoot,a)}for(const[o,a]of e){const l=m(o,"package.json");if(!f(l))continue;JSON.parse(W($(l,"utf-8"))),wt(o,a.source,n)&&vt(o);const h=yt(o,tt(o));if(h.length===0)continue;const g=tt(o).filter(x=>h.some(d=>d.endsWith(m(...x.split("/")))));i.push({path:l,warning:A(S('\u6269\u5C55\u5305\u5728 dependencies \u91CC\u81EA\u5E26\u4E86 DAL \u5DF2\u63D0\u4F9B\u7684\u5E93\uFF08{names}\uFF09\uFF0C\u8FD9\u4E9B\u526F\u672C\u4F1A\u548C DAL \u81EA\u5DF1\u7684\u91CD\u590D\u52A0\u8F7D\u3002\u8BF7\u628A\u5B83\u4EEC\u6539\u5230 peerDependencies\uFF0C\u7248\u672C\u5199 "*"\u3002'),{names:g.join(", ")})})}return i}P(it,"prepareExtensionPackages");function B(c,t){c.warnings=[...new Map([...c.warnings??[],...t].map(n=>[n.path,n])).values()]}P(B,"mergeExtensionWarnings");function nt(c){return typeof c!="function"&&c.builtin===!0}P(nt,"isBuiltinExtension");let ot;function At(c){return ot??=new Set(xt().map(t=>y(t))),ot.has(y(c))}P(At,"isDalBundledExtensionPath");function at(c,t){const n=P(i=>[...[...i.tools.keys()].map(e=>`tool:${e}`),...[...i.commands.keys()].map(e=>`command:${e}`),...[...i.flags.keys()].map(e=>`flag:${e}`)],"names"),s=new Map(c.filter(i=>!i.replaceable).flatMap(i=>n(i).map(e=>[e,i])));return c.filter(i=>{if(!i.replaceable)return!0;const e=n(i).map(o=>({name:o,extension:s.get(o)})).find(o=>o.extension!==void 0);if(!e)return!0;if(i.path.startsWith(k)&&!At(e.extension.path)){const o=i.path.slice(k.length),[a,l]=e.name.split(":",2),h=a==="command"?`/${l}`:a==="flag"?`--${l}`:l;t?.push({path:i.path,warning:A(S("\u6269\u5C55 {path} \u6CE8\u518C\u4E86{kind} `{name}`\uFF0C\u6240\u4EE5\u5185\u7F6E\u6269\u5C55 `{builtin}` \u6CA1\u6709\u52A0\u8F7D\u3002\u8981\u4F7F\u7528 `{builtin}`\uFF0C\u8FD0\u884C `{app} config`\uFF0C\u5728\u5185\u7F6E\u6269\u5C55\u91CC\u786E\u8BA4\u5B83\u5DF2\u542F\u7528\uFF0C\u7136\u540E\u505C\u7528\u6216\u79FB\u9664\u8FD9\u4E2A\u6269\u5C55\u3002\u4E24\u8005\u6700\u597D\u53EA\u4FDD\u7559\u4E00\u4E2A\u3002"),{path:e.extension.path,kind:a==="command"?S("\u4E00\u4E2A\u547D\u4EE4"):a==="flag"?S("\u4E00\u4E2A\u53C2\u6570"):S("\u4E00\u4E2A\u5DE5\u5177"),name:h,builtin:o,app:ut})})}return!1})}P(at,"omitReplacedExtensions");function rt(c,t){if(c){if(f(c))try{return W($(c,"utf-8"))}catch(n){return console.error(Z.yellow(A(S("\u8B66\u544A\uFF1A\u65E0\u6CD5\u8BFB\u53D6{what}\u6587\u4EF6 {path}\uFF1A{error}"),{what:t,path:c,error:String(n)}))),c}return c}}P(rt,"resolvePromptInput");function L(c){const t=["AGENTS.override.md","AGENTS.md","AGENTS.MD","CLAUDE.md","CLAUDE.MD"];for(const n of t){const s=m(c,n);if(f(s))try{if(!T(s).isFile())continue;return{path:s,content:W($(s,"utf-8"))}}catch(i){console.error(Z.yellow(A(S("\u8B66\u544A\uFF1A\u65E0\u6CD5\u8BFB\u53D6 {path}\uFF1A{error}"),{path:s,error:String(i)})))}}return null}P(L,"loadContextFileFromDir");function Bt(c){const t=Tt(c);if(!t)return;const n=M(t.commonGitDir),s=M(t.repoDir),i=V(n);if(!s.startsWith(`${i}${b}`)||M(m(i,".git"))!==n)return;const e=L(s);return e?m(i,Q(e.path)):void 0}P(Bt,"findShadowedContextFile");function $t(c){const t=w(c.cwd),n=w(c.agentDir),s=[],i=new Set,e=L(n);e&&(s.push(e),i.add(e.path));const o=[],a=Bt(t);let l=t;for(;;){const h=L(l),g=a!==void 0&&h!==null&&m(M(l),Q(h.path))===a;h&&!g&&!i.has(h.path)&&(o.unshift(h),i.add(h.path));const x=V(l);if(x===l)break;l=x}return s.push(...o),s}P($t,"loadProjectContextFiles");class ne{static{P(this,"DefaultResourceLoader")}cwd;agentDir;settingsManager;eventBus;packageManager;additionalExtensionPaths;additionalSkillPaths;additionalPromptTemplatePaths;additionalThemePaths;extensionFactories;builtinExtensions;noExtensions;disabledBuiltinExtensions;noSkills;noPromptTemplates;noThemes;noContextFiles;systemPromptSource;appendSystemPromptSource;extensionsOverride;skillsOverride;promptsOverride;themesOverride;agentsFilesOverride;systemPromptOverride;appendSystemPromptOverride;extensionsResult;skills;skillDiagnostics;prompts;promptDiagnostics;themes;themeDiagnostics;agentsFiles;systemPrompt;systemPromptSourcePath;appendSystemPrompt;appendSystemPromptSourcePaths;lastSkillPaths;extensionSkillSourceInfos;extensionPromptSourceInfos;extensionThemeSourceInfos;resourceMetadataByPath;lastPromptPaths;lastThemePaths;loaded;constructor(t){this.cwd=w(t.cwd),this.agentDir=w(t.agentDir),this.settingsManager=t.settingsManager??It.create(this.cwd,this.agentDir),this.eventBus=t.eventBus??Et();const n=t.extensionFactories??[];this.extensionFactories=n.filter(s=>!nt(s)),this.builtinExtensions=new Map(n.filter(nt).map(s=>[s.name,s])),this.packageManager=new bt({cwd:this.cwd,agentDir:this.agentDir,settingsManager:this.settingsManager,builtinExtensions:[...this.builtinExtensions.keys()]}),this.additionalExtensionPaths=t.additionalExtensionPaths??[],this.additionalSkillPaths=t.additionalSkillPaths??[],this.additionalPromptTemplatePaths=t.additionalPromptTemplatePaths??[],this.additionalThemePaths=t.additionalThemePaths??[],this.noExtensions=t.noExtensions??!1,this.disabledBuiltinExtensions=new Set(t.disabledBuiltinExtensions),this.noSkills=t.noSkills??!1,this.noPromptTemplates=t.noPromptTemplates??!1,this.noThemes=t.noThemes??!1,this.noContextFiles=t.noContextFiles??!1,this.systemPromptSource=t.systemPrompt,this.appendSystemPromptSource=t.appendSystemPrompt,this.extensionsOverride=t.extensionsOverride,this.skillsOverride=t.skillsOverride,this.promptsOverride=t.promptsOverride,this.themesOverride=t.themesOverride,this.agentsFilesOverride=t.agentsFilesOverride,this.systemPromptOverride=t.systemPromptOverride,this.appendSystemPromptOverride=t.appendSystemPromptOverride,this.extensionsResult={extensions:[],errors:[],runtime:Ft()},this.skills=[],this.skillDiagnostics=[],this.prompts=[],this.promptDiagnostics=[],this.themes=[],this.themeDiagnostics=[],this.agentsFiles=[],this.appendSystemPrompt=[],this.appendSystemPromptSourcePaths=[],this.lastSkillPaths=[],this.extensionSkillSourceInfos=new Map,this.extensionPromptSourceInfos=new Map,this.extensionThemeSourceInfos=new Map,this.resourceMetadataByPath=new Map,this.lastPromptPaths=[],this.lastThemePaths=[],this.loaded=!1}getExtensions(){return this.extensionsResult}getSkills(){return{skills:this.skills,diagnostics:this.skillDiagnostics}}getPrompts(){return{prompts:this.prompts,diagnostics:this.promptDiagnostics}}getThemes(){return{themes:this.themes,diagnostics:this.themeDiagnostics}}getAgentsFiles(){return{agentsFiles:this.agentsFiles}}getSystemPrompt(){return this.systemPrompt}getSystemPromptSource(){return this.systemPromptSourcePath?{path:this.systemPromptSourcePath}:void 0}getAppendSystemPrompt(){return this.appendSystemPrompt}getAppendSystemPromptSources(){return this.appendSystemPromptSourcePaths.map(t=>({path:t}))}extendResources(t){const n=this.normalizeExtensionPaths(t.skillPaths??[]),s=this.normalizeExtensionPaths(t.promptPaths??[]),i=this.normalizeExtensionPaths(t.themePaths??[]);for(const e of n)this.extensionSkillSourceInfos.set(e.path,I(e.path,e.metadata));for(const e of s)this.extensionPromptSourceInfos.set(e.path,I(e.path,e.metadata));for(const e of i)this.extensionThemeSourceInfos.set(e.path,I(e.path,e.metadata));n.length>0&&(this.lastSkillPaths=this.mergePaths(this.lastSkillPaths,n.map(e=>e.path)),this.updateSkillsFromPaths(this.lastSkillPaths,this.resourceMetadataByPath)),s.length>0&&(this.lastPromptPaths=this.mergePaths(this.lastPromptPaths,s.map(e=>e.path)),this.updatePromptsFromPaths(this.lastPromptPaths,this.resourceMetadataByPath)),i.length>0&&(this.lastThemePaths=this.mergePaths(this.lastThemePaths,i.map(e=>e.path)),this.updateThemesFromPaths(this.lastThemePaths,this.resourceMetadataByPath))}async loadProjectTrustExtensions(){return this.settingsManager.setProjectTrusted(!1),await this.settingsManager.reload(),this.loadCurrentExtensionSet({includeInlineFactories:!0})}async reload(t){Ct("extensions"),this.loaded&&Dt();let n;if(t?.resolveProjectTrust){n=await this.loadProjectTrustExtensions();const r=await t.resolveProjectTrust({extensionsResult:n});this.settingsManager.setProjectTrusted(r)}await this.settingsManager.reload();const s=await this.packageManager.resolve(),i=await this.packageManager.resolveExtensionSources(this.additionalExtensionPaths,{temporary:!0});this.resourceMetadataByPath=new Map;const e=this.resourceMetadataByPath;this.extensionSkillSourceInfos=new Map,this.extensionPromptSourceInfos=new Map,this.extensionThemeSourceInfos=new Map;const o=P(r=>{for(const p of r)e.has(p.path)||e.set(p.path,p.metadata);return r.filter(p=>p.enabled)},"getEnabledResources"),a=P(r=>o(r).map(p=>p.path),"getEnabledPaths"),l=a(s.extensions),h=o(s.skills),g=a(s.prompts),x=a(s.themes),d=h.map(r=>this.mapSkillPath(r,e));for(const r of i.extensions)e.has(r.path)||e.set(r.path,{source:"cli",scope:"temporary",origin:"top-level"});for(const r of i.skills)e.has(r.path)||e.set(r.path,{source:"cli",scope:"temporary",origin:"top-level"});const u=a(i.extensions),E=a(i.skills),z=a(i.prompts),U=a(i.themes),G=(this.noExtensions?u:this.mergePaths(u,l)).filter(r=>!r.startsWith(k)||!this.disabledBuiltinExtensions.has(r.slice(k.length))),ht=it(G,e,{agentDir:this.agentDir,cwd:this.cwd}),O=await this.loadFinalExtensionSet(G,n);B(O,ht);for(const r of this.additionalExtensionPaths)if(j(r)){const p=this.resolveResourcePath(r);f(p)||O.errors.push({path:p,error:`Extension path does not exist: ${p}`})}this.extensionsResult=this.extensionsOverride?this.extensionsOverride(O):O,this.applyExtensionSourceInfo(this.extensionsResult.extensions,e);const D=m(ft(),"skills"),_=!this.noSkills&&f(D)?[D]:[];_.length>0&&!e.has(D)&&e.set(D,{source:"auto",scope:"user",origin:"top-level",baseDir:D});const Y=this.noSkills?this.mergePaths(E,this.additionalSkillPaths):this.mergePaths([...E,...d,..._],this.additionalSkillPaths);this.lastSkillPaths=Y,this.updateSkillsFromPaths(Y,e);for(const r of this.additionalSkillPaths)if(j(r)){const p=this.resolveResourcePath(r);!f(p)&&!this.skillDiagnostics.some(F=>F.path===p)&&this.skillDiagnostics.push({type:"error",message:"Skill path does not exist",path:p})}const H=this.noPromptTemplates?this.mergePaths(z,this.additionalPromptTemplatePaths):this.mergePaths([...z,...g],this.additionalPromptTemplatePaths);this.lastPromptPaths=H,this.updatePromptsFromPaths(H,e);for(const r of this.additionalPromptTemplatePaths)if(j(r)){const p=this.resolveResourcePath(r);!f(p)&&!this.promptDiagnostics.some(F=>F.path===p)&&this.promptDiagnostics.push({type:"error",message:"Prompt template path does not exist",path:p})}const J=this.noThemes?this.mergePaths(U,this.additionalThemePaths):this.mergePaths([...U,...x],this.additionalThemePaths);this.lastThemePaths=J,this.updateThemesFromPaths(J,e);for(const r of this.additionalThemePaths){const p=this.resolveResourcePath(r);!f(p)&&!this.themeDiagnostics.some(F=>F.path===p)&&this.themeDiagnostics.push({type:"error",message:"Theme path does not exist",path:p})}const K={agentsFiles:this.noContextFiles?[]:$t({cwd:this.cwd,agentDir:this.agentDir})},lt=this.agentsFilesOverride?this.agentsFilesOverride(K):K;this.agentsFiles=lt.agentsFiles;const R=this.systemPromptSource??this.discoverSystemPromptFile(),X=rt(R,S("\u7CFB\u7EDF\u63D0\u793A\u8BCD"));this.systemPrompt=this.systemPromptOverride?this.systemPromptOverride(X):X,this.systemPromptSourcePath=R&&f(R)?w(R):void 0;let C=this.appendSystemPromptSource;if(!C){const r=this.discoverAppendSystemPromptFile();C=r?[r]:[]}const q=C.map(r=>rt(r,S("\u8FFD\u52A0\u7684\u7CFB\u7EDF\u63D0\u793A\u8BCD"))).filter(r=>r!==void 0);this.appendSystemPrompt=this.appendSystemPromptOverride?this.appendSystemPromptOverride(q):q,this.appendSystemPromptSourcePaths=C.filter(r=>f(r)).map(r=>w(r)),this.loaded=!0}async loadCurrentExtensionSet(t){const n=await this.packageManager.resolve(),s=await this.packageManager.resolveExtensionSources(this.additionalExtensionPaths,{temporary:!0}),i=n.extensions.filter(d=>d.enabled).map(d=>d.path),e=s.extensions.filter(d=>d.enabled).map(d=>d.path),o=(this.noExtensions?e:this.mergePaths(e,i)).filter(d=>!d.startsWith(k)),a=new Map([...n.extensions,...s.extensions].map(d=>[d.path,d.metadata])),l=it(o,a,{agentDir:this.agentDir,cwd:this.cwd}),h=await st(o,this.cwd,this.eventBus);if(B(h,l),!t.includeInlineFactories)return h;const g=await this.loadExtensionFactories(h.runtime);h.extensions.push(...g.extensions),h.errors.push(...g.errors);const x=[];return h.extensions=at(h.extensions,x),B(h,x),h}resolveExtensionLoadPath(t){return N(t)?t:w(t,this.cwd,{normalizeUnicodeSpaces:!0})}async loadExtensionPaths(t,n){const s=P(e=>e.startsWith(k),"isBuiltinPath"),i=await st(t.filter(e=>!s(e)),this.cwd,this.eventBus,n);for(const e of t.filter(s)){const o=this.builtinExtensions.get(e.slice(k.length));if(!o){i.errors.push({path:e,error:`Unknown built-in extension: ${e}`});continue}try{const a=await et(o.factory,this.cwd,this.eventBus,i.runtime,e);a.hidden=!0,a.replaceable=o.replaceable===!0,i.extensions.push(a)}catch(a){i.errors.push({path:e,error:a instanceof Error?a.message:"failed to load extension"})}}return i}async loadFinalExtensionSet(t,n){const s=n?.extensions??[],i=new Map(s.filter(u=>!u.path.startsWith("<inline:")).map(u=>[u.resolvedPath,u])),e=new Set((n?.errors??[]).map(u=>this.resolveExtensionLoadPath(u.path))),o=t.filter(u=>{const E=this.resolveExtensionLoadPath(u);return!i.has(E)&&!e.has(E)}),a=await this.loadExtensionPaths(o,n?.runtime),l=new Map(i);for(const u of a.extensions)l.set(u.resolvedPath,u);const h=n?{extensions:s.filter(u=>u.path.startsWith("<inline:")),errors:[]}:await this.loadExtensionFactories(a.runtime),g=t.map(u=>l.get(this.resolveExtensionLoadPath(u))).filter(u=>u!==void 0);g.push(...h.extensions);const x=[],d={extensions:at(g,x),errors:[...n?.errors??[],...a.errors,...h.errors],warnings:[...n?.warnings??[],...a.warnings??[]],runtime:a.runtime};return B(d,x),this.addExtensionConflictDiagnostics(d),d}addExtensionConflictDiagnostics(t){const n=this.detectExtensionConflicts(t.extensions);for(const s of n)t.errors.push({path:s.path,error:s.message})}mapSkillPath(t,n){if(t.metadata.source!=="auto"&&t.metadata.origin!=="package")return t.path;try{if(!T(t.path).isDirectory())return t.path}catch{return t.path}const s=m(t.path,"SKILL.md");return f(s)?(n.has(s)||n.set(s,t.metadata),s):t.path}normalizeExtensionPaths(t){return t.map(n=>{const s=n.metadata.baseDir?{...n.metadata,baseDir:this.resolveResourcePath(n.metadata.baseDir)}:n.metadata;return{path:this.resolveResourcePath(n.path),metadata:s}})}updateSkillsFromPaths(t,n){let s;this.noSkills&&t.length===0?s={skills:[],diagnostics:[]}:s=Ot({cwd:this.cwd,agentDir:this.agentDir,skillPaths:t,includeDefaults:!1});const i=this.skillsOverride?this.skillsOverride(s):s;this.skills=i.skills.map(e=>({...e,sourceInfo:this.findSourceInfoForPath(e.filePath,this.extensionSkillSourceInfos,n)??e.sourceInfo??this.getDefaultSourceInfoForPath(e.filePath)})),this.skillDiagnostics=i.diagnostics}updatePromptsFromPaths(t,n){let s;if(this.noPromptTemplates&&t.length===0)s={prompts:[],diagnostics:[]};else{const e=Mt({cwd:this.cwd,agentDir:this.agentDir,promptPaths:t,includeDefaults:!1}),o=this.dedupePrompts(e.templates);s={prompts:o.prompts,diagnostics:[...e.diagnostics,...o.diagnostics]}}const i=this.promptsOverride?this.promptsOverride(s):s;this.prompts=i.prompts.map(e=>({...e,sourceInfo:this.findSourceInfoForPath(e.filePath,this.extensionPromptSourceInfos,n)??e.sourceInfo??this.getDefaultSourceInfoForPath(e.filePath)})),this.promptDiagnostics=i.diagnostics}updateThemesFromPaths(t,n){let s;if(this.noThemes&&t.length===0)s={themes:[],diagnostics:[]};else{const e=dt({...pt(()=>!1),...this.settingsManager.getTerminalCapabilityOverrides()}),o=this.loadThemes(t,!1,e),a=this.dedupeThemes(o.themes);s={themes:a.themes,diagnostics:[...o.diagnostics,...a.diagnostics]}}const i=this.themesOverride?this.themesOverride(s):s;this.themes=i.themes.map(e=>{const o=e.sourcePath;return e.sourceInfo=o?this.findSourceInfoForPath(o,this.extensionThemeSourceInfos,n)??e.sourceInfo??this.getDefaultSourceInfoForPath(o):e.sourceInfo,e}),this.themeDiagnostics=i.diagnostics}applyExtensionSourceInfo(t,n){for(const s of t){s.sourceInfo=this.findSourceInfoForPath(s.path,void 0,n)??this.getDefaultSourceInfoForPath(s.path);for(const i of s.commands.values())i.sourceInfo=s.sourceInfo;for(const i of s.tools.values())i.sourceInfo=s.sourceInfo}}findSourceInfoForPath(t,n,s){if(!t)return;if(N(t))return this.getDefaultSourceInfoForPath(t);const i=y(t);if(n)for(const[e,o]of n.entries()){const a=y(e);if(i===a||i.startsWith(`${a}${b}`))return{...o,path:t}}if(s){const e=s.get(i)??s.get(t);if(e)return I(t,e);for(const[o,a]of s.entries()){const l=y(o);if(i===l||i.startsWith(`${l}${b}`))return I(t,a)}}}getDefaultSourceInfoForPath(t){const n=Rt(t);if(n)return{path:t,source:n,scope:"temporary",origin:"top-level"};const s=y(t),i=[m(this.agentDir,"skills"),m(this.agentDir,"prompts"),m(this.agentDir,"themes"),m(this.agentDir,"extensions")],e=[m(this.cwd,v,"skills"),gt(m(this.cwd,v)),m(this.cwd,v,"themes"),m(this.cwd,v,"extensions")];for(const o of i)if(this.isUnderPath(s,o))return{path:t,source:"local",scope:"user",origin:"top-level",baseDir:o};for(const o of e)if(this.isUnderPath(s,o))return{path:t,source:"local",scope:"project",origin:"top-level",baseDir:o};return{path:t,source:"local",scope:"temporary",origin:"top-level",baseDir:T(s).isDirectory()?s:y(s,"..")}}mergePaths(t,n){const s=[],i=new Set;for(const e of[...t,...n]){const o=this.resolveResourcePath(e),a=M(o);i.has(a)||(i.add(a),s.push(o))}return s}resolveResourcePath(t){return N(t)?t:w(t,this.cwd,{trim:!0})}loadThemes(t,n,s){const i=[],e=[];if(n){const o=[m(this.agentDir,"themes"),m(this.cwd,v,"themes")];for(const a of o)this.loadThemesFromDir(a,i,e,s)}for(const o of t){const a=this.resolveResourcePath(o);if(!f(a)){e.push({type:"warning",message:"theme path does not exist",path:a});continue}try{const l=T(a);l.isDirectory()?this.loadThemesFromDir(a,i,e,s):l.isFile()&&a.endsWith(".json")?this.loadThemeFromFile(a,i,e,s):e.push({type:"warning",message:"theme path is not a json file",path:a})}catch(l){const h=l instanceof Error?l.message:"failed to read theme path";e.push({type:"warning",message:h,path:a})}}return{themes:i,diagnostics:e}}loadThemesFromDir(t,n,s,i){if(f(t))try{const e=mt(t,{withFileTypes:!0});for(const o of e){let a=o.isFile();if(o.isSymbolicLink())try{a=T(m(t,o.name)).isFile()}catch{continue}a&&o.name.endsWith(".json")&&this.loadThemeFromFile(m(t,o.name),n,s,i)}}catch(e){const o=e instanceof Error?e.message:"failed to read theme directory";s.push({type:"warning",message:o,path:t})}}loadThemeFromFile(t,n,s,i){try{n.push(kt(t,i))}catch(e){const o=e instanceof Error?e.message:"failed to load theme";s.push({type:"warning",message:o,path:t})}}async loadExtensionFactories(t){const n=[],s=[];for(const[i,e]of this.extensionFactories.entries()){const o=typeof e!="function",a=o?e.factory:e,l=`<inline:${o?e.name:i+1}>`;try{const h=await et(a,this.cwd,this.eventBus,t,l);h.hidden=o&&e.hidden,h.replaceable=o&&e.replaceable===!0,n.push(h)}catch(h){const g=h instanceof Error?h.message:"failed to load extension";s.push({path:l,error:g})}}return{extensions:n,errors:s}}dedupePrompts(t){const n=new Map,s=[];for(const i of t){const e=n.get(i.name);e?s.push({type:"collision",message:`name "/${i.name}" collision`,path:i.filePath,collision:{resourceType:"prompt",name:i.name,winnerPath:e.filePath,loserPath:i.filePath}}):n.set(i.name,i)}return{prompts:Array.from(n.values()),diagnostics:s}}dedupeThemes(t){const n=new Map,s=[];for(const i of t){const e=i.name??"unnamed",o=n.get(e);o?s.push({type:"collision",message:`name "${e}" collision`,path:i.sourcePath,collision:{resourceType:"theme",name:e,winnerPath:o.sourcePath??"<builtin>",loserPath:i.sourcePath??"<builtin>"}}):n.set(e,i)}return{themes:Array.from(n.values()),diagnostics:s}}discoverSystemPromptFile(){const t=m(this.cwd,v,"SYSTEM.md");if(this.settingsManager.isProjectTrusted()&&f(t))return t;const n=m(this.agentDir,"SYSTEM.md");if(f(n))return n}discoverAppendSystemPromptFile(){const t=m(this.cwd,v,"APPEND_SYSTEM.md");if(this.settingsManager.isProjectTrusted()&&f(t))return t;const n=m(this.agentDir,"APPEND_SYSTEM.md");if(f(n))return n}isUnderPath(t,n){const s=y(n);if(t===s)return!0;const i=s.endsWith(b)?s:`${s}${b}`;return t.startsWith(i)}detectExtensionConflicts(t){const n=[],s=new Map,i=new Map;for(const e of t){for(const o of e.tools.keys()){const a=s.get(o);a&&a!==e.path?n.push({path:e.path,message:`Tool "${o}" conflicts with ${a}`}):s.set(o,e.path)}for(const o of e.flags.keys()){const a=i.get(o);a&&a!==e.path?n.push({path:e.path,message:`Flag "--${o}" conflicts with ${a}`}):i.set(o,e.path)}}return n}}export{ne as DefaultResourceLoader,nt as isBuiltinExtension,$t as loadProjectContextFiles};
@@ -1 +1 @@
1
- var M=Object.defineProperty;var a=(e,s)=>M(e,"name",{value:s,configurable:!0});import{lstatSync as O,statSync as P,unlinkSync as T}from"node:fs";import{createRequire as U}from"node:module";import{dirname as p}from"node:path";const m=U(import.meta.url)("shell-quote"),$={"--new-session":0,"--die-with-parent":0,"--unshare-net":0,"--unshare-pid":0,"--dev":1,"--proc":1,"--tmpfs":1,"--bind":2,"--ro-bind":2,"--setenv":2},w={"--bind":"rw","--ro-bind":"ro","--tmpfs":"rw","--dev":"rw","--proc":"rw"};function b(e){try{return P(e).isDirectory()?"dir":"file"}catch{return"missing"}}a(b,"pathKind");const A=a((e,s)=>e.startsWith(s==="/"?"/":`${s}/`),"within");function B(e,s=b){if(e[0]!=="bwrap")return;const c=[];let n=1;for(;n<e.length&&e[n]!=="--";){const t=e[n],r=$[t];if(r===void 0||n+r>=e.length)return;c.push({name:t,values:e.slice(n+1,n+1+r)}),n+=1+r}if(e[n]!=="--")return;const o=e.slice(n),i=a(t=>t.name==="--ro-bind"&&t.values[0]==="/dev/null","isPlaceholder"),y=c.filter(t=>w[t.name]&&!i(t)),x=a(t=>{let r;for(const f of y){const u=f.values[f.values.length-1];if(!A(t,u)&&t!==u)continue;const v=r?.values[r.values.length-1];(v===void 0||u.length>=v.length)&&(r=f)}return r},"decidingMount"),d=[],h=new Set,g=new Set;for(const t of c){if(!i(t)){d.push(t);continue}let r=t.values[1];for(let u=p(r);u!==p(u);u=p(u))s(u)==="file"&&(r=u);const f=x(p(r));f?.name==="--ro-bind"&&s(f.values[1])==="dir"||g.has(r)||(g.add(r),s(r)==="missing"&&h.add(r),d.push({name:t.name,values:["/dev/null",r]}))}const S=["bwrap",...d.flatMap(t=>[t.name,...t.values]),...o],q=d.filter(t=>w[t.name]).map(t=>t.values[t.values.length-1]);return{args:S,placeholders:[...h],targets:[...new Set(q)]}}a(B,"planBwrapArgs");function j(e,s=b){if(!e.startsWith("bwrap "))return;let c;try{c=m.parse(e,i=>`$${i}`)}catch{return}const n=c.map(i=>typeof i=="object"&&i!==null&&i.op==="glob"?i.pattern:i);if(!n.every(i=>typeof i=="string")||m.quote(n)!==e)return;const o=B(n,s);if(o)return{...o,command:m.quote(o.args)}}a(j,"planBwrapCommand");const l=new Map;function z(e){for(const s of e.targets)l.set(s,(l.get(s)??0)+1)}a(z,"acquirePlan");function C(e,s){for(const n of e.targets){const o=(l.get(n)??1)-1;o>0?l.set(n,o):l.delete(n)}const c=[];for(const n of e.placeholders)if(!l.has(n))try{const o=O(n);if(!o.isFile()||o.size!==0||(o.mode&146)!==0||process.getuid&&o.uid!==process.getuid()||o.mtimeMs<s-2e3)continue;T(n),c.push(n)}catch{}return c}a(C,"releasePlan");function D(e){return l.get(e)??0}a(D,"mountUsersOf");export{z as acquirePlan,D as mountUsersOf,b as pathKind,B as planBwrapArgs,j as planBwrapCommand,C as releasePlan};
1
+ var M=Object.defineProperty;var a=(e,s)=>M(e,"name",{value:s,configurable:!0});import{lstatSync as O,statSync as P,unlinkSync as T}from"node:fs";import{createRequire as U}from"node:module";import{dirname as p}from"node:path";const m=U(import.meta.url)("shell-quote"),$={"--new-session":0,"--die-with-parent":0,"--unshare-net":0,"--unshare-pid":0,"--dev":1,"--proc":1,"--tmpfs":1,"--bind":2,"--ro-bind":2,"--setenv":2},w={"--bind":"rw","--ro-bind":"ro","--tmpfs":"rw","--dev":"rw","--proc":"rw"};function b(e){try{return P(e).isDirectory()?"dir":"file"}catch{return"missing"}}a(b,"pathKind");const A=a((e,s)=>e.startsWith(s==="/"?"/":`${s}/`),"within");function B(e,s=b){if(e[0]!=="bwrap")return;const c=[];let n=1;for(;n<e.length&&e[n]!=="--";){const t=e[n],r=$[t];if(r===void 0||n+r>=e.length)return;c.push({name:t,values:e.slice(n+1,n+1+r)}),n+=1+r}if(e[n]!=="--")return;const o=e.slice(n),i=a(t=>t.name==="--ro-bind"&&t.values[0]==="/dev/null","isPlaceholder"),y=c.filter(t=>w[t.name]&&!i(t)),x=a(t=>{let r;for(const f of y){const u=f.values[f.values.length-1];if(!A(t,u)&&t!==u)continue;const v=r?.values[r.values.length-1];(v===void 0||u.length>=v.length)&&(r=f)}return r},"decidingMount"),d=[],h=new Set,g=new Set;for(const t of c){if(!i(t)){d.push(t);continue}let r=t.values[1];for(let u=p(r);u!==p(u);u=p(u))s(u)==="file"&&(r=u);const f=s(r)==="missing"?x(p(r)):void 0;f?.name==="--ro-bind"&&s(f.values[1])==="dir"||g.has(r)||(g.add(r),s(r)==="missing"&&h.add(r),d.push({name:t.name,values:["/dev/null",r]}))}const S=["bwrap",...d.flatMap(t=>[t.name,...t.values]),...o],q=d.filter(t=>w[t.name]).map(t=>t.values[t.values.length-1]);return{args:S,placeholders:[...h],targets:[...new Set(q)]}}a(B,"planBwrapArgs");function j(e,s=b){if(!e.startsWith("bwrap "))return;let c;try{c=m.parse(e,i=>`$${i}`)}catch{return}const n=c.map(i=>typeof i=="object"&&i!==null&&i.op==="glob"?i.pattern:i);if(!n.every(i=>typeof i=="string")||m.quote(n)!==e)return;const o=B(n,s);if(o)return{...o,command:m.quote(o.args)}}a(j,"planBwrapCommand");const l=new Map;function z(e){for(const s of e.targets)l.set(s,(l.get(s)??0)+1)}a(z,"acquirePlan");function C(e,s){for(const n of e.targets){const o=(l.get(n)??1)-1;o>0?l.set(n,o):l.delete(n)}const c=[];for(const n of e.placeholders)if(!l.has(n))try{const o=O(n);if(!o.isFile()||o.size!==0||(o.mode&146)!==0||process.getuid&&o.uid!==process.getuid()||o.mtimeMs<s-2e3)continue;T(n),c.push(n)}catch{}return c}a(C,"releasePlan");function D(e){return l.get(e)??0}a(D,"mountUsersOf");export{z as acquirePlan,D as mountUsersOf,b as pathKind,B as planBwrapArgs,j as planBwrapCommand,C as releasePlan};
@@ -1,6 +1,6 @@
1
1
  export { detectSandboxAvailability, type SandboxAvailability, setSandboxAvailabilityForTesting, } from "./availability.ts";
2
2
  export { collectBlockedAccesses, describeDenialForModel, parseOutput, parseViolationLine, type SandboxBlockedAccess, type SandboxDenial, } from "./denial.ts";
3
3
  export { detectNetworkCommand, FAIL_FAST_NETWORK_ENV, type NetworkCommand, networkDomainsFor, PACKAGE_MANAGERS, type PackageEcosystem, type PackageManager, packageCacheDirs, } from "./package-managers.ts";
4
- export { domainMatches, filesystemRules, isAlwaysBlockedHost, isSandboxLevel, PROTECTED_HOME_READS, PROTECTED_HOME_WRITES, PROTECTED_WRITE_NAMES, type ResolvedSandboxPolicy, readSandboxEnvironment, resolveSandboxPolicy, SANDBOX_ENV, SANDBOX_LEVELS, type SandboxLevel, type SandboxOverride, type SandboxSettings, type SandboxSettingsSources, sandboxEnvironmentValue, stricterLevel, } from "./policy.ts";
4
+ export { domainMatches, filesystemRules, isAlwaysBlockedHost, isSandboxLevel, PROTECTED_HOME_READS, PROTECTED_HOME_WRITES, PROTECTED_WRITE_NAMES, type ResolvedSandboxPolicy, readSandboxEnvironment, resolveSandboxPolicy, SANDBOX_ENV, SANDBOX_LEVELS, type SandboxLevel, type SandboxOverride, type SandboxSettings, type SandboxSettingsSources, sandboxEnvironmentValue, stricterLevel, systemTempDirs, } from "./policy.ts";
5
5
  export { decideNetworkRequest, type NetworkGrant, registerNetworkGrant, resetSandboxRuntime } from "./runtime.ts";
6
6
  export { getProcessShellSandbox, type PlannedNetworkEscalation, type PreparedCommand, registerSandboxEscalationHandler, type SandboxEscalationDecision, type SandboxEscalationHandler, type SandboxEscalationInput, type SandboxEscalationRequest, type SandboxEvent, type SandboxOptions, type SandboxRunDetails, type SandboxStatus, ShellSandbox, type ShellSandboxOptions, setProcessShellSandbox, } from "./shell-sandbox.ts";
@@ -1 +1 @@
1
- import{detectSandboxAvailability as r,setSandboxAvailabilityForTesting as t}from"./availability.js";import{collectBlockedAccesses as s,describeDenialForModel as n,parseOutput as i,parseViolationLine as l}from"./denial.js";import{detectNetworkCommand as E,FAIL_FAST_NETWORK_ENV as S,networkDomainsFor as c,PACKAGE_MANAGERS as x,packageCacheDirs as b}from"./package-managers.js";import{domainMatches as A,filesystemRules as _,isAlwaysBlockedHost as R,isSandboxLevel as T,PROTECTED_HOME_READS as p,PROTECTED_HOME_WRITES as N,PROTECTED_WRITE_NAMES as D,readSandboxEnvironment as O,resolveSandboxPolicy as f,SANDBOX_ENV as k,SANDBOX_LEVELS as v,sandboxEnvironmentValue as P,stricterLevel as u}from"./policy.js";import{decideNetworkRequest as L,registerNetworkGrant as M,resetSandboxRuntime as g}from"./runtime.js";import{getProcessShellSandbox as w,registerSandboxEscalationHandler as y,ShellSandbox as F,setProcessShellSandbox as V}from"./shell-sandbox.js";export{S as FAIL_FAST_NETWORK_ENV,x as PACKAGE_MANAGERS,p as PROTECTED_HOME_READS,N as PROTECTED_HOME_WRITES,D as PROTECTED_WRITE_NAMES,k as SANDBOX_ENV,v as SANDBOX_LEVELS,F as ShellSandbox,s as collectBlockedAccesses,L as decideNetworkRequest,n as describeDenialForModel,E as detectNetworkCommand,r as detectSandboxAvailability,A as domainMatches,_ as filesystemRules,w as getProcessShellSandbox,R as isAlwaysBlockedHost,T as isSandboxLevel,c as networkDomainsFor,b as packageCacheDirs,i as parseOutput,l as parseViolationLine,O as readSandboxEnvironment,M as registerNetworkGrant,y as registerSandboxEscalationHandler,g as resetSandboxRuntime,f as resolveSandboxPolicy,P as sandboxEnvironmentValue,V as setProcessShellSandbox,t as setSandboxAvailabilityForTesting,u as stricterLevel};
1
+ import{detectSandboxAvailability as r,setSandboxAvailabilityForTesting as t}from"./availability.js";import{collectBlockedAccesses as a,describeDenialForModel as n,parseOutput as i,parseViolationLine as l}from"./denial.js";import{detectNetworkCommand as E,FAIL_FAST_NETWORK_ENV as S,networkDomainsFor as c,PACKAGE_MANAGERS as x,packageCacheDirs as m}from"./package-managers.js";import{domainMatches as A,filesystemRules as T,isAlwaysBlockedHost as _,isSandboxLevel as p,PROTECTED_HOME_READS as R,PROTECTED_HOME_WRITES as D,PROTECTED_WRITE_NAMES as N,readSandboxEnvironment as O,resolveSandboxPolicy as f,SANDBOX_ENV as k,SANDBOX_LEVELS as v,sandboxEnvironmentValue as P,stricterLevel as u,systemTempDirs as y}from"./policy.js";import{decideNetworkRequest as L,registerNetworkGrant as M,resetSandboxRuntime as g}from"./runtime.js";import{getProcessShellSandbox as w,registerSandboxEscalationHandler as F,ShellSandbox as V,setProcessShellSandbox as B}from"./shell-sandbox.js";export{S as FAIL_FAST_NETWORK_ENV,x as PACKAGE_MANAGERS,R as PROTECTED_HOME_READS,D as PROTECTED_HOME_WRITES,N as PROTECTED_WRITE_NAMES,k as SANDBOX_ENV,v as SANDBOX_LEVELS,V as ShellSandbox,a as collectBlockedAccesses,L as decideNetworkRequest,n as describeDenialForModel,E as detectNetworkCommand,r as detectSandboxAvailability,A as domainMatches,T as filesystemRules,w as getProcessShellSandbox,_ as isAlwaysBlockedHost,p as isSandboxLevel,c as networkDomainsFor,m as packageCacheDirs,i as parseOutput,l as parseViolationLine,O as readSandboxEnvironment,M as registerNetworkGrant,F as registerSandboxEscalationHandler,g as resetSandboxRuntime,f as resolveSandboxPolicy,P as sandboxEnvironmentValue,B as setProcessShellSandbox,t as setSandboxAvailabilityForTesting,u as stricterLevel,y as systemTempDirs};
@@ -0,0 +1 @@
1
+ var p=Object.defineProperty;var o=(e,t)=>p(e,"name",{value:t,configurable:!0});import{createHash as l}from"node:crypto";import{realpathSync as a}from"node:fs";import{join as c}from"node:path";import{pathToFileURL as s}from"node:url";function m(e){return[...l("md5").update(Buffer.from(e,"utf16le")).digest()].map(r=>r.toString(16)).join("")}o(m,"libreOfficePipeHash");function O(e,t=process.platform,r=process.getuid?.()){if(t!=="darwin"||r===void 0)return;let i;try{i=a(e)}catch{i=e}const f=s(c(i,"libreoffice")).href,n=`/private/tmp/OSL_PIPE_${r}_SingleOfficeIPC_${m(f)}`;return{env:{UserInstallation:f},allowWrite:["/private/tm[p]",n],allowUnixSockets:[n]}}o(O,"libreOfficeAccess");export{O as libreOfficeAccess,m as libreOfficePipeHash};
@@ -3,6 +3,7 @@ export declare const SANDBOX_LEVELS: readonly SandboxLevel[];
3
3
  export interface SandboxSettings {
4
4
  level?: SandboxLevel;
5
5
  network?: {
6
+ access?: "open" | "allowlist";
6
7
  allowedDomains?: string[];
7
8
  deniedDomains?: string[];
8
9
  allowLocalBinding?: boolean;
@@ -26,6 +27,7 @@ export interface ResolvedSandboxPolicy {
26
27
  level: SandboxLevel;
27
28
  levelSource: "override" | "environment" | "settings" | "project" | "default";
28
29
  network: {
30
+ open: boolean;
29
31
  allowedDomains: string[];
30
32
  deniedDomains: string[];
31
33
  allowLocalBinding: boolean;
@@ -51,6 +53,8 @@ export declare function resolveSandboxPolicy(options: {
51
53
  export declare const PROTECTED_WRITE_NAMES: readonly string[];
52
54
  export declare const PROTECTED_HOME_WRITES: readonly string[];
53
55
  export declare const PROTECTED_HOME_READS: readonly string[];
56
+ export declare const HOME_CACHE_DIRS: readonly string[];
57
+ export declare function systemTempDirs(): string[];
54
58
  export declare function expandPath(path: string, cwd: string): string;
55
59
  export interface CommandFilesystemRules {
56
60
  allowWrite: string[];
@@ -1 +1 @@
1
- var A=Object.defineProperty;var i=(e,r)=>A(e,"name",{value:r,configurable:!0});import{existsSync as O,readdirSync as C,realpathSync as N}from"node:fs";import{homedir as h}from"node:os";import{isAbsolute as W,join as u,relative as T,resolve as _,sep as j}from"node:path";import{packageCacheDirs as B}from"./package-managers.js";const I=["read-only","workspace-write","off"],g="DAL_SANDBOX",D={off:0,"workspace-write":1,"read-only":2};function v(e){return typeof e=="string"&&I.includes(e)}i(v,"isSandboxLevel");function P(e,r){return D[r]>D[e]?r:e}i(P,"stricterLevel");function a(e){return Array.isArray(e)?e.filter(r=>typeof r=="string"&&r.length>0):[]}i(a,"strings");function f(e){return[...new Set(e)]}i(f,"unique");const z=process.env[g];function H(e={[g]:z}){const r=e[g];if(r)try{const t=JSON.parse(r);return v(t.level)?{level:t.level,allowedDomains:a(t.allowedDomains)}:void 0}catch{return}}i(H,"readSandboxEnvironment");function Q(e){return JSON.stringify({level:e.level,allowedDomains:e.network.allowedDomains})}i(Q,"sandboxEnvironmentValue");function U(e){const r=e.settings?.global??{},t=e.settings?.project??{},s=H(e.env),l=e.override??{};let o,c;return l.level?(o=l.level,c="override"):s?.level?(o=s.level,c="environment"):v(r.level)?(o=r.level,c="settings"):(o=e.defaultLevel,c="default"),!l.level&&v(t.level)&&P(o,t.level)!==o&&(o=t.level,c="project"),{level:o,levelSource:c,network:{allowedDomains:f([...a(r.network?.allowedDomains),...a(s?.allowedDomains),...a(l.allowedDomains)]),deniedDomains:f([...a(r.network?.deniedDomains),...a(t.network?.deniedDomains)]),allowLocalBinding:r.network?.allowLocalBinding===!0},filesystem:{allowWrite:a(r.filesystem?.allowWrite),denyRead:f([...a(r.filesystem?.denyRead),...a(t.filesystem?.denyRead)]),denyWrite:f([...a(r.filesystem?.denyWrite),...a(t.filesystem?.denyWrite)]),allowRead:a(r.filesystem?.allowRead)}}}i(U,"resolveSandboxPolicy");const M=[".git/hooks",".git/config",".gitmodules",".dal",".claude",".agents",".mcp.json",".cursor",".vscode",".idea",".env"],V=[".gitconfig",".bashrc",".bash_profile",".zshrc",".zprofile",".profile",".config/fish",".dal"],X=[".ssh",".gnupg",".aws",".config/gcloud",".azure",".kube",".docker/config.json",".netrc",".npmrc",".pypirc",".git-credentials",".config/gh","Library/Keychains","Library/Application Support/Google/Chrome","Library/Application Support/Firefox","Library/Safari",".mozilla",".config/google-chrome",".config/chromium",".dal/agent/auth.json"];function m(e,r){return e==="~"?h():e.startsWith("~/")?u(h(),e.slice(2)):W(e)?e:_(r,e)}i(m,"expandPath");function w(e){try{return N(e)}catch{return e}}i(w,"realpathOrSelf");function x(e,r){const t=T(r,e);return t===""||t!==".."&&!t.startsWith(`..${j}`)&&!W(t)}i(x,"isWithin");function Y(e,r,t={}){const s=h(),l=e.level==="workspace-write"?f([r,w(r),...e.filesystem.allowWrite.map(n=>m(n,r))]):[],o=e.level==="workspace-write"?t.gitDirs??[]:[],c=(t.extraWrite??[]).map(n=>m(n,r)),k=t.scratchDir?[t.scratchDir,w(t.scratchDir)]:[],E=e.level==="workspace-write"?t.packageCaches??B():[],R=f([...l,...o,...c,...k,...E]),d=[];if(e.level==="read-only"){const n=f([r,w(r)]);c.some(y=>n.some(S=>x(y,S)||x(S,y)))||d.push(...n)}for(const n of[...l,...c]){for(const p of M)d.push(u(n,p));d.push(u(n,".env.*"));for(const p of F(n))d.push(u(n,p))}for(const n of o)d.push(u(n,"hooks"),u(n,"config"));for(const n of V)d.push(u(s,n));d.push(...e.filesystem.denyWrite.map(n=>m(n,r)));const b=new Set(e.filesystem.allowRead.map(n=>m(n,r))),L=[...X.map(n=>u(s,n)).filter(n=>!b.has(n)),...e.filesystem.denyRead.map(n=>m(n,r))];return{allowWrite:R,denyWrite:f(d),denyRead:f(L)}}i(Y,"filesystemRules");function F(e){if(!O(e))return[];try{return C(e).filter(r=>r.startsWith(".env."))}catch{return[]}}i(F,"listEnvFiles");function Z(e,r){const t=e.toLowerCase(),s=r.toLowerCase();return s.startsWith("*.")?t.endsWith(s.slice(1)):t===s}i(Z,"domainMatches");function ee(e){const r=e.toLowerCase().replace(/^\[|\]$/g,"");if(r==="localhost"||r.endsWith(".localhost")||r==="::1"||r==="0.0.0.0")return!0;if(r.startsWith("fe80:")||r.startsWith("fc")||r.startsWith("fd"))return r.includes(":");const t=r.split(".").map(o=>Number(o));if(t.length!==4||t.some(o=>!Number.isInteger(o)||o<0||o>255))return!1;const[s,l]=t;return s===127||s===10||s===172&&l>=16&&l<=31||s===192&&l===168||s===169&&l===254}i(ee,"isAlwaysBlockedHost");export{X as PROTECTED_HOME_READS,V as PROTECTED_HOME_WRITES,M as PROTECTED_WRITE_NAMES,g as SANDBOX_ENV,I as SANDBOX_LEVELS,Z as domainMatches,m as expandPath,Y as filesystemRules,ee as isAlwaysBlockedHost,v as isSandboxLevel,H as readSandboxEnvironment,U as resolveSandboxPolicy,Q as sandboxEnvironmentValue,P as stricterLevel};
1
+ var T=Object.defineProperty;var i=(e,t)=>T(e,"name",{value:t,configurable:!0});import{existsSync as A,readdirSync as k,realpathSync as C}from"node:fs";import{homedir as g,tmpdir as O}from"node:os";import{isAbsolute as E,join as c,relative as N,resolve as P,sep as I}from"node:path";import{packageCacheDirs as j}from"./package-managers.js";const H=["read-only","workspace-write","off"],v="DAL_SANDBOX",x={off:0,"workspace-write":1,"read-only":2};function y(e){return typeof e=="string"&&H.includes(e)}i(y,"isSandboxLevel");function B(e,t){return x[t]>x[e]?t:e}i(B,"stricterLevel");function f(e){return Array.isArray(e)?e.filter(t=>typeof t=="string"&&t.length>0):[]}i(f,"strings");function u(e){return[...new Set(e)]}i(u,"unique");const M=process.env[v];function z(e={[v]:M}){const t=e[v];if(t)try{const r=JSON.parse(t);return y(r.level)?{level:r.level,allowedDomains:f(r.allowedDomains)}:void 0}catch{return}}i(z,"readSandboxEnvironment");function re(e){return JSON.stringify({level:e.level,allowedDomains:e.network.allowedDomains})}i(re,"sandboxEnvironmentValue");function ne(e){const t=e.settings?.global??{},r=e.settings?.project??{},o=z(e.env),a=e.override??{};let s,l;a.level?(s=a.level,l="override"):o?.level?(s=o.level,l="environment"):y(t.level)?(s=t.level,l="settings"):(s=e.defaultLevel,l="default"),!a.level&&y(r.level)&&B(s,r.level)!==s&&(s=r.level,l="project");const w=s==="workspace-write"&&t.network?.access!=="allowlist"&&r.network?.access!=="allowlist";return{level:s,levelSource:l,network:{open:w,allowedDomains:u([...f(t.network?.allowedDomains),...f(o?.allowedDomains),...f(a.allowedDomains)]),deniedDomains:u([...f(t.network?.deniedDomains),...f(r.network?.deniedDomains)]),allowLocalBinding:t.network?.allowLocalBinding===!0},filesystem:{allowWrite:f(t.filesystem?.allowWrite),denyRead:u([...f(t.filesystem?.denyRead),...f(r.filesystem?.denyRead)]),denyWrite:u([...f(t.filesystem?.denyWrite),...f(r.filesystem?.denyWrite)]),allowRead:f(t.filesystem?.allowRead)}}}i(ne,"resolveSandboxPolicy");const F=[".git/hooks",".git/config",".gitmodules",".dal",".claude",".agents",".mcp.json",".cursor",".vscode",".idea",".env"],V=[".gitconfig",".bashrc",".bash_profile",".zshrc",".zprofile",".profile",".config/fish",".dal"],X=[".ssh",".gnupg",".aws",".config/gcloud",".azure",".kube","Library/Keychains","Library/Application Support/Google/Chrome","Library/Application Support/Firefox","Library/Safari",".mozilla",".config/google-chrome",".config/chromium",".dal/agent/auth.json",".dal/agent/factory.json",".dal/agent/web.json"],J=[".cache","Library/Caches","go/pkg",".gradle/caches",".m2/repository"];function K(){const e=[O(),"/tmp","/var/tmp"];return process.platform==="darwin"&&e.push("/private/tmp","/private/var/tmp"),u([...e,...e.map(h)])}i(K,"systemTempDirs");function p(e,t){return e==="~"?g():e.startsWith("~/")?c(g(),e.slice(2)):E(e)?e:P(t,e)}i(p,"expandPath");function h(e){try{return C(e)}catch{return e}}i(h,"realpathOrSelf");function W(e,t){const r=N(t,e);return r===""||r!==".."&&!r.startsWith(`..${I}`)&&!E(r)}i(W,"isWithin");function oe(e,t,r={}){const o=g(),a=e.level==="workspace-write"?u([t,h(t),...e.filesystem.allowWrite.map(n=>p(n,t))]):[],s=e.level==="workspace-write"?r.gitDirs??[]:[],l=(r.extraWrite??[]).map(n=>p(n,t)),w=r.scratchDir?[r.scratchDir,h(r.scratchDir)]:[],R=e.level==="workspace-write"?[...r.packageCaches??j(),...J.map(n=>c(o,n)),...K()]:[],b=u([...a,...s,...l,...w,...R]),d=[];if(e.level==="read-only"){const n=u([t,h(t)]);l.some(D=>n.some(S=>W(D,S)||W(S,D)))||d.push(...n)}for(const n of[...a,...l]){for(const m of F)d.push(c(n,m));d.push(c(n,".env.*"));for(const m of Q(n))d.push(c(n,m))}for(const n of s)d.push(c(n,"hooks"),c(n,"config"));if(e.level==="workspace-write")for(const n of a)for(const m of G(n))d.push(c(m,".git","config"),c(m,".git","hooks"));for(const n of V)d.push(c(o,n));d.push(...e.filesystem.denyWrite.map(n=>p(n,t)));const L=new Set(e.filesystem.allowRead.map(n=>p(n,t))),_=[...X.map(n=>c(o,n)).filter(n=>!L.has(n)),...e.filesystem.denyRead.map(n=>p(n,t))];return{allowWrite:b,denyWrite:u(d),denyRead:u(_)}}i(oe,"filesystemRules");const $=3,q=new Set(["node_modules",".git","dist","build","target",".venv","venv"]);function G(e){const t=[],r=i((o,a)=>{let s;try{s=k(o,{withFileTypes:!0})}catch{return}for(const l of s)if(l.isDirectory()){if(l.name===".git"){t.push(o);continue}a<$&&!q.has(l.name)&&r(c(o,l.name),a+1)}},"walk");return r(e,0),t}i(G,"nestedRepositories");function Q(e){if(!A(e))return[];try{return k(e).filter(t=>t.startsWith(".env."))}catch{return[]}}i(Q,"listEnvFiles");function se(e,t){const r=e.toLowerCase(),o=t.toLowerCase();return o.startsWith("*.")?r.endsWith(o.slice(1)):r===o}i(se,"domainMatches");function ie(e){const t=e.toLowerCase().replace(/^\[|\]$/g,"");if(t==="localhost"||t.endsWith(".localhost")||t==="::1"||t==="0.0.0.0")return!0;if(t.startsWith("fe80:")||t.startsWith("fc")||t.startsWith("fd"))return t.includes(":");const r=t.split(".").map(s=>Number(s));if(r.length!==4||r.some(s=>!Number.isInteger(s)||s<0||s>255))return!1;const[o,a]=r;return o===127||o===10||o===172&&a>=16&&a<=31||o===192&&a===168||o===169&&a===254}i(ie,"isAlwaysBlockedHost");export{J as HOME_CACHE_DIRS,X as PROTECTED_HOME_READS,V as PROTECTED_HOME_WRITES,F as PROTECTED_WRITE_NAMES,v as SANDBOX_ENV,H as SANDBOX_LEVELS,se as domainMatches,p as expandPath,oe as filesystemRules,ie as isAlwaysBlockedHost,y as isSandboxLevel,z as readSandboxEnvironment,ne as resolveSandboxPolicy,re as sandboxEnvironmentValue,B as stricterLevel,K as systemTempDirs};
@@ -15,6 +15,9 @@ export interface WrapRequest {
15
15
  denyWrite: string[];
16
16
  denyRead: string[];
17
17
  allowLocalBinding: boolean;
18
+ openNetwork?: boolean;
19
+ allowGitConfig?: boolean;
20
+ allowUnixSockets?: string[];
18
21
  ripgrep?: string;
19
22
  }
20
23
  export declare function registerNetworkGrant(grant: NetworkGrant): () => void;
@@ -1 +1 @@
1
- var M=Object.defineProperty;var t=(e,r)=>M(e,"name",{value:r,configurable:!0});import{acquirePlan as W,planBwrapCommand as F,releasePlan as L}from"./bwrap-placeholders.js";import{domainMatches as R,isAlwaysBlockedHost as N}from"./policy.js";const b="dal-sandbox.invalid",u=new Set;let l,c,x,w=Promise.resolve(),y=0;async function A(){return l??=import("@anthropic-ai/sandbox-runtime").then(e=>e.SandboxManager),l}t(A,"loadManager");function D(e){return{network:{allowedDomains:[b],deniedDomains:[],allowLocalBinding:e.allowLocalBinding},filesystem:{denyRead:[],allowWrite:[],denyWrite:[]},...e.ripgrep?{ripgrep:{command:e.ripgrep}}:{}}}t(D,"baseConfig");function B(e){return u.add(e),()=>{u.delete(e)}}t(B,"registerNetworkGrant");function T(e,r){let i=!1;if(!N(e))for(const a of u)a.deniedDomains.some(n=>R(e,n))||a.allowedDomains.some(n=>R(e,n))&&(i=!0);if(!i)for(const a of u)a.refusals.some(n=>n.host===e&&n.port===r)||a.refusals.push({host:e,...r!==void 0?{port:r}:{}});return i}t(T,"decideNetworkRequest");function G(){const e=process._getActiveHandles;return new Set(typeof e=="function"?e.call(process):[])}t(G,"activeHandles");async function H(e,r){c||(x??=(async()=>{const i={SIGINT:new Set(process.listeners("SIGINT")),SIGTERM:new Set(process.listeners("SIGTERM"))},a=G();try{await e.initialize(D(r),async({host:n,port:s})=>T(n,s),!1),c={ready:!0}}catch(n){c={ready:!1,error:n instanceof Error?n.message:String(n)}}finally{for(const n of["SIGINT","SIGTERM"])for(const s of process.listeners(n))i[n].has(s)||process.removeListener(n,s);for(const n of G())!a.has(n)&&typeof n.unref=="function"&&n.unref()}})(),await x)}t(H,"ensureProxy");function X(){return c&&!c.ready?c.error:o&&"error"in o?o.error:void 0}t(X,"proxyUnavailableReason");let o,g,I;function Y(e){I=e?async()=>{const r=await e();return"error"in r?r:{port:r.port,server:{close:t(()=>{},"close")}}}:void 0,o=void 0,g=void 0}t(Y,"setFilteringProxyStarterForTesting");async function O(){try{const{createHttpProxyServer:e}=await import("@anthropic-ai/sandbox-runtime/dist/sandbox/http-proxy.js"),r=e({filter:t((a,n)=>T(n,a),"filter")}),i=await new Promise((a,n)=>{r.once("error",n),r.listen(0,"127.0.0.1",()=>{const s=r.address();a(typeof s=="object"&&s?s.port:0)})});return r.unref(),{port:i,server:r}}catch(e){return{error:e instanceof Error?e.message:String(e)}}}t(O,"startFilteringProxy");async function J(){return o?"error"in o?o:{port:o.port}:(g??=(I??O)(),o=await g,"error"in o?o:{port:o.port})}t(J,"ensureFilteringProxy");function K(){y++}t(K,"acquireSandboxRuntime");async function Q(){y=Math.max(0,y-1),y===0&&await V()}t(Q,"releaseSandboxRuntime");async function Z(e,r){const i=await A(),a=r.allowedDomains.length>0;a&&await H(i,e);const n=t(async()=>{const f={denyRead:e.denyRead,allowWrite:e.allowWrite,denyWrite:e.denyWrite};i.updateConfig({...D(e),filesystem:f});const h=a&&c?.ready===!0,E=Date.now(),v=await i.wrapWithSandbox(e.command,e.shell,{network:{allowedDomains:h?[b]:[],deniedDomains:[]},filesystem:f}),m=process.platform==="linux"?F(v):void 0;return m&&W(m),{wrapped:m?.command??v,proxied:h,plan:m,wrappedAt:E}},"run"),s=w.then(n,n);w=s.catch(()=>{});const{wrapped:p,proxied:d,plan:S,wrappedAt:C}=await s,k=B(r);let P=!1;return{command:p,proxied:d,release:t(()=>{if(P||(P=!0,k(),!S))return;const f=t(()=>{L(S,C)},"cleanup");w=w.then(f,f)},"release")}}t(Z,"wrapCommand");async function $(e,r,i){if(!l)return[];const n=(await l).getSandboxViolationStore();if(n.getTotalCount()===0)return[];const s=Date.now()+i;for(;;){const p=n.getViolationsForCommand(e).filter(d=>d.timestamp.getTime()>=r-1e3);if(p.length>0||Date.now()>=s)return p;await new Promise(d=>setTimeout(d,50))}}t($,"violationsForCommand");async function V(){u.clear(),o&&"server"in o&&o.server.close(),o=void 0,g=void 0;const e=c!==void 0;if(c=void 0,x=void 0,!e||!l)return;await(await l).reset()}t(V,"resetSandboxRuntime");export{K as acquireSandboxRuntime,T as decideNetworkRequest,J as ensureFilteringProxy,X as proxyUnavailableReason,B as registerNetworkGrant,Q as releaseSandboxRuntime,V as resetSandboxRuntime,Y as setFilteringProxyStarterForTesting,$ as violationsForCommand,Z as wrapCommand};
1
+ var W=Object.defineProperty;var t=(e,r)=>W(e,"name",{value:r,configurable:!0});import{acquirePlan as E,planBwrapCommand as L,releasePlan as M}from"./bwrap-placeholders.js";import{domainMatches as R,isAlwaysBlockedHost as A}from"./policy.js";const v="dal-sandbox.invalid",p=new Set;let d,l,x,m=Promise.resolve(),g=0;async function B(){return d??=import("@anthropic-ai/sandbox-runtime").then(e=>e.SandboxManager),d}t(B,"loadManager");function D(e){return e.openNetwork?{network:{deniedDomains:[],allowLocalBinding:!0,allowAllUnixSockets:!0},filesystem:{denyRead:[],allowWrite:[],denyWrite:[]},...e.ripgrep?{ripgrep:{command:e.ripgrep}}:{}}:{network:{allowedDomains:[v],deniedDomains:[],allowLocalBinding:e.allowLocalBinding,...e.allowUnixSockets?.length?{allowUnixSockets:e.allowUnixSockets}:{}},filesystem:{denyRead:[],allowWrite:[],denyWrite:[]},...e.ripgrep?{ripgrep:{command:e.ripgrep}}:{}}}t(D,"baseConfig");function F(e){return p.add(e),()=>{p.delete(e)}}t(F,"registerNetworkGrant");function b(e,r){let i=!1;if(!A(e))for(const a of p)a.deniedDomains.some(n=>R(e,n))||a.allowedDomains.some(n=>R(e,n))&&(i=!0);if(!i)for(const a of p)a.refusals.some(n=>n.host===e&&n.port===r)||a.refusals.push({host:e,...r!==void 0?{port:r}:{}});return i}t(b,"decideNetworkRequest");function G(){const e=process._getActiveHandles;return new Set(typeof e=="function"?e.call(process):[])}t(G,"activeHandles");async function H(e,r){l||(x??=(async()=>{const i={SIGINT:new Set(process.listeners("SIGINT")),SIGTERM:new Set(process.listeners("SIGTERM"))},a=G();try{await e.initialize(D(r),async({host:n,port:s})=>b(n,s),!1),l={ready:!0}}catch(n){l={ready:!1,error:n instanceof Error?n.message:String(n)}}finally{for(const n of["SIGINT","SIGTERM"])for(const s of process.listeners(n))i[n].has(s)||process.removeListener(n,s);for(const n of G())!a.has(n)&&typeof n.unref=="function"&&n.unref()}})(),await x)}t(H,"ensureProxy");function X(){return l&&!l.ready?l.error:o&&"error"in o?o.error:void 0}t(X,"proxyUnavailableReason");let o,y,C;function Y(e){C=e?async()=>{const r=await e();return"error"in r?r:{port:r.port,server:{close:t(()=>{},"close")}}}:void 0,o=void 0,y=void 0}t(Y,"setFilteringProxyStarterForTesting");async function U(){try{const{createHttpProxyServer:e}=await import("@anthropic-ai/sandbox-runtime/dist/sandbox/http-proxy.js"),r=e({filter:t((a,n)=>b(n,a),"filter")}),i=await new Promise((a,n)=>{r.once("error",n),r.listen(0,"127.0.0.1",()=>{const s=r.address();a(typeof s=="object"&&s?s.port:0)})});return r.unref(),{port:i,server:r}}catch(e){return{error:e instanceof Error?e.message:String(e)}}}t(U,"startFilteringProxy");async function J(){return o?"error"in o?o:{port:o.port}:(y??=(C??U)(),o=await y,"error"in o?o:{port:o.port})}t(J,"ensureFilteringProxy");function K(){g++}t(K,"acquireSandboxRuntime");async function Q(){g=Math.max(0,g-1),g===0&&await O()}t(Q,"releaseSandboxRuntime");async function Z(e,r){const i=await B(),a=!e.openNetwork&&r.allowedDomains.length>0;a&&await H(i,e);const n=t(async()=>{const c={denyRead:e.denyRead,allowWrite:e.allowWrite,denyWrite:e.denyWrite,...e.allowGitConfig?{allowGitConfig:!0}:{}};i.updateConfig({...D(e),filesystem:c});const h=a&&l?.ready===!0,N=Date.now(),k=await i.wrapWithSandbox(e.command,e.shell,e.openNetwork?{filesystem:c}:{network:{allowedDomains:h?[v]:[],deniedDomains:[]},filesystem:c}),w=process.platform==="linux"?L(k):void 0;return w&&E(w),{wrapped:w?.command??k,proxied:h,plan:w,wrappedAt:N}},"run"),s=m.then(n,n);m=s.catch(()=>{});const{wrapped:u,proxied:f,plan:S,wrappedAt:T}=await s,I=F(r);let P=!1;return{command:u,proxied:f,release:t(()=>{if(P||(P=!0,I(),!S))return;const c=t(()=>{M(S,T)},"cleanup");m=m.then(c,c)},"release")}}t(Z,"wrapCommand");async function $(e,r,i){if(!d)return[];const n=(await d).getSandboxViolationStore();if(n.getTotalCount()===0)return[];const s=Date.now()+i;for(;;){const u=n.getViolationsForCommand(e).filter(f=>f.timestamp.getTime()>=r-1e3);if(u.length>0||Date.now()>=s)return u;await new Promise(f=>setTimeout(f,50))}}t($,"violationsForCommand");async function O(){p.clear(),o&&"server"in o&&o.server.close(),o=void 0,y=void 0;const e=l!==void 0;if(l=void 0,x=void 0,!e||!d)return;await(await d).reset()}t(O,"resetSandboxRuntime");export{K as acquireSandboxRuntime,b as decideNetworkRequest,J as ensureFilteringProxy,X as proxyUnavailableReason,F as registerNetworkGrant,Q as releaseSandboxRuntime,O as resetSandboxRuntime,Y as setFilteringProxyStarterForTesting,$ as violationsForCommand,Z as wrapCommand};
@@ -98,6 +98,7 @@ export interface SandboxRunDetails {
98
98
  export declare function registerSandboxEscalationHandler(handler: SandboxEscalationHandler): () => void;
99
99
  export declare function setProcessShellSandbox(sandbox: ShellSandbox | undefined): void;
100
100
  export declare function getProcessShellSandbox(): ShellSandbox | undefined;
101
+ export declare const MACOS_HEREDOC_TEMP = "/private/tmp/sh-thd-*";
101
102
  export declare class ShellSandbox {
102
103
  readonly policy: ResolvedSandboxPolicy;
103
104
  private readonly onEscalation?;
@@ -115,6 +116,7 @@ export declare class ShellSandbox {
115
116
  get active(): boolean;
116
117
  private availability;
117
118
  status(): SandboxStatus;
119
+ private networkOpen;
118
120
  describeForModel(): string | undefined;
119
121
  unavailableRefusal(): string | undefined;
120
122
  planNetworkEscalation(call: {