bugx-cli 0.1.4 → 0.1.6

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 (127) hide show
  1. package/README.md +89 -210
  2. package/core/README.md +1 -1
  3. package/core/agent/agent_execution.py +7 -0
  4. package/core/agent/agent_targets.py +5 -1
  5. package/core/agent/agent_workspace.py +10 -2
  6. package/core/autonomous_cve/run_fault_matrix.py +692 -0
  7. package/core/autonomous_cve/run_oss_cve_exploit_verify.py +608 -0
  8. package/core/autonomous_cve/run_six_worker_penetration.py +382 -0
  9. package/core/autonomous_cve/verifier.py +5 -7
  10. package/core/bugx.md +1 -1
  11. package/core/bugx_paths.py +2 -2
  12. package/core/bundled_docs/OVERVIEW.md +70 -236
  13. package/core/bundled_docs/README.md +2 -2
  14. package/core/bundled_docs/README_EN.md +67 -211
  15. package/core/bundled_docs/ai/01_AI_REFERENCE.md +11 -6
  16. package/core/bundled_docs/ai/02_AI_USAGE.md +1 -1
  17. package/core/bundled_docs/ai/03_AI_COMMANDS.md +1 -1
  18. package/core/bundled_docs/guides/01_USER_GUIDE.md +5 -5
  19. package/core/bundled_docs/guides/02_COMMANDS.md +3 -3
  20. package/core/bundled_docs/guides/03_TROUBLESHOOTING.md +4 -4
  21. package/core/bundled_docs/guides/05_HOST_MATRIX_AND_DISPATCH.md +4 -2
  22. package/core/bundled_docs/hosts/bugx_SKILL.md +2 -2
  23. package/core/bundled_docs/hosts/platform_bugx_SKILL.md +2 -2
  24. package/core/bundled_docs/manifest.json +22 -22
  25. package/core/bundled_docs/reference/01_ENVIRONMENT_VARIABLES.md +1 -0
  26. package/core/bundled_docs/reference/04_REPOSITORY_TOPOLOGY.md +1 -1
  27. package/core/cloud_sync/flywheel_client.py +89 -0
  28. package/core/contracts/README.md +1 -1
  29. package/core/contracts/bugx-runtime-contract.md +1 -1
  30. package/core/contracts/bugx-worker.md +1 -1
  31. package/core/coverage/coverage_ai_review.py +15 -11
  32. package/core/coverage/coverage_bootstrap.py +18 -13
  33. package/core/coverage/coverage_discovery.py +1 -1
  34. package/core/coverage/coverage_gate.py +12 -2
  35. package/core/coverage/coverage_manifest.py +1 -1
  36. package/core/coverage/coverage_validate.py +5 -3
  37. package/core/dev_harness/interaction_preset.py +1 -1
  38. package/core/engine-integrity.json +183 -163
  39. package/core/host_acp/README.md +4 -0
  40. package/core/host_acp/agnescode.py +128 -0
  41. package/core/host_runtime/README.md +3 -0
  42. package/core/host_runtime/adapters.py +45 -6
  43. package/core/host_runtime/autonomous_runner.py +3 -2
  44. package/core/host_runtime/host_registry.py +7 -1
  45. package/core/hosts/README.md +4 -0
  46. package/core/hosts/__init__.py +1 -0
  47. package/core/hosts/agnescode.py +415 -0
  48. package/core/hosts/base.py +1 -0
  49. package/core/hosts/claude.py +6 -0
  50. package/core/hosts/cline.py +6 -0
  51. package/core/hosts/codex.py +10 -1
  52. package/core/hosts/kimi.py +6 -4
  53. package/core/hosts/opencode.py +12 -4
  54. package/core/hosts/zcode.py +6 -0
  55. package/core/infra/README.md +1 -1
  56. package/core/infra/build_info.py +2 -2
  57. package/core/infra/python_runtime.py +4 -1
  58. package/core/launch_phases/README.md +2 -2
  59. package/core/launch_phases/finding_confirm_phase.py +1 -1
  60. package/core/launch_phases/semantic_recon.py +3 -19
  61. package/core/launch_phases/startup_gates.py +10 -1
  62. package/core/launch_phases/startup_version_gate.py +2 -2
  63. package/core/launch_phases/verify_loop.py +3 -19
  64. package/core/ledger/README.md +1 -1
  65. package/core/ledger/finding_confirmation.py +1 -1
  66. package/core/ledger/finding_verification.py +2 -20
  67. package/core/ledger/fp_ledger.py +3 -19
  68. package/core/ledger/life_ledger.py +7 -33
  69. package/core/ledger/schema.py +1 -1
  70. package/core/locales/en-US.json +2 -0
  71. package/core/locales/zh-CN.json +2 -0
  72. package/core/mcp_handlers/supervisor_handlers.py +34 -2
  73. package/core/mcp_handlers/telemetry_handlers.py +32 -0
  74. package/core/mcp_handlers/tool_table.py +34 -0
  75. package/core/mcp_runtime_support/common.py +6 -0
  76. package/core/mcp_runtime_support/environment.py +82 -23
  77. package/core/metadata.txt +1 -1
  78. package/core/planning/README.md +1 -1
  79. package/core/planning/target_sandbox_manager.py +2 -0
  80. package/core/probes/mobile_probe.py +1 -0
  81. package/core/probes/sast_probe.py +1 -1
  82. package/core/probes/sca_scanner.py +1 -1
  83. package/core/project_profiler/constants.py +1 -1
  84. package/core/retrieval/README.md +1 -1
  85. package/core/retrieval/symbol_index.py +229 -53
  86. package/core/retrieval/universal_code_matcher.py +1 -0
  87. package/core/runtime/README.md +1 -1
  88. package/core/runtime/daemon_runner.py +3 -2
  89. package/core/runtime/mining_quality_framework.py +2 -1
  90. package/core/runtime/project_init.py +1 -1
  91. package/core/runtime/scenario_eval.py +5 -2
  92. package/core/skills/bugx_mcp_server.py +9 -0
  93. package/core/skills/mcp_session_proof.py +3 -31
  94. package/core/supervisor/README.md +1 -1
  95. package/core/supervisor/finding_commit.py +3 -24
  96. package/core/supervisor/task_scheduler.py +5 -2
  97. package/core/supervisor/worker_execution.py +5 -0
  98. package/core/supervisor/worker_handoff.py +2 -2
  99. package/docs/07_distribution/01_README_NPM.md +89 -210
  100. package/ecosystem/integrations/dsh/mcp/package.json +2 -2
  101. package/ecosystem/integrations/dsh/ui/package.json +1 -1
  102. package/ecosystem/integrations/opencode/bugx-mcp-manifest.json +3 -3
  103. package/ecosystem/integrations/opencode/mcp-lock.json +1 -1
  104. package/ecosystem/integrations/pi/extensions/bugx/manifest.json +1 -1
  105. package/ecosystem/integrations/qoder/connector-meta.json +1 -1
  106. package/ecosystem/integrations/workbuddy/connector-meta.json +1 -1
  107. package/ecosystem/integrations/workbuddy/skills/bugx/SKILL.md +1 -1
  108. package/ecosystem/plugins/bugx/.claude-plugin/plugin.json +1 -1
  109. package/ecosystem/plugins/bugx/.codex-plugin/plugin.json +1 -1
  110. package/ecosystem/plugins/bugx/.zcode-plugin/plugin.json +1 -1
  111. package/ecosystem/plugins/bugx/skills/bugx/SKILL.md +2 -2
  112. package/interfaces/cli/bugx_cli/__init__.py +1 -1
  113. package/interfaces/cli/bugx_cli/cli.py +15 -0
  114. package/interfaces/cli/bugx_cli/commands/agent.py +18 -0
  115. package/interfaces/cli/bugx_cli/commands/audit.py +5 -6
  116. package/interfaces/cli/bugx_cli/commands/doctor.py +1 -1
  117. package/interfaces/cli/bugx_cli/commands/lifecycle.py +1 -1
  118. package/interfaces/cli/bugx_cli/commands/patch.py +5 -1
  119. package/interfaces/cli/bugx_cli/commands/plugin.py +31 -2
  120. package/interfaces/cli/bugx_cli/commands/plugin_claude.py +2 -2
  121. package/interfaces/cli/bugx_cli/host_adapters.py +167 -1
  122. package/interfaces/cli/bugx_cli/hosts/registry.py +33 -1
  123. package/interfaces/cli/bugx_cli/infra/engine_installer.py +4 -4
  124. package/interfaces/cli/bugx_cli/infra/host_sync.py +1 -1
  125. package/package.json +1 -1
  126. package/scripts/sync-version.mjs +1 -1
  127. package/skills/platform/bugx/SKILL.md +2 -2
