--- name: semantics-core description: Universal physics, global invariants, and hierarchical routing for the GRACE-Poly v2.4 protocol. --- # [DEF:Std:Semantics:Core] # @COMPLEXITY: 5 # @PURPOSE: # @RELATION: DISPATCHES -> [Std:Semantics:Contracts] # @RELATION: DISPATCHES -> [Std:Semantics:Belief] # @RELATION: DISPATCHES -> [Std:Semantics:Testing] # @RELATION: DISPATCHES ->[Std:Semantics:Frontend] ## 0. ZERO-STATE RATIONALE (LLM PHYSICS) You are an autoregressive Transformer model. You process tokens sequentially and cannot reverse generation. In large codebases, your KV-Cache is vulnerable to Attention Sink, leading to context blindness and hallucinations. This protocol is your **cognitive exoskeleton**. `[DEF]` anchors are your attention vectors. Contracts (`@PRE`, `@POST`) force you to form a strict Belief State BEFORE generating syntax. We do not write raw text; we compile semantics into strictly bounded AST (Abstract Syntax Tree) nodes. ## I. GLOBAL INVARIANTS - **[INV_1: SEMANTICS > SYNTAX]:** Naked code without a contract is classified as garbage. You must define the contract before writing the implementation. - **[INV_2: NO HALLUCINATIONS]:** If context is blind (unknown `@RELATION` node or missing data schema), generation is blocked. Emit `[NEED_CONTEXT: target]`. - **[INV_3: ANCHOR INVIOLABILITY]:** `[DEF]...[/DEF]` blocks are AST accumulators. The closing tag carrying the exact ID is strictly mandatory. - **[INV_4: TOPOLOGICAL STRICTNESS]:** All metadata tags (`@PURPOSE`, `@PRE`, etc.) MUST be placed contiguously immediately following the opening `[DEF]` anchor and strictly BEFORE any code syntax (imports, decorators, or declarations). Keep metadata visually compact. - **[INV_5: RESOLUTION OF CONTRADICTIONS]:** A local workaround (Micro-ADR) CANNOT override a Global ADR limitation. If reality requires breaking a Global ADR, stop and emit `` to the Architect. - **[INV_6: TOMBSTONES FOR DELETION]:** Never delete a `[DEF]` node if it has incoming `@RELATION` edges. Instead, mutate its type to `[DEF:id:Tombstone]`, remove the code body, and add `@STATUS: DEPRECATED -> REPLACED_BY: [New_ID]`. - **[INV_7: FRACTAL LIMIT (ZERO-EROSION)]:** Module length MUST strictly remain < 400 lines of code. Single [DEF] node length MUST remain < 150 lines, and its Cyclomatic Complexity MUST NOT exceed 10. If these limits are breached, forced decomposition into smaller files/nodes is MANDATORY. Do not accumulate "Slop". ## II. SYNTAX AND MARKUP Format depends on the execution environment: - Python/Markdown: `# [DEF:Id:Type] ... # [/DEF:Id:Type]` - Svelte/HTML: ` ... ` - JS/TS: `// [DEF:Id:Type] ... // [/DEF:Id:Type]` *Allowed Types: Root, Standard, Module, Class, Function, Component, Store, Block, ADR, Tombstone.* **Graph Dependencies (GraphRAG):** `@RELATION: [PREDICATE] -> [TARGET_ID]` *Allowed Predicates:* DEPENDS_ON, CALLS, INHERITS, IMPLEMENTS, DISPATCHES, BINDS_TO. ## III. COMPLEXITY SCALE (1-5) The level of control is defined in the Header via `@COMPLEXITY` (alias: `@C:`). Default is 1 if omitted. - **C1 (Atomic):** DTOs, simple utils. Requires ONLY `[DEF]...[/DEF]`. - **C2 (Simple):** Requires `[DEF]` + `@PURPOSE`. - **C3 (Flow):** Requires `[DEF]` + `@PURPOSE` + `@RELATION`. - **C4 (Orchestration):** Adds `@PRE`, `@POST`, `@SIDE_EFFECT`. Requires Belief State runtime logging. - **C5 (Critical):** Adds `@DATA_CONTRACT`, `@INVARIANT`, and mandatory Decision Memory tracking. ## IV. DOMAIN SUB-PROTOCOLS (ROUTING) Depending on your active task, you MUST request and apply the following domain-specific rules: - For Backend Logic & Architecture: Use `skill({name="semantics-contracts"})` and `skill({name="semantics-belief"})`. - For QA & External Dependencies: Use `skill({name="semantics-testing"})`. - For UI & Svelte Components: Use `skill({name="semantics-frontend"})`. # [/DEF:Std:Semantics:Core]