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.
Files changed (167) hide show
  1. package/core/README.md +5 -3
  2. package/core/agent/agent_execution.py +7 -0
  3. package/core/assets/bugx-wechat-group.png +0 -0
  4. package/core/bugx.md +2 -2
  5. package/core/bugx_paths.py +10 -2
  6. package/core/bundled_docs/OVERVIEW.md +311 -0
  7. package/core/bundled_docs/README.md +10 -0
  8. package/core/bundled_docs/README_EN.md +278 -0
  9. package/core/bundled_docs/ai/01_AI_REFERENCE.md +838 -0
  10. package/core/bundled_docs/ai/02_AI_USAGE.md +161 -0
  11. package/core/bundled_docs/ai/03_AI_COMMANDS.md +322 -0
  12. package/core/bundled_docs/guides/01_USER_GUIDE.md +887 -0
  13. package/core/bundled_docs/guides/02_COMMANDS.md +935 -0
  14. package/core/bundled_docs/guides/03_TROUBLESHOOTING.md +763 -0
  15. package/core/bundled_docs/guides/04_CLOUD_AUTH_AND_SYNC_COOKBOOK.md +48 -0
  16. package/core/bundled_docs/guides/05_HOST_MATRIX_AND_DISPATCH.md +25 -0
  17. package/core/bundled_docs/guides/06_PROBES_AND_POC_COOKBOOK.md +49 -0
  18. package/core/bundled_docs/guides/07_LIFECYCLE_AND_RECOVERY_STATES.md +46 -0
  19. package/core/bundled_docs/guides/08_LESSONS_AND_PRIVACY_BOUNDARY.md +35 -0
  20. package/core/bundled_docs/hosts/bugx-claude_SKILL.md +326 -0
  21. package/core/bundled_docs/hosts/bugx-dsh_SKILL.md +229 -0
  22. package/core/bundled_docs/hosts/bugx-opencode_SKILL.md +129 -0
  23. package/core/bundled_docs/hosts/bugx-zcode_SKILL.md +459 -0
  24. package/core/bundled_docs/hosts/bugx_SKILL.md +118 -0
  25. package/core/bundled_docs/hosts/cline_bugx_SKILL.md +69 -0
  26. package/core/bundled_docs/hosts/platform_bugx_SKILL.md +50 -0
  27. package/core/bundled_docs/manifest.json +140 -0
  28. package/core/bundled_docs/reference/01_ENVIRONMENT_VARIABLES.md +422 -0
  29. package/core/bundled_docs/reference/04_REPOSITORY_TOPOLOGY.md +180 -0
  30. package/core/cli-help.txt +7 -3
  31. package/core/cloud_sync/cloud_client.py +81 -2
  32. package/core/cloud_sync/endpoint_router.py +22 -9
  33. package/core/cloud_sync/issue_uploader.py +297 -0
  34. package/core/cloud_sync/sensitive_filter.py +77 -7
  35. package/core/contracts/AGENT_GUIDE.md +3 -9
  36. package/core/contracts/README.md +1 -1
  37. package/core/contracts/bugx-runtime-contract.md +10 -20
  38. package/core/contracts/bugx-worker.md +1 -1
  39. package/core/coverage/coverage_ai_review.py +15 -11
  40. package/core/coverage/coverage_bootstrap.py +18 -13
  41. package/core/coverage/coverage_discovery.py +1 -1
  42. package/core/dev_harness/interaction_preset.py +1 -1
  43. package/core/engine-integrity.json +283 -159
  44. package/core/host_acp/README.md +4 -0
  45. package/core/host_acp/agnescode.py +128 -0
  46. package/core/host_acp/antigravity.py +153 -0
  47. package/core/host_runtime/README.md +3 -0
  48. package/core/host_runtime/adapters.py +5 -1
  49. package/core/host_runtime/antigravity.py +162 -0
  50. package/core/host_runtime/host_bootstrap.py +18 -7
  51. package/core/host_runtime/host_evaluators.py +4 -4
  52. package/core/host_runtime/host_registry.py +3 -1
  53. package/core/host_runtime/mcp_process_tracker.py +30 -3
  54. package/core/host_runtime/mcp_registry_gate.py +34 -11
  55. package/core/hosts/README.md +4 -0
  56. package/core/hosts/agnescode.py +415 -0
  57. package/core/hosts/antigravity.py +115 -0
  58. package/core/hosts/codex.py +3 -0
  59. package/core/hosts/dsh.py +42 -23
  60. package/core/hosts/minimax.py +5 -4
  61. package/core/hosts/opencode.py +11 -3
  62. package/core/i18n.py +94 -5
  63. package/core/infra/README.md +1 -1
  64. package/core/infra/build_info.py +2 -2
  65. package/core/infra/python_runtime.py +4 -1
  66. package/core/launch_phases/README.md +2 -2
  67. package/core/launch_phases/finding_confirm_phase.py +1 -1
  68. package/core/launch_phases/semantic_recon.py +3 -19
  69. package/core/launch_phases/startup_version_gate.py +2 -2
  70. package/core/launch_phases/supervisor_bridge.py +2 -0
  71. package/core/launch_phases/supervisor_degraded.py +7 -5
  72. package/core/launch_phases/verify_loop.py +3 -19
  73. package/core/ledger/README.md +1 -1
  74. package/core/ledger/finding_confirmation.py +1 -1
  75. package/core/ledger/finding_verification.py +2 -20
  76. package/core/ledger/fp_ledger.py +3 -19
  77. package/core/ledger/life_ledger.py +7 -33
  78. package/core/ledger/schema.py +1 -1
  79. package/core/locales/en-US.json +3 -3
  80. package/core/locales/zh-CN.json +3 -3
  81. package/core/mcp_handlers/supervisor_handlers.py +1 -1
  82. package/core/mcp_runtime_support/common.py +6 -0
  83. package/core/mcp_runtime_support/environment.py +88 -24
  84. package/core/metadata.txt +1 -1
  85. package/core/planning/README.md +1 -1
  86. package/core/planning/prompt_harness.py +2 -2
  87. package/core/planning/target_sandbox_manager.py +2 -0
  88. package/core/probes/codebase_memory_probe.py +43 -24
  89. package/core/probes/mobile_probe.py +1 -0
  90. package/core/probes/probe_registry.py +10 -7
  91. package/core/probes/sast_probe.py +1 -1
  92. package/core/probes/sca_scanner.py +1 -1
  93. package/core/project_profiler/constants.py +1 -1
  94. package/core/prompts/command_routing_en.md +6 -5
  95. package/core/prompts/command_routing_zh.md +6 -5
  96. package/core/repair/rsi_rounds.py +3 -0
  97. package/core/repair/self_heal.py +160 -6
  98. package/core/retrieval/README.md +1 -1
  99. package/core/retrieval/symbol_index.py +227 -52
  100. package/core/runtime/README.md +1 -1
  101. package/core/runtime/daemon_runner.py +3 -2
  102. package/core/runtime/project_init.py +1 -1
  103. package/core/runtime/scenario_eval.py +5 -1
  104. package/core/runtime/tool_install_targets.py +12 -2
  105. package/core/skills/README.md +4 -2
  106. package/core/skills/bugx_docs_cloud_sync.py +658 -0
  107. package/core/skills/bugx_docs_mcp_server.py +966 -140
  108. package/core/skills/bugx_mcp_server.py +9 -0
  109. package/core/skills/mcp_session_proof.py +3 -31
  110. package/core/supervisor/README.md +1 -1
  111. package/core/supervisor/finding_commit.py +3 -24
  112. package/core/supervisor/task_scheduler.py +5 -2
  113. package/core/supervisor/worker_execution.py +16 -3
  114. package/core/supervisor/worker_handoff.py +2 -2
  115. package/core/webui/docs_session_service.py +40 -2
  116. package/core/webui/mcp_inspector.py +6 -6
  117. package/ecosystem/integrations/cline/skills/bugx/SKILL.md +46 -46
  118. package/ecosystem/integrations/dsh/agents/bugx.md +2 -1
  119. package/ecosystem/integrations/dsh/mcp/package.json +1 -1
  120. package/ecosystem/integrations/dsh/skills/bugx/SKILL.md +5 -5
  121. package/ecosystem/integrations/dsh/ui/package.json +1 -1
  122. package/ecosystem/integrations/opencode/bugx-mcp-manifest.json +4 -4
  123. package/ecosystem/integrations/opencode/mcp-lock.json +1 -1
  124. package/ecosystem/integrations/pi/extensions/bugx/manifest.json +1 -1
  125. package/ecosystem/integrations/pi/skills/bugx/SKILL.md +5 -5
  126. package/ecosystem/integrations/qoder/CONNECTORS.md +11 -23
  127. package/ecosystem/integrations/qoder/connector-meta.json +1 -1
  128. package/ecosystem/integrations/workbuddy/connector-meta.json +1 -1
  129. package/ecosystem/integrations/workbuddy/skills/bugx/SKILL.md +8 -7
  130. package/ecosystem/plugins/bugx/.claude-plugin/plugin.json +1 -1
  131. package/ecosystem/plugins/bugx/.codex-plugin/plugin.json +1 -1
  132. package/ecosystem/plugins/bugx/.zcode-plugin/plugin.json +1 -1
  133. package/ecosystem/plugins/bugx/agents/bugx-worker.md +14 -18
  134. package/ecosystem/plugins/bugx/agents/bugx.md +45 -49
  135. package/ecosystem/plugins/bugx/skills/bugx/SKILL.md +7 -7
  136. package/ecosystem/plugins/bugx/skills/bugx-zcode/SKILL.md +2 -2
  137. package/interfaces/cli/bugx_cli/__init__.py +1 -1
  138. package/interfaces/cli/bugx_cli/cli.py +153 -8
  139. package/interfaces/cli/bugx_cli/commands/agent.py +376 -69
  140. package/interfaces/cli/bugx_cli/commands/audit.py +2 -1
  141. package/interfaces/cli/bugx_cli/commands/cloud.py +42 -1
  142. package/interfaces/cli/bugx_cli/commands/doctor.py +650 -223
  143. package/interfaces/cli/bugx_cli/commands/guide.py +143 -0
  144. package/interfaces/cli/bugx_cli/commands/issue.py +262 -0
  145. package/interfaces/cli/bugx_cli/commands/lifecycle.py +56 -26
  146. package/interfaces/cli/bugx_cli/commands/patch.py +5 -1
  147. package/interfaces/cli/bugx_cli/commands/plugin.py +306 -56
  148. package/interfaces/cli/bugx_cli/commands/plugin_antigravity.py +350 -0
  149. package/interfaces/cli/bugx_cli/commands/plugin_claude.py +2 -2
  150. package/interfaces/cli/bugx_cli/commands/plugin_kimi.py +154 -62
  151. package/interfaces/cli/bugx_cli/commands/plugin_minimax.py +308 -108
  152. package/interfaces/cli/bugx_cli/commands/system.py +11 -1
  153. package/interfaces/cli/bugx_cli/common.py +39 -8
  154. package/interfaces/cli/bugx_cli/host_adapters.py +46 -3
  155. package/interfaces/cli/bugx_cli/hosts/registry.py +3 -2
  156. package/interfaces/cli/bugx_cli/hosts/template_engine.py +21 -2
  157. package/interfaces/cli/bugx_cli/infra/__init__.py +4 -0
  158. package/interfaces/cli/bugx_cli/infra/ai_advisor.py +14 -12
  159. package/interfaces/cli/bugx_cli/infra/engine_installer.py +76 -10
  160. package/interfaces/cli/bugx_cli/infra/host_sync.py +66 -1
  161. package/interfaces/cli/bugx_cli/infra/mcp_advisor.py +240 -50
  162. package/package.json +3 -2
  163. package/pyproject.toml +22 -2
  164. package/scripts/sync-version.mjs +1 -1
  165. package/skills/README.md +1 -2
  166. package/skills/platform/bugx/SKILL.md +50 -0
  167. package/skills/platform/bugx-user/SKILL.md +0 -92
