@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
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/** Comparability of reported measurement data; neither source verification nor benchmark admission. */
|
|
2
|
+
export declare const MEASUREMENT_MAX_METRICS = 64;
|
|
3
|
+
export declare const MEASUREMENT_MAX_SELECTION = 16;
|
|
4
|
+
export declare const MEASUREMENT_MAX_REASONS = 32;
|
|
5
|
+
export declare const MEASUREMENT_MAX_ENVELOPE_BYTES: number;
|
|
6
|
+
export declare const MEASUREMENT_MAX_REPORT_BYTES: number;
|
|
7
|
+
export interface MeasurementSource {
|
|
8
|
+
revision: string;
|
|
9
|
+
artifactSha256: string;
|
|
10
|
+
}
|
|
11
|
+
export interface MeasurementWorkload {
|
|
12
|
+
id: string;
|
|
13
|
+
stage: string;
|
|
14
|
+
inputShape: Record<string, string | number>;
|
|
15
|
+
}
|
|
16
|
+
export interface MeasurementInstrumentation {
|
|
17
|
+
mode: string;
|
|
18
|
+
version: string;
|
|
19
|
+
synchronization: 'production' | 'diagnostic';
|
|
20
|
+
runtimePath: string;
|
|
21
|
+
}
|
|
22
|
+
export interface ReportedMetric {
|
|
23
|
+
id: string;
|
|
24
|
+
value: number;
|
|
25
|
+
unit: string;
|
|
26
|
+
timingDomain: string;
|
|
27
|
+
scope: string;
|
|
28
|
+
rank: number;
|
|
29
|
+
worldSize: number;
|
|
30
|
+
coverage: 'inclusive' | 'exclusive';
|
|
31
|
+
parentId?: string;
|
|
32
|
+
}
|
|
33
|
+
export interface MeasurementEnvelope {
|
|
34
|
+
schemaVersion: 1;
|
|
35
|
+
runId: string;
|
|
36
|
+
source: MeasurementSource;
|
|
37
|
+
workload: MeasurementWorkload;
|
|
38
|
+
instrumentation: MeasurementInstrumentation;
|
|
39
|
+
completion: {
|
|
40
|
+
status: 'running' | 'completed' | 'failed';
|
|
41
|
+
passed: boolean | null;
|
|
42
|
+
};
|
|
43
|
+
smoke: {
|
|
44
|
+
mode: string;
|
|
45
|
+
runtimePath: string;
|
|
46
|
+
fields: string[];
|
|
47
|
+
passed: boolean;
|
|
48
|
+
};
|
|
49
|
+
metrics: ReportedMetric[];
|
|
50
|
+
}
|
|
51
|
+
export interface MeasurementRequirements {
|
|
52
|
+
workload: MeasurementWorkload;
|
|
53
|
+
instrumentation: MeasurementInstrumentation;
|
|
54
|
+
metricIds: string[];
|
|
55
|
+
unit: string;
|
|
56
|
+
timingDomain: string;
|
|
57
|
+
scope: string;
|
|
58
|
+
worldSize: number;
|
|
59
|
+
expectedRanks: number[];
|
|
60
|
+
/** Requested metric IDs must exist both in smoke.fields and in the metrics array. */
|
|
61
|
+
smokeFields: string[];
|
|
62
|
+
aggregation: 'none' | 'sum_exclusive';
|
|
63
|
+
totalMetricId?: string;
|
|
64
|
+
}
|
|
65
|
+
export interface MeasurementReason {
|
|
66
|
+
code: string;
|
|
67
|
+
message: string;
|
|
68
|
+
}
|
|
69
|
+
export type MeasurementCompatibility = 'compatible' | 'incompatible' | 'unknown';
|
|
70
|
+
export type MeasurementCompletion = 'incomplete' | 'reported_pass' | 'reported_fail' | 'unknown';
|
|
71
|
+
export type MeasurementValue = Pick<ReportedMetric, 'id' | 'value' | 'unit' | 'timingDomain' | 'scope' | 'rank' | 'worldSize'>;
|
|
72
|
+
export interface MeasurementReport {
|
|
73
|
+
compatibility: MeasurementCompatibility;
|
|
74
|
+
verification: 'unknown';
|
|
75
|
+
benchmarkEligibility: 'unknown';
|
|
76
|
+
completion: MeasurementCompletion;
|
|
77
|
+
runId: string | null;
|
|
78
|
+
source: MeasurementSource | null;
|
|
79
|
+
reasons: MeasurementReason[];
|
|
80
|
+
values: MeasurementValue[];
|
|
81
|
+
aggregate: number | null;
|
|
82
|
+
residual: {
|
|
83
|
+
value: number;
|
|
84
|
+
attribution: 'unattributed';
|
|
85
|
+
removableWin: false;
|
|
86
|
+
} | null;
|
|
87
|
+
}
|
|
88
|
+
export interface MeasurementDelta {
|
|
89
|
+
id: string;
|
|
90
|
+
baseline: number;
|
|
91
|
+
candidate: number;
|
|
92
|
+
delta: number;
|
|
93
|
+
relativeChangePercent: number | null;
|
|
94
|
+
}
|
|
95
|
+
export interface MeasurementComparison {
|
|
96
|
+
compatibility: MeasurementCompatibility;
|
|
97
|
+
verification: 'unknown';
|
|
98
|
+
benchmarkEligibility: 'unknown';
|
|
99
|
+
baseline: MeasurementReport;
|
|
100
|
+
candidate: MeasurementReport;
|
|
101
|
+
reasons: MeasurementReason[];
|
|
102
|
+
deltas: MeasurementDelta[];
|
|
103
|
+
}
|
|
104
|
+
/** Parse only the producer's bounded declaration. A well-formed declaration is not verified evidence. */
|
|
105
|
+
export declare function parseMeasurementEnvelope(value: unknown): MeasurementEnvelope | null;
|
|
106
|
+
export declare function parseMeasurementRequirements(value: unknown): MeasurementRequirements | null;
|
|
107
|
+
/** Check comparability against visible caller requirements, without trusting the producer's scientific or source claims. */
|
|
108
|
+
export declare function assessMeasurements(value: unknown, requirements: unknown): MeasurementReport;
|
|
109
|
+
/** Compare matching reported identities. Positive/negative deltas have no inferred optimization direction. */
|
|
110
|
+
export declare function compareMeasurements(base: unknown, candidate: unknown, requirements: unknown): MeasurementComparison;
|
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
/** Comparability of reported measurement data; neither source verification nor benchmark admission. */
|
|
2
|
+
export const MEASUREMENT_MAX_METRICS = 64;
|
|
3
|
+
export const MEASUREMENT_MAX_SELECTION = 16;
|
|
4
|
+
export const MEASUREMENT_MAX_REASONS = 32;
|
|
5
|
+
export const MEASUREMENT_MAX_ENVELOPE_BYTES = 128 * 1024;
|
|
6
|
+
export const MEASUREMENT_MAX_REPORT_BYTES = 64 * 1024;
|
|
7
|
+
const encoder = new TextEncoder();
|
|
8
|
+
const byteLength = (value) => encoder.encode(value).length;
|
|
9
|
+
const serializedBytes = (value) => byteLength(JSON.stringify(value));
|
|
10
|
+
function object(value, required, optional = []) {
|
|
11
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
12
|
+
throw new TypeError('Expected an object');
|
|
13
|
+
const record = value;
|
|
14
|
+
if (required.some(key => !Object.hasOwn(record, key))
|
|
15
|
+
|| Object.keys(record).some(key => !required.includes(key) && !optional.includes(key)))
|
|
16
|
+
throw new TypeError('Invalid fields');
|
|
17
|
+
return record;
|
|
18
|
+
}
|
|
19
|
+
function text(value, maxBytes = 256) {
|
|
20
|
+
if (typeof value !== 'string' || !value.trim() || byteLength(value) > maxBytes
|
|
21
|
+
|| /[\u0000-\u001f\u007f]/u.test(value))
|
|
22
|
+
throw new TypeError('Invalid bounded text');
|
|
23
|
+
return value;
|
|
24
|
+
}
|
|
25
|
+
function integer(value, minimum = 0) {
|
|
26
|
+
if (typeof value !== 'number' || !Number.isSafeInteger(value) || value < minimum)
|
|
27
|
+
throw new TypeError('Invalid integer');
|
|
28
|
+
return value;
|
|
29
|
+
}
|
|
30
|
+
function number(value) {
|
|
31
|
+
if (typeof value !== 'number' || !Number.isFinite(value))
|
|
32
|
+
throw new TypeError('Invalid finite number');
|
|
33
|
+
return value;
|
|
34
|
+
}
|
|
35
|
+
function strings(value, minimum = 0) {
|
|
36
|
+
if (!Array.isArray(value) || value.length < minimum || value.length > MEASUREMENT_MAX_SELECTION)
|
|
37
|
+
throw new TypeError('Invalid bounded list');
|
|
38
|
+
const result = value.map(item => text(item));
|
|
39
|
+
if (new Set(result).size !== result.length)
|
|
40
|
+
throw new TypeError('Duplicate identity');
|
|
41
|
+
return result;
|
|
42
|
+
}
|
|
43
|
+
function workload(value) {
|
|
44
|
+
const record = object(value, ['id', 'stage', 'inputShape']);
|
|
45
|
+
if (!record.inputShape || typeof record.inputShape !== 'object' || Array.isArray(record.inputShape))
|
|
46
|
+
throw new TypeError('Invalid input shape');
|
|
47
|
+
const entries = Object.entries(record.inputShape);
|
|
48
|
+
if (entries.length > MEASUREMENT_MAX_SELECTION)
|
|
49
|
+
throw new TypeError('Input shape exceeds its bound');
|
|
50
|
+
return { id: text(record.id), stage: text(record.stage, 128), inputShape: Object.fromEntries(entries.map(([key, item]) => [text(key, 128), typeof item === 'string' ? text(item) : number(item)])) };
|
|
51
|
+
}
|
|
52
|
+
function instrumentation(value) {
|
|
53
|
+
const record = object(value, ['mode', 'version', 'synchronization', 'runtimePath']);
|
|
54
|
+
if (record.synchronization !== 'production' && record.synchronization !== 'diagnostic')
|
|
55
|
+
throw new TypeError('Invalid synchronization');
|
|
56
|
+
return { mode: text(record.mode, 128), version: text(record.version, 128), synchronization: record.synchronization,
|
|
57
|
+
runtimePath: text(record.runtimePath, 4096) };
|
|
58
|
+
}
|
|
59
|
+
function metric(value) {
|
|
60
|
+
const record = object(value, ['id', 'value', 'unit', 'timingDomain', 'scope', 'rank', 'worldSize', 'coverage'], ['parentId']);
|
|
61
|
+
const measured = number(record.value), rank = integer(record.rank), worldSize = integer(record.worldSize, 1);
|
|
62
|
+
if (measured < 0 || rank >= worldSize || (record.coverage !== 'inclusive' && record.coverage !== 'exclusive'))
|
|
63
|
+
throw new TypeError('Invalid metric scope');
|
|
64
|
+
return { id: text(record.id), value: measured, unit: text(record.unit, 128), timingDomain: text(record.timingDomain, 128),
|
|
65
|
+
scope: text(record.scope, 128), rank, worldSize, coverage: record.coverage,
|
|
66
|
+
...(record.parentId === undefined ? {} : { parentId: text(record.parentId) }) };
|
|
67
|
+
}
|
|
68
|
+
/** Parse only the producer's bounded declaration. A well-formed declaration is not verified evidence. */
|
|
69
|
+
export function parseMeasurementEnvelope(value) {
|
|
70
|
+
try {
|
|
71
|
+
const record = object(value, ['schemaVersion', 'runId', 'source', 'workload', 'instrumentation', 'completion', 'smoke', 'metrics']);
|
|
72
|
+
if (record.schemaVersion !== 1)
|
|
73
|
+
return null;
|
|
74
|
+
const source = object(record.source, ['revision', 'artifactSha256']);
|
|
75
|
+
if (typeof source.artifactSha256 !== 'string' || !/^[a-f0-9]{64}$/.test(source.artifactSha256))
|
|
76
|
+
return null;
|
|
77
|
+
const completion = object(record.completion, ['status', 'passed']);
|
|
78
|
+
if (completion.status !== 'running' && completion.status !== 'completed' && completion.status !== 'failed')
|
|
79
|
+
return null;
|
|
80
|
+
if (completion.passed !== null && typeof completion.passed !== 'boolean')
|
|
81
|
+
return null;
|
|
82
|
+
const smoke = object(record.smoke, ['mode', 'runtimePath', 'fields', 'passed']);
|
|
83
|
+
if (typeof smoke.passed !== 'boolean' || !Array.isArray(record.metrics) || record.metrics.length > MEASUREMENT_MAX_METRICS)
|
|
84
|
+
return null;
|
|
85
|
+
const metrics = record.metrics.map(metric), byId = new Map(metrics.map(item => [item.id, item]));
|
|
86
|
+
if (byId.size !== metrics.length)
|
|
87
|
+
return null;
|
|
88
|
+
for (const item of metrics) {
|
|
89
|
+
const visited = new Set([item.id]);
|
|
90
|
+
let parent = item.parentId;
|
|
91
|
+
while (parent !== undefined) {
|
|
92
|
+
if (!byId.has(parent) || visited.has(parent))
|
|
93
|
+
return null;
|
|
94
|
+
visited.add(parent);
|
|
95
|
+
parent = byId.get(parent).parentId;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
const parsed = { schemaVersion: 1, runId: text(record.runId),
|
|
99
|
+
source: { revision: text(source.revision), artifactSha256: source.artifactSha256 },
|
|
100
|
+
workload: workload(record.workload), instrumentation: instrumentation(record.instrumentation),
|
|
101
|
+
completion: { status: completion.status, passed: completion.passed },
|
|
102
|
+
smoke: { mode: text(smoke.mode, 128), runtimePath: text(smoke.runtimePath, 4096), fields: strings(smoke.fields), passed: smoke.passed }, metrics };
|
|
103
|
+
return serializedBytes(parsed) <= MEASUREMENT_MAX_ENVELOPE_BYTES ? parsed : null;
|
|
104
|
+
}
|
|
105
|
+
catch {
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
export function parseMeasurementRequirements(value) {
|
|
110
|
+
try {
|
|
111
|
+
const record = object(value, ['workload', 'instrumentation', 'metricIds', 'unit', 'timingDomain', 'scope', 'worldSize',
|
|
112
|
+
'expectedRanks', 'smokeFields', 'aggregation'], ['totalMetricId']);
|
|
113
|
+
const worldSize = integer(record.worldSize, 1);
|
|
114
|
+
if (!Array.isArray(record.expectedRanks) || record.expectedRanks.length < 1 || record.expectedRanks.length > MEASUREMENT_MAX_SELECTION)
|
|
115
|
+
return null;
|
|
116
|
+
const ranks = record.expectedRanks.map(item => integer(item));
|
|
117
|
+
if (new Set(ranks).size !== ranks.length || ranks.some(rank => rank >= worldSize))
|
|
118
|
+
return null;
|
|
119
|
+
if (record.aggregation !== 'none' && record.aggregation !== 'sum_exclusive')
|
|
120
|
+
return null;
|
|
121
|
+
return { workload: workload(record.workload), instrumentation: instrumentation(record.instrumentation),
|
|
122
|
+
metricIds: strings(record.metricIds, 1), unit: text(record.unit, 128), timingDomain: text(record.timingDomain, 128),
|
|
123
|
+
scope: text(record.scope, 128), worldSize, expectedRanks: ranks, smokeFields: strings(record.smokeFields, 1), aggregation: record.aggregation,
|
|
124
|
+
...(record.totalMetricId === undefined ? {} : { totalMetricId: text(record.totalMetricId) }) };
|
|
125
|
+
}
|
|
126
|
+
catch {
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
function emptyReport(envelope) {
|
|
131
|
+
return { compatibility: 'unknown', verification: 'unknown', benchmarkEligibility: 'unknown', completion: 'unknown',
|
|
132
|
+
runId: envelope?.runId ?? null, source: envelope?.source ?? null, reasons: [], values: [], aggregate: null, residual: null };
|
|
133
|
+
}
|
|
134
|
+
function compactReport(report) {
|
|
135
|
+
return { ...report, compatibility: 'unknown', reasons: [{ code: 'report_limit', message: 'The report exceeds its bounded representation; narrow the selection.' }],
|
|
136
|
+
values: [], aggregate: null, residual: null };
|
|
137
|
+
}
|
|
138
|
+
function sameShape(left, right) {
|
|
139
|
+
const keys = Object.keys(left);
|
|
140
|
+
return keys.length === Object.keys(right).length && keys.every(key => Object.hasOwn(right, key) && left[key] === right[key]);
|
|
141
|
+
}
|
|
142
|
+
function sameScope(item, required) {
|
|
143
|
+
return item.unit === required.unit && item.timingDomain === required.timingDomain && item.scope === required.scope
|
|
144
|
+
&& item.worldSize === required.worldSize;
|
|
145
|
+
}
|
|
146
|
+
/** Check comparability against visible caller requirements, without trusting the producer's scientific or source claims. */
|
|
147
|
+
export function assessMeasurements(value, requirements) {
|
|
148
|
+
const envelope = parseMeasurementEnvelope(value), required = parseMeasurementRequirements(requirements);
|
|
149
|
+
const report = emptyReport(envelope);
|
|
150
|
+
if (!envelope || !required) {
|
|
151
|
+
if (!envelope)
|
|
152
|
+
report.reasons.push({ code: 'invalid_envelope', message: 'The reported measurement envelope is missing, malformed, or exceeds its bounds.' });
|
|
153
|
+
if (!required)
|
|
154
|
+
report.reasons.push({ code: 'invalid_requirements', message: 'Explicit bounded measurement requirements are missing or malformed.' });
|
|
155
|
+
return report;
|
|
156
|
+
}
|
|
157
|
+
let incompatible = false, unknown = false;
|
|
158
|
+
const issue = (compatibility, code, message) => {
|
|
159
|
+
if (compatibility === 'incompatible')
|
|
160
|
+
incompatible = true;
|
|
161
|
+
else
|
|
162
|
+
unknown = true;
|
|
163
|
+
if (report.reasons.length < MEASUREMENT_MAX_REASONS)
|
|
164
|
+
report.reasons.push({ code, message });
|
|
165
|
+
};
|
|
166
|
+
if (envelope.workload.id !== required.workload.id || envelope.workload.stage !== required.workload.stage
|
|
167
|
+
|| !sameShape(envelope.workload.inputShape, required.workload.inputShape)) {
|
|
168
|
+
issue('incompatible', 'workload_mismatch', 'Reported workload, stage and input shape must match the declared comparison.');
|
|
169
|
+
}
|
|
170
|
+
if (envelope.instrumentation.mode !== required.instrumentation.mode || envelope.instrumentation.version !== required.instrumentation.version
|
|
171
|
+
|| envelope.instrumentation.synchronization !== required.instrumentation.synchronization
|
|
172
|
+
|| envelope.instrumentation.runtimePath !== required.instrumentation.runtimePath) {
|
|
173
|
+
issue('incompatible', 'instrumentation_mismatch', 'Reported instrumentation mode, version, synchronization and runtime path must match.');
|
|
174
|
+
}
|
|
175
|
+
if (envelope.completion.status === 'running') {
|
|
176
|
+
report.completion = 'incomplete';
|
|
177
|
+
issue('unknown', 'incomplete', 'A running producer has not reported a completed measurement.');
|
|
178
|
+
}
|
|
179
|
+
else if (envelope.completion.status === 'failed' || envelope.completion.passed === false) {
|
|
180
|
+
report.completion = 'reported_fail';
|
|
181
|
+
issue('incompatible', 'reported_failure', 'The producer reports a failed run.');
|
|
182
|
+
}
|
|
183
|
+
else if (envelope.completion.passed === null) {
|
|
184
|
+
issue('unknown', 'missing_pass', 'The completed producer has not reported a pass outcome.');
|
|
185
|
+
}
|
|
186
|
+
else
|
|
187
|
+
report.completion = 'reported_pass';
|
|
188
|
+
if (envelope.smoke.mode !== required.instrumentation.mode || envelope.smoke.runtimePath !== required.instrumentation.runtimePath) {
|
|
189
|
+
issue('incompatible', 'smoke_path_mismatch', 'Smoke observations must name the requested mode and runtime path.');
|
|
190
|
+
}
|
|
191
|
+
if (!envelope.smoke.passed)
|
|
192
|
+
issue('incompatible', 'smoke_failed', 'The producer reports a failed smoke check.');
|
|
193
|
+
const byId = new Map(envelope.metrics.map(item => [item.id, item]));
|
|
194
|
+
for (const id of required.smokeFields) {
|
|
195
|
+
const item = byId.get(id);
|
|
196
|
+
if (!envelope.smoke.fields.includes(id) || !item)
|
|
197
|
+
issue('unknown', 'missing_smoke_metric', `Requested smoke metric is missing: ${id}`);
|
|
198
|
+
else if (!sameScope(item, required) || !required.expectedRanks.includes(item.rank)) {
|
|
199
|
+
issue('incompatible', 'smoke_scope_mismatch', `Requested smoke metric has a different timing or execution scope: ${id}`);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
const selected = [];
|
|
203
|
+
for (const id of required.metricIds) {
|
|
204
|
+
const item = byId.get(id);
|
|
205
|
+
if (!item) {
|
|
206
|
+
issue('unknown', 'missing_metric', `Requested measurement is missing: ${id}`);
|
|
207
|
+
continue;
|
|
208
|
+
}
|
|
209
|
+
selected.push(item);
|
|
210
|
+
const { value: measured, unit, timingDomain, scope, rank, worldSize } = item;
|
|
211
|
+
report.values.push({ id, value: measured, unit, timingDomain, scope, rank, worldSize });
|
|
212
|
+
if (!sameScope(item, required))
|
|
213
|
+
issue('incompatible', 'metric_scope_mismatch', `Measurement unit, timing domain, scope or world size differs: ${id}`);
|
|
214
|
+
if (!required.expectedRanks.includes(rank))
|
|
215
|
+
issue('incompatible', 'unexpected_rank', `Measurement has an undeclared rank: ${id}`);
|
|
216
|
+
}
|
|
217
|
+
const ranks = new Set(selected.map(item => item.rank));
|
|
218
|
+
for (const rank of required.expectedRanks)
|
|
219
|
+
if (!ranks.has(rank))
|
|
220
|
+
issue('unknown', 'missing_rank', `Requested rank has no selected measurement: ${rank}`);
|
|
221
|
+
let aggregate = null;
|
|
222
|
+
if (required.aggregation === 'sum_exclusive') {
|
|
223
|
+
const selectedIds = new Set(required.metricIds);
|
|
224
|
+
for (const item of selected) {
|
|
225
|
+
if (item.coverage !== 'exclusive')
|
|
226
|
+
issue('incompatible', 'inclusive_sum', `An inclusive measurement cannot enter an exclusive sum: ${item.id}`);
|
|
227
|
+
let parent = item.parentId;
|
|
228
|
+
while (parent !== undefined) {
|
|
229
|
+
if (selectedIds.has(parent)) {
|
|
230
|
+
issue('incompatible', 'nested_sum', 'A selected ancestor and descendant cannot be summed together.');
|
|
231
|
+
break;
|
|
232
|
+
}
|
|
233
|
+
parent = byId.get(parent).parentId;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
if (ranks.size > 1)
|
|
237
|
+
issue('incompatible', 'cross_rank_sum', 'Measurements from different ranks cannot be added as one exclusive duration.');
|
|
238
|
+
aggregate = selected.reduce((total, item) => total + item.value, 0);
|
|
239
|
+
if (!Number.isFinite(aggregate)) {
|
|
240
|
+
aggregate = null;
|
|
241
|
+
issue('incompatible', 'arithmetic_overflow', 'The selected sum is not representable as a finite number.');
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
let residual = null;
|
|
245
|
+
if (required.totalMetricId !== undefined) {
|
|
246
|
+
const total = byId.get(required.totalMetricId);
|
|
247
|
+
if (!total)
|
|
248
|
+
issue('unknown', 'missing_total', 'The requested denominator measurement is absent.');
|
|
249
|
+
else if (required.metricIds.includes(total.id))
|
|
250
|
+
issue('incompatible', 'selected_total', 'The denominator cannot also be selected as a summed component.');
|
|
251
|
+
else if (total.coverage !== 'inclusive')
|
|
252
|
+
issue('incompatible', 'exclusive_total', 'A residual denominator must report inclusive coverage.');
|
|
253
|
+
else if (!sameScope(total, required)) {
|
|
254
|
+
issue('incompatible', 'total_scope_mismatch', 'The denominator must match selected units, timing domain, scope, world size and rank.');
|
|
255
|
+
}
|
|
256
|
+
else if (ranks.size === 0)
|
|
257
|
+
issue('unknown', 'missing_selected_scope', 'No selected component establishes a rank for the denominator.');
|
|
258
|
+
else if (ranks.size !== 1 || !ranks.has(total.rank)) {
|
|
259
|
+
issue('incompatible', 'total_scope_mismatch', 'The denominator must match selected units, timing domain, scope, world size and rank.');
|
|
260
|
+
}
|
|
261
|
+
else if (aggregate === null)
|
|
262
|
+
issue('unknown', 'missing_aggregate', 'A residual requires an explicit finite exclusive sum.');
|
|
263
|
+
else if (total.value < aggregate)
|
|
264
|
+
issue('incompatible', 'over_accounted', 'Selected components exceed the reported denominator.');
|
|
265
|
+
else
|
|
266
|
+
residual = { value: total.value - aggregate, attribution: 'unattributed', removableWin: false };
|
|
267
|
+
}
|
|
268
|
+
report.compatibility = incompatible ? 'incompatible' : unknown ? 'unknown' : 'compatible';
|
|
269
|
+
if (report.compatibility === 'compatible') {
|
|
270
|
+
report.aggregate = aggregate;
|
|
271
|
+
report.residual = residual;
|
|
272
|
+
}
|
|
273
|
+
return serializedBytes(report) <= MEASUREMENT_MAX_REPORT_BYTES ? report : compactReport(report);
|
|
274
|
+
}
|
|
275
|
+
/** Compare matching reported identities. Positive/negative deltas have no inferred optimization direction. */
|
|
276
|
+
export function compareMeasurements(base, candidate, requirements) {
|
|
277
|
+
const baseEnvelope = parseMeasurementEnvelope(base), nextEnvelope = parseMeasurementEnvelope(candidate);
|
|
278
|
+
const baseline = assessMeasurements(baseEnvelope, requirements), next = assessMeasurements(nextEnvelope, requirements);
|
|
279
|
+
const comparison = { compatibility: 'compatible', verification: 'unknown', benchmarkEligibility: 'unknown',
|
|
280
|
+
baseline, candidate: next, reasons: [], deltas: [] };
|
|
281
|
+
if (baseline.compatibility !== 'compatible' || next.compatibility !== 'compatible') {
|
|
282
|
+
comparison.compatibility = baseline.compatibility === 'incompatible' || next.compatibility === 'incompatible' ? 'incompatible' : 'unknown';
|
|
283
|
+
for (const [label, report] of [['baseline', baseline], ['candidate', next]]) {
|
|
284
|
+
if (report.compatibility !== 'compatible')
|
|
285
|
+
comparison.reasons.push({ code: `${label}_${report.compatibility}`, message: `Inspect the ${label} report for unmet measurement requirements.` });
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
else {
|
|
289
|
+
const candidates = new Map(next.values.map(item => [item.id, item]));
|
|
290
|
+
const previousCoverage = new Map(baseEnvelope.metrics.map(item => [item.id, item.coverage]));
|
|
291
|
+
const nextCoverage = new Map(nextEnvelope.metrics.map(item => [item.id, item.coverage]));
|
|
292
|
+
for (const previous of baseline.values) {
|
|
293
|
+
const measured = candidates.get(previous.id);
|
|
294
|
+
if (measured.rank !== previous.rank || measured.scope !== previous.scope || previousCoverage.get(previous.id) !== nextCoverage.get(previous.id)) {
|
|
295
|
+
comparison.compatibility = 'incompatible';
|
|
296
|
+
comparison.reasons.push({ code: 'identity_scope_changed', message: `A selected identity changed rank, scope or coverage: ${previous.id}` });
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
if (comparison.compatibility === 'compatible') {
|
|
300
|
+
for (const previous of baseline.values) {
|
|
301
|
+
const measured = candidates.get(previous.id);
|
|
302
|
+
const delta = measured.value - previous.value;
|
|
303
|
+
const relative = previous.value === 0 ? null : delta / previous.value * 100;
|
|
304
|
+
comparison.deltas.push({ id: previous.id, baseline: previous.value, candidate: measured.value, delta,
|
|
305
|
+
relativeChangePercent: relative !== null && Number.isFinite(relative) ? relative : null });
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
if (serializedBytes(comparison) > MEASUREMENT_MAX_REPORT_BYTES) {
|
|
310
|
+
comparison.compatibility = 'unknown';
|
|
311
|
+
comparison.baseline = compactReport(baseline);
|
|
312
|
+
comparison.candidate = compactReport(next);
|
|
313
|
+
comparison.deltas = [];
|
|
314
|
+
comparison.reasons = [{ code: 'report_limit', message: 'Narrow the selection to fit the bounded comparison report.' }];
|
|
315
|
+
}
|
|
316
|
+
return comparison;
|
|
317
|
+
}
|
|
@@ -4,10 +4,14 @@ export interface ToolPolicyRequest {
|
|
|
4
4
|
name: string;
|
|
5
5
|
args: Record<string, unknown>;
|
|
6
6
|
capabilities: ToolCapability[];
|
|
7
|
+
/** Host-declared effective directory, after hooks and adapter mapping. */
|
|
8
|
+
executionCwd?: string;
|
|
7
9
|
}
|
|
8
10
|
export interface ToolPolicyDecision {
|
|
9
11
|
allowed: boolean;
|
|
10
12
|
reason?: string;
|
|
13
|
+
/** Reuse the host approval boundary before this admitted effect. */
|
|
14
|
+
approvalRequired?: boolean;
|
|
11
15
|
}
|
|
12
16
|
export interface Policy {
|
|
13
17
|
evaluateTool(request: ToolPolicyRequest): ToolPolicyDecision;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { ToolCapability } from './capabilities.js';
|
|
2
2
|
import { homedir } from 'os';
|
|
3
3
|
import { resolve, isAbsolute, sep } from 'path';
|
|
4
|
+
import { parseCheckedCommandPlan } from './checked_commands.js';
|
|
5
|
+
import { formatCheckedStageCommand } from '../../utils/checked_shell.js';
|
|
4
6
|
export class AllowAllPolicy {
|
|
5
7
|
evaluateTool() {
|
|
6
8
|
return { allowed: true };
|
|
@@ -46,13 +48,14 @@ export class CapabilityPolicy {
|
|
|
46
48
|
if (!networkDecision.allowed) {
|
|
47
49
|
return networkDecision;
|
|
48
50
|
}
|
|
49
|
-
|
|
51
|
+
const approvalRequired = this.profile?.approvalRequiredCapabilities?.some(cap => request.capabilities.includes(cap)) === true;
|
|
52
|
+
return { allowed: true, ...(approvalRequired ? { approvalRequired } : {}) };
|
|
50
53
|
}
|
|
51
54
|
evaluatePathPolicy(request) {
|
|
52
55
|
if (!this.profile || !request.capabilities.some(capability => (capability === ToolCapability.FILE_READ || capability === ToolCapability.FILE_WRITE))) {
|
|
53
56
|
return { allowed: true };
|
|
54
57
|
}
|
|
55
|
-
const paths = extractPathArgs(request.args);
|
|
58
|
+
const paths = extractPathArgs(request.args, request.executionCwd);
|
|
56
59
|
if (paths.length === 0) {
|
|
57
60
|
return { allowed: true };
|
|
58
61
|
}
|
|
@@ -79,23 +82,28 @@ export class CapabilityPolicy {
|
|
|
79
82
|
if (!this.profile || !request.capabilities.includes(ToolCapability.SHELL_EXEC)) {
|
|
80
83
|
return { allowed: true };
|
|
81
84
|
}
|
|
82
|
-
const
|
|
83
|
-
if (
|
|
84
|
-
return { allowed:
|
|
85
|
-
|
|
85
|
+
const checked = Object.hasOwn(request.args, 'checked') ? parseCheckedCommandPlan(request.args.checked) : undefined;
|
|
86
|
+
if (checked === null)
|
|
87
|
+
return { allowed: false, reason: 'Permission denied: invalid checked command plan' };
|
|
88
|
+
const commands = checked ? checked.steps.flatMap(step => step.pipeline.map(formatCheckedStageCommand))
|
|
89
|
+
: [typeof request.args.command === 'string' ? request.args.command.trim() : ''];
|
|
86
90
|
const denied = this.profile.deniedShellCommands || [];
|
|
87
|
-
if (denied.some(prefix => command.startsWith(prefix))) {
|
|
88
|
-
return {
|
|
89
|
-
allowed: false,
|
|
90
|
-
reason: `Permission denied: shell command blocked by profile (${command})`,
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
91
|
const allowed = this.profile.allowedShellCommands || [];
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
92
|
+
for (const command of commands) {
|
|
93
|
+
if (!command)
|
|
94
|
+
continue;
|
|
95
|
+
if (denied.some(prefix => command.startsWith(prefix))) {
|
|
96
|
+
return {
|
|
97
|
+
allowed: false,
|
|
98
|
+
reason: `Permission denied: shell command blocked by profile (${command})`,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
if (allowed.length > 0 && !allowed.some(prefix => command.startsWith(prefix))) {
|
|
102
|
+
return {
|
|
103
|
+
allowed: false,
|
|
104
|
+
reason: `Permission denied: shell command is outside allowed profile commands (${command})`,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
99
107
|
}
|
|
100
108
|
return { allowed: true };
|
|
101
109
|
}
|
|
@@ -126,9 +134,12 @@ export class CapabilityPolicy {
|
|
|
126
134
|
return { allowed: true };
|
|
127
135
|
}
|
|
128
136
|
}
|
|
129
|
-
function extractPathArgs(args) {
|
|
130
|
-
|
|
131
|
-
|
|
137
|
+
function extractPathArgs(args, executionCwd) {
|
|
138
|
+
// Declared execution mapping owns cwd/workdir precedence. Undeclared tools
|
|
139
|
+
// retain conservative checks of both raw fields and all other file paths.
|
|
140
|
+
const candidates = ['path', 'file_path', 'filepath', 'directory',
|
|
141
|
+
...(executionCwd === undefined ? ['cwd', 'workdir'] : []), 'repo_path', 'artifact_path'];
|
|
142
|
+
const paths = executionCwd === undefined ? [] : [executionCwd];
|
|
132
143
|
for (const key of candidates) {
|
|
133
144
|
const value = args[key];
|
|
134
145
|
if (typeof value === 'string' && value.trim().length > 0) {
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { BackendObservation } from '../backends/types.js';
|
|
2
|
+
import type { EvidenceSource } from './evidence.js';
|
|
3
|
+
export declare const NATIVE_REPORT_OUTPUT_BYTES: number;
|
|
4
|
+
export declare const NATIVE_REPORT_INPUT_OUTPUT_BYTES: number;
|
|
5
|
+
export declare const NATIVE_REPORT_MAX_ARTIFACTS = 16;
|
|
6
|
+
export declare class NativeObservationLimitError extends Error {
|
|
7
|
+
constructor(maximum: number);
|
|
8
|
+
}
|
|
9
|
+
export interface NativeEvidenceCapture {
|
|
10
|
+
handle: string;
|
|
11
|
+
content: string;
|
|
12
|
+
source: EvidenceSource;
|
|
13
|
+
partial: boolean;
|
|
14
|
+
isError: boolean;
|
|
15
|
+
}
|
|
16
|
+
/** Only explicit command/action fields are retained; reasoning and opaque detail are display-only. */
|
|
17
|
+
export declare function captureNativeReport(observation: BackendObservation, fallback: {
|
|
18
|
+
provider: string;
|
|
19
|
+
turnId: string;
|
|
20
|
+
}): NativeEvidenceCapture | null;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
export const NATIVE_REPORT_OUTPUT_BYTES = 64 * 1024;
|
|
3
|
+
export const NATIVE_REPORT_INPUT_OUTPUT_BYTES = 1024 * 1024;
|
|
4
|
+
export const NATIVE_REPORT_MAX_ARTIFACTS = 16;
|
|
5
|
+
export class NativeObservationLimitError extends Error {
|
|
6
|
+
constructor(maximum) {
|
|
7
|
+
super(`Native observation limit exceeded (${maximum}); inspect retained reports before repeating work.`);
|
|
8
|
+
this.name = 'NativeObservationLimitError';
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
function identity(value) {
|
|
12
|
+
return typeof value === 'string' && value.length > 0 && Buffer.byteLength(value) <= 256
|
|
13
|
+
&& !/[\u0000-\u001f\u007f]/u.test(value);
|
|
14
|
+
}
|
|
15
|
+
function path(value) {
|
|
16
|
+
return typeof value === 'string' && value.length > 0 && Buffer.byteLength(value) <= 4096
|
|
17
|
+
&& !/[\u0000-\u001f\u007f]/u.test(value);
|
|
18
|
+
}
|
|
19
|
+
function prefix(value, maximum) {
|
|
20
|
+
const encoded = Buffer.from(value);
|
|
21
|
+
let end = Math.min(encoded.length, maximum);
|
|
22
|
+
while (end > 0 && end < encoded.length && (encoded[end] & 0xc0) === 0x80)
|
|
23
|
+
end--;
|
|
24
|
+
return encoded.subarray(0, end).toString('utf8');
|
|
25
|
+
}
|
|
26
|
+
/** Only explicit command/action fields are retained; reasoning and opaque detail are display-only. */
|
|
27
|
+
export function captureNativeReport(observation, fallback) {
|
|
28
|
+
if (observation.kind === 'reasoning')
|
|
29
|
+
return null;
|
|
30
|
+
const native = observation.native;
|
|
31
|
+
const provider = native?.provider ?? fallback.provider;
|
|
32
|
+
const turnId = native?.turnId ?? fallback.turnId;
|
|
33
|
+
const threadId = native?.threadId;
|
|
34
|
+
if (!identity(observation.id) || !identity(provider) || !identity(turnId)
|
|
35
|
+
|| (threadId !== undefined && !identity(threadId)))
|
|
36
|
+
return null;
|
|
37
|
+
if (observation.kind === 'command' && !path(observation.command))
|
|
38
|
+
return null;
|
|
39
|
+
if (observation.kind === 'action' && (!identity(observation.label) || /reasoning|thinking|analysis/i.test(observation.label)))
|
|
40
|
+
return null;
|
|
41
|
+
if (observation.kind === 'command' && observation.cwd !== undefined && !path(observation.cwd))
|
|
42
|
+
return null;
|
|
43
|
+
const status = observation.status ?? 'unknown';
|
|
44
|
+
if (!identity(status))
|
|
45
|
+
return null;
|
|
46
|
+
const exitCode = observation.kind === 'command' ? observation.exitCode ?? null : null;
|
|
47
|
+
if (exitCode !== null && (!Number.isSafeInteger(exitCode) || typeof exitCode !== 'number'))
|
|
48
|
+
return null;
|
|
49
|
+
const durationMs = observation.kind === 'command' ? observation.durationMs : undefined;
|
|
50
|
+
if (durationMs !== undefined && (!Number.isSafeInteger(durationMs) || durationMs < 0))
|
|
51
|
+
return null;
|
|
52
|
+
const output = observation.output;
|
|
53
|
+
if (output !== undefined && (typeof output !== 'string' || Buffer.byteLength(output) > NATIVE_REPORT_INPUT_OUTPUT_BYTES))
|
|
54
|
+
return null;
|
|
55
|
+
const keptOutput = output === undefined ? undefined : prefix(output, NATIVE_REPORT_OUTPUT_BYTES);
|
|
56
|
+
const outputBytes = output === undefined ? 0 : Buffer.byteLength(output);
|
|
57
|
+
const omittedOutputBytes = outputBytes - (keptOutput === undefined ? 0 : Buffer.byteLength(keptOutput));
|
|
58
|
+
const artifacts = [];
|
|
59
|
+
const rawArtifacts = observation.kind === 'action' ? observation.artifacts ?? [] : [];
|
|
60
|
+
if (!Array.isArray(rawArtifacts) || rawArtifacts.length > 1024)
|
|
61
|
+
return null;
|
|
62
|
+
for (const artifact of rawArtifacts.slice(0, NATIVE_REPORT_MAX_ARTIFACTS)) {
|
|
63
|
+
if (!artifact || !path(artifact.path) || (artifact.sha256 !== undefined && !/^[a-f0-9]{64}$/.test(artifact.sha256)))
|
|
64
|
+
return null;
|
|
65
|
+
artifacts.push({ path: artifact.path, ...(artifact.sha256 === undefined ? {} : { sha256: artifact.sha256 }) });
|
|
66
|
+
}
|
|
67
|
+
const omittedArtifacts = rawArtifacts.length - artifacts.length;
|
|
68
|
+
const partial = output === undefined || status === 'unknown' || omittedOutputBytes > 0 || omittedArtifacts > 0
|
|
69
|
+
|| (observation.kind === 'action' && observation.partial === true)
|
|
70
|
+
|| (observation.kind === 'command' && exitCode === null);
|
|
71
|
+
const scope = { provider, ...(threadId === undefined ? {} : { threadId }), turnId, itemId: observation.id };
|
|
72
|
+
// Filesystem-safe names preserve the full source identity without provider-ID path/name limits.
|
|
73
|
+
const handle = `native_${createHash('sha256').update(JSON.stringify(scope)).digest('hex')}`;
|
|
74
|
+
const content = JSON.stringify({ schemaVersion: 1, kind: observation.kind, ...scope, status, exitCode,
|
|
75
|
+
...(durationMs === undefined ? {} : { durationMs }),
|
|
76
|
+
...(observation.kind === 'command' ? { command: observation.command, ...(observation.cwd === undefined ? {} : { cwd: observation.cwd }) }
|
|
77
|
+
: { label: observation.label, detailRetained: false }),
|
|
78
|
+
...(keptOutput === undefined ? {} : { output: keptOutput, outputSha256: createHash('sha256').update(output).digest('hex') }),
|
|
79
|
+
outputBytes, omittedOutputBytes, artifacts, omittedArtifacts, partial, verification: 'unknown' });
|
|
80
|
+
return { handle, content, partial, isError: (exitCode !== null && exitCode !== 0) || status === 'failed'
|
|
81
|
+
|| (observation.kind === 'action' && observation.isError === true),
|
|
82
|
+
source: { origin: 'provider_reported', originToolCallId: observation.id,
|
|
83
|
+
native: { ...scope, status, exitCode, ...(durationMs === undefined ? {} : { durationMs }) },
|
|
84
|
+
...(observation.kind === 'command' && observation.cwd !== undefined ? { cwd: observation.cwd } : {}),
|
|
85
|
+
...(artifacts.length ? { artifact: artifacts[0] } : {}) } };
|
|
86
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type ExecutionSettings } from '../../config/execution.js';
|
|
2
|
+
import type { ManagedCommandObservation } from './command_jobs.js';
|
|
2
3
|
/** Group failures by cause rather than command spelling, paths, or changing IDs. */
|
|
3
4
|
export declare function normalizeFailure(content: string): string;
|
|
4
5
|
/** One budget per run; a new, substantive successful observation resets it. */
|
|
@@ -6,4 +7,5 @@ export declare function createRecoveryGuard(settings: ExecutionSettings): (resul
|
|
|
6
7
|
name: string;
|
|
7
8
|
content: string;
|
|
8
9
|
isError: boolean;
|
|
10
|
+
managedCommand?: ManagedCommandObservation;
|
|
9
11
|
}[]) => "continue" | "recover" | "stop";
|