dal-code 1.0.39 → 1.0.40

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 (305) hide show
  1. package/CHANGELOG.md +82 -4
  2. package/NOTICE +224 -0
  3. package/dal-docs/examples/extensions/LICENSE +21 -0
  4. package/dal-docs/examples/extensions/README.md +64 -0
  5. package/dal-docs/examples/extensions/bookmark.ts +52 -0
  6. package/dal-docs/examples/extensions/claude-rules.ts +88 -0
  7. package/dal-docs/examples/extensions/commands.ts +74 -0
  8. package/dal-docs/examples/extensions/custom-footer.ts +66 -0
  9. package/dal-docs/examples/extensions/dirty-repo-guard.ts +58 -0
  10. package/dal-docs/examples/extensions/dynamic-tools.ts +76 -0
  11. package/dal-docs/examples/extensions/hello.ts +49 -0
  12. package/dal-docs/examples/extensions/inline-bash.ts +96 -0
  13. package/dal-docs/examples/extensions/permission-gate.ts +36 -0
  14. package/dal-docs/examples/extensions/protected-paths.ts +32 -0
  15. package/dal-docs/examples/extensions/session-name.ts +29 -0
  16. package/dal-docs/examples/extensions/status-line.ts +34 -0
  17. package/dal-docs/examples/extensions/structured-output.ts +67 -0
  18. package/dal-docs/examples/extensions/tool-override.ts +146 -0
  19. package/dal-docs/examples/extensions/trigger-compact.ts +59 -0
  20. package/dal-docs/examples/extensions/truncated-tool.ts +197 -0
  21. package/dal-docs/extensions.md +27 -0
  22. package/dist/cli/args.d.ts +3 -0
  23. package/dist/cli/args.js +17 -17
  24. package/dist/config.d.ts +1 -0
  25. package/dist/config.js +1 -1
  26. package/dist/core/agent-session.js +6 -6
  27. package/dist/core/extensions/loader.js +1 -1
  28. package/dist/core/extensions/permission-surface.js +1 -1
  29. package/dist/core/extensions/runner.js +1 -1
  30. package/dist/core/extensions/types.d.ts +15 -1
  31. package/dist/core/model-registry.d.ts +1 -0
  32. package/dist/core/model-registry.js +1 -1
  33. package/dist/core/nested-tool-calls.js +2 -2
  34. package/dist/core/resource-loader.js +1 -1
  35. package/dist/core/system-prompt.js +10 -9
  36. package/dist/core/tools/bash.js +13 -12
  37. package/dist/core/tools/path-utils.d.ts +5 -0
  38. package/dist/core/tools/process.d.ts +2 -0
  39. package/dist/core/tools/process.js +14 -13
  40. package/dist/dal/extension-compat.d.ts +62 -0
  41. package/dist/dal/extension-compat.js +4 -0
  42. package/dist/dal/hooks/extension.js +2 -2
  43. package/dist/dal/i18n.js +1 -1
  44. package/dist/dal/manifest.js +1 -1
  45. package/dist/dal/reviewed/endorsed-cli.js +1 -1
  46. package/dist/dal/reviewed/endorsed.js +1 -1
  47. package/dist/dal/reviewed/market-keys.js +1 -0
  48. package/dist/dal/reviewed/market.d.ts +64 -0
  49. package/dist/dal/reviewed/market.js +2 -0
  50. package/dist/extensions/mcp/runtime.d.ts +2 -1
  51. package/dist/extensions/mcp/runtime.js +3 -3
  52. package/dist/extensions/mcp/runtime.lazy.d.ts +1 -0
  53. package/dist/index.d.ts +7 -1
  54. package/dist/index.js +1 -1
  55. package/dist/main.js +4 -4
  56. package/dist/modes/acp/acp-mode.js +1 -1
  57. package/dist/modes/interactive/interactive-mode.d.ts +1 -0
  58. package/dist/modes/interactive/interactive-mode.js +14 -14
  59. package/dist/modes/print-mode.js +3 -3
  60. package/dist/modes/rpc/rpc-mode.js +1 -1
  61. package/dist/node_modules/@dalcode/dal-advisor/LICENSE +45 -0
  62. package/dist/node_modules/@dalcode/dal-advisor/package.json +35 -0
  63. package/dist/node_modules/@dalcode/dal-advisor/src/index.js +22 -0
  64. package/dist/node_modules/@dalcode/dal-bridge/package.json +2 -2
  65. package/dist/node_modules/@dalcode/dal-bridge/src/ask-user.js +1 -1
  66. package/dist/node_modules/@dalcode/dal-capabilities/LICENSE +21 -0
  67. package/dist/node_modules/@dalcode/dal-capabilities/package.json +38 -0
  68. package/dist/node_modules/@dalcode/dal-capabilities/src/catalogue.js +1 -0
  69. package/dist/node_modules/@dalcode/dal-capabilities/src/index.js +11 -0
  70. package/dist/node_modules/@dalcode/dal-capabilities/src/install.js +4 -0
  71. package/dist/node_modules/@dalcode/dal-capabilities/src/match.js +1 -0
  72. package/dist/node_modules/@dalcode/dal-capabilities/src/state.js +3 -0
  73. package/dist/node_modules/@dalcode/dal-compat/LICENSE +21 -0
  74. package/dist/node_modules/@dalcode/dal-compat/package.json +32 -0
  75. package/dist/node_modules/@dalcode/dal-compat/src/claude-rules.js +3 -0
  76. package/dist/node_modules/@dalcode/dal-compat/src/index.js +7 -0
  77. package/dist/node_modules/@dalcode/dal-dap/LICENSE +47 -0
  78. package/dist/node_modules/@dalcode/dal-dap/package.json +38 -0
  79. package/dist/node_modules/@dalcode/dal-dap/src/adapters.js +1 -0
  80. package/dist/node_modules/@dalcode/dal-dap/src/client.js +5 -0
  81. package/dist/node_modules/@dalcode/dal-dap/src/index.js +9 -0
  82. package/dist/node_modules/@dalcode/dal-dap/src/install.js +2 -0
  83. package/dist/node_modules/@dalcode/dal-dap/src/session.js +2 -0
  84. package/dist/node_modules/@dalcode/dal-dap/src/types.js +0 -0
  85. package/dist/node_modules/@dalcode/dal-gateway/package.json +2 -2
  86. package/dist/node_modules/@dalcode/dal-goal/package.json +4 -3
  87. package/dist/node_modules/@dalcode/dal-goal/src/core.js +6 -6
  88. package/dist/node_modules/@dalcode/dal-goal/src/index.js +17 -7
  89. package/dist/node_modules/@dalcode/dal-goal/src/verify.js +26 -0
  90. package/dist/node_modules/@dalcode/dal-guard/package.json +6 -4
  91. package/dist/node_modules/@dalcode/dal-guard/src/credentials.js +1 -1
  92. package/dist/node_modules/@dalcode/dal-guard/src/edit-anchor-core.js +23 -0
  93. package/dist/node_modules/@dalcode/dal-guard/src/edit-anchor.js +4 -0
  94. package/dist/node_modules/@dalcode/dal-guard/src/index.js +1 -1
  95. package/dist/node_modules/@dalcode/dal-guard/src/workspace.js +2 -2
  96. package/dist/node_modules/@dalcode/dal-halo/package.json +1 -1
  97. package/dist/node_modules/@dalcode/dal-interactive/LICENSE +209 -0
  98. package/dist/node_modules/@dalcode/dal-interactive/package.json +4 -3
  99. package/dist/node_modules/@dalcode/dal-interactive/src/btw.js +25 -0
  100. package/dist/node_modules/@dalcode/dal-interactive/src/index.js +1 -1
  101. package/dist/node_modules/@dalcode/dal-lang/package.json +3 -3
  102. package/dist/node_modules/@dalcode/dal-learn/LICENSE +21 -0
  103. package/dist/node_modules/@dalcode/dal-learn/package.json +35 -0
  104. package/dist/node_modules/@dalcode/dal-learn/src/engine.js +8 -0
  105. package/dist/node_modules/@dalcode/dal-learn/src/extract.js +14 -0
  106. package/dist/node_modules/@dalcode/dal-learn/src/index.js +17 -0
  107. package/dist/node_modules/@dalcode/dal-learn/src/lessons.js +3 -0
  108. package/dist/node_modules/@dalcode/dal-learn/src/migrate.js +1 -0
  109. package/dist/node_modules/@dalcode/dal-learn/src/procedures.js +11 -0
  110. package/dist/node_modules/@dalcode/dal-learn/src/project-map.js +2 -0
  111. package/dist/node_modules/@dalcode/dal-learn/src/project.js +1 -0
  112. package/dist/node_modules/@dalcode/dal-learn/src/safety.js +2 -0
  113. package/dist/node_modules/@dalcode/dal-learn/src/signals.js +5 -0
  114. package/dist/node_modules/@dalcode/dal-learn/src/skill-actions.js +1 -0
  115. package/dist/node_modules/@dalcode/dal-learn/src/skill-evolution.js +16 -0
  116. package/dist/node_modules/@dalcode/dal-learn/src/store.js +2 -0
  117. package/dist/node_modules/@dalcode/dal-lsp/package.json +6 -4
  118. package/dist/node_modules/@dalcode/dal-lsp/src/client.js +3 -3
  119. package/dist/node_modules/@dalcode/dal-lsp/src/config.js +1 -1
  120. package/dist/node_modules/@dalcode/dal-lsp/src/format.js +8 -7
  121. package/dist/node_modules/@dalcode/dal-lsp/src/index.js +11 -8
  122. package/dist/node_modules/@dalcode/dal-mcp/package.json +6 -5
  123. package/dist/node_modules/@dalcode/dal-mcp/src/config.d.ts +1 -0
  124. package/dist/node_modules/@dalcode/dal-mcp/src/config.js +1 -1
  125. package/dist/node_modules/@dalcode/dal-mcp/src/http-client.d.ts +32 -1
  126. package/dist/node_modules/@dalcode/dal-mcp/src/http-client.js +2 -1
  127. package/dist/node_modules/@dalcode/dal-mcp/src/index.js +16 -16
  128. package/dist/node_modules/@dalcode/dal-mcp/src/oauth.js +2 -0
  129. package/dist/node_modules/@dalcode/dal-mcp/src/stdio-client.d.ts +4 -2
  130. package/dist/node_modules/@dalcode/dal-mcp/src/stdio-client.js +4 -4
  131. package/dist/node_modules/@dalcode/dal-mcp/src/types.d.ts +9 -0
  132. package/dist/node_modules/@dalcode/dal-mcp/src/types.js +1 -1
  133. package/dist/node_modules/@dalcode/dal-office/package.json +2 -2
  134. package/dist/node_modules/@dalcode/dal-office/src/index.d.ts +6 -3
  135. package/dist/node_modules/@dalcode/dal-office/src/index.js +1 -1
  136. package/dist/node_modules/@dalcode/dal-office/src/render/chart-theme.d.ts +13 -0
  137. package/dist/node_modules/@dalcode/dal-office/src/render/chart-theme.js +1 -0
  138. package/dist/node_modules/@dalcode/dal-office/src/render/chart.d.ts +16 -0
  139. package/dist/node_modules/@dalcode/dal-office/src/render/chart.js +4 -2
  140. package/dist/node_modules/@dalcode/dal-office/src/render/docx.d.ts +4 -1
  141. package/dist/node_modules/@dalcode/dal-office/src/render/docx.js +1 -1
  142. package/dist/node_modules/@dalcode/dal-office/src/render/drawio-style.d.ts +4 -0
  143. package/dist/node_modules/@dalcode/dal-office/src/render/drawio-style.js +1 -0
  144. package/dist/node_modules/@dalcode/dal-office/src/render/pptx.d.ts +52 -4
  145. package/dist/node_modules/@dalcode/dal-office/src/render/pptx.js +3 -2
  146. package/dist/node_modules/@dalcode/dal-office/src/render/thumbnails.d.ts +1 -1
  147. package/dist/node_modules/@dalcode/dal-office/src/render/thumbnails.js +1 -1
  148. package/dist/node_modules/@dalcode/dal-office/src/render/xlsx.d.ts +1 -0
  149. package/dist/node_modules/@dalcode/dal-office/src/render/xlsx.js +1 -1
  150. package/dist/node_modules/@dalcode/dal-office/src/scratchpad.d.ts +30 -1
  151. package/dist/node_modules/@dalcode/dal-office/src/scratchpad.js +1 -1
  152. package/dist/node_modules/@dalcode/dal-office/src/themes.d.ts +35 -1
  153. package/dist/node_modules/@dalcode/dal-office/src/themes.js +1 -1
  154. package/dist/node_modules/@dalcode/dal-office/src/tools/chart-generate.js +3 -3
  155. package/dist/node_modules/@dalcode/dal-office/src/tools/doc-generate.js +2 -2
  156. package/dist/node_modules/@dalcode/dal-office/src/tools/drawio-generate.js +3 -3
  157. package/dist/node_modules/@dalcode/dal-office/src/tools/ppt-generate.js +2 -2
  158. package/dist/node_modules/@dalcode/dal-office/src/tools/ppt-plan.js +2 -2
  159. package/dist/node_modules/@dalcode/dal-office/src/tools/sheet-generate.js +2 -2
  160. package/dist/node_modules/@dalcode/dal-pi-kit/dist/i18n.js +4 -4
  161. package/dist/node_modules/@dalcode/dal-pi-kit/package.json +1 -1
  162. package/dist/node_modules/@dalcode/dal-pi-kit/src/i18n.js +4 -4
  163. package/dist/node_modules/@dalcode/dal-plugins/package.json +4 -5
  164. package/dist/node_modules/@dalcode/dal-plugins/src/index.js +11 -11
  165. package/dist/node_modules/@dalcode/dal-plugins/src/manage.js +8 -10
  166. package/dist/node_modules/@dalcode/dal-plugins/src/npm-hook.js +1 -1
  167. package/dist/node_modules/@dalcode/dal-plugins/src/registry.js +2 -2
  168. package/dist/node_modules/@dalcode/dal-recall/LICENSE +45 -0
  169. package/dist/node_modules/@dalcode/dal-recall/package.json +34 -0
  170. package/dist/node_modules/@dalcode/dal-recall/src/index-db.js +57 -0
  171. package/dist/node_modules/@dalcode/dal-recall/src/index.js +1 -0
  172. package/dist/node_modules/@dalcode/dal-recall/src/query.js +1 -0
  173. package/dist/node_modules/@dalcode/dal-recall/src/redact.js +1 -0
  174. package/dist/node_modules/@dalcode/dal-recall/src/sqlite.js +1 -0
  175. package/dist/node_modules/@dalcode/dal-review/package.json +3 -3
  176. package/dist/node_modules/@dalcode/dal-rewind/package.json +2 -2
  177. package/dist/node_modules/@dalcode/dal-rewind/src/commands.js +2 -2
  178. package/dist/node_modules/@dalcode/dal-rewind/src/core.d.ts +21 -8
  179. package/dist/node_modules/@dalcode/dal-rewind/src/core.js +8 -3
  180. package/dist/node_modules/@dalcode/dal-rewind/src/index.js +1 -1
  181. package/dist/node_modules/@dalcode/dal-rewind/src/state.js +1 -1
  182. package/dist/node_modules/@dalcode/dal-router/package.json +6 -5
  183. package/dist/node_modules/@dalcode/dal-router/src/advisor.js +1 -0
  184. package/dist/node_modules/@dalcode/dal-router/src/assist.js +4 -2
  185. package/dist/node_modules/@dalcode/dal-router/src/commands.js +8 -8
  186. package/dist/node_modules/@dalcode/dal-router/src/config.d.ts +3 -0
  187. package/dist/node_modules/@dalcode/dal-router/src/config.js +2 -2
  188. package/dist/node_modules/@dalcode/dal-router/src/index.js +4 -4
  189. package/dist/node_modules/@dalcode/dal-router/src/jev.d.ts +2 -1
  190. package/dist/node_modules/@dalcode/dal-router/src/jev.js +4 -4
  191. package/dist/node_modules/@dalcode/dal-router/src/services.js +1 -1
  192. package/dist/node_modules/@dalcode/dal-router/src/subagent.js +1 -1
  193. package/dist/node_modules/@dalcode/dal-skills/package.json +4 -3
  194. package/dist/node_modules/@dalcode/dal-skills/src/bundled/browser-qa/SKILL.md +48 -0
  195. package/dist/node_modules/@dalcode/dal-skills/src/bundled/diagram-design/SKILL.md +81 -0
  196. package/dist/node_modules/@dalcode/dal-skills/src/bundled/poster-design/SKILL.md +50 -0
  197. package/dist/node_modules/@dalcode/dal-skills/src/bundled/print-design/SKILL.md +55 -0
  198. package/dist/node_modules/@dalcode/dal-skills/src/bundled/visual-kit/dashboard.html +177 -0
  199. package/dist/node_modules/@dalcode/dal-skills/src/bundled/visual-kit/diagram.html +39 -0
  200. package/dist/node_modules/@dalcode/dal-skills/src/bundled/visual-kit/echarts-dal.json +360 -0
  201. package/dist/node_modules/@dalcode/dal-skills/src/bundled/visual-kit/email/notice.html +46 -0
  202. package/dist/node_modules/@dalcode/dal-skills/src/bundled/visual-kit/landing.html +173 -0
  203. package/dist/node_modules/@dalcode/dal-skills/src/bundled/visual-kit/mermaid-dal.json +140 -0
  204. package/dist/node_modules/@dalcode/dal-skills/src/bundled/visual-kit/mindmap.html +65 -0
  205. package/dist/node_modules/@dalcode/dal-skills/src/bundled/visual-kit/posters/event-poster.html +40 -0
  206. package/dist/node_modules/@dalcode/dal-skills/src/bundled/visual-kit/posters/poster.css +41 -0
  207. package/dist/node_modules/@dalcode/dal-skills/src/bundled/visual-kit/posters/square-card.html +25 -0
  208. package/dist/node_modules/@dalcode/dal-skills/src/bundled/visual-kit/posters/wechat-cover.html +29 -0
  209. package/dist/node_modules/@dalcode/dal-skills/src/bundled/visual-kit/posters/xhs-card.html +35 -0
  210. package/dist/node_modules/@dalcode/dal-skills/src/bundled/visual-kit/posters/xhs-cover.html +26 -0
  211. package/dist/node_modules/@dalcode/dal-skills/src/bundled/visual-kit/print/letter.html +35 -0
  212. package/dist/node_modules/@dalcode/dal-skills/src/bundled/visual-kit/print/print.css +65 -0
  213. package/dist/node_modules/@dalcode/dal-skills/src/bundled/visual-kit/print/report.html +76 -0
  214. package/dist/node_modules/@dalcode/dal-skills/src/bundled/visual-kit/print/resume.html +72 -0
  215. package/dist/node_modules/@dalcode/dal-skills/src/bundled/visual-kit/render.mjs +18 -0
  216. package/dist/node_modules/@dalcode/dal-skills/src/bundled/visual-kit/tokens.css +264 -0
  217. package/dist/node_modules/@dalcode/dal-skills/src/bundled/web-design/SKILL.md +73 -0
  218. package/dist/node_modules/@dalcode/dal-skills/src/bundled.js +1 -0
  219. package/dist/node_modules/@dalcode/dal-skills/src/catalog.js +2 -2
  220. package/dist/node_modules/@dalcode/dal-skills/src/index.js +16 -11
  221. package/dist/node_modules/@dalcode/dal-statusline/LICENSE +21 -0
  222. package/dist/node_modules/@dalcode/dal-statusline/package.json +31 -0
  223. package/dist/node_modules/@dalcode/dal-statusline/src/index.js +3 -0
  224. package/dist/node_modules/@dalcode/dal-structured/LICENSE +21 -0
  225. package/dist/node_modules/@dalcode/dal-structured/package.json +32 -0
  226. package/dist/node_modules/@dalcode/dal-structured/src/index.js +9 -0
  227. package/dist/node_modules/@dalcode/dal-subagent/LICENSE +24 -0
  228. package/dist/node_modules/@dalcode/dal-subagent/package.json +7 -6
  229. package/dist/node_modules/@dalcode/dal-subagent/src/background.js +13 -0
  230. package/dist/node_modules/@dalcode/dal-subagent/src/index.js +22 -14
  231. package/dist/node_modules/@dalcode/dal-subagent/src/inproc-runner.js +3 -0
  232. package/dist/node_modules/@dalcode/dal-subagent/src/pool.js +1 -0
  233. package/dist/node_modules/@dalcode/dal-subagent/src/process-runner.js +3 -3
  234. package/dist/node_modules/@dalcode/dal-subagent/src/tmux-runner.js +3 -0
  235. package/dist/node_modules/@dalcode/dal-subagent/src/worktree.js +2 -0
  236. package/dist/node_modules/@dalcode/dal-telemetry/package.json +2 -2
  237. package/dist/node_modules/@dalcode/dal-terminal/package.json +2 -2
  238. package/dist/node_modules/@dalcode/dal-tool-catalog/package.json +2 -2
  239. package/dist/node_modules/@dalcode/dal-tool-catalog/src/groups.js +1 -1
  240. package/dist/node_modules/@dalcode/dal-tool-catalog/src/index.js +4 -4
  241. package/dist/node_modules/@dalcode/dal-tool-catalog/src/repair-hook.js +1 -0
  242. package/dist/node_modules/@dalcode/dal-tool-catalog/src/repair.js +4 -0
  243. package/dist/node_modules/@dalcode/dal-usage/LICENSE +45 -0
  244. package/dist/node_modules/@dalcode/dal-usage/package.json +33 -0
  245. package/dist/node_modules/@dalcode/dal-usage/src/budget.d.ts +14 -0
  246. package/dist/node_modules/@dalcode/dal-usage/src/budget.js +3 -0
  247. package/dist/node_modules/@dalcode/dal-usage/src/data.d.ts +30 -0
  248. package/dist/node_modules/@dalcode/dal-usage/src/data.js +1 -0
  249. package/dist/node_modules/@dalcode/dal-usage/src/index.d.ts +12 -0
  250. package/dist/node_modules/@dalcode/dal-usage/src/index.js +2 -0
  251. package/dist/node_modules/@dalcode/dal-usage/src/report.d.ts +29 -0
  252. package/dist/node_modules/@dalcode/dal-usage/src/report.js +3 -0
  253. package/dist/node_modules/@dalcode/dal-web/package.json +6 -4
  254. package/dist/node_modules/@dalcode/dal-web/src/fetch.js +11 -5
  255. package/dist/node_modules/@dalcode/dal-web/src/index.js +2 -2
  256. package/dist/node_modules/@dalcode/dal-web/src/pdf.js +5 -0
  257. package/dist/node_modules/@dalcode/dal-workflow/LICENSE +24 -0
  258. package/dist/node_modules/@dalcode/dal-workflow/package.json +2 -2
  259. package/dist/node_modules/@dalcode/dal-workflow/src/announce-check.js +1 -0
  260. package/dist/node_modules/@dalcode/dal-workflow/src/check-in.js +1 -1
  261. package/dist/node_modules/@dalcode/dal-workflow/src/completion-check.js +2 -2
  262. package/dist/node_modules/@dalcode/dal-workflow/src/index.js +4 -4
  263. package/dist/node_modules/@dalcode/dal-workflow/src/lean-code.js +1 -0
  264. package/dist/node_modules/@dalcode/dal-workflow/src/ledger.js +3 -3
  265. package/dist/node_modules/@dalcode/dal-workflow/src/loop-guard.js +3 -0
  266. package/dist/node_modules/@dalcode/dal-workflow/src/shared.js +2 -2
  267. package/dist/node_modules/@dalcode/dal-workflow/src/todo.js +4 -2
  268. package/dist/node_modules/@dalcode/dal-workflow/src/verify-check.js +2 -0
  269. package/dist/node_modules/@dalcode/deepailab/package.json +3 -3
  270. package/dist/node_modules/@earendil-works/chord/package.json +1 -1
  271. package/dist/node_modules/@earendil-works/pi-agent-core/package.json +2 -2
  272. package/dist/node_modules/@earendil-works/pi-ai/dist/cli.js +0 -0
  273. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/.manifest.json +1 -1
  274. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/opencode.json +1 -1
  275. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/openrouter.json +1 -1
  276. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/radius.json +1 -1
  277. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/vercel-ai-gateway.json +1 -1
  278. package/dist/node_modules/@earendil-works/pi-ai/package.json +2 -2
  279. package/dist/node_modules/@earendil-works/pi-client/package.json +3 -3
  280. package/dist/node_modules/@earendil-works/pi-codemode/package.json +1 -1
  281. package/dist/node_modules/@earendil-works/pi-coding-agent/package.json +1 -1
  282. package/dist/node_modules/@earendil-works/pi-mcp/package.json +1 -1
  283. package/dist/node_modules/@earendil-works/pi-protocol/package.json +2 -2
  284. package/dist/node_modules/@earendil-works/pi-server/package.json +3 -3
  285. package/dist/node_modules/@earendil-works/pi-telemetry/package.json +1 -1
  286. package/dist/node_modules/@earendil-works/pi-tui/package.json +1 -1
  287. package/dist/package-manager-cli.js +61 -61
  288. package/dist/sdk/office.d.ts +1 -1
  289. package/dist/sdk/office.js +1 -1
  290. package/dist/sdk/rewind.d.ts +1 -1
  291. package/dist/sdk/rewind.js +1 -1
  292. package/dist/sdk/usage.d.ts +8 -0
  293. package/dist/sdk/usage.js +1 -0
  294. package/dist/utils/open-browser.d.ts +1 -0
  295. package/dist/utils/tools-manager.js +1 -1
  296. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  297. package/examples/extensions/gondolin/package-lock.json +2 -2
  298. package/examples/extensions/gondolin/package.json +1 -1
  299. package/examples/extensions/sandbox/package-lock.json +2 -2
  300. package/examples/extensions/sandbox/package.json +1 -1
  301. package/examples/extensions/with-deps/package-lock.json +2 -2
  302. package/examples/extensions/with-deps/package.json +1 -1
  303. package/npm-shrinkwrap.json +57 -14
  304. package/package.json +9 -2
  305. package/dist/node_modules/@dalcode/dal-plugins/src/compat.js +0 -2
