@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,43 @@
|
|
|
1
|
+
export { SimulationInputError, fail, actors, inputActorId, sessionDocuments, validateDocumentWrite } from './session_documents.js';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import type { SimulationDynamicMechanicDefinitionV1, SimulationDynamicStateV1, SimulationJsonObjectV1, SimulationSessionSnapshotV1, SimulationTransitionBatchV1 } from '../plugin/simulation_contract.js';
|
|
4
|
+
import type { SimulationPrivateInputTextV1, ActorInterventionContext, SimulationInputBatchV1, SimulationInputJournalV1, SimulationInterventionResolutionV1 } from '../plugin/simulation_interventions.js';
|
|
5
|
+
export declare const requestSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
6
|
+
inputId: z.ZodString;
|
|
7
|
+
kind: z.ZodLiteral<"message">;
|
|
8
|
+
recipientActorIds: z.ZodArray<z.ZodString>;
|
|
9
|
+
body: z.ZodString;
|
|
10
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
11
|
+
inputId: z.ZodString;
|
|
12
|
+
kind: z.ZodLiteral<"document-edit">;
|
|
13
|
+
documentId: z.ZodString;
|
|
14
|
+
expectedVersion: z.ZodNumber;
|
|
15
|
+
body: z.ZodString;
|
|
16
|
+
}, z.core.$strict>], "kind">;
|
|
17
|
+
export declare function parseInputJournal(value: unknown): SimulationInputJournalV1;
|
|
18
|
+
/** Validate cross-record references before a restored session can expose any projection. */
|
|
19
|
+
export declare function validateSessionInputSnapshot(snapshot: SimulationSessionSnapshotV1): void;
|
|
20
|
+
export declare function emptyJournal(): SimulationInputJournalV1;
|
|
21
|
+
export declare function inputDigest(value: unknown): string;
|
|
22
|
+
export declare function worldDigest(snapshot: SimulationSessionSnapshotV1): string;
|
|
23
|
+
export declare function batchDigest(snapshot: SimulationSessionSnapshotV1, batch: Omit<SimulationInputBatchV1, 'digest'>): string;
|
|
24
|
+
export declare function checkedCheckpoint(value: SimulationJsonObjectV1): SimulationJsonObjectV1;
|
|
25
|
+
export declare function assertSealedReadSet(snapshot: SimulationSessionSnapshotV1, digest: string): SimulationInputBatchV1;
|
|
26
|
+
export declare function actorInterventionContext(snapshot: SimulationSessionSnapshotV1, actorId: string): ActorInterventionContext | null;
|
|
27
|
+
export declare function validateInputResolutions(journal: SimulationInputJournalV1, next: SimulationDynamicStateV1 | null, digest: string, values: readonly SimulationInterventionResolutionV1[], previous?: SimulationDynamicStateV1 | null): void;
|
|
28
|
+
export declare function validateInputTransition(snapshot: SimulationSessionSnapshotV1, batch: SimulationTransitionBatchV1): void;
|
|
29
|
+
export declare function interventionResolutionSchema(context: ActorInterventionContext, updateSchema: Record<string, unknown>, goalIds: readonly string[], causeIds: readonly string[], agencyVersion?: 'emergent-v1'): Record<string, unknown>;
|
|
30
|
+
export declare function interventionPrivacyCorpus(snapshot: SimulationSessionSnapshotV1): SimulationPrivateInputTextV1[];
|
|
31
|
+
/** Recover only a complete canonical match already present in authored public text. */
|
|
32
|
+
export declare function literalInterventionPrivacyPhrase(texts: readonly string[], phrase: string): string | undefined;
|
|
33
|
+
export declare function assertInterventionPrivacy(value: unknown, contexts: readonly ActorInterventionContext[], permittedActorId?: string, baseline?: unknown, retained?: readonly SimulationPrivateInputTextV1[], onMatch?: (phrase: string) => void): void;
|
|
34
|
+
/** Diagnostic candidates come only from the exact recipient input, never the private world corpus. */
|
|
35
|
+
export declare function collectActorInputPrivacyPhrases(value: unknown, actorInput: string, permittedActorId: string | undefined, baseline: unknown): {
|
|
36
|
+
complete: boolean;
|
|
37
|
+
phrases: string[];
|
|
38
|
+
};
|
|
39
|
+
export declare function checkpointInputJournal(checkpoint: SimulationJsonObjectV1): SimulationInputJournalV1 | undefined;
|
|
40
|
+
/** Authorize exact declared key/value bindings only when the owning object is world-visible. */
|
|
41
|
+
export declare function publicInterventionEnumBindings(world: SimulationDynamicStateV1['world'], mechanics: readonly SimulationDynamicMechanicDefinitionV1[]): string[];
|
|
42
|
+
/** Exact authored reference slots for world-public objects; never a shared word vocabulary. */
|
|
43
|
+
export declare function publicInterventionReferenceBindings(world: SimulationDynamicStateV1['world'], mechanics: readonly SimulationDynamicMechanicDefinitionV1[]): string[];
|
|
@@ -0,0 +1,364 @@
|
|
|
1
|
+
import { fail, actors, sessionDocuments, validateSessionDocuments } from './session_documents.js';
|
|
2
|
+
export { SimulationInputError, fail, actors, inputActorId, sessionDocuments, validateDocumentWrite } from './session_documents.js';
|
|
3
|
+
import { createHash } from 'node:crypto';
|
|
4
|
+
import { isDeepStrictEqual } from 'node:util';
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
import { agentSchema } from './toolkit/dynamic_state.js';
|
|
7
|
+
import { hasMaterialInterventionChange } from './intervention_material.js';
|
|
8
|
+
import { dynamicBeliefEvidenceHistory, dynamicHistory } from './dynamic_history.js';
|
|
9
|
+
const id = z.string().min(1).max(200);
|
|
10
|
+
const key = z.string().min(8).max(200).regex(/^[A-Za-z0-9_-]+$/);
|
|
11
|
+
const revision = z.number().int().nonnegative();
|
|
12
|
+
const hashSchema = z.string().regex(/^[a-f0-9]{64}$/);
|
|
13
|
+
const documentReference = z.object({ documentId: id, versionId: id, version: z.number().int().positive() }).strict();
|
|
14
|
+
export const requestSchema = z.discriminatedUnion('kind', [
|
|
15
|
+
z.object({ inputId: key, kind: z.literal('message'), recipientActorIds: z.array(id).min(1).max(4), body: z.string().min(1) }).strict(),
|
|
16
|
+
z.object({ inputId: key, kind: z.literal('document-edit'), documentId: id, expectedVersion: z.number().int().positive(), body: z.string() }).strict(),
|
|
17
|
+
]);
|
|
18
|
+
const resolutionSchema = z.object({ inputId: key, actorId: id, revision, disposition: z.enum(['acted', 'refused', 'ignored', 'deferred']), reason: z.string().trim().min(1).max(400),
|
|
19
|
+
causeIds: z.array(id).min(1).max(16), change: z.object({ kind: z.enum(['intent', 'belief', 'relationship']), recordId: id }).strict().nullable(),
|
|
20
|
+
}).strict();
|
|
21
|
+
const journalSchema = z.object({ schemaVersion: z.literal(1),
|
|
22
|
+
materialFromRevision: z.number().int().positive().optional(),
|
|
23
|
+
inputs: z.array(z.object({ inputId: key, senderActorId: id, recipientActorIds: z.array(id).min(1).max(16), acceptedSequence: z.number().int().positive(), eligibleRevision: revision, fingerprint: hashSchema,
|
|
24
|
+
payload: z.discriminatedUnion('kind', [z.object({ kind: z.literal('message'), body: z.string() }).strict(), documentReference.extend({ kind: z.literal('document-edit') }).strict()]),
|
|
25
|
+
}).strict()).max(256),
|
|
26
|
+
acknowledgements: z.array(z.object({ inputId: key, recipientActorIds: z.array(id), recipientNames: z.array(z.string()), eligibleRevision: revision, acceptedSequence: z.number().int().positive(), document: documentReference.optional() }).strict()).max(256),
|
|
27
|
+
batches: z.array(z.object({ resolutionContract: z.object({ version: z.literal(2), actorsBefore: z.array(agentSchema).max(4) }).strict().optional(), revision, basedOnRevision: revision, documentVersionIds: z.array(id).max(512), inputIds: z.array(key).max(8), worldDigest: hashSchema, digest: hashSchema }).strict()).max(257),
|
|
28
|
+
resolutions: z.array(resolutionSchema).max(1024),
|
|
29
|
+
}).strict();
|
|
30
|
+
export function parseInputJournal(value) {
|
|
31
|
+
const parsed = journalSchema.safeParse(value);
|
|
32
|
+
if (!parsed.success)
|
|
33
|
+
return fail('input_state_invalid', 'Session input state is invalid');
|
|
34
|
+
const j = parsed.data;
|
|
35
|
+
if (new Set(j.inputs.map(input => input.inputId)).size !== j.inputs.length || j.inputs.some((input, index) => input.acceptedSequence !== index + 1)
|
|
36
|
+
|| j.acknowledgements.length !== j.inputs.length || j.acknowledgements.some((ack, index) => ack.inputId !== j.inputs[index].inputId || ack.eligibleRevision !== j.inputs[index].eligibleRevision
|
|
37
|
+
|| ack.acceptedSequence !== j.inputs[index].acceptedSequence || !isDeepStrictEqual(ack.recipientActorIds, j.inputs[index].recipientActorIds))
|
|
38
|
+
|| new Set(j.batches.map(batch => batch.revision)).size !== j.batches.length
|
|
39
|
+
|| j.batches.some(batch => Boolean(batch.resolutionContract) !== (j.materialFromRevision !== undefined && batch.revision >= j.materialFromRevision))
|
|
40
|
+
|| j.batches.some(batch => batch.revision !== batch.basedOnRevision + 1 || batch.inputIds.some(inputId => !j.inputs.some(input => input.inputId === inputId && input.eligibleRevision === batch.revision)))
|
|
41
|
+
|| new Set(j.resolutions.map(item => `${item.inputId}:${item.actorId}`)).size !== j.resolutions.length) {
|
|
42
|
+
return fail('input_state_invalid', 'Session input lineage is invalid');
|
|
43
|
+
}
|
|
44
|
+
return j;
|
|
45
|
+
}
|
|
46
|
+
/** Validate cross-record references before a restored session can expose any projection. */
|
|
47
|
+
export function validateSessionInputSnapshot(snapshot) {
|
|
48
|
+
const invalid = () => fail('input_state_invalid', 'Session input references are invalid');
|
|
49
|
+
const roster = actors(snapshot);
|
|
50
|
+
const actorIds = new Set(roster.map(actor => actor.actorId));
|
|
51
|
+
const documents = sessionDocuments(snapshot);
|
|
52
|
+
validateSessionDocuments(snapshot);
|
|
53
|
+
const journal = snapshot.inputJournal;
|
|
54
|
+
if (!journal)
|
|
55
|
+
return;
|
|
56
|
+
for (const [index, input] of journal.inputs.entries()) {
|
|
57
|
+
const ack = journal.acknowledgements[index];
|
|
58
|
+
if (!roster.some(actor => actor.actorId === input.senderActorId && actor.humanControlled)
|
|
59
|
+
|| new Set(input.recipientActorIds).size !== input.recipientActorIds.length
|
|
60
|
+
|| input.recipientActorIds.some(id => !actorIds.has(id))
|
|
61
|
+
|| !input.recipientActorIds.some(id => roster.some(actor => actor.actorId === id && !actor.humanControlled))
|
|
62
|
+
|| !isDeepStrictEqual(ack.recipientNames, input.recipientActorIds.map(id => roster.find(actor => actor.actorId === id)?.name)))
|
|
63
|
+
invalid();
|
|
64
|
+
let request;
|
|
65
|
+
if (input.payload.kind === 'message') {
|
|
66
|
+
if (ack.document !== undefined || Buffer.byteLength(input.payload.body, 'utf8') > 4000 || input.payload.body.length === 0)
|
|
67
|
+
invalid();
|
|
68
|
+
request = { inputId: input.inputId, kind: 'message', recipientActorIds: input.recipientActorIds, body: input.payload.body };
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
const payload = input.payload;
|
|
72
|
+
const doc = documents.find(doc => doc.versionId === payload.versionId);
|
|
73
|
+
const reference = { documentId: payload.documentId, versionId: payload.versionId, version: payload.version };
|
|
74
|
+
if (!doc || doc.documentId !== payload.documentId || doc.version !== payload.version || doc.version < 2
|
|
75
|
+
|| doc.ownerActorId !== input.senderActorId || !isDeepStrictEqual(doc.recipientActorIds, input.recipientActorIds)
|
|
76
|
+
|| !isDeepStrictEqual(ack.document, reference))
|
|
77
|
+
invalid();
|
|
78
|
+
request = { inputId: input.inputId, kind: 'document-edit', documentId: payload.documentId, expectedVersion: payload.version - 1, body: doc.body };
|
|
79
|
+
}
|
|
80
|
+
if (inputDigest({ senderActorId: input.senderActorId, request }) !== input.fingerprint
|
|
81
|
+
|| input.eligibleRevision > snapshot.revision + 2 || input.eligibleRevision < 1)
|
|
82
|
+
invalid();
|
|
83
|
+
}
|
|
84
|
+
for (const batch of journal.batches) {
|
|
85
|
+
if (new Set(batch.documentVersionIds).size !== batch.documentVersionIds.length || new Set(batch.inputIds).size !== batch.inputIds.length || batch.basedOnRevision > snapshot.revision
|
|
86
|
+
|| !isDeepStrictEqual(batch.inputIds, journal.inputs.filter(input => input.eligibleRevision === batch.revision).map(input => input.inputId)))
|
|
87
|
+
invalid();
|
|
88
|
+
if (journal.inputs.some(input => batch.inputIds.includes(input.inputId) && input.payload.kind === 'document-edit' && !batch.documentVersionIds.includes(input.payload.versionId)))
|
|
89
|
+
invalid();
|
|
90
|
+
if (batch.resolutionContract) {
|
|
91
|
+
const expected = [...new Set(journal.inputs.filter(input => batch.inputIds.includes(input.inputId)).flatMap(input => input.recipientActorIds))].filter(id => snapshot.dynamicState?.agents.some(actor => actor.actorId === id && !actor.humanControlled)).sort();
|
|
92
|
+
if (!isDeepStrictEqual(batch.resolutionContract.actorsBefore.map(actor => actor.actorId).sort(), expected))
|
|
93
|
+
invalid();
|
|
94
|
+
if (batch.revision === snapshot.revision + 1 && batch.resolutionContract.actorsBefore.some(before => !isDeepStrictEqual(before, snapshot.dynamicState?.agents.find(actor => actor.actorId === before.actorId))))
|
|
95
|
+
invalid();
|
|
96
|
+
}
|
|
97
|
+
const { digest, ...data } = batch;
|
|
98
|
+
if (batchDigest(snapshot, data) !== digest)
|
|
99
|
+
invalid();
|
|
100
|
+
if (batch.revision === snapshot.revision + 1 && worldDigest(snapshot) !== batch.worldDigest)
|
|
101
|
+
invalid();
|
|
102
|
+
}
|
|
103
|
+
for (const resolution of journal.resolutions) {
|
|
104
|
+
const input = journal.inputs.find(input => input.inputId === resolution.inputId);
|
|
105
|
+
if (!input || !input.recipientActorIds.includes(resolution.actorId)
|
|
106
|
+
|| !roster.some(actor => actor.actorId === resolution.actorId && !actor.humanControlled)
|
|
107
|
+
|| resolution.revision !== input.eligibleRevision || resolution.revision > snapshot.revision
|
|
108
|
+
|| !resolution.causeIds.includes(resolution.inputId)
|
|
109
|
+
|| !journal.batches.some(batch => batch.revision === resolution.revision && batch.inputIds.includes(resolution.inputId)))
|
|
110
|
+
invalid();
|
|
111
|
+
const entry = snapshot.dynamicState ? dynamicHistory(snapshot.dynamicState).find(entry => entry.revision === resolution.revision) : undefined;
|
|
112
|
+
const update = entry?.gmProposal.agentUpdates.find(update => update.actorId === resolution.actorId);
|
|
113
|
+
const validCauses = new Set([resolution.inputId, ...(update?.sourceActionIds ?? []), ...(update?.sourceAdjudicationProposalIds ?? [])]);
|
|
114
|
+
const emergent = snapshot.dynamicState?.agencyVersion === 'emergent-v1';
|
|
115
|
+
const change = resolution.change;
|
|
116
|
+
if ((!emergent && (change === null || !['acted', 'refused'].includes(resolution.disposition)))
|
|
117
|
+
|| (change === null && (resolution.disposition === 'acted' || !isDeepStrictEqual(resolution.causeIds, [resolution.inputId])))
|
|
118
|
+
|| (change !== null && ['ignored', 'deferred'].includes(resolution.disposition)))
|
|
119
|
+
invalid();
|
|
120
|
+
const recordExists = change === null ? emergent && resolution.disposition !== 'acted'
|
|
121
|
+
: change.kind === 'intent' ? update?.nextIntent?.goalId === change.recordId || (emergent && change.recordId === resolution.actorId && update !== undefined)
|
|
122
|
+
: change.kind === 'belief' ? update?.beliefsToAppend.some(item => item.id === change.recordId) || update?.beliefUpdates.some(item => item.beliefId === change.recordId)
|
|
123
|
+
: update?.relationshipDeltas.some(item => item.targetActorId === change.recordId);
|
|
124
|
+
if ((change !== null && !update) || !recordExists || resolution.causeIds.some(id => !validCauses.has(id)))
|
|
125
|
+
invalid();
|
|
126
|
+
const contract = journal.batches.find(batch => batch.revision === resolution.revision)?.resolutionContract;
|
|
127
|
+
if (contract) {
|
|
128
|
+
const before = contract.actorsBefore.find(actor => actor.actorId === resolution.actorId);
|
|
129
|
+
if (!before || !entry || !hasMaterialInterventionChange(before, entry, resolution, undefined, snapshot.dynamicState?.agencyVersion, resolution.change?.kind === 'belief' && snapshot.dynamicState ? dynamicBeliefEvidenceHistory({ ...snapshot.dynamicState, revision: resolution.revision - 1 })?.[resolution.actorId] : undefined))
|
|
130
|
+
invalid();
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
for (const input of journal.inputs.filter(input => input.eligibleRevision <= snapshot.revision)) {
|
|
134
|
+
for (const actorId of input.recipientActorIds.filter(id => roster.some(actor => actor.actorId === id && !actor.humanControlled))) {
|
|
135
|
+
if (!journal.resolutions.some(result => result.inputId === input.inputId && result.actorId === actorId))
|
|
136
|
+
invalid();
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
export function emptyJournal() { return { schemaVersion: 1, inputs: [], acknowledgements: [], batches: [], resolutions: [] }; }
|
|
141
|
+
export function inputDigest(value) {
|
|
142
|
+
const canonical = (item) => Array.isArray(item) ? item.map(canonical) : item !== null && typeof item === 'object'
|
|
143
|
+
? Object.fromEntries(Object.entries(item).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([k, v]) => [k, canonical(v)])) : item;
|
|
144
|
+
return createHash('sha256').update(JSON.stringify(canonical(value))).digest('hex');
|
|
145
|
+
}
|
|
146
|
+
export function worldDigest(snapshot) {
|
|
147
|
+
return inputDigest({ ref: snapshot.ref, revision: snapshot.revision, state: snapshot.dynamicState ?? null, world: snapshot.world, actors: snapshot.actors });
|
|
148
|
+
}
|
|
149
|
+
export function batchDigest(snapshot, batch) {
|
|
150
|
+
const inputs = batch.inputIds.map(id => snapshot.inputJournal?.inputs.find(input => input.inputId === id) ?? fail('input_state_invalid', 'Sealed input is missing'));
|
|
151
|
+
const documents = sessionDocuments(snapshot);
|
|
152
|
+
return inputDigest({ ...batch, inputs, versions: batch.documentVersionIds.map(id => documents.find(doc => doc.versionId === id) ?? fail('input_state_invalid', 'Sealed document version is missing')) });
|
|
153
|
+
}
|
|
154
|
+
export function checkedCheckpoint(value) {
|
|
155
|
+
if (Buffer.byteLength(JSON.stringify(value), 'utf8') > 4194304)
|
|
156
|
+
fail('input_storage_exhausted', 'This run has reached its durable checkpoint storage limit; retrying cannot free storage');
|
|
157
|
+
return value;
|
|
158
|
+
}
|
|
159
|
+
export function assertSealedReadSet(snapshot, digest) {
|
|
160
|
+
const batch = snapshot.inputJournal?.batches.find(batch => batch.revision === snapshot.revision + 1);
|
|
161
|
+
if (!batch || batch.digest !== digest || batch.worldDigest !== worldDigest(snapshot))
|
|
162
|
+
return fail('input_batch_conflict', 'Sealed input world or rules changed');
|
|
163
|
+
const { digest: _digest, ...data } = batch;
|
|
164
|
+
if (batchDigest(snapshot, data) !== digest)
|
|
165
|
+
return fail('input_batch_conflict', 'Sealed input or document version changed');
|
|
166
|
+
return batch;
|
|
167
|
+
}
|
|
168
|
+
export function actorInterventionContext(snapshot, actorId) {
|
|
169
|
+
const batch = snapshot.inputJournal?.batches.find(batch => batch.revision === snapshot.revision + 1);
|
|
170
|
+
if (!batch)
|
|
171
|
+
return null;
|
|
172
|
+
assertSealedReadSet(snapshot, batch.digest);
|
|
173
|
+
const inputs = snapshot.inputJournal.inputs.filter(input => batch.inputIds.includes(input.inputId) && input.recipientActorIds.includes(actorId));
|
|
174
|
+
const docs = sessionDocuments(snapshot).filter(doc => doc.recipientActorIds.includes(actorId) && batch.documentVersionIds.includes(doc.versionId));
|
|
175
|
+
return { revision: batch.revision, batchId: batch.digest, actorId, addressedInputs: inputs, documents: docs, requiredResolutionInputIds: inputs.map(input => input.inputId) };
|
|
176
|
+
}
|
|
177
|
+
export function validateInputResolutions(journal, next, digest, values, previous) {
|
|
178
|
+
const resolutions = z.array(resolutionSchema).parse(values);
|
|
179
|
+
const batch = journal.batches.find(batch => batch.digest === digest);
|
|
180
|
+
if (!batch || !next || !previous || next.revision !== batch.revision)
|
|
181
|
+
fail('input_resolution_invalid', 'Input resolution revision is invalid');
|
|
182
|
+
const required = journal.inputs.filter(input => batch.inputIds.includes(input.inputId)).flatMap(input => input.recipientActorIds.filter(id => previous.agents.some(actor => actor.actorId === id && !actor.humanControlled)).map(actorId => ({ inputId: input.inputId, actorId })));
|
|
183
|
+
if (resolutions.length !== required.length || new Set(resolutions.map(item => `${item.inputId}:${item.actorId}`)).size !== required.length)
|
|
184
|
+
fail('input_resolution_invalid', 'Every addressed character needs exactly one input resolution');
|
|
185
|
+
for (const result of resolutions) {
|
|
186
|
+
if (!required.some(item => item.inputId === result.inputId && item.actorId === result.actorId) || result.revision !== batch.revision
|
|
187
|
+
|| journal.resolutions.some(item => item.inputId === result.inputId && item.actorId === result.actorId))
|
|
188
|
+
fail('input_resolution_invalid', 'Input resolution is not addressed to this character');
|
|
189
|
+
const before = previous.agents.find(actor => actor.actorId === result.actorId);
|
|
190
|
+
const after = next.agents.find(actor => actor.actorId === result.actorId);
|
|
191
|
+
if (batch.resolutionContract && !isDeepStrictEqual(before, batch.resolutionContract.actorsBefore.find(actor => actor.actorId === result.actorId)))
|
|
192
|
+
fail('input_resolution_invalid', 'Sealed actor witness changed');
|
|
193
|
+
if (!after || !hasMaterialInterventionChange(before, next.history.at(-1), result, after, previous.agencyVersion, result.change?.kind === 'belief' ? dynamicBeliefEvidenceHistory(previous)?.[result.actorId] : undefined))
|
|
194
|
+
fail('input_resolution_invalid', 'Input needs a causally linked accepted change; an echo is insufficient');
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
export function validateInputTransition(snapshot, batch) {
|
|
198
|
+
const journal = snapshot.inputJournal;
|
|
199
|
+
const sealed = journal?.batches.find(item => item.revision === snapshot.revision + 1);
|
|
200
|
+
const resolutions = batch.operations.filter(op => op.operation === 'session-inputs.resolve');
|
|
201
|
+
if (!sealed) {
|
|
202
|
+
if (resolutions.length)
|
|
203
|
+
fail('input_batch_conflict', 'No input batch is sealed');
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
assertSealedReadSet(snapshot, sealed.digest);
|
|
207
|
+
if (resolutions.length !== 1 || resolutions[0].sealedDigest !== sealed.digest)
|
|
208
|
+
fail('input_resolution_invalid', 'Transition must resolve its exact sealed input batch');
|
|
209
|
+
const next = batch.operations.find(op => op.operation === 'dynamic-state.commit');
|
|
210
|
+
if (!next)
|
|
211
|
+
fail('input_resolution_invalid', 'Inputs require a dynamic state transition');
|
|
212
|
+
validateInputResolutions(journal, next.state, sealed.digest, resolutions[0].resolutions, snapshot.dynamicState);
|
|
213
|
+
if (next.state.status !== 'active' && journal.inputs.some(input => input.eligibleRevision > sealed.revision))
|
|
214
|
+
fail('input_pending_ending', 'An ending cannot strand accepted input');
|
|
215
|
+
}
|
|
216
|
+
export function interventionResolutionSchema(context, updateSchema, goalIds, causeIds, agencyVersion) {
|
|
217
|
+
const properties = updateSchema.properties;
|
|
218
|
+
const relationshipItems = properties.relationshipDeltas.items;
|
|
219
|
+
const relationshipIds = relationshipItems.anyOf?.map(branch => branch.properties.targetActorId.const)
|
|
220
|
+
?? relationshipItems.properties?.targetActorId.enum ?? [];
|
|
221
|
+
const variants = [
|
|
222
|
+
['intent', [...(agencyVersion === 'emergent-v1' ? [context.actorId] : []), ...goalIds, ...properties.goalsToAppend.items.properties.id.enum]],
|
|
223
|
+
['belief', [...(properties.beliefUpdates.items.properties.beliefId.enum ?? []), ...(properties.beliefsToAppend.items.properties.id.enum ?? [])]],
|
|
224
|
+
['relationship', relationshipIds],
|
|
225
|
+
];
|
|
226
|
+
const schema = { type: 'array', minItems: context.requiredResolutionInputIds.length, maxItems: context.requiredResolutionInputIds.length, items: {
|
|
227
|
+
type: 'object', additionalProperties: false, required: ['inputId', 'actorId', 'revision', 'disposition', 'reason', 'causeIds', 'change'], properties: {
|
|
228
|
+
inputId: { enum: context.requiredResolutionInputIds }, actorId: { const: context.actorId }, revision: { const: context.revision },
|
|
229
|
+
disposition: { enum: ['acted', 'refused'] }, reason: { type: 'string', minLength: 1, maxLength: 400 },
|
|
230
|
+
causeIds: { type: 'array', minItems: 1 + causeIds.length, maxItems: 1 + causeIds.length, uniqueItems: true, items: { enum: [...context.requiredResolutionInputIds, ...causeIds] } },
|
|
231
|
+
change: { anyOf: variants.filter(([, ids]) => ids.length > 0).map(([kind, ids]) => ({ type: 'object', additionalProperties: false, required: ['kind', 'recordId'], properties: { kind: { const: kind }, recordId: { enum: ids } } })) },
|
|
232
|
+
},
|
|
233
|
+
} };
|
|
234
|
+
if (agencyVersion !== 'emergent-v1')
|
|
235
|
+
return schema;
|
|
236
|
+
const item = schema.items;
|
|
237
|
+
return { ...schema,
|
|
238
|
+
description: 'Record each addressed input as acted, refused, ignored, or deferred. Acted names an actual change. Refusal, ignoring, and deferral may record change:null with only that inputId as cause. This decision does not invent speech or require a mental or physical change.',
|
|
239
|
+
items: { anyOf: [
|
|
240
|
+
{ ...item, properties: { ...item.properties, disposition: { enum: ['acted', 'refused'] } } },
|
|
241
|
+
{ ...item, properties: { ...item.properties, disposition: { enum: ['refused', 'ignored', 'deferred'] },
|
|
242
|
+
causeIds: { type: 'array', minItems: 1, maxItems: 1, items: { enum: context.requiredResolutionInputIds } },
|
|
243
|
+
change: { type: 'null' },
|
|
244
|
+
} },
|
|
245
|
+
] },
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
export function interventionPrivacyCorpus(snapshot) {
|
|
249
|
+
return [
|
|
250
|
+
...(snapshot.inputJournal?.inputs ?? []).flatMap(input => input.payload.kind === 'message' ? [{ recipientActorIds: input.recipientActorIds, text: input.payload.body }] : []),
|
|
251
|
+
...sessionDocuments(snapshot).flatMap(doc => [doc.body, doc.label].map(text => ({ recipientActorIds: doc.recipientActorIds, text }))),
|
|
252
|
+
...(snapshot.inputJournal?.resolutions ?? []).map(resolution => ({ recipientActorIds: [resolution.actorId], text: resolution.reason })),
|
|
253
|
+
];
|
|
254
|
+
}
|
|
255
|
+
const normalizePrivacyText = (text) => text.toLowerCase().replace(/[^\p{L}\p{N}]+/gu, ' ').trim();
|
|
256
|
+
const privacyContainsPhrase = (text, phrase) => ` ${text} `.includes(` ${phrase} `);
|
|
257
|
+
const privacyStrings = (value) => typeof value === 'string' ? [value] : Array.isArray(value) ? value.flatMap(privacyStrings)
|
|
258
|
+
: value !== null && typeof value === 'object' ? Object.values(value).flatMap(privacyStrings) : [];
|
|
259
|
+
function* interventionPrivacyMatches(value, contexts, permittedActorId, baseline = {}, retained = []) {
|
|
260
|
+
const text = normalizePrivacyText(JSON.stringify(value, (_key, item) => typeof item === 'string' ? normalizePrivacyText(item) : item));
|
|
261
|
+
const actorPhrases = permittedActorId === undefined ? [] : [
|
|
262
|
+
...contexts.flatMap(context => [
|
|
263
|
+
...context.addressedInputs.filter(input => input.recipientActorIds.includes(permittedActorId)).flatMap(input => input.payload.kind === 'message' ? [input.payload.body] : []),
|
|
264
|
+
...context.documents.filter(doc => doc.recipientActorIds.includes(permittedActorId)).flatMap(doc => [doc.body, doc.label]),
|
|
265
|
+
]),
|
|
266
|
+
...retained.filter(item => item.recipientActorIds.includes(permittedActorId)).map(item => item.text),
|
|
267
|
+
];
|
|
268
|
+
const permittedPhrases = [...privacyStrings(baseline), ...actorPhrases].map(normalizePrivacyText);
|
|
269
|
+
const privateBodies = contexts.filter(context => context.actorId !== permittedActorId).flatMap(context => [
|
|
270
|
+
...context.addressedInputs.filter(input => permittedActorId === undefined || !input.recipientActorIds.includes(permittedActorId)).flatMap(input => input.payload.kind === 'message' ? [input.payload.body] : []),
|
|
271
|
+
...context.documents.filter(doc => permittedActorId === undefined || !doc.recipientActorIds.includes(permittedActorId)).flatMap(doc => [doc.body, doc.label]),
|
|
272
|
+
]);
|
|
273
|
+
privateBodies.push(...retained.filter(item => permittedActorId === undefined || !item.recipientActorIds.includes(permittedActorId)).map(item => item.text));
|
|
274
|
+
for (const body of privateBodies) {
|
|
275
|
+
const normalized = normalizePrivacyText(body);
|
|
276
|
+
const words = normalized.split(' ');
|
|
277
|
+
const stopWords = new Set(['with', 'from', 'that', 'this', 'then', 'your', 'their', 'have', 'make', 'over', 'next', 'more', 'before', 'after', 'will', 'must', 'only', 'into', 'each']);
|
|
278
|
+
const phrases = [normalized, ...words.slice(0, -2).map((_word, index) => words.slice(index, index + 3)).filter(tokens => tokens.every(token => token.length >= 4 && !stopWords.has(token))).map(tokens => tokens.join(' '))];
|
|
279
|
+
for (const phrase of phrases)
|
|
280
|
+
if (phrase.length >= 8 && !permittedPhrases.some(text => privacyContainsPhrase(text, phrase)) && privacyContainsPhrase(text, phrase))
|
|
281
|
+
yield phrase;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
/** Recover only a complete canonical match already present in authored public text. */
|
|
285
|
+
export function literalInterventionPrivacyPhrase(texts, phrase) {
|
|
286
|
+
const normalizedPhrase = normalizePrivacyText(phrase);
|
|
287
|
+
for (const text of texts) {
|
|
288
|
+
if (!privacyContainsPhrase(normalizePrivacyText(text), normalizedPhrase))
|
|
289
|
+
continue;
|
|
290
|
+
const offsets = [];
|
|
291
|
+
let position = 0;
|
|
292
|
+
for (const character of text) {
|
|
293
|
+
const end = position + character.length;
|
|
294
|
+
for (let index = 0; index < character.toLowerCase().length; index++)
|
|
295
|
+
offsets.push({ start: position, end });
|
|
296
|
+
position = end;
|
|
297
|
+
}
|
|
298
|
+
const words = [...text.toLowerCase().matchAll(/[\p{L}\p{N}]+/gu)];
|
|
299
|
+
for (let start = 0; start < words.length; start++) {
|
|
300
|
+
for (let end = start; end < words.length; end++) {
|
|
301
|
+
const last = words[end];
|
|
302
|
+
const literal = text.slice(offsets[words[start].index].start, offsets[last.index + last[0].length - 1].end);
|
|
303
|
+
const normalized = normalizePrivacyText(literal);
|
|
304
|
+
if (normalized === normalizedPhrase)
|
|
305
|
+
return literal;
|
|
306
|
+
if (normalized.length > normalizedPhrase.length)
|
|
307
|
+
break;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
return undefined;
|
|
312
|
+
}
|
|
313
|
+
export function assertInterventionPrivacy(value, contexts, permittedActorId, baseline = {}, retained = [], onMatch) {
|
|
314
|
+
const matches = interventionPrivacyMatches(value, contexts, permittedActorId, baseline, retained);
|
|
315
|
+
const first = matches.next();
|
|
316
|
+
if (first.done)
|
|
317
|
+
return;
|
|
318
|
+
if (onMatch) {
|
|
319
|
+
onMatch(first.value);
|
|
320
|
+
for (const phrase of matches)
|
|
321
|
+
onMatch(phrase);
|
|
322
|
+
}
|
|
323
|
+
fail('input_privacy_violation', 'Private intervention text reached an unauthorized surface');
|
|
324
|
+
}
|
|
325
|
+
/** Diagnostic candidates come only from the exact recipient input, never the private world corpus. */
|
|
326
|
+
export function collectActorInputPrivacyPhrases(value, actorInput, permittedActorId, baseline) {
|
|
327
|
+
const packet = JSON.parse(actorInput);
|
|
328
|
+
const context = packet.intervention;
|
|
329
|
+
const corpus = context === undefined ? [] : [
|
|
330
|
+
...context.documents.flatMap(document => [document.body, document.label].map(text => ({ recipientActorIds: document.recipientActorIds, text }))),
|
|
331
|
+
...context.addressedInputs.flatMap(input => input.payload.kind === 'message' ? [{ recipientActorIds: input.recipientActorIds, text: input.payload.body }] : []),
|
|
332
|
+
];
|
|
333
|
+
if (corpus.length > 2_048)
|
|
334
|
+
return { complete: false, phrases: [] };
|
|
335
|
+
const phrases = new Set();
|
|
336
|
+
let examined = 0;
|
|
337
|
+
for (const phrase of interventionPrivacyMatches(value, [], permittedActorId, baseline, corpus)) {
|
|
338
|
+
if (++examined > 64)
|
|
339
|
+
return { complete: false, phrases: [] };
|
|
340
|
+
phrases.add(phrase);
|
|
341
|
+
if (phrases.size > 8)
|
|
342
|
+
return { complete: false, phrases: [] };
|
|
343
|
+
}
|
|
344
|
+
return { complete: true, phrases: [...phrases] };
|
|
345
|
+
}
|
|
346
|
+
export function checkpointInputJournal(checkpoint) {
|
|
347
|
+
const extensions = checkpoint.extensions;
|
|
348
|
+
const host = extensions?.['ztc.host'];
|
|
349
|
+
const data = host?.data;
|
|
350
|
+
return data?.inputJournal === undefined ? undefined : parseInputJournal(data.inputJournal);
|
|
351
|
+
}
|
|
352
|
+
/** Authorize exact declared key/value bindings only when the owning object is world-visible. */
|
|
353
|
+
export function publicInterventionEnumBindings(world, mechanics) {
|
|
354
|
+
const parameters = mechanics.flatMap(mechanic => [...mechanic.intentParameters, ...mechanic.resolutionParameters]);
|
|
355
|
+
return [...new Set(world.domainObjects.filter(object => object.visibility.scope === 'world').flatMap(object => parameters.flatMap(parameter => {
|
|
356
|
+
const value = object.data[parameter.id];
|
|
357
|
+
return parameter.kind === 'enum' && typeof value === 'string' && parameter.values.includes(value) ? [`${parameter.id} ${value}`] : [];
|
|
358
|
+
})))];
|
|
359
|
+
}
|
|
360
|
+
/** Exact authored reference slots for world-public objects; never a shared word vocabulary. */
|
|
361
|
+
export function publicInterventionReferenceBindings(world, mechanics) {
|
|
362
|
+
const parameters = mechanics.flatMap(mechanic => mechanic.intentParameters);
|
|
363
|
+
return [...new Set(world.domainObjects.filter(object => object.visibility.scope === 'world').flatMap(object => parameters.flatMap(parameter => parameter.kind === 'object-reference' && parameter.objectKinds.includes(object.kind) ? [`${parameter.id} ${object.id}`] : [])))];
|
|
364
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { SimulationJsonObjectV1, SimulationDynamicStateV1 } from '../plugin/simulation_contract.js';
|
|
2
|
+
import type { ActorInterventionContext, SimulationPrivateInputTextV1, SimulationInputRequestV1, SimulationAddressedInputV1, SimulationInputAcknowledgementV1, SimulationInputBatchV1, SimulationAuthorizedDocumentV1, SimulationInterventionResolutionV1, SimulationDetachedInputCommitV1 } from '../plugin/simulation_interventions.js';
|
|
3
|
+
export { getOriginalSessionTransition as getSessionTransition } from './plugin_host.js';
|
|
4
|
+
export { SimulationInputError, actorInterventionContext, checkpointInputJournal } from './session_input_validation.js';
|
|
5
|
+
/** Derives private validation context from a caller-owned sealed checkpoint. */
|
|
6
|
+
export declare function checkpointInterventionContext(checkpoint: SimulationJsonObjectV1): Promise<{
|
|
7
|
+
sessionId: string;
|
|
8
|
+
state: SimulationDynamicStateV1;
|
|
9
|
+
privateContext: {
|
|
10
|
+
interventions: ActorInterventionContext[];
|
|
11
|
+
interventionPrivacy: SimulationPrivateInputTextV1[];
|
|
12
|
+
};
|
|
13
|
+
}>;
|
|
14
|
+
export declare function prepareSessionInput(checkpoint: SimulationJsonObjectV1, senderActorId: string, value: SimulationInputRequestV1): Promise<{
|
|
15
|
+
checkpoint: SimulationJsonObjectV1;
|
|
16
|
+
acknowledgement: SimulationInputAcknowledgementV1;
|
|
17
|
+
replayed: boolean;
|
|
18
|
+
}>;
|
|
19
|
+
export declare function sealSessionInputs(checkpoint: SimulationJsonObjectV1): Promise<{
|
|
20
|
+
checkpoint: SimulationJsonObjectV1;
|
|
21
|
+
batch: SimulationInputBatchV1;
|
|
22
|
+
}>;
|
|
23
|
+
export declare function projectSessionInputs(checkpoint: SimulationJsonObjectV1, actorId: string, includeDocumentHistory?: boolean): Promise<{
|
|
24
|
+
inputs: SimulationAddressedInputV1[];
|
|
25
|
+
documents: SimulationAuthorizedDocumentV1[];
|
|
26
|
+
acknowledgements: SimulationInputAcknowledgementV1[];
|
|
27
|
+
resolutions: SimulationInterventionResolutionV1[];
|
|
28
|
+
}>;
|
|
29
|
+
export declare function commitSessionInputBatch(request: SimulationDetachedInputCommitV1): Promise<{
|
|
30
|
+
checkpoint: SimulationJsonObjectV1;
|
|
31
|
+
state: SimulationDynamicStateV1;
|
|
32
|
+
}>;
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { applyDetachedSessionTransition, detachedSessionCheckpoint, detachedSessionRecord, detachedSessionSnapshot } from './plugin_host.js';
|
|
2
|
+
import { actors, assertSealedReadSet, batchDigest, checkedCheckpoint, emptyJournal, fail, inputDigest, requestSchema, sessionDocuments, worldDigest, actorInterventionContext, interventionPrivacyCorpus } from './session_input_validation.js';
|
|
3
|
+
export { getOriginalSessionTransition as getSessionTransition } from './plugin_host.js';
|
|
4
|
+
export { SimulationInputError, actorInterventionContext, checkpointInputJournal } from './session_input_validation.js';
|
|
5
|
+
/** Derives private validation context from a caller-owned sealed checkpoint. */
|
|
6
|
+
export async function checkpointInterventionContext(checkpoint) {
|
|
7
|
+
const record = await detachedSessionRecord(checkpoint);
|
|
8
|
+
try {
|
|
9
|
+
const snapshot = detachedSessionSnapshot(record);
|
|
10
|
+
if (!snapshot.dynamicState)
|
|
11
|
+
return fail('input_invalid', 'Dynamic checkpoint state is missing');
|
|
12
|
+
const batch = snapshot.inputJournal?.batches.find(item => item.revision === snapshot.revision + 1);
|
|
13
|
+
if (!batch)
|
|
14
|
+
return fail('input_batch_conflict', 'The original input batch must be sealed');
|
|
15
|
+
assertSealedReadSet(snapshot, batch.digest);
|
|
16
|
+
return { sessionId: snapshot.ref.sessionId, state: snapshot.dynamicState,
|
|
17
|
+
privateContext: {
|
|
18
|
+
interventions: snapshot.dynamicState.agents.filter(actor => !actor.humanControlled).flatMap(actor => {
|
|
19
|
+
const context = actorInterventionContext(snapshot, actor.actorId);
|
|
20
|
+
return context ? [context] : [];
|
|
21
|
+
}),
|
|
22
|
+
interventionPrivacy: interventionPrivacyCorpus(snapshot),
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
finally {
|
|
27
|
+
record.state.close();
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
export async function prepareSessionInput(checkpoint, senderActorId, value) {
|
|
31
|
+
const record = await detachedSessionRecord(checkpoint);
|
|
32
|
+
try {
|
|
33
|
+
const snapshot = detachedSessionSnapshot(record);
|
|
34
|
+
const roster = actors(snapshot);
|
|
35
|
+
if (!roster.some(actor => actor.actorId === senderActorId && actor.humanControlled))
|
|
36
|
+
fail('sender_invalid', 'Only the authenticated player owner can submit input');
|
|
37
|
+
const parsed = requestSchema.safeParse(value);
|
|
38
|
+
if (!parsed.success)
|
|
39
|
+
return fail('input_invalid', 'Input request is invalid');
|
|
40
|
+
const request = parsed.data.kind === 'message' ? { ...parsed.data, recipientActorIds: [...parsed.data.recipientActorIds].sort() } : parsed.data;
|
|
41
|
+
const fingerprint = inputDigest({ senderActorId, request });
|
|
42
|
+
const journal = record.inputJournal ?? emptyJournal();
|
|
43
|
+
const prior = journal.inputs.find(input => input.inputId === request.inputId);
|
|
44
|
+
if (prior) {
|
|
45
|
+
if (prior.fingerprint !== fingerprint)
|
|
46
|
+
fail('idempotency_conflict', 'That input key was used for different input');
|
|
47
|
+
return { checkpoint, acknowledgement: structuredClone(journal.acknowledgements[journal.inputs.indexOf(prior)]), replayed: true };
|
|
48
|
+
}
|
|
49
|
+
if (record.dynamicState && record.dynamicState.status !== 'active')
|
|
50
|
+
fail('run_ended', 'This run cannot accept input');
|
|
51
|
+
if (Buffer.byteLength(JSON.stringify(request), 'utf8') > 16384 || Buffer.byteLength(request.body, 'utf8') > (request.kind === 'message' ? 4000 : 8192))
|
|
52
|
+
fail('body_too_large', 'Input exceeds its byte limit');
|
|
53
|
+
const docs = sessionDocuments(snapshot);
|
|
54
|
+
const document = request.kind === 'document-edit' ? docs.filter(doc => doc.documentId === request.documentId).at(-1) : undefined;
|
|
55
|
+
if (request.kind === 'document-edit') {
|
|
56
|
+
if (!document || !document.recipientActorIds.includes(senderActorId))
|
|
57
|
+
fail('document_not_found', 'Document was not found');
|
|
58
|
+
if (document.ownerActorId !== senderActorId)
|
|
59
|
+
fail('document_edit_denied', 'Only the document owner may edit');
|
|
60
|
+
if (document.version !== request.expectedVersion)
|
|
61
|
+
fail('document_version_conflict', 'Document version changed; keep your draft and reload the saved version');
|
|
62
|
+
}
|
|
63
|
+
const recipients = request.kind === 'message' ? [...request.recipientActorIds].sort() : [...document.recipientActorIds];
|
|
64
|
+
if (new Set(recipients).size !== recipients.length || recipients.some(id => !roster.some(actor => actor.actorId === id))
|
|
65
|
+
|| !recipients.some(id => roster.some(actor => actor.actorId === id && !actor.humanControlled)))
|
|
66
|
+
fail('recipient_invalid', 'Input recipients must name the exact character cast');
|
|
67
|
+
const eligibleRevision = record.revision + (journal.batches.some(batch => batch.revision === record.revision + 1) ? 2 : 1);
|
|
68
|
+
if (record.dynamicState && eligibleRevision > record.dynamicState.safetyCeiling)
|
|
69
|
+
fail('input_after_final_beat', 'The world ends at this beat; messages and edits can no longer reach it');
|
|
70
|
+
if (journal.inputs.length >= 256)
|
|
71
|
+
fail('input_storage_exhausted', 'This run has reached its durable input storage limit; retrying cannot free storage');
|
|
72
|
+
const open = journal.inputs.filter(input => input.eligibleRevision === eligibleRevision);
|
|
73
|
+
const recipientSet = new Set([...open.flatMap(input => input.recipientActorIds), ...recipients].filter(id => !roster.find(actor => actor.actorId === id)?.humanControlled));
|
|
74
|
+
const bodyBytes = open.reduce((sum, input) => sum + Buffer.byteLength(input.payload.kind === 'message' ? input.payload.body : docs.find(doc => doc.versionId === input.payload.versionId).body, 'utf8'), Buffer.byteLength(request.body, 'utf8'));
|
|
75
|
+
if (open.length >= 8 || bodyBytes > 16384 || recipientSet.size > 4)
|
|
76
|
+
fail('input_capacity', 'The next input batch is full; retry after it advances');
|
|
77
|
+
let payload = { kind: 'message', body: request.body };
|
|
78
|
+
if (request.kind === 'document-edit') {
|
|
79
|
+
const written = record.state.addDocument({
|
|
80
|
+
...(document.provenance === undefined ? {} : { provenance: { policyVersion: 'document-stream-1', documentKey: document.provenance.documentKey, eligibleRevision, kind: 'player-edit', inputId: request.inputId } }),
|
|
81
|
+
label: document.label, type: 'memo', content: request.body, summary: '', createdBy: senderActorId,
|
|
82
|
+
sentTo: recipients, ownerActorId: document.ownerActorId, revisionOf: document.versionId
|
|
83
|
+
});
|
|
84
|
+
payload = { kind: 'document-edit', documentId: document.documentId, versionId: written.id, version: document.version + 1 };
|
|
85
|
+
}
|
|
86
|
+
const input = { inputId: request.inputId, senderActorId, recipientActorIds: recipients, acceptedSequence: journal.inputs.length + 1, eligibleRevision, fingerprint, payload };
|
|
87
|
+
const acknowledgement = { inputId: input.inputId, recipientActorIds: recipients, recipientNames: recipients.map(id => roster.find(actor => actor.actorId === id).name), eligibleRevision, acceptedSequence: input.acceptedSequence,
|
|
88
|
+
...(payload.kind === 'document-edit' ? { document: { documentId: payload.documentId, versionId: payload.versionId, version: payload.version } } : {}) };
|
|
89
|
+
journal.inputs.push(input);
|
|
90
|
+
journal.acknowledgements.push(acknowledgement);
|
|
91
|
+
record.inputJournal = journal;
|
|
92
|
+
return { checkpoint: checkedCheckpoint(detachedSessionCheckpoint(record, checkpoint)), acknowledgement, replayed: false };
|
|
93
|
+
}
|
|
94
|
+
finally {
|
|
95
|
+
record.state.close();
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
export async function sealSessionInputs(checkpoint) {
|
|
99
|
+
const record = await detachedSessionRecord(checkpoint);
|
|
100
|
+
try {
|
|
101
|
+
record.inputJournal ??= emptyJournal();
|
|
102
|
+
const snapshot = detachedSessionSnapshot(record);
|
|
103
|
+
const prior = record.inputJournal.batches.find(batch => batch.revision === record.revision + 1);
|
|
104
|
+
if (prior) {
|
|
105
|
+
assertSealedReadSet(snapshot, prior.digest);
|
|
106
|
+
return { checkpoint, batch: prior };
|
|
107
|
+
}
|
|
108
|
+
record.inputJournal.materialFromRevision ??= record.revision + 1;
|
|
109
|
+
record.inputJournal.batches = record.inputJournal.batches.filter(batch => batch.inputIds.length > 0 || batch.revision > record.revision);
|
|
110
|
+
const documents = sessionDocuments(snapshot);
|
|
111
|
+
const documentVersionIds = documents.filter(doc => !documents.some(next => next.documentId === doc.documentId && next.version > doc.version)
|
|
112
|
+
|| record.inputJournal.inputs.some(input => input.eligibleRevision === record.revision + 1 && input.payload.kind === 'document-edit' && input.payload.versionId === doc.versionId)).map(doc => doc.versionId);
|
|
113
|
+
const inputIds = record.inputJournal.inputs.filter(input => input.eligibleRevision === record.revision + 1).map(input => input.inputId);
|
|
114
|
+
const recipientIds = new Set(record.inputJournal.inputs.filter(input => inputIds.includes(input.inputId)).flatMap(input => input.recipientActorIds));
|
|
115
|
+
const resolutionContract = { version: 2, actorsBefore: structuredClone(record.dynamicState?.agents.filter(actor => recipientIds.has(actor.actorId) && !actor.humanControlled) ?? []) };
|
|
116
|
+
const data = { resolutionContract, documentVersionIds, revision: record.revision + 1, basedOnRevision: record.revision, inputIds: record.inputJournal.inputs.filter(input => input.eligibleRevision === record.revision + 1).map(input => input.inputId), worldDigest: worldDigest(snapshot) };
|
|
117
|
+
const batch = { ...data, digest: batchDigest(snapshot, data) };
|
|
118
|
+
record.inputJournal.batches.push(batch);
|
|
119
|
+
return { checkpoint: checkedCheckpoint(detachedSessionCheckpoint(record, checkpoint)), batch };
|
|
120
|
+
}
|
|
121
|
+
finally {
|
|
122
|
+
record.state.close();
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
export async function projectSessionInputs(checkpoint, actorId, includeDocumentHistory = false) {
|
|
126
|
+
const record = await detachedSessionRecord(checkpoint);
|
|
127
|
+
try {
|
|
128
|
+
const snapshot = detachedSessionSnapshot(record);
|
|
129
|
+
if (!actors(snapshot).some(actor => actor.actorId === actorId))
|
|
130
|
+
fail('sender_invalid', 'Actor was not found');
|
|
131
|
+
const journal = record.inputJournal ?? emptyJournal();
|
|
132
|
+
const inputs = journal.inputs.filter(input => input.senderActorId === actorId || input.recipientActorIds.includes(actorId));
|
|
133
|
+
const all = sessionDocuments(snapshot).filter(doc => doc.recipientActorIds.includes(actorId));
|
|
134
|
+
return { inputs, documents: includeDocumentHistory ? all : all.filter(doc => !all.some(other => other.documentId === doc.documentId && other.version > doc.version)), acknowledgements: journal.acknowledgements.filter(ack => inputs.some(input => input.inputId === ack.inputId)), resolutions: journal.resolutions.filter(item => inputs.some(input => input.inputId === item.inputId)) };
|
|
135
|
+
}
|
|
136
|
+
finally {
|
|
137
|
+
record.state.close();
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
export async function commitSessionInputBatch(request) {
|
|
141
|
+
const record = await detachedSessionRecord(request.checkpoint);
|
|
142
|
+
try {
|
|
143
|
+
assertSealedReadSet(detachedSessionSnapshot(record), request.sealedDigest);
|
|
144
|
+
if (request.batch.operations.some(op => op.operation === 'document.write' && op.ownerActorId === undefined))
|
|
145
|
+
fail('input_invalid', 'Detached documents require explicit ownership');
|
|
146
|
+
await applyDetachedSessionTransition(record, request.batch);
|
|
147
|
+
if (!record.dynamicState)
|
|
148
|
+
return fail('input_state_invalid', 'Dynamic state is missing');
|
|
149
|
+
return { checkpoint: checkedCheckpoint(detachedSessionCheckpoint(record, request.checkpoint)), state: record.dynamicState };
|
|
150
|
+
}
|
|
151
|
+
finally {
|
|
152
|
+
record.state.close();
|
|
153
|
+
}
|
|
154
|
+
}
|