@@ -32,12 +32,16 @@ flowchart TD
32
32
  | 文件名 | 职责与功能定位 | 关键类 / 函数 |
33
33
  | :--- | :--- | :--- |
34
34
  | `__init__.py` | Python 包初始化与核心模块符号导出 | `__all__` |
35
+ | `agnescode.py` | Agnes Code 宿主专属 ACP 协议实现 | `PLUGIN` |
36
+ | `antigravity.py` | Google Antigravity 宿主专属 ACP 协议实现 | `PLUGIN` |
35
37
  | `base.py` | ACP 协议抽象基座,实现客户端/服务端双向通信握手、消息编解码与心跳保活 | `BaseACPAdapter` |
36
38
  | `claude.py` | Claude 系列宿主的 ACP 扩展适配,处理专属会话流与认证注入 | `ClaudeACPAdapter` |
37
39
  | `cline.py` | Cline 宿主的 ACP 扩展适配,对接 VS Code 扩展通信通道 | `ClineACPAdapter` |
38
40
  | `codex.py` | OpenAI Codex 智能体的 ACP 扩展适配,支持任务流分发与上下文刷新 | `CodexACPAdapter` |
39
41
  | `dsh.py` | DSH 环境的 ACP 协议实现,支持 Shell 会话双向流转 | `DshACPAdapter` |
