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,1564 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""core/supervisor/checkpoint_pipeline.py - Checkpoint 校验与发布流水线 (DOC-070)。
|
|
3
|
+
|
|
4
|
+
负责 Checkpoint 数据清洗、大小/深度门禁、Finding/Evidence 去重与规整、
|
|
5
|
+
签名提取与覆盖证据发布到 coverage-evidence.json。
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import copy
|
|
11
|
+
import errno
|
|
12
|
+
import hashlib
|
|
13
|
+
import json
|
|
14
|
+
import math
|
|
15
|
+
import os
|
|
16
|
+
import sys
|
|
17
|
+
import tempfile
|
|
18
|
+
import time
|
|
19
|
+
from datetime import datetime, timezone
|
|
20
|
+
from pathlib import Path
|
|
21
|
+
from typing import Callable, Iterable, Mapping, Sequence
|
|
22
|
+
|
|
23
|
+
try:
|
|
24
|
+
from core.coverage import module_coverage
|
|
25
|
+
except ImportError:
|
|
26
|
+
from coverage import module_coverage
|
|
27
|
+
|
|
28
|
+
from .supervisor_models import (
|
|
29
|
+
MAX_ARTIFACT_PATH_LENGTH,
|
|
30
|
+
MAX_COMMAND_LENGTH,
|
|
31
|
+
MAX_COVERAGE_PER_CHECKPOINT,
|
|
32
|
+
MAX_EVIDENCE_PER_CHECKPOINT,
|
|
33
|
+
MAX_FINDING_FIELD_LENGTH,
|
|
34
|
+
MAX_FINDING_FINGERPRINT_LENGTH,
|
|
35
|
+
MAX_FINDINGS_PER_CHECKPOINT,
|
|
36
|
+
MAX_ARTIFACT_BYTES,
|
|
37
|
+
ARTIFACT_HASH_CHUNK_BYTES,
|
|
38
|
+
MAX_SIGNATURE_LENGTH,
|
|
39
|
+
MAX_SIGNATURES_PER_CHECKPOINT,
|
|
40
|
+
MAX_UNIT_NOTE_LENGTH,
|
|
41
|
+
SHA256_RE,
|
|
42
|
+
VALID_COVERAGE_STATES,
|
|
43
|
+
TERMINAL_COVERED,
|
|
44
|
+
COVERAGE_COVERED,
|
|
45
|
+
COVERAGE_PENDING,
|
|
46
|
+
unit_source_path,
|
|
47
|
+
COVERAGE_REMOVED,
|
|
48
|
+
COVERAGE_CORRUPTED,
|
|
49
|
+
COVERAGE_STALE,
|
|
50
|
+
VALID_EVIDENCE_STATES,
|
|
51
|
+
InvalidCheckpoint,
|
|
52
|
+
finding_severity_levels,
|
|
53
|
+
normalize_finding_severity,
|
|
54
|
+
RunState,
|
|
55
|
+
WorkspacePathError,
|
|
56
|
+
check_depth_and_keys,
|
|
57
|
+
canonical_json,
|
|
58
|
+
confined_regular_file,
|
|
59
|
+
confined_worker_artifact,
|
|
60
|
+
default_coverage_manifest,
|
|
61
|
+
invalidate_git_head_cache,
|
|
62
|
+
workspace_fingerprint,
|
|
63
|
+
target_identity,
|
|
64
|
+
atomic_write_bytes,
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
_workspace_fingerprint = workspace_fingerprint
|
|
68
|
+
_target_identity = target_identity
|
|
69
|
+
|
|
70
|
+
from core.supervisor.lease_manager import append_event
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
# A passed checkpoint must point at a generated execution artifact, not the
|
|
74
|
+
# source file used to run the check. The Supervisor cannot observe an
|
|
75
|
+
# external worker's stdout directly, so this bounded denylist closes the
|
|
76
|
+
# reported ``verify.py``/``repro.py`` loophole without pretending to prove
|
|
77
|
+
# process execution. ponytail: suffix denylist; add an explicit artifact
|
|
78
|
+
# kind/receipt contract if generated source-suffix outputs become necessary.
|
|
79
|
+
_SOURCE_ARTIFACT_SUFFIXES = frozenset({
|
|
80
|
+
".bash", ".c", ".cc", ".cjs", ".cpp", ".cs", ".cxx", ".fish",
|
|
81
|
+
".go", ".h", ".hpp", ".java", ".js", ".jsx", ".kt", ".kts",
|
|
82
|
+
".mjs", ".php", ".pl", ".pm", ".py", ".pyw", ".rb", ".rs",
|
|
83
|
+
".scala", ".sh", ".swift", ".ts", ".tsx", ".zsh",
|
|
84
|
+
})
|
|
85
|
+
EXECUTION_RECEIPT_KIND = "bugx-worker-execution-receipt/v1"
|
|
86
|
+
UNVERIFIED_EXECUTION = "UNVERIFIED_EXECUTION"
|
|
87
|
+
_EXECUTION_RECEIPT_FIELDS = frozenset({
|
|
88
|
+
"schema_version", "execution_id", "worker_id", "lease_id", "command",
|
|
89
|
+
"exit_code", "artifact_path", "artifact_sha256", "status",
|
|
90
|
+
})
|
|
91
|
+
# Worker 输出契约要求候选自带的结构化复现三件套(worker_runtime/worker_orchestrator)。
|
|
92
|
+
# 这是结算自动裁决器(finding_settlement._adjudicate_candidate_findings)的关键
|
|
93
|
+
# 复现信号:归一化时只在非空字符串时透传,半截/垃圾值一律剔除,防止污染下游。
|
|
94
|
+
_POC_CARRY_FIELDS = ("poc_cmd", "poc_input", "poc_negative_input")
|
|
95
|
+
MAX_CHECKPOINT_BYTES = 512 * 1024
|
|
96
|
+
_STAGED_EVIDENCE_TTL_NS = 10 * 60 * 1_000_000_000
|
|
97
|
+
# DEF-2:证据校验拒绝的有界自纠回路。首次校验 + ≤2 轮自纠 = 最多 3 次评估
|
|
98
|
+
# 机会;同因第三次仍失败则按既有语义中止并如实记录。自纠只做"真相保持"的
|
|
99
|
+
# 格式改写(path:line 拆分 / file→path 键名 / workspace 内绝对路径相对化 /
|
|
100
|
+
# 反斜杠归一 / line 数字字符串转整数),每一步改写都必须重新通过原契约的
|
|
101
|
+
# 真实文件校验才被采纳——契约本身不放宽,伪造 path 无法被自纠成有效证据。
|
|
102
|
+
MAX_EVIDENCE_SELFCORRECTION_ROUNDS = 2
|
|
103
|
+
_EVIDENCE_FEEDBACK_MAX_CHARS = 1600
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def _preserve_poc_carry_fields(item: dict[str, object]) -> None:
|
|
107
|
+
"""就地保留结构化复现三件套:非空字符串才保留,其余剔除(不新增事实)。"""
|
|
108
|
+
for field in _POC_CARRY_FIELDS:
|
|
109
|
+
value = item.get(field)
|
|
110
|
+
if not (isinstance(value, str) and value.strip()):
|
|
111
|
+
item.pop(field, None)
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def execution_receipt_sha256(receipt: Mapping[str, object]) -> str:
|
|
115
|
+
"""Return the durable digest for a normalized claim-bound receipt.
|
|
116
|
+
|
|
117
|
+
The digest preserves the receipt identity when the coverage manifest stores
|
|
118
|
+
only the compact execution metadata. It does not turn a Worker assertion
|
|
119
|
+
into independent proof that a command ran.
|
|
120
|
+
"""
|
|
121
|
+
return hashlib.sha256(canonical_json(receipt)).hexdigest()
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def normalize_execution_receipt(
|
|
125
|
+
receipt: Mapping[str, object], unit: str,
|
|
126
|
+
) -> dict[str, object]:
|
|
127
|
+
"""Normalize the worker-produced receipt without trusting its claims yet."""
|
|
128
|
+
if not isinstance(receipt, Mapping):
|
|
129
|
+
raise InvalidCheckpoint(f"evidence[{unit}].execution_receipt 必须是对象")
|
|
130
|
+
check_depth_and_keys(receipt)
|
|
131
|
+
missing = _EXECUTION_RECEIPT_FIELDS - set(receipt)
|
|
132
|
+
unknown = set(receipt) - _EXECUTION_RECEIPT_FIELDS
|
|
133
|
+
if missing:
|
|
134
|
+
raise InvalidCheckpoint(
|
|
135
|
+
f"evidence[{unit}].execution_receipt 缺字段: {sorted(missing)}"
|
|
136
|
+
)
|
|
137
|
+
if unknown:
|
|
138
|
+
raise InvalidCheckpoint(
|
|
139
|
+
f"evidence[{unit}].execution_receipt 含未知字段: {sorted(unknown)}"
|
|
140
|
+
)
|
|
141
|
+
if receipt["schema_version"] != 1:
|
|
142
|
+
raise InvalidCheckpoint(
|
|
143
|
+
f"evidence[{unit}].execution_receipt schema_version 不支持"
|
|
144
|
+
)
|
|
145
|
+
for field in (
|
|
146
|
+
"execution_id", "worker_id", "lease_id", "command", "artifact_path",
|
|
147
|
+
"artifact_sha256", "status",
|
|
148
|
+
):
|
|
149
|
+
value = receipt[field]
|
|
150
|
+
if not isinstance(value, str) or not value.strip():
|
|
151
|
+
raise InvalidCheckpoint(
|
|
152
|
+
f"evidence[{unit}].execution_receipt.{field} 无效"
|
|
153
|
+
)
|
|
154
|
+
if not isinstance(receipt["exit_code"], int) or isinstance(receipt["exit_code"], bool):
|
|
155
|
+
raise InvalidCheckpoint(
|
|
156
|
+
f"evidence[{unit}].execution_receipt.exit_code 无效"
|
|
157
|
+
)
|
|
158
|
+
if not SHA256_RE.fullmatch(str(receipt["artifact_sha256"])):
|
|
159
|
+
raise InvalidCheckpoint(
|
|
160
|
+
f"evidence[{unit}].execution_receipt.artifact_sha256 无效"
|
|
161
|
+
)
|
|
162
|
+
if receipt["status"] not in VALID_EVIDENCE_STATES:
|
|
163
|
+
raise InvalidCheckpoint(
|
|
164
|
+
f"evidence[{unit}].execution_receipt.status 无效"
|
|
165
|
+
)
|
|
166
|
+
return copy.deepcopy(dict(receipt))
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
def validate_execution_receipt(
|
|
170
|
+
item: Mapping[str, object],
|
|
171
|
+
*,
|
|
172
|
+
unit: str,
|
|
173
|
+
worker_id: str,
|
|
174
|
+
lease_id: str,
|
|
175
|
+
execution_id: str,
|
|
176
|
+
trusted_execution: bool,
|
|
177
|
+
) -> None:
|
|
178
|
+
"""Bind a receipt to the Supervisor-owned claim and evidence metadata."""
|
|
179
|
+
receipt = item.get("execution_receipt")
|
|
180
|
+
artifact = str(item.get("artifact_path") or "")
|
|
181
|
+
if receipt is None:
|
|
182
|
+
if item.get("status") == "passed":
|
|
183
|
+
if Path(artifact).suffix.lower() in _SOURCE_ARTIFACT_SUFFIXES:
|
|
184
|
+
raise InvalidCheckpoint(
|
|
185
|
+
f"evidence[{unit}].artifact_path 必须是执行输出,不能直接引用源码脚本"
|
|
186
|
+
)
|
|
187
|
+
raise InvalidCheckpoint(
|
|
188
|
+
f"evidence[{unit}] passed 必须绑定受信 worker execution receipt"
|
|
189
|
+
"(缺失项是 execution_receipt 对象:schema_version=1 + execution_id/"
|
|
190
|
+
"worker_id/lease_id/command/exit_code/artifact_path/artifact_sha256/"
|
|
191
|
+
"status 与本条 evidence 逐字一致;可用 "
|
|
192
|
+
"`worker_checkpoint.py finalize` 按 claim 自动生成)"
|
|
193
|
+
)
|
|
194
|
+
return
|
|
195
|
+
if not trusted_execution:
|
|
196
|
+
raise InvalidCheckpoint(
|
|
197
|
+
f"evidence[{unit}] 缺少受信 worker execution 记录"
|
|
198
|
+
)
|
|
199
|
+
expected = {
|
|
200
|
+
"execution_id": execution_id,
|
|
201
|
+
"worker_id": worker_id,
|
|
202
|
+
"lease_id": lease_id,
|
|
203
|
+
"command": item["command"],
|
|
204
|
+
"exit_code": item["exit_code"],
|
|
205
|
+
"artifact_path": item["artifact_path"],
|
|
206
|
+
"artifact_sha256": item["artifact_sha256"],
|
|
207
|
+
"status": item["status"],
|
|
208
|
+
}
|
|
209
|
+
for field, value in expected.items():
|
|
210
|
+
if receipt[field] != value:
|
|
211
|
+
raise InvalidCheckpoint(
|
|
212
|
+
f"evidence[{unit}].execution_receipt.{field} 与执行证据不一致"
|
|
213
|
+
)
|
|
214
|
+
if receipt["status"] == "passed" and receipt["exit_code"] != 0:
|
|
215
|
+
raise InvalidCheckpoint(
|
|
216
|
+
f"evidence[{unit}].execution_receipt passed 时 exit_code 必须为 0"
|
|
217
|
+
)
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
def finding_key(finding: Mapping[str, object]) -> str:
|
|
221
|
+
explicit = finding.get("fingerprint")
|
|
222
|
+
if explicit is not None and not isinstance(explicit, str):
|
|
223
|
+
raise InvalidCheckpoint("finding fingerprint 必须是字符串")
|
|
224
|
+
if isinstance(explicit, str) and explicit.strip():
|
|
225
|
+
return explicit.strip()
|
|
226
|
+
try:
|
|
227
|
+
from core.ledger.life_ledger import finding_fingerprint
|
|
228
|
+
|
|
229
|
+
return finding_fingerprint(finding)
|
|
230
|
+
except (ImportError, TypeError, ValueError) as exc:
|
|
231
|
+
raise InvalidCheckpoint(
|
|
232
|
+
"finding 必须包含可识别的 finding_id/id/root_cause/title"
|
|
233
|
+
) from exc
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
def _unit_source_path(unit: object) -> str:
|
|
237
|
+
"""兼容别名:唯一实现已收敛到 ``supervisor_models.unit_source_path``。
|
|
238
|
+
|
|
239
|
+
保留本名是因为 checkpoint 侧的调用点与回归用例按该名字断言;解析逻辑不得
|
|
240
|
+
在本文件里再复制一份(claim 期的同文件互斥键与证据回填必须同源)。
|
|
241
|
+
"""
|
|
242
|
+
return unit_source_path(unit)
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
def merge_coverage_updates(
|
|
246
|
+
current: Mapping[str, str], updates: Mapping[str, str],
|
|
247
|
+
) -> dict[str, str]:
|
|
248
|
+
"""Apply checkpoint coverage updates while preserving covered monotonicity."""
|
|
249
|
+
merged = dict(current)
|
|
250
|
+
for unit, status in updates.items():
|
|
251
|
+
if merged.get(unit) == COVERAGE_COVERED and status != COVERAGE_STALE:
|
|
252
|
+
continue
|
|
253
|
+
merged[unit] = status
|
|
254
|
+
return dict(sorted(merged.items()))
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
def migrate_coverage(
|
|
258
|
+
previous: Mapping[str, str], current_units: Sequence[str],
|
|
259
|
+
) -> tuple[dict[str, str], dict[str, list[str]]]:
|
|
260
|
+
"""Reconcile coverage history against a newly trusted manifest."""
|
|
261
|
+
current = set(current_units)
|
|
262
|
+
migrated = dict(previous)
|
|
263
|
+
added: list[str] = []
|
|
264
|
+
removed: list[str] = []
|
|
265
|
+
stale: list[str] = []
|
|
266
|
+
for unit, status in tuple(migrated.items()):
|
|
267
|
+
if unit not in current:
|
|
268
|
+
if status not in {COVERAGE_CORRUPTED, COVERAGE_REMOVED}:
|
|
269
|
+
migrated[unit] = COVERAGE_REMOVED
|
|
270
|
+
removed.append(unit)
|
|
271
|
+
elif status in TERMINAL_COVERED and status != COVERAGE_CORRUPTED:
|
|
272
|
+
migrated[unit] = COVERAGE_STALE
|
|
273
|
+
stale.append(unit)
|
|
274
|
+
for unit in sorted(current - set(previous)):
|
|
275
|
+
migrated[unit] = COVERAGE_PENDING
|
|
276
|
+
added.append(unit)
|
|
277
|
+
return dict(sorted(migrated.items())), {
|
|
278
|
+
"added": added,
|
|
279
|
+
"removed": sorted(removed),
|
|
280
|
+
"stale": sorted(stale),
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
def load_manifest_units(root: Path, manifest: Path) -> list[str]:
|
|
285
|
+
"""Load trusted coverage IDs; callers cannot invent queue units."""
|
|
286
|
+
try:
|
|
287
|
+
# Reject symlinked manifests before parsing. A project-local link must
|
|
288
|
+
# not redirect queue construction to the shared engine or another
|
|
289
|
+
# workspace.
|
|
290
|
+
manifest = confined_regular_file(root, str(manifest))
|
|
291
|
+
except WorkspacePathError as exc:
|
|
292
|
+
raise InvalidCheckpoint(
|
|
293
|
+
"coverage manifest 必须是 workspace 内的普通文件,不能经过符号链接"
|
|
294
|
+
) from exc
|
|
295
|
+
try:
|
|
296
|
+
manifest.relative_to(root.resolve())
|
|
297
|
+
except ValueError as exc:
|
|
298
|
+
raise InvalidCheckpoint("coverage manifest 路径必须位于 workspace 内") from exc
|
|
299
|
+
try:
|
|
300
|
+
rows, errors = module_coverage.parse_manifest(manifest)
|
|
301
|
+
except (OSError, ValueError) as exc:
|
|
302
|
+
raise InvalidCheckpoint(f"覆盖清单无法加载: {exc}") from exc
|
|
303
|
+
if errors:
|
|
304
|
+
raise InvalidCheckpoint("覆盖清单无效: " + "; ".join(errors))
|
|
305
|
+
units = sorted({module_coverage.coverage_unit_id(row) for row in rows})
|
|
306
|
+
if not units:
|
|
307
|
+
raise InvalidCheckpoint(f"覆盖清单没有可调度单元: {manifest}")
|
|
308
|
+
return units
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
def load_checkpoint_payload(path: Path) -> Mapping[str, object]:
|
|
312
|
+
"""Read and structurally bound one CLI checkpoint JSON object."""
|
|
313
|
+
try:
|
|
314
|
+
if path.stat().st_size > MAX_CHECKPOINT_BYTES:
|
|
315
|
+
raise InvalidCheckpoint(f"checkpoint JSON 过大(>512 KiB): {path}")
|
|
316
|
+
with path.open("rb") as stream:
|
|
317
|
+
raw = stream.read(MAX_CHECKPOINT_BYTES + 1)
|
|
318
|
+
if len(raw) > MAX_CHECKPOINT_BYTES:
|
|
319
|
+
raise InvalidCheckpoint(f"checkpoint JSON 过大(>512 KiB): {path}")
|
|
320
|
+
text = raw.decode("utf-8")
|
|
321
|
+
payload = json.loads(text)
|
|
322
|
+
check_depth_and_keys(payload)
|
|
323
|
+
except (OSError, UnicodeDecodeError, json.JSONDecodeError) as exc:
|
|
324
|
+
raise InvalidCheckpoint(f"checkpoint JSON 无法读取: {path}: {exc}") from exc
|
|
325
|
+
if not isinstance(payload, Mapping):
|
|
326
|
+
raise InvalidCheckpoint("checkpoint JSON 必须是对象")
|
|
327
|
+
return payload
|
|
328
|
+
|
|
329
|
+
|
|
330
|
+
def _stage_owner_alive(pid: int) -> bool:
|
|
331
|
+
if pid <= 0:
|
|
332
|
+
return False
|
|
333
|
+
try:
|
|
334
|
+
os.kill(pid, 0)
|
|
335
|
+
return True
|
|
336
|
+
except OSError as exc:
|
|
337
|
+
return exc.errno == errno.EPERM
|
|
338
|
+
|
|
339
|
+
|
|
340
|
+
def _reconcile_staged_evidence(target: Path) -> None:
|
|
341
|
+
"""Delete only dead or expired stage files for this locked evidence target."""
|
|
342
|
+
prefix = f".{target.name}.stage-"
|
|
343
|
+
now_ns = time.time_ns()
|
|
344
|
+
for candidate in target.parent.glob(prefix + "*"):
|
|
345
|
+
if candidate.is_symlink():
|
|
346
|
+
raise WorkspacePathError(f"拒绝清理符号链接暂存证据: {candidate}")
|
|
347
|
+
if not candidate.is_file():
|
|
348
|
+
continue
|
|
349
|
+
stem = candidate.name.removesuffix(".tmp.lock").removesuffix(".tmp")
|
|
350
|
+
suffix = stem[len(prefix):]
|
|
351
|
+
fields = suffix.split("-", 2)
|
|
352
|
+
if len(fields) != 3 or not fields[0].isdigit() or not fields[1].isdigit():
|
|
353
|
+
continue
|
|
354
|
+
pid, created_ns = int(fields[0]), int(fields[1])
|
|
355
|
+
if _stage_owner_alive(pid) and now_ns - created_ns < _STAGED_EVIDENCE_TTL_NS:
|
|
356
|
+
continue
|
|
357
|
+
candidate.unlink()
|
|
358
|
+
|
|
359
|
+
|
|
360
|
+
def checkpoint_payload_digest(
|
|
361
|
+
*,
|
|
362
|
+
findings: Sequence[Mapping[str, object]],
|
|
363
|
+
coverage: Mapping[str, str],
|
|
364
|
+
evidence: Mapping[str, Mapping[str, object]],
|
|
365
|
+
notes: Mapping[str, str],
|
|
366
|
+
signatures: Sequence[str],
|
|
367
|
+
suggested_modules: Sequence[str],
|
|
368
|
+
life_delta: float,
|
|
369
|
+
) -> str:
|
|
370
|
+
"""Digest the normalized checkpoint payload for retry/fencing checks."""
|
|
371
|
+
payload = {
|
|
372
|
+
"findings": [dict(item) for item in findings],
|
|
373
|
+
"coverage": dict(coverage),
|
|
374
|
+
"evidence": {key: dict(value) for key, value in evidence.items()},
|
|
375
|
+
"notes": dict(notes),
|
|
376
|
+
"signatures": list(signatures),
|
|
377
|
+
"suggested_modules": list(suggested_modules),
|
|
378
|
+
"life_delta": float(life_delta),
|
|
379
|
+
}
|
|
380
|
+
return hashlib.sha256(canonical_json(payload)).hexdigest()
|
|
381
|
+
|
|
382
|
+
|
|
383
|
+
def _derive_run_reference(
|
|
384
|
+
failure_refs: list[tuple[str, str]],
|
|
385
|
+
enriched: Mapping[str, object],
|
|
386
|
+
) -> str:
|
|
387
|
+
"""PE-20261005-006:target_execution.run_reference 取运行身份。
|
|
388
|
+
|
|
389
|
+
优先候选 evidence 里的 run_id(checkpoint 契约要求其等于 state.run_id,
|
|
390
|
+
见 checkpoint_sync evidence 校验);无从取得时回退既有 channel:reference
|
|
391
|
+
拼接,保持旧数据行为不变。
|
|
392
|
+
"""
|
|
393
|
+
evidence = enriched.get("evidence")
|
|
394
|
+
if isinstance(evidence, list):
|
|
395
|
+
for item in evidence:
|
|
396
|
+
if isinstance(item, dict):
|
|
397
|
+
run_id = item.get("run_id")
|
|
398
|
+
if isinstance(run_id, str) and run_id.strip():
|
|
399
|
+
return run_id
|
|
400
|
+
return "; ".join(
|
|
401
|
+
f"{channel}:{reference}" for channel, reference in failure_refs
|
|
402
|
+
)
|
|
403
|
+
|
|
404
|
+
|
|
405
|
+
def enrich_gate_finding(
|
|
406
|
+
finding: Mapping[str, object],
|
|
407
|
+
workspace_root: Path | None = None,
|
|
408
|
+
) -> dict[str, object]:
|
|
409
|
+
"""把 worker 侧自由 schema 的 finding 归一化为确认门禁兼容契约。
|
|
410
|
+
|
|
411
|
+
摄入即补齐 agent_eval 必需字段(id/title/root_cause/confidence/
|
|
412
|
+
evidence 数组),确认门禁从"永远 invalid"变为可裁决;语义状态
|
|
413
|
+
(candidate)与既有字段原样保留,不伪造确认。
|
|
414
|
+
"""
|
|
415
|
+
enriched = dict(finding)
|
|
416
|
+
# 结构化复现三件套透传:非空字符串才保留(旧候选无 poc 字段时行为不变)。
|
|
417
|
+
_preserve_poc_carry_fields(enriched)
|
|
418
|
+
if "severity" in enriched:
|
|
419
|
+
enriched["severity"] = normalize_finding_severity(enriched["severity"])
|
|
420
|
+
fingerprint = str(enriched.get("fingerprint") or enriched.get("id") or "")
|
|
421
|
+
if not str(enriched.get("id") or "").strip():
|
|
422
|
+
enriched["id"] = fingerprint
|
|
423
|
+
if not str(enriched.get("title") or "").strip():
|
|
424
|
+
enriched["title"] = str(
|
|
425
|
+
enriched.get("description") or enriched["id"]
|
|
426
|
+
)[:120]
|
|
427
|
+
if not str(enriched.get("root_cause") or "").strip():
|
|
428
|
+
enriched["root_cause"] = str(
|
|
429
|
+
enriched.get("trigger_condition")
|
|
430
|
+
or enriched.get("description")
|
|
431
|
+
or enriched["title"]
|
|
432
|
+
)
|
|
433
|
+
confidence = enriched.get("confidence")
|
|
434
|
+
if not isinstance(confidence, (int, float)) or isinstance(confidence, bool) or not 0 <= confidence <= 1:
|
|
435
|
+
evidence_blob = json.dumps(
|
|
436
|
+
enriched.get("evidence", ""), ensure_ascii=False, default=str,
|
|
437
|
+
).lower()
|
|
438
|
+
blob = evidence_blob + str(enriched.get("trigger_condition", "")).lower()
|
|
439
|
+
enriched["confidence"] = 0.6 if (
|
|
440
|
+
"repro" in blob or "复现" in blob
|
|
441
|
+
) else 0.35
|
|
442
|
+
# 确认包缺 target_execution 时,只能从带哈希且已重算通过的观测工件派生。
|
|
443
|
+
# reference/channel 是 worker 自报字段,单独存在不能证明发生过目标执行。
|
|
444
|
+
confirmation = enriched.get("confirmation")
|
|
445
|
+
if (
|
|
446
|
+
isinstance(confirmation, dict)
|
|
447
|
+
and confirmation.get("state") == "confirmed"
|
|
448
|
+
and not isinstance(confirmation.get("target_execution"), dict)
|
|
449
|
+
):
|
|
450
|
+
import platform as _platform_mod
|
|
451
|
+
|
|
452
|
+
observations = [
|
|
453
|
+
dict(item) for item in confirmation.get("observations", [])
|
|
454
|
+
if isinstance(item, dict)
|
|
455
|
+
]
|
|
456
|
+
failure_refs = [
|
|
457
|
+
(str(item.get("channel") or "unknown"),
|
|
458
|
+
str(item.get("reference") or item.get("artifact_path") or ""))
|
|
459
|
+
for item in observations if item.get("outcome") == "failure"
|
|
460
|
+
]
|
|
461
|
+
failure_observations = [
|
|
462
|
+
item for item in observations if item.get("outcome") == "failure"
|
|
463
|
+
]
|
|
464
|
+
artifacts_bound = bool(failure_observations) and all(
|
|
465
|
+
isinstance(item.get("artifact_path"), str)
|
|
466
|
+
and bool(item.get("artifact_path"))
|
|
467
|
+
and isinstance(item.get("artifact_sha256"), str)
|
|
468
|
+
and bool(SHA256_RE.fullmatch(item["artifact_sha256"]))
|
|
469
|
+
for item in failure_observations
|
|
470
|
+
)
|
|
471
|
+
artifact_errors = (
|
|
472
|
+
[] if workspace_root is None or not artifacts_bound
|
|
473
|
+
else _verify_observation_artifacts(enriched, workspace_root)
|
|
474
|
+
)
|
|
475
|
+
if (
|
|
476
|
+
failure_refs
|
|
477
|
+
and all(reference for _c, reference in failure_refs)
|
|
478
|
+
and workspace_root is not None
|
|
479
|
+
and artifacts_bound
|
|
480
|
+
and not artifact_errors
|
|
481
|
+
):
|
|
482
|
+
channel_platform = {
|
|
483
|
+
"wsl2": "linux", "docker": "linux", "docker-desktop": "linux",
|
|
484
|
+
}
|
|
485
|
+
executed_platform = next(
|
|
486
|
+
(channel_platform.get(channel, _platform_mod.system().lower())
|
|
487
|
+
for channel, _ref in failure_refs),
|
|
488
|
+
_platform_mod.system().lower(),
|
|
489
|
+
)
|
|
490
|
+
confirmation["target_execution"] = {
|
|
491
|
+
"target_platform": executed_platform,
|
|
492
|
+
"executed_platform": executed_platform,
|
|
493
|
+
"target_fingerprint": (
|
|
494
|
+
_workspace_fingerprint(workspace_root)
|
|
495
|
+
if workspace_root is not None else ""
|
|
496
|
+
),
|
|
497
|
+
# PE-20261005-006:run_reference 必须引用运行身份使 sync 可判定
|
|
498
|
+
# "报告属于本次运行";优先候选 evidence 的 run_id(checkpoint 契约
|
|
499
|
+
# 要求其等于 state.run_id),旧数据回退 channel:reference。
|
|
500
|
+
"run_reference": _derive_run_reference(failure_refs, enriched),
|
|
501
|
+
"executed": True,
|
|
502
|
+
"simulated": False,
|
|
503
|
+
"outcome": "failure",
|
|
504
|
+
"errors": [],
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
evidence = enriched.get("evidence")
|
|
508
|
+
if not isinstance(evidence, list) or not evidence:
|
|
509
|
+
source = str(enriched.get("file") or "").strip()
|
|
510
|
+
if not source:
|
|
511
|
+
unit = str(enriched.get("unit") or "")
|
|
512
|
+
source = _unit_source_path(unit)
|
|
513
|
+
# ``id`` is an identity, never a source path. Keep an empty list when
|
|
514
|
+
# no source was supplied so the checkpoint boundary can reject it
|
|
515
|
+
# instead of manufacturing a path that only looks like evidence.
|
|
516
|
+
enriched["evidence"] = [{"path": source}] if source else []
|
|
517
|
+
return enriched
|
|
518
|
+
|
|
519
|
+
|
|
520
|
+
def _verify_observation_artifacts(finding: dict, workspace_root: Path) -> list[str]:
|
|
521
|
+
"""Reuse the confirmation verifier without making it a module import cycle."""
|
|
522
|
+
from core.ledger.finding_confirmation import verify_observation_artifacts
|
|
523
|
+
|
|
524
|
+
return verify_observation_artifacts(finding, workspace_root)
|
|
525
|
+
|
|
526
|
+
|
|
527
|
+
def _repair_evidence_item(item: object, root: Path) -> object:
|
|
528
|
+
"""单条 evidence 项的真相保持格式自纠;无有效改写时原样返回。
|
|
529
|
+
|
|
530
|
+
每个候选改写必须通过 ``agent_eval.evidence_item_valid``(与契约同一
|
|
531
|
+
判定)才被采纳:自纠只能把"真实证据的格式写错"修正为契约形状,
|
|
532
|
+
绝不构造、猜测或放宽任何事实。DEF-2。
|
|
533
|
+
"""
|
|
534
|
+
from core.agent import agent_eval
|
|
535
|
+
|
|
536
|
+
if not isinstance(item, dict):
|
|
537
|
+
# "path:line" 字符串(worker 指令明令禁止的写法):按最后一处冒号
|
|
538
|
+
# 拆分;仅当拆分结果落在真实 workspace 文件上才采纳。
|
|
539
|
+
if isinstance(item, str):
|
|
540
|
+
text = item.strip()
|
|
541
|
+
path_part, sep, line_part = text.rpartition(":")
|
|
542
|
+
if (
|
|
543
|
+
sep
|
|
544
|
+
and path_part.strip()
|
|
545
|
+
and line_part.isdigit()
|
|
546
|
+
and len(line_part) <= 7
|
|
547
|
+
):
|
|
548
|
+
candidate: dict[str, object] = {
|
|
549
|
+
"path": path_part.strip(),
|
|
550
|
+
"line": int(line_part),
|
|
551
|
+
}
|
|
552
|
+
candidate = _repair_evidence_item(candidate, root)
|
|
553
|
+
if isinstance(candidate, dict) and agent_eval.evidence_item_valid(
|
|
554
|
+
candidate, root,
|
|
555
|
+
):
|
|
556
|
+
return candidate
|
|
557
|
+
return item
|
|
558
|
+
repaired = dict(item)
|
|
559
|
+
path = repaired.get("path")
|
|
560
|
+
if not isinstance(path, str) or not path.strip():
|
|
561
|
+
# {"file": ...} 键名自纠:worker 指令契约键是 path。
|
|
562
|
+
file_value = repaired.pop("file", None)
|
|
563
|
+
if isinstance(file_value, str) and file_value.strip():
|
|
564
|
+
repaired["path"] = file_value
|
|
565
|
+
path = repaired["path"]
|
|
566
|
+
if isinstance(path, str):
|
|
567
|
+
raw = path.strip()
|
|
568
|
+
candidate_path = Path(raw)
|
|
569
|
+
if candidate_path.is_absolute():
|
|
570
|
+
# workspace 内绝对路径 → 相对化(仍须是真实文件)。
|
|
571
|
+
try:
|
|
572
|
+
rel = candidate_path.resolve(strict=True).relative_to(
|
|
573
|
+
root.resolve()
|
|
574
|
+
)
|
|
575
|
+
raw = rel.as_posix()
|
|
576
|
+
except (OSError, ValueError):
|
|
577
|
+
pass
|
|
578
|
+
elif "\\" in raw:
|
|
579
|
+
# Windows 分隔符笔误 → 正斜杠(POSIX 语义下的格式自纠)。
|
|
580
|
+
raw = raw.replace("\\", "/")
|
|
581
|
+
if (
|
|
582
|
+
raw != path
|
|
583
|
+
and agent_eval.evidence_item_valid({**repaired, "path": raw}, root)
|
|
584
|
+
):
|
|
585
|
+
repaired["path"] = raw
|
|
586
|
+
# line 数字字符串 → int(仍须通过行数校验;布尔/越界一律不自纠)。
|
|
587
|
+
line = repaired.get("line")
|
|
588
|
+
if isinstance(line, str) and line.strip().isdigit():
|
|
589
|
+
candidate = dict(repaired)
|
|
590
|
+
candidate["line"] = int(line.strip())
|
|
591
|
+
if agent_eval.evidence_item_valid(candidate, root):
|
|
592
|
+
repaired = candidate
|
|
593
|
+
if repaired != item and agent_eval.evidence_item_valid(repaired, root):
|
|
594
|
+
return repaired
|
|
595
|
+
return item
|
|
596
|
+
|
|
597
|
+
|
|
598
|
+
def _repair_finding_evidence(finding: dict, root: Path) -> dict | None:
|
|
599
|
+
"""对单个 finding 的 evidence 数组做有界格式自纠;无改写返回 None。"""
|
|
600
|
+
evidence = finding.get("evidence")
|
|
601
|
+
if not isinstance(evidence, list):
|
|
602
|
+
return None
|
|
603
|
+
changed = False
|
|
604
|
+
new_evidence: list[object] = []
|
|
605
|
+
for item in evidence:
|
|
606
|
+
repaired = _repair_evidence_item(item, root)
|
|
607
|
+
if repaired != item:
|
|
608
|
+
changed = True
|
|
609
|
+
new_evidence.append(repaired)
|
|
610
|
+
if not changed:
|
|
611
|
+
return None
|
|
612
|
+
repaired_finding = dict(finding)
|
|
613
|
+
repaired_finding["evidence"] = new_evidence
|
|
614
|
+
return repaired_finding
|
|
615
|
+
|
|
616
|
+
|
|
617
|
+
def finding_evidence_rejections(
|
|
618
|
+
findings: list[dict], workspace_root: Path,
|
|
619
|
+
) -> list[dict]:
|
|
620
|
+
"""结构化拒绝原因:每个证据无效 finding 的逐项违规(回注原料)。"""
|
|
621
|
+
from core.agent import agent_eval
|
|
622
|
+
|
|
623
|
+
records: list[dict] = []
|
|
624
|
+
for finding in findings:
|
|
625
|
+
violations = agent_eval.finding_evidence_violations(finding, workspace_root)
|
|
626
|
+
if violations:
|
|
627
|
+
records.append({
|
|
628
|
+
"finding_id": str(
|
|
629
|
+
finding.get("id") or finding.get("fingerprint") or "<unnamed>"
|
|
630
|
+
),
|
|
631
|
+
"violations": violations,
|
|
632
|
+
"correct_sample": agent_eval.CORRECT_EVIDENCE_SAMPLE,
|
|
633
|
+
})
|
|
634
|
+
return records
|
|
635
|
+
|
|
636
|
+
|
|
637
|
+
def selfcorrect_finding_evidence(
|
|
638
|
+
findings: list[dict],
|
|
639
|
+
workspace_root: Path,
|
|
640
|
+
*,
|
|
641
|
+
max_rounds: int = MAX_EVIDENCE_SELFCORRECTION_ROUNDS,
|
|
642
|
+
) -> tuple[list[dict], list[dict]]:
|
|
643
|
+
"""DEF-2 有界证据自纠回路(finalize 有界重提语义的管道内等效通道)。
|
|
644
|
+
|
|
645
|
+
每轮先把当前违规 finding 的结构化拒绝原因记录下来(回注原料),再做
|
|
646
|
+
真相保持的格式改写,随后按**原契约**全量复检;最多 ``max_rounds`` 轮
|
|
647
|
+
(默认 2,与首次校验合计 3 次评估机会)。同因第三次仍失败由调用方按
|
|
648
|
+
既有语义中止;轮次记录如实保留每一轮的拒绝原因供回写与诊断。
|
|
649
|
+
返回 ``(自纠后的 findings, 轮次记录列表)``。
|
|
650
|
+
"""
|
|
651
|
+
from core.agent import agent_eval
|
|
652
|
+
|
|
653
|
+
rounds: list[dict] = []
|
|
654
|
+
current = findings
|
|
655
|
+
for round_no in range(1, max_rounds + 1):
|
|
656
|
+
rejection_records = finding_evidence_rejections(current, workspace_root)
|
|
657
|
+
if not rejection_records:
|
|
658
|
+
break
|
|
659
|
+
rejected_ids = {record["finding_id"] for record in rejection_records}
|
|
660
|
+
repaired: list[dict] = []
|
|
661
|
+
repaired_ids: list[str] = []
|
|
662
|
+
for finding in current:
|
|
663
|
+
fid = str(
|
|
664
|
+
finding.get("id") or finding.get("fingerprint") or "<unnamed>"
|
|
665
|
+
)
|
|
666
|
+
new_finding = (
|
|
667
|
+
_repair_finding_evidence(finding, workspace_root)
|
|
668
|
+
if fid in rejected_ids
|
|
669
|
+
else None
|
|
670
|
+
)
|
|
671
|
+
if new_finding is not None:
|
|
672
|
+
repaired_ids.append(fid)
|
|
673
|
+
repaired.append(new_finding)
|
|
674
|
+
else:
|
|
675
|
+
repaired.append(finding)
|
|
676
|
+
still_invalid = agent_eval.invalid_evidence_ids(repaired, workspace_root)
|
|
677
|
+
rounds.append({
|
|
678
|
+
"round": round_no,
|
|
679
|
+
"rejections": rejection_records,
|
|
680
|
+
"repaired_ids": repaired_ids,
|
|
681
|
+
"invalid_after": list(still_invalid),
|
|
682
|
+
})
|
|
683
|
+
current = repaired
|
|
684
|
+
if not still_invalid:
|
|
685
|
+
break
|
|
686
|
+
return current, rounds
|
|
687
|
+
|
|
688
|
+
|
|
689
|
+
def _evidence_retry_prompt(
|
|
690
|
+
rejection_records: list[dict],
|
|
691
|
+
correction_rounds: list[dict],
|
|
692
|
+
) -> str:
|
|
693
|
+
"""把结构化拒绝原因渲染成可回注 worker 重试提示词的自纠文本(有界)。"""
|
|
694
|
+
from core.agent import agent_eval
|
|
695
|
+
|
|
696
|
+
lines = [
|
|
697
|
+
(
|
|
698
|
+
f"[evidence 自纠回路] 摄入侧已有界自纠 {len(correction_rounds)} 轮"
|
|
699
|
+
"仍未通过证据契约,本次 checkpoint 按既有语义拒绝:"
|
|
700
|
+
),
|
|
701
|
+
]
|
|
702
|
+
for record in rejection_records[:8]:
|
|
703
|
+
violations = record.get("violations") or []
|
|
704
|
+
lines.append(
|
|
705
|
+
f"- finding {record.get('finding_id')}: "
|
|
706
|
+
+ ";".join(str(v) for v in violations[:4])
|
|
707
|
+
)
|
|
708
|
+
lines.append(
|
|
709
|
+
"正确格式: " + agent_eval.CORRECT_EVIDENCE_SAMPLE
|
|
710
|
+
+ "(path=workspace 内真实文件的相对路径;line=正整数行号且 ≤ 文件行数);"
|
|
711
|
+
"请修正 evidence 后重新提交 checkpoint。"
|
|
712
|
+
)
|
|
713
|
+
text = "\n".join(lines)
|
|
714
|
+
if len(text) > _EVIDENCE_FEEDBACK_MAX_CHARS:
|
|
715
|
+
text = text[:_EVIDENCE_FEEDBACK_MAX_CHARS] + "…(截断)"
|
|
716
|
+
return text
|
|
717
|
+
|
|
718
|
+
|
|
719
|
+
def normalize_findings(
|
|
720
|
+
findings: Iterable[Mapping[str, object]] | None,
|
|
721
|
+
workspace_root: Path | None = None,
|
|
722
|
+
) -> list[dict[str, object]]:
|
|
723
|
+
input_findings: list[Mapping[str, object]] = []
|
|
724
|
+
if findings is not None:
|
|
725
|
+
if isinstance(findings, (str, bytes)):
|
|
726
|
+
raise InvalidCheckpoint("findings 必须是数组")
|
|
727
|
+
try:
|
|
728
|
+
iterator = iter(findings)
|
|
729
|
+
except TypeError as exc:
|
|
730
|
+
raise InvalidCheckpoint("findings 必须是可迭代数组") from exc
|
|
731
|
+
# Materialize exactly once. This preserves generator payloads and
|
|
732
|
+
# stops an unbounded iterable at the protocol limit.
|
|
733
|
+
for item in iterator:
|
|
734
|
+
if len(input_findings) >= MAX_FINDINGS_PER_CHECKPOINT:
|
|
735
|
+
raise InvalidCheckpoint(
|
|
736
|
+
f"findings 条数过多(>{MAX_FINDINGS_PER_CHECKPOINT})"
|
|
737
|
+
)
|
|
738
|
+
input_findings.append(item)
|
|
739
|
+
# Depth/keys guard after bounded materialization (fail-closed).
|
|
740
|
+
check_depth_and_keys(input_findings)
|
|
741
|
+
normalized: dict[str, dict[str, object]] = {}
|
|
742
|
+
for finding in input_findings:
|
|
743
|
+
if not isinstance(finding, Mapping):
|
|
744
|
+
raise InvalidCheckpoint("findings 成员必须是对象")
|
|
745
|
+
check_depth_and_keys(finding)
|
|
746
|
+
key = finding_key(finding)
|
|
747
|
+
if len(key) > MAX_FINDING_FINGERPRINT_LENGTH:
|
|
748
|
+
raise InvalidCheckpoint(
|
|
749
|
+
f"fingerprint 过长(>{MAX_FINDING_FINGERPRINT_LENGTH})"
|
|
750
|
+
)
|
|
751
|
+
for fname, fval in finding.items():
|
|
752
|
+
if isinstance(fval, str) and len(fval) > MAX_FINDING_FIELD_LENGTH:
|
|
753
|
+
raise InvalidCheckpoint(
|
|
754
|
+
f"findings[{fname}] 过长(>{MAX_FINDING_FIELD_LENGTH})"
|
|
755
|
+
)
|
|
756
|
+
if isinstance(fval, str) and "\x00" in fval:
|
|
757
|
+
raise InvalidCheckpoint("findings 不得包含空字节")
|
|
758
|
+
# C11(第三轮审计):DOC-230 §3.8 第 2 项要求"写入期即校验",但此前
|
|
759
|
+
# `severity` 的 enum 只落在 MCP schema 层——核心摄入路径(含引擎 CLI
|
|
760
|
+
# `supervisor checkpoint`)可写入任意字符串(实测 `severity='urgent'`
|
|
761
|
+
# 落盘成功),把失败推迟到确认门,正是 §3.8 要消除的形态。此处把校验
|
|
762
|
+
# 下沉到核心边界:归一(p0-p3 别名)后必须命中唯一词表,否则拒绝。
|
|
763
|
+
# 注意:必须放在上面的字段循环**之后**——首次插入时误置于循环中间,
|
|
764
|
+
# 把 NUL 字节检查吞进了本分支(已由 test_null_byte_in_a_field_is_rejected
|
|
765
|
+
# 捕获并修复)。
|
|
766
|
+
declared = finding.get("severity")
|
|
767
|
+
if declared is not None:
|
|
768
|
+
normalized_severity = normalize_finding_severity(declared)
|
|
769
|
+
if normalized_severity not in finding_severity_levels():
|
|
770
|
+
raise InvalidCheckpoint(
|
|
771
|
+
f"findings[{key}] severity 必须属于词表 "
|
|
772
|
+
f"{list(finding_severity_levels())},收到: {declared!r}"
|
|
773
|
+
)
|
|
774
|
+
item = copy.deepcopy(dict(finding))
|
|
775
|
+
if not (isinstance(item.get("fingerprint"), str) and item["fingerprint"].strip()):
|
|
776
|
+
item["fingerprint"] = key
|
|
777
|
+
item.setdefault("reproducible", False)
|
|
778
|
+
item.setdefault("id", key)
|
|
779
|
+
# 结构化复现三件套透传:非空字符串才保留(旧候选无 poc 字段时行为不变),
|
|
780
|
+
# 使其随 checkpoint 完整落到 supervisor state 的候选上。
|
|
781
|
+
_preserve_poc_carry_fields(item)
|
|
782
|
+
if workspace_root is not None:
|
|
783
|
+
item = enrich_gate_finding(item, workspace_root)
|
|
784
|
+
if key not in normalized:
|
|
785
|
+
normalized[key] = item
|
|
786
|
+
if len(normalized) > MAX_FINDINGS_PER_CHECKPOINT:
|
|
787
|
+
raise InvalidCheckpoint(
|
|
788
|
+
f"findings 去重后仍超过 {MAX_FINDINGS_PER_CHECKPOINT} 条上限"
|
|
789
|
+
)
|
|
790
|
+
result = [normalized[key] for key in sorted(normalized)]
|
|
791
|
+
if workspace_root is not None and result:
|
|
792
|
+
root_path = Path(workspace_root)
|
|
793
|
+
try:
|
|
794
|
+
from core.agent import agent_eval
|
|
795
|
+
|
|
796
|
+
invalid = agent_eval.invalid_evidence_ids(result, root_path)
|
|
797
|
+
except (ImportError, OSError, TypeError, ValueError) as exc:
|
|
798
|
+
raise InvalidCheckpoint(f"finding evidence 校验失败: {exc}") from exc
|
|
799
|
+
if invalid:
|
|
800
|
+
# DEF-2:证据校验拒绝不再直接中止 attempt——先走有界自纠回路
|
|
801
|
+
# (≤MAX_EVIDENCE_SELFCORRECTION_ROUNDS 轮)。每轮以结构化拒绝
|
|
802
|
+
# 原因为回注原料做真相保持的格式改写,改写后仍按原契约全量复检;
|
|
803
|
+
# 同因第三轮(首次校验 + 2 轮自纠)仍失败才按既有语义中止,
|
|
804
|
+
# 并把结构化拒绝原因 + 正确格式样例随拒绝带回(evidence_feedback),
|
|
805
|
+
# 使宿主/模型在下一通道(MCP 错误回包 / failure 回写 / finalize
|
|
806
|
+
# CLI)能拿到可执行的自纠指令。
|
|
807
|
+
result, correction_rounds = selfcorrect_finding_evidence(
|
|
808
|
+
result, root_path,
|
|
809
|
+
)
|
|
810
|
+
try:
|
|
811
|
+
invalid = agent_eval.invalid_evidence_ids(result, root_path)
|
|
812
|
+
except (ImportError, OSError, TypeError, ValueError) as exc:
|
|
813
|
+
raise InvalidCheckpoint(f"finding evidence 校验失败: {exc}") from exc
|
|
814
|
+
if invalid:
|
|
815
|
+
rejection_records = finding_evidence_rejections(result, root_path)
|
|
816
|
+
feedback = {
|
|
817
|
+
"schema_version": 1,
|
|
818
|
+
"contract": (
|
|
819
|
+
"finding.evidence 必须是对象数组:path 为 workspace 内"
|
|
820
|
+
"真实文件的相对路径,line 为正整数且不超过文件行数"
|
|
821
|
+
),
|
|
822
|
+
"correct_sample": agent_eval.CORRECT_EVIDENCE_SAMPLE,
|
|
823
|
+
"self_correction_rounds": len(correction_rounds),
|
|
824
|
+
"findings": rejection_records,
|
|
825
|
+
"retry_prompt": _evidence_retry_prompt(
|
|
826
|
+
rejection_records, correction_rounds,
|
|
827
|
+
),
|
|
828
|
+
}
|
|
829
|
+
exc = InvalidCheckpoint(
|
|
830
|
+
"finding 缺真实 workspace evidence: " + ", ".join(invalid)
|
|
831
|
+
+ ";" + feedback["retry_prompt"]
|
|
832
|
+
)
|
|
833
|
+
exc.evidence_feedback = feedback
|
|
834
|
+
raise exc
|
|
835
|
+
return result
|
|
836
|
+
|
|
837
|
+
|
|
838
|
+
def attach_evidence_receipts(
|
|
839
|
+
findings: list[dict[str, object]],
|
|
840
|
+
evidence: Mapping[str, Mapping[str, object]] | None,
|
|
841
|
+
) -> None:
|
|
842
|
+
"""F1'(Round7 审计条件一):checkpoint 摄入侧 receipt 关联管道。
|
|
843
|
+
|
|
844
|
+
worker findings schema 不携带 execution_receipt;同一 checkpoint 的
|
|
845
|
+
per-unit evidence 项携带(且已经 :func:`validate_execution_receipt`
|
|
846
|
+
与 Supervisor 持有的 claim/execution 记录绑定)。这里在摄入时把
|
|
847
|
+
finding 能关联到的 receipt 附到 finding 上(``evidence_receipt``),
|
|
848
|
+
使结算自动裁决器可以"查找匹配"引擎台账而不是文本信任 worker 自述:
|
|
849
|
+
|
|
850
|
+
- 关联键:finding 的 ``case_id`` 或 ``unit`` 精确等于某个带 receipt 的
|
|
851
|
+
evidence unit(worker runtime 约定 case_id 即 coverage unit id);
|
|
852
|
+
- 附着内容是已归一化 receipt 的拷贝(execution_id/lease_id/worker_id/
|
|
853
|
+
artifact_path/artifact_sha256/command/exit_code/status);
|
|
854
|
+
- 关联不上的 finding 保持原样(不报错、不猜测)。
|
|
855
|
+
"""
|
|
856
|
+
if not findings or not isinstance(evidence, Mapping) or not evidence:
|
|
857
|
+
return
|
|
858
|
+
# F-RSI-20261110-044:关联键逐条 os.path.normpath 归一——coverage unit id
|
|
859
|
+
# 是路径形态(coverage_unit_id),worker 回传的 evidence 键/finding 的
|
|
860
|
+
# case_id 可能携带 "./x.py"/"sub/../x.py" 别名变体;不归一 = receipt
|
|
861
|
+
# **静默不附着**(关联不上保持原样),结算裁决器失去引擎台账可查。
|
|
862
|
+
# 与 F-019/F-028/F-029 同根因:路径比较前必须归一。非路径键
|
|
863
|
+
# (业务单元等)normpath 无斜杠时原样保留。
|
|
864
|
+
def _norm_unit_key(value: object) -> str:
|
|
865
|
+
return os.path.normpath(str(value).strip())
|
|
866
|
+
|
|
867
|
+
receipt_by_unit: dict[str, Mapping[str, object]] = {}
|
|
868
|
+
for unit, item in evidence.items():
|
|
869
|
+
if not isinstance(item, Mapping):
|
|
870
|
+
continue
|
|
871
|
+
receipt = item.get("execution_receipt")
|
|
872
|
+
if isinstance(receipt, Mapping) and receipt:
|
|
873
|
+
receipt_by_unit[_norm_unit_key(unit)] = receipt
|
|
874
|
+
if not receipt_by_unit:
|
|
875
|
+
return
|
|
876
|
+
for finding in findings:
|
|
877
|
+
if not isinstance(finding, dict):
|
|
878
|
+
continue
|
|
879
|
+
if isinstance(finding.get("evidence_receipt"), Mapping) and finding["evidence_receipt"]:
|
|
880
|
+
continue
|
|
881
|
+
for key in ("case_id", "unit"):
|
|
882
|
+
unit_key = str(finding.get(key) or "").strip()
|
|
883
|
+
normalized = _norm_unit_key(unit_key)
|
|
884
|
+
if normalized and normalized in receipt_by_unit:
|
|
885
|
+
finding["evidence_receipt"] = dict(receipt_by_unit[normalized])
|
|
886
|
+
break
|
|
887
|
+
|
|
888
|
+
|
|
889
|
+
def normalize_notes(notes: Mapping[str, str] | None) -> dict[str, str]:
|
|
890
|
+
"""校验断点手记:unit_id → 非空文本(≤2000 字符)。"""
|
|
891
|
+
if notes is None:
|
|
892
|
+
return {}
|
|
893
|
+
if not isinstance(notes, Mapping):
|
|
894
|
+
raise InvalidCheckpoint("notes 必须是 unit_id -> 文本 对象")
|
|
895
|
+
check_depth_and_keys(notes)
|
|
896
|
+
if len(notes) > MAX_COVERAGE_PER_CHECKPOINT:
|
|
897
|
+
raise InvalidCheckpoint(
|
|
898
|
+
f"notes 单元过多(>{MAX_COVERAGE_PER_CHECKPOINT});超出单次提交上限"
|
|
899
|
+
)
|
|
900
|
+
result: dict[str, str] = {}
|
|
901
|
+
for unit_id, note in notes.items():
|
|
902
|
+
if not isinstance(unit_id, str) or not unit_id.strip():
|
|
903
|
+
raise InvalidCheckpoint("notes 的 unit_id 必须是非空字符串")
|
|
904
|
+
if len(unit_id.strip()) > 1024:
|
|
905
|
+
raise InvalidCheckpoint(f"notes unit_id 过长(>1024): {unit_id[:64]}")
|
|
906
|
+
if "\x00" in unit_id:
|
|
907
|
+
raise InvalidCheckpoint("notes unit_id 不得包含空字节")
|
|
908
|
+
if not isinstance(note, str) or not note.strip():
|
|
909
|
+
raise InvalidCheckpoint(f"notes[{unit_id}] 必须是非空文本")
|
|
910
|
+
if len(note) > MAX_UNIT_NOTE_LENGTH:
|
|
911
|
+
raise InvalidCheckpoint(
|
|
912
|
+
f"notes[{unit_id}] 超过 {MAX_UNIT_NOTE_LENGTH} 字符上限"
|
|
913
|
+
)
|
|
914
|
+
if "\x00" in note:
|
|
915
|
+
raise InvalidCheckpoint("notes 不得包含空字节")
|
|
916
|
+
result[unit_id] = note
|
|
917
|
+
return result
|
|
918
|
+
|
|
919
|
+
|
|
920
|
+
def normalize_signatures(signatures: Iterable[str] | None) -> list[str]:
|
|
921
|
+
"""校验并去重错误签名;None/空列表返回空。"""
|
|
922
|
+
if signatures is None:
|
|
923
|
+
return []
|
|
924
|
+
if isinstance(signatures, (str, bytes)) or not isinstance(signatures, Iterable):
|
|
925
|
+
raise InvalidCheckpoint("signatures 必须是字符串数组")
|
|
926
|
+
result: list[str] = []
|
|
927
|
+
for signature in signatures:
|
|
928
|
+
if not isinstance(signature, str) or not signature.strip():
|
|
929
|
+
raise InvalidCheckpoint("signatures 成员必须是非空字符串")
|
|
930
|
+
value = signature.strip()
|
|
931
|
+
if len(value) > MAX_SIGNATURE_LENGTH:
|
|
932
|
+
raise InvalidCheckpoint(
|
|
933
|
+
f"签名超过 {MAX_SIGNATURE_LENGTH} 字符上限;请用错误摘要而非完整日志"
|
|
934
|
+
)
|
|
935
|
+
if "\x00" in value:
|
|
936
|
+
raise InvalidCheckpoint("签名不得包含空字节")
|
|
937
|
+
if value not in result:
|
|
938
|
+
result.append(value)
|
|
939
|
+
if len(result) > MAX_SIGNATURES_PER_CHECKPOINT:
|
|
940
|
+
raise InvalidCheckpoint(
|
|
941
|
+
f"单次 checkpoint 签名不得超过 {MAX_SIGNATURES_PER_CHECKPOINT} 条"
|
|
942
|
+
)
|
|
943
|
+
return result
|
|
944
|
+
|
|
945
|
+
|
|
946
|
+
def confirmation_gate(findings: Sequence[Mapping[str, object]]) -> dict[str, object]:
|
|
947
|
+
"""Evaluate the shared Finding confirmation protocol without waiting."""
|
|
948
|
+
if not findings:
|
|
949
|
+
return {
|
|
950
|
+
"schema_version": 1, "total": 0, "confirmed": 0,
|
|
951
|
+
"rejected": 0, "pending": 0, "ready": True,
|
|
952
|
+
}
|
|
953
|
+
try:
|
|
954
|
+
from core.agent import agent_eval
|
|
955
|
+
from core.ledger import finding_confirmation
|
|
956
|
+
|
|
957
|
+
total_toks = sum(
|
|
958
|
+
int(item.get("token_count", 0)) for item in findings
|
|
959
|
+
if isinstance(item, dict) and isinstance(item.get("token_count"), (int, float))
|
|
960
|
+
)
|
|
961
|
+
payload = {
|
|
962
|
+
"schema_version": 1, "duration_seconds": 0,
|
|
963
|
+
"token_count": total_toks, "findings": [dict(item) for item in findings],
|
|
964
|
+
}
|
|
965
|
+
return finding_confirmation.gate(payload)
|
|
966
|
+
except Exception as exc:
|
|
967
|
+
# BX-ENGINE-18 / A6: an aggregation failure does not prove that there
|
|
968
|
+
# are zero findings. Keep the shape stable for consumers, but mark every
|
|
969
|
+
# unavailable numeric metric as unknown instead of fabricating a count.
|
|
970
|
+
return {
|
|
971
|
+
"schema_version": 1, "total": None,
|
|
972
|
+
"confirmed": None, "rejected": None, "pending": None,
|
|
973
|
+
"ready": False, "degraded": True,
|
|
974
|
+
"error": f"confirmation protocol invalid: {exc}",
|
|
975
|
+
"states": {},
|
|
976
|
+
# A6:降级时不得伪造数值(详见 finding_confirmation.gate 同处说明)。
|
|
977
|
+
"assurance": {
|
|
978
|
+
"average_score": None, "minimum_score": None,
|
|
979
|
+
"fully_confirmed_rate": None, "blocking_reasons": {},
|
|
980
|
+
},
|
|
981
|
+
"findings": [],
|
|
982
|
+
}
|
|
983
|
+
|
|
984
|
+
|
|
985
|
+
def refresh_confirmation_gate(state: RunState) -> dict[str, object]:
|
|
986
|
+
state.confirmation_gate = confirmation_gate(state.findings)
|
|
987
|
+
return state.confirmation_gate
|
|
988
|
+
|
|
989
|
+
|
|
990
|
+
def normalize_coverage(
|
|
991
|
+
coverage: Mapping[str, str] | None,
|
|
992
|
+
) -> dict[str, str]:
|
|
993
|
+
if coverage is None:
|
|
994
|
+
return {}
|
|
995
|
+
if not isinstance(coverage, Mapping):
|
|
996
|
+
raise InvalidCheckpoint("coverage 必须是 unit -> status 对象")
|
|
997
|
+
check_depth_and_keys(coverage)
|
|
998
|
+
if len(coverage) > MAX_COVERAGE_PER_CHECKPOINT:
|
|
999
|
+
raise InvalidCheckpoint(
|
|
1000
|
+
f"coverage 单元过多(>{MAX_COVERAGE_PER_CHECKPOINT});超出单次提交上限"
|
|
1001
|
+
)
|
|
1002
|
+
normalized: dict[str, str] = {}
|
|
1003
|
+
for unit, status in coverage.items():
|
|
1004
|
+
if not isinstance(unit, str) or not unit.strip():
|
|
1005
|
+
raise InvalidCheckpoint("coverage unit 不能为空")
|
|
1006
|
+
if len(unit.strip()) > 1024:
|
|
1007
|
+
raise InvalidCheckpoint(f"coverage unit 过长(>1024): {unit[:64]}")
|
|
1008
|
+
if "\x00" in unit:
|
|
1009
|
+
raise InvalidCheckpoint("coverage unit 不得包含空字节")
|
|
1010
|
+
if status not in VALID_COVERAGE_STATES:
|
|
1011
|
+
raise InvalidCheckpoint(
|
|
1012
|
+
f"coverage[{unit}] 状态无效: {status}; "
|
|
1013
|
+
f"允许 {sorted(VALID_COVERAGE_STATES)}"
|
|
1014
|
+
)
|
|
1015
|
+
normalized[unit.strip()] = status
|
|
1016
|
+
return normalized
|
|
1017
|
+
|
|
1018
|
+
|
|
1019
|
+
def session_coverage_complete(
|
|
1020
|
+
state: RunState,
|
|
1021
|
+
ledger_path: Path | None,
|
|
1022
|
+
) -> bool:
|
|
1023
|
+
"""Check the session ledger without mutating Supervisor state (P2-1)."""
|
|
1024
|
+
if ledger_path is None or not ledger_path.is_file():
|
|
1025
|
+
return False
|
|
1026
|
+
try:
|
|
1027
|
+
data = json.loads(ledger_path.read_text(encoding="utf-8"))
|
|
1028
|
+
records = data.get("records", [])
|
|
1029
|
+
covered_units = {
|
|
1030
|
+
record.get("unit_id")
|
|
1031
|
+
for record in records
|
|
1032
|
+
if isinstance(record, dict) and record.get("unit_id")
|
|
1033
|
+
}
|
|
1034
|
+
if not state.coverage:
|
|
1035
|
+
return False
|
|
1036
|
+
return all(
|
|
1037
|
+
status in TERMINAL_COVERED or unit in covered_units
|
|
1038
|
+
for unit, status in state.coverage.items()
|
|
1039
|
+
)
|
|
1040
|
+
except Exception:
|
|
1041
|
+
return False
|
|
1042
|
+
|
|
1043
|
+
|
|
1044
|
+
def resolve_session_coverage_ledger_path(
|
|
1045
|
+
workspace_root: Path,
|
|
1046
|
+
configured_path: str | os.PathLike[str] | None = None,
|
|
1047
|
+
) -> Path | None:
|
|
1048
|
+
"""Resolve the Session coverage ledger without owning Supervisor state."""
|
|
1049
|
+
if configured_path is not None:
|
|
1050
|
+
return Path(configured_path)
|
|
1051
|
+
try:
|
|
1052
|
+
import core.bugx_paths as bugx_paths
|
|
1053
|
+
|
|
1054
|
+
scope = bugx_paths.require(workspace_root)
|
|
1055
|
+
return scope.polling_root / "coverage-ledger.json"
|
|
1056
|
+
except Exception:
|
|
1057
|
+
pollings_dir = workspace_root / ".bugx" / "pollings"
|
|
1058
|
+
if not pollings_dir.is_dir():
|
|
1059
|
+
return None
|
|
1060
|
+
candidates = list(pollings_dir.glob("*/coverage-ledger.json"))
|
|
1061
|
+
if not candidates:
|
|
1062
|
+
return None
|
|
1063
|
+
candidates.sort(key=lambda path: path.stat().st_mtime, reverse=True)
|
|
1064
|
+
return candidates[0]
|
|
1065
|
+
|
|
1066
|
+
|
|
1067
|
+
def normalize_evidence(
|
|
1068
|
+
evidence: Mapping[str, Mapping[str, object]] | None,
|
|
1069
|
+
) -> dict[str, dict[str, object]]:
|
|
1070
|
+
if evidence is None:
|
|
1071
|
+
return {}
|
|
1072
|
+
if not isinstance(evidence, Mapping):
|
|
1073
|
+
raise InvalidCheckpoint("evidence 必须是 unit -> object 对象")
|
|
1074
|
+
check_depth_and_keys(evidence)
|
|
1075
|
+
if len(evidence) > MAX_EVIDENCE_PER_CHECKPOINT:
|
|
1076
|
+
raise InvalidCheckpoint(
|
|
1077
|
+
f"evidence 单元过多(>{MAX_EVIDENCE_PER_CHECKPOINT});超出单次提交上限"
|
|
1078
|
+
)
|
|
1079
|
+
normalized: dict[str, dict[str, object]] = {}
|
|
1080
|
+
required = {
|
|
1081
|
+
"command", "exit_code", "artifact_path", "artifact_sha256",
|
|
1082
|
+
"target_fingerprint", "timestamp", "worker_id", "run_id",
|
|
1083
|
+
"round_no", "lease_id", "status",
|
|
1084
|
+
}
|
|
1085
|
+
for unit, item in evidence.items():
|
|
1086
|
+
if not isinstance(unit, str) or not unit.strip():
|
|
1087
|
+
raise InvalidCheckpoint("evidence unit 不能为空")
|
|
1088
|
+
if len(unit.strip()) > 1024:
|
|
1089
|
+
raise InvalidCheckpoint(f"evidence unit 过长(>1024): {unit[:64]}")
|
|
1090
|
+
if "\x00" in unit:
|
|
1091
|
+
raise InvalidCheckpoint("evidence unit 不得包含空字节")
|
|
1092
|
+
if not isinstance(item, Mapping):
|
|
1093
|
+
raise InvalidCheckpoint(f"evidence[{unit}] 必须是对象")
|
|
1094
|
+
check_depth_and_keys(item)
|
|
1095
|
+
missing = required - set(item)
|
|
1096
|
+
if missing:
|
|
1097
|
+
raise InvalidCheckpoint(
|
|
1098
|
+
f"evidence[{unit}] 缺字段: {sorted(missing)}"
|
|
1099
|
+
)
|
|
1100
|
+
command = item["command"]
|
|
1101
|
+
exit_code = item["exit_code"]
|
|
1102
|
+
artifact_path = item["artifact_path"]
|
|
1103
|
+
digest = item["artifact_sha256"]
|
|
1104
|
+
target = item["target_fingerprint"]
|
|
1105
|
+
timestamp = item["timestamp"]
|
|
1106
|
+
worker_id = item["worker_id"]
|
|
1107
|
+
run_id = item["run_id"]
|
|
1108
|
+
round_no = item["round_no"]
|
|
1109
|
+
lease_id = item["lease_id"]
|
|
1110
|
+
status = item["status"]
|
|
1111
|
+
if not isinstance(command, str) or not command.strip():
|
|
1112
|
+
raise InvalidCheckpoint(f"evidence[{unit}].command 无效")
|
|
1113
|
+
if len(command) > MAX_COMMAND_LENGTH:
|
|
1114
|
+
raise InvalidCheckpoint(
|
|
1115
|
+
f"evidence[{unit}].command 过长(>{MAX_COMMAND_LENGTH})"
|
|
1116
|
+
)
|
|
1117
|
+
if "\x00" in command:
|
|
1118
|
+
raise InvalidCheckpoint(f"evidence[{unit}].command 不得包含空字节")
|
|
1119
|
+
if not isinstance(artifact_path, str) or not artifact_path.strip():
|
|
1120
|
+
raise InvalidCheckpoint(f"evidence[{unit}].artifact_path 无效")
|
|
1121
|
+
if len(artifact_path) > MAX_ARTIFACT_PATH_LENGTH:
|
|
1122
|
+
raise InvalidCheckpoint(
|
|
1123
|
+
f"evidence[{unit}].artifact_path 过长(>{MAX_ARTIFACT_PATH_LENGTH})"
|
|
1124
|
+
)
|
|
1125
|
+
if "\x00" in artifact_path:
|
|
1126
|
+
raise InvalidCheckpoint(f"evidence[{unit}].artifact_path 不得包含空字节")
|
|
1127
|
+
if isinstance(exit_code, bool) or not isinstance(exit_code, int):
|
|
1128
|
+
raise InvalidCheckpoint(f"evidence[{unit}].exit_code 无效")
|
|
1129
|
+
if not isinstance(digest, str) or not SHA256_RE.fullmatch(digest):
|
|
1130
|
+
raise InvalidCheckpoint(f"evidence[{unit}].artifact_sha256 无效")
|
|
1131
|
+
if not isinstance(target, str) or not target.strip():
|
|
1132
|
+
raise InvalidCheckpoint(
|
|
1133
|
+
f"evidence[{unit}].target_fingerprint 无效"
|
|
1134
|
+
)
|
|
1135
|
+
if isinstance(timestamp, bool) or not isinstance(timestamp, (int, float)) \
|
|
1136
|
+
or not math.isfinite(float(timestamp)) or timestamp <= 0:
|
|
1137
|
+
raise InvalidCheckpoint(f"evidence[{unit}].timestamp 无效")
|
|
1138
|
+
timestamp = float(timestamp)
|
|
1139
|
+
if timestamp >= 1_000_000_000_000:
|
|
1140
|
+
timestamp /= 1000
|
|
1141
|
+
try:
|
|
1142
|
+
datetime.fromtimestamp(timestamp, tz=timezone.utc)
|
|
1143
|
+
except (OverflowError, OSError, ValueError) as exc:
|
|
1144
|
+
raise InvalidCheckpoint(
|
|
1145
|
+
f"evidence[{unit}].timestamp 超出可表示范围"
|
|
1146
|
+
) from exc
|
|
1147
|
+
if not isinstance(worker_id, str) or not worker_id.strip():
|
|
1148
|
+
raise InvalidCheckpoint(f"evidence[{unit}].worker_id 无效")
|
|
1149
|
+
if not isinstance(run_id, str) or not run_id.strip():
|
|
1150
|
+
raise InvalidCheckpoint(f"evidence[{unit}].run_id 无效")
|
|
1151
|
+
if isinstance(round_no, bool) or not isinstance(round_no, int) or round_no < 1:
|
|
1152
|
+
raise InvalidCheckpoint(f"evidence[{unit}].round_no 无效")
|
|
1153
|
+
if not isinstance(lease_id, str) or not lease_id.strip():
|
|
1154
|
+
raise InvalidCheckpoint(f"evidence[{unit}].lease_id 无效")
|
|
1155
|
+
if status not in VALID_EVIDENCE_STATES:
|
|
1156
|
+
raise InvalidCheckpoint(
|
|
1157
|
+
f"evidence[{unit}].status 无效;允许 {sorted(VALID_EVIDENCE_STATES)}"
|
|
1158
|
+
)
|
|
1159
|
+
if status == "passed" and exit_code != 0:
|
|
1160
|
+
raise InvalidCheckpoint(f"evidence[{unit}] passed 时 exit_code 必须为 0")
|
|
1161
|
+
normalized_item = copy.deepcopy(dict(item))
|
|
1162
|
+
normalized_item["timestamp"] = timestamp
|
|
1163
|
+
if "execution_receipt" in item:
|
|
1164
|
+
normalized_item["execution_receipt"] = normalize_execution_receipt(
|
|
1165
|
+
item["execution_receipt"], unit.strip(),
|
|
1166
|
+
)
|
|
1167
|
+
normalized[unit.strip()] = normalized_item
|
|
1168
|
+
return normalized
|
|
1169
|
+
|
|
1170
|
+
|
|
1171
|
+
def assert_artifact_not_before_claim(
|
|
1172
|
+
*,
|
|
1173
|
+
artifact: Path,
|
|
1174
|
+
claimed_at: float,
|
|
1175
|
+
unit: str,
|
|
1176
|
+
channel: str,
|
|
1177
|
+
grace_seconds: float = 5.0,
|
|
1178
|
+
) -> None:
|
|
1179
|
+
"""拒绝早于本 claim 领取时刻写入的工件(跨纪元证据)。
|
|
1180
|
+
|
|
1181
|
+
worker 通道与 salvage 通道共用本判据,落实 `L3-C2` 要求的「代交通道与
|
|
1182
|
+
worker 通道同强度」:`artifact_root` 可被 supersede/recover 继承,两通道
|
|
1183
|
+
都只信任本 claim 领取时刻之后写入的工件。
|
|
1184
|
+
|
|
1185
|
+
边界:``mtime + grace_seconds < claimed_at`` 拒绝;
|
|
1186
|
+
``mtime + grace_seconds == claimed_at`` 放行(与原 salvage 内联实现一致)。
|
|
1187
|
+
|
|
1188
|
+
残留弱点(本轮不解决):``st_mtime`` 可被 ``os.utime`` 任意改写,本函数
|
|
1189
|
+
只消除两条通道的不对称,**不提供防伪造能力**;不可伪造锚(内容寻址快照)
|
|
1190
|
+
由缺陷 B6 在后续 Wave 承接。
|
|
1191
|
+
"""
|
|
1192
|
+
try:
|
|
1193
|
+
mtime = artifact.stat().st_mtime
|
|
1194
|
+
except OSError as exc:
|
|
1195
|
+
raise InvalidCheckpoint(
|
|
1196
|
+
f"{channel} evidence 工件不可读: {unit}: {artifact}: {exc}"
|
|
1197
|
+
) from exc
|
|
1198
|
+
if mtime + grace_seconds < claimed_at:
|
|
1199
|
+
raise InvalidCheckpoint(
|
|
1200
|
+
f"{channel} evidence 工件早于本 claim 领取时刻(跨纪元证据): "
|
|
1201
|
+
f"{unit}: {artifact}"
|
|
1202
|
+
)
|
|
1203
|
+
|
|
1204
|
+
|
|
1205
|
+
def validate_worker_artifacts(
|
|
1206
|
+
*,
|
|
1207
|
+
workspace_root: Path,
|
|
1208
|
+
artifact_root: str,
|
|
1209
|
+
evidence: Mapping[str, Mapping[str, object]],
|
|
1210
|
+
findings: Iterable[Mapping[str, object]],
|
|
1211
|
+
claimed_at: float,
|
|
1212
|
+
worker_id: str = "",
|
|
1213
|
+
lease_id: str = "",
|
|
1214
|
+
execution_id: str = "",
|
|
1215
|
+
trusted_execution: bool = False,
|
|
1216
|
+
) -> None:
|
|
1217
|
+
"""Validate worker-owned checkpoint artifacts before state mutation."""
|
|
1218
|
+
owners: dict[Path, str] = {}
|
|
1219
|
+
for unit, item in evidence.items():
|
|
1220
|
+
validate_execution_receipt(
|
|
1221
|
+
item,
|
|
1222
|
+
unit=unit,
|
|
1223
|
+
worker_id=worker_id or str(item["worker_id"]),
|
|
1224
|
+
lease_id=lease_id or str(item["lease_id"]),
|
|
1225
|
+
execution_id=execution_id,
|
|
1226
|
+
trusted_execution=trusted_execution,
|
|
1227
|
+
)
|
|
1228
|
+
try:
|
|
1229
|
+
artifact = confined_worker_artifact(
|
|
1230
|
+
workspace_root, artifact_root, str(item["artifact_path"]),
|
|
1231
|
+
)
|
|
1232
|
+
if artifact.suffix.lower() in _SOURCE_ARTIFACT_SUFFIXES:
|
|
1233
|
+
raise InvalidCheckpoint(
|
|
1234
|
+
f"evidence[{unit}].artifact_path 必须是执行输出,"
|
|
1235
|
+
"不能直接引用源码脚本"
|
|
1236
|
+
)
|
|
1237
|
+
previous_unit = owners.get(artifact)
|
|
1238
|
+
if previous_unit is not None:
|
|
1239
|
+
raise InvalidCheckpoint(
|
|
1240
|
+
f"evidence[{unit}].artifact_path 与 {previous_unit} 复用同一 artifact;"
|
|
1241
|
+
"每个 coverage unit 必须使用独立产物"
|
|
1242
|
+
)
|
|
1243
|
+
owners[artifact] = unit
|
|
1244
|
+
stat_result = artifact.stat()
|
|
1245
|
+
if stat_result.st_size > MAX_ARTIFACT_BYTES:
|
|
1246
|
+
raise InvalidCheckpoint(
|
|
1247
|
+
f"evidence[{unit}] artifact 超过 {MAX_ARTIFACT_BYTES} 字节上限"
|
|
1248
|
+
)
|
|
1249
|
+
assert_artifact_not_before_claim(
|
|
1250
|
+
artifact=artifact,
|
|
1251
|
+
claimed_at=claimed_at,
|
|
1252
|
+
unit=unit,
|
|
1253
|
+
channel="worker",
|
|
1254
|
+
)
|
|
1255
|
+
digest = hashlib.sha256()
|
|
1256
|
+
with artifact.open("rb") as artifact_fh:
|
|
1257
|
+
while True:
|
|
1258
|
+
chunk = artifact_fh.read(ARTIFACT_HASH_CHUNK_BYTES)
|
|
1259
|
+
if not chunk:
|
|
1260
|
+
break
|
|
1261
|
+
digest.update(chunk)
|
|
1262
|
+
actual = digest.hexdigest()
|
|
1263
|
+
except InvalidCheckpoint:
|
|
1264
|
+
raise
|
|
1265
|
+
except (OSError, WorkspacePathError) as exc:
|
|
1266
|
+
raise InvalidCheckpoint(
|
|
1267
|
+
f"evidence[{unit}] artifact 无法读取: {exc}"
|
|
1268
|
+
) from exc
|
|
1269
|
+
if actual.lower() != str(item["artifact_sha256"]).lower():
|
|
1270
|
+
raise InvalidCheckpoint(
|
|
1271
|
+
f"evidence[{unit}].artifact_sha256 与 artifact 内容不匹配"
|
|
1272
|
+
)
|
|
1273
|
+
# Worker Runtime artifacts carry a copy of the claim fields. Check
|
|
1274
|
+
# that copy when present so the hashed artifact and submitted receipt
|
|
1275
|
+
# cannot silently describe different work. The digest is intentionally
|
|
1276
|
+
# blank in the embedded copy because hashing a file that contains its
|
|
1277
|
+
# own final hash is circular; the outer artifact hash remains the
|
|
1278
|
+
# authoritative integrity check.
|
|
1279
|
+
if item.get("execution_receipt") is not None:
|
|
1280
|
+
try:
|
|
1281
|
+
artifact_payload = json.loads(artifact.read_text(encoding="utf-8"))
|
|
1282
|
+
except (OSError, UnicodeDecodeError, json.JSONDecodeError):
|
|
1283
|
+
artifact_payload = None
|
|
1284
|
+
if isinstance(artifact_payload, Mapping) and artifact_payload.get(
|
|
1285
|
+
"artifact_type"
|
|
1286
|
+
) == "bugx-worker-execution/v1":
|
|
1287
|
+
embedded = artifact_payload.get("execution_receipt")
|
|
1288
|
+
submitted = item["execution_receipt"]
|
|
1289
|
+
if not isinstance(embedded, Mapping):
|
|
1290
|
+
raise InvalidCheckpoint(
|
|
1291
|
+
f"evidence[{unit}] Worker Runtime artifact 缺少 receipt"
|
|
1292
|
+
)
|
|
1293
|
+
for field in _EXECUTION_RECEIPT_FIELDS - {"artifact_sha256"}:
|
|
1294
|
+
if embedded.get(field) != submitted[field]:
|
|
1295
|
+
raise InvalidCheckpoint(
|
|
1296
|
+
f"evidence[{unit}] artifact receipt.{field} 与提交 receipt 不一致"
|
|
1297
|
+
)
|
|
1298
|
+
if embedded.get("artifact_sha256") not in {
|
|
1299
|
+
"", submitted["artifact_sha256"],
|
|
1300
|
+
}:
|
|
1301
|
+
raise InvalidCheckpoint(
|
|
1302
|
+
f"evidence[{unit}] artifact receipt.artifact_sha256 无效"
|
|
1303
|
+
)
|
|
1304
|
+
if item.get("status") == "passed":
|
|
1305
|
+
raise InvalidCheckpoint(
|
|
1306
|
+
f"evidence[{unit}] {UNVERIFIED_EXECUTION}: "
|
|
1307
|
+
"Worker Runtime receipt 不是外部命令执行证明"
|
|
1308
|
+
)
|
|
1309
|
+
|
|
1310
|
+
for finding in findings:
|
|
1311
|
+
bundle = finding.get("evidence_bundle")
|
|
1312
|
+
if not isinstance(bundle, Mapping):
|
|
1313
|
+
continue
|
|
1314
|
+
for artifact_item in bundle.get("artifacts", []):
|
|
1315
|
+
if not isinstance(artifact_item, Mapping):
|
|
1316
|
+
raise InvalidCheckpoint("evidence_bundle.artifact 必须是对象")
|
|
1317
|
+
try:
|
|
1318
|
+
bundle_artifact = confined_worker_artifact(
|
|
1319
|
+
workspace_root, artifact_root, str(artifact_item["path"]),
|
|
1320
|
+
)
|
|
1321
|
+
if not bundle_artifact.is_file():
|
|
1322
|
+
raise InvalidCheckpoint("evidence_bundle artifact 必须是文件")
|
|
1323
|
+
if bundle_artifact.stat().st_size > MAX_ARTIFACT_BYTES:
|
|
1324
|
+
raise InvalidCheckpoint("evidence_bundle artifact 超过大小上限")
|
|
1325
|
+
digest = hashlib.sha256()
|
|
1326
|
+
with bundle_artifact.open("rb") as bundle_fh:
|
|
1327
|
+
for chunk in iter(
|
|
1328
|
+
lambda: bundle_fh.read(ARTIFACT_HASH_CHUNK_BYTES), b"",
|
|
1329
|
+
):
|
|
1330
|
+
digest.update(chunk)
|
|
1331
|
+
except InvalidCheckpoint:
|
|
1332
|
+
raise
|
|
1333
|
+
except (KeyError, OSError, WorkspacePathError) as exc:
|
|
1334
|
+
raise InvalidCheckpoint(
|
|
1335
|
+
f"evidence_bundle artifact 不可用: {exc}"
|
|
1336
|
+
) from exc
|
|
1337
|
+
if digest.hexdigest().lower() != str(artifact_item["sha256"]).lower():
|
|
1338
|
+
raise InvalidCheckpoint("evidence_bundle artifact sha256 不匹配")
|
|
1339
|
+
|
|
1340
|
+
|
|
1341
|
+
def coverage_evidence_path(workspace_root: Path, state_path: Path) -> Path | None:
|
|
1342
|
+
"""Return the current Life evidence store when a project manifest exists."""
|
|
1343
|
+
manifest = default_coverage_manifest(workspace_root)
|
|
1344
|
+
if not manifest.is_file() or manifest.is_symlink():
|
|
1345
|
+
return None
|
|
1346
|
+
target = state_path.with_name("coverage-evidence.json")
|
|
1347
|
+
if target.is_symlink():
|
|
1348
|
+
raise WorkspacePathError(f"拒绝使用符号链接覆盖证据清单: {target}")
|
|
1349
|
+
return target
|
|
1350
|
+
|
|
1351
|
+
|
|
1352
|
+
def assert_target_fingerprint(
|
|
1353
|
+
workspace_root: Path,
|
|
1354
|
+
expected_fingerprint: str | None,
|
|
1355
|
+
state: RunState,
|
|
1356
|
+
now: float,
|
|
1357
|
+
) -> None:
|
|
1358
|
+
"""Reject work against a changed source/coverage target.
|
|
1359
|
+
|
|
1360
|
+
BX-R4-02:drift 判定比较 `target_identity`(git tree + manifest
|
|
1361
|
+
units,跨 worktree 稳定),而非指纹字符串相等。v1 `workspace:<sha>`
|
|
1362
|
+
(含绝对路径)与 v2(路径无关)即使字符串不同,只要目标身份一致
|
|
1363
|
+
就放行——同 HEAD 多 worktree 不再误杀;源码/计划真变(身份不同)
|
|
1364
|
+
才拒绝。拒绝时给出 rebind 迁移指引而非死胡同。
|
|
1365
|
+
"""
|
|
1366
|
+
invalidate_git_head_cache(workspace_root)
|
|
1367
|
+
current = _workspace_fingerprint(workspace_root)
|
|
1368
|
+
current_identity = _target_identity(workspace_root)
|
|
1369
|
+
expected = state.target_fingerprint or expected_fingerprint
|
|
1370
|
+
if state.target_fingerprint is None:
|
|
1371
|
+
state.target_fingerprint = current
|
|
1372
|
+
append_event(
|
|
1373
|
+
state, "target_fingerprint_bound", now,
|
|
1374
|
+
target_fingerprint=current,
|
|
1375
|
+
target_identity=current_identity,
|
|
1376
|
+
)
|
|
1377
|
+
return
|
|
1378
|
+
if current == expected:
|
|
1379
|
+
return
|
|
1380
|
+
# v1 指纹含绝对路径,不可逆;但"同目标换路径"有一个可验证的必要
|
|
1381
|
+
# 条件:state 绑定的旧身份 == 当前工作区的目标身份。旧身份取自
|
|
1382
|
+
# state 历史中最近一次 target_fingerprint_bound / target_rebound /
|
|
1383
|
+
# target_forward_rolled 事件记录的 target_identity。老版本 state 没有
|
|
1384
|
+
# 该事件时,先以当前 canonical identity 重锚并写入前滚事件,后续调用
|
|
1385
|
+
# 即恢复严格的历史身份比较。
|
|
1386
|
+
bound_identity: str | None = None
|
|
1387
|
+
for event in reversed(state.history):
|
|
1388
|
+
if not isinstance(event, dict):
|
|
1389
|
+
continue
|
|
1390
|
+
if event.get("type") in (
|
|
1391
|
+
"target_fingerprint_bound",
|
|
1392
|
+
"target_rebound",
|
|
1393
|
+
"target_forward_rolled",
|
|
1394
|
+
):
|
|
1395
|
+
candidate = event.get("target_identity")
|
|
1396
|
+
if isinstance(candidate, str) and candidate:
|
|
1397
|
+
bound_identity = candidate
|
|
1398
|
+
break
|
|
1399
|
+
legacy_identity_fallback = bound_identity is None and any(
|
|
1400
|
+
isinstance(event, dict)
|
|
1401
|
+
and event.get("type") == "run_started"
|
|
1402
|
+
and event.get("target_fingerprint") == expected
|
|
1403
|
+
for event in state.history
|
|
1404
|
+
)
|
|
1405
|
+
if legacy_identity_fallback:
|
|
1406
|
+
# Legacy states predate the bound-identity event. Re-anchor them to
|
|
1407
|
+
# the current canonical target identity once, so the next persisted
|
|
1408
|
+
# forward-roll event restores the strict historical comparison.
|
|
1409
|
+
bound_identity = current_identity
|
|
1410
|
+
if bound_identity == current_identity:
|
|
1411
|
+
# 同源码树 + 同覆盖单元,仅工作区路径不同 → 前滚指纹,放行。
|
|
1412
|
+
append_event(
|
|
1413
|
+
state, "target_forward_rolled", now,
|
|
1414
|
+
previous_target_fingerprint=expected,
|
|
1415
|
+
target_fingerprint=current,
|
|
1416
|
+
target_identity=current_identity,
|
|
1417
|
+
reason=(
|
|
1418
|
+
"legacy state re-anchored to current target identity"
|
|
1419
|
+
if legacy_identity_fallback
|
|
1420
|
+
else "same source tree and coverage units; workspace path only"
|
|
1421
|
+
),
|
|
1422
|
+
)
|
|
1423
|
+
state.target_fingerprint = current
|
|
1424
|
+
return
|
|
1425
|
+
append_event(
|
|
1426
|
+
state, "target_drift_rejected", now,
|
|
1427
|
+
expected_target_fingerprint=expected,
|
|
1428
|
+
actual_target_fingerprint=current,
|
|
1429
|
+
actual_target_identity=current_identity,
|
|
1430
|
+
bound_target_identity=bound_identity,
|
|
1431
|
+
)
|
|
1432
|
+
raise InvalidCheckpoint(
|
|
1433
|
+
"审计目标已变化;请重新生成当前覆盖计划后再继续"
|
|
1434
|
+
"(若仅切换 worktree 且源码/计划未变,请执行 rebind_target 迁移指纹)"
|
|
1435
|
+
)
|
|
1436
|
+
|
|
1437
|
+
|
|
1438
|
+
def publish_checkpoint_evidence(
|
|
1439
|
+
workspace_root: Path,
|
|
1440
|
+
state_path: Path,
|
|
1441
|
+
evidence: Mapping[str, Mapping[str, object]],
|
|
1442
|
+
) -> Callable[[], None] | None:
|
|
1443
|
+
"""Prepare and publish evidence, returning a best-effort rollback hook.
|
|
1444
|
+
|
|
1445
|
+
The staged manifest makes a batch all-or-nothing at the evidence-file level.
|
|
1446
|
+
The returned hook closes the remaining cross-file gap when run-state
|
|
1447
|
+
persistence fails; this is a recovery boundary, not cross-file atomicity.
|
|
1448
|
+
"""
|
|
1449
|
+
if not evidence:
|
|
1450
|
+
return None
|
|
1451
|
+
target = coverage_evidence_path(workspace_root, state_path)
|
|
1452
|
+
if target is None:
|
|
1453
|
+
return None
|
|
1454
|
+
try:
|
|
1455
|
+
from core.coverage import coverage_evidence
|
|
1456
|
+
|
|
1457
|
+
lock_path = target.with_name(target.name + ".lock")
|
|
1458
|
+
with coverage_evidence._exclusive_lock(lock_path):
|
|
1459
|
+
_reconcile_staged_evidence(target)
|
|
1460
|
+
if target.is_symlink():
|
|
1461
|
+
raise WorkspacePathError(f"拒绝使用符号链接覆盖证据清单: {target}")
|
|
1462
|
+
original_exists = target.exists()
|
|
1463
|
+
if original_exists and not target.is_file():
|
|
1464
|
+
raise WorkspacePathError(f"覆盖证据清单不是普通文件: {target}")
|
|
1465
|
+
original_payload = target.read_bytes() if original_exists else None
|
|
1466
|
+
|
|
1467
|
+
descriptor, staged_name = tempfile.mkstemp(
|
|
1468
|
+
prefix=(f".{target.name}.stage-{os.getpid()}-{time.time_ns()}-"),
|
|
1469
|
+
suffix=".tmp", dir=str(target.parent),
|
|
1470
|
+
)
|
|
1471
|
+
os.close(descriptor)
|
|
1472
|
+
staged = Path(staged_name)
|
|
1473
|
+
staged.unlink()
|
|
1474
|
+
staged_lock = staged.with_name(staged.name + ".lock")
|
|
1475
|
+
try:
|
|
1476
|
+
if original_payload is not None:
|
|
1477
|
+
atomic_write_bytes(staged, original_payload)
|
|
1478
|
+
store = coverage_evidence.EvidenceStore(
|
|
1479
|
+
staged, workspace_root=workspace_root,
|
|
1480
|
+
)
|
|
1481
|
+
for unit_id, item in evidence.items():
|
|
1482
|
+
artifact = confined_regular_file(
|
|
1483
|
+
workspace_root, str(item["artifact_path"]),
|
|
1484
|
+
)
|
|
1485
|
+
observed_at = datetime.fromtimestamp(
|
|
1486
|
+
float(item["timestamp"]), tz=timezone.utc,
|
|
1487
|
+
).isoformat()
|
|
1488
|
+
record = {
|
|
1489
|
+
"unit_id": unit_id,
|
|
1490
|
+
"command": item["command"],
|
|
1491
|
+
"exit_code": item["exit_code"],
|
|
1492
|
+
"artifact_path": artifact.relative_to(
|
|
1493
|
+
workspace_root,
|
|
1494
|
+
).as_posix(),
|
|
1495
|
+
"artifact_sha256": item["artifact_sha256"],
|
|
1496
|
+
"target_fingerprint": item["target_fingerprint"],
|
|
1497
|
+
"observed_at": observed_at,
|
|
1498
|
+
"worker_id": item["worker_id"],
|
|
1499
|
+
"status": item["status"],
|
|
1500
|
+
}
|
|
1501
|
+
if item.get("target_drifted") is True:
|
|
1502
|
+
record["target_drifted"] = True
|
|
1503
|
+
if item.get("reproduced_crash") is True:
|
|
1504
|
+
record["reproduced_crash"] = True
|
|
1505
|
+
if item.get("evidence_type") is not None:
|
|
1506
|
+
record["evidence_type"] = item["evidence_type"]
|
|
1507
|
+
receipt = item.get("execution_receipt")
|
|
1508
|
+
if isinstance(receipt, Mapping):
|
|
1509
|
+
record["execution_id"] = receipt["execution_id"]
|
|
1510
|
+
record["lease_id"] = receipt["lease_id"]
|
|
1511
|
+
record["execution_receipt_sha256"] = execution_receipt_sha256(
|
|
1512
|
+
receipt
|
|
1513
|
+
)
|
|
1514
|
+
# Supervisor has already validated this checkpoint as a
|
|
1515
|
+
# re-verification boundary; prepare every record off-target.
|
|
1516
|
+
# BX-ENGINE-21:复验路径显式允许跨 target 替换——target 重绑后
|
|
1517
|
+
# 旧记录的目标已不是当前目标,若不允许则同一 unit 永久不可提交。
|
|
1518
|
+
result = store.store(
|
|
1519
|
+
record, allow_supersede=True, allow_target_rebind=True,
|
|
1520
|
+
)
|
|
1521
|
+
if result.status == "conflict":
|
|
1522
|
+
reason = f": {result.reason}" if getattr(result, "reason", "") else ""
|
|
1523
|
+
raise InvalidCheckpoint(
|
|
1524
|
+
f"coverage evidence[{unit_id}] 与已有证据冲突,拒绝覆盖{reason}"
|
|
1525
|
+
)
|
|
1526
|
+
if staged_lock.exists():
|
|
1527
|
+
staged_lock.unlink()
|
|
1528
|
+
if target.is_symlink():
|
|
1529
|
+
raise WorkspacePathError(
|
|
1530
|
+
f"拒绝使用符号链接覆盖证据清单: {target}"
|
|
1531
|
+
)
|
|
1532
|
+
os.replace(staged, target)
|
|
1533
|
+
finally:
|
|
1534
|
+
for temporary in (staged, staged_lock):
|
|
1535
|
+
if temporary.is_symlink():
|
|
1536
|
+
raise WorkspacePathError(
|
|
1537
|
+
f"拒绝清理符号链接临时证据: {temporary}"
|
|
1538
|
+
)
|
|
1539
|
+
if temporary.exists():
|
|
1540
|
+
temporary.unlink()
|
|
1541
|
+
|
|
1542
|
+
def rollback() -> None:
|
|
1543
|
+
with coverage_evidence._exclusive_lock(lock_path):
|
|
1544
|
+
if target.is_symlink():
|
|
1545
|
+
raise WorkspacePathError(
|
|
1546
|
+
f"证据回滚遇到符号链接,拒绝继续: {target}"
|
|
1547
|
+
)
|
|
1548
|
+
if original_payload is None:
|
|
1549
|
+
if target.exists():
|
|
1550
|
+
if not target.is_file():
|
|
1551
|
+
raise WorkspacePathError(
|
|
1552
|
+
f"证据回滚目标不是普通文件: {target}"
|
|
1553
|
+
)
|
|
1554
|
+
target.unlink()
|
|
1555
|
+
else:
|
|
1556
|
+
atomic_write_bytes(target, original_payload)
|
|
1557
|
+
|
|
1558
|
+
return rollback
|
|
1559
|
+
except InvalidCheckpoint:
|
|
1560
|
+
raise
|
|
1561
|
+
except (OSError, ValueError, RuntimeError) as exc:
|
|
1562
|
+
raise InvalidCheckpoint(
|
|
1563
|
+
f"无法发布 checkpoint 覆盖证据: {exc}"
|
|
1564
|
+
) from exc
|