@@ -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 = getattr(ctx, "model", None) or _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
+ }
@@ -75,6 +75,7 @@ class RunContext:
75
75
  agent: str
76
76
  session: str
77
77
  prompt: str
78
+ model: str | None = None
78
79
 
79
80
 
80
81
 
@@ -61,6 +61,9 @@ def _headless_argv(ctx: RunContext) -> list[str]:
61
61
  command = ["claude", "-p", ctx.prompt]
62
62
  if ctx.session:
63
63
  command[1:1] = ["--resume", ctx.session]
64
+ model = getattr(ctx, "model", None)
65
+ if model:
66
+ command += ["--model", model]
64
67
  return command
65
68
 
66
69
 
@@ -68,6 +71,9 @@ def _autonomous_argv(ctx: RunContext) -> list[str]:
68
71
  command = ["claude"]
69
72
  if ctx.session:
70
73
  command += ["--resume", ctx.session]
74
+ model = getattr(ctx, "model", None)
75
+ if model:
76
+ command += ["--model", model]
71
77
  command += [
72
78
  "-p", ctx.prompt,
73
79
  "--output-format", "json",
@@ -87,6 +87,9 @@ def _mcp_settings_path(root: Path) -> Path:
87
87
 
88
88
  def _headless_argv(ctx: RunContext) -> list[str]:
89
89
  command = ["cline", "--json"]
90
+ model = getattr(ctx, "model", None)
91
+ if model:
92
+ command += ["-m", model]
90
93
  if ctx.session:
91
94
  command += ["--id", ctx.session]
92
95
  return [*command, ctx.prompt]
@@ -94,6 +97,9 @@ def _headless_argv(ctx: RunContext) -> list[str]:
94
97
 
95
98
  def _autonomous_argv(ctx: RunContext) -> list[str]:
96
99
  command = ["cline", "--json", "--auto-approve", "true"]
100
+ model = getattr(ctx, "model", None)
101
+ if model:
102
+ command += ["-m", model]
97
103
  if ctx.session:
98
104
  command += ["--id", ctx.session]
99
105
  return [*command, ctx.prompt]
@@ -172,11 +172,17 @@ def _headless_argv(ctx: RunContext) -> list[str]:
172
172
  # workspace-write」(``codex exec --help``),与 ``_autonomous_argv`` 保持同一
173
173
  # approval 语义:无头通道没有人类可以点「允许」,缺它等于让每个 Worker 的
174
174
  # 控制面调用恒失败。
175
- return [
175
+ cmd = [
176
176
  "codex", "exec", "--approve-for-me",
177
+ ]
178
+ model = getattr(ctx, "model", None)
179
+ if model:
180
+ cmd += ["-m", model]
181
+ cmd += [
177
182
  *_state_grants(),
178
183
  ctx.prompt,
179
184
  ]
185
+ return cmd
180
186
 
181
187
 
182
188
  _SCOUT_FEATURE_OPTIONS = (
@@ -319,6 +325,9 @@ def _autonomous_argv(ctx: RunContext) -> list[str]:
319
325
  # 不加 ``--skip-git-repo-check``:Git 仓库由 ``pre`` 的 ``git_environment`` 门禁
320
326
  # 保证(见 ``_headless_argv`` 注释与模块 docstring 的 ``git`` 面)。
321
327
  command = ["codex", "exec", "--approve-for-me"]
328
+ model = getattr(ctx, "model", None)
329
+ if model:
330
+ command += ["-m", model]
322
331
  # --approve-for-me keeps workspace-write; grant only this clone's Git metadata so
323
332
  # its startup write probe and local commits work. worktree/submodule 的 ``.git``
324
333
  # 是 gitfile,需要同时授权 gitdir 与 commondir(见 ``_git_metadata_dirs``)。
@@ -99,8 +99,9 @@ def _headless_argv(ctx: RunContext) -> list[str]:
99
99
  command = [_resolve_kimi_executable() or "kimi", "-p", ctx.prompt]
100
100
  if ctx.session:
101
101
  command[1:1] = ["--session", ctx.session]
102
- if ctx.model:
103
- command += ["-m", ctx.model]
102
+ model = getattr(ctx, "model", None)
103
+ if model:
104
+ command += ["-m", model]
104
105
  return command
105
106
 
106
107
 
@@ -108,8 +109,9 @@ def _autonomous_argv(ctx: RunContext) -> list[str]:
108
109
  command = [_resolve_kimi_executable() or "kimi"]
109
110
  if ctx.session:
110
111
  command += ["--session", ctx.session]
111
- if ctx.model:
112
- command += ["-m", ctx.model]
112
+ model = getattr(ctx, "model", None)
113
+ if model:
114
+ command += ["-m", model]
113
115
  command += [
114
116
  "-p",
115
117
  ctx.prompt,
@@ -18,6 +18,7 @@ from contextlib import contextmanager
18
18
  import json
19
19
  import os
20
20
  from pathlib import Path
21
+ import shutil
21
22
  from typing import Iterator
22
23
 
23
24
  from core.infra.json_utils import unique_json_object
@@ -208,9 +209,16 @@ def _autonomous_environment(root: Path) -> Iterator[dict[str, str | None]]:
208
209
  for entry in source_dir.iterdir():
209
210
  if entry.name in {"opencode.json", "opencode.jsonc", "plugin", "plugins"}:
210
211
  continue
211
- (private_dir / entry.name).symlink_to(
212
- entry, target_is_directory=entry.is_dir(),
213
- )
212
+ dest = private_dir / entry.name
213
+ try:
214
+ dest.symlink_to(entry, target_is_directory=entry.is_dir())
215
+ except OSError:
216
+ if os.name != "nt":
217
+ raise
218
+ if entry.is_dir():
219
+ shutil.copytree(entry, dest, dirs_exist_ok=True)
220
+ else:
221
+ shutil.copy2(entry, dest)
214
222
  except OSError as exc:
215
223
  raise RuntimeError(
216
224
  f"OpenCode 自治配置资产无法隔离 ({type(exc).__name__})"
@@ -250,7 +258,7 @@ def _argv(ctx: RunContext, *, auto: bool) -> list[str]:
250
258
  # project instance can resolve shell work outside the requested root.
251
259
  cmd.append("--standalone")
252
260
  cmd += ["--agent", ctx.agent, "--format", "json"]
253
- model = _configured_model(ctx.root)
261
+ model = getattr(ctx, "model", None) or _configured_model(ctx.root)
254
262
  if model:
255
263
  cmd += ["--model", model]
256
264
  if auto:
@@ -119,6 +119,9 @@ def _headless_argv(ctx: RunContext) -> list[str]:
119
119
  command = ["zcode", "-p", ctx.prompt, "--mode", "yolo", "--cwd", str(ctx.root)]
120
120
  if ctx.session:
121
121
  command += ["--resume", ctx.session]
122
+ model = getattr(ctx, "model", None)
123
+ if model:
124
+ command += ["-m", model]
122
125
  return command
123
126
 
124
127
 
@@ -126,6 +129,9 @@ def _autonomous_argv(ctx: RunContext) -> list[str]:
126
129
  command = ["zcode", "-p", ctx.prompt, "--mode", "yolo", "--json", "--cwd", str(ctx.root)]
127
130
  if ctx.session:
128
131
  command += ["--resume", ctx.session]
132
+ model = getattr(ctx, "model", None)
133
+ if model:
134
+ command += ["-m", model]
129
135
  return command
130
136
 
131
137
 
@@ -1,6 +1,6 @@
1
1
  # BugX Core Infrastructure & Primitives (核心基础设施与底层操作系统原语子系统)
2
2
 
3
- > **版本契约**: `0.1.4` | **所属分层**: `Layer 0: 基础设施与操作系统抽象`
3
+ > **版本契约**: `0.1.6` | **所属分层**: `Layer 0: 基础设施与操作系统抽象`
4
4
  > **工程规范**: 参见 [`docs/02_architecture/05_ARCH_NOMENCLATURE_GUIDE.md`](../../docs/02_architecture/05_ARCH_NOMENCLATURE_GUIDE.md) 与 [`docs/02_architecture/06_MODULE_GOVERNANCE_SPEC.md`](../../docs/02_architecture/06_MODULE_GOVERNANCE_SPEC.md)
5
5
  > **守卫机制**: `scripts/verify_directory_indices.py` (100% 物理条目索引覆盖)
6
6
 
@@ -12,8 +12,8 @@ import re
12
12
  from pathlib import Path
13
13
 
14
14
  VERSION_ENV = "BUGX_VERSION"
15
- VERSION_TOKEN = "0.1.4"
16
- _DEFAULT_VERSION = "0.1.4"
15
+ VERSION_TOKEN = "0.1.6"
16
+ _DEFAULT_VERSION = "0.1.6"
17
17
  _VERSION_RE = re.compile(r"^\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?$")
18
18
 
19
19
 
@@ -47,6 +47,8 @@ def parse_python_version(executable_path):
47
47
  stdout=subprocess.PIPE,
48
48
  stderr=subprocess.PIPE,
49
49
  text=True,
50
+ encoding="utf-8",
51
+ errors="replace",
50
52
  timeout=2.0,
51
53
  check=False,
52
54
  )
@@ -131,7 +133,8 @@ def find_python_candidates(extra_paths=None):
131
133
  try:
132
134
  res = subprocess.run(
133
135
  [py_launcher, ver_flag, "-c", "import sys; print(sys.executable)"],
134
- stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, timeout=2.0, check=False,
136
+ stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True,
137
+ encoding="utf-8", errors="replace", timeout=2.0, check=False,
135
138
  )
136
139
  if res.returncode == 0 and res.stdout.strip():
137
140
  add_candidate(res.stdout.strip())
@@ -91,7 +91,7 @@ flowchart TD
91
91
  | `startup_gates.py` | 启动前置安全门禁(文件树白名单、脏工作区检查、权限拦截) | `verify_startup_gates` |
92
92
  | `startup_interaction.py` | 交互式问答决策引擎,根据终端能力与配置解析交互模式 | `resolve_startup_interaction` |
93
93
  | `verify_loop.py` | 独立验证员盲审输入包构造、Anti-Gaming 校验与报错驱动 PoC 自纠错闭环 | `build_verify_bundle`, `execute_verify_attempt`, `run_verification_loop` |
94
- | `startup_version_gate.py` | 版本硬门禁校验器,确保运行时版本严格等于 `0.1.4` 绝不漂移 | `assert_version_integrity` |
94
+ | `startup_version_gate.py` | 版本硬门禁校验器,确保运行时版本严格等于 `0.1.6` 绝不漂移 | `assert_version_integrity` |
95
95
  | `supervisor_bridge.py` | Supervisor 模块间解耦桥接层,提供轻量化调用门面 | `SupervisorBridge` |
96
96
  | `supervisor_coverage.py` | 覆盖率生命周期继承器,支持空闲历史会话继承与动态分发 | `SupervisorCoverageSync` |
97
97
  | `supervisor_degraded.py` | 降级容灾与探针就地自愈控制器,无损处理缺失依赖与环境 | `SupervisorDegradedCoordinator` |
@@ -103,7 +103,7 @@ flowchart TD
103
103
 
104
104
  ## 3. 核心设计契约与公理 (Design Axioms)
105
105
 
106
- 1. **版本绝对固化公理**:`startup_version_gate.py` 必须在任何业务逻辑启动前执行,基线版本严格锁定在 `0.1.4`,杜绝任何环境版本漂移。
106
+ 1. **版本绝对固化公理**:`startup_version_gate.py` 必须在任何业务逻辑启动前执行,基线版本严格锁定在 `0.1.6`,杜绝任何环境版本漂移。
107
107
  2. **状态机单向流转与幂等性**:生命周期从 `Pre` $\rightarrow$ `Round` $\rightarrow$ `Worker` $\rightarrow$ `Judge` $\rightarrow$ `Settlement` $\rightarrow$ `Post` 严格单向流动,禁止逆流操作;重试必须走显式的轮次迭代(`advance_round_lifecycle`)。
108
108
  3. **证据零伪造公理**:在 `findings_adjudication.py` 与 `candidate_revalidation.py` 中,所有缺陷判定必须有可执行的反事实测试证据,严禁仅凭模型推理文本定性。
109
109
  4. **工作树物理安全红线**:`post_dry_run.py` 与 `post_commit.py` 严格遵守工作树保护宪法,未授权时绝对禁止覆盖用户未暂存的修改。
@@ -153,7 +153,7 @@ def build_recipes_from_verdicts(verdicts_path: Path) -> Path:
153
153
  "fingerprint": fp, "oracle_file": oracle_rel,
154
154
  "positive": pos, "negative": neg,
155
155
  })
156
- out = Path(f"/tmp/recipes-{int(__import__('time').time())}.json")
156
+ out = Path(__import__("tempfile").gettempdir()) / f"recipes-{int(__import__('time').time())}.json"
157
157
  out.write_text(json.dumps(recipes, ensure_ascii=False, indent=1), encoding="utf-8")
158
158
  print(f"[findings-confirm] 自动生成 {len(recipes)} 条 recipe → {out}")
159
159
  return out