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
|
@@ -186,6 +186,9 @@ _SAFE_MODULES = {"math", "datetime", "itertools", "functools", "typing", "datacl
|
|
|
186
186
|
_RULES_FILE_NAME = "judge-rules.json"
|
|
187
187
|
_PROMOTE_THRESHOLD = 3
|
|
188
188
|
_MAX_ACTIVE_ADDITIONS = 20
|
|
189
|
+
#: 每类 candidates 的驻留上限(F-RSI-20261112-091):防一次性反馈 token
|
|
190
|
+
#: 无界驻留撑爆 rules 文件。晋升会清理对应 candidate;超限时拒绝新增。
|
|
191
|
+
_MAX_CANDIDATE_ENTRIES = 200
|
|
189
192
|
|
|
190
193
|
|
|
191
194
|
def default_rules() -> dict[str, Any]:
|
|
@@ -279,6 +282,11 @@ def harvest_feedback(
|
|
|
279
282
|
if token is None or token in base[key]:
|
|
280
283
|
counts["rejected"] += 1
|
|
281
284
|
continue
|
|
285
|
+
# F-RSI-20261112-091:已晋升生效的 token 直接跳过 candidate
|
|
286
|
+
# 记录——否则后续反馈经 setdefault 复活 candidate,形成
|
|
287
|
+
# active+candidate 双轨死数据。
|
|
288
|
+
if token in active.get(key, []):
|
|
289
|
+
continue
|
|
282
290
|
slot = candidates.setdefault(key, {})
|
|
283
291
|
entry = slot.setdefault(token, {"count": 0, "sources": []})
|
|
284
292
|
if unit not in entry["sources"]:
|
|
@@ -290,6 +298,28 @@ def harvest_feedback(
|
|
|
290
298
|
if token not in lst and len(lst) < _MAX_ACTIVE_ADDITIONS:
|
|
291
299
|
lst.append(token)
|
|
292
300
|
counts["promoted"] += 1
|
|
301
|
+
# F-RSI-20261112-091:晋升即从 candidates 清除——
|
|
302
|
+
# 已 active 的候选残留是死数据(count/sources 永久
|
|
303
|
+
# 驻留 rules 文件)。token in lst 幂等检查保证重复
|
|
304
|
+
# 晋升安全,清理不影响既有 active 语义。
|
|
305
|
+
slot.pop(token, None)
|
|
306
|
+
# F-RSI-20261112-091:candidates 每键上限——一次性反馈 token 无界驻留
|
|
307
|
+
# 会让 rules 文件无限膨胀(每次 harvest 全量读写)。超限时拒绝新增并
|
|
308
|
+
# 留痕(既有条目继续计数),上限按保守值不淘汰既有数据。
|
|
309
|
+
for key, slot in candidates.items():
|
|
310
|
+
overflow = len(slot) - _MAX_CANDIDATE_ENTRIES
|
|
311
|
+
if overflow > 0:
|
|
312
|
+
print(
|
|
313
|
+
f"[judge] ⚠ rule_feedback candidates[{key}] 已达上限 "
|
|
314
|
+
f"{_MAX_CANDIDATE_ENTRIES}(超出 {overflow} 条新增被拒;"
|
|
315
|
+
"清理 knowledge/judge-rules.json 或晋升既有条目可腾位)",
|
|
316
|
+
file=sys.stderr,
|
|
317
|
+
)
|
|
318
|
+
for token in list(slot):
|
|
319
|
+
if len(slot) <= _MAX_CANDIDATE_ENTRIES:
|
|
320
|
+
break
|
|
321
|
+
if token not in active.get(key, []):
|
|
322
|
+
slot.pop(token, None)
|
|
293
323
|
path.parent.mkdir(parents=True, exist_ok=True)
|
|
294
324
|
path.write_text(json.dumps(data, ensure_ascii=False, indent=1), encoding="utf-8")
|
|
295
325
|
return counts
|
|
@@ -602,10 +632,8 @@ def run_battery(
|
|
|
602
632
|
"json": "json.loads"}.get(suffix)
|
|
603
633
|
code = f"import pathlib\nraw = pathlib.Path({file_path!r}).read_text(encoding='utf-8', errors='ignore')\nassert raw.strip(), 'empty asset'\nprint('asset_bytes=%d' % len(raw))"
|
|
604
634
|
if parser:
|
|
605
|
-
body = ("import importlib\n"
|
|
606
|
-
f"parser = lambda t: __import__({{{suffix!r}: 'json'}}.get({suffix!r}, 'yaml')).{'loads' if suffix=='json' else 'safe_load'}(t)\n")
|
|
607
635
|
code = (f"import pathlib\nraw = pathlib.Path({file_path!r}).read_text(encoding='utf-8', errors='ignore')\nassert raw.strip(), 'empty asset'\n"
|
|
608
|
-
+ ("import json\
|
|
636
|
+
+ ("import json\nprint('parsed_items=%d' % len(json.loads(raw)))\n" if suffix == "json" else
|
|
609
637
|
"import yaml\ndata = yaml.safe_load(raw)\nassert data is not None, 'unparsable asset'\nprint('parsed_type=%s' % type(data).__name__)\n"))
|
|
610
638
|
all_probes = all_probes + [{"desc": f"asset-integrity[{suffix or 'text'}] {file_path}", "code": code}]
|
|
611
639
|
if has_exec_signal(unit_source, dep_sources=dep_sources, rules=rules):
|
|
@@ -903,6 +931,39 @@ def run_battery_probe(
|
|
|
903
931
|
|
|
904
932
|
|
|
905
933
|
_PROBE_REQUEST_SHELL_TOKENS = (";", "&&", "||", "`", "$(", ">", "<")
|
|
934
|
+
#: probe_requests 的宿主执行身份是引擎进程——被审项目的恶意内容可能提示
|
|
935
|
+
#: 注入 judge 产出 probe_requests(conventions 消毒同款威胁模型)。shell
|
|
936
|
+
#: 字符黑名单挡不住 `import os` + 换行分隔的 python 逃逸,此处按 AST 拒收
|
|
937
|
+
#: 高危导入与动态执行调用(纵深防御;-c 无沙箱,最终信任边界是宿主)。
|
|
938
|
+
_PROBE_REQUEST_BANNED_MODULES = frozenset({
|
|
939
|
+
"os", "subprocess", "socket", "ctypes", "signal", "importlib",
|
|
940
|
+
"shutil", "sys", "pathlib", "builtins",
|
|
941
|
+
})
|
|
942
|
+
_PROBE_REQUEST_BANNED_CALLS = frozenset({
|
|
943
|
+
"eval", "exec", "compile", "__import__", "open", "globals", "locals",
|
|
944
|
+
})
|
|
945
|
+
|
|
946
|
+
|
|
947
|
+
def _probe_code_escaped_sandbox(code: str) -> bool:
|
|
948
|
+
"""True = 代码含逃逸出「观测断言」语义的构造(import 高危模块/动态执行)。"""
|
|
949
|
+
try:
|
|
950
|
+
tree = ast.parse(code)
|
|
951
|
+
except (SyntaxError, ValueError):
|
|
952
|
+
return True
|
|
953
|
+
for node in ast.walk(tree):
|
|
954
|
+
if isinstance(node, ast.Import):
|
|
955
|
+
for alias in node.names:
|
|
956
|
+
if alias.name.split(".")[0] in _PROBE_REQUEST_BANNED_MODULES:
|
|
957
|
+
return True
|
|
958
|
+
elif isinstance(node, ast.ImportFrom):
|
|
959
|
+
if (node.module or "").split(".")[0] in _PROBE_REQUEST_BANNED_MODULES:
|
|
960
|
+
return True
|
|
961
|
+
elif isinstance(node, ast.Call):
|
|
962
|
+
fn = node.func
|
|
963
|
+
name = getattr(fn, "id", None) or getattr(fn, "attr", None)
|
|
964
|
+
if name in _PROBE_REQUEST_BANNED_CALLS:
|
|
965
|
+
return True
|
|
966
|
+
return False
|
|
906
967
|
|
|
907
968
|
|
|
908
969
|
def validate_probe_requests(requests: object) -> list[dict[str, str]]:
|
|
@@ -917,6 +978,14 @@ def validate_probe_requests(requests: object) -> list[dict[str, str]]:
|
|
|
917
978
|
desc = str(item.get("desc") or "probe")[:120]
|
|
918
979
|
if not code or any(tok in code for tok in _PROBE_REQUEST_SHELL_TOKENS):
|
|
919
980
|
continue
|
|
981
|
+
# F-RSI-20261112-093:AST 纵深守卫——拒收 import os/subprocess 等
|
|
982
|
+
# 逃逸构造与 eval/exec/open 动态执行(观测断言语义不需要它们)。
|
|
983
|
+
if _probe_code_escaped_sandbox(code):
|
|
984
|
+
print(
|
|
985
|
+
f"[judge] ✗ probe_requests 含越出观测断言语义的构造,已拒收: {desc}",
|
|
986
|
+
file=sys.stderr,
|
|
987
|
+
)
|
|
988
|
+
continue
|
|
920
989
|
out.append({"desc": desc, "code": code})
|
|
921
990
|
return out
|
|
922
991
|
|
|
@@ -974,6 +1043,18 @@ def execute_reproduction(
|
|
|
974
1043
|
artifact_root = (root / artifact_root).resolve() if not Path(artifact_root).is_absolute() else Path(artifact_root).resolve()
|
|
975
1044
|
artifact_root.mkdir(parents=True, exist_ok=True)
|
|
976
1045
|
argv = command.split(" ", 1)
|
|
1046
|
+
# F-RSI-20261112-092:复现脚本的执行边界必须锁定在被审项目 root 内——
|
|
1047
|
+
# judge 给出的相对路径(../)或绝对路径可指向 root 外任意 py 文件
|
|
1048
|
+
# (宿主机脚本/引擎自身代码),越出「复现被审项目缺陷」的边界。
|
|
1049
|
+
if len(argv) > 1:
|
|
1050
|
+
script = Path(argv[1])
|
|
1051
|
+
script = (root / script).resolve() if not script.is_absolute() else script.resolve()
|
|
1052
|
+
if script != root and root not in script.parents:
|
|
1053
|
+
print(
|
|
1054
|
+
f"[judge] ✗ 复现命令越界拒绝:{argv[1]} 不在项目 root 内",
|
|
1055
|
+
file=sys.stderr,
|
|
1056
|
+
)
|
|
1057
|
+
return None
|
|
977
1058
|
started = time.time()
|
|
978
1059
|
try:
|
|
979
1060
|
proc = subprocess.run(
|
|
@@ -1055,7 +1136,9 @@ def checkpoint_payload_from_verdict(
|
|
|
1055
1136
|
) -> dict[str, Any] | None:
|
|
1056
1137
|
"""把裁决映射成 supervisor checkpoint payload(机器构造,无手搓)。
|
|
1057
1138
|
|
|
1058
|
-
- clean
|
|
1139
|
+
- clean 且电池/复现证据可绑定 → 全单元 covered(结构化证据落账)
|
|
1140
|
+
- insufficient_data → 全单元 unverified(judge 明确拒判:不得以电池
|
|
1141
|
+
探针通过冒充已覆盖;artifact_only 例外记 not_applicable)
|
|
1059
1142
|
- bug → 单元 covered,findings 附带,且每条 finding 的复现收据
|
|
1060
1143
|
(宿主实跑)优先作为该单元 evidence;无复现收据时回退电池 evidence,
|
|
1061
1144
|
finding 标记 reproducible=false。
|
|
@@ -1370,10 +1370,12 @@ PROBE_SPECIFICATIONS: dict[str, str] = {
|
|
|
1370
1370
|
"- 工具接口: `apk_decompile_manifest` (解析 exported 组件与 DeepLink 过滤器), `adb_send_intent` (跨进程触发 Intent 越权)\n"
|
|
1371
1371
|
"- 操作规范: 验证能否未认证越权拉起私有 Activity/Service,或通过伪造 Intent Extras 提取沙箱 SQLite 敏感数据。"
|
|
1372
1372
|
),
|
|
1373
|
-
"
|
|
1374
|
-
"### [黑盒探针:
|
|
1375
|
-
"- 工具接口: `
|
|
1376
|
-
"
|
|
1373
|
+
"ios_binary": (
|
|
1374
|
+
"### [黑盒探针: ios_binary (Mach-O 加固 / 代码签名 / entitlements / ATS)]\n"
|
|
1375
|
+
"- 工具接口: `codesign`/`otool`/`nm` 宿主二进制审计(PIE、栈保护、cryptid、entitlements), "
|
|
1376
|
+
"Info.plist 静态安全门(ATS 放宽 `NSAllowsArbitraryLoads*`、`UIFileSharingEnabled` 明文落盘)\n"
|
|
1377
|
+
"- 操作规范: 审查 ATS 强制放宽、敏感 entitlements 过宽(keychain-access-groups 等)"
|
|
1378
|
+
"及二进制加固缺失(no-PIE / no-stack-canary)对应的可利用面。"
|
|
1377
1379
|
),
|
|
1378
1380
|
"miniprogram_probe": (
|
|
1379
1381
|
"### [黑盒探针: MiniProgramProbe (Subpackage Router & Cloud Functions)]\n"
|
|
@@ -1492,7 +1494,7 @@ def build_domain_specialized_prompt(
|
|
|
1492
1494
|
elif target_form_norm in ("mobile_android", "android"):
|
|
1493
1495
|
probes = ["android_probe"]
|
|
1494
1496
|
elif target_form_norm in ("mobile_ios", "ios"):
|
|
1495
|
-
probes = ["
|
|
1497
|
+
probes = ["ios_binary"]
|
|
1496
1498
|
elif target_form_norm in ("miniprogram", "wechat"):
|
|
1497
1499
|
probes = ["miniprogram_probe"]
|
|
1498
1500
|
elif target_form_norm in ("binary", "embedded"):
|
|
@@ -301,10 +301,10 @@ def harvest_specification(project_root: Path) -> BusinessSpec:
|
|
|
301
301
|
# 2. 扫描权威设计文档与 README
|
|
302
302
|
doc_candidates = (
|
|
303
303
|
"README.md",
|
|
304
|
-
"docs/02_architecture/
|
|
305
|
-
"docs/02_architecture/
|
|
306
|
-
"docs/02_architecture/
|
|
307
|
-
"docs/03_ai/
|
|
304
|
+
"docs/02_architecture/02_DESIGN_SPEC.md",
|
|
305
|
+
"docs/02_architecture/01_ARCHITECTURE.md",
|
|
306
|
+
"docs/02_architecture/03_BUGX_AUDIT_FLOW.md",
|
|
307
|
+
"docs/03_ai/01_AI_REFERENCE.md",
|
|
308
308
|
)
|
|
309
309
|
for rel_path in doc_candidates:
|
|
310
310
|
candidate = project_root / rel_path
|
package/core/probes/INTERFACE.md
CHANGED
|
@@ -42,9 +42,10 @@
|
|
|
42
42
|
#### `class WebDynamicProbe(BaseProbe)` - Web 专属黑盒动态探针,支持 HTTP 原始发包与 Playwright 无头浏览器探针。
|
|
43
43
|
- **Public Methods**:
|
|
44
44
|
- `browser_slot(cls, timeout: float = 2.0)`
|
|
45
|
+
- `capture_browser_page(page: Any, url: str, *, browser_version: str, actions: Sequence[dict[str, Any]] | None = None, timeout: float = 10.0, screenshot_path: str | Path | None = None, screenshot_full_page: bool = True, screenshot_masks: Sequence[str] = (), wait_until: str = 'load', after_navigation: Callable[[Any], None] | None = None, inspect_page: Callable[[Any], Mapping[str, Any] | None] | None = None) -> dict[str, Any]`
|
|
45
46
|
- `classify_http_response(cls, response_data: Mapping[str, Any], baseline_data: Mapping[str, Any] | None = None) -> dict[str, Any]`
|
|
46
47
|
- `get_active_instances(cls) -> int`
|
|
47
|
-
- `headless_browser_action(self, url: str, actions: Sequence[dict[str, Any]] | None = None, timeout: float = 10.0) -> dict[str, Any]`
|
|
48
|
+
- `headless_browser_action(self, url: str, actions: Sequence[dict[str, Any]] | None = None, timeout: float = 10.0, *, screenshot_path: str | Path | None = None, viewport: Mapping[str, int] | None = None) -> dict[str, Any]`
|
|
48
49
|
- `http_raw_request(self, url: str, method: str = 'GET', headers: Mapping[str, str] | None = None, data: bytes | str | None = None, timeout: float = 10.0) -> dict[str, Any]`
|
|
49
50
|
- `is_available(self) -> bool`
|
|
50
51
|
- `probe_name(self) -> str`
|
|
@@ -70,4 +71,13 @@
|
|
|
70
71
|
<!-- generated:end -->
|
|
71
72
|
|
|
72
73
|
## 3. Usage Examples & Defensive Patterns
|
|
74
|
+
The CLI registry exposes `bugx probe ui` through `ui_audit.py:main`. Rules are loaded by
|
|
75
|
+
`ui_contract.py`. `ui_accessibility.py` runs axe-core and keyboard steps,
|
|
76
|
+
`ui_evidence.py` verifies receipts, and `ui_visual_diff.py` compares reference captures.
|
|
77
|
+
`ui_storybook.py` resolves a deployed index and preview, and `ui_tokens.py` loads mapped
|
|
78
|
+
CSS values from project token JSON.
|
|
79
|
+
Browser measurements, model review and token repair remain internal to the CLI
|
|
80
|
+
implementation. Input, receipt and exit contracts are specified in
|
|
81
|
+
`core/report_engine/web-conformance.md`.
|
|
82
|
+
|
|
73
83
|
Refer to `SPEC.md` for architectural context, event topologies, and failure domain mappings.
|
package/core/probes/SPEC.md
CHANGED
|
@@ -22,5 +22,15 @@ res = probe.execute_probe('http://localhost:8080')
|
|
|
22
22
|
```
|
|
23
23
|
|
|
24
24
|
## 5. Maintenance & Verification
|
|
25
|
-
-
|
|
25
|
+
- Verification is performed with short-lived tests outside the repository; no persistent `tests/` registry is retained.
|
|
26
|
+
- Validation runners and fixtures are process artifacts under `/tmp/bugx-tests-*`; they are
|
|
27
|
+
physically removed after the verification window and are not a repository interface.
|
|
28
|
+
- `capture_browser_page` is shared by `headless_browser_action` and `bugx probe ui`. The UI
|
|
29
|
+
audit owns its browser contexts, records native zoom, and adds computed style, layout and
|
|
30
|
+
explicit state and keyboard assertions to the same screenshot receipt. The packaged
|
|
31
|
+
axe-core bundle runs in the rendered context. The Web conformance reader verifies the
|
|
32
|
+
run identity, manifest, screenshot hashes and scoped outcomes.
|
|
33
|
+
- Storybook inputs bind the index digest and preview ID to each captured story. The
|
|
34
|
+
token importer resolves declared same-file aliases in project JSON and adds its file
|
|
35
|
+
digest and CSS mapping to the design receipt.
|
|
26
36
|
- Changes to exported interfaces must be synchronized via `python3 scripts/gen_interface_spec.py --package core/probes --write`.
|
package/core/probes/__init__.py
CHANGED
|
@@ -2,50 +2,22 @@
|
|
|
2
2
|
"""core/probes - 形态专属黑盒探针系统 (DOC-248 Dynamic Probes)。
|
|
3
3
|
|
|
4
4
|
统一导出所有领域专属探针基类与实现类。
|
|
5
|
+
|
|
6
|
+
W-004 惰性化(耗时账本):本包历史上 eager import 全部 19 个探针模块
|
|
7
|
+
(含 playwright 链的 web_probe/differential_probe 等重型依赖),被引擎
|
|
8
|
+
门禁链(launch_phases.common → governance → supervisor → coverage)
|
|
9
|
+
连带 import,每次引擎启动固定支付 ~190ms。改为 PEP 562 模块级
|
|
10
|
+
__getattr__ 按需加载:BaseProbe(轻量基类)保持 eager(probe_registry
|
|
11
|
+
注册面依赖),其余探针在首次属性访问时才 import——消费方三种形态
|
|
12
|
+
(from core.probes import X / from core.probes.X import Y / 子模块直
|
|
13
|
+
import)语义全部不变。
|
|
5
14
|
"""
|
|
6
15
|
|
|
7
16
|
from __future__ import annotations
|
|
8
17
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
from .android_probe import AndroidProbe
|
|
13
|
-
from .miniprogram_probe import MiniProgramProbe
|
|
14
|
-
from . import sast_probe
|
|
15
|
-
from . import sast_rules
|
|
16
|
-
from . import sca_scanner
|
|
17
|
-
from . import desktop_probe
|
|
18
|
-
from . import mobile_probe
|
|
19
|
-
from . import native_probe
|
|
20
|
-
from . import platform_probe
|
|
21
|
-
from . import memory_probe
|
|
22
|
-
from . import efficiency_probe
|
|
23
|
-
from . import differential_probe
|
|
24
|
-
from . import pattern_probe
|
|
25
|
-
from . import ios_binary_probe
|
|
26
|
-
from . import codebase_memory_probe
|
|
27
|
-
from . import openwiki_probe
|
|
28
|
-
from . import probe_registry
|
|
29
|
-
except (ImportError, ValueError):
|
|
30
|
-
from core.probes.base import BaseProbe
|
|
31
|
-
from core.probes.web_probe import WebDynamicProbe
|
|
32
|
-
from core.probes.android_probe import AndroidProbe
|
|
33
|
-
from core.probes.miniprogram_probe import MiniProgramProbe
|
|
34
|
-
from core.probes import sast_probe
|
|
35
|
-
from core.probes import sast_rules
|
|
36
|
-
from core.probes import sca_scanner
|
|
37
|
-
from core.probes import desktop_probe
|
|
38
|
-
from core.probes import mobile_probe
|
|
39
|
-
from core.probes import native_probe
|
|
40
|
-
from core.probes import platform_probe
|
|
41
|
-
from core.probes import memory_probe
|
|
42
|
-
from core.probes import efficiency_probe
|
|
43
|
-
from core.probes import differential_probe
|
|
44
|
-
from core.probes import pattern_probe
|
|
45
|
-
from core.probes import ios_binary_probe
|
|
46
|
-
from core.probes import codebase_memory_probe
|
|
47
|
-
from core.probes import openwiki_probe
|
|
48
|
-
from core.probes import probe_registry
|
|
18
|
+
from typing import Any
|
|
19
|
+
|
|
20
|
+
from .base import BaseProbe
|
|
49
21
|
|
|
50
22
|
__all__ = [
|
|
51
23
|
"BaseProbe",
|
|
@@ -68,3 +40,37 @@ __all__ = [
|
|
|
68
40
|
"openwiki_probe",
|
|
69
41
|
"probe_registry",
|
|
70
42
|
]
|
|
43
|
+
|
|
44
|
+
# 惰性成员 → 所属子模块(属性名与历史 eager 导出逐一对应,语义不变)
|
|
45
|
+
_LAZY_MEMBERS: dict[str, str] = {
|
|
46
|
+
"WebDynamicProbe": "web_probe",
|
|
47
|
+
"AndroidProbe": "android_probe",
|
|
48
|
+
"MiniProgramProbe": "miniprogram_probe",
|
|
49
|
+
"sast_probe": "sast_probe",
|
|
50
|
+
"sast_rules": "sast_rules",
|
|
51
|
+
"sca_scanner": "sca_scanner",
|
|
52
|
+
"desktop_probe": "desktop_probe",
|
|
53
|
+
"mobile_probe": "mobile_probe",
|
|
54
|
+
"native_probe": "native_probe",
|
|
55
|
+
"platform_probe": "platform_probe",
|
|
56
|
+
"memory_probe": "memory_probe",
|
|
57
|
+
"efficiency_probe": "efficiency_probe",
|
|
58
|
+
"differential_probe": "differential_probe",
|
|
59
|
+
"pattern_probe": "pattern_probe",
|
|
60
|
+
"ios_binary_probe": "ios_binary_probe",
|
|
61
|
+
"codebase_memory_probe": "codebase_memory_probe",
|
|
62
|
+
"openwiki_probe": "openwiki_probe",
|
|
63
|
+
"probe_registry": "probe_registry",
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def __getattr__(name: str) -> Any:
|
|
68
|
+
"""PEP 562 按需加载探针成员(W-004:消除门禁链 190ms eager 税)。"""
|
|
69
|
+
target = _LAZY_MEMBERS.get(name)
|
|
70
|
+
if target is None:
|
|
71
|
+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
|
72
|
+
import importlib
|
|
73
|
+
|
|
74
|
+
module = importlib.import_module(f"{__name__}.{target}")
|
|
75
|
+
globals()[name] = module # 缓存:后续访问零开销
|
|
76
|
+
return module
|
|
@@ -9,9 +9,25 @@
|
|
|
9
9
|
|
|
10
10
|
from __future__ import annotations
|
|
11
11
|
|
|
12
|
+
# 脚本被 CLI 以独立进程执行(bugx probe android)时的 sys.path 自举:
|
|
13
|
+
# 沿 parents 找 ``core/bugx.md`` 引擎标记,把引擎/仓库根插入 sys.path——
|
|
14
|
+
# 与 mobile_probe.py 同形态(缺了它 ``from core.probes.base`` 在子进程
|
|
15
|
+
# 里必然 ImportError,F-RSI-20261118-003 实测)。
|
|
16
|
+
import sys as _sys
|
|
17
|
+
from pathlib import Path as _Path
|
|
18
|
+
for _p in _Path(__file__).resolve().parents:
|
|
19
|
+
if (_p / "core" / "bugx.md").is_file():
|
|
20
|
+
if str(_p) not in _sys.path:
|
|
21
|
+
_sys.path.insert(0, str(_p))
|
|
22
|
+
break
|
|
23
|
+
del _p
|
|
24
|
+
|
|
25
|
+
import argparse
|
|
26
|
+
import json
|
|
12
27
|
import os
|
|
13
28
|
import shutil
|
|
14
29
|
import subprocess
|
|
30
|
+
import sys
|
|
15
31
|
import threading
|
|
16
32
|
from pathlib import Path
|
|
17
33
|
from typing import Any, Mapping, Sequence
|
|
@@ -39,7 +55,11 @@ class AndroidProbe(BaseProbe):
|
|
|
39
55
|
return "android_probe"
|
|
40
56
|
|
|
41
57
|
def is_available(self) -> bool:
|
|
42
|
-
"""AUDIT-04: 极速探活 (<5ms,零阻塞)。
|
|
58
|
+
"""AUDIT-04: 极速探活 (<5ms,零阻塞)。
|
|
59
|
+
|
|
60
|
+
降级契约:布尔返回值受 BaseProbe 布尔契约约束(execute_probe 以真值
|
|
61
|
+
判定是否降级);(bool, detail) 明细结构见模块级 ``check_availability()``。
|
|
62
|
+
"""
|
|
43
63
|
return shutil.which("adb") is not None
|
|
44
64
|
|
|
45
65
|
@classmethod
|
|
@@ -101,6 +121,17 @@ class AndroidProbe(BaseProbe):
|
|
|
101
121
|
"message": "Application has android:allowBackup enabled, allowing unauthorized adb backup extraction",
|
|
102
122
|
})
|
|
103
123
|
|
|
124
|
+
# AM-4: 明文流量声明(CWE-311/MSTG-NETWORK-1)。与 debuggable/allowBackup
|
|
125
|
+
# 同形态的 application 级 Manifest 属性检查;targetSdk >= 28 默认禁用,
|
|
126
|
+
# 显式声明 true 即为回退到明文通道,全量 HTTP 流量暴露于中间人拦截。
|
|
127
|
+
uses_cleartext = self._get_android_attr(application, "usesCleartextTraffic")
|
|
128
|
+
if uses_cleartext and uses_cleartext.lower() == "true":
|
|
129
|
+
findings.append({
|
|
130
|
+
"rule_id": "CLEARTEXT_TRAFFIC_ENABLED",
|
|
131
|
+
"severity": "HIGH",
|
|
132
|
+
"message": "Application declares android:usesCleartextTraffic='true', permitting unencrypted HTTP traffic that is exposed to MITM interception",
|
|
133
|
+
})
|
|
134
|
+
|
|
104
135
|
component_tags = ("activity", "activity-alias", "service", "receiver", "provider")
|
|
105
136
|
for elem in application:
|
|
106
137
|
tag_name = elem.tag.split("}")[-1]
|
|
@@ -332,13 +363,44 @@ class AndroidProbe(BaseProbe):
|
|
|
332
363
|
context: dict[str, Any] | None = None,
|
|
333
364
|
**kwargs: Any,
|
|
334
365
|
) -> dict[str, Any]:
|
|
335
|
-
"""AUDIT-04: 无 adb 环境时,优雅降级为静态 AndroidManifest.xml 语义解析。
|
|
366
|
+
"""AUDIT-04: 无 adb 环境时,优雅降级为静态 AndroidManifest.xml 语义解析。
|
|
367
|
+
|
|
368
|
+
降级契约:输出与成功路径(run_dynamic,status="ok")**可区分**——
|
|
369
|
+
status="degraded" + degraded=True + degraded_reason,绝不伪装成正常动态结果。
|
|
370
|
+
"""
|
|
371
|
+
if self.is_available():
|
|
372
|
+
degraded_reason = "static_mode_forced"
|
|
373
|
+
else:
|
|
374
|
+
degraded_reason = "adb_unavailable"
|
|
375
|
+
|
|
336
376
|
manifest_file = self._find_manifest(target)
|
|
337
377
|
if manifest_file and manifest_file.exists():
|
|
338
|
-
|
|
378
|
+
try:
|
|
379
|
+
parsed = self.parse_manifest(manifest_file)
|
|
380
|
+
except Exception as exc:
|
|
381
|
+
# 显式失败结构,禁止静默吞错(解析失败 ≠ 未发现问题)
|
|
382
|
+
return {
|
|
383
|
+
"success": False,
|
|
384
|
+
"status": "degraded",
|
|
385
|
+
"degraded": True,
|
|
386
|
+
"degraded_reason": "android_manifest_parse_failed",
|
|
387
|
+
"probe_mode": "static_degraded",
|
|
388
|
+
"findings": [],
|
|
389
|
+
"evidence": {
|
|
390
|
+
"manifest_path": str(manifest_file),
|
|
391
|
+
"error": str(exc),
|
|
392
|
+
"error_type": exc.__class__.__name__,
|
|
393
|
+
},
|
|
394
|
+
"metadata": {
|
|
395
|
+
"target": str(target),
|
|
396
|
+
"degraded_mode": "static_manifest_semantic_analysis",
|
|
397
|
+
},
|
|
398
|
+
}
|
|
339
399
|
return {
|
|
340
400
|
"success": True,
|
|
341
|
-
"status": "
|
|
401
|
+
"status": "degraded",
|
|
402
|
+
"degraded": True,
|
|
403
|
+
"degraded_reason": degraded_reason,
|
|
342
404
|
"probe_mode": "static_degraded",
|
|
343
405
|
"findings": parsed["findings"],
|
|
344
406
|
"evidence": {
|
|
@@ -355,10 +417,29 @@ class AndroidProbe(BaseProbe):
|
|
|
355
417
|
|
|
356
418
|
# 若 target 是直接传入的 XML 文本
|
|
357
419
|
if isinstance(target, str) and "<manifest" in target:
|
|
358
|
-
|
|
420
|
+
try:
|
|
421
|
+
parsed = self.parse_manifest(target)
|
|
422
|
+
except Exception as exc:
|
|
423
|
+
return {
|
|
424
|
+
"success": False,
|
|
425
|
+
"status": "degraded",
|
|
426
|
+
"degraded": True,
|
|
427
|
+
"degraded_reason": "android_manifest_parse_failed",
|
|
428
|
+
"probe_mode": "static_degraded",
|
|
429
|
+
"findings": [],
|
|
430
|
+
"evidence": {
|
|
431
|
+
"error": str(exc),
|
|
432
|
+
"error_type": exc.__class__.__name__,
|
|
433
|
+
},
|
|
434
|
+
"metadata": {
|
|
435
|
+
"degraded_mode": "static_manifest_string_analysis",
|
|
436
|
+
},
|
|
437
|
+
}
|
|
359
438
|
return {
|
|
360
439
|
"success": True,
|
|
361
|
-
"status": "
|
|
440
|
+
"status": "degraded",
|
|
441
|
+
"degraded": True,
|
|
442
|
+
"degraded_reason": degraded_reason,
|
|
362
443
|
"probe_mode": "static_degraded",
|
|
363
444
|
"findings": parsed["findings"],
|
|
364
445
|
"evidence": {
|
|
@@ -372,13 +453,100 @@ class AndroidProbe(BaseProbe):
|
|
|
372
453
|
}
|
|
373
454
|
|
|
374
455
|
return {
|
|
375
|
-
"success":
|
|
376
|
-
"status": "
|
|
456
|
+
"success": False,
|
|
457
|
+
"status": "degraded",
|
|
458
|
+
"degraded": True,
|
|
459
|
+
"degraded_reason": "android_manifest_not_found",
|
|
377
460
|
"probe_mode": "static_degraded",
|
|
378
461
|
"findings": [],
|
|
379
462
|
"evidence": {},
|
|
380
463
|
"metadata": {
|
|
381
464
|
"target": str(target),
|
|
382
|
-
"
|
|
465
|
+
"degraded_mode": "static_manifest_semantic_analysis",
|
|
383
466
|
},
|
|
384
467
|
}
|
|
468
|
+
|
|
469
|
+
|
|
470
|
+
def check_availability() -> dict[str, Any]:
|
|
471
|
+
"""降级契约:Android 审计能力结构化探活明细((bool, detail) 的结构化形态)。
|
|
472
|
+
|
|
473
|
+
机械探测 adb 是否在 PATH(<5ms,零阻塞、零子进程);READY/DEGRADED
|
|
474
|
+
与 check_availability 明细一并返回,DEGRADED 时必须走
|
|
475
|
+
``AndroidProbe.run_static_degraded``,禁止伪装成动态审计结果。
|
|
476
|
+
"""
|
|
477
|
+
adb_path = shutil.which("adb")
|
|
478
|
+
ready = adb_path is not None
|
|
479
|
+
return {
|
|
480
|
+
"name": "android_probe",
|
|
481
|
+
"status": "READY" if ready else "DEGRADED",
|
|
482
|
+
"available": ready,
|
|
483
|
+
"detail": adb_path or "adb 未安装:动态 Intent 拉起不可用,降级为静态 Manifest 解析",
|
|
484
|
+
"checks": [
|
|
485
|
+
{
|
|
486
|
+
"name": "adb",
|
|
487
|
+
"ok": ready,
|
|
488
|
+
"required": True,
|
|
489
|
+
"detail": adb_path or "未找到 adb(安装:brew install android-platform-tools)",
|
|
490
|
+
}
|
|
491
|
+
],
|
|
492
|
+
"capabilities": ["adb_intent_dispatch", "device_lock_mutex"] if ready else [],
|
|
493
|
+
"fallbacks": {} if ready else {
|
|
494
|
+
"audit": "AndroidProbe.run_static_degraded(AndroidManifest.xml 静态语义解析)",
|
|
495
|
+
},
|
|
496
|
+
"warnings": [],
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
|
|
500
|
+
def print_report(report: dict[str, Any], as_json: bool = False) -> None:
|
|
501
|
+
"""打印 check 报告(``--json`` 原样输出,否则人读摘要)。"""
|
|
502
|
+
if as_json:
|
|
503
|
+
print(json.dumps(report, ensure_ascii=False, indent=2))
|
|
504
|
+
return
|
|
505
|
+
status = report.get("status", "UNKNOWN")
|
|
506
|
+
print(f"[{status}] Android 审计通道(Manifest 静态语义 + adb 动态)")
|
|
507
|
+
for item in report.get("checks", []):
|
|
508
|
+
print(f" {'✓' if item.get('ok') else '!'} {item['name']}: {item['detail']}")
|
|
509
|
+
if status != "READY":
|
|
510
|
+
print(" ⏸ 动态 Intent 通道不可用;静态审计可显式执行:--static-degraded")
|
|
511
|
+
|
|
512
|
+
|
|
513
|
+
def main(argv: list[str] | None = None) -> int:
|
|
514
|
+
"""CLI 入口(``bugx probe android``):check=通道探活,--static-degraded=静态审计。
|
|
515
|
+
|
|
516
|
+
与 mobile_probe 同语义:``check``/``status`` 只探测通道可用性(不产出
|
|
517
|
+
findings);静态 manifest 审计必须显式 ``--static-degraded`` 触发,
|
|
518
|
+
DEGRADED 结果绝不伪装为动态审计。
|
|
519
|
+
"""
|
|
520
|
+
parser = argparse.ArgumentParser(description=__doc__)
|
|
521
|
+
parser.add_argument("command", choices=("check", "status"), nargs="?", default="check")
|
|
522
|
+
parser.add_argument("--root", type=Path, default=Path.cwd())
|
|
523
|
+
parser.add_argument("--json", action="store_true")
|
|
524
|
+
parser.add_argument("--strict", action="store_true")
|
|
525
|
+
parser.add_argument(
|
|
526
|
+
"--allow-degraded", action="store_true",
|
|
527
|
+
help="明确允许使用回退方案;否则 DEGRADED 返回 2",
|
|
528
|
+
)
|
|
529
|
+
parser.add_argument(
|
|
530
|
+
"--static-degraded", action="store_true",
|
|
531
|
+
help="显式执行降级路径(AndroidManifest.xml 静态语义解析;"
|
|
532
|
+
"输出 status=degraded,绝不伪造 adb 动态证据)",
|
|
533
|
+
)
|
|
534
|
+
args = parser.parse_args(argv)
|
|
535
|
+
if args.static_degraded:
|
|
536
|
+
report = AndroidProbe().run_static_degraded(args.root)
|
|
537
|
+
print(json.dumps(report, ensure_ascii=False, indent=2) if args.json else
|
|
538
|
+
f"[{report.get('status')}] findings={len(report.get('findings', []))}")
|
|
539
|
+
return 0
|
|
540
|
+
report = check_availability()
|
|
541
|
+
print_report(report, args.json)
|
|
542
|
+
if report["status"] == "READY":
|
|
543
|
+
return 0
|
|
544
|
+
if args.allow_degraded:
|
|
545
|
+
return 0
|
|
546
|
+
if args.strict:
|
|
547
|
+
return 2
|
|
548
|
+
return 1
|
|
549
|
+
|
|
550
|
+
|
|
551
|
+
if __name__ == "__main__":
|
|
552
|
+
raise SystemExit(main())
|
|
@@ -586,5 +586,62 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
586
586
|
return 1 if args.strict and report["status"] != "READY" else 0
|
|
587
587
|
|
|
588
588
|
|
|
589
|
+
def is_available() -> tuple[bool, str]:
|
|
590
|
+
"""降级契约:机械探活 codebase-memory-mcp 固定版本候选(<5ms,零子进程)。
|
|
591
|
+
|
|
592
|
+
只做 PATH 候选枚举与固定版本规格校验,不执行 ``--version`` 或任何 CLI
|
|
593
|
+
子命令;版本兼容验证仍归 ``inspect()``。环境不满足时返回 False,调用方
|
|
594
|
+
必须走 ``run_static_degraded``,禁止伪装语义图谱可用。
|
|
595
|
+
"""
|
|
596
|
+
expected_version = _pinned_cli_version()
|
|
597
|
+
if expected_version is None:
|
|
598
|
+
return False, "core/tool_install_targets.py 中的 codebase-memory 固定规格无效"
|
|
599
|
+
candidates, _ = _binary_candidates(_probe_environment(), None)
|
|
600
|
+
if not candidates:
|
|
601
|
+
return False, f"codebase-memory-mcp 未安装(需要固定版本 {expected_version})"
|
|
602
|
+
return True, f"发现候选 {candidates[0]}(固定版本 {expected_version})"
|
|
603
|
+
|
|
604
|
+
|
|
605
|
+
def run_static_degraded(root: Path, *, binary: str | None = None) -> dict:
|
|
606
|
+
"""降级契约:CLI 不可用时输出本地静态覆盖事实,绝不伪装语义增强可用。
|
|
607
|
+
|
|
608
|
+
输出与成功路径(``inspect()`` 的 READY/DEGRADED 报告)字段级可区分:
|
|
609
|
+
``status="degraded"`` + ``degraded=True`` + ``degraded_reason``,并把
|
|
610
|
+
本轮回退显式钉在 ``symbol_index.py + project_graph.py`` 本地枚举上。
|
|
611
|
+
"""
|
|
612
|
+
available, availability_detail = is_available()
|
|
613
|
+
root = Path(root).resolve()
|
|
614
|
+
root_exists = root.is_dir()
|
|
615
|
+
degraded_reason = (
|
|
616
|
+
"codebase_memory_cli_unavailable" if not available else "static_mode_forced"
|
|
617
|
+
)
|
|
618
|
+
evidence: dict = {
|
|
619
|
+
"availability_detail": availability_detail,
|
|
620
|
+
"root_exists": root_exists,
|
|
621
|
+
}
|
|
622
|
+
success = False
|
|
623
|
+
if root_exists:
|
|
624
|
+
success = True
|
|
625
|
+
evidence["source_files"] = _source_count(root)
|
|
626
|
+
evidence["git_head"] = _git_head(root)
|
|
627
|
+
return {
|
|
628
|
+
"schema_version": 1,
|
|
629
|
+
"success": success,
|
|
630
|
+
"status": "degraded",
|
|
631
|
+
"degraded": True,
|
|
632
|
+
"degraded_reason": degraded_reason,
|
|
633
|
+
"probe_mode": "static_degraded",
|
|
634
|
+
"root": str(root),
|
|
635
|
+
"findings": [],
|
|
636
|
+
"evidence": evidence,
|
|
637
|
+
"fallback": "symbol_index.py + project_graph.py(本地全量枚举,不依赖语义图谱)",
|
|
638
|
+
"install": f"pipx install --force {OPTIONAL_TOOL_PACKAGE_SPECS['codebase-memory']}",
|
|
639
|
+
"metadata": {
|
|
640
|
+
"degraded_mode": "local_coverage_facts_only",
|
|
641
|
+
"semantic_graph_available": False,
|
|
642
|
+
},
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
|
|
589
646
|
if __name__ == "__main__":
|
|
590
647
|
raise SystemExit(main())
|