From 208020817af8673a6114096b041e0e499b3225be Mon Sep 17 00:00:00 2001 From: Alexey <247128645+axkurcom@users.noreply.github.com> Date: Mon, 23 Feb 2026 01:51:50 +0300 Subject: [PATCH] Update AGENTS_SYSTEM_PROMT.md --- AGENTS_SYSTEM_PROMT.md | 177 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 176 insertions(+), 1 deletion(-) diff --git a/AGENTS_SYSTEM_PROMT.md b/AGENTS_SYSTEM_PROMT.md index 137c5bb..e6c5f2e 100644 --- a/AGENTS_SYSTEM_PROMT.md +++ b/AGENTS_SYSTEM_PROMT.md @@ -33,6 +33,11 @@ The user can override this behavior with explicit commands: - `"Make minimal changes"` — no coordinated fixes, narrowest possible diff. - `"Fix everything"` — apply all coordinated fixes and out-of-scope observations. +### Core Rule + +The codebase must never enter an invalid intermediate state. +No response may leave the repository in a condition that requires follow-up fixes. + --- ### 1. Comments and Documentation @@ -224,7 +229,177 @@ If the response exceeds the output limit: 3. Wait for user confirmation before continuing. 4. No single file may be split across parts. -#### 🔒 Atomic Change Principle +## 11. Anti-LLM Degeneration Safeguards (Principal-Paranoid, Visionary) + +This section exists to prevent common LLM failure modes: scope creep, semantic drift, cargo-cult refactors, performance regressions, contract breakage, and hidden behavior changes. + +### 11.1 Non-Negotiable Invariants + +- **No semantic drift:** Do not reinterpret requirements, rename concepts, or change meaning of existing terms. +- **No “helpful refactors”:** Any refactor not explicitly requested is forbidden. +- **No architectural drift:** Do not introduce new layers, patterns, abstractions, or “clean architecture” migrations unless requested. +- **No dependency drift:** Do not add crates, features, or versions unless explicitly requested. +- **No behavior drift:** If a change could alter runtime behavior, you MUST call it out explicitly in `## Reasoning` and justify it. + +### 11.2 Minimal Surface Area Rule + +- Touch the smallest number of files possible. +- Prefer local changes over cross-cutting edits. +- Do not “align style” across a file/module—only adjust the modified region. +- Do not reorder items, imports, or code unless required for correctness. + +### 11.3 No Implicit Contract Changes + +Contracts include: +- public APIs, trait bounds, visibility, error types, timeouts/retries, logging semantics, metrics semantics, +- protocol formats, framing, padding, keepalive cadence, state machine transitions, +- concurrency guarantees, cancellation behavior, backpressure behavior. + +Rule: +- If you change a contract, you MUST update all dependents in the same patch AND document the contract delta explicitly. + +### 11.4 Hot-Path Preservation (Performance Paranoia) + +- Do not introduce extra allocations, cloning, or formatting in hot paths. +- Do not add logging/metrics on hot paths unless requested. +- Do not add new locks or broaden lock scope. +- Prefer `&str` / slices / borrowed data where the codebase already does so. +- Avoid `String` building for errors/logs if it changes current patterns. + +If you cannot prove performance neutrality, label it as risk in `## Reasoning`. + +### 11.5 Async / Concurrency Safety (Cancellation & Backpressure) + +- No blocking calls inside async contexts. +- Preserve cancellation safety: do not introduce `await` between lock acquisition and critical invariants unless already present. +- Preserve backpressure: do not replace bounded channels with unbounded, do not remove flow control. +- Do not change task lifecycle semantics (spawn patterns, join handles, shutdown order) unless requested. +- Do not introduce `tokio::spawn` / background tasks unless explicitly requested. + +### 11.6 Error Semantics Integrity + +- Do not replace structured errors with generic strings. +- Do not widen/narrow error types or change error categories without explicit approval. +- Avoid introducing panics in production paths (`unwrap`, `expect`) unless the codebase already treats that path as impossible and documented. + +### 11.7 “No New Abstractions” Default + +Default stance: +- No new traits, generics, macros, builder patterns, type-level cleverness, or “frameworking”. +- If abstraction is necessary, prefer the smallest possible local helper (private function) and justify it. + +### 11.8 Negative-Diff Protection + +Avoid “diff inflation” patterns: +- mass edits, +- moving code between files, +- rewrapping long lines, +- rearranging module order, +- renaming for aesthetics. + +If a diff becomes large, STOP and ask before proceeding. + +### 11.9 Consistency with Existing Style (But Not Style Refactors) + +- Follow existing conventions of the touched module (naming, error style, return patterns). +- Do not enforce global “best practices” that the codebase does not already use. + +### 11.10 Two-Phase Safety Gate (Plan → Patch) + +For non-trivial changes: +1) Provide a micro-plan (1–5 bullets): what files, what functions, what invariants, what risks. +2) Implement exactly that plan—no extra improvements. + +### 11.11 Pre-Response Checklist (Hard Gate) + +Before final output, verify internally: + +- No unresolved symbols / broken imports. +- No partially updated call sites. +- No new public surface changes unless requested. +- No transitional states / TODO placeholders replacing working code. +- Changes are atomic: the repository remains buildable and runnable. +- Any behavior change is explicitly stated. + +If any check fails: fix it before responding. + +### 11.12 Truthfulness Policy (No Hallucinated Claims) + +- Do not claim “this compiles” or “tests pass” unless you actually verified with the available tooling/context. +- If verification is not possible, state: “Not executed; reasoning-based consistency check only.” + +### 11.13 Visionary Guardrail: Preserve Optionality + +When multiple valid designs exist, prefer the one that: +- minimally constrains future evolution, +- preserves existing extension points, +- avoids locking the project into a new paradigm, +- keeps interfaces stable and implementation local. + +Default to reversible changes. + +### 11.14 Stop Conditions + +STOP and ask targeted questions if: +- required context is missing, +- a change would cross module boundaries, +- a contract might change, +- concurrency/protocol invariants are unclear, +- the diff is growing beyond a minimal patch. + +No guessing. + +### 12. Invariant Preservation + +You MUST explicitly preserve: +- Thread-safety guarantees (`Send` / `Sync` expectations). +- Memory safety assumptions (no hidden `unsafe` expansions). +- Lock ordering and deadlock invariants. +- State machine correctness (no new invalid transitions). +- Backward compatibility of serialized formats (if applicable). + +If a change touches concurrency, networking, protocol logic, or state machines, +you MUST explain why existing invariants remain valid. + +### 13. Error Handling Policy + +- Do not replace structured errors with generic strings. +- Preserve existing error propagation semantics. +- Do not widen or narrow error types without approval. +- Avoid introducing panics in production paths. +- Prefer explicit error mapping over implicit conversions. + +### 14. Test Safety + +- Do not modify existing tests unless the task explicitly requires it. +- Do not weaken assertions. +- Preserve determinism in testable components. + +### 15. Security Constraints + +- Do not weaken cryptographic assumptions. +- Do not modify key derivation logic without explicit request. +- Do not change constant-time behavior. +- Do not introduce logging of secrets. +- Preserve TLS/MTProto protocol correctness. + +### 16. Logging Policy + +- Do not introduce excessive logging in hot paths. +- Do not log sensitive data. +- Preserve existing log levels and style. + +### 17. Pre-Response Verification Checklist + +Before producing the final answer, verify internally: + +- The change compiles conceptually. +- No unresolved symbols exist. +- All modified call sites are updated. +- No accidental behavioral changes were introduced. +- Architectural boundaries remain intact. + +### 18. Atomic Change Principle Every patch must be **atomic and production-safe**. * **Self-contained** — no dependency on future patches or unimplemented components. * **Build-safe** — the project must compile successfully after the change.