Add controlled coding agent automation
Some checks failed
CI / test (push) Has been cancelled

This commit is contained in:
2026-08-21 22:49:49 +02:00
parent 9bac41f071
commit bfa5cdcd3e
25 changed files with 1263 additions and 1 deletions

View File

@@ -0,0 +1,63 @@
from __future__ import annotations
import re
from .models import FailureReport
_SECRET_PATTERNS = (
(
re.compile(r"(?i)\b(?:mysql|mariadb|postgres(?:ql)?|sqlserver)://[^\s]+"),
"[DATABASE_URL]",
),
(re.compile(r"(?i)(password|passwd|secret|token|api[_ -]?key)\s*[:=]\s*\S+"), r"\1=[REDACTED]"),
(re.compile(r"\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}\b"), "[EMAIL]"),
(re.compile(r"\b(?:\d{1,3}\.){3}\d{1,3}\b"), "[IP]"),
(re.compile(r"(?i)bearer\s+[A-Za-z0-9._~+/=-]+"), "Bearer [REDACTED]"),
(re.compile(r"\bAKIA[0-9A-Z]{16}\b"), "[AWS_KEY]"),
(re.compile(r"-----BEGIN [A-Z ]+KEY-----[\s\S]+?-----END [A-Z ]+KEY-----"), "[PRIVATE_KEY]"),
(re.compile(r"\b[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\b"), "[JWT]"),
)
def redact(value: str | None) -> str:
result = value or ""
for pattern, replacement in _SECRET_PATTERNS:
result = pattern.sub(replacement, result)
return result[:12_000]
def build_task(report: FailureReport) -> str:
prompt = redact(report.prompt)
feedback = redact(report.user_feedback)
error = redact(report.error_message)
sql = redact(report.sql_query)
return f"""You are fixing failure report #{report.id} in the Laravel AI Chat repository.
Rules:
- First add a regression test that reproduces the reported behavior.
- Make the smallest production change that fixes the root cause.
- Preserve read-only SQL validation and tenant isolation.
- Never read or modify .env files, credentials, deployment secrets, or production data.
- Do not weaken tests, authentication, authorization, SQL validation, or safety checks.
- Do not commit or push; the orchestrator owns Git publication.
Failure category: {report.category}
Source: {report.source}
Model: {redact(str(report.context.get('model', 'unknown')))}
Database type: {redact(str(report.context.get('database_type', 'unknown')))}
User request:
{prompt or '[not available]'}
User feedback:
{feedback or '[not available]'}
Observed error:
{error or '[not available]'}
Generated SQL, if relevant:
{sql or '[not available]'}
Run focused tests while working. Leave the repository with the fix and regression test applied.
"""