dal-code 1.0.44 → 1.0.46

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (780) hide show
  1. package/CHANGELOG.md +103 -0
  2. package/NOTICE +66 -1
  3. package/PRIVACY.md +159 -102
  4. package/dal-docs/README.md +1 -1
  5. package/dal-docs/keybindings.md +1 -0
  6. package/dal-docs/settings.md +5 -0
  7. package/dist/bun/register-bedrock.js +1 -0
  8. package/dist/cli/args.js +2 -2
  9. package/dist/cli/auth-check.js +1 -1
  10. package/dist/cli/auth-command.js +6 -5
  11. package/dist/cli/credential-print.js +1 -1
  12. package/dist/cli/experimental/auth.js +1 -0
  13. package/dist/cli/experimental/cli.js +1 -0
  14. package/dist/cli/experimental/command-options.js +1 -0
  15. package/dist/cli/experimental/command.js +1 -0
  16. package/dist/cli/experimental/commands/client.js +1 -0
  17. package/dist/cli/experimental/commands/pi.js +1 -0
  18. package/dist/cli/experimental/commands/server.js +1 -0
  19. package/dist/cli/experimental/transport-address.js +1 -0
  20. package/dist/cli/list-models.js +2 -2
  21. package/dist/cli/piped-stdin.js +2 -0
  22. package/dist/cli/startup-diagnostics.js +1 -0
  23. package/dist/client/index.js +1 -0
  24. package/dist/client/remote-session.js +1 -0
  25. package/dist/client/transcript.js +1 -0
  26. package/dist/config.d.ts +1 -0
  27. package/dist/config.js +1 -1
  28. package/dist/core/agent-log.d.ts +6 -0
  29. package/dist/core/agent-log.js +3 -0
  30. package/dist/core/agent-session-runtime.js +1 -1
  31. package/dist/core/agent-session-services.d.ts +0 -1
  32. package/dist/core/agent-session-services.js +1 -1
  33. package/dist/core/agent-session.d.ts +20 -3
  34. package/dist/core/agent-session.js +8 -8
  35. package/dist/core/auth-storage.js +1 -1
  36. package/dist/core/background-processes.js +7 -7
  37. package/dist/core/client-identity.js +1 -0
  38. package/dist/core/compaction/branch-summarization.js +3 -3
  39. package/dist/core/compaction/compaction.d.ts +2 -2
  40. package/dist/core/compaction/compaction.js +11 -9
  41. package/dist/core/compaction-backoff.js +1 -0
  42. package/dist/core/dal-session-headers.js +1 -0
  43. package/dist/core/export-html/index.js +2 -2
  44. package/dist/core/export-html/template.html +1 -0
  45. package/dist/core/export-html/template.js +35 -35
  46. package/dist/core/export-html/vendor/marked-cjk-friendly.min.js +6 -0
  47. package/dist/core/export-html/vendor/marked.min.js +30 -29
  48. package/dist/core/extensions/loader.js +1 -1
  49. package/dist/core/extensions/runner.d.ts +6 -0
  50. package/dist/core/extensions/runner.js +1 -1
  51. package/dist/core/extensions/types.d.ts +6 -1
  52. package/dist/core/extensions/virtual-modules.js +1 -1
  53. package/dist/core/http-dispatcher.js +1 -1
  54. package/dist/core/key-id-schema.js +1 -0
  55. package/dist/core/keybindings-schema.js +1 -0
  56. package/dist/core/keybindings.d.ts +5 -0
  57. package/dist/core/keybindings.js +1 -1
  58. package/dist/core/model-config.d.ts +1805 -102
  59. package/dist/core/model-config.js +4 -4
  60. package/dist/core/model-identity.js +2 -0
  61. package/dist/core/model-resolver.d.ts +30 -10
  62. package/dist/core/model-resolver.js +1 -1
  63. package/dist/core/model-runtime.d.ts +3 -0
  64. package/dist/core/model-runtime.js +2 -2
  65. package/dist/core/package-manager.d.ts +7 -0
  66. package/dist/core/package-manager.js +2 -2
  67. package/dist/core/permissions/shell-words.d.ts +26 -0
  68. package/dist/core/project-trust.js +2 -2
  69. package/dist/core/prompt-templates.js +2 -2
  70. package/dist/core/provider-attribution.js +1 -1
  71. package/dist/core/provider-composer.d.ts +2 -1
  72. package/dist/core/provider-composer.js +1 -1
  73. package/dist/core/remote-catalog-provider.js +1 -1
  74. package/dist/core/resource-loader.js +1 -1
  75. package/dist/core/sandbox/bwrap-placeholders.js +1 -1
  76. package/dist/core/sandbox/index.d.ts +1 -1
  77. package/dist/core/sandbox/index.js +1 -1
  78. package/dist/core/sandbox/libreoffice.js +1 -0
  79. package/dist/core/sandbox/policy.d.ts +4 -0
  80. package/dist/core/sandbox/policy.js +1 -1
  81. package/dist/core/sandbox/runtime.d.ts +3 -0
  82. package/dist/core/sandbox/runtime.js +1 -1
  83. package/dist/core/sandbox/shell-sandbox.d.ts +2 -0
  84. package/dist/core/sandbox/shell-sandbox.js +6 -6
  85. package/dist/core/sandbox/windows.js +4 -4
  86. package/dist/core/sdk.js +1 -1
  87. package/dist/core/session-manager.d.ts +1 -0
  88. package/dist/core/session-manager.js +12 -12
  89. package/dist/core/session-stall-monitor.d.ts +41 -0
  90. package/dist/core/session-stall-monitor.js +2 -0
  91. package/dist/core/settings-defaults.js +1 -0
  92. package/dist/core/settings-manager.d.ts +9 -0
  93. package/dist/core/settings-manager.js +1 -1
  94. package/dist/core/settings-schema.d.ts +231 -0
  95. package/dist/core/settings-schema.js +1 -0
  96. package/dist/core/stall-watchdog.d.ts +55 -0
  97. package/dist/core/stall-watchdog.js +1 -0
  98. package/dist/core/system-prompt.js +10 -10
  99. package/dist/core/tools/bash-read-only.d.ts +1 -0
  100. package/dist/core/tools/bash.d.ts +1 -0
  101. package/dist/core/tools/bash.js +14 -14
  102. package/dist/core/tools/edit.d.ts +1 -1
  103. package/dist/core/tools/edit.js +3 -3
  104. package/dist/core/tools/grep.js +1 -1
  105. package/dist/core/tools/path-utils.d.ts +1 -0
  106. package/dist/core/tools/path-utils.js +1 -1
  107. package/dist/core/tools/read.js +12 -12
  108. package/dist/core/tools/render-utils.d.ts +40 -0
  109. package/dist/core/tools/render-utils.js +7 -7
  110. package/dist/core/tools/renderers/read.js +8 -8
  111. package/dist/core/trust-manager.js +1 -1
  112. package/dist/core/workspace-lock.d.ts +6 -2
  113. package/dist/core/workspace-lock.js +3 -3
  114. package/dist/dal/builtins.js +2 -2
  115. package/dist/dal/extension-compat.js +4 -4
  116. package/dist/dal/hooks/config.d.ts +5 -1
  117. package/dist/dal/hooks/config.js +1 -1
  118. package/dist/dal/hooks/extension.js +3 -3
  119. package/dist/dal/hooks/index.d.ts +1 -1
  120. package/dist/dal/hooks/index.js +1 -1
  121. package/dist/dal/i18n.js +1 -1
  122. package/dist/dal/manifest.d.ts +1 -0
  123. package/dist/dal/manifest.js +1 -1
  124. package/dist/dal/safety-net.js +3 -1
  125. package/dist/extensions/codemode/execute.js +22 -15
  126. package/dist/extensions/codemode/index.js +1 -1
  127. package/dist/extensions/codemode/renderer.js +6 -6
  128. package/dist/extensions/codemode/tool.d.ts +2 -3
  129. package/dist/extensions/codemode/tool.js +9 -12
  130. package/dist/extensions/mcp/cli.js +4 -4
  131. package/dist/extensions/mcp/config.js +2 -2
  132. package/dist/extensions/mcp/index.js +12 -12
  133. package/dist/extensions/mcp/oauth.js +2 -2
  134. package/dist/extensions/mcp/resources.d.ts +0 -5
  135. package/dist/extensions/mcp/resources.js +1 -1
  136. package/dist/extensions/mcp/runtime.d.ts +1 -4
  137. package/dist/extensions/mcp/runtime.js +3 -3
  138. package/dist/extensions/mcp/tools.js +7 -7
  139. package/dist/extensions/tool-search/tool.js +3 -3
  140. package/dist/index.d.ts +7 -3
  141. package/dist/index.js +1 -1
  142. package/dist/main.js +4 -4
  143. package/dist/migrations.js +3 -5
  144. package/dist/modes/interactive/components/daxnuts.js +1 -0
  145. package/dist/modes/interactive/components/settings-selector.d.ts +3 -1
  146. package/dist/modes/interactive/components/settings-selector.js +1 -1
  147. package/dist/modes/interactive/components/status-indicator.d.ts +1 -1
  148. package/dist/modes/interactive/components/status-indicator.js +1 -1
  149. package/dist/modes/interactive/components/tree-selector.js +1 -1
  150. package/dist/modes/interactive/external-editor.js +1 -1
  151. package/dist/modes/interactive/interactive-mode.d.ts +7 -7
  152. package/dist/modes/interactive/interactive-mode.js +26 -26
  153. package/dist/modes/interactive/session-share.js +2 -2
  154. package/dist/modes/interactive/theme/dark.json +1 -1
  155. package/dist/modes/interactive/theme/light.json +1 -1
  156. package/dist/modes/interactive/theme/theme-json.js +4 -4
  157. package/dist/modes/interactive/theme/theme-schema.d.ts +18 -0
  158. package/dist/modes/interactive/theme/theme-schema.js +12 -0
  159. package/dist/modes/interactive/theme/theme-schema.json +2 -7
  160. package/dist/modes/interactive/theme/theme-tokens.d.ts +255 -0
  161. package/dist/modes/interactive/theme/theme-tokens.js +1 -0
  162. package/dist/modes/interactive/theme/theme.d.ts +7 -10
  163. package/dist/modes/interactive/theme/theme.js +5 -5
  164. package/dist/modes/print-mode.d.ts +1 -0
  165. package/dist/modes/print-mode.js +8 -7
  166. package/dist/modes/rpc/rpc-client.d.ts +5 -1
  167. package/dist/modes/rpc/rpc-client.js +3 -3
  168. package/dist/modes/rpc/rpc-mode.js +1 -1
  169. package/dist/modes/rpc/rpc-types.d.ts +20 -0
  170. package/dist/node_modules/@dalcode/dal-advisor/package.json +3 -3
  171. package/dist/node_modules/@dalcode/dal-advisor/src/index.js +8 -8
  172. package/dist/node_modules/@dalcode/dal-awake/package.json +2 -2
  173. package/dist/node_modules/@dalcode/dal-bridge/package.json +2 -2
  174. package/dist/node_modules/@dalcode/dal-capabilities/package.json +4 -4
  175. package/dist/node_modules/@dalcode/dal-capabilities/src/catalogue.js +1 -1
  176. package/dist/node_modules/@dalcode/dal-capabilities/src/index.js +9 -9
  177. package/dist/node_modules/@dalcode/dal-capabilities/src/match.js +1 -1
  178. package/dist/node_modules/@dalcode/dal-capabilities/src/state.js +3 -3
  179. package/dist/node_modules/@dalcode/dal-codeindex/package.json +34 -0
  180. package/dist/node_modules/@dalcode/dal-codeindex/src/extract.js +3 -0
  181. package/dist/node_modules/@dalcode/dal-codeindex/src/format.js +11 -0
  182. package/dist/node_modules/@dalcode/dal-codeindex/src/index.js +4 -0
  183. package/dist/node_modules/@dalcode/dal-codeindex/src/indexer.js +1 -0
  184. package/dist/node_modules/@dalcode/dal-codeindex/src/languages.js +176 -0
  185. package/dist/node_modules/@dalcode/dal-codeindex/src/project.js +1 -0
  186. package/dist/node_modules/@dalcode/dal-codeindex/src/query.js +2 -0
  187. package/dist/node_modules/@dalcode/dal-codeindex/src/runtime.js +1 -0
  188. package/dist/node_modules/@dalcode/dal-codeindex/src/scan.js +1 -0
  189. package/dist/node_modules/@dalcode/dal-codeindex/src/semantic.js +2 -0
  190. package/dist/node_modules/@dalcode/dal-codeindex/src/sqlite.js +1 -0
  191. package/dist/node_modules/@dalcode/dal-codeindex/src/store.js +33 -0
  192. package/dist/node_modules/@dalcode/dal-codeindex/src/worker.js +1 -0
  193. package/dist/node_modules/@dalcode/dal-compat/package.json +2 -2
  194. package/dist/node_modules/@dalcode/dal-dap/package.json +2 -2
  195. package/dist/node_modules/@dalcode/dal-dap/src/install.js +2 -2
  196. package/dist/node_modules/@dalcode/dal-gateway/package.json +2 -2
  197. package/dist/node_modules/@dalcode/dal-goal/package.json +3 -3
  198. package/dist/node_modules/@dalcode/dal-guard/package.json +5 -4
  199. package/dist/node_modules/@dalcode/dal-guard/src/credentials.js +7 -1
  200. package/dist/node_modules/@dalcode/dal-guard/src/edit-anchor-core.js +25 -23
  201. package/dist/node_modules/@dalcode/dal-guard/src/edit-anchor.js +4 -4
  202. package/dist/node_modules/@dalcode/dal-guard/src/index.js +4 -2
  203. package/dist/node_modules/@dalcode/dal-guard/src/mode.js +2 -2
  204. package/dist/node_modules/@dalcode/dal-guard/src/policy.js +1 -0
  205. package/dist/node_modules/@dalcode/dal-guard/src/session-files.js +1 -0
  206. package/dist/node_modules/@dalcode/dal-guard/src/suspicion.js +1 -0
  207. package/dist/node_modules/@dalcode/dal-guard/src/workspace.js +2 -2
  208. package/dist/node_modules/@dalcode/dal-halo/package.json +1 -1
  209. package/dist/node_modules/@dalcode/dal-interactive/package.json +2 -2
  210. package/dist/node_modules/@dalcode/dal-lang/package.json +3 -3
  211. package/dist/node_modules/@dalcode/dal-learn/package.json +4 -2
  212. package/dist/node_modules/@dalcode/dal-learn/src/engine.js +4 -4
  213. package/dist/node_modules/@dalcode/dal-learn/src/index.js +15 -14
  214. package/dist/node_modules/@dalcode/dal-learn/src/revisions.js +3 -0
  215. package/dist/node_modules/@dalcode/dal-learn/src/safety.js +1 -1
  216. package/dist/node_modules/@dalcode/dal-learn/src/skill-evolution.js +14 -14
  217. package/dist/node_modules/@dalcode/dal-lsp/package.json +5 -3
  218. package/dist/node_modules/@dalcode/dal-lsp/src/config.js +1 -1
  219. package/dist/node_modules/@dalcode/dal-lsp/src/index.js +14 -11
  220. package/dist/node_modules/@dalcode/dal-lsp/src/managed.js +1 -0
  221. package/dist/node_modules/@dalcode/dal-mcp/package.json +8 -5
  222. package/dist/node_modules/@dalcode/dal-mcp/src/child-env.js +3 -0
  223. package/dist/node_modules/@dalcode/dal-mcp/src/http-client.d.ts +9 -27
  224. package/dist/node_modules/@dalcode/dal-mcp/src/http-client.js +1 -2
  225. package/dist/node_modules/@dalcode/dal-mcp/src/index.js +17 -17
  226. package/dist/node_modules/@dalcode/dal-mcp/src/protocol-client.d.ts +38 -0
  227. package/dist/node_modules/@dalcode/dal-mcp/src/protocol-client.js +1 -0
  228. package/dist/node_modules/@dalcode/dal-mcp/src/proxy.js +6 -6
  229. package/dist/node_modules/@dalcode/dal-mcp/src/resources.js +1 -0
  230. package/dist/node_modules/@dalcode/dal-mcp/src/stdio-client.d.ts +10 -18
  231. package/dist/node_modules/@dalcode/dal-mcp/src/stdio-client.js +4 -5
  232. package/dist/node_modules/@dalcode/dal-mcp/src/types.d.ts +50 -5
  233. package/dist/node_modules/@dalcode/dal-mcp/src/types.js +1 -1
  234. package/dist/node_modules/@dalcode/dal-office/package.json +3 -2
  235. package/dist/node_modules/@dalcode/dal-office/src/extract/cell.js +1 -0
  236. package/dist/node_modules/@dalcode/dal-office/src/extract/index.js +2 -2
  237. package/dist/node_modules/@dalcode/dal-office/src/extract/ooxml.js +4 -4
  238. package/dist/node_modules/@dalcode/dal-office/src/extract/pdf.js +4 -4
  239. package/dist/node_modules/@dalcode/dal-office/src/facts.d.ts +15 -0
  240. package/dist/node_modules/@dalcode/dal-office/src/facts.js +4 -0
  241. package/dist/node_modules/@dalcode/dal-office/src/index.js +1 -1
  242. package/dist/node_modules/@dalcode/dal-office/src/lazy.js +1 -0
  243. package/dist/node_modules/@dalcode/dal-office/src/{index.d.ts → office.d.ts} +4 -5
  244. package/dist/node_modules/@dalcode/dal-office/src/office.js +1 -0
  245. package/dist/node_modules/@dalcode/dal-office/src/render/capture.d.ts +21 -0
  246. package/dist/node_modules/@dalcode/dal-office/src/render/capture.js +13 -0
  247. package/dist/node_modules/@dalcode/dal-office/src/render/chart.d.ts +15 -0
  248. package/dist/node_modules/@dalcode/dal-office/src/render/chart.js +3 -3
  249. package/dist/node_modules/@dalcode/dal-office/src/render/docx.d.ts +4 -0
  250. package/dist/node_modules/@dalcode/dal-office/src/render/docx.js +1 -1
  251. package/dist/node_modules/@dalcode/dal-office/src/render/pptx.d.ts +10 -0
  252. package/dist/node_modules/@dalcode/dal-office/src/render/pptx.js +4 -3
  253. package/dist/node_modules/@dalcode/dal-office/src/render/table-layout.js +1 -0
  254. package/dist/node_modules/@dalcode/dal-office/src/render/xlsx-chart.d.ts +24 -0
  255. package/dist/node_modules/@dalcode/dal-office/src/render/xlsx-chart.js +1 -0
  256. package/dist/node_modules/@dalcode/dal-office/src/render/xlsx.d.ts +9 -0
  257. package/dist/node_modules/@dalcode/dal-office/src/render/xlsx.js +1 -1
  258. package/dist/node_modules/@dalcode/dal-office/src/scratchpad.d.ts +2 -0
  259. package/dist/node_modules/@dalcode/dal-office/src/scratchpad.js +1 -1
  260. package/dist/node_modules/@dalcode/dal-office/src/table-stats.js +2 -0
  261. package/dist/node_modules/@dalcode/dal-office/src/themes.d.ts +2 -0
  262. package/dist/node_modules/@dalcode/dal-office/src/themes.js +1 -1
  263. package/dist/node_modules/@dalcode/dal-office/src/tools/chart-generate.js +4 -3
  264. package/dist/node_modules/@dalcode/dal-office/src/tools/doc-generate.js +2 -3
  265. package/dist/node_modules/@dalcode/dal-office/src/tools/docx-edit.js +5 -5
  266. package/dist/node_modules/@dalcode/dal-office/src/tools/drawio-generate.js +2 -3
  267. package/dist/node_modules/@dalcode/dal-office/src/tools/md-generate.js +2 -3
  268. package/dist/node_modules/@dalcode/dal-office/src/tools/ppt-generate.js +5 -2
  269. package/dist/node_modules/@dalcode/dal-office/src/tools/ppt-plan.js +4 -2
  270. package/dist/node_modules/@dalcode/dal-office/src/tools/pptx-edit.js +5 -5
  271. package/dist/node_modules/@dalcode/dal-office/src/tools/read-file.js +4 -3
  272. package/dist/node_modules/@dalcode/dal-office/src/tools/render-page.js +4 -0
  273. package/dist/node_modules/@dalcode/dal-office/src/tools/sheet-generate.js +3 -3
  274. package/dist/node_modules/@dalcode/dal-office/src/tools/xlsx-edit.js +3 -3
  275. package/dist/node_modules/@dalcode/dal-pi-kit/dist/i18n.js +19 -13
  276. package/dist/node_modules/@dalcode/dal-pi-kit/dist/index.js +1 -1
  277. package/dist/node_modules/@dalcode/dal-pi-kit/dist/project-size.js +1 -0
  278. package/dist/node_modules/@dalcode/dal-pi-kit/dist/session-scope.js +1 -0
  279. package/dist/node_modules/@dalcode/dal-pi-kit/package.json +1 -1
  280. package/dist/node_modules/@dalcode/dal-pi-kit/src/i18n.js +19 -13
  281. package/dist/node_modules/@dalcode/dal-pi-kit/src/index.js +1 -1
  282. package/dist/node_modules/@dalcode/dal-pi-kit/src/project-size.js +1 -0
  283. package/dist/node_modules/@dalcode/dal-pi-kit/src/session-scope.js +1 -0
  284. package/dist/node_modules/@dalcode/dal-plugins/package.json +4 -5
  285. package/dist/node_modules/@dalcode/dal-plugins/src/brand.js +1 -1
  286. package/dist/node_modules/@dalcode/dal-plugins/src/index.js +10 -10
  287. package/dist/node_modules/@dalcode/dal-plugins/src/manage.js +7 -7
  288. package/dist/node_modules/@dalcode/dal-recall/package.json +2 -2
  289. package/dist/node_modules/@dalcode/dal-recall/src/index.js +1 -1
  290. package/dist/node_modules/@dalcode/dal-remote/package.json +2 -2
  291. package/dist/node_modules/@dalcode/dal-review/package.json +3 -3
  292. package/dist/node_modules/@dalcode/dal-rewind/package.json +2 -2
  293. package/dist/node_modules/@dalcode/dal-rewind/src/commands.js +1 -1
  294. package/dist/node_modules/@dalcode/dal-rewind/src/core.d.ts +2 -1
  295. package/dist/node_modules/@dalcode/dal-rewind/src/core.js +8 -8
  296. package/dist/node_modules/@dalcode/dal-rewind/src/index.js +1 -1
  297. package/dist/node_modules/@dalcode/dal-rewind/src/state.js +1 -1
  298. package/dist/node_modules/@dalcode/dal-router/package.json +13 -10
  299. package/dist/node_modules/@dalcode/dal-router/src/advisor.js +1 -1
  300. package/dist/node_modules/@dalcode/dal-router/src/commands.js +8 -8
  301. package/dist/node_modules/@dalcode/dal-router/src/config.d.ts +12 -34
  302. package/dist/node_modules/@dalcode/dal-router/src/config.js +2 -2
  303. package/dist/node_modules/@dalcode/dal-router/src/index.js +2 -4
  304. package/dist/node_modules/@dalcode/dal-router/src/notice.js +1 -0
  305. package/dist/node_modules/@dalcode/dal-router/src/roles/changes.js +5 -0
  306. package/dist/node_modules/@dalcode/dal-router/src/roles/deliverables.js +4 -0
  307. package/dist/node_modules/@dalcode/dal-router/src/roles/index.js +15 -0
  308. package/dist/node_modules/@dalcode/dal-router/src/roles/models.d.ts +50 -0
  309. package/dist/node_modules/@dalcode/dal-router/src/roles/models.js +1 -0
  310. package/dist/node_modules/@dalcode/dal-router/src/roles/planner.js +4 -0
  311. package/dist/node_modules/@dalcode/dal-router/src/roles/prompts.js +42 -0
  312. package/dist/node_modules/@dalcode/dal-router/src/roles/signals.js +2 -0
  313. package/dist/node_modules/@dalcode/dal-router/src/runtime.d.ts +3 -13
  314. package/dist/node_modules/@dalcode/dal-router/src/runtime.js +1 -1
  315. package/dist/node_modules/@dalcode/dal-router/src/subagent.js +1 -1
  316. package/dist/node_modules/@dalcode/dal-router/src/task-shape.d.ts +8 -0
  317. package/dist/node_modules/@dalcode/dal-router/src/task-shape.js +1 -0
  318. package/dist/node_modules/@dalcode/dal-rtk/package.json +2 -2
  319. package/dist/node_modules/@dalcode/dal-skills/package.json +4 -3
  320. package/dist/node_modules/@dalcode/dal-skills/src/bundled/chart-design/SKILL.md +35 -0
  321. package/dist/node_modules/@dalcode/dal-skills/src/bundled/dal-slides/SKILL.md +82 -0
  322. package/dist/node_modules/@dalcode/dal-skills/src/bundled/diagram-design/SKILL.md +7 -5
  323. package/dist/node_modules/@dalcode/dal-skills/src/bundled/poster-design/SKILL.md +8 -6
  324. package/dist/node_modules/@dalcode/dal-skills/src/bundled/print-design/SKILL.md +21 -8
  325. package/dist/node_modules/@dalcode/dal-skills/src/bundled/visual-kit/diagram.html +1 -1
  326. package/dist/node_modules/@dalcode/dal-skills/src/bundled/visual-kit/mindmap.html +1 -1
  327. package/dist/node_modules/@dalcode/dal-skills/src/bundled/visual-kit/posters/event-poster.html +1 -1
  328. package/dist/node_modules/@dalcode/dal-skills/src/bundled/visual-kit/posters/poster.css +1 -1
  329. package/dist/node_modules/@dalcode/dal-skills/src/bundled/visual-kit/posters/square-card.html +1 -1
  330. package/dist/node_modules/@dalcode/dal-skills/src/bundled/visual-kit/posters/wechat-cover.html +1 -1
  331. package/dist/node_modules/@dalcode/dal-skills/src/bundled/visual-kit/posters/xhs-card.html +1 -1
  332. package/dist/node_modules/@dalcode/dal-skills/src/bundled/visual-kit/posters/xhs-cover.html +8 -5
  333. package/dist/node_modules/@dalcode/dal-skills/src/bundled/visual-kit/print/letter.html +1 -1
  334. package/dist/node_modules/@dalcode/dal-skills/src/bundled/visual-kit/print/report.html +1 -1
  335. package/dist/node_modules/@dalcode/dal-skills/src/bundled/visual-kit/print/resume.html +7 -3
  336. package/dist/node_modules/@dalcode/dal-skills/src/bundled/web-design/SKILL.md +4 -4
  337. package/dist/node_modules/@dalcode/dal-skills/src/bundled.js +1 -1
  338. package/dist/node_modules/@dalcode/dal-skills/src/catalog.js +3 -2
  339. package/dist/node_modules/@dalcode/dal-skills/src/client.js +1 -1
  340. package/dist/node_modules/@dalcode/dal-skills/src/hint.js +1 -0
  341. package/dist/node_modules/@dalcode/dal-skills/src/index.js +13 -14
  342. package/dist/node_modules/@dalcode/dal-skills/src/packages.js +3 -3
  343. package/dist/node_modules/@dalcode/dal-skills/src/search.js +1 -1
  344. package/dist/node_modules/@dalcode/dal-statusline/package.json +2 -2
  345. package/dist/node_modules/@dalcode/dal-structured/package.json +2 -2
  346. package/dist/node_modules/@dalcode/dal-subagent/package.json +5 -5
  347. package/dist/node_modules/@dalcode/dal-subagent/src/background.js +10 -10
  348. package/dist/node_modules/@dalcode/dal-subagent/src/index.js +18 -20
  349. package/dist/node_modules/@dalcode/dal-telemetry/package.json +3 -3
  350. package/dist/node_modules/@dalcode/dal-terminal/package.json +2 -2
  351. package/dist/node_modules/@dalcode/dal-tool-catalog/package.json +2 -2
  352. package/dist/node_modules/@dalcode/dal-tool-catalog/src/groups.js +1 -1
  353. package/dist/node_modules/@dalcode/dal-tool-catalog/src/index.js +4 -4
  354. package/dist/node_modules/@dalcode/dal-usage/package.json +2 -2
  355. package/dist/node_modules/@dalcode/dal-web/package.json +3 -3
  356. package/dist/node_modules/@dalcode/dal-workflow/LICENSE +27 -0
  357. package/dist/node_modules/@dalcode/dal-workflow/package.json +2 -2
  358. package/dist/node_modules/@dalcode/dal-workflow/src/announce-check.js +3 -1
  359. package/dist/node_modules/@dalcode/dal-workflow/src/deliverable-scope.js +1 -0
  360. package/dist/node_modules/@dalcode/dal-workflow/src/index.js +4 -4
  361. package/dist/node_modules/@dalcode/dal-workflow/src/plan-mode.js +13 -13
  362. package/dist/node_modules/@dalcode/dal-workflow/src/test-proof-note.js +3 -0
  363. package/dist/node_modules/@dalcode/dal-workflow/src/todo-snapshot.js +2 -0
  364. package/dist/node_modules/@dalcode/dal-workflow/src/todo.js +3 -3
  365. package/dist/node_modules/@dalcode/dal-workflow/src/truncation-check.js +1 -0
  366. package/dist/node_modules/@dalcode/dal-workflow/src/working-contract.js +1 -1
  367. package/dist/node_modules/@dalcode/deepailab/package.json +3 -3
  368. package/dist/node_modules/@dalcode/deepailab/src/index.js +3 -3
  369. package/dist/node_modules/@earendil-works/pi-agent-core/README.md +5 -0
  370. package/dist/node_modules/@earendil-works/pi-agent-core/dist/agent-loop.d.ts +2 -1
  371. package/dist/node_modules/@earendil-works/pi-agent-core/dist/agent-loop.js +1 -1
  372. package/dist/node_modules/@earendil-works/pi-agent-core/dist/agent.d.ts +3 -1
  373. package/dist/node_modules/@earendil-works/pi-agent-core/dist/agent.js +1 -1
  374. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/agent-harness.js +1 -0
  375. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/compaction/branch-summarization.js +37 -0
  376. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/compaction/compaction.js +104 -0
  377. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/compaction/utils.js +16 -0
  378. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/config.js +1 -0
  379. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/context.js +1 -0
  380. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/env/nodejs.js +10 -0
  381. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/events.js +1 -0
  382. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/execution/assistant.js +1 -0
  383. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/execution/effect-gate.js +1 -0
  384. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/execution/tools.js +1 -0
  385. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/hooks.js +1 -0
  386. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/messages.js +17 -0
  387. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/pico3/bash.js +1 -0
  388. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/pico3/bounded.js +1 -0
  389. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/pico3/chord.js +1 -0
  390. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/pico3/context.js +1 -0
  391. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/pico3/harness.js +1 -0
  392. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/pico3/hooks.js +1 -0
  393. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/pico3/index.js +1 -0
  394. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/pico3/jsonl.js +4 -0
  395. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/pico3/kinds/collapse.js +3 -0
  396. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/pico3/kinds/entries.js +1 -0
  397. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/pico3/kinds/frames.js +1 -0
  398. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/pico3/kinds/generation.js +1 -0
  399. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/pico3/kinds/job.js +1 -0
  400. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/pico3/kinds/plugin.js +1 -0
  401. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/pico3/kinds/post-tools.js +1 -0
  402. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/pico3/kinds/task-api.js +1 -0
  403. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/pico3/kinds/tool.js +3 -0
  404. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/pico3/membrane.js +1 -0
  405. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/pico3/memory.js +1 -0
  406. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/pico3/scheduler.js +1 -0
  407. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/pico3/session.js +1 -0
  408. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/pico3/system.js +8 -0
  409. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/pico3/types.js +1 -0
  410. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/pico3/view.js +1 -0
  411. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/prompt-templates.js +5 -0
  412. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/reducer.js +1 -0
  413. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/result.js +1 -0
  414. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/runtime/drive/boundary.js +1 -0
  415. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/runtime/drive/checkpoint.js +1 -0
  416. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/runtime/drive/deferred.js +1 -0
  417. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/runtime/drive/generation.js +1 -0
  418. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/runtime/drive/reconcile.js +1 -0
  419. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/runtime/drive/recovery.js +1 -0
  420. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/runtime/drive/response.js +1 -0
  421. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/runtime/drive/retry.js +1 -0
  422. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/runtime/drive/structural.js +1 -0
  423. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/runtime/drive/terminal.js +1 -0
  424. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/runtime/drive/tool-placement.js +1 -0
  425. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/runtime/drive/tools.js +1 -0
  426. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/runtime/drive.js +1 -0
  427. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/runtime/harness.js +1 -0
  428. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/runtime/index.js +1 -0
  429. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/runtime/lane.js +1 -0
  430. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/runtime/progress.js +1 -0
  431. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/runtime/reducer.js +1 -0
  432. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/runtime/restore.js +1 -0
  433. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/runtime/transcript.js +1 -0
  434. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/runtime/types.js +1 -0
  435. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/commit.js +1 -0
  436. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/context.js +1 -0
  437. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/fork-policy.js +1 -0
  438. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/fork.js +1 -0
  439. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/in-memory-storage-state.js +1 -0
  440. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/index.js +1 -0
  441. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl/codec.js +1 -0
  442. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl/errors.js +1 -0
  443. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl/fork.js +1 -0
  444. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl/index.js +1 -0
  445. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl/io.js +3 -0
  446. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl/legacy-v3.js +1 -0
  447. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl/repo.js +1 -0
  448. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl/storage.js +8 -0
  449. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl/types.js +1 -0
  450. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl-repo.js +1 -0
  451. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl-storage.js +5 -0
  452. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl.js +1 -0
  453. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/memory-repo.js +1 -0
  454. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/memory-storage.js +1 -0
  455. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/memory.js +1 -0
  456. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/mutation-line.js +1 -0
  457. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/repo-utils.js +1 -0
  458. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/session.js +1 -0
  459. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/state.js +1 -0
  460. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/testing/benchmark/datasets.js +1 -0
  461. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/testing/benchmark/session-repo.js +1 -0
  462. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/testing/benchmark/storage.js +1 -0
  463. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/testing/conformance/session-repo.js +1 -0
  464. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/testing/conformance/storage.js +1 -0
  465. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/testing/conformance.js +1 -0
  466. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/testing/gating-storage.js +1 -0
  467. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/testing/index.js +1 -0
  468. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/testing/instrumented-storage.js +1 -0
  469. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/testing/storage-decorator.js +1 -0
  470. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/types.js +1 -0
  471. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/values.js +1 -0
  472. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/skills.js +10 -0
  473. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/system-prompt.js +2 -0
  474. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/telemetry.js +1 -0
  475. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/tools/bash.js +12 -0
  476. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/tools/edit-diff.js +16 -0
  477. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/tools/edit.js +1 -0
  478. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/tools/file-mutation-queue.js +1 -0
  479. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/tools/image.js +1 -0
  480. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/tools/index.js +1 -0
  481. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/tools/path-utils.js +1 -0
  482. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/tools/read.js +14 -0
  483. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/tools/write.js +1 -0
  484. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/types.js +1 -0
  485. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/adaptive-publisher.js +1 -0
  486. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/output-capture.js +5 -0
  487. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/shell-output.js +1 -0
  488. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/truncate.js +5 -0
  489. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/usage.js +1 -0
  490. package/dist/node_modules/@earendil-works/pi-agent-core/dist/node.js +1 -0
  491. package/dist/node_modules/@earendil-works/pi-agent-core/dist/search/scanning.js +1 -0
  492. package/dist/node_modules/@earendil-works/pi-agent-core/dist/types.d.ts +2 -0
  493. package/dist/node_modules/@earendil-works/pi-agent-core/package.json +2 -2
  494. package/dist/node_modules/@earendil-works/pi-ai/README.md +83 -37
  495. package/dist/node_modules/@earendil-works/pi-ai/dist/api/anthropic-messages.js +5 -5
  496. package/dist/node_modules/@earendil-works/pi-ai/dist/api/azure-openai-responses.js +1 -1
  497. package/dist/node_modules/@earendil-works/pi-ai/dist/api/bedrock-converse-stream.js +1 -1
  498. package/dist/node_modules/@earendil-works/pi-ai/dist/api/classifier-shared.js +1 -1
  499. package/dist/node_modules/@earendil-works/pi-ai/dist/api/cloudflare-gateway-binding.js +1 -0
  500. package/dist/node_modules/@earendil-works/pi-ai/dist/api/cloudflare-workers-ai-system-one.js +1 -1
  501. package/dist/node_modules/@earendil-works/pi-ai/dist/api/google-generative-ai.js +1 -1
  502. package/dist/node_modules/@earendil-works/pi-ai/dist/api/google-shared.js +2 -2
  503. package/dist/node_modules/@earendil-works/pi-ai/dist/api/google-vertex.js +1 -1
  504. package/dist/node_modules/@earendil-works/pi-ai/dist/api/lazy.d.ts +6 -2
  505. package/dist/node_modules/@earendil-works/pi-ai/dist/api/lazy.js +1 -1
  506. package/dist/node_modules/@earendil-works/pi-ai/dist/api/llama-cpp-classify.js +5 -5
  507. package/dist/node_modules/@earendil-works/pi-ai/dist/api/mistral-conversations.js +4 -4
  508. package/dist/node_modules/@earendil-works/pi-ai/dist/api/openai-codex-responses.js +6 -6
  509. package/dist/node_modules/@earendil-works/pi-ai/dist/api/openai-completions.js +5 -5
  510. package/dist/node_modules/@earendil-works/pi-ai/dist/api/openai-responses-shared.js +11 -6
  511. package/dist/node_modules/@earendil-works/pi-ai/dist/api/openai-responses.js +3 -2
  512. package/dist/node_modules/@earendil-works/pi-ai/dist/api/openrouter-images.js +1 -1
  513. package/dist/node_modules/@earendil-works/pi-ai/dist/api/pi-messages.js +4 -4
  514. package/dist/node_modules/@earendil-works/pi-ai/dist/api/simple-options.js +1 -1
  515. package/dist/node_modules/@earendil-works/pi-ai/dist/api/system-one-shared.js +1 -1
  516. package/dist/node_modules/@earendil-works/pi-ai/dist/api/typesafe-system-one.js +1 -1
  517. package/dist/node_modules/@earendil-works/pi-ai/dist/auth/oauth/oauth-page.js +74 -0
  518. package/dist/node_modules/@earendil-works/pi-ai/dist/cli.js +0 -0
  519. package/dist/node_modules/@earendil-works/pi-ai/dist/image-models.generated.js +1 -0
  520. package/dist/node_modules/@earendil-works/pi-ai/dist/images-models.js +1 -0
  521. package/dist/node_modules/@earendil-works/pi-ai/dist/index.d.ts +2 -1
  522. package/dist/node_modules/@earendil-works/pi-ai/dist/index.js +1 -1
  523. package/dist/node_modules/@earendil-works/pi-ai/dist/models.d.ts +5 -0
  524. package/dist/node_modules/@earendil-works/pi-ai/dist/models.js +1 -1
  525. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/azure-openai-responses.js +1 -0
  526. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/azure-openai-responses.models.js +1 -0
  527. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/compat-schema.d.ts +539 -0
  528. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/compat-schema.js +1 -0
  529. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/.manifest.json +1 -1
  530. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/amazon-bedrock.json +1 -1
  531. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/anthropic.json +1 -1
  532. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/azure.json +1 -1
  533. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/baseten.json +1 -1
  534. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/cerebras.json +1 -1
  535. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/cloudflare-ai-gateway.json +1 -1
  536. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/cloudflare-workers-ai.json +1 -1
  537. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/fireworks.json +1 -1
  538. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/github-copilot.json +1 -1
  539. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/google.json +1 -1
  540. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/groq.json +1 -1
  541. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/huggingface.json +1 -1
  542. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/kimi-coding.json +1 -1
  543. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/minimax-cn.json +1 -1
  544. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/minimax.json +1 -1
  545. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/mistral.json +1 -1
  546. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/moonshotai-cn.json +1 -1
  547. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/nvidia.json +1 -1
  548. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/openai-codex.json +1 -1
  549. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/openai.json +1 -1
  550. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/opencode-go.json +1 -1
  551. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/opencode.json +1 -1
  552. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/openrouter.json +1 -1
  553. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/qwen-token-plan-cn.json +1 -1
  554. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/qwen-token-plan.json +1 -1
  555. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/radius.json +1 -1
  556. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/together.json +1 -1
  557. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/typesafe.json +1 -1
  558. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/vercel-ai-gateway.json +1 -1
  559. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/xai.json +1 -1
  560. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/xiaomi-token-plan-ams.json +1 -1
  561. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/xiaomi-token-plan-cn.json +1 -1
  562. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/xiaomi-token-plan-sgp.json +1 -1
  563. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/xiaomi.json +1 -1
  564. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/kimi-coding.js +1 -1
  565. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/model-schema.d.ts +90 -0
  566. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/model-schema.js +1 -0
  567. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/openrouter-api.js +1 -0
  568. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/openrouter-images.js +1 -0
  569. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/openrouter.js +1 -1
  570. package/dist/node_modules/@earendil-works/pi-ai/dist/telemetry.d.ts +286 -0
  571. package/dist/node_modules/@earendil-works/pi-ai/dist/telemetry.js +1 -0
  572. package/dist/node_modules/@earendil-works/pi-ai/dist/types.d.ts +23 -148
  573. package/dist/node_modules/@earendil-works/pi-ai/dist/utils/deferred-tools.js +1 -0
  574. package/dist/node_modules/@earendil-works/pi-ai/dist/utils/event-stream.d.ts +4 -0
  575. package/dist/node_modules/@earendil-works/pi-ai/dist/utils/event-stream.js +1 -1
  576. package/dist/node_modules/@earendil-works/pi-ai/dist/utils/identity.d.ts +27 -0
  577. package/dist/node_modules/@earendil-works/pi-ai/dist/utils/identity.js +1 -0
  578. package/dist/node_modules/@earendil-works/pi-ai/dist/utils/overflow.js +1 -1
  579. package/dist/node_modules/@earendil-works/pi-ai/dist/utils/provider-retry.js +1 -1
  580. package/dist/node_modules/@earendil-works/pi-ai/dist/utils/retry.js +1 -1
  581. package/dist/node_modules/@earendil-works/pi-ai/dist/utils/transcript.d.ts +3 -2
  582. package/dist/node_modules/@earendil-works/pi-ai/dist/utils/transcript.js +2 -2
  583. package/dist/node_modules/@earendil-works/pi-ai/dist/utils/version.d.ts +1 -0
  584. package/dist/node_modules/@earendil-works/pi-ai/dist/utils/version.js +1 -0
  585. package/dist/node_modules/@earendil-works/pi-ai/package.json +2 -2
  586. package/dist/node_modules/@earendil-works/pi-codemode/README.md +195 -11
  587. package/dist/node_modules/@earendil-works/pi-codemode/dist/cloudflare.js +1 -0
  588. package/dist/node_modules/@earendil-works/pi-codemode/dist/declarations.d.ts +0 -2
  589. package/dist/node_modules/@earendil-works/pi-codemode/dist/declarations.js +9 -84
  590. package/dist/node_modules/@earendil-works/pi-codemode/dist/index.d.ts +5 -2
  591. package/dist/node_modules/@earendil-works/pi-codemode/dist/index.js +1 -1
  592. package/dist/node_modules/@earendil-works/pi-codemode/dist/portable.js +1 -0
  593. package/dist/node_modules/@earendil-works/pi-codemode/dist/runtime/execution.d.ts +29 -0
  594. package/dist/node_modules/@earendil-works/pi-codemode/dist/runtime/execution.js +1 -0
  595. package/dist/node_modules/@earendil-works/pi-codemode/dist/runtime/host.d.ts +3 -16
  596. package/dist/node_modules/@earendil-works/pi-codemode/dist/runtime/host.js +1 -1
  597. package/dist/node_modules/@earendil-works/pi-codemode/dist/runtime/inline.d.ts +13 -0
  598. package/dist/node_modules/@earendil-works/pi-codemode/dist/runtime/inline.js +1 -0
  599. package/dist/node_modules/@earendil-works/pi-codemode/dist/runtime/prelude-source.js +14 -6
  600. package/dist/node_modules/@earendil-works/pi-codemode/dist/runtime/protocol.d.ts +72 -0
  601. package/dist/node_modules/@earendil-works/pi-codemode/dist/runtime/protocol.js +1 -1
  602. package/dist/node_modules/@earendil-works/pi-codemode/dist/runtime/remote.d.ts +32 -0
  603. package/dist/node_modules/@earendil-works/pi-codemode/dist/runtime/remote.js +1 -0
  604. package/dist/node_modules/@earendil-works/pi-codemode/dist/runtime/vm.js +3 -0
  605. package/dist/node_modules/@earendil-works/pi-codemode/dist/runtime/worker.js +1 -3
  606. package/dist/node_modules/@earendil-works/pi-codemode/dist/source.js +4 -3
  607. package/dist/node_modules/@earendil-works/pi-codemode/dist/types.d.ts +51 -1
  608. package/dist/node_modules/@earendil-works/pi-codemode/package.json +14 -2
  609. package/dist/node_modules/@earendil-works/pi-coding-agent/package.json +1 -1
  610. package/dist/node_modules/@earendil-works/pi-mcp/CHANGELOG.md +15 -0
  611. package/dist/node_modules/@earendil-works/pi-mcp/dist/client.js +1 -1
  612. package/dist/node_modules/@earendil-works/pi-mcp/dist/index.d.ts +1 -1
  613. package/dist/node_modules/@earendil-works/pi-mcp/dist/oauth/errors.d.ts +2 -2
  614. package/dist/node_modules/@earendil-works/pi-mcp/dist/oauth/errors.js +1 -1
  615. package/dist/node_modules/@earendil-works/pi-mcp/dist/oauth/flow.js +1 -1
  616. package/dist/node_modules/@earendil-works/pi-mcp/dist/protocol/content.d.ts +1 -1
  617. package/dist/node_modules/@earendil-works/pi-mcp/dist/transports/streamable-http.d.ts +2 -2
  618. package/dist/node_modules/@earendil-works/pi-mcp/dist/transports/streamable-http.js +4 -4
  619. package/dist/node_modules/@earendil-works/pi-mcp/dist/transports/transport.d.ts +4 -1
  620. package/dist/node_modules/@earendil-works/pi-mcp/package.json +1 -1
  621. package/dist/node_modules/@earendil-works/pi-telemetry/README.md +167 -21
  622. package/dist/node_modules/@earendil-works/pi-telemetry/dist/index.d.ts +77 -2
  623. package/dist/node_modules/@earendil-works/pi-telemetry/dist/index.js +1 -1
  624. package/dist/node_modules/@earendil-works/pi-telemetry/dist/memory.d.ts +35 -2
  625. package/dist/node_modules/@earendil-works/pi-telemetry/dist/memory.js +1 -1
  626. package/dist/node_modules/@earendil-works/pi-telemetry/dist/metrics.d.ts +70 -0
  627. package/dist/node_modules/@earendil-works/pi-telemetry/dist/metrics.js +1 -0
  628. package/dist/node_modules/@earendil-works/pi-telemetry/dist/noop.d.ts +5 -2
  629. package/dist/node_modules/@earendil-works/pi-telemetry/dist/noop.js +1 -1
  630. package/dist/node_modules/@earendil-works/pi-telemetry/dist/render.js +2 -0
  631. package/dist/node_modules/@earendil-works/pi-telemetry/dist/testing/conformance.js +1 -1
  632. package/dist/node_modules/@earendil-works/pi-telemetry/package.json +6 -1
  633. package/dist/node_modules/@earendil-works/pi-tui/README.md +5 -3
  634. package/dist/node_modules/@earendil-works/pi-tui/dist/autocomplete.js +2 -2
  635. package/dist/node_modules/@earendil-works/pi-tui/dist/components/editor.js +6 -6
  636. package/dist/node_modules/@earendil-works/pi-tui/dist/components/input.js +2 -2
  637. package/dist/node_modules/@earendil-works/pi-tui/dist/components/markdown.js +8 -7
  638. package/dist/node_modules/@earendil-works/pi-tui/dist/index.d.ts +1 -1
  639. package/dist/node_modules/@earendil-works/pi-tui/dist/index.js +1 -1
  640. package/dist/node_modules/@earendil-works/pi-tui/dist/keys.js +5 -5
  641. package/dist/node_modules/@earendil-works/pi-tui/dist/stdin-buffer.d.ts +3 -0
  642. package/dist/node_modules/@earendil-works/pi-tui/dist/stdin-buffer.js +1 -1
  643. package/dist/node_modules/@earendil-works/pi-tui/dist/terminal-image.js +1 -1
  644. package/dist/node_modules/@earendil-works/pi-tui/dist/terminal.d.ts +3 -0
  645. package/dist/node_modules/@earendil-works/pi-tui/dist/terminal.js +1 -1
  646. package/dist/node_modules/@earendil-works/pi-tui/dist/tui-alt-screen.d.ts +2 -0
  647. package/dist/node_modules/@earendil-works/pi-tui/dist/tui-alt-screen.js +4 -4
  648. package/dist/node_modules/@earendil-works/pi-tui/dist/tui-main-screen.js +1 -1
  649. package/dist/node_modules/@earendil-works/pi-tui/dist/tui.d.ts +7 -0
  650. package/dist/node_modules/@earendil-works/pi-tui/dist/tui.js +2 -2
  651. package/dist/node_modules/@earendil-works/pi-tui/dist/utils.js +1 -1
  652. package/dist/node_modules/@earendil-works/pi-tui/package.json +3 -2
  653. package/dist/package-manager-cli.js +9 -9
  654. package/dist/sdk/index.d.ts +3 -3
  655. package/dist/sdk/index.js +1 -1
  656. package/dist/sdk/office.d.ts +1 -1
  657. package/dist/sdk/office.js +1 -1
  658. package/dist/sdk/rewind.d.ts +1 -1
  659. package/dist/sdk/rewind.js +1 -1
  660. package/dist/sdk/router.d.ts +4 -4
  661. package/dist/sdk/router.js +1 -1
  662. package/dist/server/create-harness.js +1 -0
  663. package/dist/utils/clipboard-command.js +1 -1
  664. package/dist/utils/clipboard-native.js +1 -0
  665. package/dist/utils/clipboard.js +1 -1
  666. package/dist/utils/output-files.js +1 -1
  667. package/dist/utils/pi-user-agent.js +1 -1
  668. package/dist/utils/shell.js +2 -2
  669. package/dist/utils/temp-files.js +1 -0
  670. package/dist/utils/tools-manager.js +1 -1
  671. package/docs/security.md +24 -7
  672. package/examples/README.md +0 -3
  673. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  674. package/examples/extensions/dynamic-resources/dynamic.json +1 -1
  675. package/examples/extensions/gondolin/package-lock.json +2 -2
  676. package/examples/extensions/gondolin/package.json +1 -1
  677. package/examples/extensions/minimal-mode.ts +4 -5
  678. package/examples/extensions/overlay-test.ts +2 -2
  679. package/examples/extensions/sandbox/package-lock.json +2 -2
  680. package/examples/extensions/sandbox/package.json +1 -1
  681. package/examples/extensions/subagent/index.ts +4 -6
  682. package/examples/extensions/with-deps/package-lock.json +2 -2
  683. package/examples/extensions/with-deps/package.json +1 -1
  684. package/npm-shrinkwrap.json +22 -460
  685. package/package.json +7 -12
  686. package/dist/modes/interactive/theme/theme-json.d.ts +0 -75
  687. package/dist/node_modules/@dalcode/dal-guard/src/review.js +0 -3
  688. package/dist/node_modules/@dalcode/dal-office/src/scenes.js +0 -1
  689. package/dist/node_modules/@dalcode/dal-plugins/src/rank.js +0 -4
  690. package/dist/node_modules/@dalcode/dal-router/src/assist.js +0 -4
  691. package/dist/node_modules/@dalcode/dal-router/src/compact-defer.js +0 -3
  692. package/dist/node_modules/@dalcode/dal-router/src/jev.d.ts +0 -52
  693. package/dist/node_modules/@dalcode/dal-router/src/jev.js +0 -5
  694. package/dist/node_modules/@dalcode/dal-router/src/router.d.ts +0 -32
  695. package/dist/node_modules/@dalcode/dal-router/src/router.js +0 -1
  696. package/dist/node_modules/@dalcode/dal-router/src/services.js +0 -1
  697. package/dist/node_modules/@dalcode/dal-subagent/src/role-pick.js +0 -2
  698. package/dist/node_modules/@earendil-works/chord/README.md +0 -264
  699. package/dist/node_modules/@earendil-works/chord/dist/api.js +0 -1
  700. package/dist/node_modules/@earendil-works/chord/dist/bundler.js +0 -1
  701. package/dist/node_modules/@earendil-works/chord/dist/context/index.js +0 -1
  702. package/dist/node_modules/@earendil-works/chord/dist/delta/apply-immutable-trusted.js +0 -1
  703. package/dist/node_modules/@earendil-works/chord/dist/delta/diff.js +0 -1
  704. package/dist/node_modules/@earendil-works/chord/dist/delta/index.js +0 -1
  705. package/dist/node_modules/@earendil-works/chord/dist/delta/revision-validator.js +0 -1
  706. package/dist/node_modules/@earendil-works/chord/dist/delta/tracker.js +0 -1
  707. package/dist/node_modules/@earendil-works/chord/dist/facets/host.js +0 -1
  708. package/dist/node_modules/@earendil-works/chord/dist/facets/loader.js +0 -1
  709. package/dist/node_modules/@earendil-works/chord/dist/index.js +0 -1
  710. package/dist/node_modules/@earendil-works/chord/dist/json.js +0 -1
  711. package/dist/node_modules/@earendil-works/chord/dist/node/bundle-loader.js +0 -2
  712. package/dist/node_modules/@earendil-works/chord/dist/node/bundle.js +0 -4
  713. package/dist/node_modules/@earendil-works/chord/dist/node/manifest.js +0 -1
  714. package/dist/node_modules/@earendil-works/chord/dist/node/package.js +0 -1
  715. package/dist/node_modules/@earendil-works/chord/dist/node.js +0 -1
  716. package/dist/node_modules/@earendil-works/chord/dist/services/consumer.js +0 -1
  717. package/dist/node_modules/@earendil-works/chord/dist/services/errors.js +0 -1
  718. package/dist/node_modules/@earendil-works/chord/dist/services/handle.js +0 -1
  719. package/dist/node_modules/@earendil-works/chord/dist/services/instances.js +0 -1
  720. package/dist/node_modules/@earendil-works/chord/dist/services/loopback.js +0 -1
  721. package/dist/node_modules/@earendil-works/chord/dist/services/provider.js +0 -1
  722. package/dist/node_modules/@earendil-works/chord/dist/services/state-codec.js +0 -1
  723. package/dist/node_modules/@earendil-works/chord/dist/services/state-internals.js +0 -1
  724. package/dist/node_modules/@earendil-works/chord/dist/services/state.js +0 -1
  725. package/dist/node_modules/@earendil-works/chord/dist/services/wire.js +0 -1
  726. package/dist/node_modules/@earendil-works/chord/package.json +0 -62
  727. package/dist/node_modules/@earendil-works/chord/src/delta/README.md +0 -191
  728. package/dist/node_modules/@earendil-works/pi-ai/dist/utils/assistant-message-frame.d.ts +0 -63
  729. package/dist/node_modules/@earendil-works/pi-client/CHANGELOG.md +0 -45
  730. package/dist/node_modules/@earendil-works/pi-client/LICENSE +0 -21
  731. package/dist/node_modules/@earendil-works/pi-client/README.md +0 -72
  732. package/dist/node_modules/@earendil-works/pi-client/dist/client.js +0 -1
  733. package/dist/node_modules/@earendil-works/pi-client/dist/connection.js +0 -1
  734. package/dist/node_modules/@earendil-works/pi-client/dist/errors.js +0 -1
  735. package/dist/node_modules/@earendil-works/pi-client/dist/index.js +0 -1
  736. package/dist/node_modules/@earendil-works/pi-client/dist/promise.js +0 -1
  737. package/dist/node_modules/@earendil-works/pi-client/dist/types.js +0 -0
  738. package/dist/node_modules/@earendil-works/pi-client/dist/unix.js +0 -1
  739. package/dist/node_modules/@earendil-works/pi-client/package.json +0 -46
  740. package/dist/node_modules/@earendil-works/pi-protocol/LICENSE +0 -21
  741. package/dist/node_modules/@earendil-works/pi-protocol/README.md +0 -41
  742. package/dist/node_modules/@earendil-works/pi-protocol/dist/cbor/decoder.js +0 -1
  743. package/dist/node_modules/@earendil-works/pi-protocol/dist/cbor/encoder.js +0 -1
  744. package/dist/node_modules/@earendil-works/pi-protocol/dist/cbor/index.js +0 -1
  745. package/dist/node_modules/@earendil-works/pi-protocol/dist/cbor/options.js +0 -1
  746. package/dist/node_modules/@earendil-works/pi-protocol/dist/codec.js +0 -1
  747. package/dist/node_modules/@earendil-works/pi-protocol/dist/framing.js +0 -1
  748. package/dist/node_modules/@earendil-works/pi-protocol/dist/index.js +0 -1
  749. package/dist/node_modules/@earendil-works/pi-protocol/dist/protocol.js +0 -1
  750. package/dist/node_modules/@earendil-works/pi-protocol/dist/schemas.js +0 -1
  751. package/dist/node_modules/@earendil-works/pi-protocol/package.json +0 -39
  752. package/dist/node_modules/@earendil-works/pi-server/CHANGELOG.md +0 -81
  753. package/dist/node_modules/@earendil-works/pi-server/LICENSE +0 -21
  754. package/dist/node_modules/@earendil-works/pi-server/README.md +0 -63
  755. package/dist/node_modules/@earendil-works/pi-server/dist/connection.js +0 -1
  756. package/dist/node_modules/@earendil-works/pi-server/dist/errors.js +0 -1
  757. package/dist/node_modules/@earendil-works/pi-server/dist/index.js +0 -1
  758. package/dist/node_modules/@earendil-works/pi-server/dist/listener.js +0 -0
  759. package/dist/node_modules/@earendil-works/pi-server/dist/server.js +0 -1
  760. package/dist/node_modules/@earendil-works/pi-server/dist/session-router.js +0 -1
  761. package/dist/node_modules/@earendil-works/pi-server/dist/testing/client.js +0 -1
  762. package/dist/node_modules/@earendil-works/pi-server/dist/testing/host.js +0 -1
  763. package/dist/node_modules/@earendil-works/pi-server/dist/testing/index.js +0 -1
  764. package/dist/node_modules/@earendil-works/pi-server/dist/testing/server.js +0 -1
  765. package/dist/node_modules/@earendil-works/pi-server/dist/transports/unix/address.js +0 -1
  766. package/dist/node_modules/@earendil-works/pi-server/dist/transports/unix/index.js +0 -1
  767. package/dist/node_modules/@earendil-works/pi-server/dist/transports/unix/listener.js +0 -1
  768. package/dist/node_modules/@earendil-works/pi-server/dist/transports/unix/preset.js +0 -1
  769. package/dist/node_modules/@earendil-works/pi-server/dist/transports/unix/types.js +0 -0
  770. package/dist/node_modules/@earendil-works/pi-server/dist/types.js +0 -0
  771. package/dist/node_modules/@earendil-works/pi-server/package.json +0 -45
  772. package/examples/plugins/pi-example-plugin/README.md +0 -38
  773. package/examples/plugins/pi-example-plugin/package.json +0 -10
  774. package/examples/plugins/pi-example-plugin/src/contract.ts +0 -13
  775. package/examples/plugins/pi-example-plugin/src/session.ts +0 -24
  776. package/examples/plugins/pi-example-plugin/src/tui.ts +0 -31
  777. /package/dist/node_modules/{@earendil-works/chord → @dalcode/dal-codeindex}/LICENSE +0 -0
  778. /package/dist/node_modules/@earendil-works/{chord/dist → pi-agent-core/dist/harness/session/testing}/types.js +0 -0
  779. /package/dist/node_modules/@earendil-works/{chord/dist/delta/draft.js → pi-agent-core/dist/harness/tools/tool-context.js} +0 -0
  780. /package/dist/node_modules/@earendil-works/{pi-client/dist/transport.js → pi-agent-core/dist/search/index.js} +0 -0
