4.8 KiB
name, description
| name | description |
|---|---|
| semantics-contracts | Core extension protocol for Design by Contract, Fractal Decision Memory (ADR), and Long-Horizon Agentic Engineering. |
[DEF:Std:Semantics:Contracts]
@COMPLEXITY: 5
@PURPOSE: Core extension protocol for Design by Contract, Fractal Decision Memory (ADR), and Long-Horizon Agentic Engineering.
@RELATION: DEPENDS_ON -> [Std:Semantics:Core]
@INVARIANT: A contract's @POST guarantees cannot be weakened without verifying upstream @RELATION dependencies.
0. AGENTIC ENGINEERING & PRESERVED THINKING (GLM-5 PARADIGM)
You are operating in an "Agentic Engineering" paradigm, far beyond single-turn "vibe coding". In long-horizon tasks (over 50+ commits), LLMs naturally degrade, producing "Slop" (high verbosity, structural erosion) due to Amnesia of Rationale and Context Blindness. To survive this:
- Preserved Thinking: We store the architectural thoughts of past agents directly in the AST via
@RATIONALEand@REJECTEDtags. You MUST read and respect them to avoid cyclic regressions. - Interleaved Thinking: You MUST reason before you act. Deductive logic (via
<thinking>orlogger.reason) MUST precede any AST mutation. - Anti-Erosion: You are strictly forbidden from haphazardly patching new
if/elselogic into existing functions. If a[DEF]block grows in Cyclomatic Complexity, you MUST decompose it into new[DEF]nodes.
I. CORE SEMANTIC CONTRACTS (C4-C5 REQUIREMENTS)
Before implementing or modifying any logic inside a [DEF] anchor, you MUST define or respect its contract metadata:
@PURPOSE:One-line essence of the node.@PRE:Execution prerequisites. MUST be enforced in code via explicitif/raiseearly returns or guards. NEVER useassertfor business logic.@POST:Strict output guarantees. Cascading Failure Protection: You CANNOT alter a@POSTguarantee without explicitly verifying that no upstream[DEF](which has a@RELATION: CALLSto your node) will break.@SIDE_EFFECT:Explicit declaration of state mutations, I/O, DB writes, or network calls.@DATA_CONTRACT:DTO mappings (e.g.,Input -> UserCreateDTO, Output -> UserResponseDTO).
II. FRACTAL DECISION MEMORY & ADRs (ADMentor PROTOCOL)
Decision memory prevents architectural drift. It records the Decision Space (Why we do it, and What we abandoned).
@RATIONALE:The strict reasoning behind the chosen implementation path.@REJECTED:The alternative path that was considered but FORBIDDEN, and the exact risk, bug, or technical debt that disqualified it.
The 3 Layers of Decision Memory:
- Global ADR (
[DEF:id:ADR]): Standalone nodes defining repo-shaping decisions (e.g.,[DEF:AuthPattern:ADR]). You cannot override these locally. - Task Guardrails: Preventative
@REJECTEDtags injected by the Orchestrator to keep you away from known LLM pitfalls. - Reactive Micro-ADR (Your Responsibility): If you encounter a runtime failure, use
logger.explore(), and invent a valid workaround, you MUST ascend to the[DEF]header and document it via@RATIONALE: [Why]and@REJECTED:[The failing path]BEFORE closing the task.
Resurrection Ban: Silently reintroducing a coding pattern, library, or logic flow previously marked as @REJECTED is classified as a fatal regression. If the rejected path is now required, emit <ESCALATION> to the Architect.
III. ZERO-EROSION & ANTI-VERBOSITY RULES (SlopCodeBench PROTOCOL)
Long-horizon AI coding naturally accumulates "slop". You are audited against two strict metrics:
- Structural Erosion: Do not concentrate decision-point mass into monolithic functions. If your modifications push a
[DEF]node's Cyclomatic Complexity (CC) above 10, or its length beyond 150 lines, you MUST decompose the logic into smaller[DEF]helpers and link them via@RELATION: CALLS. - Verbosity: Do not write identity-wrappers, useless intermediate variables, or defensive checks for impossible states if the
@PREcontract already guarantees data validity. Trust the contract.
IV. EXECUTION LOOP (INTERLEAVED PROTOCOL)
When assigned a Worker Packet for a specific [DEF] node, execute strictly in this order:
- READ (Preserved Thinking): Analyze the injected
@RATIONALE,@REJECTED, and@PRE/@POSTtags. - REASON (Interleaved Thinking): Emit your deductive logic. How will you satisfy the
@POSTwithout violating@REJECTED? - ACT (AST Mutation): Write the code strictly within the
[DEF]...[/DEF]AST boundaries. - REFLECT: Emit
logger.reflect()(or equivalent<reflection>) verifying that the resulting code physically guarantees the@POSTcondition. - UPDATE MEMORY: If you discovered a new dead-end during implementation, inject a Reactive Micro-ADR into the header.
[/DEF:Std:Semantics:Contracts]
[SYSTEM: END OF CONTRACTS DIRECTIVE. ENFORCE STRICT AST COMPLIANCE.]