Specification & Grammar Reference

Formal H2C block grammar, field types, and context management commands for AI-to-AI communication.

Block Types

[ARCH:PLAN]

Architecture Block

Declares project architecture, framework, libraries, auth, and file structure. Fields: id, fw, lib, auth, struct, notes. Typically the first block in a workflow.

[BUILD:EXEC]

Build Execution Block

Initiates a build step on a target file. Fields: id, target, desc. Paired with BUILD:DONE for completion tracking.

[BUILD:DONE]

Build Completion Block

Confirms a build step finished. Fields: id, diff, rev. The diff field uses [filename~revision] format for versioning.

[TEST:RUN]

Test Execution Block

Triggers a test suite. Fields: id, target, framework. Paired with TEST:PASS or TEST:FAIL for results.

[TEST:PASS]

Test Result Block

Reports test outcomes with metrics. Fields: id, count, coverage. Supports pass/fail status and coverage reporting.

[CTX:UPDATE]

Context Update Block

Tracks workflow layer transitions. Fields: ~progress, ~next, ~active_files. CTX fields use ~ prefix. Mandatory on every layer change.

[CTX:NEGOTIATE]

Handshake Block (v1.4)

Mandatory first block of every chain. Fields: version, capabilities. Negotiates protocol version and features between agents.

[BUILD:NACK]

Error Recovery Block (v1.4)

Explicit malformed block rejection. Fields: ref_id, error, hint. Replaces silent discard of invalid blocks.

Context Management Commands

[CTX:PRUNE]

Prune

Removes old blocks from the context window. Fields: keep, pruned, reason. Mandatory every 5 messages. Keeps active blocks while pruning completed ones.

[CTX:COMPACT]

Compact

Consolidates message history into a summary. Fields: summary, keep_active, pruned_history. Mandatory every 20 messages with pass/fail counters.

[CTX:FREEZE]

Freeze

Archives history when COMPACT is no longer sufficient (~100 msgs). Fields: snapshot, baseline. Resets PRUNE and COMPACT counters.

[ORCH:END]

Orchestration End

Terminal block signaling workflow completion. Fields: final (complete|error|timeout), est_token, pass_count, fail_count.

Formal Grammar (BNF)

<message>     ::= <block>
<block>       ::= "[" <type> ":" <subtype> "]" "\n" <fields>
<type>        ::= "ARCH" | "BUILD" | "TEST" | "CTX" | "STATE" | "ORCH" | "SKILL"

<subtype>     ::= "PLAN" | "EXEC" | "DONE" | "FIX" | "REVERT" | "NACK"
                | "RUN" | "PASS" | "FAIL"
                | "PRIMITIVES" | "UPDATE" | "PRUNE" | "COMPACT" | "FREEZE"
                | "NEGOTIATE" | "FINDINGS" | "ACK" | "END" | "PROMPT"

<fields>      ::= <field> ("|" <field>)*
<field>       ::= <key> ":" <value> | "~" <key> ":" <value>
<key>         ::= [a-zA-Z_][a-zA-Z0-9_]*

<value>       ::= <int> | <signed_int> | <rev> | <list> | <string>
<int>         ::= [0-9]+
<signed_int>  ::= ["+" | "-"] <int>
<rev>         ::= <string> "~" <int>
<list>        ::= "[" <string> ("," <string>)* "]"
<string>      ::= [^\|\n\[\]\:]+

<env-ref>     ::= "::env(" <identifier> ")"

EBNF ISO 14977 compliant. See the full SPEC.md on GitHub for the complete formal specification, AST model, and opcodes.

Field Reference

FieldTypeUsed InDescription
idstringAll blocksUnique identifier for correlation
fwstringARCH:PLANFramework and version (e.g. python3.11)
libstringARCH:PLANDependencies (comma-separated)
structlistARCH:PLANFile/directory structure
difflist_revBUILD:DONEChanged files with revision [file~N]
revintBUILD:DONERevision number (monotonic)
cycle_idstringBUILD:FIX, TEST:FAIL, TEST:PASSUnique fix cycle identifier
~progressstringCTX:UPDATECurrent layer and status (layer=N,status=X)
~active_fileslist_revCTX:UPDATEFiles currently in play with revision
keeplist_idsCTX:PRUNEBlocks to retain
prunedlist_idsCTX:PRUNEBlocks to remove
summarylistCTX:COMPACTMax 5 entries summarizing pruned history
baselineintCTX:FREEZEMessage number at freeze point
est_tokenintORCH:ENDEstimated token consumption

Ready to Implement H2C?

The specification is open-source (MIT). No dependencies, no runtime — just plain text.