bugx-cli 0.1.4 → 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 (95) hide show
  1. package/core/README.md +1 -1
  2. package/core/agent/agent_execution.py +7 -0
  3. package/core/bugx.md +1 -1
  4. package/core/bugx_paths.py +2 -2
  5. package/core/bundled_docs/OVERVIEW.md +3 -2
  6. package/core/bundled_docs/README.md +2 -2
  7. package/core/bundled_docs/ai/01_AI_REFERENCE.md +11 -6
  8. package/core/bundled_docs/ai/02_AI_USAGE.md +1 -1
  9. package/core/bundled_docs/ai/03_AI_COMMANDS.md +1 -1
  10. package/core/bundled_docs/guides/01_USER_GUIDE.md +5 -5
  11. package/core/bundled_docs/guides/02_COMMANDS.md +3 -3
  12. package/core/bundled_docs/guides/03_TROUBLESHOOTING.md +4 -4
  13. package/core/bundled_docs/guides/05_HOST_MATRIX_AND_DISPATCH.md +4 -2
  14. package/core/bundled_docs/hosts/bugx_SKILL.md +2 -2
  15. package/core/bundled_docs/hosts/platform_bugx_SKILL.md +2 -2
  16. package/core/bundled_docs/manifest.json +20 -20
  17. package/core/bundled_docs/reference/01_ENVIRONMENT_VARIABLES.md +1 -0
  18. package/core/bundled_docs/reference/04_REPOSITORY_TOPOLOGY.md +1 -1
  19. package/core/contracts/README.md +1 -1
  20. package/core/contracts/bugx-runtime-contract.md +1 -1
  21. package/core/contracts/bugx-worker.md +1 -1
  22. package/core/coverage/coverage_ai_review.py +15 -11
  23. package/core/coverage/coverage_bootstrap.py +18 -13
  24. package/core/coverage/coverage_discovery.py +1 -1
  25. package/core/dev_harness/interaction_preset.py +1 -1
  26. package/core/engine-integrity.json +119 -111
  27. package/core/host_acp/README.md +4 -0
  28. package/core/host_acp/agnescode.py +128 -0
  29. package/core/host_runtime/README.md +3 -0
  30. package/core/host_runtime/host_registry.py +1 -0
  31. package/core/hosts/README.md +4 -0
  32. package/core/hosts/agnescode.py +415 -0
  33. package/core/hosts/opencode.py +11 -3
  34. package/core/infra/README.md +1 -1
  35. package/core/infra/build_info.py +2 -2
  36. package/core/infra/python_runtime.py +4 -1
  37. package/core/launch_phases/README.md +2 -2
  38. package/core/launch_phases/finding_confirm_phase.py +1 -1
  39. package/core/launch_phases/semantic_recon.py +3 -19
  40. package/core/launch_phases/startup_version_gate.py +2 -2
  41. package/core/launch_phases/verify_loop.py +3 -19
  42. package/core/ledger/README.md +1 -1
  43. package/core/ledger/finding_confirmation.py +1 -1
  44. package/core/ledger/finding_verification.py +2 -20
  45. package/core/ledger/fp_ledger.py +3 -19
  46. package/core/ledger/life_ledger.py +7 -33
  47. package/core/ledger/schema.py +1 -1
  48. package/core/mcp_handlers/supervisor_handlers.py +1 -1
  49. package/core/mcp_runtime_support/common.py +6 -0
  50. package/core/mcp_runtime_support/environment.py +82 -23
  51. package/core/metadata.txt +1 -1
  52. package/core/planning/README.md +1 -1
  53. package/core/planning/target_sandbox_manager.py +2 -0
  54. package/core/probes/mobile_probe.py +1 -0
  55. package/core/probes/sast_probe.py +1 -1
  56. package/core/probes/sca_scanner.py +1 -1
  57. package/core/project_profiler/constants.py +1 -1
  58. package/core/retrieval/README.md +1 -1
  59. package/core/retrieval/symbol_index.py +227 -52
  60. package/core/runtime/README.md +1 -1
  61. package/core/runtime/daemon_runner.py +3 -2
  62. package/core/runtime/project_init.py +1 -1
  63. package/core/runtime/scenario_eval.py +1 -1
  64. package/core/skills/bugx_mcp_server.py +9 -0
  65. package/core/skills/mcp_session_proof.py +3 -31
  66. package/core/supervisor/README.md +1 -1
  67. package/core/supervisor/finding_commit.py +3 -24
  68. package/core/supervisor/task_scheduler.py +5 -2
  69. package/core/supervisor/worker_handoff.py +2 -2
  70. package/ecosystem/integrations/dsh/mcp/package.json +1 -1
  71. package/ecosystem/integrations/dsh/ui/package.json +1 -1
  72. package/ecosystem/integrations/opencode/bugx-mcp-manifest.json +3 -3
  73. package/ecosystem/integrations/opencode/mcp-lock.json +1 -1
  74. package/ecosystem/integrations/pi/extensions/bugx/manifest.json +1 -1
  75. package/ecosystem/integrations/qoder/connector-meta.json +1 -1
  76. package/ecosystem/integrations/workbuddy/connector-meta.json +1 -1
  77. package/ecosystem/integrations/workbuddy/skills/bugx/SKILL.md +1 -1
  78. package/ecosystem/plugins/bugx/.claude-plugin/plugin.json +1 -1
  79. package/ecosystem/plugins/bugx/.codex-plugin/plugin.json +1 -1
  80. package/ecosystem/plugins/bugx/.zcode-plugin/plugin.json +1 -1
  81. package/ecosystem/plugins/bugx/skills/bugx/SKILL.md +2 -2
  82. package/interfaces/cli/bugx_cli/__init__.py +1 -1
  83. package/interfaces/cli/bugx_cli/cli.py +15 -0
  84. package/interfaces/cli/bugx_cli/commands/audit.py +2 -1
  85. package/interfaces/cli/bugx_cli/commands/lifecycle.py +1 -1
  86. package/interfaces/cli/bugx_cli/commands/patch.py +5 -1
  87. package/interfaces/cli/bugx_cli/commands/plugin.py +11 -2
  88. package/interfaces/cli/bugx_cli/commands/plugin_claude.py +2 -2
  89. package/interfaces/cli/bugx_cli/host_adapters.py +6 -0
  90. package/interfaces/cli/bugx_cli/hosts/registry.py +1 -1
  91. package/interfaces/cli/bugx_cli/infra/engine_installer.py +4 -4
  92. package/interfaces/cli/bugx_cli/infra/host_sync.py +1 -1
  93. package/package.json +1 -1
  94. package/scripts/sync-version.mjs +1 -1
  95. package/skills/platform/bugx/SKILL.md +2 -2
