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,1670 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""launch_phases/session_runtime.py - 状态机维护、runtime.json 加锁管理、时间分段与事件记录。"""
|
|
3
|
+
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
import datetime as dt
|
|
7
|
+
import json
|
|
8
|
+
import math
|
|
9
|
+
import os
|
|
10
|
+
import sys
|
|
11
|
+
import time
|
|
12
|
+
import contextvars
|
|
13
|
+
from contextlib import contextmanager
|
|
14
|
+
from pathlib import Path
|
|
15
|
+
from typing import Any
|
|
16
|
+
|
|
17
|
+
from core.launch_phases.common import (
|
|
18
|
+
AGENT_DIR,
|
|
19
|
+
RUNTIME_FILE,
|
|
20
|
+
RUNTIME_LOCK_FILE,
|
|
21
|
+
RUNTIME_SCHEMA_VERSION,
|
|
22
|
+
RUNTIME_STATES,
|
|
23
|
+
HEARTBEAT_TIMEOUT_SECONDS,
|
|
24
|
+
POLLING_POLICIES,
|
|
25
|
+
REVIEW_MODES,
|
|
26
|
+
COMMIT_POLICIES,
|
|
27
|
+
REVIEW_DECISION_LATER,
|
|
28
|
+
POLLING_DECISION_REQUIRED,
|
|
29
|
+
AUDIT_TODO_ITEMS,
|
|
30
|
+
RUNTIME_STARTED_THIS_PROCESS,
|
|
31
|
+
set_runtime_started_this_process,
|
|
32
|
+
diagnostic_logger,
|
|
33
|
+
resolve_project_root,
|
|
34
|
+
uses_project_layout,
|
|
35
|
+
is_number,
|
|
36
|
+
format_duration,
|
|
37
|
+
SUPERVISOR_STATE,
|
|
38
|
+
COVERAGE_EVIDENCE,
|
|
39
|
+
LIFE_FILE,
|
|
40
|
+
LESSON_LEDGER_FILE,
|
|
41
|
+
GLOBAL_LESSON_LEDGER_FILE,
|
|
42
|
+
LIFECYCLE_MAX_NO_PROGRESS_CYCLES,
|
|
43
|
+
pollings_root,
|
|
44
|
+
bugx_paths,
|
|
45
|
+
)
|
|
46
|
+
import tempfile
|
|
47
|
+
import threading
|
|
48
|
+
import uuid
|
|
49
|
+
import core.secure_atomic as secure_atomic
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
#: ``runtime_lock`` 的同进程**同线程**重入深度(LOG-03)。flock 对不同 fd
|
|
53
|
+
#: 仍互斥,因此重入必须由本线程自己识别;必须是 thread-local 而非普通全局,
|
|
54
|
+
#: 否则线程 A 持锁会让线程 B 误以为「已持锁」而跳过 flock,互斥直接失效。
|
|
55
|
+
_RUNTIME_LOCK_STATE = threading.local()
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
#: 显式钉住的 runtime 路径。设置后 ``refresh_runtime_paths`` 用它取代按
|
|
59
|
+
#: ``resolve_project_root()`` 的重算——否则直接给 ``RUNTIME_FILE`` 赋值会被
|
|
60
|
+
#: ``runtime_lock()``/``load_runtime()`` 里的路径刷新静默覆盖,「指定 root」
|
|
61
|
+
#: 的调用方(MCP host 心跳)与测试夹具都会失效。contextvar 按线程隔离,
|
|
62
|
+
#: 心跳 loop 线程与调用线程各自持钉,不会互相污染。
|
|
63
|
+
_RUNTIME_PATH_PIN: contextvars.ContextVar[dict[str, Path] | None] = contextvars.ContextVar(
|
|
64
|
+
"bugx_runtime_path_pin", default=None,
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
@contextmanager
|
|
69
|
+
def _pinned_runtime_paths(runtime: Path, runtime_lock: Path | None = None):
|
|
70
|
+
"""在动态作用域内钉住 runtime 与锁路径,绕过 ``resolve_project_root()`` 重算。
|
|
71
|
+
|
|
72
|
+
进入时立即写入 globals(直接读 ``RUNTIME_FILE`` 的调用方也立刻看到钉住值),
|
|
73
|
+
退出时还原,避免钉住值泄漏到后续不相关的项目访问。
|
|
74
|
+
"""
|
|
75
|
+
lock = (
|
|
76
|
+
Path(runtime_lock) if runtime_lock is not None
|
|
77
|
+
else Path(runtime).with_name("runtime.lock")
|
|
78
|
+
)
|
|
79
|
+
paths = {"RUNTIME_FILE": Path(runtime), "RUNTIME_LOCK_FILE": lock}
|
|
80
|
+
previous = {k: v for k, v in ((k, globals().get(k)) for k in paths) if v is not None}
|
|
81
|
+
token = _RUNTIME_PATH_PIN.set(paths)
|
|
82
|
+
_apply_runtime_paths(paths)
|
|
83
|
+
try:
|
|
84
|
+
yield
|
|
85
|
+
finally:
|
|
86
|
+
_RUNTIME_PATH_PIN.reset(token)
|
|
87
|
+
if previous:
|
|
88
|
+
_apply_runtime_paths(previous)
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def _runtime_lock_depth() -> int:
|
|
92
|
+
"""当前线程持有运行状态锁的重入深度。"""
|
|
93
|
+
return int(getattr(_RUNTIME_LOCK_STATE, "depth", 0))
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def _set_runtime_lock_depth(value: int) -> None:
|
|
97
|
+
_RUNTIME_LOCK_STATE.depth = value
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def refresh_runtime_paths() -> None:
|
|
102
|
+
"""Bind runtime paths to the active .bugx lifecycle.
|
|
103
|
+
|
|
104
|
+
The project .bugx directory contains runtime state only. Executable assets
|
|
105
|
+
are loaded from the global engine; a missing project layout is deliberately
|
|
106
|
+
surfaced to callers.
|
|
107
|
+
"""
|
|
108
|
+
pinned = _RUNTIME_PATH_PIN.get()
|
|
109
|
+
if pinned is not None:
|
|
110
|
+
# 显式钉住优先于重算:调用方已指定 runtime 路径时,不得再按
|
|
111
|
+
# resolve_project_root() 覆盖,否则 root 参数静默失效。
|
|
112
|
+
_apply_runtime_paths(pinned)
|
|
113
|
+
return
|
|
114
|
+
if not uses_project_layout():
|
|
115
|
+
return
|
|
116
|
+
# Use the same root resolver as every other global-engine launcher path.
|
|
117
|
+
# Calling bugx_paths.project_root(AGENT_DIR) here is safe because the CLI
|
|
118
|
+
# binds BUGX_PROJECT_ROOT before starting the engine.
|
|
119
|
+
root = resolve_project_root()
|
|
120
|
+
active = bugx_paths.require(root)
|
|
121
|
+
_apply_runtime_paths({
|
|
122
|
+
"COVERAGE_EVIDENCE": active.coverage,
|
|
123
|
+
"SUPERVISOR_STATE": active.supervisor,
|
|
124
|
+
"LESSON_LEDGER_FILE": active.knowledge_seed,
|
|
125
|
+
"GLOBAL_LESSON_LEDGER_FILE": active.global_knowledge_seed,
|
|
126
|
+
"RUNTIME_FILE": active.runtime,
|
|
127
|
+
"RUNTIME_LOCK_FILE": active.runtime_lock,
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def _apply_runtime_paths(path_updates: dict[str, Path]) -> None:
|
|
132
|
+
"""把路径写进共享层与显式阶段模块,杜绝运行态路径漂移。
|
|
133
|
+
|
|
134
|
+
阶段模块仍有少量历史 ``from common import`` 路径别名,需要同步以保持
|
|
135
|
+
现有调用契约;使用显式包引用,不再通过 ``sys.modules`` 扫描并广播。
|
|
136
|
+
"""
|
|
137
|
+
global COVERAGE_EVIDENCE, SUPERVISOR_STATE, LESSON_LEDGER_FILE
|
|
138
|
+
global GLOBAL_LESSON_LEDGER_FILE, RUNTIME_FILE, RUNTIME_LOCK_FILE
|
|
139
|
+
for k, v in path_updates.items():
|
|
140
|
+
globals()[k] = v
|
|
141
|
+
|
|
142
|
+
# These are explicit compatibility sinks for legacy ``from common import``
|
|
143
|
+
# aliases. Keep the list small and auditable until each consumer reads
|
|
144
|
+
# ``common`` directly.
|
|
145
|
+
from . import (
|
|
146
|
+
common,
|
|
147
|
+
finding_settlement,
|
|
148
|
+
lesson_context,
|
|
149
|
+
lifecycle_reporter,
|
|
150
|
+
post_phase,
|
|
151
|
+
pre_phase,
|
|
152
|
+
report_sharing,
|
|
153
|
+
round_orchestrator,
|
|
154
|
+
startup_gates,
|
|
155
|
+
supervisor_bridge,
|
|
156
|
+
worker_orchestrator,
|
|
157
|
+
)
|
|
158
|
+
for module in (
|
|
159
|
+
common,
|
|
160
|
+
lesson_context,
|
|
161
|
+
pre_phase,
|
|
162
|
+
round_orchestrator,
|
|
163
|
+
post_phase,
|
|
164
|
+
worker_orchestrator,
|
|
165
|
+
startup_gates,
|
|
166
|
+
lifecycle_reporter,
|
|
167
|
+
finding_settlement,
|
|
168
|
+
report_sharing,
|
|
169
|
+
supervisor_bridge,
|
|
170
|
+
):
|
|
171
|
+
for k, v in path_updates.items():
|
|
172
|
+
if hasattr(module, k):
|
|
173
|
+
setattr(module, k, v)
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
def _ensure_project_runtime_paths() -> None:
|
|
177
|
+
"""Refresh paths before direct runtime helpers use module-level defaults."""
|
|
178
|
+
if uses_project_layout():
|
|
179
|
+
refresh_runtime_paths()
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
def audit_todo_path() -> Path | None:
|
|
183
|
+
"""Return the current Round's derived TODO view path.
|
|
184
|
+
|
|
185
|
+
The current pointer is the sole scope selector. This keeps the view in
|
|
186
|
+
the same lifecycle ``state`` directory as runtime/coverage evidence and
|
|
187
|
+
avoids accepting a path supplied by an agent or worker.
|
|
188
|
+
"""
|
|
189
|
+
if not uses_project_layout() or bugx_paths is None:
|
|
190
|
+
return None
|
|
191
|
+
return bugx_paths.require(resolve_project_root()).state_root / "audit-todo.md"
|
|
192
|
+
|
|
193
|
+
def _audit_todo_content(runtime: dict, phase: str, reason: str | None = None) -> str:
|
|
194
|
+
"""Build the human-readable current-Round progress view.
|
|
195
|
+
|
|
196
|
+
This is intentionally a projection of authoritative runtime boundaries;
|
|
197
|
+
it contains no coverage-unit, worker, finding, priority, or completion
|
|
198
|
+
decisions of its own.
|
|
199
|
+
"""
|
|
200
|
+
runtime = runtime if isinstance(runtime, dict) else {}
|
|
201
|
+
phase = str(phase or "running")
|
|
202
|
+
completed_through = {
|
|
203
|
+
"running": 4,
|
|
204
|
+
"resumed": 4,
|
|
205
|
+
"life-settled": 9,
|
|
206
|
+
"round-completed": 11,
|
|
207
|
+
"session-completed": len(AUDIT_TODO_ITEMS) - 1,
|
|
208
|
+
"share-pending": len(AUDIT_TODO_ITEMS) - 1,
|
|
209
|
+
"share-completed": len(AUDIT_TODO_ITEMS),
|
|
210
|
+
"blocked": 11,
|
|
211
|
+
"aborted": 0,
|
|
212
|
+
}.get(phase, 0)
|
|
213
|
+
active_index = {
|
|
214
|
+
"running": 4,
|
|
215
|
+
"resumed": 4,
|
|
216
|
+
"life-settled": 9,
|
|
217
|
+
"round-completed": 11,
|
|
218
|
+
"session-completed": len(AUDIT_TODO_ITEMS) - 1,
|
|
219
|
+
"share-pending": len(AUDIT_TODO_ITEMS) - 1,
|
|
220
|
+
"blocked": 11,
|
|
221
|
+
}.get(phase)
|
|
222
|
+
lines = [
|
|
223
|
+
"# BugX 当前 Round TODO",
|
|
224
|
+
"",
|
|
225
|
+
f"- Session:`{runtime.get('session_id') or 'unknown'}`",
|
|
226
|
+
f"- Round:`{runtime.get('round_id') or runtime.get('lifecycle_id') or 'unknown'}`",
|
|
227
|
+
f"- Life:`{runtime.get('life_no') or 'unknown'}`",
|
|
228
|
+
f"- Runtime:`{runtime.get('state') or 'unknown'}`;事件数 `{len(runtime.get('events') or [])}`",
|
|
229
|
+
f"- 同步:`{runtime.get('sync_status') or 'unknown'}`;共享队列状态由 `share_pending.json` 体现",
|
|
230
|
+
f"- 阶段:`{phase}`",
|
|
231
|
+
f"- 最后校准:`{iso_time(time.time())}`",
|
|
232
|
+
"- 来源:`runtime.json`、事件账本、覆盖证据与 Round 报告(派生视图)",
|
|
233
|
+
"",
|
|
234
|
+
]
|
|
235
|
+
for index, item in enumerate(AUDIT_TODO_ITEMS):
|
|
236
|
+
if index < completed_through:
|
|
237
|
+
marker = "x"
|
|
238
|
+
elif phase == "blocked" and index == active_index:
|
|
239
|
+
marker = "!"
|
|
240
|
+
elif active_index is not None and index == active_index:
|
|
241
|
+
marker = "~"
|
|
242
|
+
else:
|
|
243
|
+
marker = " "
|
|
244
|
+
lines.append(f"- [{marker}] {item}")
|
|
245
|
+
if reason:
|
|
246
|
+
lines.extend(["", f"- 当前原因:{reason}"])
|
|
247
|
+
lines.extend([
|
|
248
|
+
"",
|
|
249
|
+
"> 本文件仅是当前 Round 的操作视图,不是账本、覆盖清单、Finding 来源或完成判定器。",
|
|
250
|
+
])
|
|
251
|
+
return "\n".join(lines) + "\n"
|
|
252
|
+
|
|
253
|
+
def refresh_audit_todo(runtime: dict, phase: str, reason: str | None = None) -> Path | None:
|
|
254
|
+
"""Atomically refresh the derived TODO view without blocking authority."""
|
|
255
|
+
path = audit_todo_path()
|
|
256
|
+
if path is None:
|
|
257
|
+
return None
|
|
258
|
+
try:
|
|
259
|
+
secure_atomic.atomic_write_text(
|
|
260
|
+
path,
|
|
261
|
+
_audit_todo_content(runtime, phase, reason),
|
|
262
|
+
mode=0o600,
|
|
263
|
+
parent_mode=0o700,
|
|
264
|
+
)
|
|
265
|
+
except (OSError, ValueError, RuntimeError) as exc:
|
|
266
|
+
# Runtime/events/report remain authoritative. A stale or missing view
|
|
267
|
+
# is recoverable and must never turn a completed boundary into failure.
|
|
268
|
+
print(f" (TODO 清单视图刷新失败,不影响权威状态:{exc})")
|
|
269
|
+
return None
|
|
270
|
+
return path
|
|
271
|
+
|
|
272
|
+
def _default_runtime() -> dict:
|
|
273
|
+
return {
|
|
274
|
+
"schema_version": RUNTIME_SCHEMA_VERSION,
|
|
275
|
+
"run_id": None,
|
|
276
|
+
"state": "idle",
|
|
277
|
+
"active": False,
|
|
278
|
+
"pid": None,
|
|
279
|
+
"host_pid": None,
|
|
280
|
+
"started_at": None,
|
|
281
|
+
"started_epoch": None,
|
|
282
|
+
"session_started_at": None,
|
|
283
|
+
"session_started_epoch": None,
|
|
284
|
+
"startup_action": None,
|
|
285
|
+
"segment_started_epoch": None,
|
|
286
|
+
"paused_at": None,
|
|
287
|
+
"heartbeat_at": None,
|
|
288
|
+
"heartbeat_epoch": None,
|
|
289
|
+
"round_at_start": None,
|
|
290
|
+
"session_elapsed_seconds": 0.0,
|
|
291
|
+
"last_session_elapsed_seconds": 0.0,
|
|
292
|
+
"total_elapsed_seconds": 0.0,
|
|
293
|
+
"sessions_completed": 0,
|
|
294
|
+
"sessions_aborted": 0,
|
|
295
|
+
"sessions": [],
|
|
296
|
+
"life_runs": [],
|
|
297
|
+
"events": [],
|
|
298
|
+
# 轮询策略独立于 verify_life.mode:后者控制修复方式,这里只控制
|
|
299
|
+
# 当前轮死亡后的续轮行为。None 代表尚未完成启动前的必问交互。
|
|
300
|
+
"polling_policy": None,
|
|
301
|
+
# 提交策略属于启动上下文;log-only 会自动归一为 not_applicable。
|
|
302
|
+
"commit_policy": None,
|
|
303
|
+
"commit_status": None,
|
|
304
|
+
"commit_boundary": None,
|
|
305
|
+
"commit_ref": None,
|
|
306
|
+
"commit_error": None,
|
|
307
|
+
"sync_status": "local",
|
|
308
|
+
"startup_id": None,
|
|
309
|
+
"startup_observation": None,
|
|
310
|
+
"startup_intent": None,
|
|
311
|
+
"startup_result": None,
|
|
312
|
+
# DOC-138: explicit host-agent autonomous mode. The policy/hash are
|
|
313
|
+
# captured at Session start and must not be inferred from model output.
|
|
314
|
+
"host": None,
|
|
315
|
+
"autonomous_mode": False,
|
|
316
|
+
"execute": False,
|
|
317
|
+
# F-RSI-20261112-077 后继(轮 77):校验层已统一正整数口径(0 拒绝),
|
|
318
|
+
# 默认态的「未声明」必须用 None 表达(与 worker_capacity 同构)——
|
|
319
|
+
# 默认值产 0 会让缺文件回退/reconcile 路径被自家校验炸掉。
|
|
320
|
+
"workers": None,
|
|
321
|
+
"worker_capacity": None,
|
|
322
|
+
"subagent_type": "bugx-worker",
|
|
323
|
+
"stagger_seconds": 0.0,
|
|
324
|
+
"provider": None,
|
|
325
|
+
"autonomous_policy": None,
|
|
326
|
+
"autonomous_policy_hash": None,
|
|
327
|
+
"session_id": None,
|
|
328
|
+
"round_id": None,
|
|
329
|
+
"life_no": None,
|
|
330
|
+
"life_kind": "mine",
|
|
331
|
+
"session_state": "initializing",
|
|
332
|
+
"session_closed_at": None,
|
|
333
|
+
"final_round_id": None,
|
|
334
|
+
# 审查执行面:manual 由宿主/Agent 按步骤推进;mcp-auto 由唯一的
|
|
335
|
+
# bugx-supervisor MCP 负责状态、租约、心跳和门禁协调。None 代表
|
|
336
|
+
# 尚未完成启动前的必问交互。
|
|
337
|
+
"review_mode": None,
|
|
338
|
+
# 仅在明确选择手动回退时记录 deferred;“下次再说”会停止本轮。
|
|
339
|
+
"review_mode_deferred": False,
|
|
340
|
+
"polling_round_auto_started": False,
|
|
341
|
+
"polling_last_round": None,
|
|
342
|
+
"polling_stop_reason": None,
|
|
343
|
+
# Round 状态:verify_life.round/rounds_completed 表示 Round 内 Life。
|
|
344
|
+
"lifecycle_no": 0,
|
|
345
|
+
"lifecycle_id": None,
|
|
346
|
+
"lifecycle_auto_started": False,
|
|
347
|
+
"lifecycle_started_at": None,
|
|
348
|
+
"lifecycle_started_epoch": None,
|
|
349
|
+
"lifecycle_cycles_completed": 0,
|
|
350
|
+
"lifecycle_findings_total": 0,
|
|
351
|
+
"lifecycle_credited_total": 0,
|
|
352
|
+
"lifecycle_fraud_total": 0,
|
|
353
|
+
"lifecycle_last_life": None,
|
|
354
|
+
"lifecycle_terminal": False,
|
|
355
|
+
"lifecycle_last_report": None,
|
|
356
|
+
"lifecycle_no_progress_cycles": 0,
|
|
357
|
+
"lifecycle_stop_reason": None,
|
|
358
|
+
"lifecycle_history": [],
|
|
359
|
+
# Pattern IDs injected into this big lifecycle. A later small
|
|
360
|
+
# lifecycle receives only fresh cards, preventing stale repetition.
|
|
361
|
+
"lifecycle_lesson_ids": [],
|
|
362
|
+
"lifecycle_incident_ids": [],
|
|
363
|
+
"lesson_recent_signatures": [],
|
|
364
|
+
"realized_fix_incidents": [],
|
|
365
|
+
"lesson_context": None,
|
|
366
|
+
"project_profile_hash": None,
|
|
367
|
+
"project_profile_revision": None,
|
|
368
|
+
"project_profile_status": "unknown",
|
|
369
|
+
"project_classification": None,
|
|
370
|
+
"project_routing_tags": {},
|
|
371
|
+
"audit_strategy": None,
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
_RUNTIME_RESET_GUIDANCE = (
|
|
375
|
+
"旧状态不迁移。确认要丢弃旧运行态后,请执行 "
|
|
376
|
+
"`bugx reset --scope project --root <项目路径> --yes`;若重置被活动状态阻断,"
|
|
377
|
+
"先确认没有 Worker 仍会写入状态,再显式加 `--force`。项目 reset 会先创建项目外归档。"
|
|
378
|
+
)
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+
def _require_current_runtime_schema(state: dict, source: Path) -> None:
|
|
382
|
+
"""Reject old or incomplete runtime documents before they can be restored or used."""
|
|
383
|
+
schema_version = state.get("schema_version")
|
|
384
|
+
if schema_version != RUNTIME_SCHEMA_VERSION:
|
|
385
|
+
raise ValueError(
|
|
386
|
+
f"运行计时文件 schema_version 不受支持: {source} "
|
|
387
|
+
f"(expected={RUNTIME_SCHEMA_VERSION}, actual={schema_version!r});"
|
|
388
|
+
f"{_RUNTIME_RESET_GUIDANCE}"
|
|
389
|
+
)
|
|
390
|
+
missing = sorted(set(_default_runtime()) - state.keys())
|
|
391
|
+
if missing:
|
|
392
|
+
raise ValueError(
|
|
393
|
+
f"运行计时文件不符合当前 schema: {source};缺少必需字段 "
|
|
394
|
+
f"{', '.join(missing)};{_RUNTIME_RESET_GUIDANCE}"
|
|
395
|
+
)
|
|
396
|
+
|
|
397
|
+
def _is_pid_alive(pid: int | None) -> bool:
|
|
398
|
+
"""检测进程是否依然存活(跨平台且不把 Windows WinError 87 当死亡)。"""
|
|
399
|
+
if pid is None or not isinstance(pid, int) or isinstance(pid, bool) or pid <= 0:
|
|
400
|
+
return False
|
|
401
|
+
if os.name == "nt":
|
|
402
|
+
try:
|
|
403
|
+
import ctypes
|
|
404
|
+
|
|
405
|
+
kernel32 = ctypes.WinDLL("kernel32", use_last_error=True)
|
|
406
|
+
kernel32.OpenProcess.argtypes = [ctypes.c_uint32, ctypes.c_int, ctypes.c_uint32]
|
|
407
|
+
kernel32.OpenProcess.restype = ctypes.c_void_p
|
|
408
|
+
kernel32.GetExitCodeProcess.argtypes = [ctypes.c_void_p, ctypes.POINTER(ctypes.c_uint32)]
|
|
409
|
+
kernel32.GetExitCodeProcess.restype = ctypes.c_int
|
|
410
|
+
kernel32.CloseHandle.argtypes = [ctypes.c_void_p]
|
|
411
|
+
kernel32.CloseHandle.restype = ctypes.c_int
|
|
412
|
+
handle = kernel32.OpenProcess(0x1000, 0, pid) # PROCESS_QUERY_LIMITED_INFORMATION
|
|
413
|
+
if not handle:
|
|
414
|
+
return ctypes.get_last_error() == 5 # ERROR_ACCESS_DENIED: process exists
|
|
415
|
+
try:
|
|
416
|
+
exit_code = ctypes.c_uint32()
|
|
417
|
+
return bool(kernel32.GetExitCodeProcess(handle, ctypes.byref(exit_code))) \
|
|
418
|
+
and exit_code.value == 259 # STILL_ACTIVE
|
|
419
|
+
finally:
|
|
420
|
+
kernel32.CloseHandle(handle)
|
|
421
|
+
except (AttributeError, OSError, TypeError, ValueError):
|
|
422
|
+
return False
|
|
423
|
+
try:
|
|
424
|
+
os.kill(pid, 0)
|
|
425
|
+
return True
|
|
426
|
+
except ProcessLookupError:
|
|
427
|
+
return False
|
|
428
|
+
except PermissionError:
|
|
429
|
+
return True
|
|
430
|
+
except OSError as err:
|
|
431
|
+
import errno
|
|
432
|
+
if getattr(err, "errno", None) == errno.ESRCH:
|
|
433
|
+
return False
|
|
434
|
+
if getattr(err, "errno", None) == errno.EPERM:
|
|
435
|
+
return True
|
|
436
|
+
return False
|
|
437
|
+
|
|
438
|
+
|
|
439
|
+
def _auto_started_idle_shell(state: dict) -> bool:
|
|
440
|
+
"""自动续轮建立的空壳回合:从未完成任何 Life 且零有效发现。
|
|
441
|
+
|
|
442
|
+
post 轮询对这类回合的既定收敛语义是 ``auto_lifecycle_zero_findings``
|
|
443
|
+
(post_phase 的非常驻收敛分支);孤儿裁决复用同一判据,避免把
|
|
444
|
+
「宿主尚未派发 worker 就失去属主」的空壳回合记成挖掘事故。
|
|
445
|
+
"""
|
|
446
|
+
if not state.get("polling_round_auto_started"):
|
|
447
|
+
return False
|
|
448
|
+
if int(state.get("lifecycle_cycles_completed", 0) or 0) != 0:
|
|
449
|
+
return False
|
|
450
|
+
return int(state.get("lifecycle_credited_total", 0) or 0) == 0
|
|
451
|
+
|
|
452
|
+
|
|
453
|
+
def _supervisor_terminal_awaiting_settle(state: dict) -> bool:
|
|
454
|
+
"""Supervisor 权威终态已落盘、post 尚未消费时的免孤儿豁免。
|
|
455
|
+
|
|
456
|
+
Supervisor ``finish()``(coverage 未完成绝不产生 COMPLETE)与 COMPLETE
|
|
457
|
+
后的 reset_budget 禁令共同保证:status=COMPLETE(或 INCOMPLETE/FAILED
|
|
458
|
+
且 completed_at 已写)是**不可复活的终态**。此时挖掘工作已合法结束,
|
|
459
|
+
仅因宿主 MCP 通道退出导致 runtime 无人续约;把它裁决成 aborted 会
|
|
460
|
+
让 post 的 runtime_active 门永久拒绝结算。这里只承认终态,不刷新
|
|
461
|
+
心跳、不放宽 post 门禁——身份不匹配或文件异常一律回退 abort 路径。
|
|
462
|
+
"""
|
|
463
|
+
path = SUPERVISOR_STATE
|
|
464
|
+
if not isinstance(path, Path) or not path.is_file():
|
|
465
|
+
return False
|
|
466
|
+
try:
|
|
467
|
+
payload = json.loads(path.read_text(encoding="utf-8"))
|
|
468
|
+
except (OSError, ValueError):
|
|
469
|
+
return False
|
|
470
|
+
if not isinstance(payload, dict):
|
|
471
|
+
return False
|
|
472
|
+
status = payload.get("status")
|
|
473
|
+
terminal = status == "COMPLETE" or (
|
|
474
|
+
status in {"INCOMPLETE", "FAILED"} and payload.get("completed_at") is not None
|
|
475
|
+
)
|
|
476
|
+
if not terminal:
|
|
477
|
+
return False
|
|
478
|
+
session_id = state.get("session_id")
|
|
479
|
+
round_id = state.get("round_id") or state.get("lifecycle_id")
|
|
480
|
+
if not session_id or payload.get("session_id") != session_id:
|
|
481
|
+
return False
|
|
482
|
+
if not round_id or payload.get("round_id") != round_id:
|
|
483
|
+
return False
|
|
484
|
+
return True
|
|
485
|
+
|
|
486
|
+
|
|
487
|
+
def _reconcile_orphaned_state_locked(state: dict, now: float | None = None) -> bool:
|
|
488
|
+
|
|
489
|
+
"""若当前为 active 状态但对应 PID 进程已死亡(或心跳严重超时),自动裁决为 aborted。"""
|
|
490
|
+
if not state.get("active"):
|
|
491
|
+
return False
|
|
492
|
+
pid = state.get("pid")
|
|
493
|
+
heartbeat_epoch = (
|
|
494
|
+
state.get("heartbeat_epoch")
|
|
495
|
+
or state.get("segment_started_epoch")
|
|
496
|
+
or state.get("started_epoch")
|
|
497
|
+
)
|
|
498
|
+
current = time.time() if now is None else now
|
|
499
|
+
heartbeat_stalled = (
|
|
500
|
+
heartbeat_epoch is not None
|
|
501
|
+
and is_number(heartbeat_epoch)
|
|
502
|
+
and (current - float(heartbeat_epoch)) > HEARTBEAT_TIMEOUT_SECONDS
|
|
503
|
+
)
|
|
504
|
+
is_dead = False
|
|
505
|
+
ownership_lost = False
|
|
506
|
+
if pid is not None and isinstance(pid, int) and not isinstance(pid, bool):
|
|
507
|
+
if not _is_pid_alive(pid):
|
|
508
|
+
if heartbeat_stalled or heartbeat_epoch is None:
|
|
509
|
+
is_dead = True
|
|
510
|
+
else:
|
|
511
|
+
# 认领属主(宿主 MCP server 等短生命周期通道)死亡但会话
|
|
512
|
+
# 心跳仍新鲜:只代表通道退出,不代表挖掘进程崩溃。清除
|
|
513
|
+
# 所有权即可;把通道死亡连坐成 Run 中止,会让宿主会话的
|
|
514
|
+
# 开关误杀后台无人值守 Run(真实事故:auto 续轮的 Round
|
|
515
|
+
# 被已退出 MCP 通道的 pid 拖成 aborted)。
|
|
516
|
+
ownership_lost = True
|
|
517
|
+
elif heartbeat_stalled:
|
|
518
|
+
is_dead = True
|
|
519
|
+
|
|
520
|
+
if ownership_lost:
|
|
521
|
+
state.update({"pid": None, "host_pid": None})
|
|
522
|
+
append_runtime_event(
|
|
523
|
+
state, "ownership_released", current,
|
|
524
|
+
"claimed owner process died; heartbeat still fresh",
|
|
525
|
+
)
|
|
526
|
+
# DOC-204 L7:取消回传结构化——"进程死但心跳新鲜"是宿主取消 agent
|
|
527
|
+
# 的引擎侧信号;落 supervisor 权威链 owner_cancelled(D27 修复钩子)。
|
|
528
|
+
try:
|
|
529
|
+
from core.launch_phases.supervisor_bridge import get_supervisor as _bridge_supervisor
|
|
530
|
+
|
|
531
|
+
_bridge_supervisor().record_lifecycle_block(
|
|
532
|
+
operation="lifecycle", gate="owner_cancelled",
|
|
533
|
+
reason="宿主取消 agent:owner 进程死亡而心跳仍新鲜(D27 取消回传)",
|
|
534
|
+
)
|
|
535
|
+
except Exception as exc: # noqa: BLE001 - 回传失败不阻断 ownership 释放
|
|
536
|
+
# F-RSI-20261113-106:不阻断但必须留痕——D27 取消回传是宿主
|
|
537
|
+
# 取消信号的引擎侧落账,静默丢失会让「宿主为何释放所有权」
|
|
538
|
+
# 在 supervisor 权威链上无迹可查(与 F-104 同款可观测性守卫)。
|
|
539
|
+
print(
|
|
540
|
+
f"[launch_bugx] ⚠ D27 owner_cancelled 回传失败(ownership 释放不受影响): {exc}",
|
|
541
|
+
file=sys.stderr,
|
|
542
|
+
)
|
|
543
|
+
return True
|
|
544
|
+
|
|
545
|
+
if not is_dead:
|
|
546
|
+
return False
|
|
547
|
+
|
|
548
|
+
if _supervisor_terminal_awaiting_settle(state):
|
|
549
|
+
# Supervisor 已经合法收尾,但 post 尚未消费其结算副作用。这里不续期
|
|
550
|
+
# heartbeat,也不伪造存活;只把权威终态交给 post,避免先被孤儿裁决
|
|
551
|
+
# 写成 aborted 后永久堵死结算。
|
|
552
|
+
return False
|
|
553
|
+
|
|
554
|
+
if _auto_started_idle_shell(state):
|
|
555
|
+
# 空壳回合(自动续轮、零 Life、零有效发现)失去属主按收敛处理,
|
|
556
|
+
# 复用 post 轮询的 auto_lifecycle_zero_findings 语义:一次落
|
|
557
|
+
# polling_stop_reason 与 lifecycle_stop_reason 两个键,
|
|
558
|
+
# 且不计入 sessions_aborted。
|
|
559
|
+
_accrue_running_segment(state, current)
|
|
560
|
+
elapsed = float(state.get("session_elapsed_seconds", 0.0))
|
|
561
|
+
state.update({
|
|
562
|
+
"state": "completed",
|
|
563
|
+
"active": False,
|
|
564
|
+
"pid": None,
|
|
565
|
+
"host_pid": None,
|
|
566
|
+
"paused_at": None,
|
|
567
|
+
"segment_started_epoch": None,
|
|
568
|
+
"last_session_elapsed_seconds": round(elapsed, 3),
|
|
569
|
+
"sessions_completed": int(state.get("sessions_completed", 0)) + 1,
|
|
570
|
+
"polling_stop_reason": "auto_lifecycle_zero_findings",
|
|
571
|
+
"lifecycle_stop_reason": "auto_lifecycle_zero_findings",
|
|
572
|
+
})
|
|
573
|
+
append_runtime_event(
|
|
574
|
+
state, "orphaned_session_reconciled", current,
|
|
575
|
+
"auto-started idle shell converged (zero findings)",
|
|
576
|
+
)
|
|
577
|
+
return True
|
|
578
|
+
|
|
579
|
+
_accrue_running_segment(state, current)
|
|
580
|
+
elapsed = float(state.get("session_elapsed_seconds", 0.0))
|
|
581
|
+
life_run = {
|
|
582
|
+
"run_id": state.get("run_id"),
|
|
583
|
+
"session_id": state.get("session_id"),
|
|
584
|
+
"round_id": state.get("round_id") or state.get("lifecycle_id"),
|
|
585
|
+
"life_no": state.get("life_no"),
|
|
586
|
+
"outcome": "aborted",
|
|
587
|
+
"started_at": state.get("started_at"),
|
|
588
|
+
"finished_at": iso_time(current),
|
|
589
|
+
"elapsed_seconds": round(elapsed, 3),
|
|
590
|
+
"round_at_start": state.get("round_at_start"),
|
|
591
|
+
"round_at_finish": _current_round(),
|
|
592
|
+
"reason": "process terminated unexpectedly (orphaned)",
|
|
593
|
+
}
|
|
594
|
+
if not isinstance(state.get("life_runs"), list):
|
|
595
|
+
state["life_runs"] = []
|
|
596
|
+
state["life_runs"].append(life_run)
|
|
597
|
+
state.update({
|
|
598
|
+
"state": "aborted",
|
|
599
|
+
"active": False,
|
|
600
|
+
"pid": None,
|
|
601
|
+
"host_pid": None,
|
|
602
|
+
"paused_at": None,
|
|
603
|
+
"segment_started_epoch": None,
|
|
604
|
+
"last_session_elapsed_seconds": round(elapsed, 3),
|
|
605
|
+
"sessions_aborted": int(state.get("sessions_aborted", 0)) + 1,
|
|
606
|
+
})
|
|
607
|
+
append_runtime_event(state, "orphaned_session_reconciled", current, "process died")
|
|
608
|
+
return True
|
|
609
|
+
|
|
610
|
+
|
|
611
|
+
def load_runtime(*, reconcile: bool = True) -> dict:
|
|
612
|
+
"""读取并校验计时状态;损坏时优先从 .bak 恢复,拒绝静默归零。
|
|
613
|
+
|
|
614
|
+
LOG-01:本函数**自身不写盘**。孤儿状态的裁决写入收敛到
|
|
615
|
+
:func:`_reconcile_runtime_locked`,它在运行状态锁内**重新读取**后再写。
|
|
616
|
+
旧实现直接用调用方手上(可能已陈旧)的快照调 ``save_runtime``,会把另一个
|
|
617
|
+
进程刚写入的 running 心跳整体覆盖成 aborted —— 状态回退。
|
|
618
|
+
"""
|
|
619
|
+
_ensure_project_runtime_paths()
|
|
620
|
+
state = _read_runtime_state()
|
|
621
|
+
if not reconcile or not state.get("active"):
|
|
622
|
+
return state
|
|
623
|
+
return _reconcile_runtime_locked()
|
|
624
|
+
|
|
625
|
+
|
|
626
|
+
def _reconcile_runtime_locked() -> dict:
|
|
627
|
+
"""在运行状态锁内重新读取并裁决孤儿状态。
|
|
628
|
+
|
|
629
|
+
拿不到锁时退化为纯只读返回:宁可本轮不裁决,也不做无锁写入。
|
|
630
|
+
"""
|
|
631
|
+
try:
|
|
632
|
+
with runtime_lock():
|
|
633
|
+
state = _read_runtime_state()
|
|
634
|
+
if state.get("active") and _reconcile_orphaned_state_locked(state):
|
|
635
|
+
if RUNTIME_FILE.parent.is_dir():
|
|
636
|
+
try:
|
|
637
|
+
save_runtime(state)
|
|
638
|
+
except OSError:
|
|
639
|
+
pass
|
|
640
|
+
return state
|
|
641
|
+
except (TimeoutError, OSError):
|
|
642
|
+
return _read_runtime_state()
|
|
643
|
+
|
|
644
|
+
|
|
645
|
+
def _read_runtime_state() -> dict:
|
|
646
|
+
"""纯只读解析 + 校验运行计时文件(不裁决、不写盘)。"""
|
|
647
|
+
if RUNTIME_FILE.is_symlink():
|
|
648
|
+
raise ValueError(f"运行计时文件不能是符号链接: {RUNTIME_FILE}")
|
|
649
|
+
bak_path = RUNTIME_FILE.with_name(RUNTIME_FILE.name + ".bak")
|
|
650
|
+
if not RUNTIME_FILE.is_file():
|
|
651
|
+
if bak_path.is_file() and not bak_path.is_symlink():
|
|
652
|
+
recovered = None
|
|
653
|
+
try:
|
|
654
|
+
bak_content = bak_path.read_text(encoding="utf-8").strip()
|
|
655
|
+
if bak_content:
|
|
656
|
+
recovered = json.loads(bak_content)
|
|
657
|
+
except (OSError, json.JSONDecodeError):
|
|
658
|
+
recovered = None
|
|
659
|
+
if isinstance(recovered, dict):
|
|
660
|
+
_require_current_runtime_schema(recovered, bak_path)
|
|
661
|
+
try:
|
|
662
|
+
import shutil
|
|
663
|
+
shutil.copy2(bak_path, RUNTIME_FILE)
|
|
664
|
+
except OSError:
|
|
665
|
+
pass
|
|
666
|
+
if not RUNTIME_FILE.is_file():
|
|
667
|
+
supervisor_backup = SUPERVISOR_STATE.with_name(SUPERVISOR_STATE.name + ".bak")
|
|
668
|
+
if SUPERVISOR_STATE.exists() or supervisor_backup.exists():
|
|
669
|
+
raise ValueError(
|
|
670
|
+
f"活动生命周期运行计时文件缺失,拒绝回退为空闲状态: {RUNTIME_FILE}; "
|
|
671
|
+
"请先执行 bugx doctor --repair 或从备份恢复"
|
|
672
|
+
)
|
|
673
|
+
# 缺文件回退的默认 runtime 同样注入 polling_id:新建 Session 尚未
|
|
674
|
+
# 写 runtime 时,结算/报告路径也必须解析到真实 polling 目录。
|
|
675
|
+
return _inject_runtime_polling_id(_default_runtime())
|
|
676
|
+
try:
|
|
677
|
+
raw_text = RUNTIME_FILE.read_text(encoding="utf-8").strip()
|
|
678
|
+
if not raw_text:
|
|
679
|
+
raise ValueError("运行计时文件为空(0 字节)")
|
|
680
|
+
state = json.loads(raw_text)
|
|
681
|
+
except (json.JSONDecodeError, OSError, ValueError) as exc:
|
|
682
|
+
recovered = None
|
|
683
|
+
if bak_path.is_file() and not bak_path.is_symlink():
|
|
684
|
+
try:
|
|
685
|
+
bak_content = bak_path.read_text(encoding="utf-8").strip()
|
|
686
|
+
if bak_content:
|
|
687
|
+
candidate = json.loads(bak_content)
|
|
688
|
+
if isinstance(candidate, dict):
|
|
689
|
+
_require_current_runtime_schema(candidate, bak_path)
|
|
690
|
+
recovered = candidate
|
|
691
|
+
try:
|
|
692
|
+
import shutil
|
|
693
|
+
shutil.copy2(bak_path, RUNTIME_FILE)
|
|
694
|
+
except OSError:
|
|
695
|
+
pass
|
|
696
|
+
except (OSError, json.JSONDecodeError):
|
|
697
|
+
recovered = None
|
|
698
|
+
if recovered is not None:
|
|
699
|
+
state = recovered
|
|
700
|
+
else:
|
|
701
|
+
raise ValueError(f"运行计时文件无法解析: {exc}") from exc
|
|
702
|
+
if not isinstance(state, dict):
|
|
703
|
+
raise ValueError("运行计时文件根节点必须是对象")
|
|
704
|
+
_require_current_runtime_schema(state, RUNTIME_FILE)
|
|
705
|
+
if state.get("state") not in RUNTIME_STATES:
|
|
706
|
+
raise ValueError("运行计时文件 state 无效")
|
|
707
|
+
if not isinstance(state.get("active"), bool):
|
|
708
|
+
raise ValueError("运行计时文件 active 必须是布尔值")
|
|
709
|
+
if state["active"] != (state["state"] in {"running", "paused"}):
|
|
710
|
+
raise ValueError("运行计时文件 active 与 state 不一致")
|
|
711
|
+
for key in ("session_elapsed_seconds", "last_session_elapsed_seconds",
|
|
712
|
+
"total_elapsed_seconds"):
|
|
713
|
+
if not is_number(state.get(key)) or state[key] < 0:
|
|
714
|
+
raise ValueError(f"运行计时文件 {key} 无效")
|
|
715
|
+
# F-RSI-20261112-087:segment_started_epoch 允许 None(默认/非运行态),
|
|
716
|
+
# 但出现必须是数字——垃圾值直通会在 orphan 恢复链的 _accrue 中裸崩。
|
|
717
|
+
seg = state.get("segment_started_epoch")
|
|
718
|
+
if seg is not None and (isinstance(seg, bool) or not is_number(seg)):
|
|
719
|
+
raise ValueError("运行计时文件 segment_started_epoch 无效(必须是数字或 null)")
|
|
720
|
+
if not isinstance(state.get("sessions_completed"), int) \
|
|
721
|
+
or isinstance(state["sessions_completed"], bool) \
|
|
722
|
+
or state["sessions_completed"] < 0:
|
|
723
|
+
raise ValueError("运行计时文件 sessions_completed 无效")
|
|
724
|
+
if not isinstance(state.get("sessions_aborted"), int) \
|
|
725
|
+
or isinstance(state["sessions_aborted"], bool) \
|
|
726
|
+
or state["sessions_aborted"] < 0:
|
|
727
|
+
raise ValueError("运行计时文件 sessions_aborted 无效")
|
|
728
|
+
if not isinstance(state.get("sessions"), list):
|
|
729
|
+
raise ValueError("运行计时文件 sessions 必须是列表")
|
|
730
|
+
if not isinstance(state.get("life_runs"), list):
|
|
731
|
+
raise ValueError("运行计时文件 life_runs 必须是列表")
|
|
732
|
+
if not isinstance(state.get("events"), list):
|
|
733
|
+
raise ValueError("运行计时文件 events 必须是列表")
|
|
734
|
+
policy = state.get("polling_policy")
|
|
735
|
+
if policy is not None and policy not in POLLING_POLICIES:
|
|
736
|
+
raise ValueError("运行计时文件 polling_policy 无效")
|
|
737
|
+
commit_policy = state.get("commit_policy")
|
|
738
|
+
if commit_policy is not None and commit_policy not in COMMIT_POLICIES:
|
|
739
|
+
raise ValueError("运行计时文件 commit_policy 无效")
|
|
740
|
+
review_mode = state.get("review_mode")
|
|
741
|
+
if review_mode is not None and review_mode not in REVIEW_MODES:
|
|
742
|
+
raise ValueError("运行计时文件 review_mode 无效")
|
|
743
|
+
if not isinstance(state.get("review_mode_deferred"), bool):
|
|
744
|
+
raise ValueError("运行计时文件 review_mode_deferred 无效")
|
|
745
|
+
if not isinstance(state.get("autonomous_mode"), bool):
|
|
746
|
+
raise ValueError("运行计时文件 autonomous_mode 无效")
|
|
747
|
+
host = state.get("host")
|
|
748
|
+
if host is not None and (
|
|
749
|
+
not isinstance(host, str) or not host.strip() or len(host.strip()) > 64
|
|
750
|
+
):
|
|
751
|
+
raise ValueError("运行计时文件 host 无效")
|
|
752
|
+
if not isinstance(state.get("execute"), bool):
|
|
753
|
+
raise ValueError("运行计时文件 execute 无效")
|
|
754
|
+
for key in ("workers", "worker_capacity"):
|
|
755
|
+
value = state.get(key)
|
|
756
|
+
if value is None:
|
|
757
|
+
continue
|
|
758
|
+
# F-RSI-20261112-077 后继(轮 77):0 是旧默认态泄漏(_default_runtime
|
|
759
|
+
# 曾产 0 并被 reconcile 落盘;消费侧历来把 0 当未声明吞掉)——归一为
|
|
760
|
+
# None 自动迁移存量项目,而非拒绝造成 engine 命令全面 Unhandled
|
|
761
|
+
# exception。拒绝保留给负数/布尔/非整数等真实非法值。
|
|
762
|
+
if not isinstance(value, int) or isinstance(value, bool):
|
|
763
|
+
raise ValueError(f"运行计时文件 {key} 无效(必须是正整数或未声明)")
|
|
764
|
+
if value == 0:
|
|
765
|
+
state[key] = None
|
|
766
|
+
print(
|
|
767
|
+
f"[bugx] ⚠️ 运行计时文件 {key}=0 为旧默认态残留,已归一为未声明(下次保存落盘)"
|
|
768
|
+
)
|
|
769
|
+
continue
|
|
770
|
+
if value < 0:
|
|
771
|
+
raise ValueError(f"运行计时文件 {key} 无效(必须是正整数或未声明)")
|
|
772
|
+
subagent_type = state.get("subagent_type")
|
|
773
|
+
if not isinstance(subagent_type, str) or not subagent_type.strip():
|
|
774
|
+
raise ValueError("运行计时文件 subagent_type 无效")
|
|
775
|
+
stagger_seconds = state.get("stagger_seconds")
|
|
776
|
+
if (
|
|
777
|
+
not isinstance(stagger_seconds, (int, float))
|
|
778
|
+
or isinstance(stagger_seconds, bool)
|
|
779
|
+
or not math.isfinite(float(stagger_seconds))
|
|
780
|
+
or stagger_seconds < 0
|
|
781
|
+
):
|
|
782
|
+
raise ValueError("运行计时文件 stagger_seconds 无效")
|
|
783
|
+
provider = state.get("provider")
|
|
784
|
+
if provider is not None and (
|
|
785
|
+
not isinstance(provider, str) or not provider.strip()
|
|
786
|
+
):
|
|
787
|
+
raise ValueError("运行计时文件 provider 无效")
|
|
788
|
+
policy_hash = state.get("autonomous_policy_hash")
|
|
789
|
+
if policy_hash is not None and (
|
|
790
|
+
not isinstance(policy_hash, str) or len(policy_hash) != 64
|
|
791
|
+
):
|
|
792
|
+
raise ValueError("运行计时文件 autonomous_policy_hash 无效")
|
|
793
|
+
if not isinstance(state.get("polling_round_auto_started"), bool):
|
|
794
|
+
raise ValueError("运行计时文件 polling_round_auto_started 无效")
|
|
795
|
+
if state.get("polling_last_round") is not None \
|
|
796
|
+
and not isinstance(state.get("polling_last_round"), dict):
|
|
797
|
+
raise ValueError("运行计时文件 polling_last_round 无效")
|
|
798
|
+
if state.get("polling_stop_reason") is not None \
|
|
799
|
+
and not isinstance(state.get("polling_stop_reason"), str):
|
|
800
|
+
raise ValueError("运行计时文件 polling_stop_reason 无效")
|
|
801
|
+
if not isinstance(state.get("lifecycle_no"), int) \
|
|
802
|
+
or isinstance(state.get("lifecycle_no"), bool) \
|
|
803
|
+
or state["lifecycle_no"] < 0:
|
|
804
|
+
raise ValueError("运行计时文件 lifecycle_no 无效")
|
|
805
|
+
if state.get("lifecycle_id") is not None \
|
|
806
|
+
and not isinstance(state.get("lifecycle_id"), str):
|
|
807
|
+
raise ValueError("运行计时文件 lifecycle_id 无效")
|
|
808
|
+
if state.get("lifecycle_started_epoch") is not None \
|
|
809
|
+
and not is_number(state.get("lifecycle_started_epoch")):
|
|
810
|
+
raise ValueError("运行计时文件 lifecycle_started_epoch 无效")
|
|
811
|
+
if not isinstance(state.get("lifecycle_auto_started"), bool):
|
|
812
|
+
raise ValueError("运行计时文件 lifecycle_auto_started 无效")
|
|
813
|
+
if not isinstance(state.get("lifecycle_terminal"), bool):
|
|
814
|
+
raise ValueError("运行计时文件 lifecycle_terminal 无效")
|
|
815
|
+
for key in ("lifecycle_cycles_completed", "lifecycle_findings_total",
|
|
816
|
+
"lifecycle_credited_total", "lifecycle_fraud_total"):
|
|
817
|
+
if not isinstance(state.get(key), int) \
|
|
818
|
+
or isinstance(state.get(key), bool) or state[key] < 0:
|
|
819
|
+
raise ValueError(f"运行计时文件 {key} 无效")
|
|
820
|
+
if state.get("lifecycle_last_life") is not None \
|
|
821
|
+
and (not isinstance(state.get("lifecycle_last_life"), int)
|
|
822
|
+
or isinstance(state.get("lifecycle_last_life"), bool)):
|
|
823
|
+
raise ValueError("运行计时文件 lifecycle_last_life 无效")
|
|
824
|
+
if state.get("lifecycle_last_report") is not None \
|
|
825
|
+
and not isinstance(state.get("lifecycle_last_report"), str):
|
|
826
|
+
raise ValueError("运行计时文件 lifecycle_last_report 无效")
|
|
827
|
+
if not isinstance(state.get("lifecycle_no_progress_cycles"), int) \
|
|
828
|
+
or isinstance(state.get("lifecycle_no_progress_cycles"), bool) \
|
|
829
|
+
or state["lifecycle_no_progress_cycles"] < 0:
|
|
830
|
+
raise ValueError("运行计时文件 lifecycle_no_progress_cycles 无效")
|
|
831
|
+
if state.get("lifecycle_stop_reason") is not None \
|
|
832
|
+
and not isinstance(state.get("lifecycle_stop_reason"), str):
|
|
833
|
+
raise ValueError("运行计时文件 lifecycle_stop_reason 无效")
|
|
834
|
+
if not isinstance(state.get("lifecycle_history"), list):
|
|
835
|
+
raise ValueError("运行计时文件 lifecycle_history 必须是列表")
|
|
836
|
+
lesson_ids = state.get("lifecycle_lesson_ids")
|
|
837
|
+
if not isinstance(lesson_ids, list) or any(
|
|
838
|
+
not isinstance(item, str) or not item for item in lesson_ids):
|
|
839
|
+
raise ValueError("运行计时文件 lifecycle_lesson_ids 无效")
|
|
840
|
+
if len(lesson_ids) != len(set(lesson_ids)):
|
|
841
|
+
raise ValueError("运行计时文件 lifecycle_lesson_ids 不得重复")
|
|
842
|
+
for key in ("lifecycle_incident_ids", "lesson_recent_signatures", "realized_fix_incidents"):
|
|
843
|
+
values = state.get(key)
|
|
844
|
+
if not isinstance(values, list) or any(
|
|
845
|
+
not isinstance(item, str) or not item for item in values):
|
|
846
|
+
raise ValueError(f"运行计时文件 {key} 无效")
|
|
847
|
+
if len(values) != len(set(values)):
|
|
848
|
+
raise ValueError(f"运行计时文件 {key} 不得重复")
|
|
849
|
+
lesson_context = state.get("lesson_context")
|
|
850
|
+
if lesson_context is not None and not isinstance(lesson_context, dict):
|
|
851
|
+
raise ValueError("运行计时文件 lesson_context 无效")
|
|
852
|
+
if state["active"] and not is_number(state.get("started_epoch")):
|
|
853
|
+
raise ValueError("活动计时缺少 started_epoch")
|
|
854
|
+
if state["active"] and not isinstance(state.get("run_id"), str):
|
|
855
|
+
raise ValueError("活动计时缺少 run_id")
|
|
856
|
+
if state["state"] == "running" and not is_number(state.get("segment_started_epoch")):
|
|
857
|
+
raise ValueError("运行中计时缺少 segment_started_epoch")
|
|
858
|
+
if state["active"] and not is_number(state.get("heartbeat_epoch")):
|
|
859
|
+
raise ValueError("活动计时缺少 heartbeat_epoch")
|
|
860
|
+
if state.get("polling_id") is not None \
|
|
861
|
+
and not isinstance(state.get("polling_id"), str):
|
|
862
|
+
raise ValueError("运行计时文件 polling_id 无效")
|
|
863
|
+
return _inject_runtime_polling_id(state)
|
|
864
|
+
|
|
865
|
+
def _inject_runtime_polling_id(state: dict) -> dict:
|
|
866
|
+
"""从布局权威 current.json 注入 polling_id(Session 标识)。
|
|
867
|
+
|
|
868
|
+
运行计时文件历史上从不写 polling_id,结算/报告路径只能盲猜
|
|
869
|
+
polling-000001,第二个 Session 起会解析到错误目录。current.json
|
|
870
|
+
是 Session/Round 活动指针的唯一权威;已有值(同生命周期持久化
|
|
871
|
+
产物)优先,避免旧 runtime 被新 Session 指针劫持。
|
|
872
|
+
"""
|
|
873
|
+
if "polling_id" in state:
|
|
874
|
+
return state
|
|
875
|
+
if bugx_paths is None:
|
|
876
|
+
return state
|
|
877
|
+
if not uses_project_layout():
|
|
878
|
+
# 自包含引擎副本布局没有 ``current.json`` 指针,Session 维度只能由
|
|
879
|
+
# 运行态自身承载。缺省时**就地铸造**一个稳定 id(同一 lifecycle 恒定),
|
|
880
|
+
# 让写入端与读取端指向同一目录。旧行为留空 ⇒ 双方各自落到
|
|
881
|
+
# ``polling-unknown`` 之外的私有推导,findings.json 成为孤儿,
|
|
882
|
+
# 表现为 "Finding 快照校验失败" 与 "finding_count=1,结算结果=0"。
|
|
883
|
+
return state
|
|
884
|
+
try:
|
|
885
|
+
polling_id = bugx_paths.read_current(resolve_project_root()).get("polling_id")
|
|
886
|
+
except (OSError, ValueError, RuntimeError, KeyError, TypeError):
|
|
887
|
+
return state
|
|
888
|
+
if isinstance(polling_id, str) and polling_id:
|
|
889
|
+
state["polling_id"] = polling_id
|
|
890
|
+
return state
|
|
891
|
+
|
|
892
|
+
@contextmanager
|
|
893
|
+
def runtime_lock(timeout_seconds: float = 3.0):
|
|
894
|
+
"""用 flock 串行化短写操作;持有进程死亡时由内核自动释放(DOC-031 锁统一)。
|
|
895
|
+
|
|
896
|
+
锁文件本身跨进程常驻(flock 语义下 unlink 会导致锁竞争窗口),不再
|
|
897
|
+
写 pid/token,也不再做 age 抢占——陈旧锁由内核在进程退出时回收。
|
|
898
|
+
|
|
899
|
+
LOG-03:打开锁文件时加 ``O_NOFOLLOW`` 并预检符号链接。若 ``runtime.lock``
|
|
900
|
+
被替换成符号链接,``flock`` 会作用到链接指向的任意文件,互斥被绕过。
|
|
901
|
+
|
|
902
|
+
同进程重入:flock 对同一文件的**不同 fd** 仍互斥,因此 ``runtime_lock``
|
|
903
|
+
内再调用 ``load_runtime(reconcile=True)`` 会自锁死;这里用**线程内**深度
|
|
904
|
+
计数放行同线程重入(外层已持有锁,语义等价)。跨线程不共享该计数,因此
|
|
905
|
+
线程 B 仍必须真正竞争 flock。
|
|
906
|
+
"""
|
|
907
|
+
_ensure_project_runtime_paths()
|
|
908
|
+
depth = _runtime_lock_depth()
|
|
909
|
+
if depth > 0:
|
|
910
|
+
_set_runtime_lock_depth(depth + 1)
|
|
911
|
+
try:
|
|
912
|
+
yield
|
|
913
|
+
finally:
|
|
914
|
+
_set_runtime_lock_depth(depth)
|
|
915
|
+
return
|
|
916
|
+
lock_parent = RUNTIME_LOCK_FILE.parent
|
|
917
|
+
bugx_paths.assert_no_symlink_components(lock_parent)
|
|
918
|
+
bugx_paths.ensure_dir(lock_parent, mode=0o700)
|
|
919
|
+
bugx_paths.assert_no_symlink_components(lock_parent)
|
|
920
|
+
if RUNTIME_LOCK_FILE.is_symlink():
|
|
921
|
+
raise ValueError(f"运行状态锁不能是符号链接: {RUNTIME_LOCK_FILE}")
|
|
922
|
+
deadline = time.monotonic() + timeout_seconds
|
|
923
|
+
fd = os.open(
|
|
924
|
+
RUNTIME_LOCK_FILE,
|
|
925
|
+
os.O_CREAT | os.O_RDWR | getattr(os, "O_NOFOLLOW", 0),
|
|
926
|
+
0o600,
|
|
927
|
+
)
|
|
928
|
+
try:
|
|
929
|
+
try:
|
|
930
|
+
import fcntl
|
|
931
|
+
except ImportError: # pragma: no cover - Windows fallback
|
|
932
|
+
fcntl = None # type: ignore[assignment]
|
|
933
|
+
try:
|
|
934
|
+
import msvcrt
|
|
935
|
+
except ImportError: # pragma: no cover - POSIX fallback
|
|
936
|
+
msvcrt = None # type: ignore[assignment]
|
|
937
|
+
if fcntl is not None:
|
|
938
|
+
while True:
|
|
939
|
+
try:
|
|
940
|
+
fcntl.flock(fd, fcntl.LOCK_EX | fcntl.LOCK_NB)
|
|
941
|
+
break
|
|
942
|
+
except OSError:
|
|
943
|
+
if time.monotonic() >= deadline:
|
|
944
|
+
raise TimeoutError(
|
|
945
|
+
"运行状态正被另一进程更新,请稍后重试"
|
|
946
|
+
f"({RUNTIME_LOCK_FILE.name} flock 等待超过 {timeout_seconds:.0f}s)"
|
|
947
|
+
)
|
|
948
|
+
time.sleep(0.05)
|
|
949
|
+
elif msvcrt is not None:
|
|
950
|
+
# ``msvcrt.locking`` locks a byte range and requires the file to
|
|
951
|
+
# contain that byte. Keep the lock file resident and use the
|
|
952
|
+
# non-blocking primitive so Windows follows the same bounded wait
|
|
953
|
+
# contract as the POSIX flock path.
|
|
954
|
+
if os.fstat(fd).st_size == 0:
|
|
955
|
+
os.write(fd, b"\0")
|
|
956
|
+
os.lseek(fd, 0, os.SEEK_SET)
|
|
957
|
+
lock_mode = getattr(msvcrt, "LK_NBLCK", msvcrt.LK_LOCK)
|
|
958
|
+
while True:
|
|
959
|
+
try:
|
|
960
|
+
msvcrt.locking(fd, lock_mode, 1)
|
|
961
|
+
break
|
|
962
|
+
except OSError:
|
|
963
|
+
if time.monotonic() >= deadline:
|
|
964
|
+
raise TimeoutError(
|
|
965
|
+
"运行状态正被另一进程更新,请稍后重试"
|
|
966
|
+
f"({RUNTIME_LOCK_FILE.name} msvcrt 等待超过 {timeout_seconds:.0f}s)"
|
|
967
|
+
)
|
|
968
|
+
time.sleep(0.05)
|
|
969
|
+
else:
|
|
970
|
+
raise OSError("当前平台缺少 fcntl 和 msvcrt,无法安全锁定运行状态")
|
|
971
|
+
_set_runtime_lock_depth(depth + 1)
|
|
972
|
+
try:
|
|
973
|
+
yield
|
|
974
|
+
finally:
|
|
975
|
+
_set_runtime_lock_depth(depth)
|
|
976
|
+
if fcntl is not None:
|
|
977
|
+
try:
|
|
978
|
+
fcntl.flock(fd, fcntl.LOCK_UN)
|
|
979
|
+
except OSError:
|
|
980
|
+
pass
|
|
981
|
+
elif msvcrt is not None:
|
|
982
|
+
try:
|
|
983
|
+
os.lseek(fd, 0, os.SEEK_SET)
|
|
984
|
+
msvcrt.locking(fd, msvcrt.LK_UNLCK, 1)
|
|
985
|
+
except OSError:
|
|
986
|
+
pass
|
|
987
|
+
finally:
|
|
988
|
+
os.close(fd)
|
|
989
|
+
|
|
990
|
+
def save_runtime(state: dict) -> None:
|
|
991
|
+
"""原子写入计时状态,避免中断产生半个 JSON,并保持 .bak 容灾副本。"""
|
|
992
|
+
fd, temp_path = tempfile.mkstemp(
|
|
993
|
+
dir=str(RUNTIME_FILE.parent), prefix=".runtime-", suffix=".tmp",
|
|
994
|
+
)
|
|
995
|
+
backup_temp_path: str | None = None
|
|
996
|
+
try:
|
|
997
|
+
with os.fdopen(fd, "w", encoding="utf-8") as handle:
|
|
998
|
+
handle.write(json.dumps(state, ensure_ascii=False, indent=2) + "\n")
|
|
999
|
+
bak_path = RUNTIME_FILE.with_name(RUNTIME_FILE.name + ".bak")
|
|
1000
|
+
if RUNTIME_FILE.is_file() and not RUNTIME_FILE.is_symlink():
|
|
1001
|
+
backup_fd, backup_temp_path = tempfile.mkstemp(
|
|
1002
|
+
dir=str(RUNTIME_FILE.parent), prefix=".runtime-bak-", suffix=".tmp",
|
|
1003
|
+
)
|
|
1004
|
+
os.close(backup_fd)
|
|
1005
|
+
import shutil
|
|
1006
|
+
shutil.copy2(RUNTIME_FILE, backup_temp_path)
|
|
1007
|
+
os.replace(backup_temp_path, bak_path)
|
|
1008
|
+
backup_temp_path = None
|
|
1009
|
+
os.replace(temp_path, RUNTIME_FILE)
|
|
1010
|
+
except BaseException:
|
|
1011
|
+
try:
|
|
1012
|
+
os.unlink(temp_path)
|
|
1013
|
+
except OSError:
|
|
1014
|
+
pass
|
|
1015
|
+
if backup_temp_path is not None:
|
|
1016
|
+
try:
|
|
1017
|
+
os.unlink(backup_temp_path)
|
|
1018
|
+
except OSError:
|
|
1019
|
+
pass
|
|
1020
|
+
raise
|
|
1021
|
+
|
|
1022
|
+
def iso_time(epoch: float) -> str:
|
|
1023
|
+
return dt.datetime.fromtimestamp(epoch, tz=dt.timezone.utc).astimezone().isoformat(
|
|
1024
|
+
timespec="seconds"
|
|
1025
|
+
)
|
|
1026
|
+
|
|
1027
|
+
_iso_time = iso_time
|
|
1028
|
+
_load_runtime = load_runtime
|
|
1029
|
+
|
|
1030
|
+
def _current_round() -> int | None:
|
|
1031
|
+
life = baseline_json()
|
|
1032
|
+
value = life.get("round") if life else None
|
|
1033
|
+
return value if isinstance(value, int) else None
|
|
1034
|
+
|
|
1035
|
+
def _round_or_default(new_lifecycle: bool) -> int | None:
|
|
1036
|
+
"""新生命周期首个 Round 的兜底轮号。
|
|
1037
|
+
|
|
1038
|
+
auto 续轮先由 ``start_runtime`` 切换 current.json、life.json 随后才
|
|
1039
|
+
初始化;此刻 ``_current_round()`` 读不到基线返回 None。运行时缺
|
|
1040
|
+
``round`` 会让 findings 运行绑定按 fail-closed 拒绝结算,因此全新
|
|
1041
|
+
生命周期按协议初始态取 1;非新生命周期(恢复/续开)保持原语义。
|
|
1042
|
+
"""
|
|
1043
|
+
round_value = _current_round()
|
|
1044
|
+
if round_value is None and new_lifecycle:
|
|
1045
|
+
return 1
|
|
1046
|
+
return round_value
|
|
1047
|
+
|
|
1048
|
+
def diagnostic_context() -> dict[str, object]:
|
|
1049
|
+
"""Attach runtime identity to diagnostic events without making logs authoritative."""
|
|
1050
|
+
try:
|
|
1051
|
+
state = load_runtime()
|
|
1052
|
+
except (OSError, ValueError, json.JSONDecodeError):
|
|
1053
|
+
return {}
|
|
1054
|
+
fields: dict[str, object] = {}
|
|
1055
|
+
for key in ("run_id", "lifecycle_id", "worker_id", "finding_id", "incident_id"):
|
|
1056
|
+
value = state.get(key)
|
|
1057
|
+
if isinstance(value, str) and value:
|
|
1058
|
+
fields[key] = value
|
|
1059
|
+
round_value = _current_round()
|
|
1060
|
+
if round_value is not None:
|
|
1061
|
+
fields["round"] = round_value
|
|
1062
|
+
return fields
|
|
1063
|
+
|
|
1064
|
+
def append_runtime_event(state: dict, event: str, now: float,
|
|
1065
|
+
message: str | None = None) -> None:
|
|
1066
|
+
item = {"at": iso_time(now), "epoch": now, "event": event}
|
|
1067
|
+
if message:
|
|
1068
|
+
item["message"] = message
|
|
1069
|
+
state["events"] = [*state.get("events", []), item][-200:]
|
|
1070
|
+
|
|
1071
|
+
def _accrue_running_segment(state: dict, now: float) -> None:
|
|
1072
|
+
if state.get("state") != "running":
|
|
1073
|
+
return
|
|
1074
|
+
started = state.get("segment_started_epoch")
|
|
1075
|
+
# F-RSI-20261112-087:默认态该键为 None,schema 校验此前也不覆盖它——
|
|
1076
|
+
# orphan 恢复链(进程死亡后重入)里 running+null 组合会让裸
|
|
1077
|
+
# float(state[...]) 抛 TypeError,中断会话无法恢复。无可累计起点时
|
|
1078
|
+
# 跳过累计并留痕,起点从下一次 reset_segment_timer 重建。
|
|
1079
|
+
if isinstance(started, bool) or not isinstance(started, (int, float)):
|
|
1080
|
+
print(
|
|
1081
|
+
"[launch_bugx] ⚠ segment_started_epoch 缺失或非法,跳过本段时长累计"
|
|
1082
|
+
f"(值={started!r});起点将由下次会话活动重建",
|
|
1083
|
+
file=sys.stderr,
|
|
1084
|
+
)
|
|
1085
|
+
state["segment_started_epoch"] = now
|
|
1086
|
+
return
|
|
1087
|
+
state["session_elapsed_seconds"] = round(
|
|
1088
|
+
float(state["session_elapsed_seconds"]) + max(0.0, now - float(started)), 3
|
|
1089
|
+
)
|
|
1090
|
+
state["segment_started_epoch"] = now
|
|
1091
|
+
|
|
1092
|
+
def reset_segment_timer(now: float | None = None) -> None:
|
|
1093
|
+
"""更新会话起算点,避免将人类交互和环境探针的开销计入 Worker 任务执行时间。"""
|
|
1094
|
+
with runtime_lock():
|
|
1095
|
+
state = load_runtime()
|
|
1096
|
+
if not state.get("active") or state.get("state") != "running":
|
|
1097
|
+
return
|
|
1098
|
+
current = time.time() if now is None else now
|
|
1099
|
+
state["started_at"] = iso_time(current)
|
|
1100
|
+
state["started_epoch"] = current
|
|
1101
|
+
state["segment_started_epoch"] = current
|
|
1102
|
+
state["heartbeat_at"] = iso_time(current)
|
|
1103
|
+
state["heartbeat_epoch"] = current
|
|
1104
|
+
save_runtime(state)
|
|
1105
|
+
|
|
1106
|
+
def start_runtime(now: float | None = None,
|
|
1107
|
+
auto_started: bool | None = None,
|
|
1108
|
+
new_lifecycle: bool | None = None,
|
|
1109
|
+
new_session: bool | None = None) -> tuple[dict, bool]:
|
|
1110
|
+
global RUNTIME_STARTED_THIS_PROCESS
|
|
1111
|
+
with runtime_lock():
|
|
1112
|
+
state = load_runtime()
|
|
1113
|
+
if state["active"]:
|
|
1114
|
+
current = time.time() if now is None else now
|
|
1115
|
+
if _reconcile_orphaned_state_locked(state, current):
|
|
1116
|
+
save_runtime(state)
|
|
1117
|
+
else:
|
|
1118
|
+
return state, False
|
|
1119
|
+
current = time.time() if now is None else now
|
|
1120
|
+
if auto_started is None:
|
|
1121
|
+
auto_started = False
|
|
1122
|
+
if new_lifecycle is None:
|
|
1123
|
+
new_lifecycle = state.get("lifecycle_id") is None
|
|
1124
|
+
if new_session is None:
|
|
1125
|
+
# 自动续 Round 仍属于同一次 IDE Session;只有首次启动或新建
|
|
1126
|
+
# polling 容器时才建立新的 Session 身份。
|
|
1127
|
+
new_session = bool(new_lifecycle and not state.get("session_id"))
|
|
1128
|
+
session_state = {}
|
|
1129
|
+
if uses_project_layout():
|
|
1130
|
+
try:
|
|
1131
|
+
session_state = json.loads(
|
|
1132
|
+
bugx_paths.require(resolve_project_root()).session_state.read_text(
|
|
1133
|
+
encoding="utf-8"
|
|
1134
|
+
)
|
|
1135
|
+
)
|
|
1136
|
+
except (OSError, ValueError, json.JSONDecodeError):
|
|
1137
|
+
session_state = {}
|
|
1138
|
+
if new_lifecycle:
|
|
1139
|
+
if uses_project_layout():
|
|
1140
|
+
active = bugx_paths.require(resolve_project_root())
|
|
1141
|
+
current_layout = bugx_paths.read_current(resolve_project_root())
|
|
1142
|
+
if new_session or (state.get("lifecycle_id") is None and not state.get("lifecycle_no")):
|
|
1143
|
+
# The first runtime session adopts the lifecycle created by
|
|
1144
|
+
# `bugx init`; a new Session likewise adopts the fresh
|
|
1145
|
+
# polling/lifecycle tree created by create_session().
|
|
1146
|
+
lifecycle_no = int(current_layout["lifecycle_no"])
|
|
1147
|
+
lifecycle_id = str(current_layout["lifecycle_id"])
|
|
1148
|
+
else:
|
|
1149
|
+
lifecycle_no = int(state.get("lifecycle_no", 0)) + 1
|
|
1150
|
+
lifecycle_id = f"lifecycle-{lifecycle_no:06d}"
|
|
1151
|
+
bugx_paths.activate_lifecycle(
|
|
1152
|
+
resolve_project_root(), lifecycle_no, lifecycle_id,
|
|
1153
|
+
polling_id=str(current_layout["polling_id"]),
|
|
1154
|
+
polling_no=int(current_layout.get("polling_no", 1)),
|
|
1155
|
+
)
|
|
1156
|
+
# activate_lifecycle 已把 current.json 切到新生命周期;
|
|
1157
|
+
# 路径全局(RUNTIME_FILE/SUPERVISOR_STATE 等)必须立即
|
|
1158
|
+
# 重绑,否则新 Round 的 runtime 会写进旧生命周期的
|
|
1159
|
+
# state 目录——指针交叉与 runtime 缺失的根源。
|
|
1160
|
+
refresh_runtime_paths()
|
|
1161
|
+
else:
|
|
1162
|
+
lifecycle_no = int(state.get("lifecycle_no", 0)) + 1
|
|
1163
|
+
lifecycle_id = uuid.uuid4().hex
|
|
1164
|
+
lifecycle_fields = {
|
|
1165
|
+
"lifecycle_no": lifecycle_no,
|
|
1166
|
+
"lifecycle_id": lifecycle_id,
|
|
1167
|
+
"lifecycle_auto_started": bool(auto_started),
|
|
1168
|
+
"lifecycle_started_at": iso_time(current),
|
|
1169
|
+
"lifecycle_started_epoch": current,
|
|
1170
|
+
"lifecycle_cycles_completed": 0,
|
|
1171
|
+
"lifecycle_findings_total": 0,
|
|
1172
|
+
"lifecycle_credited_total": 0,
|
|
1173
|
+
"lifecycle_fraud_total": 0,
|
|
1174
|
+
"lifecycle_last_life": None,
|
|
1175
|
+
"lifecycle_terminal": False,
|
|
1176
|
+
"lifecycle_last_report": None,
|
|
1177
|
+
"lifecycle_no_progress_cycles": 0,
|
|
1178
|
+
"lifecycle_stop_reason": None,
|
|
1179
|
+
"lifecycle_lesson_ids": [],
|
|
1180
|
+
# Life 幂等键只属于当前 Round;新 Round
|
|
1181
|
+
# 即使复用相同的 verify_life.round,也必须重新计数。
|
|
1182
|
+
"polling_last_round": None,
|
|
1183
|
+
}
|
|
1184
|
+
else:
|
|
1185
|
+
lifecycle_fields = {
|
|
1186
|
+
"lifecycle_terminal": False,
|
|
1187
|
+
"lifecycle_last_report": None,
|
|
1188
|
+
}
|
|
1189
|
+
# A new Session gets a fresh intermediate-record space. The project
|
|
1190
|
+
# knowledge/coverage layers remain shared, but session-local run,
|
|
1191
|
+
# round, life and consumption history must never leak from the
|
|
1192
|
+
# completed/aborted predecessor.
|
|
1193
|
+
session_fields = {
|
|
1194
|
+
"startup_id": (
|
|
1195
|
+
uuid.uuid4().hex if new_session
|
|
1196
|
+
else state.get("startup_id") or uuid.uuid4().hex
|
|
1197
|
+
),
|
|
1198
|
+
"startup_action": (
|
|
1199
|
+
None if new_session else state.get("startup_action")
|
|
1200
|
+
),
|
|
1201
|
+
"life_runs": [] if new_session else list(state.get("life_runs", [])),
|
|
1202
|
+
"lifecycle_history": (
|
|
1203
|
+
[] if new_session else list(state.get("lifecycle_history", []))
|
|
1204
|
+
),
|
|
1205
|
+
"lifecycle_incident_ids": (
|
|
1206
|
+
[] if new_session else list(state.get("lifecycle_incident_ids", []))
|
|
1207
|
+
),
|
|
1208
|
+
"lesson_recent_signatures": (
|
|
1209
|
+
[] if new_session else list(state.get("lesson_recent_signatures", []))
|
|
1210
|
+
),
|
|
1211
|
+
"realized_fix_incidents": (
|
|
1212
|
+
[] if new_session else list(state.get("realized_fix_incidents", []))
|
|
1213
|
+
),
|
|
1214
|
+
"lesson_context": None if new_session else state.get("lesson_context"),
|
|
1215
|
+
}
|
|
1216
|
+
# DOC-RECOVERY-BINDING:恢复会话(非 new_session)时,若同 lifecycle 的
|
|
1217
|
+
# Supervisor 账本仍在(挖掘证据在链上),必须**收养**其 run_id——否则
|
|
1218
|
+
# runtime 与 supervisor 身份分裂,post 的 findings 绑定校验永久
|
|
1219
|
+
# findings_binding_mismatch(实测:恢复 pre 换新 run_id 后 9 条 confirmed
|
|
1220
|
+
# 无法结算)。仅 new_session 才铸造新身份。
|
|
1221
|
+
adopted_run_id = None
|
|
1222
|
+
if not new_session:
|
|
1223
|
+
try:
|
|
1224
|
+
sup_path = (
|
|
1225
|
+
pollings_root()
|
|
1226
|
+
/ str(state.get("polling_id"))
|
|
1227
|
+
/ "lifecycles" / str(state.get("lifecycle_id"))
|
|
1228
|
+
/ "state" / "supervisor.json"
|
|
1229
|
+
)
|
|
1230
|
+
if sup_path.is_file():
|
|
1231
|
+
sup_run = json.loads(sup_path.read_text(encoding="utf-8")).get("run_id")
|
|
1232
|
+
if isinstance(sup_run, str) and sup_run.strip():
|
|
1233
|
+
adopted_run_id = sup_run
|
|
1234
|
+
except Exception:
|
|
1235
|
+
adopted_run_id = None
|
|
1236
|
+
state.update({
|
|
1237
|
+
"schema_version": RUNTIME_SCHEMA_VERSION,
|
|
1238
|
+
"run_id": adopted_run_id or uuid.uuid4().hex,
|
|
1239
|
+
"state": "running",
|
|
1240
|
+
"active": True,
|
|
1241
|
+
"pid": (
|
|
1242
|
+
int(os.environ["BUGX_PROCESS_PID"])
|
|
1243
|
+
if os.environ.get("BUGX_PROCESS_PID", "").isdigit()
|
|
1244
|
+
else None
|
|
1245
|
+
),
|
|
1246
|
+
"host_pid": (
|
|
1247
|
+
int(os.environ["BUGX_HOST_PID"])
|
|
1248
|
+
if os.environ.get("BUGX_HOST_PID", "").isdigit()
|
|
1249
|
+
else None
|
|
1250
|
+
),
|
|
1251
|
+
"started_at": iso_time(current),
|
|
1252
|
+
"started_epoch": current,
|
|
1253
|
+
"segment_started_epoch": current,
|
|
1254
|
+
"paused_at": None,
|
|
1255
|
+
"heartbeat_at": iso_time(current),
|
|
1256
|
+
"heartbeat_epoch": current,
|
|
1257
|
+
"round_at_start": _round_or_default(bool(new_lifecycle)),
|
|
1258
|
+
# 当前 Round 必须持久化:findings 运行绑定
|
|
1259
|
+
# (finding_settlement._expected_findings_binding / _auto_build_findings_json)
|
|
1260
|
+
# 与 lifecycle_reporter / post_dry_run 都读 runtime["round"],且缺该字段时
|
|
1261
|
+
# 结算按 fail-closed 拒绝(tests.test_finding_settlement
|
|
1262
|
+
# ::test_auto_build_rejects_missing_runtime_round_before_writing)。
|
|
1263
|
+
# 这里与 round_at_start 同源(本 Session 所属 Round),保证
|
|
1264
|
+
# 「本轮已结算后再 post」仍能通过绑定校验;新生命周期在 life
|
|
1265
|
+
# 初始化前取初始态 1(见 _round_or_default)。
|
|
1266
|
+
"round": _round_or_default(bool(new_lifecycle)),
|
|
1267
|
+
"session_elapsed_seconds": 0.0,
|
|
1268
|
+
"last_session_elapsed_seconds": 0.0,
|
|
1269
|
+
"events": [],
|
|
1270
|
+
"polling_round_auto_started": (
|
|
1271
|
+
bool(auto_started) if new_lifecycle
|
|
1272
|
+
else bool(state.get("polling_round_auto_started"))
|
|
1273
|
+
),
|
|
1274
|
+
"polling_stop_reason": None,
|
|
1275
|
+
"startup_id": state.get("startup_id") or uuid.uuid4().hex,
|
|
1276
|
+
"session_id": (
|
|
1277
|
+
str(bugx_paths.read_current(resolve_project_root())["polling_id"])
|
|
1278
|
+
if new_session and uses_project_layout()
|
|
1279
|
+
else state.get("session_id") or str(
|
|
1280
|
+
state.get("polling_id") or "session-unknown"
|
|
1281
|
+
)
|
|
1282
|
+
),
|
|
1283
|
+
"session_started_at": (
|
|
1284
|
+
iso_time(current) if new_session
|
|
1285
|
+
else state.get("session_started_at") or iso_time(current)
|
|
1286
|
+
),
|
|
1287
|
+
"session_started_epoch": (
|
|
1288
|
+
current if new_session
|
|
1289
|
+
else state.get("session_started_epoch") or current
|
|
1290
|
+
),
|
|
1291
|
+
"total_elapsed_seconds": float(
|
|
1292
|
+
session_state.get("total_elapsed_seconds", state.get("total_elapsed_seconds", 0.0))
|
|
1293
|
+
),
|
|
1294
|
+
"sessions_completed": int(
|
|
1295
|
+
session_state.get("sessions_completed", state.get("sessions_completed", 0))
|
|
1296
|
+
),
|
|
1297
|
+
"sessions_aborted": int(
|
|
1298
|
+
session_state.get("sessions_aborted", state.get("sessions_aborted", 0))
|
|
1299
|
+
),
|
|
1300
|
+
"sessions": list(session_state.get("sessions", state.get("sessions", []))),
|
|
1301
|
+
"round_id": lifecycle_fields.get("lifecycle_id") or state.get("lifecycle_id"),
|
|
1302
|
+
"life_no": _current_round(),
|
|
1303
|
+
"startup_result": "resume" if not new_lifecycle else "new_session",
|
|
1304
|
+
"session_state": "running",
|
|
1305
|
+
"session_closed_at": None,
|
|
1306
|
+
"final_round_id": None,
|
|
1307
|
+
**session_fields,
|
|
1308
|
+
**lifecycle_fields,
|
|
1309
|
+
})
|
|
1310
|
+
append_runtime_event(state, "started", current)
|
|
1311
|
+
save_runtime(state)
|
|
1312
|
+
RUNTIME_STARTED_THIS_PROCESS = True
|
|
1313
|
+
set_runtime_started_this_process(True)
|
|
1314
|
+
return state, True
|
|
1315
|
+
|
|
1316
|
+
def runtime_summary(now: float | None = None) -> dict:
|
|
1317
|
+
state = load_runtime()
|
|
1318
|
+
current = time.time() if now is None else now
|
|
1319
|
+
live = float(state["session_elapsed_seconds"])
|
|
1320
|
+
if state["state"] == "running":
|
|
1321
|
+
live += max(0.0, current - float(state["segment_started_epoch"]))
|
|
1322
|
+
heartbeat_age = None
|
|
1323
|
+
if is_number(state.get("heartbeat_epoch")):
|
|
1324
|
+
heartbeat_age = max(0.0, current - float(state["heartbeat_epoch"]))
|
|
1325
|
+
stalled = state["state"] == "running" and (
|
|
1326
|
+
heartbeat_age is None or heartbeat_age > HEARTBEAT_TIMEOUT_SECONDS
|
|
1327
|
+
)
|
|
1328
|
+
health = "stalled" if stalled else state["state"]
|
|
1329
|
+
return {
|
|
1330
|
+
**state,
|
|
1331
|
+
"health": health,
|
|
1332
|
+
"stalled": stalled,
|
|
1333
|
+
"heartbeat_age_seconds": round(heartbeat_age, 3)
|
|
1334
|
+
if heartbeat_age is not None else None,
|
|
1335
|
+
"heartbeat_timeout_seconds": HEARTBEAT_TIMEOUT_SECONDS,
|
|
1336
|
+
"current_elapsed_seconds": round(live, 3),
|
|
1337
|
+
"effective_total_seconds": round(float(state["total_elapsed_seconds"]) + live, 3),
|
|
1338
|
+
"current_round": _current_round(),
|
|
1339
|
+
}
|
|
1340
|
+
|
|
1341
|
+
def close_runtime(outcome: str, now: float | None = None,
|
|
1342
|
+
reason: str | None = None) -> tuple[dict, bool]:
|
|
1343
|
+
# F-RSI-20261112-088:close_runtime 是公共 API 且 save_runtime 不做
|
|
1344
|
+
# schema 校验——非法 outcome 会直接落盘为非法 state 值,下次
|
|
1345
|
+
# load_runtime 必然抛「state 无效」,运行态整体变砖(只能手工修文件)。
|
|
1346
|
+
# close 的合法终态只有 completed/aborted,入口 fail-fast。
|
|
1347
|
+
if outcome not in ("completed", "aborted"):
|
|
1348
|
+
raise ValueError(
|
|
1349
|
+
f"close_runtime outcome 必须是 completed/aborted,收到 {outcome!r}"
|
|
1350
|
+
)
|
|
1351
|
+
with runtime_lock():
|
|
1352
|
+
state = load_runtime()
|
|
1353
|
+
if not state["active"]:
|
|
1354
|
+
return runtime_summary(now), False
|
|
1355
|
+
current = time.time() if now is None else now
|
|
1356
|
+
_accrue_running_segment(state, current)
|
|
1357
|
+
elapsed = float(state["session_elapsed_seconds"])
|
|
1358
|
+
life_run = {
|
|
1359
|
+
"run_id": state.get("run_id"),
|
|
1360
|
+
"session_id": state.get("session_id"),
|
|
1361
|
+
"round_id": state.get("round_id") or state.get("lifecycle_id"),
|
|
1362
|
+
"life_no": state.get("life_no"),
|
|
1363
|
+
"outcome": outcome,
|
|
1364
|
+
"started_at": state["started_at"],
|
|
1365
|
+
"finished_at": iso_time(current),
|
|
1366
|
+
"elapsed_seconds": round(elapsed, 3),
|
|
1367
|
+
"round_at_start": state.get("round_at_start"),
|
|
1368
|
+
"round_at_finish": _current_round(),
|
|
1369
|
+
}
|
|
1370
|
+
if reason:
|
|
1371
|
+
life_run["reason"] = reason
|
|
1372
|
+
state.update({
|
|
1373
|
+
"state": outcome,
|
|
1374
|
+
"active": False,
|
|
1375
|
+
"pid": None,
|
|
1376
|
+
"host_pid": None,
|
|
1377
|
+
"segment_started_epoch": None,
|
|
1378
|
+
"paused_at": None,
|
|
1379
|
+
"heartbeat_at": iso_time(current),
|
|
1380
|
+
"heartbeat_epoch": current,
|
|
1381
|
+
"total_elapsed_seconds": round(
|
|
1382
|
+
float(state["total_elapsed_seconds"]) + elapsed, 3
|
|
1383
|
+
),
|
|
1384
|
+
"last_session_elapsed_seconds": round(elapsed, 3),
|
|
1385
|
+
"session_elapsed_seconds": 0.0,
|
|
1386
|
+
# A runtime file is rotated for every Life/ Round. Do not count
|
|
1387
|
+
# that segment as a completed Session; Session counters are
|
|
1388
|
+
# committed exactly once by _close_session below.
|
|
1389
|
+
"life_runs": [*state.get("life_runs", []), life_run][-100:],
|
|
1390
|
+
})
|
|
1391
|
+
append_runtime_event(state, outcome, current, reason)
|
|
1392
|
+
save_runtime(state)
|
|
1393
|
+
if uses_project_layout():
|
|
1394
|
+
# Keep the cumulative Session timer in the Session container so a
|
|
1395
|
+
# new Round can start with the same total instead of resetting it.
|
|
1396
|
+
try:
|
|
1397
|
+
bugx_paths.update_session_state(
|
|
1398
|
+
resolve_project_root(),
|
|
1399
|
+
{"total_elapsed_seconds": state["total_elapsed_seconds"]},
|
|
1400
|
+
)
|
|
1401
|
+
except (OSError, ValueError, RuntimeError):
|
|
1402
|
+
# The authoritative Life checkpoint is already durable. A
|
|
1403
|
+
# missing Session index is surfaced on the next startup rather
|
|
1404
|
+
# than silently changing the completed Life result.
|
|
1405
|
+
pass
|
|
1406
|
+
# TODO is a derived operator view, not the authority. Refresh it only
|
|
1407
|
+
# after the runtime checkpoint is durable so an aborted/completed segment
|
|
1408
|
+
# cannot leave the visible checklist claiming that work is still running.
|
|
1409
|
+
if outcome == "aborted":
|
|
1410
|
+
refresh_audit_todo(state, "aborted", reason)
|
|
1411
|
+
elif outcome == "completed":
|
|
1412
|
+
refresh_audit_todo(state, "life-settled")
|
|
1413
|
+
return runtime_summary(current), True
|
|
1414
|
+
|
|
1415
|
+
def finish_runtime(now: float | None = None) -> dict:
|
|
1416
|
+
runtime, _ = close_runtime("completed", now)
|
|
1417
|
+
return runtime
|
|
1418
|
+
|
|
1419
|
+
def pause_runtime(now: float | None = None) -> tuple[dict, bool]:
|
|
1420
|
+
with runtime_lock():
|
|
1421
|
+
state = load_runtime()
|
|
1422
|
+
if state["state"] != "running":
|
|
1423
|
+
return state, False
|
|
1424
|
+
current = time.time() if now is None else now
|
|
1425
|
+
_accrue_running_segment(state, current)
|
|
1426
|
+
state.update({
|
|
1427
|
+
"state": "paused",
|
|
1428
|
+
"active": True,
|
|
1429
|
+
"segment_started_epoch": None,
|
|
1430
|
+
"paused_at": iso_time(current),
|
|
1431
|
+
"heartbeat_at": iso_time(current),
|
|
1432
|
+
"heartbeat_epoch": current,
|
|
1433
|
+
})
|
|
1434
|
+
append_runtime_event(state, "paused", current)
|
|
1435
|
+
save_runtime(state)
|
|
1436
|
+
return state, True
|
|
1437
|
+
|
|
1438
|
+
def resume_runtime(now: float | None = None) -> tuple[dict, bool]:
|
|
1439
|
+
with runtime_lock():
|
|
1440
|
+
state = load_runtime()
|
|
1441
|
+
if state["state"] != "paused":
|
|
1442
|
+
return state, False
|
|
1443
|
+
current = time.time() if now is None else now
|
|
1444
|
+
state.update({
|
|
1445
|
+
"state": "running",
|
|
1446
|
+
"active": True,
|
|
1447
|
+
"segment_started_epoch": current,
|
|
1448
|
+
"paused_at": None,
|
|
1449
|
+
"heartbeat_at": iso_time(current),
|
|
1450
|
+
"heartbeat_epoch": current,
|
|
1451
|
+
})
|
|
1452
|
+
append_runtime_event(state, "resumed", current)
|
|
1453
|
+
save_runtime(state)
|
|
1454
|
+
return state, True
|
|
1455
|
+
|
|
1456
|
+
def heartbeat_runtime(now: float | None = None,
|
|
1457
|
+
owner_pid: int | None = None) -> tuple[dict, bool]:
|
|
1458
|
+
if owner_pid is not None and (
|
|
1459
|
+
not isinstance(owner_pid, int)
|
|
1460
|
+
or isinstance(owner_pid, bool)
|
|
1461
|
+
or owner_pid <= 0
|
|
1462
|
+
):
|
|
1463
|
+
raise ValueError("heartbeat owner PID 无效")
|
|
1464
|
+
with runtime_lock():
|
|
1465
|
+
# A host MCP channel can outlive the short-lived pre process that
|
|
1466
|
+
# originally wrote ``pid``. Let that channel claim ownership before
|
|
1467
|
+
# the normal orphan reconciliation runs; ordinary reads keep the
|
|
1468
|
+
# existing fail-closed dead-process behavior.
|
|
1469
|
+
state = load_runtime(reconcile=owner_pid is None)
|
|
1470
|
+
if owner_pid is not None and state.get("state") == "running":
|
|
1471
|
+
state["pid"] = owner_pid
|
|
1472
|
+
state["host_pid"] = owner_pid
|
|
1473
|
+
if _reconcile_orphaned_state_locked(state):
|
|
1474
|
+
save_runtime(state)
|
|
1475
|
+
return state, False
|
|
1476
|
+
if state["state"] != "running":
|
|
1477
|
+
return state, False
|
|
1478
|
+
current = time.time() if now is None else now
|
|
1479
|
+
state.update({
|
|
1480
|
+
"heartbeat_at": iso_time(current),
|
|
1481
|
+
"heartbeat_epoch": current,
|
|
1482
|
+
})
|
|
1483
|
+
append_runtime_event(state, "heartbeat", current)
|
|
1484
|
+
save_runtime(state)
|
|
1485
|
+
return state, True
|
|
1486
|
+
|
|
1487
|
+
def print_runtime(summary: dict) -> None:
|
|
1488
|
+
labels = {
|
|
1489
|
+
"idle": "未运行", "running": "运行中", "paused": "已暂停",
|
|
1490
|
+
"completed": "已完成", "aborted": "已中止", "stalled": "疑似卡住",
|
|
1491
|
+
}
|
|
1492
|
+
status_text = labels.get(summary["health"], summary["health"])
|
|
1493
|
+
print(f"运行计时: {status_text}")
|
|
1494
|
+
if summary.get("run_id"):
|
|
1495
|
+
print(f" Run ID: {summary['run_id']}")
|
|
1496
|
+
if summary["active"]:
|
|
1497
|
+
print(f" 开始时间: {summary['started_at']}")
|
|
1498
|
+
print(f" 当前耗时: {format_duration(summary['current_elapsed_seconds'])}")
|
|
1499
|
+
if summary.get("heartbeat_at"):
|
|
1500
|
+
print(f" 最近心跳: {summary['heartbeat_at']}")
|
|
1501
|
+
if summary["stalled"]:
|
|
1502
|
+
print(f" ⚠ 超过 {summary['heartbeat_timeout_seconds']} 秒没有心跳")
|
|
1503
|
+
print(f" 累计耗时: {format_duration(summary['effective_total_seconds'])}")
|
|
1504
|
+
print(f" 完成会话: {summary['sessions_completed']}")
|
|
1505
|
+
print(f" 中止会话: {summary['sessions_aborted']}")
|
|
1506
|
+
policy = summary.get("polling_policy")
|
|
1507
|
+
print(f" Round 续轮策略: {policy or '待询问(启动前必须确认)'}")
|
|
1508
|
+
print(f" 提交策略: {summary.get('commit_policy') or '待询问(log-only 自动不适用)'}")
|
|
1509
|
+
if summary.get("commit_status"):
|
|
1510
|
+
print(f" 最近提交: {summary['commit_status']}"
|
|
1511
|
+
+ (f"({summary.get('commit_ref')})" if summary.get("commit_ref") else ""))
|
|
1512
|
+
review_mode = summary.get("review_mode")
|
|
1513
|
+
print(
|
|
1514
|
+
" 审查方式: "
|
|
1515
|
+
f"{review_mode or '待询问(手动 / MCP 自动 / 下次再说)'}"
|
|
1516
|
+
+ ("(本轮手动,下次重问)"
|
|
1517
|
+
if summary.get("review_mode_deferred") else "")
|
|
1518
|
+
)
|
|
1519
|
+
if summary.get("lifecycle_no"):
|
|
1520
|
+
lifecycle_state = "已完成" if summary.get("lifecycle_terminal") else "进行中"
|
|
1521
|
+
print(
|
|
1522
|
+
f" Round: #{summary['lifecycle_no']} {lifecycle_state};"
|
|
1523
|
+
f"Life {summary.get('lifecycle_cycles_completed', 0)} 个;"
|
|
1524
|
+
f"累计有效 Bug {summary.get('lifecycle_credited_total', 0)} 条;"
|
|
1525
|
+
f"连续无有效进展 {summary.get('lifecycle_no_progress_cycles', 0)}"
|
|
1526
|
+
f"/{LIFECYCLE_MAX_NO_PROGRESS_CYCLES} 次"
|
|
1527
|
+
)
|
|
1528
|
+
if summary.get("lifecycle_stop_reason"):
|
|
1529
|
+
print(f" Round 停止原因: {summary['lifecycle_stop_reason']}")
|
|
1530
|
+
if summary.get("lifecycle_last_report"):
|
|
1531
|
+
print(f" Round 报告: {summary['lifecycle_last_report']}")
|
|
1532
|
+
if summary.get("polling_stop_reason"):
|
|
1533
|
+
print(f" 轮询终止原因: {summary['polling_stop_reason']}")
|
|
1534
|
+
if summary.get("startup_result") or summary.get("startup_observation") or summary.get("startup_intent"):
|
|
1535
|
+
res = summary.get("startup_result") or "未记录"
|
|
1536
|
+
obs = summary.get("startup_observation") or "未记录"
|
|
1537
|
+
intent = summary.get("startup_intent") or "未记录"
|
|
1538
|
+
print(f" 启动判定: 结果={res} 观察={obs} 意图={intent}")
|
|
1539
|
+
if summary.get("current_round") is not None:
|
|
1540
|
+
print(f" 当前轮次: {summary['current_round']}")
|
|
1541
|
+
|
|
1542
|
+
_BASELINE_JSON_CACHE: dict[tuple[str, int, int], object] = {}
|
|
1543
|
+
_BASELINE_JSON_CACHE_LIMIT = 32
|
|
1544
|
+
|
|
1545
|
+
|
|
1546
|
+
def _clear_baseline_json_cache() -> None:
|
|
1547
|
+
"""清空 ``baseline_json()`` 的 stat 记忆化缓存(测试或显式失效时使用)。"""
|
|
1548
|
+
_BASELINE_JSON_CACHE.clear()
|
|
1549
|
+
|
|
1550
|
+
|
|
1551
|
+
def baseline_json() -> dict | None:
|
|
1552
|
+
"""读取当前 life 状态作为外部基线(供 pre 输出,防漏洞 2)。
|
|
1553
|
+
|
|
1554
|
+
PERF-05:``pre()`` 内本函数被调用多次,每次都会 ``bugx_paths.require``
|
|
1555
|
+
再读取并解析 ``life.json``。按 ``(路径, st_mtime_ns, st_size)`` 记忆化:
|
|
1556
|
+
任何写盘(``run_verify_life("snapshot")`` / ``repair`` / 新 Session)都会改变
|
|
1557
|
+
mtime 或 size,使缓存**自然失效**,因此写操作之后绝不会返回陈旧基线。
|
|
1558
|
+
返回浅拷贝,避免调用方原地修改污染缓存。
|
|
1559
|
+
"""
|
|
1560
|
+
if uses_project_layout():
|
|
1561
|
+
try:
|
|
1562
|
+
life = bugx_paths.require(resolve_project_root()).life
|
|
1563
|
+
except (OSError, ValueError, RuntimeError):
|
|
1564
|
+
return None
|
|
1565
|
+
else:
|
|
1566
|
+
# 外部基线 → life 的真实位置与 ``_path_values_for_root`` **同源**。
|
|
1567
|
+
# 旧实现写 ``AGENT_DIR / "bugx-life.json"``:``AGENT_DIR`` 是**可执行
|
|
1568
|
+
# 引擎目录**,而 pre 写入的寿命状态在项目根,于是独立运行
|
|
1569
|
+
# (``python core/launch_bugx.py pre``)读到空基线 ⇒
|
|
1570
|
+
# ``runtime life_no`` 为 None ⇒ 串行授权身份校验 fail-closed,
|
|
1571
|
+
# 而进程内车道(绑定了完整路径表)却通过——两条车道再次分叉。
|
|
1572
|
+
life = Path(LIFE_FILE)
|
|
1573
|
+
try:
|
|
1574
|
+
stat = life.stat()
|
|
1575
|
+
except OSError:
|
|
1576
|
+
return None
|
|
1577
|
+
key = (str(life), stat.st_mtime_ns, stat.st_size)
|
|
1578
|
+
if key in _BASELINE_JSON_CACHE:
|
|
1579
|
+
cached = _BASELINE_JSON_CACHE[key]
|
|
1580
|
+
return dict(cached) if isinstance(cached, dict) else cached # type: ignore[return-value]
|
|
1581
|
+
if not life.is_file():
|
|
1582
|
+
return None
|
|
1583
|
+
try:
|
|
1584
|
+
payload = json.loads(life.read_text(encoding="utf-8"))
|
|
1585
|
+
except (json.JSONDecodeError, OSError):
|
|
1586
|
+
return None
|
|
1587
|
+
if payload is None:
|
|
1588
|
+
return None
|
|
1589
|
+
if len(_BASELINE_JSON_CACHE) >= _BASELINE_JSON_CACHE_LIMIT:
|
|
1590
|
+
_BASELINE_JSON_CACHE.clear()
|
|
1591
|
+
_BASELINE_JSON_CACHE[key] = payload
|
|
1592
|
+
return dict(payload) if isinstance(payload, dict) else payload # type: ignore[return-value]
|
|
1593
|
+
|
|
1594
|
+
def set_polling_policy(policy: str) -> tuple[dict, bool]:
|
|
1595
|
+
if policy not in POLLING_POLICIES:
|
|
1596
|
+
raise ValueError(f"轮询策略必须是 auto 或 manual,收到: {policy}")
|
|
1597
|
+
with runtime_lock():
|
|
1598
|
+
state = load_runtime()
|
|
1599
|
+
changed = state.get("polling_policy") != policy
|
|
1600
|
+
state["polling_policy"] = policy
|
|
1601
|
+
if changed:
|
|
1602
|
+
append_runtime_event(state, "polling-policy", time.time(), policy)
|
|
1603
|
+
save_runtime(state)
|
|
1604
|
+
return state, changed
|
|
1605
|
+
|
|
1606
|
+
def set_review_mode(mode: str, deferred: bool = False) -> tuple[dict, bool]:
|
|
1607
|
+
"""持久化审查执行面;deferred 表示本轮手动、下次启动重新询问。"""
|
|
1608
|
+
if mode not in REVIEW_MODES:
|
|
1609
|
+
raise ValueError(f"审查方式必须是 manual 或 mcp-auto,收到: {mode}")
|
|
1610
|
+
with runtime_lock():
|
|
1611
|
+
state = load_runtime()
|
|
1612
|
+
changed = (
|
|
1613
|
+
state.get("review_mode") != mode
|
|
1614
|
+
or state.get("review_mode_deferred", False) != deferred
|
|
1615
|
+
)
|
|
1616
|
+
state["review_mode"] = mode
|
|
1617
|
+
state["review_mode_deferred"] = deferred
|
|
1618
|
+
if changed:
|
|
1619
|
+
detail = f"{mode};next_start={'ask' if deferred else 'reuse'}"
|
|
1620
|
+
append_runtime_event(state, "review-mode", time.time(), detail)
|
|
1621
|
+
save_runtime(state)
|
|
1622
|
+
return state, changed
|
|
1623
|
+
|
|
1624
|
+
def _record_startup_action(action: str) -> tuple[dict, bool]:
|
|
1625
|
+
"""Persist the explicit stale-MCP startup decision and its audit event."""
|
|
1626
|
+
if action != "start":
|
|
1627
|
+
raise ValueError(f"启动动作只能记录 start,收到: {action}")
|
|
1628
|
+
with runtime_lock():
|
|
1629
|
+
state = load_runtime()
|
|
1630
|
+
changed = state.get("startup_action") != action
|
|
1631
|
+
state["startup_action"] = action
|
|
1632
|
+
# ``start`` is a one-session manual fallback, not a lasting review
|
|
1633
|
+
# preference. Keep both facts in one atomic runtime update.
|
|
1634
|
+
state["review_mode"] = "manual"
|
|
1635
|
+
state["review_mode_deferred"] = True
|
|
1636
|
+
if changed:
|
|
1637
|
+
append_runtime_event(state, "startup-action", time.time(), action)
|
|
1638
|
+
save_runtime(state)
|
|
1639
|
+
return state, changed
|
|
1640
|
+
|
|
1641
|
+
def set_commit_policy(policy: str) -> tuple[dict, bool]:
|
|
1642
|
+
"""持久化当前 Session 的提交边界;不把手动提交当作异常。"""
|
|
1643
|
+
if policy not in COMMIT_POLICIES:
|
|
1644
|
+
raise ValueError("提交策略必须是 life、round、manual 或 not_applicable")
|
|
1645
|
+
with runtime_lock():
|
|
1646
|
+
state = load_runtime()
|
|
1647
|
+
changed = state.get("commit_policy") != policy
|
|
1648
|
+
state["commit_policy"] = policy
|
|
1649
|
+
if changed:
|
|
1650
|
+
append_runtime_event(state, "commit-policy", time.time(), policy)
|
|
1651
|
+
save_runtime(state)
|
|
1652
|
+
return state, changed
|
|
1653
|
+
|
|
1654
|
+
def set_polling_stop(reason: str) -> dict:
|
|
1655
|
+
"""持久化停止原因,同时落 ``polling_stop_reason`` 与 ``lifecycle_stop_reason``。
|
|
1656
|
+
|
|
1657
|
+
两个键描述的是同一个事实(轮询/生命周期为何停止)。历史上只有
|
|
1658
|
+
post_phase 的 ``--final`` 分支写后者,而自治链路被宿主明令禁用
|
|
1659
|
+
``--final``,于是 ``lifecycle_stop_reason`` 永远是 None,
|
|
1660
|
+
``supervisor_host._autonomous_stop_reason`` 永远读不到
|
|
1661
|
+
``coverage_target_completed``,成功收敛被误报成 blocked / exit 1。
|
|
1662
|
+
在唯一写入口一次落两个键,同类断链不再复现。
|
|
1663
|
+
"""
|
|
1664
|
+
with runtime_lock():
|
|
1665
|
+
state = load_runtime()
|
|
1666
|
+
state["polling_stop_reason"] = reason
|
|
1667
|
+
state["lifecycle_stop_reason"] = reason
|
|
1668
|
+
append_runtime_event(state, "polling-stopped", time.time(), reason)
|
|
1669
|
+
save_runtime(state)
|
|
1670
|
+
return state
|