bugx-cli 0.1.0 → 0.1.2
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/README.md +193 -185
- package/core/README.md +2 -2
- package/core/agent/README.md +2 -1
- package/core/agent/agent_artifacts.py +8 -6
- package/core/agent/agent_eval.py +136 -54
- package/core/agent/agent_execution.py +218 -52
- package/core/agent/agent_orchestrator.py +14 -8
- package/core/agent/agent_targets.py +8 -2
- package/core/agent/feature_baseline.py +150 -0
- package/core/assets/README.md +3 -2
- 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-hero-en.svg +74 -0
- package/core/assets/bugx-hero-zh.svg +74 -0
- package/core/assets/bugx-social-preview.svg +71 -0
- package/core/assets/bugx-wechat-group.png +0 -0
- package/core/assets/codex.png +0 -0
- package/core/assets/dsh.png +0 -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 +2 -0
- package/core/audit_packs/pitfalls/auth_crypto.json +64 -0
- package/core/audit_packs/pitfalls/file_ssrf_cmd.json +64 -0
- package/core/audit_packs/pitfalls/go_backend.json +66 -0
- package/core/audit_packs/pitfalls/java_spring.json +64 -0
- package/core/audit_packs/pitfalls/js_ts_web.json +67 -0
- package/core/audit_packs/pitfalls/python_web.json +82 -0
- package/core/autonomous_cve/SPEC.md +1 -1
- package/core/autonomous_cve/attack_graph_store.py +152 -106
- package/core/autonomous_cve/behavior_graph.py +8 -2
- package/core/autonomous_cve/verifier.py +4 -1
- package/core/bugx.md +1 -1
- package/core/bugx_paths.py +43 -8
- package/core/cli-help.txt +66 -0
- package/core/cloud_sync/SPEC.md +1 -1
- package/core/cloud_sync/cloud_client.py +81 -11
- package/core/cloud_sync/cloud_onboard.py +42 -1
- package/core/cloud_sync/consent.py +33 -3
- package/core/cloud_sync/flywheel_client.py +186 -15
- package/core/cloud_sync/network_transport.py +24 -3
- package/core/cloud_sync/sensitive_filter.py +2 -2
- package/core/cloud_sync/sync_push.py +12 -10
- package/core/contracts/AGENT_GUIDE.md +6 -9
- package/core/contracts/README.md +2 -2
- package/core/contracts/bugx-runtime-contract.md +1 -1
- package/core/contracts/bugx-worker.md +1 -1
- package/core/contracts/engine_gap_contracts.py +86 -3
- package/core/coverage/coverage_discovery.py +599 -29
- package/core/coverage/coverage_evidence.py +47 -0
- package/core/coverage/coverage_forensics.py +9 -0
- package/core/coverage/coverage_validate.py +6 -1
- package/core/dev_harness/SPEC.md +1 -1
- package/core/engine-integrity.json +670 -442
- package/core/fuzzing/concurrency_fuzzer.py +53 -0
- package/core/fuzzing/differential_oracle.py +562 -27
- package/core/fuzzing/fuzz_input.py +109 -6
- package/core/fuzzing/stateful_fuzzer.py +72 -0
- package/core/governance/secret_redactor.py +22 -10
- package/core/host_acp/SPEC.md +1 -1
- package/core/host_acp/__init__.py +4 -4
- package/core/host_acp/claude.py +59 -1
- package/core/host_acp/cline.py +64 -1
- package/core/host_acp/codex.py +56 -1
- package/core/host_acp/dsh.py +59 -1
- package/core/host_acp/opencode.py +56 -1
- package/core/host_acp/pi.py +59 -1
- package/core/host_acp/zcode.py +59 -1
- package/core/host_runtime/SPEC.md +1 -1
- package/core/host_runtime/adapters.py +1 -1
- package/core/host_runtime/cline.py +13 -0
- package/core/host_runtime/host_evaluators.py +44 -4
- package/core/host_runtime/host_probe.py +1 -1
- package/core/host_runtime/host_provider_arbitrator.py +116 -62
- package/core/host_runtime/host_registry.py +15 -8
- package/core/host_runtime/mcp_registry_gate.py +12 -1
- package/core/host_runtime/pi.py +102 -0
- package/core/host_runtime/provider_facts.py +66 -0
- package/core/hosts/SPEC.md +1 -1
- package/core/hosts/__init__.py +6 -2
- package/core/hosts/_dsh_usage.py +1 -1
- package/core/hosts/base.py +32 -4
- package/core/hosts/claude.py +55 -0
- package/core/hosts/cline.py +6 -2
- package/core/hosts/codex.py +58 -0
- package/core/hosts/dsh.py +9 -1
- package/core/hosts/opencode.py +6 -6
- package/core/hosts/pi.py +159 -2
- package/core/infra/README.md +4 -2
- package/core/infra/__init__.py +2 -0
- package/core/infra/build_info.py +22 -3
- package/core/infra/client_metadata.py +1 -1
- package/core/infra/json_utils.py +22 -0
- package/core/launch_phases/README.md +6 -3
- package/core/launch_phases/SPEC.md +1 -1
- package/core/launch_phases/common.py +21 -2
- package/core/launch_phases/finding_confirm_phase.py +170 -5
- package/core/launch_phases/finding_settlement.py +188 -1
- package/core/launch_phases/judge_phase.py +69 -12
- package/core/launch_phases/orchestrator_controls.py +11 -7
- package/core/launch_phases/post_coverage_sync.py +9 -2
- package/core/launch_phases/post_phase.py +144 -8
- package/core/launch_phases/post_receipt.py +12 -1
- package/core/launch_phases/pre_phase.py +3 -3
- package/core/launch_phases/pre_recon_scout.py +66 -36
- package/core/launch_phases/pre_state_builder.py +23 -176
- package/core/launch_phases/report_sharing.py +3 -7
- package/core/launch_phases/round_orchestrator.py +129 -58
- package/core/launch_phases/semantic_recon.py +545 -0
- package/core/launch_phases/session_runtime.py +56 -9
- package/core/launch_phases/startup_gates.py +36 -8
- package/core/launch_phases/startup_interaction.py +68 -12
- package/core/launch_phases/startup_version_gate.py +13 -3
- package/core/launch_phases/supervisor_bridge.py +46 -17
- package/core/launch_phases/supervisor_coverage.py +8 -2
- package/core/launch_phases/supervisor_degraded.py +1 -9
- package/core/launch_phases/verify_loop.py +767 -0
- package/core/launch_phases/worker_barriers.py +15 -5
- package/core/launch_phases/worker_orchestrator.py +105 -25
- package/core/launch_phases/worker_prior.py +115 -0
- package/core/ledger/README.md +2 -1
- package/core/ledger/SPEC.md +1 -1
- package/core/ledger/_facade.py +2 -1
- package/core/ledger/archive_ops.py +60 -2
- package/core/ledger/cli.py +6 -1
- package/core/ledger/export_ops.py +6 -1
- package/core/ledger/finding_confirmation.py +48 -6
- package/core/ledger/finding_lifecycle.py +428 -5
- package/core/ledger/finding_verification.py +555 -10
- package/core/ledger/fp_ledger.py +255 -0
- package/core/ledger/incidents.py +10 -4
- package/core/ledger/patterns.py +10 -7
- package/core/ledger/receipt_contract.py +17 -1
- package/core/ledger/sync_ops.py +21 -16
- package/core/ledger/tool_experience.py +2 -1
- package/core/ledger/verify_life.py +88 -17
- package/core/locales/en-US.json +2 -2
- package/core/locales/zh-CN.json +2 -2
- package/core/mcp_handlers/SPEC.md +1 -1
- package/core/mcp_handlers/base.py +23 -3
- package/core/mcp_handlers/channel_lifecycle.py +85 -30
- package/core/mcp_handlers/retrieval_handlers.py +11 -1
- package/core/mcp_handlers/rpc_server.py +6 -1
- package/core/mcp_handlers/supervisor_handlers.py +32 -6
- package/core/mcp_handlers/tool_table.py +15 -0
- package/core/mcp_runtime_support/environment.py +0 -38
- package/core/mcp_runtime_support/verifier.py +0 -52
- package/core/metadata.txt +2 -3
- package/core/planning/README.md +2 -1
- package/core/planning/domain_router.py +4 -2
- package/core/planning/dynamic_flow_analyzer.py +219 -14
- package/core/planning/judge_pipeline.py +87 -4
- package/core/planning/prompt_harness.py +57 -15
- package/core/planning/prompt_policy_engine.py +386 -0
- package/core/planning/spec_harvester.py +4 -4
- package/core/probes/INTERFACE.md +11 -1
- package/core/probes/SPEC.md +11 -1
- package/core/probes/__init__.py +46 -40
- package/core/probes/android_probe.py +177 -9
- package/core/probes/codebase_memory_probe.py +57 -0
- package/core/probes/desktop_probe.py +104 -0
- package/core/probes/differential_probe.py +99 -21
- package/core/probes/efficiency_probe.py +64 -0
- package/core/probes/ios_binary_probe.py +105 -1
- package/core/probes/memory_probe.py +66 -0
- package/core/probes/miniprogram_probe.py +75 -13
- package/core/probes/mobile_probe.py +215 -30
- package/core/probes/native_probe.py +88 -0
- package/core/probes/openwiki_probe.py +70 -0
- package/core/probes/pattern_probe.py +106 -0
- package/core/probes/platform_probe.py +81 -0
- package/core/probes/probe_registry.py +108 -7
- package/core/probes/sast_fixture_corpus.py +340 -0
- package/core/probes/sast_probe.py +553 -52
- package/core/probes/sast_rules.py +668 -28
- package/core/probes/sca_scanner.py +48 -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 +373 -18
- package/core/project_profiler/SPEC.md +1 -1
- package/core/project_profiler/arbitrator.py +6 -1
- package/core/project_profiler/detector.py +8 -1
- package/core/project_profiler/strategy.py +51 -15
- package/core/prompts/README.md +4 -2
- package/core/prompts/command_routing_en.md +2 -2
- package/core/prompts/command_routing_zh.md +2 -2
- package/core/prompts/policies/prompt_policies.json +101 -0
- package/core/prompts/stages/stage_repair.md +1 -1
- package/core/prompts/stages/stage_verify.defensive.md +42 -0
- package/core/prompts/stages/stage_verify.md +44 -0
- package/core/repair/README.md +1 -1
- package/core/repair/l7_repair_loop.py +1 -4
- package/core/repair/rsi_fixer.py +4 -4
- package/core/repair/rsi_loop.py +1 -3
- package/core/repair/rsi_repair.py +7 -7
- package/core/repair/rsi_scope.py +27 -8
- package/core/report_engine/SPEC.md +1 -1
- package/core/report_engine/attestation.py +8 -4
- package/core/report_engine/finding_report.py +2 -1
- package/core/report_engine/models.py +7 -9
- package/core/report_engine/report_share.py +0 -8
- package/core/report_engine/sast_bridge.py +2 -2
- package/core/report_engine/server.py +18 -8
- package/core/report_engine/web-conformance.md +123 -18
- package/core/report_engine/web_conformance.py +21 -52
- package/core/retrieval/README.md +2 -1
- package/core/retrieval/SPEC.md +1 -1
- package/core/retrieval/code_analyzer.py +50 -14
- package/core/retrieval/context_assembler.py +7 -1
- package/core/retrieval/knowledge_sync.py +108 -14
- package/core/retrieval/pitfall_packs.py +277 -0
- package/core/retrieval/symbol_index.py +25 -6
- package/core/retrieval/universal_code_matcher.py +234 -49
- package/core/runtime/README.md +1 -1
- package/core/runtime/bugx_logging.py +78 -7
- package/core/runtime/fixture_solidify.py +5 -10
- package/core/runtime/global_telemetry.py +20 -0
- package/core/runtime/incident_eval.py +1 -1
- package/core/runtime/model_runner.py +4 -41
- package/core/runtime/platform_adapter.py +2 -2
- package/core/runtime/prep_validate.py +4 -2
- package/core/runtime/project_settings.py +2 -1
- package/core/runtime/scenario_eval.py +50 -8
- package/core/skills/bugx_docs_mcp_server.py +3 -1
- package/core/skills/bugx_mcp_server.py +29 -2
- package/core/skills/tools_kb.py +1 -1
- package/core/supervisor/README.md +1 -1
- package/core/supervisor/SPEC.md +1 -1
- package/core/supervisor/budget_governor.py +503 -9
- package/core/supervisor/checkpoint_pipeline.py +248 -6
- package/core/supervisor/checkpoint_sync.py +13 -0
- package/core/supervisor/claim_events.py +1 -1
- package/core/supervisor/finding_workflow.py +22 -5
- package/core/supervisor/lease_manager.py +1 -1
- package/core/supervisor/lifecycle_blocks.py +6 -1
- package/core/supervisor/rejection_remedies.py +52 -5
- package/core/supervisor/serial_authorization.py +48 -4
- package/core/supervisor/task_scheduler.py +2 -2
- package/core/supervisor/worker_checkpoint.py +8 -1
- package/core/supervisor/worker_runtime.py +8 -2
- package/core/supervisor_types/worker_claim.py +9 -0
- package/core/webui/README.md +1 -1
- package/core/webui/SPEC.md +2 -1
- package/core/webui/adapters/claude.py +5 -1
- package/core/webui/adapters/cline.py +10 -2
- package/core/webui/adapters/codex.py +5 -1
- package/core/webui/adapters/dsh.py +5 -1
- package/core/webui/docs_session_service.py +2 -2
- package/core/webui/mcp_inspector.py +11 -7
- 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/design-tokens.css +113 -0
- package/core/webui/static/index.html +14 -1
- package/core/webui/workspace_service.py +1 -1
- package/docs/07_distribution/01_README_NPM.md +193 -185
- package/ecosystem/integrations/README.md +1 -1
- package/ecosystem/integrations/dsh/mcp/package.json +1 -1
- package/ecosystem/integrations/dsh/skills/bugx-dsh/SKILL.md +1 -1
- package/ecosystem/integrations/dsh/ui/package.json +1 -1
- package/ecosystem/integrations/opencode/bugx-mcp-manifest.json +4 -4
- package/ecosystem/integrations/opencode/mcp-lock.json +14 -6
- package/ecosystem/integrations/opencode/opencode.json +23 -12
- package/ecosystem/integrations/pi/extensions/bugx/manifest.json +1 -1
- package/ecosystem/integrations/qoder/connector-meta.json +1 -1
- package/ecosystem/integrations/workbuddy/connector-meta.json +1 -1
- package/ecosystem/integrations/workbuddy/skills/bugx/SKILL.md +1 -1
- package/ecosystem/plugins/bugx/.claude-plugin/plugin.json +1 -1
- package/ecosystem/plugins/bugx/.codex-plugin/plugin.json +1 -1
- package/ecosystem/plugins/bugx/.zcode-plugin/plugin.json +1 -1
- package/ecosystem/plugins/bugx/skills/bugx/SKILL.md +2 -2
- package/ecosystem/plugins/bugx/skills/bugx-dsh/SKILL.md +1 -1
- package/ecosystem/plugins/bugx/skills/bugx-opencode/SKILL.md +1 -1
- package/ecosystem/plugins/bugx/skills/bugx-zcode/SKILL.md +1 -1
- package/interfaces/bin/bugx.js +37 -0
- package/interfaces/cli/bugx_cli/__init__.py +4 -2
- package/interfaces/cli/bugx_cli/cli.py +172 -69
- package/interfaces/cli/bugx_cli/commands/advisory.py +1 -1
- package/interfaces/cli/bugx_cli/commands/agent.py +461 -134
- package/interfaces/cli/bugx_cli/commands/audit.py +10 -9
- package/interfaces/cli/bugx_cli/commands/autonomous.py +1 -1
- package/interfaces/cli/bugx_cli/commands/cloud.py +31 -22
- package/interfaces/cli/bugx_cli/commands/doctor.py +449 -204
- package/interfaces/cli/bugx_cli/commands/interaction.py +5 -1
- package/interfaces/cli/bugx_cli/commands/knowledge.py +5 -4
- package/interfaces/cli/bugx_cli/commands/lifecycle.py +3 -3
- package/interfaces/cli/bugx_cli/commands/plugin.py +58 -23
- package/interfaces/cli/bugx_cli/commands/plugin_claude.py +7 -7
- package/interfaces/cli/bugx_cli/commands/plugin_funide.py +2 -1
- package/interfaces/cli/bugx_cli/commands/plugin_zcode.py +1 -1
- package/interfaces/cli/bugx_cli/commands/project.py +6 -13
- package/interfaces/cli/bugx_cli/commands/report.py +2 -6
- package/interfaces/cli/bugx_cli/commands/system.py +524 -169
- package/interfaces/cli/bugx_cli/common.py +21 -15
- package/interfaces/cli/bugx_cli/host_adapters.py +29 -54
- package/interfaces/cli/bugx_cli/hosts/registry.py +8 -6
- package/interfaces/cli/bugx_cli/infra/ai_advisor.py +157 -27
- package/interfaces/cli/bugx_cli/infra/engine_installer.py +35 -16
- package/interfaces/cli/bugx_cli/infra/host_sync.py +11 -8
- package/interfaces/cli/bugx_cli/infra/mcp_advisor.py +76 -5
- package/interfaces/cli/bugx_cli/infra/security.py +13 -6
- package/package.json +30 -15
- package/pyproject.toml +60 -9
- package/scripts/ensure-python.mjs +7 -7
- package/scripts/sync-version.mjs +10 -21
- package/scripts/test-npm-wrapper.mjs +1 -1
- package/core/assets/bugx-hero-cn.png +0 -0
- package/core/assets/bugx-hero-en.png +0 -0
- package/core/webui/static/project-settings.css +0 -6458
- package/docs/07_distribution/README.md +0 -16
- package/docs/README.md +0 -121
- package/interfaces/README.md +0 -143
- package/interfaces/bin/README.md +0 -35
- package/interfaces/cli/README.md +0 -90
- package/scripts/README.md +0 -118
|
@@ -70,23 +70,43 @@ def _run(args: list[str], timeout: float = 10.0) -> subprocess.CompletedProcess[
|
|
|
70
70
|
return subprocess.CompletedProcess(args, 1, stdout="", stderr=str(exc))
|
|
71
71
|
|
|
72
72
|
|
|
73
|
-
def _version(cmd: list[str]) -> str:
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
73
|
+
def _version(cmd: list[str], *, timeout: float = 10.0) -> str:
|
|
74
|
+
"""读取工具版本首行;``timeout`` 用于 JVM 类工具(maestro ~7.5s 冷启动)。
|
|
75
|
+
|
|
76
|
+
超时早退:``--version`` 超时说明是进程启动级问题,换 ``-version`` 变体
|
|
77
|
+
只会把同一冷启动再烧一遍预算(实测 2s+2s 双倍溢出)——超时后直接返回
|
|
78
|
+
空串,由调用方按「存在性已验证、版本未取到」处置。
|
|
79
|
+
"""
|
|
80
|
+
result = _run([*cmd, "--version"], timeout=timeout)
|
|
81
|
+
timed_out = bool(result and "timed out" in (result.stderr or ""))
|
|
82
|
+
if result and result.returncode != 0 and not timed_out:
|
|
83
|
+
result = _run([*cmd, "-version"], timeout=timeout)
|
|
84
|
+
if not result or timed_out:
|
|
78
85
|
return ""
|
|
79
86
|
output = (result.stdout or result.stderr or "").strip().splitlines()
|
|
80
87
|
return output[0] if output else ""
|
|
81
88
|
|
|
82
89
|
|
|
83
|
-
def _check_tool(
|
|
90
|
+
def _check_tool(
|
|
91
|
+
name: str, version_args: list[str], *, version_timeout: float = 10.0,
|
|
92
|
+
) -> dict:
|
|
93
|
+
"""探测工具存在性与版本。
|
|
94
|
+
|
|
95
|
+
通道判据是**存在性**(which 命中),版本探测只是详情增强:JVM 类工具
|
|
96
|
+
(maestro)``--version`` 冷启动实测 ~7.5s,在 pre 的 5s 探针预算下会把
|
|
97
|
+
整条 mobile 探针拖成 BLOCKED 并触发安装决策阻断(F-RSI-20261118-004
|
|
98
|
+
实证)。版本探测超时不再把工具判成不可用——存在性已验证,detail 注明
|
|
99
|
+
版本读取超时。
|
|
100
|
+
"""
|
|
84
101
|
path = _which(name)
|
|
85
102
|
if not path:
|
|
86
103
|
return {"name": name, "ok": False, "path": None, "version": None, "detail": "未安装"}
|
|
87
|
-
version = _version([path, *version_args])
|
|
88
|
-
|
|
89
|
-
|
|
104
|
+
version = _version([path, *version_args], timeout=version_timeout)
|
|
105
|
+
if version:
|
|
106
|
+
return {"name": name, "ok": True, "path": path, "version": version,
|
|
107
|
+
"detail": version}
|
|
108
|
+
return {"name": name, "ok": True, "path": path, "version": None,
|
|
109
|
+
"detail": f"已安装({path};版本读取超时/失败,存在性已验证)"}
|
|
90
110
|
|
|
91
111
|
|
|
92
112
|
from core.runtime.platform_adapter import parse_adb_devices, parse_booted_simulators
|
|
@@ -118,19 +138,69 @@ def _ios_tier1(xcrun: str) -> dict:
|
|
|
118
138
|
}
|
|
119
139
|
|
|
120
140
|
|
|
141
|
+
#: 移动形态标记(与 core/project_profiler detector 同口径的文件名集合,
|
|
142
|
+
#: casefold 比较;profiler 判据为扫描树内任意层级的同名文件)。
|
|
143
|
+
_MOBILE_MARKER_FILES = frozenset({
|
|
144
|
+
"androidmanifest.xml", "build.gradle", "build.gradle.kts",
|
|
145
|
+
"gradlew", "info.plist", "podfile", "pubspec.yaml", "project.pbxproj",
|
|
146
|
+
})
|
|
147
|
+
#: 目录形态标记(Xcode 工程 / 工作区 / IPA 产物)。
|
|
148
|
+
_MOBILE_MARKER_SUFFIXES = (".xcodeproj", ".xcworkspace", ".ipa")
|
|
149
|
+
#: 有界探测硬上限:AndroidManifest.xml 位于 app/src/main/ 时需 4 层,
|
|
150
|
+
#: 深度 5 覆盖典型 Gradle/Xcode 布局且绝不退化为全盘扫描。
|
|
151
|
+
_MOBILE_SCAN_MAX_DEPTH = 5
|
|
152
|
+
_MOBILE_SCAN_MAX_DIRS = 128
|
|
153
|
+
#: 探测时跳过的隐藏目录与依赖/构建产物目录(内部含海量 Info.plist 等噪声,
|
|
154
|
+
#: 跳过既保性能上界,也避免 vendor 树误判为移动项目)。
|
|
155
|
+
_MOBILE_SCAN_SKIP_DIRS = frozenset({
|
|
156
|
+
".git", ".bugx", ".gradle", ".idea", "__pycache__", "node_modules",
|
|
157
|
+
"build", "dist", "target", "vendor", "Pods", "DerivedData",
|
|
158
|
+
})
|
|
159
|
+
|
|
160
|
+
|
|
121
161
|
def _is_mobile_project(root: Path) -> bool:
|
|
122
|
-
"""检测当前目标项目是否为移动端应用形态(Android/iOS/Flutter/RN)。
|
|
162
|
+
"""检测当前目标项目是否为移动端应用形态(Android/iOS/Flutter/RN)。
|
|
163
|
+
|
|
164
|
+
与 core/project_profiler detector 同口径:根级标记或一级/多级子目录
|
|
165
|
+
递归探测(覆盖 android-sample/ + ios-sample/ 子目录形态仓库)。
|
|
166
|
+
性能有界:最大深度 ``_MOBILE_SCAN_MAX_DEPTH``、目录数上限
|
|
167
|
+
``_MOBILE_SCAN_MAX_DIRS``;跳过隐藏目录与依赖/构建产物目录,不跟随
|
|
168
|
+
symlink,禁止全盘扫描。
|
|
169
|
+
"""
|
|
123
170
|
try:
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
]
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
171
|
+
if not root.is_dir():
|
|
172
|
+
return False
|
|
173
|
+
scanned_dirs = 0
|
|
174
|
+
pending: list[tuple[Path, int]] = [(root, 0)]
|
|
175
|
+
while pending:
|
|
176
|
+
directory, depth = pending.pop()
|
|
177
|
+
scanned_dirs += 1
|
|
178
|
+
if scanned_dirs > _MOBILE_SCAN_MAX_DIRS:
|
|
179
|
+
return False
|
|
180
|
+
try:
|
|
181
|
+
entries = sorted(directory.iterdir())
|
|
182
|
+
except OSError:
|
|
183
|
+
continue
|
|
184
|
+
subdirs: list[Path] = []
|
|
185
|
+
for entry in entries:
|
|
186
|
+
try:
|
|
187
|
+
if entry.is_symlink():
|
|
188
|
+
continue
|
|
189
|
+
if entry.is_dir():
|
|
190
|
+
name_lower = entry.name.casefold()
|
|
191
|
+
if entry.name.startswith(".") or name_lower in _MOBILE_SCAN_SKIP_DIRS:
|
|
192
|
+
continue
|
|
193
|
+
if name_lower.endswith(_MOBILE_MARKER_SUFFIXES):
|
|
194
|
+
return True
|
|
195
|
+
subdirs.append(entry)
|
|
196
|
+
elif entry.is_file():
|
|
197
|
+
name_lower = entry.name.casefold()
|
|
198
|
+
if name_lower in _MOBILE_MARKER_FILES or name_lower.endswith(_MOBILE_MARKER_SUFFIXES):
|
|
199
|
+
return True
|
|
200
|
+
except OSError:
|
|
201
|
+
continue
|
|
202
|
+
if depth < _MOBILE_SCAN_MAX_DEPTH:
|
|
203
|
+
pending.extend((sub, depth + 1) for sub in subdirs)
|
|
134
204
|
except OSError:
|
|
135
205
|
pass
|
|
136
206
|
return False
|
|
@@ -156,8 +226,16 @@ def inspect(root: Path) -> dict:
|
|
|
156
226
|
ios_t1 = _ios_tier1(xcrun_path) if xcrun_path else {"tier": 1, "kind": "simctl", "ok": False, "devices": [], "detail": "xcrun 未安装"}
|
|
157
227
|
channels.append({"name": "iOS Simctl (Tier 1)", "platform": "ios", "tier": 1, **ios_t1})
|
|
158
228
|
|
|
159
|
-
# Tier 2
|
|
160
|
-
|
|
229
|
+
# Tier 2/3 并行探测(F-RSI-20261118-004):maestro 是 JVM 工具,冷启动
|
|
230
|
+
# ``--version`` 实测 ~7.5s;串行探测必然超 pre 探针预算。两者并行 + 版本
|
|
231
|
+
# 探测 2s 硬顶(存在性已由 which 验证,超时只丢版本详情不丢通道)。
|
|
232
|
+
import concurrent.futures as _futures
|
|
233
|
+
|
|
234
|
+
with _futures.ThreadPoolExecutor(max_workers=2) as pool:
|
|
235
|
+
maestro_f = pool.submit(_check_tool, "maestro", ["--version"], version_timeout=2.0)
|
|
236
|
+
appium_f = pool.submit(_check_tool, "appium", ["--version"], version_timeout=2.0)
|
|
237
|
+
maestro_info = maestro_f.result()
|
|
238
|
+
appium_info = appium_f.result()
|
|
161
239
|
channels.append({
|
|
162
240
|
"name": "Maestro CLI (Tier 2)",
|
|
163
241
|
"platform": "cross",
|
|
@@ -169,7 +247,6 @@ def inspect(root: Path) -> dict:
|
|
|
169
247
|
})
|
|
170
248
|
|
|
171
249
|
# Tier 3: Appium REST
|
|
172
|
-
appium_info = _check_tool("appium", ["--version"])
|
|
173
250
|
channels.append({
|
|
174
251
|
"name": "Appium REST (Tier 3)",
|
|
175
252
|
"platform": "cross",
|
|
@@ -196,8 +273,16 @@ def inspect(root: Path) -> dict:
|
|
|
196
273
|
"appium": "npm install -g appium",
|
|
197
274
|
}
|
|
198
275
|
|
|
276
|
+
# F-RSI-20261118-005:critical 按「Tier1 是否全灭」判定,而非项目级
|
|
277
|
+
# required 一刀切。双形态仓库(android+ios 样本)中,任一 Tier1 平台通道
|
|
278
|
+
# 就绪即已覆盖黑盒动态面,其余平台通道未就绪(如 macOS 无 iOS runtime 时
|
|
279
|
+
# iOS Simctl 永不可就绪)降为 advisory——静态探针(sast/android_probe/
|
|
280
|
+
# ios_binary)对未就绪平台仍可完整行使。全灭才 critical(此时确无任何
|
|
281
|
+
# 动态验证能力)。
|
|
282
|
+
tier1_ready = any(c["tier"] == 1 and c["ok"] for c in channels)
|
|
199
283
|
checks = []
|
|
200
284
|
for c in channels:
|
|
285
|
+
channel_critical = bool(required and not tier1_ready)
|
|
201
286
|
checks.append({
|
|
202
287
|
"name": c["name"],
|
|
203
288
|
"ok": c["ok"],
|
|
@@ -205,25 +290,33 @@ def inspect(root: Path) -> dict:
|
|
|
205
290
|
"kind": c["kind"],
|
|
206
291
|
"tier": c["tier"],
|
|
207
292
|
"required": required,
|
|
208
|
-
"critical":
|
|
293
|
+
"critical": channel_critical,
|
|
294
|
+
"advisory": bool(required and tier1_ready and not c["ok"]),
|
|
209
295
|
"install": install_map.get(c["kind"], "见项目文档"),
|
|
210
296
|
})
|
|
211
297
|
|
|
298
|
+
# 降级项在 ready 时也显式生成(标 advisory),避免 extract_degraded_actions
|
|
299
|
+
# 回落到 checks 聚合把 advisory 通道重新当成 critical 缺口。
|
|
212
300
|
degraded_actions = []
|
|
213
|
-
if
|
|
301
|
+
if True:
|
|
214
302
|
for c in channels:
|
|
215
303
|
if not c["ok"]:
|
|
216
304
|
cmd = install_map.get(c["kind"], "见项目文档")
|
|
305
|
+
channel_critical = bool(required and not tier1_ready)
|
|
306
|
+
if channel_critical:
|
|
307
|
+
detail_text = f"{c['detail']}(移动端黑盒自动化驱动通道缺失,全部 Tier1 均未就绪)"
|
|
308
|
+
else:
|
|
309
|
+
detail_text = f"{c['detail']}(该平台动态通道不可用;已有 Tier1 通道就绪,静态审计仍可行使)"
|
|
217
310
|
degraded_actions.append({
|
|
218
311
|
"name": f"mobile/{c['name']}",
|
|
219
|
-
"detail":
|
|
312
|
+
"detail": detail_text,
|
|
220
313
|
"options": [
|
|
221
314
|
f"安装/启动:{cmd}",
|
|
222
315
|
"明确豁免:使用 --allow-degraded 或配置 tooling_exemptions 放行降级",
|
|
223
316
|
],
|
|
224
317
|
"required": required,
|
|
225
|
-
"critical":
|
|
226
|
-
"advisory": not
|
|
318
|
+
"critical": channel_critical,
|
|
319
|
+
"advisory": bool(required and not channel_critical),
|
|
227
320
|
})
|
|
228
321
|
|
|
229
322
|
return {
|
|
@@ -242,15 +335,98 @@ def inspect(root: Path) -> dict:
|
|
|
242
335
|
}
|
|
243
336
|
|
|
244
337
|
|
|
338
|
+
def is_available() -> tuple[bool, str]:
|
|
339
|
+
"""降级契约:机械探测移动端 UI 自动化通道前置条件(<5ms,零阻塞、零子进程)。
|
|
340
|
+
|
|
341
|
+
仅做 PATH 工具存在性检查(adb/xcrun/maestro/appium 任一在 PATH 即具备
|
|
342
|
+
至少一条动态通道);不查询设备(设备查询属 inspect() 的慢路径)。
|
|
343
|
+
返回 (available, detail),detail 列出在场与缺失通道。
|
|
344
|
+
"""
|
|
345
|
+
channel_tools = ("adb", "xcrun", "maestro", "appium")
|
|
346
|
+
present = [name for name in channel_tools if _which(name)]
|
|
347
|
+
missing = [name for name in channel_tools if name not in present]
|
|
348
|
+
detail = (
|
|
349
|
+
f"可用通道工具: {', '.join(present)}"
|
|
350
|
+
if present
|
|
351
|
+
else "adb/xcrun/maestro/appium 均未安装:移动端黑盒动态通道全部不可用"
|
|
352
|
+
)
|
|
353
|
+
if missing:
|
|
354
|
+
detail += f";缺失: {', '.join(missing)}"
|
|
355
|
+
return bool(present), detail
|
|
356
|
+
|
|
357
|
+
|
|
358
|
+
def run_static_degraded(root: Path | str | None = None) -> dict:
|
|
359
|
+
"""降级路径:无任何动态通道时,仅做项目形态静态分析。
|
|
360
|
+
|
|
361
|
+
降级契约:输出与成功路径(inspect(),status=READY)**可区分**——
|
|
362
|
+
status="degraded" + degraded=True + degraded_reason,绝不伪造界面/设备证据;
|
|
363
|
+
设备可用性、UI 树等动态结论一律标注未执行。
|
|
364
|
+
"""
|
|
365
|
+
root_path = Path(root or Path.cwd()).resolve()
|
|
366
|
+
notes: list[str] = []
|
|
367
|
+
if not root_path.is_dir():
|
|
368
|
+
return {
|
|
369
|
+
"probe": "mobile",
|
|
370
|
+
"status": "degraded",
|
|
371
|
+
"degraded": True,
|
|
372
|
+
"degraded_reason": "target_root_not_found",
|
|
373
|
+
"success": False,
|
|
374
|
+
"root": str(root_path),
|
|
375
|
+
"findings": [],
|
|
376
|
+
"evidence": {},
|
|
377
|
+
"notes": [f"目标目录不存在: {root_path}"],
|
|
378
|
+
"checks_not_run": ["adb-devices", "simctl-booted", "ui-automation"],
|
|
379
|
+
"install": {"adb": "brew install android-platform-tools", "xcrun": "xcode-select --install",
|
|
380
|
+
"maestro": "curl -FsSL https://get.maestro.mobile.dev | bash",
|
|
381
|
+
"appium": "npm install -g appium"},
|
|
382
|
+
}
|
|
383
|
+
is_mobile = _is_mobile_project(root_path)
|
|
384
|
+
available, availability_detail = is_available()
|
|
385
|
+
notes.append("降级模式:仅完成项目形态静态识别;设备/界面动态检查全部未执行,"
|
|
386
|
+
"禁止据此声称已完成移动端黑盒审计")
|
|
387
|
+
if not available:
|
|
388
|
+
notes.append(f"动态通道缺失:{availability_detail}")
|
|
389
|
+
return {
|
|
390
|
+
"probe": "mobile",
|
|
391
|
+
"status": "degraded",
|
|
392
|
+
"degraded": True,
|
|
393
|
+
"degraded_reason": (
|
|
394
|
+
"no_dynamic_channel_available" if not available else "static_mode_forced"
|
|
395
|
+
),
|
|
396
|
+
"success": True,
|
|
397
|
+
"root": str(root_path),
|
|
398
|
+
"findings": [],
|
|
399
|
+
"evidence": {
|
|
400
|
+
"is_mobile_project": is_mobile,
|
|
401
|
+
"dynamic_channels_available": available,
|
|
402
|
+
"availability_detail": availability_detail,
|
|
403
|
+
"mobile_markers_hint": (
|
|
404
|
+
"AndroidManifest.xml/build.gradle/gradlew/Info.plist/Podfile/"
|
|
405
|
+
"pubspec.yaml/project.pbxproj/*.xcodeproj(根级或子目录递归有界探测)"
|
|
406
|
+
if is_mobile else "未命中任何移动端项目标记"
|
|
407
|
+
),
|
|
408
|
+
},
|
|
409
|
+
"notes": notes,
|
|
410
|
+
"checks_not_run": ["adb-devices", "simctl-booted", "ui-automation"],
|
|
411
|
+
"install": {"adb": "brew install android-platform-tools", "xcrun": "xcode-select --install",
|
|
412
|
+
"maestro": "curl -FsSL https://get.maestro.mobile.dev | bash",
|
|
413
|
+
"appium": "npm install -g appium"},
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
|
|
245
417
|
def print_report(report: dict, as_json: bool = False) -> None:
|
|
246
418
|
if as_json:
|
|
247
419
|
print(json.dumps(report, ensure_ascii=False, indent=2))
|
|
248
420
|
return
|
|
249
421
|
print(f"[{report['status']}] 移动端 UI 驱动通道(最佳通道: Tier {report.get('best_tier') or 'N/A'})")
|
|
250
|
-
for channel in report
|
|
422
|
+
for channel in report.get("channels", []):
|
|
251
423
|
print(f" {'✓' if channel['ok'] else '!'} {channel['name']}: {channel['detail']}")
|
|
424
|
+
for note in report.get("notes", []):
|
|
425
|
+
print(f" · {note}")
|
|
252
426
|
if report["status"] != "READY":
|
|
253
|
-
print(f" → 回退:{report
|
|
427
|
+
print(f" → 回退:{report.get('fallback', '见 install 建议或 notes')}")
|
|
428
|
+
if report.get("degraded_reason"):
|
|
429
|
+
print(f" → 降级原因:{report['degraded_reason']}")
|
|
254
430
|
|
|
255
431
|
|
|
256
432
|
def main(argv: list[str] | None = None) -> int:
|
|
@@ -263,7 +439,16 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
263
439
|
"--allow-degraded", action="store_true",
|
|
264
440
|
help="明确允许使用回退方案;否则 DEGRADED 返回 2",
|
|
265
441
|
)
|
|
442
|
+
parser.add_argument(
|
|
443
|
+
"--static-degraded", action="store_true",
|
|
444
|
+
help="显式执行降级路径(仅项目形态静态识别;输出 status=degraded,"
|
|
445
|
+
"绝不伪造设备/界面证据)",
|
|
446
|
+
)
|
|
266
447
|
args = parser.parse_args(argv)
|
|
448
|
+
if args.static_degraded:
|
|
449
|
+
report = run_static_degraded(args.root)
|
|
450
|
+
print_report(report, args.json)
|
|
451
|
+
return 0
|
|
267
452
|
report = inspect(args.root)
|
|
268
453
|
print_report(report, args.json)
|
|
269
454
|
if report["status"] == "READY":
|
|
@@ -186,6 +186,86 @@ def native_report(root: Path | str | None = None) -> Report:
|
|
|
186
186
|
)
|
|
187
187
|
|
|
188
188
|
|
|
189
|
+
def is_available() -> tuple[bool, str]:
|
|
190
|
+
"""降级契约:机械探测原生审计前置条件(<5ms,零阻塞、零编译)。
|
|
191
|
+
|
|
192
|
+
编译器(clang/cc/gcc 任一在 PATH)是原生构建/插桩审计的必需前置;
|
|
193
|
+
缺失时 detail 明确给出降级路径。只查 PATH,不执行编译。
|
|
194
|
+
"""
|
|
195
|
+
for name in ("clang", "cc", "gcc"):
|
|
196
|
+
path = _which(name)
|
|
197
|
+
if path:
|
|
198
|
+
return True, f"编译器可用: {name}={path}"
|
|
199
|
+
return False, (
|
|
200
|
+
"未找到 clang/cc/gcc:原生构建、插桩(sanitizer)与行为证据全部不可得,"
|
|
201
|
+
"降级为 run_static_degraded(仅源码/构建标记静态识别)"
|
|
202
|
+
)
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
def run_static_degraded(root: Path | str | None = None) -> dict:
|
|
206
|
+
"""降级路径:无编译器环境时,仅做源码/构建标记静态识别。
|
|
207
|
+
|
|
208
|
+
降级契约:输出与成功路径(native_report,status=READY)**可区分**——
|
|
209
|
+
status="degraded" + degraded=True + degraded_reason + checks_not_run;
|
|
210
|
+
sanitizer/插桩能力一律标注未执行,禁止把静态推断写成运行验证。
|
|
211
|
+
"""
|
|
212
|
+
root_path = Path(root or Path.cwd())
|
|
213
|
+
if not root_path.is_dir():
|
|
214
|
+
return {
|
|
215
|
+
"platform": "native",
|
|
216
|
+
"status": "degraded",
|
|
217
|
+
"degraded": True,
|
|
218
|
+
"degraded_reason": "target_root_not_found",
|
|
219
|
+
"success": False,
|
|
220
|
+
"root": str(root_path),
|
|
221
|
+
"checks": [],
|
|
222
|
+
"warnings": [f"目标目录不存在: {root_path}"],
|
|
223
|
+
"checks_not_run": ["compile-probe", "sanitizer-support"],
|
|
224
|
+
}
|
|
225
|
+
sources, markers = _scan_sources(root_path)
|
|
226
|
+
toolchain = {name: _which(name) for name in TOOLCHAIN}
|
|
227
|
+
present = [name for name, path in toolchain.items() if path]
|
|
228
|
+
available, availability_detail = is_available()
|
|
229
|
+
warnings: list[str] = []
|
|
230
|
+
if not available:
|
|
231
|
+
warnings.append(
|
|
232
|
+
"无编译器:构建/插桩/行为证据均不可得,内存与并发结论只能静态推断、未运行验证"
|
|
233
|
+
)
|
|
234
|
+
warnings.append("降级模式:sanitizer 支持未做真实编译验证;禁止声称已覆盖运行时插桩")
|
|
235
|
+
return {
|
|
236
|
+
"platform": "native",
|
|
237
|
+
"status": "degraded",
|
|
238
|
+
"degraded": True,
|
|
239
|
+
"degraded_reason": (
|
|
240
|
+
"compiler_unavailable" if not available else "static_mode_forced"
|
|
241
|
+
),
|
|
242
|
+
"success": True,
|
|
243
|
+
"root": str(root_path),
|
|
244
|
+
"checks": [
|
|
245
|
+
{
|
|
246
|
+
"name": "原生工程识别",
|
|
247
|
+
"ok": sources > 0 or bool(markers),
|
|
248
|
+
"detail": f"原生源文件 {sources} 个;构建标记 {', '.join(markers) or '无'}",
|
|
249
|
+
"required": True,
|
|
250
|
+
},
|
|
251
|
+
{
|
|
252
|
+
"name": "工具链在场(仅 PATH 检测,未验证可用性)",
|
|
253
|
+
"ok": bool(present),
|
|
254
|
+
"detail": ", ".join(present) or "无",
|
|
255
|
+
"required": False,
|
|
256
|
+
},
|
|
257
|
+
],
|
|
258
|
+
"evidence": {
|
|
259
|
+
"native_sources": sources,
|
|
260
|
+
"build_markers": markers,
|
|
261
|
+
"toolchain_present": present,
|
|
262
|
+
"availability_detail": availability_detail,
|
|
263
|
+
},
|
|
264
|
+
"warnings": warnings,
|
|
265
|
+
"checks_not_run": ["compile-probe", "sanitizer-support"],
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
|
|
189
269
|
def print_report(report: Report, *, as_json: bool = False) -> None:
|
|
190
270
|
if as_json:
|
|
191
271
|
print(json.dumps(asdict(report), ensure_ascii=False, indent=2))
|
|
@@ -203,7 +283,15 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
203
283
|
parser.add_argument("command", choices=("check", "status"), nargs="?", default="check")
|
|
204
284
|
parser.add_argument("--root", type=Path, default=Path.cwd())
|
|
205
285
|
parser.add_argument("--json", action="store_true")
|
|
286
|
+
parser.add_argument(
|
|
287
|
+
"--static-degraded", action="store_true",
|
|
288
|
+
help="显式执行降级路径(仅源码/构建标记静态识别;输出 status=degraded,"
|
|
289
|
+
"不做编译与 sanitizer 验证)",
|
|
290
|
+
)
|
|
206
291
|
args = parser.parse_args(argv)
|
|
292
|
+
if args.static_degraded:
|
|
293
|
+
print(json.dumps(run_static_degraded(args.root), ensure_ascii=False, indent=2))
|
|
294
|
+
return 0
|
|
207
295
|
report = native_report(args.root)
|
|
208
296
|
print_report(report, as_json=args.json)
|
|
209
297
|
# “不适用”不是失败:退出码 0 表示探针结论有效,避免上游把它误判为执行失败。
|
|
@@ -164,6 +164,66 @@ def inspect(root: Path) -> dict:
|
|
|
164
164
|
}
|
|
165
165
|
|
|
166
166
|
|
|
167
|
+
def is_available() -> tuple[bool, str]:
|
|
168
|
+
"""降级契约:机械探测叙述层能力前置条件(<5ms,零阻塞、零子进程)。
|
|
169
|
+
|
|
170
|
+
只查 openwiki CLI 是否在 PATH(不执行 --version 子进程);缺失时
|
|
171
|
+
detail 明确给出安装建议。纯建议性能力:缺失不阻断审计(ABSENT=维持现状)。
|
|
172
|
+
"""
|
|
173
|
+
cli_path = shutil.which("openwiki")
|
|
174
|
+
if cli_path:
|
|
175
|
+
return True, f"openwiki CLI 可用: {cli_path}"
|
|
176
|
+
return False, f"openwiki CLI 未安装:叙述层能力缺失({INSTALL_HINT});缺失不构成降级阻断,回退就是不使用 wiki"
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
def run_static_degraded(root: Path | str | None = None) -> dict:
|
|
180
|
+
"""降级路径:CLI 缺失时仅静态读取 wiki 产物(清单/更新时间/页面目录)。
|
|
181
|
+
|
|
182
|
+
降级契约:输出与成功路径(inspect,status=READY)**可区分**——
|
|
183
|
+
status="degraded" + degraded=True + degraded_reason;findings 恒为空
|
|
184
|
+
(叙述层是待验证假设,按 DOC-032 永不进入 Finding 证据链)。
|
|
185
|
+
"""
|
|
186
|
+
root_path = Path(root or Path.cwd()).resolve()
|
|
187
|
+
available, availability_detail = is_available()
|
|
188
|
+
wiki_dir = root_path / WIKI_DIR
|
|
189
|
+
wiki_present = wiki_dir.is_dir() and any(wiki_dir.rglob("*.md"))
|
|
190
|
+
manifest_path = root_path / MANIFEST
|
|
191
|
+
pages = 0
|
|
192
|
+
if manifest_path.is_file() and not manifest_path.is_symlink():
|
|
193
|
+
try:
|
|
194
|
+
manifest = json.loads(manifest_path.read_text(encoding="utf-8"))
|
|
195
|
+
if isinstance(manifest, dict) and isinstance(manifest.get("pages"), dict):
|
|
196
|
+
pages = len(manifest["pages"])
|
|
197
|
+
except (OSError, ValueError) as exc:
|
|
198
|
+
notes = [f"manifest 读取失败(显式留痕,不静默): {exc.__class__.__name__}: {exc}"]
|
|
199
|
+
else:
|
|
200
|
+
notes = []
|
|
201
|
+
else:
|
|
202
|
+
notes = []
|
|
203
|
+
return {
|
|
204
|
+
"probe": "openwiki",
|
|
205
|
+
"status": "degraded",
|
|
206
|
+
"degraded": True,
|
|
207
|
+
"degraded_reason": (
|
|
208
|
+
"openwiki_cli_unavailable" if not available else "static_mode_forced"
|
|
209
|
+
),
|
|
210
|
+
"success": True,
|
|
211
|
+
"root": str(root_path),
|
|
212
|
+
"findings": [],
|
|
213
|
+
"evidence": {
|
|
214
|
+
"wiki_present": wiki_present,
|
|
215
|
+
"manifest_pages": pages,
|
|
216
|
+
"availability_detail": availability_detail,
|
|
217
|
+
"narrative_layer_note": "叙述层内容属待验证假设,禁止作为 Finding 依据",
|
|
218
|
+
},
|
|
219
|
+
"notes": notes or [
|
|
220
|
+
"降级模式:仅静态读取 wiki 产物;不执行 CLI 子进程,不刷新 wiki",
|
|
221
|
+
],
|
|
222
|
+
"recommendations": [] if available else [f"如需叙述层增强:{INSTALL_HINT}"],
|
|
223
|
+
"checks_not_run": ["openwiki-version", "freshness-git-compare"],
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
|
|
167
227
|
def print_report(report: dict, as_json: bool = False) -> None:
|
|
168
228
|
if as_json:
|
|
169
229
|
print(json.dumps(report, ensure_ascii=False, indent=2))
|
|
@@ -183,7 +243,17 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
183
243
|
parser.add_argument("command", choices=("check",), nargs="?", default="check")
|
|
184
244
|
parser.add_argument("--root", type=Path, default=Path.cwd())
|
|
185
245
|
parser.add_argument("--json", action="store_true")
|
|
246
|
+
parser.add_argument(
|
|
247
|
+
"--static-degraded", action="store_true",
|
|
248
|
+
help="显式执行降级路径(仅静态读取 wiki 产物;输出 status=degraded,"
|
|
249
|
+
"findings 恒为空)",
|
|
250
|
+
)
|
|
186
251
|
args = parser.parse_args(argv)
|
|
252
|
+
if args.static_degraded:
|
|
253
|
+
print(json.dumps(
|
|
254
|
+
run_static_degraded(args.root), ensure_ascii=False, indent=2,
|
|
255
|
+
))
|
|
256
|
+
return 0
|
|
187
257
|
report = inspect(args.root.resolve())
|
|
188
258
|
print_report(report, getattr(args, "json", False))
|
|
189
259
|
return 0
|
|
@@ -343,5 +343,111 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
343
343
|
return 0
|
|
344
344
|
|
|
345
345
|
|
|
346
|
+
def _mechanical_checks() -> list[dict]:
|
|
347
|
+
"""降级契约的机械自检清单(零子进程):账本适配器 + 内置正则库。
|
|
348
|
+
|
|
349
|
+
异常一律带类型名与原因写入 ``detail`` 上报,禁止静默吞掉;不产出能力
|
|
350
|
+
声明(能力声明归 ``check_readiness``)。
|
|
351
|
+
"""
|
|
352
|
+
checks: list[dict] = []
|
|
353
|
+
try:
|
|
354
|
+
ledger = _ledger_module()
|
|
355
|
+
ledger_ready = callable(getattr(ledger, "retrieve", None))
|
|
356
|
+
checks.append({
|
|
357
|
+
"name": "lesson_ledger_adapter",
|
|
358
|
+
"ok": ledger_ready,
|
|
359
|
+
"detail": (
|
|
360
|
+
"账本检索适配器已加载" if ledger_ready
|
|
361
|
+
else "账本检索适配器缺少 retrieve 接口"
|
|
362
|
+
),
|
|
363
|
+
})
|
|
364
|
+
except Exception as exc: # noqa: BLE001 - 适配器加载失败必须带原因上报
|
|
365
|
+
checks.append({
|
|
366
|
+
"name": "lesson_ledger_adapter",
|
|
367
|
+
"ok": False,
|
|
368
|
+
"detail": f"账本检索适配器不可用: {type(exc).__name__}: {exc}",
|
|
369
|
+
})
|
|
370
|
+
try:
|
|
371
|
+
regex_count = 0
|
|
372
|
+
for expressions in PROBE_LIBRARY.values():
|
|
373
|
+
if expressions is None:
|
|
374
|
+
continue
|
|
375
|
+
for expression in expressions:
|
|
376
|
+
re.compile(expression)
|
|
377
|
+
regex_count += 1
|
|
378
|
+
checks.append({
|
|
379
|
+
"name": "pattern_library", "ok": regex_count > 0,
|
|
380
|
+
"detail": f"已校验 {regex_count} 条内置规则",
|
|
381
|
+
})
|
|
382
|
+
except (re.error, TypeError) as exc:
|
|
383
|
+
checks.append({
|
|
384
|
+
"name": "pattern_library", "ok": False,
|
|
385
|
+
"detail": f"内置规则不可编译: {type(exc).__name__}: {exc}",
|
|
386
|
+
})
|
|
387
|
+
return checks
|
|
388
|
+
|
|
389
|
+
|
|
390
|
+
def is_available() -> tuple[bool, str]:
|
|
391
|
+
"""降级契约:机械探针自检(零子进程):账本适配器可加载 + 内置正则可编译。
|
|
392
|
+
|
|
393
|
+
本探针的目标依赖是 lesson-ledger 检索适配器(``retrieve``)与内置
|
|
394
|
+
``PROBE_LIBRARY`` 正则库;扫描本身是纯标准库(``re``)有界读,不发子进程。
|
|
395
|
+
依赖缺失时调用方必须走 :func:`run_static_degraded`,禁止伪装扫描就绪。
|
|
396
|
+
"""
|
|
397
|
+
failed = [check for check in _mechanical_checks() if not check["ok"]]
|
|
398
|
+
if failed:
|
|
399
|
+
return False, ";".join(
|
|
400
|
+
f"{check['name']}: {check['detail']}" for check in failed
|
|
401
|
+
)
|
|
402
|
+
return True, "账本检索适配器与内置正则库就绪"
|
|
403
|
+
|
|
404
|
+
|
|
405
|
+
def run_static_degraded(root: Path | str | None = None) -> dict:
|
|
406
|
+
"""依赖缺失/静态降级时的输出:只声明机械事实,绝不伪造扫描命中。
|
|
407
|
+
|
|
408
|
+
与成功路径(``scan()`` 的 ``status="ok"`` 报告)字段级可区分:
|
|
409
|
+
``status="degraded"`` + ``degraded=True`` + ``degraded_reason`` +
|
|
410
|
+
``scan_executed=False``;runtime-only 类别保持「需动态验证」声明。
|
|
411
|
+
"""
|
|
412
|
+
available, availability_detail = is_available()
|
|
413
|
+
checks = _mechanical_checks()
|
|
414
|
+
failed_names = {check["name"] for check in checks if not check["ok"]}
|
|
415
|
+
if available:
|
|
416
|
+
degraded_reason = "static_mode_forced"
|
|
417
|
+
elif "lesson_ledger_adapter" in failed_names:
|
|
418
|
+
degraded_reason = "lesson_ledger_adapter_missing"
|
|
419
|
+
else:
|
|
420
|
+
degraded_reason = "pattern_library_not_compilable"
|
|
421
|
+
return {
|
|
422
|
+
"probe": "pattern",
|
|
423
|
+
"schema_version": 1,
|
|
424
|
+
"success": True,
|
|
425
|
+
"status": "degraded",
|
|
426
|
+
"degraded": True,
|
|
427
|
+
"degraded_reason": degraded_reason,
|
|
428
|
+
"probe_mode": "static_degraded",
|
|
429
|
+
"root": str(root) if root else None,
|
|
430
|
+
"scan_executed": False,
|
|
431
|
+
"checks": checks,
|
|
432
|
+
"probe_categories": sorted(
|
|
433
|
+
name for name, expressions in PROBE_LIBRARY.items() if expressions
|
|
434
|
+
),
|
|
435
|
+
"runtime_only_categories": sorted(
|
|
436
|
+
name for name, expressions in PROBE_LIBRARY.items()
|
|
437
|
+
if expressions is None
|
|
438
|
+
),
|
|
439
|
+
"findings": [],
|
|
440
|
+
"evidence": {"availability_detail": availability_detail},
|
|
441
|
+
"fallback": (
|
|
442
|
+
"内置 PROBE_LIBRARY 正则库可机械枚举;scan() 需要 "
|
|
443
|
+
".bugx/knowledge/lesson-ledger.json 检索模式,先沉淀经验账本"
|
|
444
|
+
),
|
|
445
|
+
"metadata": {
|
|
446
|
+
"degraded_mode": "mechanical_dependency_check_only",
|
|
447
|
+
"runtime_validation": "runtime-only 类别需动态验证,静态扫描不覆盖",
|
|
448
|
+
},
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
|
|
346
452
|
if __name__ == "__main__":
|
|
347
453
|
sys.exit(main())
|