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,873 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""launch_phases/startup_version_gate.py - 启动版本一致性门禁与远端更新检查。"""
|
|
3
|
+
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
import datetime as dt
|
|
7
|
+
import functools
|
|
8
|
+
import json
|
|
9
|
+
import os
|
|
10
|
+
import re
|
|
11
|
+
import sys
|
|
12
|
+
import threading
|
|
13
|
+
import time
|
|
14
|
+
from pathlib import Path
|
|
15
|
+
from typing import Any
|
|
16
|
+
|
|
17
|
+
from core.launch_phases.common import (
|
|
18
|
+
AGENT_DIR,
|
|
19
|
+
HOST_DISPLAY_NAMES,
|
|
20
|
+
ISOLATED_REMOTE_VERSION_RESULT,
|
|
21
|
+
resolve_project_root,
|
|
22
|
+
uses_project_layout,
|
|
23
|
+
child_environment,
|
|
24
|
+
run_child,
|
|
25
|
+
POLLING_DECISION_REQUIRED,
|
|
26
|
+
bugx_paths,
|
|
27
|
+
bugx_logging,
|
|
28
|
+
)
|
|
29
|
+
import shutil
|
|
30
|
+
import subprocess
|
|
31
|
+
import core.secure_atomic as secure_atomic
|
|
32
|
+
from core.launch_phases.session_runtime import (
|
|
33
|
+
iso_time,
|
|
34
|
+
load_runtime,
|
|
35
|
+
save_runtime,
|
|
36
|
+
append_runtime_event,
|
|
37
|
+
runtime_lock,
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
from core.launch_phases.common import resolve_project_root as _orig_resolve_project_root
|
|
44
|
+
from core.launch_phases.session_runtime import load_runtime as _orig_load_runtime, save_runtime as _orig_save_runtime
|
|
45
|
+
|
|
46
|
+
def _sg():
|
|
47
|
+
"""已加载的 ``startup_gates`` 模块(点分名优先,扁平名仅为归档布局兼容)。"""
|
|
48
|
+
return (sys.modules.get("core.launch_phases.startup_gates")
|
|
49
|
+
or sys.modules.get("launch_phases.startup_gates"))
|
|
50
|
+
|
|
51
|
+
def _sg_dispatch(name, fallback_fn=None):
|
|
52
|
+
def wrapper(*args, **kwargs):
|
|
53
|
+
sg = _sg()
|
|
54
|
+
if sg is not None and hasattr(sg, name):
|
|
55
|
+
target = getattr(sg, name)
|
|
56
|
+
if target is not wrapper:
|
|
57
|
+
return target(*args, **kwargs)
|
|
58
|
+
if fallback_fn is not None:
|
|
59
|
+
return fallback_fn(*args, **kwargs)
|
|
60
|
+
raise RuntimeError(f"{name} not available and no fallback provided")
|
|
61
|
+
wrapper.__name__ = name
|
|
62
|
+
return wrapper
|
|
63
|
+
|
|
64
|
+
def _orig_maybe_onboard(*args, **kwargs):
|
|
65
|
+
try:
|
|
66
|
+
from core.cloud_sync.onboard_wizard import maybe_onboard as fn
|
|
67
|
+
return fn(*args, **kwargs)
|
|
68
|
+
except Exception:
|
|
69
|
+
return None
|
|
70
|
+
|
|
71
|
+
def _orig_get_state(*args, **kwargs):
|
|
72
|
+
try:
|
|
73
|
+
from core.cloud_sync.cloud_onboard import get_state as fn
|
|
74
|
+
return fn(*args, **kwargs)
|
|
75
|
+
except Exception:
|
|
76
|
+
return None
|
|
77
|
+
|
|
78
|
+
def _orig_set_state(*args, **kwargs):
|
|
79
|
+
try:
|
|
80
|
+
from core.cloud_sync.cloud_onboard import set_state as fn
|
|
81
|
+
return fn(*args, **kwargs)
|
|
82
|
+
except Exception:
|
|
83
|
+
return None
|
|
84
|
+
|
|
85
|
+
def _orig_sync_layers(*args, **kwargs):
|
|
86
|
+
try:
|
|
87
|
+
from core.cloud_sync.cloud_onboard import sync_layers as fn
|
|
88
|
+
return fn(*args, **kwargs)
|
|
89
|
+
except Exception:
|
|
90
|
+
return None
|
|
91
|
+
|
|
92
|
+
def _orig_uses_project_layout(*args, **kwargs):
|
|
93
|
+
from core.launch_phases.common import uses_project_layout as fn
|
|
94
|
+
return fn(*args, **kwargs)
|
|
95
|
+
|
|
96
|
+
resolve_project_root = _sg_dispatch("resolve_project_root", _orig_resolve_project_root)
|
|
97
|
+
uses_project_layout = _sg_dispatch("uses_project_layout", _orig_uses_project_layout)
|
|
98
|
+
maybe_onboard = _sg_dispatch("maybe_onboard", _orig_maybe_onboard)
|
|
99
|
+
get_state = _sg_dispatch("get_state", _orig_get_state)
|
|
100
|
+
set_state = _sg_dispatch("set_state", _orig_set_state)
|
|
101
|
+
sync_layers = _sg_dispatch("sync_layers", _orig_sync_layers)
|
|
102
|
+
load_runtime = _sg_dispatch("load_runtime", _orig_load_runtime)
|
|
103
|
+
save_runtime = _sg_dispatch("save_runtime", _orig_save_runtime)
|
|
104
|
+
|
|
105
|
+
class _CloudClientDispatcher:
|
|
106
|
+
def __call__(self, *args, **kwargs):
|
|
107
|
+
sg = _sg()
|
|
108
|
+
cls = getattr(sg, "CloudClient", None) if sg else None
|
|
109
|
+
if cls is not None:
|
|
110
|
+
return cls(*args, **kwargs)
|
|
111
|
+
from core.cloud_sync.cloud_client import CloudClient as real_cls
|
|
112
|
+
return real_cls(*args, **kwargs)
|
|
113
|
+
def __getattr__(self, name):
|
|
114
|
+
sg = _sg()
|
|
115
|
+
cls = getattr(sg, "CloudClient", None) if sg else None
|
|
116
|
+
if cls is not None:
|
|
117
|
+
return getattr(cls, name)
|
|
118
|
+
from core.cloud_sync.cloud_client import CloudClient as real_cls
|
|
119
|
+
return getattr(real_cls, name)
|
|
120
|
+
|
|
121
|
+
CloudClient = _CloudClientDispatcher()
|
|
122
|
+
|
|
123
|
+
FATAL_BLOCKED_BANNER = (
|
|
124
|
+
"\n[FATAL_BLOCKED] 阻断已确凿,严禁模型自行连续重试或发散自旋推理。\n"
|
|
125
|
+
"【强制停机指示】请立即停止调用工具,直接向用户呈现上述阻断原因与修复建议。\n"
|
|
126
|
+
)
|
|
127
|
+
|
|
128
|
+
def _si():
|
|
129
|
+
"""已加载的 ``startup_interaction`` 模块(同上)。"""
|
|
130
|
+
return (sys.modules.get("core.launch_phases.startup_interaction")
|
|
131
|
+
or sys.modules.get("launch_phases.startup_interaction"))
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def emit_startup_gate(*args, **kwargs):
|
|
136
|
+
mod = _sg()
|
|
137
|
+
if mod and hasattr(mod, "emit_startup_gate"):
|
|
138
|
+
return mod.emit_startup_gate(*args, **kwargs)
|
|
139
|
+
raise RuntimeError("startup_gates.emit_startup_gate not available")
|
|
140
|
+
|
|
141
|
+
def _stdin_tty():
|
|
142
|
+
mod = _sg() or _si()
|
|
143
|
+
if mod and hasattr(mod, "stdin_tty"):
|
|
144
|
+
return mod.stdin_tty()
|
|
145
|
+
if mod and hasattr(mod, "_stdin_tty"):
|
|
146
|
+
return mod._stdin_tty()
|
|
147
|
+
try:
|
|
148
|
+
return bool(sys.stdin.isatty())
|
|
149
|
+
except Exception:
|
|
150
|
+
return False
|
|
151
|
+
|
|
152
|
+
def _tty_menu_available():
|
|
153
|
+
mod = _sg() or _si()
|
|
154
|
+
if mod and hasattr(mod, "tty_menu_available"):
|
|
155
|
+
return mod.tty_menu_available()
|
|
156
|
+
if mod and hasattr(mod, "_tty_menu_available"):
|
|
157
|
+
return mod._tty_menu_available()
|
|
158
|
+
return False
|
|
159
|
+
|
|
160
|
+
def detect_startup_environment():
|
|
161
|
+
mod = _sg()
|
|
162
|
+
if mod and hasattr(mod, "detect_startup_environment"):
|
|
163
|
+
return mod.detect_startup_environment()
|
|
164
|
+
return "terminal"
|
|
165
|
+
|
|
166
|
+
def normalize_cli_version(value: str) -> str | None:
|
|
167
|
+
"""Normalize a BugX/Python version to the compatibility contract version.
|
|
168
|
+
|
|
169
|
+
委托 :func:`bugx_paths.contract_version`(唯一实现)。历史缺陷:此处曾把
|
|
170
|
+
``+build`` 保留在 base 组里,于是 ``1.0.0+2`` 与 ``1.0.0`` 被判为不一致并
|
|
171
|
+
**拒绝启动**,而 ``bugx doctor`` 用另一套规则判为"一致"——同一份清单、两个
|
|
172
|
+
相反结论。归一化规则只能有一处,否则两边必然再次漂移。
|
|
173
|
+
"""
|
|
174
|
+
return bugx_paths.contract_version(value)
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
def installed_cli_version(root: Path) -> str | None:
|
|
178
|
+
"""Read the CLI version without letting an old PATH wrapper win.
|
|
179
|
+
|
|
180
|
+
Scheme 3 has one executable runtime: the global engine. When a launcher
|
|
181
|
+
is executed directly from that engine (for example via ``bugx engine path``)
|
|
182
|
+
there may be no CLI wrapper process to report its version, and probing an
|
|
183
|
+
unrelated ``bugx`` found on PATH can reintroduce the very drift this layout
|
|
184
|
+
removes. An explicit ``BUGX_CLI_VERSION`` still wins because the wrapper
|
|
185
|
+
uses it to prove that its own version matches the engine. Direct global
|
|
186
|
+
launcher execution falls back to the engine's own marker; source-tree
|
|
187
|
+
launchers keep the historical PATH probe for compatibility and tests.
|
|
188
|
+
"""
|
|
189
|
+
override = os.environ.get("BUGX_CLI_VERSION")
|
|
190
|
+
if override:
|
|
191
|
+
normalized = _normalize_cli_version(override)
|
|
192
|
+
if normalized:
|
|
193
|
+
return normalized
|
|
194
|
+
try:
|
|
195
|
+
runtime_root = Path(__file__).resolve().parent.parent
|
|
196
|
+
engine_root = _global_engine_root().resolve()
|
|
197
|
+
if runtime_root == engine_root:
|
|
198
|
+
engine_version = version_marker(engine_root / "metadata.txt")
|
|
199
|
+
if engine_version is None:
|
|
200
|
+
engine_version = version_marker(engine_root / "bugx.md")
|
|
201
|
+
if engine_version:
|
|
202
|
+
return engine_version
|
|
203
|
+
except (OSError, ValueError, RuntimeError):
|
|
204
|
+
pass
|
|
205
|
+
executable = shutil.which("bugx")
|
|
206
|
+
if not executable:
|
|
207
|
+
return None
|
|
208
|
+
try:
|
|
209
|
+
result = subprocess.run(
|
|
210
|
+
[executable, "--version"], cwd=root, capture_output=True,
|
|
211
|
+
text=True, check=False, timeout=5,
|
|
212
|
+
)
|
|
213
|
+
except (OSError, subprocess.TimeoutExpired):
|
|
214
|
+
return None
|
|
215
|
+
match = re.search(
|
|
216
|
+
r"\bbugx(?:\s+cli)?(?:\s+version)?\s+v?"
|
|
217
|
+
r"(?P<base>\d+\.\d+\.\d+(?:\+[0-9A-Za-z.-]+)?)"
|
|
218
|
+
r"(?:[-.]?(?:alpha|a|beta|b|rc)[-.]?\d+)?\b",
|
|
219
|
+
result.stdout or "",
|
|
220
|
+
re.IGNORECASE,
|
|
221
|
+
)
|
|
222
|
+
return match.group("base") if result.returncode == 0 and match else None
|
|
223
|
+
|
|
224
|
+
def global_engine_root() -> Path:
|
|
225
|
+
return bugx_paths.global_engine_root()
|
|
226
|
+
|
|
227
|
+
_global_engine_root = _sg_dispatch("_global_engine_root", global_engine_root)
|
|
228
|
+
|
|
229
|
+
def version_marker(path: Path) -> str | None:
|
|
230
|
+
"""Read a human-readable BugX version marker without failing startup."""
|
|
231
|
+
try:
|
|
232
|
+
text = path.read_text(encoding="utf-8")
|
|
233
|
+
except (OSError, UnicodeError):
|
|
234
|
+
return None
|
|
235
|
+
match = re.search(
|
|
236
|
+
r"(?:bugx_version[\"']?\s*:\s*[\"']?|^version:\s*)"
|
|
237
|
+
r"([0-9]+\.[0-9]+\.[0-9]+(?:\+[0-9A-Za-z.-]+)?)", text, re.MULTILINE,
|
|
238
|
+
)
|
|
239
|
+
return match.group(1) if match else None
|
|
240
|
+
|
|
241
|
+
def startup_release_version(value: object) -> tuple[int, int, int] | None:
|
|
242
|
+
"""Parse the strict x.y.z release format used by the update endpoint."""
|
|
243
|
+
if not isinstance(value, str):
|
|
244
|
+
return None
|
|
245
|
+
value = value.strip()
|
|
246
|
+
if not re.fullmatch(r"\d+\.\d+\.\d+", value):
|
|
247
|
+
return None
|
|
248
|
+
major, minor, patch = (int(part) for part in value.split("."))
|
|
249
|
+
return major, minor, patch
|
|
250
|
+
|
|
251
|
+
def startup_version_banner(*, stream=None) -> None:
|
|
252
|
+
"""Always show the Agent version before dispatching a launch command."""
|
|
253
|
+
stream = stream or sys.stdout
|
|
254
|
+
root = resolve_project_root()
|
|
255
|
+
engine = _global_engine_root()
|
|
256
|
+
engine_version = version_marker(engine / "metadata.txt")
|
|
257
|
+
if engine_version is None:
|
|
258
|
+
engine_version = version_marker(engine / "bugx.md")
|
|
259
|
+
# The project manifest records layout/installation state; executable code
|
|
260
|
+
# has one version source: the global engine.
|
|
261
|
+
project_version = version_marker(root / ".bugx" / "manifest.json")
|
|
262
|
+
cli_version = _installed_cli_version(root)
|
|
263
|
+
display = engine_version or project_version or cli_version or "unknown"
|
|
264
|
+
print(f"[BugX] Agent version: {display}", file=stream)
|
|
265
|
+
print(
|
|
266
|
+
"[BugX] Version contract: "
|
|
267
|
+
f"cli={cli_version or 'unknown'} "
|
|
268
|
+
f"project_manifest={project_version or 'unknown'} "
|
|
269
|
+
f"engine={engine_version or 'unknown'}",
|
|
270
|
+
file=stream,
|
|
271
|
+
)
|
|
272
|
+
|
|
273
|
+
def startup_cloud_onboarding(
|
|
274
|
+
cloud_sync_policy: str | None = None, *, autonomous: bool = False,
|
|
275
|
+
) -> int:
|
|
276
|
+
"""取得云端同步决定,并在经验上下文构建前完成一次正式同步。"""
|
|
277
|
+
if not uses_project_layout():
|
|
278
|
+
return 0
|
|
279
|
+
try:
|
|
280
|
+
from core.cloud_sync.cloud_onboard import get_state, set_state
|
|
281
|
+
state = get_state(resolve_project_root())
|
|
282
|
+
policy = cloud_sync_policy
|
|
283
|
+
if autonomous and policy is None and state == "pending":
|
|
284
|
+
# An undecided project is not consent to upload. Headless startup
|
|
285
|
+
# defaults only this pending state to local; persisted or explicit
|
|
286
|
+
# sync choices remain authoritative below.
|
|
287
|
+
policy = "local"
|
|
288
|
+
if policy in {"skip", "local"} and state == "pending":
|
|
289
|
+
# Profile 只补齐未决状态;已由用户选择的 done/local 不被覆盖。
|
|
290
|
+
set_state(resolve_project_root(), "local")
|
|
291
|
+
state = "local"
|
|
292
|
+
print("[launch_bugx] ✓ Profile 已选择本地云同步模式")
|
|
293
|
+
elif policy == "sync" or state in {"sync", "done"}:
|
|
294
|
+
# 云端同步模式:严禁擅自消极降级为 local!
|
|
295
|
+
# 未登录时必须直接跳转浏览器登录授权页面,授权完成后自动对齐并同步。
|
|
296
|
+
pass
|
|
297
|
+
elif state == "pending":
|
|
298
|
+
# 仅在调用方未显式指定云端策略、且当前处于完全无交互环境时,才临时以本地模式运行,避免无头 CI 挂起
|
|
299
|
+
if not _stdin_tty() and not _tty_menu_available():
|
|
300
|
+
try:
|
|
301
|
+
from core.cloud_sync.cloud_client import CloudClient
|
|
302
|
+
client = CloudClient()
|
|
303
|
+
is_auth = bool(client.cred.is_authenticated())
|
|
304
|
+
except Exception:
|
|
305
|
+
is_auth = False
|
|
306
|
+
if not is_auth:
|
|
307
|
+
set_state(resolve_project_root(), "local")
|
|
308
|
+
state = "local"
|
|
309
|
+
print("[launch_bugx] ✓ 无交互环境下未配置云端策略,已采用本地模式运行(不阻断启动)")
|
|
310
|
+
|
|
311
|
+
# 门禁重入去重(build 389):``pre`` 是无状态一次性进程,每道门禁应答后
|
|
312
|
+
# 都要重跑 pre,此前每次都全量推拉云同步(实测每轮 6 个网络往返、秒级开销×N)。
|
|
313
|
+
# 已 done/sync 且距本次启动上一次同步成功不足 900s 时直接复用结果;
|
|
314
|
+
# 显式 ``--cloud-sync sync`` 视为用户点名同步,不跳过。
|
|
315
|
+
marker_path = resolve_project_root() / ".bugx" / "state" / "cloud-sync-startup.json"
|
|
316
|
+
marker_age: float | None = None
|
|
317
|
+
if state in {"sync", "done"} and policy != "sync":
|
|
318
|
+
try:
|
|
319
|
+
marker_age = time.time() - float(
|
|
320
|
+
json.loads(marker_path.read_text(encoding="utf-8")).get("at") or 0.0
|
|
321
|
+
)
|
|
322
|
+
except (OSError, ValueError):
|
|
323
|
+
marker_age = None
|
|
324
|
+
if marker_age is not None and 0.0 <= marker_age <= 900.0:
|
|
325
|
+
print(
|
|
326
|
+
f"[launch_bugx] ✓ 门禁重入:{int(marker_age)} 秒前已完成本次启动云同步,"
|
|
327
|
+
"跳过重复推拉"
|
|
328
|
+
)
|
|
329
|
+
synced = True
|
|
330
|
+
else:
|
|
331
|
+
synced = maybe_onboard(
|
|
332
|
+
resolve_project_root(), require_interaction=not autonomous, perform_sync=True,
|
|
333
|
+
decision=("sync" if (policy == "sync" and state == "pending") else None),
|
|
334
|
+
allow_identity_create=autonomous,
|
|
335
|
+
)
|
|
336
|
+
if synced:
|
|
337
|
+
try:
|
|
338
|
+
marker_path.parent.mkdir(parents=True, exist_ok=True)
|
|
339
|
+
marker_path.write_text(
|
|
340
|
+
json.dumps({"at": time.time()}, ensure_ascii=False),
|
|
341
|
+
encoding="utf-8",
|
|
342
|
+
)
|
|
343
|
+
except (OSError, ValueError):
|
|
344
|
+
pass
|
|
345
|
+
state = get_state(resolve_project_root())
|
|
346
|
+
if state not in {"done", "local"}:
|
|
347
|
+
# ``sync`` = 用户**已显式选择**云端同步(`init --cloud-sync sync`),
|
|
348
|
+
# 但本轮同步没走到 ``done``(服务端/网络/身份失败)。此前它与
|
|
349
|
+
# 「从未选择」共用同一条「决策尚未完成」文案,导致用户被告知去做他
|
|
350
|
+
# 已经做过的事(build 288 实测)。两种情形必须分开报告。
|
|
351
|
+
if state == "sync":
|
|
352
|
+
reason = ""
|
|
353
|
+
try:
|
|
354
|
+
payload = json.loads(
|
|
355
|
+
(resolve_project_root() / ".bugx" / "cloud-last-error.json")
|
|
356
|
+
.read_text(encoding="utf-8")
|
|
357
|
+
)
|
|
358
|
+
reason = str(payload.get("error") or "")
|
|
359
|
+
except (OSError, ValueError):
|
|
360
|
+
reason = ""
|
|
361
|
+
print(
|
|
362
|
+
"[launch_bugx] ✗ 云端同步已获授权但本轮未完成;"
|
|
363
|
+
+ ("自治模式已 BLOCKED,不会等待交互。" if autonomous else "")
|
|
364
|
+
)
|
|
365
|
+
if reason == "data_sharing_revoked":
|
|
366
|
+
print(
|
|
367
|
+
" 原因:数据共享授权已被撤销(隐私门禁,不会绕过)。"
|
|
368
|
+
"如需云端同步请显式重新授权:"
|
|
369
|
+
"`bugx cloud config --root . --accept-data-sharing`;"
|
|
370
|
+
"本地开发可改用 `--cloud-sync local`。"
|
|
371
|
+
)
|
|
372
|
+
elif reason:
|
|
373
|
+
print(f" 原因:{reason};请检查 `bugx cloud status --root .`。")
|
|
374
|
+
else:
|
|
375
|
+
print(" 原因未记录;请检查 `bugx cloud status --root .` 后重试。")
|
|
376
|
+
return POLLING_DECISION_REQUIRED
|
|
377
|
+
print(
|
|
378
|
+
"[launch_bugx] ✗ 云端多设备同步决策尚未完成;"
|
|
379
|
+
+ ("自治模式已 BLOCKED,不会等待交互。" if autonomous else
|
|
380
|
+
"本轮不会进入审查方式、轮询策略或修复模式询问。")
|
|
381
|
+
)
|
|
382
|
+
print(" 请在当前云端菜单完成选择并成功登录/同步,或明确选择本地模式后重试。")
|
|
383
|
+
return POLLING_DECISION_REQUIRED
|
|
384
|
+
except Exception as exc:
|
|
385
|
+
# Import lazily so standalone protocol tests do not need cloud dependencies.
|
|
386
|
+
try:
|
|
387
|
+
from core.cloud_sync.cloud_onboard import CloudOnboardDecisionRequired
|
|
388
|
+
except Exception: # pragma: no cover - only malformed installations
|
|
389
|
+
CloudOnboardDecisionRequired = ()
|
|
390
|
+
if CloudOnboardDecisionRequired and isinstance(exc, CloudOnboardDecisionRequired):
|
|
391
|
+
if getattr(exc, "request_emitted", False):
|
|
392
|
+
if autonomous:
|
|
393
|
+
print("[launch_bugx] ✗ 自治模式需要云端登录/身份决策,已 BLOCKED,不等待交互。")
|
|
394
|
+
return POLLING_DECISION_REQUIRED
|
|
395
|
+
print("[launch_bugx] ✗ 云端同步/项目身份决策尚未完成;当前交互请求已交给宿主处理。")
|
|
396
|
+
return POLLING_DECISION_REQUIRED
|
|
397
|
+
if autonomous:
|
|
398
|
+
print("[launch_bugx] ✗ 自治模式需要云端登录/身份决策,已 BLOCKED,不发起交互。")
|
|
399
|
+
return POLLING_DECISION_REQUIRED
|
|
400
|
+
environment = detect_startup_environment()
|
|
401
|
+
print("[launch_bugx] ✗ 启动前需要云同步/登录决策。")
|
|
402
|
+
emit_startup_gate(
|
|
403
|
+
"cloud_sync",
|
|
404
|
+
"选择本项目的云端多设备同步模式",
|
|
405
|
+
[
|
|
406
|
+
{
|
|
407
|
+
"label": "立即登录并同步",
|
|
408
|
+
"description": "完成登录、设备登记并同步本项目",
|
|
409
|
+
"value": "sync",
|
|
410
|
+
"action": "cloud_sync_all",
|
|
411
|
+
},
|
|
412
|
+
{
|
|
413
|
+
"label": "本地模式",
|
|
414
|
+
"description": "持久化本地模式,不自动同步",
|
|
415
|
+
"value": "local",
|
|
416
|
+
"action": "set_cloud_local",
|
|
417
|
+
},
|
|
418
|
+
{
|
|
419
|
+
"label": "下次再说",
|
|
420
|
+
"description": "保持待决定并停止本轮启动",
|
|
421
|
+
"value": "later",
|
|
422
|
+
"action": "stop_startup",
|
|
423
|
+
},
|
|
424
|
+
],
|
|
425
|
+
environment=environment,
|
|
426
|
+
detail="选择后执行 bugx cloud sync 或 bugx cloud onboard off,再重新运行 pre",
|
|
427
|
+
)
|
|
428
|
+
try:
|
|
429
|
+
from core.cloud_sync.cloud_onboard import get_state
|
|
430
|
+
if get_state(resolve_project_root()) == "done":
|
|
431
|
+
print(f"[launch_bugx] ⚠ 云同步 onboarding 遇网络异常({exc}),自动降级为本地运行(不阻断启动)")
|
|
432
|
+
return 0
|
|
433
|
+
except Exception:
|
|
434
|
+
pass
|
|
435
|
+
print(f"[launch_bugx] ✗ 云同步 onboarding 检查失败:{exc}")
|
|
436
|
+
return 1
|
|
437
|
+
if state == "done" and not synced:
|
|
438
|
+
print(
|
|
439
|
+
"[launch_bugx] ⚠ 云端网络不可达或同步未完成,自动平滑降级为本地模式(已标记 sync_pending,不阻断启动)"
|
|
440
|
+
)
|
|
441
|
+
try:
|
|
442
|
+
from core.cloud_sync.auto_sync import schedule_recovery
|
|
443
|
+
for scope in ("global", "project"):
|
|
444
|
+
schedule_recovery(resolve_project_root(), scope)
|
|
445
|
+
except (ImportError, OSError, ValueError, RuntimeError):
|
|
446
|
+
pass
|
|
447
|
+
try:
|
|
448
|
+
with runtime_lock():
|
|
449
|
+
st = load_runtime()
|
|
450
|
+
st["sync_status"] = "sync_pending"
|
|
451
|
+
save_runtime(st)
|
|
452
|
+
except Exception:
|
|
453
|
+
pass
|
|
454
|
+
return 0
|
|
455
|
+
return 0
|
|
456
|
+
|
|
457
|
+
def run_cloud_boundary_sync(runtime: dict, scope: str) -> str:
|
|
458
|
+
"""在 Life/终局 Round 边界同步对应层,并把结果写回运行态。"""
|
|
459
|
+
if scope not in {"project", "global"}:
|
|
460
|
+
raise ValueError("同步边界只能是 project/global")
|
|
461
|
+
status = "local"
|
|
462
|
+
detail = "local mode"
|
|
463
|
+
consecutive_failures = int(runtime.get("cloud_sync_consecutive_failures") or 0)
|
|
464
|
+
# L5-OPT-4: 离线熔断断路器(连续失败达到 5 次以上转入休眠保护,消除每轮无意义子进程唤醒)
|
|
465
|
+
if consecutive_failures >= 5 and scope == "project":
|
|
466
|
+
status = "offline_dormant"
|
|
467
|
+
detail = f"连续 {consecutive_failures} 次网络同步失败,进入离线熔断保护(可运行 bugx cloud sync 重试)"
|
|
468
|
+
elif uses_project_layout():
|
|
469
|
+
try:
|
|
470
|
+
from core.cloud_sync.cloud_client import CloudClient
|
|
471
|
+
from core.cloud_sync.cloud_onboard import get_state, sync_layers
|
|
472
|
+
if get_state(resolve_project_root()) == "done":
|
|
473
|
+
summary = sync_layers(
|
|
474
|
+
CloudClient(), resolve_project_root(), scopes={scope},
|
|
475
|
+
)
|
|
476
|
+
status = "ready" if summary.get("ok") else "sync_pending"
|
|
477
|
+
detail = summary.get("error") or summary.get(f"{scope}_pull") or status
|
|
478
|
+
else:
|
|
479
|
+
detail = "cloud sync is not enabled"
|
|
480
|
+
except Exception as exc: # noqa: BLE001
|
|
481
|
+
status = "sync_pending"
|
|
482
|
+
detail = f"{type(exc).__name__}: {exc}"
|
|
483
|
+
if status == "ready":
|
|
484
|
+
consecutive_failures = 0
|
|
485
|
+
elif status == "sync_pending":
|
|
486
|
+
consecutive_failures += 1
|
|
487
|
+
try:
|
|
488
|
+
with runtime_lock():
|
|
489
|
+
state = load_runtime()
|
|
490
|
+
state["cloud_sync_consecutive_failures"] = consecutive_failures
|
|
491
|
+
boundaries = state.get("sync_boundaries")
|
|
492
|
+
if not isinstance(boundaries, dict):
|
|
493
|
+
boundaries = {}
|
|
494
|
+
boundaries[scope] = {
|
|
495
|
+
"status": status, "detail": str(detail),
|
|
496
|
+
"updated_at": iso_time(time.time()),
|
|
497
|
+
}
|
|
498
|
+
state["sync_boundaries"] = boundaries
|
|
499
|
+
statuses = [
|
|
500
|
+
item.get("status") for item in boundaries.values()
|
|
501
|
+
if isinstance(item, dict)
|
|
502
|
+
]
|
|
503
|
+
state["sync_status"] = (
|
|
504
|
+
"sync_pending" if "sync_pending" in statuses else
|
|
505
|
+
"ready" if "ready" in statuses else
|
|
506
|
+
"local"
|
|
507
|
+
)
|
|
508
|
+
append_runtime_event(
|
|
509
|
+
state, "cloud-boundary-sync", time.time(),
|
|
510
|
+
f"scope={scope} status={status}",
|
|
511
|
+
)
|
|
512
|
+
save_runtime(state)
|
|
513
|
+
except (OSError, ValueError):
|
|
514
|
+
print(f" ⚠ 无法写入 {scope} 云同步边界状态;后续启动将重新检查")
|
|
515
|
+
if status == "sync_pending":
|
|
516
|
+
print(f" ⚠ {scope} 边界同步未完成:已保留待重放状态({detail})")
|
|
517
|
+
try:
|
|
518
|
+
from core.cloud_sync.auto_sync import schedule_recovery
|
|
519
|
+
schedule_recovery(resolve_project_root(), scope)
|
|
520
|
+
except (ImportError, OSError, ValueError, RuntimeError):
|
|
521
|
+
pass
|
|
522
|
+
elif status == "offline_dormant":
|
|
523
|
+
print(f" ℹ {scope} 云端同步连续失败达到阈值,已转入离线静默状态(可通过 bugx cloud sync 手动重试)")
|
|
524
|
+
return status
|
|
525
|
+
|
|
526
|
+
def startup_version_gate() -> tuple[bool, str, str]:
|
|
527
|
+
"""Require CLI, project layout/manifest and global engine versions to agree."""
|
|
528
|
+
root = resolve_project_root()
|
|
529
|
+
cli_version = _installed_cli_version(root)
|
|
530
|
+
try:
|
|
531
|
+
status = bugx_paths.version_status(
|
|
532
|
+
root, _global_engine_root(), cli_version=cli_version,
|
|
533
|
+
)
|
|
534
|
+
except (OSError, ValueError, RuntimeError) as exc:
|
|
535
|
+
return False, f"版本清单无法读取:{exc}{FATAL_BLOCKED_BANNER}", "version_contract"
|
|
536
|
+
if status.get("consistent"):
|
|
537
|
+
return True, str(status.get("detail", "版本一致")), ""
|
|
538
|
+
versions = status.get("versions", {})
|
|
539
|
+
project_versions = status.get("legacy_versions")
|
|
540
|
+
project_integrity = status.get("project_core_integrity") or {}
|
|
541
|
+
layout_invalid = (
|
|
542
|
+
isinstance(project_versions, dict)
|
|
543
|
+
and "project_layout" in project_versions
|
|
544
|
+
and project_versions["project_layout"] != bugx_paths.LAYOUT_VERSION
|
|
545
|
+
) or (project_integrity.get("available") and not project_integrity.get("ok"))
|
|
546
|
+
if layout_invalid:
|
|
547
|
+
return False, (
|
|
548
|
+
f"项目 BugX 状态不完整或格式不受支持:{status.get('detail', '')};"
|
|
549
|
+
f"程序版本标记:{versions}。布局格式标记不是 BugX 程序版本;"
|
|
550
|
+
"已保留既有项目状态,请检查并恢复,不要直接重建或刷新全局引擎。"
|
|
551
|
+
f"{FATAL_BLOCKED_BANNER}"
|
|
552
|
+
), "project_layout"
|
|
553
|
+
return False, (
|
|
554
|
+
f"{status.get('detail', '版本标记不一致')};当前版本:{versions}。"
|
|
555
|
+
"本次启动不会自动重试;请检查实际不一致的程序版本或缺失的版本标记。"
|
|
556
|
+
"若仅是 CLI 版本识别失败,可临时设置 `BUGX_CLI_VERSION=X.Y.Z` 覆盖识别;"
|
|
557
|
+
"该覆盖不替代实际 CLI 升级,也不能掩盖项目/引擎版本漂移。"
|
|
558
|
+
f"{FATAL_BLOCKED_BANNER}"
|
|
559
|
+
), "version_contract"
|
|
560
|
+
|
|
561
|
+
# PERF-07:远端版本检查的硬超时与后台线程状态。
|
|
562
|
+
# 单次请求 timeout 压到 1 秒且不重试;此设置不是 DNS/配置读取的总墙钟保证。
|
|
563
|
+
# CLI 仍由后台线程检查;进程内 harness 必须在恢复全局环境前完成检查。
|
|
564
|
+
REMOTE_VERSION_CHECK_TIMEOUT_SECONDS = 1.0
|
|
565
|
+
|
|
566
|
+
REMOTE_VERSION_LOCK = threading.Lock()
|
|
567
|
+
REMOTE_VERSION_THREAD: threading.Thread | None = None
|
|
568
|
+
def pending_remote_version_result() -> dict[str, Any]:
|
|
569
|
+
return {
|
|
570
|
+
"status": "pending",
|
|
571
|
+
"detail": "",
|
|
572
|
+
"current_version": "",
|
|
573
|
+
"latest_version": "",
|
|
574
|
+
"checked_at": None,
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
|
|
578
|
+
_pending_remote_version_result = pending_remote_version_result
|
|
579
|
+
REMOTE_VERSION_RESULT: dict[str, Any] = _pending_remote_version_result()
|
|
580
|
+
|
|
581
|
+
|
|
582
|
+
def _active_remote_version_result() -> dict[str, Any]:
|
|
583
|
+
sg = _sg()
|
|
584
|
+
if sg and hasattr(sg, "_REMOTE_VERSION_RESULT"):
|
|
585
|
+
target = getattr(sg, "_REMOTE_VERSION_RESULT")
|
|
586
|
+
if target is not _REMOTE_VERSION_RESULT and isinstance(target, dict):
|
|
587
|
+
return target
|
|
588
|
+
return _REMOTE_VERSION_RESULT
|
|
589
|
+
|
|
590
|
+
|
|
591
|
+
def remote_version_check_result() -> dict[str, Any]:
|
|
592
|
+
"""返回最近一次后台远端版本检查的快照(PERF-07)。
|
|
593
|
+
|
|
594
|
+
状态取值:``pending``(尚未运行/进行中)、``disabled``(显式关闭)、
|
|
595
|
+
``unavailable``(cloud_client 不可导入)、``network_error``(不可达)、
|
|
596
|
+
``invalid_metadata``(服务端元数据无效)、``up_to_date``、
|
|
597
|
+
``update_available``、``update_required``。
|
|
598
|
+
"""
|
|
599
|
+
scoped_result = ISOLATED_REMOTE_VERSION_RESULT.get()
|
|
600
|
+
if scoped_result is not None:
|
|
601
|
+
if not scoped_result:
|
|
602
|
+
scoped_result.update(_pending_remote_version_result())
|
|
603
|
+
return dict(scoped_result)
|
|
604
|
+
with REMOTE_VERSION_LOCK:
|
|
605
|
+
return dict(_active_remote_version_result())
|
|
606
|
+
|
|
607
|
+
|
|
608
|
+
def clear_remote_version_check_cache() -> None:
|
|
609
|
+
"""清空后台版本检查的结果缓存(测试用;不影响已启动的线程)。"""
|
|
610
|
+
global _REMOTE_VERSION_THREAD
|
|
611
|
+
scoped_result = ISOLATED_REMOTE_VERSION_RESULT.get()
|
|
612
|
+
if scoped_result is not None:
|
|
613
|
+
scoped_result.clear()
|
|
614
|
+
scoped_result.update(_pending_remote_version_result())
|
|
615
|
+
return
|
|
616
|
+
with REMOTE_VERSION_LOCK:
|
|
617
|
+
REMOTE_VERSION_THREAD = None
|
|
618
|
+
target = _active_remote_version_result()
|
|
619
|
+
target.clear()
|
|
620
|
+
target.update(_pending_remote_version_result())
|
|
621
|
+
|
|
622
|
+
|
|
623
|
+
def record_remote_version_result(
|
|
624
|
+
*, status: str, detail: str = "",
|
|
625
|
+
current_version: str = "", latest_version: str = "",
|
|
626
|
+
) -> None:
|
|
627
|
+
"""记录后台版本检查结论,供 :func:`remote_version_check_result` 读取。"""
|
|
628
|
+
payload = {
|
|
629
|
+
"status": status,
|
|
630
|
+
"detail": detail,
|
|
631
|
+
"current_version": current_version,
|
|
632
|
+
"latest_version": latest_version,
|
|
633
|
+
"checked_at": time.time(),
|
|
634
|
+
}
|
|
635
|
+
scoped_result = ISOLATED_REMOTE_VERSION_RESULT.get()
|
|
636
|
+
if scoped_result is not None:
|
|
637
|
+
scoped_result.update(payload)
|
|
638
|
+
return
|
|
639
|
+
with REMOTE_VERSION_LOCK:
|
|
640
|
+
target = _active_remote_version_result()
|
|
641
|
+
target.update(payload)
|
|
642
|
+
|
|
643
|
+
|
|
644
|
+
def schedule_startup_remote_version_check(
|
|
645
|
+
*, stream=None,
|
|
646
|
+
) -> threading.Thread | None:
|
|
647
|
+
"""在守护线程中执行远端版本检查,立即返回、绝不阻塞启动(PERF-07)。
|
|
648
|
+
|
|
649
|
+
旧实现自称「非阻断」,实际是在 ``main()`` 中同步调用:黑洞网络下
|
|
650
|
+
``2 × 5s + sleep ≈ 10.5s`` 全部压在任何后续启动步骤之前。现在只负责
|
|
651
|
+
启动一个 daemon 线程;进程退出时线程自动终止,慢检查不可能拖慢
|
|
652
|
+
``bugx pre``。结果写入进程内缓存(:func:`remote_version_check_result`)。
|
|
653
|
+
|
|
654
|
+
进程内 harness 没有 OS 进程退出边界:检查在当前作用域同步完成,结果写入
|
|
655
|
+
ContextVar 容器,既不遗留后台线程也不覆盖宿主的线程/结果状态。
|
|
656
|
+
"""
|
|
657
|
+
global _REMOTE_VERSION_THREAD
|
|
658
|
+
if ISOLATED_REMOTE_VERSION_RESULT.get() is not None:
|
|
659
|
+
_startup_remote_version_check(stream=stream)
|
|
660
|
+
return None
|
|
661
|
+
with REMOTE_VERSION_LOCK:
|
|
662
|
+
sg = _sg()
|
|
663
|
+
sg_thread = getattr(sg, "_REMOTE_VERSION_THREAD", None) if sg else None
|
|
664
|
+
if sg_thread is not None and getattr(sg_thread, "is_alive", lambda: False)():
|
|
665
|
+
return sg_thread
|
|
666
|
+
if _REMOTE_VERSION_THREAD is not None and _REMOTE_VERSION_THREAD.is_alive():
|
|
667
|
+
return _REMOTE_VERSION_THREAD
|
|
668
|
+
thread_cls = getattr(getattr(sg, "threading", None), "Thread", threading.Thread)
|
|
669
|
+
thread = thread_cls(
|
|
670
|
+
target=_startup_remote_version_check,
|
|
671
|
+
kwargs={"stream": stream},
|
|
672
|
+
name="bugx-remote-version-check",
|
|
673
|
+
daemon=True,
|
|
674
|
+
)
|
|
675
|
+
REMOTE_VERSION_THREAD = thread
|
|
676
|
+
thread.start()
|
|
677
|
+
return thread
|
|
678
|
+
|
|
679
|
+
|
|
680
|
+
def startup_remote_version_check(*, stream=None) -> None:
|
|
681
|
+
"""远端版本检查体;经调度器选择 CLI 后台或 harness 同步边界。
|
|
682
|
+
|
|
683
|
+
Queries the BugX server for the latest CLI version. If a newer version
|
|
684
|
+
is available, prints a non-blocking hint. If the check fails (air-gap,
|
|
685
|
+
DNS, etc.), it is silently skipped.
|
|
686
|
+
|
|
687
|
+
直接调用本函数会阻塞当前线程;启动链路经
|
|
688
|
+
:func:`schedule_startup_remote_version_check` 决定执行边界。
|
|
689
|
+
|
|
690
|
+
Can be disabled with BUGX_DISABLE_VERSION_CHECK=1 env var or
|
|
691
|
+
disable_version_check=true in cloud-config.json.
|
|
692
|
+
"""
|
|
693
|
+
stream = stream or sys.stdout
|
|
694
|
+
if os.environ.get("BUGX_DISABLE_VERSION_CHECK", "").lower() in {"1", "true", "yes"}:
|
|
695
|
+
_record_remote_version_result(status="disabled", detail="BUGX_DISABLE_VERSION_CHECK")
|
|
696
|
+
return
|
|
697
|
+
cloud_client = getattr(_sg(), "_cloud_client_module", None)
|
|
698
|
+
client_metadata = getattr(_sg(), "_client_metadata_module", None)
|
|
699
|
+
if cloud_client is None or client_metadata is None:
|
|
700
|
+
_record_remote_version_result(status="unavailable", detail="cloud_client 不可导入")
|
|
701
|
+
return
|
|
702
|
+
|
|
703
|
+
# Check persisted config for disable_version_check.
|
|
704
|
+
try:
|
|
705
|
+
cfg = cloud_client.load_cloud_config()
|
|
706
|
+
if cfg.get("disable_version_check", False):
|
|
707
|
+
_record_remote_version_result(status="disabled", detail="cloud-config")
|
|
708
|
+
return
|
|
709
|
+
except Exception: # noqa: BLE001
|
|
710
|
+
pass # config read failure; continue with env check
|
|
711
|
+
|
|
712
|
+
try:
|
|
713
|
+
client = cloud_client.CloudClient()
|
|
714
|
+
# PERF-07: 单次短超时且不重试——后台线程也不应长期挂起。
|
|
715
|
+
try:
|
|
716
|
+
client.timeout = min(float(client.timeout), REMOTE_VERSION_CHECK_TIMEOUT_SECONDS)
|
|
717
|
+
except (TypeError, ValueError):
|
|
718
|
+
client.timeout = REMOTE_VERSION_CHECK_TIMEOUT_SECONDS
|
|
719
|
+
if hasattr(client, "retries"):
|
|
720
|
+
client.retries = 0
|
|
721
|
+
# Get current CLI version.
|
|
722
|
+
cli_ver = ""
|
|
723
|
+
if hasattr(cloud_client, "current_version_str"):
|
|
724
|
+
cli_ver = cloud_client.current_version_str()
|
|
725
|
+
elif hasattr(cloud_client, "__version__"):
|
|
726
|
+
cli_ver = cloud_client.__version__
|
|
727
|
+
if cli_ver == "unknown":
|
|
728
|
+
cli_ver = ""
|
|
729
|
+
result = client.check_version(
|
|
730
|
+
current_version=cli_ver,
|
|
731
|
+
channel=client_metadata.release_channel(),
|
|
732
|
+
)
|
|
733
|
+
if not result.ok:
|
|
734
|
+
_record_remote_version_result(
|
|
735
|
+
status="network_error", detail=str(result.error or ""),
|
|
736
|
+
current_version=str(cli_ver),
|
|
737
|
+
)
|
|
738
|
+
return # network unreachable; silently skip
|
|
739
|
+
data = result.data if isinstance(result.data, dict) else {}
|
|
740
|
+
info = data.get("data") if isinstance(data.get("data"), dict) else data
|
|
741
|
+
latest = str(info.get("latest_version") or "").strip()
|
|
742
|
+
min_client = str(info.get("min_client_version") or "").strip()
|
|
743
|
+
current_tuple = _startup_release_version(cli_ver)
|
|
744
|
+
latest_tuple = _startup_release_version(latest)
|
|
745
|
+
min_tuple = _startup_release_version(min_client) if min_client else None
|
|
746
|
+
if latest_tuple is None or (min_client and min_tuple is None):
|
|
747
|
+
print(
|
|
748
|
+
f"[version] 服务端版本元数据无效,已跳过启动提示: "
|
|
749
|
+
f"latest={latest!r} min_client={min_client!r}",
|
|
750
|
+
file=stream,
|
|
751
|
+
)
|
|
752
|
+
_record_remote_version_result(
|
|
753
|
+
status="invalid_metadata",
|
|
754
|
+
detail=f"latest={latest!r} min_client={min_client!r}",
|
|
755
|
+
current_version=str(cli_ver),
|
|
756
|
+
)
|
|
757
|
+
return
|
|
758
|
+
if current_tuple is None:
|
|
759
|
+
_record_remote_version_result(
|
|
760
|
+
status="invalid_metadata", detail=f"cli={cli_ver!r}",
|
|
761
|
+
current_version=str(cli_ver), latest_version=latest,
|
|
762
|
+
)
|
|
763
|
+
return
|
|
764
|
+
if latest_tuple < current_tuple:
|
|
765
|
+
print(
|
|
766
|
+
f"[version] 服务端发布版本 {latest} 低于当前 CLI {cli_ver},"
|
|
767
|
+
"已跳过启动更新提示",
|
|
768
|
+
file=stream,
|
|
769
|
+
)
|
|
770
|
+
_record_remote_version_result(
|
|
771
|
+
status="up_to_date", detail="服务端发布版本低于当前 CLI",
|
|
772
|
+
current_version=str(cli_ver), latest_version=latest,
|
|
773
|
+
)
|
|
774
|
+
return
|
|
775
|
+
if min_tuple is not None and min_tuple > latest_tuple:
|
|
776
|
+
print(
|
|
777
|
+
f"[version] 服务端版本元数据矛盾,已跳过启动提示:"
|
|
778
|
+
f"最低兼容版本 {min_client} 高于发布版本 {latest}",
|
|
779
|
+
file=stream,
|
|
780
|
+
)
|
|
781
|
+
_record_remote_version_result(
|
|
782
|
+
status="invalid_metadata", detail="min_client_version 高于 latest_version",
|
|
783
|
+
current_version=str(cli_ver), latest_version=latest,
|
|
784
|
+
)
|
|
785
|
+
return
|
|
786
|
+
update_required = (info.get("update_required") is True
|
|
787
|
+
or (min_tuple is not None and current_tuple < min_tuple))
|
|
788
|
+
update_available = (info.get("update_available") is True
|
|
789
|
+
or latest_tuple > current_tuple)
|
|
790
|
+
if update_required:
|
|
791
|
+
print(
|
|
792
|
+
f"\n⚠ BugX CLI 版本 {cli_ver} 低于最低兼容版本 {min_client},"
|
|
793
|
+
"可能导致 Cloud Sync 协议不兼容。",
|
|
794
|
+
file=stream,
|
|
795
|
+
)
|
|
796
|
+
print(f" 最新版本: {latest}", file=stream)
|
|
797
|
+
print(" 请立即执行:bugx update\n", file=stream)
|
|
798
|
+
_record_remote_version_result(
|
|
799
|
+
status="update_required", detail=f"min_client={min_client}",
|
|
800
|
+
current_version=str(cli_ver), latest_version=latest,
|
|
801
|
+
)
|
|
802
|
+
elif update_available and latest:
|
|
803
|
+
print(f"\n✦ BugX CLI 有新版本可用: {latest}(当前: {cli_ver})", file=stream)
|
|
804
|
+
print(" 建议执行:bugx update\n", file=stream)
|
|
805
|
+
_record_remote_version_result(
|
|
806
|
+
status="update_available", detail="",
|
|
807
|
+
current_version=str(cli_ver), latest_version=latest,
|
|
808
|
+
)
|
|
809
|
+
else:
|
|
810
|
+
_record_remote_version_result(
|
|
811
|
+
status="up_to_date", detail="",
|
|
812
|
+
current_version=str(cli_ver), latest_version=latest,
|
|
813
|
+
)
|
|
814
|
+
except Exception as exc: # noqa: BLE001
|
|
815
|
+
_record_remote_version_result(
|
|
816
|
+
status="network_error", detail=f"{type(exc).__name__}: {exc}",
|
|
817
|
+
)
|
|
818
|
+
return
|
|
819
|
+
|
|
820
|
+
def emit_version_contract_gate(detail: str, environment=None) -> None:
|
|
821
|
+
"""Stop at one explicit version gate instead of feeding a retry loop.
|
|
822
|
+
|
|
823
|
+
Version repair can replace the global engine and host entrypoints. The
|
|
824
|
+
current process must therefore never repair and re-enter itself. The host
|
|
825
|
+
performs one explicit repair action, restarts, and only then retries.
|
|
826
|
+
"""
|
|
827
|
+
emit_startup_gate(
|
|
828
|
+
"version_contract",
|
|
829
|
+
"BugX CLI、项目核心和全局引擎版本契约不一致",
|
|
830
|
+
[
|
|
831
|
+
{
|
|
832
|
+
"label": "执行一次受控更新并重启宿主",
|
|
833
|
+
"description": "只执行一次更新;完成后重启宿主,再重试启动",
|
|
834
|
+
"value": "repair_once",
|
|
835
|
+
"action": "repair_version_contract",
|
|
836
|
+
"retry": "only_after_host_restart_once",
|
|
837
|
+
},
|
|
838
|
+
{
|
|
839
|
+
"label": "停止本轮",
|
|
840
|
+
"description": "保留当前状态,等待人工处理版本契约",
|
|
841
|
+
"value": "stop",
|
|
842
|
+
"action": "stop_startup",
|
|
843
|
+
},
|
|
844
|
+
],
|
|
845
|
+
environment=environment,
|
|
846
|
+
detail=detail + ";不得在同一会话中自动循环重试。",
|
|
847
|
+
)
|
|
848
|
+
|
|
849
|
+
def emit_project_layout_gate(detail: str, environment=None) -> None:
|
|
850
|
+
"""Keep existing project data intact when its layout cannot be trusted."""
|
|
851
|
+
emit_startup_gate(
|
|
852
|
+
"project_layout",
|
|
853
|
+
"项目 BugX 状态不完整或格式不受支持",
|
|
854
|
+
[{
|
|
855
|
+
"label": "停止本轮并检查项目状态",
|
|
856
|
+
"description": "保留已有状态,检查或恢复项目数据后继续",
|
|
857
|
+
"value": "stop",
|
|
858
|
+
"action": "stop_startup",
|
|
859
|
+
}],
|
|
860
|
+
environment=environment,
|
|
861
|
+
detail=detail,
|
|
862
|
+
)
|
|
863
|
+
|
|
864
|
+
|
|
865
|
+
_normalize_cli_version = normalize_cli_version
|
|
866
|
+
_installed_cli_version = installed_cli_version
|
|
867
|
+
_startup_release_version = startup_release_version
|
|
868
|
+
_pending_remote_version_result = pending_remote_version_result
|
|
869
|
+
_record_remote_version_result = record_remote_version_result
|
|
870
|
+
_startup_remote_version_check = startup_remote_version_check
|
|
871
|
+
_REMOTE_VERSION_LOCK = REMOTE_VERSION_LOCK
|
|
872
|
+
_REMOTE_VERSION_RESULT = REMOTE_VERSION_RESULT
|
|
873
|
+
_REMOTE_VERSION_THREAD = REMOTE_VERSION_THREAD
|