bugx-cli 0.1.0 → 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/README.md +190 -186
- 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/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/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/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 +25 -6
- package/core/cloud_sync/cloud_onboard.py +42 -1
- package/core/cloud_sync/flywheel_client.py +16 -7
- 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 +591 -419
- 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 +2 -2
- package/core/launch_phases/SPEC.md +1 -1
- package/core/launch_phases/common.py +21 -2
- package/core/launch_phases/finding_confirm_phase.py +5 -1
- 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 +139 -3
- 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 +53 -36
- package/core/launch_phases/pre_state_builder.py +23 -176
- package/core/launch_phases/round_orchestrator.py +15 -32
- 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 +9 -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/worker_barriers.py +15 -5
- package/core/launch_phases/worker_orchestrator.py +105 -25
- package/core/ledger/README.md +1 -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 +44 -8
- 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 +1 -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 +7 -5
- 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/command_routing_en.md +2 -2
- package/core/prompts/command_routing_zh.md +2 -2
- package/core/prompts/stages/stage_repair.md +1 -1
- 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/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 +1 -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/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/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 +190 -186
- 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 +11 -4
- package/interfaces/cli/bugx_cli/commands/advisory.py +1 -1
- package/interfaces/cli/bugx_cli/commands/agent.py +339 -73
- package/interfaces/cli/bugx_cli/commands/audit.py +2 -2
- package/interfaces/cli/bugx_cli/commands/autonomous.py +1 -1
- package/interfaces/cli/bugx_cli/commands/cloud.py +4 -3
- 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 +2 -0
- package/interfaces/cli/bugx_cli/commands/lifecycle.py +3 -3
- package/interfaces/cli/bugx_cli/commands/plugin.py +55 -20
- 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/report.py +2 -6
- package/interfaces/cli/bugx_cli/commands/system.py +11 -11
- package/interfaces/cli/bugx_cli/common.py +15 -7
- 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 +18 -10
- 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 +2 -1
- package/pyproject.toml +20 -8
- package/scripts/ensure-python.mjs +7 -7
- package/scripts/sync-version.mjs +10 -21
- package/scripts/test-npm-wrapper.mjs +1 -1
- 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
|
@@ -61,7 +61,11 @@ class MiniProgramProbe(BaseProbe):
|
|
|
61
61
|
return "miniprogram_probe"
|
|
62
62
|
|
|
63
63
|
def is_available(self) -> bool:
|
|
64
|
-
"""AUDIT-04: 极速探活 (<5ms,零阻塞)。
|
|
64
|
+
"""AUDIT-04: 极速探活 (<5ms,零阻塞)。
|
|
65
|
+
|
|
66
|
+
降级契约:布尔返回值受 BaseProbe 布尔契约约束(execute_probe 以真值
|
|
67
|
+
判定是否降级);(bool, detail) 明细结构见模块级 ``check_availability()``。
|
|
68
|
+
"""
|
|
65
69
|
for tool in ("miniprogram-ci", "cli", "wechat-cli"):
|
|
66
70
|
if shutil.which(tool) is not None:
|
|
67
71
|
return True
|
|
@@ -126,11 +130,13 @@ class MiniProgramProbe(BaseProbe):
|
|
|
126
130
|
cf_dir = Path(cloud_functions_dir)
|
|
127
131
|
findings: list[dict[str, Any]] = []
|
|
128
132
|
scanned_functions = 0
|
|
133
|
+
read_errors: list[str] = []
|
|
129
134
|
|
|
130
135
|
if not cf_dir.exists():
|
|
131
136
|
return {
|
|
132
137
|
"scanned_functions": 0,
|
|
133
138
|
"findings": [],
|
|
139
|
+
"read_errors": [f"cloud_functions_dir 不存在: {cf_dir}"],
|
|
134
140
|
}
|
|
135
141
|
|
|
136
142
|
# 遍历所有云函数目录
|
|
@@ -146,7 +152,8 @@ class MiniProgramProbe(BaseProbe):
|
|
|
146
152
|
for src_file in source_files:
|
|
147
153
|
try:
|
|
148
154
|
code = src_file.read_text(encoding="utf-8", errors="replace")
|
|
149
|
-
except
|
|
155
|
+
except OSError as exc:
|
|
156
|
+
read_errors.append(f"{src_file}: {exc}")
|
|
150
157
|
continue
|
|
151
158
|
|
|
152
159
|
has_privileged_op = any(op in code for op in self.PRIVILEGED_CLOUD_OPERATIONS)
|
|
@@ -195,6 +202,7 @@ class MiniProgramProbe(BaseProbe):
|
|
|
195
202
|
"scanned_functions": scanned_functions,
|
|
196
203
|
"findings": findings,
|
|
197
204
|
"unprotected_cloud_functions": len(findings),
|
|
205
|
+
"read_errors": read_errors,
|
|
198
206
|
}
|
|
199
207
|
|
|
200
208
|
def _find_app_json(self, target: str | Path) -> Path | None:
|
|
@@ -267,47 +275,67 @@ class MiniProgramProbe(BaseProbe):
|
|
|
267
275
|
context: dict[str, Any] | None = None,
|
|
268
276
|
**kwargs: Any,
|
|
269
277
|
) -> dict[str, Any]:
|
|
270
|
-
"""AUDIT-04: 无微信 CLI 环境时,优雅降级为静态 WXML/JSON 路由遍历与云函数源码扫描。
|
|
278
|
+
"""AUDIT-04: 无微信 CLI 环境时,优雅降级为静态 WXML/JSON 路由遍历与云函数源码扫描。
|
|
279
|
+
|
|
280
|
+
降级契约:输出与成功路径(run_dynamic,status="ok")**可区分**——
|
|
281
|
+
status="degraded" + degraded=True + degraded_reason,绝不伪装成正常动态结果。
|
|
282
|
+
"""
|
|
271
283
|
all_findings: list[dict[str, Any]] = []
|
|
272
284
|
routes_summary: list[str] = []
|
|
285
|
+
parse_errors: list[str] = []
|
|
273
286
|
|
|
274
|
-
# 1. 尝试解析 app.json
|
|
287
|
+
# 1. 尝试解析 app.json(解析失败显式留痕,禁止静默吞错)
|
|
275
288
|
app_json_path = self._find_app_json(target)
|
|
276
289
|
if app_json_path and app_json_path.exists():
|
|
277
|
-
|
|
290
|
+
try:
|
|
291
|
+
route_res = self.parse_app_json(app_json_path)
|
|
292
|
+
except Exception as exc:
|
|
293
|
+
parse_errors.append(
|
|
294
|
+
f"{app_json_path}: {exc.__class__.__name__}: {exc}"
|
|
295
|
+
)
|
|
296
|
+
route_res = {"findings": [], "all_routes": []}
|
|
278
297
|
all_findings.extend(route_res["findings"])
|
|
279
298
|
routes_summary.extend(route_res["all_routes"])
|
|
280
299
|
elif isinstance(target, str) and "pages" in target and "{" in target:
|
|
281
|
-
# 传入的是 app.json
|
|
300
|
+
# 传入的是 app.json 文本;解析失败必须显式留痕,禁止静默吞错
|
|
282
301
|
try:
|
|
283
302
|
route_res = self.parse_app_json(target)
|
|
284
303
|
all_findings.extend(route_res["findings"])
|
|
285
304
|
routes_summary.extend(route_res["all_routes"])
|
|
286
|
-
except Exception:
|
|
287
|
-
|
|
305
|
+
except Exception as exc:
|
|
306
|
+
parse_errors.append(
|
|
307
|
+
f"inline app.json: {exc.__class__.__name__}: {exc}"
|
|
308
|
+
)
|
|
288
309
|
|
|
289
310
|
# 2. 扫描云函数源码
|
|
290
311
|
cf_dir = self._find_cloud_functions_dir(target)
|
|
291
|
-
cf_res = {"scanned_functions": 0, "findings": []}
|
|
312
|
+
cf_res = {"scanned_functions": 0, "findings": [], "read_errors": []}
|
|
292
313
|
if cf_dir:
|
|
293
314
|
cf_res = self.probe_cloud_functions(cf_dir)
|
|
294
315
|
all_findings.extend(cf_res["findings"])
|
|
295
316
|
|
|
296
317
|
# 3. 静态扫描 WXML 导航标签
|
|
297
318
|
wxml_nav_count = 0
|
|
319
|
+
read_errors: list[str] = []
|
|
298
320
|
p = Path(target)
|
|
299
321
|
if p.is_dir():
|
|
300
322
|
for wxml in list(p.glob("**/*.wxml"))[:50]:
|
|
301
323
|
try:
|
|
302
324
|
txt = wxml.read_text(encoding="utf-8", errors="ignore")
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
except Exception:
|
|
325
|
+
except OSError as exc:
|
|
326
|
+
read_errors.append(f"{wxml}: {exc}")
|
|
306
327
|
continue
|
|
328
|
+
matches = re.findall(r'<navigator\s+[^>]*url=["\']([^"\']+)["\']', txt)
|
|
329
|
+
wxml_nav_count += len(matches)
|
|
307
330
|
|
|
331
|
+
parse_errors.extend(cf_res.get("read_errors", []))
|
|
308
332
|
return {
|
|
309
333
|
"success": True,
|
|
310
|
-
"status": "
|
|
334
|
+
"status": "degraded",
|
|
335
|
+
"degraded": True,
|
|
336
|
+
"degraded_reason": (
|
|
337
|
+
"wechat_cli_unavailable" if not self.is_available() else "static_mode_forced"
|
|
338
|
+
),
|
|
311
339
|
"probe_mode": "static_degraded",
|
|
312
340
|
"findings": all_findings,
|
|
313
341
|
"evidence": {
|
|
@@ -315,9 +343,43 @@ class MiniProgramProbe(BaseProbe):
|
|
|
315
343
|
"wxml_nav_links": wxml_nav_count,
|
|
316
344
|
"cloud_functions_scanned": cf_res.get("scanned_functions", 0),
|
|
317
345
|
"findings_count": len(all_findings),
|
|
346
|
+
"read_errors": parse_errors,
|
|
318
347
|
},
|
|
319
348
|
"metadata": {
|
|
320
349
|
"target": str(target),
|
|
321
350
|
"degraded_mode": "static_miniprogram_structure_analysis",
|
|
322
351
|
},
|
|
323
352
|
}
|
|
353
|
+
|
|
354
|
+
|
|
355
|
+
def check_availability() -> dict[str, Any]:
|
|
356
|
+
"""降级契约:小程序审计能力结构化探活明细((bool, detail) 的结构化形态)。
|
|
357
|
+
|
|
358
|
+
机械探测微信开发者工具 CLI / miniprogram-ci 是否在 PATH(<5ms,零阻塞、
|
|
359
|
+
零子进程);DEGRADED 时必须走 ``MiniProgramProbe.run_static_degraded``,
|
|
360
|
+
禁止伪装成动态审计结果。
|
|
361
|
+
"""
|
|
362
|
+
tools = ("miniprogram-ci", "cli", "wechat-cli")
|
|
363
|
+
found = {tool: shutil.which(tool) for tool in tools}
|
|
364
|
+
hit = next((path for path in found.values() if path), None)
|
|
365
|
+
ready = hit is not None
|
|
366
|
+
return {
|
|
367
|
+
"name": "miniprogram_probe",
|
|
368
|
+
"status": "READY" if ready else "DEGRADED",
|
|
369
|
+
"available": ready,
|
|
370
|
+
"detail": hit or "微信开发者工具 CLI / miniprogram-ci 均未安装:动态探针不可用,降级为静态结构分析",
|
|
371
|
+
"checks": [
|
|
372
|
+
{
|
|
373
|
+
"name": tool,
|
|
374
|
+
"ok": path is not None,
|
|
375
|
+
"required": True,
|
|
376
|
+
"detail": path or f"未找到 {tool}",
|
|
377
|
+
}
|
|
378
|
+
for tool, path in found.items()
|
|
379
|
+
],
|
|
380
|
+
"capabilities": ["miniprogram_dynamic_probe"] if ready else [],
|
|
381
|
+
"fallbacks": {} if ready else {
|
|
382
|
+
"audit": "MiniProgramProbe.run_static_degraded(app.json 路由 + WXML + 云函数静态扫描)",
|
|
383
|
+
},
|
|
384
|
+
"warnings": [],
|
|
385
|
+
}
|
|
@@ -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 表示探针结论有效,避免上游把它误判为执行失败。
|