@@ -1,6 +1,6 @@
1
- var R=Object.defineProperty;var n=(r,f)=>R(r,"name",{value:f,configurable:!0});import{flushRawStdout as I,waitForRawStdoutBackpressure as M,writeRawStdout as c}from"../core/output-guard.js";import{fill as j,t as l}from"../dal/i18n.js";import{killTrackedDetachedChildren as k}from"../utils/shell.js";import{toJsonEvent as E}from"./json-event.js";async function J(r,f){const{mode:i,messages:h=[],initialMessage:m,initialImages:x}=f;let d=0,p,o=r.session,u,g,w=!1;const y=[],S=n(async()=>{w||(w=!0,u?.(),g?.(),await r.dispose())},"disposeRuntime");n(()=>{const s=["SIGTERM"];process.platform!=="win32"&&s.push("SIGHUP");for(const e of s){const t=n(()=>{k(),S().finally(()=>{process.exit(e==="SIGHUP"?129:143)})},"handler");process.on(e,t),y.push(()=>process.off(e,t))}},"registerSignalHandlers")(),r.setRebindSession(async()=>{await b()});const b=n(async()=>{o=r.session,await o.bindExtensions({mode:i==="json"?"json":"print",commandContextActions:{waitForIdle:n(()=>o.waitForIdle(),"waitForIdle"),newSession:n(async s=>r.newSession(s),"newSession"),fork:n(async(s,e)=>({cancelled:(await r.fork(s,e)).cancelled}),"fork"),navigateTree:n(async(s,e)=>({cancelled:(await o.navigateTree(s,{summarize:e?.summarize,customInstructions:e?.customInstructions,replaceInstructions:e?.replaceInstructions,label:e?.label})).cancelled}),"navigateTree"),switchSession:n(async(s,e)=>r.switchSession(s,e),"switchSession"),reload:n(async()=>{await o.reload()},"reload")},onError:n(s=>{console.error(j(l("\u6269\u5C55\u51FA\u9519\uFF08{path}\uFF09\uFF1A{error}"),{path:s.extensionPath,error:String(s.error)}))},"onError")}),u?.(),g?.(),u=o.subscribe(s=>{s.type==="message_end"&&s.message.role==="assistant"&&(p=s.message),i==="json"&&c(`${JSON.stringify(E(s))}
1
+ var x=Object.defineProperty;var n=(r,f)=>x(r,"name",{value:f,configurable:!0});import{flushRawStdout as R,waitForRawStdoutBackpressure as M,writeRawStdout as c}from"../core/output-guard.js";import{fill as j,t as l}from"../dal/i18n.js";import{killTrackedDetachedChildren as k}from"../utils/shell.js";import{toJsonEvent as T}from"./json-event.js";async function F(r,f){const{mode:i,messages:h=[],initialMessage:m,initialImages:I}=f;let d=0,p,o=r.session,u,g,w=!1;const y=[],S=n(async()=>{w||(w=!0,u?.(),g?.(),await r.dispose())},"disposeRuntime");n(()=>{const s=["SIGTERM","SIGINT"];process.platform!=="win32"&&s.push("SIGHUP");for(const e of s){const t=n(()=>{k(),S().finally(()=>{process.exit(e==="SIGHUP"?129:e==="SIGINT"?130:143)})},"handler");process.on(e,t),y.push(()=>process.off(e,t))}},"registerSignalHandlers")(),r.setRebindSession(async()=>{await b()});const b=n(async()=>{o=r.session,await o.bindExtensions({mode:i==="json"?"json":"print",commandContextActions:{waitForIdle:n(()=>o.waitForIdle(),"waitForIdle"),newSession:n(async s=>r.newSession(s),"newSession"),fork:n(async(s,e)=>({cancelled:(await r.fork(s,e)).cancelled}),"fork"),navigateTree:n(async(s,e)=>({cancelled:(await o.navigateTree(s,{summarize:e?.summarize,customInstructions:e?.customInstructions,replaceInstructions:e?.replaceInstructions,label:e?.label})).cancelled}),"navigateTree"),switchSession:n(async(s,e)=>r.switchSession(s,e),"switchSession"),reload:n(async()=>{await o.reload()},"reload")},onError:n(s=>{console.error(j(l("\u6269\u5C55\u51FA\u9519\uFF08{path}\uFF09\uFF1A{error}"),{path:s.extensionPath,error:String(s.error)}))},"onError")}),u?.(),g?.(),u=o.subscribe(s=>{s.type==="message_end"&&s.message.role==="assistant"&&(p=s.message),i==="json"&&c(`${JSON.stringify(T(s))}
2
2
  `)}),g=i==="json"?o.agent.subscribe(async()=>{await M()}):void 0},"rebindSession");try{if(i==="json"){const s=o.sessionManager.getHeader();s&&c(`${JSON.stringify(s)}
3
- `)}await b(),m&&await o.prompt(m,{images:x});for(const s of h)await o.prompt(s);if(i==="text"){const s=o.state,e=s.messages[s.messages.length-1];if(e?.role==="custom"&&e.display){const t=typeof e.content=="string"?e.content:e.content.filter(a=>a.type==="text").map(a=>a.text).join(`
3
+ `)}await b(),m&&await o.prompt(m,{images:I});for(const s of h)await o.prompt(s);if(i==="text"){const s=o.state,e=s.messages[s.messages.length-1];if(e?.role==="custom"&&e.display){const t=typeof e.content=="string"?e.content:e.content.filter(a=>a.type==="text").map(a=>a.text).join(`
4
4
  `);t&&c(`${t}
5
5
  `)}else if(p||e?.role==="assistant"){const t=p??e;if(t.stopReason==="error"||t.stopReason==="aborted")console.error(t.errorMessage||(t.stopReason==="aborted"?l("\u8BF7\u6C42\u5DF2\u4E2D\u6B62"):l("\u8BF7\u6C42\u51FA\u9519"))),d=1;else{for(const a of t.content)a.type==="text"&&c(`${a.text}
6
- `);t.stopReason==="length"&&(console.error(l("\u56DE\u7B54\u88AB\u622A\u65AD\uFF1A\u6A21\u578B\u5DF2\u8FBE\u5230\u8F93\u51FA\u957F\u5EA6\u4E0A\u9650\u3002")),d=1)}}}return d}catch(s){return console.error(s instanceof Error?s.message:String(s)),1}finally{for(const s of y)s();await S(),await I()}}n(J,"runPrintMode");export{J as runPrintMode};
6
+ `);t.stopReason==="length"&&(console.error(l("\u56DE\u7B54\u88AB\u622A\u65AD\uFF1A\u6A21\u578B\u5DF2\u8FBE\u5230\u8F93\u51FA\u957F\u5EA6\u4E0A\u9650\u3002")),d=1)}}}return d}catch(s){return console.error(s instanceof Error?s.message:String(s)),1}finally{for(const s of y)s();await S(),await R()}}n(F,"runPrintMode");export{F as runPrintMode};
@@ -1 +1 @@
1
- var O=Object.defineProperty;var i=(u,o)=>O(u,"name",{value:o,configurable:!0});import*as p from"node:crypto";import{resolveExtensionNotify as N}from"../../core/extensions/index.js";import{DEFAULT_HOST_CALL_TIMEOUT_MS as $,getHostCapabilities as L,HostCallError as x,parseHostCapabilities as J}from"../../core/host-capabilities.js";import{flushRawStdout as W,takeOverStdout as j,waitForRawStdoutBackpressure as I,writeRawStdout as G}from"../../core/output-guard.js";import{killTrackedDetachedChildren as H}from"../../utils/shell.js";import{theme as z}from"../interactive/theme/theme.js";import{toJsonEvent as K}from"../json-event.js";import{applyEnvironmentUpdate as Q}from"./environment-update.js";import{attachJsonlLineReader as X,serializeJsonLine as Y}from"./jsonl.js";const Z="Prompt aborted before it started";async function ce(u){j();let o=u.session,k,S;const c=i(e=>{G(Y(e))},"output"),r=i((e,t,s)=>s===void 0?{id:e,type:"response",command:t,success:!0}:{id:e,type:"response",command:t,success:!0,data:s},"success"),d=i((e,t,s)=>({id:e,type:"response",command:t,success:!1,error:s}),"error"),m=new Map,b=new Map,q=i((e,t)=>{const s=p.randomUUID();return new Promise((n,a)=>{const l=i(()=>{clearTimeout(w),t.signal?.removeEventListener("abort",f),b.delete(s)},"cleanup"),y=i(g=>{l(),c({type:"host_request_cancelled",id:s}),a(g)},"giveUp"),f=i(()=>y(new x("aborted","host call aborted")),"onAbort"),w=setTimeout(()=>y(new x("timeout","host did not answer in time")),t.timeoutMs??$);t.signal?.addEventListener("abort",f,{once:!0}),b.set(s,{resolve:i(g=>{l(),n(g)},"resolve"),reject:i(g=>{l(),a(g)},"reject")});const v={type:"host_request",id:s,capability:e.capability,method:e.method,params:e.params};c(v)})},"rpcHostTransport");let E=!1,C=!1;const U=[];function h(e,t,s,n){if(e?.signal?.aborted)return Promise.resolve(t);const a=p.randomUUID();return new Promise((l,y)=>{let f;const w=i(()=>{f&&clearTimeout(f),e?.signal?.removeEventListener("abort",v),m.delete(a)},"cleanup"),v=i(()=>{w(),l(t)},"onAbort");e?.signal?.addEventListener("abort",v,{once:!0}),e?.timeout&&(f=setTimeout(()=>{w(),l(t)},e.timeout)),m.set(a,{resolve:i(g=>{w(),l(n(g))},"resolve"),reject:y}),c({type:"extension_ui_request",id:a,...s})})}i(h,"createDialogPromise");const F=i(()=>({select:i((e,t,s)=>h(s,void 0,{method:"select",title:e,options:t,timeout:s?.timeout},n=>"cancelled"in n&&n.cancelled?void 0:"value"in n?n.value:void 0),"select"),confirm:i((e,t,s)=>h(s,!1,{method:"confirm",title:e,message:t,timeout:s?.timeout},n=>"cancelled"in n&&n.cancelled?!1:"confirmed"in n?n.confirmed:!1),"confirm"),input:i((e,t,s)=>h(s,void 0,{method:"input",title:e,placeholder:t,timeout:s?.timeout},n=>"cancelled"in n&&n.cancelled?void 0:"value"in n?n.value:void 0),"input"),notify(e,t){const s=N(e,t);c({type:"extension_ui_request",id:p.randomUUID(),method:"notify",message:s.message,notifyType:s.type})},setPanel(e,t){c({type:"extension_ui_request",id:p.randomUUID(),method:"setPanel",panelId:e,panel:t})},requestInput:i(e=>h(e,void 0,{method:"requestInput",title:e.title,placeholder:e.placeholder,timeout:e.timeout},t=>"cancelled"in t&&t.cancelled?void 0:"value"in t?t.value:void 0),"requestInput"),requestChoice:i(e=>h(e,void 0,{method:"requestChoice",title:e.title,items:e.items,timeout:e.timeout},t=>"cancelled"in t&&t.cancelled?void 0:"value"in t?t.value:void 0),"requestChoice"),onTerminalInput(){return()=>{}},setStatus(e,t){c({type:"extension_ui_request",id:p.randomUUID(),method:"setStatus",statusKey:e,statusText:t})},setWorkingMessage(e){},setWorkingVisible(e){},setWorkingIndicator(e){},setHiddenThinkingLabel(e){},setWidget(e,t,s){(t===void 0||Array.isArray(t))&&c({type:"extension_ui_request",id:p.randomUUID(),method:"setWidget",widgetKey:e,widgetLines:t,widgetPlacement:s?.placement})},setFooter(e){},setHeader(e){},setTitle(e){c({type:"extension_ui_request",id:p.randomUUID(),method:"setTitle",title:e})},async custom(){},pasteToEditor(e){this.setEditorText(e)},setEditorText(e){c({type:"extension_ui_request",id:p.randomUUID(),method:"set_editor_text",text:e})},getEditorText(){return""},async editor(e,t){const s=p.randomUUID();return new Promise((n,a)=>{m.set(s,{resolve:i(l=>{"cancelled"in l&&l.cancelled?n(void 0):"value"in l?n(l.value):n(void 0)},"resolve"),reject:a}),c({type:"extension_ui_request",id:s,method:"editor",title:e,prefill:t})})},addAutocompleteProvider(){},setEditorComponent(){},getEditorComponent(){},get theme(){return z},getAllThemes(){return[]},getTheme(e){},setTheme(e){return{success:!1,error:"Theme switching not supported in RPC mode"}},getToolsExpanded(){return!1},setToolsExpanded(e){}}),"createExtensionUIContext");u.setRebindSession(async()=>{await _()});const _=i(async()=>{o=u.session,k?.(),S?.(),k=o.subscribe(e=>{c(K(e)),e.type==="agent_settled"&&R()}),S=o.agent.subscribe(async()=>{await I()}),await o.bindExtensions({uiContext:F(),mode:"rpc",commandContextActions:{waitForIdle:i(()=>o.waitForIdle(),"waitForIdle"),newSession:i(async e=>u.newSession(e),"newSession"),fork:i(async(e,t)=>({cancelled:(await u.fork(e,t)).cancelled}),"fork"),navigateTree:i(async(e,t)=>({cancelled:(await o.navigateTree(e,{summarize:t?.summarize,customInstructions:t?.customInstructions,replaceInstructions:t?.replaceInstructions,label:t?.label})).cancelled}),"navigateTree"),switchSession:i(async(e,t)=>u.switchSession(e,t),"switchSession"),reload:i(async()=>{await o.reload()},"reload")},shutdownHandler:i(()=>{E=!0},"shutdownHandler"),onError:i(e=>{c({type:"extension_error",extensionPath:e.extensionPath,event:e.event,error:e.error})},"onError")})},"rebindSession"),A=i(()=>{const e=["SIGTERM"];process.platform!=="win32"&&e.push("SIGHUP");for(const t of e){const s=i(()=>{H(),T(t==="SIGHUP"?129:143,t)},"handler");process.on(t,s),U.push(()=>process.off(t,s))}},"registerSignalHandlers");await _(),A();const D=i(async e=>{const t=e.id;switch(e.type){case"prompt":{let s=!1,n=!1;o.prompt(e.message,{images:e.images,streamingBehavior:e.streamingBehavior,source:"rpc",preflightResult:i(a=>{if(a==="cancelled"){n=!0;return}s=!0,c(r(t,"prompt",{disposition:a}))},"preflightResult")}).then(()=>{n&&!s&&c(d(t,"prompt",Z))},a=>{s||c(d(t,"prompt",a.message))});return}case"steer":{const s=await o.steer(e.message,e.images,{source:"rpc"});return r(t,"steer",{disposition:s})}case"follow_up":{const s=await o.followUp(e.message,e.images,{source:"rpc"});return r(t,"follow_up",{disposition:s})}case"abort":return await o.abort(),r(t,"abort");case"clear_queue":return r(t,"clear_queue",o.clearQueue());case"new_session":{const s=e.parentSession?{parentSession:e.parentSession}:void 0,n=await u.newSession(s);return n.cancelled||await _(),r(t,"new_session",n)}case"get_state":{const s={model:o.model,thinkingLevel:o.thinkingLevel,isStreaming:o.isStreaming,isCompacting:o.isCompacting,steeringMode:o.steeringMode,followUpMode:o.followUpMode,sessionFile:o.sessionFile,sessionId:o.sessionId,sessionName:o.sessionName,autoCompactionEnabled:o.autoCompactionEnabled,messageCount:o.messages.length,pendingMessageCount:o.pendingMessageCount};return r(t,"get_state",s)}case"set_model":{const n=o.modelRuntime.getAvailableSnapshot().find(a=>a.provider===e.provider&&a.id===e.modelId);return n?(await o.setModel(n),r(t,"set_model",n)):d(t,"set_model",`Model not found: ${e.provider}/${e.modelId}`)}case"cycle_model":{const s=await o.cycleModel();return s?r(t,"cycle_model",s):r(t,"cycle_model",null)}case"get_available_models":{const s=o.modelRuntime.getAvailableSnapshot();return r(t,"get_available_models",{models:s})}case"set_thinking_level":return o.setThinkingLevel(e.level),r(t,"set_thinking_level");case"cycle_thinking_level":{const s=o.cycleThinkingLevel();return s?r(t,"cycle_thinking_level",{level:s}):r(t,"cycle_thinking_level",null)}case"get_available_thinking_levels":{const s=o.getAvailableThinkingLevels();return r(t,"get_available_thinking_levels",{levels:s})}case"set_steering_mode":return o.setSteeringMode(e.mode),r(t,"set_steering_mode");case"set_follow_up_mode":return o.setFollowUpMode(e.mode),r(t,"set_follow_up_mode");case"compact":{const s=await o.compact(e.customInstructions);return r(t,"compact",s)}case"set_auto_compaction":return o.setAutoCompactionEnabled(e.enabled),r(t,"set_auto_compaction");case"set_auto_retry":return o.setAutoRetryEnabled(e.enabled),r(t,"set_auto_retry");case"abort_retry":return o.abortRetry(),r(t,"abort_retry");case"bash":{const s=await o.extensionRunner.emitUserBash({type:"user_bash",command:e.command,excludeFromContext:e.excludeFromContext??!1,cwd:o.sessionManager.getCwd()});if(s?.result)return o.recordBashResult(e.command,s.result,{excludeFromContext:e.excludeFromContext}),r(t,"bash",s.result);const n=await o.executeBash(e.command,void 0,{excludeFromContext:e.excludeFromContext,id:t,operations:s?.operations});return r(t,"bash",n)}case"abort_bash":return o.abortBash(),r(t,"abort_bash");case"get_sandbox_status":return r(t,"get_sandbox_status",o.getSandboxStatus()??null);case"list_background_processes":return r(t,"list_background_processes",{processes:o.backgroundProcesses.list()});case"read_background_process":{const{text:s,truncated:n,info:a}=o.backgroundProcesses.read(e.processId,e.tail!==void 0?{tail:e.tail}:{tail:200});return r(t,"read_background_process",{text:s,truncated:n,process:a})}case"stop_background_process":{const s=await o.backgroundProcesses.stop(e.processId);return r(t,"stop_background_process",{process:s})}case"get_session_stats":{const s=o.getSessionStats();return r(t,"get_session_stats",s)}case"export_html":{const s=await o.exportToHtml(e.outputPath);return r(t,"export_html",{path:s})}case"switch_session":{const s=await u.switchSession(e.sessionPath);return s.cancelled||await _(),r(t,"switch_session",s)}case"fork":{const s=await u.fork(e.entryId);return s.cancelled||await _(),r(t,"fork",{text:s.selectedText,cancelled:s.cancelled})}case"clone":{const s=o.sessionManager.getLeafId();if(!s)return d(t,"clone","Cannot clone session: no current entry selected");const n=await u.fork(s,{position:"at"});return n.cancelled||await _(),r(t,"clone",{cancelled:n.cancelled})}case"get_fork_messages":{const s=o.getUserMessagesForForking();return r(t,"get_fork_messages",{messages:s})}case"get_entries":{const s=o.sessionManager;let n=s.getEntries();if(e.since!==void 0){const a=n.findIndex(l=>l.id===e.since);if(a===-1)return d(t,"get_entries",`Entry not found: ${e.since}`);n=n.slice(a+1)}return r(t,"get_entries",{entries:n,leafId:s.getLeafId()})}case"get_tree":{const s=o.sessionManager;return r(t,"get_tree",{tree:s.getTree(),leafId:s.getLeafId()})}case"get_last_assistant_text":{const s=o.getLastAssistantText();return r(t,"get_last_assistant_text",{text:s})}case"set_session_name":{const s=e.name.trim();return s?(o.setSessionName(s),r(t,"set_session_name")):d(t,"set_session_name","Session name cannot be empty")}case"get_messages":return r(t,"get_messages",{messages:o.messages});case"get_commands":{const s=[];for(const n of o.extensionRunner.getRegisteredCommands())s.push({name:n.invocationName,description:n.description,source:"extension",sourceInfo:n.sourceInfo});for(const n of o.promptTemplates)s.push({name:n.name,description:n.description,source:"prompt",sourceInfo:n.sourceInfo});for(const n of o.resourceLoader.getSkills().skills)s.push({name:`skill:${n.name}`,description:n.description,source:"skill",sourceInfo:n.sourceInfo});return r(t,"get_commands",{commands:s})}case"set_host_capabilities":{const s=L();return s.set("rpc",J(e.capabilities),q),r(t,"set_host_capabilities",{capabilities:s.list()})}case"set_environment":{const s=Q({set:e.set,unset:e.unset});return r(t,"set_environment",{changed:s})}default:{const s=e;return d(t,s.type,`Unknown command: ${s.type}`)}}},"handleCommand");let M=i(()=>{},"detachInput");async function T(e=0,t){C&&process.exit(e),C=!0;for(const s of U)s();k?.(),S?.(),L().clear("rpc");for(const s of b.values())s.reject(new x("unavailable","RPC host disconnected"));await u.dispose(),M(),process.stdin.pause(),t!=="SIGTERM"&&await W(),process.exit(e)}i(T,"shutdown");async function R(){E&&await T()}i(R,"checkShutdownRequested");const B=i(async e=>{let t;try{t=JSON.parse(e)}catch(n){c(d(void 0,"parse",`Failed to parse command: ${n instanceof Error?n.message:String(n)}`)),await I();return}if(typeof t=="object"&&t!==null&&"type"in t&&t.type==="extension_ui_response"){const n=t,a=m.get(n.id);a&&(m.delete(n.id),a.resolve(n));return}if(typeof t=="object"&&t!==null&&"type"in t&&t.type==="host_response"){const n=t,a=b.get(n.id);a&&("error"in n?a.reject(new x("host_error",String(n.error))):a.resolve(n.result));return}const s=t;try{const n=await D(s);n&&(c(n),await I()),await R()}catch(n){c(d(s.id,s.type,n instanceof Error?n.message:String(n))),await I()}},"handleInputLine"),P=i(()=>{T()},"onInputEnd");return process.stdin.on("end",P),M=(()=>{const e=X(process.stdin,t=>{B(t)});return()=>{e(),process.stdin.off("end",P)}})(),new Promise(()=>{})}i(ce,"runRpcMode");export{Z as PROMPT_ABORTED_BEFORE_START,ce as runRpcMode};
1
+ var N=Object.defineProperty;var i=(u,o)=>N(u,"name",{value:o,configurable:!0});import*as p from"node:crypto";import{resolveExtensionNotify as O}from"../../core/extensions/index.js";import{DEFAULT_HOST_CALL_TIMEOUT_MS as G,getHostCapabilities as L,HostCallError as x,parseHostCapabilities as $}from"../../core/host-capabilities.js";import{flushRawStdout as J,takeOverStdout as W,waitForRawStdoutBackpressure as I,writeRawStdout as j}from"../../core/output-guard.js";import{killTrackedDetachedChildren as H}from"../../utils/shell.js";import{theme as z}from"../interactive/theme/theme.js";import{toJsonEvent as K}from"../json-event.js";import{applyEnvironmentUpdate as Q}from"./environment-update.js";import{attachJsonlLineReader as X,serializeJsonLine as Y}from"./jsonl.js";const Z="Prompt aborted before it started";async function ce(u){W();let o=u.session,k,S;const c=i(e=>{j(Y(e))},"output"),r=i((e,t,s)=>s===void 0?{id:e,type:"response",command:t,success:!0}:{id:e,type:"response",command:t,success:!0,data:s},"success"),d=i((e,t,s)=>({id:e,type:"response",command:t,success:!1,error:s}),"error"),m=new Map,b=new Map,q=i((e,t)=>{const s=p.randomUUID();return new Promise((n,a)=>{const l=i(()=>{clearTimeout(w),t.signal?.removeEventListener("abort",f),b.delete(s)},"cleanup"),y=i(g=>{l(),c({type:"host_request_cancelled",id:s}),a(g)},"giveUp"),f=i(()=>y(new x("aborted","host call aborted")),"onAbort"),w=setTimeout(()=>y(new x("timeout","host did not answer in time")),t.timeoutMs??G);t.signal?.addEventListener("abort",f,{once:!0}),b.set(s,{resolve:i(g=>{l(),n(g)},"resolve"),reject:i(g=>{l(),a(g)},"reject")});const v={type:"host_request",id:s,capability:e.capability,method:e.method,params:e.params};c(v)})},"rpcHostTransport");let E=!1,C=!1;const U=[];function h(e,t,s,n){if(e?.signal?.aborted)return Promise.resolve(t);const a=p.randomUUID();return new Promise((l,y)=>{let f;const w=i(()=>{f&&clearTimeout(f),e?.signal?.removeEventListener("abort",v),m.delete(a)},"cleanup"),v=i(()=>{w(),l(t)},"onAbort");e?.signal?.addEventListener("abort",v,{once:!0}),e?.timeout&&(f=setTimeout(()=>{w(),l(t)},e.timeout)),m.set(a,{resolve:i(g=>{w(),l(n(g))},"resolve"),reject:y}),c({type:"extension_ui_request",id:a,...s})})}i(h,"createDialogPromise");const F=i(()=>({select:i((e,t,s)=>h(s,void 0,{method:"select",title:e,options:t,timeout:s?.timeout},n=>"cancelled"in n&&n.cancelled?void 0:"value"in n?n.value:void 0),"select"),confirm:i((e,t,s)=>h(s,!1,{method:"confirm",title:e,message:t,timeout:s?.timeout},n=>"cancelled"in n&&n.cancelled?!1:"confirmed"in n?n.confirmed:!1),"confirm"),input:i((e,t,s)=>h(s,void 0,{method:"input",title:e,placeholder:t,timeout:s?.timeout},n=>"cancelled"in n&&n.cancelled?void 0:"value"in n?n.value:void 0),"input"),notify(e,t){const s=O(e,t);c({type:"extension_ui_request",id:p.randomUUID(),method:"notify",message:s.message,notifyType:s.type})},setPanel(e,t){c({type:"extension_ui_request",id:p.randomUUID(),method:"setPanel",panelId:e,panel:t})},requestInput:i(e=>h(e,void 0,{method:"requestInput",title:e.title,placeholder:e.placeholder,timeout:e.timeout},t=>"cancelled"in t&&t.cancelled?void 0:"value"in t?t.value:void 0),"requestInput"),requestChoice:i(e=>h(e,void 0,{method:"requestChoice",title:e.title,items:e.items,timeout:e.timeout},t=>"cancelled"in t&&t.cancelled?void 0:"value"in t?t.value:void 0),"requestChoice"),onTerminalInput(){return()=>{}},setStatus(e,t){c({type:"extension_ui_request",id:p.randomUUID(),method:"setStatus",statusKey:e,statusText:t})},setWorkingMessage(e){},setWorkingVisible(e){},setWorkingIndicator(e){},setHiddenThinkingLabel(e){},setWidget(e,t,s){(t===void 0||Array.isArray(t))&&c({type:"extension_ui_request",id:p.randomUUID(),method:"setWidget",widgetKey:e,widgetLines:t,widgetPlacement:s?.placement})},setFooter(e){},setHeader(e){},setTitle(e){c({type:"extension_ui_request",id:p.randomUUID(),method:"setTitle",title:e})},async custom(){},pasteToEditor(e){this.setEditorText(e)},setEditorText(e){c({type:"extension_ui_request",id:p.randomUUID(),method:"set_editor_text",text:e})},getEditorText(){return""},async editor(e,t){const s=p.randomUUID();return new Promise((n,a)=>{m.set(s,{resolve:i(l=>{"cancelled"in l&&l.cancelled?n(void 0):"value"in l?n(l.value):n(void 0)},"resolve"),reject:a}),c({type:"extension_ui_request",id:s,method:"editor",title:e,prefill:t})})},addAutocompleteProvider(){},setEditorComponent(){},getEditorComponent(){},get theme(){return z},getAllThemes(){return[]},getTheme(e){},setTheme(e){return{success:!1,error:"Theme switching not supported in RPC mode"}},getToolsExpanded(){return!1},setToolsExpanded(e){}}),"createExtensionUIContext");u.setRebindSession(async()=>{await _()});const _=i(async()=>{o=u.session,k?.(),S?.(),k=o.subscribe(e=>{c(K(e)),e.type==="agent_settled"&&R()}),S=o.agent.subscribe(async()=>{await I()}),await o.bindExtensions({uiContext:F(),mode:"rpc",commandContextActions:{waitForIdle:i(()=>o.waitForIdle(),"waitForIdle"),newSession:i(async e=>u.newSession(e),"newSession"),fork:i(async(e,t)=>({cancelled:(await u.fork(e,t)).cancelled}),"fork"),navigateTree:i(async(e,t)=>({cancelled:(await o.navigateTree(e,{summarize:t?.summarize,customInstructions:t?.customInstructions,replaceInstructions:t?.replaceInstructions,label:t?.label})).cancelled}),"navigateTree"),switchSession:i(async(e,t)=>u.switchSession(e,t),"switchSession"),reload:i(async()=>{await o.reload()},"reload")},shutdownHandler:i(()=>{E=!0},"shutdownHandler"),onError:i(e=>{c({type:"extension_error",extensionPath:e.extensionPath,event:e.event,error:e.error})},"onError")})},"rebindSession"),A=i(()=>{const e=["SIGTERM","SIGINT"];process.platform!=="win32"&&e.push("SIGHUP");for(const t of e){const s=i(()=>{H(),T(t==="SIGHUP"?129:t==="SIGINT"?130:143,t)},"handler");process.on(t,s),U.push(()=>process.off(t,s))}},"registerSignalHandlers");await _(),A();const D=i(async e=>{const t=e.id;switch(e.type){case"prompt":{let s=!1,n=!1;o.prompt(e.message,{images:e.images,streamingBehavior:e.streamingBehavior,source:"rpc",preflightResult:i(a=>{if(a==="cancelled"){n=!0;return}s=!0,c(r(t,"prompt",{disposition:a}))},"preflightResult")}).then(()=>{n&&!s&&c(d(t,"prompt",Z))},a=>{s||c(d(t,"prompt",a.message))});return}case"steer":{const s=await o.steer(e.message,e.images,{source:"rpc"});return r(t,"steer",{disposition:s})}case"follow_up":{const s=await o.followUp(e.message,e.images,{source:"rpc"});return r(t,"follow_up",{disposition:s})}case"abort":return await o.abort(),r(t,"abort");case"clear_queue":return r(t,"clear_queue",o.clearQueue());case"new_session":{const s=e.parentSession?{parentSession:e.parentSession}:void 0,n=await u.newSession(s);return n.cancelled||await _(),r(t,"new_session",n)}case"get_state":{const s={model:o.model,thinkingLevel:o.thinkingLevel,isStreaming:o.isStreaming,isCompacting:o.isCompacting,steeringMode:o.steeringMode,followUpMode:o.followUpMode,sessionFile:o.sessionFile,sessionId:o.sessionId,sessionName:o.sessionName,autoCompactionEnabled:o.autoCompactionEnabled,messageCount:o.messages.length,pendingMessageCount:o.pendingMessageCount};return r(t,"get_state",s)}case"set_model":{const n=o.modelRuntime.getAvailableSnapshot().find(a=>a.provider===e.provider&&a.id===e.modelId);return n?(await o.setModel(n),r(t,"set_model",n)):d(t,"set_model",`Model not found: ${e.provider}/${e.modelId}`)}case"cycle_model":{const s=await o.cycleModel();return s?r(t,"cycle_model",s):r(t,"cycle_model",null)}case"get_available_models":{const s=o.modelRuntime.getAvailableSnapshot();return r(t,"get_available_models",{models:s})}case"set_thinking_level":return o.setThinkingLevel(e.level),r(t,"set_thinking_level");case"cycle_thinking_level":{const s=o.cycleThinkingLevel();return s?r(t,"cycle_thinking_level",{level:s}):r(t,"cycle_thinking_level",null)}case"get_available_thinking_levels":{const s=o.getAvailableThinkingLevels();return r(t,"get_available_thinking_levels",{levels:s})}case"set_steering_mode":return o.setSteeringMode(e.mode),r(t,"set_steering_mode");case"set_follow_up_mode":return o.setFollowUpMode(e.mode),r(t,"set_follow_up_mode");case"compact":{const s=await o.compact(e.customInstructions);return r(t,"compact",s)}case"set_auto_compaction":return o.setAutoCompactionEnabled(e.enabled),r(t,"set_auto_compaction");case"set_auto_retry":return o.setAutoRetryEnabled(e.enabled),r(t,"set_auto_retry");case"abort_retry":return o.abortRetry(),r(t,"abort_retry");case"bash":{const s=await o.extensionRunner.emitUserBash({type:"user_bash",command:e.command,excludeFromContext:e.excludeFromContext??!1,cwd:o.sessionManager.getCwd()});if(s?.result)return o.recordBashResult(e.command,s.result,{excludeFromContext:e.excludeFromContext}),r(t,"bash",s.result);const n=await o.executeBash(e.command,void 0,{excludeFromContext:e.excludeFromContext,id:t,operations:s?.operations});return r(t,"bash",n)}case"abort_bash":return o.abortBash(),r(t,"abort_bash");case"get_sandbox_status":return r(t,"get_sandbox_status",o.getSandboxStatus()??null);case"list_background_processes":return r(t,"list_background_processes",{processes:o.backgroundProcesses.list()});case"read_background_process":{const{text:s,truncated:n,info:a}=o.backgroundProcesses.read(e.processId,e.tail!==void 0?{tail:e.tail}:{tail:200});return r(t,"read_background_process",{text:s,truncated:n,process:a})}case"stop_background_process":{const s=await o.backgroundProcesses.stop(e.processId);return r(t,"stop_background_process",{process:s})}case"get_session_stats":{const s=o.getSessionStats();return r(t,"get_session_stats",s)}case"export_html":{const s=await o.exportToHtml(e.outputPath);return r(t,"export_html",{path:s})}case"switch_session":{const s=await u.switchSession(e.sessionPath);return s.cancelled||await _(),r(t,"switch_session",s)}case"fork":{const s=await u.fork(e.entryId);return s.cancelled||await _(),r(t,"fork",{text:s.selectedText,cancelled:s.cancelled})}case"clone":{const s=o.sessionManager.getLeafId();if(!s)return d(t,"clone","Cannot clone session: no current entry selected");const n=await u.fork(s,{position:"at"});return n.cancelled||await _(),r(t,"clone",{cancelled:n.cancelled})}case"get_fork_messages":{const s=o.getUserMessagesForForking();return r(t,"get_fork_messages",{messages:s})}case"get_entries":{const s=o.sessionManager;let n=s.getEntries();if(e.since!==void 0){const a=n.findIndex(l=>l.id===e.since);if(a===-1)return d(t,"get_entries",`Entry not found: ${e.since}`);n=n.slice(a+1)}return r(t,"get_entries",{entries:n,leafId:s.getLeafId()})}case"get_tree":{const s=o.sessionManager;return r(t,"get_tree",{tree:s.getTree(),leafId:s.getLeafId()})}case"get_last_assistant_text":{const s=o.getLastAssistantText();return r(t,"get_last_assistant_text",{text:s})}case"set_session_name":{const s=e.name.trim();return s?(o.setSessionName(s),r(t,"set_session_name")):d(t,"set_session_name","Session name cannot be empty")}case"get_messages":return r(t,"get_messages",{messages:o.messages});case"get_commands":{const s=[];for(const n of o.extensionRunner.getRegisteredCommands())s.push({name:n.invocationName,description:n.description,source:"extension",sourceInfo:n.sourceInfo});for(const n of o.promptTemplates)s.push({name:n.name,description:n.description,source:"prompt",sourceInfo:n.sourceInfo});for(const n of o.resourceLoader.getSkills().skills)s.push({name:`skill:${n.name}`,description:n.description,source:"skill",sourceInfo:n.sourceInfo});return r(t,"get_commands",{commands:s})}case"set_host_capabilities":{const s=L();return s.set("rpc",$(e.capabilities),q),r(t,"set_host_capabilities",{capabilities:s.list()})}case"set_environment":{const s=Q({set:e.set,unset:e.unset});return r(t,"set_environment",{changed:s})}default:{const s=e;return d(t,s.type,`Unknown command: ${s.type}`)}}},"handleCommand");let M=i(()=>{},"detachInput");async function T(e=0,t){C&&process.exit(e),C=!0;for(const s of U)s();k?.(),S?.(),L().clear("rpc");for(const s of b.values())s.reject(new x("unavailable","RPC host disconnected"));await u.dispose(),M(),process.stdin.pause(),t!=="SIGTERM"&&await J(),process.exit(e)}i(T,"shutdown");async function R(){E&&await T()}i(R,"checkShutdownRequested");const B=i(async e=>{let t;try{t=JSON.parse(e)}catch(n){c(d(void 0,"parse",`Failed to parse command: ${n instanceof Error?n.message:String(n)}`)),await I();return}if(typeof t=="object"&&t!==null&&"type"in t&&t.type==="extension_ui_response"){const n=t,a=m.get(n.id);a&&(m.delete(n.id),a.resolve(n));return}if(typeof t=="object"&&t!==null&&"type"in t&&t.type==="host_response"){const n=t,a=b.get(n.id);a&&("error"in n?a.reject(new x("host_error",String(n.error))):a.resolve(n.result));return}const s=t;try{const n=await D(s);n&&(c(n),await I()),await R()}catch(n){c(d(s.id,s.type,n instanceof Error?n.message:String(n))),await I()}},"handleInputLine"),P=i(()=>{T()},"onInputEnd");return process.stdin.on("end",P),M=(()=>{const e=X(process.stdin,t=>{B(t)});return()=>{e(),process.stdin.off("end",P)}})(),new Promise(()=>{})}i(ce,"runRpcMode");export{Z as PROMPT_ABORTED_BEFORE_START,ce as runRpcMode};
@@ -0,0 +1,45 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 juicesharp
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
23
+ ---
24
+
25
+ MIT License
26
+
27
+ Copyright (c) 2025 Mario Zechner
28
+
29
+ Permission is hereby granted, free of charge, to any person obtaining a copy
30
+ of this software and associated documentation files (the "Software"), to deal
31
+ in the Software without restriction, including without limitation the rights
32
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
33
+ copies of the Software, and to permit persons to whom the Software is
34
+ furnished to do so, subject to the following conditions:
35
+
36
+ The above copyright notice and this permission notice shall be included in all
37
+ copies or substantial portions of the Software.
38
+
39
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
40
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
41
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
42
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
43
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
44
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
45
+ SOFTWARE.
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "@dalcode/dal-advisor",
3
+ "version": "1.0.40",
4
+ "private": true,
5
+ "description": "advisor: the model asks another strong model to review its current plan and point out risks. Adapted from @juicesharp/rpiv-advisor 2.13.8 (MIT).",
6
+ "license": "MIT",
7
+ "type": "module",
8
+ "main": "./src/index.js",
9
+ "exports": {
10
+ ".": "./src/index.js",
11
+ "./package.json": "./package.json"
12
+ },
13
+ "files": [
14
+ "src",
15
+ "LICENSE"
16
+ ],
17
+ "pi": {
18
+ "extensions": [
19
+ "./src/index.js"
20
+ ]
21
+ },
22
+ "dependencies": {
23
+ "@dalcode/dal-pi-kit": "1.0.40",
24
+ "@dalcode/dal-router": "1.0.40",
25
+ "typebox": "1.3.27"
26
+ },
27
+ "peerDependencies": {
28
+ "@earendil-works/pi-coding-agent": "^1.0.9"
29
+ },
30
+ "peerDependenciesMeta": {
31
+ "@earendil-works/pi-coding-agent": {
32
+ "optional": false
33
+ }
34
+ }
35
+ }
@@ -0,0 +1,22 @@
1
+ var D=Object.defineProperty;var a=(s,e)=>D(s,"name",{value:e,configurable:!0});var _=Object.defineProperty,i=a((s,e)=>_(s,"name",{value:e,configurable:!0}),"i");import{readFileSync as L}from"node:fs";import{join as N}from"node:path";import{t as I}from"@dalcode/dal-pi-kit";import{pickSecondOpinion as W,routerAdvisorPool as Y}from"@dalcode/dal-router/advisor";import{uuidv7 as B}from"@earendil-works/pi-ai";import{buildSessionContext as F,convertToLlm as U,getAgentDir as q,serializeConversation as G}from"@earendil-works/pi-coding-agent";import{Type as V}from"typebox";const p="advisor",y=3,X=24e4,z=2e3,$=`You are a senior engineer giving a second opinion to a coding assistant that is in the middle of a task.
2
+ You get the task and the conversation so far as a transcript (every tool call and result the assistant saw), plus the tools it can use.
3
+ Review its current approach. Answer with:
4
+ 1. The risks: wrong assumptions, steps that will fail, things it has not checked, a simpler or safer way it missed. Name files, commands and lines from the transcript.
5
+ 2. What to do next, as concrete steps; or say plainly that the approach is sound.
6
+ 3. When the task cannot be done safely as asked, say that it should stop and ask the user, and why.
7
+ You cannot run tools or change anything. Do not repeat the transcript. Be brief and direct; no preamble. Answer in the language of the user's task.`;function w(s=q()){try{const e=JSON.parse(L(N(s,"settings.json"),"utf8")).dalAdvisor,t=e?.maxCallsPerSession;return{...typeof e?.model=="string"&&e.model.includes("/")?{model:e.model}:{},maxCallsPerSession:typeof t=="number"&&Number.isInteger(t)&&t>=0?t:y}}catch{return{maxCallsPerSession:y}}}a(w,"L"),i(w,"readAdvisorSettings");function b(s){const e=new Set;s.model&&(e.add(s.model.id),e.add(`${s.model.provider}/${s.model.id}`));const t=s.sessionManager.getBranch();for(let n=t.length-1;n>=0;n--){const r=t[n];if(r.type==="message"&&r.message.role==="assistant"){e.add(r.message.model),e.add(`${r.message.provider}/${r.message.model}`);break}}return[...e]}a(b,"W"),i(b,"workingModels");function S(s,e){if(e.model){const o=e.model.indexOf("/");return s.modelRegistry.find(e.model.slice(0,o),e.model.slice(o+1))}const t=s.modelRegistry.getAvailable(),n=Y(),r=[];for(const o of t){const g=n?.find(l=>l.id===o.id&&l.provider===o.provider);n&&!g||r.push({provider:o.provider,id:o.id,reasoning:g?.reasoning??o.reasoning===!0,costPerMtok:g?.costPerMtok??(o.cost?.input??0)+(o.cost?.output??0),model:o})}return W(r,b(s))?.model}a(S,"Y"),i(S,"pickAdvisorModel");function R(s,e){if(s.length<=e)return s;const t=s.slice(-e),n=t.indexOf(`
8
+ `);return`[\u2026 earlier conversation omitted \u2026]
9
+ ${n>=0?t.slice(n+1):t}`}a(R,"V"),i(R,"keepTail");function k(s,e){return{role:"user",content:[{type:"text",text:[`## Tools the assistant can use
10
+
11
+ ${e.map(t=>`- ${t.name}: ${(t.description??"").split(`
12
+ `)[0].slice(0,160)}`).join(`
13
+ `)||"(none)"}`,`## Conversation so far
14
+
15
+ ${s||"(empty)"}`,`## Your review
16
+
17
+ Give your second opinion on the assistant's current approach now.`].join(`
18
+
19
+ `)}],timestamp:Date.now()}}a(k,"B"),i(k,"advisorRequest");function C(s){return s.content.filter(e=>e.type==="text").map(e=>e.text).join(`
20
+ `).trim()}a(C,"F"),i(C,"textOf");function P(s,e){return s?(s.input+=e.input,s.output+=e.output,s.cacheRead+=e.cacheRead,s.cacheWrite+=e.cacheWrite,s.totalTokens+=e.totalTokens,s.cost.input+=e.cost.input,s.cost.output+=e.cost.output,s.cost.cacheRead+=e.cost.cacheRead,s.cost.cacheWrite+=e.cost.cacheWrite,s.cost.total+=e.cost.total,s):structuredClone(e)}a(P,"X"),i(P,"addUsage");function T(s){return s.sessionManager.getBranch().filter(e=>e.type==="message"&&e.message.role==="toolResult"&&e.message.toolName===p&&!e.message.isError).length}a(T,"q"),i(T,"callsSoFar");function x(s={}){return i(function(e){const t=s.settings??(()=>w());e.on("session_start",async()=>{if(t().maxCallsPerSession>0)return;const n=e.getActiveTools();n.includes(p)&&e.setActiveTools(n.filter(r=>r!==p))}),e.registerTool({name:p,label:I("\u7B2C\u4E8C\u610F\u89C1"),description:"Ask another strong model to review your current approach and name its risks. No arguments: the conversation is sent automatically. Limited per session.",promptSnippet:"advisor - second opinion on the current plan from another strong model",promptGuidelines:["Use advisor only before a risky or hard-to-undo change, after repeated failures, or before finishing a complex task; tell the user its key point."],parameters:V.Object({}),async execute(n,r,o,g,l){const d=t(),h=T(l);if(d.maxCallsPerSession===0)throw new Error("advisor is turned off in the settings.");if(h>=d.maxCallsPerSession)throw new Error(`advisor was already used ${h} times in this session (limit ${d.maxCallsPerSession}); continue on your own judgment.`);const c=S(l,d);if(!c)throw new Error(d.model?`The advisor model ${d.model} is not available.`:"No other model is available for a second opinion; continue on your own judgment.");const{messages:M}=F(l.sessionManager.getEntries(),l.sessionManager.getLeafId()),O=R(G(U(M)),X),E=k(O,e.getAllTools()),f=`${c.provider}/${c.id}`;let m,v="";for(let A=0;A<2&&!v;A++){const u=await l.modelRegistry.complete(c,{systemPrompt:$,messages:[E]},{...o?{signal:o}:{},cacheRetention:"none",sessionId:B(),maxTokens:z});if(m=P(m,u.usage),u.stopReason==="aborted"||u.stopReason==="error")throw e.appendUsage(m,{kind:"advisor",provider:c.provider,model:c.id}),new Error(u.stopReason==="aborted"?"advisor call aborted":`advisor call to ${f} failed: ${u.errorMessage??"unknown error"}`);v=C(u)}const j={model:f,calls:h+1,limit:d.maxCallsPerSession};return{content:[{type:"text",text:v?`[Second opinion from ${f}; ${h+1}/${d.maxCallsPerSession} this session]
21
+
22
+ ${v}`:`${f} gave no answer.`}],details:j,...m?{usage:m}:{}}}})},"dalAdvisor")}a(x,"G"),i(x,"createDalAdvisor");var J=x();export{$ as ADVISOR_SYSTEM_PROMPT,p as ADVISOR_TOOL,y as DEFAULT_MAX_CALLS_PER_SESSION,k as advisorRequest,x as createDalAdvisor,J as default,S as pickAdvisorModel,w as readAdvisorSettings};
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dalcode/dal-bridge",
3
- "version": "1.0.39",
3
+ "version": "1.0.40",
4
4
  "private": true,
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
@@ -18,7 +18,7 @@
18
18
  ]
