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
|
@@ -20,13 +20,14 @@ from __future__ import annotations
|
|
|
20
20
|
|
|
21
21
|
import json
|
|
22
22
|
import os
|
|
23
|
+
import shutil
|
|
23
24
|
import tempfile
|
|
24
25
|
from pathlib import Path
|
|
25
26
|
from typing import Any
|
|
26
27
|
|
|
27
28
|
from .base import AcpPlugin
|
|
28
29
|
|
|
29
|
-
__all__ = ["OpenCodeAcpPlugin", "PLUGIN"]
|
|
30
|
+
__all__ = ["OpenCodeAcpPlugin", "PLUGIN", "is_available", "run_static_degraded"]
|
|
30
31
|
|
|
31
32
|
|
|
32
33
|
class OpenCodeAcpPlugin(AcpPlugin):
|
|
@@ -152,3 +153,57 @@ class OpenCodeAcpPlugin(AcpPlugin):
|
|
|
152
153
|
|
|
153
154
|
|
|
154
155
|
PLUGIN = OpenCodeAcpPlugin
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
def is_available() -> tuple[bool, str]:
|
|
159
|
+
"""降级契约:机械探活宿主 CLI 是否安装(零子进程 ``shutil.which``)。
|
|
160
|
+
|
|
161
|
+
ACP 适配器探活语义:宿主 CLI 缺失时本适配器无法拉起任何真实 ACP 会话,
|
|
162
|
+
调用方必须走 :func:`run_static_degraded` 输出静态适配器事实声明;真实 ACP
|
|
163
|
+
可达性(仅 ``acp_status == "ready"`` 的宿主适用)归宿主探活链路验证,
|
|
164
|
+
本函数不发任何子进程。
|
|
165
|
+
"""
|
|
166
|
+
path = shutil.which(PLUGIN.executable)
|
|
167
|
+
if path is None:
|
|
168
|
+
return False, (
|
|
169
|
+
f"{PLUGIN.executable} 可执行文件未安装;ACP 适配器无法拉起真实会话"
|
|
170
|
+
)
|
|
171
|
+
return True, path
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
def run_static_degraded(root: Path | None = None) -> dict:
|
|
175
|
+
"""宿主 CLI 缺失/降级时的静态输出:只声明适配器事实,绝不伪装 ACP 会话。
|
|
176
|
+
|
|
177
|
+
与真实 ACP 探活输出字段级可区分:``status="degraded"`` + ``degraded=True``
|
|
178
|
+
+ ``degraded_reason``;``acp_status`` 保持机读声明,MCP 健康显式 ``unknown``
|
|
179
|
+
(真实可达性归宿主探活链路,本函数不探 MCP、不发子进程)。
|
|
180
|
+
"""
|
|
181
|
+
available, availability_detail = is_available()
|
|
182
|
+
plugin = PLUGIN()
|
|
183
|
+
return {
|
|
184
|
+
"adapter": f"core/host_acp/{plugin.name}.py",
|
|
185
|
+
"plugin": plugin.name,
|
|
186
|
+
"schema_version": 1,
|
|
187
|
+
"success": available,
|
|
188
|
+
"status": "degraded",
|
|
189
|
+
"degraded": True,
|
|
190
|
+
"degraded_reason": (
|
|
191
|
+
"static_facts_only" if available else f"{plugin.name}_cli_not_installed"
|
|
192
|
+
),
|
|
193
|
+
"probe_mode": "static_degraded",
|
|
194
|
+
"acp_status": plugin.status,
|
|
195
|
+
"acp_supported": plugin.supports_acp(),
|
|
196
|
+
"acp_reason": plugin.reason or None,
|
|
197
|
+
"executable": plugin.executable,
|
|
198
|
+
"mcp_health": "unknown",
|
|
199
|
+
"findings": [],
|
|
200
|
+
"evidence": {
|
|
201
|
+
"availability_detail": availability_detail,
|
|
202
|
+
"project_root": str(root) if root else None,
|
|
203
|
+
},
|
|
204
|
+
"metadata": {
|
|
205
|
+
"degraded_mode": "static_adapter_facts_only",
|
|
206
|
+
"mcp_probing": "deferred_to_host_probe_chain",
|
|
207
|
+
"fallback": "宿主 CLI 缺失时由外层宿主/用户决策接管;BugX 不代装宿主 CLI",
|
|
208
|
+
},
|
|
209
|
+
}
|
package/core/host_acp/pi.py
CHANGED
|
@@ -13,9 +13,12 @@
|
|
|
13
13
|
|
|
14
14
|
from __future__ import annotations
|
|
15
15
|
|
|
16
|
+
import shutil
|
|
17
|
+
from pathlib import Path
|
|
18
|
+
|
|
16
19
|
from .base import AcpPlugin
|
|
17
20
|
|
|
18
|
-
__all__ = ["PiAcpPlugin", "PLUGIN"]
|
|
21
|
+
__all__ = ["PiAcpPlugin", "PLUGIN", "is_available", "run_static_degraded"]
|
|
19
22
|
|
|
20
23
|
#: 宿主名由模块名派生(``core/host_acp/<host>.py``),实现体不写字面量。
|
|
21
24
|
_HOST_NAME = __name__.rsplit(".", 1)[-1]
|
|
@@ -34,3 +37,58 @@ class PiAcpPlugin(AcpPlugin):
|
|
|
34
37
|
|
|
35
38
|
|
|
36
39
|
PLUGIN = PiAcpPlugin
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def is_available() -> tuple[bool, str]:
|
|
43
|
+
"""降级契约:机械探活宿主 CLI 是否安装(零子进程 ``shutil.which``)。
|
|
44
|
+
|
|
45
|
+
ACP 适配器探活语义:宿主 CLI 缺失时本适配器无法拉起任何真实 ACP 会话,
|
|
46
|
+
调用方必须走 :func:`run_static_degraded` 输出静态适配器事实声明;真实 ACP
|
|
47
|
+
可达性(仅 ``acp_status == "ready"`` 的宿主适用)归宿主探活链路验证,
|
|
48
|
+
本函数不发任何子进程。
|
|
49
|
+
"""
|
|
50
|
+
path = shutil.which(PLUGIN.executable)
|
|
51
|
+
if path is None:
|
|
52
|
+
return False, (
|
|
53
|
+
f"{PLUGIN.executable} 可执行文件未安装;ACP 适配器无法拉起真实会话"
|
|
54
|
+
)
|
|
55
|
+
return True, path
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def run_static_degraded(root: Path | None = None) -> dict:
|
|
59
|
+
"""宿主 CLI 缺失/降级时的静态输出:只声明适配器事实,绝不伪装 ACP 会话。
|
|
60
|
+
|
|
61
|
+
与真实 ACP 探活输出字段级可区分:``status="degraded"`` + ``degraded=True``
|
|
62
|
+
+ ``degraded_reason``;``acp_status`` 保持上游机读声明(``unavailable`` =
|
|
63
|
+
宿主产品没有 ACP 协议面,非本仓欠适配),MCP 健康显式 ``unknown``
|
|
64
|
+
(真实可达性归宿主探活链路,本函数不探 MCP、不发子进程)。
|
|
65
|
+
"""
|
|
66
|
+
available, availability_detail = is_available()
|
|
67
|
+
plugin = PLUGIN()
|
|
68
|
+
return {
|
|
69
|
+
"adapter": f"core/host_acp/{plugin.name}.py",
|
|
70
|
+
"plugin": plugin.name,
|
|
71
|
+
"schema_version": 1,
|
|
72
|
+
"success": available,
|
|
73
|
+
"status": "degraded",
|
|
74
|
+
"degraded": True,
|
|
75
|
+
"degraded_reason": (
|
|
76
|
+
"static_facts_only" if available else f"{plugin.name}_cli_not_installed"
|
|
77
|
+
),
|
|
78
|
+
"probe_mode": "static_degraded",
|
|
79
|
+
"acp_status": plugin.status,
|
|
80
|
+
"acp_supported": plugin.supports_acp(),
|
|
81
|
+
"acp_reason": plugin.reason or None,
|
|
82
|
+
"executable": plugin.executable,
|
|
83
|
+
"mcp_health": "unknown",
|
|
84
|
+
"findings": [],
|
|
85
|
+
"evidence": {
|
|
86
|
+
"availability_detail": availability_detail,
|
|
87
|
+
"project_root": str(root) if root else None,
|
|
88
|
+
},
|
|
89
|
+
"metadata": {
|
|
90
|
+
"degraded_mode": "static_adapter_facts_only",
|
|
91
|
+
"mcp_probing": "deferred_to_host_probe_chain",
|
|
92
|
+
"fallback": "宿主 CLI 缺失时由外层宿主/用户决策接管;BugX 不代装宿主 CLI",
|
|
93
|
+
},
|
|
94
|
+
}
|
package/core/host_acp/zcode.py
CHANGED
|
@@ -17,9 +17,12 @@
|
|
|
17
17
|
|
|
18
18
|
from __future__ import annotations
|
|
19
19
|
|
|
20
|
+
import shutil
|
|
21
|
+
from pathlib import Path
|
|
22
|
+
|
|
20
23
|
from .base import AcpPlugin
|
|
21
24
|
|
|
22
|
-
__all__ = ["ZCodeAcpPlugin", "PLUGIN"]
|
|
25
|
+
__all__ = ["ZCodeAcpPlugin", "PLUGIN", "is_available", "run_static_degraded"]
|
|
23
26
|
|
|
24
27
|
#: 宿主名由模块名派生(``core/host_acp/<host>.py``),实现体不写字面量。
|
|
25
28
|
_HOST_NAME = __name__.rsplit(".", 1)[-1]
|
|
@@ -39,3 +42,58 @@ class ZCodeAcpPlugin(AcpPlugin):
|
|
|
39
42
|
|
|
40
43
|
|
|
41
44
|
PLUGIN = ZCodeAcpPlugin
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def is_available() -> tuple[bool, str]:
|
|
48
|
+
"""降级契约:机械探活宿主 CLI 是否安装(零子进程 ``shutil.which``)。
|
|
49
|
+
|
|
50
|
+
ACP 适配器探活语义:宿主 CLI 缺失时本适配器无法拉起任何真实 ACP 会话,
|
|
51
|
+
调用方必须走 :func:`run_static_degraded` 输出静态适配器事实声明;真实 ACP
|
|
52
|
+
可达性(仅 ``acp_status == "ready"`` 的宿主适用)归宿主探活链路验证,
|
|
53
|
+
本函数不发任何子进程。
|
|
54
|
+
"""
|
|
55
|
+
path = shutil.which(PLUGIN.executable)
|
|
56
|
+
if path is None:
|
|
57
|
+
return False, (
|
|
58
|
+
f"{PLUGIN.executable} 可执行文件未安装;ACP 适配器无法拉起真实会话"
|
|
59
|
+
)
|
|
60
|
+
return True, path
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def run_static_degraded(root: Path | None = None) -> dict:
|
|
64
|
+
"""宿主 CLI 缺失/降级时的静态输出:只声明适配器事实,绝不伪装 ACP 会话。
|
|
65
|
+
|
|
66
|
+
与真实 ACP 探活输出字段级可区分:``status="degraded"`` + ``degraded=True``
|
|
67
|
+
+ ``degraded_reason``;``acp_status`` 保持上游机读声明(``unavailable`` =
|
|
68
|
+
宿主产品没有 ACP 协议面,非本仓欠适配),MCP 健康显式 ``unknown``
|
|
69
|
+
(真实可达性归宿主探活链路,本函数不探 MCP、不发子进程)。
|
|
70
|
+
"""
|
|
71
|
+
available, availability_detail = is_available()
|
|
72
|
+
plugin = PLUGIN()
|
|
73
|
+
return {
|
|
74
|
+
"adapter": f"core/host_acp/{plugin.name}.py",
|
|
75
|
+
"plugin": plugin.name,
|
|
76
|
+
"schema_version": 1,
|
|
77
|
+
"success": available,
|
|
78
|
+
"status": "degraded",
|
|
79
|
+
"degraded": True,
|
|
80
|
+
"degraded_reason": (
|
|
81
|
+
"static_facts_only" if available else f"{plugin.name}_cli_not_installed"
|
|
82
|
+
),
|
|
83
|
+
"probe_mode": "static_degraded",
|
|
84
|
+
"acp_status": plugin.status,
|
|
85
|
+
"acp_supported": plugin.supports_acp(),
|
|
86
|
+
"acp_reason": plugin.reason or None,
|
|
87
|
+
"executable": plugin.executable,
|
|
88
|
+
"mcp_health": "unknown",
|
|
89
|
+
"findings": [],
|
|
90
|
+
"evidence": {
|
|
91
|
+
"availability_detail": availability_detail,
|
|
92
|
+
"project_root": str(root) if root else None,
|
|
93
|
+
},
|
|
94
|
+
"metadata": {
|
|
95
|
+
"degraded_mode": "static_adapter_facts_only",
|
|
96
|
+
"mcp_probing": "deferred_to_host_probe_chain",
|
|
97
|
+
"fallback": "宿主 CLI 缺失时由外层宿主/用户决策接管;BugX 不代装宿主 CLI",
|
|
98
|
+
},
|
|
99
|
+
}
|
|
@@ -21,5 +21,5 @@ from core.host_runtime import detect_host_runtime
|
|
|
21
21
|
```
|
|
22
22
|
|
|
23
23
|
## 5. Maintenance & Verification
|
|
24
|
-
-
|
|
24
|
+
- Verification is performed with short-lived tests outside the repository; no persistent `tests/` registry is retained.
|
|
25
25
|
- Changes to exported interfaces must be synchronized via `python3 scripts/gen_interface_spec.py --package core/host_runtime --write`.
|
|
@@ -356,7 +356,7 @@ def host_adapter(name: str) -> HostAdapter:
|
|
|
356
356
|
# 在 detect_host 时静默退化成 UnknownAdapter(那会让真实宿主的 Supervisor MCP
|
|
357
357
|
# 被误判为硬缺失)。
|
|
358
358
|
_MISSING_ADAPTERS = [name for name in host_registry.SUPPORTED_HOSTS if name not in _ADAPTERS]
|
|
359
|
-
if _MISSING_ADAPTERS: # pragma: no cover -
|
|
359
|
+
if _MISSING_ADAPTERS: # pragma: no cover - 缺适配器即 fail-fast,契约以本注释为准
|
|
360
360
|
raise RuntimeError(f"宿主注册表与适配器不一致,缺少: {', '.join(_MISSING_ADAPTERS)}")
|
|
361
361
|
|
|
362
362
|
|
|
@@ -343,12 +343,25 @@ def execute_worker(
|
|
|
343
343
|
f"{failure}: 未检测到任何可用的 Cline Provider 配置或凭据 "
|
|
344
344
|
"(缺少 providers.json 且未设置凭据环境变量)"
|
|
345
345
|
)
|
|
346
|
+
# 宿主 profile 预算基数(``worker_timeout_seconds``,导入期 validate_plugin 已
|
|
347
|
+
# 强阻断非正数):声明了该字段的宿主以它作为 resolve_worker_timeout 的
|
|
348
|
+
# ``base_override``(保留重试退避与 1800s 钳制);未声明时为 None,与既有
|
|
349
|
+
# tier 阶梯行为逐字节一致(其他宿主零变化)。
|
|
350
|
+
profile_budget = getattr(_PLUGIN.worker_runtime, "worker_timeout_seconds", None)
|
|
351
|
+
base_override = (
|
|
352
|
+
float(profile_budget)
|
|
353
|
+
if isinstance(profile_budget, (int, float))
|
|
354
|
+
and not isinstance(profile_budget, bool)
|
|
355
|
+
and profile_budget > 0
|
|
356
|
+
else None
|
|
357
|
+
)
|
|
346
358
|
timeout_seconds = resolve_worker_timeout(
|
|
347
359
|
model_tier={
|
|
348
360
|
"exploit": "tier_2_exploit",
|
|
349
361
|
"verify": "tier_3_verify",
|
|
350
362
|
}.get(str(stage_name).split("-")[-1], "tier_1_recon"),
|
|
351
363
|
attempt=int(getattr(claim, "attempt", 1) or 1),
|
|
364
|
+
base_override=base_override,
|
|
352
365
|
)
|
|
353
366
|
host_executable = _PLUGIN.identity.executable
|
|
354
367
|
executable = executable or shutil.which(host_executable) or host_executable
|
|
@@ -21,6 +21,7 @@ from .free_models import (
|
|
|
21
21
|
is_subscription_token,
|
|
22
22
|
score_free_model_capability,
|
|
23
23
|
)
|
|
24
|
+
from .provider_facts import credits_exhausted, load_provider_availability_facts
|
|
24
25
|
|
|
25
26
|
logger = logging.getLogger(__name__)
|
|
26
27
|
|
|
@@ -81,6 +82,7 @@ def evaluate_cline_provider(
|
|
|
81
82
|
data_dir: Path | None = None,
|
|
82
83
|
*,
|
|
83
84
|
preferred_free_model: str | None = None,
|
|
85
|
+
external_facts: Mapping[str, Any] | None = None,
|
|
84
86
|
) -> ProviderCandidate:
|
|
85
87
|
"""评估 Cline 单个 Provider 候选条目并评定梯队。"""
|
|
86
88
|
now = now_ts if now_ts is not None else time.time()
|
|
@@ -204,7 +206,15 @@ def evaluate_cline_provider(
|
|
|
204
206
|
supports_reasoning=reasoning,
|
|
205
207
|
))
|
|
206
208
|
|
|
207
|
-
|
|
209
|
+
# 可用性事实守卫(评估层补全,E1 观察 #2 / A3 残余根治):is_free_model 命名匹配
|
|
210
|
+
# 此前在任何余额检查之前短路 TIER_1_FREE。通道携带 credits 耗尽 / 0 余额事实时
|
|
211
|
+
# 跳过该短路,通道按常规梯队继续评估并参与排序(聚合层守卫仍整体降级留痕);
|
|
212
|
+
# 无任何耗尽事实时 credits_exhausted 恒为 False,本短路行为逐字节不变。
|
|
213
|
+
if prov_free_candidates and not credits_exhausted(
|
|
214
|
+
name,
|
|
215
|
+
info,
|
|
216
|
+
external_facts if external_facts is not None else load_provider_availability_facts(),
|
|
217
|
+
):
|
|
208
218
|
prov_free_candidates.sort(key=lambda c: c.rank_tuple)
|
|
209
219
|
best_free, manifest = evaluate_and_select_free_model(
|
|
210
220
|
prov_free_candidates,
|
|
@@ -337,12 +347,18 @@ def evaluate_zcode_candidates(
|
|
|
337
347
|
*,
|
|
338
348
|
preferred_domain: str | None = None,
|
|
339
349
|
preferred_model: str | None = None,
|
|
350
|
+
external_facts: Mapping[str, Any] | None = None,
|
|
340
351
|
) -> list[ProviderCandidate]:
|
|
341
352
|
"""全量探查 ZCode 宿主环境中的候选通道(官方订阅、凭据、自定义规则)。"""
|
|
342
353
|
v2 = v2_dir or (Path.home() / ".zcode" / "v2")
|
|
343
354
|
candidates: list[ProviderCandidate] = []
|
|
344
355
|
if not v2.is_dir():
|
|
345
356
|
return candidates
|
|
357
|
+
# 可用性事实守卫(A3/D2 同型扩轴,与 cline 共用消费端 credits_exhausted):
|
|
358
|
+
# 通道余额是机器本地事实、与宿主无关,故继续共用既有受控事实库
|
|
359
|
+
# (provider_facts.PROVIDER_FACTS_FILE,schema 键为通道名,向后兼容);
|
|
360
|
+
# 缺失/损坏时 fail-open 返回空,无任何耗尽事实时行为逐字节不变。
|
|
361
|
+
facts = external_facts if external_facts is not None else load_provider_availability_facts()
|
|
346
362
|
|
|
347
363
|
# 1. 探查 coding-plan-cache.json 中的官方订阅套餐 (Tier 2)
|
|
348
364
|
cache_file = v2 / "coding-plan-cache.json"
|
|
@@ -458,7 +474,13 @@ def evaluate_zcode_candidates(
|
|
|
458
474
|
continue
|
|
459
475
|
|
|
460
476
|
# 检查是否有免费模型 (Tier 1)
|
|
461
|
-
|
|
477
|
+
# 可用性事实守卫(A3/D2 同型扩轴):is_free_model 命名匹配此前在
|
|
478
|
+
# 任何余额检查之前短路 TIER_1_FREE。通道携带 credits 耗尽 / 0 余额
|
|
479
|
+
# 事实(条目显式声明优先,其次受控事实库)时跳过该短路,通道按
|
|
480
|
+
# 常规梯队继续评估并参与排序;无任何耗尽事实时本短路行为逐字节不变。
|
|
481
|
+
has_free = any(is_free_model(str(m), base_url) for m in models) and not credits_exhausted(
|
|
482
|
+
p_id, rule, facts,
|
|
483
|
+
)
|
|
462
484
|
if has_free:
|
|
463
485
|
free_m = next(m for m in models if is_free_model(str(m), base_url))
|
|
464
486
|
score, cat, scale, r_text, _ = score_free_model_capability(str(free_m))
|
|
@@ -514,9 +536,13 @@ def evaluate_opencode_candidates(
|
|
|
514
536
|
*,
|
|
515
537
|
preferred_provider: str | None = None,
|
|
516
538
|
preferred_model: str | None = None,
|
|
539
|
+
external_facts: Mapping[str, Any] | None = None,
|
|
517
540
|
) -> list[ProviderCandidate]:
|
|
518
541
|
"""全量探查 OpenCode 宿主环境中的候选通道。"""
|
|
519
542
|
candidates: list[ProviderCandidate] = []
|
|
543
|
+
# 可用性事实守卫(A3/D2 同型扩轴):与 cline/zcode 共用同一受控事实库
|
|
544
|
+
# (通道余额是机器本地事实,schema 键为通道名);缺失/损坏 fail-open 返回空。
|
|
545
|
+
facts = external_facts if external_facts is not None else load_provider_availability_facts()
|
|
520
546
|
target_file: Path | None = None
|
|
521
547
|
if config_dir_or_file:
|
|
522
548
|
target_file = config_dir_or_file if config_dir_or_file.is_file() else (config_dir_or_file / "opencode.json")
|
|
@@ -568,7 +594,12 @@ def evaluate_opencode_candidates(
|
|
|
568
594
|
continue
|
|
569
595
|
|
|
570
596
|
# 免费模型 (Tier 1)
|
|
571
|
-
|
|
597
|
+
# 可用性事实守卫(A3/D2 同型扩轴):携带 credits 耗尽 / 0 余额事实的通道
|
|
598
|
+
# 跳过 is_free_model 命名短路,按常规梯队继续评估参与排序;
|
|
599
|
+
# 无任何耗尽事实时本短路行为逐字节不变。
|
|
600
|
+
has_free = any(is_free_model(str(m), base_url) for m in model_names) and not credits_exhausted(
|
|
601
|
+
p_name, p_info, facts,
|
|
602
|
+
)
|
|
572
603
|
if has_free:
|
|
573
604
|
free_m = next(m for m in model_names if is_free_model(str(m), base_url))
|
|
574
605
|
score, cat, scale, r_text, _ = score_free_model_capability(str(free_m))
|
|
@@ -621,12 +652,16 @@ def evaluate_pi_candidates(
|
|
|
621
652
|
*,
|
|
622
653
|
preferred_provider: str | None = None,
|
|
623
654
|
preferred_model: str | None = None,
|
|
655
|
+
external_facts: Mapping[str, Any] | None = None,
|
|
624
656
|
) -> list[ProviderCandidate]:
|
|
625
657
|
"""全量探查 Pi 宿主环境中的候选通道。"""
|
|
626
658
|
candidates: list[ProviderCandidate] = []
|
|
627
659
|
pi_dir = agent_dir or (Path.home() / ".pi" / "agent")
|
|
628
660
|
if not pi_dir.is_dir():
|
|
629
661
|
return candidates
|
|
662
|
+
# 可用性事实守卫(A3/D2 同型扩轴):与 cline/zcode/opencode 共用同一受控
|
|
663
|
+
# 事实库(通道余额是机器本地事实,schema 键为通道名);缺失/损坏 fail-open 返回空。
|
|
664
|
+
facts = external_facts if external_facts is not None else load_provider_availability_facts()
|
|
630
665
|
|
|
631
666
|
auth_file = pi_dir / "auth.json"
|
|
632
667
|
models_file = pi_dir / "models.json"
|
|
@@ -674,7 +709,12 @@ def evaluate_pi_candidates(
|
|
|
674
709
|
))
|
|
675
710
|
continue
|
|
676
711
|
|
|
677
|
-
|
|
712
|
+
# 可用性事实守卫(A3/D2 同型扩轴):携带 credits 耗尽 / 0 余额事实的通道
|
|
713
|
+
# 跳过 is_free_model 命名短路,按常规梯队继续评估参与排序;
|
|
714
|
+
# 无任何耗尽事实时本短路行为逐字节不变。
|
|
715
|
+
has_free = any(is_free_model(str(m), base_url) for m in model_ids) and not credits_exhausted(
|
|
716
|
+
p_name, p_conf, facts,
|
|
717
|
+
)
|
|
678
718
|
if has_free:
|
|
679
719
|
free_m = next(m for m in model_ids if is_free_model(str(m), base_url))
|
|
680
720
|
score, cat, scale, r_text, _ = score_free_model_capability(str(free_m))
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
为什么独立成模块(架构收敛,2026-10-26):``host_registry`` 与 ``supervisor_host``
|
|
5
5
|
此前互为依赖——``host_registry`` 在探测分支里 `import supervisor_host`,而
|
|
6
6
|
``supervisor_host`` 顶层 `import host_registry`。这类双向依赖把「模块依赖方向」从
|
|
7
|
-
|
|
7
|
+
静态可分析变成运行期才发现(导入图无环约束,人工核查为准)。
|
|
8
8
|
|
|
9
9
|
探测原语本身只依赖 ``startup_environment``(进程祖先链 + 可执行段识别),与
|
|
10
10
|
宿主适配器注册表无关,因此可以下沉到本模块:
|
|
@@ -12,6 +12,10 @@
|
|
|
12
12
|
- Tier 3: 官方原生直接 API Key (Official Direct Key) - 如 OpenAI/Anthropic/Google 直连
|
|
13
13
|
- Tier 4: 第三方代理与中转路由 (Third-Party Router) - 如 9router, OpenRouter
|
|
14
14
|
- Tier 5: 按量扣费点数代扣通道 (Usage-Billing / Credits) - 如 Cline Credits
|
|
15
|
+
|
|
16
|
+
可用性守卫(availability guard,E1 验收实证 #2):tier 语义是"可用性优先"而非
|
|
17
|
+
"命名即胜"。通道声明携带 0 余额 / credits 耗尽可用性事实时,该通道在阶梯排序中
|
|
18
|
+
整体降级到最后,不得凭 ":free" 等命名匹配压过实测可用的高梯队路由。
|
|
15
19
|
"""
|
|
16
20
|
|
|
17
21
|
from __future__ import annotations
|
|
@@ -82,6 +86,11 @@ from .host_evaluators import (
|
|
|
82
86
|
evaluate_pi_candidates,
|
|
83
87
|
evaluate_zcode_candidates,
|
|
84
88
|
)
|
|
89
|
+
from .provider_facts import (
|
|
90
|
+
PROVIDER_FACTS_FILE,
|
|
91
|
+
credits_exhausted,
|
|
92
|
+
load_provider_availability_facts,
|
|
93
|
+
)
|
|
85
94
|
|
|
86
95
|
|
|
87
96
|
class HostProviderArbitrator:
|
|
@@ -107,6 +116,26 @@ class HostProviderArbitrator:
|
|
|
107
116
|
def evaluate_pi_candidates(cls, *args, **kwargs) -> list[ProviderCandidate]:
|
|
108
117
|
return evaluate_pi_candidates(cls, *args, **kwargs)
|
|
109
118
|
|
|
119
|
+
# ---- 可用性事实守卫(availability facts guard, E1 实证 #2)----
|
|
120
|
+
# 事实提取实现已抽取至共享模块 provider_facts(评估层 is_free_model 短路判定
|
|
121
|
+
# 消费同一事实源);本类保留转发入口,对外调用面与类级常量逐字节不变。
|
|
122
|
+
PROVIDER_FACTS_FILE = PROVIDER_FACTS_FILE
|
|
123
|
+
|
|
124
|
+
@classmethod
|
|
125
|
+
def _load_provider_availability_facts(cls, facts_file: Path | None = None) -> dict[str, Any]:
|
|
126
|
+
"""读取通道可用性事实声明(转发共享模块;缺失/损坏时 fail-open 返回空)。"""
|
|
127
|
+
return load_provider_availability_facts(facts_file or cls.PROVIDER_FACTS_FILE)
|
|
128
|
+
|
|
129
|
+
@classmethod
|
|
130
|
+
def _credits_exhausted(
|
|
131
|
+
cls,
|
|
132
|
+
p_name: str,
|
|
133
|
+
p_info: Mapping[str, Any],
|
|
134
|
+
external_facts: Mapping[str, Any] | None = None,
|
|
135
|
+
) -> bool:
|
|
136
|
+
"""判定通道是否携带 credits 耗尽 / 0 余额可用性事实(转发共享模块)。"""
|
|
137
|
+
return credits_exhausted(p_name, p_info, external_facts)
|
|
138
|
+
|
|
110
139
|
@classmethod
|
|
111
140
|
def rank_cline_providers(
|
|
112
141
|
cls,
|
|
@@ -117,10 +146,16 @@ class HostProviderArbitrator:
|
|
|
117
146
|
excluded_providers: set[str] | None = None,
|
|
118
147
|
data_dir: Path | None = None,
|
|
119
148
|
) -> list[ProviderCandidate]:
|
|
120
|
-
"""
|
|
149
|
+
"""扫描并按阶梯优先级排序所有可用通道(可用性优先守卫)。
|
|
150
|
+
|
|
151
|
+
携带 0 余额 / credits 耗尽事实的通道不参与 tier 命名竞争,整体降级到
|
|
152
|
+
健康通道之后(不剔除:仅剩耗尽通道时仍可作为兜底返回)。
|
|
153
|
+
"""
|
|
121
154
|
prov_map = providers_data.get("providers", {}) if isinstance(providers_data, Mapping) else {}
|
|
122
155
|
excluded = excluded_providers or set()
|
|
123
|
-
|
|
156
|
+
external_facts = cls._load_provider_availability_facts()
|
|
157
|
+
healthy: list[ProviderCandidate] = []
|
|
158
|
+
degraded: list[ProviderCandidate] = []
|
|
124
159
|
|
|
125
160
|
for p_name, p_info in prov_map.items():
|
|
126
161
|
if p_name in excluded:
|
|
@@ -131,13 +166,21 @@ class HostProviderArbitrator:
|
|
|
131
166
|
models_data,
|
|
132
167
|
data_dir=data_dir,
|
|
133
168
|
preferred_free_model=preferred_free_model,
|
|
169
|
+
external_facts=external_facts,
|
|
134
170
|
)
|
|
135
171
|
if cand.is_valid and cand.tier != ProviderTier.TIER_9_UNAVAILABLE:
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
172
|
+
if cls._credits_exhausted(p_name, p_info, external_facts):
|
|
173
|
+
cand.metadata["credits_exhausted"] = True
|
|
174
|
+
cand.reason = f"[可用性守卫:credits_exhausted 已降级] {cand.reason}"
|
|
175
|
+
degraded.append(cand)
|
|
176
|
+
else:
|
|
177
|
+
healthy.append(cand)
|
|
178
|
+
|
|
179
|
+
# 排序:tier 单调递增(数值越小越优),然后 score 递减;
|
|
180
|
+
# 可用性守卫:携带耗尽事实的通道整体排在健康通道之后
|
|
181
|
+
healthy.sort(key=lambda c: c.rank_tuple)
|
|
182
|
+
degraded.sort(key=lambda c: c.rank_tuple)
|
|
183
|
+
return healthy + degraded
|
|
141
184
|
|
|
142
185
|
@classmethod
|
|
143
186
|
def select_best_cline_provider(
|
|
@@ -257,25 +300,13 @@ class HostProviderArbitrator:
|
|
|
257
300
|
preferred_domain=requested_domain,
|
|
258
301
|
preferred_model=requested_model,
|
|
259
302
|
)
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
manifest = format_provider_manifest(candidates, host="zcode", selected=c)
|
|
268
|
-
return c.provider_id, requested_model or c.model, c, manifest
|
|
269
|
-
|
|
270
|
-
valid_cands = [c for c in candidates if c.is_valid and c.tier != ProviderTier.TIER_9_UNAVAILABLE]
|
|
271
|
-
if not valid_cands:
|
|
272
|
-
manifest = format_provider_manifest(candidates, host="zcode", selected=candidates[0])
|
|
273
|
-
return None, requested_model, None, manifest
|
|
274
|
-
|
|
275
|
-
best = valid_cands[0]
|
|
276
|
-
manifest = format_provider_manifest(candidates, host="zcode", selected=best)
|
|
277
|
-
final_model = requested_model or best.model
|
|
278
|
-
return best.provider_id, final_model, best, manifest
|
|
303
|
+
return cls._select_best_provider(
|
|
304
|
+
candidates,
|
|
305
|
+
host="zcode",
|
|
306
|
+
requested_provider=requested_domain,
|
|
307
|
+
requested_model=requested_model,
|
|
308
|
+
empty_manifest="*(未发现 ZCode 候选通道)*",
|
|
309
|
+
)
|
|
279
310
|
|
|
280
311
|
@classmethod
|
|
281
312
|
def self_heal_zcode_provider(
|
|
@@ -377,6 +408,51 @@ class HostProviderArbitrator:
|
|
|
377
408
|
"manifest": manifest,
|
|
378
409
|
}
|
|
379
410
|
|
|
411
|
+
@classmethod
|
|
412
|
+
def _select_best_provider(
|
|
413
|
+
cls,
|
|
414
|
+
candidates: Sequence[ProviderCandidate],
|
|
415
|
+
*,
|
|
416
|
+
host: str,
|
|
417
|
+
requested_provider: str | None,
|
|
418
|
+
requested_model: str | None,
|
|
419
|
+
empty_manifest: str,
|
|
420
|
+
) -> tuple[str | None, str | None, ProviderCandidate | None, str]:
|
|
421
|
+
"""Apply the shared provider-choice policy after host-specific evaluation."""
|
|
422
|
+
if not candidates:
|
|
423
|
+
return requested_provider, requested_model, None, empty_manifest
|
|
424
|
+
|
|
425
|
+
if requested_provider:
|
|
426
|
+
for candidate in candidates:
|
|
427
|
+
if (
|
|
428
|
+
candidate.provider_id.lower() == requested_provider.lower()
|
|
429
|
+
and candidate.is_valid
|
|
430
|
+
):
|
|
431
|
+
manifest = format_provider_manifest(
|
|
432
|
+
candidates, host=host, selected=candidate,
|
|
433
|
+
)
|
|
434
|
+
return (
|
|
435
|
+
candidate.provider_id,
|
|
436
|
+
requested_model or candidate.model,
|
|
437
|
+
candidate,
|
|
438
|
+
manifest,
|
|
439
|
+
)
|
|
440
|
+
|
|
441
|
+
valid = [
|
|
442
|
+
candidate
|
|
443
|
+
for candidate in candidates
|
|
444
|
+
if candidate.is_valid and candidate.tier != ProviderTier.TIER_9_UNAVAILABLE
|
|
445
|
+
]
|
|
446
|
+
if not valid:
|
|
447
|
+
manifest = format_provider_manifest(
|
|
448
|
+
candidates, host=host, selected=candidates[0],
|
|
449
|
+
)
|
|
450
|
+
return None, requested_model, None, manifest
|
|
451
|
+
|
|
452
|
+
best = valid[0]
|
|
453
|
+
manifest = format_provider_manifest(candidates, host=host, selected=best)
|
|
454
|
+
return best.provider_id, requested_model or best.model, best, manifest
|
|
455
|
+
|
|
380
456
|
@classmethod
|
|
381
457
|
def select_best_opencode_provider(
|
|
382
458
|
cls,
|
|
@@ -390,24 +466,13 @@ class HostProviderArbitrator:
|
|
|
390
466
|
preferred_provider=requested_provider,
|
|
391
467
|
preferred_model=requested_model,
|
|
392
468
|
)
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
return c.provider_id, requested_model or c.model, c, manifest
|
|
401
|
-
|
|
402
|
-
valid = [c for c in candidates if c.is_valid and c.tier != ProviderTier.TIER_9_UNAVAILABLE]
|
|
403
|
-
if not valid:
|
|
404
|
-
manifest = format_provider_manifest(candidates, host="opencode", selected=candidates[0])
|
|
405
|
-
return None, requested_model, None, manifest
|
|
406
|
-
|
|
407
|
-
best = valid[0]
|
|
408
|
-
manifest = format_provider_manifest(candidates, host="opencode", selected=best)
|
|
409
|
-
final_model = requested_model or best.model
|
|
410
|
-
return best.provider_id, final_model, best, manifest
|
|
469
|
+
return cls._select_best_provider(
|
|
470
|
+
candidates,
|
|
471
|
+
host="opencode",
|
|
472
|
+
requested_provider=requested_provider,
|
|
473
|
+
requested_model=requested_model,
|
|
474
|
+
empty_manifest="*(未发现 OpenCode 候选)*",
|
|
475
|
+
)
|
|
411
476
|
|
|
412
477
|
@classmethod
|
|
413
478
|
def self_heal_opencode_provider(
|
|
@@ -481,24 +546,13 @@ class HostProviderArbitrator:
|
|
|
481
546
|
preferred_provider=requested_provider,
|
|
482
547
|
preferred_model=requested_model,
|
|
483
548
|
)
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
return c.provider_id, requested_model or c.model, c, manifest
|
|
492
|
-
|
|
493
|
-
valid = [c for c in candidates if c.is_valid and c.tier != ProviderTier.TIER_9_UNAVAILABLE]
|
|
494
|
-
if not valid:
|
|
495
|
-
manifest = format_provider_manifest(candidates, host="pi", selected=candidates[0])
|
|
496
|
-
return None, requested_model, None, manifest
|
|
497
|
-
|
|
498
|
-
best = valid[0]
|
|
499
|
-
manifest = format_provider_manifest(candidates, host="pi", selected=best)
|
|
500
|
-
final_model = requested_model or best.model
|
|
501
|
-
return best.provider_id, final_model, best, manifest
|
|
549
|
+
return cls._select_best_provider(
|
|
550
|
+
candidates,
|
|
551
|
+
host="pi",
|
|
552
|
+
requested_provider=requested_provider,
|
|
553
|
+
requested_model=requested_model,
|
|
554
|
+
empty_manifest="*(未发现 Pi 候选)*",
|
|
555
|
+
)
|
|
502
556
|
|
|
503
557
|
@classmethod
|
|
504
558
|
def self_heal_pi_provider(
|