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
|
@@ -164,6 +164,66 @@ def inspect(root: Path) -> dict:
|
|
|
164
164
|
}
|
|
165
165
|
|
|
166
166
|
|
|
167
|
+
def is_available() -> tuple[bool, str]:
|
|
168
|
+
"""降级契约:机械探测叙述层能力前置条件(<5ms,零阻塞、零子进程)。
|
|
169
|
+
|
|
170
|
+
只查 openwiki CLI 是否在 PATH(不执行 --version 子进程);缺失时
|
|
171
|
+
detail 明确给出安装建议。纯建议性能力:缺失不阻断审计(ABSENT=维持现状)。
|
|
172
|
+
"""
|
|
173
|
+
cli_path = shutil.which("openwiki")
|
|
174
|
+
if cli_path:
|
|
175
|
+
return True, f"openwiki CLI 可用: {cli_path}"
|
|
176
|
+
return False, f"openwiki CLI 未安装:叙述层能力缺失({INSTALL_HINT});缺失不构成降级阻断,回退就是不使用 wiki"
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
def run_static_degraded(root: Path | str | None = None) -> dict:
|
|
180
|
+
"""降级路径:CLI 缺失时仅静态读取 wiki 产物(清单/更新时间/页面目录)。
|
|
181
|
+
|
|
182
|
+
降级契约:输出与成功路径(inspect,status=READY)**可区分**——
|
|
183
|
+
status="degraded" + degraded=True + degraded_reason;findings 恒为空
|
|
184
|
+
(叙述层是待验证假设,按 DOC-032 永不进入 Finding 证据链)。
|
|
185
|
+
"""
|
|
186
|
+
root_path = Path(root or Path.cwd()).resolve()
|
|
187
|
+
available, availability_detail = is_available()
|
|
188
|
+
wiki_dir = root_path / WIKI_DIR
|
|
189
|
+
wiki_present = wiki_dir.is_dir() and any(wiki_dir.rglob("*.md"))
|
|
190
|
+
manifest_path = root_path / MANIFEST
|
|
191
|
+
pages = 0
|
|
192
|
+
if manifest_path.is_file() and not manifest_path.is_symlink():
|
|
193
|
+
try:
|
|
194
|
+
manifest = json.loads(manifest_path.read_text(encoding="utf-8"))
|
|
195
|
+
if isinstance(manifest, dict) and isinstance(manifest.get("pages"), dict):
|
|
196
|
+
pages = len(manifest["pages"])
|
|
197
|
+
except (OSError, ValueError) as exc:
|
|
198
|
+
notes = [f"manifest 读取失败(显式留痕,不静默): {exc.__class__.__name__}: {exc}"]
|
|
199
|
+
else:
|
|
200
|
+
notes = []
|
|
201
|
+
else:
|
|
202
|
+
notes = []
|
|
203
|
+
return {
|
|
204
|
+
"probe": "openwiki",
|
|
205
|
+
"status": "degraded",
|
|
206
|
+
"degraded": True,
|
|
207
|
+
"degraded_reason": (
|
|
208
|
+
"openwiki_cli_unavailable" if not available else "static_mode_forced"
|
|
209
|
+
),
|
|
210
|
+
"success": True,
|
|
211
|
+
"root": str(root_path),
|
|
212
|
+
"findings": [],
|
|
213
|
+
"evidence": {
|
|
214
|
+
"wiki_present": wiki_present,
|
|
215
|
+
"manifest_pages": pages,
|
|
216
|
+
"availability_detail": availability_detail,
|
|
217
|
+
"narrative_layer_note": "叙述层内容属待验证假设,禁止作为 Finding 依据",
|
|
218
|
+
},
|
|
219
|
+
"notes": notes or [
|
|
220
|
+
"降级模式:仅静态读取 wiki 产物;不执行 CLI 子进程,不刷新 wiki",
|
|
221
|
+
],
|
|
222
|
+
"recommendations": [] if available else [f"如需叙述层增强:{INSTALL_HINT}"],
|
|
223
|
+
"checks_not_run": ["openwiki-version", "freshness-git-compare"],
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
|
|
167
227
|
def print_report(report: dict, as_json: bool = False) -> None:
|
|
168
228
|
if as_json:
|
|
169
229
|
print(json.dumps(report, ensure_ascii=False, indent=2))
|
|
@@ -183,7 +243,17 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
183
243
|
parser.add_argument("command", choices=("check",), nargs="?", default="check")
|
|
184
244
|
parser.add_argument("--root", type=Path, default=Path.cwd())
|
|
185
245
|
parser.add_argument("--json", action="store_true")
|
|
246
|
+
parser.add_argument(
|
|
247
|
+
"--static-degraded", action="store_true",
|
|
248
|
+
help="显式执行降级路径(仅静态读取 wiki 产物;输出 status=degraded,"
|
|
249
|
+
"findings 恒为空)",
|
|
250
|
+
)
|
|
186
251
|
args = parser.parse_args(argv)
|
|
252
|
+
if args.static_degraded:
|
|
253
|
+
print(json.dumps(
|
|
254
|
+
run_static_degraded(args.root), ensure_ascii=False, indent=2,
|
|
255
|
+
))
|
|
256
|
+
return 0
|
|
187
257
|
report = inspect(args.root.resolve())
|
|
188
258
|
print_report(report, getattr(args, "json", False))
|
|
189
259
|
return 0
|
|
@@ -343,5 +343,111 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
343
343
|
return 0
|
|
344
344
|
|
|
345
345
|
|
|
346
|
+
def _mechanical_checks() -> list[dict]:
|
|
347
|
+
"""降级契约的机械自检清单(零子进程):账本适配器 + 内置正则库。
|
|
348
|
+
|
|
349
|
+
异常一律带类型名与原因写入 ``detail`` 上报,禁止静默吞掉;不产出能力
|
|
350
|
+
声明(能力声明归 ``check_readiness``)。
|
|
351
|
+
"""
|
|
352
|
+
checks: list[dict] = []
|
|
353
|
+
try:
|
|
354
|
+
ledger = _ledger_module()
|
|
355
|
+
ledger_ready = callable(getattr(ledger, "retrieve", None))
|
|
356
|
+
checks.append({
|
|
357
|
+
"name": "lesson_ledger_adapter",
|
|
358
|
+
"ok": ledger_ready,
|
|
359
|
+
"detail": (
|
|
360
|
+
"账本检索适配器已加载" if ledger_ready
|
|
361
|
+
else "账本检索适配器缺少 retrieve 接口"
|
|
362
|
+
),
|
|
363
|
+
})
|
|
364
|
+
except Exception as exc: # noqa: BLE001 - 适配器加载失败必须带原因上报
|
|
365
|
+
checks.append({
|
|
366
|
+
"name": "lesson_ledger_adapter",
|
|
367
|
+
"ok": False,
|
|
368
|
+
"detail": f"账本检索适配器不可用: {type(exc).__name__}: {exc}",
|
|
369
|
+
})
|
|
370
|
+
try:
|
|
371
|
+
regex_count = 0
|
|
372
|
+
for expressions in PROBE_LIBRARY.values():
|
|
373
|
+
if expressions is None:
|
|
374
|
+
continue
|
|
375
|
+
for expression in expressions:
|
|
376
|
+
re.compile(expression)
|
|
377
|
+
regex_count += 1
|
|
378
|
+
checks.append({
|
|
379
|
+
"name": "pattern_library", "ok": regex_count > 0,
|
|
380
|
+
"detail": f"已校验 {regex_count} 条内置规则",
|
|
381
|
+
})
|
|
382
|
+
except (re.error, TypeError) as exc:
|
|
383
|
+
checks.append({
|
|
384
|
+
"name": "pattern_library", "ok": False,
|
|
385
|
+
"detail": f"内置规则不可编译: {type(exc).__name__}: {exc}",
|
|
386
|
+
})
|
|
387
|
+
return checks
|
|
388
|
+
|
|
389
|
+
|
|
390
|
+
def is_available() -> tuple[bool, str]:
|
|
391
|
+
"""降级契约:机械探针自检(零子进程):账本适配器可加载 + 内置正则可编译。
|
|
392
|
+
|
|
393
|
+
本探针的目标依赖是 lesson-ledger 检索适配器(``retrieve``)与内置
|
|
394
|
+
``PROBE_LIBRARY`` 正则库;扫描本身是纯标准库(``re``)有界读,不发子进程。
|
|
395
|
+
依赖缺失时调用方必须走 :func:`run_static_degraded`,禁止伪装扫描就绪。
|
|
396
|
+
"""
|
|
397
|
+
failed = [check for check in _mechanical_checks() if not check["ok"]]
|
|
398
|
+
if failed:
|
|
399
|
+
return False, ";".join(
|
|
400
|
+
f"{check['name']}: {check['detail']}" for check in failed
|
|
401
|
+
)
|
|
402
|
+
return True, "账本检索适配器与内置正则库就绪"
|
|
403
|
+
|
|
404
|
+
|
|
405
|
+
def run_static_degraded(root: Path | str | None = None) -> dict:
|
|
406
|
+
"""依赖缺失/静态降级时的输出:只声明机械事实,绝不伪造扫描命中。
|
|
407
|
+
|
|
408
|
+
与成功路径(``scan()`` 的 ``status="ok"`` 报告)字段级可区分:
|
|
409
|
+
``status="degraded"`` + ``degraded=True`` + ``degraded_reason`` +
|
|
410
|
+
``scan_executed=False``;runtime-only 类别保持「需动态验证」声明。
|
|
411
|
+
"""
|
|
412
|
+
available, availability_detail = is_available()
|
|
413
|
+
checks = _mechanical_checks()
|
|
414
|
+
failed_names = {check["name"] for check in checks if not check["ok"]}
|
|
415
|
+
if available:
|
|
416
|
+
degraded_reason = "static_mode_forced"
|
|
417
|
+
elif "lesson_ledger_adapter" in failed_names:
|
|
418
|
+
degraded_reason = "lesson_ledger_adapter_missing"
|
|
419
|
+
else:
|
|
420
|
+
degraded_reason = "pattern_library_not_compilable"
|
|
421
|
+
return {
|
|
422
|
+
"probe": "pattern",
|
|
423
|
+
"schema_version": 1,
|
|
424
|
+
"success": True,
|
|
425
|
+
"status": "degraded",
|
|
426
|
+
"degraded": True,
|
|
427
|
+
"degraded_reason": degraded_reason,
|
|
428
|
+
"probe_mode": "static_degraded",
|
|
429
|
+
"root": str(root) if root else None,
|
|
430
|
+
"scan_executed": False,
|
|
431
|
+
"checks": checks,
|
|
432
|
+
"probe_categories": sorted(
|
|
433
|
+
name for name, expressions in PROBE_LIBRARY.items() if expressions
|
|
434
|
+
),
|
|
435
|
+
"runtime_only_categories": sorted(
|
|
436
|
+
name for name, expressions in PROBE_LIBRARY.items()
|
|
437
|
+
if expressions is None
|
|
438
|
+
),
|
|
439
|
+
"findings": [],
|
|
440
|
+
"evidence": {"availability_detail": availability_detail},
|
|
441
|
+
"fallback": (
|
|
442
|
+
"内置 PROBE_LIBRARY 正则库可机械枚举;scan() 需要 "
|
|
443
|
+
".bugx/knowledge/lesson-ledger.json 检索模式,先沉淀经验账本"
|
|
444
|
+
),
|
|
445
|
+
"metadata": {
|
|
446
|
+
"degraded_mode": "mechanical_dependency_check_only",
|
|
447
|
+
"runtime_validation": "runtime-only 类别需动态验证,静态扫描不覆盖",
|
|
448
|
+
},
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
|
|
346
452
|
if __name__ == "__main__":
|
|
347
453
|
sys.exit(main())
|
|
@@ -256,6 +256,77 @@ def reports_for(target: str, root: Path | None = None,
|
|
|
256
256
|
return [desktop_report(platform), android_report(root), ios_report(platform)]
|
|
257
257
|
|
|
258
258
|
|
|
259
|
+
def is_available(target: str = "all") -> tuple[bool, str]:
|
|
260
|
+
"""降级契约:机械探测平台测试环境前置条件(<5ms,零阻塞、零子进程)。
|
|
261
|
+
|
|
262
|
+
只做 PATH 工具存在性与主机平台判定,不查询设备(设备查询属 check/status
|
|
263
|
+
慢路径)。返回 (available, detail):任一所选目标的必需通道工具在场即 True。
|
|
264
|
+
"""
|
|
265
|
+
host = host_name()
|
|
266
|
+
missing: list[str] = []
|
|
267
|
+
present: list[str] = []
|
|
268
|
+
targets = ("desktop", "android", "ios") if target == "all" else (target,)
|
|
269
|
+
wanted: set[str] = set()
|
|
270
|
+
if host == "unsupported":
|
|
271
|
+
return False, f"不支持的主机平台: {sys.platform};无任何平台测试通道"
|
|
272
|
+
if "desktop" in targets:
|
|
273
|
+
capture_by_host = {
|
|
274
|
+
"macos": ("screencapture", "appium"),
|
|
275
|
+
"windows": ("powershell", "WinAppDriver", "appium"),
|
|
276
|
+
"linux": ("gnome-screenshot", "scrot", "import", "appium"),
|
|
277
|
+
}
|
|
278
|
+
wanted.update(capture_by_host[host])
|
|
279
|
+
if "android" in targets:
|
|
280
|
+
wanted.add("adb")
|
|
281
|
+
if "ios" in targets:
|
|
282
|
+
wanted.update(("xcrun", "xcodebuild"))
|
|
283
|
+
for name in sorted(wanted):
|
|
284
|
+
(present if _which(name) else missing).append(name)
|
|
285
|
+
if present:
|
|
286
|
+
detail = f"主机 {host};通道工具在场: {', '.join(present)}"
|
|
287
|
+
else:
|
|
288
|
+
detail = f"主机 {host};所需通道工具全部缺失: {', '.join(sorted(wanted))}"
|
|
289
|
+
if missing:
|
|
290
|
+
detail += f";缺失: {', '.join(missing)}"
|
|
291
|
+
return bool(present), detail
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
def run_static_degraded(
|
|
295
|
+
target: str = "all", root: Path | str | None = None,
|
|
296
|
+
) -> dict:
|
|
297
|
+
"""降级路径:仅做 PATH 工具存在性静态检测,不查询设备/模拟器。
|
|
298
|
+
|
|
299
|
+
降级契约:输出与成功路径(check/status,status=READY)**可区分**——
|
|
300
|
+
status="degraded" + degraded=True + degraded_reason + checks_not_run;
|
|
301
|
+
设备可用性一律标注未验证,禁止把"工具在场"写成"目标可运行"。
|
|
302
|
+
"""
|
|
303
|
+
root_path = Path(root) if root is not None else None
|
|
304
|
+
available, availability_detail = is_available(target)
|
|
305
|
+
warnings = [
|
|
306
|
+
"降级模式:仅完成 PATH 工具存在性静态检测;设备/模拟器可用性未验证,"
|
|
307
|
+
"禁止把工具在场当成可运行目标"
|
|
308
|
+
]
|
|
309
|
+
payload: dict[str, Any] = {
|
|
310
|
+
"probe": "platform",
|
|
311
|
+
"status": "degraded",
|
|
312
|
+
"degraded": True,
|
|
313
|
+
"degraded_reason": (
|
|
314
|
+
"device_query_skipped" if available else "channel_tools_missing"
|
|
315
|
+
),
|
|
316
|
+
"success": True,
|
|
317
|
+
"target": target,
|
|
318
|
+
"root": str(root_path) if root_path is not None else None,
|
|
319
|
+
"findings": [],
|
|
320
|
+
"evidence": {
|
|
321
|
+
"availability_detail": availability_detail,
|
|
322
|
+
"host": host_name(),
|
|
323
|
+
},
|
|
324
|
+
"warnings": warnings,
|
|
325
|
+
"checks_not_run": ["adb-devices", "simctl-booted", "xctrace-devices"],
|
|
326
|
+
}
|
|
327
|
+
return payload
|
|
328
|
+
|
|
329
|
+
|
|
259
330
|
def summary_dict(reports: list[Report], *, root: Path | None = None) -> dict[str, Any]:
|
|
260
331
|
"""构建单根标准环境探测报告字典。"""
|
|
261
332
|
eval_reports = reports
|
|
@@ -321,7 +392,17 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
321
392
|
parser.add_argument("--json", action="store_true")
|
|
322
393
|
parser.add_argument("--envelope", action="store_true", default=True)
|
|
323
394
|
parser.add_argument("--no-envelope", dest="envelope", action="store_false")
|
|
395
|
+
parser.add_argument(
|
|
396
|
+
"--static-degraded", action="store_true",
|
|
397
|
+
help="显式执行降级路径(仅 PATH 工具存在性检测;输出 status=degraded,"
|
|
398
|
+
"不查询设备/模拟器)",
|
|
399
|
+
)
|
|
324
400
|
args = parser.parse_args(argv)
|
|
401
|
+
if args.static_degraded:
|
|
402
|
+
print(json.dumps(
|
|
403
|
+
run_static_degraded(args.target, args.root), ensure_ascii=False, indent=2,
|
|
404
|
+
))
|
|
405
|
+
return 0
|
|
325
406
|
reports = reports_for(args.target, args.root)
|
|
326
407
|
print_reports(reports, as_json=args.json, envelope=args.envelope, root=args.root)
|
|
327
408
|
if all(report.ready for report in reports):
|
|
@@ -37,6 +37,15 @@ PROBE_TIMEOUT_BUDGET: dict[str, float] = {
|
|
|
37
37
|
# 结果翻转。这里给出显式预算,消除该非确定性。
|
|
38
38
|
"platform": 30.0,
|
|
39
39
|
"memory": 20.0,
|
|
40
|
+
# mobile 探针逐 tier 拉起 adb/xcrun/maestro/appium 子进程,且 maestro 是
|
|
41
|
+
# JVM 工具:冷启动 --version 实测 7.5s(arm64 本机);版本探测已并行+2s
|
|
42
|
+
# 硬顶后单跑 ~3.4s,但 pre 并行跑全部探针时 CPU 争抢实测 5.13s,沿用
|
|
43
|
+
# default 5.0s 仍临界假超时并触发「安装决策」阻断链
|
|
44
|
+
# (F-RSI-20261118-004/005)。15s 提供 3x 余量,与 platform 冷启动策略一致。
|
|
45
|
+
"mobile": 15.0,
|
|
46
|
+
# openwiki 冷启动读索引约 2.3s,并行满载时临界 5s;建议性探针假超时
|
|
47
|
+
# 只产生噪音告警,同样的预算策略消除翻转。
|
|
48
|
+
"openwiki": 10.0,
|
|
40
49
|
"default": 5.0,
|
|
41
50
|
}
|
|
42
51
|
PROBE_TIMEOUT_MAX_SECONDS = 120.0
|
|
@@ -192,6 +201,17 @@ _BUILTIN_PROBES: tuple[ProbeDescriptor, ...] = (
|
|
|
192
201
|
# 设备/工具状态为宿主级;形态、目标平台由报告重投影处理。
|
|
193
202
|
cache_scope="host",
|
|
194
203
|
),
|
|
204
|
+
ProbeDescriptor(
|
|
205
|
+
name="android",
|
|
206
|
+
script="android_probe.py",
|
|
207
|
+
domain="mobile",
|
|
208
|
+
accepts_root=True,
|
|
209
|
+
description="Android 探针(Manifest 静态语义 + adb 动态 Intent)",
|
|
210
|
+
priority=59,
|
|
211
|
+
lifecycle="runtime",
|
|
212
|
+
readiness_args=("check",),
|
|
213
|
+
required=False,
|
|
214
|
+
),
|
|
195
215
|
ProbeDescriptor(
|
|
196
216
|
name="ios_binary",
|
|
197
217
|
script="ios_binary_probe.py",
|
|
@@ -472,15 +492,19 @@ def _cached_profile(
|
|
|
472
492
|
|
|
473
493
|
|
|
474
494
|
def _cached_probe_is_reusable(name: str, report: Mapping[str, Any]) -> bool:
|
|
475
|
-
"""
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
495
|
+
"""判定缓存的探针报告能否复用(跳过本次重探)。
|
|
496
|
+
|
|
497
|
+
F-RSI-20261118-005 深层语义:``BLOCKED``/``DEGRADED`` 是**环境时刻相关**
|
|
498
|
+
的失败结论——宿主环境恢复(如模拟器启动)后,30 分钟 TTL 内的缓存自锁
|
|
499
|
+
会让恢复不可见(真机实证:模拟器就绪后 pre 仍连续阻断)。因此失败/降级
|
|
500
|
+
结论一律不可复用(每次重查,成本仅几秒);只有 ``READY``/``NOT_APPLICABLE``
|
|
501
|
+
/``ABSENT`` 才进入 30 分钟复用窗口。Codebase Memory 额外校验版本 pin:
|
|
502
|
+
其就绪依赖可替换的外部可执行文件,缓存的成功必须证明当前精确 pin。
|
|
481
503
|
"""
|
|
482
504
|
status = str(report.get("status", "")).upper()
|
|
483
|
-
if status
|
|
505
|
+
if status in {"BLOCKED", "DEGRADED"}:
|
|
506
|
+
return False
|
|
507
|
+
if status not in {"READY", "NOT_APPLICABLE", "ABSENT"}:
|
|
484
508
|
return False
|
|
485
509
|
if name != "codebase-memory":
|
|
486
510
|
return True
|
|
@@ -1667,3 +1691,80 @@ def run_preflight_probes(
|
|
|
1667
1691
|
pass
|
|
1668
1692
|
|
|
1669
1693
|
return profile
|
|
1694
|
+
|
|
1695
|
+
|
|
1696
|
+
def is_available() -> tuple[bool, str]:
|
|
1697
|
+
"""降级契约:机械探活内置探针注册表完整性(零子进程、零探针执行)。
|
|
1698
|
+
|
|
1699
|
+
判定两条机械事实:注册表非空,且每个内置描述符声明的脚本文件真实存在。
|
|
1700
|
+
脚本缺失说明引擎安装损坏,调用方必须走 ``run_static_degraded`` 只输出
|
|
1701
|
+
静态注册表快照,禁止伪装探针执行就绪。
|
|
1702
|
+
"""
|
|
1703
|
+
if not _REGISTRY:
|
|
1704
|
+
return False, "探针注册表为空;没有可分发的探针"
|
|
1705
|
+
# 描述符 script 相对引擎根(core/)解析,复用与执行链相同的
|
|
1706
|
+
# _resolve_probe_script 候选规则,避免把「脚本已迁移」误报成「脚本缺失」。
|
|
1707
|
+
core_dir = Path(__file__).resolve().parent.parent
|
|
1708
|
+
missing = sorted(
|
|
1709
|
+
descriptor.script
|
|
1710
|
+
for descriptor in _REGISTRY.values()
|
|
1711
|
+
if not _resolve_probe_script(core_dir, descriptor.script).is_file()
|
|
1712
|
+
)
|
|
1713
|
+
if missing:
|
|
1714
|
+
return False, f"探针脚本缺失: {', '.join(missing)}"
|
|
1715
|
+
return True, f"{len(_REGISTRY)} 个内置探针脚本齐全"
|
|
1716
|
+
|
|
1717
|
+
|
|
1718
|
+
def run_static_degraded(name: str | None = None) -> dict[str, Any]:
|
|
1719
|
+
"""降级契约:不执行任何探针子进程,只输出注册表静态快照。
|
|
1720
|
+
|
|
1721
|
+
输出与成功路径(``run_probe_readiness`` / profile 合成的真实探针执行报告)
|
|
1722
|
+
字段级可区分:``status="degraded"`` + ``degraded=True`` + ``degraded_reason``,
|
|
1723
|
+
每个条目只含描述符元数据并显式声明 ``executed=False``,禁止把静态快照
|
|
1724
|
+
伪装成探针执行结果。
|
|
1725
|
+
"""
|
|
1726
|
+
available, availability_detail = is_available()
|
|
1727
|
+
probes = list_probes()
|
|
1728
|
+
if name:
|
|
1729
|
+
descriptor = get_probe(name)
|
|
1730
|
+
probes = [descriptor] if descriptor is not None else []
|
|
1731
|
+
unknown = descriptor is None
|
|
1732
|
+
else:
|
|
1733
|
+
unknown = False
|
|
1734
|
+
entries = [
|
|
1735
|
+
{
|
|
1736
|
+
"name": p.name,
|
|
1737
|
+
"script": p.script,
|
|
1738
|
+
"domain": p.domain,
|
|
1739
|
+
"lifecycle": p.lifecycle,
|
|
1740
|
+
"priority": p.priority,
|
|
1741
|
+
"accepts_root": p.accepts_root,
|
|
1742
|
+
"required": p.required,
|
|
1743
|
+
"critical": p.critical,
|
|
1744
|
+
"cache_scope": p.cache_scope,
|
|
1745
|
+
"readiness_action_declared": p.readiness_args is not None,
|
|
1746
|
+
"executed": False,
|
|
1747
|
+
}
|
|
1748
|
+
for p in probes
|
|
1749
|
+
]
|
|
1750
|
+
return {
|
|
1751
|
+
"schema_version": 1,
|
|
1752
|
+
"success": bool(entries) and not unknown,
|
|
1753
|
+
"status": "degraded",
|
|
1754
|
+
"degraded": True,
|
|
1755
|
+
"degraded_reason": (
|
|
1756
|
+
"unknown_probe" if unknown
|
|
1757
|
+
else "static_mode_forced" if available else "probe_registry_incomplete"
|
|
1758
|
+
),
|
|
1759
|
+
"probe_mode": "static_degraded",
|
|
1760
|
+
"registry_total": len(_REGISTRY),
|
|
1761
|
+
"count": len(entries),
|
|
1762
|
+
"entries": entries,
|
|
1763
|
+
"findings": [],
|
|
1764
|
+
"evidence": {"availability_detail": availability_detail},
|
|
1765
|
+
"metadata": {
|
|
1766
|
+
"degraded_mode": "registry_snapshot_only",
|
|
1767
|
+
"probe_execution_skipped": True,
|
|
1768
|
+
"fallback": "注册表不可用或探针执行被跳过时只提供描述符元数据;禁止据此判定环境就绪",
|
|
1769
|
+
},
|
|
1770
|
+
}
|