dal-code 1.0.39 → 1.0.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +82 -4
- package/NOTICE +224 -0
- package/dal-docs/examples/extensions/LICENSE +21 -0
- package/dal-docs/examples/extensions/README.md +64 -0
- package/dal-docs/examples/extensions/bookmark.ts +52 -0
- package/dal-docs/examples/extensions/claude-rules.ts +88 -0
- package/dal-docs/examples/extensions/commands.ts +74 -0
- package/dal-docs/examples/extensions/custom-footer.ts +66 -0
- package/dal-docs/examples/extensions/dirty-repo-guard.ts +58 -0
- package/dal-docs/examples/extensions/dynamic-tools.ts +76 -0
- package/dal-docs/examples/extensions/hello.ts +49 -0
- package/dal-docs/examples/extensions/inline-bash.ts +96 -0
- package/dal-docs/examples/extensions/permission-gate.ts +36 -0
- package/dal-docs/examples/extensions/protected-paths.ts +32 -0
- package/dal-docs/examples/extensions/session-name.ts +29 -0
- package/dal-docs/examples/extensions/status-line.ts +34 -0
- package/dal-docs/examples/extensions/structured-output.ts +67 -0
- package/dal-docs/examples/extensions/tool-override.ts +146 -0
- package/dal-docs/examples/extensions/trigger-compact.ts +59 -0
- package/dal-docs/examples/extensions/truncated-tool.ts +197 -0
- package/dal-docs/extensions.md +27 -0
- package/dist/cli/args.d.ts +3 -0
- package/dist/cli/args.js +17 -17
- package/dist/config.d.ts +1 -0
- package/dist/config.js +1 -1
- package/dist/core/agent-session.js +6 -6
- package/dist/core/extensions/loader.js +1 -1
- package/dist/core/extensions/permission-surface.js +1 -1
- package/dist/core/extensions/runner.js +1 -1
- package/dist/core/extensions/types.d.ts +15 -1
- package/dist/core/model-registry.d.ts +1 -0
- package/dist/core/model-registry.js +1 -1
- package/dist/core/nested-tool-calls.js +2 -2
- package/dist/core/resource-loader.js +1 -1
- package/dist/core/system-prompt.js +10 -9
- package/dist/core/tools/bash.js +13 -12
- package/dist/core/tools/path-utils.d.ts +5 -0
- package/dist/core/tools/process.d.ts +2 -0
- package/dist/core/tools/process.js +14 -13
- package/dist/dal/extension-compat.d.ts +62 -0
- package/dist/dal/extension-compat.js +4 -0
- package/dist/dal/hooks/extension.js +2 -2
- package/dist/dal/i18n.js +1 -1
- package/dist/dal/manifest.js +1 -1
- package/dist/dal/reviewed/endorsed-cli.js +1 -1
- package/dist/dal/reviewed/endorsed.js +1 -1
- package/dist/dal/reviewed/market-keys.js +1 -0
- package/dist/dal/reviewed/market.d.ts +64 -0
- package/dist/dal/reviewed/market.js +2 -0
- package/dist/extensions/mcp/runtime.d.ts +2 -1
- package/dist/extensions/mcp/runtime.js +3 -3
- package/dist/extensions/mcp/runtime.lazy.d.ts +1 -0
- package/dist/index.d.ts +7 -1
- package/dist/index.js +1 -1
- package/dist/main.js +4 -4
- package/dist/modes/acp/acp-mode.js +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +1 -0
- package/dist/modes/interactive/interactive-mode.js +14 -14
- package/dist/modes/print-mode.js +3 -3
- package/dist/modes/rpc/rpc-mode.js +1 -1
- package/dist/node_modules/@dalcode/dal-advisor/LICENSE +45 -0
- package/dist/node_modules/@dalcode/dal-advisor/package.json +35 -0
- package/dist/node_modules/@dalcode/dal-advisor/src/index.js +22 -0
- package/dist/node_modules/@dalcode/dal-bridge/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-bridge/src/ask-user.js +1 -1
- package/dist/node_modules/@dalcode/dal-capabilities/LICENSE +21 -0
- package/dist/node_modules/@dalcode/dal-capabilities/package.json +38 -0
- package/dist/node_modules/@dalcode/dal-capabilities/src/catalogue.js +1 -0
- package/dist/node_modules/@dalcode/dal-capabilities/src/index.js +11 -0
- package/dist/node_modules/@dalcode/dal-capabilities/src/install.js +4 -0
- package/dist/node_modules/@dalcode/dal-capabilities/src/match.js +1 -0
- package/dist/node_modules/@dalcode/dal-capabilities/src/state.js +3 -0
- package/dist/node_modules/@dalcode/dal-compat/LICENSE +21 -0
- package/dist/node_modules/@dalcode/dal-compat/package.json +32 -0
- package/dist/node_modules/@dalcode/dal-compat/src/claude-rules.js +3 -0
- package/dist/node_modules/@dalcode/dal-compat/src/index.js +7 -0
- package/dist/node_modules/@dalcode/dal-dap/LICENSE +47 -0
- package/dist/node_modules/@dalcode/dal-dap/package.json +38 -0
- package/dist/node_modules/@dalcode/dal-dap/src/adapters.js +1 -0
- package/dist/node_modules/@dalcode/dal-dap/src/client.js +5 -0
- package/dist/node_modules/@dalcode/dal-dap/src/index.js +9 -0
- package/dist/node_modules/@dalcode/dal-dap/src/install.js +2 -0
- package/dist/node_modules/@dalcode/dal-dap/src/session.js +2 -0
- package/dist/node_modules/@dalcode/dal-dap/src/types.js +0 -0
- package/dist/node_modules/@dalcode/dal-gateway/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-goal/package.json +4 -3
- package/dist/node_modules/@dalcode/dal-goal/src/core.js +6 -6
- package/dist/node_modules/@dalcode/dal-goal/src/index.js +17 -7
- package/dist/node_modules/@dalcode/dal-goal/src/verify.js +26 -0
- package/dist/node_modules/@dalcode/dal-guard/package.json +6 -4
- package/dist/node_modules/@dalcode/dal-guard/src/credentials.js +1 -1
- package/dist/node_modules/@dalcode/dal-guard/src/edit-anchor-core.js +23 -0
- package/dist/node_modules/@dalcode/dal-guard/src/edit-anchor.js +4 -0
- package/dist/node_modules/@dalcode/dal-guard/src/index.js +1 -1
- package/dist/node_modules/@dalcode/dal-guard/src/workspace.js +2 -2
- package/dist/node_modules/@dalcode/dal-halo/package.json +1 -1
- package/dist/node_modules/@dalcode/dal-interactive/LICENSE +209 -0
- package/dist/node_modules/@dalcode/dal-interactive/package.json +4 -3
- package/dist/node_modules/@dalcode/dal-interactive/src/btw.js +25 -0
- package/dist/node_modules/@dalcode/dal-interactive/src/index.js +1 -1
- package/dist/node_modules/@dalcode/dal-lang/package.json +3 -3
- package/dist/node_modules/@dalcode/dal-learn/LICENSE +21 -0
- package/dist/node_modules/@dalcode/dal-learn/package.json +35 -0
- package/dist/node_modules/@dalcode/dal-learn/src/engine.js +8 -0
- package/dist/node_modules/@dalcode/dal-learn/src/extract.js +14 -0
- package/dist/node_modules/@dalcode/dal-learn/src/index.js +17 -0
- package/dist/node_modules/@dalcode/dal-learn/src/lessons.js +3 -0
- package/dist/node_modules/@dalcode/dal-learn/src/migrate.js +1 -0
- package/dist/node_modules/@dalcode/dal-learn/src/procedures.js +11 -0
- package/dist/node_modules/@dalcode/dal-learn/src/project-map.js +2 -0
- package/dist/node_modules/@dalcode/dal-learn/src/project.js +1 -0
- package/dist/node_modules/@dalcode/dal-learn/src/safety.js +2 -0
- package/dist/node_modules/@dalcode/dal-learn/src/signals.js +5 -0
- package/dist/node_modules/@dalcode/dal-learn/src/skill-actions.js +1 -0
- package/dist/node_modules/@dalcode/dal-learn/src/skill-evolution.js +16 -0
- package/dist/node_modules/@dalcode/dal-learn/src/store.js +2 -0
- package/dist/node_modules/@dalcode/dal-lsp/package.json +6 -4
- package/dist/node_modules/@dalcode/dal-lsp/src/client.js +3 -3
- package/dist/node_modules/@dalcode/dal-lsp/src/config.js +1 -1
- package/dist/node_modules/@dalcode/dal-lsp/src/format.js +8 -7
- package/dist/node_modules/@dalcode/dal-lsp/src/index.js +11 -8
- package/dist/node_modules/@dalcode/dal-mcp/package.json +6 -5
- package/dist/node_modules/@dalcode/dal-mcp/src/config.d.ts +1 -0
- package/dist/node_modules/@dalcode/dal-mcp/src/config.js +1 -1
- package/dist/node_modules/@dalcode/dal-mcp/src/http-client.d.ts +32 -1
- package/dist/node_modules/@dalcode/dal-mcp/src/http-client.js +2 -1
- package/dist/node_modules/@dalcode/dal-mcp/src/index.js +16 -16
- package/dist/node_modules/@dalcode/dal-mcp/src/oauth.js +2 -0
- package/dist/node_modules/@dalcode/dal-mcp/src/stdio-client.d.ts +4 -2
- package/dist/node_modules/@dalcode/dal-mcp/src/stdio-client.js +4 -4
- package/dist/node_modules/@dalcode/dal-mcp/src/types.d.ts +9 -0
- package/dist/node_modules/@dalcode/dal-mcp/src/types.js +1 -1
- package/dist/node_modules/@dalcode/dal-office/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-office/src/index.d.ts +6 -3
- package/dist/node_modules/@dalcode/dal-office/src/index.js +1 -1
- package/dist/node_modules/@dalcode/dal-office/src/render/chart-theme.d.ts +13 -0
- package/dist/node_modules/@dalcode/dal-office/src/render/chart-theme.js +1 -0
- package/dist/node_modules/@dalcode/dal-office/src/render/chart.d.ts +16 -0
- package/dist/node_modules/@dalcode/dal-office/src/render/chart.js +4 -2
- package/dist/node_modules/@dalcode/dal-office/src/render/docx.d.ts +4 -1
- package/dist/node_modules/@dalcode/dal-office/src/render/docx.js +1 -1
- package/dist/node_modules/@dalcode/dal-office/src/render/drawio-style.d.ts +4 -0
- package/dist/node_modules/@dalcode/dal-office/src/render/drawio-style.js +1 -0
- package/dist/node_modules/@dalcode/dal-office/src/render/pptx.d.ts +52 -4
- package/dist/node_modules/@dalcode/dal-office/src/render/pptx.js +3 -2
- package/dist/node_modules/@dalcode/dal-office/src/render/thumbnails.d.ts +1 -1
- package/dist/node_modules/@dalcode/dal-office/src/render/thumbnails.js +1 -1
- package/dist/node_modules/@dalcode/dal-office/src/render/xlsx.d.ts +1 -0
- package/dist/node_modules/@dalcode/dal-office/src/render/xlsx.js +1 -1
- package/dist/node_modules/@dalcode/dal-office/src/scratchpad.d.ts +30 -1
- package/dist/node_modules/@dalcode/dal-office/src/scratchpad.js +1 -1
- package/dist/node_modules/@dalcode/dal-office/src/themes.d.ts +35 -1
- package/dist/node_modules/@dalcode/dal-office/src/themes.js +1 -1
- package/dist/node_modules/@dalcode/dal-office/src/tools/chart-generate.js +3 -3
- package/dist/node_modules/@dalcode/dal-office/src/tools/doc-generate.js +2 -2
- package/dist/node_modules/@dalcode/dal-office/src/tools/drawio-generate.js +3 -3
- package/dist/node_modules/@dalcode/dal-office/src/tools/ppt-generate.js +2 -2
- package/dist/node_modules/@dalcode/dal-office/src/tools/ppt-plan.js +2 -2
- package/dist/node_modules/@dalcode/dal-office/src/tools/sheet-generate.js +2 -2
- package/dist/node_modules/@dalcode/dal-pi-kit/dist/i18n.js +4 -4
- package/dist/node_modules/@dalcode/dal-pi-kit/package.json +1 -1
- package/dist/node_modules/@dalcode/dal-pi-kit/src/i18n.js +4 -4
- package/dist/node_modules/@dalcode/dal-plugins/package.json +4 -5
- package/dist/node_modules/@dalcode/dal-plugins/src/index.js +11 -11
- package/dist/node_modules/@dalcode/dal-plugins/src/manage.js +8 -10
- package/dist/node_modules/@dalcode/dal-plugins/src/npm-hook.js +1 -1
- package/dist/node_modules/@dalcode/dal-plugins/src/registry.js +2 -2
- package/dist/node_modules/@dalcode/dal-recall/LICENSE +45 -0
- package/dist/node_modules/@dalcode/dal-recall/package.json +34 -0
- package/dist/node_modules/@dalcode/dal-recall/src/index-db.js +57 -0
- package/dist/node_modules/@dalcode/dal-recall/src/index.js +1 -0
- package/dist/node_modules/@dalcode/dal-recall/src/query.js +1 -0
- package/dist/node_modules/@dalcode/dal-recall/src/redact.js +1 -0
- package/dist/node_modules/@dalcode/dal-recall/src/sqlite.js +1 -0
- package/dist/node_modules/@dalcode/dal-review/package.json +3 -3
- package/dist/node_modules/@dalcode/dal-rewind/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-rewind/src/commands.js +2 -2
- package/dist/node_modules/@dalcode/dal-rewind/src/core.d.ts +21 -8
- package/dist/node_modules/@dalcode/dal-rewind/src/core.js +8 -3
- package/dist/node_modules/@dalcode/dal-rewind/src/index.js +1 -1
- package/dist/node_modules/@dalcode/dal-rewind/src/state.js +1 -1
- package/dist/node_modules/@dalcode/dal-router/package.json +6 -5
- package/dist/node_modules/@dalcode/dal-router/src/advisor.js +1 -0
- package/dist/node_modules/@dalcode/dal-router/src/assist.js +4 -2
- package/dist/node_modules/@dalcode/dal-router/src/commands.js +8 -8
- package/dist/node_modules/@dalcode/dal-router/src/config.d.ts +3 -0
- package/dist/node_modules/@dalcode/dal-router/src/config.js +2 -2
- package/dist/node_modules/@dalcode/dal-router/src/index.js +4 -4
- package/dist/node_modules/@dalcode/dal-router/src/jev.d.ts +2 -1
- package/dist/node_modules/@dalcode/dal-router/src/jev.js +4 -4
- package/dist/node_modules/@dalcode/dal-router/src/services.js +1 -1
- package/dist/node_modules/@dalcode/dal-router/src/subagent.js +1 -1
- package/dist/node_modules/@dalcode/dal-skills/package.json +4 -3
- package/dist/node_modules/@dalcode/dal-skills/src/bundled/browser-qa/SKILL.md +48 -0
- package/dist/node_modules/@dalcode/dal-skills/src/bundled/diagram-design/SKILL.md +81 -0
- package/dist/node_modules/@dalcode/dal-skills/src/bundled/poster-design/SKILL.md +50 -0
- package/dist/node_modules/@dalcode/dal-skills/src/bundled/print-design/SKILL.md +55 -0
- package/dist/node_modules/@dalcode/dal-skills/src/bundled/visual-kit/dashboard.html +177 -0
- package/dist/node_modules/@dalcode/dal-skills/src/bundled/visual-kit/diagram.html +39 -0
- package/dist/node_modules/@dalcode/dal-skills/src/bundled/visual-kit/echarts-dal.json +360 -0
- package/dist/node_modules/@dalcode/dal-skills/src/bundled/visual-kit/email/notice.html +46 -0
- package/dist/node_modules/@dalcode/dal-skills/src/bundled/visual-kit/landing.html +173 -0
- package/dist/node_modules/@dalcode/dal-skills/src/bundled/visual-kit/mermaid-dal.json +140 -0
- package/dist/node_modules/@dalcode/dal-skills/src/bundled/visual-kit/mindmap.html +65 -0
- package/dist/node_modules/@dalcode/dal-skills/src/bundled/visual-kit/posters/event-poster.html +40 -0
- package/dist/node_modules/@dalcode/dal-skills/src/bundled/visual-kit/posters/poster.css +41 -0
- package/dist/node_modules/@dalcode/dal-skills/src/bundled/visual-kit/posters/square-card.html +25 -0
- package/dist/node_modules/@dalcode/dal-skills/src/bundled/visual-kit/posters/wechat-cover.html +29 -0
- package/dist/node_modules/@dalcode/dal-skills/src/bundled/visual-kit/posters/xhs-card.html +35 -0
- package/dist/node_modules/@dalcode/dal-skills/src/bundled/visual-kit/posters/xhs-cover.html +26 -0
- package/dist/node_modules/@dalcode/dal-skills/src/bundled/visual-kit/print/letter.html +35 -0
- package/dist/node_modules/@dalcode/dal-skills/src/bundled/visual-kit/print/print.css +65 -0
- package/dist/node_modules/@dalcode/dal-skills/src/bundled/visual-kit/print/report.html +76 -0
- package/dist/node_modules/@dalcode/dal-skills/src/bundled/visual-kit/print/resume.html +72 -0
- package/dist/node_modules/@dalcode/dal-skills/src/bundled/visual-kit/render.mjs +18 -0
- package/dist/node_modules/@dalcode/dal-skills/src/bundled/visual-kit/tokens.css +264 -0
- package/dist/node_modules/@dalcode/dal-skills/src/bundled/web-design/SKILL.md +73 -0
- package/dist/node_modules/@dalcode/dal-skills/src/bundled.js +1 -0
- package/dist/node_modules/@dalcode/dal-skills/src/catalog.js +2 -2
- package/dist/node_modules/@dalcode/dal-skills/src/index.js +16 -11
- package/dist/node_modules/@dalcode/dal-statusline/LICENSE +21 -0
- package/dist/node_modules/@dalcode/dal-statusline/package.json +31 -0
- package/dist/node_modules/@dalcode/dal-statusline/src/index.js +3 -0
- package/dist/node_modules/@dalcode/dal-structured/LICENSE +21 -0
- package/dist/node_modules/@dalcode/dal-structured/package.json +32 -0
- package/dist/node_modules/@dalcode/dal-structured/src/index.js +9 -0
- package/dist/node_modules/@dalcode/dal-subagent/LICENSE +24 -0
- package/dist/node_modules/@dalcode/dal-subagent/package.json +7 -6
- package/dist/node_modules/@dalcode/dal-subagent/src/background.js +13 -0
- package/dist/node_modules/@dalcode/dal-subagent/src/index.js +22 -14
- package/dist/node_modules/@dalcode/dal-subagent/src/inproc-runner.js +3 -0
- package/dist/node_modules/@dalcode/dal-subagent/src/pool.js +1 -0
- package/dist/node_modules/@dalcode/dal-subagent/src/process-runner.js +3 -3
- package/dist/node_modules/@dalcode/dal-subagent/src/tmux-runner.js +3 -0
- package/dist/node_modules/@dalcode/dal-subagent/src/worktree.js +2 -0
- package/dist/node_modules/@dalcode/dal-telemetry/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-terminal/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-tool-catalog/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-tool-catalog/src/groups.js +1 -1
- package/dist/node_modules/@dalcode/dal-tool-catalog/src/index.js +4 -4
- package/dist/node_modules/@dalcode/dal-tool-catalog/src/repair-hook.js +1 -0
- package/dist/node_modules/@dalcode/dal-tool-catalog/src/repair.js +4 -0
- package/dist/node_modules/@dalcode/dal-usage/LICENSE +45 -0
- package/dist/node_modules/@dalcode/dal-usage/package.json +33 -0
- package/dist/node_modules/@dalcode/dal-usage/src/budget.d.ts +14 -0
- package/dist/node_modules/@dalcode/dal-usage/src/budget.js +3 -0
- package/dist/node_modules/@dalcode/dal-usage/src/data.d.ts +30 -0
- package/dist/node_modules/@dalcode/dal-usage/src/data.js +1 -0
- package/dist/node_modules/@dalcode/dal-usage/src/index.d.ts +12 -0
- package/dist/node_modules/@dalcode/dal-usage/src/index.js +2 -0
- package/dist/node_modules/@dalcode/dal-usage/src/report.d.ts +29 -0
- package/dist/node_modules/@dalcode/dal-usage/src/report.js +3 -0
- package/dist/node_modules/@dalcode/dal-web/package.json +6 -4
- package/dist/node_modules/@dalcode/dal-web/src/fetch.js +11 -5
- package/dist/node_modules/@dalcode/dal-web/src/index.js +2 -2
- package/dist/node_modules/@dalcode/dal-web/src/pdf.js +5 -0
- package/dist/node_modules/@dalcode/dal-workflow/LICENSE +24 -0
- package/dist/node_modules/@dalcode/dal-workflow/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-workflow/src/announce-check.js +1 -0
- package/dist/node_modules/@dalcode/dal-workflow/src/check-in.js +1 -1
- package/dist/node_modules/@dalcode/dal-workflow/src/completion-check.js +2 -2
- package/dist/node_modules/@dalcode/dal-workflow/src/index.js +4 -4
- package/dist/node_modules/@dalcode/dal-workflow/src/lean-code.js +1 -0
- package/dist/node_modules/@dalcode/dal-workflow/src/ledger.js +3 -3
- package/dist/node_modules/@dalcode/dal-workflow/src/loop-guard.js +3 -0
- package/dist/node_modules/@dalcode/dal-workflow/src/shared.js +2 -2
- package/dist/node_modules/@dalcode/dal-workflow/src/todo.js +4 -2
- package/dist/node_modules/@dalcode/dal-workflow/src/verify-check.js +2 -0
- package/dist/node_modules/@dalcode/deepailab/package.json +3 -3
- package/dist/node_modules/@earendil-works/chord/package.json +1 -1
- package/dist/node_modules/@earendil-works/pi-agent-core/package.json +2 -2
- package/dist/node_modules/@earendil-works/pi-ai/dist/cli.js +0 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/.manifest.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/opencode.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/openrouter.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/radius.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/vercel-ai-gateway.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/package.json +2 -2
- package/dist/node_modules/@earendil-works/pi-client/package.json +3 -3
- package/dist/node_modules/@earendil-works/pi-codemode/package.json +1 -1
- package/dist/node_modules/@earendil-works/pi-coding-agent/package.json +1 -1
- package/dist/node_modules/@earendil-works/pi-mcp/package.json +1 -1
- package/dist/node_modules/@earendil-works/pi-protocol/package.json +2 -2
- package/dist/node_modules/@earendil-works/pi-server/package.json +3 -3
- package/dist/node_modules/@earendil-works/pi-telemetry/package.json +1 -1
- package/dist/node_modules/@earendil-works/pi-tui/package.json +1 -1
- package/dist/package-manager-cli.js +61 -61
- package/dist/sdk/office.d.ts +1 -1
- package/dist/sdk/office.js +1 -1
- package/dist/sdk/rewind.d.ts +1 -1
- package/dist/sdk/rewind.js +1 -1
- package/dist/sdk/usage.d.ts +8 -0
- package/dist/sdk/usage.js +1 -0
- package/dist/utils/open-browser.d.ts +1 -0
- package/dist/utils/tools-manager.js +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/gondolin/package-lock.json +2 -2
- package/examples/extensions/gondolin/package.json +1 -1
- package/examples/extensions/sandbox/package-lock.json +2 -2
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/npm-shrinkwrap.json +57 -14
- package/package.json +9 -2
- package/dist/node_modules/@dalcode/dal-plugins/src/compat.js +0 -2
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
var U=Object.defineProperty;var u=(e,n)=>U(e,"name",{value:n,configurable:!0});var $=Object.defineProperty,g=u((e,n)=>$(e,"name",{value:n,configurable:!0}),"g");import{normalizeForFuzzyMatch as T}from"@earendil-works/pi-coding-agent";function p(e){return(e.startsWith("\uFEFF")?e.slice(1):e).replace(/\r\n/g,`
|
|
2
|
+
`).replace(/\r/g,`
|
|
3
|
+
`)}u(p,"m"),g(p,"toLF");function x(e,n){if(n.length===0)return 0;const r=e.split(n).length-1;if(r>0)return r;const t=T(n);return t.length===0?0:T(e).split(t).length-1}u(x,"x"),g(x,"countMatches");function v(e,n){if(x(e,n)!==1)return;let r=e,t=n,o=r.indexOf(t);if(o===-1&&(r=T(e),t=T(n),o=r.indexOf(t),o===-1))return;const i=M(r,0,o),l=i+M(t,0,t.length)-(t.endsWith(`
|
|
4
|
+
`)?1:0),f=e.split(`
|
|
5
|
+
`);return{first:i,last:l,text:f.slice(i,l+1).join(`
|
|
6
|
+
`)}}u(v,"w"),g(v,"matchedLines");function M(e,n,r){let t=0;for(let o=n;o<r;o++)e.charCodeAt(o)===10&&t++;return t}u(M,"k"),g(M,"countNewlines");function b(e,n){if(e===n)return;const r=e.split(`
|
|
7
|
+
`),t=n.split(`
|
|
8
|
+
`);let o=0;for(;o<r.length&&o<t.length&&r[o]===t[o];)o++;let i=0;for(;i<r.length-o&&i<t.length-o&&r[r.length-1-i]===t[t.length-1-i];)i++;return{from:o+1,to:Math.max(o+1,t.length-i)}}u(b,"A"),g(b,"changedRange");function y(e,n,r){const t=e.split(`
|
|
9
|
+
`),o=Math.max(1,n),i=Math.min(t.length,r),l=String(i).length,f=[];for(let a=o;a<=i;a++)f.push(`${String(a).padStart(l," ")}| ${t[a-1]}`);return f.join(`
|
|
10
|
+
`)}u(y,"L"),g(y,"numberedLines");const z=3,C=40;function F(e,n,r){if(e===n)return{kind:"ok"};for(let o=0;o<r.length;o++){const i=p(r[o].oldText),l=v(e,i);if(!l)continue;const f=x(n,i),a=f===1?v(n,i):void 0;if(a&&a.text===l.text&&W(e,l,n,a))continue;const m=f===0?"gone":f>1?"ambiguous":a&&a.text===l.text?"moved":"changed",c=a?{from:a.first+1,to:a.last+1}:N(e,n,l.first,l.last),s=Math.max(1,c.from-z),h=Math.min(c.to+z,s+C-1);return{kind:"stale",editIndex:o,reason:m,occurrences:f,from:s,to:h}}const t=b(e,n);return t?{kind:"changed-elsewhere",...t}:{kind:"ok"}}u(F,"B"),g(F,"checkAgainstSnapshot");function W(e,n,r,t){const o=e.split(`
|
|
11
|
+
`),i=r.split(`
|
|
12
|
+
`);return o[n.first-1]===i[t.first-1]&&o[n.last+1]===i[t.last+1]}u(W,"M"),g(W,"sameNeighbours");function N(e,n,r,t){const o=e.split(`
|
|
13
|
+
`),i=n.split(`
|
|
14
|
+
`);let l=0;for(;l<o.length&&l<i.length&&o[l]===i[l];)l++;let f=0;for(;f<o.length-l&&f<i.length-l&&o[o.length-1-f]===i[i.length-1-f];)f++;const a=o.length-f,m=i.length-o.length;return t<l?{from:r+1,to:t+1}:r>=a?{from:r+1+m,to:t+1+m}:{from:l+1,to:Math.max(l+1,i.length-f)}}u(N,"v"),g(N,"mapRegion");const I=/\n{1,2}\[(?:Showing lines \d+-\d+ of \d+(?: \([^)\]]*\))?\. Use offset=\d+ to continue\.|\d+ more lines in file\. Use offset=\d+ to continue\.)\]\s*$/;function S(e){const n=I.exec(e);return n?e.slice(0,n.index):void 0}u(S,"S"),g(S,"stripReadNotice");function w(e){return/^[ \t]*/.exec(e)?.[0]??""}u(w,"y"),g(w,"leadingWhitespace");function R(e,n){const r=p(n.oldText).split(`
|
|
15
|
+
`);if(r.length>1&&r[r.length-1]===""&&r.pop(),r.every(s=>s.trim()===""))return;const t=e.split(`
|
|
16
|
+
`),o=r.map(s=>s.trim());let i=-1;for(let s=0;s+r.length<=t.length;s++){let h=!0;for(let d=0;d<r.length&&h;d++)h=t[s+d].trim()===o[d];if(h){if(i!==-1)return;i=s}}if(i===-1)return;let l;for(let s=0;s<r.length;s++){if(o[s]==="")continue;const h=w(t[i+s]),d=w(r[s]);let k;if(h.endsWith(d))k={add:h.slice(0,h.length-d.length)};else if(d.endsWith(h))k={remove:d.slice(0,d.length-h.length)};else return;if(!l)l=k;else if(JSON.stringify(l)!==JSON.stringify(k))return}if(!l)return;const f=t.slice(i,i+r.length).join(`
|
|
17
|
+
`),a=p(n.oldText).endsWith(`
|
|
18
|
+
`),m=p(n.newText).split(`
|
|
19
|
+
`),c=m.map((s,h)=>s.trim()===""||h===m.length-1&&s===""?s:"add"in l?l.add+s:s.startsWith(l.remove)?s.slice(l.remove.length):s);return{oldText:f+(a?`
|
|
20
|
+
`:""),newText:c.join(`
|
|
21
|
+
`)}}u(R,"O"),g(R,"indentationRepair");function O(e,n){if(x(e,p(n.oldText))>0)return;const r=S(p(n.oldText));if(r!==void 0&&r.length>0&&x(e,r)===1)return{edit:{oldText:r,newText:S(p(n.newText))??n.newText},kind:"read-notice"};const t=R(e,n);if(t&&x(e,t.oldText)===1)return{edit:t,kind:"indentation"}}u(O,"C"),g(O,"repairEdit");function L(e){const n=e.replace(/\s+/g," ").trim(),r=new Set;for(let t=0;t<n.length-1;t++)r.add(n.slice(t,t+2));return r}u(L,"E"),g(L,"bigrams");function j(e,n){if(e===n)return 1;const r=L(e),t=L(n);if(r.size===0||t.size===0)return 0;let o=0;for(const i of r)t.has(i)&&o++;return 2*o/(r.size+t.size)}u(j,"R"),g(j,"similarity");const J=4e5;function A(e,n,r=2){const t=p(n).split(`
|
|
22
|
+
`).map(c=>c.trim());for(;t.length>1&&t[t.length-1]==="";)t.pop();const o=e.split(`
|
|
23
|
+
`).map(c=>c.trim()),i=Math.min(t.length,o.length);if(i===0||t.every(c=>c===""))return[];const l=o.length*i<=J,f=g((c,s)=>s===""?0:c===s?1:l?j(c,s):0,"lineScore"),a=[];for(let c=0;c+i<=o.length;c++){let s=0;for(let h=0;h<i;h++)s+=f(o[c+h],t[h]);a.push({start:c,score:s/i})}a.sort((c,s)=>s.score-c.score||c.start-s.start);const m=[];for(const c of a){if(m.length>=r||c.score<.4)break;const s=c.start+1,h=c.start+i;m.some(d=>s<=d.to&&h>=d.from)||m.push({from:s,to:h,score:c.score})}return m}u(A,"F"),g(A,"nearestRegions");function E(e,n,r=5){let t=e,o=n;t.includes(o)||(t=T(e),o=T(n));const i=[];if(o.length===0)return i;let l=0;for(;i.length<r;){const f=t.indexOf(o,l);if(f===-1)break;i.push(M(t,0,f)+1),l=f+o.length}return i}u(E,"U"),g(E,"occurrenceLines");export{b as changedRange,F as checkAgainstSnapshot,x as countMatches,R as indentationRepair,v as matchedLines,A as nearestRegions,y as numberedLines,E as occurrenceLines,O as repairEdit,S as stripReadNotice,p as toLF};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
var I=Object.defineProperty;var r=(t,u)=>I(t,"name",{value:u,configurable:!0});var M=Object.defineProperty,a=r((t,u)=>M(t,"name",{value:u,configurable:!0}),"u");import{readFileSync as _,statSync as R}from"node:fs";import{basename as L}from"node:path";import{tm as E}from"@dalcode/dal-pi-kit";import{resolveToCwd as m}from"@earendil-works/pi-coding-agent";import{checkAgainstSnapshot as z,countMatches as O,nearestRegions as P,numberedLines as b,occurrenceLines as $,repairEdit as H,stripReadNotice as U,toLF as g}from"./edit-anchor-core.js";const q=2*1024*1024,X=64;function l(t,u){return t.replace(/\{(\w+)\}/g,(o,e)=>e in u?String(u[e]):o)}r(l,"l"),a(l,"fill");function p(t){try{const u=R(t);return!u.isFile()||u.size>q?void 0:g(_(t,"utf8"))}catch{return}}r(p,"w"),a(p,"readText");function A(t){return(typeof t.path=="string"?t.path:typeof t.file_path=="string"?t.file_path:void 0)?.trim()||void 0}r(A,"A"),a(A,"inputPath");function x(t){const u=t.edits;if(!Array.isArray(u))return;const o=u.filter(e=>!!e&&typeof e.oldText=="string"&&typeof e.newText=="string");return o.length===u.length?o:void 0}r(x,"S"),a(x,"editsOf");function v(){return{snapshots:new Map,notes:new Map}}r(v,"U"),a(v,"createEditAnchorState");function w(t,u,o){if(t.snapshots.delete(u),o!==void 0)for(t.snapshots.set(u,o);t.snapshots.size>X;){const e=t.snapshots.keys().next().value;if(e===void 0)break;t.snapshots.delete(e)}}r(w,"N"),a(w,"remember");function k(t,u,o,e){const i=u>1?`edits[${o.editIndex}]`:"oldText",s=o.reason==="gone"?E("\u5B83\u8981\u66FF\u6362\u7684\u5185\u5BB9\u5DF2\u7ECF\u4E0D\u5728\u6587\u4EF6\u91CC\u4E86"):o.reason==="ambiguous"?l(E("\u5B83\u73B0\u5728\u5728\u6587\u4EF6\u91CC\u51FA\u73B0\u4E86 {n} \u5904"),{n:o.occurrences}):o.reason==="moved"?E("\u5B83\u524D\u540E\u7684\u4EE3\u7801\u53D8\u4E86\uFF0C\u73B0\u5728\u5339\u914D\u5230\u7684\u53EF\u80FD\u5DF2\u7ECF\u4E0D\u662F\u4F60\u770B\u5230\u7684\u90A3\u4E00\u5904"):E("\u5B83\u6240\u5728\u7684\u884C\u5DF2\u7ECF\u88AB\u6539\u8FC7");return[l(E("\u7F16\u8F91\u672A\u6267\u884C\uFF1A{path} \u5728\u4F60\u4E0A\u6B21\u8BFB\u53D6\u4E4B\u540E\u88AB\u6539\u52A8\u8FC7\uFF08\u683C\u5F0F\u5316\u3001\u811A\u672C\u6216\u5176\u4ED6\u8FDB\u7A0B\uFF09\uFF0C{which} \u7684\u951A\u70B9\u5DF2\u8FC7\u671F\uFF1A{why}\u3002\u4E3A\u4E86\u4E0D\u6539\u9519\u5730\u65B9\uFF0C\u8FD9\u6B21\u4EC0\u4E48\u90FD\u6CA1\u5199\u3002\u4E0B\u9762\u662F\u8BE5\u4F4D\u7F6E\u73B0\u5728\u7684\u5185\u5BB9\uFF08\u7B2C {from}-{to} \u884C\uFF09\uFF0C\u8BF7\u6309\u5B83\u91CD\u5199 oldText\uFF1B\u9700\u8981\u66F4\u591A\u4E0A\u4E0B\u6587\u5C31\u91CD\u65B0 read \u8FD9\u4E2A\u6587\u4EF6\u3002"),{path:t,which:i,why:s,from:o.from,to:o.to}),"",b(e,o.from,o.to)].join(`
|
|
2
|
+
`)}r(k,"z"),a(k,"staleMessage");function y(t,u,o){const e=u.input;if(u.toolName==="bash"||u.toolName==="powershell"){const n=typeof e.command=="string"?e.command:"";for(const f of[...t.snapshots.keys()])n.includes(L(f))&&t.snapshots.delete(f);return}if(u.toolName==="write"){const n=A(e),f=typeof e.content=="string"?e.content:void 0;if(!n||f===void 0)return;const D=U(g(f));if(D===void 0)return;const h=p(m(n,o));return h===void 0||h.length<=D.length?void 0:{block:!0,reason:l(E("\u5199\u5165\u672A\u6267\u884C\uFF1A\u5185\u5BB9\u7ED3\u5C3E\u662F\u8BFB\u53D6\u5DE5\u5177\u7684\u622A\u65AD\u63D0\u793A\uFF08\u201CUse offset=\u2026 to continue\u201D\uFF09\uFF0C\u8BF4\u660E\u4F60\u53EA\u770B\u5230\u4E86 {path} \u7684\u4E00\u90E8\u5206\uFF0C\u800C\u73B0\u6709\u6587\u4EF6\u66F4\u957F\uFF1B\u8FD9\u6837\u5199\u4F1A\u628A\u6CA1\u770B\u5230\u7684\u90E8\u5206\u5220\u6389\u3002\u53EA\u6539\u5176\u4E2D\u4E00\u5904\u8BF7\u7528 edit\uFF1B\u786E\u5B9E\u8981\u6574\u4F53\u91CD\u5199\uFF0C\u5148\u8BFB\u5B8C\u6574\u4E2A\u6587\u4EF6\uFF0C\u5E76\u53BB\u6389\u8FD9\u884C\u63D0\u793A\u3002"),{path:n})}}if(u.toolName!=="edit")return;const i=A(e),s=x(e);if(!i||!s||s.length===0)return;const c=m(i,o),F=p(c);if(F===void 0)return;const B=t.snapshots.get(c);if(B!==void 0){const n=z(B,F,s);if(n.kind==="stale")return w(t,c,F),{block:!0,reason:k(i,s.length,n,F)};n.kind==="changed-elsewhere"&&T(t,u.toolCallId,l(E("\u6CE8\u610F\uFF1A{path} \u5728\u4F60\u4E0A\u6B21\u8BFB\u53D6\u4E4B\u540E\u6709\u522B\u5904\u88AB\u6539\u52A8\uFF08\u7B2C {from}-{to} \u884C\uFF09\uFF0C\u4F60\u7684\u4FEE\u6539\u5DF2\u6309\u539F\u610F\u5E94\u7528\uFF1B\u8981\u7528\u5230\u90A3\u51E0\u884C\u8BF7\u5148\u91CD\u65B0\u8BFB\u53D6\u3002"),{path:i,from:n.from,to:n.to}))}let d=!1;const C=s.map((n,f)=>{const D=H(F,n);if(!D)return n;d=!0;const h=s.length>1?`edits[${f}]`:"oldText";return T(t,u.toolCallId,D.kind==="read-notice"?l(E("\u5DF2\u81EA\u52A8\u4FEE\u6B63\uFF1A{which} \u7ED3\u5C3E\u5E26\u4E86\u8BFB\u53D6\u5DE5\u5177\u7684\u622A\u65AD\u63D0\u793A\uFF08\u4E0D\u662F\u6587\u4EF6\u5185\u5BB9\uFF09\uFF0C\u5DF2\u53BB\u6389\u540E\u518D\u5339\u914D\u3002"),{which:h}):l(E("\u5DF2\u81EA\u52A8\u4FEE\u6B63\uFF1A{which} \u7684\u7F29\u8FDB\u548C\u6587\u4EF6\u4E0D\u4E00\u81F4\uFF0C\u5DF2\u6309\u6587\u4EF6\u7684\u5B9E\u9645\u7F29\u8FDB\u5339\u914D\uFF0C\u5E76\u5BF9 newText \u505A\u4E86\u540C\u6837\u7684\u7F29\u8FDB\u8C03\u6574\uFF1B\u8BF7\u68C0\u67E5\u7ED3\u679C\u3002"),{which:h})),D.edit});d&&(e.edits=C)}r(y,"D"),a(y,"onToolCall");function T(t,u,o){const e=t.notes.get(u)??[];e.push(o),t.notes.set(u,e)}r(T,"k"),a(T,"addNote");const Y=/Could not find (?:the exact text|edits\[(\d+)\])/,G=/Found (\d+) occurrences of (?:the text|edits\[(\d+)\])/;function S(t,u,o,e){const i=Y.exec(t);if(i){const c=i[1]?Number(i[1]):0,F=u[c];if(!F)return;const B=P(o,F.oldText);if(B.length===0)return l(E("{path} \u91CC\u6CA1\u6709\u4E0E oldText \u76F8\u8FD1\u7684\u5185\u5BB9\u3002\u6587\u4EF6\u53EF\u80FD\u5DF2\u7ECF\u6539\u8FC7\uFF0C\u6216\u8005\u8DEF\u5F84\u4E0D\u5BF9\uFF1A\u8BF7\u91CD\u65B0 read \u540E\u518D\u7F16\u8F91\u3002"),{path:e});const d=[l(E("{path} \u91CC\u4E0E oldText \u6700\u63A5\u8FD1\u7684\u4F4D\u7F6E\u5982\u4E0B\uFF08\u884C\u53F7| \u5185\u5BB9\uFF09\u3002\u7167\u8FD9\u4E9B\u884C\u7684\u539F\u6587\u91CD\u5199 oldText\uFF1B\u90FD\u4E0D\u5BF9\u5C31\u91CD\u65B0 read\u3002"),{path:e})];for(const C of B)d.push("",b(o,C.from-1,C.to+1));return d.join(`
|
|
3
|
+
`)}const s=G.exec(t);if(s){const c=s[2]?Number(s[2]):0,F=u[c];if(!F)return;const B=$(o,g(F.oldText));return B.length===0?void 0:l(E("\u8FD9\u4E9B\u51FA\u73B0\u4F4D\u7F6E\u5728\u7B2C {lines} \u884C\u3002\u628A\u8981\u6539\u7684\u90A3\u4E00\u5904\u524D\u540E\u591A\u5E26\u4E00\u4E24\u884C\uFF0C\u8BA9 oldText \u53EA\u5339\u914D\u4E00\u5904\u3002"),{lines:B.join(", ")})}}r(S,"B"),a(S,"failureHelp");function N(t,u,o){const e=u.input,i=t.notes.get(u.toolCallId);if(t.notes.delete(u.toolCallId),u.toolName!=="read"&&u.toolName!=="write"&&u.toolName!=="edit")return;const s=A(e);if(!s)return;const c=m(s,o);if(u.isError){if(u.toolName!=="edit")return;const F=x(e),B=p(c),d=u.content.map(n=>n.type==="text"?n.text:"").join(`
|
|
4
|
+
`),C=F&&B!==void 0?S(d,F,B,s):void 0;return C?{content:[...u.content,{type:"text",text:C}]}:void 0}if(!(u.toolName==="read"&&u.content.some(F=>F.type==="image"))&&(w(t,c,p(c)),!!i?.length))return{content:[...u.content,...i.map(F=>({type:"text",text:F}))]}}r(N,"Y"),a(N,"onToolResult");function j(t){const u=v();t.on("session_start",()=>{u.snapshots.clear(),u.notes.clear()}),t.on("tool_call",(o,e)=>y(u,o,e.cwd)),t.on("tool_result",(o,e)=>N(u,o,e.cwd))}r(j,"q"),a(j,"editAnchor");export{O as countMatches,v as createEditAnchorState,j as default,y as onToolCall,N as onToolResult};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var J=Object.defineProperty;var l=(u,a)=>J(u,"name",{value:a,configurable:!0});var K=Object.defineProperty,n=l((u,a)=>K(u,"name",{value:a,configurable:!0}),"l");import{realpathSync as O}from"node:fs";import{basename as Q,dirname as X,isAbsolute as N,join as Y,relative as Z,resolve as b,sep as uu}from"node:path";import{readBridgeConfig as C}from"@dalcode/dal-bridge/client";import{getOwnTty as eu,requestHaloApproval as au}from"@dalcode/dal-halo";import{hasChosenLanguage as ou,t as e}from"@dalcode/dal-pi-kit";import{DAL_HOOK_NOTIFICATION_CHANNEL as tu,getAgentDir as D,registerSandboxEscalationHandler as su}from"@earendil-works/pi-coding-agent";import{DAL_CO_AUTHOR as P,foreignAttributionInMessageFile as ru,rewriteCommitAttribution as iu}from"./attribution.js";import{credentialBlockReason as nu,namesDalCredential as lu,readsDalSecretCopy as du,redactContent as Fu,secretCopyBlockReason as cu}from"./credentials.js";import{exportGuardMode as Eu,saveGuardMode as T,shouldAskGuardMode as Au,startupGuardMode as mu}from"./mode.js";import{wrongPackageManager as fu}from"./package-manager.js";import{reviewBashCommand as Cu}from"./review.js";import{createWorkspaceGate as Du}from"./workspace.js";import{DAL_CO_AUTHOR as pu,foreignAttributionInMessageFile as Bu,foreignCoAuthors as gu,isGitCommit as hu,rewriteCommitAttribution as bu}from"./attribution.js";import{dalSecretValues as yu,fileHoldsDalSecret as wu,namesDalCredential as vu,REDACTED as $u,readsDalSecretCopy as ku,redactContent as _u,redactDalSecrets as Mu,shellPathCandidates as Iu}from"./credentials.js";import{GUARD_MODE_ENV as Su,savedGuardMode as Gu,saveGuardMode as Ou,shouldAskGuardMode as Nu,startupGuardMode as Pu}from"./mode.js";import{installingManager as Tu,wrongPackageManager as Uu}from"./package-manager.js";import{reviewBashCommand as Ru,suspicionFor as xu}from"./review.js";import{createWorkspaceGate as Lu,modifiedDirectory as ju}from"./workspace.js";const U=new Set;function R(u,a){if(u.toolName!=="bash"&&u.toolName!=="powershell")return;const s=u.input;if(typeof s.command!="string")return;const r=ru(s.command,a);if(r)return{block:!0,reason:e("dal-guard\uFF1A\u63D0\u4EA4\u8BF4\u660E\u6587\u4EF6 {file} \u628A\u53E6\u4E00\u4E2A\u4EA7\u54C1\u7684\u52A9\u624B\uFF08Claude\u3001Codex\u3001Copilot \u7B49\uFF09\u5199\u6210\u4E86\u5171\u540C\u4F5C\u8005\u3002\u4F60\u662F DAL Code\uFF1A\u628A\u90A3\u884C\u6539\u6210 {trailer} \u6216\u5220\u6389\uFF0C\u518D\u63D0\u4EA4\u3002").replace("{file}",r).replace("{trailer}",P)};const o=iu(s.command);o!==void 0&&(s.command=o,U.add(u.toolCallId))}l(R,"le"),n(R,"checkCommitAttribution");function y(u){try{return O(u)}catch{try{return Y(O(X(u)),Q(u))}catch{return u}}}l(y,"N"),n(y,"realPathBestEffort");const E=n(u=>a=>u.test(a),"has"),Hu=[{id:"sudo",label:e("\u7279\u6743\u6267\u884C\uFF08sudo/doas\uFF09"),test:E(/(^|[;&|\n]\s*)(sudo|doas)\s/)},{id:"force-push",label:e("\u5F3A\u5236\u63A8\u9001\u5C06\u6539\u5199\u8FDC\u7A0B\u5386\u53F2"),test:E(/git\s+push\b[^;&|]*(--force\b|--force-with-lease\b|\s-f\b)/)},{id:"hard-reset",label:e("\u786C\u91CD\u7F6E\u4F1A\u4E22\u5F03\u672C\u5730\u6539\u52A8"),test:E(/git\s+reset\b[^;&|]*--hard/)},{id:"git-clean",label:e("git clean \u4F1A\u5220\u9664\u672A\u8DDF\u8E2A\u6587\u4EF6"),test:E(/git\s+clean\b[^;&|]*(-[a-z]*f|--force)/)},{id:"pipe-to-shell",label:e("\u5C06\u4E0B\u8F7D\u5185\u5BB9\u76F4\u63A5\u7BA1\u9053\u6267\u884C"),test:E(/(curl|wget)\b[^;&|]*\|\s*(ba|z|da|fi)?sh\b/)},{id:"exec-download",label:e("\u6267\u884C\u4E0B\u8F7D\u7684\u811A\u672C"),test:E(/\b(ba|z|da|fi)?sh\s+<\(\s*(curl|wget)\b|eval\b[^;&|\n]*\$\(\s*(curl|wget)\b/)},{id:"recursive-perms",label:e("\u9012\u5F52\u4FEE\u6539\u6743\u9650/\u5C5E\u4E3B"),test:E(/(chmod|chown)\b[^;&|]*-[a-zA-Z]*R/)},{id:"publish",label:e("\u53D1\u5E03\u8F6F\u4EF6\u5305"),test:E(/(npm|pnpm|yarn)\s+publish\b/)},{id:"kill",label:e("\u6309\u540D\u79F0\u7ED3\u675F\u8FDB\u7A0B"),test:E(/(^|[;&|\n]\s*)(killall|pkill)\s/)},{id:"disk",label:e("\u5E95\u5C42\u78C1\u76D8\u64CD\u4F5C"),test:E(/(^|[;&|\n]\s*)(dd|mkfs\w*|diskutil|fdisk)\s/)}];function w(u){return Hu.find(a=>a.test(u))}l(w,"ue"),n(w,"riskForBash");function v(u,a){const s=y(N(u)?b(u):b(a,u)),r=y(b(a)),o=Z(r,s);return o===".."||o.startsWith(`..${uu}`)||N(o)}l(v,"ce"),n(v,"pathOutsideProject");function $(u,a){if(u.toolName.startsWith("mcp__")){const s=u.toolName.split("__")[1]||"unknown",r=JSON.stringify(u.input??{});return{ruleId:`mcp:${s}`,title:`${e("\u7B2C\u4E09\u65B9 MCP \u5DE5\u5177\u8C03\u7528\uFF08")}${s}${e("\uFF09")}`,detail:`${u.toolName} ${r.length>200?`${r.slice(0,200)}\u2026`:r}`}}if(u.toolName==="bash"){const s=String(u.input.command??""),r=w(s);return r?{ruleId:`bash:${r.id}`,title:r.label,detail:s}:void 0}if(u.toolName==="edit"||u.toolName==="write"){const s=String(u.input.path??u.input.file_path??"");if(s&&v(s,a))return{ruleId:`${u.toolName}:outside-project`,title:e("\u9879\u76EE\u76EE\u5F55\u4E4B\u5916\u7684\u6587\u4EF6\u6539\u52A8"),detail:s}}}l($,"fe"),n($,"classify");async function x(u,a){if(u.toolName!=="bash")return;const s=String(u.input.command??""),r=await Cu(s,a);if(r)return{ruleId:`bash:jev-${r.suspicion.id}`,title:`${e("jev \u590D\u6838\u5224\u5B9A\u53EF\u7591")} (${Math.round(r.confidence*100)}%)`,detail:s}}l(x,"me"),n(x,"secondOpinion");const zu=n(()=>e("\u4EC5\u672C\u6B21\u5141\u8BB8"),"allowOnce"),Wu=n(()=>e("\u672C\u6B21\u4F1A\u8BDD\u5185\u5141\u8BB8\uFF08\u540C\u7C7B\u64CD\u4F5C\uFF09"),"allowSession"),Vu=n(()=>e("\u62D2\u7EDD"),"deny"),L=Symbol.for("dalcode.guard.state"),j=globalThis;j[L]??={mode:"default",sessionAllows:new Set};const d=j[L];function p(u){d.mode=u,Eu(u)}l(p,"A"),n(p,"setGuardMode");function H(){d.escalationApprover||(d.escalationApprover=su(()=>{if(!(d.mode!=="yolo"||C(process.env)))return{approved:!0,scope:"once"}}))}l(H,"be"),n(H,"registerEscalationApprover");const B=d.sessionAllows;async function k(u,a,s,r,o,t=process.env,i){if(lu(u,a))return{block:!0,reason:nu()};const F=du(u,a);if(F)return{block:!0,reason:cu(F)};const c=R(u,a);if(c)return c;const m=fu(u,a);if(m)return{block:!0,reason:m};if(d.mode==="yolo"||C(t))return;const A=$(u,a)??await x(u,a);if(!A||B.has(A.ruleId))return;if(!s||!r)return{block:!0,reason:`${e('dal-guard\uFF1A"')}${A.title}${e('"\u9700\u8981\u4EA4\u4E92\u5F0F\u5BA1\u6279\uFF08')}${A.detail}${e("\uFF09\u3002\u8BF7\u5728\u4EA4\u4E92\u6A21\u5F0F\u4E0B\u91CD\u8BD5\uFF0C\u6216\u7528 /guard yolo \u5173\u95ED\u5BA1\u6279\u95E8\u3002")}`};const g=o?au({session_id:o.sessionId,cwd:a,event:"PermissionRequest",status:"waiting_for_approval",pid:process.pid,tty:eu(),tool:u.toolName,tool_input:{command:A.detail},tool_use_id:u.toolCallId,productName:"dal"}):void 0;i?.({type:"permission_prompt",message:`DAL needs your permission to use ${u.toolName}`});const _=new AbortController,[h,M,I]=[zu(),Wu(),Vu()],V=r.select(`${e("\u9700\u8981\u5BA1\u6279\uFF1A")}${A.title} \u2014 ${A.detail}`,[h,M,I],{signal:_.signal}).then(f=>({surface:"terminal",choice:f})),q=g?g.decision.then(f=>f===void 0?new Promise(()=>{}):{surface:"halo",choice:f==="allow"?h:I}):new Promise(()=>{}),S=await Promise.race([V,q]);S.surface==="halo"?_.abort():g?.cancel();const G=S.choice;if(G!==h){if(G===M){B.add(A.ruleId);return}return{block:!0,reason:`${e("dal-guard\uFF1A\u7528\u6237\u5DF2\u62D2\u7EDD\uFF08")}${A.title}${e("\uFF09\u3002")}`}}}l(k,"ye"),n(k,"evaluateToolCall");async function z(u){const a=e("\u5168\u81EA\u52A8\uFF1A\u4E0D\u518D\u8BE2\u95EE\uFF0C\u53EA\u62E6\u622A\u7834\u574F\u6027\u547D\u4EE4\uFF08\u63A8\u8350\u719F\u6089\u7684\u7528\u6237\uFF09"),s=e("\u6BCF\u6B21\u8BE2\u95EE\uFF1A\u9AD8\u98CE\u9669\u64CD\u4F5C\u548C\u8D8A\u51FA\u6C99\u7BB1\u524D\u5148\u95EE\u6211"),r=await u.ui.select(e("\u9009\u62E9 dal \u7684\u5DE5\u4F5C\u65B9\u5F0F\uFF08\u4EE5\u540E\u53EF\u7528 /guard \u4FEE\u6539\uFF09"),[a,s]);if(r===void 0)return;const o=r===a?"yolo":"default";p(o);try{T(D(),o)}catch(t){u.ui.notify(`${e("\u4FDD\u5B58\u5931\u8D25\uFF1A")}${t instanceof Error?t.message:String(t)}`,"error");return}u.ui.notify(o==="yolo"?e("\u5DF2\u8BBE\u4E3A\u5168\u81EA\u52A8\u3002\u6539\u56DE\u6BCF\u6B21\u8BE2\u95EE\uFF1A/guard default save"):e("\u5DF2\u8BBE\u4E3A\u6BCF\u6B21\u8BE2\u95EE\u3002\u6539\u6210\u5168\u81EA\u52A8\uFF1A/guard yolo save"),"info")}l(z,"Ce"),n(z,"askGuardModeOnce");function W(u){u.registerFlag("yolo",{description:e("\u4EE5\u5168\u81EA\u52A8\u6A21\u5F0F\u542F\u52A8\uFF1A\u4E0D\u518D\u5F39\u51FA\u4EFB\u4F55\u5BA1\u6279\uFF08\u542B\u6C99\u7BB1\u8D8A\u6743\uFF09\uFF0C\u53EA\u62E6\u622A\u7834\u574F\u6027\u547D\u4EE4\u548C\u767B\u5F55\u51ED\u636E"),type:"boolean",default:!1}),H();let a="default";u.on("session_start",async(o,t)=>{if(a="default",d.started)return;d.started=!0;const i=u.getFlag("yolo")===!0;p(mu(D(),i)),o.reason==="startup"&&Au({agentDir:D(),mode:t.mode,hasUI:t.hasUI,flag:i,underDalCode:!!C(process.env),languageChosen:ou()})&&await z(t)}),u.on("before_agent_start",async()=>{if(!(d.mode===a||C(process.env)))return a=d.mode,{message:{customType:"dal-guard-mode",content:d.mode==="yolo"?e("[\u5168\u81EA\u52A8\u6A21\u5F0F] \u7528\u6237\u5F00\u542F\u4E86\u5168\u81EA\u52A8\uFF1A\u6240\u6709\u5BA1\u6279\uFF08\u5305\u62EC sandbox_escalation \u8D8A\u6743\uFF09\u90FD\u4F1A\u81EA\u52A8\u901A\u8FC7\uFF0C\u4E0D\u4F1A\u6709\u4EBA\u6765\u786E\u8BA4\u3002\u547D\u4EE4\u88AB\u6C99\u7BB1\u6321\u4F4F\u3001\u800C\u4EFB\u52A1\u786E\u5B9E\u9700\u8981\u65F6\uFF0C\u76F4\u63A5\u5E26 sandbox_escalation \u91CD\u8BD5\uFF0C\u4E0D\u8981\u505C\u4E0B\u6765\u95EE\u7528\u6237\u8981\u4E0D\u8981\u653E\u884C\u3002\u7834\u574F\u6027\u547D\u4EE4\u548C\u767B\u5F55\u51ED\u636E\u4ECD\u4F1A\u88AB\u62E6\u622A\u3002"):e("[\u5BA1\u6279\u5DF2\u6062\u590D] \u5168\u81EA\u52A8\u5DF2\u5173\u95ED\uFF1A\u8D8A\u6743\u548C\u9AD8\u98CE\u9669\u547D\u4EE4\u4F1A\u5148\u8BE2\u95EE\u7528\u6237\u3002"),display:!1}}});const s=Du(),r=new Map;u.on("tool_call",async(o,t)=>{const i=await k(o,t.cwd,t.hasUI,t.ui,{sessionId:t.sessionManager.getSessionId()},process.env,c=>u.events.emit(tu,c));if(i?.block)return i;const F=await s.check(o,t.cwd,t.sessionManager.getSessionId(),{hasUI:t.hasUI,confirm:t.hasUI?(c,m)=>t.ui.confirm(c,m):void 0});return F?.block?{block:!0,reason:F.reason}:(F?.note&&r.set(o.toolCallId,F.note),i)}),u.on("session_shutdown",async()=>{s.releaseAll()}),u.on("tool_result",async o=>{const t=Fu(o.content),i=[];U.delete(o.toolCallId)&&i.push(e("[dal-guard] \u63D0\u4EA4\u91CC\u53E6\u4E00\u4E2A\u4EA7\u54C1\u52A9\u624B\u7684\u5171\u540C\u4F5C\u8005\u884C\u5DF2\u6539\u4E3A {trailer}\uFF1A\u4F60\u662F DAL Code\u3002").replace("{trailer}",P));const F=r.get(o.toolCallId);return F&&(r.delete(o.toolCallId),i.push(`[dal-guard] ${F}`)),i.length===0?t?{content:t}:void 0:{content:[...t??o.content,...i.map(c=>({type:"text",text:c}))]}}),u.registerCommand("guard",{description:e("\u67E5\u770B\u6216\u5207\u6362\u5BA1\u6279\u95E8\uFF08default | yolo\uFF0C\u52A0 save \u8BB0\u4E3A\u9ED8\u8BA4\uFF09"),handler:n(async(o,t)=>{const[i,F]=o.trim().split(/\s+/);if((i==="yolo"||i==="default")&&(p(i),F==="save"))try{T(D(),i),t.ui.notify(i==="yolo"?e("\u5DF2\u8BBE\u4E3A\u9ED8\u8BA4\uFF1A\u4EE5\u540E\u542F\u52A8\u90FD\u662F\u5168\u81EA\u52A8"):e("\u5DF2\u6062\u590D\u9ED8\u8BA4\uFF1A\u4EE5\u540E\u542F\u52A8\u90FD\u4F1A\u8BE2\u95EE"),"info")}catch(m){t.ui.notify(`${e("\u4FDD\u5B58\u5931\u8D25\uFF1A")}${m instanceof Error?m.message:String(m)}`,"error")}const c=B.size?`${e(" \xB7 \u672C\u6B21\u4F1A\u8BDD\u5DF2\u5141\u8BB8\uFF1A")}${[...B].join(", ")}`:"";t.ui.notify(`${e("dal-guard \u6A21\u5F0F\uFF1A")}${d.mode}${c}`,d.mode==="yolo"?"warning":"info")},"handler")})}l(W,"we"),n(W,"default");export{pu as DAL_CO_AUTHOR,Su as GUARD_MODE_ENV,$u as REDACTED,$ as classify,Lu as createWorkspaceGate,yu as dalSecretValues,W as default,k as evaluateToolCall,wu as fileHoldsDalSecret,Bu as foreignAttributionInMessageFile,gu as foreignCoAuthors,Tu as installingManager,hu as isGitCommit,ju as modifiedDirectory,vu as namesDalCredential,v as pathOutsideProject,ku as readsDalSecretCopy,_u as redactContent,Mu as redactDalSecrets,Ru as reviewBashCommand,bu as rewriteCommitAttribution,w as riskForBash,Ou as saveGuardMode,Gu as savedGuardMode,Iu as shellPathCandidates,Nu as shouldAskGuardMode,Pu as startupGuardMode,xu as suspicionFor,Uu as wrongPackageManager};
|
|
1
|
+
var V=Object.defineProperty;var l=(u,a)=>V(u,"name",{value:a,configurable:!0});var q=Object.defineProperty,n=l((u,a)=>q(u,"name",{value:a,configurable:!0}),"l");import{realpathSync as G}from"node:fs";import{basename as J,dirname as K,isAbsolute as Z,join as X,relative as Y,resolve as Q,sep as uu}from"node:path";import{readBridgeConfig as C}from"@dalcode/dal-bridge/client";import{getOwnTty as eu,requestHaloApproval as au}from"@dalcode/dal-halo";import{hasChosenLanguage as ou,t as e}from"@dalcode/dal-pi-kit";import{DAL_HOOK_NOTIFICATION_CHANNEL as tu,getAgentDir as D,registerSandboxEscalationHandler as su,resolveToCwd as ru}from"@earendil-works/pi-coding-agent";import{DAL_CO_AUTHOR as O,foreignAttributionInMessageFile as iu,rewriteCommitAttribution as nu}from"./attribution.js";import{credentialBlockReason as lu,namesDalCredential as du,readsDalSecretCopy as Fu,redactContent as cu,secretCopyBlockReason as Eu}from"./credentials.js";import{exportGuardMode as Au,saveGuardMode as N,shouldAskGuardMode as mu,startupGuardMode as fu}from"./mode.js";import{wrongPackageManager as Cu}from"./package-manager.js";import{reviewBashCommand as Du}from"./review.js";import{createWorkspaceGate as pu}from"./workspace.js";import{DAL_CO_AUTHOR as Bu,foreignAttributionInMessageFile as gu,foreignCoAuthors as hu,isGitCommit as bu,rewriteCommitAttribution as yu}from"./attribution.js";import{dalSecretValues as wu,fileHoldsDalSecret as vu,namesDalCredential as $u,REDACTED as ku,readsDalSecretCopy as _u,redactContent as Mu,redactDalSecrets as Iu,shellPathCandidates as Su}from"./credentials.js";import{GUARD_MODE_ENV as Gu,savedGuardMode as Ou,saveGuardMode as Nu,shouldAskGuardMode as Pu,startupGuardMode as Tu}from"./mode.js";import{installingManager as Uu,wrongPackageManager as Ru}from"./package-manager.js";import{reviewBashCommand as xu,suspicionFor as Hu}from"./review.js";import{createWorkspaceGate as Lu,modifiedDirectory as ju}from"./workspace.js";const P=new Set;function T(u,a){if(u.toolName!=="bash"&&u.toolName!=="powershell")return;const s=u.input;if(typeof s.command!="string")return;const r=iu(s.command,a);if(r)return{block:!0,reason:e("dal-guard\uFF1A\u63D0\u4EA4\u8BF4\u660E\u6587\u4EF6 {file} \u628A\u53E6\u4E00\u4E2A\u4EA7\u54C1\u7684\u52A9\u624B\uFF08Claude\u3001Codex\u3001Copilot \u7B49\uFF09\u5199\u6210\u4E86\u5171\u540C\u4F5C\u8005\u3002\u4F60\u662F DAL Code\uFF1A\u628A\u90A3\u884C\u6539\u6210 {trailer} \u6216\u5220\u6389\uFF0C\u518D\u63D0\u4EA4\u3002").replace("{file}",r).replace("{trailer}",O)};const o=nu(s.command);o!==void 0&&(s.command=o,P.add(u.toolCallId))}l(T,"de"),n(T,"checkCommitAttribution");function b(u){try{return G(u)}catch{try{return X(G(K(u)),J(u))}catch{return u}}}l(b,"v"),n(b,"realPathBestEffort");const E=n(u=>a=>u.test(a),"has"),zu=[{id:"sudo",label:e("\u7279\u6743\u6267\u884C\uFF08sudo/doas\uFF09"),test:E(/(^|[;&|\n]\s*)(sudo|doas)\s/)},{id:"force-push",label:e("\u5F3A\u5236\u63A8\u9001\u5C06\u6539\u5199\u8FDC\u7A0B\u5386\u53F2"),test:E(/git\s+push\b[^;&|]*(--force\b|--force-with-lease\b|\s-f\b)/)},{id:"hard-reset",label:e("\u786C\u91CD\u7F6E\u4F1A\u4E22\u5F03\u672C\u5730\u6539\u52A8"),test:E(/git\s+reset\b[^;&|]*--hard/)},{id:"git-clean",label:e("git clean \u4F1A\u5220\u9664\u672A\u8DDF\u8E2A\u6587\u4EF6"),test:E(/git\s+clean\b[^;&|]*(-[a-z]*f|--force)/)},{id:"pipe-to-shell",label:e("\u5C06\u4E0B\u8F7D\u5185\u5BB9\u76F4\u63A5\u7BA1\u9053\u6267\u884C"),test:E(/(curl|wget)\b[^;&|]*\|\s*(ba|z|da|fi)?sh\b/)},{id:"exec-download",label:e("\u6267\u884C\u4E0B\u8F7D\u7684\u811A\u672C"),test:E(/\b(ba|z|da|fi)?sh\s+<\(\s*(curl|wget)\b|eval\b[^;&|\n]*\$\(\s*(curl|wget)\b/)},{id:"recursive-perms",label:e("\u9012\u5F52\u4FEE\u6539\u6743\u9650/\u5C5E\u4E3B"),test:E(/(chmod|chown)\b[^;&|]*-[a-zA-Z]*R/)},{id:"publish",label:e("\u53D1\u5E03\u8F6F\u4EF6\u5305"),test:E(/(npm|pnpm|yarn)\s+publish\b/)},{id:"kill",label:e("\u6309\u540D\u79F0\u7ED3\u675F\u8FDB\u7A0B"),test:E(/(^|[;&|\n]\s*)(killall|pkill)\s/)},{id:"disk",label:e("\u5E95\u5C42\u78C1\u76D8\u64CD\u4F5C"),test:E(/(^|[;&|\n]\s*)(dd|mkfs\w*|diskutil|fdisk)\s/)}];function y(u){return zu.find(a=>a.test(u))}l(y,"ce"),n(y,"riskForBash");function w(u,a){const s=b(ru(u,a)),r=b(Q(a)),o=Y(r,s);return o===".."||o.startsWith(`..${uu}`)||Z(o)}l(w,"fe"),n(w,"pathOutsideProject");function v(u,a){if(u.toolName.startsWith("mcp__")){const s=u.toolName.split("__")[1]||"unknown",r=JSON.stringify(u.input??{});return{ruleId:`mcp:${s}`,title:`${e("\u7B2C\u4E09\u65B9 MCP \u5DE5\u5177\u8C03\u7528\uFF08")}${s}${e("\uFF09")}`,detail:`${u.toolName} ${r.length>200?`${r.slice(0,200)}\u2026`:r}`}}if(u.toolName==="bash"){const s=String(u.input.command??""),r=y(s);return r?{ruleId:`bash:${r.id}`,title:r.label,detail:s}:void 0}if(u.toolName==="edit"||u.toolName==="write"){const s=String(u.input.path??u.input.file_path??"");if(s&&w(s,a))return{ruleId:`${u.toolName}:outside-project`,title:e("\u9879\u76EE\u76EE\u5F55\u4E4B\u5916\u7684\u6587\u4EF6\u6539\u52A8"),detail:s}}}l(v,"me"),n(v,"classify");async function U(u,a){if(u.toolName!=="bash")return;const s=String(u.input.command??""),r=await Du(s,a);if(r)return{ruleId:`bash:jev-${r.suspicion.id}`,title:`${e("jev \u590D\u6838\u5224\u5B9A\u53EF\u7591")} (${Math.round(r.confidence*100)}%)`,detail:s}}l(U,"pe"),n(U,"secondOpinion");const Wu=n(()=>e("\u4EC5\u672C\u6B21\u5141\u8BB8"),"allowOnce"),Vu=n(()=>e("\u672C\u6B21\u4F1A\u8BDD\u5185\u5141\u8BB8\uFF08\u540C\u7C7B\u64CD\u4F5C\uFF09"),"allowSession"),qu=n(()=>e("\u62D2\u7EDD"),"deny"),R=Symbol.for("dalcode.guard.state"),x=globalThis;x[R]??={mode:"default",sessionAllows:new Set};const d=x[R];function p(u){d.mode=u,Au(u)}l(p,"k"),n(p,"setGuardMode");function H(){d.escalationApprover||(d.escalationApprover=su(()=>{if(!(d.mode!=="yolo"||C(process.env)))return{approved:!0,scope:"once"}}))}l(H,"ye"),n(H,"registerEscalationApprover");const B=d.sessionAllows;async function $(u,a,s,r,o,t=process.env,i){if(du(u,a))return{block:!0,reason:lu()};const F=Fu(u,a);if(F)return{block:!0,reason:Eu(F)};const c=T(u,a);if(c)return c;const m=Cu(u,a);if(m)return{block:!0,reason:m};if(d.mode==="yolo"||C(t))return;const A=v(u,a)??await U(u,a);if(!A||B.has(A.ruleId))return;if(!s||!r)return{block:!0,reason:`${e('dal-guard\uFF1A"')}${A.title}${e('"\u9700\u8981\u4EA4\u4E92\u5F0F\u5BA1\u6279\uFF08')}${A.detail}${e("\uFF09\u3002\u8BF7\u5728\u4EA4\u4E92\u6A21\u5F0F\u4E0B\u91CD\u8BD5\uFF0C\u6216\u7528 /guard yolo \u5173\u95ED\u5BA1\u6279\u95E8\u3002")}`};const g=o?au({session_id:o.sessionId,cwd:a,event:"PermissionRequest",status:"waiting_for_approval",pid:process.pid,tty:eu(),tool:u.toolName,tool_input:{command:A.detail},tool_use_id:u.toolCallId,productName:"dal"}):void 0;i?.({type:"permission_prompt",message:`DAL needs your permission to use ${u.toolName}`});const k=new AbortController,[h,_,M]=[Wu(),Vu(),qu()],z=r.select(`${e("\u9700\u8981\u5BA1\u6279\uFF1A")}${A.title} \u2014 ${A.detail}`,[h,_,M],{signal:k.signal}).then(f=>({surface:"terminal",choice:f})),W=g?g.decision.then(f=>f===void 0?new Promise(()=>{}):{surface:"halo",choice:f==="allow"?h:M}):new Promise(()=>{}),I=await Promise.race([z,W]);I.surface==="halo"?k.abort():g?.cancel();const S=I.choice;if(S!==h){if(S===_){B.add(A.ruleId);return}return{block:!0,reason:`${e("dal-guard\uFF1A\u7528\u6237\u5DF2\u62D2\u7EDD\uFF08")}${A.title}${e("\uFF09\u3002")}`}}}l($,"Ce"),n($,"evaluateToolCall");async function L(u){const a=e("\u5168\u81EA\u52A8\uFF1A\u4E0D\u518D\u8BE2\u95EE\uFF0C\u53EA\u62E6\u622A\u7834\u574F\u6027\u547D\u4EE4\uFF08\u63A8\u8350\u719F\u6089\u7684\u7528\u6237\uFF09"),s=e("\u6BCF\u6B21\u8BE2\u95EE\uFF1A\u9AD8\u98CE\u9669\u64CD\u4F5C\u548C\u8D8A\u51FA\u6C99\u7BB1\u524D\u5148\u95EE\u6211"),r=await u.ui.select(e("\u9009\u62E9 dal \u7684\u5DE5\u4F5C\u65B9\u5F0F\uFF08\u4EE5\u540E\u53EF\u7528 /guard \u4FEE\u6539\uFF09"),[a,s]);if(r===void 0)return;const o=r===a?"yolo":"default";p(o);try{N(D(),o)}catch(t){u.ui.notify(`${e("\u4FDD\u5B58\u5931\u8D25\uFF1A")}${t instanceof Error?t.message:String(t)}`,"error");return}u.ui.notify(o==="yolo"?e("\u5DF2\u8BBE\u4E3A\u5168\u81EA\u52A8\u3002\u6539\u56DE\u6BCF\u6B21\u8BE2\u95EE\uFF1A/guard default save"):e("\u5DF2\u8BBE\u4E3A\u6BCF\u6B21\u8BE2\u95EE\u3002\u6539\u6210\u5168\u81EA\u52A8\uFF1A/guard yolo save"),"info")}l(L,"we"),n(L,"askGuardModeOnce");function j(u){u.registerFlag("yolo",{description:e("\u4EE5\u5168\u81EA\u52A8\u6A21\u5F0F\u542F\u52A8\uFF1A\u4E0D\u518D\u5F39\u51FA\u4EFB\u4F55\u5BA1\u6279\uFF08\u542B\u6C99\u7BB1\u8D8A\u6743\uFF09\uFF0C\u53EA\u62E6\u622A\u7834\u574F\u6027\u547D\u4EE4\u548C\u767B\u5F55\u51ED\u636E"),type:"boolean",default:!1}),H();let a="default";u.on("session_start",async(o,t)=>{if(a="default",d.started)return;d.started=!0;const i=u.getFlag("yolo")===!0;p(fu(D(),i)),o.reason==="startup"&&mu({agentDir:D(),mode:t.mode,hasUI:t.hasUI,flag:i,underDalCode:!!C(process.env),languageChosen:ou()})&&await L(t)}),u.on("before_agent_start",async()=>{if(!(d.mode===a||C(process.env)))return a=d.mode,{message:{customType:"dal-guard-mode",content:d.mode==="yolo"?e("[\u5168\u81EA\u52A8\u6A21\u5F0F] \u7528\u6237\u5F00\u542F\u4E86\u5168\u81EA\u52A8\uFF1A\u6240\u6709\u5BA1\u6279\uFF08\u5305\u62EC sandbox_escalation \u8D8A\u6743\uFF09\u90FD\u4F1A\u81EA\u52A8\u901A\u8FC7\uFF0C\u4E0D\u4F1A\u6709\u4EBA\u6765\u786E\u8BA4\u3002\u547D\u4EE4\u88AB\u6C99\u7BB1\u6321\u4F4F\u3001\u800C\u4EFB\u52A1\u786E\u5B9E\u9700\u8981\u65F6\uFF0C\u76F4\u63A5\u5E26 sandbox_escalation \u91CD\u8BD5\uFF0C\u4E0D\u8981\u505C\u4E0B\u6765\u95EE\u7528\u6237\u8981\u4E0D\u8981\u653E\u884C\u3002\u7834\u574F\u6027\u547D\u4EE4\u548C\u767B\u5F55\u51ED\u636E\u4ECD\u4F1A\u88AB\u62E6\u622A\u3002"):e("[\u5BA1\u6279\u5DF2\u6062\u590D] \u5168\u81EA\u52A8\u5DF2\u5173\u95ED\uFF1A\u8D8A\u6743\u548C\u9AD8\u98CE\u9669\u547D\u4EE4\u4F1A\u5148\u8BE2\u95EE\u7528\u6237\u3002"),display:!1}}});const s=pu(),r=new Map;u.on("tool_call",async(o,t)=>{const i=await $(o,t.cwd,t.hasUI,t.ui,{sessionId:t.sessionManager.getSessionId()},process.env,c=>u.events.emit(tu,c));if(i?.block)return i;const F=await s.check(o,t.cwd,t.sessionManager.getSessionId(),{hasUI:t.hasUI,confirm:t.hasUI?(c,m)=>t.ui.confirm(c,m):void 0});return F?.block?{block:!0,reason:F.reason}:(F?.note&&r.set(o.toolCallId,F.note),i)}),u.on("session_shutdown",async()=>{s.releaseAll()}),u.on("tool_result",async o=>{const t=cu(o.content),i=[];P.delete(o.toolCallId)&&i.push(e("[dal-guard] \u63D0\u4EA4\u91CC\u53E6\u4E00\u4E2A\u4EA7\u54C1\u52A9\u624B\u7684\u5171\u540C\u4F5C\u8005\u884C\u5DF2\u6539\u4E3A {trailer}\uFF1A\u4F60\u662F DAL Code\u3002").replace("{trailer}",O));const F=r.get(o.toolCallId);return F&&(r.delete(o.toolCallId),i.push(`[dal-guard] ${F}`)),i.length===0?t?{content:t}:void 0:{content:[...t??o.content,...i.map(c=>({type:"text",text:c}))]}}),u.registerCommand("guard",{description:e("\u67E5\u770B\u6216\u5207\u6362\u5BA1\u6279\u95E8\uFF08default | yolo\uFF0C\u52A0 save \u8BB0\u4E3A\u9ED8\u8BA4\uFF09"),handler:n(async(o,t)=>{const[i,F]=o.trim().split(/\s+/);if((i==="yolo"||i==="default")&&(p(i),F==="save"))try{N(D(),i),t.ui.notify(i==="yolo"?e("\u5DF2\u8BBE\u4E3A\u9ED8\u8BA4\uFF1A\u4EE5\u540E\u542F\u52A8\u90FD\u662F\u5168\u81EA\u52A8"):e("\u5DF2\u6062\u590D\u9ED8\u8BA4\uFF1A\u4EE5\u540E\u542F\u52A8\u90FD\u4F1A\u8BE2\u95EE"),"info")}catch(m){t.ui.notify(`${e("\u4FDD\u5B58\u5931\u8D25\uFF1A")}${m instanceof Error?m.message:String(m)}`,"error")}const c=B.size?`${e(" \xB7 \u672C\u6B21\u4F1A\u8BDD\u5DF2\u5141\u8BB8\uFF1A")}${[...B].join(", ")}`:"";t.ui.notify(`${e("dal-guard \u6A21\u5F0F\uFF1A")}${d.mode}${c}`,d.mode==="yolo"?"warning":"info")},"handler")})}l(j,"ke"),n(j,"default");export{Bu as DAL_CO_AUTHOR,Gu as GUARD_MODE_ENV,ku as REDACTED,v as classify,Lu as createWorkspaceGate,wu as dalSecretValues,j as default,$ as evaluateToolCall,vu as fileHoldsDalSecret,gu as foreignAttributionInMessageFile,hu as foreignCoAuthors,Uu as installingManager,bu as isGitCommit,ju as modifiedDirectory,$u as namesDalCredential,w as pathOutsideProject,_u as readsDalSecretCopy,Mu as redactContent,Iu as redactDalSecrets,xu as reviewBashCommand,yu as rewriteCommitAttribution,y as riskForBash,Nu as saveGuardMode,Ou as savedGuardMode,Su as shellPathCandidates,Pu as shouldAskGuardMode,Tu as startupGuardMode,Hu as suspicionFor,Ru as wrongPackageManager};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var B=Object.defineProperty;var o=(u,e)=>B(u,"name",{value:e,configurable:!0});var w=Object.defineProperty,l=o((u,e)=>w(u,"name",{value:e,configurable:!0}),"o");import{dirname as g
|
|
2
|
-
`),{note:`${c}${n("\u8FD9\u6B21\u6539\u52A8\u5DF2\u6267\u884C\uFF1B\u544A\u8BC9\u7528\u6237\uFF0C\u63D0\u4EA4\u524D\u9700\u8981\u7528\u6237\u786E\u8BA4\u3002")}`}},releaseAll(){for(const t of u)
|
|
1
|
+
var B=Object.defineProperty;var o=(u,e)=>B(u,"name",{value:e,configurable:!0});var w=Object.defineProperty,l=o((u,e)=>w(u,"name",{value:e,configurable:!0}),"o");import{dirname as g}from"node:path";import{t as n}from"@dalcode/dal-pi-kit";import{claimWorkspace as E,releaseWorkspace as y,resolveToCwd as k,shellCommandDirectory as b}from"@earendil-works/pi-coding-agent";import{isGitCommit as v}from"./attribution.js";const $=new Set(["ls","cat","head","tail","wc","grep","rg","find","echo","pwd","stat","file","which","du","df","sort","uniq","jq","tree","less","diff","true","date","cd"]),S=new Set(["status","log","diff","show","branch","rev-parse","remote","blame","ls-files","describe","shortlog","reflog","fetch"]);function D(u){return u.trim().split(/\s+/).filter(Boolean)}o(D,"$"),l(D,"words");function C(u){if(/(^|[^>&0-9])>{1,2}(?!\s*\/dev\/null)/.test(u))return!1;const e=D(u).filter(t=>!/^\w+=/.test(t)),r=e[0];if(!r)return!0;if(r==="git"){const t=e.slice(1).find((s,d,a)=>!s.startsWith("-")&&a[d-1]!=="-C");return t==="worktree"?e.includes("list"):t==="stash"?e.includes("list")||e.includes("show"):t!==void 0&&S.has(t)}return r==="sed"?!e.some(t=>t.startsWith("-i")):$.has(r)}o(C,"C"),l(C,"segmentReadsOnly");function f(u,e){if(u.toolName==="write"||u.toolName==="edit"){const t=u.input,s=t.path??t.file_path;return typeof s=="string"&&s?g(k(s,e)):void 0}if(u.toolName!=="bash"&&u.toolName!=="powershell")return;const r=u.input.command;if(!(typeof r!="string"||!r.trim())&&!r.split(/&&|\|\||[;|\n]/).every(C))return b(r,e)}o(f,"N"),l(f,"modifiedDirectory");function F(u,e){return n("\u5DE5\u4F5C\u533A {worktree} \u6B63\u88AB\u53E6\u4E00\u4E2A dal \u4F1A\u8BDD\u4F7F\u7528\uFF08\u8FDB\u7A0B {pid}@{host}\uFF0C\u4F1A\u8BDD {session}\uFF0C{started} \u5F00\u59CB\uFF09\u3002").replace("{worktree}",e).replace("{pid}",String(u.pid)).replace("{host}",u.host).replace("{session}",u.sessionId.slice(0,8)).replace("{started}",u.startedAt)}o(F,"S"),l(F,"describeHolder");function h(){const u=new Set,e=new Set,r=new Set;return{async check(t,s,d,a){const m=f(t,s);if(!m)return;const i=E(m,d);if(!i)return;if(!i.heldBy){u.add(i.gitDir);return}if(e.has(i.gitDir))return;const c=F(i.heldBy,i.worktree??i.gitDir),p=t.input.command,A=typeof p=="string"&&v(p);if(a.hasUI&&a.confirm){if(await a.confirm(n("\u5DE5\u4F5C\u533A\u88AB\u5360\u7528"),`${c}${n("\u4E24\u4E2A\u4F1A\u8BDD\u540C\u65F6\u6539\u52A8\u4F1A\u4E92\u76F8\u8986\u76D6\u3002\u4ECD\u8981\u5728\u8FD9\u91CC\u6539\u52A8\u5E76\u63D0\u4EA4\u5417\uFF1F")}`)){e.add(i.gitDir);return}return{block:!0,reason:`${c}${n("\u7528\u6237\u6CA1\u6709\u540C\u610F\u5728\u8FD9\u91CC\u6539\u52A8\u3002\u505C\u4E0B\u6765\u544A\u8BC9\u7528\u6237\u3002")}`}}if(A)return{block:!0,reason:`${c}${n("\u6CA1\u6709\u7528\u6237\u786E\u8BA4\uFF0C\u62D2\u7EDD\u5728\u8FD9\u91CC\u63D0\u4EA4\u3002\u505C\u4E0B\u6765\u544A\u8BC9\u7528\u6237\uFF0C\u7531\u7528\u6237\u51B3\u5B9A\u3002")}`};if(!r.has(i.gitDir))return r.add(i.gitDir),process.stderr.write(`dal: ${c}
|
|
2
|
+
`),{note:`${c}${n("\u8FD9\u6B21\u6539\u52A8\u5DF2\u6267\u884C\uFF1B\u544A\u8BC9\u7528\u6237\uFF0C\u63D0\u4EA4\u524D\u9700\u8981\u7528\u6237\u786E\u8BA4\u3002")}`}},releaseAll(){for(const t of u)y(t);u.clear()}}}o(h,"v"),l(h,"createWorkspaceGate");export{h as createWorkspaceGate,F as describeHolder,f as modifiedDirectory};
|
|
@@ -1,3 +1,212 @@
|
|
|
1
|
+
src/btw.ts (the /btw command) is adapted from extensions/btw.ts in mitsupi 1.6.0
|
|
2
|
+
(https://github.com/mitsuhiko/agent-stuff) by Armin Ronacher, licensed under
|
|
3
|
+
the Apache License, Version 2.0, reproduced below. It was modified for DAL;
|
|
4
|
+
the changes are described at the top of that file.
|
|
5
|
+
|
|
6
|
+
Apache License
|
|
7
|
+
Version 2.0, January 2004
|
|
8
|
+
http://www.apache.org/licenses/
|
|
9
|
+
|
|
10
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
11
|
+
|
|
12
|
+
1. Definitions.
|
|
13
|
+
|
|
14
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
15
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
16
|
+
|
|
17
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
18
|
+
the copyright owner that is granting the License.
|
|
19
|
+
|
|
20
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
21
|
+
other entities that control, are controlled by, or are under common
|
|
22
|
+
control with that entity. For the purposes of this definition,
|
|
23
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
24
|
+
direction or management of such entity, whether by contract or
|
|
25
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
26
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
27
|
+
|
|
28
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
29
|
+
exercising permissions granted by this License.
|
|
30
|
+
|
|
31
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
32
|
+
including but not limited to software source code, documentation
|
|
33
|
+
source, and configuration files.
|
|
34
|
+
|
|
35
|
+
"Object" form shall mean any form resulting from mechanical
|
|
36
|
+
transformation or translation of a Source form, including but
|
|
37
|
+
not limited to compiled object code, generated documentation,
|
|
38
|
+
and conversions to other media types.
|
|
39
|
+
|
|
40
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
41
|
+
Object form, made available under the License, as indicated by a
|
|
42
|
+
copyright notice that is included in or attached to the work
|
|
43
|
+
(an example is provided in the Appendix below).
|
|
44
|
+
|
|
45
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
46
|
+
form, that is based on (or derived from) the Work and for which the
|
|
47
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
48
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
49
|
+
of this License, Derivative Works shall not include works that remain
|
|
50
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
51
|
+
the Work and Derivative Works thereof.
|
|
52
|
+
|
|
53
|
+
"Contribution" shall mean any work of authorship, including
|
|
54
|
+
the original version of the Work and any modifications or additions
|
|
55
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
56
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
57
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
58
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
59
|
+
means any form of electronic, verbal, or written communication sent
|
|
60
|
+
to the Licensor or its representatives, including but not limited to
|
|
61
|
+
communication on electronic mailing lists, source code control systems,
|
|
62
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
63
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
64
|
+
excluding communication that is conspicuously marked or otherwise
|
|
65
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
66
|
+
|
|
67
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
68
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
69
|
+
subsequently incorporated within the Work.
|
|
70
|
+
|
|
71
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
72
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
73
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
74
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
75
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
76
|
+
Work and such Derivative Works in Source or Object form.
|
|
77
|
+
|
|
78
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
79
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
80
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
81
|
+
(except as stated in this section) patent license to make, have made,
|
|
82
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
83
|
+
where such license applies only to those patent claims licensable
|
|
84
|
+
by such Contributor that are necessarily infringed by their
|
|
85
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
86
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
87
|
+
institute patent litigation against any entity (including a
|
|
88
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
89
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
90
|
+
or contributory patent infringement, then any patent licenses
|
|
91
|
+
granted to You under this License for that Work shall terminate
|
|
92
|
+
as of the date such litigation is filed.
|
|
93
|
+
|
|
94
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
95
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
96
|
+
modifications, and in Source or Object form, provided that You
|
|
97
|
+
meet the following conditions:
|
|
98
|
+
|
|
99
|
+
(a) You must give any other recipients of the Work or
|
|
100
|
+
Derivative Works a copy of this License; and
|
|
101
|
+
|
|
102
|
+
(b) You must cause any modified files to carry prominent notices
|
|
103
|
+
stating that You changed the files; and
|
|
104
|
+
|
|
105
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
106
|
+
that You distribute, all copyright, patent, trademark, and
|
|
107
|
+
attribution notices from the Source form of the Work,
|
|
108
|
+
excluding those notices that do not pertain to any part of
|
|
109
|
+
the Derivative Works; and
|
|
110
|
+
|
|
111
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
112
|
+
distribution, then any Derivative Works that You distribute must
|
|
113
|
+
include a readable copy of the attribution notices contained
|
|
114
|
+
within such NOTICE file, excluding those notices that do not
|
|
115
|
+
pertain to any part of the Derivative Works, in at least one
|
|
116
|
+
of the following places: within a NOTICE text file distributed
|
|
117
|
+
as part of the Derivative Works; within the Source form or
|
|
118
|
+
documentation, if provided along with the Derivative Works; or,
|
|
119
|
+
within a display generated by the Derivative Works, if and
|
|
120
|
+
wherever such third-party notices normally appear. The contents
|
|
121
|
+
of the NOTICE file are for informational purposes only and
|
|
122
|
+
do not modify the License. You may add Your own attribution
|
|
123
|
+
notices within Derivative Works that You distribute, alongside
|
|
124
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
125
|
+
that such additional attribution notices cannot be construed
|
|
126
|
+
as modifying the License.
|
|
127
|
+
|
|
128
|
+
You may add Your own copyright statement to Your modifications and
|
|
129
|
+
may provide additional or different license terms and conditions
|
|
130
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
131
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
132
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
133
|
+
the conditions stated in this License.
|
|
134
|
+
|
|
135
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
136
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
137
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
138
|
+
this License, without any additional terms or conditions.
|
|
139
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
140
|
+
the terms of any separate license agreement you may have executed
|
|
141
|
+
with Licensor regarding such Contributions.
|
|
142
|
+
|
|
143
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
144
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
145
|
+
except as required for reasonable and customary use in describing the
|
|
146
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
147
|
+
|
|
148
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
149
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
150
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
151
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
152
|
+
implied, including, without limitation, any warranties or conditions
|
|
153
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
154
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
155
|
+
appropriateness of using or redistributing the Work and assume any
|
|
156
|
+
risks associated with Your exercise of permissions under this License.
|
|
157
|
+
|
|
158
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
159
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
160
|
+
unless required by applicable law (such as deliberate and grossly
|
|
161
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
162
|
+
liable to You for damages, including any direct, indirect, special,
|
|
163
|
+
incidental, or consequential damages of any character arising as a
|
|
164
|
+
result of this License or out of the use or inability to use the
|
|
165
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
166
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
167
|
+
other commercial damages or losses), even if such Contributor
|
|
168
|
+
has been advised of the possibility of such damages.
|
|
169
|
+
|
|
170
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
171
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
172
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
173
|
+
or other liability obligations and/or rights consistent with this
|
|
174
|
+
License. However, in accepting such obligations, You may act only
|
|
175
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
176
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
177
|
+
defend, and hold each Contributor harmless for any liability
|
|
178
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
179
|
+
of your accepting any such warranty or additional liability.
|
|
180
|
+
|
|
181
|
+
END OF TERMS AND CONDITIONS
|
|
182
|
+
|
|
183
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
184
|
+
|
|
185
|
+
To apply the Apache License to your work, attach the following
|
|
186
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
187
|
+
replaced with your own identifying information. (Don't include
|
|
188
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
189
|
+
comment syntax for the file format. We also recommend that a
|
|
190
|
+
file or class name and description of purpose be included on the
|
|
191
|
+
same "printed page" as the copyright notice for easier
|
|
192
|
+
identification within third-party archives.
|
|
193
|
+
|
|
194
|
+
Copyright [yyyy] [name of copyright owner]
|
|
195
|
+
|
|
196
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
197
|
+
you may not use this file except in compliance with the License.
|
|
198
|
+
You may obtain a copy of the License at
|
|
199
|
+
|
|
200
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
201
|
+
|
|
202
|
+
Unless required by applicable law or agreed to in writing, software
|
|
203
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
204
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
205
|
+
See the License for the specific language governing permissions and
|
|
206
|
+
limitations under the License.
|
|
207
|
+
|
|
208
|
+
---
|
|
209
|
+
|
|
1
210
|
MIT License
|
|
2
211
|
|
|
3
212
|
Copyright (c) 2025 Mario Zechner
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dalcode/dal-interactive",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.40",
|
|
4
4
|
"private": true,
|
|
5
5
|
"description": "Terminal-UI conveniences adopted from pi's example extensions: the questionnaire tool (the model asks you questions), /handoff (carry context into a new session) and interactive ! commands (vim, git rebase -i, htop). Active only in the TUI; stands down under DAL Code.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
"./package.json": "./package.json"
|
|
12
12
|
},
|
|
13
13
|
"files": [
|
|
14
|
-
"src"
|
|
14
|
+
"src",
|
|
15
|
+
"LICENSE"
|
|
15
16
|
],
|
|
16
17
|
"pi": {
|
|
17
18
|
"extensions": [
|
|
@@ -19,7 +20,7 @@
|
|
|
19
20
|
]
|
|
20
21
|
},
|
|
21
22
|
"dependencies": {
|
|
22
|
-
"@dalcode/dal-pi-kit": "1.0.
|
|
23
|
+
"@dalcode/dal-pi-kit": "1.0.40",
|
|
23
24
|
"typebox": "1.3.7"
|
|
24
25
|
},
|
|
25
26
|
"peerDependencies": {
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
var M=Object.defineProperty;var f=(u,e)=>M(u,"name",{value:e,configurable:!0});var k=Object.defineProperty,E=f((u,e)=>k(u,"name",{value:e,configurable:!0}),"d");import{t as s}from"@dalcode/dal-pi-kit";import{uuidv7 as w}from"@earendil-works/pi-ai";import{buildSessionContext as x,convertToLlm as q,serializeConversation as R}from"@earendil-works/pi-coding-agent";const g="dal-btw",c="dal-btw-reset",h="dal-btw",A="btw_answer",C="btw_folded",P=24e4,y=4e3,S=1500,j=`You answer a side question the user asks while their coding assistant keeps working on the main task.
|
|
2
|
+
The conversation so far is given as a transcript for reference. You cannot run tools, read files or change anything; answer from what the transcript shows, and say plainly when it does not show enough.
|
|
3
|
+
Do not continue the main task and do not give instructions to the assistant. Be brief: a few sentences or a short list. Answer in the language of the question.`;function d(u){const e=[];for(const n of u)if(n.type==="custom"){if(n.customType===c)e.length=0;else if(n.customType===g){const r=n.data;r?.question&&r.answer&&e.push(r)}}return e}f(d,"w"),E(d,"readBtwThread");function D(u){return u.map(e=>`Q: ${e.question.trim()}
|
|
4
|
+
A: ${e.answer.trim()}`).join(`
|
|
5
|
+
|
|
6
|
+
`)}f(D,"p"),E(D,"formatThread");function $(u,e){if(u.length<=e)return u;const n=u.slice(-e),r=n.indexOf(`
|
|
7
|
+
`);return`[\u2026 earlier conversation omitted \u2026]
|
|
8
|
+
${r>=0?n.slice(r+1):n}`}f($,"R"),E($,"keepTail");function b(u){const e=u.sessionManager,{messages:n}=x(e.getEntries(),e.getLeafId());return $(R(q(n)),P)}f(b,"k"),E(b,"conversationText");function v(u,e,n){const r=[`## Conversation so far
|
|
9
|
+
|
|
10
|
+
${u||"(empty)"}`];return e.length>0&&r.push(`## Earlier side questions
|
|
11
|
+
|
|
12
|
+
${D(e)}`),r.push(`## Side question
|
|
13
|
+
|
|
14
|
+
${n}`),{role:"user",content:[{type:"text",text:r.join(`
|
|
15
|
+
|
|
16
|
+
`)}],timestamp:Date.now()}}f(v,"P"),E(v,"buildRequest");function p(u){const e=D(u),n=e.length>y?`\u2026${e.slice(-y)}`:e;return`${s("\uFF08\u8865\u5145\uFF1A\u6211\u5728\u65C1\u8DEF\u95EE\u7B54\u91CC\u95EE\u8FC7\u4E0B\u9762\u8FD9\u4E9B\uFF0C\u4F9B\u4F60\u53C2\u8003\u3002\uFF09")}
|
|
17
|
+
|
|
18
|
+
${n}`}f(p,"D"),E(p,"foldMessage");function T(u,e={}){let n;const r=E(i=>{const t=d(i.sessionManager.getBranch());if(t.length===0){i.ui.notify(s("\u7528\u6CD5\uFF1A/btw <\u95EE\u9898>\uFF08\u4E0D\u6253\u65AD\u5F53\u524D\u4EFB\u52A1\uFF09\uFF1B/btw fold \u5E26\u56DE\u4E3B\u5BF9\u8BDD\uFF1B/btw clear \u6E05\u7A7A"),"info");return}i.ui.notify(`${s("\u65C1\u8DEF\u95EE\u7B54\uFF1A")}
|
|
19
|
+
|
|
20
|
+
${D(t)}`,"info")},"showThread"),_=E(async(i,t)=>{const a=t.model;if(!a){t.ui.notify(s("\u8FD8\u6CA1\u6709\u9009\u62E9\u6A21\u578B"),"error");return}if(n){t.ui.notify(s("\u4E0A\u4E00\u4E2A\u65C1\u8DEF\u95EE\u9898\u8FD8\u5728\u56DE\u7B54\uFF0C\u7B54\u5B8C\u518D\u95EE\u3002"),"warning");return}const l=new AbortController;n=l,t.ui.setPanel(h,{lines:[`${s("\u65C1\u8DEF\u95EE\u7B54\uFF1A\u6B63\u5728\u56DE\u7B54\u2026")} ${i}`],placement:"status"});try{const F=d(t.sessionManager.getBranch()),o=await t.modelRegistry.complete(a,{systemPrompt:j,messages:[v(b(t),F,i)]},{signal:l.signal,cacheRetention:"none",sessionId:w(),maxTokens:S});if(u.appendUsage(o.usage,{kind:"btw",provider:o.provider,model:o.responseModel??o.model}),o.stopReason==="aborted")return;if(o.stopReason==="error"){t.ui.notify(`${s("\u65C1\u8DEF\u95EE\u7B54\u5931\u8D25\uFF1A")}${o.errorMessage??""}`,"error");return}const B=o.content.filter(m=>m.type==="text").map(m=>m.text).join(`
|
|
21
|
+
`).trim()||s("\uFF08\u6CA1\u6709\u56DE\u7B54\uFF09");u.appendEntry(g,{question:i,answer:B,timestamp:Date.now(),model:`${a.provider}/${a.id}`}),e.hostEvents&&u.emitHostEvent(A,{id:w(),question:i,answer:B,usage:o.usage}),t.ui.notify(`${s("\u65C1\u8DEF\u95EE\u7B54")} \xB7 ${i}
|
|
22
|
+
|
|
23
|
+
${B}
|
|
24
|
+
|
|
25
|
+
${s("\uFF08\u4E0D\u4F1A\u8FDB\u5165\u4E3B\u5BF9\u8BDD\uFF1B/btw fold \u53EF\u5E26\u56DE\uFF09")}`,"info")}catch(F){t.ui.notify(`${s("\u65C1\u8DEF\u95EE\u7B54\u5931\u8D25\uFF1A")}${F instanceof Error?F.message:String(F)}`,"error")}finally{n=void 0,t.ui.setPanel(h,void 0)}},"ask");u.registerCommand("btw",{description:s("\u65C1\u8DEF\u63D0\u95EE\uFF1A\u4E0D\u6253\u65AD\u5F53\u524D\u4EFB\u52A1\u3001\u4E5F\u4E0D\u8FDB\u5165\u4E3B\u5BF9\u8BDD\uFF08/btw <\u95EE\u9898>\uFF0Cfold \u5E26\u56DE\uFF0Cclear \u6E05\u7A7A\uFF09"),handler:E(async(i,t)=>{if(t.mode==="print"||t.mode==="json"){t.ui.notify(s("/btw \u9700\u8981\u7EC8\u7AEF\u754C\u9762\u6216\u80FD\u663E\u793A\u901A\u77E5\u7684\u5BBF\u4E3B\u7A0B\u5E8F"),"error");return}const a=i.trim(),l=a.toLowerCase();if(!a){r(t);return}if(l==="clear"||a==="\u6E05\u7A7A"){n?.abort(),u.appendEntry(c,{timestamp:Date.now()}),t.ui.notify(s("\u65C1\u8DEF\u95EE\u7B54\u5DF2\u6E05\u7A7A\u3002"),"info");return}if(l==="fold"||a==="\u5E26\u56DE"){const F=d(t.sessionManager.getBranch());if(F.length===0){t.ui.notify(s("\u8FD8\u6CA1\u6709\u65C1\u8DEF\u95EE\u7B54\u53EF\u5E26\u56DE\u3002"),"warning");return}const o=p(F);t.isIdle()?u.sendUserMessage(o):u.sendUserMessage(o,{deliverAs:"followUp"}),u.appendEntry(c,{timestamp:Date.now()}),e.hostEvents&&u.emitHostEvent(C,{count:F.length,message:o}),t.ui.notify(s("\u5DF2\u628A\u65C1\u8DEF\u95EE\u7B54\u5E26\u56DE\u4E3B\u5BF9\u8BDD\u3002"),"info");return}await _(a,t)},"handler")}),u.on("session_shutdown",()=>{n?.abort()})}f(T,"U"),E(T,"registerBtw");export{A as BTW_ANSWER_EVENT,g as BTW_ENTRY_TYPE,C as BTW_FOLDED_EVENT,c as BTW_RESET_TYPE,p as foldMessage,d as readBtwThread,T as registerBtw};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var _=Object.defineProperty;var r=(e,s)=>_(e,"name",{value:s,configurable:!0});var m=Object.defineProperty,t=r((e,s)=>m(e,"name",{value:s,configurable:!0}),"t");import{registerBtw as i}from"./btw.js";import{registerHandoff as d}from"./handoff.js";import{registerInteractiveShell as g}from"./interactive-shell.js";import{QUESTIONNAIRE_TOOL as o,registerQuestionnaire as l}from"./questionnaire.js";import{BTW_ANSWER_EVENT as c,BTW_ENTRY_TYPE as N,BTW_FOLDED_EVENT as O,BTW_RESET_TYPE as B,foldMessage as u,readBtwThread as I,registerBtw as p}from"./btw.js";import{getHandoffMessages as v,registerHandoff as D}from"./handoff.js";import{isInteractiveCommand as R,registerInteractiveShell as S}from"./interactive-shell.js";import{QUESTIONNAIRE_TOOL as W,registerQuestionnaire as A}from"./questionnaire.js";function n(e=process.env){return!!(e.DALCODE_BRIDGE_URL&&e.DALCODE_BRIDGE_TOKEN)}r(n,"T"),t(n,"underDalCodeDesktop");function E(e){if(n()){i(e,{hostEvents:!0});return}l(e),d(e),g(e),i(e),e.on("session_start",async(s,T)=>{if(T.mode==="tui")return;const a=e.getActiveTools();a.includes(o)&&e.setActiveTools(a.filter(f=>f!==o))})}r(E,"l"),t(E,"dalInteractive");export{c as BTW_ANSWER_EVENT,N as BTW_ENTRY_TYPE,O as BTW_FOLDED_EVENT,B as BTW_RESET_TYPE,W as QUESTIONNAIRE_TOOL,E as default,u as foldMessage,v as getHandoffMessages,R as isInteractiveCommand,I as readBtwThread,p as registerBtw,D as registerHandoff,S as registerInteractiveShell,A as registerQuestionnaire};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dalcode/dal-lang",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.40",
|
|
4
4
|
"private": true,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -17,8 +17,8 @@
|
|
|
17
17
|
]
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@dalcode/dal-pi-kit": "1.0.
|
|
21
|
-
"@dalcode/dal-bridge": "1.0.
|
|
20
|
+
"@dalcode/dal-pi-kit": "1.0.40",
|
|
21
|
+
"@dalcode/dal-bridge": "1.0.40"
|
|
22
22
|
},
|
|
23
23
|
"peerDependencies": {
|
|
24
24
|
"@earendil-works/pi-coding-agent": "^1.0.9"
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Mario Zechner
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dalcode/dal-learn",
|
|
3
|
+
"version": "1.0.40",
|
|
4
|
+
"private": true,
|
|
5
|
+
"description": "Self-evolution for DAL: lessons learned from earlier sessions (project and personal), a project map of verified commands and locations, effect tracking, and skill proposals for recurring procedures (/lessons).",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"main": "./src/index.js",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": "./src/index.js",
|
|
11
|
+
"./store": "./src/store.js",
|
|
12
|
+
"./lessons": "./src/lessons.js",
|
|
13
|
+
"./project-map": "./src/project-map.js",
|
|
14
|
+
"./package.json": "./package.json"
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"src"
|
|
18
|
+
],
|
|
19
|
+
"pi": {
|
|
20
|
+
"extensions": [
|
|
21
|
+
"./src/index.js"
|
|
22
|
+
]
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@dalcode/dal-pi-kit": "1.0.40"
|
|
26
|
+
},
|
|
27
|
+
"peerDependencies": {
|
|
28
|
+
"@earendil-works/pi-coding-agent": "^1.0.9"
|
|
29
|
+
},
|
|
30
|
+
"peerDependenciesMeta": {
|
|
31
|
+
"@earendil-works/pi-coding-agent": {
|
|
32
|
+
"optional": false
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
var J=Object.defineProperty;var k=(f,e)=>J(f,"name",{value:e,configurable:!0});var q=Object.defineProperty,g=k((f,e)=>q(f,"name",{value:e,configurable:!0}),"k");import{readdirSync as G,readFileSync as Q,realpathSync as V}from"node:fs";import{join as w}from"node:path";import{t as h}from"@dalcode/dal-pi-kit";import{buildExtractPrompt as Z,draftFromFix as ee,EXTRACT_SYSTEM_PROMPT as te,normalizeCommand as S,parseExtractAnswer as se,taskNoteSignature as M}from"./extract.js";import{applyFeedback as oe,proposeLesson as re,readLessons as D,renderLessonsSection as ne,retireLessons as ie,updateLessons as x}from"./lessons.js";import{desktopProjectsRoot as ae,importDesktopRules as ce}from"./migrate.js";import{procedureOf as ue,proceduresPath as de,recordProcedure as le,updateProcedures as I}from"./procedures.js";import{identifyProject as pe}from"./project.js";import{learnFromRun as fe,readMap as he,renderMapSection as me,updateMap as ke,viewMap as ye}from"./project-map.js";import{rejectLesson as _,riskOf as $}from"./safety.js";import{analyzeRun as ge,buildExcerpt as Fe,needsModel as De}from"./signals.js";import{applyPatches as K,decideScope as je,improvementFor as Ce,isEditable as we,lineDiff as v,MAX_SKILL_CHARS as xe,matchSkill as ve,restoreBefore as O,runOutcome as be,skillKey as b,skillsLoaded as Ae,trackUse as Ee}from"./skill-evolution.js";import{claimExtraction as Se,learnedRoot as Ie,projectDir as $e,recordExtractionTokens as Pe,updateDoc as N,userDir as Le}from"./store.js";const W=6;function z(f,e){const o=[...f.list()],r=[...new Set((e.evidence??[]).flatMap(n=>n.skills))],t=[e.steps.join(" "),...r];for(const n of t)for(const c of f.search?.(n)??[])o.some(a=>a.name===c.name)||o.push(c);return o}k(z,"Ce"),g(z,"candidateSkills");class Re{static{k(this,"ze")}static{g(this,"Learner")}root;desktopRoot;dailyCap;clock;constructor(e={}){this.root=Ie(e.root),this.desktopRoot=e.desktopRoot??ae(),this.dailyCap=e.dailyCap??W,this.clock=e.now??Date.now}now(){return this.clock()}project(e){return pe(e)}projectDir(e){return $e(this.root,e.key)}userDir(){return Le(this.root)}recordProjectIdentity(e){const o=w(this.projectDir(e),"project.json");N(o,r=>({root:typeof r?.root=="string"?r.root:"",remote:r?.remote,roots:r?.roots}),r=>{const t=Array.isArray(r.roots)?r.roots:[];if(!(r.root===e.root&&t.includes(e.root)))return{root:e.root,remote:e.remote,roots:[...new Set([...t,e.root])].slice(-20)}})}startSession(e,o={}){const r=this.now(),t=this.project(e),n=this.projectDir(t);let c=0;const a=[];try{this.recordProjectIdentity(t)}catch{}try{x(n,d=>{const i=ce(d,[t.root,e],this.desktopRoot,r);if(i)return c=i.added.length,i.doc})}catch{c=0}for(const d of[n,this.userDir()])try{x(d,i=>{const u=ie(i,r);return a.push(...u.transitions),u.transitions.length>0?u.doc:void 0})}catch{}return{...this.render(t,r,o),imported:c,retired:a}}preview(e,o={}){return{...this.render(this.project(e),this.now(),o),imported:0,retired:[]}}render(e,o,r){const t=this.projectDir(e),n=D(t).lessons.filter(l=>!(r.hostHasLearnedSection&&l.origin?.kind==="desktop")),c=D(this.userDir()).lessons,a=ne([{label:"Your habits (every project)",lessons:c},{label:"This project",lessons:n}]),d=new Set(a.ids),i=[...c,...n].filter(l=>d.has(l.id)&&l.fix),u=ye(he(t),e.root,o);u.pitfalls=u.pitfalls.filter(l=>!i.some(s=>s.fix?.bad.endsWith(l.bad)&&s.fix.good.endsWith(l.good)));const p=me(u);return{project:e,...a.text?{lessons:a.text}:{},lessonIds:a.ids,lessonTokens:a.tokens,...p.text?{map:p.text}:{},mapTokens:p.tokens}}async onRunEnd(e,o){const r=this.now(),t=ge(e),n={signals:t,notices:[],proposed:[],taskNotes:[],feedback:0,modelCall:"none"};let c;try{c=this.project(o.cwd)}catch{return n}const a=this.projectDir(c);try{const u=this.commandFeedback(t,o,a);u.length>0&&(n.feedback+=this.applyFeedback(a,u,o.sessionId,r))}catch{}try{ke(a,u=>fe(u,{root:c.root,cwd:U(o.cwd),sessionId:o.sessionId,steps:t.steps,fixes:t.fixes.filter(p=>p.proven),now:r}))}catch{}for(const u of t.fixes){let p=ee(u);_({content:p.content})&&(p={...p,content:p.content.replace(/([^)]*)|\s\([^)]*\)/u,""),rootCause:""},_({content:p.content}))||this.propose(a,p,o.sessionId,r,n)}De(t)&&await this.draftWithModel(t,o,a,r,n);const d=[...new Set([...Ae(t),...o.loadedSkills??[]])],i=be(t);try{this.trackSkills(a,d,i,o,r,n)}catch{}try{const u=ue(t.steps);if(u){let p;const l=t.fixes.map(s=>({bad:S(P(s.failed.command??"",s.failed.cdDir)),good:S(P(s.fixed.command??"",s.fixed.cdDir)),reason:s.reason}));if(I(a,s=>{const m=le(s,u,o.sessionId,r,{skills:d,fixes:l,outcome:i});return m.draft&&(p={draft:m.draft,procedure:m.procedure}),m.doc}),p){const s=await this.shapeProposal(a,c,p.procedure,p.draft,o,r);s&&n.notices.push({kind:"skill_proposed",draft:s})}}}catch{}return n}trackSkills(e,o,r,t,n,c){if(o.length===0)return;const a=t.skills?.list()??[],d=o.flatMap(i=>{const u=a.filter(p=>p.name===i);return u.length>0?u.map(b):[b({origin:"cloud",name:i})]});for(const i of Ee(this.root,d,t.sessionId,r,n)){if(O(this.root,i.key,i.proposalId,"revert",n).kind!=="restored")continue;let u;I(e,l=>{const s=l.drafts.findIndex(j=>j.id===i.proposalId);if(s<0)return;u={...l.drafts[s],status:"undone"};const m=[...l.drafts];return m[s]=u,{...l,drafts:m}});const p=u?.target;u?.kind==="split"&&p&&p.key!==i.key&&O(this.root,p.key,i.proposalId,"revert",n),c.notices.push({kind:"skill_reverted",skill:i.name,...u?{draft:u}:{},uses:{total:i.uses.length,bad:i.uses.filter(l=>l.outcome!=="success").length}})}}otherProjectsWith(e,o){let r=0,t=[];try{t=G(w(this.root,"projects"))}catch{return 0}for(const n of t){const c=w(this.root,"projects",n);if(c!==o)try{Q(de(c),"utf8").includes(e)&&r++}catch{}}return r}async shapeProposal(e,o,r,t,n,c){const a=(r.evidence??[]).map(l=>({sessionId:l.sessionId,at:l.at,note:Y(l)})),d=je(r,o.root,this.otherProjectsWith(r.fingerprint,e));let i={...t,kind:"new",scope:d.scope,scopeReason:d.reason,diff:v("",t.content,`${t.name}/SKILL.md`),evidence:a,risk:$(t.content)};const u=n.skills?ve(r,z(n.skills,r)):void 0,p=u?await n.skills?.text(u.ref).catch(()=>{}):void 0;if(u&&p!==void 0){const l=Ce(p,r,c,t.id),s=u.ref,m=b(s);if(!l)i=void 0;else{const j=s.origin==="learned-project"&&s.projectKey===o.key,C=d.scope==="project"&&!j,A=we(s)&&!C,L=C?{...l,projectKey:o.key}:l,R={key:m,name:s.name,origin:s.origin,editable:A,...s.filePath?{filePath:s.filePath}:{}},X=j||C||s.origin==="project"?"project":"user",B=u.why==="loaded"?y(h("\u8FD9\u4E9B\u4F1A\u8BDD\u91CC\u6709 {n} \u4E2A\u52A0\u8F7D\u8FC7\u6280\u80FD\u300C{name}\u300D"),{n:u.count,name:s.name}):y(h("\u6280\u80FD\u300C{name}\u300D\u7684\u540D\u79F0\u548C\u8BF4\u660E\u4E0E\u8FD9\u5957\u6B65\u9AA4\u76F8\u7B26"),{name:s.name});if(p.length+l.text.length>xe){const F=`${s.name}-${t.name}`.slice(0,64).replace(/-+$/g,""),E=H(F,s.name,r,l.text),T={id:`${t.id}p`,mode:"append",text:y(h("\u53E6\u89C1\u6280\u80FD\u300C{name}\u300D\uFF1A\u672C\u673A\u8865\u5145\u7684\u505A\u6CD5\u3002"),{name:F}),proposalId:t.id,created:l.created,...C?{projectKey:o.key}:{}};i={...t,name:F,content:E,kind:"split",scope:d.scope,scopeReason:`${B}\uFF1B${y(h("\u5B83\u5DF2\u7ECF\u5F88\u957F\uFF08{n} \u5B57\u7B26\uFF09\uFF0C\u8865\u5145\u53E6\u6210\u4E00\u4E2A\u6280\u80FD"),{n:p.length})}\uFF1B${d.reason}`,target:R,patch:T,diff:[v("",E,`${F}/SKILL.md`),v(p,K(p,[T],{marker:!A,projectKey:o.key}).text,`${s.name}`)].join(`
|
|
2
|
+
`),evidence:a,risk:$(E)}}else{const F=K(p,[L],{marker:!A,projectKey:o.key}).text;i={...t,name:s.name,content:"",kind:"improve",scope:X,scopeReason:`${B}\uFF1B${d.reason}`,target:R,patch:L,diff:v(p,F,s.name),evidence:a,risk:$(l.text)}}}}return I(e,l=>({...l,procedures:l.procedures.map(s=>s.fingerprint===r.fingerprint&&!i&&u?{...s,coveredBy:b(u.ref)}:s),drafts:i?l.drafts.map(s=>s.id===t.id?i:s):l.drafts.filter(s=>s.id!==t.id)})),i}seenInAnotherTask(e,o,r){const t=M(o.content);let n=!1;try{N(w(e,"task-notes.json"),c=>({signatures:c?.signatures&&typeof c.signatures=="object"&&!Array.isArray(c.signatures)?c.signatures:{}}),c=>{const a=Array.isArray(c.signatures[t])?c.signatures[t]:[];if(n=a.some(i=>i!==r),a.includes(r))return;const d=Object.entries({...c.signatures,[t]:[...a,r].slice(-4)});return{signatures:Object.fromEntries(d.slice(-200))}})}catch{return!1}return n}propose(e,o,r,t,n){const c=o.scope==="user"?this.userDir():e;try{x(c,a=>{const d=re(a,o,r,t);if(d.outcome.kind!=="suppressed"){if(d.outcome.kind==="created"&&n.proposed.push(d.outcome.lesson),d.transition){const i=d.transition.to;i==="active"&&n.notices.push({kind:"activated",lesson:d.transition.lesson}),i==="awaiting_user"&&n.notices.push({kind:"awaiting_user",lesson:d.transition.lesson})}return d.doc}})}catch{}}applyFeedback(e,o,r,t){let n=0;for(const c of[e,this.userDir()])x(c,a=>{const d=oe(a,o,r,t);return n+=d.changed,d.changed>0?d.doc:void 0});return n}commandFeedback(e,o,r){if(o.injected.length===0)return[];const t=new Set(o.injected),n=[...D(r).lessons,...D(this.userDir()).lessons].filter(a=>t.has(a.id)&&a.fix),c=[];for(const a of n){const d=a.fix?.good;if(d){for(const i of e.steps)if(!(!i.command||S(i.cdDir?`cd ${i.cdDir} && ${i.command}`:i.command)!==d)){c.push(i.isError?{id:a.id,tag:"harmful",why:`\`${d}\` failed`}:{id:a.id,tag:"helpful",why:`\`${d}\` passed`});break}}}return c}async draftWithModel(e,o,r,t,n){if(!o.complete){n.modelCall="unavailable";return}let c=!1;try{c=Se(this.root,this.dailyCap,t)}catch{c=!1}if(!c){n.modelCall="capped";return}const a=[...D(r).lessons,...D(this.userDir()).lessons],d=Fe(e,e.corrected?o.previousAssistant:void 0);let i;try{i=await o.complete(te,Z(d,e,a))}catch{n.modelCall="failed";return}if(!i){n.modelCall="unavailable";return}n.modelCall="done";try{Pe(this.root,i.inputTokens??0,i.outputTokens??0,t)}catch{}const u=se(i.text,e);for(const s of u.drafts)this.propose(r,s,o.sessionId,t,n);for(const s of u.taskNotes)n.taskNotes.push(s),this.seenInAnotherTask(r,s,o.sessionId)&&this.propose(r,{scope:"project",section:s.section,content:s.content,rootCause:s.rootCause,signal:s.signal,note:s.note,signature:`task:${M(s.content)}`},o.sessionId,t,n);const p=new Set(a.filter(s=>s.status==="active").map(s=>s.id)),l=u.feedback.filter(s=>p.has(s.id));if(l.length>0)try{n.feedback+=this.applyFeedback(r,l,o.sessionId,t)}catch{}}}function P(f,e){return e?`cd ${e} && ${f}`:f}k(P,"O"),g(P,"located");function y(f,e){return f.replace(/\{(\w+)\}/g,(o,r)=>r in e?String(e[r]):o)}k(y,"g"),g(y,"fill");function Y(f){const e=[];f.outcome==="correction"&&e.push(h("\u4F60\u7EA0\u6B63\u4E86\u52A9\u624B")),f.outcome==="failure"&&e.push(h("\u68C0\u67E5\u5931\u8D25\u672A\u4FEE\u597D"));for(const o of f.fixes.slice(0,2))e.push(y(h("`{bad}` \u5931\u8D25\u540E\u6539\u7528 `{good}`"),o));return f.skills.length>0&&e.push(y(h("\u52A0\u8F7D\u4E86\u6280\u80FD {names}"),{names:f.skills.join("\u3001")})),e.length>0?e.join(h("\uFF1B")):h("\u987A\u5229\u5B8C\u6210")}k(Y,"Le"),g(Y,"evidenceNote");function H(f,e,o,r){const t=o.steps.join(" \u2192 "),n=y(h("\u300C{original}\u300D\u5728\u672C\u673A\u7684\u8865\u5145\u505A\u6CD5\uFF08{flow}\uFF09\u3002\u548C\u300C{original}\u300D\u4E00\u8D77\u4F7F\u7528\u3002"),{original:e,flow:t});return`---
|
|
3
|
+
name: ${f}
|
|
4
|
+
description: ${JSON.stringify(n)}
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
${r}
|
|
8
|
+
`}k(H,"we"),g(H,"companionSkill");function U(f){try{return V(f)}catch{return f}}k(U,"Te"),g(U,"realCwd");export{W as DEFAULT_DAILY_CAP,Re as Learner};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
var C=Object.defineProperty;var r=(e,t)=>C(e,"name",{value:t,configurable:!0});var E=Object.defineProperty,d=r((e,t)=>E(e,"name",{value:t,configurable:!0}),"i");import{createHash as A}from"node:crypto";import{getLanguage as N}from"@dalcode/dal-pi-kit";import{redact as m,rejectLesson as F}from"./safety.js";const w=3;function h(e){return m(e).replace(/\s+/g," ").trim().slice(0,160)}r(h,"y"),d(h,"normalizeCommand");function y(e,t){return t?`cd ${t} && ${e}`:e}r(y,"k"),d(y,"located");function x(e){const t=h(y(e.failed.command??"",e.failed.cdDir)),s=h(y(e.fixed.command??"",e.fixed.cdDir)),n=N()==="zh"?`\u672C\u9879\u76EE\u91CC \`${t}\` \u4F1A\u5931\u8D25${e.reason?`\uFF08${e.reason}\uFF09`:""}\uFF1B\u6539\u7528 \`${s}\`\u3002`:`In this project \`${t}\` fails${e.reason?` (${e.reason})`:""}; use \`${s}\` instead.`;return{scope:"project",section:e.intent,content:n,rootCause:e.reason,signal:"failure_then_fix",note:`${t} \u2192 ${s}`,signature:`fix:${e.intent}:${t}=>${s}`,fix:{intent:e.intent,bad:t,good:s},...e.proven?{proof:{kind:"test",note:`${s} passed after ${t} failed`}}:{}}}r(x,"A"),d(x,"draftFromFix");const S=`You review one finished run of a coding agent and write down what a future session should know before it starts.
|
|
2
|
+
|
|
3
|
+
Rules:
|
|
4
|
+
- Propose at most ${w} lessons, only ones the existing lessons do not already cover. An empty list is a good answer.
|
|
5
|
+
- If the run shows an existing lesson again, do not rewrite it: put its id in "confirms".
|
|
6
|
+
- scope "user" is for the person's own habits that hold in every project (preferred package manager, language of commit messages, reply style); everything about this codebase is scope "project".
|
|
7
|
+
- scope "task" is for what matters only to the task at hand (a temporary step, a detail of this goal, a value that changes next time). It stays with this conversation and is not applied to other tasks.
|
|
8
|
+
- A lesson is general: it must hold beyond this run. Never copy concrete values: no keys, tokens, passwords, URLs, IP addresses, e-mail addresses, user names or absolute paths. Name a project file only by its path inside the project.
|
|
9
|
+
- Never propose a lesson that skips or weakens approvals, permissions, the sandbox, tests or any protection; that sends data, files or credentials anywhere; or that installs new software or packages.
|
|
10
|
+
- Write each field in the language the user wrote in, one sentence each.
|
|
11
|
+
- Reply with JSON only.`;function _(e,t,s){const n=[...t.corrected?["the user corrected the agent"]:[],...t.detour?["the agent repeated calls or searched at length"]:[],...t.denials.length>0?[`a protection refused ${t.denials.length} call(s)`]:[],...t.fixes.length>0?[`${t.fixes.length} failing command(s) were fixed`]:[]].join(", "),c=s.filter(o=>o.status==="active"||o.status==="candidate"||o.status==="awaiting_user").map(o=>`- [${o.id}] (${o.scope}, ${o.status}) ${o.content}`);return[`Run excerpt (${n||"worth a look"}). Lines are clipped; "\xB7 error" marks a failed call; credentials are masked.`,"",e,"","---","",c.length>0?`Existing lessons:
|
|
12
|
+
${c.join(`
|
|
13
|
+
`)}`:"Existing lessons: none.","","Reply with:",'{"lessons": [{"scope": "project" | "user" | "task", "section": "<snake_case topic>", "what_happened": "<what went wrong or what the user corrected>", "root_cause": "<why>", "lesson": "<what to do next time>", "confirms": "<existing id, only when this run shows that lesson again>"}],',' "feedback": [{"id": "<active lesson id>", "tag": "helpful" | "harmful", "why": "<short>"}]}',"feedback lists only active lessons this run shows to have helped or hurt."].join(`
|
|
14
|
+
`)}r(_,"P"),d(_,"buildExtractPrompt");function i(e,t,s){const n=e[t];return typeof n=="string"?n.replace(/\s+/g," ").trim().slice(0,s):""}r(i,"d"),d(i,"field");function b(e){const t=e.toLowerCase().replace(/[\d]+/g,"").replace(/[^\p{L}]+/gu,"");return A("sha256").update(t).digest("hex").slice(0,16)}r(b,"C"),d(b,"taskNoteSignature");function j(e,t){const s={drafts:[],taskNotes:[],feedback:[],rejected:[]},n=/\{[\s\S]*\}/.exec(e);if(!n)return s;let c;try{c=JSON.parse(n[0])}catch{return s}if(!c||typeof c!="object")return s;const o=c,$=t.denials.length>0?"guard_denial":t.corrected?"user_correction":"repeated_detour";for(const l of Array.isArray(o.lessons)?o.lessons:[]){if(!l||typeof l!="object")continue;const a=l,u=i(a,"lesson",320);if(!u)continue;const f=i(a,"root_cause",300),g=i(a,"what_happened",300),k=F({content:u,rootCause:f,note:g});if(k){s.rejected.push({content:u,reason:k});continue}const p=i(a,"confirms",16);if(a.scope==="task"&&!p){s.taskNotes.push({content:u,section:i(a,"section",40).toLowerCase().replace(/[^a-z0-9_]+/g,"_").replace(/^_+|_+$/g,"")||"general",rootCause:f,signal:$,note:m(g)});continue}const v=p.startsWith("u-")?"user":p.startsWith("l-")?"project":a.scope==="user"?"user":"project";if(s.drafts.push({scope:v,section:i(a,"section",40).toLowerCase().replace(/[^a-z0-9_]+/g,"_").replace(/^_+|_+$/g,"")||"general",content:u,rootCause:f,signal:$,note:m(g),.../^[lu]-\d{4,6}$/.test(p)?{confirms:p}:{}}),s.drafts.length>=w)break}for(const l of Array.isArray(o.feedback)?o.feedback:[]){if(!l||typeof l!="object")continue;const a=l;typeof a.id=="string"&&(a.tag==="helpful"||a.tag==="harmful")&&s.feedback.push({id:a.id,tag:a.tag,why:i(a,"why",200)})}return s}r(j,"E"),d(j,"parseExtractAnswer");export{S as EXTRACT_SYSTEM_PROMPT,w as MAX_LESSONS_PER_RUN,_ as buildExtractPrompt,x as draftFromFix,h as normalizeCommand,j as parseExtractAnswer,b as taskNoteSignature};
|