@sayknow-cli/coding-agent 0.7.10 → 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 +18 -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 +170 -10
- 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
package/src/tools/todo-write.ts
CHANGED
|
@@ -241,6 +241,14 @@ function removeTasks(phases: TodoPhase[], entry: TodoOpEntryValue, errors: strin
|
|
|
241
241
|
return phases;
|
|
242
242
|
}
|
|
243
243
|
|
|
244
|
+
/** Type of a value that was expected to be a string, with its article. */
|
|
245
|
+
function describeArgument(value: unknown): string {
|
|
246
|
+
if (value === null) return "null";
|
|
247
|
+
if (Array.isArray(value)) return "an array";
|
|
248
|
+
if (typeof value === "object") return "an object";
|
|
249
|
+
return `a ${typeof value}`;
|
|
250
|
+
}
|
|
251
|
+
|
|
244
252
|
function applyEntry(phases: TodoPhase[], entry: TodoOpEntryValue, errors: string[]): TodoPhase[] {
|
|
245
253
|
switch (entry.op) {
|
|
246
254
|
case "init":
|
|
@@ -275,6 +283,16 @@ function applyEntry(phases: TodoPhase[], entry: TodoOpEntryValue, errors: string
|
|
|
275
283
|
case "note": {
|
|
276
284
|
const hit = resolveTaskOrError(phases, entry.task, errors);
|
|
277
285
|
if (!hit) return phases;
|
|
286
|
+
// The schema types `text`, but bridges and replays reach `execute` without
|
|
287
|
+
// raw validation, and `.replace` on a non-string body used to crash the
|
|
288
|
+
// call. Reject it with a correction instead of storing it.
|
|
289
|
+
if (entry.text !== undefined && typeof entry.text !== "string") {
|
|
290
|
+
errors.push(
|
|
291
|
+
`Note text must be a string; got ${describeArgument(entry.text)}. ` +
|
|
292
|
+
'Pass the note body as "text", for example { op: "note", task: "<task content>", text: "why" }.',
|
|
293
|
+
);
|
|
294
|
+
return phases;
|
|
295
|
+
}
|
|
278
296
|
const text = (entry.text ?? "").replace(/\s+$/u, "");
|
|
279
297
|
if (!text) {
|
|
280
298
|
errors.push("Missing text for note operation");
|
|
@@ -310,6 +328,26 @@ export function applyOpsToPhases(
|
|
|
310
328
|
// Markdown round-trip
|
|
311
329
|
// =============================================================================
|
|
312
330
|
|
|
331
|
+
/**
|
|
332
|
+
* Notes are declared as `string[]`, but the array is only typed, never validated:
|
|
333
|
+
* a session persisted elsewhere or a bridged caller that reached `execute`
|
|
334
|
+
* without raw validation can hand over any element, and every render path splits
|
|
335
|
+
* each note on newlines. One non-string element used to crash the call with a
|
|
336
|
+
* minified `.split is not a function` TypeError instead of a tool result. String
|
|
337
|
+
* notes render exactly as before.
|
|
338
|
+
*/
|
|
339
|
+
function noteDisplayText(note: unknown): string {
|
|
340
|
+
if (typeof note === "string") return note;
|
|
341
|
+
if (note !== null && typeof note === "object") {
|
|
342
|
+
try {
|
|
343
|
+
return JSON.stringify(note) ?? "[unrenderable note]";
|
|
344
|
+
} catch {
|
|
345
|
+
return "[unrenderable note]";
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
return String(note);
|
|
349
|
+
}
|
|
350
|
+
|
|
313
351
|
const STATUS_TO_MARKER: Record<TodoStatus, string> = {
|
|
314
352
|
pending: " ",
|
|
315
353
|
in_progress: "/",
|
|
@@ -329,7 +367,7 @@ export function phasesToMarkdown(phases: TodoPhase[]): string {
|
|
|
329
367
|
if (task.notes && task.notes.length > 0) {
|
|
330
368
|
for (let j = 0; j < task.notes.length; j++) {
|
|
331
369
|
if (j > 0) out.push(" >");
|
|
332
|
-
for (const noteLine of task.notes[j].split("\n")) {
|
|
370
|
+
for (const noteLine of noteDisplayText(task.notes[j]).split("\n")) {
|
|
333
371
|
out.push(noteLine === "" ? " >" : ` > ${noteLine}`);
|
|
334
372
|
}
|
|
335
373
|
}
|
|
@@ -477,7 +515,7 @@ function formatSummary(phases: TodoPhase[], errors: string[]): string {
|
|
|
477
515
|
if (task.status === "in_progress" && task.notes && task.notes.length > 0) {
|
|
478
516
|
for (let j = 0; j < task.notes.length; j++) {
|
|
479
517
|
if (j > 0) lines.push(" ---");
|
|
480
|
-
for (const noteLine of task.notes[j].split("\n")) {
|
|
518
|
+
for (const noteLine of noteDisplayText(task.notes[j]).split("\n")) {
|
|
481
519
|
lines.push(` ${noteLine}`);
|
|
482
520
|
}
|
|
483
521
|
}
|
|
@@ -628,7 +666,7 @@ function renderNoteAttachments(phases: TodoPhase[], uiTheme: Theme): string[] {
|
|
|
628
666
|
lines.push(` ${title}`);
|
|
629
667
|
for (let j = 0; j < task.notes.length; j++) {
|
|
630
668
|
if (j > 0) lines.push(` ${bar}`);
|
|
631
|
-
for (const noteLine of task.notes[j].split("\n")) {
|
|
669
|
+
for (const noteLine of noteDisplayText(task.notes[j]).split("\n")) {
|
|
632
670
|
lines.push(` ${bar} ${uiTheme.fg("dim", noteLine)}`);
|
|
633
671
|
}
|
|
634
672
|
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `<untrusted-content>` envelope for tool output the model must treat as data.
|
|
3
|
+
*
|
|
4
|
+
* Kept free of imports so low-level tools (for example `gh`, which is reachable
|
|
5
|
+
* from `config/settings` through internal URLs) can wrap output without pulling
|
|
6
|
+
* `tools/fetch` and the web scrapers into the settings import cycle.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
export const UNTRUSTED_CONTENT_OPEN = "<untrusted-content>";
|
|
10
|
+
const UNTRUSTED_CONTENT_CLOSE = "</untrusted-content>";
|
|
11
|
+
export const WRAP_PREFIX_CHARS = `${UNTRUSTED_CONTENT_OPEN}\n`.length;
|
|
12
|
+
export const WRAP_SUFFIX = `\n${UNTRUSTED_CONTENT_CLOSE}`;
|
|
13
|
+
|
|
14
|
+
export function escapeUntrustedContent(content: string): string {
|
|
15
|
+
// HTML and XML accept whitespace between the tag name and ">".
|
|
16
|
+
return content
|
|
17
|
+
.replace(/<\/untrusted-content>/gi, "</untrusted-content>")
|
|
18
|
+
.replace(/<\/untrusted-content[ \t\n\r\f]+>/gi, "</untrusted-content>");
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function wrapUntrustedContent(content: string): string {
|
|
22
|
+
return `${UNTRUSTED_CONTENT_OPEN}\n${escapeUntrustedContent(content)}${WRAP_SUFFIX}`;
|
|
23
|
+
}
|
package/src/tools/vim.ts
CHANGED
|
@@ -485,7 +485,7 @@ export class VimTool implements AgentTool<typeof vimSchema, VimToolDetails> {
|
|
|
485
485
|
async #beforeMutate(buffer: VimBuffer): Promise<void> {
|
|
486
486
|
enforcePlanModeWrite(this.session, buffer.displayPath, { op: buffer.baseFingerprint ? "update" : "create" });
|
|
487
487
|
if (!buffer.editabilityChecked && buffer.baseFingerprint) {
|
|
488
|
-
await assertEditableFile(buffer.filePath, buffer.displayPath);
|
|
488
|
+
await assertEditableFile(buffer.filePath, buffer.displayPath, this.session.settings);
|
|
489
489
|
buffer.editabilityChecked = true;
|
|
490
490
|
}
|
|
491
491
|
}
|
|
@@ -493,7 +493,7 @@ export class VimTool implements AgentTool<typeof vimSchema, VimToolDetails> {
|
|
|
493
493
|
async #saveBuffer(buffer: VimBuffer, options?: { force?: boolean }): Promise<VimSaveResult> {
|
|
494
494
|
enforcePlanModeWrite(this.session, buffer.displayPath, { op: buffer.baseFingerprint ? "update" : "create" });
|
|
495
495
|
if (buffer.baseFingerprint) {
|
|
496
|
-
await assertEditableFile(buffer.filePath, buffer.displayPath);
|
|
496
|
+
await assertEditableFile(buffer.filePath, buffer.displayPath, this.session.settings);
|
|
497
497
|
}
|
|
498
498
|
if (!options?.force) {
|
|
499
499
|
const diskFingerprint = await statFingerprint(buffer.filePath);
|
package/src/tools/write.ts
CHANGED
|
@@ -4,7 +4,7 @@ import * as path from "node:path";
|
|
|
4
4
|
import type { AgentTool, AgentToolContext, AgentToolResult, AgentToolUpdateCallback } from "@sayknow-cli/agent-core";
|
|
5
5
|
import type { Component } from "@sayknow-cli/tui";
|
|
6
6
|
import { Text } from "@sayknow-cli/tui";
|
|
7
|
-
import { isEnoent, isRecord, prompt, untilAborted } from "@sayknow-cli/utils";
|
|
7
|
+
import { isEnoent, isRecord, pathIsWithin, prompt, untilAborted } from "@sayknow-cli/utils";
|
|
8
8
|
import * as z from "zod/v4";
|
|
9
9
|
import { stripHashlinePrefixes } from "../edit";
|
|
10
10
|
import type { RenderResultOptions } from "../extensibility/custom-tools/types";
|
|
@@ -177,6 +177,31 @@ function parseSqliteWriteTarget(subPath: string, queryString: string): { table:
|
|
|
177
177
|
return { table, key };
|
|
178
178
|
}
|
|
179
179
|
|
|
180
|
+
/**
|
|
181
|
+
* `new Database` follows symlinks. A lexical path inside the workspace can
|
|
182
|
+
* still name a file outside it, so open only the real path that stays inside
|
|
183
|
+
* the same session workspace an ordinary write resolves against.
|
|
184
|
+
*/
|
|
185
|
+
async function realSqliteDatabaseInWorkspace(
|
|
186
|
+
workspaceRoot: string,
|
|
187
|
+
absolutePath: string,
|
|
188
|
+
signal?: AbortSignal,
|
|
189
|
+
): Promise<string> {
|
|
190
|
+
signal?.throwIfAborted();
|
|
191
|
+
let realPath: string;
|
|
192
|
+
try {
|
|
193
|
+
realPath = await fs.realpath(absolutePath);
|
|
194
|
+
} catch (error) {
|
|
195
|
+
if (isEnoent(error)) throw error;
|
|
196
|
+
throw new ToolError(error instanceof Error ? error.message : String(error));
|
|
197
|
+
}
|
|
198
|
+
signal?.throwIfAborted();
|
|
199
|
+
if (!pathIsWithin(workspaceRoot, realPath)) {
|
|
200
|
+
throw new ToolError(`SQLite write target resolves outside the workspace: ${absolutePath}`);
|
|
201
|
+
}
|
|
202
|
+
return realPath;
|
|
203
|
+
}
|
|
204
|
+
|
|
180
205
|
/**
|
|
181
206
|
* Write tool implementation.
|
|
182
207
|
*
|
|
@@ -375,6 +400,7 @@ export class WriteTool implements AgentTool<typeof writeSchema, WriteToolDetails
|
|
|
375
400
|
displayPath: string,
|
|
376
401
|
content: string,
|
|
377
402
|
resolvedSqlitePath: ResolvedSqliteWritePath,
|
|
403
|
+
signal?: AbortSignal,
|
|
378
404
|
): Promise<AgentToolResult<WriteToolDetails>> {
|
|
379
405
|
let db: Database | null = null;
|
|
380
406
|
try {
|
|
@@ -382,7 +408,13 @@ export class WriteTool implements AgentTool<typeof writeSchema, WriteToolDetails
|
|
|
382
408
|
throw new ToolError(`SQLite database '${displayPath}' not found`);
|
|
383
409
|
}
|
|
384
410
|
|
|
385
|
-
|
|
411
|
+
const realDatabasePath = await realSqliteDatabaseInWorkspace(
|
|
412
|
+
this.session.cwd,
|
|
413
|
+
resolvedSqlitePath.absolutePath,
|
|
414
|
+
signal,
|
|
415
|
+
);
|
|
416
|
+
signal?.throwIfAborted();
|
|
417
|
+
db = new Database(realDatabasePath, { create: false, strict: true });
|
|
386
418
|
db.run("PRAGMA busy_timeout = 3000");
|
|
387
419
|
|
|
388
420
|
const trimmedContent = content.trim();
|
|
@@ -465,6 +497,7 @@ export class WriteTool implements AgentTool<typeof writeSchema, WriteToolDetails
|
|
|
465
497
|
context: AgentToolContext | undefined,
|
|
466
498
|
): Promise<AgentToolResult<WriteToolDetails>> {
|
|
467
499
|
const absolutePath = entry.absolutePath;
|
|
500
|
+
enforcePlanModeWrite(this.session, absolutePath, { op: "update" });
|
|
468
501
|
if (!(await fs.exists(absolutePath))) {
|
|
469
502
|
throw new ToolError(`Conflict #${entry.id} target '${entry.displayPath}' no longer exists.`);
|
|
470
503
|
}
|
|
@@ -720,7 +753,7 @@ export class WriteTool implements AgentTool<typeof writeSchema, WriteToolDetails
|
|
|
720
753
|
if (resolvedSqlitePath) {
|
|
721
754
|
enforcePlanModeWrite(this.session, resolvedSqlitePath.sqlitePath, { op: "update" });
|
|
722
755
|
|
|
723
|
-
const sqliteResult = await this.#writeSqliteRow(path, cleanContent, resolvedSqlitePath);
|
|
756
|
+
const sqliteResult = await this.#writeSqliteRow(path, cleanContent, resolvedSqlitePath, signal);
|
|
724
757
|
if (stripped) {
|
|
725
758
|
const firstText = sqliteResult.content.find(
|
|
726
759
|
(block): block is { type: "text"; text: string } =>
|
|
@@ -739,7 +772,7 @@ export class WriteTool implements AgentTool<typeof writeSchema, WriteToolDetails
|
|
|
739
772
|
|
|
740
773
|
// Check if file exists and is auto-generated before overwriting
|
|
741
774
|
if (await fs.exists(absolutePath)) {
|
|
742
|
-
await assertEditableFile(absolutePath, path);
|
|
775
|
+
await assertEditableFile(absolutePath, path, this.session.settings);
|
|
743
776
|
}
|
|
744
777
|
|
|
745
778
|
// Try ACP bridge first — no disk write when client handles it
|
package/src/tui/tree-list.ts
CHANGED
|
@@ -3,11 +3,25 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import { replaceTabs } from "@sayknow-cli/tui";
|
|
6
|
+
import { sanitizeText } from "@sayknow-cli/utils";
|
|
6
7
|
import type { Theme } from "../modes/theme/theme";
|
|
7
8
|
import { formatMoreItems } from "../tools/render-utils";
|
|
8
9
|
import type { TreeContext } from "./types";
|
|
9
10
|
import { getTreeBranch, getTreeContinuePrefix } from "./utils";
|
|
10
11
|
|
|
12
|
+
/**
|
|
13
|
+
* Tool renderers pass raw match lines or line groups into `renderItem`, which
|
|
14
|
+
* then applies theme colors. Strip controls first so OSC bytes are not wrapped
|
|
15
|
+
* into the styled string. Objects (file entries, todos) are left unchanged.
|
|
16
|
+
*/
|
|
17
|
+
function sanitizeTreeItem<T>(item: T): T {
|
|
18
|
+
if (typeof item === "string") return sanitizeText(item) as T;
|
|
19
|
+
if (Array.isArray(item)) {
|
|
20
|
+
return item.map(part => (typeof part === "string" ? sanitizeText(part) : part)) as T;
|
|
21
|
+
}
|
|
22
|
+
return item;
|
|
23
|
+
}
|
|
24
|
+
|
|
11
25
|
export interface TreeListOptions<T> {
|
|
12
26
|
items: T[];
|
|
13
27
|
expanded?: boolean;
|
|
@@ -32,7 +46,7 @@ export function renderTreeList<T>(options: TreeListOptions<T>, theme: Theme): st
|
|
|
32
46
|
// renderItem implementations MUST NOT vary line count based on isLast.
|
|
33
47
|
const preRendered: string[][] = [];
|
|
34
48
|
for (let i = 0; i < maxItems; i++) {
|
|
35
|
-
const rendered = renderItem(items[i], {
|
|
49
|
+
const rendered = renderItem(sanitizeTreeItem(items[i]!), {
|
|
36
50
|
index: i,
|
|
37
51
|
isLast: false,
|
|
38
52
|
depth: 0,
|
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
import type { ThinkingLevel } from "@sayknow-cli/agent-core";
|
|
6
6
|
import type { Api, Model } from "@sayknow-cli/ai";
|
|
7
7
|
import { completeSimple } from "@sayknow-cli/ai";
|
|
8
|
-
import { logger, prompt } from "@sayknow-cli/utils";
|
|
8
|
+
import { logger, prompt, redactCrashSecrets } from "@sayknow-cli/utils";
|
|
9
|
+
import { redactChangelogEntry } from "../commit/changelog";
|
|
9
10
|
import type { ModelRegistry } from "../config/model-registry";
|
|
10
11
|
import { resolveModelRoleValue } from "../config/model-resolver";
|
|
11
12
|
import type { Settings } from "../config/settings";
|
|
@@ -35,6 +36,11 @@ function filterDiffNoise(diff: string): string {
|
|
|
35
36
|
return filtered.join("\n");
|
|
36
37
|
}
|
|
37
38
|
|
|
39
|
+
/** Keep changelog patterns, then scrub known credential shapes on the whole string. */
|
|
40
|
+
function redactCommitMessageText(text: string): string {
|
|
41
|
+
return redactCrashSecrets(redactChangelogEntry(text));
|
|
42
|
+
}
|
|
43
|
+
|
|
38
44
|
function getModelCandidates(
|
|
39
45
|
registry: ModelRegistry,
|
|
40
46
|
settings: Settings,
|
|
@@ -87,7 +93,7 @@ export async function generateCommitMessage(
|
|
|
87
93
|
logger.debug("commit-msg-generator: diff is empty after noise filtering");
|
|
88
94
|
return null;
|
|
89
95
|
}
|
|
90
|
-
const userMessage = `<diff>\n${truncatedDiff}\n</diff>`;
|
|
96
|
+
const userMessage = `<diff>\n${redactCommitMessageText(truncatedDiff)}\n</diff>`;
|
|
91
97
|
|
|
92
98
|
for (const candidate of candidates) {
|
|
93
99
|
const apiKey = await registry.getApiKey(candidate.model, sessionId);
|
|
@@ -120,6 +126,7 @@ export async function generateCommitMessage(
|
|
|
120
126
|
|
|
121
127
|
// Clean up: remove wrapping quotes, backticks, trailing period
|
|
122
128
|
msg = msg.replace(/^[`"']|[`"']$/g, "").replace(/\.$/, "");
|
|
129
|
+
msg = redactCommitMessageText(msg);
|
|
123
130
|
|
|
124
131
|
logger.debug("commit-msg-generator: generated", { model: candidate.model.id, msg });
|
|
125
132
|
return msg;
|
|
@@ -5,7 +5,7 @@ import { spawn } from "node:child_process";
|
|
|
5
5
|
import * as fs from "node:fs/promises";
|
|
6
6
|
import * as os from "node:os";
|
|
7
7
|
import * as path from "node:path";
|
|
8
|
-
import { $env
|
|
8
|
+
import { $env } from "@sayknow-cli/utils";
|
|
9
9
|
|
|
10
10
|
/** Returns the user's preferred editor command, or undefined if not configured. */
|
|
11
11
|
export function getEditorCommand(): string | undefined {
|
|
@@ -38,10 +38,22 @@ export async function openInEditor(
|
|
|
38
38
|
options?: OpenInEditorOptions,
|
|
39
39
|
): Promise<string | null> {
|
|
40
40
|
const ext = options?.extension ?? ".md";
|
|
41
|
-
|
|
41
|
+
// Random directory plus an exclusive create: a preexisting symlink under the
|
|
42
|
+
// temp directory is not opened, and the draft is not left world-readable.
|
|
43
|
+
let tempDir: string | undefined;
|
|
44
|
+
let tmpFile = "";
|
|
42
45
|
|
|
43
46
|
try {
|
|
44
|
-
await
|
|
47
|
+
tempDir = await fs.mkdtemp(path.join(os.tmpdir(), "skc-editor-"));
|
|
48
|
+
if (process.platform !== "win32") await fs.chmod(tempDir, 0o700);
|
|
49
|
+
tmpFile = path.join(tempDir, `draft${ext}`);
|
|
50
|
+
const handle = await fs.open(tmpFile, "wx", 0o600);
|
|
51
|
+
try {
|
|
52
|
+
await handle.writeFile(content);
|
|
53
|
+
} finally {
|
|
54
|
+
await handle.close();
|
|
55
|
+
}
|
|
56
|
+
if (process.platform !== "win32") await fs.chmod(tmpFile, 0o600);
|
|
45
57
|
|
|
46
58
|
const [editor, ...editorArgs] = editorCmd.split(" ");
|
|
47
59
|
const stdio = options?.stdio ?? ["inherit", "inherit", "inherit"];
|
|
@@ -61,10 +73,12 @@ export async function openInEditor(
|
|
|
61
73
|
}
|
|
62
74
|
return null;
|
|
63
75
|
} finally {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
76
|
+
if (tempDir) {
|
|
77
|
+
try {
|
|
78
|
+
await fs.rm(tempDir, { recursive: true, force: true });
|
|
79
|
+
} catch {
|
|
80
|
+
// Ignore cleanup errors
|
|
81
|
+
}
|
|
68
82
|
}
|
|
69
83
|
}
|
|
70
84
|
}
|
|
@@ -11,7 +11,7 @@ import type { AgentMessage } from "@sayknow-cli/agent-core";
|
|
|
11
11
|
import type { ImageContent } from "@sayknow-cli/ai";
|
|
12
12
|
import { glob } from "@sayknow-cli/natives";
|
|
13
13
|
import { fuzzyMatch } from "@sayknow-cli/tui";
|
|
14
|
-
import { formatAge, formatBytes, readImageMetadata } from "@sayknow-cli/utils";
|
|
14
|
+
import { formatAge, formatBytes, pathIsWithin, readImageMetadata, resolveEquivalentPath } from "@sayknow-cli/utils";
|
|
15
15
|
import { formatHashLines } from "../hashline/hash";
|
|
16
16
|
import type { FileMentionMessage } from "../session/messages";
|
|
17
17
|
import {
|
|
@@ -73,6 +73,7 @@ type MentionCandidate = {
|
|
|
73
73
|
path: string;
|
|
74
74
|
pathLower: string;
|
|
75
75
|
normalizedPath: string;
|
|
76
|
+
segments: string[];
|
|
76
77
|
};
|
|
77
78
|
|
|
78
79
|
function normalizeMentionQuery(query: string): string {
|
|
@@ -110,11 +111,37 @@ async function listMentionCandidates(cwd: string): Promise<MentionCandidate[]> {
|
|
|
110
111
|
if (normalizedPath.length === 0) {
|
|
111
112
|
continue;
|
|
112
113
|
}
|
|
113
|
-
|
|
114
|
+
const segments = pathLower.split(PATH_SEPARATOR_REGEX).filter(segment => segment.length > 0);
|
|
115
|
+
candidates.push({ path: entry, pathLower, normalizedPath, segments });
|
|
114
116
|
}
|
|
115
117
|
return candidates;
|
|
116
118
|
}
|
|
117
119
|
|
|
120
|
+
/**
|
|
121
|
+
* True when `query` can be spelled as prefixes of path segments taken in order
|
|
122
|
+
* (segments may be skipped), e.g. `httpserap` → `http_server_api_tests`.
|
|
123
|
+
* Plain subsequence matching would also accept letters scattered mid-word across
|
|
124
|
+
* any long path, so a stray `@handle` or `@word` would resolve to an unrelated file.
|
|
125
|
+
*/
|
|
126
|
+
function matchesSegmentPrefixes(query: string, segments: string[]): boolean {
|
|
127
|
+
const failed = new Set<number>();
|
|
128
|
+
const visit = (segmentIndex: number, queryIndex: number): boolean => {
|
|
129
|
+
if (queryIndex === query.length) return true;
|
|
130
|
+
if (segmentIndex === segments.length) return false;
|
|
131
|
+
const key = segmentIndex * (query.length + 1) + queryIndex;
|
|
132
|
+
if (failed.has(key)) return false;
|
|
133
|
+
const segment = segments[segmentIndex]!;
|
|
134
|
+
for (let taken = 1; taken <= segment.length && queryIndex + taken <= query.length; taken++) {
|
|
135
|
+
if (segment[taken - 1] !== query[queryIndex + taken - 1]) break;
|
|
136
|
+
if (visit(segmentIndex + 1, queryIndex + taken)) return true;
|
|
137
|
+
}
|
|
138
|
+
if (visit(segmentIndex + 1, queryIndex)) return true;
|
|
139
|
+
failed.add(key);
|
|
140
|
+
return false;
|
|
141
|
+
};
|
|
142
|
+
return visit(0, 0);
|
|
143
|
+
}
|
|
144
|
+
|
|
118
145
|
async function resolveMentionPath(
|
|
119
146
|
filePath: string,
|
|
120
147
|
cwd: string,
|
|
@@ -141,6 +168,7 @@ async function resolveMentionPath(
|
|
|
141
168
|
}
|
|
142
169
|
|
|
143
170
|
const scored = candidates
|
|
171
|
+
.filter(candidate => matchesSegmentPrefixes(normalizedQuery, candidate.segments))
|
|
144
172
|
.map(candidate => ({ candidate, match: fuzzyMatch(normalizedQuery, candidate.normalizedPath) }))
|
|
145
173
|
.filter(entry => entry.match.matches)
|
|
146
174
|
.sort((a, b) => {
|
|
@@ -278,6 +306,26 @@ export function extractFileMentions(text: string): string[] {
|
|
|
278
306
|
return [...new Set(mentions)];
|
|
279
307
|
}
|
|
280
308
|
|
|
309
|
+
/**
|
|
310
|
+
* Compare canonical Windows paths without folding directory names: individual
|
|
311
|
+
* directories can opt into case-sensitive names.
|
|
312
|
+
*/
|
|
313
|
+
export function isCanonicalWindowsPathWithin(root: string, candidate: string): boolean {
|
|
314
|
+
if (!path.win32.isAbsolute(root) || !path.win32.isAbsolute(candidate)) return false;
|
|
315
|
+
|
|
316
|
+
const canonicalRoot = path.win32.resolve(root);
|
|
317
|
+
const canonicalCandidate = path.win32.resolve(candidate);
|
|
318
|
+
const rootParts = path.win32.parse(canonicalRoot);
|
|
319
|
+
const candidateParts = path.win32.parse(canonicalCandidate);
|
|
320
|
+
if (rootParts.root.toLowerCase() !== candidateParts.root.toLowerCase()) return false;
|
|
321
|
+
|
|
322
|
+
const rootSegments = canonicalRoot.slice(rootParts.root.length).split(path.win32.sep).filter(Boolean);
|
|
323
|
+
const candidateSegments = canonicalCandidate.slice(candidateParts.root.length).split(path.win32.sep).filter(Boolean);
|
|
324
|
+
if (candidateSegments.length < rootSegments.length) return false;
|
|
325
|
+
|
|
326
|
+
return rootSegments.every((segment, index) => segment === candidateSegments[index]);
|
|
327
|
+
}
|
|
328
|
+
|
|
281
329
|
/**
|
|
282
330
|
* Generate a FileMentionMessage containing the contents of mentioned files.
|
|
283
331
|
* Returns empty array if no files could be read.
|
|
@@ -301,6 +349,8 @@ export async function generateFileMentionMessages(
|
|
|
301
349
|
if (filePaths.length === 0) return [];
|
|
302
350
|
|
|
303
351
|
const autoResizeImages = options?.autoResizeImages ?? true;
|
|
352
|
+
const canonicalWindowsCwd = process.platform === "win32" ? await fs.realpath(cwd).catch(() => undefined) : undefined;
|
|
353
|
+
if (process.platform === "win32" && canonicalWindowsCwd === undefined) return [];
|
|
304
354
|
|
|
305
355
|
const files: FileMentionMessage["files"] = [];
|
|
306
356
|
let mentionCandidatesPromise: Promise<MentionCandidate[]> | null = null;
|
|
@@ -316,6 +366,24 @@ export async function generateFileMentionMessages(
|
|
|
316
366
|
continue;
|
|
317
367
|
}
|
|
318
368
|
const absolutePath = resolveReadPath(resolvedPath, cwd);
|
|
369
|
+
// Skip `..`, `~`, and outside absolute paths. On Windows, realpath both
|
|
370
|
+
// paths and compare exact components because directories can be case-sensitive.
|
|
371
|
+
// Fail closed if either real path is unavailable. Read the canonical path so
|
|
372
|
+
// replacing the original mention symlink does not retarget this read.
|
|
373
|
+
const canonicalPath =
|
|
374
|
+
process.platform === "win32"
|
|
375
|
+
? await fs.realpath(absolutePath).catch(() => undefined)
|
|
376
|
+
: resolveEquivalentPath(absolutePath);
|
|
377
|
+
if (!canonicalPath) {
|
|
378
|
+
continue;
|
|
379
|
+
}
|
|
380
|
+
const staysWithinSession =
|
|
381
|
+
process.platform === "win32"
|
|
382
|
+
? canonicalWindowsCwd !== undefined && isCanonicalWindowsPathWithin(canonicalWindowsCwd, canonicalPath)
|
|
383
|
+
: pathIsWithin(cwd, canonicalPath);
|
|
384
|
+
if (!staysWithinSession) {
|
|
385
|
+
continue;
|
|
386
|
+
}
|
|
319
387
|
// Duplicate suppression, keyed by absolute path: same path shown earlier this
|
|
320
388
|
// batch or recently in the conversation → compact note, no re-read (the path
|
|
321
389
|
// stays referenced so the model can re-fetch via the read tool).
|
|
@@ -329,14 +397,14 @@ export async function generateFileMentionMessages(
|
|
|
329
397
|
}
|
|
330
398
|
shownInBatch.add(absolutePath);
|
|
331
399
|
try {
|
|
332
|
-
const stat = await Bun.file(
|
|
400
|
+
const stat = await Bun.file(canonicalPath).stat();
|
|
333
401
|
if (stat.isDirectory()) {
|
|
334
|
-
const { output, lineCount } = await buildDirectoryListing(
|
|
402
|
+
const { output, lineCount } = await buildDirectoryListing(canonicalPath);
|
|
335
403
|
files.push({ path: resolvedPath, content: output, lineCount });
|
|
336
404
|
continue;
|
|
337
405
|
}
|
|
338
406
|
|
|
339
|
-
const imageMetadata = await readImageMetadata(
|
|
407
|
+
const imageMetadata = await readImageMetadata(canonicalPath);
|
|
340
408
|
const mimeType = imageMetadata?.mimeType;
|
|
341
409
|
if (mimeType) {
|
|
342
410
|
if (stat.size > MAX_AUTO_READ_IMAGE_BYTES) {
|
|
@@ -348,7 +416,7 @@ export async function generateFileMentionMessages(
|
|
|
348
416
|
});
|
|
349
417
|
continue;
|
|
350
418
|
}
|
|
351
|
-
const buffer = await fs.readFile(
|
|
419
|
+
const buffer = await fs.readFile(canonicalPath);
|
|
352
420
|
if (buffer.length === 0) {
|
|
353
421
|
continue;
|
|
354
422
|
}
|
|
@@ -385,7 +453,7 @@ export async function generateFileMentionMessages(
|
|
|
385
453
|
continue;
|
|
386
454
|
}
|
|
387
455
|
|
|
388
|
-
const content = await Bun.file(
|
|
456
|
+
const content = await Bun.file(canonicalPath).text();
|
|
389
457
|
let { output, lineCount } = buildTextOutput(content, options?.maxInlineBytes);
|
|
390
458
|
if (options?.useHashLines) {
|
|
391
459
|
output = formatHashLines(output);
|
package/src/utils/git.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import * as fs from "node:fs";
|
|
2
2
|
import * as os from "node:os";
|
|
3
3
|
import * as path from "node:path";
|
|
4
|
-
import { $which, hasFsCode, isEnoent
|
|
4
|
+
import { $which, hasFsCode, isEnoent } from "@sayknow-cli/utils";
|
|
5
|
+
import { projectSafeSpawnEnv } from "@sayknow-cli/utils/shell-config";
|
|
5
6
|
import {
|
|
6
7
|
parseDiffHunks as parseCommitDiffHunks,
|
|
7
8
|
parseFileDiffs,
|
|
@@ -197,7 +198,10 @@ async function runCommand(
|
|
|
197
198
|
const commandArgs = withShortLivedGitConfig(options.readOnly ? withNoOptionalLocks(args) : [...args]);
|
|
198
199
|
const child = Bun.spawn(["git", ...commandArgs], {
|
|
199
200
|
cwd,
|
|
200
|
-
|
|
201
|
+
// The inherited environment holds the autoloaded project `.env`; without
|
|
202
|
+
// filtering, a repository could set e.g. `GIT_CONFIG_*` (`core.hooksPath`)
|
|
203
|
+
// or `GIT_SSH_COMMAND` and have SKC's own commit/fetch/push run its code.
|
|
204
|
+
env: options.env ? { ...projectSafeSpawnEnv(), GIT_OPTIONAL_LOCKS: "0", ...options.env } : projectSafeSpawnEnv(),
|
|
201
205
|
signal: options.signal,
|
|
202
206
|
stdin: normalizeStdin(options.stdin),
|
|
203
207
|
stdout: "pipe",
|
|
@@ -363,9 +367,24 @@ function buildApplyArgs(patchPath: string, options: PatchOptions): string[] {
|
|
|
363
367
|
}
|
|
364
368
|
|
|
365
369
|
async function writeTempPatch(content: string): Promise<string> {
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
370
|
+
// Random directory plus an exclusive create: a preexisting symlink under the
|
|
371
|
+
// shared temp directory is not opened, and the patch is not left world-readable.
|
|
372
|
+
const tempDir = await fs.promises.mkdtemp(path.join(os.tmpdir(), "skc-git-patch-"));
|
|
373
|
+
try {
|
|
374
|
+
if (process.platform !== "win32") await fs.promises.chmod(tempDir, 0o700);
|
|
375
|
+
const tempPath = path.join(tempDir, "patch");
|
|
376
|
+
const handle = await fs.promises.open(tempPath, "wx", 0o600);
|
|
377
|
+
try {
|
|
378
|
+
await handle.writeFile(content);
|
|
379
|
+
} finally {
|
|
380
|
+
await handle.close();
|
|
381
|
+
}
|
|
382
|
+
if (process.platform !== "win32") await fs.promises.chmod(tempPath, 0o600);
|
|
383
|
+
return tempPath;
|
|
384
|
+
} catch (error) {
|
|
385
|
+
await fs.promises.rm(tempDir, { recursive: true, force: true });
|
|
386
|
+
throw error;
|
|
387
|
+
}
|
|
369
388
|
}
|
|
370
389
|
|
|
371
390
|
// ════════════════════════════════════════════════════════════════════════════
|
|
@@ -1180,7 +1199,7 @@ export const patch = {
|
|
|
1180
1199
|
try {
|
|
1181
1200
|
await patch.apply(cwd, tempPath, options);
|
|
1182
1201
|
} finally {
|
|
1183
|
-
await fs.promises.rm(tempPath, { force: true });
|
|
1202
|
+
await fs.promises.rm(path.dirname(tempPath), { recursive: true, force: true });
|
|
1184
1203
|
}
|
|
1185
1204
|
},
|
|
1186
1205
|
|
|
@@ -1201,7 +1220,7 @@ export const patch = {
|
|
|
1201
1220
|
try {
|
|
1202
1221
|
return await patch.canApply(cwd, tempPath, options);
|
|
1203
1222
|
} finally {
|
|
1204
|
-
await fs.promises.rm(tempPath, { force: true });
|
|
1223
|
+
await fs.promises.rm(path.dirname(tempPath), { recursive: true, force: true });
|
|
1205
1224
|
}
|
|
1206
1225
|
},
|
|
1207
1226
|
|
|
@@ -1540,6 +1559,14 @@ function formatGhFailure(args: readonly string[], stdout: string, stderr: string
|
|
|
1540
1559
|
return `GitHub CLI command failed: gh ${args.join(" ")}`;
|
|
1541
1560
|
}
|
|
1542
1561
|
|
|
1562
|
+
/** Captured `gh` output never wants a pager or forced-terminal behavior. */
|
|
1563
|
+
function ghSpawnEnv(): Record<string, string> {
|
|
1564
|
+
const env = projectSafeSpawnEnv();
|
|
1565
|
+
delete env.GH_FORCE_TTY;
|
|
1566
|
+
env.GH_PAGER = "cat";
|
|
1567
|
+
return env;
|
|
1568
|
+
}
|
|
1569
|
+
|
|
1543
1570
|
export const github = {
|
|
1544
1571
|
/** Check if `gh` CLI is installed. */
|
|
1545
1572
|
available(): boolean {
|
|
@@ -1555,6 +1582,10 @@ export const github = {
|
|
|
1555
1582
|
try {
|
|
1556
1583
|
const child = Bun.spawn(["gh", ...args], {
|
|
1557
1584
|
cwd,
|
|
1585
|
+
// Same project-dotenv filtering as git: `gh` runs git for checkout
|
|
1586
|
+
// and push. Output is captured, so gh must never page or act as if
|
|
1587
|
+
// on a terminal; pin both so a project `.env` cannot select a pager.
|
|
1588
|
+
env: ghSpawnEnv(),
|
|
1558
1589
|
stdin: "ignore",
|
|
1559
1590
|
stdout: "pipe",
|
|
1560
1591
|
stderr: "pipe",
|