19
19
  },
20
20
  "dependencies": {
21
- "@dalcode/dal-pi-kit": "1.0.39",
21
+ "@dalcode/dal-pi-kit": "1.0.40",
22
22
  "typebox": "1.3.7"
23
23
  },
24
24
  "peerDependencies": {
@@ -1,4 +1,4 @@
1
- var P=Object.defineProperty;var d=(e,t)=>P(e,"name",{value:t,configurable:!0});var T=Object.defineProperty,F=d((e,t)=>T(e,"name",{value:t,configurable:!0}),"p");import{realpathSync as b,statSync as N}from"node:fs";import{extname as _,isAbsolute as O,relative as G,resolve as D}from"node:path";import{t as s}from"@dalcode/dal-pi-kit";import{Type as u}from"typebox";const z="dal:ask-user-thumbnail",S=20*1024,f=500,M=new Set([".png",".jpg",".jpeg",".gif",".webp",".svg"]),V=u.Object({id:u.Optional(u.String({description:s("\u9009\u9879 id\uFF08\u53EF\u9009\uFF0C\u9ED8\u8BA4 o1\u3001o2\u2026\uFF09")})),label:u.String({description:s("\u9009\u9879\u540D\u79F0")}),description:u.Optional(u.String({description:s("\u9009\u9879\u8BF4\u660E")})),recommended:u.Optional(u.Boolean({description:s("\u63A8\u8350\u9879\uFF1Bchoice / swatch \u6BCF\u9898\u81F3\u5C11\u4E00\u4E2A")})),thumbnail:u.Optional(u.String({description:s("\u7F29\u7565\u56FE\uFF0C\u7531\u7CFB\u7EDF\u6309\u771F\u5B9E\u7248\u5F0F\u7ED8\u5236\uFF1Atheme:default|business|tech|warm|minimal\uFF08PPT \u4E3B\u9898\u5C01\u9762\uFF09\u3001page:hero|split|dashboard\uFF08\u9875\u9762\u5E03\u5C40\uFF09\u3001doc:report|brief|handout\uFF08\u6587\u6863\u7248\u5F0F\uFF09")})),image:u.Optional(u.String({description:s("\u5F53\u524D\u5DE5\u4F5C\u76EE\u5F55\u5185\u7684\u56FE\u7247\u8DEF\u5F84\uFF0C\u4F5C\u4E3A\u9009\u9879\u9884\u89C8")})),colors:u.Optional(u.Array(u.String(),{description:s("swatch \u8272\u677F\uFF1A2\u20135 \u4E2A #RRGGBB")})),preview:u.Optional(u.String({description:s("\u9009\u9879\u9884\u89C8")}))}),W=u.Object({id:u.Optional(u.String({description:s("\u95EE\u9898 id\uFF08\u53EF\u9009\uFF0C\u9ED8\u8BA4 q1\u3001q2\u2026\uFF09\uFF1B\u7B54\u6848\u6309\u5B83\u56DE\u4F20")})),question:u.String({description:s("\u8981\u5411\u7528\u6237\u786E\u8BA4\u7684\u95EE\u9898")}),header:u.Optional(u.String({description:s("\u95EE\u9898\u6807\u9898")})),type:u.Optional(u.Union([u.Literal("choice"),u.Literal("swatch"),u.Literal("outline"),u.Literal("slider"),u.Literal("text")],{description:s("\u9898\u578B\uFF1Achoice \u9009\u9879\uFF08\u53EF\u914D\u7F29\u7565\u56FE\uFF09/ swatch \u914D\u8272\u8272\u677F / outline \u53EF\u62D6\u62FD\u6392\u5E8F\u7684\u5927\u7EB2 / slider \u6ED1\u6746\u6570\u503C / text \u81EA\u7531\u6587\u672C\u3002\u4E0D\u586B\u65F6\u6709 options \u4E3A choice")})),required:u.Optional(u.Boolean({description:s("\u662F\u5426\u5FC5\u7B54\uFF0C\u9ED8\u8BA4\u662F")})),options:u.Optional(u.Array(V,{description:s("choice / swatch \u7684\u9009\u9879\uFF0C2\u20136 \u4E2A")})),multiSelect:u.Optional(u.Boolean()),maxSelect:u.Optional(u.Integer({minimum:1,description:s("\u591A\u9009\u65F6\u6700\u591A\u9009\u51E0\u4E2A")})),layout:u.Optional(u.Union([u.Literal("list"),u.Literal("cards")],{description:s("cards \u4E3A\u7F29\u7565\u56FE\u5361\u7247\u7F51\u683C")})),allowOther:u.Optional(u.Boolean({description:s("\u9644\u52A0\u300C\u5176\u4ED6\uFF1A___\u300D\u81EA\u586B\u9879")})),items:u.Optional(u.Array(u.Object({id:u.Optional(u.String()),text:u.String()}),{description:s("outline \u7684\u6761\u76EE\uFF08\u5982 PPT \u6BCF\u9875\u6807\u9898\uFF09\uFF0C\u6700\u591A 15 \u6761\uFF0C\u987A\u5E8F\u5373\u63A8\u8350\u987A\u5E8F")})),allowEdit:u.Optional(u.Boolean()),allowAdd:u.Optional(u.Boolean()),allowRemove:u.Optional(u.Boolean()),min:u.Optional(u.Number()),max:u.Optional(u.Number()),step:u.Optional(u.Number()),value:u.Optional(u.Number({description:s("slider \u7684\u63A8\u8350\u503C")})),unit:u.Optional(u.String()),marks:u.Optional(u.Array(u.Object({value:u.Number(),label:u.String()}))),placeholder:u.Optional(u.String()),multiline:u.Optional(u.Boolean()),maxLength:u.Optional(u.Integer({minimum:1,maximum:f}))}),H=u.Object({title:u.Optional(u.String({description:s("\u5361\u7247\u6807\u9898\uFF0C\u5982\u300C\u5F00\u59CB\u505A PPT \u524D\u786E\u8BA4 3 \u4EF6\u4E8B\u300D")})),intent:u.Optional(u.Union([u.Literal("slides"),u.Literal("document"),u.Literal("sheet"),u.Literal("page"),u.Literal("other")])),subject:u.Optional(u.String({description:s("\u4F5C\u54C1\u6807\u9898\uFF0C\u753B\u5728\u4E3B\u9898\u7F29\u7565\u56FE\u7684\u5C01\u9762\u4E0A")})),questions:u.Array(W,{minItems:1,maxItems:3,description:s("\u4E00\u6B21\u6700\u591A 3 \u4E2A\u95EE\u9898")})});class q extends Error{static{d(this,"B")}static{F(this,"AskUserInputError")}}function A(e,t){let i=s(e);for(const[o,a]of Object.entries(t))i=i.replaceAll(`{${o}}`,String(a));throw new q(i)}d(A,"h"),F(A,"fail");const Y=new Set(["svg","g","rect","circle","ellipse","line","path","polygon","polyline","text","tspan"]),Z=new Set(["xmlns","viewBox","width","height","x","y","x1","y1","x2","y2","cx","cy","r","rx","ry","d","points","transform","fill","fill-opacity","stroke","stroke-width","stroke-opacity","opacity","font-size","font-weight","font-family","text-anchor","dx","dy"]);function v(e){if(Buffer.byteLength(e,"utf8")>S||/<!|<\?|&(?!amp;|lt;|gt;|quot;|apos;|#\d+;|#x[0-9a-fA-F]+;)/.test(e))return;const t=/<\/?([A-Za-z][\w:-]*)((?:\s+[\w:-]+\s*=\s*"[^"<]*")*)\s*\/?>/g;let i=0;for(let o=t.exec(e);o!==null;o=t.exec(e)){if(e.slice(i,o.index).includes("<")||(i=o.index+o[0].length,!Y.has(o[1])))return;for(const a of o[2].matchAll(/([\w:-]+)\s*=\s*"([^"]*)"/g))if(!Z.has(a[1])||/url\s*\(|javascript:|expression\s*\(/i.test(a[2]))return}if(!e.slice(i).includes("<"))return/^\s*<svg[\s>]/.test(e)?e:void 0}d(v,"N"),F(v,"sanitizeSvg");function k(e,t){const i=G(e,t);return i===""||!i.startsWith("..")&&!O(i)}d(k,"_"),F(k,"isInside");function $(e,t){const i=O(t)?D(t):D(e,t);let o;try{o=b(i)}catch{A("\u9884\u89C8\u56FE\u7247\u4E0D\u5B58\u5728\uFF1A{path}",{path:t})}return(!k(b(e),o)||!N(o).isFile())&&A("\u9884\u89C8\u56FE\u7247\u5FC5\u987B\u662F\u5F53\u524D\u5DE5\u4F5C\u76EE\u5F55\u5185\u7684\u6587\u4EF6\uFF1A{path}",{path:t}),M.has(_(o).toLowerCase())||A("\u9884\u89C8\u56FE\u7247\u683C\u5F0F\u4E0D\u652F\u6301\uFF1A{path}",{path:t}),{kind:"image",path:o}}d($,"Q"),F($,"imagePreview");function w(e,t,i){const o=(e??"").trim().slice(0,64)||t;let a=o;for(let l=2;i.has(a);l++)a=`${o}-${l}`;return i.add(a),a}d(w,"y"),F(w,"uniqueId");function C(e,t,i,o,a,l){const r=e.options??[];(r.length<2||r.length>6)&&A("\u300C{q}\u300D\u9700\u8981 2\u20136 \u4E2A\u9009\u9879",{q:t}),r.some(n=>n.recommended===!0)||A("\u300C{q}\u300D\u6CA1\u6709\u63A8\u8350\u9879\uFF1A\u8BF7\u628A\u4F60\u63A8\u8350\u7684\u9009\u9879\u6807\u4E0A recommended: true",{q:t});const p=new Set;return r.map((n,c)=>{const m={id:w(n.id,`o${c+1}`,p),label:n.label.trim().slice(0,200)||`${c+1}`,...n.description?.trim()?{description:n.description.trim().slice(0,1e3)}:{},...n.recommended===!0?{recommended:!0}:{}};if(l){const E=n.colors??[];(E.length<2||E.length>5||!E.every(g=>/^#[0-9A-Fa-f]{6}$/.test(g)))&&A("\u300C{q}\u300D\u7684\u8272\u677F\u9009\u9879\u300C{o}\u300D\u9700\u8981 2\u20135 \u4E2A #RRGGBB \u989C\u8272",{q:t,o:m.label}),m.colors=E.map(g=>g.toUpperCase())}let h;if(n.thumbnail){const E=a(n.thumbnail.trim(),o),g=E===void 0?void 0:v(E);g!==void 0&&(h={kind:"svg",svg:g})}return!h&&n.image&&(h=$(i,n.image)),!h&&n.preview?.trim()&&(h={kind:"text",text:n.preview.slice(0,4e3)}),h&&(m.preview=h),m})}d(C,"S"),F(C,"buildOptions");function L(e){return e.type?e.type:e.options&&e.options.length>0?e.options.every(t=>(t.colors?.length??0)>0)?"swatch":"choice":e.items&&e.items.length>0?"outline":e.value!==void 0&&e.min!==void 0&&e.max!==void 0?"slider":"text"}d(L,"C"),F(L,"inferType");function j(e,t,i,o,a){switch(L(e)){case"choice":{const l=C(e,t,i,o,a,!1),r=e.multiSelect===!0;e.maxSelect!==void 0&&(!r||e.maxSelect>l.length)&&A("\u300C{q}\u300D\u7684 maxSelect \u53EA\u7528\u4E8E\u591A\u9009\uFF0C\u4E14\u4E0D\u80FD\u8D85\u8FC7\u9009\u9879\u6570",{q:t});const p=l.some(c=>c.preview?.kind==="svg"||c.preview?.kind==="image"),n=e.layout??(p?"cards":void 0);return{type:"choice",...r?{multi:!0}:{},...e.maxSelect!==void 0?{max:e.maxSelect}:{},...n?{layout:n}:{},options:l}}case"swatch":return{type:"swatch",options:C(e,t,i,o,a,!0)};case"outline":{const l=(e.items??[]).filter(p=>p.text.trim()!=="");(l.length<1||l.length>15)&&A("\u300C{q}\u300D\u7684\u5927\u7EB2\u9700\u8981 1\u201315 \u6761",{q:t});const r=new Set;return{type:"outline",items:l.map((p,n)=>({id:w(p.id,`i${n+1}`,r),text:p.text.trim().slice(0,500)})),allowEdit:e.allowEdit??!0,allowAdd:e.allowAdd??!0,allowRemove:e.allowRemove??!0}}case"slider":{const{min:l,max:r,value:p}=e,n=e.step??1;return(l===void 0||r===void 0||p===void 0)&&A("\u300C{q}\u300D\u7684\u6ED1\u6746\u9700\u8981 min\u3001max \u548C\u63A8\u8350\u503C value",{q:t}),(!(l<r)||!(n>0)||p<l||p>r)&&A("\u300C{q}\u300D\u7684\u6ED1\u6746\u53D6\u503C\u4E0D\u5408\u7406\uFF1A\u9700\u8981 min < max\u3001step > 0\u3001min \u2264 value \u2264 max",{q:t}),{type:"slider",min:l,max:r,step:n,value:p,...e.unit?{unit:e.unit.slice(0,16)}:{},...e.marks&&e.marks.length>0?{marks:e.marks.filter(c=>c.value>=l&&c.value<=r).slice(0,11).map(c=>({value:c.value,label:c.label.slice(0,40)}))}:{}}}default:return{type:"text",...e.placeholder?{placeholder:e.placeholder.slice(0,200)}:{},...e.multiline?{multiline:!0}:{},maxLength:Math.min(e.maxLength??f,f)}}}d(j,"G"),F(j,"buildControl");function U(e,t,i){(e.questions.length<1||e.questions.length>3)&&A("\u4E00\u6B21\u53EA\u80FD\u95EE 1\u20133 \u4E2A\u95EE\u9898",{});const o=new Set,a=e.subject?.trim()||void 0,l=e.questions.map((r,p)=>{const n=r.question.trim().slice(0,500);n===""&&A("\u7B2C {n} \u4E2A\u95EE\u9898\u662F\u7A7A\u7684",{n:p+1});const c=r.header?.trim().slice(0,60)||void 0,m=j(r,c??n,t,a,i),h=m.type==="choice"||m.type==="swatch";return{id:w(r.id,`q${p+1}`,o),question:n,...c?{header:c}:{},...r.required===!1?{required:!1}:{},control:m,...h&&r.allowOther?{allowOther:!0}:{},options:h?m.options.map(E=>({label:E.label,description:E.description??E.label,...E.preview?.kind==="text"?{preview:E.preview.text}:{}})):[],multiSelect:m.type==="choice"&&m.multi===!0}});return{version:2,...e.intent?{intent:e.intent}:{},...e.title?.trim()?{title:e.title.trim().slice(0,120)}:{},questions:l}}d(U,"Z"),F(U,"buildAskUserRequest");function x(e,t){const i=e.type==="choice"||e.type==="swatch"?e.options:[];return t.map(o=>i.find(a=>a.id===o)?.label??o).join(", ")}d(x,"k"),F(x,"labelsFor");function y(e){return e.map((t,i)=>`${i+1}. ${t.text}`).join(" ")}d(y,"A"),F(y,"numbered");function B(e){const t=e.control;switch(t.type){case"choice":case"swatch":return x(t,t.options.filter(i=>i.recommended).map(i=>i.id));case"outline":return y(t.items);case"slider":return`${t.value}${t.unit??""}`;default:return}}d(B,"V"),F(B,"recommendedAnswer");function R(e,t){return"choice"in t?x(e.control,t.choice):"other"in t?`${s("\u5176\u4ED6\uFF1A")}${t.other}`:"outline"in t?y(t.outline):"value"in t?`${t.value}${e.control.type==="slider"?e.control.unit??"":""}`:"text"in t?t.text:""}d(R,"M"),F(R,"answerText");function I(e,t){const i=[],o=[],a=[],l=t.structured?.answers;if(l)for(const n of e.questions){const c=n.header??n.question,m=l[n.id];if(!m||"skipped"in m){const h=B(n);o.push(c),a.push(`- ${c}: ${h??"(no recommendation, your call)"}`),i.push(`- ${c}: ${h?`${h} (skipped \u2192 recommended)`:"(skipped \u2192 your call)"}`);continue}i.push(`- ${c}: ${R(n,m)}`)}else for(const[n,c]of Object.entries(t.answers??{}))i.push(`- ${n}: ${c}`);const r=t.summary?.trim();let p=r?`User answers: ${r}${a.length>0?`
1
+ var P=Object.defineProperty;var d=(e,t)=>P(e,"name",{value:t,configurable:!0});var T=Object.defineProperty,F=d((e,t)=>T(e,"name",{value:t,configurable:!0}),"p");import{realpathSync as O,statSync as N}from"node:fs";import{extname as _,isAbsolute as b,relative as G,resolve as D}from"node:path";import{t as s}from"@dalcode/dal-pi-kit";import{Type as u}from"typebox";const z="dal:ask-user-thumbnail",S=20*1024,f=500,M=new Set([".png",".jpg",".jpeg",".gif",".webp",".svg"]),V=u.Object({id:u.Optional(u.String({description:s("\u9009\u9879 id\uFF08\u53EF\u9009\uFF0C\u9ED8\u8BA4 o1\u3001o2\u2026\uFF09")})),label:u.String({description:s("\u9009\u9879\u540D\u79F0")}),description:u.Optional(u.String({description:s("\u9009\u9879\u8BF4\u660E")})),recommended:u.Optional(u.Boolean({description:s("\u63A8\u8350\u9879\uFF1Bchoice / swatch \u6BCF\u9898\u81F3\u5C11\u4E00\u4E2A")})),thumbnail:u.Optional(u.String({description:s("\u7F29\u7565\u56FE\uFF0C\u7531\u7CFB\u7EDF\u6309\u771F\u5B9E\u7248\u5F0F\u7ED8\u5236\uFF1Atheme:consulting|keynote|minimal|education|gov\uFF08PPT \u98CE\u683C\u5C01\u9762\uFF09\u3001page:hero|split|dashboard\uFF08\u9875\u9762\u5E03\u5C40\uFF09\u3001doc:report|brief|handout\uFF08\u6587\u6863\u7248\u5F0F\uFF09")})),image:u.Optional(u.String({description:s("\u5F53\u524D\u5DE5\u4F5C\u76EE\u5F55\u5185\u7684\u56FE\u7247\u8DEF\u5F84\uFF0C\u4F5C\u4E3A\u9009\u9879\u9884\u89C8")})),colors:u.Optional(u.Array(u.String(),{description:s("swatch \u8272\u677F\uFF1A2\u20135 \u4E2A #RRGGBB")})),preview:u.Optional(u.String({description:s("\u9009\u9879\u9884\u89C8")}))}),W=u.Object({id:u.Optional(u.String({description:s("\u95EE\u9898 id\uFF08\u53EF\u9009\uFF0C\u9ED8\u8BA4 q1\u3001q2\u2026\uFF09\uFF1B\u7B54\u6848\u6309\u5B83\u56DE\u4F20")})),question:u.String({description:s("\u8981\u5411\u7528\u6237\u786E\u8BA4\u7684\u95EE\u9898")}),header:u.Optional(u.String({description:s("\u95EE\u9898\u6807\u9898")})),type:u.Optional(u.Union([u.Literal("choice"),u.Literal("swatch"),u.Literal("outline"),u.Literal("slider"),u.Literal("text")],{description:s("\u9898\u578B\uFF1Achoice \u9009\u9879\uFF08\u53EF\u914D\u7F29\u7565\u56FE\uFF09/ swatch \u914D\u8272\u8272\u677F / outline \u53EF\u62D6\u62FD\u6392\u5E8F\u7684\u5927\u7EB2 / slider \u6ED1\u6746\u6570\u503C / text \u81EA\u7531\u6587\u672C\u3002\u4E0D\u586B\u65F6\u6709 options \u4E3A choice")})),required:u.Optional(u.Boolean({description:s("\u662F\u5426\u5FC5\u7B54\uFF0C\u9ED8\u8BA4\u662F")})),options:u.Optional(u.Array(V,{description:s("choice / swatch \u7684\u9009\u9879\uFF0C2\u20136 \u4E2A")})),multiSelect:u.Optional(u.Boolean()),maxSelect:u.Optional(u.Integer({minimum:1,description:s("\u591A\u9009\u65F6\u6700\u591A\u9009\u51E0\u4E2A")})),layout:u.Optional(u.Union([u.Literal("list"),u.Literal("cards")],{description:s("cards \u4E3A\u7F29\u7565\u56FE\u5361\u7247\u7F51\u683C")})),allowOther:u.Optional(u.Boolean({description:s("\u9644\u52A0\u300C\u5176\u4ED6\uFF1A___\u300D\u81EA\u586B\u9879")})),items:u.Optional(u.Array(u.Object({id:u.Optional(u.String()),text:u.String()}),{description:s("outline \u7684\u6761\u76EE\uFF08\u5982 PPT \u6BCF\u9875\u6807\u9898\uFF09\uFF0C\u6700\u591A 15 \u6761\uFF0C\u987A\u5E8F\u5373\u63A8\u8350\u987A\u5E8F")})),allowEdit:u.Optional(u.Boolean()),allowAdd:u.Optional(u.Boolean()),allowRemove:u.Optional(u.Boolean()),min:u.Optional(u.Number()),max:u.Optional(u.Number()),step:u.Optional(u.Number()),value:u.Optional(u.Number({description:s("slider \u7684\u63A8\u8350\u503C")})),unit:u.Optional(u.String()),marks:u.Optional(u.Array(u.Object({value:u.Number(),label:u.String()}))),placeholder:u.Optional(u.String()),multiline:u.Optional(u.Boolean()),maxLength:u.Optional(u.Integer({minimum:1,maximum:f}))}),H=u.Object({title:u.Optional(u.String({description:s("\u5361\u7247\u6807\u9898\uFF0C\u5982\u300C\u5F00\u59CB\u505A PPT \u524D\u786E\u8BA4 3 \u4EF6\u4E8B\u300D")})),intent:u.Optional(u.Union([u.Literal("slides"),u.Literal("document"),u.Literal("sheet"),u.Literal("page"),u.Literal("other")])),subject:u.Optional(u.String({description:s("\u4F5C\u54C1\u6807\u9898\uFF0C\u753B\u5728\u4E3B\u9898\u7F29\u7565\u56FE\u7684\u5C01\u9762\u4E0A")})),questions:u.Array(W,{minItems:1,maxItems:3,description:s("\u4E00\u6B21\u6700\u591A 3 \u4E2A\u95EE\u9898")})});class q extends Error{static{d(this,"B")}static{F(this,"AskUserInputError")}}function A(e,t){let i=s(e);for(const[o,a]of Object.entries(t))i=i.replaceAll(`{${o}}`,String(a));throw new q(i)}d(A,"h"),F(A,"fail");const Y=new Set(["svg","g","rect","circle","ellipse","line","path","polygon","polyline","text","tspan"]),Z=new Set(["xmlns","viewBox","width","height","x","y","x1","y1","x2","y2","cx","cy","r","rx","ry","d","points","transform","fill","fill-opacity","stroke","stroke-width","stroke-opacity","opacity","font-size","font-weight","font-family","text-anchor","dx","dy"]);function v(e){if(Buffer.byteLength(e,"utf8")>S||/<!|<\?|&(?!amp;|lt;|gt;|quot;|apos;|#\d+;|#x[0-9a-fA-F]+;)/.test(e))return;const t=/<\/?([A-Za-z][\w:-]*)((?:\s+[\w:-]+\s*=\s*"[^"<]*")*)\s*\/?>/g;let i=0;for(let o=t.exec(e);o!==null;o=t.exec(e)){if(e.slice(i,o.index).includes("<")||(i=o.index+o[0].length,!Y.has(o[1])))return;for(const a of o[2].matchAll(/([\w:-]+)\s*=\s*"([^"]*)"/g))if(!Z.has(a[1])||/url\s*\(|javascript:|expression\s*\(/i.test(a[2]))return}if(!e.slice(i).includes("<"))return/^\s*<svg[\s>]/.test(e)?e:void 0}d(v,"N"),F(v,"sanitizeSvg");function k(e,t){const i=G(e,t);return i===""||!i.startsWith("..")&&!b(i)}d(k,"_"),F(k,"isInside");function $(e,t){const i=b(t)?D(t):D(e,t);let o;try{o=O(i)}catch{A("\u9884\u89C8\u56FE\u7247\u4E0D\u5B58\u5728\uFF1A{path}",{path:t})}return(!k(O(e),o)||!N(o).isFile())&&A("\u9884\u89C8\u56FE\u7247\u5FC5\u987B\u662F\u5F53\u524D\u5DE5\u4F5C\u76EE\u5F55\u5185\u7684\u6587\u4EF6\uFF1A{path}",{path:t}),M.has(_(o).toLowerCase())||A("\u9884\u89C8\u56FE\u7247\u683C\u5F0F\u4E0D\u652F\u6301\uFF1A{path}",{path:t}),{kind:"image",path:o}}d($,"Q"),F($,"imagePreview");function w(e,t,i){const o=(e??"").trim().slice(0,64)||t;let a=o;for(let l=2;i.has(a);l++)a=`${o}-${l}`;return i.add(a),a}d(w,"y"),F(w,"uniqueId");function C(e,t,i,o,a,l){const r=e.options??[];(r.length<2||r.length>6)&&A("\u300C{q}\u300D\u9700\u8981 2\u20136 \u4E2A\u9009\u9879",{q:t}),r.some(n=>n.recommended===!0)||A("\u300C{q}\u300D\u6CA1\u6709\u63A8\u8350\u9879\uFF1A\u8BF7\u628A\u4F60\u63A8\u8350\u7684\u9009\u9879\u6807\u4E0A recommended: true",{q:t});const p=new Set;return r.map((n,c)=>{const m={id:w(n.id,`o${c+1}`,p),label:n.label.trim().slice(0,200)||`${c+1}`,...n.description?.trim()?{description:n.description.trim().slice(0,1e3)}:{},...n.recommended===!0?{recommended:!0}:{}};if(l){const E=n.colors??[];(E.length<2||E.length>5||!E.every(g=>/^#[0-9A-Fa-f]{6}$/.test(g)))&&A("\u300C{q}\u300D\u7684\u8272\u677F\u9009\u9879\u300C{o}\u300D\u9700\u8981 2\u20135 \u4E2A #RRGGBB \u989C\u8272",{q:t,o:m.label}),m.colors=E.map(g=>g.toUpperCase())}let h;if(n.thumbnail){const E=a(n.thumbnail.trim(),o),g=E===void 0?void 0:v(E);g!==void 0&&(h={kind:"svg",svg:g})}return!h&&n.image&&(h=$(i,n.image)),!h&&n.preview?.trim()&&(h={kind:"text",text:n.preview.slice(0,4e3)}),h&&(m.preview=h),m})}d(C,"S"),F(C,"buildOptions");function L(e){return e.type?e.type:e.options&&e.options.length>0?e.options.every(t=>(t.colors?.length??0)>0)?"swatch":"choice":e.items&&e.items.length>0?"outline":e.value!==void 0&&e.min!==void 0&&e.max!==void 0?"slider":"text"}d(L,"C"),F(L,"inferType");function j(e,t,i,o,a){switch(L(e)){case"choice":{const l=C(e,t,i,o,a,!1),r=e.multiSelect===!0;e.maxSelect!==void 0&&(!r||e.maxSelect>l.length)&&A("\u300C{q}\u300D\u7684 maxSelect \u53EA\u7528\u4E8E\u591A\u9009\uFF0C\u4E14\u4E0D\u80FD\u8D85\u8FC7\u9009\u9879\u6570",{q:t});const p=l.some(c=>c.preview?.kind==="svg"||c.preview?.kind==="image"),n=e.layout??(p?"cards":void 0);return{type:"choice",...r?{multi:!0}:{},...e.maxSelect!==void 0?{max:e.maxSelect}:{},...n?{layout:n}:{},options:l}}case"swatch":return{type:"swatch",options:C(e,t,i,o,a,!0)};case"outline":{const l=(e.items??[]).filter(p=>p.text.trim()!=="");(l.length<1||l.length>15)&&A("\u300C{q}\u300D\u7684\u5927\u7EB2\u9700\u8981 1\u201315 \u6761",{q:t});const r=new Set;return{type:"outline",items:l.map((p,n)=>({id:w(p.id,`i${n+1}`,r),text:p.text.trim().slice(0,500)})),allowEdit:e.allowEdit??!0,allowAdd:e.allowAdd??!0,allowRemove:e.allowRemove??!0}}case"slider":{const{min:l,max:r,value:p}=e,n=e.step??1;return(l===void 0||r===void 0||p===void 0)&&A("\u300C{q}\u300D\u7684\u6ED1\u6746\u9700\u8981 min\u3001max \u548C\u63A8\u8350\u503C value",{q:t}),(!(l<r)||!(n>0)||p<l||p>r)&&A("\u300C{q}\u300D\u7684\u6ED1\u6746\u53D6\u503C\u4E0D\u5408\u7406\uFF1A\u9700\u8981 min < max\u3001step > 0\u3001min \u2264 value \u2264 max",{q:t}),{type:"slider",min:l,max:r,step:n,value:p,...e.unit?{unit:e.unit.slice(0,16)}:{},...e.marks&&e.marks.length>0?{marks:e.marks.filter(c=>c.value>=l&&c.value<=r).slice(0,11).map(c=>({value:c.value,label:c.label.slice(0,40)}))}:{}}}default:return{type:"text",...e.placeholder?{placeholder:e.placeholder.slice(0,200)}:{},...e.multiline?{multiline:!0}:{},maxLength:Math.min(e.maxLength??f,f)}}}d(j,"G"),F(j,"buildControl");function U(e,t,i){(e.questions.length<1||e.questions.length>3)&&A("\u4E00\u6B21\u53EA\u80FD\u95EE 1\u20133 \u4E2A\u95EE\u9898",{});const o=new Set,a=e.subject?.trim()||void 0,l=e.questions.map((r,p)=>{const n=r.question.trim().slice(0,500);n===""&&A("\u7B2C {n} \u4E2A\u95EE\u9898\u662F\u7A7A\u7684",{n:p+1});const c=r.header?.trim().slice(0,60)||void 0,m=j(r,c??n,t,a,i),h=m.type==="choice"||m.type==="swatch";return{id:w(r.id,`q${p+1}`,o),question:n,...c?{header:c}:{},...r.required===!1?{required:!1}:{},control:m,...h&&r.allowOther?{allowOther:!0}:{},options:h?m.options.map(E=>({label:E.label,description:E.description??E.label,...E.preview?.kind==="text"?{preview:E.preview.text}:{}})):[],multiSelect:m.type==="choice"&&m.multi===!0}});return{version:2,...e.intent?{intent:e.intent}:{},...e.title?.trim()?{title:e.title.trim().slice(0,120)}:{},questions:l}}d(U,"Z"),F(U,"buildAskUserRequest");function x(e,t){const i=e.type==="choice"||e.type==="swatch"?e.options:[];return t.map(o=>i.find(a=>a.id===o)?.label??o).join(", ")}d(x,"k"),F(x,"labelsFor");function y(e){return e.map((t,i)=>`${i+1}. ${t.text}`).join(" ")}d(y,"A"),F(y,"numbered");function B(e){const t=e.control;switch(t.type){case"choice":case"swatch":return x(t,t.options.filter(i=>i.recommended).map(i=>i.id));case"outline":return y(t.items);case"slider":return`${t.value}${t.unit??""}`;default:return}}d(B,"V"),F(B,"recommendedAnswer");function R(e,t){return"choice"in t?x(e.control,t.choice):"other"in t?`${s("\u5176\u4ED6\uFF1A")}${t.other}`:"outline"in t?y(t.outline):"value"in t?`${t.value}${e.control.type==="slider"?e.control.unit??"":""}`:"text"in t?t.text:""}d(R,"M"),F(R,"answerText");function I(e,t){const i=[],o=[],a=[],l=t.structured?.answers;if(l)for(const n of e.questions){const c=n.header??n.question,m=l[n.id];if(!m||"skipped"in m){const h=B(n);o.push(c),a.push(`- ${c}: ${h??"(no recommendation, your call)"}`),i.push(`- ${c}: ${h?`${h} (skipped \u2192 recommended)`:"(skipped \u2192 your call)"}`);continue}i.push(`- ${c}: ${R(n,m)}`)}else for(const[n,c]of Object.entries(t.answers??{}))i.push(`- ${n}: ${c}`);const r=t.summary?.trim();let p=r?`User answers: ${r}${a.length>0?`
2
2
  Recommended options for the skipped questions:
3
3
  ${a.join(`
4
4
  `)}`:""}`:`User answers:
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Mario Zechner
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "@dalcode/dal-capabilities",
3
+ "version": "1.0.40",
4
+ "private": true,
5
+ "description": "Capability center for DAL: switches on the reviewed MCP connectors, skills and engine packages a task needs (installed automatically from the signed DAL market), with /capabilities to list, disable and enable them.",
6
+ "license": "MIT",
7
+ "type": "module",
8
+ "main": "./src/index.js",
9
+ "exports": {
10
+ ".": "./src/index.js",
11
+ "./catalogue": "./src/catalogue.js",
12
+ "./match": "./src/match.js",
13
+ "./install": "./src/install.js",
14
+ "./state": "./src/state.js",
15
+ "./package.json": "./package.json"
16
+ },
17
+ "files": [
18
+ "src"
19
+ ],
20
+ "pi": {
21
+ "extensions": [
22
+ "./src/index.js"
23
+ ]
24
+ },
25
+ "dependencies": {
26
+ "@dalcode/dal-mcp": "1.0.40",
27
+ "@dalcode/dal-pi-kit": "1.0.40",
28
+ "@dalcode/deepailab": "1.0.40"
29
+ },
30
+ "peerDependencies": {
31
+ "@earendil-works/pi-coding-agent": "^1.0.9"
32
+ },
33
+ "peerDependenciesMeta": {
34
+ "@earendil-works/pi-coding-agent": {
35
+ "optional": false
36
+ }
37
+ }
38
+ }
@@ -0,0 +1 @@
1
+ var S=Object.defineProperty;var n=(t,u)=>S(t,"name",{value:u,configurable:!0});var N=Object.defineProperty,o=n((t,u)=>N(t,"name",{value:u,configurable:!0}),"a");import{readSignedSection as T}from"@earendil-works/pi-coding-agent";import{pinnedPackageArg as z}from"./install.js";function c(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}n(c,"d"),o(c,"isRecord");function r(t){return typeof t=="string"&&t.trim()?t.trim():void 0}n(r,"i"),o(r,"text");function d(t){return Array.isArray(t)?t.filter(u=>typeof u=="string"):[]}n(d,"y"),o(d,"strings");const L=["write","credentials","account","delete","git-clean","messages","payments","download"];function k(t){if(!Array.isArray(t.risk))return["unreviewed"];const u=new Set;for(const e of t.risk){const i=typeof e=="string"?L.find(s=>s===e.trim()):void 0;u.add(i??"unreviewed")}return[...u]}n(k,"h"),o(k,"riskOf");function p(t){const u=t.activation;if(!c(u))return;const e=r(u.hint);if(!e)return;const i=d(u.keywords).map(s=>s.trim()).filter(Boolean).slice(0,20);return{hint:e,keywords:i}}n(p,"g"),o(p,"activationOf");function B(t){if(!Array.isArray(t))return[];const u=[];for(const e of t){if(!c(e))continue;const i=r(e.key),s=r(e.label),a=e.target==="header"||e.target==="arg"?e.target:e.target==="env"?"env":void 0;!i||!s||!a||u.push({key:i,target:a,label:s,required:e.required===!0,secret:e.secret===!0,...r(e.template)?{template:r(e.template)}:{},...r(e.help)?{help:r(e.help)}:{},...r(e.placeholder)?{placeholder:r(e.placeholder)}:{}})}return u}n(B,"x"),o(B,"inputsOf");function A(t){const u={};if(!c(t))return u;for(const[e,i]of Object.entries(t))typeof i=="string"&&(u[e]=i);return u}n(A,"w"),o(A,"stringRecord");const g=/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/,w=/^sha512-[A-Za-z0-9+/]{86}==$/,$=/^[0-9a-f]{64}$/;function E(t,u,e){return e.some(i=>i.id===t&&(i.version==="*"||i.version===u))}n(E,"F"),o(E,"isRevoked");function C(t){const u=r(t.id),e=p(t);if(!u||!g.test(u)||!e)return;const i=c(t.install)?t.install:t,s=t.transport==="http"?"http":"stdio",a=s==="http"?r(t.url)??r(i.url):void 0,l=r(i.command)??"";if(s==="http"?!a?.startsWith("https://"):!l)return;const F=r(t.summary)??r(t.description),f=c(t.source)?t.source:void 0,v=r(f?.spec),R=z(d(i.args))?.replace(/^npm:/,""),b=!v||v.replace(/^npm:/,"")===R,m=b?r(f?.integrity)??r(t.integrity):void 0,y=b?(r(f?.sha256)??r(t.sha256))?.toLowerCase():void 0;return{id:u,kind:"mcp",name:r(t.displayName)??r(t.name)??u,hint:e.hint,keywords:e.keywords,...F?{summary:F}:{},...r(t.category)?{category:r(t.category)}:{},risk:k(t),inputs:B(t.inputs),mcp:{transport:s,command:s==="http"?"":l,args:s==="http"?[]:d(i.args),env:s==="http"?{}:A(i.env),...a?{url:a}:{},...m&&w.test(m)?{integrity:m}:{},...y&&$.test(y)?{sha256:y}:{}},installable:t.installable!==!1}}n(C,"O"),o(C,"mcpRow");function D(t){const u=r(t.id),e=p(t);if(!(!u||!g.test(u)||!e))return{id:u,kind:"skill",name:r(t.displayName)??r(t.name)??u,hint:e.hint,keywords:e.keywords,risk:[],inputs:[],installable:!1}}n(D,"E"),o(D,"skillRow");function I(t){const u=r(t.id),e=p(t);if(!u||!g.test(u)||!e)return;const i=t.source,s=typeof i=="string"?i:c(i)?r(i.spec):r(t.spec),a=c(i)?r(i.integrity):r(t.integrity),l=r(t.summary)??r(t.description);return{id:u,kind:"package",name:r(t.displayName)??r(t.name)??u,hint:e.hint,keywords:e.keywords,...l?{summary:l}:{},risk:k(t),inputs:[],...s?{packageSpec:s.replace(/^npm:/,"")}:{},...a&&w.test(a)?{packageIntegrity:a}:{},installable:t.installable!==!1&&!!s&&!!a}}n(I,"N"),o(I,"packageRow");function x(t){return r(t.version)}n(x,"_"),o(x,"rowVersion");function h(t){const u=t.section==="mcp"?C:t.section==="skills"?D:I,e=[];for(const i of t.rows){const s=u(i);s&&(E(s.id,x(i),t.revoked)||e.push(s))}return e}n(h,"L"),o(h,"capabilitiesOf");const O=[{id:"office",kind:"builtin",name:"\u529E\u516C\u6587\u6863",hint:"\u8981\u751F\u6210\u3001\u8BFB\u53D6\u6216\u4FEE\u6539 PPT\u3001Word\u3001Excel \u6587\u6863\u6216\u56FE\u8868\u65F6\u542F\u7528\u3002",keywords:["PPT","\u5E7B\u706F\u7247","Word","docx","Excel","xlsx","\u8868\u683C","\u6F14\u793A\u6587\u7A3F","\u62A5\u544A\u6587\u6863"],risk:[],inputs:[],installable:!1},{id:"web",kind:"builtin",name:"\u8054\u7F51",hint:"\u8981\u641C\u7D22\u7F51\u9875\u6216\u8BFB\u53D6\u7F51\u9875\u5185\u5BB9\u65F6\u542F\u7528\u3002",keywords:["\u8054\u7F51","\u641C\u7D22\u4E00\u4E0B","\u4E0A\u7F51\u67E5","\u7F51\u9875\u5185\u5BB9","\u6700\u65B0\u6D88\u606F","\u8BFB\u4E00\u4E0B\u8FD9\u4E2A\u94FE\u63A5"],risk:[],inputs:[],installable:!1},{id:"debug",kind:"builtin",name:"\u8C03\u8BD5\u5668",hint:"\u8981\u7528\u8C03\u8BD5\u5668\u65AD\u70B9\u3001\u5355\u6B65\u8FD0\u884C\u7A0B\u5E8F\uFF0C\u67E5\u770B\u8FD0\u884C\u65F6\u53D8\u91CF\u7684\u503C\u65F6\u542F\u7528\u3002",keywords:["\u8C03\u8BD5\u5668","\u65AD\u70B9","\u5355\u6B65","debugger","breakpoint","debugpy","\u8C03\u7528\u6808"],risk:[],inputs:[],installable:!1}];function P(t={}){const u=[...O],e={};for(const i of["mcp","skills","packages"]){const s=T(i,t);if(!s.ok){e[i]=s.reason;continue}e[i]=`v${s.value.catalogVersion}`,u.push(...h(s.value))}return{capabilities:u,sources:e}}n(P,"z"),o(P,"readInventory");export{O as BUILTIN_CAPABILITIES,h as capabilitiesOf,P as readInventory};
@@ -0,0 +1,11 @@
1
+ var bu=Object.defineProperty;var B=(d,D)=>bu(d,"name",{value:D,configurable:!0});var yu=Object.defineProperty,c=B((d,D)=>yu(d,"name",{value:D,configurable:!0}),"c");import{readFileSync as G}from"node:fs";import{join as H}from"node:path";import{loadMcpServerConfigs as hu,takeMcpConfigProblems as ku}from"@dalcode/dal-mcp/config";import{t as a,tm as M}from"@dalcode/dal-pi-kit";import{defaultConfig as wu}from"@dalcode/deepailab/oidc";import{CONFIG_DIR_NAME as v,DefaultPackageManager as Iu,ENGINE_MARKET_CACHE_FILE as vu,fetchSignedMarket as $u,getAgentDir as Tu,marketCacheDir as Su,resolveMarketEndpoint as xu,SettingsManager as ju,tryEnsurePackageAdapted as Mu}from"@earendil-works/pi-coding-agent";import{readInventory as K}from"./catalogue.js";import{autoInstallBlocker as V,buildMcpEntry as _u,checkReachable as Pu,chooseRegistry as Nu,endpointOf as Ou,pinOf as J,removeMcpEntry as Lu,setMcpEntryDisabled as Y,userMcpEntries as Ru,userRegistries as qu,writeMcpEntry as Uu}from"./install.js";import{breakTieByProject as z,buildIndex as Q,route as Wu,scoreRequest as X}from"./match.js";import{isCiLike as Z,markApproved as Gu,markDeclined as uu,markDisabled as eu,markInstalled as tu,readSettings as $,readState as iu,writeAutoInstall as Hu}from"./state.js";import{BUILTIN_CAPABILITIES as Ku,capabilitiesOf as Vu,readInventory as Ju}from"./catalogue.js";import{buildIndex as Yu,route as zu,scoreRequest as Qu}from"./match.js";function au(){return globalThis[Symbol.for("dalcode.tool-catalog.api")]}B(au,"Le"),c(au,"toolCatalog");function nu(){return globalThis[Symbol.for("dalcode.mcp.api")]}B(nu,"Ne"),c(nu,"mcpRuntime");function ru(){return globalThis[Symbol.for("dalcode.skills.search")]}B(ru,"Fe"),c(ru,"skillSearch");const Xu={write:"\u4F1A\u4FEE\u6539\u6587\u4EF6\u6216\u4ED3\u5E93",credentials:"\u4F1A\u4F7F\u7528\u4F60\u7684\u51ED\u636E",account:"\u4F1A\u64CD\u4F5C\u4F60\u7684\u5916\u90E8\u8D26\u53F7",delete:"\u53EF\u80FD\u5220\u9664\u6570\u636E","git-clean":"\u53EF\u80FD\u6267\u884C git clean \u5220\u9664\u672A\u63D0\u4EA4\u7684\u6587\u4EF6",messages:"\u4F1A\u4EE5\u4F60\u7684\u540D\u4E49\u53D1\u9001\u6D88\u606F",payments:"\u6D89\u53CA\u652F\u4ED8",download:"\u542F\u7528\u524D\u8981\u4E0B\u8F7D\u8F83\u5927\u7684\u8FD0\u884C\u65F6\u3001\u6D4F\u89C8\u5668\u6216\u6A21\u578B",unreviewed:"\u8FD8\u6CA1\u6709\u7ECF\u8FC7\u98CE\u9669\u5BA1\u6838"},Zu=["package.json",".env",".env.example",".env.local","docker-compose.yml","docker-compose.yaml","compose.yaml","pyproject.toml","requirements.txt","prisma/schema.prisma","go.mod","Cargo.toml","Gemfile","application.yml","application.properties"];function _(d){let D="";for(const A of Zu)try{D+=`
2
+ ${G(H(d,A),"utf8").slice(0,64*1024)}`}catch{}return D}B(_,"te"),c(_,"readProjectText");const ue=/(接入|对接|集成|打通|调用.{0,12}(api|接口)|连上|连接到|没有.{0,6}工具|需要.{0,6}工具|做一个.{0,8}工具|integrate with|connect to|a tool (to|that|for))/i,ee=360*60*1e3;function su(d,D){try{const A=JSON.parse(G(H(Su(d),vu),"utf8")),f=Object.values(A.sections??{}).map(w=>Date.parse(w.fetchedAt??"")).filter(w=>!Number.isNaN(w));return f.length===3?D-Math.min(...f):Number.POSITIVE_INFINITY}catch{return Number.POSITIVE_INFINITY}}B(su,"Ue"),c(su,"engineCacheAgeMs");const ou=Symbol.for("dalcode.capabilities.handle"),lu="capabilities_route",cu="capabilities_install";function Fu(){return globalThis[ou]}B(Fu,"rn"),c(Fu,"capabilitiesHandle");function P(d={}){return D=>{const A=d.env??process.env;let f;const w={settled:c(async()=>{for(let e=0;e<5&&f;e++){const u=f.pending;if(await u,f.pending===u)break}},"settled"),inventory:c(()=>f?.inventory,"inventory")};globalThis[ou]=w;const T=c(e=>{f&&(f.pending=Promise.all([f.pending,e.then(()=>{},()=>{})]).then(()=>{}))},"later"),h=c((e,u,t="info")=>{e.hasUI?e.ui.notify(u,t):process.stderr.write(`${u}
3
+ `)},"say"),y=c((e,u,t)=>{const i={id:e.id,name:e.name,kind:e.kind,status:u,...t!==void 0?{error:t instanceof Error?t.message:String(t)}:{}};D.emitHostEvent(cu,i)},"installEvent"),k=c((e,u,t,i="info")=>{e.noted.has(u)||(e.noted.add(u),h(e.ctx,t,i))},"noteOnce"),du=c(e=>{e.inventory=K({env:A,...d.catalogueFiles?{files:d.catalogueFiles}:{}}),e.index=Q(e.inventory.capabilities)},"reload"),N=c(e=>d.packageManager?.(e.cwd,e.agentDir)??new Iu({cwd:e.cwd,agentDir:e.agentDir,settingsManager:ju.create(e.cwd,e.agentDir)}),"packageManager"),O=c((e,u)=>u.kind==="builtin"?!0:u.kind==="mcp"?S(e,u)!==void 0:u.kind==="package"?R(e,u):!1,"isAvailable"),S=c((e,u)=>{const t=hu(e.cwd,{projectTrusted:e.ctx.isProjectTrusted()});if(ku(),t[u.id])return u.id;const i=J(u);for(const[s,n]of Object.entries(t)){if("url"in n){if(u.mcp?.url&&n.url===u.mcp.url)return s;continue}const o=n.args??[];if(i&&o.some(r=>r.startsWith(`${i.name}@`)||r.startsWith(`${i.name}==`)))return s}},"mcpInstalledName"),L=c(e=>e.slice(0,e.lastIndexOf("@")>0?e.lastIndexOf("@"):e.length),"packageName"),R=c((e,u)=>{if(!u.packageSpec)return!1;const t=L(u.packageSpec);try{return N(e).listConfiguredPackages().some(i=>{const s=i.source.replace(/^npm:/,"");return s===t||s.startsWith(`${t}@`)})}catch{return!1}},"packageInstalled"),x=c((e,u)=>iu(e.agentDir).disabled.includes(u.id)?!0:u.kind!=="mcp"?!1:Ru(e.agentDir).get(u.id)?.disabled===!0,"userDisabled"),pu=c(e=>{const u=au();return u?u.inactiveGroups().some(t=>t.id===e)?u.activate(e):[]:[]},"activateGroup"),mu=c(async(e,u)=>{const t={};for(const i of u.inputs.filter(s=>s.required)){const s=`${a("\u300C{name}\u300D\u9700\u8981\uFF1A").replace("{name}",u.name)}${i.label}${i.help?`
4
+ ${i.help}`:""}`,n=(await e.ctx.ui.requestInput({title:s,...i.placeholder?{placeholder:i.placeholder}:{}}))?.trim();if(!n)return;t[i.key]=n}return t},"askInputs"),Eu=c(async e=>{for(const u of Object.values(e)){const t=Ou(u);if(t)try{await(d.checkReachable??Pu)(t.host,t.port)}catch(i){const s=i instanceof Error?i.message:String(i);return a("\u8FDE\u4E0D\u5230 {host}:{port}\uFF08{why}\uFF09").replace("{host}",t.host).replace("{port}",String(t.port)).replace("{why}",s)}}},"firstUnreachable"),q=c((e,u)=>{const t=e.inputs.filter(s=>s.required).map(s=>s.label).join("\u3001"),i=t?a("\u8BF7\u68C0\u67E5{labels}\u662F\u5426\u6B63\u786E\uFF0C\u4E0B\u6B21\u7528\u5230\u65F6\u4F1A\u91CD\u65B0\u8BE2\u95EE\u3002").replace("{labels}",t):a("\u8BF7\u68C0\u67E5\u7F51\u7EDC\u540E\u91CD\u8BD5\uFF0C\u6216\u7528 /capabilities enable {id} \u518D\u8BD5\u4E00\u6B21\u3002").replace("{id}",e.id);return`${a("\u300C{name}\u300D\u8FDE\u63A5\u4E0D\u4E0A\uFF1A").replace("{name}",e.name)}${u}${a("\u3002")}${i}`},"cannotConnect"),fu=c(async(e,u,t)=>{const i=J(u);let s;if(i){const r=i.ecosystem==="npm"?u.mcp?.integrity:u.mcp?.sha256;if(!r)return{outcome:"no-digest"};const F=await(d.userRegistries??((p,b)=>qu(p,b,A)))(i.ecosystem,e.cwd);s=await Nu(i,r,{env:A,user:F,...d.fetch?{fetch:d.fetch}:{}})}let n=_u(u,t,s?.env??{});d.adjustMcpEntry&&(n=d.adjustMcpEntry(u,n));const o=u.inputs.some(r=>r.secret&&t[r.key]!==void 0);return Uu(e.agentDir,u.id,n,o),{outcome:"written",...s?{registry:s}:{},...i?{version:i.version}:{}}},"installMcp"),U=c(async(e,u,t)=>{if(t.outcome!=="written")return t;const i=t,s=i.registry?{registry:i.registry}:{},n=nu(),o=n?(await n.connectAdded([u.id]))[u.id]:void 0;if(o?.status==="connected"&&o.tools.length>0)return tu(e.agentDir,u.id,"mcp",i.version),y(u,"installed"),{outcome:"installed",...s,line:a("\u5DF2\u4E3A\u8FD9\u4E2A\u4EFB\u52A1\u542F\u7528\uFF1A{name}").replace("{name}",u.name),note:M("\u5DF2\u4E3A\u672C\u4EFB\u52A1\u5B89\u88C5\u5E76\u542F\u7528 MCP \u8FDE\u63A5\u5668\u300C{name}\u300D\uFF08{hint}\uFF09\uFF0C\u53EF\u76F4\u63A5\u8C03\u7528\uFF1A{tools}").replace("{name}",u.name).replace("{hint}",u.hint).replace("{tools}",o.tools.join(", "))};Lu(e.agentDir,u.id,u.id),e.enabled.delete(u.id);const r=o?.error??(o?.status==="connected"?a("\u6CA1\u6709\u63D0\u4F9B\u4EFB\u4F55\u5DE5\u5177"):n?a("\u672A\u8FDE\u63A5"):a("MCP \u652F\u6301\u672A\u52A0\u8F7D"));return y(u,"failed",r),{outcome:"connect-failed",...s,line:q(u,r)}},"connectInstalled"),Au=c((e,u)=>{const t=u.packageSpec,i=u.packageIntegrity;if(!t||!i)return;const s=`npm:${t}`,n=(async()=>{const o=N(e),r=await o.getRegistryIntegrity(s);if(r!==i)throw new Error(a("\u5B89\u88C5\u5305\u6821\u9A8C\u4E0D\u4E00\u81F4\uFF1ADAL \u767B\u8BB0\u7684\u662F {want}\uFF0C\u4E0B\u8F7D\u6E90\u73B0\u5728\u662F {got}").replace("{want}",i).replace("{got}",r??"?"));await o.installAndPersist(s);const F=o.getRecordedIntegrity(L(t),"user");if(F!==void 0&&F!==i)throw await o.removeAndPersist(s),new Error(a("\u88C5\u4E0B\u6765\u7684\u5B89\u88C5\u5305\u6821\u9A8C\u4E0D\u4E00\u81F4\uFF0C\u5DF2\u79FB\u9664"));const p=o.getInstalledPath(s,"user");p&&Mu(p),tu(e.agentDir,u.id,"package",t.slice(t.lastIndexOf("@")+1)),y(u,"installed"),h(e.ctx,a("\u5DF2\u5B89\u88C5\u300C{name}\u300D\uFF0C\u4E0B\u4E2A\u4F1A\u8BDD\u8D77\u53EF\u7528\uFF08\u6216\u8F93\u5165 /reload \u7ACB\u5373\u52A0\u8F7D\uFF09").replace("{name}",u.name))})().catch(o=>{y(u,"failed",o),h(e.ctx,`${a("\u672A\u80FD\u5B89\u88C5\u300C{name}\u300D\uFF1A").replace("{name}",u.name)}${o instanceof Error?o.message:String(o)}`,"warning")});T(n)},"installPackage"),W=c(async(e,u,t)=>{if(!t&&x(e,u))return{outcome:"disabled"};if(e.enabled.has(u.id)&&!t)return{outcome:"already"};const i=e.ctx;if(u.kind==="builtin"||u.kind==="mcp"&&S(e,u)){const l=u.kind==="mcp"?S(e,u)??u.id:u.id;e.enabled.add(u.id);const E=pu(l);return E.length===0?{outcome:"ready"}:{outcome:"activated",line:a("\u5DF2\u4E3A\u8FD9\u4E2A\u4EFB\u52A1\u542F\u7528\uFF1A{name}").replace("{name}",u.name),note:M("\u5DF2\u4E3A\u672C\u4EFB\u52A1\u542F\u7528\u300C{name}\u300D\uFF0C\u53EF\u76F4\u63A5\u8C03\u7528\uFF1A{tools}").replace("{name}",u.name).replace("{tools}",E.join(", "))}}if(u.kind==="package"&&R(e,u))return e.enabled.add(u.id),{outcome:"ready"};const s=V(u);if(s)return s!=="not-installable"&&k(e,`blocked:${u.id}`,a("\u300C{name}\u300D\u53EF\u4EE5\u5904\u7406\u8FD9\u4E2A\u4EFB\u52A1\uFF0C\u4F46\u76EE\u5F55\u91CC\u6CA1\u6709\u767B\u8BB0\u5B83\u7684\u5B89\u88C5\u5305\u6821\u9A8C\u503C\uFF0C\u4E0D\u4F1A\u81EA\u52A8\u5B89\u88C5\u3002").replace("{name}",u.name)),{outcome:s};if(u.kind==="mcp"&&D.getToolAllowlist()?.some(l=>l.startsWith("mcp__"))===!1)return{outcome:"allowlist"};const n=$(e.agentDir,e.cwd,A,v);if(!t&&!n.autoInstall)return k(e,`auto-off:${u.id}`,a("\u300C{name}\u300D\u53EF\u4EE5\u5904\u7406\u8FD9\u4E2A\u4EFB\u52A1\uFF1B\u81EA\u52A8\u5B89\u88C5\u5DF2\u5173\u95ED\uFF0C\u53EF\u7528 /capabilities enable {id} \u542F\u7528\u3002").replace("{name}",u.name).replace("{id}",u.id)),{outcome:"auto-off"};if(!t&&Z(A)&&!n.allowInCI)return k(e,`ci:${u.id}`,a("CI \u73AF\u5883\u4E2D\u4E0D\u81EA\u52A8\u5B89\u88C5\u300C{name}\u300D\uFF08\u8BBE\u7F6E capabilities.allowInCI \u6216 DAL_CAPABILITIES_AUTO_INSTALL=1 \u53EF\u5141\u8BB8\uFF09\u3002").replace("{name}",u.name)),{outcome:"ci"};const o=iu(e.agentDir);if(!t&&o.declined.includes(u.id))return{outcome:"declined"};if(u.risk.length>0&&!t&&!o.approved.includes(u.id)){const l=u.risk.map(E=>a(Xu[E])).join("\u3001");if(!i.hasUI)return k(e,`risk:${u.id}`,a("\u300C{name}\u300D{risks}\uFF0C\u9700\u8981\u4F60\u786E\u8BA4\u540E\u624D\u80FD\u542F\u7528\uFF1B\u8FD9\u6B21\u8FD0\u884C\u6CA1\u6709\u754C\u9762\uFF0C\u5DF2\u8DF3\u8FC7\u3002\u5728\u4EA4\u4E92\u6A21\u5F0F\u4E2D\u7528\u5230\u65F6\u4F1A\u8BE2\u95EE\u4E00\u6B21\u3002").replace("{name}",u.name).replace("{risks}",l)),{outcome:"risk-skipped"};if(!await i.ui.confirm(a("\u4E3A\u8FD9\u4E2A\u4EFB\u52A1\u542F\u7528\u300C{name}\u300D\uFF1F").replace("{name}",u.name),`${u.summary??u.hint}
5
+ ${a("\u6CE8\u610F\uFF1A")}${l}`))return uu(e.agentDir,u.id),{outcome:"declined"};Gu(e.agentDir,u.id)}let r={};if(u.inputs.some(l=>l.required)){if(!i.hasUI){const j=u.inputs.filter(m=>m.required).map(m=>m.label).join("\u3001");return k(e,`inputs:${u.id}`,a("\u300C{name}\u300D\u9700\u8981\u5148\u586B\u5199{labels}\uFF1B\u8FD9\u6B21\u8FD0\u884C\u6CA1\u6709\u754C\u9762\uFF0C\u5DF2\u8DF3\u8FC7\u3002\u5728\u4EA4\u4E92\u6A21\u5F0F\u4E2D\u7528\u5230\u65F6\u4F1A\u8BE2\u95EE\u4E00\u6B21\u3002").replace("{name}",u.name).replace("{labels}",j)),{outcome:"inputs-skipped"}}const l=await mu(e,u);if(!l)return uu(e.agentDir,u.id),{outcome:"declined"};r=l;const E=await Eu(r);if(E)return y(u,"failed",E),{outcome:"connect-failed",line:q(u,E)}}if(e.enabled.add(u.id),u.kind==="package")return Au(e,u),{outcome:"installing",line:a("\u6B63\u5728\u4E3A\u8FD9\u4E2A\u4EFB\u52A1\u5B89\u88C5\uFF1A{name}\uFF08\u540E\u53F0\u8FDB\u884C\uFF0C\u4E0B\u4E2A\u4F1A\u8BDD\u8D77\u53EF\u7528\uFF09").replace("{name}",u.name)};const F=fu(e,u,r),p=c(l=>`${a("\u672A\u80FD\u542F\u7528\u300C{name}\u300D\uFF1A").replace("{name}",u.name)}${l instanceof Error?l.message:String(l)}`,"failedLine"),b=d.installBudgetMs??2e4;let C;const g=new Promise(l=>{C=setTimeout(()=>l("timeout"),b),C.unref?.()});try{const l=await Promise.race([F,g]);if(l!=="timeout")return await U(e,u,l)}catch(l){return e.enabled.delete(u.id),y(u,"failed",l),{outcome:"failed",line:p(l)}}finally{clearTimeout(C)}return T(F.then(l=>U(e,u,l)).then(l=>{l.line&&h(i,l.line,l.outcome==="installed"?"info":"warning")},l=>{e.enabled.delete(u.id),y(u,"failed",l),h(i,p(l),"warning")})),{outcome:"installing",line:a("\u6B63\u5728\u4E3A\u8FD9\u4E2A\u4EFB\u52A1\u542F\u7528\uFF1A{name}\u2026").replace("{name}",u.name)}},"enable"),Du=c(async(e,u)=>{e.projectText??=_(e.cwd);const t=z(u,e.projectText);if(t)return t;const i=`tie:${u.map(n=>n.capability.id).join(",")}`;if(!e.ctx.hasUI){k(e,i,a("\u6709\u51E0\u4E2A\u80FD\u529B\u90FD\u53EF\u80FD\u9002\u5408\u8FD9\u4E2A\u4EFB\u52A1\uFF08{names}\uFF09\uFF0C\u6CA1\u6709\u81EA\u52A8\u542F\u7528\uFF1B\u53EF\u7528 /capabilities enable <id> \u6307\u5B9A\u3002").replace("{names}",u.map(n=>`${n.capability.name} ${n.capability.id}`).join("\u3001")));return}if(e.noted.has(i))return;e.noted.add(i);const s=await e.ctx.ui.requestChoice({title:a("\u8FD9\u4E2A\u4EFB\u52A1\u53EF\u4EE5\u7528\u4EE5\u4E0B\u80FD\u529B\uFF0C\u9009\u4E00\u4E2A\u542F\u7528\uFF1A"),items:[...u.map(n=>({id:n.capability.id,label:n.capability.name,description:n.capability.hint})),{id:"__none__",label:a("\u90FD\u4E0D\u7528")}]});return u.find(n=>n.capability.id===s)},"resolveTie");D.on("session_start",async(e,u)=>{const t=Tu(),i=$(t,u.cwd,A,v),s=K({env:A,...d.catalogueFiles?{files:d.catalogueFiles}:{}});if(f={ctx:u,cwd:u.cwd,agentDir:t,inventory:s,index:Q(s.capabilities),enabled:new Set,noted:new Set,pending:Promise.resolve()},!i.enabled||d.skipMarketFetch||su(A,Date.now())<ee)return;const n=f;T((async()=>{const o=await u.modelRegistry?.getApiKeyForProvider?.("deepailab").catch(()=>{}),r=xu({env:A,apiBase:wu().apiBase,...o?{virtualKey:o}:{}});r&&(await $u({endpoint:r,env:A,...d.fetch?{fetch:d.fetch}:{}})).updated.length>0&&f===n&&du(n)})())}),D.on("before_agent_start",async(e,u)=>{const t=f;if(!t||e.messageType!=="user")return;const i=e.prompt.trim();if(!i||i.startsWith("/")||!$(t.agentDir,t.cwd,A,v).enabled)return;const s=performance.now(),n=X(t.index,i);let o=Wu(n,m=>{const I=t.inventory.capabilities.find(Bu=>Bu.id===m);return I?O(t,I):!1});t.projectText??=o.tied.length>0?_(t.cwd):void 0;const r=o.tied.length>0?z(o.tied,t.projectText??""):void 0;r&&(o={...o,tool:r,tied:[]});const F=performance.now()-s;t.lastRouteMs=F;let p=o.tool;!p&&o.tied.length>0&&(p=await Du(t,o.tied));const b=[],C=[];let g,l;if(p){const m=await W(t,p.capability,!1);g=m.outcome,l=m.registry,m.line&&b.push(m.line),m.note&&C.push(m.note)}const E=o.skill?.capability;if(E&&!t.enabled.has(E.id)&&!x(t,E)){const m=await ru()?.load?.(E.id).catch(()=>{});m&&(t.enabled.add(E.id),b.push(a("\u5DF2\u4E3A\u8FD9\u4E2A\u4EFB\u52A1\u542F\u7528\uFF1A{name}").replace("{name}",E.name)),C.push(`<skill name="${E.id}">
6
+ ${m.trim()}
7
+ </skill>`))}if(!p&&o.tied.length===0&&n.length===0&&ue.test(i)&&C.push(M("DAL \u5BA1\u6838\u8FC7\u7684\u80FD\u529B\u91CC\u6CA1\u6709\u9002\u5408\u8FD9\u4E2A\u4EFB\u52A1\u7684\u5DE5\u5177\u3002\u5982\u679C\u786E\u5B9E\u9700\u8981\u4E00\u4E2A\u65B0\u5DE5\u5177\uFF0C\u53EF\u4EE5\u5411\u7528\u6237\u63D0\u8BAE\u4E3A\u5B83\u7F16\u5199\u4E00\u4E2A DAL \u6269\u5C55\uFF08\u6269\u5C55\u5199\u6CD5\u89C1 DAL \u6587\u6863\u91CC\u7684\u6269\u5C55\u793A\u4F8B\uFF09\uFF0C\u7528\u6237\u540C\u610F\u540E\u518D\u52A8\u624B\uFF1B\u4E0D\u8981\u4ECE\u7F51\u4E0A\u5B89\u88C5\u672A\u7ECF\u5BA1\u6838\u7684\u5305\u3002")),d.onRoute?.({prompt:i,routeMs:F,tied:o.tied.map(m=>m.capability.id),...p?{chosen:p.capability.id}:{},...o.skill?{skill:o.skill.capability.id}:{},...g?{outcome:g}:{},...l?{registry:l}:{}}),p||o.tied.length>0||o.skill){const m={routeMs:F,tied:o.tied.map(I=>I.capability.id),lines:b,...p?{chosen:{id:p.capability.id,name:p.capability.name,kind:p.capability.kind}}:{},...g?{outcome:g}:{},...E?{skill:{id:E.id,name:E.name}}:{},...l?{registry:{source:l.source,registry:l.registry.replace(/\/\/[^/@\s]+@/,"//"),...l.fallback?{fallback:l.fallback}:{}}}:{}};D.emitHostEvent(lu,m)}const j=g==="connect-failed"||g==="failed";for(const m of b)h(u,m,j?"warning":"info");if(C.length!==0)return{message:{customType:"dal-capabilities",content:C.join(`
8
+
9
+ `),display:!1}}}),D.on("session_shutdown",async()=>{f=void 0}),D.registerCommand("capabilities",{description:a("\u67E5\u770B\u3001\u505C\u7528\u6216\u542F\u7528\u4E3A\u4EFB\u52A1\u81EA\u52A8\u542F\u7528\u7684\u80FD\u529B\uFF08list | enable <id> | disable <id> | auto on|off\uFF09"),getArgumentCompletions:c(e=>{const u=e.trimStart(),t=u.indexOf(" ");if(t===-1)return["list","enable","disable","auto","why"].filter(n=>n.startsWith(u)).map(n=>({value:`${n} `,label:n}));const i=u.slice(0,t),s=u.slice(t+1);return(i==="enable"||i==="disable")&&f?f.inventory.capabilities.filter(n=>n.id.startsWith(s)).slice(0,30).map(n=>({value:`${i} ${n.id}`,label:`${n.id} ${n.name}`})):null},"getArgumentCompletions"),handler:c(async(e,u)=>{const t=f;if(!t)return;const[i="list",...s]=e.trim().split(/\s+/).filter(Boolean),n=s.join(" "),o=c(()=>t.inventory.capabilities.find(r=>r.id===n),"find");switch(i){case"list":{const r=s[0]==="all";u.ui.notify(gu(t,r),"info");return}case"enable":{const r=o();if(!r){u.ui.notify(`${a("\u76EE\u5F55\u91CC\u6CA1\u6709\u8FD9\u4E2A\u80FD\u529B\uFF1A")}${n||"?"}`,"warning");return}if(eu(t.agentDir,r.id,!1),r.kind==="mcp"&&Y(t.agentDir,r.id,!1)){u.ui.notify(a("\u5DF2\u91CD\u65B0\u542F\u7528\uFF1A{name}").replace("{name}",r.name),"info");return}const F=await W(t,r,!0);u.ui.notify(F.line??a("\u300C{name}\u300D\u5DF2\u53EF\u7528\u3002").replace("{name}",r.name),F.outcome==="failed"?"warning":"info");return}case"disable":{const r=o();if(!r){u.ui.notify(`${a("\u76EE\u5F55\u91CC\u6CA1\u6709\u8FD9\u4E2A\u80FD\u529B\uFF1A")}${n||"?"}`,"warning");return}eu(t.agentDir,r.id,!0),t.enabled.delete(r.id),r.kind==="mcp"&&Y(t.agentDir,r.id,!0),u.ui.notify(a("\u5DF2\u505C\u7528\uFF1A{name}\uFF0C\u4E0D\u4F1A\u518D\u81EA\u52A8\u542F\u7528\u3002").replace("{name}",r.name),"info");return}case"auto":{const r=s[0];if(r!=="on"&&r!=="off"){u.ui.notify(a("\u7528\u6CD5\uFF1A/capabilities auto on|off"),"info");return}Hu(t.agentDir,r==="on"),u.ui.notify(r==="on"?a("\u5DF2\u5F00\u542F\u81EA\u52A8\u5B89\u88C5\u3002"):a("\u5DF2\u5173\u95ED\u81EA\u52A8\u5B89\u88C5\uFF1A\u53EA\u542F\u7528\u5DF2\u5B89\u88C5\u7684\u80FD\u529B\u3002"),"info");return}case"why":{const r=X(t.index,n).slice(0,5).map(F=>`${F.capability.id} ${F.score.toFixed(1)} [${[...F.keywords,...F.pieces].join(", ")}]`);u.ui.notify(r.length>0?r.join(`
10
+ `):a("\u6CA1\u6709\u5339\u914D\u7684\u80FD\u529B\u3002"),"info");return}default:u.ui.notify(a("\u7528\u6CD5\uFF1A/capabilities list [all] | enable <id> | disable <id> | auto on|off | why <\u4EFB\u52A1>"),"info")}},"handler")});const Cu=c((e,u)=>{if(x(e,u))return a("\u5DF2\u505C\u7528");if(e.enabled.has(u.id))return a("\u672C\u4F1A\u8BDD\u5DF2\u542F\u7528");if(O(e,u))return u.kind==="builtin"?a("\u5185\u7F6E"):a("\u5DF2\u5B89\u88C5");if(u.kind==="skill")return a("\u6280\u80FD");if(V(u))return a("\u9700\u624B\u52A8\u5B89\u88C5");const t=u.risk.length>0?a("\uFF08\u542F\u7528\u524D\u786E\u8BA4\uFF09"):"",i=u.inputs.some(s=>s.required)?a("\uFF08\u9700\u8981\u586B\u5199\u914D\u7F6E\uFF09"):"";return`${a("\u53EF\u81EA\u52A8\u5B89\u88C5")}${t}${i}`},"statusOf"),gu=c((e,u)=>{const t=$(e.agentDir,e.cwd,A,v),i=e.inventory.capabilities.map(F=>({capability:F,status:Cu(e,F)})).filter(F=>u||![a("\u53EF\u81EA\u52A8\u5B89\u88C5"),a("\u6280\u80FD"),a("\u9700\u624B\u52A8\u5B89\u88C5")].some(p=>F.status.startsWith(p))),s=Object.entries(e.inventory.sources).map(([F,p])=>`${F} ${p}`).join(" \xB7 "),n=[`${a("\u80FD\u529B\u4E2D\u5FC3")}\uFF1A${a("\u81EA\u52A8\u5B89\u88C5")}${t.autoInstall?a("\u5F00"):a("\u5173")}${Z(A)&&!t.allowInCI?a("\uFF08CI \u73AF\u5883\u4E2D\u4E0D\u5B89\u88C5\uFF09"):""}`,`${a("\u5BA1\u6838\u76EE\u5F55\uFF1A")}${s}`,e.lastRouteMs!==void 0?`${a("\u4E0A\u4E00\u8F6E\u5339\u914D\u8017\u65F6\uFF1A")}${e.lastRouteMs.toFixed(2)} ms`:void 0].filter(Boolean),o=i.map(F=>`- ${F.capability.id} ${F.capability.name} \u2014 ${F.status}`),r=u?[]:[a("\u5171 {n} \u9879\u80FD\u529B\uFF0C/capabilities list all \u67E5\u770B\u5168\u90E8\u3002").replace("{n}",String(e.inventory.capabilities.length))];return[...n,"",...o.length>0?o:[a("\uFF08\u8FD8\u6CA1\u6709\u542F\u7528\u6216\u5B89\u88C5\u4EFB\u4F55\u80FD\u529B\uFF09")],...r].join(`
11
+ `)},"listText")}}B(P,"Je"),c(P,"createDalCapabilities");var te=P();export{Ku as BUILTIN_CAPABILITIES,cu as CAPABILITIES_INSTALL_EVENT,lu as CAPABILITIES_ROUTE_EVENT,Yu as buildIndex,Fu as capabilitiesHandle,Vu as capabilitiesOf,P as createDalCapabilities,te as default,Ju as readInventory,zu as route,Qu as scoreRequest};
@@ -0,0 +1,4 @@
1
+ var tt=Object.defineProperty;var a=(t,e)=>tt(t,"name",{value:e,configurable:!0});var et=Object.defineProperty,u=a((t,e)=>et(t,"name",{value:e,configurable:!0}),"c");import{execFile as rt}from"node:child_process";import{chmodSync as st,existsSync as w,readFileSync as C}from"node:fs";import{connect as nt}from"node:net";import{homedir as ot}from"node:os";import{join as f}from"node:path";import{t as it,withFileLockSync as O,writeFileAtomicSync as $}from"@dalcode/dal-pi-kit";const E="https://registry.npmjs.org",S="https://registry.npmmirror.com",M="https://pypi.org/simple",F="https://mirrors.aliyun.com/pypi/simple",L="https://registry.npmmirror.com/-/binary/python-build-standalone",b="DALCODE_MCP_MIRROR",T=/^(@[a-z0-9-~][a-z0-9-._~]*\/)?[a-z0-9-~][a-z0-9-._~]*@\d+\.\d+\.\d+([-+][0-9A-Za-z.-]+)?$/,at=/^([A-Za-z0-9][A-Za-z0-9._-]*)(?:\[[^\]]*\])?==([A-Za-z0-9.+!_-]+)$/;function R(t){for(let e=0;e<t.length;e++){const r=t[e]??"";if(r==="--from")return t[e+1];if(r==="--with"){e++;continue}if(!r.startsWith("-"))return r}}a(R,"V"),u(R,"pinnedPackageArg");function g(t){const e=t.mcp;if(!e||e.transport!=="stdio")return;const r=(e.command.split(/[\\/]/).pop()??"").toLowerCase().replace(/\.(cmd|exe|bat|ps1)$/,""),s=R(e.args)?.replace(/^npm:/,"");if(s){if(r==="npx"&&T.test(s)){const n=s.lastIndexOf("@");return{ecosystem:"npm",name:s.slice(0,n),version:s.slice(n+1)}}if(r==="uvx"){const n=at.exec(s);if(n)return{ecosystem:"pypi",name:n[1],version:n[2]}}}}a(g,"v"),u(g,"pinOf");function D(t){if(!t.installable)return"not-installable";if(t.kind==="package")return t.packageSpec&&T.test(t.packageSpec)&&t.packageIntegrity?void 0:"no-digest";if(t.kind!=="mcp"||!t.mcp)return"unsupported";if(t.mcp.transport==="http")return t.mcp.url?.startsWith("https://")?void 0:"unsupported";const e=g(t);if(!e)return"no-pin";if(e.ecosystem==="npm"?!t.mcp.integrity:!t.mcp.sha256)return"no-digest"}a(D,"ae"),u(D,"autoInstallBlocker");function A(t){return t instanceof Error?t.message:String(t)}a(A,"C"),u(A,"messageOf");async function P(t,e,r,s){const n=`${t}/${e.name.replace("/","%2F")}/${encodeURIComponent(e.version)}`;try{const o=await r(n,{headers:{accept:"application/json","cache-control":"no-cache"},signal:AbortSignal.timeout(s)});if(o.status===404)return{status:"missing",detail:`${e.name}@${e.version} is not on ${t}`};if(!o.ok)return{status:"error",detail:`${t}: HTTP ${o.status}`};const i=await o.json();return typeof i.dist?.integrity=="string"?{status:"found",hashes:[i.dist.integrity]}:{status:"error",detail:`${t}: metadata has no dist.integrity`}}catch(o){return{status:"error",detail:`${t}: ${A(o)}`}}}a(P,"G"),u(P,"probeNpm");function v(t){return t.toLowerCase().replace(/[-_.]+/g,"-")}a(v,"_"),u(v,"pypiProjectName");function x(t){if(t.endsWith(".whl")){const s=t.slice(0,-4).split("-");return s.length>=5?{name:s[0],version:s[1]}:void 0}const e=t.replace(/\.(tar\.gz|tar\.bz2|tar\.xz|zip|tgz)$/i,""),r=e.lastIndexOf("-");return e!==t&&r>0?{name:e.slice(0,r),version:e.slice(r+1)}:void 0}a(x,"X"),u(x,"pythonFile");function N(t,e){const r=[],s=v(e.name);for(const n of t.matchAll(/href\s*=\s*["']([^"']+)["']/gi)){const o=n[1].replace(/&amp;/g,"&"),i=/#(?:.*&)?sha256=([0-9a-fA-F]{64})/.exec(o)?.[1],c=o.split("#")[0].split("?")[0];let l;try{l=decodeURIComponent(c.slice(c.lastIndexOf("/")+1))}catch{continue}const p=x(l);i&&p&&v(p.name)===s&&p.version.toLowerCase()===e.version.toLowerCase()&&r.push(i.toLowerCase())}return r}a(N,"z"),u(N,"simpleIndexHashes");async function j(t,e,r,s){try{const n=await r(`${t}/${v(e.name)}/`,{headers:{accept:"text/html","cache-control":"no-cache"},signal:AbortSignal.timeout(s)});if(n.status===404)return{status:"missing",detail:`${e.name} is not on ${t}`};if(!n.ok)return{status:"error",detail:`${t}: HTTP ${n.status}`};const o=N(await n.text(),e);return o.length>0?{status:"found",hashes:o}:{status:"missing",detail:`${e.name}==${e.version} is not on ${t}`}}catch(n){return{status:"error",detail:`${t}: ${A(n)}`}}}a(j,"J"),u(j,"probePypi");const ct=8e3,ut=3e4;async function k(t,e,r){const s=r.env[b]?.trim().toLowerCase()==="off",n=t.ecosystem==="pypi"&&!s&&!r.user.pythonMirror?{UV_PYTHON_INSTALL_MIRROR:L}:{},o=t.ecosystem==="npm"?r.user.npm:r.user.uvIndex;if(o)return{source:"user",registry:o,env:n};const i=r.fetch??fetch,c=t.ecosystem==="npm"?P:j,[l,p]=t.ecosystem==="npm"?[S,E]:[F,M];let m;if(s)m=`${b}=off`;else{const y=await c(l,t,i,ct);if(y.status==="found"&&y.hashes.includes(e)){const Q=t.ecosystem==="npm"?{npm_config_registry:l}:{UV_DEFAULT_INDEX:l,UV_INDEX_URL:l,...n};return{source:"mirror",registry:l,env:Q}}m=y.status==="found"?`${l}: lists ${y.hashes.join(", ")}, not ${e}`:y.detail}const d=await c(p,t,i,ut);if(d.status!=="found")throw new Error(`${d.detail}; ${m}`);if(!d.hashes.includes(e))throw new Error(it("\u5B89\u88C5\u5305\u6821\u9A8C\u4E0D\u4E00\u81F4\uFF1ADAL \u767B\u8BB0\u7684\u662F {want}\uFF0C\u4E0B\u8F7D\u6E90\u73B0\u5728\u662F {got}").replace("{want}",e).replace("{got}",`${d.hashes.join(", ")} (${p})`));return{source:"official",registry:p,fallback:m,env:n}}a(k,"ce"),u(k,"chooseRegistry");function U(t,e){return new Promise(r=>{rt("npm",["config","get","registry"],{cwd:t,env:e,timeout:1e4,windowsHide:!0,shell:process.platform==="win32"},(s,n)=>{const o=String(n??"").trim().split(/\r?\n/).pop()?.trim();r(s||!o?void 0:o)})})}a(U,"B"),u(U,"npmConfigRegistry");function V(t){const e=[];if(t.UV_CONFIG_FILE?.trim()&&e.push(t.UV_CONFIG_FILE.trim()),process.platform==="win32")t.APPDATA&&e.push(f(t.APPDATA,"uv","uv.toml")),e.push(f(t.PROGRAMDATA??`${t.SYSTEMDRIVE??"C:"}\\ProgramData`,"uv","uv.toml"));else{e.push(f(t.XDG_CONFIG_HOME?.trim()||f(t.HOME??ot(),".config"),"uv","uv.toml"));for(const r of(t.XDG_CONFIG_DIRS?.trim()||"/etc/xdg").split(":").filter(Boolean))e.push(f(r,"uv","uv.toml"));e.push("/etc/uv/uv.toml")}return e}a(V,"W"),u(V,"uvConfigFiles");const pt=/^\s*(?:index-url|default-index|extra-index-url)\s*=|^\s*\[\[\s*index\s*\]\]/m,lt=/^\s*python-install-mirror\s*=/m;function z(t){try{return C(t,"utf8")}catch{return}}a(z,"K"),u(z,"readText");async function G(t,e,r,s=U){if(t==="npm"){for(const[l,p]of Object.entries(r))if(l.toLowerCase()==="npm_config_registry"&&p?.trim())return{npm:p.trim()};const i=await s(e,r),c=i?.trim().replace(/\/+$/,"").toLowerCase()===E;return i&&!c?{npm:i}:{}}let n=["UV_DEFAULT_INDEX","UV_INDEX_URL","UV_INDEX","UV_EXTRA_INDEX_URL"].map(i=>r[i]?.trim()).find(Boolean),o=!!r.UV_PYTHON_INSTALL_MIRROR?.trim();if(!(r.UV_NO_CONFIG&&r.UV_NO_CONFIG!=="0"&&r.UV_NO_CONFIG.toLowerCase()!=="false"))for(const i of V(r)){const c=z(i);c!==void 0&&(!n&&pt.test(c)&&(n=`uv.toml (${i})`),lt.test(c)&&(o=!0))}return{...n?{uvIndex:n}:{},...o?{pythonMirror:o}:{}}}a(G,"ue"),u(G,"userRegistries");const H={postgres:5432,postgresql:5432,mysql:3306,mariadb:3306,redis:6379,rediss:6379,mongodb:27017,sqlserver:1433,mssql:1433,clickhouse:9e3};function X(t){let e;try{e=new URL(t)}catch{return}const r=e.protocol.replace(/:$/,"").toLowerCase();if(!e.hostname||!(r in H))return;const s=e.port?Number(e.port):H[r];return{host:e.hostname.replace(/^\[|\]$/g,""),port:s}}a(X,"de"),u(X,"endpointOf");function B(t,e,r=5e3){return new Promise((s,n)=>{const o=nt({host:t,port:e}),i=u(c=>{o.destroy(),c?n(c):s()},"done");o.setTimeout(r,()=>i(new Error(`timed out after ${Math.round(r/1e3)}s`))),o.once("connect",()=>i()),o.once("error",c=>i(new Error(c.code??c.message)))})}a(B,"le"),u(B,"checkReachable");function _(t,e){return t.template?t.template.replace("{value}",e):e}a(_,"w"),u(_,"applyTemplate");const Y=6e4;function J(t,e,r={}){const s=t.mcp;if(!s)throw new Error(`${t.id} is not an MCP connector`);const n=g(t),o=s.transport==="http"||t.category==="data"?{connectTimeoutMs:Y}:{},i={id:t.id,...n?{version:n.version}:{},installedAt:new Date().toISOString()};if(s.transport==="http"){const p={};for(const m of t.inputs){const d=e[m.key];d!==void 0&&m.target==="header"&&(p[m.key]=_(m,d))}return{url:s.url??"",...Object.keys(p).length>0?{headers:p}:{},...o,dalCapability:i}}const c={...r},l=[...s.args];for(const p of t.inputs){const m=e[p.key];m!==void 0&&(p.target==="env"?c[p.key]=_(p,m):p.target==="arg"&&l.push(_(p,m)))}return Object.assign(c,s.env),{command:s.command,args:l,...Object.keys(c).length>0?{env:c}:{},...o,dalCapability:i}}a(J,"fe"),u(J,"buildMcpEntry");function h(t){if(!w(t))return{};const e=C(t,"utf8"),r=JSON.parse(e.charCodeAt(0)===65279?e.slice(1):e);if(!r||typeof r!="object"||Array.isArray(r))throw new Error(`${t}: top level is not a JSON object`);return r}a(h,"g"),u(h,"readMcpFile");function I(t,e){t.mcpServers??={};const r=t.mcpServers;if(!r||typeof r!="object"||Array.isArray(r))throw new Error(`${e}: "mcpServers" is not an object`);return r}a(I,"I"),u(I,"serversOf");function W(t,e,r,s){const n=f(t,"mcp.json");return O(n,()=>{const o=h(n),i=I(o,n);return e in i?!1:(i[e]=r,$(n,`${JSON.stringify(o,null,2)}
2
+ `,{mode:s?384:420}),s&&process.platform!=="win32"&&st(n,384),!0)})}a(W,"pe"),u(W,"writeMcpEntry");function q(t,e,r){const s=f(t,"mcp.json");return w(s)?O(s,()=>{const n=h(s),o=I(n,s);return o[e]?.dalCapability?.id!==r?!1:(delete o[e],$(s,`${JSON.stringify(n,null,2)}
3
+ `),!0)}):!1}a(q,"me"),u(q,"removeMcpEntry");function Z(t,e,r){const s=f(t,"mcp.json");return w(s)?O(s,()=>{const n=h(s),o=I(n,s)[e];if(!o||typeof o!="object"||Array.isArray(o))return!1;const i=o;return r?i.disabled=!0:delete i.disabled,$(s,`${JSON.stringify(n,null,2)}
4
+ `),!0}):!1}a(Z,"ge"),u(Z,"setMcpEntryDisabled");function K(t){const e=new Map;let r;try{r=h(f(t,"mcp.json"))}catch{return e}const s=r.mcpServers;if(!s||typeof s!="object"||Array.isArray(s))return e;for(const[n,o]of Object.entries(s)){if(!o||typeof o!="object"||Array.isArray(o))continue;const i=o,c=i.dalCapability;e.set(n,{disabled:i.disabled===!0,...typeof c?.id=="string"?{capabilityId:c.id}:{}})}return e}a(K,"ye"),u(K,"userMcpEntries");export{b as MIRROR_SWITCH_ENV,E as NPMJS_REGISTRY,S as NPMMIRROR_REGISTRY,M as PYPI_INDEX,F as PYPI_MIRROR_INDEX,L as PYTHON_INSTALL_MIRROR,Y as SLOW_CONNECT_TIMEOUT_MS,D as autoInstallBlocker,J as buildMcpEntry,B as checkReachable,k as chooseRegistry,X as endpointOf,g as pinOf,R as pinnedPackageArg,q as removeMcpEntry,Z as setMcpEntryDisabled,N as simpleIndexHashes,K as userMcpEntries,G as userRegistries,W as writeMcpEntry};
@@ -0,0 +1 @@
1
+ var A=Object.defineProperty;var a=(e,u)=>A(e,"name",{value:u,configurable:!0});var B=Object.defineProperty,f=a((e,u)=>B(e,"name",{value:u,configurable:!0}),"d");const g=/[㐀-鿿]/,m=/[a-z0-9][a-z0-9.+#_-]*/g,x=new Set([..."\u8FD9\u90A3\u4E2A\u4E00\u4E0B\u4E86\u7684\u5417\u4E48\u4EC0\u6211\u4F60\u4ED6\u5979\u4EEC\u770B\u5E2E\u628A\u7ED9\u5728\u662F\u6709\u548C\u4E0E\u53CA\u91CC\u4E0A\u4E2D\u5427\u5462\u554A\u8BF7\u80FD\u4F1A\u8981\u60F3\u5C31\u90FD\u4E5F\u8FD8\u518D\u8BA9\u88AB\u65F6\u7528\u6216"]),v=new Set(["\u4EE3\u7801","\u51FD\u6570","\u6587\u4EF6","\u9879\u76EE","\u4FEE\u6539","\u5408\u5E76","\u63D0\u4EA4","\u91CD\u6784","\u5B9E\u73B0","\u529F\u80FD","\u95EE\u9898","\u6A21\u5757","\u65B9\u6CD5","\u53D8\u91CF","\u542F\u7528","\u67E5\u770B","\u64CD\u4F5C","\u9700\u8981","\u6253\u5F00"]);function k(e){return!v.has(e)&&![...e].some(u=>x.has(u))}a(k,"k"),f(k,"isEvidence");function E(e){const u=[];let s="";const n=f(()=>{for(let r=0;r+1<s.length;r++)u.push(s.slice(r,r+2));s=""},"flush");for(const r of e)g.test(r)?s+=r:n();return n(),u}a(E,"g"),f(E,"bigrams");function h(e){return e.toLowerCase().match(m)??[]}a(h,"y"),f(h,"asciiWords");function w(e){const u=[],s=new Map;for(const i of e){const o=i.keywords.map(t=>{const l=t.toLowerCase();return g.test(l)?{text:l}:{text:l,words:h(l)}}),c=new Set;for(const t of[...i.keywords.flatMap(E),...E(i.hint)])k(t)&&c.add(t);for(const t of h(i.hint))t.length>=4&&c.add(t);for(const t of c)s.set(t,(s.get(t)??0)+1);u.push({capability:i,keywords:o,pieces:c})}const n=Math.max(1,u.length),r=new Map;for(const[i,o]of s)r.set(i,Math.log(1+n/o));return{entries:u,idf:r}}a(w,"_"),f(w,"buildIndex");const M=3,j=4;function y(e,u){if(u.length===0)return!1;e:for(let s=0;s+u.length<=e.length;s++){for(let n=0;n<u.length;n++)if(e[s+n]!==u[n])continue e;return!0}return!1}a(y,"h"),f(y,"containsWords");function F(e,u){const s=u.toLowerCase(),n=h(s),r=new Set([...E(s),...n.filter(o=>o.length>=4)]),i=[];for(const o of e.entries){const c=[];for(const d of o.keywords)(d.words?y(n,d.words):s.includes(d.text))&&c.push(d.text);const t=[];let l=0;for(const d of r)o.pieces.has(d)&&(t.push(d),l+=e.idf.get(d)??0);const p=o.capability.kind==="mcp"||o.capability.kind==="builtin";(c.length>0||p&&t.length>=2&&l>=j)&&i.push({capability:o.capability,score:c.length*M+l,keywords:c,pieces:t})}return i.sort((o,c)=>c.score-o.score)}a(F,"M"),f(F,"scoreRequest");const b=.85;function C(e,u){const s=e.filter(t=>t.capability.kind!=="skill"),n=e.find(t=>t.capability.kind==="skill"&&t.keywords.length>0);if(s.length===0)return{tied:[],scored:e,...n?{skill:n}:{}};const r=s[0],i=s.filter(t=>t.score>=r.score*b);if(i.length===1)return{tool:r,tied:[],scored:e,...n?{skill:n}:{}};const o=i.find(t=>i.every(l=>l===t||l.pieces.every(p=>t.pieces.includes(p))&&t.pieces.length>l.pieces.length));if(o)return{tool:o,tied:[],scored:e,...n?{skill:n}:{}};const c=i.filter(t=>u(t.capability.id));return c.length===1?{tool:c[0],tied:[],scored:e,...n?{skill:n}:{}}:{tied:i,scored:e,...n?{skill:n}:{}}}a(C,"O"),f(C,"route");function D(e,u){if(!u)return;const s=h(u),n=u.toLowerCase(),r=e.filter(i=>i.capability.keywords.some(o=>{if(g.test(o))return!1;const c=h(o);return c.join(" ").length>=4&&(y(s,c)||n.includes(`${c.join("")}://`))}));return r.length===1?r[0]:void 0}a(D,"K"),f(D,"breakTieByProject");export{b as TIE_RATIO,D as breakTieByProject,w as buildIndex,C as route,F as scoreRequest};
@@ -0,0 +1,3 @@
1
+ var J=Object.defineProperty;var n=(e,t)=>J(e,"name",{value:t,configurable:!0});var F=Object.defineProperty,s=n((e,t)=>F(e,"name",{value:t,configurable:!0}),"r");import{existsSync as T,readFileSync as l}from"node:fs";import{join as d}from"node:path";import{declaredDataFormat as R,withFileLockSync as D,writeFileAtomicSync as _}from"@dalcode/dal-pi-kit";const c=1;function u(e){return d(e,"capabilities.json")}n(u,"m"),s(u,"statePath");function N(){return{formatVersion:c,disabled:[],declined:[],approved:[],installed:{}}}n(N,"v"),s(N,"emptyState");function f(e){return Array.isArray(e)?e.filter(t=>typeof t=="string"):[]}n(f,"u"),s(f,"stringList");function p(e){try{const t=JSON.parse(l(u(e),"utf8"));return{...t,formatVersion:c,disabled:f(t.disabled),declined:f(t.declined),approved:f(t.approved),installed:t.installed&&typeof t.installed=="object"&&!Array.isArray(t.installed)?t.installed:{}}}catch{return N()}}n(p,"L"),s(p,"readState");function o(e,t){const a=u(e);return D(a,()=>{if(T(a))try{if(R(JSON.parse(l(a,"utf8")))>c)return p(e)}catch{}const i=p(e);return t(i),_(a,`${JSON.stringify(i,null,2)}
2
+ `),i})}n(o,"l"),s(o,"updateState");function I(e,t){e.includes(t)||e.push(t)}n(I,"f"),s(I,"addUnique");function O(e,t,a){o(e,i=>{i.disabled=i.disabled.filter(r=>r!==t),a?I(i.disabled,t):i.declined=i.declined.filter(r=>r!==t)})}n(O,"U"),s(O,"markDisabled");function g(e,t){o(e,a=>I(a.declined,t))}n(g,"j"),s(g,"markDeclined");function v(e,t){o(e,a=>I(a.approved,t))}n(v,"J"),s(v,"markApproved");function k(e,t,a,i){o(e,r=>{r.installed[t]={kind:a,at:new Date().toISOString(),...i?{version:i}:{}}})}n(k,"h"),s(k,"markInstalled");function m(e){try{const t=JSON.parse(l(e,"utf8")).capabilities;return t&&typeof t=="object"&&!Array.isArray(t)?t:void 0}catch{return}}n(m,"w"),s(m,"readCapabilitiesSetting");function E(e,t,a=process.env,i=".dal"){const r=m(d(e,"settings.json"))??{},j=m(d(t,i,"settings.json"))??{},y={...r,...j},A=s((C,h)=>typeof y[C]=="boolean"?y[C]:h,"flag"),b=/^(0|off|false|no)$/i,L=/^(1|on|true|yes)$/i,w=a.DAL_CAPABILITIES?.trim()??"",S=a.DAL_CAPABILITIES_AUTO_INSTALL?.trim()??"";return{enabled:!b.test(w)&&A("enabled",!0),autoInstall:b.test(S)?!1:L.test(S)?!0:A("autoInstall",!0),allowInCI:L.test(S)||A("allowInCI",!1)}}n(E,"F"),s(E,"readSettings");function B(e,t){const a=d(e,"settings.json");D(a,()=>{let i={};T(a)&&(i=JSON.parse(l(a,"utf8")));const r=i.capabilities&&typeof i.capabilities=="object"&&!Array.isArray(i.capabilities)?i.capabilities:{};i.capabilities={...r,autoInstall:t},_(a,`${JSON.stringify(i,null,2)}
3
+ `)})}n(B,"P"),s(B,"writeAutoInstall");const P=["GITHUB_ACTIONS","GITLAB_CI","BUILDKITE","JENKINS_URL","TF_BUILD","TEAMCITY_VERSION","CIRCLECI","DRONE","GITEA_ACTIONS","BITBUCKET_BUILD_NUMBER","CODEBUILD_BUILD_ID"];function U(e=process.env){const t=e.CI?.trim().toLowerCase();return t&&t!=="0"&&t!=="false"?!0:P.some(a=>!!e[a]?.trim())}n(U,"V"),s(U,"isCiLike");export{c as STATE_FORMAT,U as isCiLike,v as markApproved,g as markDeclined,O as markDisabled,k as markInstalled,E as readSettings,p as readState,u as statePath,o as updateState,B as writeAutoInstall};
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Mario Zechner
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "@dalcode/dal-compat",
3
+ "version": "1.0.40",
4
+ "private": true,
5
+ "description": "Claude Code compatibility: the user's and project's .claude/rules/ and .claude/CLAUDE.md apply in DAL. Grown from the claude-rules extension example.",
6
+ "type": "module",
7
+ "main": "./src/index.js",
8
+ "exports": {
9
+ ".": "./src/index.js",
10
+ "./package.json": "./package.json"
11
+ },
12
+ "files": [
13
+ "src"
14
+ ],
15
+ "pi": {
16
+ "extensions": [
17
+ "./src/index.js"
18
+ ]
19
+ },
20
+ "dependencies": {
21
+ "@dalcode/dal-pi-kit": "1.0.40",
22
+ "minimatch": "10.2.6"
23
+ },
24
+ "peerDependencies": {
25
+ "@earendil-works/pi-coding-agent": "^1.0.9"
26
+ },
27
+ "peerDependenciesMeta": {
28
+ "@earendil-works/pi-coding-agent": {
29
+ "optional": false
30
+ }
31
+ }
32
+ }
@@ -0,0 +1,3 @@
1
+ var A=Object.defineProperty;var m=(e,t)=>A(e,"name",{value:t,configurable:!0});var D=Object.defineProperty,u=m((e,t)=>D(e,"name",{value:t,configurable:!0}),"l");import{existsSync as E,readdirSync as M,readFileSync as T,realpathSync as $,statSync as F}from"node:fs";import{homedir as R}from"node:os";import{dirname as k,join as S,relative as B,resolve as p,sep as U}from"node:path";import{minimatch as Y}from"minimatch";const _=64*1024,v=256*1024,q=6;function b(e){const t=e.replace(/^/,"").replace(/\r\n/g,`
2
+ `),o=/^---\n([\s\S]*?)\n---\n?/.exec(t);if(!o)return{content:t.trim()};const n=t.slice(o[0].length).trim(),s=o[1].split(`
3
+ `),c=[],a=u(i=>i.trim().replace(/^["']|["']$/g,""),"unquote");for(let i=0;i<s.length;i++){const L=/^paths\s*:\s*(.*)$/.exec(s[i]);if(!L)continue;const r=L[1].trim();if(r.startsWith("["))c.push(...r.replace(/^\[|\]$/g,"").split(",").map(a));else if(r)c.push(...r.split(",").map(a));else for(let l=i+1;l<s.length;l++){const h=/^\s*-\s*(.+)$/.exec(s[l]);if(!h)break;c.push(a(h[1]))}}const y=c.filter(i=>i.length>0);return y.length>0?{content:n,paths:y}:{content:n}}m(b,"$"),u(b,"parseRuleFile");function w(e,t=0){if(t>q)return[];let o;try{o=M(e).sort()}catch{return[]}const n=[];for(const s of o){if(s.startsWith("."))continue;const c=S(e,s);let a;try{a=F(c)}catch{continue}a.isDirectory()?n.push(...w(c,t+1)):a.isFile()&&s.toLowerCase().endsWith(".md")&&n.push(c)}return n}m(w,"b"),u(w,"markdownFiles");function j(e,t=R()){const o=[];let n=p(e);for(;;){if(n!==p(t)&&o.push(n),E(S(n,".git")))return o.reverse();const s=k(n);if(s===n)break;n=s}return p(e)===p(t)?[]:[p(e)]}m(j,"k"),u(j,"projectDirs");function C(e){const t=e.home??R(),o=new Set,n=u(r=>{try{return $(r)}catch{return r}},"canonical");for(const r of e.alreadyLoaded??[])o.add(n(r));const s=[];let c=0;const a=u((r,l,h)=>{const f=n(r);if(o.has(f)||!f.toLowerCase().endsWith(".md"))return;o.add(f);let g;try{if(F(f).size>_)return;g=T(f,"utf8")}catch{return}const d=b(g);if(!d.content)return;const x=Buffer.byteLength(d.content);c+x>v||(c+=x,s.push({path:r,scope:l,content:d.content,...d.paths?{paths:d.paths,base:h}:{}}))},"add"),y=u((r,l,h)=>{const f=S(r,".claude"),g=S(f,"CLAUDE.md");E(g)&&a(g,l,h);for(const d of w(S(f,"rules")))a(d,l,h)},"scan");y(t,"user",p(e.cwd));const i=j(e.cwd,t),L=i[0]??p(e.cwd);for(const r of i)y(r,"project",L);return s}m(C,"Y"),u(C,"findClaudeRules");function W(e,t,o){if(!e.paths||!e.base)return!1;const n=p(o,t),s=B(e.base,n);if(s.startsWith(".."))return!1;const c=s.split(U).join("/");return e.paths.some(a=>Y(c,a.replace(/^\.\//,""),{dot:!0}))}m(W,"q"),u(W,"ruleMatches");export{v as MAX_RULES_TOTAL_BYTES,_ as MAX_RULE_FILE_BYTES,C as findClaudeRules,b as parseRuleFile,j as projectDirs,W as ruleMatches};
@@ -0,0 +1,7 @@
1
+ var E=Object.defineProperty;var s=(t,e)=>E(t,"name",{value:e,configurable:!0});var g=Object.defineProperty,i=s((t,e)=>g(t,"name",{value:e,configurable:!0}),"r");import{readFileSync as R}from"node:fs";import{join as y}from"node:path";import{t as F}from"@dalcode/dal-pi-kit";import{getAgentDir as S}from"@earendil-works/pi-coding-agent";import{findClaudeRules as C,ruleMatches as T}from"./claude-rules.js";import{findClaudeRules as j,MAX_RULE_FILE_BYTES as w,MAX_RULES_TOTAL_BYTES as x,parseRuleFile as L,projectDirs as A,ruleMatches as M}from"./claude-rules.js";const v=new Set(["read","edit","write"]);function m(t,e){if(e.includes("--no-context-files")||e.includes("-nc"))return!1;try{return JSON.parse(R(y(t,"settings.json"),"utf8")).dalCompat?.claudeRules!==!1}catch{return!0}}s(m,"E"),i(m,"claudeRulesEnabled");function f(t){return`<project_instructions path="${t.path}" applies_to="${(t.paths??[]).join(", ")}">
2
+ ${t.content}
3
+ </project_instructions>`}s(f,"w"),i(f,"conditionalRuleText");function d(t={}){return i(function(e){let u=!1,l=process.cwd(),r=[];const p=new Set,h=i(o=>{r=C({cwd:l,...t.home?{home:t.home}:{},alreadyLoaded:o})},"rescan");e.on("session_start",async(o,n)=>{l=n.cwd,p.clear(),u=m(S(),t.argv??process.argv),u&&(h([]),r.length>0&&n.mode==="tui"&&n.ui.notify(F("\u5DF2\u5E94\u7528 {count} \u4E2A Claude Code \u89C4\u5219\u6587\u4EF6\uFF08.claude/\uFF09").replace("{count}",String(r.length)),"info"))}),e.on("before_agent_start",async o=>{if(!u)return;const n=o.systemPromptOptions;h(n.contextFiles.map(a=>a.path));for(const a of r)a.paths||n.contextFiles.push({path:a.path,content:a.content})}),e.on("tool_result",async o=>{if(!u||o.isError||!v.has(o.toolName))return;const n=typeof o.input.path=="string"?o.input.path:void 0;if(!n)return;const a=r.filter(c=>!p.has(c.path)&&T(c,n,l));if(a.length===0)return;for(const c of a)p.add(c.path);const _=["The following project rules apply to this file; follow them:",...a.map(f)].join(`
4
+
5
+ `);return{content:[...o.content,{type:"text",text:`
6
+
7
+ ${_}`}]}})},"dalCompat")}s(d,"S"),i(d,"createDalCompat");var D=d();export{x as MAX_RULES_TOTAL_BYTES,w as MAX_RULE_FILE_BYTES,f as conditionalRuleText,d as createDalCompat,D as default,j as findClaudeRules,L as parseRuleFile,A as projectDirs,M as ruleMatches};