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
@@ -22,10 +22,12 @@ from pathlib import Path
22
22
 
23
23
  import argparse
24
24
  import ast
25
+ import concurrent.futures
25
26
  import json
26
27
  import hashlib
27
28
  import os
28
29
  import re
30
+ import sqlite3
29
31
  from dataclasses import asdict, dataclass, field, replace
30
32
  from fnmatch import fnmatchcase
31
33
 
@@ -91,7 +93,7 @@ HOST_ROOT_CONFIG_NAMES = {
91
93
  }
92
94
  DEPENDENCY_OR_GENERATED_DIRS = {
93
95
  ".git", "node_modules", "target", "dist", ".venv", "venv", "__pycache__",
94
- ".gradle", "vendor", "third_party", ".pytest_cache", ".ruff_cache",
96
+ ".gradle", "vendor", "third_party", ".pytest_cache", ".ruff_cache", ".tools",
95
97
  }
96
98
  # Keep the old public name for callers that used it, but do not use it as a
97
99
  # blunt ``any path segment`` filter: product code may legitimately contain a
@@ -237,11 +239,14 @@ _PROJECT_EXCLUDE_TOP_DIRS_CACHE: dict[Path, frozenset[str]] = {}
237
239
 
238
240
 
239
241
  def _project_exclude_top_dirs(root: Path) -> frozenset[str]:
240
- """项目级覆盖排除,两路来源取并集(AI 复核为主,手工配置为辅):
242
+ """项目级覆盖排除(DOC-AIREV 双轨中的 Track 2 动态语义收敛 + 手工配置):
241
243
 
242
- 1. **AI 复核定案**(主通道):``.bugx/knowledge/coverage-review.json``
243
- 里宿主 AI 逐目录排查后的 ``exclude`` 裁决——裁决带理由/时间/裁决者,
244
- 换项目时由该机制重新排查,不携带任何项目名清单(DOC-AIREV)。
244
+ 在 Track 1(``HOST_RUNTIME_DIRS`` / ``DEPENDENCY_OR_GENERATED_DIRS`` 等静态白名单)
245
+ 自动排除公认基础设施与工具链之后,剩余目录由 AI 复核再过一遍,两路来源取并集:
246
+
247
+ 1. **AI 复核定案**(Track 2 主通道):``.bugx/knowledge/coverage-review.json``
248
+ 里宿主 AI 对白名单放行目录逐一排查后的 ``exclude`` 裁决——裁决带理由/时间/
249
+ 裁决者,换项目时动态重查,不携带任何项目名清单(DOC-AIREV)。
245
250
  2. **手工覆盖**(辅助):``.bugx/config.json`` 的
246
251
  ``coverage.exclude_top_dirs`` 顶层目录名列表,供人工紧急纠偏。
247
252
 
@@ -994,60 +999,230 @@ def index_repository(
994
999
  }
995
1000
 
996
1001
 
