bugx-cli 0.1.1__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.
- bugx_cli/__init__.py +6 -0
- bugx_cli/cli.py +1685 -0
- bugx_cli/commands/__init__.py +1 -0
- bugx_cli/commands/advisory.py +94 -0
- bugx_cli/commands/agent.py +4210 -0
- bugx_cli/commands/audit.py +632 -0
- bugx_cli/commands/autonomous.py +260 -0
- bugx_cli/commands/cloud.py +1371 -0
- bugx_cli/commands/daemon.py +50 -0
- bugx_cli/commands/doctor.py +1590 -0
- bugx_cli/commands/goal.py +107 -0
- bugx_cli/commands/interaction.py +248 -0
- bugx_cli/commands/knowledge.py +619 -0
- bugx_cli/commands/lifecycle.py +2763 -0
- bugx_cli/commands/patch.py +1014 -0
- bugx_cli/commands/plugin.py +2749 -0
- bugx_cli/commands/plugin_claude.py +1446 -0
- bugx_cli/commands/plugin_cline.py +269 -0
- bugx_cli/commands/plugin_codex.py +74 -0
- bugx_cli/commands/plugin_funide.py +729 -0
- bugx_cli/commands/plugin_qoder.py +216 -0
- bugx_cli/commands/plugin_zcode.py +710 -0
- bugx_cli/commands/project.py +670 -0
- bugx_cli/commands/report.py +256 -0
- bugx_cli/commands/skill.py +251 -0
- bugx_cli/commands/stats.py +133 -0
- bugx_cli/commands/system.py +2567 -0
- bugx_cli/common.py +906 -0
- bugx_cli/host_adapters.py +1892 -0
- bugx_cli/hosts/__init__.py +80 -0
- bugx_cli/hosts/base.py +99 -0
- bugx_cli/hosts/registry.py +573 -0
- bugx_cli/hosts/template_engine.py +188 -0
- bugx_cli/infra/__init__.py +209 -0
- bugx_cli/infra/ai_advisor.py +851 -0
- bugx_cli/infra/engine_installer.py +1945 -0
- bugx_cli/infra/host_sync.py +548 -0
- bugx_cli/infra/mcp_advisor.py +826 -0
- bugx_cli/infra/security.py +339 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/bugx-mcp-manifest.json +53 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/CATALOG.json +141 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/README.md +254 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/adapters/README.md +35 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/adapters/android-interaction.json +81 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/adapters/android.json +24 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/adapters/desktop-macos.json +20 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/adapters/ios-interaction.json +34 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/adapters/ios.json +23 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/adapters/memory-macos.json +24 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/agent/README.md +51 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/agent/__init__.py +146 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/agent/agent_artifacts.py +766 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/agent/agent_eval.py +1155 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/agent/agent_execution.py +718 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/agent/agent_orchestrator.py +1351 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/agent/agent_targets.py +877 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/agent/agent_workspace.py +770 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/agent/feature_baseline.py +150 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/assets/README.md +24 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/assets/axe-core/LICENSE-3RD-PARTY.txt +66 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/assets/axe-core/LICENSE.txt +362 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/assets/axe-core/UPSTREAM.md +10 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/assets/axe-core/axe.min.js +12 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/assets/bugx-avatar-1024.png +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/assets/bugx-avatar-512.png +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/assets/bugx-avatar-tight.svg +23 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/assets/bugx-avatar.svg +28 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/assets/bugx-hero-cn.png +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/assets/bugx-hero-en.png +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/assets/bugx-hero-en.svg +74 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/assets/bugx-hero-zh.svg +74 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/assets/codex.png +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/assets/dsh.png +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/assets/project-layout.md +42 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/assets/zcode.png +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/README.md +37 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/data-audit/manifest.json +94 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/data-audit/stages/00-scope.md +14 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/data-audit/stages/10-schema-inventory.md +14 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/data-audit/stages/20-query-and-integrity.md +14 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/data-audit/stages/80-evidence-regression.md +14 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/desktop-audit/manifest.json +123 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/desktop-audit/stages/00-scope.md +15 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/desktop-audit/stages/10-process-model.md +14 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/desktop-audit/stages/20-package-integrity.md +15 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/desktop-audit/stages/30-ui-behavior.md +14 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/desktop-audit/stages/80-evidence-regression.md +15 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/memory-testing.md +227 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/mobile-audit/manifest.json +155 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/mobile-audit/modules/android.md +19 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/mobile-audit/modules/h5.md +18 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/mobile-audit/modules/ios.md +25 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/mobile-audit/modules/miniprogram.md +26 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/mobile-audit/modules/webview.md +18 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/mobile-audit/stages/00-scope.md +14 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/mobile-audit/stages/10-platform-inventory.md +14 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/mobile-audit/stages/20-masvs-static.md +20 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/mobile-audit/stages/30-component-exposure.md +14 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/mobile-audit/stages/40-device-behavior.md +14 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/mobile-audit/stages/80-evidence-regression.md +13 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/native-audit/manifest.json +127 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/native-audit/stages/00-scope.md +14 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/native-audit/stages/10-static-white-box.md +14 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/native-audit/stages/20-memory-concurrency.md +15 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/native-audit/stages/30-behavior-black-box.md +39 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/native-audit/stages/80-evidence-regression.md +14 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/platform-testing.md +174 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/web-audit/manifest.json +191 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/web-audit/modules/graphql.md +5 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/web-audit/modules/h5.md +18 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/web-audit/modules/multi-tenant.md +4 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/web-audit/modules/oauth.md +4 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/web-audit/modules/upload.md +4 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/web-audit/modules/websocket.md +4 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/web-audit/stages/00-scope.md +13 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/web-audit/stages/10-discovery.md +13 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/web-audit/stages/20-auth-session.md +13 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/web-audit/stages/30-authz-business.md +13 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/web-audit/stages/40-input-output.md +13 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/web-audit/stages/50-state-async.md +13 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/web-audit/stages/60-file-ssrf-deser.md +12 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/web-audit/stages/70-config-dependency.md +12 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/web-audit/stages/80-evidence-regression.md +12 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/autonomous_cve/INTERFACE.md +61 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/autonomous_cve/README.md +58 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/autonomous_cve/SPEC.md +25 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/autonomous_cve/__init__.py +109 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/autonomous_cve/attack_graph.py +1096 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/autonomous_cve/attack_graph_store.py +1868 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/autonomous_cve/audit_campaign.py +1232 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/autonomous_cve/behavior_graph.py +465 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/autonomous_cve/ghsa_advisories.py +174 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/autonomous_cve/models.py +93 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/autonomous_cve/mutator.py +87 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/autonomous_cve/patcher.py +126 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/autonomous_cve/scout.py +278 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/autonomous_cve/synthesizer.py +207 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/autonomous_cve/verifier.py +103 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/bugx.md +1299 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/bugx_paths.py +1881 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/cli-help.txt +66 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/cloud_sync/INTERFACE.md +32 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/cloud_sync/README.md +62 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/cloud_sync/SPEC.md +25 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/cloud_sync/__init__.py +23 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/cloud_sync/auto_sync.py +398 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/cloud_sync/cloud_client.py +1218 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/cloud_sync/cloud_onboard.py +743 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/cloud_sync/cloud_schema.py +648 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/cloud_sync/consent.py +81 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/cloud_sync/device_identity.py +307 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/cloud_sync/endpoint_router.py +415 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/cloud_sync/flywheel_client.py +769 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/cloud_sync/network_transport.py +296 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/cloud_sync/onboard_wizard.py +493 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/cloud_sync/sensitive_filter.py +285 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/cloud_sync/sync_pull.py +695 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/cloud_sync/sync_push.py +723 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/contracts/AGENT_GUIDE.md +359 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/contracts/README.md +34 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/contracts/bugx-blackbox.md +541 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/contracts/bugx-opencode.md +469 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/contracts/bugx-quick.md +44 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/contracts/bugx-runtime-contract.md +353 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/contracts/bugx-worker.md +470 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/contracts/engine_gap_contracts.py +473 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/coverage/README.md +70 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/coverage/__init__.py +106 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/coverage/coverage_ai_review.py +185 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/coverage/coverage_backfill.py +54 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/coverage/coverage_bootstrap.py +713 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/coverage/coverage_business.py +36 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/coverage/coverage_cli.py +715 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/coverage/coverage_discovery.py +1429 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/coverage/coverage_evidence.py +1024 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/coverage/coverage_forensics.py +124 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/coverage/coverage_gate.py +277 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/coverage/coverage_intelligence.py +734 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/coverage/coverage_manifest.py +396 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/coverage/coverage_platform.py +77 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/coverage/coverage_validate.py +241 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/coverage/module_coverage.py +157 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/dev_harness/INTERFACE.md +20 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/dev_harness/README.md +21 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/dev_harness/SPEC.md +25 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/dev_harness/__init__.py +5 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/dev_harness/interaction_preset.py +408 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/engine-integrity.json +2797 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/fuzzing/README.md +49 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/fuzzing/__init__.py +82 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/fuzzing/concurrency_fuzzer.py +435 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/fuzzing/differential_oracle.py +1164 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/fuzzing/fuzz_input.py +1291 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/fuzzing/stateful_fuzzer.py +404 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/governance/README.md +61 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/governance/__init__.py +130 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/governance/capacity_planner.py +124 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/governance/dependency_lock.py +317 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/governance/goal_governor.py +754 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/governance/guide_budget.py +458 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/governance/lockdown.sh +50 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/governance/readonly_enforcer.py +154 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/governance/runtime_tool_gate.py +373 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/governance/secret_redactor.py +784 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/governance/token_budget.py +38 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_acp/INTERFACE.md +36 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_acp/README.md +51 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_acp/SPEC.md +25 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_acp/__init__.py +121 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_acp/base.py +111 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_acp/claude.py +99 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_acp/cline.py +298 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_acp/codex.py +300 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_acp/dsh.py +106 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_acp/opencode.py +209 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_acp/pi.py +94 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_acp/zcode.py +99 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_runtime/INTERFACE.md +24 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_runtime/README.md +62 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_runtime/SPEC.md +25 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_runtime/__init__.py +21 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_runtime/adapters.py +412 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_runtime/autonomous_runner.py +1152 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_runtime/cline.py +448 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_runtime/common.py +103 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_runtime/free_models.py +786 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_runtime/host_bootstrap.py +389 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_runtime/host_evaluators.py +761 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_runtime/host_probe.py +41 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_runtime/host_provider_arbitrator.py +831 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_runtime/host_registry.py +662 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_runtime/host_usage.py +127 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_runtime/mcp_process_tracker.py +509 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_runtime/mcp_registry_gate.py +379 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_runtime/pi.py +102 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_runtime/provider_facts.py +66 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/hosts/INTERFACE.md +51 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/hosts/README.md +67 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/hosts/SPEC.md +25 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/hosts/__init__.py +140 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/hosts/_base_usage.py +152 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/hosts/_codex_usage.py +297 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/hosts/_dsh_usage.py +184 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/hosts/_mcp_toml.py +365 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/hosts/_zcode_usage.py +269 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/hosts/base.py +479 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/hosts/claude.py +212 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/hosts/cline.py +229 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/hosts/codex.py +1006 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/hosts/dsh.py +526 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/hosts/opencode.py +358 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/hosts/pi.py +308 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/hosts/zcode.py +219 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/i18n.py +252 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/infra/README.md +41 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/infra/__init__.py +17 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/infra/build_info.py +105 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/infra/client_metadata.py +185 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/infra/json_utils.py +22 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/infra/python_runtime.py +540 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/infra/safe_xml.py +221 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_bugx.py +118 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/INTERFACE.md +31 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/README.md +106 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/SPEC.md +25 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/__init__.py +29 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/candidate_revalidation.py +484 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/common.py +1060 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/finding_confirm_phase.py +391 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/finding_settlement.py +1432 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/findings_adjudication.py +666 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/findings_snapshot.py +357 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/judge_phase.py +848 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/lesson_context.py +536 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/lifecycle_reporter.py +627 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/orchestrator_controls.py +686 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/post_commit.py +567 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/post_coverage_sync.py +598 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/post_dry_run.py +817 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/post_observability.py +367 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/post_phase.py +1223 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/post_receipt.py +373 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/post_round_lifecycle.py +786 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/pre_phase.py +1029 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/pre_recon_scout.py +879 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/pre_state_builder.py +1133 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/report_sharing.py +414 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/round_orchestrator.py +1116 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/session_runtime.py +1670 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/startup_gates.py +1050 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/startup_interaction.py +1003 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/startup_version_gate.py +879 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/supervisor_bridge.py +1253 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/supervisor_coverage.py +423 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/supervisor_degraded.py +1211 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/worker_barriers.py +424 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/worker_orchestrator.py +1246 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/worker_prior.py +749 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/INTERFACE.md +35 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/README.md +160 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/SPEC.md +25 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/__init__.py +67 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/_facade.py +227 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/archive_ops.py +630 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/auto_materialization.py +459 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/bug-log.md +22 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/cli.py +275 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/export_ops.py +554 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/finding_confirmation.py +1316 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/finding_io.py +299 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/finding_lifecycle.py +730 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/finding_verification.py +405 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/incidents.py +1005 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/lesson-replay-cases.json +20 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/lesson_ledger.py +241 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/lesson_replay.py +272 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/life_ledger.py +668 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/mistake-book.md +130 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/patterns.py +684 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/receipt_contract.py +269 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/schema.py +1192 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/sync_ops.py +940 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/tool_experience.py +683 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/verify_life.py +1597 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/lesson-ledger.json +275 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/locales/README.md +19 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/locales/en-US.json +462 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/locales/zh-CN.json +462 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/mcp_handlers/INTERFACE.md +75 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/mcp_handlers/README.md +62 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/mcp_handlers/SPEC.md +25 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/mcp_handlers/__init__.py +128 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/mcp_handlers/base.py +717 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/mcp_handlers/channel_lifecycle.py +751 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/mcp_handlers/graph_handlers.py +222 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/mcp_handlers/knowledge_handlers.py +536 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/mcp_handlers/mining_handlers.py +586 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/mcp_handlers/resource_prompt_table.py +116 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/mcp_handlers/retrieval_handlers.py +249 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/mcp_handlers/rpc_server.py +470 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/mcp_handlers/supervisor_handlers.py +1461 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/mcp_handlers/telemetry_handlers.py +227 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/mcp_handlers/tool_table.py +1030 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/mcp_runtime_support/README.md +21 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/mcp_runtime_support/__init__.py +1 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/mcp_runtime_support/common.py +363 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/mcp_runtime_support/environment.py +567 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/mcp_runtime_support/verifier.py +758 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/metadata.txt +4 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/planning/README.md +157 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/planning/__init__.py +242 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/planning/capability_plan.py +187 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/planning/capability_planner.py +195 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/planning/domain_archetype.py +542 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/planning/domain_router.py +269 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/planning/dynamic_flow_analyzer.py +533 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/planning/impact_pruner.py +435 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/planning/intent_adjudicator.py +175 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/planning/judge_pipeline.py +1246 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/planning/logic_analysis.py +419 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/planning/prompt_harness.py +1704 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/planning/source_inspector.py +267 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/planning/spec_harvester.py +449 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/planning/target_sandbox_manager.py +573 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/planning/test_capability_verifier.py +1364 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/planning/tools-kb.md +38 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/planning/unit_kind.py +122 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/INTERFACE.md +83 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/README.md +51 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/SPEC.md +36 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/__init__.py +76 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/android_probe.py +552 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/base.py +147 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/codebase_memory_probe.py +647 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/desktop_probe.py +342 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/differential_probe.py +434 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/efficiency_probe.py +232 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/ios_binary_probe.py +472 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/memory_probe.py +392 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/miniprogram_probe.py +385 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/mobile_probe.py +466 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/native_probe.py +302 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/openwiki_probe.py +263 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/pattern_probe.py +453 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/platform_probe.py +424 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/probe_registry.py +1770 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/sast_fixture_corpus.py +340 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/sast_probe.py +1510 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/sast_rules.py +1481 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/sca_scanner.py +779 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/ui_accessibility.py +149 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/ui_audit.py +513 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/ui_contract.py +273 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/ui_evidence.py +212 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/ui_measurements.py +314 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/ui_repair.py +250 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/ui_review.py +133 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/ui_storybook.py +107 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/ui_tokens.py +185 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/ui_visual_diff.py +131 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/web_probe.py +714 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/project_profiler/INTERFACE.md +62 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/project_profiler/README.md +53 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/project_profiler/SPEC.md +28 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/project_profiler/__init__.py +201 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/project_profiler/arbitrator.py +316 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/project_profiler/constants.py +247 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/project_profiler/detector.py +399 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/project_profiler/extractors.py +836 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/project_profiler/fingerprint.py +116 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/project_profiler/storage.py +258 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/project_profiler/strategy.py +301 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/prompts/README.md +35 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/prompts/codex_dialog_dispatch.md +9 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/prompts/command_routing_en.md +42 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/prompts/command_routing_zh.md +42 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/prompts/l0_router.md +47 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/prompts/rules/anti_patterns.md +16 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/prompts/rules/concurrency_rules.md +14 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/prompts/rules/memory_leak_rules.md +13 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/prompts/rules/prompt_injection_defense.md +13 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/prompts/stages/stage_explore.md +31 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/prompts/stages/stage_gate.md +43 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/prompts/stages/stage_mutate.md +42 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/prompts/stages/stage_repair.md +85 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/repair/README.md +74 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/repair/__init__.py +169 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/repair/fix_watchlist.py +391 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/repair/l7_dynamic.py +418 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/repair/l7_repair_loop.py +462 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/repair/l7_selfcheck.py +862 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/repair/minimize_repro.py +466 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/repair/patch_synthesizer.py +617 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/repair/regression_pack.py +379 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/repair/rsi_fixer.py +910 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/repair/rsi_loop.py +311 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/repair/rsi_repair.py +348 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/repair/rsi_rounds.py +212 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/repair/rsi_scope.py +281 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/repair/self_heal.py +604 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/repair/test_generator.py +1108 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/repair/test_quality_auditor.py +410 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/repair/test_strategy.py +511 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/report_engine/INTERFACE.md +59 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/report_engine/README.md +69 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/report_engine/SPEC.md +28 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/report_engine/__init__.py +47 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/report_engine/attestation.py +228 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/report_engine/authority.py +255 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/report_engine/finding_report.py +418 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/report_engine/formal_report_builder.py +924 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/report_engine/html_renderers.py +696 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/report_engine/models.py +759 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/report_engine/pdf_exporter.py +231 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/report_engine/projects_assets.py +730 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/report_engine/report_client.py +743 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/report_engine/report_data_builder.py +388 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/report_engine/report_share.py +459 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/report_engine/sast_bridge.py +116 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/report_engine/server.py +832 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/report_engine/visual_report_builder.py +796 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/report_engine/web-conformance.md +168 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/report_engine/web_conformance.py +428 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/report_engine/workbench_assets.py +484 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/retrieval/INTERFACE.md +20 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/retrieval/README.md +161 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/retrieval/SPEC.md +25 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/retrieval/__init__.py +3 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/retrieval/code_analyzer.py +1720 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/retrieval/codebase_memory_bridge.py +337 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/retrieval/context_assembler.py +240 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/retrieval/corpus_fetch.py +369 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/retrieval/graph_ego.py +597 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/retrieval/knowledge_auto.py +662 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/retrieval/knowledge_sources.py +168 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/retrieval/knowledge_sync.py +1003 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/retrieval/memory_store.py +480 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/retrieval/query_planner.py +1020 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/retrieval/rrf_engine.py +137 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/retrieval/slice_extractor.py +1209 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/retrieval/slice_normalizer.py +373 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/retrieval/slice_spec.py +357 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/retrieval/symbol_index.py +1151 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/retrieval/universal_code_matcher.py +622 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/retrieval/xerj_bridge.py +476 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/retrieval/xerj_supervisor.py +362 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/README.md +33 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/ios/PROVENANCE.json +30 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/ios/crypto.yaml +36 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/ios/network.yaml +20 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/ios/resilience.yaml +47 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/ios/storage.yaml +48 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/LICENSE +173 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/PROVENANCE.json +270 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-asymmetric-key-pair-used-for-multiple-purposes.yml +13 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-backup-manifest.yml +24 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-biometric-event-bound.yml +49 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-biometric-invalidated-enrollment.yml +11 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-biometric-no-confirmation-required.yml +10 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-biometric-validity-duration.yml +24 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-broken-encryption-algorithms.yaml +9 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-broken-encryption-modes.yaml +13 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-content-provider-exported.yml +35 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-custom-deeplink-scheme.yml +29 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-dangerous-app-permissions.yaml +65 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-data-unencrypted-shared-storage-no-user-interaction-apis.yml +36 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-data-unencrypted-shared-storage-no-user-interaction-manifest.yml +15 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-debuggable-flag.yml +10 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-debugger-checks.yml +12 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-deeplink-autoverify-missing.yml +33 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-deeplink-unvalidated-parameter.yml +11 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-device-passcode-present.yml +17 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-fileprovider-broad-scope.yml +46 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-hardcoded-crypto-keys-usage.yml +14 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-hardcoded-security-provider.yaml +18 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-implicit-intent-internal-communication.yml +30 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-implicit-intent-leaking-extras.yml +29 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-input-field-usage.yml +11 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-key-generation-with-insufficient-key-length.yml +21 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-keyboard-cache-input-types.yml +10 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-local-storage-input-validation.yml +48 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-native-debugger-checks.yml +12 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-network-checkservertrusted.yml +12 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-network-hostname-verification.yml +11 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-network-insecure-trust-anchors.yml +11 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-network-onreceivedsslerror.yml +12 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-non-random-use.yml +16 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-object-deserialization.yml +14 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-overlay-protection.yml +68 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-pendingintent-mutable.yml +39 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-random-apis-insufficient-entropy.yml +17 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-root-detection.yaml +59 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-sdk-version.yml +10 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-sensitive-data-in-notifications-manifest.yml +17 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-sensitive-data-in-notifications.yml +11 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-sensitive-data-in-screenshot.yml +18 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-sql-injection-contentprovider.yml +17 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-ssl-socket-hostnameverifier.yml +15 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-strictmode.yml +10 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-system-alert-window.yml +9 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-webview-allow-local-access.yml +15 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-webview-bridges.yml +28 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-webview-safebrowsing.yml +20 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-webview-url-handlers.yml +41 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/miniprogram/PROVENANCE.json +26 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/miniprogram/network.yaml +37 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/miniprogram/platform.yaml +36 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/miniprogram/storage.yaml +48 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mobsfscan-swift/LICENSE +165 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mobsfscan-swift/PROVENANCE.json +58 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mobsfscan-swift/auth.yaml +59 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mobsfscan-swift/crypto.yaml +66 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mobsfscan-swift/jailbreak.yaml +14 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mobsfscan-swift/keyboard.yaml +34 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mobsfscan-swift/logging.yaml +23 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mobsfscan-swift/network.yaml +55 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mobsfscan-swift/resilience.yaml +29 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mobsfscan-swift/secrets.yaml +33 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mobsfscan-swift/storage.yaml +29 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mobsfscan-swift/webview.yaml +32 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/README.md +198 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/__init__.py +3 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/bugx_logging.py +1464 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/daemon_runner.py +623 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/fixture_solidify.py +444 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/global_telemetry.py +549 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/incident_eval.py +148 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/interaction.py +605 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/interaction_store.py +435 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/interactive_menu.py +95 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/log_analytics.py +922 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/mining_quality_framework.py +1387 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/model_runner.py +732 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/platform_adapter.py +579 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/prep_validate.py +478 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/project_graph.py +827 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/project_init.py +481 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/project_profile.py +224 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/project_settings.py +964 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/provider_window.py +97 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/resume_ticket.py +115 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/scenario_eval.py +856 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/seed_drill.py +549 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/self_audit.py +550 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/session_profile.py +205 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/setup_ui_env.py +229 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/startup_environment.py +859 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/sync_store.py +1421 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/tool_install_targets.py +18 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/schemas/README.md +35 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/schemas/agent-graph.schema.json +368 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/schemas/attack-graph.schema.json +88 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/schemas/evidence-bundle.schema.json +33 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/schemas/skill-pack.schema.json +230 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/schemas/worker-checkpoint.schema.json +119 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/secure_atomic.py +289 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/seed_corpus/README.md +55 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/seed_corpus/c.txt +29 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/seed_corpus/cpp.txt +32 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/seed_corpus/css.txt +70 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/seed_corpus/go.txt +46 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/seed_corpus/java.txt +30 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/seed_corpus/javascript.txt +55 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/seed_corpus/kotlin.txt +28 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/seed_corpus/python.txt +71 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/seed_corpus/rust.txt +53 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/seed_corpus/swift.txt +29 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/seed_corpus/typescript.txt +29 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/skills/README.md +53 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/skills/__init__.py +189 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/skills/bugx_docs_mcp_server.py +418 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/skills/bugx_mcp_server.py +1161 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/skills/mcp_runtime.py +968 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/skills/mcp_session_proof.py +605 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/skills/mobile_ui_inspector.py +405 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/skills/skill_pack.py +1214 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/skills/skill_synthesizer.py +1153 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/skills/tools_kb.py +313 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/INTERFACE.md +121 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/README.md +209 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/SPEC.md +25 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/__init__.py +175 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/audit_supervisor.py +1015 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/budget_governor.py +1254 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/checkpoint_handler.py +368 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/checkpoint_pipeline.py +1564 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/checkpoint_sync.py +653 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/claim_events.py +74 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/claim_sync.py +590 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/cli.py +812 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/context_sync.py +55 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/coverage_sync.py +115 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/finding_commit.py +470 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/finding_sync.py +688 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/finding_workflow.py +676 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/finish_policy.py +224 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/finish_sync.py +185 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/graph_sync.py +669 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/lease_manager.py +788 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/lifecycle_blocks.py +129 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/next_round_sync.py +126 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/observability.py +140 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/recovery_sync.py +165 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/rejection_remedies.py +355 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/round_governor.py +306 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/serial_authorization.py +544 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/start_sync.py +87 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/state_store.py +249 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/supervisor_host.py +511 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/supervisor_models.py +1143 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/systemic_failure.py +104 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/task_scheduler.py +1640 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/worker_checkpoint.py +230 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/worker_execution.py +265 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/worker_handoff.py +192 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/worker_lifecycle.py +396 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/worker_runtime.py +1005 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/worker_sync.py +89 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor_types/README.md +36 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor_types/__init__.py +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor_types/exceptions.py +52 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor_types/graph_models.py +357 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor_types/path_containment.py +151 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor_types/target_fingerprint.py +310 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor_types/worker_claim.py +411 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/INTERFACE.md +50 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/README.md +57 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/SPEC.md +26 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/__init__.py +11 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/adapters/__init__.py +27 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/adapters/base.py +87 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/adapters/bugx.py +102 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/adapters/claude.py +222 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/adapters/cline.py +407 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/adapters/codex.py +260 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/adapters/dsh.py +177 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/adapters/opencode.py +218 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/adapters/pi.py +272 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/adapters/registry.py +100 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/adapters/zcode.py +312 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/api_routes_post.py +668 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/dispatcher.py +1376 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/docs_session_service.py +473 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/handler.py +674 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/ide_cloud_service.py +526 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/mcp_inspector.py +1747 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/00-base.css +1060 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/01-monitoring.css +802 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/02-header-actions.css +321 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/03-trigger-popover.css +697 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/04-composer.css +628 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/05-skills-center.css +878 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/06-mcp-center.css +623 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/07-skill-detail.css +265 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/08-files-management.css +167 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/09-files-center.css +386 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/10-icons.css +105 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/11-project-options.css +185 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/12-profile-tab.css +383 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/index-CXAsl8mr.js +333 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/index-DHQUtWtx.css +1 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/source-serif-4-cyrillic-400-normal-B8Z6Jvzv.woff +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/source-serif-4-cyrillic-400-normal-C44pakCn.woff2 +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/source-serif-4-cyrillic-500-normal-Bb4u56_6.woff +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/source-serif-4-cyrillic-500-normal-BdVUvljg.woff2 +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/source-serif-4-cyrillic-ext-400-normal-CWV284fw.woff2 +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/source-serif-4-cyrillic-ext-400-normal-DLkyKLvH.woff +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/source-serif-4-cyrillic-ext-500-normal-8-8HP2PF.woff +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/source-serif-4-cyrillic-ext-500-normal-DaDZE_Na.woff2 +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/source-serif-4-greek-400-normal-BccYJ-vZ.woff +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/source-serif-4-greek-400-normal-Cw5-AHNN.woff2 +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/source-serif-4-greek-500-normal-By8GFJzz.woff2 +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/source-serif-4-greek-500-normal-z-Q6FFuG.woff +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/source-serif-4-latin-400-normal-DJ5YJwmz.woff2 +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/source-serif-4-latin-400-normal-Dn3IlU-Z.woff +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/source-serif-4-latin-500-normal-CUHe9xxf.woff2 +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/source-serif-4-latin-500-normal-DVVamBqs.woff +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/source-serif-4-latin-ext-400-normal-CEpydyUl.woff +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/source-serif-4-latin-ext-400-normal-Cp7z-ARB.woff2 +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/source-serif-4-latin-ext-500-normal-BYjRCDVy.woff2 +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/source-serif-4-latin-ext-500-normal-D-qasQTj.woff +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/source-serif-4-vietnamese-400-normal-BbG3LG1A.woff2 +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/source-serif-4-vietnamese-400-normal-DR1UuFon.woff +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/source-serif-4-vietnamese-500-normal-8N8MYVKB.woff +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/source-serif-4-vietnamese-500-normal-Bi3OSTTW.woff2 +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/design-tokens.css +113 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/favicon.png +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/icon-192.png +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/index.html +55 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/manifest.webmanifest +19 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/project-settings.js +9602 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/sw.js +8 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/workspace_service.py +218 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/dsh/agents/bugx.md +27 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/dsh/dsh-patch.yml +18 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/dsh/mcp/cordis.patch.yml +4 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/dsh/mcp/index.js +219 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/dsh/mcp/package.json +28 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/dsh/skills/bugx/SKILL.md +70 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/dsh/skills/bugx-dsh/SKILL.md +229 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/dsh/ui/client.js +87 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/dsh/ui/cordis.patch.yml +4 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/dsh/ui/index.js +7 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/dsh/ui/package.json +27 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/mcp-lock.json +3075 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/opencode.json +129 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/pi/extensions/bugx/README.md +12 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/pi/extensions/bugx/index.ts +299 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/pi/extensions/bugx/manifest.json +11 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/pi/skills/bugx/SKILL.md +69 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/plugins/bugx/skills/bugx-claude/SKILL.md +326 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/plugins/bugx/skills/bugx-opencode/SKILL.md +129 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/plugins/bugx/skills/bugx-zcode/SKILL.md +459 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/workbuddy/connector-meta.json +19 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/workbuddy/icon.png +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/workbuddy/skills/bugx/SKILL.md +70 -0
- bugx_cli-0.1.1.dist-info/METADATA +335 -0
- bugx_cli-0.1.1.dist-info/RECORD +762 -0
- bugx_cli-0.1.1.dist-info/WHEEL +5 -0
- bugx_cli-0.1.1.dist-info/entry_points.txt +2 -0
- bugx_cli-0.1.1.dist-info/licenses/LICENSE +55 -0
- bugx_cli-0.1.1.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,1597 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""verify_life.py — bugx 寿命状态文件外部校验/修复器(元审计修复)。
|
|
3
|
+
|
|
4
|
+
背景:bugx 寿命机制的漏洞 A/B/E —— 寿命文件此前唯一的权威是 agent
|
|
5
|
+
自评自写回,无任何外部校验;且「支付轮费立即写回」在中断(kill/超时/打断)
|
|
6
|
+
下会产生「幽灵轮费」(life 已扣、history 无记录),状态不可恢复。
|
|
7
|
+
|
|
8
|
+
审计修复(v0.0.1 审计发现的三条逃逸链,全部在此封堵):
|
|
9
|
+
1. 自评刷命(漏洞 1):settle 此前全盘信任 agent 自报 findings/credited,
|
|
10
|
+
可凭空编造 5 条刷命。→ 现在每条 finding 必须含真实证据引用
|
|
11
|
+
(`文件:行号` 且文件真实存在,或 `test_*` 测试名 + 复现/观察标记),
|
|
12
|
+
无证据的编造条自动剔除出计命,刷命被拒。
|
|
13
|
+
2. bash 篡改校验器/快照(漏洞 2):校验器与快照与寿命文件同权限,agent
|
|
14
|
+
可用 bash 的 sed/cp 改掉校验逻辑或同步改快照绕过 diff。
|
|
15
|
+
→ 现在校验器内嵌 SELF_HASH 自校验(脚本被改则所有命令拒绝执行);
|
|
16
|
+
且 pre 输出「外部基线」JSON,post 用调用方传入的基线对比,
|
|
17
|
+
agent 改仓库内 snapshot 不再有效。
|
|
18
|
+
3. repair 滥用(漏洞 3):repair 机械修复可能被用来掩盖双结算痕迹。
|
|
19
|
+
→ repair 增加审计日志(repair-audit.log),每次修复留痕,调用方可查。
|
|
20
|
+
|
|
21
|
+
本脚本由调用方(主会话/用户)在启动 bugx 前后执行,提供硬校验:
|
|
22
|
+
check 校验一致性(不一致 exit 1,打印差异)
|
|
23
|
+
repair 修复不一致(回滚幽灵轮费:life 恢复到最后结算值,留审计日志)
|
|
24
|
+
settle 每轮结算(确定性入口:脚本计算 delta/life 并原子写回;含证据校验)
|
|
25
|
+
reset 重置为初始状态
|
|
26
|
+
snapshot 把当前状态备份到 .snapshot.json(基线)
|
|
27
|
+
diff 对比当前状态与快照/外部基线,检出「自洽撒谎」与超范围涨命
|
|
28
|
+
restore 从快照恢复当前状态(diff 检出异常后的回滚)
|
|
29
|
+
selfhash 输出本脚本当前 SHA256(维护用:改完脚本后更新 SELF_HASH)
|
|
30
|
+
set-mode 持久化用户确认的修复模式(auto/log-only)
|
|
31
|
+
|
|
32
|
+
调用规范(防「自洽撒谎」盲区,v0.0.1 加固):
|
|
33
|
+
1. 启动 bugx 前:`bugx engine --root . pre` —— 做 check + snapshot,
|
|
34
|
+
并**输出一行外部基线 JSON**(含 life/rounds_completed/history 前缀哈希)。
|
|
35
|
+
调用方把该基线保存到 agent 会话之外(如手动记录,或 export 环境变量)。
|
|
36
|
+
2. bugx 运行结束后:`bugx engine --root . post` —— 优先用
|
|
37
|
+
`BH_PRE_BASELINE` 环境变量(调用方传入的外部基线)做 diff;
|
|
38
|
+
若未设置则回退读仓库内 snapshot。外部基线由 pre 阶段签发
|
|
39
|
+
`baseline_hash` + `baseline_source`,post 先校验来源与完整性再采信;
|
|
40
|
+
agent 篡改基线内容或注入无签名基线将被 fail-closed 拒绝,
|
|
41
|
+
不再依赖「agent 无法篡改 env」的进程边界假设。
|
|
42
|
+
3. diff 异常 → restore 回滚到基线,并复核 agent 报告是否真实。
|
|
43
|
+
|
|
44
|
+
不变量(新机制:轮费改在结算时支付,life 只由结算写入):
|
|
45
|
+
1. history 的 round 号必须连续 1..N
|
|
46
|
+
2. life == 最后一条 history.life_after(无 history 则必须 == 1)
|
|
47
|
+
—— 违反即「幽灵轮费/未结算」,可被 repair 回滚
|
|
48
|
+
3. rounds_completed == len(history)
|
|
49
|
+
4. round == rounds_completed + 1
|
|
50
|
+
5. alive == (life > 0)
|
|
51
|
+
6. found_total == sum(credited)(各轮计命数之和,超额/重复不计命)
|
|
52
|
+
|
|
53
|
+
用法:
|
|
54
|
+
python3 verify_life.py check # 一致 exit 0;不一致 exit 1
|
|
55
|
+
python3 verify_life.py repair # 修复不一致(幂等,留审计日志)
|
|
56
|
+
python3 verify_life.py reset # 重置初始态
|
|
57
|
+
python3 verify_life.py snapshot # 备份当前状态
|
|
58
|
+
python3 verify_life.py selfhash # 输出自身 SHA256(维护用)
|
|
59
|
+
"""
|
|
60
|
+
|
|
61
|
+
from __future__ import annotations
|
|
62
|
+
# --- 引擎导入根(直接执行脚本时自举 core.* 命名空间)---
|
|
63
|
+
import sys as _sys
|
|
64
|
+
from pathlib import Path as _Path
|
|
65
|
+
|
|
66
|
+
for _p in _Path(__file__).resolve().parents:
|
|
67
|
+
if (_p / "core" / "bugx.md").is_file():
|
|
68
|
+
if str(_p) not in _sys.path:
|
|
69
|
+
_sys.path.insert(0, str(_p))
|
|
70
|
+
break
|
|
71
|
+
del _p
|
|
72
|
+
|
|
73
|
+
import hashlib
|
|
74
|
+
import hmac
|
|
75
|
+
import json
|
|
76
|
+
import os
|
|
77
|
+
import re
|
|
78
|
+
import shutil
|
|
79
|
+
import sys
|
|
80
|
+
import tempfile
|
|
81
|
+
import time
|
|
82
|
+
import uuid
|
|
83
|
+
from contextlib import contextmanager
|
|
84
|
+
from pathlib import Path
|
|
85
|
+
|
|
86
|
+
_core_dir = str(Path(__file__).resolve().parent.parent)
|
|
87
|
+
if _core_dir not in sys.path:
|
|
88
|
+
sys.path.insert(0, _core_dir)
|
|
89
|
+
|
|
90
|
+
try:
|
|
91
|
+
import core.bugx_paths as bugx_paths
|
|
92
|
+
except ImportError: # pragma: no cover - compatibility with standalone copies.
|
|
93
|
+
bugx_paths = None # type: ignore[assignment]
|
|
94
|
+
|
|
95
|
+
try:
|
|
96
|
+
import fcntl
|
|
97
|
+
except ImportError: # pragma: no cover - POSIX is the supported runtime.
|
|
98
|
+
fcntl = None # type: ignore[assignment]
|
|
99
|
+
|
|
100
|
+
try:
|
|
101
|
+
import msvcrt
|
|
102
|
+
except ImportError: # pragma: no cover - Windows-only fallback.
|
|
103
|
+
msvcrt = None # type: ignore[assignment]
|
|
104
|
+
|
|
105
|
+
def _default_life_paths() -> tuple[Path, Path, Path, Path]:
|
|
106
|
+
script_dir = Path(__file__).resolve().parent
|
|
107
|
+
if bugx_paths is not None:
|
|
108
|
+
# Layout 2 的引擎始终位于全局目录;交给
|
|
109
|
+
# bugx_paths.project_root() 解析 BUGX_PROJECT_ROOT 或 cwd。
|
|
110
|
+
try:
|
|
111
|
+
root = bugx_paths.project_root(script_dir)
|
|
112
|
+
active = bugx_paths.require(root)
|
|
113
|
+
return active.life, active.life_snapshot, active.state_root / "repair-audit.log", active.life_lock
|
|
114
|
+
except (OSError, ValueError, RuntimeError):
|
|
115
|
+
# 无合法 .bugx 运行态(独立协议测试/自包含引擎副本)。
|
|
116
|
+
life = _standalone_life_file(script_dir)
|
|
117
|
+
return life, life.with_suffix(".json.snapshot"), life.parent / "repair-audit.log", \
|
|
118
|
+
life.with_name(life.name + ".lock")
|
|
119
|
+
life = _standalone_life_file(script_dir)
|
|
120
|
+
return life, life.with_suffix(".json.snapshot"), life.parent / "repair-audit.log", \
|
|
121
|
+
life.with_name(life.name + ".lock")
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def _standalone_life_file(script_dir: Path) -> Path:
|
|
125
|
+
"""无项目布局时寿命状态文件的唯一位置。
|
|
126
|
+
|
|
127
|
+
必须与 ``launch_phases.common._path_values_for_root`` 同源:自包含引擎副本
|
|
128
|
+
的布局是 ``root/core/ledger/verify_life.py``,运行态在 ``root``。旧实现固定
|
|
129
|
+
写 ``script_dir/bugx-life.json``,于是
|
|
130
|
+
``python core/ledger/verify_life.py reset`` 把状态写进 ``core/ledger/``,
|
|
131
|
+
而启动器读 ``root/bugx-life.json`` —— 两份状态各自存在、互不可见,
|
|
132
|
+
``status``/``check`` 报"寿命文件不存在",reset 却宣称成功。
|
|
133
|
+
"""
|
|
134
|
+
engine_root = script_dir.parent
|
|
135
|
+
if (engine_root / "launch_bugx.py").is_file():
|
|
136
|
+
return engine_root.parent / "bugx-life.json"
|
|
137
|
+
return script_dir / "bugx-life.json"
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
LIFE_FILE, SNAPSHOT_FILE, AUDIT_LOG, LIFE_LOCK_FILE = _default_life_paths()
|
|
141
|
+
|
|
142
|
+
# 自校验:脚本被 bash/sed/cp 篡改后,所有命令拒绝执行。
|
|
143
|
+
# 维护方法:改完本脚本后运行 `python3 verify_life.py selfhash`,
|
|
144
|
+
# 把输出粘贴到下面 SELF_HASH = "..." 即可(哈希会随每次编辑变化)。
|
|
145
|
+
SELF_HASH = "1d29d8cf0342e4ee0f371da3528fd26f29524d0436714e7a86d9163abccbd3f4"
|
|
146
|
+
|
|
147
|
+
# 单轮每项真实发现的加分上限(与 bugx.md「单轮加分上限」一致)。
|
|
148
|
+
# 防「凑数无限续命」:每轮 life 净增上限 = -1(轮费) + MAX_PER_ROUND。
|
|
149
|
+
MAX_PER_ROUND = 5
|
|
150
|
+
# 本脚本被设计成**可独立复制执行**(独立平铺副本场景;行为契约以本注释与
|
|
151
|
+
# 拷进临时目录跑,那里没有 core 包),因此不能 import canonical 常量。字面量必须在
|
|
152
|
+
# 上游 docstring 共同维护;与
|
|
153
|
+
# core.launch_phases.common.FIX_MODES 完全相等——单一事实源靠契约测试守,不靠 import。
|
|
154
|
+
VALID_MODES = {"auto", "log-only"}
|
|
155
|
+
SETTLEMENT_WAL_SCHEMA = 1
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
class SettlementRecoveryError(RuntimeError):
|
|
159
|
+
"""A pending cross-file settlement cannot be recovered safely."""
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
def self_check() -> None:
|
|
163
|
+
"""脚本自校验:SELF_HASH 与真实内容不符 → 拒绝执行(exit 3)。
|
|
164
|
+
|
|
165
|
+
哈希计算**排除本文件内的 SELF_HASH 行**(避免自引用死循环)——
|
|
166
|
+
只校验代码与注释,SELF_HASH 常量行本身可自由更新。
|
|
167
|
+
维护:改完脚本后运行 `python3 verify_life.py selfhash` 更新基线。
|
|
168
|
+
"""
|
|
169
|
+
try:
|
|
170
|
+
raw = Path(__file__).resolve().read_bytes()
|
|
171
|
+
except OSError:
|
|
172
|
+
return
|
|
173
|
+
# 去掉 SELF_HASH = "..." 这一行再算哈希
|
|
174
|
+
lines = raw.splitlines()
|
|
175
|
+
cleaned = b"\n".join(
|
|
176
|
+
ln for ln in lines if not ln.startswith(b'SELF_HASH = "')
|
|
177
|
+
)
|
|
178
|
+
actual = hashlib.sha256(cleaned).hexdigest()
|
|
179
|
+
# 仅当 selfhash 作为命令本身(argv[1])时输出当前哈希——这是维护命令。
|
|
180
|
+
# 作为任意位置的后缀参数出现时【不得】绕过上方篡改检测:否则攻击者只需
|
|
181
|
+
# 在 argv 里塞一个 --selfhash 就能让已篡改脚本身份校验通过。
|
|
182
|
+
if len(sys.argv) > 1 and sys.argv[1] in {"selfhash", "--selfhash"}:
|
|
183
|
+
print(actual)
|
|
184
|
+
sys.exit(0)
|
|
185
|
+
if actual != SELF_HASH:
|
|
186
|
+
print("[verify_life] 校验器自身被篡改(SHA256 不匹配),拒绝执行。")
|
|
187
|
+
print(" 可能被 bash 的 sed/cp 修改。请从仓库恢复:")
|
|
188
|
+
print(" git checkout -- core/verify_life.py")
|
|
189
|
+
print(" 或维护者运行 `python3 verify_life.py selfhash` 更新基线。")
|
|
190
|
+
sys.exit(3)
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
def load() -> dict:
|
|
196
|
+
"""读寿命文件;区分「尚未初始化」与「JSON 损坏(写回中断)」。
|
|
197
|
+
|
|
198
|
+
二者恢复路径完全不同:前者由 reset 的 bootstrap 例外创建初始状态,
|
|
199
|
+
后者才适用 restore/人工修复。混报会让首次运行的用户去"人工修复"
|
|
200
|
+
一个根本不存在的文件(LOOP-1)。
|
|
201
|
+
"""
|
|
202
|
+
if not LIFE_FILE.is_file():
|
|
203
|
+
print("[verify_life] 寿命文件不存在(首次运行尚未初始化)。")
|
|
204
|
+
print(f" 路径: {LIFE_FILE}")
|
|
205
|
+
print(" 处理:运行 `python3 verify_life.py reset` 创建初始状态"
|
|
206
|
+
"(启动器会在首次启动时自动完成)。")
|
|
207
|
+
sys.exit(2)
|
|
208
|
+
try:
|
|
209
|
+
value = json.loads(LIFE_FILE.read_text(encoding="utf-8"))
|
|
210
|
+
except (json.JSONDecodeError, OSError) as e:
|
|
211
|
+
print(f"[verify_life] 寿命文件无法解析: {e}")
|
|
212
|
+
print(f" 路径: {LIFE_FILE}")
|
|
213
|
+
print(" 可能上次写回被中断导致 JSON 损坏。")
|
|
214
|
+
print(" 处理:有快照基线则 `restore` 回滚;否则人工修复该文件。")
|
|
215
|
+
sys.exit(2)
|
|
216
|
+
if not isinstance(value, dict):
|
|
217
|
+
print("[verify_life] 寿命文件根节点必须是 JSON 对象")
|
|
218
|
+
print(f" 路径: {LIFE_FILE}")
|
|
219
|
+
sys.exit(2)
|
|
220
|
+
return value
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
def save(d: dict) -> None:
|
|
224
|
+
_save_atomic(d)
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
def _assert_no_symlink_components(path: Path) -> None:
|
|
228
|
+
"""拒绝路径中任何已存在的符号链接/reparse 组件。
|
|
229
|
+
|
|
230
|
+
DES-17:符号链接防越界检查收敛到 ``bugx_paths.assert_no_symlink_components``
|
|
231
|
+
这一唯一实现(含 Windows junction/reparse point 平台分支),本模块不再
|
|
232
|
+
自带一份只认 ``is_symlink()`` 的副本。仅在 ``bugx_paths`` 完全不可导入
|
|
233
|
+
(独立协议测试的平铺副本)时才退回最小本地实现,行为与旧版一致。
|
|
234
|
+
"""
|
|
235
|
+
if bugx_paths is not None:
|
|
236
|
+
bugx_paths.assert_no_symlink_components(path, OSError)
|
|
237
|
+
return
|
|
238
|
+
absolute = Path(os.path.abspath(str(path)))
|
|
239
|
+
current = Path(absolute.anchor)
|
|
240
|
+
for part in absolute.parts[1:]:
|
|
241
|
+
current /= part
|
|
242
|
+
if current.is_symlink() and current.parent != Path(absolute.anchor):
|
|
243
|
+
raise OSError(f"拒绝使用符号链接路径组件: {path}")
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
# 寿命锁等待上限:超过即判定存在卡死/并发冲突,带诊断信息失败(DOC-031 锁统一)。
|
|
247
|
+
LIFE_LOCK_TIMEOUT_SECONDS = 10.0
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
@contextmanager
|
|
251
|
+
def _life_lock(timeout_seconds: float | None = None):
|
|
252
|
+
"""Serialize read/check/settle/write and release the lock on process crash.
|
|
253
|
+
|
|
254
|
+
flock 非阻塞重试至超时(默认 LIFE_LOCK_TIMEOUT_SECONDS=10s):持锁进程
|
|
255
|
+
崩溃由内核自动释放;超时则报出锁文件路径与持有提示,避免无界等待。
|
|
256
|
+
"""
|
|
257
|
+
if timeout_seconds is None:
|
|
258
|
+
timeout_seconds = LIFE_LOCK_TIMEOUT_SECONDS
|
|
259
|
+
lock_file = LIFE_LOCK_FILE
|
|
260
|
+
_assert_no_symlink_components(lock_file.parent)
|
|
261
|
+
if lock_file.is_symlink():
|
|
262
|
+
raise OSError(f"拒绝使用符号链接锁文件: {lock_file}")
|
|
263
|
+
lock_file.parent.mkdir(parents=True, exist_ok=True)
|
|
264
|
+
if lock_file.is_symlink():
|
|
265
|
+
raise OSError(f"拒绝使用符号链接锁文件: {lock_file}")
|
|
266
|
+
with lock_file.open("a+b") as handle:
|
|
267
|
+
if fcntl is not None:
|
|
268
|
+
deadline = time.monotonic() + timeout_seconds
|
|
269
|
+
while True:
|
|
270
|
+
try:
|
|
271
|
+
fcntl.flock(handle.fileno(), fcntl.LOCK_EX | fcntl.LOCK_NB)
|
|
272
|
+
break
|
|
273
|
+
except OSError as exc:
|
|
274
|
+
if time.monotonic() >= deadline:
|
|
275
|
+
holder = ""
|
|
276
|
+
try:
|
|
277
|
+
handle.seek(0)
|
|
278
|
+
raw = handle.read(64).decode("utf-8", "replace").strip()
|
|
279
|
+
except OSError:
|
|
280
|
+
raw = ""
|
|
281
|
+
if raw:
|
|
282
|
+
holder = f"(内容:{raw})"
|
|
283
|
+
raise TimeoutError(
|
|
284
|
+
f"寿命状态锁等待超时({timeout_seconds:.0f}s):{lock_file} "
|
|
285
|
+
f"正被其他进程持有{holder};请确认没有其他 "
|
|
286
|
+
"verify_life/launch_bugx 进程正在结算后重试"
|
|
287
|
+
) from exc
|
|
288
|
+
time.sleep(0.05)
|
|
289
|
+
try:
|
|
290
|
+
yield
|
|
291
|
+
finally:
|
|
292
|
+
fcntl.flock(handle.fileno(), fcntl.LOCK_UN)
|
|
293
|
+
return
|
|
294
|
+
if msvcrt is not None: # pragma: no cover - exercised by Windows tests.
|
|
295
|
+
# ``LK_LOCK`` may raise ``Resource deadlock avoided`` immediately
|
|
296
|
+
# when the peer is in the same process. Use the non-blocking
|
|
297
|
+
# primitive and apply the same bounded diagnostic wait as flock.
|
|
298
|
+
if handle.seek(0, 2) == 0:
|
|
299
|
+
handle.write(b"\0")
|
|
300
|
+
handle.flush()
|
|
301
|
+
handle.seek(0)
|
|
302
|
+
deadline = time.monotonic() + timeout_seconds
|
|
303
|
+
lock_mode = getattr(msvcrt, "LK_NBLCK", msvcrt.LK_LOCK)
|
|
304
|
+
while True:
|
|
305
|
+
try:
|
|
306
|
+
msvcrt.locking(handle.fileno(), lock_mode, 1)
|
|
307
|
+
break
|
|
308
|
+
except OSError as exc:
|
|
309
|
+
if time.monotonic() >= deadline:
|
|
310
|
+
holder = ""
|
|
311
|
+
try:
|
|
312
|
+
handle.seek(0)
|
|
313
|
+
raw = handle.read(64).decode("utf-8", "replace").strip()
|
|
314
|
+
except OSError:
|
|
315
|
+
raw = ""
|
|
316
|
+
if raw:
|
|
317
|
+
holder = f"(内容:{raw})"
|
|
318
|
+
raise TimeoutError(
|
|
319
|
+
f"寿命状态锁等待超时({timeout_seconds:.0f}s):{lock_file} "
|
|
320
|
+
f"正被其他进程持有{holder};请确认没有其他 "
|
|
321
|
+
"verify_life/launch_bugx 进程正在结算后重试"
|
|
322
|
+
) from exc
|
|
323
|
+
time.sleep(0.05)
|
|
324
|
+
try:
|
|
325
|
+
yield
|
|
326
|
+
finally:
|
|
327
|
+
handle.seek(0)
|
|
328
|
+
msvcrt.locking(handle.fileno(), msvcrt.LK_UNLCK, 1)
|
|
329
|
+
return
|
|
330
|
+
# A platform without either kernel locking primitive is not safe for
|
|
331
|
+
# concurrent settlement. Keep importability, but fail closed at use.
|
|
332
|
+
raise OSError("当前平台不支持寿命状态的跨进程锁")
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
def _credited(h: dict) -> int:
|
|
336
|
+
"""本轮计命发现数:优先取 credited 字段(新机制,超额/重复不计命),
|
|
337
|
+
缺失(旧数据)回退到 len(findings)。"""
|
|
338
|
+
if h.get("credited") is not None:
|
|
339
|
+
value = h["credited"]
|
|
340
|
+
if isinstance(value, bool) or not isinstance(value, int):
|
|
341
|
+
raise ValueError("credited 必须是整数")
|
|
342
|
+
return value
|
|
343
|
+
findings = h.get("findings") or []
|
|
344
|
+
if not isinstance(findings, list):
|
|
345
|
+
raise ValueError("findings 必须是数组")
|
|
346
|
+
return len(findings)
|
|
347
|
+
|
|
348
|
+
|
|
349
|
+
def _load_json(path: Path, what: str) -> dict:
|
|
350
|
+
"""读 JSON 文件;损坏/缺失时优雅报错(exit 2),不 traceback。"""
|
|
351
|
+
try:
|
|
352
|
+
return json.loads(path.read_text(encoding="utf-8"))
|
|
353
|
+
except (json.JSONDecodeError, OSError) as e:
|
|
354
|
+
print(f"[verify_life] {what} 无法解析: {e}")
|
|
355
|
+
print(f" 路径: {path}")
|
|
356
|
+
print(" 可能文件被写回中断或篡改。先 `snapshot` 重建基线,"
|
|
357
|
+
"或人工修复。")
|
|
358
|
+
sys.exit(2)
|
|
359
|
+
|
|
360
|
+
|
|
361
|
+
def _int_arg(val: str, name: str) -> int:
|
|
362
|
+
try:
|
|
363
|
+
return int(val)
|
|
364
|
+
except ValueError:
|
|
365
|
+
print(f"[verify_life] 参数 {name} 必须是整数,got {val!r}")
|
|
366
|
+
sys.exit(2)
|
|
367
|
+
|
|
368
|
+
|
|
369
|
+
# ---- 证据校验(修复漏洞 1:堵「凭空编造 findings 刷命」)----
|
|
370
|
+
|
|
371
|
+
# 真实证据引用形态:
|
|
372
|
+
# 1) `文件路径:行号`(文件必须真实存在;路径可相对仓库根或绝对)
|
|
373
|
+
# 2) `test_xxx` 测试名 + 出现 复现/观察/Repro/Observed 标记
|
|
374
|
+
# 两者任一命中且文件存在才计为「有证据」。
|
|
375
|
+
_EVIDENCE_FILE_RE = re.compile(
|
|
376
|
+
r"(?P<path>[A-Za-z0-9_./\\\-]+\.(?:py|js|ts|jsx|tsx|go|rs|java|kt|"
|
|
377
|
+
r"c|cpp|h|sh|md|json|yaml|yml|toml|xml|html|css|sql|log|txt|"
|
|
378
|
+
r"cjs|mjs|mts|cts))"
|
|
379
|
+
r"\s*[:#]\s*(?P<line>\d+)"
|
|
380
|
+
)
|
|
381
|
+
_TEST_NAME_RE = re.compile(r"\btest_[A-Za-z0-9_]+")
|
|
382
|
+
_TEST_DEF_RE = re.compile(r"(?:def|async\s+def)\s+(?P<name>test_[A-Za-z0-9_]+)\b")
|
|
383
|
+
_REPRO_MARK_RE = re.compile(r"(复现|观察|预期|Repro|Observed|Expected|exit\s+code)")
|
|
384
|
+
|
|
385
|
+
# 源码仓库根是 core/ 的上级;Layout 2 的项目根由
|
|
386
|
+
# BUGX_PROJECT_ROOT/cwd 绑定,不从项目可执行目录反推。
|
|
387
|
+
def _resolve_repo_root(invocation_file: Path) -> Path:
|
|
388
|
+
configured = os.environ.get("BUGX_PROJECT_ROOT")
|
|
389
|
+
if configured:
|
|
390
|
+
return Path(configured).expanduser().resolve()
|
|
391
|
+
# Layout 2 executes the shared engine with the project as cwd. Standalone
|
|
392
|
+
# test/portable copies also carry their launcher beside the project files;
|
|
393
|
+
# prefer that explicit working tree before falling back to the source tree
|
|
394
|
+
# parent used when verify_life.py is executed from ``core/``.
|
|
395
|
+
cwd = Path.cwd().resolve()
|
|
396
|
+
if invocation_file.exists() and (
|
|
397
|
+
(cwd / ".bugx").is_dir() or (cwd / "launch_bugx.py").is_file()
|
|
398
|
+
):
|
|
399
|
+
return cwd
|
|
400
|
+
link_dir = invocation_file.absolute().parent
|
|
401
|
+
if link_dir.name in ("ledger", "probes", "supervisor"):
|
|
402
|
+
link_dir = link_dir.parent
|
|
403
|
+
return link_dir.parent
|
|
404
|
+
|
|
405
|
+
|
|
406
|
+
_REPO_ROOT = _resolve_repo_root(Path(__file__))
|
|
407
|
+
|
|
408
|
+
|
|
409
|
+
def _file_real(path: str, line: int | None = None) -> bool:
|
|
410
|
+
"""文件和(如提供)行号真实存在于仓库。"""
|
|
411
|
+
p = Path(path).expanduser()
|
|
412
|
+
if not p.is_absolute():
|
|
413
|
+
p = _REPO_ROOT / path
|
|
414
|
+
try:
|
|
415
|
+
p = p.resolve(strict=True)
|
|
416
|
+
p.relative_to(_REPO_ROOT.resolve(strict=True))
|
|
417
|
+
except (OSError, ValueError):
|
|
418
|
+
return False
|
|
419
|
+
if not p.is_file():
|
|
420
|
+
return False
|
|
421
|
+
if line is None:
|
|
422
|
+
return True
|
|
423
|
+
try:
|
|
424
|
+
# 行号证据至少不能超出文件实际范围;语义正确性仍需调用方复核。
|
|
425
|
+
with p.open("r", encoding="utf-8", errors="replace") as fh:
|
|
426
|
+
line_count = sum(1 for _ in fh)
|
|
427
|
+
return 1 <= line <= line_count
|
|
428
|
+
except OSError:
|
|
429
|
+
return False
|
|
430
|
+
|
|
431
|
+
|
|
432
|
+
def _test_real(name: str) -> bool:
|
|
433
|
+
"""Require a test name to resolve to an actual test definition."""
|
|
434
|
+
root = _REPO_ROOT.resolve()
|
|
435
|
+
try:
|
|
436
|
+
for candidate in root.rglob("test*.py"):
|
|
437
|
+
if not candidate.is_file() or candidate.is_symlink():
|
|
438
|
+
continue
|
|
439
|
+
try:
|
|
440
|
+
text = candidate.read_text(encoding="utf-8", errors="replace")
|
|
441
|
+
except OSError:
|
|
442
|
+
continue
|
|
443
|
+
if any(match.group("name") == name for match in _TEST_DEF_RE.finditer(text)):
|
|
444
|
+
return True
|
|
445
|
+
except OSError:
|
|
446
|
+
return False
|
|
447
|
+
return False
|
|
448
|
+
|
|
449
|
+
|
|
450
|
+
def _audit(kind: str, detail: str) -> None:
|
|
451
|
+
"""修复/重置等外部操作用途留痕(修复漏洞 3:repair 可被追踪)。"""
|
|
452
|
+
import datetime
|
|
453
|
+
|
|
454
|
+
try:
|
|
455
|
+
with AUDIT_LOG.open("a", encoding="utf-8") as f:
|
|
456
|
+
f.write(
|
|
457
|
+
f"{datetime.datetime.now().isoformat(timespec='seconds')} "
|
|
458
|
+
f"[{kind}] {detail}\n"
|
|
459
|
+
)
|
|
460
|
+
except OSError:
|
|
461
|
+
pass
|
|
462
|
+
|
|
463
|
+
|
|
464
|
+
def evidence_bad_lines(findings: list[str]) -> list[str]:
|
|
465
|
+
"""返回没有真实证据引用的 findings 行(漏洞 1 校验)。
|
|
466
|
+
|
|
467
|
+
有证据判定:`文件:行号` 且文件存在;或 `test_*` 名 + 复现/观察标记。
|
|
468
|
+
"""
|
|
469
|
+
bad: list[str] = []
|
|
470
|
+
for f in findings:
|
|
471
|
+
has_file_ref = False
|
|
472
|
+
for m in _EVIDENCE_FILE_RE.finditer(f):
|
|
473
|
+
if _file_real(m.group("path"), int(m.group("line"))):
|
|
474
|
+
has_file_ref = True
|
|
475
|
+
break
|
|
476
|
+
test_match = _TEST_NAME_RE.search(f)
|
|
477
|
+
has_test_repro = bool(
|
|
478
|
+
test_match and _REPRO_MARK_RE.search(f) and _test_real(test_match.group(0))
|
|
479
|
+
)
|
|
480
|
+
if not (has_file_ref or has_test_repro):
|
|
481
|
+
bad.append(f)
|
|
482
|
+
return bad
|
|
483
|
+
|
|
484
|
+
|
|
485
|
+
# ---- 外部基线完整性锚(F-184)----
|
|
486
|
+
# 旧实现只做 json.loads/路径读取,docstring 的「agent 无法篡改」是进程边界
|
|
487
|
+
# 假设而非代码校验;具备 env 控制权的进程可注入被篡改基线掩盖历史篡改。
|
|
488
|
+
# 现在由可信宿主在 pre 阶段(snapshot)对基线载荷签发 baseline_hash,
|
|
489
|
+
# post 读取时强制校验来源标识 + 完整性,失败即 fail-closed 拒绝。
|
|
490
|
+
BASELINE_HASH_FIELD = "baseline_hash"
|
|
491
|
+
BASELINE_SOURCE_FIELD = "baseline_source"
|
|
492
|
+
HOST_SIGNED_SOURCE = "host-signed-pre"
|
|
493
|
+
REPO_SNAPSHOT_SOURCE = "repo-snapshot"
|
|
494
|
+
|
|
495
|
+
|
|
496
|
+
def baseline_integrity_hash(payload: dict) -> str:
|
|
497
|
+
"""基线载荷的确定性 SHA256——排除锚字段本身,避免自引用死循环。"""
|
|
498
|
+
body = {
|
|
499
|
+
key: value for key, value in payload.items()
|
|
500
|
+
if key not in (BASELINE_HASH_FIELD, BASELINE_SOURCE_FIELD)
|
|
501
|
+
}
|
|
502
|
+
blob = json.dumps(
|
|
503
|
+
body, ensure_ascii=False, sort_keys=True, separators=(",", ":"), allow_nan=False,
|
|
504
|
+
).encode("utf-8")
|
|
505
|
+
return hashlib.sha256(blob).hexdigest()
|
|
506
|
+
|
|
507
|
+
|
|
508
|
+
def sign_baseline(payload: dict) -> dict:
|
|
509
|
+
"""由可信宿主在 pre 阶段调用,为基线载荷签发来源标识与完整性锚。"""
|
|
510
|
+
signed = dict(payload)
|
|
511
|
+
signed[BASELINE_SOURCE_FIELD] = HOST_SIGNED_SOURCE
|
|
512
|
+
signed[BASELINE_HASH_FIELD] = baseline_integrity_hash(signed)
|
|
513
|
+
return signed
|
|
514
|
+
|
|
515
|
+
|
|
516
|
+
def external_baseline() -> dict | None:
|
|
517
|
+
"""读取外部基线(pre 签发、post 校验)。
|
|
518
|
+
|
|
519
|
+
优先级:环境变量 BH_PRE_BASELINE(pre 签发、post 传回,JSON 字符串或
|
|
520
|
+
文件路径)> 仓库内 snapshot 文件。env 基线必须携带合法来源标识与
|
|
521
|
+
baseline_hash,且哈希与载荷逐字节一致,否则 fail-closed 拒绝;
|
|
522
|
+
快照回退显式标记 baseline_source,不再以进程边界假设代替校验。
|
|
523
|
+
"""
|
|
524
|
+
import os
|
|
525
|
+
|
|
526
|
+
raw = os.environ.get("BH_PRE_BASELINE", "").strip()
|
|
527
|
+
if raw:
|
|
528
|
+
payload: dict | None = None
|
|
529
|
+
try:
|
|
530
|
+
p = Path(raw)
|
|
531
|
+
if p.is_file():
|
|
532
|
+
payload = _load_json(p, "外部基线文件")
|
|
533
|
+
except (OSError, ValueError):
|
|
534
|
+
pass
|
|
535
|
+
if payload is None:
|
|
536
|
+
try:
|
|
537
|
+
parsed = json.loads(raw)
|
|
538
|
+
payload = parsed if isinstance(parsed, dict) else None
|
|
539
|
+
except json.JSONDecodeError as e:
|
|
540
|
+
print(f"[verify_life] BH_PRE_BASELINE 无法解析: {e}")
|
|
541
|
+
return None
|
|
542
|
+
if not isinstance(payload, dict):
|
|
543
|
+
print("[verify_life] 外部基线必须是 JSON 对象,拒绝。")
|
|
544
|
+
return None
|
|
545
|
+
source = payload.get(BASELINE_SOURCE_FIELD)
|
|
546
|
+
if source != HOST_SIGNED_SOURCE:
|
|
547
|
+
print(f"[verify_life] 外部基线来源标识缺失或不合法"
|
|
548
|
+
f"(要求 {HOST_SIGNED_SOURCE!r},实际 {source!r}),拒绝。")
|
|
549
|
+
return None
|
|
550
|
+
expected = payload.get(BASELINE_HASH_FIELD)
|
|
551
|
+
if not isinstance(expected, str) or not expected:
|
|
552
|
+
print("[verify_life] 外部基线缺 baseline_hash(新格式强制校验),拒绝。")
|
|
553
|
+
return None
|
|
554
|
+
actual = baseline_integrity_hash(payload)
|
|
555
|
+
if not hmac.compare_digest(actual, expected):
|
|
556
|
+
print(f"[verify_life] 外部基线完整性校验失败"
|
|
557
|
+
f"(签发 {expected},实算 {actual}),拒绝。")
|
|
558
|
+
return None
|
|
559
|
+
return payload
|
|
560
|
+
if SNAPSHOT_FILE.is_file():
|
|
561
|
+
snap = _load_json(SNAPSHOT_FILE, "快照基线")
|
|
562
|
+
if isinstance(snap, dict):
|
|
563
|
+
snap = dict(snap)
|
|
564
|
+
snap[BASELINE_SOURCE_FIELD] = REPO_SNAPSHOT_SOURCE
|
|
565
|
+
return snap
|
|
566
|
+
return None
|
|
567
|
+
|
|
568
|
+
|
|
569
|
+
|
|
570
|
+
|
|
571
|
+
|
|
572
|
+
def check_errors(d: dict) -> list[str]:
|
|
573
|
+
"""返回不变量违反清单(空列表 = 一致)。"""
|
|
574
|
+
errors: list[str] = []
|
|
575
|
+
if not isinstance(d, dict):
|
|
576
|
+
return ["寿命状态根节点必须是 JSON 对象"]
|
|
577
|
+
hist = d.get("history") or []
|
|
578
|
+
if not isinstance(hist, list):
|
|
579
|
+
return ["history 必须是数组"]
|
|
580
|
+
life = d.get("life")
|
|
581
|
+
if isinstance(life, bool) or not isinstance(life, int):
|
|
582
|
+
errors.append(f"life({life!r}) 必须是整数")
|
|
583
|
+
rounds_completed = d.get("rounds_completed")
|
|
584
|
+
if isinstance(rounds_completed, bool) or not isinstance(rounds_completed, int) \
|
|
585
|
+
or rounds_completed < 0:
|
|
586
|
+
errors.append(f"rounds_completed({rounds_completed!r}) 必须是非负整数")
|
|
587
|
+
rounds_completed = 0
|
|
588
|
+
round_value = d.get("round")
|
|
589
|
+
if isinstance(round_value, bool) or not isinstance(round_value, int):
|
|
590
|
+
errors.append(f"round({round_value!r}) 必须是整数")
|
|
591
|
+
round_value = 0
|
|
592
|
+
alive = d.get("alive")
|
|
593
|
+
if not isinstance(alive, bool):
|
|
594
|
+
errors.append(f"alive({alive!r}) 必须是布尔值")
|
|
595
|
+
alive = bool(alive)
|
|
596
|
+
rounds = [h.get("round") if isinstance(h, dict) else None for h in hist]
|
|
597
|
+
if rounds != list(range(1, len(hist) + 1)):
|
|
598
|
+
errors.append(f"history round 号不连续: {rounds}")
|
|
599
|
+
if hist and isinstance(hist[-1], dict):
|
|
600
|
+
last_after = hist[-1].get("life_after")
|
|
601
|
+
if not isinstance(last_after, int) or isinstance(last_after, bool):
|
|
602
|
+
errors.append(f"最后 history.life_after({last_after!r}) 必须是整数")
|
|
603
|
+
elif life != last_after:
|
|
604
|
+
errors.append(
|
|
605
|
+
f"life({life}) != 最后 history.life_after({last_after})"
|
|
606
|
+
" —— 幽灵轮费/未结算"
|
|
607
|
+
)
|
|
608
|
+
else:
|
|
609
|
+
if life != 1:
|
|
610
|
+
errors.append(f"空 history 时 life 必须为 1,当前 {life}")
|
|
611
|
+
if rounds_completed != len(hist):
|
|
612
|
+
errors.append(
|
|
613
|
+
f"rounds_completed({rounds_completed}) != len(history)"
|
|
614
|
+
f"({len(hist)})"
|
|
615
|
+
)
|
|
616
|
+
# round 恒等于 rounds_completed + 1(下一轮号)。结算写回时必须同步推进。
|
|
617
|
+
if round_value != rounds_completed + 1:
|
|
618
|
+
errors.append(
|
|
619
|
+
f"round({round_value}) != rounds_completed+1"
|
|
620
|
+
f"({rounds_completed + 1})"
|
|
621
|
+
)
|
|
622
|
+
if isinstance(life, int) and not isinstance(life, bool) and alive != (life > 0):
|
|
623
|
+
errors.append(f"alive({alive}) 与 life({life}) 不一致")
|
|
624
|
+
mode = d.get("mode")
|
|
625
|
+
if mode is not None and mode not in VALID_MODES:
|
|
626
|
+
errors.append(
|
|
627
|
+
f"mode({mode!r}) 无效,必须是 auto/log-only 或 null"
|
|
628
|
+
)
|
|
629
|
+
# found_total 必须等于各轮计命数(credited)之和——超额/重复发现计入
|
|
630
|
+
# findings 但不计命,故不能用 sum(findings)。
|
|
631
|
+
try:
|
|
632
|
+
ft = sum(_credited(h) for h in hist)
|
|
633
|
+
except (TypeError, ValueError) as exc:
|
|
634
|
+
errors.append(f"history credited/findings 无效: {exc}")
|
|
635
|
+
ft = -1
|
|
636
|
+
found_total = d.get("found_total")
|
|
637
|
+
if isinstance(found_total, bool) or not isinstance(found_total, int):
|
|
638
|
+
errors.append(f"found_total({found_total!r}) 必须是非负整数")
|
|
639
|
+
elif found_total != ft:
|
|
640
|
+
errors.append(
|
|
641
|
+
f"found_total({found_total}) != sum(credited)({ft})"
|
|
642
|
+
)
|
|
643
|
+
# life_after 链:第 i 条(i>=1)必须 == 上一条 life_after + delta。
|
|
644
|
+
# 第一条无前置参照(初始 life 未硬编码,兼容非 1 初始),仅要求 delta 存在。
|
|
645
|
+
# life == 最后一条 life_after 已在上方单独校验。
|
|
646
|
+
if hist and isinstance(hist[0], dict) and hist[0].get("delta") is None:
|
|
647
|
+
errors.append(f"history[0](round={hist[0].get('round')}) 缺 delta")
|
|
648
|
+
for i, h in enumerate(hist):
|
|
649
|
+
if not isinstance(h, dict):
|
|
650
|
+
errors.append(f"history[{i}] 必须是对象")
|
|
651
|
+
continue
|
|
652
|
+
dlt = h.get("delta")
|
|
653
|
+
if dlt is not None and (
|
|
654
|
+
isinstance(dlt, bool) or not isinstance(dlt, int)
|
|
655
|
+
):
|
|
656
|
+
errors.append(f"history[{i}](round={h.get('round')}) delta 必须是整数")
|
|
657
|
+
elif dlt is not None and dlt > MAX_PER_ROUND - 1:
|
|
658
|
+
errors.append(
|
|
659
|
+
f"history[{i}](round={h.get('round')}) delta({dlt}) 超上界 "
|
|
660
|
+
f"(≤{MAX_PER_ROUND - 1})——计命发现数可疑/伪造"
|
|
661
|
+
)
|
|
662
|
+
cred = h.get("credited")
|
|
663
|
+
if cred is not None and (
|
|
664
|
+
isinstance(cred, bool) or not isinstance(cred, int)
|
|
665
|
+
or not (0 <= cred <= MAX_PER_ROUND)
|
|
666
|
+
):
|
|
667
|
+
errors.append(
|
|
668
|
+
f"history[{i}](round={h.get('round')}) credited({cred}) 越界,"
|
|
669
|
+
f"须在 [0, {MAX_PER_ROUND}]"
|
|
670
|
+
)
|
|
671
|
+
for i in range(1, len(hist)):
|
|
672
|
+
if not isinstance(hist[i - 1], dict) or not isinstance(hist[i], dict):
|
|
673
|
+
continue
|
|
674
|
+
prev_after = hist[i - 1].get("life_after")
|
|
675
|
+
h = hist[i]
|
|
676
|
+
delta = h.get("delta")
|
|
677
|
+
after = h.get("life_after")
|
|
678
|
+
if delta is None:
|
|
679
|
+
errors.append(f"history[{i}](round={h.get('round')}) 缺 delta")
|
|
680
|
+
continue
|
|
681
|
+
if prev_after is None or after is None or after != prev_after + delta:
|
|
682
|
+
errors.append(
|
|
683
|
+
f"history[{i}](round={h.get('round')}) life_after({after}) "
|
|
684
|
+
f"!= prev({prev_after})+delta({delta})"
|
|
685
|
+
f"{'' if prev_after is None else '=' + str(prev_after + delta)}"
|
|
686
|
+
)
|
|
687
|
+
return errors
|
|
688
|
+
|
|
689
|
+
|
|
690
|
+
def _cmd_check_unlocked() -> int:
|
|
691
|
+
d = load()
|
|
692
|
+
errors = check_errors(d)
|
|
693
|
+
if errors:
|
|
694
|
+
print(f"[verify_life] 不一致({len(errors)} 项):")
|
|
695
|
+
for e in errors:
|
|
696
|
+
print(f" ✗ {e}")
|
|
697
|
+
return 1
|
|
698
|
+
print(
|
|
699
|
+
f"[verify_life] OK: life={d.get('life')} round={d.get('round')} "
|
|
700
|
+
f"rounds_completed={d.get('rounds_completed')} alive={d.get('alive')}"
|
|
701
|
+
)
|
|
702
|
+
return 0
|
|
703
|
+
|
|
704
|
+
|
|
705
|
+
def cmd_check() -> int:
|
|
706
|
+
return _run_locked(_cmd_check_unlocked)
|
|
707
|
+
|
|
708
|
+
|
|
709
|
+
def _cmd_repair_unlocked() -> int:
|
|
710
|
+
if not LIFE_FILE.is_file():
|
|
711
|
+
# bootstrap 例外:寿命文件缺失时 reset 免确认创建初始状态
|
|
712
|
+
# (_cmd_reset_unlocked 的设计边界),随后按新基线做一致性校验。
|
|
713
|
+
print("[verify_life] 寿命文件不存在,按首次运行初始化…")
|
|
714
|
+
if _cmd_reset_unlocked([]) != 0:
|
|
715
|
+
return 1
|
|
716
|
+
d = load()
|
|
717
|
+
errors = check_errors(d)
|
|
718
|
+
if errors:
|
|
719
|
+
print(f"[verify_life] 初始化基线仍不一致({len(errors)} 项),拒绝继续")
|
|
720
|
+
return 1
|
|
721
|
+
print("[verify_life] ✓ 初始基线已创建且一致")
|
|
722
|
+
return 0
|
|
723
|
+
d = load()
|
|
724
|
+
errors = check_errors(d)
|
|
725
|
+
if not errors:
|
|
726
|
+
print("[verify_life] 已一致,无需修复")
|
|
727
|
+
return 0
|
|
728
|
+
hist = d.get("history") or []
|
|
729
|
+
if any(not isinstance(item, dict) for item in hist):
|
|
730
|
+
print("[verify_life] history 含非对象条目,拒绝自动 repair;请 restore 或人工复核")
|
|
731
|
+
_audit("repair-refused", "history member is not object")
|
|
732
|
+
return 1
|
|
733
|
+
# 先检测 history 的 life_after 链是否断裂 / 缺 delta:
|
|
734
|
+
# 若断裂,说明 history 内容被篡改,机械修复会把伪造的 life_after
|
|
735
|
+
# 当作权威写进 life —— 拒绝自动修,交给 diff/restore 或人工。
|
|
736
|
+
prev = 1
|
|
737
|
+
chain_broken = False
|
|
738
|
+
for h in hist:
|
|
739
|
+
delta = h.get("delta")
|
|
740
|
+
after = h.get("life_after")
|
|
741
|
+
if delta is None or after is None or after != prev + delta:
|
|
742
|
+
chain_broken = True
|
|
743
|
+
break
|
|
744
|
+
prev = after
|
|
745
|
+
if chain_broken:
|
|
746
|
+
print("[verify_life] history 的 life_after 链断裂或缺 delta——文件可能"
|
|
747
|
+
"被篡改,拒绝机械修复。")
|
|
748
|
+
print(" 请用 `snapshot` 建立基线后 `restore` 回滚,"
|
|
749
|
+
"或人工复核 history 内容。")
|
|
750
|
+
_audit("repair-refused", f"链断裂拒绝修复: {errors[:3]}")
|
|
751
|
+
return 1
|
|
752
|
+
d["life"] = hist[-1]["life_after"] if hist else 1
|
|
753
|
+
d["rounds_completed"] = len(hist)
|
|
754
|
+
d["round"] = len(hist) + 1
|
|
755
|
+
d["alive"] = d["life"] > 0
|
|
756
|
+
d["found_total"] = sum(_credited(h) for h in hist)
|
|
757
|
+
save(d)
|
|
758
|
+
_audit("repair", f"life={d['life']} rounds={d['rounds_completed']}")
|
|
759
|
+
print(
|
|
760
|
+
f"[verify_life] 已修复: life={d['life']} round={d['round']} "
|
|
761
|
+
f"rounds_completed={d['rounds_completed']} alive={d['alive']} "
|
|
762
|
+
f"found_total={d['found_total']}"
|
|
763
|
+
)
|
|
764
|
+
print(" 回滚项: 幽灵轮费已退回(life 恢复到最后结算值,未结算轮次不扣命)")
|
|
765
|
+
for e in errors:
|
|
766
|
+
print(f" ✓ 已处理: {e}")
|
|
767
|
+
return 0
|
|
768
|
+
|
|
769
|
+
|
|
770
|
+
def cmd_repair() -> int:
|
|
771
|
+
return _run_locked(_cmd_repair_unlocked)
|
|
772
|
+
|
|
773
|
+
|
|
774
|
+
def _cmd_reset_unlocked(argv: list[str] | None = None) -> int:
|
|
775
|
+
"""Reset only during bootstrap or with an explicit user confirmation.
|
|
776
|
+
|
|
777
|
+
A reset is a destructive state transition. The bootstrap exception is
|
|
778
|
+
limited to a missing life file; once a state exists, automation must carry
|
|
779
|
+
the explicit ``--confirm-reset`` acknowledgement.
|
|
780
|
+
"""
|
|
781
|
+
argv = argv or []
|
|
782
|
+
if LIFE_FILE.exists() and "--confirm-reset" not in argv:
|
|
783
|
+
print("[verify_life] 已存在寿命状态;reset 必须显式提供 --confirm-reset")
|
|
784
|
+
_audit("reset-refused", "missing --confirm-reset")
|
|
785
|
+
return 2
|
|
786
|
+
ledger_file = LIFE_FILE.with_name("finding-ledger.json")
|
|
787
|
+
if ledger_file.is_file():
|
|
788
|
+
try:
|
|
789
|
+
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
|
790
|
+
from core.ledger.life_ledger import FindingLedger
|
|
791
|
+
|
|
792
|
+
FindingLedger(ledger_file).reset(worker="verify_life", evidence_refs=[])
|
|
793
|
+
except (ImportError, OSError, ValueError, KeyError) as exc:
|
|
794
|
+
print(f"[verify_life] 全局 finding ledger reset 审计失败,拒绝重置: {exc}")
|
|
795
|
+
return 1
|
|
796
|
+
d = {
|
|
797
|
+
"life": 1,
|
|
798
|
+
"found_total": 0,
|
|
799
|
+
"round": 1,
|
|
800
|
+
"rounds_completed": 0,
|
|
801
|
+
"alive": True,
|
|
802
|
+
"mode": None,
|
|
803
|
+
"history": [],
|
|
804
|
+
}
|
|
805
|
+
save(d)
|
|
806
|
+
print("[verify_life] 已重置为初始状态")
|
|
807
|
+
return 0
|
|
808
|
+
|
|
809
|
+
|
|
810
|
+
def cmd_reset(argv: list[str] | None = None) -> int:
|
|
811
|
+
return _run_locked(lambda: _cmd_reset_unlocked(argv))
|
|
812
|
+
|
|
813
|
+
|
|
814
|
+
def _cmd_set_mode_unlocked(argv: list[str]) -> int:
|
|
815
|
+
"""持久化用户已确认的修复模式;模式不由 agent 自行猜测。"""
|
|
816
|
+
mode = None
|
|
817
|
+
confirmed = False
|
|
818
|
+
i = 0
|
|
819
|
+
while i < len(argv):
|
|
820
|
+
if argv[i] == "--mode" and i + 1 < len(argv):
|
|
821
|
+
mode = argv[i + 1]
|
|
822
|
+
i += 2
|
|
823
|
+
elif argv[i] == "--confirm":
|
|
824
|
+
confirmed = True
|
|
825
|
+
i += 1
|
|
826
|
+
else:
|
|
827
|
+
print(f"[verify_life] set-mode 未知参数: {argv[i]}")
|
|
828
|
+
return 2
|
|
829
|
+
if mode not in VALID_MODES:
|
|
830
|
+
print(
|
|
831
|
+
f"[verify_life] mode({mode!r}) 无效,必须是 "
|
|
832
|
+
"auto 或 log-only"
|
|
833
|
+
)
|
|
834
|
+
return 1
|
|
835
|
+
d = load()
|
|
836
|
+
if not d.get("alive", True) or d.get("life", 0) <= 0:
|
|
837
|
+
print("[verify_life] 已死亡,不能设置会话模式——先经用户确认 reset")
|
|
838
|
+
return 1
|
|
839
|
+
if d.get("mode") not in (None, mode) and not confirmed:
|
|
840
|
+
print("[verify_life] 修改已确认 mode 必须显式提供 --confirm")
|
|
841
|
+
_audit("set-mode-refused", f"{d.get('mode')} -> {mode}")
|
|
842
|
+
return 2
|
|
843
|
+
d["mode"] = mode
|
|
844
|
+
_save_atomic(d)
|
|
845
|
+
errs = check_errors(d)
|
|
846
|
+
if errs:
|
|
847
|
+
print("[verify_life] 设置 mode 后校验失败:")
|
|
848
|
+
for e in errs:
|
|
849
|
+
print(f" ✗ {e}")
|
|
850
|
+
return 1
|
|
851
|
+
print(f"[verify_life] 已保存用户确认模式: {mode}")
|
|
852
|
+
return 0
|
|
853
|
+
|
|
854
|
+
|
|
855
|
+
def cmd_set_mode(argv: list[str]) -> int:
|
|
856
|
+
return _run_locked(lambda: _cmd_set_mode_unlocked(argv))
|
|
857
|
+
|
|
858
|
+
|
|
859
|
+
def _cmd_snapshot_unlocked() -> int:
|
|
860
|
+
if not LIFE_FILE.is_file():
|
|
861
|
+
print("[verify_life] 无寿命文件可备份——先确认 bugx-life.json 存在")
|
|
862
|
+
return 1
|
|
863
|
+
if SNAPSHOT_FILE.is_symlink() or SNAPSHOT_FILE.parent.is_symlink():
|
|
864
|
+
print(f"[verify_life] 拒绝写入符号链接快照路径: {SNAPSHOT_FILE}")
|
|
865
|
+
return 1
|
|
866
|
+
try:
|
|
867
|
+
# F-184:pre 的可信宿主在此签发外部基线锚。baseline_json() 读的就是
|
|
868
|
+
# LIFE_FILE,因此把锚写回寿命文件后,pre 导出的 BH_PRE_BASELINE 天然
|
|
869
|
+
# 携带来源标识与 hash;post 的 external_baseline() 据此强制校验。
|
|
870
|
+
current = load()
|
|
871
|
+
if not isinstance(current, dict):
|
|
872
|
+
print("[verify_life] 寿命状态根节点必须是 JSON 对象,拒绝快照。")
|
|
873
|
+
return 1
|
|
874
|
+
signed = sign_baseline(current)
|
|
875
|
+
_write_json_durable(LIFE_FILE, signed, prefix=".life-")
|
|
876
|
+
_copy_atomic(LIFE_FILE, SNAPSHOT_FILE)
|
|
877
|
+
except OSError as e:
|
|
878
|
+
print(f"[verify_life] 快照建立失败: {e}")
|
|
879
|
+
return 1
|
|
880
|
+
print(f"[verify_life] 已备份当前状态到 {SNAPSHOT_FILE.name}(已签发基线完整性锚)")
|
|
881
|
+
return 0
|
|
882
|
+
|
|
883
|
+
|
|
884
|
+
def cmd_snapshot() -> int:
|
|
885
|
+
return _run_locked(_cmd_snapshot_unlocked)
|
|
886
|
+
|
|
887
|
+
|
|
888
|
+
def _cmd_diff_unlocked() -> int:
|
|
889
|
+
"""对比当前状态与基线(外部基线优先,快照文件兜底),
|
|
890
|
+
检出「自洽撒谎」/超范围涨命/历史篡改。修复漏洞 2。"""
|
|
891
|
+
snap = external_baseline()
|
|
892
|
+
if snap is None:
|
|
893
|
+
print("[verify_life] 无可用基线——外部基线校验失败/未设置且无快照文件,"
|
|
894
|
+
"先修复基线来源或运行 snapshot 再跑 diff")
|
|
895
|
+
return 2
|
|
896
|
+
baseline_errors = check_errors(snap)
|
|
897
|
+
if baseline_errors:
|
|
898
|
+
print("[verify_life] 外部基线不合法,拒绝 diff:")
|
|
899
|
+
for error in baseline_errors:
|
|
900
|
+
print(f" ✗ {error}")
|
|
901
|
+
return 2
|
|
902
|
+
src = snap.get(BASELINE_SOURCE_FIELD, "未知来源")
|
|
903
|
+
cur = load()
|
|
904
|
+
current_errors = check_errors(cur)
|
|
905
|
+
if current_errors:
|
|
906
|
+
print("[verify_life] 当前寿命状态不合法,拒绝 diff:")
|
|
907
|
+
for error in current_errors:
|
|
908
|
+
print(f" ✗ {error}")
|
|
909
|
+
return 1
|
|
910
|
+
issues: list[str] = []
|
|
911
|
+
snap_rounds = snap.get("rounds_completed", 0)
|
|
912
|
+
cur_rounds = cur.get("rounds_completed", 0)
|
|
913
|
+
run = cur_rounds - snap_rounds
|
|
914
|
+
# 已确认的会话模式不可在运行中静默切换;旧基线没有 mode 时允许一次迁移初始化。
|
|
915
|
+
snap_mode = snap.get("mode")
|
|
916
|
+
cur_mode = cur.get("mode")
|
|
917
|
+
if snap_mode is not None and cur_mode != snap_mode:
|
|
918
|
+
issues.append(f"会话 mode 被改写: {snap_mode!r} -> {cur_mode!r}")
|
|
919
|
+
if run < 0:
|
|
920
|
+
issues.append(f"rounds_completed 回退: {snap_rounds} -> {cur_rounds}")
|
|
921
|
+
snap_hist = snap.get("history") or []
|
|
922
|
+
cur_hist = cur.get("history") or []
|
|
923
|
+
# 历史前缀不可篡改(已结算的轮次不允许被改/删)
|
|
924
|
+
for i in range(min(len(snap_hist), len(cur_hist))):
|
|
925
|
+
if snap_hist[i] != cur_hist[i]:
|
|
926
|
+
issues.append(f"history[{i}](round={snap_hist[i].get('round')})"
|
|
927
|
+
f"被篡改或改写")
|
|
928
|
+
break
|
|
929
|
+
if len(cur_hist) < len(snap_hist):
|
|
930
|
+
issues.append("history 条目被删除")
|
|
931
|
+
if len(cur_hist) != snap_rounds + run:
|
|
932
|
+
issues.append(
|
|
933
|
+
f"history 条数({len(cur_hist)}) != 基线轮数+运行轮数"
|
|
934
|
+
f"({snap_rounds}+{run})"
|
|
935
|
+
)
|
|
936
|
+
# 新增轮次的 delta 精确校验(替代旧的粗略范围,防「诚实记欺诈被误报」):
|
|
937
|
+
# delta = -1(轮费) + credited - fraud
|
|
938
|
+
# 上界:credited ≤ MAX_PER_ROUND → delta ≤ MAX_PER_ROUND - 1
|
|
939
|
+
# 下界:fraud 无上限,不硬校验(诚实记录欺诈不该被回滚)
|
|
940
|
+
cur_life = cur.get("life", 0)
|
|
941
|
+
new_hist = cur_hist[len(snap_hist):]
|
|
942
|
+
total_delta = 0
|
|
943
|
+
for h in new_hist:
|
|
944
|
+
dlt = h.get("delta")
|
|
945
|
+
if dlt is None:
|
|
946
|
+
issues.append(f"新增轮次 round={h.get('round')} 缺 delta")
|
|
947
|
+
continue
|
|
948
|
+
total_delta += dlt
|
|
949
|
+
if dlt > MAX_PER_ROUND - 1:
|
|
950
|
+
issues.append(
|
|
951
|
+
f"round={h.get('round')} delta({dlt}) 超上界 "
|
|
952
|
+
f"(≤{MAX_PER_ROUND - 1})——计命发现数可疑/伪造"
|
|
953
|
+
)
|
|
954
|
+
snap_life = snap.get("life", 1)
|
|
955
|
+
if cur_life != snap_life + total_delta:
|
|
956
|
+
issues.append(
|
|
957
|
+
f"life 变化({cur_life - snap_life}) != 新增轮 delta 之和"
|
|
958
|
+
f"({total_delta})"
|
|
959
|
+
)
|
|
960
|
+
if cur_life <= 0 and cur.get("alive"):
|
|
961
|
+
issues.append("life≤0 但仍 alive(死亡绕过)")
|
|
962
|
+
if issues:
|
|
963
|
+
print(f"[verify_life] diff 检出异常({len(issues)} 项):")
|
|
964
|
+
for e in issues:
|
|
965
|
+
print(f" ✗ {e}")
|
|
966
|
+
return 1
|
|
967
|
+
print(
|
|
968
|
+
f"[verify_life] diff OK({src}): life {snap.get('life')} -> {cur_life} "
|
|
969
|
+
f"({run} 轮)history 前缀未篡改"
|
|
970
|
+
)
|
|
971
|
+
return 0
|
|
972
|
+
|
|
973
|
+
|
|
974
|
+
def cmd_diff() -> int:
|
|
975
|
+
return _run_locked(_cmd_diff_unlocked)
|
|
976
|
+
|
|
977
|
+
|
|
978
|
+
def _cmd_restore_unlocked() -> int:
|
|
979
|
+
"""从快照恢复;快照必须本身合法(可解析 + 通过不变量),防恢复损坏文件。"""
|
|
980
|
+
if not SNAPSHOT_FILE.is_file():
|
|
981
|
+
print("[verify_life] 无快照可恢复——先运行 snapshot")
|
|
982
|
+
return 2
|
|
983
|
+
snap = _load_json(SNAPSHOT_FILE, "快照基线")
|
|
984
|
+
errs = check_errors(snap)
|
|
985
|
+
if errs:
|
|
986
|
+
print("[verify_life] 快照基线本身不合法,拒绝恢复——防止把损坏/篡改的"
|
|
987
|
+
"快照写回并覆盖真实状态:")
|
|
988
|
+
for e in errs:
|
|
989
|
+
print(f" ✗ {e}")
|
|
990
|
+
print(" 请人工复核 bugx-life.json 与快照内容。")
|
|
991
|
+
return 1
|
|
992
|
+
if LIFE_FILE.is_symlink() or LIFE_FILE.parent.is_symlink():
|
|
993
|
+
print(f"[verify_life] 拒绝覆盖符号链接寿命路径: {LIFE_FILE}")
|
|
994
|
+
return 1
|
|
995
|
+
try:
|
|
996
|
+
_copy_atomic(SNAPSHOT_FILE, LIFE_FILE)
|
|
997
|
+
except OSError as exc:
|
|
998
|
+
print(f"[verify_life] 恢复写入失败: {exc}")
|
|
999
|
+
return 1
|
|
1000
|
+
d = load()
|
|
1001
|
+
print(
|
|
1002
|
+
f"[verify_life] 已从快照恢复: life={d.get('life')} "
|
|
1003
|
+
f"round={d.get('round')} rounds_completed={d.get('rounds_completed')}"
|
|
1004
|
+
)
|
|
1005
|
+
return 0
|
|
1006
|
+
|
|
1007
|
+
|
|
1008
|
+
def cmd_restore() -> int:
|
|
1009
|
+
return _run_locked(_cmd_restore_unlocked)
|
|
1010
|
+
|
|
1011
|
+
|
|
1012
|
+
def _fsync_parent(path: Path) -> None:
|
|
1013
|
+
"""Durably flush a directory when the platform exposes directory fsync."""
|
|
1014
|
+
try:
|
|
1015
|
+
descriptor = os.open(str(path), os.O_RDONLY | getattr(os, "O_DIRECTORY", 0))
|
|
1016
|
+
except OSError:
|
|
1017
|
+
return
|
|
1018
|
+
try:
|
|
1019
|
+
os.fsync(descriptor)
|
|
1020
|
+
except OSError:
|
|
1021
|
+
pass
|
|
1022
|
+
finally:
|
|
1023
|
+
os.close(descriptor)
|
|
1024
|
+
|
|
1025
|
+
|
|
1026
|
+
def _write_json_durable(path: Path, payload: dict, *, prefix: str) -> None:
|
|
1027
|
+
"""Atomically write JSON and flush both file and containing directory."""
|
|
1028
|
+
_assert_no_symlink_components(path.parent)
|
|
1029
|
+
if path.is_symlink():
|
|
1030
|
+
raise OSError(f"拒绝写入符号链接 JSON 路径: {path}")
|
|
1031
|
+
fd, tmp = tempfile.mkstemp(
|
|
1032
|
+
dir=str(path.parent), prefix=prefix, suffix=".tmp"
|
|
1033
|
+
)
|
|
1034
|
+
try:
|
|
1035
|
+
with os.fdopen(fd, "w", encoding="utf-8") as f:
|
|
1036
|
+
f.write(json.dumps(payload, ensure_ascii=False, indent=2, allow_nan=False) + "\n")
|
|
1037
|
+
f.flush()
|
|
1038
|
+
os.fsync(f.fileno())
|
|
1039
|
+
os.replace(tmp, path)
|
|
1040
|
+
_fsync_parent(path.parent)
|
|
1041
|
+
except BaseException:
|
|
1042
|
+
try:
|
|
1043
|
+
os.unlink(tmp)
|
|
1044
|
+
except OSError:
|
|
1045
|
+
pass
|
|
1046
|
+
raise
|
|
1047
|
+
|
|
1048
|
+
|
|
1049
|
+
def _save_atomic(d: dict) -> None:
|
|
1050
|
+
"""原子且耐久地写回寿命状态。"""
|
|
1051
|
+
_write_json_durable(LIFE_FILE, d, prefix=".life-")
|
|
1052
|
+
|
|
1053
|
+
|
|
1054
|
+
def _settlement_wal_path() -> Path:
|
|
1055
|
+
return LIFE_FILE.with_name(f".{LIFE_FILE.name}.settlement-wal.json")
|
|
1056
|
+
|
|
1057
|
+
|
|
1058
|
+
def _state_digest(value: dict) -> str:
|
|
1059
|
+
encoded = json.dumps(
|
|
1060
|
+
value, ensure_ascii=False, sort_keys=True, separators=(",", ":"), allow_nan=False,
|
|
1061
|
+
).encode("utf-8")
|
|
1062
|
+
return hashlib.sha256(encoded).hexdigest()
|
|
1063
|
+
|
|
1064
|
+
|
|
1065
|
+
def _resolve_ledger_path(value: str | os.PathLike[str]) -> Path:
|
|
1066
|
+
candidate = Path(value)
|
|
1067
|
+
if not candidate.is_absolute():
|
|
1068
|
+
candidate = LIFE_FILE.parent / candidate
|
|
1069
|
+
candidate = candidate.resolve(strict=False)
|
|
1070
|
+
candidate.relative_to(LIFE_FILE.parent.resolve())
|
|
1071
|
+
return candidate
|
|
1072
|
+
|
|
1073
|
+
|
|
1074
|
+
def _clear_settlement_wal() -> None:
|
|
1075
|
+
wal_path = _settlement_wal_path()
|
|
1076
|
+
if wal_path.is_symlink():
|
|
1077
|
+
raise SettlementRecoveryError(f"pending settlement WAL 是符号链接: {wal_path}")
|
|
1078
|
+
try:
|
|
1079
|
+
wal_path.unlink()
|
|
1080
|
+
except FileNotFoundError:
|
|
1081
|
+
return
|
|
1082
|
+
_fsync_parent(wal_path.parent)
|
|
1083
|
+
|
|
1084
|
+
|
|
1085
|
+
def _ledger_has_settlement(state: dict, fingerprints: list[str], settlement_id: str) -> bool:
|
|
1086
|
+
findings = state.get("findings")
|
|
1087
|
+
if not isinstance(findings, dict):
|
|
1088
|
+
return False
|
|
1089
|
+
for fingerprint in fingerprints:
|
|
1090
|
+
record = findings.get(fingerprint)
|
|
1091
|
+
if not isinstance(record, dict):
|
|
1092
|
+
return False
|
|
1093
|
+
audits = record.get("audits")
|
|
1094
|
+
if not isinstance(audits, list) or not any(
|
|
1095
|
+
isinstance(audit, dict) and audit.get("settlement_id") == settlement_id
|
|
1096
|
+
for audit in audits
|
|
1097
|
+
):
|
|
1098
|
+
return False
|
|
1099
|
+
return True
|
|
1100
|
+
|
|
1101
|
+
|
|
1102
|
+
def _ledger_has_any(state: dict, fingerprints: list[str]) -> bool:
|
|
1103
|
+
findings = state.get("findings")
|
|
1104
|
+
return isinstance(findings, dict) and any(item in findings for item in fingerprints)
|
|
1105
|
+
|
|
1106
|
+
|
|
1107
|
+
def _validate_settlement_wal(payload: object) -> dict:
|
|
1108
|
+
if not isinstance(payload, dict) or payload.get("schema_version") != SETTLEMENT_WAL_SCHEMA:
|
|
1109
|
+
raise SettlementRecoveryError("pending settlement WAL schema 无法识别")
|
|
1110
|
+
required = {
|
|
1111
|
+
"settlement_id", "before_hash", "after_hash", "before_state", "after_state",
|
|
1112
|
+
"findings", "finding_fingerprints", "round", "ledger_path", "ledger_version",
|
|
1113
|
+
}
|
|
1114
|
+
if not required <= set(payload):
|
|
1115
|
+
raise SettlementRecoveryError("pending settlement WAL 缺少必要字段")
|
|
1116
|
+
txid = payload.get("settlement_id")
|
|
1117
|
+
if not isinstance(txid, str) or not re.fullmatch(r"[A-Za-z0-9_-]{16,128}", txid):
|
|
1118
|
+
raise SettlementRecoveryError("pending settlement WAL transaction ID 无效")
|
|
1119
|
+
before = payload.get("before_state")
|
|
1120
|
+
after = payload.get("after_state")
|
|
1121
|
+
if not isinstance(before, dict) or not isinstance(after, dict):
|
|
1122
|
+
raise SettlementRecoveryError("pending settlement WAL 状态快照无效")
|
|
1123
|
+
if payload.get("before_hash") != _state_digest(before) or payload.get("after_hash") != _state_digest(after):
|
|
1124
|
+
raise SettlementRecoveryError("pending settlement WAL 状态哈希不匹配")
|
|
1125
|
+
if check_errors(before) or check_errors(after):
|
|
1126
|
+
raise SettlementRecoveryError("pending settlement WAL 包含不一致的寿命状态")
|
|
1127
|
+
findings = payload.get("findings")
|
|
1128
|
+
fingerprints = payload.get("finding_fingerprints")
|
|
1129
|
+
if not isinstance(findings, list) or not isinstance(fingerprints, list) \
|
|
1130
|
+
or len(findings) != len(fingerprints) \
|
|
1131
|
+
or any(not isinstance(item, str) or not item for item in findings) \
|
|
1132
|
+
or any(not isinstance(item, str) or not item for item in fingerprints) \
|
|
1133
|
+
or len(set(fingerprints)) != len(fingerprints):
|
|
1134
|
+
raise SettlementRecoveryError("pending settlement WAL finding 批次无效")
|
|
1135
|
+
round_no = payload.get("round")
|
|
1136
|
+
if isinstance(round_no, bool) or not isinstance(round_no, int) or round_no < 1:
|
|
1137
|
+
raise SettlementRecoveryError("pending settlement WAL round 无效")
|
|
1138
|
+
ledger_path = payload.get("ledger_path")
|
|
1139
|
+
if ledger_path is not None and (not isinstance(ledger_path, str) or not ledger_path.strip()):
|
|
1140
|
+
raise SettlementRecoveryError("pending settlement WAL ledger 路径无效")
|
|
1141
|
+
ledger_version = payload.get("ledger_version")
|
|
1142
|
+
if ledger_version is not None and (
|
|
1143
|
+
isinstance(ledger_version, bool) or not isinstance(ledger_version, int) or ledger_version < 0
|
|
1144
|
+
):
|
|
1145
|
+
raise SettlementRecoveryError("pending settlement WAL ledger 版本无效")
|
|
1146
|
+
return payload
|
|
1147
|
+
|
|
1148
|
+
|
|
1149
|
+
def _load_settlement_wal() -> dict | None:
|
|
1150
|
+
wal_path = _settlement_wal_path()
|
|
1151
|
+
if wal_path.is_symlink():
|
|
1152
|
+
raise SettlementRecoveryError(f"pending settlement WAL 是符号链接: {wal_path}")
|
|
1153
|
+
if not wal_path.exists():
|
|
1154
|
+
return None
|
|
1155
|
+
try:
|
|
1156
|
+
payload = json.loads(wal_path.read_text(encoding="utf-8"))
|
|
1157
|
+
except (OSError, UnicodeDecodeError, json.JSONDecodeError) as exc:
|
|
1158
|
+
raise SettlementRecoveryError(f"pending settlement WAL 无法解析: {exc}") from exc
|
|
1159
|
+
return _validate_settlement_wal(payload)
|
|
1160
|
+
|
|
1161
|
+
|
|
1162
|
+
def _recover_pending_settlement_unlocked() -> None:
|
|
1163
|
+
payload = _load_settlement_wal()
|
|
1164
|
+
if payload is None:
|
|
1165
|
+
return
|
|
1166
|
+
try:
|
|
1167
|
+
current = load()
|
|
1168
|
+
except SystemExit as exc:
|
|
1169
|
+
raise SettlementRecoveryError("pending settlement 存在,但 life 状态不可读取") from exc
|
|
1170
|
+
current_hash = _state_digest(current)
|
|
1171
|
+
before_hash = payload["before_hash"]
|
|
1172
|
+
after_hash = payload["after_hash"]
|
|
1173
|
+
if current_hash not in {before_hash, after_hash}:
|
|
1174
|
+
raise SettlementRecoveryError("pending settlement 的当前 life 不匹配 before/after 快照")
|
|
1175
|
+
|
|
1176
|
+
fingerprints = list(payload["finding_fingerprints"])
|
|
1177
|
+
findings = list(payload["findings"])
|
|
1178
|
+
if fingerprints:
|
|
1179
|
+
try:
|
|
1180
|
+
from core.ledger.life_ledger import FindingLedger
|
|
1181
|
+
|
|
1182
|
+
ledger = FindingLedger(_resolve_ledger_path(payload["ledger_path"]))
|
|
1183
|
+
ledger_state = ledger.read()
|
|
1184
|
+
if not _ledger_has_settlement(ledger_state, fingerprints, payload["settlement_id"]):
|
|
1185
|
+
if _ledger_has_any(ledger_state, fingerprints):
|
|
1186
|
+
raise SettlementRecoveryError(
|
|
1187
|
+
"pending settlement 的 fingerprint 已存在,但没有本 transaction ID"
|
|
1188
|
+
)
|
|
1189
|
+
result = ledger.settle(
|
|
1190
|
+
findings,
|
|
1191
|
+
round=payload["round"],
|
|
1192
|
+
worker="verify_life",
|
|
1193
|
+
timestamp=payload.get("timestamp"),
|
|
1194
|
+
expected_version=payload.get("ledger_version"),
|
|
1195
|
+
settlement_id=payload["settlement_id"],
|
|
1196
|
+
)
|
|
1197
|
+
if result.conflicts:
|
|
1198
|
+
raise SettlementRecoveryError("pending settlement ledger CAS 冲突")
|
|
1199
|
+
ledger_state = ledger.read()
|
|
1200
|
+
if not _ledger_has_settlement(ledger_state, fingerprints, payload["settlement_id"]):
|
|
1201
|
+
raise SettlementRecoveryError("pending settlement ledger 提交后无法核验")
|
|
1202
|
+
except SettlementRecoveryError:
|
|
1203
|
+
raise
|
|
1204
|
+
except (ImportError, OSError, ValueError, KeyError) as exc:
|
|
1205
|
+
raise SettlementRecoveryError(f"pending settlement ledger 恢复失败: {exc}") from exc
|
|
1206
|
+
|
|
1207
|
+
if current_hash == before_hash:
|
|
1208
|
+
_save_atomic(payload["after_state"])
|
|
1209
|
+
_clear_settlement_wal()
|
|
1210
|
+
|
|
1211
|
+
|
|
1212
|
+
def _settlement_failpoint(stage: str) -> None:
|
|
1213
|
+
"""Test hook; production is a no-op and subprocess tests may replace it."""
|
|
1214
|
+
del stage
|
|
1215
|
+
|
|
1216
|
+
|
|
1217
|
+
def _run_locked(callback):
|
|
1218
|
+
try:
|
|
1219
|
+
with _life_lock():
|
|
1220
|
+
_recover_pending_settlement_unlocked()
|
|
1221
|
+
return callback()
|
|
1222
|
+
except SettlementRecoveryError as exc:
|
|
1223
|
+
print(f"[verify_life] ✗ pending settlement 恢复失败,已拒绝继续: {exc}")
|
|
1224
|
+
return 1
|
|
1225
|
+
|
|
1226
|
+
|
|
1227
|
+
def _copy_atomic(source: Path, target: Path) -> None:
|
|
1228
|
+
"""Copy a validated JSON file without exposing a partial target."""
|
|
1229
|
+
_assert_no_symlink_components(source.parent)
|
|
1230
|
+
_assert_no_symlink_components(target.parent)
|
|
1231
|
+
if source.is_symlink() or target.is_symlink():
|
|
1232
|
+
raise OSError(f"拒绝通过符号链接复制状态文件: {source} -> {target}")
|
|
1233
|
+
if not source.is_file():
|
|
1234
|
+
raise OSError(f"源状态文件不存在: {source}")
|
|
1235
|
+
target.parent.mkdir(parents=True, exist_ok=True)
|
|
1236
|
+
fd, tmp = tempfile.mkstemp(
|
|
1237
|
+
dir=str(target.parent), prefix=f".{target.name}-", suffix=".tmp",
|
|
1238
|
+
)
|
|
1239
|
+
try:
|
|
1240
|
+
with source.open("rb") as src, os.fdopen(fd, "wb") as dst:
|
|
1241
|
+
shutil.copyfileobj(src, dst)
|
|
1242
|
+
dst.flush()
|
|
1243
|
+
os.fsync(dst.fileno())
|
|
1244
|
+
os.replace(tmp, target)
|
|
1245
|
+
except BaseException:
|
|
1246
|
+
try:
|
|
1247
|
+
os.unlink(tmp)
|
|
1248
|
+
except OSError:
|
|
1249
|
+
pass
|
|
1250
|
+
raise
|
|
1251
|
+
|
|
1252
|
+
|
|
1253
|
+
def _cmd_settle_unlocked(argv: list[str]) -> int:
|
|
1254
|
+
"""agent 每轮结算的确定性入口(替代手写 JSON)。
|
|
1255
|
+
|
|
1256
|
+
由脚本计算 delta/life/life_after/found_total/rounds 并原子写回,
|
|
1257
|
+
结算结果必然满足全部不变量(check 必过)。参数:
|
|
1258
|
+
--credited N 本轮计命发现数([0, MAX_PER_ROUND],脚本护栏)
|
|
1259
|
+
--fraud N 本轮欺诈扣分(≥0,默认 0)
|
|
1260
|
+
--findings-file PATH 本轮全部发现清单文件(每行一条;可含超额/重复)
|
|
1261
|
+
--ts YYYY-MM-DD 时间戳(默认今天)
|
|
1262
|
+
--round N 期望本轮号(可选;与 rounds_completed+1 不符则拒绝,
|
|
1263
|
+
防误用旧轮号重复结算)
|
|
1264
|
+
"""
|
|
1265
|
+
credited = 0
|
|
1266
|
+
fraud = 0
|
|
1267
|
+
findings_file = None
|
|
1268
|
+
ledger_path = None
|
|
1269
|
+
ts = None
|
|
1270
|
+
expect_round = None
|
|
1271
|
+
replay = False
|
|
1272
|
+
i = 0
|
|
1273
|
+
while i < len(argv):
|
|
1274
|
+
a = argv[i]
|
|
1275
|
+
if a == "--credited" and i + 1 < len(argv):
|
|
1276
|
+
credited = _int_arg(argv[i + 1], "--credited")
|
|
1277
|
+
i += 2
|
|
1278
|
+
elif a == "--fraud" and i + 1 < len(argv):
|
|
1279
|
+
fraud = _int_arg(argv[i + 1], "--fraud")
|
|
1280
|
+
i += 2
|
|
1281
|
+
elif a == "--findings-file" and i + 1 < len(argv):
|
|
1282
|
+
findings_file = argv[i + 1]
|
|
1283
|
+
i += 2
|
|
1284
|
+
elif a == "--ledger" and i + 1 < len(argv):
|
|
1285
|
+
ledger_path = argv[i + 1]
|
|
1286
|
+
i += 2
|
|
1287
|
+
elif a == "--ts" and i + 1 < len(argv):
|
|
1288
|
+
ts = argv[i + 1]
|
|
1289
|
+
i += 2
|
|
1290
|
+
elif a == "--round" and i + 1 < len(argv):
|
|
1291
|
+
expect_round = _int_arg(argv[i + 1], "--round")
|
|
1292
|
+
i += 2
|
|
1293
|
+
elif a == "--replay":
|
|
1294
|
+
replay = True
|
|
1295
|
+
i += 1
|
|
1296
|
+
else:
|
|
1297
|
+
print(f"[verify_life] settle 未知参数: {a}")
|
|
1298
|
+
return 2
|
|
1299
|
+
if credited < 0 or credited > MAX_PER_ROUND:
|
|
1300
|
+
print(f"[verify_life] credited({credited}) 越界,须在 [0, {MAX_PER_ROUND}]")
|
|
1301
|
+
return 1
|
|
1302
|
+
if fraud < 0:
|
|
1303
|
+
print(f"[verify_life] fraud({fraud}) 不能为负")
|
|
1304
|
+
return 1
|
|
1305
|
+
d = load()
|
|
1306
|
+
if not d.get("alive", True) or d.get("life", 0) <= 0:
|
|
1307
|
+
print("[verify_life] 已死亡(alive=false, life≤0),拒绝结算——"
|
|
1308
|
+
"死亡即冻结,不得再记录轮次")
|
|
1309
|
+
return 1
|
|
1310
|
+
errs = check_errors(d)
|
|
1311
|
+
if errs:
|
|
1312
|
+
print("[verify_life] 基线不一致,拒绝结算——先 `repair` 或 `restore` 恢复基线")
|
|
1313
|
+
for e in errs:
|
|
1314
|
+
print(f" ✗ {e}")
|
|
1315
|
+
return 1
|
|
1316
|
+
if findings_file is None:
|
|
1317
|
+
print("[verify_life] settle 必须提供 --findings-file")
|
|
1318
|
+
return 2
|
|
1319
|
+
try:
|
|
1320
|
+
findings = [
|
|
1321
|
+
ln.strip()
|
|
1322
|
+
for ln in Path(findings_file).read_text(encoding="utf-8").splitlines()
|
|
1323
|
+
if ln.strip()
|
|
1324
|
+
]
|
|
1325
|
+
except (OSError, UnicodeDecodeError) as e:
|
|
1326
|
+
print(f"[verify_life] 读取 findings 文件失败: {e}")
|
|
1327
|
+
return 1
|
|
1328
|
+
if len(findings) < credited:
|
|
1329
|
+
print(f"[verify_life] findings({len(findings)} 条) 少于 credited({credited})"
|
|
1330
|
+
"——计命数不能超过已记录发现")
|
|
1331
|
+
return 1
|
|
1332
|
+
if replay:
|
|
1333
|
+
if d.get("rounds_completed", 0) <= 0 or not d.get("history"):
|
|
1334
|
+
print("[verify_life] 尚未有已完成轮次,无法 --replay 覆盖")
|
|
1335
|
+
return 1
|
|
1336
|
+
if expect_round is not None and expect_round != d["rounds_completed"]:
|
|
1337
|
+
print(f"[verify_life] --replay 期望轮号({expect_round}) != 当前最后完成轮号({d['rounds_completed']})")
|
|
1338
|
+
return 1
|
|
1339
|
+
last_entry = d["history"].pop()
|
|
1340
|
+
last_delta = last_entry.get("delta", 0)
|
|
1341
|
+
last_credited = _credited(last_entry)
|
|
1342
|
+
d["rounds_completed"] -= 1
|
|
1343
|
+
d["life"] -= last_delta
|
|
1344
|
+
d["found_total"] -= last_credited
|
|
1345
|
+
round_no = d["rounds_completed"] + 1
|
|
1346
|
+
if expect_round is not None and expect_round != round_no:
|
|
1347
|
+
print(f"[verify_life] 期望轮号({expect_round}) != 当前应结算轮号"
|
|
1348
|
+
f"({round_no})——疑似重复结算或轮号错乱,拒绝")
|
|
1349
|
+
return 1
|
|
1350
|
+
# 与历史「原样字符串」重复的发现不计命(根因去重的字符串级护栏):
|
|
1351
|
+
# 堵「复制粘贴历史 findings 刷命」;语义重复(措辞不同)仍靠 agent 自觉。
|
|
1352
|
+
all_hist_findings = set()
|
|
1353
|
+
for h in d.get("history") or []:
|
|
1354
|
+
for f in (h.get("findings") or []):
|
|
1355
|
+
all_hist_findings.add(str(f))
|
|
1356
|
+
dups = [f for f in findings if f in all_hist_findings]
|
|
1357
|
+
if dups:
|
|
1358
|
+
# 跨 Life 重放(2026-11-09 实测修复):历史原样重复条**幂等剔除**而非
|
|
1359
|
+
# 拒绝——拒绝会让 auto 续轮死锁(同一批 findings 重放是自动重建
|
|
1360
|
+
# findings.json 的正常产物)。剔除后计命集合(countable)替换 findings
|
|
1361
|
+
# 成为后续全部防线与 ledger 的输入;history 仍记录原始提交(审计可追溯)。
|
|
1362
|
+
dups_set = set(dups)
|
|
1363
|
+
countable = [f for f in findings if f not in dups_set]
|
|
1364
|
+
credited = min(credited, len(countable))
|
|
1365
|
+
print(f"[verify_life] 与历史原样重复 {len(dups)} 条已幂等剔除"
|
|
1366
|
+
f"(credited 钳至 {credited}),继续结算")
|
|
1367
|
+
for dd in dups[:5]:
|
|
1368
|
+
print(f" ✗ 剔除重复: {dd[:80]}")
|
|
1369
|
+
countable_findings: list = countable
|
|
1370
|
+
else:
|
|
1371
|
+
countable_findings = list(findings)
|
|
1372
|
+
max_creditable = len(countable_findings)
|
|
1373
|
+
if credited > max_creditable:
|
|
1374
|
+
print(f"[verify_life] credited={credited} 超过可计命发现数 {max_creditable},拒绝结算")
|
|
1375
|
+
return 1
|
|
1376
|
+
# 证据校验(修复漏洞 1:堵「凭空编造 findings 刷命」):
|
|
1377
|
+
# 每条计命发现必须含真实证据引用——`文件:行号`(文件真实存在)或
|
|
1378
|
+
# `test_*` 测试名 + 复现/观察标记。校验必须逐行覆盖计命前缀
|
|
1379
|
+
# findings[:credited]:按整份文件计数时,「1 条编造 + 5 条真实」
|
|
1380
|
+
# 会让 credited=5 通过,而实际计命前缀含编造行。
|
|
1381
|
+
fingerprints: list[str] = []
|
|
1382
|
+
if credited:
|
|
1383
|
+
bad_evidence = evidence_bad_lines(countable_findings[:credited])
|
|
1384
|
+
if bad_evidence:
|
|
1385
|
+
print(f"[verify_life] 计命前缀含 {len(bad_evidence)} 条缺真实证据引用的发现"
|
|
1386
|
+
f"(无存在的 `文件:行号`,或非 `test_*`+复现标记)——"
|
|
1387
|
+
f"countable_findings[:{credited}] 必须逐条具备证据,拒绝结算。")
|
|
1388
|
+
for b in bad_evidence[:5]:
|
|
1389
|
+
print(f" ✗ 无证据: {b[:100]}")
|
|
1390
|
+
return 1
|
|
1391
|
+
# 去重必须覆盖同一 findings 文件内部;否则把同一条真实 Bug 重复五次
|
|
1392
|
+
# 仍可把 credited 设为 5,绕过仅检查历史的旧门禁。与证据校验同源,
|
|
1393
|
+
# 只对计命前缀 findings[:credited] 计算指纹。
|
|
1394
|
+
if credited:
|
|
1395
|
+
try:
|
|
1396
|
+
from core.ledger.life_ledger import finding_fingerprint
|
|
1397
|
+
fingerprints = [finding_fingerprint(item) for item in countable_findings[:credited]]
|
|
1398
|
+
except (ImportError, TypeError, ValueError) as exc:
|
|
1399
|
+
print(f"[verify_life] finding 身份无法计算: {exc}")
|
|
1400
|
+
return 1
|
|
1401
|
+
if len(set(fingerprints)) < credited:
|
|
1402
|
+
print("[verify_life] 本轮 findings 含重复 finding,credited 超过唯一发现数,拒绝结算")
|
|
1403
|
+
return 1
|
|
1404
|
+
ledger = None
|
|
1405
|
+
ledger_state = None
|
|
1406
|
+
ledger_findings = countable_findings[:credited]
|
|
1407
|
+
if credited and ledger_path is None:
|
|
1408
|
+
# ledger 是计命的强制防线,调用方不能通过省略 --ledger 选择性绕过。
|
|
1409
|
+
ledger_path = str(LIFE_FILE.with_name("finding-ledger.json"))
|
|
1410
|
+
if ledger_path and credited:
|
|
1411
|
+
try:
|
|
1412
|
+
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
|
1413
|
+
from core.ledger.life_ledger import FindingLedger, finding_fingerprint
|
|
1414
|
+
|
|
1415
|
+
candidate = _resolve_ledger_path(ledger_path)
|
|
1416
|
+
ledger = FindingLedger(candidate)
|
|
1417
|
+
ledger_state = ledger.read()
|
|
1418
|
+
existing = set(ledger_state.get("findings", {}))
|
|
1419
|
+
duplicate_fingerprints = [
|
|
1420
|
+
finding_fingerprint(item) for item in ledger_findings
|
|
1421
|
+
if finding_fingerprint(item) in existing
|
|
1422
|
+
]
|
|
1423
|
+
if duplicate_fingerprints:
|
|
1424
|
+
# 跨 Life 重放(2026-11-09 实测修复):同指纹在上一 Life 已入账
|
|
1425
|
+
# 的 finding 再次提交是**幂等重复**,不计新命(从 credited 扣除)
|
|
1426
|
+
# 而不是拒绝整个结算——拒绝会让 auto 续轮场景死锁(同一批
|
|
1427
|
+
# findings 重放是自动重建 findings.json 的正常产物)。本轮内部
|
|
1428
|
+
# 重复仍由上方 set(fingerprints) 防线拒绝(伪造防线不变)。
|
|
1429
|
+
dup_set = set(duplicate_fingerprints)
|
|
1430
|
+
fresh_findings = [
|
|
1431
|
+
item for item in ledger_findings
|
|
1432
|
+
if finding_fingerprint(item) not in dup_set
|
|
1433
|
+
]
|
|
1434
|
+
deduped = len(ledger_findings) - len(fresh_findings)
|
|
1435
|
+
print(
|
|
1436
|
+
"[verify_life] 全局 finding ledger 跨 Life 重复 "
|
|
1437
|
+
f"{deduped} 条已幂等扣除(credited {credited} → "
|
|
1438
|
+
f"{len(fresh_findings)}),继续结算"
|
|
1439
|
+
)
|
|
1440
|
+
credited = len(fresh_findings)
|
|
1441
|
+
ledger_findings = fresh_findings
|
|
1442
|
+
# WAL 的 fingerprints 与前缀同源:同步到幂等扣除后的清单,
|
|
1443
|
+
# 否则 WAL 记录含已入账指纹(审计口径不一致)。
|
|
1444
|
+
fingerprints = [finding_fingerprint(item) for item in fresh_findings]
|
|
1445
|
+
except (ImportError, OSError, ValueError, KeyError) as exc:
|
|
1446
|
+
print(f"[verify_life] 全局 finding ledger 无法读取: {exc}")
|
|
1447
|
+
return 1
|
|
1448
|
+
previous = json.loads(json.dumps(d, ensure_ascii=False))
|
|
1449
|
+
delta = -1 + credited - fraud
|
|
1450
|
+
d["life"] = d["life"] + delta
|
|
1451
|
+
d["found_total"] = d["found_total"] + credited
|
|
1452
|
+
d["rounds_completed"] += 1
|
|
1453
|
+
d["round"] = d["rounds_completed"] + 1
|
|
1454
|
+
d["alive"] = d["life"] > 0
|
|
1455
|
+
d["history"].append({
|
|
1456
|
+
"round": round_no,
|
|
1457
|
+
"ts": ts or time.strftime("%Y-%m-%d"),
|
|
1458
|
+
"delta": delta,
|
|
1459
|
+
"credited": credited,
|
|
1460
|
+
"life_after": d["life"],
|
|
1461
|
+
"findings": findings,
|
|
1462
|
+
})
|
|
1463
|
+
settlement_id = uuid.uuid4().hex
|
|
1464
|
+
wal_payload = {
|
|
1465
|
+
"schema_version": SETTLEMENT_WAL_SCHEMA,
|
|
1466
|
+
"settlement_id": settlement_id,
|
|
1467
|
+
"created_at": time.time(),
|
|
1468
|
+
"before_hash": _state_digest(previous),
|
|
1469
|
+
"after_hash": _state_digest(d),
|
|
1470
|
+
"before_state": previous,
|
|
1471
|
+
"after_state": d,
|
|
1472
|
+
"findings": ledger_findings,
|
|
1473
|
+
"finding_fingerprints": fingerprints,
|
|
1474
|
+
"round": round_no,
|
|
1475
|
+
"timestamp": ts,
|
|
1476
|
+
"ledger_path": str(ledger.path) if ledger is not None else None,
|
|
1477
|
+
"ledger_version": int(ledger_state["version"]) if ledger_state is not None else None,
|
|
1478
|
+
}
|
|
1479
|
+
_write_json_durable(
|
|
1480
|
+
_settlement_wal_path(), wal_payload, prefix=".settlement-wal-",
|
|
1481
|
+
)
|
|
1482
|
+
_settlement_failpoint("after-wal")
|
|
1483
|
+
if ledger is not None and ledger_state is not None:
|
|
1484
|
+
try:
|
|
1485
|
+
result = ledger.settle(
|
|
1486
|
+
ledger_findings,
|
|
1487
|
+
round=round_no,
|
|
1488
|
+
worker="verify_life",
|
|
1489
|
+
timestamp=ts,
|
|
1490
|
+
expected_version=int(ledger_state["version"]),
|
|
1491
|
+
settlement_id=settlement_id,
|
|
1492
|
+
)
|
|
1493
|
+
if result.conflicts or result.duplicate_count or result.accepted_count != credited:
|
|
1494
|
+
print("[verify_life] 全局 finding ledger 并发冲突或计命不一致,保留 pending settlement")
|
|
1495
|
+
return 1
|
|
1496
|
+
except (OSError, ValueError, KeyError) as exc:
|
|
1497
|
+
print(f"[verify_life] 全局 finding ledger 写入失败,保留 pending settlement: {exc}")
|
|
1498
|
+
return 1
|
|
1499
|
+
_settlement_failpoint("after-ledger")
|
|
1500
|
+
_save_atomic(d)
|
|
1501
|
+
_settlement_failpoint("after-life")
|
|
1502
|
+
_clear_settlement_wal()
|
|
1503
|
+
# 自证:settle 写出的状态必须通过 check
|
|
1504
|
+
errs2 = check_errors(d)
|
|
1505
|
+
if errs2:
|
|
1506
|
+
print("[verify_life] settle 后校验失败(内部错误,请上报):")
|
|
1507
|
+
for e in errs2:
|
|
1508
|
+
print(f" ✗ {e}")
|
|
1509
|
+
return 1
|
|
1510
|
+
print(
|
|
1511
|
+
f"[verify_life] 第 {round_no} 轮结算完成: "
|
|
1512
|
+
f"delta={delta} (credited={credited}, fraud={fraud}) "
|
|
1513
|
+
f"life={d['life']} found_total={d['found_total']} "
|
|
1514
|
+
f"rounds_completed={d['rounds_completed']} alive={d['alive']}"
|
|
1515
|
+
)
|
|
1516
|
+
print(f" findings 记录: {len(findings)} 条(含超额/重复,计命 {credited} 条)")
|
|
1517
|
+
return 0
|
|
1518
|
+
|
|
1519
|
+
|
|
1520
|
+
def cmd_settle(argv: list[str]) -> int:
|
|
1521
|
+
"""Serialize settlement so parallel workers cannot lose or duplicate a round."""
|
|
1522
|
+
return _run_locked(lambda: _cmd_settle_unlocked(argv))
|
|
1523
|
+
|
|
1524
|
+
|
|
1525
|
+
def _print_help() -> int:
|
|
1526
|
+
"""Print the life-state commands without reading or modifying state."""
|
|
1527
|
+
print(
|
|
1528
|
+
"""BugX verify_life 寿命状态校验器
|
|
1529
|
+
|
|
1530
|
+
用法
|
|
1531
|
+
python3 verify_life.py <命令> [选项]
|
|
1532
|
+
|
|
1533
|
+
命令
|
|
1534
|
+
check 校验寿命状态一致性
|
|
1535
|
+
repair 修复不一致并记录审计日志
|
|
1536
|
+
reset 重置为初始状态(受确认保护)
|
|
1537
|
+
set-mode --mode MODE 设置修复模式(auto 或 log-only)
|
|
1538
|
+
snapshot 保存当前状态快照
|
|
1539
|
+
diff 对比当前状态与快照/外部基线
|
|
1540
|
+
restore 从快照恢复当前状态
|
|
1541
|
+
settle [选项] 结算当前轮次
|
|
1542
|
+
selfhash 输出校验器自身 SHA256
|
|
1543
|
+
help | --help | -h 显示本说明
|
|
1544
|
+
|
|
1545
|
+
返回码
|
|
1546
|
+
0 成功 1 校验/业务失败 2 参数或命令无效 3 校验器被篡改 4 锁等待超时
|
|
1547
|
+
"""
|
|
1548
|
+
)
|
|
1549
|
+
return 0
|
|
1550
|
+
|
|
1551
|
+
|
|
1552
|
+
def main(argv: list[str]) -> int:
|
|
1553
|
+
# 自校验前置:脚本被篡改则拒绝执行(漏洞 2 防线)。
|
|
1554
|
+
# --selfhash 也走这里(self_check 内处理)。
|
|
1555
|
+
self_check()
|
|
1556
|
+
args = argv[1:]
|
|
1557
|
+
cmd = args[0] if args else "check"
|
|
1558
|
+
if any(arg in {"help", "--help", "-h"} for arg in args):
|
|
1559
|
+
return _print_help()
|
|
1560
|
+
try:
|
|
1561
|
+
if cmd == "settle":
|
|
1562
|
+
return cmd_settle(args[1:])
|
|
1563
|
+
if cmd == "set-mode":
|
|
1564
|
+
return cmd_set_mode(args[1:])
|
|
1565
|
+
if cmd == "reset":
|
|
1566
|
+
return cmd_reset(args[1:])
|
|
1567
|
+
fn = {
|
|
1568
|
+
"check": cmd_check,
|
|
1569
|
+
"repair": cmd_repair,
|
|
1570
|
+
"snapshot": cmd_snapshot,
|
|
1571
|
+
"diff": cmd_diff,
|
|
1572
|
+
"restore": cmd_restore,
|
|
1573
|
+
}.get(cmd)
|
|
1574
|
+
if fn is None:
|
|
1575
|
+
print(
|
|
1576
|
+
"[verify_life] 未知命令: "
|
|
1577
|
+
f"{cmd}(可选 check/repair/reset/set-mode/snapshot/diff/restore/settle/selfhash)"
|
|
1578
|
+
)
|
|
1579
|
+
return 2
|
|
1580
|
+
return fn()
|
|
1581
|
+
except TimeoutError as exc:
|
|
1582
|
+
# _life_lock 超时(DOC-031 锁统一):带锁路径与持有提示的受控失败,
|
|
1583
|
+
# 不以裸 traceback 暴露给调用方。exit 4 = 寿命锁超时。
|
|
1584
|
+
print(f"[verify_life] ✗ {exc}")
|
|
1585
|
+
return 4
|
|
1586
|
+
|
|
1587
|
+
|
|
1588
|
+
def _run_direct(*args: str) -> int:
|
|
1589
|
+
"""进程内直接调用入口:执行 verify_life 命令并返回退出码。"""
|
|
1590
|
+
try:
|
|
1591
|
+
return main(["verify_life.py", *args])
|
|
1592
|
+
except SystemExit as exc:
|
|
1593
|
+
return int(exc.code) if isinstance(exc.code, int) else (0 if exc.code is None else 1)
|
|
1594
|
+
|
|
1595
|
+
|
|
1596
|
+
if __name__ == "__main__":
|
|
1597
|
+
sys.exit(main(sys.argv))
|