cosmos-platform 1.6.0.dev1__py3-none-any.whl
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.
- cosmos_platform-1.6.0.dev1.dist-info/METADATA +150 -0
- cosmos_platform-1.6.0.dev1.dist-info/RECORD +541 -0
- cosmos_platform-1.6.0.dev1.dist-info/WHEEL +5 -0
- cosmos_platform-1.6.0.dev1.dist-info/entry_points.txt +2 -0
- cosmos_platform-1.6.0.dev1.dist-info/licenses/LICENSE +202 -0
- cosmos_platform-1.6.0.dev1.dist-info/top_level.txt +2 -0
- runtime/__init__.py +1 -0
- runtime/candidate/__init__.py +8 -0
- runtime/candidate/admission_gate.py +1776 -0
- runtime/certification/test_certify_opencode_identity.py +71 -0
- runtime/certification/test_certify_w304_windows_silence.py +888 -0
- runtime/certification/test_cosmos15_empirical.py +60 -0
- runtime/certification/test_cosmos_control_center.py +490 -0
- runtime/certification/test_cosmos_dogfood.py +143 -0
- runtime/certification/test_enforcement_census_lc16.py +1112 -0
- runtime/certification/test_eol_byte_stability_p001.py +394 -0
- runtime/certification/test_lc113_adapter_terminal_proofs.py +414 -0
- runtime/certification/test_live_certification_k3.py +622 -0
- runtime/certification/test_mcp_live_c4b.py +1210 -0
- runtime/certification/test_phase9_closeout.py +19 -0
- runtime/certification/test_preservation_census_lc17.py +1039 -0
- runtime/certification/test_self_hosting_cold_reconstruction.py +158 -0
- runtime/certification/test_self_hosting_conformance.py +18 -0
- runtime/certification/test_self_hosting_continuity.py +50 -0
- runtime/certification/test_self_hosting_environment.py +329 -0
- runtime/certification/test_self_hosting_learning.py +56 -0
- runtime/certification/test_self_hosting_two_generation.py +21 -0
- runtime/certification/test_truth_drift_lc18.py +557 -0
- runtime/certification/test_universal_binding_c3.py +770 -0
- runtime/certification/test_w101_attempt2.py +698 -0
- runtime/certification/test_w101_preservation.py +425 -0
- runtime/certification/test_w304_option_a_startup_liveness.py +1093 -0
- runtime/certification/test_w304_wedge_log_flood.py +468 -0
- runtime/certification/test_w304_wedge_recovery.py +258 -0
- runtime/cosmos_runtime/__init__.py +169 -0
- runtime/cosmos_runtime/__main__.py +3 -0
- runtime/cosmos_runtime/actors.py +363 -0
- runtime/cosmos_runtime/adaptive_reasoning.py +242 -0
- runtime/cosmos_runtime/authorization.py +567 -0
- runtime/cosmos_runtime/cli.py +61 -0
- runtime/cosmos_runtime/config.py +21 -0
- runtime/cosmos_runtime/context.py +347 -0
- runtime/cosmos_runtime/continuation.py +548 -0
- runtime/cosmos_runtime/continuity/__init__.py +16 -0
- runtime/cosmos_runtime/continuity/handoff.py +208 -0
- runtime/cosmos_runtime/controller.py +218 -0
- runtime/cosmos_runtime/effects.py +546 -0
- runtime/cosmos_runtime/execution.py +725 -0
- runtime/cosmos_runtime/execution_shim.py +428 -0
- runtime/cosmos_runtime/governance/__init__.py +60 -0
- runtime/cosmos_runtime/governance/completion.py +434 -0
- runtime/cosmos_runtime/governance/gates.py +952 -0
- runtime/cosmos_runtime/governance/scope_types.py +150 -0
- runtime/cosmos_runtime/ids.py +25 -0
- runtime/cosmos_runtime/intake.py +170 -0
- runtime/cosmos_runtime/learning.py +294 -0
- runtime/cosmos_runtime/model.py +240 -0
- runtime/cosmos_runtime/resilience.py +298 -0
- runtime/cosmos_runtime/security/__init__.py +72 -0
- runtime/cosmos_runtime/security/audit.py +139 -0
- runtime/cosmos_runtime/security/consent.py +153 -0
- runtime/cosmos_runtime/security/encryption.py +158 -0
- runtime/cosmos_runtime/security/enterprise_fence.py +169 -0
- runtime/cosmos_runtime/security/injection_detector.py +123 -0
- runtime/cosmos_runtime/security/microphone.py +145 -0
- runtime/cosmos_runtime/security/retention.py +168 -0
- runtime/cosmos_runtime/security/tenant.py +108 -0
- runtime/cosmos_runtime/services.py +187 -0
- runtime/cosmos_runtime/store.py +802 -0
- runtime/cosmos_runtime/telemetry/__init__.py +42 -0
- runtime/cosmos_runtime/telemetry/bus.py +198 -0
- runtime/cosmos_runtime/telemetry/events.py +187 -0
- runtime/cosmos_runtime/telemetry/scrubber.py +119 -0
- runtime/tests/__init__.py +11 -0
- runtime/tests/_pollution_guard.py +311 -0
- runtime/tests/_retrieval_fixtures.py +102 -0
- runtime/tests/_world_isolation.py +138 -0
- runtime/tests/conftest.py +56 -0
- runtime/tests/gate_local_support.py +234 -0
- runtime/tests/test_aaa_pollution_guard.py +218 -0
- runtime/tests/test_actor_routing.py +187 -0
- runtime/tests/test_adapter_family_agent_frameworks_activation.py +883 -0
- runtime/tests/test_adapter_family_cloud_coding_activation.py +1090 -0
- runtime/tests/test_adapter_family_core_cli_activation.py +2039 -0
- runtime/tests/test_adapter_family_emacs_activation.py +769 -0
- runtime/tests/test_adapter_family_ide_rules_activation.py +1016 -0
- runtime/tests/test_adapter_family_jetbrains_eclipse_activation.py +990 -0
- runtime/tests/test_adapter_family_neovim_activation.py +830 -0
- runtime/tests/test_adaptive_reasoning.py +115 -0
- runtime/tests/test_ar4_self_hosting_decoupling.py +49 -0
- runtime/tests/test_assurance_spine_c2.py +411 -0
- runtime/tests/test_authorization_gateway.py +203 -0
- runtime/tests/test_capability_reconciliation_lc14.py +257 -0
- runtime/tests/test_carrier_flow_k3.py +326 -0
- runtime/tests/test_cert_invalidation_k4.py +764 -0
- runtime/tests/test_certification_adversarial_v1.py +882 -0
- runtime/tests/test_claims_matrix_lc15.py +551 -0
- runtime/tests/test_completion.py +306 -0
- runtime/tests/test_context_binding.py +160 -0
- runtime/tests/test_continuation.py +269 -0
- runtime/tests/test_cosmos15_baseline.py +31 -0
- runtime/tests/test_cosmos15_claude_door.py +108 -0
- runtime/tests/test_cosmos15_developer_world.py +194 -0
- runtime/tests/test_cosmos15_observatory.py +286 -0
- runtime/tests/test_cosmos15_operator.py +329 -0
- runtime/tests/test_cosmos_admin.py +221 -0
- runtime/tests/test_cosmos_agent_directory_boundary.py +32 -0
- runtime/tests/test_cosmos_ask.py +119 -0
- runtime/tests/test_cosmos_blocker_gate.py +192 -0
- runtime/tests/test_cosmos_branch_audit.py +227 -0
- runtime/tests/test_cosmos_by_path.py +557 -0
- runtime/tests/test_cosmos_capability_health.py +651 -0
- runtime/tests/test_cosmos_certification.py +98 -0
- runtime/tests/test_cosmos_check_proposal.py +584 -0
- runtime/tests/test_cosmos_check_runner.py +578 -0
- runtime/tests/test_cosmos_check_runner_shard_s1.py +765 -0
- runtime/tests/test_cosmos_cloud_bundle.py +33 -0
- runtime/tests/test_cosmos_cold_clone_binding.py +106 -0
- runtime/tests/test_cosmos_context_authority.py +276 -0
- runtime/tests/test_cosmos_continuation.py +210 -0
- runtime/tests/test_cosmos_continuity.py +147 -0
- runtime/tests/test_cosmos_continuity_demo.py +93 -0
- runtime/tests/test_cosmos_continuity_hook.py +453 -0
- runtime/tests/test_cosmos_controller.py +125 -0
- runtime/tests/test_cosmos_cross_harness_handoff.py +93 -0
- runtime/tests/test_cosmos_current_task_derivation.py +202 -0
- runtime/tests/test_cosmos_decision_guard.py +179 -0
- runtime/tests/test_cosmos_decisions.py +161 -0
- runtime/tests/test_cosmos_defensibility_qualification.py +135 -0
- runtime/tests/test_cosmos_delta.py +512 -0
- runtime/tests/test_cosmos_delta_cli.py +196 -0
- runtime/tests/test_cosmos_dependency_graph.py +94 -0
- runtime/tests/test_cosmos_dependency_graph_scope.py +67 -0
- runtime/tests/test_cosmos_deployment_reconciler.py +213 -0
- runtime/tests/test_cosmos_doctor_command_shadowing.py +61 -0
- runtime/tests/test_cosmos_doorway_validator.py +139 -0
- runtime/tests/test_cosmos_enforce.py +222 -0
- runtime/tests/test_cosmos_events.py +77 -0
- runtime/tests/test_cosmos_evidence.py +122 -0
- runtime/tests/test_cosmos_execution_shim.py +254 -0
- runtime/tests/test_cosmos_feedback.py +97 -0
- runtime/tests/test_cosmos_gate.py +3007 -0
- runtime/tests/test_cosmos_gate_backlog.py +218 -0
- runtime/tests/test_cosmos_gate_categories.py +240 -0
- runtime/tests/test_cosmos_gate_f008.py +386 -0
- runtime/tests/test_cosmos_gate_fast.py +3527 -0
- runtime/tests/test_cosmos_gate_governance.py +196 -0
- runtime/tests/test_cosmos_gate_lessons.py +113 -0
- runtime/tests/test_cosmos_gate_load.py +283 -0
- runtime/tests/test_cosmos_gate_multi.py +357 -0
- runtime/tests/test_cosmos_gate_override.py +114 -0
- runtime/tests/test_cosmos_gate_profile.py +271 -0
- runtime/tests/test_cosmos_gate_recheck.py +134 -0
- runtime/tests/test_cosmos_gate_runtime.py +304 -0
- runtime/tests/test_cosmos_gate_selfcheck.py +27 -0
- runtime/tests/test_cosmos_gate_skip.py +95 -0
- runtime/tests/test_cosmos_git_hooks.py +117 -0
- runtime/tests/test_cosmos_guard.py +938 -0
- runtime/tests/test_cosmos_harness_doors.py +50 -0
- runtime/tests/test_cosmos_hygiene.py +76 -0
- runtime/tests/test_cosmos_hypothesis.py +106 -0
- runtime/tests/test_cosmos_index_hot_journal.py +108 -0
- runtime/tests/test_cosmos_landing_board.py +228 -0
- runtime/tests/test_cosmos_learn.py +92 -0
- runtime/tests/test_cosmos_levels_of_done.py +67 -0
- runtime/tests/test_cosmos_lineage.py +157 -0
- runtime/tests/test_cosmos_mcp_binding.py +182 -0
- runtime/tests/test_cosmos_mcp_governed_tools.py +185 -0
- runtime/tests/test_cosmos_mcp_registration.py +430 -0
- runtime/tests/test_cosmos_memory_maintenance.py +81 -0
- runtime/tests/test_cosmos_modality_registry.py +52 -0
- runtime/tests/test_cosmos_narrative.py +189 -0
- runtime/tests/test_cosmos_navigator_product_path.py +56 -0
- runtime/tests/test_cosmos_next.py +669 -0
- runtime/tests/test_cosmos_no_raw_process_start.py +92 -0
- runtime/tests/test_cosmos_objective_convergence.py +86 -0
- runtime/tests/test_cosmos_obligation_lc03.py +745 -0
- runtime/tests/test_cosmos_obligations.py +302 -0
- runtime/tests/test_cosmos_observe.py +100 -0
- runtime/tests/test_cosmos_onboarding.py +224 -0
- runtime/tests/test_cosmos_override_gate.py +288 -0
- runtime/tests/test_cosmos_packaging_billing_gate.py +396 -0
- runtime/tests/test_cosmos_pilot.py +165 -0
- runtime/tests/test_cosmos_popup_check.py +75 -0
- runtime/tests/test_cosmos_proc_owned_tree.py +249 -0
- runtime/tests/test_cosmos_project_adapters.py +158 -0
- runtime/tests/test_cosmos_push.py +178 -0
- runtime/tests/test_cosmos_qualification.py +94 -0
- runtime/tests/test_cosmos_remediation.py +67 -0
- runtime/tests/test_cosmos_report.py +99 -0
- runtime/tests/test_cosmos_retrieval.py +512 -0
- runtime/tests/test_cosmos_retrieval_cli_mcp.py +198 -0
- runtime/tests/test_cosmos_retrieval_model_fetch.py +40 -0
- runtime/tests/test_cosmos_safety.py +528 -0
- runtime/tests/test_cosmos_security_package.py +417 -0
- runtime/tests/test_cosmos_security_qualification.py +59 -0
- runtime/tests/test_cosmos_self_repair.py +504 -0
- runtime/tests/test_cosmos_serving.py +153 -0
- runtime/tests/test_cosmos_session_lifecycle.py +181 -0
- runtime/tests/test_cosmos_session_start.py +493 -0
- runtime/tests/test_cosmos_settings_hooks.py +36 -0
- runtime/tests/test_cosmos_speed_limits.py +36 -0
- runtime/tests/test_cosmos_staging_qualification.py +117 -0
- runtime/tests/test_cosmos_stop_guard.py +84 -0
- runtime/tests/test_cosmos_studio.py +1102 -0
- runtime/tests/test_cosmos_substrate_liveness.py +111 -0
- runtime/tests/test_cosmos_supply_chain_gate.py +238 -0
- runtime/tests/test_cosmos_synthetic_pilot.py +46 -0
- runtime/tests/test_cosmos_telemetry.py +65 -0
- runtime/tests/test_cosmos_telemetry_bus.py +157 -0
- runtime/tests/test_cosmos_telemetry_scrubber.py +124 -0
- runtime/tests/test_cosmos_tracker_render.py +95 -0
- runtime/tests/test_cosmos_trigger_records.py +198 -0
- runtime/tests/test_cosmos_tripartite_delta.py +154 -0
- runtime/tests/test_cosmos_tripartite_events.py +103 -0
- runtime/tests/test_cosmos_trust_readiness.py +375 -0
- runtime/tests/test_cosmos_vault.py +3524 -0
- runtime/tests/test_cosmos_vault_entry_points.py +920 -0
- runtime/tests/test_cosmos_vault_worker.py +1450 -0
- runtime/tests/test_cosmos_visibility_policy.py +187 -0
- runtime/tests/test_cosmos_wake.py +43 -0
- runtime/tests/test_cosmos_watchdog.py +1318 -0
- runtime/tests/test_cosmos_world_refresh_and_capture.py +711 -0
- runtime/tests/test_cosmos_wrong_direction.py +214 -0
- runtime/tests/test_cosmos_zero_step.py +245 -0
- runtime/tests/test_daemon_supervisor_c5b.py +845 -0
- runtime/tests/test_enforcement_live_c4.py +485 -0
- runtime/tests/test_execution_loop.py +216 -0
- runtime/tests/test_foundation.py +145 -0
- runtime/tests/test_governance_gates.py +327 -0
- runtime/tests/test_intake.py +107 -0
- runtime/tests/test_invalidationscan_k4.py +776 -0
- runtime/tests/test_lc112_live_attestation_commission.py +292 -0
- runtime/tests/test_lc133_lp2_entry_points.py +268 -0
- runtime/tests/test_lc1_baseline_lc19.py +702 -0
- runtime/tests/test_levels_of_done_k1.py +474 -0
- runtime/tests/test_live_attestation_k2.py +521 -0
- runtime/tests/test_live_attestation_k2_regressions.py +442 -0
- runtime/tests/test_live_certification_k3_regressions.py +623 -0
- runtime/tests/test_lp7_studio_trigger.py +191 -0
- runtime/tests/test_master_plan_revision_identity.py +123 -0
- runtime/tests/test_multi_harness_acceptance.py +292 -0
- runtime/tests/test_multi_harness_stress.py +188 -0
- runtime/tests/test_objective_live_c1.py +437 -0
- runtime/tests/test_obligation_reconciliation_lc13.py +351 -0
- runtime/tests/test_observation_projection.py +156 -0
- runtime/tests/test_observation_wiring.py +100 -0
- runtime/tests/test_one_active_wave_lc06.py +629 -0
- runtime/tests/test_operational_sandbox_harness.py +111 -0
- runtime/tests/test_p002_canonical_engine.py +275 -0
- runtime/tests/test_p003_watcher_failure_attribution.py +933 -0
- runtime/tests/test_phase8_closeout.py +89 -0
- runtime/tests/test_phase8_company_environment.py +84 -0
- runtime/tests/test_phase8_company_proof.py +278 -0
- runtime/tests/test_phase8_cross_environment_audit.py +89 -0
- runtime/tests/test_phase8_developer_environment.py +59 -0
- runtime/tests/test_phase8_developer_proof.py +204 -0
- runtime/tests/test_phase8_harness.py +66 -0
- runtime/tests/test_phase8_personal_environment.py +62 -0
- runtime/tests/test_phase8_personal_proof.py +105 -0
- runtime/tests/test_phase8_protocol.py +180 -0
- runtime/tests/test_plan_before_code_lc04.py +830 -0
- runtime/tests/test_plan_census_lc12.py +243 -0
- runtime/tests/test_repo_census_lc11.py +230 -0
- runtime/tests/test_resilience.py +182 -0
- runtime/tests/test_retrieval_live_c5.py +270 -0
- runtime/tests/test_run_monitor_s2.py +587 -0
- runtime/tests/test_runtime_conformance.py +389 -0
- runtime/tests/test_sandbox_adapters.py +238 -0
- runtime/tests/test_scale_acceptance.py +114 -0
- runtime/tests/test_scope_freeze_lc05.py +638 -0
- runtime/tests/test_self_hosting_first_change.py +69 -0
- runtime/tests/test_self_hosting_projection.py +145 -0
- runtime/tests/test_self_hosting_protocol.py +87 -0
- runtime/tests/test_siem_integration_harness.py +98 -0
- runtime/tests/test_sign_release_archive.py +141 -0
- runtime/tests/test_store_concurrency.py +118 -0
- runtime/tests/test_studio_broker_integration.py +147 -0
- runtime/tests/test_tiers_doc.py +54 -0
- runtime/tests/test_trigger_firing_c1.py +342 -0
- runtime/tests/test_verify_tripartite_observability.py +120 -0
- runtime/tests/test_w102_branch_audit_equivalence.py +334 -0
- runtime/tests/test_w102_git_timeout_hang.py +233 -0
- runtime/tests/test_w103_identity.py +378 -0
- runtime/tests/test_w103_real_harness_identity.py +159 -0
- runtime/tests/test_w103_review_correction.py +224 -0
- runtime/tests/test_w103_round2_consumption.py +304 -0
- runtime/tests/test_w304_silent_background.py +713 -0
- runtime/tests/test_wave_report_lc07.py +332 -0
- tools/__init__.py +5 -0
- tools/adapter_families/agent_frameworks.py +1418 -0
- tools/adapter_families/cloud_coding.py +875 -0
- tools/adapter_families/core_cli.py +2519 -0
- tools/adapter_families/emacs.py +1247 -0
- tools/adapter_families/ide_rules.py +1105 -0
- tools/adapter_families/jetbrains_eclipse.py +1381 -0
- tools/adapter_families/neovim.py +995 -0
- tools/build_cosmos15_release_archive.py +110 -0
- tools/catalogs/model-modalities.json +84 -0
- tools/catalogs/ui-ux-catalog.json +173 -0
- tools/control_center/app.js +78 -0
- tools/control_center/index.html +35 -0
- tools/control_center/styles.css +4 -0
- tools/cosmos.py +1018 -0
- tools/cosmos15_operator.py +980 -0
- tools/cosmos15_world_recovery.py +292 -0
- tools/cosmos_adapter_health.py +311 -0
- tools/cosmos_ask.py +102 -0
- tools/cosmos_attach.py +237 -0
- tools/cosmos_background.py +258 -0
- tools/cosmos_bind.py +764 -0
- tools/cosmos_binding.py +130 -0
- tools/cosmos_blocker_gate.py +285 -0
- tools/cosmos_branch_audit.py +315 -0
- tools/cosmos_capability_health.py +4202 -0
- tools/cosmos_capability_reconciliation.py +419 -0
- tools/cosmos_capture_hook.py +644 -0
- tools/cosmos_cert_invalidation.py +1673 -0
- tools/cosmos_certification.py +506 -0
- tools/cosmos_check_proposal.py +483 -0
- tools/cosmos_check_runner.py +2480 -0
- tools/cosmos_claims_matrix.py +851 -0
- tools/cosmos_claude_door.py +268 -0
- tools/cosmos_cloud_bundle.py +73 -0
- tools/cosmos_context_authority.py +515 -0
- tools/cosmos_continuation.py +315 -0
- tools/cosmos_continuity_demo.py +180 -0
- tools/cosmos_continuity_wrapper.py +194 -0
- tools/cosmos_control_center.py +476 -0
- tools/cosmos_curator.py +175 -0
- tools/cosmos_daemon_supervisor.py +3082 -0
- tools/cosmos_decision_guard.py +206 -0
- tools/cosmos_decision_rank.py +103 -0
- tools/cosmos_decisions.py +343 -0
- tools/cosmos_defensibility_qualification.py +322 -0
- tools/cosmos_delta.py +887 -0
- tools/cosmos_dependency_graph.py +235 -0
- tools/cosmos_deployment_reconciler.py +393 -0
- tools/cosmos_design_dna.py +377 -0
- tools/cosmos_developer_world.py +1233 -0
- tools/cosmos_doctor.py +427 -0
- tools/cosmos_door_common.py +16 -0
- tools/cosmos_door_helpers.py +54 -0
- tools/cosmos_doorway_validator.py +152 -0
- tools/cosmos_enforce.py +527 -0
- tools/cosmos_enforcement_census.py +2657 -0
- tools/cosmos_eval.py +310 -0
- tools/cosmos_events.py +123 -0
- tools/cosmos_evidence.py +135 -0
- tools/cosmos_feedback.py +252 -0
- tools/cosmos_forge_adapters.py +190 -0
- tools/cosmos_forge_protection.py +154 -0
- tools/cosmos_fs_watcher.py +1378 -0
- tools/cosmos_gate.py +3172 -0
- tools/cosmos_gate_backlog.py +294 -0
- tools/cosmos_gate_carry.py +122 -0
- tools/cosmos_gate_categories.py +159 -0
- tools/cosmos_gate_closure.py +56 -0
- tools/cosmos_gate_fast.py +2592 -0
- tools/cosmos_gate_governance.py +282 -0
- tools/cosmos_gate_holdout.py +704 -0
- tools/cosmos_gate_linux.py +203 -0
- tools/cosmos_gate_load.py +205 -0
- tools/cosmos_gate_override.py +82 -0
- tools/cosmos_gate_profile.py +169 -0
- tools/cosmos_gate_protect.py +79 -0
- tools/cosmos_gate_replacements.py +66 -0
- tools/cosmos_gate_runtime.py +123 -0
- tools/cosmos_gate_scope.py +110 -0
- tools/cosmos_gate_selfcheck.py +79 -0
- tools/cosmos_gate_service.py +591 -0
- tools/cosmos_gate_union.py +108 -0
- tools/cosmos_git_hooks.py +59 -0
- tools/cosmos_githooks.py +94 -0
- tools/cosmos_guard.py +1887 -0
- tools/cosmos_harness_doors.py +350 -0
- tools/cosmos_home_guard.py +199 -0
- tools/cosmos_hygiene.py +251 -0
- tools/cosmos_hypothesis.py +124 -0
- tools/cosmos_identity.py +295 -0
- tools/cosmos_invariants.py +212 -0
- tools/cosmos_landing_board.py +394 -0
- tools/cosmos_launch.py +432 -0
- tools/cosmos_launcher.py +177 -0
- tools/cosmos_lc1_baseline.py +776 -0
- tools/cosmos_learn.py +319 -0
- tools/cosmos_levels_of_done.py +740 -0
- tools/cosmos_lineage.py +201 -0
- tools/cosmos_live_attestation.py +1559 -0
- tools/cosmos_mcp_registration.py +625 -0
- tools/cosmos_mcp_server.py +2253 -0
- tools/cosmos_memory.py +273 -0
- tools/cosmos_memory_check.py +97 -0
- tools/cosmos_modality_registry.py +113 -0
- tools/cosmos_narrative.py +225 -0
- tools/cosmos_next.py +659 -0
- tools/cosmos_objective_convergence.py +167 -0
- tools/cosmos_obligations.py +2809 -0
- tools/cosmos_observation_projection.py +144 -0
- tools/cosmos_observe.py +353 -0
- tools/cosmos_opencode_push.js +164 -0
- tools/cosmos_overlay_injector.py +44 -0
- tools/cosmos_override_gate.py +550 -0
- tools/cosmos_packaging_billing_gate.py +314 -0
- tools/cosmos_packet.py +973 -0
- tools/cosmos_pilot.py +731 -0
- tools/cosmos_plan_census.py +634 -0
- tools/cosmos_popup_check.py +260 -0
- tools/cosmos_premise.py +327 -0
- tools/cosmos_preservation_census.py +2185 -0
- tools/cosmos_proc.py +639 -0
- tools/cosmos_project_adapters.py +2773 -0
- tools/cosmos_push.py +138 -0
- tools/cosmos_qualification.py +291 -0
- tools/cosmos_reachability.py +345 -0
- tools/cosmos_reconciliation.py +451 -0
- tools/cosmos_refresh_adapters.py +80 -0
- tools/cosmos_remediation.py +166 -0
- tools/cosmos_repo_census.py +640 -0
- tools/cosmos_repo_finder.py +217 -0
- tools/cosmos_report.py +134 -0
- tools/cosmos_retrieval/__init__.py +41 -0
- tools/cosmos_retrieval/__main__.py +4 -0
- tools/cosmos_retrieval/activation.py +564 -0
- tools/cosmos_retrieval/cli.py +274 -0
- tools/cosmos_retrieval/embedders.py +214 -0
- tools/cosmos_retrieval/index.py +884 -0
- tools/cosmos_retrieval/model_fetch.py +122 -0
- tools/cosmos_retrieval/text.py +243 -0
- tools/cosmos_retrieval/vectors.py +101 -0
- tools/cosmos_rollback.py +453 -0
- tools/cosmos_run_monitor.py +1198 -0
- tools/cosmos_safety.py +350 -0
- tools/cosmos_scorecard.py +466 -0
- tools/cosmos_security_qualification.py +202 -0
- tools/cosmos_self_repair.py +192 -0
- tools/cosmos_serving.py +339 -0
- tools/cosmos_session_brief.py +302 -0
- tools/cosmos_session_lifecycle.py +389 -0
- tools/cosmos_session_start.py +1894 -0
- tools/cosmos_setup.py +585 -0
- tools/cosmos_staging_qualification.py +252 -0
- tools/cosmos_stop_guard.py +111 -0
- tools/cosmos_studio_app.py +2225 -0
- tools/cosmos_supply_chain_gate.py +454 -0
- tools/cosmos_synthetic_pilot.py +215 -0
- tools/cosmos_telemetry.py +153 -0
- tools/cosmos_tracker_render.py +196 -0
- tools/cosmos_trust_readiness.py +607 -0
- tools/cosmos_truth_drift.py +1573 -0
- tools/cosmos_vault.py +2023 -0
- tools/cosmos_vault_acl.py +715 -0
- tools/cosmos_vault_bundle.py +438 -0
- tools/cosmos_vault_install.py +471 -0
- tools/cosmos_vault_service.py +345 -0
- tools/cosmos_vault_worker.py +745 -0
- tools/cosmos_visibility_policy.py +134 -0
- tools/cosmos_wake.py +262 -0
- tools/cosmos_watchdog.py +1775 -0
- tools/cosmos_watchdog_timing.py +100 -0
- tools/cosmos_wave_report.py +357 -0
- tools/cosmos_wrong_direction.py +217 -0
- tools/evaluate_assurance_risk.py +302 -0
- tools/generate_execution_stack_conformance_fixtures.py +122 -0
- tools/generate_execution_stack_envelope_fixtures.py +122 -0
- tools/generate_model_route_receipt_fixtures.py +320 -0
- tools/observatory/README.md +64 -0
- tools/observatory/app.js +486 -0
- tools/observatory/index.html +82 -0
- tools/observatory/launcher.css +249 -0
- tools/observatory/launcher.html +80 -0
- tools/observatory/launcher.js +173 -0
- tools/observatory/styles.css +83 -0
- tools/operational_sandbox_harness.py +481 -0
- tools/owner_requeue.py +402 -0
- tools/reference_authorization.py +427 -0
- tools/reference_cold_reconstruction.py +264 -0
- tools/reference_context_binder.py +570 -0
- tools/reference_cosmos15_empirical.py +208 -0
- tools/reference_dogfood_runner.py +166 -0
- tools/reference_environment_audit.py +332 -0
- tools/reference_environment_harness.py +764 -0
- tools/reference_environment_proof.py +206 -0
- tools/reference_first_self_change.py +342 -0
- tools/reference_generation_a_continuation.py +111 -0
- tools/reference_generation_b_continuation.py +102 -0
- tools/reference_knowledge_lifecycle.py +318 -0
- tools/reference_maintenance.py +399 -0
- tools/reference_observatory.py +848 -0
- tools/reference_phase8_closeout.py +249 -0
- tools/reference_phase9_closeout.py +138 -0
- tools/reference_repository_projection.py +689 -0
- tools/reference_self_hosting.py +245 -0
- tools/reference_self_hosting_conformance.py +118 -0
- tools/reference_self_hosting_continuity.py +227 -0
- tools/reference_self_hosting_environment.py +411 -0
- tools/reference_self_learning.py +284 -0
- tools/run_execution_stack_conformance.py +195 -0
- tools/schemas/cosmos-certification.schema.json +65 -0
- tools/schemas/cosmos-record.schema.json +2918 -0
- tools/schemas/enterprise-audit-export.schema.json +255 -0
- tools/schemas/enterprise-durability-recovery.schema.json +282 -0
- tools/schemas/enterprise-execution-sandbox.schema.json +241 -0
- tools/schemas/enterprise-identity-policy.schema.json +222 -0
- tools/schemas/enterprise-secrets.schema.json +243 -0
- tools/schemas/environment-pack.schema.json +184 -0
- tools/schemas/environment-proof-case.schema.json +131 -0
- tools/schemas/execution-stack-conformance.schema.json +132 -0
- tools/schemas/execution-stack-envelope.schema.json +161 -0
- tools/schemas/model-modality-profile.schema.json +66 -0
- tools/schemas/model-route-receipt.schema.json +71 -0
- tools/schemas/relation-type.schema.json +76 -0
- tools/schemas/release-manifest.schema.json +58 -0
- tools/schemas/self-hosting-contract.schema.json +143 -0
- tools/siem_integration_harness.py +413 -0
- tools/sign_release_archive.py +357 -0
- tools/spec/reveal-register.json +65 -0
- tools/spec/reveal-register.schema.json +41 -0
- tools/stitch_design_bridge.py +593 -0
- tools/studio/byom_router.js +101 -0
- tools/studio/ide.html +109 -0
- tools/studio/ide.js +62 -0
- tools/studio/index.html +23 -0
- tools/studio/modality_guard.js +101 -0
- tools/studio/observatory_dock.js +60 -0
- tools/studio/studio.css +489 -0
- tools/studio/studio.js +50 -0
- tools/studio/studio_concentric_live.png +0 -0
- tools/studio/studio_cosmos_canvas.png +0 -0
- tools/studio/studio_hero_live.png +0 -0
- tools/studio/studio_live.png +0 -0
- tools/studio/studio_preview.png +0 -0
- tools/studio/studio_refined_platform.png +0 -0
- tools/studio/subatomic_sidecar.js +57 -0
- tools/validate_environment_proof.py +39 -0
- tools/validate_execution_stack_envelopes.py +157 -0
- tools/validate_model_route_receipts.py +183 -0
- tools/validate_ontology.py +121 -0
- tools/verify_cosmos15_baseline.py +104 -0
- tools/verify_cosmos15_release_archive.py +225 -0
- tools/verify_tripartite_observability.py +136 -0
|
@@ -0,0 +1,802 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from contextlib import contextmanager
|
|
4
|
+
import json
|
|
5
|
+
import sqlite3
|
|
6
|
+
import threading
|
|
7
|
+
from typing import Any, Iterator, Protocol, runtime_checkable
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
from .model import (
|
|
11
|
+
ExecutionEpisode,
|
|
12
|
+
ExecutionPackage,
|
|
13
|
+
ExecutionState,
|
|
14
|
+
RESULT_OBSERVED_EVENT,
|
|
15
|
+
RuntimeErrorInfo,
|
|
16
|
+
RuntimeEvent,
|
|
17
|
+
TaskRecord,
|
|
18
|
+
TaskState,
|
|
19
|
+
utc_now,
|
|
20
|
+
validate_transition,
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class ResultObservationRequired(ValueError):
|
|
25
|
+
"""Raised when an episode is completed without a recorded result observation.
|
|
26
|
+
|
|
27
|
+
Enforces Invariant 1 (LOOP-1 / DEC-2026-0920-07): "no meaningful action is
|
|
28
|
+
complete until its result has been observed." Subclasses ValueError so
|
|
29
|
+
existing ``except ValueError`` transition-guard handling still catches it.
|
|
30
|
+
"""
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
@runtime_checkable
|
|
34
|
+
class StorageBackend(Protocol):
|
|
35
|
+
"""Protocol defining the Storage Service Provider Interface (SPI).
|
|
36
|
+
|
|
37
|
+
Permits pluggable storage engines (e.g. SQLiteRuntimeStore, PostgresRuntimeStore)
|
|
38
|
+
to back Cosmos Runtime without altering semantic business logic.
|
|
39
|
+
"""
|
|
40
|
+
|
|
41
|
+
def create_task(self, task: TaskRecord) -> TaskRecord: ...
|
|
42
|
+
def get_task(self, task_ref: str) -> TaskRecord | None: ...
|
|
43
|
+
def list_tasks(self) -> list[TaskRecord]: ...
|
|
44
|
+
def create_episode(self, episode: ExecutionEpisode) -> ExecutionEpisode: ...
|
|
45
|
+
def get_episode(self, episode_id: str) -> ExecutionEpisode | None: ...
|
|
46
|
+
def append_event(self, event: RuntimeEvent) -> RuntimeEvent: ...
|
|
47
|
+
def list_events(self, episode_id: str) -> list[RuntimeEvent]: ...
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
class SQLiteRuntimeStore:
|
|
51
|
+
"""Durable Phase 7 continuity store.
|
|
52
|
+
|
|
53
|
+
SQLite is the baseline implementation, not a Cosmos semantic invariant.
|
|
54
|
+
Runtime callers consume this interface rather than SQLite directly.
|
|
55
|
+
Concurrency-hardened (DEF-4.2): busy_timeout, WAL checkpointing, and a
|
|
56
|
+
reentrant lock serializing every connection (readers and writers alike)
|
|
57
|
+
so concurrent callers retry via the lock instead of racing SQLite's own
|
|
58
|
+
busy-timeout under high thread contention.
|
|
59
|
+
"""
|
|
60
|
+
|
|
61
|
+
def __init__(self, path: Path | str, timeout: float = 30.0):
|
|
62
|
+
self.path = Path(path)
|
|
63
|
+
self.path.parent.mkdir(parents=True, exist_ok=True)
|
|
64
|
+
self.timeout = timeout
|
|
65
|
+
self._closed = False
|
|
66
|
+
# RLock (not Lock): a plain Lock would deadlock if any method ever
|
|
67
|
+
# calls another store method (and so re-enters _connect()) from the
|
|
68
|
+
# same thread while already holding it. No such case exists today,
|
|
69
|
+
# but RLock costs nothing and closes off that whole class of bug
|
|
70
|
+
# rather than relying on every future change to avoid it.
|
|
71
|
+
self._write_lock = threading.RLock()
|
|
72
|
+
self._initialize()
|
|
73
|
+
|
|
74
|
+
def close(self) -> None:
|
|
75
|
+
"""Mark the store closed. Idempotent.
|
|
76
|
+
|
|
77
|
+
Connections are opened and closed around each operation, so no SQLite
|
|
78
|
+
file handle is held between calls. Closing therefore only forbids further
|
|
79
|
+
use; callers that discard a store (for example a temporary proof workspace)
|
|
80
|
+
should close it before removing the database file.
|
|
81
|
+
"""
|
|
82
|
+
with self._write_lock:
|
|
83
|
+
self._closed = True
|
|
84
|
+
|
|
85
|
+
def __enter__(self) -> "SQLiteRuntimeStore":
|
|
86
|
+
return self
|
|
87
|
+
|
|
88
|
+
def __exit__(self, exc_type: Any, exc: Any, tb: Any) -> None:
|
|
89
|
+
self.close()
|
|
90
|
+
|
|
91
|
+
@contextmanager
|
|
92
|
+
def _connect(self) -> Iterator[sqlite3.Connection]:
|
|
93
|
+
with self._write_lock:
|
|
94
|
+
if self._closed:
|
|
95
|
+
raise RuntimeError(f"runtime store is closed: {self.path}")
|
|
96
|
+
conn = sqlite3.connect(self.path, timeout=self.timeout)
|
|
97
|
+
conn.row_factory = sqlite3.Row
|
|
98
|
+
conn.execute("PRAGMA foreign_keys = ON")
|
|
99
|
+
conn.execute("PRAGMA journal_mode = WAL")
|
|
100
|
+
conn.execute(f"PRAGMA busy_timeout = {int(self.timeout * 1000)}")
|
|
101
|
+
conn.execute("PRAGMA synchronous = NORMAL")
|
|
102
|
+
try:
|
|
103
|
+
with conn:
|
|
104
|
+
yield conn
|
|
105
|
+
finally:
|
|
106
|
+
conn.close()
|
|
107
|
+
|
|
108
|
+
def checkpoint(self, mode: str = "PASSIVE") -> tuple[int, int, int]:
|
|
109
|
+
"""Executes PRAGMA wal_checkpoint with specified mode (PASSIVE, FULL, RESTART, TRUNCATE)."""
|
|
110
|
+
with self._connect() as conn:
|
|
111
|
+
row = conn.execute(f"PRAGMA wal_checkpoint({mode})").fetchone()
|
|
112
|
+
return (row[0], row[1], row[2]) if row else (0, 0, 0)
|
|
113
|
+
|
|
114
|
+
def _initialize(self) -> None:
|
|
115
|
+
with self._connect() as conn:
|
|
116
|
+
conn.executescript(
|
|
117
|
+
"""
|
|
118
|
+
CREATE TABLE IF NOT EXISTS runtime_tasks (
|
|
119
|
+
task_ref TEXT PRIMARY KEY,
|
|
120
|
+
objective TEXT NOT NULL,
|
|
121
|
+
task_state TEXT NOT NULL,
|
|
122
|
+
completion_evidence_refs_json TEXT NOT NULL,
|
|
123
|
+
requested_by_ref TEXT NOT NULL,
|
|
124
|
+
environment_ref TEXT NOT NULL,
|
|
125
|
+
scope_refs_json TEXT NOT NULL,
|
|
126
|
+
idempotency_key TEXT NOT NULL UNIQUE,
|
|
127
|
+
created_at TEXT NOT NULL,
|
|
128
|
+
updated_at TEXT NOT NULL,
|
|
129
|
+
completion_criteria_json TEXT NOT NULL,
|
|
130
|
+
evidence_criteria_json TEXT NOT NULL,
|
|
131
|
+
result_summary TEXT,
|
|
132
|
+
metadata_json TEXT NOT NULL,
|
|
133
|
+
depends_on_json TEXT NOT NULL DEFAULT '[]'
|
|
134
|
+
);
|
|
135
|
+
|
|
136
|
+
CREATE TABLE IF NOT EXISTS execution_packages (
|
|
137
|
+
package_id TEXT PRIMARY KEY,
|
|
138
|
+
task_ref TEXT NOT NULL UNIQUE,
|
|
139
|
+
objective TEXT NOT NULL,
|
|
140
|
+
requester_ref TEXT NOT NULL,
|
|
141
|
+
execution_actor_ref TEXT,
|
|
142
|
+
environment_ref TEXT NOT NULL,
|
|
143
|
+
environment_revision TEXT,
|
|
144
|
+
scope_refs_json TEXT NOT NULL,
|
|
145
|
+
modality_hints_json TEXT NOT NULL,
|
|
146
|
+
tool_hints_json TEXT NOT NULL,
|
|
147
|
+
completion_criteria_json TEXT NOT NULL,
|
|
148
|
+
evidence_criteria_json TEXT NOT NULL,
|
|
149
|
+
created_at TEXT NOT NULL,
|
|
150
|
+
status TEXT NOT NULL,
|
|
151
|
+
metadata_json TEXT NOT NULL,
|
|
152
|
+
FOREIGN KEY(task_ref) REFERENCES runtime_tasks(task_ref)
|
|
153
|
+
);
|
|
154
|
+
|
|
155
|
+
CREATE TABLE IF NOT EXISTS runtime_episodes (
|
|
156
|
+
episode_id TEXT PRIMARY KEY,
|
|
157
|
+
correlation_id TEXT NOT NULL,
|
|
158
|
+
state TEXT NOT NULL,
|
|
159
|
+
created_at TEXT NOT NULL,
|
|
160
|
+
updated_at TEXT NOT NULL,
|
|
161
|
+
task_ref TEXT,
|
|
162
|
+
actor_ref TEXT,
|
|
163
|
+
environment_ref TEXT,
|
|
164
|
+
environment_revision TEXT,
|
|
165
|
+
context_revision TEXT,
|
|
166
|
+
capability_revision TEXT,
|
|
167
|
+
metadata_json TEXT NOT NULL,
|
|
168
|
+
last_error_json TEXT
|
|
169
|
+
);
|
|
170
|
+
CREATE UNIQUE INDEX IF NOT EXISTS idx_runtime_episode_correlation
|
|
171
|
+
ON runtime_episodes(correlation_id, episode_id);
|
|
172
|
+
CREATE INDEX IF NOT EXISTS idx_runtime_episode_task
|
|
173
|
+
ON runtime_episodes(task_ref, created_at);
|
|
174
|
+
|
|
175
|
+
CREATE TABLE IF NOT EXISTS runtime_bindings (
|
|
176
|
+
binding_id TEXT PRIMARY KEY,
|
|
177
|
+
episode_id TEXT NOT NULL,
|
|
178
|
+
task_ref TEXT NOT NULL,
|
|
179
|
+
graph_revision TEXT NOT NULL,
|
|
180
|
+
binding_policy TEXT NOT NULL,
|
|
181
|
+
status TEXT NOT NULL,
|
|
182
|
+
bundle_json TEXT,
|
|
183
|
+
binding_record_json TEXT NOT NULL,
|
|
184
|
+
content_digest TEXT NOT NULL,
|
|
185
|
+
created_at TEXT NOT NULL,
|
|
186
|
+
FOREIGN KEY(episode_id) REFERENCES runtime_episodes(episode_id)
|
|
187
|
+
);
|
|
188
|
+
CREATE INDEX IF NOT EXISTS idx_runtime_bindings_episode
|
|
189
|
+
ON runtime_bindings(episode_id, created_at);
|
|
190
|
+
|
|
191
|
+
CREATE TABLE IF NOT EXISTS runtime_checkpoints (
|
|
192
|
+
checkpoint_id TEXT PRIMARY KEY,
|
|
193
|
+
episode_id TEXT NOT NULL,
|
|
194
|
+
context_revision TEXT,
|
|
195
|
+
capability_revision TEXT,
|
|
196
|
+
payload_json TEXT NOT NULL,
|
|
197
|
+
created_at TEXT NOT NULL,
|
|
198
|
+
FOREIGN KEY(episode_id) REFERENCES runtime_episodes(episode_id)
|
|
199
|
+
);
|
|
200
|
+
CREATE INDEX IF NOT EXISTS idx_runtime_checkpoints_episode
|
|
201
|
+
ON runtime_checkpoints(episode_id, created_at);
|
|
202
|
+
|
|
203
|
+
CREATE TABLE IF NOT EXISTS runtime_idempotency (
|
|
204
|
+
idempotency_key TEXT PRIMARY KEY,
|
|
205
|
+
episode_id TEXT NOT NULL,
|
|
206
|
+
status TEXT NOT NULL,
|
|
207
|
+
result_json TEXT,
|
|
208
|
+
created_at TEXT NOT NULL,
|
|
209
|
+
updated_at TEXT NOT NULL,
|
|
210
|
+
FOREIGN KEY(episode_id) REFERENCES runtime_episodes(episode_id)
|
|
211
|
+
);
|
|
212
|
+
|
|
213
|
+
CREATE TABLE IF NOT EXISTS runtime_events (
|
|
214
|
+
event_id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
215
|
+
episode_id TEXT NOT NULL,
|
|
216
|
+
event_type TEXT NOT NULL,
|
|
217
|
+
occurred_at TEXT NOT NULL,
|
|
218
|
+
correlation_id TEXT NOT NULL,
|
|
219
|
+
payload_json TEXT NOT NULL,
|
|
220
|
+
FOREIGN KEY(episode_id) REFERENCES runtime_episodes(episode_id)
|
|
221
|
+
);
|
|
222
|
+
CREATE INDEX IF NOT EXISTS idx_runtime_events_episode
|
|
223
|
+
ON runtime_events(episode_id, event_id);
|
|
224
|
+
"""
|
|
225
|
+
)
|
|
226
|
+
# Additive schema migration: pre-existing runtime databases created
|
|
227
|
+
# before the autonomous-continuation extension lack the dependency
|
|
228
|
+
# edge column. Adding it (with a JSON default) preserves all rows.
|
|
229
|
+
cols = {row["name"] for row in conn.execute("PRAGMA table_info(runtime_tasks)")}
|
|
230
|
+
if "depends_on_json" not in cols:
|
|
231
|
+
conn.execute(
|
|
232
|
+
"ALTER TABLE runtime_tasks ADD COLUMN depends_on_json TEXT NOT NULL DEFAULT '[]'"
|
|
233
|
+
)
|
|
234
|
+
|
|
235
|
+
def health(self) -> dict[str, Any]:
|
|
236
|
+
with self._connect() as conn:
|
|
237
|
+
version = conn.execute("select sqlite_version()").fetchone()[0]
|
|
238
|
+
conn.execute("select 1").fetchone()
|
|
239
|
+
return {"status": "ok", "store": "sqlite", "sqlite_version": version}
|
|
240
|
+
|
|
241
|
+
# ---- Task continuity -------------------------------------------------
|
|
242
|
+
|
|
243
|
+
def create_task(self, task: TaskRecord) -> TaskRecord:
|
|
244
|
+
with self._connect() as conn:
|
|
245
|
+
conn.execute(
|
|
246
|
+
"""INSERT INTO runtime_tasks (
|
|
247
|
+
task_ref, objective, task_state, completion_evidence_refs_json,
|
|
248
|
+
requested_by_ref, environment_ref, scope_refs_json,
|
|
249
|
+
idempotency_key, created_at, updated_at,
|
|
250
|
+
completion_criteria_json, evidence_criteria_json,
|
|
251
|
+
result_summary, metadata_json, depends_on_json
|
|
252
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)""",
|
|
253
|
+
(
|
|
254
|
+
task.task_ref,
|
|
255
|
+
task.objective,
|
|
256
|
+
task.task_state.value,
|
|
257
|
+
json.dumps(task.completion_evidence_refs, sort_keys=True),
|
|
258
|
+
task.requested_by_ref,
|
|
259
|
+
task.environment_ref,
|
|
260
|
+
json.dumps(task.scope_refs, sort_keys=True),
|
|
261
|
+
task.idempotency_key,
|
|
262
|
+
task.created_at,
|
|
263
|
+
task.updated_at,
|
|
264
|
+
json.dumps(task.completion_criteria, sort_keys=True),
|
|
265
|
+
json.dumps(task.evidence_criteria, sort_keys=True),
|
|
266
|
+
task.result_summary,
|
|
267
|
+
json.dumps(task.metadata, sort_keys=True),
|
|
268
|
+
json.dumps(sorted(set(task.depends_on)), sort_keys=True),
|
|
269
|
+
),
|
|
270
|
+
)
|
|
271
|
+
return task
|
|
272
|
+
|
|
273
|
+
def _task_from_row(self, row: sqlite3.Row) -> TaskRecord:
|
|
274
|
+
return TaskRecord.from_dict({
|
|
275
|
+
"task_ref": row["task_ref"],
|
|
276
|
+
"objective": row["objective"],
|
|
277
|
+
"task_state": row["task_state"],
|
|
278
|
+
"completion_evidence_refs": json.loads(row["completion_evidence_refs_json"]),
|
|
279
|
+
"requested_by_ref": row["requested_by_ref"],
|
|
280
|
+
"environment_ref": row["environment_ref"],
|
|
281
|
+
"scope_refs": json.loads(row["scope_refs_json"]),
|
|
282
|
+
"idempotency_key": row["idempotency_key"],
|
|
283
|
+
"created_at": row["created_at"],
|
|
284
|
+
"updated_at": row["updated_at"],
|
|
285
|
+
"completion_criteria": json.loads(row["completion_criteria_json"]),
|
|
286
|
+
"evidence_criteria": json.loads(row["evidence_criteria_json"]),
|
|
287
|
+
"result_summary": row["result_summary"],
|
|
288
|
+
"metadata": json.loads(row["metadata_json"]),
|
|
289
|
+
"depends_on": json.loads(row["depends_on_json"]),
|
|
290
|
+
})
|
|
291
|
+
|
|
292
|
+
def get_task(self, task_ref: str) -> TaskRecord | None:
|
|
293
|
+
with self._connect() as conn:
|
|
294
|
+
row = conn.execute(
|
|
295
|
+
"SELECT * FROM runtime_tasks WHERE task_ref = ?", (task_ref,)
|
|
296
|
+
).fetchone()
|
|
297
|
+
return self._task_from_row(row) if row is not None else None
|
|
298
|
+
|
|
299
|
+
def get_task_by_idempotency_key(self, key: str) -> TaskRecord | None:
|
|
300
|
+
with self._connect() as conn:
|
|
301
|
+
row = conn.execute(
|
|
302
|
+
"SELECT * FROM runtime_tasks WHERE idempotency_key = ?", (key,)
|
|
303
|
+
).fetchone()
|
|
304
|
+
return self._task_from_row(row) if row is not None else None
|
|
305
|
+
|
|
306
|
+
def list_tasks(self) -> list[TaskRecord]:
|
|
307
|
+
"""All durable tasks in deterministic (created_at, task_ref) order.
|
|
308
|
+
|
|
309
|
+
The continuation engine enumerates the authorized task pool from this
|
|
310
|
+
method; ordering is stable so scheduling decisions are reproducible
|
|
311
|
+
across agents and processes (spec §5, §23).
|
|
312
|
+
"""
|
|
313
|
+
with self._connect() as conn:
|
|
314
|
+
rows = conn.execute(
|
|
315
|
+
"SELECT * FROM runtime_tasks ORDER BY created_at, task_ref"
|
|
316
|
+
).fetchall()
|
|
317
|
+
return [self._task_from_row(row) for row in rows]
|
|
318
|
+
|
|
319
|
+
def set_task_state(self, task_ref: str, state: TaskState) -> TaskRecord:
|
|
320
|
+
with self._connect() as conn:
|
|
321
|
+
cur = conn.execute(
|
|
322
|
+
"UPDATE runtime_tasks SET task_state = ?, updated_at = ? WHERE task_ref = ?",
|
|
323
|
+
(state.value, utc_now(), task_ref),
|
|
324
|
+
)
|
|
325
|
+
if cur.rowcount != 1:
|
|
326
|
+
raise KeyError(f"unknown task: {task_ref}")
|
|
327
|
+
result = self.get_task(task_ref)
|
|
328
|
+
assert result is not None
|
|
329
|
+
return result
|
|
330
|
+
|
|
331
|
+
def complete_task(
|
|
332
|
+
self,
|
|
333
|
+
task_ref: str,
|
|
334
|
+
*,
|
|
335
|
+
evidence_refs: list[str],
|
|
336
|
+
result_summary: str,
|
|
337
|
+
) -> TaskRecord:
|
|
338
|
+
with self._connect() as conn:
|
|
339
|
+
cur = conn.execute(
|
|
340
|
+
"""UPDATE runtime_tasks
|
|
341
|
+
SET task_state = ?, completion_evidence_refs_json = ?,
|
|
342
|
+
result_summary = ?, updated_at = ?
|
|
343
|
+
WHERE task_ref = ?""",
|
|
344
|
+
(
|
|
345
|
+
TaskState.COMPLETED.value,
|
|
346
|
+
json.dumps(sorted(set(evidence_refs)), sort_keys=True),
|
|
347
|
+
result_summary,
|
|
348
|
+
utc_now(),
|
|
349
|
+
task_ref,
|
|
350
|
+
),
|
|
351
|
+
)
|
|
352
|
+
if cur.rowcount != 1:
|
|
353
|
+
raise KeyError(f"unknown task: {task_ref}")
|
|
354
|
+
result = self.get_task(task_ref)
|
|
355
|
+
assert result is not None
|
|
356
|
+
return result
|
|
357
|
+
|
|
358
|
+
def link_obligation(self, task_ref: str, obligation_id: str) -> TaskRecord:
|
|
359
|
+
"""Back-reference the obligation this runtime task executes (LOOP-2).
|
|
360
|
+
|
|
361
|
+
Converge "what to do" behind the obligation spine (DEC-2026-0920-08): a
|
|
362
|
+
runtime task becomes an *execution projection* of an obligation, stored
|
|
363
|
+
in the task's metadata so no schema migration is needed. The convergence
|
|
364
|
+
checker (tools/cosmos_objective_convergence.py) uses this link to detect
|
|
365
|
+
drift between a task's execution state and its obligation's state.
|
|
366
|
+
"""
|
|
367
|
+
task = self.get_task(task_ref)
|
|
368
|
+
if task is None:
|
|
369
|
+
raise KeyError(f"unknown task: {task_ref}")
|
|
370
|
+
metadata = dict(task.metadata)
|
|
371
|
+
metadata["obligation_ref"] = obligation_id
|
|
372
|
+
with self._connect() as conn:
|
|
373
|
+
conn.execute(
|
|
374
|
+
"UPDATE runtime_tasks SET metadata_json = ?, updated_at = ? WHERE task_ref = ?",
|
|
375
|
+
(json.dumps(metadata, sort_keys=True), utc_now(), task_ref),
|
|
376
|
+
)
|
|
377
|
+
result = self.get_task(task_ref)
|
|
378
|
+
assert result is not None
|
|
379
|
+
return result
|
|
380
|
+
|
|
381
|
+
# ---- Execution packages ---------------------------------------------
|
|
382
|
+
|
|
383
|
+
def create_execution_package(self, package: ExecutionPackage) -> ExecutionPackage:
|
|
384
|
+
with self._connect() as conn:
|
|
385
|
+
conn.execute(
|
|
386
|
+
"""INSERT INTO execution_packages (
|
|
387
|
+
package_id, task_ref, objective, requester_ref, execution_actor_ref,
|
|
388
|
+
environment_ref, environment_revision, scope_refs_json,
|
|
389
|
+
modality_hints_json, tool_hints_json, completion_criteria_json,
|
|
390
|
+
evidence_criteria_json, created_at, status, metadata_json
|
|
391
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)""",
|
|
392
|
+
(
|
|
393
|
+
package.package_id,
|
|
394
|
+
package.task_ref,
|
|
395
|
+
package.objective,
|
|
396
|
+
package.requester_ref,
|
|
397
|
+
package.execution_actor_ref,
|
|
398
|
+
package.environment_ref,
|
|
399
|
+
package.environment_revision,
|
|
400
|
+
json.dumps(package.scope_refs, sort_keys=True),
|
|
401
|
+
json.dumps(package.modality_hints, sort_keys=True),
|
|
402
|
+
json.dumps(package.tool_hints, sort_keys=True),
|
|
403
|
+
json.dumps(package.completion_criteria, sort_keys=True),
|
|
404
|
+
json.dumps(package.evidence_criteria, sort_keys=True),
|
|
405
|
+
package.created_at,
|
|
406
|
+
package.status,
|
|
407
|
+
json.dumps(package.metadata, sort_keys=True),
|
|
408
|
+
),
|
|
409
|
+
)
|
|
410
|
+
return package
|
|
411
|
+
|
|
412
|
+
def _package_from_row(self, row: sqlite3.Row) -> ExecutionPackage:
|
|
413
|
+
return ExecutionPackage(
|
|
414
|
+
package_id=row["package_id"],
|
|
415
|
+
task_ref=row["task_ref"],
|
|
416
|
+
objective=row["objective"],
|
|
417
|
+
requester_ref=row["requester_ref"],
|
|
418
|
+
execution_actor_ref=row["execution_actor_ref"],
|
|
419
|
+
environment_ref=row["environment_ref"],
|
|
420
|
+
environment_revision=row["environment_revision"],
|
|
421
|
+
scope_refs=json.loads(row["scope_refs_json"]),
|
|
422
|
+
modality_hints=json.loads(row["modality_hints_json"]),
|
|
423
|
+
tool_hints=json.loads(row["tool_hints_json"]),
|
|
424
|
+
completion_criteria=json.loads(row["completion_criteria_json"]),
|
|
425
|
+
evidence_criteria=json.loads(row["evidence_criteria_json"]),
|
|
426
|
+
created_at=row["created_at"],
|
|
427
|
+
status=row["status"],
|
|
428
|
+
metadata=json.loads(row["metadata_json"]),
|
|
429
|
+
)
|
|
430
|
+
|
|
431
|
+
def get_execution_package(self, package_id: str) -> ExecutionPackage | None:
|
|
432
|
+
with self._connect() as conn:
|
|
433
|
+
row = conn.execute(
|
|
434
|
+
"SELECT * FROM execution_packages WHERE package_id = ?", (package_id,)
|
|
435
|
+
).fetchone()
|
|
436
|
+
return self._package_from_row(row) if row is not None else None
|
|
437
|
+
|
|
438
|
+
def get_execution_package_for_task(self, task_ref: str) -> ExecutionPackage | None:
|
|
439
|
+
with self._connect() as conn:
|
|
440
|
+
row = conn.execute(
|
|
441
|
+
"SELECT * FROM execution_packages WHERE task_ref = ?", (task_ref,)
|
|
442
|
+
).fetchone()
|
|
443
|
+
return self._package_from_row(row) if row is not None else None
|
|
444
|
+
|
|
445
|
+
def set_execution_package_status(self, task_ref: str, status: str) -> ExecutionPackage:
|
|
446
|
+
with self._connect() as conn:
|
|
447
|
+
cur = conn.execute(
|
|
448
|
+
"UPDATE execution_packages SET status = ? WHERE task_ref = ?",
|
|
449
|
+
(status, task_ref),
|
|
450
|
+
)
|
|
451
|
+
if cur.rowcount != 1:
|
|
452
|
+
raise KeyError(f"no execution package for task: {task_ref}")
|
|
453
|
+
result = self.get_execution_package_for_task(task_ref)
|
|
454
|
+
assert result is not None
|
|
455
|
+
return result
|
|
456
|
+
|
|
457
|
+
# ---- Runtime episodes ------------------------------------------------
|
|
458
|
+
|
|
459
|
+
def create_episode(self, episode: ExecutionEpisode) -> ExecutionEpisode:
|
|
460
|
+
with self._connect() as conn:
|
|
461
|
+
conn.execute(
|
|
462
|
+
"""INSERT INTO runtime_episodes (
|
|
463
|
+
episode_id, correlation_id, state, created_at, updated_at,
|
|
464
|
+
task_ref, actor_ref, environment_ref, environment_revision,
|
|
465
|
+
context_revision, capability_revision, metadata_json, last_error_json
|
|
466
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)""",
|
|
467
|
+
(
|
|
468
|
+
episode.episode_id,
|
|
469
|
+
episode.correlation_id,
|
|
470
|
+
episode.state.value,
|
|
471
|
+
episode.created_at,
|
|
472
|
+
episode.updated_at,
|
|
473
|
+
episode.task_ref,
|
|
474
|
+
episode.actor_ref,
|
|
475
|
+
episode.environment_ref,
|
|
476
|
+
episode.environment_revision,
|
|
477
|
+
episode.context_revision,
|
|
478
|
+
episode.capability_revision,
|
|
479
|
+
json.dumps(episode.metadata, sort_keys=True),
|
|
480
|
+
json.dumps(episode.last_error.to_dict(), sort_keys=True) if episode.last_error else None,
|
|
481
|
+
),
|
|
482
|
+
)
|
|
483
|
+
return episode
|
|
484
|
+
|
|
485
|
+
def _episode_from_row(self, row: sqlite3.Row) -> ExecutionEpisode:
|
|
486
|
+
error = json.loads(row["last_error_json"]) if row["last_error_json"] else None
|
|
487
|
+
return ExecutionEpisode.from_dict({
|
|
488
|
+
"episode_id": row["episode_id"],
|
|
489
|
+
"correlation_id": row["correlation_id"],
|
|
490
|
+
"state": row["state"],
|
|
491
|
+
"created_at": row["created_at"],
|
|
492
|
+
"updated_at": row["updated_at"],
|
|
493
|
+
"task_ref": row["task_ref"],
|
|
494
|
+
"actor_ref": row["actor_ref"],
|
|
495
|
+
"environment_ref": row["environment_ref"],
|
|
496
|
+
"environment_revision": row["environment_revision"],
|
|
497
|
+
"context_revision": row["context_revision"],
|
|
498
|
+
"capability_revision": row["capability_revision"],
|
|
499
|
+
"metadata": json.loads(row["metadata_json"]),
|
|
500
|
+
"last_error": error,
|
|
501
|
+
})
|
|
502
|
+
|
|
503
|
+
def get_episode(self, episode_id: str) -> ExecutionEpisode | None:
|
|
504
|
+
with self._connect() as conn:
|
|
505
|
+
row = conn.execute(
|
|
506
|
+
"SELECT * FROM runtime_episodes WHERE episode_id = ?", (episode_id,)
|
|
507
|
+
).fetchone()
|
|
508
|
+
return self._episode_from_row(row) if row is not None else None
|
|
509
|
+
|
|
510
|
+
def get_latest_episode_for_task(self, task_ref: str) -> ExecutionEpisode | None:
|
|
511
|
+
with self._connect() as conn:
|
|
512
|
+
row = conn.execute(
|
|
513
|
+
"""SELECT * FROM runtime_episodes
|
|
514
|
+
WHERE task_ref = ?
|
|
515
|
+
ORDER BY created_at DESC, episode_id DESC
|
|
516
|
+
LIMIT 1""",
|
|
517
|
+
(task_ref,),
|
|
518
|
+
).fetchone()
|
|
519
|
+
return self._episode_from_row(row) if row is not None else None
|
|
520
|
+
|
|
521
|
+
def transition_episode(
|
|
522
|
+
self,
|
|
523
|
+
episode_id: str,
|
|
524
|
+
target: ExecutionState,
|
|
525
|
+
*,
|
|
526
|
+
error: RuntimeErrorInfo | None = None,
|
|
527
|
+
expected_state: ExecutionState | None = None,
|
|
528
|
+
) -> ExecutionEpisode:
|
|
529
|
+
with self._connect() as conn:
|
|
530
|
+
row = conn.execute(
|
|
531
|
+
"SELECT * FROM runtime_episodes WHERE episode_id = ?", (episode_id,)
|
|
532
|
+
).fetchone()
|
|
533
|
+
if row is None:
|
|
534
|
+
raise KeyError(f"unknown episode: {episode_id}")
|
|
535
|
+
current = ExecutionState(row["state"])
|
|
536
|
+
if expected_state is not None and current != expected_state:
|
|
537
|
+
raise ValueError(
|
|
538
|
+
f"runtime state conflict: expected {expected_state.value}, got {current.value}"
|
|
539
|
+
)
|
|
540
|
+
validate_transition(current, target)
|
|
541
|
+
# Invariant 1 (LOOP-1 / DEC-2026-0920-07): an episode may not be
|
|
542
|
+
# completed until its result has been observed. Success (COMPLETED)
|
|
543
|
+
# requires a recorded result-observation event; FAILED/CANCELLED are
|
|
544
|
+
# exempt (failure is itself the observed result; Invariant 9).
|
|
545
|
+
if target == ExecutionState.COMPLETED and not self._has_result_observation(conn, episode_id):
|
|
546
|
+
raise ResultObservationRequired(
|
|
547
|
+
f"episode {episode_id} cannot transition to COMPLETED without a recorded "
|
|
548
|
+
f"result observation (Invariant 1); call record_result_observation() first"
|
|
549
|
+
)
|
|
550
|
+
updated_at = utc_now()
|
|
551
|
+
conn.execute(
|
|
552
|
+
"""UPDATE runtime_episodes
|
|
553
|
+
SET state = ?, updated_at = ?, last_error_json = ?
|
|
554
|
+
WHERE episode_id = ?""",
|
|
555
|
+
(
|
|
556
|
+
target.value,
|
|
557
|
+
updated_at,
|
|
558
|
+
json.dumps(error.to_dict(), sort_keys=True) if error else None,
|
|
559
|
+
episode_id,
|
|
560
|
+
),
|
|
561
|
+
)
|
|
562
|
+
result = self.get_episode(episode_id)
|
|
563
|
+
assert result is not None
|
|
564
|
+
return result
|
|
565
|
+
|
|
566
|
+
def set_episode_context_revision(self, episode_id: str, revision: str) -> ExecutionEpisode:
|
|
567
|
+
with self._connect() as conn:
|
|
568
|
+
cur = conn.execute(
|
|
569
|
+
"UPDATE runtime_episodes SET context_revision = ?, updated_at = ? WHERE episode_id = ?",
|
|
570
|
+
(revision, utc_now(), episode_id),
|
|
571
|
+
)
|
|
572
|
+
if cur.rowcount != 1:
|
|
573
|
+
raise KeyError(f"unknown episode: {episode_id}")
|
|
574
|
+
result = self.get_episode(episode_id)
|
|
575
|
+
assert result is not None
|
|
576
|
+
return result
|
|
577
|
+
|
|
578
|
+
def set_episode_capability_revision(self, episode_id: str, revision: str) -> ExecutionEpisode:
|
|
579
|
+
with self._connect() as conn:
|
|
580
|
+
cur = conn.execute(
|
|
581
|
+
"UPDATE runtime_episodes SET capability_revision = ?, updated_at = ? WHERE episode_id = ?",
|
|
582
|
+
(revision, utc_now(), episode_id),
|
|
583
|
+
)
|
|
584
|
+
if cur.rowcount != 1:
|
|
585
|
+
raise KeyError(f"unknown episode: {episode_id}")
|
|
586
|
+
result = self.get_episode(episode_id)
|
|
587
|
+
assert result is not None
|
|
588
|
+
return result
|
|
589
|
+
|
|
590
|
+
# ---- Binding snapshots ----------------------------------------------
|
|
591
|
+
|
|
592
|
+
def save_binding_snapshot(
|
|
593
|
+
self,
|
|
594
|
+
*,
|
|
595
|
+
binding_id: str,
|
|
596
|
+
episode_id: str,
|
|
597
|
+
task_ref: str,
|
|
598
|
+
graph_revision: str,
|
|
599
|
+
binding_policy: str,
|
|
600
|
+
status: str,
|
|
601
|
+
bundle: dict[str, Any] | None,
|
|
602
|
+
binding_record: dict[str, Any],
|
|
603
|
+
content_digest: str,
|
|
604
|
+
created_at: str,
|
|
605
|
+
) -> None:
|
|
606
|
+
with self._connect() as conn:
|
|
607
|
+
conn.execute(
|
|
608
|
+
"""INSERT OR REPLACE INTO runtime_bindings (
|
|
609
|
+
binding_id, episode_id, task_ref, graph_revision, binding_policy,
|
|
610
|
+
status, bundle_json, binding_record_json, content_digest, created_at
|
|
611
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)""",
|
|
612
|
+
(
|
|
613
|
+
binding_id,
|
|
614
|
+
episode_id,
|
|
615
|
+
task_ref,
|
|
616
|
+
graph_revision,
|
|
617
|
+
binding_policy,
|
|
618
|
+
status,
|
|
619
|
+
json.dumps(bundle, sort_keys=True) if bundle is not None else None,
|
|
620
|
+
json.dumps(binding_record, sort_keys=True),
|
|
621
|
+
content_digest,
|
|
622
|
+
created_at,
|
|
623
|
+
),
|
|
624
|
+
)
|
|
625
|
+
|
|
626
|
+
def get_latest_binding(self, episode_id: str) -> dict[str, Any] | None:
|
|
627
|
+
with self._connect() as conn:
|
|
628
|
+
row = conn.execute(
|
|
629
|
+
"""SELECT * FROM runtime_bindings
|
|
630
|
+
WHERE episode_id = ?
|
|
631
|
+
ORDER BY created_at DESC, binding_id DESC
|
|
632
|
+
LIMIT 1""",
|
|
633
|
+
(episode_id,),
|
|
634
|
+
).fetchone()
|
|
635
|
+
if row is None:
|
|
636
|
+
return None
|
|
637
|
+
return {
|
|
638
|
+
"binding_id": row["binding_id"],
|
|
639
|
+
"episode_id": row["episode_id"],
|
|
640
|
+
"task_ref": row["task_ref"],
|
|
641
|
+
"graph_revision": row["graph_revision"],
|
|
642
|
+
"binding_policy": row["binding_policy"],
|
|
643
|
+
"status": row["status"],
|
|
644
|
+
"bundle": json.loads(row["bundle_json"]) if row["bundle_json"] else None,
|
|
645
|
+
"binding_record": json.loads(row["binding_record_json"]),
|
|
646
|
+
"content_digest": row["content_digest"],
|
|
647
|
+
"created_at": row["created_at"],
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
# ---- Resilience state -----------------------------------------------
|
|
651
|
+
|
|
652
|
+
def save_checkpoint(self, checkpoint: dict[str, Any]) -> None:
|
|
653
|
+
with self._connect() as conn:
|
|
654
|
+
conn.execute(
|
|
655
|
+
"""INSERT INTO runtime_checkpoints (
|
|
656
|
+
checkpoint_id, episode_id, context_revision, capability_revision,
|
|
657
|
+
payload_json, created_at
|
|
658
|
+
) VALUES (?, ?, ?, ?, ?, ?)""",
|
|
659
|
+
(
|
|
660
|
+
checkpoint["checkpoint_id"],
|
|
661
|
+
checkpoint["episode_id"],
|
|
662
|
+
checkpoint.get("context_revision"),
|
|
663
|
+
checkpoint.get("capability_revision"),
|
|
664
|
+
json.dumps(checkpoint.get("payload", {}), sort_keys=True),
|
|
665
|
+
checkpoint["created_at"],
|
|
666
|
+
),
|
|
667
|
+
)
|
|
668
|
+
|
|
669
|
+
def get_latest_checkpoint(self, episode_id: str) -> dict[str, Any] | None:
|
|
670
|
+
with self._connect() as conn:
|
|
671
|
+
row = conn.execute(
|
|
672
|
+
"""SELECT * FROM runtime_checkpoints
|
|
673
|
+
WHERE episode_id = ?
|
|
674
|
+
ORDER BY created_at DESC, checkpoint_id DESC
|
|
675
|
+
LIMIT 1""",
|
|
676
|
+
(episode_id,),
|
|
677
|
+
).fetchone()
|
|
678
|
+
if row is None:
|
|
679
|
+
return None
|
|
680
|
+
return {
|
|
681
|
+
"checkpoint_id": row["checkpoint_id"],
|
|
682
|
+
"episode_id": row["episode_id"],
|
|
683
|
+
"context_revision": row["context_revision"],
|
|
684
|
+
"capability_revision": row["capability_revision"],
|
|
685
|
+
"payload": json.loads(row["payload_json"]),
|
|
686
|
+
"created_at": row["created_at"],
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
def claim_idempotency(self, key: str, episode_id: str) -> dict[str, Any]:
|
|
690
|
+
now = utc_now()
|
|
691
|
+
with self._connect() as conn:
|
|
692
|
+
cur = conn.execute(
|
|
693
|
+
"""INSERT OR IGNORE INTO runtime_idempotency
|
|
694
|
+
(idempotency_key, episode_id, status, result_json, created_at, updated_at)
|
|
695
|
+
VALUES (?, ?, 'pending', NULL, ?, ?)""",
|
|
696
|
+
(key, episode_id, now, now),
|
|
697
|
+
)
|
|
698
|
+
claimed = cur.rowcount == 1
|
|
699
|
+
row = conn.execute(
|
|
700
|
+
"SELECT * FROM runtime_idempotency WHERE idempotency_key = ?",
|
|
701
|
+
(key,),
|
|
702
|
+
).fetchone()
|
|
703
|
+
assert row is not None
|
|
704
|
+
if row["episode_id"] != episode_id:
|
|
705
|
+
raise ValueError("idempotency key belongs to another episode")
|
|
706
|
+
return {
|
|
707
|
+
"claimed": claimed,
|
|
708
|
+
"status": row["status"],
|
|
709
|
+
"result": json.loads(row["result_json"]) if row["result_json"] else None,
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
def complete_idempotency(self, key: str, result: Any) -> None:
|
|
713
|
+
with self._connect() as conn:
|
|
714
|
+
cur = conn.execute(
|
|
715
|
+
"""UPDATE runtime_idempotency
|
|
716
|
+
SET status = 'completed', result_json = ?, updated_at = ?
|
|
717
|
+
WHERE idempotency_key = ? AND status = 'pending'""",
|
|
718
|
+
(json.dumps(result, sort_keys=True), utc_now(), key),
|
|
719
|
+
)
|
|
720
|
+
if cur.rowcount != 1:
|
|
721
|
+
raise ValueError("idempotency entry is not pending")
|
|
722
|
+
|
|
723
|
+
def mark_idempotency_indeterminate(self, key: str) -> None:
|
|
724
|
+
with self._connect() as conn:
|
|
725
|
+
cur = conn.execute(
|
|
726
|
+
"""UPDATE runtime_idempotency
|
|
727
|
+
SET status = 'indeterminate', updated_at = ?
|
|
728
|
+
WHERE idempotency_key = ? AND status = 'pending'""",
|
|
729
|
+
(utc_now(), key),
|
|
730
|
+
)
|
|
731
|
+
if cur.rowcount != 1:
|
|
732
|
+
raise ValueError("idempotency entry is not pending")
|
|
733
|
+
|
|
734
|
+
# ---- Runtime event stream -------------------------------------------
|
|
735
|
+
|
|
736
|
+
def append_event(self, event: RuntimeEvent) -> RuntimeEvent:
|
|
737
|
+
with self._connect() as conn:
|
|
738
|
+
cur = conn.execute(
|
|
739
|
+
"""INSERT INTO runtime_events
|
|
740
|
+
(episode_id, event_type, occurred_at, correlation_id, payload_json)
|
|
741
|
+
VALUES (?, ?, ?, ?, ?)""",
|
|
742
|
+
(
|
|
743
|
+
event.episode_id,
|
|
744
|
+
event.event_type,
|
|
745
|
+
event.occurred_at,
|
|
746
|
+
event.correlation_id,
|
|
747
|
+
json.dumps(event.payload, sort_keys=True),
|
|
748
|
+
),
|
|
749
|
+
)
|
|
750
|
+
event.event_id = int(cur.lastrowid)
|
|
751
|
+
return event
|
|
752
|
+
|
|
753
|
+
def record_result_observation(
|
|
754
|
+
self,
|
|
755
|
+
episode_id: str,
|
|
756
|
+
*,
|
|
757
|
+
correlation_id: str,
|
|
758
|
+
summary: str = "",
|
|
759
|
+
evidence_refs: list[str] | None = None,
|
|
760
|
+
verified: bool | None = None,
|
|
761
|
+
) -> RuntimeEvent:
|
|
762
|
+
"""Record that this episode's result was observed (Invariant 1, LOOP-1).
|
|
763
|
+
|
|
764
|
+
The canonical, single way to satisfy the completion precondition enforced
|
|
765
|
+
by ``transition_episode``. Carries the observed result summary and any
|
|
766
|
+
evidence refs so the observation is auditable, not a bare flag.
|
|
767
|
+
"""
|
|
768
|
+
payload: dict[str, Any] = {"summary": summary, "evidence_refs": list(evidence_refs or [])}
|
|
769
|
+
if verified is not None:
|
|
770
|
+
payload["verified"] = verified
|
|
771
|
+
return self.append_event(RuntimeEvent(
|
|
772
|
+
episode_id=episode_id,
|
|
773
|
+
event_type=RESULT_OBSERVED_EVENT,
|
|
774
|
+
occurred_at=utc_now(),
|
|
775
|
+
correlation_id=correlation_id,
|
|
776
|
+
payload=payload,
|
|
777
|
+
))
|
|
778
|
+
|
|
779
|
+
def _has_result_observation(self, conn: sqlite3.Connection, episode_id: str) -> bool:
|
|
780
|
+
row = conn.execute(
|
|
781
|
+
"SELECT 1 FROM runtime_events WHERE episode_id = ? AND event_type = ? LIMIT 1",
|
|
782
|
+
(episode_id, RESULT_OBSERVED_EVENT),
|
|
783
|
+
).fetchone()
|
|
784
|
+
return row is not None
|
|
785
|
+
|
|
786
|
+
def list_events(self, episode_id: str) -> list[RuntimeEvent]:
|
|
787
|
+
with self._connect() as conn:
|
|
788
|
+
rows = conn.execute(
|
|
789
|
+
"SELECT * FROM runtime_events WHERE episode_id = ? ORDER BY event_id",
|
|
790
|
+
(episode_id,),
|
|
791
|
+
).fetchall()
|
|
792
|
+
return [
|
|
793
|
+
RuntimeEvent(
|
|
794
|
+
event_id=row["event_id"],
|
|
795
|
+
episode_id=row["episode_id"],
|
|
796
|
+
event_type=row["event_type"],
|
|
797
|
+
occurred_at=row["occurred_at"],
|
|
798
|
+
correlation_id=row["correlation_id"],
|
|
799
|
+
payload=json.loads(row["payload_json"]),
|
|
800
|
+
)
|
|
801
|
+
for row in rows
|
|
802
|
+
]
|