bugx-cli 0.0.0-stage → 0.1.1
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 +284 -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 +51 -0
- package/core/agent/__init__.py +146 -0
- package/core/agent/agent_artifacts.py +766 -0
- package/core/agent/agent_eval.py +1155 -0
- package/core/agent/agent_execution.py +718 -0
- package/core/agent/agent_orchestrator.py +1351 -0
- package/core/agent/agent_targets.py +877 -0
- package/core/agent/agent_workspace.py +770 -0
- package/core/agent/feature_baseline.py +150 -0
- package/core/assets/README.md +24 -0
- package/core/assets/axe-core/LICENSE-3RD-PARTY.txt +66 -0
- package/core/assets/axe-core/LICENSE.txt +362 -0
- package/core/assets/axe-core/UPSTREAM.md +10 -0
- package/core/assets/axe-core/axe.min.js +12 -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/bugx-hero-en.svg +74 -0
- package/core/assets/bugx-hero-zh.svg +74 -0
- package/core/assets/codex.png +0 -0
- package/core/assets/dsh.png +0 -0
- package/core/assets/project-layout.md +42 -0
- package/core/assets/webui-chatgpt.jpg +0 -0
- package/core/assets/webui-session.jpg +0 -0
- package/core/assets/webui-skills.jpg +0 -0
- package/core/assets/webui-studio.jpg +0 -0
- package/core/assets/webui-zcode.jpg +0 -0
- package/core/assets/zcode.png +0 -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 +1868 -0
- package/core/autonomous_cve/audit_campaign.py +1232 -0
- package/core/autonomous_cve/behavior_graph.py +465 -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 +103 -0
- package/core/bugx.md +1299 -0
- package/core/bugx_paths.py +1881 -0
- package/core/cli-help.txt +66 -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 +1218 -0
- package/core/cloud_sync/cloud_onboard.py +743 -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 +769 -0
- package/core/cloud_sync/network_transport.py +296 -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 +723 -0
- package/core/contracts/AGENT_GUIDE.md +359 -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 +473 -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 +1429 -0
- package/core/coverage/coverage_evidence.py +1024 -0
- package/core/coverage/coverage_forensics.py +124 -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 +241 -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 +2797 -0
- package/core/fuzzing/README.md +49 -0
- package/core/fuzzing/__init__.py +82 -0
- package/core/fuzzing/concurrency_fuzzer.py +435 -0
- package/core/fuzzing/differential_oracle.py +1164 -0
- package/core/fuzzing/fuzz_input.py +1291 -0
- package/core/fuzzing/stateful_fuzzer.py +404 -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 +784 -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 +99 -0
- package/core/host_acp/cline.py +298 -0
- package/core/host_acp/codex.py +300 -0
- package/core/host_acp/dsh.py +106 -0
- package/core/host_acp/opencode.py +209 -0
- package/core/host_acp/pi.py +94 -0
- package/core/host_acp/zcode.py +99 -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 +448 -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 +761 -0
- package/core/host_runtime/host_probe.py +41 -0
- package/core/host_runtime/host_provider_arbitrator.py +831 -0
- package/core/host_runtime/host_registry.py +662 -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 +379 -0
- package/core/host_runtime/pi.py +102 -0
- package/core/host_runtime/provider_facts.py +66 -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 +140 -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 +479 -0
- package/core/hosts/claude.py +212 -0
- package/core/hosts/cline.py +229 -0
- package/core/hosts/codex.py +1006 -0
- package/core/hosts/dsh.py +526 -0
- package/core/hosts/opencode.py +358 -0
- package/core/hosts/pi.py +308 -0
- package/core/hosts/zcode.py +219 -0
- package/core/i18n.py +252 -0
- package/core/infra/README.md +41 -0
- package/core/infra/__init__.py +17 -0
- package/core/infra/build_info.py +105 -0
- package/core/infra/client_metadata.py +185 -0
- package/core/infra/json_utils.py +22 -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 +1060 -0
- package/core/launch_phases/finding_confirm_phase.py +391 -0
- package/core/launch_phases/finding_settlement.py +1432 -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 +848 -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 +686 -0
- package/core/launch_phases/post_commit.py +567 -0
- package/core/launch_phases/post_coverage_sync.py +598 -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 +1223 -0
- package/core/launch_phases/post_receipt.py +373 -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 +879 -0
- package/core/launch_phases/pre_state_builder.py +1133 -0
- package/core/launch_phases/report_sharing.py +414 -0
- package/core/launch_phases/round_orchestrator.py +1116 -0
- package/core/launch_phases/session_runtime.py +1670 -0
- package/core/launch_phases/startup_gates.py +1050 -0
- package/core/launch_phases/startup_interaction.py +1003 -0
- package/core/launch_phases/startup_version_gate.py +879 -0
- package/core/launch_phases/supervisor_bridge.py +1253 -0
- package/core/launch_phases/supervisor_coverage.py +423 -0
- package/core/launch_phases/supervisor_degraded.py +1211 -0
- package/core/launch_phases/worker_barriers.py +424 -0
- package/core/launch_phases/worker_orchestrator.py +1246 -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 +227 -0
- package/core/ledger/archive_ops.py +630 -0
- package/core/ledger/auto_materialization.py +459 -0
- package/core/ledger/bug-log.md +22 -0
- package/core/ledger/cli.py +275 -0
- package/core/ledger/export_ops.py +554 -0
- package/core/ledger/finding_confirmation.py +1316 -0
- package/core/ledger/finding_io.py +299 -0
- package/core/ledger/finding_lifecycle.py +730 -0
- package/core/ledger/finding_verification.py +405 -0
- package/core/ledger/incidents.py +1005 -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 +684 -0
- package/core/ledger/receipt_contract.py +269 -0
- package/core/ledger/schema.py +1192 -0
- package/core/ledger/sync_ops.py +940 -0
- package/core/ledger/tool_experience.py +683 -0
- package/core/ledger/verify_life.py +1597 -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 +717 -0
- package/core/mcp_handlers/channel_lifecycle.py +751 -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 +249 -0
- package/core/mcp_handlers/rpc_server.py +470 -0
- package/core/mcp_handlers/supervisor_handlers.py +1461 -0
- package/core/mcp_handlers/telemetry_handlers.py +227 -0
- package/core/mcp_handlers/tool_table.py +1030 -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 +567 -0
- package/core/mcp_runtime_support/verifier.py +758 -0
- package/core/metadata.txt +4 -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 +269 -0
- package/core/planning/dynamic_flow_analyzer.py +533 -0
- package/core/planning/impact_pruner.py +435 -0
- package/core/planning/intent_adjudicator.py +175 -0
- package/core/planning/judge_pipeline.py +1246 -0
- package/core/planning/logic_analysis.py +419 -0
- package/core/planning/prompt_harness.py +1704 -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 +83 -0
- package/core/probes/README.md +51 -0
- package/core/probes/SPEC.md +36 -0
- package/core/probes/__init__.py +76 -0
- package/core/probes/android_probe.py +552 -0
- package/core/probes/base.py +147 -0
- package/core/probes/codebase_memory_probe.py +647 -0
- package/core/probes/desktop_probe.py +342 -0
- package/core/probes/differential_probe.py +434 -0
- package/core/probes/efficiency_probe.py +232 -0
- package/core/probes/ios_binary_probe.py +472 -0
- package/core/probes/memory_probe.py +392 -0
- package/core/probes/miniprogram_probe.py +385 -0
- package/core/probes/mobile_probe.py +466 -0
- package/core/probes/native_probe.py +302 -0
- package/core/probes/openwiki_probe.py +263 -0
- package/core/probes/pattern_probe.py +453 -0
- package/core/probes/platform_probe.py +424 -0
- package/core/probes/probe_registry.py +1770 -0
- package/core/probes/sast_fixture_corpus.py +340 -0
- package/core/probes/sast_probe.py +1510 -0
- package/core/probes/sast_rules.py +1481 -0
- package/core/probes/sca_scanner.py +779 -0
- package/core/probes/ui_accessibility.py +149 -0
- package/core/probes/ui_audit.py +513 -0
- package/core/probes/ui_contract.py +273 -0
- package/core/probes/ui_evidence.py +212 -0
- package/core/probes/ui_measurements.py +314 -0
- package/core/probes/ui_repair.py +250 -0
- package/core/probes/ui_review.py +133 -0
- package/core/probes/ui_storybook.py +107 -0
- package/core/probes/ui_tokens.py +185 -0
- package/core/probes/ui_visual_diff.py +131 -0
- package/core/probes/web_probe.py +714 -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 +316 -0
- package/core/project_profiler/constants.py +247 -0
- package/core/project_profiler/detector.py +399 -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 +301 -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 +462 -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 +311 -0
- package/core/repair/rsi_repair.py +348 -0
- package/core/repair/rsi_rounds.py +212 -0
- package/core/repair/rsi_scope.py +281 -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 +228 -0
- package/core/report_engine/authority.py +255 -0
- package/core/report_engine/finding_report.py +418 -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 +759 -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 +832 -0
- package/core/report_engine/visual_report_builder.py +796 -0
- package/core/report_engine/web-conformance.md +168 -0
- package/core/report_engine/web_conformance.py +428 -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 +1720 -0
- package/core/retrieval/codebase_memory_bridge.py +337 -0
- package/core/retrieval/context_assembler.py +240 -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 +1003 -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 +1151 -0
- package/core/retrieval/universal_code_matcher.py +622 -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 +1464 -0
- package/core/runtime/daemon_runner.py +623 -0
- package/core/runtime/fixture_solidify.py +444 -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 +732 -0
- package/core/runtime/platform_adapter.py +579 -0
- package/core/runtime/prep_validate.py +478 -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 +964 -0
- package/core/runtime/provider_window.py +97 -0
- package/core/runtime/resume_ticket.py +115 -0
- package/core/runtime/scenario_eval.py +856 -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 +418 -0
- package/core/skills/bugx_mcp_server.py +1161 -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 +1254 -0
- package/core/supervisor/checkpoint_handler.py +368 -0
- package/core/supervisor/checkpoint_pipeline.py +1564 -0
- package/core/supervisor/checkpoint_sync.py +653 -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 +676 -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 +129 -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 +355 -0
- package/core/supervisor/round_governor.py +306 -0
- package/core/supervisor/serial_authorization.py +544 -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 +230 -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 +1005 -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 +411 -0
- package/core/webui/INTERFACE.md +50 -0
- package/core/webui/README.md +57 -0
- package/core/webui/SPEC.md +26 -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 +222 -0
- package/core/webui/adapters/cline.py +407 -0
- package/core/webui/adapters/codex.py +260 -0
- package/core/webui/adapters/dsh.py +177 -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 +1747 -0
- package/core/webui/static/00-base.css +1060 -0
- package/core/webui/static/01-monitoring.css +802 -0
- package/core/webui/static/02-header-actions.css +321 -0
- package/core/webui/static/03-trigger-popover.css +697 -0
- package/core/webui/static/04-composer.css +628 -0
- package/core/webui/static/05-skills-center.css +878 -0
- package/core/webui/static/06-mcp-center.css +623 -0
- package/core/webui/static/07-skill-detail.css +265 -0
- package/core/webui/static/08-files-management.css +167 -0
- package/core/webui/static/09-files-center.css +386 -0
- package/core/webui/static/10-icons.css +105 -0
- package/core/webui/static/11-project-options.css +185 -0
- package/core/webui/static/12-profile-tab.css +383 -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/design-tokens.css +113 -0
- package/core/webui/static/favicon.png +0 -0
- package/core/webui/static/icon-192.png +0 -0
- package/core/webui/static/index.html +55 -0
- package/core/webui/static/manifest.webmanifest +19 -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 +285 -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 +3075 -0
- package/ecosystem/integrations/opencode/opencode.json +129 -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/bin/bugx.js +117 -0
- package/interfaces/cli/bugx_cli/__init__.py +6 -0
- package/interfaces/cli/bugx_cli/cli.py +1685 -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 +4210 -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 +1371 -0
- package/interfaces/cli/bugx_cli/commands/daemon.py +50 -0
- package/interfaces/cli/bugx_cli/commands/doctor.py +1590 -0
- package/interfaces/cli/bugx_cli/commands/goal.py +107 -0
- package/interfaces/cli/bugx_cli/commands/interaction.py +248 -0
- package/interfaces/cli/bugx_cli/commands/knowledge.py +619 -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 +2749 -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 +729 -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 +256 -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 +906 -0
- package/interfaces/cli/bugx_cli/host_adapters.py +1892 -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 +573 -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 +851 -0
- package/interfaces/cli/bugx_cli/infra/engine_installer.py +1945 -0
- package/interfaces/cli/bugx_cli/infra/host_sync.py +548 -0
- package/interfaces/cli/bugx_cli/infra/mcp_advisor.py +826 -0
- package/interfaces/cli/bugx_cli/infra/security.py +339 -0
- package/package.json +99 -4
- package/pyproject.toml +258 -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 +26 -0
- package/scripts/test-npm-wrapper.mjs +265 -0
|
@@ -0,0 +1,1770 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""BugX 探针插件注册中心(Probe Registry)。
|
|
3
|
+
|
|
4
|
+
统一维护全系统探针元数据、自检协议与调用边界,支持动态探针注册与自适应分发。
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import concurrent.futures
|
|
10
|
+
from dataclasses import dataclass
|
|
11
|
+
import hashlib
|
|
12
|
+
import json
|
|
13
|
+
import math
|
|
14
|
+
import os
|
|
15
|
+
from pathlib import Path
|
|
16
|
+
import subprocess
|
|
17
|
+
import sys
|
|
18
|
+
import time
|
|
19
|
+
from typing import Any, Mapping, Sequence
|
|
20
|
+
|
|
21
|
+
import core.secure_atomic as secure_atomic
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
PROBE_TIMEOUT_BUDGET: dict[str, float] = {
|
|
25
|
+
"sast": 30.0,
|
|
26
|
+
# codebase-memory starts a Go CLI, loads sqlite and may scan the
|
|
27
|
+
# repository before answering. Measured cold start on this repo
|
|
28
|
+
# (nodes=44133, edges=190210, index 170MB) is 18~24s, so the old 15s floor
|
|
29
|
+
# degraded a healthy accelerator on every first probe. 45s keeps the same
|
|
30
|
+
# ~1.9x margin the platform probe uses over its 11~17s cold start, and the
|
|
31
|
+
# probe adds one bounded retry for the slow-tail case.
|
|
32
|
+
"codebase-memory": 45.0,
|
|
33
|
+
# platform 探针逐个枚举宿主平台能力并拉起子命令,冷启动实测 11~17s;
|
|
34
|
+
# memory 探针要加载索引与内存画像,实测约 5.7s。二者若沿用 default 5.0s,
|
|
35
|
+
# 在无历史耗时的首次启动必然假超时(下一次凭 previous_duration 把预算抬到
|
|
36
|
+
# 12s 才通过),使同一环境在两次 pre 之间出现「这次要处置、下次又健康」的
|
|
37
|
+
# 结果翻转。这里给出显式预算,消除该非确定性。
|
|
38
|
+
"platform": 30.0,
|
|
39
|
+
"memory": 20.0,
|
|
40
|
+
# mobile 探针逐 tier 拉起 adb/xcrun/maestro/appium 子进程,且 maestro 是
|
|
41
|
+
# JVM 工具:冷启动 --version 实测 7.5s(arm64 本机);版本探测已并行+2s
|
|
42
|
+
# 硬顶后单跑 ~3.4s,但 pre 并行跑全部探针时 CPU 争抢实测 5.13s,沿用
|
|
43
|
+
# default 5.0s 仍临界假超时并触发「安装决策」阻断链
|
|
44
|
+
# (F-RSI-20261118-004/005)。15s 提供 3x 余量,与 platform 冷启动策略一致。
|
|
45
|
+
"mobile": 15.0,
|
|
46
|
+
# openwiki 冷启动读索引约 2.3s,并行满载时临界 5s;建议性探针假超时
|
|
47
|
+
# 只产生噪音告警,同样的预算策略消除翻转。
|
|
48
|
+
"openwiki": 10.0,
|
|
49
|
+
"default": 5.0,
|
|
50
|
+
}
|
|
51
|
+
PROBE_TIMEOUT_MAX_SECONDS = 120.0
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def normalized_tool_environment(environ: Mapping[str, str] | None = None) -> dict[str, str]:
|
|
55
|
+
"""Return a child environment that can see common user tool locations."""
|
|
56
|
+
environment = dict(os.environ if environ is None else environ)
|
|
57
|
+
entries = [item for item in environment.get("PATH", "").split(os.pathsep) if item]
|
|
58
|
+
candidates = [environment.get("BUGX_TOOL_PATH", "")]
|
|
59
|
+
if os.name != "nt":
|
|
60
|
+
candidates.extend((
|
|
61
|
+
"/opt/homebrew/bin", "/usr/local/bin",
|
|
62
|
+
"/home/linuxbrew/.linuxbrew/bin",
|
|
63
|
+
str(Path.home() / ".local" / "bin"),
|
|
64
|
+
str(Path.home() / ".cargo" / "bin"),
|
|
65
|
+
))
|
|
66
|
+
for candidate in candidates:
|
|
67
|
+
if not candidate or candidate in entries:
|
|
68
|
+
continue
|
|
69
|
+
try:
|
|
70
|
+
if Path(candidate).is_dir():
|
|
71
|
+
entries.append(candidate)
|
|
72
|
+
except OSError:
|
|
73
|
+
continue
|
|
74
|
+
environment["PATH"] = os.pathsep.join(entries)
|
|
75
|
+
return environment
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def _positive_timeout(value: object) -> float | None:
|
|
79
|
+
try:
|
|
80
|
+
parsed = float(value)
|
|
81
|
+
except (TypeError, ValueError):
|
|
82
|
+
return None
|
|
83
|
+
if not math.isfinite(parsed) or parsed <= 0:
|
|
84
|
+
return None
|
|
85
|
+
return parsed
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def probe_timeout_budget(name: str, previous_duration: float | None = None) -> float:
|
|
89
|
+
"""Choose a bounded timeout from a cold-start floor and prior telemetry."""
|
|
90
|
+
normalized = name.upper().replace("-", "_")
|
|
91
|
+
override = (
|
|
92
|
+
os.environ.get(f"BUGX_PROBE_TIMEOUT_{normalized}")
|
|
93
|
+
or os.environ.get("BUGX_PROBE_TIMEOUT_SECONDS")
|
|
94
|
+
)
|
|
95
|
+
budget = _positive_timeout(override)
|
|
96
|
+
if budget is None:
|
|
97
|
+
budget = PROBE_TIMEOUT_BUDGET.get(name, PROBE_TIMEOUT_BUDGET["default"])
|
|
98
|
+
if previous_duration and previous_duration > 0:
|
|
99
|
+
budget = max(budget, previous_duration * 2.0 + 2.0)
|
|
100
|
+
minimum = 5.0 if name == "codebase-memory" else 2.0
|
|
101
|
+
return min(PROBE_TIMEOUT_MAX_SECONDS, max(minimum, budget))
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
@dataclass(frozen=True)
|
|
105
|
+
class ProbeDescriptor:
|
|
106
|
+
"""探针插件元数据描述符。"""
|
|
107
|
+
|
|
108
|
+
name: str
|
|
109
|
+
script: str
|
|
110
|
+
domain: str
|
|
111
|
+
accepts_root: bool = True
|
|
112
|
+
description: str = ""
|
|
113
|
+
priority: int = 100
|
|
114
|
+
lifecycle: str = "preflight" # "preflight" (启动前预检) | "runtime" (运行期专项执行)
|
|
115
|
+
# DES-13:``required=True`` 表示脚本缺失时启动必须硬阻断;
|
|
116
|
+
# 建议性探针(如 openwiki)设为 False,缺失即静默跳过。
|
|
117
|
+
required: bool = True
|
|
118
|
+
# DOC-236 C1:``critical=True`` 表示缺失/不可用必须硬阻断且**不得**被
|
|
119
|
+
# ``tooling_exemptions`` 豁免。只有"引擎自身没有等价回退"的能力才配 True;
|
|
120
|
+
# 带内置回退的加速器(如 codebase-memory → symbol_index/project_graph)
|
|
121
|
+
# 必须为 False,仍可经项目配置显式豁免并留痕。
|
|
122
|
+
critical: bool = True
|
|
123
|
+
# 只有显式声明 host 的探针才允许跨项目复用;新探针缺省绑定项目。
|
|
124
|
+
cache_scope: str = "project"
|
|
125
|
+
# 运行期探针只有显式声明不执行目标工作的就绪动作,才能被 Skill Pack
|
|
126
|
+
# 声明为 required_runtime.tools。参数只作为 argv 传递,不经过 shell。
|
|
127
|
+
readiness_args: tuple[str, ...] | None = None
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
# 内置探针静态定义清单
|
|
131
|
+
_BUILTIN_PROBES: tuple[ProbeDescriptor, ...] = (
|
|
132
|
+
ProbeDescriptor(
|
|
133
|
+
name="efficiency",
|
|
134
|
+
script="efficiency_probe.py",
|
|
135
|
+
domain="performance",
|
|
136
|
+
accepts_root=True,
|
|
137
|
+
description="系统效率基线与环境计算性能评测探针",
|
|
138
|
+
priority=10,
|
|
139
|
+
lifecycle="preflight",
|
|
140
|
+
# check 只读查询可选 CLI 的 PATH/版本,不扫描项目源码。
|
|
141
|
+
readiness_args=("check",),
|
|
142
|
+
),
|
|
143
|
+
ProbeDescriptor(
|
|
144
|
+
name="sast",
|
|
145
|
+
script="sast_probe.py",
|
|
146
|
+
domain="security",
|
|
147
|
+
accepts_root=True,
|
|
148
|
+
description="多引擎静态代码安全扫描与规则违规探针",
|
|
149
|
+
priority=20,
|
|
150
|
+
lifecycle="preflight",
|
|
151
|
+
# check 只核对扫描器二进制与版本;scan(root) 才读取目标源码。
|
|
152
|
+
readiness_args=("check",),
|
|
153
|
+
# inspect() 只检查扫描器二进制与版本;扫描目标由后续 scan(root) 执行。
|
|
154
|
+
cache_scope="host",
|
|
155
|
+
# 外部扫描器(semgrep/codeql/trivy/bandit)为加速器,引擎自带 universal_code_matcher
|
|
156
|
+
# 与 sast_rules 内置 AST 回退,可经 tooling_exemptions 豁免并留痕。
|
|
157
|
+
critical=False,
|
|
158
|
+
),
|
|
159
|
+
ProbeDescriptor(
|
|
160
|
+
name="codebase-memory",
|
|
161
|
+
script="codebase_memory_probe.py",
|
|
162
|
+
domain="knowledge",
|
|
163
|
+
accepts_root=True,
|
|
164
|
+
description="Codebase Memory MCP 图谱语义与知识索引探针",
|
|
165
|
+
priority=30,
|
|
166
|
+
lifecycle="preflight",
|
|
167
|
+
# 加速器而非硬依赖:引擎自带 symbol_index/project_graph 回退
|
|
168
|
+
# (``BUGX_USE_CODEBASE_MEMORY=0`` 是受支持运行模式),因此可经
|
|
169
|
+
# 项目 ``tooling_exemptions`` 显式豁免;critical 能力不得豁免。
|
|
170
|
+
critical=False,
|
|
171
|
+
),
|
|
172
|
+
ProbeDescriptor(
|
|
173
|
+
name="pattern",
|
|
174
|
+
script="pattern_probe.py",
|
|
175
|
+
domain="security",
|
|
176
|
+
accepts_root=True,
|
|
177
|
+
description="高频历史缺陷模式与已知陷阱特征扫描探针",
|
|
178
|
+
priority=40,
|
|
179
|
+
lifecycle="runtime",
|
|
180
|
+
readiness_args=("check",),
|
|
181
|
+
),
|
|
182
|
+
ProbeDescriptor(
|
|
183
|
+
name="platform",
|
|
184
|
+
script="platform_probe.py",
|
|
185
|
+
domain="system",
|
|
186
|
+
accepts_root=True,
|
|
187
|
+
description="多平台运行时与工具链依赖适配探针",
|
|
188
|
+
priority=50,
|
|
189
|
+
lifecycle="preflight",
|
|
190
|
+
# 原始平台报告会在当前 profile 下重新筛选目标与形态。
|
|
191
|
+
cache_scope="host",
|
|
192
|
+
),
|
|
193
|
+
ProbeDescriptor(
|
|
194
|
+
name="mobile",
|
|
195
|
+
script="mobile_probe.py",
|
|
196
|
+
domain="mobile",
|
|
197
|
+
accepts_root=True,
|
|
198
|
+
description="移动端(Android/iOS)自动化与设备可用性探针",
|
|
199
|
+
priority=60,
|
|
200
|
+
lifecycle="preflight",
|
|
201
|
+
# 设备/工具状态为宿主级;形态、目标平台由报告重投影处理。
|
|
202
|
+
cache_scope="host",
|
|
203
|
+
),
|
|
204
|
+
ProbeDescriptor(
|
|
205
|
+
name="android",
|
|
206
|
+
script="android_probe.py",
|
|
207
|
+
domain="mobile",
|
|
208
|
+
accepts_root=True,
|
|
209
|
+
description="Android 探针(Manifest 静态语义 + adb 动态 Intent)",
|
|
210
|
+
priority=59,
|
|
211
|
+
lifecycle="runtime",
|
|
212
|
+
readiness_args=("check",),
|
|
213
|
+
required=False,
|
|
214
|
+
),
|
|
215
|
+
ProbeDescriptor(
|
|
216
|
+
name="ios_binary",
|
|
217
|
+
script="ios_binary_probe.py",
|
|
218
|
+
domain="mobile",
|
|
219
|
+
accepts_root=True,
|
|
220
|
+
description="iOS 二进制层探针(Mach-O 加固、代码签名、entitlements、ATS)",
|
|
221
|
+
priority=61,
|
|
222
|
+
lifecycle="runtime",
|
|
223
|
+
readiness_args=("--check-availability",),
|
|
224
|
+
required=False,
|
|
225
|
+
),
|
|
226
|
+
ProbeDescriptor(
|
|
227
|
+
name="memory",
|
|
228
|
+
script="memory_probe.py",
|
|
229
|
+
domain="memory",
|
|
230
|
+
accepts_root=False,
|
|
231
|
+
description="进程常驻与堆内存泄漏增长检测探针",
|
|
232
|
+
priority=70,
|
|
233
|
+
lifecycle="preflight",
|
|
234
|
+
cache_scope="host",
|
|
235
|
+
),
|
|
236
|
+
ProbeDescriptor(
|
|
237
|
+
name="differential",
|
|
238
|
+
script="differential_probe.py",
|
|
239
|
+
domain="testing",
|
|
240
|
+
accepts_root=False,
|
|
241
|
+
description="双跑差分与沙盒行为偏离检测探针",
|
|
242
|
+
priority=80,
|
|
243
|
+
lifecycle="runtime",
|
|
244
|
+
readiness_args=("check",),
|
|
245
|
+
),
|
|
246
|
+
ProbeDescriptor(
|
|
247
|
+
name="openwiki",
|
|
248
|
+
script="openwiki_probe.py",
|
|
249
|
+
domain="knowledge",
|
|
250
|
+
accepts_root=True,
|
|
251
|
+
description="OpenWiki 叙事层知识图谱检索探针",
|
|
252
|
+
priority=90,
|
|
253
|
+
lifecycle="preflight",
|
|
254
|
+
# 纯建议性探测(DOC-032):缺失不阻断启动。
|
|
255
|
+
required=False,
|
|
256
|
+
),
|
|
257
|
+
ProbeDescriptor(
|
|
258
|
+
name="concurrency",
|
|
259
|
+
script="fuzzing/concurrency_fuzzer.py",
|
|
260
|
+
domain="concurrency",
|
|
261
|
+
accepts_root=True,
|
|
262
|
+
description="并发竞态与异步时序死锁专项探针",
|
|
263
|
+
priority=82,
|
|
264
|
+
lifecycle="runtime",
|
|
265
|
+
readiness_args=("check",),
|
|
266
|
+
),
|
|
267
|
+
ProbeDescriptor(
|
|
268
|
+
name="stateful",
|
|
269
|
+
script="fuzzing/stateful_fuzzer.py",
|
|
270
|
+
domain="stateful",
|
|
271
|
+
accepts_root=True,
|
|
272
|
+
description="业务状态机序列突变推演与不变量校验探针",
|
|
273
|
+
priority=84,
|
|
274
|
+
lifecycle="runtime",
|
|
275
|
+
readiness_args=("check",),
|
|
276
|
+
),
|
|
277
|
+
ProbeDescriptor(
|
|
278
|
+
name="web_conformance",
|
|
279
|
+
script="report_engine/web_conformance.py",
|
|
280
|
+
domain="web",
|
|
281
|
+
accepts_root=True,
|
|
282
|
+
description="Web 标准、无障碍与 HTML 语义合规基线探针",
|
|
283
|
+
priority=65,
|
|
284
|
+
lifecycle="preflight",
|
|
285
|
+
),
|
|
286
|
+
ProbeDescriptor(
|
|
287
|
+
name="desktop",
|
|
288
|
+
script="desktop_probe.py",
|
|
289
|
+
domain="desktop",
|
|
290
|
+
accepts_root=True,
|
|
291
|
+
description="桌面应用项目级预检:进程模型安全开关、打包完整性与更新通道(只读)",
|
|
292
|
+
priority=66,
|
|
293
|
+
lifecycle="preflight",
|
|
294
|
+
),
|
|
295
|
+
ProbeDescriptor(
|
|
296
|
+
name="native",
|
|
297
|
+
script="native_probe.py",
|
|
298
|
+
domain="native",
|
|
299
|
+
accepts_root=True,
|
|
300
|
+
description="原生/嵌入式项目级预检:工具链、构建与 sanitizer 插桩能力(只读)",
|
|
301
|
+
priority=67,
|
|
302
|
+
lifecycle="preflight",
|
|
303
|
+
),
|
|
304
|
+
)
|
|
305
|
+
|
|
306
|
+
_REGISTRY: dict[str, ProbeDescriptor] = {p.name: p for p in _BUILTIN_PROBES}
|
|
307
|
+
_PROFILE_CACHE_SECONDS = 30.0 * 60.0
|
|
308
|
+
_ENGINE_DIR = Path(__file__).resolve().parent
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
def _is_engine_dir(root: Path) -> bool:
|
|
312
|
+
"""``root`` 是否指向引擎目录自身(而非项目根)。
|
|
313
|
+
|
|
314
|
+
DOC-004 Engine-State Separation:引擎目录只承载静态协议文件。
|
|
315
|
+
若把 ``.bugx/state/environment-profile.json`` 这类运行态缓存写进引擎包,
|
|
316
|
+
它会被 ``engine-integrity.json`` 冻结并随包分发到每个用户的
|
|
317
|
+
``~/.bugx/core``。``launch_phases.common._project_root()`` 在缺少
|
|
318
|
+
``BUGX_PROJECT_ROOT`` 时回落到 cwd,因此以 ``core/`` 为 cwd 运行会命中
|
|
319
|
+
这个错误路径(实测曾把引擎清单从 196 个文件撑到 197)。
|
|
320
|
+
"""
|
|
321
|
+
try:
|
|
322
|
+
return root.resolve() == _ENGINE_DIR
|
|
323
|
+
except OSError:
|
|
324
|
+
return True
|
|
325
|
+
|
|
326
|
+
|
|
327
|
+
def _resolve_probe_script(core_dir: Path, script_name: str) -> Path:
|
|
328
|
+
"""把探针脚本名解析成真实路径。
|
|
329
|
+
|
|
330
|
+
探针脚本会随架构收敛在 ``core/`` 内迁移(``core/web_conformance.py`` →
|
|
331
|
+
``core/report_engine/web_conformance.py``)。这里保留三条固定候选以覆盖
|
|
332
|
+
已知布局,最后再加一层**按文件名递归唯一解析**:迁移后不会因为写死的前缀
|
|
333
|
+
全部落空而把「脚本在别处」误报成「缺少脚本」,也不必每次搬迁都回来改这里。
|
|
334
|
+
同名多份时**不猜**——回落到 direct(不存在即由调用方显式报缺失)。
|
|
335
|
+
"""
|
|
336
|
+
for candidate in (
|
|
337
|
+
core_dir / script_name,
|
|
338
|
+
core_dir / "probes" / script_name,
|
|
339
|
+
core_dir.parent / "probes" / script_name,
|
|
340
|
+
):
|
|
341
|
+
if candidate.is_file():
|
|
342
|
+
return candidate
|
|
343
|
+
basename = Path(script_name).name
|
|
344
|
+
# 传入的 ``core_dir`` 可能已经是 ``core/probes`` 自己(旧调用点),因此递归
|
|
345
|
+
# 解析必须从**引擎根**开始;否则 ``core/report_engine/web_conformance.py``
|
|
346
|
+
# 在 ``core/probes`` 下永远搜不到。引擎根的判定锚点是 ``core/bugx.md``。
|
|
347
|
+
for search_root in (core_dir, *core_dir.parents):
|
|
348
|
+
if not (search_root / "bugx.md").is_file():
|
|
349
|
+
continue
|
|
350
|
+
matches = sorted(
|
|
351
|
+
path for path in search_root.rglob(basename)
|
|
352
|
+
if path.is_file() and "__pycache__" not in path.parts
|
|
353
|
+
)
|
|
354
|
+
if len(matches) == 1:
|
|
355
|
+
return matches[0]
|
|
356
|
+
break
|
|
357
|
+
return core_dir / script_name
|
|
358
|
+
|
|
359
|
+
|
|
360
|
+
def _registry_digest_part(digest: "hashlib._Hash", core_path: Path) -> None:
|
|
361
|
+
"""把注册中心自身指纹并入缓存键。
|
|
362
|
+
|
|
363
|
+
分类/剪枝/瞬态判定逻辑都住在 ``probe_registry.py`` 里:只按探针脚本
|
|
364
|
+
指纹做缓存键会让升级后的新逻辑继续吃旧画像,从而复现已修复的假阻断。
|
|
365
|
+
"""
|
|
366
|
+
try:
|
|
367
|
+
registry_file = core_path / "probe_registry.py"
|
|
368
|
+
if not registry_file.is_file():
|
|
369
|
+
registry_file = core_path / "probes" / "probe_registry.py"
|
|
370
|
+
if not registry_file.is_file():
|
|
371
|
+
registry_file = Path(__file__).resolve()
|
|
372
|
+
stat = registry_file.stat()
|
|
373
|
+
digest.update(f"registry:{stat.st_mtime_ns}:{stat.st_size}".encode("utf-8"))
|
|
374
|
+
except OSError:
|
|
375
|
+
digest.update(b"registry:missing")
|
|
376
|
+
|
|
377
|
+
|
|
378
|
+
def _profile_cache_key(
|
|
379
|
+
root: Path,
|
|
380
|
+
core_path: Path,
|
|
381
|
+
probes: list[ProbeDescriptor],
|
|
382
|
+
project_fingerprint: str | None = None,
|
|
383
|
+
) -> str:
|
|
384
|
+
digest = hashlib.sha256(str(root).encode("utf-8"))
|
|
385
|
+
_registry_digest_part(digest, core_path)
|
|
386
|
+
digest.update(
|
|
387
|
+
f"project-content:{project_fingerprint or 'unavailable'}".encode("utf-8")
|
|
388
|
+
)
|
|
389
|
+
for probe in probes:
|
|
390
|
+
script = _resolve_probe_script(core_path, probe.script)
|
|
391
|
+
try:
|
|
392
|
+
stat = script.stat()
|
|
393
|
+
digest.update(f"{probe.name}:{stat.st_mtime_ns}:{stat.st_size}".encode("utf-8"))
|
|
394
|
+
except OSError:
|
|
395
|
+
digest.update(f"{probe.name}:missing".encode("utf-8"))
|
|
396
|
+
return digest.hexdigest()
|
|
397
|
+
|
|
398
|
+
|
|
399
|
+
def _host_cache_key(core_path: Path, probes: list[ProbeDescriptor]) -> str:
|
|
400
|
+
"""基于引擎脚本指纹的宿主探针缓存键(独立于临时目录路径),用于跨沙箱复用。"""
|
|
401
|
+
digest = hashlib.sha256(b"host_probe_profile_v1")
|
|
402
|
+
_registry_digest_part(digest, core_path)
|
|
403
|
+
for probe in probes:
|
|
404
|
+
script = _resolve_probe_script(core_path, probe.script)
|
|
405
|
+
try:
|
|
406
|
+
stat = script.stat()
|
|
407
|
+
digest.update(f"{probe.name}:{stat.st_mtime_ns}:{stat.st_size}".encode("utf-8"))
|
|
408
|
+
except OSError:
|
|
409
|
+
digest.update(f"{probe.name}:missing".encode("utf-8"))
|
|
410
|
+
return digest.hexdigest()
|
|
411
|
+
|
|
412
|
+
|
|
413
|
+
import tempfile
|
|
414
|
+
|
|
415
|
+
|
|
416
|
+
def _global_cache_path(key: str) -> Path:
|
|
417
|
+
return Path(tempfile.gettempdir()) / f"bugx-probe-profile-{key[:16]}.json"
|
|
418
|
+
|
|
419
|
+
|
|
420
|
+
def _cached_profile(
|
|
421
|
+
root: Path,
|
|
422
|
+
key: str,
|
|
423
|
+
host_key: str | None = None,
|
|
424
|
+
*,
|
|
425
|
+
allow_project_cache: bool = True,
|
|
426
|
+
) -> dict[str, Any] | None:
|
|
427
|
+
path = root / ".bugx" / "state" / "environment-profile.json"
|
|
428
|
+
root_resolved = str(root.resolve())
|
|
429
|
+
|
|
430
|
+
def same_project(payload: Mapping[str, Any]) -> bool:
|
|
431
|
+
origin = payload.get("project_root")
|
|
432
|
+
if not isinstance(origin, str) or not origin.strip():
|
|
433
|
+
return False
|
|
434
|
+
try:
|
|
435
|
+
return str(Path(origin).resolve()) == root_resolved
|
|
436
|
+
except (OSError, RuntimeError):
|
|
437
|
+
return False
|
|
438
|
+
|
|
439
|
+
def fresh(payload: Mapping[str, Any]) -> bool:
|
|
440
|
+
try:
|
|
441
|
+
generated = float(payload.get("generated_at", 0))
|
|
442
|
+
except (OverflowError, TypeError, ValueError):
|
|
443
|
+
return False
|
|
444
|
+
age = time.time() - generated
|
|
445
|
+
return (
|
|
446
|
+
payload.get("schema_version") == 1
|
|
447
|
+
and math.isfinite(generated)
|
|
448
|
+
and 0 <= age <= _PROFILE_CACHE_SECONDS
|
|
449
|
+
)
|
|
450
|
+
|
|
451
|
+
try:
|
|
452
|
+
if path.is_file():
|
|
453
|
+
payload = json.loads(path.read_text(encoding="utf-8"))
|
|
454
|
+
if isinstance(payload, dict) and fresh(payload):
|
|
455
|
+
project_match = (
|
|
456
|
+
allow_project_cache
|
|
457
|
+
and same_project(payload)
|
|
458
|
+
and payload.get("cache_key") == key
|
|
459
|
+
)
|
|
460
|
+
host_match = host_key is not None and payload.get("host_cache_key") == host_key
|
|
461
|
+
if project_match or host_match:
|
|
462
|
+
return {
|
|
463
|
+
**payload,
|
|
464
|
+
"project_root": str(root),
|
|
465
|
+
"cached": True,
|
|
466
|
+
"_cache_match": "project" if project_match else "host",
|
|
467
|
+
}
|
|
468
|
+
# 跨测试沙箱降级:检查系统全局画像缓存
|
|
469
|
+
candidate_keys = [(key, "project")] if allow_project_cache else []
|
|
470
|
+
if host_key:
|
|
471
|
+
candidate_keys.append((host_key, "host"))
|
|
472
|
+
for candidate_key, match_kind in candidate_keys:
|
|
473
|
+
global_path = _global_cache_path(candidate_key)
|
|
474
|
+
if global_path.is_file():
|
|
475
|
+
payload = json.loads(global_path.read_text(encoding="utf-8"))
|
|
476
|
+
if not isinstance(payload, dict) or not fresh(payload):
|
|
477
|
+
continue
|
|
478
|
+
if match_kind == "project":
|
|
479
|
+
valid = same_project(payload) and payload.get("cache_key") == key
|
|
480
|
+
else:
|
|
481
|
+
valid = host_key is not None and payload.get("host_cache_key") == host_key
|
|
482
|
+
if valid:
|
|
483
|
+
return {
|
|
484
|
+
**payload,
|
|
485
|
+
"project_root": str(root),
|
|
486
|
+
"cached": True,
|
|
487
|
+
"_cache_match": match_kind,
|
|
488
|
+
}
|
|
489
|
+
except (OSError, RuntimeError, UnicodeError, ValueError, TypeError, json.JSONDecodeError):
|
|
490
|
+
return None
|
|
491
|
+
return None
|
|
492
|
+
|
|
493
|
+
|
|
494
|
+
def _cached_probe_is_reusable(name: str, report: Mapping[str, Any]) -> bool:
|
|
495
|
+
"""判定缓存的探针报告能否复用(跳过本次重探)。
|
|
496
|
+
|
|
497
|
+
F-RSI-20261118-005 深层语义:``BLOCKED``/``DEGRADED`` 是**环境时刻相关**
|
|
498
|
+
的失败结论——宿主环境恢复(如模拟器启动)后,30 分钟 TTL 内的缓存自锁
|
|
499
|
+
会让恢复不可见(真机实证:模拟器就绪后 pre 仍连续阻断)。因此失败/降级
|
|
500
|
+
结论一律不可复用(每次重查,成本仅几秒);只有 ``READY``/``NOT_APPLICABLE``
|
|
501
|
+
/``ABSENT`` 才进入 30 分钟复用窗口。Codebase Memory 额外校验版本 pin:
|
|
502
|
+
其就绪依赖可替换的外部可执行文件,缓存的成功必须证明当前精确 pin。
|
|
503
|
+
"""
|
|
504
|
+
status = str(report.get("status", "")).upper()
|
|
505
|
+
if status in {"BLOCKED", "DEGRADED"}:
|
|
506
|
+
return False
|
|
507
|
+
if status not in {"READY", "NOT_APPLICABLE", "ABSENT"}:
|
|
508
|
+
return False
|
|
509
|
+
if name != "codebase-memory":
|
|
510
|
+
return True
|
|
511
|
+
if status != "READY":
|
|
512
|
+
return False
|
|
513
|
+
|
|
514
|
+
raw = report.get("raw")
|
|
515
|
+
raw_checks = raw.get("checks") if isinstance(raw, dict) else None
|
|
516
|
+
if not isinstance(raw_checks, list):
|
|
517
|
+
return False
|
|
518
|
+
by_name = {
|
|
519
|
+
check.get("name"): check
|
|
520
|
+
for check in raw_checks
|
|
521
|
+
if isinstance(check, dict)
|
|
522
|
+
}
|
|
523
|
+
binary_check = by_name.get("binary")
|
|
524
|
+
supported_check = by_name.get("supported_version")
|
|
525
|
+
version_check = by_name.get("validated_version")
|
|
526
|
+
if not isinstance(binary_check, dict) or binary_check.get("ok") is not True:
|
|
527
|
+
return False
|
|
528
|
+
if not isinstance(supported_check, dict) or supported_check.get("ok") is not True:
|
|
529
|
+
return False
|
|
530
|
+
if not isinstance(version_check, dict) or version_check.get("ok") is not True:
|
|
531
|
+
return False
|
|
532
|
+
binary_path = binary_check.get("detail")
|
|
533
|
+
if not isinstance(binary_path, str) or not binary_path.strip():
|
|
534
|
+
return False
|
|
535
|
+
|
|
536
|
+
try:
|
|
537
|
+
from . import codebase_memory_probe
|
|
538
|
+
|
|
539
|
+
expected_version = codebase_memory_probe._pinned_cli_version()
|
|
540
|
+
if not expected_version or supported_check.get("expected") != expected_version:
|
|
541
|
+
return False
|
|
542
|
+
if version_check.get("detail") != f"codebase-memory-mcp {expected_version}":
|
|
543
|
+
return False
|
|
544
|
+
current_binary = codebase_memory_probe.resolve_compatible_binary(
|
|
545
|
+
environment=normalized_tool_environment(),
|
|
546
|
+
expected_version=expected_version,
|
|
547
|
+
# The cache check validates only the cheap version response; a full
|
|
548
|
+
# project/index probe runs if this cannot prove the cached identity.
|
|
549
|
+
timeout_seconds=2.0,
|
|
550
|
+
)
|
|
551
|
+
except Exception:
|
|
552
|
+
return False
|
|
553
|
+
return current_binary == binary_path
|
|
554
|
+
|
|
555
|
+
|
|
556
|
+
def register_probe(descriptor: ProbeDescriptor) -> None:
|
|
557
|
+
"""动态注册或覆盖一个探针插件。"""
|
|
558
|
+
if not isinstance(descriptor, ProbeDescriptor):
|
|
559
|
+
raise TypeError("descriptor 必须是 ProbeDescriptor 实例")
|
|
560
|
+
_REGISTRY[descriptor.name] = descriptor
|
|
561
|
+
|
|
562
|
+
|
|
563
|
+
def get_probe(name: str) -> ProbeDescriptor | None:
|
|
564
|
+
"""根据别名获取探针描述符。"""
|
|
565
|
+
return _REGISTRY.get(name)
|
|
566
|
+
|
|
567
|
+
|
|
568
|
+
def list_probes() -> list[ProbeDescriptor]:
|
|
569
|
+
"""按优先级返回所有已注册的探针描述符列表。"""
|
|
570
|
+
return sorted(_REGISTRY.values(), key=lambda p: (p.priority, p.name))
|
|
571
|
+
|
|
572
|
+
|
|
573
|
+
def preflight_probes() -> list[ProbeDescriptor]:
|
|
574
|
+
"""返回所有声明为启动前预检 (preflight) 的探针描述符,按优先级升序。"""
|
|
575
|
+
return [p for p in list_probes() if p.lifecycle == "preflight"]
|
|
576
|
+
|
|
577
|
+
|
|
578
|
+
def runtime_probes() -> list[ProbeDescriptor]:
|
|
579
|
+
"""返回所有声明为运行期专项 (runtime) 的探针描述符,按优先级升序。"""
|
|
580
|
+
return [p for p in list_probes() if p.lifecycle == "runtime"]
|
|
581
|
+
|
|
582
|
+
|
|
583
|
+
def probe_scripts_map() -> dict[str, str]:
|
|
584
|
+
"""返回探针名称到脚本文件的只读映射表。"""
|
|
585
|
+
return {p.name: p.script for p in _REGISTRY.values()}
|
|
586
|
+
|
|
587
|
+
|
|
588
|
+
def probes_without_root() -> set[str]:
|
|
589
|
+
"""返回不接受 --root 参数的探针集合。"""
|
|
590
|
+
return {p.name for p in _REGISTRY.values() if not p.accepts_root}
|
|
591
|
+
|
|
592
|
+
|
|
593
|
+
# 探针 checks 的字段别名:不同探针用不同字段名表达同一语义(例如
|
|
594
|
+
# web_conformance 用 rule_id/status/message,效率探针用 name/ok/detail)。
|
|
595
|
+
# 归一化必须把别名折叠成统一的 (name, ok, detail) 契约,否则下游
|
|
596
|
+
# extract_degraded_actions 会把「无 name 的多条检查」按探针名合并成一条、
|
|
597
|
+
# 并把有 message 却缺 detail 的真实原因误报为「探针未返回诊断信息」。
|
|
598
|
+
_CHECK_NAME_ALIASES: tuple[str, ...] = ("rule_id", "id", "check")
|
|
599
|
+
_CHECK_DETAIL_ALIASES: tuple[str, ...] = ("message", "summary", "description")
|
|
600
|
+
_CHECK_OK_STATUSES = frozenset({"PASS", "READY", "OK", "SUCCESS", "APPLICABLE", "DEFERRED"})
|
|
601
|
+
|
|
602
|
+
|
|
603
|
+
def normalize_check(check: Any) -> Any:
|
|
604
|
+
"""把单条探针 check 折叠为统一的 (name, ok, detail) 契约。
|
|
605
|
+
|
|
606
|
+
只补齐缺失的规范字段,绝不覆盖探针已给出的值,因此对标准 check 幂等;
|
|
607
|
+
探针原始字段(rule_id/oracle/status/message/evidence 等)原样保留。
|
|
608
|
+
"""
|
|
609
|
+
if not isinstance(check, dict):
|
|
610
|
+
return check
|
|
611
|
+
item = dict(check)
|
|
612
|
+
|
|
613
|
+
if not str(item.get("name") or "").strip():
|
|
614
|
+
for alias in _CHECK_NAME_ALIASES:
|
|
615
|
+
candidate = item.get(alias)
|
|
616
|
+
if isinstance(candidate, str) and candidate.strip():
|
|
617
|
+
item["name"] = candidate.strip()
|
|
618
|
+
break
|
|
619
|
+
|
|
620
|
+
if not isinstance(item.get("ok"), bool):
|
|
621
|
+
status = str(item.get("status") or "").strip().upper()
|
|
622
|
+
if status:
|
|
623
|
+
item["ok"] = status in _CHECK_OK_STATUSES
|
|
624
|
+
|
|
625
|
+
if not str(item.get("detail") or "").strip():
|
|
626
|
+
for alias in _CHECK_DETAIL_ALIASES:
|
|
627
|
+
candidate = item.get(alias)
|
|
628
|
+
if isinstance(candidate, str) and candidate.strip():
|
|
629
|
+
item["detail"] = candidate.strip()
|
|
630
|
+
break
|
|
631
|
+
|
|
632
|
+
return item
|
|
633
|
+
|
|
634
|
+
|
|
635
|
+
def normalize_checks(checks: Any) -> list[Any]:
|
|
636
|
+
"""对 checks 序列逐条归一化;None 安全降级为空列表。"""
|
|
637
|
+
if not isinstance(checks, (list, tuple)):
|
|
638
|
+
return [] if checks is None else [normalize_check(checks)]
|
|
639
|
+
return [normalize_check(check) for check in checks]
|
|
640
|
+
|
|
641
|
+
|
|
642
|
+
def extract_degraded_actions(report: dict[str, Any], *, probe_name: str = "") -> list[dict[str, Any]]:
|
|
643
|
+
"""从探针 JSON 报告提取降级项与对应处置选项。
|
|
644
|
+
|
|
645
|
+
detail 为空时的兜底文案与探针命令名/退出码附带都在这个 checks 聚合处
|
|
646
|
+
完成:探针自己说不出为什么失败时,降级项至少要能自证来源(哪条探针
|
|
647
|
+
命令、以什么退出码结束),而不是落成一句无信息量的占位文本。
|
|
648
|
+
|
|
649
|
+
DOC-236 C1 两条硬约束:
|
|
650
|
+
* ``NOT_APPLICABLE``/``DEFERRED`` 是**项目形态结论**,不是能力缺口,
|
|
651
|
+
必须剪枝为 0 个降级项——否则"项目没有原生代码"会被当成"环境缺工具"
|
|
652
|
+
顶到启动阻断通道上。
|
|
653
|
+
* ``transient`` 必须原样下传:二进制存在但本次调用超时与"未安装"是
|
|
654
|
+
两种不同的处置。
|
|
655
|
+
"""
|
|
656
|
+
actions: list[dict[str, Any]] = []
|
|
657
|
+
report_status = str(report.get("status", "")).strip().upper()
|
|
658
|
+
if report_status in {"NOT_APPLICABLE", "DEFERRED"}:
|
|
659
|
+
return actions
|
|
660
|
+
|
|
661
|
+
explicit_actions = report.get("degraded_actions")
|
|
662
|
+
if isinstance(explicit_actions, list) and explicit_actions:
|
|
663
|
+
return [dict(a) for a in explicit_actions if isinstance(a, dict)]
|
|
664
|
+
|
|
665
|
+
checks = normalize_checks(report.get("checks") or report.get("base_tools") or report.get("channels") or [])
|
|
666
|
+
eff_probe_name = "codebase-memory-mcp" if probe_name in {"codebase-memory", "codebase_memory_probe"} else probe_name
|
|
667
|
+
probe_command = str(report.get("name") or "").strip() or eff_probe_name
|
|
668
|
+
exit_code = report.get("returncode")
|
|
669
|
+
report_transient = report.get("transient") is True
|
|
670
|
+
provenance = ""
|
|
671
|
+
context: list[str] = []
|
|
672
|
+
if probe_command:
|
|
673
|
+
context.append(f"探针命令 {probe_command}")
|
|
674
|
+
if isinstance(exit_code, int) and not isinstance(exit_code, bool):
|
|
675
|
+
context.append(f"退出码 {exit_code}")
|
|
676
|
+
if context:
|
|
677
|
+
provenance = f"({','.join(context)})"
|
|
678
|
+
for check in checks:
|
|
679
|
+
if not isinstance(check, dict) or check.get("ok"):
|
|
680
|
+
continue
|
|
681
|
+
raw_name = check.get("name")
|
|
682
|
+
name = str(raw_name).strip() if raw_name is not None else ""
|
|
683
|
+
if not name:
|
|
684
|
+
name = eff_probe_name or "probe"
|
|
685
|
+
# DOC-226: 消除将未执行的浏览器动态测试规则误提取为工具安装动作
|
|
686
|
+
rule_id = str(check.get("rule_id", ""))
|
|
687
|
+
if name.startswith("dynamic.") or rule_id.startswith("dynamic.") or str(check.get("status", "")).upper() == "DEFERRED":
|
|
688
|
+
continue
|
|
689
|
+
detail = str(check.get("detail") or "").strip()
|
|
690
|
+
if not detail or detail == "探针未提供失败详情":
|
|
691
|
+
detail = "探针未返回诊断信息(probe 无 stderr/diagnostics 输出)"
|
|
692
|
+
if provenance:
|
|
693
|
+
detail = f"{detail}{provenance}"
|
|
694
|
+
is_mcp = (
|
|
695
|
+
"mcp" in name.casefold()
|
|
696
|
+
or "mcp" in eff_probe_name.casefold()
|
|
697
|
+
or "codebase-memory" in eff_probe_name.casefold()
|
|
698
|
+
)
|
|
699
|
+
display_name = (
|
|
700
|
+
f"{eff_probe_name}/{name}"
|
|
701
|
+
if is_mcp and "mcp" not in name.casefold() and eff_probe_name else name
|
|
702
|
+
)
|
|
703
|
+
is_required = check.get("required", report.get("required", True))
|
|
704
|
+
item = {
|
|
705
|
+
"name": display_name,
|
|
706
|
+
"detail": detail,
|
|
707
|
+
"options": [
|
|
708
|
+
f"安装/升级:{report.get('install', '见项目文档')}",
|
|
709
|
+
"跳过:使用回退方案 " + str(report.get("fallback", "内置工具")),
|
|
710
|
+
],
|
|
711
|
+
"required": bool(is_required),
|
|
712
|
+
"advisory": not is_required,
|
|
713
|
+
"critical": bool(is_required),
|
|
714
|
+
}
|
|
715
|
+
if is_mcp:
|
|
716
|
+
item["kind"] = "mcp"
|
|
717
|
+
if report_transient or check.get("transient") is True:
|
|
718
|
+
item["transient"] = True
|
|
719
|
+
actions.append(item)
|
|
720
|
+
return actions
|
|
721
|
+
|
|
722
|
+
|
|
723
|
+
def _should_skip_platform_sub_report(
|
|
724
|
+
platform_name: str,
|
|
725
|
+
forms: set[str] | None,
|
|
726
|
+
languages: set[str] | None,
|
|
727
|
+
targets: set[str] | None = None,
|
|
728
|
+
frameworks: set[str] | None = None,
|
|
729
|
+
) -> bool:
|
|
730
|
+
"""DOC-200 / DOC-248: 精细化多维形态与目标平台守卫。"""
|
|
731
|
+
# 1. 宏观形态守卫:非移动端项目跳过 android 与 ios 硬件平台状态裁决
|
|
732
|
+
if forms is not None and "mobile" not in forms and platform_name in {"android", "ios", "apple"}:
|
|
733
|
+
return True
|
|
734
|
+
# 2. 目标架构与框架精准守卫:
|
|
735
|
+
# A. Android 平台:如果移动端项目中明确只有 iOS 目标或纯小程序 (无 Android 目标且无 Android 源码/清单特征),跳过 Android 硬件平台裁决
|
|
736
|
+
if platform_name == "android":
|
|
737
|
+
if targets is not None and targets and "android" not in targets:
|
|
738
|
+
return True
|
|
739
|
+
if frameworks is not None and "miniprogram" in frameworks and (not targets or "android" not in targets):
|
|
740
|
+
return True
|
|
741
|
+
# B. iOS/Apple 平台:如果移动端项目中明确只有 Android 目标或纯小程序 (无 iOS 目标且无 Xcode/iOS 源码),跳过 iOS 硬件平台裁决
|
|
742
|
+
if platform_name in {"ios", "apple"}:
|
|
743
|
+
if targets is not None and targets and not (targets & {"ios", "apple"}):
|
|
744
|
+
return True
|
|
745
|
+
if frameworks is not None and "miniprogram" in frameworks and not (targets and targets & {"ios", "apple"}):
|
|
746
|
+
return True
|
|
747
|
+
# 3. 技术栈形态对齐:非 JVM 项目跳过 jvm 状态裁决;非桌面GUI/Node项目跳过 electron 状态裁决
|
|
748
|
+
if languages and not any(l in languages for l in ("java", "kotlin", "scala", "groovy", "jvm")) and platform_name == "jvm":
|
|
749
|
+
return True
|
|
750
|
+
if (forms and "desktop_gui" not in forms) and (languages and not any(l in languages for l in ("javascript", "typescript", "electron", "node"))) and platform_name == "electron":
|
|
751
|
+
return True
|
|
752
|
+
return False
|
|
753
|
+
|
|
754
|
+
|
|
755
|
+
def _relax_preflight_dynamic_hardware_checks(
|
|
756
|
+
chk: dict[str, Any], platform_name: str
|
|
757
|
+
) -> dict[str, Any]:
|
|
758
|
+
"""预检阶段动态物理硬件通道容错放行:未连接真机/模拟器降级为建议性警告,不阻断静态审计。"""
|
|
759
|
+
p = str(platform_name or "").strip().casefold()
|
|
760
|
+
if p in {"android", "ios", "apple", "mobile"}:
|
|
761
|
+
cname = str(chk.get("name", "")).strip()
|
|
762
|
+
if any(kw in cname for kw in ("已连接真机", "真机/模拟器", "Simulator", "dumpsys", "Perfetto")):
|
|
763
|
+
if not chk.get("ok"):
|
|
764
|
+
relaxed = dict(chk)
|
|
765
|
+
relaxed["required"] = False
|
|
766
|
+
relaxed["advisory"] = True
|
|
767
|
+
return relaxed
|
|
768
|
+
return chk
|
|
769
|
+
|
|
770
|
+
|
|
771
|
+
def _detect_check_platform(chk: dict[str, Any], default_platform: str = "") -> str:
|
|
772
|
+
"""提取单项 check 所属的技术栈/硬件平台。"""
|
|
773
|
+
p = str(chk.get("platform") or chk.get("target") or default_platform or "").strip().casefold()
|
|
774
|
+
if p in {"android", "ios", "apple", "jvm", "electron"}:
|
|
775
|
+
return p
|
|
776
|
+
cname = str(chk.get("name") or "").casefold()
|
|
777
|
+
kind = str(chk.get("kind") or "").casefold()
|
|
778
|
+
if "android" in cname or "adb" in cname or kind == "adb" or "perfetto" in cname or "dumpsys" in cname:
|
|
779
|
+
return "android"
|
|
780
|
+
if "ios" in cname or "simulator" in cname or "simctl" in cname or kind == "simctl" or "xcode" in cname:
|
|
781
|
+
return "ios"
|
|
782
|
+
if "jvm" in cname or "java" in cname or "jcmd" in cname:
|
|
783
|
+
return "jvm"
|
|
784
|
+
if "electron" in cname:
|
|
785
|
+
return "electron"
|
|
786
|
+
return p
|
|
787
|
+
|
|
788
|
+
|
|
789
|
+
def _normalize_probe_report(
|
|
790
|
+
name: str,
|
|
791
|
+
payload: Any,
|
|
792
|
+
returncode: int = 0,
|
|
793
|
+
forms: set[str] | None = None,
|
|
794
|
+
languages: set[str] | None = None,
|
|
795
|
+
targets: set[str] | None = None,
|
|
796
|
+
frameworks: set[str] | None = None,
|
|
797
|
+
) -> dict[str, Any]:
|
|
798
|
+
"""将探针原始输出统一归一化为标准的 ProbeReport 单根字典结构。"""
|
|
799
|
+
p_name = "codebase-memory-mcp" if name in {"codebase-memory", "codebase_memory_probe"} else name
|
|
800
|
+
|
|
801
|
+
if payload is None or (returncode != 0 and not payload):
|
|
802
|
+
report_dict: dict[str, Any] = {
|
|
803
|
+
"name": name,
|
|
804
|
+
"status": "DEGRADED" if returncode != 0 else "BLOCKED",
|
|
805
|
+
"checks": [{"name": name, "ok": False, "detail": "探针输出异常或执行失败"}],
|
|
806
|
+
"capabilities": [],
|
|
807
|
+
"fallbacks": {},
|
|
808
|
+
"warnings": [f"探针 {name} 退出码 {returncode},未返回有效 JSON"],
|
|
809
|
+
"raw": payload,
|
|
810
|
+
"returncode": returncode,
|
|
811
|
+
}
|
|
812
|
+
report_dict["degraded_actions"] = extract_degraded_actions(report_dict, probe_name=p_name)
|
|
813
|
+
return report_dict
|
|
814
|
+
|
|
815
|
+
if isinstance(payload, list):
|
|
816
|
+
checks: list[dict[str, Any]] = []
|
|
817
|
+
warnings: list[str] = []
|
|
818
|
+
capabilities: list[str] = []
|
|
819
|
+
sub_statuses: list[str] = []
|
|
820
|
+
platforms: list[str] = []
|
|
821
|
+
for item in payload:
|
|
822
|
+
if isinstance(item, dict):
|
|
823
|
+
platform_name = str(item.get("platform", item.get("target", name))).casefold()
|
|
824
|
+
if _should_skip_platform_sub_report(platform_name, forms, languages, targets, frameworks):
|
|
825
|
+
continue
|
|
826
|
+
platforms.append(platform_name)
|
|
827
|
+
item_checks: list[dict[str, Any]] = []
|
|
828
|
+
for chk in item.get("checks", []):
|
|
829
|
+
if isinstance(chk, dict):
|
|
830
|
+
chk = normalize_check(chk)
|
|
831
|
+
chk = _relax_preflight_dynamic_hardware_checks(chk, platform_name)
|
|
832
|
+
item_checks.append(chk)
|
|
833
|
+
checks.append(chk)
|
|
834
|
+
if chk.get("ok"):
|
|
835
|
+
capabilities.append(f"{platform_name}:{chk.get('name', '')}")
|
|
836
|
+
if any(not c.get("ok") and c.get("required", True) for c in item_checks):
|
|
837
|
+
st = "BLOCKED"
|
|
838
|
+
elif any(not c.get("ok") for c in item_checks):
|
|
839
|
+
st = "DEGRADED"
|
|
840
|
+
else:
|
|
841
|
+
st = "READY"
|
|
842
|
+
sub_statuses.append(st)
|
|
843
|
+
warnings.extend(item.get("warnings", []))
|
|
844
|
+
if not sub_statuses:
|
|
845
|
+
status = "NOT_APPLICABLE"
|
|
846
|
+
checks = [{"name": name, "ok": True, "detail": "当前项目形态/目标免检", "required": False}]
|
|
847
|
+
elif any(s == "BLOCKED" for s in sub_statuses):
|
|
848
|
+
status = "BLOCKED"
|
|
849
|
+
elif any(s == "DEGRADED" for s in sub_statuses):
|
|
850
|
+
status = "DEGRADED"
|
|
851
|
+
else:
|
|
852
|
+
status = "READY"
|
|
853
|
+
report_dict = {
|
|
854
|
+
"name": name,
|
|
855
|
+
"status": status,
|
|
856
|
+
"platforms": platforms,
|
|
857
|
+
"checks": checks,
|
|
858
|
+
"capabilities": capabilities,
|
|
859
|
+
"fallbacks": {},
|
|
860
|
+
"warnings": warnings,
|
|
861
|
+
"reports": payload,
|
|
862
|
+
"raw": payload,
|
|
863
|
+
"returncode": returncode,
|
|
864
|
+
}
|
|
865
|
+
report_dict["degraded_actions"] = extract_degraded_actions(report_dict, probe_name=p_name)
|
|
866
|
+
return report_dict
|
|
867
|
+
|
|
868
|
+
if isinstance(payload, dict):
|
|
869
|
+
# DOC-226: web_conformance 预检阶段免检动态浏览器规则
|
|
870
|
+
if name == "web_conformance":
|
|
871
|
+
raw_checks = payload.get("checks") or []
|
|
872
|
+
normalized_checks = []
|
|
873
|
+
for chk in raw_checks:
|
|
874
|
+
if isinstance(chk, dict):
|
|
875
|
+
r_id = str(chk.get("rule_id", chk.get("name", "")))
|
|
876
|
+
st = str(chk.get("status", "")).upper()
|
|
877
|
+
msg = str(chk.get("message", chk.get("detail", "")))
|
|
878
|
+
if r_id.startswith("dynamic.") and (st in {"BLOCKED", "DEFERRED"} or "缺少浏览器动态证据" in msg):
|
|
879
|
+
chk_copy = dict(chk)
|
|
880
|
+
chk_copy["status"] = "DEFERRED"
|
|
881
|
+
chk_copy["ok"] = True
|
|
882
|
+
chk_copy["detail"] = f"动态规则运行期检验({r_id}),预检免检"
|
|
883
|
+
normalized_checks.append(chk_copy)
|
|
884
|
+
continue
|
|
885
|
+
normalized_checks.append(chk)
|
|
886
|
+
payload = dict(payload)
|
|
887
|
+
payload["checks"] = normalized_checks
|
|
888
|
+
statuses = [
|
|
889
|
+
str(c.get("status", "")).upper()
|
|
890
|
+
for c in normalized_checks
|
|
891
|
+
if isinstance(c, dict) and str(c.get("status", "")).upper() not in {"DEFERRED", "NOT_APPLICABLE"}
|
|
892
|
+
]
|
|
893
|
+
if payload.get("status") == "NOT_APPLICABLE":
|
|
894
|
+
pass
|
|
895
|
+
elif any(s == "FAIL" for s in statuses):
|
|
896
|
+
payload["status"] = "FAIL"
|
|
897
|
+
elif any(s == "BLOCKED" for s in statuses):
|
|
898
|
+
payload["status"] = "BLOCKED"
|
|
899
|
+
else:
|
|
900
|
+
payload["status"] = "READY"
|
|
901
|
+
|
|
902
|
+
raw_reports = payload.get("reports")
|
|
903
|
+
if isinstance(raw_reports, list):
|
|
904
|
+
filtered_sub_reports = [
|
|
905
|
+
r for r in raw_reports
|
|
906
|
+
if isinstance(r, dict)
|
|
907
|
+
and not _should_skip_platform_sub_report(
|
|
908
|
+
str(r.get("platform", r.get("target", ""))).casefold(),
|
|
909
|
+
forms, languages, targets, frameworks,
|
|
910
|
+
)
|
|
911
|
+
]
|
|
912
|
+
checks = []
|
|
913
|
+
warnings = []
|
|
914
|
+
capabilities = []
|
|
915
|
+
sub_statuses = []
|
|
916
|
+
platforms = []
|
|
917
|
+
for item in filtered_sub_reports:
|
|
918
|
+
pname = str(item.get("platform", item.get("target", name)))
|
|
919
|
+
platforms.append(pname)
|
|
920
|
+
item_checks = []
|
|
921
|
+
for chk in item.get("checks", []):
|
|
922
|
+
if isinstance(chk, dict):
|
|
923
|
+
chk = normalize_check(chk)
|
|
924
|
+
chk = _relax_preflight_dynamic_hardware_checks(chk, pname.casefold())
|
|
925
|
+
item_checks.append(chk)
|
|
926
|
+
checks.append(chk)
|
|
927
|
+
if chk.get("ok"):
|
|
928
|
+
capabilities.append(f"{pname}:{chk.get('name', '')}")
|
|
929
|
+
if any(not c.get("ok") and c.get("required", True) for c in item_checks):
|
|
930
|
+
st = "BLOCKED"
|
|
931
|
+
elif any(not c.get("ok") for c in item_checks):
|
|
932
|
+
st = "DEGRADED"
|
|
933
|
+
else:
|
|
934
|
+
st = "READY"
|
|
935
|
+
sub_statuses.append(st)
|
|
936
|
+
warnings.extend(item.get("warnings", []))
|
|
937
|
+
if not sub_statuses:
|
|
938
|
+
status = "NOT_APPLICABLE"
|
|
939
|
+
checks = [{"name": name, "ok": True, "detail": "当前项目形态/目标免检", "required": False}]
|
|
940
|
+
elif any(s == "BLOCKED" for s in sub_statuses):
|
|
941
|
+
status = "BLOCKED"
|
|
942
|
+
elif any(s == "DEGRADED" for s in sub_statuses):
|
|
943
|
+
status = "DEGRADED"
|
|
944
|
+
else:
|
|
945
|
+
status = "READY"
|
|
946
|
+
report_dict = dict(payload)
|
|
947
|
+
report_dict.update({
|
|
948
|
+
"name": name,
|
|
949
|
+
"status": status,
|
|
950
|
+
"platforms": platforms,
|
|
951
|
+
"checks": checks,
|
|
952
|
+
"capabilities": capabilities,
|
|
953
|
+
"warnings": warnings,
|
|
954
|
+
"reports": filtered_sub_reports,
|
|
955
|
+
"raw": payload,
|
|
956
|
+
"returncode": returncode,
|
|
957
|
+
})
|
|
958
|
+
report_dict["degraded_actions"] = extract_degraded_actions(report_dict, probe_name=p_name)
|
|
959
|
+
return report_dict
|
|
960
|
+
|
|
961
|
+
raw_status = str(payload.get("status", "READY" if returncode == 0 else "DEGRADED")).upper()
|
|
962
|
+
if raw_status == "PASS":
|
|
963
|
+
status = "READY"
|
|
964
|
+
elif raw_status == "NOT_APPLICABLE":
|
|
965
|
+
# Preserve the distinction between a probe that ran successfully
|
|
966
|
+
# and one intentionally skipped by a profile guard. DOC-200
|
|
967
|
+
# relies on this value for transparent coverage accounting.
|
|
968
|
+
status = "NOT_APPLICABLE"
|
|
969
|
+
else:
|
|
970
|
+
status = raw_status
|
|
971
|
+
raw_checks = normalize_checks(payload.get("checks") or payload.get("base_tools") or [])
|
|
972
|
+
checks = []
|
|
973
|
+
for chk in raw_checks:
|
|
974
|
+
if isinstance(chk, dict):
|
|
975
|
+
pname = _detect_check_platform(chk, default_platform=name)
|
|
976
|
+
if pname and _should_skip_platform_sub_report(pname, forms, languages, targets, frameworks):
|
|
977
|
+
continue
|
|
978
|
+
chk = _relax_preflight_dynamic_hardware_checks(chk, pname)
|
|
979
|
+
checks.append(chk)
|
|
980
|
+
if raw_status == "NOT_APPLICABLE":
|
|
981
|
+
status = "NOT_APPLICABLE"
|
|
982
|
+
elif raw_checks and not checks:
|
|
983
|
+
status = "NOT_APPLICABLE"
|
|
984
|
+
checks = [{"name": name, "ok": True, "detail": "当前项目形态/目标免检", "required": False}]
|
|
985
|
+
elif any(not c.get("ok") and c.get("required", True) for c in checks):
|
|
986
|
+
status = "BLOCKED"
|
|
987
|
+
elif any(not c.get("ok") for c in checks):
|
|
988
|
+
status = "DEGRADED"
|
|
989
|
+
elif checks:
|
|
990
|
+
status = "READY"
|
|
991
|
+
warnings = list(payload.get("warnings") or [])
|
|
992
|
+
fallbacks = dict(payload.get("fallbacks") or {})
|
|
993
|
+
if "fallback" in payload and "fallback" not in fallbacks:
|
|
994
|
+
fallbacks["default"] = str(payload["fallback"])
|
|
995
|
+
capabilities = list(payload.get("capabilities") or [])
|
|
996
|
+
for chk in checks:
|
|
997
|
+
if isinstance(chk, dict) and chk.get("ok"):
|
|
998
|
+
cname = str(chk.get("name", "")).strip()
|
|
999
|
+
if cname and cname not in capabilities:
|
|
1000
|
+
capabilities.append(cname)
|
|
1001
|
+
report_dict = dict(payload)
|
|
1002
|
+
report_dict.update({
|
|
1003
|
+
"name": name,
|
|
1004
|
+
"status": status,
|
|
1005
|
+
"checks": checks,
|
|
1006
|
+
"capabilities": capabilities,
|
|
1007
|
+
"fallbacks": fallbacks,
|
|
1008
|
+
"warnings": warnings,
|
|
1009
|
+
"raw": payload,
|
|
1010
|
+
"returncode": returncode,
|
|
1011
|
+
})
|
|
1012
|
+
if "degraded_actions" in report_dict and isinstance(report_dict["degraded_actions"], list):
|
|
1013
|
+
valid_actions = []
|
|
1014
|
+
for a in report_dict["degraded_actions"]:
|
|
1015
|
+
if isinstance(a, dict):
|
|
1016
|
+
pname = _detect_check_platform(a, default_platform=name)
|
|
1017
|
+
if pname and _should_skip_platform_sub_report(pname, forms, languages, targets, frameworks):
|
|
1018
|
+
continue
|
|
1019
|
+
if any(kw in str(a.get("name", "")) for kw in ("已连接真机", "真机/模拟器", "Simulator", "dumpsys", "Perfetto")):
|
|
1020
|
+
a_rel = dict(a)
|
|
1021
|
+
a_rel["critical"] = False
|
|
1022
|
+
a_rel["advisory"] = True
|
|
1023
|
+
valid_actions.append(a_rel)
|
|
1024
|
+
else:
|
|
1025
|
+
valid_actions.append(a)
|
|
1026
|
+
report_dict["degraded_actions"] = valid_actions
|
|
1027
|
+
report_dict["degraded_actions"] = extract_degraded_actions(report_dict, probe_name=p_name)
|
|
1028
|
+
return report_dict
|
|
1029
|
+
|
|
1030
|
+
return {
|
|
1031
|
+
"name": name,
|
|
1032
|
+
"status": "DEGRADED",
|
|
1033
|
+
"checks": [{"name": name, "ok": False, "detail": f"未知输出格式: {type(payload).__name__}"}],
|
|
1034
|
+
"capabilities": [],
|
|
1035
|
+
"fallbacks": {},
|
|
1036
|
+
"warnings": ["非标准输出"],
|
|
1037
|
+
"degraded_actions": [],
|
|
1038
|
+
"raw": payload,
|
|
1039
|
+
}
|
|
1040
|
+
|
|
1041
|
+
|
|
1042
|
+
def _run_single_probe(
|
|
1043
|
+
descriptor: ProbeDescriptor,
|
|
1044
|
+
root: Path,
|
|
1045
|
+
core_dir: Path,
|
|
1046
|
+
timeout: float,
|
|
1047
|
+
*,
|
|
1048
|
+
forms: set[str] | None = None,
|
|
1049
|
+
languages: set[str] | None = None,
|
|
1050
|
+
targets: set[str] | None = None,
|
|
1051
|
+
frameworks: set[str] | None = None,
|
|
1052
|
+
action_args: Sequence[str] | None = None,
|
|
1053
|
+
) -> tuple[str, dict[str, Any]]:
|
|
1054
|
+
script = _resolve_probe_script(core_dir, descriptor.script)
|
|
1055
|
+
if not script.is_file():
|
|
1056
|
+
return descriptor.name, _normalize_probe_report(
|
|
1057
|
+
descriptor.name,
|
|
1058
|
+
{"status": "DEGRADED", "checks": [{"name": descriptor.name, "ok": False, "detail": f"脚本缺失: {descriptor.script}"}]},
|
|
1059
|
+
returncode=1,
|
|
1060
|
+
forms=forms,
|
|
1061
|
+
languages=languages,
|
|
1062
|
+
targets=targets,
|
|
1063
|
+
frameworks=frameworks,
|
|
1064
|
+
)
|
|
1065
|
+
|
|
1066
|
+
cmd = [sys.executable, str(script), *(action_args or ("check",))]
|
|
1067
|
+
if descriptor.accepts_root:
|
|
1068
|
+
cmd.extend(["--root", str(root)])
|
|
1069
|
+
if descriptor.name == "web_conformance":
|
|
1070
|
+
cmd.append("--preflight")
|
|
1071
|
+
cmd.append("--json")
|
|
1072
|
+
|
|
1073
|
+
started = time.monotonic()
|
|
1074
|
+
try:
|
|
1075
|
+
environment = normalized_tool_environment()
|
|
1076
|
+
if descriptor.name == "codebase-memory":
|
|
1077
|
+
# Keep the probe's internal CLI deadline aligned with the outer
|
|
1078
|
+
# adaptive budget; otherwise the outer expansion would be fake.
|
|
1079
|
+
environment["BUGX_PROBE_TIMEOUT_CODEBASE_MEMORY"] = str(timeout)
|
|
1080
|
+
proc = subprocess.run(
|
|
1081
|
+
cmd,
|
|
1082
|
+
cwd=str(root),
|
|
1083
|
+
capture_output=True,
|
|
1084
|
+
text=True,
|
|
1085
|
+
timeout=timeout,
|
|
1086
|
+
env=environment,
|
|
1087
|
+
)
|
|
1088
|
+
stdout = proc.stdout.strip()
|
|
1089
|
+
payload = None
|
|
1090
|
+
if stdout:
|
|
1091
|
+
try:
|
|
1092
|
+
payload = json.loads(stdout)
|
|
1093
|
+
except json.JSONDecodeError:
|
|
1094
|
+
payload = None
|
|
1095
|
+
report = _normalize_probe_report(
|
|
1096
|
+
descriptor.name,
|
|
1097
|
+
payload,
|
|
1098
|
+
returncode=proc.returncode,
|
|
1099
|
+
forms=forms,
|
|
1100
|
+
languages=languages,
|
|
1101
|
+
targets=targets,
|
|
1102
|
+
frameworks=frameworks,
|
|
1103
|
+
)
|
|
1104
|
+
report["duration_seconds"] = round(time.monotonic() - started, 3)
|
|
1105
|
+
report["timeout_seconds"] = timeout
|
|
1106
|
+
return descriptor.name, report
|
|
1107
|
+
except subprocess.TimeoutExpired:
|
|
1108
|
+
report = _normalize_probe_report(
|
|
1109
|
+
descriptor.name,
|
|
1110
|
+
{"status": "DEGRADED", "transient": True, "checks": [{"name": descriptor.name, "ok": False, "detail": f"探针超时 (>{timeout}s)"}]},
|
|
1111
|
+
returncode=124,
|
|
1112
|
+
forms=forms,
|
|
1113
|
+
languages=languages,
|
|
1114
|
+
targets=targets,
|
|
1115
|
+
frameworks=frameworks,
|
|
1116
|
+
)
|
|
1117
|
+
report["duration_seconds"] = round(time.monotonic() - started, 3)
|
|
1118
|
+
report["timeout_seconds"] = timeout
|
|
1119
|
+
return descriptor.name, report
|
|
1120
|
+
except Exception as exc:
|
|
1121
|
+
report = _normalize_probe_report(
|
|
1122
|
+
descriptor.name,
|
|
1123
|
+
{"status": "DEGRADED", "checks": [{"name": descriptor.name, "ok": False, "detail": f"执行异常: {exc}"}]},
|
|
1124
|
+
returncode=1,
|
|
1125
|
+
forms=forms,
|
|
1126
|
+
languages=languages,
|
|
1127
|
+
targets=targets,
|
|
1128
|
+
frameworks=frameworks,
|
|
1129
|
+
)
|
|
1130
|
+
report["duration_seconds"] = round(time.monotonic() - started, 3)
|
|
1131
|
+
report["timeout_seconds"] = timeout
|
|
1132
|
+
return descriptor.name, report
|
|
1133
|
+
|
|
1134
|
+
|
|
1135
|
+
def run_probe_readiness(
|
|
1136
|
+
name: str,
|
|
1137
|
+
root: Path,
|
|
1138
|
+
*,
|
|
1139
|
+
core_dir: Path | None = None,
|
|
1140
|
+
forms: set[str] | None = None,
|
|
1141
|
+
languages: set[str] | None = None,
|
|
1142
|
+
targets: set[str] | None = None,
|
|
1143
|
+
frameworks: set[str] | None = None,
|
|
1144
|
+
) -> dict[str, Any]:
|
|
1145
|
+
"""Run the descriptor's bounded, target-safe availability action."""
|
|
1146
|
+
descriptor = get_probe(name)
|
|
1147
|
+
if descriptor is None:
|
|
1148
|
+
return _normalize_probe_report(
|
|
1149
|
+
name,
|
|
1150
|
+
{"status": "BLOCKED", "checks": [{
|
|
1151
|
+
"name": "descriptor", "ok": False,
|
|
1152
|
+
"detail": f"未注册的 BugX probe: {name}",
|
|
1153
|
+
}]},
|
|
1154
|
+
returncode=1,
|
|
1155
|
+
forms=forms,
|
|
1156
|
+
languages=languages,
|
|
1157
|
+
targets=targets,
|
|
1158
|
+
frameworks=frameworks,
|
|
1159
|
+
)
|
|
1160
|
+
if descriptor.lifecycle not in {"preflight", "runtime"}:
|
|
1161
|
+
return _normalize_probe_report(
|
|
1162
|
+
descriptor.name,
|
|
1163
|
+
{"status": "BLOCKED", "checks": [{
|
|
1164
|
+
"name": "lifecycle", "ok": False,
|
|
1165
|
+
"detail": f"probe lifecycle 无法执行就绪检查: {descriptor.lifecycle}",
|
|
1166
|
+
}]},
|
|
1167
|
+
returncode=1,
|
|
1168
|
+
forms=forms,
|
|
1169
|
+
languages=languages,
|
|
1170
|
+
targets=targets,
|
|
1171
|
+
frameworks=frameworks,
|
|
1172
|
+
)
|
|
1173
|
+
if not descriptor.readiness_args:
|
|
1174
|
+
return _normalize_probe_report(
|
|
1175
|
+
descriptor.name,
|
|
1176
|
+
{"status": "BLOCKED", "checks": [{
|
|
1177
|
+
"name": "readiness_action", "ok": False,
|
|
1178
|
+
"detail": "探针未声明目标安全的 availability action;拒绝隐式运行 check",
|
|
1179
|
+
}]},
|
|
1180
|
+
returncode=1,
|
|
1181
|
+
forms=forms,
|
|
1182
|
+
languages=languages,
|
|
1183
|
+
targets=targets,
|
|
1184
|
+
frameworks=frameworks,
|
|
1185
|
+
)
|
|
1186
|
+
action_args = descriptor.readiness_args
|
|
1187
|
+
_, report = _run_single_probe(
|
|
1188
|
+
descriptor,
|
|
1189
|
+
root.resolve(),
|
|
1190
|
+
(core_dir or Path(__file__).resolve().parent).resolve(),
|
|
1191
|
+
probe_timeout_budget(descriptor.name),
|
|
1192
|
+
forms=forms,
|
|
1193
|
+
languages=languages,
|
|
1194
|
+
targets=targets,
|
|
1195
|
+
frameworks=frameworks,
|
|
1196
|
+
action_args=action_args,
|
|
1197
|
+
)
|
|
1198
|
+
return report
|
|
1199
|
+
|
|
1200
|
+
|
|
1201
|
+
def _previous_probe_durations(root: Path) -> dict[str, float]:
|
|
1202
|
+
path = root / ".bugx" / "state" / "environment-profile.json"
|
|
1203
|
+
try:
|
|
1204
|
+
payload = json.loads(path.read_text(encoding="utf-8"))
|
|
1205
|
+
probes = payload.get("probes", {}) if isinstance(payload, dict) else {}
|
|
1206
|
+
return {
|
|
1207
|
+
str(name): float(report["duration_seconds"])
|
|
1208
|
+
for name, report in probes.items()
|
|
1209
|
+
if isinstance(report, dict)
|
|
1210
|
+
and _positive_timeout(report.get("duration_seconds")) is not None
|
|
1211
|
+
}
|
|
1212
|
+
except (OSError, UnicodeError, ValueError, TypeError, json.JSONDecodeError):
|
|
1213
|
+
return {}
|
|
1214
|
+
|
|
1215
|
+
|
|
1216
|
+
def _classify_degraded_actions(
|
|
1217
|
+
reports_by_name: Mapping[str, Any],
|
|
1218
|
+
descriptors: Sequence[ProbeDescriptor],
|
|
1219
|
+
) -> list[dict[str, Any]]:
|
|
1220
|
+
"""给每个降级项补上描述符级机器语义(advisory / critical / probe)。
|
|
1221
|
+
|
|
1222
|
+
DOC-236 C1:上层门禁必须能吃到**机器结论**,不能靠名字或文案猜测。
|
|
1223
|
+
|
|
1224
|
+
* 报告状态为 ``NOT_APPLICABLE``/``DEFERRED`` 一律剪枝——项目形态决定的
|
|
1225
|
+
"不适用"不是能力缺口,进入阻断通道就是假阻断。
|
|
1226
|
+
* ``required=False`` 的建议性探针 ⇒ ``advisory=True``:它的缺失按注册表
|
|
1227
|
+
策略不构成启动阻断,但保留条目与告警,绝不静默消失。
|
|
1228
|
+
* ``critical`` 直接取自描述符,覆盖上层 ``kind=mcp ⇒ critical`` 的猜测。
|
|
1229
|
+
* ``transient``(二进制存在但调用超时)原样保留,与"未安装"分开处置。
|
|
1230
|
+
"""
|
|
1231
|
+
by_name = {descriptor.name: descriptor for descriptor in descriptors}
|
|
1232
|
+
classified: list[dict[str, Any]] = []
|
|
1233
|
+
for name, report in reports_by_name.items():
|
|
1234
|
+
if not isinstance(report, dict):
|
|
1235
|
+
continue
|
|
1236
|
+
if str(report.get("status", "")).strip().upper() in {"NOT_APPLICABLE", "DEFERRED"}:
|
|
1237
|
+
continue
|
|
1238
|
+
descriptor = by_name.get(name)
|
|
1239
|
+
for raw in report.get("degraded_actions") or []:
|
|
1240
|
+
if not isinstance(raw, dict):
|
|
1241
|
+
continue
|
|
1242
|
+
item = dict(raw)
|
|
1243
|
+
if descriptor is not None:
|
|
1244
|
+
item["probe"] = descriptor.name
|
|
1245
|
+
if not descriptor.critical:
|
|
1246
|
+
item["critical"] = False
|
|
1247
|
+
elif "critical" not in item:
|
|
1248
|
+
item["critical"] = descriptor.critical
|
|
1249
|
+
if not descriptor.required:
|
|
1250
|
+
item["advisory"] = True
|
|
1251
|
+
elif "advisory" not in item or not item["advisory"]:
|
|
1252
|
+
item["advisory"] = not descriptor.required
|
|
1253
|
+
classified.append(item)
|
|
1254
|
+
return classified
|
|
1255
|
+
|
|
1256
|
+
|
|
1257
|
+
def _project_single_probe_report(
|
|
1258
|
+
name: str,
|
|
1259
|
+
rep: dict[str, Any],
|
|
1260
|
+
forms: set[str] | None,
|
|
1261
|
+
languages: set[str] | None,
|
|
1262
|
+
targets: set[str] | None = None,
|
|
1263
|
+
frameworks: set[str] | None = None,
|
|
1264
|
+
) -> dict[str, Any]:
|
|
1265
|
+
"""根据当前项目的形态 (forms/languages/targets/frameworks) 重新投影探针报告。"""
|
|
1266
|
+
# 1. 当前形态不适用时,直接投影为 NOT_APPLICABLE,彻底剪枝降级项与阻断
|
|
1267
|
+
if name == "mobile":
|
|
1268
|
+
is_pure_miniprogram = (
|
|
1269
|
+
frameworks is not None
|
|
1270
|
+
and "miniprogram" in frameworks
|
|
1271
|
+
and not (targets and targets & {"android", "ios", "apple"})
|
|
1272
|
+
)
|
|
1273
|
+
if (forms is not None and "mobile" not in forms) or is_pure_miniprogram:
|
|
1274
|
+
proj_rep = _normalize_probe_report(
|
|
1275
|
+
"mobile",
|
|
1276
|
+
{
|
|
1277
|
+
"status": "NOT_APPLICABLE",
|
|
1278
|
+
"detail": "当前项目非原生移动端形态(或为纯小程序),已自适应跳过原生驱动",
|
|
1279
|
+
"checks": [{"name": "mobile", "ok": True, "detail": "非原生移动端项目,免检"}],
|
|
1280
|
+
},
|
|
1281
|
+
returncode=0,
|
|
1282
|
+
forms=forms,
|
|
1283
|
+
languages=languages,
|
|
1284
|
+
targets=targets,
|
|
1285
|
+
frameworks=frameworks,
|
|
1286
|
+
)
|
|
1287
|
+
proj_rep["duration_seconds"] = rep.get("duration_seconds", 0.001)
|
|
1288
|
+
return proj_rep
|
|
1289
|
+
|
|
1290
|
+
if name == "web_conformance" and (forms is not None and "web" not in forms):
|
|
1291
|
+
proj_rep = _normalize_probe_report(
|
|
1292
|
+
"web_conformance",
|
|
1293
|
+
{
|
|
1294
|
+
"status": "NOT_APPLICABLE",
|
|
1295
|
+
"detail": "当前项目非 Web 视口形态,已自适应跳过",
|
|
1296
|
+
"checks": [{"name": "web_conformance", "ok": True, "detail": "非 Web 项目,免检"}],
|
|
1297
|
+
},
|
|
1298
|
+
returncode=0,
|
|
1299
|
+
forms=forms,
|
|
1300
|
+
languages=languages,
|
|
1301
|
+
targets=targets,
|
|
1302
|
+
frameworks=frameworks,
|
|
1303
|
+
)
|
|
1304
|
+
proj_rep["duration_seconds"] = rep.get("duration_seconds", 0.001)
|
|
1305
|
+
return proj_rep
|
|
1306
|
+
|
|
1307
|
+
# 2. 如果缓存中是免检状态,但当前项目形态需要该探针,返回失效标记触发实测
|
|
1308
|
+
if rep.get("status") == "NOT_APPLICABLE":
|
|
1309
|
+
if (name == "mobile" and forms is not None and "mobile" in forms) or (
|
|
1310
|
+
name == "web_conformance" and forms is not None and "web" in forms
|
|
1311
|
+
):
|
|
1312
|
+
return {"status": "STALE_NOT_APPLICABLE"}
|
|
1313
|
+
|
|
1314
|
+
# 3. 适用探针:使用原始输出重新走归一化与动态容错门禁
|
|
1315
|
+
payload = rep.get("raw", rep)
|
|
1316
|
+
returncode = rep.get("returncode", 0)
|
|
1317
|
+
proj_rep = _normalize_probe_report(
|
|
1318
|
+
name,
|
|
1319
|
+
payload,
|
|
1320
|
+
returncode=returncode,
|
|
1321
|
+
forms=forms,
|
|
1322
|
+
languages=languages,
|
|
1323
|
+
targets=targets,
|
|
1324
|
+
frameworks=frameworks,
|
|
1325
|
+
)
|
|
1326
|
+
proj_rep["duration_seconds"] = rep.get("duration_seconds", 0.001)
|
|
1327
|
+
if "timeout_seconds" in rep:
|
|
1328
|
+
proj_rep["timeout_seconds"] = rep["timeout_seconds"]
|
|
1329
|
+
return proj_rep
|
|
1330
|
+
|
|
1331
|
+
|
|
1332
|
+
def _synthesize_profile(
|
|
1333
|
+
root: Path,
|
|
1334
|
+
cache_key: str,
|
|
1335
|
+
host_key: str,
|
|
1336
|
+
reports_by_name: Mapping[str, dict[str, Any]],
|
|
1337
|
+
probes: Sequence[ProbeDescriptor],
|
|
1338
|
+
cached: bool = False,
|
|
1339
|
+
reused_ready_probes: Sequence[str] | None = None,
|
|
1340
|
+
rechecked_probes: Sequence[str] | None = None,
|
|
1341
|
+
) -> dict[str, Any]:
|
|
1342
|
+
all_capabilities: set[str] = set()
|
|
1343
|
+
statuses: list[str] = []
|
|
1344
|
+
|
|
1345
|
+
for name, rep in reports_by_name.items():
|
|
1346
|
+
if not isinstance(rep, dict):
|
|
1347
|
+
continue
|
|
1348
|
+
st = rep.get("status", "READY")
|
|
1349
|
+
statuses.append(st)
|
|
1350
|
+
for cap in rep.get("capabilities", []):
|
|
1351
|
+
all_capabilities.add(cap)
|
|
1352
|
+
|
|
1353
|
+
# DOC-236 C1:降级项必须携带**描述符级**机器语义,让上层门禁能区分
|
|
1354
|
+
# 「建议性探针」「critical 能力」和普通缺口,而不是靠名字/文案猜。
|
|
1355
|
+
all_degraded_actions = _classify_degraded_actions(reports_by_name, probes)
|
|
1356
|
+
|
|
1357
|
+
if any(s == "BLOCKED" for s in statuses):
|
|
1358
|
+
overall_status = "BLOCKED"
|
|
1359
|
+
elif any(s == "DEGRADED" for s in statuses):
|
|
1360
|
+
overall_status = "DEGRADED"
|
|
1361
|
+
else:
|
|
1362
|
+
overall_status = "READY"
|
|
1363
|
+
|
|
1364
|
+
blocked_probes = [
|
|
1365
|
+
{"name": name, "status": rep.get("status"), "checks": [c for c in rep.get("checks", []) if not c.get("ok", True)]}
|
|
1366
|
+
for name, rep in reports_by_name.items()
|
|
1367
|
+
if isinstance(rep, dict) and rep.get("status") in {"BLOCKED", "ERROR"}
|
|
1368
|
+
]
|
|
1369
|
+
escalation = None
|
|
1370
|
+
if overall_status == "BLOCKED":
|
|
1371
|
+
escalation = {
|
|
1372
|
+
"required": True,
|
|
1373
|
+
"failed_probes": blocked_probes,
|
|
1374
|
+
"suggested_llm_action": "diagnose_probe_blocker",
|
|
1375
|
+
"message": "系统级探针环境检测阻断,需唤醒 LLM 基于 failed_probes 进行定点根因排查",
|
|
1376
|
+
}
|
|
1377
|
+
|
|
1378
|
+
return {
|
|
1379
|
+
"schema_version": 1,
|
|
1380
|
+
"generated_at": time.time(),
|
|
1381
|
+
"overall_status": overall_status,
|
|
1382
|
+
"project_root": str(root),
|
|
1383
|
+
"cache_key": cache_key,
|
|
1384
|
+
"host_cache_key": host_key,
|
|
1385
|
+
"cached": cached,
|
|
1386
|
+
"capabilities": sorted(all_capabilities),
|
|
1387
|
+
"probes": dict(reports_by_name),
|
|
1388
|
+
"reused_ready_probes": sorted(reused_ready_probes or []),
|
|
1389
|
+
"rechecked_probes": sorted(rechecked_probes or []),
|
|
1390
|
+
"degraded_actions": all_degraded_actions,
|
|
1391
|
+
"escalation": escalation,
|
|
1392
|
+
}
|
|
1393
|
+
|
|
1394
|
+
|
|
1395
|
+
def run_preflight_probes(
|
|
1396
|
+
root: Path,
|
|
1397
|
+
timeout: float = 10.0,
|
|
1398
|
+
parallel: bool = True,
|
|
1399
|
+
core_dir: Path | None = None,
|
|
1400
|
+
save_profile: bool = True,
|
|
1401
|
+
refresh: bool = False,
|
|
1402
|
+
project_profile_data: Mapping[str, Any] | None = None,
|
|
1403
|
+
) -> dict[str, Any]:
|
|
1404
|
+
"""统一并发执行所有启动前预检探针并生成环境画像。"""
|
|
1405
|
+
import concurrent.futures
|
|
1406
|
+
import time
|
|
1407
|
+
import core.secure_atomic as secure_atomic
|
|
1408
|
+
|
|
1409
|
+
root = root.resolve()
|
|
1410
|
+
core_path = (core_dir or Path(__file__).resolve().parent).resolve()
|
|
1411
|
+
probes = preflight_probes()
|
|
1412
|
+
host_key = _host_cache_key(core_path, probes)
|
|
1413
|
+
|
|
1414
|
+
# DOC-200 / DOC-183 / DOC-226: 基于工程画像对形态与技术栈进行精准对齐与自适应剪枝
|
|
1415
|
+
project_forms: set[str] = set()
|
|
1416
|
+
project_languages: set[str] = set()
|
|
1417
|
+
project_targets: set[str] = set()
|
|
1418
|
+
project_frameworks: set[str] = set()
|
|
1419
|
+
project_fingerprint: str | None = None
|
|
1420
|
+
try:
|
|
1421
|
+
from core.runtime import project_profile
|
|
1422
|
+
profile = (
|
|
1423
|
+
project_profile_data
|
|
1424
|
+
if isinstance(project_profile_data, Mapping)
|
|
1425
|
+
else project_profile.detect_project_profile(root)
|
|
1426
|
+
)
|
|
1427
|
+
project_forms = set(profile.get("forms", []))
|
|
1428
|
+
project_languages = {str(lang).casefold() for lang in profile.get("languages", [])}
|
|
1429
|
+
project_targets = {str(t).casefold() for t in (profile.get("declared_targets") or [])}
|
|
1430
|
+
for bt in profile.get("build_targets") or []:
|
|
1431
|
+
if isinstance(bt, dict):
|
|
1432
|
+
for k in ("platform", "name"):
|
|
1433
|
+
val = bt.get(k)
|
|
1434
|
+
if isinstance(val, str) and val.strip():
|
|
1435
|
+
project_targets.add(val.strip().casefold())
|
|
1436
|
+
for t in profile.get("targets") or []:
|
|
1437
|
+
if isinstance(t, str):
|
|
1438
|
+
project_targets.add(t.casefold())
|
|
1439
|
+
project_frameworks = {str(f).casefold() for f in profile.get("frameworks", [])}
|
|
1440
|
+
source_fingerprint = profile.get("source_fingerprint")
|
|
1441
|
+
fingerprint_digest = (
|
|
1442
|
+
source_fingerprint[7:]
|
|
1443
|
+
if isinstance(source_fingerprint, str)
|
|
1444
|
+
and source_fingerprint.startswith("sha256:")
|
|
1445
|
+
and len(source_fingerprint) == 71
|
|
1446
|
+
else ""
|
|
1447
|
+
)
|
|
1448
|
+
profile_complete = (
|
|
1449
|
+
profile.get("status") in {"complete", "unknown"}
|
|
1450
|
+
and profile.get("scan_truncated") is not True
|
|
1451
|
+
)
|
|
1452
|
+
detector_version = profile.get("detector_version")
|
|
1453
|
+
if (
|
|
1454
|
+
profile_complete
|
|
1455
|
+
and isinstance(detector_version, str)
|
|
1456
|
+
and detector_version.strip()
|
|
1457
|
+
and len(fingerprint_digest) == 64
|
|
1458
|
+
and all(
|
|
1459
|
+
char in "0123456789abcdef" for char in fingerprint_digest
|
|
1460
|
+
)
|
|
1461
|
+
):
|
|
1462
|
+
project_fingerprint = f"{detector_version}:{source_fingerprint}"
|
|
1463
|
+
except Exception:
|
|
1464
|
+
pass
|
|
1465
|
+
cache_key = _profile_cache_key(
|
|
1466
|
+
root, core_path, probes, project_fingerprint=project_fingerprint,
|
|
1467
|
+
)
|
|
1468
|
+
|
|
1469
|
+
probes_to_run = probes
|
|
1470
|
+
cached_ready: dict[str, dict[str, Any]] = {}
|
|
1471
|
+
if save_profile and not refresh:
|
|
1472
|
+
cached = _cached_profile(
|
|
1473
|
+
root,
|
|
1474
|
+
cache_key,
|
|
1475
|
+
host_key=host_key,
|
|
1476
|
+
allow_project_cache=project_fingerprint is not None,
|
|
1477
|
+
)
|
|
1478
|
+
if cached is not None:
|
|
1479
|
+
cached_reports = cached.get("probes")
|
|
1480
|
+
if isinstance(cached_reports, dict):
|
|
1481
|
+
descriptors_by_name = {probe.name: probe for probe in probes}
|
|
1482
|
+
same_project_cache = cached.get("_cache_match") == "project"
|
|
1483
|
+
cached_ready = {
|
|
1484
|
+
name: _project_single_probe_report(
|
|
1485
|
+
name,
|
|
1486
|
+
report,
|
|
1487
|
+
forms=project_forms,
|
|
1488
|
+
languages=project_languages,
|
|
1489
|
+
targets=project_targets,
|
|
1490
|
+
frameworks=project_frameworks,
|
|
1491
|
+
)
|
|
1492
|
+
for name, report in cached_reports.items()
|
|
1493
|
+
if name in descriptors_by_name
|
|
1494
|
+
and (
|
|
1495
|
+
same_project_cache
|
|
1496
|
+
or descriptors_by_name[name].cache_scope == "host"
|
|
1497
|
+
)
|
|
1498
|
+
if isinstance(report, dict)
|
|
1499
|
+
and _cached_probe_is_reusable(name, report)
|
|
1500
|
+
}
|
|
1501
|
+
cached_ready = {
|
|
1502
|
+
name: report for name, report in cached_ready.items()
|
|
1503
|
+
if report.get("status") in {"READY", "NOT_APPLICABLE", "ABSENT", "BLOCKED", "DEGRADED"}
|
|
1504
|
+
}
|
|
1505
|
+
probes_to_run = [p for p in probes if p.name not in cached_ready]
|
|
1506
|
+
if not probes_to_run:
|
|
1507
|
+
synth = _synthesize_profile(
|
|
1508
|
+
root=root,
|
|
1509
|
+
cache_key=cache_key,
|
|
1510
|
+
host_key=host_key,
|
|
1511
|
+
reports_by_name=cached_ready,
|
|
1512
|
+
probes=probes,
|
|
1513
|
+
cached=True,
|
|
1514
|
+
reused_ready_probes=list(cached_ready.keys()),
|
|
1515
|
+
rechecked_probes=[],
|
|
1516
|
+
)
|
|
1517
|
+
if save_profile and not _is_engine_dir(root):
|
|
1518
|
+
try:
|
|
1519
|
+
state_dir = root / ".bugx" / "state"
|
|
1520
|
+
state_dir.mkdir(parents=True, exist_ok=True)
|
|
1521
|
+
secure_atomic.atomic_write_json(state_dir / "environment-profile.json", synth)
|
|
1522
|
+
except Exception:
|
|
1523
|
+
pass
|
|
1524
|
+
return synth
|
|
1525
|
+
|
|
1526
|
+
previous_durations = _previous_probe_durations(root)
|
|
1527
|
+
per_probe_timeout_by_name = {
|
|
1528
|
+
probe.name: probe_timeout_budget(probe.name, previous_durations.get(probe.name))
|
|
1529
|
+
for probe in probes_to_run
|
|
1530
|
+
}
|
|
1531
|
+
reports_by_name: dict[str, dict[str, Any]] = dict(cached_ready)
|
|
1532
|
+
|
|
1533
|
+
applicable_probes = []
|
|
1534
|
+
for probe in probes_to_run:
|
|
1535
|
+
if probe.name == "mobile":
|
|
1536
|
+
is_pure_miniprogram = (
|
|
1537
|
+
project_frameworks
|
|
1538
|
+
and "miniprogram" in project_frameworks
|
|
1539
|
+
and not (project_targets and project_targets & {"android", "ios", "apple"})
|
|
1540
|
+
)
|
|
1541
|
+
if "mobile" not in project_forms or is_pure_miniprogram:
|
|
1542
|
+
rep = _normalize_probe_report(
|
|
1543
|
+
"mobile",
|
|
1544
|
+
{
|
|
1545
|
+
"status": "NOT_APPLICABLE",
|
|
1546
|
+
"detail": "当前项目非原生移动端形态(或为纯小程序),已自适应跳过原生驱动",
|
|
1547
|
+
"checks": [{"name": "mobile", "ok": True, "detail": "非原生移动端项目,免检"}],
|
|
1548
|
+
},
|
|
1549
|
+
returncode=0,
|
|
1550
|
+
forms=project_forms,
|
|
1551
|
+
languages=project_languages,
|
|
1552
|
+
targets=project_targets,
|
|
1553
|
+
frameworks=project_frameworks,
|
|
1554
|
+
)
|
|
1555
|
+
rep["duration_seconds"] = 0.001
|
|
1556
|
+
reports_by_name["mobile"] = rep
|
|
1557
|
+
continue
|
|
1558
|
+
if probe.name == "web_conformance" and "web" not in project_forms:
|
|
1559
|
+
rep = _normalize_probe_report(
|
|
1560
|
+
"web_conformance",
|
|
1561
|
+
{
|
|
1562
|
+
"status": "NOT_APPLICABLE",
|
|
1563
|
+
"detail": "当前项目非 Web 视口形态,已自适应跳过",
|
|
1564
|
+
"checks": [{"name": "web_conformance", "ok": True, "detail": "非 Web 项目,免检"}],
|
|
1565
|
+
},
|
|
1566
|
+
returncode=0,
|
|
1567
|
+
forms=project_forms,
|
|
1568
|
+
languages=project_languages,
|
|
1569
|
+
targets=project_targets,
|
|
1570
|
+
frameworks=project_frameworks,
|
|
1571
|
+
)
|
|
1572
|
+
rep["duration_seconds"] = 0.001
|
|
1573
|
+
reports_by_name["web_conformance"] = rep
|
|
1574
|
+
continue
|
|
1575
|
+
applicable_probes.append(probe)
|
|
1576
|
+
probes_to_run = applicable_probes
|
|
1577
|
+
|
|
1578
|
+
if parallel and len(probes_to_run) > 1:
|
|
1579
|
+
max_workers = min(8, len(probes_to_run))
|
|
1580
|
+
with concurrent.futures.ThreadPoolExecutor(max_workers=max_workers) as executor:
|
|
1581
|
+
future_map = {
|
|
1582
|
+
executor.submit(
|
|
1583
|
+
_run_single_probe,
|
|
1584
|
+
p,
|
|
1585
|
+
root,
|
|
1586
|
+
core_path,
|
|
1587
|
+
per_probe_timeout_by_name[p.name],
|
|
1588
|
+
forms=project_forms,
|
|
1589
|
+
languages=project_languages,
|
|
1590
|
+
targets=project_targets,
|
|
1591
|
+
frameworks=project_frameworks,
|
|
1592
|
+
): p.name
|
|
1593
|
+
for p in probes_to_run
|
|
1594
|
+
}
|
|
1595
|
+
deadline = max(
|
|
1596
|
+
float(timeout) + 1.0,
|
|
1597
|
+
max(per_probe_timeout_by_name.values(), default=5.0) + 1.0,
|
|
1598
|
+
)
|
|
1599
|
+
done, not_done = concurrent.futures.wait(future_map.keys(), timeout=deadline)
|
|
1600
|
+
for fut in done:
|
|
1601
|
+
try:
|
|
1602
|
+
name, rep = fut.result()
|
|
1603
|
+
reports_by_name[name] = rep
|
|
1604
|
+
except Exception as exc:
|
|
1605
|
+
name = future_map[fut]
|
|
1606
|
+
reports_by_name[name] = _normalize_probe_report(
|
|
1607
|
+
name,
|
|
1608
|
+
{"status": "DEGRADED", "checks": [{"name": name, "ok": False, "detail": str(exc)}]},
|
|
1609
|
+
returncode=1,
|
|
1610
|
+
forms=project_forms,
|
|
1611
|
+
languages=project_languages,
|
|
1612
|
+
targets=project_targets,
|
|
1613
|
+
frameworks=project_frameworks,
|
|
1614
|
+
)
|
|
1615
|
+
for fut in not_done:
|
|
1616
|
+
name = future_map[fut]
|
|
1617
|
+
fut.cancel()
|
|
1618
|
+
reports_by_name[name] = _normalize_probe_report(
|
|
1619
|
+
name,
|
|
1620
|
+
{"status": "DEGRADED", "transient": True, "checks": [{"name": name, "ok": False, "detail": "总体超时被取消"}]},
|
|
1621
|
+
returncode=124,
|
|
1622
|
+
forms=project_forms,
|
|
1623
|
+
languages=project_languages,
|
|
1624
|
+
targets=project_targets,
|
|
1625
|
+
frameworks=project_frameworks,
|
|
1626
|
+
)
|
|
1627
|
+
else:
|
|
1628
|
+
for p in probes_to_run:
|
|
1629
|
+
name, rep = _run_single_probe(
|
|
1630
|
+
p,
|
|
1631
|
+
root,
|
|
1632
|
+
core_path,
|
|
1633
|
+
per_probe_timeout_by_name[p.name],
|
|
1634
|
+
forms=project_forms,
|
|
1635
|
+
languages=project_languages,
|
|
1636
|
+
targets=project_targets,
|
|
1637
|
+
frameworks=project_frameworks,
|
|
1638
|
+
)
|
|
1639
|
+
reports_by_name[name] = rep
|
|
1640
|
+
|
|
1641
|
+
profile = _synthesize_profile(
|
|
1642
|
+
root=root,
|
|
1643
|
+
cache_key=cache_key,
|
|
1644
|
+
host_key=host_key,
|
|
1645
|
+
reports_by_name=reports_by_name,
|
|
1646
|
+
probes=probes,
|
|
1647
|
+
cached=bool(cached_ready),
|
|
1648
|
+
reused_ready_probes=list(cached_ready.keys()),
|
|
1649
|
+
rechecked_probes=[p.name for p in probes_to_run],
|
|
1650
|
+
)
|
|
1651
|
+
|
|
1652
|
+
# 引擎目录不是项目根:把运行态缓存写进引擎包会被 engine-integrity.json
|
|
1653
|
+
# 冻结并随包分发(DOC-004)。此处只关闭落盘,返回值 profile 保持完整——
|
|
1654
|
+
# 调用方 supervisor_bridge.run_preflight_probes 依赖它。
|
|
1655
|
+
if save_profile and _is_engine_dir(root):
|
|
1656
|
+
save_profile = False
|
|
1657
|
+
|
|
1658
|
+
if save_profile:
|
|
1659
|
+
state_dir = root / ".bugx" / "state"
|
|
1660
|
+
try:
|
|
1661
|
+
state_dir.mkdir(parents=True, exist_ok=True)
|
|
1662
|
+
profile_path = state_dir / "environment-profile.json"
|
|
1663
|
+
secure_atomic.atomic_write_json(profile_path, profile)
|
|
1664
|
+
except Exception:
|
|
1665
|
+
pass
|
|
1666
|
+
try:
|
|
1667
|
+
secure_atomic.atomic_write_json(_global_cache_path(cache_key), profile)
|
|
1668
|
+
except Exception:
|
|
1669
|
+
pass
|
|
1670
|
+
try:
|
|
1671
|
+
# 合并 host 级探针缓存:保留已探测到的各领域真实工具输出,避免被特定项目的 NOT_APPLICABLE 冲掉
|
|
1672
|
+
global_host_path = _global_cache_path(host_key)
|
|
1673
|
+
merged_host_probes = dict(profile.get("probes", {}))
|
|
1674
|
+
if global_host_path.is_file():
|
|
1675
|
+
try:
|
|
1676
|
+
existing_host_profile = json.loads(global_host_path.read_text(encoding="utf-8"))
|
|
1677
|
+
if isinstance(existing_host_profile, dict):
|
|
1678
|
+
for p_name, p_rep in existing_host_profile.get("probes", {}).items():
|
|
1679
|
+
cur_rep = merged_host_probes.get(p_name)
|
|
1680
|
+
if (
|
|
1681
|
+
cur_rep is None
|
|
1682
|
+
or cur_rep.get("status") == "NOT_APPLICABLE"
|
|
1683
|
+
) and isinstance(p_rep, dict) and p_rep.get("status") != "NOT_APPLICABLE":
|
|
1684
|
+
merged_host_probes[p_name] = p_rep
|
|
1685
|
+
except Exception:
|
|
1686
|
+
pass
|
|
1687
|
+
host_profile_to_save = dict(profile)
|
|
1688
|
+
host_profile_to_save["probes"] = merged_host_probes
|
|
1689
|
+
secure_atomic.atomic_write_json(global_host_path, host_profile_to_save)
|
|
1690
|
+
except Exception:
|
|
1691
|
+
pass
|
|
1692
|
+
|
|
1693
|
+
return profile
|
|
1694
|
+
|
|
1695
|
+
|
|
1696
|
+
def is_available() -> tuple[bool, str]:
|
|
1697
|
+
"""降级契约:机械探活内置探针注册表完整性(零子进程、零探针执行)。
|
|
1698
|
+
|
|
1699
|
+
判定两条机械事实:注册表非空,且每个内置描述符声明的脚本文件真实存在。
|
|
1700
|
+
脚本缺失说明引擎安装损坏,调用方必须走 ``run_static_degraded`` 只输出
|
|
1701
|
+
静态注册表快照,禁止伪装探针执行就绪。
|
|
1702
|
+
"""
|
|
1703
|
+
if not _REGISTRY:
|
|
1704
|
+
return False, "探针注册表为空;没有可分发的探针"
|
|
1705
|
+
# 描述符 script 相对引擎根(core/)解析,复用与执行链相同的
|
|
1706
|
+
# _resolve_probe_script 候选规则,避免把「脚本已迁移」误报成「脚本缺失」。
|
|
1707
|
+
core_dir = Path(__file__).resolve().parent.parent
|
|
1708
|
+
missing = sorted(
|
|
1709
|
+
descriptor.script
|
|
1710
|
+
for descriptor in _REGISTRY.values()
|
|
1711
|
+
if not _resolve_probe_script(core_dir, descriptor.script).is_file()
|
|
1712
|
+
)
|
|
1713
|
+
if missing:
|
|
1714
|
+
return False, f"探针脚本缺失: {', '.join(missing)}"
|
|
1715
|
+
return True, f"{len(_REGISTRY)} 个内置探针脚本齐全"
|
|
1716
|
+
|
|
1717
|
+
|
|
1718
|
+
def run_static_degraded(name: str | None = None) -> dict[str, Any]:
|
|
1719
|
+
"""降级契约:不执行任何探针子进程,只输出注册表静态快照。
|
|
1720
|
+
|
|
1721
|
+
输出与成功路径(``run_probe_readiness`` / profile 合成的真实探针执行报告)
|
|
1722
|
+
字段级可区分:``status="degraded"`` + ``degraded=True`` + ``degraded_reason``,
|
|
1723
|
+
每个条目只含描述符元数据并显式声明 ``executed=False``,禁止把静态快照
|
|
1724
|
+
伪装成探针执行结果。
|
|
1725
|
+
"""
|
|
1726
|
+
available, availability_detail = is_available()
|
|
1727
|
+
probes = list_probes()
|
|
1728
|
+
if name:
|
|
1729
|
+
descriptor = get_probe(name)
|
|
1730
|
+
probes = [descriptor] if descriptor is not None else []
|
|
1731
|
+
unknown = descriptor is None
|
|
1732
|
+
else:
|
|
1733
|
+
unknown = False
|
|
1734
|
+
entries = [
|
|
1735
|
+
{
|
|
1736
|
+
"name": p.name,
|
|
1737
|
+
"script": p.script,
|
|
1738
|
+
"domain": p.domain,
|
|
1739
|
+
"lifecycle": p.lifecycle,
|
|
1740
|
+
"priority": p.priority,
|
|
1741
|
+
"accepts_root": p.accepts_root,
|
|
1742
|
+
"required": p.required,
|
|
1743
|
+
"critical": p.critical,
|
|
1744
|
+
"cache_scope": p.cache_scope,
|
|
1745
|
+
"readiness_action_declared": p.readiness_args is not None,
|
|
1746
|
+
"executed": False,
|
|
1747
|
+
}
|
|
1748
|
+
for p in probes
|
|
1749
|
+
]
|
|
1750
|
+
return {
|
|
1751
|
+
"schema_version": 1,
|
|
1752
|
+
"success": bool(entries) and not unknown,
|
|
1753
|
+
"status": "degraded",
|
|
1754
|
+
"degraded": True,
|
|
1755
|
+
"degraded_reason": (
|
|
1756
|
+
"unknown_probe" if unknown
|
|
1757
|
+
else "static_mode_forced" if available else "probe_registry_incomplete"
|
|
1758
|
+
),
|
|
1759
|
+
"probe_mode": "static_degraded",
|
|
1760
|
+
"registry_total": len(_REGISTRY),
|
|
1761
|
+
"count": len(entries),
|
|
1762
|
+
"entries": entries,
|
|
1763
|
+
"findings": [],
|
|
1764
|
+
"evidence": {"availability_detail": availability_detail},
|
|
1765
|
+
"metadata": {
|
|
1766
|
+
"degraded_mode": "registry_snapshot_only",
|
|
1767
|
+
"probe_execution_skipped": True,
|
|
1768
|
+
"fallback": "注册表不可用或探针执行被跳过时只提供描述符元数据;禁止据此判定环境就绪",
|
|
1769
|
+
},
|
|
1770
|
+
}
|