@prestyj/cli 5.32.2 → 5.33.0
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/assets/motion/skills/motion/SKILL.md +1 -1
- package/assets/skills/bulletproof/SKILL.md +72 -131
- package/assets/skills/bulletproof/references/agent-surface.md +22 -1
- package/assets/skills/bulletproof/references/audit-protocol.md +23 -6
- package/assets/skills/bulletproof/references/platform-playbooks.md +12 -0
- package/assets/skills/bulletproof/references/provenance.md +19 -2
- package/assets/skills/bulletproof/references/secure-defaults.md +13 -1
- package/assets/skills/bulletproof/references/supply-chain.md +8 -5
- package/assets/skills/bulletproof/references/threat-landscape.md +46 -57
- package/assets/skills/compliance-guard/SKILL.md +59 -212
- package/assets/skills/compliance-guard/references/artifacts.md +14 -1
- package/assets/skills/compliance-guard/references/eu-uk.md +17 -7
- package/assets/skills/compliance-guard/references/exposure-triage.md +16 -0
- package/assets/skills/compliance-guard/references/full-review.md +155 -0
- package/assets/skills/compliance-guard/references/lawsuit-vectors.md +14 -2
- package/assets/skills/compliance-guard/references/provenance.md +33 -2
- package/assets/skills/compliance-guard/references/sector-gates.md +15 -1
- package/assets/skills/compliance-guard/references/security-baseline.md +21 -34
- package/assets/skills/compliance-guard/references/trigger-map.md +15 -1
- package/assets/skills/compliance-guard/references/us.md +32 -8
- package/assets/skills/durable/SKILL.md +22 -29
- package/assets/skills/durable/references/agent-db-safety.md +2 -2
- package/assets/skills/durable/references/backups-and-runtime.md +6 -6
- package/assets/skills/durable/references/migrations-and-schema.md +5 -4
- package/assets/skills/lean/SKILL.md +36 -50
- package/assets/skills/lean/references/playbooks.md +9 -7
- package/dist/app-sidecar/app-settings.d.ts +5 -0
- package/dist/app-sidecar/app-settings.js +13 -0
- package/dist/app-sidecar/app-settings.js.map +1 -1
- package/dist/app-sidecar/auth-routes.js +45 -2
- package/dist/app-sidecar/auth-routes.js.map +1 -1
- package/dist/app-sidecar/desktop-guidance.d.ts +1 -0
- package/dist/app-sidecar/desktop-guidance.js +27 -0
- package/dist/app-sidecar/desktop-guidance.js.map +1 -0
- package/dist/app-sidecar/history-routes.d.ts +6 -0
- package/dist/app-sidecar/history-routes.js +57 -2
- package/dist/app-sidecar/history-routes.js.map +1 -1
- package/dist/app-sidecar/history.d.ts +17 -0
- package/dist/app-sidecar/history.js.map +1 -1
- package/dist/app-sidecar/http.d.ts +1 -1
- package/dist/app-sidecar/http.js +2 -2
- package/dist/app-sidecar/http.js.map +1 -1
- package/dist/app-sidecar/integration-routes.js +4 -0
- package/dist/app-sidecar/integration-routes.js.map +1 -1
- package/dist/app-sidecar/prompt-routes.js +28 -5
- package/dist/app-sidecar/prompt-routes.js.map +1 -1
- package/dist/app-sidecar/route-context.d.ts +10 -1
- package/dist/app-sidecar/run-control-routes.js +9 -2
- package/dist/app-sidecar/run-control-routes.js.map +1 -1
- package/dist/app-sidecar/session-routes.js +8 -0
- package/dist/app-sidecar/session-routes.js.map +1 -1
- package/dist/app-sidecar/shell-routes.d.ts +12 -0
- package/dist/app-sidecar/shell-routes.js +133 -0
- package/dist/app-sidecar/shell-routes.js.map +1 -0
- package/dist/app-sidecar/shell-runs.d.ts +103 -0
- package/dist/app-sidecar/shell-runs.js +268 -0
- package/dist/app-sidecar/shell-runs.js.map +1 -0
- package/dist/app-sidecar/shell-suggestions.d.ts +33 -0
- package/dist/app-sidecar/shell-suggestions.js +152 -0
- package/dist/app-sidecar/shell-suggestions.js.map +1 -0
- package/dist/app-sidecar/usage.js +26 -2
- package/dist/app-sidecar/usage.js.map +1 -1
- package/dist/app-sidecar-sessions.js +13 -3
- package/dist/app-sidecar-sessions.js.map +1 -1
- package/dist/app-sidecar.js +231 -60
- package/dist/app-sidecar.js.map +1 -1
- package/dist/chat-agents/index.d.ts +1 -1
- package/dist/chat-agents/index.js +1 -1
- package/dist/chat-agents/index.js.map +1 -1
- package/dist/chat-agents/shared.d.ts +4 -0
- package/dist/chat-agents/shared.js +8 -1
- package/dist/chat-agents/shared.js.map +1 -1
- package/dist/cli.js +28 -6
- package/dist/cli.js.map +1 -1
- package/dist/config.d.ts +22 -2
- package/dist/config.js +40 -97
- package/dist/config.js.map +1 -1
- package/dist/core/agent-session.d.ts +100 -11
- package/dist/core/agent-session.js +734 -165
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/ask-user.d.ts +6 -0
- package/dist/core/ask-user.js +20 -5
- package/dist/core/ask-user.js.map +1 -1
- package/dist/core/autopilot-gate.js +2 -3
- package/dist/core/autopilot-gate.js.map +1 -1
- package/dist/core/bundled-agents.js +9 -29
- package/dist/core/bundled-agents.js.map +1 -1
- package/dist/core/cache-diagnostics.d.ts +4 -0
- package/dist/core/cache-diagnostics.js +4 -1
- package/dist/core/cache-diagnostics.js.map +1 -1
- package/dist/core/cache-expiry.d.ts +2 -0
- package/dist/core/cache-expiry.js +6 -0
- package/dist/core/cache-expiry.js.map +1 -1
- package/dist/core/checklist-items.d.ts +0 -8
- package/dist/core/checklist-items.js +0 -8
- package/dist/core/checklist-items.js.map +1 -1
- package/dist/core/checkpoint-store.d.ts +17 -0
- package/dist/core/checkpoint-store.js +72 -0
- package/dist/core/checkpoint-store.js.map +1 -1
- package/dist/core/claude-code/complete.d.ts +33 -0
- package/dist/core/claude-code/complete.js +112 -0
- package/dist/core/claude-code/complete.js.map +1 -0
- package/dist/core/claude-code/events.d.ts +65 -0
- package/dist/core/claude-code/events.js +434 -0
- package/dist/core/claude-code/events.js.map +1 -0
- package/dist/core/claude-code/live-session.d.ts +92 -0
- package/dist/core/claude-code/live-session.js +519 -0
- package/dist/core/claude-code/live-session.js.map +1 -0
- package/dist/core/claude-code/loop.d.ts +9 -0
- package/dist/core/claude-code/loop.js +15 -0
- package/dist/core/claude-code/loop.js.map +1 -0
- package/dist/core/claude-code/session-sync.d.ts +28 -0
- package/dist/core/claude-code/session-sync.js +53 -0
- package/dist/core/claude-code/session-sync.js.map +1 -0
- package/dist/core/claude-code/tool-bridge.d.ts +49 -0
- package/dist/core/claude-code/tool-bridge.js +352 -0
- package/dist/core/claude-code/tool-bridge.js.map +1 -0
- package/dist/core/claude-code-version.d.ts +1 -1
- package/dist/core/claude-code-version.js +1 -1
- package/dist/core/claude-code-version.js.map +1 -1
- package/dist/core/code-retrieval.d.ts +1 -1
- package/dist/core/code-retrieval.js +2 -2
- package/dist/core/code-retrieval.js.map +1 -1
- package/dist/core/compaction/compactor.d.ts +25 -1
- package/dist/core/compaction/compactor.js +137 -7
- package/dist/core/compaction/compactor.js.map +1 -1
- package/dist/core/compaction/policy.d.ts +18 -0
- package/dist/core/compaction/policy.js +24 -5
- package/dist/core/compaction/policy.js.map +1 -1
- package/dist/core/compaction/tool-result-pruner.d.ts +10 -0
- package/dist/core/compaction/tool-result-pruner.js +14 -0
- package/dist/core/compaction/tool-result-pruner.js.map +1 -1
- package/dist/core/env-delta.d.ts +3 -3
- package/dist/core/env-delta.js +4 -5
- package/dist/core/env-delta.js.map +1 -1
- package/dist/core/goals-store.d.ts +9 -0
- package/dist/core/goals-store.js +111 -50
- package/dist/core/goals-store.js.map +1 -1
- package/dist/core/internal-diagnostics.d.ts +17 -0
- package/dist/core/internal-diagnostics.js +45 -0
- package/dist/core/internal-diagnostics.js.map +1 -1
- package/dist/core/language-detector.d.ts +2 -3
- package/dist/core/language-detector.js.map +1 -1
- package/dist/core/local-endpoint-store.d.ts +4 -0
- package/dist/core/local-endpoint-store.js +31 -15
- package/dist/core/local-endpoint-store.js.map +1 -1
- package/dist/core/logger.d.ts +5 -0
- package/dist/core/logger.js +10 -2
- package/dist/core/logger.js.map +1 -1
- package/dist/core/lsp/edit-telemetry.js +3 -1
- package/dist/core/lsp/edit-telemetry.js.map +1 -1
- package/dist/core/lsp/manager.d.ts +15 -0
- package/dist/core/lsp/manager.js +31 -0
- package/dist/core/lsp/manager.js.map +1 -1
- package/dist/core/mcp/deferred-catalog.d.ts +1 -1
- package/dist/core/mcp/deferred-catalog.js +1 -1
- package/dist/core/openrouter-catalog-store.d.ts +24 -0
- package/dist/core/openrouter-catalog-store.js +140 -0
- package/dist/core/openrouter-catalog-store.js.map +1 -0
- package/dist/core/plan-delta.d.ts +23 -0
- package/dist/core/plan-delta.js +36 -0
- package/dist/core/plan-delta.js.map +1 -0
- package/dist/core/process-gate.d.ts +17 -0
- package/dist/core/process-gate.js +24 -0
- package/dist/core/process-gate.js.map +1 -1
- package/dist/core/project-discovery.js +2 -2
- package/dist/core/project-discovery.js.map +1 -1
- package/dist/core/project-files.js +1 -1
- package/dist/core/project-files.js.map +1 -1
- package/dist/core/prompt-commands.js +41 -75
- package/dist/core/prompt-commands.js.map +1 -1
- package/dist/core/radio-players.d.ts +28 -0
- package/dist/core/radio-players.js +133 -0
- package/dist/core/radio-players.js.map +1 -0
- package/dist/core/radio.js +20 -3
- package/dist/core/radio.js.map +1 -1
- package/dist/core/runtime-mode.d.ts +9 -0
- package/dist/core/runtime-mode.js +26 -0
- package/dist/core/runtime-mode.js.map +1 -1
- package/dist/core/session-history.d.ts +7 -0
- package/dist/core/session-history.js +34 -2
- package/dist/core/session-history.js.map +1 -1
- package/dist/core/session-manager.d.ts +5 -1
- package/dist/core/session-manager.js +36 -7
- package/dist/core/session-manager.js.map +1 -1
- package/dist/core/session-preview.js +2 -2
- package/dist/core/session-preview.js.map +1 -1
- package/dist/core/session-summary-index.d.ts +18 -4
- package/dist/core/session-summary-index.js +28 -8
- package/dist/core/session-summary-index.js.map +1 -1
- package/dist/core/settings-manager.d.ts +7 -0
- package/dist/core/settings-manager.js +53 -7
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/shell.d.ts +4 -0
- package/dist/core/shell.js +15 -1
- package/dist/core/shell.js.map +1 -1
- package/dist/core/skills.d.ts +8 -0
- package/dist/core/skills.js +15 -5
- package/dist/core/skills.js.map +1 -1
- package/dist/core/steering.d.ts +4 -0
- package/dist/core/steering.js +8 -1
- package/dist/core/steering.js.map +1 -1
- package/dist/core/stream-diag-level.d.ts +3 -0
- package/dist/core/stream-diag-level.js +24 -0
- package/dist/core/stream-diag-level.js.map +1 -0
- package/dist/core/subagent-manager.d.ts +11 -0
- package/dist/core/subagent-manager.js +16 -4
- package/dist/core/subagent-manager.js.map +1 -1
- package/dist/core/subagent-policy.d.ts +6 -0
- package/dist/core/subagent-policy.js +22 -3
- package/dist/core/subagent-policy.js.map +1 -1
- package/dist/core/subagent-receipt.d.ts +3 -3
- package/dist/core/subagent-receipt.js +6 -9
- package/dist/core/subagent-receipt.js.map +1 -1
- package/dist/core/trophies/catalog-more.js +16 -36
- package/dist/core/trophies/catalog-more.js.map +1 -1
- package/dist/core/trophies/engine.js +0 -4
- package/dist/core/trophies/engine.js.map +1 -1
- package/dist/core/trophies/types.d.ts +1 -1
- package/dist/core/trophies/types.js +0 -2
- package/dist/core/trophies/types.js.map +1 -1
- package/dist/core/user-shell-context.d.ts +8 -0
- package/dist/core/user-shell-context.js +12 -0
- package/dist/core/user-shell-context.js.map +1 -0
- package/dist/core/verify-commands.d.ts +1 -1
- package/dist/goals-agent/goal-team.js +3 -4
- package/dist/goals-agent/goal-team.js.map +1 -1
- package/dist/goals-agent/goals-agent.d.ts +1 -1
- package/dist/goals-agent/goals-agent.js +4 -3
- package/dist/goals-agent/goals-agent.js.map +1 -1
- package/dist/modes/acp-mode.d.ts +1 -1
- package/dist/modes/acp-mode.js +4 -5
- package/dist/modes/acp-mode.js.map +1 -1
- package/dist/modes/agent-home-mode.js +5 -5
- package/dist/modes/agent-home-mode.js.map +1 -1
- package/dist/modes/json-mode.js +5 -0
- package/dist/modes/json-mode.js.map +1 -1
- package/dist/modes/serve-mode.js +5 -5
- package/dist/modes/serve-mode.js.map +1 -1
- package/dist/motion-agent/motion-agent.d.ts +12 -5
- package/dist/motion-agent/motion-agent.js +24 -9
- package/dist/motion-agent/motion-agent.js.map +1 -1
- package/dist/subagent-entry.d.ts +1 -0
- package/dist/subagent-entry.js +50 -0
- package/dist/subagent-entry.js.map +1 -0
- package/dist/system-prompt.d.ts +6 -3
- package/dist/system-prompt.js +24 -15
- package/dist/system-prompt.js.map +1 -1
- package/dist/tools/ask-user.js +3 -2
- package/dist/tools/ask-user.js.map +1 -1
- package/dist/tools/bash.d.ts +7 -0
- package/dist/tools/bash.js +23 -8
- package/dist/tools/bash.js.map +1 -1
- package/dist/tools/checklist.js +6 -11
- package/dist/tools/checklist.js.map +1 -1
- package/dist/tools/debug.js +6 -9
- package/dist/tools/debug.js.map +1 -1
- package/dist/tools/document-text.d.ts +6 -0
- package/dist/tools/document-text.js +154 -0
- package/dist/tools/document-text.js.map +1 -0
- package/dist/tools/enter-plan.js +4 -7
- package/dist/tools/enter-plan.js.map +1 -1
- package/dist/tools/find.d.ts +9 -0
- package/dist/tools/find.js +38 -1
- package/dist/tools/find.js.map +1 -1
- package/dist/tools/generate-image.d.ts +18 -0
- package/dist/tools/generate-image.js +208 -17
- package/dist/tools/generate-image.js.map +1 -1
- package/dist/tools/goals.d.ts +2 -2
- package/dist/tools/index.d.ts +5 -2
- package/dist/tools/index.js +5 -13
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/operations.js +1 -1
- package/dist/tools/operations.js.map +1 -1
- package/dist/tools/overflow.d.ts +2 -0
- package/dist/tools/overflow.js +10 -0
- package/dist/tools/overflow.js.map +1 -1
- package/dist/tools/prompt-hints.d.ts +2 -0
- package/dist/tools/prompt-hints.js +16 -9
- package/dist/tools/prompt-hints.js.map +1 -1
- package/dist/tools/read.js +25 -10
- package/dist/tools/read.js.map +1 -1
- package/dist/tools/routine-output.d.ts +10 -1
- package/dist/tools/routine-output.js +79 -1
- package/dist/tools/routine-output.js.map +1 -1
- package/dist/tools/screenshot.js +6 -10
- package/dist/tools/screenshot.js.map +1 -1
- package/dist/tools/side-web-search.d.ts +35 -0
- package/dist/tools/side-web-search.js +147 -0
- package/dist/tools/side-web-search.js.map +1 -0
- package/dist/tools/skill.d.ts +2 -0
- package/dist/tools/skill.js +33 -6
- package/dist/tools/skill.js.map +1 -1
- package/dist/tools/steroids.d.ts +7 -6
- package/dist/tools/steroids.js +193 -87
- package/dist/tools/steroids.js.map +1 -1
- package/dist/tools/subagent-control.js +66 -10
- package/dist/tools/subagent-control.js.map +1 -1
- package/dist/tools/subagent-shared.d.ts +19 -2
- package/dist/tools/subagent-shared.js +35 -10
- package/dist/tools/subagent-shared.js.map +1 -1
- package/dist/tools/subagent.js +23 -7
- package/dist/tools/subagent.js.map +1 -1
- package/dist/tools/tool-search.js +7 -1
- package/dist/tools/tool-search.js.map +1 -1
- package/dist/tools/tool-tiers.d.ts +3 -2
- package/dist/tools/tool-tiers.js +7 -5
- package/dist/tools/tool-tiers.js.map +1 -1
- package/dist/tools/truncate.js +4 -8
- package/dist/tools/truncate.js.map +1 -1
- package/dist/tools/web-fetch.d.ts +8 -0
- package/dist/tools/web-fetch.js +123 -17
- package/dist/tools/web-fetch.js.map +1 -1
- package/dist/tools/web-search.d.ts +3 -2
- package/dist/tools/web-search.js +25 -1
- package/dist/tools/web-search.js.map +1 -1
- package/dist/ui/App.js +37 -37
- package/dist/ui/App.js.map +1 -1
- package/dist/ui/components/Footer.js +4 -1
- package/dist/ui/components/Footer.js.map +1 -1
- package/dist/ui/components/SkillsOverlay.js +2 -1
- package/dist/ui/components/SkillsOverlay.js.map +1 -1
- package/dist/ui/hooks/useAgentLoop.d.ts +3 -0
- package/dist/ui/hooks/useAgentLoop.js +54 -4
- package/dist/ui/hooks/useAgentLoop.js.map +1 -1
- package/dist/ui/hooks/useContextCompaction.js +1 -0
- package/dist/ui/hooks/useContextCompaction.js.map +1 -1
- package/dist/ui/language-pack-update.d.ts +25 -0
- package/dist/ui/language-pack-update.js +19 -0
- package/dist/ui/language-pack-update.js.map +1 -0
- package/dist/ui/terminal-history.js +3 -1
- package/dist/ui/terminal-history.js.map +1 -1
- package/dist/utils/http-body.d.ts +5 -0
- package/dist/utils/http-body.js +5 -0
- package/dist/utils/http-body.js.map +1 -1
- package/dist/utils/image.d.ts +11 -0
- package/dist/utils/image.js +34 -1
- package/dist/utils/image.js.map +1 -1
- package/dist/utils/plan-steps.d.ts +1 -0
- package/dist/utils/plan-steps.js +10 -0
- package/dist/utils/plan-steps.js.map +1 -1
- package/dist/utils/prompt-enhancer.d.ts +3 -1
- package/dist/utils/prompt-enhancer.js +21 -16
- package/dist/utils/prompt-enhancer.js.map +1 -1
- package/package.json +24 -7
- package/assets/skills/clarify/SKILL.md +0 -39
- package/assets/skills/code-review/SKILL.md +0 -88
- package/assets/skills/code-review/references/agent-diffs.md +0 -27
- package/assets/skills/code-review/references/tests.md +0 -19
- package/assets/skills/evidence-led-ui/LICENSES.md +0 -80
- package/assets/skills/evidence-led-ui/SKILL.md +0 -100
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/LICENSE +0 -21
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/airbnb/DESIGN.md +0 -545
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/airtable/DESIGN.md +0 -554
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/apple/DESIGN.md +0 -562
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/binance/DESIGN.md +0 -634
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/bmw/DESIGN.md +0 -544
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/bmw-m/DESIGN.md +0 -503
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/bugatti/DESIGN.md +0 -454
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/cal/DESIGN.md +0 -542
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/claude/DESIGN.md +0 -589
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/clay/DESIGN.md +0 -541
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/clickhouse/DESIGN.md +0 -544
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/cohere/DESIGN.md +0 -451
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/coinbase/DESIGN.md +0 -570
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/composio/DESIGN.md +0 -506
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/cursor/DESIGN.md +0 -537
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/dell-1996/DESIGN.md +0 -632
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/elevenlabs/DESIGN.md +0 -504
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/expo/DESIGN.md +0 -526
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/ferrari/DESIGN.md +0 -531
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/figma/DESIGN.md +0 -578
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/framer/DESIGN.md +0 -544
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/hashicorp/DESIGN.md +0 -575
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/hp/DESIGN.md +0 -670
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/ibm/DESIGN.md +0 -550
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/intercom/DESIGN.md +0 -546
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/kraken/DESIGN.md +0 -125
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/lamborghini/DESIGN.md +0 -288
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/linear.app/DESIGN.md +0 -548
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/lovable/DESIGN.md +0 -298
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/mastercard/DESIGN.md +0 -365
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/meta/DESIGN.md +0 -683
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/minimax/DESIGN.md +0 -746
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/mintlify/DESIGN.md +0 -852
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/miro/DESIGN.md +0 -825
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/mistral.ai/DESIGN.md +0 -773
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/mongodb/DESIGN.md +0 -767
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/nike/DESIGN.md +0 -575
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/nintendo-2001/DESIGN.md +0 -649
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/notion/DESIGN.md +0 -821
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/nvidia/DESIGN.md +0 -640
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/ollama/DESIGN.md +0 -539
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/opencode.ai/DESIGN.md +0 -521
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/pinterest/DESIGN.md +0 -597
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/playstation/DESIGN.md +0 -661
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/posthog/DESIGN.md +0 -690
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/raycast/DESIGN.md +0 -669
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/renault/DESIGN.md +0 -589
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/replicate/DESIGN.md +0 -616
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/resend/DESIGN.md +0 -585
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/revolut/DESIGN.md +0 -636
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/runwayml/DESIGN.md +0 -244
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/sanity/DESIGN.md +0 -357
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/sentry/DESIGN.md +0 -551
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/shopify/DESIGN.md +0 -516
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/slack/DESIGN.md +0 -482
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/spacex/DESIGN.md +0 -363
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/spotify/DESIGN.md +0 -246
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/starbucks/DESIGN.md +0 -580
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/stripe/DESIGN.md +0 -487
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/supabase/DESIGN.md +0 -462
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/superhuman/DESIGN.md +0 -448
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/tesla/DESIGN.md +0 -286
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/theverge/DESIGN.md +0 -339
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/together.ai/DESIGN.md +0 -633
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/uber/DESIGN.md +0 -636
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/vercel/DESIGN.md +0 -736
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/vodafone/DESIGN.md +0 -538
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/voltagent/DESIGN.md +0 -521
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/warp/DESIGN.md +0 -526
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/webflow/DESIGN.md +0 -588
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/wired/DESIGN.md +0 -497
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/wise/DESIGN.md +0 -544
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/x.ai/DESIGN.md +0 -465
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/zapier/DESIGN.md +0 -537
- package/assets/skills/evidence-led-ui/data/corpus-manifest.json +0 -768
- package/assets/skills/evidence-led-ui/data/observations.json +0 -47053
- package/assets/skills/evidence-led-ui/references/anti-defaults.md +0 -110
- package/assets/skills/evidence-led-ui/references/archetypes.md +0 -97
- package/assets/skills/evidence-led-ui/references/craft-rulings.md +0 -242
- package/assets/skills/evidence-led-ui/references/direction.md +0 -124
- package/assets/skills/evidence-led-ui/references/methodology.md +0 -72
- package/assets/skills/evidence-led-ui/references/observed-patterns.md +0 -68
- package/assets/skills/evidence-led-ui/references/production-contract.md +0 -148
- package/assets/skills/evidence-led-ui/references/provenance.md +0 -142
- package/assets/skills/evidence-led-ui/references/quality-rubric.md +0 -126
- package/assets/skills/evidence-led-ui/references/ui-libraries.md +0 -30
- package/assets/skills/refactoring/SKILL.md +0 -87
- package/assets/skills/refactoring/references/agent-pitfalls.md +0 -46
- package/assets/skills/refactoring/references/legacy.md +0 -70
- package/assets/skills/refactoring/references/smells.md +0 -71
- package/assets/skills/root-cause/SKILL.md +0 -46
- package/assets/skills/shared-language/SKILL.md +0 -32
- package/assets/skills/tdd/SKILL.md +0 -42
- package/dist/core/setup-history.d.ts +0 -6
- package/dist/core/setup-history.js +0 -55
- package/dist/core/setup-history.js.map +0 -1
- package/dist/core/style-packs/index.d.ts +0 -18
- package/dist/core/style-packs/index.js +0 -60
- package/dist/core/style-packs/index.js.map +0 -1
- package/dist/core/style-packs/packs.d.ts +0 -8
- package/dist/core/style-packs/packs.js +0 -188
- package/dist/core/style-packs/packs.js.map +0 -1
- package/dist/interactive.d.ts +0 -2
- package/dist/interactive.js +0 -257
- package/dist/interactive.js.map +0 -1
- package/dist/motion-agent/motion-review-coverage.d.ts +0 -12
- package/dist/motion-agent/motion-review-coverage.js +0 -33
- package/dist/motion-agent/motion-review-coverage.js.map +0 -1
- package/dist/motion-agent/motion-review-session.d.ts +0 -65
- package/dist/motion-agent/motion-review-session.js +0 -422
- package/dist/motion-agent/motion-review-session.js.map +0 -1
- package/dist/tools/code-nav.d.ts +0 -29
- package/dist/tools/code-nav.js +0 -299
- package/dist/tools/code-nav.js.map +0 -1
- package/dist/tools/code-skeleton.d.ts +0 -28
- package/dist/tools/code-skeleton.js +0 -115
- package/dist/tools/code-skeleton.js.map +0 -1
- package/dist/tools/search-code.d.ts +0 -10
- package/dist/tools/search-code.js +0 -90
- package/dist/tools/search-code.js.map +0 -1
- package/dist/ui/stores/index.d.ts +0 -2
- package/dist/ui/stores/index.js +0 -3
- package/dist/ui/stores/index.js.map +0 -1
- package/dist/utils/format.d.ts +0 -16
- package/dist/utils/format.js +0 -159
- package/dist/utils/format.js.map +0 -1
- package/dist/utils/shell.d.ts +0 -2
- package/dist/utils/shell.js +0 -8
- package/dist/utils/shell.js.map +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { agentLoop, isAbortError, isUsageLimitError, repairToolPairingAdjacent, } from "@prestyj/agent";
|
|
2
|
-
import { ProviderError, resolveToolSchema, stream, } from "@prestyj/ai";
|
|
2
|
+
import { ProviderError, resolveToolSchema, stream, preconnectProvider, } from "@prestyj/ai";
|
|
3
3
|
import { EventBus } from "./event-bus.js";
|
|
4
4
|
import { flagUntrustedToolResult } from "./injection-detect.js";
|
|
5
5
|
import { sameStamp, scanProjectLockfiles, stampProjectLockfiles, } from "./installed-threats.js";
|
|
@@ -14,7 +14,8 @@ import { expandPromptCommand } from "./prompt-command-expansion.js";
|
|
|
14
14
|
import { SettingsManager } from "./settings-manager.js";
|
|
15
15
|
import { AuthStorage, NotLoggedInError } from "./auth-storage.js";
|
|
16
16
|
import { dualAuthProvider } from "@prestyj/core";
|
|
17
|
-
import { getClaudeCliUserAgent
|
|
17
|
+
import { getClaudeCliUserAgent } from "./claude-code-version.js";
|
|
18
|
+
import { runSideWebSearch, runSideWebSearchViaClaudeCode, SIDE_SEARCH_MODEL, } from "../tools/side-web-search.js";
|
|
18
19
|
import { kimiCodingHeaders, isKimiCodingEndpoint } from "./oauth/kimi.js";
|
|
19
20
|
import { isGrokCliEndpoint } from "./oauth/xai.js";
|
|
20
21
|
import { SessionManager, } from "./session-manager.js";
|
|
@@ -22,14 +23,14 @@ import { ExtensionLoader } from "./extensions/loader.js";
|
|
|
22
23
|
import { shouldCompact, compact, } from "./compaction/compactor.js";
|
|
23
24
|
import { getHistoryMessageVisibility } from "./session-history.js";
|
|
24
25
|
import { sourceFingerprint as computeSourceFingerprint } from "./session-compaction.js";
|
|
25
|
-
import { getAuthStorageKeys, getContextWindow, getModel,
|
|
26
|
+
import { getAuthStorageKeys, getContextWindow, getListedModels, getModel, } from "./model-registry.js";
|
|
26
27
|
import { discoverSkillsWithBlocked } from "./skills.js";
|
|
27
28
|
import { ensureAppDirs } from "../config.js";
|
|
28
29
|
import { buildSubAgentSystemPrompt, buildSystemPrompt, } from "../system-prompt.js";
|
|
29
30
|
import { createTools, createWebSearchTool, } from "../tools/index.js";
|
|
30
31
|
import { partitionToolsByTier } from "../tools/tool-tiers.js";
|
|
31
32
|
import { formatImpactForVerification } from "./test-impact.js";
|
|
32
|
-
import { buildProcessCompletionFollowUp } from "./process-gate.js";
|
|
33
|
+
import { buildProcessCompletionFollowUp, mergeCompletionGateFollowUps } from "./process-gate.js";
|
|
33
34
|
import { PLAN_SUBMISSION_NUDGE, shouldNudgePlanSubmission } from "./plan-submission-gate.js";
|
|
34
35
|
import { buildSubAgentCompletionFollowUp, } from "./subagent-manager.js";
|
|
35
36
|
import { applyAsyncSubagentPolicy } from "./subagent-policy.js";
|
|
@@ -42,7 +43,7 @@ import { createSessionStatsTool } from "../tools/session-stats.js";
|
|
|
42
43
|
import { createDiagnoseCommand, isInternalDiagnosticsEnabled, SessionDiagnosticsRecorder, } from "./internal-diagnostics.js";
|
|
43
44
|
import { log } from "./logger.js";
|
|
44
45
|
import { CacheDiagnostics } from "./cache-diagnostics.js";
|
|
45
|
-
import { assessCacheExpiry, resolveCacheTtl } from "./cache-expiry.js";
|
|
46
|
+
import { assessCacheExpiry, CLAUDE_CODE_CACHE_TTL, resolveCacheTtl, } from "./cache-expiry.js";
|
|
46
47
|
import { setEstimatorModel, calibrateEstimatorFromUsage, estimateConversationTokens, } from "./compaction/token-estimator.js";
|
|
47
48
|
import { calculateActiveContextTokens } from "./compaction/active-context.js";
|
|
48
49
|
import { resolveCompactionPolicy } from "./compaction/policy.js";
|
|
@@ -50,14 +51,20 @@ import { decidePlanStepCompaction, DEFAULT_CACHE_WRITE_READ_RATIO, PLAN_STEP_KEE
|
|
|
50
51
|
import { extractPlanSteps, findCompletedMarkers } from "../utils/plan-steps.js";
|
|
51
52
|
import { readFileSync } from "node:fs";
|
|
52
53
|
import { clampThinkingForPlanMode } from "./thinking-level.js";
|
|
53
|
-
import { pruneStaleToolResults, shouldPruneToolResults } from "./compaction/tool-result-pruner.js";
|
|
54
|
+
import { pruneMinimumTokens, pruneStaleToolResults, shouldPruneToolResults, } from "./compaction/tool-result-pruner.js";
|
|
54
55
|
import { discoverAgents } from "./agents.js";
|
|
55
56
|
import { enhancePrompt } from "../utils/prompt-enhancer.js";
|
|
57
|
+
import { assistantText, renderTranscript } from "./claude-code/events.js";
|
|
58
|
+
import { ClaudeCodeLiveSession, systemPrompt } from "./claude-code/live-session.js";
|
|
59
|
+
import { CLAUDE_CODE_SEED_CHARS, CLAUDE_CODE_SESSION_KIND, claudeCodeResumeId, claudeCodeSessionEntryData, parseClaudeCodeSessionState, } from "./claude-code/session-sync.js";
|
|
60
|
+
import { claudeCodeComplete, resolveClaudeCodeProcess, } from "./claude-code/complete.js";
|
|
56
61
|
import { detectLanguages, detectProjectStack } from "./language-detector.js";
|
|
57
62
|
import { buildLoopBreakMessage } from "./loop-breaker.js";
|
|
58
63
|
import { buildRegroundingMessage, requestTextForRegrounding } from "./regrounding.js";
|
|
59
64
|
import { buildSemanticLoopJudgePrompt, buildSemanticLoopMessage, parseSemanticLoopVerdict, SEMANTIC_LOOP_JUDGE_TIMEOUT_MS, withJudgeTimeout, } from "./semantic-loop-check.js";
|
|
60
65
|
import { buildEnvDeltaMessage, buildLanguageUpdateMessage } from "./env-delta.js";
|
|
66
|
+
import { buildUserShellContextText } from "./user-shell-context.js";
|
|
67
|
+
import { buildPlanStateMessage, samePlanState } from "./plan-delta.js";
|
|
61
68
|
import { listProjectFiles } from "./project-files.js";
|
|
62
69
|
import { wrapSteeringText, buildNotificationSteeringText, buildIdleWakeNotificationText, STEERING_PREFIX, } from "./steering.js";
|
|
63
70
|
import { AgentNotificationQueue } from "./agent-notifications.js";
|
|
@@ -125,9 +132,46 @@ export class PaidModelConfirmationError extends Error {
|
|
|
125
132
|
export { resolveSessionToolResultCharLimit, resolveSessionTurnToolResultCharLimit, } from "./agent-session/helpers.js";
|
|
126
133
|
// ── Agent Session ──────────────────────────────────────────
|
|
127
134
|
/** A prompt that asks for the live web (see AgentSession.attachWebSearchIfAsked). */
|
|
135
|
+
/** True when the transcript holds a native (server-side) `web_search` call. */
|
|
136
|
+
export function historyUsesNativeWebSearch(messages) {
|
|
137
|
+
for (const message of messages) {
|
|
138
|
+
if (message.role !== "assistant" || !Array.isArray(message.content))
|
|
139
|
+
continue;
|
|
140
|
+
for (const part of message.content) {
|
|
141
|
+
if (part.type === "server_tool_call" && part.name === "web_search")
|
|
142
|
+
return true;
|
|
143
|
+
if (part.type === "raw") {
|
|
144
|
+
const data = part.data;
|
|
145
|
+
if (data?.type === "server_tool_use" && data.name === "web_search")
|
|
146
|
+
return true;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return false;
|
|
151
|
+
}
|
|
128
152
|
const WEB_INTENT = /\b(?:web|internet|online|google|googling|website|look (?:it |this |that )?up|(?:latest|newest|current) (?:version|release|news|docs?|documentation)|release notes|news)\b/i;
|
|
129
153
|
/** Distinct security rows one run may add to the chat (and session file). */
|
|
130
154
|
const MAX_SECURITY_ROWS_PER_RUN = 20;
|
|
155
|
+
/** How long dispose waits for a post-turn compaction before aborting it. */
|
|
156
|
+
export const DISPOSE_COMPACTION_WAIT_MS = 2_500;
|
|
157
|
+
/** Grace after aborting it, for the compaction to unwind. */
|
|
158
|
+
const DISPOSE_COMPACTION_ABORT_GRACE_MS = 500;
|
|
159
|
+
/** Resolves true if `promise` settles within `ms`, else false. Never rejects. */
|
|
160
|
+
async function settleWithin(promise, ms) {
|
|
161
|
+
let timer;
|
|
162
|
+
const timeout = new Promise((resolve) => {
|
|
163
|
+
timer = setTimeout(() => resolve(false), ms);
|
|
164
|
+
});
|
|
165
|
+
try {
|
|
166
|
+
return await Promise.race([
|
|
167
|
+
promise.then(() => true, () => true),
|
|
168
|
+
timeout,
|
|
169
|
+
]);
|
|
170
|
+
}
|
|
171
|
+
finally {
|
|
172
|
+
clearTimeout(timer);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
131
175
|
/**
|
|
132
176
|
* A chat row's target: first line, no control or bidi-override characters
|
|
133
177
|
* (they could make a command look like another), at most 120 chars.
|
|
@@ -221,6 +265,8 @@ export class AgentSession {
|
|
|
221
265
|
renderedEnvironment = {};
|
|
222
266
|
/** Project files as of the first prompt build (undefined until then). */
|
|
223
267
|
projectFiles;
|
|
268
|
+
/** `git ls-files` started at the top of initialize(), overlapping the rest of setup. */
|
|
269
|
+
projectFilesPending;
|
|
224
270
|
/** Wall-clock start of the current run; scopes the background-process gate. */
|
|
225
271
|
runStartedAt = 0;
|
|
226
272
|
/** Gate injections spent this run, capped by MAX_PROCESS_GATE_INJECTIONS. */
|
|
@@ -245,6 +291,8 @@ export class AgentSession {
|
|
|
245
291
|
compactionArmedForNextRun = false;
|
|
246
292
|
/** In-flight post-turn (background) compaction, if any. */
|
|
247
293
|
postTurnCompaction;
|
|
294
|
+
/** Aborts the in-flight post-turn compaction (dispose caps its wait). */
|
|
295
|
+
postTurnCompactionAbort;
|
|
248
296
|
lastCompactionCompacted = false;
|
|
249
297
|
compactionRetryAfter = 0;
|
|
250
298
|
/**
|
|
@@ -282,6 +330,11 @@ export class AgentSession {
|
|
|
282
330
|
// every turn boundary, so an index captured by the UI can point at a
|
|
283
331
|
// different message (or past the end) by the time the cancel arrives.
|
|
284
332
|
userQueue = [];
|
|
333
|
+
// Steering whose text the model already read in an ask_user result.
|
|
334
|
+
askAnswerSteering = new WeakSet();
|
|
335
|
+
// Taken into the run but not yet in the transcript. Claude Code takes queued
|
|
336
|
+
// messages at once but reads them at its next turn, so they still show as queued.
|
|
337
|
+
deliveringQueue = [];
|
|
285
338
|
queueSeq = 0;
|
|
286
339
|
/** Monotonic count of human-originated prompts; idle-wake budgets reset on it. */
|
|
287
340
|
humanPromptSeq = 0;
|
|
@@ -313,6 +366,10 @@ export class AgentSession {
|
|
|
313
366
|
* can discover and promote them; a promoted name drops out of this list.
|
|
314
367
|
*/
|
|
315
368
|
deferredBuiltinToolNames = [];
|
|
369
|
+
/** Deferred built-ins in tier order, fixed at session start. Sent as the
|
|
370
|
+
* provider's on-demand catalog (see @prestyj/ai `deferredTools`) so promoting one
|
|
371
|
+
* loads it through the transcript and the cached tools block stays put. */
|
|
372
|
+
deferredToolCatalog = [];
|
|
316
373
|
provider;
|
|
317
374
|
model;
|
|
318
375
|
cwd;
|
|
@@ -329,10 +386,18 @@ export class AgentSession {
|
|
|
329
386
|
agentPrompt;
|
|
330
387
|
/** Stable prompt prefix retained separately from the volatile uncached tail. */
|
|
331
388
|
baseSystemPrompt = "";
|
|
389
|
+
/** Plan state rendered into the cached system prompt. */
|
|
390
|
+
promptPlanState = { planMode: false, approvedPlanPath: undefined };
|
|
391
|
+
/** Plan state the model has been told (prompt or appended notice). */
|
|
392
|
+
seenPlanState = { planMode: false, approvedPlanPath: undefined };
|
|
393
|
+
/** Plan notice waiting for the next request, with the state it describes. */
|
|
394
|
+
pendingPlanNotice = null;
|
|
395
|
+
/** Latest plan notice appended — re-announced if compaction drops it. */
|
|
396
|
+
lastPlanNotice = null;
|
|
332
397
|
/**
|
|
333
|
-
* Project languages whose
|
|
334
|
-
*
|
|
335
|
-
*
|
|
398
|
+
* Project languages whose verify commands are in the standard prompt.
|
|
399
|
+
* Only ever grows within a session (same policy as the terminal UI): a
|
|
400
|
+
* section disappearing mid-task would rewrite the cached prefix
|
|
336
401
|
* for no benefit.
|
|
337
402
|
*/
|
|
338
403
|
activeLanguages = new Set();
|
|
@@ -379,6 +444,8 @@ export class AgentSession {
|
|
|
379
444
|
* dropped as out-of-range. Anchoring to the persisted prefix keeps resume
|
|
380
445
|
* placement 1:1 with where the row appeared live.
|
|
381
446
|
*/
|
|
447
|
+
/** Commands the user ran themselves, held until their next message. */
|
|
448
|
+
pendingUserShell = [];
|
|
382
449
|
persistedTranscriptCount() {
|
|
383
450
|
return this.messages.slice(0, this.lastPersistedIndex).filter((m) => m.role !== "system")
|
|
384
451
|
.length;
|
|
@@ -434,6 +501,12 @@ export class AgentSession {
|
|
|
434
501
|
// so it overlaps session setup and the user's typing instead.
|
|
435
502
|
if (this.provider === "anthropic")
|
|
436
503
|
void getClaudeCliUserAgent().catch(() => { });
|
|
504
|
+
// The prompt's file list is a `git ls-files` (~30 ms on a mid-size repo)
|
|
505
|
+
// that nothing before buildBasePrompt depends on: start it now so it runs
|
|
506
|
+
// alongside settings/auth/skills/tools instead of after them.
|
|
507
|
+
if (!this.customSystemPrompt && this.projectFiles === undefined) {
|
|
508
|
+
this.projectFilesPending = listProjectFiles(this.cwd);
|
|
509
|
+
}
|
|
437
510
|
const paths = await ensureAppDirs();
|
|
438
511
|
// Load settings & auth
|
|
439
512
|
this.settingsManager = new SettingsManager(paths.settingsFile);
|
|
@@ -444,7 +517,7 @@ export class AgentSession {
|
|
|
444
517
|
// Session manager. Agent-specific roots keep chat and coder histories isolated.
|
|
445
518
|
this.sessionManager = new SessionManager(this.opts.sessionRootDir ?? paths.sessionsDir);
|
|
446
519
|
const projectCustomization = this.opts.projectCustomization !== false;
|
|
447
|
-
// A real project folder: not Motion (own skills), not
|
|
520
|
+
// A real project folder: not Motion (own skills), not EZ Goals (goal notes
|
|
448
521
|
// folder, agentContext "none"), not chat (no project customization).
|
|
449
522
|
this.projectSession =
|
|
450
523
|
projectCustomization &&
|
|
@@ -462,6 +535,7 @@ export class AgentSession {
|
|
|
462
535
|
}
|
|
463
536
|
if (this.opts.skills) {
|
|
464
537
|
this.skills = [...this.opts.skills];
|
|
538
|
+
this.blockedSkills = [...(this.opts.blockedSkills ?? [])];
|
|
465
539
|
}
|
|
466
540
|
else if (projectCustomization) {
|
|
467
541
|
const discovery = await discoverSkillsWithBlocked({
|
|
@@ -503,6 +577,7 @@ export class AgentSession {
|
|
|
503
577
|
additionalRoots: this.additionalRoots,
|
|
504
578
|
}),
|
|
505
579
|
getPackageCooldownDays: () => this.settingsManager.get("packageCooldownDays"),
|
|
580
|
+
getBashPath: () => this.settingsManager.get("bashPath"),
|
|
506
581
|
getNetworkPolicy: () => ({
|
|
507
582
|
mode: this.settingsManager.get("networkMode"),
|
|
508
583
|
allow: this.settingsManager.get("networkAllow"),
|
|
@@ -521,6 +596,7 @@ export class AgentSession {
|
|
|
521
596
|
allowUnixSockets: this.settingsManager.get("sandboxAllowUnixSockets"),
|
|
522
597
|
}),
|
|
523
598
|
getUseExternalGrep: () => this.settingsManager.get("grepUseRipgrep"),
|
|
599
|
+
sideWebSearch: (request) => this.runSideWebSearch(request),
|
|
524
600
|
authStorage: this.authStorage,
|
|
525
601
|
onFileMutated: (filePath) => {
|
|
526
602
|
const relative = path.relative(this.cwd, filePath) || path.basename(filePath);
|
|
@@ -600,6 +676,7 @@ export class AgentSession {
|
|
|
600
676
|
// sits inside the cached prefix stays byte-stable across turns.
|
|
601
677
|
this.tools = core;
|
|
602
678
|
this.deferredBuiltinToolNames = deferred.map((t) => t.name);
|
|
679
|
+
this.deferredToolCatalog = [...deferred];
|
|
603
680
|
this.mcp.addDeferred(deferred);
|
|
604
681
|
}
|
|
605
682
|
}
|
|
@@ -734,6 +811,7 @@ export class AgentSession {
|
|
|
734
811
|
await this.extensionLoader.loadAll(paths.extensionsDir, extContext);
|
|
735
812
|
}
|
|
736
813
|
this.eventBus.emit("session_start", { sessionId: this.sessionId });
|
|
814
|
+
this.preconnect();
|
|
737
815
|
}
|
|
738
816
|
/**
|
|
739
817
|
* Whether a tool name is permitted for this session. With no `allowedTools`
|
|
@@ -865,7 +943,7 @@ export class AgentSession {
|
|
|
865
943
|
* Whether provider-native web search rides along with this request.
|
|
866
944
|
*
|
|
867
945
|
* Anthropic's `web_search_20250305` server tool costs ~2.5k prefix tokens on
|
|
868
|
-
* every request (count_tokens: 6,628 vs 4,098 for the
|
|
946
|
+
* every request (count_tokens: 6,628 vs 4,098 for the EZ Coder prefix without it),
|
|
869
947
|
* yet web search is reached in ~6% of sessions — the reason the client tool
|
|
870
948
|
* is deferred everywhere else. So on a tiered Anthropic session it is only
|
|
871
949
|
* attached once the model has promoted `web_search` (tool_search or a direct
|
|
@@ -875,9 +953,14 @@ export class AgentSession {
|
|
|
875
953
|
nativeWebSearchOn() {
|
|
876
954
|
if (this.provider !== "anthropic")
|
|
877
955
|
return true;
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
956
|
+
// Anthropic search runs inside the client web_search tool as a side
|
|
957
|
+
// request (runSideWebSearch): its result pages cost 11–20k cache-write
|
|
958
|
+
// tokens each in the main context. A restored, branched or compacted conversation can already hold native
|
|
959
|
+
// `web_search` blocks from when the tool was attached. Anthropic rejects
|
|
960
|
+
// any request whose history references a server tool that is not declared
|
|
961
|
+
// (400 "`server_tool_use` block references `web_search`…"), so the history
|
|
962
|
+
// itself keeps native search on.
|
|
963
|
+
return historyUsesNativeWebSearch(this.messages);
|
|
881
964
|
}
|
|
882
965
|
/**
|
|
883
966
|
* A human prompt that plainly asks for the web gets native web search from
|
|
@@ -888,7 +971,7 @@ export class AgentSession {
|
|
|
888
971
|
* one discovery turn, a false hit only the ~2.5k-token schema.
|
|
889
972
|
*/
|
|
890
973
|
attachWebSearchIfAsked(content) {
|
|
891
|
-
if (this.provider !== "anthropic" || this.
|
|
974
|
+
if (this.provider !== "anthropic" || this.tools.some((t) => t.name === "web_search"))
|
|
892
975
|
return;
|
|
893
976
|
const text = typeof content === "string"
|
|
894
977
|
? content
|
|
@@ -900,6 +983,240 @@ export class AgentSession {
|
|
|
900
983
|
if (WEB_INTENT.test(text))
|
|
901
984
|
this.promoteDeferredBuiltin("web_search");
|
|
902
985
|
}
|
|
986
|
+
async runSideWebSearch(request) {
|
|
987
|
+
if (this.provider !== "anthropic")
|
|
988
|
+
return null;
|
|
989
|
+
const claudeCode = await this.claudeCodeProcess();
|
|
990
|
+
if (claudeCode)
|
|
991
|
+
return await runSideWebSearchViaClaudeCode(request, claudeCode);
|
|
992
|
+
const creds = await this.authStorage.resolveCredentials("anthropic", {
|
|
993
|
+
storageKeys: getAuthStorageKeys("anthropic", SIDE_SEARCH_MODEL),
|
|
994
|
+
});
|
|
995
|
+
return await runSideWebSearch(request, {
|
|
996
|
+
apiKey: creds.accessToken,
|
|
997
|
+
baseUrl: this.baseUrl ?? creds.baseUrl,
|
|
998
|
+
userAgent: await getClaudeCliUserAgent(),
|
|
999
|
+
});
|
|
1000
|
+
}
|
|
1001
|
+
// No creds = Claude subscription route; compact() then summarizes through Claude Code.
|
|
1002
|
+
async maybeCompactPreRun(creds) {
|
|
1003
|
+
if (this.settingsManager.get("autoCompact") && Date.now() >= this.compactionRetryAfter) {
|
|
1004
|
+
// A post-turn compaction may still be running in the background. Let it
|
|
1005
|
+
// settle first: it usually already compacted this history, so the
|
|
1006
|
+
// decision below turns into a no-op instead of duplicate work.
|
|
1007
|
+
if (this.postTurnCompaction)
|
|
1008
|
+
await this.postTurnCompaction;
|
|
1009
|
+
const contextWindow = getContextWindow(this.model, {
|
|
1010
|
+
provider: this.provider,
|
|
1011
|
+
accountId: creds?.accountId,
|
|
1012
|
+
});
|
|
1013
|
+
const policy = resolveCompactionPolicy({
|
|
1014
|
+
provider: this.provider,
|
|
1015
|
+
model: this.model,
|
|
1016
|
+
contextWindow,
|
|
1017
|
+
threshold: this.settingsManager.get("compactThreshold"),
|
|
1018
|
+
compactAtTokens: this.settingsManager.get("compactAtTokens"),
|
|
1019
|
+
accountId: creds?.accountId,
|
|
1020
|
+
approvedPlanPath: this.approvedPlanPath,
|
|
1021
|
+
});
|
|
1022
|
+
let activeTokens;
|
|
1023
|
+
if (this.providerContext) {
|
|
1024
|
+
const anchorIndex = this.messages.lastIndexOf(this.providerContext.anchor);
|
|
1025
|
+
if (anchorIndex >= 0) {
|
|
1026
|
+
activeTokens = calculateActiveContextTokens(this.messages, {
|
|
1027
|
+
usage: this.providerContext.usage,
|
|
1028
|
+
pendingMessages: this.messages.slice(anchorIndex + 1),
|
|
1029
|
+
});
|
|
1030
|
+
}
|
|
1031
|
+
else {
|
|
1032
|
+
this.providerContext = null;
|
|
1033
|
+
}
|
|
1034
|
+
}
|
|
1035
|
+
log("INFO", "compaction", "Pre-run compaction decision", {
|
|
1036
|
+
provider: this.provider,
|
|
1037
|
+
model: this.model,
|
|
1038
|
+
transport: this.compactionTransport(creds),
|
|
1039
|
+
contextWindow: String(contextWindow),
|
|
1040
|
+
activeTokens: activeTokens === undefined ? "estimated" : String(activeTokens),
|
|
1041
|
+
triggerLimit: String(policy.targetTokens),
|
|
1042
|
+
});
|
|
1043
|
+
if (shouldCompact(this.messages, contextWindow, policy.threshold, activeTokens, policy.targetTokens)) {
|
|
1044
|
+
try {
|
|
1045
|
+
await this.compact(creds, "automatic");
|
|
1046
|
+
if (this.lastCompactionCompacted) {
|
|
1047
|
+
// Re-grounding hook keys off this — the context was just summarized.
|
|
1048
|
+
this.compactionOccurred = true;
|
|
1049
|
+
this.compactionRetryAfter = 0;
|
|
1050
|
+
}
|
|
1051
|
+
else {
|
|
1052
|
+
this.compactionRetryAfter = Date.now() + 30_000;
|
|
1053
|
+
}
|
|
1054
|
+
}
|
|
1055
|
+
catch (error) {
|
|
1056
|
+
this.compactionRetryAfter = Date.now() + 30_000;
|
|
1057
|
+
if (isAbortError(error) || this.opts.signal?.aborted)
|
|
1058
|
+
throw error;
|
|
1059
|
+
log("WARN", "compaction", `Pre-run compaction failed; cooling down for 30s: ${error instanceof Error ? error.message : String(error)}`);
|
|
1060
|
+
}
|
|
1061
|
+
}
|
|
1062
|
+
}
|
|
1063
|
+
}
|
|
1064
|
+
compactionTransport(creds) {
|
|
1065
|
+
if (!creds)
|
|
1066
|
+
return "claude_code";
|
|
1067
|
+
return this.provider === "openai" && creds.accountId ? "codex_oauth" : "public_api";
|
|
1068
|
+
}
|
|
1069
|
+
/** One run on the Claude subscription route: Claude Code drives the loop with our prompt and tools. */
|
|
1070
|
+
async runClaudeCodeLoop(process, options) {
|
|
1071
|
+
let loopMessages = await this.prepareDynamicContext();
|
|
1072
|
+
const resume = claudeCodeResumeId(this.claudeCodeSession, loopMessages);
|
|
1073
|
+
// A fresh Claude Code session gets our history as text; summarize it first
|
|
1074
|
+
// when it would not fit.
|
|
1075
|
+
if (!resume &&
|
|
1076
|
+
renderTranscript(loopMessages, Number.MAX_SAFE_INTEGER).length > CLAUDE_CODE_SEED_CHARS) {
|
|
1077
|
+
try {
|
|
1078
|
+
await this.compact(undefined, "automatic");
|
|
1079
|
+
}
|
|
1080
|
+
catch (error) {
|
|
1081
|
+
if (isAbortError(error) || this.opts.signal?.aborted)
|
|
1082
|
+
throw error;
|
|
1083
|
+
log("WARN", "compaction", "Summary before seeding Claude Code failed", {
|
|
1084
|
+
error: error instanceof Error ? error.message : String(error),
|
|
1085
|
+
});
|
|
1086
|
+
}
|
|
1087
|
+
loopMessages = await this.prepareDynamicContext();
|
|
1088
|
+
}
|
|
1089
|
+
let sessionId = resume;
|
|
1090
|
+
const title = this.sessionPreview?.trim().slice(0, 80);
|
|
1091
|
+
const thinking = this.planModeRef.current || options.capThinking
|
|
1092
|
+
? clampThinkingForPlanMode(this.thinkingLevel)
|
|
1093
|
+
: this.thinkingLevel;
|
|
1094
|
+
const live = await this.claudeCodeLiveFor(process, loopMessages, resume, thinking, options);
|
|
1095
|
+
const generator = live.run(loopMessages, {
|
|
1096
|
+
provider: this.provider,
|
|
1097
|
+
model: this.model,
|
|
1098
|
+
tools: options.disableTools ? [] : this.tools,
|
|
1099
|
+
maxTurns: this.opts.maxTurns,
|
|
1100
|
+
thinking,
|
|
1101
|
+
signal: this.opts.signal,
|
|
1102
|
+
maxToolResultChars: resolveSessionToolResultCharLimit(this.model, this.provider, undefined),
|
|
1103
|
+
transformToolResult: flagUntrustedToolResult,
|
|
1104
|
+
...(options.disableTools
|
|
1105
|
+
? {}
|
|
1106
|
+
: { resolveTool: (name) => this.promoteDeferredBuiltin(name) }),
|
|
1107
|
+
getSteeringMessages: () => this.getHookSteeringMessages(),
|
|
1108
|
+
steeringAlreadyRead: (message) => this.askAnswerSteering.has(message),
|
|
1109
|
+
onSteeringAvailable: (listener) => {
|
|
1110
|
+
this.steeringListeners.add(listener);
|
|
1111
|
+
return () => this.steeringListeners.delete(listener);
|
|
1112
|
+
},
|
|
1113
|
+
getFollowUpMessages: () => this.getHookFollowUpMessages(),
|
|
1114
|
+
claudeCode: {
|
|
1115
|
+
...process,
|
|
1116
|
+
maxSeedChars: CLAUDE_CODE_SEED_CHARS,
|
|
1117
|
+
...(resume ? { resume } : {}),
|
|
1118
|
+
...(title ? { title } : {}),
|
|
1119
|
+
onSessionId: (id) => {
|
|
1120
|
+
sessionId = id;
|
|
1121
|
+
},
|
|
1122
|
+
},
|
|
1123
|
+
});
|
|
1124
|
+
this.activeLoopMessages = loopMessages;
|
|
1125
|
+
try {
|
|
1126
|
+
for await (const event of generator) {
|
|
1127
|
+
await this.trackHookEvent(event);
|
|
1128
|
+
// Claude Code sends the requests, so the cache-diagnostics pass never
|
|
1129
|
+
// sees them; without a touch every idle chat read as an expired cache.
|
|
1130
|
+
if (event.type === "turn_end" && event.stopReason !== "error") {
|
|
1131
|
+
this.cacheDiagnostics.noteCacheTouch({
|
|
1132
|
+
at: Date.now(),
|
|
1133
|
+
provider: this.provider,
|
|
1134
|
+
model: this.model,
|
|
1135
|
+
policy: CLAUDE_CODE_CACHE_TTL,
|
|
1136
|
+
});
|
|
1137
|
+
}
|
|
1138
|
+
this.eventBus.forwardAgentEvent(event);
|
|
1139
|
+
}
|
|
1140
|
+
}
|
|
1141
|
+
finally {
|
|
1142
|
+
// The SDK counts maxTurns per process, so a capped session runs one process per run.
|
|
1143
|
+
if (live !== this.claudeCodeLive?.session)
|
|
1144
|
+
live.close("one-shot");
|
|
1145
|
+
this.activeLoopMessages = null;
|
|
1146
|
+
// A stopped run records unplaced messages without an event.
|
|
1147
|
+
this.settleDeliveredMessages(() => true);
|
|
1148
|
+
this.messages = loopMessages;
|
|
1149
|
+
for (let i = this.lastPersistedIndex; i < this.messages.length; i++) {
|
|
1150
|
+
await this.persistMessage(this.messages[i]);
|
|
1151
|
+
}
|
|
1152
|
+
this.lastPersistedIndex = this.messages.length;
|
|
1153
|
+
if (sessionId)
|
|
1154
|
+
await this.recordClaudeCodeSession(sessionId);
|
|
1155
|
+
}
|
|
1156
|
+
}
|
|
1157
|
+
/**
|
|
1158
|
+
* The Claude Code process for this run: the chat's live one when it holds
|
|
1159
|
+
* exactly our history with the same settings, else a new one (the old one is
|
|
1160
|
+
* closed first, so a chat never keeps two).
|
|
1161
|
+
*/
|
|
1162
|
+
async claudeCodeLiveFor(process, messages, resume, thinking, options) {
|
|
1163
|
+
const hash = (value) => crypto.createHash("sha256").update(JSON.stringify(value)).digest("hex").slice(0, 16);
|
|
1164
|
+
const key = {
|
|
1165
|
+
executable: process.executable,
|
|
1166
|
+
cwd: process.cwd,
|
|
1167
|
+
model: this.model,
|
|
1168
|
+
system: hash(systemPrompt(messages, undefined)),
|
|
1169
|
+
thinking: thinking ? "on" : "off",
|
|
1170
|
+
tools: options.disableTools ? "off" : "on",
|
|
1171
|
+
};
|
|
1172
|
+
// Per variable, so a restart log names what moved (names only, never values).
|
|
1173
|
+
for (const [name, value] of Object.entries(process.env)) {
|
|
1174
|
+
// The SDK writes this into the daemon's env on its first query(); it sets it for the child anyway.
|
|
1175
|
+
if (name !== "CLAUDE_AGENT_SDK_VERSION")
|
|
1176
|
+
key[`env:${name}`] = hash(value);
|
|
1177
|
+
}
|
|
1178
|
+
const current = this.claudeCodeLive;
|
|
1179
|
+
const changed = current
|
|
1180
|
+
? [...new Set([...Object.keys(key), ...Object.keys(current.key)])].filter((name) => current.key[name] !== key[name])
|
|
1181
|
+
: [];
|
|
1182
|
+
if (current &&
|
|
1183
|
+
changed.length === 0 &&
|
|
1184
|
+
current.session.alive &&
|
|
1185
|
+
!current.session.busy &&
|
|
1186
|
+
resume !== undefined &&
|
|
1187
|
+
resume === current.session.sessionId &&
|
|
1188
|
+
(await current.session.setEffort(thinking))) {
|
|
1189
|
+
return current.session;
|
|
1190
|
+
}
|
|
1191
|
+
this.closeClaudeCodeLive(changed.length > 0 ? `changed: ${changed.join(",")}` : "history or effort changed");
|
|
1192
|
+
const session = new ClaudeCodeLiveSession();
|
|
1193
|
+
if (!this.opts.maxTurns)
|
|
1194
|
+
this.claudeCodeLive = { session, key };
|
|
1195
|
+
return session;
|
|
1196
|
+
}
|
|
1197
|
+
closeClaudeCodeLive(reason) {
|
|
1198
|
+
this.claudeCodeLive?.session.close(reason);
|
|
1199
|
+
this.claudeCodeLive = null;
|
|
1200
|
+
}
|
|
1201
|
+
async recordClaudeCodeSession(sessionId) {
|
|
1202
|
+
const history = this.messages.filter((m) => m.role !== "system");
|
|
1203
|
+
const state = { sessionId, messageCount: history.length, anchor: history.at(-1) };
|
|
1204
|
+
this.claudeCodeSession = state;
|
|
1205
|
+
if (!this.sessionPath)
|
|
1206
|
+
return;
|
|
1207
|
+
await this.sessionManager.appendEntry(this.sessionPath, {
|
|
1208
|
+
type: "custom",
|
|
1209
|
+
kind: CLAUDE_CODE_SESSION_KIND,
|
|
1210
|
+
id: crypto.randomUUID(),
|
|
1211
|
+
parentId: null,
|
|
1212
|
+
timestamp: new Date().toISOString(),
|
|
1213
|
+
data: claudeCodeSessionEntryData(state),
|
|
1214
|
+
});
|
|
1215
|
+
}
|
|
1216
|
+
/** Claude Code settings when this session runs on a Claude subscription, else null. */
|
|
1217
|
+
claudeCodeProcess() {
|
|
1218
|
+
return resolveClaudeCodeProcess(this.authStorage, this.provider, this.cwd);
|
|
1219
|
+
}
|
|
903
1220
|
/** Append a deferred built-in to the live tool list (append-only). */
|
|
904
1221
|
promoteDeferredBuiltin(name) {
|
|
905
1222
|
if (!this.deferredBuiltinToolNames.includes(name))
|
|
@@ -923,8 +1240,17 @@ export class AgentSession {
|
|
|
923
1240
|
const result = await tool.execute(args, context);
|
|
924
1241
|
if (when(args)) {
|
|
925
1242
|
const missing = followUps.filter((name) => !this.tools.some((t) => t.name === name));
|
|
926
|
-
|
|
927
|
-
|
|
1243
|
+
const promoted = missing.length > 0 ? this.mcp.promote(missing) : [];
|
|
1244
|
+
if (promoted.length > 0) {
|
|
1245
|
+
this.tools.push(...promoted);
|
|
1246
|
+
// The trigger's result is where the follow-ups load (cache-safe
|
|
1247
|
+
// transports load them in the transcript, not the tools block).
|
|
1248
|
+
const structured = typeof result === "string" ? { content: result } : result;
|
|
1249
|
+
return {
|
|
1250
|
+
...structured,
|
|
1251
|
+
loadedTools: [...(structured.loadedTools ?? []), ...promoted.map((t) => t.name)],
|
|
1252
|
+
};
|
|
1253
|
+
}
|
|
928
1254
|
}
|
|
929
1255
|
return result;
|
|
930
1256
|
},
|
|
@@ -1001,6 +1327,8 @@ export class AgentSession {
|
|
|
1001
1327
|
// Prompt templates remain human-originated: the user invoked the command.
|
|
1002
1328
|
const userMessage = { role: "user", content: slash.fullPrompt, provenance };
|
|
1003
1329
|
await this.announceNewLanguages();
|
|
1330
|
+
if (provenance.source === "human")
|
|
1331
|
+
await this.deliverUserShellContext();
|
|
1004
1332
|
this.messages.push(userMessage);
|
|
1005
1333
|
await this.persistMessage(userMessage);
|
|
1006
1334
|
this.lastPersistedIndex = this.messages.length;
|
|
@@ -1018,6 +1346,8 @@ export class AgentSession {
|
|
|
1018
1346
|
// Push user message
|
|
1019
1347
|
const userMessage = { role: "user", content, provenance };
|
|
1020
1348
|
await this.announceNewLanguages();
|
|
1349
|
+
if (provenance.source === "human")
|
|
1350
|
+
await this.deliverUserShellContext();
|
|
1021
1351
|
this.messages.push(userMessage);
|
|
1022
1352
|
await this.persistMessage(userMessage);
|
|
1023
1353
|
this.lastPersistedIndex = this.messages.length;
|
|
@@ -1047,11 +1377,16 @@ export class AgentSession {
|
|
|
1047
1377
|
provenance: { source: "human", kind: "prompt", visibility: "transcript" },
|
|
1048
1378
|
};
|
|
1049
1379
|
await this.announceNewLanguages();
|
|
1380
|
+
await this.deliverUserShellContext();
|
|
1050
1381
|
this.messages.push(userMessage);
|
|
1051
1382
|
await this.persistMessage(userMessage);
|
|
1052
1383
|
this.lastPersistedIndex = this.messages.length;
|
|
1053
1384
|
await this.runLoop();
|
|
1054
1385
|
}
|
|
1386
|
+
/** A typed reply's attachments as blocks for the question it answers (ask_user). */
|
|
1387
|
+
askReplyAttachmentParts(attachments) {
|
|
1388
|
+
return this.buildAttachmentParts("", attachments);
|
|
1389
|
+
}
|
|
1055
1390
|
/**
|
|
1056
1391
|
* Build the native content blocks (text + image/video notes + file notes) for
|
|
1057
1392
|
* a user message with attachments. Shared by {@link promptWithAttachments} and
|
|
@@ -1116,12 +1451,24 @@ export class AgentSession {
|
|
|
1116
1451
|
else if (a.path) {
|
|
1117
1452
|
fileNotes.push(`- ${a.name} (saved at ${a.path})`);
|
|
1118
1453
|
}
|
|
1454
|
+
else {
|
|
1455
|
+
// Never drop a file silently: a file-only prompt would otherwise build no
|
|
1456
|
+
// parts and never run.
|
|
1457
|
+
parts.push({
|
|
1458
|
+
type: "text",
|
|
1459
|
+
text: `[User attached a file "${a.name}" but it could not be saved, so it can't be opened.]`,
|
|
1460
|
+
});
|
|
1461
|
+
}
|
|
1119
1462
|
}
|
|
1120
1463
|
const textParts = [];
|
|
1121
1464
|
if (text.trim())
|
|
1122
1465
|
textParts.push(text.trim());
|
|
1123
1466
|
if (fileNotes.length > 0) {
|
|
1124
|
-
|
|
1467
|
+
// Without this the model unzips/greps documents through bash instead.
|
|
1468
|
+
const docHint = attachments.some((a) => a.kind === "file" && a.path && /\.(pdf|epub)$/i.test(a.path))
|
|
1469
|
+
? "\nThe read tool opens PDF and EPUB files as text."
|
|
1470
|
+
: "";
|
|
1471
|
+
textParts.push(`Attached files (inspect with your tools):\n${fileNotes.join("\n")}${docHint}`);
|
|
1125
1472
|
}
|
|
1126
1473
|
if (textParts.length > 0)
|
|
1127
1474
|
parts.unshift({ type: "text", text: textParts.join("\n\n") });
|
|
@@ -1207,6 +1554,9 @@ export class AgentSession {
|
|
|
1207
1554
|
// The assistant message for this turn is now in the array.
|
|
1208
1555
|
await this.flushPendingMessages();
|
|
1209
1556
|
break;
|
|
1557
|
+
case "steering_message":
|
|
1558
|
+
this.settleDeliveredMessages((m) => m.content === event.content);
|
|
1559
|
+
break;
|
|
1210
1560
|
case "checkpoint":
|
|
1211
1561
|
// Tool results for this step are in the array and their side effects
|
|
1212
1562
|
// already hit the filesystem. Flushing here is what makes a crash lose
|
|
@@ -1216,6 +1566,14 @@ export class AgentSession {
|
|
|
1216
1566
|
break;
|
|
1217
1567
|
}
|
|
1218
1568
|
}
|
|
1569
|
+
/** Drop delivered queued messages and announce the new queue depth. */
|
|
1570
|
+
settleDeliveredMessages(delivered) {
|
|
1571
|
+
const before = this.deliveringQueue.length;
|
|
1572
|
+
this.deliveringQueue = this.deliveringQueue.filter((m) => !delivered(m));
|
|
1573
|
+
if (this.deliveringQueue.length !== before) {
|
|
1574
|
+
this.eventBus.emit("queue_drained", { count: this.userQueue.length });
|
|
1575
|
+
}
|
|
1576
|
+
}
|
|
1219
1577
|
/**
|
|
1220
1578
|
* Count full-file `cat` output from the step that just finished as reads, so
|
|
1221
1579
|
* an edit after `cat` does not cost a second read. Uses the step's results as
|
|
@@ -1288,6 +1646,11 @@ export class AgentSession {
|
|
|
1288
1646
|
// never been told about. The note states the facts outright rather than
|
|
1289
1647
|
// referring to a section such a prompt does not have.
|
|
1290
1648
|
const environmentDelta = buildEnvDeltaMessage(this.renderedEnvironment, this.promptEnvironment());
|
|
1649
|
+
// Plan mode toggled / plan approved mid-run: appended, never re-rendered.
|
|
1650
|
+
const planNotice = this.takePlanNotice();
|
|
1651
|
+
if (planNotice) {
|
|
1652
|
+
log("INFO", "session", "Injecting plan state update instead of rebuilding the prompt");
|
|
1653
|
+
}
|
|
1291
1654
|
if (environmentDelta) {
|
|
1292
1655
|
// The model has now been told; only a further change re-triggers this.
|
|
1293
1656
|
this.renderedEnvironment = this.promptEnvironment();
|
|
@@ -1324,11 +1687,9 @@ export class AgentSession {
|
|
|
1324
1687
|
// agent sees them mid-loop instead of after it stops.
|
|
1325
1688
|
if (this.userQueue.length > 0) {
|
|
1326
1689
|
const queued = this.userQueue.splice(0);
|
|
1327
|
-
//
|
|
1328
|
-
// clients
|
|
1329
|
-
//
|
|
1330
|
-
// the loop, and showing it as still-pending for minutes is a lie.
|
|
1331
|
-
this.eventBus.emit("queue_drained", { count: this.userQueue.length });
|
|
1690
|
+
// `queue_drained` fires when each lands in the transcript (its
|
|
1691
|
+
// steering_message event), not here, so clients drop the "queued" look
|
|
1692
|
+
// when the agent reads it, not minutes later at run end.
|
|
1332
1693
|
// Frame each queued item as concurrent steering — without this wrapper
|
|
1333
1694
|
// the model treats a mid-run message as a fresh request that supersedes
|
|
1334
1695
|
// the original task and silently drops it. ONE message per queued item
|
|
@@ -1351,15 +1712,25 @@ export class AgentSession {
|
|
|
1351
1712
|
];
|
|
1352
1713
|
return { role: "user", content: parts, provenance };
|
|
1353
1714
|
});
|
|
1715
|
+
steeringMessages.forEach((message, index) => {
|
|
1716
|
+
const { id, text, answeredAsk } = queued[index];
|
|
1717
|
+
if (answeredAsk)
|
|
1718
|
+
this.askAnswerSteering.add(message);
|
|
1719
|
+
this.deliveringQueue.push({ id, text, content: message.content });
|
|
1720
|
+
});
|
|
1721
|
+
const userShell = this.takeUserShellContext();
|
|
1354
1722
|
return [
|
|
1355
1723
|
...(environmentDelta ? [environmentDelta] : []),
|
|
1724
|
+
...(planNotice ? [planNotice] : []),
|
|
1725
|
+
...(userShell ? [userShell] : []),
|
|
1356
1726
|
...steeringMessages,
|
|
1357
1727
|
...(notificationMessage ? [notificationMessage] : []),
|
|
1358
1728
|
];
|
|
1359
1729
|
}
|
|
1360
|
-
if (environmentDelta || notificationMessage) {
|
|
1730
|
+
if (environmentDelta || planNotice || notificationMessage) {
|
|
1361
1731
|
return [
|
|
1362
1732
|
...(environmentDelta ? [environmentDelta] : []),
|
|
1733
|
+
...(planNotice ? [planNotice] : []),
|
|
1363
1734
|
...(notificationMessage ? [notificationMessage] : []),
|
|
1364
1735
|
];
|
|
1365
1736
|
}
|
|
@@ -1453,6 +1824,23 @@ export class AgentSession {
|
|
|
1453
1824
|
throw new Error("Active model has no confirmed image support");
|
|
1454
1825
|
signal.throwIfAborted();
|
|
1455
1826
|
try {
|
|
1827
|
+
const claudeCode = await this.claudeCodeProcess();
|
|
1828
|
+
if (claudeCode) {
|
|
1829
|
+
const response = await claudeCodeComplete({
|
|
1830
|
+
...claudeCode,
|
|
1831
|
+
model,
|
|
1832
|
+
messages: [
|
|
1833
|
+
{ role: "system", content: request.instruction },
|
|
1834
|
+
{ role: "user", content: [{ type: "text", text: request.context }, ...request.images] },
|
|
1835
|
+
],
|
|
1836
|
+
thinking,
|
|
1837
|
+
signal,
|
|
1838
|
+
});
|
|
1839
|
+
const text = assistantText(response.message.content);
|
|
1840
|
+
if (text.length > 32_768)
|
|
1841
|
+
throw new Error("Review response exceeded its limit");
|
|
1842
|
+
return { text, model, provider, thinking };
|
|
1843
|
+
}
|
|
1456
1844
|
const creds = await this.authStorage.resolveCredentials(provider, {
|
|
1457
1845
|
storageKeys: this.currentAuthStorageKeys(),
|
|
1458
1846
|
});
|
|
@@ -1500,6 +1888,16 @@ export class AgentSession {
|
|
|
1500
1888
|
* cheaper routing: judging a model's own failure patterns with a weaker
|
|
1501
1889
|
* model swaps false negatives for false positives. */
|
|
1502
1890
|
async callSemanticLoopJudge(prompt) {
|
|
1891
|
+
const claudeCode = await this.claudeCodeProcess();
|
|
1892
|
+
if (claudeCode) {
|
|
1893
|
+
const response = await withJudgeTimeout(claudeCodeComplete({
|
|
1894
|
+
...claudeCode,
|
|
1895
|
+
model: this.model,
|
|
1896
|
+
messages: [{ role: "user", content: prompt }],
|
|
1897
|
+
signal: this.opts.signal,
|
|
1898
|
+
}), SEMANTIC_LOOP_JUDGE_TIMEOUT_MS);
|
|
1899
|
+
return assistantText(response.message.content);
|
|
1900
|
+
}
|
|
1503
1901
|
const creds = await this.authStorage.resolveCredentials(this.provider, {
|
|
1504
1902
|
storageKeys: this.currentAuthStorageKeys(),
|
|
1505
1903
|
});
|
|
@@ -1610,19 +2008,26 @@ export class AgentSession {
|
|
|
1610
2008
|
},
|
|
1611
2009
|
]
|
|
1612
2010
|
: [];
|
|
1613
|
-
const childCompletionFollowUp = buildSubAgentCompletionFollowUp(this.subAgentManager);
|
|
1614
|
-
if (childCompletionFollowUp)
|
|
1615
|
-
return [...diagnosticMessages, ...childCompletionFollowUp];
|
|
2011
|
+
const childCompletionFollowUp = buildSubAgentCompletionFollowUp(this.subAgentManager) ?? [];
|
|
1616
2012
|
// Background processes started this run and never read block completion:
|
|
1617
2013
|
// their progress/exit checkpoints only land on the steering path, which an
|
|
1618
|
-
// agent about to stop never reaches.
|
|
1619
|
-
|
|
1620
|
-
|
|
2014
|
+
// agent about to stop never reaches. Sent in the same follow-up as the
|
|
2015
|
+
// child-agent gate: one forced turn can collect both, where returning them
|
|
2016
|
+
// one per stop cost a separate model round-trip each.
|
|
2017
|
+
const processFollowUp = buildProcessCompletionFollowUp(this.processManager?.list() ?? [], this.runStartedAt, this.processGateInjected) ?? [];
|
|
2018
|
+
if (processFollowUp.length > 0) {
|
|
1621
2019
|
this.processGateInjected += 1;
|
|
1622
2020
|
log("INFO", "process-gate", "Injecting background-process completion gate", {
|
|
1623
2021
|
injected: String(this.processGateInjected),
|
|
1624
2022
|
});
|
|
1625
|
-
|
|
2023
|
+
}
|
|
2024
|
+
// Child agents and background processes ride one forced turn together
|
|
2025
|
+
// (with any diagnostics). Diagnostics alone fall through, so the
|
|
2026
|
+
// verification gate below can join them in that same turn.
|
|
2027
|
+
if (childCompletionFollowUp.length > 0 || processFollowUp.length > 0) {
|
|
2028
|
+
const gateMessages = mergeCompletionGateFollowUps(diagnosticMessages, childCompletionFollowUp, processFollowUp);
|
|
2029
|
+
if (gateMessages)
|
|
2030
|
+
return gateMessages;
|
|
1626
2031
|
}
|
|
1627
2032
|
// A check whose exit status could not count (`npm test | tail; node -e …`)
|
|
1628
2033
|
// is re-run on its own before the gate decides, so a passing run is not
|
|
@@ -1797,6 +2202,16 @@ export class AgentSession {
|
|
|
1797
2202
|
.reverse()
|
|
1798
2203
|
.find((m) => m.role === "user" && m.provenance?.kind !== "notification");
|
|
1799
2204
|
this.resetHookState(requestTextForRegrounding(lastUser));
|
|
2205
|
+
// A Claude subscription only connects through Claude Code; compaction stays ours.
|
|
2206
|
+
const claudeCode = await this.claudeCodeProcess();
|
|
2207
|
+
if (claudeCode) {
|
|
2208
|
+
await this.maybeCompactPreRun();
|
|
2209
|
+
await this.runClaudeCodeLoop(claudeCode, options);
|
|
2210
|
+
this.maybeCompactPostTurn();
|
|
2211
|
+
return;
|
|
2212
|
+
}
|
|
2213
|
+
// Left the Claude subscription route (provider switch, sign-out).
|
|
2214
|
+
this.closeClaudeCodeLive("route changed");
|
|
1800
2215
|
// Resolve OAuth credentials and run agent loop.
|
|
1801
2216
|
// On 401, force-refresh the token and retry once — the provider may have
|
|
1802
2217
|
// revoked the token server-side before the stored expiry (e.g. after a restart).
|
|
@@ -1812,72 +2227,9 @@ export class AgentSession {
|
|
|
1812
2227
|
let lastResolvedAccessToken = creds.accessToken;
|
|
1813
2228
|
// Auto-compact if needed. This must happen after credential resolution so
|
|
1814
2229
|
// OpenAI OAuth/Codex sessions use the Codex product context window instead
|
|
1815
|
-
// of the public API model window.
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
// A post-turn compaction may still be running in the background. Let it
|
|
1819
|
-
// settle first: it usually already compacted this history, so the
|
|
1820
|
-
// decision below turns into a no-op instead of duplicate work.
|
|
1821
|
-
if (this.postTurnCompaction)
|
|
1822
|
-
await this.postTurnCompaction;
|
|
1823
|
-
const contextWindow = getContextWindow(this.model, {
|
|
1824
|
-
provider: this.provider,
|
|
1825
|
-
accountId: creds.accountId,
|
|
1826
|
-
});
|
|
1827
|
-
const policy = resolveCompactionPolicy({
|
|
1828
|
-
provider: this.provider,
|
|
1829
|
-
model: this.model,
|
|
1830
|
-
contextWindow,
|
|
1831
|
-
threshold: this.settingsManager.get("compactThreshold"),
|
|
1832
|
-
accountId: creds.accountId,
|
|
1833
|
-
approvedPlanPath: this.approvedPlanPath,
|
|
1834
|
-
});
|
|
1835
|
-
let activeTokens;
|
|
1836
|
-
if (this.providerContext) {
|
|
1837
|
-
const anchorIndex = this.messages.lastIndexOf(this.providerContext.anchor);
|
|
1838
|
-
if (anchorIndex >= 0) {
|
|
1839
|
-
activeTokens = calculateActiveContextTokens(this.messages, {
|
|
1840
|
-
usage: this.providerContext.usage,
|
|
1841
|
-
pendingMessages: this.messages.slice(anchorIndex + 1),
|
|
1842
|
-
});
|
|
1843
|
-
}
|
|
1844
|
-
else {
|
|
1845
|
-
this.providerContext = null;
|
|
1846
|
-
}
|
|
1847
|
-
}
|
|
1848
|
-
log("INFO", "compaction", "Pre-run compaction decision", {
|
|
1849
|
-
provider: this.provider,
|
|
1850
|
-
model: this.model,
|
|
1851
|
-
transport: this.provider === "openai" && creds.accountId ? "codex_oauth" : "public_api",
|
|
1852
|
-
contextWindow: String(contextWindow),
|
|
1853
|
-
activeTokens: activeTokens === undefined ? "estimated" : String(activeTokens),
|
|
1854
|
-
triggerLimit: String(policy.targetTokens),
|
|
1855
|
-
});
|
|
1856
|
-
if (shouldCompact(this.messages, contextWindow, policy.threshold, activeTokens, policy.targetTokens)) {
|
|
1857
|
-
try {
|
|
1858
|
-
await this.compact(creds, "automatic");
|
|
1859
|
-
if (this.lastCompactionCompacted) {
|
|
1860
|
-
// Re-grounding hook keys off this — the context was just summarized.
|
|
1861
|
-
this.compactionOccurred = true;
|
|
1862
|
-
this.compactionRetryAfter = 0;
|
|
1863
|
-
}
|
|
1864
|
-
else {
|
|
1865
|
-
this.compactionRetryAfter = Date.now() + 30_000;
|
|
1866
|
-
}
|
|
1867
|
-
}
|
|
1868
|
-
catch (error) {
|
|
1869
|
-
this.compactionRetryAfter = Date.now() + 30_000;
|
|
1870
|
-
if (isAbortError(error) || this.opts.signal?.aborted)
|
|
1871
|
-
throw error;
|
|
1872
|
-
log("WARN", "compaction", `Pre-run compaction failed; cooling down for 30s: ${error instanceof Error ? error.message : String(error)}`);
|
|
1873
|
-
}
|
|
1874
|
-
}
|
|
1875
|
-
}
|
|
1876
|
-
// Reassigned when Anthropic rejects the turn for being below a model's
|
|
1877
|
-
// minimum Claude Code version; the retry below rebuilds it from the floor
|
|
1878
|
-
// that rejection taught us. The anthropic client cache is keyed on the UA,
|
|
1879
|
-
// so the new value transparently yields a correctly-identified client.
|
|
1880
|
-
let userAgent = this.provider === "anthropic" ? await getClaudeCliUserAgent() : undefined;
|
|
2230
|
+
// of the public API model window.
|
|
2231
|
+
await this.maybeCompactPreRun(creds);
|
|
2232
|
+
const userAgent = this.provider === "anthropic" ? await getClaudeCliUserAgent() : undefined;
|
|
1881
2233
|
const loopMessages = await this.prepareDynamicContext();
|
|
1882
2234
|
// Re-read every run so rule-file edits apply on the next turn; a few small files.
|
|
1883
2235
|
const streamRules = await loadStreamRules(this.cwd);
|
|
@@ -1890,6 +2242,7 @@ export class AgentSession {
|
|
|
1890
2242
|
provider: this.provider,
|
|
1891
2243
|
model: this.model,
|
|
1892
2244
|
tools: options.disableTools ? [] : this.tools,
|
|
2245
|
+
...(options.disableTools ? {} : { deferredTools: this.deferredToolCatalog }),
|
|
1893
2246
|
webSearch: options.disableTools ? false : () => this.nativeWebSearchOn(),
|
|
1894
2247
|
maxTokens: this.requestMaxTokens(accountId),
|
|
1895
2248
|
maxTurns: this.opts.maxTurns,
|
|
@@ -1902,6 +2255,7 @@ export class AgentSession {
|
|
|
1902
2255
|
thinking: this.planModeRef.current || options.capThinking
|
|
1903
2256
|
? clampThinkingForPlanMode(this.thinkingLevel)
|
|
1904
2257
|
: this.thinkingLevel,
|
|
2258
|
+
...(modelInfo?.thinkingLevels ? { thinkingLevels: modelInfo.thinkingLevels } : {}),
|
|
1905
2259
|
apiKey,
|
|
1906
2260
|
// Per-turn credential resolution. A run can span many minutes; if any
|
|
1907
2261
|
// process sharing auth.json refreshes this grant meanwhile, the token
|
|
@@ -1952,10 +2306,15 @@ export class AgentSession {
|
|
|
1952
2306
|
promptCacheKey: this.getPromptCacheKey(),
|
|
1953
2307
|
},
|
|
1954
2308
|
});
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
2309
|
+
// "Context cache outcome" (persistTurnMetric) repeats this whole report
|
|
2310
|
+
// with usage attached, so only log the prepared report on its own when
|
|
2311
|
+
// it carries a cache-relevant change or risk worth seeing pre-response.
|
|
2312
|
+
if (report.changes.length > 0 || report.thinkingPrefixRiskBlocks > 0) {
|
|
2313
|
+
log("INFO", "cache", "Prepared context", {
|
|
2314
|
+
sessionId: this.sessionId || this.transportSessionId,
|
|
2315
|
+
data: JSON.stringify(report),
|
|
2316
|
+
});
|
|
2317
|
+
}
|
|
1959
2318
|
if (report.thinkingPrefixRiskBlocks > 0) {
|
|
1960
2319
|
log("WARN", "cache", "Possible signed-thinking prefix mismatch; not server verified", {
|
|
1961
2320
|
sessionId: this.sessionId || this.transportSessionId,
|
|
@@ -2018,6 +2377,7 @@ export class AgentSession {
|
|
|
2018
2377
|
model: this.model,
|
|
2019
2378
|
contextWindow,
|
|
2020
2379
|
threshold: this.settingsManager.get("compactThreshold"),
|
|
2380
|
+
compactAtTokens: this.settingsManager.get("compactAtTokens"),
|
|
2021
2381
|
accountId,
|
|
2022
2382
|
approvedPlanPath: this.approvedPlanPath,
|
|
2023
2383
|
});
|
|
@@ -2044,7 +2404,10 @@ export class AgentSession {
|
|
|
2044
2404
|
// anchors; drop the retained usage afterwards since it counted the
|
|
2045
2405
|
// pruned content.
|
|
2046
2406
|
if (shouldPruneToolResults(activeTokens, policy.targetTokens)) {
|
|
2047
|
-
const
|
|
2407
|
+
const cacheCold = this.getCacheExpiryStatus()?.expired ?? false;
|
|
2408
|
+
const pruneResult = pruneStaleToolResults(messages, {
|
|
2409
|
+
minimumTokens: pruneMinimumTokens(activeTokens, cacheCold),
|
|
2410
|
+
});
|
|
2048
2411
|
if (pruneResult.pruned) {
|
|
2049
2412
|
this.cacheDiagnostics.noteEdit("tool_prune", pruneResult.freedTokens);
|
|
2050
2413
|
this.providerContext = null;
|
|
@@ -2067,6 +2430,8 @@ export class AgentSession {
|
|
|
2067
2430
|
// An approved plan runs as ONE run, so step boundaries are only
|
|
2068
2431
|
// visible here, between model steps — not after the run ends.
|
|
2069
2432
|
const planStep = this.observePlanStepProgress(messages, contextWindow, activeTokens);
|
|
2433
|
+
// The decision line carries the outcome (compact=) next to its inputs.
|
|
2434
|
+
const overLimit = shouldCompact(messages, contextWindow, policy.threshold, activeTokens, policy.targetTokens);
|
|
2070
2435
|
log("INFO", "compaction", "In-flight compaction decision", {
|
|
2071
2436
|
provider: this.provider,
|
|
2072
2437
|
model: this.model,
|
|
@@ -2074,10 +2439,10 @@ export class AgentSession {
|
|
|
2074
2439
|
contextWindow: String(contextWindow),
|
|
2075
2440
|
activeTokens: String(activeTokens),
|
|
2076
2441
|
triggerLimit: String(policy.targetTokens),
|
|
2442
|
+
compact: String(overLimit || Boolean(planStep?.compact)),
|
|
2077
2443
|
...(planStep ? { planStep: `${planStep.compact} (${planStep.reason})` } : {}),
|
|
2078
2444
|
});
|
|
2079
|
-
if (!
|
|
2080
|
-
!planStep?.compact)
|
|
2445
|
+
if (!overLimit && !planStep?.compact)
|
|
2081
2446
|
return messages;
|
|
2082
2447
|
}
|
|
2083
2448
|
// compact() operates on this.messages, while an earlier transform may
|
|
@@ -2119,6 +2484,7 @@ export class AgentSession {
|
|
|
2119
2484
|
}
|
|
2120
2485
|
finally {
|
|
2121
2486
|
this.activeLoopMessages = null;
|
|
2487
|
+
this.settleDeliveredMessages(() => true);
|
|
2122
2488
|
// An in-flight compaction rebinds `this.messages` to the compacted array
|
|
2123
2489
|
// while the loop keeps appending to `loopMessages`. Resync on every exit
|
|
2124
2490
|
// — a failed or aborted run included — or the session silently drops
|
|
@@ -2136,8 +2502,9 @@ export class AgentSession {
|
|
|
2136
2502
|
// fallback key, not the model's first preference).
|
|
2137
2503
|
const badKey = (await this.authStorage.pickStorageKey(this.currentAuthStorageKeys())) ??
|
|
2138
2504
|
this.currentAuthStorageKeys()[0];
|
|
2139
|
-
|
|
2140
|
-
|
|
2505
|
+
const cleared = await this.authStorage.clearRejectedApiKey(badKey);
|
|
2506
|
+
log("WARN", "auth", `Got 401 for ${this.provider} (${badKey}) — ` +
|
|
2507
|
+
(cleared ? "API key is invalid or revoked" : "key rejected, kept on file"));
|
|
2141
2508
|
return true;
|
|
2142
2509
|
};
|
|
2143
2510
|
try {
|
|
@@ -2198,17 +2565,22 @@ export class AgentSession {
|
|
|
2198
2565
|
throw fallbackErr;
|
|
2199
2566
|
}
|
|
2200
2567
|
}
|
|
2201
|
-
else if (
|
|
2202
|
-
err
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
//
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2568
|
+
else if (err instanceof ProviderError &&
|
|
2569
|
+
err.statusCode === 401 &&
|
|
2570
|
+
!this.baseUrl &&
|
|
2571
|
+
(await this.authStorage.relocateRegionalApiKey(this.currentAuthStorageKeys()))) {
|
|
2572
|
+
// The key was valid all along, just sent to another region's cluster.
|
|
2573
|
+
creds = await this.authStorage.resolveCredentials(this.provider, {
|
|
2574
|
+
storageKeys: this.currentAuthStorageKeys(),
|
|
2575
|
+
});
|
|
2576
|
+
this.lastAccountId = creds.accountId;
|
|
2577
|
+
try {
|
|
2578
|
+
await runAgentLoop(creds.accessToken, creds.accountId, creds.projectId);
|
|
2579
|
+
}
|
|
2580
|
+
catch (retryErr) {
|
|
2581
|
+
await clearInvalidStaticApiKey(retryErr);
|
|
2582
|
+
throw retryErr;
|
|
2583
|
+
}
|
|
2212
2584
|
}
|
|
2213
2585
|
else if (err instanceof ProviderError && err.statusCode === 401) {
|
|
2214
2586
|
// Static API-key providers (GLM, Moonshot API key, etc.) have no refresh
|
|
@@ -2283,6 +2655,8 @@ export class AgentSession {
|
|
|
2283
2655
|
// booted on e.g. Kimi (256K) keeps sending that cap after switching to a
|
|
2284
2656
|
// smaller model (Opus 128K), which the provider rejects.
|
|
2285
2657
|
this.maxTokens = this.resolveMaxTokens(model);
|
|
2658
|
+
if (changed)
|
|
2659
|
+
this.preconnect();
|
|
2286
2660
|
this.eventBus.emit("model_change", {
|
|
2287
2661
|
provider: this.provider,
|
|
2288
2662
|
model: this.model,
|
|
@@ -2320,25 +2694,15 @@ export class AgentSession {
|
|
|
2320
2694
|
}
|
|
2321
2695
|
// Update provider-specific tools when provider changes
|
|
2322
2696
|
if (provider && provider !== prevProvider) {
|
|
2323
|
-
//
|
|
2324
|
-
//
|
|
2697
|
+
// The client web_search tool serves every provider (on Anthropic it
|
|
2698
|
+
// runs the native search as a side request), so a switch only adds it
|
|
2699
|
+
// when an untiered session lacks it.
|
|
2325
2700
|
const hasWebSearch = this.tools.some((t) => t.name === "web_search");
|
|
2326
|
-
if (this.deferredBuiltinToolNames.includes("web_search")) {
|
|
2327
|
-
// Tiered: the client tool lives in the catalog for every provider and,
|
|
2328
|
-
// once promoted, is swapped for the native server tool by the Anthropic
|
|
2329
|
-
// transport. Nothing to add or remove — doing so would either load the
|
|
2330
|
-
// schema eagerly or take away a capability the model already has.
|
|
2331
|
-
}
|
|
2332
|
-
else if (this.provider === "anthropic" && hasWebSearch) {
|
|
2333
|
-
// Switching TO anthropic — remove client-side web_search (server-side handles it)
|
|
2334
|
-
this.tools = this.tools.filter((t) => t.name !== "web_search");
|
|
2335
|
-
}
|
|
2336
|
-
else if (this.provider !== "anthropic" && !hasWebSearch) {
|
|
2337
|
-
// Switching FROM anthropic — add client-side web_search
|
|
2701
|
+
if (!this.deferredBuiltinToolNames.includes("web_search") && !hasWebSearch) {
|
|
2338
2702
|
this.tools.push(createWebSearchTool(() => ({
|
|
2339
2703
|
mode: this.settingsManager.get("networkMode"),
|
|
2340
2704
|
allow: this.settingsManager.get("networkAllow"),
|
|
2341
|
-
})));
|
|
2705
|
+
}), (request) => this.runSideWebSearch(request)));
|
|
2342
2706
|
}
|
|
2343
2707
|
// Reconnect MCP servers ONLY when GLM is involved on either side — GLM
|
|
2344
2708
|
// is the only provider with a different server set (Z.AI tools), so a
|
|
@@ -2592,7 +2956,7 @@ export class AgentSession {
|
|
|
2592
2956
|
return;
|
|
2593
2957
|
const contextWindow = getContextWindow(this.model, {
|
|
2594
2958
|
provider: this.provider,
|
|
2595
|
-
accountId: creds
|
|
2959
|
+
accountId: creds?.accountId,
|
|
2596
2960
|
});
|
|
2597
2961
|
// One compaction per turn boundary: a pre-run, in-flight or overflow
|
|
2598
2962
|
// compaction already shrank this run's history — re-probing right after
|
|
@@ -2607,7 +2971,8 @@ export class AgentSession {
|
|
|
2607
2971
|
model: this.model,
|
|
2608
2972
|
contextWindow,
|
|
2609
2973
|
threshold: this.settingsManager.get("compactThreshold"),
|
|
2610
|
-
|
|
2974
|
+
compactAtTokens: this.settingsManager.get("compactAtTokens"),
|
|
2975
|
+
accountId: creds?.accountId,
|
|
2611
2976
|
approvedPlanPath: this.approvedPlanPath,
|
|
2612
2977
|
});
|
|
2613
2978
|
let activeTokens;
|
|
@@ -2628,14 +2993,16 @@ export class AgentSession {
|
|
|
2628
2993
|
trigger: planStep?.compact ? `plan-step (${planStep.reason})` : "size",
|
|
2629
2994
|
provider: this.provider,
|
|
2630
2995
|
model: this.model,
|
|
2631
|
-
transport: this.
|
|
2996
|
+
transport: this.compactionTransport(creds),
|
|
2632
2997
|
contextWindow: String(contextWindow),
|
|
2633
2998
|
activeTokens: activeTokens === undefined ? "estimated" : String(activeTokens),
|
|
2634
2999
|
triggerLimit: String(policy.targetTokens),
|
|
2635
3000
|
});
|
|
3001
|
+
const postTurnAbort = new AbortController();
|
|
3002
|
+
this.postTurnCompactionAbort = postTurnAbort;
|
|
2636
3003
|
this.postTurnCompaction = (async () => {
|
|
2637
3004
|
try {
|
|
2638
|
-
await this.compact(creds, "automatic");
|
|
3005
|
+
await this.compact(creds, "automatic", undefined, postTurnAbort.signal);
|
|
2639
3006
|
if (this.lastCompactionCompacted) {
|
|
2640
3007
|
// Arm re-grounding for the next turn. resetHookState clears
|
|
2641
3008
|
// compactionOccurred at run start, before the injection point, so
|
|
@@ -2655,17 +3022,27 @@ export class AgentSession {
|
|
|
2655
3022
|
}
|
|
2656
3023
|
finally {
|
|
2657
3024
|
this.postTurnCompaction = undefined;
|
|
3025
|
+
if (this.postTurnCompactionAbort === postTurnAbort)
|
|
3026
|
+
this.postTurnCompactionAbort = undefined;
|
|
2658
3027
|
}
|
|
2659
3028
|
})();
|
|
2660
3029
|
}
|
|
2661
3030
|
async compact(existingCredentials, mode = "manual",
|
|
2662
3031
|
/** User-stated focus (`/compact <focus>`): what must survive verbatim. */
|
|
2663
|
-
focus
|
|
3032
|
+
focus,
|
|
3033
|
+
/** Extra abort source (post-turn compaction, cancelled by dispose). */
|
|
3034
|
+
abortSignal) {
|
|
2664
3035
|
this.lastCompactionCompacted = false;
|
|
3036
|
+
const compactionSignal = abortSignal && this.opts.signal
|
|
3037
|
+
? AbortSignal.any([this.opts.signal, abortSignal])
|
|
3038
|
+
: (abortSignal ?? this.opts.signal);
|
|
3039
|
+
const claudeCode = existingCredentials ? null : await this.claudeCodeProcess();
|
|
2665
3040
|
const creds = existingCredentials ??
|
|
2666
|
-
(
|
|
2667
|
-
|
|
2668
|
-
|
|
3041
|
+
(claudeCode
|
|
3042
|
+
? { accessToken: "" }
|
|
3043
|
+
: await this.authStorage.resolveCredentials(this.provider, {
|
|
3044
|
+
storageKeys: this.currentAuthStorageKeys(),
|
|
3045
|
+
}));
|
|
2669
3046
|
const contextWindow = getContextWindow(this.model, {
|
|
2670
3047
|
provider: this.provider,
|
|
2671
3048
|
accountId: creds.accountId,
|
|
@@ -2675,6 +3052,7 @@ export class AgentSession {
|
|
|
2675
3052
|
model: this.model,
|
|
2676
3053
|
contextWindow,
|
|
2677
3054
|
threshold: this.settingsManager.get("compactThreshold"),
|
|
3055
|
+
compactAtTokens: this.settingsManager.get("compactAtTokens"),
|
|
2678
3056
|
accountId: creds.accountId,
|
|
2679
3057
|
approvedPlanPath: this.approvedPlanPath,
|
|
2680
3058
|
});
|
|
@@ -2692,9 +3070,14 @@ export class AgentSession {
|
|
|
2692
3070
|
baseUrl: this.baseUrl ?? creds.baseUrl,
|
|
2693
3071
|
contextWindow,
|
|
2694
3072
|
targetTokens: policy.targetTokens,
|
|
2695
|
-
signal:
|
|
3073
|
+
signal: compactionSignal,
|
|
2696
3074
|
approvedPlanPath: this.approvedPlanPath,
|
|
2697
3075
|
focus,
|
|
3076
|
+
...(claudeCode
|
|
3077
|
+
? {
|
|
3078
|
+
complete: (req) => claudeCodeComplete({ ...claudeCode, ...req }),
|
|
3079
|
+
}
|
|
3080
|
+
: {}),
|
|
2698
3081
|
});
|
|
2699
3082
|
contextSelection = output.result.contextSelection;
|
|
2700
3083
|
return output;
|
|
@@ -2713,7 +3096,7 @@ export class AgentSession {
|
|
|
2713
3096
|
}
|
|
2714
3097
|
else {
|
|
2715
3098
|
const conversationId = this.conversationId;
|
|
2716
|
-
await this.sessionManager.withCompactionLease(conversationId,
|
|
3099
|
+
await this.sessionManager.withCompactionLease(conversationId, compactionSignal, async () => {
|
|
2717
3100
|
let sourceFingerprint = computeSourceFingerprint(this.messages);
|
|
2718
3101
|
const canonicalPath = await this.sessionManager.resolveCanonicalSession(conversationId, this.cwd);
|
|
2719
3102
|
if (canonicalPath && canonicalPath !== this.sessionPath) {
|
|
@@ -2819,6 +3202,7 @@ export class AgentSession {
|
|
|
2819
3202
|
// into the fresh session (e.g. an accepted plan's build would inherit the
|
|
2820
3203
|
// whole planning conversation and lose the approved-plan prompt).
|
|
2821
3204
|
await this.settlePostTurnCompaction();
|
|
3205
|
+
this.closeClaudeCodeLive("new session");
|
|
2822
3206
|
this.cacheDiagnostics.reset();
|
|
2823
3207
|
// Approved-plan execution is a clean checkpoint of the same conversation;
|
|
2824
3208
|
// explicit new sessions reset the conversation identity.
|
|
@@ -2866,6 +3250,7 @@ export class AgentSession {
|
|
|
2866
3250
|
this.eventBus.emit("session_start", { sessionId: this.sessionId });
|
|
2867
3251
|
}
|
|
2868
3252
|
async loadSession(sessionPath) {
|
|
3253
|
+
this.closeClaudeCodeLive("session loaded");
|
|
2869
3254
|
await this.loadExistingSession(sessionPath);
|
|
2870
3255
|
this.cacheDiagnostics.reset();
|
|
2871
3256
|
if (this.sessionId)
|
|
@@ -2919,6 +3304,10 @@ export class AgentSession {
|
|
|
2919
3304
|
this.setSessionPath(loaded.path);
|
|
2920
3305
|
return this.sessionManager.listBranches(loaded.entries);
|
|
2921
3306
|
}
|
|
3307
|
+
/** The session's first user-authored prompt, or "" before there is one. */
|
|
3308
|
+
getSessionPreview() {
|
|
3309
|
+
return this.sessionPreview;
|
|
3310
|
+
}
|
|
2922
3311
|
/** Skills the safety scan kept out of this session, for the app/CLI to show. */
|
|
2923
3312
|
getBlockedSkills() {
|
|
2924
3313
|
return this.blockedSkills;
|
|
@@ -3106,17 +3495,57 @@ export class AgentSession {
|
|
|
3106
3495
|
/** Queue a user message (optionally with attachments) to be injected mid-run
|
|
3107
3496
|
* as steering. Returns the new queue length. No-op semantics are the caller's
|
|
3108
3497
|
* concern. */
|
|
3109
|
-
queueMessage(text, attachments = []) {
|
|
3498
|
+
queueMessage(text, attachments = [], opts = {}) {
|
|
3110
3499
|
this.queueSeq += 1;
|
|
3111
|
-
this.userQueue.push({
|
|
3500
|
+
this.userQueue.push({
|
|
3501
|
+
id: `q${this.queueSeq}`,
|
|
3502
|
+
text,
|
|
3503
|
+
attachments,
|
|
3504
|
+
...(opts.answeredAsk ? { answeredAsk: true } : {}),
|
|
3505
|
+
});
|
|
3112
3506
|
// Instant interrupt: preempt running tools so the steer lands right away.
|
|
3113
3507
|
for (const listener of [...this.steeringListeners])
|
|
3114
3508
|
listener();
|
|
3115
3509
|
return this.userQueue.length;
|
|
3116
3510
|
}
|
|
3117
|
-
/**
|
|
3511
|
+
/**
|
|
3512
|
+
* Hold the output of a command the user ran themselves (`!cmd` in the app)
|
|
3513
|
+
* so it reaches the agent with their next message: a prompt, or a message
|
|
3514
|
+
* queued as steering. Never on its own, and never mid-run without one.
|
|
3515
|
+
*/
|
|
3516
|
+
addUserShellContext(runId, text) {
|
|
3517
|
+
if (text.trim())
|
|
3518
|
+
this.pendingUserShell.push({ runId, text });
|
|
3519
|
+
}
|
|
3520
|
+
/** Run ids of user commands still waiting for the next message. */
|
|
3521
|
+
getPendingUserShellRunIds() {
|
|
3522
|
+
return this.pendingUserShell.map((entry) => entry.runId);
|
|
3523
|
+
}
|
|
3524
|
+
takeUserShellContext() {
|
|
3525
|
+
if (this.pendingUserShell.length === 0)
|
|
3526
|
+
return null;
|
|
3527
|
+
const blocks = this.pendingUserShell.splice(0).map((entry) => entry.text);
|
|
3528
|
+
return {
|
|
3529
|
+
role: "user",
|
|
3530
|
+
content: buildUserShellContextText(blocks),
|
|
3531
|
+
provenance: { source: "runtime", kind: "notification", visibility: "hidden" },
|
|
3532
|
+
};
|
|
3533
|
+
}
|
|
3534
|
+
/** Persist pending user command output just ahead of the human message. */
|
|
3535
|
+
async deliverUserShellContext() {
|
|
3536
|
+
const message = this.takeUserShellContext();
|
|
3537
|
+
if (!message)
|
|
3538
|
+
return;
|
|
3539
|
+
this.messages.push(message);
|
|
3540
|
+
await this.persistMessage(message);
|
|
3541
|
+
}
|
|
3542
|
+
/** Pending queued messages (id + text), oldest first, for client display.
|
|
3543
|
+
* `delivering` ones are already with the agent and can no longer be cancelled. */
|
|
3118
3544
|
listQueuedMessages() {
|
|
3119
|
-
return
|
|
3545
|
+
return [
|
|
3546
|
+
...this.deliveringQueue.map((m) => ({ id: m.id, text: m.text, delivering: true })),
|
|
3547
|
+
...this.userQueue.map((m) => ({ id: m.id, text: m.text })),
|
|
3548
|
+
];
|
|
3120
3549
|
}
|
|
3121
3550
|
/** Cancel one pending message by id. Returns true if it was still queued.
|
|
3122
3551
|
* A false return is the normal race rather than an error: the message drained
|
|
@@ -3253,6 +3682,8 @@ export class AgentSession {
|
|
|
3253
3682
|
*/
|
|
3254
3683
|
stopBackgroundProcesses() {
|
|
3255
3684
|
this.processManager?.shutdownAll();
|
|
3685
|
+
// Synchronous, so app quit stops Claude Code even when later teardown hangs.
|
|
3686
|
+
this.closeClaudeCodeLive("shutdown");
|
|
3256
3687
|
}
|
|
3257
3688
|
/** Replace a host-owned system prompt in place without resetting conversation history. */
|
|
3258
3689
|
setCustomSystemPrompt(systemPrompt, promptCacheKeyPrefix) {
|
|
@@ -3286,7 +3717,7 @@ export class AgentSession {
|
|
|
3286
3717
|
// is about to be drafted); exiting keeps it (set explicitly via accept).
|
|
3287
3718
|
if (active)
|
|
3288
3719
|
this.approvedPlanPath = undefined;
|
|
3289
|
-
await this.
|
|
3720
|
+
await this.applyPlanStateChange();
|
|
3290
3721
|
}
|
|
3291
3722
|
/**
|
|
3292
3723
|
* Bake an approved plan into the system prompt so the model is told to emit
|
|
@@ -3296,7 +3727,48 @@ export class AgentSession {
|
|
|
3296
3727
|
*/
|
|
3297
3728
|
async setApprovedPlan(approvedPlanPath) {
|
|
3298
3729
|
this.approvedPlanPath = approvedPlanPath;
|
|
3299
|
-
await this.
|
|
3730
|
+
await this.applyPlanStateChange();
|
|
3731
|
+
}
|
|
3732
|
+
/**
|
|
3733
|
+
* Before the conversation starts, render plan state into the prompt. After,
|
|
3734
|
+
* the prompt is a cached prefix: queue an appended notice instead, so the
|
|
3735
|
+
* cached bytes stay identical (a rebuild re-sent the whole history).
|
|
3736
|
+
*/
|
|
3737
|
+
async applyPlanStateChange() {
|
|
3738
|
+
if (this.customSystemPrompt || this.agentPrompt !== undefined)
|
|
3739
|
+
return;
|
|
3740
|
+
if (!this.messages.some((message) => message.role !== "system")) {
|
|
3741
|
+
this.pendingPlanNotice = null;
|
|
3742
|
+
await this.rebuildSystemPromptInPlace();
|
|
3743
|
+
return;
|
|
3744
|
+
}
|
|
3745
|
+
const state = {
|
|
3746
|
+
planMode: this.planModeRef.current,
|
|
3747
|
+
approvedPlanPath: this.approvedPlanPath,
|
|
3748
|
+
};
|
|
3749
|
+
const message = await buildPlanStateMessage(this.seenPlanState, state, [
|
|
3750
|
+
...this.tools.map((t) => t.name),
|
|
3751
|
+
...this.deferredBuiltinToolNames,
|
|
3752
|
+
]);
|
|
3753
|
+
this.pendingPlanNotice = message ? { message, state } : null;
|
|
3754
|
+
}
|
|
3755
|
+
/** The plan notice to append now, if any (pending, or a compacted-away one). */
|
|
3756
|
+
takePlanNotice() {
|
|
3757
|
+
if (this.pendingPlanNotice) {
|
|
3758
|
+
const { message, state } = this.pendingPlanNotice;
|
|
3759
|
+
this.pendingPlanNotice = null;
|
|
3760
|
+
this.seenPlanState = state;
|
|
3761
|
+
this.lastPlanNotice = message;
|
|
3762
|
+
return message;
|
|
3763
|
+
}
|
|
3764
|
+
if (this.lastPlanNotice &&
|
|
3765
|
+
!samePlanState(this.seenPlanState, this.promptPlanState) &&
|
|
3766
|
+
!this.messages.includes(this.lastPlanNotice)) {
|
|
3767
|
+
const again = { ...this.lastPlanNotice };
|
|
3768
|
+
this.lastPlanNotice = again;
|
|
3769
|
+
return again;
|
|
3770
|
+
}
|
|
3771
|
+
return null;
|
|
3300
3772
|
}
|
|
3301
3773
|
/** Extra workspace roots added with `/add-dir`, in the order added. */
|
|
3302
3774
|
getAdditionalRoots() {
|
|
@@ -3406,8 +3878,11 @@ export class AgentSession {
|
|
|
3406
3878
|
return this.customSystemPrompt;
|
|
3407
3879
|
// Listed once: a rebuild (plan mode, /add-dir, compaction) must not churn the
|
|
3408
3880
|
// prompt as the agent adds files.
|
|
3409
|
-
if (this.projectFiles === undefined)
|
|
3410
|
-
|
|
3881
|
+
if (this.projectFiles === undefined) {
|
|
3882
|
+
const pending = this.projectFilesPending;
|
|
3883
|
+
this.projectFilesPending = undefined;
|
|
3884
|
+
this.projectFiles = await (pending ?? listProjectFiles(this.cwd));
|
|
3885
|
+
}
|
|
3411
3886
|
const toolNames = this.tools.map((tool) => tool.name);
|
|
3412
3887
|
const deferredToolNames = this.deferredToolNamesForPrompt(toolNames);
|
|
3413
3888
|
// Whatever is rendered now is what the model has been told.
|
|
@@ -3445,7 +3920,7 @@ export class AgentSession {
|
|
|
3445
3920
|
return this.messages.some((m) => m.role === "assistant");
|
|
3446
3921
|
}
|
|
3447
3922
|
/**
|
|
3448
|
-
* Give the model
|
|
3923
|
+
* Give the model verify commands for languages that appeared after its prompt
|
|
3449
3924
|
* was cached (e.g. the previous task scaffolded a TypeScript project), as a
|
|
3450
3925
|
* hidden message appended to the history rather than a prompt re-render that
|
|
3451
3926
|
* would throw away the whole cache. Runs just before a new user message is
|
|
@@ -3453,6 +3928,13 @@ export class AgentSession {
|
|
|
3453
3928
|
* update is saved in order with the rest of the conversation.
|
|
3454
3929
|
*/
|
|
3455
3930
|
async announceNewLanguages() {
|
|
3931
|
+
const planNotice = this.takePlanNotice();
|
|
3932
|
+
if (planNotice) {
|
|
3933
|
+
this.messages.push(planNotice);
|
|
3934
|
+
await this.persistMessage(planNotice);
|
|
3935
|
+
this.lastPersistedIndex = this.messages.length;
|
|
3936
|
+
log("INFO", "session", "Appended plan state update instead of rebuilding the prompt");
|
|
3937
|
+
}
|
|
3456
3938
|
if (!this.hasReply())
|
|
3457
3939
|
return; // the next request rebuilds the prompt instead
|
|
3458
3940
|
this.refreshActiveLanguages();
|
|
@@ -3467,7 +3949,7 @@ export class AgentSession {
|
|
|
3467
3949
|
this.messages.push(update);
|
|
3468
3950
|
await this.persistMessage(update);
|
|
3469
3951
|
this.lastPersistedIndex = this.messages.length;
|
|
3470
|
-
log("INFO", "language", "Appended
|
|
3952
|
+
log("INFO", "language", "Appended verify commands for new languages", {
|
|
3471
3953
|
added: [...fresh].join(","),
|
|
3472
3954
|
});
|
|
3473
3955
|
}
|
|
@@ -3503,7 +3985,7 @@ export class AgentSession {
|
|
|
3503
3985
|
return false;
|
|
3504
3986
|
}
|
|
3505
3987
|
if (grew) {
|
|
3506
|
-
log("INFO", "language", "
|
|
3988
|
+
log("INFO", "language", "Languages active", {
|
|
3507
3989
|
active: [...this.activeLanguages].join(","),
|
|
3508
3990
|
});
|
|
3509
3991
|
}
|
|
@@ -3518,6 +4000,13 @@ export class AgentSession {
|
|
|
3518
4000
|
return;
|
|
3519
4001
|
const rebuilt = await this.buildBasePrompt(this.planModeRef.current, this.approvedPlanPath);
|
|
3520
4002
|
this.baseSystemPrompt = rebuilt;
|
|
4003
|
+
this.promptPlanState = {
|
|
4004
|
+
planMode: this.planModeRef.current,
|
|
4005
|
+
approvedPlanPath: this.approvedPlanPath,
|
|
4006
|
+
};
|
|
4007
|
+
this.seenPlanState = this.promptPlanState;
|
|
4008
|
+
this.pendingPlanNotice = null;
|
|
4009
|
+
this.lastPlanNotice = null;
|
|
3521
4010
|
const content = this.withSystemPromptTail(rebuilt);
|
|
3522
4011
|
if (this.messages[0]?.role === "system") {
|
|
3523
4012
|
this.messages[0] = { role: "system", content };
|
|
@@ -3766,9 +4255,12 @@ export class AgentSession {
|
|
|
3766
4255
|
// if the user switches models while credential resolution is pending.
|
|
3767
4256
|
const { provider, model, thinkingLevel, baseUrl } = this;
|
|
3768
4257
|
const threshold = this.settingsManager.get("compactThreshold");
|
|
3769
|
-
const
|
|
3770
|
-
|
|
3771
|
-
|
|
4258
|
+
const claudeCode = await this.claudeCodeProcess();
|
|
4259
|
+
const creds = claudeCode
|
|
4260
|
+
? { accessToken: "" }
|
|
4261
|
+
: await this.authStorage.resolveCredentials(provider, {
|
|
4262
|
+
storageKeys: this.currentAuthStorageKeys(),
|
|
4263
|
+
});
|
|
3772
4264
|
const maxTokens = outputCapForRequest({
|
|
3773
4265
|
provider,
|
|
3774
4266
|
model,
|
|
@@ -3798,6 +4290,17 @@ export class AgentSession {
|
|
|
3798
4290
|
baseUrl: baseUrl ?? creds.baseUrl,
|
|
3799
4291
|
accountId: creds.accountId,
|
|
3800
4292
|
signal: this.opts.signal,
|
|
4293
|
+
...(claudeCode
|
|
4294
|
+
? {
|
|
4295
|
+
complete: (messages) => claudeCodeComplete({
|
|
4296
|
+
...claudeCode,
|
|
4297
|
+
model,
|
|
4298
|
+
messages,
|
|
4299
|
+
thinking: thinkingLevel,
|
|
4300
|
+
signal: this.opts.signal,
|
|
4301
|
+
}),
|
|
4302
|
+
}
|
|
4303
|
+
: {}),
|
|
3801
4304
|
});
|
|
3802
4305
|
}
|
|
3803
4306
|
/** Current reasoning/thinking level, or undefined when thinking is off. */
|
|
@@ -3825,7 +4328,38 @@ export class AgentSession {
|
|
|
3825
4328
|
runLoopDepth = 0;
|
|
3826
4329
|
lastRealRequestAt = 0;
|
|
3827
4330
|
lastPrewarmAt = 0;
|
|
4331
|
+
/** Last connection pre-open per provider origin (see {@link preconnect}). */
|
|
4332
|
+
preconnectedAt = new Map();
|
|
4333
|
+
/**
|
|
4334
|
+
* Fire-and-forget: open the TLS connection to the active provider before the
|
|
4335
|
+
* first request, through the shared keep-alive pool. Zero tokens — an
|
|
4336
|
+
* unauthenticated HEAD; skipped for local endpoints and throttled per origin.
|
|
4337
|
+
* Transient sessions (one-shot tools) and test runs never touch the network here.
|
|
4338
|
+
*/
|
|
4339
|
+
preconnect() {
|
|
4340
|
+
const enabled = this.opts.preconnect ?? (this.opts.transient !== true && !process.env.VITEST);
|
|
4341
|
+
if (!enabled)
|
|
4342
|
+
return;
|
|
4343
|
+
const provider = this.provider;
|
|
4344
|
+
void this.authStorage
|
|
4345
|
+
.resolveCredentials(provider, { storageKeys: this.currentAuthStorageKeys() })
|
|
4346
|
+
.then((creds) => {
|
|
4347
|
+
if (provider !== this.provider)
|
|
4348
|
+
return;
|
|
4349
|
+
preconnectProvider({
|
|
4350
|
+
provider,
|
|
4351
|
+
baseUrl: this.baseUrl ?? creds.baseUrl,
|
|
4352
|
+
accountId: creds.accountId,
|
|
4353
|
+
warmedAt: this.preconnectedAt,
|
|
4354
|
+
});
|
|
4355
|
+
})
|
|
4356
|
+
.catch(() => { });
|
|
4357
|
+
}
|
|
3828
4358
|
prewarmController = null;
|
|
4359
|
+
/** Claude Code session that has seen this history (Claude subscription route). */
|
|
4360
|
+
claudeCodeSession = null;
|
|
4361
|
+
/** This chat's running Claude Code process, reused while `key` (its start settings) matches. */
|
|
4362
|
+
claudeCodeLive = null;
|
|
3829
4363
|
/**
|
|
3830
4364
|
* Best-effort Anthropic prompt-cache prewarm before the user's next turn
|
|
3831
4365
|
* (desktop app calls this on the first keystroke after opening a chat or an
|
|
@@ -3834,6 +4368,11 @@ export class AgentSession {
|
|
|
3834
4368
|
* first real reply is a cache read instead of a cold write.
|
|
3835
4369
|
*/
|
|
3836
4370
|
async prewarm(signal) {
|
|
4371
|
+
// Claude Code keeps its own cache; there is no request prefix of ours to warm.
|
|
4372
|
+
if (await this.claudeCodeProcess().catch(() => null))
|
|
4373
|
+
return { ok: false, reason: "claude_code" };
|
|
4374
|
+
// Every provider: the user is typing, so the first request is seconds away.
|
|
4375
|
+
this.preconnect();
|
|
3837
4376
|
if (this.provider !== "anthropic")
|
|
3838
4377
|
return { ok: false, reason: "provider" };
|
|
3839
4378
|
if (this.settingsManager?.get("cachePrewarm") === false) {
|
|
@@ -3892,11 +4431,13 @@ export class AgentSession {
|
|
|
3892
4431
|
model: this.model,
|
|
3893
4432
|
messages,
|
|
3894
4433
|
tools: this.tools,
|
|
4434
|
+
deferredTools: this.deferredToolCatalog,
|
|
3895
4435
|
webSearch: this.nativeWebSearchOn(),
|
|
3896
4436
|
maxTokens: this.requestMaxTokens(creds.accountId),
|
|
3897
4437
|
thinking: this.planModeRef.current
|
|
3898
4438
|
? clampThinkingForPlanMode(this.thinkingLevel)
|
|
3899
4439
|
: this.thinkingLevel,
|
|
4440
|
+
...(modelInfo?.thinkingLevels ? { thinkingLevels: modelInfo.thinkingLevels } : {}),
|
|
3900
4441
|
apiKey: creds.accessToken,
|
|
3901
4442
|
baseUrl: this.baseUrl ?? creds.baseUrl,
|
|
3902
4443
|
accountId: creds.accountId,
|
|
@@ -3993,8 +4534,18 @@ export class AgentSession {
|
|
|
3993
4534
|
// the background compact() snapshots and replaces `this.messages`, so
|
|
3994
4535
|
// letting it run past this point would checkpoint a near-empty history
|
|
3995
4536
|
// and leak a junk session file after teardown.
|
|
3996
|
-
|
|
3997
|
-
|
|
4537
|
+
// Capped: a hung summary call must not hold MCP/LSP/sub-agent teardown and
|
|
4538
|
+
// window close hostage. Past the cap it is aborted (compact() checks the
|
|
4539
|
+
// signal before replacing history), with a short grace to unwind.
|
|
4540
|
+
if (this.postTurnCompaction) {
|
|
4541
|
+
const pending = this.postTurnCompaction;
|
|
4542
|
+
const settledInTime = await settleWithin(pending, DISPOSE_COMPACTION_WAIT_MS);
|
|
4543
|
+
if (!settledInTime) {
|
|
4544
|
+
log("WARN", "compaction", "Post-turn compaction still running at dispose — aborting");
|
|
4545
|
+
this.postTurnCompactionAbort?.abort();
|
|
4546
|
+
await settleWithin(pending, DISPOSE_COMPACTION_ABORT_GRACE_MS);
|
|
4547
|
+
}
|
|
4548
|
+
}
|
|
3998
4549
|
this.cacheDiagnostics.reset();
|
|
3999
4550
|
this.diagnosticsRecorder?.finalize();
|
|
4000
4551
|
this.managerAbortSignal?.removeEventListener("abort", this.managerAbortHandler);
|
|
@@ -4043,14 +4594,28 @@ export class AgentSession {
|
|
|
4043
4594
|
: await this.sessionManager.load(sessionPath);
|
|
4044
4595
|
// Use the leaf from the header to walk the correct branch
|
|
4045
4596
|
const loadedMessages = this.sessionManager.getMessages(loaded.entries, loaded.header.leafId);
|
|
4046
|
-
|
|
4047
|
-
|
|
4048
|
-
|
|
4597
|
+
// One backward scan for both latest host checkpoints (no full copies).
|
|
4598
|
+
let savedCompletionReview;
|
|
4599
|
+
let savedVerification;
|
|
4600
|
+
let savedClaudeCode;
|
|
4601
|
+
for (let i = loaded.entries.length - 1; i >= 0; i--) {
|
|
4602
|
+
if (savedCompletionReview && savedVerification && savedClaudeCode)
|
|
4603
|
+
break;
|
|
4604
|
+
const entry = loaded.entries[i];
|
|
4605
|
+
if (entry?.type !== "custom")
|
|
4606
|
+
continue;
|
|
4607
|
+
if (!savedClaudeCode && entry.kind === CLAUDE_CODE_SESSION_KIND) {
|
|
4608
|
+
savedClaudeCode = entry;
|
|
4609
|
+
}
|
|
4610
|
+
else if (!savedCompletionReview && entry.kind === COMPLETION_REVIEW_STATE_KIND) {
|
|
4611
|
+
savedCompletionReview = entry;
|
|
4612
|
+
}
|
|
4613
|
+
else if (!savedVerification && entry.kind === VERIFICATION_STATE_KIND) {
|
|
4614
|
+
savedVerification = entry;
|
|
4615
|
+
}
|
|
4616
|
+
}
|
|
4049
4617
|
this.opts.completionReview?.restore(savedCompletionReview?.type === "custom" ? savedCompletionReview.data : null);
|
|
4050
4618
|
this.verificationTracker.clearBackground();
|
|
4051
|
-
const savedVerification = [...loaded.entries]
|
|
4052
|
-
.reverse()
|
|
4053
|
-
.find((entry) => entry.type === "custom" && entry.kind === VERIFICATION_STATE_KIND);
|
|
4054
4619
|
if (savedVerification?.type === "custom") {
|
|
4055
4620
|
this.verificationGate.restore(savedVerification.data);
|
|
4056
4621
|
}
|
|
@@ -4090,6 +4655,7 @@ export class AgentSession {
|
|
|
4090
4655
|
// not fail when Anthropic's stricter many-image limit activates later.
|
|
4091
4656
|
const systemMsg = this.messages[0]; // Already built
|
|
4092
4657
|
this.messages = [systemMsg, ...loadedMessages];
|
|
4658
|
+
this.claudeCodeSession = parseClaudeCodeSessionState(savedClaudeCode?.type === "custom" ? savedClaudeCode.data : null, loadedMessages);
|
|
4093
4659
|
// Reads recorded for the previous conversation don't carry over.
|
|
4094
4660
|
this.clearReadTracker?.();
|
|
4095
4661
|
const normalizedImageCount = await normalizeMessageImages(this.messages);
|
|
@@ -4129,6 +4695,7 @@ export class AgentSession {
|
|
|
4129
4695
|
model: this.model,
|
|
4130
4696
|
contextWindow,
|
|
4131
4697
|
threshold: this.settingsManager.get("compactThreshold"),
|
|
4698
|
+
compactAtTokens: this.settingsManager.get("compactAtTokens"),
|
|
4132
4699
|
accountId: creds?.accountId,
|
|
4133
4700
|
approvedPlanPath: this.approvedPlanPath,
|
|
4134
4701
|
});
|
|
@@ -4235,7 +4802,9 @@ export class AgentSession {
|
|
|
4235
4802
|
},
|
|
4236
4803
|
getModelList: () => {
|
|
4237
4804
|
const current = `Current: ${this.provider}:${this.model}\n\nAvailable models:\n`;
|
|
4238
|
-
const list =
|
|
4805
|
+
const list = getListedModels()
|
|
4806
|
+
.map((m) => ` ${m.provider}:${m.id} — ${m.name} (${m.costTier})`)
|
|
4807
|
+
.join("\n");
|
|
4239
4808
|
return current + list;
|
|
4240
4809
|
},
|
|
4241
4810
|
quit: () => {
|