40
42
  | `INTERFACE.md` | ACP 接口契约说明文档,定义数据帧与错误码 | 协议格式定义 |
43
+ | `kimi.py` | Kimi Code 宿主专属 ACP 协议实现 | `PLUGIN` |
44
+ | `minimax.py` | MiniMax Code 宿主专属 ACP 协议实现 | `PLUGIN` |
41
45
  | `opencode.py` | OpenCode 标准 ACP 协议实现,处理通用智能体事件通道 | `OpenCodeACPAdapter` |
42
46
  | `pi.py` | Pi 智能体 ACP 协议实现,支持轻量级边缘环境适配 | `PiACPAdapter` |
43
47
  | `SPEC.md` | ACP 架构设计规范与长连接稳定性保障标准 | 规范与重连策略 |
@@ -0,0 +1,128 @@
1
+ #!/usr/bin/env python3
2
+ """core/host_acp/agnescode.py - Agnes Code 的 ACP 适配插件。
3
+
4
+ 实机口径:
5
+ * ACP 入口为 ``agnescode acp``(或 ``agnes acp``),工作区绑定由探针 cwd 提供;
6
+ * 探活服务器绑定到探活项目的 ``agnescode.json``(v2 ``mcp.servers`` 形状)。
7
+ """
8
+
9
+ from __future__ import annotations
10
+
11
+ import json
12
+ import os
13
+ from pathlib import Path
14
+ import shutil
15
+ from typing import Any
16
+
17
+ from .base import AcpPlugin
18
+
19
+ __all__ = ["AgnesCodeAcpPlugin", "PLUGIN", "is_available", "run_static_degraded"]
20
+
21
+
22
+ def _resolve_executable() -> str:
23
+ for cmd in ("agnescode", "agnes"):
24
+ found = shutil.which(cmd)
25
+ if found:
26
+ return found
27
+ return "agnescode"
28
+
29
+
30
+ class AgnesCodeAcpPlugin(AcpPlugin):
31
+ """Agnes Code ACP 插件。"""
32
+
33
+ name = "agnescode"
34
+ executable = "agnescode"
35
+ status = "ready"
36
+ supports_project_permissions = True
37
+
38
+ def acp_argv(
39
+ self,
40
+ *,
41
+ model: str | None = None,
42
+ data_dir: Path | str | None = None,
43
+ ) -> list[str]:
44
+ del model, data_dir
45
+ return [_resolve_executable(), "acp"]
46
+
47
+ def ensure_probe_servers(
48
+ self,
49
+ project_root: Path,
50
+ config_paths: tuple[Path, ...],
51
+ servers: dict[str, dict[str, Any]],
52
+ ) -> list[str]:
53
+ """把 BugX 通道绑定到探活项目的 ``agnescode.json``(v2 ``mcp.servers`` 形状)。"""
54
+ updated: list[str] = []
55
+ root_resolved = project_root.resolve()
56
+ for path in config_paths:
57
+ try:
58
+ resolved = path.resolve()
59
+ except OSError:
60
+ continue
61
+ if root_resolved not in resolved.parents and resolved.parent != root_resolved:
62
+ continue
63
+ try:
64
+ if resolved.is_symlink() or not resolved.is_file():
65
+ continue
66
+ payload = json.loads(resolved.read_text(encoding="utf-8"))
67
+ except (OSError, UnicodeError, ValueError):
68
+ continue
69
+ if not isinstance(payload, dict):
70
+ continue
71
+ if "mcp" not in payload:
72
+ payload["mcp"] = {}
73
+ block = payload["mcp"]
74
+ if not isinstance(block, dict):
75
+ raise ValueError(f"AgnesCode v2 mcp 配置必须是对象: {resolved}")
76
+ entries = block.get("servers")
77
+ if "servers" not in block:
78
+ entries = {}
79
+ block["servers"] = entries
80
+ if not isinstance(entries, dict):
81
+ raise ValueError(f"AgnesCode v2 mcp.servers 必须是对象: {resolved}")
82
+
83
+ changed = False
84
+ for server_name, server_def in servers.items():
85
+ target_def = {
86
+ "type": "local",
87
+ "command": [server_def.get("command", "bugx"), *server_def.get("args", [])],
88
+ "disabled": False,
89
+ }
90
+ if entries.get(server_name) != target_def:
91
+ entries[server_name] = target_def
92
+ changed = True
93
+
94
+ if changed:
95
+ resolved.write_text(
96
+ json.dumps(payload, ensure_ascii=False, indent=2) + "\n",
97
+ encoding="utf-8",
98
+ )
99
+ updated.append(str(resolved))
100
+ return updated
101
+
102
+
103
+ PLUGIN = AgnesCodeAcpPlugin
104
+
105
+
106
+ def is_available() -> tuple[bool, str]:
107
+ for cmd in ("agnescode", "agnes"):
108
+ found = shutil.which(cmd)
109
+ if found:
110
+ return True, found
111
+ return False, "agnescode 可执行文件未安装;ACP 通道不可用"
112
+
113
+
114
+ def run_static_degraded(root: Path | None = None) -> dict[str, Any]:
115
+ available, detail = is_available()
116
+ return {
117
+ "plugin": "agnescode",
118
+ "schema_version": 1,
119
+ "success": available,
120
+ "status": "degraded",
121
+ "degraded": True,
122
+ "degraded_reason": "static_facts_only" if available else "agnescode_not_installed",
123
+ "probe_mode": "static_degraded",
124
+ "evidence": {
125
+ "availability_detail": detail,
126
+ "project_root": str(root) if root else None,
127
+ },
128
+ }
@@ -0,0 +1,153 @@
1
+ """Antigravity ACP adapter.
2
+
3
+ ``agy acp`` is a real ACP v1 server. Authentication remains an external
4
+ precondition owned by Antigravity; the adapter must expose the correct command
5
+ and let the probe report ``Authentication required`` instead of hiding it as a
6
+ missing/unsupported ACP implementation.
7
+ """
8
+
9
+ from __future__ import annotations
10
+
11
+ import json
12
+ import os
13
+ from pathlib import Path
14
+ import sys
15
+ import tempfile
16
+ from typing import Any
17
+
18
+ from .base import AcpPlugin
19
+
20
+
21
+ class AntigravityAcpPlugin(AcpPlugin):
22
+ name = "antigravity"
23
+ executable = "agy"
24
+ status = "ready"
25
+ supports_project_permissions = False
26
+
27
+ def acp_argv(
28
+ self,
29
+ *,
30
+ model: str | None = None,
31
+ data_dir: Path | str | None = None,
32
+ ) -> list[str]:
33
+ # Antigravity exposes no model/data-dir ACP flags. The selected Agent
34
+ # is explicit so ACP cannot silently fall back to the default Agent.
35
+ # The official ACP flag is required for an unattended client to execute
36
+ # MCP calls; otherwise Antigravity emits a permission request that a
37
+ # headless ACP client cannot approve and the tool call is denied.
38
+ del model, data_dir
39
+ return [
40
+ "agy", "acp", "--agent", "BugX",
41
+ "--dangerously-skip-permissions", "--disable-telemetry",
42
+ ]
43
+
44
+ def launch_policy(self) -> dict[str, object]:
45
+ return {
46
+ "auto_approve": True,
47
+ "auto_approve_flag": "--dangerously-skip-permissions",
48
+ "model_flag": None,
49
+ "reason": (
50
+ "Antigravity ACP 使用缓存登录凭据;无人值守 MCP 探活必须使用官方 "
51
+ "--dangerously-skip-permissions,否则 ACP 客户端无法批准工具请求;"
52
+ "无凭据时由宿主返回 Authentication required"
53
+ ),
54
+ }
55
+
56
+ def ensure_probe_servers(
57
+ self,
58
+ project_root: Path,
59
+ config_paths: tuple[Path, ...],
60
+ servers: dict[str, dict[str, Any]],
61
+ ) -> list[str]:
62
+ """重绑隔离项目的 MCP,并保持 ACP 冷启动的直通引擎启动器。
63
+
64
+ Antigravity 会在 ACP 会话建立前预加载 stdio MCP。探针项目是从真实项目
65
+ 复制出来的,不能沿用真实项目的绝对 ``--root``;而通用探针定义使用完整
66
+ ``bugx`` CLI,在 Windows 冷启动窗口内又可能超时。因此这里由宿主适配器
67
+ 重建三条 BugX 条目:解释器直接执行已安装引擎的 ``skills/*_mcp_server.py``。
68
+ 只允许改写探针项目内部的 ``.agents/mcp_config.json``。
69
+ """
70
+ project_root = Path(project_root).resolve()
71
+ engine_override = os.environ.get("BUGX_GLOBAL_ENGINE_ROOT", "").strip()
72
+ engine_root = (
73
+ Path(engine_override).expanduser().resolve()
74
+ if engine_override
75
+ else (Path.home() / ".bugx" / "core").resolve()
76
+ )
77
+ python = str(Path(sys.executable).resolve())
78
+ expected: dict[str, dict[str, Any]] = {}
79
+ roles = {
80
+ "bugx-supervisor": "host",
81
+ "bugx-supervisor-worker": "worker",
82
+ }
83
+ for name, role in roles.items():
84
+ script = engine_root / "skills" / "bugx_mcp_server.py"
85
+ if not script.is_file():
86
+ raise ValueError(f"Antigravity 探活缺少 BugX 引擎脚本: {script}")
87
+ expected[name] = {
88
+ "type": "stdio",
89
+ "command": python,
90
+ "args": [
91
+ str(script), "serve", "--root", str(project_root),
92
+ "--role", role,
93
+ ],
94
+ }
95
+ docs_script = engine_root / "skills" / "bugx_docs_mcp_server.py"
96
+ if not docs_script.is_file():
97
+ raise ValueError(f"Antigravity 探活缺少 BugX 文档引擎脚本: {docs_script}")
98
+ expected["bugx-docs"] = {
99
+ "type": "stdio",
100
+ "command": python,
101
+ "args": [
102
+ str(docs_script), "serve", "--root", str(project_root),
103
+ "--db", str(project_root / ".bugx" / "knowledge" / "docs.sqlite3"),
104
+ ],
105
+ }
106
+ # ``servers`` 是探针的通用输入;名称集合仍由探针控制,具体命令由本适配器
107
+ # 收敛为直通引擎定义,避免隐式接受第三方条目。
108
+ names = [name for name in expected if name in servers]
109
+ updated: list[str] = []
110
+ for path in config_paths:
111
+ try:
112
+ resolved = path.resolve()
113
+ except OSError:
114
+ continue
115
+ if project_root not in resolved.parents or resolved.is_symlink() or not resolved.is_file():
116
+ continue
117
+ try:
118
+ payload = json.loads(resolved.read_text(encoding="utf-8"))
119
+ except (OSError, UnicodeError, ValueError):
120
+ continue
121
+ if not isinstance(payload, dict):
122
+ continue
123
+ block = payload.get("mcpServers")
124
+ if not isinstance(block, dict):
125
+ block = {}
126
+ payload["mcpServers"] = block
127
+ changed = False
128
+ for name in names:
129
+ if block.get(name) != expected[name]:
130
+ block[name] = expected[name]
131
+ changed = True
132
+ if name not in updated:
133
+ updated.append(name)
134
+ if not changed:
135
+ continue
136
+ mode = resolved.stat().st_mode & 0o777
137
+ fd, tmp_name = tempfile.mkstemp(
138
+ prefix=f".{resolved.name}.", suffix=".tmp", dir=resolved.parent,
139
+ )
140
+ tmp = Path(tmp_name)
141
+ try:
142
+ with os.fdopen(fd, "w", encoding="utf-8") as stream:
143
+ stream.write(json.dumps(payload, ensure_ascii=False, indent=2) + "\n")
144
+ stream.flush()
145
+ os.fsync(stream.fileno())
146
+ os.chmod(tmp, mode)
147
+ os.replace(tmp, resolved)
148
+ finally:
149
+ tmp.unlink(missing_ok=True)
150
+ return updated
151
+
152
+
153
+ PLUGIN = AntigravityAcpPlugin
@@ -38,6 +38,7 @@ flowchart TD
38
38
  | :--- | :--- | :--- |
