feat(devgen/modules): streamline provider guard and enhance ManifestInspector flexibility
Add token‑limit error handling and switch git diff to null‑delimited output for reliable file detection.
This commit is contained in:
3 files changed
+30
-20
No files matched your search
@@ -33,6 +33,8 @@ from devgen.utils import (
|
|||||||
extract_commit_messages,
|
extract_commit_messages,
|
||||||
get_commit_dry_run_path,
|
get_commit_dry_run_path,
|
||||||
is_file_recent,
|
is_file_recent,
|
||||||
|
is_token_limit_error,
|
||||||
|
format_token_limit_error,
|
||||||
load_template,
|
load_template,
|
||||||
render_template,
|
render_template,
|
||||||
sanitize_ai_commit_message,
|
sanitize_ai_commit_message,
|
||||||
@@ -241,9 +243,10 @@ class CommitEngine:
|
|||||||
if not self._process_group(group, group_files, cache_map):
|
if not self._process_group(group, group_files, cache_map):
|
||||||
failed.append(group)
|
failed.append(group)
|
||||||
if len(groups) > 1 and i < len(groups) - 1:
|
if len(groups) > 1 and i < len(groups) - 1:
|
||||||
import time
|
if self.provider != "ollama":
|
||||||
|
import time
|
||||||
|
|
||||||
time.sleep(15) # Conservative 4 RPM guard for free-tier
|
time.sleep(15) # Conservative 4 RPM guard for free-tier
|
||||||
return failed
|
return failed
|
||||||
|
|
||||||
def _process_group(
|
def _process_group(
|
||||||
@@ -265,7 +268,7 @@ class CommitEngine:
|
|||||||
return self._apply_message(group, cache[group], files)
|
return self._apply_message(group, cache[group], files)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
manifest_context = ManifestInspector.summary()
|
manifest_context = ManifestInspector.summary(cwd=self.git.cwd)
|
||||||
if manifest_context:
|
if manifest_context:
|
||||||
self.logger.info("Including manifest context in prompt")
|
self.logger.info("Including manifest context in prompt")
|
||||||
with self.console.status(
|
with self.console.status(
|
||||||
@@ -279,10 +282,15 @@ class CommitEngine:
|
|||||||
)
|
)
|
||||||
message = sanitize_ai_commit_message(raw)
|
message = sanitize_ai_commit_message(raw)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.error(
|
if is_token_limit_error(e):
|
||||||
f"Failed to generate message for group {group!r}: {e}",
|
msg = format_token_limit_error(self.provider, e, group=group)
|
||||||
exc_info=True,
|
self.console.print(f"[bold red]{msg}[/bold red]")
|
||||||
)
|
self.logger.error(msg)
|
||||||
|
else:
|
||||||
|
self.logger.error(
|
||||||
|
f"Failed to generate message for group {group!r}: {e}",
|
||||||
|
exc_info=True,
|
||||||
|
)
|
||||||
self.git.reset(files)
|
self.git.reset(files)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|||||||
@@ -143,13 +143,14 @@ class ManifestInspector:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def summary() -> str:
|
def summary(cwd: Optional[Path] = None) -> str:
|
||||||
|
cwd = cwd or get_git_root() or Path(".")
|
||||||
lines = [
|
lines = [
|
||||||
s
|
s
|
||||||
for s in (
|
for s in (
|
||||||
ManifestInspector._pyproject(),
|
ManifestInspector._pyproject(cwd),
|
||||||
ManifestInspector._package_json(),
|
ManifestInspector._package_json(cwd),
|
||||||
ManifestInspector._requirements(),
|
ManifestInspector._requirements(cwd),
|
||||||
)
|
)
|
||||||
if s
|
if s
|
||||||
]
|
]
|
||||||
@@ -164,8 +165,8 @@ class ManifestInspector:
|
|||||||
return re.split(r"[><=!~\[]", spec, 1)[0].strip()
|
return re.split(r"[><=!~\[]", spec, 1)[0].strip()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _pyproject() -> Optional[str]:
|
def _pyproject(cwd: Path) -> Optional[str]:
|
||||||
path = Path("pyproject.toml")
|
path = cwd / "pyproject.toml"
|
||||||
if not path.exists():
|
if not path.exists():
|
||||||
return None
|
return None
|
||||||
try:
|
try:
|
||||||
@@ -186,8 +187,8 @@ class ManifestInspector:
|
|||||||
return f"[pyproject.toml] {' '.join(parts)}" if parts else None
|
return f"[pyproject.toml] {' '.join(parts)}" if parts else None
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _package_json() -> Optional[str]:
|
def _package_json(cwd: Path) -> Optional[str]:
|
||||||
path = Path("package.json")
|
path = cwd / "package.json"
|
||||||
if not path.exists():
|
if not path.exists():
|
||||||
return None
|
return None
|
||||||
try:
|
try:
|
||||||
@@ -203,8 +204,8 @@ class ManifestInspector:
|
|||||||
return f"[package.json] {' '.join(parts)}" if parts else None
|
return f"[package.json] {' '.join(parts)}" if parts else None
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _requirements() -> Optional[str]:
|
def _requirements(cwd: Path) -> Optional[str]:
|
||||||
path = Path("requirements.txt")
|
path = cwd / "requirements.txt"
|
||||||
if not path.exists():
|
if not path.exists():
|
||||||
return None
|
return None
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -91,15 +91,16 @@ class GitOperator:
|
|||||||
[
|
[
|
||||||
"git",
|
"git",
|
||||||
"ls-files",
|
"ls-files",
|
||||||
|
"-z",
|
||||||
"--deleted",
|
"--deleted",
|
||||||
"--modified",
|
"--modified",
|
||||||
"--others",
|
"--others",
|
||||||
"--exclude-standard",
|
"--exclude-standard",
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
files = {f.strip() for f in out.split("\n") if f.strip()}
|
files = {f for f in out.split("\0") if f}
|
||||||
staged_out = self._run(["git", "diff", "--name-only", "--cached"])
|
staged_out = self._run(["git", "diff", "-z", "--name-only", "--cached"])
|
||||||
files.update(f.strip() for f in staged_out.split("\n") if f.strip())
|
files.update(f for f in staged_out.split("\0") if f)
|
||||||
return sorted(files)
|
return sorted(files)
|
||||||
|
|
||||||
# ------------------------------------------------------------------ actions
|
# ------------------------------------------------------------------ actions
|
||||||
|
|||||||
Reference in new issue
Block a user