3.4 KiB
3.4 KiB
SYSTEM STANDARD: CODE GENERATION PROTOCOL
OBJECTIVE: Generate Python code that strictly adheres to the Semantic Coherence standards defined below. All output must be machine-readable, fractal-structured, and optimized for Sparse Attention navigation.
I. CORE REQUIREMENTS
- Causal Validity: Semantic definitions (Contracts) must ALWAYS precede implementation code.
- Immutability: Once defined, architectural decisions in the Module Header are treated as immutable constraints.
- Format Compliance: Output must strictly follow the
[DEF]/[/DEF]anchor syntax.
II. SYNTAX SPECIFICATION
Code must be wrapped in semantic anchors using square brackets to minimize token interference.
1. Entity Anchors (The "Container")
- Start:
# [DEF:identifier:Type] - End:
# [/DEF:identifier](MANDATORY for semantic accumulation) - Types:
Module,Class,Function,DataClass,Enum.
2. Metadata Tags (The "Content")
- Syntax:
# @KEY: Value - Location: Inside the
[DEF]block, before any code.
3. Graph Relations (The "Map")
- Syntax:
# @RELATION: TYPE -> TARGET_ID - Types:
DEPENDS_ON,CALLS,INHERITS_FROM,IMPLEMENTS,WRITES_TO,READS_FROM.
III. FILE STRUCTURE STANDARD
1. Python Module Header
Every .py file starts with a Module definition.
# [DEF:module_name:Module]
#
# @SEMANTICS: [keywords for vector search]
# @PURPOSE: [Primary responsibility of the module]
# @LAYER: [Architecture layer: Domain/Infra/UI]
# @RELATION: [Dependencies]
#
# @INVARIANT: [Global immutable rule for this file]
# @CONSTRAINT: [Hard restriction, e.g., "No SQL here"]
# @PUBLIC_API: [Exported symbols]
# [SECTION: IMPORTS]
...
# [/SECTION]
# ... IMPLEMENTATION ...
# [/DEF:module_name]
2. Svelte Component Header
Every .svelte file starts with a Component definition inside an HTML comment.
<!--
[DEF:ComponentName:Component]
@SEMANTICS: [keywords]
@PURPOSE: [Primary responsibility]
@LAYER: [UI/State/Layout]
@RELATION: [Child components, Stores, API]
@PROPS:
- name: type - description
@EVENTS:
- name: payload_type - description
@INVARIANT: [Immutable UI rule]
-->
<script>
// ...
</script>
<!-- [/DEF:ComponentName] -->
IV. FUNCTION & CLASS CONTRACTS (DbC)
Contracts are the Source of Truth.
Required Template:
# [DEF:func_name:Function]
# @PURPOSE: [Description]
# @SPEC_LINK: [Requirement ID]
#
# @PRE: [Condition required before execution]
# @POST: [Condition guaranteed after execution]
# @PARAM: [name] ([type]) - [desc]
# @RETURN: [type] - [desc]
# @THROW: [Exception] - [Reason]
#
# @RELATION: [Graph connections]
def func_name(...):
# 1. Runtime check of @PRE
# 2. Logic implementation
# 3. Runtime check of @POST
pass
# [/DEF:func_name]
V. LOGGING STANDARD (BELIEF STATE)
Logs define the agent's internal state for debugging and coherence checks.
Format: logger.level(f"[{ANCHOR_ID}][{STATE}] {MESSAGE} context={...}")
States: Entry, Validation, Action, Coherence:OK, Coherence:Failed, Exit.
VI. GENERATION WORKFLOW
- Analyze Request: Identify target module and graph position.
- Define Structure: Generate
[DEF]anchors and Contracts FIRST. - Implement Logic: Write code satisfying Contracts.
- Validate: If logic conflicts with Contract -> Stop -> Report Error.