39
39
  | `__init__.py` | Python 包初始化与核心模块符号导出 | `__all__` |
40
40
  | `adapters.py` | 宿主运行时适配器转接层,抹平不同宿主在 CLI / API 交互上的协议差异 | `RuntimeAdapterFactory` |
41
+ | `antigravity.py` | Google Antigravity 宿主专用运行时适配 | `AntigravityRuntimeAdapter` |
41
42
  | `autonomous_runner.py` | 自主攻防运行器主干,驱动无头环境下的全自动循环(Pre $\rightarrow$ Run $\rightarrow$ Post) | `AutonomousRunner` |
42
43
  | `cline.py` | Cline / Roo Code 运行时特定扩展,处理专用会话注入与命令执行 | `ClineRuntimeAdapter` |
43
44
  | `common.py` | 运行时共享工具函数,包括超时保护、跨平台管道封装与环境变量清洗 | `run_with_timeout`, `sanitize_env` |
@@ -51,6 +52,8 @@ flowchart TD
51
52
  | `INTERFACE.md` | 运行时模块间协议接口规范 | 运行时状态与生命周期契约 |
52
53
  | `mcp_process_tracker.py` | MCP 守护进程追踪器,记录每个拉起的 MCP Server PID,防止孤儿进程泄漏 | `MCPProcessTracker` |