1002
+ def _build_file_audit_units(
1003
+ root: Path, path: Path, backend: str, strict: bool,
1004
+ *, cache: SourceContentCache | None = None,
1005
+ ) -> tuple[str, int, int, str, list[dict]]:
1006
+ """Parse one source file into its leaf-symbol or file-level audit units."""
1007
+ relative = path.relative_to(root).as_posix()
1008
+ st = path.stat()
1009
+ size = int(st.st_size)
1010
+ mtime_ns = int(st.st_mtime_ns)
1011
+ symbols, error, language = parse_file(path, backend, cache=cache)
1012
+ try:
1013
+ digest = file_sha256(path, cache)
1014
+ except OSError as exc:
1015
+ if strict:
1016
+ raise SourceDiscoveryError(f"源码读取失败 {path}: {exc}") from exc
1017
+ digest = ""
1018
+ # F-RSI-20261115-284 同型输出面:与 index_repository 的 digest_status
1019
+ # 对齐,避免读失败单元以空 content_hash 静默进入下游审计/覆盖清单。
1020
+ digest_status = "error"
1021
+ else:
1022
+ digest_status = "ok"
1023
+ leaves = _leaf_symbols(symbols)
1024
+ if leaves and all(symbol.kind == "module" for symbol in leaves):
1025
+ # A file containing only constants/configuration remains a useful
1026
+ # file-level task; do not manufacture a synthetic callable task.
1027
+ leaves = []
1028
+ if leaves:
1029
+ units = [{
1030
+ "scope": f"{relative}::{symbol.scope_name}",
1031
+ "path": relative,
1032
+ "name": symbol.name,
1033
+ "kind": symbol.kind,
1034
+ "line": symbol.start_line,
1035
+ "parser": symbol.parser,
1036
+ "error": error,
1037
+ "end_line": symbol.end_line,
1038
+ "content_hash": digest,
1039
+ "digest_status": digest_status,
1040
+ "language": language,
1041
+ } for symbol in leaves]
1042
+ else:
1043
+ units = [{
1044
+ "scope": relative,
1045
+ "path": relative,
1046
+ "name": path.stem,
1047
+ "kind": "file",
1048
+ "line": 1,
1049
+ "parser": "fallback-file",
1050
+ "error": error,
1051
+ "language": language,
1052
+ "content_hash": digest,
1053
+ "digest_status": digest_status,
1054
+ }]
1055
+ return relative, size, mtime_ns, digest, units
1056
+
1057
+
1058
+ def _parse_audit_unit_worker(args: tuple[str, str, str, bool]) -> tuple[str, int, int, str, list[dict]]:
1059
+ """Top-level picklable worker for parallel ProcessPoolExecutor indexing."""
1060
+ root_str, path_str, backend, strict = args
1061
+ return _build_file_audit_units(Path(root_str), Path(path_str), backend, strict)
1062
+
1063
+
1064
+ class _PersistentSymbolCache:
1065
+ """Content-addressed SQLite cache for audit_units under ``.bugx/cache/``."""
1066
+
1067
+ def __init__(self, root: Path) -> None:
1068
+ self._conn: sqlite3.Connection | None = None
1069
+ bugx_dir = root / ".bugx"
1070
+ if not bugx_dir.is_dir() or bugx_dir.is_symlink():
1071
+ return
1072
+ cache_dir = bugx_dir / "cache"
1073
+ try:
1074
+ cache_dir.mkdir(parents=True, exist_ok=True)
1075
+ db_path = cache_dir / "symbol_cache.db"
1076
+ conn = sqlite3.connect(str(db_path), timeout=5.0)
1077
+ conn.execute(
1078
+ "CREATE TABLE IF NOT EXISTS unit_cache ("
1079
+ "rel_path TEXT NOT NULL, backend TEXT NOT NULL, "
1080
+ "size INTEGER NOT NULL, mtime_ns INTEGER NOT NULL, "
1081
+ "sha256 TEXT NOT NULL, units_json TEXT NOT NULL, "
1082
+ "PRIMARY KEY (rel_path, backend))"
1083
+ )
1084
+ self._conn = conn
1085
+ except (OSError, sqlite3.Error):
1086
+ self._conn = None
1087
+
1088
+ def get_by_stat(self, rel_path: str, backend: str, size: int, mtime_ns: int) -> list[dict] | None:
1089
+ if self._conn is None:
1090
+ return None
1091
+ try:
1092
+ row = self._conn.execute(
1093
+ "SELECT units_json FROM unit_cache "
1094
+ "WHERE rel_path = ? AND backend = ? AND size = ? AND mtime_ns = ?",
1095
+ (rel_path, backend, size, mtime_ns),
1096
+ ).fetchone()
1097
+ if row is not None:
1098
+ data = json.loads(row[0])
1099
+ if isinstance(data, list):
1100
+ return data
1101
+ except (sqlite3.Error, ValueError, TypeError):
1102
+ pass
1103
+ return None
1104
+
1105
+ def put_many(self, rows: list[tuple[str, str, int, int, str, list[dict]]]) -> None:
1106
+ if self._conn is None or not rows:
1107
+ return
1108
+ try:
1109
+ with self._conn:
1110
+ self._conn.executemany(
1111
+ "INSERT OR REPLACE INTO unit_cache "
1112
+ "(rel_path, backend, size, mtime_ns, sha256, units_json) "
1113
+ "VALUES (?, ?, ?, ?, ?, ?)",
1114
+ [
1115
+ (rel, backend, size, mtime_ns, digest, json.dumps(units, ensure_ascii=False))
1116
+ for rel, backend, size, mtime_ns, digest, units in rows
1117
+ ],
1118
+ )
1119
+ except (sqlite3.Error, TypeError, ValueError):
1120
+ pass
1121
+
1122
+ def close(self) -> None:
1123
+ if self._conn is not None:
1124
+ try:
1125
+ self._conn.close()
1126
+ except sqlite3.Error:
1127
+ pass
1128
+ self._conn = None
1129
+
1130
+
997
1131
  def audit_units(
998
1132
  root: Path, backend: str = "auto", strict: bool = False,
999
1133
  *, cache: SourceContentCache | None = None,
1134
+ parallel: bool = True,
1135
+ use_persistent_cache: bool = True,
1000
1136
  ) -> list[dict]:
1001
- """返回最细审计单元;有符号时取叶子符号,否则退回文件。"""
1137
+ """返回最细审计单元;有符号时取叶子符号,否则退回文件。
1138
+
1139
+ 支持:
1140
+ 1. 基于 ``.bugx/cache/symbol_cache.db`` 的文件级内容/stat 持久化缓存;
1141
+ 2. 超过 32 个未命中文件时自动启用多进程并发 AST 解析;
1142
+ 3. 大规模扫描时定期向 stderr 输出心跳进度,避免宿主误判挂死。
1143
+ """
1002
1144
  root = root.resolve()
1003
1145
  cache = cache if cache is not None else SourceContentCache()
1004
- result: list[dict] = []
1005
- for path in discover_source_paths(root, strict=strict):
1006
- relative = path.relative_to(root).as_posix()
1007
- symbols, error, language = parse_file(path, backend, cache=cache)
1008
- try:
1009
- digest = file_sha256(path, cache)
1010
- except OSError as exc:
1011
- if strict:
1012
- raise SourceDiscoveryError(f"源码读取失败 {path}: {exc}") from exc
1013
- digest = ""
1014
- # F-RSI-20261115-284 同型输出面:与 index_repository 的 digest_status
1015
- # 对齐,避免读失败单元以空 content_hash 静默进入下游审计/覆盖清单。
1016
- digest_status = "error"
1017
- else:
1018
- digest_status = "ok"
1019
- leaves = _leaf_symbols(symbols)
1020
- if leaves and all(symbol.kind == "module" for symbol in leaves):
1021
- # A file containing only constants/configuration remains a useful
1022
- # file-level task; do not manufacture a synthetic callable task.
1023
- leaves = []
1024
- if leaves:
1025
- result.extend({
1026
- "scope": f"{relative}::{symbol.scope_name}",
1027
- "path": relative,
1028
- "name": symbol.name,
1029
- "kind": symbol.kind,
1030
- "line": symbol.start_line,
1031
- "parser": symbol.parser,
1032
- "error": error,
1033
- "end_line": symbol.end_line,
1034
- "content_hash": digest,
1035
- "digest_status": digest_status,
1036
- "language": language,
1037
- } for symbol in leaves)
1146
+ source_paths = discover_source_paths(root, strict=strict)
1147
+ persistent = _PersistentSymbolCache(root) if use_persistent_cache else None
1148
+
1149
+ units_by_rel: dict[str, list[dict]] = {}
1150
+ uncached: list[Path] = []
1151
+ ordered_rels: list[str] = []
1152
+
1153
+ try:
1154
+ for path in source_paths:
1155
+ relative = path.relative_to(root).as_posix()
1156
+ ordered_rels.append(relative)
1157
+ if persistent is not None:
1158
+ try:
1159
+ st = path.stat()
1160
+ cached_units = persistent.get_by_stat(
1161
+ relative, backend, int(st.st_size), int(st.st_mtime_ns),
1162
+ )
1163
+ if cached_units is not None:
1164
+ units_by_rel[relative] = cached_units
1165
+ continue
1166
+ except OSError:
1167
+ pass
1168
+ uncached.append(path)
1169
+
1170
+ total_uncached = len(uncached)
1171
+ new_cache_rows: list[tuple[str, str, int, int, str, list[dict]]] = []
1172
+
1173
+ main_file = getattr(sys.modules.get("__main__"), "__file__", None)
1174
+ can_spawn = bool(main_file and os.path.isfile(main_file))
1175
+ if parallel and can_spawn and total_uncached >= 32 and (os.cpu_count() or 1) > 1:
1176
+ workers = min(os.cpu_count() or 4, 8)
1177
+ tasks = [(str(root), str(p), backend, strict) for p in uncached]
1178
+ try:
1179
+ with concurrent.futures.ProcessPoolExecutor(max_workers=workers) as pool:
1180
+ for idx, (rel, size, mtime_ns, digest, file_units) in enumerate(
1181
+ pool.map(_parse_audit_unit_worker, tasks, chunksize=16), 1,
1182
+ ):
1183
+ units_by_rel[rel] = file_units
1184
+ if digest:
1185
+ new_cache_rows.append((rel, backend, size, mtime_ns, digest, file_units))
1186
+ if total_uncached >= 200 and idx % 200 == 0:
1187
+ print(
1188
+ f"[symbol_index] 并发解析进度: {idx}/{total_uncached}",
1189
+ file=sys.stderr, flush=True,
1190
+ )
1191
+ except (OSError, PermissionError, RuntimeError, ValueError):
1192
+ # 受限沙箱或子进程启动失败时安全退回单进程路径
1193
+ units_by_rel = {k: v for k, v in units_by_rel.items()}
1194
+ new_cache_rows.clear()
1195
+ for p in uncached:
1196
+ if p.relative_to(root).as_posix() not in units_by_rel:
1197
+ rel, size, mtime_ns, digest, file_units = _build_file_audit_units(
1198
+ root, p, backend, strict, cache=cache,
1199
+ )
1200
+ units_by_rel[rel] = file_units
1201
+ if digest:
1202
+ new_cache_rows.append((rel, backend, size, mtime_ns, digest, file_units))
1038
1203
  else:
