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,528 @@
|
|
|
1
|
+
"""Unattended safety: `cosmos pause`, budget caps, and the Claude Code hook that enforces them."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
import os
|
|
7
|
+
import sys
|
|
8
|
+
import tempfile
|
|
9
|
+
import time
|
|
10
|
+
import unittest
|
|
11
|
+
from pathlib import Path
|
|
12
|
+
from unittest import mock
|
|
13
|
+
|
|
14
|
+
from tools import cosmos_proc as subprocess
|
|
15
|
+
from tools import cosmos_safety as safety
|
|
16
|
+
from tools.cosmos_home_guard import home_snapshot, home_write_guard # X-003: beside the repo-write guard
|
|
17
|
+
|
|
18
|
+
ROOT = Path(__file__).resolve().parents[2]
|
|
19
|
+
HOOK = ROOT / "tools" / "cosmos_safety.py"
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class SafetyTests(unittest.TestCase):
|
|
23
|
+
def setUp(self) -> None:
|
|
24
|
+
self._tmp = tempfile.TemporaryDirectory(prefix="cosmos-safety-")
|
|
25
|
+
self.home = Path(self._tmp.name)
|
|
26
|
+
self._saved = os.environ.get(safety.HOME_ENV)
|
|
27
|
+
os.environ[safety.HOME_ENV] = str(self.home)
|
|
28
|
+
|
|
29
|
+
def tearDown(self) -> None:
|
|
30
|
+
if self._saved is None:
|
|
31
|
+
os.environ.pop(safety.HOME_ENV, None)
|
|
32
|
+
else:
|
|
33
|
+
os.environ[safety.HOME_ENV] = self._saved
|
|
34
|
+
self._tmp.cleanup()
|
|
35
|
+
|
|
36
|
+
def run_hook(self, payload: dict) -> tuple[int, str]:
|
|
37
|
+
env = dict(os.environ, **{safety.HOME_ENV: str(self.home)})
|
|
38
|
+
done = subprocess.run([sys.executable, str(HOOK)], input=json.dumps(payload), capture_output=True, text=True,
|
|
39
|
+
env=env, timeout=60)
|
|
40
|
+
return done.returncode, done.stdout
|
|
41
|
+
|
|
42
|
+
def test_nothing_set_allows_everything_and_writes_nothing(self) -> None:
|
|
43
|
+
code, out = self.run_hook({"session_id": "s1", "tool_name": "Bash"})
|
|
44
|
+
self.assertEqual((code, out), (0, ""))
|
|
45
|
+
self.assertEqual(list(self.home.iterdir()), []) # no cap, no counting, no files
|
|
46
|
+
|
|
47
|
+
def test_pause_denies_the_hook_until_resume_and_names_the_reason(self) -> None:
|
|
48
|
+
safety.pause("deploying by hand", by="Harvey")
|
|
49
|
+
code, out = self.run_hook({"session_id": "s1", "tool_name": "Bash"})
|
|
50
|
+
self.assertEqual(code, 0)
|
|
51
|
+
reply = json.loads(out)["hookSpecificOutput"]
|
|
52
|
+
self.assertEqual((reply["hookEventName"], reply["permissionDecision"]), ("PreToolUse", "deny"))
|
|
53
|
+
self.assertIn("paused by the owner", reply["permissionDecisionReason"])
|
|
54
|
+
self.assertIn("deploying by hand", reply["permissionDecisionReason"])
|
|
55
|
+
self.assertIn("cosmos resume", reply["permissionDecisionReason"])
|
|
56
|
+
self.assertTrue(safety.resume()["was_paused"])
|
|
57
|
+
self.assertEqual(self.run_hook({"session_id": "s1", "tool_name": "Bash"}), (0, ""))
|
|
58
|
+
|
|
59
|
+
def test_an_unreadable_pause_file_still_pauses(self) -> None:
|
|
60
|
+
(self.home / "pause.json").write_text("{not json", encoding="utf-8")
|
|
61
|
+
_code, out = self.run_hook({"session_id": "s1"})
|
|
62
|
+
self.assertEqual(json.loads(out)["hookSpecificOutput"]["permissionDecision"], "deny")
|
|
63
|
+
|
|
64
|
+
def test_a_broken_payload_fails_open(self) -> None:
|
|
65
|
+
env = dict(os.environ, **{safety.HOME_ENV: str(self.home)})
|
|
66
|
+
done = subprocess.run([sys.executable, str(HOOK)], input="not json at all", capture_output=True, text=True,
|
|
67
|
+
env=env, timeout=60)
|
|
68
|
+
self.assertEqual((done.returncode, done.stdout), (0, ""))
|
|
69
|
+
|
|
70
|
+
def test_session_cap_denies_after_the_cap_and_only_that_session(self) -> None:
|
|
71
|
+
safety.set_limits(actions_per_session=3)
|
|
72
|
+
for n in range(3):
|
|
73
|
+
self.assertIsNone(safety.decision({"session_id": "a"}), n)
|
|
74
|
+
denied = safety.decision({"session_id": "a"})
|
|
75
|
+
self.assertIn("budget reached", denied)
|
|
76
|
+
self.assertIn("3 per session", denied)
|
|
77
|
+
self.assertIsNone(safety.decision({"session_id": "b"})) # another session has its own count
|
|
78
|
+
|
|
79
|
+
def test_day_cap_counts_every_session(self) -> None:
|
|
80
|
+
safety.set_limits(actions_per_day=2)
|
|
81
|
+
self.assertIsNone(safety.decision({"session_id": "a"}))
|
|
82
|
+
self.assertIsNone(safety.decision({"session_id": "b"}))
|
|
83
|
+
self.assertIn("per day", safety.decision({"session_id": "c"}))
|
|
84
|
+
|
|
85
|
+
def test_minutes_cap_uses_the_session_start(self) -> None:
|
|
86
|
+
safety.set_limits(minutes_per_session=10)
|
|
87
|
+
start = time.time() - 11 * 60
|
|
88
|
+
self.assertIsNone(safety.over_budget("m", now=start)) # the first action starts the clock
|
|
89
|
+
self.assertIn("minutes", safety.over_budget("m", now=start + 11 * 60))
|
|
90
|
+
|
|
91
|
+
def test_caps_are_kept_between_sets_validated_and_cleared(self) -> None:
|
|
92
|
+
safety.set_limits(actions_per_session=5)
|
|
93
|
+
safety.set_limits(minutes_per_session=30)
|
|
94
|
+
self.assertEqual(safety.limits(), {"actions_per_session": 5, "minutes_per_session": 30, "actions_per_day": None})
|
|
95
|
+
with self.assertRaises(ValueError):
|
|
96
|
+
safety.set_limits(actions_per_day=0)
|
|
97
|
+
safety.clear_limits()
|
|
98
|
+
self.assertEqual(set(safety.limits().values()), {None})
|
|
99
|
+
|
|
100
|
+
def test_parallel_hooks_lose_no_count_and_the_cap_holds_exactly(self) -> None:
|
|
101
|
+
safety.set_limits(actions_per_session=5)
|
|
102
|
+
env = dict(os.environ, **{safety.HOME_ENV: str(self.home)})
|
|
103
|
+
payload = json.dumps({"session_id": "parallel", "tool_name": "Bash"})
|
|
104
|
+
workers = [subprocess.Popen([sys.executable, str(HOOK)], stdin=subprocess.PIPE, stdout=subprocess.PIPE,
|
|
105
|
+
stderr=subprocess.PIPE, text=True, env=env) for _ in range(12)]
|
|
106
|
+
denied = 0
|
|
107
|
+
for worker in workers:
|
|
108
|
+
worker.stdin.write(payload)
|
|
109
|
+
worker.stdin.close()
|
|
110
|
+
for worker in workers:
|
|
111
|
+
out = worker.stdout.read()
|
|
112
|
+
worker.wait(timeout=120)
|
|
113
|
+
worker.stdout.close()
|
|
114
|
+
worker.stderr.close()
|
|
115
|
+
denied += 1 if out.strip() else 0
|
|
116
|
+
self.assertEqual(denied, 12 - 5, "12 simultaneous actions against a cap of 5 must deny exactly 7")
|
|
117
|
+
self.assertEqual(safety.status()["actions_today"], 12)
|
|
118
|
+
|
|
119
|
+
def test_the_hook_costs_little_over_a_bare_python_start(self) -> None:
|
|
120
|
+
"""Measured against a bare interpreter start taken in the same moments, so machine load cancels out: the hook may add
|
|
121
|
+
at most 150 ms (median of 7 interleaved pairs) to the unavoidable cost of starting Python.
|
|
122
|
+
|
|
123
|
+
The absolute bound stands beside the relative one (owner directive 2026-10-17): the hook runs before every
|
|
124
|
+
side-effecting action, so one call must stay under a second whatever a bare start costs.
|
|
125
|
+
"""
|
|
126
|
+
env = dict(os.environ, **{safety.HOME_ENV: str(self.home)})
|
|
127
|
+
payload = json.dumps({"session_id": "speed", "tool_name": "Bash"})
|
|
128
|
+
|
|
129
|
+
def once(argv: list[str], data: str | None) -> float:
|
|
130
|
+
started = time.perf_counter()
|
|
131
|
+
subprocess.run(argv, input=data, capture_output=True, text=True, env=env, timeout=120)
|
|
132
|
+
return time.perf_counter() - started
|
|
133
|
+
|
|
134
|
+
once([sys.executable, str(HOOK)], payload) # warm the file cache
|
|
135
|
+
extra, absolute = [], []
|
|
136
|
+
for _ in range(7):
|
|
137
|
+
bare = once([sys.executable, "-c", "pass"], None)
|
|
138
|
+
hook = once([sys.executable, str(HOOK)], payload)
|
|
139
|
+
extra.append(hook - bare)
|
|
140
|
+
absolute.append(hook)
|
|
141
|
+
extra.sort()
|
|
142
|
+
absolute.sort()
|
|
143
|
+
self.assertLess(extra[len(extra) // 2], 0.150, f"hook overhead over a bare start, median {extra[3] * 1000:.0f} ms")
|
|
144
|
+
# The absolute bound stays beside the relative one: one hook call stays under a second, median.
|
|
145
|
+
self.assertLess(absolute[len(absolute) // 2], 1.0, f"hook call, median {absolute[3] * 1000:.0f} ms")
|
|
146
|
+
|
|
147
|
+
def test_setup_installs_one_safety_hook_with_the_matcher_and_remove_takes_it_out(self) -> None:
|
|
148
|
+
from tools import cosmos_setup
|
|
149
|
+
settings = self.home / "settings.json"
|
|
150
|
+
settings.write_text(json.dumps({"model": "x", "hooks": {"PreToolUse": [
|
|
151
|
+
{"matcher": "Bash", "hooks": [{"type": "command", "command": "other"}]}]}}), encoding="utf-8")
|
|
152
|
+
for _ in range(2): # twice: never duplicated
|
|
153
|
+
plan = cosmos_setup._plan_claude_hooks(settings, sys.executable, False, 47917)
|
|
154
|
+
settings.write_text(plan["text"], encoding="utf-8")
|
|
155
|
+
entries = json.loads(settings.read_text(encoding="utf-8"))["hooks"]["PreToolUse"]
|
|
156
|
+
mine = [e for e in entries if "cosmos_safety.py" in json.dumps(e)]
|
|
157
|
+
self.assertEqual(len(mine), 1)
|
|
158
|
+
self.assertEqual(mine[0]["matcher"], safety.MATCHER)
|
|
159
|
+
self.assertEqual(cosmos_setup.SAFETY_MATCHER, safety.MATCHER)
|
|
160
|
+
plan = cosmos_setup._plan_claude_hooks(settings, sys.executable, True, 47917)
|
|
161
|
+
settings.write_text(plan["text"], encoding="utf-8")
|
|
162
|
+
left = json.loads(settings.read_text(encoding="utf-8"))
|
|
163
|
+
self.assertNotIn("cosmos_safety.py", json.dumps(left))
|
|
164
|
+
|
|
165
|
+
def test_the_cosmos_tools_say_paused(self) -> None:
|
|
166
|
+
from tools import cosmos_mcp_server
|
|
167
|
+
safety.pause("owner stop")
|
|
168
|
+
for tool in ("cosmos_bind", "cosmos_remember"):
|
|
169
|
+
reply = cosmos_mcp_server._dispatch_request(tool, {"task": "x", "statement": "y"})
|
|
170
|
+
self.assertEqual(reply["status"], "paused")
|
|
171
|
+
self.assertIn("cosmos resume", reply["text"])
|
|
172
|
+
|
|
173
|
+
def test_the_opencode_plugin_carries_the_pause_notice(self) -> None:
|
|
174
|
+
text = (ROOT / "tools" / "cosmos_opencode_push.js").read_text(encoding="utf-8")
|
|
175
|
+
self.assertIn("COSMOS IS PAUSED", text)
|
|
176
|
+
self.assertIn("pause.json", text)
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
class ContainedCommandTests(unittest.TestCase):
|
|
181
|
+
"""The OS-level half of the budget: a real process tree, in a temporary folder, stopped by a Windows Job Object."""
|
|
182
|
+
|
|
183
|
+
def setUp(self) -> None:
|
|
184
|
+
self._tmp = tempfile.TemporaryDirectory(prefix="cosmos-contain-")
|
|
185
|
+
self.addCleanup(self._tmp.cleanup)
|
|
186
|
+
self.work = Path(self._tmp.name)
|
|
187
|
+
|
|
188
|
+
def tree_script(self, children: int, hold: int = 60) -> str:
|
|
189
|
+
"""A parent that starts `children` sleepers, writes every pid it got to pids.txt, then waits."""
|
|
190
|
+
return (
|
|
191
|
+
"import os, subprocess, sys, time\n"
|
|
192
|
+
f"out = open(r'{self.work / 'pids.txt'}', 'w')\n"
|
|
193
|
+
"out.write(str(os.getpid()) + chr(10)); out.flush()\n"
|
|
194
|
+
"started = 0\n"
|
|
195
|
+
f"for _ in range({children}):\n"
|
|
196
|
+
" try:\n"
|
|
197
|
+
f" child = subprocess.Popen([sys.executable, '-c', 'import time; time.sleep({hold})'])\n"
|
|
198
|
+
" except OSError:\n"
|
|
199
|
+
" continue\n"
|
|
200
|
+
" started += 1\n"
|
|
201
|
+
" out.write(str(child.pid) + chr(10)); out.flush()\n"
|
|
202
|
+
"out.write('started ' + str(started) + chr(10)); out.close()\n"
|
|
203
|
+
f"time.sleep({hold})\n")
|
|
204
|
+
|
|
205
|
+
def pids(self) -> list[int]:
|
|
206
|
+
lines = (self.work / "pids.txt").read_text(encoding="utf-8").splitlines()
|
|
207
|
+
return [int(line) for line in lines if line.strip().isdigit()]
|
|
208
|
+
|
|
209
|
+
def started(self) -> int:
|
|
210
|
+
return int(next(line.split()[1] for line in (self.work / "pids.txt").read_text(encoding="utf-8").splitlines()
|
|
211
|
+
if line.startswith("started")))
|
|
212
|
+
|
|
213
|
+
def assert_all_dead(self, pids: list[int]) -> None:
|
|
214
|
+
deadline = time.time() + 10
|
|
215
|
+
while time.time() < deadline and any(subprocess.is_alive(p) for p in pids):
|
|
216
|
+
time.sleep(0.1)
|
|
217
|
+
self.assertEqual([p for p in pids if subprocess.is_alive(p)], [], "a process of the tree is still running")
|
|
218
|
+
|
|
219
|
+
def test_the_time_limit_stops_the_command_and_every_process_it_started(self) -> None:
|
|
220
|
+
result = subprocess.run_contained([sys.executable, "-c", self.tree_script(4)], max_seconds=4)
|
|
221
|
+
self.assertTrue(result["timed_out"])
|
|
222
|
+
self.assertEqual(result["returncode"], subprocess.TIMED_OUT)
|
|
223
|
+
pids = self.pids()
|
|
224
|
+
self.assertGreaterEqual(len(pids), 5, "the parent and its four sleepers should have started")
|
|
225
|
+
self.assert_all_dead(pids)
|
|
226
|
+
|
|
227
|
+
def test_what_a_finished_command_left_running_is_stopped_too(self) -> None:
|
|
228
|
+
script = ("import subprocess, sys\n"
|
|
229
|
+
"c = subprocess.Popen([sys.executable, '-c', 'import time; time.sleep(60)'])\n"
|
|
230
|
+
f"open(r'{self.work / 'pids.txt'}', 'w').write(str(c.pid))\n")
|
|
231
|
+
result = subprocess.run_contained([sys.executable, "-c", script], max_seconds=30)
|
|
232
|
+
self.assertFalse(result["timed_out"])
|
|
233
|
+
self.assertEqual(result["returncode"], 0)
|
|
234
|
+
self.assertGreaterEqual(result["leftover_stopped"], 1)
|
|
235
|
+
self.assert_all_dead(self.pids())
|
|
236
|
+
|
|
237
|
+
@unittest.skipUnless(os.name == "nt", "Job Objects are a Windows facility; elsewhere only the time limit and the group cleanup apply")
|
|
238
|
+
def test_the_process_cap_stops_a_runaway_tree_at_the_cap(self) -> None:
|
|
239
|
+
result = subprocess.run_contained([sys.executable, "-c", self.tree_script(10, hold=6)], max_seconds=30, max_processes=3)
|
|
240
|
+
self.assertIn("active-process-limit", result["enforced"])
|
|
241
|
+
started = self.started()
|
|
242
|
+
self.assertLess(started, 10, "the cap must have refused some of the ten children")
|
|
243
|
+
self.assertLessEqual(started + 1, 3, "the parent and its children never exceed the cap of three")
|
|
244
|
+
self.assert_all_dead(self.pids())
|
|
245
|
+
|
|
246
|
+
@unittest.skipUnless(os.name == "nt", "Job Objects are a Windows facility")
|
|
247
|
+
def test_when_the_supervisor_dies_the_whole_tree_dies_with_it(self) -> None:
|
|
248
|
+
supervisor = (
|
|
249
|
+
"import sys\n"
|
|
250
|
+
f"sys.path.insert(0, r'{ROOT}')\n"
|
|
251
|
+
"from tools import cosmos_proc\n"
|
|
252
|
+
f"cosmos_proc.run_contained([sys.executable, '-c', {self.tree_script(3)!r}], max_seconds=120)\n")
|
|
253
|
+
holder = subprocess.Popen([sys.executable, "-c", supervisor], stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL,
|
|
254
|
+
stderr=subprocess.DEVNULL)
|
|
255
|
+
try:
|
|
256
|
+
deadline = time.time() + 30
|
|
257
|
+
while time.time() < deadline and not ((self.work / "pids.txt").is_file() and "started" in (self.work / "pids.txt").read_text()):
|
|
258
|
+
time.sleep(0.1)
|
|
259
|
+
pids = self.pids()
|
|
260
|
+
self.assertGreaterEqual(len(pids), 4)
|
|
261
|
+
self.assertTrue(all(subprocess.is_alive(p) for p in pids))
|
|
262
|
+
os.kill(holder.pid, 15) # the supervisor alone is killed (TerminateProcess); nothing else is touched
|
|
263
|
+
holder.wait(timeout=30)
|
|
264
|
+
self.assert_all_dead(pids)
|
|
265
|
+
finally:
|
|
266
|
+
if holder.poll() is None:
|
|
267
|
+
subprocess.kill_tree(holder.pid)
|
|
268
|
+
|
|
269
|
+
def test_the_command_runs_it_with_the_minutes_cap_and_exits_124(self) -> None:
|
|
270
|
+
env = dict(os.environ, PYTHONPATH=str(ROOT), **{safety.HOME_ENV: str(self.work / "safety")})
|
|
271
|
+
done = subprocess.run([sys.executable, "-m", "tools.cosmos", "budget", "run", "--minutes", "0.05", "--", sys.executable, "-c",
|
|
272
|
+
self.tree_script(2)], cwd=str(ROOT), env=env, capture_output=True, text=True, timeout=120)
|
|
273
|
+
self.assertEqual(done.returncode, 124, done.stderr)
|
|
274
|
+
self.assertIn("stopped after", done.stderr)
|
|
275
|
+
self.assert_all_dead(self.pids())
|
|
276
|
+
usage = subprocess.run([sys.executable, "-m", "tools.cosmos", "budget", "run"], cwd=str(ROOT), env=env, capture_output=True,
|
|
277
|
+
text=True, timeout=120)
|
|
278
|
+
self.assertEqual(usage.returncode, 2)
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
class HomeWriteGuardTests(unittest.TestCase):
|
|
282
|
+
"""X-003: the home-write guard sits beside the repo-write guard. A demo is given throwaway temp folders and must
|
|
283
|
+
not change the owner's real Startup or the gate's own state, status, profile and approvals. The guard only
|
|
284
|
+
reads; every snapshot here is of a fake home, so these tests never touch the owner's machine.
|
|
285
|
+
|
|
286
|
+
The service-owned files (service.json, service-heartbeat.json, heavy.lock) are deliberately NOT watched: the
|
|
287
|
+
gate service rewrites them at arbitrary times, so a change there is not evidence about a demo."""
|
|
288
|
+
|
|
289
|
+
def setUp(self) -> None:
|
|
290
|
+
self._tmp = tempfile.TemporaryDirectory(prefix="cosmos-home-guard-")
|
|
291
|
+
self.addCleanup(self._tmp.cleanup)
|
|
292
|
+
self.home = Path(self._tmp.name) / "home"
|
|
293
|
+
self.startup = (self.home / "AppData" / "Roaming" / "Microsoft" / "Windows" / "Start Menu"
|
|
294
|
+
/ "Programs" / "Startup")
|
|
295
|
+
self.startup.mkdir(parents=True)
|
|
296
|
+
(self.startup / "old.cmd").write_text("old\n", encoding="utf-8")
|
|
297
|
+
(self.home / ".claude.json").write_text('{"a": 1}\n', encoding="utf-8")
|
|
298
|
+
(self.home / ".claude").mkdir()
|
|
299
|
+
(self.home / ".claude" / "settings.json").write_text('{"m": "x"}\n', encoding="utf-8")
|
|
300
|
+
(self.home / ".codex").mkdir()
|
|
301
|
+
(self.home / ".codex" / "config.toml").write_text("x = 1\n", encoding="utf-8")
|
|
302
|
+
(self.home / ".config" / "opencode").mkdir(parents=True)
|
|
303
|
+
(self.home / ".config" / "opencode" / "opencode.jsonc").write_text("{}\n", encoding="utf-8")
|
|
304
|
+
(self.home / ".cosmos").mkdir()
|
|
305
|
+
(self.home / ".cosmos" / "events.jsonl").write_text('{"kind": "seed"}\n', encoding="utf-8")
|
|
306
|
+
self.gate = self.home / ".cosmos" / "gate"
|
|
307
|
+
self.gate.mkdir()
|
|
308
|
+
(self.gate / "state.json").write_text("{}\n", encoding="utf-8")
|
|
309
|
+
(self.gate / "serve-status.json").write_text('{"at": "2026-11-25T00:00:00Z"}\n', encoding="utf-8")
|
|
310
|
+
(self.gate / "profile.json").write_text('{"required": []}\n', encoding="utf-8")
|
|
311
|
+
(self.gate / "approvals.json").write_text('{"abc123": {"by": "Harvey"}}\n', encoding="utf-8")
|
|
312
|
+
# service-owned files: present, but never watched
|
|
313
|
+
(self.gate / "service.json").write_text('{"pid": 1}\n', encoding="utf-8")
|
|
314
|
+
(self.gate / "service-heartbeat.json").write_text('{"phase": "idle"}\n', encoding="utf-8")
|
|
315
|
+
(self.gate / "heavy.lock").write_text("1", encoding="utf-8")
|
|
316
|
+
self.demo_temp = Path(self._tmp.name) / "demo-temp"
|
|
317
|
+
self.demo_temp.mkdir()
|
|
318
|
+
|
|
319
|
+
def snap(self):
|
|
320
|
+
return home_snapshot(self.home, startup=self.startup)
|
|
321
|
+
|
|
322
|
+
def test_snapshot_is_read_only_and_covers_every_owner_home_target(self):
|
|
323
|
+
before = self.snap()
|
|
324
|
+
self.assertEqual(set(before), {"startup", "state.json", "serve-status.json", "profile.json",
|
|
325
|
+
"approvals.json"})
|
|
326
|
+
self.assertNotIn("service.json", before, "the service's pid file is not watched")
|
|
327
|
+
self.assertNotIn("service-heartbeat.json", before, "the service's heartbeat is not watched")
|
|
328
|
+
self.assertNotIn("heavy.lock", before, "the service's lock is not watched")
|
|
329
|
+
self.assertNotIn("status.json", before, "status.json never existed")
|
|
330
|
+
self.assertNotIn("pid", before, "pid never existed")
|
|
331
|
+
self.assertEqual(self.snap(), before, "snapshotting must not mutate the home")
|
|
332
|
+
report = home_write_guard(before, self.snap())
|
|
333
|
+
self.assertEqual(report["status"], "pass", report["tail"])
|
|
334
|
+
self.assertEqual(report["changed"], [])
|
|
335
|
+
self.assertEqual(report["name"], "home-write-guard")
|
|
336
|
+
|
|
337
|
+
def test_a_change_to_any_watched_target_fails_the_guard(self):
|
|
338
|
+
mutations = (
|
|
339
|
+
lambda: (self.startup / "new.cmd").write_text("new\n", encoding="utf-8"), # Startup: added entry
|
|
340
|
+
lambda: (self.gate / "state.json").write_text('{"z": 1}\n', encoding="utf-8"),
|
|
341
|
+
lambda: (self.gate / "serve-status.json").write_text('{"at": "now"}\n', encoding="utf-8"),
|
|
342
|
+
lambda: (self.gate / "profile.json").write_text('{"required": ["weakened"]}\n', encoding="utf-8"),
|
|
343
|
+
lambda: (self.gate / "approvals.json").write_text('{"other": 1}\n', encoding="utf-8"), # clobber
|
|
344
|
+
lambda: (self.gate / "state.json").unlink(), # deletion
|
|
345
|
+
)
|
|
346
|
+
for mutate in mutations:
|
|
347
|
+
before = self.snap()
|
|
348
|
+
mutate()
|
|
349
|
+
report = home_write_guard(before, self.snap())
|
|
350
|
+
self.assertEqual(report["status"], "fail", "a change to a watched target must fail the guard")
|
|
351
|
+
self.assertTrue(report["changed"], "the report must name the changed target")
|
|
352
|
+
|
|
353
|
+
def test_service_owned_files_are_not_watched(self):
|
|
354
|
+
"""service.json, service-heartbeat.json and heavy.lock are rewritten by the service at arbitrary times, so a
|
|
355
|
+
change there is not evidence about a demo and must never fail the guard."""
|
|
356
|
+
for mutate in (
|
|
357
|
+
lambda: (self.gate / "service.json").write_text('{"pid": 999}\n', encoding="utf-8"),
|
|
358
|
+
lambda: (self.gate / "service-heartbeat.json").write_text('{"phase": "judging"}\n', encoding="utf-8"),
|
|
359
|
+
lambda: (self.gate / "heavy.lock").write_text("2", encoding="utf-8"),
|
|
360
|
+
lambda: (self.gate / "service.json").unlink(),
|
|
361
|
+
):
|
|
362
|
+
before = self.snap()
|
|
363
|
+
mutate()
|
|
364
|
+
report = home_write_guard(before, self.snap())
|
|
365
|
+
self.assertEqual(report["status"], "pass", report["tail"])
|
|
366
|
+
self.assertEqual(report["changed"], [])
|
|
367
|
+
|
|
368
|
+
def test_a_mid_round_owner_approval_is_accepted(self):
|
|
369
|
+
"""approvals.json is append-only: an owner approval may land while a round is running, so an append that
|
|
370
|
+
keeps every old entry passes the guard."""
|
|
371
|
+
before = self.snap()
|
|
372
|
+
(self.gate / "approvals.json").write_text(
|
|
373
|
+
'{"abc123": {"by": "Harvey"}, "def456": {"by": "Harvey"}}\n', encoding="utf-8")
|
|
374
|
+
report = home_write_guard(before, self.snap())
|
|
375
|
+
self.assertEqual(report["status"], "pass", report["tail"])
|
|
376
|
+
self.assertEqual(report["changed"], [])
|
|
377
|
+
|
|
378
|
+
def test_a_clobber_truncate_or_delete_of_approvals_still_fails(self):
|
|
379
|
+
original = '{"abc123": {"by": "Harvey"}}\n'
|
|
380
|
+
cases = (
|
|
381
|
+
('{"unrelated": 1}\n', "clobber"), # old entry gone
|
|
382
|
+
('{}\n', "truncate to empty"), # old entry gone
|
|
383
|
+
('{"abc123": {"by": "someone-else"}}\n', "edit an existing approval"),
|
|
384
|
+
('not json at all', "truncate to invalid JSON"),
|
|
385
|
+
)
|
|
386
|
+
for content, label in cases:
|
|
387
|
+
(self.gate / "approvals.json").write_text(original, encoding="utf-8") # start from the real state
|
|
388
|
+
before = self.snap()
|
|
389
|
+
(self.gate / "approvals.json").write_text(content, encoding="utf-8")
|
|
390
|
+
report = home_write_guard(before, self.snap())
|
|
391
|
+
self.assertEqual(report["status"], "fail", f"{label} must fail the guard: {report['tail']}")
|
|
392
|
+
self.assertIn("approvals.json", report["changed"], label)
|
|
393
|
+
(self.gate / "approvals.json").write_text(original, encoding="utf-8")
|
|
394
|
+
before = self.snap()
|
|
395
|
+
(self.gate / "approvals.json").unlink() # delete
|
|
396
|
+
report = home_write_guard(before, self.snap())
|
|
397
|
+
self.assertEqual(report["status"], "fail", "deleting approvals must fail the guard")
|
|
398
|
+
self.assertIn("approvals.json", report["changed"])
|
|
399
|
+
|
|
400
|
+
def test_a_change_to_an_unwatched_target_passes_the_guard(self):
|
|
401
|
+
# codex, opencode, and cosmos events are not watched: touching them must not fail the guard
|
|
402
|
+
for mutate in (
|
|
403
|
+
lambda: (self.home / ".codex" / "config.toml").write_text("x = 2\n", encoding="utf-8"),
|
|
404
|
+
lambda: (self.home / ".config" / "opencode" / "extra.jsonc").write_text("{}\n", encoding="utf-8"),
|
|
405
|
+
lambda: (self.home / ".cosmos" / "events.jsonl").write_text('{"kind": "leak"}\n', encoding="utf-8"),
|
|
406
|
+
):
|
|
407
|
+
before = self.snap()
|
|
408
|
+
mutate()
|
|
409
|
+
report = home_write_guard(before, self.snap())
|
|
410
|
+
self.assertEqual(report["status"], "pass", report["tail"])
|
|
411
|
+
self.assertEqual(report["changed"], [])
|
|
412
|
+
|
|
413
|
+
# ---- the wiring: the guard is inside run_checks, not a manual probe ----
|
|
414
|
+
|
|
415
|
+
def _redirect_gate_home(self) -> Path:
|
|
416
|
+
"""Point COSMOS_GATE_HOME at a temp gate home (restored on cleanup), so the round's own snapshot pair reads
|
|
417
|
+
and writes a throwaway home instead of the owner's real one."""
|
|
418
|
+
gate_home = Path(self._tmp.name) / "round-gate-home"
|
|
419
|
+
gate_home.mkdir(parents=True, exist_ok=True)
|
|
420
|
+
previous = os.environ.get("COSMOS_GATE_HOME")
|
|
421
|
+
|
|
422
|
+
def restore() -> None:
|
|
423
|
+
if previous is None:
|
|
424
|
+
os.environ.pop("COSMOS_GATE_HOME", None)
|
|
425
|
+
else:
|
|
426
|
+
os.environ["COSMOS_GATE_HOME"] = previous
|
|
427
|
+
|
|
428
|
+
self.addCleanup(restore)
|
|
429
|
+
os.environ["COSMOS_GATE_HOME"] = str(gate_home)
|
|
430
|
+
return gate_home
|
|
431
|
+
|
|
432
|
+
def _worktree(self) -> Path:
|
|
433
|
+
worktree = Path(self._tmp.name) / "worktree"
|
|
434
|
+
worktree.mkdir(parents=True, exist_ok=True)
|
|
435
|
+
done = subprocess.run(["git", "init", "-q", str(worktree)], capture_output=True, text=True, timeout=120)
|
|
436
|
+
self.assertEqual(done.returncode, 0, done.stderr)
|
|
437
|
+
return worktree
|
|
438
|
+
|
|
439
|
+
def _run_round(self, worktree: Path, gate_home: Path, source: str) -> list[dict]:
|
|
440
|
+
"""Run a real gate round over a throwaway git repo with one check, and return its rows."""
|
|
441
|
+
from tools import cosmos_gate as gate
|
|
442
|
+
step = {"name": "test:home-write", "kind": "required", "class": "test",
|
|
443
|
+
"argv": [sys.executable, "-c", source]}
|
|
444
|
+
cache = Path(self._tmp.name) / "round-cache"
|
|
445
|
+
return gate.run_checks({}, [step], worktree, time.time() + 120, cache)
|
|
446
|
+
|
|
447
|
+
def _row(self, results: list[dict], name: str) -> dict:
|
|
448
|
+
found = [row for row in results if row.get("name") == name]
|
|
449
|
+
self.assertTrue(found, f"no {name} row in {[r.get('name') for r in results]}")
|
|
450
|
+
return found[0]
|
|
451
|
+
|
|
452
|
+
def test_a_step_that_writes_state_json_makes_the_round_home_guard_fail(self):
|
|
453
|
+
"""X-003's proof: a check that writes the owner's state.json is caught by the round itself, as a failing
|
|
454
|
+
home-write-guard row in run_checks' results — not by a manual probe."""
|
|
455
|
+
gate_home = self._redirect_gate_home()
|
|
456
|
+
worktree = self._worktree()
|
|
457
|
+
source = ("import pathlib, os; "
|
|
458
|
+
"pathlib.Path(os.environ['COSMOS_GATE_HOME'], 'state.json').write_text('{\"hacked\": 1}', "
|
|
459
|
+
"encoding='utf-8')")
|
|
460
|
+
results = self._run_round(worktree, gate_home, source)
|
|
461
|
+
step = self._row(results, "test:home-write")
|
|
462
|
+
self.assertEqual(step["status"], "pass", step) # the check itself succeeded
|
|
463
|
+
guard = self._row(results, "home-write-guard")
|
|
464
|
+
self.assertEqual(guard["status"], "fail", guard["tail"])
|
|
465
|
+
self.assertIn("state.json", guard["changed"], guard)
|
|
466
|
+
|
|
467
|
+
def test_a_step_that_writes_service_files_does_not_fail_the_round_home_guard(self):
|
|
468
|
+
"""The service rewrites service.json, service-heartbeat.json and heavy.lock at arbitrary times, so a check
|
|
469
|
+
touching them is not evidence about a demo and the round's home guard must pass."""
|
|
470
|
+
gate_home = self._redirect_gate_home()
|
|
471
|
+
worktree = self._worktree()
|
|
472
|
+
source = ("import pathlib, os; "
|
|
473
|
+
"g = pathlib.Path(os.environ['COSMOS_GATE_HOME']); "
|
|
474
|
+
"g.joinpath('service.json').write_text('{\"pid\": 999}', encoding='utf-8'); "
|
|
475
|
+
"g.joinpath('service-heartbeat.json').write_text('{\"phase\": \"judging\"}', encoding='utf-8'); "
|
|
476
|
+
"g.joinpath('heavy.lock').write_text('9', encoding='utf-8')")
|
|
477
|
+
results = self._run_round(worktree, gate_home, source)
|
|
478
|
+
step = self._row(results, "test:home-write")
|
|
479
|
+
self.assertEqual(step["status"], "pass", step)
|
|
480
|
+
guard = self._row(results, "home-write-guard")
|
|
481
|
+
self.assertEqual(guard["status"], "pass", guard["tail"])
|
|
482
|
+
self.assertEqual(guard["changed"], [])
|
|
483
|
+
|
|
484
|
+
def test_a_step_that_appends_an_approval_does_not_fail_the_round_home_guard(self):
|
|
485
|
+
"""An owner approval may land mid-round: the round's home guard accepts an append to approvals.json."""
|
|
486
|
+
gate_home = self._redirect_gate_home()
|
|
487
|
+
(gate_home / "approvals.json").write_text('{"old": {"by": "Harvey"}}\n', encoding="utf-8")
|
|
488
|
+
worktree = self._worktree()
|
|
489
|
+
source = ("import pathlib, os, json; "
|
|
490
|
+
"p = pathlib.Path(os.environ['COSMOS_GATE_HOME'], 'approvals.json'); "
|
|
491
|
+
"data = json.loads(p.read_text(encoding='utf-8')); data['new'] = {'by': 'Harvey'}; "
|
|
492
|
+
"p.write_text(json.dumps(data), encoding='utf-8')")
|
|
493
|
+
results = self._run_round(worktree, gate_home, source)
|
|
494
|
+
self.assertEqual(self._row(results, "test:home-write")["status"], "pass")
|
|
495
|
+
guard = self._row(results, "home-write-guard")
|
|
496
|
+
self.assertEqual(guard["status"], "pass", guard["tail"])
|
|
497
|
+
self.assertEqual(guard["changed"], [])
|
|
498
|
+
|
|
499
|
+
def test_a_real_check_run_writes_only_to_its_given_temp_dir(self):
|
|
500
|
+
"""Run an actual shipped check headless (the PreToolUse safety hook), with its home redirected into the demo's
|
|
501
|
+
temp folder, and prove the guard still passes: nothing outside the temp dir changed."""
|
|
502
|
+
before = self.snap()
|
|
503
|
+
demo_home = self.demo_temp / "safety-home"
|
|
504
|
+
env = dict(os.environ, **{safety.HOME_ENV: str(demo_home)})
|
|
505
|
+
done = subprocess.run([sys.executable, str(HOOK)], input=json.dumps({"session_id": "guard", "tool_name": "Bash"}),
|
|
506
|
+
capture_output=True, text=True, env=env, timeout=60)
|
|
507
|
+
self.assertEqual((done.returncode, done.stdout), (0, ""), done.stderr)
|
|
508
|
+
(self.demo_temp / "result.txt").write_text("ok\n", encoding="utf-8") # the demo's own scratch space
|
|
509
|
+
report = home_write_guard(before, self.snap())
|
|
510
|
+
self.assertEqual(report["status"], "pass", report["tail"])
|
|
511
|
+
self.assertEqual(report["changed"], [])
|
|
512
|
+
|
|
513
|
+
def test_cleared_environment_without_home_vars_still_guards_gate_home(self):
|
|
514
|
+
gate_home = Path(self._tmp.name) / "cleared-env-gate"
|
|
515
|
+
gate_home.mkdir(parents=True, exist_ok=True)
|
|
516
|
+
(gate_home / "state.json").write_text('{"pr": 1}\n', encoding="utf-8")
|
|
517
|
+
with mock.patch.dict(os.environ, {"COSMOS_GATE_HOME": str(gate_home)}, clear=True):
|
|
518
|
+
before = home_snapshot()
|
|
519
|
+
clean = home_write_guard(before, home_snapshot())
|
|
520
|
+
self.assertEqual(clean["status"], "pass", clean["tail"])
|
|
521
|
+
(gate_home / "state.json").write_text('{"tampered": 1}\n', encoding="utf-8")
|
|
522
|
+
report = home_write_guard(before, home_snapshot())
|
|
523
|
+
self.assertEqual(report["status"], "fail", report["tail"])
|
|
524
|
+
self.assertEqual(report["changed"], ["state.json"])
|
|
525
|
+
|
|
526
|
+
|
|
527
|
+
if __name__ == "__main__":
|
|
528
|
+
unittest.main()
|