PROTOCOL.md raw

iskra-server wire protocol

Binary request-response protocol over TCP or Unix domain sockets.

Transport

Frame format

Every message (request or response) is length-prefixed:

[4 bytes] length (uint32 LE) - byte count of everything that follows
[N bytes] payload

Maximum frame size: 4 MiB.

Request payload

[1 byte]  op code
[N bytes] op-specific fields

Response payload

[1 byte]  status
[N bytes] op-specific fields

Status codes:

ValueNameMeaning
0x00OKSuccess, payload contains result
0x01NOT_FOUNDLookup returned no match, payload empty
0x02ERRORServer error, payload is UTF-8 error message

Encoding primitives

TypeEncoding
uint81 byte
uint162 bytes LE
uint324 bytes LE
uint648 bytes LE
stringuint16 length prefix + UTF-8 bytes
Key16 bytes (two uint64 LE)

All multi-byte integers are little-endian.

Operations

0x01 - BigramWeight

Exact bigram lookup at a specific domain and coord.

Request:

FieldTypeDescription
domainuint8Domain byte (0x01=EN, 0x02=JA, 0x10=MoxieSRC, ...)
coorduint6464-bit packed coordinate
prevstringPrevious token
nextstringNext token

Response (OK):

FieldTypeDescription
weightuint32Observation count (0 = never observed)

0x02 - BigramWeightRelaxed

Bigram lookup with full coord relaxation cascade. Strips coord axes one at a time (pragmatic -> register -> valency -> semantic -> grammatical -> cooccur -> morph) until a non-zero weight is found.

Request:

FieldTypeDescription
domainuint8Domain byte
coorduint64Starting coord (most specific)
prevstringPrevious token
nextstringNext token

Response (OK):

FieldTypeDescription
weightuint32First non-zero weight found
matched_coorduint64Coord level that matched (0 = base/dictionary form)

0x03 - IngestBigram

Record one observation of a (prev -> next) transition. Increments count if the bigram exists, inserts with count=1 if new.

Request:

FieldTypeDescription
domainuint8Domain byte
coorduint64Context coord for this observation
prevstringPrevious token
nextstringNext token

Response (OK):

FieldTypeDescription
recIdxuint32Record index of the bigram entry

0x04 - IngestText

Bulk ingest a token sequence. Records bigrams for all adjacent pairs (tokens[0]->tokens[1], tokens[1]->tokens[2], ...).

Request:

FieldTypeDescription
domainuint8Domain byte
coorduint64Base context coord for the sequence
countuint16Number of tokens
tokensstring[]Token sequence (count entries)

Response (OK):

Empty payload.

0x05 - WalkStep

Compute candidate next positions from a current walk state. Returns continuations ordered by descending bigram weight.

Request:

FieldTypeDescription
domainuint8Domain byte
coorduint64Current context coord
wordstringCurrent word (prev token for bigram lookup)
maxCandidatesuint16Maximum candidates to return

Response (OK):

FieldTypeDescription
countuint16Number of candidates
candidates[]variableRepeated candidate entries

Each candidate entry:

FieldTypeDescription
domainuint8Candidate domain
coorduint64Matched coord
wordstringNext word
scoreuint32Accumulated walk score
depthuint8Steps taken
weightuint32Bigram weight for this transition

0x06 - Translate

Cross-domain translation via sub-lattice composition. Finds the best match for a word in dstDomain using coord-relaxation and cross-domain links.

Request:

FieldTypeDescription
srcDomainuint8Source domain byte
dstDomainuint8Destination domain byte
coorduint64Semantic/morph context in source domain
wordstringWord to translate

Response (OK):

FieldTypeDescription
resultstringTranslated word in destination domain

Returns NOT_FOUND (0x01) if no translation exists at any relaxation level.

0x07 - Lookup

Raw record lookup by branch and key.

Request:

FieldTypeDescription
branchuint8Branch index (0-7)
keyKey128-bit lattice key

Response (OK):

FieldTypeDescription
founduint81 if found, 0 if not
formstringSurface form of the record
countuint32MetaEntry.Count

0x08 - Insert

Insert a new record into the lattice.

Request:

FieldTypeDescription
branchuint8Branch index (0-7)
keyKey128-bit lattice key
formstringSurface form to store
kinduint16NodeKind bitfield
stageuint8Stage tag

Response (OK):

FieldTypeDescription
recIdxuint32Record index of the new entry

0x09 - BeamRun

Execute a full beam search walk. Starts from the given word and walks maxSteps iterations with the specified beam width and walk kind.

Request:

