@gajae-code/coding-agent 0.1.1
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 +8662 -0
- package/README.md +37 -0
- package/dist/types/async/index.d.ts +2 -0
- package/dist/types/async/job-manager.d.ts +101 -0
- package/dist/types/async/support.d.ts +2 -0
- package/dist/types/autoresearch/dashboard.d.ts +4 -0
- package/dist/types/autoresearch/git.d.ts +36 -0
- package/dist/types/autoresearch/helpers.d.ts +24 -0
- package/dist/types/autoresearch/index.d.ts +2 -0
- package/dist/types/autoresearch/state.d.ts +17 -0
- package/dist/types/autoresearch/storage.d.ts +142 -0
- package/dist/types/autoresearch/tools/init-experiment.d.ts +31 -0
- package/dist/types/autoresearch/tools/log-experiment.d.ts +23 -0
- package/dist/types/autoresearch/tools/run-experiment.d.ts +8 -0
- package/dist/types/autoresearch/tools/update-notes.d.ts +12 -0
- package/dist/types/autoresearch/types.d.ts +154 -0
- package/dist/types/capability/context-file.d.ts +17 -0
- package/dist/types/capability/extension-module.d.ts +15 -0
- package/dist/types/capability/extension.d.ts +28 -0
- package/dist/types/capability/fs.d.ts +20 -0
- package/dist/types/capability/hook.d.ts +19 -0
- package/dist/types/capability/index.d.ts +80 -0
- package/dist/types/capability/instruction.d.ts +17 -0
- package/dist/types/capability/mcp.d.ts +45 -0
- package/dist/types/capability/prompt.d.ts +15 -0
- package/dist/types/capability/rule.d.ts +61 -0
- package/dist/types/capability/settings.d.ts +15 -0
- package/dist/types/capability/skill.d.ts +36 -0
- package/dist/types/capability/slash-command.d.ts +17 -0
- package/dist/types/capability/ssh.d.ts +23 -0
- package/dist/types/capability/system-prompt.d.ts +15 -0
- package/dist/types/capability/tool.d.ts +19 -0
- package/dist/types/capability/types.d.ts +154 -0
- package/dist/types/cli/agents-cli.d.ts +12 -0
- package/dist/types/cli/args.d.ts +53 -0
- package/dist/types/cli/auth-broker-cli.d.ts +25 -0
- package/dist/types/cli/auth-gateway-cli.d.ts +18 -0
- package/dist/types/cli/classify-install-target.d.ts +18 -0
- package/dist/types/cli/commands/init-xdg.d.ts +1 -0
- package/dist/types/cli/config-cli.d.ts +22 -0
- package/dist/types/cli/file-processor.d.ts +11 -0
- package/dist/types/cli/grep-cli.d.ts +17 -0
- package/dist/types/cli/initial-message.d.ts +17 -0
- package/dist/types/cli/list-models.d.ts +30 -0
- package/dist/types/cli/plugin-cli.d.ts +32 -0
- package/dist/types/cli/read-cli.d.ts +4 -0
- package/dist/types/cli/session-picker.d.ts +3 -0
- package/dist/types/cli/setup-cli.d.ts +31 -0
- package/dist/types/cli/shell-cli.d.ts +8 -0
- package/dist/types/cli/ssh-cli.d.ts +21 -0
- package/dist/types/cli/stats-cli.d.ts +17 -0
- package/dist/types/cli/update-cli.d.ts +38 -0
- package/dist/types/cli/web-search-cli.d.ts +20 -0
- package/dist/types/cli/worktree-cli.d.ts +26 -0
- package/dist/types/cli.d.ts +3 -0
- package/dist/types/commands/acp.d.ts +12 -0
- package/dist/types/commands/agents.d.ts +34 -0
- package/dist/types/commands/auth-broker.d.ts +54 -0
- package/dist/types/commands/auth-gateway.d.ts +32 -0
- package/dist/types/commands/codex-native-hook.d.ts +6 -0
- package/dist/types/commands/commit.d.ts +27 -0
- package/dist/types/commands/config.d.ts +30 -0
- package/dist/types/commands/deep-interview.d.ts +7 -0
- package/dist/types/commands/gjc-runtime-bridge.d.ts +6 -0
- package/dist/types/commands/grep.d.ts +42 -0
- package/dist/types/commands/launch.d.ts +121 -0
- package/dist/types/commands/plugin.d.ts +52 -0
- package/dist/types/commands/question.d.ts +7 -0
- package/dist/types/commands/ralplan.d.ts +7 -0
- package/dist/types/commands/read.d.ts +15 -0
- package/dist/types/commands/setup.d.ts +48 -0
- package/dist/types/commands/shell.d.ts +21 -0
- package/dist/types/commands/ssh.d.ts +48 -0
- package/dist/types/commands/state.d.ts +7 -0
- package/dist/types/commands/stats.d.ts +25 -0
- package/dist/types/commands/team.d.ts +24 -0
- package/dist/types/commands/ultragoal.d.ts +7 -0
- package/dist/types/commands/update.d.ts +20 -0
- package/dist/types/commands/web-search.d.ts +33 -0
- package/dist/types/commands/worktree.d.ts +34 -0
- package/dist/types/commit/agentic/agent.d.ts +31 -0
- package/dist/types/commit/agentic/fallback.d.ts +5 -0
- package/dist/types/commit/agentic/index.d.ts +2 -0
- package/dist/types/commit/agentic/state.d.ts +58 -0
- package/dist/types/commit/agentic/tools/analyze-file.d.ts +19 -0
- package/dist/types/commit/agentic/tools/git-file-diff.d.ts +10 -0
- package/dist/types/commit/agentic/tools/git-hunk.d.ts +9 -0
- package/dist/types/commit/agentic/tools/git-overview.d.ts +9 -0
- package/dist/types/commit/agentic/tools/index.d.ts +16 -0
- package/dist/types/commit/agentic/tools/propose-changelog.d.ts +28 -0
- package/dist/types/commit/agentic/tools/propose-commit.d.ts +36 -0
- package/dist/types/commit/agentic/tools/recent-commits.d.ts +7 -0
- package/dist/types/commit/agentic/tools/schemas.d.ts +27 -0
- package/dist/types/commit/agentic/tools/split-commit.d.ts +53 -0
- package/dist/types/commit/agentic/topo-sort.d.ts +4 -0
- package/dist/types/commit/agentic/trivial.d.ts +7 -0
- package/dist/types/commit/agentic/validation.d.ts +20 -0
- package/dist/types/commit/analysis/conventional.d.ts +22 -0
- package/dist/types/commit/analysis/index.d.ts +4 -0
- package/dist/types/commit/analysis/scope.d.ts +6 -0
- package/dist/types/commit/analysis/summary.d.ts +19 -0
- package/dist/types/commit/analysis/validation.d.ts +8 -0
- package/dist/types/commit/changelog/detect.d.ts +2 -0
- package/dist/types/commit/changelog/generate.d.ts +30 -0
- package/dist/types/commit/changelog/index.d.ts +30 -0
- package/dist/types/commit/changelog/parse.d.ts +2 -0
- package/dist/types/commit/cli.d.ts +3 -0
- package/dist/types/commit/git/diff.d.ts +5 -0
- package/dist/types/commit/index.d.ts +4 -0
- package/dist/types/commit/map-reduce/index.d.ts +28 -0
- package/dist/types/commit/map-reduce/map-phase.d.ts +17 -0
- package/dist/types/commit/map-reduce/reduce-phase.d.ts +13 -0
- package/dist/types/commit/map-reduce/utils.d.ts +2 -0
- package/dist/types/commit/message.d.ts +2 -0
- package/dist/types/commit/model-selection.d.ts +15 -0
- package/dist/types/commit/pipeline.d.ts +5 -0
- package/dist/types/commit/shared-llm.d.ts +54 -0
- package/dist/types/commit/types.d.ts +78 -0
- package/dist/types/commit/utils/exclusions.d.ts +4 -0
- package/dist/types/commit/utils.d.ts +20 -0
- package/dist/types/config/config-file.d.ts +58 -0
- package/dist/types/config/file-lock.d.ts +6 -0
- package/dist/types/config/keybindings.d.ts +334 -0
- package/dist/types/config/model-equivalence.d.ts +24 -0
- package/dist/types/config/model-registry.d.ts +390 -0
- package/dist/types/config/model-resolver.d.ts +230 -0
- package/dist/types/config/models-config-schema.d.ts +504 -0
- package/dist/types/config/prompt-templates.d.ts +32 -0
- package/dist/types/config/resolve-config-value.d.ts +17 -0
- package/dist/types/config/settings-schema.d.ts +3337 -0
- package/dist/types/config/settings.d.ts +132 -0
- package/dist/types/config/skill-settings-defaults.d.ts +14 -0
- package/dist/types/config.d.ts +66 -0
- package/dist/types/cursor.d.ts +24 -0
- package/dist/types/dap/client.d.ts +38 -0
- package/dist/types/dap/config.d.ts +6 -0
- package/dist/types/dap/index.d.ts +4 -0
- package/dist/types/dap/session.d.ts +108 -0
- package/dist/types/dap/types.d.ts +524 -0
- package/dist/types/debug/index.d.ts +15 -0
- package/dist/types/debug/log-formatting.d.ts +4 -0
- package/dist/types/debug/log-viewer.d.ts +68 -0
- package/dist/types/debug/profiler.d.ts +24 -0
- package/dist/types/debug/raw-sse-buffer.d.ts +44 -0
- package/dist/types/debug/raw-sse.d.ts +16 -0
- package/dist/types/debug/report-bundle.d.ts +55 -0
- package/dist/types/debug/system-info.d.ts +26 -0
- package/dist/types/defaults/gjc-defaults.d.ts +44 -0
- package/dist/types/discovery/agents-md.d.ts +1 -0
- package/dist/types/discovery/agents.d.ts +12 -0
- package/dist/types/discovery/builtin.d.ts +1 -0
- package/dist/types/discovery/claude-plugins.d.ts +1 -0
- package/dist/types/discovery/claude.d.ts +1 -0
- package/dist/types/discovery/cline.d.ts +1 -0
- package/dist/types/discovery/codex.d.ts +1 -0
- package/dist/types/discovery/cursor.d.ts +16 -0
- package/dist/types/discovery/gemini.d.ts +1 -0
- package/dist/types/discovery/github.d.ts +1 -0
- package/dist/types/discovery/helpers.d.ts +268 -0
- package/dist/types/discovery/index.d.ts +48 -0
- package/dist/types/discovery/mcp-json.d.ts +1 -0
- package/dist/types/discovery/opencode.d.ts +1 -0
- package/dist/types/discovery/plugin-dir-roots.d.ts +15 -0
- package/dist/types/discovery/ssh.d.ts +1 -0
- package/dist/types/discovery/substitute-plugin-root.d.ts +5 -0
- package/dist/types/discovery/vscode.d.ts +1 -0
- package/dist/types/discovery/windsurf.d.ts +13 -0
- package/dist/types/edit/apply-patch/index.d.ts +35 -0
- package/dist/types/edit/apply-patch/parser.d.ts +34 -0
- package/dist/types/edit/diff.d.ts +59 -0
- package/dist/types/edit/file-read-cache.d.ts +25 -0
- package/dist/types/edit/index.d.ts +58 -0
- package/dist/types/edit/modes/apply-patch.d.ts +24 -0
- package/dist/types/edit/modes/patch.d.ts +99 -0
- package/dist/types/edit/modes/replace.d.ts +142 -0
- package/dist/types/edit/normalize.d.ts +43 -0
- package/dist/types/edit/notebook.d.ts +23 -0
- package/dist/types/edit/read-file.d.ts +2 -0
- package/dist/types/edit/renderer.d.ts +110 -0
- package/dist/types/edit/streaming.d.ts +66 -0
- package/dist/types/eval/backend.d.ts +40 -0
- package/dist/types/eval/index.d.ts +4 -0
- package/dist/types/eval/js/context-manager.d.ts +24 -0
- package/dist/types/eval/js/executor.d.ts +28 -0
- package/dist/types/eval/js/index.d.ts +10 -0
- package/dist/types/eval/js/shared/helpers.d.ts +38 -0
- package/dist/types/eval/js/shared/indirect-eval.d.ts +14 -0
- package/dist/types/eval/js/shared/prelude.d.ts +1 -0
- package/dist/types/eval/js/shared/rewrite-imports.d.ts +6 -0
- package/dist/types/eval/js/shared/runtime.d.ts +47 -0
- package/dist/types/eval/js/shared/types.d.ts +24 -0
- package/dist/types/eval/js/tool-bridge.d.ts +18 -0
- package/dist/types/eval/js/worker-core.d.ts +5 -0
- package/dist/types/eval/js/worker-entry.d.ts +1 -0
- package/dist/types/eval/js/worker-protocol.d.ts +77 -0
- package/dist/types/eval/py/display.d.ts +25 -0
- package/dist/types/eval/py/executor.d.ts +83 -0
- package/dist/types/eval/py/index.d.ts +10 -0
- package/dist/types/eval/py/kernel.d.ts +61 -0
- package/dist/types/eval/py/prelude.d.ts +1 -0
- package/dist/types/eval/py/runtime.d.ts +21 -0
- package/dist/types/eval/py/tool-bridge.d.ts +20 -0
- package/dist/types/eval/types.d.ts +52 -0
- package/dist/types/exa/factory.d.ts +13 -0
- package/dist/types/exa/index.d.ts +20 -0
- package/dist/types/exa/mcp-client.d.ts +45 -0
- package/dist/types/exa/render.d.ts +19 -0
- package/dist/types/exa/researcher.d.ts +9 -0
- package/dist/types/exa/search.d.ts +9 -0
- package/dist/types/exa/types.d.ts +155 -0
- package/dist/types/exa/websets.d.ts +9 -0
- package/dist/types/exec/bash-executor.d.ts +41 -0
- package/dist/types/exec/exec.d.ts +25 -0
- package/dist/types/exec/idle-timeout-watchdog.d.ts +18 -0
- package/dist/types/exec/non-interactive-env.d.ts +1 -0
- package/dist/types/export/custom-share.d.ts +20 -0
- package/dist/types/export/html/index.d.ts +10 -0
- package/dist/types/export/html/template.generated.d.ts +1 -0
- package/dist/types/export/html/template.macro.d.ts +5 -0
- package/dist/types/export/ttsr.d.ts +44 -0
- package/dist/types/extensibility/custom-commands/bundled/ci-green/index.d.ts +9 -0
- package/dist/types/extensibility/custom-commands/bundled/review/index.d.ts +10 -0
- package/dist/types/extensibility/custom-commands/index.d.ts +2 -0
- package/dist/types/extensibility/custom-commands/loader.d.ts +29 -0
- package/dist/types/extensibility/custom-commands/types.d.ts +106 -0
- package/dist/types/extensibility/custom-tools/index.d.ts +6 -0
- package/dist/types/extensibility/custom-tools/loader.d.ts +69 -0
- package/dist/types/extensibility/custom-tools/types.d.ts +226 -0
- package/dist/types/extensibility/custom-tools/wrapper.d.ts +23 -0
- package/dist/types/extensibility/extensions/compact-handler.d.ts +26 -0
- package/dist/types/extensibility/extensions/get-commands-handler.d.ts +29 -0
- package/dist/types/extensibility/extensions/index.d.ts +8 -0
- package/dist/types/extensibility/extensions/loader.d.ts +43 -0
- package/dist/types/extensibility/extensions/runner.d.ts +134 -0
- package/dist/types/extensibility/extensions/types.d.ts +864 -0
- package/dist/types/extensibility/extensions/wrapper.d.ts +54 -0
- package/dist/types/extensibility/hooks/index.d.ts +5 -0
- package/dist/types/extensibility/hooks/loader.d.ts +89 -0
- package/dist/types/extensibility/hooks/runner.d.ts +126 -0
- package/dist/types/extensibility/hooks/tool-wrapper.d.ts +25 -0
- package/dist/types/extensibility/hooks/types.d.ts +431 -0
- package/dist/types/extensibility/plugins/doctor.d.ts +3 -0
- package/dist/types/extensibility/plugins/git-url.d.ts +34 -0
- package/dist/types/extensibility/plugins/index.d.ts +7 -0
- package/dist/types/extensibility/plugins/installer.d.ts +5 -0
- package/dist/types/extensibility/plugins/legacy-pi-compat.d.ts +2 -0
- package/dist/types/extensibility/plugins/loader.d.ts +31 -0
- package/dist/types/extensibility/plugins/manager.d.ts +65 -0
- package/dist/types/extensibility/plugins/marketplace/cache.d.ts +41 -0
- package/dist/types/extensibility/plugins/marketplace/fetcher.d.ts +48 -0
- package/dist/types/extensibility/plugins/marketplace/index.d.ts +6 -0
- package/dist/types/extensibility/plugins/marketplace/manager.d.ts +57 -0
- package/dist/types/extensibility/plugins/marketplace/registry.d.ts +34 -0
- package/dist/types/extensibility/plugins/marketplace/source-resolver.d.ts +28 -0
- package/dist/types/extensibility/plugins/marketplace/types.d.ts +130 -0
- package/dist/types/extensibility/plugins/parser.d.ts +52 -0
- package/dist/types/extensibility/plugins/types.d.ts +149 -0
- package/dist/types/extensibility/shared-events.d.ts +279 -0
- package/dist/types/extensibility/skills.d.ts +74 -0
- package/dist/types/extensibility/slash-commands.d.ts +48 -0
- package/dist/types/extensibility/tool-proxy.d.ts +4 -0
- package/dist/types/extensibility/typebox.d.ts +155 -0
- package/dist/types/extensibility/utils.d.ts +12 -0
- package/dist/types/gjc-runtime/goal-mode-request.d.ts +46 -0
- package/dist/types/gjc-runtime/launch-tmux.d.ts +45 -0
- package/dist/types/gjc-runtime/launch-worktree.d.ts +46 -0
- package/dist/types/gjc-runtime/team-runtime.d.ts +204 -0
- package/dist/types/gjc-runtime/ultragoal-runtime.d.ts +85 -0
- package/dist/types/goals/index.d.ts +3 -0
- package/dist/types/goals/runtime.d.ts +68 -0
- package/dist/types/goals/state.d.ts +35 -0
- package/dist/types/goals/tools/goal-tool.d.ts +128 -0
- package/dist/types/hashline/anchors.d.ts +20 -0
- package/dist/types/hashline/apply.d.ts +14 -0
- package/dist/types/hashline/constants.d.ts +19 -0
- package/dist/types/hashline/diff-preview.d.ts +2 -0
- package/dist/types/hashline/diff.d.ts +17 -0
- package/dist/types/hashline/execute.d.ts +4 -0
- package/dist/types/hashline/hash.d.ts +123 -0
- package/dist/types/hashline/index.d.ts +13 -0
- package/dist/types/hashline/input.d.ts +11 -0
- package/dist/types/hashline/parser.d.ts +7 -0
- package/dist/types/hashline/prefixes.d.ts +7 -0
- package/dist/types/hashline/recovery.d.ts +27 -0
- package/dist/types/hashline/stream.d.ts +2 -0
- package/dist/types/hashline/types.d.ts +77 -0
- package/dist/types/hindsight/backend.d.ts +13 -0
- package/dist/types/hindsight/bank.d.ts +54 -0
- package/dist/types/hindsight/client.d.ts +224 -0
- package/dist/types/hindsight/config.d.ts +51 -0
- package/dist/types/hindsight/content.d.ts +70 -0
- package/dist/types/hindsight/index.d.ts +8 -0
- package/dist/types/hindsight/mental-models.d.ts +125 -0
- package/dist/types/hindsight/state.d.ts +99 -0
- package/dist/types/hindsight/transcript.d.ts +28 -0
- package/dist/types/hooks/codex-native-hooks-config.d.ts +29 -0
- package/dist/types/hooks/native-skill-hook.d.ts +16 -0
- package/dist/types/hooks/skill-keywords.d.ts +17 -0
- package/dist/types/hooks/skill-state.d.ts +80 -0
- package/dist/types/index.d.ts +33 -0
- package/dist/types/internal-urls/agent-protocol.d.ts +12 -0
- package/dist/types/internal-urls/artifact-protocol.d.ts +6 -0
- package/dist/types/internal-urls/docs-index.generated.d.ts +2 -0
- package/dist/types/internal-urls/gjc-protocol.d.ts +12 -0
- package/dist/types/internal-urls/index.d.ts +20 -0
- package/dist/types/internal-urls/issue-pr-protocol.d.ts +17 -0
- package/dist/types/internal-urls/json-query.d.ts +30 -0
- package/dist/types/internal-urls/local-protocol.d.ts +39 -0
- package/dist/types/internal-urls/mcp-protocol.d.ts +12 -0
- package/dist/types/internal-urls/memory-protocol.d.ts +23 -0
- package/dist/types/internal-urls/parse.d.ts +19 -0
- package/dist/types/internal-urls/registry-helpers.d.ts +10 -0
- package/dist/types/internal-urls/router.d.ts +14 -0
- package/dist/types/internal-urls/rule-protocol.d.ts +6 -0
- package/dist/types/internal-urls/skill-protocol.d.ts +13 -0
- package/dist/types/internal-urls/types.d.ts +105 -0
- package/dist/types/lsp/client.d.ts +65 -0
- package/dist/types/lsp/clients/biome-client.d.ts +16 -0
- package/dist/types/lsp/clients/index.d.ts +19 -0
- package/dist/types/lsp/clients/lsp-linter-client.d.ts +16 -0
- package/dist/types/lsp/clients/swiftlint-client.d.ts +20 -0
- package/dist/types/lsp/config.d.ts +65 -0
- package/dist/types/lsp/edits.d.ts +23 -0
- package/dist/types/lsp/index.d.ts +130 -0
- package/dist/types/lsp/lspmux.d.ts +58 -0
- package/dist/types/lsp/render.d.ts +32 -0
- package/dist/types/lsp/startup-events.d.ts +11 -0
- package/dist/types/lsp/types.d.ts +302 -0
- package/dist/types/lsp/utils.d.ts +108 -0
- package/dist/types/main.d.ts +50 -0
- package/dist/types/memories/index.d.ts +28 -0
- package/dist/types/memories/storage.d.ts +110 -0
- package/dist/types/memory-backend/index.d.ts +4 -0
- package/dist/types/memory-backend/local-backend.d.ts +9 -0
- package/dist/types/memory-backend/off-backend.d.ts +7 -0
- package/dist/types/memory-backend/resolve.d.ts +15 -0
- package/dist/types/memory-backend/types.d.ts +61 -0
- package/dist/types/modes/acp/acp-agent.d.ts +61 -0
- package/dist/types/modes/acp/acp-client-bridge.d.ts +9 -0
- package/dist/types/modes/acp/acp-event-mapper.d.ts +32 -0
- package/dist/types/modes/acp/acp-mode.d.ts +5 -0
- package/dist/types/modes/acp/index.d.ts +2 -0
- package/dist/types/modes/acp/terminal-auth.d.ts +6 -0
- package/dist/types/modes/components/agent-dashboard.d.ts +21 -0
- package/dist/types/modes/components/assistant-message.d.ts +16 -0
- package/dist/types/modes/components/bash-execution.d.ts +29 -0
- package/dist/types/modes/components/bordered-loader.d.ts +11 -0
- package/dist/types/modes/components/branch-summary-message.d.ts +13 -0
- package/dist/types/modes/components/btw-panel.d.ts +16 -0
- package/dist/types/modes/components/compaction-summary-message.d.ts +13 -0
- package/dist/types/modes/components/countdown-timer.d.ts +14 -0
- package/dist/types/modes/components/custom-editor.d.ts +47 -0
- package/dist/types/modes/components/custom-message.d.ts +15 -0
- package/dist/types/modes/components/diff.d.ts +11 -0
- package/dist/types/modes/components/dynamic-border.d.ts +14 -0
- package/dist/types/modes/components/eval-execution.d.ts +23 -0
- package/dist/types/modes/components/execution-shared.d.ts +46 -0
- package/dist/types/modes/components/extensions/extension-dashboard.d.ts +26 -0
- package/dist/types/modes/components/extensions/extension-list.d.ts +39 -0
- package/dist/types/modes/components/extensions/index.d.ts +8 -0
- package/dist/types/modes/components/extensions/inspector-panel.d.ts +8 -0
- package/dist/types/modes/components/extensions/state-manager.d.ts +50 -0
- package/dist/types/modes/components/extensions/types.d.ts +151 -0
- package/dist/types/modes/components/footer.d.ts +30 -0
- package/dist/types/modes/components/history-search.d.ts +7 -0
- package/dist/types/modes/components/hook-editor.d.ts +18 -0
- package/dist/types/modes/components/hook-input.d.ts +15 -0
- package/dist/types/modes/components/hook-message.d.ts +15 -0
- package/dist/types/modes/components/hook-selector.d.ts +23 -0
- package/dist/types/modes/components/index.d.ts +35 -0
- package/dist/types/modes/components/keybinding-hints.d.ts +40 -0
- package/dist/types/modes/components/login-dialog.d.ts +32 -0
- package/dist/types/modes/components/message-frame.d.ts +42 -0
- package/dist/types/modes/components/model-selector.d.ts +26 -0
- package/dist/types/modes/components/oauth-selector.d.ts +14 -0
- package/dist/types/modes/components/plugin-selector.d.ts +26 -0
- package/dist/types/modes/components/plugin-settings.d.ts +66 -0
- package/dist/types/modes/components/provider-onboarding-selector.d.ts +7 -0
- package/dist/types/modes/components/queue-mode-selector.d.ts +9 -0
- package/dist/types/modes/components/read-tool-group.d.ts +30 -0
- package/dist/types/modes/components/runtime-mcp-add-wizard.d.ts +25 -0
- package/dist/types/modes/components/session-observer-overlay.d.ts +11 -0
- package/dist/types/modes/components/session-selector.d.ts +30 -0
- package/dist/types/modes/components/settings-defs.d.ts +50 -0
- package/dist/types/modes/components/settings-selector.d.ts +54 -0
- package/dist/types/modes/components/show-images-selector.d.ts +9 -0
- package/dist/types/modes/components/skill-hud/render.d.ts +2 -0
- package/dist/types/modes/components/skill-message.d.ts +9 -0
- package/dist/types/modes/components/status-line/context-thresholds.d.ts +4 -0
- package/dist/types/modes/components/status-line/git-utils.d.ts +22 -0
- package/dist/types/modes/components/status-line/index.d.ts +4 -0
- package/dist/types/modes/components/status-line/presets.d.ts +3 -0
- package/dist/types/modes/components/status-line/segments.d.ts +5 -0
- package/dist/types/modes/components/status-line/separators.d.ts +3 -0
- package/dist/types/modes/components/status-line/token-rate.d.ts +10 -0
- package/dist/types/modes/components/status-line/types.d.ts +80 -0
- package/dist/types/modes/components/status-line.d.ts +80 -0
- package/dist/types/modes/components/theme-selector.d.ts +10 -0
- package/dist/types/modes/components/thinking-selector.d.ts +10 -0
- package/dist/types/modes/components/todo-reminder.d.ts +13 -0
- package/dist/types/modes/components/tool-execution.d.ts +53 -0
- package/dist/types/modes/components/tree-selector.d.ts +31 -0
- package/dist/types/modes/components/ttsr-notification.d.ts +13 -0
- package/dist/types/modes/components/user-message-selector.d.ts +28 -0
- package/dist/types/modes/components/user-message.d.ts +7 -0
- package/dist/types/modes/components/visual-truncate.d.ts +19 -0
- package/dist/types/modes/components/welcome.d.ts +34 -0
- package/dist/types/modes/controllers/btw-controller.d.ts +10 -0
- package/dist/types/modes/controllers/command-controller-shared.d.ts +47 -0
- package/dist/types/modes/controllers/command-controller.d.ts +36 -0
- package/dist/types/modes/controllers/event-controller.d.ts +12 -0
- package/dist/types/modes/controllers/extension-ui-controller.d.ts +80 -0
- package/dist/types/modes/controllers/input-controller.d.ts +35 -0
- package/dist/types/modes/controllers/runtime-mcp-command-controller.d.ts +10 -0
- package/dist/types/modes/controllers/selector-controller.d.ts +46 -0
- package/dist/types/modes/controllers/ssh-command-controller.d.ts +10 -0
- package/dist/types/modes/controllers/todo-command-controller.d.ts +7 -0
- package/dist/types/modes/emoji-autocomplete.d.ts +16 -0
- package/dist/types/modes/index.d.ts +9 -0
- package/dist/types/modes/interactive-mode.d.ts +271 -0
- package/dist/types/modes/loop-limit.d.ts +22 -0
- package/dist/types/modes/oauth-manual-input.d.ts +8 -0
- package/dist/types/modes/print-mode.d.ts +27 -0
- package/dist/types/modes/prompt-action-autocomplete.d.ts +46 -0
- package/dist/types/modes/rpc/host-tools.d.ts +16 -0
- package/dist/types/modes/rpc/host-uris.d.ts +38 -0
- package/dist/types/modes/rpc/rpc-client.d.ts +249 -0
- package/dist/types/modes/rpc/rpc-mode.d.ts +17 -0
- package/dist/types/modes/rpc/rpc-types.d.ts +586 -0
- package/dist/types/modes/runtime-init.d.ts +21 -0
- package/dist/types/modes/session-observer-registry.d.ts +26 -0
- package/dist/types/modes/shared.d.ts +15 -0
- package/dist/types/modes/theme/defaults/index.d.ts +9559 -0
- package/dist/types/modes/theme/mermaid-cache.d.ts +9 -0
- package/dist/types/modes/theme/shimmer.d.ts +38 -0
- package/dist/types/modes/theme/theme.d.ts +273 -0
- package/dist/types/modes/types.d.ts +278 -0
- package/dist/types/modes/utils/context-usage.d.ts +47 -0
- package/dist/types/modes/utils/hotkeys-markdown.d.ts +5 -0
- package/dist/types/modes/utils/keybinding-matchers.d.ts +10 -0
- package/dist/types/modes/utils/tools-markdown.d.ts +5 -0
- package/dist/types/modes/utils/ui-helpers.d.ts +53 -0
- package/dist/types/plan-mode/approved-plan.d.ts +49 -0
- package/dist/types/plan-mode/state.d.ts +6 -0
- package/dist/types/registry/agent-registry.d.ts +62 -0
- package/dist/types/runtime-mcp/client.d.ts +74 -0
- package/dist/types/runtime-mcp/config-writer.d.ts +53 -0
- package/dist/types/runtime-mcp/config.d.ts +75 -0
- package/dist/types/runtime-mcp/discoverable-tool-metadata.d.ts +7 -0
- package/dist/types/runtime-mcp/index.d.ts +18 -0
- package/dist/types/runtime-mcp/json-rpc.d.ts +22 -0
- package/dist/types/runtime-mcp/loader.d.ts +43 -0
- package/dist/types/runtime-mcp/manager.d.ts +193 -0
- package/dist/types/runtime-mcp/oauth-discovery.d.ts +40 -0
- package/dist/types/runtime-mcp/oauth-flow.d.ts +59 -0
- package/dist/types/runtime-mcp/render.d.ts +25 -0
- package/dist/types/runtime-mcp/smithery-auth.d.ts +16 -0
- package/dist/types/runtime-mcp/smithery-connect.d.ts +38 -0
- package/dist/types/runtime-mcp/smithery-registry.d.ts +51 -0
- package/dist/types/runtime-mcp/tool-bridge.d.ts +86 -0
- package/dist/types/runtime-mcp/tool-cache.d.ts +8 -0
- package/dist/types/runtime-mcp/transports/http.d.ts +36 -0
- package/dist/types/runtime-mcp/transports/index.d.ts +5 -0
- package/dist/types/runtime-mcp/transports/stdio.d.ts +32 -0
- package/dist/types/runtime-mcp/types.d.ts +333 -0
- package/dist/types/sdk.d.ts +216 -0
- package/dist/types/secrets/index.d.ts +9 -0
- package/dist/types/secrets/obfuscator.d.ts +23 -0
- package/dist/types/secrets/regex.d.ts +2 -0
- package/dist/types/session/agent-session.d.ts +930 -0
- package/dist/types/session/agent-storage.d.ts +100 -0
- package/dist/types/session/artifacts.d.ts +61 -0
- package/dist/types/session/auth-broker-config.d.ts +13 -0
- package/dist/types/session/auth-storage.d.ts +6 -0
- package/dist/types/session/blob-store.d.ts +63 -0
- package/dist/types/session/client-bridge.d.ts +88 -0
- package/dist/types/session/history-storage.d.ts +16 -0
- package/dist/types/session/messages.d.ts +162 -0
- package/dist/types/session/session-dump-format.d.ts +22 -0
- package/dist/types/session/session-manager.d.ts +549 -0
- package/dist/types/session/session-storage.d.ts +82 -0
- package/dist/types/session/streaming-output.d.ts +185 -0
- package/dist/types/session/tool-choice-queue.d.ts +78 -0
- package/dist/types/session/yield-queue.d.ts +24 -0
- package/dist/types/setup/model-onboarding-guidance.d.ts +8 -0
- package/dist/types/setup/provider-onboarding.d.ts +28 -0
- package/dist/types/skill-state/active-state.d.ts +50 -0
- package/dist/types/slash-commands/acp-builtins.d.ts +18 -0
- package/dist/types/slash-commands/builtin-registry.d.ts +23 -0
- package/dist/types/slash-commands/helpers/context-report.d.ts +7 -0
- package/dist/types/slash-commands/helpers/format.d.ts +10 -0
- package/dist/types/slash-commands/helpers/mcp.d.ts +3 -0
- package/dist/types/slash-commands/helpers/parse.d.ts +33 -0
- package/dist/types/slash-commands/helpers/ssh.d.ts +3 -0
- package/dist/types/slash-commands/helpers/todo.d.ts +3 -0
- package/dist/types/slash-commands/helpers/usage-report.d.ts +7 -0
- package/dist/types/slash-commands/types.d.ts +118 -0
- package/dist/types/ssh/config-writer.d.ts +49 -0
- package/dist/types/ssh/connection-manager.d.ts +33 -0
- package/dist/types/ssh/ssh-executor.d.ts +37 -0
- package/dist/types/ssh/sshfs-mount.d.ts +6 -0
- package/dist/types/ssh/utils.d.ts +2 -0
- package/dist/types/stt/downloader.d.ts +9 -0
- package/dist/types/stt/index.d.ts +3 -0
- package/dist/types/stt/recorder.d.ts +13 -0
- package/dist/types/stt/setup.d.ts +18 -0
- package/dist/types/stt/stt-controller.d.ts +16 -0
- package/dist/types/stt/transcriber.d.ts +16 -0
- package/dist/types/system-prompt.d.ts +93 -0
- package/dist/types/task/agents.d.ts +28 -0
- package/dist/types/task/commands.d.ts +35 -0
- package/dist/types/task/discovery.d.ts +19 -0
- package/dist/types/task/executor.d.ts +106 -0
- package/dist/types/task/gjc-command.d.ts +7 -0
- package/dist/types/task/index.d.ts +38 -0
- package/dist/types/task/name-generator.d.ts +16 -0
- package/dist/types/task/output-manager.d.ts +36 -0
- package/dist/types/task/parallel.d.ts +34 -0
- package/dist/types/task/render.d.ts +22 -0
- package/dist/types/task/simple-mode.d.ts +8 -0
- package/dist/types/task/subprocess-tool-registry.d.ts +72 -0
- package/dist/types/task/types.d.ts +295 -0
- package/dist/types/task/worktree.d.ts +94 -0
- package/dist/types/thinking.d.ts +30 -0
- package/dist/types/tool-discovery/tool-index.d.ts +112 -0
- package/dist/types/tools/archive-reader.d.ts +40 -0
- package/dist/types/tools/ask.d.ts +109 -0
- package/dist/types/tools/ast-edit.d.ts +77 -0
- package/dist/types/tools/ast-grep.d.ts +69 -0
- package/dist/types/tools/auto-generated-guard.d.ts +17 -0
- package/dist/types/tools/bash-command-fixup.d.ts +11 -0
- package/dist/types/tools/bash-interactive.d.ts +16 -0
- package/dist/types/tools/bash-interceptor.d.ts +24 -0
- package/dist/types/tools/bash-pty-selection.d.ts +7 -0
- package/dist/types/tools/bash-skill-urls.d.ts +31 -0
- package/dist/types/tools/bash.d.ts +130 -0
- package/dist/types/tools/browser/attach.d.ts +34 -0
- package/dist/types/tools/browser/launch.d.ts +62 -0
- package/dist/types/tools/browser/readable.d.ts +17 -0
- package/dist/types/tools/browser/registry.d.ts +42 -0
- package/dist/types/tools/browser/render.d.ts +50 -0
- package/dist/types/tools/browser/tab-protocol.d.ts +144 -0
- package/dist/types/tools/browser/tab-supervisor.d.ts +63 -0
- package/dist/types/tools/browser/tab-worker-entry.d.ts +1 -0
- package/dist/types/tools/browser/tab-worker.d.ts +19 -0
- package/dist/types/tools/browser.d.ts +114 -0
- package/dist/types/tools/calculator.d.ts +76 -0
- package/dist/types/tools/checkpoint.d.ts +63 -0
- package/dist/types/tools/conflict-detect.d.ts +205 -0
- package/dist/types/tools/context.d.ts +19 -0
- package/dist/types/tools/debug.d.ts +209 -0
- package/dist/types/tools/eval.d.ts +108 -0
- package/dist/types/tools/fetch.d.ts +61 -0
- package/dist/types/tools/file-recorder.d.ts +13 -0
- package/dist/types/tools/find.d.ts +95 -0
- package/dist/types/tools/fs-cache-invalidation.d.ts +15 -0
- package/dist/types/tools/gh-format.d.ts +6 -0
- package/dist/types/tools/gh-renderer.d.ts +25 -0
- package/dist/types/tools/gh.d.ts +356 -0
- package/dist/types/tools/github-cache.d.ts +103 -0
- package/dist/types/tools/grouped-file-output.d.ts +36 -0
- package/dist/types/tools/hindsight-recall.d.ts +23 -0
- package/dist/types/tools/hindsight-reflect.d.ts +25 -0
- package/dist/types/tools/hindsight-retain.d.ts +29 -0
- package/dist/types/tools/image-gen.d.ts +78 -0
- package/dist/types/tools/index.d.ts +242 -0
- package/dist/types/tools/inspect-image-renderer.d.ts +26 -0
- package/dist/types/tools/inspect-image.d.ts +31 -0
- package/dist/types/tools/irc.d.ts +79 -0
- package/dist/types/tools/job.d.ts +65 -0
- package/dist/types/tools/json-tree.d.ts +23 -0
- package/dist/types/tools/jtd-to-json-schema.d.ts +29 -0
- package/dist/types/tools/jtd-to-typescript.d.ts +26 -0
- package/dist/types/tools/jtd-utils.d.ts +42 -0
- package/dist/types/tools/list-limit.d.ts +12 -0
- package/dist/types/tools/match-line-format.d.ts +11 -0
- package/dist/types/tools/output-meta.d.ts +204 -0
- package/dist/types/tools/path-utils.d.ts +146 -0
- package/dist/types/tools/plan-mode-guard.d.ts +18 -0
- package/dist/types/tools/read.d.ts +85 -0
- package/dist/types/tools/recipe/index.d.ts +45 -0
- package/dist/types/tools/recipe/render.d.ts +36 -0
- package/dist/types/tools/recipe/runner.d.ts +60 -0
- package/dist/types/tools/recipe/runners/cargo.d.ts +16 -0
- package/dist/types/tools/recipe/runners/index.d.ts +2 -0
- package/dist/types/tools/recipe/runners/just.d.ts +2 -0
- package/dist/types/tools/recipe/runners/make.d.ts +2 -0
- package/dist/types/tools/recipe/runners/pkg.d.ts +2 -0
- package/dist/types/tools/recipe/runners/task.d.ts +2 -0
- package/dist/types/tools/render-mermaid.d.ts +37 -0
- package/dist/types/tools/render-utils.d.ts +158 -0
- package/dist/types/tools/renderers.d.ts +26 -0
- package/dist/types/tools/resolve.d.ts +90 -0
- package/dist/types/tools/review.d.ts +63 -0
- package/dist/types/tools/search-tool-bm25.d.ts +65 -0
- package/dist/types/tools/search.d.ts +93 -0
- package/dist/types/tools/sqlite-reader.d.ts +93 -0
- package/dist/types/tools/ssh.d.ts +67 -0
- package/dist/types/tools/subagent.d.ts +58 -0
- package/dist/types/tools/todo-write.d.ts +120 -0
- package/dist/types/tools/tool-errors.d.ts +33 -0
- package/dist/types/tools/tool-result.d.ts +30 -0
- package/dist/types/tools/tool-timeouts.d.ts +51 -0
- package/dist/types/tools/vim.d.ts +58 -0
- package/dist/types/tools/write.d.ts +59 -0
- package/dist/types/tools/yield.d.ts +25 -0
- package/dist/types/tui/code-cell.d.ts +32 -0
- package/dist/types/tui/file-list.d.ts +22 -0
- package/dist/types/tui/hyperlink.d.ts +42 -0
- package/dist/types/tui/index.d.ts +11 -0
- package/dist/types/tui/output-block.d.ts +28 -0
- package/dist/types/tui/status-line.d.ts +18 -0
- package/dist/types/tui/tree-list.d.ts +19 -0
- package/dist/types/tui/types.d.ts +13 -0
- package/dist/types/tui/utils.d.ts +36 -0
- package/dist/types/utils/changelog.d.ts +20 -0
- package/dist/types/utils/clipboard.d.ts +22 -0
- package/dist/types/utils/command-args.d.ts +9 -0
- package/dist/types/utils/commit-message-generator.d.ts +7 -0
- package/dist/types/utils/edit-mode.d.ts +13 -0
- package/dist/types/utils/event-bus.d.ts +6 -0
- package/dist/types/utils/external-editor.d.ts +17 -0
- package/dist/types/utils/file-display-mode.d.ts +27 -0
- package/dist/types/utils/file-mentions.d.ts +11 -0
- package/dist/types/utils/git.d.ts +361 -0
- package/dist/types/utils/image-loading.d.ts +26 -0
- package/dist/types/utils/image-resize.d.ts +39 -0
- package/dist/types/utils/lang-from-path.d.ts +8 -0
- package/dist/types/utils/markit.d.ts +7 -0
- package/dist/types/utils/open.d.ts +2 -0
- package/dist/types/utils/session-color.d.ts +10 -0
- package/dist/types/utils/shell-snapshot.d.ts +5 -0
- package/dist/types/utils/sixel.d.ts +21 -0
- package/dist/types/utils/title-generator.d.ts +31 -0
- package/dist/types/utils/tool-choice.d.ts +7 -0
- package/dist/types/utils/tools-manager.d.ts +9 -0
- package/dist/types/vim/buffer.d.ts +41 -0
- package/dist/types/vim/commands.d.ts +6 -0
- package/dist/types/vim/engine.d.ts +47 -0
- package/dist/types/vim/parser.d.ts +3 -0
- package/dist/types/vim/render.d.ts +25 -0
- package/dist/types/vim/types.d.ts +182 -0
- package/dist/types/web/kagi.d.ts +23 -0
- package/dist/types/web/parallel.d.ts +58 -0
- package/dist/types/web/scrapers/artifacthub.d.ts +6 -0
- package/dist/types/web/scrapers/arxiv.d.ts +5 -0
- package/dist/types/web/scrapers/aur.d.ts +5 -0
- package/dist/types/web/scrapers/biorxiv.d.ts +5 -0
- package/dist/types/web/scrapers/bluesky.d.ts +5 -0
- package/dist/types/web/scrapers/brew.d.ts +5 -0
- package/dist/types/web/scrapers/cheatsh.d.ts +8 -0
- package/dist/types/web/scrapers/chocolatey.d.ts +5 -0
- package/dist/types/web/scrapers/choosealicense.d.ts +2 -0
- package/dist/types/web/scrapers/cisa-kev.d.ts +5 -0
- package/dist/types/web/scrapers/clojars.d.ts +5 -0
- package/dist/types/web/scrapers/coingecko.d.ts +5 -0
- package/dist/types/web/scrapers/crates-io.d.ts +5 -0
- package/dist/types/web/scrapers/crossref.d.ts +2 -0
- package/dist/types/web/scrapers/devto.d.ts +5 -0
- package/dist/types/web/scrapers/discogs.d.ts +8 -0
- package/dist/types/web/scrapers/discourse.d.ts +5 -0
- package/dist/types/web/scrapers/dockerhub.d.ts +5 -0
- package/dist/types/web/scrapers/docs-rs.d.ts +2 -0
- package/dist/types/web/scrapers/fdroid.d.ts +5 -0
- package/dist/types/web/scrapers/firefox-addons.d.ts +2 -0
- package/dist/types/web/scrapers/flathub.d.ts +2 -0
- package/dist/types/web/scrapers/github-gist.d.ts +5 -0
- package/dist/types/web/scrapers/github.d.ts +12 -0
- package/dist/types/web/scrapers/gitlab.d.ts +5 -0
- package/dist/types/web/scrapers/go-pkg.d.ts +5 -0
- package/dist/types/web/scrapers/hackage.d.ts +5 -0
- package/dist/types/web/scrapers/hackernews.d.ts +2 -0
- package/dist/types/web/scrapers/hex.d.ts +5 -0
- package/dist/types/web/scrapers/huggingface.d.ts +2 -0
- package/dist/types/web/scrapers/iacr.d.ts +5 -0
- package/dist/types/web/scrapers/index.d.ts +84 -0
- package/dist/types/web/scrapers/jetbrains-marketplace.d.ts +2 -0
- package/dist/types/web/scrapers/lemmy.d.ts +2 -0
- package/dist/types/web/scrapers/lobsters.d.ts +5 -0
- package/dist/types/web/scrapers/mastodon.d.ts +5 -0
- package/dist/types/web/scrapers/maven.d.ts +6 -0
- package/dist/types/web/scrapers/mdn.d.ts +2 -0
- package/dist/types/web/scrapers/metacpan.d.ts +5 -0
- package/dist/types/web/scrapers/musicbrainz.d.ts +5 -0
- package/dist/types/web/scrapers/npm.d.ts +5 -0
- package/dist/types/web/scrapers/nuget.d.ts +5 -0
- package/dist/types/web/scrapers/nvd.d.ts +5 -0
- package/dist/types/web/scrapers/ollama.d.ts +2 -0
- package/dist/types/web/scrapers/open-vsx.d.ts +5 -0
- package/dist/types/web/scrapers/opencorporates.d.ts +5 -0
- package/dist/types/web/scrapers/openlibrary.d.ts +5 -0
- package/dist/types/web/scrapers/orcid.d.ts +5 -0
- package/dist/types/web/scrapers/osv.d.ts +5 -0
- package/dist/types/web/scrapers/packagist.d.ts +5 -0
- package/dist/types/web/scrapers/pub-dev.d.ts +5 -0
- package/dist/types/web/scrapers/pubmed.d.ts +5 -0
- package/dist/types/web/scrapers/pypi.d.ts +5 -0
- package/dist/types/web/scrapers/rawg.d.ts +2 -0
- package/dist/types/web/scrapers/readthedocs.d.ts +2 -0
- package/dist/types/web/scrapers/reddit.d.ts +5 -0
- package/dist/types/web/scrapers/repology.d.ts +5 -0
- package/dist/types/web/scrapers/rfc.d.ts +5 -0
- package/dist/types/web/scrapers/rubygems.d.ts +5 -0
- package/dist/types/web/scrapers/searchcode.d.ts +2 -0
- package/dist/types/web/scrapers/sec-edgar.d.ts +5 -0
- package/dist/types/web/scrapers/semantic-scholar.d.ts +2 -0
- package/dist/types/web/scrapers/snapcraft.d.ts +2 -0
- package/dist/types/web/scrapers/sourcegraph.d.ts +2 -0
- package/dist/types/web/scrapers/spdx.d.ts +5 -0
- package/dist/types/web/scrapers/spotify.d.ts +8 -0
- package/dist/types/web/scrapers/stackoverflow.d.ts +6 -0
- package/dist/types/web/scrapers/terraform.d.ts +5 -0
- package/dist/types/web/scrapers/tldr.d.ts +7 -0
- package/dist/types/web/scrapers/twitter.d.ts +5 -0
- package/dist/types/web/scrapers/types.d.ts +78 -0
- package/dist/types/web/scrapers/utils.d.ts +26 -0
- package/dist/types/web/scrapers/vimeo.d.ts +5 -0
- package/dist/types/web/scrapers/vscode-marketplace.d.ts +5 -0
- package/dist/types/web/scrapers/w3c.d.ts +2 -0
- package/dist/types/web/scrapers/wikidata.d.ts +5 -0
- package/dist/types/web/scrapers/wikipedia.d.ts +5 -0
- package/dist/types/web/scrapers/youtube.d.ts +5 -0
- package/dist/types/web/search/index.d.ts +84 -0
- package/dist/types/web/search/provider.d.ts +21 -0
- package/dist/types/web/search/providers/anthropic.d.ts +32 -0
- package/dist/types/web/search/providers/base.d.ts +67 -0
- package/dist/types/web/search/providers/brave.d.ts +27 -0
- package/dist/types/web/search/providers/codex.d.ts +35 -0
- package/dist/types/web/search/providers/exa.d.ts +52 -0
- package/dist/types/web/search/providers/gemini.d.ts +57 -0
- package/dist/types/web/search/providers/jina.d.ts +26 -0
- package/dist/types/web/search/providers/kagi.d.ts +24 -0
- package/dist/types/web/search/providers/kimi.d.ts +27 -0
- package/dist/types/web/search/providers/parallel.d.ts +15 -0
- package/dist/types/web/search/providers/perplexity.d.ts +38 -0
- package/dist/types/web/search/providers/searxng.d.ts +44 -0
- package/dist/types/web/search/providers/synthetic.d.ts +21 -0
- package/dist/types/web/search/providers/tavily.d.ts +29 -0
- package/dist/types/web/search/providers/utils.d.ts +52 -0
- package/dist/types/web/search/providers/zai.d.ts +28 -0
- package/dist/types/web/search/render.d.ts +35 -0
- package/dist/types/web/search/types.d.ts +344 -0
- package/dist/types/web/search/utils.d.ts +4 -0
- package/dist/types/workspace-tree.d.ts +42 -0
- package/examples/README.md +21 -0
- package/examples/custom-tools/README.md +104 -0
- package/examples/custom-tools/hello/index.ts +20 -0
- package/examples/extensions/README.md +141 -0
- package/examples/extensions/api-demo.ts +79 -0
- package/examples/extensions/chalk-logger.ts +25 -0
- package/examples/extensions/hello.ts +31 -0
- package/examples/extensions/pirate.ts +43 -0
- package/examples/extensions/plan-mode.ts +549 -0
- package/examples/extensions/reload-runtime.ts +38 -0
- package/examples/extensions/tools.ts +144 -0
- package/examples/extensions/with-deps/index.ts +36 -0
- package/examples/extensions/with-deps/package-lock.json +31 -0
- package/examples/extensions/with-deps/package.json +16 -0
- package/examples/hooks/README.md +56 -0
- package/examples/hooks/auto-commit-on-exit.ts +48 -0
- package/examples/hooks/confirm-destructive.ts +58 -0
- package/examples/hooks/custom-compaction.ts +115 -0
- package/examples/hooks/dirty-repo-guard.ts +51 -0
- package/examples/hooks/file-trigger.ts +40 -0
- package/examples/hooks/git-checkpoint.ts +52 -0
- package/examples/hooks/handoff.ts +149 -0
- package/examples/hooks/permission-gate.ts +33 -0
- package/examples/hooks/protected-paths.ts +29 -0
- package/examples/hooks/qna.ts +118 -0
- package/examples/hooks/status-line.ts +39 -0
- package/examples/sdk/01-minimal.ts +21 -0
- package/examples/sdk/02-custom-model.ts +49 -0
- package/examples/sdk/03-custom-prompt.ts +46 -0
- package/examples/sdk/04-skills.ts +43 -0
- package/examples/sdk/06-extensions.ts +82 -0
- package/examples/sdk/06-hooks.ts +61 -0
- package/examples/sdk/07-context-files.ts +35 -0
- package/examples/sdk/08-prompt-templates.ts +41 -0
- package/examples/sdk/08-slash-commands.ts +46 -0
- package/examples/sdk/09-api-keys-and-oauth.ts +54 -0
- package/examples/sdk/11-sessions.ts +47 -0
- package/examples/sdk/README.md +172 -0
- package/package.json +533 -0
- package/scripts/build-binary.ts +77 -0
- package/scripts/format-prompts.ts +68 -0
- package/scripts/generate-docs-index.ts +71 -0
- package/scripts/generate-template.ts +33 -0
- package/src/async/index.ts +2 -0
- package/src/async/job-manager.ts +586 -0
- package/src/async/support.ts +6 -0
- package/src/autoresearch/command-resume.md +14 -0
- package/src/autoresearch/dashboard.ts +446 -0
- package/src/autoresearch/git.ts +319 -0
- package/src/autoresearch/helpers.ts +218 -0
- package/src/autoresearch/index.ts +536 -0
- package/src/autoresearch/prompt-setup.md +43 -0
- package/src/autoresearch/prompt.md +103 -0
- package/src/autoresearch/resume-message.md +10 -0
- package/src/autoresearch/state.ts +273 -0
- package/src/autoresearch/storage.ts +699 -0
- package/src/autoresearch/tools/init-experiment.ts +272 -0
- package/src/autoresearch/tools/log-experiment.ts +524 -0
- package/src/autoresearch/tools/run-experiment.ts +475 -0
- package/src/autoresearch/tools/update-notes.ts +109 -0
- package/src/autoresearch/types.ts +168 -0
- package/src/bun-imports.d.ts +28 -0
- package/src/capability/context-file.ts +44 -0
- package/src/capability/extension-module.ts +34 -0
- package/src/capability/extension.ts +47 -0
- package/src/capability/fs.ts +107 -0
- package/src/capability/hook.ts +40 -0
- package/src/capability/index.ts +436 -0
- package/src/capability/instruction.ts +37 -0
- package/src/capability/mcp.ts +74 -0
- package/src/capability/prompt.ts +35 -0
- package/src/capability/rule.ts +244 -0
- package/src/capability/settings.ts +34 -0
- package/src/capability/skill.ts +56 -0
- package/src/capability/slash-command.ts +40 -0
- package/src/capability/ssh.ts +41 -0
- package/src/capability/system-prompt.ts +34 -0
- package/src/capability/tool.ts +38 -0
- package/src/capability/types.ts +168 -0
- package/src/cli/agents-cli.ts +138 -0
- package/src/cli/args.ts +269 -0
- package/src/cli/auth-broker-cli.ts +746 -0
- package/src/cli/auth-gateway-cli.ts +411 -0
- package/src/cli/classify-install-target.ts +50 -0
- package/src/cli/commands/init-xdg.ts +27 -0
- package/src/cli/config-cli.ts +418 -0
- package/src/cli/file-processor.ts +123 -0
- package/src/cli/grep-cli.ts +160 -0
- package/src/cli/initial-message.ts +58 -0
- package/src/cli/list-models.ts +194 -0
- package/src/cli/plugin-cli.ts +942 -0
- package/src/cli/read-cli.ts +57 -0
- package/src/cli/session-picker.ts +52 -0
- package/src/cli/setup-cli.ts +433 -0
- package/src/cli/shell-cli.ts +176 -0
- package/src/cli/ssh-cli.ts +179 -0
- package/src/cli/stats-cli.ts +238 -0
- package/src/cli/update-cli.ts +408 -0
- package/src/cli/web-search-cli.ts +133 -0
- package/src/cli/worktree-cli.ts +291 -0
- package/src/cli.ts +99 -0
- package/src/commands/acp.ts +24 -0
- package/src/commands/agents.ts +57 -0
- package/src/commands/auth-broker.ts +96 -0
- package/src/commands/auth-gateway.ts +63 -0
- package/src/commands/codex-native-hook.ts +11 -0
- package/src/commands/commit.ts +46 -0
- package/src/commands/config.ts +51 -0
- package/src/commands/deep-interview.ts +12 -0
- package/src/commands/gjc-runtime-bridge.ts +81 -0
- package/src/commands/grep.ts +48 -0
- package/src/commands/launch.ts +161 -0
- package/src/commands/plugin.ts +78 -0
- package/src/commands/question.ts +12 -0
- package/src/commands/ralplan.ts +12 -0
- package/src/commands/read.ts +35 -0
- package/src/commands/setup.ts +52 -0
- package/src/commands/shell.ts +29 -0
- package/src/commands/ssh.ts +60 -0
- package/src/commands/state.ts +12 -0
- package/src/commands/stats.ts +29 -0
- package/src/commands/team.ts +130 -0
- package/src/commands/ultragoal.ts +32 -0
- package/src/commands/update.ts +21 -0
- package/src/commands/web-search.ts +42 -0
- package/src/commands/worktree.ts +56 -0
- package/src/commit/agentic/agent.ts +316 -0
- package/src/commit/agentic/fallback.ts +96 -0
- package/src/commit/agentic/index.ts +355 -0
- package/src/commit/agentic/prompts/analyze-file.md +22 -0
- package/src/commit/agentic/prompts/session-user.md +25 -0
- package/src/commit/agentic/prompts/split-confirm.md +1 -0
- package/src/commit/agentic/prompts/system.md +38 -0
- package/src/commit/agentic/state.ts +60 -0
- package/src/commit/agentic/tools/analyze-file.ts +127 -0
- package/src/commit/agentic/tools/git-file-diff.ts +191 -0
- package/src/commit/agentic/tools/git-hunk.ts +50 -0
- package/src/commit/agentic/tools/git-overview.ts +81 -0
- package/src/commit/agentic/tools/index.ts +54 -0
- package/src/commit/agentic/tools/propose-changelog.ts +144 -0
- package/src/commit/agentic/tools/propose-commit.ts +109 -0
- package/src/commit/agentic/tools/recent-commits.ts +81 -0
- package/src/commit/agentic/tools/schemas.ts +23 -0
- package/src/commit/agentic/tools/split-commit.ts +238 -0
- package/src/commit/agentic/topo-sort.ts +44 -0
- package/src/commit/agentic/trivial.ts +51 -0
- package/src/commit/agentic/validation.ts +183 -0
- package/src/commit/analysis/conventional.ts +64 -0
- package/src/commit/analysis/index.ts +4 -0
- package/src/commit/analysis/scope.ts +242 -0
- package/src/commit/analysis/summary.ts +105 -0
- package/src/commit/analysis/validation.ts +66 -0
- package/src/commit/changelog/detect.ts +40 -0
- package/src/commit/changelog/generate.ts +97 -0
- package/src/commit/changelog/index.ts +234 -0
- package/src/commit/changelog/parse.ts +44 -0
- package/src/commit/cli.ts +85 -0
- package/src/commit/git/diff.ts +148 -0
- package/src/commit/index.ts +5 -0
- package/src/commit/map-reduce/index.ts +69 -0
- package/src/commit/map-reduce/map-phase.ts +193 -0
- package/src/commit/map-reduce/reduce-phase.ts +49 -0
- package/src/commit/map-reduce/utils.ts +9 -0
- package/src/commit/message.ts +11 -0
- package/src/commit/model-selection.ts +66 -0
- package/src/commit/pipeline.ts +243 -0
- package/src/commit/prompts/analysis-system.md +148 -0
- package/src/commit/prompts/analysis-user.md +38 -0
- package/src/commit/prompts/changelog-system.md +50 -0
- package/src/commit/prompts/changelog-user.md +18 -0
- package/src/commit/prompts/file-observer-system.md +24 -0
- package/src/commit/prompts/file-observer-user.md +8 -0
- package/src/commit/prompts/reduce-system.md +50 -0
- package/src/commit/prompts/reduce-user.md +17 -0
- package/src/commit/prompts/summary-retry.md +3 -0
- package/src/commit/prompts/summary-system.md +38 -0
- package/src/commit/prompts/summary-user.md +13 -0
- package/src/commit/prompts/types-description.md +2 -0
- package/src/commit/shared-llm.ts +77 -0
- package/src/commit/types.ts +118 -0
- package/src/commit/utils/exclusions.ts +42 -0
- package/src/commit/utils.ts +58 -0
- package/src/config/config-file.ts +232 -0
- package/src/config/file-lock.ts +121 -0
- package/src/config/keybindings.ts +493 -0
- package/src/config/mcp-schema.json +230 -0
- package/src/config/model-equivalence.ts +811 -0
- package/src/config/model-registry.ts +2384 -0
- package/src/config/model-resolver.ts +1398 -0
- package/src/config/models-config-schema.ts +175 -0
- package/src/config/prompt-templates.ts +310 -0
- package/src/config/resolve-config-value.ts +94 -0
- package/src/config/settings-schema.ts +2939 -0
- package/src/config/settings.ts +919 -0
- package/src/config/skill-settings-defaults.ts +27 -0
- package/src/config.ts +212 -0
- package/src/cursor.ts +350 -0
- package/src/dap/client.ts +675 -0
- package/src/dap/config.ts +150 -0
- package/src/dap/defaults.json +211 -0
- package/src/dap/index.ts +4 -0
- package/src/dap/session.ts +1306 -0
- package/src/dap/types.ts +600 -0
- package/src/debug/index.ts +459 -0
- package/src/debug/log-formatting.ts +58 -0
- package/src/debug/log-viewer.ts +908 -0
- package/src/debug/profiler.ts +162 -0
- package/src/debug/raw-sse-buffer.ts +270 -0
- package/src/debug/raw-sse.ts +213 -0
- package/src/debug/report-bundle.ts +365 -0
- package/src/debug/system-info.ts +111 -0
- package/src/defaults/gjc/skills/deep-interview/SKILL.md +795 -0
- package/src/defaults/gjc/skills/ralplan/SKILL.md +142 -0
- package/src/defaults/gjc/skills/team/SKILL.md +373 -0
- package/src/defaults/gjc/skills/ultragoal/SKILL.md +176 -0
- package/src/defaults/gjc-defaults.ts +151 -0
- package/src/discovery/agents-md.ts +67 -0
- package/src/discovery/agents.ts +230 -0
- package/src/discovery/builtin.ts +932 -0
- package/src/discovery/claude-plugins.ts +387 -0
- package/src/discovery/claude.ts +313 -0
- package/src/discovery/cline.ts +83 -0
- package/src/discovery/codex.ts +330 -0
- package/src/discovery/cursor.ts +220 -0
- package/src/discovery/gemini.ts +383 -0
- package/src/discovery/github.ts +118 -0
- package/src/discovery/helpers.ts +964 -0
- package/src/discovery/index.ts +76 -0
- package/src/discovery/mcp-json.ts +171 -0
- package/src/discovery/opencode.ts +398 -0
- package/src/discovery/plugin-dir-roots.ts +28 -0
- package/src/discovery/ssh.ts +153 -0
- package/src/discovery/substitute-plugin-root.ts +29 -0
- package/src/discovery/vscode.ts +105 -0
- package/src/discovery/windsurf.ts +147 -0
- package/src/edit/apply-patch/index.ts +87 -0
- package/src/edit/apply-patch/parser.ts +174 -0
- package/src/edit/diff.ts +810 -0
- package/src/edit/file-read-cache.ts +95 -0
- package/src/edit/index.ts +528 -0
- package/src/edit/modes/apply-patch.lark +19 -0
- package/src/edit/modes/apply-patch.ts +53 -0
- package/src/edit/modes/patch.ts +1835 -0
- package/src/edit/modes/replace.ts +1103 -0
- package/src/edit/normalize.ts +375 -0
- package/src/edit/notebook.ts +222 -0
- package/src/edit/read-file.ts +25 -0
- package/src/edit/renderer.ts +683 -0
- package/src/edit/streaming.ts +561 -0
- package/src/eval/backend.ts +43 -0
- package/src/eval/index.ts +4 -0
- package/src/eval/js/context-manager.ts +414 -0
- package/src/eval/js/executor.ts +134 -0
- package/src/eval/js/index.ts +46 -0
- package/src/eval/js/shared/helpers.ts +237 -0
- package/src/eval/js/shared/indirect-eval.ts +30 -0
- package/src/eval/js/shared/prelude.ts +2 -0
- package/src/eval/js/shared/prelude.txt +70 -0
- package/src/eval/js/shared/rewrite-imports.ts +416 -0
- package/src/eval/js/shared/runtime.ts +301 -0
- package/src/eval/js/shared/types.ts +18 -0
- package/src/eval/js/tool-bridge.ts +144 -0
- package/src/eval/js/worker-core.ts +146 -0
- package/src/eval/js/worker-entry.ts +24 -0
- package/src/eval/js/worker-protocol.ts +41 -0
- package/src/eval/py/display.ts +71 -0
- package/src/eval/py/executor.ts +602 -0
- package/src/eval/py/index.ts +58 -0
- package/src/eval/py/kernel.ts +668 -0
- package/src/eval/py/prelude.py +462 -0
- package/src/eval/py/prelude.ts +3 -0
- package/src/eval/py/runner.py +910 -0
- package/src/eval/py/runtime.ts +210 -0
- package/src/eval/py/tool-bridge.ts +137 -0
- package/src/eval/types.ts +48 -0
- package/src/exa/factory.ts +60 -0
- package/src/exa/index.ts +27 -0
- package/src/exa/mcp-client.ts +364 -0
- package/src/exa/render.ts +244 -0
- package/src/exa/researcher.ts +36 -0
- package/src/exa/search.ts +47 -0
- package/src/exa/types.ts +166 -0
- package/src/exa/websets.ts +248 -0
- package/src/exec/bash-executor.ts +309 -0
- package/src/exec/exec.ts +53 -0
- package/src/exec/idle-timeout-watchdog.ts +126 -0
- package/src/exec/non-interactive-env.ts +48 -0
- package/src/export/custom-share.ts +65 -0
- package/src/export/html/index.ts +164 -0
- package/src/export/html/template.css +1060 -0
- package/src/export/html/template.generated.ts +2 -0
- package/src/export/html/template.html +47 -0
- package/src/export/html/template.js +2268 -0
- package/src/export/html/template.macro.ts +25 -0
- package/src/export/html/vendor/highlight.min.js +1213 -0
- package/src/export/html/vendor/marked.min.js +6 -0
- package/src/export/ttsr.ts +434 -0
- package/src/extensibility/custom-commands/bundled/ci-green/index.ts +25 -0
- package/src/extensibility/custom-commands/bundled/review/index.ts +456 -0
- package/src/extensibility/custom-commands/index.ts +2 -0
- package/src/extensibility/custom-commands/loader.ts +238 -0
- package/src/extensibility/custom-commands/types.ts +113 -0
- package/src/extensibility/custom-tools/index.ts +7 -0
- package/src/extensibility/custom-tools/loader.ts +245 -0
- package/src/extensibility/custom-tools/types.ts +254 -0
- package/src/extensibility/custom-tools/wrapper.ts +47 -0
- package/src/extensibility/extensions/compact-handler.ts +40 -0
- package/src/extensibility/extensions/get-commands-handler.ts +80 -0
- package/src/extensibility/extensions/index.ts +15 -0
- package/src/extensibility/extensions/loader.ts +545 -0
- package/src/extensibility/extensions/runner.ts +900 -0
- package/src/extensibility/extensions/types.ts +1259 -0
- package/src/extensibility/extensions/wrapper.ts +189 -0
- package/src/extensibility/hooks/index.ts +5 -0
- package/src/extensibility/hooks/loader.ts +257 -0
- package/src/extensibility/hooks/runner.ts +425 -0
- package/src/extensibility/hooks/tool-wrapper.ts +107 -0
- package/src/extensibility/hooks/types.ts +599 -0
- package/src/extensibility/plugins/doctor.ts +66 -0
- package/src/extensibility/plugins/git-url.ts +281 -0
- package/src/extensibility/plugins/index.ts +9 -0
- package/src/extensibility/plugins/installer.ts +192 -0
- package/src/extensibility/plugins/legacy-pi-compat.ts +336 -0
- package/src/extensibility/plugins/loader.ts +288 -0
- package/src/extensibility/plugins/manager.ts +731 -0
- package/src/extensibility/plugins/marketplace/cache.ts +136 -0
- package/src/extensibility/plugins/marketplace/fetcher.ts +317 -0
- package/src/extensibility/plugins/marketplace/index.ts +6 -0
- package/src/extensibility/plugins/marketplace/manager.ts +770 -0
- package/src/extensibility/plugins/marketplace/registry.ts +196 -0
- package/src/extensibility/plugins/marketplace/source-resolver.ts +147 -0
- package/src/extensibility/plugins/marketplace/types.ts +191 -0
- package/src/extensibility/plugins/parser.ts +105 -0
- package/src/extensibility/plugins/types.ts +194 -0
- package/src/extensibility/shared-events.ts +343 -0
- package/src/extensibility/skills.ts +391 -0
- package/src/extensibility/slash-commands.ts +227 -0
- package/src/extensibility/tool-proxy.ts +25 -0
- package/src/extensibility/typebox.ts +418 -0
- package/src/extensibility/utils.ts +44 -0
- package/src/gjc-runtime/goal-mode-request.ts +212 -0
- package/src/gjc-runtime/launch-tmux.ts +162 -0
- package/src/gjc-runtime/launch-worktree.ts +291 -0
- package/src/gjc-runtime/team-runtime.ts +2025 -0
- package/src/gjc-runtime/ultragoal-runtime.ts +564 -0
- package/src/goals/index.ts +3 -0
- package/src/goals/runtime.ts +524 -0
- package/src/goals/state.ts +37 -0
- package/src/goals/tools/goal-tool.ts +371 -0
- package/src/hashline/anchors.ts +113 -0
- package/src/hashline/apply.ts +737 -0
- package/src/hashline/bigrams.json +649 -0
- package/src/hashline/constants.ts +25 -0
- package/src/hashline/diff-preview.ts +43 -0
- package/src/hashline/diff.ts +56 -0
- package/src/hashline/execute.ts +267 -0
- package/src/hashline/grammar.lark +21 -0
- package/src/hashline/hash.ts +173 -0
- package/src/hashline/index.ts +13 -0
- package/src/hashline/input.ts +130 -0
- package/src/hashline/parser.ts +246 -0
- package/src/hashline/prefixes.ts +101 -0
- package/src/hashline/recovery.ts +113 -0
- package/src/hashline/stream.ts +123 -0
- package/src/hashline/types.ts +68 -0
- package/src/hindsight/backend.ts +205 -0
- package/src/hindsight/bank.ts +131 -0
- package/src/hindsight/client.ts +598 -0
- package/src/hindsight/config.ts +175 -0
- package/src/hindsight/content.ts +210 -0
- package/src/hindsight/index.ts +8 -0
- package/src/hindsight/mental-models.ts +382 -0
- package/src/hindsight/seeds.json +32 -0
- package/src/hindsight/state.ts +469 -0
- package/src/hindsight/transcript.ts +71 -0
- package/src/hooks/codex-native-hooks-config.ts +143 -0
- package/src/hooks/native-skill-hook.ts +279 -0
- package/src/hooks/skill-keywords.ts +86 -0
- package/src/hooks/skill-state.ts +416 -0
- package/src/index.ts +56 -0
- package/src/internal-urls/agent-protocol.ts +129 -0
- package/src/internal-urls/artifact-protocol.ts +80 -0
- package/src/internal-urls/docs-index.generated.ts +81 -0
- package/src/internal-urls/gjc-protocol.ts +83 -0
- package/src/internal-urls/index.ts +21 -0
- package/src/internal-urls/issue-pr-protocol.ts +577 -0
- package/src/internal-urls/json-query.ts +126 -0
- package/src/internal-urls/local-protocol.ts +249 -0
- package/src/internal-urls/mcp-protocol.ts +151 -0
- package/src/internal-urls/memory-protocol.ts +164 -0
- package/src/internal-urls/parse.ts +72 -0
- package/src/internal-urls/registry-helpers.ts +25 -0
- package/src/internal-urls/router.ts +78 -0
- package/src/internal-urls/rule-protocol.ts +38 -0
- package/src/internal-urls/skill-protocol.ts +103 -0
- package/src/internal-urls/types.ts +110 -0
- package/src/lsp/client.ts +951 -0
- package/src/lsp/clients/biome-client.ts +202 -0
- package/src/lsp/clients/index.ts +50 -0
- package/src/lsp/clients/lsp-linter-client.ts +93 -0
- package/src/lsp/clients/swiftlint-client.ts +120 -0
- package/src/lsp/config.ts +492 -0
- package/src/lsp/defaults.json +493 -0
- package/src/lsp/edits.ts +166 -0
- package/src/lsp/index.ts +2282 -0
- package/src/lsp/lspmux.ts +233 -0
- package/src/lsp/render.ts +692 -0
- package/src/lsp/startup-events.ts +13 -0
- package/src/lsp/types.ts +443 -0
- package/src/lsp/utils.ts +678 -0
- package/src/main.ts +961 -0
- package/src/memories/index.ts +1135 -0
- package/src/memories/storage.ts +577 -0
- package/src/memory-backend/index.ts +4 -0
- package/src/memory-backend/local-backend.ts +30 -0
- package/src/memory-backend/off-backend.ts +16 -0
- package/src/memory-backend/resolve.ts +24 -0
- package/src/memory-backend/types.ts +79 -0
- package/src/modes/acp/acp-agent.ts +2170 -0
- package/src/modes/acp/acp-client-bridge.ts +154 -0
- package/src/modes/acp/acp-event-mapper.ts +879 -0
- package/src/modes/acp/acp-mode.ts +23 -0
- package/src/modes/acp/index.ts +2 -0
- package/src/modes/acp/terminal-auth.ts +37 -0
- package/src/modes/components/agent-dashboard.ts +1120 -0
- package/src/modes/components/assistant-message.ts +231 -0
- package/src/modes/components/bash-execution.ts +228 -0
- package/src/modes/components/bordered-loader.ts +41 -0
- package/src/modes/components/branch-summary-message.ts +45 -0
- package/src/modes/components/btw-panel.ts +104 -0
- package/src/modes/components/compaction-summary-message.ts +51 -0
- package/src/modes/components/countdown-timer.ts +75 -0
- package/src/modes/components/custom-editor.ts +237 -0
- package/src/modes/components/custom-message.ts +65 -0
- package/src/modes/components/diff.ts +266 -0
- package/src/modes/components/dynamic-border.ts +25 -0
- package/src/modes/components/eval-execution.ts +164 -0
- package/src/modes/components/execution-shared.ts +102 -0
- package/src/modes/components/extensions/extension-dashboard.ts +350 -0
- package/src/modes/components/extensions/extension-list.ts +492 -0
- package/src/modes/components/extensions/index.ts +9 -0
- package/src/modes/components/extensions/inspector-panel.ts +317 -0
- package/src/modes/components/extensions/state-manager.ts +628 -0
- package/src/modes/components/extensions/types.ts +191 -0
- package/src/modes/components/footer.ts +270 -0
- package/src/modes/components/history-search.ts +158 -0
- package/src/modes/components/hook-editor.ts +151 -0
- package/src/modes/components/hook-input.ts +79 -0
- package/src/modes/components/hook-message.ts +68 -0
- package/src/modes/components/hook-selector.ts +190 -0
- package/src/modes/components/index.ts +36 -0
- package/src/modes/components/keybinding-hints.ts +65 -0
- package/src/modes/components/login-dialog.ts +164 -0
- package/src/modes/components/message-frame.ts +88 -0
- package/src/modes/components/model-selector.ts +794 -0
- package/src/modes/components/oauth-selector.ts +248 -0
- package/src/modes/components/plugin-selector.ts +95 -0
- package/src/modes/components/plugin-settings.ts +488 -0
- package/src/modes/components/provider-onboarding-selector.ts +88 -0
- package/src/modes/components/queue-mode-selector.ts +56 -0
- package/src/modes/components/read-tool-group.ts +267 -0
- package/src/modes/components/runtime-mcp-add-wizard.ts +1341 -0
- package/src/modes/components/session-observer-overlay.ts +839 -0
- package/src/modes/components/session-selector.ts +343 -0
- package/src/modes/components/settings-defs.ts +175 -0
- package/src/modes/components/settings-selector.ts +635 -0
- package/src/modes/components/show-images-selector.ts +45 -0
- package/src/modes/components/skill-hud/render.ts +47 -0
- package/src/modes/components/skill-message.ts +90 -0
- package/src/modes/components/status-line/context-thresholds.ts +68 -0
- package/src/modes/components/status-line/git-utils.ts +42 -0
- package/src/modes/components/status-line/index.ts +4 -0
- package/src/modes/components/status-line/presets.ts +105 -0
- package/src/modes/components/status-line/segments.ts +560 -0
- package/src/modes/components/status-line/separators.ts +55 -0
- package/src/modes/components/status-line/token-rate.ts +66 -0
- package/src/modes/components/status-line/types.ts +93 -0
- package/src/modes/components/status-line.ts +839 -0
- package/src/modes/components/theme-selector.ts +63 -0
- package/src/modes/components/thinking-selector.ts +52 -0
- package/src/modes/components/todo-reminder.ts +40 -0
- package/src/modes/components/tool-execution.ts +830 -0
- package/src/modes/components/tree-selector.ts +930 -0
- package/src/modes/components/ttsr-notification.ts +80 -0
- package/src/modes/components/user-message-selector.ts +141 -0
- package/src/modes/components/user-message.ts +51 -0
- package/src/modes/components/visual-truncate.ts +63 -0
- package/src/modes/components/welcome.ts +389 -0
- package/src/modes/controllers/btw-controller.ts +105 -0
- package/src/modes/controllers/command-controller-shared.ts +108 -0
- package/src/modes/controllers/command-controller.ts +1630 -0
- package/src/modes/controllers/event-controller.ts +786 -0
- package/src/modes/controllers/extension-ui-controller.ts +927 -0
- package/src/modes/controllers/input-controller.ts +858 -0
- package/src/modes/controllers/runtime-mcp-command-controller.ts +1934 -0
- package/src/modes/controllers/selector-controller.ts +1039 -0
- package/src/modes/controllers/ssh-command-controller.ts +384 -0
- package/src/modes/controllers/todo-command-controller.ts +485 -0
- package/src/modes/data/emojis.json +1 -0
- package/src/modes/emoji-autocomplete.ts +285 -0
- package/src/modes/index.ts +34 -0
- package/src/modes/interactive-mode.ts +2756 -0
- package/src/modes/loop-limit.ts +140 -0
- package/src/modes/oauth-manual-input.ts +42 -0
- package/src/modes/print-mode.ts +121 -0
- package/src/modes/prompt-action-autocomplete.ts +345 -0
- package/src/modes/rpc/host-tools.ts +186 -0
- package/src/modes/rpc/host-uris.ts +235 -0
- package/src/modes/rpc/rpc-client.ts +810 -0
- package/src/modes/rpc/rpc-mode.ts +851 -0
- package/src/modes/rpc/rpc-types.ts +378 -0
- package/src/modes/runtime-init.ts +116 -0
- package/src/modes/session-observer-registry.ts +146 -0
- package/src/modes/shared.ts +55 -0
- package/src/modes/theme/dark.json +95 -0
- package/src/modes/theme/defaults/alabaster.json +93 -0
- package/src/modes/theme/defaults/amethyst.json +96 -0
- package/src/modes/theme/defaults/anthracite.json +93 -0
- package/src/modes/theme/defaults/basalt.json +91 -0
- package/src/modes/theme/defaults/birch.json +95 -0
- package/src/modes/theme/defaults/dark-abyss.json +91 -0
- package/src/modes/theme/defaults/dark-arctic.json +104 -0
- package/src/modes/theme/defaults/dark-aurora.json +95 -0
- package/src/modes/theme/defaults/dark-catppuccin.json +107 -0
- package/src/modes/theme/defaults/dark-cavern.json +91 -0
- package/src/modes/theme/defaults/dark-copper.json +95 -0
- package/src/modes/theme/defaults/dark-cosmos.json +90 -0
- package/src/modes/theme/defaults/dark-cyberpunk.json +102 -0
- package/src/modes/theme/defaults/dark-dracula.json +98 -0
- package/src/modes/theme/defaults/dark-eclipse.json +91 -0
- package/src/modes/theme/defaults/dark-ember.json +95 -0
- package/src/modes/theme/defaults/dark-equinox.json +90 -0
- package/src/modes/theme/defaults/dark-forest.json +96 -0
- package/src/modes/theme/defaults/dark-github.json +105 -0
- package/src/modes/theme/defaults/dark-gruvbox.json +112 -0
- package/src/modes/theme/defaults/dark-lavender.json +95 -0
- package/src/modes/theme/defaults/dark-lunar.json +89 -0
- package/src/modes/theme/defaults/dark-midnight.json +95 -0
- package/src/modes/theme/defaults/dark-monochrome.json +94 -0
- package/src/modes/theme/defaults/dark-monokai.json +98 -0
- package/src/modes/theme/defaults/dark-nebula.json +90 -0
- package/src/modes/theme/defaults/dark-nord.json +97 -0
- package/src/modes/theme/defaults/dark-ocean.json +101 -0
- package/src/modes/theme/defaults/dark-one.json +100 -0
- package/src/modes/theme/defaults/dark-poimandres.json +142 -0
- package/src/modes/theme/defaults/dark-rainforest.json +91 -0
- package/src/modes/theme/defaults/dark-reef.json +91 -0
- package/src/modes/theme/defaults/dark-retro.json +92 -0
- package/src/modes/theme/defaults/dark-rose-pine.json +96 -0
- package/src/modes/theme/defaults/dark-sakura.json +95 -0
- package/src/modes/theme/defaults/dark-slate.json +95 -0
- package/src/modes/theme/defaults/dark-solarized.json +97 -0
- package/src/modes/theme/defaults/dark-solstice.json +90 -0
- package/src/modes/theme/defaults/dark-starfall.json +91 -0
- package/src/modes/theme/defaults/dark-sunset.json +99 -0
- package/src/modes/theme/defaults/dark-swamp.json +90 -0
- package/src/modes/theme/defaults/dark-synthwave.json +103 -0
- package/src/modes/theme/defaults/dark-taiga.json +91 -0
- package/src/modes/theme/defaults/dark-terminal.json +95 -0
- package/src/modes/theme/defaults/dark-tokyo-night.json +101 -0
- package/src/modes/theme/defaults/dark-tundra.json +91 -0
- package/src/modes/theme/defaults/dark-twilight.json +91 -0
- package/src/modes/theme/defaults/dark-volcanic.json +91 -0
- package/src/modes/theme/defaults/graphite.json +92 -0
- package/src/modes/theme/defaults/index.ts +201 -0
- package/src/modes/theme/defaults/light-arctic.json +107 -0
- package/src/modes/theme/defaults/light-aurora-day.json +91 -0
- package/src/modes/theme/defaults/light-canyon.json +91 -0
- package/src/modes/theme/defaults/light-catppuccin.json +106 -0
- package/src/modes/theme/defaults/light-cirrus.json +90 -0
- package/src/modes/theme/defaults/light-coral.json +95 -0
- package/src/modes/theme/defaults/light-cyberpunk.json +96 -0
- package/src/modes/theme/defaults/light-dawn.json +90 -0
- package/src/modes/theme/defaults/light-dunes.json +91 -0
- package/src/modes/theme/defaults/light-eucalyptus.json +95 -0
- package/src/modes/theme/defaults/light-forest.json +100 -0
- package/src/modes/theme/defaults/light-frost.json +95 -0
- package/src/modes/theme/defaults/light-github.json +115 -0
- package/src/modes/theme/defaults/light-glacier.json +91 -0
- package/src/modes/theme/defaults/light-gruvbox.json +108 -0
- package/src/modes/theme/defaults/light-haze.json +90 -0
- package/src/modes/theme/defaults/light-honeycomb.json +95 -0
- package/src/modes/theme/defaults/light-lagoon.json +91 -0
- package/src/modes/theme/defaults/light-lavender.json +95 -0
- package/src/modes/theme/defaults/light-meadow.json +91 -0
- package/src/modes/theme/defaults/light-mint.json +95 -0
- package/src/modes/theme/defaults/light-monochrome.json +101 -0
- package/src/modes/theme/defaults/light-ocean.json +99 -0
- package/src/modes/theme/defaults/light-one.json +99 -0
- package/src/modes/theme/defaults/light-opal.json +91 -0
- package/src/modes/theme/defaults/light-orchard.json +91 -0
- package/src/modes/theme/defaults/light-paper.json +95 -0
- package/src/modes/theme/defaults/light-poimandres.json +142 -0
- package/src/modes/theme/defaults/light-prism.json +90 -0
- package/src/modes/theme/defaults/light-retro.json +98 -0
- package/src/modes/theme/defaults/light-sand.json +95 -0
- package/src/modes/theme/defaults/light-savanna.json +91 -0
- package/src/modes/theme/defaults/light-solarized.json +102 -0
- package/src/modes/theme/defaults/light-soleil.json +90 -0
- package/src/modes/theme/defaults/light-sunset.json +99 -0
- package/src/modes/theme/defaults/light-synthwave.json +98 -0
- package/src/modes/theme/defaults/light-tokyo-night.json +111 -0
- package/src/modes/theme/defaults/light-wetland.json +91 -0
- package/src/modes/theme/defaults/light-zenith.json +89 -0
- package/src/modes/theme/defaults/limestone.json +94 -0
- package/src/modes/theme/defaults/mahogany.json +97 -0
- package/src/modes/theme/defaults/marble.json +93 -0
- package/src/modes/theme/defaults/obsidian.json +91 -0
- package/src/modes/theme/defaults/onyx.json +91 -0
- package/src/modes/theme/defaults/pearl.json +93 -0
- package/src/modes/theme/defaults/porcelain.json +91 -0
- package/src/modes/theme/defaults/quartz.json +96 -0
- package/src/modes/theme/defaults/red-claw.json +123 -0
- package/src/modes/theme/defaults/sandstone.json +95 -0
- package/src/modes/theme/defaults/titanium.json +90 -0
- package/src/modes/theme/light.json +93 -0
- package/src/modes/theme/mermaid-cache.ts +29 -0
- package/src/modes/theme/shimmer.ts +219 -0
- package/src/modes/theme/theme-schema.json +429 -0
- package/src/modes/theme/theme.ts +2413 -0
- package/src/modes/types.ts +313 -0
- package/src/modes/utils/context-usage.ts +335 -0
- package/src/modes/utils/hotkeys-markdown.ts +59 -0
- package/src/modes/utils/keybinding-matchers.ts +30 -0
- package/src/modes/utils/tools-markdown.ts +27 -0
- package/src/modes/utils/ui-helpers.ts +741 -0
- package/src/plan-mode/approved-plan.ts +163 -0
- package/src/plan-mode/state.ts +6 -0
- package/src/priority.json +37 -0
- package/src/prompts/agents/architect.md +79 -0
- package/src/prompts/agents/critic.md +55 -0
- package/src/prompts/agents/executor.md +45 -0
- package/src/prompts/agents/explore.md +58 -0
- package/src/prompts/agents/frontmatter.md +12 -0
- package/src/prompts/agents/init.md +34 -0
- package/src/prompts/agents/plan.md +49 -0
- package/src/prompts/agents/planner.md +49 -0
- package/src/prompts/agents/reviewer.md +141 -0
- package/src/prompts/agents/task.md +16 -0
- package/src/prompts/ci-green-request.md +36 -0
- package/src/prompts/commands/orchestrate.md +49 -0
- package/src/prompts/goals/goal-budget-limit.md +16 -0
- package/src/prompts/goals/goal-continuation.md +28 -0
- package/src/prompts/goals/goal-mode-active.md +23 -0
- package/src/prompts/memories/consolidation.md +30 -0
- package/src/prompts/memories/read-path.md +11 -0
- package/src/prompts/memories/stage_one_input.md +6 -0
- package/src/prompts/memories/stage_one_system.md +21 -0
- package/src/prompts/review-request.md +70 -0
- package/src/prompts/system/agent-creation-architect.md +75 -0
- package/src/prompts/system/agent-creation-user.md +6 -0
- package/src/prompts/system/auto-continue.md +1 -0
- package/src/prompts/system/btw-user.md +8 -0
- package/src/prompts/system/commit-message-system.md +2 -0
- package/src/prompts/system/custom-system-prompt.md +64 -0
- package/src/prompts/system/eager-todo.md +13 -0
- package/src/prompts/system/irc-incoming.md +8 -0
- package/src/prompts/system/plan-mode-active.md +116 -0
- package/src/prompts/system/plan-mode-approved.md +28 -0
- package/src/prompts/system/plan-mode-compact-instructions.md +16 -0
- package/src/prompts/system/plan-mode-reference.md +14 -0
- package/src/prompts/system/plan-mode-subagent.md +34 -0
- package/src/prompts/system/plan-mode-tool-decision-reminder.md +9 -0
- package/src/prompts/system/project-prompt.md +46 -0
- package/src/prompts/system/subagent-system-prompt.md +54 -0
- package/src/prompts/system/subagent-user-prompt.md +3 -0
- package/src/prompts/system/subagent-yield-reminder.md +12 -0
- package/src/prompts/system/system-prompt.md +267 -0
- package/src/prompts/system/title-system.md +2 -0
- package/src/prompts/system/ttsr-interrupt.md +7 -0
- package/src/prompts/system/ttsr-tool-reminder.md +5 -0
- package/src/prompts/system/web-search.md +25 -0
- package/src/prompts/tools/apply-patch.md +65 -0
- package/src/prompts/tools/ask.md +29 -0
- package/src/prompts/tools/ast-edit.md +39 -0
- package/src/prompts/tools/ast-grep.md +42 -0
- package/src/prompts/tools/async-result.md +8 -0
- package/src/prompts/tools/bash.md +39 -0
- package/src/prompts/tools/browser.md +70 -0
- package/src/prompts/tools/calculator.md +10 -0
- package/src/prompts/tools/checkpoint.md +16 -0
- package/src/prompts/tools/create-goal.md +3 -0
- package/src/prompts/tools/debug.md +33 -0
- package/src/prompts/tools/eval.md +75 -0
- package/src/prompts/tools/find.md +34 -0
- package/src/prompts/tools/get-goal.md +3 -0
- package/src/prompts/tools/github.md +20 -0
- package/src/prompts/tools/goal.md +18 -0
- package/src/prompts/tools/hashline.md +130 -0
- package/src/prompts/tools/image-gen.md +7 -0
- package/src/prompts/tools/inspect-image-system.md +20 -0
- package/src/prompts/tools/inspect-image.md +32 -0
- package/src/prompts/tools/irc.md +49 -0
- package/src/prompts/tools/job.md +19 -0
- package/src/prompts/tools/lsp.md +42 -0
- package/src/prompts/tools/patch.md +70 -0
- package/src/prompts/tools/read.md +82 -0
- package/src/prompts/tools/recall.md +5 -0
- package/src/prompts/tools/recipe.md +16 -0
- package/src/prompts/tools/reflect.md +5 -0
- package/src/prompts/tools/render-mermaid.md +9 -0
- package/src/prompts/tools/replace.md +36 -0
- package/src/prompts/tools/resolve.md +9 -0
- package/src/prompts/tools/retain.md +6 -0
- package/src/prompts/tools/rewind.md +13 -0
- package/src/prompts/tools/search-tool-bm25.md +33 -0
- package/src/prompts/tools/search.md +25 -0
- package/src/prompts/tools/ssh.md +35 -0
- package/src/prompts/tools/subagent.md +21 -0
- package/src/prompts/tools/task-summary.md +28 -0
- package/src/prompts/tools/task.md +79 -0
- package/src/prompts/tools/todo-write.md +50 -0
- package/src/prompts/tools/update-goal.md +3 -0
- package/src/prompts/tools/vim.md +98 -0
- package/src/prompts/tools/web-search.md +10 -0
- package/src/prompts/tools/write.md +14 -0
- package/src/registry/agent-registry.ts +140 -0
- package/src/runtime-mcp/client.ts +482 -0
- package/src/runtime-mcp/config-writer.ts +225 -0
- package/src/runtime-mcp/config.ts +365 -0
- package/src/runtime-mcp/discoverable-tool-metadata.ts +25 -0
- package/src/runtime-mcp/index.ts +29 -0
- package/src/runtime-mcp/json-rpc.ts +84 -0
- package/src/runtime-mcp/loader.ts +124 -0
- package/src/runtime-mcp/manager.ts +1172 -0
- package/src/runtime-mcp/oauth-discovery.ts +349 -0
- package/src/runtime-mcp/oauth-flow.ts +407 -0
- package/src/runtime-mcp/render.ts +123 -0
- package/src/runtime-mcp/smithery-auth.ts +104 -0
- package/src/runtime-mcp/smithery-connect.ts +145 -0
- package/src/runtime-mcp/smithery-registry.ts +477 -0
- package/src/runtime-mcp/tool-bridge.ts +416 -0
- package/src/runtime-mcp/tool-cache.ts +117 -0
- package/src/runtime-mcp/transports/http.ts +477 -0
- package/src/runtime-mcp/transports/index.ts +6 -0
- package/src/runtime-mcp/transports/stdio.ts +325 -0
- package/src/runtime-mcp/types.ts +423 -0
- package/src/sdk.ts +2064 -0
- package/src/secrets/index.ts +116 -0
- package/src/secrets/obfuscator.ts +277 -0
- package/src/secrets/regex.ts +21 -0
- package/src/session/agent-session.ts +8794 -0
- package/src/session/agent-storage.ts +466 -0
- package/src/session/artifacts.ts +135 -0
- package/src/session/auth-broker-config.ts +102 -0
- package/src/session/auth-storage.ts +23 -0
- package/src/session/blob-store.ts +168 -0
- package/src/session/client-bridge.ts +85 -0
- package/src/session/history-storage.ts +311 -0
- package/src/session/messages.ts +403 -0
- package/src/session/session-dump-format.ts +209 -0
- package/src/session/session-manager.ts +3333 -0
- package/src/session/session-storage.ts +389 -0
- package/src/session/streaming-output.ts +1093 -0
- package/src/session/tool-choice-queue.ts +213 -0
- package/src/session/yield-queue.ts +155 -0
- package/src/setup/model-onboarding-guidance.ts +36 -0
- package/src/setup/provider-onboarding.ts +195 -0
- package/src/skill-state/active-state.ts +272 -0
- package/src/slash-commands/acp-builtins.ts +46 -0
- package/src/slash-commands/builtin-registry.ts +955 -0
- package/src/slash-commands/helpers/context-report.ts +39 -0
- package/src/slash-commands/helpers/format.ts +46 -0
- package/src/slash-commands/helpers/mcp.ts +532 -0
- package/src/slash-commands/helpers/parse.ts +85 -0
- package/src/slash-commands/helpers/ssh.ts +195 -0
- package/src/slash-commands/helpers/todo.ts +279 -0
- package/src/slash-commands/helpers/usage-report.ts +91 -0
- package/src/slash-commands/types.ts +125 -0
- package/src/ssh/config-writer.ts +183 -0
- package/src/ssh/connection-manager.ts +482 -0
- package/src/ssh/ssh-executor.ts +133 -0
- package/src/ssh/sshfs-mount.ts +140 -0
- package/src/ssh/utils.ts +8 -0
- package/src/stt/downloader.ts +71 -0
- package/src/stt/index.ts +3 -0
- package/src/stt/recorder.ts +351 -0
- package/src/stt/setup.ts +52 -0
- package/src/stt/stt-controller.ts +160 -0
- package/src/stt/transcribe.py +70 -0
- package/src/stt/transcriber.ts +91 -0
- package/src/system-prompt.ts +581 -0
- package/src/task/agents.ts +162 -0
- package/src/task/commands.ts +135 -0
- package/src/task/discovery.ts +130 -0
- package/src/task/executor.ts +1564 -0
- package/src/task/gjc-command.ts +26 -0
- package/src/task/index.ts +1366 -0
- package/src/task/name-generator.ts +1577 -0
- package/src/task/output-manager.ts +107 -0
- package/src/task/parallel.ts +116 -0
- package/src/task/render.ts +1136 -0
- package/src/task/simple-mode.ts +27 -0
- package/src/task/subprocess-tool-registry.ts +88 -0
- package/src/task/types.ts +315 -0
- package/src/task/worktree.ts +506 -0
- package/src/thinking.ts +87 -0
- package/src/tool-discovery/tool-index.ts +400 -0
- package/src/tools/archive-reader.ts +321 -0
- package/src/tools/ask.ts +790 -0
- package/src/tools/ast-edit.ts +542 -0
- package/src/tools/ast-grep.ts +423 -0
- package/src/tools/auto-generated-guard.ts +305 -0
- package/src/tools/bash-command-fixup.ts +37 -0
- package/src/tools/bash-interactive.ts +388 -0
- package/src/tools/bash-interceptor.ts +67 -0
- package/src/tools/bash-pty-selection.ts +14 -0
- package/src/tools/bash-skill-urls.ts +248 -0
- package/src/tools/bash.ts +1061 -0
- package/src/tools/browser/attach.ts +175 -0
- package/src/tools/browser/launch.ts +651 -0
- package/src/tools/browser/readable.ts +95 -0
- package/src/tools/browser/registry.ts +194 -0
- package/src/tools/browser/render.ts +212 -0
- package/src/tools/browser/tab-protocol.ts +105 -0
- package/src/tools/browser/tab-supervisor.ts +577 -0
- package/src/tools/browser/tab-worker-entry.ts +21 -0
- package/src/tools/browser/tab-worker.ts +1054 -0
- package/src/tools/browser.ts +301 -0
- package/src/tools/calculator.ts +540 -0
- package/src/tools/checkpoint.ts +134 -0
- package/src/tools/conflict-detect.ts +672 -0
- package/src/tools/context.ts +39 -0
- package/src/tools/debug.ts +1014 -0
- package/src/tools/eval.ts +1101 -0
- package/src/tools/fetch.ts +1482 -0
- package/src/tools/file-recorder.ts +35 -0
- package/src/tools/find.ts +540 -0
- package/src/tools/fs-cache-invalidation.ts +28 -0
- package/src/tools/gh-format.ts +12 -0
- package/src/tools/gh-renderer.ts +428 -0
- package/src/tools/gh.ts +3499 -0
- package/src/tools/github-cache.ts +548 -0
- package/src/tools/grouped-file-output.ts +96 -0
- package/src/tools/hindsight-recall.ts +68 -0
- package/src/tools/hindsight-reflect.ts +57 -0
- package/src/tools/hindsight-retain.ts +56 -0
- package/src/tools/image-gen.ts +1248 -0
- package/src/tools/index.ts +519 -0
- package/src/tools/inspect-image-renderer.ts +103 -0
- package/src/tools/inspect-image.ts +165 -0
- package/src/tools/irc.ts +239 -0
- package/src/tools/job.ts +520 -0
- package/src/tools/json-tree.ts +243 -0
- package/src/tools/jtd-to-json-schema.ts +219 -0
- package/src/tools/jtd-to-typescript.ts +136 -0
- package/src/tools/jtd-utils.ts +102 -0
- package/src/tools/list-limit.ts +40 -0
- package/src/tools/match-line-format.ts +22 -0
- package/src/tools/output-meta.ts +754 -0
- package/src/tools/path-utils.ts +739 -0
- package/src/tools/plan-mode-guard.ts +68 -0
- package/src/tools/puppeteer/00_stealth_tampering.txt +63 -0
- package/src/tools/puppeteer/01_stealth_activity.txt +20 -0
- package/src/tools/puppeteer/02_stealth_hairline.txt +11 -0
- package/src/tools/puppeteer/03_stealth_botd.txt +384 -0
- package/src/tools/puppeteer/04_stealth_iframe.txt +81 -0
- package/src/tools/puppeteer/05_stealth_webgl.txt +75 -0
- package/src/tools/puppeteer/06_stealth_screen.txt +72 -0
- package/src/tools/puppeteer/07_stealth_fonts.txt +97 -0
- package/src/tools/puppeteer/08_stealth_audio.txt +51 -0
- package/src/tools/puppeteer/09_stealth_locale.txt +46 -0
- package/src/tools/puppeteer/10_stealth_plugins.txt +206 -0
- package/src/tools/puppeteer/11_stealth_hardware.txt +8 -0
- package/src/tools/puppeteer/12_stealth_codecs.txt +40 -0
- package/src/tools/puppeteer/13_stealth_worker.txt +74 -0
- package/src/tools/read.ts +2332 -0
- package/src/tools/recipe/index.ts +80 -0
- package/src/tools/recipe/render.ts +19 -0
- package/src/tools/recipe/runner.ts +219 -0
- package/src/tools/recipe/runners/cargo.ts +131 -0
- package/src/tools/recipe/runners/index.ts +8 -0
- package/src/tools/recipe/runners/just.ts +73 -0
- package/src/tools/recipe/runners/make.ts +101 -0
- package/src/tools/recipe/runners/pkg.ts +167 -0
- package/src/tools/recipe/runners/task.ts +72 -0
- package/src/tools/render-mermaid.ts +68 -0
- package/src/tools/render-utils.ts +774 -0
- package/src/tools/renderers.ts +75 -0
- package/src/tools/resolve.ts +258 -0
- package/src/tools/review.ts +252 -0
- package/src/tools/search-tool-bm25.ts +360 -0
- package/src/tools/search.ts +786 -0
- package/src/tools/sqlite-reader.ts +736 -0
- package/src/tools/ssh.ts +310 -0
- package/src/tools/subagent.ts +312 -0
- package/src/tools/todo-write.ts +695 -0
- package/src/tools/tool-errors.ts +62 -0
- package/src/tools/tool-result.ts +86 -0
- package/src/tools/tool-timeouts.ts +30 -0
- package/src/tools/vim.ts +949 -0
- package/src/tools/write.ts +953 -0
- package/src/tools/yield.ts +268 -0
- package/src/tui/code-cell.ts +201 -0
- package/src/tui/file-list.ts +55 -0
- package/src/tui/hyperlink.ts +126 -0
- package/src/tui/index.ts +12 -0
- package/src/tui/output-block.ts +150 -0
- package/src/tui/status-line.ts +39 -0
- package/src/tui/tree-list.ts +84 -0
- package/src/tui/types.ts +15 -0
- package/src/tui/utils.ts +103 -0
- package/src/utils/changelog.ts +98 -0
- package/src/utils/clipboard.ts +156 -0
- package/src/utils/command-args.ts +76 -0
- package/src/utils/commit-message-generator.ts +142 -0
- package/src/utils/edit-mode.ts +42 -0
- package/src/utils/event-bus.ts +33 -0
- package/src/utils/external-editor.ts +65 -0
- package/src/utils/file-display-mode.ts +45 -0
- package/src/utils/file-mentions.ts +376 -0
- package/src/utils/git.ts +1536 -0
- package/src/utils/image-loading.ts +102 -0
- package/src/utils/image-resize.ts +309 -0
- package/src/utils/lang-from-path.ts +239 -0
- package/src/utils/markit.ts +89 -0
- package/src/utils/open.ts +20 -0
- package/src/utils/session-color.ts +43 -0
- package/src/utils/shell-snapshot.ts +187 -0
- package/src/utils/sixel.ts +69 -0
- package/src/utils/title-generator.ts +223 -0
- package/src/utils/tool-choice.ts +33 -0
- package/src/utils/tools-manager.ts +363 -0
- package/src/vim/buffer.ts +309 -0
- package/src/vim/commands.ts +382 -0
- package/src/vim/engine.ts +2409 -0
- package/src/vim/parser.ts +134 -0
- package/src/vim/render.ts +252 -0
- package/src/vim/types.ts +197 -0
- package/src/web/kagi.ts +183 -0
- package/src/web/parallel.ts +349 -0
- package/src/web/scrapers/artifacthub.ts +207 -0
- package/src/web/scrapers/arxiv.ts +83 -0
- package/src/web/scrapers/aur.ts +162 -0
- package/src/web/scrapers/biorxiv.ts +133 -0
- package/src/web/scrapers/bluesky.ts +262 -0
- package/src/web/scrapers/brew.ts +172 -0
- package/src/web/scrapers/cheatsh.ts +68 -0
- package/src/web/scrapers/chocolatey.ts +196 -0
- package/src/web/scrapers/choosealicense.ts +95 -0
- package/src/web/scrapers/cisa-kev.ts +87 -0
- package/src/web/scrapers/clojars.ts +154 -0
- package/src/web/scrapers/coingecko.ts +177 -0
- package/src/web/scrapers/crates-io.ts +97 -0
- package/src/web/scrapers/crossref.ts +136 -0
- package/src/web/scrapers/devto.ts +147 -0
- package/src/web/scrapers/discogs.ts +306 -0
- package/src/web/scrapers/discourse.ts +197 -0
- package/src/web/scrapers/dockerhub.ts +138 -0
- package/src/web/scrapers/docs-rs.ts +653 -0
- package/src/web/scrapers/fdroid.ts +134 -0
- package/src/web/scrapers/firefox-addons.ts +191 -0
- package/src/web/scrapers/flathub.ts +223 -0
- package/src/web/scrapers/github-gist.ts +58 -0
- package/src/web/scrapers/github.ts +452 -0
- package/src/web/scrapers/gitlab.ts +401 -0
- package/src/web/scrapers/go-pkg.ts +266 -0
- package/src/web/scrapers/hackage.ts +140 -0
- package/src/web/scrapers/hackernews.ts +189 -0
- package/src/web/scrapers/hex.ts +105 -0
- package/src/web/scrapers/huggingface.ts +321 -0
- package/src/web/scrapers/iacr.ts +89 -0
- package/src/web/scrapers/index.ts +252 -0
- package/src/web/scrapers/jetbrains-marketplace.ts +159 -0
- package/src/web/scrapers/lemmy.ts +203 -0
- package/src/web/scrapers/lobsters.ts +175 -0
- package/src/web/scrapers/mastodon.ts +292 -0
- package/src/web/scrapers/maven.ts +138 -0
- package/src/web/scrapers/mdn.ts +173 -0
- package/src/web/scrapers/metacpan.ts +222 -0
- package/src/web/scrapers/musicbrainz.ts +250 -0
- package/src/web/scrapers/npm.ts +98 -0
- package/src/web/scrapers/nuget.ts +183 -0
- package/src/web/scrapers/nvd.ts +222 -0
- package/src/web/scrapers/ollama.ts +239 -0
- package/src/web/scrapers/open-vsx.ts +106 -0
- package/src/web/scrapers/opencorporates.ts +292 -0
- package/src/web/scrapers/openlibrary.ts +336 -0
- package/src/web/scrapers/orcid.ts +286 -0
- package/src/web/scrapers/osv.ts +176 -0
- package/src/web/scrapers/packagist.ts +160 -0
- package/src/web/scrapers/pub-dev.ts +143 -0
- package/src/web/scrapers/pubmed.ts +211 -0
- package/src/web/scrapers/pypi.ts +112 -0
- package/src/web/scrapers/rawg.ts +110 -0
- package/src/web/scrapers/readthedocs.ts +120 -0
- package/src/web/scrapers/reddit.ts +95 -0
- package/src/web/scrapers/repology.ts +251 -0
- package/src/web/scrapers/rfc.ts +201 -0
- package/src/web/scrapers/rubygems.ts +103 -0
- package/src/web/scrapers/searchcode.ts +189 -0
- package/src/web/scrapers/sec-edgar.ts +261 -0
- package/src/web/scrapers/semantic-scholar.ts +171 -0
- package/src/web/scrapers/snapcraft.ts +187 -0
- package/src/web/scrapers/sourcegraph.ts +336 -0
- package/src/web/scrapers/spdx.ts +108 -0
- package/src/web/scrapers/spotify.ts +198 -0
- package/src/web/scrapers/stackoverflow.ts +120 -0
- package/src/web/scrapers/terraform.ts +277 -0
- package/src/web/scrapers/tldr.ts +47 -0
- package/src/web/scrapers/twitter.ts +93 -0
- package/src/web/scrapers/types.ts +318 -0
- package/src/web/scrapers/utils.ts +109 -0
- package/src/web/scrapers/vimeo.ts +133 -0
- package/src/web/scrapers/vscode-marketplace.ts +187 -0
- package/src/web/scrapers/w3c.ts +156 -0
- package/src/web/scrapers/wikidata.ts +344 -0
- package/src/web/scrapers/wikipedia.ts +84 -0
- package/src/web/scrapers/youtube.ts +319 -0
- package/src/web/search/index.ts +288 -0
- package/src/web/search/provider.ts +173 -0
- package/src/web/search/providers/anthropic.ts +302 -0
- package/src/web/search/providers/base.ts +71 -0
- package/src/web/search/providers/brave.ts +149 -0
- package/src/web/search/providers/codex.ts +556 -0
- package/src/web/search/providers/exa.ts +193 -0
- package/src/web/search/providers/gemini.ts +455 -0
- package/src/web/search/providers/jina.ts +101 -0
- package/src/web/search/providers/kagi.ts +75 -0
- package/src/web/search/providers/kimi.ts +171 -0
- package/src/web/search/providers/parallel.ts +210 -0
- package/src/web/search/providers/perplexity.ts +575 -0
- package/src/web/search/providers/searxng.ts +309 -0
- package/src/web/search/providers/synthetic.ts +108 -0
- package/src/web/search/providers/tavily.ts +173 -0
- package/src/web/search/providers/utils.ts +128 -0
- package/src/web/search/providers/zai.ts +320 -0
- package/src/web/search/render.ts +299 -0
- package/src/web/search/types.ts +436 -0
- package/src/web/search/utils.ts +17 -0
- package/src/workspace-tree.ts +286 -0
|
@@ -0,0 +1,1835 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Patch application logic for the edit tool.
|
|
3
|
+
*
|
|
4
|
+
* Applies parsed diff hunks to file content using fuzzy matching
|
|
5
|
+
* for robust handling of whitespace and formatting differences.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import * as fs from "node:fs";
|
|
9
|
+
import * as path from "node:path";
|
|
10
|
+
import type { AgentToolResult } from "@gajae-code/agent-core";
|
|
11
|
+
import { isEnoent } from "@gajae-code/utils";
|
|
12
|
+
import * as z from "zod/v4";
|
|
13
|
+
import {
|
|
14
|
+
type FileDiagnosticsResult,
|
|
15
|
+
flushLspWritethroughBatch,
|
|
16
|
+
type WritethroughCallback,
|
|
17
|
+
type WritethroughDeferredHandle,
|
|
18
|
+
} from "../../lsp";
|
|
19
|
+
import type { ToolSession } from "../../tools";
|
|
20
|
+
import { assertEditableFile } from "../../tools/auto-generated-guard";
|
|
21
|
+
import {
|
|
22
|
+
invalidateFsScanAfterDelete,
|
|
23
|
+
invalidateFsScanAfterRename,
|
|
24
|
+
invalidateFsScanAfterWrite,
|
|
25
|
+
} from "../../tools/fs-cache-invalidation";
|
|
26
|
+
import { outputMeta } from "../../tools/output-meta";
|
|
27
|
+
import { resolveToCwd } from "../../tools/path-utils";
|
|
28
|
+
import { enforcePlanModeWrite, resolvePlanPath } from "../../tools/plan-mode-guard";
|
|
29
|
+
import { ToolError } from "../../tools/tool-errors";
|
|
30
|
+
import {
|
|
31
|
+
ApplyPatchError,
|
|
32
|
+
type DiffHunk,
|
|
33
|
+
generateUnifiedDiffString,
|
|
34
|
+
normalizeCreateContent,
|
|
35
|
+
parseDiffHunks,
|
|
36
|
+
} from "../diff";
|
|
37
|
+
import {
|
|
38
|
+
adjustIndentation,
|
|
39
|
+
convertLeadingTabsToSpaces,
|
|
40
|
+
countLeadingWhitespace,
|
|
41
|
+
detectLineEnding,
|
|
42
|
+
getLeadingWhitespace,
|
|
43
|
+
normalizeToLF,
|
|
44
|
+
restoreLineEndings,
|
|
45
|
+
stripBom,
|
|
46
|
+
} from "../normalize";
|
|
47
|
+
import { readEditFileText, serializeEditFileText } from "../read-file";
|
|
48
|
+
import type { EditToolDetails, LspBatchRequest } from "../renderer";
|
|
49
|
+
import {
|
|
50
|
+
type ContextLineResult,
|
|
51
|
+
DEFAULT_FUZZY_THRESHOLD,
|
|
52
|
+
findClosestSequenceMatch,
|
|
53
|
+
findContextLine,
|
|
54
|
+
findMatch,
|
|
55
|
+
type SequenceSearchResult,
|
|
56
|
+
seekSequence,
|
|
57
|
+
} from "./replace";
|
|
58
|
+
|
|
59
|
+
export type Operation = "create" | "delete" | "update";
|
|
60
|
+
|
|
61
|
+
export interface PatchInput {
|
|
62
|
+
path: string;
|
|
63
|
+
op: Operation;
|
|
64
|
+
rename?: string;
|
|
65
|
+
diff?: string;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export interface FileSystem {
|
|
69
|
+
exists(path: string): Promise<boolean>;
|
|
70
|
+
read(path: string): Promise<string>;
|
|
71
|
+
readBinary?: (path: string) => Promise<Uint8Array>;
|
|
72
|
+
write(path: string, content: string): Promise<void>;
|
|
73
|
+
delete(path: string): Promise<void>;
|
|
74
|
+
mkdir(path: string): Promise<void>;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
interface FileChange {
|
|
78
|
+
type: Operation;
|
|
79
|
+
path: string;
|
|
80
|
+
newPath?: string;
|
|
81
|
+
oldContent?: string;
|
|
82
|
+
newContent?: string;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export interface ApplyPatchResult {
|
|
86
|
+
change: FileChange;
|
|
87
|
+
warnings?: string[];
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export interface ApplyPatchOptions {
|
|
91
|
+
cwd: string;
|
|
92
|
+
dryRun?: boolean;
|
|
93
|
+
fuzzyThreshold?: number;
|
|
94
|
+
allowFuzzy?: boolean;
|
|
95
|
+
fs?: FileSystem;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
99
|
+
// Default File System
|
|
100
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
101
|
+
|
|
102
|
+
/** Default filesystem implementation using Bun APIs */
|
|
103
|
+
export const defaultFileSystem: FileSystem = {
|
|
104
|
+
async exists(path: string): Promise<boolean> {
|
|
105
|
+
return Bun.file(path).exists();
|
|
106
|
+
},
|
|
107
|
+
async read(path: string): Promise<string> {
|
|
108
|
+
return readEditFileText(path, path);
|
|
109
|
+
},
|
|
110
|
+
async readBinary(path: string): Promise<Uint8Array> {
|
|
111
|
+
return fs.promises.readFile(path);
|
|
112
|
+
},
|
|
113
|
+
async write(path: string, content: string): Promise<void> {
|
|
114
|
+
await Bun.write(path, await serializeEditFileText(path, path, content));
|
|
115
|
+
},
|
|
116
|
+
async delete(path: string): Promise<void> {
|
|
117
|
+
await fs.promises.unlink(path);
|
|
118
|
+
},
|
|
119
|
+
async mkdir(path: string): Promise<void> {
|
|
120
|
+
await fs.promises.mkdir(path, { recursive: true });
|
|
121
|
+
},
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
125
|
+
// Internal Types
|
|
126
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
127
|
+
|
|
128
|
+
interface Replacement {
|
|
129
|
+
startIndex: number;
|
|
130
|
+
oldLen: number;
|
|
131
|
+
newLines: string[];
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
type HunkVariantKind = "trim-common" | "dedupe-shared" | "collapse-repeated" | "single-line";
|
|
135
|
+
|
|
136
|
+
interface HunkVariant {
|
|
137
|
+
oldLines: string[];
|
|
138
|
+
newLines: string[];
|
|
139
|
+
kind: HunkVariantKind;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function isBlankLine(line: string): boolean {
|
|
143
|
+
return line.trim().length === 0;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function areEqualLines(left: string[], right: string[]): boolean {
|
|
147
|
+
if (left.length !== right.length) return false;
|
|
148
|
+
for (let i = 0; i < left.length; i++) {
|
|
149
|
+
if (left[i] !== right[i]) return false;
|
|
150
|
+
}
|
|
151
|
+
return true;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function areEqualTrimmedLines(left: string[], right: string[]): boolean {
|
|
155
|
+
if (left.length !== right.length) return false;
|
|
156
|
+
for (let i = 0; i < left.length; i++) {
|
|
157
|
+
if (left[i].trim() !== right[i].trim()) return false;
|
|
158
|
+
}
|
|
159
|
+
return true;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function getIndentChar(lines: string[]): string {
|
|
163
|
+
for (const line of lines) {
|
|
164
|
+
const ws = getLeadingWhitespace(line);
|
|
165
|
+
if (ws.length > 0) return ws[0];
|
|
166
|
+
}
|
|
167
|
+
return " ";
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function collectIndentDeltas(oldLines: string[], actualLines: string[]): number[] {
|
|
171
|
+
const deltas: number[] = [];
|
|
172
|
+
const lineCount = Math.min(oldLines.length, actualLines.length);
|
|
173
|
+
for (let i = 0; i < lineCount; i++) {
|
|
174
|
+
const oldLine = oldLines[i];
|
|
175
|
+
const actualLine = actualLines[i];
|
|
176
|
+
if (isBlankLine(oldLine) || isBlankLine(actualLine)) continue;
|
|
177
|
+
deltas.push(countLeadingWhitespace(actualLine) - countLeadingWhitespace(oldLine));
|
|
178
|
+
}
|
|
179
|
+
return deltas;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function applyIndentDelta(lines: string[], delta: number, indentChar: string): string[] {
|
|
183
|
+
return lines.map(line => {
|
|
184
|
+
if (isBlankLine(line)) return line;
|
|
185
|
+
if (delta > 0) return indentChar.repeat(delta) + line;
|
|
186
|
+
const toRemove = Math.min(-delta, countLeadingWhitespace(line));
|
|
187
|
+
return line.slice(toRemove);
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
function canConvertTabsToSpaces(oldLines: string[], actualLines: string[], spacesPerTab: number): boolean {
|
|
192
|
+
const lineCount = Math.min(oldLines.length, actualLines.length);
|
|
193
|
+
for (let i = 0; i < lineCount; i++) {
|
|
194
|
+
const oldLine = oldLines[i];
|
|
195
|
+
const actualLine = actualLines[i];
|
|
196
|
+
if (isBlankLine(oldLine) || isBlankLine(actualLine)) continue;
|
|
197
|
+
const oldIndent = getLeadingWhitespace(oldLine);
|
|
198
|
+
const actualIndent = getLeadingWhitespace(actualLine);
|
|
199
|
+
if (oldIndent.length === 0) continue;
|
|
200
|
+
if (actualIndent.length !== oldIndent.length * spacesPerTab) {
|
|
201
|
+
return false;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
return true;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
208
|
+
// Replacement Computation
|
|
209
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
210
|
+
|
|
211
|
+
/** Adjust indentation of newLines to match the delta between patternLines and actualLines */
|
|
212
|
+
function adjustLinesIndentation(patternLines: string[], actualLines: string[], newLines: string[]): string[] {
|
|
213
|
+
if (patternLines.length === 0 || actualLines.length === 0 || newLines.length === 0) {
|
|
214
|
+
return newLines;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// If pattern already matches actual exactly (including indentation), preserve agent's intended changes
|
|
218
|
+
if (areEqualLines(patternLines, actualLines)) {
|
|
219
|
+
return newLines;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// If the patch is purely an indentation change (same trimmed content), apply exactly as specified
|
|
223
|
+
if (areEqualTrimmedLines(patternLines, newLines)) {
|
|
224
|
+
return newLines;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
// Detect indent character from actual content
|
|
228
|
+
const indentChar = getIndentChar(actualLines);
|
|
229
|
+
|
|
230
|
+
let patternTabOnly = true;
|
|
231
|
+
let actualSpaceOnly = true;
|
|
232
|
+
let patternSpaceOnly = true;
|
|
233
|
+
let actualTabOnly = true;
|
|
234
|
+
let patternMixed = false;
|
|
235
|
+
let actualMixed = false;
|
|
236
|
+
|
|
237
|
+
for (const line of patternLines) {
|
|
238
|
+
if (line.trim().length === 0) continue;
|
|
239
|
+
const ws = getLeadingWhitespace(line);
|
|
240
|
+
if (ws.includes(" ")) patternTabOnly = false;
|
|
241
|
+
if (ws.includes("\t")) patternSpaceOnly = false;
|
|
242
|
+
if (ws.includes(" ") && ws.includes("\t")) patternMixed = true;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
for (const line of actualLines) {
|
|
246
|
+
if (line.trim().length === 0) continue;
|
|
247
|
+
const ws = getLeadingWhitespace(line);
|
|
248
|
+
if (ws.includes("\t")) actualSpaceOnly = false;
|
|
249
|
+
if (ws.includes(" ")) actualTabOnly = false;
|
|
250
|
+
if (ws.includes(" ") && ws.includes("\t")) actualMixed = true;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
if (!patternMixed && !actualMixed && patternTabOnly && actualSpaceOnly) {
|
|
254
|
+
let ratio: number | undefined;
|
|
255
|
+
const lineCount = Math.min(patternLines.length, actualLines.length);
|
|
256
|
+
let consistent = true;
|
|
257
|
+
for (let i = 0; i < lineCount; i++) {
|
|
258
|
+
const patternLine = patternLines[i];
|
|
259
|
+
const actualLine = actualLines[i];
|
|
260
|
+
if (patternLine.trim().length === 0 || actualLine.trim().length === 0) continue;
|
|
261
|
+
const patternIndent = countLeadingWhitespace(patternLine);
|
|
262
|
+
const actualIndent = countLeadingWhitespace(actualLine);
|
|
263
|
+
if (patternIndent === 0) continue;
|
|
264
|
+
if (actualIndent % patternIndent !== 0) {
|
|
265
|
+
consistent = false;
|
|
266
|
+
break;
|
|
267
|
+
}
|
|
268
|
+
const nextRatio = actualIndent / patternIndent;
|
|
269
|
+
if (!ratio) {
|
|
270
|
+
ratio = nextRatio;
|
|
271
|
+
} else if (ratio !== nextRatio) {
|
|
272
|
+
consistent = false;
|
|
273
|
+
break;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
if (consistent && ratio && canConvertTabsToSpaces(patternLines, actualLines, ratio)) {
|
|
278
|
+
return convertLeadingTabsToSpaces(newLines.join("\n"), ratio).split("\n");
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
// Reverse: pattern uses spaces, actual uses tabs — infer spaces = tabs * width + offset
|
|
283
|
+
// Collect (tabs, spaces) pairs from matched lines to solve for the model's tab rendering.
|
|
284
|
+
// With one data point: spaces = tabs * width (offset=0).
|
|
285
|
+
// With two+: solve ax + b via pairs with distinct tab counts.
|
|
286
|
+
if (!patternMixed && !actualMixed && patternSpaceOnly && actualTabOnly) {
|
|
287
|
+
const samples = new Map<number, number>(); // tabs -> spaces
|
|
288
|
+
const lineCount = Math.min(patternLines.length, actualLines.length);
|
|
289
|
+
let consistent = true;
|
|
290
|
+
for (let i = 0; i < lineCount; i++) {
|
|
291
|
+
const patternLine = patternLines[i];
|
|
292
|
+
const actualLine = actualLines[i];
|
|
293
|
+
if (patternLine.trim().length === 0 || actualLine.trim().length === 0) continue;
|
|
294
|
+
const spaces = countLeadingWhitespace(patternLine);
|
|
295
|
+
const tabs = countLeadingWhitespace(actualLine);
|
|
296
|
+
if (tabs === 0) continue;
|
|
297
|
+
const existing = samples.get(tabs);
|
|
298
|
+
if (existing !== undefined && existing !== spaces) {
|
|
299
|
+
consistent = false;
|
|
300
|
+
break;
|
|
301
|
+
}
|
|
302
|
+
samples.set(tabs, spaces);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
if (consistent && samples.size > 0) {
|
|
306
|
+
let tabWidth: number | undefined;
|
|
307
|
+
let offset = 0;
|
|
308
|
+
|
|
309
|
+
if (samples.size === 1) {
|
|
310
|
+
// One level: assume offset=0, width = spaces / tabs
|
|
311
|
+
const [[tabs, spaces]] = samples;
|
|
312
|
+
if (spaces % tabs === 0) {
|
|
313
|
+
tabWidth = spaces / tabs;
|
|
314
|
+
}
|
|
315
|
+
} else {
|
|
316
|
+
// Two+ levels: solve via any two distinct pairs
|
|
317
|
+
// spaces = tabs * width + offset => width = (s2 - s1) / (t2 - t1)
|
|
318
|
+
const entries = [...samples.entries()];
|
|
319
|
+
const [t1, s1] = entries[0];
|
|
320
|
+
const [t2, s2] = entries[1];
|
|
321
|
+
if (t1 !== t2) {
|
|
322
|
+
const w = (s2 - s1) / (t2 - t1);
|
|
323
|
+
if (w > 0 && Number.isInteger(w)) {
|
|
324
|
+
const b = s1 - t1 * w;
|
|
325
|
+
// Validate all samples against this model
|
|
326
|
+
let valid = true;
|
|
327
|
+
for (const [t, s] of samples) {
|
|
328
|
+
if (t * w + b !== s) {
|
|
329
|
+
valid = false;
|
|
330
|
+
break;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
if (valid) {
|
|
334
|
+
tabWidth = w;
|
|
335
|
+
offset = b;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
if (tabWidth !== undefined && tabWidth > 0) {
|
|
342
|
+
const converted = newLines.map(line => {
|
|
343
|
+
if (line.trim().length === 0) return line;
|
|
344
|
+
const ws = countLeadingWhitespace(line);
|
|
345
|
+
if (ws === 0) return line;
|
|
346
|
+
// Reverse: tabs = (spaces - offset) / width
|
|
347
|
+
const adjusted = ws - offset;
|
|
348
|
+
if (adjusted >= 0 && adjusted % tabWidth! === 0) {
|
|
349
|
+
return "\t".repeat(adjusted / tabWidth!) + line.slice(ws);
|
|
350
|
+
}
|
|
351
|
+
// Partial tab — keep remainder as spaces
|
|
352
|
+
const tabCount = Math.floor(adjusted / tabWidth!);
|
|
353
|
+
const remainder = adjusted - tabCount * tabWidth!;
|
|
354
|
+
if (tabCount >= 0) {
|
|
355
|
+
return "\t".repeat(tabCount) + " ".repeat(remainder) + line.slice(ws);
|
|
356
|
+
}
|
|
357
|
+
return line;
|
|
358
|
+
});
|
|
359
|
+
return converted;
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
// Build a map from trimmed content to actual lines (by content, not position)
|
|
365
|
+
// This handles fuzzy matches where pattern and actual may not be positionally aligned
|
|
366
|
+
const contentToActualLines = new Map<string, string[]>();
|
|
367
|
+
for (const line of actualLines) {
|
|
368
|
+
const trimmed = line.trim();
|
|
369
|
+
if (trimmed.length === 0) continue;
|
|
370
|
+
const arr = contentToActualLines.get(trimmed);
|
|
371
|
+
if (arr) {
|
|
372
|
+
arr.push(line);
|
|
373
|
+
} else {
|
|
374
|
+
contentToActualLines.set(trimmed, [line]);
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
let patternMin = Infinity;
|
|
379
|
+
for (const line of patternLines) {
|
|
380
|
+
if (line.trim().length === 0) continue;
|
|
381
|
+
patternMin = Math.min(patternMin, countLeadingWhitespace(line));
|
|
382
|
+
}
|
|
383
|
+
if (patternMin === Infinity) {
|
|
384
|
+
patternMin = 0;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
const deltas = collectIndentDeltas(patternLines, actualLines);
|
|
388
|
+
const delta = deltas.length > 0 && deltas.every(value => value === deltas[0]) ? deltas[0] : undefined;
|
|
389
|
+
|
|
390
|
+
// Track which actual lines we've used to handle duplicate content correctly
|
|
391
|
+
const usedActualLines = new Map<string, number>(); // trimmed content -> count used
|
|
392
|
+
|
|
393
|
+
return newLines.map(newLine => {
|
|
394
|
+
if (newLine.trim().length === 0) {
|
|
395
|
+
return newLine;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
const trimmed = newLine.trim();
|
|
399
|
+
const matchingActualLines = contentToActualLines.get(trimmed);
|
|
400
|
+
|
|
401
|
+
// Check if this is a context line (same trimmed content exists in actual)
|
|
402
|
+
if (matchingActualLines && matchingActualLines.length > 0) {
|
|
403
|
+
if (matchingActualLines.length === 1) {
|
|
404
|
+
return matchingActualLines[0];
|
|
405
|
+
}
|
|
406
|
+
if (matchingActualLines.includes(newLine)) {
|
|
407
|
+
return newLine;
|
|
408
|
+
}
|
|
409
|
+
const usedCount = usedActualLines.get(trimmed) ?? 0;
|
|
410
|
+
if (usedCount < matchingActualLines.length) {
|
|
411
|
+
usedActualLines.set(trimmed, usedCount + 1);
|
|
412
|
+
// Use actual file content directly for context lines
|
|
413
|
+
return matchingActualLines[usedCount];
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
// This is a new/added line - apply consistent delta if safe
|
|
418
|
+
if (delta && delta !== 0) {
|
|
419
|
+
const newIndent = countLeadingWhitespace(newLine);
|
|
420
|
+
if (newIndent === patternMin) {
|
|
421
|
+
return applyIndentDelta([newLine], delta, indentChar)[0];
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
return newLine;
|
|
425
|
+
});
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
function trimCommonContext(oldLines: string[], newLines: string[]): HunkVariant | undefined {
|
|
429
|
+
let start = 0;
|
|
430
|
+
let endOld = oldLines.length;
|
|
431
|
+
let endNew = newLines.length;
|
|
432
|
+
|
|
433
|
+
while (start < endOld && start < endNew && oldLines[start] === newLines[start]) {
|
|
434
|
+
start++;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
while (endOld > start && endNew > start && oldLines[endOld - 1] === newLines[endNew - 1]) {
|
|
438
|
+
endOld--;
|
|
439
|
+
endNew--;
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
if (start === 0 && endOld === oldLines.length && endNew === newLines.length) {
|
|
443
|
+
return undefined;
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
const trimmedOld = oldLines.slice(start, endOld);
|
|
447
|
+
const trimmedNew = newLines.slice(start, endNew);
|
|
448
|
+
if (trimmedOld.length === 0 && trimmedNew.length === 0) {
|
|
449
|
+
return undefined;
|
|
450
|
+
}
|
|
451
|
+
return { oldLines: trimmedOld, newLines: trimmedNew, kind: "trim-common" };
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
function collapseConsecutiveSharedLines(oldLines: string[], newLines: string[]): HunkVariant | undefined {
|
|
455
|
+
const shared = new Set(oldLines.filter(line => newLines.includes(line)));
|
|
456
|
+
const collapse = (lines: string[]): string[] => {
|
|
457
|
+
const out: string[] = [];
|
|
458
|
+
let i = 0;
|
|
459
|
+
while (i < lines.length) {
|
|
460
|
+
const line = lines[i];
|
|
461
|
+
out.push(line);
|
|
462
|
+
let j = i + 1;
|
|
463
|
+
while (j < lines.length && lines[j] === line && shared.has(line)) {
|
|
464
|
+
j++;
|
|
465
|
+
}
|
|
466
|
+
i = j;
|
|
467
|
+
}
|
|
468
|
+
return out;
|
|
469
|
+
};
|
|
470
|
+
|
|
471
|
+
const collapsedOld = collapse(oldLines);
|
|
472
|
+
const collapsedNew = collapse(newLines);
|
|
473
|
+
if (collapsedOld.length === oldLines.length && collapsedNew.length === newLines.length) {
|
|
474
|
+
return undefined;
|
|
475
|
+
}
|
|
476
|
+
return { oldLines: collapsedOld, newLines: collapsedNew, kind: "dedupe-shared" };
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
function collapseRepeatedBlocks(oldLines: string[], newLines: string[]): HunkVariant | undefined {
|
|
480
|
+
const shared = new Set(oldLines.filter(line => newLines.includes(line)));
|
|
481
|
+
const collapse = (lines: string[]): string[] => {
|
|
482
|
+
const output = [...lines];
|
|
483
|
+
let changed = false;
|
|
484
|
+
let i = 0;
|
|
485
|
+
while (i < output.length) {
|
|
486
|
+
let collapsed = false;
|
|
487
|
+
for (let size = Math.floor((output.length - i) / 2); size >= 2; size--) {
|
|
488
|
+
const first = output.slice(i, i + size);
|
|
489
|
+
const second = output.slice(i + size, i + size * 2);
|
|
490
|
+
if (first.length !== second.length || first.length === 0) continue;
|
|
491
|
+
if (!first.every(line => shared.has(line))) continue;
|
|
492
|
+
let same = true;
|
|
493
|
+
for (let idx = 0; idx < size; idx++) {
|
|
494
|
+
if (first[idx] !== second[idx]) {
|
|
495
|
+
same = false;
|
|
496
|
+
break;
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
if (same) {
|
|
500
|
+
output.splice(i + size, size);
|
|
501
|
+
changed = true;
|
|
502
|
+
collapsed = true;
|
|
503
|
+
break;
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
if (!collapsed) {
|
|
507
|
+
i++;
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
return changed ? output : lines;
|
|
511
|
+
};
|
|
512
|
+
|
|
513
|
+
const collapsedOld = collapse(oldLines);
|
|
514
|
+
const collapsedNew = collapse(newLines);
|
|
515
|
+
if (collapsedOld.length === oldLines.length && collapsedNew.length === newLines.length) {
|
|
516
|
+
return undefined;
|
|
517
|
+
}
|
|
518
|
+
return { oldLines: collapsedOld, newLines: collapsedNew, kind: "collapse-repeated" };
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
function reduceToSingleLineChange(oldLines: string[], newLines: string[]): HunkVariant | undefined {
|
|
522
|
+
if (oldLines.length !== newLines.length || oldLines.length === 0) return undefined;
|
|
523
|
+
let changedIndex: number | undefined;
|
|
524
|
+
for (let i = 0; i < oldLines.length; i++) {
|
|
525
|
+
if (oldLines[i] !== newLines[i]) {
|
|
526
|
+
if (changedIndex !== undefined) return undefined;
|
|
527
|
+
changedIndex = i;
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
if (changedIndex === undefined) return undefined;
|
|
531
|
+
return { oldLines: [oldLines[changedIndex]], newLines: [newLines[changedIndex]], kind: "single-line" };
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
function buildFallbackVariants(hunk: DiffHunk): HunkVariant[] {
|
|
535
|
+
const variants: HunkVariant[] = [];
|
|
536
|
+
const base: HunkVariant = { oldLines: hunk.oldLines, newLines: hunk.newLines, kind: "trim-common" };
|
|
537
|
+
|
|
538
|
+
const trimmed = trimCommonContext(base.oldLines, base.newLines);
|
|
539
|
+
if (trimmed) variants.push(trimmed);
|
|
540
|
+
|
|
541
|
+
const deduped = collapseConsecutiveSharedLines(
|
|
542
|
+
trimmed?.oldLines ?? base.oldLines,
|
|
543
|
+
trimmed?.newLines ?? base.newLines,
|
|
544
|
+
);
|
|
545
|
+
if (deduped) variants.push(deduped);
|
|
546
|
+
|
|
547
|
+
const collapsed = collapseRepeatedBlocks(
|
|
548
|
+
deduped?.oldLines ?? trimmed?.oldLines ?? base.oldLines,
|
|
549
|
+
deduped?.newLines ?? trimmed?.newLines ?? base.newLines,
|
|
550
|
+
);
|
|
551
|
+
if (collapsed) variants.push(collapsed);
|
|
552
|
+
|
|
553
|
+
const singleLine = reduceToSingleLineChange(trimmed?.oldLines ?? base.oldLines, trimmed?.newLines ?? base.newLines);
|
|
554
|
+
if (singleLine) variants.push(singleLine);
|
|
555
|
+
|
|
556
|
+
const seen = new Set<string>();
|
|
557
|
+
return variants.filter(variant => {
|
|
558
|
+
if (variant.oldLines.length === 0 && variant.newLines.length === 0) return false;
|
|
559
|
+
const key = `${variant.oldLines.join("\n")}||${variant.newLines.join("\n")}`;
|
|
560
|
+
if (seen.has(key)) return false;
|
|
561
|
+
seen.add(key);
|
|
562
|
+
return true;
|
|
563
|
+
});
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
function filterFallbackVariants(variants: HunkVariant[], allowAggressive: boolean): HunkVariant[] {
|
|
567
|
+
if (allowAggressive) return variants;
|
|
568
|
+
return variants.filter(variant => variant.kind !== "collapse-repeated" && variant.kind !== "single-line");
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
function findContextRelativeMatch(
|
|
572
|
+
lines: string[],
|
|
573
|
+
patternLine: string,
|
|
574
|
+
contextIndex: number,
|
|
575
|
+
preferSecondForwardMatch: boolean,
|
|
576
|
+
): number | undefined {
|
|
577
|
+
const trimmed = patternLine.trim();
|
|
578
|
+
const forwardMatches: number[] = [];
|
|
579
|
+
for (let i = contextIndex + 1; i < lines.length; i++) {
|
|
580
|
+
if (lines[i].trim() === trimmed) {
|
|
581
|
+
forwardMatches.push(i);
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
if (forwardMatches.length > 0) {
|
|
585
|
+
if (preferSecondForwardMatch && forwardMatches.length > 1) {
|
|
586
|
+
return forwardMatches[1];
|
|
587
|
+
}
|
|
588
|
+
return forwardMatches[0];
|
|
589
|
+
}
|
|
590
|
+
for (let i = contextIndex - 1; i >= 0; i--) {
|
|
591
|
+
if (lines[i].trim() === trimmed) {
|
|
592
|
+
return i;
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
return undefined;
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
const AMBIGUITY_HINT_WINDOW = 200;
|
|
599
|
+
const MATCH_PREVIEW_CONTEXT = 2;
|
|
600
|
+
const MATCH_PREVIEW_MAX_LEN = 80;
|
|
601
|
+
|
|
602
|
+
function formatSequenceMatchPreview(lines: string[], startIdx: number): string {
|
|
603
|
+
const start = Math.max(0, startIdx - MATCH_PREVIEW_CONTEXT);
|
|
604
|
+
const end = Math.min(lines.length, startIdx + MATCH_PREVIEW_CONTEXT + 1);
|
|
605
|
+
const previewLines = lines.slice(start, end);
|
|
606
|
+
return previewLines
|
|
607
|
+
.map((line, i) => {
|
|
608
|
+
const num = start + i + 1;
|
|
609
|
+
const truncated = line.length > MATCH_PREVIEW_MAX_LEN ? `${line.slice(0, MATCH_PREVIEW_MAX_LEN - 1)}…` : line;
|
|
610
|
+
return ` ${num} | ${truncated}`;
|
|
611
|
+
})
|
|
612
|
+
.join("\n");
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
function formatSequenceMatchPreviews(
|
|
616
|
+
lines: string[],
|
|
617
|
+
matchIndices: number[] | undefined,
|
|
618
|
+
matchCount: number | undefined,
|
|
619
|
+
): string | undefined {
|
|
620
|
+
if (!matchIndices || matchIndices.length === 0) return undefined;
|
|
621
|
+
const previews = matchIndices.map(index => formatSequenceMatchPreview(lines, index));
|
|
622
|
+
const moreMsg =
|
|
623
|
+
matchCount && matchCount > matchIndices.length ? ` (showing first ${matchIndices.length} of ${matchCount})` : "";
|
|
624
|
+
return `${previews.join("\n\n")}${moreMsg}`;
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
function chooseHintedMatch(
|
|
628
|
+
matchIndices: number[] | undefined,
|
|
629
|
+
hintIndex: number | undefined,
|
|
630
|
+
window: number,
|
|
631
|
+
): number | undefined {
|
|
632
|
+
if (!matchIndices || matchIndices.length === 0 || hintIndex === undefined) return undefined;
|
|
633
|
+
const candidates = matchIndices.filter(index => Math.abs(index - hintIndex) <= window);
|
|
634
|
+
if (candidates.length === 1) return candidates[0];
|
|
635
|
+
return undefined;
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
/** Get hint index from hunk's line number */
|
|
639
|
+
function getHunkHintIndex(hunk: DiffHunk, currentIndex: number): number | undefined {
|
|
640
|
+
if (hunk.oldStartLine === undefined) return undefined;
|
|
641
|
+
const hintIndex = Math.max(0, hunk.oldStartLine - 1);
|
|
642
|
+
return hintIndex >= currentIndex ? hintIndex : undefined;
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
/**
|
|
646
|
+
* Find hierarchical context in file lines.
|
|
647
|
+
*
|
|
648
|
+
* Handles three formats:
|
|
649
|
+
* 1. Simple context: "function foo" - find this line
|
|
650
|
+
* 2. Hierarchical (newline): "class Foo\nmethod" - find class, then method after it
|
|
651
|
+
* 3. Hierarchical (space): "class Foo method" - try as literal first, then split and search
|
|
652
|
+
*
|
|
653
|
+
* @returns The result from finding the final (innermost) context, or undefined if not found
|
|
654
|
+
*/
|
|
655
|
+
function findHierarchicalContext(
|
|
656
|
+
lines: string[],
|
|
657
|
+
context: string,
|
|
658
|
+
startFrom: number,
|
|
659
|
+
lineHint: number | undefined,
|
|
660
|
+
allowFuzzy: boolean,
|
|
661
|
+
): ContextLineResult {
|
|
662
|
+
// Check for newline-separated hierarchical contexts (from nested @@ anchors)
|
|
663
|
+
if (context.includes("\n")) {
|
|
664
|
+
const parts = context
|
|
665
|
+
.split("\n")
|
|
666
|
+
.map(p => p.trim())
|
|
667
|
+
.filter(p => p.length > 0);
|
|
668
|
+
let currentStart = startFrom;
|
|
669
|
+
|
|
670
|
+
for (let i = 0; i < parts.length; i++) {
|
|
671
|
+
const part = parts[i];
|
|
672
|
+
const isLast = i === parts.length - 1;
|
|
673
|
+
|
|
674
|
+
const result = findContextLine(lines, part, currentStart, { allowFuzzy });
|
|
675
|
+
|
|
676
|
+
if (result.matchCount !== undefined && result.matchCount > 1) {
|
|
677
|
+
if (isLast && lineHint !== undefined) {
|
|
678
|
+
const hintStart = Math.max(0, lineHint - 1);
|
|
679
|
+
if (hintStart >= currentStart) {
|
|
680
|
+
const hintedResult = findContextLine(lines, part, hintStart, { allowFuzzy });
|
|
681
|
+
if (hintedResult.index !== undefined) {
|
|
682
|
+
return { ...hintedResult, matchCount: 1, matchIndices: [hintedResult.index] };
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
return {
|
|
687
|
+
index: undefined,
|
|
688
|
+
confidence: result.confidence,
|
|
689
|
+
matchCount: result.matchCount,
|
|
690
|
+
matchIndices: result.matchIndices,
|
|
691
|
+
strategy: result.strategy,
|
|
692
|
+
};
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
if (result.index === undefined) {
|
|
696
|
+
if (isLast && lineHint !== undefined) {
|
|
697
|
+
const hintStart = Math.max(0, lineHint - 1);
|
|
698
|
+
if (hintStart >= currentStart) {
|
|
699
|
+
const hintedResult = findContextLine(lines, part, hintStart, { allowFuzzy });
|
|
700
|
+
if (hintedResult.index !== undefined) {
|
|
701
|
+
return { ...hintedResult, matchCount: 1, matchIndices: [hintedResult.index] };
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
return { index: undefined, confidence: result.confidence };
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
if (isLast) {
|
|
709
|
+
return result;
|
|
710
|
+
}
|
|
711
|
+
currentStart = result.index + 1;
|
|
712
|
+
}
|
|
713
|
+
return { index: undefined, confidence: 0 };
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
// Try literal context first
|
|
717
|
+
const spaceParts = context.split(/\s+/).filter(p => p.length > 0);
|
|
718
|
+
const hasSignatureChars = /[(){}[\]]/.test(context);
|
|
719
|
+
if (!hasSignatureChars && spaceParts.length > 2) {
|
|
720
|
+
const outer = spaceParts.slice(0, -1).join(" ");
|
|
721
|
+
const inner = spaceParts[spaceParts.length - 1];
|
|
722
|
+
const outerResult = findContextLine(lines, outer, startFrom, { allowFuzzy });
|
|
723
|
+
if (outerResult.matchCount !== undefined && outerResult.matchCount > 1) {
|
|
724
|
+
return {
|
|
725
|
+
index: undefined,
|
|
726
|
+
confidence: outerResult.confidence,
|
|
727
|
+
matchCount: outerResult.matchCount,
|
|
728
|
+
matchIndices: outerResult.matchIndices,
|
|
729
|
+
strategy: outerResult.strategy,
|
|
730
|
+
};
|
|
731
|
+
}
|
|
732
|
+
if (outerResult.index !== undefined) {
|
|
733
|
+
const innerResult = findContextLine(lines, inner, outerResult.index + 1, { allowFuzzy });
|
|
734
|
+
if (innerResult.index !== undefined) {
|
|
735
|
+
return innerResult.matchCount && innerResult.matchCount > 1
|
|
736
|
+
? { ...innerResult, matchCount: 1, matchIndices: [innerResult.index] }
|
|
737
|
+
: innerResult;
|
|
738
|
+
}
|
|
739
|
+
if (innerResult.matchCount !== undefined && innerResult.matchCount > 1) {
|
|
740
|
+
return {
|
|
741
|
+
...innerResult,
|
|
742
|
+
matchCount: 1,
|
|
743
|
+
matchIndices: innerResult.index !== undefined ? [innerResult.index] : innerResult.matchIndices,
|
|
744
|
+
};
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
const result = findContextLine(lines, context, startFrom, { allowFuzzy });
|
|
750
|
+
|
|
751
|
+
// If line hint exists and result is ambiguous or missing, try from hint
|
|
752
|
+
if ((result.index === undefined || (result.matchCount ?? 0) > 1) && lineHint !== undefined) {
|
|
753
|
+
const hintStart = Math.max(0, lineHint - 1);
|
|
754
|
+
const hintedResult = findContextLine(lines, context, hintStart, { allowFuzzy });
|
|
755
|
+
if (hintedResult.index !== undefined) {
|
|
756
|
+
return { ...hintedResult, matchCount: 1, matchIndices: [hintedResult.index] };
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
// If found uniquely, return it
|
|
761
|
+
if (result.index !== undefined && (result.matchCount ?? 0) <= 1) {
|
|
762
|
+
return result;
|
|
763
|
+
}
|
|
764
|
+
if (result.matchCount !== undefined && result.matchCount > 1) {
|
|
765
|
+
return result;
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
// Try from beginning if not found from current position
|
|
769
|
+
if (result.index === undefined && startFrom !== 0) {
|
|
770
|
+
const fromStartResult = findContextLine(lines, context, 0, { allowFuzzy });
|
|
771
|
+
if (fromStartResult.index !== undefined && (fromStartResult.matchCount ?? 0) <= 1) {
|
|
772
|
+
return fromStartResult;
|
|
773
|
+
}
|
|
774
|
+
if (fromStartResult.matchCount !== undefined && fromStartResult.matchCount > 1) {
|
|
775
|
+
return fromStartResult;
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
// Fallback: try space-separated hierarchical matching
|
|
780
|
+
// e.g., "class PatchTool constructor" -> find "class PatchTool", then "constructor" after it
|
|
781
|
+
if (!hasSignatureChars && spaceParts.length > 1) {
|
|
782
|
+
const outer = spaceParts.slice(0, -1).join(" ");
|
|
783
|
+
const inner = spaceParts[spaceParts.length - 1];
|
|
784
|
+
const outerResult = findContextLine(lines, outer, startFrom, { allowFuzzy });
|
|
785
|
+
|
|
786
|
+
if (outerResult.matchCount !== undefined && outerResult.matchCount > 1) {
|
|
787
|
+
return {
|
|
788
|
+
index: undefined,
|
|
789
|
+
confidence: outerResult.confidence,
|
|
790
|
+
matchCount: outerResult.matchCount,
|
|
791
|
+
matchIndices: outerResult.matchIndices,
|
|
792
|
+
strategy: outerResult.strategy,
|
|
793
|
+
};
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
if (outerResult.index === undefined) {
|
|
797
|
+
return { index: undefined, confidence: outerResult.confidence };
|
|
798
|
+
}
|
|
799
|
+
|
|
800
|
+
const innerResult = findContextLine(lines, inner, outerResult.index + 1, { allowFuzzy });
|
|
801
|
+
if (innerResult.index !== undefined) {
|
|
802
|
+
return innerResult.matchCount && innerResult.matchCount > 1
|
|
803
|
+
? { ...innerResult, matchCount: 1, matchIndices: [innerResult.index] }
|
|
804
|
+
: innerResult;
|
|
805
|
+
}
|
|
806
|
+
if (innerResult.matchCount !== undefined && innerResult.matchCount > 1) {
|
|
807
|
+
return {
|
|
808
|
+
...innerResult,
|
|
809
|
+
matchCount: 1,
|
|
810
|
+
matchIndices: innerResult.index !== undefined ? [innerResult.index] : innerResult.matchIndices,
|
|
811
|
+
};
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
|
|
815
|
+
return result;
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
/** Find sequence with optional hint position, returning full search result */
|
|
819
|
+
function findSequenceWithHint(
|
|
820
|
+
lines: string[],
|
|
821
|
+
pattern: string[],
|
|
822
|
+
currentIndex: number,
|
|
823
|
+
hintIndex: number | undefined,
|
|
824
|
+
eof: boolean,
|
|
825
|
+
allowFuzzy: boolean,
|
|
826
|
+
): SequenceSearchResult {
|
|
827
|
+
// Prefer content-based search starting from currentIndex
|
|
828
|
+
const primaryResult = seekSequence(lines, pattern, currentIndex, eof, { allowFuzzy });
|
|
829
|
+
if (
|
|
830
|
+
primaryResult.matchCount &&
|
|
831
|
+
primaryResult.matchCount > 1 &&
|
|
832
|
+
hintIndex !== undefined &&
|
|
833
|
+
hintIndex !== currentIndex
|
|
834
|
+
) {
|
|
835
|
+
const hintedResult = seekSequence(lines, pattern, hintIndex, eof, { allowFuzzy });
|
|
836
|
+
if (hintedResult.index !== undefined && (hintedResult.matchCount ?? 1) <= 1) {
|
|
837
|
+
return hintedResult;
|
|
838
|
+
}
|
|
839
|
+
if (hintedResult.matchCount && hintedResult.matchCount > 1) {
|
|
840
|
+
return hintedResult;
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
if (primaryResult.index !== undefined || (primaryResult.matchCount && primaryResult.matchCount > 1)) {
|
|
844
|
+
return primaryResult;
|
|
845
|
+
}
|
|
846
|
+
|
|
847
|
+
// Use line hint as a secondary bias only if needed
|
|
848
|
+
if (hintIndex !== undefined && hintIndex !== currentIndex) {
|
|
849
|
+
const hintedResult = seekSequence(lines, pattern, hintIndex, eof, { allowFuzzy });
|
|
850
|
+
if (hintedResult.index !== undefined || (hintedResult.matchCount && hintedResult.matchCount > 1)) {
|
|
851
|
+
return hintedResult;
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
// Last resort: search from beginning (handles out-of-order hunks)
|
|
856
|
+
if (currentIndex !== 0) {
|
|
857
|
+
const fromStartResult = seekSequence(lines, pattern, 0, eof, { allowFuzzy });
|
|
858
|
+
if (fromStartResult.index !== undefined || (fromStartResult.matchCount && fromStartResult.matchCount > 1)) {
|
|
859
|
+
return fromStartResult;
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
|
|
863
|
+
return primaryResult;
|
|
864
|
+
}
|
|
865
|
+
|
|
866
|
+
function attemptSequenceFallback(
|
|
867
|
+
lines: string[],
|
|
868
|
+
hunk: DiffHunk,
|
|
869
|
+
currentIndex: number,
|
|
870
|
+
lineHint: number | undefined,
|
|
871
|
+
allowFuzzy: boolean,
|
|
872
|
+
allowAggressiveFallbacks: boolean,
|
|
873
|
+
): number | undefined {
|
|
874
|
+
if (hunk.oldLines.length === 0) return undefined;
|
|
875
|
+
const matchHint = getHunkHintIndex(hunk, currentIndex);
|
|
876
|
+
const fallbackResult = findSequenceWithHint(
|
|
877
|
+
lines,
|
|
878
|
+
hunk.oldLines,
|
|
879
|
+
currentIndex,
|
|
880
|
+
matchHint ?? lineHint,
|
|
881
|
+
false,
|
|
882
|
+
allowFuzzy,
|
|
883
|
+
);
|
|
884
|
+
if (fallbackResult.index !== undefined && (fallbackResult.matchCount ?? 1) <= 1) {
|
|
885
|
+
const nextIndex = fallbackResult.index + 1;
|
|
886
|
+
if (nextIndex <= lines.length - hunk.oldLines.length) {
|
|
887
|
+
const secondMatch = seekSequence(lines, hunk.oldLines, nextIndex, false, { allowFuzzy });
|
|
888
|
+
if (secondMatch.index !== undefined) {
|
|
889
|
+
return undefined;
|
|
890
|
+
}
|
|
891
|
+
}
|
|
892
|
+
return fallbackResult.index;
|
|
893
|
+
}
|
|
894
|
+
|
|
895
|
+
for (const variant of filterFallbackVariants(buildFallbackVariants(hunk), allowAggressiveFallbacks)) {
|
|
896
|
+
if (variant.oldLines.length === 0) continue;
|
|
897
|
+
const variantResult = findSequenceWithHint(
|
|
898
|
+
lines,
|
|
899
|
+
variant.oldLines,
|
|
900
|
+
currentIndex,
|
|
901
|
+
matchHint ?? lineHint,
|
|
902
|
+
false,
|
|
903
|
+
allowFuzzy,
|
|
904
|
+
);
|
|
905
|
+
if (variantResult.index !== undefined && (variantResult.matchCount ?? 1) <= 1) {
|
|
906
|
+
return variantResult.index;
|
|
907
|
+
}
|
|
908
|
+
}
|
|
909
|
+
return undefined;
|
|
910
|
+
}
|
|
911
|
+
|
|
912
|
+
/**
|
|
913
|
+
* Apply a hunk using character-based fuzzy matching.
|
|
914
|
+
* Used when the hunk contains only -/+ lines without context.
|
|
915
|
+
*/
|
|
916
|
+
function applyCharacterMatch(
|
|
917
|
+
originalContent: string,
|
|
918
|
+
path: string,
|
|
919
|
+
hunk: DiffHunk,
|
|
920
|
+
fuzzyThreshold: number,
|
|
921
|
+
allowFuzzy: boolean,
|
|
922
|
+
): { content: string; warnings: string[] } {
|
|
923
|
+
const oldText = hunk.oldLines.join("\n");
|
|
924
|
+
const newText = hunk.newLines.join("\n");
|
|
925
|
+
|
|
926
|
+
const normalizedContent = normalizeToLF(originalContent);
|
|
927
|
+
const normalizedOldText = normalizeToLF(oldText);
|
|
928
|
+
|
|
929
|
+
let matchOutcome = findMatch(normalizedContent, normalizedOldText, {
|
|
930
|
+
allowFuzzy,
|
|
931
|
+
threshold: fuzzyThreshold,
|
|
932
|
+
});
|
|
933
|
+
if (!matchOutcome.match && allowFuzzy) {
|
|
934
|
+
const relaxedThreshold = Math.min(fuzzyThreshold, 0.92);
|
|
935
|
+
if (relaxedThreshold < fuzzyThreshold) {
|
|
936
|
+
const relaxedOutcome = findMatch(normalizedContent, normalizedOldText, {
|
|
937
|
+
allowFuzzy,
|
|
938
|
+
threshold: relaxedThreshold,
|
|
939
|
+
});
|
|
940
|
+
if (relaxedOutcome.match) {
|
|
941
|
+
matchOutcome = relaxedOutcome;
|
|
942
|
+
}
|
|
943
|
+
}
|
|
944
|
+
}
|
|
945
|
+
|
|
946
|
+
// Check for multiple exact occurrences
|
|
947
|
+
if (matchOutcome.occurrences && matchOutcome.occurrences > 1) {
|
|
948
|
+
const previews = matchOutcome.occurrencePreviews?.join("\n\n") ?? "";
|
|
949
|
+
const moreMsg = matchOutcome.occurrences > 5 ? ` (showing first 5 of ${matchOutcome.occurrences})` : "";
|
|
950
|
+
throw new ApplyPatchError(
|
|
951
|
+
`Found ${matchOutcome.occurrences} occurrences in ${path}${moreMsg}:\n\n${previews}\n\n` +
|
|
952
|
+
`Add more context lines to disambiguate.`,
|
|
953
|
+
);
|
|
954
|
+
}
|
|
955
|
+
|
|
956
|
+
if (matchOutcome.fuzzyMatches && matchOutcome.fuzzyMatches > 1) {
|
|
957
|
+
throw new ApplyPatchError(
|
|
958
|
+
`Found ${matchOutcome.fuzzyMatches} high-confidence matches in ${path}. ` +
|
|
959
|
+
`The text must be unique. Please provide more context to make it unique.`,
|
|
960
|
+
);
|
|
961
|
+
}
|
|
962
|
+
|
|
963
|
+
if (!matchOutcome.match) {
|
|
964
|
+
const closest = matchOutcome.closest;
|
|
965
|
+
if (closest) {
|
|
966
|
+
const similarity = Math.round(closest.confidence * 100);
|
|
967
|
+
throw new ApplyPatchError(
|
|
968
|
+
`Could not find a close enough match in ${path}. ` +
|
|
969
|
+
`Closest match (${similarity}% similar) at line ${closest.startLine}.`,
|
|
970
|
+
);
|
|
971
|
+
}
|
|
972
|
+
throw new ApplyPatchError(`Failed to find expected lines in ${path}:\n${oldText}`);
|
|
973
|
+
}
|
|
974
|
+
|
|
975
|
+
// Adjust indentation to match what was actually found
|
|
976
|
+
const adjustedNewText = adjustIndentation(normalizedOldText, matchOutcome.match.actualText, newText);
|
|
977
|
+
|
|
978
|
+
const warnings: string[] = [];
|
|
979
|
+
if (matchOutcome.dominantFuzzy && matchOutcome.match) {
|
|
980
|
+
const similarity = Math.round(matchOutcome.match.confidence * 100);
|
|
981
|
+
warnings.push(
|
|
982
|
+
`Dominant fuzzy match selected in ${path} near line ${matchOutcome.match.startLine} (${similarity}% similar).`,
|
|
983
|
+
);
|
|
984
|
+
}
|
|
985
|
+
|
|
986
|
+
// Apply the replacement
|
|
987
|
+
const before = normalizedContent.substring(0, matchOutcome.match.startIndex);
|
|
988
|
+
const after = normalizedContent.substring(matchOutcome.match.startIndex + matchOutcome.match.actualText.length);
|
|
989
|
+
return { content: before + adjustedNewText + after, warnings };
|
|
990
|
+
}
|
|
991
|
+
|
|
992
|
+
function applyTrailingNewlinePolicy(content: string, hadFinalNewline: boolean): string {
|
|
993
|
+
if (hadFinalNewline) {
|
|
994
|
+
return content.endsWith("\n") ? content : `${content}\n`;
|
|
995
|
+
}
|
|
996
|
+
return content.replace(/\n+$/u, "");
|
|
997
|
+
}
|
|
998
|
+
|
|
999
|
+
async function readExistingPatchFile(fileSystem: FileSystem, absolutePath: string, path: string): Promise<string> {
|
|
1000
|
+
try {
|
|
1001
|
+
return await fileSystem.read(absolutePath);
|
|
1002
|
+
} catch (error) {
|
|
1003
|
+
if (isEnoent(error) || (error instanceof Error && error.message.startsWith("File not found:"))) {
|
|
1004
|
+
throw new ApplyPatchError(`File not found: ${path}`);
|
|
1005
|
+
}
|
|
1006
|
+
throw error;
|
|
1007
|
+
}
|
|
1008
|
+
}
|
|
1009
|
+
|
|
1010
|
+
/**
|
|
1011
|
+
* Compute replacements needed to transform originalLines using the diff hunks.
|
|
1012
|
+
*/
|
|
1013
|
+
function computeReplacements(
|
|
1014
|
+
originalLines: string[],
|
|
1015
|
+
path: string,
|
|
1016
|
+
hunks: DiffHunk[],
|
|
1017
|
+
allowFuzzy: boolean,
|
|
1018
|
+
): { replacements: Replacement[]; warnings: string[] } {
|
|
1019
|
+
const replacements: Replacement[] = [];
|
|
1020
|
+
const warnings: string[] = [];
|
|
1021
|
+
let lineIndex = 0;
|
|
1022
|
+
|
|
1023
|
+
for (const hunk of hunks) {
|
|
1024
|
+
let contextIndex: number | undefined;
|
|
1025
|
+
if (hunk.oldStartLine !== undefined && hunk.oldStartLine < 1) {
|
|
1026
|
+
throw new ApplyPatchError(
|
|
1027
|
+
`Line hint ${hunk.oldStartLine} is out of range for ${path} (line numbers start at 1)`,
|
|
1028
|
+
);
|
|
1029
|
+
}
|
|
1030
|
+
if (hunk.newStartLine !== undefined && hunk.newStartLine < 1) {
|
|
1031
|
+
throw new ApplyPatchError(
|
|
1032
|
+
`Line hint ${hunk.newStartLine} is out of range for ${path} (line numbers start at 1)`,
|
|
1033
|
+
);
|
|
1034
|
+
}
|
|
1035
|
+
const lineHint = hunk.oldStartLine;
|
|
1036
|
+
const allowAggressiveFallbacks = hunk.changeContext !== undefined || lineHint !== undefined || hunk.isEndOfFile;
|
|
1037
|
+
const fallbackVariants = filterFallbackVariants(buildFallbackVariants(hunk), allowAggressiveFallbacks);
|
|
1038
|
+
if (lineHint !== undefined && hunk.changeContext === undefined && !hunk.hasContextLines) {
|
|
1039
|
+
lineIndex = Math.max(0, Math.min(lineHint - 1, originalLines.length - 1));
|
|
1040
|
+
}
|
|
1041
|
+
|
|
1042
|
+
// If hunk has a changeContext, find it and adjust lineIndex
|
|
1043
|
+
if (hunk.changeContext !== undefined) {
|
|
1044
|
+
// Use hierarchical context matching for nested @@ anchors and space-separated contexts
|
|
1045
|
+
const result = findHierarchicalContext(originalLines, hunk.changeContext, lineIndex, lineHint, allowFuzzy);
|
|
1046
|
+
const idx = result.index;
|
|
1047
|
+
contextIndex = idx;
|
|
1048
|
+
|
|
1049
|
+
if (idx === undefined || (result.matchCount !== undefined && result.matchCount > 1)) {
|
|
1050
|
+
const fallback = attemptSequenceFallback(
|
|
1051
|
+
originalLines,
|
|
1052
|
+
hunk,
|
|
1053
|
+
lineIndex,
|
|
1054
|
+
lineHint,
|
|
1055
|
+
allowFuzzy,
|
|
1056
|
+
allowAggressiveFallbacks,
|
|
1057
|
+
);
|
|
1058
|
+
if (fallback !== undefined) {
|
|
1059
|
+
lineIndex = fallback;
|
|
1060
|
+
} else if (result.matchCount !== undefined && result.matchCount > 1) {
|
|
1061
|
+
const displayContext = hunk.changeContext.includes("\n")
|
|
1062
|
+
? hunk.changeContext.split("\n").pop()
|
|
1063
|
+
: hunk.changeContext;
|
|
1064
|
+
const previews = formatSequenceMatchPreviews(originalLines, result.matchIndices, result.matchCount);
|
|
1065
|
+
const strategyHint = result.strategy ? ` Matching strategy: ${result.strategy}.` : "";
|
|
1066
|
+
const previewText = previews ? `\n\n${previews}` : "";
|
|
1067
|
+
throw new ApplyPatchError(
|
|
1068
|
+
`Found ${result.matchCount} matches for context '${displayContext}' in ${path}.${strategyHint}` +
|
|
1069
|
+
`${previewText}\n\nAdd more surrounding context or additional @@ anchors to make it unique.`,
|
|
1070
|
+
);
|
|
1071
|
+
} else {
|
|
1072
|
+
const displayContext = hunk.changeContext.includes("\n")
|
|
1073
|
+
? hunk.changeContext.split("\n").join(" > ")
|
|
1074
|
+
: hunk.changeContext;
|
|
1075
|
+
throw new ApplyPatchError(`Failed to find context '${displayContext}' in ${path}`);
|
|
1076
|
+
}
|
|
1077
|
+
} else {
|
|
1078
|
+
// If oldLines[0] matches the final context, start search at idx (not idx+1)
|
|
1079
|
+
// This handles the common case where @@ scope and first context line are identical
|
|
1080
|
+
const firstOldLine = hunk.oldLines[0];
|
|
1081
|
+
const finalContext = hunk.changeContext.includes("\n")
|
|
1082
|
+
? hunk.changeContext.split("\n").pop()?.trim()
|
|
1083
|
+
: hunk.changeContext.trim();
|
|
1084
|
+
const isHierarchicalContext =
|
|
1085
|
+
hunk.changeContext.includes("\n") || hunk.changeContext.trim().split(/\s+/).length > 2;
|
|
1086
|
+
if (firstOldLine !== undefined && (firstOldLine.trim() === finalContext || isHierarchicalContext)) {
|
|
1087
|
+
lineIndex = idx;
|
|
1088
|
+
} else {
|
|
1089
|
+
lineIndex = idx + 1;
|
|
1090
|
+
}
|
|
1091
|
+
}
|
|
1092
|
+
}
|
|
1093
|
+
|
|
1094
|
+
if (hunk.oldLines.length === 0) {
|
|
1095
|
+
// Pure addition - prefer changeContext position, then line hint, then end of file
|
|
1096
|
+
let insertionIdx: number;
|
|
1097
|
+
if (hunk.changeContext !== undefined) {
|
|
1098
|
+
// changeContext was processed above; lineIndex is set to the context line or after it
|
|
1099
|
+
insertionIdx = lineIndex;
|
|
1100
|
+
} else {
|
|
1101
|
+
const lineHintForInsertion = hunk.oldStartLine ?? hunk.newStartLine;
|
|
1102
|
+
if (lineHintForInsertion !== undefined) {
|
|
1103
|
+
// Reject if line hint is out of range for insertion
|
|
1104
|
+
// Valid insertion points are 1 to (file length + 1) for 1-indexed hints
|
|
1105
|
+
if (lineHintForInsertion < 1) {
|
|
1106
|
+
throw new ApplyPatchError(
|
|
1107
|
+
`Line hint ${lineHintForInsertion} is out of range for insertion in ${path} ` +
|
|
1108
|
+
`(line numbers start at 1)`,
|
|
1109
|
+
);
|
|
1110
|
+
}
|
|
1111
|
+
if (lineHintForInsertion > originalLines.length + 1) {
|
|
1112
|
+
throw new ApplyPatchError(
|
|
1113
|
+
`Line hint ${lineHintForInsertion} is out of range for insertion in ${path} ` +
|
|
1114
|
+
`(file has ${originalLines.length} lines)`,
|
|
1115
|
+
);
|
|
1116
|
+
}
|
|
1117
|
+
insertionIdx = Math.max(0, lineHintForInsertion - 1);
|
|
1118
|
+
} else {
|
|
1119
|
+
insertionIdx =
|
|
1120
|
+
originalLines.length > 0 && originalLines[originalLines.length - 1] === ""
|
|
1121
|
+
? originalLines.length - 1
|
|
1122
|
+
: originalLines.length;
|
|
1123
|
+
}
|
|
1124
|
+
}
|
|
1125
|
+
|
|
1126
|
+
replacements.push({ startIndex: insertionIdx, oldLen: 0, newLines: [...hunk.newLines] });
|
|
1127
|
+
continue;
|
|
1128
|
+
}
|
|
1129
|
+
|
|
1130
|
+
// Try to find the old lines in the file
|
|
1131
|
+
let pattern = [...hunk.oldLines];
|
|
1132
|
+
const matchHint = getHunkHintIndex(hunk, lineIndex);
|
|
1133
|
+
let searchResult = findSequenceWithHint(
|
|
1134
|
+
originalLines,
|
|
1135
|
+
pattern,
|
|
1136
|
+
lineIndex,
|
|
1137
|
+
matchHint,
|
|
1138
|
+
hunk.isEndOfFile,
|
|
1139
|
+
allowFuzzy,
|
|
1140
|
+
);
|
|
1141
|
+
let newSlice = [...hunk.newLines];
|
|
1142
|
+
|
|
1143
|
+
// Retry without trailing empty line if present
|
|
1144
|
+
if (searchResult.index === undefined && pattern.length > 0 && pattern[pattern.length - 1] === "") {
|
|
1145
|
+
pattern = pattern.slice(0, -1);
|
|
1146
|
+
if (newSlice.length > 0 && newSlice[newSlice.length - 1] === "") {
|
|
1147
|
+
newSlice = newSlice.slice(0, -1);
|
|
1148
|
+
}
|
|
1149
|
+
searchResult = findSequenceWithHint(
|
|
1150
|
+
originalLines,
|
|
1151
|
+
pattern,
|
|
1152
|
+
lineIndex,
|
|
1153
|
+
matchHint,
|
|
1154
|
+
hunk.isEndOfFile,
|
|
1155
|
+
allowFuzzy,
|
|
1156
|
+
);
|
|
1157
|
+
}
|
|
1158
|
+
|
|
1159
|
+
if (searchResult.index === undefined || (searchResult.matchCount ?? 0) > 1) {
|
|
1160
|
+
for (const variant of fallbackVariants) {
|
|
1161
|
+
if (variant.oldLines.length === 0) continue;
|
|
1162
|
+
const variantResult = findSequenceWithHint(
|
|
1163
|
+
originalLines,
|
|
1164
|
+
variant.oldLines,
|
|
1165
|
+
lineIndex,
|
|
1166
|
+
matchHint,
|
|
1167
|
+
hunk.isEndOfFile,
|
|
1168
|
+
allowFuzzy,
|
|
1169
|
+
);
|
|
1170
|
+
if (variantResult.index !== undefined && (variantResult.matchCount ?? 1) <= 1) {
|
|
1171
|
+
pattern = variant.oldLines;
|
|
1172
|
+
newSlice = variant.newLines;
|
|
1173
|
+
searchResult = variantResult;
|
|
1174
|
+
break;
|
|
1175
|
+
}
|
|
1176
|
+
}
|
|
1177
|
+
}
|
|
1178
|
+
|
|
1179
|
+
if (searchResult.index === undefined && contextIndex !== undefined) {
|
|
1180
|
+
for (const variant of fallbackVariants) {
|
|
1181
|
+
if (variant.oldLines.length !== 1 || variant.newLines.length !== 1) continue;
|
|
1182
|
+
const removedLine = variant.oldLines[0];
|
|
1183
|
+
const hasSharedDuplicate = hunk.newLines.some(line => line.trim() === removedLine.trim());
|
|
1184
|
+
const adjacentIndex = findContextRelativeMatch(
|
|
1185
|
+
originalLines,
|
|
1186
|
+
removedLine,
|
|
1187
|
+
contextIndex,
|
|
1188
|
+
hasSharedDuplicate,
|
|
1189
|
+
);
|
|
1190
|
+
if (adjacentIndex !== undefined) {
|
|
1191
|
+
pattern = variant.oldLines;
|
|
1192
|
+
newSlice = variant.newLines;
|
|
1193
|
+
searchResult = { index: adjacentIndex, confidence: 0.95 };
|
|
1194
|
+
break;
|
|
1195
|
+
}
|
|
1196
|
+
}
|
|
1197
|
+
}
|
|
1198
|
+
|
|
1199
|
+
if (searchResult.index !== undefined && contextIndex !== undefined && pattern.length === 1) {
|
|
1200
|
+
const trimmed = pattern[0].trim();
|
|
1201
|
+
let occurrenceCount = 0;
|
|
1202
|
+
for (const line of originalLines) {
|
|
1203
|
+
if (line.trim() === trimmed) occurrenceCount++;
|
|
1204
|
+
}
|
|
1205
|
+
if (occurrenceCount > 1) {
|
|
1206
|
+
const hasSharedDuplicate = hunk.newLines.some(line => line.trim() === trimmed);
|
|
1207
|
+
const contextMatch = findContextRelativeMatch(originalLines, pattern[0], contextIndex, hasSharedDuplicate);
|
|
1208
|
+
if (contextMatch !== undefined) {
|
|
1209
|
+
searchResult = { index: contextMatch, confidence: searchResult.confidence ?? 0.95 };
|
|
1210
|
+
}
|
|
1211
|
+
}
|
|
1212
|
+
}
|
|
1213
|
+
|
|
1214
|
+
if ((searchResult.matchCount ?? 0) > 1) {
|
|
1215
|
+
const hintIndex = matchHint ?? (lineHint ? lineHint - 1 : undefined);
|
|
1216
|
+
const hinted = chooseHintedMatch(searchResult.matchIndices, hintIndex, AMBIGUITY_HINT_WINDOW);
|
|
1217
|
+
if (hinted !== undefined) {
|
|
1218
|
+
searchResult = { ...searchResult, index: hinted, matchCount: 1 };
|
|
1219
|
+
}
|
|
1220
|
+
}
|
|
1221
|
+
|
|
1222
|
+
if (searchResult.index === undefined) {
|
|
1223
|
+
if (searchResult.matchCount !== undefined && searchResult.matchCount > 1) {
|
|
1224
|
+
const previews = formatSequenceMatchPreviews(
|
|
1225
|
+
originalLines,
|
|
1226
|
+
searchResult.matchIndices,
|
|
1227
|
+
searchResult.matchCount,
|
|
1228
|
+
);
|
|
1229
|
+
const strategyHint = searchResult.strategy ? ` Matching strategy: ${searchResult.strategy}.` : "";
|
|
1230
|
+
const previewText = previews ? `\n\n${previews}` : "";
|
|
1231
|
+
throw new ApplyPatchError(
|
|
1232
|
+
`Found ${searchResult.matchCount} matches for the text in ${path}.${strategyHint}` +
|
|
1233
|
+
`${previewText}\n\nAdd more surrounding context or additional @@ anchors to make it unique.`,
|
|
1234
|
+
);
|
|
1235
|
+
}
|
|
1236
|
+
const closest = findClosestSequenceMatch(originalLines, pattern, {
|
|
1237
|
+
start: lineIndex,
|
|
1238
|
+
eof: hunk.isEndOfFile,
|
|
1239
|
+
});
|
|
1240
|
+
if (closest.index !== undefined && closest.confidence > 0) {
|
|
1241
|
+
const similarity = Math.round(closest.confidence * 100);
|
|
1242
|
+
const preview = formatSequenceMatchPreview(originalLines, closest.index);
|
|
1243
|
+
throw new ApplyPatchError(
|
|
1244
|
+
`Failed to find expected lines in ${path}:\n${hunk.oldLines.join("\n")}\n\n` +
|
|
1245
|
+
`Closest match (${similarity}% similar) near line ${closest.index + 1}:\n${preview}`,
|
|
1246
|
+
);
|
|
1247
|
+
}
|
|
1248
|
+
throw new ApplyPatchError(`Failed to find expected lines in ${path}:\n${hunk.oldLines.join("\n")}`);
|
|
1249
|
+
}
|
|
1250
|
+
|
|
1251
|
+
const found = searchResult.index;
|
|
1252
|
+
|
|
1253
|
+
if (searchResult.strategy === "fuzzy-dominant") {
|
|
1254
|
+
const similarity = Math.round(searchResult.confidence * 100);
|
|
1255
|
+
warnings.push(`Dominant fuzzy match selected in ${path} near line ${found + 1} (${similarity}% similar).`);
|
|
1256
|
+
}
|
|
1257
|
+
|
|
1258
|
+
// Reject if match is ambiguous (prefix/substring matching found multiple matches)
|
|
1259
|
+
if (searchResult.matchCount !== undefined && searchResult.matchCount > 1) {
|
|
1260
|
+
const previews = formatSequenceMatchPreviews(
|
|
1261
|
+
originalLines,
|
|
1262
|
+
searchResult.matchIndices,
|
|
1263
|
+
searchResult.matchCount,
|
|
1264
|
+
);
|
|
1265
|
+
const strategyHint = searchResult.strategy ? ` Matching strategy: ${searchResult.strategy}.` : "";
|
|
1266
|
+
const previewText = previews ? `\n\n${previews}` : "";
|
|
1267
|
+
throw new ApplyPatchError(
|
|
1268
|
+
`Found ${searchResult.matchCount} matches for the text in ${path}.${strategyHint}` +
|
|
1269
|
+
`${previewText}\n\nAdd more surrounding context or additional @@ anchors to make it unique.`,
|
|
1270
|
+
);
|
|
1271
|
+
}
|
|
1272
|
+
|
|
1273
|
+
// For simple diffs (no context marker, no context lines), check for multiple occurrences
|
|
1274
|
+
// This ensures ambiguous replacements are rejected
|
|
1275
|
+
// Skip this check if isEndOfFile is set (EOF marker provides disambiguation)
|
|
1276
|
+
if (hunk.changeContext === undefined && !hunk.hasContextLines && !hunk.isEndOfFile && lineHint === undefined) {
|
|
1277
|
+
const secondMatch = seekSequence(originalLines, pattern, found + 1, false, { allowFuzzy });
|
|
1278
|
+
if (secondMatch.index !== undefined) {
|
|
1279
|
+
const preview1 = formatSequenceMatchPreview(originalLines, found);
|
|
1280
|
+
const preview2 = formatSequenceMatchPreview(originalLines, secondMatch.index);
|
|
1281
|
+
throw new ApplyPatchError(
|
|
1282
|
+
`Found 2 occurrences in ${path}:\n\n${preview1}\n\n${preview2}\n\n` +
|
|
1283
|
+
`Add more context lines to disambiguate.`,
|
|
1284
|
+
);
|
|
1285
|
+
}
|
|
1286
|
+
}
|
|
1287
|
+
|
|
1288
|
+
// Adjust indentation if needed (handles fuzzy matches where indentation differs)
|
|
1289
|
+
const actualMatchedLines = originalLines.slice(found, found + pattern.length);
|
|
1290
|
+
|
|
1291
|
+
// Skip pure-context hunks (no +/- lines — oldLines === newLines).
|
|
1292
|
+
// They serve only to advance lineIndex for subsequent hunks.
|
|
1293
|
+
let isNoOp = pattern.length === newSlice.length;
|
|
1294
|
+
if (isNoOp) {
|
|
1295
|
+
for (let i = 0; i < pattern.length; i++) {
|
|
1296
|
+
if (pattern[i] !== newSlice[i]) {
|
|
1297
|
+
isNoOp = false;
|
|
1298
|
+
break;
|
|
1299
|
+
}
|
|
1300
|
+
}
|
|
1301
|
+
}
|
|
1302
|
+
|
|
1303
|
+
if (isNoOp) {
|
|
1304
|
+
lineIndex = found + pattern.length;
|
|
1305
|
+
continue;
|
|
1306
|
+
}
|
|
1307
|
+
|
|
1308
|
+
const adjustedNewLines = adjustLinesIndentation(pattern, actualMatchedLines, newSlice);
|
|
1309
|
+
replacements.push({ startIndex: found, oldLen: pattern.length, newLines: adjustedNewLines });
|
|
1310
|
+
lineIndex = found + pattern.length;
|
|
1311
|
+
}
|
|
1312
|
+
|
|
1313
|
+
// Sort by start index
|
|
1314
|
+
replacements.sort((a, b) => a.startIndex - b.startIndex);
|
|
1315
|
+
|
|
1316
|
+
for (let i = 1; i < replacements.length; i++) {
|
|
1317
|
+
const prev = replacements[i - 1];
|
|
1318
|
+
const next = replacements[i];
|
|
1319
|
+
const prevEnd = prev.startIndex + prev.oldLen;
|
|
1320
|
+
if (next.startIndex < prevEnd) {
|
|
1321
|
+
const formatRange = (replacement: Replacement): string => {
|
|
1322
|
+
if (replacement.oldLen === 0) {
|
|
1323
|
+
return `${replacement.startIndex + 1} (insertion)`;
|
|
1324
|
+
}
|
|
1325
|
+
return `${replacement.startIndex + 1}-${replacement.startIndex + replacement.oldLen}`;
|
|
1326
|
+
};
|
|
1327
|
+
const prevRange = formatRange(prev);
|
|
1328
|
+
const nextRange = formatRange(next);
|
|
1329
|
+
throw new ApplyPatchError(
|
|
1330
|
+
`Overlapping hunks detected in ${path} at lines ${prevRange} and ${nextRange}. ` +
|
|
1331
|
+
`Split hunks or add more context to avoid overlap.`,
|
|
1332
|
+
);
|
|
1333
|
+
}
|
|
1334
|
+
}
|
|
1335
|
+
|
|
1336
|
+
return { replacements, warnings };
|
|
1337
|
+
}
|
|
1338
|
+
|
|
1339
|
+
/**
|
|
1340
|
+
* Apply replacements to lines, returning the modified content.
|
|
1341
|
+
*/
|
|
1342
|
+
function applyReplacements(lines: string[], replacements: Replacement[]): string[] {
|
|
1343
|
+
const result = [...lines];
|
|
1344
|
+
|
|
1345
|
+
// Apply in reverse order to maintain indices
|
|
1346
|
+
for (let i = replacements.length - 1; i >= 0; i--) {
|
|
1347
|
+
const { startIndex, oldLen, newLines } = replacements[i];
|
|
1348
|
+
result.splice(startIndex, oldLen);
|
|
1349
|
+
result.splice(startIndex, 0, ...newLines);
|
|
1350
|
+
}
|
|
1351
|
+
|
|
1352
|
+
return result;
|
|
1353
|
+
}
|
|
1354
|
+
|
|
1355
|
+
/**
|
|
1356
|
+
* Apply diff hunks to file content.
|
|
1357
|
+
*/
|
|
1358
|
+
function applyHunksToContent(
|
|
1359
|
+
originalContent: string,
|
|
1360
|
+
path: string,
|
|
1361
|
+
hunks: DiffHunk[],
|
|
1362
|
+
fuzzyThreshold: number,
|
|
1363
|
+
allowFuzzy: boolean,
|
|
1364
|
+
): { content: string; warnings: string[] } {
|
|
1365
|
+
const hadFinalNewline = originalContent.endsWith("\n");
|
|
1366
|
+
|
|
1367
|
+
// Detect simple replace pattern: single hunk, no @@ context, no context lines, has old lines to match
|
|
1368
|
+
// Only use character-based matching when there are no hints to disambiguate
|
|
1369
|
+
if (hunks.length === 1) {
|
|
1370
|
+
const hunk = hunks[0];
|
|
1371
|
+
if (
|
|
1372
|
+
hunk.changeContext === undefined &&
|
|
1373
|
+
!hunk.hasContextLines &&
|
|
1374
|
+
hunk.oldLines.length > 0 &&
|
|
1375
|
+
hunk.oldStartLine === undefined && // No line hint to use for positioning
|
|
1376
|
+
!hunk.isEndOfFile // No EOF targeting (prefer end of file)
|
|
1377
|
+
) {
|
|
1378
|
+
const { content, warnings } = applyCharacterMatch(originalContent, path, hunk, fuzzyThreshold, allowFuzzy);
|
|
1379
|
+
return { content: applyTrailingNewlinePolicy(content, hadFinalNewline), warnings };
|
|
1380
|
+
}
|
|
1381
|
+
}
|
|
1382
|
+
|
|
1383
|
+
let originalLines = originalContent.split("\n");
|
|
1384
|
+
|
|
1385
|
+
// Track if we have a trailing empty element from the final newline
|
|
1386
|
+
// Only strip ONE trailing empty (the newline marker), preserve actual blank lines
|
|
1387
|
+
let strippedTrailingEmpty = false;
|
|
1388
|
+
if (hadFinalNewline && originalLines.length > 0 && originalLines[originalLines.length - 1] === "") {
|
|
1389
|
+
// Check if the second-to-last is also empty (actual blank line) - if so, only strip one
|
|
1390
|
+
originalLines = originalLines.slice(0, -1);
|
|
1391
|
+
strippedTrailingEmpty = true;
|
|
1392
|
+
}
|
|
1393
|
+
|
|
1394
|
+
const { replacements, warnings } = computeReplacements(originalLines, path, hunks, allowFuzzy);
|
|
1395
|
+
const newLines = applyReplacements(originalLines, replacements);
|
|
1396
|
+
|
|
1397
|
+
// Restore the trailing empty element if we stripped it
|
|
1398
|
+
if (strippedTrailingEmpty) {
|
|
1399
|
+
newLines.push("");
|
|
1400
|
+
}
|
|
1401
|
+
|
|
1402
|
+
const content = newLines.join("\n");
|
|
1403
|
+
return { content: applyTrailingNewlinePolicy(content, hadFinalNewline), warnings };
|
|
1404
|
+
}
|
|
1405
|
+
|
|
1406
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
1407
|
+
// Public API
|
|
1408
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
1409
|
+
|
|
1410
|
+
/**
|
|
1411
|
+
* Apply a patch operation to the filesystem.
|
|
1412
|
+
*/
|
|
1413
|
+
export async function applyPatch(input: PatchInput, options: ApplyPatchOptions): Promise<ApplyPatchResult> {
|
|
1414
|
+
return applyNormalizedPatch(input, options);
|
|
1415
|
+
}
|
|
1416
|
+
|
|
1417
|
+
/**
|
|
1418
|
+
* Apply a normalized patch operation to the filesystem.
|
|
1419
|
+
* @internal
|
|
1420
|
+
*/
|
|
1421
|
+
async function applyNormalizedPatch(input: PatchInput, options: ApplyPatchOptions): Promise<ApplyPatchResult> {
|
|
1422
|
+
const {
|
|
1423
|
+
cwd,
|
|
1424
|
+
dryRun = false,
|
|
1425
|
+
fs = defaultFileSystem,
|
|
1426
|
+
fuzzyThreshold = DEFAULT_FUZZY_THRESHOLD,
|
|
1427
|
+
allowFuzzy = true,
|
|
1428
|
+
} = options;
|
|
1429
|
+
|
|
1430
|
+
const resolvePath = (p: string): string => resolveToCwd(p, cwd);
|
|
1431
|
+
const absolutePath = resolvePath(input.path);
|
|
1432
|
+
const op = input.op ?? "update";
|
|
1433
|
+
|
|
1434
|
+
if (input.rename) {
|
|
1435
|
+
const destPath = resolvePath(input.rename);
|
|
1436
|
+
if (destPath === absolutePath) {
|
|
1437
|
+
throw new ApplyPatchError("rename path is the same as source path");
|
|
1438
|
+
}
|
|
1439
|
+
}
|
|
1440
|
+
|
|
1441
|
+
// Handle CREATE operation
|
|
1442
|
+
if (op === "create") {
|
|
1443
|
+
if (!input.diff) {
|
|
1444
|
+
throw new ApplyPatchError("Create operation requires diff (file content)");
|
|
1445
|
+
}
|
|
1446
|
+
// Strip + prefixes if present (handles diffs formatted as additions)
|
|
1447
|
+
const normalizedContent = normalizeCreateContent(input.diff);
|
|
1448
|
+
const content = normalizedContent.endsWith("\n") ? normalizedContent : `${normalizedContent}\n`;
|
|
1449
|
+
|
|
1450
|
+
if (!dryRun) {
|
|
1451
|
+
const parentDir = path.dirname(absolutePath);
|
|
1452
|
+
if (parentDir && parentDir !== ".") {
|
|
1453
|
+
await fs.mkdir(parentDir);
|
|
1454
|
+
}
|
|
1455
|
+
await fs.write(absolutePath, content);
|
|
1456
|
+
}
|
|
1457
|
+
|
|
1458
|
+
return {
|
|
1459
|
+
change: {
|
|
1460
|
+
type: "create",
|
|
1461
|
+
path: absolutePath,
|
|
1462
|
+
newContent: content,
|
|
1463
|
+
},
|
|
1464
|
+
};
|
|
1465
|
+
}
|
|
1466
|
+
|
|
1467
|
+
// Handle DELETE operation
|
|
1468
|
+
if (op === "delete") {
|
|
1469
|
+
const oldContent = await readExistingPatchFile(fs, absolutePath, input.path);
|
|
1470
|
+
if (!dryRun) {
|
|
1471
|
+
await fs.delete(absolutePath);
|
|
1472
|
+
}
|
|
1473
|
+
|
|
1474
|
+
return {
|
|
1475
|
+
change: {
|
|
1476
|
+
type: "delete",
|
|
1477
|
+
path: absolutePath,
|
|
1478
|
+
oldContent,
|
|
1479
|
+
},
|
|
1480
|
+
};
|
|
1481
|
+
}
|
|
1482
|
+
|
|
1483
|
+
// Handle UPDATE operation
|
|
1484
|
+
if (!input.diff) {
|
|
1485
|
+
throw new ApplyPatchError("Update operation requires diff (hunks)");
|
|
1486
|
+
}
|
|
1487
|
+
|
|
1488
|
+
const originalContent = await readExistingPatchFile(fs, absolutePath, input.path);
|
|
1489
|
+
const { bom: bomFromText, text: strippedContent } = stripBom(originalContent);
|
|
1490
|
+
let bom = bomFromText;
|
|
1491
|
+
if (!bom && fs.readBinary) {
|
|
1492
|
+
const bytes = await fs.readBinary(absolutePath);
|
|
1493
|
+
if (bytes.length >= 3 && bytes[0] === 0xef && bytes[1] === 0xbb && bytes[2] === 0xbf) {
|
|
1494
|
+
bom = "\uFEFF";
|
|
1495
|
+
}
|
|
1496
|
+
}
|
|
1497
|
+
const lineEnding = detectLineEnding(strippedContent);
|
|
1498
|
+
const normalizedContent = normalizeToLF(strippedContent);
|
|
1499
|
+
const hunks = parseDiffHunks(input.diff);
|
|
1500
|
+
|
|
1501
|
+
if (hunks.length === 0) {
|
|
1502
|
+
throw new ApplyPatchError("Diff contains no hunks");
|
|
1503
|
+
}
|
|
1504
|
+
|
|
1505
|
+
const { content: newContent, warnings } = applyHunksToContent(
|
|
1506
|
+
normalizedContent,
|
|
1507
|
+
input.path,
|
|
1508
|
+
hunks,
|
|
1509
|
+
fuzzyThreshold,
|
|
1510
|
+
allowFuzzy,
|
|
1511
|
+
);
|
|
1512
|
+
const finalContent = bom + restoreLineEndings(newContent, lineEnding);
|
|
1513
|
+
const destPath = input.rename ? resolvePath(input.rename) : absolutePath;
|
|
1514
|
+
const isMove = Boolean(input.rename) && destPath !== absolutePath;
|
|
1515
|
+
|
|
1516
|
+
if (!dryRun) {
|
|
1517
|
+
if (isMove) {
|
|
1518
|
+
const parentDir = path.dirname(destPath);
|
|
1519
|
+
if (parentDir && parentDir !== ".") {
|
|
1520
|
+
await fs.mkdir(parentDir);
|
|
1521
|
+
}
|
|
1522
|
+
await fs.write(destPath, finalContent);
|
|
1523
|
+
await fs.delete(absolutePath);
|
|
1524
|
+
} else {
|
|
1525
|
+
await fs.write(absolutePath, finalContent);
|
|
1526
|
+
}
|
|
1527
|
+
}
|
|
1528
|
+
|
|
1529
|
+
return {
|
|
1530
|
+
change: {
|
|
1531
|
+
type: "update",
|
|
1532
|
+
path: absolutePath,
|
|
1533
|
+
newPath: isMove ? destPath : undefined,
|
|
1534
|
+
oldContent: originalContent,
|
|
1535
|
+
newContent: finalContent,
|
|
1536
|
+
},
|
|
1537
|
+
warnings: warnings.length > 0 ? warnings : undefined,
|
|
1538
|
+
};
|
|
1539
|
+
}
|
|
1540
|
+
|
|
1541
|
+
/**
|
|
1542
|
+
* Preview what changes a patch would make without applying it.
|
|
1543
|
+
*/
|
|
1544
|
+
export async function previewPatch(input: PatchInput, options: ApplyPatchOptions): Promise<ApplyPatchResult> {
|
|
1545
|
+
return applyPatch(input, { ...options, dryRun: true });
|
|
1546
|
+
}
|
|
1547
|
+
|
|
1548
|
+
export async function computePatchDiff(
|
|
1549
|
+
input: PatchInput,
|
|
1550
|
+
cwd: string,
|
|
1551
|
+
options?: { fuzzyThreshold?: number; allowFuzzy?: boolean },
|
|
1552
|
+
): Promise<
|
|
1553
|
+
| {
|
|
1554
|
+
diff: string;
|
|
1555
|
+
firstChangedLine: number | undefined;
|
|
1556
|
+
}
|
|
1557
|
+
| {
|
|
1558
|
+
error: string;
|
|
1559
|
+
}
|
|
1560
|
+
> {
|
|
1561
|
+
try {
|
|
1562
|
+
const result = await previewPatch(input, {
|
|
1563
|
+
cwd,
|
|
1564
|
+
fuzzyThreshold: options?.fuzzyThreshold,
|
|
1565
|
+
allowFuzzy: options?.allowFuzzy,
|
|
1566
|
+
});
|
|
1567
|
+
const oldContent = result.change.oldContent ?? "";
|
|
1568
|
+
const newContent = result.change.newContent ?? "";
|
|
1569
|
+
const normalizedOld = normalizeToLF(stripBom(oldContent).text);
|
|
1570
|
+
const normalizedNew = normalizeToLF(stripBom(newContent).text);
|
|
1571
|
+
if (!normalizedOld && !normalizedNew) {
|
|
1572
|
+
return { diff: "", firstChangedLine: undefined };
|
|
1573
|
+
}
|
|
1574
|
+
return generateUnifiedDiffString(normalizedOld, normalizedNew);
|
|
1575
|
+
} catch (err) {
|
|
1576
|
+
return { error: err instanceof Error ? err.message : String(err) };
|
|
1577
|
+
}
|
|
1578
|
+
}
|
|
1579
|
+
|
|
1580
|
+
export const patchEditEntrySchema = z
|
|
1581
|
+
.object({
|
|
1582
|
+
op: z.enum(["create", "delete", "update"]).optional().describe("operation (default update)"),
|
|
1583
|
+
rename: z.string().describe("new path for move").optional(),
|
|
1584
|
+
diff: z.string().describe("diff hunks or full content for create").optional(),
|
|
1585
|
+
})
|
|
1586
|
+
.strict();
|
|
1587
|
+
|
|
1588
|
+
export const patchEditSchema = z
|
|
1589
|
+
.object({
|
|
1590
|
+
path: z.string().describe("file path"),
|
|
1591
|
+
edits: z.array(patchEditEntrySchema).min(1).describe("patch operations"),
|
|
1592
|
+
})
|
|
1593
|
+
.strict();
|
|
1594
|
+
|
|
1595
|
+
export type PatchEditEntry = z.infer<typeof patchEditEntrySchema>;
|
|
1596
|
+
export type PatchParams = z.infer<typeof patchEditSchema>;
|
|
1597
|
+
|
|
1598
|
+
export interface ExecutePatchSingleOptions {
|
|
1599
|
+
session: ToolSession;
|
|
1600
|
+
path: string;
|
|
1601
|
+
params: PatchEditEntry;
|
|
1602
|
+
signal?: AbortSignal;
|
|
1603
|
+
batchRequest?: LspBatchRequest;
|
|
1604
|
+
allowFuzzy: boolean;
|
|
1605
|
+
fuzzyThreshold: number;
|
|
1606
|
+
writethrough: WritethroughCallback;
|
|
1607
|
+
beginDeferredDiagnosticsForPath: (path: string) => WritethroughDeferredHandle;
|
|
1608
|
+
}
|
|
1609
|
+
|
|
1610
|
+
class LspFileSystem implements FileSystem {
|
|
1611
|
+
#lastDiagnostics: FileDiagnosticsResult | undefined;
|
|
1612
|
+
#fileCache: Record<string, Bun.BunFile> = {};
|
|
1613
|
+
|
|
1614
|
+
constructor(
|
|
1615
|
+
private readonly writethrough: WritethroughCallback,
|
|
1616
|
+
private readonly signal?: AbortSignal,
|
|
1617
|
+
private readonly batchRequest?: LspBatchRequest,
|
|
1618
|
+
private readonly deferredForPath?: (path: string) => WritethroughDeferredHandle,
|
|
1619
|
+
) {}
|
|
1620
|
+
|
|
1621
|
+
#getFile(path: string): Bun.BunFile {
|
|
1622
|
+
if (this.#fileCache[path]) {
|
|
1623
|
+
return this.#fileCache[path];
|
|
1624
|
+
}
|
|
1625
|
+
const file = Bun.file(path);
|
|
1626
|
+
this.#fileCache[path] = file;
|
|
1627
|
+
return file;
|
|
1628
|
+
}
|
|
1629
|
+
|
|
1630
|
+
async exists(path: string): Promise<boolean> {
|
|
1631
|
+
return this.#getFile(path).exists();
|
|
1632
|
+
}
|
|
1633
|
+
|
|
1634
|
+
async read(path: string): Promise<string> {
|
|
1635
|
+
return readEditFileText(path, path);
|
|
1636
|
+
}
|
|
1637
|
+
|
|
1638
|
+
async readBinary(path: string): Promise<Uint8Array> {
|
|
1639
|
+
const bytes = await fs.promises.readFile(path);
|
|
1640
|
+
return bytes;
|
|
1641
|
+
}
|
|
1642
|
+
|
|
1643
|
+
async write(path: string, content: string): Promise<void> {
|
|
1644
|
+
const file = this.#getFile(path);
|
|
1645
|
+
const finalContent = await serializeEditFileText(path, path, content);
|
|
1646
|
+
const deferredForPath = this.deferredForPath;
|
|
1647
|
+
const result = await this.writethrough(
|
|
1648
|
+
path,
|
|
1649
|
+
finalContent,
|
|
1650
|
+
this.signal,
|
|
1651
|
+
file,
|
|
1652
|
+
this.batchRequest,
|
|
1653
|
+
deferredForPath ? (dst: string) => deferredForPath(dst) : undefined,
|
|
1654
|
+
);
|
|
1655
|
+
if (result) {
|
|
1656
|
+
this.#lastDiagnostics = result;
|
|
1657
|
+
}
|
|
1658
|
+
}
|
|
1659
|
+
|
|
1660
|
+
async delete(path: string): Promise<void> {
|
|
1661
|
+
await this.#getFile(path).unlink();
|
|
1662
|
+
}
|
|
1663
|
+
|
|
1664
|
+
async mkdir(path: string): Promise<void> {
|
|
1665
|
+
await fs.promises.mkdir(path, { recursive: true });
|
|
1666
|
+
}
|
|
1667
|
+
|
|
1668
|
+
getDiagnostics(): FileDiagnosticsResult | undefined {
|
|
1669
|
+
return this.#lastDiagnostics;
|
|
1670
|
+
}
|
|
1671
|
+
}
|
|
1672
|
+
|
|
1673
|
+
function mergeDiagnosticsWithWarnings(
|
|
1674
|
+
diagnostics: FileDiagnosticsResult | undefined,
|
|
1675
|
+
warnings: string[],
|
|
1676
|
+
): FileDiagnosticsResult | undefined {
|
|
1677
|
+
if (warnings.length === 0) return diagnostics;
|
|
1678
|
+
const warningMessages = warnings.map(warning => `patch: ${warning}`);
|
|
1679
|
+
if (!diagnostics) {
|
|
1680
|
+
return {
|
|
1681
|
+
server: "patch",
|
|
1682
|
+
messages: warningMessages,
|
|
1683
|
+
summary: `Patch warnings: ${warnings.length}`,
|
|
1684
|
+
errored: false,
|
|
1685
|
+
};
|
|
1686
|
+
}
|
|
1687
|
+
return {
|
|
1688
|
+
...diagnostics,
|
|
1689
|
+
messages: [...warningMessages, ...diagnostics.messages],
|
|
1690
|
+
summary: `${diagnostics.summary}; Patch warnings: ${warnings.length}`,
|
|
1691
|
+
};
|
|
1692
|
+
}
|
|
1693
|
+
|
|
1694
|
+
export async function executePatchSingle(
|
|
1695
|
+
options: ExecutePatchSingleOptions,
|
|
1696
|
+
): Promise<AgentToolResult<EditToolDetails, typeof patchEditEntrySchema>> {
|
|
1697
|
+
const {
|
|
1698
|
+
session,
|
|
1699
|
+
path,
|
|
1700
|
+
params,
|
|
1701
|
+
signal,
|
|
1702
|
+
batchRequest,
|
|
1703
|
+
allowFuzzy,
|
|
1704
|
+
fuzzyThreshold,
|
|
1705
|
+
writethrough,
|
|
1706
|
+
beginDeferredDiagnosticsForPath,
|
|
1707
|
+
} = options;
|
|
1708
|
+
const { op: rawOp, rename, diff } = params;
|
|
1709
|
+
|
|
1710
|
+
const op: Operation = rawOp === "create" || rawOp === "delete" ? rawOp : "update";
|
|
1711
|
+
|
|
1712
|
+
enforcePlanModeWrite(session, path, { op, move: rename });
|
|
1713
|
+
const resolvedPath = resolvePlanPath(session, path);
|
|
1714
|
+
const resolvedRename = rename ? resolvePlanPath(session, rename) : undefined;
|
|
1715
|
+
|
|
1716
|
+
await assertEditableFile(resolvedPath, path);
|
|
1717
|
+
|
|
1718
|
+
// Capture pre-edit content so we can verify the write actually hit disk.
|
|
1719
|
+
// `LspFileSystem.writeFile` delegates to a writethrough callback that, in
|
|
1720
|
+
// some host integrations, has been observed to report success without
|
|
1721
|
+
// persisting bytes — leaving the tool to claim "Updated <path>" while the
|
|
1722
|
+
// file on disk is byte-identical to before. After the write we re-read
|
|
1723
|
+
// the file and assert the bytes match the expected newContent; relying
|
|
1724
|
+
// on stat (mtime/size) is unreliable because filesystems with coarse
|
|
1725
|
+
// timestamp resolution can record an unchanged mtime even when the
|
|
1726
|
+
// content was rewritten, and same-length rewrites leave size unchanged.
|
|
1727
|
+
let preEditContent: Uint8Array | undefined;
|
|
1728
|
+
if (op === "update") {
|
|
1729
|
+
try {
|
|
1730
|
+
preEditContent = await fs.promises.readFile(resolvedPath);
|
|
1731
|
+
} catch (err) {
|
|
1732
|
+
if (!isEnoent(err)) throw err;
|
|
1733
|
+
}
|
|
1734
|
+
}
|
|
1735
|
+
|
|
1736
|
+
const input: PatchInput = { path: resolvedPath, op, rename: resolvedRename, diff };
|
|
1737
|
+
const patchFileSystem = new LspFileSystem(writethrough, signal, batchRequest, beginDeferredDiagnosticsForPath);
|
|
1738
|
+
const result = await applyPatch(input, {
|
|
1739
|
+
cwd: session.cwd,
|
|
1740
|
+
fs: patchFileSystem,
|
|
1741
|
+
fuzzyThreshold,
|
|
1742
|
+
allowFuzzy,
|
|
1743
|
+
});
|
|
1744
|
+
|
|
1745
|
+
// Post-write verification: only meaningful for in-place updates where the
|
|
1746
|
+
// patch actually changes content and the file is not being renamed away.
|
|
1747
|
+
if (
|
|
1748
|
+
result.change.type === "update" &&
|
|
1749
|
+
!result.change.newPath &&
|
|
1750
|
+
preEditContent !== undefined &&
|
|
1751
|
+
result.change.oldContent !== undefined &&
|
|
1752
|
+
result.change.newContent !== undefined &&
|
|
1753
|
+
result.change.oldContent !== result.change.newContent
|
|
1754
|
+
) {
|
|
1755
|
+
let postEditContent: Uint8Array | undefined;
|
|
1756
|
+
try {
|
|
1757
|
+
postEditContent = await fs.promises.readFile(resolvedPath);
|
|
1758
|
+
} catch (err) {
|
|
1759
|
+
if (!isEnoent(err)) throw err;
|
|
1760
|
+
}
|
|
1761
|
+
const unchanged =
|
|
1762
|
+
postEditContent !== undefined &&
|
|
1763
|
+
postEditContent.length === preEditContent.length &&
|
|
1764
|
+
postEditContent.every((b, i) => b === preEditContent[i]);
|
|
1765
|
+
if (unchanged) {
|
|
1766
|
+
throw new ToolError(`edit appeared successful but file content did not change on disk: ${resolvedPath}`, {
|
|
1767
|
+
path: resolvedPath,
|
|
1768
|
+
});
|
|
1769
|
+
}
|
|
1770
|
+
}
|
|
1771
|
+
|
|
1772
|
+
if (resolvedRename) {
|
|
1773
|
+
invalidateFsScanAfterRename(resolvedPath, resolvedRename);
|
|
1774
|
+
} else if (result.change.type === "delete") {
|
|
1775
|
+
invalidateFsScanAfterDelete(resolvedPath);
|
|
1776
|
+
} else {
|
|
1777
|
+
invalidateFsScanAfterWrite(resolvedPath);
|
|
1778
|
+
}
|
|
1779
|
+
const effectiveRename = result.change.newPath ? rename : undefined;
|
|
1780
|
+
|
|
1781
|
+
let diffResult: { diff: string; firstChangedLine: number | undefined } = {
|
|
1782
|
+
diff: "",
|
|
1783
|
+
firstChangedLine: undefined,
|
|
1784
|
+
};
|
|
1785
|
+
if (result.change.type === "update" && result.change.oldContent && result.change.newContent) {
|
|
1786
|
+
const normalizedOld = normalizeToLF(stripBom(result.change.oldContent).text);
|
|
1787
|
+
const normalizedNew = normalizeToLF(stripBom(result.change.newContent).text);
|
|
1788
|
+
diffResult = generateUnifiedDiffString(normalizedOld, normalizedNew);
|
|
1789
|
+
}
|
|
1790
|
+
|
|
1791
|
+
let resultText: string;
|
|
1792
|
+
switch (result.change.type) {
|
|
1793
|
+
case "create":
|
|
1794
|
+
resultText = `Created ${path}`;
|
|
1795
|
+
break;
|
|
1796
|
+
case "delete":
|
|
1797
|
+
resultText = `Deleted ${path}`;
|
|
1798
|
+
break;
|
|
1799
|
+
case "update":
|
|
1800
|
+
resultText = effectiveRename ? `Updated and moved ${path} to ${effectiveRename}` : `Updated ${path}`;
|
|
1801
|
+
break;
|
|
1802
|
+
}
|
|
1803
|
+
|
|
1804
|
+
let diagnostics = patchFileSystem.getDiagnostics();
|
|
1805
|
+
if (op === "delete" && batchRequest?.flush) {
|
|
1806
|
+
const flushedDiagnostics = await flushLspWritethroughBatch(batchRequest.id, session.cwd, signal);
|
|
1807
|
+
diagnostics ??= flushedDiagnostics;
|
|
1808
|
+
}
|
|
1809
|
+
const mergedDiagnostics = mergeDiagnosticsWithWarnings(diagnostics, result.warnings ?? []);
|
|
1810
|
+
const meta = outputMeta()
|
|
1811
|
+
.diagnostics(mergedDiagnostics?.summary ?? "", mergedDiagnostics?.messages ?? [])
|
|
1812
|
+
.get();
|
|
1813
|
+
|
|
1814
|
+
const oldText = result.change.type !== "create" ? result.change.oldContent : undefined;
|
|
1815
|
+
const newText = result.change.type !== "delete" ? result.change.newContent : undefined;
|
|
1816
|
+
|
|
1817
|
+
return {
|
|
1818
|
+
content: [{ type: "text", text: resultText }],
|
|
1819
|
+
details: {
|
|
1820
|
+
diff: diffResult.diff,
|
|
1821
|
+
// When the patch moves the file, anchor the diff to the destination
|
|
1822
|
+
// path. ACP `ToolCallContent.diff.path` comes from this field, and
|
|
1823
|
+
// clients use it to open or focus the file post-change; pointing at
|
|
1824
|
+
// the (now-deleted) source navigates to nothing.
|
|
1825
|
+
path: result.change.newPath ?? resolvedPath,
|
|
1826
|
+
firstChangedLine: diffResult.firstChangedLine,
|
|
1827
|
+
diagnostics: mergedDiagnostics,
|
|
1828
|
+
op,
|
|
1829
|
+
move: effectiveRename,
|
|
1830
|
+
meta,
|
|
1831
|
+
oldText,
|
|
1832
|
+
newText,
|
|
1833
|
+
},
|
|
1834
|
+
};
|
|
1835
|
+
}
|