refactor(tools): lift engine ensure/sub-section boilerplate into _Engine.__init__/_build, contextlib.suppress for swallow-only try/except, collapse yuanbao _err into _YbError, fold pending-dir helpers

This commit is contained in:
Teknium
2026-09-03 00:10:38 -07:00
parent 1e06d9b8ee
commit 0f99f96a5e
6 changed files with 183 additions and 279 deletions
+2 -3
View File
@@ -12,6 +12,7 @@ from __future__ import annotations
import os
import shutil
import subprocess
from contextlib import suppress
from typing import Dict, List
from hermes_cli._subprocess_compat import harden_git_argv, noninteractive_git_env
@@ -49,13 +50,11 @@ def _untracked_diff(cwd: str, files: List[str]) -> str:
"""Render untracked files as new-file diffs via ``git diff --no-index``."""
chunks: List[str] = []
for rel in files[:_MAX_UNTRACKED_FILES]:
try:
with suppress(subprocess.TimeoutExpired, OSError):
# --no-index exits 1 when files differ — the success path, so the code is ignored.
_, out = _run(["diff", "--no-index", "--", os.devnull, rel], cwd)
if out.strip():
chunks.append(out.rstrip("\n"))
except (subprocess.TimeoutExpired, OSError):
continue
if len(files) > _MAX_UNTRACKED_FILES:
chunks.append(f"... ({len(files) - _MAX_UNTRACKED_FILES} more untracked files not shown)")
return "\n".join(chunks)