@@ -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
@@ -24,6 +24,8 @@ import time
24
24
  from pathlib import Path
25
25
  from typing import Any, Callable, Mapping, Sequence
26
26
 
27
+ import core.secure_atomic as secure_atomic
28
+
27
29
  OVERLAY_SCHEMA_VERSION = 1
28
30
  MAX_FIELD_CHARS = 200
29
31
  MAX_CONTEXT_FILES = 24
@@ -59,26 +61,8 @@ def _sha256_bytes(data: bytes) -> str:
59
61
 
60
62
 
61
63
  def _atomic_write_json(path: Path, payload: Mapping[str, Any]) -> None:
62
- path.parent.mkdir(parents=True, exist_ok=True, mode=0o700)
63
64
  raw = json.dumps(payload, ensure_ascii=False, indent=2, sort_keys=True).encode("utf-8")
64
- fd, tmp_name = tempfile.mkstemp(prefix=f".{path.name}.", dir=str(path.parent))
65
- try:
66
- os.fchmod(fd, 0o600)
67
- with os.fdopen(fd, "wb") as handle:
68
- handle.write(raw)
69
- handle.flush()
70
- os.fsync(handle.fileno())
71
- os.replace(tmp_name, path)
72
- except BaseException:
73
- try:
74
- os.close(fd)
75
- except OSError:
76
- pass
77
- try:
78
- os.unlink(tmp_name)
79
- except OSError:
80
- pass
81
- raise
65
+ secure_atomic.atomic_write_bytes(path, raw, mode=0o600, parent_mode=0o700)
82
66
 
83
67
 
84
68
  def _sanitize_text(value: object, *, max_len: int = MAX_FIELD_CHARS) -> tuple[str, bool]:
@@ -240,8 +240,8 @@ def version_marker(path: Path) -> str | None:
240
240
  if not match:
241
241
  return None
242
242
  value = match.group(1)
243
- if value == "0.1.4":
244
- value = os.environ.get("BUGX_VERSION", "0.1.4")
243
+ if value == "0.1.5":
244
+ value = os.environ.get("BUGX_VERSION", "0.1.5")
245
245
  return value
246
246
 
247
247
  def startup_release_version(value: object) -> tuple[int, int, int] | None:
@@ -28,6 +28,8 @@ import time
28
28
  from pathlib import Path
29
29
  from typing import Any, Callable, Mapping, Sequence
30
30
 
31
+ import core.secure_atomic as secure_atomic
32
+
31
33
  from core.ledger.finding_verification import (
32
34
  RETRYABLE_FAILURE_CODES,
33
35
  VerificationDiagnostic,
@@ -68,26 +70,8 @@ def _fp_slug(fingerprint: str) -> str:
68
70
 
69
71
 
70
72
  def _atomic_write_json(path: Path, payload: Mapping[str, Any]) -> None:
71
- path.parent.mkdir(parents=True, exist_ok=True, mode=0o700)
72
73
  data = json.dumps(payload, ensure_ascii=False, indent=2, sort_keys=True).encode("utf-8")
73
- fd, tmp_name = tempfile.mkstemp(prefix=f".{path.name}.", dir=str(path.parent))
74
- try:
75
- os.fchmod(fd, 0o600)
76
- with os.fdopen(fd, "wb") as handle:
77
- handle.write(data)
78
- handle.flush()
79
- os.fsync(handle.fileno())
80
- os.replace(tmp_name, path)
81
- except BaseException:
82
- try:
83
- os.close(fd)
84
- except OSError:
85
- pass
86
- try:
87
- os.unlink(tmp_name)
88
- except OSError:
89
- pass
90
- raise
74
+ secure_atomic.atomic_write_bytes(path, data, mode=0o600, parent_mode=0o700)
91
75
 
92
76
 
93
77
  def strip_runner_wrapper(code: str) -> str:
@@ -1,6 +1,6 @@
1
1
  # BugX Ledger (攻防复盘账本与错题经验库)
2
2
 
3
- > **版本契约**: `0.1.4` | **所属分层**: `Layer 3: 并发协调、智能体编排与账本`
3
+ > **版本契约**: `0.1.5` | **所属分层**: `Layer 3: 并发协调、智能体编排与账本`
4
4
  > **工程规范**: 参见 [`docs/02_architecture/05_ARCH_NOMENCLATURE_GUIDE.md`](../../docs/02_architecture/05_ARCH_NOMENCLATURE_GUIDE.md)
5
5
  > **守卫机制**: `scripts/verify_directory_indices.py` (100% 物理条目索引覆盖)
6
6
 
@@ -251,7 +251,7 @@ def reproduction_not_executable(value: object) -> bool:
251
251
  try:
252
252
  result = subprocess.run(
253
253
  ["bash", "-n", "-c", text], capture_output=True, text=True,
254
- timeout=5, check=False,
254
+ encoding="utf-8", errors="replace", timeout=5, check=False,
255
255
  )
256
256
  except (OSError, subprocess.SubprocessError):
257
257
  return False
@@ -22,6 +22,7 @@ from dataclasses import dataclass
22
22
  from pathlib import Path
23
23
  from typing import Any, Mapping, Sequence
24
24
 
25
+ import core.secure_atomic as secure_atomic
25
26
  from core.supervisor.worker_execution import run_bounded, WorkerExecutionError
26
27
 
27
28
 
@@ -255,26 +256,7 @@ def _result_record(result: Any, *, execution_id: str, case: str, argv: Sequence[
255
256
 
256
257
 
257
258
  def _atomic_json(path: Path, payload: Mapping[str, object]) -> None:
258
- path.parent.mkdir(parents=True, exist_ok=True, mode=0o700)
259
- raw = _canonical(payload)
260
- descriptor, temporary = tempfile.mkstemp(prefix=f".{path.name}.", dir=str(path.parent))
261
- try:
262
- os.fchmod(descriptor, 0o600)
263
- with os.fdopen(descriptor, "wb") as handle:
264
- handle.write(raw)
265
- handle.flush()
266
- os.fsync(handle.fileno())
267
- os.replace(temporary, path)
268
- except BaseException:
269
- try:
270
- os.close(descriptor)
271
- except OSError:
272
- pass
273
- try:
274
- os.unlink(temporary)
275
- except OSError:
276
- pass
277
- raise
259
+ secure_atomic.atomic_write_bytes(path, _canonical(payload), mode=0o600, parent_mode=0o700)
278
260
 
279
261
 
280
262
  def verify_finding(root: Path, finding: Mapping[str, object], recipe: Mapping[str, object] | VerificationRecipe,
@@ -20,6 +20,8 @@ import time
20
20
  from pathlib import Path
21
21
  from typing import Any, Mapping, Sequence
22
22
 
23
+ import core.secure_atomic as secure_atomic
24
+
23
25
  LEDGER_SCHEMA_VERSION = 1
24
26
  ALLOWED_FP_REJECTION_CLASSES = frozenset({
25
27
  "not_reproducible",
@@ -72,26 +74,8 @@ def ledger_path(root: Path) -> Path:
72
74
 
73
75
 
74
76
  def _atomic_write_json(path: Path, payload: Mapping[str, Any]) -> None:
75
- path.parent.mkdir(parents=True, exist_ok=True, mode=0o700)
76
77
  raw = json.dumps(payload, ensure_ascii=False, indent=2, sort_keys=True).encode("utf-8")
77
- fd, tmp_name = tempfile.mkstemp(prefix=f".{path.name}.", dir=str(path.parent))
78
- try:
79
- os.fchmod(fd, 0o600)
80
- with os.fdopen(fd, "wb") as handle:
81
- handle.write(raw)
82
- handle.flush()
83
- os.fsync(handle.fileno())
84
- os.replace(tmp_name, path)
85
- except BaseException:
86
- try:
87
- os.close(fd)
88
- except OSError:
89
- pass
90
- try:
91
- os.unlink(tmp_name)
92
- except OSError:
93
- pass
94
- raise
78
+ secure_atomic.atomic_write_bytes(path, raw, mode=0o600, parent_mode=0o700)
95
79
 
96
80
 
97
81
  def load_fp_ledger(root: Path) -> dict[str, Any]:
@@ -34,6 +34,8 @@ from contextlib import contextmanager
34
34
  from dataclasses import dataclass
35
35
  from pathlib import Path
36
36
 
37
+ import core.secure_atomic as secure_atomic
38
+
37
39
  try:
38
40
  import fcntl
39
41
  except ImportError: # pragma: no cover - Windows
@@ -259,39 +261,11 @@ def _fsync_directory(directory: Path) -> None:
259
261
 
260
262
  def atomic_write_json(path: str | os.PathLike[str], data: Mapping[str, Any]) -> None:
261
263
  """Atomically replace *path* with JSON, flushing file and directory metadata."""
262
- target = Path(path)
263
- directory = target.parent if target.parent != Path("") else Path(".")
264
- directory.mkdir(parents=True, exist_ok=True)
265
- temporary: Path | None = None
266
- descriptor, temporary_name = tempfile.mkstemp(
267
- prefix=f".{target.name}.", suffix=".tmp", dir=str(directory)
268
- )
269
- temporary = Path(temporary_name)
270
- try:
271
- os.fchmod(descriptor, 0o600)
272
- with os.fdopen(descriptor, "w", encoding="utf-8") as handle:
273
- descriptor = -1
274
- json.dump(
275
- data,
276
- handle,
277
- ensure_ascii=False,
278
- sort_keys=True,
279
- separators=(",", ":"),
280
- )
281
- handle.write("\n")
282
- handle.flush()
283
- os.fsync(handle.fileno())
284
- os.replace(temporary, target)
285
- temporary = None
286
- _fsync_directory(directory)
287
- finally:
288
- if descriptor != -1:
289
- os.close(descriptor)
290
- if temporary is not None:
291
- try:
292
- temporary.unlink()
293
- except FileNotFoundError:
294
- pass
264
+ payload = (
265
+ json.dumps(data, ensure_ascii=False, sort_keys=True, separators=(",", ":"))
266
+ + "\n"
267
+ ).encode("utf-8")
268
+ secure_atomic.atomic_write_bytes(path, payload, mode=0o600)
295
269
 
296
270
 
297
271
  def _lock_for(path: Path) -> threading.RLock:
@@ -384,7 +384,7 @@ def _journal_mode_lock(db: Path) -> Iterator[None]:
384
384
  thread_acquired = True
385
385
  if not stat.S_ISREG(os.fstat(descriptor).st_mode):
386
386
  raise LessonLedgerError("SQLite journal-mode 锁必须是普通文件")
387
- if os.name != "nt":
387
+ if hasattr(os, "fchmod"):
388
388
  os.fchmod(descriptor, 0o600)
389
389
  deadline = time.monotonic() + 10.0
390
390
  if _fcntl is not None:
@@ -1259,7 +1259,7 @@ def handle_supervisor_run_sandboxed_probe(service: Any, arguments: Mapping[str,
1259
1259
  except Exception:
1260
1260
  pass
1261
1261
  stdout, stderr = proc.communicate()
1262
- exit_code = -signal.SIGKILL
1262
+ exit_code = -getattr(signal, "SIGKILL", 9)
1263
1263
  stderr = (stderr or "") + f"\n[timeout]: Command timed out after {timeout}s and process group was terminated."
1264
1264
  except Exception as exc:
1265
1265
  exit_code = 1
@@ -317,6 +317,12 @@ def _check_venv_shebang(
317
317
  first_line = handle.readline(4096)
318
318
  except OSError as exc:
319
319
  return f"入口无法读取: {entry_rel}({exc})"
320
+ if (
321
+ first_line.startswith(b"MZ")
322
+ or entry_path.suffix.lower() in (".exe", ".com", ".cmd", ".bat")
323
+ ):
324
+ # Windows PE 可执行二进制文件或脚本(由 Windows 原生加载执行,无 Unix 文本 shebang)
325
+ return None
320
326
  if not first_line.startswith(b"#!"):
321
327
  return f"入口缺少 shebang(pypi console script 必须有): {entry_rel}"
322
328
  interpreter = first_line[2:].strip().decode("utf-8", "replace")
@@ -171,7 +171,7 @@ def _uv_managed_python(minor_spec: str) -> str:
171
171
 
172
172
 
173
173
  def _interpreter_candidates(spec: str) -> list[tuple[str, str, str]]:
174
- """列出本机**可用且满足约束**的解释器:``(路径, 版本, 来源)``,按版本降序。"""
174
+ """列出本机**可用且满足约束**的解释器:``(路径, 版本, 来源)``,按优先级排序。"""
175
175
  normalized = _normalize_python_spec(spec)
176
176
  found: dict[str, tuple[str, str, str]] = {}
177
177
 
@@ -187,10 +187,43 @@ def _interpreter_candidates(spec: str) -> list[tuple[str, str, str]]:
187
187
  if ok:
188
188
  found[resolved] = (resolved, version, source)
189
189
 
190
- for major, minor in _allowed_minors(spec):
191
- on_path = shutil.which(f"python{major}.{minor}")
190
+ # 1. 优先使用当前正在运行 BugX 的解释器 (sys.executable)
191
+ if sys.executable:
192
+ consider(sys.executable, "host")
193
+
194
+ # 2. 检索 PATH 中的通用 Python 命令
195
+ for name in ("python", "python3", "python.exe", "python3.exe"):
196
+ on_path = shutil.which(name)
192
197
  if on_path:
193
198
  consider(on_path, "host")
199
+
200
+ # 3. 检索具体小版本命令 (python3.12, python3.13 等)
201
+ for major, minor in _allowed_minors(spec):
202
+ for name in (f"python{major}.{minor}", f"python{major}.{minor}.exe"):
203
+ on_path = shutil.which(name)
204
+ if on_path:
205
+ consider(on_path, "host")
206
+
207
+ # 4. Windows 常见官方与系统安装目录
208
+ if os.name == "nt":
209
+ local_app = os.environ.get("LOCALAPPDATA")
210
+ if local_app:
211
+ programs_py = Path(local_app) / "Programs" / "Python"
212
+ if programs_py.is_dir():
213
+ for candidate in sorted(programs_py.glob("Python3*")):
214
+ exe = candidate / "python.exe"
215
+ if exe.is_file():
216
+ consider(str(exe), "host")
217
+ roaming_app = os.environ.get("APPDATA")
218
+ if roaming_app:
219
+ uv_py = Path(roaming_app) / "uv" / "python"
220
+ if uv_py.is_dir():
221
+ for candidate in sorted(uv_py.glob("cpython-3.*")):
222
+ exe = candidate / "python.exe"
223
+ if exe.is_file():
224
+ consider(str(exe), "uv-managed")
225
+
226
+ # 5. pyenv 与 uv 目录 (POSIX 及通用)
194
227
  pyenv_root = Path(os.environ.get("PYENV_ROOT") or (Path.home() / ".pyenv"))
195
228
  versions_dir = pyenv_root / "versions"
196
229
  if versions_dir.is_dir():
@@ -207,8 +240,11 @@ def _interpreter_candidates(spec: str) -> list[tuple[str, str, str]]:
207
240
  if executable.is_file():
208
241
  consider(str(executable), "uv-managed")
209
242
 
210
- def sort_key(item: tuple[str, str, str]) -> tuple[int, ...]:
211
- return tuple(int(part) for part in item[1].split(".") if part.isdigit())
243
+ def sort_key(item: tuple[str, str, str]) -> tuple[int, tuple[int, ...]]:
244
+ # 优先使用本机宿主已有解释器 (host),避免无端触发外部工具多装一份
245
+ source_prio = 2 if item[2] == "host" else (1 if item[2] == "pyenv" else 0)
246
+ ver_tuple = tuple(int(part) for part in item[1].split(".") if part.isdigit())
247
+ return (source_prio, ver_tuple)
212
248
 
213
249
  return sorted(found.values(), key=sort_key, reverse=True)
214
250
 
@@ -216,10 +252,10 @@ def _interpreter_candidates(spec: str) -> list[tuple[str, str, str]]:
216
252
  def _resolve_env_python(env_id: str, spec: str | None) -> tuple[str, str, str]:
217
253
  """解析 pypi 环境使用的解释器;返回 ``(可执行路径, 'X.Y.Z', 来源)``。
218
254
 
219
- ``spec`` 可以是 **约束**(``">=3.12,<3.14"``)或 ``"3.12"``(前缀匹配),
255
+ ``spec`` 可以是 **约束**(``">=3.12"``)或 ``"3.12"``(前缀匹配),
220
256
  ``None`` ⇒ 引擎自身解释器。**不写死小版本**:在本机满足约束的解释器里挑
221
- **最高**的一个(3.13 可用就用 3.13),一个都没有才用 uv 自愈安装
222
- **约束允许的最高版本**,全部失败才 fail-closed。
257
+ 满足要求的本机解释器(优先使用 host 已有环境),没有才用 uv 自愈安装
258
+ 约束允许的版本,全部失败才 fail-closed。
223
259
 
224
260
  来源 ∈ ``{"host", "pyenv", "uv-managed"}`` 并写入安装报告,便于审计
225
261
  "解释器是主机自带的,还是引擎自愈获取的"。
@@ -236,7 +272,8 @@ def _resolve_env_python(env_id: str, spec: str | None) -> tuple[str, str, str]:
236
272
  allowed = allowed_fn(spec)
237
273
  uv_fn = _get_mr_attr("_uv_managed_python", _uv_managed_python)
238
274
  pyver_fn = _get_mr_attr("_python_version_of", _python_version_of)
239
- for major, minor in reversed(allowed):
275
+ uv_minors = [m for m in reversed(allowed) if m[1] <= 14] or list(reversed(allowed))
276
+ for major, minor in uv_minors:
240
277
  healed = uv_fn(f"{major}.{minor}")
241
278
  if healed:
242
279
  return healed, pyver_fn(healed), "uv-managed"
@@ -401,7 +438,11 @@ def _install_pypi_environment(
401
438
  bin_dir = _venv_bin_dir(staging, env_id)
402
439
  if bin_dir.is_dir():
403
440
  for candidate in sorted(bin_dir.iterdir()):
404
- if candidate.is_file() and os.access(candidate, os.X_OK):
441
+ is_exec = candidate.is_file() and (
442
+ os.access(candidate, os.X_OK)
443
+ or (os.name == "nt" and candidate.suffix.lower() in (".exe", ".cmd", ".bat"))
444
+ )
445
+ if is_exec:
405
446
  executable_rels.add(candidate.relative_to(staging).as_posix())
406
447
  # 字节码闸门必须在**计算文件树/哈希之前**落地并预编译,
407
448
  # 否则首次运行写入的 .pyc 会让 tree_hash 漂移、verify 永久失败。
@@ -441,7 +482,11 @@ def _install_bytecode_guard(staging: Path, env_id: str) -> Path:
441
482
  "sys.dont_write_bytecode = True\n",
442
483
  encoding="utf-8",
443
484
  )
444
- interpreter = _venv_bin_dir(staging, env_id) / "python"
485
+ interpreter = _venv_bin_dir(staging, env_id) / ("python.exe" if os.name == "nt" else "python")
486
+ if not interpreter.is_file() and os.name == "nt":
487
+ alt = _venv_bin_dir(staging, env_id) / "python"
488
+ if alt.is_file():
489
+ interpreter = alt
445
490
  for arguments, label in (
446
491
  (["-m", "py_compile", str(guard)], "闸门预编译"),
447
492
  (["-m", "compileall", "-q", str(venv_dir)], "整棵 venv 预编译"),
@@ -465,18 +510,26 @@ def _install_bytecode_guard(staging: Path, env_id: str) -> Path:
465
510
 
466
511
  def _resolve_pypi_entry(staging: Path, env_id: str, entry_name: str) -> str:
467
512
  """把 lock 声明的 console script 名解析为 venv 内相对路径(fail-closed)。"""
468
- candidate = _venv_bin_dir(staging, env_id) / entry_name
469
- if candidate.is_symlink() or not candidate.is_file():
470
- raise McpRuntimeError(
471
- f"pypi server 的 console script 缺失或非普通文件: "
472
- f"{VENV_DIRNAME}/{env_id}/bin/{entry_name}"
473
- )
474
- if not os.access(candidate, os.X_OK):
475
- raise McpRuntimeError(
476
- f"pypi server 的 console script 不可执行: "
477
- f"{VENV_DIRNAME}/{env_id}/bin/{entry_name}"
478
- )
479
- return candidate.relative_to(staging).as_posix()
513
+ bin_dir = _venv_bin_dir(staging, env_id)
514
+ candidates = [bin_dir / entry_name]
515
+ if os.name == "nt" or sys.platform == "win32":
516
+ candidates.extend([
517
+ bin_dir / f"{entry_name}.exe",
518
+ bin_dir / f"{entry_name}.cmd",
519
+ bin_dir / f"{entry_name}.bat",
520
+ ])
521
+ for candidate in candidates:
522
+ if candidate.is_file() and not candidate.is_symlink():
523
+ if os.name != "nt" and not os.access(candidate, os.X_OK):
524
+ raise McpRuntimeError(
525
+ f"pypi server 的 console script 不可执行: "
526
+ f"{VENV_DIRNAME}/{env_id}/{bin_dir.name}/{candidate.name}"
527
+ )
528
+ return candidate.relative_to(staging).as_posix()
529
+ raise McpRuntimeError(
530
+ f"pypi server 的 console script 缺失或非普通文件: "
531
+ f"{VENV_DIRNAME}/{env_id}/{bin_dir.name}/{entry_name}"
532
+ )
480
533
 
481
534
 
482
535
  def _check_venv_shebang(
@@ -494,6 +547,12 @@ def _check_venv_shebang(
494
547
  first_line = handle.readline(4096)
495
548
  except OSError as exc:
496
549
  return f"入口无法读取: {entry_rel}({exc})"
550
+ if (
551
+ first_line.startswith(b"MZ")
552
+ or entry_path.suffix.lower() in (".exe", ".com", ".cmd", ".bat")
553
+ ):
554
+ # Windows PE 可执行二进制文件或脚本(由 Windows 原生加载执行,无 Unix 文本 shebang)
555
+ return None
497
556
  if not first_line.startswith(b"#!"):
498
557
  return f"入口缺少 shebang(pypi console script 必须有): {entry_rel}"
499
558
  interpreter = first_line[2:].strip().decode("utf-8", "replace")
package/core/metadata.txt CHANGED
@@ -1,4 +1,4 @@
1
- bugx_version: "0.1.4"
1
+ bugx_version: "0.1.5"
2
2
  bugx_channel: "stable"
3
3
  bugx_marker: "stable"
4
4
  build_id: 1
@@ -1,6 +1,6 @@
1
1
  # BugX Planning & Slicing Engine (能力规划、领域路由、代码切片与仲裁流水线)
2
2
 
3
- > **版本契约**: `0.1.4` | **所属分层**: `Layer 2: 分析、切片与探测引擎`
3
+ > **版本契约**: `0.1.5` | **所属分层**: `Layer 2: 分析、切片与探测引擎`
4
4
  > **工程规范**: 参见 [`docs/02_architecture/05_ARCH_NOMENCLATURE_GUIDE.md`](../../docs/02_architecture/05_ARCH_NOMENCLATURE_GUIDE.md)
5
5
  > **守卫机制**: `scripts/verify_directory_indices.py` (100% 物理条目索引覆盖)
6
6
 
@@ -37,6 +37,8 @@ DEFAULT_IGNORES = frozenset({
37
37
  ".mypy_cache",
38
38
  ".bugx",
39
39
  ".DS_Store",
40
+ "artifacts",
41
+ ".tools",
40
42
  })
41
43
 
42
44
 
@@ -155,6 +155,7 @@ _MOBILE_SCAN_MAX_DIRS = 128
155
155
  _MOBILE_SCAN_SKIP_DIRS = frozenset({
156
156
  ".git", ".bugx", ".gradle", ".idea", "__pycache__", "node_modules",
157
157
  "build", "dist", "target", "vendor", "Pods", "DerivedData",
158
+ "artifacts", ".tools",
158
159
  })
159
160
 
160
161
 
@@ -79,7 +79,7 @@ VERSION_FLAG = {"codeql": "version"}
79
79
  SKIP_DIRS = {
80
80
  ".git", ".bugx", ".venv", "venv", "node_modules", "__pycache__",
81
81
  "dist", "build", "target", ".tox", ".mypy_cache", ".pytest_cache",
82
- "vendor", "Pods", ".gradle", ".idea",
82
+ "vendor", "Pods", ".gradle", ".idea", "artifacts", ".tools",
83
83
  }
84
84
 
85
85
  #: 项目级忽略文件名(放在项目根,gitignore 语法)。
@@ -29,7 +29,7 @@ from typing import Any, Mapping
29
29
  SKIP_DIRS = {
30
30
  ".git", ".bugx", ".venv", "venv", "node_modules", "__pycache__",
31
31
  "dist", "build", "target", ".tox", ".mypy_cache", ".pytest_cache",
32
- "vendor", "Pods", ".gradle", ".idea", ".dart_tool",
32
+ "vendor", "Pods", ".gradle", ".idea", ".dart_tool", "artifacts", ".tools",
33
33
  }
34
34
 
35
35
  LOCK_FILES = {
@@ -48,7 +48,7 @@ SKIP_DIRS = {
48
48
  ".agents", ".cursor", ".gemini", "node_modules", ".venv",
49
49
  "venv", "env", "__pycache__", "dist", "build", ".idea", ".tox", ".mypy_cache",
50
50
  ".pytest_cache", "target", "vendor", "Pods", "DerivedData", ".next", ".nuxt",
51
- "evals",
51
+ "evals", "artifacts", ".tools",
52
52
  }
53
53
  _SKIP_DIRS = SKIP_DIRS
54
54
 
@@ -1,6 +1,6 @@
1
1
  # BugX Retrieval Engine (代码切片、拓扑与混合检索增强引擎)
2
2
 
3
- > **版本契约**: `0.1.4` | **所属分层**: `Layer 2: 分析、切片与探测引擎`
3
+ > **版本契约**: `0.1.5` | **所属分层**: `Layer 2: 分析、切片与探测引擎`
4
4
  > **工程规范**: 参见 [`docs/02_architecture/05_ARCH_NOMENCLATURE_GUIDE.md`](../../docs/02_architecture/05_ARCH_NOMENCLATURE_GUIDE.md)
5
5
  > **守卫机制**: `scripts/verify_directory_indices.py` (100% 物理条目索引覆盖)
6
6