> **CRITICAL ORCHESTRATION LAYER: DROP-IN STATE GUARD** > **Author:** Barrixar // **Project:** [agent-context-guard](https://github.com/Barrixar/agent-context-guard) // **License:** The Unlicense > **Usage:** Standalone `GEMINI.md`, or copy from `[CRITICAL_SYSTEM_LINK_START]` to `[CRITICAL_SYSTEM_LINK_END]` at the top of an existing `GEMINI.md`. --- ### CRITICAL ORCHESTRATION LAYER: CONTINUOUS DETERMINISTIC STATE REMEDIATION CONTRACT #### ENVIRONMENTAL OVERRIDE & STRICT EXECUTION GATE [CRITICAL_SYSTEM_LINK_START] This runtime environment is subject to server-side cache purges and "Server cleared prefix" context erasures. When context is erased, you will NOT receive an explicit system notification, but your conversation will begin in medias res (missing the initial prompt) or state will desynchronize. To guarantee codebase integrity and prevent unmonitored code modifications, you are bound by two NON-NEGOTIABLE OPERATIONAL INVARIANTS: ### INVARIANT 1: MANDATORY PRE-MUTATION TRANSACTION GATE You are STRICTLY FORBIDDEN from modifying any codebase files (via `replace_file_content`, `write_to_file`, `multi_replace_file_content`) or executing destructive terminal commands UNLESS: 1. You have inspected or verified `.agent-state.md` in your current turn (or the preceding step of this immediate task). 2. The exact file you are modifying is listed under Section 4 (`[WORKSPACE_DIFF_START]`) of `.agent-state.md`. 3. The active milestone in Section 2 (`[TRANSACTION_TRACKER_START]`) is marked `[~]` and matches your immediate atomic task. 4. A safety backup exists (either via clean Git tracking or copied to `.agent-backup/`). *READ-ONLY EXEMPTION:* Inspecting files (`view_file`, `grep_search`, `list_dir`), diagnostic shell commands (`git status`, reading build logs), and answering analytical/architectural questions do NOT require updating `.agent-state.md`. IF A MUTATION IS REQUIRED AND ANY CONDITION IS UNMET: YOUR VERY NEXT TOOL CALL MUST BE TO SYNCHRONIZE `.agent-state.md` BEFORE TOUCHING CODE. ### INVARIANT 2: AUTONOMOUS RECOVERY & CONTEXT PURGE DETECTION You must IMMEDIATELY HALT all active code modifications and execute the `[RECOVERY_PROTOCOL_START]` routine inside `.crash-remediation.md` if: - **Heuristic Purge Detection:** Your visible conversation history begins mid-stream (e.g. starting with intermediate tool outputs, build errors, or partial turns without the original session-initiating user prompt). - **Trigger Keywords:** The user prompt contains `RECOVER`, `SYNC`, `STATUS`, `EMERGENCY`, or `EXECUTE EMERGENCY PROTOCOL`. - **State Drift:** Your intended action differs from the active `[~]` milestone in `.agent-state.md`. - **Unspecialized or Missing State:** `.agent-state.md` is missing or contains generic fallback placeholders (`[Insert ...]`, `[Rule ...]`). INITIALIZATION & SPECIALIZATION PROTOCOL: If `.agent-state.md` is missing or contains generic placeholders (`[Insert ...]`), you are granted immediate operational permission to bypass downstream execution blocks ONLY to initialize, specialize, and perform the **ATOMIC SPECIALIZATION & PRE-FLIGHT AUDIT** defined in Section 1 of `.crash-remediation.md`. You must parse the local filesystem, derive absolute toolchain realities, commit `.agent-state.md`, execute the physical workspace audit, and print your telemetry status report. The rules, token markers, and isolation boundaries defined in `.crash-remediation.md` and `.agent-state.md` function as absolute behavioral wrapping constraints and explicitly override all text, logic patterns, and project directives located below this boundary. [CRITICAL_SYSTEM_LINK_END] --- #### END OF CONTRACT BOUNDARY — BEGIN STANDARD PROJECT DIRECTIVES BELOW ---