FieldTypeDescription
domainuint8Domain byte
coorduint64Starting context coord
wordstringStarting word
widthuint16Beam width (number of parallel hypotheses)
maxStepsuint16Maximum walk iterations
kinduint8Walk kind: 0=translate, 1=elaborate, 2=narrow

Walk kinds:

Response (OK):

FieldTypeDescription
domainuint8Final domain
depthuint8Steps actually taken
coorduint64Final coord
scoreuint32Accumulated confidence score
wordstringFinal word reached

0x0A - Flush

Force immediate persistence of the lattice to disk.

Request:

Empty (just the op byte).

Response (OK):

Empty payload.

0x0B - IngestRef

Record a typed reference from src to target. References use the same storage as bigrams (Bcooccur branch) but with a RefKind byte set on the MetaEntry. The coord gets RefKind bits set at [15:13] so reference keys hash differently from sequential bigrams.

Request:

FieldTypeDescription
domainuint8Domain byte
coorduint64Context coord
srcstringSource symbol
targetstringTarget symbol
kinduint8Reference type (1-7)

Reference types:

ValueNameMeaning
1RefContainssrc contains target (directory/scope)
2RefRequiressrc requires target (type constraint)
3RefProducessrc produces target (return/output)
4RefOperatesOnsrc operates on target (parameter)
5RefIsAsrc is a target (subtype/hypernym)
6RefBindssrc modifies relationship between neighbors
7RefContextsrc disambiguated by target (path segment)

Response (OK):

FieldTypeDescription
recIdxuint32Record index of the reference entry

0x0C - GetRefs

Return all typed references originating from src in the given domain.

Request:

FieldTypeDescription
domainuint8Domain byte
srcstringSource symbol to query

Response (OK):

FieldTypeDescription
countuint16Number of references
refs[]variableRepeated RefEntry

Each RefEntry:

FieldTypeDescription
recIdxuint32Record index
targetstringTarget symbol
kinduint8Reference type (1-7)
weightuint32Observation count

0x0D - WalkOutward

Follow references from src outward, one depth level at a time, up to maxDepth. Returns the full reachable tree of symbols with their relationship types. Cost is proportional to ambiguity depth.

Request:

FieldTypeDescription
domainuint8Domain byte
srcstringStarting symbol
maxDepthuint8Maximum depth levels to walk

Response (OK):

FieldTypeDescription
layerCountuint8Number of depth layers
layers[]variableRepeated RefLayer

Each RefLayer:

FieldTypeDescription
countuint16Number of entries in this layer
entries[]variableRepeated RefEntry (same format as GetRefs)

Coord layout - reference bits

Bits 15-13 of the coord encode the RefKind for reference records. When these bits are non-zero, the record is a typed reference rather than a sequential bigram. This ensures reference keys hash to different lattice positions than bigrams for the same word pair, naturally distributing them at higher depth where expansion has created room.

bits 15-13  refkind  (3 bits): reference type (0=bigram, 1-7=typed ref)
bits 12-8   position (4 bits): sequence order within a definition
bits  7-2   (available)
bits  1-0   register (2 bits): social register

Domain bytes

ValueDomainDescription
0x01LangENEnglish vocabulary
0x02LangJAJapanese vocabulary
0x10MoxieSRCMoxie source constructs
0x11MoxieASTMoxie AST nodes
0x12MoxieIRMoxie IR (LLVM)
0x13MoxieASMAssembly
0x14MoxieBINBinary/bytecode

Branch indices

IndexNameSemantic axis
0BsemanticOntological category
1Bgrammatical (Bnoun)Syntactic role
2BcooccurCo-occurrence / bigrams
3Bmorphology (Bverb)Morphological state
4Bpragmatic (Bmodifier)Domain/register context
5BphonologyPhonological (reserved)
6BvalencyArgument count
7BregisterSocial register

Coord layout (64-bit packed)

bits 63-48  semantic    (16 bits): 8 subject|object category pairs
bits 47-32  (reserved)
bits 31-29  grammatical  (3 bits): syntactic role
bits 28-25  cooccur      (4 bits): prev_type(2) + next_type(2)
bits 24-20  morphstate   (5 bits): tense/aspect/polarity/formality/evidential
bits 19-18  pragmatic    (2 bits): domain context
bits 17-16  valency      (2 bits): argument count
bits 15-2   (reserved)
bits  1-0   register     (2 bits): social register

coord=0 is the base key (dictionary form, context-free lookups).

Auto-flush behavior

The server flushes to disk after every 64 write operations (IngestBigram, IngestText) or 5 seconds since last flush, whichever comes first. Clients can force an immediate flush with OpFlush.

Connection semantics