@code-yeongyu/senpi 2026.8.1 → 2026.8.3-3
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 +74 -0
- package/README.md +10 -0
- package/dist/cli/args.d.ts +2 -0
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +28 -0
- package/dist/cli/args.js.map +1 -1
- package/dist/cli/credential-print.d.ts +23 -0
- package/dist/cli/credential-print.d.ts.map +1 -0
- package/dist/cli/credential-print.js +116 -0
- package/dist/cli/credential-print.js.map +1 -0
- package/dist/client/index.d.ts +3 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +3 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/remote-session.d.ts +53 -0
- package/dist/client/remote-session.d.ts.map +1 -0
- package/dist/client/remote-session.js +340 -0
- package/dist/client/remote-session.js.map +1 -0
- package/dist/client/transcript.d.ts +12 -0
- package/dist/client/transcript.d.ts.map +1 -0
- package/dist/client/transcript.js +98 -0
- package/dist/client/transcript.js.map +1 -0
- package/dist/core/agent-session-runtime.d.ts.map +1 -1
- package/dist/core/agent-session-runtime.js +3 -0
- package/dist/core/agent-session-runtime.js.map +1 -1
- package/dist/core/agent-session.d.ts +40 -1
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +434 -53
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/auth-storage.d.ts +5 -0
- package/dist/core/auth-storage.d.ts.map +1 -1
- package/dist/core/auth-storage.js +72 -11
- package/dist/core/auth-storage.js.map +1 -1
- package/dist/core/dynamic-prompt/verification.d.ts +2 -2
- package/dist/core/dynamic-prompt/verification.d.ts.map +1 -1
- package/dist/core/dynamic-prompt/verification.js +2 -2
- package/dist/core/dynamic-prompt/verification.js.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/bounded-queue.d.ts +17 -0
- package/dist/core/extensions/builtin/claude-sdk-oauth/bounded-queue.d.ts.map +1 -0
- package/dist/core/extensions/builtin/claude-sdk-oauth/bounded-queue.js +56 -0
- package/dist/core/extensions/builtin/claude-sdk-oauth/bounded-queue.js.map +1 -0
- package/dist/core/extensions/builtin/claude-sdk-oauth/sdk-boundary.d.ts +1 -0
- package/dist/core/extensions/builtin/claude-sdk-oauth/sdk-boundary.d.ts.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/sdk-boundary.js.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-binding.d.ts +32 -0
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-binding.d.ts.map +1 -0
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-binding.js +43 -0
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-binding.js.map +1 -0
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-commit-boundary.d.ts +18 -0
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-commit-boundary.d.ts.map +1 -0
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-commit-boundary.js +46 -0
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-commit-boundary.js.map +1 -0
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-continuity.d.ts +81 -0
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-continuity.d.ts.map +1 -0
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-continuity.js +127 -0
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-continuity.js.map +1 -0
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-entry-annotations.d.ts +10 -0
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-entry-annotations.d.ts.map +1 -0
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-entry-annotations.js +34 -0
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-entry-annotations.js.map +1 -0
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-observability.d.ts +56 -0
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-observability.d.ts.map +1 -0
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-observability.js +174 -0
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-observability.js.map +1 -0
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-reaper.d.ts +24 -0
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-reaper.d.ts.map +1 -0
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-reaper.js +34 -0
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-reaper.js.map +1 -0
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-reattach.d.ts +34 -0
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-reattach.d.ts.map +1 -0
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-reattach.js +85 -0
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-reattach.js.map +1 -0
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-registry-pump.d.ts +2 -13
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-registry-pump.d.ts.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-registry-pump.js +34 -55
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-registry-pump.js.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-registry-wiring.d.ts.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-registry-wiring.js +35 -93
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-registry-wiring.js.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-registry.d.ts +13 -11
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-registry.d.ts.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-registry.js +44 -55
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-registry.js.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-stream.d.ts +3 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-stream.d.ts.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-stream.js +101 -126
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-stream.js.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-sync.d.ts +2 -31
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-sync.d.ts.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-sync.js +26 -98
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-sync.js.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-turn-claim.d.ts +14 -0
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-turn-claim.d.ts.map +1 -0
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-turn-claim.js +42 -0
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-turn-claim.js.map +1 -0
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-turn-types.d.ts +32 -0
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-turn-types.d.ts.map +1 -0
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-turn-types.js +8 -0
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-turn-types.js.map +1 -0
- package/dist/core/extensions/builtin/claude-sdk-oauth/stream-events.d.ts +16 -0
- package/dist/core/extensions/builtin/claude-sdk-oauth/stream-events.d.ts.map +1 -0
- package/dist/core/extensions/builtin/claude-sdk-oauth/stream-events.js +92 -0
- package/dist/core/extensions/builtin/claude-sdk-oauth/stream-events.js.map +1 -0
- package/dist/core/extensions/builtin/claude-sdk-oauth/stream.d.ts.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/stream.js +48 -88
- package/dist/core/extensions/builtin/claude-sdk-oauth/stream.js.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/tools.d.ts +1 -0
- package/dist/core/extensions/builtin/claude-sdk-oauth/tools.d.ts.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/tools.js +1 -0
- package/dist/core/extensions/builtin/claude-sdk-oauth/tools.js.map +1 -1
- package/dist/core/extensions/builtin/compaction/checkpoint-state.d.ts +18 -1
- package/dist/core/extensions/builtin/compaction/checkpoint-state.d.ts.map +1 -1
- package/dist/core/extensions/builtin/compaction/checkpoint-state.js +32 -0
- package/dist/core/extensions/builtin/compaction/checkpoint-state.js.map +1 -1
- package/dist/core/extensions/builtin/compaction/deterministic-fallback.d.ts +1 -1
- package/dist/core/extensions/builtin/compaction/deterministic-fallback.d.ts.map +1 -1
- package/dist/core/extensions/builtin/compaction/deterministic-fallback.js +4 -0
- package/dist/core/extensions/builtin/compaction/deterministic-fallback.js.map +1 -1
- package/dist/core/extensions/builtin/compaction/idle-retry.d.ts +21 -0
- package/dist/core/extensions/builtin/compaction/idle-retry.d.ts.map +1 -0
- package/dist/core/extensions/builtin/compaction/idle-retry.js +24 -0
- package/dist/core/extensions/builtin/compaction/idle-retry.js.map +1 -0
- package/dist/core/extensions/builtin/compaction/index.d.ts.map +1 -1
- package/dist/core/extensions/builtin/compaction/index.js +91 -13
- package/dist/core/extensions/builtin/compaction/index.js.map +1 -1
- package/dist/core/extensions/builtin/compaction/lane-policy.d.ts +71 -0
- package/dist/core/extensions/builtin/compaction/lane-policy.d.ts.map +1 -0
- package/dist/core/extensions/builtin/compaction/lane-policy.js +94 -0
- package/dist/core/extensions/builtin/compaction/lane-policy.js.map +1 -0
- package/dist/core/extensions/builtin/compaction/log.d.ts.map +1 -1
- package/dist/core/extensions/builtin/compaction/log.js +1 -0
- package/dist/core/extensions/builtin/compaction/log.js.map +1 -1
- package/dist/core/extensions/builtin/compaction/overflow-retry.d.ts +59 -0
- package/dist/core/extensions/builtin/compaction/overflow-retry.d.ts.map +1 -0
- package/dist/core/extensions/builtin/compaction/overflow-retry.js +155 -0
- package/dist/core/extensions/builtin/compaction/overflow-retry.js.map +1 -0
- package/dist/core/extensions/builtin/compaction/speculative.d.ts.map +1 -1
- package/dist/core/extensions/builtin/compaction/speculative.js +17 -98
- package/dist/core/extensions/builtin/compaction/speculative.js.map +1 -1
- package/dist/core/extensions/builtin/compaction/transient-failure.d.ts.map +1 -1
- package/dist/core/extensions/builtin/compaction/transient-failure.js +3 -0
- package/dist/core/extensions/builtin/compaction/transient-failure.js.map +1 -1
- package/dist/core/extensions/builtin/goal/continuation.d.ts +2 -1
- package/dist/core/extensions/builtin/goal/continuation.d.ts.map +1 -1
- package/dist/core/extensions/builtin/goal/continuation.js +2 -1
- package/dist/core/extensions/builtin/goal/continuation.js.map +1 -1
- package/dist/core/extensions/builtin/goal/index.d.ts.map +1 -1
- package/dist/core/extensions/builtin/goal/index.js +14 -1
- package/dist/core/extensions/builtin/goal/index.js.map +1 -1
- package/dist/core/extensions/builtin/goal/monitor-continuation.d.ts +3 -2
- package/dist/core/extensions/builtin/goal/monitor-continuation.d.ts.map +1 -1
- package/dist/core/extensions/builtin/goal/monitor-continuation.js +89 -46
- package/dist/core/extensions/builtin/goal/monitor-continuation.js.map +1 -1
- package/dist/core/extensions/builtin/goal/wait-progress.d.ts +11 -0
- package/dist/core/extensions/builtin/goal/wait-progress.d.ts.map +1 -0
- package/dist/core/extensions/builtin/goal/wait-progress.js +30 -0
- package/dist/core/extensions/builtin/goal/wait-progress.js.map +1 -0
- package/dist/core/extensions/builtin/goal/wait-ticker.d.ts +38 -0
- package/dist/core/extensions/builtin/goal/wait-ticker.d.ts.map +1 -0
- package/dist/core/extensions/builtin/goal/wait-ticker.js +71 -0
- package/dist/core/extensions/builtin/goal/wait-ticker.js.map +1 -0
- package/dist/core/extensions/builtin/gpt-apply-patch/apply.d.ts +1 -0
- package/dist/core/extensions/builtin/gpt-apply-patch/apply.d.ts.map +1 -1
- package/dist/core/extensions/builtin/gpt-apply-patch/apply.js +13 -1
- package/dist/core/extensions/builtin/gpt-apply-patch/apply.js.map +1 -1
- package/dist/core/extensions/builtin/gpt-apply-patch/index.d.ts +1 -1
- package/dist/core/extensions/builtin/gpt-apply-patch/index.d.ts.map +1 -1
- package/dist/core/extensions/builtin/gpt-apply-patch/index.js +1 -1
- package/dist/core/extensions/builtin/gpt-apply-patch/index.js.map +1 -1
- package/dist/core/extensions/builtin/gpt-apply-patch/tool.d.ts +1 -0
- package/dist/core/extensions/builtin/gpt-apply-patch/tool.d.ts.map +1 -1
- package/dist/core/extensions/builtin/gpt-apply-patch/tool.js +23 -5
- package/dist/core/extensions/builtin/gpt-apply-patch/tool.js.map +1 -1
- package/dist/core/extensions/builtin/loop-guard/detectors.d.ts.map +1 -1
- package/dist/core/extensions/builtin/loop-guard/detectors.js +42 -1
- package/dist/core/extensions/builtin/loop-guard/detectors.js.map +1 -1
- package/dist/core/extensions/builtin/mcp/health.d.ts.map +1 -1
- package/dist/core/extensions/builtin/mcp/health.js +2 -1
- package/dist/core/extensions/builtin/mcp/health.js.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/gpt-5.6.d.ts +1 -1
- package/dist/core/extensions/builtin/prompt-preset/gpt-5.6.d.ts.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/gpt-5.6.js +5 -3
- package/dist/core/extensions/builtin/prompt-preset/gpt-5.6.js.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/kimi-k3.d.ts.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/kimi-k3.js +8 -1
- package/dist/core/extensions/builtin/prompt-preset/kimi-k3.js.map +1 -1
- package/dist/core/extensions/builtin/rules/config.d.ts +3 -0
- package/dist/core/extensions/builtin/rules/config.d.ts.map +1 -0
- package/dist/core/extensions/builtin/rules/config.js +24 -0
- package/dist/core/extensions/builtin/rules/config.js.map +1 -0
- package/dist/core/extensions/builtin/rules/index.d.ts.map +1 -1
- package/dist/core/extensions/builtin/rules/index.js +5 -3
- package/dist/core/extensions/builtin/rules/index.js.map +1 -1
- package/dist/core/extensions/builtin/rules/rules/formatter.d.ts.map +1 -1
- package/dist/core/extensions/builtin/rules/rules/formatter.js +21 -5
- package/dist/core/extensions/builtin/rules/rules/formatter.js.map +1 -1
- package/dist/core/extensions/builtin/rules/rules/types.d.ts +1 -1
- package/dist/core/extensions/builtin/rules/rules/types.js.map +1 -1
- package/dist/core/extensions/builtin/service-tier.d.ts.map +1 -1
- package/dist/core/extensions/builtin/service-tier.js +2 -3
- package/dist/core/extensions/builtin/service-tier.js.map +1 -1
- package/dist/core/extensions/builtin/terminal/tools/context.d.ts +1 -1
- package/dist/core/extensions/builtin/terminal/tools/context.d.ts.map +1 -1
- package/dist/core/extensions/builtin/terminal/tools/context.js.map +1 -1
- package/dist/core/extensions/builtin/terminal/tools/monitor.d.ts.map +1 -1
- package/dist/core/extensions/builtin/terminal/tools/monitor.js +1 -0
- package/dist/core/extensions/builtin/terminal/tools/monitor.js.map +1 -1
- package/dist/core/extensions/builtin/tool-pair-guard/index.d.ts.map +1 -1
- package/dist/core/extensions/builtin/tool-pair-guard/index.js +1 -1
- package/dist/core/extensions/builtin/tool-pair-guard/index.js.map +1 -1
- package/dist/core/extensions/index.d.ts +1 -1
- package/dist/core/extensions/index.d.ts.map +1 -1
- package/dist/core/extensions/index.js.map +1 -1
- package/dist/core/extensions/loader.d.ts.map +1 -1
- package/dist/core/extensions/loader.js +14 -18
- package/dist/core/extensions/loader.js.map +1 -1
- package/dist/core/extensions/runner.d.ts +4 -1
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +18 -0
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/extensions/types.d.ts +16 -1
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/footer-data-provider.d.ts +10 -0
- package/dist/core/footer-data-provider.d.ts.map +1 -1
- package/dist/core/footer-data-provider.js +1 -1
- package/dist/core/footer-data-provider.js.map +1 -1
- package/dist/core/keybindings.d.ts +24 -0
- package/dist/core/keybindings.d.ts.map +1 -1
- package/dist/core/model-registry.d.ts +2 -1
- package/dist/core/model-registry.d.ts.map +1 -1
- package/dist/core/model-registry.js +3 -0
- package/dist/core/model-registry.js.map +1 -1
- package/dist/core/model-resolver.d.ts.map +1 -1
- package/dist/core/model-resolver.js +1 -0
- package/dist/core/model-resolver.js.map +1 -1
- package/dist/core/model-runtime.d.ts +2 -0
- package/dist/core/model-runtime.d.ts.map +1 -1
- package/dist/core/model-runtime.js +2 -2
- package/dist/core/model-runtime.js.map +1 -1
- package/dist/core/package-manager.d.ts +0 -1
- package/dist/core/package-manager.d.ts.map +1 -1
- package/dist/core/package-manager.js +18 -34
- package/dist/core/package-manager.js.map +1 -1
- package/dist/core/pi-manifest.d.ts +9 -0
- package/dist/core/pi-manifest.d.ts.map +1 -0
- package/dist/core/pi-manifest.js +25 -0
- package/dist/core/pi-manifest.js.map +1 -0
- package/dist/core/provider-composer.d.ts.map +1 -1
- package/dist/core/provider-composer.js +8 -3
- package/dist/core/provider-composer.js.map +1 -1
- package/dist/core/provider-display-names.d.ts.map +1 -1
- package/dist/core/provider-display-names.js +1 -0
- package/dist/core/provider-display-names.js.map +1 -1
- package/dist/core/resource-loader.d.ts +15 -0
- package/dist/core/resource-loader.d.ts.map +1 -1
- package/dist/core/resource-loader.js +55 -6
- package/dist/core/resource-loader.js.map +1 -1
- package/dist/core/retry-fallback/hint-policy.d.ts +29 -0
- package/dist/core/retry-fallback/hint-policy.d.ts.map +1 -0
- package/dist/core/retry-fallback/hint-policy.js +54 -0
- package/dist/core/retry-fallback/hint-policy.js.map +1 -0
- package/dist/core/retry-fallback/probe-scheduler.d.ts +60 -0
- package/dist/core/retry-fallback/probe-scheduler.d.ts.map +1 -0
- package/dist/core/retry-fallback/probe-scheduler.js +206 -0
- package/dist/core/retry-fallback/probe-scheduler.js.map +1 -0
- package/dist/core/retry-fallback/settings.d.ts +9 -0
- package/dist/core/retry-fallback/settings.d.ts.map +1 -1
- package/dist/core/retry-fallback/settings.js +14 -0
- package/dist/core/retry-fallback/settings.js.map +1 -1
- package/dist/core/session-log.js +1 -1
- package/dist/core/session-log.js.map +1 -1
- package/dist/core/settings-manager.d.ts +10 -1
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +21 -1
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/extensions/llama/provider.js +1 -1
- package/dist/extensions/llama/provider.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +44 -0
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive/components/assistant-message.d.ts +5 -2
- package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/assistant-message.js +16 -4
- package/dist/modes/interactive/components/assistant-message.js.map +1 -1
- package/dist/modes/interactive/components/continuity-notice.d.ts +21 -0
- package/dist/modes/interactive/components/continuity-notice.d.ts.map +1 -0
- package/dist/modes/interactive/components/continuity-notice.js +58 -0
- package/dist/modes/interactive/components/continuity-notice.js.map +1 -0
- package/dist/modes/interactive/components/custom-editor.d.ts +5 -0
- package/dist/modes/interactive/components/custom-editor.d.ts.map +1 -1
- package/dist/modes/interactive/components/custom-editor.js +22 -1
- package/dist/modes/interactive/components/custom-editor.js.map +1 -1
- package/dist/modes/interactive/components/markdown-transform.d.ts +3 -0
- package/dist/modes/interactive/components/markdown-transform.d.ts.map +1 -0
- package/dist/modes/interactive/components/markdown-transform.js +19 -0
- package/dist/modes/interactive/components/markdown-transform.js.map +1 -0
- package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/model-selector.js +4 -1
- package/dist/modes/interactive/components/model-selector.js.map +1 -1
- package/dist/modes/interactive/components/settings-selector.d.ts +6 -2
- package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-selector.js +20 -0
- package/dist/modes/interactive/components/settings-selector.js.map +1 -1
- package/dist/modes/interactive/components/user-message.d.ts +3 -1
- package/dist/modes/interactive/components/user-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/user-message.js +8 -2
- package/dist/modes/interactive/components/user-message.js.map +1 -1
- package/dist/modes/interactive/help-content.d.ts.map +1 -1
- package/dist/modes/interactive/help-content.js +1 -0
- package/dist/modes/interactive/help-content.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +21 -0
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +151 -50
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/theme/dark.json +1 -0
- package/dist/modes/interactive/theme/grok-day.json +1 -0
- package/dist/modes/interactive/theme/grok-night.json +1 -0
- package/dist/modes/interactive/theme/light.json +1 -0
- package/dist/modes/interactive/theme/theme-schema.json +5 -1
- package/dist/modes/interactive/theme/theme.d.ts +2 -2
- package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
- package/dist/modes/interactive/theme/theme.js +13 -3
- package/dist/modes/interactive/theme/theme.js.map +1 -1
- package/dist/modes/rpc/connection-handler.d.ts.map +1 -1
- package/dist/modes/rpc/connection-handler.js +13 -0
- package/dist/modes/rpc/connection-handler.js.map +1 -1
- package/dist/utils/clipboard.d.ts +1 -1
- package/dist/utils/clipboard.d.ts.map +1 -1
- package/dist/utils/clipboard.js +22 -2
- package/dist/utils/clipboard.js.map +1 -1
- package/docs/AGENTS.md +1 -6
- package/docs/custom-provider.md +10 -3
- package/docs/development.md +1 -2
- package/docs/extensions.md +24 -1
- package/docs/keybindings.md +13 -0
- package/docs/mcp.md +63 -4
- package/docs/models.md +1 -0
- package/docs/providers.md +39 -0
- package/docs/release-guide.md +5 -3
- package/docs/session-format.md +2 -0
- package/docs/settings.md +2 -0
- package/docs/skills.md +29 -0
- package/docs/themes.md +5 -3
- package/docs/usage.md +5 -0
- package/examples/extensions/custom-compaction.ts +1 -2
- package/examples/extensions/custom-provider-anthropic/index.ts +8 -2
- package/examples/extensions/doom-overlay/wad-finder.ts +7 -3
- package/examples/extensions/handoff.ts +2 -3
- package/examples/extensions/qna.ts +2 -2
- package/examples/rpc-extension-ui.ts +11 -2
- package/examples/sdk/02-custom-model.ts +1 -2
- package/examples/sdk/12-full-control.ts +2 -0
- package/node_modules/@code-yeongyu/senpi-codemode/CHANGELOG.md +36 -0
- package/node_modules/@code-yeongyu/senpi-codemode/package.json +4 -4
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/agent-harness.d.ts +14 -3
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/agent-harness.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/agent-harness.js +156 -67
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/agent-harness.js.map +1 -1
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/array-session-reader.d.ts +3 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/array-session-reader.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/array-session-reader.js +70 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/array-session-reader.js.map +1 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/fork.d.ts +4 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/fork.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/fork.js +22 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/fork.js.map +1 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl-store.d.ts +13 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl-store.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl-store.js +304 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl-store.js.map +1 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/keyed-operation-queue.d.ts +17 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/keyed-operation-queue.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/keyed-operation-queue.js +60 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/keyed-operation-queue.js.map +1 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/memory-store.d.ts +6 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/memory-store.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/memory-store.js +107 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/memory-store.js.map +1 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/repository.d.ts +28 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/repository.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/repository.js +61 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/repository.js.map +1 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/search-backend.d.ts +8 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/search-backend.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/search-backend.js +22 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/search-backend.js.map +1 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/session.d.ts +6 -10
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/session.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/session.js +154 -77
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/session.js.map +1 -1
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/types.d.ts +49 -23
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/types.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/types.js.map +1 -1
- package/node_modules/@earendil-works/pi-agent-core/dist/index.d.ts +6 -6
- package/node_modules/@earendil-works/pi-agent-core/dist/index.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-agent-core/dist/index.js +6 -6
- package/node_modules/@earendil-works/pi-agent-core/dist/index.js.map +1 -1
- package/node_modules/@earendil-works/pi-agent-core/dist/proxy.js +1 -1
- package/node_modules/@earendil-works/pi-agent-core/dist/proxy.js.map +1 -1
- package/node_modules/@earendil-works/pi-agent-core/package.json +4 -4
- package/node_modules/@earendil-works/pi-ai/README.md +5 -2
- package/node_modules/@earendil-works/pi-ai/dist/api/anthropic-messages.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/anthropic-messages.js +46 -10
- package/node_modules/@earendil-works/pi-ai/dist/api/anthropic-messages.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/anthropic-tool-pairs.d.ts +3 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/anthropic-tool-pairs.d.ts.map +1 -0
- package/{dist/core/extensions/builtin/tool-pair-guard/sanitize-anthropic-payload.js → node_modules/@earendil-works/pi-ai/dist/api/anthropic-tool-pairs.js} +3 -3
- package/node_modules/@earendil-works/pi-ai/dist/api/anthropic-tool-pairs.js.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/azure-openai-responses.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/azure-openai-responses.js +5 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/azure-openai-responses.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/bedrock-converse-stream.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/bedrock-converse-stream.js +64 -4
- package/node_modules/@earendil-works/pi-ai/dist/api/bedrock-converse-stream.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/google-generative-ai.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/google-generative-ai.js +12 -2
- package/node_modules/@earendil-works/pi-ai/dist/api/google-generative-ai.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/google-shared.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/google-shared.js +13 -6
- package/node_modules/@earendil-works/pi-ai/dist/api/google-shared.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/google-vertex.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/google-vertex.js +12 -2
- package/node_modules/@earendil-works/pi-ai/dist/api/google-vertex.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/mistral-conversations.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/mistral-conversations.js +19 -10
- package/node_modules/@earendil-works/pi-ai/dist/api/mistral-conversations.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/openai-codex-responses.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/openai-codex-responses.js +84 -47
- package/node_modules/@earendil-works/pi-ai/dist/api/openai-codex-responses.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/openai-completions.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/openai-completions.js +18 -9
- package/node_modules/@earendil-works/pi-ai/dist/api/openai-completions.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/openai-responses-shared.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/openai-responses-shared.js +11 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/openai-responses-shared.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/openai-responses.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/openai-responses.js +7 -3
- package/node_modules/@earendil-works/pi-ai/dist/api/openai-responses.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/openrouter-images.js +3 -2
- package/node_modules/@earendil-works/pi-ai/dist/api/openrouter-images.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/pi-messages.js +2 -2
- package/node_modules/@earendil-works/pi-ai/dist/api/pi-messages.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/simple-options.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/simple-options.js +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/simple-options.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/openrouter.d.ts +3 -1
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/openrouter.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/openrouter.js +81 -26
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/openrouter.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/auth/resolve.d.ts +2 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/resolve.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/auth/resolve.js +16 -8
- package/node_modules/@earendil-works/pi-ai/dist/auth/resolve.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/env-api-keys.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/env-api-keys.js +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/env-api-keys.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/index.d.ts +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/index.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/index.js +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/index.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/models.js +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/models.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/all.d.ts +2 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/all.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/all.js +3 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/all.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/.manifest.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/cloudflare-ai-gateway.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/fireworks.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/github-copilot.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/huggingface.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/mistral.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/openai-codex.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/openai.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/opencode-go.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/opencode.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/openrouter.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/qwen-token-plan-cn.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/qwen-token-plan.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/together.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/vercel-ai-gateway.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/zai-coding-cn.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/zai.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/faux.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/faux.js +4 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/faux.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/ollama.d.ts +9 -0
- package/node_modules/@earendil-works/pi-ai/dist/providers/ollama.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/providers/ollama.js +142 -0
- package/node_modules/@earendil-works/pi-ai/dist/providers/ollama.js.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/providers/opencode-go.js +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/opencode-go.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/types.d.ts +14 -2
- package/node_modules/@earendil-works/pi-ai/dist/types.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/types.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/utils/error-body.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/utils/error-body.js +23 -4
- package/node_modules/@earendil-works/pi-ai/dist/utils/error-body.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/utils/prompt-cache-ttl.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/utils/prompt-cache-ttl.js +10 -1
- package/node_modules/@earendil-works/pi-ai/dist/utils/prompt-cache-ttl.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/utils/provider-retry.d.ts +3 -0
- package/node_modules/@earendil-works/pi-ai/dist/utils/provider-retry.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/utils/provider-retry.js +13 -12
- package/node_modules/@earendil-works/pi-ai/dist/utils/provider-retry.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/utils/retry-hint.d.ts +24 -0
- package/node_modules/@earendil-works/pi-ai/dist/utils/retry-hint.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/utils/retry-hint.js +233 -0
- package/node_modules/@earendil-works/pi-ai/dist/utils/retry-hint.js.map +1 -0
- package/node_modules/@earendil-works/pi-ai/package.json +10 -6
- package/node_modules/@earendil-works/pi-pty/package.json +2 -2
- package/node_modules/@earendil-works/pi-tui/README.md +77 -14
- package/node_modules/@earendil-works/pi-tui/dist/TuiAltScreen.d.ts +83 -0
- package/node_modules/@earendil-works/pi-tui/dist/TuiAltScreen.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-tui/dist/TuiAltScreen.js +687 -0
- package/node_modules/@earendil-works/pi-tui/dist/TuiAltScreen.js.map +1 -0
- package/node_modules/@earendil-works/pi-tui/dist/TuiMainScreen.d.ts +5 -0
- package/node_modules/@earendil-works/pi-tui/dist/TuiMainScreen.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-tui/dist/TuiMainScreen.js +5 -0
- package/node_modules/@earendil-works/pi-tui/dist/TuiMainScreen.js.map +1 -0
- package/node_modules/@earendil-works/pi-tui/dist/components/alt-screen-flash.d.ts +13 -0
- package/node_modules/@earendil-works/pi-tui/dist/components/alt-screen-flash.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-tui/dist/components/alt-screen-flash.js +36 -0
- package/node_modules/@earendil-works/pi-tui/dist/components/alt-screen-flash.js.map +1 -0
- package/node_modules/@earendil-works/pi-tui/dist/components/editor.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-tui/dist/components/editor.js +5 -1
- package/node_modules/@earendil-works/pi-tui/dist/components/editor.js.map +1 -1
- package/node_modules/@earendil-works/pi-tui/dist/components/h-stack.d.ts +7 -0
- package/node_modules/@earendil-works/pi-tui/dist/components/h-stack.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-tui/dist/components/h-stack.js +43 -0
- package/node_modules/@earendil-works/pi-tui/dist/components/h-stack.js.map +1 -0
- package/node_modules/@earendil-works/pi-tui/dist/components/image.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-tui/dist/components/image.js +4 -4
- package/node_modules/@earendil-works/pi-tui/dist/components/image.js.map +1 -1
- package/node_modules/@earendil-works/pi-tui/dist/components/markdown.d.ts +2 -0
- package/node_modules/@earendil-works/pi-tui/dist/components/markdown.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-tui/dist/components/markdown.js +3 -2
- package/node_modules/@earendil-works/pi-tui/dist/components/markdown.js.map +1 -1
- package/node_modules/@earendil-works/pi-tui/dist/components/scroll-view.d.ts +51 -0
- package/node_modules/@earendil-works/pi-tui/dist/components/scroll-view.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-tui/dist/components/scroll-view.js +163 -0
- package/node_modules/@earendil-works/pi-tui/dist/components/scroll-view.js.map +1 -0
- package/node_modules/@earendil-works/pi-tui/dist/components/settings-list.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-tui/dist/components/settings-list.js +3 -6
- package/node_modules/@earendil-works/pi-tui/dist/components/settings-list.js.map +1 -1
- package/node_modules/@earendil-works/pi-tui/dist/components/stack.d.ts +32 -0
- package/node_modules/@earendil-works/pi-tui/dist/components/stack.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-tui/dist/components/stack.js +109 -0
- package/node_modules/@earendil-works/pi-tui/dist/components/stack.js.map +1 -0
- package/node_modules/@earendil-works/pi-tui/dist/components/v-stack.d.ts +8 -0
- package/node_modules/@earendil-works/pi-tui/dist/components/v-stack.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-tui/dist/components/v-stack.js +21 -0
- package/node_modules/@earendil-works/pi-tui/dist/components/v-stack.js.map +1 -0
- package/node_modules/@earendil-works/pi-tui/dist/index.d.ts +10 -4
- package/node_modules/@earendil-works/pi-tui/dist/index.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-tui/dist/index.js +10 -4
- package/node_modules/@earendil-works/pi-tui/dist/index.js.map +1 -1
- package/node_modules/@earendil-works/pi-tui/dist/keybindings.d.ts +30 -0
- package/node_modules/@earendil-works/pi-tui/dist/keybindings.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-tui/dist/keybindings.js +18 -0
- package/node_modules/@earendil-works/pi-tui/dist/keybindings.js.map +1 -1
- package/node_modules/@earendil-works/pi-tui/dist/layout-node.d.ts +40 -0
- package/node_modules/@earendil-works/pi-tui/dist/layout-node.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-tui/dist/layout-node.js +6 -0
- package/node_modules/@earendil-works/pi-tui/dist/layout-node.js.map +1 -0
- package/node_modules/@earendil-works/pi-tui/dist/layout.d.ts +40 -0
- package/node_modules/@earendil-works/pi-tui/dist/layout.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-tui/dist/layout.js +315 -0
- package/node_modules/@earendil-works/pi-tui/dist/layout.js.map +1 -0
- package/node_modules/@earendil-works/pi-tui/dist/slash-command-autocomplete.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-tui/dist/slash-command-autocomplete.js +36 -8
- package/node_modules/@earendil-works/pi-tui/dist/slash-command-autocomplete.js.map +1 -1
- package/node_modules/@earendil-works/pi-tui/dist/terminal-image.d.ts +10 -0
- package/node_modules/@earendil-works/pi-tui/dist/terminal-image.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-tui/dist/terminal-image.js +61 -3
- package/node_modules/@earendil-works/pi-tui/dist/terminal-image.js.map +1 -1
- package/node_modules/@earendil-works/pi-tui/dist/terminal-text.d.ts +1 -0
- package/node_modules/@earendil-works/pi-tui/dist/terminal-text.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-tui/dist/terminal-text.js +12 -2
- package/node_modules/@earendil-works/pi-tui/dist/terminal-text.js.map +1 -1
- package/node_modules/@earendil-works/pi-tui/dist/tui.d.ts +38 -16
- package/node_modules/@earendil-works/pi-tui/dist/tui.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-tui/dist/tui.js +121 -51
- package/node_modules/@earendil-works/pi-tui/dist/tui.js.map +1 -1
- package/node_modules/@earendil-works/pi-tui/dist/utils.d.ts +10 -0
- package/node_modules/@earendil-works/pi-tui/dist/utils.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-tui/dist/utils.js +95 -4
- package/node_modules/@earendil-works/pi-tui/dist/utils.js.map +1 -1
- package/node_modules/@earendil-works/pi-tui/package.json +2 -2
- package/node_modules/typebox/build/compile/validator.d.mts +3 -11
- package/node_modules/typebox/build/compile/validator.mjs +6 -36
- package/node_modules/typebox/build/error/errors.d.mts +1 -7
- package/node_modules/typebox/build/format/_idna.mjs +36 -6
- package/node_modules/typebox/build/format/_puny.mjs +4 -1
- package/node_modules/typebox/build/format/uuid.d.mts +2 -2
- package/node_modules/typebox/build/format/uuid.mjs +3 -3
- package/node_modules/typebox/build/guard/emit.d.mts +0 -4
- package/node_modules/typebox/build/guard/emit.mjs +0 -8
- package/node_modules/typebox/build/guard/guard.d.mts +5 -9
- package/node_modules/typebox/build/guard/guard.mjs +10 -15
- package/node_modules/typebox/build/guard/string.mjs +16 -4
- package/node_modules/typebox/build/schema/engine/_functions.mjs +34 -15
- package/node_modules/typebox/build/schema/engine/boolean.d.mts +3 -3
- package/node_modules/typebox/build/schema/engine/boolean.mjs +4 -4
- package/node_modules/typebox/build/schema/engine/index.d.mts +0 -1
- package/node_modules/typebox/build/schema/engine/index.mjs +0 -1
- package/node_modules/typebox/build/schema/engine/schema.mjs +6 -11
- package/node_modules/typebox/build/schema/engine/type.mjs +14 -18
- package/node_modules/typebox/build/schema/types/dependencies.mjs +1 -1
- package/node_modules/typebox/build/schema/types/index.d.mts +0 -1
- package/node_modules/typebox/build/schema/types/index.mjs +0 -1
- package/node_modules/typebox/build/schema/types/schema.d.mts +1 -1
- package/node_modules/typebox/build/schema/types/schema.mjs +2 -2
- package/node_modules/typebox/build/system/locale/ar_001.mjs +0 -1
- package/node_modules/typebox/build/system/locale/bn_BD.mjs +0 -1
- package/node_modules/typebox/build/system/locale/cs_CZ.mjs +0 -1
- package/node_modules/typebox/build/system/locale/de_DE.mjs +0 -1
- package/node_modules/typebox/build/system/locale/el_GR.mjs +0 -1
- package/node_modules/typebox/build/system/locale/en_US.mjs +0 -1
- package/node_modules/typebox/build/system/locale/es_419.mjs +0 -1
- package/node_modules/typebox/build/system/locale/es_AR.mjs +0 -1
- package/node_modules/typebox/build/system/locale/es_ES.mjs +0 -1
- package/node_modules/typebox/build/system/locale/es_MX.mjs +0 -1
- package/node_modules/typebox/build/system/locale/fa_IR.mjs +0 -1
- package/node_modules/typebox/build/system/locale/fil_PH.mjs +0 -1
- package/node_modules/typebox/build/system/locale/fr_CA.mjs +0 -1
- package/node_modules/typebox/build/system/locale/fr_FR.mjs +0 -1
- package/node_modules/typebox/build/system/locale/ha_NG.mjs +0 -1
- package/node_modules/typebox/build/system/locale/hi_IN.mjs +0 -1
- package/node_modules/typebox/build/system/locale/hu_HU.mjs +0 -1
- package/node_modules/typebox/build/system/locale/id_ID.mjs +0 -1
- package/node_modules/typebox/build/system/locale/it_IT.mjs +0 -1
- package/node_modules/typebox/build/system/locale/ja_JP.mjs +0 -1
- package/node_modules/typebox/build/system/locale/ko_KR.mjs +0 -1
- package/node_modules/typebox/build/system/locale/ms_MY.mjs +0 -1
- package/node_modules/typebox/build/system/locale/nl_NL.mjs +0 -1
- package/node_modules/typebox/build/system/locale/pl_PL.mjs +0 -1
- package/node_modules/typebox/build/system/locale/pt_BR.mjs +0 -1
- package/node_modules/typebox/build/system/locale/pt_PT.mjs +0 -1
- package/node_modules/typebox/build/system/locale/ro_RO.mjs +0 -1
- package/node_modules/typebox/build/system/locale/ru_RU.mjs +0 -1
- package/node_modules/typebox/build/system/locale/sv_SE.mjs +0 -1
- package/node_modules/typebox/build/system/locale/sw_TZ.mjs +0 -1
- package/node_modules/typebox/build/system/locale/th_TH.mjs +0 -1
- package/node_modules/typebox/build/system/locale/tr_TR.mjs +0 -1
- package/node_modules/typebox/build/system/locale/uk_UA.mjs +0 -1
- package/node_modules/typebox/build/system/locale/ur_PK.mjs +0 -1
- package/node_modules/typebox/build/system/locale/vi_VN.mjs +0 -1
- package/node_modules/typebox/build/system/locale/yo_NG.mjs +0 -1
- package/node_modules/typebox/build/system/locale/zh_Hans.mjs +0 -1
- package/node_modules/typebox/build/system/locale/zh_Hant.mjs +0 -1
- package/node_modules/typebox/build/system/memory/clone.d.mts +2 -3
- package/node_modules/typebox/build/system/memory/clone.mjs +73 -26
- package/node_modules/typebox/build/system/settings/settings.d.mts +15 -0
- package/node_modules/typebox/build/system/settings/settings.mjs +3 -1
- package/node_modules/typebox/build/type/action/_add_immutable.d.mts +11 -0
- package/node_modules/typebox/build/type/action/_add_immutable.mjs +11 -0
- package/node_modules/typebox/build/type/action/_add_optional.d.mts +11 -0
- package/node_modules/typebox/build/type/action/_add_optional.mjs +11 -0
- package/node_modules/typebox/build/type/action/_add_readonly.d.mts +11 -0
- package/node_modules/typebox/build/type/action/_add_readonly.mjs +11 -0
- package/node_modules/typebox/build/type/action/_remove_immutable.d.mts +11 -0
- package/node_modules/typebox/build/type/action/_remove_immutable.mjs +11 -0
- package/node_modules/typebox/build/type/action/_remove_optional.d.mts +11 -0
- package/node_modules/typebox/build/type/action/_remove_optional.mjs +11 -0
- package/node_modules/typebox/build/type/action/_remove_readonly.d.mts +11 -0
- package/node_modules/typebox/build/type/action/_remove_readonly.mjs +11 -0
- package/node_modules/typebox/build/type/action/conditional.d.mts +2 -3
- package/node_modules/typebox/build/type/action/conditional.mjs +2 -1
- package/node_modules/typebox/build/type/action/index.d.mts +7 -4
- package/node_modules/typebox/build/type/action/index.mjs +7 -4
- package/node_modules/typebox/build/type/action/mapped.d.mts +2 -3
- package/node_modules/typebox/build/type/action/mapped.mjs +2 -1
- package/node_modules/typebox/build/type/action/module.d.mts +8 -7
- package/node_modules/typebox/build/type/action/module.mjs +7 -6
- package/node_modules/typebox/build/type/action/readonly_object.mjs +3 -0
- package/node_modules/typebox/build/type/action/with.d.mts +11 -0
- package/node_modules/typebox/build/type/action/with.mjs +11 -0
- package/node_modules/typebox/build/type/engine/call/distribute_arguments.mjs +1 -1
- package/node_modules/typebox/build/type/engine/call/instantiate.d.mts +1 -3
- package/node_modules/typebox/build/type/engine/call/instantiate.mjs +3 -2
- package/node_modules/typebox/build/type/engine/call/resolve_arguments.mjs +2 -2
- package/node_modules/typebox/build/type/engine/constructor_parameters/instantiate.d.mts +3 -4
- package/node_modules/typebox/build/type/engine/constructor_parameters/instantiate.mjs +2 -1
- package/node_modules/typebox/build/type/engine/cyclic/candidates.d.mts +2 -3
- package/node_modules/typebox/build/type/engine/cyclic/candidates.mjs +3 -6
- package/node_modules/typebox/build/type/engine/cyclic/check.d.mts +6 -9
- package/node_modules/typebox/build/type/engine/cyclic/check.mjs +10 -16
- package/node_modules/typebox/build/type/engine/cyclic/dependencies.d.mts +1 -4
- package/node_modules/typebox/build/type/engine/cyclic/dependencies.mjs +9 -15
- package/node_modules/typebox/build/type/engine/cyclic/extends.d.mts +1 -4
- package/node_modules/typebox/build/type/engine/cyclic/extends.mjs +8 -14
- package/node_modules/typebox/build/type/engine/cyclic/instantiate.d.mts +2 -5
- package/node_modules/typebox/build/type/engine/cyclic/instantiate.mjs +3 -2
- package/node_modules/typebox/build/type/engine/enum/index.d.mts +0 -1
- package/node_modules/typebox/build/type/engine/enum/index.mjs +0 -1
- package/node_modules/typebox/build/type/engine/evaluate/broaden.d.mts +1 -2
- package/node_modules/typebox/build/type/engine/evaluate/broaden.mjs +2 -6
- package/node_modules/typebox/build/type/engine/evaluate/composite.d.mts +10 -6
- package/node_modules/typebox/build/type/engine/evaluate/composite.mjs +10 -6
- package/node_modules/typebox/build/type/engine/evaluate/distribute.d.mts +2 -1
- package/node_modules/typebox/build/type/engine/evaluate/distribute.mjs +3 -3
- package/node_modules/typebox/build/type/engine/evaluate/evaluate.d.mts +17 -5
- package/node_modules/typebox/build/type/engine/evaluate/evaluate.mjs +34 -8
- package/node_modules/typebox/build/type/engine/exclude/operation.d.mts +5 -6
- package/node_modules/typebox/build/type/engine/exclude/operation.mjs +11 -12
- package/node_modules/typebox/build/type/engine/extract/operation.d.mts +5 -6
- package/node_modules/typebox/build/type/engine/extract/operation.mjs +11 -12
- package/node_modules/typebox/build/type/engine/immutable/instantiate_add.d.mts +10 -0
- package/node_modules/typebox/build/type/engine/immutable/instantiate_add.mjs +14 -0
- package/node_modules/typebox/build/type/engine/immutable/instantiate_remove.d.mts +10 -0
- package/node_modules/typebox/build/type/engine/immutable/instantiate_remove.mjs +14 -0
- package/node_modules/typebox/build/type/engine/index.d.mts +2 -2
- package/node_modules/typebox/build/type/engine/index.mjs +2 -2
- package/node_modules/typebox/build/type/engine/indexable/from_dependent.d.mts +5 -0
- package/node_modules/typebox/build/type/engine/indexable/from_dependent.mjs +8 -0
- package/node_modules/typebox/build/type/engine/indexable/from_enum.d.mts +3 -3
- package/node_modules/typebox/build/type/engine/indexable/from_enum.mjs +4 -4
- package/node_modules/typebox/build/type/engine/indexable/from_template_literal.d.mts +2 -2
- package/node_modules/typebox/build/type/engine/indexable/from_template_literal.mjs +3 -3
- package/node_modules/typebox/build/type/engine/indexable/from_type.d.mts +3 -1
- package/node_modules/typebox/build/type/engine/indexable/from_type.mjs +9 -6
- package/node_modules/typebox/build/type/engine/indexed/instantiate.d.mts +2 -1
- package/node_modules/typebox/build/type/engine/indexed/instantiate.mjs +5 -2
- package/node_modules/typebox/build/type/engine/instantiate.d.mts +44 -31
- package/node_modules/typebox/build/type/engine/instantiate.mjs +82 -83
- package/node_modules/typebox/build/type/engine/interface/instantiate.d.mts +3 -6
- package/node_modules/typebox/build/type/engine/intrinsics/from_template_literal.d.mts +2 -2
- package/node_modules/typebox/build/type/engine/intrinsics/from_template_literal.mjs +3 -3
- package/node_modules/typebox/build/type/engine/keyof/instantiate.d.mts +2 -1
- package/node_modules/typebox/build/type/engine/keyof/instantiate.mjs +5 -1
- package/node_modules/typebox/build/type/engine/mapped/mapped_operation.d.mts +4 -4
- package/node_modules/typebox/build/type/engine/mapped/mapped_operation.mjs +3 -3
- package/node_modules/typebox/build/type/engine/mapped/mapped_variants.d.mts +5 -4
- package/node_modules/typebox/build/type/engine/mapped/mapped_variants.mjs +10 -5
- package/node_modules/typebox/build/type/engine/module/instantiate.d.mts +7 -9
- package/node_modules/typebox/build/type/engine/module/instantiate.mjs +17 -15
- package/node_modules/typebox/build/type/engine/object/from_dependent.d.mts +5 -0
- package/node_modules/typebox/build/type/engine/object/from_dependent.mjs +8 -0
- package/node_modules/typebox/build/type/engine/object/from_type.d.mts +3 -1
- package/node_modules/typebox/build/type/engine/object/from_type.mjs +8 -5
- package/node_modules/typebox/build/type/engine/object/from_union.mjs +2 -2
- package/node_modules/typebox/build/type/engine/optional/instantiate_add.d.mts +10 -0
- package/node_modules/typebox/build/type/engine/optional/instantiate_add.mjs +14 -0
- package/node_modules/typebox/build/type/engine/optional/instantiate_remove.d.mts +10 -0
- package/node_modules/typebox/build/type/engine/optional/instantiate_remove.mjs +14 -0
- package/node_modules/typebox/build/type/engine/parameters/instantiate.d.mts +3 -4
- package/node_modules/typebox/build/type/engine/parameters/instantiate.mjs +2 -1
- package/node_modules/typebox/build/type/engine/partial/from_dependent.d.mts +5 -0
- package/node_modules/typebox/build/type/engine/partial/from_dependent.mjs +8 -0
- package/node_modules/typebox/build/type/engine/partial/from_intersect.d.mts +1 -1
- package/node_modules/typebox/build/type/engine/partial/from_intersect.mjs +3 -2
- package/node_modules/typebox/build/type/engine/partial/from_object.d.mts +2 -2
- package/node_modules/typebox/build/type/engine/partial/from_object.mjs +2 -2
- package/node_modules/typebox/build/type/engine/partial/from_type.d.mts +3 -1
- package/node_modules/typebox/build/type/engine/partial/from_type.mjs +7 -4
- package/node_modules/typebox/build/type/engine/priority/index.d.mts +1 -0
- package/node_modules/typebox/build/type/engine/priority/index.mjs +1 -0
- package/node_modules/typebox/build/type/engine/priority/priority.d.mts +20 -0
- package/node_modules/typebox/build/type/engine/priority/priority.mjs +28 -0
- package/node_modules/typebox/build/type/engine/readonly/instantiate_add.d.mts +10 -0
- package/node_modules/typebox/build/type/engine/readonly/instantiate_add.mjs +14 -0
- package/node_modules/typebox/build/type/engine/readonly/instantiate_remove.d.mts +10 -0
- package/node_modules/typebox/build/type/engine/readonly/instantiate_remove.mjs +14 -0
- package/node_modules/typebox/build/type/engine/readonly_object/from_array.d.mts +2 -2
- package/node_modules/typebox/build/type/engine/readonly_object/from_array.mjs +2 -2
- package/node_modules/typebox/build/type/engine/readonly_object/from_dependent.d.mts +5 -0
- package/node_modules/typebox/build/type/engine/readonly_object/from_dependent.mjs +8 -0
- package/node_modules/typebox/build/type/engine/readonly_object/from_intersect.d.mts +1 -1
- package/node_modules/typebox/build/type/engine/readonly_object/from_intersect.mjs +3 -2
- package/node_modules/typebox/build/type/engine/readonly_object/from_object.d.mts +2 -2
- package/node_modules/typebox/build/type/engine/readonly_object/from_object.mjs +2 -2
- package/node_modules/typebox/build/type/engine/readonly_object/from_tuple.d.mts +2 -2
- package/node_modules/typebox/build/type/engine/readonly_object/from_tuple.mjs +2 -2
- package/node_modules/typebox/build/type/engine/readonly_object/from_type.d.mts +3 -1
- package/node_modules/typebox/build/type/engine/readonly_object/from_type.mjs +8 -5
- package/node_modules/typebox/build/type/engine/record/from_key_enum.d.mts +2 -2
- package/node_modules/typebox/build/type/engine/record/from_key_enum.mjs +2 -2
- package/node_modules/typebox/build/type/engine/record/from_key_template_literal.d.mts +2 -2
- package/node_modules/typebox/build/type/engine/record/from_key_template_literal.mjs +2 -2
- package/node_modules/typebox/build/type/engine/ref/instantiate.d.mts +3 -3
- package/node_modules/typebox/build/type/engine/ref/instantiate.mjs +6 -6
- package/node_modules/typebox/build/type/engine/required/from_dependent.d.mts +5 -0
- package/node_modules/typebox/build/type/engine/required/from_dependent.mjs +8 -0
- package/node_modules/typebox/build/type/engine/required/from_intersect.d.mts +1 -1
- package/node_modules/typebox/build/type/engine/required/from_intersect.mjs +3 -2
- package/node_modules/typebox/build/type/engine/required/from_object.d.mts +2 -2
- package/node_modules/typebox/build/type/engine/required/from_object.mjs +2 -2
- package/node_modules/typebox/build/type/engine/required/from_type.d.mts +3 -1
- package/node_modules/typebox/build/type/engine/required/from_type.mjs +7 -4
- package/node_modules/typebox/build/type/engine/template_literal/decode.mjs +3 -3
- package/node_modules/typebox/build/type/engine/template_literal/encode.d.mts +2 -2
- package/node_modules/typebox/build/type/engine/template_literal/encode.mjs +6 -6
- package/node_modules/typebox/build/type/engine/template_literal/is_finite.mjs +1 -1
- package/node_modules/typebox/build/type/engine/template_literal/is_pattern.mjs +1 -0
- package/node_modules/typebox/build/type/engine/this/expand_this.d.mts +1 -4
- package/node_modules/typebox/build/type/engine/this/expand_this.mjs +7 -13
- package/node_modules/typebox/build/type/engine/with/instantiate.d.mts +8 -0
- package/node_modules/typebox/build/type/engine/{options → with}/instantiate.mjs +5 -5
- package/node_modules/typebox/build/type/extends/dependent.d.mts +6 -0
- package/node_modules/typebox/build/type/extends/dependent.mjs +6 -0
- package/node_modules/typebox/build/type/extends/enum.d.mts +4 -4
- package/node_modules/typebox/build/type/extends/enum.mjs +3 -2
- package/node_modules/typebox/build/type/extends/extends_left.d.mts +5 -7
- package/node_modules/typebox/build/type/extends/extends_left.mjs +24 -27
- package/node_modules/typebox/build/type/extends/extends_right.d.mts +7 -5
- package/node_modules/typebox/build/type/extends/extends_right.mjs +20 -15
- package/node_modules/typebox/build/type/extends/inference.mjs +1 -1
- package/node_modules/typebox/build/type/extends/object.d.mts +8 -1
- package/node_modules/typebox/build/type/extends/object.mjs +25 -3
- package/node_modules/typebox/build/type/extends/parameters.mjs +2 -2
- package/node_modules/typebox/build/type/extends/record.d.mts +13 -0
- package/node_modules/typebox/build/type/extends/record.mjs +23 -0
- package/node_modules/typebox/build/type/extends/template_literal.d.mts +3 -3
- package/node_modules/typebox/build/type/extends/template_literal.mjs +3 -3
- package/node_modules/typebox/build/type/extends/tuple.d.mts +3 -6
- package/node_modules/typebox/build/type/extends/tuple.mjs +6 -5
- package/node_modules/typebox/build/type/extends/union.mjs +2 -2
- package/node_modules/typebox/build/type/script/mapping.d.mts +86 -98
- package/node_modules/typebox/build/type/script/mapping.mjs +95 -92
- package/node_modules/typebox/build/type/script/parser.d.mts +42 -40
- package/node_modules/typebox/build/type/script/parser.mjs +23 -22
- package/node_modules/typebox/build/type/script/script.d.mts +3 -4
- package/node_modules/typebox/build/type/script/script.mjs +3 -2
- package/node_modules/typebox/build/type/script/token/internal/guard.d.mts +1 -1
- package/node_modules/typebox/build/type/script/token/internal/guard.mjs +1 -1
- package/node_modules/typebox/build/type/script/token/internal/take.mjs +1 -1
- package/node_modules/typebox/build/type/script/token/until.mjs +2 -2
- package/node_modules/typebox/build/type/types/_codec.d.mts +12 -12
- package/node_modules/typebox/build/type/types/_codec.mjs +0 -1
- package/node_modules/typebox/build/type/types/_immutable.d.mts +2 -9
- package/node_modules/typebox/build/type/types/_immutable.mjs +2 -10
- package/node_modules/typebox/build/type/types/_optional.d.mts +2 -9
- package/node_modules/typebox/build/type/types/_optional.mjs +2 -11
- package/node_modules/typebox/build/type/types/_readonly.d.mts +2 -9
- package/node_modules/typebox/build/type/types/_readonly.mjs +2 -10
- package/node_modules/typebox/build/type/types/_refine.d.mts +8 -10
- package/node_modules/typebox/build/type/types/_refine.mjs +1 -2
- package/node_modules/typebox/build/type/types/call.d.mts +3 -3
- package/node_modules/typebox/build/type/types/call.mjs +3 -2
- package/node_modules/typebox/build/type/types/deferred.d.mts +1 -0
- package/node_modules/typebox/build/type/types/deferred.mjs +1 -1
- package/node_modules/typebox/build/type/types/dependent.d.mts +17 -0
- package/node_modules/typebox/build/type/types/dependent.mjs +24 -0
- package/node_modules/typebox/build/type/types/enum.d.mts +3 -1
- package/node_modules/typebox/build/type/types/enum.mjs +5 -0
- package/node_modules/typebox/build/type/types/index.d.mts +1 -4
- package/node_modules/typebox/build/type/types/index.mjs +1 -4
- package/node_modules/typebox/build/type/types/number.d.mts +1 -1
- package/node_modules/typebox/build/type/types/number.mjs +1 -1
- package/node_modules/typebox/build/type/types/record.d.mts +13 -7
- package/node_modules/typebox/build/type/types/record.mjs +15 -9
- package/node_modules/typebox/build/type/types/static.d.mts +2 -5
- package/node_modules/typebox/build/typebox.d.mts +3 -7
- package/node_modules/typebox/build/typebox.mjs +3 -7
- package/node_modules/typebox/build/value/clean/clean.mjs +4 -2
- package/node_modules/typebox/build/value/clean/from_intersect.mjs +2 -2
- package/node_modules/typebox/build/value/clean/from_type.mjs +8 -10
- package/node_modules/typebox/build/value/clean/from_union.d.mts +1 -1
- package/node_modules/typebox/build/value/clean/from_union.mjs +1 -2
- package/node_modules/typebox/build/value/clone/clone.mjs +2 -73
- package/node_modules/typebox/build/value/codec/decode.mjs +4 -2
- package/node_modules/typebox/build/value/codec/encode.mjs +4 -2
- package/node_modules/typebox/build/value/codec/from_array.mjs +1 -4
- package/node_modules/typebox/build/value/codec/from_object.mjs +1 -4
- package/node_modules/typebox/build/value/codec/from_record.mjs +2 -7
- package/node_modules/typebox/build/value/codec/from_tuple.mjs +1 -4
- package/node_modules/typebox/build/value/codec/from_union.mjs +2 -3
- package/node_modules/typebox/build/value/convert/from_enum.mjs +3 -4
- package/node_modules/typebox/build/value/convert/from_template_literal.d.mts +1 -1
- package/node_modules/typebox/build/value/convert/from_template_literal.mjs +2 -3
- package/node_modules/typebox/build/value/convert/from_type.mjs +19 -21
- package/node_modules/typebox/build/value/create/from_enum.mjs +2 -2
- package/node_modules/typebox/build/value/create/from_type.mjs +23 -31
- package/node_modules/typebox/build/value/default/from_object.mjs +1 -1
- package/node_modules/typebox/build/value/default/from_type.mjs +8 -10
- package/node_modules/typebox/build/value/errors/errors.d.mts +2 -2
- package/node_modules/typebox/build/value/errors/errors.mjs +1 -1
- package/node_modules/typebox/build/value/index.d.mts +0 -1
- package/node_modules/typebox/build/value/index.mjs +0 -1
- package/node_modules/typebox/build/value/repair/from_enum.mjs +2 -3
- package/node_modules/typebox/build/value/repair/from_type.mjs +24 -22
- package/node_modules/typebox/build/value/shared/union_priority_sort.d.mts +6 -2
- package/node_modules/typebox/build/value/shared/union_priority_sort.mjs +62 -26
- package/node_modules/typebox/build/value/value.d.mts +0 -1
- package/node_modules/typebox/build/value/value.mjs +0 -1
- package/node_modules/typebox/package.json +33 -33
- package/node_modules/typebox/readme.md +117 -103
- package/package.json +16 -11
- package/vendor/pi-client/client.d.ts +25 -0
- package/vendor/pi-client/client.d.ts.map +1 -0
- package/vendor/pi-client/client.js +386 -0
- package/vendor/pi-client/client.js.map +1 -0
- package/vendor/pi-client/connection.d.ts +25 -0
- package/vendor/pi-client/connection.d.ts.map +1 -0
- package/vendor/pi-client/connection.js +204 -0
- package/vendor/pi-client/connection.js.map +1 -0
- package/vendor/pi-client/errors.d.ts +23 -0
- package/vendor/pi-client/errors.d.ts.map +1 -0
- package/vendor/pi-client/errors.js +42 -0
- package/vendor/pi-client/errors.js.map +1 -0
- package/vendor/pi-client/index.d.ts +6 -0
- package/vendor/pi-client/index.d.ts.map +1 -0
- package/vendor/pi-client/index.js +3 -0
- package/vendor/pi-client/index.js.map +1 -0
- package/vendor/pi-client/promise.d.ts +8 -0
- package/vendor/pi-client/promise.d.ts.map +1 -0
- package/vendor/pi-client/promise.js +11 -0
- package/vendor/pi-client/promise.js.map +1 -0
- package/vendor/pi-client/session-handle.d.ts +54 -0
- package/vendor/pi-client/session-handle.d.ts.map +1 -0
- package/vendor/pi-client/session-handle.js +50 -0
- package/vendor/pi-client/session-handle.js.map +1 -0
- package/vendor/pi-client/state.d.ts +22 -0
- package/vendor/pi-client/state.d.ts.map +1 -0
- package/vendor/pi-client/state.js +149 -0
- package/vendor/pi-client/state.js.map +1 -0
- package/vendor/pi-client/transport.d.ts +17 -0
- package/vendor/pi-client/transport.d.ts.map +1 -0
- package/vendor/pi-client/transport.js +2 -0
- package/vendor/pi-client/transport.js.map +1 -0
- package/vendor/pi-client/types.d.ts +23 -0
- package/vendor/pi-client/types.d.ts.map +1 -0
- package/vendor/pi-client/types.js +2 -0
- package/vendor/pi-client/types.js.map +1 -0
- package/vendor/pi-client/unix.d.ts +8 -0
- package/vendor/pi-client/unix.d.ts.map +1 -0
- package/vendor/pi-client/unix.js +151 -0
- package/vendor/pi-client/unix.js.map +1 -0
- package/vendor/pi-protocol/cbor/decoder.d.ts +4 -0
- package/vendor/pi-protocol/cbor/decoder.d.ts.map +1 -0
- package/vendor/pi-protocol/cbor/decoder.js +163 -0
- package/vendor/pi-protocol/cbor/decoder.js.map +1 -0
- package/vendor/pi-protocol/cbor/encoder.d.ts +4 -0
- package/vendor/pi-protocol/cbor/encoder.d.ts.map +1 -0
- package/vendor/pi-protocol/cbor/encoder.js +199 -0
- package/vendor/pi-protocol/cbor/encoder.js.map +1 -0
- package/vendor/pi-protocol/cbor/index.d.ts +4 -0
- package/vendor/pi-protocol/cbor/index.d.ts.map +1 -0
- package/vendor/pi-protocol/cbor/index.js +4 -0
- package/vendor/pi-protocol/cbor/index.js.map +1 -0
- package/vendor/pi-protocol/cbor/options.d.ts +26 -0
- package/vendor/pi-protocol/cbor/options.d.ts.map +1 -0
- package/vendor/pi-protocol/cbor/options.js +29 -0
- package/vendor/pi-protocol/cbor/options.js.map +1 -0
- package/vendor/pi-protocol/codec.d.ts +29 -0
- package/vendor/pi-protocol/codec.d.ts.map +1 -0
- package/vendor/pi-protocol/codec.js +140 -0
- package/vendor/pi-protocol/codec.js.map +1 -0
- package/vendor/pi-protocol/framing.d.ts +29 -0
- package/vendor/pi-protocol/framing.d.ts.map +1 -0
- package/vendor/pi-protocol/framing.js +152 -0
- package/vendor/pi-protocol/framing.js.map +1 -0
- package/vendor/pi-protocol/index.d.ts +5 -0
- package/vendor/pi-protocol/index.d.ts.map +1 -0
- package/vendor/pi-protocol/index.js +5 -0
- package/vendor/pi-protocol/index.js.map +1 -0
- package/vendor/pi-protocol/schemas.d.ts +13818 -0
- package/vendor/pi-protocol/schemas.d.ts.map +1 -0
- package/vendor/pi-protocol/schemas.js +382 -0
- package/vendor/pi-protocol/schemas.js.map +1 -0
- package/dist/core/extensions/builtin/tool-pair-guard/sanitize-anthropic-payload.d.ts +0 -3
- package/dist/core/extensions/builtin/tool-pair-guard/sanitize-anthropic-payload.d.ts.map +0 -1
- package/dist/core/extensions/builtin/tool-pair-guard/sanitize-anthropic-payload.js.map +0 -1
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl-repo.d.ts +0 -26
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl-repo.d.ts.map +0 -1
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl-repo.js +0 -100
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl-repo.js.map +0 -1
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl-storage.d.ts +0 -42
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl-storage.d.ts.map +0 -1
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl-storage.js +0 -286
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl-storage.js.map +0 -1
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/memory-repo.d.ts +0 -18
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/memory-repo.d.ts.map +0 -1
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/memory-repo.js +0 -44
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/memory-repo.js.map +0 -1
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/memory-storage.d.ts +0 -33
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/memory-storage.d.ts.map +0 -1
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/memory-storage.js +0 -163
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/memory-storage.js.map +0 -1
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/repo-utils.d.ts +0 -11
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/repo-utils.d.ts.map +0 -1
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/repo-utils.js +0 -39
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/repo-utils.js.map +0 -1
- package/node_modules/typebox/build/schema/engine/_guard.d.mts +0 -6
- package/node_modules/typebox/build/schema/engine/_guard.mjs +0 -26
- package/node_modules/typebox/build/schema/types/_guard.d.mts +0 -10
- package/node_modules/typebox/build/schema/types/_guard.mjs +0 -16
- package/node_modules/typebox/build/type/action/_optional.d.mts +0 -19
- package/node_modules/typebox/build/type/action/_optional.mjs +0 -40
- package/node_modules/typebox/build/type/action/_readonly.d.mts +0 -19
- package/node_modules/typebox/build/type/action/_readonly.mjs +0 -40
- package/node_modules/typebox/build/type/action/awaited.d.mts +0 -15
- package/node_modules/typebox/build/type/action/awaited.mjs +0 -15
- package/node_modules/typebox/build/type/action/options.d.mts +0 -11
- package/node_modules/typebox/build/type/action/options.mjs +0 -11
- package/node_modules/typebox/build/type/engine/awaited/instantiate.d.mts +0 -11
- package/node_modules/typebox/build/type/engine/awaited/instantiate.mjs +0 -20
- package/node_modules/typebox/build/type/engine/enum/enum_to_union.d.mts +0 -14
- package/node_modules/typebox/build/type/engine/enum/enum_to_union.mjs +0 -24
- package/node_modules/typebox/build/type/engine/options/index.d.mts +0 -1
- package/node_modules/typebox/build/type/engine/options/index.mjs +0 -1
- package/node_modules/typebox/build/type/engine/options/instantiate.d.mts +0 -8
- package/node_modules/typebox/build/type/extends/async_iterator.d.mts +0 -7
- package/node_modules/typebox/build/type/extends/async_iterator.mjs +0 -9
- package/node_modules/typebox/build/type/extends/iterator.d.mts +0 -7
- package/node_modules/typebox/build/type/extends/iterator.mjs +0 -9
- package/node_modules/typebox/build/type/extends/promise.d.mts +0 -7
- package/node_modules/typebox/build/type/extends/promise.mjs +0 -9
- package/node_modules/typebox/build/type/types/async_iterator.d.mts +0 -20
- package/node_modules/typebox/build/type/types/async_iterator.mjs +0 -28
- package/node_modules/typebox/build/type/types/base.d.mts +0 -50
- package/node_modules/typebox/build/type/types/base.mjs +0 -84
- package/node_modules/typebox/build/type/types/iterator.d.mts +0 -20
- package/node_modules/typebox/build/type/types/iterator.mjs +0 -28
- package/node_modules/typebox/build/type/types/promise.d.mts +0 -21
- package/node_modules/typebox/build/type/types/promise.mjs +0 -29
- package/node_modules/typebox/build/value/clean/from_base.d.mts +0 -2
- package/node_modules/typebox/build/value/clean/from_base.mjs +0 -4
- package/node_modules/typebox/build/value/convert/from_base.d.mts +0 -2
- package/node_modules/typebox/build/value/convert/from_base.mjs +0 -4
- package/node_modules/typebox/build/value/create/from_async_iterator.d.mts +0 -2
- package/node_modules/typebox/build/value/create/from_async_iterator.mjs +0 -5
- package/node_modules/typebox/build/value/create/from_base.d.mts +0 -2
- package/node_modules/typebox/build/value/create/from_base.mjs +0 -4
- package/node_modules/typebox/build/value/create/from_iterator.d.mts +0 -2
- package/node_modules/typebox/build/value/create/from_iterator.mjs +0 -5
- package/node_modules/typebox/build/value/create/from_promise.d.mts +0 -2
- package/node_modules/typebox/build/value/create/from_promise.mjs +0 -5
- package/node_modules/typebox/build/value/default/from_base.d.mts +0 -2
- package/node_modules/typebox/build/value/default/from_base.mjs +0 -5
- package/node_modules/typebox/build/value/mutate/error.d.mts +0 -3
- package/node_modules/typebox/build/value/mutate/error.mjs +0 -6
- package/node_modules/typebox/build/value/mutate/from_array.d.mts +0 -2
- package/node_modules/typebox/build/value/mutate/from_array.mjs +0 -16
- package/node_modules/typebox/build/value/mutate/from_object.d.mts +0 -2
- package/node_modules/typebox/build/value/mutate/from_object.mjs +0 -40
- package/node_modules/typebox/build/value/mutate/from_unknown.d.mts +0 -2
- package/node_modules/typebox/build/value/mutate/from_unknown.mjs +0 -7
- package/node_modules/typebox/build/value/mutate/from_value.d.mts +0 -2
- package/node_modules/typebox/build/value/mutate/from_value.mjs +0 -12
- package/node_modules/typebox/build/value/mutate/index.d.mts +0 -1
- package/node_modules/typebox/build/value/mutate/index.mjs +0 -1
- package/node_modules/typebox/build/value/mutate/mutate.d.mts +0 -11
- package/node_modules/typebox/build/value/mutate/mutate.mjs +0 -41
- package/node_modules/typebox/build/value/repair/from_base.d.mts +0 -2
- package/node_modules/typebox/build/value/repair/from_base.mjs +0 -8
- /package/node_modules/typebox/build/type/engine/{awaited → with}/index.d.mts +0 -0
- /package/node_modules/typebox/build/type/engine/{awaited → with}/index.mjs +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apply.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/gpt-apply-patch/apply.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAClF,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,qBAAqB,EAAE,MAAM,uCAAuC,CAAC;AAC9E,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAC5E,OAAO,EAAE,0BA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ACzG,CAAC;YACF,MAAM,MAAM,GAAqB;gBAChC,SAAS;gBACT,YAAY;gBACZ,QAAQ;gBACR,iBAAiB,EAAE,YAAY,CAAC,MAAM,GAAG,CAAC;gBAC1C,oBAAoB,EAAE,0BAA0B,CAAC,EAAE,YAAY,EAAE,QAAQ,EAAE,CAAC;gBAC5E,OAAO,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,iBAAiB,EAAE;aACvC,CAAC;YACF,MAAM,IAAI,eAAe,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QAC5C,CAAC;IACF,CAAC;IAED,OAAO,SAAS,CAAC;AAClB,CAAC","sourcesContent":["import { mkdir, readFile, rename, rm, unlink, writeFile } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { withFileMutationQueue } from \"../../../tools/file-mutation-queue.ts\";\nimport { ApplyPatchError } from \"./errors.ts\";\nimport { parsePatch } from \"./parser.ts\";\nimport { replaceChunks } from \"./patch-replace.ts\";\nimport { buildPatchPreviewFile, readPatchFileSnapshot } from \"./preview.ts\";\nimport { createRecoveryInstructions } from \"./recovery.ts\";\n\nexport { buildPartialFailureText } from \"./recovery.ts\";\n\nimport { normalizePatchText } from \"./text.ts\";\nimport type {\n\tAppliedPatchOperation,\n\tApplyPatchFailure,\n\tApplyPatchProgressCallback,\n\tApplyPatchResult,\n\tAtomicWriteOperations,\n\tParsedPatch,\n} from \"./types.ts\";\nimport { resolvePatchPath } from \"./workspace.ts\";\n\nconst ATOMIC_WRITE_OPERATIONS: AtomicWriteOperations = { writeFile, rename, unlink };\n\nasync function notifyApplyPatchProgress(\n\tonProgress: ApplyPatchProgressCallback | undefined,\n\tprogress: Parameters<ApplyPatchProgressCallback>[0],\n): Promise<void> {\n\ttry {\n\t\tawait onProgress?.(progress);\n\t} catch {\n\t\t// Rendering progress must not affect patch application or recovery details.\n\t}\n}\n\nfunction hasErrorCode(error: unknown, code: string): boolean {\n\treturn Boolean(error && typeof error === \"object\" && \"code\" in error && error.code === code);\n}\n\nfunction extractErrorCode(error: unknown): string | undefined {\n\tif (error && typeof error === \"object\" && \"code\" in error && typeof error.code === \"string\") {\n\t\treturn error.code;\n\t}\n\treturn undefined;\n}\n\nasync function writeFileAtomic(\n\tabsPath: string,\n\tcontent: string,\n\toperations: AtomicWriteOperations = ATOMIC_WRITE_OPERATIONS,\n): Promise<void> {\n\tconst tempPath = `${absPath}.tmp.${process.pid}.${Math.random().toString(16).slice(2)}`;\n\tawait operations.writeFile(tempPath, content, \"utf-8\");\n\ttry {\n\t\tawait operations.rename(tempPath, absPath);\n\t} catch (error) {\n\t\tif (!hasErrorCode(error, \"EEXIST\")) throw error;\n\t\tawait operations.unlink(absPath);\n\t\tawait operations.rename(tempPath, absPath);\n\t}\n}\n\nexport async function __testWriteFileAtomic(\n\tabsPath: string,\n\tcontent: string,\n\toperations: AtomicWriteOperations,\n): Promise<void> {\n\tawait writeFileAtomic(absPath, content, operations);\n}\n\nasync function applySingleHunk(\n\tcwd: string,\n\thunk: ParsedPatch,\n): Promise<{\n\treadonly summary: string;\n\treadonly appliedFile: string;\n\treadonly fuzz: number;\n\treadonly preview: ReturnType<typeof buildPatchPreviewFile>;\n}> {\n\tconst absolutePath = resolvePatchPath(cwd, hunk.filePath);\n\tconst mutationPaths =\n\t\thunk.type === \"update\" && hunk.movePath ? [absolutePath, resolvePatchPath(cwd, hunk.movePath)] : [absolutePath];\n\treturn withPatchMutationQueues(mutationPaths, async () => {\n\t\tif (hunk.type === \"add\") {\n\t\t\tconst source = await readPatchFileSnapshot(absolutePath);\n\t\t\tconst preview = buildPatchPreviewFile({ hunk, source, newContent: hunk.content });\n\t\t\tawait mkdir(path.dirname(absolutePath), { recursive: true });\n\t\t\tawait writeFileAtomic(absolutePath, hunk.content);\n\t\t\treturn { summary: `add: ${hunk.filePath}`, appliedFile: hunk.filePath, fuzz: 0, preview };\n\t\t}\n\n\t\tif (hunk.type === \"delete\") {\n\t\t\tconst oldContent = await readFile(absolutePath, \"utf-8\");\n\t\t\tconst preview = buildPatchPreviewFile({\n\t\t\t\thunk,\n\t\t\t\tsource: { exists: true, content: oldContent },\n\t\t\t\tnewContent: \"\",\n\t\t\t});\n\t\t\tawait rm(absolutePath);\n\t\t\treturn { summary: `delete: ${hunk.filePath}`, appliedFile: hunk.filePath, fuzz: 0, preview };\n\t\t}\n\n\t\tconst currentContent = await readFile(absolutePath, \"utf-8\");\n\t\tconst chunkResult =\n\t\t\thunk.chunks.length === 0\n\t\t\t\t? { content: currentContent, fuzz: 0 }\n\t\t\t\t: replaceChunks(currentContent, hunk.filePath, hunk.chunks);\n\n\t\tif (hunk.movePath) {\n\t\t\tconst absoluteMovePath = resolvePatchPath(cwd, hunk.movePath);\n\t\t\tconst moveDestination =\n\t\t\t\tabsoluteMovePath === absolutePath ? undefined : await readPatchFileSnapshot(absoluteMovePath);\n\t\t\tconst preview = buildPatchPreviewFile({\n\t\t\t\thunk,\n\t\t\t\tsource: { exists: true, content: currentContent },\n\t\t\t\tnewContent: chunkResult.content,\n\t\t\t\t...(moveDestination ? { moveDestination } : {}),\n\t\t\t});\n\t\t\tawait mkdir(path.dirname(absoluteMovePath), { recursive: true });\n\t\t\tawait writeFileAtomic(absoluteMovePath, chunkResult.content);\n\t\t\tif (absoluteMovePath !== absolutePath) await rm(absolutePath);\n\t\t\treturn {\n\t\t\t\tsummary: `move: ${hunk.filePath} -> ${hunk.movePath}`,\n\t\t\t\tappliedFile: hunk.movePath,\n\t\t\t\tfuzz: chunkResult.fuzz,\n\t\t\t\tpreview,\n\t\t\t};\n\t\t}\n\n\t\tconst preview = buildPatchPreviewFile({\n\t\t\thunk,\n\t\t\tsource: { exists: true, content: currentContent },\n\t\t\tnewContent: chunkResult.content,\n\t\t});\n\t\tawait writeFileAtomic(absolutePath, chunkResult.content);\n\t\treturn { summary: `update: ${hunk.filePath}`, appliedFile: hunk.filePath, fuzz: chunkResult.fuzz, preview };\n\t});\n}\n\nasync function withPatchMutationQueues<T>(filePaths: readonly string[], operation: () => Promise<T>): Promise<T> {\n\tconst sortedPaths = [...new Set(filePaths)].sort((left, right) => left.localeCompare(right));\n\tconst runQueued = (index: number): Promise<T> => {\n\t\tconst filePath = sortedPaths[index];\n\t\tif (filePath === undefined) return operation();\n\t\treturn withFileMutationQueue(filePath, () => runQueued(index + 1));\n\t};\n\treturn runQueued(0);\n}\n\nfunction parseNonEmptyPatch(patchText: string): ParsedPatch[] {\n\tconst hunks = parsePatch(patchText);\n\tif (hunks.length === 0) {\n\t\tconst normalized = normalizePatchText(patchText).trim();\n\t\tif (normalized === \"*** Begin Patch\\n*** End Patch\") throw new Error(\"patch rejected: empty patch\");\n\t\tthrow new Error(\"apply_patch verification failed: no hunks found\");\n\t}\n\treturn hunks;\n}\n\nexport async function applyPatchDetailed(\n\tcwd: string,\n\tpatchText: string,\n\tonProgress?: ApplyPatchProgressCallback,\n): Promise<ApplyPatchResult> {\n\tconst hunks = parseNonEmptyPatch(patchText);\n\tconst summaries: string[] = [];\n\tconst appliedFiles: string[] = [];\n\tconst appliedOperations: AppliedPatchOperation[] = [];\n\tconst failures: ApplyPatchFailure[] = [];\n\tlet fuzz = 0;\n\n\tfor (const [operationIndex, hunk] of hunks.entries()) {\n\t\ttry {\n\t\t\tconst applied = await applySingleHunk(cwd, hunk);\n\t\t\tsummaries.push(applied.summary);\n\t\t\tappliedFiles.push(applied.appliedFile);\n\t\t\tappliedOperations.push({ operationIndex, preview: applied.preview });\n\t\t\tfuzz += applied.fuzz;\n\t\t} catch (error) {\n\t\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\t\tconst code = extractErrorCode(error);\n\t\t\tfailures.push({ operationIndex, filePath: hunk.filePath, operation: hunk.type, message, code });\n\t\t}\n\t\tawait notifyApplyPatchProgress(onProgress, {\n\t\t\tapplied: appliedFiles.length,\n\t\t\tfailed: failures.length,\n\t\t\ttotal: hunks.length,\n\t\t});\n\t}\n\n\tconst result: ApplyPatchResult = {\n\t\tsummaries,\n\t\tappliedFiles,\n\t\tfailures,\n\t\thasPartialSuccess: appliedFiles.length > 0 && failures.length > 0,\n\t\trecoveryInstructions: { mustReadFiles: [], mustNotReadFiles: [], failedFiles: [] },\n\t\tdetails: { fuzz, appliedOperations },\n\t};\n\tresult.recoveryInstructions = createRecoveryInstructions(result);\n\treturn result;\n}\n\nexport async function applyPatch(cwd: string, patchText: string): Promise<string[]> {\n\tconst hunks = parseNonEmptyPatch(patchText);\n\tconst summaries: string[] = [];\n\tconst appliedFiles: string[] = [];\n\tconst appliedOperations: AppliedPatchOperation[] = [];\n\tfor (const [operationIndex, hunk] of hunks.entries()) {\n\t\ttry {\n\t\t\tconst applied = await applySingleHunk(cwd, hunk);\n\t\t\tsummaries.push(applied.summary);\n\t\t\tappliedFiles.push(applied.appliedFile);\n\t\t\tappliedOperations.push({ operationIndex, preview: applied.preview });\n\t\t} catch (error) {\n\t\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\t\tconst failures: ApplyPatchFailure[] = [\n\t\t\t\t{ operationIndex, filePath: hunk.filePath, operation: hunk.type, message, code: extractErrorCode(error) },\n\t\t\t];\n\t\t\tconst result: ApplyPatchResult = {\n\t\t\t\tsummaries,\n\t\t\t\tappliedFiles,\n\t\t\t\tfailures,\n\t\t\t\thasPartialSuccess: appliedFiles.length > 0,\n\t\t\t\trecoveryInstructions: createRecoveryInstructions({ appliedFiles, failures }),\n\t\t\t\tdetails: { fuzz: 0, appliedOperations },\n\t\t\t};\n\t\t\tthrow new ApplyPatchError(message, result);\n\t\t}\n\t}\n\n\treturn summaries;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"apply.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/gpt-apply-patch/apply.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAClF,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,qBAAqB,EAAE,M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nimport { withFileMutationQueue } from \"../../../tools/file-mutation-queue.ts\";\nimport { ApplyPatchError } from \"./errors.ts\";\nimport { parsePatch } from \"./parser.ts\";\nimport { replaceChunks } from \"./patch-replace.ts\";\nimport { buildPatchPreviewFile, readPatchFileSnapshot } from \"./preview.ts\";\nimport { createRecoveryInstructions } from \"./recovery.ts\";\n\nexport { buildPartialFailureText } from \"./recovery.ts\";\n\nimport { normalizePatchText } from \"./text.ts\";\nimport type {\n\tAppliedPatchOperation,\n\tApplyPatchFailure,\n\tApplyPatchProgressCallback,\n\tApplyPatchResult,\n\tAtomicWriteOperations,\n\tParsedPatch,\n} from \"./types.ts\";\nimport { resolvePatchPath } from \"./workspace.ts\";\n\nconst ATOMIC_WRITE_OPERATIONS: AtomicWriteOperations = { writeFile, rename, unlink };\n\nasync function notifyApplyPatchProgress(\n\tonProgress: ApplyPatchProgressCallback | undefined,\n\tprogress: Parameters<ApplyPatchProgressCallback>[0],\n): Promise<void> {\n\ttry {\n\t\tawait onProgress?.(progress);\n\t} catch {\n\t\t// Rendering progress must not affect patch application or recovery details.\n\t}\n}\n\nfunction hasErrorCode(error: unknown, code: string): boolean {\n\treturn Boolean(error && typeof error === \"object\" && \"code\" in error && error.code === code);\n}\n\nfunction extractErrorCode(error: unknown): string | undefined {\n\tif (error && typeof error === \"object\" && \"code\" in error && typeof error.code === \"string\") {\n\t\treturn error.code;\n\t}\n\treturn undefined;\n}\n\nexport function compactApplyPatchResult(result: ApplyPatchResult): ApplyPatchResult {\n\treturn {\n\t\t...result,\n\t\tdetails: {\n\t\t\t...result.details,\n\t\t\tappliedOperations: result.details.appliedOperations.map(({ operationIndex, preview }) => {\n\t\t\t\tconst { diff: _diff, patch: _patch, ...metadata } = preview;\n\t\t\t\treturn { operationIndex, preview: { ...metadata, diff: \"\" } };\n\t\t\t}),\n\t\t},\n\t};\n}\n\nasync function writeFileAtomic(\n\tabsPath: string,\n\tcontent: string,\n\toperations: AtomicWriteOperations = ATOMIC_WRITE_OPERATIONS,\n): Promise<void> {\n\tconst tempPath = `${absPath}.tmp.${process.pid}.${Math.random().toString(16).slice(2)}`;\n\tawait operations.writeFile(tempPath, content, \"utf-8\");\n\ttry {\n\t\tawait operations.rename(tempPath, absPath);\n\t} catch (error) {\n\t\tif (!hasErrorCode(error, \"EEXIST\")) throw error;\n\t\tawait operations.unlink(absPath);\n\t\tawait operations.rename(tempPath, absPath);\n\t}\n}\n\nexport async function __testWriteFileAtomic(\n\tabsPath: string,\n\tcontent: string,\n\toperations: AtomicWriteOperations,\n): Promise<void> {\n\tawait writeFileAtomic(absPath, content, operations);\n}\n\nasync function applySingleHunk(\n\tcwd: string,\n\thunk: ParsedPatch,\n): Promise<{\n\treadonly summary: string;\n\treadonly appliedFile: string;\n\treadonly fuzz: number;\n\treadonly preview: ReturnType<typeof buildPatchPreviewFile>;\n}> {\n\tconst absolutePath = resolvePatchPath(cwd, hunk.filePath);\n\tconst mutationPaths =\n\t\thunk.type === \"update\" && hunk.movePath ? [absolutePath, resolvePatchPath(cwd, hunk.movePath)] : [absolutePath];\n\treturn withPatchMutationQueues(mutationPaths, async () => {\n\t\tif (hunk.type === \"add\") {\n\t\t\tconst source = await readPatchFileSnapshot(absolutePath);\n\t\t\tconst preview = buildPatchPreviewFile({ hunk, source, newContent: hunk.content });\n\t\t\tawait mkdir(path.dirname(absolutePath), { recursive: true });\n\t\t\tawait writeFileAtomic(absolutePath, hunk.content);\n\t\t\treturn { summary: `add: ${hunk.filePath}`, appliedFile: hunk.filePath, fuzz: 0, preview };\n\t\t}\n\n\t\tif (hunk.type === \"delete\") {\n\t\t\tconst oldContent = await readFile(absolutePath, \"utf-8\");\n\t\t\tconst preview = buildPatchPreviewFile({\n\t\t\t\thunk,\n\t\t\t\tsource: { exists: true, content: oldContent },\n\t\t\t\tnewContent: \"\",\n\t\t\t});\n\t\t\tawait rm(absolutePath);\n\t\t\treturn { summary: `delete: ${hunk.filePath}`, appliedFile: hunk.filePath, fuzz: 0, preview };\n\t\t}\n\n\t\tconst currentContent = await readFile(absolutePath, \"utf-8\");\n\t\tconst chunkResult =\n\t\t\thunk.chunks.length === 0\n\t\t\t\t? { content: currentContent, fuzz: 0 }\n\t\t\t\t: replaceChunks(currentContent, hunk.filePath, hunk.chunks);\n\n\t\tif (hunk.movePath) {\n\t\t\tconst absoluteMovePath = resolvePatchPath(cwd, hunk.movePath);\n\t\t\tconst moveDestination =\n\t\t\t\tabsoluteMovePath === absolutePath ? undefined : await readPatchFileSnapshot(absoluteMovePath);\n\t\t\tconst preview = buildPatchPreviewFile({\n\t\t\t\thunk,\n\t\t\t\tsource: { exists: true, content: currentContent },\n\t\t\t\tnewContent: chunkResult.content,\n\t\t\t\t...(moveDestination ? { moveDestination } : {}),\n\t\t\t});\n\t\t\tawait mkdir(path.dirname(absoluteMovePath), { recursive: true });\n\t\t\tawait writeFileAtomic(absoluteMovePath, chunkResult.content);\n\t\t\tif (absoluteMovePath !== absolutePath) await rm(absolutePath);\n\t\t\treturn {\n\t\t\t\tsummary: `move: ${hunk.filePath} -> ${hunk.movePath}`,\n\t\t\t\tappliedFile: hunk.movePath,\n\t\t\t\tfuzz: chunkResult.fuzz,\n\t\t\t\tpreview,\n\t\t\t};\n\t\t}\n\n\t\tconst preview = buildPatchPreviewFile({\n\t\t\thunk,\n\t\t\tsource: { exists: true, content: currentContent },\n\t\t\tnewContent: chunkResult.content,\n\t\t});\n\t\tawait writeFileAtomic(absolutePath, chunkResult.content);\n\t\treturn { summary: `update: ${hunk.filePath}`, appliedFile: hunk.filePath, fuzz: chunkResult.fuzz, preview };\n\t});\n}\n\nasync function withPatchMutationQueues<T>(filePaths: readonly string[], operation: () => Promise<T>): Promise<T> {\n\tconst sortedPaths = [...new Set(filePaths)].sort((left, right) => left.localeCompare(right));\n\tconst runQueued = (index: number): Promise<T> => {\n\t\tconst filePath = sortedPaths[index];\n\t\tif (filePath === undefined) return operation();\n\t\treturn withFileMutationQueue(filePath, () => runQueued(index + 1));\n\t};\n\treturn runQueued(0);\n}\n\nfunction parseNonEmptyPatch(patchText: string): ParsedPatch[] {\n\tconst hunks = parsePatch(patchText);\n\tif (hunks.length === 0) {\n\t\tconst normalized = normalizePatchText(patchText).trim();\n\t\tif (normalized === \"*** Begin Patch\\n*** End Patch\") throw new Error(\"patch rejected: empty patch\");\n\t\tthrow new Error(\"apply_patch verification failed: no hunks found\");\n\t}\n\treturn hunks;\n}\n\nexport async function applyPatchDetailed(\n\tcwd: string,\n\tpatchText: string,\n\tonProgress?: ApplyPatchProgressCallback,\n): Promise<ApplyPatchResult> {\n\tconst hunks = parseNonEmptyPatch(patchText);\n\tconst summaries: string[] = [];\n\tconst appliedFiles: string[] = [];\n\tconst appliedOperations: AppliedPatchOperation[] = [];\n\tconst failures: ApplyPatchFailure[] = [];\n\tlet fuzz = 0;\n\n\tfor (const [operationIndex, hunk] of hunks.entries()) {\n\t\ttry {\n\t\t\tconst applied = await applySingleHunk(cwd, hunk);\n\t\t\tsummaries.push(applied.summary);\n\t\t\tappliedFiles.push(applied.appliedFile);\n\t\t\tappliedOperations.push({ operationIndex, preview: applied.preview });\n\t\t\tfuzz += applied.fuzz;\n\t\t} catch (error) {\n\t\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\t\tconst code = extractErrorCode(error);\n\t\t\tfailures.push({ operationIndex, filePath: hunk.filePath, operation: hunk.type, message, code });\n\t\t}\n\t\tawait notifyApplyPatchProgress(onProgress, {\n\t\t\tapplied: appliedFiles.length,\n\t\t\tfailed: failures.length,\n\t\t\ttotal: hunks.length,\n\t\t});\n\t}\n\n\tconst result: ApplyPatchResult = {\n\t\tsummaries,\n\t\tappliedFiles,\n\t\tfailures,\n\t\thasPartialSuccess: appliedFiles.length > 0 && failures.length > 0,\n\t\trecoveryInstructions: { mustReadFiles: [], mustNotReadFiles: [], failedFiles: [] },\n\t\tdetails: { fuzz, appliedOperations },\n\t};\n\tresult.recoveryInstructions = createRecoveryInstructions(result);\n\treturn result;\n}\n\nexport async function applyPatch(cwd: string, patchText: string): Promise<string[]> {\n\tconst hunks = parseNonEmptyPatch(patchText);\n\tconst summaries: string[] = [];\n\tconst appliedFiles: string[] = [];\n\tconst appliedOperations: AppliedPatchOperation[] = [];\n\tfor (const [operationIndex, hunk] of hunks.entries()) {\n\t\ttry {\n\t\t\tconst applied = await applySingleHunk(cwd, hunk);\n\t\t\tsummaries.push(applied.summary);\n\t\t\tappliedFiles.push(applied.appliedFile);\n\t\t\tappliedOperations.push({ operationIndex, preview: applied.preview });\n\t\t} catch (error) {\n\t\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\t\tconst failures: ApplyPatchFailure[] = [\n\t\t\t\t{ operationIndex, filePath: hunk.filePath, operation: hunk.type, message, code: extractErrorCode(error) },\n\t\t\t];\n\t\t\tconst result: ApplyPatchResult = {\n\t\t\t\tsummaries,\n\t\t\t\tappliedFiles,\n\t\t\t\tfailures,\n\t\t\t\thasPartialSuccess: appliedFiles.length > 0,\n\t\t\t\trecoveryInstructions: createRecoveryInstructions({ appliedFiles, failures }),\n\t\t\t\tdetails: { fuzz: 0, appliedOperations },\n\t\t\t};\n\t\t\tthrow new ApplyPatchError(message, compactApplyPatchResult(result));\n\t\t}\n\t}\n\n\treturn summaries;\n}\n"]}
|
|
@@ -7,6 +7,6 @@ export { clearApplyPatchRenderState, displayPath, formatInFlightCallText, format
|
|
|
7
7
|
export { seekSequence } from "./seek-sequence.ts";
|
|
8
8
|
export { StreamingPatchParser } from "./streaming-parser.ts";
|
|
9
9
|
export { extractPatchedPaths, normalizePatchText, stripHeredoc } from "./text.ts";
|
|
10
|
-
export { createApplyPatchTool } from "./tool.ts";
|
|
10
|
+
export { APPLY_PATCH_RESULT_PATCH_MAX_BYTES, createApplyPatchTool } from "./tool.ts";
|
|
11
11
|
export type { ApplyPatchExtensionAPI, ApplyPatchFailure, ApplyPatchParams, ApplyPatchPreview, ApplyPatchProgress, ApplyPatchProgressCallback, ApplyPatchRecoveryInstructions, ApplyPatchRenderState, ApplyPatchResult, ApplyPatchToolDefinition, ApplyPatchToolDetails, AtomicWriteOperations, FreeformToolFormat, ParsedPatch, PatchChunk, } from "./types.ts";
|
|
12
12
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/gpt-apply-patch/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,UAAU,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AAC5G,OAAO,EACN,gCAAgC,EAChC,4BAA4B,EAC5B,wBAAwB,EACxB,kBAAkB,EAClB,6BAA6B,GAC7B,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,2BAA2B,EAAE,MAAM,gBAAgB,CAAC;AAC/G,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EACN,0BAA0B,EAC1B,WAAW,EACX,sBAAsB,EACtB,kBAAkB,EAClB,wBAAwB,EACxB,uBAAuB,EACvB,uBAAuB,EACvB,kBAAkB,EAClB,eAAe,GACf,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAClF,OAAO,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/gpt-apply-patch/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,UAAU,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AAC5G,OAAO,EACN,gCAAgC,EAChC,4BAA4B,EAC5B,wBAAwB,EACxB,kBAAkB,EAClB,6BAA6B,GAC7B,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,2BAA2B,EAAE,MAAM,gBAAgB,CAAC;AAC/G,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EACN,0BAA0B,EAC1B,WAAW,EACX,sBAAsB,EACtB,kBAAkB,EAClB,wBAAwB,EACxB,uBAAuB,EACvB,uBAAuB,EACvB,kBAAkB,EAClB,eAAe,GACf,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAClF,OAAO,EAAE,kCAAkC,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AACrF,YAAY,EACX,sBAAsB,EACtB,iBAAiB,EACjB,gBAAgB,EAChB,iBAAiB,EACjB,kBAAkB,EAClB,0BAA0B,EAC1B,8BAA8B,EAC9B,qBAAqB,EACrB,gBAAgB,EAChB,wBAAwB,EACxB,qBAAqB,EACrB,qBAAqB,EACrB,kBAAkB,EAClB,WAAW,EACX,UAAU,GACV,MAAM,YAAY,CAAC"}
|
|
@@ -7,5 +7,5 @@ export { clearApplyPatchRenderState, displayPath, formatInFlightCallText, format
|
|
|
7
7
|
export { seekSequence } from "./seek-sequence.js";
|
|
8
8
|
export { StreamingPatchParser } from "./streaming-parser.js";
|
|
9
9
|
export { extractPatchedPaths, normalizePatchText, stripHeredoc } from "./text.js";
|
|
10
|
-
export { createApplyPatchTool } from "./tool.js";
|
|
10
|
+
export { APPLY_PATCH_RESULT_PATCH_MAX_BYTES, createApplyPatchTool } from "./tool.js";
|
|
11
11
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/gpt-apply-patch/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,UAAU,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AAC5G,OAAO,EACN,gCAAgC,EAChC,4BAA4B,EAC5B,wBAAwB,EACxB,kBAAkB,EAClB,6BAA6B,GAC7B,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,2BAA2B,EAAE,MAAM,gBAAgB,CAAC;AAC/G,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EACN,0BAA0B,EAC1B,WAAW,EACX,sBAAsB,EACtB,kBAAkB,EAClB,wBAAwB,EACxB,uBAAuB,EACvB,uBAAuB,EACvB,kBAAkB,EAClB,eAAe,GACf,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAClF,OAAO,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC","sourcesContent":["export { __testWriteFileAtomic, applyPatch, applyPatchDetailed, buildPartialFailureText } from \"./apply.ts\";\nexport {\n\tAPPLY_PATCH_FREEFORM_DESCRIPTION,\n\tAPPLY_PATCH_JSON_DESCRIPTION,\n\tAPPLY_PATCH_LARK_GRAMMAR,\n\tAPPLY_PATCH_PARAMS,\n\tCODEX_APPLY_PATCH_DESCRIPTION,\n} from \"./constants.ts\";\nexport { ApplyPatchError } from \"./errors.ts\";\nexport { default, getApplyPatchWireMode, isOpenAIGptModel, registerApplyPatchExtension } from \"./extension.ts\";\nexport { parsePatch } from \"./parser.ts\";\nexport {\n\tclearApplyPatchRenderState,\n\tdisplayPath,\n\tformatInFlightCallText,\n\tformatPatchPreview,\n\tgetApplyPatchRenderState,\n\tPATCH_PREVIEW_MAX_CHARS,\n\tPATCH_PREVIEW_MAX_LINES,\n\trenderPatchPreview,\n\ttruncatePreview,\n} from \"./preview-format.ts\";\nexport { seekSequence } from \"./seek-sequence.ts\";\nexport { StreamingPatchParser } from \"./streaming-parser.ts\";\nexport { extractPatchedPaths, normalizePatchText, stripHeredoc } from \"./text.ts\";\nexport { createApplyPatchTool } from \"./tool.ts\";\nexport type {\n\tApplyPatchExtensionAPI,\n\tApplyPatchFailure,\n\tApplyPatchParams,\n\tApplyPatchPreview,\n\tApplyPatchProgress,\n\tApplyPatchProgressCallback,\n\tApplyPatchRecoveryInstructions,\n\tApplyPatchRenderState,\n\tApplyPatchResult,\n\tApplyPatchToolDefinition,\n\tApplyPatchToolDetails,\n\tAtomicWriteOperations,\n\tFreeformToolFormat,\n\tParsedPatch,\n\tPatchChunk,\n} from \"./types.ts\";\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/gpt-apply-patch/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,UAAU,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AAC5G,OAAO,EACN,gCAAgC,EAChC,4BAA4B,EAC5B,wBAAwB,EACxB,kBAAkB,EAClB,6BAA6B,GAC7B,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,2BAA2B,EAAE,MAAM,gBAAgB,CAAC;AAC/G,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EACN,0BAA0B,EAC1B,WAAW,EACX,sBAAsB,EACtB,kBAAkB,EAClB,wBAAwB,EACxB,uBAAuB,EACvB,uBAAuB,EACvB,kBAAkB,EAClB,eAAe,GACf,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAClF,OAAO,EAAE,kCAAkC,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC","sourcesContent":["export { __testWriteFileAtomic, applyPatch, applyPatchDetailed, buildPartialFailureText } from \"./apply.ts\";\nexport {\n\tAPPLY_PATCH_FREEFORM_DESCRIPTION,\n\tAPPLY_PATCH_JSON_DESCRIPTION,\n\tAPPLY_PATCH_LARK_GRAMMAR,\n\tAPPLY_PATCH_PARAMS,\n\tCODEX_APPLY_PATCH_DESCRIPTION,\n} from \"./constants.ts\";\nexport { ApplyPatchError } from \"./errors.ts\";\nexport { default, getApplyPatchWireMode, isOpenAIGptModel, registerApplyPatchExtension } from \"./extension.ts\";\nexport { parsePatch } from \"./parser.ts\";\nexport {\n\tclearApplyPatchRenderState,\n\tdisplayPath,\n\tformatInFlightCallText,\n\tformatPatchPreview,\n\tgetApplyPatchRenderState,\n\tPATCH_PREVIEW_MAX_CHARS,\n\tPATCH_PREVIEW_MAX_LINES,\n\trenderPatchPreview,\n\ttruncatePreview,\n} from \"./preview-format.ts\";\nexport { seekSequence } from \"./seek-sequence.ts\";\nexport { StreamingPatchParser } from \"./streaming-parser.ts\";\nexport { extractPatchedPaths, normalizePatchText, stripHeredoc } from \"./text.ts\";\nexport { APPLY_PATCH_RESULT_PATCH_MAX_BYTES, createApplyPatchTool } from \"./tool.ts\";\nexport type {\n\tApplyPatchExtensionAPI,\n\tApplyPatchFailure,\n\tApplyPatchParams,\n\tApplyPatchPreview,\n\tApplyPatchProgress,\n\tApplyPatchProgressCallback,\n\tApplyPatchRecoveryInstructions,\n\tApplyPatchRenderState,\n\tApplyPatchResult,\n\tApplyPatchToolDefinition,\n\tApplyPatchToolDetails,\n\tAtomicWriteOperations,\n\tFreeformToolFormat,\n\tParsedPatch,\n\tPatchChunk,\n} from \"./types.ts\";\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/gpt-apply-patch/tool.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAKX,wBAAwB,EAGxB,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"tool.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/gpt-apply-patch/tool.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAKX,wBAAwB,EAGxB,MAAM,YAAY,CAAC;AAEpB,eAAO,MAAM,kCAAkC,QAAY,CAAC;AA8F5D,wBAAgB,oBAAoB,CAAC,OAAO,GAAE,UAAU,GAAG,MAAmB,GAAG,wBAAwB,CAkGxG"}
|
|
@@ -1,16 +1,31 @@
|
|
|
1
1
|
import { Box, Container, Spacer, Text } from "@earendil-works/pi-tui";
|
|
2
2
|
import { defineTool } from "../../types.js";
|
|
3
|
-
import { applyPatchDetailed, buildPartialFailureText } from "./apply.js";
|
|
3
|
+
import { applyPatchDetailed, buildPartialFailureText, compactApplyPatchResult } from "./apply.js";
|
|
4
4
|
import { APPLY_PATCH_FREEFORM_DESCRIPTION, APPLY_PATCH_JSON_DESCRIPTION, APPLY_PATCH_LARK_GRAMMAR, APPLY_PATCH_PARAMS, } from "./constants.js";
|
|
5
5
|
import { normalizeApplyPatchArguments } from "./params.js";
|
|
6
6
|
import { parsePatch } from "./parser.js";
|
|
7
7
|
import { createPendingPatchUpdate } from "./preview.js";
|
|
8
|
-
import { getApplyPatchRenderState, renderPatchPreview } from "./preview-format.js";
|
|
8
|
+
import { getApplyPatchRenderState, renderPatchPreview, truncatePreview } from "./preview-format.js";
|
|
9
9
|
import { renderStreamingPatchCall } from "./streaming-render.js";
|
|
10
|
+
export const APPLY_PATCH_RESULT_PATCH_MAX_BYTES = 16 * 1024;
|
|
11
|
+
function retainedPatch(patch) {
|
|
12
|
+
if (patch === undefined || Buffer.byteLength(patch, "utf8") > APPLY_PATCH_RESULT_PATCH_MAX_BYTES) {
|
|
13
|
+
return undefined;
|
|
14
|
+
}
|
|
15
|
+
return patch;
|
|
16
|
+
}
|
|
10
17
|
function appliedPreview(result) {
|
|
11
18
|
const files = [...result.details.appliedOperations]
|
|
12
19
|
.sort((left, right) => left.operationIndex - right.operationIndex)
|
|
13
|
-
.map((operation) =>
|
|
20
|
+
.map((operation) => {
|
|
21
|
+
const { diff, patch, ...metadata } = operation.preview;
|
|
22
|
+
const boundedPatch = retainedPatch(patch);
|
|
23
|
+
return {
|
|
24
|
+
...metadata,
|
|
25
|
+
diff: truncatePreview(diff),
|
|
26
|
+
...(boundedPatch === undefined ? {} : { patch: boundedPatch }),
|
|
27
|
+
};
|
|
28
|
+
});
|
|
14
29
|
if (files.length === 0)
|
|
15
30
|
return undefined;
|
|
16
31
|
return {
|
|
@@ -100,15 +115,18 @@ export function createApplyPatchTool(variant = "freeform") {
|
|
|
100
115
|
onUpdate?.({ content: [{ type: "text", text: progressUpdate.text }], details: progressUpdate.details });
|
|
101
116
|
});
|
|
102
117
|
const resultPreview = appliedPreview(result);
|
|
118
|
+
const persistedResult = compactApplyPatchResult(result);
|
|
103
119
|
if (result.failures.length > 0) {
|
|
104
120
|
return {
|
|
105
121
|
content: [{ type: "text", text: buildPartialFailureText(result) }],
|
|
106
|
-
details: resultPreview
|
|
122
|
+
details: resultPreview
|
|
123
|
+
? { preview: resultPreview, result: persistedResult }
|
|
124
|
+
: { result: persistedResult },
|
|
107
125
|
};
|
|
108
126
|
}
|
|
109
127
|
return {
|
|
110
128
|
content: [{ type: "text", text: result.summaries.join("\n") }],
|
|
111
|
-
details: resultPreview ? { preview: resultPreview, result } : { result },
|
|
129
|
+
details: resultPreview ? { preview: resultPreview, result: persistedResult } : { result: persistedResult },
|
|
112
130
|
};
|
|
113
131
|
},
|
|
114
132
|
renderCall(args, theme, context) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/gpt-apply-patch/tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AAEtE,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AACzE,OAAO,EACN,gCAAgC,EAChC,4BAA4B,EAC5B,wBAAwB,EACxB,kBAAkB,GAClB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,4BAA4B,EAAE,MAAM,aAAa,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAC;AACxD,OAAO,EAAE,wBAAwB,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACnF,OAAO,EAAE,wBAAwB,EAAE,MAAM,uBAAuB,CAAC;AAWjE,SAAS,cAAc,CAAC,MAAwB;IAC/C,MAAM,KAAK,GAAG,CAAC,GAAG,MAAM,CAAC,OAAO,CAAC,iBAAiB,CAAC;SACjD,IAAI,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,cAAc,GAAG,KAAK,CAAC,cAAc,CAAC;SACjE,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;IACxC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;QAAE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C;gBACxB,OAAO,SAAS,CAAC;YAClB,CAAC;YACD,OAAO,gBAAgB,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;QACxC,CAAC;KACD,CAAC,CAAC;IAEH,IAAI,OAAO,KAAK,MAAM;QAAE,OAAO,IAAI,CAAC;IACpC,OAAO,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE;QAC1B,QAAQ,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,wBAAwB,EAA+B;KAChH,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { Box, Container, Spacer, Text } from \"@earendil-works/pi-tui\";\nimport type { AgentToolResult, ToolRenderContext } from \"../../types.ts\";\nimport { defineTool } from \"../../types.ts\";\nimport { applyPatchDetailed, buildPartialFailureText } from \"./apply.ts\";\nimport {\n\tAPPLY_PATCH_FREEFORM_DESCRIPTION,\n\tAPPLY_PATCH_JSON_DESCRIPTION,\n\tAPPLY_PATCH_LARK_GRAMMAR,\n\tAPPLY_PATCH_PARAMS,\n} from \"./constants.ts\";\nimport { normalizeApplyPatchArguments } from \"./params.ts\";\nimport { parsePatch } from \"./parser.ts\";\nimport { createPendingPatchUpdate } from \"./preview.ts\";\nimport { getApplyPatchRenderState, renderPatchPreview } from \"./preview-format.ts\";\nimport { renderStreamingPatchCall } from \"./streaming-render.ts\";\nimport type {\n\tApplyPatchPreview,\n\tApplyPatchRenderState,\n\tApplyPatchResult,\n\tApplyPatchTheme,\n\tApplyPatchToolDefinition,\n\tApplyPatchToolDetails,\n\tFreeformToolFormat,\n} from \"./types.ts\";\n\nfunction appliedPreview(result: ApplyPatchResult): ApplyPatchPreview | undefined {\n\tconst files = [...result.details.appliedOperations]\n\t\t.sort((left, right) => left.operationIndex - right.operationIndex)\n\t\t.map((operation) => operation.preview);\n\tif (files.length === 0) return undefined;\n\treturn {\n\t\tfiles,\n\t\tadded: files.reduce((total, file) => total + file.added, 0),\n\t\tremoved: files.reduce((total, file) => total + file.removed, 0),\n\t};\n}\n\nfunction renderPreviewBox(\n\ttitle: string,\n\tdetails: ApplyPatchToolDetails,\n\tisPartial: boolean,\n\tcwd: string,\n\texpanded: boolean,\n\ttheme: ApplyPatchTheme,\n): Container {\n\tconst component = new Container();\n\tif (!details.preview) return component;\n\tconst bgName = isPartial ? \"toolPendingBg\" : \"toolSuccessBg\";\n\tconst progress = details.progress;\n\tconst renderedTitle = progress ? `Applying patch (${progress.applied + progress.failed}/${progress.total})` : title;\n\tconst box = new Box(1, 1, (text: string) => theme.bg(bgName, text));\n\tbox.addChild(new Text(theme.fg(\"toolTitle\", theme.bold(renderedTitle)), 0, 0));\n\tbox.addChild(new Spacer(1));\n\tbox.addChild(new Text(renderPatchPreview(details.preview, cwd, theme, expanded), 0, 0));\n\tcomponent.addChild(box);\n\treturn component;\n}\n\nfunction renderTextResult(\n\tresult: AgentToolResult<ApplyPatchToolDetails | undefined>,\n\ttheme: ApplyPatchTheme,\n): Container {\n\tconst component = new Container();\n\tconst text = resultText(result);\n\tif (text) component.addChild(new Text(theme.fg(\"toolOutput\", text), 0, 0));\n\treturn component;\n}\n\nfunction resultText(result: AgentToolResult<ApplyPatchToolDetails | undefined>): string {\n\treturn result.content\n\t\t.filter((block) => block.type === \"text\")\n\t\t.map((block) => block.text)\n\t\t.filter((value) => typeof value === \"string\" && value.length > 0)\n\t\t.join(\"\\n\");\n}\n\nfunction renderFailureBox(\n\tresult: AgentToolResult<ApplyPatchToolDetails>,\n\tcwd: string,\n\texpanded: boolean,\n\ttheme: ApplyPatchTheme,\n): Container {\n\tconst patchResult = result.details?.result;\n\tif (!patchResult) return renderTextResult(result, theme);\n\tconst component = new Container();\n\tconst appliedCount = patchResult.appliedFiles.length;\n\tconst title = appliedCount > 0 ? \"Patch partially failed\" : \"Patch failed\";\n\tconst box = new Box(1, 1, (text: string) => theme.bg(\"toolErrorBg\", text));\n\tbox.addChild(new Text(theme.fg(\"toolTitle\", theme.bold(title)), 0, 0));\n\tif (result.details.preview) {\n\t\tbox.addChild(new Spacer(1));\n\t\tbox.addChild(new Text(renderPatchPreview(result.details.preview, cwd, theme, expanded), 0, 0));\n\t}\n\tconst text = resultText(result);\n\tif (text) {\n\t\tbox.addChild(new Spacer(1));\n\t\tbox.addChild(new Text(theme.fg(\"toolOutput\", text), 0, 0));\n\t}\n\tcomponent.addChild(box);\n\treturn component;\n}\n\nexport function createApplyPatchTool(variant: \"freeform\" | \"json\" = \"freeform\"): ApplyPatchToolDefinition {\n\tconst tool = defineTool<typeof APPLY_PATCH_PARAMS, ApplyPatchToolDetails | undefined, ApplyPatchRenderState>({\n\t\tname: \"apply_patch\",\n\t\tlabel: \"ApplyPatch\",\n\t\tdescription: variant === \"json\" ? APPLY_PATCH_JSON_DESCRIPTION : APPLY_PATCH_FREEFORM_DESCRIPTION,\n\t\tparameters: APPLY_PATCH_PARAMS,\n\t\tprepareArguments: normalizeApplyPatchArguments,\n\t\tpromptSnippet: \"Apply Codex-format file patches with apply_patch\",\n\t\tpromptGuidelines: [\n\t\t\t\"Use apply_patch for file edits instead of mutating files through bash, Python scripts, heredocs, or shell redirection.\",\n\t\t\t\"After apply_patch succeeds, do not re-read the edited files just to confirm the patch applied.\",\n\t\t],\n\t\tasync execute(\n\t\t\t_toolCallId,\n\t\t\tparams,\n\t\t\t_signal,\n\t\t\tonUpdate,\n\t\t\tctx,\n\t\t): Promise<AgentToolResult<ApplyPatchToolDetails | undefined>> {\n\t\t\tconst normalizedParams = normalizeApplyPatchArguments(params);\n\t\t\tif (!normalizedParams.input) throw new Error(\"input is required\");\n\t\t\tlet totalOperations = 0;\n\t\t\ttry {\n\t\t\t\ttotalOperations = parsePatch(normalizedParams.input).length;\n\t\t\t} catch {\n\t\t\t\t// createPendingPatchUpdate keeps incomplete or invalid patch text renderable.\n\t\t\t}\n\t\t\tconst initialProgress = totalOperations > 0 ? { applied: 0, failed: 0, total: totalOperations } : undefined;\n\t\t\tconst pendingUpdate = await createPendingPatchUpdate(ctx.cwd, normalizedParams.input, initialProgress);\n\t\t\tonUpdate?.({ content: [{ type: \"text\", text: pendingUpdate.text }], details: pendingUpdate.details });\n\t\t\tconst preview = pendingUpdate.details?.preview;\n\t\t\tconst result = await applyPatchDetailed(ctx.cwd, normalizedParams.input, async (progress) => {\n\t\t\t\tconst progressUpdate = await createPendingPatchUpdate(ctx.cwd, normalizedParams.input, progress, preview);\n\t\t\t\tonUpdate?.({ content: [{ type: \"text\", text: progressUpdate.text }], details: progressUpdate.details });\n\t\t\t});\n\t\t\tconst resultPreview = appliedPreview(result);\n\t\t\tif (result.failures.length > 0) {\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [{ type: \"text\", text: buildPartialFailureText(result) }],\n\t\t\t\t\tdetails: resultPreview ? { preview: resultPreview, result } : { result },\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tcontent: [{ type: \"text\", text: result.summaries.join(\"\\n\") }],\n\t\t\t\tdetails: resultPreview ? { preview: resultPreview, result } : { result },\n\t\t\t};\n\t\t},\n\t\trenderCall(args, theme, context: ToolRenderContext<ApplyPatchRenderState, { input: string }>) {\n\t\t\tif (!context.executionStarted) {\n\t\t\t\tconst streaming = renderStreamingPatchCall(normalizeApplyPatchArguments(args), theme, context.state);\n\t\t\t\tif (streaming) return streaming;\n\t\t\t}\n\t\t\tif (!context.argsComplete) return new Text(theme.fg(\"toolTitle\", theme.bold(\"apply_patch: Patching\")), 0, 0);\n\t\t\tconst normalizedArgs = normalizeApplyPatchArguments(args);\n\t\t\tconst renderState = getApplyPatchRenderState(context.toolCallId, context.cwd, normalizedArgs.input);\n\t\t\tconst text = renderState.callText?.length ? `apply_patch: ${renderState.callText}` : \"apply_patch\";\n\t\t\treturn new Text(theme.fg(\"toolTitle\", theme.bold(text)), 0, 0);\n\t\t},\n\t\trenderResult(result, options, theme, context) {\n\t\t\tif (context.isError && result.details?.result?.failures.length) {\n\t\t\t\treturn renderFailureBox(result as AgentToolResult<ApplyPatchToolDetails>, context.cwd, true, theme);\n\t\t\t}\n\t\t\tif (result.details?.preview) {\n\t\t\t\tconst expanded = true;\n\t\t\t\treturn renderPreviewBox(\n\t\t\t\t\toptions.isPartial ? \"Applying patch\" : \"Applied patch\",\n\t\t\t\t\tresult.details,\n\t\t\t\t\toptions.isPartial,\n\t\t\t\t\tcontext.cwd,\n\t\t\t\t\texpanded,\n\t\t\t\t\ttheme,\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (result.details?.result) {\n\t\t\t\tconst component = new Container();\n\t\t\t\tconst box = new Box(1, 1, (text: string) =>\n\t\t\t\t\ttheme.bg(options.isPartial ? \"toolPendingBg\" : \"toolSuccessBg\", text),\n\t\t\t\t);\n\t\t\t\tbox.addChild(new Text(theme.fg(\"toolTitle\", theme.bold(\"Applying patch\")), 0, 0));\n\t\t\t\tbox.addChild(new Spacer(1));\n\t\t\t\tif (result.details.preview) {\n\t\t\t\t\tconst expanded = options.isPartial ? true : (options.expanded ?? true);\n\t\t\t\t\tbox.addChild(new Text(renderPatchPreview(result.details.preview, context.cwd, theme, expanded), 0, 0));\n\t\t\t\t}\n\t\t\t\tcomponent.addChild(box);\n\t\t\t\treturn component;\n\t\t\t}\n\t\t\treturn renderTextResult(result, theme);\n\t\t},\n\t});\n\n\tif (variant === \"json\") return tool;\n\treturn Object.assign(tool, {\n\t\tfreeform: { type: \"grammar\", syntax: \"lark\", definition: APPLY_PATCH_LARK_GRAMMAR } satisfies FreeformToolFormat,\n\t});\n}\n"]}
|
|
1
|
+
{"version":3,"file":"tool.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/gpt-apply-patch/tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AAEtE,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,uBAAuB,EAAE,MAAM,YAAY,C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AI,CAAC,kBAAkB,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,GAAG,EAAE,KAAK,EAAE,QAAQ,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;gBACxG,CAAC;gBACD,SAAS,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;gBACxB,OAAO,SAAS,CAAC;YAClB,CAAC;YACD,OAAO,gBAAgB,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;QACxC,CAAC;KACD,CAAC,CAAC;IAEH,IAAI,OAAO,KAAK,MAAM;QAAE,OAAO,IAAI,CAAC;IACpC,OAAO,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE;QAC1B,QAAQ,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,wBAAwB,EAA+B;KAChH,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { Box, Container, Spacer, Text } from \"@earendil-works/pi-tui\";\nimport type { AgentToolResult, ToolRenderContext } from \"../../types.ts\";\nimport { defineTool } from \"../../types.ts\";\nimport { applyPatchDetailed, buildPartialFailureText, compactApplyPatchResult } from \"./apply.ts\";\nimport {\n\tAPPLY_PATCH_FREEFORM_DESCRIPTION,\n\tAPPLY_PATCH_JSON_DESCRIPTION,\n\tAPPLY_PATCH_LARK_GRAMMAR,\n\tAPPLY_PATCH_PARAMS,\n} from \"./constants.ts\";\nimport { normalizeApplyPatchArguments } from \"./params.ts\";\nimport { parsePatch } from \"./parser.ts\";\nimport { createPendingPatchUpdate } from \"./preview.ts\";\nimport { getApplyPatchRenderState, renderPatchPreview, truncatePreview } from \"./preview-format.ts\";\nimport { renderStreamingPatchCall } from \"./streaming-render.ts\";\nimport type {\n\tApplyPatchPreview,\n\tApplyPatchRenderState,\n\tApplyPatchResult,\n\tApplyPatchTheme,\n\tApplyPatchToolDefinition,\n\tApplyPatchToolDetails,\n\tFreeformToolFormat,\n} from \"./types.ts\";\n\nexport const APPLY_PATCH_RESULT_PATCH_MAX_BYTES = 16 * 1024;\n\nfunction retainedPatch(patch: string | undefined): string | undefined {\n\tif (patch === undefined || Buffer.byteLength(patch, \"utf8\") > APPLY_PATCH_RESULT_PATCH_MAX_BYTES) {\n\t\treturn undefined;\n\t}\n\treturn patch;\n}\n\nfunction appliedPreview(result: ApplyPatchResult): ApplyPatchPreview | undefined {\n\tconst files = [...result.details.appliedOperations]\n\t\t.sort((left, right) => left.operationIndex - right.operationIndex)\n\t\t.map((operation) => {\n\t\t\tconst { diff, patch, ...metadata } = operation.preview;\n\t\t\tconst boundedPatch = retainedPatch(patch);\n\t\t\treturn {\n\t\t\t\t...metadata,\n\t\t\t\tdiff: truncatePreview(diff),\n\t\t\t\t...(boundedPatch === undefined ? {} : { patch: boundedPatch }),\n\t\t\t};\n\t\t});\n\tif (files.length === 0) return undefined;\n\treturn {\n\t\tfiles,\n\t\tadded: files.reduce((total, file) => total + file.added, 0),\n\t\tremoved: files.reduce((total, file) => total + file.removed, 0),\n\t};\n}\n\nfunction renderPreviewBox(\n\ttitle: string,\n\tdetails: ApplyPatchToolDetails,\n\tisPartial: boolean,\n\tcwd: string,\n\texpanded: boolean,\n\ttheme: ApplyPatchTheme,\n): Container {\n\tconst component = new Container();\n\tif (!details.preview) return component;\n\tconst bgName = isPartial ? \"toolPendingBg\" : \"toolSuccessBg\";\n\tconst progress = details.progress;\n\tconst renderedTitle = progress ? `Applying patch (${progress.applied + progress.failed}/${progress.total})` : title;\n\tconst box = new Box(1, 1, (text: string) => theme.bg(bgName, text));\n\tbox.addChild(new Text(theme.fg(\"toolTitle\", theme.bold(renderedTitle)), 0, 0));\n\tbox.addChild(new Spacer(1));\n\tbox.addChild(new Text(renderPatchPreview(details.preview, cwd, theme, expanded), 0, 0));\n\tcomponent.addChild(box);\n\treturn component;\n}\n\nfunction renderTextResult(\n\tresult: AgentToolResult<ApplyPatchToolDetails | undefined>,\n\ttheme: ApplyPatchTheme,\n): Container {\n\tconst component = new Container();\n\tconst text = resultText(result);\n\tif (text) component.addChild(new Text(theme.fg(\"toolOutput\", text), 0, 0));\n\treturn component;\n}\n\nfunction resultText(result: AgentToolResult<ApplyPatchToolDetails | undefined>): string {\n\treturn result.content\n\t\t.filter((block) => block.type === \"text\")\n\t\t.map((block) => block.text)\n\t\t.filter((value) => typeof value === \"string\" && value.length > 0)\n\t\t.join(\"\\n\");\n}\n\nfunction renderFailureBox(\n\tresult: AgentToolResult<ApplyPatchToolDetails>,\n\tcwd: string,\n\texpanded: boolean,\n\ttheme: ApplyPatchTheme,\n): Container {\n\tconst patchResult = result.details?.result;\n\tif (!patchResult) return renderTextResult(result, theme);\n\tconst component = new Container();\n\tconst appliedCount = patchResult.appliedFiles.length;\n\tconst title = appliedCount > 0 ? \"Patch partially failed\" : \"Patch failed\";\n\tconst box = new Box(1, 1, (text: string) => theme.bg(\"toolErrorBg\", text));\n\tbox.addChild(new Text(theme.fg(\"toolTitle\", theme.bold(title)), 0, 0));\n\tif (result.details.preview) {\n\t\tbox.addChild(new Spacer(1));\n\t\tbox.addChild(new Text(renderPatchPreview(result.details.preview, cwd, theme, expanded), 0, 0));\n\t}\n\tconst text = resultText(result);\n\tif (text) {\n\t\tbox.addChild(new Spacer(1));\n\t\tbox.addChild(new Text(theme.fg(\"toolOutput\", text), 0, 0));\n\t}\n\tcomponent.addChild(box);\n\treturn component;\n}\n\nexport function createApplyPatchTool(variant: \"freeform\" | \"json\" = \"freeform\"): ApplyPatchToolDefinition {\n\tconst tool = defineTool<typeof APPLY_PATCH_PARAMS, ApplyPatchToolDetails | undefined, ApplyPatchRenderState>({\n\t\tname: \"apply_patch\",\n\t\tlabel: \"ApplyPatch\",\n\t\tdescription: variant === \"json\" ? APPLY_PATCH_JSON_DESCRIPTION : APPLY_PATCH_FREEFORM_DESCRIPTION,\n\t\tparameters: APPLY_PATCH_PARAMS,\n\t\tprepareArguments: normalizeApplyPatchArguments,\n\t\tpromptSnippet: \"Apply Codex-format file patches with apply_patch\",\n\t\tpromptGuidelines: [\n\t\t\t\"Use apply_patch for file edits instead of mutating files through bash, Python scripts, heredocs, or shell redirection.\",\n\t\t\t\"After apply_patch succeeds, do not re-read the edited files just to confirm the patch applied.\",\n\t\t],\n\t\tasync execute(\n\t\t\t_toolCallId,\n\t\t\tparams,\n\t\t\t_signal,\n\t\t\tonUpdate,\n\t\t\tctx,\n\t\t): Promise<AgentToolResult<ApplyPatchToolDetails | undefined>> {\n\t\t\tconst normalizedParams = normalizeApplyPatchArguments(params);\n\t\t\tif (!normalizedParams.input) throw new Error(\"input is required\");\n\t\t\tlet totalOperations = 0;\n\t\t\ttry {\n\t\t\t\ttotalOperations = parsePatch(normalizedParams.input).length;\n\t\t\t} catch {\n\t\t\t\t// createPendingPatchUpdate keeps incomplete or invalid patch text renderable.\n\t\t\t}\n\t\t\tconst initialProgress = totalOperations > 0 ? { applied: 0, failed: 0, total: totalOperations } : undefined;\n\t\t\tconst pendingUpdate = await createPendingPatchUpdate(ctx.cwd, normalizedParams.input, initialProgress);\n\t\t\tonUpdate?.({ content: [{ type: \"text\", text: pendingUpdate.text }], details: pendingUpdate.details });\n\t\t\tconst preview = pendingUpdate.details?.preview;\n\t\t\tconst result = await applyPatchDetailed(ctx.cwd, normalizedParams.input, async (progress) => {\n\t\t\t\tconst progressUpdate = await createPendingPatchUpdate(ctx.cwd, normalizedParams.input, progress, preview);\n\t\t\t\tonUpdate?.({ content: [{ type: \"text\", text: progressUpdate.text }], details: progressUpdate.details });\n\t\t\t});\n\t\t\tconst resultPreview = appliedPreview(result);\n\t\t\tconst persistedResult = compactApplyPatchResult(result);\n\t\t\tif (result.failures.length > 0) {\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [{ type: \"text\", text: buildPartialFailureText(result) }],\n\t\t\t\t\tdetails: resultPreview\n\t\t\t\t\t\t? { preview: resultPreview, result: persistedResult }\n\t\t\t\t\t\t: { result: persistedResult },\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tcontent: [{ type: \"text\", text: result.summaries.join(\"\\n\") }],\n\t\t\t\tdetails: resultPreview ? { preview: resultPreview, result: persistedResult } : { result: persistedResult },\n\t\t\t};\n\t\t},\n\t\trenderCall(args, theme, context: ToolRenderContext<ApplyPatchRenderState, { input: string }>) {\n\t\t\tif (!context.executionStarted) {\n\t\t\t\tconst streaming = renderStreamingPatchCall(normalizeApplyPatchArguments(args), theme, context.state);\n\t\t\t\tif (streaming) return streaming;\n\t\t\t}\n\t\t\tif (!context.argsComplete) return new Text(theme.fg(\"toolTitle\", theme.bold(\"apply_patch: Patching\")), 0, 0);\n\t\t\tconst normalizedArgs = normalizeApplyPatchArguments(args);\n\t\t\tconst renderState = getApplyPatchRenderState(context.toolCallId, context.cwd, normalizedArgs.input);\n\t\t\tconst text = renderState.callText?.length ? `apply_patch: ${renderState.callText}` : \"apply_patch\";\n\t\t\treturn new Text(theme.fg(\"toolTitle\", theme.bold(text)), 0, 0);\n\t\t},\n\t\trenderResult(result, options, theme, context) {\n\t\t\tif (context.isError && result.details?.result?.failures.length) {\n\t\t\t\treturn renderFailureBox(result as AgentToolResult<ApplyPatchToolDetails>, context.cwd, true, theme);\n\t\t\t}\n\t\t\tif (result.details?.preview) {\n\t\t\t\tconst expanded = true;\n\t\t\t\treturn renderPreviewBox(\n\t\t\t\t\toptions.isPartial ? \"Applying patch\" : \"Applied patch\",\n\t\t\t\t\tresult.details,\n\t\t\t\t\toptions.isPartial,\n\t\t\t\t\tcontext.cwd,\n\t\t\t\t\texpanded,\n\t\t\t\t\ttheme,\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (result.details?.result) {\n\t\t\t\tconst component = new Container();\n\t\t\t\tconst box = new Box(1, 1, (text: string) =>\n\t\t\t\t\ttheme.bg(options.isPartial ? \"toolPendingBg\" : \"toolSuccessBg\", text),\n\t\t\t\t);\n\t\t\t\tbox.addChild(new Text(theme.fg(\"toolTitle\", theme.bold(\"Applying patch\")), 0, 0));\n\t\t\t\tbox.addChild(new Spacer(1));\n\t\t\t\tif (result.details.preview) {\n\t\t\t\t\tconst expanded = options.isPartial ? true : (options.expanded ?? true);\n\t\t\t\t\tbox.addChild(new Text(renderPatchPreview(result.details.preview, context.cwd, theme, expanded), 0, 0));\n\t\t\t\t}\n\t\t\t\tcomponent.addChild(box);\n\t\t\t\treturn component;\n\t\t\t}\n\t\t\treturn renderTextResult(result, theme);\n\t\t},\n\t});\n\n\tif (variant === \"json\") return tool;\n\treturn Object.assign(tool, {\n\t\tfreeform: { type: \"grammar\", syntax: \"lark\", definition: APPLY_PATCH_LARK_GRAMMAR } satisfies FreeformToolFormat,\n\t});\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"detectors.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/loop-guard/detectors.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"detectors.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/loop-guard/detectors.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAWnD,MAAM,MAAM,kBAAkB,GAC3B;IAAE,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC;IAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAA;CAAE,GAC/G;IACA,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;CAC5B,GACD;IACA,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,UAAU,EAAE,SAAS,MAAM,EAAE,CAAC;IACvC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;CAC5B,CAAC;AAEL,MAAM,MAAM,aAAa,GAAG,kBAAkB,CAAC,MAAM,CAAC,CAAC;AA6BvD,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,SAAS,cAAc,EAAE,GAAG,kBAAkB,GAAG,SAAS,CAUrG;AAED,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,SAAS,cAAc,EAAE,GAAG,kBAAkB,GAAG,SAAS,CAgBnG;AAED,wBAAgB,WAAW,CAAC,OAAO,EAAE,SAAS,cAAc,EAAE,GAAG,kBAAkB,GAAG,SAAS,CA6B9F;AAOD,qBAAa,UAAU;IACtB,OAAO,CAAC,OAAO,CAAuC;IAEtD,KAAK,CAAC,SAAS,EAAE,kBAAkB,GAAG,OAAO,CAW5C;IAED,KAAK,CAAC,MAAM,EAAE,WAAW,CAAC,aAAa,EAAE,MAAM,CAAC,GAAG,IAAI,CAItD;IAED,KAAK,IAAI,IAAI,CAEZ;CACD;AAED,wBAAgB,UAAU,CAAC,OAAO,EAAE,SAAS,cAAc,EAAE,EAAE,IAAI,EAAE,UAAU,GAAG,kBAAkB,GAAG,SAAS,CAW/G"}
|
|
@@ -1,5 +1,43 @@
|
|
|
1
1
|
import { CYCLE_MAX_PERIOD, CYCLE_MIN_PERIOD, CYCLE_REPETITION_THRESHOLD, ESCALATION_FACTOR, IDENTICAL_RUN_THRESHOLD, SIMILAR_RUN_THRESHOLD, SIMILARITY_THRESHOLD, } from "./policy.js";
|
|
2
2
|
import { meanAdjacentSimilarity } from "./similarity.js";
|
|
3
|
+
const TARGET_FIELDS = new Map([
|
|
4
|
+
["read", ["path"]],
|
|
5
|
+
["bash_output", ["bash_id"]],
|
|
6
|
+
["task_output", ["task_id", "name"]],
|
|
7
|
+
["task_update", ["task_id"]],
|
|
8
|
+
["task_send", ["to"]],
|
|
9
|
+
["lsp_diagnostics", ["filePath"]],
|
|
10
|
+
]);
|
|
11
|
+
function targetIdentity(record) {
|
|
12
|
+
const fields = TARGET_FIELDS.get(record.toolName);
|
|
13
|
+
if (fields === undefined)
|
|
14
|
+
return undefined;
|
|
15
|
+
let args;
|
|
16
|
+
try {
|
|
17
|
+
args = JSON.parse(record.argsJson);
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
if (typeof args !== "object" || args === null || Array.isArray(args))
|
|
23
|
+
return undefined;
|
|
24
|
+
for (const field of fields) {
|
|
25
|
+
const value = Reflect.get(args, field);
|
|
26
|
+
if (typeof value === "string" && value.length > 0)
|
|
27
|
+
return value;
|
|
28
|
+
}
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
function hasAllDistinctTargets(records) {
|
|
32
|
+
const identities = [];
|
|
33
|
+
for (const record of records) {
|
|
34
|
+
const identity = targetIdentity(record);
|
|
35
|
+
if (identity === undefined)
|
|
36
|
+
return false;
|
|
37
|
+
identities.push(identity);
|
|
38
|
+
}
|
|
39
|
+
return new Set(identities).size === identities.length;
|
|
40
|
+
}
|
|
3
41
|
export function detectIdenticalRun(records) {
|
|
4
42
|
const last = records[records.length - 1];
|
|
5
43
|
if (last === undefined)
|
|
@@ -26,9 +64,12 @@ export function detectSimilarRun(records) {
|
|
|
26
64
|
}
|
|
27
65
|
if (run < SIMILAR_RUN_THRESHOLD)
|
|
28
66
|
return undefined;
|
|
29
|
-
const
|
|
67
|
+
const runRecords = records.slice(records.length - run);
|
|
68
|
+
const argStrings = runRecords.map((record) => record.argsJson);
|
|
30
69
|
if (new Set(argStrings).size === 1)
|
|
31
70
|
return undefined;
|
|
71
|
+
if (hasAllDistinctTargets(runRecords))
|
|
72
|
+
return undefined;
|
|
32
73
|
const similarity = meanAdjacentSimilarity(argStrings);
|
|
33
74
|
if (similarity < SIMILARITY_THRESHOLD)
|
|
34
75
|
return undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"detectors.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/loop-guard/detectors.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,gBAAgB,EAChB,gBAAgB,EAChB,0BAA0B,EAC1B,iBAAiB,EACjB,uBAAuB,EACvB,qBAAqB,EACrB,oBAAoB,GACpB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AAsBzD,MAAM,UAAU,kBAAkB,CAAC,OAAkC;IACpE,MAAM,IAAI,GAAG,OAAO,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IACzC,IAAI,IAAI,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IACzC,IAAI,GAAG,GAAG,CAAC,CAAC;IACZ,KAAK,IAAI,CAAC,GAAG,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QAC9C,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE,SAAS,KAAK,IAAI,CAAC,SAAS;YAAE,MAAM;QACpD,GAAG,EAAE,CAAC;IACP,CAAC;IACD,IAAI,GAAG,GAAG,uBAAuB;QAAE,OAAO,SAAS,CAAC;IACpD,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,KAAK,EAAE,GAAG,EAAE,WAAW,EAAE,IAAI,CAAC,SAAS,EAAE,CAAC;AAChG,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,OAAkC;IAClE,MAAM,IAAI,GAAG,OAAO,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IACzC,IAAI,IAAI,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IACzC,IAAI,GAAG,GAAG,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AAC,WAAW,CAAC,CAAC;IAChF,CAAC;IACD,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IACnB,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;QACpC,IAAI,SAAS,KAAK,SAAS,IAAI,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC;YAAE,OAAO,SAAS,CAAC;IACxE,CAAC;IACD,OAAO,SAAS,CAAC;AAClB,CAAC","sourcesContent":["import {\n\tCYCLE_MAX_PERIOD,\n\tCYCLE_MIN_PERIOD,\n\tCYCLE_REPETITION_THRESHOLD,\n\tESCALATION_FACTOR,\n\tIDENTICAL_RUN_THRESHOLD,\n\tSIMILAR_RUN_THRESHOLD,\n\tSIMILARITY_THRESHOLD,\n} from \"./policy.ts\";\nimport { meanAdjacentSimilarity } from \"./similarity.ts\";\nimport type { ToolCallRecord } from \"./tracker.ts\";\n\nexport type LoopGuardDetection =\n\t| { readonly kind: \"identical\"; readonly toolName: string; readonly count: number; readonly fingerprint: string }\n\t| {\n\t\t\treadonly kind: \"similar\";\n\t\t\treadonly toolName: string;\n\t\t\treadonly count: number;\n\t\t\treadonly similarity: number;\n\t\t\treadonly fingerprint: string;\n\t }\n\t| {\n\t\t\treadonly kind: \"cycle\";\n\t\t\treadonly period: number;\n\t\t\treadonly count: number;\n\t\t\treadonly cycleTools: readonly string[];\n\t\t\treadonly fingerprint: string;\n\t };\n\nexport type LoopGuardKind = LoopGuardDetection[\"kind\"];\n\nexport function detectIdenticalRun(records: readonly ToolCallRecord[]): LoopGuardDetection | undefined {\n\tconst last = records[records.length - 1];\n\tif (last === undefined) return undefined;\n\tlet run = 1;\n\tfor (let i = records.length - 2; i >= 0; i--) {\n\t\tif (records[i]?.signature !== last.signature) break;\n\t\trun++;\n\t}\n\tif (run < IDENTICAL_RUN_THRESHOLD) return undefined;\n\treturn { kind: \"identical\", toolName: last.toolName, count: run, fingerprint: last.signature };\n}\n\nexport function detectSimilarRun(records: readonly ToolCallRecord[]): LoopGuardDetection | undefined {\n\tconst last = records[records.length - 1];\n\tif (last === undefined) return undefined;\n\tlet run = 1;\n\tfor (let i = records.length - 2; i >= 0; i--) {\n\t\tif (records[i]?.toolName !== last.toolName) break;\n\t\trun++;\n\t}\n\tif (run < SIMILAR_RUN_THRESHOLD) return undefined;\n\tconst argStrings = records.slice(records.length - run).map((record) => record.argsJson);\n\tif (new Set(argStrings).size === 1) return undefined;\n\tconst similarity = meanAdjacentSimilarity(argStrings);\n\tif (similarity < SIMILARITY_THRESHOLD) return undefined;\n\treturn { kind: \"similar\", toolName: last.toolName, count: run, similarity, fingerprint: last.toolName };\n}\n\nexport function detectCycle(records: readonly ToolCallRecord[]): LoopGuardDetection | undefined {\n\tconst total = records.length;\n\tfor (let period = CYCLE_MIN_PERIOD; period <= CYCLE_MAX_PERIOD; period++) {\n\t\tif (total < period * CYCLE_REPETITION_THRESHOLD) continue;\n\t\tconst cycle = records.slice(total - period);\n\t\tif (new Set(cycle.map((record) => record.signature)).size < 2) continue;\n\t\tlet repetitions = 1;\n\t\twhile (repetitions * period + period <= total) {\n\t\t\tconst blockStart = total - (repetitions + 1) * period;\n\t\t\tlet matches = true;\n\t\t\tfor (let offset = 0; offset < period; offset++) {\n\t\t\t\tif (records[blockStart + offset]?.signature !== cycle[offset]?.signature) {\n\t\t\t\t\tmatches = false;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (!matches) break;\n\t\t\trepetitions++;\n\t\t}\n\t\tif (repetitions < CYCLE_REPETITION_THRESHOLD) continue;\n\t\treturn {\n\t\t\tkind: \"cycle\",\n\t\t\tperiod,\n\t\t\tcount: repetitions,\n\t\t\tcycleTools: cycle.map((record) => record.toolName),\n\t\t\tfingerprint: cycle.map((record) => record.signature).join(\"\\u0001\"),\n\t\t};\n\t}\n\treturn undefined;\n}\n\ninterface GateEntry {\n\tfingerprint: string;\n\tlastNotifiedCount: number;\n}\n\nexport class NoticeGate {\n\tprivate entries = new Map<LoopGuardKind, GateEntry>();\n\n\tadmit(detection: LoopGuardDetection): boolean {\n\t\tconst existing = this.entries.get(detection.kind);\n\t\tif (existing === undefined || existing.fingerprint !== detection.fingerprint) {\n\t\t\tthis.entries.set(detection.kind, { fingerprint: detection.fingerprint, lastNotifiedCount: detection.count });\n\t\t\treturn true;\n\t\t}\n\t\tif (detection.count >= existing.lastNotifiedCount * ESCALATION_FACTOR) {\n\t\t\texisting.lastNotifiedCount = detection.count;\n\t\t\treturn true;\n\t\t}\n\t\treturn false;\n\t}\n\n\tprune(active: ReadonlyMap<LoopGuardKind, string>): void {\n\t\tfor (const [kind, entry] of this.entries) {\n\t\t\tif (active.get(kind) !== entry.fingerprint) this.entries.delete(kind);\n\t\t}\n\t}\n\n\treset(): void {\n\t\tthis.entries.clear();\n\t}\n}\n\nexport function detectLoop(records: readonly ToolCallRecord[], gate: NoticeGate): LoopGuardDetection | undefined {\n\tconst detections = [detectIdenticalRun(records), detectCycle(records), detectSimilarRun(records)];\n\tconst active = new Map<LoopGuardKind, string>();\n\tfor (const detection of detections) {\n\t\tif (detection !== undefined) active.set(detection.kind, detection.fingerprint);\n\t}\n\tgate.prune(active);\n\tfor (const detection of detections) {\n\t\tif (detection !== undefined && gate.admit(detection)) return detection;\n\t}\n\treturn undefined;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"detectors.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/loop-guard/detectors.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,gBAAgB,EAChB,gBAAgB,EAChB,0BAA0B,EAC1B,iBAAiB,EACjB,uBAAuB,EACvB,qBAAqB,EACrB,oBAAoB,GACpB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AAGzD,MAAM,aAAa,GAAG,IAAI,GAAG,CAA4B;IACxD,CAAC,MAAM,EAAE,CAAC,MAAM,CAAC,CAAC;IAClB,CAAC,aAAa,EAAE,CAAC,SAAS,CAAC,CAAC;IAC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AS,IAAI,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC;YAAE,OAAO,SAAS,CAAC;IACxE,CAAC;IACD,OAAO,SAAS,CAAC;AAClB,CAAC","sourcesContent":["import {\n\tCYCLE_MAX_PERIOD,\n\tCYCLE_MIN_PERIOD,\n\tCYCLE_REPETITION_THRESHOLD,\n\tESCALATION_FACTOR,\n\tIDENTICAL_RUN_THRESHOLD,\n\tSIMILAR_RUN_THRESHOLD,\n\tSIMILARITY_THRESHOLD,\n} from \"./policy.ts\";\nimport { meanAdjacentSimilarity } from \"./similarity.ts\";\nimport type { ToolCallRecord } from \"./tracker.ts\";\n\nconst TARGET_FIELDS = new Map<string, readonly string[]>([\n\t[\"read\", [\"path\"]],\n\t[\"bash_output\", [\"bash_id\"]],\n\t[\"task_output\", [\"task_id\", \"name\"]],\n\t[\"task_update\", [\"task_id\"]],\n\t[\"task_send\", [\"to\"]],\n\t[\"lsp_diagnostics\", [\"filePath\"]],\n]);\n\nexport type LoopGuardDetection =\n\t| { readonly kind: \"identical\"; readonly toolName: string; readonly count: number; readonly fingerprint: string }\n\t| {\n\t\t\treadonly kind: \"similar\";\n\t\t\treadonly toolName: string;\n\t\t\treadonly count: number;\n\t\t\treadonly similarity: number;\n\t\t\treadonly fingerprint: string;\n\t }\n\t| {\n\t\t\treadonly kind: \"cycle\";\n\t\t\treadonly period: number;\n\t\t\treadonly count: number;\n\t\t\treadonly cycleTools: readonly string[];\n\t\t\treadonly fingerprint: string;\n\t };\n\nexport type LoopGuardKind = LoopGuardDetection[\"kind\"];\n\nfunction targetIdentity(record: ToolCallRecord): string | undefined {\n\tconst fields = TARGET_FIELDS.get(record.toolName);\n\tif (fields === undefined) return undefined;\n\tlet args: unknown;\n\ttry {\n\t\targs = JSON.parse(record.argsJson);\n\t} catch {\n\t\treturn undefined;\n\t}\n\tif (typeof args !== \"object\" || args === null || Array.isArray(args)) return undefined;\n\tfor (const field of fields) {\n\t\tconst value: unknown = Reflect.get(args, field);\n\t\tif (typeof value === \"string\" && value.length > 0) return value;\n\t}\n\treturn undefined;\n}\n\nfunction hasAllDistinctTargets(records: readonly ToolCallRecord[]): boolean {\n\tconst identities: string[] = [];\n\tfor (const record of records) {\n\t\tconst identity = targetIdentity(record);\n\t\tif (identity === undefined) return false;\n\t\tidentities.push(identity);\n\t}\n\treturn new Set(identities).size === identities.length;\n}\n\nexport function detectIdenticalRun(records: readonly ToolCallRecord[]): LoopGuardDetection | undefined {\n\tconst last = records[records.length - 1];\n\tif (last === undefined) return undefined;\n\tlet run = 1;\n\tfor (let i = records.length - 2; i >= 0; i--) {\n\t\tif (records[i]?.signature !== last.signature) break;\n\t\trun++;\n\t}\n\tif (run < IDENTICAL_RUN_THRESHOLD) return undefined;\n\treturn { kind: \"identical\", toolName: last.toolName, count: run, fingerprint: last.signature };\n}\n\nexport function detectSimilarRun(records: readonly ToolCallRecord[]): LoopGuardDetection | undefined {\n\tconst last = records[records.length - 1];\n\tif (last === undefined) return undefined;\n\tlet run = 1;\n\tfor (let i = records.length - 2; i >= 0; i--) {\n\t\tif (records[i]?.toolName !== last.toolName) break;\n\t\trun++;\n\t}\n\tif (run < SIMILAR_RUN_THRESHOLD) return undefined;\n\tconst runRecords = records.slice(records.length - run);\n\tconst argStrings = runRecords.map((record) => record.argsJson);\n\tif (new Set(argStrings).size === 1) return undefined;\n\tif (hasAllDistinctTargets(runRecords)) return undefined;\n\tconst similarity = meanAdjacentSimilarity(argStrings);\n\tif (similarity < SIMILARITY_THRESHOLD) return undefined;\n\treturn { kind: \"similar\", toolName: last.toolName, count: run, similarity, fingerprint: last.toolName };\n}\n\nexport function detectCycle(records: readonly ToolCallRecord[]): LoopGuardDetection | undefined {\n\tconst total = records.length;\n\tfor (let period = CYCLE_MIN_PERIOD; period <= CYCLE_MAX_PERIOD; period++) {\n\t\tif (total < period * CYCLE_REPETITION_THRESHOLD) continue;\n\t\tconst cycle = records.slice(total - period);\n\t\tif (new Set(cycle.map((record) => record.signature)).size < 2) continue;\n\t\tlet repetitions = 1;\n\t\twhile (repetitions * period + period <= total) {\n\t\t\tconst blockStart = total - (repetitions + 1) * period;\n\t\t\tlet matches = true;\n\t\t\tfor (let offset = 0; offset < period; offset++) {\n\t\t\t\tif (records[blockStart + offset]?.signature !== cycle[offset]?.signature) {\n\t\t\t\t\tmatches = false;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (!matches) break;\n\t\t\trepetitions++;\n\t\t}\n\t\tif (repetitions < CYCLE_REPETITION_THRESHOLD) continue;\n\t\treturn {\n\t\t\tkind: \"cycle\",\n\t\t\tperiod,\n\t\t\tcount: repetitions,\n\t\t\tcycleTools: cycle.map((record) => record.toolName),\n\t\t\tfingerprint: cycle.map((record) => record.signature).join(\"\\u0001\"),\n\t\t};\n\t}\n\treturn undefined;\n}\n\ninterface GateEntry {\n\tfingerprint: string;\n\tlastNotifiedCount: number;\n}\n\nexport class NoticeGate {\n\tprivate entries = new Map<LoopGuardKind, GateEntry>();\n\n\tadmit(detection: LoopGuardDetection): boolean {\n\t\tconst existing = this.entries.get(detection.kind);\n\t\tif (existing === undefined || existing.fingerprint !== detection.fingerprint) {\n\t\t\tthis.entries.set(detection.kind, { fingerprint: detection.fingerprint, lastNotifiedCount: detection.count });\n\t\t\treturn true;\n\t\t}\n\t\tif (detection.count >= existing.lastNotifiedCount * ESCALATION_FACTOR) {\n\t\t\texisting.lastNotifiedCount = detection.count;\n\t\t\treturn true;\n\t\t}\n\t\treturn false;\n\t}\n\n\tprune(active: ReadonlyMap<LoopGuardKind, string>): void {\n\t\tfor (const [kind, entry] of this.entries) {\n\t\t\tif (active.get(kind) !== entry.fingerprint) this.entries.delete(kind);\n\t\t}\n\t}\n\n\treset(): void {\n\t\tthis.entries.clear();\n\t}\n}\n\nexport function detectLoop(records: readonly ToolCallRecord[], gate: NoticeGate): LoopGuardDetection | undefined {\n\tconst detections = [detectIdenticalRun(records), detectCycle(records), detectSimilarRun(records)];\n\tconst active = new Map<LoopGuardKind, string>();\n\tfor (const detection of detections) {\n\t\tif (detection !== undefined) active.set(detection.kind, detection.fingerprint);\n\t}\n\tgate.prune(active);\n\tfor (const detection of detections) {\n\t\tif (detection !== undefined && gate.admit(detection)) return detection;\n\t}\n\treturn undefined;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"health.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/mcp/health.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,EACN,SAAS,EAKT,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"health.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/mcp/health.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,EACN,SAAS,EAKT,MAAM,aAAa,CAAC;AAGrB,eAAO,MAAM,iBAAiB,QAAS,CAAC;AACxC,eAAO,MAAM,mBAAmB,OAAQ,CAAC;AASzC,MAAM,MAAM,kBAAkB,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;AAExD,wBAAsB,2BAA2B,CAChD,UAAU,EAAE,gBAAgB,EAC5B,WAAW,CAAC,EAAE,kBAAkB,GAC9B,OAAO,CAAC,IAAI,CAAC,CA+Bf;AAED,wBAAsB,yBAAyB,CAAC,CAAC,EAChD,UAAU,EAAE,gBAAgB,EAC5B,SAAS,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GACzB,OAAO,CAAC,CAAC,CAAC,CAgBZ;AAED,wBAAsB,+BAA+B,CAAC,CAAC,EACtD,UAAU,EAAE,gBAAgB,EAC5B,SAAS,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GACzB,OAAO,CAAC,CAAC,CAAC,CAgBZ;AA6CD,wBAAgB,0BAA0B,CAAC,UAAU,EAAE,gBAAgB,EAAE,KAAK,EAAE,OAAO,GAAG,SAAS,GAAG,SAAS,CAK9G"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { UnauthorizedError } from "@modelcontextprotocol/sdk/client/auth.js";
|
|
2
2
|
import { OAuthFlowError } from "./auth/oauth-errors.js";
|
|
3
3
|
import { AuthError, ConnectError, isMcpSessionExpiredError, isRetriableMcpError, SessionExpiredError, } from "./errors.js";
|
|
4
|
+
import { reconnectMcpNow } from "./reconnect.js";
|
|
4
5
|
export const MCP_PING_STALE_MS = 30_000;
|
|
5
6
|
export const MCP_PING_TIMEOUT_MS = 2_000;
|
|
6
7
|
const healthByConnection = new WeakMap();
|
|
@@ -49,7 +50,7 @@ export async function withMcpSessionExpiryRetry(connection, operation) {
|
|
|
49
50
|
if (!isMcpSessionExpiredError(error))
|
|
50
51
|
throw error;
|
|
51
52
|
connection.markDegraded(sessionExpiredError(connection, error, true));
|
|
52
|
-
await connection
|
|
53
|
+
await reconnectMcpNow(connection);
|
|
53
54
|
try {
|
|
54
55
|
return await operation();
|
|
55
56
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"health.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/mcp/health.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,0CAA0C,CAAC;AAC7E,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAExD,OAAO,EACN,SAAS,EACT,YAAY,EACZ,wBAAwB,EACxB,mBAAmB,EACnB,mBAAmB,GACnB,MAAM,aAAa,CAAC;AAErB,MAAM,CAAC,MAAM,iBAAiB,GAAG,MAAM,CAAC;AACxC,MAAM,CAAC,MAAM,mBAAmB,GAAG,KAAK,CAAC;AAOzC,MAAM,kBAAkB,GAAG,IAAI,OAAO,EAAoC,CAAC;AAI3E,MAAM,CAAC,KAAK,UAAU,2BAA2B,CAChD,UAA4B,EAC5B,WAAgC;IAEhC,MAAM,eAAe,CAAC,UAAU,EAAE,WAAW,CAA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AU;KACjC,CAAC,CAAC;AACJ,CAAC;AAED,SAAS,mBAAmB,CAAC,UAA4B,EAAE,KAAc,EAAE,SAAkB;IAC5F,MAAM,MAAM,GAAG,SAAS;QACvB,CAAC,CAAC,qBAAqB;QACvB,CAAC,CAAC,uDAAuD,UAAU,CAAC,UAAU,EAAE,CAAC;IAClF,OAAO,IAAI,mBAAmB,CAAC,cAAc,UAAU,CAAC,UAAU,qBAAqB,MAAM,EAAE,EAAE;QAChG,KAAK;QACL,KAAK,EAAE,SAAS;QAChB,SAAS;QACT,UAAU,EAAE,UAAU,CAAC,UAAU;KACjC,CAAC,CAAC;AACJ,CAAC;AAED,SAAS,iBAAiB,CAAC,UAA4B,EAAE,KAAe;IACvE,OAAO,IAAI,SAAS,CACnB,cAAc,UAAU,CAAC,UAAU,6DAA6D,UAAU,CAAC,UAAU,2BAA2B,UAAU,CAAC,UAAU,kBAAkB,EACvL,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,CAAC,UAAU,EAAE,CAC3D,CAAC;AACH,CAAC;AAED,SAAS,gBAAgB,CAAC,KAAc,EAAE,KAAK,GAAG,CAAC;IAClD,IAAI,KAAK,YAAY,iBAAiB;QAAE,OAAO,IAAI,CAAC;IACpD,IAAI,KAAK,YAAY,cAAc;QAAE,OAAO,KAAK,CAAC,QAAQ,CAAC;IAC3D,IAAI,KAAK,GAAG,CAAC,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,IAAI,KAAK,EAAE,CAAC;QAClF,OAAO,gBAAgB,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,GAAG,CAAC,CAAC,CAAC;IACjD,CAAC;IACD,OAAO,KAAK,CAAC;AACd,CAAC","sourcesContent":["import { UnauthorizedError } from \"@modelcontextprotocol/sdk/client/auth.js\";\nimport { OAuthFlowError } from \"./auth/oauth-errors.ts\";\nimport type { ServerConnection } from \"./connection.ts\";\nimport {\n\tAuthError,\n\tConnectError,\n\tisMcpSessionExpiredError,\n\tisRetriableMcpError,\n\tSessionExpiredError,\n} from \"./errors.ts\";\n\nexport const MCP_PING_STALE_MS = 30_000;\nexport const MCP_PING_TIMEOUT_MS = 2_000;\n\ninterface McpHealthState {\n\tlastSuccessfulPingAtMs: number | undefined;\n\tpendingValidation: Promise<void> | undefined;\n}\n\nconst healthByConnection = new WeakMap<ServerConnection, McpHealthState>();\n\nexport type McpEnsureFreshAuth = () => Promise<unknown>;\n\nexport async function ensureMcpToolCallConnection(\n\tconnection: ServerConnection,\n\tensureFresh?: McpEnsureFreshAuth,\n): Promise<void> {\n\tawait ensureFreshAuth(connection, ensureFresh);\n\tconst health = healthStateFor(connection);\n\tif (connection.state !== \"connected\") {\n\t\tif (connection.state === \"idle\" || connection.state === \"connecting\") {\n\t\t\ttry {\n\t\t\t\tawait connection.connect();\n\t\t\t} catch (error) {\n\t\t\t\tif (isNeedsAuthError(error)) throw headlessAuthError(connection, error);\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t} else if (connection.state === \"needs_auth\") {\n\t\t\tthrow headlessAuthError(connection);\n\t\t} else {\n\t\t\tawait renewConnection(connection, health);\n\t\t\treturn;\n\t\t}\n\t}\n\tconst lastSuccessfulPingAtMs = health.lastSuccessfulPingAtMs;\n\tif (lastSuccessfulPingAtMs !== undefined && Date.now() - lastSuccessfulPingAtMs <= MCP_PING_STALE_MS) {\n\t\treturn;\n\t}\n\tif (health.pendingValidation !== undefined) {\n\t\tawait health.pendingValidation;\n\t\treturn;\n\t}\n\tconst pendingValidation = pingOrRenew(connection, health).finally(() => {\n\t\tif (health.pendingValidation === pendingValidation) health.pendingValidation = undefined;\n\t});\n\thealth.pendingValidation = pendingValidation;\n\tawait pendingValidation;\n}\n\nexport async function withMcpSessionExpiryRetry<T>(\n\tconnection: ServerConnection,\n\toperation: () => Promise<T>,\n): Promise<T> {\n\ttry {\n\t\treturn await operation();\n\t} catch (error) {\n\t\tif (!isMcpSessionExpiredError(error)) throw error;\n\t\tconnection.markDegraded(sessionExpiredError(connection, error, true));\n\t\tawait connection.renew();\n\t\ttry {\n\t\t\treturn await operation();\n\t\t} catch (retryError) {\n\t\t\tif (!isMcpSessionExpiredError(retryError)) throw retryError;\n\t\t\tconst expired = sessionExpiredError(connection, retryError, false);\n\t\t\tconnection.markSuspended(expired);\n\t\t\tthrow expired;\n\t\t}\n\t}\n}\n\nexport async function withMcpRetriableFailedSendRetry<T>(\n\tconnection: ServerConnection,\n\toperation: () => Promise<T>,\n): Promise<T> {\n\ttry {\n\t\treturn await operation();\n\t} catch (error) {\n\t\tif (!isRetriableFailedSendError(error)) throw error;\n\t\tconnection.markDegraded(failedSendError(connection, error, true));\n\t\tawait connection.renew();\n\t\ttry {\n\t\t\treturn await operation();\n\t\t} catch (retryError) {\n\t\t\tif (isRetriableFailedSendError(retryError)) {\n\t\t\t\tconnection.markDegraded(failedSendError(connection, retryError, false));\n\t\t\t}\n\t\t\tthrow retryError;\n\t\t}\n\t}\n}\n\nfunction healthStateFor(connection: ServerConnection): McpHealthState {\n\tlet health = healthByConnection.get(connection);\n\tif (health === undefined) {\n\t\thealth = { lastSuccessfulPingAtMs: undefined, pendingValidation: undefined };\n\t\thealthByConnection.set(connection, health);\n\t}\n\treturn health;\n}\n\nasync function pingOrRenew(connection: ServerConnection, health: McpHealthState): Promise<void> {\n\ttry {\n\t\tawait connection.client.ping({ timeout: MCP_PING_TIMEOUT_MS });\n\t\thealth.lastSuccessfulPingAtMs = Date.now();\n\t} catch (error) {\n\t\tconnection.markDegraded(error instanceof Error ? error : new Error(String(error)));\n\t\tawait renewConnection(connection, health);\n\t}\n}\n\nasync function renewConnection(connection: ServerConnection, health: McpHealthState): Promise<void> {\n\ttry {\n\t\tawait connection.renew();\n\t} catch (error) {\n\t\tif (isNeedsAuthError(error)) throw headlessAuthError(connection, error);\n\t\tthrow error;\n\t}\n\thealth.lastSuccessfulPingAtMs = Date.now();\n}\n\nasync function ensureFreshAuth(\n\tconnection: ServerConnection,\n\tensureFresh: McpEnsureFreshAuth | undefined,\n): Promise<void> {\n\tif (ensureFresh === undefined) return;\n\ttry {\n\t\tawait ensureFresh();\n\t} catch (error) {\n\t\tconst authError = markMcpConnectionNeedsAuth(connection, error);\n\t\tif (authError !== undefined) throw authError;\n\t\tthrow error;\n\t}\n}\n\nexport function markMcpConnectionNeedsAuth(connection: ServerConnection, error: unknown): AuthError | undefined {\n\tif (!isNeedsAuthError(error)) return undefined;\n\tconst authError = headlessAuthError(connection, error);\n\tconnection.markNeedsAuth(authError);\n\treturn authError;\n}\n\nfunction isRetriableFailedSendError(error: unknown): boolean {\n\treturn isRetriableMcpError(error) && !isMcpSessionExpiredError(error);\n}\n\nfunction failedSendError(connection: ServerConnection, cause: unknown, retriable: boolean): ConnectError {\n\tconst suffix = retriable\n\t\t? \"reconnecting once before retry\"\n\t\t: `post-reconnect retry also failed; run /mcp reconnect ${connection.serverName}`;\n\treturn new ConnectError(`MCP server ${connection.serverName} failed to send tool call; ${suffix}`, {\n\t\tcause,\n\t\tphase: \"call\",\n\t\tretriable,\n\t\tserverName: connection.serverName,\n\t});\n}\n\nfunction sessionExpiredError(connection: ServerConnection, cause: unknown, retriable: boolean): SessionExpiredError {\n\tconst suffix = retriable\n\t\t? \"reinitializing once\"\n\t\t: `reinitialize retry also expired; run /mcp reconnect ${connection.serverName}`;\n\treturn new SessionExpiredError(`MCP server ${connection.serverName} session expired; ${suffix}`, {\n\t\tcause,\n\t\tphase: \"session\",\n\t\tretriable,\n\t\tserverName: connection.serverName,\n\t});\n}\n\nfunction headlessAuthError(connection: ServerConnection, cause?: unknown): AuthError {\n\treturn new AuthError(\n\t\t`MCP server ${connection.serverName} needs OAuth. Run senpi interactive, then /mcp auth-start ${connection.serverName} and /mcp auth-complete ${connection.serverName} <redirect-url>.`,\n\t\t{ cause, phase: \"auth\", serverName: connection.serverName },\n\t);\n}\n\nfunction isNeedsAuthError(error: unknown, depth = 0): boolean {\n\tif (error instanceof UnauthorizedError) return true;\n\tif (error instanceof OAuthFlowError) return error.terminal;\n\tif (depth < 5 && error !== null && typeof error === \"object\" && \"cause\" in error) {\n\t\treturn isNeedsAuthError(error.cause, depth + 1);\n\t}\n\treturn false;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"health.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/mcp/health.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,0CAA0C,CAAC;AAC7E,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAExD,OAAO,EACN,SAAS,EACT,YAAY,EACZ,wBAAwB,EACxB,mBAAmB,EACnB,mBAAmB,GACnB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEjD,MAAM,CAAC,MAAM,iBAAiB,GAAG,MAAM,CAAC;AACxC,MAAM,CAAC,MAAM,mBAAmB,GAAG,KAAK,CAAC;AAOzC,MAAM,kBAAkB,GAAG,IAAI,OAAO,EAAoC,CAAC;AAI3E,MAAM,CAAC,KAAK,UAAU,2BAA2B,CAChD,UAA4B,EAC5B,WAAgC;IAEhC,MAAM,eAAe,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC;IAC/C,MAAM,MAAM,GAAG,cAAc,CAAC,UAAU,CAAC,CAAC;IAC1C,IAAI,UAAU,CAAC,KAAK,KAAK,WAAW,EAAE,CAAC;QACtC,IAAI,UAAU,CAAC,KAAK,KAAK,MAAM,IAAI,UAAU,CAAC,KAAK,KAAK,YAAY,EAAE,CAAC;YACtE,IAAI,CAAC;gBACJ,MAAM,UAAU,CAAC,OAAO,EAAE,CAAC;YAC5B,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBAChB,IAAI,gBAAgB,CAAC,KAAK,CAAC;oBAAE,MAAM,iBAAiB,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;gBACxE,MAAM,KAAK,CAAC;YACb,CAAC;QACF,CAAC;aAAM,I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AS,CACnB,cAAc,UAAU,CAAC,UAAU,6DAA6D,UAAU,CAAC,UAAU,2BAA2B,UAAU,CAAC,UAAU,kBAAkB,EACvL,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,CAAC,UAAU,EAAE,CAC3D,CAAC;AACH,CAAC;AAED,SAAS,gBAAgB,CAAC,KAAc,EAAE,KAAK,GAAG,CAAC;IAClD,IAAI,KAAK,YAAY,iBAAiB;QAAE,OAAO,IAAI,CAAC;IACpD,IAAI,KAAK,YAAY,cAAc;QAAE,OAAO,KAAK,CAAC,QAAQ,CAAC;IAC3D,IAAI,KAAK,GAAG,CAAC,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,IAAI,KAAK,EAAE,CAAC;QAClF,OAAO,gBAAgB,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,GAAG,CAAC,CAAC,CAAC;IACjD,CAAC;IACD,OAAO,KAAK,CAAC;AACd,CAAC","sourcesContent":["import { UnauthorizedError } from \"@modelcontextprotocol/sdk/client/auth.js\";\nimport { OAuthFlowError } from \"./auth/oauth-errors.ts\";\nimport type { ServerConnection } from \"./connection.ts\";\nimport {\n\tAuthError,\n\tConnectError,\n\tisMcpSessionExpiredError,\n\tisRetriableMcpError,\n\tSessionExpiredError,\n} from \"./errors.ts\";\nimport { reconnectMcpNow } from \"./reconnect.ts\";\n\nexport const MCP_PING_STALE_MS = 30_000;\nexport const MCP_PING_TIMEOUT_MS = 2_000;\n\ninterface McpHealthState {\n\tlastSuccessfulPingAtMs: number | undefined;\n\tpendingValidation: Promise<void> | undefined;\n}\n\nconst healthByConnection = new WeakMap<ServerConnection, McpHealthState>();\n\nexport type McpEnsureFreshAuth = () => Promise<unknown>;\n\nexport async function ensureMcpToolCallConnection(\n\tconnection: ServerConnection,\n\tensureFresh?: McpEnsureFreshAuth,\n): Promise<void> {\n\tawait ensureFreshAuth(connection, ensureFresh);\n\tconst health = healthStateFor(connection);\n\tif (connection.state !== \"connected\") {\n\t\tif (connection.state === \"idle\" || connection.state === \"connecting\") {\n\t\t\ttry {\n\t\t\t\tawait connection.connect();\n\t\t\t} catch (error) {\n\t\t\t\tif (isNeedsAuthError(error)) throw headlessAuthError(connection, error);\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t} else if (connection.state === \"needs_auth\") {\n\t\t\tthrow headlessAuthError(connection);\n\t\t} else {\n\t\t\tawait renewConnection(connection, health);\n\t\t\treturn;\n\t\t}\n\t}\n\tconst lastSuccessfulPingAtMs = health.lastSuccessfulPingAtMs;\n\tif (lastSuccessfulPingAtMs !== undefined && Date.now() - lastSuccessfulPingAtMs <= MCP_PING_STALE_MS) {\n\t\treturn;\n\t}\n\tif (health.pendingValidation !== undefined) {\n\t\tawait health.pendingValidation;\n\t\treturn;\n\t}\n\tconst pendingValidation = pingOrRenew(connection, health).finally(() => {\n\t\tif (health.pendingValidation === pendingValidation) health.pendingValidation = undefined;\n\t});\n\thealth.pendingValidation = pendingValidation;\n\tawait pendingValidation;\n}\n\nexport async function withMcpSessionExpiryRetry<T>(\n\tconnection: ServerConnection,\n\toperation: () => Promise<T>,\n): Promise<T> {\n\ttry {\n\t\treturn await operation();\n\t} catch (error) {\n\t\tif (!isMcpSessionExpiredError(error)) throw error;\n\t\tconnection.markDegraded(sessionExpiredError(connection, error, true));\n\t\tawait reconnectMcpNow(connection);\n\t\ttry {\n\t\t\treturn await operation();\n\t\t} catch (retryError) {\n\t\t\tif (!isMcpSessionExpiredError(retryError)) throw retryError;\n\t\t\tconst expired = sessionExpiredError(connection, retryError, false);\n\t\t\tconnection.markSuspended(expired);\n\t\t\tthrow expired;\n\t\t}\n\t}\n}\n\nexport async function withMcpRetriableFailedSendRetry<T>(\n\tconnection: ServerConnection,\n\toperation: () => Promise<T>,\n): Promise<T> {\n\ttry {\n\t\treturn await operation();\n\t} catch (error) {\n\t\tif (!isRetriableFailedSendError(error)) throw error;\n\t\tconnection.markDegraded(failedSendError(connection, error, true));\n\t\tawait connection.renew();\n\t\ttry {\n\t\t\treturn await operation();\n\t\t} catch (retryError) {\n\t\t\tif (isRetriableFailedSendError(retryError)) {\n\t\t\t\tconnection.markDegraded(failedSendError(connection, retryError, false));\n\t\t\t}\n\t\t\tthrow retryError;\n\t\t}\n\t}\n}\n\nfunction healthStateFor(connection: ServerConnection): McpHealthState {\n\tlet health = healthByConnection.get(connection);\n\tif (health === undefined) {\n\t\thealth = { lastSuccessfulPingAtMs: undefined, pendingValidation: undefined };\n\t\thealthByConnection.set(connection, health);\n\t}\n\treturn health;\n}\n\nasync function pingOrRenew(connection: ServerConnection, health: McpHealthState): Promise<void> {\n\ttry {\n\t\tawait connection.client.ping({ timeout: MCP_PING_TIMEOUT_MS });\n\t\thealth.lastSuccessfulPingAtMs = Date.now();\n\t} catch (error) {\n\t\tconnection.markDegraded(error instanceof Error ? error : new Error(String(error)));\n\t\tawait renewConnection(connection, health);\n\t}\n}\n\nasync function renewConnection(connection: ServerConnection, health: McpHealthState): Promise<void> {\n\ttry {\n\t\tawait connection.renew();\n\t} catch (error) {\n\t\tif (isNeedsAuthError(error)) throw headlessAuthError(connection, error);\n\t\tthrow error;\n\t}\n\thealth.lastSuccessfulPingAtMs = Date.now();\n}\n\nasync function ensureFreshAuth(\n\tconnection: ServerConnection,\n\tensureFresh: McpEnsureFreshAuth | undefined,\n): Promise<void> {\n\tif (ensureFresh === undefined) return;\n\ttry {\n\t\tawait ensureFresh();\n\t} catch (error) {\n\t\tconst authError = markMcpConnectionNeedsAuth(connection, error);\n\t\tif (authError !== undefined) throw authError;\n\t\tthrow error;\n\t}\n}\n\nexport function markMcpConnectionNeedsAuth(connection: ServerConnection, error: unknown): AuthError | undefined {\n\tif (!isNeedsAuthError(error)) return undefined;\n\tconst authError = headlessAuthError(connection, error);\n\tconnection.markNeedsAuth(authError);\n\treturn authError;\n}\n\nfunction isRetriableFailedSendError(error: unknown): boolean {\n\treturn isRetriableMcpError(error) && !isMcpSessionExpiredError(error);\n}\n\nfunction failedSendError(connection: ServerConnection, cause: unknown, retriable: boolean): ConnectError {\n\tconst suffix = retriable\n\t\t? \"reconnecting once before retry\"\n\t\t: `post-reconnect retry also failed; run /mcp reconnect ${connection.serverName}`;\n\treturn new ConnectError(`MCP server ${connection.serverName} failed to send tool call; ${suffix}`, {\n\t\tcause,\n\t\tphase: \"call\",\n\t\tretriable,\n\t\tserverName: connection.serverName,\n\t});\n}\n\nfunction sessionExpiredError(connection: ServerConnection, cause: unknown, retriable: boolean): SessionExpiredError {\n\tconst suffix = retriable\n\t\t? \"reinitializing once\"\n\t\t: `reinitialize retry also expired; run /mcp reconnect ${connection.serverName}`;\n\treturn new SessionExpiredError(`MCP server ${connection.serverName} session expired; ${suffix}`, {\n\t\tcause,\n\t\tphase: \"session\",\n\t\tretriable,\n\t\tserverName: connection.serverName,\n\t});\n}\n\nfunction headlessAuthError(connection: ServerConnection, cause?: unknown): AuthError {\n\treturn new AuthError(\n\t\t`MCP server ${connection.serverName} needs OAuth. Run senpi interactive, then /mcp auth-start ${connection.serverName} and /mcp auth-complete ${connection.serverName} <redirect-url>.`,\n\t\t{ cause, phase: \"auth\", serverName: connection.serverName },\n\t);\n}\n\nfunction isNeedsAuthError(error: unknown, depth = 0): boolean {\n\tif (error instanceof UnauthorizedError) return true;\n\tif (error instanceof OAuthFlowError) return error.terminal;\n\tif (depth < 5 && error !== null && typeof error === \"object\" && \"cause\" in error) {\n\t\treturn isNeedsAuthError(error.cause, depth + 1);\n\t}\n\treturn false;\n}\n"]}
|
|
@@ -37,7 +37,7 @@ export declare const GPT56_EXECUTION_RULES: readonly [{
|
|
|
37
37
|
}, {
|
|
38
38
|
readonly id: "test-first";
|
|
39
39
|
readonly concern: "test-first";
|
|
40
|
-
readonly directive: "Work test-first on behavior changes: write the failing test, watch it fail for the right reason, then make the smallest change that turns it green.
|
|
40
|
+
readonly directive: "Work test-first on behavior changes: write the one failing test at the seam the change touches, watch it fail for the right reason, then make the smallest change that turns it green. Prose, doc, and visual-only changes take review plus real-surface QA, not tests. Skip test-first also for formatting, comments, renames, or dependency bumps, and never write a test that cannot fail for the regression it names.";
|
|
41
41
|
}, {
|
|
42
42
|
readonly id: "atomic-commits";
|
|
43
43
|
readonly concern: "commit-discipline";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gpt-5.6.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/prompt-preset/gpt-5.6.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"gpt-5.6.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/prompt-preset/gpt-5.6.ts"],"names":[],"mappings":"AA+CA,OAAO,EAAE,KAAK,+BAA+B,EAA4B,MAAM,kCAAkC,CAAC;AAKlH,MAAM,MAAM,oBAAoB,GAC7B,oBAAoB,GACpB,mBAAmB,GACnB,gBAAgB,GAChB,qBAAqB,GACrB,wBAAwB,GACxB,YAAY,GACZ,kBAAkB,GAClB,YAAY,GACZ,gBAAgB,GAChB,oBAAoB,CAAC;AAExB,MAAM,MAAM,qBAAqB,GAC9B,oBAAoB,GACpB,YAAY,GACZ,iBAAiB,GACjB,YAAY,GACZ,mBAAmB,GACnB,gBAAgB,CAAC;AAEpB,MAAM,WAAW,kBAAkB;IAClC,EAAE,EAAE,oBAAoB,CAAC;IACzB,OAAO,EAAE,qBAAqB,CAAC;IAC/B,SAAS,EAAE,MAAM,CAAC;CAClB;AAgCD,eAAO,MAAM,qBAAqB;iBAC3B,oBAAoB;sBAAW,oBAAoB;;;iBACnD,mBAAmB;sBAAW,oBAAoB;;;iBAClD,gBAAgB;sBAAW,oBAAoB;;;iBAC/C,qBAAqB;sBAAW,oBAAoB;;;iBACpD,wBAAwB;sBAAW,oBAAoB;;;iBACvD,YAAY;sBAAW,YAAY;;;iBACnC,kBAAkB;sBAAW,iBAAiB;;;iBAC9C,YAAY;sBAAW,YAAY;;;iBACnC,gBAAgB;sBAAW,mBAAmB;;;iBAC9C,oBAAoB;sBAAW,gBAAgB;;EACJ,CAAC;AAoGnD,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,+BAA+B,GAAG,MAAM,CAEjF"}
|
|
@@ -36,8 +36,10 @@
|
|
|
36
36
|
// its point of use, replacing the weaker text it supersedes rather than being
|
|
37
37
|
// appended as a trailer: the old "independent calls run in the same message" /
|
|
38
38
|
// "each shell command is its own bash call" pair, the mid-paragraph todo
|
|
39
|
-
// mechanics, and the "default to not adding tests" rule (
|
|
40
|
-
//
|
|
39
|
+
// mechanics, and the "default to not adding tests" rule (re-scoped into
|
|
40
|
+
// test-first itself: tests at the touched seam, prose and visual work via
|
|
41
|
+
// real-surface QA - the blanket version contradicted test-first, the scoped
|
|
42
|
+
// version bounds it). The GPT-5.6 guide's Programmatic-Tool-Calling
|
|
41
43
|
// section drives the shape: a bounded routing contract naming the stage,
|
|
42
44
|
// eligible surface, output, and what stays direct beats generic "use PTC
|
|
43
45
|
// efficiently" wording, which does not route.
|
|
@@ -52,7 +54,7 @@ const IN_KERNEL_REDUCTION = "Write real code around those calls - comprehensions
|
|
|
52
54
|
const STAY_DIRECT_EXCEPTIONS = "Call tools directly instead when one call is enough, the output is already small, each result decides the next call, semantic judgment sits between calls, or the action needs approval - and after two failed cell strategies for the same fact, or an empty or suspiciously narrow result, fall back to direct calls and one or two meaningful alternatives before concluding nothing exists.";
|
|
53
55
|
const DELEGATION = "When subagent or task tools are available, fan sizeable independent tracks out to them in one wave - each brief naming its deliverable, scope, observable stop condition, and the evidence it returns for you to verify - and keep work you can finish in a few calls yourself.";
|
|
54
56
|
const TODO_GRANULARITY = "Split the work to the finest actionable grain - one item per edit plus the check that proves it - and drive every transition the moment it happens: start it, complete it, append newly discovered steps, drop abandoned ones, never batch the updates.";
|
|
55
|
-
const TEST_FIRST = "Work test-first on behavior changes: write the failing test, watch it fail for the right reason, then make the smallest change that turns it green.
|
|
57
|
+
const TEST_FIRST = "Work test-first on behavior changes: write the one failing test at the seam the change touches, watch it fail for the right reason, then make the smallest change that turns it green. Prose, doc, and visual-only changes take review plus real-surface QA, not tests. Skip test-first also for formatting, comments, renames, or dependency bumps, and never write a test that cannot fail for the regression it names.";
|
|
56
58
|
const ATOMIC_COMMITS = "When commits are authorized, commit atomically per verified increment, in the repository's existing message convention, each commit green on its own - never one omnibus commit at the end.";
|
|
57
59
|
const LSP_SYMBOL_ROUTING = "Route symbol work through the language server when LSP tools are available - definitions, references, rename impact, and diagnostics on the files you changed - and keep text search for text, filenames, and history.";
|
|
58
60
|
export const GPT56_EXECUTION_RULES = [
|