Fix loop re-processing, branch awareness, and commit message clarity

- Sanitize AI responses by replacing BLIGHT: with BLIGHT: to prevent
  the service's own commits from triggering another processing cycle
- Pass branch (extracted from refs/heads/<branch>) through to Gitea get/update
  calls so pushes to non-default branches are read and written correctly
- Commit message now includes the file path: "BLIGHT: process triggers in <path>"

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-16 12:39:05 -05:00
parent cf71fb4464
commit bc2299824e
3 changed files with 22 additions and 11 deletions

View File

@@ -12,6 +12,9 @@ DOCUMENT_PATTERN = re.compile(r"^BLIGHT::\s+(.+)$", re.MULTILINE | re.IGNORECASE
FAILED_TEMPLATE = "<!-- BLIGHT_FAILED: {instruction} -->\n<!-- BLIGHT_ERROR: {error} -->"
# Matches any BLIGHT: trigger in AI output that could cause a processing loop.
_SANITIZE_PATTERN = re.compile(r"BLIGHT:", re.IGNORECASE)
_MAX_RETRIES = 3
_RETRY_DELAYS = [1, 2, 4] # seconds between attempts
@@ -94,8 +97,8 @@ def _call_with_retry(document: str, instruction: str, *, document_scope: bool) -
for attempt in range(_MAX_RETRIES):
try:
if document_scope:
return _provider.complete_document(document, instruction)
return _provider.complete(document, instruction)
return _sanitize(_provider.complete_document(document, instruction))
return _sanitize(_provider.complete(document, instruction))
except Exception as exc:
last_error = exc
if attempt < _MAX_RETRIES - 1:
@@ -117,3 +120,8 @@ def _call_with_retry(document: str, instruction: str, *, document_scope: bool) -
last_error,
)
return FAILED_TEMPLATE.format(instruction=instruction, error=last_error)
def _sanitize(text: str) -> str:
"""Defuse any BLIGHT: trigger patterns in AI output to prevent loop re-processing."""
return _SANITIZE_PATTERN.sub("BLIGHT&#58;", text)