@@ -1,20 +1,20 @@
1
- var $e=Object.defineProperty;var a=(t,e)=>$e(t,"name",{value:e,configurable:!0});import{constants as Le}from"node:fs";import{access as Te}from"node:fs/promises";import{constants as Ce}from"node:os";import{ToolExecutionError as le}from"@earendil-works/pi-agent-core";import{Container as Pe,Text as j,truncateToWidth as Ie}from"@earendil-works/pi-tui";import{spawn as ve}from"child_process";import{Type as l}from"typebox";import{fill as G,t as I}from"../../dal/i18n.js";import{keyHint as De}from"../../modes/interactive/components/keybinding-hints.js";import{truncateToVisualLines as Ae}from"../../modes/interactive/components/visual-truncate.js";import{theme as x}from"../../modes/interactive/theme/theme.js";import{waitForChildProcess as ke}from"../../utils/child-process.js";import{writeOutputFile as Me}from"../../utils/output-files.js";import{getShellConfig as ue,getShellEnv as ce,killProcessTree as me,trackDetachedChildPid as Fe,untrackDetachedChildPid as Ne}from"../../utils/shell.js";import{missingManagedToolHint as Be}from"../../utils/tools-manager.js";import{describeDenialForModel as Re}from"../sandbox/denial.js";import{getProcessShellSandbox as Ue}from"../sandbox/shell-sandbox.js";import{toolDenial as Ge,withToolDenial as He}from"../tool-denial.js";import{isReadOnlyBashCommand as je}from"./bash-read-only.js";import{OutputAccumulator as We}from"./output-accumulator.js";import{condenseShellOutput as Ve,outputCondenseDisabled as Ye}from"./output-condense.js";import{countOutputLines as Xe,formatCollapsedSummary as Ke,getTextOutput as pe,invalidArgText as qe,str as fe,truncateDisplay as ze}from"./render-utils.js";import{wrapToolDefinition as Je}from"./tool-definition-wrapper.js";import{DEFAULT_MAX_BYTES as Qe,formatSize as Ze,SHELL_OUTPUT_MAX_CHARS as ee,truncateHeadTail as et}from"./truncate.js";const he=2147483647,we=1024*1024,tt=8*1024*1024,nt=he/1e3,te=12e4,ne=30;function ot(t){if(t===void 0)return te;if(!Number.isFinite(t)||t<=0)throw new Error("Invalid timeout: must be a finite number of seconds");const e=t*1e3;if(e>he)throw new Error(`Invalid timeout: maximum is ${nt} seconds`);return e}a(ot,"resolveTimeoutMs");const Se=l.Object({command:l.String({description:"Shell command to execute"}),description:l.String({description:`What it does and why, 3-10 words in the user's language, shown instead of the command: "Find hardcoded key names", not "run grep"`}),timeout:l.Optional(l.Number({description:"Seconds to wait for the command (default in the tool description). Raise it for long builds."}))}),it=l.Optional(l.Object({mode:l.Union([l.Literal("allow"),l.Literal("unsandboxed")],{description:'"allow": stay sandboxed with the domains/paths below; "unsandboxed": run outside the sandbox'}),justification:l.String({description:"Why, in one sentence for the user, who must approve it"}),allow_domains:l.Optional(l.Array(l.String(),{description:"e.g. registry.npmjs.org"})),allow_write:l.Optional(l.Array(l.String(),{description:"Paths to make writable"}))},{description:"Only after the sandbox blocked this command: the access it needs. Never pre-emptively."})),st=l.Object({...Se.properties,sandbox_escalation:it}),be={snippet:"Execute bash commands (ls, grep, find, etc.)",guidelines:["You can inspect DAL_* environment variables for current model and session details."]},at=l.Object({output:l.String({description:"Combined stdout and stderr, possibly truncated"}),truncated:l.Boolean(),full_output_path:l.Optional(l.String({description:"Full output, when truncated"})),exit_code:l.Number({description:"-1 while the command runs in the background"}),background_id:l.Optional(l.String({description:"Background process id, when it is still running"})),wall_time_seconds:l.Number()});function rt(t,e){return{exec:a(async(n,o,{onData:u,signal:i,timeout:y,env:w,yieldTo:s})=>{const $=ot(y);if(i?.aborted)throw new Error("aborted");const S=e();try{await Te(o,Le.F_OK)}catch{throw new Error(`Working directory does not exist: ${o}
2
- Cannot execute ${t} commands.`)}const b=S.commandTransport==="stdin",c=ve(S.shell,b?S.args:[...S.args,n],{cwd:o,detached:process.platform!=="win32",env:w??ce(),stdio:[b?"pipe":"ignore","pipe","pipe"],windowsHide:!0});b&&(c.stdin?.on("error",()=>{}),c.stdin?.end(n)),c.pid&&Fe(c.pid);let r=!1,m=!1,h;const p=new Promise(A=>{h=a(()=>A("yielded"),"onYielded")});let f;const _=a(()=>{c.pid&&me(c.pid)},"onAbort");try{$!==void 0&&(f=setTimeout(()=>{if(s&&c.exitCode===null&&c.signalCode===null&&s(c)){m=!0,h?.();return}r=!0,c.pid&&me(c.pid)},$)),c.stdout?.on("data",u),c.stderr?.on("data",u),i&&(i.aborted?_():i.addEventListener("abort",_,{once:!0}));const A=ke(c),N=await Promise.race([A,p]);if(N==="yielded")return A.catch(()=>{}),{exitCode:null,yielded:!0};const V=N;if(i?.aborted)throw new Error("aborted");if(r)throw new Error(`timeout:${($??te)/1e3}`);const L=c.signalCode;return{exitCode:V??(L?128+(Ce.signals[L]??0):1)}}finally{c.pid&&!m&&Ne(c.pid),f&&clearTimeout(f),i&&i.removeEventListener("abort",_)}},"exec")}}a(rt,"createLocalShellOperations");function dt(t){return rt("bash",()=>ue(t?.shellPath))}a(dt,"createLocalBashOperations");const oe=Symbol.for("dal.shell.executionGuards"),ie=globalThis;ie[oe]instanceof Set||(ie[oe]=new Set);const se=ie[oe];function Xt(t){return se.add(t),()=>{se.delete(t)}}a(Xt,"registerShellExecutionGuard");async function lt(t){for(const e of se){let n;try{n=await e(t)}catch(o){return`Command refused: the safety check could not run (${o instanceof Error?o.message:String(o)}).`}if(n!==void 0)return n}}a(lt,"shellExecutionRefusal");const ut=["SESSION_ID","SESSION_FILE","PROVIDER","MODEL","REASONING_LEVEL"];function ct(t,e,n,o,u){const i={...ce()};if(delete i.PI_SESSION_ID,delete i.PI_SESSION_FILE,delete i.PI_PROVIDER,delete i.PI_MODEL,delete i.PI_REASONING_LEVEL,o&&u){const w=u.model;i.PI_SESSION_ID=u.sessionManager.getSessionId();const s=u.sessionManager.getSessionFile();s&&(i.PI_SESSION_FILE=s),w&&(i.PI_PROVIDER=w.provider,i.PI_MODEL=w.id),u.thinkingLevel&&(i.PI_REASONING_LEVEL=u.thinkingLevel)}for(const w of ut){delete i[`DAL_${w}`];const s=i[`PI_${w}`];s!==void 0&&(i[`DAL_${w}`]=s)}const y={command:t,cwd:e,env:i};return n?n(y):y}a(ct,"resolveSpawnContext");const mt=5,pt=100;class ft extends Pe{static{a(this,"BashResultRenderComponent")}state={cachedWidth:void 0,cachedLines:void 0,cachedSkipped:void 0}}function ht(t){const e=t/1e3;if(e<60)return`${e.toFixed(1)}s`;const n=Math.floor(e),o=Math.floor(n/60),u=n%60;return o<60?`${o}m ${u}s`:`${Math.floor(o/60)}h ${o%60}m ${u}s`}a(ht,"formatDuration");function wt(t,e,n=!1){const o=fe(t?.command),u=fe(t?.description)?.trim(),i=t?.timeout,y=i?x.fg("muted",G(I(" (\u8D85\u65F6 {seconds} \u79D2)"),{seconds:i})):"";if(u){const s=x.fg("toolTitle",x.bold(u))+y;return!n||!o?s:`${s}
3
- ${x.fg("muted",` \u23BF ${e} ${o.trim()}`)}`}const w=o===null?qe(x):o?x.fg("dim",ze(o.replace(/\s+/g," ").trim(),42)):x.fg("dim","\u2026");return`${x.fg("toolTitle",x.bold(e))} ${w}${y}`}a(wt,"formatShellCall");function St(t,e,n,o,u,i,y,w){const s=t.state;t.clear();const $=bt(n,u,i,w);if(!n.expanded&&!y){const r=pe(e,o),m=Xe(r),h=[];m>0&&h.push(G(I("{count} \u884C"),{count:m})),$&&h.push($);const p=Ke(x,h);p&&t.addChild(new j(p,0,0));return}let S=pe(e,o).trim();const b=e.details?.truncation,c=e.details?.fullOutputPath;if(!n.isPartial&&b?.truncated&&c&&S.endsWith("]")){const r=S.lastIndexOf(`
1
+ var $e=Object.defineProperty;var r=(t,e)=>$e(t,"name",{value:e,configurable:!0});import{constants as Le}from"node:fs";import{access as Te}from"node:fs/promises";import{constants as Ce}from"node:os";import{ToolExecutionError as le}from"@earendil-works/pi-agent-core";import{Container as Pe,Text as W,truncateToWidth as De}from"@earendil-works/pi-tui";import{spawn as ve}from"child_process";import{Type as l}from"typebox";import{fill as G,t as P}from"../../dal/i18n.js";import{keyHint as Ie}from"../../modes/interactive/components/keybinding-hints.js";import{truncateToVisualLines as Ae}from"../../modes/interactive/components/visual-truncate.js";import{theme as x}from"../../modes/interactive/theme/theme.js";import{waitForChildProcess as ke}from"../../utils/child-process.js";import{writeOutputFile as Me}from"../../utils/output-files.js";import{getShellConfig as ue,getShellEnv as ce,killProcessTree as me,trackDetachedChildPid as Fe,untrackDetachedChildPid as Ne}from"../../utils/shell.js";import{missingManagedToolHint as Be}from"../../utils/tools-manager.js";import{describeDenialForModel as Re}from"../sandbox/denial.js";import{getProcessShellSandbox as Ue}from"../sandbox/shell-sandbox.js";import{toolDenial as Ge,withToolDenial as He}from"../tool-denial.js";import{isReadOnlyBashCommand as je}from"./bash-read-only.js";import{OutputAccumulator as We}from"./output-accumulator.js";import{condenseShellOutput as Ve,outputCondenseDisabled as Ye}from"./output-condense.js";import{countOutputLines as Xe,formatCollapsedSummary as Ke,getTextOutput as pe,invalidArgText as qe,str as fe,truncateDisplay as ze}from"./render-utils.js";import{wrapToolDefinition as Je}from"./tool-definition-wrapper.js";import{DEFAULT_MAX_BYTES as Qe,formatSize as Ze,SHELL_OUTPUT_MAX_CHARS as ee,truncateHeadTail as et}from"./truncate.js";const he=2147483647,we=1024*1024,tt=8*1024*1024,nt=he/1e3,te=12e4,ne=30;function ot(t){if(t===void 0)return te;if(!Number.isFinite(t)||t<=0)throw new Error("Invalid timeout: must be a finite number of seconds");const e=t*1e3;if(e>he)throw new Error(`Invalid timeout: maximum is ${nt} seconds`);return e}r(ot,"resolveTimeoutMs");const Se=l.Object({command:l.String({description:"Shell command to execute"}),description:l.String({description:`What it does and why, 3-10 words in the user's language, shown instead of the command: "Find hardcoded key names", not "run grep"`}),timeout:l.Optional(l.Number({description:"Seconds to wait for the command (default in the tool description). Raise it for long builds."}))}),it=l.Optional(l.Object({mode:l.Union([l.Literal("allow"),l.Literal("unsandboxed")],{description:'"allow": stay sandboxed with the domains/paths below; "unsandboxed": run outside the sandbox'}),justification:l.String({description:"Why, in one sentence for the user, who must approve it"}),allow_domains:l.Optional(l.Array(l.String(),{description:"e.g. registry.npmjs.org"})),allow_write:l.Optional(l.Array(l.String(),{description:"Paths to make writable"}))},{description:"Only after the sandbox blocked this command: the access it needs. Never pre-emptively."})),st=l.Object({...Se.properties,sandbox_escalation:it}),be={snippet:"Execute bash commands (ls, grep, find, etc.)",guidelines:["You can inspect DAL_* environment variables for current model and session details."]},rt=l.Object({output:l.String({description:"Combined stdout and stderr, possibly truncated"}),truncated:l.Boolean(),full_output_path:l.Optional(l.String({description:"Full output, when truncated"})),exit_code:l.Number({description:"-1 while the command runs in the background"}),background_id:l.Optional(l.String({description:"Background process id, when it is still running"})),wall_time_seconds:l.Number()});function at(t,e){return{exec:r(async(n,o,{onData:u,signal:i,timeout:y,env:w,yieldTo:s})=>{const $=ot(y);if(i?.aborted)throw new Error("aborted");const S=e();try{await Te(o,Le.F_OK)}catch{throw new Error(`Working directory does not exist: ${o}
2
+ Cannot execute ${t} commands.`)}const b=S.commandTransport==="stdin",c=ve(S.shell,b?S.args:[...S.args,n],{cwd:o,detached:process.platform!=="win32",env:w??ce(),stdio:[b?"pipe":"ignore","pipe","pipe"],windowsHide:!0});b&&(c.stdin?.on("error",()=>{}),c.stdin?.end(n)),c.pid&&Fe(c.pid);let a=!1,m=!1,h;const p=new Promise(A=>{h=r(()=>A("yielded"),"onYielded")});let f;const _=r(()=>{c.pid&&me(c.pid)},"onAbort");try{$!==void 0&&(f=setTimeout(()=>{if(s&&c.exitCode===null&&c.signalCode===null&&s(c)){m=!0,h?.();return}a=!0,c.pid&&me(c.pid)},$)),c.stdout?.on("data",u),c.stderr?.on("data",u),i&&(i.aborted?_():i.addEventListener("abort",_,{once:!0}));const A=ke(c),D=await Promise.race([A,p]);if(D==="yielded")return A.catch(()=>{}),{exitCode:null,yielded:!0};const H=D;if(i?.aborted)throw new Error("aborted");if(a)throw new Error(`timeout:${($??te)/1e3}`);const V=c.signalCode;return{exitCode:H??(V?128+(Ce.signals[V]??0):1)}}finally{c.pid&&!m&&Ne(c.pid),f&&clearTimeout(f),i&&i.removeEventListener("abort",_)}},"exec")}}r(at,"createLocalShellOperations");function dt(t){return at("bash",()=>ue(t?.shellPath))}r(dt,"createLocalBashOperations");const oe=Symbol.for("dal.shell.executionGuards"),ie=globalThis;ie[oe]instanceof Set||(ie[oe]=new Set);const se=ie[oe];function Xt(t){return se.add(t),()=>{se.delete(t)}}r(Xt,"registerShellExecutionGuard");async function lt(t){for(const e of se){let n;try{n=await e(t)}catch(o){return`Command refused: the safety check could not run (${o instanceof Error?o.message:String(o)}).`}if(n!==void 0)return n}}r(lt,"shellExecutionRefusal");const ut=["SESSION_ID","SESSION_FILE","PROVIDER","MODEL","REASONING_LEVEL"];function ct(t,e,n,o,u){const i={...ce()};if(delete i.PI_SESSION_ID,delete i.PI_SESSION_FILE,delete i.PI_PROVIDER,delete i.PI_MODEL,delete i.PI_REASONING_LEVEL,o&&u){const w=u.model;i.PI_SESSION_ID=u.sessionManager.getSessionId();const s=u.sessionManager.getSessionFile();s&&(i.PI_SESSION_FILE=s),w&&(i.PI_PROVIDER=w.provider,i.PI_MODEL=w.id),u.thinkingLevel&&(i.PI_REASONING_LEVEL=u.thinkingLevel)}for(const w of ut){delete i[`DAL_${w}`];const s=i[`PI_${w}`];s!==void 0&&(i[`DAL_${w}`]=s)}const y={command:t,cwd:e,env:i};return n?n(y):y}r(ct,"resolveSpawnContext");const mt=5,pt=100;class ft extends Pe{static{r(this,"BashResultRenderComponent")}state={cachedWidth:void 0,cachedLines:void 0,cachedSkipped:void 0}}function ht(t){const e=t/1e3;if(e<60)return`${e.toFixed(1)}s`;const n=Math.floor(e),o=Math.floor(n/60),u=n%60;return o<60?`${o}m ${u}s`:`${Math.floor(o/60)}h ${o%60}m ${u}s`}r(ht,"formatDuration");function wt(t,e,n=!1){const o=fe(t?.command),u=fe(t?.description)?.trim(),i=t?.timeout,y=i?x.fg("muted",G(P(" (\u8D85\u65F6 {seconds} \u79D2)"),{seconds:i})):"";if(u){const s=x.fg("toolTitle",x.bold(u))+y;return!n||!o?s:`${s}
3
+ ${x.fg("muted",` \u23BF ${e} ${o.trim()}`)}`}const w=o===null?qe(x):o?x.fg("dim",ze(o.replace(/\s+/g," ").trim(),42)):x.fg("dim","\u2026");return`${x.fg("toolTitle",x.bold(e))} ${w}${y}`}r(wt,"formatShellCall");function St(t,e,n,o,u,i,y,w){const s=t.state;t.clear();const $=bt(n,u,i,w);if(!n.expanded&&!y){const a=pe(e,o),m=Xe(a),h=[];m>0&&h.push(G(P("{count} \u884C"),{count:m})),$&&h.push($);const p=Ke(x,h);p&&t.addChild(new W(p,0,0));return}let S=pe(e,o).trim();const b=e.details?.truncation,c=e.details?.fullOutputPath;if(!n.isPartial&&b?.truncated&&c&&S.endsWith("]")){const a=S.lastIndexOf(`
4
4
 
5
- [`);r!==-1&&S.slice(r).includes(c)&&(S=S.slice(0,r).trimEnd())}if(S){const r=S.split(`
5
+ [`);a!==-1&&S.slice(a).includes(c)&&(S=S.slice(0,a).trimEnd())}if(S){const a=S.split(`
6
6
  `).map(m=>x.fg("toolOutput",m)).join(`
7
- `);n.expanded?t.addChild(new j(`
8
- ${r}`,0,0)):t.addChild({render:a(m=>{if(s.cachedLines===void 0||s.cachedWidth!==m){const h=Ae(r,mt,m);s.cachedLines=h.visualLines,s.cachedSkipped=h.skippedCount,s.cachedWidth=m}if(s.cachedSkipped&&s.cachedSkipped>0){const h=x.fg("muted",G(I("... (\u524D\u9762\u8FD8\u6709 {count} \u884C\uFF0C"),{count:s.cachedSkipped}))+` ${De("app.tools.expand",I("\u5373\u53EF\u5C55\u5F00"))}${x.fg("muted",")")}`;return["",Ie(h,m,"..."),...s.cachedLines??[]]}return["",...s.cachedLines??[]]},"render"),invalidate:a(()=>{s.cachedWidth=void 0,s.cachedLines=void 0,s.cachedSkipped=void 0},"invalidate")})}if(b?.truncated||c){const r=[];c&&r.push(G(I("\u5B8C\u6574\u8F93\u51FA\uFF1A{path}"),{path:c})),b?.truncated&&(b.truncatedBy==="lines"?r.push(G(I("\u5DF2\u622A\u65AD\uFF1A\u663E\u793A {shown}/{total} \u884C"),{shown:b.outputLines,total:b.totalLines})):r.push(G(I("\u5DF2\u622A\u65AD\uFF1A\u663E\u793A\u4E86 {shown} \u884C\uFF08\u4E0A\u9650 {limit}\uFF09"),{shown:b.outputLines,limit:Ze(b.maxBytes??Qe)}))),t.addChild(new j(`
9
- ${x.fg("warning",`[${r.join(". ")}]`)}`,0,0))}$&&t.addChild(new j(`
10
- ${x.fg("muted",$)}`,0,0))}a(St,"rebuildBashResultRenderComponent");function bt(t,e,n,o){let u;if(!t.isPartial&&o!==void 0)u=o;else if(e!==void 0)u=(n??Date.now())-e;else return;if(!(!t.isPartial&&u<100))return`${t.isPartial?I("\u5DF2\u8FD0\u884C"):I("\u8017\u65F6")} ${ht(u)}`}a(bt,"bashTimingLabel");function xt(t,e,n){const o=n?.operations??e.defaultOperations?.()??dt({shellPath:n?.shellPath}),u=n?.commandPrefix,i=n?.exposeSessionEnvironment??!0,y=n?.spawnHook,w=n?.sandbox,s=n?.operations===void 0,$=w?.describeForModel(),S=n?.background;let b=!1;const c=a(r=>`Execute a ${e.shellName} command in the current working directory; returns stdout and stderr. Long output is cut to its start and end (error lines kept) and the full output saved to a file named in the result. ${r?`A command still running after \`timeout\` seconds (default ${ne}) keeps running in the background: you get its id and the output so far, then use the process tool to poll or kill it.`:`A command still running after \`timeout\` seconds (default ${te/1e3}) is killed.`}${$?` ${$}`:""}`,"describe");return{name:e.name,label:e.label,description:c(!1),prepareLoadout:S&&s?r=>(b=r.declared.some(m=>m.name==="process"),b?{descriptions:{[e.name]:c(!0)}}:void 0):void 0,promptSnippet:e.promptSnippet,promptGuidelines:i&&e.promptGuidelines?[...e.promptGuidelines]:void 0,executionMode:"sequential",executionModeFor:e.readOnlyCommand&&!u?r=>e.readOnlyCommand?.(r?.command)?"parallel":void 0:void 0,parameters:w?.active?st:Se,outputSchema:at,constrainedSampling:{type:"json_schema",strict:"prefer"},async execute(r,m,h,p,f){const{command:_,timeout:A}=m;p&&p({content:[],details:void 0});const N=await lt({toolName:e.name,command:_,cwd:f?.cwd||t,sessionFile:f?.sessionManager?.getSessionFile()});if(N!==void 0)throw new le(N,He(void 0,Ge("dangerous-command",N)));const V=u?`${u}
11
- ${_}`:_,L=ct(V,f?.cwd||t,y,i,f),Y=w??(s?Ue():void 0);let T;if(Y?.active){if(!e.sandboxShell)throw new Error(`Command refused: ${e.shellName} commands cannot run inside the OS sandbox yet, and the sandbox level is "${Y.level}". Use the bash tool, or the user can opt out with \`dal --sandbox off\`.`);T=await Y.prepare({command:L.command,cwd:L.cwd,shell:e.sandboxShell(n?.shellPath),shellKind:e.sandboxShellKind??"bash",env:L.env,toolCallId:r,toolName:e.name,escalation:m.sandbox_escalation,ctx:f,signal:h})}const P=new We({tempFilePrefix:e.tempFilePrefix,maxBytes:ee});let W=!0,H,X=!1,ae=0;const K=a(()=>{if(!p||!X)return;X=!1,ae=Date.now();const d=P.snapshot({persistIfTruncated:!0});p({content:[{type:"text",text:d.content||""}],details:{truncation:d.truncation.truncated?d.truncation:void 0,fullOutputPath:d.fullOutputPath}})},"emitOutputUpdate"),q=a(()=>{H&&(clearTimeout(H),H=void 0)},"clearUpdateTimer"),xe=a(()=>{if(!p)return;X=!0;const d=pt-(Date.now()-ae);if(d<=0){q(),K();return}H??=setTimeout(()=>{H=void 0,K()},d)},"scheduleOutputUpdate"),Ee=a(d=>{W&&(P.append(d),xe())},"handleData"),_e=a(async()=>{W=!1,P.finish(),q(),K();const d=P.snapshot({persistIfTruncated:!0});return await P.closeTempFile(),d},"finishOutput"),z=a(async(d="(no output)")=>{const O=await _e(),k=await P.readFullOutput(tt),C=Ye()?void 0:Ve(k.content),E=et(C?.text??k.content,ee);let D=O.fullOutputPath;(E.truncated||C)&&!D&&(D=await Me(e.tempFilePrefix,".log",k.content));let M=E.content||d,R;const U=O.truncation.totalLines;return E.truncated?(R={truncation:{content:E.content,truncated:!0,truncatedBy:"bytes",totalLines:U,totalBytes:O.truncation.totalBytes,outputLines:E.headLines+E.tailLines,outputBytes:Buffer.byteLength(E.content,"utf-8"),lastLinePartial:!1,firstLineExceedsLimit:!1,maxLines:U,maxBytes:ee},fullOutputPath:D},M+=`
7
+ `);n.expanded?t.addChild(new W(`
8
+ ${a}`,0,0)):t.addChild({render:r(m=>{if(s.cachedLines===void 0||s.cachedWidth!==m){const h=Ae(a,mt,m);s.cachedLines=h.visualLines,s.cachedSkipped=h.skippedCount,s.cachedWidth=m}if(s.cachedSkipped&&s.cachedSkipped>0){const h=x.fg("muted",G(P("... (\u524D\u9762\u8FD8\u6709 {count} \u884C\uFF0C"),{count:s.cachedSkipped}))+` ${Ie("app.tools.expand",P("\u5373\u53EF\u5C55\u5F00"))}${x.fg("muted",")")}`;return["",De(h,m,"..."),...s.cachedLines??[]]}return["",...s.cachedLines??[]]},"render"),invalidate:r(()=>{s.cachedWidth=void 0,s.cachedLines=void 0,s.cachedSkipped=void 0},"invalidate")})}if(b?.truncated||c){const a=[];c&&a.push(G(P("\u5B8C\u6574\u8F93\u51FA\uFF1A{path}"),{path:c})),b?.truncated&&(b.truncatedBy==="lines"?a.push(G(P("\u5DF2\u622A\u65AD\uFF1A\u663E\u793A {shown}/{total} \u884C"),{shown:b.outputLines,total:b.totalLines})):a.push(G(P("\u5DF2\u622A\u65AD\uFF1A\u663E\u793A\u4E86 {shown} \u884C\uFF08\u4E0A\u9650 {limit}\uFF09"),{shown:b.outputLines,limit:Ze(b.maxBytes??Qe)}))),t.addChild(new W(`
9
+ ${x.fg("warning",`[${a.join(". ")}]`)}`,0,0))}$&&t.addChild(new W(`
10
+ ${x.fg("muted",$)}`,0,0))}r(St,"rebuildBashResultRenderComponent");function bt(t,e,n,o){let u;if(!t.isPartial&&o!==void 0)u=o;else if(e!==void 0)u=(n??Date.now())-e;else return;if(!(!t.isPartial&&u<100))return`${t.isPartial?P("\u5DF2\u8FD0\u884C"):P("\u8017\u65F6")} ${ht(u)}`}r(bt,"bashTimingLabel");function xt(t,e,n){const o=n?.operations??e.defaultOperations?.()??dt({shellPath:n?.shellPath}),u=n?.commandPrefix,i=n?.exposeSessionEnvironment??!0,y=n?.spawnHook,w=n?.sandbox,s=n?.operations===void 0,$=w?.describeForModel(),S=n?.background;let b=!1;const c=r(a=>`Execute a ${e.shellName} command in the current working directory; returns stdout and stderr. Long output is cut to its start and end (error lines kept) and the full output saved to a file named in the result. ${a?`A command still running after \`timeout\` seconds (default ${ne}) keeps running in the background: you get its id and the output so far, then use the process tool to poll or kill it.`:`A command still running after \`timeout\` seconds (default ${te/1e3}) is killed.`}${$?` ${$}`:""}`,"describe");return{name:e.name,label:e.label,description:c(!1),prepareLoadout:S&&s?a=>(b=a.declared.some(m=>m.name==="process"),b?{descriptions:{[e.name]:c(!0)}}:void 0):void 0,promptSnippet:e.promptSnippet,promptGuidelines:i&&e.promptGuidelines?[...e.promptGuidelines]:void 0,executionMode:"sequential",executionModeFor:e.readOnlyCommand&&!u?a=>e.readOnlyCommand?.(a?.command)?"parallel":void 0:void 0,parameters:w?.active?st:Se,outputSchema:rt,constrainedSampling:{type:"json_schema",strict:"prefer"},async execute(a,m,h,p,f){const{command:_,timeout:A}=m;p&&p({content:[],details:void 0});const D=w??(s?Ue():void 0),H=await lt({toolName:e.name,command:_,cwd:f?.cwd||t,sessionFile:f?.sessionManager?.getSessionFile(),...D?.active?{tempDir:D.scratchDir()}:{}});if(H!==void 0)throw new le(H,He(void 0,Ge("dangerous-command",H)));const V=u?`${u}
11
+ ${_}`:_,k=ct(V,f?.cwd||t,y,i,f);let L;if(D?.active){if(!e.sandboxShell)throw new Error(`Command refused: ${e.shellName} commands cannot run inside the OS sandbox yet, and the sandbox level is "${D.level}". Use the bash tool, or the user can opt out with \`dal --sandbox off\`.`);L=await D.prepare({command:k.command,cwd:k.cwd,shell:e.sandboxShell(n?.shellPath),shellKind:e.sandboxShellKind??"bash",env:k.env,toolCallId:a,toolName:e.name,escalation:m.sandbox_escalation,ctx:f,signal:h})}const C=new We({tempFilePrefix:e.tempFilePrefix,maxBytes:ee});let Y=!0,j,X=!1,re=0;const K=r(()=>{if(!p||!X)return;X=!1,re=Date.now();const d=C.snapshot({persistIfTruncated:!0});p({content:[{type:"text",text:d.content||""}],details:{truncation:d.truncation.truncated?d.truncation:void 0,fullOutputPath:d.fullOutputPath}})},"emitOutputUpdate"),q=r(()=>{j&&(clearTimeout(j),j=void 0)},"clearUpdateTimer"),xe=r(()=>{if(!p)return;X=!0;const d=pt-(Date.now()-re);if(d<=0){q(),K();return}j??=setTimeout(()=>{j=void 0,K()},d)},"scheduleOutputUpdate"),Ee=r(d=>{Y&&(C.append(d),xe())},"handleData"),_e=r(async()=>{Y=!1,C.finish(),q(),K();const d=C.snapshot({persistIfTruncated:!0});return await C.closeTempFile(),d},"finishOutput"),z=r(async(d="(no output)")=>{const O=await _e(),M=await C.readFullOutput(tt),T=Ye()?void 0:Ve(M.content),E=et(T?.text??M.content,ee);let I=O.fullOutputPath;(E.truncated||T)&&!I&&(I=await Me(e.tempFilePrefix,".log",M.content));let F=E.content||d,R;const U=O.truncation.totalLines;return E.truncated?(R={truncation:{content:E.content,truncated:!0,truncatedBy:"bytes",totalLines:U,totalBytes:O.truncation.totalBytes,outputLines:E.headLines+E.tailLines,outputBytes:Buffer.byteLength(E.content,"utf-8"),lastLinePartial:!1,firstLineExceedsLimit:!1,maxLines:U,maxBytes:ee},fullOutputPath:I},F+=`
12
12
 
13
- [Truncated: first ${E.headLines} and last ${E.tailLines} of ${E.totalLines} lines shown${C?`, after condensing ${U} lines (${C.summary})`:""}; read more with read (offset/limit) or grep. Full output: ${D}]`):C&&(R={fullOutputPath:D},M+=`
13
+ [Truncated: first ${E.headLines} and last ${E.tailLines} of ${E.totalLines} lines shown${T?`, after condensing ${U} lines (${T.summary})`:""}; read more with read (offset/limit) or grep. Full output: ${I}]`):T&&(R={fullOutputPath:I},F+=`
14
14
 
15
- [Condensed: ${C.summary}. Full output: ${D}]`),{text:M,details:R,snapshot:O}},"modelOutput"),B=a((d,O)=>`${d?`${d}
15
+ [Condensed: ${T.summary}. Full output: ${I}]`),{text:F,details:R,snapshot:O}},"modelOutput"),B=r((d,O)=>`${d?`${d}
16
16
 
17
- `:""}${O}`,"appendStatus"),re=performance.now();let v;const J=S&&s&&b?d=>{W=!1;try{return v=S.adopt({child:d,command:_,cwd:L.cwd,...T?{prepared:T}:{},...P.handOff()}),!0}catch{return W=!0,!1}}:void 0;try{let d;try{const g=await o.exec(T?.command??L.command,L.cwd,{onData:Ee,signal:h,timeout:A??(J?ne:void 0),env:L.env,...J?{yieldTo:J}:{}});if(g.yielded&&v){const{text:F,details:Z}=await z(""),Oe=A??ne,ge=v.urls.length>0?` It printed ${v.urls.join(" ")}.`:"",ye=`[Still running after ${Oe}s, now in the background as ${v.id}.${ge} For new output and the exit code call process with action "poll" and id "${v.id}"; "kill" stops it.]`,de=await P.readFullOutput(we);return{content:[{type:"text",text:B(F,ye)}],details:{...Z,background:v},structuredContent:{output:de.content,truncated:de.truncated,exit_code:-1,background_id:v.id,wall_time_seconds:Math.round((performance.now()-re)/100)/10}}}d=g.exitCode}catch(g){const{text:F}=await z("");if(await T?.finish(null,""),g instanceof Error&&g.message==="aborted")throw new Error(B(F,"Command aborted"));if(g instanceof Error&&g.message.startsWith("timeout:")){const Z=g.message.split(":")[1];throw new Error(B(F,`Command timed out after ${Z} seconds`))}throw g}const{text:O,details:k,snapshot:C}=await z(),E=await T?.finish(d,C.content||"");if(E&&T)throw new le(`${B(O,`Command exited with code ${d??"(none)"}`)}
17
+ `:""}${O}`,"appendStatus"),ae=performance.now();let v;const J=S&&s&&b?d=>{Y=!1;try{return v=S.adopt({child:d,command:_,cwd:k.cwd,...L?{prepared:L}:{},...C.handOff()}),!0}catch{return Y=!0,!1}}:void 0;try{let d;try{const g=await o.exec(L?.command??k.command,k.cwd,{onData:Ee,signal:h,timeout:A??(J?ne:void 0),env:k.env,...J?{yieldTo:J}:{}});if(g.yielded&&v){const{text:N,details:Z}=await z(""),Oe=A??ne,ge=v.urls.length>0?` It printed ${v.urls.join(" ")}.`:"",ye=`[Still running after ${Oe}s, now in the background as ${v.id}.${ge} For new output and the exit code call process with action "poll" and id "${v.id}"; "kill" stops it.]`,de=await C.readFullOutput(we);return{content:[{type:"text",text:B(N,ye)}],details:{...Z,background:v},structuredContent:{output:de.content,truncated:de.truncated,exit_code:-1,background_id:v.id,wall_time_seconds:Math.round((performance.now()-ae)/100)/10}}}d=g.exitCode}catch(g){const{text:N}=await z("");if(await L?.finish(null,""),g instanceof Error&&g.message==="aborted")throw new Error(B(N,"Command aborted"));if(g instanceof Error&&g.message.startsWith("timeout:")){const Z=g.message.split(":")[1];throw new Error(B(N,`Command timed out after ${Z} seconds`))}throw g}const{text:O,details:M,snapshot:T}=await z(),E=await L?.finish(d,T.content||"");if(E&&L)throw new le(`${B(O,`Command exited with code ${d??"(none)"}`)}
18
18
 
19
- ${Re(E)}`,{...k,sandbox:T.details});if(d===null)throw new Error(B(O,"Command terminated without an exit code"));const D=Math.round((performance.now()-re)/100)/10,M=await P.readFullOutput(we),R={output:M.content,truncated:M.truncated,...M.truncated&&C.fullOutputPath?{full_output_path:C.fullOutputPath}:{},exit_code:d,wall_time_seconds:D},U=T?.details.escalation?T.details:void 0,Q=U?{...k,sandbox:U}:k;if(d!==0){const g=d===127?await Be(O):void 0,F=B(O,`Command exited with code ${d}`);return{content:[{type:"text",text:g?`${F}
20
- ${g}`:F}],details:Q,structuredContent:R,isError:!0}}return{content:[{type:"text",text:O}],details:Q,structuredContent:R}}finally{q()}},renderCall(r,m,h){const p=h.state;h.executionStarted&&p.startedAt===void 0&&(p.startedAt=Date.now(),p.endedAt=void 0);const f=h.lastComponent??new j("",0,0);return f.setText(wt(r,e.prompt,h.expanded===!0)),f},renderResult(r,m,h,p){const f=p.state;f.startedAt!==void 0&&m.isPartial&&!f.interval&&(f.interval=setInterval(()=>p.invalidate(),1e3)),(!m.isPartial||p.isError)&&(f.endedAt??=Date.now(),f.interval&&(clearInterval(f.interval),f.interval=void 0));const _=p.lastComponent??new ft;return St(_,r,m,p.showImages,f.startedAt,f.endedAt,p.isError,p.durationMs),_.invalidate(),_}}}a(xt,"createShellToolDefinition");const Et={name:"bash",label:"bash",shellName:"bash",prompt:"$",promptSnippet:be.snippet,promptGuidelines:be.guidelines,tempFilePrefix:"dal-bash",readOnlyCommand:je,sandboxShell:a(t=>ue(t).shell,"sandboxShell")};function _t(t,e){return xt(t,Et,e)}a(_t,"createBashToolDefinition");function Kt(t,e){const n=_t(t,e),o=Je(n);return Object.assign(o,{promptSnippet:n.promptSnippet,promptGuidelines:n.promptGuidelines}),o}a(Kt,"createBashTool");export{be as bashToolSystemPromptContribution,Kt as createBashTool,_t as createBashToolDefinition,dt as createLocalBashOperations,rt as createLocalShellOperations,xt as createShellToolDefinition,Xt as registerShellExecutionGuard,it as sandboxEscalationSchema,lt as shellExecutionRefusal};
19
+ ${Re(E)}`,{...M,sandbox:L.details});if(d===null)throw new Error(B(O,"Command terminated without an exit code"));const I=Math.round((performance.now()-ae)/100)/10,F=await C.readFullOutput(we),R={output:F.content,truncated:F.truncated,...F.truncated&&T.fullOutputPath?{full_output_path:T.fullOutputPath}:{},exit_code:d,wall_time_seconds:I},U=L?.details.escalation?L.details:void 0,Q=U?{...M,sandbox:U}:M;if(d!==0){const g=d===127?await Be(O):void 0,N=B(O,`Command exited with code ${d}`);return{content:[{type:"text",text:g?`${N}
20
+ ${g}`:N}],details:Q,structuredContent:R,isError:!0}}return{content:[{type:"text",text:O}],details:Q,structuredContent:R}}finally{q()}},renderCall(a,m,h){const p=h.state;h.executionStarted&&p.startedAt===void 0&&(p.startedAt=Date.now(),p.endedAt=void 0);const f=h.lastComponent??new W("",0,0);return f.setText(wt(a,e.prompt,h.expanded===!0)),f},renderResult(a,m,h,p){const f=p.state;f.startedAt!==void 0&&m.isPartial&&!f.interval&&(f.interval=setInterval(()=>p.invalidate(),1e3)),(!m.isPartial||p.isError)&&(f.endedAt??=Date.now(),f.interval&&(clearInterval(f.interval),f.interval=void 0));const _=p.lastComponent??new ft;return St(_,a,m,p.showImages,f.startedAt,f.endedAt,p.isError,p.durationMs),_.invalidate(),_}}}r(xt,"createShellToolDefinition");const Et={name:"bash",label:"bash",shellName:"bash",prompt:"$",promptSnippet:be.snippet,promptGuidelines:be.guidelines,tempFilePrefix:"dal-bash",readOnlyCommand:je,sandboxShell:r(t=>ue(t).shell,"sandboxShell")};function _t(t,e){return xt(t,Et,e)}r(_t,"createBashToolDefinition");function Kt(t,e){const n=_t(t,e),o=Je(n);return Object.assign(o,{promptSnippet:n.promptSnippet,promptGuidelines:n.promptGuidelines}),o}r(Kt,"createBashTool");export{be as bashToolSystemPromptContribution,Kt as createBashTool,_t as createBashToolDefinition,dt as createLocalBashOperations,at as createLocalShellOperations,xt as createShellToolDefinition,Xt as registerShellExecutionGuard,it as sandboxEscalationSchema,lt as shellExecutionRefusal};
@@ -16,7 +16,7 @@ declare const editSchema: Type.TObject<{
16
16
  }>;
17
17
  export declare const editToolSystemPromptContribution: {
18
18
  readonly snippet: "Make precise file edits with exact text replacement, including multiple disjoint edits in one call";
19
- readonly guidelines: readonly ["Use edit for precise changes (edits[].oldText must match exactly)", "When changing multiple separate locations in one file, use one edit call with multiple entries in edits[] instead of multiple edit calls", "Each edits[].oldText is matched against the original file, not after earlier edits are applied. Do not emit overlapping or nested edits. Merge nearby changes into one edit.", "Keep edits[].oldText as small as possible while still being unique in the file. Do not pad with large unchanged regions."];
19
+ readonly guidelines: readonly ["Use edit for precise changes: each edits[].oldText matches the original file exactly, is unique and as short as that allows; several changes to one file go in one call, without overlapping"];
20
20
  };
21
21
  export type EditToolInput = Static<typeof editSchema>;
22
22
  export interface EditToolDetails {
@@ -1,3 +1,3 @@
1
- var B=Object.defineProperty;var d=(e,t)=>B(e,"name",{value:t,configurable:!0});import{Box as v,Container as W,Spacer as x,Text as E}from"@earendil-works/pi-tui";import{constants as A}from"fs";import{access as k,readFile as q,writeFile as M}from"fs/promises";import{Type as g}from"typebox";import{renderDiff as S}from"../../modes/interactive/components/diff.js";import{splitBom as N}from"../../utils/text.js";import{applyEditsToNormalizedContent as z,computeEditsDiff as J,detectLineEnding as U,generateDiffString as G,generateUnifiedPatch as H,normalizeToLF as Q,restoreLineEndings as X}from"./edit-diff.js";import{withFileMutationQueue as V}from"./file-mutation-queue.js";import{resolveToCwd as Y}from"./path-utils.js";import{renderToolPath as Z,str as P}from"./render-utils.js";import{wrapToolDefinition as ee}from"./tool-definition-wrapper.js";const te=g.Object({oldText:g.String({description:"Exact text for one targeted replacement. It must be unique in the original file and must not overlap with any other edits[].oldText in the same call."}),newText:g.String({description:"Replacement text for this targeted edit."})},{}),ie=g.Object({path:g.String({description:"Path to the file to edit (relative or absolute)"}),edits:g.Array(te,{description:"One or more targeted replacements. Each edit is matched against the original file, not incrementally. Do not include overlapping or nested edits. If two changes touch the same block or nearby lines, merge them into one edit instead."})},{}),D={snippet:"Make precise file edits with exact text replacement, including multiple disjoint edits in one call",guidelines:["Use edit for precise changes (edits[].oldText must match exactly)","When changing multiple separate locations in one file, use one edit call with multiple entries in edits[] instead of multiple edit calls","Each edits[].oldText is matched against the original file, not after earlier edits are applied. Do not emit overlapping or nested edits. Merge nearby changes into one edit.","Keep edits[].oldText as small as possible while still being unique in the file. Do not pad with large unchanged regions."]};function F(e){if(!e||typeof e!="object"||Array.isArray(e))return!1;const t=e;return typeof t.oldText=="string"&&typeof t.newText=="string"}d(F,"isSingleEditInput");const re={readFile:d(e=>q(e),"readFile"),writeFile:d((e,t)=>M(e,t,"utf-8"),"writeFile"),access:d(e=>k(e,A.R_OK|A.W_OK),"access")};function ne(e){if(!e||typeof e!="object")return e;const t=e;if(typeof t.edits=="string")try{const o=JSON.parse(t.edits);Array.isArray(o)?t.edits=o:F(o)&&(t.edits=[o])}catch{}else F(t.edits)&&(t.edits=[t.edits]);const r=t;if(typeof r.oldText!="string"||typeof r.newText!="string")return t;const i=Array.isArray(r.edits)?[...r.edits]:[];i.push({oldText:r.oldText,newText:r.newText});const{oldText:f,newText:a,...n}=r;return{...n,edits:i}}d(ne,"prepareEditArguments");function oe(e){if(!Array.isArray(e.edits)||e.edits.length===0)throw new Error("Edit tool input is invalid. edits must contain at least one replacement.");return{path:e.path,edits:e.edits}}d(oe,"validateEditInput");function se(){return Object.assign(new v(0,0),{preview:void 0,previewArgsKey:void 0,previewPending:!1,settledError:!1})}d(se,"createEditCallRenderComponent");function de(e,t){if(t instanceof v){const i=t;return e.callComponent=i,i}if(e.callComponent)return e.callComponent;const r=se();return e.callComponent=r,r}d(de,"getEditCallRenderComponent");function K(e){if(!e)return null;const t=typeof e.path=="string"?e.path:typeof e.file_path=="string"?e.file_path:null;return t?Array.isArray(e.edits)&&e.edits.length>0&&e.edits.every(r=>typeof r?.oldText=="string"&&typeof r?.newText=="string")?{path:t,edits:e.edits}:typeof e.oldText=="string"&&typeof e.newText=="string"?{path:t,edits:[{oldText:e.oldText,newText:e.newText}]}:null:null}d(K,"getRenderablePreviewInput");function ae(e){let t=0,r=0;for(const i of e.split(`
2
- `))i.startsWith("+")&&!i.startsWith("+++")&&t++,i.startsWith("-")&&!i.startsWith("---")&&r++;return{additions:t,removals:r}}d(ae,"diffStats");function le(e,t,r){const i=Z(P(e?.file_path??e?.path),t,r);return`${t.fg("toolTitle",t.bold("edit"))} ${i}`}d(le,"formatEditCall");function fe(e,t,r,i,f){const a=P(e?.file_path??e?.path),n=t&&!("error"in t)?t.diff:void 0,o=t&&"error"in t?t.error:void 0;if(f){const c=r.content.filter(l=>l.type==="text").map(l=>l.text||"").join(`
3
- `);return!c||c===o?void 0:i.fg("error",c)}const s=r.details?.diff;if(s&&s!==n)return S(s,{filePath:a??void 0})}d(fe,"formatEditResult");function ce(e,t,r){return e?"error"in e?i=>r.bg("toolErrorBg",i):i=>r.bg("toolSuccessBg",i):t?i=>r.bg("toolErrorBg",i):i=>r.bg("toolPendingBg",i)}d(ce,"getEditHeaderBg");function O(e,t,r,i,f,a){e.setPaddingX(a),e.setBgFn("error"in(e.preview??{})||e.settledError?ce(e.preview,e.settledError,r):void 0),e.clear();let n=le(t,r,i);if(!f&&e.preview&&!("error"in e.preview)){const{additions:s,removals:c}=ae(e.preview.diff);n+=r.fg("muted",` +${s} / -${c}`)}if(e.addChild(new E(n,0,0)),!e.preview||!f&&!("error"in e.preview))return e;const o="error"in e.preview?r.fg("error",e.preview.error):S(e.preview.diff);return e.addChild(new x(1)),e.addChild(new E(o,0,0)),e}d(O,"buildEditCallComponent");function _(e,t,r){const i=e.preview,f=i===void 0||("error"in i&&"error"in t?i.error!==t.error:"error"in i!="error"in t)||!("error"in i)&&!("error"in t)&&(i.diff!==t.diff||i.firstChangedLine!==t.firstChangedLine);return e.preview=t,e.previewArgsKey=r,e.previewPending=!1,f}d(_,"setEditPreview");function pe(e,t){const r=t?.operations??re;return{name:"edit",label:"edit",description:"Edit a single file using exact text replacement. Every edits[].oldText must match a unique, non-overlapping region of the original file. If two changes affect the same block or nearby lines, merge them into one edit instead of emitting overlapping edits. Do not include large unchanged regions just to connect distant changes.",promptSnippet:D.snippet,promptGuidelines:[...D.guidelines],parameters:ie,constrainedSampling:{type:"json_schema",strict:"prefer"},renderShell:"self",prepareArguments:ne,async execute(i,f,a,n,o){const{path:s,edits:c}=oe(f),l=Y(s,o?.cwd||e);return V(l,async()=>{const p=d(()=>{if(a?.aborted)throw new Error("Operation aborted")},"throwIfAborted");p();try{await r.access(l)}catch(m){p();const $=m instanceof Error&&"code"in m?`Error code: ${m.code}`:String(m);throw new Error(`Could not edit file: ${s}. ${$}.`)}p();const w=(await r.readFile(l)).toString("utf-8");p();const{bom:u,text:T}=N(w),I=U(T),R=Q(T),{baseContent:C,newContent:y}=z(R,c,s);p();const j=u+X(y,I);await r.writeFile(l,j),p();const b=G(C,y),L=H(s,C,y);return{content:[{type:"text",text:`Successfully replaced ${c.length} block(s) in ${s}.`}],details:{diff:b.diff,patch:L,firstChangedLine:b.firstChangedLine}}})},renderCall(i,f,a){const n=de(a.state,a.lastComponent),o=K(i),s=o?JSON.stringify({path:o.path,edits:o.edits}):void 0;if(n.previewArgsKey!==s&&(n.preview=void 0,n.previewArgsKey=s,n.previewPending=!1,n.settledError=!1),a.argsComplete&&o&&!n.preview&&!n.previewPending){n.previewPending=!0;const c=s;J(o.path,o.edits,a.cwd).then(l=>{n.previewArgsKey===c&&(_(n,l,c),a.invalidate())})}return O(n,i,f,a.cwd,a.expanded,a.outputPad)},renderResult(i,f,a,n){const o=n.state.callComponent,s=K(n.args),c=s?JSON.stringify({path:s.path,edits:s.edits}):void 0,l=i,p=n.isError?void 0:l.details?.diff;let h=!1;o&&(typeof p=="string"&&(h=_(o,{diff:p,firstChangedLine:l.details?.firstChangedLine},c)||h),o.settledError!==n.isError&&(o.settledError=n.isError,h=!0),h&&O(o,n.args,a,n.cwd,f.expanded,n.outputPad));const w=fe(n.args,o?.preview,l,a,n.isError),u=n.lastComponent??new W;return u.clear(),w&&(u.addChild(new x(1)),u.addChild(new E(w,1+n.outputPad,0))),u}}}d(pe,"createEditToolDefinition");function Ae(e,t){return ee(pe(e,t))}d(Ae,"createEditTool");export{Ae as createEditTool,pe as createEditToolDefinition,D as editToolSystemPromptContribution};
1
+ var B=Object.defineProperty;var d=(e,t)=>B(e,"name",{value:t,configurable:!0});import{Box as b,Container as W,Spacer as x,Text as E}from"@earendil-works/pi-tui";import{constants as A}from"fs";import{access as k,readFile as q,writeFile as N}from"fs/promises";import{Type as g}from"typebox";import{renderDiff as S}from"../../modes/interactive/components/diff.js";import{splitBom as z}from"../../utils/text.js";import{applyEditsToNormalizedContent as J,computeEditsDiff as M,detectLineEnding as U,generateDiffString as G,generateUnifiedPatch as H,normalizeToLF as Q,restoreLineEndings as X}from"./edit-diff.js";import{withFileMutationQueue as V}from"./file-mutation-queue.js";import{resolveToCwd as Y}from"./path-utils.js";import{renderToolPath as Z,str as P}from"./render-utils.js";import{wrapToolDefinition as ee}from"./tool-definition-wrapper.js";const te=g.Object({oldText:g.String({description:"Exact text for one targeted replacement. It must be unique in the original file and must not overlap with any other edits[].oldText in the same call."}),newText:g.String({description:"Replacement text for this targeted edit."})},{}),re=g.Object({path:g.String({description:"Path to the file to edit (relative or absolute)"}),edits:g.Array(te,{description:"One or more targeted replacements. Each edit is matched against the original file, not incrementally. Do not include overlapping or nested edits. If two changes touch the same block or nearby lines, merge them into one edit instead."})},{}),D={snippet:"Make precise file edits with exact text replacement, including multiple disjoint edits in one call",guidelines:["Use edit for precise changes: each edits[].oldText matches the original file exactly, is unique and as short as that allows; several changes to one file go in one call, without overlapping"]};function F(e){if(!e||typeof e!="object"||Array.isArray(e))return!1;const t=e;return typeof t.oldText=="string"&&typeof t.newText=="string"}d(F,"isSingleEditInput");const ie={readFile:d(e=>q(e),"readFile"),writeFile:d((e,t)=>N(e,t,"utf-8"),"writeFile"),access:d(e=>k(e,A.R_OK|A.W_OK),"access")};function ne(e){if(!e||typeof e!="object")return e;const t=e;if(typeof t.edits=="string")try{const o=JSON.parse(t.edits);Array.isArray(o)?t.edits=o:F(o)&&(t.edits=[o])}catch{}else F(t.edits)&&(t.edits=[t.edits]);const i=t;if(typeof i.oldText!="string"||typeof i.newText!="string")return t;const r=Array.isArray(i.edits)?[...i.edits]:[];r.push({oldText:i.oldText,newText:i.newText});const{oldText:f,newText:a,...n}=i;return{...n,edits:r}}d(ne,"prepareEditArguments");function oe(e){if(!Array.isArray(e.edits)||e.edits.length===0)throw new Error("Edit tool input is invalid. edits must contain at least one replacement.");return{path:e.path,edits:e.edits}}d(oe,"validateEditInput");function se(){return Object.assign(new b(0,0),{preview:void 0,previewArgsKey:void 0,previewPending:!1,settledError:!1})}d(se,"createEditCallRenderComponent");function de(e,t){if(t instanceof b){const r=t;return e.callComponent=r,r}if(e.callComponent)return e.callComponent;const i=se();return e.callComponent=i,i}d(de,"getEditCallRenderComponent");function O(e){if(!e)return null;const t=typeof e.path=="string"?e.path:typeof e.file_path=="string"?e.file_path:null;return t?Array.isArray(e.edits)&&e.edits.length>0&&e.edits.every(i=>typeof i?.oldText=="string"&&typeof i?.newText=="string")?{path:t,edits:e.edits}:typeof e.oldText=="string"&&typeof e.newText=="string"?{path:t,edits:[{oldText:e.oldText,newText:e.newText}]}:null:null}d(O,"getRenderablePreviewInput");function ae(e){let t=0,i=0;for(const r of e.split(`
2
+ `))r.startsWith("+")&&!r.startsWith("+++")&&t++,r.startsWith("-")&&!r.startsWith("---")&&i++;return{additions:t,removals:i}}d(ae,"diffStats");function le(e,t,i){const r=Z(P(e?.file_path??e?.path),t,i);return`${t.fg("toolTitle",t.bold("edit"))} ${r}`}d(le,"formatEditCall");function fe(e,t,i,r,f){const a=P(e?.file_path??e?.path),n=t&&!("error"in t)?t.diff:void 0,o=t&&"error"in t?t.error:void 0;if(f){const c=i.content.filter(l=>l.type==="text").map(l=>l.text||"").join(`
3
+ `);return!c||c===o?void 0:r.fg("error",c)}const s=i.details?.diff;if(s&&s!==n)return S(s,{filePath:a??void 0})}d(fe,"formatEditResult");function ce(e,t,i){return e?"error"in e?r=>i.bg("toolErrorBg",r):r=>i.bg("toolSuccessBg",r):t?r=>i.bg("toolErrorBg",r):r=>i.bg("toolPendingBg",r)}d(ce,"getEditHeaderBg");function _(e,t,i,r,f,a){e.setPaddingX(a),e.setBgFn("error"in(e.preview??{})||e.settledError?ce(e.preview,e.settledError,i):void 0),e.clear();let n=le(t,i,r);if(!f&&e.preview&&!("error"in e.preview)){const{additions:s,removals:c}=ae(e.preview.diff);n+=i.fg("muted",` +${s} / -${c}`)}if(e.addChild(new E(n,0,0)),!e.preview||!f&&!("error"in e.preview))return e;const o="error"in e.preview?i.fg("error",e.preview.error):S(e.preview.diff);return e.addChild(new x(1)),e.addChild(new E(o,0,0)),e}d(_,"buildEditCallComponent");function I(e,t,i){const r=e.preview,f=r===void 0||("error"in r&&"error"in t?r.error!==t.error:"error"in r!="error"in t)||!("error"in r)&&!("error"in t)&&(r.diff!==t.diff||r.firstChangedLine!==t.firstChangedLine);return e.preview=t,e.previewArgsKey=i,e.previewPending=!1,f}d(I,"setEditPreview");function pe(e,t){const i=t?.operations??ie;return{name:"edit",label:"edit",description:"Edit a single file using exact text replacement. Every edits[].oldText must match a unique, non-overlapping region of the original file. If two changes affect the same block or nearby lines, merge them into one edit instead of emitting overlapping edits. Do not include large unchanged regions just to connect distant changes.",promptSnippet:D.snippet,promptGuidelines:[...D.guidelines],parameters:re,constrainedSampling:{type:"json_schema",strict:"prefer"},renderShell:"self",prepareArguments:ne,async execute(r,f,a,n,o){const{path:s,edits:c}=oe(f),l=Y(s,o?.cwd||e);return V(l,async()=>{const p=d(()=>{if(a?.aborted)throw new Error("Operation aborted")},"throwIfAborted");p();try{await i.access(l)}catch(y){p();const $=y instanceof Error&&"code"in y?`Error code: ${y.code}`:String(y);throw new Error(`Could not edit file: ${s}. ${$}.`)}p();const w=(await i.readFile(l)).toString("utf-8");p();const{bom:u,text:C}=z(w),K=U(C),R=Q(C),{baseContent:T,newContent:m}=J(R,c,s);p();const j=u+X(m,K);await i.writeFile(l,j),p();const v=G(T,m),L=H(s,T,m);return{content:[{type:"text",text:`Successfully replaced ${c.length} block(s) in ${s}.`}],details:{diff:v.diff,patch:L,firstChangedLine:v.firstChangedLine}}})},renderCall(r,f,a){const n=de(a.state,a.lastComponent),o=O(r),s=o?JSON.stringify({path:o.path,edits:o.edits}):void 0;if(n.previewArgsKey!==s&&(n.preview=void 0,n.previewArgsKey=s,n.previewPending=!1,n.settledError=!1),a.argsComplete&&o&&!n.preview&&!n.previewPending){n.previewPending=!0;const c=s;M(o.path,o.edits,a.cwd).then(l=>{n.previewArgsKey===c&&(I(n,l,c),a.invalidate())})}return _(n,r,f,a.cwd,a.expanded,a.outputPad)},renderResult(r,f,a,n){const o=n.state.callComponent,s=O(n.args),c=s?JSON.stringify({path:s.path,edits:s.edits}):void 0,l=r,p=n.isError?void 0:l.details?.diff;let h=!1;o&&(typeof p=="string"&&(h=I(o,{diff:p,firstChangedLine:l.details?.firstChangedLine},c)||h),o.settledError!==n.isError&&(o.settledError=n.isError,h=!0),h&&_(o,n.args,a,n.cwd,f.expanded,n.outputPad));const w=fe(n.args,o?.preview,l,a,n.isError),u=n.lastComponent??new W;return u.clear(),w&&(u.addChild(new x(1)),u.addChild(new E(w,1+n.outputPad,0))),u}}}d(pe,"createEditToolDefinition");function Ae(e,t){return ee(pe(e,t))}d(Ae,"createEditTool");export{Ae as createEditTool,pe as createEditToolDefinition,D as editToolSystemPromptContribution};
@@ -6,7 +6,7 @@ ${C(b("... (\u8FD8\u6709 {count} \u884C\uFF0C"),{count:F})}`)} ${bt("app.tools.e
6
6
  ${l.fg("warning",C(b("[\u5DF2\u622A\u65AD\uFF1A{reasons}]"),{reasons:s.join(", ")}))}`}return r}i(Pt,"formatGrepResult");function Rt(n,o){const l=o?.operations;return{name:"grep",label:"grep",description:`Search file contents for a pattern. Returns matching lines with file paths and line numbers. Respects .gitignore. Output is truncated to ${ft} matches or ${z/1024}KB (whichever is hit first). Long lines are truncated to ${pt} chars.`,promptSnippet:_t.snippet,parameters:Mt,async execute(d,{pattern:m,path:p,glob:r,ignoreCase:u,literal:x,context:L,limit:s},O,U,F){return new Promise((P,$)=>{if(O?.aborted){$(new Error("Operation aborted"));return}let H=!1;const T=i(E=>{H||(H=!0,E())},"settle");(async()=>{try{const E=await yt("rg");if(!E){T(()=>$(new Error("ripgrep (rg) is not available and could not be downloaded")));return}const S=Lt(p||".",F?.cwd||n),X=l??At,J=l?void 0:st(S);if(J){T(()=>$(new Error(J)));return}let K;try{K=await X.isDirectory(S)}catch{T(()=>$(new Error(`Path not found: ${S}`)));return}const D=L&&L>0?L:0,M=Math.max(1,s??ft),V=i(e=>{if(K){const t=B.relative(S,e);if(t&&!t.startsWith(".."))return t.replace(/\\/g,"/")}return B.basename(e)},"formatPath"),W=new Map,dt=i(async e=>{let t=W.get(e);if(!t){try{t=(await X.readFile(e)).replace(/\r\n/g,`
7
7
  `).replace(/\r/g,`
8
8
  `).split(`
9
- `)}catch{t=[]}W.set(e,t)}return t},"getFileLines"),_=["--json","--line-number","--color=never","--hidden"];u&&_.push("--ignore-case"),x&&_.push("--fixed-strings"),r&&_.push("--glob",r),_.push("--",m,S);const v=$t(E,_,{stdio:["ignore","pipe","pipe"]}),Y=wt({input:v.stdout});let j="",A=0,q=!1,R=!1,Q=!1,Z=!1;const k=[],tt=i(()=>{Y.close(),O?.removeEventListener("abort",nt)},"cleanup"),et=i((e=!1)=>{v.killed||(Z=e,v.kill())},"stopChild"),nt=i(()=>{Q=!0,et()},"onAbort");O?.addEventListener("abort",nt,{once:!0}),v.stderr?.on("data",e=>{j+=e.toString()});const mt=i(async(e,t)=>{const c=V(e),w=await dt(e);if(!w.length)return[`${c}:${t}: (unable to read file)`];const f=[],y=D>0?Math.max(1,t-D):t,h=D>0?Math.min(w.length,t+D):t;for(let g=y;g<=h;g++){const G=(w[g-1]??"").replace(/\r/g,""),N=g===t,{text:it,wasTruncated:ht}=ut(G);ht&&(R=!0),N?f.push(`${c}:${g}: ${it}`):f.push(`${c}-${g}- ${it}`)}return f},"formatBlock"),rt=[];Y.on("line",e=>{if(!e.trim()||A>=M)return;let t;try{t=JSON.parse(e)}catch{return}if(t.type==="match"){A++;const c=t.data?.path?.text,w=t.data?.line_number,f=t.data?.lines?.text;if(c&&!l&&st(B.resolve(S,c))){A--;return}c&&typeof w=="number"&&rt.push({filePath:c,lineNumber:w,lineText:f}),A>=M&&(q=!0,et(!0))}}),v.on("error",e=>{tt(),T(()=>$(new Error(`Failed to run ripgrep: ${e.message}`)))}),v.on("close",async e=>{if(tt(),Q){T(()=>$(new Error("Operation aborted")));return}if(!Z&&e!==0&&e!==1){const h=j.trim()||`ripgrep exited with code ${e}`;T(()=>$(new Error(h)));return}if(A===0){T(()=>P({content:[{type:"text",text:"No matches found"}],details:void 0}));return}for(const h of rt)if(D===0&&h.lineText!==void 0){const g=V(h.filePath),ot=h.lineText.replace(/\r\n/g,`
9
+ `)}catch{t=[]}W.set(e,t)}return t},"getFileLines"),_=["--no-config","--json","--line-number","--color=never","--hidden"];u&&_.push("--ignore-case"),x&&_.push("--fixed-strings"),r&&_.push("--glob",r),_.push("--",m,S);const v=$t(E,_,{stdio:["ignore","pipe","pipe"]}),Y=wt({input:v.stdout});let j="",A=0,q=!1,R=!1,Q=!1,Z=!1;const k=[],tt=i(()=>{Y.close(),O?.removeEventListener("abort",nt)},"cleanup"),et=i((e=!1)=>{v.killed||(Z=e,v.kill())},"stopChild"),nt=i(()=>{Q=!0,et()},"onAbort");O?.addEventListener("abort",nt,{once:!0}),v.stderr?.on("data",e=>{j+=e.toString()});const mt=i(async(e,t)=>{const c=V(e),w=await dt(e);if(!w.length)return[`${c}:${t}: (unable to read file)`];const f=[],y=D>0?Math.max(1,t-D):t,h=D>0?Math.min(w.length,t+D):t;for(let g=y;g<=h;g++){const G=(w[g-1]??"").replace(/\r/g,""),N=g===t,{text:it,wasTruncated:ht}=ut(G);ht&&(R=!0),N?f.push(`${c}:${g}: ${it}`):f.push(`${c}-${g}- ${it}`)}return f},"formatBlock"),rt=[];Y.on("line",e=>{if(!e.trim()||A>=M)return;let t;try{t=JSON.parse(e)}catch{return}if(t.type==="match"){A++;const c=t.data?.path?.text,w=t.data?.line_number,f=t.data?.lines?.text;if(c&&!l&&st(B.resolve(S,c))){A--;return}c&&typeof w=="number"&&rt.push({filePath:c,lineNumber:w,lineText:f}),A>=M&&(q=!0,et(!0))}}),v.on("error",e=>{tt(),T(()=>$(new Error(`Failed to run ripgrep: ${e.message}`)))}),v.on("close",async e=>{if(tt(),Q){T(()=>$(new Error("Operation aborted")));return}if(!Z&&e!==0&&e!==1){const h=j.trim()||`ripgrep exited with code ${e}`;T(()=>$(new Error(h)));return}if(A===0){T(()=>P({content:[{type:"text",text:"No matches found"}],details:void 0}));return}for(const h of rt)if(D===0&&h.lineText!==void 0){const g=V(h.filePath),ot=h.lineText.replace(/\r\n/g,`
10
10
  `).replace(/\r/g,"").replace(/\n$/,""),{text:G,wasTruncated:N}=ut(ot);N&&(R=!0),k.push(`${g}:${h.lineNumber}: ${G}`)}else{const g=await mt(h.filePath,h.lineNumber);k.push(...g)}const t=k.join(`
11
11
  `),c=Dt(t,{maxLines:Number.MAX_SAFE_INTEGER});let w=c.content;const f={},y=[];q&&(y.push(`${M} matches limit reached. Use limit=${M*2} for more, or refine pattern`),f.matchLimitReached=M),c.truncated&&(y.push(`${lt(z)} limit reached`),f.truncation=c),R&&(y.push(`Some lines truncated to ${pt} chars. Use read tool to see full lines`),f.linesTruncated=!0),y.length>0&&(w+=`
12
12
 
@@ -1,4 +1,5 @@
1
1
  export declare function pathExists(filePath: string): Promise<boolean>;
2
+ export declare function expandTempDirVariable(filePath: string, tempDir: string): string;
2
3
  export declare function expandPath(filePath: string): string;
3
4
  export declare function resolveToCwd(filePath: string, cwd: string): string;
4
5
  export declare function resolveReadPath(filePath: string, cwd: string): string;
@@ -1 +1 @@
1
- var d=Object.defineProperty;var n=(t,a)=>d(t,"name",{value:a,configurable:!0});import{accessSync as P,constants as l}from"node:fs";import{access as h}from"node:fs/promises";import{normalizePath as x,resolvePath as V}from"../../utils/paths.js";const w="\u202F";function p(t){return t.replace(/ (AM|PM)\./gi,`${w}$1.`)}n(p,"tryMacOSScreenshotPath");function m(t){return t.normalize("NFD")}n(m,"tryNFDVariant");function f(t){return t.replace(/'/g,"\u2019")}n(f,"tryCurlyQuoteVariant");function c(t){try{return P(t,l.F_OK),!0}catch{return!1}}n(c,"fileExists");async function s(t){try{return await h(t,l.F_OK),!0}catch{return!1}}n(s,"pathExists");function F(t){return x(t,{normalizeUnicodeSpaces:!0,stripAtPrefix:!0})}n(F,"expandPath");function y(t,a){return V(t,a,{normalizeUnicodeSpaces:!0,stripAtPrefix:!0})}n(y,"resolveToCwd");function O(t,a){const r=y(t,a);if(c(r))return r;const i=p(r);if(i!==r&&c(i))return i;const e=m(r);if(e!==r&&c(e))return e;const o=f(r);if(o!==r&&c(o))return o;const u=f(e);return u!==r&&c(u)?u:r}n(O,"resolveReadPath");async function R(t,a){const r=y(t,a);if(await s(r))return r;const i=p(r);if(i!==r&&await s(i))return i;const e=m(r);if(e!==r&&await s(e))return e;const o=f(r);if(o!==r&&await s(o))return o;const u=f(e);return u!==r&&await s(u)?u:r}n(R,"resolveReadPathAsync");export{F as expandPath,s as pathExists,O as resolveReadPath,R as resolveReadPathAsync,y as resolveToCwd};
1
+ var d=Object.defineProperty;var n=(t,e)=>d(t,"name",{value:e,configurable:!0});import{accessSync as x,constants as l}from"node:fs";import{access as P}from"node:fs/promises";import{normalizePath as V,resolvePath as h}from"../../utils/paths.js";const A="\u202F";function p(t){return t.replace(/ (AM|PM)\./gi,`${A}$1.`)}n(p,"tryMacOSScreenshotPath");function m(t){return t.normalize("NFD")}n(m,"tryNFDVariant");function f(t){return t.replace(/'/g,"\u2019")}n(f,"tryCurlyQuoteVariant");function u(t){try{return x(t,l.F_OK),!0}catch{return!1}}n(u,"fileExists");async function s(t){try{return await P(t,l.F_OK),!0}catch{return!1}}n(s,"pathExists");const R=/^(?:\$TMPDIR|\$\{TMPDIR\})(?=[\\/]|$)/;function E(t,e){const r=R.exec(t);return r?e+t.slice(r[0].length):t}n(E,"expandTempDirVariable");function M(t){return V(t,{normalizeUnicodeSpaces:!0,stripAtPrefix:!0})}n(M,"expandPath");function y(t,e){return h(t,e,{normalizeUnicodeSpaces:!0,stripAtPrefix:!0})}n(y,"resolveToCwd");function S(t,e){const r=y(t,e);if(u(r))return r;const i=p(r);if(i!==r&&u(i))return i;const a=m(r);if(a!==r&&u(a))return a;const o=f(r);if(o!==r&&u(o))return o;const c=f(a);return c!==r&&u(c)?c:r}n(S,"resolveReadPath");async function C(t,e){const r=y(t,e);if(await s(r))return r;const i=p(r);if(i!==r&&await s(i))return i;const a=m(r);if(a!==r&&await s(a))return a;const o=f(r);if(o!==r&&await s(o))return o;const c=f(a);return c!==r&&await s(c)?c:r}n(C,"resolveReadPathAsync");export{M as expandPath,E as expandTempDirVariable,s as pathExists,S as resolveReadPath,C as resolveReadPathAsync,y as resolveToCwd};
@@ -1,22 +1,22 @@
1
- var Y=Object.defineProperty;var s=(e,t)=>Y(e,"name",{value:t,configurable:!0});import{basename as W,dirname as G,isAbsolute as J,relative as Q,resolve as K,sep as H}from"node:path";import{Text as V}from"@earendil-works/pi-tui";import{constants as Z}from"fs";import{access as ee,readFile as te}from"fs/promises";import{Type as d}from"typebox";import{getReadmePath as ne}from"../../config.js";import{fill as I,t as O}from"../../dal/i18n.js";import{keyHint as ie}from"../../modes/interactive/components/keybinding-hints.js";import{getLanguageFromPath as oe,highlightCode as re}from"../../modes/interactive/theme/theme.js";import{processImage as se}from"../../utils/image-process.js";import{detectSupportedImageMimeTypeFromFile as ae}from"../../utils/mime.js";import{formatPathRelativeToCwdOrAbsolute as le}from"../../utils/paths.js";import{readAccessDenial as fe}from"../permissions/tool-policy.js";import{resolveReadPathAsync as de,resolveToCwd as me}from"./path-utils.js";import{getTextOutput as ce,renderToolPath as ue,replaceTabs as N,str as U}from"./render-utils.js";import{wrapToolDefinition as pe}from"./tool-definition-wrapper.js";import{DEFAULT_MAX_BYTES as T,DEFAULT_MAX_LINES as X,formatSize as A,truncateHead as ge}from"./truncate.js";const he=d.Object({path:d.String({description:"Path to the file to read (relative or absolute)"}),offset:d.Optional(d.Number({description:"Line number to start reading from (1-indexed)"})),limit:d.Optional(d.Number({description:"Maximum number of lines to read"}))}),q={snippet:"Read file contents",guidelines:["Use read to examine files instead of cat or sed."]},$e=d.Union([d.String(),d.Object({type:d.Literal("image"),data:d.String(),mimeType:d.String(),note:d.String()})]),be=new Set(["AGENTS.override.md","AGENTS.md","AGENTS.MD","CLAUDE.md","CLAUDE.MD"]),Le={readFile:s(e=>te(e),"readFile"),access:s(e=>ee(e,Z.R_OK),"access"),detectImageMimeType:ae};function k(e,t){if(e?.offset==null&&e?.limit==null)return"";const n=e.offset??1,i=e.limit!=null?n+e.limit-1:"";return t.fg("warning",`:${n}${i?`-${i}`:""}`)}s(k,"formatReadLineRange");function xe(e,t,n){const i=ue(U(e?.file_path??e?.path),t,n);return`${t.fg("toolTitle",t.bold("read"))} ${i}${k(e,t)}`}s(xe,"formatReadCall");function we(e){let t=e.length;for(;t>0&&e[t-1]==="";)t--;return e.slice(0,t)}s(we,"trimTrailingEmptyLines");function ye(e){const t=e.find(i=>i.type==="text")?.text??"",n=e.find(i=>i.type==="image");return n?{type:"image",data:n.data,mimeType:n.mimeType,note:t}:t}s(ye,"toReadOutput");function Te(e){if(!(!e||e.input.includes("image")))return"[Current model does not support images. The image will be omitted from this request.]"}s(Te,"getNonVisionImageNote");function Re(e){return e.split(H).join("/")}s(Re,"toPosixPath");function Se(e){const t=G(ne()),n=Q(K(t),K(e));if(n===""||n===".."||n.startsWith(`..${H}`)||J(n))return;const i=Re(n);if(i==="README.md"||i.startsWith("docs/")||i.startsWith("dal-docs/")||i.startsWith("examples/"))return{kind:"docs",label:i}}s(Se,"getPiDocsClassification");function Ce(e,t){const n=U(e?.file_path??e?.path);if(!n)return;const i=me(n,t),m=W(i);if(m==="SKILL.md")return{kind:"skill",label:W(G(i))||m};const c=Se(i);if(c)return c;if(be.has(m))return{kind:"resource",label:le(i,t)}}s(Ce,"getCompactReadClassification");function Ee(e,t,n){return e.kind==="skill"?n.fg("customMessageLabel","\x1B[1m[skill]\x1B[22m ")+n.fg("customMessageText",e.label)+k(t,n):n.fg("toolTitle",n.bold(`read ${e.kind}`))+" "+n.fg("accent",e.label)+k(t,n)}s(Ee,"formatCompactReadCall");function Oe(e,t,n,i,m,c,u){if(!n.expanded&&!u)return"";const f=U(e?.file_path??e?.path),a=ce(t,m),l=!u&&f?oe(f):void 0,z=l?re(N(a),l):a.split(`
2
- `),x=we(z),w=n.expanded?x.length:10,R=x.slice(0,w),b=x.length-w;let h=`
1
+ var Y=Object.defineProperty;var a=(e,t)=>Y(e,"name",{value:t,configurable:!0});import{basename as W,dirname as G,isAbsolute as J,relative as Q,resolve as K,sep as H}from"node:path";import{Text as V}from"@earendil-works/pi-tui";import{constants as Z}from"fs";import{access as ee,readFile as te}from"fs/promises";import{Type as f}from"typebox";import{getReadmePath as ne}from"../../config.js";import{fill as I,t as O}from"../../dal/i18n.js";import{keyHint as ie}from"../../modes/interactive/components/keybinding-hints.js";import{getLanguageFromPath as oe,highlightCode as re}from"../../modes/interactive/theme/theme.js";import{processImage as ae}from"../../utils/image-process.js";import{detectSupportedImageMimeTypeFromFile as se}from"../../utils/mime.js";import{formatPathRelativeToCwdOrAbsolute as le}from"../../utils/paths.js";import{readAccessDenial as de}from"../permissions/tool-policy.js";import{resolveReadPathAsync as fe,resolveToCwd as me}from"./path-utils.js";import{formatReadLineRange as ce,getTextOutput as ue,renderToolPath as pe,replaceTabs as N,str as U}from"./render-utils.js";import{wrapToolDefinition as ge}from"./tool-definition-wrapper.js";import{DEFAULT_MAX_BYTES as T,DEFAULT_MAX_LINES as X,formatSize as A,truncateHead as he}from"./truncate.js";const be=f.Object({path:f.String({description:"Path to the file to read (relative or absolute)"}),offset:f.Optional(f.Number({description:"Line number to start reading from (1-indexed)"})),limit:f.Optional(f.Number({description:"Maximum number of lines to read"}))}),q={snippet:"Read file contents",guidelines:["Use read to examine files instead of cat or sed."]},Le=f.Union([f.String(),f.Object({type:f.Literal("image"),data:f.String(),mimeType:f.String(),note:f.String()})]),xe=new Set(["AGENTS.override.md","AGENTS.md","AGENTS.MD","CLAUDE.md","CLAUDE.MD"]),we={readFile:a(e=>te(e),"readFile"),access:a(e=>ee(e,Z.R_OK),"access"),detectImageMimeType:se};function k(e,t){const n=ce(e?.offset,e?.limit);return n?t.fg("warning",n):""}a(k,"formatReadLineRange");function $e(e,t,n){const i=pe(U(e?.file_path??e?.path),t,n);return`${t.fg("toolTitle",t.bold("read"))} ${i}${k(e,t)}`}a($e,"formatReadCall");function ye(e){let t=e.length;for(;t>0&&e[t-1]==="";)t--;return e.slice(0,t)}a(ye,"trimTrailingEmptyLines");function Te(e){const t=e.find(i=>i.type==="text")?.text??"",n=e.find(i=>i.type==="image");return n?{type:"image",data:n.data,mimeType:n.mimeType,note:t}:t}a(Te,"toReadOutput");function Re(e){if(!(!e||e.input.includes("image")))return"[Current model does not support images. The image will be omitted from this request.]"}a(Re,"getNonVisionImageNote");function Se(e){return e.split(H).join("/")}a(Se,"toPosixPath");function Ce(e){const t=G(ne()),n=Q(K(t),K(e));if(n===""||n===".."||n.startsWith(`..${H}`)||J(n))return;const i=Se(n);if(i==="README.md"||i.startsWith("docs/")||i.startsWith("dal-docs/")||i.startsWith("examples/"))return{kind:"docs",label:i}}a(Ce,"getPiDocsClassification");function Ee(e,t){const n=U(e?.file_path??e?.path);if(!n)return;const i=me(n,t),m=W(i);if(m==="SKILL.md")return{kind:"skill",label:W(G(i))||m};const c=Ce(i);if(c)return c;if(xe.has(m))return{kind:"resource",label:le(i,t)}}a(Ee,"getCompactReadClassification");function Oe(e,t,n){return e.kind==="skill"?n.fg("customMessageLabel","\x1B[1m[skill]\x1B[22m ")+n.fg("customMessageText",e.label)+k(t,n):n.fg("toolTitle",n.bold(`read ${e.kind}`))+" "+n.fg("accent",e.label)+k(t,n)}a(Oe,"formatCompactReadCall");function Ae(e,t,n,i,m,c,u){if(!n.expanded&&!u)return"";const d=U(e?.file_path??e?.path),s=ue(t,m),l=!u&&d?oe(d):void 0,z=l?re(N(s),l):s.split(`
2
+ `),w=ye(z),$=n.expanded?w.length:10,R=w.slice(0,$),L=w.length-$;let h=`
3
3
  ${R.map(S=>l?N(S):i.fg("toolOutput",N(S))).join(`
4
- `)}`;b>0&&(h+=`${i.fg("muted",`
5
- ${I(O("... (\u8FD8\u6709 {count} \u884C\uFF0C"),{count:b})}`)} ${ie("app.tools.expand",O("\u5373\u53EF\u5C55\u5F00"))}${i.fg("muted",")")}`);const o=t.details?.truncation;return o?.truncated&&(o.firstLineExceedsLimit?h+=`
4
+ `)}`;L>0&&(h+=`${i.fg("muted",`
5
+ ${I(O("... (\u8FD8\u6709 {count} \u884C\uFF0C"),{count:L})}`)} ${ie("app.tools.expand",O("\u5373\u53EF\u5C55\u5F00"))}${i.fg("muted",")")}`);const o=t.details?.truncation;return o?.truncated&&(o.firstLineExceedsLimit?h+=`
6
6
  ${i.fg("warning",I(O("[\u9996\u884C\u8D85\u51FA {limit} \u4E0A\u9650]"),{limit:A(o.maxBytes??T)}))}`:o.truncatedBy==="lines"?h+=`
7
7
  ${i.fg("warning",I(O("[\u5DF2\u622A\u65AD\uFF1A\u663E\u793A {shown}/{total} \u884C\uFF08\u4E0A\u9650 {max} \u884C\uFF09]"),{shown:o.outputLines,total:o.totalLines,max:o.maxLines??X}))}`:h+=`
8
- ${i.fg("warning",I(O("[\u5DF2\u622A\u65AD\uFF1A\u663E\u793A\u4E86 {shown} \u884C\uFF08\u4E0A\u9650 {limit}\uFF09]"),{shown:o.outputLines,limit:A(o.maxBytes??T)}))}`),h}s(Oe,"formatReadResult");function Ae(e,t){const n=t?.autoResizeImages??!0,i=t?.resizeOptions,m=t?.operations??Le;return{name:"read",label:"read",description:`Read the contents of a file. Supports text files and images (jpg, png, gif, webp, bmp). Images are sent as attachments. For text files, output is truncated to ${X} lines or ${T/1024}KB (whichever is hit first). Use offset/limit for large files. When you need the full file, continue with offset until complete.`,promptSnippet:q.snippet,promptGuidelines:[...q.guidelines],parameters:he,outputSchema:$e,constrainedSampling:{type:"json_schema",strict:"prefer"},async execute(c,{path:u,offset:f,limit:a},l,z,x){return new Promise((w,R)=>{if(l?.aborted){R(new Error("Operation aborted"));return}let b=!1;const h=s(()=>{b=!0,R(new Error("Operation aborted"))},"onAbort");l?.addEventListener("abort",h,{once:!0}),(async()=>{try{const o=await de(u,x?.cwd||e);if(b)return;const S=t?.operations?void 0:fe(o);if(S)throw new Error(S);if(await m.access(o),b)return;const _=m.detectImageMimeType?await m.detectImageMimeType(o):void 0;let P,D;const M=Te(x?.model);if(_){const j=await m.readFile(o),L=await se(j,_,{autoResizeImages:n,resizeOptions:x?.model?.inputLimits?.images?.resize??i});if(L.ok){let r=`Read image file [${L.mimeType}]`;L.hints.length>0&&(r+=`
9
- ${L.hints.join(`
8
+ ${i.fg("warning",I(O("[\u5DF2\u622A\u65AD\uFF1A\u663E\u793A\u4E86 {shown} \u884C\uFF08\u4E0A\u9650 {limit}\uFF09]"),{shown:o.outputLines,limit:A(o.maxBytes??T)}))}`),h}a(Ae,"formatReadResult");function Pe(e,t){const n=t?.autoResizeImages??!0,i=t?.resizeOptions,m=t?.operations??we;return{name:"read",label:"read",description:`Read the contents of a file. Supports text files and images (jpg, png, gif, webp, bmp). Images are sent as attachments. For text files, output is truncated to ${X} lines or ${T/1024}KB (whichever is hit first). Use offset/limit for large files. When you need the full file, continue with offset until complete.`,promptSnippet:q.snippet,promptGuidelines:[...q.guidelines],parameters:be,outputSchema:Le,constrainedSampling:{type:"json_schema",strict:"prefer"},async execute(c,{path:u,offset:d,limit:s},l,z,w){return new Promise(($,R)=>{if(l?.aborted){R(new Error("Operation aborted"));return}let L=!1;const h=a(()=>{L=!0,R(new Error("Operation aborted"))},"onAbort");l?.addEventListener("abort",h,{once:!0}),(async()=>{try{const o=await fe(u,w?.cwd||e);if(L)return;const S=t?.operations?void 0:de(o);if(S)throw new Error(S);if(await m.access(o),L)return;const _=m.detectImageMimeType?await m.detectImageMimeType(o):void 0;let P,D;const M=Re(w?.model);if(_){const j=await m.readFile(o),x=await ae(j,_,{autoResizeImages:n,resizeOptions:w?.model?.inputLimits?.images?.resize??i});if(x.ok){let r=`Read image file [${x.mimeType}]`;x.hints.length>0&&(r+=`
9
+ ${x.hints.join(`
10
10
  `)}`),M&&(r+=`
11
- ${M}`),P=[{type:"text",text:r},{type:"image",data:L.data,mimeType:L.mimeType}]}else{let r=`Read image file [${_}]
12
- ${L.message}`;M&&(r+=`
11
+ ${M}`),P=[{type:"text",text:r},{type:"image",data:x.data,mimeType:x.mimeType}]}else{let r=`Read image file [${_}]
12
+ ${x.message}`;M&&(r+=`
13
13
  ${M}`),P=[{type:"text",text:r}]}}else{const r=(await m.readFile(o)).toString("utf-8").split(`
14
- `),B=r.length,p=f?Math.max(0,f-1):0,C=p+1;if(p>=r.length)throw new Error(`Offset ${f} is beyond end of file (${r.length} lines total)`);let F,E;if(a!==void 0){const g=Math.min(p+a,r.length);F=r.slice(p,g).join(`
14
+ `),B=r.length,p=d?Math.max(0,d-1):0,C=p+1;if(p>=r.length)throw new Error(`Offset ${d} is beyond end of file (${r.length} lines total)`);let F,E;if(s!==void 0){const g=Math.min(p+s,r.length);F=r.slice(p,g).join(`
15
15
  `),E=g-p}else F=r.slice(p).join(`
16
- `);const $=ge(F);let y;if($.firstLineExceedsLimit){const g=A(Buffer.byteLength(r[p],"utf-8"));y=`[Line ${C} is ${g}, exceeds ${A(T)} limit. Use bash: sed -n '${C}p' ${u} | head -c ${T}]`,D={truncation:$}}else if($.truncated){const g=C+$.outputLines-1,v=g+1;y=$.content,$.truncatedBy==="lines"?y+=`
16
+ `);const b=he(F);let y;if(b.firstLineExceedsLimit){const g=A(Buffer.byteLength(r[p],"utf-8"));y=`[Line ${C} is ${g}, exceeds ${A(T)} limit. Use bash: sed -n '${C}p' ${u} | head -c ${T}]`,D={truncation:b}}else if(b.truncated){const g=C+b.outputLines-1,v=g+1;y=b.content,b.truncatedBy==="lines"?y+=`
17
17
 
18
18
  [Showing lines ${C}-${g} of ${B}. Use offset=${v} to continue.]`:y+=`
19
19
 
20
- [Showing lines ${C}-${g} of ${B} (${A(T)} limit). Use offset=${v} to continue.]`,D={truncation:$}}else if(E!==void 0&&p+E<r.length){const g=r.length-(p+E),v=p+E+1;y=`${$.content}
20
+ [Showing lines ${C}-${g} of ${B} (${A(T)} limit). Use offset=${v} to continue.]`,D={truncation:b}}else if(E!==void 0&&p+E<r.length){const g=r.length-(p+E),v=p+E+1;y=`${b.content}
21
21
 
22
- [${g} more lines in file. Use offset=${v} to continue.]`}else y=$.content;P=[{type:"text",text:y}]}if(b)return;l?.removeEventListener("abort",h),w({content:P,details:D})}catch(o){l?.removeEventListener("abort",h),b||R(o)}})()}).then(w=>({...w,structuredContent:ye(w.content)}))},renderCall(c,u,f){const a=f.lastComponent??new V("",0,0),l=f.expanded?void 0:Ce(c,f.cwd);return a.setText(l?Ee(l,c,u):xe(c,u,f.cwd)),a},renderResult(c,u,f,a){const l=a.lastComponent??new V("",0,0);return l.setText(Oe(a.args,c,u,f,a.showImages,a.cwd,a.isError)),l}}}s(Ae,"createReadToolDefinition");function Xe(e,t){return pe(Ae(e,t))}s(Xe,"createReadTool");export{Xe as createReadTool,Ae as createReadToolDefinition,q as readToolSystemPromptContribution};
22
+ [${g} more lines in file. Use offset=${v} to continue.]`}else y=b.content;P=[{type:"text",text:y}]}if(L)return;l?.removeEventListener("abort",h),$({content:P,details:D})}catch(o){l?.removeEventListener("abort",h),L||R(o)}})()}).then($=>({...$,structuredContent:Te($.content)}))},renderCall(c,u,d){const s=d.lastComponent??new V("",0,0),l=d.expanded?void 0:Ee(c,d.cwd);return s.setText(l?Oe(l,c,u):$e(c,u,d.cwd)),s},renderResult(c,u,d,s){const l=s.lastComponent??new V("",0,0);return l.setText(Ae(s.args,c,u,d,s.showImages,s.cwd,s.isError)),l}}}a(Pe,"createReadToolDefinition");function qe(e,t){return ge(Pe(e,t))}a(qe,"createReadTool");export{qe as createReadTool,Pe as createReadToolDefinition,q as readToolSystemPromptContribution};
@@ -0,0 +1,40 @@
1
+ import type { ImageContent, TextContent } from "@earendil-works/pi-ai";
2
+ import type { Theme } from "../../modes/interactive/theme/theme.ts";
3
+ import type { ToolRenderContext } from "../extensions/types.ts";
4
+ export declare function shortenPath(path: unknown): string;
5
+ export declare function linkPath(styledText: string, rawPath: string, cwd: string): string;
6
+ export declare function str(value: unknown): string | null;
7
+ export declare function formatReadLineRange(offset: unknown, limit: unknown): string;
8
+ export declare function replaceTabs(text: string): string;
9
+ export declare function normalizeDisplayText(text: string): string;
10
+ export declare function getTextOutput(result: {
11
+ content: Array<{
12
+ type: string;
13
+ text?: string;
14
+ data?: string;
15
+ mimeType?: string;
16
+ }>;
17
+ } | undefined, showImages: boolean): string;
18
+ export type ToolRenderResultLike<TDetails> = {
19
+ content: (TextContent | ImageContent)[];
20
+ details: TDetails;
21
+ };
22
+ export declare function formatToolCallWithArgs(title: string, args: unknown, theme: Theme, expanded: boolean): string;
23
+ export declare function formatToolDuration(ms: number): string;
24
+ interface ToolTimerState {
25
+ startedAt?: number;
26
+ endedAt?: number;
27
+ interval?: ReturnType<typeof setInterval>;
28
+ }
29
+ export declare function startToolTimer(context: ToolRenderContext<ToolTimerState>): void;
30
+ export declare function toolTimerText(context: ToolRenderContext<ToolTimerState>, isPartial: boolean): string | undefined;
31
+ export declare function invalidArgText(theme: Theme): string;
32
+ export declare function countOutputLines(output: string): number;
33
+ export declare function formatCollapsedSummary(theme: Theme, parts: string[]): string;
34
+ export declare function compactToolArgHint(args: unknown, maxLength?: number): string;
35
+ export declare function prettyToolLabel(toolName: string): string;
36
+ export declare function truncateDisplay(text: string, maxLength?: number): string;
37
+ export declare function renderToolPath(rawPath: string | null, theme: Theme, cwd: string, options?: {
38
+ emptyFallback?: string;
39
+ }): string;
40
+ export {};
@@ -1,10 +1,10 @@
1
- var y=Object.defineProperty;var i=(t,n)=>y(t,"name",{value:n,configurable:!0});import*as d from"node:os";import{pathToFileURL as h}from"node:url";import{getCapabilities as a,getImageDimensions as $,hyperlink as x,imageFallback as T}from"@earendil-works/pi-tui";import{t as A}from"../../dal/i18n.js";import{stripAnsi as _}from"../../utils/ansi.js";import{resolvePath as b}from"../../utils/paths.js";import{sanitizeBinaryOutput as j}from"../../utils/shell.js";function k(t){if(typeof t!="string")return"";const n=d.homedir();return t.startsWith(n)?`~${t.slice(n.length)}`:t}i(k,"shortenPath");function O(t,n,e){if(!a().hyperlinks)return t;const o=b(n,e);return x(t,h(o).href)}i(O,"linkPath");function E(t){return typeof t=="string"?t:t==null?"":null}i(E,"str");function S(t){return t.replace(/\t/g," ")}i(S,"replaceTabs");function G(t){return t.replace(/\r/g,"")}i(G,"normalizeDisplayText");function H(t,n){if(!t)return"";const e=t.content.filter(c=>c.type==="text"),o=t.content.filter(c=>c.type==="image");let r=e.map(c=>j(_(c.text||"")).replace(/\r/g,"")).join(`
2
- `);const p=a();if(o.length>0&&(!p.images||!n)){const c=o.map(f=>{const s=f.mimeType??"image/unknown",u=f.data&&f.mimeType?$(f.data,f.mimeType)??void 0:void 0;return T(s,u)}).join(`
1
+ var h=Object.defineProperty;var o=(t,n)=>h(t,"name",{value:n,configurable:!0});import*as T from"node:os";import{pathToFileURL as A}from"node:url";import{getCapabilities as d,getImageDimensions as x,hyperlink as b,imageFallback as S}from"@earendil-works/pi-tui";import{t as a}from"../../dal/i18n.js";import{stripAnsi as _}from"../../utils/ansi.js";import{resolvePath as j}from"../../utils/paths.js";import{sanitizeBinaryOutput as k}from"../../utils/shell.js";function O(t){if(typeof t!="string")return"";const n=T.homedir();return t.startsWith(n)?`~${t.slice(n.length)}`:t}o(O,"shortenPath");function D(t,n,e){if(!d().hyperlinks)return t;const i=j(n,e);return b(t,A(i).href)}o(D,"linkPath");function W(t){return typeof t=="string"?t:t==null?"":null}o(W,"str");function m(t){return typeof t=="string"&&t.trim()!==""&&(t=Number(t)),typeof t=="number"&&Number.isFinite(t)?t:void 0}o(m,"parseLineNumber");function z(t,n){if(t==null&&n==null)return"";const e=t==null?1:m(t);if(e===void 0)return"";if(n==null)return`:${e}`;const i=m(n);if(i===void 0)return"";const r=e+i-1;return`:${e}${r?`-${r}`:""}`}o(z,"formatReadLineRange");function C(t){return t.replace(/\t/g," ")}o(C,"replaceTabs");function G(t){return t.replace(/\r/g,"")}o(G,"normalizeDisplayText");function H(t,n){if(!t)return"";const e=t.content.filter(u=>u.type==="text"),i=t.content.filter(u=>u.type==="image");let r=e.map(u=>k(_(u.text||"")).replace(/\r/g,"")).join(`
2
+ `);const c=d();if(i.length>0&&(!c.images||!n)){const u=i.map(f=>{const l=f.mimeType??"image/unknown",s=f.data&&f.mimeType?x(f.data,f.mimeType)??void 0:void 0;return S(l,s)}).join(`
3
3
  `);r=r?`${r}
4
- ${c}`:c}return r}i(H,"getTextOutput");const m=100;function I(t,n,e,o){const r=e.fg("toolTitle",e.bold(t));if(n==null)return r;const p=typeof n=="object"&&!Array.isArray(n)?Object.entries(n):[["args",n]];if(p.length===0)return r;if(o){const s=p.map(([u,l])=>{const g=typeof l=="string"?l:JSON.stringify(l,null,2)??String(l);return` ${u}: ${S(g).replace(/\r/g,"").split(`
4
+ ${u}`:u}return r}o(H,"getTextOutput");const g=100;function J(t,n,e,i){const r=e.fg("toolTitle",e.bold(t));if(n==null)return r;const c=typeof n=="object"&&!Array.isArray(n)?Object.entries(n):[["args",n]];if(c.length===0)return r;if(i){const l=c.map(([s,p])=>{const y=typeof p=="string"?p:JSON.stringify(p,null,2)??String(p);return` ${s}: ${C(y).replace(/\r/g,"").split(`
5
5
  `).join(`
6
6
  `)}`});return`${r}
7
- ${e.fg("muted",s.join(`
8
- `))}`}const c=p.map(([s,u])=>`${s}=${JSON.stringify(u)??String(u)}`).join(" "),f=c.length>m?`${c.slice(0,m-3)}...`:c;return`${r} ${e.fg("muted",f)}`}i(I,"formatToolCallWithArgs");function C(t){return t.fg("error",A("[\u53C2\u6570\u65E0\u6548]"))}i(C,"invalidArgText");function J(t){const n=t.trim();return n?n.split(`
9
- `).length:0}i(J,"countOutputLines");function q(t,n){const e=n.filter(o=>o.length>0);return e.length===0?"":`
10
- ${t.fg("muted",e.join(" \xB7 "))}`}i(q,"formatCollapsedSummary");const P=["path","file_path","filePath","command","query","pattern","description","uri","name","file","goal"];function w(t,n=48){if(!t||typeof t!="object")return"";const e=t;for(const o of P){const r=e[o];if(typeof r=="string"&&r.length>0)return r.length>n?`${r.slice(0,n-1)}\u2026`:r}return""}i(w,"compactToolArgHint");function K(t){if(!t.startsWith("mcp__"))return t;const n=t.split("__");return n.length<3?t:`${n[1]}:${n.slice(2).join("__")}`}i(K,"prettyToolLabel");function M(t,n=72){return t.length<=n?t:`${t.slice(0,n-1)}\u2026`}i(M,"truncateDisplay");function U(t,n,e,o){if(t===null)return C(n);const r=t||o?.emptyFallback;return r?O(n.fg("accent",k(r)),r,e):n.fg("toolOutput","...")}i(U,"renderToolPath");export{w as compactToolArgHint,J as countOutputLines,q as formatCollapsedSummary,I as formatToolCallWithArgs,H as getTextOutput,C as invalidArgText,O as linkPath,G as normalizeDisplayText,K as prettyToolLabel,U as renderToolPath,S as replaceTabs,k as shortenPath,E as str,M as truncateDisplay};
7
+ ${e.fg("muted",l.join(`
8
+ `))}`}const u=c.map(([l,s])=>`${l}=${JSON.stringify(s)??String(s)}`).join(" "),f=u.length>g?`${u.slice(0,g-3)}...`:u;return`${r} ${e.fg("muted",f)}`}o(J,"formatToolCallWithArgs");function $(t){const n=t/1e3;if(n<60)return`${n.toFixed(1)}s`;const e=Math.floor(n),i=Math.floor(e/60),r=e%60;return i<60?`${i}m ${r}s`:`${Math.floor(i/60)}h ${i%60}m ${r}s`}o($,"formatToolDuration");function N(t){const n=t.state;t.executionStarted&&n.startedAt===void 0&&(n.startedAt=Date.now(),n.endedAt=void 0)}o(N,"startToolTimer");function q(t,n){const e=t.state;if(e.startedAt!==void 0&&n&&!e.interval&&(e.interval=setInterval(()=>t.invalidate(),1e3)),(!n||t.isError)&&(e.endedAt??=Date.now(),e.interval&&(clearInterval(e.interval),e.interval=void 0)),!n&&t.durationMs!==void 0)return`${a("\u8017\u65F6")} ${$(t.durationMs)}`;if(e.startedAt===void 0)return;const i=e.endedAt??Date.now();return`${n?a("\u5DF2\u8FD0\u884C"):a("\u8017\u65F6")} ${$(i-e.startedAt)}`}o(q,"toolTimerText");function M(t){return t.fg("error",a("[\u53C2\u6570\u65E0\u6548]"))}o(M,"invalidArgText");function v(t){const n=t.trim();return n?n.split(`
9
+ `).length:0}o(v,"countOutputLines");function K(t,n){const e=n.filter(i=>i.length>0);return e.length===0?"":`
10
+ ${t.fg("muted",e.join(" \xB7 "))}`}o(K,"formatCollapsedSummary");const R=["path","file_path","filePath","command","query","pattern","description","uri","name","file","goal"];function U(t,n=48){if(!t||typeof t!="object")return"";const e=t;for(const i of R){const r=e[i];if(typeof r=="string"&&r.length>0)return r.length>n?`${r.slice(0,n-1)}\u2026`:r}return""}o(U,"compactToolArgHint");function Y(t){if(!t.startsWith("mcp__"))return t;const n=t.split("__");return n.length<3?t:`${n[1]}:${n.slice(2).join("__")}`}o(Y,"prettyToolLabel");function Q(t,n=72){return t.length<=n?t:`${t.slice(0,n-1)}\u2026`}o(Q,"truncateDisplay");function V(t,n,e,i){if(t===null)return M(n);const r=t||i?.emptyFallback;return r?D(n.fg("accent",O(r)),r,e):n.fg("toolOutput","...")}o(V,"renderToolPath");export{U as compactToolArgHint,v as countOutputLines,K as formatCollapsedSummary,z as formatReadLineRange,J as formatToolCallWithArgs,$ as formatToolDuration,H as getTextOutput,M as invalidArgText,D as linkPath,G as normalizeDisplayText,Y as prettyToolLabel,V as renderToolPath,C as replaceTabs,O as shortenPath,N as startToolTimer,W as str,q as toolTimerText,Q as truncateDisplay};
@@ -1,8 +1,8 @@
1
- var S=Object.defineProperty;var a=(n,i)=>S(n,"name",{value:i,configurable:!0});import{basename as E,dirname as $,isAbsolute as D,relative as M,resolve as b,sep as R}from"node:path";import{Text as A}from"@earendil-works/pi-tui";import{getReadmePath as v}from"../../../config.js";import{fill as f,t as l}from"../../../dal/i18n.js";import{keyHint as N,keyText as O}from"../../../modes/interactive/components/keybinding-hints.js";import{getLanguageFromPath as U,highlightCode as B}from"../../../modes/interactive/theme/theme.js";import{formatPathRelativeToCwdOrAbsolute as F}from"../../../utils/paths.js";import{resolveToCwd as I}from"../path-utils.js";import{getTextOutput as W,renderToolPath as G,replaceTabs as m,str as p}from"../render-utils.js";import{DEFAULT_MAX_BYTES as k,DEFAULT_MAX_LINES as j,formatSize as P}from"../truncate.js";const H=new Set(["AGENTS.override.md","AGENTS.md","AGENTS.MD","CLAUDE.md","CLAUDE.MD"]);function g(n,i){if(n?.offset==null&&n?.limit==null)return"";const e=n.offset??1,t=n.limit!=null?e+n.limit-1:"";return i.fg("warning",`:${e}${t?`-${t}`:""}`)}a(g,"formatReadLineRange");function X(n,i,e){const t=G(p(n?.file_path??n?.path),i,e);return`${i.fg("toolTitle",i.bold("read"))} ${t}${g(n,i)}`}a(X,"formatReadCall");function z(n){let i=n.length;for(;i>0&&n[i-1]==="";)i--;return n.slice(0,i)}a(z,"trimTrailingEmptyLines");function K(n){return n.split(R).join("/")}a(K,"toPosixPath");function Y(n){const i=$(v()),e=M(b(i),b(n));if(e===""||e===".."||e.startsWith(`..${R}`)||D(e))return;const t=K(e);if(t==="README.md"||t.startsWith("docs/")||t.startsWith("dal-docs/")||t.startsWith("examples/"))return{kind:"docs",label:t}}a(Y,"getPiDocsClassification");function q(n,i){const e=p(n?.file_path??n?.path);if(!e)return;const t=I(e,i),o=E(t);if(o==="SKILL.md")return{kind:"skill",label:E($(t))||o};const s=Y(t);if(s)return s;if(H.has(o))return{kind:"resource",label:F(t,i)}}a(q,"getCompactReadClassification");function J(n,i,e){const t=e.fg("dim",f(l(" ({key} \u5373\u53EF\u5C55\u5F00)"),{key:O("app.tools.expand")}));return n.kind==="skill"?e.fg("customMessageLabel","\x1B[1m[skill]\x1B[22m ")+e.fg("customMessageText",n.label)+g(i,e)+t:e.fg("toolTitle",e.bold(`read ${n.kind}`))+" "+e.fg("accent",n.label)+g(i,e)+t}a(J,"formatCompactReadCall");function Q(n,i,e,t,o,s,L){if(!e.expanded&&!L)return"";const w=p(n?.file_path??n?.path),x=W(i,o),u=!L&&w?U(w):void 0,_=u?B(m(x),u):x.split(`
2
- `),c=z(_),T=e.expanded?c.length:10,y=c.slice(0,T),h=c.length-T;let d=`
3
- ${y.map(C=>u?m(C):t.fg("toolOutput",m(C))).join(`
4
- `)}`;h>0&&(d+=`${t.fg("muted",`
5
- ${f(l("... (\u8FD8\u6709 {count} \u884C\uFF0C"),{count:h})}`)} ${N("app.tools.expand",l("\u5373\u53EF\u5C55\u5F00"))}${t.fg("muted",")")}`);const r=i.details?.truncation;return r?.truncated&&(r.firstLineExceedsLimit?d+=`
6
- ${t.fg("warning",f(l("[\u9996\u884C\u8D85\u51FA {limit} \u4E0A\u9650]"),{limit:P(r.maxBytes??k)}))}`:r.truncatedBy==="lines"?d+=`
7
- ${t.fg("warning",f(l("[\u5DF2\u622A\u65AD\uFF1A\u663E\u793A {shown}/{total} \u884C\uFF08\u4E0A\u9650 {max} \u884C\uFF09]"),{shown:r.outputLines,total:r.totalLines,max:r.maxLines??j}))}`:d+=`
8
- ${t.fg("warning",f(l("[\u5DF2\u622A\u65AD\uFF1A\u663E\u793A\u4E86 {shown} \u884C\uFF08\u4E0A\u9650 {limit}\uFF09]"),{shown:r.outputLines,limit:P(r.maxBytes??k)}))}`),d}a(Q,"formatReadResult");const dt={renderCall(n,i,e){const t=n,o=e.lastComponent??new A("",0,0),s=e.expanded?void 0:q(t,e.cwd);return o.setText(s?J(s,t,i):X(t,i,e.cwd)),o},renderResult(n,i,e,t){const o=t.lastComponent??new A("",0,0);return o.setText(Q(t.args,n,i,e,t.showImages,t.cwd,t.isError)),o}};export{dt as readRenderers};
1
+ var S=Object.defineProperty;var r=(e,i)=>S(e,"name",{value:i,configurable:!0});import{basename as E,dirname as R,isAbsolute as D,relative as M,resolve as b,sep as A}from"node:path";import{Text as k}from"@earendil-works/pi-tui";import{getReadmePath as v}from"../../../config.js";import{fill as f,t as l}from"../../../dal/i18n.js";import{keyHint as N,keyText as O}from"../../../modes/interactive/components/keybinding-hints.js";import{getLanguageFromPath as U,highlightCode as B}from"../../../modes/interactive/theme/theme.js";import{formatPathRelativeToCwdOrAbsolute as F}from"../../../utils/paths.js";import{resolveToCwd as I}from"../path-utils.js";import{formatReadLineRange as W,getTextOutput as G,renderToolPath as j,replaceTabs as m,str as p}from"../render-utils.js";import{DEFAULT_MAX_BYTES as P,DEFAULT_MAX_LINES as H,formatSize as $}from"../truncate.js";const X=new Set(["AGENTS.override.md","AGENTS.md","AGENTS.MD","CLAUDE.md","CLAUDE.MD"]);function g(e,i){const t=W(e?.offset,e?.limit);return t?i.fg("warning",t):""}r(g,"styledReadLineRange");function z(e,i,t){const n=j(p(e?.file_path??e?.path),i,t);return`${i.fg("toolTitle",i.bold("read"))} ${n}${g(e,i)}`}r(z,"formatReadCall");function K(e){let i=e.length;for(;i>0&&e[i-1]==="";)i--;return e.slice(0,i)}r(K,"trimTrailingEmptyLines");function Y(e){return e.split(A).join("/")}r(Y,"toPosixPath");function q(e){const i=R(v()),t=M(b(i),b(e));if(t===""||t===".."||t.startsWith(`..${A}`)||D(t))return;const n=Y(t);if(n==="README.md"||n.startsWith("docs/")||n.startsWith("dal-docs/")||n.startsWith("examples/"))return{kind:"docs",label:n}}r(q,"getPiDocsClassification");function J(e,i){const t=p(e?.file_path??e?.path);if(!t)return;const n=I(t,i),o=E(n);if(o==="SKILL.md")return{kind:"skill",label:E(R(n))||o};const s=q(n);if(s)return s;if(X.has(o))return{kind:"resource",label:F(n,i)}}r(J,"getCompactReadClassification");function Q(e,i,t){const n=t.fg("dim",f(l(" ({key} \u5373\u53EF\u5C55\u5F00)"),{key:O("app.tools.expand")}));return e.kind==="skill"?t.fg("customMessageLabel","\x1B[1m[skill]\x1B[22m ")+t.fg("customMessageText",e.label)+g(i,t)+n:t.fg("toolTitle",t.bold(`read ${e.kind}`))+" "+t.fg("accent",e.label)+g(i,t)+n}r(Q,"formatCompactReadCall");function V(e,i,t,n,o,s,L){if(!t.expanded&&!L)return"";const w=p(e?.file_path??e?.path),x=G(i,o),u=!L&&w?U(w):void 0,y=u?B(m(x),u):x.split(`
2
+ `),c=K(y),T=t.expanded?c.length:10,_=c.slice(0,T),h=c.length-T;let d=`
3
+ ${_.map(C=>u?m(C):n.fg("toolOutput",m(C))).join(`
4
+ `)}`;h>0&&(d+=`${n.fg("muted",`
5
+ ${f(l("... (\u8FD8\u6709 {count} \u884C\uFF0C"),{count:h})}`)} ${N("app.tools.expand",l("\u5373\u53EF\u5C55\u5F00"))}${n.fg("muted",")")}`);const a=i.details?.truncation;return a?.truncated&&(a.firstLineExceedsLimit?d+=`
6
+ ${n.fg("warning",f(l("[\u9996\u884C\u8D85\u51FA {limit} \u4E0A\u9650]"),{limit:$(a.maxBytes??P)}))}`:a.truncatedBy==="lines"?d+=`
7
+ ${n.fg("warning",f(l("[\u5DF2\u622A\u65AD\uFF1A\u663E\u793A {shown}/{total} \u884C\uFF08\u4E0A\u9650 {max} \u884C\uFF09]"),{shown:a.outputLines,total:a.totalLines,max:a.maxLines??H}))}`:d+=`
8
+ ${n.fg("warning",f(l("[\u5DF2\u622A\u65AD\uFF1A\u663E\u793A\u4E86 {shown} \u884C\uFF08\u4E0A\u9650 {limit}\uFF09]"),{shown:a.outputLines,limit:$(a.maxBytes??P)}))}`),d}r(V,"formatReadResult");const ft={renderCall(e,i,t){const n=e,o=t.lastComponent??new k("",0,0),s=t.expanded?void 0:J(n,t.cwd);return o.setText(s?Q(s,n,i):z(n,i,t.cwd)),o},renderResult(e,i,t,n){const o=n.lastComponent??new k("",0,0);return o.setText(V(n.args,e,i,t,n.showImages,n.cwd,n.isError)),o}};export{ft as readRenderers};
@@ -1,2 +1,2 @@
1
- var D=Object.defineProperty;var i=(o,t)=>D(o,"name",{value:t,configurable:!0});import{existsSync as h,mkdirSync as m,readFileSync as T}from"node:fs";import{homedir as w}from"node:os";import{dirname as l,join as c}from"node:path";import O from"proper-lockfile";import{CONFIG_DIR_NAME as k,SHARED_SKILL_CONFIG_DIRS as y}from"../config.js";import{projectFileDeclaresHooks as j,TRUST_REQUIRING_PROJECT_HOOK_FILES as R}from"../dal/hooks/config.js";import{canonicalizePath as p,resolvePath as a}from"../utils/paths.js";import{stripBom as g}from"../utils/text.js";import{writeFileAtomicSync as _}from"./shared-data.js";const v=["settings.json","mcp.json","extensions","mcp.json","lsp.json","skills","prompts","themes","SYSTEM.md","APPEND_SYSTEM.md"];function f(o){return p(a(o))}i(f,"normalizeCwd");function I(o,t){let r=f(t);for(;;){const e=o[r];if(e===!0||e===!1)return{path:r,decision:e};const s=l(r);if(s===r)return null;r=s}}i(I,"findNearestTrustEntry");function F(o){const t=f(o),r=l(t);return r===t?void 0:r}i(F,"getProjectTrustParentPath");function q(o,t){const r=f(o),e=[{label:"Trust",trusted:!0,updates:[{path:r,decision:!0}],savedPath:r}],s=F(o);return s!==void 0&&e.push({label:`Trust parent folder (${s})`,trusted:!0,updates:[{path:s,decision:!0},{path:r,decision:null}],savedPath:s}),t?.includeSessionOnly&&e.push({label:"Trust (this session only)",trusted:!0,updates:[]}),e.push({label:"Do not trust",trusted:!1,updates:[{path:r,decision:!1}],savedPath:r}),t?.includeSessionOnly&&e.push({label:"Do not trust (this session only)",trusted:!1,updates:[]}),e}i(q,"getProjectTrustOptions");function S(o){if(!h(o))return{};let t;try{t=JSON.parse(g(T(o,"utf-8")))}catch(e){const s=e instanceof Error?e.message:String(e);throw new Error(`Failed to read trust store ${o}: ${s}`)}if(typeof t!="object"||t===null||Array.isArray(t))throw new Error(`Invalid trust store ${o}: expected an object`);const r={};for(const[e,s]of Object.entries(t)){if(s!==!0&&s!==!1&&s!==null)throw new Error(`Invalid trust store ${o}: value for ${JSON.stringify(e)} must be true, false, or null`);r[e]=s}return r}i(S,"readTrustFile");function b(o,t){const r={};for(const e of Object.keys(t).sort()){const s=t[e];(s===!0||s===!1||s===null)&&(r[e]=s)}m(l(o),{recursive:!0}),_(o,`${JSON.stringify(r,null,2)}
1
+ var D=Object.defineProperty;var i=(o,t)=>D(o,"name",{value:t,configurable:!0});import{existsSync as h,mkdirSync as m,readFileSync as T}from"node:fs";import{homedir as w}from"node:os";import{dirname as l,join as c}from"node:path";import O from"proper-lockfile";import{CONFIG_DIR_NAME as k,SHARED_SKILL_CONFIG_DIRS as y}from"../config.js";import{projectFileDeclaresHooks as j,TRUST_REQUIRING_PROJECT_HOOK_FILES as R}from"../dal/hooks/config.js";import{canonicalizePath as p,resolvePath as a}from"../utils/paths.js";import{stripBom as g}from"../utils/text.js";import{writeFileAtomicSync as _}from"./shared-data.js";const v=["settings.json","mcp.json","extensions","mcp.json","lsp.json","skills","prompts","commands","themes","SYSTEM.md","APPEND_SYSTEM.md"];function f(o){return p(a(o))}i(f,"normalizeCwd");function I(o,t){let r=f(t);for(;;){const e=o[r];if(e===!0||e===!1)return{path:r,decision:e};const s=l(r);if(s===r)return null;r=s}}i(I,"findNearestTrustEntry");function F(o){const t=f(o),r=l(t);return r===t?void 0:r}i(F,"getProjectTrustParentPath");function q(o,t){const r=f(o),e=[{label:"Trust",trusted:!0,updates:[{path:r,decision:!0}],savedPath:r}],s=F(o);return s!==void 0&&e.push({label:`Trust parent folder (${s})`,trusted:!0,updates:[{path:s,decision:!0},{path:r,decision:null}],savedPath:s}),t?.includeSessionOnly&&e.push({label:"Trust (this session only)",trusted:!0,updates:[]}),e.push({label:"Do not trust",trusted:!1,updates:[{path:r,decision:!1}],savedPath:r}),t?.includeSessionOnly&&e.push({label:"Do not trust (this session only)",trusted:!1,updates:[]}),e}i(q,"getProjectTrustOptions");function S(o){if(!h(o))return{};let t;try{t=JSON.parse(g(T(o,"utf-8")))}catch(e){const s=e instanceof Error?e.message:String(e);throw new Error(`Failed to read trust store ${o}: ${s}`)}if(typeof t!="object"||t===null||Array.isArray(t))throw new Error(`Invalid trust store ${o}: expected an object`);const r={};for(const[e,s]of Object.entries(t)){if(s!==!0&&s!==!1&&s!==null)throw new Error(`Invalid trust store ${o}: value for ${JSON.stringify(e)} must be true, false, or null`);r[e]=s}return r}i(S,"readTrustFile");function b(o,t){const r={};for(const e of Object.keys(t).sort()){const s=t[e];(s===!0||s===!1||s===null)&&(r[e]=s)}m(l(o),{recursive:!0}),_(o,`${JSON.stringify(r,null,2)}
2
2
  `)}i(b,"writeTrustFile");function N(o){const t=l(o);m(t,{recursive:!0});const r=100,e=20;let s;for(let n=1;n<=r;n++)try{return O.lockSync(t,{realpath:!1,lockfilePath:`${o}.lock`})}catch(u){if((typeof u=="object"&&u!==null&&"code"in u?String(u.code):void 0)!=="ELOCKED"||n===r)throw u;s=u;const E=Date.now();for(;Date.now()-E<e;);}throw s instanceof Error?s:new Error("Failed to acquire trust store lock")}i(N,"acquireTrustLockSync");function P(o,t){const r=N(o);try{return t()}finally{r()}}i(P,"withTrustFileLock");function K(o){const t=p(a(process.env.HOME||w())),r=new Set(y.map(n=>c(t,n,"skills")));let e=p(a(o));const s=c(e,k);if(v.some(n=>h(c(s,n)))||R.some(n=>j(c(e,n))))return!0;for(;;){for(const u of y){const d=c(e,u,"skills");if(!r.has(d)&&h(d))return!0}const n=l(e);if(n===e)return!1;e=n}}i(K,"hasTrustRequiringProjectResources");class z{static{i(this,"ProjectTrustStore")}trustPath;constructor(t){this.trustPath=c(a(t),"trust.json")}get(t){return this.getEntry(t)?.decision??null}getEntry(t){return P(this.trustPath,()=>{const r=S(this.trustPath);return I(r,t)})}set(t,r){this.setMany([{path:t,decision:r}])}setMany(t){P(this.trustPath,()=>{const r=S(this.trustPath);for(const{path:e,decision:s}of t){const n=f(e);s===null?delete r[n]:r[n]=s}b(this.trustPath,r)})}}export{z as ProjectTrustStore,q as getProjectTrustOptions,F as getProjectTrustParentPath,K as hasTrustRequiringProjectResources};
@@ -1,4 +1,7 @@
1
+ export declare const WORKSPACE_LOCK_DIR_NAME = "workspace-locks";
1
2
  export declare const WORKSPACE_LOCK_FILE = "dal-workspace.lock";
3
+ export declare function defaultWorkspaceLockDir(): string;
4
+ export declare function workspaceLockPath(gitDir: string, lockDir?: string): string;
2
5
  export declare const STALE_AFTER_MS: number;
3
6
  export interface WorkspaceLock {
4
7
  pid: number;
@@ -18,12 +21,13 @@ export declare function gitDirOf(dir: string): {
18
21
  worktree?: string;
19
22
  } | undefined;
20
23
  export declare function workspaceOwnerSessionId(sessionId: string, env?: NodeJS.ProcessEnv): string;
21
- export declare function readWorkspaceLock(gitDir: string): WorkspaceLock | undefined;
24
+ export declare function readWorkspaceLock(gitDir: string, lockDir?: string): WorkspaceLock | undefined;
22
25
  export declare function workspaceLockIsLive(lock: WorkspaceLock, now?: number): boolean;
23
26
  export declare function claimWorkspace(dir: string, sessionId: string, options?: {
24
27
  now?: number;
25
28
  env?: NodeJS.ProcessEnv;
26
29
  force?: boolean;
30
+ lockDir?: string;
27
31
  }): WorkspaceClaim | undefined;
28
- export declare function releaseWorkspace(gitDir: string): void;
32
+ export declare function releaseWorkspace(gitDir: string, lockDir?: string): void;
29
33
  export declare function shellCommandDirectory(command: string, cwd: string): string;
@@ -1,3 +1,3 @@
1
- var l=Object.defineProperty;var c=(t,e)=>l(t,"name",{value:e,configurable:!0});import{execFileSync as m}from"node:child_process";import{readFileSync as k,renameSync as y,rmSync as D,writeFileSync as A}from"node:fs";import{hostname as p}from"node:os";import{isAbsolute as E,join as u,resolve as f}from"node:path";const a="dal-workspace.lock",I=7200*1e3,O=60*1e3,x="DALCODE_PARENT_SESSION_ID",w=new Map;function _(t){const e=f(t),n=w.get(e);if(n!==void 0)return n??void 0;let r=null;try{const i=m("git",["rev-parse","--git-dir","--show-toplevel"],{cwd:e,encoding:"utf8",stdio:["ignore","pipe","ignore"],timeout:3e3}).trim().split(`
2
- `),o=i[0]?.trim();o&&(r={gitDir:E(o)?o:f(e,o),worktree:i[1]?.trim()})}catch{r=null}return w.set(e,r),r??void 0}c(_,"gitDirOf");function v(t,e=process.env){return e[x]||t}c(v,"workspaceOwnerSessionId");function S(t){try{const e=JSON.parse(k(u(t,a),"utf8"));return typeof e.pid!="number"||typeof e.sessionId!="string"||typeof e.host!="string"?void 0:{pid:e.pid,host:e.host,sessionId:e.sessionId,startedAt:typeof e.startedAt=="string"?e.startedAt:new Date(0).toISOString(),refreshedAt:typeof e.refreshedAt=="string"?e.refreshedAt:new Date(0).toISOString(),...typeof e.worktree=="string"?{worktree:e.worktree}:{}}}catch{return}}c(S,"readWorkspaceLock");function L(t){try{return process.kill(t,0),!0}catch(e){return e.code==="EPERM"}}c(L,"processAlive");function g(t,e=Date.now()){const n=Date.parse(t.refreshedAt);return!Number.isFinite(n)||e-n>I?!1:t.host===p()?L(t.pid):!0}c(g,"workspaceLockIsLive");function h(t,e){const n=u(t,a),r=`${n}.${process.pid}.tmp`;A(r,`${JSON.stringify(e,null,2)}
3
- `),y(r,n)}c(h,"writeLock");function $(t,e,n={}){const r=_(t);if(!r)return;const i=n.now??Date.now(),o=v(e,n.env),s=S(r.gitDir),d={gitDir:r.gitDir,...r.worktree?{worktree:r.worktree}:{}};if(s&&s.sessionId!==o&&g(s,i)&&!n.force)return{...d,heldBy:s};if(s?.sessionId===o&&g(s,i)){if(!(s.pid===process.pid&&s.host===p())||i-Date.parse(s.refreshedAt)<O)return d;try{h(r.gitDir,{...s,refreshedAt:new Date(i).toISOString()})}catch{}return d}try{h(r.gitDir,{pid:process.pid,host:p(),sessionId:o,startedAt:new Date(i).toISOString(),refreshedAt:new Date(i).toISOString(),...r.worktree?{worktree:r.worktree}:{}})}catch{return}return d}c($,"claimWorkspace");function H(t){const e=S(t);if(!(!e||e.pid!==process.pid||e.host!==p()))try{D(u(t,a),{force:!0})}catch{}}c(H,"releaseWorkspace");function P(t,e){let n=e;for(const i of t.split(/&&|;|\n/)){const o=/^\s*cd\s+("([^"]+)"|'([^']+)'|(\S+))\s*$/.exec(i);if(!o)break;const s=(o[2]??o[3]??o[4]??"").replace(/^~(?=\/|$)/,process.env.HOME??"~");n=f(n,s)}const r=/\bgit\s+-C\s+("([^"]+)"|'([^']+)'|(\S+))/.exec(t);return r&&(n=f(n,r[2]??r[3]??r[4]??".")),n}c(P,"shellCommandDirectory");export{I as STALE_AFTER_MS,a as WORKSPACE_LOCK_FILE,$ as claimWorkspace,_ as gitDirOf,S as readWorkspaceLock,H as releaseWorkspace,P as shellCommandDirectory,g as workspaceLockIsLive,v as workspaceOwnerSessionId};
1
+ var A=Object.defineProperty;var i=(t,e)=>A(t,"name",{value:e,configurable:!0});import{execFileSync as E}from"node:child_process";import{createHash as I}from"node:crypto";import{mkdirSync as O,readFileSync as x,realpathSync as _,renameSync as L,rmSync as v,writeFileSync as R}from"node:fs";import{hostname as l}from"node:os";import{basename as h,isAbsolute as C,join as g,resolve as p}from"node:path";import{getAgentDir as N}from"../config.js";const F="workspace-locks",S="dal-workspace.lock";function P(){return g(N(),F)}i(P,"defaultWorkspaceLockDir");function w(t,e=P()){let r=p(t);try{r=_.native(r)}catch{}const o=I("sha256").update(r).digest("hex").slice(0,16),n=h(r)===".git"?h(p(r,"..")):h(r);return g(e,`${n.replace(/[^\w.-]/g,"_").slice(0,40)||"repo"}-${o}.lock`)}i(w,"workspaceLockPath");const $=7200*1e3,b=60*1e3,M="DALCODE_PARENT_SESSION_ID",k=new Map;function W(t){const e=p(t),r=k.get(e);if(r!==void 0)return r??void 0;let o=null;try{const n=E("git",["rev-parse","--git-dir","--show-toplevel"],{cwd:e,encoding:"utf8",stdio:["ignore","pipe","ignore"],timeout:3e3}).trim().split(`
2
+ `),s=n[0]?.trim();s&&(o={gitDir:C(s)?s:p(e,s),worktree:n[1]?.trim()})}catch{o=null}return k.set(e,o),o??void 0}i(W,"gitDirOf");function H(t,e=process.env){return e[M]||t}i(H,"workspaceOwnerSessionId");function f(t){try{const e=JSON.parse(x(t,"utf8"));return typeof e.pid!="number"||typeof e.sessionId!="string"||typeof e.host!="string"?void 0:{pid:e.pid,host:e.host,sessionId:e.sessionId,startedAt:typeof e.startedAt=="string"?e.startedAt:new Date(0).toISOString(),refreshedAt:typeof e.refreshedAt=="string"?e.refreshedAt:new Date(0).toISOString(),...typeof e.worktree=="string"?{worktree:e.worktree}:{}}}catch{return}}i(f,"readLockFile");function z(t,e){return f(w(t,e))??f(g(t,S))}i(z,"readWorkspaceLock");function K(t){try{return process.kill(t,0),!0}catch(e){return e.code==="EPERM"}}i(K,"processAlive");function m(t,e=Date.now()){const r=Date.parse(t.refreshedAt);return!Number.isFinite(r)||e-r>$?!1:t.host===l()?K(t.pid):!0}i(m,"workspaceLockIsLive");function y(t,e){O(p(t,".."),{recursive:!0});const r=`${t}.${process.pid}.tmp`;R(r,`${JSON.stringify(e,null,2)}
3
+ `),L(r,t)}i(y,"writeLock");function G(t,e,r={}){const o=W(t);if(!o)return;const n=r.now??Date.now(),s=H(e,r.env),a=w(o.gitDir,r.lockDir),c=f(a),u={gitDir:o.gitDir,...o.worktree?{worktree:o.worktree}:{}},D=f(g(o.gitDir,S));for(const d of[c,D])if(d&&d.sessionId!==s&&m(d,n)&&!r.force)return{...u,heldBy:d};if(c?.sessionId===s&&m(c,n)){if(!(c.pid===process.pid&&c.host===l())||n-Date.parse(c.refreshedAt)<b)return u;try{y(a,{...c,refreshedAt:new Date(n).toISOString()})}catch{}return u}try{y(a,{pid:process.pid,host:l(),sessionId:s,startedAt:new Date(n).toISOString(),refreshedAt:new Date(n).toISOString(),...o.worktree?{worktree:o.worktree}:{}})}catch{return}return u}i(G,"claimWorkspace");function Q(t,e){const r=w(t,e),o=f(r);if(!(!o||o.pid!==process.pid||o.host!==l()))try{v(r,{force:!0})}catch{}}i(Q,"releaseWorkspace");function U(t,e){let r=e;for(const n of t.split(/&&|;|\n/)){const s=/^\s*cd\s+("([^"]+)"|'([^']+)'|(\S+))\s*$/.exec(n);if(!s)break;const a=(s[2]??s[3]??s[4]??"").replace(/^~(?=\/|$)/,process.env.HOME??"~");r=p(r,a)}const o=/\bgit\s+-C\s+("([^"]+)"|'([^']+)'|(\S+))/.exec(t);return o&&(r=p(r,o[2]??o[3]??o[4]??".")),r}i(U,"shellCommandDirectory");export{$ as STALE_AFTER_MS,F as WORKSPACE_LOCK_DIR_NAME,S as WORKSPACE_LOCK_FILE,G as claimWorkspace,P as defaultWorkspaceLockDir,W as gitDirOf,z as readWorkspaceLock,Q as releaseWorkspace,U as shellCommandDirectory,m as workspaceLockIsLive,w as workspaceLockPath,H as workspaceOwnerSessionId};
@@ -1,3 +1,3 @@
1
- var p=Object.defineProperty;var t=(n,o)=>p(n,"name",{value:o,configurable:!0});import{execFileSync as a}from"node:child_process";import{readFileSync as P}from"node:fs";import{createRequire as l}from"node:module";import{dirname as f,join as u}from"node:path";import{setAmbientAuthPolicy as m,setEnvApiKeyPolicy as T}from"@earendil-works/pi-ai";import{houseProvidersEnforced as y,isProviderConfigurable as d}from"../core/house-providers.js";import{BUNDLED_EXTENSION_PACKAGES as E,SAFETY_CRITICAL_PACKAGES as S}from"./manifest.js";function C(){if(!y())return;const n=t(o=>d(o),"allowed");T(n),m(n)}t(C,"applyDalEnvApiKeyPolicy");import{BUNDLED_EXTENSION_PACKAGES as K,SAFETY_CRITICAL_PACKAGES as b}from"./manifest.js";function x(){const n=l(import.meta.url),o=[];for(const e of E)try{const r=n.resolve(`${e}/package.json`),s=JSON.parse(P(r,"utf8"));for(const c of s.pi?.extensions??[])o.push(u(f(r),c))}catch(r){S.has(e)&&process.stderr.write(`dal: \u5B89\u5168\u6269\u5C55 ${e} \u52A0\u8F7D\u5931\u8D25\uFF0C\u5371\u9669\u547D\u4EE4\u7684\u5BA1\u6279\u95E8\u5DF2\u5931\u6548 \u2014 ${r instanceof Error?r.message:String(r)}
1
+ var a=Object.defineProperty;var r=(n,e)=>a(n,"name",{value:e,configurable:!0});import{execFileSync as P}from"node:child_process";import{readFileSync as l}from"node:fs";import{createRequire as f}from"node:module";import{dirname as u,join as T}from"node:path";import{setAmbientAuthPolicy as m,setEnvApiKeyPolicy as d}from"@earendil-works/pi-ai";import{houseProvidersEnforced as E,isProviderConfigurable as y}from"../core/house-providers.js";import{BUNDLED_EXTENSION_PACKAGES as S,PROVIDER_EXTENSION_PACKAGES as x,SAFETY_CRITICAL_PACKAGES as _}from"./manifest.js";function H(){if(!E())return;const n=r(e=>y(e),"allowed");d(n),m(n)}r(H,"applyDalEnvApiKeyPolicy");import{BUNDLED_EXTENSION_PACKAGES as D,SAFETY_CRITICAL_PACKAGES as b}from"./manifest.js";function p(n=S){const e=f(import.meta.url),t=[];for(const i of n)try{const o=e.resolve(`${i}/package.json`),c=JSON.parse(l(o,"utf8"));for(const s of c.pi?.extensions??[])t.push(T(u(o),s))}catch(o){_.has(i)&&process.stderr.write(`dal: \u5B89\u5168\u6269\u5C55 ${i} \u52A0\u8F7D\u5931\u8D25\uFF0C\u5371\u9669\u547D\u4EE4\u7684\u5BA1\u6279\u95E8\u5DF2\u5931\u6548 \u2014 ${o instanceof Error?o.message:String(o)}
2
2
  \u91CD\u65B0\u5B89\u88C5\u53EF\u6062\u590D\uFF1Anpm i -g dal-code@latest
3
- `)}return o}t(x,"bundledPackageExtensionPaths");function N(){return x()}t(N,"dalBuiltinExtensionPaths");function X(){if(!(process.platform!=="darwin"||["HTTPS_PROXY","https_proxy","HTTP_PROXY","http_proxy","ALL_PROXY","all_proxy"].some(o=>process.env[o])))try{const o=a("scutil",["--proxy"],{encoding:"utf8",timeout:2e3}),e=t(i=>o.match(new RegExp(`${i}\\s*:\\s*(\\S+)`))?.[1],"get"),r=t(i=>e(`${i}Enable`)==="1","enabled"),s=r("HTTPS")?`http://${e("HTTPSProxy")}:${e("HTTPSPort")}`:r("HTTP")?`http://${e("HTTPProxy")}:${e("HTTPPort")}`:void 0;if(!s||s.includes("undefined"))return;process.env.HTTPS_PROXY=s,process.env.HTTP_PROXY=s;const c=new Set((process.env.NO_PROXY??process.env.no_proxy??"").split(",").filter(Boolean));for(const i of["localhost","127.0.0.1","::1"])c.add(i);process.env.NO_PROXY=[...c].join(",")}catch{}}t(X,"applyDalSystemProxyFallback");export{K as BUNDLED_EXTENSION_PACKAGES,b as SAFETY_CRITICAL_PACKAGES,C as applyDalEnvApiKeyPolicy,X as applyDalSystemProxyFallback,N as dalBuiltinExtensionPaths};
3
+ `)}return t}r(p,"bundledPackageExtensionPaths");function X(){return p()}r(X,"dalBuiltinExtensionPaths");function K(){return p(x)}r(K,"dalProviderExtensionPaths");function Y(){if(!(process.platform!=="darwin"||["HTTPS_PROXY","https_proxy","HTTP_PROXY","http_proxy","ALL_PROXY","all_proxy"].some(e=>process.env[e])))try{const e=P("scutil",["--proxy"],{encoding:"utf8",timeout:2e3}),t=r(s=>e.match(new RegExp(`${s}\\s*:\\s*(\\S+)`))?.[1],"get"),i=r(s=>t(`${s}Enable`)==="1","enabled"),o=i("HTTPS")?`http://${t("HTTPSProxy")}:${t("HTTPSPort")}`:i("HTTP")?`http://${t("HTTPProxy")}:${t("HTTPPort")}`:void 0;if(!o||o.includes("undefined"))return;process.env.HTTPS_PROXY=o,process.env.HTTP_PROXY=o;const c=new Set((process.env.NO_PROXY??process.env.no_proxy??"").split(",").filter(Boolean));for(const s of["localhost","127.0.0.1","::1"])c.add(s);process.env.NO_PROXY=[...c].join(",")}catch{}}r(Y,"applyDalSystemProxyFallback");export{D as BUNDLED_EXTENSION_PACKAGES,b as SAFETY_CRITICAL_PACKAGES,H as applyDalEnvApiKeyPolicy,Y as applyDalSystemProxyFallback,X as dalBuiltinExtensionPaths,K as dalProviderExtensionPaths};