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
|
@@ -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())
|
|
@@ -210,6 +210,102 @@ def desktop_report(root: Path | str | None = None) -> Report:
|
|
|
210
210
|
return Report("desktop", "READY", tuple(checks), tuple(warnings))
|
|
211
211
|
|
|
212
212
|
|
|
213
|
+
def is_available(root: Path | str | None = None) -> tuple[bool, str]:
|
|
214
|
+
"""降级契约:机械探测桌面审计前置条件(<5ms,零阻塞、零子进程)。
|
|
215
|
+
|
|
216
|
+
desktop_probe 为纯静态只读探针:无外部工具/SDK 依赖,环境层面恒可用;
|
|
217
|
+
若提供 root 则顺带校验目标目录可读性。返回 (available, detail)。
|
|
218
|
+
"""
|
|
219
|
+
detail = "desktop_probe 为纯静态只读探针,无外部工具/SDK 依赖,环境恒可用"
|
|
220
|
+
if root is not None:
|
|
221
|
+
root_path = Path(root)
|
|
222
|
+
if not root_path.is_dir():
|
|
223
|
+
return False, f"目标目录不存在或不可读: {root_path}"
|
|
224
|
+
detail += f";目标目录可读: {root_path}"
|
|
225
|
+
return True, detail
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
def run_static_degraded(root: Path | str | None = None) -> dict:
|
|
229
|
+
"""降级路径:受限静态取证(有界文件扫描 + 框架识别 + 打包/更新通道检查)。
|
|
230
|
+
|
|
231
|
+
降级契约:输出与成功路径(desktop_report,status=READY)**可区分**——
|
|
232
|
+
status="degraded" + degraded=True + degraded_reason;框架未识别或工程
|
|
233
|
+
不可读时如实返回 success=False,禁止把未取证写成 PASS。
|
|
234
|
+
"""
|
|
235
|
+
root_path = Path(root or Path.cwd())
|
|
236
|
+
available, availability_detail = is_available(root_path)
|
|
237
|
+
if not available:
|
|
238
|
+
return {
|
|
239
|
+
"platform": "desktop",
|
|
240
|
+
"status": "degraded",
|
|
241
|
+
"degraded": True,
|
|
242
|
+
"degraded_reason": "target_root_not_found",
|
|
243
|
+
"success": False,
|
|
244
|
+
"root": str(root_path),
|
|
245
|
+
"findings": [],
|
|
246
|
+
"warnings": [availability_detail],
|
|
247
|
+
"checks_not_run": ["electron-process-model", "packaging", "update-channel"],
|
|
248
|
+
}
|
|
249
|
+
files = _iter_files(root_path)
|
|
250
|
+
framework, evidence = _detect_framework(files)
|
|
251
|
+
warnings: list[str] = []
|
|
252
|
+
if not framework:
|
|
253
|
+
warnings.append(
|
|
254
|
+
"未识别到 Electron/Tauri/Qt/WPF 桌面框架:桌面取证不适用(非环境缺口,"
|
|
255
|
+
"与 BLOCKED 严格区分);如需桌面审计请先确认项目形态"
|
|
256
|
+
)
|
|
257
|
+
return {
|
|
258
|
+
"platform": "desktop",
|
|
259
|
+
"status": "degraded",
|
|
260
|
+
"degraded": True,
|
|
261
|
+
"degraded_reason": "desktop_framework_not_detected",
|
|
262
|
+
"success": False,
|
|
263
|
+
"root": str(root_path),
|
|
264
|
+
"findings": [],
|
|
265
|
+
"evidence": {"files_scanned": len(files)},
|
|
266
|
+
"warnings": warnings,
|
|
267
|
+
"checks_not_run": ["electron-process-model", "packaging", "update-channel"],
|
|
268
|
+
}
|
|
269
|
+
if framework == "electron":
|
|
270
|
+
process_details, process_warnings = _electron_findings(files)
|
|
271
|
+
packaging_details, packaging_warnings = _packaging_findings(files)
|
|
272
|
+
update_details, update_warnings = _update_findings(files)
|
|
273
|
+
findings = [
|
|
274
|
+
{"area": "process_model", "details": process_details},
|
|
275
|
+
{"area": "packaging", "details": packaging_details},
|
|
276
|
+
{"area": "update_channel", "details": update_details},
|
|
277
|
+
]
|
|
278
|
+
warnings.extend([*process_warnings, *packaging_warnings, *update_warnings])
|
|
279
|
+
else:
|
|
280
|
+
packaging_details, packaging_warnings = _packaging_findings(files)
|
|
281
|
+
findings = [{"area": "packaging", "details": packaging_details}]
|
|
282
|
+
warnings.extend(packaging_warnings)
|
|
283
|
+
warnings.append(
|
|
284
|
+
f"{framework} 的进程模型/更新通道无自动化探针:需宿主 Agent 以现有工具取证"
|
|
285
|
+
)
|
|
286
|
+
warnings.append(
|
|
287
|
+
"降级模式:以上为有界静态扫描结果(≤4000 文件);进程运行时行为、安装与"
|
|
288
|
+
"更新通道真实行为均未验证,禁止声称已完成桌面动态取证"
|
|
289
|
+
)
|
|
290
|
+
return {
|
|
291
|
+
"platform": "desktop",
|
|
292
|
+
"status": "degraded",
|
|
293
|
+
"degraded": True,
|
|
294
|
+
"degraded_reason": "static_mode_forced",
|
|
295
|
+
"success": True,
|
|
296
|
+
"root": str(root_path),
|
|
297
|
+
"findings": findings,
|
|
298
|
+
"evidence": {
|
|
299
|
+
"files_scanned": len(files),
|
|
300
|
+
"framework": framework,
|
|
301
|
+
"framework_evidence": evidence,
|
|
302
|
+
"availability_detail": availability_detail,
|
|
303
|
+
},
|
|
304
|
+
"warnings": warnings,
|
|
305
|
+
"checks_not_run": ["runtime-process-behavior", "installer-verification"],
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
|
|
213
309
|
def print_report(report: Report, *, as_json: bool = False) -> None:
|
|
214
310
|
if as_json:
|
|
215
311
|
print(json.dumps(asdict(report), ensure_ascii=False, indent=2))
|
|
@@ -227,7 +323,15 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
227
323
|
parser.add_argument("command", choices=("check", "status"), nargs="?", default="check")
|
|
228
324
|
parser.add_argument("--root", type=Path, default=Path.cwd())
|
|
229
325
|
parser.add_argument("--json", action="store_true")
|
|
326
|
+
parser.add_argument(
|
|
327
|
+
"--static-degraded", action="store_true",
|
|
328
|
+
help="显式执行降级路径(有界静态取证;输出 status=degraded,"
|
|
329
|
+
"不验证运行时行为)",
|
|
330
|
+
)
|
|
230
331
|
args = parser.parse_args(argv)
|
|
332
|
+
if args.static_degraded:
|
|
333
|
+
print(json.dumps(run_static_degraded(args.root), ensure_ascii=False, indent=2))
|
|
334
|
+
return 0
|
|
231
335
|
report = desktop_report(args.root)
|
|
232
336
|
print_report(report, as_json=args.json)
|
|
233
337
|
# “不适用”不是失败:退出码 0 表示探针结论有效,避免上游把它误判为执行失败。
|
|
@@ -41,20 +41,15 @@ from pathlib import Path
|
|
|
41
41
|
|
|
42
42
|
from core.supervisor.worker_execution import run_bounded
|
|
43
43
|
|
|
44
|
-
# QUA-03:
|
|
45
|
-
# DifferentialError
|
|
46
|
-
from core.fuzzing.fuzz_input import shell_argv as _shell_argv
|
|
44
|
+
# QUA-03:argv lexer 与 shell 运算符校验只保留一份;本模块仅适配
|
|
45
|
+
# DifferentialError 语义,不能复制解析实现。
|
|
46
|
+
from core.fuzzing.fuzz_input import shell_argv as _shell_argv, split_argv as _split_argv_shared
|
|
47
47
|
|
|
48
48
|
DEFAULT_TIMEOUT = 10.0
|
|
49
49
|
DEFAULT_REPEAT = 1
|
|
50
50
|
MAX_INPUTS = 2000
|
|
51
51
|
MAX_CAPTURE = 65536
|
|
52
52
|
MAX_INPUT_BYTES = 16 * 1024 * 1024
|
|
53
|
-
_SHELL_PUNCTUATION = ";&|<>`$()"
|
|
54
|
-
_SHELL_OPERATORS = frozenset({
|
|
55
|
-
";", "&", "&&", "|", "||", "<", ">", ">>", "<<", "<&", ">&",
|
|
56
|
-
"`", "$(", "(", ")",
|
|
57
|
-
})
|
|
58
53
|
|
|
59
54
|
|
|
60
55
|
class DifferentialError(ValueError):
|
|
@@ -62,19 +57,14 @@ class DifferentialError(ValueError):
|
|
|
62
57
|
|
|
63
58
|
|
|
64
59
|
def _split_argv(template: str) -> list[str]:
|
|
65
|
-
"""
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
if not argv:
|
|
74
|
-
raise DifferentialError("命令不能为空")
|
|
75
|
-
if any(token in _SHELL_OPERATORS for token in argv):
|
|
76
|
-
raise DifferentialError("命令包含 shell 运算符;如确需使用,请显式传入 --allow-shell")
|
|
77
|
-
return argv
|
|
60
|
+
"""复用全仓 argv 解析器,仅适配本模块的异常契约。"""
|
|
61
|
+
return _split_argv_shared(
|
|
62
|
+
template,
|
|
63
|
+
error_type=DifferentialError,
|
|
64
|
+
parse_error_prefix="命令无法解析",
|
|
65
|
+
empty_message="命令不能为空",
|
|
66
|
+
operator_message="命令包含 shell 运算符;如确需使用,请显式传入 --allow-shell",
|
|
67
|
+
)
|
|
78
68
|
|
|
79
69
|
|
|
80
70
|
def check_readiness() -> dict:
|
|
@@ -352,5 +342,93 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
352
342
|
return 0
|
|
353
343
|
|
|
354
344
|
|
|
345
|
+
def is_available() -> tuple[bool, str]:
|
|
346
|
+
"""降级契约:机械探活差分执行前提,对齐既有 ``check_readiness()`` 先例。
|
|
347
|
+
|
|
348
|
+
只检查受限执行器与 argv 解析器是否已加载(纯属性/可调用性判定,零子进程);
|
|
349
|
+
环境不满足时返回 False,调用方必须走 ``run_static_degraded``,禁止伪装
|
|
350
|
+
双侧执行完成。
|
|
351
|
+
"""
|
|
352
|
+
readiness = check_readiness()
|
|
353
|
+
ok = readiness["status"] == "READY"
|
|
354
|
+
if ok:
|
|
355
|
+
return True, "受限执行器与 argv 解析器就绪"
|
|
356
|
+
failed = ";".join(
|
|
357
|
+
f"{check['name']}: {check['detail']}" for check in readiness["checks"] if not check["ok"]
|
|
358
|
+
)
|
|
359
|
+
return False, f"差分执行前提缺失: {failed}"
|
|
360
|
+
|
|
361
|
+
|
|
362
|
+
def run_static_degraded(recorded_cases: list[dict] | None = None) -> dict:
|
|
363
|
+
"""降级契约:不执行目标/参考命令,仅对已记录双侧 outcome 做静态比对。
|
|
364
|
+
|
|
365
|
+
输出与成功路径(``run_comparison`` 的 report.json 摘要,含真实双侧执行
|
|
366
|
+
工件)字段级可区分:``status="degraded"`` + ``degraded=True`` +
|
|
367
|
+
``degraded_reason``;每个 case 显式声明 ``executed=False``,禁止把静态
|
|
368
|
+
比对结论伪装成 ``oracle.tier=differential`` 的真实执行工件。
|
|
369
|
+
"""
|
|
370
|
+
available, availability_detail = is_available()
|
|
371
|
+
degraded_reason = (
|
|
372
|
+
"static_mode_forced" if available else "differential_execution_unavailable"
|
|
373
|
+
)
|
|
374
|
+
cases: list[dict] = []
|
|
375
|
+
divergent = 0
|
|
376
|
+
if recorded_cases:
|
|
377
|
+
for index, case in enumerate(recorded_cases, 1):
|
|
378
|
+
target = case.get("target")
|
|
379
|
+
reference = case.get("reference")
|
|
380
|
+
required_keys = {"exit", "stdout", "stderr"}
|
|
381
|
+
sides_valid = (
|
|
382
|
+
isinstance(target, dict) and isinstance(reference, dict)
|
|
383
|
+
and required_keys.issubset(target) and required_keys.issubset(reference)
|
|
384
|
+
)
|
|
385
|
+
if not sides_valid:
|
|
386
|
+
cases.append({
|
|
387
|
+
"case_id": f"case-{index:04d}",
|
|
388
|
+
"executed": False,
|
|
389
|
+
"skipped_reason": "recorded_side_missing_or_invalid",
|
|
390
|
+
})
|
|
391
|
+
continue
|
|
392
|
+
outcome_pair = (
|
|
393
|
+
_outcome({**target, "stdout": _as_bytes(target["stdout"]), "stderr": _as_bytes(target["stderr"])}),
|
|
394
|
+
_outcome({**reference, "stdout": _as_bytes(reference["stdout"]), "stderr": _as_bytes(reference["stderr"])}),
|
|
395
|
+
)
|
|
396
|
+
kinds = _divergence_kinds(*outcome_pair)
|
|
397
|
+
if kinds:
|
|
398
|
+
divergent += 1
|
|
399
|
+
cases.append({
|
|
400
|
+
"case_id": f"case-{index:04d}",
|
|
401
|
+
"executed": False,
|
|
402
|
+
"target_exit": str(target.get("exit")),
|
|
403
|
+
"reference_exit": str(reference.get("exit")),
|
|
404
|
+
"kinds": kinds,
|
|
405
|
+
"stable": True,
|
|
406
|
+
})
|
|
407
|
+
return {
|
|
408
|
+
"schema_version": 1,
|
|
409
|
+
"success": bool(recorded_cases),
|
|
410
|
+
"status": "degraded",
|
|
411
|
+
"degraded": True,
|
|
412
|
+
"degraded_reason": degraded_reason,
|
|
413
|
+
"probe_mode": "static_degraded",
|
|
414
|
+
"inputs_total": len(cases),
|
|
415
|
+
"divergences": divergent,
|
|
416
|
+
"flaky_divergences": 0,
|
|
417
|
+
"cases": cases,
|
|
418
|
+
"findings": [],
|
|
419
|
+
"evidence": {
|
|
420
|
+
"availability_detail": availability_detail,
|
|
421
|
+
"recorded_cases_present": bool(recorded_cases),
|
|
422
|
+
},
|
|
423
|
+
"metadata": {
|
|
424
|
+
"degraded_mode": "recorded_outcome_static_compare",
|
|
425
|
+
"target_executed": False,
|
|
426
|
+
"oracle_usage": (
|
|
427
|
+
"降级比对不产生 oracle.tier=differential 工件;正式确认仍需真实双侧执行"
|
|
428
|
+
),
|
|
429
|
+
},
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
|
|
355
433
|
if __name__ == "__main__":
|
|
356
434
|
sys.exit(main())
|
|
@@ -164,5 +164,69 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
164
164
|
return 0 if args.allow_degraded else 2
|
|
165
165
|
|
|
166
166
|
|
|
167
|
+
def is_available() -> tuple[bool, str]:
|
|
168
|
+
"""降级契约:机械探活基础效率工具是否在 PATH(零子进程,不跑 --version)。
|
|
169
|
+
|
|
170
|
+
只做 ``shutil.which`` 枚举;版本下限校验(含 ast-grep 身份识别)仍归
|
|
171
|
+
``inspect()`` 的 ``_command``。环境不满足时返回 False,调用方必须走
|
|
172
|
+
``run_static_degraded``,禁止伪装效率工具链就绪。
|
|
173
|
+
"""
|
|
174
|
+
environment = _probe_environment()
|
|
175
|
+
path = environment.get("PATH")
|
|
176
|
+
found: list[str] = []
|
|
177
|
+
missing: list[str] = []
|
|
178
|
+
for names, label in ((("rg",), "ripgrep"), (("ast-grep", "sg"), "ast-grep"), (("jq",), "jq")):
|
|
179
|
+
resolved = None
|
|
180
|
+
for name in names:
|
|
181
|
+
resolved = shutil.which(name, path=path)
|
|
182
|
+
if resolved:
|
|
183
|
+
break
|
|
184
|
+
(found if resolved else missing).append(label)
|
|
185
|
+
if missing:
|
|
186
|
+
return False, f"缺失工具: {', '.join(missing)};回退 Python 标准库 + symbol_index/project_graph"
|
|
187
|
+
return True, f"基础工具就绪: {', '.join(found)}"
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
def run_static_degraded(root: Path | None = None) -> dict:
|
|
191
|
+
"""降级契约:效率工具缺失时的降级输出,绝不伪装 READY。
|
|
192
|
+
|
|
193
|
+
输出与成功路径(``inspect()`` 的 READY 报告)字段级可区分:
|
|
194
|
+
``status="degraded"`` + ``degraded=True`` + ``degraded_reason``;只声明
|
|
195
|
+
机械探活事实与回退路径,不执行 ``--version`` 子进程,也不替用户决定安装。
|
|
196
|
+
"""
|
|
197
|
+
available, availability_detail = is_available()
|
|
198
|
+
resolved_root = Path(root).resolve() if root else None
|
|
199
|
+
tools = []
|
|
200
|
+
environment = _probe_environment()
|
|
201
|
+
for names, label in ((("rg",), "ripgrep"), (("ast-grep", "sg"), "ast-grep"), (("jq",), "jq")):
|
|
202
|
+
resolved = None
|
|
203
|
+
for name in names:
|
|
204
|
+
resolved = shutil.which(name, path=environment.get("PATH"))
|
|
205
|
+
if resolved:
|
|
206
|
+
break
|
|
207
|
+
tools.append({"name": label, "ok": bool(resolved), "path": resolved})
|
|
208
|
+
return {
|
|
209
|
+
"schema_version": 1,
|
|
210
|
+
"success": True,
|
|
211
|
+
"status": "degraded",
|
|
212
|
+
"degraded": True,
|
|
213
|
+
"degraded_reason": (
|
|
214
|
+
"static_mode_forced" if available else "efficiency_tools_missing"
|
|
215
|
+
),
|
|
216
|
+
"probe_mode": "static_degraded",
|
|
217
|
+
"required": False,
|
|
218
|
+
"recommended": True,
|
|
219
|
+
"root": str(resolved_root) if resolved_root else None,
|
|
220
|
+
"base_tools": tools,
|
|
221
|
+
"findings": [],
|
|
222
|
+
"evidence": {"availability_detail": availability_detail},
|
|
223
|
+
"fallback": "Python 标准库 + 内置 symbol_index/project_graph + 官方文档搜索",
|
|
224
|
+
"metadata": {
|
|
225
|
+
"degraded_mode": "mechanical_which_only",
|
|
226
|
+
"version_validation": "deferred_to_inspect",
|
|
227
|
+
},
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
|
|
167
231
|
if __name__ == "__main__":
|
|
168
232
|
raise SystemExit(main())
|