1039
- result.append({
1040
- "scope": relative,
1041
- "path": relative,
1042
- "name": path.stem,
1043
- "kind": "file",
1044
- "line": 1,
1045
- "parser": "fallback-file",
1046
- "error": error,
1047
- "language": language,
1048
- "content_hash": digest,
1049
- "digest_status": digest_status,
1050
- })
1204
+ for idx, p in enumerate(uncached, 1):
1205
+ rel, size, mtime_ns, digest, file_units = _build_file_audit_units(
1206
+ root, p, backend, strict, cache=cache,
1207
+ )
1208
+ units_by_rel[rel] = file_units
1209
+ if digest:
1210
+ new_cache_rows.append((rel, backend, size, mtime_ns, digest, file_units))
1211
+ if total_uncached >= 200 and idx % 200 == 0:
1212
+ print(
1213
+ f"[symbol_index] 解析进度: {idx}/{total_uncached}",
1214
+ file=sys.stderr, flush=True,
1215
+ )
1216
+
1217
+ if persistent is not None and new_cache_rows:
1218
+ persistent.put_many(new_cache_rows)
1219
+ finally:
1220
+ if persistent is not None:
1221
+ persistent.close()
1222
+
1223
+ result: list[dict] = []
1224
+ for rel in ordered_rels:
1225
+ result.extend(units_by_rel.get(rel, ()))
1051
1226
  return result
1052
1227
 
1053
1228
 
@@ -1,6 +1,6 @@
1
1
  # BugX Core Runtime Subsystem (核心运行时、环境与基础设施)
2
2
 
3
- > **版本契约**: `0.1.4` | **所属分层**: `Layer 0: 基础设施与操作系统抽象`
3
+ > **版本契约**: `0.1.5` | **所属分层**: `Layer 0: 基础设施与操作系统抽象`
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
 
@@ -175,9 +175,10 @@ class DaemonRunner:
175
175
  self._remove_pid()
176
176
  return 0
177
177
 
178
+ sigkill = getattr(signal, "SIGKILL", signal.SIGTERM)
178
179
  print(f"[BugX Daemon] 正在终止守护进程 (PID: {pid})...")
179
180
  try:
180
- sig = signal.SIGKILL if force else signal.SIGTERM
181
+ sig = sigkill if force else signal.SIGTERM
181
182
  os.kill(pid, sig)
182
183
  except OSError as exc:
183
184
  print(f"[BugX Daemon] 发送信号失败: {exc}")
@@ -190,7 +191,7 @@ class DaemonRunner:
190
191
 
191
192
  if _is_pid_alive(pid) and force:
192
193
  try:
193
- os.kill(pid, signal.SIGKILL)
194
+ os.kill(pid, sigkill)
194
195
  except OSError:
195
196
  pass
196
197
 
@@ -468,7 +468,7 @@ def run_init_pipeline(root: Path, engine_root: Path) -> dict[str, Any]:
468
468
  if not coverage.get("ready"):
469
469
  if coverage.get("blocked"):
470
470
  raise RuntimeError(str(coverage.get("detail") or "覆盖清单被阻断"))
