apex-code 0.0.1-alpha.1 → 0.0.1-alpha.11
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 +482 -0
- package/README.md +75 -680
- package/dist/cli/args.d.ts +21 -1
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +119 -15
- package/dist/cli/args.js.map +1 -1
- package/dist/cli/auth-command.d.ts.map +1 -1
- package/dist/cli/auth-command.js +3 -3
- package/dist/cli/auth-command.js.map +1 -1
- package/dist/cli/concurrent-session.d.ts +3 -0
- package/dist/cli/concurrent-session.d.ts.map +1 -0
- package/dist/cli/concurrent-session.js +13 -0
- package/dist/cli/concurrent-session.js.map +1 -0
- package/dist/cli/cost-command.d.ts +19 -0
- package/dist/cli/cost-command.d.ts.map +1 -0
- package/dist/cli/cost-command.js +107 -0
- package/dist/cli/cost-command.js.map +1 -0
- package/dist/cli/file-processor.d.ts.map +1 -1
- package/dist/cli/file-processor.js +2 -1
- package/dist/cli/file-processor.js.map +1 -1
- package/dist/cli/startup-ui.d.ts +1 -1
- package/dist/cli/startup-ui.d.ts.map +1 -1
- package/dist/cli/startup-ui.js +1 -2
- package/dist/cli/startup-ui.js.map +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +99 -16
- package/dist/cli.js.map +1 -1
- package/dist/config.d.ts +5 -4
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +58 -24
- package/dist/config.js.map +1 -1
- package/dist/core/agent-session-runtime.d.ts.map +1 -1
- package/dist/core/agent-session-runtime.js +2 -0
- package/dist/core/agent-session-runtime.js.map +1 -1
- package/dist/core/agent-session-services.d.ts +28 -0
- package/dist/core/agent-session-services.d.ts.map +1 -1
- package/dist/core/agent-session-services.js +140 -4
- package/dist/core/agent-session-services.js.map +1 -1
- package/dist/core/agent-session.d.ts +147 -9
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +440 -123
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/auth-storage.d.ts +4 -1
- package/dist/core/auth-storage.d.ts.map +1 -1
- package/dist/core/auth-storage.js +17 -14
- package/dist/core/auth-storage.js.map +1 -1
- package/dist/core/bash-executor.d.ts.map +1 -1
- package/dist/core/bash-executor.js +18 -10
- package/dist/core/bash-executor.js.map +1 -1
- package/dist/core/checkpoints/git-checkpoints.d.ts +33 -0
- package/dist/core/checkpoints/git-checkpoints.d.ts.map +1 -0
- package/dist/core/checkpoints/git-checkpoints.js +230 -0
- package/dist/core/checkpoints/git-checkpoints.js.map +1 -0
- package/dist/core/checkpoints/session-checkpoints.d.ts +23 -0
- package/dist/core/checkpoints/session-checkpoints.d.ts.map +1 -0
- package/dist/core/checkpoints/session-checkpoints.js +29 -0
- package/dist/core/checkpoints/session-checkpoints.js.map +1 -0
- package/dist/core/compaction/branch-summarization.d.ts.map +1 -1
- package/dist/core/compaction/branch-summarization.js +3 -0
- package/dist/core/compaction/branch-summarization.js.map +1 -1
- package/dist/core/compaction/compaction.d.ts +4 -3
- package/dist/core/compaction/compaction.d.ts.map +1 -1
- package/dist/core/compaction/compaction.js +41 -32
- package/dist/core/compaction/compaction.js.map +1 -1
- package/dist/core/context/deferred-schemas.d.ts +92 -0
- package/dist/core/context/deferred-schemas.d.ts.map +1 -0
- package/dist/core/context/deferred-schemas.js +74 -0
- package/dist/core/context/deferred-schemas.js.map +1 -0
- package/dist/core/context/eviction.d.ts +47 -0
- package/dist/core/context/eviction.d.ts.map +1 -0
- package/dist/core/context/eviction.js +83 -0
- package/dist/core/context/eviction.js.map +1 -0
- package/dist/core/context/pipeline.d.ts +90 -0
- package/dist/core/context/pipeline.d.ts.map +1 -0
- package/dist/core/context/pipeline.js +109 -0
- package/dist/core/context/pipeline.js.map +1 -0
- package/dist/core/credential-failover.d.ts +30 -0
- package/dist/core/credential-failover.d.ts.map +1 -0
- package/dist/core/credential-failover.js +46 -0
- package/dist/core/credential-failover.js.map +1 -0
- package/dist/core/credential-pool.d.ts +60 -0
- package/dist/core/credential-pool.d.ts.map +1 -0
- package/dist/core/credential-pool.js +84 -0
- package/dist/core/credential-pool.js.map +1 -0
- package/dist/core/defaults.d.ts +1 -0
- package/dist/core/defaults.d.ts.map +1 -1
- package/dist/core/defaults.js +9 -0
- package/dist/core/defaults.js.map +1 -1
- package/dist/core/delegation/agents.d.ts +15 -0
- package/dist/core/delegation/agents.d.ts.map +1 -0
- package/dist/core/delegation/agents.js +55 -0
- package/dist/core/delegation/agents.js.map +1 -0
- package/dist/core/delegation/ceiling.d.ts +29 -0
- package/dist/core/delegation/ceiling.d.ts.map +1 -0
- package/dist/core/delegation/ceiling.js +34 -0
- package/dist/core/delegation/ceiling.js.map +1 -0
- package/dist/core/delegation/runtime.d.ts +94 -0
- package/dist/core/delegation/runtime.d.ts.map +1 -0
- package/dist/core/delegation/runtime.js +117 -0
- package/dist/core/delegation/runtime.js.map +1 -0
- package/dist/core/durable-state/daemon.d.ts +37 -0
- package/dist/core/durable-state/daemon.d.ts.map +1 -0
- package/dist/core/durable-state/daemon.js +62 -0
- package/dist/core/durable-state/daemon.js.map +1 -0
- package/dist/core/durable-state/provenance.d.ts +7 -0
- package/dist/core/durable-state/provenance.d.ts.map +1 -0
- package/dist/core/durable-state/provenance.js +24 -0
- package/dist/core/durable-state/provenance.js.map +1 -0
- package/dist/core/durable-state/sqlite.d.ts +84 -0
- package/dist/core/durable-state/sqlite.d.ts.map +1 -0
- package/dist/core/durable-state/sqlite.js +355 -0
- package/dist/core/durable-state/sqlite.js.map +1 -0
- package/dist/core/environment.d.ts +12 -0
- package/dist/core/environment.d.ts.map +1 -0
- package/dist/core/environment.js +69 -0
- package/dist/core/environment.js.map +1 -0
- package/dist/core/evidence-policy.d.ts +17 -0
- package/dist/core/evidence-policy.d.ts.map +1 -0
- package/dist/core/evidence-policy.js +25 -0
- package/dist/core/evidence-policy.js.map +1 -0
- package/dist/core/evidence.d.ts +16 -0
- package/dist/core/evidence.d.ts.map +1 -0
- package/dist/core/evidence.js +51 -0
- package/dist/core/evidence.js.map +1 -0
- package/dist/core/exec.d.ts.map +1 -1
- package/dist/core/exec.js +5 -2
- package/dist/core/exec.js.map +1 -1
- package/dist/core/experimental.d.ts +4 -0
- package/dist/core/experimental.d.ts.map +1 -1
- package/dist/core/experimental.js +6 -1
- package/dist/core/experimental.js.map +1 -1
- package/dist/core/extensions/index.d.ts +2 -2
- package/dist/core/extensions/index.d.ts.map +1 -1
- package/dist/core/extensions/index.js +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 +122 -49
- package/dist/core/extensions/loader.js.map +1 -1
- package/dist/core/extensions/types.d.ts +44 -9
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js +3 -0
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/footer-data-provider.d.ts +1 -1
- 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/http-dispatcher.d.ts +1 -2
- package/dist/core/http-dispatcher.d.ts.map +1 -1
- package/dist/core/http-dispatcher.js +2 -17
- package/dist/core/http-dispatcher.js.map +1 -1
- package/dist/core/http-idle-timeout.d.ts +12 -0
- package/dist/core/http-idle-timeout.d.ts.map +1 -0
- package/dist/core/http-idle-timeout.js +27 -0
- package/dist/core/http-idle-timeout.js.map +1 -0
- package/dist/core/index.d.ts +1 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +1 -0
- package/dist/core/index.js.map +1 -1
- package/dist/core/keybindings.d.ts +38 -13
- package/dist/core/keybindings.d.ts.map +1 -1
- package/dist/core/keybindings.js +26 -5
- package/dist/core/keybindings.js.map +1 -1
- package/dist/core/lsp/client.d.ts +78 -0
- package/dist/core/lsp/client.d.ts.map +1 -0
- package/dist/core/lsp/client.js +494 -0
- package/dist/core/lsp/client.js.map +1 -0
- package/dist/core/lsp/diagnostics.d.ts +47 -0
- package/dist/core/lsp/diagnostics.d.ts.map +1 -0
- package/dist/core/lsp/diagnostics.js +224 -0
- package/dist/core/lsp/diagnostics.js.map +1 -0
- package/dist/core/lsp/pool.d.ts +48 -0
- package/dist/core/lsp/pool.d.ts.map +1 -0
- package/dist/core/lsp/pool.js +150 -0
- package/dist/core/lsp/pool.js.map +1 -0
- package/dist/core/lsp/registry.d.ts +49 -0
- package/dist/core/lsp/registry.d.ts.map +1 -0
- package/dist/core/lsp/registry.js +215 -0
- package/dist/core/lsp/registry.js.map +1 -0
- package/dist/core/lsp/status.d.ts +23 -0
- package/dist/core/lsp/status.d.ts.map +1 -0
- package/dist/core/lsp/status.js +35 -0
- package/dist/core/lsp/status.js.map +1 -0
- package/dist/core/lsp/sync.d.ts +13 -0
- package/dist/core/lsp/sync.d.ts.map +1 -0
- package/dist/core/lsp/sync.js +71 -0
- package/dist/core/lsp/sync.js.map +1 -0
- package/dist/core/mcp/config.d.ts +16 -0
- package/dist/core/mcp/config.d.ts.map +1 -0
- package/dist/core/mcp/config.js +152 -0
- package/dist/core/mcp/config.js.map +1 -0
- package/dist/core/mcp/connector.d.ts +10 -0
- package/dist/core/mcp/connector.d.ts.map +1 -0
- package/dist/core/mcp/connector.js +70 -0
- package/dist/core/mcp/connector.js.map +1 -0
- package/dist/core/mcp/contract.d.ts +19 -0
- package/dist/core/mcp/contract.d.ts.map +1 -0
- package/dist/core/mcp/contract.js +89 -0
- package/dist/core/mcp/contract.js.map +1 -0
- package/dist/core/mcp/mcp-tool.d.ts +32 -0
- package/dist/core/mcp/mcp-tool.d.ts.map +1 -0
- package/dist/core/mcp/mcp-tool.js +165 -0
- package/dist/core/mcp/mcp-tool.js.map +1 -0
- package/dist/core/mcp/metadata-cache.d.ts +29 -0
- package/dist/core/mcp/metadata-cache.d.ts.map +1 -0
- package/dist/core/mcp/metadata-cache.js +99 -0
- package/dist/core/mcp/metadata-cache.js.map +1 -0
- package/dist/core/mcp/runtime.d.ts +18 -0
- package/dist/core/mcp/runtime.d.ts.map +1 -0
- package/dist/core/mcp/runtime.js +35 -0
- package/dist/core/mcp/runtime.js.map +1 -0
- package/dist/core/mcp/schema.d.ts +22 -0
- package/dist/core/mcp/schema.d.ts.map +1 -0
- package/dist/core/mcp/schema.js +20 -0
- package/dist/core/mcp/schema.js.map +1 -0
- package/dist/core/mcp/server-manager.d.ts +43 -0
- package/dist/core/mcp/server-manager.d.ts.map +1 -0
- package/dist/core/mcp/server-manager.js +142 -0
- package/dist/core/mcp/server-manager.js.map +1 -0
- package/dist/core/mcp/types.d.ts +98 -0
- package/dist/core/mcp/types.d.ts.map +1 -0
- package/dist/core/mcp/types.js +8 -0
- package/dist/core/mcp/types.js.map +1 -0
- package/dist/core/model-config.d.ts +18 -0
- package/dist/core/model-config.d.ts.map +1 -1
- package/dist/core/model-config.js +25 -6
- package/dist/core/model-config.js.map +1 -1
- package/dist/core/model-resolver.d.ts +21 -0
- package/dist/core/model-resolver.d.ts.map +1 -1
- package/dist/core/model-resolver.js +73 -8
- package/dist/core/model-resolver.js.map +1 -1
- package/dist/core/model-runtime.d.ts +73 -0
- package/dist/core/model-runtime.d.ts.map +1 -1
- package/dist/core/model-runtime.js +225 -8
- package/dist/core/model-runtime.js.map +1 -1
- package/dist/core/models-store.d.ts.map +1 -1
- package/dist/core/models-store.js +2 -1
- package/dist/core/models-store.js.map +1 -1
- package/dist/core/observability/aggregate.d.ts +21 -0
- package/dist/core/observability/aggregate.d.ts.map +1 -0
- package/dist/core/observability/aggregate.js +36 -0
- package/dist/core/observability/aggregate.js.map +1 -0
- package/dist/core/observability/otlp.d.ts +66 -0
- package/dist/core/observability/otlp.d.ts.map +1 -0
- package/dist/core/observability/otlp.js +95 -0
- package/dist/core/observability/otlp.js.map +1 -0
- package/dist/core/package-manager.d.ts.map +1 -1
- package/dist/core/package-manager.js +40 -16
- package/dist/core/package-manager.js.map +1 -1
- package/dist/core/permissions/gate.d.ts +42 -0
- package/dist/core/permissions/gate.d.ts.map +1 -0
- package/dist/core/permissions/gate.js +72 -0
- package/dist/core/permissions/gate.js.map +1 -0
- package/dist/core/permissions/modes.d.ts +18 -0
- package/dist/core/permissions/modes.d.ts.map +1 -0
- package/dist/core/permissions/modes.js +57 -0
- package/dist/core/permissions/modes.js.map +1 -0
- package/dist/core/permissions/responder.d.ts +30 -0
- package/dist/core/permissions/responder.d.ts.map +1 -0
- package/dist/core/permissions/responder.js +32 -0
- package/dist/core/permissions/responder.js.map +1 -0
- package/dist/core/permissions/rules.d.ts +34 -0
- package/dist/core/permissions/rules.d.ts.map +1 -0
- package/dist/core/permissions/rules.js +74 -0
- package/dist/core/permissions/rules.js.map +1 -0
- package/dist/core/permissions/startup.d.ts +45 -0
- package/dist/core/permissions/startup.d.ts.map +1 -0
- package/dist/core/permissions/startup.js +63 -0
- package/dist/core/permissions/startup.js.map +1 -0
- package/dist/core/permissions/store.d.ts +114 -0
- package/dist/core/permissions/store.d.ts.map +1 -0
- package/dist/core/permissions/store.js +229 -0
- package/dist/core/permissions/store.js.map +1 -0
- package/dist/core/pi-manifest.d.ts.map +1 -1
- package/dist/core/pi-manifest.js +2 -1
- package/dist/core/pi-manifest.js.map +1 -1
- package/dist/core/project-trust.d.ts.map +1 -1
- package/dist/core/project-trust.js +1 -1
- package/dist/core/project-trust.js.map +1 -1
- package/dist/core/provider-attribution.d.ts.map +1 -1
- package/dist/core/provider-attribution.js +6 -7
- package/dist/core/provider-attribution.js.map +1 -1
- package/dist/core/remote-catalog-provider.d.ts +2 -2
- package/dist/core/remote-catalog-provider.d.ts.map +1 -1
- package/dist/core/remote-catalog-provider.js +22 -17
- package/dist/core/remote-catalog-provider.js.map +1 -1
- package/dist/core/resource-loader.d.ts.map +1 -1
- package/dist/core/resource-loader.js +3 -2
- package/dist/core/resource-loader.js.map +1 -1
- package/dist/core/sandbox/bwrap-arguments.d.ts +52 -0
- package/dist/core/sandbox/bwrap-arguments.d.ts.map +1 -0
- package/dist/core/sandbox/bwrap-arguments.js +86 -0
- package/dist/core/sandbox/bwrap-arguments.js.map +1 -0
- package/dist/core/sandbox/child-entry.d.ts +2 -0
- package/dist/core/sandbox/child-entry.d.ts.map +1 -0
- package/dist/core/sandbox/child-entry.js +22 -0
- package/dist/core/sandbox/child-entry.js.map +1 -0
- package/dist/core/sandbox/cli-launch.d.ts +88 -0
- package/dist/core/sandbox/cli-launch.d.ts.map +1 -0
- package/dist/core/sandbox/cli-launch.js +272 -0
- package/dist/core/sandbox/cli-launch.js.map +1 -0
- package/dist/core/sandbox/cli-supervisor.d.ts +30 -0
- package/dist/core/sandbox/cli-supervisor.d.ts.map +1 -0
- package/dist/core/sandbox/cli-supervisor.js +123 -0
- package/dist/core/sandbox/cli-supervisor.js.map +1 -0
- package/dist/core/sandbox/default-hosts.d.ts +28 -0
- package/dist/core/sandbox/default-hosts.d.ts.map +1 -0
- package/dist/core/sandbox/default-hosts.js +69 -0
- package/dist/core/sandbox/default-hosts.js.map +1 -0
- package/dist/core/sandbox/full-access.d.ts +28 -0
- package/dist/core/sandbox/full-access.d.ts.map +1 -0
- package/dist/core/sandbox/full-access.js +63 -0
- package/dist/core/sandbox/full-access.js.map +1 -0
- package/dist/core/sandbox/git-identity.d.ts +57 -0
- package/dist/core/sandbox/git-identity.d.ts.map +1 -0
- package/dist/core/sandbox/git-identity.js +78 -0
- package/dist/core/sandbox/git-identity.js.map +1 -0
- package/dist/core/sandbox/host-approval.d.ts +42 -0
- package/dist/core/sandbox/host-approval.d.ts.map +1 -0
- package/dist/core/sandbox/host-approval.js +99 -0
- package/dist/core/sandbox/host-approval.js.map +1 -0
- package/dist/core/sandbox/linux-backend.d.ts +46 -0
- package/dist/core/sandbox/linux-backend.d.ts.map +1 -0
- package/dist/core/sandbox/linux-backend.js +304 -0
- package/dist/core/sandbox/linux-backend.js.map +1 -0
- package/dist/core/sandbox/macos-backend.d.ts +28 -0
- package/dist/core/sandbox/macos-backend.d.ts.map +1 -0
- package/dist/core/sandbox/macos-backend.js +313 -0
- package/dist/core/sandbox/macos-backend.js.map +1 -0
- package/dist/core/sandbox/network-proxy.d.ts +38 -0
- package/dist/core/sandbox/network-proxy.d.ts.map +1 -0
- package/dist/core/sandbox/network-proxy.js +153 -0
- package/dist/core/sandbox/network-proxy.js.map +1 -0
- package/dist/core/sandbox/network-refusal.d.ts +24 -0
- package/dist/core/sandbox/network-refusal.d.ts.map +1 -0
- package/dist/core/sandbox/network-refusal.js +72 -0
- package/dist/core/sandbox/network-refusal.js.map +1 -0
- package/dist/core/sandbox/policy.d.ts +40 -0
- package/dist/core/sandbox/policy.d.ts.map +1 -0
- package/dist/core/sandbox/policy.js +55 -0
- package/dist/core/sandbox/policy.js.map +1 -0
- package/dist/core/sandbox/profiles.d.ts +25 -0
- package/dist/core/sandbox/profiles.d.ts.map +1 -0
- package/dist/core/sandbox/profiles.js +23 -0
- package/dist/core/sandbox/profiles.js.map +1 -0
- package/dist/core/sandbox/rpc/command-client.d.ts +28 -0
- package/dist/core/sandbox/rpc/command-client.d.ts.map +1 -0
- package/dist/core/sandbox/rpc/command-client.js +86 -0
- package/dist/core/sandbox/rpc/command-client.js.map +1 -0
- package/dist/core/sandbox/rpc/command-proxy.d.ts +48 -0
- package/dist/core/sandbox/rpc/command-proxy.d.ts.map +1 -0
- package/dist/core/sandbox/rpc/command-proxy.js +120 -0
- package/dist/core/sandbox/rpc/command-proxy.js.map +1 -0
- package/dist/core/sandbox/rpc/credential-client.d.ts +20 -0
- package/dist/core/sandbox/rpc/credential-client.d.ts.map +1 -0
- package/dist/core/sandbox/rpc/credential-client.js +170 -0
- package/dist/core/sandbox/rpc/credential-client.js.map +1 -0
- package/dist/core/sandbox/rpc/credential-proxy.d.ts +44 -0
- package/dist/core/sandbox/rpc/credential-proxy.d.ts.map +1 -0
- package/dist/core/sandbox/rpc/credential-proxy.js +287 -0
- package/dist/core/sandbox/rpc/credential-proxy.js.map +1 -0
- package/dist/core/sandbox/rpc/framing.d.ts +35 -0
- package/dist/core/sandbox/rpc/framing.d.ts.map +1 -0
- package/dist/core/sandbox/rpc/framing.js +114 -0
- package/dist/core/sandbox/rpc/framing.js.map +1 -0
- package/dist/core/sandbox/rpc/git-credential-helper.d.ts +40 -0
- package/dist/core/sandbox/rpc/git-credential-helper.d.ts.map +1 -0
- package/dist/core/sandbox/rpc/git-credential-helper.js +152 -0
- package/dist/core/sandbox/rpc/git-credential-helper.js.map +1 -0
- package/dist/core/sandbox/rpc/git-credential-proxy.d.ts +48 -0
- package/dist/core/sandbox/rpc/git-credential-proxy.d.ts.map +1 -0
- package/dist/core/sandbox/rpc/git-credential-proxy.js +142 -0
- package/dist/core/sandbox/rpc/git-credential-proxy.js.map +1 -0
- package/dist/core/sandbox/supervisor-temp.d.ts +18 -0
- package/dist/core/sandbox/supervisor-temp.d.ts.map +1 -0
- package/dist/core/sandbox/supervisor-temp.js +21 -0
- package/dist/core/sandbox/supervisor-temp.js.map +1 -0
- package/dist/core/sandbox/supervisor.d.ts +51 -0
- package/dist/core/sandbox/supervisor.d.ts.map +1 -0
- package/dist/core/sandbox/supervisor.js +18 -0
- package/dist/core/sandbox/supervisor.js.map +1 -0
- package/dist/core/sandbox/terminal-handoff.d.ts +45 -0
- package/dist/core/sandbox/terminal-handoff.d.ts.map +1 -0
- package/dist/core/sandbox/terminal-handoff.js +176 -0
- package/dist/core/sandbox/terminal-handoff.js.map +1 -0
- package/dist/core/sandbox/terminal-size.d.ts +40 -0
- package/dist/core/sandbox/terminal-size.d.ts.map +1 -0
- package/dist/core/sandbox/terminal-size.js +105 -0
- package/dist/core/sandbox/terminal-size.js.map +1 -0
- package/dist/core/sandbox/violations.d.ts +23 -0
- package/dist/core/sandbox/violations.d.ts.map +1 -0
- package/dist/core/sandbox/violations.js +30 -0
- package/dist/core/sandbox/violations.js.map +1 -0
- package/dist/core/sdk.d.ts +32 -41
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +174 -6
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/session-export.d.ts +4 -0
- package/dist/core/session-export.d.ts.map +1 -0
- package/dist/core/session-export.js +32 -0
- package/dist/core/session-export.js.map +1 -0
- package/dist/core/session-lease.d.ts +31 -0
- package/dist/core/session-lease.d.ts.map +1 -0
- package/dist/core/session-lease.js +138 -0
- package/dist/core/session-lease.js.map +1 -0
- package/dist/core/session-manager.d.ts +58 -2
- package/dist/core/session-manager.d.ts.map +1 -1
- package/dist/core/session-manager.js +92 -7
- package/dist/core/session-manager.js.map +1 -1
- package/dist/core/session-share.d.ts +31 -0
- package/dist/core/session-share.d.ts.map +1 -0
- package/dist/core/session-share.js +45 -0
- package/dist/core/session-share.js.map +1 -0
- package/dist/core/settings-diagnostics.d.ts +9 -0
- package/dist/core/settings-diagnostics.d.ts.map +1 -0
- package/dist/core/settings-diagnostics.js +21 -0
- package/dist/core/settings-diagnostics.js.map +1 -0
- package/dist/core/settings-manager.d.ts +99 -9
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +141 -36
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/skills.d.ts +19 -7
- package/dist/core/skills.d.ts.map +1 -1
- package/dist/core/skills.js +128 -52
- package/dist/core/skills.js.map +1 -1
- package/dist/core/slash-commands.d.ts.map +1 -1
- package/dist/core/slash-commands.js +6 -2
- package/dist/core/slash-commands.js.map +1 -1
- package/dist/core/system-prompt.d.ts +2 -2
- package/dist/core/system-prompt.d.ts.map +1 -1
- package/dist/core/system-prompt.js +59 -68
- package/dist/core/system-prompt.js.map +1 -1
- package/dist/core/timings.d.ts +1 -1
- package/dist/core/timings.d.ts.map +1 -1
- package/dist/core/timings.js +3 -2
- package/dist/core/timings.js.map +1 -1
- package/dist/core/tools/ask-user.d.ts +25 -0
- package/dist/core/tools/ask-user.d.ts.map +1 -0
- package/dist/core/tools/ask-user.js +49 -0
- package/dist/core/tools/ask-user.js.map +1 -0
- package/dist/core/tools/bash-command-segments.d.ts +22 -0
- package/dist/core/tools/bash-command-segments.d.ts.map +1 -0
- package/dist/core/tools/bash-command-segments.js +128 -0
- package/dist/core/tools/bash-command-segments.js.map +1 -0
- package/dist/core/tools/bash.d.ts +40 -4
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +183 -32
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/contract-snapshot.d.ts +58 -0
- package/dist/core/tools/contract-snapshot.d.ts.map +1 -0
- package/dist/core/tools/contract-snapshot.js +51 -0
- package/dist/core/tools/contract-snapshot.js.map +1 -0
- package/dist/core/tools/contract.d.ts +185 -0
- package/dist/core/tools/contract.d.ts.map +1 -0
- package/dist/core/tools/contract.js +50 -0
- package/dist/core/tools/contract.js.map +1 -0
- package/dist/core/tools/delegate.d.ts +38 -0
- package/dist/core/tools/delegate.d.ts.map +1 -0
- package/dist/core/tools/delegate.js +90 -0
- package/dist/core/tools/delegate.js.map +1 -0
- package/dist/core/tools/diagnostics.d.ts +39 -0
- package/dist/core/tools/diagnostics.d.ts.map +1 -0
- package/dist/core/tools/diagnostics.js +62 -0
- package/dist/core/tools/diagnostics.js.map +1 -0
- package/dist/core/tools/edit-diff.d.ts +0 -5
- package/dist/core/tools/edit-diff.d.ts.map +1 -1
- package/dist/core/tools/edit-diff.js +2 -5
- package/dist/core/tools/edit-diff.js.map +1 -1
- package/dist/core/tools/edit.d.ts +12 -2
- package/dist/core/tools/edit.d.ts.map +1 -1
- package/dist/core/tools/edit.js +61 -10
- package/dist/core/tools/edit.js.map +1 -1
- package/dist/core/tools/find.d.ts +2 -2
- package/dist/core/tools/find.d.ts.map +1 -1
- package/dist/core/tools/find.js +13 -1
- package/dist/core/tools/find.js.map +1 -1
- package/dist/core/tools/grep.d.ts +4 -2
- package/dist/core/tools/grep.d.ts.map +1 -1
- package/dist/core/tools/grep.js +47 -10
- package/dist/core/tools/grep.js.map +1 -1
- package/dist/core/tools/index.d.ts +60 -6
- package/dist/core/tools/index.d.ts.map +1 -1
- package/dist/core/tools/index.js +148 -2
- package/dist/core/tools/index.js.map +1 -1
- package/dist/core/tools/ls.d.ts +4 -2
- package/dist/core/tools/ls.d.ts.map +1 -1
- package/dist/core/tools/ls.js +17 -1
- package/dist/core/tools/ls.js.map +1 -1
- package/dist/core/tools/lsp.d.ts +62 -0
- package/dist/core/tools/lsp.d.ts.map +1 -0
- package/dist/core/tools/lsp.js +216 -0
- package/dist/core/tools/lsp.js.map +1 -0
- package/dist/core/tools/output-accumulator.d.ts.map +1 -1
- package/dist/core/tools/output-accumulator.js +1 -1
- package/dist/core/tools/output-accumulator.js.map +1 -1
- package/dist/core/tools/path-permission.d.ts +18 -0
- package/dist/core/tools/path-permission.d.ts.map +1 -0
- package/dist/core/tools/path-permission.js +28 -0
- package/dist/core/tools/path-permission.js.map +1 -0
- package/dist/core/tools/plan-present.d.ts +27 -0
- package/dist/core/tools/plan-present.d.ts.map +1 -0
- package/dist/core/tools/plan-present.js +55 -0
- package/dist/core/tools/plan-present.js.map +1 -0
- package/dist/core/tools/powershell.d.ts +16 -0
- package/dist/core/tools/powershell.d.ts.map +1 -0
- package/dist/core/tools/powershell.js +39 -0
- package/dist/core/tools/powershell.js.map +1 -0
- package/dist/core/tools/read.d.ts +2 -2
- package/dist/core/tools/read.d.ts.map +1 -1
- package/dist/core/tools/read.js +14 -0
- package/dist/core/tools/read.js.map +1 -1
- package/dist/core/tools/skill-search.d.ts +32 -0
- package/dist/core/tools/skill-search.d.ts.map +1 -0
- package/dist/core/tools/skill-search.js +56 -0
- package/dist/core/tools/skill-search.js.map +1 -0
- package/dist/core/tools/test.d.ts +34 -0
- package/dist/core/tools/test.d.ts.map +1 -0
- package/dist/core/tools/test.js +75 -0
- package/dist/core/tools/test.js.map +1 -0
- package/dist/core/tools/todo-write.d.ts +31 -0
- package/dist/core/tools/todo-write.d.ts.map +1 -0
- package/dist/core/tools/todo-write.js +51 -0
- package/dist/core/tools/todo-write.js.map +1 -0
- package/dist/core/tools/tool-definition-wrapper.d.ts +13 -2
- package/dist/core/tools/tool-definition-wrapper.d.ts.map +1 -1
- package/dist/core/tools/tool-definition-wrapper.js +11 -1
- package/dist/core/tools/tool-definition-wrapper.js.map +1 -1
- package/dist/core/tools/tool-schema.d.ts +22 -0
- package/dist/core/tools/tool-schema.d.ts.map +1 -0
- package/dist/core/tools/tool-schema.js +45 -0
- package/dist/core/tools/tool-schema.js.map +1 -0
- package/dist/core/tools/web-fetch.d.ts +26 -0
- package/dist/core/tools/web-fetch.d.ts.map +1 -0
- package/dist/core/tools/web-fetch.js +62 -0
- package/dist/core/tools/web-fetch.js.map +1 -0
- package/dist/core/tools/web-search-exa.d.ts +33 -0
- package/dist/core/tools/web-search-exa.d.ts.map +1 -0
- package/dist/core/tools/web-search-exa.js +128 -0
- package/dist/core/tools/web-search-exa.js.map +1 -0
- package/dist/core/tools/web-search.d.ts +26 -0
- package/dist/core/tools/web-search.d.ts.map +1 -0
- package/dist/core/tools/web-search.js +53 -0
- package/dist/core/tools/web-search.js.map +1 -0
- package/dist/core/tools/write.d.ts +16 -2
- package/dist/core/tools/write.d.ts.map +1 -1
- package/dist/core/tools/write.js +48 -2
- package/dist/core/tools/write.js.map +1 -1
- package/dist/core/trust-manager.d.ts.map +1 -1
- package/dist/core/trust-manager.js +2 -1
- package/dist/core/trust-manager.js.map +1 -1
- package/dist/core/usage-performance-store.d.ts +56 -0
- package/dist/core/usage-performance-store.d.ts.map +1 -0
- package/dist/core/usage-performance-store.js +85 -0
- package/dist/core/usage-performance-store.js.map +1 -0
- package/dist/core/web-search-provider.d.ts +64 -0
- package/dist/core/web-search-provider.d.ts.map +1 -0
- package/dist/core/web-search-provider.js +149 -0
- package/dist/core/web-search-provider.js.map +1 -0
- package/dist/extensions/llama/index.d.ts.map +1 -1
- package/dist/extensions/llama/index.js +2 -0
- package/dist/extensions/llama/index.js.map +1 -1
- package/dist/extensions/llama/provider.d.ts.map +1 -1
- package/dist/extensions/llama/provider.js +6 -2
- package/dist/extensions/llama/provider.js.map +1 -1
- package/dist/index.d.ts +9 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -4
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts +5 -0
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +87 -22
- package/dist/main.js.map +1 -1
- package/dist/migrations.d.ts.map +1 -1
- package/dist/migrations.js +6 -5
- package/dist/migrations.js.map +1 -1
- package/dist/modes/interactive/components/assistant-message.d.ts +29 -0
- package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/assistant-message.js +182 -23
- package/dist/modes/interactive/components/assistant-message.js.map +1 -1
- package/dist/modes/interactive/components/bash-execution.d.ts +7 -0
- package/dist/modes/interactive/components/bash-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/bash-execution.js +20 -0
- package/dist/modes/interactive/components/bash-execution.js.map +1 -1
- package/dist/modes/interactive/components/config-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/config-selector.js +9 -6
- package/dist/modes/interactive/components/config-selector.js.map +1 -1
- package/dist/modes/interactive/components/custom-editor.d.ts +72 -1
- package/dist/modes/interactive/components/custom-editor.d.ts.map +1 -1
- package/dist/modes/interactive/components/custom-editor.js +338 -1
- package/dist/modes/interactive/components/custom-editor.js.map +1 -1
- package/dist/modes/interactive/components/dynamic-border.d.ts +7 -1
- package/dist/modes/interactive/components/dynamic-border.d.ts.map +1 -1
- package/dist/modes/interactive/components/dynamic-border.js +11 -2
- package/dist/modes/interactive/components/dynamic-border.js.map +1 -1
- package/dist/modes/interactive/components/extension-selector.d.ts +4 -0
- package/dist/modes/interactive/components/extension-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/extension-selector.js +24 -6
- package/dist/modes/interactive/components/extension-selector.js.map +1 -1
- package/dist/modes/interactive/components/first-time-setup.d.ts +1 -4
- package/dist/modes/interactive/components/first-time-setup.d.ts.map +1 -1
- package/dist/modes/interactive/components/first-time-setup.js +17 -41
- package/dist/modes/interactive/components/first-time-setup.js.map +1 -1
- package/dist/modes/interactive/components/first-use-hints.d.ts +8 -0
- package/dist/modes/interactive/components/first-use-hints.d.ts.map +1 -0
- package/dist/modes/interactive/components/first-use-hints.js +22 -0
- package/dist/modes/interactive/components/first-use-hints.js.map +1 -0
- package/dist/modes/interactive/components/footer.d.ts +31 -1
- package/dist/modes/interactive/components/footer.d.ts.map +1 -1
- package/dist/modes/interactive/components/footer.js +205 -24
- package/dist/modes/interactive/components/footer.js.map +1 -1
- package/dist/modes/interactive/components/index.d.ts +2 -0
- package/dist/modes/interactive/components/index.d.ts.map +1 -1
- package/dist/modes/interactive/components/index.js +2 -0
- package/dist/modes/interactive/components/index.js.map +1 -1
- package/dist/modes/interactive/components/model-selector.d.ts +31 -9
- package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/model-selector.js +236 -96
- package/dist/modes/interactive/components/model-selector.js.map +1 -1
- package/dist/modes/interactive/components/settings-selector.d.ts +25 -5
- package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-selector.js +226 -58
- package/dist/modes/interactive/components/settings-selector.js.map +1 -1
- package/dist/modes/interactive/components/settings-submenu.d.ts +72 -0
- package/dist/modes/interactive/components/settings-submenu.d.ts.map +1 -0
- package/dist/modes/interactive/components/settings-submenu.js +165 -0
- package/dist/modes/interactive/components/settings-submenu.js.map +1 -0
- package/dist/modes/interactive/components/splash-header.d.ts +66 -0
- package/dist/modes/interactive/components/splash-header.d.ts.map +1 -0
- package/dist/modes/interactive/components/splash-header.js +180 -0
- package/dist/modes/interactive/components/splash-header.js.map +1 -0
- package/dist/modes/interactive/components/thinking-selector.d.ts +15 -3
- package/dist/modes/interactive/components/thinking-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/thinking-selector.js +74 -17
- package/dist/modes/interactive/components/thinking-selector.js.map +1 -1
- package/dist/modes/interactive/components/tool-execution.d.ts +28 -1
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-execution.js +144 -35
- package/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/dist/modes/interactive/components/tool-panel.d.ts +30 -0
- package/dist/modes/interactive/components/tool-panel.d.ts.map +1 -0
- package/dist/modes/interactive/components/tool-panel.js +130 -0
- package/dist/modes/interactive/components/tool-panel.js.map +1 -0
- package/dist/modes/interactive/external-editor.d.ts.map +1 -1
- package/dist/modes/interactive/external-editor.js +60 -10
- package/dist/modes/interactive/external-editor.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +90 -5
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +729 -206
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/model-catalog-refresh.d.ts +7 -0
- package/dist/modes/interactive/model-catalog-refresh.d.ts.map +1 -0
- package/dist/modes/interactive/model-catalog-refresh.js +34 -0
- package/dist/modes/interactive/model-catalog-refresh.js.map +1 -0
- package/dist/modes/interactive/theme/apex.json +93 -0
- package/dist/modes/interactive/theme/dark.json +2 -0
- package/dist/modes/interactive/theme/light.json +3 -1
- package/dist/modes/interactive/theme/theme-controller.d.ts +10 -2
- package/dist/modes/interactive/theme/theme-controller.d.ts.map +1 -1
- package/dist/modes/interactive/theme/theme-controller.js +25 -11
- package/dist/modes/interactive/theme/theme-controller.js.map +1 -1
- package/dist/modes/interactive/theme/theme-schema.json +11 -3
- package/dist/modes/interactive/theme/theme.d.ts +14 -3
- package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
- package/dist/modes/interactive/theme/theme.js +65 -10
- package/dist/modes/interactive/theme/theme.js.map +1 -1
- package/dist/modes/json-event.d.ts +18 -12
- package/dist/modes/json-event.d.ts.map +1 -1
- package/dist/modes/json-event.js +22 -5
- package/dist/modes/json-event.js.map +1 -1
- package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-mode.js +2 -1
- package/dist/modes/rpc/rpc-mode.js.map +1 -1
- package/dist/package-manager-cli.d.ts +1 -0
- package/dist/package-manager-cli.d.ts.map +1 -1
- package/dist/package-manager-cli.js +210 -19
- package/dist/package-manager-cli.js.map +1 -1
- package/dist/rpc-entry.d.ts.map +1 -1
- package/dist/rpc-entry.js +2 -1
- package/dist/rpc-entry.js.map +1 -1
- package/dist/testing/replay/metrics.d.ts +24 -0
- package/dist/testing/replay/metrics.d.ts.map +1 -0
- package/dist/testing/replay/metrics.js +35 -0
- package/dist/testing/replay/metrics.js.map +1 -0
- package/dist/testing/replay/recorded-provider.d.ts +10 -0
- package/dist/testing/replay/recorded-provider.d.ts.map +1 -0
- package/dist/testing/replay/recorded-provider.js +108 -0
- package/dist/testing/replay/recorded-provider.js.map +1 -0
- package/dist/testing/replay/runner.d.ts +56 -0
- package/dist/testing/replay/runner.d.ts.map +1 -0
- package/dist/testing/replay/runner.js +406 -0
- package/dist/testing/replay/runner.js.map +1 -0
- package/dist/themes/apex-logo.d.ts +41 -0
- package/dist/themes/apex-logo.d.ts.map +1 -0
- package/dist/themes/apex-logo.js +35 -0
- package/dist/themes/apex-logo.js.map +1 -0
- package/dist/utils/apex-code-user-agent.d.ts +2 -0
- package/dist/utils/apex-code-user-agent.d.ts.map +1 -0
- package/dist/utils/apex-code-user-agent.js +5 -0
- package/dist/utils/apex-code-user-agent.js.map +1 -0
- package/dist/utils/changelog.d.ts +7 -2
- package/dist/utils/changelog.d.ts.map +1 -1
- package/dist/utils/changelog.js +82 -13
- package/dist/utils/changelog.js.map +1 -1
- package/dist/utils/clipboard-image.d.ts.map +1 -1
- package/dist/utils/clipboard-image.js +1 -1
- package/dist/utils/clipboard-image.js.map +1 -1
- package/dist/utils/frontmatter.d.ts.map +1 -1
- package/dist/utils/frontmatter.js +2 -1
- package/dist/utils/frontmatter.js.map +1 -1
- package/dist/utils/management-http.d.ts +5 -3
- package/dist/utils/management-http.d.ts.map +1 -1
- package/dist/utils/management-http.js +14 -10
- package/dist/utils/management-http.js.map +1 -1
- package/dist/utils/shell.d.ts +3 -0
- package/dist/utils/shell.d.ts.map +1 -1
- package/dist/utils/shell.js +17 -5
- package/dist/utils/shell.js.map +1 -1
- package/dist/utils/syntax-highlight.d.ts +1 -0
- package/dist/utils/syntax-highlight.d.ts.map +1 -1
- package/dist/utils/syntax-highlight.js +60 -1
- package/dist/utils/syntax-highlight.js.map +1 -1
- package/dist/utils/text.d.ts +8 -0
- package/dist/utils/text.d.ts.map +1 -0
- package/dist/utils/text.js +9 -0
- package/dist/utils/text.js.map +1 -0
- package/dist/utils/tools-manager.d.ts +70 -2
- package/dist/utils/tools-manager.d.ts.map +1 -1
- package/dist/utils/tools-manager.js +280 -124
- package/dist/utils/tools-manager.js.map +1 -1
- package/dist/utils/version-check.d.ts +7 -5
- package/dist/utils/version-check.d.ts.map +1 -1
- package/dist/utils/version-check.js +27 -14
- package/dist/utils/version-check.js.map +1 -1
- package/dist/utils/windows-self-update.d.ts.map +1 -1
- package/dist/utils/windows-self-update.js +1 -1
- package/dist/utils/windows-self-update.js.map +1 -1
- package/docs/compaction.md +41 -24
- package/docs/containerization.md +24 -21
- package/docs/custom-provider.md +15 -12
- package/docs/development.md +11 -11
- package/docs/environment-variables.md +37 -77
- package/docs/extensions.md +68 -54
- package/docs/index.md +12 -24
- package/docs/json.md +18 -11
- package/docs/keybindings.md +18 -12
- package/docs/llama-cpp.md +9 -7
- package/docs/models.md +17 -11
- package/docs/packages.md +47 -43
- package/docs/prompt-templates.md +3 -3
- package/docs/providers.md +10 -10
- package/docs/quickstart.md +49 -32
- package/docs/rpc.md +35 -18
- package/docs/sdk.md +20 -6
- package/docs/security.md +18 -18
- package/docs/session-format.md +9 -9
- package/docs/sessions.md +13 -13
- package/docs/settings.md +83 -16
- package/docs/shell-aliases.md +1 -1
- package/docs/skills.md +66 -15
- package/docs/terminal-setup.md +44 -19
- package/docs/termux.md +4 -4
- package/docs/themes.md +32 -11
- package/docs/tmux.md +4 -4
- package/docs/tui.md +5 -5
- package/docs/usage.md +61 -53
- package/docs/windows.md +24 -2
- package/examples/extensions/border-status-editor.ts +1 -1
- package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
- package/examples/extensions/custom-provider-anthropic/package.json +2 -2
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/git-checkpoint.ts +24 -36
- package/examples/extensions/gondolin/package-lock.json +2 -2
- package/examples/extensions/gondolin/package.json +1 -1
- package/examples/extensions/notify.ts +3 -1
- package/examples/extensions/sandbox/package-lock.json +2 -2
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/subagent/README.md +3 -1
- package/examples/extensions/subagent/agents.ts +40 -9
- package/examples/extensions/subagent/index.ts +27 -4
- package/examples/extensions/titlebar-spinner.ts +1 -1
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/examples/rpc-extension-ui.ts +1 -1
- package/examples/sdk/06-extensions.ts +1 -1
- package/examples/sdk/README.md +1 -1
- package/npm-shrinkwrap.json +435 -452
- package/package.json +17 -18
- package/dist/core/telemetry.d.ts +0 -3
- package/dist/core/telemetry.d.ts.map +0 -1
- package/dist/core/telemetry.js +0 -9
- package/dist/core/telemetry.js.map +0 -1
- package/dist/server/create-harness.d.ts +0 -26
- package/dist/server/create-harness.d.ts.map +0 -1
- package/dist/server/create-harness.js +0 -104
- package/dist/server/create-harness.js.map +0 -1
- package/dist/utils/pi-user-agent.d.ts +0 -2
- package/dist/utils/pi-user-agent.d.ts.map +0 -1
- package/dist/utils/pi-user-agent.js +0 -5
- package/dist/utils/pi-user-agent.js.map +0 -1
|
@@ -12,31 +12,42 @@
|
|
|
12
12
|
*
|
|
13
13
|
* Modes use this class and add their own I/O layer on top.
|
|
14
14
|
*/
|
|
15
|
-
import {
|
|
15
|
+
import { readFileSync } from "node:fs";
|
|
16
16
|
import { basename, dirname } from "node:path";
|
|
17
17
|
import { contentText } from "@earendil-works/pi-ai";
|
|
18
|
-
import { clampThinkingLevel, cleanupSessionResources, getSupportedThinkingLevels, isContextOverflow, isRecoverableLength, isRetryableAssistantError, modelsAreEqual, resetApiProviders,
|
|
18
|
+
import { clampThinkingLevel, cleanupSessionResources, getSupportedThinkingLevels, isContextOverflow, isRecoverableLength, isRetryableAssistantError, modelsAreEqual, resetApiProviders, } from "@earendil-works/pi-ai/compat";
|
|
19
19
|
import { getThemeByName, theme } from "../modes/interactive/theme/theme.js";
|
|
20
20
|
import { stripFrontmatter } from "../utils/frontmatter.js";
|
|
21
|
-
import { resolvePath } from "../utils/paths.js";
|
|
22
21
|
import { sleep } from "../utils/sleep.js";
|
|
23
22
|
import { normalizeToolResultImages } from "../utils/tool-result-images.js";
|
|
24
23
|
import { formatNoApiKeyFoundMessage, formatNoModelSelectedMessage } from "./auth-guidance.js";
|
|
25
24
|
import { executeBashWithOperations } from "./bash-executor.js";
|
|
25
|
+
import { createSessionCheckpoints } from "./checkpoints/session-checkpoints.js";
|
|
26
26
|
import { calculateContextTokens, collectEntriesForBranchSummary, compact, estimateContextTokens, estimateTokens, generateBranchSummary, prepareCompaction, shouldCompact, } from "./compaction/index.js";
|
|
27
|
-
import {
|
|
27
|
+
import { evictionBudget, installContextPipeline, isDefaultStreamFunction } from "./context/pipeline.js";
|
|
28
|
+
import { DEFAULT_THINKING_LEVEL, THINKING_LEVEL_OPTIONS } from "./defaults.js";
|
|
29
|
+
import { SessionEvidenceSink } from "./evidence.js";
|
|
28
30
|
import { exportSessionToHtml } from "./export-html/index.js";
|
|
29
31
|
import { createToolHtmlRenderer } from "./export-html/tool-renderer.js";
|
|
30
32
|
import { ExtensionRunner, wrapRegisteredTools, } from "./extensions/index.js";
|
|
31
33
|
import { emitSessionShutdownEvent } from "./extensions/runner.js";
|
|
32
34
|
import { ModelRegistry } from "./model-registry.js";
|
|
35
|
+
import { evaluateToolCall } from "./permissions/gate.js";
|
|
36
|
+
import { createInteractiveResponder } from "./permissions/responder.js";
|
|
37
|
+
import { resolveEffectiveModeWithOrigin } from "./permissions/startup.js";
|
|
33
38
|
import { expandPromptTemplate } from "./prompt-templates.js";
|
|
34
|
-
import {
|
|
39
|
+
import { exportSessionToJsonl } from "./session-export.js";
|
|
40
|
+
import { getLatestCompactionEntry, TODO_CUSTOM_ENTRY_TYPE } from "./session-manager.js";
|
|
41
|
+
import { slugifySkillCommandName } from "./skills.js";
|
|
35
42
|
import { createSyntheticSourceInfo } from "./source-info.js";
|
|
36
43
|
import { buildSystemPrompt } from "./system-prompt.js";
|
|
37
44
|
import { createLocalBashOperations } from "./tools/bash.js";
|
|
45
|
+
import { buildToolContractSnapshot, isUnclassifiedTool, } from "./tools/contract-snapshot.js";
|
|
38
46
|
import { createAllToolDefinitions } from "./tools/index.js";
|
|
47
|
+
import { createSkillSearchToolDefinition } from "./tools/skill-search.js";
|
|
48
|
+
import { createTodoWriteToolDefinition } from "./tools/todo-write.js";
|
|
39
49
|
import { createToolDefinitionFromAgentTool } from "./tools/tool-definition-wrapper.js";
|
|
50
|
+
import { createToolSchemaToolDefinition } from "./tools/tool-schema.js";
|
|
40
51
|
import { addUsageToTotals, createUsageTotals } from "./usage-totals.js";
|
|
41
52
|
/**
|
|
42
53
|
* Parse a skill block from message text.
|
|
@@ -71,8 +82,6 @@ function estimateMessagesTokens(messages) {
|
|
|
71
82
|
// ============================================================================
|
|
72
83
|
// Constants
|
|
73
84
|
// ============================================================================
|
|
74
|
-
/** Standard thinking levels */
|
|
75
|
-
const THINKING_LEVELS = ["off", "minimal", "low", "medium", "high"];
|
|
76
85
|
// ============================================================================
|
|
77
86
|
// AgentSession Class
|
|
78
87
|
// ============================================================================
|
|
@@ -97,6 +106,7 @@ export class AgentSession {
|
|
|
97
106
|
_compactionAbortController = undefined;
|
|
98
107
|
_autoCompactionAbortController = undefined;
|
|
99
108
|
_overflowRecoveryAttempted = false;
|
|
109
|
+
_midRunCompactionNeeded = false;
|
|
100
110
|
// Branch summarization state
|
|
101
111
|
_branchSummaryAbortController = undefined;
|
|
102
112
|
// Retry state
|
|
@@ -118,6 +128,21 @@ export class AgentSession {
|
|
|
118
128
|
_excludedToolNames;
|
|
119
129
|
_baseToolsOverride;
|
|
120
130
|
_sessionStartEvent;
|
|
131
|
+
_permissionGate;
|
|
132
|
+
_evidenceSink;
|
|
133
|
+
_diagnosticsOperations;
|
|
134
|
+
_lspOperations;
|
|
135
|
+
_mcpRuntime;
|
|
136
|
+
/** Configured MCP subsystem, or undefined when no server is configured. */
|
|
137
|
+
get mcpRuntime() {
|
|
138
|
+
return this._mcpRuntime;
|
|
139
|
+
}
|
|
140
|
+
_checkpoints;
|
|
141
|
+
/** Worktree checkpoints for this session. Inert unless `checkpoints.enabled` is set. */
|
|
142
|
+
get checkpoints() {
|
|
143
|
+
return this._checkpoints;
|
|
144
|
+
}
|
|
145
|
+
_webSearchOperations;
|
|
121
146
|
_extensionUIContext;
|
|
122
147
|
_extensionMode = "print";
|
|
123
148
|
_extensionCommandContextActions;
|
|
@@ -131,6 +156,7 @@ export class AgentSession {
|
|
|
131
156
|
_toolDefinitions = new Map();
|
|
132
157
|
_toolPromptSnippets = new Map();
|
|
133
158
|
_toolPromptGuidelines = new Map();
|
|
159
|
+
_loadedDeferredSchemas = new Set();
|
|
134
160
|
// Base system prompt (without extension appends) - used to apply fresh appends each turn
|
|
135
161
|
_baseSystemPrompt = "";
|
|
136
162
|
_baseSystemPromptOptions;
|
|
@@ -150,11 +176,24 @@ export class AgentSession {
|
|
|
150
176
|
this._excludedToolNames = config.excludedToolNames ? new Set(config.excludedToolNames) : undefined;
|
|
151
177
|
this._baseToolsOverride = config.baseToolsOverride;
|
|
152
178
|
this._sessionStartEvent = config.sessionStartEvent ?? { type: "session_start", reason: "startup" };
|
|
179
|
+
this._permissionGate = config.permissionGate;
|
|
180
|
+
this._evidenceSink = config.evidenceSink ?? new SessionEvidenceSink(this.sessionManager);
|
|
181
|
+
this._diagnosticsOperations = config.diagnosticsOperations;
|
|
182
|
+
this._lspOperations = config.lspOperations;
|
|
183
|
+
this._mcpRuntime = config.mcpRuntime;
|
|
184
|
+
this._webSearchOperations = config.webSearchOperations;
|
|
185
|
+
this._checkpoints = createSessionCheckpoints({
|
|
186
|
+
workspace: this._cwd,
|
|
187
|
+
sessionId: this.sessionManager.getSessionId(),
|
|
188
|
+
settings: config.checkpointSettings,
|
|
189
|
+
});
|
|
153
190
|
// Always subscribe to agent events for internal handling
|
|
154
191
|
// (session persistence, extensions, auto-compaction, retry logic)
|
|
155
192
|
this._unsubscribeAgent = this.agent.subscribe(this._handleAgentEvent);
|
|
156
193
|
this._installAgentToolHooks();
|
|
157
194
|
this._installAgentNextTurnRefresh();
|
|
195
|
+
this._installMidRunCompactionHook();
|
|
196
|
+
this._installContextPipeline();
|
|
158
197
|
this._buildRuntime({
|
|
159
198
|
activeToolNames: this._initialActiveToolNames,
|
|
160
199
|
includeAllExtensionTools: true,
|
|
@@ -193,7 +232,7 @@ export class AgentSession {
|
|
|
193
232
|
throw new Error(formatNoApiKeyFoundMessage(model.provider));
|
|
194
233
|
}
|
|
195
234
|
async _getSummarizationRequestAuth(model) {
|
|
196
|
-
if (this.agent.streamFunction
|
|
235
|
+
if (isDefaultStreamFunction(this.agent.streamFunction)) {
|
|
197
236
|
return this._getRequiredRequestAuth(model);
|
|
198
237
|
}
|
|
199
238
|
try {
|
|
@@ -223,25 +262,63 @@ export class AgentSession {
|
|
|
223
262
|
_installAgentToolHooks() {
|
|
224
263
|
this.agent.beforeToolCall = async ({ toolCall, args }) => {
|
|
225
264
|
const runner = this._extensionRunner;
|
|
226
|
-
if (
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
265
|
+
if (runner.hasHandlers("tool_call")) {
|
|
266
|
+
let extensionResult;
|
|
267
|
+
try {
|
|
268
|
+
extensionResult = await runner.emitToolCall({
|
|
269
|
+
type: "tool_call",
|
|
270
|
+
toolName: toolCall.name,
|
|
271
|
+
toolCallId: toolCall.id,
|
|
272
|
+
input: args,
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
catch (err) {
|
|
276
|
+
if (err instanceof Error) {
|
|
277
|
+
throw err;
|
|
278
|
+
}
|
|
279
|
+
throw new Error(`Extension failed, blocking execution: ${String(err)}`);
|
|
240
280
|
}
|
|
241
|
-
|
|
281
|
+
// A blocking extension remains authoritative. A non-blocking result
|
|
282
|
+
// (including a mutation-only `{}`) must still pass the permission gate,
|
|
283
|
+
// which evaluates the extension's final input below.
|
|
284
|
+
if (extensionResult?.block === true)
|
|
285
|
+
return extensionResult;
|
|
286
|
+
}
|
|
287
|
+
// Permission gate (roadmap Phase 2a, ADR 0004). Off by default — see
|
|
288
|
+
// AgentSessionConfig.permissionGate. When present, every registered tool
|
|
289
|
+
// call passes through it (contracts.md invariant 2): this is the seam,
|
|
290
|
+
// not a per-tool opt-in.
|
|
291
|
+
if (this._permissionGate) {
|
|
292
|
+
const decision = await evaluateToolCall(toolCall.name, args, {
|
|
293
|
+
...this._permissionGate,
|
|
294
|
+
getContract: (name) => this.getToolDefinition(name)?.contract,
|
|
295
|
+
getResponder: () => this._extensionMode === "tui" && this._extensionUIContext
|
|
296
|
+
? createInteractiveResponder(this._extensionUIContext)
|
|
297
|
+
: undefined,
|
|
298
|
+
});
|
|
299
|
+
if (decision.block)
|
|
300
|
+
return { block: true, reason: decision.reason };
|
|
242
301
|
}
|
|
302
|
+
return undefined;
|
|
243
303
|
};
|
|
244
304
|
this.agent.afterToolCall = async ({ toolCall, args, result, isError }) => {
|
|
305
|
+
const definition = this.getToolDefinition(toolCall.name);
|
|
306
|
+
if (this._evidenceSink && definition?.contract) {
|
|
307
|
+
try {
|
|
308
|
+
const records = definition.contract.evidence.capture(args, result);
|
|
309
|
+
if (!records.every((record) => definition.contract?.evidence.emits.has(record.kind))) {
|
|
310
|
+
throw new Error("Evidence capture emitted a kind not declared by its tool contract");
|
|
311
|
+
}
|
|
312
|
+
if (records.length > 0)
|
|
313
|
+
this._evidenceSink.record({ toolName: toolCall.name, records });
|
|
314
|
+
}
|
|
315
|
+
catch (error) {
|
|
316
|
+
this._evidenceSink.recordDiagnostic?.({
|
|
317
|
+
toolName: toolCall.name,
|
|
318
|
+
reason: error instanceof Error ? error.message : String(error),
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
}
|
|
245
322
|
const runner = this._extensionRunner;
|
|
246
323
|
const hookResult = runner.hasHandlers("tool_result")
|
|
247
324
|
? await runner.emitToolResult({
|
|
@@ -291,6 +368,75 @@ export class AgentSession {
|
|
|
291
368
|
};
|
|
292
369
|
};
|
|
293
370
|
}
|
|
371
|
+
/** Stop an over-threshold tool loop before it sends another provider request. */
|
|
372
|
+
_installMidRunCompactionHook() {
|
|
373
|
+
const previousShouldStopAfterTurn = this.agent.shouldStopAfterTurn;
|
|
374
|
+
this.agent.shouldStopAfterTurn = async (turn, signal) => {
|
|
375
|
+
if (await previousShouldStopAfterTurn?.(turn, signal)) {
|
|
376
|
+
return true;
|
|
377
|
+
}
|
|
378
|
+
return this._shouldStopForMidRunCompaction(turn);
|
|
379
|
+
};
|
|
380
|
+
}
|
|
381
|
+
_shouldStopForMidRunCompaction(turn) {
|
|
382
|
+
if (!turn.hasMoreToolCalls || turn.toolResults.length === 0) {
|
|
383
|
+
return false;
|
|
384
|
+
}
|
|
385
|
+
const settings = this.settingsManager.getCompactionSettings();
|
|
386
|
+
if (!settings.enabled) {
|
|
387
|
+
return false;
|
|
388
|
+
}
|
|
389
|
+
const contextWindow = this.model?.contextWindow ?? 0;
|
|
390
|
+
if (contextWindow <= 0) {
|
|
391
|
+
return false;
|
|
392
|
+
}
|
|
393
|
+
const contextTokens = estimateContextTokens(turn.context.messages).tokens;
|
|
394
|
+
if (!shouldCompact(contextTokens, contextWindow, settings)) {
|
|
395
|
+
return false;
|
|
396
|
+
}
|
|
397
|
+
this._midRunCompactionNeeded = true;
|
|
398
|
+
return true;
|
|
399
|
+
}
|
|
400
|
+
/**
|
|
401
|
+
* Installs the context pipeline settled in `docs/architecture/contracts.md` § 2:
|
|
402
|
+
* deferred-schema resolution → tool-result eviction → compaction. Compaction
|
|
403
|
+
* already runs reactively from `_checkCompaction`, after a response comes back
|
|
404
|
+
* over-threshold or overflowed; this method only adds the two stages that run
|
|
405
|
+
* *ahead of* every LLM request, so that reactive check is reached less often
|
|
406
|
+
* because the request it is reacting to is smaller. It does not call into
|
|
407
|
+
* compaction and does not need to.
|
|
408
|
+
*
|
|
409
|
+
* The wiring itself — where each stage attaches, and why they land in different
|
|
410
|
+
* seams (`transformContext` for eviction, `streamFunction` for schema
|
|
411
|
+
* projection) — lives in `./context/pipeline.ts`'s `installContextPipeline`,
|
|
412
|
+
* shared with the offline replay harness so there is one implementation, not
|
|
413
|
+
* two. This method only supplies this session's two dependencies: a contract
|
|
414
|
+
* lookup backed by `getToolDefinition`, and a budget thunk (never cached — see
|
|
415
|
+
* `_evictionBudget`, which reads live `this.model` / `this.settingsManager` on
|
|
416
|
+
* every call, so a model switch or settings edit mid-session takes effect on
|
|
417
|
+
* the very next request).
|
|
418
|
+
*/
|
|
419
|
+
_installContextPipeline() {
|
|
420
|
+
installContextPipeline(this.agent, {
|
|
421
|
+
contractLookup: (name) => this.getToolDefinition(name)?.contract,
|
|
422
|
+
loadedSchemaNames: this._loadedDeferredSchemas,
|
|
423
|
+
evictionBudget: () => this._evictionBudget(),
|
|
424
|
+
});
|
|
425
|
+
}
|
|
426
|
+
/**
|
|
427
|
+
* Token budget for `evictToolResults`'s outbound pass, derived from the same
|
|
428
|
+
* quantities compaction already uses for its own threshold
|
|
429
|
+
* (`getCompactionSettings()`; see `shouldCompact` in
|
|
430
|
+
* `core/compaction/compaction.ts`). The formula itself is `./context/
|
|
431
|
+
* pipeline.ts`'s `evictionBudget` — see that function's comment for the "why
|
|
432
|
+
* half of headroom" reasoning; this method only supplies production's real
|
|
433
|
+
* `contextWindow` / `reserveTokens` inputs.
|
|
434
|
+
*/
|
|
435
|
+
_evictionBudget() {
|
|
436
|
+
const contextWindow = this.model?.contextWindow ?? 0;
|
|
437
|
+
const { reserveTokens } = this.settingsManager.getCompactionSettings();
|
|
438
|
+
return evictionBudget(contextWindow, reserveTokens);
|
|
439
|
+
}
|
|
294
440
|
// =========================================================================
|
|
295
441
|
// Event Subscription
|
|
296
442
|
// =========================================================================
|
|
@@ -307,6 +453,11 @@ export class AgentSession {
|
|
|
307
453
|
followUp: [...this._followUpMessages],
|
|
308
454
|
});
|
|
309
455
|
}
|
|
456
|
+
async _emitSessionCompactFailed(event) {
|
|
457
|
+
if (this._extensionRunner.hasHandlers("session_compact_failed")) {
|
|
458
|
+
await this._extensionRunner.emit({ type: "session_compact_failed", ...event });
|
|
459
|
+
}
|
|
460
|
+
}
|
|
310
461
|
_getIdleWaitPromise() {
|
|
311
462
|
if (!this._idleWaitPromise) {
|
|
312
463
|
this._idleWaitPromise = new Promise((resolve) => {
|
|
@@ -446,6 +597,18 @@ export class AgentSession {
|
|
|
446
597
|
await this._extensionRunner.emit({ type: "agent_end", messages: event.messages });
|
|
447
598
|
}
|
|
448
599
|
else if (event.type === "turn_start") {
|
|
600
|
+
// Snapshot before the model gets to act, keyed to the entry `/tree` and `/fork`
|
|
601
|
+
// already navigate to, so the two agree about what an entry means.
|
|
602
|
+
//
|
|
603
|
+
// Awaited, despite the turn latency. Detached, the snapshot races the turn it is
|
|
604
|
+
// supposed to precede: a tool call can edit the worktree while `add -A` is still
|
|
605
|
+
// walking it, and the ref then holds mid-turn state that no `/fork` should ever
|
|
606
|
+
// restore. "The state before the model acted" is the whole guarantee, so paying
|
|
607
|
+
// for it here is the point. The engine's own timeout bounds the wait and a failed
|
|
608
|
+
// capture is never fatal.
|
|
609
|
+
const leafEntryId = this.sessionManager.getLeafEntry()?.id;
|
|
610
|
+
if (leafEntryId)
|
|
611
|
+
await this._checkpoints.capture(leafEntryId);
|
|
449
612
|
const extensionEvent = {
|
|
450
613
|
type: "turn_start",
|
|
451
614
|
turnIndex: this._turnIndex,
|
|
@@ -567,6 +730,9 @@ export class AgentSession {
|
|
|
567
730
|
this._extensionRunner.invalidate("This extension ctx is stale after session replacement or reload. Do not use a captured pi or command ctx after ctx.newSession(), ctx.fork(), ctx.switchSession(), or ctx.reload(). For newSession, fork, and switchSession, move post-replacement work into withSession and use the ctx passed to withSession. For reload, do not use the old ctx after await ctx.reload().");
|
|
568
731
|
this._disconnectFromAgent();
|
|
569
732
|
this._eventListeners = [];
|
|
733
|
+
// Every connected MCP server is a child process this session started. Without
|
|
734
|
+
// this, one leaks per server per session, because nothing else owns them.
|
|
735
|
+
this._mcpRuntime?.close().catch(() => undefined);
|
|
570
736
|
cleanupSessionResources(this.sessionId);
|
|
571
737
|
}
|
|
572
738
|
// =========================================================================
|
|
@@ -610,13 +776,24 @@ export class AgentSession {
|
|
|
610
776
|
/**
|
|
611
777
|
* Get all configured tools with name, description, parameter schema, prompt guidelines, and source metadata.
|
|
612
778
|
*/
|
|
779
|
+
/**
|
|
780
|
+
* The ADR 0010 projection over this session's registry: the one read every surface
|
|
781
|
+
* that *describes* the tool set consumes. Never an authorization input.
|
|
782
|
+
*/
|
|
783
|
+
getToolContractSnapshot() {
|
|
784
|
+
return buildToolContractSnapshot(Array.from(this._toolDefinitions.values()).map(({ definition }) => definition));
|
|
785
|
+
}
|
|
613
786
|
getAllTools() {
|
|
614
|
-
|
|
787
|
+
const schemaToolActive = this.getActiveToolNames().includes("tool_schema");
|
|
788
|
+
return Array.from(this._toolDefinitions.values())
|
|
789
|
+
.filter(({ definition }) => definition.name !== "tool_schema" || schemaToolActive)
|
|
790
|
+
.map(({ definition, sourceInfo }) => ({
|
|
615
791
|
name: definition.name,
|
|
616
792
|
description: definition.description,
|
|
617
793
|
parameters: definition.parameters,
|
|
618
794
|
promptGuidelines: definition.promptGuidelines,
|
|
619
795
|
sourceInfo,
|
|
796
|
+
unclassified: isUnclassifiedTool(definition),
|
|
620
797
|
}));
|
|
621
798
|
}
|
|
622
799
|
getToolDefinition(name) {
|
|
@@ -756,6 +933,10 @@ export class AgentSession {
|
|
|
756
933
|
}
|
|
757
934
|
}
|
|
758
935
|
async _handlePostAgentRun() {
|
|
936
|
+
if (this._midRunCompactionNeeded) {
|
|
937
|
+
this._midRunCompactionNeeded = false;
|
|
938
|
+
return await this._runAutoCompaction("threshold", true);
|
|
939
|
+
}
|
|
759
940
|
const msg = this._lastAssistantMessage;
|
|
760
941
|
this._lastAssistantMessage = undefined;
|
|
761
942
|
if (!msg) {
|
|
@@ -954,9 +1135,16 @@ export class AgentSession {
|
|
|
954
1135
|
if (!text.startsWith("/skill:"))
|
|
955
1136
|
return text;
|
|
956
1137
|
const spaceIndex = text.indexOf(" ");
|
|
957
|
-
const
|
|
1138
|
+
const commandToken = spaceIndex === -1 ? text.slice(7) : text.slice(7, spaceIndex);
|
|
958
1139
|
const args = spaceIndex === -1 ? "" : text.slice(spaceIndex + 1).trim();
|
|
959
|
-
|
|
1140
|
+
// Matched against the slugged command token (SKILL.5), not the raw frontmatter
|
|
1141
|
+
// name -- identity for an already command-safe name, so an exactly-typed raw
|
|
1142
|
+
// name still matches too. A skill whose name contains a space or other
|
|
1143
|
+
// slash-command-breaking character (docs/skills.md's lenient loading allows
|
|
1144
|
+
// this) is only reachable through its slugged token.
|
|
1145
|
+
const skill = this.resourceLoader
|
|
1146
|
+
.getSkills()
|
|
1147
|
+
.skills.find((s) => slugifySkillCommandName(s.name) === commandToken);
|
|
960
1148
|
if (!skill)
|
|
961
1149
|
return text; // Unknown skill, pass through
|
|
962
1150
|
try {
|
|
@@ -1078,7 +1266,7 @@ export class AgentSession {
|
|
|
1078
1266
|
if (options?.deliverAs === "nextTurn") {
|
|
1079
1267
|
this._pendingNextTurnMessages.push(appMessage);
|
|
1080
1268
|
}
|
|
1081
|
-
else if (this.isStreaming) {
|
|
1269
|
+
else if (this.isStreaming && options?.triggerTurn !== false) {
|
|
1082
1270
|
if (options?.deliverAs === "followUp") {
|
|
1083
1271
|
this.agent.followUp(appMessage);
|
|
1084
1272
|
}
|
|
@@ -1102,6 +1290,7 @@ export class AgentSession {
|
|
|
1102
1290
|
*
|
|
1103
1291
|
* @param content User message content (string or content array)
|
|
1104
1292
|
* @param options.deliverAs Delivery mode when streaming: "steer" or "followUp"
|
|
1293
|
+
* @param options.expandPromptTemplates Whether to dispatch extension commands and expand skill commands and prompt templates. Default: false.
|
|
1105
1294
|
*/
|
|
1106
1295
|
async sendUserMessage(content, options) {
|
|
1107
1296
|
// Normalize content to text string + optional images
|
|
@@ -1125,9 +1314,8 @@ export class AgentSession {
|
|
|
1125
1314
|
if (images.length === 0)
|
|
1126
1315
|
images = undefined;
|
|
1127
1316
|
}
|
|
1128
|
-
// Use prompt() with expandPromptTemplates: false to skip command handling and template expansion
|
|
1129
1317
|
await this.prompt(text, {
|
|
1130
|
-
expandPromptTemplates: false,
|
|
1318
|
+
expandPromptTemplates: options?.expandPromptTemplates ?? false,
|
|
1131
1319
|
streamingBehavior: options?.deliverAs,
|
|
1132
1320
|
images,
|
|
1133
1321
|
source: "extension",
|
|
@@ -1189,21 +1377,53 @@ export class AgentSession {
|
|
|
1189
1377
|
source,
|
|
1190
1378
|
});
|
|
1191
1379
|
}
|
|
1380
|
+
/** True when this session runs behind a permission gate at all. */
|
|
1381
|
+
get hasPermissionGate() {
|
|
1382
|
+
return this._permissionGate !== undefined;
|
|
1383
|
+
}
|
|
1384
|
+
/**
|
|
1385
|
+
* The mode in force right now, and which source won. `getMode` in the gate
|
|
1386
|
+
* config re-reads the store on every decision, so a mode written here applies
|
|
1387
|
+
* to the next tool call with no restart.
|
|
1388
|
+
*/
|
|
1389
|
+
async getPermissionMode() {
|
|
1390
|
+
if (!this._permissionGate)
|
|
1391
|
+
return undefined;
|
|
1392
|
+
const snapshot = await this._permissionGate.store.snapshot();
|
|
1393
|
+
return resolveEffectiveModeWithOrigin(this._permissionGate.flagMode, snapshot.modesBySource);
|
|
1394
|
+
}
|
|
1395
|
+
/**
|
|
1396
|
+
* Persist a permission mode to user scope (`~/.apex-code/agent/permissions.json`).
|
|
1397
|
+
* Returns the resolution that is actually in force afterwards, which is *not*
|
|
1398
|
+
* necessarily `mode`: `flag`, `local`, and `project` all outrank `user`, so the
|
|
1399
|
+
* caller has to be able to tell the user their choice was recorded but shadowed.
|
|
1400
|
+
*/
|
|
1401
|
+
async setPermissionMode(mode) {
|
|
1402
|
+
if (!this._permissionGate)
|
|
1403
|
+
return undefined;
|
|
1404
|
+
await this._permissionGate.store.apply({ type: "setMode", destination: "user", mode });
|
|
1405
|
+
return this.getPermissionMode();
|
|
1406
|
+
}
|
|
1192
1407
|
/**
|
|
1193
1408
|
* Set model directly.
|
|
1194
|
-
* Validates that auth is configured
|
|
1409
|
+
* Validates that auth is configured and saves to the session transcript.
|
|
1410
|
+
* Persists to global defaults only when options.persist is true.
|
|
1195
1411
|
* @throws Error if no auth is configured for the model
|
|
1196
1412
|
*/
|
|
1197
|
-
async setModel(model) {
|
|
1413
|
+
async setModel(model, options = {}) {
|
|
1198
1414
|
if (!(await this._modelRuntime.checkAuth(model.provider))) {
|
|
1199
1415
|
throw new Error(`No API key for ${model.provider}/${model.id}`);
|
|
1200
1416
|
}
|
|
1201
1417
|
const previousModel = this.model;
|
|
1202
|
-
const thinkingLevel = this._getThinkingLevelForModelSwitch();
|
|
1418
|
+
const thinkingLevel = this._getThinkingLevelForModelSwitch(model);
|
|
1203
1419
|
this.agent.state.model = model;
|
|
1204
1420
|
this.sessionManager.appendModelChange(model.provider, model.id);
|
|
1205
|
-
|
|
1206
|
-
|
|
1421
|
+
if (options.persist) {
|
|
1422
|
+
this.settingsManager.setDefaultModelAndProvider(model.provider, model.id);
|
|
1423
|
+
}
|
|
1424
|
+
// Apply thinking level for the new model.
|
|
1425
|
+
// Per-model thinking level overrides take priority over the global default.
|
|
1426
|
+
// Model persistence does not implicitly rewrite the global thinking default.
|
|
1207
1427
|
this.setThinkingLevel(thinkingLevel);
|
|
1208
1428
|
await this._emitModelSelect(model, previousModel, "set");
|
|
1209
1429
|
}
|
|
@@ -1213,13 +1433,13 @@ export class AgentSession {
|
|
|
1213
1433
|
* @param direction - "forward" (default) or "backward"
|
|
1214
1434
|
* @returns The new model info, or undefined if only one model available
|
|
1215
1435
|
*/
|
|
1216
|
-
async cycleModel(direction = "forward") {
|
|
1436
|
+
async cycleModel(direction = "forward", options = {}) {
|
|
1217
1437
|
if (this._scopedModels.length > 0) {
|
|
1218
|
-
return this._cycleScopedModel(direction);
|
|
1438
|
+
return this._cycleScopedModel(direction, options);
|
|
1219
1439
|
}
|
|
1220
|
-
return this._cycleAvailableModel(direction);
|
|
1440
|
+
return this._cycleAvailableModel(direction, options);
|
|
1221
1441
|
}
|
|
1222
|
-
async _cycleScopedModel(direction) {
|
|
1442
|
+
async _cycleScopedModel(direction, options) {
|
|
1223
1443
|
const availableIds = new Set(this._modelRuntime.getAvailableSnapshot().map((model) => `${model.provider}\0${model.id}`));
|
|
1224
1444
|
const scopedModels = this._scopedModels.filter((scoped) => availableIds.has(`${scoped.model.provider}\0${scoped.model.id}`));
|
|
1225
1445
|
if (scopedModels.length <= 1)
|
|
@@ -1231,20 +1451,23 @@ export class AgentSession {
|
|
|
1231
1451
|
const len = scopedModels.length;
|
|
1232
1452
|
const nextIndex = direction === "forward" ? (currentIndex + 1) % len : (currentIndex - 1 + len) % len;
|
|
1233
1453
|
const next = scopedModels[nextIndex];
|
|
1234
|
-
const thinkingLevel = this._getThinkingLevelForModelSwitch(next.thinkingLevel);
|
|
1454
|
+
const thinkingLevel = this._getThinkingLevelForModelSwitch(next.model, next.thinkingLevel);
|
|
1235
1455
|
// Apply model
|
|
1236
1456
|
this.agent.state.model = next.model;
|
|
1237
1457
|
this.sessionManager.appendModelChange(next.model.provider, next.model.id);
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
//
|
|
1458
|
+
if (options.persist) {
|
|
1459
|
+
this.settingsManager.setDefaultModelAndProvider(next.model.provider, next.model.id);
|
|
1460
|
+
}
|
|
1461
|
+
// Apply thinking level for the new model.
|
|
1462
|
+
// - Explicit scoped model thinking level overrides defaults
|
|
1463
|
+
// - Per-model thinking level overrides take priority over the global default
|
|
1242
1464
|
// setThinkingLevel clamps to model capabilities.
|
|
1465
|
+
// Model persistence does not implicitly rewrite the global thinking default.
|
|
1243
1466
|
this.setThinkingLevel(thinkingLevel);
|
|
1244
1467
|
await this._emitModelSelect(next.model, currentModel, "cycle");
|
|
1245
1468
|
return { model: next.model, thinkingLevel: this.thinkingLevel, isScoped: true };
|
|
1246
1469
|
}
|
|
1247
|
-
async _cycleAvailableModel(direction) {
|
|
1470
|
+
async _cycleAvailableModel(direction, options) {
|
|
1248
1471
|
const availableModels = this._modelRuntime.getAvailableSnapshot();
|
|
1249
1472
|
if (availableModels.length <= 1)
|
|
1250
1473
|
return undefined;
|
|
@@ -1255,11 +1478,14 @@ export class AgentSession {
|
|
|
1255
1478
|
const len = availableModels.length;
|
|
1256
1479
|
const nextIndex = direction === "forward" ? (currentIndex + 1) % len : (currentIndex - 1 + len) % len;
|
|
1257
1480
|
const nextModel = availableModels[nextIndex];
|
|
1258
|
-
const thinkingLevel = this._getThinkingLevelForModelSwitch();
|
|
1481
|
+
const thinkingLevel = this._getThinkingLevelForModelSwitch(nextModel);
|
|
1259
1482
|
this.agent.state.model = nextModel;
|
|
1260
1483
|
this.sessionManager.appendModelChange(nextModel.provider, nextModel.id);
|
|
1261
|
-
|
|
1262
|
-
|
|
1484
|
+
if (options.persist) {
|
|
1485
|
+
this.settingsManager.setDefaultModelAndProvider(nextModel.provider, nextModel.id);
|
|
1486
|
+
}
|
|
1487
|
+
// Apply thinking level for the new model.
|
|
1488
|
+
// Model persistence does not implicitly rewrite the global thinking default.
|
|
1263
1489
|
this.setThinkingLevel(thinkingLevel);
|
|
1264
1490
|
await this._emitModelSelect(nextModel, currentModel, "cycle");
|
|
1265
1491
|
return { model: nextModel, thinkingLevel: this.thinkingLevel, isScoped: false };
|
|
@@ -1270,20 +1496,21 @@ export class AgentSession {
|
|
|
1270
1496
|
/**
|
|
1271
1497
|
* Set thinking level.
|
|
1272
1498
|
* Clamps to model capabilities based on available thinking levels.
|
|
1273
|
-
* Saves to session
|
|
1499
|
+
* Saves the clamped level to the session transcript only if the level actually changes.
|
|
1500
|
+
* Persists the requested level to global defaults only when options.persist is true.
|
|
1274
1501
|
*/
|
|
1275
|
-
setThinkingLevel(level) {
|
|
1502
|
+
setThinkingLevel(level, options = {}) {
|
|
1276
1503
|
const availableLevels = this.getAvailableThinkingLevels();
|
|
1277
1504
|
const effectiveLevel = availableLevels.includes(level) ? level : this._clampThinkingLevel(level, availableLevels);
|
|
1278
1505
|
// Only persist if actually changing
|
|
1279
1506
|
const previousLevel = this.agent.state.thinkingLevel;
|
|
1280
1507
|
const isChanging = effectiveLevel !== previousLevel;
|
|
1281
1508
|
this.agent.state.thinkingLevel = effectiveLevel;
|
|
1509
|
+
if (options.persist) {
|
|
1510
|
+
this.settingsManager.setDefaultThinkingLevel(level);
|
|
1511
|
+
}
|
|
1282
1512
|
if (isChanging) {
|
|
1283
1513
|
this.sessionManager.appendThinkingLevelChange(effectiveLevel);
|
|
1284
|
-
if (this.supportsThinking() || effectiveLevel !== "off") {
|
|
1285
|
-
this.settingsManager.setDefaultThinkingLevel(effectiveLevel);
|
|
1286
|
-
}
|
|
1287
1514
|
this._emit({ type: "thinking_level_changed", level: effectiveLevel });
|
|
1288
1515
|
void this._extensionRunner.emit({
|
|
1289
1516
|
type: "thinking_level_select",
|
|
@@ -1296,14 +1523,14 @@ export class AgentSession {
|
|
|
1296
1523
|
* Cycle to next thinking level.
|
|
1297
1524
|
* @returns New level, or undefined if model doesn't support thinking
|
|
1298
1525
|
*/
|
|
1299
|
-
cycleThinkingLevel() {
|
|
1526
|
+
cycleThinkingLevel(options = {}) {
|
|
1300
1527
|
if (!this.supportsThinking())
|
|
1301
1528
|
return undefined;
|
|
1302
1529
|
const levels = this.getAvailableThinkingLevels();
|
|
1303
1530
|
const currentIndex = levels.indexOf(this.thinkingLevel);
|
|
1304
1531
|
const nextIndex = (currentIndex + 1) % levels.length;
|
|
1305
1532
|
const nextLevel = levels[nextIndex];
|
|
1306
|
-
this.setThinkingLevel(nextLevel);
|
|
1533
|
+
this.setThinkingLevel(nextLevel, options);
|
|
1307
1534
|
return nextLevel;
|
|
1308
1535
|
}
|
|
1309
1536
|
/**
|
|
@@ -1312,7 +1539,7 @@ export class AgentSession {
|
|
|
1312
1539
|
*/
|
|
1313
1540
|
getAvailableThinkingLevels() {
|
|
1314
1541
|
if (!this.model)
|
|
1315
|
-
return
|
|
1542
|
+
return [...THINKING_LEVEL_OPTIONS];
|
|
1316
1543
|
return getSupportedThinkingLevels(this.model);
|
|
1317
1544
|
}
|
|
1318
1545
|
/**
|
|
@@ -1321,14 +1548,18 @@ export class AgentSession {
|
|
|
1321
1548
|
supportsThinking() {
|
|
1322
1549
|
return !!this.model?.reasoning;
|
|
1323
1550
|
}
|
|
1324
|
-
_getThinkingLevelForModelSwitch(explicitLevel) {
|
|
1551
|
+
_getThinkingLevelForModelSwitch(targetModel, explicitLevel) {
|
|
1325
1552
|
if (explicitLevel !== undefined) {
|
|
1326
1553
|
return explicitLevel;
|
|
1327
1554
|
}
|
|
1328
|
-
|
|
1329
|
-
|
|
1555
|
+
// Per-model default takes priority when switching to a model that has one
|
|
1556
|
+
if (targetModel) {
|
|
1557
|
+
const perModel = this.settingsManager.getModelThinkingLevel(targetModel.provider, targetModel.id);
|
|
1558
|
+
if (perModel !== undefined) {
|
|
1559
|
+
return perModel;
|
|
1560
|
+
}
|
|
1330
1561
|
}
|
|
1331
|
-
return this.thinkingLevel;
|
|
1562
|
+
return this.settingsManager.getDefaultThinkingLevel() ?? this.thinkingLevel ?? DEFAULT_THINKING_LEVEL;
|
|
1332
1563
|
}
|
|
1333
1564
|
_clampThinkingLevel(level, _availableLevels) {
|
|
1334
1565
|
return this.model ? clampThinkingLevel(this.model, level) : "off";
|
|
@@ -1359,15 +1590,30 @@ export class AgentSession {
|
|
|
1359
1590
|
// =========================================================================
|
|
1360
1591
|
// Compaction
|
|
1361
1592
|
// =========================================================================
|
|
1593
|
+
/** Generate Pi's built-in compaction summary for manual and automatic compaction. */
|
|
1594
|
+
async _runDefaultCompaction(preparation, requestModel, apiKey, headers, customInstructions, signal, env, reason) {
|
|
1595
|
+
return compact(preparation, requestModel, apiKey, headers, customInstructions, signal, this.thinkingLevel, this.agent.streamFunction, env, this.settingsManager.getRetrySettings(), this._summarizationRetryCallbacks({ source: "compaction", reason }), undefined);
|
|
1596
|
+
}
|
|
1362
1597
|
/**
|
|
1363
1598
|
* Manually compact the session context.
|
|
1364
|
-
*
|
|
1599
|
+
*
|
|
1600
|
+
* This is the manual entry point used by `/compact`, RPC, and extensions. It is
|
|
1601
|
+
* separate from automatic threshold/overflow compaction, which enters through
|
|
1602
|
+
* `_checkCompaction()` and `_runAutoCompaction()`. After preparation and the
|
|
1603
|
+
* `session_before_compact` hook, both paths call the lower-level `compact()`
|
|
1604
|
+
* function imported from `./compaction/index.ts`, unless the hook cancels or
|
|
1605
|
+
* supplies a custom result.
|
|
1606
|
+
*
|
|
1607
|
+
* Aborts the current agent operation first. Manual compaction never retries or
|
|
1608
|
+
* continues the interrupted agent turn.
|
|
1609
|
+
*
|
|
1365
1610
|
* @param customInstructions Optional instructions for the compaction summary
|
|
1366
1611
|
*/
|
|
1367
1612
|
async compact(customInstructions) {
|
|
1368
1613
|
await this.abort();
|
|
1369
1614
|
this._compactionAbortController = new AbortController();
|
|
1370
1615
|
this._emit({ type: "compaction_start", reason: "manual" });
|
|
1616
|
+
let fromExtension = false;
|
|
1371
1617
|
try {
|
|
1372
1618
|
if (!this.model) {
|
|
1373
1619
|
throw new Error(formatNoModelSelectedMessage());
|
|
@@ -1385,7 +1631,6 @@ export class AgentSession {
|
|
|
1385
1631
|
throw new Error("Nothing to compact (session too small)");
|
|
1386
1632
|
}
|
|
1387
1633
|
let extensionCompaction;
|
|
1388
|
-
let fromExtension = false;
|
|
1389
1634
|
if (this._extensionRunner.hasHandlers("session_before_compact")) {
|
|
1390
1635
|
const result = (await this._extensionRunner.emit({
|
|
1391
1636
|
type: "session_before_compact",
|
|
@@ -1418,8 +1663,8 @@ export class AgentSession {
|
|
|
1418
1663
|
details = extensionCompaction.details;
|
|
1419
1664
|
}
|
|
1420
1665
|
else {
|
|
1421
|
-
//
|
|
1422
|
-
const result = await
|
|
1666
|
+
// Shared default summary generator, also used by automatic compaction.
|
|
1667
|
+
const result = await this._runDefaultCompaction(preparation, requestModel, apiKey, headers, customInstructions, this._compactionAbortController.signal, env, "manual");
|
|
1423
1668
|
summary = result.summary;
|
|
1424
1669
|
firstKeptEntryId = result.firstKeptEntryId;
|
|
1425
1670
|
tokensBefore = result.tokensBefore;
|
|
@@ -1467,6 +1712,7 @@ export class AgentSession {
|
|
|
1467
1712
|
catch (error) {
|
|
1468
1713
|
const message = error instanceof Error ? error.message : String(error);
|
|
1469
1714
|
const aborted = message === "Compaction cancelled" || (error instanceof Error && error.name === "AbortError");
|
|
1715
|
+
const errorMessage = aborted ? undefined : `Compaction failed: ${message}`;
|
|
1470
1716
|
this._compactionAbortController = undefined;
|
|
1471
1717
|
this._emit({
|
|
1472
1718
|
type: "compaction_end",
|
|
@@ -1474,7 +1720,14 @@ export class AgentSession {
|
|
|
1474
1720
|
result: undefined,
|
|
1475
1721
|
aborted,
|
|
1476
1722
|
willRetry: false,
|
|
1477
|
-
errorMessage
|
|
1723
|
+
errorMessage,
|
|
1724
|
+
});
|
|
1725
|
+
await this._emitSessionCompactFailed({
|
|
1726
|
+
reason: "manual",
|
|
1727
|
+
errorMessage,
|
|
1728
|
+
aborted,
|
|
1729
|
+
willRetry: false,
|
|
1730
|
+
fromExtension,
|
|
1478
1731
|
});
|
|
1479
1732
|
throw error;
|
|
1480
1733
|
}
|
|
@@ -1496,16 +1749,25 @@ export class AgentSession {
|
|
|
1496
1749
|
this._branchSummaryAbortController?.abort();
|
|
1497
1750
|
}
|
|
1498
1751
|
/**
|
|
1499
|
-
*
|
|
1500
|
-
*
|
|
1752
|
+
* Dispatch automatic compaction after `agent_end` or before prompt submission.
|
|
1753
|
+
* Manual compaction does not call this method; it enters through `compact()`.
|
|
1501
1754
|
*
|
|
1502
|
-
*
|
|
1503
|
-
* 1.
|
|
1504
|
-
* remove the assistant message, compact, and
|
|
1505
|
-
* 2.
|
|
1755
|
+
* Automatic cases:
|
|
1756
|
+
* 1. Overflow with retry: a context-overflow error or recoverable length stop;
|
|
1757
|
+
* remove the failed assistant message, compact, and retry the turn once.
|
|
1758
|
+
* 2. Overflow without retry: a successful response exceeded the configured
|
|
1759
|
+
* context window; compact but preserve the completed response.
|
|
1760
|
+
* 3. Threshold without retry: valid or estimated context usage crossed the
|
|
1761
|
+
* configured threshold; compact without retrying the completed response.
|
|
1762
|
+
*
|
|
1763
|
+
* Each case calls `_runAutoCompaction()`. After preparation and the
|
|
1764
|
+
* `session_before_compact` hook, that method calls the lower-level `compact()`
|
|
1765
|
+
* function imported from `./compaction/index.ts`, unless the hook cancels or
|
|
1766
|
+
* supplies a custom result.
|
|
1506
1767
|
*
|
|
1507
1768
|
* @param assistantMessage The assistant message to check
|
|
1508
1769
|
* @param skipAbortedCheck If false, include aborted messages (for pre-prompt check). Default: true
|
|
1770
|
+
* @returns Whether the post-run loop should call `agent.continue()` for overflow recovery or queued messages
|
|
1509
1771
|
*/
|
|
1510
1772
|
async _checkCompaction(assistantMessage, skipAbortedCheck = true) {
|
|
1511
1773
|
const settings = this.settingsManager.getCompactionSettings();
|
|
@@ -1528,38 +1790,49 @@ export class AgentSession {
|
|
|
1528
1790
|
if (assistantIsFromBeforeCompaction) {
|
|
1529
1791
|
return false;
|
|
1530
1792
|
}
|
|
1531
|
-
//
|
|
1793
|
+
// Automatic cases 1 and 2: context overflow.
|
|
1532
1794
|
// A length stop is recoverable when output ended below the model's original desired limit,
|
|
1533
1795
|
// independent of the configured context size or any context-clamped provider request limit.
|
|
1534
|
-
|
|
1535
|
-
// assistant answer already completed and agent.continue() cannot continue from an assistant.
|
|
1796
|
+
const contextOverflow = sameModel && isContextOverflow(assistantMessage, contextWindow);
|
|
1536
1797
|
const recoverableLength = sameModel && isRecoverableLength(assistantMessage, this.model?.maxTokens ?? 0);
|
|
1537
|
-
if (
|
|
1798
|
+
if (contextOverflow || recoverableLength) {
|
|
1538
1799
|
const willRetry = assistantMessage.stopReason !== "stop";
|
|
1800
|
+
// Case 2: the response completed successfully. Compact, but do not retry because
|
|
1801
|
+
// agent.continue() cannot continue from a completed assistant response.
|
|
1539
1802
|
if (!willRetry) {
|
|
1540
1803
|
return await this._runAutoCompaction("overflow", false);
|
|
1541
1804
|
}
|
|
1542
1805
|
if (this._overflowRecoveryAttempted) {
|
|
1806
|
+
const errorMessage = contextOverflow
|
|
1807
|
+
? "Context overflow recovery failed after one compact-and-retry attempt. Try reducing context or switching to a larger-context model."
|
|
1808
|
+
: "Truncated response recovery failed after one compact-and-retry attempt.";
|
|
1543
1809
|
this._emit({
|
|
1544
1810
|
type: "compaction_end",
|
|
1545
1811
|
reason: "overflow",
|
|
1546
1812
|
result: undefined,
|
|
1547
1813
|
aborted: false,
|
|
1548
1814
|
willRetry: false,
|
|
1549
|
-
errorMessage
|
|
1815
|
+
errorMessage,
|
|
1816
|
+
});
|
|
1817
|
+
await this._emitSessionCompactFailed({
|
|
1818
|
+
reason: "overflow",
|
|
1819
|
+
errorMessage,
|
|
1820
|
+
aborted: false,
|
|
1821
|
+
willRetry: false,
|
|
1822
|
+
fromExtension: false,
|
|
1550
1823
|
});
|
|
1551
1824
|
return false;
|
|
1552
1825
|
}
|
|
1826
|
+
// Case 1: remove the failed or truncated message from agent state, compact, and
|
|
1827
|
+
// retry once. The message remains in session history but is excluded from retry context.
|
|
1553
1828
|
this._overflowRecoveryAttempted = true;
|
|
1554
|
-
// Remove the failed or truncated message from agent state. It remains in session history,
|
|
1555
|
-
// but must not be included in the compact-and-retry context.
|
|
1556
1829
|
const messages = this.agent.state.messages;
|
|
1557
1830
|
if (messages.length > 0 && messages[messages.length - 1].role === "assistant") {
|
|
1558
1831
|
this.agent.state.messages = messages.slice(0, -1);
|
|
1559
1832
|
}
|
|
1560
1833
|
return await this._runAutoCompaction("overflow", willRetry);
|
|
1561
1834
|
}
|
|
1562
|
-
// Case
|
|
1835
|
+
// Case 3: threshold compaction without retry.
|
|
1563
1836
|
// For error messages or all-zero usage messages, estimate from the last valid response.
|
|
1564
1837
|
// This ensures sessions that hit persistent API errors (e.g. 529) or malformed zero-usage
|
|
1565
1838
|
// responses can still compact and do not reset context accounting.
|
|
@@ -1568,16 +1841,18 @@ export class AgentSession {
|
|
|
1568
1841
|
if (assistantMessage.stopReason === "error" || directContextTokens === 0) {
|
|
1569
1842
|
const messages = this.agent.state.messages;
|
|
1570
1843
|
const estimate = estimateContextTokens(messages);
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1844
|
+
// Without provider usage, estimate.tokens is the pure message-size estimate.
|
|
1845
|
+
// Only usage-backed estimates need the stale pre-compaction check.
|
|
1846
|
+
if (estimate.lastUsageIndex !== null) {
|
|
1847
|
+
// Verify the usage source is post-compaction. Kept pre-compaction messages
|
|
1848
|
+
// have stale usage reflecting the old (larger) context and would falsely
|
|
1849
|
+
// trigger compaction right after one just finished.
|
|
1850
|
+
const usageMsg = messages[estimate.lastUsageIndex];
|
|
1851
|
+
if (compactionEntry &&
|
|
1852
|
+
usageMsg.role === "assistant" &&
|
|
1853
|
+
usageMsg.timestamp <= new Date(compactionEntry.timestamp).getTime()) {
|
|
1854
|
+
return false;
|
|
1855
|
+
}
|
|
1581
1856
|
}
|
|
1582
1857
|
contextTokens = estimate.tokens;
|
|
1583
1858
|
}
|
|
@@ -1590,11 +1865,19 @@ export class AgentSession {
|
|
|
1590
1865
|
return false;
|
|
1591
1866
|
}
|
|
1592
1867
|
/**
|
|
1593
|
-
*
|
|
1868
|
+
* Execute threshold or overflow compaction. Manual compaction uses
|
|
1869
|
+
* `AgentSession.compact()` instead. Both paths call the lower-level `compact()`
|
|
1870
|
+
* function imported from `./compaction/index.ts` after preparation and extension
|
|
1871
|
+
* interception.
|
|
1872
|
+
*
|
|
1873
|
+
* @param reason Automatic trigger selected by `_checkCompaction()`
|
|
1874
|
+
* @param willRetry Whether to continue the interrupted turn after overflow compaction
|
|
1875
|
+
* @returns Whether the post-run loop should call `agent.continue()`
|
|
1594
1876
|
*/
|
|
1595
1877
|
async _runAutoCompaction(reason, willRetry) {
|
|
1596
1878
|
const settings = this.settingsManager.getCompactionSettings();
|
|
1597
1879
|
let started = false;
|
|
1880
|
+
let fromExtension = false;
|
|
1598
1881
|
try {
|
|
1599
1882
|
if (!this.model) {
|
|
1600
1883
|
return false;
|
|
@@ -1609,7 +1892,6 @@ export class AgentSession {
|
|
|
1609
1892
|
this._autoCompactionAbortController = new AbortController();
|
|
1610
1893
|
started = true;
|
|
1611
1894
|
let extensionCompaction;
|
|
1612
|
-
let fromExtension = false;
|
|
1613
1895
|
if (this._extensionRunner.hasHandlers("session_before_compact")) {
|
|
1614
1896
|
const extensionResult = (await this._extensionRunner.emit({
|
|
1615
1897
|
type: "session_before_compact",
|
|
@@ -1628,6 +1910,12 @@ export class AgentSession {
|
|
|
1628
1910
|
aborted: true,
|
|
1629
1911
|
willRetry: false,
|
|
1630
1912
|
});
|
|
1913
|
+
await this._emitSessionCompactFailed({
|
|
1914
|
+
reason,
|
|
1915
|
+
aborted: true,
|
|
1916
|
+
willRetry: false,
|
|
1917
|
+
fromExtension: false,
|
|
1918
|
+
});
|
|
1631
1919
|
return false;
|
|
1632
1920
|
}
|
|
1633
1921
|
if (extensionResult?.compaction) {
|
|
@@ -1649,8 +1937,8 @@ export class AgentSession {
|
|
|
1649
1937
|
details = extensionCompaction.details;
|
|
1650
1938
|
}
|
|
1651
1939
|
else {
|
|
1652
|
-
//
|
|
1653
|
-
const compactResult = await
|
|
1940
|
+
// Shared default summary generator, also used by manual compaction.
|
|
1941
|
+
const compactResult = await this._runDefaultCompaction(preparation, requestModel, apiKey, headers, undefined, this._autoCompactionAbortController.signal, env, reason);
|
|
1654
1942
|
summary = compactResult.summary;
|
|
1655
1943
|
firstKeptEntryId = compactResult.firstKeptEntryId;
|
|
1656
1944
|
tokensBefore = compactResult.tokensBefore;
|
|
@@ -1665,6 +1953,12 @@ export class AgentSession {
|
|
|
1665
1953
|
aborted: true,
|
|
1666
1954
|
willRetry: false,
|
|
1667
1955
|
});
|
|
1956
|
+
await this._emitSessionCompactFailed({
|
|
1957
|
+
reason,
|
|
1958
|
+
aborted: true,
|
|
1959
|
+
willRetry: false,
|
|
1960
|
+
fromExtension,
|
|
1961
|
+
});
|
|
1668
1962
|
return false;
|
|
1669
1963
|
}
|
|
1670
1964
|
this.sessionManager.appendCompaction(summary, firstKeptEntryId, tokensBefore, details, fromExtension, usage);
|
|
@@ -1711,15 +2005,23 @@ export class AgentSession {
|
|
|
1711
2005
|
catch (error) {
|
|
1712
2006
|
const errorMessage = error instanceof Error ? error.message : "compaction failed";
|
|
1713
2007
|
if (started) {
|
|
2008
|
+
const formattedErrorMessage = reason === "overflow"
|
|
2009
|
+
? `Context overflow recovery failed: ${errorMessage}`
|
|
2010
|
+
: `Auto-compaction failed: ${errorMessage}`;
|
|
1714
2011
|
this._emit({
|
|
1715
2012
|
type: "compaction_end",
|
|
1716
2013
|
reason,
|
|
1717
2014
|
result: undefined,
|
|
1718
2015
|
aborted: false,
|
|
1719
2016
|
willRetry: false,
|
|
1720
|
-
errorMessage:
|
|
1721
|
-
|
|
1722
|
-
|
|
2017
|
+
errorMessage: formattedErrorMessage,
|
|
2018
|
+
});
|
|
2019
|
+
await this._emitSessionCompactFailed({
|
|
2020
|
+
reason,
|
|
2021
|
+
errorMessage: formattedErrorMessage,
|
|
2022
|
+
aborted: false,
|
|
2023
|
+
willRetry: false,
|
|
2024
|
+
fromExtension,
|
|
1723
2025
|
});
|
|
1724
2026
|
}
|
|
1725
2027
|
return false;
|
|
@@ -1835,7 +2137,7 @@ export class AgentSession {
|
|
|
1835
2137
|
sourceInfo: template.sourceInfo,
|
|
1836
2138
|
}));
|
|
1837
2139
|
const skills = this._resourceLoader.getSkills().skills.map((skill) => ({
|
|
1838
|
-
name: `skill:${skill.name}`,
|
|
2140
|
+
name: `skill:${slugifySkillCommandName(skill.name)}`,
|
|
1839
2141
|
description: skill.description,
|
|
1840
2142
|
source: "skill",
|
|
1841
2143
|
sourceInfo: skill.sourceInfo,
|
|
@@ -2012,6 +2314,14 @@ export class AgentSession {
|
|
|
2012
2314
|
}
|
|
2013
2315
|
}
|
|
2014
2316
|
}
|
|
2317
|
+
const hasDeferredActiveTool = nextActiveToolNames.some((name) => {
|
|
2318
|
+
const contract = definitionRegistry.get(name)?.definition
|
|
2319
|
+
?.contract;
|
|
2320
|
+
return contract?.context.deferSchema === true;
|
|
2321
|
+
});
|
|
2322
|
+
if (hasDeferredActiveTool && this._toolRegistry.has("tool_schema")) {
|
|
2323
|
+
nextActiveToolNames.push("tool_schema");
|
|
2324
|
+
}
|
|
2015
2325
|
this.setActiveToolsByName([...new Set(nextActiveToolNames)]);
|
|
2016
2326
|
}
|
|
2017
2327
|
_buildRuntime(options) {
|
|
@@ -2026,7 +2336,34 @@ export class AgentSession {
|
|
|
2026
2336
|
: createAllToolDefinitions(this._cwd, {
|
|
2027
2337
|
read: { autoResizeImages },
|
|
2028
2338
|
bash: { commandPrefix: shellCommandPrefix, shellPath },
|
|
2339
|
+
edit: { diagnosticsOperations: this._diagnosticsOperations },
|
|
2340
|
+
write: { diagnosticsOperations: this._diagnosticsOperations },
|
|
2341
|
+
...(this._lspOperations ? { lsp: { operations: this._lspOperations } } : {}),
|
|
2342
|
+
...(this._mcpRuntime ? { mcp: this._mcpRuntime } : {}),
|
|
2343
|
+
...(this._webSearchOperations ? { web_search: { operations: this._webSearchOperations } } : {}),
|
|
2029
2344
|
});
|
|
2345
|
+
baseToolDefinitions.tool_schema = createToolSchemaToolDefinition({
|
|
2346
|
+
getTool: (name) => {
|
|
2347
|
+
if (!this.getActiveToolNames().includes(name))
|
|
2348
|
+
return undefined;
|
|
2349
|
+
const definition = this._toolDefinitions.get(name)?.definition;
|
|
2350
|
+
return definition ? { name: definition.name, parameters: definition.parameters } : undefined;
|
|
2351
|
+
},
|
|
2352
|
+
markLoaded: (name) => {
|
|
2353
|
+
this._loadedDeferredSchemas.add(name);
|
|
2354
|
+
},
|
|
2355
|
+
});
|
|
2356
|
+
baseToolDefinitions.todo_write = createTodoWriteToolDefinition({
|
|
2357
|
+
write: (todos) => {
|
|
2358
|
+
this.sessionManager.appendCustomEntry(TODO_CUSTOM_ENTRY_TYPE, todos);
|
|
2359
|
+
},
|
|
2360
|
+
});
|
|
2361
|
+
// Reads the resource loader live on every call (not a snapshot taken here), so
|
|
2362
|
+
// a project-trust change or a settings reload that alters the loaded skill set
|
|
2363
|
+
// is reflected on the next search without rebuilding the tool registry.
|
|
2364
|
+
baseToolDefinitions.skill_search = createSkillSearchToolDefinition({
|
|
2365
|
+
getSkills: () => this.resourceLoader.getSkills().skills,
|
|
2366
|
+
});
|
|
2030
2367
|
this._baseToolDefinitions = new Map(Object.entries(baseToolDefinitions).map(([name, tool]) => [name, tool]));
|
|
2031
2368
|
const extensionsResult = this._resourceLoader.getExtensions();
|
|
2032
2369
|
if (options.flagValues) {
|
|
@@ -2042,7 +2379,9 @@ export class AgentSession {
|
|
|
2042
2379
|
this._applyExtensionBindings(this._extensionRunner);
|
|
2043
2380
|
const defaultActiveToolNames = this._baseToolsOverride
|
|
2044
2381
|
? Object.keys(this._baseToolsOverride)
|
|
2045
|
-
:
|
|
2382
|
+
: this._lspOperations
|
|
2383
|
+
? ["read", "bash", "edit", "write", "lsp"]
|
|
2384
|
+
: ["read", "bash", "edit", "write"];
|
|
2046
2385
|
const baseActiveToolNames = options.activeToolNames ?? defaultActiveToolNames;
|
|
2047
2386
|
this._refreshToolRegistry({
|
|
2048
2387
|
activeToolNames: baseActiveToolNames,
|
|
@@ -2583,11 +2922,11 @@ export class AgentSession {
|
|
|
2583
2922
|
/**
|
|
2584
2923
|
* Export session to HTML.
|
|
2585
2924
|
* @param outputPath Optional output path (defaults to session directory)
|
|
2925
|
+
* @param options Optional export presentation settings
|
|
2586
2926
|
* @returns Path to exported file
|
|
2587
2927
|
*/
|
|
2588
|
-
async exportToHtml(outputPath) {
|
|
2589
|
-
const
|
|
2590
|
-
const themeName = configuredThemeName && getThemeByName(configuredThemeName) ? configuredThemeName : undefined;
|
|
2928
|
+
async exportToHtml(outputPath, options = {}) {
|
|
2929
|
+
const themeName = [options.themeName, this.settingsManager.getTheme()].find((candidate) => candidate !== undefined && getThemeByName(candidate) !== undefined);
|
|
2591
2930
|
// Create tool renderer if we have an extension runner (for custom tool HTML rendering)
|
|
2592
2931
|
const toolRenderer = createToolHtmlRenderer({
|
|
2593
2932
|
getToolDefinition: (name) => this.getToolDefinition(name),
|
|
@@ -2607,29 +2946,7 @@ export class AgentSession {
|
|
|
2607
2946
|
* @returns The resolved output file path.
|
|
2608
2947
|
*/
|
|
2609
2948
|
exportToJsonl(outputPath) {
|
|
2610
|
-
|
|
2611
|
-
const dir = dirname(filePath);
|
|
2612
|
-
if (!existsSync(dir)) {
|
|
2613
|
-
mkdirSync(dir, { recursive: true });
|
|
2614
|
-
}
|
|
2615
|
-
const header = {
|
|
2616
|
-
type: "session",
|
|
2617
|
-
version: CURRENT_SESSION_VERSION,
|
|
2618
|
-
id: this.sessionManager.getSessionId(),
|
|
2619
|
-
timestamp: new Date().toISOString(),
|
|
2620
|
-
cwd: this.sessionManager.getCwd(),
|
|
2621
|
-
};
|
|
2622
|
-
const branchEntries = this.sessionManager.getBranch();
|
|
2623
|
-
const lines = [JSON.stringify(header)];
|
|
2624
|
-
// Re-chain parentIds to form a linear sequence
|
|
2625
|
-
let prevId = null;
|
|
2626
|
-
for (const entry of branchEntries) {
|
|
2627
|
-
const linear = { ...entry, parentId: prevId };
|
|
2628
|
-
lines.push(JSON.stringify(linear));
|
|
2629
|
-
prevId = entry.id;
|
|
2630
|
-
}
|
|
2631
|
-
writeFileSync(filePath, `${lines.join("\n")}\n`);
|
|
2632
|
-
return filePath;
|
|
2949
|
+
return exportSessionToJsonl(this.sessionManager, outputPath);
|
|
2633
2950
|
}
|
|
2634
2951
|
// =========================================================================
|
|
2635
2952
|
// Utilities
|