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.
- package/README.md +89 -210
- package/core/README.md +1 -1
- package/core/agent/agent_execution.py +7 -0
- package/core/agent/agent_targets.py +5 -1
- package/core/agent/agent_workspace.py +10 -2
- package/core/autonomous_cve/run_fault_matrix.py +692 -0
- package/core/autonomous_cve/run_oss_cve_exploit_verify.py +608 -0
- package/core/autonomous_cve/run_six_worker_penetration.py +382 -0
- package/core/autonomous_cve/verifier.py +5 -7
- package/core/bugx.md +1 -1
- package/core/bugx_paths.py +2 -2
- package/core/bundled_docs/OVERVIEW.md +70 -236
- package/core/bundled_docs/README.md +2 -2
- package/core/bundled_docs/README_EN.md +67 -211
- package/core/bundled_docs/ai/01_AI_REFERENCE.md +11 -6
- package/core/bundled_docs/ai/02_AI_USAGE.md +1 -1
- package/core/bundled_docs/ai/03_AI_COMMANDS.md +1 -1
- package/core/bundled_docs/guides/01_USER_GUIDE.md +5 -5
- package/core/bundled_docs/guides/02_COMMANDS.md +3 -3
- package/core/bundled_docs/guides/03_TROUBLESHOOTING.md +4 -4
- package/core/bundled_docs/guides/05_HOST_MATRIX_AND_DISPATCH.md +4 -2
- package/core/bundled_docs/hosts/bugx_SKILL.md +2 -2
- package/core/bundled_docs/hosts/platform_bugx_SKILL.md +2 -2
- package/core/bundled_docs/manifest.json +22 -22
- package/core/bundled_docs/reference/01_ENVIRONMENT_VARIABLES.md +1 -0
- package/core/bundled_docs/reference/04_REPOSITORY_TOPOLOGY.md +1 -1
- package/core/cloud_sync/flywheel_client.py +89 -0
- package/core/contracts/README.md +1 -1
- package/core/contracts/bugx-runtime-contract.md +1 -1
- package/core/contracts/bugx-worker.md +1 -1
- package/core/coverage/coverage_ai_review.py +15 -11
- package/core/coverage/coverage_bootstrap.py +18 -13
- package/core/coverage/coverage_discovery.py +1 -1
- package/core/coverage/coverage_gate.py +12 -2
- package/core/coverage/coverage_manifest.py +1 -1
- package/core/coverage/coverage_validate.py +5 -3
- package/core/dev_harness/interaction_preset.py +1 -1
- package/core/engine-integrity.json +183 -163
- package/core/host_acp/README.md +4 -0
- package/core/host_acp/agnescode.py +128 -0
- package/core/host_runtime/README.md +3 -0
- package/core/host_runtime/adapters.py +45 -6
- package/core/host_runtime/autonomous_runner.py +3 -2
- package/core/host_runtime/host_registry.py +7 -1
- package/core/hosts/README.md +4 -0
- package/core/hosts/__init__.py +1 -0
- package/core/hosts/agnescode.py +415 -0
- package/core/hosts/base.py +1 -0
- package/core/hosts/claude.py +6 -0
- package/core/hosts/cline.py +6 -0
- package/core/hosts/codex.py +10 -1
- package/core/hosts/kimi.py +6 -4
- package/core/hosts/opencode.py +12 -4
- package/core/hosts/zcode.py +6 -0
- package/core/infra/README.md +1 -1
- package/core/infra/build_info.py +2 -2
- package/core/infra/python_runtime.py +4 -1
- package/core/launch_phases/README.md +2 -2
- package/core/launch_phases/finding_confirm_phase.py +1 -1
- package/core/launch_phases/semantic_recon.py +3 -19
- package/core/launch_phases/startup_gates.py +10 -1
- package/core/launch_phases/startup_version_gate.py +2 -2
- package/core/launch_phases/verify_loop.py +3 -19
- package/core/ledger/README.md +1 -1
- package/core/ledger/finding_confirmation.py +1 -1
- package/core/ledger/finding_verification.py +2 -20
- package/core/ledger/fp_ledger.py +3 -19
- package/core/ledger/life_ledger.py +7 -33
- package/core/ledger/schema.py +1 -1
- package/core/locales/en-US.json +2 -0
- package/core/locales/zh-CN.json +2 -0
- package/core/mcp_handlers/supervisor_handlers.py +34 -2
- package/core/mcp_handlers/telemetry_handlers.py +32 -0
- package/core/mcp_handlers/tool_table.py +34 -0
- package/core/mcp_runtime_support/common.py +6 -0
- package/core/mcp_runtime_support/environment.py +82 -23
- package/core/metadata.txt +1 -1
- package/core/planning/README.md +1 -1
- package/core/planning/target_sandbox_manager.py +2 -0
- package/core/probes/mobile_probe.py +1 -0
- package/core/probes/sast_probe.py +1 -1
- package/core/probes/sca_scanner.py +1 -1
- package/core/project_profiler/constants.py +1 -1
- package/core/retrieval/README.md +1 -1
- package/core/retrieval/symbol_index.py +229 -53
- package/core/retrieval/universal_code_matcher.py +1 -0
- package/core/runtime/README.md +1 -1
- package/core/runtime/daemon_runner.py +3 -2
- package/core/runtime/mining_quality_framework.py +2 -1
- package/core/runtime/project_init.py +1 -1
- package/core/runtime/scenario_eval.py +5 -2
- package/core/skills/bugx_mcp_server.py +9 -0
- package/core/skills/mcp_session_proof.py +3 -31
- package/core/supervisor/README.md +1 -1
- package/core/supervisor/finding_commit.py +3 -24
- package/core/supervisor/task_scheduler.py +5 -2
- package/core/supervisor/worker_execution.py +5 -0
- package/core/supervisor/worker_handoff.py +2 -2
- package/docs/07_distribution/01_README_NPM.md +89 -210
- package/ecosystem/integrations/dsh/mcp/package.json +2 -2
- package/ecosystem/integrations/dsh/ui/package.json +1 -1
- package/ecosystem/integrations/opencode/bugx-mcp-manifest.json +3 -3
- package/ecosystem/integrations/opencode/mcp-lock.json +1 -1
- package/ecosystem/integrations/pi/extensions/bugx/manifest.json +1 -1
- package/ecosystem/integrations/qoder/connector-meta.json +1 -1
- package/ecosystem/integrations/workbuddy/connector-meta.json +1 -1
- package/ecosystem/integrations/workbuddy/skills/bugx/SKILL.md +1 -1
- package/ecosystem/plugins/bugx/.claude-plugin/plugin.json +1 -1
- package/ecosystem/plugins/bugx/.codex-plugin/plugin.json +1 -1
- package/ecosystem/plugins/bugx/.zcode-plugin/plugin.json +1 -1
- package/ecosystem/plugins/bugx/skills/bugx/SKILL.md +2 -2
- package/interfaces/cli/bugx_cli/__init__.py +1 -1
- package/interfaces/cli/bugx_cli/cli.py +15 -0
- package/interfaces/cli/bugx_cli/commands/agent.py +18 -0
- package/interfaces/cli/bugx_cli/commands/audit.py +5 -6
- package/interfaces/cli/bugx_cli/commands/doctor.py +1 -1
- package/interfaces/cli/bugx_cli/commands/lifecycle.py +1 -1
- package/interfaces/cli/bugx_cli/commands/patch.py +5 -1
- package/interfaces/cli/bugx_cli/commands/plugin.py +31 -2
- package/interfaces/cli/bugx_cli/commands/plugin_claude.py +2 -2
- package/interfaces/cli/bugx_cli/host_adapters.py +167 -1
- package/interfaces/cli/bugx_cli/hosts/registry.py +33 -1
- package/interfaces/cli/bugx_cli/infra/engine_installer.py +4 -4
- package/interfaces/cli/bugx_cli/infra/host_sync.py +1 -1
- package/package.json +1 -1
- package/scripts/sync-version.mjs +1 -1
- package/skills/platform/bugx/SKILL.md +2 -2
|
@@ -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
|
-
|
|
191
|
-
|
|
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
|
-
|
|
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
|
|
255
|
+
``spec`` 可以是 **约束**(``">=3.12"``)或 ``"3.12"``(前缀匹配),
|
|
220
256
|
``None`` ⇒ 引擎自身解释器。**不写死小版本**:在本机满足约束的解释器里挑
|
|
221
|
-
|
|
222
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
f"{
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
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
package/core/planning/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# BugX Planning & Slicing Engine (能力规划、领域路由、代码切片与仲裁流水线)
|
|
2
2
|
|
|
3
|
-
> **版本契约**: `0.1.
|
|
3
|
+
> **版本契约**: `0.1.6` | **所属分层**: `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
|
|
|
@@ -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
|
|
package/core/retrieval/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# BugX Retrieval Engine (代码切片、拓扑与混合检索增强引擎)
|
|
2
2
|
|
|
3
|
-
> **版本契约**: `0.1.
|
|
3
|
+
> **版本契约**: `0.1.6` | **所属分层**: `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
|
|
|
@@ -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,8 @@ 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",
|
|
97
|
+
".dart_tool",
|
|
95
98
|
}
|
|
96
99
|
# Keep the old public name for callers that used it, but do not use it as a
|
|
97
100
|
# blunt ``any path segment`` filter: product code may legitimately contain a
|
|
@@ -115,7 +118,7 @@ TOP_LEVEL_ASSET_EXCLUDED_DIRS = {
|
|
|
115
118
|
SOURCE_EXTS = {
|
|
116
119
|
".py", ".js", ".mjs", ".cjs", ".jsx", ".ts", ".tsx", ".java", ".kt", ".kts", ".go",
|
|
117
120
|
".rs", ".swift", ".c", ".h", ".cc", ".cpp", ".cxx", ".cs", ".rb",
|
|
118
|
-
".php", ".vue", ".svelte",
|
|
121
|
+
".php", ".vue", ".svelte", ".dart",
|
|
119
122
|
}
|
|
120
123
|
AUDIT_ASSET_EXTS = {
|
|
121
124
|
".sh", ".bash", ".zsh", ".fish", ".sql", ".yaml", ".yml", ".toml",
|
|
@@ -237,11 +240,14 @@ _PROJECT_EXCLUDE_TOP_DIRS_CACHE: dict[Path, frozenset[str]] = {}
|
|
|
237
240
|
|
|
238
241
|
|
|
239
242
|
def _project_exclude_top_dirs(root: Path) -> frozenset[str]:
|
|
240
|
-
"""
|
|
243
|
+
"""项目级覆盖排除(DOC-AIREV 双轨中的 Track 2 动态语义收敛 + 手工配置):
|
|
241
244
|
|
|
242
|
-
1
|
|
243
|
-
|
|
244
|
-
|
|
245
|
+
在 Track 1(``HOST_RUNTIME_DIRS`` / ``DEPENDENCY_OR_GENERATED_DIRS`` 等静态白名单)
|
|
246
|
+
自动排除公认基础设施与工具链之后,剩余目录由 AI 复核再过一遍,两路来源取并集:
|
|
247
|
+
|
|
248
|
+
1. **AI 复核定案**(Track 2 主通道):``.bugx/knowledge/coverage-review.json``
|
|
249
|
+
里宿主 AI 对白名单放行目录逐一排查后的 ``exclude`` 裁决——裁决带理由/时间/
|
|
250
|
+
裁决者,换项目时动态重查,不携带任何项目名清单(DOC-AIREV)。
|
|
245
251
|
2. **手工覆盖**(辅助):``.bugx/config.json`` 的
|
|
246
252
|
``coverage.exclude_top_dirs`` 顶层目录名列表,供人工紧急纠偏。
|
|
247
253
|
|
|
@@ -994,60 +1000,230 @@ def index_repository(
|
|
|
994
1000
|
}
|
|
995
1001
|
|
|
996
1002
|
|
|
1003
|
+
def _build_file_audit_units(
|
|
1004
|
+
root: Path, path: Path, backend: str, strict: bool,
|
|
1005
|
+
*, cache: SourceContentCache | None = None,
|
|
1006
|
+
) -> tuple[str, int, int, str, list[dict]]:
|
|
1007
|
+
"""Parse one source file into its leaf-symbol or file-level audit units."""
|
|
1008
|
+
relative = path.relative_to(root).as_posix()
|
|
1009
|
+
st = path.stat()
|
|
1010
|
+
size = int(st.st_size)
|
|
1011
|
+
mtime_ns = int(st.st_mtime_ns)
|
|
1012
|
+
symbols, error, language = parse_file(path, backend, cache=cache)
|
|
1013
|
+
try:
|
|
1014
|
+
digest = file_sha256(path, cache)
|
|
1015
|
+
except OSError as exc:
|
|
1016
|
+
if strict:
|
|
1017
|
+
raise SourceDiscoveryError(f"源码读取失败 {path}: {exc}") from exc
|
|
1018
|
+
digest = ""
|
|
1019
|
+
# F-RSI-20261115-284 同型输出面:与 index_repository 的 digest_status
|
|
1020
|
+
# 对齐,避免读失败单元以空 content_hash 静默进入下游审计/覆盖清单。
|
|
1021
|
+
digest_status = "error"
|
|
1022
|
+
else:
|
|
1023
|
+
digest_status = "ok"
|
|
1024
|
+
leaves = _leaf_symbols(symbols)
|
|
1025
|
+
if leaves and all(symbol.kind == "module" for symbol in leaves):
|
|
1026
|
+
# A file containing only constants/configuration remains a useful
|
|
1027
|
+
# file-level task; do not manufacture a synthetic callable task.
|
|
1028
|
+
leaves = []
|
|
1029
|
+
if leaves:
|
|
1030
|
+
units = [{
|
|
1031
|
+
"scope": f"{relative}::{symbol.scope_name}",
|
|
1032
|
+
"path": relative,
|
|
1033
|
+
"name": symbol.name,
|
|
1034
|
+
"kind": symbol.kind,
|
|
1035
|
+
"line": symbol.start_line,
|
|
1036
|
+
"parser": symbol.parser,
|
|
1037
|
+
"error": error,
|
|
1038
|
+
"end_line": symbol.end_line,
|
|
1039
|
+
"content_hash": digest,
|
|
1040
|
+
"digest_status": digest_status,
|
|
1041
|
+
"language": language,
|
|
1042
|
+
} for symbol in leaves]
|
|
1043
|
+
else:
|
|
1044
|
+
units = [{
|
|
1045
|
+
"scope": relative,
|
|
1046
|
+
"path": relative,
|
|
1047
|
+
"name": path.stem,
|
|
1048
|
+
"kind": "file",
|
|
1049
|
+
"line": 1,
|
|
1050
|
+
"parser": "fallback-file",
|
|
1051
|
+
"error": error,
|
|
1052
|
+
"language": language,
|
|
1053
|
+
"content_hash": digest,
|
|
1054
|
+
"digest_status": digest_status,
|
|
1055
|
+
}]
|
|
1056
|
+
return relative, size, mtime_ns, digest, units
|
|
1057
|
+
|
|
1058
|
+
|
|
1059
|
+
def _parse_audit_unit_worker(args: tuple[str, str, str, bool]) -> tuple[str, int, int, str, list[dict]]:
|
|
1060
|
+
"""Top-level picklable worker for parallel ProcessPoolExecutor indexing."""
|
|
1061
|
+
root_str, path_str, backend, strict = args
|
|
1062
|
+
return _build_file_audit_units(Path(root_str), Path(path_str), backend, strict)
|
|
1063
|
+
|
|
1064
|
+
|
|
1065
|
+
class _PersistentSymbolCache:
|
|
1066
|
+
"""Content-addressed SQLite cache for audit_units under ``.bugx/cache/``."""
|
|
1067
|
+
|
|
1068
|
+
def __init__(self, root: Path) -> None:
|
|
1069
|
+
self._conn: sqlite3.Connection | None = None
|
|
1070
|
+
bugx_dir = root / ".bugx"
|
|
1071
|
+
if not bugx_dir.is_dir() or bugx_dir.is_symlink():
|
|
1072
|
+
return
|
|
1073
|
+
cache_dir = bugx_dir / "cache"
|
|
1074
|
+
try:
|
|
1075
|
+
cache_dir.mkdir(parents=True, exist_ok=True)
|
|
1076
|
+
db_path = cache_dir / "symbol_cache.db"
|
|
1077
|
+
conn = sqlite3.connect(str(db_path), timeout=5.0)
|
|
1078
|
+
conn.execute(
|
|
1079
|
+
"CREATE TABLE IF NOT EXISTS unit_cache ("
|
|
1080
|
+
"rel_path TEXT NOT NULL, backend TEXT NOT NULL, "
|
|
1081
|
+
"size INTEGER NOT NULL, mtime_ns INTEGER NOT NULL, "
|
|
1082
|
+
"sha256 TEXT NOT NULL, units_json TEXT NOT NULL, "
|
|
1083
|
+
"PRIMARY KEY (rel_path, backend))"
|
|
1084
|
+
)
|
|
1085
|
+
self._conn = conn
|
|
1086
|
+
except (OSError, sqlite3.Error):
|
|
1087
|
+
self._conn = None
|
|
1088
|
+
|
|
1089
|
+
def get_by_stat(self, rel_path: str, backend: str, size: int, mtime_ns: int) -> list[dict] | None:
|
|
1090
|
+
if self._conn is None:
|
|
1091
|
+
return None
|
|
1092
|
+
try:
|
|
1093
|
+
row = self._conn.execute(
|
|
1094
|
+
"SELECT units_json FROM unit_cache "
|
|
1095
|
+
"WHERE rel_path = ? AND backend = ? AND size = ? AND mtime_ns = ?",
|
|
1096
|
+
(rel_path, backend, size, mtime_ns),
|
|
1097
|
+
).fetchone()
|
|
1098
|
+
if row is not None:
|
|
1099
|
+
data = json.loads(row[0])
|
|
1100
|
+
if isinstance(data, list):
|
|
1101
|
+
return data
|
|
1102
|
+
except (sqlite3.Error, ValueError, TypeError):
|
|
1103
|
+
pass
|
|
1104
|
+
return None
|
|
1105
|
+
|
|
1106
|
+
def put_many(self, rows: list[tuple[str, str, int, int, str, list[dict]]]) -> None:
|
|
1107
|
+
if self._conn is None or not rows:
|
|
1108
|
+
return
|
|
1109
|
+
try:
|
|
1110
|
+
with self._conn:
|
|
1111
|
+
self._conn.executemany(
|
|
1112
|
+
"INSERT OR REPLACE INTO unit_cache "
|
|
1113
|
+
"(rel_path, backend, size, mtime_ns, sha256, units_json) "
|
|
1114
|
+
"VALUES (?, ?, ?, ?, ?, ?)",
|
|
1115
|
+
[
|
|
1116
|
+
(rel, backend, size, mtime_ns, digest, json.dumps(units, ensure_ascii=False))
|
|
1117
|
+
for rel, backend, size, mtime_ns, digest, units in rows
|
|
1118
|
+
],
|
|
1119
|
+
)
|
|
1120
|
+
except (sqlite3.Error, TypeError, ValueError):
|
|
1121
|
+
pass
|
|
1122
|
+
|
|
1123
|
+
def close(self) -> None:
|
|
1124
|
+
if self._conn is not None:
|
|
1125
|
+
try:
|
|
1126
|
+
self._conn.close()
|
|
1127
|
+
except sqlite3.Error:
|
|
1128
|
+
pass
|
|
1129
|
+
self._conn = None
|
|
1130
|
+
|
|
1131
|
+
|
|
997
1132
|
def audit_units(
|
|
998
1133
|
root: Path, backend: str = "auto", strict: bool = False,
|
|
999
1134
|
*, cache: SourceContentCache | None = None,
|
|
1135
|
+
parallel: bool = True,
|
|
1136
|
+
use_persistent_cache: bool = True,
|
|
1000
1137
|
) -> list[dict]:
|
|
1001
|
-
"""返回最细审计单元;有符号时取叶子符号,否则退回文件。
|
|
1138
|
+
"""返回最细审计单元;有符号时取叶子符号,否则退回文件。
|
|
1139
|
+
|
|
1140
|
+
支持:
|
|
1141
|
+
1. 基于 ``.bugx/cache/symbol_cache.db`` 的文件级内容/stat 持久化缓存;
|
|
1142
|
+
2. 超过 32 个未命中文件时自动启用多进程并发 AST 解析;
|
|
1143
|
+
3. 大规模扫描时定期向 stderr 输出心跳进度,避免宿主误判挂死。
|
|
1144
|
+
"""
|
|
1002
1145
|
root = root.resolve()
|
|
1003
1146
|
cache = cache if cache is not None else SourceContentCache()
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1147
|
+
source_paths = discover_source_paths(root, strict=strict)
|
|
1148
|
+
persistent = _PersistentSymbolCache(root) if use_persistent_cache else None
|
|
1149
|
+
|
|
1150
|
+
units_by_rel: dict[str, list[dict]] = {}
|
|
1151
|
+
uncached: list[Path] = []
|
|
1152
|
+
ordered_rels: list[str] = []
|
|
1153
|
+
|
|
1154
|
+
try:
|
|
1155
|
+
for path in source_paths:
|
|
1156
|
+
relative = path.relative_to(root).as_posix()
|
|
1157
|
+
ordered_rels.append(relative)
|
|
1158
|
+
if persistent is not None:
|
|
1159
|
+
try:
|
|
1160
|
+
st = path.stat()
|
|
1161
|
+
cached_units = persistent.get_by_stat(
|
|
1162
|
+
relative, backend, int(st.st_size), int(st.st_mtime_ns),
|
|
1163
|
+
)
|
|
1164
|
+
if cached_units is not None:
|
|
1165
|
+
units_by_rel[relative] = cached_units
|
|
1166
|
+
continue
|
|
1167
|
+
except OSError:
|
|
1168
|
+
pass
|
|
1169
|
+
uncached.append(path)
|
|
1170
|
+
|
|
1171
|
+
total_uncached = len(uncached)
|
|
1172
|
+
new_cache_rows: list[tuple[str, str, int, int, str, list[dict]]] = []
|
|
1173
|
+
|
|
1174
|
+
main_file = getattr(sys.modules.get("__main__"), "__file__", None)
|
|
1175
|
+
can_spawn = bool(main_file and os.path.isfile(main_file))
|
|
1176
|
+
if parallel and can_spawn and total_uncached >= 32 and (os.cpu_count() or 1) > 1:
|
|
1177
|
+
workers = min(os.cpu_count() or 4, 8)
|
|
1178
|
+
tasks = [(str(root), str(p), backend, strict) for p in uncached]
|
|
1179
|
+
try:
|
|
1180
|
+
with concurrent.futures.ProcessPoolExecutor(max_workers=workers) as pool:
|
|
1181
|
+
for idx, (rel, size, mtime_ns, digest, file_units) in enumerate(
|
|
1182
|
+
pool.map(_parse_audit_unit_worker, tasks, chunksize=16), 1,
|
|
1183
|
+
):
|
|
1184
|
+
units_by_rel[rel] = file_units
|
|
1185
|
+
if digest:
|
|
1186
|
+
new_cache_rows.append((rel, backend, size, mtime_ns, digest, file_units))
|
|
1187
|
+
if total_uncached >= 200 and idx % 200 == 0:
|
|
1188
|
+
print(
|
|
1189
|
+
f"[symbol_index] 并发解析进度: {idx}/{total_uncached}",
|
|
1190
|
+
file=sys.stderr, flush=True,
|
|
1191
|
+
)
|
|
1192
|
+
except (OSError, PermissionError, RuntimeError, ValueError):
|
|
1193
|
+
# 受限沙箱或子进程启动失败时安全退回单进程路径
|
|
1194
|
+
units_by_rel = {k: v for k, v in units_by_rel.items()}
|
|
1195
|
+
new_cache_rows.clear()
|
|
1196
|
+
for p in uncached:
|
|
1197
|
+
if p.relative_to(root).as_posix() not in units_by_rel:
|
|
1198
|
+
rel, size, mtime_ns, digest, file_units = _build_file_audit_units(
|
|
1199
|
+
root, p, backend, strict, cache=cache,
|
|
1200
|
+
)
|
|
1201
|
+
units_by_rel[rel] = file_units
|
|
1202
|
+
if digest:
|
|
1203
|
+
new_cache_rows.append((rel, backend, size, mtime_ns, digest, file_units))
|
|
1038
1204
|
else:
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1205
|
+
for idx, p in enumerate(uncached, 1):
|
|
1206
|
+
rel, size, mtime_ns, digest, file_units = _build_file_audit_units(
|
|
1207
|
+
root, p, backend, strict, cache=cache,
|
|
1208
|
+
)
|
|
1209
|
+
units_by_rel[rel] = file_units
|
|
1210
|
+
if digest:
|
|
1211
|
+
new_cache_rows.append((rel, backend, size, mtime_ns, digest, file_units))
|
|
1212
|
+
if total_uncached >= 200 and idx % 200 == 0:
|
|
1213
|
+
print(
|
|
1214
|
+
f"[symbol_index] 解析进度: {idx}/{total_uncached}",
|
|
1215
|
+
file=sys.stderr, flush=True,
|
|
1216
|
+
)
|
|
1217
|
+
|
|
1218
|
+
if persistent is not None and new_cache_rows:
|
|
1219
|
+
persistent.put_many(new_cache_rows)
|
|
1220
|
+
finally:
|
|
1221
|
+
if persistent is not None:
|
|
1222
|
+
persistent.close()
|
|
1223
|
+
|
|
1224
|
+
result: list[dict] = []
|
|
1225
|
+
for rel in ordered_rels:
|
|
1226
|
+
result.extend(units_by_rel.get(rel, ()))
|
|
1051
1227
|
return result
|
|
1052
1228
|
|
|
1053
1229
|
|
package/core/runtime/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# BugX Core Runtime Subsystem (核心运行时、环境与基础设施)
|
|
2
2
|
|
|
3
|
-
> **版本契约**: `0.1.
|
|
3
|
+
> **版本契约**: `0.1.6` | **所属分层**: `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 =
|
|
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,
|
|
194
|
+
os.kill(pid, sigkill)
|
|
194
195
|
except OSError:
|
|
195
196
|
pass
|
|
196
197
|
|
|
@@ -50,12 +50,13 @@ SUPPORTED_SOURCE_EXTS = {
|
|
|
50
50
|
".rs",
|
|
51
51
|
".js", ".jsx", ".mjs", ".cjs", ".ts", ".tsx",
|
|
52
52
|
".cs", ".php", ".rb",
|
|
53
|
+
".dart",
|
|
53
54
|
}
|
|
54
55
|
|
|
55
56
|
SKIP_DIRS = {
|
|
56
57
|
".git", ".bugx", ".venv", "venv", "node_modules", "__pycache__",
|
|
57
58
|
"dist", "build", "target", ".tox", ".mypy_cache", ".pytest_cache",
|
|
58
|
-
"vendor", "Pods", ".gradle", ".idea",
|
|
59
|
+
"vendor", "Pods", ".gradle", ".idea", ".dart_tool", ".vscode",
|
|
59
60
|
}
|
|
60
61
|
|
|
61
62
|
# 路由装饰器识别正则与特征
|
|
@@ -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)
|