53
54
  | `mcp_registry_gate.py` | MCP 注册表门禁校验器,确保 MCP 服务配置完整有效,防止假死启动 | `verify_mcp_registry` |
55
+ | `pi.py` | Pi 宿主专用运行时适配与超时预算透传 | `PiRuntimeAdapter` |
56
+ | `provider_facts.py` | 宿主模型事实与提供商元数据表 | `ProviderFacts` |
54
57
  | `SPEC.md` | 运行时技术设计规范文档 | 子进程模型与信号传播规则 |
55
58
 
56
59
  ---
@@ -49,6 +49,8 @@ class HostAdapter:
49
49
  name = "unknown"
50
50
  executable = ""
51
51
  host_surface = "tui"
52
+ mcp_config_container: str | None = None
53
+ merge_mcp_config_fields = True
52
54
 
53
55
  def is_callable(self, root: Path) -> bool:
54
56
  """Return whether this host has a callable local entry point.
@@ -246,6 +248,8 @@ class QoderAdapter(HostAdapter):
246
248
 
247
249
  name = "qoder"
248
250
  executable = "qoder"
251
+ mcp_config_container = "mcpServers"
252
+ merge_mcp_config_fields = False
249
253
 
250
254
  def headless_run(self, root: Path, agent: str, session: str, prompt: str) -> list[str]:
251
255
  return ["qoder", "run", "--prompt", prompt]
@@ -254,7 +258,7 @@ class QoderAdapter(HostAdapter):
254
258
  return root / ".qoder"
255
259
 
256
260
  def mcp_config_paths(self, root: Path) -> tuple[Path, ...]:
257
- return (root / ".qoder" / "mcp.json",)
261
+ return (root / ".qoder" / "settings.json", root / ".mcp.json")
258
262
 
259
263
  def required_mcp(self, root: Path) -> list[str]:
260
264
  return list(MCP_CATALOG)
@@ -0,0 +1,162 @@
1
+ #!/usr/bin/env python3
2
+ """Antigravity Worker process executor.
3
+
4
+ The Agent, not this module, owns the BugX lifecycle decisions. This module
5
+ only starts one bounded ``agy`` Worker process after a claim exists, binds it to
6
+ the requested workspace, and refuses to report success without a Supervisor
7
+ checkpoint.
8
+ """
9
+
10
+ from __future__ import annotations
11
+
12
+ import os
13
+ import shutil
14
+ import subprocess
15
+ from pathlib import Path
16
+ from typing import Any
17
+
18
+ import core.hosts as host_plugins
19
+
20
+ from .common import (
21
+ WorkerRuntimeError,
22
+ claim_checkpoint_id,
23
+ terminate_process_group,
24
+ )
25
+
26
+ __all__ = ["execute_worker"]
27
+
28
+
29
+ _HOST_NAME = __name__.rsplit(".", 1)[-1]
30
+ _PLUGIN = host_plugins.get(_HOST_NAME)
31
+ if _PLUGIN is None: # pragma: no cover - plugin removal is an import-time defect
32
+ raise RuntimeError(f"{__name__} 需要 core/hosts/{_HOST_NAME}.py 声明;插件缺失")
33
+
34
+ _NAME = _PLUGIN.name
35
+ _PROVIDER_KEY = _PLUGIN.worker_runtime.provider_key or _NAME
36
+
37
+
38
+ def execute_worker(
39
+ workspace_root: Path,
40
+ claim: Any,
41
+ task_spec: str,
42
+ *,
43
+ supervisor: Any,
44
+ stage_name: str,
45
+ executable: str | None = None,
46
+ model: str | None = None,
47
+ provider: str | None = None,
48
+ ) -> dict[str, Any]:
49
+ """Run one pre-claimed Antigravity Worker and require a checkpoint."""
50
+
51
+ del provider
52
+ from core.supervisor.worker_runtime import resolve_worker_timeout
53
+
54
+ failure = f"{_NAME}_worker_failed"
55
+ root = workspace_root.resolve()
56
+ worker_id = getattr(claim, "worker_id", str(claim))
57
+ execution_id = getattr(claim, "execution_id", f"exec-{worker_id}")
58
+ artifact_root_rel = getattr(claim, "artifact_root", "")
59
+ if artifact_root_rel:
60
+ artifact_dir = (root / artifact_root_rel).resolve()
61
+ if artifact_dir != root and root not in artifact_dir.parents:
62
+ raise WorkerRuntimeError(f"{failure}: claim artifact_root 越界")
63
+ artifact_dir.mkdir(parents=True, exist_ok=True)
64
+
65
+ profile_budget = getattr(_PLUGIN.worker_runtime, "worker_timeout_seconds", None)
66
+ base_override = (
67
+ float(profile_budget)
68
+ if isinstance(profile_budget, (int, float))
69
+ and not isinstance(profile_budget, bool)
70
+ and profile_budget > 0
71
+ else None
72
+ )
73
+ timeout_seconds = resolve_worker_timeout(
74
+ model_tier={
75
+ "exploit": "tier_2_exploit",
76
+ "verify": "tier_3_verify",
77
+ }.get(str(stage_name).split("-")[-1], "tier_1_recon"),
78
+ attempt=int(getattr(claim, "attempt", 1) or 1),
79
+ base_override=base_override,
80
+ )
81
+
82
+ host_executable = executable or shutil.which("agy") or "agy"
83
+ command = [
84
+ host_executable,
85
+ "--agent", "bugx-worker",
86
+ "--mode", "auto",
87
+ "--dangerously-skip-permissions",
88
+ "--add-dir", str(root),
89
+ "--output-format", "json",
90
+ "-p", task_spec,
91
+ ]
92
+ if model:
93
+ command[3:3] = ["--model", str(model)]
94
+
95
+ environment = os.environ.copy()
96
+ popen_kwargs: dict[str, Any] = {
97
+ "cwd": str(root),
98
+ "env": environment,
99
+ "stdout": subprocess.PIPE,
100
+ "stderr": subprocess.PIPE,
101
+ "text": True,
102
+ }
103
+ if os.name == "posix":
104
+ popen_kwargs["preexec_fn"] = os.setsid
105
+ elif os.name == "nt": # pragma: no cover - exercised on Windows hosts
106
+ popen_kwargs["creationflags"] = getattr(subprocess, "CREATE_NEW_PROCESS_GROUP", 0)
107
+
108
+ process = subprocess.Popen(command, **popen_kwargs)
109
+ try:
110
+ supervisor.start_worker(
111
+ worker_id,
112
+ provider=_PROVIDER_KEY,
113
+ execution_id=execution_id,
114
+ process_pid=process.pid,
115
+ )
116
+ except Exception:
117
+ terminate_process_group(process)
118
+ try:
119
+ process.communicate(timeout=5)
120
+ except (subprocess.TimeoutExpired, OSError):
121
+ terminate_process_group(process, force=True)
122
+ raise
123
+
124
+ try:
125
+ stdout, stderr = process.communicate(timeout=timeout_seconds)
126
+ except subprocess.TimeoutExpired as exc:
127
+ terminate_process_group(process)
128
+ try:
129
+ stdout, stderr = process.communicate(timeout=5)
130
+ except (subprocess.TimeoutExpired, OSError):
131
+ terminate_process_group(process, force=True)
132
+ stdout, stderr = "", ""
133
+ checkpoint_id = claim_checkpoint_id(supervisor, worker_id, execution_id)
134
+ if checkpoint_id is None:
135
+ raise WorkerRuntimeError(
136
+ f"{failure}: timeout after {timeout_seconds:.1f}s"
137
+ ) from exc
138
+ return {
139
+ "worker_id": worker_id,
140
+ "checkpoint_id": checkpoint_id,
141
+ "status": "checkpointed",
142
+ "exit_code": process.returncode,
143
+ "stdout": (stdout or "")[-2000:],
144
+ "stderr": (stderr or "")[-2000:],
145
+ }
146
+
147
+ checkpoint_id = claim_checkpoint_id(supervisor, worker_id, execution_id)
148
+ if checkpoint_id is None:
149
+ detail = (stderr or stdout or "").strip()[-500:]
150
+ raise WorkerRuntimeError(
151
+ f"{failure}: process exited without a valid Checkpoint"
152
+ + (f": {detail}" if detail else "")
153
+ )
154
+ return {
155
+ "worker_id": worker_id,
156
+ "checkpoint_id": checkpoint_id,
157
+ "status": "checkpointed",
158
+ "exit_code": process.returncode,
159
+ "stdout": (stdout or "")[-2000:],
160
+ "stderr": (stderr or "")[-2000:],
161
+ }
162
+
@@ -189,8 +189,23 @@ def _extract_json_object(output: str) -> dict | None:
189
189
  return None
190
190
 
191
191
 
192
- def _builtin_mcp_servers() -> dict[str, dict[str, object]]:
193
- """Return the three fixed BugX local MCP registrations."""
192
+ def _builtin_mcp_servers(
193
+ *, docs_transport: str = "stdio", remote_url: str | None = None,
194
+ ) -> dict[str, dict[str, object]]:
195
+ """Return the three fixed BugX MCP registrations."""
196
+ if docs_transport == "remote":
197
+ from core.skills.bugx_docs_cloud_sync import contract_version_of, resolve_remote_base_url
198
+ base = resolve_remote_base_url(remote_url)
199
+ ver = contract_version_of()
200
+ docs_entry: dict[str, object] = {
201
+ "url": f"{base}/api/v1/mcp/docs?contract_version={ver}",
202
+ }
203
+ else:
204
+ docs_entry = {
205
+ "command": "bugx",
206
+ "args": ["mcp", "docs", "serve", "--root", ".",
207
+ "--db", ".bugx/knowledge/docs.sqlite3"],
208
+ }
194
209
  return {
195
210
  "bugx-supervisor": {
196
211
  "command": "bugx",
@@ -200,11 +215,7 @@ def _builtin_mcp_servers() -> dict[str, dict[str, object]]:
200
215
  "command": "bugx",
201
216
  "args": ["mcp", "serve", "--root", ".", "--role", "worker"],
202
217
  },
203
- "bugx-docs": {
204
- "command": "bugx",
205
- "args": ["mcp", "docs", "serve", "--root", ".",
206
- "--db", ".bugx/knowledge/docs.sqlite3"],
207
- },
218
+ "bugx-docs": docs_entry,
208
219
  }
209
220
 
210
221
 
@@ -62,13 +62,13 @@ DEFAULT_MODELS_BY_PROVIDER = {
62
62
  "openai-codex": "gpt-4o",
63
63
  "openai-native": "gpt-4o",
64
64
  "openai": "gpt-4o",
65
- "anthropic": "claude-3-5-sonnet-20241022",
66
- "google": "gemini-1.5-pro",
67
- "gemini": "gemini-1.5-pro",
65
+ "anthropic": "claude-sonnet-5-5",
66
+ "google": "gemini-4-carbon",
67
+ "gemini": "gemini-4-carbon",
68
68
  "deepseek": "deepseek-chat",
69
69
  "bigmodel": "GLM-5.3",
70
70
  "zai": "glm-4.7",
71
- "cline": "claude-3-5-sonnet-20241022",
71
+ "cline": "claude-sonnet-5-5",
72
72
  "9router": "9dev",
73
73
  "ocsg": "deepseek-v4.1-flash-1017",
74
74
  }
@@ -40,6 +40,8 @@ SUPPORTED_HOSTS: tuple[str, ...] = (
40
40
  "dsh",
41
41
  "kimi",
42
42
  "minimax",
43
+ "antigravity",
44
+ "agnescode",
43
45
  "chatgpt",
44
46
  "workbuddy",
45
47
  "qoder",
@@ -66,7 +68,7 @@ HOST_MARKERS: dict[str, tuple[str, ...]] = {
66
68
  ".workbuddy",
67
69
  ".codebuddy",
68
70
  ),
69
- "qoder": (".qoder", ".qoder/config.json", ".qoder/mcp.json"),
71
+ "qoder": (".qoder",),
70
72
  # 真实 Trae / Trae CN 打开过的项目只会有 .trae/ 或 .trae-cn/ 目录;.trea 是 BugX 安装面。
71
73
  "trea": (".trea", ".trea/agent.yml", ".trea/mcp.json", ".trae", ".trae-cn"),
72
74
  "funide": (".github/agents/bugx.agent.md",),
@@ -29,7 +29,9 @@ def _config_candidates(root: Path, adapter: HostAdapter) -> tuple[Path, ...]:
29
29
  return adapter.mcp_config_paths(root)
30
30
 
31
31
 
32
- def _read_mcp_document(path: Path, *, require_nested_mcp: bool = False) -> dict:
32
+ def _read_mcp_document(
33
+ path: Path, *, require_nested_mcp: bool = False, container_key: str | None = None,
34
+ ) -> dict:
33
35
  try:
34
36
  if not path.is_file():
35
37
  return {}
@@ -40,6 +42,9 @@ def _read_mcp_document(path: Path, *, require_nested_mcp: bool = False) -> dict:
40
42
  data = json.loads(path.read_text(encoding="utf-8"))
41
43
  if not isinstance(data, dict):
42
44
  return {}
45
+ if container_key is not None:
46
+ servers = data.get(container_key)
47
+ return servers if isinstance(servers, dict) else {}
43
48
  if require_nested_mcp and {"plugin", "permission", "tools", "agent"}.intersection(data):
44
49
  return {}
45
50
  for key in ("mcp", "mcpServers", "mcp_servers"):
@@ -77,10 +82,13 @@ def _read_mcp_config(root: Path, adapter: HostAdapter) -> dict:
77
82
  for path in _config_candidates(root, adapter):
78
83
  for name, value in _read_mcp_document(
79
84
  path, require_nested_mcp=adapter.name == "opencode",
85
+ container_key=adapter.mcp_config_container,
80
86
  ).items():
81
87
  if isinstance(value, dict):
82
- current = merged.setdefault(name, {})
83
- current.update(value)
88
+ if adapter.merge_mcp_config_fields:
89
+ merged.setdefault(name, {}).update(value)
90
+ else:
91
+ merged[name] = value
84
92
  else:
85
93
  merged[name] = {"value": value}
86
94
  return merged
@@ -507,3 +515,22 @@ def active_mcp_process_probe(
507
515
  }
508
516
 
509
517
 
518
+ def probe_remote_docs_mcp(
519
+ mcp_config: Mapping[str, Mapping[str, object]],
520
+ ) -> dict[str, object]:
521
+ """检查宿主配置中 bugx-docs 是否为远程 HTTP URL 模式,防止误报缺本地 stdio 进程 (NEG-09)。"""
522
+ cfg = mcp_config.get("bugx-docs")
523
+ if not isinstance(cfg, Mapping) or cfg.get("enabled", True) is False:
524
+ return {"configured": False, "transport": "missing"}
525
+ raw_url = str(cfg.get("url") or "").strip()
526
+ if not raw_url:
527
+ cmd = _configured_server_command(cfg)
528
+ return {"configured": bool(cmd), "transport": "stdio", "command": cmd}
529
+ from core.cloud_sync.endpoint_router import validate_base_url
530
+ try:
531
+ normalized = validate_base_url(raw_url.split("?", 1)[0])
532
+ return {"configured": True, "transport": "remote-http", "url": normalized, "healthy": True}
533
+ except ValueError as exc:
534
+ return {"configured": True, "transport": "remote-http", "url": raw_url, "healthy": False, "error": str(exc)}
535
+
536
+