@sayknow-cli/coding-agent 0.7.11 → 0.7.12
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 +10 -0
- package/dist/types/async/result-formatting.d.ts +2 -0
- package/dist/types/capability/fs.d.ts +22 -3
- package/dist/types/capability/mcp.d.ts +2 -0
- package/dist/types/cli/append-system-prompt.d.ts +6 -0
- package/dist/types/cli/update-cli.d.ts +3 -0
- package/dist/types/commands/contribution-prep.d.ts +0 -3
- package/dist/types/commands/migrate.d.ts +1 -1
- package/dist/types/commands/sdk.d.ts +9 -0
- package/dist/types/commit/changelog/index.d.ts +1 -0
- package/dist/types/config/settings-schema.d.ts +14 -0
- package/dist/types/config/settings.d.ts +7 -1
- package/dist/types/coordinator-mcp/session-reaper.d.ts +5 -0
- package/dist/types/cursor-delete-path.d.ts +1 -0
- package/dist/types/cursor-mcp-name.d.ts +8 -0
- package/dist/types/dap/config.d.ts +8 -4
- package/dist/types/dap/session.d.ts +11 -2
- package/dist/types/debug/report-bundle-parent.d.ts +2 -0
- package/dist/types/debug/system-info.d.ts +6 -1
- package/dist/types/discovery/helpers.d.ts +11 -3
- package/dist/types/discovery/mcp-json.d.ts +1 -0
- package/dist/types/edit/file-read-cache.d.ts +4 -0
- package/dist/types/edit/modes/patch.d.ts +14 -0
- package/dist/types/edit/modes/replace.d.ts +8 -0
- package/dist/types/eval/py/runtime.d.ts +9 -0
- package/dist/types/exa/mcp-client.d.ts +11 -6
- package/dist/types/exec/bash-executor.d.ts +18 -1
- package/dist/types/export/html/css-color.d.ts +2 -0
- package/dist/types/export/html/html-export-destination.d.ts +2 -0
- package/dist/types/export/html/template.generated.d.ts +1 -1
- package/dist/types/extensibility/custom-tools/loader.d.ts +3 -2
- package/dist/types/extensibility/custom-tools/types.d.ts +3 -1
- package/dist/types/extensibility/plugins/marketplace/cache.d.ts +2 -0
- package/dist/types/extensibility/plugins/plugin-link-path.d.ts +2 -0
- package/dist/types/goals/runtime.d.ts +6 -0
- package/dist/types/harness-control-plane/receipt-spool.d.ts +4 -0
- package/dist/types/hindsight/content.d.ts +5 -6
- package/dist/types/internal-urls/skill-path.d.ts +1 -0
- package/dist/types/internal-urls/types.d.ts +2 -0
- package/dist/types/lsp/clients/swiftlint-client.d.ts +0 -4
- package/dist/types/lsp/config.d.ts +8 -5
- package/dist/types/lsp/workspace-path.d.ts +1 -0
- package/dist/types/migrate/adapters/codex.d.ts +2 -1
- package/dist/types/migrate/adapters/index.d.ts +10 -1
- package/dist/types/migrate/executor.d.ts +3 -1
- package/dist/types/migrate/types.d.ts +15 -3
- package/dist/types/modes/components/custom-editor.d.ts +6 -0
- package/dist/types/modes/components/extensions/state-manager.d.ts +4 -3
- package/dist/types/modes/components/model-selector.d.ts +46 -0
- package/dist/types/modes/controllers/input-controller.d.ts +9 -0
- package/dist/types/modes/interactive-mode.d.ts +1 -0
- package/dist/types/modes/utils/macos-option-forwarding.d.ts +17 -0
- package/dist/types/runtime-mcp/content-limits.d.ts +4 -0
- package/dist/types/runtime-mcp/manager.d.ts +9 -1
- package/dist/types/runtime-mcp/mcp-redirect.d.ts +9 -0
- package/dist/types/runtime-mcp/oauth-public-url.d.ts +1 -0
- package/dist/types/runtime-mcp/plugin-mcp-name-filter.d.ts +22 -0
- package/dist/types/runtime-mcp/plugin-network-boundary.d.ts +1 -0
- package/dist/types/runtime-mcp/project-host-values.d.ts +33 -0
- package/dist/types/runtime-mcp/smithery-registry.d.ts +24 -0
- package/dist/types/runtime-mcp/tool-bridge.d.ts +4 -0
- package/dist/types/runtime-mcp/types.d.ts +6 -0
- package/dist/types/sdk/broker/ensure.d.ts +2 -0
- package/dist/types/sdk/broker/lifecycle-ledger.d.ts +5 -1
- package/dist/types/sdk/broker/runtime.d.ts +1 -1
- package/dist/types/sdk/bus/chat-daemon-control.d.ts +3 -1
- package/dist/types/sdk/bus/telegram-daemon-contract.d.ts +3 -1
- package/dist/types/sdk/bus/telegram-daemon.d.ts +1 -0
- package/dist/types/sdk/host/events.d.ts +4 -0
- package/dist/types/session/agent-session.d.ts +20 -1
- package/dist/types/session/messages.d.ts +5 -1
- package/dist/types/session/session-manager.d.ts +13 -0
- package/dist/types/session/session-storage.d.ts +8 -0
- package/dist/types/session/streaming-output.d.ts +11 -0
- package/dist/types/session-import/redact.d.ts +1 -1
- package/dist/types/skc-runtime/managed-owner-admission.d.ts +3 -0
- package/dist/types/skc-runtime/psmux-detect.d.ts +5 -4
- package/dist/types/skc-runtime/ralplan-runtime.d.ts +5 -0
- package/dist/types/skc-runtime/sidecar-bootstrap-env.d.ts +6 -0
- package/dist/types/skc-runtime/state-writer.d.ts +4 -1
- package/dist/types/skc-runtime/tmux-sessions.d.ts +24 -0
- package/dist/types/skc-runtime/ultragoal-runtime.d.ts +4 -0
- package/dist/types/skill-state/workflow-mutation-guard.d.ts +20 -1
- package/dist/types/slash-commands/helpers/mcp.d.ts +5 -0
- package/dist/types/ssh/ssh-executor.d.ts +3 -1
- package/dist/types/system-prompt.d.ts +5 -2
- package/dist/types/task/executor.d.ts +17 -3
- package/dist/types/task/isolation-dir.d.ts +26 -0
- package/dist/types/task/role-body.d.ts +11 -0
- package/dist/types/task/token-log-mode.test.d.ts +1 -0
- package/dist/types/tools/ask.d.ts +77 -254
- package/dist/types/tools/ast-edit-write-path.d.ts +23 -0
- package/dist/types/tools/atomic-file-write.d.ts +74 -0
- package/dist/types/tools/auto-generated-guard.d.ts +5 -2
- package/dist/types/tools/bash-allowed-prefixes.d.ts +16 -0
- package/dist/types/tools/bash-interactive.d.ts +2 -0
- package/dist/types/tools/bash-skill-urls.d.ts +5 -1
- package/dist/types/tools/bash.d.ts +1 -0
- package/dist/types/tools/browser/cdp-url.d.ts +2 -0
- package/dist/types/tools/browser/tab-worker.d.ts +2 -0
- package/dist/types/tools/debug.d.ts +2 -2
- package/dist/types/tools/explicit-artifact.d.ts +8 -0
- package/dist/types/tools/fetch.d.ts +7 -4
- package/dist/types/tools/github-side-effect.d.ts +22 -0
- package/dist/types/tools/index.d.ts +3 -0
- package/dist/types/tools/monitor-mutation.d.ts +9 -0
- package/dist/types/tools/recipe/index.d.ts +2 -0
- package/dist/types/tools/recipe/recipe-guard.d.ts +7 -0
- package/dist/types/tools/restricted-cwd.d.ts +1 -0
- package/dist/types/tools/reverse-engineer.d.ts +81 -0
- package/dist/types/tools/search-tool-bm25.d.ts +2 -0
- package/dist/types/tools/tmux-self-injection-guard.d.ts +17 -0
- package/dist/types/tools/untrusted-content.d.ts +12 -0
- package/dist/types/utils/file-mentions.d.ts +5 -0
- package/dist/types/utils/open.d.ts +0 -1
- package/dist/types/utils/shell-snapshot.d.ts +2 -0
- package/dist/types/utils/title-generator.d.ts +12 -2
- package/dist/types/utils/tools-checksum.d.ts +7 -0
- package/dist/types/utils/xml-escape.d.ts +2 -0
- package/dist/types/web/scrapers/types.d.ts +8 -1
- package/dist/types/web/search/providers/codex.d.ts +6 -7
- package/dist/types/web/search/providers/insane.d.ts +7 -1
- package/dist/types/web/search/providers/kimi.d.ts +2 -0
- package/dist/types/web/search/providers/searxng.d.ts +7 -0
- package/dist/types/web/search/providers/xai.d.ts +2 -0
- package/package.json +7 -7
- package/scripts/generate-sdk-operation-inventory.ts +4 -0
- package/src/async/job-manager.ts +23 -9
- package/src/async/result-formatting.ts +40 -0
- package/src/capability/fs.ts +78 -11
- package/src/capability/mcp.ts +2 -0
- package/src/cli/append-system-prompt.ts +12 -0
- package/src/cli/auth-broker-cli.ts +22 -12
- package/src/cli/config-cli.ts +8 -18
- package/src/cli/migrate-cli.ts +7 -5
- package/src/cli/ssh-cli.ts +6 -3
- package/src/cli/stats-cli.ts +9 -4
- package/src/cli/update-cli.ts +42 -0
- package/src/cli/web-search-cli.ts +9 -3
- package/src/cli.ts +5 -9
- package/src/commands/commit.ts +2 -2
- package/src/commands/contribution-prep.ts +1 -3
- package/src/commands/harness.ts +25 -15
- package/src/commands/launch.ts +1 -1
- package/src/commands/migrate.ts +3 -3
- package/src/commands/sdk.ts +115 -14
- package/src/commands/ultragoal.ts +14 -8
- package/src/commit/agentic/agent.ts +6 -6
- package/src/commit/analysis/conventional.ts +14 -5
- package/src/commit/changelog/index.ts +39 -1
- package/src/commit/message.ts +10 -3
- package/src/config/config-file.ts +106 -3
- package/src/config/keybindings.ts +154 -7
- package/src/config/mcp-schema.json +4 -0
- package/src/config/model-registry.ts +10 -2
- package/src/config/settings-schema.ts +18 -0
- package/src/config/settings.ts +32 -4
- package/src/coordinator-mcp/policy.ts +14 -4
- package/src/coordinator-mcp/server.ts +44 -4
- package/src/coordinator-mcp/session-reaper.ts +9 -1
- package/src/cursor-delete-path.ts +10 -0
- package/src/cursor-mcp-name.ts +15 -0
- package/src/cursor.ts +13 -2
- package/src/dap/client.ts +9 -2
- package/src/dap/config.ts +33 -13
- package/src/dap/defaults.json +1 -1
- package/src/dap/session.ts +161 -36
- package/src/debug/crash-diagnostics.ts +89 -6
- package/src/debug/report-bundle-parent.ts +22 -0
- package/src/debug/report-bundle.ts +100 -3
- package/src/debug/system-info.ts +21 -4
- package/src/defaults/skc/extensions/grok-cli-vendor/src/shared/base-url.ts +21 -7
- package/src/defaults/skc/skills/deep-interview/SKILL.md +1 -1
- package/src/discovery/agents-md.ts +3 -2
- package/src/discovery/agents.ts +3 -2
- package/src/discovery/builtin.ts +21 -11
- package/src/discovery/claude.ts +5 -4
- package/src/discovery/cline.ts +2 -2
- package/src/discovery/codex.ts +6 -5
- package/src/discovery/cursor.ts +11 -2
- package/src/discovery/gemini.ts +4 -3
- package/src/discovery/github.ts +2 -2
- package/src/discovery/helpers.ts +51 -11
- package/src/discovery/mcp-json.ts +28 -12
- package/src/discovery/opencode.ts +2 -1
- package/src/discovery/ssh.ts +11 -6
- package/src/discovery/substitute-plugin-root.ts +3 -1
- package/src/discovery/vscode.ts +3 -3
- package/src/edit/apply-patch/index.ts +12 -1
- package/src/edit/file-read-cache.ts +24 -6
- package/src/edit/index.ts +90 -20
- package/src/edit/modes/patch.ts +215 -9
- package/src/edit/modes/replace.ts +141 -0
- package/src/eval/js/context-manager.ts +29 -3
- package/src/eval/js/worker-entry.ts +51 -18
- package/src/eval/py/runner.py +144 -5
- package/src/eval/py/runtime.ts +44 -4
- package/src/eval/py/tool-bridge.ts +4 -0
- package/src/exa/mcp-client.ts +53 -11
- package/src/exec/bash-executor.ts +87 -4
- package/src/exec/non-interactive-env.ts +0 -1
- package/src/export/html/css-color.ts +9 -0
- package/src/export/html/html-export-destination.ts +16 -0
- package/src/export/html/index.ts +102 -8
- package/src/export/html/template.generated.ts +1 -1
- package/src/extensibility/custom-tools/loader.ts +13 -3
- package/src/extensibility/custom-tools/types.ts +3 -1
- package/src/extensibility/custom-tools/wrapper.ts +3 -1
- package/src/extensibility/plugins/manager.ts +3 -2
- package/src/extensibility/plugins/marketplace/cache.ts +15 -0
- package/src/extensibility/plugins/marketplace/fetcher.ts +2 -2
- package/src/extensibility/plugins/marketplace/manager.ts +5 -3
- package/src/extensibility/plugins/plugin-link-path.ts +12 -0
- package/src/extensibility/skc-plugins/mcp-policy.ts +2 -1
- package/src/goals/runtime.ts +30 -8
- package/src/harness-control-plane/finalize.ts +10 -0
- package/src/harness-control-plane/operate.ts +12 -4
- package/src/harness-control-plane/owner.ts +8 -1
- package/src/harness-control-plane/receipt-spool.ts +105 -28
- package/src/harness-control-plane/storage.ts +124 -6
- package/src/hashline/execute.ts +3 -3
- package/src/hashline/recovery.ts +85 -2
- package/src/hindsight/config.ts +9 -3
- package/src/hindsight/content.ts +116 -16
- package/src/hindsight/mental-models.ts +22 -10
- package/src/hindsight/state.ts +7 -4
- package/src/hooks/native-skill-hook.ts +17 -12
- package/src/i18n/messages/de.settings.ts +3 -0
- package/src/i18n/messages/es.settings.ts +3 -0
- package/src/i18n/messages/fr.settings.ts +3 -0
- package/src/i18n/messages/ja.settings.ts +3 -0
- package/src/i18n/messages/ko.settings.ts +3 -0
- package/src/i18n/messages/zh.settings.ts +3 -0
- package/src/internal-urls/artifact-protocol.ts +3 -1
- package/src/internal-urls/docs-index.generated.ts +10 -10
- package/src/internal-urls/local-protocol.ts +167 -8
- package/src/internal-urls/skill-path.ts +18 -0
- package/src/internal-urls/skill-protocol.ts +2 -0
- package/src/internal-urls/types.ts +2 -0
- package/src/lsp/client.ts +2 -1
- package/src/lsp/clients/biome-client.ts +2 -0
- package/src/lsp/clients/swiftlint-client.ts +2 -0
- package/src/lsp/config.ts +18 -62
- package/src/lsp/edits.ts +6 -0
- package/src/lsp/index.ts +29 -0
- package/src/lsp/workspace-path.ts +75 -0
- package/src/main.ts +33 -11
- package/src/memories/index.ts +141 -9
- package/src/migrate/action-planner.ts +57 -0
- package/src/migrate/adapters/claude-code.ts +23 -4
- package/src/migrate/adapters/codex.ts +22 -4
- package/src/migrate/adapters/index.ts +22 -4
- package/src/migrate/adapters/opencode.ts +6 -1
- package/src/migrate/executor.ts +84 -7
- package/src/migrate/report.ts +19 -2
- package/src/migrate/types.ts +14 -4
- package/src/modes/DESIGN.md +5 -0
- package/src/modes/acp/acp-agent.ts +35 -2
- package/src/modes/acp/permission-mode.ts +18 -1
- package/src/modes/components/custom-editor.ts +14 -0
- package/src/modes/components/extensions/extension-dashboard.ts +2 -2
- package/src/modes/components/extensions/inspector-panel.ts +9 -5
- package/src/modes/components/extensions/state-manager.ts +15 -5
- package/src/modes/components/model-selector.ts +144 -94
- package/src/modes/components/welcome.ts +3 -2
- package/src/modes/controllers/command-controller.ts +300 -9
- package/src/modes/controllers/event-controller.ts +1 -1
- package/src/modes/controllers/extension-ui-controller.ts +32 -19
- package/src/modes/controllers/input-controller.ts +62 -26
- package/src/modes/controllers/plan-mode-controller.ts +17 -7
- package/src/modes/controllers/runtime-mcp-command-controller.ts +25 -20
- package/src/modes/controllers/ssh-command-controller.ts +3 -1
- package/src/modes/interactive-mode.ts +10 -0
- package/src/modes/utils/macos-option-forwarding.ts +80 -0
- package/src/prompts/system/irc-incoming.md +3 -1
- package/src/prompts/system/project-prompt.md +19 -0
- package/src/prompts/system/system-prompt.md +3 -0
- package/src/prompts/tools/ask.md +2 -0
- package/src/prompts/tools/debug.md +1 -1
- package/src/prompts/tools/monitor.md +7 -5
- package/src/prompts/tools/reverse-engineer.md +29 -0
- package/src/runtime-credential-selector.ts +2 -2
- package/src/runtime-mcp/config-writer.ts +10 -6
- package/src/runtime-mcp/config.ts +1 -0
- package/src/runtime-mcp/content-limits.ts +7 -0
- package/src/runtime-mcp/json-rpc.ts +2 -1
- package/src/runtime-mcp/manager.ts +57 -9
- package/src/runtime-mcp/mcp-redirect.ts +73 -0
- package/src/runtime-mcp/oauth-flow.ts +43 -5
- package/src/runtime-mcp/oauth-public-url.ts +8 -0
- package/src/runtime-mcp/plugin-mcp-name-filter.ts +62 -0
- package/src/runtime-mcp/plugin-network-boundary.ts +4 -0
- package/src/runtime-mcp/project-host-values.ts +50 -0
- package/src/runtime-mcp/render.ts +16 -1
- package/src/runtime-mcp/smithery-registry.ts +22 -3
- package/src/runtime-mcp/tool-bridge.ts +194 -21
- package/src/runtime-mcp/transports/http.ts +4 -3
- package/src/runtime-mcp/transports/stdio.ts +2 -1
- package/src/runtime-mcp/types.ts +6 -0
- package/src/sdk/broker/broker.ts +11 -2
- package/src/sdk/broker/ensure.ts +131 -10
- package/src/sdk/broker/lifecycle-ledger.ts +18 -3
- package/src/sdk/broker/lifecycle.ts +21 -19
- package/src/sdk/broker/runtime.ts +1 -1
- package/src/sdk/bus/chat-daemon-cli.ts +38 -1
- package/src/sdk/bus/chat-daemon-control.ts +5 -3
- package/src/sdk/bus/index.ts +5 -3
- package/src/sdk/bus/lifecycle-control-runtime.ts +9 -2
- package/src/sdk/bus/session-control.ts +2 -0
- package/src/sdk/bus/slack-daemon.ts +8 -1
- package/src/sdk/bus/slack-live-provider.ts +3 -1
- package/src/sdk/bus/telegram-daemon-contract.ts +3 -1
- package/src/sdk/bus/telegram-daemon-control.ts +17 -12
- package/src/sdk/bus/telegram-daemon.ts +41 -1
- package/src/sdk/host/events.ts +67 -4
- package/src/sdk/mcp/server.ts +16 -3
- package/src/sdk/protocol/operation-inventory.generated.json +22 -0
- package/src/sdk/session.ts +18 -25
- package/src/secrets/obfuscator.ts +92 -12
- package/src/session/agent-session.ts +395 -79
- package/src/session/artifacts.ts +3 -1
- package/src/session/history-storage.ts +172 -8
- package/src/session/internal/managed-session-scope.ts +130 -52
- package/src/session/messages.ts +47 -6
- package/src/session/session-manager.ts +116 -8
- package/src/session/session-storage.ts +31 -1
- package/src/session/streaming-output.ts +263 -4
- package/src/session-import/redact.ts +76 -3
- package/src/setup/hermes-setup.ts +4 -1
- package/src/skc-runtime/gc-runtime.ts +26 -4
- package/src/skc-runtime/launch-tmux.ts +21 -11
- package/src/skc-runtime/launch-worktree.ts +42 -3
- package/src/skc-runtime/managed-owner-admission.ts +46 -2
- package/src/skc-runtime/psmux-detect.ts +29 -5
- package/src/skc-runtime/ralplan-runtime.ts +14 -1
- package/src/skc-runtime/session-resolution.ts +38 -6
- package/src/skc-runtime/sidecar-bootstrap-env.ts +19 -0
- package/src/skc-runtime/state-writer.ts +134 -16
- package/src/skc-runtime/tmux-sessions.ts +85 -4
- package/src/skc-runtime/ultragoal-change-set.ts +18 -2
- package/src/skc-runtime/ultragoal-guard.ts +9 -1
- package/src/skc-runtime/ultragoal-runtime.ts +26 -9
- package/src/skill-state/active-state.ts +13 -0
- package/src/skill-state/workflow-mutation-guard.ts +3297 -180
- package/src/slash-commands/builtin-registry.ts +14 -8
- package/src/slash-commands/helpers/mcp.ts +20 -7
- package/src/ssh/ssh-executor.ts +3 -1
- package/src/stt/recorder.ts +26 -9
- package/src/system-prompt.ts +65 -16
- package/src/task/commands.ts +3 -1
- package/src/task/executor.ts +52 -7
- package/src/task/index.ts +28 -0
- package/src/task/isolation-dir.ts +143 -0
- package/src/task/role-body.ts +84 -0
- package/src/task/token-log-mode.test.ts +162 -0
- package/src/task/token-log.ts +91 -2
- package/src/task/worktree.ts +16 -7
- package/src/tools/archive-reader.ts +653 -31
- package/src/tools/ask.ts +86 -14
- package/src/tools/ast-edit-write-path.ts +133 -0
- package/src/tools/ast-edit.ts +27 -1
- package/src/tools/ast-grep.ts +7 -2
- package/src/tools/atomic-file-write.ts +625 -0
- package/src/tools/auto-generated-guard.ts +28 -8
- package/src/tools/bash-allowed-prefixes.ts +225 -6
- package/src/tools/bash-interactive.ts +12 -0
- package/src/tools/bash-skill-urls.ts +113 -7
- package/src/tools/bash.ts +152 -20
- package/src/tools/browser/cdp-url.ts +18 -0
- package/src/tools/browser/tab-worker.ts +49 -14
- package/src/tools/browser.ts +25 -8
- package/src/tools/cron.ts +10 -1
- package/src/tools/debug.ts +16 -8
- package/src/tools/eval.ts +71 -34
- package/src/tools/explicit-artifact.ts +89 -0
- package/src/tools/fetch.ts +26 -17
- package/src/tools/gh.ts +40 -12
- package/src/tools/github-side-effect.ts +112 -0
- package/src/tools/image-gen.ts +24 -10
- package/src/tools/index.ts +6 -0
- package/src/tools/monitor-mutation.ts +27 -0
- package/src/tools/monitor.ts +28 -1
- package/src/tools/output-meta.ts +74 -5
- package/src/tools/read.ts +24 -36
- package/src/tools/recipe/index.ts +12 -0
- package/src/tools/recipe/recipe-guard.ts +19 -0
- package/src/tools/recipe/runner.ts +23 -12
- package/src/tools/render-utils.ts +2 -2
- package/src/tools/restricted-cwd.ts +10 -0
- package/src/tools/reverse-engineer.ts +497 -0
- package/src/tools/search-tool-bm25.ts +14 -3
- package/src/tools/search.ts +3 -2
- package/src/tools/ssh.ts +235 -8
- package/src/tools/subagent-render.ts +43 -7
- package/src/tools/subagent.ts +7 -3
- package/src/tools/tmux-self-injection-guard.ts +3538 -0
- package/src/tools/todo-write.ts +41 -3
- package/src/tools/untrusted-content.ts +23 -0
- package/src/tools/vim.ts +2 -2
- package/src/tools/write.ts +37 -4
- package/src/tui/tree-list.ts +15 -1
- package/src/utils/commit-message-generator.ts +9 -2
- package/src/utils/external-editor.ts +21 -7
- package/src/utils/file-mentions.ts +75 -7
- package/src/utils/git.ts +38 -7
- package/src/utils/open.ts +73 -4
- package/src/utils/shell-snapshot.ts +9 -1
- package/src/utils/title-generator.ts +61 -16
- package/src/utils/tools-checksum.ts +34 -0
- package/src/utils/tools-manager.ts +24 -6
- package/src/utils/xml-escape.ts +14 -0
- package/src/web/insane/url-guard.ts +2 -1
- package/src/web/scrapers/types.ts +8 -0
- package/src/web/scrapers/youtube.ts +3 -2
- package/src/web/search/index.ts +4 -3
- package/src/web/search/providers/anthropic.ts +4 -4
- package/src/web/search/providers/codex.ts +31 -34
- package/src/web/search/providers/insane.ts +145 -28
- package/src/web/search/providers/kimi.ts +15 -5
- package/src/web/search/providers/searxng.ts +47 -4
- package/src/web/search/providers/xai.ts +7 -2
- package/dist/types/cli/shell-cli.d.ts +0 -8
- package/dist/types/commands/shell.d.ts +0 -21
- package/src/cli/shell-cli.ts +0 -176
- package/src/commands/shell.ts +0 -29
|
@@ -146,6 +146,109 @@ async function assertDirectoryNotSymlink(directoryPath: string): Promise<void> {
|
|
|
146
146
|
}
|
|
147
147
|
}
|
|
148
148
|
|
|
149
|
+
/** Group-write and world-write bits. Either one lets another user rename the session directory. */
|
|
150
|
+
const GROUP_OR_WORLD_WRITABLE = 0o022;
|
|
151
|
+
|
|
152
|
+
interface DirectoryIdentityStat {
|
|
153
|
+
isDirectory(): boolean;
|
|
154
|
+
isSymbolicLink(): boolean;
|
|
155
|
+
dev: number;
|
|
156
|
+
ino: number;
|
|
157
|
+
uid: number;
|
|
158
|
+
mode: number;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
interface ManagedRootIdentity {
|
|
162
|
+
readonly dev: number;
|
|
163
|
+
readonly ino: number;
|
|
164
|
+
readonly uid: number;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function isUnsafeDirectory(stat: DirectoryIdentityStat): boolean {
|
|
168
|
+
return !stat.isDirectory() || stat.isSymbolicLink();
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function managedRootIdentity(stat: DirectoryIdentityStat): ManagedRootIdentity {
|
|
172
|
+
return { dev: stat.dev, ino: stat.ino, uid: stat.uid };
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function sameManagedRoot(stat: DirectoryIdentityStat, recorded: ManagedRootIdentity): boolean {
|
|
176
|
+
if (isUnsafeDirectory(stat) || stat.dev !== recorded.dev || stat.ino !== recorded.ino) return false;
|
|
177
|
+
// A later chmod to 0755 keeps the same directory. Only a writable bit, a new
|
|
178
|
+
// inode, or a different owner means the root was replaced or opened up.
|
|
179
|
+
if (process.platform === "win32") return true;
|
|
180
|
+
return stat.uid === recorded.uid && (stat.mode & GROUP_OR_WORLD_WRITABLE) === 0;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* An existing managed session directory is adopted only when this user owns it
|
|
185
|
+
* and the group and world cannot write it. Windows has no POSIX owner bits.
|
|
186
|
+
*/
|
|
187
|
+
function assertAdoptedManagedRoot(stat: DirectoryIdentityStat): void {
|
|
188
|
+
if (isUnsafeDirectory(stat)) throw new Error("Unsafe local:// root");
|
|
189
|
+
if (process.platform === "win32") return;
|
|
190
|
+
const uid = process.getuid?.();
|
|
191
|
+
if (uid === undefined || stat.uid !== uid || (stat.mode & GROUP_OR_WORLD_WRITABLE) !== 0) {
|
|
192
|
+
throw new Error("Unsafe local:// root");
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function assertManagedParentSync(localRoot: string): void {
|
|
197
|
+
let parentStat: fsSync.Stats;
|
|
198
|
+
try {
|
|
199
|
+
parentStat = fsSync.lstatSync(path.dirname(localRoot));
|
|
200
|
+
} catch {
|
|
201
|
+
throw new Error("Unsafe local:// root");
|
|
202
|
+
}
|
|
203
|
+
assertAdoptedManagedRoot(parentStat);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Keep a pinned root unless a changed inode is validated as a settled
|
|
208
|
+
* recreation. A root created by this call may be rebound after migration.
|
|
209
|
+
*/
|
|
210
|
+
function acceptManagedRootForInit(
|
|
211
|
+
localRoot: string,
|
|
212
|
+
rootStat: DirectoryIdentityStat,
|
|
213
|
+
recorded: ManagedRootIdentity | undefined,
|
|
214
|
+
adoptedExisting: boolean,
|
|
215
|
+
): void {
|
|
216
|
+
if (recorded && adoptedExisting) {
|
|
217
|
+
if (sameManagedRoot(rootStat, recorded)) return;
|
|
218
|
+
const pending = pendingCreatedRoots.get(localRoot);
|
|
219
|
+
if (pending && sameManagedRoot(rootStat, pending)) return;
|
|
220
|
+
if (isSettledRecreatedManagedRoot(localRoot, rootStat)) return;
|
|
221
|
+
throw new Error("Unsafe local:// root");
|
|
222
|
+
}
|
|
223
|
+
if (recorded || adoptedExisting) {
|
|
224
|
+
assertAdoptedManagedRoot(rootStat);
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
if (isUnsafeDirectory(rootStat)) throw new Error("Unsafe local:// root");
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* A pinned root whose inode changed is still ours when a skc initializer
|
|
232
|
+
* completed it: the temp sweeper (or `skc gc`) removed the directory and
|
|
233
|
+
* another process for the same session recreated it, writing a settled
|
|
234
|
+
* migration marker. POSIX owner and write-bit checks on the root and parent
|
|
235
|
+
* protect this exception. Windows changed-inode adoption stays fail-closed
|
|
236
|
+
* until this path validates the replacement's identity and ACLs.
|
|
237
|
+
*/
|
|
238
|
+
function isSettledRecreatedManagedRoot(localRoot: string, rootStat: DirectoryIdentityStat): boolean {
|
|
239
|
+
if (process.platform === "win32") return false;
|
|
240
|
+
try {
|
|
241
|
+
assertAdoptedManagedRoot(rootStat);
|
|
242
|
+
assertManagedParentSync(localRoot);
|
|
243
|
+
const marker = path.join(localRoot, LEGACY_MIGRATION_MARKER);
|
|
244
|
+
const markerStat = fsSync.lstatSync(marker);
|
|
245
|
+
if (!markerStat.isFile() || markerStat.isSymbolicLink()) return false;
|
|
246
|
+
return isSettledMigrationMarkerValue(fsSync.readFileSync(marker, "utf8"));
|
|
247
|
+
} catch {
|
|
248
|
+
return false;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
149
252
|
const LEGACY_MIGRATION_MARKER = ".skc-local-legacy-migrated-v1";
|
|
150
253
|
const MAX_LEGACY_LOCAL_BYTES = 64 * 1024 * 1024;
|
|
151
254
|
|
|
@@ -475,7 +578,31 @@ async function migrateLegacyLocal(
|
|
|
475
578
|
}
|
|
476
579
|
}
|
|
477
580
|
|
|
478
|
-
const initializedLocalRoots = new
|
|
581
|
+
const initializedLocalRoots = new Map<string, ManagedRootIdentity>();
|
|
582
|
+
/** A directory this process created and has not finished migrating. */
|
|
583
|
+
const pendingCreatedRoots = new Map<string, ManagedRootIdentity>();
|
|
584
|
+
|
|
585
|
+
function assertRememberedManagedRoot(localRoot: string, recorded: ManagedRootIdentity): void {
|
|
586
|
+
let stat: fsSync.Stats;
|
|
587
|
+
try {
|
|
588
|
+
stat = fsSync.lstatSync(localRoot);
|
|
589
|
+
} catch {
|
|
590
|
+
throw new Error("Unsafe local:// root");
|
|
591
|
+
}
|
|
592
|
+
if (!sameManagedRoot(stat, recorded)) throw new Error("Unsafe local:// root");
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
function rememberManagedRoot(localRoot: string, expected: ManagedRootIdentity): void {
|
|
596
|
+
let stat: fsSync.Stats;
|
|
597
|
+
try {
|
|
598
|
+
stat = fsSync.lstatSync(localRoot);
|
|
599
|
+
} catch {
|
|
600
|
+
throw new Error("Unsafe local:// root");
|
|
601
|
+
}
|
|
602
|
+
if (!sameManagedRoot(stat, expected)) throw new Error("Unsafe local:// root");
|
|
603
|
+
initializedLocalRoots.set(localRoot, managedRootIdentity(stat));
|
|
604
|
+
pendingCreatedRoots.delete(localRoot);
|
|
605
|
+
}
|
|
479
606
|
|
|
480
607
|
/**
|
|
481
608
|
* Completes the mandatory legacy migration gate for a local root.
|
|
@@ -513,16 +640,21 @@ export async function initializeLocalRoot(options: LocalProtocolOptions): Promis
|
|
|
513
640
|
|
|
514
641
|
await fs.mkdir(scratchParent, { recursive: true, mode: 0o700 });
|
|
515
642
|
await assertDirectoryNotSymlink(scratchParent);
|
|
643
|
+
assertAdoptedManagedRoot(await fs.lstat(scratchParent));
|
|
644
|
+
let adoptedExisting = false;
|
|
516
645
|
try {
|
|
517
646
|
await fs.mkdir(localRoot, { mode: 0o700 });
|
|
518
647
|
} catch (error) {
|
|
519
648
|
if (error instanceof Error && "code" in error && error.code === "EEXIST") {
|
|
520
|
-
|
|
649
|
+
adoptedExisting = true;
|
|
521
650
|
} else {
|
|
522
651
|
throw error;
|
|
523
652
|
}
|
|
524
653
|
}
|
|
525
|
-
await
|
|
654
|
+
const rootStat = await fs.lstat(localRoot);
|
|
655
|
+
const recorded = initializedLocalRoots.get(localRoot);
|
|
656
|
+
acceptManagedRootForInit(localRoot, rootStat, recorded, adoptedExisting);
|
|
657
|
+
if (!adoptedExisting) pendingCreatedRoots.set(localRoot, managedRootIdentity(rootStat));
|
|
526
658
|
await migrateLegacyLocal(options, localRoot, scratchParent);
|
|
527
659
|
|
|
528
660
|
const resolvedScratchParent = await fs.realpath(scratchParent);
|
|
@@ -531,7 +663,10 @@ export async function initializeLocalRoot(options: LocalProtocolOptions): Promis
|
|
|
531
663
|
if (resolvedLocalRoot === resolvedScratchParent) {
|
|
532
664
|
throw new Error("Unsafe local:// root");
|
|
533
665
|
}
|
|
534
|
-
|
|
666
|
+
// Key the lexical path the sync resolver checks. realpath(/var -> /private/var)
|
|
667
|
+
// is a different string for the same directory, so caching only the real path
|
|
668
|
+
// let a later rename-swap skip this identity check.
|
|
669
|
+
rememberManagedRoot(localRoot, managedRootIdentity(rootStat));
|
|
535
670
|
return resolvedLocalRoot;
|
|
536
671
|
}
|
|
537
672
|
|
|
@@ -541,18 +676,41 @@ function initializeLocalRootSyncWhenLegacyAbsent(options: LocalProtocolOptions,
|
|
|
541
676
|
initializeExplicitLocalRootSync(explicitRoot);
|
|
542
677
|
return;
|
|
543
678
|
}
|
|
544
|
-
|
|
679
|
+
const recorded = initializedLocalRoots.get(localRoot);
|
|
680
|
+
if (recorded) {
|
|
681
|
+
assertManagedParentSync(localRoot);
|
|
682
|
+
let present: fsSync.Stats | undefined;
|
|
683
|
+
try {
|
|
684
|
+
present = fsSync.lstatSync(localRoot);
|
|
685
|
+
} catch (error) {
|
|
686
|
+
if (!isEnoent(error)) throw new Error("Unsafe local:// root");
|
|
687
|
+
}
|
|
688
|
+
if (present) {
|
|
689
|
+
if (sameManagedRoot(present, recorded)) {
|
|
690
|
+
assertRememberedManagedRoot(localRoot, recorded);
|
|
691
|
+
return;
|
|
692
|
+
}
|
|
693
|
+
const pending = pendingCreatedRoots.get(localRoot);
|
|
694
|
+
if (!(pending && sameManagedRoot(present, pending)) && !isSettledRecreatedManagedRoot(localRoot, present)) {
|
|
695
|
+
throw new Error("Unsafe local:// root");
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
}
|
|
545
699
|
const scratchParent = path.dirname(localRoot);
|
|
546
700
|
fsSync.mkdirSync(scratchParent, { recursive: true, mode: 0o700 });
|
|
547
701
|
const parentStat = fsSync.lstatSync(scratchParent);
|
|
548
702
|
if (!parentStat.isDirectory() || parentStat.isSymbolicLink()) throw new Error("Unsafe local:// root");
|
|
703
|
+
assertAdoptedManagedRoot(parentStat);
|
|
704
|
+
let adoptedExisting = false;
|
|
549
705
|
try {
|
|
550
706
|
fsSync.mkdirSync(localRoot, { mode: 0o700 });
|
|
551
707
|
} catch (error) {
|
|
552
708
|
if ((error as NodeJS.ErrnoException).code !== "EEXIST") throw error;
|
|
709
|
+
adoptedExisting = true;
|
|
553
710
|
}
|
|
554
711
|
const rootStat = fsSync.lstatSync(localRoot);
|
|
555
|
-
|
|
712
|
+
acceptManagedRootForInit(localRoot, rootStat, recorded, adoptedExisting);
|
|
713
|
+
if (!adoptedExisting) pendingCreatedRoots.set(localRoot, managedRootIdentity(rootStat));
|
|
556
714
|
const marker = path.join(localRoot, LEGACY_MIGRATION_MARKER);
|
|
557
715
|
try {
|
|
558
716
|
// Accept exactly the marker states the async gate treats as settled. A
|
|
@@ -562,7 +720,7 @@ function initializeLocalRootSyncWhenLegacyAbsent(options: LocalProtocolOptions,
|
|
|
562
720
|
// async gate had already completed.
|
|
563
721
|
if (!isSettledMigrationMarkerValue(fsSync.readFileSync(marker, "utf8")))
|
|
564
722
|
throw new Error("Unsafe local:// migration marker");
|
|
565
|
-
|
|
723
|
+
rememberManagedRoot(localRoot, managedRootIdentity(rootStat));
|
|
566
724
|
return;
|
|
567
725
|
} catch (error) {
|
|
568
726
|
if (!isEnoent(error)) throw error;
|
|
@@ -583,7 +741,7 @@ function initializeLocalRootSyncWhenLegacyAbsent(options: LocalProtocolOptions,
|
|
|
583
741
|
if (!isSettledMigrationMarkerValue(fsSync.readFileSync(marker, "utf8")))
|
|
584
742
|
throw new Error("Unsafe local:// migration marker");
|
|
585
743
|
}
|
|
586
|
-
|
|
744
|
+
rememberManagedRoot(localRoot, managedRootIdentity(rootStat));
|
|
587
745
|
}
|
|
588
746
|
|
|
589
747
|
export function resolveLocalRoot(options: LocalProtocolOptions): string {
|
|
@@ -650,6 +808,7 @@ export class LocalProtocolHandler implements ProtocolHandler {
|
|
|
650
808
|
LocalProtocolHandler.#override = undefined;
|
|
651
809
|
LocalProtocolHandler.#ownedOverrides = [];
|
|
652
810
|
initializedLocalRoots.clear();
|
|
811
|
+
pendingCreatedRoots.clear();
|
|
653
812
|
}
|
|
654
813
|
|
|
655
814
|
/**
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import * as fs from "node:fs/promises";
|
|
2
|
+
import * as path from "node:path";
|
|
3
|
+
import { isEnoent } from "@sayknow-cli/utils";
|
|
4
|
+
|
|
5
|
+
export async function realSkillPath(baseDir: string, targetPath: string): Promise<string> {
|
|
6
|
+
const realBase = await fs.realpath(baseDir);
|
|
7
|
+
let realTarget: string;
|
|
8
|
+
try {
|
|
9
|
+
realTarget = await fs.realpath(targetPath);
|
|
10
|
+
} catch (error) {
|
|
11
|
+
if (isEnoent(error)) throw new Error(`File not found: ${targetPath}`);
|
|
12
|
+
throw error;
|
|
13
|
+
}
|
|
14
|
+
if (realTarget !== realBase && !realTarget.startsWith(realBase + path.sep)) {
|
|
15
|
+
throw new Error("Path traversal is not allowed");
|
|
16
|
+
}
|
|
17
|
+
return realTarget;
|
|
18
|
+
}
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
*/
|
|
10
10
|
import * as path from "node:path";
|
|
11
11
|
import { getActiveSkills } from "../extensibility/skills";
|
|
12
|
+
import { realSkillPath } from "./skill-path";
|
|
12
13
|
import type { InternalResource, InternalUrl, ProtocolHandler } from "./types";
|
|
13
14
|
|
|
14
15
|
function getContentType(filePath: string): InternalResource["contentType"] {
|
|
@@ -70,6 +71,7 @@ export class SkillProtocolHandler implements ProtocolHandler {
|
|
|
70
71
|
if (!resolvedPath.startsWith(resolvedBaseDir + path.sep) && resolvedPath !== resolvedBaseDir) {
|
|
71
72
|
throw new Error("Path traversal is not allowed");
|
|
72
73
|
}
|
|
74
|
+
targetPath = await realSkillPath(skill.baseDir, targetPath);
|
|
73
75
|
} else {
|
|
74
76
|
targetPath = skill.filePath;
|
|
75
77
|
}
|
|
@@ -21,6 +21,8 @@ export interface InternalResource {
|
|
|
21
21
|
size?: number;
|
|
22
22
|
/** Underlying filesystem path (for debugging, not exposed to agent) */
|
|
23
23
|
sourcePath?: string;
|
|
24
|
+
/** True when model-facing reads must wrap the selected content as untrusted. */
|
|
25
|
+
untrusted?: boolean;
|
|
24
26
|
/** Additional notes about resolution */
|
|
25
27
|
notes?: string[];
|
|
26
28
|
/**
|
package/src/lsp/client.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { isEnoent, isKnownSinkPeerClosedError, logger, untilAborted } from "@sayknow-cli/utils";
|
|
2
|
+
import { projectSafeSpawnEnv } from "@sayknow-cli/utils/shell-config";
|
|
2
3
|
import { formatCrashDiagnosticNotice, writeCrashReport } from "../debug/crash-diagnostics";
|
|
3
4
|
import { registerResourceOwner, spawnOwnedProcess } from "../runtime/process-lifecycle";
|
|
4
5
|
import { ToolAbortError, throwIfAborted } from "../tools/tool-errors";
|
|
@@ -514,7 +515,7 @@ export async function getOrCreateClient(config: ServerConfig, cwd: string, initT
|
|
|
514
515
|
const owner = spawnOwnedProcess([command, ...args], {
|
|
515
516
|
cwd,
|
|
516
517
|
stdin: "pipe",
|
|
517
|
-
env:
|
|
518
|
+
env: { ...projectSafeSpawnEnv(), ...env },
|
|
518
519
|
name: `lsp:${config.command}`,
|
|
519
520
|
});
|
|
520
521
|
const proc = owner.child;
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* Uses Biome's CLI with JSON output instead of LSP (which has stale diagnostics issues).
|
|
4
4
|
*/
|
|
5
5
|
import path from "node:path";
|
|
6
|
+
import { projectSafeSpawnEnv } from "@sayknow-cli/utils/shell-config";
|
|
6
7
|
import type { Diagnostic, DiagnosticSeverity, LinterClient, ServerConfig } from "../../lsp/types";
|
|
7
8
|
|
|
8
9
|
// =============================================================================
|
|
@@ -84,6 +85,7 @@ async function runBiome(
|
|
|
84
85
|
try {
|
|
85
86
|
const proc = Bun.spawn([command, ...args], {
|
|
86
87
|
cwd,
|
|
88
|
+
env: projectSafeSpawnEnv(),
|
|
87
89
|
stdout: "pipe",
|
|
88
90
|
stderr: "pipe",
|
|
89
91
|
windowsHide: true,
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* SwiftLint CLI-based linter client.
|
|
3
3
|
* Parses SwiftLint's JSON reporter output into LSP Diagnostic format.
|
|
4
4
|
*/
|
|
5
|
+
import { projectSafeSpawnEnv } from "@sayknow-cli/utils/shell-config";
|
|
5
6
|
import type { Diagnostic, DiagnosticSeverity, LinterClient, ServerConfig } from "../../lsp/types";
|
|
6
7
|
|
|
7
8
|
/** Shape of a single violation from `swiftlint lint --reporter json`. */
|
|
@@ -36,6 +37,7 @@ async function runSwiftLint(
|
|
|
36
37
|
try {
|
|
37
38
|
const proc = Bun.spawn([command, ...args], {
|
|
38
39
|
cwd,
|
|
40
|
+
env: projectSafeSpawnEnv(),
|
|
39
41
|
stdout: "pipe",
|
|
40
42
|
stderr: "pipe",
|
|
41
43
|
windowsHide: true,
|
package/src/lsp/config.ts
CHANGED
|
@@ -275,74 +275,30 @@ export function hasRootMarkers(cwd: string, markers: string[]): boolean {
|
|
|
275
275
|
}
|
|
276
276
|
|
|
277
277
|
// =============================================================================
|
|
278
|
-
//
|
|
278
|
+
// Trusted executable resolution
|
|
279
279
|
// =============================================================================
|
|
280
280
|
|
|
281
281
|
/**
|
|
282
|
-
*
|
|
283
|
-
*
|
|
284
|
-
*/
|
|
285
|
-
const LOCAL_BIN_PATHS: Array<{ markers: string[]; binDir: string }> = [
|
|
286
|
-
// Node.js - check node_modules/.bin/
|
|
287
|
-
{ markers: ["package.json", "package-lock.json", "yarn.lock", "pnpm-lock.yaml"], binDir: "node_modules/.bin" },
|
|
288
|
-
// Python - check virtual environment bin directories
|
|
289
|
-
{ markers: ["pyproject.toml", "requirements.txt", "setup.py", "Pipfile"], binDir: ".venv/bin" },
|
|
290
|
-
{ markers: ["pyproject.toml", "requirements.txt", "setup.py", "Pipfile"], binDir: "venv/bin" },
|
|
291
|
-
{ markers: ["pyproject.toml", "requirements.txt", "setup.py", "Pipfile"], binDir: ".env/bin" },
|
|
292
|
-
// Ruby - check vendor bundle and binstubs
|
|
293
|
-
{ markers: ["Gemfile", "Gemfile.lock"], binDir: "vendor/bundle/bin" },
|
|
294
|
-
{ markers: ["Gemfile", "Gemfile.lock"], binDir: "bin" },
|
|
295
|
-
// Go - check project-local bin
|
|
296
|
-
{ markers: ["go.mod", "go.sum"], binDir: "bin" },
|
|
297
|
-
];
|
|
298
|
-
|
|
299
|
-
const WINDOWS_LOCAL_EXECUTABLE_EXTENSIONS = [".exe", ".cmd", ".bat"] as const;
|
|
300
|
-
|
|
301
|
-
function resolveLocalCommand(basePath: string): string | null {
|
|
302
|
-
if (fs.existsSync(basePath)) return basePath;
|
|
303
|
-
if (process.platform !== "win32") return null;
|
|
304
|
-
|
|
305
|
-
// Package managers write Windows launchers with executable suffixes in node_modules/.bin.
|
|
306
|
-
for (const extension of WINDOWS_LOCAL_EXECUTABLE_EXTENSIONS) {
|
|
307
|
-
const candidate = `${basePath}${extension}`;
|
|
308
|
-
if (fs.existsSync(candidate)) return candidate;
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
return null;
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
/**
|
|
315
|
-
* Resolve a command to an executable path.
|
|
316
|
-
* Checks project-local bin directories first, then falls back to $PATH.
|
|
282
|
+
* Resolve a host-spawn executable from $PATH without consulting project-controlled bin directories.
|
|
283
|
+
* LSP auto-detection and DAP adapter launch both use this rule.
|
|
317
284
|
*
|
|
318
|
-
*
|
|
319
|
-
*
|
|
320
|
-
*
|
|
285
|
+
* Trust is evaluated on both the discovered and canonical paths, but the returned
|
|
286
|
+
* path is the discovered one: multiplexed launchers such as rustup pick the proxied
|
|
287
|
+
* tool from argv[0], so `~/.cargo/bin/rust-analyzer -> rustup` must be spawned as
|
|
288
|
+
* `rust-analyzer`, not as the resolved `rustup` binary.
|
|
321
289
|
*/
|
|
322
|
-
export function
|
|
323
|
-
// Check local bin directories based on project markers
|
|
324
|
-
for (const { markers, binDir } of LOCAL_BIN_PATHS) {
|
|
325
|
-
if (hasRootMarkers(cwd, markers)) {
|
|
326
|
-
const localPath = path.join(cwd, binDir, command);
|
|
327
|
-
const resolvedLocalPath = resolveLocalCommand(localPath);
|
|
328
|
-
if (resolvedLocalPath) {
|
|
329
|
-
return resolvedLocalPath;
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
// Fall back to $PATH
|
|
335
|
-
return $which(command);
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
/** Resolve an LSP executable without consulting project-controlled bin directories. */
|
|
339
|
-
function resolveTrustedLspCommand(command: string, cwd: string): string | null {
|
|
290
|
+
export function resolveTrustedCommand(command: string, cwd: string): string | null {
|
|
340
291
|
if (!path.isAbsolute(command) && (command.includes("/") || command.includes("\\"))) return null;
|
|
341
292
|
const discovered = path.isAbsolute(command) ? command : $which(command);
|
|
342
293
|
if (!discovered) return null;
|
|
343
294
|
if (isProjectControlledPath(discovered, cwd)) return null;
|
|
344
|
-
|
|
345
|
-
return
|
|
295
|
+
if (!canonicalExistingPath(discovered)) return null;
|
|
296
|
+
return discovered;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/** Same rule as `resolveTrustedCommand`: project-local bin directories are never searched. */
|
|
300
|
+
export function resolveCommand(command: string, cwd: string): string | null {
|
|
301
|
+
return resolveTrustedCommand(command, cwd);
|
|
346
302
|
}
|
|
347
303
|
|
|
348
304
|
interface ConfigSource {
|
|
@@ -548,8 +504,8 @@ export function loadConfig(cwd: string): LspConfig {
|
|
|
548
504
|
// Check if project has root markers for this language
|
|
549
505
|
if (!hasRootMarkers(cwd, config.rootMarkers)) continue;
|
|
550
506
|
|
|
551
|
-
// Check if
|
|
552
|
-
const resolved =
|
|
507
|
+
// Check if a trusted language server binary is available on $PATH.
|
|
508
|
+
const resolved = resolveTrustedCommand(config.command, cwd);
|
|
553
509
|
if (!resolved) continue;
|
|
554
510
|
|
|
555
511
|
detected[name] = { ...config, resolvedCommand: resolved };
|
|
@@ -564,7 +520,7 @@ export function loadConfig(cwd: string): LspConfig {
|
|
|
564
520
|
for (const [name, config] of Object.entries(mergedWithRuntime)) {
|
|
565
521
|
if (config.disabled) continue;
|
|
566
522
|
if (!hasRootMarkers(cwd, config.rootMarkers)) continue;
|
|
567
|
-
const resolved =
|
|
523
|
+
const resolved = resolveTrustedCommand(config.command, cwd);
|
|
568
524
|
if (!resolved) continue;
|
|
569
525
|
available[name] = { ...config, resolvedCommand: resolved };
|
|
570
526
|
}
|
package/src/lsp/edits.ts
CHANGED
|
@@ -13,6 +13,7 @@ import type {
|
|
|
13
13
|
WorkspaceEdit,
|
|
14
14
|
} from "./types";
|
|
15
15
|
import { uriToFile } from "./utils";
|
|
16
|
+
import { assertInsideWorkspace } from "./workspace-path";
|
|
16
17
|
|
|
17
18
|
// =============================================================================
|
|
18
19
|
// Text Edit Application
|
|
@@ -133,6 +134,7 @@ export async function applyWorkspaceEdit(edit: WorkspaceEdit, cwd: string): Prom
|
|
|
133
134
|
const textEditsByUri = flattenWorkspaceTextEdits(edit);
|
|
134
135
|
for (const [uri, textEdits] of textEditsByUri) {
|
|
135
136
|
const filePath = uriToFile(uri);
|
|
137
|
+
await assertInsideWorkspace(cwd, filePath);
|
|
136
138
|
await applyTextEdits(filePath, textEdits);
|
|
137
139
|
applied.push(`Applied ${textEdits.length} edit(s) to ${formatPathRelativeToCwd(filePath, cwd)}`);
|
|
138
140
|
}
|
|
@@ -144,18 +146,22 @@ export async function applyWorkspaceEdit(edit: WorkspaceEdit, cwd: string): Prom
|
|
|
144
146
|
if (change.kind === "create") {
|
|
145
147
|
const createOp = change as CreateFile;
|
|
146
148
|
const filePath = uriToFile(createOp.uri);
|
|
149
|
+
await assertInsideWorkspace(cwd, filePath);
|
|
147
150
|
await Bun.write(filePath, "");
|
|
148
151
|
applied.push(`Created ${formatPathRelativeToCwd(filePath, cwd)}`);
|
|
149
152
|
} else if (change.kind === "rename") {
|
|
150
153
|
const renameOp = change as RenameFile;
|
|
151
154
|
const oldPath = uriToFile(renameOp.oldUri);
|
|
152
155
|
const newPath = uriToFile(renameOp.newUri);
|
|
156
|
+
await assertInsideWorkspace(cwd, oldPath);
|
|
157
|
+
await assertInsideWorkspace(cwd, newPath);
|
|
153
158
|
await fs.mkdir(path.dirname(newPath), { recursive: true });
|
|
154
159
|
await fs.rename(oldPath, newPath);
|
|
155
160
|
applied.push(`Renamed ${formatPathRelativeToCwd(oldPath, cwd)} → ${formatPathRelativeToCwd(newPath, cwd)}`);
|
|
156
161
|
} else if (change.kind === "delete") {
|
|
157
162
|
const deleteOp = change as DeleteFile;
|
|
158
163
|
const filePath = uriToFile(deleteOp.uri);
|
|
164
|
+
await assertInsideWorkspace(cwd, filePath);
|
|
159
165
|
await fs.rm(filePath, { recursive: true });
|
|
160
166
|
applied.push(`Deleted ${formatPathRelativeToCwd(filePath, cwd)}`);
|
|
161
167
|
}
|
package/src/lsp/index.ts
CHANGED
|
@@ -76,6 +76,7 @@ import {
|
|
|
76
76
|
symbolKindToIcon,
|
|
77
77
|
uriToFile,
|
|
78
78
|
} from "./utils";
|
|
79
|
+
import { assertInsideWorkspace } from "./workspace-path";
|
|
79
80
|
|
|
80
81
|
export type { LspServerStatus } from "./client";
|
|
81
82
|
export type { LspToolDetails } from "./types";
|
|
@@ -346,6 +347,17 @@ interface FileRenamePair {
|
|
|
346
347
|
* For files this is a single pair. For directories this walks every regular file underneath
|
|
347
348
|
* and produces a parallel pair anchored at the new directory root.
|
|
348
349
|
*/
|
|
350
|
+
/**
|
|
351
|
+
* POSIX `/` contains every absolute path, and the shared helper's prefix for
|
|
352
|
+
* it is `//`, so skip containment there. A Windows drive root is only that
|
|
353
|
+
* volume, so it is checked. Any other platform root keeps the previous skip.
|
|
354
|
+
*/
|
|
355
|
+
function workspaceRootSkipsContainment(root: string): boolean {
|
|
356
|
+
if (root === "/") return true;
|
|
357
|
+
if (/^[A-Za-z]:[\\/]$/.test(root)) return false;
|
|
358
|
+
return root === path.parse(root).root;
|
|
359
|
+
}
|
|
360
|
+
|
|
349
361
|
async function enumerateRenamePairs(
|
|
350
362
|
source: string,
|
|
351
363
|
dest: string,
|
|
@@ -1505,6 +1517,23 @@ export class LspTool implements AgentTool<typeof lspSchema, LspToolDetails, Them
|
|
|
1505
1517
|
}
|
|
1506
1518
|
}
|
|
1507
1519
|
|
|
1520
|
+
// Reject every path this rename will write before the first write. Check the
|
|
1521
|
+
// caller signal after each await, including the last one.
|
|
1522
|
+
const cwd = this.session.cwd;
|
|
1523
|
+
throwIfAborted(signal);
|
|
1524
|
+
const workspaceRoot = await fs.promises.realpath(cwd);
|
|
1525
|
+
throwIfAborted(signal);
|
|
1526
|
+
if (!workspaceRootSkipsContainment(workspaceRoot)) {
|
|
1527
|
+
await assertInsideWorkspace(cwd, source);
|
|
1528
|
+
throwIfAborted(signal);
|
|
1529
|
+
await assertInsideWorkspace(cwd, dest);
|
|
1530
|
+
throwIfAborted(signal);
|
|
1531
|
+
for (const uri of acceptedByUri.keys()) {
|
|
1532
|
+
await assertInsideWorkspace(cwd, uriToFile(uri));
|
|
1533
|
+
throwIfAborted(signal);
|
|
1534
|
+
}
|
|
1535
|
+
}
|
|
1536
|
+
|
|
1508
1537
|
for (const [uri, bucket] of acceptedByUri) {
|
|
1509
1538
|
const filePath = uriToFile(uri);
|
|
1510
1539
|
await applyTextEdits(filePath, bucket.edits);
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import type { Stats } from "node:fs";
|
|
2
|
+
import * as fs from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { ToolError } from "../tools/tool-errors";
|
|
5
|
+
|
|
6
|
+
function isEnoent(error: unknown): boolean {
|
|
7
|
+
return (error as NodeJS.ErrnoException).code === "ENOENT";
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/** Drive-letter root such as `C:\`. A UNC share root is not a drive root. */
|
|
11
|
+
function windowsDriveLetter(root: string): string | null {
|
|
12
|
+
const match = /^([A-Za-z]):[\\/]$/.exec(root);
|
|
13
|
+
return match ? match[1].toLowerCase() : null;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* A Windows drive root already ends in a separator. Prefixing another one
|
|
18
|
+
* (`C:\` + `\`) matches nothing on that volume, so compare the drive letter.
|
|
19
|
+
* Same-volume paths stay inside, including `\\?\C:\`. Other drives and UNC
|
|
20
|
+
* shares do not.
|
|
21
|
+
*/
|
|
22
|
+
function sameWindowsDrive(driveRoot: string, candidate: string): boolean {
|
|
23
|
+
const letter = windowsDriveLetter(driveRoot);
|
|
24
|
+
if (!letter) return false;
|
|
25
|
+
const normalized = candidate.replace(/\//g, "\\");
|
|
26
|
+
const extended = /^\\\\\?\\([A-Za-z]):\\/.exec(normalized);
|
|
27
|
+
if (extended) return extended[1].toLowerCase() === letter;
|
|
28
|
+
if (normalized.startsWith("\\\\")) return false;
|
|
29
|
+
return path.win32.parse(normalized).root.toLowerCase() === `${letter}:\\`;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function escapes(root: string, candidate: string): boolean {
|
|
33
|
+
if (windowsDriveLetter(root)) return !sameWindowsDrive(root, candidate);
|
|
34
|
+
return candidate !== root && !candidate.startsWith(`${root}${path.sep}`);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Resolve a missing path through the nearest existing ancestor. */
|
|
38
|
+
async function canonicalize(filePath: string): Promise<string> {
|
|
39
|
+
try {
|
|
40
|
+
return await fs.realpath(filePath);
|
|
41
|
+
} catch (error) {
|
|
42
|
+
if (!isEnoent(error)) throw error;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const missing: string[] = [];
|
|
46
|
+
let cursor = filePath;
|
|
47
|
+
for (;;) {
|
|
48
|
+
let stat: Stats | undefined;
|
|
49
|
+
try {
|
|
50
|
+
stat = await fs.lstat(cursor);
|
|
51
|
+
} catch (error) {
|
|
52
|
+
if (!isEnoent(error)) throw error;
|
|
53
|
+
}
|
|
54
|
+
if (stat) {
|
|
55
|
+
try {
|
|
56
|
+
return path.join(await fs.realpath(cursor), ...missing);
|
|
57
|
+
} catch (error) {
|
|
58
|
+
if (isEnoent(error)) throw new ToolError(`LSP edit escapes the workspace: ${filePath}`);
|
|
59
|
+
throw error;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
const parent = path.dirname(cursor);
|
|
63
|
+
if (parent === cursor) throw new ToolError(`LSP edit escapes the workspace: ${filePath}`);
|
|
64
|
+
missing.unshift(path.basename(cursor));
|
|
65
|
+
cursor = parent;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export async function assertInsideWorkspace(cwd: string, filePath: string): Promise<void> {
|
|
70
|
+
const root = await fs.realpath(cwd);
|
|
71
|
+
const candidate = await canonicalize(filePath);
|
|
72
|
+
if (escapes(root, candidate)) {
|
|
73
|
+
throw new ToolError(`LSP edit escapes the workspace: ${filePath}`);
|
|
74
|
+
}
|
|
75
|
+
}
|