@zergai/ztc 0.4.0-beta.1 → 0.5.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +398 -45
- package/RUST_THIRD_PARTY_LICENSES.txt +1080 -822
- package/THIRD_PARTY_NOTICES.md +273 -12
- package/bin/zmux-darwin-arm64 +0 -0
- package/bin/ztc-audio-darwin-arm64 +0 -0
- package/bin/ztc-capture-darwin-arm64 +0 -0
- package/bin/ztc-computer-darwin-arm64 +0 -0
- package/bin/ztc-llm-darwin-arm64 +0 -0
- package/bin/ztc-tts-darwin-arm64 +0 -0
- package/bin/ztc-tui-darwin-arm64 +0 -0
- package/bin/ztc-zlicky-overlay-darwin-arm64 +0 -0
- package/bin/zterm-darwin-arm64 +0 -0
- package/dist/App.js +1206 -209
- package/dist/agent/agent.d.ts +74 -8
- package/dist/agent/agent.js +1073 -184
- package/dist/agent/backends/account_rotation.d.ts +4 -0
- package/dist/agent/backends/account_rotation.js +8 -2
- package/dist/agent/backends/anthropic.d.ts +13 -0
- package/dist/agent/backends/anthropic.js +169 -28
- package/dist/agent/backends/claude_cli.js +18 -8
- package/dist/agent/backends/codex_app_server.d.ts +1 -0
- package/dist/agent/backends/codex_app_server.js +55 -3
- package/dist/agent/backends/codex_auth.d.ts +1 -0
- package/dist/agent/backends/codex_auth.js +67 -13
- package/dist/agent/backends/codex_buffered_recovery.d.ts +27 -0
- package/dist/agent/backends/codex_buffered_recovery.js +293 -0
- package/dist/agent/backends/gemini.js +3 -1
- package/dist/agent/backends/http_error.d.ts +26 -0
- package/dist/agent/backends/http_error.js +221 -0
- package/dist/agent/backends/index.d.ts +9 -2
- package/dist/agent/backends/index.js +22 -2
- package/dist/agent/backends/openai.d.ts +0 -6
- package/dist/agent/backends/openai.js +5 -2
- package/dist/agent/backends/openai_compatible.d.ts +5 -4
- package/dist/agent/backends/openai_compatible.js +26 -19
- package/dist/agent/backends/openai_responses.d.ts +8 -3
- package/dist/agent/backends/openai_responses.js +77 -33
- package/dist/agent/backends/provider_ids.d.ts +1 -0
- package/dist/agent/backends/provider_ids.js +4 -0
- package/dist/agent/backends/request_metrics.js +12 -2
- package/dist/agent/backends/types.d.ts +109 -6
- package/dist/agent/backends/types.js +5 -1
- package/dist/agent/backends/zrouter_stream.d.ts +6 -1
- package/dist/agent/backends/zrouter_stream.js +160 -42
- package/dist/agent/background_registry.d.ts +2 -0
- package/dist/agent/background_registry.js +1 -0
- package/dist/agent/claim_observation.d.ts +6 -0
- package/dist/agent/claim_observation.js +54 -0
- package/dist/agent/commands/accounts.js +46 -177
- package/dist/agent/commands/attention.d.ts +2 -0
- package/dist/agent/commands/attention.js +67 -0
- package/dist/agent/commands/auth.js +18 -2
- package/dist/agent/commands/board.d.ts +2 -0
- package/dist/agent/commands/board.js +169 -0
- package/dist/agent/commands/clipboard.js +50 -1
- package/dist/agent/commands/compact.js +21 -13
- package/dist/agent/commands/config.js +4 -1
- package/dist/agent/commands/context.js +6 -1
- package/dist/agent/commands/desktop.d.ts +2 -0
- package/dist/agent/commands/desktop.js +29 -0
- package/dist/agent/commands/effort.js +14 -6
- package/dist/agent/commands/environment.d.ts +3 -0
- package/dist/agent/commands/environment.js +109 -0
- package/dist/agent/commands/evidence.d.ts +2 -0
- package/dist/agent/commands/evidence.js +9 -0
- package/dist/agent/commands/fork.js +4 -3
- package/dist/agent/commands/goal.d.ts +33 -1
- package/dist/agent/commands/goal.js +174 -14
- package/dist/agent/commands/goal_exit.d.ts +36 -0
- package/dist/agent/commands/goal_exit.js +120 -0
- package/dist/agent/commands/help.js +3 -1
- package/dist/agent/commands/history.js +3 -1
- package/dist/agent/commands/inbox.d.ts +2 -0
- package/dist/agent/commands/inbox.js +148 -0
- package/dist/agent/commands/index.js +16 -1
- package/dist/agent/commands/input_mode.js +8 -6
- package/dist/agent/commands/job.d.ts +2 -0
- package/dist/agent/commands/job.js +93 -0
- package/dist/agent/commands/keybindings.js +4 -1
- package/dist/agent/commands/label.d.ts +2 -0
- package/dist/agent/commands/label.js +77 -0
- package/dist/agent/commands/layout.d.ts +2 -0
- package/dist/agent/commands/layout.js +20 -0
- package/dist/agent/commands/mirror.js +16 -1
- package/dist/agent/commands/model.js +12 -2
- package/dist/agent/commands/permissions.d.ts +3 -1
- package/dist/agent/commands/permissions.js +79 -89
- package/dist/agent/commands/plan.js +5 -15
- package/dist/agent/commands/profile.js +21 -2
- package/dist/agent/commands/provider_selection.js +20 -1
- package/dist/agent/commands/rename.js +1 -1
- package/dist/agent/commands/resources.d.ts +2 -0
- package/dist/agent/commands/resources.js +67 -0
- package/dist/agent/commands/rewind.d.ts +3 -0
- package/dist/agent/commands/rewind.js +16 -0
- package/dist/agent/commands/runbooks.d.ts +2 -0
- package/dist/agent/commands/runbooks.js +73 -0
- package/dist/agent/commands/runbooks_lazy.d.ts +2 -0
- package/dist/agent/commands/runbooks_lazy.js +8 -0
- package/dist/agent/commands/sessions.d.ts +1 -1
- package/dist/agent/commands/sessions.js +33 -5
- package/dist/agent/commands/settings.js +185 -39
- package/dist/agent/commands/setup.d.ts +2 -0
- package/dist/agent/commands/setup.js +78 -0
- package/dist/agent/commands/share.d.ts +2 -0
- package/dist/agent/commands/share.js +64 -0
- package/dist/agent/commands/status.js +14 -2
- package/dist/agent/commands/types.d.ts +99 -6
- package/dist/agent/commands/update.js +8 -0
- package/dist/agent/commands/usage.d.ts +2 -0
- package/dist/agent/commands/usage.js +8 -0
- package/dist/agent/factory.d.ts +11 -0
- package/dist/agent/factory.js +113 -88
- package/dist/agent/loop_policy.d.ts +6 -3
- package/dist/agent/loop_policy.js +12 -3
- package/dist/agent/measurement_guidance.d.ts +2 -0
- package/dist/agent/measurement_guidance.js +5 -0
- package/dist/agent/request_encoder.d.ts +8 -1
- package/dist/agent/request_encoder.js +95 -23
- package/dist/agent/runtime/benchmark_comparison.d.ts +30 -0
- package/dist/agent/runtime/benchmark_comparison.js +94 -0
- package/dist/agent/runtime/benchmark_contract.d.ts +48 -0
- package/dist/agent/runtime/benchmark_contract.js +90 -0
- package/dist/agent/runtime/checked_commands.d.ts +32 -0
- package/dist/agent/runtime/checked_commands.js +119 -0
- package/dist/agent/runtime/command_execution_policy.d.ts +26 -0
- package/dist/agent/runtime/command_execution_policy.js +91 -0
- package/dist/agent/runtime/command_jobs.d.ts +36 -18
- package/dist/agent/runtime/command_jobs.js +151 -13
- package/dist/agent/runtime/command_panes.d.ts +59 -0
- package/dist/agent/runtime/command_panes.js +398 -0
- package/dist/agent/runtime/command_wait.d.ts +19 -0
- package/dist/agent/runtime/command_wait.js +167 -0
- package/dist/agent/runtime/cpu_benchmark.d.ts +30 -0
- package/dist/agent/runtime/cpu_benchmark.js +126 -0
- package/dist/agent/runtime/delegated_evidence.d.ts +26 -0
- package/dist/agent/runtime/delegated_evidence.js +80 -0
- package/dist/agent/runtime/evidence.d.ts +127 -0
- package/dist/agent/runtime/evidence.js +468 -0
- package/dist/agent/runtime/execution_context.d.ts +7 -0
- package/dist/agent/runtime/execution_context.js +39 -3
- package/dist/agent/runtime/json_verifier_recipe.d.ts +8 -0
- package/dist/agent/runtime/json_verifier_recipe.js +66 -0
- package/dist/agent/runtime/measurements.d.ts +110 -0
- package/dist/agent/runtime/measurements.js +317 -0
- package/dist/agent/runtime/policy.d.ts +4 -0
- package/dist/agent/runtime/policy.js +31 -20
- package/dist/agent/runtime/provider_native_evidence.d.ts +20 -0
- package/dist/agent/runtime/provider_native_evidence.js +86 -0
- package/dist/agent/runtime/recovery.d.ts +2 -0
- package/dist/agent/runtime/recovery.js +45 -2
- package/dist/agent/runtime/remote_broker_transport.d.ts +10 -0
- package/dist/agent/runtime/remote_broker_transport.js +84 -0
- package/dist/agent/runtime/remote_deletion_receipts.d.ts +3 -0
- package/dist/agent/runtime/remote_deletion_receipts.js +43 -0
- package/dist/agent/runtime/remote_journal_replay.d.ts +13 -0
- package/dist/agent/runtime/remote_journal_replay.js +233 -0
- package/dist/agent/runtime/remote_mutation_journal.d.ts +25 -0
- package/dist/agent/runtime/remote_mutation_journal.js +208 -0
- package/dist/agent/runtime/remote_resource_endpoint.d.ts +7 -0
- package/dist/agent/runtime/remote_resource_endpoint.js +6 -0
- package/dist/agent/runtime/remote_resource_errors.d.ts +5 -0
- package/dist/agent/runtime/remote_resource_errors.js +9 -0
- package/dist/agent/runtime/remote_resource_script.d.ts +2 -0
- package/dist/agent/runtime/remote_resource_script.js +1009 -0
- package/dist/agent/runtime/remote_resources.d.ts +29 -0
- package/dist/agent/runtime/remote_resources.js +160 -0
- package/dist/agent/runtime/source_verification.d.ts +12 -0
- package/dist/agent/runtime/source_verification.js +210 -0
- package/dist/agent/runtime/source_verification_contract.d.ts +75 -0
- package/dist/agent/runtime/source_verification_contract.js +203 -0
- package/dist/agent/runtime/tool_checkpoints.d.ts +11 -0
- package/dist/agent/runtime/tool_checkpoints.js +26 -0
- package/dist/agent/runtime/tool_effects.d.ts +5 -0
- package/dist/agent/runtime/tool_progress.d.ts +12 -0
- package/dist/agent/runtime/tool_progress.js +76 -0
- package/dist/agent/runtime/tool_runtime.d.ts +16 -1
- package/dist/agent/runtime/tool_runtime.js +204 -10
- package/dist/agent/runtime/tracing.d.ts +1 -1
- package/dist/agent/runtime/verifier_capture.d.ts +9 -0
- package/dist/agent/runtime/verifier_capture.js +100 -0
- package/dist/agent/runtime/verifier_contract.d.ts +24 -0
- package/dist/agent/runtime/verifier_contract.js +41 -0
- package/dist/agent/subagent.d.ts +20 -10
- package/dist/agent/subagent.js +266 -29
- package/dist/agent/tool_response_directory.d.ts +24 -0
- package/dist/agent/tool_response_directory.js +61 -0
- package/dist/agent/tool_response_source.d.ts +8 -0
- package/dist/agent/tool_response_source.js +49 -0
- package/dist/agent/tool_response_store.d.ts +75 -4
- package/dist/agent/tool_response_store.js +583 -64
- package/dist/agent/tools/ask_user.d.ts +3 -1
- package/dist/agent/tools/ask_user.js +30 -11
- package/dist/agent/tools/background.js +1 -0
- package/dist/agent/tools/benchmark_cpu.d.ts +2 -0
- package/dist/agent/tools/benchmark_cpu.js +102 -0
- package/dist/agent/tools/compare_benchmarks.d.ts +2 -0
- package/dist/agent/tools/compare_benchmarks.js +53 -0
- package/dist/agent/tools/deferred.js +1 -0
- package/dist/agent/tools/delegate.js +18 -2
- package/dist/agent/tools/helper_requirements.d.ts +7 -0
- package/dist/agent/tools/helper_requirements.js +19 -0
- package/dist/agent/tools/index.d.ts +1 -0
- package/dist/agent/tools/index.js +3 -0
- package/dist/agent/tools/measurement_report.d.ts +22 -0
- package/dist/agent/tools/measurement_report.js +190 -0
- package/dist/agent/tools/pane.d.ts +0 -7
- package/dist/agent/tools/pane.js +5 -4
- package/dist/agent/tools/project_context.d.ts +3 -0
- package/dist/agent/tools/project_context.js +45 -0
- package/dist/agent/tools/recall_tool_response.d.ts +3 -5
- package/dist/agent/tools/recall_tool_response.js +19 -29
- package/dist/agent/tools/registry.d.ts +1 -0
- package/dist/agent/tools/registry.js +23 -0
- package/dist/agent/tools/related_sessions.d.ts +2 -0
- package/dist/agent/tools/related_sessions.js +156 -0
- package/dist/agent/tools/routine.js +13 -3
- package/dist/agent/tools/session_evidence.d.ts +3 -0
- package/dist/agent/tools/session_evidence.js +72 -0
- package/dist/agent/tools/shell.d.ts +4 -3
- package/dist/agent/tools/shell.js +174 -47
- package/dist/agent/tools/tool_search.js +3 -2
- package/dist/agent/tools/types.d.ts +28 -0
- package/dist/agent/tools/verify_artifact.d.ts +2 -0
- package/dist/agent/tools/verify_artifact.js +60 -0
- package/dist/agent/tools/workflow.js +1 -0
- package/dist/app/activity.d.ts +6 -1
- package/dist/app/activity.js +81 -12
- package/dist/app/agent_runner.d.ts +6 -1
- package/dist/app/agent_runner.js +34 -19
- package/dist/app/command_context.js +106 -10
- package/dist/app/controller.d.ts +15 -4
- package/dist/app/controller.js +29 -3
- package/dist/app/escape_stop.d.ts +11 -0
- package/dist/app/escape_stop.js +15 -0
- package/dist/app/liveness.d.ts +6 -4
- package/dist/app/liveness.js +13 -3
- package/dist/app/model_catalog_cache.d.ts +5 -0
- package/dist/app/model_catalog_cache.js +138 -0
- package/dist/app/ordered_transcript.js +43 -4
- package/dist/app/prompt_turn.d.ts +14 -0
- package/dist/app/prompt_turn.js +53 -0
- package/dist/app/recap.d.ts +3 -0
- package/dist/app/recap.js +9 -3
- package/dist/app/restart.d.ts +3 -2
- package/dist/app/restart.js +22 -7
- package/dist/app/rewind.d.ts +3 -3
- package/dist/app/rewind.js +3 -3
- package/dist/app/selection_completion.d.ts +17 -2
- package/dist/app/selection_completion.js +84 -9
- package/dist/app/session_manager.d.ts +38 -6
- package/dist/app/session_manager.js +263 -60
- package/dist/app/session_messages.d.ts +3 -0
- package/dist/app/session_messages.js +60 -0
- package/dist/app/task_scope_router.d.ts +20 -0
- package/dist/app/task_scope_router.js +173 -0
- package/dist/app/transcript_window.d.ts +2 -0
- package/dist/app/transcript_window.js +4 -0
- package/dist/app/workspace_admission_details.d.ts +3 -0
- package/dist/app/workspace_admission_details.js +26 -0
- package/dist/app/workspace_layout_controller.d.ts +11 -0
- package/dist/app/workspace_layout_controller.js +88 -0
- package/dist/app/workspace_monitor.d.ts +1 -0
- package/dist/app/workspace_monitor.js +216 -0
- package/dist/app/workspace_presets.d.ts +29 -0
- package/dist/app/workspace_presets.js +192 -0
- package/dist/attention/queue.d.ts +37 -0
- package/dist/attention/queue.js +183 -0
- package/dist/bench/rf_shared.d.ts +2 -0
- package/dist/board/binding.d.ts +42 -0
- package/dist/board/binding.js +38 -0
- package/dist/board/client.d.ts +42 -0
- package/dist/board/client.js +60 -0
- package/dist/cli.js +1 -1
- package/dist/cli_args.js +19 -17
- package/dist/cli_main.js +110 -13
- package/dist/cli_ratatui.d.ts +183 -16
- package/dist/cli_ratatui.js +3989 -1255
- package/dist/components/ActivityLine.d.ts +3 -2
- package/dist/components/ActivityLine.js +2 -2
- package/dist/components/InputArea.d.ts +19 -1
- package/dist/components/InputArea.js +264 -190
- package/dist/components/MessageList.d.ts +2 -0
- package/dist/components/MessageList.js +3 -1
- package/dist/components/SingleMessage.d.ts +2 -0
- package/dist/components/SingleMessage.js +4 -2
- package/dist/components/StatusBar.d.ts +4 -2
- package/dist/components/StatusBar.js +3 -1
- package/dist/conductor_branch.js +3 -0
- package/dist/config/api_retry.d.ts +6 -1
- package/dist/config/api_retry.js +19 -1
- package/dist/config/defaults.d.ts +2 -1
- package/dist/config/defaults.js +9 -2
- package/dist/config/message_display.d.ts +1 -0
- package/dist/config/message_display.js +17 -2
- package/dist/config/permissions.d.ts +21 -0
- package/dist/config/permissions.js +89 -0
- package/dist/config/resolved.d.ts +2 -2
- package/dist/config/types.d.ts +32 -5
- package/dist/config.d.ts +38 -4
- package/dist/config.js +290 -42
- package/dist/context/project_intelligence.d.ts +44 -0
- package/dist/context/project_intelligence.js +246 -0
- package/dist/desktop/cli_launch.d.ts +8 -0
- package/dist/desktop/cli_launch.js +6 -0
- package/dist/desktop/cli_shim.d.ts +8 -0
- package/dist/desktop/cli_shim.js +120 -0
- package/dist/desktop/runtime.d.ts +16 -0
- package/dist/desktop/runtime.js +161 -0
- package/dist/desktop/worker_launch.d.ts +7 -0
- package/dist/desktop/worker_launch.js +7 -0
- package/dist/diagnostics/cargo_mutants_selection.d.ts +27 -0
- package/dist/diagnostics/cargo_mutants_selection.js +48 -0
- package/dist/diagnostics/native_terminal_benchmark.d.ts +58 -0
- package/dist/diagnostics/native_terminal_benchmark.js +1247 -0
- package/dist/diagnostics/session_evidence_package.d.ts +40 -0
- package/dist/diagnostics/session_evidence_package.js +234 -0
- package/dist/diagnostics/session_export.d.ts +93 -0
- package/dist/diagnostics/session_export.js +634 -0
- package/dist/emulation/tool_adapters.js +48 -18
- package/dist/emulation/ztc_addendum.d.ts +1 -0
- package/dist/emulation/ztc_addendum.js +13 -12
- package/dist/environment/service_runner.d.ts +1 -0
- package/dist/environment/service_runner.js +68 -0
- package/dist/environment/store.d.ts +120 -0
- package/dist/environment/store.js +387 -0
- package/dist/events.d.ts +40 -1
- package/dist/events.js +10 -17
- package/dist/goal_contract.d.ts +25 -0
- package/dist/goal_contract.js +44 -0
- package/dist/headless.d.ts +31 -0
- package/dist/headless.js +578 -70
- package/dist/headless_cli.js +8 -0
- package/dist/headless_cli_args.d.ts +1 -0
- package/dist/headless_cli_args.js +1 -0
- package/dist/intake/cli.d.ts +1 -0
- package/dist/intake/cli.js +33 -0
- package/dist/intake/format.d.ts +2 -0
- package/dist/intake/format.js +14 -0
- package/dist/intake/notifications.d.ts +16 -0
- package/dist/intake/notifications.js +132 -0
- package/dist/intake/store.d.ts +56 -0
- package/dist/intake/store.js +238 -0
- package/dist/library.d.ts +8 -0
- package/dist/library.js +19 -10
- package/dist/mcp/client.d.ts +1 -0
- package/dist/mcp/client.js +20 -0
- package/dist/modes/builtin/plan.yaml +2 -2
- package/dist/modes/handlers.js +1 -1
- package/dist/onboarding/first_run.d.ts +3 -0
- package/dist/onboarding/first_run.js +33 -25
- package/dist/onboarding/setup.d.ts +32 -0
- package/dist/onboarding/setup.js +133 -0
- package/dist/onboarding/setup_agent_health.d.ts +17 -0
- package/dist/onboarding/setup_agent_health.js +79 -0
- package/dist/onboarding/setup_environment.d.ts +66 -0
- package/dist/onboarding/setup_environment.js +219 -0
- package/dist/onboarding/setup_workspace.d.ts +17 -0
- package/dist/onboarding/setup_workspace.js +129 -0
- package/dist/optimize/adapters/index.d.ts +4 -1
- package/dist/optimize/adapters/index.js +7 -0
- package/dist/optimize/adapters/kernelbench.js +14 -5
- package/dist/optimize/adapters/popcorn.js +3 -2
- package/dist/optimize/adapters/profile_benchmark.js +13 -7
- package/dist/optimize/adapters/rfbench.js +25 -14
- package/dist/optimize/adapters/types.d.ts +3 -0
- package/dist/optimize/adapters/zergpod.js +5 -2
- package/dist/optimize/baseline.js +10 -21
- package/dist/optimize/branch.js +9 -12
- package/dist/optimize/combine.js +2 -3
- package/dist/optimize/executor.js +34 -48
- package/dist/optimize/measurements.d.ts +55 -0
- package/dist/optimize/measurements.js +173 -0
- package/dist/optimize/results.d.ts +1 -0
- package/dist/optimize/results.js +11 -33
- package/dist/optimize/tge.js +2 -1
- package/dist/panes/initial_input.d.ts +19 -0
- package/dist/panes/initial_input.js +206 -0
- package/dist/panes/labels.d.ts +16 -0
- package/dist/panes/labels.js +42 -0
- package/dist/panes/model_catalog.d.ts +3 -3
- package/dist/panes/model_catalog.js +28 -4
- package/dist/panes/pane_registry.js +6 -2
- package/dist/panes/types.d.ts +3 -0
- package/dist/panes/ztc_launch.js +19 -0
- package/dist/plugin/optimization.d.ts +2 -0
- package/dist/plugin/optimization.js +1 -0
- package/dist/plugin/runtime.d.ts +2 -0
- package/dist/plugin/simulation.d.ts +6 -1
- package/dist/plugin/simulation_contract.d.ts +836 -1
- package/dist/plugin/simulation_documents.d.ts +22 -0
- package/dist/plugin/simulation_documents.js +1 -0
- package/dist/plugin/simulation_interventions.d.ts +103 -0
- package/dist/plugin/simulation_interventions.js +1 -0
- package/dist/plugin/simulation_living.d.ts +1 -0
- package/dist/plugin/simulation_living.js +3 -0
- package/dist/plugin/simulation_meetings.d.ts +121 -0
- package/dist/plugin/simulation_meetings.js +1 -0
- package/dist/plugin/simulation_story_review.d.ts +111 -0
- package/dist/plugin/simulation_story_review.js +1 -0
- package/dist/plugin/simulation_storyteller.d.ts +91 -0
- package/dist/plugin/simulation_storyteller.js +1 -0
- package/dist/plugin/simulation_structured.d.ts +2 -0
- package/dist/plugin/simulation_structured.js +2 -0
- package/dist/plugin/simulation_toolkit.d.ts +21 -0
- package/dist/plugin/simulation_toolkit.js +24 -0
- package/dist/prompts/tool_delegate_task.j2 +1 -1
- package/dist/remote-broker/Dockerfile +10 -0
- package/dist/remote-broker/archive.py +1227 -0
- package/dist/remote-broker/cutover.py +761 -0
- package/dist/remote-broker/requirements.txt +5 -0
- package/dist/remote-broker/resources.json +6 -0
- package/dist/remote-broker/resources.write-staging.example.json +18 -0
- package/dist/remote-broker/retained.py +686 -0
- package/dist/remote-broker/retained_cleanup.py +550 -0
- package/dist/remote-broker/server.py +648 -0
- package/dist/remote-broker/worker.py +1007 -0
- package/dist/router_auth.d.ts +31 -0
- package/dist/router_auth.js +155 -9
- package/dist/runbooks/catalog.d.ts +3 -0
- package/dist/runbooks/catalog.js +26 -0
- package/dist/runbooks/library.d.ts +11 -0
- package/dist/runbooks/library.js +95 -0
- package/dist/runbooks/package.d.ts +43 -0
- package/dist/runbooks/package.js +102 -0
- package/dist/session.d.ts +65 -13
- package/dist/session.js +548 -43
- package/dist/session_handoff.d.ts +25 -0
- package/dist/session_handoff.js +322 -0
- package/dist/session_handoff_contract.d.ts +89 -0
- package/dist/session_handoff_contract.js +179 -0
- package/dist/session_media.d.ts +41 -0
- package/dist/session_media.js +357 -0
- package/dist/session_ownership.d.ts +16 -0
- package/dist/session_ownership.js +221 -0
- package/dist/session_public.d.ts +10 -2
- package/dist/session_public.js +6 -1
- package/dist/simulation/dynamic_history.d.ts +42 -0
- package/dist/simulation/dynamic_history.js +173 -0
- package/dist/simulation/engines/swarm/pane_manager.js +7 -6
- package/dist/simulation/inference.d.ts +3 -1
- package/dist/simulation/inference.js +19 -1
- package/dist/simulation/intervention_generation.d.ts +27 -0
- package/dist/simulation/intervention_generation.js +246 -0
- package/dist/simulation/intervention_material.d.ts +4 -0
- package/dist/simulation/intervention_material.js +81 -0
- package/dist/simulation/living/context.d.ts +3130 -0
- package/dist/simulation/living/context.js +944 -0
- package/dist/simulation/living/definer.d.ts +12 -0
- package/dist/simulation/living/definer.js +223 -0
- package/dist/simulation/living/definition.d.ts +257 -0
- package/dist/simulation/living/definition.js +341 -0
- package/dist/simulation/living/frame.d.ts +259 -0
- package/dist/simulation/living/frame.js +223 -0
- package/dist/simulation/living/identifiers.d.ts +2 -0
- package/dist/simulation/living/identifiers.js +12 -0
- package/dist/simulation/living/index.d.ts +15 -0
- package/dist/simulation/living/index.js +15 -0
- package/dist/simulation/living/inference.d.ts +219 -0
- package/dist/simulation/living/inference.js +576 -0
- package/dist/simulation/living/mechanics.d.ts +54 -0
- package/dist/simulation/living/mechanics.js +588 -0
- package/dist/simulation/living/model-input.d.ts +25 -0
- package/dist/simulation/living/model-input.js +215 -0
- package/dist/simulation/living/open-world.d.ts +257 -0
- package/dist/simulation/living/open-world.js +102 -0
- package/dist/simulation/living/projection.d.ts +7 -0
- package/dist/simulation/living/projection.js +31 -0
- package/dist/simulation/living/recall.d.ts +17 -0
- package/dist/simulation/living/recall.js +25 -0
- package/dist/simulation/living/reduce.d.ts +15 -0
- package/dist/simulation/living/reduce.js +1853 -0
- package/dist/simulation/living/replay.d.ts +6 -0
- package/dist/simulation/living/replay.js +22 -0
- package/dist/simulation/living/runtime.d.ts +140 -0
- package/dist/simulation/living/runtime.js +3020 -0
- package/dist/simulation/living/shared-kinds.d.ts +24 -0
- package/dist/simulation/living/shared-kinds.js +96 -0
- package/dist/simulation/living/types.d.ts +2785 -0
- package/dist/simulation/living/types.js +669 -0
- package/dist/simulation/llm.d.ts +3 -1
- package/dist/simulation/llm.js +90 -30
- package/dist/simulation/memory/embedding.d.ts +1 -1
- package/dist/simulation/memory/embedding.js +9 -3
- package/dist/simulation/memory/filesystem.d.ts +2 -0
- package/dist/simulation/memory/filesystem.js +5 -1
- package/dist/simulation/memory/filesystem_file_tree.d.ts +4 -1
- package/dist/simulation/memory/filesystem_file_tree.js +41 -10
- package/dist/simulation/memory/filesystem_invariants.js +1 -2
- package/dist/simulation/memory/filesystem_types.d.ts +1 -0
- package/dist/simulation/memory/memory.d.ts +2 -0
- package/dist/simulation/memory/memory.js +5 -1
- package/dist/simulation/orchestration/intent.js +0 -2
- package/dist/simulation/orchestration/lifecycle.js +0 -2
- package/dist/simulation/plugin_host.d.ts +25 -1
- package/dist/simulation/plugin_host.js +334 -17
- package/dist/simulation/session_documents.d.ts +20 -0
- package/dist/simulation/session_documents.js +62 -0
- package/dist/simulation/session_input_validation.d.ts +43 -0
- package/dist/simulation/session_input_validation.js +364 -0
- package/dist/simulation/session_inputs.d.ts +32 -0
- package/dist/simulation/session_inputs.js +154 -0
- package/dist/simulation/telemetry.d.ts +11 -14
- package/dist/simulation/telemetry.js +177 -54
- package/dist/simulation/toolkit/bounded_turns.d.ts +13 -0
- package/dist/simulation/toolkit/bounded_turns.js +80 -0
- package/dist/simulation/toolkit/dynamic_agents.d.ts +25 -0
- package/dist/simulation/toolkit/dynamic_agents.js +218 -0
- package/dist/simulation/toolkit/dynamic_digest.d.ts +1 -0
- package/dist/simulation/toolkit/dynamic_digest.js +8 -0
- package/dist/simulation/toolkit/dynamic_documents.d.ts +7 -0
- package/dist/simulation/toolkit/dynamic_documents.js +71 -0
- package/dist/simulation/toolkit/dynamic_driver.d.ts +8 -0
- package/dist/simulation/toolkit/dynamic_driver.js +269 -0
- package/dist/simulation/toolkit/dynamic_game.d.ts +53 -0
- package/dist/simulation/toolkit/dynamic_game.js +805 -0
- package/dist/simulation/toolkit/dynamic_knowledge.d.ts +15 -0
- package/dist/simulation/toolkit/dynamic_knowledge.js +91 -0
- package/dist/simulation/toolkit/dynamic_mechanics.d.ts +22 -0
- package/dist/simulation/toolkit/dynamic_mechanics.js +910 -0
- package/dist/simulation/toolkit/dynamic_meetings.d.ts +239 -0
- package/dist/simulation/toolkit/dynamic_meetings.js +350 -0
- package/dist/simulation/toolkit/dynamic_progress.d.ts +131 -0
- package/dist/simulation/toolkit/dynamic_progress.js +214 -0
- package/dist/simulation/toolkit/dynamic_projection.d.ts +9 -0
- package/dist/simulation/toolkit/dynamic_projection.js +219 -0
- package/dist/simulation/toolkit/dynamic_runtime.d.ts +412 -0
- package/dist/simulation/toolkit/dynamic_runtime.js +6536 -0
- package/dist/simulation/toolkit/dynamic_state.d.ts +111 -0
- package/dist/simulation/toolkit/dynamic_state.js +1967 -0
- package/dist/simulation/toolkit/dynamic_story_review.d.ts +508 -0
- package/dist/simulation/toolkit/dynamic_story_review.js +333 -0
- package/dist/simulation/toolkit/dynamic_storyteller.d.ts +77 -0
- package/dist/simulation/toolkit/dynamic_storyteller.js +114 -0
- package/dist/simulation/toolkit/dynamic_storyteller_runtime.d.ts +26 -0
- package/dist/simulation/toolkit/dynamic_storyteller_runtime.js +126 -0
- package/dist/simulation/toolkit/dynamic_world.d.ts +22 -0
- package/dist/simulation/toolkit/dynamic_world.js +377 -0
- package/dist/simulation/toolkit/structured_output.d.ts +5 -0
- package/dist/simulation/toolkit/structured_output.js +321 -0
- package/dist/simulation/types/world.d.ts +2 -0
- package/dist/simulation/world/artifact_store.js +1 -1
- package/dist/simulation/world/memory_manager.d.ts +5 -0
- package/dist/simulation/world/memory_manager.js +17 -2
- package/dist/simulation/world/state.d.ts +3 -2
- package/dist/simulation/world/state.js +15 -5
- package/dist/skills/bundled/measurement-validation/SKILL.md +144 -0
- package/dist/terminal_attach.d.ts +1 -0
- package/dist/terminal_attach.js +113 -0
- package/dist/tool_progress.d.ts +3 -0
- package/dist/tool_progress.js +27 -0
- package/dist/types.d.ts +145 -10
- package/dist/types.js +3 -0
- package/dist/ui/core/input.d.ts +3 -0
- package/dist/ui/core/input_segments.d.ts +18 -1
- package/dist/ui/core/input_segments.js +131 -47
- package/dist/ui/core/input_state.d.ts +12 -0
- package/dist/ui/core/layout_yoga.d.ts +1 -1
- package/dist/ui/core/turn_metadata.d.ts +5 -0
- package/dist/ui/core/turn_metadata.js +22 -0
- package/dist/ui/ink/render.d.ts +2 -1
- package/dist/ui/ink/render.js +6 -5
- package/dist/ui/ratatui/headless_pane_manager.d.ts +14 -1
- package/dist/ui/ratatui/headless_pane_manager.js +293 -104
- package/dist/ui/ratatui/index.d.ts +1 -0
- package/dist/ui/ratatui/input.d.ts +4 -0
- package/dist/ui/ratatui/input.js +15 -0
- package/dist/ui/ratatui/ipc_path.d.ts +2 -0
- package/dist/ui/ratatui/ipc_path.js +29 -1
- package/dist/ui/ratatui/mux_persistence.d.ts +3 -1
- package/dist/ui/ratatui/mux_persistence.js +139 -1
- package/dist/ui/ratatui/pane_relay.d.ts +1 -1
- package/dist/ui/ratatui/pane_relay.js +55 -27
- package/dist/ui/ratatui/process.d.ts +17 -1
- package/dist/ui/ratatui/process.js +80 -7
- package/dist/ui/ratatui/protocol.d.ts +236 -1
- package/dist/ui/ratatui/protocol.js +90 -0
- package/dist/ui/scrollback.d.ts +2 -1
- package/dist/ui/scrollback.js +9 -4
- package/dist/ui/stream_typewriter.d.ts +8 -3
- package/dist/ui/stream_typewriter.js +30 -1
- package/dist/ui/streaming_scrollback.d.ts +1 -0
- package/dist/ui/streaming_scrollback.js +1 -1
- package/dist/ui/transcript_render_cache.js +10 -0
- package/dist/ui/views/activity_line.d.ts +5 -3
- package/dist/ui/views/activity_line.js +65 -7
- package/dist/ui/views/app.d.ts +6 -3
- package/dist/ui/views/app.js +17 -6
- package/dist/ui/views/completion_menu.js +10 -5
- package/dist/ui/views/input_area.d.ts +7 -3
- package/dist/ui/views/input_area.js +15 -9
- package/dist/ui/views/message_list.d.ts +4 -1
- package/dist/ui/views/message_list.js +89 -19
- package/dist/ui/views/queue_panel.d.ts +3 -1
- package/dist/ui/views/queue_panel.js +9 -2
- package/dist/ui/views/status_bar.d.ts +4 -2
- package/dist/ui/views/status_bar.js +28 -13
- package/dist/ui/views/theme.d.ts +2 -0
- package/dist/ui/views/theme.js +2 -0
- package/dist/ui/widgets/color_panel.js +18 -0
- package/dist/ui/widgets/form.js +8 -0
- package/dist/ui/widgets/log_view.js +7 -0
- package/dist/ui/widgets/navigator_panel.js +8 -0
- package/dist/ui/widgets/prompt_viewer.js +2 -0
- package/dist/ui/widgets/questionnaire.d.ts +2 -0
- package/dist/ui/widgets/questionnaire.js +79 -16
- package/dist/ui/widgets/resume_panel.d.ts +2 -0
- package/dist/ui/widgets/resume_panel.js +26 -15
- package/dist/ui/widgets/rewind_panel.d.ts +2 -2
- package/dist/ui/widgets/rewind_panel.js +4 -2
- package/dist/ui/widgets/select.js +16 -27
- package/dist/ui/widgets/settings_panel.js +16 -0
- package/dist/ui/widgets/status_line_panel.d.ts +1 -0
- package/dist/ui/widgets/status_line_panel.js +30 -4
- package/dist/ui/widgets/text_input.d.ts +2 -0
- package/dist/ui/widgets/text_input.js +15 -1
- package/dist/ui/widgets/types.d.ts +2 -0
- package/dist/usage_projection.d.ts +24 -0
- package/dist/usage_projection.js +130 -0
- package/dist/usage_snapshot.d.ts +36 -0
- package/dist/usage_snapshot.js +131 -0
- package/dist/utils/assistant_message.d.ts +2 -0
- package/dist/utils/assistant_message.js +5 -0
- package/dist/utils/atomic_write.d.ts +6 -2
- package/dist/utils/atomic_write.js +29 -4
- package/dist/utils/checked_shell.d.ts +25 -0
- package/dist/utils/checked_shell.js +107 -0
- package/dist/utils/compaction.d.ts +4 -1
- package/dist/utils/compaction.js +31 -7
- package/dist/utils/context.d.ts +4 -4
- package/dist/utils/context.js +14 -12
- package/dist/utils/deepseek.d.ts +2 -2
- package/dist/utils/deepseek.js +13 -5
- package/dist/utils/ephemeral.js +4 -0
- package/dist/utils/ephemeral_tools.d.ts +18 -0
- package/dist/utils/ephemeral_tools.js +97 -0
- package/dist/utils/jev_client.d.ts +4 -0
- package/dist/utils/jev_client.js +15 -0
- package/dist/utils/model_cache.d.ts +15 -0
- package/dist/utils/model_cache.js +143 -0
- package/dist/utils/models.d.ts +4 -2
- package/dist/utils/models.js +12 -16
- package/dist/utils/reasoning.d.ts +8 -1
- package/dist/utils/reasoning.js +31 -11
- package/dist/utils/router_catalog.d.ts +49 -0
- package/dist/utils/router_catalog.js +271 -0
- package/dist/utils/sandbox.d.ts +9 -0
- package/dist/utils/sandbox.js +118 -15
- package/dist/utils/shell.d.ts +7 -0
- package/dist/utils/shell.js +98 -34
- package/dist/utils/subprocess_env.d.ts +3 -0
- package/dist/utils/subprocess_env.js +27 -1
- package/dist/web/accounts_mirror.d.ts +3 -1
- package/dist/web/accounts_mirror.js +13 -9
- package/dist/web/child_publication.d.ts +17 -0
- package/dist/web/child_publication.js +45 -0
- package/dist/web/mirror_authenticator.d.ts +31 -11
- package/dist/web/mirror_authenticator.js +67 -17
- package/dist/web/mirror_client.d.ts +31 -4
- package/dist/web/mirror_client.js +189 -23
- package/dist/web/mirror_stream.d.ts +84 -22
- package/dist/web/mirror_stream.js +676 -95
- package/dist/web/observer_query_redaction.d.ts +6 -0
- package/dist/web/observer_query_redaction.js +58 -0
- package/dist/web/pane_registry.d.ts +2 -0
- package/dist/web/pane_registry.js +86 -22
- package/dist/web/tool_image.d.ts +6 -0
- package/dist/web/tool_image.js +17 -0
- package/dist/web/view_plugin.d.ts +14 -0
- package/dist/web/view_plugin.js +23 -1
- package/dist/worker/executor.js +31 -12
- package/dist/worker/index.d.ts +1 -0
- package/dist/worker/toolsets.js +3 -1
- package/dist/worker/types.d.ts +12 -1
- package/dist/workflows/registry.js +1 -0
- package/dist/workflows/registry_handle.d.ts +2 -0
- package/dist/workflows/runtime.d.ts +2 -0
- package/dist/workflows/runtime.js +1 -0
- package/dist/workspace_agent.d.ts +7 -0
- package/dist/workspace_agent.js +36 -0
- package/dist/workspace_collision.d.ts +76 -0
- package/dist/workspace_collision.js +688 -0
- package/dist/workspace_layout.d.ts +18 -0
- package/dist/workspace_layout.js +121 -0
- package/dist/workspace_runtime.d.ts +44 -0
- package/dist/workspace_runtime.js +82 -0
- package/dist/workspace_session_context.d.ts +62 -0
- package/dist/workspace_session_context.js +160 -0
- package/dist/zlm-embed.mjs +32518 -9615
- package/dist/zlm.js +1 -0
- package/node_modules/@zerg/model-contracts/LICENSE.md +375 -0
- package/node_modules/@zerg/model-contracts/README.md +90 -0
- package/node_modules/@zerg/model-contracts/index.d.ts +20 -0
- package/node_modules/@zerg/model-contracts/index.js +223 -0
- package/node_modules/@zerg/model-contracts/package.json +8 -0
- package/node_modules/glob/node_modules/brace-expansion/index.js +78 -22
- package/node_modules/glob/node_modules/brace-expansion/package.json +1 -1
- package/node_modules/readdir-glob/node_modules/brace-expansion/index.js +78 -22
- package/node_modules/readdir-glob/node_modules/brace-expansion/package.json +1 -1
- package/package.json +45 -24
- package/packages/model-contracts/LICENSE.md +375 -0
- package/packages/model-contracts/README.md +90 -0
- package/packages/model-contracts/index.d.ts +20 -0
- package/packages/model-contracts/index.js +223 -0
- package/packages/model-contracts/package.json +8 -0
- package/remote-broker/Dockerfile +10 -0
- package/remote-broker/README.md +308 -0
- package/remote-broker/archive.py +1227 -0
- package/remote-broker/cutover.py +761 -0
- package/remote-broker/requirements.txt +5 -0
- package/remote-broker/resources.example.json +6 -0
- package/remote-broker/resources.write-staging.example.json +18 -0
- package/remote-broker/retained.py +686 -0
- package/remote-broker/retained_cleanup.py +550 -0
- package/remote-broker/server.py +648 -0
- package/scripts/build-remote-broker.mjs +13 -0
- package/scripts/ensure-local-packages.mjs +6 -0
- package/scripts/node-pty-helpers.mjs +103 -0
package/dist/config.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { modelContract } from '@zerg/model-contracts';
|
|
2
|
+
import { isLocalSubscriptionProvider } from './agent/backends/provider_ids.js';
|
|
3
|
+
import { resolveRouterModel, readRouterCatalog } from './utils/router_catalog.js';
|
|
4
|
+
import { dirname, join } from 'path';
|
|
5
|
+
import { stat, readFile, writeFile, mkdir, chmod, rm, unlink, rename, realpath } from 'fs/promises';
|
|
3
6
|
import { randomUUID } from 'crypto';
|
|
4
|
-
import { activeProfile, builtinProfileEmulation, profileConfigDir, validateProfileName } from './config/profiles.js';
|
|
7
|
+
import { activeProfile, builtinProfileEmulation, listConfigProfiles, profileConfigDir, validateProfileName } from './config/profiles.js';
|
|
5
8
|
import { accountSourceToBackendOptions, canonicalAccountProvider, probeAccountIsolated, resolveActiveAccount, resolveRotation, } from './agent/backends/account_pool.js';
|
|
6
9
|
import { notifyAccountsChanged } from './agent/backends/account_events.js';
|
|
7
10
|
import { inferDefaultProvider, getDefaultApiKeyForProvider, getDefaultModelForProvider, resolveCodexEffort, unsupportedCodexEffort } from './config/defaults.js';
|
|
@@ -118,8 +121,27 @@ export const DEFAULT_PERMISSION_PROFILES = {
|
|
|
118
121
|
file_write: false,
|
|
119
122
|
shell_exec: false,
|
|
120
123
|
network: true,
|
|
124
|
+
computer_control: false,
|
|
125
|
+
ml_inference: false,
|
|
121
126
|
},
|
|
122
127
|
},
|
|
128
|
+
safe_edits: {
|
|
129
|
+
description: 'Policy checks: edit files in the current project; shell and computer control are disabled.',
|
|
130
|
+
capabilities: { file_read: true, file_write: true, shell_exec: false, network: true, screen_capture: true, computer_control: false, ml_inference: false },
|
|
131
|
+
allowedPaths: ['.'],
|
|
132
|
+
},
|
|
133
|
+
tests_allowed: {
|
|
134
|
+
description: 'Policy checks: project edits plus host approval for every shell command, including tests. Tests may change files. Requires an OS command sandbox.',
|
|
135
|
+
capabilities: { file_read: true, file_write: true, shell_exec: true, network: true, screen_capture: true, computer_control: false, ml_inference: false },
|
|
136
|
+
approvalRequiredCapabilities: ['shell_exec'],
|
|
137
|
+
allowedPaths: ['.'],
|
|
138
|
+
sandbox: { backend: 'auto', requireOsEnforcement: true },
|
|
139
|
+
},
|
|
140
|
+
local_full: {
|
|
141
|
+
description: 'Policy checks allow full local tool access. No OS command sandbox is requested unless required by host settings.',
|
|
142
|
+
capabilities: { file_read: true, file_write: true, shell_exec: true, network: true, screen_capture: true, computer_control: true, ml_inference: true },
|
|
143
|
+
sandbox: { backend: 'none' },
|
|
144
|
+
},
|
|
123
145
|
locked_down: {
|
|
124
146
|
description: 'Disable local filesystem mutation, shell execution, network, screen, computer, and ML tools.',
|
|
125
147
|
capabilities: {
|
|
@@ -205,6 +227,21 @@ function default_provider() {
|
|
|
205
227
|
const hasRouteCredential = ROUTE_CREDENTIAL_ENV.some(name => Boolean(process.env[name]?.trim()));
|
|
206
228
|
return hasRouteCredential ? inferDefaultProvider() : PERSONAL_DEFAULT_PROVIDER;
|
|
207
229
|
}
|
|
230
|
+
export const DEFAULT_TERMINAL_INTERACTION = {
|
|
231
|
+
mouseCapture: true,
|
|
232
|
+
wheelScrollLines: 3,
|
|
233
|
+
};
|
|
234
|
+
export function resolveTerminalInteractionSettings(value) {
|
|
235
|
+
if (value === null || typeof value !== 'object' || Array.isArray(value)) {
|
|
236
|
+
return { ...DEFAULT_TERMINAL_INTERACTION };
|
|
237
|
+
}
|
|
238
|
+
const settings = value;
|
|
239
|
+
const wheel = settings.wheelScrollLines;
|
|
240
|
+
return {
|
|
241
|
+
mouseCapture: typeof settings.mouseCapture === 'boolean' ? settings.mouseCapture : true,
|
|
242
|
+
wheelScrollLines: typeof wheel === 'number' && Number.isInteger(wheel) && wheel >= 1 && wheel <= 20 ? wheel : 3,
|
|
243
|
+
};
|
|
244
|
+
}
|
|
208
245
|
export function build_default_config() {
|
|
209
246
|
const provider = default_provider();
|
|
210
247
|
return {
|
|
@@ -230,6 +267,7 @@ export function build_default_config() {
|
|
|
230
267
|
intents: { ...DEFAULT_INTENTS },
|
|
231
268
|
contextProgressBar: { ...DEFAULT_CONTEXT_PROGRESS_BAR },
|
|
232
269
|
messageDisplay: { ...DEFAULT_MESSAGE_DISPLAY },
|
|
270
|
+
terminalInteraction: { ...DEFAULT_TERMINAL_INTERACTION },
|
|
233
271
|
compaction: resolveCompactionSettings({}),
|
|
234
272
|
// zmux shortcut overrides edited from /keybindings (empty = all defaults).
|
|
235
273
|
keybindings: { zmux: {} },
|
|
@@ -290,6 +328,20 @@ const ROUTING_SETTING_KEYS = [
|
|
|
290
328
|
function normalizedOrigin(value) {
|
|
291
329
|
return value?.trim().replace(/\/+$/, '') || undefined;
|
|
292
330
|
}
|
|
331
|
+
/** Explicit deployment routing takes precedence over a saved session origin. */
|
|
332
|
+
function routerOriginFromEnvironment() {
|
|
333
|
+
if (process.env.ZERG_PROXY_URL)
|
|
334
|
+
return process.env.ZERG_PROXY_URL;
|
|
335
|
+
if (process.env.ZERG_ROUTER_BASE_URL)
|
|
336
|
+
return normalizedOrigin(process.env.ZERG_ROUTER_BASE_URL);
|
|
337
|
+
const tiers = {
|
|
338
|
+
local: 'http://host.docker.internal:8000/api/zrouter',
|
|
339
|
+
dev: 'https://api-dev.zergai.com/api/zrouter', development: 'https://api-dev.zergai.com/api/zrouter',
|
|
340
|
+
prod: 'https://api.zergai.com/api/zrouter', production: 'https://api.zergai.com/api/zrouter', main: 'https://api.zergai.com/api/zrouter',
|
|
341
|
+
};
|
|
342
|
+
const tier = process.env.ZERG_DEPLOY_TIER || '';
|
|
343
|
+
return Object.hasOwn(tiers, tier) ? tiers[tier] : undefined;
|
|
344
|
+
}
|
|
293
345
|
/**
|
|
294
346
|
* True when the saved provider route can already reach a model: a direct or
|
|
295
347
|
* platform credential, a subscription or account login, a configured
|
|
@@ -300,6 +352,10 @@ function normalizedOrigin(value) {
|
|
|
300
352
|
function savedRouteIsUsable(saved) {
|
|
301
353
|
if (!saved.provider)
|
|
302
354
|
return false;
|
|
355
|
+
// A hosted native route is deliberately independent of direct keys and
|
|
356
|
+
// personal Router logins. Keep its explicit provider/model during migration.
|
|
357
|
+
if (saved.nativeAnthropicMessagesRouter)
|
|
358
|
+
return true;
|
|
303
359
|
const provider = normalizeProviderId(saved.provider);
|
|
304
360
|
if (saved.authMode === 'direct')
|
|
305
361
|
return true;
|
|
@@ -402,6 +458,12 @@ export class ConfigStore {
|
|
|
402
458
|
// The legacy slot also carries runtime defaults. Only a configured key may
|
|
403
459
|
// be migrated into apiKeys or written to disk.
|
|
404
460
|
legacyApiKeyFromEnvironment = true;
|
|
461
|
+
/**
|
|
462
|
+
* Whether the routing in `this.config` came from a saved file or an explicit
|
|
463
|
+
* choice, rather than the built-in default. A config-less process that never
|
|
464
|
+
* picked a route must not hard-fail on the preset Router route it inherited.
|
|
465
|
+
*/
|
|
466
|
+
routingIsConfigured = false;
|
|
405
467
|
routerCredentials = null;
|
|
406
468
|
routerCredentialsError = null;
|
|
407
469
|
routerFallbackWarning = null;
|
|
@@ -409,6 +471,7 @@ export class ConfigStore {
|
|
|
409
471
|
configScope = 'global';
|
|
410
472
|
/** Session-local overrides. Never persisted to config.json. */
|
|
411
473
|
sessionOverrides = {};
|
|
474
|
+
restoredSessionSelection = false;
|
|
412
475
|
/** CLI-only overrides. Never persisted to config.json. */
|
|
413
476
|
cliOverrides = {};
|
|
414
477
|
/**
|
|
@@ -475,23 +538,10 @@ export class ConfigStore {
|
|
|
475
538
|
else if (tier === 'prod' || tier === 'production' || tier === 'main')
|
|
476
539
|
this.config.apiEnvironment = 'production';
|
|
477
540
|
}
|
|
478
|
-
//
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
else if (process.env.ZERG_ROUTER_BASE_URL) {
|
|
483
|
-
// Standalone ZergRouter (https://zergrouter.com) serves /v1/* at
|
|
484
|
-
// its root, no /api/zrouter suffix. Lower precedence than ZERG_PROXY_URL.
|
|
485
|
-
this.config.zergProxyUrl = process.env.ZERG_ROUTER_BASE_URL.replace(/\/+$/, '');
|
|
486
|
-
}
|
|
487
|
-
else if (process.env.ZERG_DEPLOY_TIER) {
|
|
488
|
-
const tier = process.env.ZERG_DEPLOY_TIER;
|
|
489
|
-
if (tier === 'local')
|
|
490
|
-
this.config.zergProxyUrl = 'http://host.docker.internal:8000/api/zrouter';
|
|
491
|
-
else if (tier === 'dev' || tier === 'development')
|
|
492
|
-
this.config.zergProxyUrl = 'https://api-dev.zergai.com/api/zrouter';
|
|
493
|
-
else if (tier === 'prod' || tier === 'production' || tier === 'main')
|
|
494
|
-
this.config.zergProxyUrl = 'https://api.zergai.com/api/zrouter';
|
|
541
|
+
// Resolve all explicit origin environment variables through one policy.
|
|
542
|
+
const originOverride = routerOriginFromEnvironment();
|
|
543
|
+
if (originOverride) {
|
|
544
|
+
this.config.zergProxyUrl = originOverride;
|
|
495
545
|
}
|
|
496
546
|
else if (!this.config.zergProxyUrl) {
|
|
497
547
|
// Local default: infer ZRouter from the selected API environment.
|
|
@@ -569,9 +619,6 @@ export class ConfigStore {
|
|
|
569
619
|
if (saved.provider && saved.model === undefined) {
|
|
570
620
|
this.config.model = getDefaultModelForProvider(saved.provider);
|
|
571
621
|
}
|
|
572
|
-
if (this.config.model === 'claude-opus-4-5-20250514' || this.config.model === 'claude-opus-4-20250514') {
|
|
573
|
-
this.config.model = 'claude-opus-5';
|
|
574
|
-
}
|
|
575
622
|
if (!this.config.spinnerVerbs) {
|
|
576
623
|
this.config.spinnerVerbs = DEFAULT_SPINNER_VERBS;
|
|
577
624
|
}
|
|
@@ -587,6 +634,7 @@ export class ConfigStore {
|
|
|
587
634
|
this.config.intents = { ...DEFAULT_INTENTS, ...(this.config.intents || {}) };
|
|
588
635
|
this.config.contextProgressBar = { ...DEFAULT_CONTEXT_PROGRESS_BAR, ...(this.config.contextProgressBar || {}) };
|
|
589
636
|
this.config.messageDisplay = { ...DEFAULT_MESSAGE_DISPLAY, ...(this.config.messageDisplay || {}) };
|
|
637
|
+
this.config.terminalInteraction = resolveTerminalInteractionSettings(this.config.terminalInteraction);
|
|
590
638
|
this.config.compaction = resolveCompactionSettings(this.config);
|
|
591
639
|
this.applyEnvOverrides();
|
|
592
640
|
this.loaded = true;
|
|
@@ -599,6 +647,59 @@ export class ConfigStore {
|
|
|
599
647
|
this.sessionOverrides = sessionOverrides;
|
|
600
648
|
this.configScope = scope;
|
|
601
649
|
}
|
|
650
|
+
/** Copy saved settings and Router credentials, then activate them transactionally.
|
|
651
|
+
* Account registrations retain their credential paths; account homes are not cloned.
|
|
652
|
+
*/
|
|
653
|
+
async duplicateProfile(requestedName, source = activeProfile(), activate = () => { }) {
|
|
654
|
+
const name = validateProfileName(requestedName.trim());
|
|
655
|
+
const from = validateProfileName(source);
|
|
656
|
+
if (name === 'default' || builtinProfileEmulation(name)) {
|
|
657
|
+
throw new Error(`Cannot duplicate onto "${name}": it is a built-in profile sharing the default settings. Pick another name.`);
|
|
658
|
+
}
|
|
659
|
+
if (name === from || (await listConfigProfiles()).includes(name)) {
|
|
660
|
+
throw new Error(`Config profile "${name}" already exists. Pick another name.`);
|
|
661
|
+
}
|
|
662
|
+
const sourceDir = profileConfigDir(from);
|
|
663
|
+
const emulation = builtinProfileEmulation(from);
|
|
664
|
+
if (from !== 'default' && !emulation && !(await stat(sourceDir)).isDirectory()) {
|
|
665
|
+
throw new Error(`Config profile "${from}" does not exist.`);
|
|
666
|
+
}
|
|
667
|
+
let saved = {};
|
|
668
|
+
try {
|
|
669
|
+
const parsed = JSON.parse(await readFile(join(sourceDir, 'config.json'), 'utf8'));
|
|
670
|
+
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
|
|
671
|
+
throw new Error(`Invalid config profile "${from}": expected an object.`);
|
|
672
|
+
}
|
|
673
|
+
saved = parsed;
|
|
674
|
+
}
|
|
675
|
+
catch (error) {
|
|
676
|
+
if (error.code !== 'ENOENT')
|
|
677
|
+
throw error;
|
|
678
|
+
}
|
|
679
|
+
if (emulation)
|
|
680
|
+
saved.emulationId = emulation;
|
|
681
|
+
const destination = profileConfigDir(name);
|
|
682
|
+
await mkdir(dirname(destination), { recursive: true, mode: 0o700 });
|
|
683
|
+
// An existing destination, including one created concurrently, is never ours to modify.
|
|
684
|
+
await mkdir(destination, { mode: 0o700 });
|
|
685
|
+
try {
|
|
686
|
+
await writeFile(join(destination, 'config.json'), JSON.stringify(saved, null, 2), { flag: 'wx', mode: 0o600 });
|
|
687
|
+
try {
|
|
688
|
+
const auth = await readFile(join(sourceDir, 'router-auth.json'));
|
|
689
|
+
await writeFile(join(destination, 'router-auth.json'), auth, { flag: 'wx', mode: 0o600 });
|
|
690
|
+
}
|
|
691
|
+
catch (error) {
|
|
692
|
+
if (error.code !== 'ENOENT')
|
|
693
|
+
throw error;
|
|
694
|
+
}
|
|
695
|
+
await this.switchProfile(name, activate);
|
|
696
|
+
}
|
|
697
|
+
catch (error) {
|
|
698
|
+
await rm(destination, { recursive: true, force: true });
|
|
699
|
+
throw error;
|
|
700
|
+
}
|
|
701
|
+
return name;
|
|
702
|
+
}
|
|
602
703
|
/** Load a profile in this process; restore the old view if runtime activation fails. */
|
|
603
704
|
async switchProfile(name, activate) {
|
|
604
705
|
const next = validateProfileName(name);
|
|
@@ -627,6 +728,7 @@ export class ConfigStore {
|
|
|
627
728
|
routerCredentialsError: this.routerCredentialsError,
|
|
628
729
|
routerFallbackWarning: this.routerFallbackWarning,
|
|
629
730
|
sessionOverrides: this.sessionOverrides,
|
|
731
|
+
restoredSessionSelection: this.restoredSessionSelection,
|
|
630
732
|
cliOverrides: this.cliOverrides,
|
|
631
733
|
runtimeActivePerProvider: this.runtimeActivePerProvider,
|
|
632
734
|
configScope: this.configScope,
|
|
@@ -640,6 +742,7 @@ export class ConfigStore {
|
|
|
640
742
|
}
|
|
641
743
|
else {
|
|
642
744
|
this.sessionOverrides = {};
|
|
745
|
+
this.restoredSessionSelection = false;
|
|
643
746
|
this.cliOverrides = {};
|
|
644
747
|
this.runtimeActivePerProvider = {};
|
|
645
748
|
this.configScope = 'global';
|
|
@@ -658,11 +761,13 @@ export class ConfigStore {
|
|
|
658
761
|
}
|
|
659
762
|
}
|
|
660
763
|
async save() {
|
|
764
|
+
const directory = configDir();
|
|
765
|
+
const path = configFile();
|
|
661
766
|
if (this.configScope === 'session') {
|
|
662
767
|
return;
|
|
663
768
|
}
|
|
664
769
|
try {
|
|
665
|
-
await mkdir(
|
|
770
|
+
await mkdir(directory, { recursive: true });
|
|
666
771
|
// Don't persist API key if it came from an environment variable
|
|
667
772
|
const toSave = { ...this.config };
|
|
668
773
|
if (this.legacyApiKeyFromEnvironment)
|
|
@@ -678,8 +783,8 @@ export class ConfigStore {
|
|
|
678
783
|
// config.json holds secrets (apiKey, apiKeys, auth.token) — keep it owner-
|
|
679
784
|
// only. writeFile's mode applies only when it CREATES the file, so also
|
|
680
785
|
// chmod to tighten an existing 0644 file left by an earlier ZTC.
|
|
681
|
-
await writeFile(
|
|
682
|
-
await chmod(
|
|
786
|
+
await writeFile(path, JSON.stringify(toSave, null, 2), { encoding: 'utf-8', mode: 0o600 });
|
|
787
|
+
await chmod(path, 0o600);
|
|
683
788
|
}
|
|
684
789
|
catch (err) {
|
|
685
790
|
runtimeDiag('error', `Failed to save config: ${err?.message ?? err}`);
|
|
@@ -714,7 +819,7 @@ export class ConfigStore {
|
|
|
714
819
|
return this.composeConfig(false);
|
|
715
820
|
}
|
|
716
821
|
composeConfig(includeEffortOverride) {
|
|
717
|
-
|
|
822
|
+
const config = {
|
|
718
823
|
...this.config,
|
|
719
824
|
...(this.profileEmulation ? { emulationId: this.profileEmulation } : {}),
|
|
720
825
|
...this.sessionOverrides,
|
|
@@ -727,11 +832,14 @@ export class ConfigStore {
|
|
|
727
832
|
provider: this.getProvider(),
|
|
728
833
|
model: this.getModel(),
|
|
729
834
|
};
|
|
835
|
+
return { ...config, terminalInteraction: resolveTerminalInteractionSettings(config.terminalInteraction) };
|
|
730
836
|
}
|
|
731
837
|
cliOverridesWithoutEffort() {
|
|
732
838
|
return {
|
|
733
839
|
...(this.cliOverrides.provider !== undefined ? { provider: this.cliOverrides.provider } : {}),
|
|
734
840
|
...(this.cliOverrides.model !== undefined ? { model: this.cliOverrides.model } : {}),
|
|
841
|
+
...(this.cliOverrides.authMode !== undefined ? { authMode: this.cliOverrides.authMode } : {}),
|
|
842
|
+
...(this.cliOverrides.zergProxyUrl !== undefined ? { zergProxyUrl: this.cliOverrides.zergProxyUrl } : {}),
|
|
735
843
|
};
|
|
736
844
|
}
|
|
737
845
|
getMaxTokensSource() {
|
|
@@ -747,6 +855,7 @@ export class ConfigStore {
|
|
|
747
855
|
}
|
|
748
856
|
clearSessionOverrides() {
|
|
749
857
|
this.sessionOverrides = {};
|
|
858
|
+
this.restoredSessionSelection = false;
|
|
750
859
|
}
|
|
751
860
|
async withConfigScope(scope, fn) {
|
|
752
861
|
const previous = this.configScope;
|
|
@@ -758,7 +867,23 @@ export class ConfigStore {
|
|
|
758
867
|
this.configScope = previous;
|
|
759
868
|
}
|
|
760
869
|
}
|
|
870
|
+
releaseRestoredSelection(key) {
|
|
871
|
+
if (!this.restoredSessionSelection || !['provider', 'model', 'authMode', 'zergProxyUrl'].includes(key))
|
|
872
|
+
return;
|
|
873
|
+
for (const route of ['provider', 'model', 'authMode', 'zergProxyUrl'])
|
|
874
|
+
delete this.sessionOverrides[route];
|
|
875
|
+
this.restoredSessionSelection = false;
|
|
876
|
+
}
|
|
761
877
|
set(key, value) {
|
|
878
|
+
this.releaseRestoredSelection(key);
|
|
879
|
+
if (key === 'terminalInteraction') {
|
|
880
|
+
const normalized = resolveTerminalInteractionSettings(value);
|
|
881
|
+
if (this.configScope === 'session')
|
|
882
|
+
this.sessionOverrides.terminalInteraction = normalized;
|
|
883
|
+
else
|
|
884
|
+
this.config.terminalInteraction = normalized;
|
|
885
|
+
return;
|
|
886
|
+
}
|
|
762
887
|
if (this.configScope === 'session' || (key === 'emulationId' && this.profileEmulation)) {
|
|
763
888
|
this.sessionOverrides[key] = value;
|
|
764
889
|
return;
|
|
@@ -768,17 +893,21 @@ export class ConfigStore {
|
|
|
768
893
|
this.legacyApiKeyFromEnvironment = false;
|
|
769
894
|
}
|
|
770
895
|
setGlobal(key, value) {
|
|
896
|
+
this.releaseRestoredSelection(key);
|
|
897
|
+
if (key === 'terminalInteraction') {
|
|
898
|
+
this.config.terminalInteraction = resolveTerminalInteractionSettings(value);
|
|
899
|
+
return;
|
|
900
|
+
}
|
|
771
901
|
this.config[key] = value;
|
|
772
902
|
if (key === 'apiKey')
|
|
773
903
|
this.legacyApiKeyFromEnvironment = false;
|
|
774
904
|
}
|
|
775
905
|
setAll(next) {
|
|
906
|
+
for (const key of Object.keys(next))
|
|
907
|
+
this.releaseRestoredSelection(key);
|
|
776
908
|
this.config = { ...build_default_config(), ...this.config, ...next };
|
|
777
909
|
if (Object.hasOwn(next, 'apiKey'))
|
|
778
910
|
this.legacyApiKeyFromEnvironment = false;
|
|
779
|
-
if (this.config.model === 'claude-opus-4-5-20250514' || this.config.model === 'claude-opus-4-20250514') {
|
|
780
|
-
this.config.model = 'claude-opus-5';
|
|
781
|
-
}
|
|
782
911
|
if (!this.config.spinnerVerbs) {
|
|
783
912
|
this.config.spinnerVerbs = DEFAULT_SPINNER_VERBS;
|
|
784
913
|
}
|
|
@@ -794,6 +923,7 @@ export class ConfigStore {
|
|
|
794
923
|
this.config.intents = { ...DEFAULT_INTENTS, ...(this.config.intents || {}) };
|
|
795
924
|
this.config.contextProgressBar = { ...DEFAULT_CONTEXT_PROGRESS_BAR, ...(this.config.contextProgressBar || {}) };
|
|
796
925
|
this.config.messageDisplay = { ...DEFAULT_MESSAGE_DISPLAY, ...(this.config.messageDisplay || {}) };
|
|
926
|
+
this.config.terminalInteraction = resolveTerminalInteractionSettings(this.config.terminalInteraction);
|
|
797
927
|
this.config.compaction = resolveCompactionSettings(this.config);
|
|
798
928
|
this.applyEnvOverrides();
|
|
799
929
|
this.loaded = true;
|
|
@@ -1021,8 +1151,34 @@ export class ConfigStore {
|
|
|
1021
1151
|
* Effective Codex effort for the active (or given) provider/model. Priority:
|
|
1022
1152
|
* per-model > per-provider > global. Defaults to the current provider/model.
|
|
1023
1153
|
*/
|
|
1154
|
+
getReasoningWireSurface(provider = this.getProvider(), model = this.getModel()) {
|
|
1155
|
+
if (provider === 'openai_compatible')
|
|
1156
|
+
return 'chat_tools';
|
|
1157
|
+
if (modelContract(provider, model)?.chatToolReasoningEfforts === undefined)
|
|
1158
|
+
return 'native_api';
|
|
1159
|
+
try {
|
|
1160
|
+
return this.resolveLLMBackendConfig({ provider, model }).useProxy ? 'chat_tools' : 'native_api';
|
|
1161
|
+
}
|
|
1162
|
+
catch (error) {
|
|
1163
|
+
if (error instanceof RouterConfigurationError)
|
|
1164
|
+
return 'chat_tools';
|
|
1165
|
+
throw error;
|
|
1166
|
+
}
|
|
1167
|
+
}
|
|
1024
1168
|
getCodexEffort(provider, model) {
|
|
1025
|
-
|
|
1169
|
+
const selectedProvider = provider ?? this.getProvider();
|
|
1170
|
+
const selectedModel = model ?? this.getModel();
|
|
1171
|
+
const catalog = this.getRoutedModelCatalog();
|
|
1172
|
+
const capabilities = catalog ? resolveRouterModel(catalog, selectedProvider, selectedModel)?.capabilities : undefined;
|
|
1173
|
+
return resolveCodexEffort(this.get(), selectedProvider, selectedModel, capabilities
|
|
1174
|
+
?? this.getReasoningWireSurface(selectedProvider, selectedModel));
|
|
1175
|
+
}
|
|
1176
|
+
/** The active transport owns the model's choices, aliases and advertised default. */
|
|
1177
|
+
getReasoningContract(provider = this.getProvider(), model = this.getModel()) {
|
|
1178
|
+
const catalog = this.getRoutedModelCatalog();
|
|
1179
|
+
if (catalog?.version === 1)
|
|
1180
|
+
return resolveRouterModel(catalog, provider, model)?.capabilities?.reasoning ?? [];
|
|
1181
|
+
return this.getReasoningWireSurface(provider, model);
|
|
1026
1182
|
}
|
|
1027
1183
|
/** Saved effort the active (or given) model rejects; undefined when it applies. */
|
|
1028
1184
|
getUnsupportedCodexEffort(provider, model) {
|
|
@@ -1201,6 +1357,84 @@ export class ConfigStore {
|
|
|
1201
1357
|
authMode: this.getAuthMode(),
|
|
1202
1358
|
};
|
|
1203
1359
|
}
|
|
1360
|
+
restoreSessionSelection(metadata) {
|
|
1361
|
+
// Legacy sessions did not persist routes. Explicit launch overrides retain priority.
|
|
1362
|
+
if (!metadata.authMode || this.cliOverrides.provider || this.cliOverrides.model
|
|
1363
|
+
|| (metadata.configProfile && metadata.configProfile !== activeProfile()))
|
|
1364
|
+
return;
|
|
1365
|
+
this.restoredSessionSelection = true;
|
|
1366
|
+
this.sessionOverrides.provider = metadata.provider;
|
|
1367
|
+
this.sessionOverrides.model = metadata.model;
|
|
1368
|
+
this.sessionOverrides.authMode = metadata.authMode;
|
|
1369
|
+
if (metadata.authMode !== 'direct' && metadata.routerOrigin && !routerOriginFromEnvironment())
|
|
1370
|
+
this.sessionOverrides.zergProxyUrl = metadata.routerOrigin;
|
|
1371
|
+
}
|
|
1372
|
+
getRouterCatalogConnection(destination = this.get().zergProxyUrl) {
|
|
1373
|
+
const origin = normalizedOrigin(destination);
|
|
1374
|
+
if (!origin)
|
|
1375
|
+
return undefined;
|
|
1376
|
+
const credentials = this.routerCredentials;
|
|
1377
|
+
if (credentials && !this.routerCredentialsError && credentials.origin === origin) {
|
|
1378
|
+
return { origin, token: credentials.token, workspaceId: credentials.workspaceId };
|
|
1379
|
+
}
|
|
1380
|
+
// Platform sessions are scoped to the platform's proxy, never another Router.
|
|
1381
|
+
const token = origin === this.deriveZRouterUrl(this.getApiBaseUrl()) ? this.getAuthToken() : undefined;
|
|
1382
|
+
return token ? { origin, token, workspaceId: this.getActiveWorkspace()?.id.toString() } : undefined;
|
|
1383
|
+
}
|
|
1384
|
+
/** New children use configured routing, not a parent's restored inference route. */
|
|
1385
|
+
getChildAuthMode() {
|
|
1386
|
+
if (!this.restoredSessionSelection)
|
|
1387
|
+
return this.getAuthMode();
|
|
1388
|
+
const { authMode: _restored, ...session } = this.sessionOverrides;
|
|
1389
|
+
return resolveAuthMode({ ...this.config, ...session, ...this.cliOverrides });
|
|
1390
|
+
}
|
|
1391
|
+
async adoptRouterCatalog(catalog) {
|
|
1392
|
+
if (catalog.version !== 1 || catalog.authRequired || this.getResolvedAuthMode() !== 'zrouter')
|
|
1393
|
+
return;
|
|
1394
|
+
const provider = this.getProvider(), model = this.getModel();
|
|
1395
|
+
const row = resolveRouterModel(catalog, provider, model);
|
|
1396
|
+
if (!row || (row.id === model && row.owned_by === provider))
|
|
1397
|
+
return;
|
|
1398
|
+
if (this.cliOverrides.provider || this.cliOverrides.model) {
|
|
1399
|
+
this.cliOverrides.provider = row.owned_by;
|
|
1400
|
+
this.cliOverrides.model = row.id;
|
|
1401
|
+
}
|
|
1402
|
+
else if (this.sessionOverrides.provider || this.sessionOverrides.model) {
|
|
1403
|
+
this.sessionOverrides.provider = row.owned_by;
|
|
1404
|
+
this.sessionOverrides.model = row.id;
|
|
1405
|
+
}
|
|
1406
|
+
else {
|
|
1407
|
+
this.config.provider = row.owned_by;
|
|
1408
|
+
this.config.model = row.id;
|
|
1409
|
+
await this.save();
|
|
1410
|
+
}
|
|
1411
|
+
}
|
|
1412
|
+
getRouterCatalog() {
|
|
1413
|
+
const connection = this.getRouterCatalogConnection();
|
|
1414
|
+
return connection ? readRouterCatalog(connection) : undefined;
|
|
1415
|
+
}
|
|
1416
|
+
getResolvedAuthMode() {
|
|
1417
|
+
const mode = this.getAuthMode();
|
|
1418
|
+
if (mode !== 'auto')
|
|
1419
|
+
return mode;
|
|
1420
|
+
try {
|
|
1421
|
+
return this.resolveLLMBackendConfig().useProxy ? 'zrouter' : 'direct';
|
|
1422
|
+
}
|
|
1423
|
+
catch {
|
|
1424
|
+
return mode;
|
|
1425
|
+
}
|
|
1426
|
+
}
|
|
1427
|
+
getRoutedModelCatalog() {
|
|
1428
|
+
if (isLocalSubscriptionProvider(this.getProvider()))
|
|
1429
|
+
return undefined;
|
|
1430
|
+
return this.getResolvedAuthMode() === 'zrouter' ? this.getRouterCatalog() : undefined;
|
|
1431
|
+
}
|
|
1432
|
+
getModelContextWindow(model = this.getModel(), provider = this.getProvider()) {
|
|
1433
|
+
const catalog = this.getRoutedModelCatalog();
|
|
1434
|
+
if (catalog?.version !== 1)
|
|
1435
|
+
return undefined;
|
|
1436
|
+
return resolveRouterModel(catalog, provider, model)?.capabilities?.context_window ?? null;
|
|
1437
|
+
}
|
|
1204
1438
|
/**
|
|
1205
1439
|
* Resolve everything a backend factory needs into one struct. Folds in the
|
|
1206
1440
|
* provider/model override precedence, the direct-key precedence
|
|
@@ -1215,8 +1449,7 @@ export class ConfigStore {
|
|
|
1215
1449
|
*
|
|
1216
1450
|
* Reads through `get()` and the env-aware getters (never raw `this.config`)
|
|
1217
1451
|
* so cli/session overrides stay honored. `apiKey` is the DIRECT provider key;
|
|
1218
|
-
* `authToken`/`useProxy` describe the proxy route separately
|
|
1219
|
-
* still prefer a direct key (e.g. Gemini) over the proxy.
|
|
1452
|
+
* `authToken`/`useProxy` describe the selected proxy route separately.
|
|
1220
1453
|
*/
|
|
1221
1454
|
resolveLLMBackendConfig(opts = {}) {
|
|
1222
1455
|
// `opts.config` resolves the config reads below (provider, model, authMode,
|
|
@@ -1233,15 +1466,15 @@ export class ConfigStore {
|
|
|
1233
1466
|
const repoOverride = !opts.provider && !opts.model && !this.hasExplicitModelOverride() && opts.cwd
|
|
1234
1467
|
? resolveRepoModelOverride(opts.cwd)
|
|
1235
1468
|
: null;
|
|
1236
|
-
|
|
1469
|
+
let provider = repoOverride?.provider
|
|
1237
1470
|
?? normalizeProviderId(opts.provider || cfg.provider || this.getProvider());
|
|
1238
1471
|
const configProvider = cfg.provider ? normalizeProviderId(cfg.provider) : undefined;
|
|
1239
|
-
|
|
1472
|
+
let model = repoOverride?.model
|
|
1240
1473
|
?? opts.model
|
|
1241
1474
|
?? (configProvider === provider ? cfg.model : undefined)
|
|
1242
1475
|
?? getDefaultModelForProvider(provider);
|
|
1243
|
-
const authMode = resolveAuthMode(cfg);
|
|
1244
|
-
const proxyUrl = cfg.zergProxyUrl;
|
|
1476
|
+
const authMode = isLocalSubscriptionProvider(provider) ? 'direct' : resolveAuthMode(cfg);
|
|
1477
|
+
const proxyUrl = normalizedOrigin(cfg.zergProxyUrl);
|
|
1245
1478
|
// Legacy platform tokens belong only to its /api/zrouter endpoint. A
|
|
1246
1479
|
// standalone Router requires its own device login, including after logout.
|
|
1247
1480
|
// Modal shared endpoints are unavailable through the legacy platform proxy.
|
|
@@ -1254,7 +1487,7 @@ export class ConfigStore {
|
|
|
1254
1487
|
routerError = new Error('Router origin does not match this login. Run ztc auth login --url <origin>.');
|
|
1255
1488
|
}
|
|
1256
1489
|
else if (Date.parse(this.routerCredentials.expiresAt) <= Date.now()) {
|
|
1257
|
-
routerError = new
|
|
1490
|
+
routerError = new RouterConfigurationError('Router session expired. Run ztc auth login again.', 'expired');
|
|
1258
1491
|
}
|
|
1259
1492
|
else {
|
|
1260
1493
|
authToken = this.routerCredentials.token;
|
|
@@ -1263,7 +1496,7 @@ export class ConfigStore {
|
|
|
1263
1496
|
if (authMode !== 'direct' && routerError) {
|
|
1264
1497
|
authToken = undefined;
|
|
1265
1498
|
if (authMode === 'zrouter') {
|
|
1266
|
-
throw new RouterConfigurationError(`${routerError.message} For a direct provider, recover with ZTC_LLM_AUTH_MODE=direct
|
|
1499
|
+
throw new RouterConfigurationError(`${routerError.message} For a direct provider, recover with ZTC_LLM_AUTH_MODE=direct.`, routerError instanceof RouterConfigurationError ? routerError.kind : 'configuration');
|
|
1267
1500
|
}
|
|
1268
1501
|
if (this.routerFallbackWarning !== routerError.message) {
|
|
1269
1502
|
runtimeDiag('warn', `${routerError.message} Auto mode is using direct-provider authentication.`);
|
|
@@ -1274,7 +1507,7 @@ export class ConfigStore {
|
|
|
1274
1507
|
this.routerFallbackWarning = null;
|
|
1275
1508
|
}
|
|
1276
1509
|
if (authMode === 'zrouter' && (!proxyUrl || !authToken)) {
|
|
1277
|
-
throw new RouterConfigurationError('Router authentication is required. Run ztc auth login before using router mode, or use ZTC_LLM_AUTH_MODE=direct for a direct provider.');
|
|
1510
|
+
throw new RouterConfigurationError('Router authentication is required. Run ztc auth login before using router mode, or use ZTC_LLM_AUTH_MODE=direct for a direct provider.', 'authentication_required');
|
|
1278
1511
|
}
|
|
1279
1512
|
// Prefer the per-provider config key over an exported env var for the direct
|
|
1280
1513
|
// key, matching the pre-seam factory's providerScopedApiKey precedence.
|
|
@@ -1293,7 +1526,19 @@ export class ConfigStore {
|
|
|
1293
1526
|
|| this.getOpenAICompatibleSettings(cfg).baseUrl
|
|
1294
1527
|
|| cfg.openaiCompatibleBaseUrl;
|
|
1295
1528
|
const proxyAvailable = Boolean(proxyUrl && authToken);
|
|
1296
|
-
|
|
1529
|
+
// Resolve the route here so discovery and backend construction agree. Auto
|
|
1530
|
+
// retains the existing local-subscription and direct-Gemini preferences.
|
|
1531
|
+
const localSubscription = isLocalSubscriptionProvider(provider);
|
|
1532
|
+
const useProxy = authMode === 'direct' ? false : proxyAvailable
|
|
1533
|
+
&& !localSubscription && !(authMode === 'auto' && provider === 'gemini' && Boolean(apiKey));
|
|
1534
|
+
if (useProxy) {
|
|
1535
|
+
const catalog = readRouterCatalog({ origin: proxyUrl, token: authToken, workspaceId: this.getRouterCatalogConnection(proxyUrl)?.workspaceId });
|
|
1536
|
+
const descriptor = catalog?.version === 1 ? resolveRouterModel(catalog, provider, model) : undefined;
|
|
1537
|
+
if (descriptor) {
|
|
1538
|
+
provider = descriptor.owned_by;
|
|
1539
|
+
model = descriptor.id;
|
|
1540
|
+
}
|
|
1541
|
+
}
|
|
1297
1542
|
const compatBaseUrl = provider === 'openai_compatible' && rawCompatBaseUrl
|
|
1298
1543
|
? compatEndpoint(rawCompatBaseUrl, { apiKey })
|
|
1299
1544
|
: rawCompatBaseUrl;
|
|
@@ -1314,7 +1559,9 @@ export class ConfigStore {
|
|
|
1314
1559
|
codexHome: accountOptions.codexHome,
|
|
1315
1560
|
codexAuthFilePath: accountOptions.codexAuthFilePath,
|
|
1316
1561
|
kimiCredsFilePath: accountOptions.kimiCredsFilePath,
|
|
1317
|
-
codexEffort:
|
|
1562
|
+
codexEffort: resolveCodexEffort(cfg, provider, model, (useProxy
|
|
1563
|
+
? this.getRouterCatalog()?.models.find(row => row.id === model && row.owned_by === provider)?.capabilities : undefined)
|
|
1564
|
+
?? (useProxy || provider === 'openai_compatible' ? 'chat_tools' : 'native_api')),
|
|
1318
1565
|
};
|
|
1319
1566
|
}
|
|
1320
1567
|
getEnvKey(provider) {
|
|
@@ -1335,6 +1582,7 @@ export class ConfigStore {
|
|
|
1335
1582
|
: undefined;
|
|
1336
1583
|
case 'openai': return process.env.OPENAI_API_KEY;
|
|
1337
1584
|
case 'deepseek': return process.env.DEEPSEEK_API_KEY;
|
|
1585
|
+
case 'fireworks': return process.env.FIREWORKS_API_KEY;
|
|
1338
1586
|
case 'gemini': return process.env.GOOGLE_API_KEY || process.env.GEMINI_API_KEY;
|
|
1339
1587
|
case 'inception': return process.env.INCEPTION_API_KEY;
|
|
1340
1588
|
case 'openai_compatible': return process.env.OPENAI_COMPAT_API_KEY;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export declare const PROJECT_CONTEXT_SOURCE_LIMIT = 16;
|
|
2
|
+
export declare const PROJECT_CONTEXT_FILE_BYTES: number;
|
|
3
|
+
export declare const PROJECT_CONTEXT_TOTAL_BYTES: number;
|
|
4
|
+
export declare const PROJECT_CONTEXT_INDEX_BYTES: number;
|
|
5
|
+
export declare const PROJECT_CONTEXT_INDEX_PATH = ".ztc/project-context.json";
|
|
6
|
+
export interface ProjectContextSource {
|
|
7
|
+
path: string;
|
|
8
|
+
sha256: string;
|
|
9
|
+
bytes: number;
|
|
10
|
+
git: {
|
|
11
|
+
head: string | null;
|
|
12
|
+
committed: boolean;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
export interface ProjectContextIndexResult {
|
|
16
|
+
status: 'indexed';
|
|
17
|
+
sources: ProjectContextSource[];
|
|
18
|
+
skipped: Array<{
|
|
19
|
+
path: string;
|
|
20
|
+
reason: string;
|
|
21
|
+
}>;
|
|
22
|
+
sourceBytes: number;
|
|
23
|
+
readBytes: number;
|
|
24
|
+
indexPath: string;
|
|
25
|
+
}
|
|
26
|
+
export interface ProjectContextMatch {
|
|
27
|
+
source: ProjectContextSource;
|
|
28
|
+
state: 'current' | 'stale' | 'missing' | 'unreadable';
|
|
29
|
+
excerpt: string;
|
|
30
|
+
line: number;
|
|
31
|
+
excerptTruncated?: true;
|
|
32
|
+
}
|
|
33
|
+
export interface ProjectContextQueryResult {
|
|
34
|
+
status: 'ok' | 'missing_index' | 'invalid_index';
|
|
35
|
+
matches: ProjectContextMatch[];
|
|
36
|
+
unknownSources: Array<{
|
|
37
|
+
path: string;
|
|
38
|
+
reason: string;
|
|
39
|
+
}>;
|
|
40
|
+
indexPath: string;
|
|
41
|
+
omittedMatches: number;
|
|
42
|
+
}
|
|
43
|
+
export declare function indexProjectContext(root: string, paths: string[]): Promise<ProjectContextIndexResult>;
|
|
44
|
+
export declare function queryProjectContext(root: string, query: string, paths?: string[]): Promise<ProjectContextQueryResult>;
|