bugx-cli 0.1.3 → 0.1.5
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/core/README.md +5 -3
- package/core/agent/agent_execution.py +7 -0
- package/core/assets/bugx-wechat-group.png +0 -0
- package/core/bugx.md +2 -2
- package/core/bugx_paths.py +10 -2
- package/core/bundled_docs/OVERVIEW.md +311 -0
- package/core/bundled_docs/README.md +10 -0
- package/core/bundled_docs/README_EN.md +278 -0
- package/core/bundled_docs/ai/01_AI_REFERENCE.md +838 -0
- package/core/bundled_docs/ai/02_AI_USAGE.md +161 -0
- package/core/bundled_docs/ai/03_AI_COMMANDS.md +322 -0
- package/core/bundled_docs/guides/01_USER_GUIDE.md +887 -0
- package/core/bundled_docs/guides/02_COMMANDS.md +935 -0
- package/core/bundled_docs/guides/03_TROUBLESHOOTING.md +763 -0
- package/core/bundled_docs/guides/04_CLOUD_AUTH_AND_SYNC_COOKBOOK.md +48 -0
- package/core/bundled_docs/guides/05_HOST_MATRIX_AND_DISPATCH.md +25 -0
- package/core/bundled_docs/guides/06_PROBES_AND_POC_COOKBOOK.md +49 -0
- package/core/bundled_docs/guides/07_LIFECYCLE_AND_RECOVERY_STATES.md +46 -0
- package/core/bundled_docs/guides/08_LESSONS_AND_PRIVACY_BOUNDARY.md +35 -0
- package/core/bundled_docs/hosts/bugx-claude_SKILL.md +326 -0
- package/core/bundled_docs/hosts/bugx-dsh_SKILL.md +229 -0
- package/core/bundled_docs/hosts/bugx-opencode_SKILL.md +129 -0
- package/core/bundled_docs/hosts/bugx-zcode_SKILL.md +459 -0
- package/core/bundled_docs/hosts/bugx_SKILL.md +118 -0
- package/core/bundled_docs/hosts/cline_bugx_SKILL.md +69 -0
- package/core/bundled_docs/hosts/platform_bugx_SKILL.md +50 -0
- package/core/bundled_docs/manifest.json +140 -0
- package/core/bundled_docs/reference/01_ENVIRONMENT_VARIABLES.md +422 -0
- package/core/bundled_docs/reference/04_REPOSITORY_TOPOLOGY.md +180 -0
- package/core/cli-help.txt +7 -3
- package/core/cloud_sync/cloud_client.py +81 -2
- package/core/cloud_sync/endpoint_router.py +22 -9
- package/core/cloud_sync/issue_uploader.py +297 -0
- package/core/cloud_sync/sensitive_filter.py +77 -7
- package/core/contracts/AGENT_GUIDE.md +3 -9
- package/core/contracts/README.md +1 -1
- package/core/contracts/bugx-runtime-contract.md +10 -20
- package/core/contracts/bugx-worker.md +1 -1
- package/core/coverage/coverage_ai_review.py +15 -11
- package/core/coverage/coverage_bootstrap.py +18 -13
- package/core/coverage/coverage_discovery.py +1 -1
- package/core/dev_harness/interaction_preset.py +1 -1
- package/core/engine-integrity.json +283 -159
- package/core/host_acp/README.md +4 -0
- package/core/host_acp/agnescode.py +128 -0
- package/core/host_acp/antigravity.py +153 -0
- package/core/host_runtime/README.md +3 -0
- package/core/host_runtime/adapters.py +5 -1
- package/core/host_runtime/antigravity.py +162 -0
- package/core/host_runtime/host_bootstrap.py +18 -7
- package/core/host_runtime/host_evaluators.py +4 -4
- package/core/host_runtime/host_registry.py +3 -1
- package/core/host_runtime/mcp_process_tracker.py +30 -3
- package/core/host_runtime/mcp_registry_gate.py +34 -11
- package/core/hosts/README.md +4 -0
- package/core/hosts/agnescode.py +415 -0
- package/core/hosts/antigravity.py +115 -0
- package/core/hosts/codex.py +3 -0
- package/core/hosts/dsh.py +42 -23
- package/core/hosts/minimax.py +5 -4
- package/core/hosts/opencode.py +11 -3
- package/core/i18n.py +94 -5
- package/core/infra/README.md +1 -1
- package/core/infra/build_info.py +2 -2
- package/core/infra/python_runtime.py +4 -1
- package/core/launch_phases/README.md +2 -2
- package/core/launch_phases/finding_confirm_phase.py +1 -1
- package/core/launch_phases/semantic_recon.py +3 -19
- package/core/launch_phases/startup_version_gate.py +2 -2
- package/core/launch_phases/supervisor_bridge.py +2 -0
- package/core/launch_phases/supervisor_degraded.py +7 -5
- package/core/launch_phases/verify_loop.py +3 -19
- package/core/ledger/README.md +1 -1
- package/core/ledger/finding_confirmation.py +1 -1
- package/core/ledger/finding_verification.py +2 -20
- package/core/ledger/fp_ledger.py +3 -19
- package/core/ledger/life_ledger.py +7 -33
- package/core/ledger/schema.py +1 -1
- package/core/locales/en-US.json +3 -3
- package/core/locales/zh-CN.json +3 -3
- package/core/mcp_handlers/supervisor_handlers.py +1 -1
- package/core/mcp_runtime_support/common.py +6 -0
- package/core/mcp_runtime_support/environment.py +88 -24
- package/core/metadata.txt +1 -1
- package/core/planning/README.md +1 -1
- package/core/planning/prompt_harness.py +2 -2
- package/core/planning/target_sandbox_manager.py +2 -0
- package/core/probes/codebase_memory_probe.py +43 -24
- package/core/probes/mobile_probe.py +1 -0
- package/core/probes/probe_registry.py +10 -7
- package/core/probes/sast_probe.py +1 -1
- package/core/probes/sca_scanner.py +1 -1
- package/core/project_profiler/constants.py +1 -1
- package/core/prompts/command_routing_en.md +6 -5
- package/core/prompts/command_routing_zh.md +6 -5
- package/core/repair/rsi_rounds.py +3 -0
- package/core/repair/self_heal.py +160 -6
- package/core/retrieval/README.md +1 -1
- package/core/retrieval/symbol_index.py +227 -52
- package/core/runtime/README.md +1 -1
- package/core/runtime/daemon_runner.py +3 -2
- package/core/runtime/project_init.py +1 -1
- package/core/runtime/scenario_eval.py +5 -1
- package/core/runtime/tool_install_targets.py +12 -2
- package/core/skills/README.md +4 -2
- package/core/skills/bugx_docs_cloud_sync.py +658 -0
- package/core/skills/bugx_docs_mcp_server.py +966 -140
- package/core/skills/bugx_mcp_server.py +9 -0
- package/core/skills/mcp_session_proof.py +3 -31
- package/core/supervisor/README.md +1 -1
- package/core/supervisor/finding_commit.py +3 -24
- package/core/supervisor/task_scheduler.py +5 -2
- package/core/supervisor/worker_execution.py +16 -3
- package/core/supervisor/worker_handoff.py +2 -2
- package/core/webui/docs_session_service.py +40 -2
- package/core/webui/mcp_inspector.py +6 -6
- package/ecosystem/integrations/cline/skills/bugx/SKILL.md +46 -46
- package/ecosystem/integrations/dsh/agents/bugx.md +2 -1
- package/ecosystem/integrations/dsh/mcp/package.json +1 -1
- package/ecosystem/integrations/dsh/skills/bugx/SKILL.md +5 -5
- 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 +1 -1
- package/ecosystem/integrations/pi/extensions/bugx/manifest.json +1 -1
- package/ecosystem/integrations/pi/skills/bugx/SKILL.md +5 -5
- package/ecosystem/integrations/qoder/CONNECTORS.md +11 -23
- 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 +8 -7
- 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/agents/bugx-worker.md +14 -18
- package/ecosystem/plugins/bugx/agents/bugx.md +45 -49
- package/ecosystem/plugins/bugx/skills/bugx/SKILL.md +7 -7
- package/ecosystem/plugins/bugx/skills/bugx-zcode/SKILL.md +2 -2
- package/interfaces/cli/bugx_cli/__init__.py +1 -1
- package/interfaces/cli/bugx_cli/cli.py +153 -8
- package/interfaces/cli/bugx_cli/commands/agent.py +376 -69
- package/interfaces/cli/bugx_cli/commands/audit.py +2 -1
- package/interfaces/cli/bugx_cli/commands/cloud.py +42 -1
- package/interfaces/cli/bugx_cli/commands/doctor.py +650 -223
- package/interfaces/cli/bugx_cli/commands/guide.py +143 -0
- package/interfaces/cli/bugx_cli/commands/issue.py +262 -0
- package/interfaces/cli/bugx_cli/commands/lifecycle.py +56 -26
- package/interfaces/cli/bugx_cli/commands/patch.py +5 -1
- package/interfaces/cli/bugx_cli/commands/plugin.py +306 -56
- package/interfaces/cli/bugx_cli/commands/plugin_antigravity.py +350 -0
- package/interfaces/cli/bugx_cli/commands/plugin_claude.py +2 -2
- package/interfaces/cli/bugx_cli/commands/plugin_kimi.py +154 -62
- package/interfaces/cli/bugx_cli/commands/plugin_minimax.py +308 -108
- package/interfaces/cli/bugx_cli/commands/system.py +11 -1
- package/interfaces/cli/bugx_cli/common.py +39 -8
- package/interfaces/cli/bugx_cli/host_adapters.py +46 -3
- package/interfaces/cli/bugx_cli/hosts/registry.py +3 -2
- package/interfaces/cli/bugx_cli/hosts/template_engine.py +21 -2
- package/interfaces/cli/bugx_cli/infra/__init__.py +4 -0
- package/interfaces/cli/bugx_cli/infra/ai_advisor.py +14 -12
- package/interfaces/cli/bugx_cli/infra/engine_installer.py +76 -10
- package/interfaces/cli/bugx_cli/infra/host_sync.py +66 -1
- package/interfaces/cli/bugx_cli/infra/mcp_advisor.py +240 -50
- package/package.json +3 -2
- package/pyproject.toml +22 -2
- package/scripts/sync-version.mjs +1 -1
- package/skills/README.md +1 -2
- package/skills/platform/bugx/SKILL.md +50 -0
- package/skills/platform/bugx-user/SKILL.md +0 -92
|
@@ -276,14 +276,17 @@ def mcp_tier(name: str) -> str | None:
|
|
|
276
276
|
def host_entry_status(root: Path) -> dict[str, object]:
|
|
277
277
|
"""宿主侧入口(skill/MCP 入口文件)就绪性检查(DOC-236 C7)。
|
|
278
278
|
|
|
279
|
-
数据源:``.bugx/hosts.json``(由 ``bugx install``
|
|
280
|
-
``
|
|
279
|
+
数据源:``.bugx/hosts.json``(由 ``bugx install`` 写入,含语义版本、
|
|
280
|
+
``bugx_build_id`` 与逐文件 ``sha256``)。语义版本和入口文件完整性是硬门禁;
|
|
281
|
+
Build ID 只是构建身份,日常递增不能单独判定宿主入口不兼容。
|
|
281
282
|
|
|
282
283
|
只读、不装配;任何异常一律返回 ``ready=False``(fail-closed,绝不谎报就绪)。
|
|
283
284
|
"""
|
|
284
285
|
import hashlib as _hashlib
|
|
285
286
|
|
|
286
|
-
result: dict[str, object] = {
|
|
287
|
+
result: dict[str, object] = {
|
|
288
|
+
"ready": False, "reason": "", "hosts": [], "stale_files": [], "warnings": [],
|
|
289
|
+
}
|
|
287
290
|
try:
|
|
288
291
|
record_path = Path(root) / ".bugx" / "hosts.json"
|
|
289
292
|
if record_path.is_symlink() or not record_path.is_file():
|
|
@@ -301,19 +304,38 @@ def host_entry_status(root: Path) -> dict[str, object]:
|
|
|
301
304
|
result["reason"] = "宿主入口登记为空(尚未安装任何宿主入口)"
|
|
302
305
|
return result
|
|
303
306
|
|
|
307
|
+
from core.infra.build_info import BASE_VERSION
|
|
308
|
+
|
|
309
|
+
recorded_version = payload.get("bugx_version")
|
|
310
|
+
if not isinstance(recorded_version, str) or not recorded_version:
|
|
311
|
+
result["reason"] = "宿主入口登记缺少语义版本,无法验证入口契约"
|
|
312
|
+
return result
|
|
313
|
+
if recorded_version != BASE_VERSION:
|
|
314
|
+
result["reason"] = (
|
|
315
|
+
f"宿主入口为 {recorded_version},当前引擎为 {BASE_VERSION}"
|
|
316
|
+
"(语义版本不一致,宿主入口需重新装配并重启)"
|
|
317
|
+
)
|
|
318
|
+
return result
|
|
319
|
+
|
|
304
320
|
try:
|
|
305
321
|
from core.infra.build_info import get_build_id as _get_build_id
|
|
306
322
|
current_build = _get_build_id()
|
|
307
|
-
except Exception: # noqa: BLE001 -
|
|
323
|
+
except Exception: # noqa: BLE001 - Build 仅作诊断;身份不可读时不据此阻断
|
|
308
324
|
current_build = None
|
|
309
325
|
recorded_build = payload.get("bugx_build_id")
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
326
|
+
build_matches = (
|
|
327
|
+
isinstance(recorded_build, int) and not isinstance(recorded_build, bool)
|
|
328
|
+
and isinstance(current_build, int) and not isinstance(current_build, bool)
|
|
329
|
+
and recorded_build == current_build
|
|
330
|
+
)
|
|
331
|
+
result["recorded_build_id"] = recorded_build
|
|
332
|
+
result["current_build_id"] = current_build
|
|
333
|
+
result["build_matches"] = build_matches
|
|
334
|
+
if not build_matches:
|
|
335
|
+
result["warnings"].append(
|
|
336
|
+
f"宿主入口装配于 build {recorded_build},当前引擎为 build {current_build}"
|
|
337
|
+
"(构建身份漂移;入口文件与语义契约一致时不阻断)"
|
|
315
338
|
)
|
|
316
|
-
return result
|
|
317
339
|
|
|
318
340
|
stale: list[str] = []
|
|
319
341
|
hosts: list[str] = []
|
|
@@ -345,7 +367,8 @@ def host_entry_status(root: Path) -> dict[str, object]:
|
|
|
345
367
|
result["reason"] = "宿主入口文件缺失或被改动:" + ", ".join(stale[:3])
|
|
346
368
|
return result
|
|
347
369
|
result["ready"] = True
|
|
348
|
-
|
|
370
|
+
build_label = str(recorded_build) if build_matches else f"{recorded_build}→{current_build}"
|
|
371
|
+
result["reason"] = f"宿主入口就绪({', '.join(hosts)};build {build_label})"
|
|
349
372
|
return result
|
|
350
373
|
|
|
351
374
|
|
package/core/hosts/README.md
CHANGED
|
@@ -47,12 +47,16 @@ flowchart TD
|
|
|
47
47
|
| `_dsh_usage.py` | DSH 环境专有调用链耗时与交互次数统计实现 | `DshUsageTracker` |
|
|
48
48
|
| `_mcp_toml.py` | MCP 客户端配置注入器,安全写入或更新 `.codex/mcp.toml` / `.vscode/cline_mcp.json` | `inject_mcp_toml_config` |
|
|
49
49
|
| `_zcode_usage.py` | ZCode 平台专有资源配额与请求频率追踪器 | `ZCodeUsageTracker` |
|
|
50
|
+
| `agnescode.py` | Agnes Code 宿主接入适配器,生成 MCP 配置与智能体入口 | `PLUGIN` |
|
|
51
|
+
| `antigravity.py` | Google Antigravity 宿主接入适配器,生成 Plugin 插件与工作区 MCP | `PLUGIN` |
|
|
50
52
|
| `base.py` | 宿主插件核心契约定义,提供探针注入、MCP 服务拉起与生命周期钩子 | `BaseHostPlugin` |
|
|
51
53
|
| `claude.py` | Claude Desktop / Claude Code 宿主接入适配器,生成 MCP 配置与技能包 | `ClaudeHostPlugin` |
|
|
52
54
|
| `cline.py` | Cline 插件适配器,实现 Roo Code / Cline 的 MCP 注入与规则提示词联动 | `ClineHostPlugin` |
|
|
53
55
|
| `codex.py` | OpenAI Codex 适配器,管理 Codex CLI 交互式与无头会话 | `CodexHostPlugin` |
|
|
54
56
|
| `dsh.py` | DSH (Deep Shell) 适配器,支持终端交互代理与工作流联动 | `DshHostPlugin` |
|
|
55
57
|
| `INTERFACE.md` | 宿主插件公共接口设计与契约规范文档 | 宿主生命周期协议说明 |
|
|
58
|
+
| `kimi.py` | Kimi Code CLI 宿主接入适配器,生成 subagent 入口与 MCP 配置 | `PLUGIN` |
|
|
59
|
+
| `minimax.py` | MiniMax Code 桌面端插件适配器,管理 Plugin V1 入口与规范 | `PLUGIN` |
|
|
56
60
|
| `opencode.py` | OpenCode 智能体适配器,提供标准 JSON-RPC MCP 挂载与环境发现 | `OpenCodeHostPlugin` |
|
|
57
61
|
| `pi.py` | Pi 智能体平台接入适配器,实现扩展注册与事件桥接 | `PiHostPlugin` |
|
|
58
62
|
| `SPEC.md` | 多宿主架构设计规格书,阐述各宿主环境差异与统一语义模型 | 规范与技术考量 |
|
|
@@ -0,0 +1,415 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""core/hosts/agnescode.py - Agnes Code 宿主插件及自治配置环境。
|
|
3
|
+
|
|
4
|
+
事实来源(Agnes AI / Agnes Code):
|
|
5
|
+
* identity ← 可执行程序 ``agnescode``(别名 ``agnes``);项目标记 ``agnescode.json`` / ``.agnescode``
|
|
6
|
+
* install ← ``subagent`` / ``agent`` 入口:``.agnescode/agents/bugx.md``
|
|
7
|
+
* engine_run ← ``agnescode run --standalone --agent <agent> --format json --auto <prompt>``
|
|
8
|
+
* mcp_write ← ``mcp.servers`` 容器键,配置文件 ``agnescode.json`` 与镜像 ``.agnescode/agnescode.json``
|
|
9
|
+
* acp ← ``core/host_acp/agnescode.py``(``agnescode acp``)
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
from contextlib import contextmanager
|
|
15
|
+
import json
|
|
16
|
+
import os
|
|
17
|
+
from pathlib import Path
|
|
18
|
+
import shutil
|
|
19
|
+
from typing import Iterator
|
|
20
|
+
|
|
21
|
+
from core.infra.json_utils import unique_json_object
|
|
22
|
+
|
|
23
|
+
from .base import (
|
|
24
|
+
AcpFacet,
|
|
25
|
+
EngineRunFacet,
|
|
26
|
+
HostPlugin,
|
|
27
|
+
IdentityFacet,
|
|
28
|
+
InstallFacet,
|
|
29
|
+
McpWriteFacet,
|
|
30
|
+
RunContext,
|
|
31
|
+
STATUS_READY,
|
|
32
|
+
WorkerRuntimeFacet,
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
__all__ = ["PLUGIN", "is_available", "run_static_degraded"]
|
|
36
|
+
|
|
37
|
+
_NAME = "agnescode"
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def _resolve_executable() -> str | None:
|
|
41
|
+
for cmd in ("agnescode", "agnes"):
|
|
42
|
+
found = shutil.which(cmd)
|
|
43
|
+
if found:
|
|
44
|
+
return found
|
|
45
|
+
app_agnesd = Path("/Applications/AgnesCode.app/Contents/Resources/bin/agnesd")
|
|
46
|
+
if app_agnesd.is_file():
|
|
47
|
+
return str(app_agnesd)
|
|
48
|
+
return None
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def _agnes_app_markers() -> tuple[Path, ...]:
|
|
52
|
+
home = Path.home()
|
|
53
|
+
return (
|
|
54
|
+
Path("/Applications/AgnesCode.app"),
|
|
55
|
+
home / "Applications" / "AgnesCode.app",
|
|
56
|
+
home / "Library" / "Application Support" / "AgnesCode",
|
|
57
|
+
home / ".agnes",
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def _configured_model(root: Path) -> str:
|
|
62
|
+
"""Read the project model without making it part of BugX state."""
|
|
63
|
+
configured = os.environ.get("BUGX_AGNESCODE_MODEL", "").strip()
|
|
64
|
+
if configured:
|
|
65
|
+
return configured
|
|
66
|
+
for candidate in (root / "agnescode.json", root / ".agnescode" / "agnescode.json"):
|
|
67
|
+
if candidate.is_file():
|
|
68
|
+
try:
|
|
69
|
+
payload = json.loads(candidate.read_text(encoding="utf-8"))
|
|
70
|
+
except (OSError, json.JSONDecodeError):
|
|
71
|
+
continue
|
|
72
|
+
model = payload.get("model") if isinstance(payload, dict) else ""
|
|
73
|
+
if isinstance(model, str) and model.strip():
|
|
74
|
+
return model.strip()
|
|
75
|
+
return ""
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def _strip_jsonc_comments_and_trailing_commas(source: str) -> str:
|
|
79
|
+
"""Remove JSONC comments and trailing commas without touching string data."""
|
|
80
|
+
clean: list[str] = []
|
|
81
|
+
in_string = False
|
|
82
|
+
escaped = False
|
|
83
|
+
line_comment = False
|
|
84
|
+
block_comment = False
|
|
85
|
+
index = 0
|
|
86
|
+
while index < len(source):
|
|
87
|
+
char = source[index]
|
|
88
|
+
next_char = source[index + 1] if index + 1 < len(source) else ""
|
|
89
|
+
if line_comment:
|
|
90
|
+
if char in "\r\n":
|
|
91
|
+
line_comment = False
|
|
92
|
+
clean.append(char)
|
|
93
|
+
else:
|
|
94
|
+
clean.append(" ")
|
|
95
|
+
elif block_comment:
|
|
96
|
+
if char == "*" and next_char == "/":
|
|
97
|
+
clean.extend((" ", " "))
|
|
98
|
+
index += 1
|
|
99
|
+
block_comment = False
|
|
100
|
+
else:
|
|
101
|
+
clean.append(char if char in "\r\n" else " ")
|
|
102
|
+
elif in_string:
|
|
103
|
+
clean.append(char)
|
|
104
|
+
if escaped:
|
|
105
|
+
escaped = False
|
|
106
|
+
elif char == "\\":
|
|
107
|
+
escaped = True
|
|
108
|
+
elif char == '"':
|
|
109
|
+
in_string = False
|
|
110
|
+
elif char == '"':
|
|
111
|
+
in_string = True
|
|
112
|
+
clean.append(char)
|
|
113
|
+
elif char == "/" and next_char == "/":
|
|
114
|
+
clean.extend((" ", " "))
|
|
115
|
+
index += 1
|
|
116
|
+
line_comment = True
|
|
117
|
+
elif char == "/" and next_char == "*":
|
|
118
|
+
clean.extend((" ", " "))
|
|
119
|
+
index += 1
|
|
120
|
+
block_comment = True
|
|
121
|
+
else:
|
|
122
|
+
clean.append(char)
|
|
123
|
+
index += 1
|
|
124
|
+
|
|
125
|
+
if block_comment:
|
|
126
|
+
raise ValueError("unterminated block comment")
|
|
127
|
+
|
|
128
|
+
without_comments = "".join(clean).lstrip("\ufeff")
|
|
129
|
+
clean = []
|
|
130
|
+
in_string = False
|
|
131
|
+
escaped = False
|
|
132
|
+
index = 0
|
|
133
|
+
while index < len(without_comments):
|
|
134
|
+
char = without_comments[index]
|
|
135
|
+
if in_string:
|
|
136
|
+
clean.append(char)
|
|
137
|
+
if escaped:
|
|
138
|
+
escaped = False
|
|
139
|
+
elif char == "\\":
|
|
140
|
+
escaped = True
|
|
141
|
+
elif char == '"':
|
|
142
|
+
in_string = False
|
|
143
|
+
elif char == '"':
|
|
144
|
+
in_string = True
|
|
145
|
+
clean.append(char)
|
|
146
|
+
elif char == ",":
|
|
147
|
+
lookahead = index + 1
|
|
148
|
+
while lookahead < len(without_comments) and without_comments[lookahead].isspace():
|
|
149
|
+
lookahead += 1
|
|
150
|
+
if lookahead >= len(without_comments) or without_comments[lookahead] not in "]}":
|
|
151
|
+
clean.append(char)
|
|
152
|
+
else:
|
|
153
|
+
clean.append(char)
|
|
154
|
+
index += 1
|
|
155
|
+
return "".join(clean)
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
def _unique_object(pairs: list[tuple[str, object]]) -> dict[str, object]:
|
|
159
|
+
return unique_json_object(
|
|
160
|
+
pairs,
|
|
161
|
+
error_factory=lambda key: ValueError(f"duplicate key: {key}"),
|
|
162
|
+
)
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
def _read_agnescode_config(path: Path) -> dict[str, object]:
|
|
166
|
+
try:
|
|
167
|
+
parsed = json.loads(
|
|
168
|
+
_strip_jsonc_comments_and_trailing_commas(path.read_text(encoding="utf-8")),
|
|
169
|
+
object_pairs_hook=_unique_object,
|
|
170
|
+
)
|
|
171
|
+
except (OSError, UnicodeError, json.JSONDecodeError, ValueError) as exc:
|
|
172
|
+
raise RuntimeError(
|
|
173
|
+
f"AgnesCode 自治配置无法安全隔离: {path.name} ({type(exc).__name__})"
|
|
174
|
+
) from exc
|
|
175
|
+
if not isinstance(parsed, dict):
|
|
176
|
+
raise RuntimeError(f"AgnesCode 自治配置必须是对象: {path.name}")
|
|
177
|
+
return parsed
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
def _child_path(value: str, root: Path) -> Path:
|
|
181
|
+
path = Path(value).expanduser()
|
|
182
|
+
return (path if path.is_absolute() else root / path).resolve()
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
def _agnescode_global_config_dir(root: Path) -> Path:
|
|
186
|
+
configured = os.environ.get("AGNESCODE_CONFIG_DIR")
|
|
187
|
+
if "AGNESCODE_CONFIG_DIR" in os.environ:
|
|
188
|
+
if not configured:
|
|
189
|
+
raise RuntimeError("AGNESCODE_CONFIG_DIR 为空,无法隔离 AgnesCode 用户配置")
|
|
190
|
+
return _child_path(configured, root)
|
|
191
|
+
xdg = os.environ.get("XDG_CONFIG_HOME")
|
|
192
|
+
base = _child_path(xdg, root) if xdg else Path.home() / ".config"
|
|
193
|
+
return (base / "agnescode").resolve()
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
@contextmanager
|
|
197
|
+
def _autonomous_environment(root: Path) -> Iterator[dict[str, str | None]]:
|
|
198
|
+
"""Hide user-global plugin/MCP sources while preserving AgnesCode's project config."""
|
|
199
|
+
for name in ("AGNESCODE_CONFIG", "AGNESCODE_CONFIG_CONTENT"):
|
|
200
|
+
if os.environ.get(name):
|
|
201
|
+
raise RuntimeError(
|
|
202
|
+
f"AgnesCode 自治配置隔离不接受额外覆盖 {name};请先移除该覆盖再运行"
|
|
203
|
+
)
|
|
204
|
+
for name in ("AGNESCODE_CONFIG_PROJECT_DISABLE", "AGNESCODE_DISABLE_PROJECT_CONFIG"):
|
|
205
|
+
value = os.environ.get(name, "")
|
|
206
|
+
if value == "1" or value.lower() == "true":
|
|
207
|
+
raise RuntimeError(f"{name} 禁用了项目配置,BugX MCP 无法加载")
|
|
208
|
+
|
|
209
|
+
import tempfile
|
|
210
|
+
|
|
211
|
+
source_dir = _agnescode_global_config_dir(root)
|
|
212
|
+
parent = source_dir.parent if source_dir.parent.is_dir() else Path(tempfile.gettempdir())
|
|
213
|
+
with tempfile.TemporaryDirectory(prefix="bugx-agnescode-config-", dir=parent) as private_name:
|
|
214
|
+
private_dir = Path(private_name).resolve()
|
|
215
|
+
project_root = root.resolve()
|
|
216
|
+
if private_dir == project_root or project_root in private_dir.parents:
|
|
217
|
+
raise RuntimeError("AgnesCode 自治私有配置目录落在被测项目内,已阻断")
|
|
218
|
+
private_dir.chmod(0o700)
|
|
219
|
+
|
|
220
|
+
if source_dir.exists():
|
|
221
|
+
if not source_dir.is_dir():
|
|
222
|
+
raise RuntimeError("AGNESCODE_CONFIG_DIR 不是目录,无法安全隔离")
|
|
223
|
+
try:
|
|
224
|
+
for entry in source_dir.iterdir():
|
|
225
|
+
if entry.name in {"agnescode.json", "agnescode.jsonc", "plugin", "plugins"}:
|
|
226
|
+
continue
|
|
227
|
+
dest = private_dir / entry.name
|
|
228
|
+
try:
|
|
229
|
+
dest.symlink_to(entry, target_is_directory=entry.is_dir())
|
|
230
|
+
except OSError:
|
|
231
|
+
if os.name != "nt":
|
|
232
|
+
raise
|
|
233
|
+
if entry.is_dir():
|
|
234
|
+
shutil.copytree(entry, dest, dirs_exist_ok=True)
|
|
235
|
+
else:
|
|
236
|
+
shutil.copy2(entry, dest)
|
|
237
|
+
except OSError as exc:
|
|
238
|
+
raise RuntimeError(
|
|
239
|
+
f"AgnesCode 自治配置资产无法隔离 ({type(exc).__name__})"
|
|
240
|
+
) from exc
|
|
241
|
+
|
|
242
|
+
for name in ("agnescode.json", "agnescode.jsonc"):
|
|
243
|
+
source_file = source_dir / name
|
|
244
|
+
if not source_file.exists() and not source_file.is_symlink():
|
|
245
|
+
continue
|
|
246
|
+
if not source_file.is_file():
|
|
247
|
+
raise RuntimeError(f"AgnesCode 用户配置不是文件: {name}")
|
|
248
|
+
payload = _read_agnescode_config(source_file)
|
|
249
|
+
for key in ("mcp", "plugin", "plugins"):
|
|
250
|
+
payload.pop(key, None)
|
|
251
|
+
target = private_dir / name
|
|
252
|
+
target.write_text(
|
|
253
|
+
json.dumps(payload, ensure_ascii=False, indent=2) + "\n",
|
|
254
|
+
encoding="utf-8",
|
|
255
|
+
)
|
|
256
|
+
target.chmod(0o600)
|
|
257
|
+
|
|
258
|
+
yield {
|
|
259
|
+
"AGNESCODE_CONFIG_DIR": str(private_dir),
|
|
260
|
+
"AGNESCODE_CONFIG": None,
|
|
261
|
+
"AGNESCODE_CONFIG_CONTENT": None,
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
def _argv(ctx: RunContext, *, auto: bool) -> list[str]:
|
|
266
|
+
exe = _resolve_executable() or "agnescode"
|
|
267
|
+
cmd = [exe, "run"]
|
|
268
|
+
if auto:
|
|
269
|
+
cmd.append("--standalone")
|
|
270
|
+
cmd += ["--agent", ctx.agent, "--format", "json"]
|
|
271
|
+
model = _configured_model(ctx.root)
|
|
272
|
+
if model:
|
|
273
|
+
cmd += ["--model", model]
|
|
274
|
+
if auto:
|
|
275
|
+
cmd.append("--auto")
|
|
276
|
+
if ctx.session:
|
|
277
|
+
cmd += ["-s", ctx.session]
|
|
278
|
+
cmd.append(ctx.prompt)
|
|
279
|
+
return cmd
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
def _headless_argv(ctx: RunContext) -> list[str]:
|
|
283
|
+
return _argv(ctx, auto=False)
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
def _autonomous_argv(ctx: RunContext) -> list[str]:
|
|
287
|
+
return _argv(ctx, auto=True)
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
def _recon_scout_argv(
|
|
291
|
+
root: Path, prompt_text: str, prompt_file: Path, inventory: object | None = None,
|
|
292
|
+
) -> list[str]:
|
|
293
|
+
del root
|
|
294
|
+
exe = _resolve_executable() or "agnescode"
|
|
295
|
+
cmd = [exe, "run", "--standalone", "--format", "json", "--auto"]
|
|
296
|
+
scout_model = (
|
|
297
|
+
os.environ.get("BUGX_SCOUT_MODEL")
|
|
298
|
+
or os.environ.get("BUGX_AGNESCODE_MODEL")
|
|
299
|
+
or os.environ.get("AGNESCODE_MODEL")
|
|
300
|
+
)
|
|
301
|
+
if scout_model:
|
|
302
|
+
cmd.extend(["-m", scout_model])
|
|
303
|
+
cmd.extend(["-f", str(prompt_file), "Execute BugX Recon Scout review"])
|
|
304
|
+
return cmd
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
def _mcp_config_paths(root: Path) -> tuple[Path, ...]:
|
|
308
|
+
return (root / "agnescode.json", root / ".agnescode" / "agnescode.json")
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
def _agent_config_path(root: Path) -> Path:
|
|
312
|
+
return root / ".agnescode" / "agents" / "bugx.md"
|
|
313
|
+
|
|
314
|
+
|
|
315
|
+
def _mcp_health(name: str, cfg: dict, root: Path | None = None) -> bool:
|
|
316
|
+
del name, cfg, root
|
|
317
|
+
return True
|
|
318
|
+
|
|
319
|
+
|
|
320
|
+
PLUGIN = HostPlugin(
|
|
321
|
+
identity=IdentityFacet(
|
|
322
|
+
name=_NAME,
|
|
323
|
+
label="Agnes Code",
|
|
324
|
+
order=20,
|
|
325
|
+
executable="agnescode",
|
|
326
|
+
markers=("agnescode.json", ".agnescode/agnescode.json", ".agnescode", ".agnes"),
|
|
327
|
+
aliases=("agnes",),
|
|
328
|
+
app_markers=_agnes_app_markers,
|
|
329
|
+
native_question=True,
|
|
330
|
+
),
|
|
331
|
+
status=STATUS_READY,
|
|
332
|
+
install=InstallFacet(
|
|
333
|
+
kind="agent",
|
|
334
|
+
path=".agnescode/agents/bugx.md",
|
|
335
|
+
marker=".agnescode",
|
|
336
|
+
entry_mode="rendered",
|
|
337
|
+
required_paths=(),
|
|
338
|
+
legacy_paths=(),
|
|
339
|
+
capabilities=frozenset({"native-mcp-config", "global-agent-link"}),
|
|
340
|
+
interaction={
|
|
341
|
+
"tool": "question",
|
|
342
|
+
"single_select": "multiple=false",
|
|
343
|
+
},
|
|
344
|
+
mcp_relpaths=("agnescode.json", ".agnescode/agnescode.json"),
|
|
345
|
+
worker_subagent=False,
|
|
346
|
+
),
|
|
347
|
+
engine_run=EngineRunFacet(
|
|
348
|
+
supports_headless=True,
|
|
349
|
+
headless_argv=_headless_argv,
|
|
350
|
+
autonomous_argv=_autonomous_argv,
|
|
351
|
+
mcp_config_paths=_mcp_config_paths,
|
|
352
|
+
agent_config_path=_agent_config_path,
|
|
353
|
+
mcp_health=_mcp_health,
|
|
354
|
+
host_surface="tui",
|
|
355
|
+
recon_scout_argv=_recon_scout_argv,
|
|
356
|
+
native_task=True,
|
|
357
|
+
autonomous_environment=_autonomous_environment,
|
|
358
|
+
),
|
|
359
|
+
worker_runtime=WorkerRuntimeFacet(
|
|
360
|
+
mode="multi",
|
|
361
|
+
max_concurrency=None,
|
|
362
|
+
requires_process_mode=False,
|
|
363
|
+
sandbox_sync=(),
|
|
364
|
+
),
|
|
365
|
+
mcp_write=McpWriteFacet(
|
|
366
|
+
container_key="mcp.servers",
|
|
367
|
+
writer_key=_NAME,
|
|
368
|
+
project_relpath="agnescode.json",
|
|
369
|
+
global_scope=None,
|
|
370
|
+
mirror_relpaths=(".agnescode/agnescode.json",),
|
|
371
|
+
requires_absolutize=True,
|
|
372
|
+
custom_writer=False,
|
|
373
|
+
),
|
|
374
|
+
acp=AcpFacet(plugin=_NAME),
|
|
375
|
+
)
|
|
376
|
+
|
|
377
|
+
|
|
378
|
+
def is_available() -> tuple[bool, str]:
|
|
379
|
+
path = _resolve_executable()
|
|
380
|
+
if path is None:
|
|
381
|
+
return False, "agnescode 未安装;headless 与 ACP 通道不可用"
|
|
382
|
+
return True, path
|
|
383
|
+
|
|
384
|
+
|
|
385
|
+
def run_static_degraded(root: Path | None = None) -> dict:
|
|
386
|
+
available, availability_detail = is_available()
|
|
387
|
+
return {
|
|
388
|
+
"plugin": _NAME,
|
|
389
|
+
"schema_version": 1,
|
|
390
|
+
"success": available,
|
|
391
|
+
"status": "degraded",
|
|
392
|
+
"degraded": True,
|
|
393
|
+
"degraded_reason": "static_facts_only" if available else "agnescode_not_installed",
|
|
394
|
+
"probe_mode": "static_degraded",
|
|
395
|
+
"headless_available": available,
|
|
396
|
+
"native_task_available": bool(available and PLUGIN.engine_run.native_task),
|
|
397
|
+
"identity": {
|
|
398
|
+
"executable": PLUGIN.identity.executable,
|
|
399
|
+
"aliases": list(PLUGIN.identity.aliases),
|
|
400
|
+
"markers": list(PLUGIN.identity.markers),
|
|
401
|
+
},
|
|
402
|
+
"agent_entry": PLUGIN.install.path,
|
|
403
|
+
"mcp_project_relpath": PLUGIN.mcp_write.project_relpath,
|
|
404
|
+
"mcp_global_scope": PLUGIN.mcp_write.global_scope,
|
|
405
|
+
"findings": [],
|
|
406
|
+
"evidence": {
|
|
407
|
+
"availability_detail": availability_detail,
|
|
408
|
+
"project_root": str(root) if root else None,
|
|
409
|
+
},
|
|
410
|
+
"metadata": {
|
|
411
|
+
"degraded_mode": "static_plugin_facts_only",
|
|
412
|
+
"acp": "ready(agnescode acp 原生支持标准 ACP,见 core/host_acp/agnescode.py)",
|
|
413
|
+
"fallback": "宿主 CLI 缺失时由外层宿主/用户决策接管;BugX 不代装宿主 CLI",
|
|
414
|
+
},
|
|
415
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"""Google Antigravity desktop and ``agy`` review/worker integration.
|
|
2
|
+
|
|
3
|
+
Antigravity has two separate configuration surfaces: the user-level plugin
|
|
4
|
+
contains the Agent and Skill, while the workspace-level ``.agents`` file is
|
|
5
|
+
the only safe place for BugX's project-bound MCP servers. Keeping those
|
|
6
|
+
surfaces separate is important because plugin stdio children do not reliably
|
|
7
|
+
inherit the active workspace as their current directory.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
|
|
12
|
+
from .base import (
|
|
13
|
+
AcpFacet, EngineRunFacet, HostPlugin, IdentityFacet,
|
|
14
|
+
InstallFacet, McpWriteFacet, RunContext, STATUS_READY, WorkerRuntimeFacet,
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
PLUGIN_DIR = ".gemini/config/plugins/bugx-review"
|
|
19
|
+
MANIFEST = "plugin.json"
|
|
20
|
+
AGENT = "agents/bugx-review.md"
|
|
21
|
+
WORKER_AGENT = "agents/bugx-worker.md"
|
|
22
|
+
SKILL = "skills/bugx-review/SKILL.md"
|
|
23
|
+
MCP = "mcp_config.json"
|
|
24
|
+
LOGO = "assets/bugx-avatar.svg"
|
|
25
|
+
PROJECT_MCP = ".agents/mcp_config.json"
|
|
26
|
+
AGENT_ID = "BugX"
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def _headless_argv(context: RunContext) -> list[str]:
|
|
30
|
+
"""Build the documented ``agy -p`` headless command.
|
|
31
|
+
|
|
32
|
+
The installed BugX Agent is the stable entry point for this host; callers
|
|
33
|
+
may pass a generic engine agent name, so it is deliberately not forwarded
|
|
34
|
+
to ``agy --agent``.
|
|
35
|
+
"""
|
|
36
|
+
|
|
37
|
+
command = [
|
|
38
|
+
"agy", "--agent", AGENT_ID, "--mode", "auto",
|
|
39
|
+
"--add-dir", str(context.root), "--output-format", "json",
|
|
40
|
+
"-p", context.prompt,
|
|
41
|
+
]
|
|
42
|
+
if context.session:
|
|
43
|
+
command[3:3] = ["--conversation", context.session]
|
|
44
|
+
return command
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def _autonomous_argv(context: RunContext) -> list[str]:
|
|
48
|
+
"""Build the unattended command with Antigravity's official permission flag."""
|
|
49
|
+
|
|
50
|
+
command = [
|
|
51
|
+
"agy", "--agent", AGENT_ID, "--mode", "auto",
|
|
52
|
+
"--dangerously-skip-permissions", "--add-dir", str(context.root),
|
|
53
|
+
"--output-format", "json", "-p", context.prompt,
|
|
54
|
+
]
|
|
55
|
+
if context.session:
|
|
56
|
+
command[3:3] = ["--conversation", context.session]
|
|
57
|
+
return command
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def _mcp_config_paths(root: Path) -> tuple[Path, ...]:
|
|
61
|
+
"""Return the workspace MCP file consumed by Antigravity."""
|
|
62
|
+
|
|
63
|
+
return (root / PROJECT_MCP,)
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def _agent_config_path(_root: Path) -> Path:
|
|
67
|
+
return Path.home() / PLUGIN_DIR / AGENT
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
PLUGIN = HostPlugin(
|
|
71
|
+
identity=IdentityFacet(
|
|
72
|
+
name="antigravity", label="Google Antigravity", order=18, executable="agy",
|
|
73
|
+
# Antigravity 的项目级事实入口是工作区 MCP 文件;插件本体位于用户级
|
|
74
|
+
# ``~/.gemini/config/plugins``,不能拿不存在的项目插件镜像路径做识别 marker。
|
|
75
|
+
markers=(PROJECT_MCP,), aliases=("agy",),
|
|
76
|
+
native_question=False,
|
|
77
|
+
),
|
|
78
|
+
status=STATUS_READY,
|
|
79
|
+
install=InstallFacet(
|
|
80
|
+
kind="plugin", path=f"{PLUGIN_DIR}/{MANIFEST}", entry_mode="user-registration",
|
|
81
|
+
marker=PROJECT_MCP,
|
|
82
|
+
capabilities=frozenset({
|
|
83
|
+
"user-agent-registration", "user-level-plugin", "native-mcp-config",
|
|
84
|
+
}),
|
|
85
|
+
worker_subagent=True,
|
|
86
|
+
worker_entry_path=WORKER_AGENT,
|
|
87
|
+
interaction={"tool": "Antigravity Agent selector"},
|
|
88
|
+
),
|
|
89
|
+
engine_run=EngineRunFacet(
|
|
90
|
+
supports_headless=True,
|
|
91
|
+
headless_argv=_headless_argv,
|
|
92
|
+
autonomous_argv=_autonomous_argv,
|
|
93
|
+
mcp_config_paths=_mcp_config_paths,
|
|
94
|
+
agent_config_path=_agent_config_path,
|
|
95
|
+
host_surface="desktop",
|
|
96
|
+
),
|
|
97
|
+
worker_runtime=WorkerRuntimeFacet(
|
|
98
|
+
mode="serial",
|
|
99
|
+
max_concurrency=1,
|
|
100
|
+
requires_process_mode=True,
|
|
101
|
+
runner_module="host_runtime.antigravity",
|
|
102
|
+
provider_key="antigravity",
|
|
103
|
+
pid_required=True,
|
|
104
|
+
autonomous_cli=True,
|
|
105
|
+
),
|
|
106
|
+
mcp_write=McpWriteFacet(
|
|
107
|
+
container_key="mcpServers", writer_key="antigravity",
|
|
108
|
+
project_relpath=PROJECT_MCP, custom_writer=False, requires_absolutize=True,
|
|
109
|
+
# ``bugx`` imports the complete CLI before handing off to the engine.
|
|
110
|
+
# Antigravity ACP preloads stdio MCP with a short deadline, so the
|
|
111
|
+
# writer must use the direct global-engine script launcher instead.
|
|
112
|
+
entry_extra={"_bugx_direct_engine_script": True},
|
|
113
|
+
),
|
|
114
|
+
acp=AcpFacet(plugin="antigravity"),
|
|
115
|
+
)
|
package/core/hosts/codex.py
CHANGED
|
@@ -374,6 +374,9 @@ def _is_bugx_entry(name: str, spec: Mapping[str, Any]) -> bool:
|
|
|
374
374
|
"""
|
|
375
375
|
|
|
376
376
|
del name
|
|
377
|
+
raw_url = spec.get("url")
|
|
378
|
+
if isinstance(raw_url, str) and "/api/v1/mcp/docs" in raw_url:
|
|
379
|
+
return True
|
|
377
380
|
tokens = [str(spec.get("command") or "")]
|
|
378
381
|
tokens.extend(str(arg) for arg in (spec.get("args") or ()))
|
|
379
382
|
return any(_BUGX_NAME_PREFIX in token.lower() for token in tokens)
|