bugx-cli 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +55 -0
- package/README.md +280 -2
- package/core/CATALOG.json +141 -0
- package/core/README.md +254 -0
- package/core/adapters/README.md +35 -0
- package/core/adapters/android-interaction.json +81 -0
- package/core/adapters/android.json +24 -0
- package/core/adapters/desktop-macos.json +20 -0
- package/core/adapters/ios-interaction.json +34 -0
- package/core/adapters/ios.json +23 -0
- package/core/adapters/memory-macos.json +24 -0
- package/core/agent/README.md +50 -0
- package/core/agent/__init__.py +146 -0
- package/core/agent/agent_artifacts.py +764 -0
- package/core/agent/agent_eval.py +1073 -0
- package/core/agent/agent_execution.py +552 -0
- package/core/agent/agent_orchestrator.py +1345 -0
- package/core/agent/agent_targets.py +871 -0
- package/core/agent/agent_workspace.py +770 -0
- package/core/assets/README.md +24 -0
- package/core/assets/bugx-avatar-1024.png +0 -0
- package/core/assets/bugx-avatar-512.png +0 -0
- package/core/assets/bugx-avatar-tight.svg +23 -0
- package/core/assets/bugx-avatar.svg +28 -0
- package/core/assets/bugx-hero-cn.png +0 -0
- package/core/assets/bugx-hero-en.png +0 -0
- package/core/assets/project-layout.md +42 -0
- package/core/audit_packs/README.md +37 -0
- package/core/audit_packs/data-audit/manifest.json +94 -0
- package/core/audit_packs/data-audit/stages/00-scope.md +14 -0
- package/core/audit_packs/data-audit/stages/10-schema-inventory.md +14 -0
- package/core/audit_packs/data-audit/stages/20-query-and-integrity.md +14 -0
- package/core/audit_packs/data-audit/stages/80-evidence-regression.md +14 -0
- package/core/audit_packs/desktop-audit/manifest.json +123 -0
- package/core/audit_packs/desktop-audit/stages/00-scope.md +15 -0
- package/core/audit_packs/desktop-audit/stages/10-process-model.md +14 -0
- package/core/audit_packs/desktop-audit/stages/20-package-integrity.md +15 -0
- package/core/audit_packs/desktop-audit/stages/30-ui-behavior.md +14 -0
- package/core/audit_packs/desktop-audit/stages/80-evidence-regression.md +15 -0
- package/core/audit_packs/memory-testing.md +227 -0
- package/core/audit_packs/mobile-audit/manifest.json +155 -0
- package/core/audit_packs/mobile-audit/modules/android.md +19 -0
- package/core/audit_packs/mobile-audit/modules/h5.md +18 -0
- package/core/audit_packs/mobile-audit/modules/ios.md +25 -0
- package/core/audit_packs/mobile-audit/modules/miniprogram.md +26 -0
- package/core/audit_packs/mobile-audit/modules/webview.md +18 -0
- package/core/audit_packs/mobile-audit/stages/00-scope.md +14 -0
- package/core/audit_packs/mobile-audit/stages/10-platform-inventory.md +14 -0
- package/core/audit_packs/mobile-audit/stages/20-masvs-static.md +20 -0
- package/core/audit_packs/mobile-audit/stages/30-component-exposure.md +14 -0
- package/core/audit_packs/mobile-audit/stages/40-device-behavior.md +14 -0
- package/core/audit_packs/mobile-audit/stages/80-evidence-regression.md +13 -0
- package/core/audit_packs/native-audit/manifest.json +127 -0
- package/core/audit_packs/native-audit/stages/00-scope.md +14 -0
- package/core/audit_packs/native-audit/stages/10-static-white-box.md +14 -0
- package/core/audit_packs/native-audit/stages/20-memory-concurrency.md +15 -0
- package/core/audit_packs/native-audit/stages/30-behavior-black-box.md +39 -0
- package/core/audit_packs/native-audit/stages/80-evidence-regression.md +14 -0
- package/core/audit_packs/platform-testing.md +174 -0
- package/core/audit_packs/web-audit/manifest.json +191 -0
- package/core/audit_packs/web-audit/modules/graphql.md +5 -0
- package/core/audit_packs/web-audit/modules/h5.md +18 -0
- package/core/audit_packs/web-audit/modules/multi-tenant.md +4 -0
- package/core/audit_packs/web-audit/modules/oauth.md +4 -0
- package/core/audit_packs/web-audit/modules/upload.md +4 -0
- package/core/audit_packs/web-audit/modules/websocket.md +4 -0
- package/core/audit_packs/web-audit/stages/00-scope.md +13 -0
- package/core/audit_packs/web-audit/stages/10-discovery.md +13 -0
- package/core/audit_packs/web-audit/stages/20-auth-session.md +13 -0
- package/core/audit_packs/web-audit/stages/30-authz-business.md +13 -0
- package/core/audit_packs/web-audit/stages/40-input-output.md +13 -0
- package/core/audit_packs/web-audit/stages/50-state-async.md +13 -0
- package/core/audit_packs/web-audit/stages/60-file-ssrf-deser.md +12 -0
- package/core/audit_packs/web-audit/stages/70-config-dependency.md +12 -0
- package/core/audit_packs/web-audit/stages/80-evidence-regression.md +12 -0
- package/core/autonomous_cve/INTERFACE.md +61 -0
- package/core/autonomous_cve/README.md +58 -0
- package/core/autonomous_cve/SPEC.md +25 -0
- package/core/autonomous_cve/__init__.py +109 -0
- package/core/autonomous_cve/attack_graph.py +1096 -0
- package/core/autonomous_cve/attack_graph_store.py +1822 -0
- package/core/autonomous_cve/audit_campaign.py +1232 -0
- package/core/autonomous_cve/behavior_graph.py +459 -0
- package/core/autonomous_cve/ghsa_advisories.py +174 -0
- package/core/autonomous_cve/models.py +93 -0
- package/core/autonomous_cve/mutator.py +87 -0
- package/core/autonomous_cve/patcher.py +126 -0
- package/core/autonomous_cve/scout.py +278 -0
- package/core/autonomous_cve/synthesizer.py +207 -0
- package/core/autonomous_cve/verifier.py +100 -0
- package/core/bugx.md +1299 -0
- package/core/bugx_paths.py +1846 -0
- package/core/cloud_sync/INTERFACE.md +32 -0
- package/core/cloud_sync/README.md +62 -0
- package/core/cloud_sync/SPEC.md +25 -0
- package/core/cloud_sync/__init__.py +23 -0
- package/core/cloud_sync/auto_sync.py +398 -0
- package/core/cloud_sync/cloud_client.py +1199 -0
- package/core/cloud_sync/cloud_onboard.py +702 -0
- package/core/cloud_sync/cloud_schema.py +648 -0
- package/core/cloud_sync/consent.py +81 -0
- package/core/cloud_sync/device_identity.py +307 -0
- package/core/cloud_sync/endpoint_router.py +415 -0
- package/core/cloud_sync/flywheel_client.py +760 -0
- package/core/cloud_sync/network_transport.py +275 -0
- package/core/cloud_sync/onboard_wizard.py +493 -0
- package/core/cloud_sync/sensitive_filter.py +285 -0
- package/core/cloud_sync/sync_pull.py +695 -0
- package/core/cloud_sync/sync_push.py +721 -0
- package/core/contracts/AGENT_GUIDE.md +362 -0
- package/core/contracts/README.md +34 -0
- package/core/contracts/bugx-blackbox.md +541 -0
- package/core/contracts/bugx-opencode.md +469 -0
- package/core/contracts/bugx-quick.md +44 -0
- package/core/contracts/bugx-runtime-contract.md +353 -0
- package/core/contracts/bugx-worker.md +470 -0
- package/core/contracts/engine_gap_contracts.py +390 -0
- package/core/coverage/README.md +70 -0
- package/core/coverage/__init__.py +106 -0
- package/core/coverage/coverage_ai_review.py +185 -0
- package/core/coverage/coverage_backfill.py +54 -0
- package/core/coverage/coverage_bootstrap.py +713 -0
- package/core/coverage/coverage_business.py +36 -0
- package/core/coverage/coverage_cli.py +715 -0
- package/core/coverage/coverage_discovery.py +859 -0
- package/core/coverage/coverage_evidence.py +977 -0
- package/core/coverage/coverage_forensics.py +115 -0
- package/core/coverage/coverage_gate.py +277 -0
- package/core/coverage/coverage_intelligence.py +734 -0
- package/core/coverage/coverage_manifest.py +396 -0
- package/core/coverage/coverage_platform.py +77 -0
- package/core/coverage/coverage_validate.py +236 -0
- package/core/coverage/module_coverage.py +157 -0
- package/core/dev_harness/INTERFACE.md +20 -0
- package/core/dev_harness/README.md +21 -0
- package/core/dev_harness/SPEC.md +25 -0
- package/core/dev_harness/__init__.py +5 -0
- package/core/dev_harness/interaction_preset.py +408 -0
- package/core/engine-integrity.json +2625 -0
- package/core/fuzzing/README.md +49 -0
- package/core/fuzzing/__init__.py +82 -0
- package/core/fuzzing/concurrency_fuzzer.py +382 -0
- package/core/fuzzing/differential_oracle.py +629 -0
- package/core/fuzzing/fuzz_input.py +1188 -0
- package/core/fuzzing/stateful_fuzzer.py +332 -0
- package/core/governance/README.md +61 -0
- package/core/governance/__init__.py +130 -0
- package/core/governance/capacity_planner.py +124 -0
- package/core/governance/dependency_lock.py +317 -0
- package/core/governance/goal_governor.py +754 -0
- package/core/governance/guide_budget.py +458 -0
- package/core/governance/lockdown.sh +50 -0
- package/core/governance/readonly_enforcer.py +154 -0
- package/core/governance/runtime_tool_gate.py +373 -0
- package/core/governance/secret_redactor.py +772 -0
- package/core/governance/token_budget.py +38 -0
- package/core/host_acp/INTERFACE.md +36 -0
- package/core/host_acp/README.md +51 -0
- package/core/host_acp/SPEC.md +25 -0
- package/core/host_acp/__init__.py +121 -0
- package/core/host_acp/base.py +111 -0
- package/core/host_acp/claude.py +41 -0
- package/core/host_acp/cline.py +235 -0
- package/core/host_acp/codex.py +245 -0
- package/core/host_acp/dsh.py +48 -0
- package/core/host_acp/opencode.py +154 -0
- package/core/host_acp/pi.py +36 -0
- package/core/host_acp/zcode.py +41 -0
- package/core/host_runtime/INTERFACE.md +24 -0
- package/core/host_runtime/README.md +62 -0
- package/core/host_runtime/SPEC.md +25 -0
- package/core/host_runtime/__init__.py +21 -0
- package/core/host_runtime/adapters.py +412 -0
- package/core/host_runtime/autonomous_runner.py +1152 -0
- package/core/host_runtime/cline.py +435 -0
- package/core/host_runtime/common.py +103 -0
- package/core/host_runtime/free_models.py +786 -0
- package/core/host_runtime/host_bootstrap.py +389 -0
- package/core/host_runtime/host_evaluators.py +721 -0
- package/core/host_runtime/host_probe.py +41 -0
- package/core/host_runtime/host_provider_arbitrator.py +777 -0
- package/core/host_runtime/host_registry.py +655 -0
- package/core/host_runtime/host_usage.py +127 -0
- package/core/host_runtime/mcp_process_tracker.py +509 -0
- package/core/host_runtime/mcp_registry_gate.py +368 -0
- package/core/hosts/INTERFACE.md +51 -0
- package/core/hosts/README.md +67 -0
- package/core/hosts/SPEC.md +25 -0
- package/core/hosts/__init__.py +136 -0
- package/core/hosts/_base_usage.py +152 -0
- package/core/hosts/_codex_usage.py +297 -0
- package/core/hosts/_dsh_usage.py +184 -0
- package/core/hosts/_mcp_toml.py +365 -0
- package/core/hosts/_zcode_usage.py +269 -0
- package/core/hosts/base.py +451 -0
- package/core/hosts/claude.py +157 -0
- package/core/hosts/cline.py +225 -0
- package/core/hosts/codex.py +948 -0
- package/core/hosts/dsh.py +518 -0
- package/core/hosts/opencode.py +358 -0
- package/core/hosts/pi.py +151 -0
- package/core/hosts/zcode.py +219 -0
- package/core/i18n.py +252 -0
- package/core/infra/README.md +39 -0
- package/core/infra/__init__.py +15 -0
- package/core/infra/build_info.py +86 -0
- package/core/infra/client_metadata.py +185 -0
- package/core/infra/python_runtime.py +540 -0
- package/core/infra/safe_xml.py +221 -0
- package/core/launch_bugx.py +118 -0
- package/core/launch_phases/INTERFACE.md +31 -0
- package/core/launch_phases/README.md +106 -0
- package/core/launch_phases/SPEC.md +25 -0
- package/core/launch_phases/__init__.py +29 -0
- package/core/launch_phases/candidate_revalidation.py +484 -0
- package/core/launch_phases/common.py +1041 -0
- package/core/launch_phases/finding_confirm_phase.py +387 -0
- package/core/launch_phases/finding_settlement.py +1245 -0
- package/core/launch_phases/findings_adjudication.py +666 -0
- package/core/launch_phases/findings_snapshot.py +357 -0
- package/core/launch_phases/judge_phase.py +791 -0
- package/core/launch_phases/lesson_context.py +536 -0
- package/core/launch_phases/lifecycle_reporter.py +627 -0
- package/core/launch_phases/orchestrator_controls.py +682 -0
- package/core/launch_phases/post_commit.py +567 -0
- package/core/launch_phases/post_coverage_sync.py +591 -0
- package/core/launch_phases/post_dry_run.py +817 -0
- package/core/launch_phases/post_observability.py +367 -0
- package/core/launch_phases/post_phase.py +1087 -0
- package/core/launch_phases/post_receipt.py +362 -0
- package/core/launch_phases/post_round_lifecycle.py +786 -0
- package/core/launch_phases/pre_phase.py +1029 -0
- package/core/launch_phases/pre_recon_scout.py +862 -0
- package/core/launch_phases/pre_state_builder.py +1286 -0
- package/core/launch_phases/report_sharing.py +414 -0
- package/core/launch_phases/round_orchestrator.py +1133 -0
- package/core/launch_phases/session_runtime.py +1623 -0
- package/core/launch_phases/startup_gates.py +1022 -0
- package/core/launch_phases/startup_interaction.py +947 -0
- package/core/launch_phases/startup_version_gate.py +873 -0
- package/core/launch_phases/supervisor_bridge.py +1224 -0
- package/core/launch_phases/supervisor_coverage.py +417 -0
- package/core/launch_phases/supervisor_degraded.py +1219 -0
- package/core/launch_phases/worker_barriers.py +414 -0
- package/core/launch_phases/worker_orchestrator.py +1166 -0
- package/core/launch_phases/worker_prior.py +749 -0
- package/core/ledger/INTERFACE.md +35 -0
- package/core/ledger/README.md +160 -0
- package/core/ledger/SPEC.md +25 -0
- package/core/ledger/__init__.py +67 -0
- package/core/ledger/_facade.py +226 -0
- package/core/ledger/archive_ops.py +572 -0
- package/core/ledger/auto_materialization.py +459 -0
- package/core/ledger/bug-log.md +22 -0
- package/core/ledger/cli.py +270 -0
- package/core/ledger/export_ops.py +549 -0
- package/core/ledger/finding_confirmation.py +1274 -0
- package/core/ledger/finding_io.py +299 -0
- package/core/ledger/finding_lifecycle.py +307 -0
- package/core/ledger/finding_verification.py +369 -0
- package/core/ledger/incidents.py +999 -0
- package/core/ledger/lesson-replay-cases.json +20 -0
- package/core/ledger/lesson_ledger.py +241 -0
- package/core/ledger/lesson_replay.py +272 -0
- package/core/ledger/life_ledger.py +668 -0
- package/core/ledger/mistake-book.md +130 -0
- package/core/ledger/patterns.py +681 -0
- package/core/ledger/receipt_contract.py +253 -0
- package/core/ledger/schema.py +1192 -0
- package/core/ledger/sync_ops.py +935 -0
- package/core/ledger/tool_experience.py +682 -0
- package/core/ledger/verify_life.py +1526 -0
- package/core/lesson-ledger.json +275 -0
- package/core/locales/README.md +19 -0
- package/core/locales/en-US.json +462 -0
- package/core/locales/zh-CN.json +462 -0
- package/core/mcp_handlers/INTERFACE.md +75 -0
- package/core/mcp_handlers/README.md +62 -0
- package/core/mcp_handlers/SPEC.md +25 -0
- package/core/mcp_handlers/__init__.py +128 -0
- package/core/mcp_handlers/base.py +697 -0
- package/core/mcp_handlers/channel_lifecycle.py +696 -0
- package/core/mcp_handlers/graph_handlers.py +222 -0
- package/core/mcp_handlers/knowledge_handlers.py +536 -0
- package/core/mcp_handlers/mining_handlers.py +586 -0
- package/core/mcp_handlers/resource_prompt_table.py +116 -0
- package/core/mcp_handlers/retrieval_handlers.py +239 -0
- package/core/mcp_handlers/rpc_server.py +465 -0
- package/core/mcp_handlers/supervisor_handlers.py +1435 -0
- package/core/mcp_handlers/telemetry_handlers.py +227 -0
- package/core/mcp_handlers/tool_table.py +1015 -0
- package/core/mcp_runtime_support/README.md +21 -0
- package/core/mcp_runtime_support/__init__.py +1 -0
- package/core/mcp_runtime_support/common.py +363 -0
- package/core/mcp_runtime_support/environment.py +605 -0
- package/core/mcp_runtime_support/verifier.py +810 -0
- package/core/metadata.txt +5 -0
- package/core/planning/README.md +157 -0
- package/core/planning/__init__.py +242 -0
- package/core/planning/capability_plan.py +187 -0
- package/core/planning/capability_planner.py +195 -0
- package/core/planning/domain_archetype.py +542 -0
- package/core/planning/domain_router.py +267 -0
- package/core/planning/dynamic_flow_analyzer.py +328 -0
- package/core/planning/impact_pruner.py +435 -0
- package/core/planning/intent_adjudicator.py +175 -0
- package/core/planning/judge_pipeline.py +1163 -0
- package/core/planning/logic_analysis.py +419 -0
- package/core/planning/prompt_harness.py +1702 -0
- package/core/planning/source_inspector.py +267 -0
- package/core/planning/spec_harvester.py +449 -0
- package/core/planning/target_sandbox_manager.py +573 -0
- package/core/planning/test_capability_verifier.py +1364 -0
- package/core/planning/tools-kb.md +38 -0
- package/core/planning/unit_kind.py +122 -0
- package/core/probes/INTERFACE.md +73 -0
- package/core/probes/README.md +51 -0
- package/core/probes/SPEC.md +26 -0
- package/core/probes/__init__.py +70 -0
- package/core/probes/android_probe.py +384 -0
- package/core/probes/base.py +147 -0
- package/core/probes/codebase_memory_probe.py +590 -0
- package/core/probes/desktop_probe.py +238 -0
- package/core/probes/differential_probe.py +356 -0
- package/core/probes/efficiency_probe.py +168 -0
- package/core/probes/ios_binary_probe.py +368 -0
- package/core/probes/memory_probe.py +326 -0
- package/core/probes/miniprogram_probe.py +323 -0
- package/core/probes/mobile_probe.py +281 -0
- package/core/probes/native_probe.py +214 -0
- package/core/probes/openwiki_probe.py +193 -0
- package/core/probes/pattern_probe.py +347 -0
- package/core/probes/platform_probe.py +343 -0
- package/core/probes/probe_registry.py +1669 -0
- package/core/probes/sast_probe.py +1009 -0
- package/core/probes/sast_rules.py +841 -0
- package/core/probes/sca_scanner.py +731 -0
- package/core/probes/web_probe.py +359 -0
- package/core/project_profiler/INTERFACE.md +62 -0
- package/core/project_profiler/README.md +53 -0
- package/core/project_profiler/SPEC.md +28 -0
- package/core/project_profiler/__init__.py +201 -0
- package/core/project_profiler/arbitrator.py +311 -0
- package/core/project_profiler/constants.py +247 -0
- package/core/project_profiler/detector.py +392 -0
- package/core/project_profiler/extractors.py +836 -0
- package/core/project_profiler/fingerprint.py +116 -0
- package/core/project_profiler/storage.py +258 -0
- package/core/project_profiler/strategy.py +265 -0
- package/core/prompts/README.md +35 -0
- package/core/prompts/codex_dialog_dispatch.md +9 -0
- package/core/prompts/command_routing_en.md +42 -0
- package/core/prompts/command_routing_zh.md +42 -0
- package/core/prompts/l0_router.md +47 -0
- package/core/prompts/rules/anti_patterns.md +16 -0
- package/core/prompts/rules/concurrency_rules.md +14 -0
- package/core/prompts/rules/memory_leak_rules.md +13 -0
- package/core/prompts/rules/prompt_injection_defense.md +13 -0
- package/core/prompts/stages/stage_explore.md +31 -0
- package/core/prompts/stages/stage_gate.md +43 -0
- package/core/prompts/stages/stage_mutate.md +42 -0
- package/core/prompts/stages/stage_repair.md +85 -0
- package/core/repair/README.md +74 -0
- package/core/repair/__init__.py +169 -0
- package/core/repair/fix_watchlist.py +391 -0
- package/core/repair/l7_dynamic.py +418 -0
- package/core/repair/l7_repair_loop.py +465 -0
- package/core/repair/l7_selfcheck.py +862 -0
- package/core/repair/minimize_repro.py +466 -0
- package/core/repair/patch_synthesizer.py +617 -0
- package/core/repair/regression_pack.py +379 -0
- package/core/repair/rsi_fixer.py +910 -0
- package/core/repair/rsi_loop.py +313 -0
- package/core/repair/rsi_repair.py +348 -0
- package/core/repair/rsi_rounds.py +212 -0
- package/core/repair/rsi_scope.py +262 -0
- package/core/repair/self_heal.py +604 -0
- package/core/repair/test_generator.py +1108 -0
- package/core/repair/test_quality_auditor.py +410 -0
- package/core/repair/test_strategy.py +511 -0
- package/core/report_engine/INTERFACE.md +59 -0
- package/core/report_engine/README.md +69 -0
- package/core/report_engine/SPEC.md +28 -0
- package/core/report_engine/__init__.py +47 -0
- package/core/report_engine/attestation.py +224 -0
- package/core/report_engine/authority.py +255 -0
- package/core/report_engine/finding_report.py +417 -0
- package/core/report_engine/formal_report_builder.py +924 -0
- package/core/report_engine/html_renderers.py +696 -0
- package/core/report_engine/models.py +761 -0
- package/core/report_engine/pdf_exporter.py +231 -0
- package/core/report_engine/projects_assets.py +730 -0
- package/core/report_engine/report_client.py +743 -0
- package/core/report_engine/report_data_builder.py +388 -0
- package/core/report_engine/report_share.py +459 -0
- package/core/report_engine/sast_bridge.py +116 -0
- package/core/report_engine/server.py +822 -0
- package/core/report_engine/visual_report_builder.py +796 -0
- package/core/report_engine/web-conformance.md +63 -0
- package/core/report_engine/web_conformance.py +459 -0
- package/core/report_engine/workbench_assets.py +484 -0
- package/core/retrieval/INTERFACE.md +20 -0
- package/core/retrieval/README.md +161 -0
- package/core/retrieval/SPEC.md +25 -0
- package/core/retrieval/__init__.py +3 -0
- package/core/retrieval/code_analyzer.py +1684 -0
- package/core/retrieval/codebase_memory_bridge.py +337 -0
- package/core/retrieval/context_assembler.py +234 -0
- package/core/retrieval/corpus_fetch.py +369 -0
- package/core/retrieval/graph_ego.py +597 -0
- package/core/retrieval/knowledge_auto.py +662 -0
- package/core/retrieval/knowledge_sources.py +168 -0
- package/core/retrieval/knowledge_sync.py +909 -0
- package/core/retrieval/memory_store.py +480 -0
- package/core/retrieval/query_planner.py +1020 -0
- package/core/retrieval/rrf_engine.py +137 -0
- package/core/retrieval/slice_extractor.py +1209 -0
- package/core/retrieval/slice_normalizer.py +373 -0
- package/core/retrieval/slice_spec.py +357 -0
- package/core/retrieval/symbol_index.py +1132 -0
- package/core/retrieval/universal_code_matcher.py +437 -0
- package/core/retrieval/xerj_bridge.py +476 -0
- package/core/retrieval/xerj_supervisor.py +362 -0
- package/core/rules/README.md +33 -0
- package/core/rules/ios/PROVENANCE.json +30 -0
- package/core/rules/ios/crypto.yaml +36 -0
- package/core/rules/ios/network.yaml +20 -0
- package/core/rules/ios/resilience.yaml +47 -0
- package/core/rules/ios/storage.yaml +48 -0
- package/core/rules/mastg/LICENSE +173 -0
- package/core/rules/mastg/PROVENANCE.json +270 -0
- package/core/rules/mastg/mastg-android-asymmetric-key-pair-used-for-multiple-purposes.yml +13 -0
- package/core/rules/mastg/mastg-android-backup-manifest.yml +24 -0
- package/core/rules/mastg/mastg-android-biometric-event-bound.yml +49 -0
- package/core/rules/mastg/mastg-android-biometric-invalidated-enrollment.yml +11 -0
- package/core/rules/mastg/mastg-android-biometric-no-confirmation-required.yml +10 -0
- package/core/rules/mastg/mastg-android-biometric-validity-duration.yml +24 -0
- package/core/rules/mastg/mastg-android-broken-encryption-algorithms.yaml +9 -0
- package/core/rules/mastg/mastg-android-broken-encryption-modes.yaml +13 -0
- package/core/rules/mastg/mastg-android-content-provider-exported.yml +35 -0
- package/core/rules/mastg/mastg-android-custom-deeplink-scheme.yml +29 -0
- package/core/rules/mastg/mastg-android-dangerous-app-permissions.yaml +65 -0
- package/core/rules/mastg/mastg-android-data-unencrypted-shared-storage-no-user-interaction-apis.yml +36 -0
- package/core/rules/mastg/mastg-android-data-unencrypted-shared-storage-no-user-interaction-manifest.yml +15 -0
- package/core/rules/mastg/mastg-android-debuggable-flag.yml +10 -0
- package/core/rules/mastg/mastg-android-debugger-checks.yml +12 -0
- package/core/rules/mastg/mastg-android-deeplink-autoverify-missing.yml +33 -0
- package/core/rules/mastg/mastg-android-deeplink-unvalidated-parameter.yml +11 -0
- package/core/rules/mastg/mastg-android-device-passcode-present.yml +17 -0
- package/core/rules/mastg/mastg-android-fileprovider-broad-scope.yml +46 -0
- package/core/rules/mastg/mastg-android-hardcoded-crypto-keys-usage.yml +14 -0
- package/core/rules/mastg/mastg-android-hardcoded-security-provider.yaml +18 -0
- package/core/rules/mastg/mastg-android-implicit-intent-internal-communication.yml +30 -0
- package/core/rules/mastg/mastg-android-implicit-intent-leaking-extras.yml +29 -0
- package/core/rules/mastg/mastg-android-input-field-usage.yml +11 -0
- package/core/rules/mastg/mastg-android-key-generation-with-insufficient-key-length.yml +21 -0
- package/core/rules/mastg/mastg-android-keyboard-cache-input-types.yml +10 -0
- package/core/rules/mastg/mastg-android-local-storage-input-validation.yml +48 -0
- package/core/rules/mastg/mastg-android-native-debugger-checks.yml +12 -0
- package/core/rules/mastg/mastg-android-network-checkservertrusted.yml +12 -0
- package/core/rules/mastg/mastg-android-network-hostname-verification.yml +11 -0
- package/core/rules/mastg/mastg-android-network-insecure-trust-anchors.yml +11 -0
- package/core/rules/mastg/mastg-android-network-onreceivedsslerror.yml +12 -0
- package/core/rules/mastg/mastg-android-non-random-use.yml +16 -0
- package/core/rules/mastg/mastg-android-object-deserialization.yml +14 -0
- package/core/rules/mastg/mastg-android-overlay-protection.yml +68 -0
- package/core/rules/mastg/mastg-android-pendingintent-mutable.yml +39 -0
- package/core/rules/mastg/mastg-android-random-apis-insufficient-entropy.yml +17 -0
- package/core/rules/mastg/mastg-android-root-detection.yaml +59 -0
- package/core/rules/mastg/mastg-android-sdk-version.yml +10 -0
- package/core/rules/mastg/mastg-android-sensitive-data-in-notifications-manifest.yml +17 -0
- package/core/rules/mastg/mastg-android-sensitive-data-in-notifications.yml +11 -0
- package/core/rules/mastg/mastg-android-sensitive-data-in-screenshot.yml +18 -0
- package/core/rules/mastg/mastg-android-sql-injection-contentprovider.yml +17 -0
- package/core/rules/mastg/mastg-android-ssl-socket-hostnameverifier.yml +15 -0
- package/core/rules/mastg/mastg-android-strictmode.yml +10 -0
- package/core/rules/mastg/mastg-android-system-alert-window.yml +9 -0
- package/core/rules/mastg/mastg-android-webview-allow-local-access.yml +15 -0
- package/core/rules/mastg/mastg-android-webview-bridges.yml +28 -0
- package/core/rules/mastg/mastg-android-webview-safebrowsing.yml +20 -0
- package/core/rules/mastg/mastg-android-webview-url-handlers.yml +41 -0
- package/core/rules/miniprogram/PROVENANCE.json +26 -0
- package/core/rules/miniprogram/network.yaml +37 -0
- package/core/rules/miniprogram/platform.yaml +36 -0
- package/core/rules/miniprogram/storage.yaml +48 -0
- package/core/rules/mobsfscan-swift/LICENSE +165 -0
- package/core/rules/mobsfscan-swift/PROVENANCE.json +58 -0
- package/core/rules/mobsfscan-swift/auth.yaml +59 -0
- package/core/rules/mobsfscan-swift/crypto.yaml +66 -0
- package/core/rules/mobsfscan-swift/jailbreak.yaml +14 -0
- package/core/rules/mobsfscan-swift/keyboard.yaml +34 -0
- package/core/rules/mobsfscan-swift/logging.yaml +23 -0
- package/core/rules/mobsfscan-swift/network.yaml +55 -0
- package/core/rules/mobsfscan-swift/resilience.yaml +29 -0
- package/core/rules/mobsfscan-swift/secrets.yaml +33 -0
- package/core/rules/mobsfscan-swift/storage.yaml +29 -0
- package/core/rules/mobsfscan-swift/webview.yaml +32 -0
- package/core/runtime/README.md +198 -0
- package/core/runtime/__init__.py +3 -0
- package/core/runtime/bugx_logging.py +1393 -0
- package/core/runtime/daemon_runner.py +623 -0
- package/core/runtime/fixture_solidify.py +449 -0
- package/core/runtime/global_telemetry.py +549 -0
- package/core/runtime/incident_eval.py +148 -0
- package/core/runtime/interaction.py +605 -0
- package/core/runtime/interaction_store.py +435 -0
- package/core/runtime/interactive_menu.py +95 -0
- package/core/runtime/log_analytics.py +922 -0
- package/core/runtime/mining_quality_framework.py +1387 -0
- package/core/runtime/model_runner.py +769 -0
- package/core/runtime/platform_adapter.py +579 -0
- package/core/runtime/prep_validate.py +476 -0
- package/core/runtime/project_graph.py +827 -0
- package/core/runtime/project_init.py +481 -0
- package/core/runtime/project_profile.py +224 -0
- package/core/runtime/project_settings.py +963 -0
- package/core/runtime/provider_window.py +97 -0
- package/core/runtime/resume_ticket.py +115 -0
- package/core/runtime/scenario_eval.py +814 -0
- package/core/runtime/seed_drill.py +549 -0
- package/core/runtime/self_audit.py +550 -0
- package/core/runtime/session_profile.py +205 -0
- package/core/runtime/setup_ui_env.py +229 -0
- package/core/runtime/startup_environment.py +859 -0
- package/core/runtime/sync_store.py +1421 -0
- package/core/runtime/tool_install_targets.py +18 -0
- package/core/schemas/README.md +35 -0
- package/core/schemas/agent-graph.schema.json +368 -0
- package/core/schemas/attack-graph.schema.json +88 -0
- package/core/schemas/evidence-bundle.schema.json +33 -0
- package/core/schemas/skill-pack.schema.json +230 -0
- package/core/schemas/worker-checkpoint.schema.json +119 -0
- package/core/secure_atomic.py +289 -0
- package/core/seed_corpus/README.md +55 -0
- package/core/seed_corpus/c.txt +29 -0
- package/core/seed_corpus/cpp.txt +32 -0
- package/core/seed_corpus/css.txt +70 -0
- package/core/seed_corpus/go.txt +46 -0
- package/core/seed_corpus/java.txt +30 -0
- package/core/seed_corpus/javascript.txt +55 -0
- package/core/seed_corpus/kotlin.txt +28 -0
- package/core/seed_corpus/python.txt +71 -0
- package/core/seed_corpus/rust.txt +53 -0
- package/core/seed_corpus/swift.txt +29 -0
- package/core/seed_corpus/typescript.txt +29 -0
- package/core/skills/README.md +53 -0
- package/core/skills/__init__.py +189 -0
- package/core/skills/bugx_docs_mcp_server.py +416 -0
- package/core/skills/bugx_mcp_server.py +1134 -0
- package/core/skills/mcp_runtime.py +968 -0
- package/core/skills/mcp_session_proof.py +605 -0
- package/core/skills/mobile_ui_inspector.py +405 -0
- package/core/skills/skill_pack.py +1214 -0
- package/core/skills/skill_synthesizer.py +1153 -0
- package/core/skills/tools_kb.py +313 -0
- package/core/supervisor/INTERFACE.md +121 -0
- package/core/supervisor/README.md +209 -0
- package/core/supervisor/SPEC.md +25 -0
- package/core/supervisor/__init__.py +175 -0
- package/core/supervisor/audit_supervisor.py +1015 -0
- package/core/supervisor/budget_governor.py +760 -0
- package/core/supervisor/checkpoint_handler.py +368 -0
- package/core/supervisor/checkpoint_pipeline.py +1322 -0
- package/core/supervisor/checkpoint_sync.py +640 -0
- package/core/supervisor/claim_events.py +74 -0
- package/core/supervisor/claim_sync.py +590 -0
- package/core/supervisor/cli.py +812 -0
- package/core/supervisor/context_sync.py +55 -0
- package/core/supervisor/coverage_sync.py +115 -0
- package/core/supervisor/finding_commit.py +470 -0
- package/core/supervisor/finding_sync.py +688 -0
- package/core/supervisor/finding_workflow.py +659 -0
- package/core/supervisor/finish_policy.py +224 -0
- package/core/supervisor/finish_sync.py +185 -0
- package/core/supervisor/graph_sync.py +669 -0
- package/core/supervisor/lease_manager.py +788 -0
- package/core/supervisor/lifecycle_blocks.py +124 -0
- package/core/supervisor/next_round_sync.py +126 -0
- package/core/supervisor/observability.py +140 -0
- package/core/supervisor/recovery_sync.py +165 -0
- package/core/supervisor/rejection_remedies.py +308 -0
- package/core/supervisor/round_governor.py +306 -0
- package/core/supervisor/serial_authorization.py +500 -0
- package/core/supervisor/start_sync.py +87 -0
- package/core/supervisor/state_store.py +249 -0
- package/core/supervisor/supervisor_host.py +511 -0
- package/core/supervisor/supervisor_models.py +1143 -0
- package/core/supervisor/systemic_failure.py +104 -0
- package/core/supervisor/task_scheduler.py +1640 -0
- package/core/supervisor/worker_checkpoint.py +223 -0
- package/core/supervisor/worker_execution.py +265 -0
- package/core/supervisor/worker_handoff.py +192 -0
- package/core/supervisor/worker_lifecycle.py +396 -0
- package/core/supervisor/worker_runtime.py +999 -0
- package/core/supervisor/worker_sync.py +89 -0
- package/core/supervisor_types/README.md +36 -0
- package/core/supervisor_types/__init__.py +0 -0
- package/core/supervisor_types/exceptions.py +52 -0
- package/core/supervisor_types/graph_models.py +357 -0
- package/core/supervisor_types/path_containment.py +151 -0
- package/core/supervisor_types/target_fingerprint.py +310 -0
- package/core/supervisor_types/worker_claim.py +402 -0
- package/core/webui/INTERFACE.md +50 -0
- package/core/webui/README.md +57 -0
- package/core/webui/SPEC.md +25 -0
- package/core/webui/__init__.py +11 -0
- package/core/webui/adapters/__init__.py +27 -0
- package/core/webui/adapters/base.py +87 -0
- package/core/webui/adapters/bugx.py +102 -0
- package/core/webui/adapters/claude.py +218 -0
- package/core/webui/adapters/cline.py +399 -0
- package/core/webui/adapters/codex.py +256 -0
- package/core/webui/adapters/dsh.py +173 -0
- package/core/webui/adapters/opencode.py +218 -0
- package/core/webui/adapters/pi.py +272 -0
- package/core/webui/adapters/registry.py +100 -0
- package/core/webui/adapters/zcode.py +312 -0
- package/core/webui/api_routes_post.py +668 -0
- package/core/webui/dispatcher.py +1376 -0
- package/core/webui/docs_session_service.py +473 -0
- package/core/webui/handler.py +674 -0
- package/core/webui/ide_cloud_service.py +526 -0
- package/core/webui/mcp_inspector.py +1743 -0
- package/core/webui/static/assets/index-CXAsl8mr.js +333 -0
- package/core/webui/static/assets/index-DHQUtWtx.css +1 -0
- package/core/webui/static/assets/source-serif-4-cyrillic-400-normal-B8Z6Jvzv.woff +0 -0
- package/core/webui/static/assets/source-serif-4-cyrillic-400-normal-C44pakCn.woff2 +0 -0
- package/core/webui/static/assets/source-serif-4-cyrillic-500-normal-Bb4u56_6.woff +0 -0
- package/core/webui/static/assets/source-serif-4-cyrillic-500-normal-BdVUvljg.woff2 +0 -0
- package/core/webui/static/assets/source-serif-4-cyrillic-ext-400-normal-CWV284fw.woff2 +0 -0
- package/core/webui/static/assets/source-serif-4-cyrillic-ext-400-normal-DLkyKLvH.woff +0 -0
- package/core/webui/static/assets/source-serif-4-cyrillic-ext-500-normal-8-8HP2PF.woff +0 -0
- package/core/webui/static/assets/source-serif-4-cyrillic-ext-500-normal-DaDZE_Na.woff2 +0 -0
- package/core/webui/static/assets/source-serif-4-greek-400-normal-BccYJ-vZ.woff +0 -0
- package/core/webui/static/assets/source-serif-4-greek-400-normal-Cw5-AHNN.woff2 +0 -0
- package/core/webui/static/assets/source-serif-4-greek-500-normal-By8GFJzz.woff2 +0 -0
- package/core/webui/static/assets/source-serif-4-greek-500-normal-z-Q6FFuG.woff +0 -0
- package/core/webui/static/assets/source-serif-4-latin-400-normal-DJ5YJwmz.woff2 +0 -0
- package/core/webui/static/assets/source-serif-4-latin-400-normal-Dn3IlU-Z.woff +0 -0
- package/core/webui/static/assets/source-serif-4-latin-500-normal-CUHe9xxf.woff2 +0 -0
- package/core/webui/static/assets/source-serif-4-latin-500-normal-DVVamBqs.woff +0 -0
- package/core/webui/static/assets/source-serif-4-latin-ext-400-normal-CEpydyUl.woff +0 -0
- package/core/webui/static/assets/source-serif-4-latin-ext-400-normal-Cp7z-ARB.woff2 +0 -0
- package/core/webui/static/assets/source-serif-4-latin-ext-500-normal-BYjRCDVy.woff2 +0 -0
- package/core/webui/static/assets/source-serif-4-latin-ext-500-normal-D-qasQTj.woff +0 -0
- package/core/webui/static/assets/source-serif-4-vietnamese-400-normal-BbG3LG1A.woff2 +0 -0
- package/core/webui/static/assets/source-serif-4-vietnamese-400-normal-DR1UuFon.woff +0 -0
- package/core/webui/static/assets/source-serif-4-vietnamese-500-normal-8N8MYVKB.woff +0 -0
- package/core/webui/static/assets/source-serif-4-vietnamese-500-normal-Bi3OSTTW.woff2 +0 -0
- package/core/webui/static/favicon.png +0 -0
- package/core/webui/static/icon-192.png +0 -0
- package/core/webui/static/index.html +42 -0
- package/core/webui/static/manifest.webmanifest +19 -0
- package/core/webui/static/project-settings.css +6458 -0
- package/core/webui/static/project-settings.js +9602 -0
- package/core/webui/static/sw.js +8 -0
- package/core/webui/workspace_service.py +218 -0
- package/docs/07_distribution/01_README_NPM.md +281 -0
- package/docs/07_distribution/README.md +16 -0
- package/docs/README.md +121 -0
- package/ecosystem/README.md +129 -0
- package/ecosystem/integrations/README.md +38 -0
- package/ecosystem/integrations/cline/skills/bugx/SKILL.md +69 -0
- package/ecosystem/integrations/dsh/agents/bugx.md +27 -0
- package/ecosystem/integrations/dsh/dsh-patch.yml +18 -0
- package/ecosystem/integrations/dsh/mcp/cordis.patch.yml +4 -0
- package/ecosystem/integrations/dsh/mcp/index.js +219 -0
- package/ecosystem/integrations/dsh/mcp/package.json +28 -0
- package/ecosystem/integrations/dsh/skills/bugx/SKILL.md +70 -0
- package/ecosystem/integrations/dsh/skills/bugx-dsh/SKILL.md +229 -0
- package/ecosystem/integrations/dsh/ui/client.js +87 -0
- package/ecosystem/integrations/dsh/ui/cordis.patch.yml +4 -0
- package/ecosystem/integrations/dsh/ui/index.js +7 -0
- package/ecosystem/integrations/dsh/ui/package.json +27 -0
- package/ecosystem/integrations/opencode/bugx-mcp-manifest.json +53 -0
- package/ecosystem/integrations/opencode/mcp-lock.json +3067 -0
- package/ecosystem/integrations/opencode/opencode.json +118 -0
- package/ecosystem/integrations/pi/extensions/bugx/README.md +12 -0
- package/ecosystem/integrations/pi/extensions/bugx/index.ts +299 -0
- package/ecosystem/integrations/pi/extensions/bugx/manifest.json +11 -0
- package/ecosystem/integrations/pi/skills/bugx/SKILL.md +69 -0
- package/ecosystem/integrations/qoder/CONNECTORS.md +54 -0
- package/ecosystem/integrations/qoder/connector-meta.json +21 -0
- package/ecosystem/integrations/workbuddy/connector-meta.json +19 -0
- package/ecosystem/integrations/workbuddy/icon.png +0 -0
- package/ecosystem/integrations/workbuddy/skills/bugx/SKILL.md +70 -0
- package/ecosystem/plugins/README.md +37 -0
- package/ecosystem/plugins/bugx/.claude-plugin/marketplace.json +17 -0
- package/ecosystem/plugins/bugx/.claude-plugin/plugin.json +16 -0
- package/ecosystem/plugins/bugx/.codex-plugin/plugin.json +41 -0
- package/ecosystem/plugins/bugx/.zcode-plugin/plugin.json +19 -0
- package/ecosystem/plugins/bugx/agents/bugx-judge.md +71 -0
- package/ecosystem/plugins/bugx/agents/bugx-worker.md +31 -0
- package/ecosystem/plugins/bugx/agents/bugx.md +74 -0
- package/ecosystem/plugins/bugx/assets/bugx-avatar-512.png +0 -0
- package/ecosystem/plugins/bugx/skills/bugx/SKILL.md +118 -0
- package/ecosystem/plugins/bugx/skills/bugx-claude/SKILL.md +326 -0
- package/ecosystem/plugins/bugx/skills/bugx-dsh/SKILL.md +229 -0
- package/ecosystem/plugins/bugx/skills/bugx-opencode/SKILL.md +129 -0
- package/ecosystem/plugins/bugx/skills/bugx-zcode/SKILL.md +459 -0
- package/interfaces/README.md +143 -0
- package/interfaces/bin/README.md +35 -0
- package/interfaces/bin/bugx.js +80 -0
- package/interfaces/cli/README.md +90 -0
- package/interfaces/cli/bugx_cli/__init__.py +4 -0
- package/interfaces/cli/bugx_cli/cli.py +1678 -0
- package/interfaces/cli/bugx_cli/commands/__init__.py +1 -0
- package/interfaces/cli/bugx_cli/commands/advisory.py +94 -0
- package/interfaces/cli/bugx_cli/commands/agent.py +3944 -0
- package/interfaces/cli/bugx_cli/commands/audit.py +632 -0
- package/interfaces/cli/bugx_cli/commands/autonomous.py +260 -0
- package/interfaces/cli/bugx_cli/commands/cloud.py +1370 -0
- package/interfaces/cli/bugx_cli/commands/daemon.py +50 -0
- package/interfaces/cli/bugx_cli/commands/doctor.py +1345 -0
- package/interfaces/cli/bugx_cli/commands/goal.py +107 -0
- package/interfaces/cli/bugx_cli/commands/interaction.py +244 -0
- package/interfaces/cli/bugx_cli/commands/knowledge.py +617 -0
- package/interfaces/cli/bugx_cli/commands/lifecycle.py +2763 -0
- package/interfaces/cli/bugx_cli/commands/patch.py +1014 -0
- package/interfaces/cli/bugx_cli/commands/plugin.py +2714 -0
- package/interfaces/cli/bugx_cli/commands/plugin_claude.py +1446 -0
- package/interfaces/cli/bugx_cli/commands/plugin_cline.py +269 -0
- package/interfaces/cli/bugx_cli/commands/plugin_codex.py +74 -0
- package/interfaces/cli/bugx_cli/commands/plugin_funide.py +728 -0
- package/interfaces/cli/bugx_cli/commands/plugin_qoder.py +216 -0
- package/interfaces/cli/bugx_cli/commands/plugin_zcode.py +710 -0
- package/interfaces/cli/bugx_cli/commands/project.py +670 -0
- package/interfaces/cli/bugx_cli/commands/report.py +260 -0
- package/interfaces/cli/bugx_cli/commands/skill.py +251 -0
- package/interfaces/cli/bugx_cli/commands/stats.py +133 -0
- package/interfaces/cli/bugx_cli/commands/system.py +2567 -0
- package/interfaces/cli/bugx_cli/common.py +898 -0
- package/interfaces/cli/bugx_cli/host_adapters.py +1917 -0
- package/interfaces/cli/bugx_cli/hosts/__init__.py +80 -0
- package/interfaces/cli/bugx_cli/hosts/base.py +99 -0
- package/interfaces/cli/bugx_cli/hosts/registry.py +571 -0
- package/interfaces/cli/bugx_cli/hosts/template_engine.py +188 -0
- package/interfaces/cli/bugx_cli/infra/__init__.py +209 -0
- package/interfaces/cli/bugx_cli/infra/ai_advisor.py +721 -0
- package/interfaces/cli/bugx_cli/infra/engine_installer.py +1937 -0
- package/interfaces/cli/bugx_cli/infra/host_sync.py +545 -0
- package/interfaces/cli/bugx_cli/infra/mcp_advisor.py +755 -0
- package/interfaces/cli/bugx_cli/infra/security.py +332 -0
- package/package.json +98 -4
- package/pyproject.toml +246 -0
- package/scripts/README.md +118 -0
- package/scripts/ensure-python.mjs +97 -0
- package/scripts/isolate-npm-readme.mjs +40 -0
- package/scripts/runtime.lock.json +31 -0
- package/scripts/sync-version.mjs +37 -0
- package/scripts/test-npm-wrapper.mjs +265 -0
|
@@ -0,0 +1,1133 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""launch_phases/round_orchestrator.py - Round 推进调度、测试执行、发现标定与终局 post 报告结算。"""
|
|
3
|
+
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
import contextlib
|
|
7
|
+
import difflib
|
|
8
|
+
import hashlib
|
|
9
|
+
import io
|
|
10
|
+
import json
|
|
11
|
+
import os
|
|
12
|
+
import re
|
|
13
|
+
import shlex
|
|
14
|
+
import shutil
|
|
15
|
+
import subprocess
|
|
16
|
+
import sys
|
|
17
|
+
import time
|
|
18
|
+
from dataclasses import dataclass
|
|
19
|
+
from pathlib import Path
|
|
20
|
+
from typing import Any
|
|
21
|
+
|
|
22
|
+
from core.launch_phases.worker_orchestrator import workers
|
|
23
|
+
# DES-06:本模块对 pre_phase 的依赖是**真实存在**的(不是死导入),见下方说明。
|
|
24
|
+
from core.launch_phases.pre_phase import ( # noqa: E402
|
|
25
|
+
pre,
|
|
26
|
+
coverage_status,
|
|
27
|
+
attach_coverage,
|
|
28
|
+
print_coverage,
|
|
29
|
+
)
|
|
30
|
+
# 修正说明(重要):此前这里曾以「零使用」为由删掉整条 import,导致
|
|
31
|
+
# ``bugx pre`` / ``bugx audit`` 报 ``NameError: name 'pre' is not defined`` ——
|
|
32
|
+
# 这是一次由**错误的依赖核查**引入的回归(当时用 grep 判定"零使用",
|
|
33
|
+
# 而该 grep 的 `\|` 交替在本机 shell 下静默失效,实际漏掉了 4 处真实调用)。
|
|
34
|
+
# 实测仍在使用:pre(:1360 分发 pre/audit)、coverage_status(:938)、
|
|
35
|
+
# attach_coverage(:939)、print_coverage(:994)。
|
|
36
|
+
# 只有 ``_prepare_project_profile`` 确实无人使用,故未回补。
|
|
37
|
+
# 方向说明:这条边是 round -> pre(与声明的 PRE -> ROUND 相反),但它不构成环
|
|
38
|
+
# (pre_phase 不反向 import round_orchestrator),且是分发所必需,故保留。
|
|
39
|
+
from core.launch_phases.post_phase import (
|
|
40
|
+
post,
|
|
41
|
+
get_last_post_failure,
|
|
42
|
+
continue_after_death,
|
|
43
|
+
close_session,
|
|
44
|
+
life_summary,
|
|
45
|
+
retry_pending_commit,
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
from core.launch_phases.common import (
|
|
49
|
+
AGENT_DIR,
|
|
50
|
+
IN_PROCESS_SCOPE,
|
|
51
|
+
VERIFY,
|
|
52
|
+
SUPERVISOR_STATE,
|
|
53
|
+
LESSON_LEDGER_FILE,
|
|
54
|
+
POLLING_POLICIES,
|
|
55
|
+
POLLING_DECISION_REQUIRED,
|
|
56
|
+
get_last_child_failure,
|
|
57
|
+
resolve_project_root,
|
|
58
|
+
uses_project_layout,
|
|
59
|
+
child_environment,
|
|
60
|
+
diagnostic_logger,
|
|
61
|
+
run_verify_life,
|
|
62
|
+
format_duration,
|
|
63
|
+
isolated_runtime_scope,
|
|
64
|
+
bugx_paths,
|
|
65
|
+
bugx_logging,
|
|
66
|
+
dependency_lock,
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
try:
|
|
70
|
+
import core.i18n as i18n
|
|
71
|
+
except ImportError:
|
|
72
|
+
try:
|
|
73
|
+
from core import i18n
|
|
74
|
+
except ImportError:
|
|
75
|
+
i18n = None # type: ignore[assignment]
|
|
76
|
+
|
|
77
|
+
from core.launch_phases.session_runtime import (
|
|
78
|
+
refresh_runtime_paths,
|
|
79
|
+
audit_todo_path,
|
|
80
|
+
refresh_audit_todo,
|
|
81
|
+
load_runtime,
|
|
82
|
+
runtime_lock,
|
|
83
|
+
save_runtime,
|
|
84
|
+
diagnostic_context,
|
|
85
|
+
append_runtime_event,
|
|
86
|
+
runtime_summary,
|
|
87
|
+
close_runtime,
|
|
88
|
+
pause_runtime,
|
|
89
|
+
resume_runtime,
|
|
90
|
+
heartbeat_runtime,
|
|
91
|
+
print_runtime,
|
|
92
|
+
set_polling_policy,
|
|
93
|
+
)
|
|
94
|
+
from core.launch_phases.startup_gates import (
|
|
95
|
+
startup_todo_path,
|
|
96
|
+
startup_todo_content,
|
|
97
|
+
refresh_startup_todo,
|
|
98
|
+
detect_startup_environment,
|
|
99
|
+
startup_environment_line,
|
|
100
|
+
git_startup_gate,
|
|
101
|
+
emit_startup_gate,
|
|
102
|
+
pre_has_explicit_startup_choices,
|
|
103
|
+
project_layout_present,
|
|
104
|
+
startup_version_banner,
|
|
105
|
+
startup_cloud_onboarding,
|
|
106
|
+
startup_version_gate,
|
|
107
|
+
schedule_startup_remote_version_check,
|
|
108
|
+
emit_version_contract_gate,
|
|
109
|
+
emit_project_layout_gate,
|
|
110
|
+
)
|
|
111
|
+
from core.launch_phases.supervisor_bridge import (
|
|
112
|
+
get_supervisor,
|
|
113
|
+
supervisor_mcp_snapshot,
|
|
114
|
+
print_supervisor_mcp_snapshot,
|
|
115
|
+
)
|
|
116
|
+
|
|
117
|
+
from core.governance.token_budget import estimate_tokens
|
|
118
|
+
import core.secure_atomic as secure_atomic
|
|
119
|
+
import tempfile
|
|
120
|
+
|
|
121
|
+
from core.supervisor.supervisor_models import BudgetExhausted
|
|
122
|
+
|
|
123
|
+
try:
|
|
124
|
+
from core.runtime import project_profile
|
|
125
|
+
except ImportError:
|
|
126
|
+
project_profile = None
|
|
127
|
+
|
|
128
|
+
try:
|
|
129
|
+
from core.ledger import lesson_ledger
|
|
130
|
+
except ImportError:
|
|
131
|
+
lesson_ledger = None
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
_STATEFUL_COMMANDS = frozenset({
|
|
135
|
+
"pre", "audit", "post", "polling", "heartbeat", "pause", "resume",
|
|
136
|
+
"abort", "bootstrap-coverage", "fix-review", "revalidate-candidates",
|
|
137
|
+
"control", "workers", "daemon",
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
@dataclass(frozen=True)
|
|
141
|
+
class RunResult:
|
|
142
|
+
"""Subprocess-compatible result returned by :func:`run_in_process`.
|
|
143
|
+
|
|
144
|
+
``stdout``, ``stderr`` and ``returncode`` intentionally mirror
|
|
145
|
+
``subprocess.CompletedProcess`` so existing protocol fixtures can switch
|
|
146
|
+
execution lanes without changing their assertions. ``exception`` is only
|
|
147
|
+
populated when a library call raises outside the launcher's normal error
|
|
148
|
+
handling; it is diagnostic metadata, never a second status channel.
|
|
149
|
+
"""
|
|
150
|
+
|
|
151
|
+
args: tuple[str, ...]
|
|
152
|
+
returncode: int
|
|
153
|
+
stdout: str = ""
|
|
154
|
+
stderr: str = ""
|
|
155
|
+
exception: BaseException | None = None
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
def _normalise_in_process_argv(argv: list[str] | tuple[str, ...]) -> list[str]:
|
|
159
|
+
"""Accept both ``["pre", ...]`` and ``["launch_bugx.py", "pre", ...]``."""
|
|
160
|
+
values = [str(value) for value in argv]
|
|
161
|
+
if values and Path(values[0]).name == "launch_bugx.py":
|
|
162
|
+
return values
|
|
163
|
+
return ["launch_bugx.py", *values]
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
def _launcher_path(root: Path) -> Path:
|
|
167
|
+
"""返回给定项目根下真实存在的启动器路径(无布局假设)。
|
|
168
|
+
|
|
169
|
+
两种受支持布局:``<root>/core/launch_bugx.py``(自包含引擎副本)与
|
|
170
|
+
``<root>/launch_bugx.py``(归档扁平副本)。都不存在时回退到
|
|
171
|
+
``common.AGENT_DIR``(全局引擎),仍不存在则返回扁平候选——让错误在
|
|
172
|
+
调用方以"文件不存在"暴露,而不是在这里静默造一个假路径。
|
|
173
|
+
"""
|
|
174
|
+
for candidate in (
|
|
175
|
+
root / "core" / "launch_bugx.py",
|
|
176
|
+
root / "launch_bugx.py",
|
|
177
|
+
AGENT_DIR / "launch_bugx.py",
|
|
178
|
+
):
|
|
179
|
+
if candidate.is_file():
|
|
180
|
+
return candidate
|
|
181
|
+
return root / "launch_bugx.py"
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
def run_in_process(
|
|
185
|
+
argv: list[str] | tuple[str, ...],
|
|
186
|
+
*,
|
|
187
|
+
project_root: Path,
|
|
188
|
+
stdin_content: str | None = None,
|
|
189
|
+
capture_output: bool = True,
|
|
190
|
+
env: dict[str, str] | None = None,
|
|
191
|
+
) -> RunResult:
|
|
192
|
+
"""Dispatch one ``launch_bugx`` command inside a recoverable sandbox.
|
|
193
|
+
|
|
194
|
+
This is the library counterpart to ``python launch_bugx.py ...``. It does
|
|
195
|
+
not fake a command by printing a prompt: the real ``main`` dispatcher and
|
|
196
|
+
all phase functions run, while :func:`isolated_runtime_scope` binds the
|
|
197
|
+
sandbox paths and restores process state on every exit path. Calls are
|
|
198
|
+
serialized by the scope because the legacy phases still use process-global
|
|
199
|
+
cwd/environment/module aliases; independent OS subprocesses remain the
|
|
200
|
+
correct lane for signal, orphan-reaping and process-group tests.
|
|
201
|
+
"""
|
|
202
|
+
command_argv = _normalise_in_process_argv(argv)
|
|
203
|
+
if command_argv[1:2] == ["daemon"] and "--help" not in command_argv[2:]:
|
|
204
|
+
message = "[launch_bugx] daemon 需要独立 OS 进程及信号生命周期,请通过 CLI/subprocess 执行。\n"
|
|
205
|
+
if not capture_output:
|
|
206
|
+
print(message, end="", file=sys.stderr)
|
|
207
|
+
return RunResult(
|
|
208
|
+
args=tuple(command_argv), returncode=2,
|
|
209
|
+
stderr=message if capture_output else "",
|
|
210
|
+
)
|
|
211
|
+
stdout_buffer = io.StringIO()
|
|
212
|
+
stderr_buffer = io.StringIO()
|
|
213
|
+
stdin = io.StringIO("" if stdin_content is None else str(stdin_content))
|
|
214
|
+
returncode = 1
|
|
215
|
+
captured_exception: BaseException | None = None
|
|
216
|
+
|
|
217
|
+
# ``redirect_stdin`` is not present on every supported Python minor. A
|
|
218
|
+
# tiny local context manager keeps the harness compatible without changing
|
|
219
|
+
# the production interaction layer.
|
|
220
|
+
@contextlib.contextmanager
|
|
221
|
+
def _redirect_stdin(stream):
|
|
222
|
+
previous = sys.stdin
|
|
223
|
+
sys.stdin = stream
|
|
224
|
+
try:
|
|
225
|
+
yield
|
|
226
|
+
finally:
|
|
227
|
+
sys.stdin = previous
|
|
228
|
+
|
|
229
|
+
with isolated_runtime_scope(project_root, env=env) as root:
|
|
230
|
+
previous_argv = list(sys.argv)
|
|
231
|
+
# ``sys.argv[0]`` 必须是**真实启动器路径**,不能假设扁平的
|
|
232
|
+
# ``<root>/launch_bugx.py``:自包含引擎副本布局是
|
|
233
|
+
# ``<root>/core/launch_bugx.py``,硬编码扁平路径会让
|
|
234
|
+
# ``bugx_paths.project_root()`` 与 ``resolve_project_root()``
|
|
235
|
+
# 拿到一个不存在的脚本位置(并让下游以它为"仓库根"拼路径)。
|
|
236
|
+
sys.argv = [str(_launcher_path(root)), *command_argv[1:]]
|
|
237
|
+
try:
|
|
238
|
+
output_context = (
|
|
239
|
+
contextlib.ExitStack()
|
|
240
|
+
if capture_output else contextlib.nullcontext()
|
|
241
|
+
)
|
|
242
|
+
with output_context as stack:
|
|
243
|
+
if capture_output:
|
|
244
|
+
stack.enter_context(contextlib.redirect_stdout(stdout_buffer))
|
|
245
|
+
stack.enter_context(contextlib.redirect_stderr(stderr_buffer))
|
|
246
|
+
with _redirect_stdin(stdin):
|
|
247
|
+
try:
|
|
248
|
+
value = main(command_argv)
|
|
249
|
+
returncode = int(value) if value is not None else 0
|
|
250
|
+
except SystemExit as exc:
|
|
251
|
+
captured_exception = exc
|
|
252
|
+
code = exc.code
|
|
253
|
+
returncode = int(code) if isinstance(code, int) else (
|
|
254
|
+
0 if code is None else 1
|
|
255
|
+
)
|
|
256
|
+
if code is not None and not isinstance(code, int):
|
|
257
|
+
print(code, file=sys.stderr)
|
|
258
|
+
except KeyboardInterrupt as exc:
|
|
259
|
+
captured_exception = exc
|
|
260
|
+
returncode = 130
|
|
261
|
+
except Exception as exc: # pragma: no cover - defensive boundary
|
|
262
|
+
captured_exception = exc
|
|
263
|
+
returncode = 1
|
|
264
|
+
print(
|
|
265
|
+
f"[launch_bugx] ✗ 进程内分发异常: {type(exc).__name__}: {exc}",
|
|
266
|
+
file=sys.stderr,
|
|
267
|
+
)
|
|
268
|
+
finally:
|
|
269
|
+
sys.argv = previous_argv
|
|
270
|
+
|
|
271
|
+
return RunResult(
|
|
272
|
+
args=tuple(command_argv),
|
|
273
|
+
returncode=returncode,
|
|
274
|
+
stdout=stdout_buffer.getvalue() if capture_output else "",
|
|
275
|
+
stderr=stderr_buffer.getvalue() if capture_output else "",
|
|
276
|
+
exception=captured_exception,
|
|
277
|
+
)
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
def _require_project_layout() -> bool:
|
|
281
|
+
"""Refuse stateful commands when the project runtime scope is unavailable."""
|
|
282
|
+
if uses_project_layout():
|
|
283
|
+
return True
|
|
284
|
+
if os.environ.get("BUGX_AIR_GAP") == "1":
|
|
285
|
+
return True
|
|
286
|
+
print(
|
|
287
|
+
"[launch_bugx] ✗ 缺少有效的 .bugx 项目运行布局;"
|
|
288
|
+
"拒绝向全局引擎写入运行态。请先在项目根执行 `bugx init`。"
|
|
289
|
+
)
|
|
290
|
+
return False
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
def _resume_ticket_handoff(
|
|
294
|
+
project_root: Path, resume_ticket_module, ticket: dict[str, Any],
|
|
295
|
+
) -> int | None:
|
|
296
|
+
"""Handle one resume ticket without duplicating host/CLI handoff logic."""
|
|
297
|
+
startup_env = detect_startup_environment()
|
|
298
|
+
gui_hosts = {"workbuddy", "qoder", "trea", "zcode"}
|
|
299
|
+
if (getattr(startup_env, "interface", None) != "acp"
|
|
300
|
+
and getattr(startup_env, "host", None) in gui_hosts):
|
|
301
|
+
print("BUGX_RESUME_TICKET " + json.dumps(
|
|
302
|
+
resume_ticket_module.resume_card(ticket), ensure_ascii=False,
|
|
303
|
+
))
|
|
304
|
+
return POLLING_DECISION_REQUIRED
|
|
305
|
+
if resume_ticket_module.consume_resume_ticket(project_root) is not None:
|
|
306
|
+
# ``os.execv`` 只在**真实 OS 进程**车道成立:它把当前进程整块替换成
|
|
307
|
+
# 新解释器。进程内车道(``run_in_process`` / 嵌入式宿主 / 测试进程)
|
|
308
|
+
# 里执行它等于把宿主进程杀掉——实测整个 pytest 会话在一次 pre 之后
|
|
309
|
+
# 静默退出(exit 0、零输出、后续用例全部消失),看起来像"全绿"。
|
|
310
|
+
# 进程内车道改为就地继续:resume ticket 已经被消费,重启语义由
|
|
311
|
+
# 调用方决定,绝不能劫持宿主进程。
|
|
312
|
+
if not IN_PROCESS_SCOPE.get():
|
|
313
|
+
os.execv(sys.executable, [sys.executable, *sys.argv])
|
|
314
|
+
return None
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
def _peek_pending_resume_ticket(project_root: Path) -> dict[str, Any] | None:
|
|
318
|
+
"""Read-only peek used only for an incomplete GUI handoff.
|
|
319
|
+
|
|
320
|
+
``resume_ticket.consume_resume_ticket`` remains the authority for all
|
|
321
|
+
mutation and claim semantics. The peek exists because a GUI must display
|
|
322
|
+
its card without deleting the ticket, and is limited to a layout already
|
|
323
|
+
validated by ``prepare_project``.
|
|
324
|
+
"""
|
|
325
|
+
target = project_root / ".bugx" / "resume_ticket.json"
|
|
326
|
+
# 路径必须**归一化后**比较:macOS 上 ``tempfile`` 给出 ``/var/...`` 而
|
|
327
|
+
# ``Path.resolve()`` 给出 ``/private/var/...``,直接用字符串比对会让同一目录
|
|
328
|
+
# 判成不同项目 → GUI resume 卡片永远不显示(build 286 全量验证发现)。
|
|
329
|
+
resolved_root = project_root.resolve()
|
|
330
|
+
try:
|
|
331
|
+
if target.is_symlink() or not target.is_file():
|
|
332
|
+
return None
|
|
333
|
+
payload = json.loads(target.read_text(encoding="utf-8"))
|
|
334
|
+
except (OSError, UnicodeError, ValueError, TypeError):
|
|
335
|
+
return None
|
|
336
|
+
if not isinstance(payload, dict) or payload.get("schema_version") != 1:
|
|
337
|
+
return None
|
|
338
|
+
recorded_root = str(payload.get("project_root") or "")
|
|
339
|
+
if not recorded_root or Path(recorded_root).resolve() != resolved_root:
|
|
340
|
+
return None
|
|
341
|
+
expires_at = payload.get("expires_at")
|
|
342
|
+
if not isinstance(expires_at, (int, float)) or float(expires_at) <= time.time():
|
|
343
|
+
return None
|
|
344
|
+
return payload
|
|
345
|
+
|
|
346
|
+
|
|
347
|
+
def _emit_post_attempt_event(
|
|
348
|
+
event: str, *, level: int = 20, **fields: object,
|
|
349
|
+
) -> bool:
|
|
350
|
+
"""Write a post command event through the acknowledged local JSONL path."""
|
|
351
|
+
try:
|
|
352
|
+
from core.launch_phases.post_observability import emit_attempt_event
|
|
353
|
+
return emit_attempt_event(event, level=level, **fields)
|
|
354
|
+
except Exception:
|
|
355
|
+
return False
|
|
356
|
+
|
|
357
|
+
|
|
358
|
+
def _log_early_post_failure(
|
|
359
|
+
exit_code: int, reason: str, *, gate_name: str = "dispatch_runtime_paths",
|
|
360
|
+
gate_status: str = "blocked",
|
|
361
|
+
) -> None:
|
|
362
|
+
"""Keep post failures structured even when startup gates return early."""
|
|
363
|
+
try:
|
|
364
|
+
from core.launch_phases.post_observability import (
|
|
365
|
+
attempt_scope, current_attempt, log_attempt_finished,
|
|
366
|
+
record_dispatch_failure,
|
|
367
|
+
)
|
|
368
|
+
if current_attempt() is None:
|
|
369
|
+
with attempt_scope("dispatcher"):
|
|
370
|
+
_emit_post_attempt_event("core_command_started")
|
|
371
|
+
record_dispatch_failure(
|
|
372
|
+
gate_name, reason, exit_code=exit_code,
|
|
373
|
+
gate_status=gate_status,
|
|
374
|
+
)
|
|
375
|
+
_emit_post_attempt_event(
|
|
376
|
+
"core_command_finished", level=40,
|
|
377
|
+
exit_code=exit_code, status="failed",
|
|
378
|
+
)
|
|
379
|
+
log_attempt_finished(exit_code)
|
|
380
|
+
else:
|
|
381
|
+
_emit_post_attempt_event("core_command_started")
|
|
382
|
+
record_dispatch_failure(
|
|
383
|
+
gate_name, reason, exit_code=exit_code,
|
|
384
|
+
gate_status=gate_status,
|
|
385
|
+
)
|
|
386
|
+
_emit_post_attempt_event(
|
|
387
|
+
"core_command_finished", level=40,
|
|
388
|
+
exit_code=exit_code, status="failed",
|
|
389
|
+
)
|
|
390
|
+
except Exception:
|
|
391
|
+
# Telemetry cannot change the early gate's business verdict.
|
|
392
|
+
pass
|
|
393
|
+
|
|
394
|
+
|
|
395
|
+
def _post_dry_run_cli() -> int:
|
|
396
|
+
"""Print a read-only frozen-snapshot report without entering post dispatch."""
|
|
397
|
+
from core.launch_phases import post_dry_run
|
|
398
|
+
|
|
399
|
+
try:
|
|
400
|
+
snapshot = post_dry_run.capture_snapshot(resolve_project_root())
|
|
401
|
+
report = post_dry_run.evaluate_snapshot(snapshot)
|
|
402
|
+
except post_dry_run.SnapshotInvalid as exc:
|
|
403
|
+
report = post_dry_run.blocked_report(exc.reason_code)
|
|
404
|
+
except Exception:
|
|
405
|
+
# Dry-run failures are structured and fail-closed. Never leak arbitrary
|
|
406
|
+
# exception detail into the machine-readable report.
|
|
407
|
+
report = post_dry_run.blocked_report("snapshot_capture_error")
|
|
408
|
+
report = dict(report)
|
|
409
|
+
report["mode"] = "post_dry_run"
|
|
410
|
+
print(json.dumps(report, ensure_ascii=False, sort_keys=True))
|
|
411
|
+
return 0 if report.get("status") == "passed" and report.get("coherence") == "proven" else 1
|
|
412
|
+
|
|
413
|
+
try:
|
|
414
|
+
from core.coverage import coverage_bootstrap
|
|
415
|
+
except ImportError:
|
|
416
|
+
coverage_bootstrap = None
|
|
417
|
+
|
|
418
|
+
|
|
419
|
+
|
|
420
|
+
from core.launch_phases.orchestrator_controls import (
|
|
421
|
+
abort,
|
|
422
|
+
bootstrap_coverage,
|
|
423
|
+
cmd_prompt,
|
|
424
|
+
fix_review,
|
|
425
|
+
heartbeat,
|
|
426
|
+
legacy_supervisor_state,
|
|
427
|
+
lesson_module,
|
|
428
|
+
pause,
|
|
429
|
+
polling,
|
|
430
|
+
print_help,
|
|
431
|
+
resume,
|
|
432
|
+
status,
|
|
433
|
+
)
|
|
434
|
+
from core.launch_phases.candidate_revalidation import (
|
|
435
|
+
candidate_dependencies,
|
|
436
|
+
candidate_inventory,
|
|
437
|
+
changed_test_files,
|
|
438
|
+
ci_detection_report,
|
|
439
|
+
declared_dependencies,
|
|
440
|
+
inside_project,
|
|
441
|
+
revalidate_candidates,
|
|
442
|
+
safe_reproduction_command,
|
|
443
|
+
verify_candidate_assets,
|
|
444
|
+
)
|
|
445
|
+
|
|
446
|
+
# Compatibility aliases
|
|
447
|
+
_lesson_module = lesson_module
|
|
448
|
+
_inside_project = inside_project
|
|
449
|
+
_candidate_inventory = candidate_inventory
|
|
450
|
+
_candidate_dependencies = candidate_dependencies
|
|
451
|
+
_declared_dependencies = declared_dependencies
|
|
452
|
+
_verify_candidate_assets = verify_candidate_assets
|
|
453
|
+
_safe_reproduction_command = safe_reproduction_command
|
|
454
|
+
_changed_test_files = changed_test_files
|
|
455
|
+
_ci_detection_report = ci_detection_report
|
|
456
|
+
_legacy_supervisor_state = legacy_supervisor_state
|
|
457
|
+
_print_help = print_help
|
|
458
|
+
|
|
459
|
+
def _option_value(args: list[str], option: str) -> str | None:
|
|
460
|
+
for i, arg in enumerate(args):
|
|
461
|
+
if arg == option:
|
|
462
|
+
return args[i + 1] if i + 1 < len(args) else None
|
|
463
|
+
if arg.startswith(f"{option}="):
|
|
464
|
+
return arg.split("=", 1)[1]
|
|
465
|
+
return None
|
|
466
|
+
|
|
467
|
+
def _reject_legacy_share_policy(argv: list[str]) -> int | None:
|
|
468
|
+
"""Reject the removed pre flag before any project/runtime side effect."""
|
|
469
|
+
if any(
|
|
470
|
+
arg == "--share-policy" or arg.startswith("--share-policy=")
|
|
471
|
+
for arg in argv[1:]
|
|
472
|
+
):
|
|
473
|
+
print(
|
|
474
|
+
"[launch_bugx] ✗ --share-policy 已移除;请使用 "
|
|
475
|
+
"`pre --report-policy none|local|submit`。"
|
|
476
|
+
)
|
|
477
|
+
return 2
|
|
478
|
+
return None
|
|
479
|
+
|
|
480
|
+
|
|
481
|
+
def main(argv: list[str]) -> int:
|
|
482
|
+
"""Bind one context-local attempt around CLI post dispatch."""
|
|
483
|
+
values = list(argv)
|
|
484
|
+
known = {
|
|
485
|
+
"pre", "post", "status", "polling", "heartbeat", "pause", "resume",
|
|
486
|
+
"abort", "bootstrap-coverage", "fix-review", "audit", "control",
|
|
487
|
+
"workers", "judge", "findings-confirm", "revalidate-candidates", "prompt", "daemon", "help", "--help", "-h",
|
|
488
|
+
"coverage",
|
|
489
|
+
}
|
|
490
|
+
if values and (values[0] in known or values[0].startswith("-")):
|
|
491
|
+
values = ["launch_bugx.py", *values]
|
|
492
|
+
legacy_share_policy = _reject_legacy_share_policy(values)
|
|
493
|
+
if legacy_share_policy is not None:
|
|
494
|
+
return legacy_share_policy
|
|
495
|
+
command = values[1] if len(values) > 1 else "status"
|
|
496
|
+
if command != "post" or "--dry-run" in values[2:]:
|
|
497
|
+
return _main_impl(values)
|
|
498
|
+
from core.launch_phases.post_observability import (
|
|
499
|
+
attempt_scope, current_attempt, log_attempt_finished,
|
|
500
|
+
record_unhandled_exception,
|
|
501
|
+
)
|
|
502
|
+
with attempt_scope("dispatcher") as attempt:
|
|
503
|
+
try:
|
|
504
|
+
result = _main_impl(
|
|
505
|
+
values, _post_attempt_token=attempt.attempt_token,
|
|
506
|
+
)
|
|
507
|
+
except BaseException as exc:
|
|
508
|
+
exit_code = 130 if isinstance(exc, KeyboardInterrupt) else 1
|
|
509
|
+
if isinstance(exc, SystemExit):
|
|
510
|
+
code = exc.code
|
|
511
|
+
exit_code = code if isinstance(code, int) and code != 0 else 1
|
|
512
|
+
active = current_attempt()
|
|
513
|
+
if active is not None and not active.failure_recorded:
|
|
514
|
+
record_unhandled_exception(exc, exit_code=exit_code)
|
|
515
|
+
_emit_post_attempt_event(
|
|
516
|
+
"core_command_finished", level=40,
|
|
517
|
+
exit_code=exit_code, status="failed",
|
|
518
|
+
)
|
|
519
|
+
log_attempt_finished(exit_code)
|
|
520
|
+
raise
|
|
521
|
+
log_attempt_finished(result)
|
|
522
|
+
return result
|
|
523
|
+
|
|
524
|
+
|
|
525
|
+
def _main_impl(
|
|
526
|
+
argv: list[str], *, _post_attempt_token: object | None = None,
|
|
527
|
+
) -> int:
|
|
528
|
+
_KNOWN_CMDS = {
|
|
529
|
+
"pre", "post", "status", "polling", "heartbeat", "pause", "resume",
|
|
530
|
+
"abort", "bootstrap-coverage", "fix-review", "audit", "control",
|
|
531
|
+
"workers", "judge", "findings-confirm", "revalidate-candidates", "prompt", "daemon", "help", "--help", "-h",
|
|
532
|
+
}
|
|
533
|
+
if argv and (argv[0] in _KNOWN_CMDS or argv[0].startswith("-")):
|
|
534
|
+
argv = ["launch_bugx.py"] + list(argv)
|
|
535
|
+
cmd = argv[1] if len(argv) > 1 else "status"
|
|
536
|
+
legacy_share_policy = _reject_legacy_share_policy(argv)
|
|
537
|
+
if legacy_share_policy is not None:
|
|
538
|
+
return legacy_share_policy
|
|
539
|
+
_HELP_TOKENS = {"help", "--help", "-h"}
|
|
540
|
+
if cmd in _HELP_TOKENS or any(token in _HELP_TOKENS for token in argv[2:]):
|
|
541
|
+
# 帮助契约要求三种写法都只读:`pre help` / `pre -h` 若不在这里截住,
|
|
542
|
+
# 会落进真实 pre 相位并写启动态,违反文档承诺。
|
|
543
|
+
return _print_help()
|
|
544
|
+
if cmd == "status" and os.environ.get("BUGX_PROJECT_ROOT"):
|
|
545
|
+
# Querying a fresh project must not require the layout that only pre
|
|
546
|
+
# creates. Keep this path read-only and recheck inside status().
|
|
547
|
+
try:
|
|
548
|
+
from core.runtime import project_init
|
|
549
|
+
|
|
550
|
+
if project_init.is_uninitialized_project(resolve_project_root()):
|
|
551
|
+
return status(as_json="--json" in argv[2:])
|
|
552
|
+
except (OSError, ValueError, RuntimeError) as exc:
|
|
553
|
+
if "--json" in argv[2:]:
|
|
554
|
+
print(json.dumps({"status": "BLOCKED", "reason": str(exc)}, ensure_ascii=False))
|
|
555
|
+
else:
|
|
556
|
+
print(f"[launch_bugx] ✗ 项目状态检查失败:{exc}")
|
|
557
|
+
return 1
|
|
558
|
+
if cmd in {"pre", "audit"} and "--allow-degraded" in argv[2:]:
|
|
559
|
+
# DOC-236 C1(A4):降级放行已废除。守卫必须位于**所有** pre/audit 出口
|
|
560
|
+
# 之前——放在尾部 dispatch 会被前置硬门禁(交互/版本/云/策略门禁)提前
|
|
561
|
+
# 返回绕过,从而变成"静默忽略"而不是"显式拒绝"。
|
|
562
|
+
print("[launch_bugx] ✗ --allow-degraded 已废除(DOC-236 C1 不允许降级):"
|
|
563
|
+
"请先自愈安装/配置;确无自动安装器的专有工具,"
|
|
564
|
+
"在 .bugx/config.json 的 tooling_exemptions 中显式豁免。")
|
|
565
|
+
return 1
|
|
566
|
+
# DOC-236 C5:只做轻量布局/config/fingerprint 准备;宿主、交互、Git、
|
|
567
|
+
# 版本与云门禁全部通过后才进入完整画像/探针/coverage pipeline。
|
|
568
|
+
# DOC-174 的 pending ticket 只做一次廉价恢复,不重新启动昂贵初始化。
|
|
569
|
+
project_root: Path | None = None
|
|
570
|
+
project_init_module = None
|
|
571
|
+
resume_ticket_module = None
|
|
572
|
+
if cmd in {"pre", "audit"} and os.environ.get("BUGX_PROJECT_ROOT"):
|
|
573
|
+
try:
|
|
574
|
+
from core.runtime import project_init as project_init_module
|
|
575
|
+
from core.runtime import resume_ticket as resume_ticket_module
|
|
576
|
+
|
|
577
|
+
project_root = Path(os.environ["BUGX_PROJECT_ROOT"]).expanduser().resolve()
|
|
578
|
+
project_init_module.prepare_project(project_root, AGENT_DIR)
|
|
579
|
+
# A headless/ACP restart can safely consume its one-use ticket and
|
|
580
|
+
# re-exec before gates, preserving the historical CLI handoff.
|
|
581
|
+
# GUI hosts must keep the ticket until the reload has passed all
|
|
582
|
+
# hard gates; otherwise the card would point at a deleted ticket.
|
|
583
|
+
startup_env = detect_startup_environment()
|
|
584
|
+
gui_hosts = {"workbuddy", "qoder", "trea", "zcode"}
|
|
585
|
+
is_gui_resume = (
|
|
586
|
+
getattr(startup_env, "interface", None) != "acp"
|
|
587
|
+
and getattr(startup_env, "host", None) in gui_hosts
|
|
588
|
+
)
|
|
589
|
+
if is_gui_resume:
|
|
590
|
+
pending_ticket = _peek_pending_resume_ticket(project_root)
|
|
591
|
+
config = project_init_module._read_config(
|
|
592
|
+
project_root / ".bugx" / "config.json",
|
|
593
|
+
)
|
|
594
|
+
if (isinstance(pending_ticket, dict)
|
|
595
|
+
and config.get("status") != "ready"):
|
|
596
|
+
print("BUGX_RESUME_TICKET " + json.dumps(
|
|
597
|
+
resume_ticket_module.resume_card(pending_ticket),
|
|
598
|
+
ensure_ascii=False,
|
|
599
|
+
))
|
|
600
|
+
return POLLING_DECISION_REQUIRED
|
|
601
|
+
else:
|
|
602
|
+
pending_ticket = resume_ticket_module.consume_resume_ticket(project_root)
|
|
603
|
+
if isinstance(pending_ticket, dict):
|
|
604
|
+
os.execv(sys.executable, [sys.executable, *sys.argv])
|
|
605
|
+
except (OSError, ValueError, RuntimeError, subprocess.SubprocessError) as exc:
|
|
606
|
+
print(f"[launch_bugx] ✗ 项目初始化/续做失败:{exc}")
|
|
607
|
+
return 1
|
|
608
|
+
if cmd == "post" and "--dry-run" in argv[2:]:
|
|
609
|
+
return _post_dry_run_cli()
|
|
610
|
+
logger = None
|
|
611
|
+
if cmd == "post":
|
|
612
|
+
# Set up diagnostics before layout/version/runtime-path gates can reject.
|
|
613
|
+
logger = diagnostic_logger(cmd)
|
|
614
|
+
from core.launch_phases.common import set_diagnostic_logger
|
|
615
|
+
set_diagnostic_logger(logger)
|
|
616
|
+
if cmd in _STATEFUL_COMMANDS and not _require_project_layout():
|
|
617
|
+
if cmd == "post":
|
|
618
|
+
_log_early_post_failure(
|
|
619
|
+
1, "project_layout_unavailable", gate_name="dispatch_layout",
|
|
620
|
+
)
|
|
621
|
+
return 1
|
|
622
|
+
startup_version_banner(
|
|
623
|
+
stream=sys.stderr if "--json" in argv[2:] else sys.stdout
|
|
624
|
+
)
|
|
625
|
+
if logger is None:
|
|
626
|
+
logger = diagnostic_logger(cmd)
|
|
627
|
+
from core.launch_phases.common import set_diagnostic_logger
|
|
628
|
+
set_diagnostic_logger(logger)
|
|
629
|
+
environment = detect_startup_environment()
|
|
630
|
+
# Stable 剥离下方 DEV_ONLY 块后开发模式参数不存在,哨兵值让下游全部回落到生产缺省。
|
|
631
|
+
dev_mode_requested = False
|
|
632
|
+
# [BEGIN DEV_ONLY: DEV_MODE_ARG]
|
|
633
|
+
dev_mode_requested = "--dev" in argv[2:]
|
|
634
|
+
# [END DEV_ONLY: DEV_MODE_ARG]
|
|
635
|
+
autonomous_requested = "--autonomous" in argv[2:] or dev_mode_requested
|
|
636
|
+
if not autonomous_requested and cmd in {"pre", "audit"}:
|
|
637
|
+
try:
|
|
638
|
+
from core.runtime import session_profile
|
|
639
|
+
early_profile = session_profile.load_profile(root=resolve_project_root()) or {}
|
|
640
|
+
autonomous_requested = (
|
|
641
|
+
str(early_profile.get("mode", "")).strip().lower() == "autonomous"
|
|
642
|
+
)
|
|
643
|
+
except Exception:
|
|
644
|
+
autonomous_requested = False
|
|
645
|
+
startup_todo_path = None
|
|
646
|
+
if cmd in {"pre", "audit"} and project_layout_present():
|
|
647
|
+
startup_todo_path = refresh_startup_todo(
|
|
648
|
+
"environment",
|
|
649
|
+
reason="启动入口已进入,正在收集并校验环境信息",
|
|
650
|
+
environment=environment,
|
|
651
|
+
)
|
|
652
|
+
if startup_todo_path:
|
|
653
|
+
print(f"[BugX] 启动总览 TODO:{startup_todo_path}")
|
|
654
|
+
print(startup_todo_content(
|
|
655
|
+
"environment",
|
|
656
|
+
reason="启动入口已进入,正在收集并校验环境信息",
|
|
657
|
+
environment=environment,
|
|
658
|
+
).rstrip())
|
|
659
|
+
if cmd in {"pre", "audit"} and environment is not None:
|
|
660
|
+
# 诊断行必须走 **stderr**:stdout 是机读协议通道(`BUGX_RESUME_TICKET <json>`
|
|
661
|
+
# 等标记要求独占可解析)。此前打到 stdout,导致宿主侧按「第一行」解析时
|
|
662
|
+
# 拿到 `[BugX] Startup environment: ...`(build 276 全量验证发现)。
|
|
663
|
+
print(
|
|
664
|
+
f"[BugX] Startup environment: {startup_environment_line(environment)}",
|
|
665
|
+
file=sys.stderr,
|
|
666
|
+
)
|
|
667
|
+
if uses_project_layout():
|
|
668
|
+
print_supervisor_mcp_snapshot(supervisor_mcp_snapshot())
|
|
669
|
+
# 哨兵必须在 DEV_ONLY 块之外:Stable 剥离后下方条件仍会读取该名字。
|
|
670
|
+
bypass_headless_gate = False
|
|
671
|
+
# [BEGIN DEV_ONLY: FAST_VERIFICATION_HEADLESS_BYPASS]
|
|
672
|
+
try:
|
|
673
|
+
from core.runtime.interaction import try_get_preset_runtime_config
|
|
674
|
+
except ImportError:
|
|
675
|
+
try:
|
|
676
|
+
from core.runtime.interaction import try_get_preset_runtime_config
|
|
677
|
+
except ImportError:
|
|
678
|
+
try_get_preset_runtime_config = None
|
|
679
|
+
if try_get_preset_runtime_config is not None:
|
|
680
|
+
if try_get_preset_runtime_config(resolve_project_root() if uses_project_layout() else None):
|
|
681
|
+
bypass_headless_gate = True
|
|
682
|
+
# [END DEV_ONLY: FAST_VERIFICATION_HEADLESS_BYPASS]
|
|
683
|
+
if (uses_project_layout()
|
|
684
|
+
# 缺字段(最小化 mock 环境)不得让启动流程崩:诊断/门禁按「未知」
|
|
685
|
+
# 处理,不等于 blocked,因此不额外拦截。
|
|
686
|
+
and getattr(environment, "interaction", None) == "blocked"
|
|
687
|
+
and not autonomous_requested
|
|
688
|
+
and not bypass_headless_gate
|
|
689
|
+
and not pre_has_explicit_startup_choices(argv[2:])):
|
|
690
|
+
emit_startup_gate(
|
|
691
|
+
"startup_interaction",
|
|
692
|
+
"当前宿主没有可用的原生单选控件或真实 TTY",
|
|
693
|
+
[
|
|
694
|
+
{
|
|
695
|
+
"label": "重启宿主并使用原生单选",
|
|
696
|
+
"description": "重启当前已识别的交互宿主后继续",
|
|
697
|
+
"value": "restart_host",
|
|
698
|
+
"action": "restart_host",
|
|
699
|
+
},
|
|
700
|
+
{
|
|
701
|
+
"label": "在真实 TTY 中运行",
|
|
702
|
+
"description": "通过方向键单选菜单继续",
|
|
703
|
+
"value": "run_tty",
|
|
704
|
+
"action": "run_in_tty",
|
|
705
|
+
},
|
|
706
|
+
{
|
|
707
|
+
"label": "下次再说",
|
|
708
|
+
"description": "停止本轮启动",
|
|
709
|
+
"value": "later",
|
|
710
|
+
"action": "stop_startup",
|
|
711
|
+
},
|
|
712
|
+
],
|
|
713
|
+
environment=environment,
|
|
714
|
+
detail=environment.reason,
|
|
715
|
+
)
|
|
716
|
+
return POLLING_DECISION_REQUIRED
|
|
717
|
+
# Git is an environment hard prerequisite, not a later tool preference.
|
|
718
|
+
# Check it before version, cloud, MCP and coverage gates so no Session or
|
|
719
|
+
# other runtime state can be created without a reproducible code baseline.
|
|
720
|
+
if cmd in {"pre", "audit"} and project_layout_present():
|
|
721
|
+
if not git_startup_gate(environment, auto_init=dev_mode_requested):
|
|
722
|
+
return POLLING_DECISION_REQUIRED
|
|
723
|
+
if project_layout_present():
|
|
724
|
+
version_ok, version_detail, gate_kind = startup_version_gate()
|
|
725
|
+
if not version_ok:
|
|
726
|
+
if gate_kind == "project_layout":
|
|
727
|
+
print(f"[launch_bugx] ✗ 项目状态检查失败:{version_detail}")
|
|
728
|
+
emit_project_layout_gate(version_detail, environment)
|
|
729
|
+
else:
|
|
730
|
+
print(f"[launch_bugx] ✗ 启动版本门禁失败:{version_detail}")
|
|
731
|
+
emit_version_contract_gate(version_detail, environment)
|
|
732
|
+
if cmd == "post":
|
|
733
|
+
_log_early_post_failure(
|
|
734
|
+
POLLING_DECISION_REQUIRED,
|
|
735
|
+
"startup_version_gate_failed",
|
|
736
|
+
gate_name="dispatch_version",
|
|
737
|
+
)
|
|
738
|
+
return POLLING_DECISION_REQUIRED
|
|
739
|
+
if cmd in {"pre", "audit"}:
|
|
740
|
+
refresh_startup_todo(
|
|
741
|
+
"startup",
|
|
742
|
+
reason="环境与版本门禁通过,准备执行串行启动配置",
|
|
743
|
+
environment=environment,
|
|
744
|
+
)
|
|
745
|
+
# 非阻断版本检查:向服务端查询是否有新版本(air-gap / 网络不可达时静默跳过)。
|
|
746
|
+
# PERF-07:调度到守护线程执行,绝不在启动关键路径上同步等待。
|
|
747
|
+
if cmd in {"pre", "audit"}:
|
|
748
|
+
schedule_startup_remote_version_check(
|
|
749
|
+
stream=sys.stderr if "--json" in argv[2:] else sys.stdout,
|
|
750
|
+
)
|
|
751
|
+
if uses_project_layout():
|
|
752
|
+
try:
|
|
753
|
+
refresh_runtime_paths()
|
|
754
|
+
except (OSError, ValueError, RuntimeError) as exc:
|
|
755
|
+
if logger is not None and cmd != "post":
|
|
756
|
+
bugx_logging.log_event(
|
|
757
|
+
logger, "core_command_failed", str(exc), level=40,
|
|
758
|
+
command=cmd, exception_type=type(exc).__name__, exc_info=True,
|
|
759
|
+
)
|
|
760
|
+
if cmd == "post":
|
|
761
|
+
_log_early_post_failure(
|
|
762
|
+
1, "runtime_paths_unavailable",
|
|
763
|
+
gate_name="dispatch_runtime_paths",
|
|
764
|
+
gate_status="error",
|
|
765
|
+
)
|
|
766
|
+
print(f"[launch_bugx] ✗ .bugx 运行布局不可用: {exc}")
|
|
767
|
+
return 1
|
|
768
|
+
if cmd in {"pre", "audit"} and uses_project_layout():
|
|
769
|
+
try:
|
|
770
|
+
retry_pending_commit()
|
|
771
|
+
except (OSError, ValueError, RuntimeError) as exc:
|
|
772
|
+
if logger is not None:
|
|
773
|
+
bugx_logging.log_event(
|
|
774
|
+
logger, "git_recovery_failed", str(exc), level=40,
|
|
775
|
+
command=cmd, exception_type=type(exc).__name__, exc_info=True,
|
|
776
|
+
)
|
|
777
|
+
if cmd in {"pre", "audit"}:
|
|
778
|
+
profile_cfg = {}
|
|
779
|
+
try:
|
|
780
|
+
from core.runtime import session_profile
|
|
781
|
+
profile_cfg = session_profile.load_profile(
|
|
782
|
+
_option_value(argv[2:], "--profile"), root=resolve_project_root(),
|
|
783
|
+
) or {}
|
|
784
|
+
except Exception:
|
|
785
|
+
profile_cfg = {}
|
|
786
|
+
autonomous_mode = (
|
|
787
|
+
"--autonomous" in argv[2:]
|
|
788
|
+
or dev_mode_requested
|
|
789
|
+
or str(profile_cfg.get("mode", "")).strip().lower() == "autonomous"
|
|
790
|
+
)
|
|
791
|
+
cloud_policy = _option_value(argv[2:], "--cloud-sync") or profile_cfg.get("cloud_sync")
|
|
792
|
+
# [BEGIN DEV_ONLY: DEV_MODE_CLOUD_LOCAL]
|
|
793
|
+
if dev_mode_requested and not cloud_policy:
|
|
794
|
+
# 开发模式默认本地:无登录态的新机器上强制 sync 会被云端门禁判成
|
|
795
|
+
# BLOCKED(绝对阻断),"极速"反而起不来。显式 --cloud-sync sync
|
|
796
|
+
# 或项目/全局配置仍是同步的唯一入口,与 --dev 帮助文案
|
|
797
|
+
# 「使用本地/显式云同步」保持一致。
|
|
798
|
+
cloud_policy = "local"
|
|
799
|
+
# [END DEV_ONLY: DEV_MODE_CLOUD_LOCAL]
|
|
800
|
+
onboarding_result = startup_cloud_onboarding(
|
|
801
|
+
cloud_policy, autonomous=autonomous_mode,
|
|
802
|
+
)
|
|
803
|
+
if onboarding_result != 0:
|
|
804
|
+
return onboarding_result
|
|
805
|
+
refresh_startup_todo(
|
|
806
|
+
"startup",
|
|
807
|
+
reason="云端同步门禁已处理,等待其余启动配置和恢复决策",
|
|
808
|
+
environment=environment,
|
|
809
|
+
)
|
|
810
|
+
# DOC-236 C5:完整项目画像、可选 MCP 探针、prep/coverage bootstrap
|
|
811
|
+
# 必须位于宿主/交互/Git/版本硬门禁和云决策之后,且早于 pre() 的
|
|
812
|
+
# 策略门禁与探针剪枝。保持 report_policy 的 C6 参数转发不变。
|
|
813
|
+
if project_root is not None and project_init_module is not None:
|
|
814
|
+
try:
|
|
815
|
+
init_state = project_init_module.run_init_pipeline(
|
|
816
|
+
project_root, AGENT_DIR,
|
|
817
|
+
)
|
|
818
|
+
except (OSError, ValueError, RuntimeError, subprocess.SubprocessError) as exc:
|
|
819
|
+
print(f"[launch_bugx] ✗ 项目初始化/续做失败:{exc}")
|
|
820
|
+
return 1
|
|
821
|
+
ticket = init_state.get("resume_ticket")
|
|
822
|
+
if isinstance(ticket, dict) and resume_ticket_module is not None:
|
|
823
|
+
handoff = _resume_ticket_handoff(
|
|
824
|
+
project_root, resume_ticket_module, ticket,
|
|
825
|
+
)
|
|
826
|
+
if handoff is not None:
|
|
827
|
+
return handoff
|
|
828
|
+
elif resume_ticket_module is not None:
|
|
829
|
+
# A GUI host leaves the ticket on disk while it reloads the
|
|
830
|
+
# workspace. On re-entry the fast path has no new ticket;
|
|
831
|
+
# consume the old one only after every startup gate passed.
|
|
832
|
+
resume_ticket_module.consume_resume_ticket(project_root)
|
|
833
|
+
diag_ctx = diagnostic_context()
|
|
834
|
+
cmd_started = time.monotonic()
|
|
835
|
+
if cmd == "post":
|
|
836
|
+
_emit_post_attempt_event("core_command_started")
|
|
837
|
+
elif logger is not None:
|
|
838
|
+
bugx_logging.log_event(
|
|
839
|
+
logger, "core_command_started", command=cmd,
|
|
840
|
+
**diag_ctx,
|
|
841
|
+
)
|
|
842
|
+
try:
|
|
843
|
+
result: int
|
|
844
|
+
if cmd == "post":
|
|
845
|
+
_share = "share" if "--share" in argv[2:] else (
|
|
846
|
+
"no-share" if "--no-share" in argv[2:] else None)
|
|
847
|
+
post_started = time.monotonic()
|
|
848
|
+
phase_status = "failed"
|
|
849
|
+
try:
|
|
850
|
+
from core.launch_phases.post_observability import current_attempt
|
|
851
|
+
attempt = current_attempt()
|
|
852
|
+
with bugx_logging.timed_phase(
|
|
853
|
+
logger, "post_settlement", post_event_schema=1,
|
|
854
|
+
post_attempt_id=(attempt.post_attempt_id if attempt else None),
|
|
855
|
+
) as tracker:
|
|
856
|
+
try:
|
|
857
|
+
result = post(
|
|
858
|
+
final="--final" in argv[2:], share=_share,
|
|
859
|
+
allow_incomplete="--allow-incomplete" in argv[2:],
|
|
860
|
+
allow_serial="--allow-serial" in argv[2:],
|
|
861
|
+
_post_attempt_token=_post_attempt_token,
|
|
862
|
+
)
|
|
863
|
+
phase_status = "ok" if result == 0 else "failed"
|
|
864
|
+
if result != 0:
|
|
865
|
+
tracker.mark_failed(
|
|
866
|
+
get_last_post_failure() or "post_return_nonzero",
|
|
867
|
+
)
|
|
868
|
+
except BaseException:
|
|
869
|
+
tracker.mark_failed(
|
|
870
|
+
get_last_post_failure() or "post_exception",
|
|
871
|
+
)
|
|
872
|
+
raise
|
|
873
|
+
finally:
|
|
874
|
+
phase_duration = max(0.0, time.monotonic() - post_started)
|
|
875
|
+
_emit_post_attempt_event(
|
|
876
|
+
"phase.post_settlement.finished",
|
|
877
|
+
level=20 if phase_status == "ok" else 40,
|
|
878
|
+
phase="post_settlement", status=phase_status,
|
|
879
|
+
duration_seconds=round(phase_duration, 3),
|
|
880
|
+
)
|
|
881
|
+
threshold = bugx_logging.DEFAULT_SLOW_THRESHOLD_SECONDS
|
|
882
|
+
configured_threshold = os.environ.get("BUGX_SLOW_THRESHOLD_SECONDS")
|
|
883
|
+
if configured_threshold:
|
|
884
|
+
try:
|
|
885
|
+
threshold = float(configured_threshold)
|
|
886
|
+
except ValueError:
|
|
887
|
+
pass
|
|
888
|
+
if threshold > 0 and phase_duration >= threshold:
|
|
889
|
+
_emit_post_attempt_event(
|
|
890
|
+
"slow_operation_warning", level=30,
|
|
891
|
+
phase="post_settlement", status=phase_status,
|
|
892
|
+
duration_seconds=round(phase_duration, 3),
|
|
893
|
+
)
|
|
894
|
+
elif cmd == "status":
|
|
895
|
+
result = status(as_json="--json" in argv[2:])
|
|
896
|
+
elif cmd == "polling":
|
|
897
|
+
value = argv[2] if len(argv) > 2 else None
|
|
898
|
+
result = polling(value)
|
|
899
|
+
elif cmd == "heartbeat":
|
|
900
|
+
result = heartbeat()
|
|
901
|
+
elif cmd == "pause":
|
|
902
|
+
result = pause()
|
|
903
|
+
elif cmd == "resume":
|
|
904
|
+
result = resume()
|
|
905
|
+
elif cmd == "abort":
|
|
906
|
+
result = abort(_option_value(argv[2:], "--reason"))
|
|
907
|
+
elif cmd == "bootstrap-coverage":
|
|
908
|
+
result = bootstrap_coverage(
|
|
909
|
+
confirmed="--confirm" in argv[2:],
|
|
910
|
+
fresh_coverage="--fresh-coverage" in argv[2:],
|
|
911
|
+
)
|
|
912
|
+
elif cmd in {"pre", "audit"}:
|
|
913
|
+
# `--allow-degraded` 已在 `_main_impl` 入口统一拒绝(A4),此处不再重复判定。
|
|
914
|
+
pre_args = argv[2:]
|
|
915
|
+
is_dev = dev_mode_requested
|
|
916
|
+
strategy_plan_val = None
|
|
917
|
+
if "--approve-strategy" in pre_args or is_dev:
|
|
918
|
+
strategy_plan_val = "approve"
|
|
919
|
+
else:
|
|
920
|
+
strategy_plan_val = _option_value(pre_args, "--strategy-plan")
|
|
921
|
+
tooling_choices: dict[str, str] = {}
|
|
922
|
+
for i, arg in enumerate(pre_args):
|
|
923
|
+
if arg == "--tooling-choice" and i + 1 < len(pre_args):
|
|
924
|
+
val = pre_args[i + 1]
|
|
925
|
+
if "=" in val:
|
|
926
|
+
t, a = val.split("=", 1)
|
|
927
|
+
tooling_choices[t.strip()] = a.strip()
|
|
928
|
+
elif arg.startswith("--tooling-choice="):
|
|
929
|
+
val = arg.split("=", 1)[1]
|
|
930
|
+
if "=" in val:
|
|
931
|
+
t, a = val.split("=", 1)
|
|
932
|
+
tooling_choices[t.strip()] = a.strip()
|
|
933
|
+
with bugx_logging.timed_phase(logger, "pre_flight_gates"):
|
|
934
|
+
result = pre(
|
|
935
|
+
_option_value(pre_args, "--polling") or ("auto" if is_dev else None),
|
|
936
|
+
allow_serial="--allow-serial" in pre_args,
|
|
937
|
+
serial_reason=_option_value(pre_args, "--serial-reason"),
|
|
938
|
+
lesson_query=_option_value(pre_args, "--lesson-query") or "",
|
|
939
|
+
lesson_category=_option_value(pre_args, "--lesson-category"),
|
|
940
|
+
review_mode=_option_value(pre_args, "--review-mode") or ("mcp-auto" if is_dev else None),
|
|
941
|
+
fix_mode=_option_value(pre_args, "--fix-mode") or ("auto" if is_dev else None),
|
|
942
|
+
life_kind=_option_value(pre_args, "--life-kind") or "mine",
|
|
943
|
+
commit_policy=_option_value(pre_args, "--commit-policy") or ("round" if is_dev else None),
|
|
944
|
+
session_recovery=_option_value(pre_args, "--session-recovery") or ("resume" if is_dev else None),
|
|
945
|
+
startup_action=_option_value(pre_args, "--startup-action") or ("start" if is_dev else None),
|
|
946
|
+
strategy_plan=strategy_plan_val,
|
|
947
|
+
tooling_choices=tooling_choices or None,
|
|
948
|
+
report_policy=_option_value(pre_args, "--report-policy"),
|
|
949
|
+
replay_share_pending_force="--replay-share-pending" in pre_args,
|
|
950
|
+
startup_interaction=_option_value(pre_args, "--startup-interaction"),
|
|
951
|
+
bootstrap_coverage="--bootstrap-coverage" in pre_args,
|
|
952
|
+
profile=_option_value(pre_args, "--profile"),
|
|
953
|
+
ignore_global_budget="--ignore-global-budget" in pre_args,
|
|
954
|
+
refresh_probes="--refresh-probes" in pre_args,
|
|
955
|
+
autonomous="--autonomous" in pre_args or is_dev,
|
|
956
|
+
max_round_wall_seconds=_option_value(
|
|
957
|
+
pre_args, "--max-round-wall-seconds",
|
|
958
|
+
),
|
|
959
|
+
host=_option_value(pre_args, "--host"),
|
|
960
|
+
)
|
|
961
|
+
elif cmd == "control":
|
|
962
|
+
sub = argv[2] if len(argv) > 2 else "status"
|
|
963
|
+
if sub == "pause":
|
|
964
|
+
result = pause()
|
|
965
|
+
elif sub == "resume":
|
|
966
|
+
result = resume()
|
|
967
|
+
elif sub == "abort":
|
|
968
|
+
result = abort(_option_value(argv[3:], "--reason"))
|
|
969
|
+
else:
|
|
970
|
+
result = status(as_json="--json" in argv[2:])
|
|
971
|
+
elif cmd == "findings-confirm":
|
|
972
|
+
from core.launch_phases import finding_confirm_phase
|
|
973
|
+
result = finding_confirm_phase.main(argv[2:])
|
|
974
|
+
elif cmd == "judge":
|
|
975
|
+
from core.launch_phases import judge_phase
|
|
976
|
+
result = judge_phase.main(argv[2:])
|
|
977
|
+
elif cmd == "coverage":
|
|
978
|
+
# F-RSI-20261110-020:coverage_cli 此前是孤儿模块——
|
|
979
|
+
# AI_REFERENCE §六·五 记载的 `bugx engine coverage
|
|
980
|
+
# review-packages/review-apply` 无任何接线(顶层/engine 均不可达)。
|
|
981
|
+
from core.coverage import coverage_cli
|
|
982
|
+
result = coverage_cli.main(argv[2:])
|
|
983
|
+
elif cmd == "workers":
|
|
984
|
+
raw_count = _option_value(argv[2:], "--count")
|
|
985
|
+
strategy = _option_value(argv[2:], "--strategy") or "risk"
|
|
986
|
+
execute = "--execute" in argv[2:]
|
|
987
|
+
dry_run = "--dry-run" in argv[2:]
|
|
988
|
+
brief = "--brief" in argv[2:]
|
|
989
|
+
provider_arg = _option_value(argv[2:], "--provider")
|
|
990
|
+
model_arg = _option_value(argv[2:], "--model")
|
|
991
|
+
executable_arg = _option_value(argv[2:], "--executable")
|
|
992
|
+
host_arg = _option_value(argv[2:], "--host")
|
|
993
|
+
subagent_type_arg = _option_value(argv[2:], "--subagent-type")
|
|
994
|
+
max_workers_raw = _option_value(argv[2:], "--max-workers")
|
|
995
|
+
stagger_raw = _option_value(argv[2:], "--stagger-seconds")
|
|
996
|
+
try:
|
|
997
|
+
parsed_count = int(raw_count) if raw_count else None
|
|
998
|
+
except ValueError:
|
|
999
|
+
parsed_count = None
|
|
1000
|
+
try:
|
|
1001
|
+
parsed_max_workers = int(max_workers_raw) if max_workers_raw else None
|
|
1002
|
+
except ValueError:
|
|
1003
|
+
parsed_max_workers = None
|
|
1004
|
+
try:
|
|
1005
|
+
parsed_stagger = float(stagger_raw) if stagger_raw else None
|
|
1006
|
+
except ValueError:
|
|
1007
|
+
parsed_stagger = None
|
|
1008
|
+
with bugx_logging.timed_phase(logger, "worker_execution", worker_count=parsed_count):
|
|
1009
|
+
result = workers(
|
|
1010
|
+
parsed_count,
|
|
1011
|
+
strategy=strategy,
|
|
1012
|
+
execute=execute,
|
|
1013
|
+
host=host_arg,
|
|
1014
|
+
max_workers=parsed_max_workers,
|
|
1015
|
+
subagent_type=subagent_type_arg,
|
|
1016
|
+
stagger_seconds=parsed_stagger,
|
|
1017
|
+
model=model_arg,
|
|
1018
|
+
provider=provider_arg,
|
|
1019
|
+
executable=executable_arg,
|
|
1020
|
+
dry_run=dry_run,
|
|
1021
|
+
brief=brief,
|
|
1022
|
+
)
|
|
1023
|
+
elif cmd == "fix-review":
|
|
1024
|
+
result = fix_review(argv[2:])
|
|
1025
|
+
elif cmd == "revalidate-candidates":
|
|
1026
|
+
result = revalidate_candidates(argv[2:])
|
|
1027
|
+
elif cmd == "prompt":
|
|
1028
|
+
stage_val = _option_value(argv[2:], "--stage")
|
|
1029
|
+
result = cmd_prompt(stage_val)
|
|
1030
|
+
elif cmd == "daemon":
|
|
1031
|
+
from core.runtime import daemon_runner
|
|
1032
|
+
result = daemon_runner.main(argv[2:])
|
|
1033
|
+
else:
|
|
1034
|
+
print(
|
|
1035
|
+
f"[launch_bugx] 未知命令: {cmd}"
|
|
1036
|
+
"(可选 pre/post/status/polling/heartbeat/pause/resume/abort/"
|
|
1037
|
+
"bootstrap-coverage/fix-review/revalidate-candidates/audit/control/workers/prompt/daemon)"
|
|
1038
|
+
)
|
|
1039
|
+
result = 2
|
|
1040
|
+
except BudgetExhausted as exc:
|
|
1041
|
+
cmd_duration = round(max(0.0, time.monotonic() - cmd_started), 3)
|
|
1042
|
+
if cmd == "post":
|
|
1043
|
+
try:
|
|
1044
|
+
from core.launch_phases.post_observability import (
|
|
1045
|
+
current_attempt, record_unhandled_exception,
|
|
1046
|
+
)
|
|
1047
|
+
active = current_attempt()
|
|
1048
|
+
if active is not None and not active.failure_recorded:
|
|
1049
|
+
record_unhandled_exception(exc, exit_code=1)
|
|
1050
|
+
except Exception:
|
|
1051
|
+
pass
|
|
1052
|
+
_emit_post_attempt_event(
|
|
1053
|
+
"core_command_finished", level=40,
|
|
1054
|
+
exit_code=1, status="failed", duration_seconds=cmd_duration,
|
|
1055
|
+
)
|
|
1056
|
+
elif logger is not None:
|
|
1057
|
+
bugx_logging.log_event(
|
|
1058
|
+
logger, "budget_exhausted", str(exc), level=40,
|
|
1059
|
+
command=cmd, exception_type=type(exc).__name__,
|
|
1060
|
+
duration_seconds=cmd_duration,
|
|
1061
|
+
**diag_ctx,
|
|
1062
|
+
)
|
|
1063
|
+
print(json.dumps({
|
|
1064
|
+
"status": "BUDGET_EXHAUSTED",
|
|
1065
|
+
"error_type": type(exc).__name__,
|
|
1066
|
+
"reason": str(exc),
|
|
1067
|
+
"recovery": [
|
|
1068
|
+
"读取 bugx engine --root . status 确认 budget_reasons",
|
|
1069
|
+
"必要时执行 audit_supervisor.py reset-budget --force 开启新的预算 epoch",
|
|
1070
|
+
],
|
|
1071
|
+
}, ensure_ascii=False))
|
|
1072
|
+
return 1
|
|
1073
|
+
except Exception as exc: # pragma: no cover - exercised by integration failures.
|
|
1074
|
+
cmd_duration = round(max(0.0, time.monotonic() - cmd_started), 3)
|
|
1075
|
+
if cmd == "post":
|
|
1076
|
+
try:
|
|
1077
|
+
from core.launch_phases.post_observability import (
|
|
1078
|
+
current_attempt, record_unhandled_exception,
|
|
1079
|
+
)
|
|
1080
|
+
active = current_attempt()
|
|
1081
|
+
if active is not None and not active.failure_recorded:
|
|
1082
|
+
record_unhandled_exception(exc, exit_code=1)
|
|
1083
|
+
except Exception:
|
|
1084
|
+
pass
|
|
1085
|
+
_emit_post_attempt_event(
|
|
1086
|
+
"core_command_finished", level=40,
|
|
1087
|
+
exit_code=1, status="failed", duration_seconds=cmd_duration,
|
|
1088
|
+
)
|
|
1089
|
+
elif logger is not None:
|
|
1090
|
+
bugx_logging.log_event(
|
|
1091
|
+
logger, "core_command_crashed", str(exc), level=40,
|
|
1092
|
+
command=cmd, exception_type=type(exc).__name__,
|
|
1093
|
+
duration_seconds=cmd_duration,
|
|
1094
|
+
**diag_ctx, exc_info=True,
|
|
1095
|
+
)
|
|
1096
|
+
err = f"[launch_bugx] ✗ 未处理异常: {type(exc).__name__}: {exc}"
|
|
1097
|
+
if i18n is not None:
|
|
1098
|
+
err = i18n.exception_text("orchestrator.unhandled", fallback=err, exc_type=type(exc).__name__, exc=exc)
|
|
1099
|
+
print(err)
|
|
1100
|
+
return 1
|
|
1101
|
+
|
|
1102
|
+
cmd_duration = round(max(0.0, time.monotonic() - cmd_started), 3)
|
|
1103
|
+
if cmd == "post":
|
|
1104
|
+
_emit_post_attempt_event(
|
|
1105
|
+
"core_command_finished", level=40 if result != 0 else 20,
|
|
1106
|
+
exit_code=result,
|
|
1107
|
+
status="failed" if result != 0 else "ok",
|
|
1108
|
+
duration_seconds=cmd_duration,
|
|
1109
|
+
)
|
|
1110
|
+
elif logger is not None:
|
|
1111
|
+
if cmd in {"pre", "audit"} and result != 0 and bugx_logging is not None:
|
|
1112
|
+
bugx_logging.log_event(
|
|
1113
|
+
logger, "pre_failed", "pre 门禁失败;已记录最近失败详情",
|
|
1114
|
+
level=40, exit_code=result,
|
|
1115
|
+
duration_seconds=cmd_duration,
|
|
1116
|
+
failure_detail=get_last_child_failure() or "pre 返回非零,但未产生子命令输出",
|
|
1117
|
+
)
|
|
1118
|
+
if result != 0:
|
|
1119
|
+
err_detail = (get_last_post_failure() if cmd == "post" else "") or (get_last_child_failure() if cmd in {"pre", "audit"} else "")
|
|
1120
|
+
err_msg = f"{cmd} 命令执行失败 (exit_code={result})" + (f": {err_detail}" if err_detail else "")
|
|
1121
|
+
bugx_logging.log_event(
|
|
1122
|
+
logger, "core_command_finished", err_msg,
|
|
1123
|
+
level=40, command=cmd, exit_code=result,
|
|
1124
|
+
duration_seconds=cmd_duration,
|
|
1125
|
+
error=err_detail or f"exit_code={result}",
|
|
1126
|
+
**diag_ctx,
|
|
1127
|
+
)
|
|
1128
|
+
else:
|
|
1129
|
+
bugx_logging.log_event(
|
|
1130
|
+
logger, "core_command_finished", command=cmd,
|
|
1131
|
+
exit_code=result, duration_seconds=cmd_duration, **diag_ctx,
|
|
1132
|
+
)
|
|
1133
|
+
return result
|