471
- coverage_bootstrap.bootstrap(root, confirmed=True)
471
+ coverage_bootstrap.bootstrap(root, confirmed=True, symbols=False)
472
472
  _write_ready_config(root, config, current, optional_mcp_report)
473
473
  ticket = resume_ticket.create_resume_ticket(root) if initialized else None
474
474
  (root / ".bugx" / ".init_progress.json").unlink(missing_ok=True)
@@ -141,7 +141,7 @@ def _run(argv: list[str], *, cwd: Path, timeout: float = 120.0,
141
141
  # L3 等场景验证当前 checkout;不让已安装的旧引擎成为量具。
142
142
  merged["BUGX_DEV_MODE"] = "1"
143
143
  # 源码树里的版本声明是构建模板;开发态启动门禁需要同一解析值。
144
- merged["BUGX_VERSION"] = os.environ.get("BUGX_VERSION", "0.1.4")
144
+ merged["BUGX_VERSION"] = os.environ.get("BUGX_VERSION", "0.1.5")
145
145
  merged["HOME"] = str(_sandbox_home())
146
146
  try:
147
147
  proc = subprocess.run(
@@ -41,6 +41,15 @@ from typing import Any, Callable, Mapping, Sequence
41
41
  from core.infra.build_info import BASE_VERSION
42
42
  from urllib.parse import parse_qs, urlparse
43
43
 
44
+ os.environ.setdefault("PYTHONUTF8", "1")
45
+ for _stream, _err_mode in ((sys.stdin, "strict"), (sys.stdout, "replace"), (sys.stderr, "replace")):
46
+ _reconf = getattr(_stream, "reconfigure", None)
47
+ if callable(_reconf):
48
+ try:
49
+ _reconf(encoding="utf-8", errors=_err_mode)
50
+ except (OSError, ValueError):
51
+ pass
52
+
44
53
  try:
45
54
  import fcntl
46
55
  except ImportError: # pragma: no cover - Windows hosts use msvcrt or fallback.
@@ -26,6 +26,8 @@ from contextlib import contextmanager
26
26
  from pathlib import Path
27
27
  from typing import Any, Mapping
28
28
 
29
+ import core.secure_atomic as secure_atomic
30
+
29
31
 
30
32
  SCHEMA_VERSION = 2
31
33
  MAX_PROOF_BYTES = 64 * 1024
@@ -286,37 +288,7 @@ def retire_request_path(state_root: Path, instance: str) -> Path:
286
288
  def _atomic_bytes(path: Path, payload: bytes, *, mode: int = 0o600) -> None:
287
289
  if len(payload) > MAX_PROOF_BYTES:
288
290
  raise SessionProofError(f"proof 超过 {MAX_PROOF_BYTES} bytes")
289
- path.parent.mkdir(parents=True, exist_ok=True, mode=0o700)
290
- try:
291
- os.chmod(path.parent, 0o700)
292
- except OSError:
293
- pass
294
- fd, temporary = tempfile.mkstemp(prefix=f".{path.name}.", dir=str(path.parent))
295
- try:
296
- os.fchmod(fd, mode)
297
- with os.fdopen(fd, "wb") as handle:
298
- handle.write(payload)
299
- handle.flush()
300
- os.fsync(handle.fileno())
301
- os.replace(temporary, path)
302
- try:
303
- descriptor = os.open(path.parent, os.O_RDONLY)
304
- try:
305
- os.fsync(descriptor)
306
- finally:
307
- os.close(descriptor)
308
- except OSError:
309
- pass
310
- except BaseException:
311
- try:
312
- os.close(fd)
313
- except OSError:
314
- pass
315
- try:
316
- os.unlink(temporary)
317
- except OSError:
318
- pass
319
- raise
291
+ secure_atomic.atomic_write_bytes(path, payload, mode=mode, parent_mode=0o700)
320
292
 
321
293
 
322
294
  def _canonical(payload: Mapping[str, object]) -> bytes:
@@ -1,6 +1,6 @@
1
1
  # BugX Supervisor (并发协调与智能体调度仲裁中心)
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
 
@@ -20,6 +20,8 @@ from contextlib import contextmanager
20
20
  from pathlib import Path
21
21
  from typing import Callable, Mapping
22
22
 
23
+ import core.secure_atomic as secure_atomic
24
+
23
25
  try:
24
26
  import fcntl
25
27
  except ImportError: # pragma: no cover
@@ -73,30 +75,7 @@ def _fsync_dir(path: Path) -> None:
73
75
 
74
76
 
75
77
  def _atomic_bytes(path: Path, data: bytes, *, mode: int = 0o600) -> None:
76
- path.parent.mkdir(parents=True, exist_ok=True, mode=0o700)
77
- try:
78
- os.chmod(path.parent, 0o700)
79
- except OSError:
80
- pass
81
- descriptor, temporary = tempfile.mkstemp(prefix=f".{path.name}.", dir=str(path.parent))
82
- try:
83
- os.fchmod(descriptor, mode)
84
- with os.fdopen(descriptor, "wb") as handle:
85
- handle.write(data)
86
- handle.flush()
87
- os.fsync(handle.fileno())
88
- os.replace(temporary, path)
89
- _fsync_dir(path.parent)
90
- except BaseException:
91
- try:
92
- os.close(descriptor)
93
- except OSError:
94
- pass
95
- try:
96
- os.unlink(temporary)
97
- except OSError:
98
- pass
99
- raise
78
+ secure_atomic.atomic_write_bytes(path, data, mode=mode, parent_mode=0o700)
100
79
 
101
80
 
102
81
  def _safe_participant(root: Path, path: Path) -> Path:
@@ -1334,6 +1334,8 @@ class ZombieDetector:
1334
1334
  才允许 ``os.killpg``,否则退化为对单个 PID 发信号,避免一次终止波及
1335
1335
  整组无关进程。
1336
1336
  """
1337
+ if not hasattr(os, "getpgid") or not hasattr(os, "getsid"):
1338
+ return False
1337
1339
  try:
1338
1340
  return os.getpgid(pid) == pid and os.getsid(pid) == pid
1339
1341
  except OSError:
@@ -1450,10 +1452,11 @@ class ZombieDetector:
1450
1452
  while ZombieDetector.is_pid_alive(pid) and time.monotonic() < deadline:
1451
1453
  time.sleep(0.02)
1452
1454
  if ZombieDetector.is_pid_alive(pid):
1455
+ sigkill = getattr(signal, "SIGKILL", signal.SIGTERM)
1453
1456
  try:
1454
- signal_target(signal.SIGKILL)
1457
+ signal_target(sigkill)
1455
1458
  except OSError:
1456
- os.kill(pid, signal.SIGKILL)
1459
+ os.kill(pid, sigkill)
1457
1460
  terminated = not ZombieDetector.is_pid_alive(pid)
1458
1461
  return terminated, ("" if terminated else "signal_failed")
1459
1462
  except (OSError, subprocess.SubprocessError):
@@ -168,7 +168,7 @@ def main(argv: list[str] | None = None) -> int:
168
168
  from core.runtime.prep_validate import REQUIRED
169
169
  print(json.dumps({"required_headings": list(REQUIRED)}, ensure_ascii=False, indent=2))
170
170
  return 0
171
- packet = json.loads(args.input.read_text() if args.input else sys.stdin.read())
171
+ packet = json.loads(args.input.read_text(encoding="utf-8") if args.input else sys.stdin.read())
172
172
  if args.operation == "decode":
173
173
  result = decode(packet)
174
174
  elif args.operation == "summary":
@@ -176,7 +176,7 @@ def main(argv: list[str] | None = None) -> int:
176
176
  elif args.operation == "handoff":
177
177
  if not args.task or not args.context:
178
178
  raise ValueError("handoff needs --task and --context")
179
- result = handoff(args.task.read_text(), decode(packet), json.loads(args.context.read_text()))
179
+ result = handoff(args.task.read_text(encoding="utf-8"), decode(packet), json.loads(args.context.read_text(encoding="utf-8")))
180
180
  elif args.operation == "checkpoint":
181
181
  result = checkpoint(packet, args.unit or "", args.note, covered=args.covered)
182
182
  else:
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bencibro/bugx-dsh-mcp-client",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "Session-aware BugX MCP bridge for DeepSeek Harness.",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bencibro/bugx-dsh-ui",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "BugX branding and Sidebar icon for DeepSeek Harness.",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "schema_version": 1,
3
3
  "name": "bugx-built-in-mcp",
4
- "version": "0.1.4",
4
+ "version": "0.1.5",
5
5
  "servers": {
6
6
  "bugx-supervisor": {
7
7
  "type": "builtin",
@@ -15,7 +15,7 @@
15
15
  "host"
16
16
  ],
17
17
  "source": "core/skills/bugx_mcp_server.py",
18
- "sha256": "25d0e926745b5d2ea80533e9455e2720c2c876bca287e6db1376e9c38d8020ef",
18
+ "sha256": "5a6114314b55840a04760300aa748cbdad9d771096e60ced2b24c45376373ec9",
19
19
  "health": "initialize"
20
20
  },
21
21
  "bugx-supervisor-worker": {
@@ -30,7 +30,7 @@
30
30
  "worker"
31
31
  ],
32
32
  "source": "core/skills/bugx_mcp_server.py",
33
- "sha256": "25d0e926745b5d2ea80533e9455e2720c2c876bca287e6db1376e9c38d8020ef",
33
+ "sha256": "5a6114314b55840a04760300aa748cbdad9d771096e60ced2b24c45376373ec9",
34
34
  "health": "initialize"
35
35
  },
36
36
  "bugx-docs": {
@@ -1821,7 +1821,7 @@
1821
1821
  }
1822
1822
  },
1823
1823
  "semgrep": {
1824
- "python": ">=3.12,<3.14",
1824
+ "python": ">=3.12",
1825
1825
  "packages": {
1826
1826
  "annotated-types": {
1827
1827
  "version": "0.8.0",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "schema_version": 1,
3
3
  "name": "bugx-pi",
4
- "version": "0.1.4",
4
+ "version": "0.1.5",
5
5
  "host": "pi",
6
6
  "kind": "extension",
7
7
  "entry": "index.ts",
@@ -7,7 +7,7 @@
7
7
  "description_en": "BugX is an autonomous code review and testing agent designed to safeguard software delivery: it surfaces hidden, deep bugs for developers right after writing code to eliminate painful debugging and rework; automates black-box, functional, and performance testing across complex edge cases for QA; and ensures software strictly meets functional requirements with rock-solid stability and resilience. By taking over tedious verification, BugX frees engineers from manual grunt work, boosts team velocity, elevates code quality, and significantly lowers long-term maintenance costs—putting technology to work for people.",
8
8
  "source": "bugx-agent",
9
9
  "type": "mcp-connector",
10
- "version": "0.1.4",
10
+ "version": "0.1.5",
11
11
  "homepage": "https://bugx.dev",
12
12
  "website": "https://bugx.dev",
13
13
  "examples_zh": [
@@ -7,7 +7,7 @@
7
7
  "description_en": "Autonomous code review and testing agent. Catches hidden deep bugs for developers, automates black-box, functional, and performance testing for QA, and ensures rock-solid software delivery.",
8
8
  "source": "bugx-agent",
9
9
  "type": "skill-only",
10
- "version": "0.1.4",
10
+ "version": "0.1.5",
11
11
  "examples_zh": [
12
12
  "运行代码审查,排查深层 Bug 与性能隐患",
13
13
  "自动化运行功能验证与黑盒测试"
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: bugx
3
3
  description: BugX 是一个具备自主代码审查与测试能力的智能体,严把代码交付关:它帮助开发人员在写完代码后自动排查隐藏的深层 Bug,减少反复排错与返工;帮助测试人员自动化运行黑盒测试、功能验证与性能测试,自动覆盖手工盲测难以覆盖的极端场景;确保代码功能符合要求、具备良好的健壮性和稳定性。让开发和测试在繁琐的工作中解放双手,大幅提高工作效率、全面提升代码质量、显著降低后期维护成本,实现科技服务于人。
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  author: BugX
6
6
  ---
7
7
  <!-- bugx-locale: zh-CN -->
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bugx",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "bugx_build_id": 98,
5
5
  "description": "Autonomous code review and testing agent. Catches hidden deep bugs for developers, automates black-box, functional, and performance testing for QA, and ensures rock-solid software delivery.",
6
6
  "author": {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bugx",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "Autonomous code review and testing agent. Catches hidden deep bugs for developers, automates black-box, functional, and performance testing for QA, and ensures rock-solid software delivery.",
5
5
  "skills": "./skills/",
6
6
  "homepage": "https://bugx.dev",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bugx",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "Autonomous code review and testing agent. Catches hidden deep bugs for developers, automates black-box, functional, and performance testing for QA, and ensures rock-solid software delivery.",
5
5
  "homepage": "https://bugx.dev",
6
6
  "author": {