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,1432 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""launch_phases/finding_settlement.py - 发现项门禁校验与自动计命结算 (DOC-069)。"""
|
|
3
|
+
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
import hashlib
|
|
7
|
+
import io
|
|
8
|
+
import json
|
|
9
|
+
import math
|
|
10
|
+
import os
|
|
11
|
+
import re
|
|
12
|
+
import subprocess
|
|
13
|
+
import sys
|
|
14
|
+
import ctypes
|
|
15
|
+
import errno
|
|
16
|
+
import stat
|
|
17
|
+
import time
|
|
18
|
+
from collections.abc import Mapping
|
|
19
|
+
from dataclasses import dataclass, field
|
|
20
|
+
from pathlib import Path
|
|
21
|
+
from types import MappingProxyType
|
|
22
|
+
from typing import Any
|
|
23
|
+
|
|
24
|
+
from core.launch_phases.common import (
|
|
25
|
+
VERIFY,
|
|
26
|
+
LIFECYCLE_ROOT_WARNED,
|
|
27
|
+
child_environment,
|
|
28
|
+
resolve_project_root,
|
|
29
|
+
supervisor_state_path,
|
|
30
|
+
uses_project_layout,
|
|
31
|
+
)
|
|
32
|
+
from core.launch_phases.session_runtime import baseline_json, load_runtime
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def _settlement_supervisor(root: Path):
|
|
36
|
+
"""Resolve the active Supervisor without creating a new run."""
|
|
37
|
+
try:
|
|
38
|
+
from core.supervisor import audit_supervisor
|
|
39
|
+
import core.bugx_paths as bugx_paths
|
|
40
|
+
scope = bugx_paths.require(root)
|
|
41
|
+
return audit_supervisor.Supervisor(root, state_path=scope.supervisor)
|
|
42
|
+
except (ImportError, OSError, RuntimeError, ValueError):
|
|
43
|
+
return None
|
|
44
|
+
|
|
45
|
+
from core.launch_phases.findings_snapshot import (
|
|
46
|
+
CREDITED_CAP_DEFAULT,
|
|
47
|
+
CREDITED_CAP_ENV,
|
|
48
|
+
CREDITED_CAP_MAX,
|
|
49
|
+
CREDITED_CAP_MIN,
|
|
50
|
+
FindingsSnapshot,
|
|
51
|
+
FindingsSnapshotError,
|
|
52
|
+
authoritative_round,
|
|
53
|
+
baseline_run_id,
|
|
54
|
+
capture_findings_snapshot,
|
|
55
|
+
credited_cap,
|
|
56
|
+
deep_freeze,
|
|
57
|
+
deep_thaw,
|
|
58
|
+
expected_findings_binding,
|
|
59
|
+
findings_artifact_paths,
|
|
60
|
+
findings_payload_path,
|
|
61
|
+
text_line_count,
|
|
62
|
+
validate_findings_payload_snapshot,
|
|
63
|
+
verify_findings_binding,
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
# Compatibility aliases
|
|
67
|
+
_FINDINGS_SEAL_EVENT_TYPES = (
|
|
68
|
+
"finding_decisions_synced", "findings_report_sealed",
|
|
69
|
+
)
|
|
70
|
+
_deep_freeze = deep_freeze
|
|
71
|
+
_deep_thaw = deep_thaw
|
|
72
|
+
_baseline_run_id = baseline_run_id
|
|
73
|
+
_text_line_count = text_line_count
|
|
74
|
+
_findings_artifact_paths = findings_artifact_paths
|
|
75
|
+
_authoritative_round = authoritative_round
|
|
76
|
+
_expected_findings_binding = expected_findings_binding
|
|
77
|
+
_validate_findings_payload_snapshot = validate_findings_payload_snapshot
|
|
78
|
+
|
|
79
|
+
def _warn_once_stderr(message: str, key: str) -> None:
|
|
80
|
+
"""stderr 一次性警告;绝不写 stdout,避免污染宿主协议输出。"""
|
|
81
|
+
if key in LIFECYCLE_ROOT_WARNED:
|
|
82
|
+
return
|
|
83
|
+
LIFECYCLE_ROOT_WARNED.add(key)
|
|
84
|
+
try:
|
|
85
|
+
print(f"[launch_bugx] ⚠ {message}", file=sys.stderr)
|
|
86
|
+
except OSError:
|
|
87
|
+
pass
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def lifecycle_root_for(runtime: dict) -> Path:
|
|
91
|
+
"""解析当前生命周期目录:polling_id 优先,session_id 次之。"""
|
|
92
|
+
# 布局归一:项目布局的账本在 ``<root>/.bugx/pollings``;无布局的
|
|
93
|
+
# 自包含引擎副本按 ``_path_values_for_root`` 把运行态放在项目根,
|
|
94
|
+
# 账本因此位于 ``<root>/<polling_id>/lifecycles``。旧实现无条件拼
|
|
95
|
+
# ``<root>/.bugx/pollings``,在副本布局下永远找不到目录,落到
|
|
96
|
+
# ``polling-unknown`` 并让 Finding 快照校验 fail-closed。
|
|
97
|
+
from core.launch_phases import common as _common
|
|
98
|
+
|
|
99
|
+
# 布局形状按**磁盘事实**判定:本模块的 ``uses_project_layout`` 是可被
|
|
100
|
+
# 调用方/测试替换的全局,而路径形状不能跟着被替换的判定漂移——夹具在
|
|
101
|
+
# ``root/.bugx/pollings`` 下写入报告却把布局判定打桩为 False 时,
|
|
102
|
+
# 旧写法会去 ``root/pollings`` 找,所有已达成的 Finding 都被判为"无"。
|
|
103
|
+
pollings_root = _common.pollings_root(resolve_project_root())
|
|
104
|
+
lifecycle_id = str(runtime.get("lifecycle_id") or "unknown")
|
|
105
|
+
candidates: list[str] = []
|
|
106
|
+
for key in ("polling_id", "session_id"):
|
|
107
|
+
value = runtime.get(key)
|
|
108
|
+
if isinstance(value, str) and value and value.startswith("polling-") \
|
|
109
|
+
and value not in candidates:
|
|
110
|
+
candidates.append(value)
|
|
111
|
+
for candidate in candidates:
|
|
112
|
+
root = pollings_root / candidate / "lifecycles" / lifecycle_id
|
|
113
|
+
if root.is_dir():
|
|
114
|
+
return root
|
|
115
|
+
_warn_once_stderr(
|
|
116
|
+
f"候选生命周期目录不存在,跳过 {candidate}: {root}",
|
|
117
|
+
f"missing:{root}",
|
|
118
|
+
)
|
|
119
|
+
# DOC-195: 移除猜测性 polling-000001 目录回退,收敛为 fail-closed 严格路径
|
|
120
|
+
preferred = candidates[0] if candidates else "polling-unknown"
|
|
121
|
+
root = pollings_root / preferred / "lifecycles" / lifecycle_id
|
|
122
|
+
_warn_once_stderr(
|
|
123
|
+
f"生命周期目录不存在: {root}",
|
|
124
|
+
f"nocandidate:{root}",
|
|
125
|
+
)
|
|
126
|
+
return root
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
def settle_findings_path(runtime: dict) -> Path | None:
|
|
130
|
+
"""结算读取当前生命周期;非正式测试布局才允许扁平路径。
|
|
131
|
+
|
|
132
|
+
stale 检测(2026-11-09 E1,opencode 复盘):文件存在但 binding 的
|
|
133
|
+
run_id 属于**已终结的旧 run**(且 lifecycle 也不同)→ 视为 stale 返回
|
|
134
|
+
None,让上游走 auto_build_findings_json 自动重建。返回旧路径只会在
|
|
135
|
+
快照校验层炸 findings_binding_mismatch(跨 6 次 post 重试 6.5 分钟的
|
|
136
|
+
实测主因)。同 lifecycle/run_id 的文件不判 stale(真损坏走快照校验)。
|
|
137
|
+
"""
|
|
138
|
+
lifecycle_findings = _lifecycle_findings_path(runtime)
|
|
139
|
+
if lifecycle_findings.is_file():
|
|
140
|
+
if _findings_binding_is_stale(lifecycle_findings, runtime):
|
|
141
|
+
return None
|
|
142
|
+
return lifecycle_findings
|
|
143
|
+
if not uses_project_layout():
|
|
144
|
+
candidate = Path(".bugx/findings.json")
|
|
145
|
+
if candidate.is_file() and not candidate.is_symlink():
|
|
146
|
+
if _findings_binding_is_stale(candidate, runtime):
|
|
147
|
+
return None
|
|
148
|
+
return candidate
|
|
149
|
+
return None
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
def _findings_binding_is_stale(path: Path, runtime: dict) -> bool:
|
|
153
|
+
"""binding 的 run_id 与当前 runtime 不同且 lifecycle 也不同 → stale。"""
|
|
154
|
+
import json as _json
|
|
155
|
+
|
|
156
|
+
try:
|
|
157
|
+
payload = _json.loads(path.read_text(encoding="utf-8"))
|
|
158
|
+
except (OSError, ValueError):
|
|
159
|
+
return False
|
|
160
|
+
if not isinstance(payload, dict):
|
|
161
|
+
return False
|
|
162
|
+
binding = payload.get("run_binding")
|
|
163
|
+
if not isinstance(binding, Mapping):
|
|
164
|
+
return False
|
|
165
|
+
old_run = str(binding.get("run_id") or "")
|
|
166
|
+
old_lifecycle = str(binding.get("lifecycle_id") or "")
|
|
167
|
+
current_run = str(runtime.get("run_id") or "")
|
|
168
|
+
current_lifecycle = str(runtime.get("lifecycle_id") or "")
|
|
169
|
+
return bool(
|
|
170
|
+
old_run and current_run and old_run != current_run
|
|
171
|
+
and old_lifecycle and current_lifecycle and old_lifecycle != current_lifecycle
|
|
172
|
+
)
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
def _finding_decision_state(item: Mapping[str, Any]) -> str:
|
|
176
|
+
"""裁决态归一:confirmed/rejected 之外(含确认块缺失或非法)一律 candidate。
|
|
177
|
+
|
|
178
|
+
与 auto_build 的口径一致——非法 confirmation 块会被 pop 掉,快照里等价于
|
|
179
|
+
candidate;这里不重复抛错,只做决定性归一。
|
|
180
|
+
"""
|
|
181
|
+
confirmation = item.get("confirmation") if isinstance(item, Mapping) else None
|
|
182
|
+
if isinstance(confirmation, Mapping):
|
|
183
|
+
state = str(confirmation.get("state") or "").strip().lower()
|
|
184
|
+
if state in {"confirmed", "rejected"}:
|
|
185
|
+
return state
|
|
186
|
+
return "candidate"
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
def _finding_identity_keys(item: Mapping[str, Any]) -> list[str]:
|
|
190
|
+
"""finding 身份键(id / finding_id / fingerprint),去重保序。"""
|
|
191
|
+
keys: list[str] = []
|
|
192
|
+
for field_name in ("id", "finding_id", "fingerprint"):
|
|
193
|
+
value = str(item.get(field_name) or "").strip() if isinstance(item, Mapping) else ""
|
|
194
|
+
if value and value not in keys:
|
|
195
|
+
keys.append(value)
|
|
196
|
+
return keys
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
def findings_json_stale_vs_authority(runtime: dict) -> str | None:
|
|
200
|
+
"""派生 findings.json 与 Supervisor 权威态的确认态/revision 一致性检查。
|
|
201
|
+
|
|
202
|
+
缺陷(2026-11-17 obs-2,dsh 重验实证):settle_findings_path 的 stale 判定
|
|
203
|
+
只看 run_id/lifecycle binding,同一 run 内**先于裁决**生成的 findings.json
|
|
204
|
+
会让 post 跳过 auto_build,把旧候选视图直接拿去结算(09:33 裁决后必须手动
|
|
205
|
+
删除派生文件)。这里追加两条从严信号:
|
|
206
|
+
|
|
207
|
+
* revision 信号:派生文件记录的 ``supervisor_binding.findings_revision``
|
|
208
|
+
落后于权威态(新 finding 已同步进 Supervisor 而视图未重建)→ stale;
|
|
209
|
+
* 确认态信号:权威终态(confirmed/rejected)必须在派生视图中以**同态**
|
|
210
|
+
出现——落后(candidate)或篡改反向(rejected↔confirmed)都是 stale;
|
|
211
|
+
权威 candidate 允许派生侧保留 candidate 或裁决器补证的 confirmed。
|
|
212
|
+
|
|
213
|
+
返回 None 表示一致(或无法可靠判定——交由快照校验兜底,绝不因检查自身
|
|
214
|
+
失败而放大阻断);返回字符串为 stale 原因,调用方应归档旧文件并重建。
|
|
215
|
+
"""
|
|
216
|
+
path = settle_findings_path(runtime)
|
|
217
|
+
if path is None or not path.is_file() or path.is_symlink():
|
|
218
|
+
return None
|
|
219
|
+
try:
|
|
220
|
+
derived = json.loads(path.read_text(encoding="utf-8"))
|
|
221
|
+
except (OSError, ValueError):
|
|
222
|
+
return None
|
|
223
|
+
if not isinstance(derived, dict):
|
|
224
|
+
return None
|
|
225
|
+
derived_findings = derived.get("findings")
|
|
226
|
+
if not isinstance(derived_findings, list):
|
|
227
|
+
return None
|
|
228
|
+
root = Path(os.path.abspath(os.fspath(resolve_project_root())))
|
|
229
|
+
from core.launch_phases.post_dry_run import RootReader, SnapshotInvalid
|
|
230
|
+
|
|
231
|
+
authority_reader = None
|
|
232
|
+
close_authority = False
|
|
233
|
+
try:
|
|
234
|
+
try:
|
|
235
|
+
project_reader = RootReader(root)
|
|
236
|
+
except SnapshotInvalid:
|
|
237
|
+
return None
|
|
238
|
+
try:
|
|
239
|
+
supervisor_payload, authority_reader, close_authority = (
|
|
240
|
+
_load_authoritative_supervisor(runtime, root, project_reader)
|
|
241
|
+
)
|
|
242
|
+
finally:
|
|
243
|
+
project_reader.close()
|
|
244
|
+
if not isinstance(supervisor_payload, dict):
|
|
245
|
+
return None
|
|
246
|
+
authority_findings = supervisor_payload.get("findings")
|
|
247
|
+
if not isinstance(authority_findings, list):
|
|
248
|
+
return None
|
|
249
|
+
# 信号一:finding 同步代 revision(新增 finding 未进派生视图)。
|
|
250
|
+
binding = derived.get("supervisor_binding")
|
|
251
|
+
if isinstance(binding, Mapping):
|
|
252
|
+
recorded_raw = binding.get("findings_revision")
|
|
253
|
+
recorded = recorded_raw if (
|
|
254
|
+
isinstance(recorded_raw, int) and not isinstance(recorded_raw, bool)
|
|
255
|
+
) else None
|
|
256
|
+
authority_revision = supervisor_payload.get("findings_revision")
|
|
257
|
+
if (
|
|
258
|
+
recorded is not None
|
|
259
|
+
and isinstance(authority_revision, int)
|
|
260
|
+
and not isinstance(authority_revision, bool)
|
|
261
|
+
and recorded != authority_revision
|
|
262
|
+
):
|
|
263
|
+
return (
|
|
264
|
+
f"supervisor_binding.findings_revision={recorded} 落后于权威态 "
|
|
265
|
+
f"{authority_revision}"
|
|
266
|
+
)
|
|
267
|
+
# 信号二:逐条确认态必须不落后于权威终态。
|
|
268
|
+
derived_index: dict[str, list[dict]] = {}
|
|
269
|
+
for item in derived_findings:
|
|
270
|
+
if isinstance(item, dict):
|
|
271
|
+
for key in _finding_identity_keys(item):
|
|
272
|
+
derived_index.setdefault(key, []).append(item)
|
|
273
|
+
matched: set[int] = set()
|
|
274
|
+
for authority in authority_findings:
|
|
275
|
+
if not isinstance(authority, dict):
|
|
276
|
+
continue
|
|
277
|
+
label = str(authority.get("id") or authority.get("fingerprint") or "?")
|
|
278
|
+
candidates: list[dict] = []
|
|
279
|
+
seen: set[int] = set()
|
|
280
|
+
for key in _finding_identity_keys(authority):
|
|
281
|
+
for item in derived_index.get(key, []):
|
|
282
|
+
marker = id(item)
|
|
283
|
+
if marker not in seen:
|
|
284
|
+
seen.add(marker)
|
|
285
|
+
candidates.append(item)
|
|
286
|
+
if len(candidates) != 1:
|
|
287
|
+
return f"权威 finding {label} 在派生视图中缺失或不唯一"
|
|
288
|
+
derived_item = candidates[0]
|
|
289
|
+
matched.add(id(derived_item))
|
|
290
|
+
authority_state = _finding_decision_state(authority)
|
|
291
|
+
derived_state = _finding_decision_state(derived_item)
|
|
292
|
+
if authority_state in {"confirmed", "rejected"}:
|
|
293
|
+
if derived_state != authority_state:
|
|
294
|
+
return (
|
|
295
|
+
f"权威 finding {label} 终态={authority_state},"
|
|
296
|
+
f"派生视图为 {derived_state}(落后或反向)"
|
|
297
|
+
)
|
|
298
|
+
elif derived_state == "rejected":
|
|
299
|
+
return f"权威 finding {label} 是 candidate,派生视图却是 rejected"
|
|
300
|
+
for item in derived_findings:
|
|
301
|
+
if isinstance(item, dict) and id(item) not in matched:
|
|
302
|
+
return "派生视图存在权威态之外的 finding"
|
|
303
|
+
return None
|
|
304
|
+
except FindingsSnapshotError:
|
|
305
|
+
return None
|
|
306
|
+
except Exception:
|
|
307
|
+
return None
|
|
308
|
+
finally:
|
|
309
|
+
if close_authority and authority_reader is not None:
|
|
310
|
+
try:
|
|
311
|
+
authority_reader.close()
|
|
312
|
+
except Exception:
|
|
313
|
+
pass
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
def refresh_stale_findings_json(runtime: dict) -> str | None:
|
|
317
|
+
"""post auto_build 前置刷新:派生视图落后于权威态时归档旧文件并放行重建。
|
|
318
|
+
|
|
319
|
+
与 :func:`archive_stale_findings_binding`(跨 run 的 binding 归档)互补:
|
|
320
|
+
本函数处理**同 run 内**确认态/revision 落后。一致文件不动(幂等);判定
|
|
321
|
+
为 stale 时把旧文件改名 ``.stale-backup``(冲突时追加时间戳,绝不覆盖)
|
|
322
|
+
并返回人读原因,settle_findings_path 随即返回 None,调用方走 auto_build
|
|
323
|
+
从权威态重建。
|
|
324
|
+
"""
|
|
325
|
+
if settle_findings_path(runtime) is None:
|
|
326
|
+
return None
|
|
327
|
+
reason = findings_json_stale_vs_authority(runtime)
|
|
328
|
+
if reason is None:
|
|
329
|
+
return None
|
|
330
|
+
path = settle_findings_path(runtime)
|
|
331
|
+
if path is None or not path.is_file():
|
|
332
|
+
return None
|
|
333
|
+
backup = path.with_name(path.name + ".stale-backup")
|
|
334
|
+
if backup.exists():
|
|
335
|
+
backup = path.with_name(f"{path.name}.stale-backup-{int(time.time())}")
|
|
336
|
+
os.replace(path, backup)
|
|
337
|
+
return (
|
|
338
|
+
f"派生 findings.json 落后于 Supervisor 权威态({reason});"
|
|
339
|
+
f"已归档为 {backup.name},将从权威态重建"
|
|
340
|
+
)
|
|
341
|
+
|
|
342
|
+
|
|
343
|
+
def _lifecycle_findings_path(runtime: dict) -> Path:
|
|
344
|
+
return lifecycle_root_for(runtime) / "findings.json"
|
|
345
|
+
|
|
346
|
+
|
|
347
|
+
def archive_stale_findings_binding(runtime: dict) -> str | None:
|
|
348
|
+
"""findings.json 绑定指向已终结的旧 run 时归档之;返回人读原因或 None。
|
|
349
|
+
|
|
350
|
+
实测死锁(2026-11-09):auto 续轮换 run_id 后,上一 Life 的 findings.json
|
|
351
|
+
留在原路径,post 的快照校验要求 binding 与当前 run 一致 → 整轮拒绝结算,
|
|
352
|
+
且报错只有码没有原因,用户只能手动改名放行。语义上旧 findings 是旧 Life
|
|
353
|
+
的合法产物:归档(原子改名)到本 lifecycle 的 snapshots/ 目录,当前 Life
|
|
354
|
+
由 agent 重新产出 findings。当前会话真损坏(同 run_id)不受影响。
|
|
355
|
+
|
|
356
|
+
判据从严:run_id **且** lifecycle_id 都与当前不同才归档;run_id 相同视为
|
|
357
|
+
当前会话数据(损坏与否交由快照校验正常报错)。
|
|
358
|
+
"""
|
|
359
|
+
import json as _json
|
|
360
|
+
|
|
361
|
+
path = _lifecycle_findings_path(runtime)
|
|
362
|
+
if not path.is_file() or path.is_symlink():
|
|
363
|
+
return None
|
|
364
|
+
try:
|
|
365
|
+
payload = _json.loads(path.read_text(encoding="utf-8"))
|
|
366
|
+
except (OSError, ValueError):
|
|
367
|
+
return None
|
|
368
|
+
if not isinstance(payload, dict):
|
|
369
|
+
return None
|
|
370
|
+
binding = payload.get("run_binding")
|
|
371
|
+
if not isinstance(binding, Mapping):
|
|
372
|
+
return None
|
|
373
|
+
old_run = str(binding.get("run_id") or "")
|
|
374
|
+
old_lifecycle = str(binding.get("lifecycle_id") or "")
|
|
375
|
+
current_run = str(runtime.get("run_id") or "")
|
|
376
|
+
current_lifecycle = str(runtime.get("lifecycle_id") or "")
|
|
377
|
+
if not old_run or old_run == current_run:
|
|
378
|
+
return None
|
|
379
|
+
if old_lifecycle and current_lifecycle and old_lifecycle == current_lifecycle:
|
|
380
|
+
return None # 同 lifecycle:run_id 漂移交由快照校验报错,不静默归档
|
|
381
|
+
target_dir = lifecycle_root_for(runtime) / "snapshots"
|
|
382
|
+
try:
|
|
383
|
+
target_dir.mkdir(parents=True, exist_ok=True)
|
|
384
|
+
target = target_dir / f"findings-archived-{old_run[:12]}.json"
|
|
385
|
+
if target.exists():
|
|
386
|
+
return None # 已归档过,避免覆盖;交由快照校验正常报错
|
|
387
|
+
os.replace(path, target)
|
|
388
|
+
return (
|
|
389
|
+
f"已归档遗留 findings(旧 run_id={old_run[:12]}… → {target.name});"
|
|
390
|
+
"当前 Life 需重新产出 findings.json 后再 post"
|
|
391
|
+
)
|
|
392
|
+
except OSError:
|
|
393
|
+
return None
|
|
394
|
+
|
|
395
|
+
|
|
396
|
+
|
|
397
|
+
|
|
398
|
+
def _supervisor_state_candidates(runtime: dict) -> list[Path]:
|
|
399
|
+
"""supervisor state 快照的候选路径(按可信度排序,取最新登记者胜出)。"""
|
|
400
|
+
lifecycle_root = lifecycle_root_for(runtime)
|
|
401
|
+
return (
|
|
402
|
+
lifecycle_root / "state" / "supervisor.json",
|
|
403
|
+
resolve_project_root() / ".bugx" / "state" / "supervisor.json",
|
|
404
|
+
lifecycle_root / "supervisor.json",
|
|
405
|
+
)
|
|
406
|
+
|
|
407
|
+
|
|
408
|
+
def _registered_findings_report_sha256(runtime: dict) -> str | None:
|
|
409
|
+
"""V2:supervisor state 中登记的当前轮 findings.json 内容哈希。
|
|
410
|
+
|
|
411
|
+
扫描 state.history 中带 report_sha256 的 seal 类事件,按生命周期与
|
|
412
|
+
Round 过滤(跨轮/跨生命周期的登记视为重放噪声,不采纳),取 seq 最新
|
|
413
|
+
的一条。无登记(旧轮 state)返回 None,由调用方跳过比对。
|
|
414
|
+
"""
|
|
415
|
+
runtime_lifecycle = str(runtime.get("lifecycle_id") or "")
|
|
416
|
+
runtime_round = _authoritative_round(runtime)
|
|
417
|
+
best: tuple[int, str] | None = None
|
|
418
|
+
for state_path in _supervisor_state_candidates(runtime):
|
|
419
|
+
payload = _read_json_object(state_path)
|
|
420
|
+
if not payload:
|
|
421
|
+
continue
|
|
422
|
+
history = payload.get("history")
|
|
423
|
+
if not isinstance(history, list):
|
|
424
|
+
continue
|
|
425
|
+
for event in history:
|
|
426
|
+
if not isinstance(event, dict):
|
|
427
|
+
continue
|
|
428
|
+
if event.get("type") not in _FINDINGS_SEAL_EVENT_TYPES:
|
|
429
|
+
continue
|
|
430
|
+
digest = event.get("report_sha256")
|
|
431
|
+
if not isinstance(digest, str) or len(digest) != 64:
|
|
432
|
+
continue
|
|
433
|
+
try:
|
|
434
|
+
int(digest, 16)
|
|
435
|
+
except ValueError:
|
|
436
|
+
continue
|
|
437
|
+
event_lifecycle = event.get("lifecycle_id")
|
|
438
|
+
if (
|
|
439
|
+
runtime_lifecycle
|
|
440
|
+
and isinstance(event_lifecycle, str) and event_lifecycle
|
|
441
|
+
and event_lifecycle != runtime_lifecycle
|
|
442
|
+
):
|
|
443
|
+
continue
|
|
444
|
+
event_round = event.get("round_no")
|
|
445
|
+
if (
|
|
446
|
+
isinstance(runtime_round, int) and not isinstance(runtime_round, bool)
|
|
447
|
+
and isinstance(event_round, int) and not isinstance(event_round, bool)
|
|
448
|
+
and event_round != runtime_round
|
|
449
|
+
):
|
|
450
|
+
continue
|
|
451
|
+
seq = event.get("seq")
|
|
452
|
+
order = seq if isinstance(seq, int) and not isinstance(seq, bool) else 0
|
|
453
|
+
if best is None or order >= best[0]:
|
|
454
|
+
best = (order, digest.lower())
|
|
455
|
+
return best[1] if best else None
|
|
456
|
+
|
|
457
|
+
|
|
458
|
+
def _verify_findings_report_seal(
|
|
459
|
+
runtime: dict, report_bytes: bytes,
|
|
460
|
+
) -> tuple[bool, str]:
|
|
461
|
+
"""V2 门禁:findings.json 在 sync 成功后不得被改写。
|
|
462
|
+
|
|
463
|
+
sync(apply_decision_sync)成功时会把报告原始字节的内容哈希登记进
|
|
464
|
+
supervisor state(hash-chain 审计事件)。post 结算读取登记哈希与当前
|
|
465
|
+
文件实际哈希比对——不一致说明 sync 之后报告被改过,结算 fail-closed。
|
|
466
|
+
返回 ``(ok, note)``;无登记(旧轮 state)返回 ``(True, "seal=unregistered")``
|
|
467
|
+
并输出一次性提示,不阻断(兼容路径)。
|
|
468
|
+
"""
|
|
469
|
+
registered = _registered_findings_report_sha256(runtime)
|
|
470
|
+
if registered is None:
|
|
471
|
+
_warn_once_stderr(
|
|
472
|
+
"supervisor state 无 findings sync 内容哈希登记(旧轮 state),"
|
|
473
|
+
"跳过 sync 后篡改比对",
|
|
474
|
+
"findings-seal-unregistered",
|
|
475
|
+
)
|
|
476
|
+
return True, "seal=unregistered"
|
|
477
|
+
actual = hashlib.sha256(report_bytes).hexdigest()
|
|
478
|
+
if actual != registered:
|
|
479
|
+
return False, (
|
|
480
|
+
f"登记 sha256={registered},实际 sha256={actual};"
|
|
481
|
+
"findings 在 sync 后被修改,请重新执行 findings sync 后再结算"
|
|
482
|
+
)
|
|
483
|
+
return True, "seal=ok"
|
|
484
|
+
|
|
485
|
+
|
|
486
|
+
def gate_confirmed_findings(
|
|
487
|
+
runtime: dict, snapshot: FindingsSnapshot | None = None, *,
|
|
488
|
+
snapshot_captured: bool = False,
|
|
489
|
+
allow_incomplete: bool = False,
|
|
490
|
+
) -> tuple[int | None, list[str], str]:
|
|
491
|
+
"""外部门禁裁定的计命数:只认 finding_confirmation gate 终态 confirmed。"""
|
|
492
|
+
try:
|
|
493
|
+
if snapshot is None and not snapshot_captured:
|
|
494
|
+
snapshot = capture_findings_snapshot(runtime)
|
|
495
|
+
except FindingsSnapshotError as exc:
|
|
496
|
+
return None, [], exc.reason_code
|
|
497
|
+
if snapshot is None:
|
|
498
|
+
return 0, [], "no-findings"
|
|
499
|
+
# V2:sync 与 post 之间报告内容完整性绑定——文件哈希必须与 sync 登记
|
|
500
|
+
# 一致,否则 sync 后的改写会无声覆盖宿主已复核的决策。
|
|
501
|
+
seal_ok, seal_note = _verify_findings_report_seal(runtime, snapshot.raw_bytes)
|
|
502
|
+
if not seal_ok:
|
|
503
|
+
return None, [], f"findings 内容完整性校验失败({seal_note})"
|
|
504
|
+
try:
|
|
505
|
+
from core.ledger import finding_confirmation
|
|
506
|
+
except ImportError:
|
|
507
|
+
return None, [], "confirmation_module_unavailable"
|
|
508
|
+
# The snapshot is deeply immutable. The adjudicator intentionally mutates
|
|
509
|
+
# its working view, so it must receive a fully detached mutable tree.
|
|
510
|
+
payload = _deep_thaw(snapshot.payload)
|
|
511
|
+
findings = payload.get("findings")
|
|
512
|
+
if not isinstance(findings, list):
|
|
513
|
+
return None, [], "findings_validation_failed"
|
|
514
|
+
# DOC-188: 程序级自动裁决未终态候选(确定性优先)
|
|
515
|
+
_adjudicate_candidate_findings(
|
|
516
|
+
findings, resolve_project_root(),
|
|
517
|
+
run_id=runtime.get("run_id") or _baseline_run_id(),
|
|
518
|
+
)
|
|
519
|
+
|
|
520
|
+
report = finding_confirmation.gate(payload)
|
|
521
|
+
if not report.get("ready"):
|
|
522
|
+
pending = report.get("pending", "?")
|
|
523
|
+
# 收集未终态候选的详细信息以供宿主 Agent 智能升阶
|
|
524
|
+
pending_ids = [
|
|
525
|
+
str(f.get("id"))
|
|
526
|
+
# F-RSI-20261112-080:`.get("confirmation", {})` 的默认值只在键
|
|
527
|
+
# 缺失时生效——键存在但为 null 时拿到 None,直链 .get 即
|
|
528
|
+
# AttributeError,整个结算门禁以未处理异常形态崩溃(is_confirmed
|
|
529
|
+
# 走 _confirmation 的 isinstance 防御不崩,两处语义漂移)。
|
|
530
|
+
# `or {}` 同时覆盖缺失与 null。
|
|
531
|
+
for f in findings if not finding_confirmation.is_confirmed(f) and (f.get("confirmation") or {}).get("state") != "rejected"
|
|
532
|
+
]
|
|
533
|
+
escalation_note = (
|
|
534
|
+
f"findings 存在 {pending} 个未终态候选({', '.join(pending_ids[:5])}),计命结算被拒:"
|
|
535
|
+
"请由宿主 Agent 基于 failed_findings 进行定点裁决后重跑 post。"
|
|
536
|
+
)
|
|
537
|
+
if not allow_incomplete:
|
|
538
|
+
return None, [], escalation_note
|
|
539
|
+
print(f"[finding-settlement] ℹ --allow-incomplete: {escalation_note}(按 INCOMPLETE 封存,未终态项不计命)")
|
|
540
|
+
lines: list[str] = []
|
|
541
|
+
artifact_rejections: list[str] = []
|
|
542
|
+
for finding in findings:
|
|
543
|
+
if not finding_confirmation.is_confirmed(finding):
|
|
544
|
+
continue
|
|
545
|
+
conf = finding.get("confirmation")
|
|
546
|
+
# F1' V4 硬门 grandfather:confirmations 分两代。
|
|
547
|
+
# - 新代际(confirmation.adjudicator_build 标记,本 build 的程序级
|
|
548
|
+
# 裁决产出):全部 failure 观测必须绑定工件哈希(require_artifacts
|
|
549
|
+
# 让"未声明"也变成错误),缺/错任一环 → 该条回退 candidate 留存
|
|
550
|
+
# (内存降级 + 打印原因),不计命,不是静默丢弃;
|
|
551
|
+
# - 存量(无标记,部署前已封存的 confirmed,如 R7 的 4 条):维持
|
|
552
|
+
# "缺省不罚"豁免,不受追溯——只校验"已声明"的哈希是否属实。
|
|
553
|
+
new_generation = (
|
|
554
|
+
isinstance(conf, dict) and bool(conf.get("adjudicator_build"))
|
|
555
|
+
)
|
|
556
|
+
artifact_errors = _snapshot_observation_artifact_errors(
|
|
557
|
+
finding, snapshot, require_artifacts=new_generation,
|
|
558
|
+
)
|
|
559
|
+
if artifact_errors:
|
|
560
|
+
finding_id = str(
|
|
561
|
+
finding.get("id") or finding.get("fingerprint") or "unknown",
|
|
562
|
+
)
|
|
563
|
+
if new_generation and isinstance(conf, dict):
|
|
564
|
+
# 回退 candidate 留存:findings.json 已被 sync 封章(V2),
|
|
565
|
+
# 不能改写文件;这里在结算视图中降级并记录原因,下一轮
|
|
566
|
+
# 宿主补齐真实工件后可重新走裁决。
|
|
567
|
+
conf["state"] = "candidate"
|
|
568
|
+
conf["decision_reason"] = (
|
|
569
|
+
"V4 新代际工件硬门:确认回退候选 —— "
|
|
570
|
+
+ ";".join(artifact_errors)
|
|
571
|
+
)
|
|
572
|
+
artifact_rejections.append(
|
|
573
|
+
f"{finding_id}: " + ";".join(artifact_errors),
|
|
574
|
+
)
|
|
575
|
+
continue
|
|
576
|
+
lines.append(derive_settle_line(
|
|
577
|
+
finding, evidence_snapshot=snapshot.artifact_snapshot, root=snapshot.root,
|
|
578
|
+
))
|
|
579
|
+
confirmed = len(lines)
|
|
580
|
+
credited = min(confirmed, credited_cap())
|
|
581
|
+
for rejection in artifact_rejections:
|
|
582
|
+
print(f"[finding-settlement] ✗ confirmed 工件复核失败,本条不计命: {rejection}")
|
|
583
|
+
note = f"confirmed={confirmed}"
|
|
584
|
+
if artifact_rejections:
|
|
585
|
+
rejected_ids = ", ".join(
|
|
586
|
+
rejection.split(":", 1)[0] for rejection in artifact_rejections
|
|
587
|
+
)
|
|
588
|
+
note += f", artifact_rejected={len(artifact_rejections)}({rejected_ids})"
|
|
589
|
+
if seal_note != "seal=ok":
|
|
590
|
+
note += f", {seal_note}"
|
|
591
|
+
return credited, lines, note
|
|
592
|
+
|
|
593
|
+
|
|
594
|
+
def _snapshot_observation_artifact_errors(
|
|
595
|
+
finding: Mapping[str, Any], snapshot: FindingsSnapshot, *, require_artifacts: bool,
|
|
596
|
+
) -> list[str]:
|
|
597
|
+
"""Check declared confirmation artifact references without reopening files."""
|
|
598
|
+
confirmation = finding.get("confirmation")
|
|
599
|
+
if not isinstance(confirmation, Mapping):
|
|
600
|
+
return ["confirmation 缺失"]
|
|
601
|
+
observations = confirmation.get("observations")
|
|
602
|
+
if not isinstance(observations, list):
|
|
603
|
+
return ["observations 无效"]
|
|
604
|
+
from core.ledger.finding_io import snapshot_relative_path
|
|
605
|
+
|
|
606
|
+
errors: list[str] = []
|
|
607
|
+
for index, item in enumerate(observations, 1):
|
|
608
|
+
if not isinstance(item, Mapping):
|
|
609
|
+
errors.append(f"observation #{index} 无效")
|
|
610
|
+
continue
|
|
611
|
+
artifact_path = item.get("artifact_path")
|
|
612
|
+
artifact_hash = item.get("artifact_sha256")
|
|
613
|
+
required = require_artifacts and item.get("outcome") == "failure"
|
|
614
|
+
if not isinstance(artifact_path, str) or not artifact_path.strip():
|
|
615
|
+
if required:
|
|
616
|
+
errors.append(f"observation #{index} 新代际 confirmed 缺工件哈希绑定")
|
|
617
|
+
continue
|
|
618
|
+
try:
|
|
619
|
+
normalized = snapshot_relative_path(artifact_path, snapshot.root)
|
|
620
|
+
except Exception:
|
|
621
|
+
errors.append(f"observation #{index} artifact_path 无效")
|
|
622
|
+
continue
|
|
623
|
+
metadata = snapshot.artifact_snapshot.get(normalized)
|
|
624
|
+
if not isinstance(metadata, Mapping):
|
|
625
|
+
errors.append(f"observation #{index} artifact 快照缺失")
|
|
626
|
+
continue
|
|
627
|
+
if isinstance(artifact_hash, str) and metadata.get("sha256") == artifact_hash.lower():
|
|
628
|
+
continue
|
|
629
|
+
if required or artifact_hash is not None:
|
|
630
|
+
errors.append(f"observation #{index} artifact hash 不匹配")
|
|
631
|
+
negative = confirmation.get("negative_control")
|
|
632
|
+
if isinstance(negative, Mapping) and negative.get("artifact_path") is not None:
|
|
633
|
+
try:
|
|
634
|
+
normalized = snapshot_relative_path(negative.get("artifact_path"), snapshot.root)
|
|
635
|
+
except Exception:
|
|
636
|
+
errors.append("negative_control artifact_path 无效")
|
|
637
|
+
else:
|
|
638
|
+
metadata = snapshot.artifact_snapshot.get(normalized)
|
|
639
|
+
artifact_hash = negative.get("artifact_sha256")
|
|
640
|
+
if not isinstance(metadata, Mapping):
|
|
641
|
+
errors.append("negative_control artifact 快照缺失")
|
|
642
|
+
elif artifact_hash is not None and (
|
|
643
|
+
not isinstance(artifact_hash, str)
|
|
644
|
+
or metadata.get("sha256") != artifact_hash.lower()
|
|
645
|
+
):
|
|
646
|
+
errors.append("negative_control artifact hash 不匹配")
|
|
647
|
+
return errors
|
|
648
|
+
|
|
649
|
+
|
|
650
|
+
|
|
651
|
+
# F1':裁决器版本标记来源。core/metadata.txt 的 build_id 随引擎一起部署,
|
|
652
|
+
# 读不到时用 "unknown" 占位——标记的**在场**比取值更重要(V4 grandfather
|
|
653
|
+
# 以在场区分新代际),取值用于取证定位构建。
|
|
654
|
+
_ADJUDICATOR_BUILD_CACHE: str | None = None
|
|
655
|
+
# 与 supervisor_models.VALID_EVIDENCE_STATES 对齐的本地副本(避免结算侧
|
|
656
|
+
# 拉起整个 supervisor 模型层)。
|
|
657
|
+
_RECEIPT_STATUSES = frozenset({"passed", "failed", "error", "blocked", "skipped"})
|
|
658
|
+
_RECEIPT_FAILURE_STATUSES = frozenset({"failed", "error"})
|
|
659
|
+
_RECEIPT_REQUIRED_FIELDS = (
|
|
660
|
+
"execution_id", "lease_id", "worker_id", "artifact_path",
|
|
661
|
+
"artifact_sha256", "command", "status",
|
|
662
|
+
)
|
|
663
|
+
from core.launch_phases.findings_adjudication import (
|
|
664
|
+
adjudicate_candidate_findings,
|
|
665
|
+
adjudicator_build,
|
|
666
|
+
artifact_matches,
|
|
667
|
+
build_receipt_backed_confirmation,
|
|
668
|
+
compact_title,
|
|
669
|
+
has_fully_bound_failure_observations,
|
|
670
|
+
ledger_supervisor_state_paths,
|
|
671
|
+
load_claim_ledger,
|
|
672
|
+
load_evidence_store_records,
|
|
673
|
+
lookup_receipt_claim,
|
|
674
|
+
receipt_observation,
|
|
675
|
+
valid_evidence_receipt,
|
|
676
|
+
verify_ledger_incident_receipt,
|
|
677
|
+
)
|
|
678
|
+
|
|
679
|
+
# Compatibility aliases
|
|
680
|
+
_MAX_LEDGER_SCANS = 64
|
|
681
|
+
_SHA64_RE = re.compile(r"^[0-9a-fA-F]{64}$")
|
|
682
|
+
_adjudicator_build = adjudicator_build
|
|
683
|
+
_valid_evidence_receipt = valid_evidence_receipt
|
|
684
|
+
_load_claim_ledger = load_claim_ledger
|
|
685
|
+
_lookup_receipt_claim = lookup_receipt_claim
|
|
686
|
+
_load_evidence_store_records = load_evidence_store_records
|
|
687
|
+
_artifact_matches = artifact_matches
|
|
688
|
+
_ledger_supervisor_state_paths = ledger_supervisor_state_paths
|
|
689
|
+
_receipt_observation = receipt_observation
|
|
690
|
+
_has_fully_bound_failure_observations = has_fully_bound_failure_observations
|
|
691
|
+
_build_receipt_backed_confirmation = build_receipt_backed_confirmation
|
|
692
|
+
_adjudicate_candidate_findings = adjudicate_candidate_findings
|
|
693
|
+
_compact_title = compact_title
|
|
694
|
+
|
|
695
|
+
def derive_settle_line(
|
|
696
|
+
finding: dict, *, evidence_snapshot: Mapping[str, Mapping[str, Any]], root: Path,
|
|
697
|
+
) -> str:
|
|
698
|
+
"""派生 settle 引用;路径和行号必须来自已验证的 no-follow 快照。"""
|
|
699
|
+
severity = str(finding.get("severity", "MEDIUM")).upper()
|
|
700
|
+
title = _compact_title(str(finding.get("title", "")).strip())
|
|
701
|
+
reference = ""
|
|
702
|
+
from core.ledger.finding_io import snapshot_relative_path
|
|
703
|
+
for item in finding.get("evidence") or []:
|
|
704
|
+
if not isinstance(item, dict) or not isinstance(item.get("path"), str):
|
|
705
|
+
continue
|
|
706
|
+
try:
|
|
707
|
+
relative = snapshot_relative_path(item["path"], root)
|
|
708
|
+
except Exception:
|
|
709
|
+
continue
|
|
710
|
+
metadata = evidence_snapshot.get(relative)
|
|
711
|
+
if not isinstance(metadata, Mapping):
|
|
712
|
+
continue
|
|
713
|
+
line_no = item.get("line")
|
|
714
|
+
if not isinstance(line_no, int) or isinstance(line_no, bool):
|
|
715
|
+
line_no = 1
|
|
716
|
+
line_count = metadata.get("line_count")
|
|
717
|
+
if not isinstance(line_count, int) or isinstance(line_count, bool) or line_no > line_count:
|
|
718
|
+
continue
|
|
719
|
+
reference = f"{relative}:{line_no}"
|
|
720
|
+
break
|
|
721
|
+
# settle 行是行导向文件(verify_life evidence_bad_lines 逐行校验证据),
|
|
722
|
+
# 多行 reproduction 原样内嵌会把一行撕成多行物理行,续行被判为
|
|
723
|
+
# 「无证据编造」拒结算(2026-11-08 实测 sys.path.insert 续行被拒)。
|
|
724
|
+
reproduction = " ".join(str(finding.get("reproduction") or "N/A").split())[:120]
|
|
725
|
+
observation = " ".join(str(finding.get("root_cause") or "").split())[:80]
|
|
726
|
+
return f"[{severity}] {title}。{reference}。复现:{reproduction}。观察:{observation}"
|
|
727
|
+
|
|
728
|
+
|
|
729
|
+
def auto_mode(runtime: dict) -> bool:
|
|
730
|
+
"""作战方案 auto 轮询时,结算允许自动生成 findings.json 骨架。"""
|
|
731
|
+
if runtime.get("polling_policy") == "auto":
|
|
732
|
+
return True
|
|
733
|
+
try:
|
|
734
|
+
manifest = _lifecycle_findings_path(runtime)
|
|
735
|
+
payload = json.loads(
|
|
736
|
+
(manifest.parent / "runtime.json").read_text(encoding="utf-8"),
|
|
737
|
+
)
|
|
738
|
+
return payload.get("polling_policy") == "auto"
|
|
739
|
+
except (OSError, ValueError):
|
|
740
|
+
return False
|
|
741
|
+
|
|
742
|
+
|
|
743
|
+
_TOKEN_FIELDS = ("total_tokens", "tokens_consumed", "token_count", "tokens")
|
|
744
|
+
_TOKEN_COMPONENT_FIELDS = (
|
|
745
|
+
("prompt_tokens", "completion_tokens"),
|
|
746
|
+
("input_tokens", "output_tokens"),
|
|
747
|
+
)
|
|
748
|
+
_TOKEN_COLLECTIONS = (
|
|
749
|
+
"leases", "workers", "by_lease", "token_accounting", "claims", "executions", "records",
|
|
750
|
+
)
|
|
751
|
+
|
|
752
|
+
|
|
753
|
+
def _token_number(value: object) -> int | None:
|
|
754
|
+
"""Return a safe non-negative integer token count, or ``None``."""
|
|
755
|
+
if isinstance(value, bool) or not isinstance(value, (int, float)):
|
|
756
|
+
return None
|
|
757
|
+
if not math.isfinite(float(value)) or value < 0:
|
|
758
|
+
return None
|
|
759
|
+
return int(value)
|
|
760
|
+
|
|
761
|
+
|
|
762
|
+
def _sum_token_records(value: object) -> int:
|
|
763
|
+
"""Read aggregate or per-lease token records without double counting.
|
|
764
|
+
|
|
765
|
+
Supervisor snapshots have existed with both an aggregate field and a
|
|
766
|
+
per-lease mapping. Once an aggregate is present it is authoritative for
|
|
767
|
+
that subtree; otherwise nested records are summed.
|
|
768
|
+
|
|
769
|
+
契约(F-RSI-20261112-082 取证固化,2026-11-12):``_TOKEN_COLLECTIONS``
|
|
770
|
+
命中后只消费该子树(丢弃兄弟键)——这在当前真实 schema 链上不可达:
|
|
771
|
+
RunState.to_dict 顶层不经本函数(``_supervisor_token_total`` 显式分层),
|
|
772
|
+
claims dict 的键是 worker_id,claim/unit 记录必先命中 _TOKEN_FIELDS 的
|
|
773
|
+
``tokens_consumed`` 聚合字段。若未来新增「collection 键与 token 携带键
|
|
774
|
+
并存」的写入形态,必须同步扩展 ``_supervisor_token_total`` 的分层或把
|
|
775
|
+
兄弟键并入求和,否则兄弟 token 会被静默丢弃。
|
|
776
|
+
"""
|
|
777
|
+
if isinstance(value, Mapping):
|
|
778
|
+
for key in _TOKEN_FIELDS:
|
|
779
|
+
number = _token_number(value.get(key))
|
|
780
|
+
if number is not None:
|
|
781
|
+
return number
|
|
782
|
+
for input_key, output_key in _TOKEN_COMPONENT_FIELDS:
|
|
783
|
+
input_tokens = _token_number(value.get(input_key))
|
|
784
|
+
output_tokens = _token_number(value.get(output_key))
|
|
785
|
+
if input_tokens is not None or output_tokens is not None:
|
|
786
|
+
return (input_tokens or 0) + (output_tokens or 0)
|
|
787
|
+
for key in _TOKEN_COLLECTIONS:
|
|
788
|
+
if key in value:
|
|
789
|
+
return _sum_token_records(value[key])
|
|
790
|
+
numbers = [_token_number(item) for item in value.values()]
|
|
791
|
+
if numbers and all(item is not None for item in numbers):
|
|
792
|
+
return sum(item for item in numbers if item is not None)
|
|
793
|
+
return sum(_sum_token_records(item) for item in value.values())
|
|
794
|
+
if isinstance(value, (list, tuple)):
|
|
795
|
+
return sum(_sum_token_records(item) for item in value)
|
|
796
|
+
number = _token_number(value)
|
|
797
|
+
return number or 0
|
|
798
|
+
|
|
799
|
+
|
|
800
|
+
def _supervisor_token_total(payload: Mapping[str, Any]) -> int:
|
|
801
|
+
"""Get the complete Worker lease token total from a Supervisor snapshot.
|
|
802
|
+
|
|
803
|
+
``execution_metrics`` is the preferred full-run ledger, followed by the
|
|
804
|
+
per-lease ``claims`` and the cumulative ``tokens_consumed`` field. The
|
|
805
|
+
DOC-196 ``token_accounting`` map is only a last fallback because older
|
|
806
|
+
writers keyed it by unit and therefore may repeat one lease's cost for a
|
|
807
|
+
bundled claim.
|
|
808
|
+
"""
|
|
809
|
+
if "execution_metrics" in payload:
|
|
810
|
+
execution_total = _sum_token_records(payload.get("execution_metrics"))
|
|
811
|
+
if execution_total > 0:
|
|
812
|
+
return execution_total
|
|
813
|
+
if "claims" in payload:
|
|
814
|
+
claim_total = _sum_token_records(payload.get("claims"))
|
|
815
|
+
if claim_total > 0:
|
|
816
|
+
return claim_total
|
|
817
|
+
top_level = _token_number(payload.get("tokens_consumed"))
|
|
818
|
+
if top_level is not None:
|
|
819
|
+
return top_level
|
|
820
|
+
return (
|
|
821
|
+
_sum_token_records(payload.get("token_accounting"))
|
|
822
|
+
if "token_accounting" in payload else 0
|
|
823
|
+
)
|
|
824
|
+
|
|
825
|
+
|
|
826
|
+
def _read_json_object(path: Path) -> dict[str, Any] | None:
|
|
827
|
+
try:
|
|
828
|
+
value = json.loads(path.read_text(encoding="utf-8"))
|
|
829
|
+
except (OSError, ValueError, UnicodeDecodeError):
|
|
830
|
+
return None
|
|
831
|
+
return value if isinstance(value, dict) else None
|
|
832
|
+
|
|
833
|
+
|
|
834
|
+
def _absolute_reader_path(path: Path, project_root: Path, project_reader: Any) -> tuple[Any, str, bool]:
|
|
835
|
+
"""Map an absolute state path to a bounded no-follow reader and relative name."""
|
|
836
|
+
candidate = Path(os.path.abspath(os.fspath(path)))
|
|
837
|
+
try:
|
|
838
|
+
relative = candidate.relative_to(project_root).as_posix()
|
|
839
|
+
return project_reader, relative, False
|
|
840
|
+
except ValueError:
|
|
841
|
+
anchor = Path(candidate.anchor)
|
|
842
|
+
try:
|
|
843
|
+
relative = candidate.relative_to(anchor).as_posix()
|
|
844
|
+
except ValueError:
|
|
845
|
+
raise FindingsSnapshotError("supervisor_state_path_invalid") from None
|
|
846
|
+
try:
|
|
847
|
+
from core.launch_phases.post_dry_run import RootReader
|
|
848
|
+
reader = RootReader(anchor)
|
|
849
|
+
except Exception:
|
|
850
|
+
raise FindingsSnapshotError("supervisor_state_unavailable_or_unsafe") from None
|
|
851
|
+
return reader, relative, True
|
|
852
|
+
|
|
853
|
+
|
|
854
|
+
def _read_supervisor_state(reader: Any, relative: str) -> dict[str, Any]:
|
|
855
|
+
from core.launch_phases.post_dry_run import JSON_LIMIT, SnapshotInvalid, verify_supervisor_history
|
|
856
|
+
|
|
857
|
+
try:
|
|
858
|
+
source = reader.read(relative, JSON_LIMIT, "supervisor")
|
|
859
|
+
payload = json.loads(source.raw_bytes.decode("utf-8"))
|
|
860
|
+
except SnapshotInvalid as exc:
|
|
861
|
+
raise FindingsSnapshotError(exc.reason_code) from None
|
|
862
|
+
except (OSError, UnicodeError, ValueError, TypeError, RecursionError):
|
|
863
|
+
raise FindingsSnapshotError("supervisor_state_invalid") from None
|
|
864
|
+
if not isinstance(payload, dict):
|
|
865
|
+
raise FindingsSnapshotError("supervisor_state_invalid")
|
|
866
|
+
revision = payload.get("revision")
|
|
867
|
+
run_id = payload.get("run_id")
|
|
868
|
+
round_id = payload.get("round_id")
|
|
869
|
+
session_id = payload.get("session_id")
|
|
870
|
+
if (
|
|
871
|
+
not isinstance(run_id, str) or not run_id.strip()
|
|
872
|
+
or not isinstance(round_id, str) or not round_id.strip()
|
|
873
|
+
or (session_id is not None and (not isinstance(session_id, str) or not session_id.strip()))
|
|
874
|
+
or isinstance(revision, bool) or not isinstance(revision, int) or revision < 0
|
|
875
|
+
or not isinstance(payload.get("audit_head"), str)
|
|
876
|
+
or not verify_supervisor_history(payload)
|
|
877
|
+
):
|
|
878
|
+
raise FindingsSnapshotError("supervisor_state_invalid")
|
|
879
|
+
return payload
|
|
880
|
+
|
|
881
|
+
|
|
882
|
+
def _optional_project_file(reader: Any, relative: str) -> bool:
|
|
883
|
+
"""Check an optional mirror path without following any component."""
|
|
884
|
+
parts = relative.split("/")
|
|
885
|
+
if not parts or any(part in {"", ".", ".."} or "\\" in part for part in parts):
|
|
886
|
+
raise FindingsSnapshotError("supervisor_mirror_path_invalid")
|
|
887
|
+
parent = os.dup(reader.fd)
|
|
888
|
+
flags = os.O_RDONLY | getattr(os, "O_DIRECTORY", 0) | getattr(os, "O_NOFOLLOW", 0)
|
|
889
|
+
try:
|
|
890
|
+
for part in parts[:-1]:
|
|
891
|
+
try:
|
|
892
|
+
child = os.open(part, flags, dir_fd=parent)
|
|
893
|
+
except FileNotFoundError:
|
|
894
|
+
return False
|
|
895
|
+
except OSError:
|
|
896
|
+
raise FindingsSnapshotError("supervisor_mirror_unavailable_or_unsafe") from None
|
|
897
|
+
os.close(parent)
|
|
898
|
+
parent = child
|
|
899
|
+
try:
|
|
900
|
+
item = os.stat(parts[-1], dir_fd=parent, follow_symlinks=False)
|
|
901
|
+
except FileNotFoundError:
|
|
902
|
+
return False
|
|
903
|
+
except OSError:
|
|
904
|
+
raise FindingsSnapshotError("supervisor_mirror_unavailable_or_unsafe") from None
|
|
905
|
+
if stat.S_ISLNK(item.st_mode) or not stat.S_ISREG(item.st_mode):
|
|
906
|
+
raise FindingsSnapshotError("supervisor_mirror_unavailable_or_unsafe")
|
|
907
|
+
return True
|
|
908
|
+
finally:
|
|
909
|
+
os.close(parent)
|
|
910
|
+
|
|
911
|
+
|
|
912
|
+
def _supervisor_state_identity(payload: Mapping[str, Any]) -> tuple[Any, ...]:
|
|
913
|
+
"""Fields that must be identical between the authority and any state mirror."""
|
|
914
|
+
history = payload.get("history")
|
|
915
|
+
if not isinstance(history, list):
|
|
916
|
+
raise FindingsSnapshotError("supervisor_state_invalid")
|
|
917
|
+
base_seq = payload.get("history_base_seq", 1)
|
|
918
|
+
base_hash = payload.get("history_base_hash", "")
|
|
919
|
+
head_event = history[-1] if history else None
|
|
920
|
+
head_seq = head_event.get("seq") if isinstance(head_event, Mapping) else base_seq - 1
|
|
921
|
+
head_hash = head_event.get("hash") if isinstance(head_event, Mapping) else base_hash
|
|
922
|
+
return (
|
|
923
|
+
payload.get("run_id"), payload.get("session_id"), payload.get("round_id"),
|
|
924
|
+
payload.get("revision"), base_seq, base_hash, head_seq, head_hash,
|
|
925
|
+
payload.get("audit_head"),
|
|
926
|
+
)
|
|
927
|
+
|
|
928
|
+
|
|
929
|
+
def _verify_auto_supervisor_identity(
|
|
930
|
+
state: Mapping[str, Any], runtime: Mapping[str, Any],
|
|
931
|
+
) -> None:
|
|
932
|
+
lifecycle_id = runtime.get("lifecycle_id")
|
|
933
|
+
runtime_run_id = runtime.get("run_id")
|
|
934
|
+
polling_id = runtime.get("polling_id")
|
|
935
|
+
allowed_run_ids = {runtime_run_id} if isinstance(runtime_run_id, str) else set()
|
|
936
|
+
if isinstance(polling_id, str) and polling_id.strip():
|
|
937
|
+
allowed_run_ids.update({
|
|
938
|
+
f"{polling_id}-{lifecycle_id}",
|
|
939
|
+
f"lifecycle-{polling_id}-{lifecycle_id}",
|
|
940
|
+
})
|
|
941
|
+
if state.get("session_id") != polling_id:
|
|
942
|
+
raise FindingsSnapshotError("supervisor_state_identity_mismatch")
|
|
943
|
+
else:
|
|
944
|
+
allowed_run_ids.add(f"lifecycle-{lifecycle_id}")
|
|
945
|
+
# 扁平(非项目)布局没有 polling 命名空间:Supervisor 的 run_id 由
|
|
946
|
+
# session_runtime 写入的 `session_id` 派生(polling_id 缺失时该字段回落为
|
|
947
|
+
# 占位值,见 session_runtime._start_or_resume_session)。这里必须按**同一**
|
|
948
|
+
# session_id 校验,否则扁平布局下 Supervisor 身份永远无法匹配
|
|
949
|
+
# (实测 4 个 post 用例命中 supervisor_state_identity_mismatch)。
|
|
950
|
+
session_id = runtime.get("session_id")
|
|
951
|
+
if isinstance(session_id, str) and session_id.strip():
|
|
952
|
+
allowed_run_ids.add(f"lifecycle-{session_id}-{lifecycle_id}")
|
|
953
|
+
state_session = state.get("session_id")
|
|
954
|
+
if state_session is not None and state_session != session_id:
|
|
955
|
+
raise FindingsSnapshotError("supervisor_state_identity_mismatch")
|
|
956
|
+
if (
|
|
957
|
+
state.get("run_id") not in allowed_run_ids
|
|
958
|
+
or state.get("round_id") != lifecycle_id
|
|
959
|
+
):
|
|
960
|
+
raise FindingsSnapshotError("supervisor_state_identity_mismatch")
|
|
961
|
+
|
|
962
|
+
|
|
963
|
+
def _load_authoritative_supervisor(
|
|
964
|
+
runtime: Mapping[str, Any], root: Path, project_reader: Any,
|
|
965
|
+
) -> tuple[dict[str, Any] | None, Any | None, bool]:
|
|
966
|
+
"""Load the sole configured Supervisor authority and verify present mirrors."""
|
|
967
|
+
from core.launch_phases.post_dry_run import SnapshotInvalid
|
|
968
|
+
|
|
969
|
+
authority_path = Path(os.path.abspath(os.fspath(supervisor_state_path())))
|
|
970
|
+
authority_reader, authority_relative, close_authority = _absolute_reader_path(
|
|
971
|
+
authority_path, root, project_reader,
|
|
972
|
+
)
|
|
973
|
+
try:
|
|
974
|
+
try:
|
|
975
|
+
if not authority_reader.exists(authority_relative):
|
|
976
|
+
return None, authority_reader, close_authority
|
|
977
|
+
except SnapshotInvalid as exc:
|
|
978
|
+
raise FindingsSnapshotError(exc.reason_code) from None
|
|
979
|
+
authority = _read_supervisor_state(authority_reader, authority_relative)
|
|
980
|
+
_verify_auto_supervisor_identity(authority, runtime)
|
|
981
|
+
authority_identity = _supervisor_state_identity(authority)
|
|
982
|
+
|
|
983
|
+
for candidate in _supervisor_state_candidates(dict(runtime)):
|
|
984
|
+
candidate = Path(os.path.abspath(os.fspath(candidate)))
|
|
985
|
+
if candidate == authority_path:
|
|
986
|
+
continue
|
|
987
|
+
try:
|
|
988
|
+
relative = candidate.relative_to(root).as_posix()
|
|
989
|
+
if not _optional_project_file(project_reader, relative):
|
|
990
|
+
continue
|
|
991
|
+
mirror = _read_supervisor_state(project_reader, relative)
|
|
992
|
+
except FindingsSnapshotError:
|
|
993
|
+
raise
|
|
994
|
+
except SnapshotInvalid as exc:
|
|
995
|
+
raise FindingsSnapshotError(exc.reason_code) from None
|
|
996
|
+
except ValueError:
|
|
997
|
+
raise FindingsSnapshotError("supervisor_mirror_path_invalid") from None
|
|
998
|
+
if _supervisor_state_identity(mirror) != authority_identity:
|
|
999
|
+
raise FindingsSnapshotError("supervisor_mirror_mismatch")
|
|
1000
|
+
return authority, authority_reader, close_authority
|
|
1001
|
+
except BaseException:
|
|
1002
|
+
if close_authority:
|
|
1003
|
+
authority_reader.close()
|
|
1004
|
+
raise
|
|
1005
|
+
|
|
1006
|
+
|
|
1007
|
+
def _open_output_parent(root: Path, relative: str) -> tuple[int, str]:
|
|
1008
|
+
"""Open an output's parent through no-follow directory descriptors."""
|
|
1009
|
+
parts = relative.split("/")
|
|
1010
|
+
if not parts or any(part in {"", ".", ".."} or "\\" in part for part in parts):
|
|
1011
|
+
raise FindingsSnapshotError("findings_output_path_invalid")
|
|
1012
|
+
flags = os.O_RDONLY | getattr(os, "O_DIRECTORY", 0) | getattr(os, "O_NOFOLLOW", 0)
|
|
1013
|
+
try:
|
|
1014
|
+
parent_fd = os.open(root, flags)
|
|
1015
|
+
except OSError:
|
|
1016
|
+
raise FindingsSnapshotError("findings_output_unavailable_or_unsafe") from None
|
|
1017
|
+
try:
|
|
1018
|
+
for part in parts[:-1]:
|
|
1019
|
+
child_fd = os.open(part, flags, dir_fd=parent_fd)
|
|
1020
|
+
os.close(parent_fd)
|
|
1021
|
+
parent_fd = child_fd
|
|
1022
|
+
return parent_fd, parts[-1]
|
|
1023
|
+
except OSError:
|
|
1024
|
+
os.close(parent_fd)
|
|
1025
|
+
raise FindingsSnapshotError("findings_output_unavailable_or_unsafe") from None
|
|
1026
|
+
|
|
1027
|
+
|
|
1028
|
+
def _read_at_no_follow(parent_fd: int, name: str, limit: int) -> bytes:
|
|
1029
|
+
flags = os.O_RDONLY | getattr(os, "O_NOFOLLOW", 0)
|
|
1030
|
+
try:
|
|
1031
|
+
fd = os.open(name, flags, dir_fd=parent_fd)
|
|
1032
|
+
except OSError:
|
|
1033
|
+
raise FindingsSnapshotError("findings_output_unsafe") from None
|
|
1034
|
+
try:
|
|
1035
|
+
before = os.fstat(fd)
|
|
1036
|
+
if not stat.S_ISREG(before.st_mode) or before.st_size > limit:
|
|
1037
|
+
raise FindingsSnapshotError("findings_output_unsafe")
|
|
1038
|
+
chunks: list[bytes] = []
|
|
1039
|
+
total = 0
|
|
1040
|
+
while True:
|
|
1041
|
+
chunk = os.read(fd, min(1024 * 1024, limit + 1 - total))
|
|
1042
|
+
if not chunk:
|
|
1043
|
+
break
|
|
1044
|
+
chunks.append(chunk)
|
|
1045
|
+
total += len(chunk)
|
|
1046
|
+
if total > limit:
|
|
1047
|
+
raise FindingsSnapshotError("findings_output_unsafe")
|
|
1048
|
+
after = os.fstat(fd)
|
|
1049
|
+
if (before.st_dev, before.st_ino, before.st_size, before.st_mtime_ns) != (
|
|
1050
|
+
after.st_dev, after.st_ino, after.st_size, after.st_mtime_ns,
|
|
1051
|
+
) or total != after.st_size:
|
|
1052
|
+
raise FindingsSnapshotError("findings_output_changed_during_read")
|
|
1053
|
+
return b"".join(chunks)
|
|
1054
|
+
finally:
|
|
1055
|
+
os.close(fd)
|
|
1056
|
+
|
|
1057
|
+
|
|
1058
|
+
def _rename_noreplace(parent_fd: int, source: str, target: str) -> None:
|
|
1059
|
+
"""Atomically publish a temp file without replacing an existing report."""
|
|
1060
|
+
libc = ctypes.CDLL(None, use_errno=True)
|
|
1061
|
+
source_bytes = os.fsencode(source)
|
|
1062
|
+
target_bytes = os.fsencode(target)
|
|
1063
|
+
if hasattr(libc, "renameat2"):
|
|
1064
|
+
rename = libc.renameat2
|
|
1065
|
+
rename.argtypes = [ctypes.c_int, ctypes.c_char_p, ctypes.c_int, ctypes.c_char_p, ctypes.c_uint]
|
|
1066
|
+
rename.restype = ctypes.c_int
|
|
1067
|
+
result = rename(parent_fd, source_bytes, parent_fd, target_bytes, 1) # RENAME_NOREPLACE
|
|
1068
|
+
if result == 0:
|
|
1069
|
+
return
|
|
1070
|
+
error = ctypes.get_errno()
|
|
1071
|
+
if error == errno.EEXIST:
|
|
1072
|
+
raise FileExistsError(error, os.strerror(error), target)
|
|
1073
|
+
if error not in {errno.ENOSYS, errno.EINVAL, getattr(errno, "EOPNOTSUPP", errno.EINVAL)}:
|
|
1074
|
+
raise OSError(error, os.strerror(error), target)
|
|
1075
|
+
elif hasattr(libc, "renameatx_np"):
|
|
1076
|
+
rename = libc.renameatx_np
|
|
1077
|
+
rename.argtypes = [ctypes.c_int, ctypes.c_char_p, ctypes.c_int, ctypes.c_char_p, ctypes.c_uint]
|
|
1078
|
+
rename.restype = ctypes.c_int
|
|
1079
|
+
result = rename(parent_fd, source_bytes, parent_fd, target_bytes, 0x00000004) # RENAME_EXCL
|
|
1080
|
+
if result == 0:
|
|
1081
|
+
return
|
|
1082
|
+
error = ctypes.get_errno()
|
|
1083
|
+
if error == errno.EEXIST:
|
|
1084
|
+
raise FileExistsError(error, os.strerror(error), target)
|
|
1085
|
+
if error not in {errno.ENOSYS, errno.EINVAL, getattr(errno, "EOPNOTSUPP", errno.EINVAL)}:
|
|
1086
|
+
raise OSError(error, os.strerror(error), target)
|
|
1087
|
+
# Portable same-directory fallback still publishes atomically and cannot
|
|
1088
|
+
# replace a raced-in destination; link/unlink has the same durable outcome.
|
|
1089
|
+
os.link(source, target, src_dir_fd=parent_fd, dst_dir_fd=parent_fd, follow_symlinks=False)
|
|
1090
|
+
os.unlink(source, dir_fd=parent_fd)
|
|
1091
|
+
|
|
1092
|
+
|
|
1093
|
+
def _write_findings_atomic_no_replace(path: Path, root: Path, raw_report: bytes) -> bool:
|
|
1094
|
+
"""Write a report through dir_fd/no-follow, idempotently only by exact hash."""
|
|
1095
|
+
from core.launch_phases.post_dry_run import FINDINGS_LIMIT
|
|
1096
|
+
|
|
1097
|
+
if len(raw_report) > FINDINGS_LIMIT:
|
|
1098
|
+
raise FindingsSnapshotError("findings_size_limit")
|
|
1099
|
+
candidate = Path(os.path.abspath(os.fspath(path)))
|
|
1100
|
+
try:
|
|
1101
|
+
relative = candidate.relative_to(root).as_posix()
|
|
1102
|
+
except ValueError:
|
|
1103
|
+
raise FindingsSnapshotError("findings_outside_project_root") from None
|
|
1104
|
+
parent_fd, name = _open_output_parent(root, relative)
|
|
1105
|
+
temp_name: str | None = None
|
|
1106
|
+
temp_fd: int | None = None
|
|
1107
|
+
expected_hash = hashlib.sha256(raw_report).hexdigest()
|
|
1108
|
+
try:
|
|
1109
|
+
try:
|
|
1110
|
+
existing_stat = os.stat(name, dir_fd=parent_fd, follow_symlinks=False)
|
|
1111
|
+
except FileNotFoundError:
|
|
1112
|
+
existing_stat = None
|
|
1113
|
+
except OSError:
|
|
1114
|
+
raise FindingsSnapshotError("findings_output_unsafe") from None
|
|
1115
|
+
if existing_stat is not None:
|
|
1116
|
+
if not stat.S_ISREG(existing_stat.st_mode):
|
|
1117
|
+
raise FindingsSnapshotError("findings_output_unsafe")
|
|
1118
|
+
existing = _read_at_no_follow(parent_fd, name, FINDINGS_LIMIT)
|
|
1119
|
+
if hashlib.sha256(existing).hexdigest() == expected_hash:
|
|
1120
|
+
return False
|
|
1121
|
+
raise FindingsSnapshotError("findings_output_conflict")
|
|
1122
|
+
|
|
1123
|
+
flags = os.O_WRONLY | os.O_CREAT | os.O_EXCL | getattr(os, "O_NOFOLLOW", 0)
|
|
1124
|
+
for _attempt in range(5):
|
|
1125
|
+
temp_name = f".{name}.{os.urandom(12).hex()}.tmp"
|
|
1126
|
+
try:
|
|
1127
|
+
temp_fd = os.open(temp_name, flags, 0o600, dir_fd=parent_fd)
|
|
1128
|
+
break
|
|
1129
|
+
except FileExistsError:
|
|
1130
|
+
temp_name = None
|
|
1131
|
+
if temp_fd is None or temp_name is None:
|
|
1132
|
+
raise FindingsSnapshotError("findings_temp_create_failed")
|
|
1133
|
+
offset = 0
|
|
1134
|
+
while offset < len(raw_report):
|
|
1135
|
+
written = os.write(temp_fd, raw_report[offset:])
|
|
1136
|
+
if written <= 0:
|
|
1137
|
+
raise FindingsSnapshotError("findings_output_write_failed")
|
|
1138
|
+
offset += written
|
|
1139
|
+
os.fsync(temp_fd)
|
|
1140
|
+
os.close(temp_fd)
|
|
1141
|
+
temp_fd = None
|
|
1142
|
+
try:
|
|
1143
|
+
_rename_noreplace(parent_fd, temp_name, name)
|
|
1144
|
+
temp_name = None
|
|
1145
|
+
except FileExistsError:
|
|
1146
|
+
existing = _read_at_no_follow(parent_fd, name, FINDINGS_LIMIT)
|
|
1147
|
+
if hashlib.sha256(existing).hexdigest() == expected_hash:
|
|
1148
|
+
return False
|
|
1149
|
+
raise FindingsSnapshotError("findings_output_conflict") from None
|
|
1150
|
+
os.fsync(parent_fd)
|
|
1151
|
+
return True
|
|
1152
|
+
except FindingsSnapshotError:
|
|
1153
|
+
raise
|
|
1154
|
+
except OSError:
|
|
1155
|
+
raise FindingsSnapshotError("findings_output_write_failed") from None
|
|
1156
|
+
finally:
|
|
1157
|
+
if temp_fd is not None:
|
|
1158
|
+
os.close(temp_fd)
|
|
1159
|
+
if temp_name is not None:
|
|
1160
|
+
try:
|
|
1161
|
+
os.unlink(temp_name, dir_fd=parent_fd)
|
|
1162
|
+
except OSError:
|
|
1163
|
+
pass
|
|
1164
|
+
os.close(parent_fd)
|
|
1165
|
+
|
|
1166
|
+
|
|
1167
|
+
def auto_build_findings_json(runtime: dict) -> str | None:
|
|
1168
|
+
"""auto 模式:从 supervisor findings 自动生成结算 findings.json。
|
|
1169
|
+
|
|
1170
|
+
携带合法 confirmation 块的 finding 计入 confirmed;其余诚实保持
|
|
1171
|
+
candidate(不写 confirmation 块),确认工作由后续 Life 继续。
|
|
1172
|
+
"""
|
|
1173
|
+
runtime_snapshot = dict(runtime) if isinstance(runtime, Mapping) else {}
|
|
1174
|
+
run_id = runtime_snapshot.get("run_id")
|
|
1175
|
+
lifecycle_id = runtime_snapshot.get("lifecycle_id")
|
|
1176
|
+
round_no = _authoritative_round(runtime_snapshot)
|
|
1177
|
+
polling_id = runtime_snapshot.get("polling_id")
|
|
1178
|
+
if (
|
|
1179
|
+
not isinstance(run_id, str) or not run_id.strip()
|
|
1180
|
+
or not isinstance(lifecycle_id, str) or not lifecycle_id.strip()
|
|
1181
|
+
or not isinstance(round_no, int) or isinstance(round_no, bool) or round_no < 1
|
|
1182
|
+
or (polling_id is not None and (
|
|
1183
|
+
not isinstance(polling_id, str) or not polling_id.strip()
|
|
1184
|
+
))
|
|
1185
|
+
):
|
|
1186
|
+
raise FindingsSnapshotError("findings_binding_mismatch")
|
|
1187
|
+
|
|
1188
|
+
out_path = _lifecycle_findings_path(runtime_snapshot)
|
|
1189
|
+
root = Path(os.path.abspath(os.fspath(resolve_project_root())))
|
|
1190
|
+
from core.launch_phases.post_dry_run import FINDINGS_LIMIT, SnapshotInvalid, RootReader
|
|
1191
|
+
|
|
1192
|
+
try:
|
|
1193
|
+
project_reader = RootReader(root)
|
|
1194
|
+
except SnapshotInvalid as exc:
|
|
1195
|
+
raise FindingsSnapshotError(exc.reason_code) from None
|
|
1196
|
+
authority_reader = None
|
|
1197
|
+
close_authority = False
|
|
1198
|
+
try:
|
|
1199
|
+
supervisor_payload, authority_reader, close_authority = _load_authoritative_supervisor(
|
|
1200
|
+
runtime_snapshot, root, project_reader,
|
|
1201
|
+
)
|
|
1202
|
+
if supervisor_payload is None:
|
|
1203
|
+
return None
|
|
1204
|
+
lifecycle_root = _lifecycle_findings_path(runtime_snapshot).parent
|
|
1205
|
+
supervisor_tokens = _supervisor_token_total(supervisor_payload)
|
|
1206
|
+
raw_findings = supervisor_payload.get("findings", [])
|
|
1207
|
+
findings = [] if raw_findings is None else raw_findings
|
|
1208
|
+
if not isinstance(findings, list):
|
|
1209
|
+
raise FindingsSnapshotError("supervisor_state_invalid")
|
|
1210
|
+
if not findings and supervisor_tokens <= 0:
|
|
1211
|
+
return None
|
|
1212
|
+
|
|
1213
|
+
from core.ledger import finding_confirmation as _fc
|
|
1214
|
+
try:
|
|
1215
|
+
from core.supervisor.checkpoint_pipeline import enrich_gate_finding
|
|
1216
|
+
except ImportError:
|
|
1217
|
+
enrich_gate_finding = None
|
|
1218
|
+
merged: list[dict] = []
|
|
1219
|
+
for item in findings:
|
|
1220
|
+
if not isinstance(item, dict):
|
|
1221
|
+
continue
|
|
1222
|
+
row = (
|
|
1223
|
+
enrich_gate_finding(item, lifecycle_root)
|
|
1224
|
+
if enrich_gate_finding else dict(item)
|
|
1225
|
+
)
|
|
1226
|
+
if isinstance(row.get("title"), str):
|
|
1227
|
+
row["title"] = _compact_title(row["title"])
|
|
1228
|
+
confirmation = row.get("confirmation")
|
|
1229
|
+
if isinstance(confirmation, dict):
|
|
1230
|
+
try:
|
|
1231
|
+
_fc.validate_confirmation(row)
|
|
1232
|
+
except Exception:
|
|
1233
|
+
row.pop("confirmation", None)
|
|
1234
|
+
merged.append(row)
|
|
1235
|
+
if not merged and supervisor_tokens <= 0:
|
|
1236
|
+
return None
|
|
1237
|
+
if merged:
|
|
1238
|
+
# DOC-188: adjudication mutates only this detached working copy.
|
|
1239
|
+
_adjudicate_candidate_findings(merged, root, run_id=run_id)
|
|
1240
|
+
confirmed = sum(1 for item in merged if _fc.is_confirmed(item))
|
|
1241
|
+
|
|
1242
|
+
# DOC-196: the authoritative Supervisor lease ledger includes workers
|
|
1243
|
+
# that produced no Finding; per-Finding token data remains a fallback.
|
|
1244
|
+
finding_tokens = sum(
|
|
1245
|
+
int(item.get("token_count", 0)) for item in findings
|
|
1246
|
+
if isinstance(item, dict) and isinstance(item.get("token_count"), (int, float))
|
|
1247
|
+
)
|
|
1248
|
+
total_tokens = supervisor_tokens or finding_tokens
|
|
1249
|
+
has_measured = supervisor_tokens > 0 or any(
|
|
1250
|
+
isinstance(item, dict) and item.get("token_method") not in (None, "unmeasured")
|
|
1251
|
+
for item in findings
|
|
1252
|
+
)
|
|
1253
|
+
|
|
1254
|
+
now_ts = time.time()
|
|
1255
|
+
elapsed_candidates: list[float] = []
|
|
1256
|
+
eff = runtime_snapshot.get("effective_total_seconds")
|
|
1257
|
+
if isinstance(eff, (int, float)) and eff > 0:
|
|
1258
|
+
elapsed_candidates.append(float(eff))
|
|
1259
|
+
cur_elapsed = runtime_snapshot.get("current_elapsed_seconds")
|
|
1260
|
+
if isinstance(cur_elapsed, (int, float)) and cur_elapsed > 0:
|
|
1261
|
+
elapsed_candidates.append(float(cur_elapsed))
|
|
1262
|
+
live_elapsed = runtime_snapshot.get("session_elapsed_seconds")
|
|
1263
|
+
if isinstance(live_elapsed, (int, float)) and live_elapsed > 0:
|
|
1264
|
+
elapsed_candidates.append(float(live_elapsed))
|
|
1265
|
+
started_epoch = runtime_snapshot.get("segment_started_epoch") or runtime_snapshot.get("started_epoch")
|
|
1266
|
+
if isinstance(started_epoch, (int, float)) and started_epoch > 0 and now_ts > started_epoch:
|
|
1267
|
+
elapsed_candidates.append(now_ts - float(started_epoch))
|
|
1268
|
+
total_elapsed = runtime_snapshot.get("total_elapsed_seconds")
|
|
1269
|
+
if isinstance(total_elapsed, (int, float)) and total_elapsed > 0:
|
|
1270
|
+
elapsed_candidates.append(float(total_elapsed))
|
|
1271
|
+
|
|
1272
|
+
if isinstance(supervisor_payload, dict):
|
|
1273
|
+
sv_started = supervisor_payload.get("round_started_at") or supervisor_payload.get("started_at")
|
|
1274
|
+
high_water = supervisor_payload.get("clock_high_water")
|
|
1275
|
+
if isinstance(high_water, (int, float)) and isinstance(sv_started, (int, float)) and high_water > sv_started:
|
|
1276
|
+
elapsed_candidates.append(float(high_water - sv_started))
|
|
1277
|
+
elif isinstance(sv_started, (int, float)) and sv_started > 0 and now_ts > sv_started:
|
|
1278
|
+
elapsed_candidates.append(now_ts - float(sv_started))
|
|
1279
|
+
|
|
1280
|
+
duration_sec = (
|
|
1281
|
+
max(1, int(round(max(elapsed_candidates))))
|
|
1282
|
+
if elapsed_candidates and max(elapsed_candidates) > 0
|
|
1283
|
+
else 0
|
|
1284
|
+
)
|
|
1285
|
+
|
|
1286
|
+
report = {
|
|
1287
|
+
"schema_version": 1,
|
|
1288
|
+
"duration_seconds": duration_sec,
|
|
1289
|
+
"token_count": total_tokens,
|
|
1290
|
+
"token_method": "aggregated" if has_measured else "unmeasured",
|
|
1291
|
+
"host": str(runtime_snapshot.get("host") or os.environ.get("BUGX_HOST") or "cli").lower(),
|
|
1292
|
+
"run_id": run_id,
|
|
1293
|
+
"run_binding": {
|
|
1294
|
+
"run_id": run_id,
|
|
1295
|
+
"lifecycle_id": lifecycle_id,
|
|
1296
|
+
"round": round_no,
|
|
1297
|
+
},
|
|
1298
|
+
# obs-2(2026-11-17):记录构建时的权威 finding 同步代,供
|
|
1299
|
+
# findings_json_stale_vs_authority 检测"先于裁决/后续同步生成的
|
|
1300
|
+
# 陈旧派生视图";确认态一致性由逐条 confirmation 对比兜底。
|
|
1301
|
+
"supervisor_binding": {
|
|
1302
|
+
"findings_revision": supervisor_payload.get("findings_revision"),
|
|
1303
|
+
},
|
|
1304
|
+
"findings": merged,
|
|
1305
|
+
}
|
|
1306
|
+
try:
|
|
1307
|
+
raw_report = (json.dumps(
|
|
1308
|
+
report, ensure_ascii=False, indent=1, allow_nan=False,
|
|
1309
|
+
) + "\n").encode("utf-8")
|
|
1310
|
+
except (TypeError, ValueError, RecursionError):
|
|
1311
|
+
raise FindingsSnapshotError("findings_validation_failed") from None
|
|
1312
|
+
if len(raw_report) > FINDINGS_LIMIT:
|
|
1313
|
+
raise FindingsSnapshotError("findings_size_limit")
|
|
1314
|
+
_validate_findings_payload_snapshot(
|
|
1315
|
+
report, runtime_snapshot, root, project_reader, initial_size=len(raw_report),
|
|
1316
|
+
)
|
|
1317
|
+
_write_findings_atomic_no_replace(out_path, root, raw_report)
|
|
1318
|
+
runtime["lifecycle_token_count"] = (
|
|
1319
|
+
runtime_snapshot.get("lifecycle_token_count", 0) + total_tokens
|
|
1320
|
+
)
|
|
1321
|
+
return f"findings={len(merged)} confirmed={confirmed}"
|
|
1322
|
+
finally:
|
|
1323
|
+
if close_authority and authority_reader is not None:
|
|
1324
|
+
authority_reader.close()
|
|
1325
|
+
project_reader.close()
|
|
1326
|
+
|
|
1327
|
+
|
|
1328
|
+
def auto_settle(
|
|
1329
|
+
active_runtime: dict, snapshot: FindingsSnapshot | None = None, *,
|
|
1330
|
+
snapshot_captured: bool = False,
|
|
1331
|
+
) -> bool:
|
|
1332
|
+
"""宿主独占结算:以 finding_confirmation 门禁裁定的 confirmed 数计命。"""
|
|
1333
|
+
state = baseline_json() or {}
|
|
1334
|
+
history = state.get("history") or []
|
|
1335
|
+
current_round = state.get("round", 1)
|
|
1336
|
+
last_history = history[-1] if history else None
|
|
1337
|
+
if (isinstance(last_history, dict)
|
|
1338
|
+
and last_history.get("round") == current_round):
|
|
1339
|
+
return True
|
|
1340
|
+
if (
|
|
1341
|
+
snapshot is None and not snapshot_captured
|
|
1342
|
+
and auto_mode(active_runtime)
|
|
1343
|
+
and settle_findings_path(active_runtime) is None
|
|
1344
|
+
):
|
|
1345
|
+
try:
|
|
1346
|
+
built = auto_build_findings_json(active_runtime)
|
|
1347
|
+
except FindingsSnapshotError as exc:
|
|
1348
|
+
print(f"[auto-settle] ✗ {exc.reason_code}")
|
|
1349
|
+
return False
|
|
1350
|
+
if built:
|
|
1351
|
+
print(f"[auto-settle] 已自动生成 findings.json({built});"
|
|
1352
|
+
"候选未经确认不计命,确认列入后续 Life")
|
|
1353
|
+
try:
|
|
1354
|
+
snapshot = capture_findings_snapshot(active_runtime)
|
|
1355
|
+
snapshot_captured = True
|
|
1356
|
+
except FindingsSnapshotError as exc:
|
|
1357
|
+
print(f"[auto-settle] ✗ {exc.reason_code}")
|
|
1358
|
+
return False
|
|
1359
|
+
elif not snapshot_captured:
|
|
1360
|
+
try:
|
|
1361
|
+
snapshot = capture_findings_snapshot(active_runtime)
|
|
1362
|
+
snapshot_captured = True
|
|
1363
|
+
except FindingsSnapshotError as exc:
|
|
1364
|
+
print(f"[auto-settle] ✗ {exc.reason_code}")
|
|
1365
|
+
return False
|
|
1366
|
+
round_at_start = active_runtime.get("round_at_start")
|
|
1367
|
+
if (isinstance(last_history, dict)
|
|
1368
|
+
and isinstance(current_round, int)
|
|
1369
|
+
and isinstance(round_at_start, int)
|
|
1370
|
+
and current_round > round_at_start
|
|
1371
|
+
and last_history.get("round") == current_round - 1):
|
|
1372
|
+
return True
|
|
1373
|
+
supervisor = _settlement_supervisor(resolve_project_root()) if uses_project_layout() else None
|
|
1374
|
+
frozen = None
|
|
1375
|
+
if supervisor is not None:
|
|
1376
|
+
try:
|
|
1377
|
+
frozen = supervisor.freeze_report_snapshot()
|
|
1378
|
+
except Exception:
|
|
1379
|
+
try:
|
|
1380
|
+
if supervisor.status().report_consumption.get("phase") == "POSTING":
|
|
1381
|
+
print("[auto-settle] ✗ report 已处于 POSTING,等待同次消费恢复")
|
|
1382
|
+
return False
|
|
1383
|
+
except Exception:
|
|
1384
|
+
pass
|
|
1385
|
+
frozen = None
|
|
1386
|
+
credited, lines, note = gate_confirmed_findings(
|
|
1387
|
+
active_runtime, snapshot, snapshot_captured=snapshot_captured,
|
|
1388
|
+
)
|
|
1389
|
+
if credited is None:
|
|
1390
|
+
print(f"[auto-settle] ✗ {note}")
|
|
1391
|
+
return False
|
|
1392
|
+
lifecycle_root = lifecycle_root_for(active_runtime)
|
|
1393
|
+
findings_file = lifecycle_root / f"findings_round{current_round}.txt"
|
|
1394
|
+
findings_file.parent.mkdir(parents=True, exist_ok=True)
|
|
1395
|
+
findings_file.write_text(
|
|
1396
|
+
"\n".join(lines) + ("\n" if lines else ""), encoding="utf-8",
|
|
1397
|
+
)
|
|
1398
|
+
cmd = [
|
|
1399
|
+
sys.executable, str(VERIFY),
|
|
1400
|
+
"settle", "--credited", str(credited), "--fraud", "0",
|
|
1401
|
+
"--findings-file", str(findings_file),
|
|
1402
|
+
"--round", str(current_round),
|
|
1403
|
+
]
|
|
1404
|
+
result = None
|
|
1405
|
+
try:
|
|
1406
|
+
result = subprocess.run(
|
|
1407
|
+
cmd, capture_output=True, text=True, cwd=str(resolve_project_root()),
|
|
1408
|
+
timeout=30, env=child_environment(),
|
|
1409
|
+
)
|
|
1410
|
+
except subprocess.TimeoutExpired:
|
|
1411
|
+
print("[auto-settle] ✗ settle 子进程超时(30s),拒绝结算")
|
|
1412
|
+
return False
|
|
1413
|
+
except OSError as exc:
|
|
1414
|
+
print(f"[auto-settle] ✗ settle 子进程启动失败: {exc}")
|
|
1415
|
+
return False
|
|
1416
|
+
if result.returncode != 0:
|
|
1417
|
+
detail = (result.stderr or result.stdout).strip()[:300]
|
|
1418
|
+
print(f"[auto-settle] ✗ settle 失败: {detail}")
|
|
1419
|
+
return False
|
|
1420
|
+
if supervisor is not None and isinstance(frozen, dict) and frozen.get("phase") == "POSTING":
|
|
1421
|
+
try:
|
|
1422
|
+
supervisor.settle_report({
|
|
1423
|
+
"report_sha256": (frozen.get("seal") or {}).get("report_sha256"),
|
|
1424
|
+
"settlement_output_sha256": hashlib.sha256(
|
|
1425
|
+
(result.stdout or "").encode("utf-8")
|
|
1426
|
+
).hexdigest(),
|
|
1427
|
+
})
|
|
1428
|
+
except Exception as exc:
|
|
1429
|
+
print(f"[auto-settle] ✗ Supervisor SETTLED 写入失败: {exc}")
|
|
1430
|
+
return False
|
|
1431
|
+
print(f"[auto-settle] ✓ 结算完成:{note},credited={credited}, round={current_round}")
|
|
1432
|
+
return True
|