bugx-cli 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +55 -0
- package/README.md +280 -2
- package/core/CATALOG.json +141 -0
- package/core/README.md +254 -0
- package/core/adapters/README.md +35 -0
- package/core/adapters/android-interaction.json +81 -0
- package/core/adapters/android.json +24 -0
- package/core/adapters/desktop-macos.json +20 -0
- package/core/adapters/ios-interaction.json +34 -0
- package/core/adapters/ios.json +23 -0
- package/core/adapters/memory-macos.json +24 -0
- package/core/agent/README.md +50 -0
- package/core/agent/__init__.py +146 -0
- package/core/agent/agent_artifacts.py +764 -0
- package/core/agent/agent_eval.py +1073 -0
- package/core/agent/agent_execution.py +552 -0
- package/core/agent/agent_orchestrator.py +1345 -0
- package/core/agent/agent_targets.py +871 -0
- package/core/agent/agent_workspace.py +770 -0
- package/core/assets/README.md +24 -0
- package/core/assets/bugx-avatar-1024.png +0 -0
- package/core/assets/bugx-avatar-512.png +0 -0
- package/core/assets/bugx-avatar-tight.svg +23 -0
- package/core/assets/bugx-avatar.svg +28 -0
- package/core/assets/bugx-hero-cn.png +0 -0
- package/core/assets/bugx-hero-en.png +0 -0
- package/core/assets/project-layout.md +42 -0
- package/core/audit_packs/README.md +37 -0
- package/core/audit_packs/data-audit/manifest.json +94 -0
- package/core/audit_packs/data-audit/stages/00-scope.md +14 -0
- package/core/audit_packs/data-audit/stages/10-schema-inventory.md +14 -0
- package/core/audit_packs/data-audit/stages/20-query-and-integrity.md +14 -0
- package/core/audit_packs/data-audit/stages/80-evidence-regression.md +14 -0
- package/core/audit_packs/desktop-audit/manifest.json +123 -0
- package/core/audit_packs/desktop-audit/stages/00-scope.md +15 -0
- package/core/audit_packs/desktop-audit/stages/10-process-model.md +14 -0
- package/core/audit_packs/desktop-audit/stages/20-package-integrity.md +15 -0
- package/core/audit_packs/desktop-audit/stages/30-ui-behavior.md +14 -0
- package/core/audit_packs/desktop-audit/stages/80-evidence-regression.md +15 -0
- package/core/audit_packs/memory-testing.md +227 -0
- package/core/audit_packs/mobile-audit/manifest.json +155 -0
- package/core/audit_packs/mobile-audit/modules/android.md +19 -0
- package/core/audit_packs/mobile-audit/modules/h5.md +18 -0
- package/core/audit_packs/mobile-audit/modules/ios.md +25 -0
- package/core/audit_packs/mobile-audit/modules/miniprogram.md +26 -0
- package/core/audit_packs/mobile-audit/modules/webview.md +18 -0
- package/core/audit_packs/mobile-audit/stages/00-scope.md +14 -0
- package/core/audit_packs/mobile-audit/stages/10-platform-inventory.md +14 -0
- package/core/audit_packs/mobile-audit/stages/20-masvs-static.md +20 -0
- package/core/audit_packs/mobile-audit/stages/30-component-exposure.md +14 -0
- package/core/audit_packs/mobile-audit/stages/40-device-behavior.md +14 -0
- package/core/audit_packs/mobile-audit/stages/80-evidence-regression.md +13 -0
- package/core/audit_packs/native-audit/manifest.json +127 -0
- package/core/audit_packs/native-audit/stages/00-scope.md +14 -0
- package/core/audit_packs/native-audit/stages/10-static-white-box.md +14 -0
- package/core/audit_packs/native-audit/stages/20-memory-concurrency.md +15 -0
- package/core/audit_packs/native-audit/stages/30-behavior-black-box.md +39 -0
- package/core/audit_packs/native-audit/stages/80-evidence-regression.md +14 -0
- package/core/audit_packs/platform-testing.md +174 -0
- package/core/audit_packs/web-audit/manifest.json +191 -0
- package/core/audit_packs/web-audit/modules/graphql.md +5 -0
- package/core/audit_packs/web-audit/modules/h5.md +18 -0
- package/core/audit_packs/web-audit/modules/multi-tenant.md +4 -0
- package/core/audit_packs/web-audit/modules/oauth.md +4 -0
- package/core/audit_packs/web-audit/modules/upload.md +4 -0
- package/core/audit_packs/web-audit/modules/websocket.md +4 -0
- package/core/audit_packs/web-audit/stages/00-scope.md +13 -0
- package/core/audit_packs/web-audit/stages/10-discovery.md +13 -0
- package/core/audit_packs/web-audit/stages/20-auth-session.md +13 -0
- package/core/audit_packs/web-audit/stages/30-authz-business.md +13 -0
- package/core/audit_packs/web-audit/stages/40-input-output.md +13 -0
- package/core/audit_packs/web-audit/stages/50-state-async.md +13 -0
- package/core/audit_packs/web-audit/stages/60-file-ssrf-deser.md +12 -0
- package/core/audit_packs/web-audit/stages/70-config-dependency.md +12 -0
- package/core/audit_packs/web-audit/stages/80-evidence-regression.md +12 -0
- package/core/autonomous_cve/INTERFACE.md +61 -0
- package/core/autonomous_cve/README.md +58 -0
- package/core/autonomous_cve/SPEC.md +25 -0
- package/core/autonomous_cve/__init__.py +109 -0
- package/core/autonomous_cve/attack_graph.py +1096 -0
- package/core/autonomous_cve/attack_graph_store.py +1822 -0
- package/core/autonomous_cve/audit_campaign.py +1232 -0
- package/core/autonomous_cve/behavior_graph.py +459 -0
- package/core/autonomous_cve/ghsa_advisories.py +174 -0
- package/core/autonomous_cve/models.py +93 -0
- package/core/autonomous_cve/mutator.py +87 -0
- package/core/autonomous_cve/patcher.py +126 -0
- package/core/autonomous_cve/scout.py +278 -0
- package/core/autonomous_cve/synthesizer.py +207 -0
- package/core/autonomous_cve/verifier.py +100 -0
- package/core/bugx.md +1299 -0
- package/core/bugx_paths.py +1846 -0
- package/core/cloud_sync/INTERFACE.md +32 -0
- package/core/cloud_sync/README.md +62 -0
- package/core/cloud_sync/SPEC.md +25 -0
- package/core/cloud_sync/__init__.py +23 -0
- package/core/cloud_sync/auto_sync.py +398 -0
- package/core/cloud_sync/cloud_client.py +1199 -0
- package/core/cloud_sync/cloud_onboard.py +702 -0
- package/core/cloud_sync/cloud_schema.py +648 -0
- package/core/cloud_sync/consent.py +81 -0
- package/core/cloud_sync/device_identity.py +307 -0
- package/core/cloud_sync/endpoint_router.py +415 -0
- package/core/cloud_sync/flywheel_client.py +760 -0
- package/core/cloud_sync/network_transport.py +275 -0
- package/core/cloud_sync/onboard_wizard.py +493 -0
- package/core/cloud_sync/sensitive_filter.py +285 -0
- package/core/cloud_sync/sync_pull.py +695 -0
- package/core/cloud_sync/sync_push.py +721 -0
- package/core/contracts/AGENT_GUIDE.md +362 -0
- package/core/contracts/README.md +34 -0
- package/core/contracts/bugx-blackbox.md +541 -0
- package/core/contracts/bugx-opencode.md +469 -0
- package/core/contracts/bugx-quick.md +44 -0
- package/core/contracts/bugx-runtime-contract.md +353 -0
- package/core/contracts/bugx-worker.md +470 -0
- package/core/contracts/engine_gap_contracts.py +390 -0
- package/core/coverage/README.md +70 -0
- package/core/coverage/__init__.py +106 -0
- package/core/coverage/coverage_ai_review.py +185 -0
- package/core/coverage/coverage_backfill.py +54 -0
- package/core/coverage/coverage_bootstrap.py +713 -0
- package/core/coverage/coverage_business.py +36 -0
- package/core/coverage/coverage_cli.py +715 -0
- package/core/coverage/coverage_discovery.py +859 -0
- package/core/coverage/coverage_evidence.py +977 -0
- package/core/coverage/coverage_forensics.py +115 -0
- package/core/coverage/coverage_gate.py +277 -0
- package/core/coverage/coverage_intelligence.py +734 -0
- package/core/coverage/coverage_manifest.py +396 -0
- package/core/coverage/coverage_platform.py +77 -0
- package/core/coverage/coverage_validate.py +236 -0
- package/core/coverage/module_coverage.py +157 -0
- package/core/dev_harness/INTERFACE.md +20 -0
- package/core/dev_harness/README.md +21 -0
- package/core/dev_harness/SPEC.md +25 -0
- package/core/dev_harness/__init__.py +5 -0
- package/core/dev_harness/interaction_preset.py +408 -0
- package/core/engine-integrity.json +2625 -0
- package/core/fuzzing/README.md +49 -0
- package/core/fuzzing/__init__.py +82 -0
- package/core/fuzzing/concurrency_fuzzer.py +382 -0
- package/core/fuzzing/differential_oracle.py +629 -0
- package/core/fuzzing/fuzz_input.py +1188 -0
- package/core/fuzzing/stateful_fuzzer.py +332 -0
- package/core/governance/README.md +61 -0
- package/core/governance/__init__.py +130 -0
- package/core/governance/capacity_planner.py +124 -0
- package/core/governance/dependency_lock.py +317 -0
- package/core/governance/goal_governor.py +754 -0
- package/core/governance/guide_budget.py +458 -0
- package/core/governance/lockdown.sh +50 -0
- package/core/governance/readonly_enforcer.py +154 -0
- package/core/governance/runtime_tool_gate.py +373 -0
- package/core/governance/secret_redactor.py +772 -0
- package/core/governance/token_budget.py +38 -0
- package/core/host_acp/INTERFACE.md +36 -0
- package/core/host_acp/README.md +51 -0
- package/core/host_acp/SPEC.md +25 -0
- package/core/host_acp/__init__.py +121 -0
- package/core/host_acp/base.py +111 -0
- package/core/host_acp/claude.py +41 -0
- package/core/host_acp/cline.py +235 -0
- package/core/host_acp/codex.py +245 -0
- package/core/host_acp/dsh.py +48 -0
- package/core/host_acp/opencode.py +154 -0
- package/core/host_acp/pi.py +36 -0
- package/core/host_acp/zcode.py +41 -0
- package/core/host_runtime/INTERFACE.md +24 -0
- package/core/host_runtime/README.md +62 -0
- package/core/host_runtime/SPEC.md +25 -0
- package/core/host_runtime/__init__.py +21 -0
- package/core/host_runtime/adapters.py +412 -0
- package/core/host_runtime/autonomous_runner.py +1152 -0
- package/core/host_runtime/cline.py +435 -0
- package/core/host_runtime/common.py +103 -0
- package/core/host_runtime/free_models.py +786 -0
- package/core/host_runtime/host_bootstrap.py +389 -0
- package/core/host_runtime/host_evaluators.py +721 -0
- package/core/host_runtime/host_probe.py +41 -0
- package/core/host_runtime/host_provider_arbitrator.py +777 -0
- package/core/host_runtime/host_registry.py +655 -0
- package/core/host_runtime/host_usage.py +127 -0
- package/core/host_runtime/mcp_process_tracker.py +509 -0
- package/core/host_runtime/mcp_registry_gate.py +368 -0
- package/core/hosts/INTERFACE.md +51 -0
- package/core/hosts/README.md +67 -0
- package/core/hosts/SPEC.md +25 -0
- package/core/hosts/__init__.py +136 -0
- package/core/hosts/_base_usage.py +152 -0
- package/core/hosts/_codex_usage.py +297 -0
- package/core/hosts/_dsh_usage.py +184 -0
- package/core/hosts/_mcp_toml.py +365 -0
- package/core/hosts/_zcode_usage.py +269 -0
- package/core/hosts/base.py +451 -0
- package/core/hosts/claude.py +157 -0
- package/core/hosts/cline.py +225 -0
- package/core/hosts/codex.py +948 -0
- package/core/hosts/dsh.py +518 -0
- package/core/hosts/opencode.py +358 -0
- package/core/hosts/pi.py +151 -0
- package/core/hosts/zcode.py +219 -0
- package/core/i18n.py +252 -0
- package/core/infra/README.md +39 -0
- package/core/infra/__init__.py +15 -0
- package/core/infra/build_info.py +86 -0
- package/core/infra/client_metadata.py +185 -0
- package/core/infra/python_runtime.py +540 -0
- package/core/infra/safe_xml.py +221 -0
- package/core/launch_bugx.py +118 -0
- package/core/launch_phases/INTERFACE.md +31 -0
- package/core/launch_phases/README.md +106 -0
- package/core/launch_phases/SPEC.md +25 -0
- package/core/launch_phases/__init__.py +29 -0
- package/core/launch_phases/candidate_revalidation.py +484 -0
- package/core/launch_phases/common.py +1041 -0
- package/core/launch_phases/finding_confirm_phase.py +387 -0
- package/core/launch_phases/finding_settlement.py +1245 -0
- package/core/launch_phases/findings_adjudication.py +666 -0
- package/core/launch_phases/findings_snapshot.py +357 -0
- package/core/launch_phases/judge_phase.py +791 -0
- package/core/launch_phases/lesson_context.py +536 -0
- package/core/launch_phases/lifecycle_reporter.py +627 -0
- package/core/launch_phases/orchestrator_controls.py +682 -0
- package/core/launch_phases/post_commit.py +567 -0
- package/core/launch_phases/post_coverage_sync.py +591 -0
- package/core/launch_phases/post_dry_run.py +817 -0
- package/core/launch_phases/post_observability.py +367 -0
- package/core/launch_phases/post_phase.py +1087 -0
- package/core/launch_phases/post_receipt.py +362 -0
- package/core/launch_phases/post_round_lifecycle.py +786 -0
- package/core/launch_phases/pre_phase.py +1029 -0
- package/core/launch_phases/pre_recon_scout.py +862 -0
- package/core/launch_phases/pre_state_builder.py +1286 -0
- package/core/launch_phases/report_sharing.py +414 -0
- package/core/launch_phases/round_orchestrator.py +1133 -0
- package/core/launch_phases/session_runtime.py +1623 -0
- package/core/launch_phases/startup_gates.py +1022 -0
- package/core/launch_phases/startup_interaction.py +947 -0
- package/core/launch_phases/startup_version_gate.py +873 -0
- package/core/launch_phases/supervisor_bridge.py +1224 -0
- package/core/launch_phases/supervisor_coverage.py +417 -0
- package/core/launch_phases/supervisor_degraded.py +1219 -0
- package/core/launch_phases/worker_barriers.py +414 -0
- package/core/launch_phases/worker_orchestrator.py +1166 -0
- package/core/launch_phases/worker_prior.py +749 -0
- package/core/ledger/INTERFACE.md +35 -0
- package/core/ledger/README.md +160 -0
- package/core/ledger/SPEC.md +25 -0
- package/core/ledger/__init__.py +67 -0
- package/core/ledger/_facade.py +226 -0
- package/core/ledger/archive_ops.py +572 -0
- package/core/ledger/auto_materialization.py +459 -0
- package/core/ledger/bug-log.md +22 -0
- package/core/ledger/cli.py +270 -0
- package/core/ledger/export_ops.py +549 -0
- package/core/ledger/finding_confirmation.py +1274 -0
- package/core/ledger/finding_io.py +299 -0
- package/core/ledger/finding_lifecycle.py +307 -0
- package/core/ledger/finding_verification.py +369 -0
- package/core/ledger/incidents.py +999 -0
- package/core/ledger/lesson-replay-cases.json +20 -0
- package/core/ledger/lesson_ledger.py +241 -0
- package/core/ledger/lesson_replay.py +272 -0
- package/core/ledger/life_ledger.py +668 -0
- package/core/ledger/mistake-book.md +130 -0
- package/core/ledger/patterns.py +681 -0
- package/core/ledger/receipt_contract.py +253 -0
- package/core/ledger/schema.py +1192 -0
- package/core/ledger/sync_ops.py +935 -0
- package/core/ledger/tool_experience.py +682 -0
- package/core/ledger/verify_life.py +1526 -0
- package/core/lesson-ledger.json +275 -0
- package/core/locales/README.md +19 -0
- package/core/locales/en-US.json +462 -0
- package/core/locales/zh-CN.json +462 -0
- package/core/mcp_handlers/INTERFACE.md +75 -0
- package/core/mcp_handlers/README.md +62 -0
- package/core/mcp_handlers/SPEC.md +25 -0
- package/core/mcp_handlers/__init__.py +128 -0
- package/core/mcp_handlers/base.py +697 -0
- package/core/mcp_handlers/channel_lifecycle.py +696 -0
- package/core/mcp_handlers/graph_handlers.py +222 -0
- package/core/mcp_handlers/knowledge_handlers.py +536 -0
- package/core/mcp_handlers/mining_handlers.py +586 -0
- package/core/mcp_handlers/resource_prompt_table.py +116 -0
- package/core/mcp_handlers/retrieval_handlers.py +239 -0
- package/core/mcp_handlers/rpc_server.py +465 -0
- package/core/mcp_handlers/supervisor_handlers.py +1435 -0
- package/core/mcp_handlers/telemetry_handlers.py +227 -0
- package/core/mcp_handlers/tool_table.py +1015 -0
- package/core/mcp_runtime_support/README.md +21 -0
- package/core/mcp_runtime_support/__init__.py +1 -0
- package/core/mcp_runtime_support/common.py +363 -0
- package/core/mcp_runtime_support/environment.py +605 -0
- package/core/mcp_runtime_support/verifier.py +810 -0
- package/core/metadata.txt +5 -0
- package/core/planning/README.md +157 -0
- package/core/planning/__init__.py +242 -0
- package/core/planning/capability_plan.py +187 -0
- package/core/planning/capability_planner.py +195 -0
- package/core/planning/domain_archetype.py +542 -0
- package/core/planning/domain_router.py +267 -0
- package/core/planning/dynamic_flow_analyzer.py +328 -0
- package/core/planning/impact_pruner.py +435 -0
- package/core/planning/intent_adjudicator.py +175 -0
- package/core/planning/judge_pipeline.py +1163 -0
- package/core/planning/logic_analysis.py +419 -0
- package/core/planning/prompt_harness.py +1702 -0
- package/core/planning/source_inspector.py +267 -0
- package/core/planning/spec_harvester.py +449 -0
- package/core/planning/target_sandbox_manager.py +573 -0
- package/core/planning/test_capability_verifier.py +1364 -0
- package/core/planning/tools-kb.md +38 -0
- package/core/planning/unit_kind.py +122 -0
- package/core/probes/INTERFACE.md +73 -0
- package/core/probes/README.md +51 -0
- package/core/probes/SPEC.md +26 -0
- package/core/probes/__init__.py +70 -0
- package/core/probes/android_probe.py +384 -0
- package/core/probes/base.py +147 -0
- package/core/probes/codebase_memory_probe.py +590 -0
- package/core/probes/desktop_probe.py +238 -0
- package/core/probes/differential_probe.py +356 -0
- package/core/probes/efficiency_probe.py +168 -0
- package/core/probes/ios_binary_probe.py +368 -0
- package/core/probes/memory_probe.py +326 -0
- package/core/probes/miniprogram_probe.py +323 -0
- package/core/probes/mobile_probe.py +281 -0
- package/core/probes/native_probe.py +214 -0
- package/core/probes/openwiki_probe.py +193 -0
- package/core/probes/pattern_probe.py +347 -0
- package/core/probes/platform_probe.py +343 -0
- package/core/probes/probe_registry.py +1669 -0
- package/core/probes/sast_probe.py +1009 -0
- package/core/probes/sast_rules.py +841 -0
- package/core/probes/sca_scanner.py +731 -0
- package/core/probes/web_probe.py +359 -0
- package/core/project_profiler/INTERFACE.md +62 -0
- package/core/project_profiler/README.md +53 -0
- package/core/project_profiler/SPEC.md +28 -0
- package/core/project_profiler/__init__.py +201 -0
- package/core/project_profiler/arbitrator.py +311 -0
- package/core/project_profiler/constants.py +247 -0
- package/core/project_profiler/detector.py +392 -0
- package/core/project_profiler/extractors.py +836 -0
- package/core/project_profiler/fingerprint.py +116 -0
- package/core/project_profiler/storage.py +258 -0
- package/core/project_profiler/strategy.py +265 -0
- package/core/prompts/README.md +35 -0
- package/core/prompts/codex_dialog_dispatch.md +9 -0
- package/core/prompts/command_routing_en.md +42 -0
- package/core/prompts/command_routing_zh.md +42 -0
- package/core/prompts/l0_router.md +47 -0
- package/core/prompts/rules/anti_patterns.md +16 -0
- package/core/prompts/rules/concurrency_rules.md +14 -0
- package/core/prompts/rules/memory_leak_rules.md +13 -0
- package/core/prompts/rules/prompt_injection_defense.md +13 -0
- package/core/prompts/stages/stage_explore.md +31 -0
- package/core/prompts/stages/stage_gate.md +43 -0
- package/core/prompts/stages/stage_mutate.md +42 -0
- package/core/prompts/stages/stage_repair.md +85 -0
- package/core/repair/README.md +74 -0
- package/core/repair/__init__.py +169 -0
- package/core/repair/fix_watchlist.py +391 -0
- package/core/repair/l7_dynamic.py +418 -0
- package/core/repair/l7_repair_loop.py +465 -0
- package/core/repair/l7_selfcheck.py +862 -0
- package/core/repair/minimize_repro.py +466 -0
- package/core/repair/patch_synthesizer.py +617 -0
- package/core/repair/regression_pack.py +379 -0
- package/core/repair/rsi_fixer.py +910 -0
- package/core/repair/rsi_loop.py +313 -0
- package/core/repair/rsi_repair.py +348 -0
- package/core/repair/rsi_rounds.py +212 -0
- package/core/repair/rsi_scope.py +262 -0
- package/core/repair/self_heal.py +604 -0
- package/core/repair/test_generator.py +1108 -0
- package/core/repair/test_quality_auditor.py +410 -0
- package/core/repair/test_strategy.py +511 -0
- package/core/report_engine/INTERFACE.md +59 -0
- package/core/report_engine/README.md +69 -0
- package/core/report_engine/SPEC.md +28 -0
- package/core/report_engine/__init__.py +47 -0
- package/core/report_engine/attestation.py +224 -0
- package/core/report_engine/authority.py +255 -0
- package/core/report_engine/finding_report.py +417 -0
- package/core/report_engine/formal_report_builder.py +924 -0
- package/core/report_engine/html_renderers.py +696 -0
- package/core/report_engine/models.py +761 -0
- package/core/report_engine/pdf_exporter.py +231 -0
- package/core/report_engine/projects_assets.py +730 -0
- package/core/report_engine/report_client.py +743 -0
- package/core/report_engine/report_data_builder.py +388 -0
- package/core/report_engine/report_share.py +459 -0
- package/core/report_engine/sast_bridge.py +116 -0
- package/core/report_engine/server.py +822 -0
- package/core/report_engine/visual_report_builder.py +796 -0
- package/core/report_engine/web-conformance.md +63 -0
- package/core/report_engine/web_conformance.py +459 -0
- package/core/report_engine/workbench_assets.py +484 -0
- package/core/retrieval/INTERFACE.md +20 -0
- package/core/retrieval/README.md +161 -0
- package/core/retrieval/SPEC.md +25 -0
- package/core/retrieval/__init__.py +3 -0
- package/core/retrieval/code_analyzer.py +1684 -0
- package/core/retrieval/codebase_memory_bridge.py +337 -0
- package/core/retrieval/context_assembler.py +234 -0
- package/core/retrieval/corpus_fetch.py +369 -0
- package/core/retrieval/graph_ego.py +597 -0
- package/core/retrieval/knowledge_auto.py +662 -0
- package/core/retrieval/knowledge_sources.py +168 -0
- package/core/retrieval/knowledge_sync.py +909 -0
- package/core/retrieval/memory_store.py +480 -0
- package/core/retrieval/query_planner.py +1020 -0
- package/core/retrieval/rrf_engine.py +137 -0
- package/core/retrieval/slice_extractor.py +1209 -0
- package/core/retrieval/slice_normalizer.py +373 -0
- package/core/retrieval/slice_spec.py +357 -0
- package/core/retrieval/symbol_index.py +1132 -0
- package/core/retrieval/universal_code_matcher.py +437 -0
- package/core/retrieval/xerj_bridge.py +476 -0
- package/core/retrieval/xerj_supervisor.py +362 -0
- package/core/rules/README.md +33 -0
- package/core/rules/ios/PROVENANCE.json +30 -0
- package/core/rules/ios/crypto.yaml +36 -0
- package/core/rules/ios/network.yaml +20 -0
- package/core/rules/ios/resilience.yaml +47 -0
- package/core/rules/ios/storage.yaml +48 -0
- package/core/rules/mastg/LICENSE +173 -0
- package/core/rules/mastg/PROVENANCE.json +270 -0
- package/core/rules/mastg/mastg-android-asymmetric-key-pair-used-for-multiple-purposes.yml +13 -0
- package/core/rules/mastg/mastg-android-backup-manifest.yml +24 -0
- package/core/rules/mastg/mastg-android-biometric-event-bound.yml +49 -0
- package/core/rules/mastg/mastg-android-biometric-invalidated-enrollment.yml +11 -0
- package/core/rules/mastg/mastg-android-biometric-no-confirmation-required.yml +10 -0
- package/core/rules/mastg/mastg-android-biometric-validity-duration.yml +24 -0
- package/core/rules/mastg/mastg-android-broken-encryption-algorithms.yaml +9 -0
- package/core/rules/mastg/mastg-android-broken-encryption-modes.yaml +13 -0
- package/core/rules/mastg/mastg-android-content-provider-exported.yml +35 -0
- package/core/rules/mastg/mastg-android-custom-deeplink-scheme.yml +29 -0
- package/core/rules/mastg/mastg-android-dangerous-app-permissions.yaml +65 -0
- package/core/rules/mastg/mastg-android-data-unencrypted-shared-storage-no-user-interaction-apis.yml +36 -0
- package/core/rules/mastg/mastg-android-data-unencrypted-shared-storage-no-user-interaction-manifest.yml +15 -0
- package/core/rules/mastg/mastg-android-debuggable-flag.yml +10 -0
- package/core/rules/mastg/mastg-android-debugger-checks.yml +12 -0
- package/core/rules/mastg/mastg-android-deeplink-autoverify-missing.yml +33 -0
- package/core/rules/mastg/mastg-android-deeplink-unvalidated-parameter.yml +11 -0
- package/core/rules/mastg/mastg-android-device-passcode-present.yml +17 -0
- package/core/rules/mastg/mastg-android-fileprovider-broad-scope.yml +46 -0
- package/core/rules/mastg/mastg-android-hardcoded-crypto-keys-usage.yml +14 -0
- package/core/rules/mastg/mastg-android-hardcoded-security-provider.yaml +18 -0
- package/core/rules/mastg/mastg-android-implicit-intent-internal-communication.yml +30 -0
- package/core/rules/mastg/mastg-android-implicit-intent-leaking-extras.yml +29 -0
- package/core/rules/mastg/mastg-android-input-field-usage.yml +11 -0
- package/core/rules/mastg/mastg-android-key-generation-with-insufficient-key-length.yml +21 -0
- package/core/rules/mastg/mastg-android-keyboard-cache-input-types.yml +10 -0
- package/core/rules/mastg/mastg-android-local-storage-input-validation.yml +48 -0
- package/core/rules/mastg/mastg-android-native-debugger-checks.yml +12 -0
- package/core/rules/mastg/mastg-android-network-checkservertrusted.yml +12 -0
- package/core/rules/mastg/mastg-android-network-hostname-verification.yml +11 -0
- package/core/rules/mastg/mastg-android-network-insecure-trust-anchors.yml +11 -0
- package/core/rules/mastg/mastg-android-network-onreceivedsslerror.yml +12 -0
- package/core/rules/mastg/mastg-android-non-random-use.yml +16 -0
- package/core/rules/mastg/mastg-android-object-deserialization.yml +14 -0
- package/core/rules/mastg/mastg-android-overlay-protection.yml +68 -0
- package/core/rules/mastg/mastg-android-pendingintent-mutable.yml +39 -0
- package/core/rules/mastg/mastg-android-random-apis-insufficient-entropy.yml +17 -0
- package/core/rules/mastg/mastg-android-root-detection.yaml +59 -0
- package/core/rules/mastg/mastg-android-sdk-version.yml +10 -0
- package/core/rules/mastg/mastg-android-sensitive-data-in-notifications-manifest.yml +17 -0
- package/core/rules/mastg/mastg-android-sensitive-data-in-notifications.yml +11 -0
- package/core/rules/mastg/mastg-android-sensitive-data-in-screenshot.yml +18 -0
- package/core/rules/mastg/mastg-android-sql-injection-contentprovider.yml +17 -0
- package/core/rules/mastg/mastg-android-ssl-socket-hostnameverifier.yml +15 -0
- package/core/rules/mastg/mastg-android-strictmode.yml +10 -0
- package/core/rules/mastg/mastg-android-system-alert-window.yml +9 -0
- package/core/rules/mastg/mastg-android-webview-allow-local-access.yml +15 -0
- package/core/rules/mastg/mastg-android-webview-bridges.yml +28 -0
- package/core/rules/mastg/mastg-android-webview-safebrowsing.yml +20 -0
- package/core/rules/mastg/mastg-android-webview-url-handlers.yml +41 -0
- package/core/rules/miniprogram/PROVENANCE.json +26 -0
- package/core/rules/miniprogram/network.yaml +37 -0
- package/core/rules/miniprogram/platform.yaml +36 -0
- package/core/rules/miniprogram/storage.yaml +48 -0
- package/core/rules/mobsfscan-swift/LICENSE +165 -0
- package/core/rules/mobsfscan-swift/PROVENANCE.json +58 -0
- package/core/rules/mobsfscan-swift/auth.yaml +59 -0
- package/core/rules/mobsfscan-swift/crypto.yaml +66 -0
- package/core/rules/mobsfscan-swift/jailbreak.yaml +14 -0
- package/core/rules/mobsfscan-swift/keyboard.yaml +34 -0
- package/core/rules/mobsfscan-swift/logging.yaml +23 -0
- package/core/rules/mobsfscan-swift/network.yaml +55 -0
- package/core/rules/mobsfscan-swift/resilience.yaml +29 -0
- package/core/rules/mobsfscan-swift/secrets.yaml +33 -0
- package/core/rules/mobsfscan-swift/storage.yaml +29 -0
- package/core/rules/mobsfscan-swift/webview.yaml +32 -0
- package/core/runtime/README.md +198 -0
- package/core/runtime/__init__.py +3 -0
- package/core/runtime/bugx_logging.py +1393 -0
- package/core/runtime/daemon_runner.py +623 -0
- package/core/runtime/fixture_solidify.py +449 -0
- package/core/runtime/global_telemetry.py +549 -0
- package/core/runtime/incident_eval.py +148 -0
- package/core/runtime/interaction.py +605 -0
- package/core/runtime/interaction_store.py +435 -0
- package/core/runtime/interactive_menu.py +95 -0
- package/core/runtime/log_analytics.py +922 -0
- package/core/runtime/mining_quality_framework.py +1387 -0
- package/core/runtime/model_runner.py +769 -0
- package/core/runtime/platform_adapter.py +579 -0
- package/core/runtime/prep_validate.py +476 -0
- package/core/runtime/project_graph.py +827 -0
- package/core/runtime/project_init.py +481 -0
- package/core/runtime/project_profile.py +224 -0
- package/core/runtime/project_settings.py +963 -0
- package/core/runtime/provider_window.py +97 -0
- package/core/runtime/resume_ticket.py +115 -0
- package/core/runtime/scenario_eval.py +814 -0
- package/core/runtime/seed_drill.py +549 -0
- package/core/runtime/self_audit.py +550 -0
- package/core/runtime/session_profile.py +205 -0
- package/core/runtime/setup_ui_env.py +229 -0
- package/core/runtime/startup_environment.py +859 -0
- package/core/runtime/sync_store.py +1421 -0
- package/core/runtime/tool_install_targets.py +18 -0
- package/core/schemas/README.md +35 -0
- package/core/schemas/agent-graph.schema.json +368 -0
- package/core/schemas/attack-graph.schema.json +88 -0
- package/core/schemas/evidence-bundle.schema.json +33 -0
- package/core/schemas/skill-pack.schema.json +230 -0
- package/core/schemas/worker-checkpoint.schema.json +119 -0
- package/core/secure_atomic.py +289 -0
- package/core/seed_corpus/README.md +55 -0
- package/core/seed_corpus/c.txt +29 -0
- package/core/seed_corpus/cpp.txt +32 -0
- package/core/seed_corpus/css.txt +70 -0
- package/core/seed_corpus/go.txt +46 -0
- package/core/seed_corpus/java.txt +30 -0
- package/core/seed_corpus/javascript.txt +55 -0
- package/core/seed_corpus/kotlin.txt +28 -0
- package/core/seed_corpus/python.txt +71 -0
- package/core/seed_corpus/rust.txt +53 -0
- package/core/seed_corpus/swift.txt +29 -0
- package/core/seed_corpus/typescript.txt +29 -0
- package/core/skills/README.md +53 -0
- package/core/skills/__init__.py +189 -0
- package/core/skills/bugx_docs_mcp_server.py +416 -0
- package/core/skills/bugx_mcp_server.py +1134 -0
- package/core/skills/mcp_runtime.py +968 -0
- package/core/skills/mcp_session_proof.py +605 -0
- package/core/skills/mobile_ui_inspector.py +405 -0
- package/core/skills/skill_pack.py +1214 -0
- package/core/skills/skill_synthesizer.py +1153 -0
- package/core/skills/tools_kb.py +313 -0
- package/core/supervisor/INTERFACE.md +121 -0
- package/core/supervisor/README.md +209 -0
- package/core/supervisor/SPEC.md +25 -0
- package/core/supervisor/__init__.py +175 -0
- package/core/supervisor/audit_supervisor.py +1015 -0
- package/core/supervisor/budget_governor.py +760 -0
- package/core/supervisor/checkpoint_handler.py +368 -0
- package/core/supervisor/checkpoint_pipeline.py +1322 -0
- package/core/supervisor/checkpoint_sync.py +640 -0
- package/core/supervisor/claim_events.py +74 -0
- package/core/supervisor/claim_sync.py +590 -0
- package/core/supervisor/cli.py +812 -0
- package/core/supervisor/context_sync.py +55 -0
- package/core/supervisor/coverage_sync.py +115 -0
- package/core/supervisor/finding_commit.py +470 -0
- package/core/supervisor/finding_sync.py +688 -0
- package/core/supervisor/finding_workflow.py +659 -0
- package/core/supervisor/finish_policy.py +224 -0
- package/core/supervisor/finish_sync.py +185 -0
- package/core/supervisor/graph_sync.py +669 -0
- package/core/supervisor/lease_manager.py +788 -0
- package/core/supervisor/lifecycle_blocks.py +124 -0
- package/core/supervisor/next_round_sync.py +126 -0
- package/core/supervisor/observability.py +140 -0
- package/core/supervisor/recovery_sync.py +165 -0
- package/core/supervisor/rejection_remedies.py +308 -0
- package/core/supervisor/round_governor.py +306 -0
- package/core/supervisor/serial_authorization.py +500 -0
- package/core/supervisor/start_sync.py +87 -0
- package/core/supervisor/state_store.py +249 -0
- package/core/supervisor/supervisor_host.py +511 -0
- package/core/supervisor/supervisor_models.py +1143 -0
- package/core/supervisor/systemic_failure.py +104 -0
- package/core/supervisor/task_scheduler.py +1640 -0
- package/core/supervisor/worker_checkpoint.py +223 -0
- package/core/supervisor/worker_execution.py +265 -0
- package/core/supervisor/worker_handoff.py +192 -0
- package/core/supervisor/worker_lifecycle.py +396 -0
- package/core/supervisor/worker_runtime.py +999 -0
- package/core/supervisor/worker_sync.py +89 -0
- package/core/supervisor_types/README.md +36 -0
- package/core/supervisor_types/__init__.py +0 -0
- package/core/supervisor_types/exceptions.py +52 -0
- package/core/supervisor_types/graph_models.py +357 -0
- package/core/supervisor_types/path_containment.py +151 -0
- package/core/supervisor_types/target_fingerprint.py +310 -0
- package/core/supervisor_types/worker_claim.py +402 -0
- package/core/webui/INTERFACE.md +50 -0
- package/core/webui/README.md +57 -0
- package/core/webui/SPEC.md +25 -0
- package/core/webui/__init__.py +11 -0
- package/core/webui/adapters/__init__.py +27 -0
- package/core/webui/adapters/base.py +87 -0
- package/core/webui/adapters/bugx.py +102 -0
- package/core/webui/adapters/claude.py +218 -0
- package/core/webui/adapters/cline.py +399 -0
- package/core/webui/adapters/codex.py +256 -0
- package/core/webui/adapters/dsh.py +173 -0
- package/core/webui/adapters/opencode.py +218 -0
- package/core/webui/adapters/pi.py +272 -0
- package/core/webui/adapters/registry.py +100 -0
- package/core/webui/adapters/zcode.py +312 -0
- package/core/webui/api_routes_post.py +668 -0
- package/core/webui/dispatcher.py +1376 -0
- package/core/webui/docs_session_service.py +473 -0
- package/core/webui/handler.py +674 -0
- package/core/webui/ide_cloud_service.py +526 -0
- package/core/webui/mcp_inspector.py +1743 -0
- package/core/webui/static/assets/index-CXAsl8mr.js +333 -0
- package/core/webui/static/assets/index-DHQUtWtx.css +1 -0
- package/core/webui/static/assets/source-serif-4-cyrillic-400-normal-B8Z6Jvzv.woff +0 -0
- package/core/webui/static/assets/source-serif-4-cyrillic-400-normal-C44pakCn.woff2 +0 -0
- package/core/webui/static/assets/source-serif-4-cyrillic-500-normal-Bb4u56_6.woff +0 -0
- package/core/webui/static/assets/source-serif-4-cyrillic-500-normal-BdVUvljg.woff2 +0 -0
- package/core/webui/static/assets/source-serif-4-cyrillic-ext-400-normal-CWV284fw.woff2 +0 -0
- package/core/webui/static/assets/source-serif-4-cyrillic-ext-400-normal-DLkyKLvH.woff +0 -0
- package/core/webui/static/assets/source-serif-4-cyrillic-ext-500-normal-8-8HP2PF.woff +0 -0
- package/core/webui/static/assets/source-serif-4-cyrillic-ext-500-normal-DaDZE_Na.woff2 +0 -0
- package/core/webui/static/assets/source-serif-4-greek-400-normal-BccYJ-vZ.woff +0 -0
- package/core/webui/static/assets/source-serif-4-greek-400-normal-Cw5-AHNN.woff2 +0 -0
- package/core/webui/static/assets/source-serif-4-greek-500-normal-By8GFJzz.woff2 +0 -0
- package/core/webui/static/assets/source-serif-4-greek-500-normal-z-Q6FFuG.woff +0 -0
- package/core/webui/static/assets/source-serif-4-latin-400-normal-DJ5YJwmz.woff2 +0 -0
- package/core/webui/static/assets/source-serif-4-latin-400-normal-Dn3IlU-Z.woff +0 -0
- package/core/webui/static/assets/source-serif-4-latin-500-normal-CUHe9xxf.woff2 +0 -0
- package/core/webui/static/assets/source-serif-4-latin-500-normal-DVVamBqs.woff +0 -0
- package/core/webui/static/assets/source-serif-4-latin-ext-400-normal-CEpydyUl.woff +0 -0
- package/core/webui/static/assets/source-serif-4-latin-ext-400-normal-Cp7z-ARB.woff2 +0 -0
- package/core/webui/static/assets/source-serif-4-latin-ext-500-normal-BYjRCDVy.woff2 +0 -0
- package/core/webui/static/assets/source-serif-4-latin-ext-500-normal-D-qasQTj.woff +0 -0
- package/core/webui/static/assets/source-serif-4-vietnamese-400-normal-BbG3LG1A.woff2 +0 -0
- package/core/webui/static/assets/source-serif-4-vietnamese-400-normal-DR1UuFon.woff +0 -0
- package/core/webui/static/assets/source-serif-4-vietnamese-500-normal-8N8MYVKB.woff +0 -0
- package/core/webui/static/assets/source-serif-4-vietnamese-500-normal-Bi3OSTTW.woff2 +0 -0
- package/core/webui/static/favicon.png +0 -0
- package/core/webui/static/icon-192.png +0 -0
- package/core/webui/static/index.html +42 -0
- package/core/webui/static/manifest.webmanifest +19 -0
- package/core/webui/static/project-settings.css +6458 -0
- package/core/webui/static/project-settings.js +9602 -0
- package/core/webui/static/sw.js +8 -0
- package/core/webui/workspace_service.py +218 -0
- package/docs/07_distribution/01_README_NPM.md +281 -0
- package/docs/07_distribution/README.md +16 -0
- package/docs/README.md +121 -0
- package/ecosystem/README.md +129 -0
- package/ecosystem/integrations/README.md +38 -0
- package/ecosystem/integrations/cline/skills/bugx/SKILL.md +69 -0
- package/ecosystem/integrations/dsh/agents/bugx.md +27 -0
- package/ecosystem/integrations/dsh/dsh-patch.yml +18 -0
- package/ecosystem/integrations/dsh/mcp/cordis.patch.yml +4 -0
- package/ecosystem/integrations/dsh/mcp/index.js +219 -0
- package/ecosystem/integrations/dsh/mcp/package.json +28 -0
- package/ecosystem/integrations/dsh/skills/bugx/SKILL.md +70 -0
- package/ecosystem/integrations/dsh/skills/bugx-dsh/SKILL.md +229 -0
- package/ecosystem/integrations/dsh/ui/client.js +87 -0
- package/ecosystem/integrations/dsh/ui/cordis.patch.yml +4 -0
- package/ecosystem/integrations/dsh/ui/index.js +7 -0
- package/ecosystem/integrations/dsh/ui/package.json +27 -0
- package/ecosystem/integrations/opencode/bugx-mcp-manifest.json +53 -0
- package/ecosystem/integrations/opencode/mcp-lock.json +3067 -0
- package/ecosystem/integrations/opencode/opencode.json +118 -0
- package/ecosystem/integrations/pi/extensions/bugx/README.md +12 -0
- package/ecosystem/integrations/pi/extensions/bugx/index.ts +299 -0
- package/ecosystem/integrations/pi/extensions/bugx/manifest.json +11 -0
- package/ecosystem/integrations/pi/skills/bugx/SKILL.md +69 -0
- package/ecosystem/integrations/qoder/CONNECTORS.md +54 -0
- package/ecosystem/integrations/qoder/connector-meta.json +21 -0
- package/ecosystem/integrations/workbuddy/connector-meta.json +19 -0
- package/ecosystem/integrations/workbuddy/icon.png +0 -0
- package/ecosystem/integrations/workbuddy/skills/bugx/SKILL.md +70 -0
- package/ecosystem/plugins/README.md +37 -0
- package/ecosystem/plugins/bugx/.claude-plugin/marketplace.json +17 -0
- package/ecosystem/plugins/bugx/.claude-plugin/plugin.json +16 -0
- package/ecosystem/plugins/bugx/.codex-plugin/plugin.json +41 -0
- package/ecosystem/plugins/bugx/.zcode-plugin/plugin.json +19 -0
- package/ecosystem/plugins/bugx/agents/bugx-judge.md +71 -0
- package/ecosystem/plugins/bugx/agents/bugx-worker.md +31 -0
- package/ecosystem/plugins/bugx/agents/bugx.md +74 -0
- package/ecosystem/plugins/bugx/assets/bugx-avatar-512.png +0 -0
- package/ecosystem/plugins/bugx/skills/bugx/SKILL.md +118 -0
- package/ecosystem/plugins/bugx/skills/bugx-claude/SKILL.md +326 -0
- package/ecosystem/plugins/bugx/skills/bugx-dsh/SKILL.md +229 -0
- package/ecosystem/plugins/bugx/skills/bugx-opencode/SKILL.md +129 -0
- package/ecosystem/plugins/bugx/skills/bugx-zcode/SKILL.md +459 -0
- package/interfaces/README.md +143 -0
- package/interfaces/bin/README.md +35 -0
- package/interfaces/bin/bugx.js +80 -0
- package/interfaces/cli/README.md +90 -0
- package/interfaces/cli/bugx_cli/__init__.py +4 -0
- package/interfaces/cli/bugx_cli/cli.py +1678 -0
- package/interfaces/cli/bugx_cli/commands/__init__.py +1 -0
- package/interfaces/cli/bugx_cli/commands/advisory.py +94 -0
- package/interfaces/cli/bugx_cli/commands/agent.py +3944 -0
- package/interfaces/cli/bugx_cli/commands/audit.py +632 -0
- package/interfaces/cli/bugx_cli/commands/autonomous.py +260 -0
- package/interfaces/cli/bugx_cli/commands/cloud.py +1370 -0
- package/interfaces/cli/bugx_cli/commands/daemon.py +50 -0
- package/interfaces/cli/bugx_cli/commands/doctor.py +1345 -0
- package/interfaces/cli/bugx_cli/commands/goal.py +107 -0
- package/interfaces/cli/bugx_cli/commands/interaction.py +244 -0
- package/interfaces/cli/bugx_cli/commands/knowledge.py +617 -0
- package/interfaces/cli/bugx_cli/commands/lifecycle.py +2763 -0
- package/interfaces/cli/bugx_cli/commands/patch.py +1014 -0
- package/interfaces/cli/bugx_cli/commands/plugin.py +2714 -0
- package/interfaces/cli/bugx_cli/commands/plugin_claude.py +1446 -0
- package/interfaces/cli/bugx_cli/commands/plugin_cline.py +269 -0
- package/interfaces/cli/bugx_cli/commands/plugin_codex.py +74 -0
- package/interfaces/cli/bugx_cli/commands/plugin_funide.py +728 -0
- package/interfaces/cli/bugx_cli/commands/plugin_qoder.py +216 -0
- package/interfaces/cli/bugx_cli/commands/plugin_zcode.py +710 -0
- package/interfaces/cli/bugx_cli/commands/project.py +670 -0
- package/interfaces/cli/bugx_cli/commands/report.py +260 -0
- package/interfaces/cli/bugx_cli/commands/skill.py +251 -0
- package/interfaces/cli/bugx_cli/commands/stats.py +133 -0
- package/interfaces/cli/bugx_cli/commands/system.py +2567 -0
- package/interfaces/cli/bugx_cli/common.py +898 -0
- package/interfaces/cli/bugx_cli/host_adapters.py +1917 -0
- package/interfaces/cli/bugx_cli/hosts/__init__.py +80 -0
- package/interfaces/cli/bugx_cli/hosts/base.py +99 -0
- package/interfaces/cli/bugx_cli/hosts/registry.py +571 -0
- package/interfaces/cli/bugx_cli/hosts/template_engine.py +188 -0
- package/interfaces/cli/bugx_cli/infra/__init__.py +209 -0
- package/interfaces/cli/bugx_cli/infra/ai_advisor.py +721 -0
- package/interfaces/cli/bugx_cli/infra/engine_installer.py +1937 -0
- package/interfaces/cli/bugx_cli/infra/host_sync.py +545 -0
- package/interfaces/cli/bugx_cli/infra/mcp_advisor.py +755 -0
- package/interfaces/cli/bugx_cli/infra/security.py +332 -0
- package/package.json +98 -4
- package/pyproject.toml +246 -0
- package/scripts/README.md +118 -0
- package/scripts/ensure-python.mjs +97 -0
- package/scripts/isolate-npm-readme.mjs +40 -0
- package/scripts/runtime.lock.json +31 -0
- package/scripts/sync-version.mjs +37 -0
- package/scripts/test-npm-wrapper.mjs +265 -0
|
@@ -0,0 +1,817 @@
|
|
|
1
|
+
"""Read-only, bounded snapshot capture for ``post --dry-run``.
|
|
2
|
+
|
|
3
|
+
This module deliberately does not import or call post-phase helpers. Its only
|
|
4
|
+
filesystem access is rooted at an already-open project directory and every
|
|
5
|
+
component is opened with ``O_NOFOLLOW``. The returned snapshot retains the raw
|
|
6
|
+
bytes used for its hashes so callers can evaluate that exact capture.
|
|
7
|
+
|
|
8
|
+
A declared source that simply does not exist yet is *not* the same failure as a
|
|
9
|
+
source that exists but is unsafe to read. Missing paths get ``source_missing``
|
|
10
|
+
while permission/IO failures keep ``source_unavailable_or_unsafe``; sources
|
|
11
|
+
declared optional (``OPTIONAL_SOURCES``) are recorded as ``watched_absent``
|
|
12
|
+
instead of aborting the preflight, and remain fail-closed when a caller
|
|
13
|
+
promotes them through ``capture_snapshot(required_sources=...)``.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
from __future__ import annotations
|
|
17
|
+
|
|
18
|
+
import errno
|
|
19
|
+
import hashlib
|
|
20
|
+
import json
|
|
21
|
+
import os
|
|
22
|
+
import re
|
|
23
|
+
import sqlite3
|
|
24
|
+
import stat
|
|
25
|
+
import time
|
|
26
|
+
from dataclasses import dataclass, field
|
|
27
|
+
from pathlib import Path, PurePosixPath
|
|
28
|
+
from types import MappingProxyType
|
|
29
|
+
from typing import Any, Collection, Mapping
|
|
30
|
+
from urllib.parse import quote
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
JSON_LIMIT = 16 * 1024 * 1024
|
|
34
|
+
# Keep the post snapshot reader aligned with Supervisor's findings sync
|
|
35
|
+
# contract. A smaller private cap would reject reports that sync accepts.
|
|
36
|
+
FINDINGS_LIMIT = 16 * 1024 * 1024
|
|
37
|
+
ARTIFACT_LIMIT = 8 * 1024 * 1024
|
|
38
|
+
SNAPSHOT_LIMIT = 64 * 1024 * 1024
|
|
39
|
+
SHA256_RE = re.compile(r"^[0-9a-fA-F]{64}$")
|
|
40
|
+
NOT_EVALUATED = (
|
|
41
|
+
"lease_refresh", "checkpoint_apply", "test_execution", "settlement",
|
|
42
|
+
"network", "git_hook", "report_publication", "next_round_start",
|
|
43
|
+
)
|
|
44
|
+
GUARANTEE = "仅表示 observed_at 时的读取结果;不锁定后续状态,也不保证最终 post 成功。"
|
|
45
|
+
|
|
46
|
+
# "文件不存在"与"文件存在但不安全"是两种不同事实,必须给出不同原因码。
|
|
47
|
+
SOURCE_MISSING = "source_missing"
|
|
48
|
+
|
|
49
|
+
# 快照源的必需性声明。``findings.json`` 由结算阶段落盘,post 预检往往早于它,
|
|
50
|
+
# 因此默认按可选源处理:缺失时记为 ``watched_absent`` 而不是中止预检;下游阶段
|
|
51
|
+
# 真正需要它时用 ``capture_snapshot(required_sources={"findings"})`` 提升为必需,
|
|
52
|
+
# 缺失即按 ``source_missing`` fail-closed。其余具名源仍恒为必需。
|
|
53
|
+
OPTIONAL_SOURCES = frozenset({"findings"})
|
|
54
|
+
|
|
55
|
+
# ENOENT/ENOTDIR(父目录缺失或不是目录)都只说明路径当前没有可读文件,属于"尚未
|
|
56
|
+
# 落盘"的正常状态;其余 errno 一律按不可用处理。O_NOFOLLOW 命中 symlink 时 open
|
|
57
|
+
# 以 ELOOP 失败,那也不是 IO 故障,而是"目标不是普通文件"的安全判定。
|
|
58
|
+
_MISSING_ERRNOS = frozenset(
|
|
59
|
+
code for code in (getattr(errno, "ENOENT", None), getattr(errno, "ENOTDIR", None))
|
|
60
|
+
if code is not None
|
|
61
|
+
)
|
|
62
|
+
_SYMLINK_ERRNOS = frozenset(
|
|
63
|
+
code for code in (getattr(errno, "ELOOP", None),) if code is not None
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def _read_failure_reason(exc: OSError) -> str:
|
|
68
|
+
"""把 ``OSError`` 归一为稳定原因码;原因码绝不回显主机绝对路径。"""
|
|
69
|
+
if isinstance(exc, FileNotFoundError) or exc.errno in _MISSING_ERRNOS:
|
|
70
|
+
return SOURCE_MISSING
|
|
71
|
+
if exc.errno in _SYMLINK_ERRNOS:
|
|
72
|
+
return "source_not_regular"
|
|
73
|
+
return "source_unavailable_or_unsafe"
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
class SnapshotInvalid(ValueError):
|
|
77
|
+
"""A fail-closed snapshot read failure with a stable reason code."""
|
|
78
|
+
|
|
79
|
+
def __init__(self, reason_code: str):
|
|
80
|
+
self.reason_code = reason_code
|
|
81
|
+
super().__init__(reason_code)
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
@dataclass(frozen=True)
|
|
85
|
+
class SourceSnapshot:
|
|
86
|
+
path: str
|
|
87
|
+
raw_bytes: bytes = field(repr=False)
|
|
88
|
+
sha256: str
|
|
89
|
+
device: int
|
|
90
|
+
inode: int
|
|
91
|
+
size: int
|
|
92
|
+
limit: int
|
|
93
|
+
kind: str
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
@dataclass(frozen=True)
|
|
97
|
+
class FrozenSnapshot:
|
|
98
|
+
root: Path
|
|
99
|
+
observed_at: str
|
|
100
|
+
snapshot_id: str
|
|
101
|
+
sources: Mapping[str, SourceSnapshot] = field(repr=False)
|
|
102
|
+
documents: Mapping[str, Any] = field(repr=False)
|
|
103
|
+
coherence: str
|
|
104
|
+
blockers: tuple[Mapping[str, str], ...]
|
|
105
|
+
watched_absent: tuple[str, ...] = ()
|
|
106
|
+
not_evaluated: tuple[str, ...] = NOT_EVALUATED
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
@dataclass(frozen=True)
|
|
110
|
+
class DryRunResult:
|
|
111
|
+
report: Mapping[str, Any]
|
|
112
|
+
snapshot: FrozenSnapshot | None = field(default=None, repr=False)
|
|
113
|
+
|
|
114
|
+
def as_dict(self) -> dict[str, Any]:
|
|
115
|
+
return dict(self.report)
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def _relative_path(path: Path, root: Path) -> str:
|
|
119
|
+
try:
|
|
120
|
+
relative = path.relative_to(root)
|
|
121
|
+
except ValueError as exc:
|
|
122
|
+
raise SnapshotInvalid("source_outside_project_root") from exc
|
|
123
|
+
value = relative.as_posix()
|
|
124
|
+
if not value or value == "." or "\\" in value:
|
|
125
|
+
raise SnapshotInvalid("source_path_invalid")
|
|
126
|
+
return value
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
class RootReader:
|
|
130
|
+
"""Open project-relative paths without following any path component."""
|
|
131
|
+
|
|
132
|
+
def __init__(self, root: Path):
|
|
133
|
+
self.root = Path(os.path.abspath(os.fspath(root)))
|
|
134
|
+
flags = os.O_RDONLY | getattr(os, "O_DIRECTORY", 0) | getattr(os, "O_NOFOLLOW", 0)
|
|
135
|
+
try:
|
|
136
|
+
self.fd = os.open(self.root, flags)
|
|
137
|
+
except OSError as exc:
|
|
138
|
+
raise SnapshotInvalid("project_root_unavailable") from exc
|
|
139
|
+
|
|
140
|
+
def close(self) -> None:
|
|
141
|
+
os.close(self.fd)
|
|
142
|
+
|
|
143
|
+
@staticmethod
|
|
144
|
+
def _parts(relative: str) -> tuple[str, ...]:
|
|
145
|
+
path = PurePosixPath(relative)
|
|
146
|
+
if path.is_absolute() or not path.parts or any(
|
|
147
|
+
part in {"", ".", ".."} or "\\" in part for part in path.parts
|
|
148
|
+
):
|
|
149
|
+
raise SnapshotInvalid("source_path_invalid")
|
|
150
|
+
return path.parts
|
|
151
|
+
|
|
152
|
+
def _open(self, relative: str) -> int:
|
|
153
|
+
parts = self._parts(relative)
|
|
154
|
+
parent = os.dup(self.fd)
|
|
155
|
+
try:
|
|
156
|
+
for part in parts[:-1]:
|
|
157
|
+
flags = os.O_RDONLY | getattr(os, "O_DIRECTORY", 0) | getattr(os, "O_NOFOLLOW", 0)
|
|
158
|
+
child = os.open(part, flags, dir_fd=parent)
|
|
159
|
+
os.close(parent)
|
|
160
|
+
parent = child
|
|
161
|
+
flags = os.O_RDONLY | getattr(os, "O_NOFOLLOW", 0)
|
|
162
|
+
return os.open(parts[-1], flags, dir_fd=parent)
|
|
163
|
+
except OSError as exc:
|
|
164
|
+
raise SnapshotInvalid(_read_failure_reason(exc)) from exc
|
|
165
|
+
finally:
|
|
166
|
+
os.close(parent)
|
|
167
|
+
|
|
168
|
+
def exists(self, relative: str) -> bool:
|
|
169
|
+
"""报告普通文件是否存在;缺失返回 False,其余不安全事实仍 fail-closed。"""
|
|
170
|
+
parts = self._parts(relative)
|
|
171
|
+
parent = os.dup(self.fd)
|
|
172
|
+
try:
|
|
173
|
+
for part in parts[:-1]:
|
|
174
|
+
flags = os.O_RDONLY | getattr(os, "O_DIRECTORY", 0) | getattr(os, "O_NOFOLLOW", 0)
|
|
175
|
+
child = os.open(part, flags, dir_fd=parent)
|
|
176
|
+
os.close(parent)
|
|
177
|
+
parent = child
|
|
178
|
+
try:
|
|
179
|
+
item = os.stat(parts[-1], dir_fd=parent, follow_symlinks=False)
|
|
180
|
+
except FileNotFoundError:
|
|
181
|
+
return False
|
|
182
|
+
if stat.S_ISLNK(item.st_mode) or not stat.S_ISREG(item.st_mode):
|
|
183
|
+
raise SnapshotInvalid("source_not_regular")
|
|
184
|
+
return True
|
|
185
|
+
except OSError as exc:
|
|
186
|
+
# 父目录缺失同样只是"还没有文件",不能让可选源把它变成安全事件。
|
|
187
|
+
reason = _read_failure_reason(exc)
|
|
188
|
+
if reason == SOURCE_MISSING:
|
|
189
|
+
return False
|
|
190
|
+
raise SnapshotInvalid(reason) from exc
|
|
191
|
+
finally:
|
|
192
|
+
os.close(parent)
|
|
193
|
+
|
|
194
|
+
def read(self, relative: str, limit: int, kind: str) -> SourceSnapshot:
|
|
195
|
+
fd = self._open(relative)
|
|
196
|
+
try:
|
|
197
|
+
before = os.fstat(fd)
|
|
198
|
+
if not stat.S_ISREG(before.st_mode):
|
|
199
|
+
raise SnapshotInvalid("source_not_regular")
|
|
200
|
+
if before.st_size > limit:
|
|
201
|
+
raise SnapshotInvalid("source_size_limit")
|
|
202
|
+
chunks: list[bytes] = []
|
|
203
|
+
total = 0
|
|
204
|
+
while True:
|
|
205
|
+
chunk = os.read(fd, min(1024 * 1024, limit + 1 - total))
|
|
206
|
+
if not chunk:
|
|
207
|
+
break
|
|
208
|
+
chunks.append(chunk)
|
|
209
|
+
total += len(chunk)
|
|
210
|
+
if total > limit:
|
|
211
|
+
raise SnapshotInvalid("source_size_limit")
|
|
212
|
+
after = os.fstat(fd)
|
|
213
|
+
if (before.st_dev, before.st_ino, before.st_size, before.st_mtime_ns) != (
|
|
214
|
+
after.st_dev, after.st_ino, after.st_size, after.st_mtime_ns,
|
|
215
|
+
) or total != after.st_size:
|
|
216
|
+
raise SnapshotInvalid("source_changed_during_read")
|
|
217
|
+
raw = b"".join(chunks)
|
|
218
|
+
return SourceSnapshot(
|
|
219
|
+
path=relative,
|
|
220
|
+
raw_bytes=raw,
|
|
221
|
+
sha256=hashlib.sha256(raw).hexdigest(),
|
|
222
|
+
device=before.st_dev,
|
|
223
|
+
inode=before.st_ino,
|
|
224
|
+
size=total,
|
|
225
|
+
limit=limit,
|
|
226
|
+
kind=kind,
|
|
227
|
+
)
|
|
228
|
+
finally:
|
|
229
|
+
os.close(fd)
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
def _json(source: SourceSnapshot) -> Any:
|
|
233
|
+
try:
|
|
234
|
+
value = json.loads(source.raw_bytes.decode("utf-8"))
|
|
235
|
+
if not isinstance(value, dict):
|
|
236
|
+
raise SnapshotInvalid("source_json_invalid")
|
|
237
|
+
return value
|
|
238
|
+
except (UnicodeDecodeError, json.JSONDecodeError, ValueError, RecursionError) as exc:
|
|
239
|
+
if isinstance(exc, SnapshotInvalid):
|
|
240
|
+
raise
|
|
241
|
+
raise SnapshotInvalid("source_json_invalid") from exc
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
def _canonical_json(value: Mapping[str, Any]) -> bytes:
|
|
245
|
+
return json.dumps(
|
|
246
|
+
value, ensure_ascii=False, sort_keys=True, separators=(",", ":"),
|
|
247
|
+
allow_nan=False,
|
|
248
|
+
).encode("utf-8")
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
def _deep_freeze(value: Any) -> Any:
|
|
252
|
+
if isinstance(value, dict):
|
|
253
|
+
return MappingProxyType({key: _deep_freeze(item) for key, item in value.items()})
|
|
254
|
+
if isinstance(value, list):
|
|
255
|
+
return tuple(_deep_freeze(item) for item in value)
|
|
256
|
+
return value
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
def _is_json_integer(value: Any, minimum: int) -> bool:
|
|
260
|
+
"""Reject bool explicitly because Python treats bool as an int."""
|
|
261
|
+
return isinstance(value, int) and not isinstance(value, bool) and value >= minimum
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
def verify_supervisor_history(state: Any) -> bool:
|
|
265
|
+
if not isinstance(state, Mapping) or not isinstance(state.get("history"), (list, tuple)):
|
|
266
|
+
return False
|
|
267
|
+
state_revision = state.get("revision")
|
|
268
|
+
if not _is_json_integer(state_revision, 0):
|
|
269
|
+
return False
|
|
270
|
+
history = state["history"]
|
|
271
|
+
base_hash = state.get("history_base_hash", "")
|
|
272
|
+
audit_head = state.get("audit_head", "")
|
|
273
|
+
if (
|
|
274
|
+
not isinstance(base_hash, str)
|
|
275
|
+
or (base_hash and not SHA256_RE.fullmatch(base_hash))
|
|
276
|
+
or not isinstance(audit_head, str)
|
|
277
|
+
):
|
|
278
|
+
return False
|
|
279
|
+
previous = state.get("history_base_hash", "")
|
|
280
|
+
expected = state.get("history_base_seq", 1)
|
|
281
|
+
if isinstance(expected, bool) or not isinstance(expected, int) or expected < 1:
|
|
282
|
+
return False
|
|
283
|
+
try:
|
|
284
|
+
previous_revision = 0
|
|
285
|
+
for event in history:
|
|
286
|
+
event_seq = event.get("seq") if isinstance(event, Mapping) else None
|
|
287
|
+
if (
|
|
288
|
+
not isinstance(event, Mapping)
|
|
289
|
+
or isinstance(event_seq, bool)
|
|
290
|
+
or not isinstance(event_seq, int)
|
|
291
|
+
or event_seq != expected
|
|
292
|
+
):
|
|
293
|
+
return False
|
|
294
|
+
event_revision = event.get("revision")
|
|
295
|
+
if (not _is_json_integer(event_revision, 1)
|
|
296
|
+
or event_revision < previous_revision
|
|
297
|
+
or event_revision > state_revision):
|
|
298
|
+
return False
|
|
299
|
+
event_previous = event.get("prev_hash", "")
|
|
300
|
+
if (
|
|
301
|
+
not isinstance(event_previous, str)
|
|
302
|
+
or (event_previous and not SHA256_RE.fullmatch(event_previous))
|
|
303
|
+
or event_previous != previous
|
|
304
|
+
):
|
|
305
|
+
return False
|
|
306
|
+
event_body = {key: value for key, value in event.items() if key != "hash"}
|
|
307
|
+
digest = hashlib.sha256(_canonical_json(event_body)).hexdigest()
|
|
308
|
+
if event.get("hash") != digest:
|
|
309
|
+
return False
|
|
310
|
+
previous = digest
|
|
311
|
+
previous_revision = event_revision
|
|
312
|
+
expected += 1
|
|
313
|
+
except (TypeError, ValueError, RecursionError):
|
|
314
|
+
return False
|
|
315
|
+
return audit_head == previous
|
|
316
|
+
|
|
317
|
+
|
|
318
|
+
def _verify_findings_seal(runtime: Any, supervisor: Any,
|
|
319
|
+
findings_source: SourceSnapshot | None) -> str | None:
|
|
320
|
+
"""校验收到的 findings 字节是否等于 Supervisor 记录的内容哈希。
|
|
321
|
+
|
|
322
|
+
``findings_source`` 为 ``None`` 表示该源在本阶段合法缺失:此时没有可比对的
|
|
323
|
+
字节,只要 Supervisor 也没有为其登记封存事件就无证明义务;一旦登记了封存
|
|
324
|
+
事件却读不到文件,那才是真正的矛盾,仍要 fail-closed。
|
|
325
|
+
"""
|
|
326
|
+
if not isinstance(runtime, Mapping) or not isinstance(supervisor, Mapping):
|
|
327
|
+
return "findings_seal_binding_missing"
|
|
328
|
+
history = supervisor.get("history")
|
|
329
|
+
if not isinstance(history, (list, tuple)):
|
|
330
|
+
return "findings_seal_history_missing"
|
|
331
|
+
runtime_lifecycle = runtime.get("lifecycle_id")
|
|
332
|
+
runtime_round = runtime.get("round")
|
|
333
|
+
if not isinstance(runtime_lifecycle, str) or not runtime_lifecycle.strip():
|
|
334
|
+
return "findings_seal_binding_missing"
|
|
335
|
+
if not _is_json_integer(runtime_round, 1):
|
|
336
|
+
return "findings_seal_binding_missing"
|
|
337
|
+
best: tuple[int, str] | None = None
|
|
338
|
+
for event in history:
|
|
339
|
+
if not isinstance(event, Mapping) or event.get("type") not in {
|
|
340
|
+
"finding_decisions_synced", "findings_report_sealed",
|
|
341
|
+
}:
|
|
342
|
+
continue
|
|
343
|
+
digest = event.get("report_sha256")
|
|
344
|
+
if not isinstance(digest, str) or not SHA256_RE.fullmatch(digest):
|
|
345
|
+
continue
|
|
346
|
+
event_lifecycle = event.get("lifecycle_id")
|
|
347
|
+
if not isinstance(event_lifecycle, str) or not event_lifecycle.strip():
|
|
348
|
+
continue
|
|
349
|
+
event_round = event.get("round_no")
|
|
350
|
+
if not _is_json_integer(event_round, 1):
|
|
351
|
+
continue
|
|
352
|
+
if event_lifecycle != runtime_lifecycle or event_round != runtime_round:
|
|
353
|
+
continue
|
|
354
|
+
seq = event.get("seq")
|
|
355
|
+
order = seq if isinstance(seq, int) and not isinstance(seq, bool) else 0
|
|
356
|
+
if best is None or order >= best[0]:
|
|
357
|
+
best = (order, digest.lower())
|
|
358
|
+
if best is None:
|
|
359
|
+
# 没有封存事件:源缺失时无可证明的矛盾,存在时才是缺 seal。
|
|
360
|
+
return None if findings_source is None else "findings_seal_missing"
|
|
361
|
+
if findings_source is None:
|
|
362
|
+
return "findings_seal_mismatch"
|
|
363
|
+
if best[1] != findings_source.sha256:
|
|
364
|
+
return "findings_seal_mismatch"
|
|
365
|
+
return None
|
|
366
|
+
|
|
367
|
+
|
|
368
|
+
def _referenced_artifacts(value: Any):
|
|
369
|
+
"""Yield (path, expected hash) pairs from captured claims/evidence/receipts."""
|
|
370
|
+
pending = [value]
|
|
371
|
+
while pending:
|
|
372
|
+
current = pending.pop()
|
|
373
|
+
if isinstance(current, dict):
|
|
374
|
+
artifact_path = current.get("artifact_path")
|
|
375
|
+
if isinstance(artifact_path, str) and artifact_path.strip():
|
|
376
|
+
expected = current.get("artifact_sha256")
|
|
377
|
+
yield artifact_path, expected if isinstance(expected, str) else None
|
|
378
|
+
pending.extend(current.values())
|
|
379
|
+
elif isinstance(current, list):
|
|
380
|
+
pending.extend(current)
|
|
381
|
+
|
|
382
|
+
|
|
383
|
+
def _snapshot_id(sources: Mapping[str, SourceSnapshot]) -> str:
|
|
384
|
+
digest = hashlib.sha256()
|
|
385
|
+
for path in sorted(sources, key=lambda item: item.encode("utf-8")):
|
|
386
|
+
digest.update(path.encode("utf-8"))
|
|
387
|
+
digest.update(b"\0")
|
|
388
|
+
digest.update(bytes.fromhex(sources[path].sha256))
|
|
389
|
+
return digest.hexdigest()
|
|
390
|
+
|
|
391
|
+
|
|
392
|
+
def _identity_coherence(documents: Mapping[str, Any], current: Any,
|
|
393
|
+
absent_sources: Collection[str] = ()) -> tuple[str, list[dict[str, str]]]:
|
|
394
|
+
"""比对身份一致性;``absent_sources`` 是本阶段合法缺失的源名。
|
|
395
|
+
|
|
396
|
+
合法缺失的可选源没有任何字节可比:它既不参与 ``run_id``/binding 比对,也不
|
|
397
|
+
承担生成标记的证明义务——否则"产物尚未落盘"会被误判成"身份不可证明"。
|
|
398
|
+
未声明为可缺失的源仍按 ``identity_source_missing`` fail-closed。
|
|
399
|
+
"""
|
|
400
|
+
blockers: list[dict[str, str]] = []
|
|
401
|
+
absent = frozenset(absent_sources)
|
|
402
|
+
runtime = documents.get("runtime")
|
|
403
|
+
supervisor = documents.get("supervisor")
|
|
404
|
+
findings = documents.get("findings")
|
|
405
|
+
# runtime/supervisor/current 在捕获阶段恒为必需源;缺失即无法证明身份。
|
|
406
|
+
if not all(isinstance(item, Mapping) for item in (runtime, supervisor, current)):
|
|
407
|
+
return "unproven", [{"gate_id": "identity_coherence", "reason_code": "identity_source_missing"}]
|
|
408
|
+
findings_present = isinstance(findings, Mapping)
|
|
409
|
+
if not findings_present and "findings" not in absent:
|
|
410
|
+
return "unproven", [{"gate_id": "identity_coherence", "reason_code": "identity_source_missing"}]
|
|
411
|
+
lifecycle_id = runtime.get("lifecycle_id")
|
|
412
|
+
current_lifecycle = current.get("lifecycle_id")
|
|
413
|
+
if (not isinstance(lifecycle_id, str) or not lifecycle_id.strip()
|
|
414
|
+
or current_lifecycle != lifecycle_id):
|
|
415
|
+
blockers.append({"gate_id": "identity_coherence", "reason_code": "lifecycle_binding_mismatch"})
|
|
416
|
+
|
|
417
|
+
runtime_round = runtime.get("round")
|
|
418
|
+
supervisor_round = supervisor.get("round_no")
|
|
419
|
+
if not _is_json_integer(runtime_round, 1):
|
|
420
|
+
blockers.append({"gate_id": "identity_coherence", "reason_code": "runtime_round_invalid"})
|
|
421
|
+
if not _is_json_integer(supervisor_round, 1):
|
|
422
|
+
blockers.append({"gate_id": "identity_coherence", "reason_code": "supervisor_round_invalid"})
|
|
423
|
+
elif _is_json_integer(runtime_round, 1) and supervisor_round != runtime_round:
|
|
424
|
+
blockers.append({"gate_id": "identity_coherence", "reason_code": "supervisor_round_mismatch"})
|
|
425
|
+
if supervisor.get("round_id") != lifecycle_id:
|
|
426
|
+
blockers.append({"gate_id": "identity_coherence", "reason_code": "supervisor_lifecycle_mismatch"})
|
|
427
|
+
|
|
428
|
+
runtime_session_values: list[str] = []
|
|
429
|
+
for field_name in ("polling_id", "session_id"):
|
|
430
|
+
value = runtime.get(field_name)
|
|
431
|
+
if value is None:
|
|
432
|
+
continue
|
|
433
|
+
if not isinstance(value, str) or not value.strip():
|
|
434
|
+
blockers.append({"gate_id": "identity_coherence", "reason_code": "runtime_session_invalid"})
|
|
435
|
+
continue
|
|
436
|
+
runtime_session_values.append(value)
|
|
437
|
+
if len(runtime_session_values) == 2 and runtime_session_values[0] != runtime_session_values[1]:
|
|
438
|
+
blockers.append({"gate_id": "identity_coherence", "reason_code": "runtime_session_conflict"})
|
|
439
|
+
session_identity = runtime_session_values[0] if runtime_session_values else None
|
|
440
|
+
current_polling = current.get("polling_id")
|
|
441
|
+
supervisor_session = supervisor.get("session_id")
|
|
442
|
+
if session_identity is not None:
|
|
443
|
+
if current_polling != session_identity:
|
|
444
|
+
blockers.append({"gate_id": "identity_coherence", "reason_code": "current_session_mismatch"})
|
|
445
|
+
if supervisor_session != session_identity:
|
|
446
|
+
blockers.append({"gate_id": "identity_coherence", "reason_code": "supervisor_session_mismatch"})
|
|
447
|
+
elif current_polling is not None or supervisor_session is not None:
|
|
448
|
+
blockers.append({"gate_id": "identity_coherence", "reason_code": "legacy_session_context_mismatch"})
|
|
449
|
+
|
|
450
|
+
# ``run_id`` is the runtime state's authoritative identity. A fallback to
|
|
451
|
+
# a similarly named extension field would let a malformed or tampered
|
|
452
|
+
# authoritative value be masked by stale secondary data.
|
|
453
|
+
runtime_uuid = runtime.get("run_id")
|
|
454
|
+
if not isinstance(runtime_uuid, str) or not runtime_uuid.strip():
|
|
455
|
+
blockers.append({"gate_id": "identity_coherence", "reason_code": "runtime_run_id_missing"})
|
|
456
|
+
allowed_run_ids: set[str] = set()
|
|
457
|
+
else:
|
|
458
|
+
allowed_run_ids = {runtime_uuid}
|
|
459
|
+
if isinstance(lifecycle_id, str) and lifecycle_id.strip():
|
|
460
|
+
if session_identity is not None:
|
|
461
|
+
allowed_run_ids.update({
|
|
462
|
+
f"{session_identity}-{lifecycle_id}",
|
|
463
|
+
f"lifecycle-{session_identity}-{lifecycle_id}",
|
|
464
|
+
})
|
|
465
|
+
else:
|
|
466
|
+
allowed_run_ids.add(f"lifecycle-{lifecycle_id}")
|
|
467
|
+
|
|
468
|
+
for owner, document, required in (
|
|
469
|
+
("supervisor", supervisor, True),
|
|
470
|
+
("findings", findings, False),
|
|
471
|
+
("current", current, False),
|
|
472
|
+
):
|
|
473
|
+
if not isinstance(document, Mapping):
|
|
474
|
+
continue
|
|
475
|
+
run_id = document.get("run_id")
|
|
476
|
+
if run_id is None and not required:
|
|
477
|
+
continue
|
|
478
|
+
if not isinstance(run_id, str) or not run_id.strip():
|
|
479
|
+
blockers.append({"gate_id": "identity_coherence", "reason_code": f"{owner}_run_id_invalid"})
|
|
480
|
+
elif run_id not in allowed_run_ids:
|
|
481
|
+
blockers.append({"gate_id": "identity_coherence", "reason_code": f"{owner}_run_mismatch"})
|
|
482
|
+
|
|
483
|
+
# findings.json 合法缺失时没有任何 binding 可比对,跳过而非判为缺失。
|
|
484
|
+
if findings_present:
|
|
485
|
+
binding = findings.get("run_binding")
|
|
486
|
+
if not isinstance(binding, dict):
|
|
487
|
+
blockers.append({"gate_id": "identity_coherence", "reason_code": "findings_binding_missing"})
|
|
488
|
+
else:
|
|
489
|
+
binding_run_id = binding.get("run_id")
|
|
490
|
+
if not isinstance(binding_run_id, str) or not binding_run_id.strip():
|
|
491
|
+
blockers.append({"gate_id": "identity_coherence", "reason_code": "findings_run_id_invalid"})
|
|
492
|
+
elif binding_run_id not in allowed_run_ids:
|
|
493
|
+
blockers.append({"gate_id": "identity_coherence", "reason_code": "findings_run_mismatch"})
|
|
494
|
+
if not isinstance(binding.get("lifecycle_id"), str) or binding.get("lifecycle_id") != lifecycle_id:
|
|
495
|
+
blockers.append({"gate_id": "identity_coherence", "reason_code": "findings_lifecycle_mismatch"})
|
|
496
|
+
binding_round = binding.get("round")
|
|
497
|
+
if not _is_json_integer(binding_round, 1):
|
|
498
|
+
blockers.append({"gate_id": "identity_coherence", "reason_code": "findings_round_invalid"})
|
|
499
|
+
elif _is_json_integer(runtime_round, 1) and binding_round != runtime_round:
|
|
500
|
+
blockers.append({"gate_id": "identity_coherence", "reason_code": "findings_round_mismatch"})
|
|
501
|
+
# A shared generation token is the only cross-file indication that the
|
|
502
|
+
# three independently persisted JSON documents belong to one state
|
|
503
|
+
# publication. It is deliberately required in addition to matching
|
|
504
|
+
# identities: without it, a snapshot can combine files from different
|
|
505
|
+
# writes and must remain unproven. ``generation_id`` is retained as the
|
|
506
|
+
# explicit alias used by older state writers; if both aliases are present
|
|
507
|
+
# they must agree exactly. A source that is legitimately absent at this
|
|
508
|
+
# phase contributes no token and therefore no proof obligation.
|
|
509
|
+
generation_names = ("snapshot_generation", "generation_id")
|
|
510
|
+
generations: list[str | None] = []
|
|
511
|
+
for item in (runtime, supervisor, findings):
|
|
512
|
+
if not isinstance(item, Mapping):
|
|
513
|
+
continue
|
|
514
|
+
values = [item[name] for name in generation_names if name in item]
|
|
515
|
+
if not values or any(not isinstance(value, str) or not value.strip() for value in values):
|
|
516
|
+
generations.append(None)
|
|
517
|
+
continue
|
|
518
|
+
if len(set(values)) != 1:
|
|
519
|
+
generations.append(None)
|
|
520
|
+
blockers.append({"gate_id": "identity_coherence", "reason_code": "generation_conflict"})
|
|
521
|
+
continue
|
|
522
|
+
generations.append(values[0])
|
|
523
|
+
if not all(generations):
|
|
524
|
+
blockers.append({"gate_id": "identity_coherence", "reason_code": "generation_unproven"})
|
|
525
|
+
elif len(set(generations)) != 1:
|
|
526
|
+
blockers.append({"gate_id": "identity_coherence", "reason_code": "generation_mismatch"})
|
|
527
|
+
return ("proven" if not blockers else "unproven"), blockers
|
|
528
|
+
|
|
529
|
+
|
|
530
|
+
def _ledger_metadata(reader: RootReader, relative: str, sources: dict[str, SourceSnapshot],
|
|
531
|
+
total: int, watched_absent: list[str]) -> tuple[dict[str, Any], int]:
|
|
532
|
+
"""Capture ledger bytes; only inspect SQLite when it is provably immutable."""
|
|
533
|
+
try:
|
|
534
|
+
present = reader.exists(relative)
|
|
535
|
+
except SnapshotInvalid:
|
|
536
|
+
return {"status": "not_evaluated", "reason_code": "ledger_source_unavailable"}, total
|
|
537
|
+
if not present:
|
|
538
|
+
return {"status": "not_evaluated", "reason_code": "ledger_missing"}, total
|
|
539
|
+
source = reader.read(relative, SNAPSHOT_LIMIT, "sqlite")
|
|
540
|
+
if total + source.size > SNAPSHOT_LIMIT:
|
|
541
|
+
raise SnapshotInvalid("snapshot_size_limit")
|
|
542
|
+
sources[relative] = source
|
|
543
|
+
total += source.size
|
|
544
|
+
sidecars = [relative + suffix for suffix in ("-wal", "-shm", "-journal")]
|
|
545
|
+
for path in sidecars:
|
|
546
|
+
if reader.exists(path):
|
|
547
|
+
return {"status": "not_evaluated", "reason_code": "ledger_sidecar_present"}, total
|
|
548
|
+
watched_absent.append(path)
|
|
549
|
+
# immutable=1 prevents SQLite from creating lock/SHM files. The DB is opened
|
|
550
|
+
# read-only and query_only is enforced before the single read transaction.
|
|
551
|
+
fd = reader._open(relative)
|
|
552
|
+
try:
|
|
553
|
+
fd_path = f"/proc/self/fd/{fd}" if Path("/proc/self/fd").is_dir() else f"/dev/fd/{fd}"
|
|
554
|
+
uri = "file:" + quote(fd_path, safe="/") + "?mode=ro&immutable=1"
|
|
555
|
+
try:
|
|
556
|
+
connection = sqlite3.connect(uri, uri=True, timeout=0, isolation_level=None)
|
|
557
|
+
try:
|
|
558
|
+
connection.execute("PRAGMA query_only=ON")
|
|
559
|
+
connection.execute("BEGIN")
|
|
560
|
+
row = connection.execute(
|
|
561
|
+
"SELECT value FROM meta WHERE key='state_hash' LIMIT 1"
|
|
562
|
+
).fetchone()
|
|
563
|
+
connection.execute("COMMIT")
|
|
564
|
+
return {"status": "captured", "state_hash": row[0] if row else None}, total
|
|
565
|
+
finally:
|
|
566
|
+
connection.close()
|
|
567
|
+
except sqlite3.Error:
|
|
568
|
+
return {"status": "not_evaluated", "reason_code": "ledger_read_unsafe"}, total
|
|
569
|
+
finally:
|
|
570
|
+
os.close(fd)
|
|
571
|
+
|
|
572
|
+
|
|
573
|
+
def capture_snapshot(project_root: str | os.PathLike[str], *,
|
|
574
|
+
required_sources: Collection[str] = ()) -> FrozenSnapshot:
|
|
575
|
+
"""Capture immutable bytes for post preflight without repairing any state.
|
|
576
|
+
|
|
577
|
+
``required_sources`` 把默认可选(``OPTIONAL_SOURCES``)的具名源在本阶段提升
|
|
578
|
+
为必需:可选源缺失时记入 ``watched_absent`` 继续评估,必需源缺失则按
|
|
579
|
+
``source_missing`` fail-closed。
|
|
580
|
+
"""
|
|
581
|
+
required = frozenset(required_sources)
|
|
582
|
+
unknown = required - OPTIONAL_SOURCES
|
|
583
|
+
if unknown:
|
|
584
|
+
raise SnapshotInvalid("source_declaration_invalid")
|
|
585
|
+
root = Path(project_root).expanduser().resolve()
|
|
586
|
+
try:
|
|
587
|
+
import core.bugx_paths as bugx_paths
|
|
588
|
+
scope = bugx_paths.require(root)
|
|
589
|
+
except Exception as exc:
|
|
590
|
+
raise SnapshotInvalid("project_layout_invalid") from exc
|
|
591
|
+
|
|
592
|
+
named_paths = {
|
|
593
|
+
"current": root / ".bugx" / "current.json",
|
|
594
|
+
"runtime": scope.runtime,
|
|
595
|
+
"life": scope.life,
|
|
596
|
+
"supervisor": scope.supervisor,
|
|
597
|
+
"coverage_evidence": scope.coverage,
|
|
598
|
+
"coverage_manifest": scope.state_root / "module-coverage.md",
|
|
599
|
+
"prep": scope.prep_record,
|
|
600
|
+
"findings": scope.lifecycle_root / "findings.json",
|
|
601
|
+
}
|
|
602
|
+
paths = {name: _relative_path(path, root) for name, path in named_paths.items()}
|
|
603
|
+
wal_path = _relative_path(
|
|
604
|
+
scope.life.with_name(f".{scope.life.name}.settlement-wal.json"), root,
|
|
605
|
+
)
|
|
606
|
+
ledger_path = _relative_path(scope.knowledge_db, root)
|
|
607
|
+
reader = RootReader(root)
|
|
608
|
+
sources: dict[str, SourceSnapshot] = {}
|
|
609
|
+
documents: dict[str, Any] = {}
|
|
610
|
+
blockers: list[dict[str, str]] = []
|
|
611
|
+
watched_absent: list[str] = []
|
|
612
|
+
absent_names: set[str] = set()
|
|
613
|
+
total = 0
|
|
614
|
+
observed_at = time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime())
|
|
615
|
+
try:
|
|
616
|
+
limits = {
|
|
617
|
+
"findings": FINDINGS_LIMIT,
|
|
618
|
+
"coverage_manifest": JSON_LIMIT,
|
|
619
|
+
"prep": JSON_LIMIT,
|
|
620
|
+
}
|
|
621
|
+
json_names = {"current", "runtime", "life", "supervisor", "coverage_evidence", "findings"}
|
|
622
|
+
for name, relative in paths.items():
|
|
623
|
+
optional = name in OPTIONAL_SOURCES and name not in required
|
|
624
|
+
try:
|
|
625
|
+
source = reader.read(relative, limits.get(name, JSON_LIMIT), "json" if name in json_names else "text")
|
|
626
|
+
except SnapshotInvalid as exc:
|
|
627
|
+
# 只有"缺失"且本阶段不需要该源时才降级为 watched_absent;
|
|
628
|
+
# 不安全、超限、读到半截等事实一律继续 fail-closed。
|
|
629
|
+
if not optional or exc.reason_code != SOURCE_MISSING:
|
|
630
|
+
raise
|
|
631
|
+
watched_absent.append(relative)
|
|
632
|
+
absent_names.add(name)
|
|
633
|
+
continue
|
|
634
|
+
total += source.size
|
|
635
|
+
if total > SNAPSHOT_LIMIT:
|
|
636
|
+
raise SnapshotInvalid("snapshot_size_limit")
|
|
637
|
+
sources[relative] = source
|
|
638
|
+
if name in json_names:
|
|
639
|
+
documents[name] = _json(source)
|
|
640
|
+
|
|
641
|
+
current = documents["current"]
|
|
642
|
+
if (current.get("polling_id") != scope.polling_root.name
|
|
643
|
+
or current.get("lifecycle_id") != scope.lifecycle_root.name):
|
|
644
|
+
blockers.append({"gate_id": "current_pointer", "reason_code": "current_pointer_mismatch"})
|
|
645
|
+
|
|
646
|
+
if reader.exists(wal_path):
|
|
647
|
+
source = reader.read(wal_path, JSON_LIMIT, "json")
|
|
648
|
+
total += source.size
|
|
649
|
+
if total > SNAPSHOT_LIMIT:
|
|
650
|
+
raise SnapshotInvalid("snapshot_size_limit")
|
|
651
|
+
sources[wal_path] = source
|
|
652
|
+
try:
|
|
653
|
+
documents["settlement_wal"] = _json(source)
|
|
654
|
+
except SnapshotInvalid:
|
|
655
|
+
blockers.append({"gate_id": "settlement_wal", "reason_code": "settlement_wal_invalid"})
|
|
656
|
+
blockers.append({"gate_id": "settlement_wal", "reason_code": "pending_settlement_wal"})
|
|
657
|
+
else:
|
|
658
|
+
watched_absent.append(wal_path)
|
|
659
|
+
|
|
660
|
+
# Capture every artifact referenced by persisted claims, receipts, or
|
|
661
|
+
# coverage records. Each artifact is hashed from the same bytes retained.
|
|
662
|
+
artifact_expectations: dict[str, set[str]] = {}
|
|
663
|
+
for document in (documents.get("supervisor"), documents.get("coverage_evidence"), documents.get("findings")):
|
|
664
|
+
for artifact, expected in _referenced_artifacts(document):
|
|
665
|
+
candidate = PurePosixPath(artifact)
|
|
666
|
+
if candidate.is_absolute() or "\\" in artifact or any(part in {"", ".", ".."} for part in candidate.parts):
|
|
667
|
+
blockers.append({"gate_id": "artifact_binding", "reason_code": "artifact_path_invalid"})
|
|
668
|
+
continue
|
|
669
|
+
relative = candidate.as_posix()
|
|
670
|
+
if expected is not None:
|
|
671
|
+
artifact_expectations.setdefault(relative, set()).add(expected.lower())
|
|
672
|
+
else:
|
|
673
|
+
blockers.append({"gate_id": "artifact_binding", "reason_code": "artifact_hash_missing"})
|
|
674
|
+
if relative in sources:
|
|
675
|
+
continue
|
|
676
|
+
source = reader.read(relative, ARTIFACT_LIMIT, "artifact")
|
|
677
|
+
total += source.size
|
|
678
|
+
if total > SNAPSHOT_LIMIT:
|
|
679
|
+
raise SnapshotInvalid("snapshot_size_limit")
|
|
680
|
+
sources[relative] = source
|
|
681
|
+
for artifact, expected_hashes in artifact_expectations.items():
|
|
682
|
+
actual = sources.get(artifact)
|
|
683
|
+
if not actual:
|
|
684
|
+
blockers.append({"gate_id": "artifact_binding", "reason_code": "artifact_missing"})
|
|
685
|
+
elif len(expected_hashes) != 1 or actual.sha256 not in expected_hashes:
|
|
686
|
+
blockers.append({"gate_id": "artifact_binding", "reason_code": "artifact_hash_mismatch"})
|
|
687
|
+
|
|
688
|
+
try:
|
|
689
|
+
ledger_present = reader.exists(ledger_path)
|
|
690
|
+
except SnapshotInvalid:
|
|
691
|
+
ledger_present = None
|
|
692
|
+
if ledger_present is False:
|
|
693
|
+
watched_absent.append(ledger_path)
|
|
694
|
+
ledger, total = _ledger_metadata(reader, ledger_path, sources, total, watched_absent)
|
|
695
|
+
documents["lesson_ledger"] = ledger
|
|
696
|
+
if total > SNAPSHOT_LIMIT:
|
|
697
|
+
raise SnapshotInvalid("snapshot_size_limit")
|
|
698
|
+
|
|
699
|
+
# The captured Supervisor JSON contains claims, receipt history and the
|
|
700
|
+
# authoritative finding seal/history; retain those exact bytes once.
|
|
701
|
+
if not verify_supervisor_history(documents.get("supervisor")):
|
|
702
|
+
blockers.append({"gate_id": "supervisor_history", "reason_code": "supervisor_history_seal_invalid"})
|
|
703
|
+
findings_relative = paths["findings"]
|
|
704
|
+
seal_reason = _verify_findings_seal(
|
|
705
|
+
documents.get("runtime"), documents.get("supervisor"),
|
|
706
|
+
sources.get(findings_relative),
|
|
707
|
+
)
|
|
708
|
+
if seal_reason:
|
|
709
|
+
blockers.append({"gate_id": "findings_seal", "reason_code": seal_reason})
|
|
710
|
+
coherence, identity_blockers = _identity_coherence(
|
|
711
|
+
documents, current, absent_sources=absent_names,
|
|
712
|
+
)
|
|
713
|
+
blockers.extend(identity_blockers)
|
|
714
|
+
|
|
715
|
+
# Reopen every captured path and compare both identity and content.
|
|
716
|
+
for relative, captured in sources.items():
|
|
717
|
+
check = reader.read(relative, captured.limit, captured.kind)
|
|
718
|
+
if (check.device, check.inode, check.sha256) != (
|
|
719
|
+
captured.device, captured.inode, captured.sha256,
|
|
720
|
+
):
|
|
721
|
+
raise SnapshotInvalid("source_changed_after_capture")
|
|
722
|
+
# 缺失判定同样是断言:被观察为缺失的可选源若在重检时出现,快照即不可信。
|
|
723
|
+
for relative in watched_absent:
|
|
724
|
+
if reader.exists(relative):
|
|
725
|
+
raise SnapshotInvalid("source_changed_after_capture")
|
|
726
|
+
|
|
727
|
+
snapshot = FrozenSnapshot(
|
|
728
|
+
root=root,
|
|
729
|
+
observed_at=observed_at,
|
|
730
|
+
snapshot_id=_snapshot_id(sources),
|
|
731
|
+
sources=MappingProxyType(dict(sources)),
|
|
732
|
+
documents=_deep_freeze(documents),
|
|
733
|
+
coherence=coherence,
|
|
734
|
+
blockers=tuple(MappingProxyType(dict(item)) for item in blockers),
|
|
735
|
+
watched_absent=tuple(sorted(watched_absent, key=lambda item: item.encode("utf-8"))),
|
|
736
|
+
)
|
|
737
|
+
return snapshot
|
|
738
|
+
finally:
|
|
739
|
+
reader.close()
|
|
740
|
+
|
|
741
|
+
|
|
742
|
+
def evaluate_snapshot(snapshot: FrozenSnapshot) -> dict[str, Any]:
|
|
743
|
+
"""Purely evaluate captured state; it does not access the filesystem."""
|
|
744
|
+
coherence_proven = snapshot.coherence == "proven"
|
|
745
|
+
gates: list[dict[str, str]] = [
|
|
746
|
+
{"gate_id": "snapshot_integrity", "status": "passed", "reason_code": "snapshot_stable"},
|
|
747
|
+
{
|
|
748
|
+
"gate_id": "coherence",
|
|
749
|
+
"status": "passed" if coherence_proven else "blocked",
|
|
750
|
+
"reason_code": "coherence_proven" if coherence_proven else "coherence_unproven",
|
|
751
|
+
},
|
|
752
|
+
]
|
|
753
|
+
for gate_id in (
|
|
754
|
+
"current_pointer", "settlement_wal", "supervisor_history", "findings_seal",
|
|
755
|
+
"identity_coherence", "artifact_binding",
|
|
756
|
+
):
|
|
757
|
+
found = [item for item in snapshot.blockers if item["gate_id"] == gate_id]
|
|
758
|
+
if found:
|
|
759
|
+
for item in found:
|
|
760
|
+
gates.append({"gate_id": gate_id, "status": "blocked", "reason_code": item["reason_code"]})
|
|
761
|
+
elif gate_id in {"current_pointer", "settlement_wal", "supervisor_history"}:
|
|
762
|
+
gates.append({"gate_id": gate_id, "status": "passed", "reason_code": f"{gate_id}_consistent"})
|
|
763
|
+
else:
|
|
764
|
+
gates.append({"gate_id": gate_id, "status": "not_evaluated", "reason_code": "binding_not_proven"})
|
|
765
|
+
if snapshot.documents.get("lesson_ledger", {}).get("status") == "captured":
|
|
766
|
+
gates.append({"gate_id": "lesson_ledger", "status": "passed", "reason_code": "ledger_metadata_readonly"})
|
|
767
|
+
else:
|
|
768
|
+
gates.append({"gate_id": "lesson_ledger", "status": "not_evaluated", "reason_code": snapshot.documents.get("lesson_ledger", {}).get("reason_code", "ledger_unavailable")})
|
|
769
|
+
known_blockers = [dict(item) for item in snapshot.blockers]
|
|
770
|
+
if not coherence_proven:
|
|
771
|
+
known_blockers.append({"gate_id": "coherence", "reason_code": "coherence_unproven"})
|
|
772
|
+
blocked = any(item["status"] == "blocked" for item in gates)
|
|
773
|
+
status = (
|
|
774
|
+
"passed" if coherence_proven and not blocked
|
|
775
|
+
else ("blocked" if snapshot.blockers else "unproven")
|
|
776
|
+
)
|
|
777
|
+
return {
|
|
778
|
+
"snapshot_id": snapshot.snapshot_id,
|
|
779
|
+
"observed_at": snapshot.observed_at,
|
|
780
|
+
"source_hashes": {path: source.sha256 for path, source in sorted(snapshot.sources.items())},
|
|
781
|
+
"watched_absent": list(snapshot.watched_absent),
|
|
782
|
+
"coherence": snapshot.coherence,
|
|
783
|
+
"status": status,
|
|
784
|
+
"gates": gates,
|
|
785
|
+
"known_blockers": known_blockers,
|
|
786
|
+
"not_evaluated": list(snapshot.not_evaluated),
|
|
787
|
+
"guarantee": GUARANTEE,
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
|
|
791
|
+
def blocked_report(reason_code: str) -> dict[str, Any]:
|
|
792
|
+
"""构造 fail-closed 的中止报告;``reason_code`` 只含稳定码,不含主机路径。"""
|
|
793
|
+
return {
|
|
794
|
+
"snapshot_id": None,
|
|
795
|
+
"observed_at": time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime()),
|
|
796
|
+
"source_hashes": {},
|
|
797
|
+
"watched_absent": [],
|
|
798
|
+
"coherence": "unproven",
|
|
799
|
+
"status": "blocked",
|
|
800
|
+
"gates": [{"gate_id": "snapshot_integrity", "status": "blocked", "reason_code": reason_code}],
|
|
801
|
+
"known_blockers": [{"gate_id": "snapshot_integrity", "reason_code": reason_code}],
|
|
802
|
+
"not_evaluated": list(NOT_EVALUATED),
|
|
803
|
+
"guarantee": GUARANTEE,
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
|
|
807
|
+
def post_dry_run(project_root: str | os.PathLike[str], *,
|
|
808
|
+
required_sources: Collection[str] = ()) -> DryRunResult:
|
|
809
|
+
"""Capture and evaluate a read-only post preflight snapshot."""
|
|
810
|
+
try:
|
|
811
|
+
snapshot = capture_snapshot(project_root, required_sources=required_sources)
|
|
812
|
+
except SnapshotInvalid as exc:
|
|
813
|
+
return DryRunResult(report=blocked_report(exc.reason_code))
|
|
814
|
+
except Exception:
|
|
815
|
+
return DryRunResult(report=blocked_report("snapshot_capture_error"))
|
|
816
|
+
return DryRunResult(report=evaluate_snapshot(snapshot), snapshot=snapshot)
|
|
817
|
+
|